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