blob: c0b3f65696cb8afe9457f98eb2a93a76e1327086 [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welte9ba50052010-03-14 15:45:01 +08002
Harald Welte8f9a3ee2010-05-02 11:26:34 +02003#include <stdint.h>
Harald Welted11c0592012-09-06 21:57:11 +02004#include <osmocom/core/timer.h>
5#include <osmocom/core/linuxlist.h>
Harald Welte8f9a3ee2010-05-02 11:26:34 +02006
Harald Welte73952e32012-06-16 14:59:56 +08007#include <osmocom/gsm/gsm48.h>
Harald Welte15a36432012-06-17 12:16:31 +08008#include <osmocom/gsm/prim.h>
Harald Welte73952e32012-06-16 14:59:56 +08009
Harald Welte8648e492012-06-17 13:12:51 +080010#include <osmocom/gprs/protocol/gsm_08_18.h>
11
Harald Welteaf086782010-05-11 10:01:17 +020012/* gprs_bssgp_util.c */
13extern struct gprs_ns_inst *bssgp_nsi;
14struct msgb *bssgp_msgb_alloc(void);
Jacob Erlbeckf78ec5c2015-11-17 09:53:23 +010015struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
Harald Welteaf086782010-05-11 10:01:17 +020016const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
17/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
18int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
19 uint16_t bvci, uint16_t ns_bvci);
20/* Chapter 10.4.14: Status */
21int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
22
Harald Welte15a36432012-06-17 12:16:31 +080023enum bssgp_prim {
24 PRIM_BSSGP_DL_UD,
25 PRIM_BSSGP_UL_UD,
26 PRIM_BSSGP_PTM_UD,
27
28 PRIM_BSSGP_GMM_SUSPEND,
29 PRIM_BSSGP_GMM_RESUME,
30 PRIM_BSSGP_GMM_PAGING,
31
32 PRIM_NM_FLUSH_LL,
33 PRIM_NM_LLC_DISCARDED,
34 PRIM_NM_BVC_RESET,
35 PRIM_NM_BVC_BLOCK,
36 PRIM_NM_BVC_UNBLOCK,
Jacob Erlbeck36153dc2015-03-17 10:21:17 +010037 PRIM_NM_STATUS,
Harald Welte15a36432012-06-17 12:16:31 +080038};
39
40struct osmo_bssgp_prim {
41 struct osmo_prim_hdr oph;
42
43 /* common fields */
44 uint16_t nsei;
45 uint16_t bvci;
46 uint32_t tlli;
47 struct tlv_parsed *tp;
48 struct gprs_ra_id *ra_id;
49
50 /* specific fields */
51 union {
52 struct {
Holger Hans Peter Freytherd296f422012-08-03 09:59:20 +020053 uint8_t suspend_ref;
Harald Welte15a36432012-06-17 12:16:31 +080054 } resume;
55 } u;
56};
57
Harald Welteaf086782010-05-11 10:01:17 +020058/* gprs_bssgp.c */
59
Harald Welted11c0592012-09-06 21:57:11 +020060/*! \brief BSSGP flow control (SGSN side) According to Section 8.2 */
61struct bssgp_flow_control {
Harald Weltebb826222012-09-07 10:22:01 +020062 uint32_t bucket_size_max; /*!< maximum size of the bucket (octets) */
63 uint32_t bucket_leak_rate; /*!< leak rate of the bucket (octets/sec) */
Harald Welted11c0592012-09-06 21:57:11 +020064
65 uint32_t bucket_counter; /*!< number of tokens in the bucket */
66 struct timeval time_last_pdu; /*!< timestamp of last PDU sent */
67
68 /* the built-in queue */
Harald Weltebb826222012-09-07 10:22:01 +020069 uint32_t max_queue_depth; /*!< how many packets to queue (mgs) */
70 uint32_t queue_depth; /*!< current length of queue (msgs) */
Harald Welted11c0592012-09-06 21:57:11 +020071 struct llist_head queue; /*!< linked list of msgb's */
72 struct osmo_timer_list timer; /*!< timer-based dequeueing */
73
74 /*! callback to be called at output of flow control */
75 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
76 uint32_t llc_pdu_len, void *priv);
77};
78
Harald Weltea78b9c22010-05-17 23:02:42 +020079#define BVC_S_BLOCKED 0x0001
80
81/* The per-BTS context that we keep on the SGSN side of the BSSGP link */
82struct bssgp_bvc_ctx {
83 struct llist_head list;
84
Harald Welteeb3ccf62011-11-25 08:15:42 +010085 struct gprs_ra_id ra_id; /*!< parsed RA ID of the remote BTS */
86 uint16_t cell_id; /*!< Cell ID of the remote BTS */
Harald Weltea78b9c22010-05-17 23:02:42 +020087
88 /* NSEI and BVCI of underlying Gb link. Together they
89 * uniquely identify a link to a BTS (5.4.4) */
90 uint16_t bvci;
91 uint16_t nsei;
92
93 uint32_t state;
94
95 struct rate_ctr_group *ctrg;
96
Harald Welted8b47692012-09-07 11:29:32 +020097 struct bssgp_flow_control *fc;
Harald Weltebb826222012-09-07 10:22:01 +020098 /*! default maximum size of per-MS bucket in octets */
Harald Welted11c0592012-09-06 21:57:11 +020099 uint32_t bmax_default_ms;
Harald Weltebb826222012-09-07 10:22:01 +0200100 /*! default bucket leak rate of per-MS bucket in octests/s */
Harald Welted11c0592012-09-06 21:57:11 +0200101 uint32_t r_default_ms;
102
Harald Weltea78b9c22010-05-17 23:02:42 +0200103 /* we might want to add this as a shortcut later, avoiding the NSVC
104 * lookup for every packet, similar to a routing cache */
105 //struct gprs_nsvc *nsvc;
106};
107extern struct llist_head bssgp_bvc_ctxts;
108/* Find a BTS Context based on parsed RA ID and Cell ID */
109struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
110/* Find a BTS context based on BVCI+NSEI tuple */
111struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
112
Harald Welte85fc3142011-11-25 08:58:40 +0100113#define BVC_F_BLOCKED 0x0001
114
115enum bssgp_ctr {
116 BSSGP_CTR_PKTS_IN,
117 BSSGP_CTR_PKTS_OUT,
118 BSSGP_CTR_BYTES_IN,
119 BSSGP_CTR_BYTES_OUT,
120 BSSGP_CTR_BLOCKED,
121 BSSGP_CTR_DISCARDED,
Jacob Erlbeck36153dc2015-03-17 10:21:17 +0100122 BSSGP_CTR_STATUS,
Harald Welte85fc3142011-11-25 08:58:40 +0100123};
124
125
Pablo Neira Ayusoff663232011-03-22 16:47:59 +0100126#include <osmocom/gsm/tlv.h>
Harald Welte605ac5d2012-06-16 16:09:52 +0800127#include <osmocom/gprs/gprs_msgb.h>
Harald Welte3771d092010-04-30 20:26:32 +0200128
Harald Welte61112342010-05-13 19:25:59 +0200129/* BSSGP-UL-UNITDATA.ind */
Harald Weltede4599c2012-06-17 13:04:02 +0800130int bssgp_rcvmsg(struct msgb *msg);
Harald Welte61112342010-05-13 19:25:59 +0200131
132/* BSSGP-DL-UNITDATA.req */
Harald Welte8ef54d12012-06-17 09:31:16 +0800133struct bssgp_lv {
134 uint16_t len;
135 uint8_t *v;
136};
137/* parameters for BSSGP downlink userdata transmission */
138struct bssgp_dl_ud_par {
139 uint32_t *tlli;
140 char *imsi;
Harald Welted11c0592012-09-06 21:57:11 +0200141 struct bssgp_flow_control *fc;
Harald Welte8ef54d12012-06-17 09:31:16 +0800142 uint16_t drx_parms;
143 /* FIXME: priority */
144 struct bssgp_lv ms_ra_cap;
145 uint8_t qos_profile[3];
146};
Harald Weltede4599c2012-06-17 13:04:02 +0800147int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
148 struct bssgp_dl_ud_par *dup);
Harald Welte61112342010-05-13 19:25:59 +0200149
Harald Weltea2ca4ed2010-05-02 11:54:55 +0200150uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
Harald Welte85fc3142011-11-25 08:58:40 +0100151int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
152 uint16_t cid);
Harald Welte9ba50052010-03-14 15:45:01 +0800153
Harald Welte3771d092010-04-30 20:26:32 +0200154/* Wrapper around TLV parser to parse BSSGP IEs */
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200155static inline int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len)
Harald Welte3771d092010-04-30 20:26:32 +0200156{
157 return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
158}
159
Harald Welteeb3ccf62011-11-25 08:15:42 +0100160/*! \brief BSSGP Paging mode */
Harald Welte68b4f032010-06-09 16:22:28 +0200161enum bssgp_paging_mode {
162 BSSGP_PAGING_PS,
163 BSSGP_PAGING_CS,
164};
165
Harald Welteeb3ccf62011-11-25 08:15:42 +0100166/*! \brief BSSGP Paging scope */
Harald Welte68b4f032010-06-09 16:22:28 +0200167enum bssgp_paging_scope {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100168 BSSGP_PAGING_BSS_AREA, /*!< all cells in BSS */
169 BSSGP_PAGING_LOCATION_AREA, /*!< all cells in LA */
170 BSSGP_PAGING_ROUTEING_AREA, /*!< all cells in RA */
171 BSSGP_PAGING_BVCI, /*!< one cell */
Harald Welte68b4f032010-06-09 16:22:28 +0200172};
173
Harald Welteeb3ccf62011-11-25 08:15:42 +0100174/*! \brief BSSGP paging information */
Harald Welte68b4f032010-06-09 16:22:28 +0200175struct bssgp_paging_info {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100176 enum bssgp_paging_mode mode; /*!< CS or PS paging */
177 enum bssgp_paging_scope scope; /*!< bssgp_paging_scope */
178 struct gprs_ra_id raid; /*!< RA Identifier */
179 uint16_t bvci; /*!< BVCI */
Harald Welte85fc3142011-11-25 08:58:40 +0100180 char *imsi; /*!< IMSI, if any */
Harald Welteeb3ccf62011-11-25 08:15:42 +0100181 uint32_t *ptmsi; /*!< P-TMSI, if any */
182 uint16_t drx_params; /*!< DRX parameters */
183 uint8_t qos[3]; /*!< QoS parameters */
Harald Welte68b4f032010-06-09 16:22:28 +0200184};
185
186/* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
Harald Weltede4599c2012-06-17 13:04:02 +0800187int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
188 struct bssgp_paging_info *pinfo);
Harald Welte68b4f032010-06-09 16:22:28 +0200189
Harald Weltebb826222012-09-07 10:22:01 +0200190void bssgp_fc_init(struct bssgp_flow_control *fc,
191 uint32_t bucket_size_max, uint32_t bucket_leak_rate,
192 uint32_t max_queue_depth,
193 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
194 uint32_t llc_pdu_len, void *priv));
195
Harald Welted11c0592012-09-06 21:57:11 +0200196/* input function of the flow control implementation, called first
197 * for the MM flow control, and then as the MM flow control output
198 * callback in order to perform BVC flow control */
199int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
200 uint32_t llc_pdu_len, void *priv);
201
202/* Initialize the Flow Control parameters for a new MS according to
203 * default values for the BVC specified by BVCI and NSEI */
204int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
Harald Weltebb826222012-09-07 10:22:01 +0200205 uint16_t nsei, uint32_t max_queue_depth);
Harald Welted11c0592012-09-06 21:57:11 +0200206
Harald Weltefdc73882010-05-18 08:02:36 +0200207/* gprs_bssgp_vty.c */
Harald Weltede4599c2012-06-17 13:04:02 +0800208int bssgp_vty_init(void);
209void bssgp_set_log_ss(int ss);
Harald Weltefdc73882010-05-18 08:02:36 +0200210
Harald Welte15a36432012-06-17 12:16:31 +0800211int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);