blob: 0646ff79eabb4dda90c846a7bad3376a948b1b9e [file] [log] [blame]
Harald Welte9ba50052010-03-14 15:45:01 +08001#ifndef _GPRS_BSSGP_H
2#define _GPRS_BSSGP_H
3
Harald Welte8f9a3ee2010-05-02 11:26:34 +02004#include <stdint.h>
Harald Welted11c0592012-09-06 21:57:11 +02005#include <osmocom/core/timer.h>
6#include <osmocom/core/linuxlist.h>
Harald Welte8f9a3ee2010-05-02 11:26:34 +02007
Harald Welte73952e32012-06-16 14:59:56 +08008#include <osmocom/gsm/gsm48.h>
Harald Welte15a36432012-06-17 12:16:31 +08009#include <osmocom/gsm/prim.h>
Harald Welte73952e32012-06-16 14:59:56 +080010
Harald Welte8648e492012-06-17 13:12:51 +080011#include <osmocom/gprs/protocol/gsm_08_18.h>
12
Harald Welteaf086782010-05-11 10:01:17 +020013/* gprs_bssgp_util.c */
14extern struct gprs_ns_inst *bssgp_nsi;
15struct msgb *bssgp_msgb_alloc(void);
16const 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,
37};
38
39struct osmo_bssgp_prim {
40 struct osmo_prim_hdr oph;
41
42 /* common fields */
43 uint16_t nsei;
44 uint16_t bvci;
45 uint32_t tlli;
46 struct tlv_parsed *tp;
47 struct gprs_ra_id *ra_id;
48
49 /* specific fields */
50 union {
51 struct {
Holger Hans Peter Freytherd296f422012-08-03 09:59:20 +020052 uint8_t suspend_ref;
Harald Welte15a36432012-06-17 12:16:31 +080053 } resume;
54 } u;
55};
56
Harald Welteaf086782010-05-11 10:01:17 +020057/* gprs_bssgp.c */
58
Harald Welted11c0592012-09-06 21:57:11 +020059/*! \brief BSSGP flow control (SGSN side) According to Section 8.2 */
60struct bssgp_flow_control {
61 uint32_t bucket_size_max; /*!< maximum size of the bucket */
62 uint32_t bucket_leak_rate; /*!< leak rate of the bucket */
63
64 uint32_t bucket_counter; /*!< number of tokens in the bucket */
65 struct timeval time_last_pdu; /*!< timestamp of last PDU sent */
66
67 /* the built-in queue */
68 uint32_t max_queue_depth; /*!< how many packets to queue */
69 uint32_t queue_depth; /*!< current length of queue */
70 struct llist_head queue; /*!< linked list of msgb's */
71 struct osmo_timer_list timer; /*!< timer-based dequeueing */
72
73 /*! callback to be called at output of flow control */
74 int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg,
75 uint32_t llc_pdu_len, void *priv);
76};
77
Harald Weltea78b9c22010-05-17 23:02:42 +020078#define BVC_S_BLOCKED 0x0001
79
80/* The per-BTS context that we keep on the SGSN side of the BSSGP link */
81struct bssgp_bvc_ctx {
82 struct llist_head list;
83
Harald Welteeb3ccf62011-11-25 08:15:42 +010084 struct gprs_ra_id ra_id; /*!< parsed RA ID of the remote BTS */
85 uint16_t cell_id; /*!< Cell ID of the remote BTS */
Harald Weltea78b9c22010-05-17 23:02:42 +020086
87 /* NSEI and BVCI of underlying Gb link. Together they
88 * uniquely identify a link to a BTS (5.4.4) */
89 uint16_t bvci;
90 uint16_t nsei;
91
92 uint32_t state;
93
94 struct rate_ctr_group *ctrg;
95
Harald Welted11c0592012-09-06 21:57:11 +020096 struct bssgp_flow_control fc;
97 uint32_t bmax_default_ms;
98 uint32_t r_default_ms;
99
Harald Weltea78b9c22010-05-17 23:02:42 +0200100 /* we might want to add this as a shortcut later, avoiding the NSVC
101 * lookup for every packet, similar to a routing cache */
102 //struct gprs_nsvc *nsvc;
103};
104extern struct llist_head bssgp_bvc_ctxts;
105/* Find a BTS Context based on parsed RA ID and Cell ID */
106struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
107/* Find a BTS context based on BVCI+NSEI tuple */
108struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
109
Harald Welte85fc3142011-11-25 08:58:40 +0100110#define BVC_F_BLOCKED 0x0001
111
112enum bssgp_ctr {
113 BSSGP_CTR_PKTS_IN,
114 BSSGP_CTR_PKTS_OUT,
115 BSSGP_CTR_BYTES_IN,
116 BSSGP_CTR_BYTES_OUT,
117 BSSGP_CTR_BLOCKED,
118 BSSGP_CTR_DISCARDED,
119};
120
121
Pablo Neira Ayusoff663232011-03-22 16:47:59 +0100122#include <osmocom/gsm/tlv.h>
Harald Welte605ac5d2012-06-16 16:09:52 +0800123#include <osmocom/gprs/gprs_msgb.h>
Harald Welte3771d092010-04-30 20:26:32 +0200124
Harald Welte61112342010-05-13 19:25:59 +0200125/* BSSGP-UL-UNITDATA.ind */
Harald Weltede4599c2012-06-17 13:04:02 +0800126int bssgp_rcvmsg(struct msgb *msg);
Harald Welte61112342010-05-13 19:25:59 +0200127
128/* BSSGP-DL-UNITDATA.req */
Harald Welte8ef54d12012-06-17 09:31:16 +0800129struct bssgp_lv {
130 uint16_t len;
131 uint8_t *v;
132};
133/* parameters for BSSGP downlink userdata transmission */
134struct bssgp_dl_ud_par {
135 uint32_t *tlli;
136 char *imsi;
Harald Welted11c0592012-09-06 21:57:11 +0200137 struct bssgp_flow_control *fc;
Harald Welte8ef54d12012-06-17 09:31:16 +0800138 uint16_t drx_parms;
139 /* FIXME: priority */
140 struct bssgp_lv ms_ra_cap;
141 uint8_t qos_profile[3];
142};
Harald Weltede4599c2012-06-17 13:04:02 +0800143int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
144 struct bssgp_dl_ud_par *dup);
Harald Welte61112342010-05-13 19:25:59 +0200145
Harald Weltea2ca4ed2010-05-02 11:54:55 +0200146uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
Harald Welte85fc3142011-11-25 08:58:40 +0100147int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
148 uint16_t cid);
Harald Welte9ba50052010-03-14 15:45:01 +0800149
Harald Welte3771d092010-04-30 20:26:32 +0200150/* Wrapper around TLV parser to parse BSSGP IEs */
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200151static inline int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len)
Harald Welte3771d092010-04-30 20:26:32 +0200152{
153 return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
154}
155
Harald Welteeb3ccf62011-11-25 08:15:42 +0100156/*! \brief BSSGP Paging mode */
Harald Welte68b4f032010-06-09 16:22:28 +0200157enum bssgp_paging_mode {
158 BSSGP_PAGING_PS,
159 BSSGP_PAGING_CS,
160};
161
Harald Welteeb3ccf62011-11-25 08:15:42 +0100162/*! \brief BSSGP Paging scope */
Harald Welte68b4f032010-06-09 16:22:28 +0200163enum bssgp_paging_scope {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100164 BSSGP_PAGING_BSS_AREA, /*!< all cells in BSS */
165 BSSGP_PAGING_LOCATION_AREA, /*!< all cells in LA */
166 BSSGP_PAGING_ROUTEING_AREA, /*!< all cells in RA */
167 BSSGP_PAGING_BVCI, /*!< one cell */
Harald Welte68b4f032010-06-09 16:22:28 +0200168};
169
Harald Welteeb3ccf62011-11-25 08:15:42 +0100170/*! \brief BSSGP paging information */
Harald Welte68b4f032010-06-09 16:22:28 +0200171struct bssgp_paging_info {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100172 enum bssgp_paging_mode mode; /*!< CS or PS paging */
173 enum bssgp_paging_scope scope; /*!< bssgp_paging_scope */
174 struct gprs_ra_id raid; /*!< RA Identifier */
175 uint16_t bvci; /*!< BVCI */
Harald Welte85fc3142011-11-25 08:58:40 +0100176 char *imsi; /*!< IMSI, if any */
Harald Welteeb3ccf62011-11-25 08:15:42 +0100177 uint32_t *ptmsi; /*!< P-TMSI, if any */
178 uint16_t drx_params; /*!< DRX parameters */
179 uint8_t qos[3]; /*!< QoS parameters */
Harald Welte68b4f032010-06-09 16:22:28 +0200180};
181
182/* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
Harald Weltede4599c2012-06-17 13:04:02 +0800183int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
184 struct bssgp_paging_info *pinfo);
Harald Welte68b4f032010-06-09 16:22:28 +0200185
Harald Welted11c0592012-09-06 21:57:11 +0200186/* input function of the flow control implementation, called first
187 * for the MM flow control, and then as the MM flow control output
188 * callback in order to perform BVC flow control */
189int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg,
190 uint32_t llc_pdu_len, void *priv);
191
192/* Initialize the Flow Control parameters for a new MS according to
193 * default values for the BVC specified by BVCI and NSEI */
194int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci,
195 uint16_t nsei);
196
Harald Weltefdc73882010-05-18 08:02:36 +0200197/* gprs_bssgp_vty.c */
Harald Weltede4599c2012-06-17 13:04:02 +0800198int bssgp_vty_init(void);
199void bssgp_set_log_ss(int ss);
Harald Weltefdc73882010-05-18 08:02:36 +0200200
Harald Welte15a36432012-06-17 12:16:31 +0800201int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
202
Harald Welte9ba50052010-03-14 15:45:01 +0800203#endif /* _GPRS_BSSGP_H */