libosmogb  1.4.1
Osmocom Gb library
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 
13 
14 /* gprs_bssgp_util.c */
15 typedef int (*bssgp_bvc_send)(void *ctx, struct msgb *msg);
16 
17 extern struct gprs_ns_inst *bssgp_nsi;
18 void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data);
19 struct msgb *bssgp_msgb_alloc(void);
20 struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
21 const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
22 const char *bssgp_pdu_str(enum bssgp_pdu_type pdu);
23 /* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
24 int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
25  uint16_t bvci, uint16_t ns_bvci);
26 /* Chapter 10.4.14: Status */
27 int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
28 
29 enum bssgp_prim {
33 
37 
44 };
45 
48 
49  /* common fields */
50  uint16_t nsei;
51  uint16_t bvci;
52  uint32_t tlli;
53  struct tlv_parsed *tp;
54  struct gprs_ra_id *ra_id;
55 
56  /* specific fields */
57  union {
58  struct {
59  uint8_t suspend_ref;
60  } resume;
61  } u;
62 };
63 
64 /* gprs_bssgp.c */
65 
68  uint32_t bucket_size_max;
69  uint32_t bucket_leak_rate;
71  uint32_t bucket_counter;
72  struct timeval time_last_pdu;
74  /* the built-in queue */
75  uint32_t max_queue_depth;
76  uint32_t queue_depth;
77  struct llist_head queue;
78  struct osmo_timer_list timer;
81  int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
82  uint32_t llc_pdu_len, void *priv);
83 };
84 
85 #define BVC_S_BLOCKED 0x0001
86 
87 /* The per-BTS context that we keep on the SGSN side of the BSSGP link */
88 struct bssgp_bvc_ctx {
89  struct llist_head list;
90 
91  struct gprs_ra_id ra_id;
92  uint16_t cell_id;
94  /* NSEI and BVCI of underlying Gb link. Together they
95  * uniquely identify a link to a BTS (5.4.4) */
96  uint16_t bvci;
97  uint16_t nsei;
98 
99  uint32_t state;
100 
102 
105  uint32_t bmax_default_ms;
107  uint32_t r_default_ms;
108 
109  /* we might want to add this as a shortcut later, avoiding the NSVC
110  * lookup for every packet, similar to a routing cache */
111  //struct gprs_nsvc *nsvc;
112 };
113 extern struct llist_head bssgp_bvc_ctxts;
114 /* Find a BTS Context based on parsed RA ID and Cell ID */
115 struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
116 /* Find a BTS context based on BVCI+NSEI tuple */
117 struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
118 /* Free a given BTS context */
119 void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx);
120 
121 #define BVC_F_BLOCKED 0x0001
122 
123 enum bssgp_ctr {
131 };
132 
133 
134 #include <osmocom/gsm/tlv.h>
135 #include <osmocom/gprs/gprs_msgb.h>
136 
137 /* BSSGP-UL-UNITDATA.ind */
138 int bssgp_rcvmsg(struct msgb *msg);
139 
140 /* BSSGP-DL-UNITDATA.req */
141 struct bssgp_lv {
142  uint16_t len;
143  uint8_t *v;
144 };
145 /* parameters for BSSGP downlink userdata transmission */
147  uint32_t *tlli;
148  char *imsi;
150  uint16_t drx_parms;
151  /* FIXME: priority */
152  struct bssgp_lv ms_ra_cap;
153  uint8_t qos_profile[3];
154 };
155 int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
156  struct bssgp_dl_ud_par *dup);
157 
158 uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
159 int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
160  uint16_t cid);
161 
162 /* Wrapper around TLV parser to parse BSSGP IEs */
163 static inline int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len)
164 {
165  return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
166 }
167 
172 };
173 
180 };
181 
185  enum bssgp_paging_scope scope;
186  struct gprs_ra_id raid;
187  uint16_t bvci;
188  char *imsi;
189  uint32_t *ptmsi;
190  uint16_t drx_params;
191  uint8_t qos[3];
192 };
193 
194 /* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
195 int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
196  struct bssgp_paging_info *pinfo);
197 
198 void bssgp_fc_init(struct bssgp_flow_control *fc,
199  uint32_t bucket_size_max, uint32_t bucket_leak_rate,
200  uint32_t max_queue_depth,
201  int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
202  uint32_t llc_pdu_len, void *priv));
203 
204 /* input function of the flow control implementation, called first
205  * for the MM flow control, and then as the MM flow control output
206  * callback in order to perform BVC flow control */
207 int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
208  uint32_t llc_pdu_len, void *priv);
209 
210 /* Initialize the Flow Control parameters for a new MS according to
211  * default values for the BVC specified by BVCI and NSEI */
212 int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
213  uint16_t nsei, uint32_t max_queue_depth);
214 
217 
218 /* gprs_bssgp_vty.c */
219 int bssgp_vty_init(void);
220 void bssgp_set_log_ss(int ss);
221 
222 int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
struct bssgp_flow_control * fc
Definition: gprs_bssgp.h:103
Definition: gprs_bssgp.h:128
Definition: gprs_bssgp.h:41
int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei, uint16_t bvci, uint16_t ns_bvci)
Definition: gprs_bssgp_util.c:199
int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, struct bssgp_paging_info *pinfo)
Definition: gprs_bssgp.c:1241
void bssgp_set_log_ss(int ss)
Definition: gprs_bssgp.c:1310
struct msgb * bssgp_msgb_copy(const struct msgb *msg, const char *name)
Definition: gprs_bssgp_util.c:168
char * imsi
IMSI, if any.
Definition: gprs_bssgp.h:188
uint8_t data[0]
variable-length payload
Definition: gsm_08_16.h:201
struct tlv_definition tvlv_att_def
struct osmo_prim_hdr oph
Definition: gprs_bssgp.h:47
BSSGP flow control (SGSN side) According to Section 8.2.
Definition: gprs_bssgp.h:67
uint32_t bucket_leak_rate
leak rate of the bucket (octets/sec)
Definition: gprs_bssgp.h:69
uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf)
Definition: gprs_bssgp.c:267
uint16_t len
Definition: gprs_bssgp.h:142
uint16_t drx_parms
Definition: gprs_bssgp.h:150
Definition: gprs_bssgp.h:36
struct bssgp_bvc_ctx * btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei)
Definition: gprs_bssgp.c:121
An instance of the NS protocol stack.
Definition: gprs_ns.h:79
all cells in RA
Definition: gprs_bssgp.h:178
uint16_t nsei
Definition: gprs_bssgp.h:50
uint32_t bucket_counter
number of tokens in the bucket
Definition: gprs_bssgp.h:71
uint32_t r_default_ms
default bucket leak rate of per-MS bucket in octests/s
Definition: gprs_bssgp.h:107
Definition: gprs_bssgp.h:141
one cell
Definition: gprs_bssgp.h:179
char * imsi
Definition: gprs_bssgp.h:148
Definition: gprs_bssgp.h:39
uint32_t bucket_size_max
maximum size of the bucket (octets)
Definition: gprs_bssgp.h:68
Definition: gprs_bssgp.h:42
Definition: gprs_bssgp.h:125
struct gprs_ra_id * ra_id
Definition: gprs_bssgp.h:54
Definition: gprs_bssgp.h:30
uint16_t cell_id
Cell ID of the remote BTS.
Definition: gprs_bssgp.h:92
uint16_t nsei
Identifiers of a BTS, equal to &#39;struct bssgp_bts_ctx&#39;.
Definition: gprs_msgb.h:81
struct bssgp_bvc_ctx * btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid)
Definition: gprs_bssgp.c:83
uint32_t tlli
Definition: gprs_bssgp.h:52
uint8_t * v
Definition: gprs_bssgp.h:143
uint32_t * ptmsi
P-TMSI, if any.
Definition: gprs_bssgp.h:189
int(* bssgp_bvc_send)(void *ctx, struct msgb *msg)
Definition: gprs_bssgp.h:15
Definition: gprs_bssgp.h:129
void bssgp_flush_all_queues()
Flush the queues of all BSSGP contexts.
Definition: gprs_bssgp.c:1333
Definition: gprs_bssgp.h:171
gprs_bssgp_cause
Cause coding (Section 11.3.8 / Table 11.10)
Definition: gsm_08_18.h:122
uint16_t bvci
Definition: gprs_msgb.h:82
int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, uint32_t llc_pdu_len, void *priv)
Definition: gprs_bssgp.c:771
struct msgb * bssgp_msgb_alloc(void)
Definition: gprs_bssgp_util.c:157
Definition: gprs_bssgp.h:35
struct osmo_bssgp_prim::@0::@1 resume
Definition: gprs_bssgp.h:170
void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data)
Definition: gprs_bssgp.c:132
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:816
Definition: gprs_bssgp.h:127
struct tlv_parsed * tp
Definition: gprs_bssgp.h:53
uint32_t * tlli
Definition: gprs_bssgp.h:147
struct llist_head bssgp_bvc_ctxts
Definition: gprs_bssgp.h:40
Definition: gprs_bssgp.h:34
Definition: gprs_bssgp.h:32
Definition: gprs_bssgp.h:46
BSSGP paging information.
Definition: gprs_bssgp.h:183
uint8_t mode
uint16_t nsei
Definition: gprs_bssgp.h:97
uint32_t queue_depth
current length of queue (msgs)
Definition: gprs_bssgp.h:76
uint8_t qos_profile[3]
QoS profile.
Definition: gsm_08_18.h:206
all cells in LA
Definition: gprs_bssgp.h:177
uint8_t msg[0]
uint32_t max_queue_depth
how many packets to queue (mgs)
Definition: gprs_bssgp.h:75
uint8_t suspend_ref
Definition: gprs_bssgp.h:59
uint32_t bmax_default_ms
default maximum size of per-MS bucket in octets
Definition: gprs_bssgp.h:105
struct bssgp_flow_control * fc
Definition: gprs_bssgp.h:149
uint32_t state
Definition: gprs_bssgp.h:99
bssgp_paging_scope
BSSGP Paging scope.
Definition: gprs_bssgp.h:175
static int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len)
Definition: gprs_bssgp.h:163
Definition: gprs_bssgp.h:124
Definition: gprs_bssgp.h:31
all cells in BSS
Definition: gprs_bssgp.h:176
Definition: gprs_bssgp.h:43
void bssgp_fc_flush_queue(struct bssgp_flow_control *fc)
Flush the queue of the bssgp_flow_control.
Definition: gprs_bssgp.c:1319
void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx)
Definition: gprs_bssgp.c:162
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:187
struct rate_ctr_group * ctrg
Definition: gprs_bssgp.h:101
int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, struct bssgp_dl_ud_par *dup)
Definition: gprs_bssgp.c:1136
bssgp_prim
Definition: gprs_bssgp.h:29
const char * bssgp_cause_str(enum gprs_bssgp_cause cause)
Definition: gprs_bssgp_util.c:147
Definition: gprs_bssgp.h:38
bssgp_pdu_type
BSSGP PDU types (Section 11.3.26 / Table 11.27)
Definition: gsm_08_18.h:12
int bssgp_vty_init(void)
Definition: gprs_bssgp_vty.c:208
uint16_t drx_params
DRX parameters.
Definition: gprs_bssgp.h:190
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:130
uint16_t bvci
Definition: gprs_bssgp.h:96
Definition: gprs_bssgp.h:126
bssgp_ctr
Definition: gprs_bssgp.h:123
int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
Definition: gprs_bssgp_util.c:218
bssgp_paging_mode
BSSGP Paging mode.
Definition: gprs_bssgp.h:169
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:800
struct gprs_ns_inst * bssgp_nsi
Definition: gprs_bssgp_util.c:38
const char * bssgp_pdu_str(enum bssgp_pdu_type pdu)
Definition: gprs_bssgp_util.c:152
Definition: gprs_bssgp.h:146
Definition: gprs_bssgp.h:88
int bssgp_rcvmsg(struct msgb *msg)
Definition: gprs_bssgp.c:1061
uint16_t bvci
Definition: gprs_bssgp.h:51
int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, uint16_t cid)
Definition: gprs_bssgp.c:275
uint8_t pdu_type
NS PDU type.
Definition: gsm_08_16.h:200