blob: 707704492798d06c82907a696c5b3e2f207772fe [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gprs_bssgp.h */
2
Sylvain Munaut12ba7782014-06-16 10:13:40 +02003#pragma once
Harald Welte9ba50052010-03-14 15:45:01 +08004
Harald Welte8f9a3ee2010-05-02 11:26:34 +02005#include <stdint.h>
Harald Welted11c0592012-09-06 21:57:11 +02006#include <osmocom/core/timer.h>
7#include <osmocom/core/linuxlist.h>
Harald Welte8f9a3ee2010-05-02 11:26:34 +02008
Harald Welte73952e32012-06-16 14:59:56 +08009#include <osmocom/gsm/gsm48.h>
Harald Welte15a36432012-06-17 12:16:31 +080010#include <osmocom/gsm/prim.h>
Harald Welte73952e32012-06-16 14:59:56 +080011
Harald Welte8648e492012-06-17 13:12:51 +080012#include <osmocom/gprs/protocol/gsm_08_18.h>
Philipp Maierbd10c212020-12-14 22:28:19 +010013#include <osmocom/gprs/protocol/gsm_24_301.h>
Harald Welte8648e492012-06-17 13:12:51 +080014
Harald Welteaf086782010-05-11 10:01:17 +020015/* gprs_bssgp_util.c */
Alexander Couzens85a8fd32020-07-18 15:57:07 +020016
Harald Welte8f825282020-12-04 18:50:11 +010017#define BSSGP_PDUF_UL 0x0001 /* PDU may occur in uplink */
18#define BSSGP_PDUF_DL 0x0002 /* PDU may occur in downlink */
19#define BSSGP_PDUF_SIG 0x0004 /* PDU may occur on Signaling BVC */
20#define BSSGP_PDUF_PTP 0x0008 /* PDU may occur on PTP BVC */
21#define BSSGP_PDUF_PTM 0x0010 /* PDU may occur on PTM BVC */
22
23extern const struct osmo_tlv_prot_def osmo_pdef_bssgp;
24
25/*! return the PDU type flags (UL/DL/SIG/PTP/PTM) of specified PDU type */
26static inline uint32_t bssgp_pdu_type_flags(uint8_t pdu_type) {
27 return osmo_tlv_prot_msgt_flags(&osmo_pdef_bssgp, pdu_type);
28}
29
30typedef int (*bssgp_bvc_send)(void *ctx, struct msgb *msg);
Harald Welteaf086782010-05-11 10:01:17 +020031extern struct gprs_ns_inst *bssgp_nsi;
Alexander Couzens85a8fd32020-07-18 15:57:07 +020032void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data);
Harald Welteaf086782010-05-11 10:01:17 +020033struct msgb *bssgp_msgb_alloc(void);
Jacob Erlbeckf78ec5c2015-11-17 09:53:23 +010034struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
Harald Welteaf086782010-05-11 10:01:17 +020035const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
Maxc0d9a6c2016-03-09 12:29:23 +010036const char *bssgp_pdu_str(enum bssgp_pdu_type pdu);
Daniel Willmann2d42b902020-09-26 09:11:05 +020037int 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);
Harald Welteaf086782010-05-11 10:01:17 +020038/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
39int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
40 uint16_t bvci, uint16_t ns_bvci);
41/* Chapter 10.4.14: Status */
42int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
43
Harald Welte15a36432012-06-17 12:16:31 +080044enum bssgp_prim {
45 PRIM_BSSGP_DL_UD,
46 PRIM_BSSGP_UL_UD,
47 PRIM_BSSGP_PTM_UD,
48
49 PRIM_BSSGP_GMM_SUSPEND,
50 PRIM_BSSGP_GMM_RESUME,
51 PRIM_BSSGP_GMM_PAGING,
52
53 PRIM_NM_FLUSH_LL,
54 PRIM_NM_LLC_DISCARDED,
55 PRIM_NM_BVC_RESET,
56 PRIM_NM_BVC_BLOCK,
57 PRIM_NM_BVC_UNBLOCK,
Jacob Erlbeck36153dc2015-03-17 10:21:17 +010058 PRIM_NM_STATUS,
Harald Welte15a36432012-06-17 12:16:31 +080059};
60
61struct osmo_bssgp_prim {
62 struct osmo_prim_hdr oph;
63
64 /* common fields */
65 uint16_t nsei;
66 uint16_t bvci;
67 uint32_t tlli;
68 struct tlv_parsed *tp;
69 struct gprs_ra_id *ra_id;
70
71 /* specific fields */
72 union {
73 struct {
Holger Hans Peter Freytherd296f422012-08-03 09:59:20 +020074 uint8_t suspend_ref;
Harald Welte15a36432012-06-17 12:16:31 +080075 } resume;
76 } u;
77};
78
Harald Welteaf086782010-05-11 10:01:17 +020079/* gprs_bssgp.c */
80
Neels Hofmeyr87e45502017-06-20 00:17:59 +020081/*! BSSGP flow control (SGSN side) According to Section 8.2 */
Harald Welted11c0592012-09-06 21:57:11 +020082struct bssgp_flow_control {
Harald Weltebb826222012-09-07 10:22:01 +020083 uint32_t bucket_size_max; /*!< maximum size of the bucket (octets) */
84 uint32_t bucket_leak_rate; /*!< leak rate of the bucket (octets/sec) */
Harald Welted11c0592012-09-06 21:57:11 +020085
86 uint32_t bucket_counter; /*!< number of tokens in the bucket */
87 struct timeval time_last_pdu; /*!< timestamp of last PDU sent */
88
89 /* the built-in queue */
Harald Weltebb826222012-09-07 10:22:01 +020090 uint32_t max_queue_depth; /*!< how many packets to queue (mgs) */
91 uint32_t queue_depth; /*!< current length of queue (msgs) */
Harald Welted11c0592012-09-06 21:57:11 +020092 struct llist_head queue; /*!< linked list of msgb's */
93 struct osmo_timer_list timer; /*!< timer-based dequeueing */
94
95 /*! callback to be called at output of flow control */
96 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
97 uint32_t llc_pdu_len, void *priv);
98};
99
Harald Weltea78b9c22010-05-17 23:02:42 +0200100#define BVC_S_BLOCKED 0x0001
101
102/* The per-BTS context that we keep on the SGSN side of the BSSGP link */
103struct bssgp_bvc_ctx {
104 struct llist_head list;
105
Harald Welteeb3ccf62011-11-25 08:15:42 +0100106 struct gprs_ra_id ra_id; /*!< parsed RA ID of the remote BTS */
107 uint16_t cell_id; /*!< Cell ID of the remote BTS */
Harald Weltea78b9c22010-05-17 23:02:42 +0200108
109 /* NSEI and BVCI of underlying Gb link. Together they
110 * uniquely identify a link to a BTS (5.4.4) */
111 uint16_t bvci;
112 uint16_t nsei;
113
114 uint32_t state;
115
116 struct rate_ctr_group *ctrg;
117
Harald Welted8b47692012-09-07 11:29:32 +0200118 struct bssgp_flow_control *fc;
Harald Weltebb826222012-09-07 10:22:01 +0200119 /*! default maximum size of per-MS bucket in octets */
Harald Welted11c0592012-09-06 21:57:11 +0200120 uint32_t bmax_default_ms;
Harald Weltebb826222012-09-07 10:22:01 +0200121 /*! default bucket leak rate of per-MS bucket in octests/s */
Harald Welted11c0592012-09-06 21:57:11 +0200122 uint32_t r_default_ms;
123
Harald Weltea78b9c22010-05-17 23:02:42 +0200124 /* we might want to add this as a shortcut later, avoiding the NSVC
125 * lookup for every packet, similar to a routing cache */
126 //struct gprs_nsvc *nsvc;
127};
128extern struct llist_head bssgp_bvc_ctxts;
Daniel Willmann07a923f2020-10-16 16:34:54 +0200129/* Create a BTS Context with BVCI+NSEI */
130struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei);
Harald Weltea78b9c22010-05-17 23:02:42 +0200131/* Find a BTS Context based on parsed RA ID and Cell ID */
132struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
133/* Find a BTS context based on BVCI+NSEI tuple */
134struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
Vadim Yanitskiy8eae2fc2019-11-09 01:45:11 +0700135/* Free a given BTS context */
136void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx);
Harald Weltea78b9c22010-05-17 23:02:42 +0200137
Harald Welte85fc3142011-11-25 08:58:40 +0100138#define BVC_F_BLOCKED 0x0001
139
140enum bssgp_ctr {
141 BSSGP_CTR_PKTS_IN,
142 BSSGP_CTR_PKTS_OUT,
143 BSSGP_CTR_BYTES_IN,
144 BSSGP_CTR_BYTES_OUT,
145 BSSGP_CTR_BLOCKED,
146 BSSGP_CTR_DISCARDED,
Jacob Erlbeck36153dc2015-03-17 10:21:17 +0100147 BSSGP_CTR_STATUS,
Harald Welte85fc3142011-11-25 08:58:40 +0100148};
149
150
Pablo Neira Ayusoff663232011-03-22 16:47:59 +0100151#include <osmocom/gsm/tlv.h>
Harald Welte605ac5d2012-06-16 16:09:52 +0800152#include <osmocom/gprs/gprs_msgb.h>
Harald Welte3771d092010-04-30 20:26:32 +0200153
Harald Welte61112342010-05-13 19:25:59 +0200154/* BSSGP-UL-UNITDATA.ind */
Harald Weltede4599c2012-06-17 13:04:02 +0800155int bssgp_rcvmsg(struct msgb *msg);
Harald Welte61112342010-05-13 19:25:59 +0200156
157/* BSSGP-DL-UNITDATA.req */
Harald Welte8ef54d12012-06-17 09:31:16 +0800158struct bssgp_lv {
159 uint16_t len;
160 uint8_t *v;
161};
162/* parameters for BSSGP downlink userdata transmission */
163struct bssgp_dl_ud_par {
164 uint32_t *tlli;
165 char *imsi;
Harald Welted11c0592012-09-06 21:57:11 +0200166 struct bssgp_flow_control *fc;
Harald Welte8ef54d12012-06-17 09:31:16 +0800167 uint16_t drx_parms;
168 /* FIXME: priority */
169 struct bssgp_lv ms_ra_cap;
170 uint8_t qos_profile[3];
171};
Harald Weltede4599c2012-06-17 13:04:02 +0800172int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
173 struct bssgp_dl_ud_par *dup);
Harald Welte61112342010-05-13 19:25:59 +0200174
Harald Weltea2ca4ed2010-05-02 11:54:55 +0200175uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
Harald Welte85fc3142011-11-25 08:58:40 +0100176int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
177 uint16_t cid);
Harald Welte9ba50052010-03-14 15:45:01 +0800178
Philipp Maierbd10c212020-12-14 22:28:19 +0100179enum bssgp_rim_routing_info_discr {
180 BSSGP_RIM_ROUTING_INFO_GERAN,
181 BSSGP_RIM_ROUTING_INFO_UTRAN,
182 BSSGP_RIM_ROUTING_INFO_EUTRAN,
183};
184
185/*! BSSGP RIM Routing information, see also 3GPP TS 48.018, section 11.3.70 */
186struct bssgp_rim_routing_info {
187 enum bssgp_rim_routing_info_discr discr;
188 union {
189 struct {
190 struct gprs_ra_id raid;
191 uint16_t cid;
192 } geran;
193 struct {
194 struct gprs_ra_id raid;
195 uint16_t rncid;
196 } utran;
197 struct {
198 struct osmo_eutran_tai tai;
199 /* See also 3GPP TS 36.413 9.2.1.37 and 3GPP TS 36.401 */
200 uint8_t global_enb_id[8];
201 uint8_t global_enb_id_len;
202 } eutran;
203 };
204};
205
206int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf,
207 unsigned int len);
208int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
209
Harald Welte3771d092010-04-30 20:26:32 +0200210/* Wrapper around TLV parser to parse BSSGP IEs */
Harald Welte465c9a52020-11-18 11:52:14 +0100211static inline int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
Harald Welte3771d092010-04-30 20:26:32 +0200212{
213 return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
214}
215
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200216/*! BSSGP Paging mode */
Harald Welte68b4f032010-06-09 16:22:28 +0200217enum bssgp_paging_mode {
218 BSSGP_PAGING_PS,
219 BSSGP_PAGING_CS,
220};
221
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200222/*! BSSGP Paging scope */
Harald Welte68b4f032010-06-09 16:22:28 +0200223enum bssgp_paging_scope {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100224 BSSGP_PAGING_BSS_AREA, /*!< all cells in BSS */
225 BSSGP_PAGING_LOCATION_AREA, /*!< all cells in LA */
226 BSSGP_PAGING_ROUTEING_AREA, /*!< all cells in RA */
227 BSSGP_PAGING_BVCI, /*!< one cell */
Harald Welte68b4f032010-06-09 16:22:28 +0200228};
229
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200230/*! BSSGP paging information */
Harald Welte68b4f032010-06-09 16:22:28 +0200231struct bssgp_paging_info {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100232 enum bssgp_paging_mode mode; /*!< CS or PS paging */
233 enum bssgp_paging_scope scope; /*!< bssgp_paging_scope */
234 struct gprs_ra_id raid; /*!< RA Identifier */
235 uint16_t bvci; /*!< BVCI */
Harald Welte85fc3142011-11-25 08:58:40 +0100236 char *imsi; /*!< IMSI, if any */
Harald Welteeb3ccf62011-11-25 08:15:42 +0100237 uint32_t *ptmsi; /*!< P-TMSI, if any */
238 uint16_t drx_params; /*!< DRX parameters */
239 uint8_t qos[3]; /*!< QoS parameters */
Harald Welte68b4f032010-06-09 16:22:28 +0200240};
241
242/* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
Harald Weltede4599c2012-06-17 13:04:02 +0800243int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
244 struct bssgp_paging_info *pinfo);
Harald Welte68b4f032010-06-09 16:22:28 +0200245
Harald Weltebb826222012-09-07 10:22:01 +0200246void bssgp_fc_init(struct bssgp_flow_control *fc,
247 uint32_t bucket_size_max, uint32_t bucket_leak_rate,
248 uint32_t max_queue_depth,
249 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
250 uint32_t llc_pdu_len, void *priv));
251
Harald Welted11c0592012-09-06 21:57:11 +0200252/* input function of the flow control implementation, called first
253 * for the MM flow control, and then as the MM flow control output
254 * callback in order to perform BVC flow control */
255int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
256 uint32_t llc_pdu_len, void *priv);
257
258/* Initialize the Flow Control parameters for a new MS according to
259 * default values for the BVC specified by BVCI and NSEI */
260int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
Harald Weltebb826222012-09-07 10:22:01 +0200261 uint16_t nsei, uint32_t max_queue_depth);
Harald Welted11c0592012-09-06 21:57:11 +0200262
Alexander Couzensacc0a072018-08-07 11:22:28 +0200263void bssgp_flush_all_queues();
264void bssgp_fc_flush_queue(struct bssgp_flow_control *fc);
265
Harald Weltefdc73882010-05-18 08:02:36 +0200266/* gprs_bssgp_vty.c */
Harald Weltede4599c2012-06-17 13:04:02 +0800267int bssgp_vty_init(void);
Harald Weltefde19ed2020-12-07 21:43:51 +0100268void bssgp_set_log_ss(int ss) OSMO_DEPRECATED("Use DLBSSGP instead!\n");
Harald Weltefdc73882010-05-18 08:02:36 +0200269
Harald Welte15a36432012-06-17 12:16:31 +0800270int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);