blob: ca02c4b5d10de33c867a10b882ad64b468b49b14 [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001#ifndef _GPRS_NS_H
2#define _GPRS_NS_H
3
Harald Weltecb991632010-04-26 19:18:54 +02004/* GPRS Networks Service (NS) messages on the Gb interface
5 * 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05)
6 * 3GPP TS 48.016 version 6.5.0 Release 6 / ETSI TS 148 016 V6.5.0 (2005-11) */
7
Harald Welte9b455bf2010-03-14 15:45:01 +08008struct gprs_ns_hdr {
9 u_int8_t pdu_type;
10 u_int8_t data[0];
11} __attribute__((packed));
12
13/* TS 08.16, Section 10.3.7, Table 14 */
14enum ns_pdu_type {
15 NS_PDUT_UNITDATA = 0x00,
16 NS_PDUT_RESET = 0x02,
17 NS_PDUT_RESET_ACK = 0x03,
18 NS_PDUT_BLOCK = 0x04,
19 NS_PDUT_BLOCK_ACK = 0x05,
20 NS_PDUT_UNBLOCK = 0x06,
21 NS_PDUT_UNBLOCK_ACK = 0x07,
22 NS_PDUT_STATUS = 0x08,
23 NS_PDUT_ALIVE = 0x0a,
24 NS_PDUT_ALIVE_ACK = 0x0b,
Harald Weltecb991632010-04-26 19:18:54 +020025 /* TS 48.016 Section 10.3.7, Table 10.3.7.1 */
26 SNS_PDUT_ACK = 0x0c,
27 SNS_PDUT_ADD = 0x0d,
28 SNS_PDUT_CHANGE_WEIGHT = 0x0e,
29 SNS_PDUT_CONFIG = 0x0f,
30 SNS_PDUT_CONFIG_ACK = 0x10,
31 SNS_PDUT_DELETE = 0x11,
32 SNS_PDUT_SIZE = 0x12,
33 SNS_PDUT_SIZE_ACK = 0x13,
Harald Welte9b455bf2010-03-14 15:45:01 +080034};
35
36/* TS 08.16, Section 10.3, Table 12 */
37enum ns_ctrl_ie {
38 NS_IE_CAUSE = 0x00,
39 NS_IE_VCI = 0x01,
40 NS_IE_PDU = 0x02,
41 NS_IE_BVCI = 0x03,
42 NS_IE_NSEI = 0x04,
Harald Weltecb991632010-04-26 19:18:54 +020043 /* TS 48.016 Section 10.3, Table 10.3.1 */
44 NS_IE_IPv4_LIST = 0x05,
45 NS_IE_IPv6_LIST = 0x06,
46 NS_IE_MAX_NR_NSVC = 0x07,
47 NS_IE_IPv4_EP_NR = 0x08,
48 NS_IE_IPv6_EP_NR = 0x09,
49 NS_IE_RESET_FLAG = 0x0a,
50 NS_IE_IP_ADDR = 0x0b,
Harald Welte9b455bf2010-03-14 15:45:01 +080051};
52
53/* TS 08.16, Section 10.3.2, Table 13 */
54enum ns_cause {
55 NS_CAUSE_TRANSIT_FAIL = 0x00,
56 NS_CAUSE_OM_INTERVENTION = 0x01,
57 NS_CAUSE_EQUIP_FAIL = 0x02,
58 NS_CAUSE_NSVC_BLOCKED = 0x03,
59 NS_CAUSE_NSVC_UNKNOWN = 0x04,
60 NS_CAUSE_BVCI_UNKNOWN = 0x05,
61 NS_CAUSE_SEM_INCORR_PDU = 0x08,
62 NS_CAUSE_PDU_INCOMP_PSTATE = 0x0a,
63 NS_CAUSE_PROTO_ERR_UNSPEC = 0x0b,
64 NS_CAUSE_INVAL_ESSENT_IE = 0x0c,
65 NS_CAUSE_MISSING_ESSENT_IE = 0x0d,
Harald Weltecb991632010-04-26 19:18:54 +020066 /* TS 48.016 Section 10.3.2, Table 10.3.2.1 */
67 NS_CAUSE_INVAL_NR_IPv4_EP = 0x0e,
68 NS_CAUSE_INVAL_NR_IPv6_EP = 0x0f,
69 NS_CAUSE_INVAL_NR_NS_VC = 0x10,
70 NS_CAUSE_INVAL_WEIGH = 0x11,
71 NS_CAUSE_UNKN_IP_EP = 0x12,
72 NS_CAUSE_UNKN_IP_ADDR = 0x13,
73 NS_CAUSE_UNKN_IP_TEST_FAILED = 0x14,
Harald Welte9b455bf2010-03-14 15:45:01 +080074};
75
Harald Welte9f75c352010-04-30 20:26:32 +020076
77/* Our Implementation */
78#include <netinet/in.h>
Harald Welteb77c6972010-05-01 11:28:43 +020079#include <osmocore/linuxlist.h>
80#include <osmocore/msgb.h>
81#include <osmocore/timer.h>
82#include <osmocore/select.h>
Harald Welte9f75c352010-04-30 20:26:32 +020083
84#define NSE_S_BLOCKED 0x0001
85#define NSE_S_ALIVE 0x0002
86
Harald Welteb77c6972010-05-01 11:28:43 +020087enum gprs_ns_ll {
88 GPRS_NS_LL_UDP,
89 GPRS_NS_LL_E1,
90};
91
92enum gprs_ns_evt {
93 GPRS_NS_EVT_UNIT_DATA,
94};
95
96struct gprs_nsvc;
97typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
98 struct msgb *msg, u_int16_t bvci);
99
100/* An instance of the NS protocol stack */
101struct gprs_ns_inst {
102 /* callback to the user for incoming UNIT DATA IND */
103 gprs_ns_cb_t *cb;
104
105 /* linked lists of all NSVC in this instance */
106 struct llist_head gprs_nsvcs;
107
108 /* which link-layer are we based on? */
109 enum gprs_ns_ll ll;
110
111 union {
112 /* NS-over-IP specific bits */
113 struct {
114 struct bsc_fd fd;
115 } nsip;
116 };
117};
118
Harald Welte9f75c352010-04-30 20:26:32 +0200119struct gprs_nsvc {
120 struct llist_head list;
121 struct gprs_ns_inst *nsi;
122
123 u_int16_t nsei; /* end-to-end significance */
124 u_int16_t nsvci; /* uniquely identifies NS-VC at SGSN */
125
126 u_int32_t state;
127 u_int32_t remote_state;
128
129 struct timer_list alive_timer;
130 int timer_is_tns_alive;
131 int alive_retries;
132
133 int remote_end_is_sgsn;
134
135 union {
136 struct {
137 struct sockaddr_in bts_addr;
138 } ip;
139 };
140};
141
Harald Weltecb991632010-04-26 19:18:54 +0200142/* Create a new NS protocol instance */
143struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb);
Harald Welte9b455bf2010-03-14 15:45:01 +0800144
Harald Weltecb991632010-04-26 19:18:54 +0200145/* Destroy a NS protocol instance */
146void gprs_ns_destroy(struct gprs_ns_inst *nsi);
147
148/* Listen for incoming GPRS packets */
149int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port);
150
151struct sockaddr_in;
152
153/* main entry point, here incoming NS frames enter */
154int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
155 struct sockaddr_in *saddr);
156
157/* main function for higher layers (BSSGP) to send NS messages */
Harald Welte44f1c272010-04-30 19:54:29 +0200158int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
Harald Weltecb991632010-04-26 19:18:54 +0200159
Harald Welte9f75c352010-04-30 20:26:32 +0200160
161/* Listen for incoming GPRS packets */
162int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port);
163
164/* Establish a connection (from the BSS) to the SGSN */
165struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,
Harald Welteb77c6972010-05-01 11:28:43 +0200166 struct sockaddr_in *dest, uint16_t nsei,
167 uint16_t nsvci);
Harald Welte9b455bf2010-03-14 15:45:01 +0800168#endif