libosmogb  1.5.1
Osmocom Gb library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
gprs_bssgp.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <stdint.h>
6 #include <osmocom/core/timer.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 
24 extern const struct osmo_tlv_prot_def osmo_pdef_bssgp;
25 
27 static inline uint32_t bssgp_pdu_type_flags(uint8_t pdu_type) {
28  return osmo_tlv_prot_msgt_flags(&osmo_pdef_bssgp, pdu_type);
29 }
30 
31 typedef int (*bssgp_bvc_send)(void *ctx, struct msgb *msg);
32 extern struct gprs_ns_inst *bssgp_nsi;
33 void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data);
34 struct msgb *bssgp_msgb_alloc(void);
35 struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
36 const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
37 const char *bssgp_pdu_str(enum bssgp_pdu_type pdu);
38 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);
39 /* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
40 int 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 */
43 int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
44 
45 enum bssgp_prim {
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;
72  struct gprs_ra_id *ra_id;
73 
74  /* specific fields */
75  union {
76  struct {
77  uint8_t suspend_ref;
78  } resume;
80  } u;
81 };
82 
83 /* gprs_bssgp.c */
84 
87  uint32_t bucket_size_max;
88  uint32_t bucket_leak_rate;
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;
96  struct llist_head queue;
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 */
108  struct llist_head list;
109 
110  struct gprs_ra_id ra_id;
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 
124  uint32_t bmax_default_ms;
126  uint32_t r_default_ms;
127 
128  /* we might want to add this as a shortcut later, avoiding the NSVC
129  * lookup for every packet, similar to a routing cache */
130  //struct gprs_nsvc *nsvc;
131 };
132 extern struct llist_head bssgp_bvc_ctxts;
133 /* Create a BTS Context with BVCI+NSEI */
134 struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei);
135 /* Find a BTS Context based on parsed RA ID and Cell ID */
136 struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
137 /* Find a BTS context based on BVCI+NSEI tuple */
138 struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
139 /* Free a given BTS context */
140 void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx);
141 
142 #define BVC_F_BLOCKED 0x0001
143 
144 enum bssgp_ctr {
152 };
153 
154 
155 #include <osmocom/gsm/tlv.h>
156 #include <osmocom/gprs/gprs_msgb.h>
157 
158 /* BSSGP-UL-UNITDATA.ind */
159 int bssgp_rcvmsg(struct msgb *msg);
160 
161 /* BSSGP-DL-UNITDATA.req */
162 struct bssgp_lv {
163  uint16_t len;
164  uint8_t *v;
165 };
166 /* parameters for BSSGP downlink userdata transmission */
168  uint32_t *tlli;
169  char *imsi;
171  uint16_t drx_parms;
172  /* FIXME: priority */
174  uint8_t qos_profile[3];
175 };
176 int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
177  struct bssgp_dl_ud_par *dup);
178 
179 uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
180 int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
181  uint16_t cid);
182 
183 /* Wrapper around TLV parser to parse BSSGP IEs */
184 static inline int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
185 {
186  return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
187 }
188 
193 };
194 
201 };
202 
207  struct gprs_ra_id raid;
208  uint16_t bvci;
209  char *imsi;
210  uint32_t *ptmsi;
211  uint16_t drx_params;
212  uint8_t qos[3];
213 };
214 
215 /* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
216 int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
217  struct bssgp_paging_info *pinfo);
218 
219 void bssgp_fc_init(struct bssgp_flow_control *fc,
220  uint32_t bucket_size_max, uint32_t bucket_leak_rate,
221  uint32_t max_queue_depth,
222  int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
223  uint32_t llc_pdu_len, void *priv));
224 
225 /* input function of the flow control implementation, called first
226  * for the MM flow control, and then as the MM flow control output
227  * callback in order to perform BVC flow control */
228 int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
229  uint32_t llc_pdu_len, void *priv);
230 
231 /* Initialize the Flow Control parameters for a new MS according to
232  * default values for the BVC specified by BVCI and NSEI */
233 int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
234  uint16_t nsei, uint32_t max_queue_depth);
235 
238 
239 /* gprs_bssgp_vty.c */
240 int bssgp_vty_init(void);
241 void bssgp_set_log_ss(int ss) OSMO_DEPRECATED("Use DLBSSGP instead!\n");
242 
243 int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
struct bssgp_flow_control * fc
Definition: gprs_bssgp.h:122
const struct osmo_tlv_prot_def osmo_pdef_bssgp
Definition: gprs_bssgp_util.c:261
Definition: gprs_bssgp.h:149
Definition: gprs_bssgp.h:57
int(* bssgp_bvc_send)(void *ctx, struct msgb *msg)
Definition: gprs_bssgp.h:31
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
struct llist_head queue
linked list of msgb's
Definition: gprs_bssgp.h:96
int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, struct bssgp_paging_info *pinfo)
Definition: gprs_bssgp.c:1293
#define OSMO_DEPRECATED(text)
uint8_t qos_profile[3]
Definition: gprs_bssgp.h:174
Definition: gprs_bssgp_rim.h:241
struct msgb * bssgp_msgb_copy(const struct msgb *msg, const char *name)
Definition: gprs_bssgp_util.c:505
uint8_t qos[3]
QoS parameters.
Definition: gprs_bssgp.h:212
void bssgp_set_log_ss(int ss) OSMO_DEPRECATED("Use DLBSSGP instead!\n")
Definition: gprs_bssgp.c:1362
char * imsi
IMSI, if any.
Definition: gprs_bssgp.h:209
uint8_t data[0]
variable-length payload
Definition: gsm_08_16.h:202
struct tlv_definition tvlv_att_def
struct osmo_prim_hdr oph
Definition: gprs_bssgp.h:65
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
BSSGP flow control (SGSN side) According to Section 8.2.
Definition: gprs_bssgp.h:86
uint32_t bucket_leak_rate
leak rate of the bucket (octets/sec)
Definition: gprs_bssgp.h:88
enum bssgp_paging_scope scope
bssgp_paging_scope
Definition: gprs_bssgp.h:206
uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf)
Definition: gprs_bssgp.c:311
uint16_t len
Definition: gprs_bssgp.h:163
uint16_t drx_parms
Definition: gprs_bssgp.h:171
Definition: gprs_bssgp.h:52
struct bssgp_lv ms_ra_cap
Definition: gprs_bssgp.h:173
struct bssgp_bvc_ctx * btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei)
Definition: gprs_bssgp.c:155
An instance of the NS protocol stack.
Definition: gprs_ns.h:79
static uint32_t osmo_tlv_prot_msgt_flags(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
all cells in RA
Definition: gprs_bssgp.h:199
uint16_t nsei
Definition: gprs_bssgp.h:68
uint32_t bucket_counter
number of tokens in the bucket
Definition: gprs_bssgp.h:90
uint32_t r_default_ms
default bucket leak rate of per-MS bucket in octests/s
Definition: gprs_bssgp.h:126
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
Definition: gprs_bssgp.h:162
one cell
Definition: gprs_bssgp.h:200
struct timeval time_last_pdu
timestamp of last PDU sent
Definition: gprs_bssgp.h:91
char * imsi
Definition: gprs_bssgp.h:169
Definition: gprs_bssgp.h:55
uint32_t bucket_size_max
maximum size of the bucket (octets)
Definition: gprs_bssgp.h:87
Definition: gprs_bssgp.h:58
Definition: gprs_bssgp.h:146
struct gprs_ra_id * ra_id
Definition: gprs_bssgp.h:72
Definition: gprs_bssgp.h:46
uint16_t cell_id
Cell ID of the remote BTS.
Definition: gprs_bssgp.h:111
uint16_t nsei
Identifiers of a BTS, equal to 'struct bssgp_bts_ctx'.
Definition: gprs_msgb.h:259
struct bssgp_bvc_ctx * btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid)
Definition: gprs_bssgp.c:84
uint32_t tlli
Definition: gprs_bssgp.h:70
struct osmo_timer_list timer
timer-based dequeueing
Definition: gprs_bssgp.h:97
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:103
uint8_t * v
Definition: gprs_bssgp.h:164
uint32_t * ptmsi
P-TMSI, if any.
Definition: gprs_bssgp.h:210
struct bssgp_ran_information_pdu rim_pdu
Definition: gprs_bssgp.h:79
Definition: gprs_bssgp.h:61
Definition: gprs_bssgp.h:150
void bssgp_flush_all_queues()
Flush the queues of all BSSGP contexts.
Definition: gprs_bssgp.c:1387
Definition: gprs_bssgp.h:192
gprs_bssgp_cause
Cause coding (Section 11.3.8 / Table 11.10)
Definition: gsm_08_18.h:266
uint16_t bvci
Definition: gprs_msgb.h:260
int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, uint32_t llc_pdu_len, void *priv)
Definition: gprs_bssgp.c:814
struct msgb * bssgp_msgb_alloc(void)
Definition: gprs_bssgp_util.c:494
Definition: gprs_bssgp.h:51
struct osmo_bssgp_prim::@0::@1 resume
Definition: gprs_bssgp.h:191
struct gprs_ra_id raid
RA Identifier.
Definition: gprs_bssgp.h:207
void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data)
Definition: gprs_bssgp.c:166
union osmo_bssgp_prim::@0 u
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:859
Definition: gprs_bssgp.h:148
struct tlv_parsed * tp
Definition: gprs_bssgp.h:71
enum bssgp_paging_mode mode
CS or PS paging.
Definition: gprs_bssgp.h:205
uint32_t * tlli
Definition: gprs_bssgp.h:168
struct gprs_ra_id ra_id
parsed RA ID of the remote BTS
Definition: gprs_bssgp.h:110
struct llist_head bssgp_bvc_ctxts
Definition: gprs_bssgp.h:56
Definition: gprs_bssgp.h:50
Definition: gprs_bssgp.h:48
Definition: gprs_bssgp.h:64
BSSGP paging information.
Definition: gprs_bssgp.h:204
uint16_t nsei
Definition: gprs_bssgp.h:116
struct bssgp_bvc_ctx * btsctx_alloc(uint16_t bvci, uint16_t nsei)
Definition: gprs_bssgp.c:172
uint32_t queue_depth
current length of queue (msgs)
Definition: gprs_bssgp.h:95
static int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
Definition: gprs_bssgp.h:184
all cells in LA
Definition: gprs_bssgp.h:198
uint8_t msg[0]
uint32_t max_queue_depth
how many packets to queue (mgs)
Definition: gprs_bssgp.h:94
uint8_t suspend_ref
Definition: gprs_bssgp.h:77
uint32_t bmax_default_ms
default maximum size of per-MS bucket in octets
Definition: gprs_bssgp.h:124
struct bssgp_flow_control * fc
Definition: gprs_bssgp.h:170
uint32_t state
Definition: gprs_bssgp.h:118
bssgp_paging_scope
BSSGP Paging scope.
Definition: gprs_bssgp.h:196
Definition: gprs_bssgp.h:145
struct llist_head list
Definition: gprs_bssgp.h:108
Definition: gprs_bssgp.h:47
all cells in BSS
Definition: gprs_bssgp.h:197
Definition: gprs_bssgp.h:59
void bssgp_fc_flush_queue(struct bssgp_flow_control *fc)
Flush the queue of the bssgp_flow_control.
Definition: gprs_bssgp.c:1373
void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx)
Definition: gprs_bssgp.c:204
static size_t len(const char *str)
int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
uint16_t bvci
BVCI.
Definition: gprs_bssgp.h:208
struct rate_ctr_group * ctrg
Definition: gprs_bssgp.h:120
int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, struct bssgp_dl_ud_par *dup)
Definition: gprs_bssgp.c:1188
bssgp_prim
Definition: gprs_bssgp.h:45
const char * bssgp_cause_str(enum gprs_bssgp_cause cause)
Definition: gprs_bssgp_util.c:484
Definition: gprs_bssgp.h:54
bssgp_pdu_type
BSSGP PDU types (Section 11.3.26 / Table 11.27)
Definition: gsm_08_18.h:17
int bssgp_vty_init(void)
Definition: gprs_bssgp_vty.c:206
uint16_t drx_params
DRX parameters.
Definition: gprs_bssgp.h:211
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)
Definition: gprs_bssgp.h:151
uint16_t bvci
Definition: gprs_bssgp.h:115
Definition: gprs_bssgp.h:147
bssgp_ctr
Definition: gprs_bssgp.h:144
int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
Definition: gprs_bssgp_util.c:555
bssgp_paging_mode
BSSGP Paging mode.
Definition: gprs_bssgp.h:190
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:843
struct gprs_ns_inst * bssgp_nsi
Definition: gprs_bssgp_util.c:37
const char * bssgp_pdu_str(enum bssgp_pdu_type pdu)
Definition: gprs_bssgp_util.c:489
Definition: gprs_bssgp.h:167
Definition: gprs_bssgp.h:107
int bssgp_rcvmsg(struct msgb *msg)
Definition: gprs_bssgp.c:1113
uint16_t bvci
Definition: gprs_bssgp.h:69
int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, uint16_t cid)
Definition: gprs_bssgp.c:319
uint8_t pdu_type
NS PDU type.
Definition: gsm_08_16.h:201