blob: 573536d11dcfa79349e58c09230d3c62e11fcc3b [file] [log] [blame]
Harald Welte9ba50052010-03-14 15:45:01 +08001#ifndef _GPRS_NS_H
2#define _GPRS_NS_H
3
Harald Welte8f9a3ee2010-05-02 11:26:34 +02004#include <stdint.h>
5
Harald Weltef030b212010-04-26 19:18:54 +02006/* GPRS Networks Service (NS) messages on the Gb interface
7 * 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05)
8 * 3GPP TS 48.016 version 6.5.0 Release 6 / ETSI TS 148 016 V6.5.0 (2005-11) */
9
Harald Welte9ba50052010-03-14 15:45:01 +080010struct gprs_ns_hdr {
Harald Welte8f9a3ee2010-05-02 11:26:34 +020011 uint8_t pdu_type;
12 uint8_t data[0];
Harald Welte9ba50052010-03-14 15:45:01 +080013} __attribute__((packed));
14
15/* TS 08.16, Section 10.3.7, Table 14 */
16enum ns_pdu_type {
17 NS_PDUT_UNITDATA = 0x00,
18 NS_PDUT_RESET = 0x02,
19 NS_PDUT_RESET_ACK = 0x03,
20 NS_PDUT_BLOCK = 0x04,
21 NS_PDUT_BLOCK_ACK = 0x05,
22 NS_PDUT_UNBLOCK = 0x06,
23 NS_PDUT_UNBLOCK_ACK = 0x07,
24 NS_PDUT_STATUS = 0x08,
25 NS_PDUT_ALIVE = 0x0a,
26 NS_PDUT_ALIVE_ACK = 0x0b,
Harald Weltef030b212010-04-26 19:18:54 +020027 /* TS 48.016 Section 10.3.7, Table 10.3.7.1 */
28 SNS_PDUT_ACK = 0x0c,
29 SNS_PDUT_ADD = 0x0d,
30 SNS_PDUT_CHANGE_WEIGHT = 0x0e,
31 SNS_PDUT_CONFIG = 0x0f,
32 SNS_PDUT_CONFIG_ACK = 0x10,
33 SNS_PDUT_DELETE = 0x11,
34 SNS_PDUT_SIZE = 0x12,
35 SNS_PDUT_SIZE_ACK = 0x13,
Harald Welte9ba50052010-03-14 15:45:01 +080036};
37
38/* TS 08.16, Section 10.3, Table 12 */
39enum ns_ctrl_ie {
40 NS_IE_CAUSE = 0x00,
41 NS_IE_VCI = 0x01,
42 NS_IE_PDU = 0x02,
43 NS_IE_BVCI = 0x03,
44 NS_IE_NSEI = 0x04,
Harald Weltef030b212010-04-26 19:18:54 +020045 /* TS 48.016 Section 10.3, Table 10.3.1 */
46 NS_IE_IPv4_LIST = 0x05,
47 NS_IE_IPv6_LIST = 0x06,
48 NS_IE_MAX_NR_NSVC = 0x07,
49 NS_IE_IPv4_EP_NR = 0x08,
50 NS_IE_IPv6_EP_NR = 0x09,
51 NS_IE_RESET_FLAG = 0x0a,
52 NS_IE_IP_ADDR = 0x0b,
Harald Welte9ba50052010-03-14 15:45:01 +080053};
54
55/* TS 08.16, Section 10.3.2, Table 13 */
56enum ns_cause {
57 NS_CAUSE_TRANSIT_FAIL = 0x00,
58 NS_CAUSE_OM_INTERVENTION = 0x01,
59 NS_CAUSE_EQUIP_FAIL = 0x02,
60 NS_CAUSE_NSVC_BLOCKED = 0x03,
61 NS_CAUSE_NSVC_UNKNOWN = 0x04,
62 NS_CAUSE_BVCI_UNKNOWN = 0x05,
63 NS_CAUSE_SEM_INCORR_PDU = 0x08,
64 NS_CAUSE_PDU_INCOMP_PSTATE = 0x0a,
65 NS_CAUSE_PROTO_ERR_UNSPEC = 0x0b,
66 NS_CAUSE_INVAL_ESSENT_IE = 0x0c,
67 NS_CAUSE_MISSING_ESSENT_IE = 0x0d,
Harald Weltef030b212010-04-26 19:18:54 +020068 /* TS 48.016 Section 10.3.2, Table 10.3.2.1 */
69 NS_CAUSE_INVAL_NR_IPv4_EP = 0x0e,
70 NS_CAUSE_INVAL_NR_IPv6_EP = 0x0f,
71 NS_CAUSE_INVAL_NR_NS_VC = 0x10,
72 NS_CAUSE_INVAL_WEIGH = 0x11,
73 NS_CAUSE_UNKN_IP_EP = 0x12,
74 NS_CAUSE_UNKN_IP_ADDR = 0x13,
75 NS_CAUSE_UNKN_IP_TEST_FAILED = 0x14,
Harald Welte9ba50052010-03-14 15:45:01 +080076};
77
Harald Welte3771d092010-04-30 20:26:32 +020078
79/* Our Implementation */
80#include <netinet/in.h>
Harald Welte1203de32010-05-01 11:28:43 +020081#include <osmocore/linuxlist.h>
82#include <osmocore/msgb.h>
83#include <osmocore/timer.h>
84#include <osmocore/select.h>
Harald Welte3771d092010-04-30 20:26:32 +020085
86#define NSE_S_BLOCKED 0x0001
87#define NSE_S_ALIVE 0x0002
88
Harald Welte1203de32010-05-01 11:28:43 +020089enum gprs_ns_ll {
90 GPRS_NS_LL_UDP,
91 GPRS_NS_LL_E1,
92};
93
94enum gprs_ns_evt {
95 GPRS_NS_EVT_UNIT_DATA,
96};
97
98struct gprs_nsvc;
99typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200100 struct msgb *msg, uint16_t bvci);
Harald Welte1203de32010-05-01 11:28:43 +0200101
102/* An instance of the NS protocol stack */
103struct gprs_ns_inst {
104 /* callback to the user for incoming UNIT DATA IND */
105 gprs_ns_cb_t *cb;
106
107 /* linked lists of all NSVC in this instance */
108 struct llist_head gprs_nsvcs;
109
110 /* which link-layer are we based on? */
111 enum gprs_ns_ll ll;
112
113 union {
114 /* NS-over-IP specific bits */
115 struct {
116 struct bsc_fd fd;
117 } nsip;
118 };
119};
120
Harald Welte3771d092010-04-30 20:26:32 +0200121struct gprs_nsvc {
122 struct llist_head list;
123 struct gprs_ns_inst *nsi;
124
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200125 uint16_t nsei; /* end-to-end significance */
126 uint16_t nsvci; /* uniquely identifies NS-VC at SGSN */
Harald Welte3771d092010-04-30 20:26:32 +0200127
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200128 uint32_t state;
129 uint32_t remote_state;
Harald Welte3771d092010-04-30 20:26:32 +0200130
131 struct timer_list alive_timer;
132 int timer_is_tns_alive;
133 int alive_retries;
134
135 int remote_end_is_sgsn;
136
137 union {
138 struct {
139 struct sockaddr_in bts_addr;
140 } ip;
141 };
142};
143
Harald Weltef030b212010-04-26 19:18:54 +0200144/* Create a new NS protocol instance */
145struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb);
Harald Welte9ba50052010-03-14 15:45:01 +0800146
Harald Weltef030b212010-04-26 19:18:54 +0200147/* Destroy a NS protocol instance */
148void gprs_ns_destroy(struct gprs_ns_inst *nsi);
149
150/* Listen for incoming GPRS packets */
151int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port);
152
153struct sockaddr_in;
154
155/* main entry point, here incoming NS frames enter */
156int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
157 struct sockaddr_in *saddr);
158
159/* main function for higher layers (BSSGP) to send NS messages */
Harald Welte24a655f2010-04-30 19:54:29 +0200160int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
Harald Weltef030b212010-04-26 19:18:54 +0200161
Harald Welte3771d092010-04-30 20:26:32 +0200162
163/* Listen for incoming GPRS packets */
164int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port);
165
166/* Establish a connection (from the BSS) to the SGSN */
167struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,
Harald Welte1203de32010-05-01 11:28:43 +0200168 struct sockaddr_in *dest, uint16_t nsei,
169 uint16_t nsvci);
Harald Welte9ba50052010-03-14 15:45:01 +0800170#endif