blob: 4eb9df418ace205a456673ef05b2cbd307a6b49d [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>
13
Harald Welteaf086782010-05-11 10:01:17 +020014/* gprs_bssgp_util.c */
Alexander Couzens85a8fd32020-07-18 15:57:07 +020015typedef int (*bssgp_bvc_send)(void *ctx, struct msgb *msg);
16
Harald Welteaf086782010-05-11 10:01:17 +020017extern struct gprs_ns_inst *bssgp_nsi;
Alexander Couzens85a8fd32020-07-18 15:57:07 +020018void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data);
Harald Welteaf086782010-05-11 10:01:17 +020019struct msgb *bssgp_msgb_alloc(void);
Jacob Erlbeckf78ec5c2015-11-17 09:53:23 +010020struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
Harald Welteaf086782010-05-11 10:01:17 +020021const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
Maxc0d9a6c2016-03-09 12:29:23 +010022const char *bssgp_pdu_str(enum bssgp_pdu_type pdu);
Daniel Willmann2d42b902020-09-26 09:11:05 +020023int 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 +020024/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
25int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
26 uint16_t bvci, uint16_t ns_bvci);
27/* Chapter 10.4.14: Status */
28int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
29
Harald Welte15a36432012-06-17 12:16:31 +080030enum bssgp_prim {
31 PRIM_BSSGP_DL_UD,
32 PRIM_BSSGP_UL_UD,
33 PRIM_BSSGP_PTM_UD,
34
35 PRIM_BSSGP_GMM_SUSPEND,
36 PRIM_BSSGP_GMM_RESUME,
37 PRIM_BSSGP_GMM_PAGING,
38
39 PRIM_NM_FLUSH_LL,
40 PRIM_NM_LLC_DISCARDED,
41 PRIM_NM_BVC_RESET,
42 PRIM_NM_BVC_BLOCK,
43 PRIM_NM_BVC_UNBLOCK,
Jacob Erlbeck36153dc2015-03-17 10:21:17 +010044 PRIM_NM_STATUS,
Harald Welte15a36432012-06-17 12:16:31 +080045};
46
47struct osmo_bssgp_prim {
48 struct osmo_prim_hdr oph;
49
50 /* common fields */
51 uint16_t nsei;
52 uint16_t bvci;
53 uint32_t tlli;
54 struct tlv_parsed *tp;
55 struct gprs_ra_id *ra_id;
56
57 /* specific fields */
58 union {
59 struct {
Holger Hans Peter Freytherd296f422012-08-03 09:59:20 +020060 uint8_t suspend_ref;
Harald Welte15a36432012-06-17 12:16:31 +080061 } resume;
62 } u;
63};
64
Harald Welteaf086782010-05-11 10:01:17 +020065/* gprs_bssgp.c */
66
Neels Hofmeyr87e45502017-06-20 00:17:59 +020067/*! BSSGP flow control (SGSN side) According to Section 8.2 */
Harald Welted11c0592012-09-06 21:57:11 +020068struct bssgp_flow_control {
Harald Weltebb826222012-09-07 10:22:01 +020069 uint32_t bucket_size_max; /*!< maximum size of the bucket (octets) */
70 uint32_t bucket_leak_rate; /*!< leak rate of the bucket (octets/sec) */
Harald Welted11c0592012-09-06 21:57:11 +020071
72 uint32_t bucket_counter; /*!< number of tokens in the bucket */
73 struct timeval time_last_pdu; /*!< timestamp of last PDU sent */
74
75 /* the built-in queue */
Harald Weltebb826222012-09-07 10:22:01 +020076 uint32_t max_queue_depth; /*!< how many packets to queue (mgs) */
77 uint32_t queue_depth; /*!< current length of queue (msgs) */
Harald Welted11c0592012-09-06 21:57:11 +020078 struct llist_head queue; /*!< linked list of msgb's */
79 struct osmo_timer_list timer; /*!< timer-based dequeueing */
80
81 /*! callback to be called at output of flow control */
82 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
83 uint32_t llc_pdu_len, void *priv);
84};
85
Harald Weltea78b9c22010-05-17 23:02:42 +020086#define BVC_S_BLOCKED 0x0001
87
88/* The per-BTS context that we keep on the SGSN side of the BSSGP link */
89struct bssgp_bvc_ctx {
90 struct llist_head list;
91
Harald Welteeb3ccf62011-11-25 08:15:42 +010092 struct gprs_ra_id ra_id; /*!< parsed RA ID of the remote BTS */
93 uint16_t cell_id; /*!< Cell ID of the remote BTS */
Harald Weltea78b9c22010-05-17 23:02:42 +020094
95 /* NSEI and BVCI of underlying Gb link. Together they
96 * uniquely identify a link to a BTS (5.4.4) */
97 uint16_t bvci;
98 uint16_t nsei;
99
100 uint32_t state;
101
102 struct rate_ctr_group *ctrg;
103
Harald Welted8b47692012-09-07 11:29:32 +0200104 struct bssgp_flow_control *fc;
Harald Weltebb826222012-09-07 10:22:01 +0200105 /*! default maximum size of per-MS bucket in octets */
Harald Welted11c0592012-09-06 21:57:11 +0200106 uint32_t bmax_default_ms;
Harald Weltebb826222012-09-07 10:22:01 +0200107 /*! default bucket leak rate of per-MS bucket in octests/s */
Harald Welted11c0592012-09-06 21:57:11 +0200108 uint32_t r_default_ms;
109
Harald Weltea78b9c22010-05-17 23:02:42 +0200110 /* we might want to add this as a shortcut later, avoiding the NSVC
111 * lookup for every packet, similar to a routing cache */
112 //struct gprs_nsvc *nsvc;
113};
114extern struct llist_head bssgp_bvc_ctxts;
Daniel Willmann07a923f2020-10-16 16:34:54 +0200115/* Create a BTS Context with BVCI+NSEI */
116struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei);
Harald Weltea78b9c22010-05-17 23:02:42 +0200117/* Find a BTS Context based on parsed RA ID and Cell ID */
118struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
119/* Find a BTS context based on BVCI+NSEI tuple */
120struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
Vadim Yanitskiy8eae2fc2019-11-09 01:45:11 +0700121/* Free a given BTS context */
122void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx);
Harald Weltea78b9c22010-05-17 23:02:42 +0200123
Harald Welte85fc3142011-11-25 08:58:40 +0100124#define BVC_F_BLOCKED 0x0001
125
126enum bssgp_ctr {
127 BSSGP_CTR_PKTS_IN,
128 BSSGP_CTR_PKTS_OUT,
129 BSSGP_CTR_BYTES_IN,
130 BSSGP_CTR_BYTES_OUT,
131 BSSGP_CTR_BLOCKED,
132 BSSGP_CTR_DISCARDED,
Jacob Erlbeck36153dc2015-03-17 10:21:17 +0100133 BSSGP_CTR_STATUS,
Harald Welte85fc3142011-11-25 08:58:40 +0100134};
135
136
Pablo Neira Ayusoff663232011-03-22 16:47:59 +0100137#include <osmocom/gsm/tlv.h>
Harald Welte605ac5d2012-06-16 16:09:52 +0800138#include <osmocom/gprs/gprs_msgb.h>
Harald Welte3771d092010-04-30 20:26:32 +0200139
Harald Welte61112342010-05-13 19:25:59 +0200140/* BSSGP-UL-UNITDATA.ind */
Harald Weltede4599c2012-06-17 13:04:02 +0800141int bssgp_rcvmsg(struct msgb *msg);
Harald Welte61112342010-05-13 19:25:59 +0200142
143/* BSSGP-DL-UNITDATA.req */
Harald Welte8ef54d12012-06-17 09:31:16 +0800144struct bssgp_lv {
145 uint16_t len;
146 uint8_t *v;
147};
148/* parameters for BSSGP downlink userdata transmission */
149struct bssgp_dl_ud_par {
150 uint32_t *tlli;
151 char *imsi;
Harald Welted11c0592012-09-06 21:57:11 +0200152 struct bssgp_flow_control *fc;
Harald Welte8ef54d12012-06-17 09:31:16 +0800153 uint16_t drx_parms;
154 /* FIXME: priority */
155 struct bssgp_lv ms_ra_cap;
156 uint8_t qos_profile[3];
157};
Harald Weltede4599c2012-06-17 13:04:02 +0800158int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
159 struct bssgp_dl_ud_par *dup);
Harald Welte61112342010-05-13 19:25:59 +0200160
Harald Weltea2ca4ed2010-05-02 11:54:55 +0200161uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
Harald Welte85fc3142011-11-25 08:58:40 +0100162int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
163 uint16_t cid);
Harald Welte9ba50052010-03-14 15:45:01 +0800164
Harald Welte3771d092010-04-30 20:26:32 +0200165/* Wrapper around TLV parser to parse BSSGP IEs */
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200166static inline int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len)
Harald Welte3771d092010-04-30 20:26:32 +0200167{
168 return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
169}
170
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200171/*! BSSGP Paging mode */
Harald Welte68b4f032010-06-09 16:22:28 +0200172enum bssgp_paging_mode {
173 BSSGP_PAGING_PS,
174 BSSGP_PAGING_CS,
175};
176
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200177/*! BSSGP Paging scope */
Harald Welte68b4f032010-06-09 16:22:28 +0200178enum bssgp_paging_scope {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100179 BSSGP_PAGING_BSS_AREA, /*!< all cells in BSS */
180 BSSGP_PAGING_LOCATION_AREA, /*!< all cells in LA */
181 BSSGP_PAGING_ROUTEING_AREA, /*!< all cells in RA */
182 BSSGP_PAGING_BVCI, /*!< one cell */
Harald Welte68b4f032010-06-09 16:22:28 +0200183};
184
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200185/*! BSSGP paging information */
Harald Welte68b4f032010-06-09 16:22:28 +0200186struct bssgp_paging_info {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100187 enum bssgp_paging_mode mode; /*!< CS or PS paging */
188 enum bssgp_paging_scope scope; /*!< bssgp_paging_scope */
189 struct gprs_ra_id raid; /*!< RA Identifier */
190 uint16_t bvci; /*!< BVCI */
Harald Welte85fc3142011-11-25 08:58:40 +0100191 char *imsi; /*!< IMSI, if any */
Harald Welteeb3ccf62011-11-25 08:15:42 +0100192 uint32_t *ptmsi; /*!< P-TMSI, if any */
193 uint16_t drx_params; /*!< DRX parameters */
194 uint8_t qos[3]; /*!< QoS parameters */
Harald Welte68b4f032010-06-09 16:22:28 +0200195};
196
197/* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
Harald Weltede4599c2012-06-17 13:04:02 +0800198int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
199 struct bssgp_paging_info *pinfo);
Harald Welte68b4f032010-06-09 16:22:28 +0200200
Harald Weltebb826222012-09-07 10:22:01 +0200201void bssgp_fc_init(struct bssgp_flow_control *fc,
202 uint32_t bucket_size_max, uint32_t bucket_leak_rate,
203 uint32_t max_queue_depth,
204 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
205 uint32_t llc_pdu_len, void *priv));
206
Harald Welted11c0592012-09-06 21:57:11 +0200207/* input function of the flow control implementation, called first
208 * for the MM flow control, and then as the MM flow control output
209 * callback in order to perform BVC flow control */
210int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
211 uint32_t llc_pdu_len, void *priv);
212
213/* Initialize the Flow Control parameters for a new MS according to
214 * default values for the BVC specified by BVCI and NSEI */
215int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
Harald Weltebb826222012-09-07 10:22:01 +0200216 uint16_t nsei, uint32_t max_queue_depth);
Harald Welted11c0592012-09-06 21:57:11 +0200217
Alexander Couzensacc0a072018-08-07 11:22:28 +0200218void bssgp_flush_all_queues();
219void bssgp_fc_flush_queue(struct bssgp_flow_control *fc);
220
Harald Weltefdc73882010-05-18 08:02:36 +0200221/* gprs_bssgp_vty.c */
Harald Weltede4599c2012-06-17 13:04:02 +0800222int bssgp_vty_init(void);
223void bssgp_set_log_ss(int ss);
Harald Weltefdc73882010-05-18 08:02:36 +0200224
Harald Welte15a36432012-06-17 12:16:31 +0800225int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);