blob: 949dbdc8935153d077ca70d9db777b6d3c507d9d [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>
5
Harald Welte73952e32012-06-16 14:59:56 +08006#include <osmocom/gsm/gsm48.h>
Harald Welte15a36432012-06-17 12:16:31 +08007#include <osmocom/gsm/prim.h>
Harald Welte73952e32012-06-16 14:59:56 +08008
Harald Welte8648e492012-06-17 13:12:51 +08009#include <osmocom/gprs/protocol/gsm_08_18.h>
10
Harald Welteaf086782010-05-11 10:01:17 +020011/* gprs_bssgp_util.c */
12extern struct gprs_ns_inst *bssgp_nsi;
13struct msgb *bssgp_msgb_alloc(void);
14const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
15/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
16int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
17 uint16_t bvci, uint16_t ns_bvci);
18/* Chapter 10.4.14: Status */
19int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
20
Harald Welte15a36432012-06-17 12:16:31 +080021enum bssgp_prim {
22 PRIM_BSSGP_DL_UD,
23 PRIM_BSSGP_UL_UD,
24 PRIM_BSSGP_PTM_UD,
25
26 PRIM_BSSGP_GMM_SUSPEND,
27 PRIM_BSSGP_GMM_RESUME,
28 PRIM_BSSGP_GMM_PAGING,
29
30 PRIM_NM_FLUSH_LL,
31 PRIM_NM_LLC_DISCARDED,
32 PRIM_NM_BVC_RESET,
33 PRIM_NM_BVC_BLOCK,
34 PRIM_NM_BVC_UNBLOCK,
35};
36
37struct osmo_bssgp_prim {
38 struct osmo_prim_hdr oph;
39
40 /* common fields */
41 uint16_t nsei;
42 uint16_t bvci;
43 uint32_t tlli;
44 struct tlv_parsed *tp;
45 struct gprs_ra_id *ra_id;
46
47 /* specific fields */
48 union {
49 struct {
50 uint8_t *suspend_ref;
51 } resume;
52 } u;
53};
54
Harald Welteaf086782010-05-11 10:01:17 +020055/* gprs_bssgp.c */
56
Harald Weltea78b9c22010-05-17 23:02:42 +020057#define BVC_S_BLOCKED 0x0001
58
59/* The per-BTS context that we keep on the SGSN side of the BSSGP link */
60struct bssgp_bvc_ctx {
61 struct llist_head list;
62
Harald Welteeb3ccf62011-11-25 08:15:42 +010063 struct gprs_ra_id ra_id; /*!< parsed RA ID of the remote BTS */
64 uint16_t cell_id; /*!< Cell ID of the remote BTS */
Harald Weltea78b9c22010-05-17 23:02:42 +020065
66 /* NSEI and BVCI of underlying Gb link. Together they
67 * uniquely identify a link to a BTS (5.4.4) */
68 uint16_t bvci;
69 uint16_t nsei;
70
71 uint32_t state;
72
73 struct rate_ctr_group *ctrg;
74
75 /* we might want to add this as a shortcut later, avoiding the NSVC
76 * lookup for every packet, similar to a routing cache */
77 //struct gprs_nsvc *nsvc;
78};
79extern struct llist_head bssgp_bvc_ctxts;
80/* Find a BTS Context based on parsed RA ID and Cell ID */
81struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid);
82/* Find a BTS context based on BVCI+NSEI tuple */
83struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei);
84
Harald Welte85fc3142011-11-25 08:58:40 +010085#define BVC_F_BLOCKED 0x0001
86
87enum bssgp_ctr {
88 BSSGP_CTR_PKTS_IN,
89 BSSGP_CTR_PKTS_OUT,
90 BSSGP_CTR_BYTES_IN,
91 BSSGP_CTR_BYTES_OUT,
92 BSSGP_CTR_BLOCKED,
93 BSSGP_CTR_DISCARDED,
94};
95
96
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010097#include <osmocom/gsm/tlv.h>
Harald Welte605ac5d2012-06-16 16:09:52 +080098#include <osmocom/gprs/gprs_msgb.h>
Harald Welte3771d092010-04-30 20:26:32 +020099
Harald Welte61112342010-05-13 19:25:59 +0200100/* BSSGP-UL-UNITDATA.ind */
Harald Weltede4599c2012-06-17 13:04:02 +0800101int bssgp_rcvmsg(struct msgb *msg);
Harald Welte61112342010-05-13 19:25:59 +0200102
103/* BSSGP-DL-UNITDATA.req */
Harald Welte8ef54d12012-06-17 09:31:16 +0800104struct bssgp_lv {
105 uint16_t len;
106 uint8_t *v;
107};
108/* parameters for BSSGP downlink userdata transmission */
109struct bssgp_dl_ud_par {
110 uint32_t *tlli;
111 char *imsi;
112 uint16_t drx_parms;
113 /* FIXME: priority */
114 struct bssgp_lv ms_ra_cap;
115 uint8_t qos_profile[3];
116};
Harald Weltede4599c2012-06-17 13:04:02 +0800117int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
118 struct bssgp_dl_ud_par *dup);
Harald Welte61112342010-05-13 19:25:59 +0200119
Harald Weltea2ca4ed2010-05-02 11:54:55 +0200120uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf);
Harald Welte85fc3142011-11-25 08:58:40 +0100121int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
122 uint16_t cid);
Harald Welte9ba50052010-03-14 15:45:01 +0800123
Harald Welte3771d092010-04-30 20:26:32 +0200124/* Wrapper around TLV parser to parse BSSGP IEs */
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200125static inline int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len)
Harald Welte3771d092010-04-30 20:26:32 +0200126{
127 return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0);
128}
129
Harald Welteeb3ccf62011-11-25 08:15:42 +0100130/*! \brief BSSGP Paging mode */
Harald Welte68b4f032010-06-09 16:22:28 +0200131enum bssgp_paging_mode {
132 BSSGP_PAGING_PS,
133 BSSGP_PAGING_CS,
134};
135
Harald Welteeb3ccf62011-11-25 08:15:42 +0100136/*! \brief BSSGP Paging scope */
Harald Welte68b4f032010-06-09 16:22:28 +0200137enum bssgp_paging_scope {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100138 BSSGP_PAGING_BSS_AREA, /*!< all cells in BSS */
139 BSSGP_PAGING_LOCATION_AREA, /*!< all cells in LA */
140 BSSGP_PAGING_ROUTEING_AREA, /*!< all cells in RA */
141 BSSGP_PAGING_BVCI, /*!< one cell */
Harald Welte68b4f032010-06-09 16:22:28 +0200142};
143
Harald Welteeb3ccf62011-11-25 08:15:42 +0100144/*! \brief BSSGP paging information */
Harald Welte68b4f032010-06-09 16:22:28 +0200145struct bssgp_paging_info {
Harald Welteeb3ccf62011-11-25 08:15:42 +0100146 enum bssgp_paging_mode mode; /*!< CS or PS paging */
147 enum bssgp_paging_scope scope; /*!< bssgp_paging_scope */
148 struct gprs_ra_id raid; /*!< RA Identifier */
149 uint16_t bvci; /*!< BVCI */
Harald Welte85fc3142011-11-25 08:58:40 +0100150 char *imsi; /*!< IMSI, if any */
Harald Welteeb3ccf62011-11-25 08:15:42 +0100151 uint32_t *ptmsi; /*!< P-TMSI, if any */
152 uint16_t drx_params; /*!< DRX parameters */
153 uint8_t qos[3]; /*!< QoS parameters */
Harald Welte68b4f032010-06-09 16:22:28 +0200154};
155
156/* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */
Harald Weltede4599c2012-06-17 13:04:02 +0800157int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
158 struct bssgp_paging_info *pinfo);
Harald Welte68b4f032010-06-09 16:22:28 +0200159
Harald Weltefdc73882010-05-18 08:02:36 +0200160/* gprs_bssgp_vty.c */
Harald Weltede4599c2012-06-17 13:04:02 +0800161int bssgp_vty_init(void);
162void bssgp_set_log_ss(int ss);
Harald Weltefdc73882010-05-18 08:02:36 +0200163
Harald Welte15a36432012-06-17 12:16:31 +0800164int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
165
Harald Welte9ba50052010-03-14 15:45:01 +0800166#endif /* _GPRS_BSSGP_H */