libosmogb 1.9.0.196-9975
Osmocom Gb library
gprs_bssgp.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <stdint.h>
8
9#include <osmocom/gsm/gsm48.h>
10#include <osmocom/gsm/prim.h>
11
15
16/* gprs_bssgp_util.c */
17
18#define BSSGP_PDUF_UL 0x0001 /* PDU may occur in uplink */
19#define BSSGP_PDUF_DL 0x0002 /* PDU may occur in downlink */
20#define BSSGP_PDUF_SIG 0x0004 /* PDU may occur on Signaling BVC */
21#define BSSGP_PDUF_PTP 0x0008 /* PDU may occur on PTP BVC */
22#define BSSGP_PDUF_PTM 0x0010 /* PDU may occur on PTM BVC */
23
24extern const struct osmo_tlv_prot_def osmo_pdef_bssgp;
25
27static inline uint32_t bssgp_pdu_type_flags(uint8_t pdu_type) {
29}
30
31typedef int (*bssgp_bvc_send)(void *ctx, struct msgb *msg);
32extern struct gprs_ns_inst *bssgp_nsi;
34struct msgb *bssgp_msgb_alloc(void);
35struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
36const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
37const char *bssgp_pdu_str(enum bssgp_pdu_type pdu);
38int bssgp_tx_bvc_reset_nsei_bvci(uint16_t nsei, uint16_t bvci, enum gprs_bssgp_cause cause, const struct gprs_ra_id *ra_id, uint16_t cell_id);
39/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
40int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
41 uint16_t bvci, uint16_t ns_bvci);
42/* Chapter 10.4.14: Status */
43int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
44
49
53
60
62};
63
66
67 /* common fields */
68 uint16_t nsei;
69 uint16_t bvci;
70 uint32_t tlli;
71 struct tlv_parsed *tp;
73
74 /* specific fields */
75 union {
76 struct {
77 uint8_t suspend_ref;
80 } u;
81};
82
83/* gprs_bssgp.c */
84
87 uint32_t bucket_size_max;
90 uint32_t bucket_counter;
91 struct timeval time_last_pdu;
93 /* the built-in queue */
94 uint32_t max_queue_depth;
95 uint32_t queue_depth;
100 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
101 uint32_t llc_pdu_len, void *priv);
102};
103
104#define BVC_S_BLOCKED 0x0001
105
106/* The per-BTS context that we keep on the SGSN side of the BSSGP link */
109
111 uint16_t cell_id;
113 /* NSEI and BVCI of underlying Gb link. Together they
114 * uniquely identify a link to a BTS (5.4.4) */
115 uint16_t bvci;
116 uint16_t nsei;
117
118 uint32_t state;
119
121
126 uint32_t r_default_ms;
127
130 /* we might want to add this as a shortcut later, avoiding the NSVC
131 * lookup for every packet, similar to a routing cache */
132 //struct gprs_nsvc *nsvc;
133};
134extern struct llist_head bssgp_bvc_ctxts;
135/* Create a BTS Context with BVCI+NSEI */
136struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei);
137/* Find a BTS Context based on parsed RA ID and Cell ID */
138struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
139/* Find a BTS context based on BVCI+NSEI tuple */
140struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
141/* Free a given BTS context */
142void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx);
143
144#define BVC_F_BLOCKED 0x0001
145
154};
155
156
157#include <osmocom/gsm/tlv.h>
159
160/* BSSGP-UL-UNITDATA.ind */
161int bssgp_rcvmsg(struct msgb *msg);
162
163/* BSSGP-DL-UNITDATA.req */
164struct bssgp_lv {
165 uint16_t len;
166 uint8_t *v;
167};
168/* parameters for BSSGP downlink userdata transmission */
170 uint32_t *tlli;
171 char *imsi;
173 uint16_t drx_parms;
174 /* FIXME: priority */
176 uint8_t qos_profile[3];
177};
178int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
179 struct bssgp_dl_ud_par *dup);
180
181uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
182int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
183 uint16_t cid);
184
185/* Wrapper around TLV parser to parse BSSGP IEs */
186static inline int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
187{
188 return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
189}
190
195};
196
203};
204
210 uint16_t bvci;
211 char *imsi;
212 uint32_t *ptmsi;
213 uint16_t drx_params;
214 uint8_t qos[3];
215};
216
217/* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
218int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
219 struct bssgp_paging_info *pinfo);
220
221void bssgp_fc_init(struct bssgp_flow_control *fc,
222 uint32_t bucket_size_max, uint32_t bucket_leak_rate,
223 uint32_t max_queue_depth,
224 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
225 uint32_t llc_pdu_len, void *priv));
226
227/* input function of the flow control implementation, called first
228 * for the MM flow control, and then as the MM flow control output
229 * callback in order to perform BVC flow control */
230int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
231 uint32_t llc_pdu_len, void *priv);
232
233/* Initialize the Flow Control parameters for a new MS according to
234 * default values for the BVC specified by BVCI and NSEI */
235int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
236 uint16_t nsei, uint32_t max_queue_depth);
237
238void bssgp_flush_all_queues(void);
240
241/* gprs_bssgp_vty.c */
242int bssgp_vty_init(void);
243void bssgp_set_log_ss(int ss) OSMO_DEPRECATED("Use DLBSSGP instead!\n");
244
245int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
struct msgb * bssgp_msgb_copy(const struct msgb *msg, const char *name)
Definition: gprs_bssgp_util.c:505
int bssgp_rcvmsg(struct msgb *msg)
Definition: gprs_bssgp.c:1157
void bssgp_fc_flush_queue(struct bssgp_flow_control *fc)
Flush the queue of the bssgp_flow_control.
Definition: gprs_bssgp.c:1417
struct bssgp_bvc_ctx * btsctx_alloc(uint16_t bvci, uint16_t nsei)
Definition: gprs_bssgp.c:209
int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei, uint16_t bvci, uint16_t ns_bvci)
Definition: gprs_bssgp_util.c:536
bssgp_paging_mode
BSSGP Paging mode.
Definition: gprs_bssgp.h:192
@ BSSGP_PAGING_PS
Definition: gprs_bssgp.h:193
@ BSSGP_PAGING_CS
Definition: gprs_bssgp.h:194
bssgp_prim
Definition: gprs_bssgp.h:45
@ PRIM_NM_BVC_UNBLOCK
Definition: gprs_bssgp.h:58
@ PRIM_BSSGP_PTM_UD
Definition: gprs_bssgp.h:48
@ PRIM_BSSGP_GMM_SUSPEND
Definition: gprs_bssgp.h:50
@ PRIM_NM_STATUS
Definition: gprs_bssgp.h:59
@ PRIM_NM_FLUSH_LL
Definition: gprs_bssgp.h:54
@ PRIM_BSSGP_GMM_RESUME
Definition: gprs_bssgp.h:51
@ PRIM_BSSGP_GMM_PAGING
Definition: gprs_bssgp.h:52
@ PRIM_NM_BVC_BLOCK
Definition: gprs_bssgp.h:57
@ PRIM_NM_BVC_RESET
Definition: gprs_bssgp.h:56
@ PRIM_NM_LLC_DISCARDED
Definition: gprs_bssgp.h:55
@ PRIM_BSSGP_DL_UD
Definition: gprs_bssgp.h:46
@ PRIM_BSSGP_RIM_PDU_TRANSFER
Definition: gprs_bssgp.h:61
@ PRIM_BSSGP_UL_UD
Definition: gprs_bssgp.h:47
struct bssgp_bvc_ctx * btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei)
Definition: gprs_bssgp.c:192
static uint32_t bssgp_pdu_type_flags(uint8_t pdu_type)
return the PDU type flags (UL/DL/SIG/PTP/PTM) of specified PDU type
Definition: gprs_bssgp.h:27
int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
const struct osmo_tlv_prot_def osmo_pdef_bssgp
Definition: gprs_bssgp_util.c:261
void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data)
Definition: gprs_bssgp.c:203
struct gprs_ns_inst * bssgp_nsi
Definition: gprs_bssgp_util.c:37
uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf)
Definition: gprs_bssgp.c:349
int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, uint16_t nsei, uint32_t max_queue_depth)
Definition: gprs_bssgp.c:900
int(* bssgp_bvc_send)(void *ctx, struct msgb *msg)
Definition: gprs_bssgp.h:31
int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, uint16_t cid)
Definition: gprs_bssgp.c:357
void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx)
Definition: gprs_bssgp.c:242
int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, struct bssgp_paging_info *pinfo)
Definition: gprs_bssgp.c:1337
const char * bssgp_pdu_str(enum bssgp_pdu_type pdu)
Definition: gprs_bssgp_util.c:489
const char * bssgp_cause_str(enum gprs_bssgp_cause cause)
Definition: gprs_bssgp_util.c:484
struct llist_head bssgp_bvc_ctxts
bssgp_ctr
Definition: gprs_bssgp.h:146
@ BSSGP_CTR_DISCARDED
Definition: gprs_bssgp.h:152
@ BSSGP_CTR_PKTS_IN
Definition: gprs_bssgp.h:147
@ BSSGP_CTR_BYTES_OUT
Definition: gprs_bssgp.h:150
@ BSSGP_CTR_PKTS_OUT
Definition: gprs_bssgp.h:148
@ BSSGP_CTR_BLOCKED
Definition: gprs_bssgp.h:151
@ BSSGP_CTR_STATUS
Definition: gprs_bssgp.h:153
@ BSSGP_CTR_BYTES_IN
Definition: gprs_bssgp.h:149
int bssgp_vty_init(void)
Definition: gprs_bssgp_vty.c:206
bssgp_paging_scope
BSSGP Paging scope.
Definition: gprs_bssgp.h:198
@ BSSGP_PAGING_ROUTEING_AREA
all cells in RA
Definition: gprs_bssgp.h:201
@ BSSGP_PAGING_LOCATION_AREA
all cells in LA
Definition: gprs_bssgp.h:200
@ BSSGP_PAGING_BVCI
one cell
Definition: gprs_bssgp.h:202
@ BSSGP_PAGING_BSS_AREA
all cells in BSS
Definition: gprs_bssgp.h:199
void bssgp_flush_all_queues(void)
Flush the queues of all BSSGP contexts.
Definition: gprs_bssgp.c:1431
struct msgb * bssgp_msgb_alloc(void)
Definition: gprs_bssgp_util.c:494
void bssgp_set_log_ss(int ss) OSMO_DEPRECATED("Use DLBSSGP instead!\n")
Definition: gprs_bssgp.c:1406
int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, struct bssgp_dl_ud_par *dup)
Definition: gprs_bssgp.c:1232
void bssgp_fc_init(struct bssgp_flow_control *fc, uint32_t bucket_size_max, uint32_t bucket_leak_rate, uint32_t max_queue_depth, int(*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, uint32_t llc_pdu_len, void *priv))
Definition: gprs_bssgp.c:884
int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
Definition: gprs_bssgp_util.c:555
static int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
Definition: gprs_bssgp.h:186
int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, uint32_t llc_pdu_len, void *priv)
Definition: gprs_bssgp.c:855
struct bssgp_bvc_ctx * btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid)
Definition: gprs_bssgp.c:85
int bssgp_tx_bvc_reset_nsei_bvci(uint16_t nsei, uint16_t bvci, enum gprs_bssgp_cause cause, const struct gprs_ra_id *ra_id, uint16_t cell_id)
Transmit a BVC-RESET message with a given nsei and bvci (Chapter 10.4.12)
Definition: gprs_bssgp.c:149
uint16_t bvci
Definition: gprs_msgb.h:8
uint16_t nsei
Identifiers of a BTS, equal to 'struct bssgp_bts_ctx'.
Definition: gprs_msgb.h:7
static size_t len(const char *str)
uint8_t pdu_type
NS PDU type.
Definition: gsm_08_16.h:0
uint8_t data[0]
variable-length payload
Definition: gsm_08_16.h:1
const char * name
int tlv_parse(struct tlv_parsed *dec, const struct tlv_definition *def, const uint8_t *buf, int buf_len, uint8_t lv_tag, uint8_t lv_tag2)
struct tlv_definition tvlv_att_def
static uint32_t osmo_tlv_prot_msgt_flags(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
#define OSMO_DEPRECATED(text)
uint8_t msg[0]
bssgp_pdu_type
BSSGP PDU types (Section 11.3.26 / Table 11.27)
Definition: gsm_08_18.h:17
gprs_bssgp_cause
Cause coding (Section 11.3.8 / Table 11.10)
Definition: gsm_08_18.h:266
Definition: gprs_bssgp.h:107
struct llist_head list
Definition: gprs_bssgp.h:108
uint16_t bvci
Definition: gprs_bssgp.h:115
struct gprs_ra_id ra_id
parsed RA ID of the remote BTS
Definition: gprs_bssgp.h:110
struct bssgp_flow_control * fc
Definition: gprs_bssgp.h:122
uint16_t cell_id
Cell ID of the remote BTS.
Definition: gprs_bssgp.h:111
uint32_t r_default_ms
default bucket leak rate of per-MS bucket in octests/s
Definition: gprs_bssgp.h:126
struct rate_ctr_group * ctrg
Definition: gprs_bssgp.h:120
uint16_t nsei
Definition: gprs_bssgp.h:116
bool is_sgsn
BSS or SGSN.
Definition: gprs_bssgp.h:129
uint32_t state
Definition: gprs_bssgp.h:118
uint32_t bmax_default_ms
default maximum size of per-MS bucket in octets
Definition: gprs_bssgp.h:124
Definition: gprs_bssgp.h:169
char * imsi
Definition: gprs_bssgp.h:171
uint32_t * tlli
Definition: gprs_bssgp.h:170
struct bssgp_flow_control * fc
Definition: gprs_bssgp.h:172
uint8_t qos_profile[3]
Definition: gprs_bssgp.h:176
struct bssgp_lv ms_ra_cap
Definition: gprs_bssgp.h:175
uint16_t drx_parms
Definition: gprs_bssgp.h:173
BSSGP flow control (SGSN side) According to Section 8.2.
Definition: gprs_bssgp.h:86
struct timeval time_last_pdu
timestamp of last PDU sent
Definition: gprs_bssgp.h:91
uint32_t bucket_counter
number of tokens in the bucket
Definition: gprs_bssgp.h:90
struct llist_head queue
linked list of msgb's
Definition: gprs_bssgp.h:96
uint32_t max_queue_depth
how many packets to queue (mgs)
Definition: gprs_bssgp.h:94
struct osmo_timer_list timer
timer-based dequeueing
Definition: gprs_bssgp.h:97
int(* out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, uint32_t llc_pdu_len, void *priv)
callback to be called at output of flow control
Definition: gprs_bssgp.h:100
uint32_t bucket_size_max
maximum size of the bucket (octets)
Definition: gprs_bssgp.h:87
uint32_t queue_depth
current length of queue (msgs)
Definition: gprs_bssgp.h:95
uint32_t bucket_leak_rate
leak rate of the bucket (octets/sec)
Definition: gprs_bssgp.h:88
Definition: gprs_bssgp.h:164
uint8_t * v
Definition: gprs_bssgp.h:166
uint16_t len
Definition: gprs_bssgp.h:165
BSSGP paging information.
Definition: gprs_bssgp.h:206
char * imsi
IMSI, if any.
Definition: gprs_bssgp.h:211
enum bssgp_paging_scope scope
bssgp_paging_scope
Definition: gprs_bssgp.h:208
uint8_t qos[3]
QoS parameters.
Definition: gprs_bssgp.h:214
uint16_t drx_params
DRX parameters.
Definition: gprs_bssgp.h:213
enum bssgp_paging_mode mode
CS or PS paging.
Definition: gprs_bssgp.h:207
struct gprs_ra_id raid
RA Identifier.
Definition: gprs_bssgp.h:209
uint16_t bvci
BVCI.
Definition: gprs_bssgp.h:210
uint32_t * ptmsi
P-TMSI, if any.
Definition: gprs_bssgp.h:212
Definition: gprs_bssgp_rim.h:242
An instance of the NS protocol stack.
Definition: gprs_ns.h:79
Definition: gprs_bssgp.h:64
struct osmo_bssgp_prim::@0::@1 resume
uint8_t suspend_ref
Definition: gprs_bssgp.h:77
union osmo_bssgp_prim::@0 u
uint16_t bvci
Definition: gprs_bssgp.h:69
struct tlv_parsed * tp
Definition: gprs_bssgp.h:71
struct bssgp_ran_information_pdu rim_pdu
Definition: gprs_bssgp.h:79
struct osmo_prim_hdr oph
Definition: gprs_bssgp.h:65
uint16_t nsei
Definition: gprs_bssgp.h:68
uint32_t tlli
Definition: gprs_bssgp.h:70
struct gprs_ra_id * ra_id
Definition: gprs_bssgp.h:72