blob: a7f32b25a2632ff19bdc0fdd9d32651d40444e0e [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 Welte3771d092010-04-30 20:26:32 +02006/* Our Implementation */
7#include <netinet/in.h>
Pablo Neira Ayusoff663232011-03-22 16:47:59 +01008#include <osmocom/core/linuxlist.h>
9#include <osmocom/core/msgb.h>
10#include <osmocom/core/timer.h>
11#include <osmocom/core/select.h>
Harald Welte605ac5d2012-06-16 16:09:52 +080012#include <osmocom/gprs/gprs_msgb.h>
Harald Welte3771d092010-04-30 20:26:32 +020013
Harald Welte8648e492012-06-17 13:12:51 +080014#include <osmocom/gprs/protocol/gsm_08_16.h>
15
Harald Weltefe4ab902010-05-12 17:19:53 +000016#define NS_TIMERS_COUNT 7
17#define NS_TIMERS "(tns-block|tns-block-retries|tns-reset|tns-reset-retries|tns-test|tns-alive|tns-alive-retries)"
18#define NS_TIMERS_HELP \
19 "(un)blocking Timer (Tns-block) timeout\n" \
20 "(un)blocking Timer (Tns-block) number of retries\n" \
21 "Reset Timer (Tns-reset) timeout\n" \
22 "Reset Timer (Tns-reset) number of retries\n" \
23 "Test Timer (Tns-test) timeout\n" \
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +010024 "Alive Timer (Tns-alive) timeout\n" \
25 "Alive Timer (Tns-alive) number of retries\n"
Harald Weltefe4ab902010-05-12 17:19:53 +000026
27enum ns_timeout {
28 NS_TOUT_TNS_BLOCK,
29 NS_TOUT_TNS_BLOCK_RETRIES,
30 NS_TOUT_TNS_RESET,
31 NS_TOUT_TNS_RESET_RETRIES,
32 NS_TOUT_TNS_TEST,
33 NS_TOUT_TNS_ALIVE,
34 NS_TOUT_TNS_ALIVE_RETRIES,
35};
36
Harald Welte3771d092010-04-30 20:26:32 +020037#define NSE_S_BLOCKED 0x0001
38#define NSE_S_ALIVE 0x0002
39
Harald Weltea9f23c82011-11-23 15:01:31 +010040/*! \brief Osmocom NS link layer types */
Harald Welte1203de32010-05-01 11:28:43 +020041enum gprs_ns_ll {
Harald Weltea9f23c82011-11-23 15:01:31 +010042 GPRS_NS_LL_UDP, /*!< NS/UDP/IP */
43 GPRS_NS_LL_E1, /*!< NS/E1 */
44 GPRS_NS_LL_FR_GRE, /*!< NS/FR/GRE/IP */
Harald Welte1203de32010-05-01 11:28:43 +020045};
46
Harald Weltea9f23c82011-11-23 15:01:31 +010047/*! \brief Osmoco NS events */
Harald Welte1203de32010-05-01 11:28:43 +020048enum gprs_ns_evt {
49 GPRS_NS_EVT_UNIT_DATA,
50};
51
52struct gprs_nsvc;
Harald Weltea9f23c82011-11-23 15:01:31 +010053/*! \brief Osmocom GPRS callback function type */
Harald Welte1203de32010-05-01 11:28:43 +020054typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
Harald Welte8f9a3ee2010-05-02 11:26:34 +020055 struct msgb *msg, uint16_t bvci);
Harald Welte1203de32010-05-01 11:28:43 +020056
Harald Weltea9f23c82011-11-23 15:01:31 +010057/*! \brief An instance of the NS protocol stack */
Harald Welte1203de32010-05-01 11:28:43 +020058struct gprs_ns_inst {
Harald Weltea9f23c82011-11-23 15:01:31 +010059 /*! \brief callback to the user for incoming UNIT DATA IND */
Harald Welte1203de32010-05-01 11:28:43 +020060 gprs_ns_cb_t *cb;
61
Harald Weltea9f23c82011-11-23 15:01:31 +010062 /*! \brief linked lists of all NSVC in this instance */
Harald Welte1203de32010-05-01 11:28:43 +020063 struct llist_head gprs_nsvcs;
64
Harald Weltea9f23c82011-11-23 15:01:31 +010065 /*! \brief a NSVC object that's needed to deal with packets for
66 * unknown NSVC */
Harald Weltedd1c83c2010-05-13 13:58:08 +020067 struct gprs_nsvc *unknown_nsvc;
68
Harald Weltefe4ab902010-05-12 17:19:53 +000069 uint16_t timeout[NS_TIMERS_COUNT];
70
Harald Weltea9f23c82011-11-23 15:01:31 +010071 /*! \brief NS-over-IP specific bits */
Harald Welteb3ee2652010-05-19 14:38:50 +020072 struct {
Pablo Neira Ayusobfadfb72011-05-06 12:11:23 +020073 struct osmo_fd fd;
Harald Welte7fb05232010-05-19 15:09:09 +020074 uint32_t local_ip;
75 uint16_t local_port;
Harald Welteb3ee2652010-05-19 14:38:50 +020076 } nsip;
Harald Weltea9f23c82011-11-23 15:01:31 +010077 /*! \brief NS-over-FR-over-GRE-over-IP specific bits */
Harald Welteb3ee2652010-05-19 14:38:50 +020078 struct {
Pablo Neira Ayusobfadfb72011-05-06 12:11:23 +020079 struct osmo_fd fd;
Harald Welte7fb05232010-05-19 15:09:09 +020080 uint32_t local_ip;
Holger Hans Peter Freyther1e57eb62012-03-02 14:14:33 +010081 unsigned int enabled:1;
Harald Welteb3ee2652010-05-19 14:38:50 +020082 } frgre;
Harald Welte1203de32010-05-01 11:28:43 +020083};
84
Harald Welte80405452010-05-03 20:16:13 +020085enum nsvc_timer_mode {
86 /* standard timers */
87 NSVC_TIMER_TNS_TEST,
88 NSVC_TIMER_TNS_ALIVE,
Harald Welte69a4cf22010-05-03 20:55:10 +020089 NSVC_TIMER_TNS_RESET,
90 _NSVC_TIMER_NR,
Harald Welte80405452010-05-03 20:16:13 +020091};
92
Harald Weltea9f23c82011-11-23 15:01:31 +010093/*! \brief Structure representing a single NS-VC */
Harald Welte3771d092010-04-30 20:26:32 +020094struct gprs_nsvc {
Harald Weltea9f23c82011-11-23 15:01:31 +010095 /*! \brief list of NS-VCs within NS Instance */
Harald Welte3771d092010-04-30 20:26:32 +020096 struct llist_head list;
Harald Weltea9f23c82011-11-23 15:01:31 +010097 /*! \brief pointer to NS Instance */
Harald Welte3771d092010-04-30 20:26:32 +020098 struct gprs_ns_inst *nsi;
99
Harald Weltea9f23c82011-11-23 15:01:31 +0100100 uint16_t nsei; /*! \brief end-to-end significance */
101 uint16_t nsvci; /*! \brief uniquely identifies NS-VC at SGSN */
Harald Welte3771d092010-04-30 20:26:32 +0200102
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200103 uint32_t state;
104 uint32_t remote_state;
Harald Welte3771d092010-04-30 20:26:32 +0200105
Pablo Neira Ayuso2b159522011-05-06 12:11:06 +0200106 struct osmo_timer_list timer;
Harald Welte80405452010-05-03 20:16:13 +0200107 enum nsvc_timer_mode timer_mode;
Harald Welte3771d092010-04-30 20:26:32 +0200108 int alive_retries;
109
Harald Welte2bffac52010-05-12 15:55:23 +0000110 unsigned int remote_end_is_sgsn:1;
111 unsigned int persistent:1;
Harald Welte3771d092010-04-30 20:26:32 +0200112
Harald Welte144e0292010-05-13 11:45:07 +0200113 struct rate_ctr_group *ctrg;
114
Harald Weltea9f23c82011-11-23 15:01:31 +0100115 /*! \brief which link-layer are we based on? */
Harald Welteb3ee2652010-05-19 14:38:50 +0200116 enum gprs_ns_ll ll;
117
Harald Welte3771d092010-04-30 20:26:32 +0200118 union {
119 struct {
120 struct sockaddr_in bts_addr;
121 } ip;
Harald Welteb3ee2652010-05-19 14:38:50 +0200122 struct {
123 struct sockaddr_in bts_addr;
124 } frgre;
Harald Welte3771d092010-04-30 20:26:32 +0200125 };
126};
127
Harald Weltef030b212010-04-26 19:18:54 +0200128/* Create a new NS protocol instance */
Harald Welte4fcdd762012-06-16 16:40:42 +0800129struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx);
Harald Welte9ba50052010-03-14 15:45:01 +0800130
Harald Weltef030b212010-04-26 19:18:54 +0200131/* Destroy a NS protocol instance */
132void gprs_ns_destroy(struct gprs_ns_inst *nsi);
133
Harald Welteb3ee2652010-05-19 14:38:50 +0200134/* Listen for incoming GPRS packets via NS/UDP */
Harald Welte7fb05232010-05-19 15:09:09 +0200135int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi);
Harald Weltef030b212010-04-26 19:18:54 +0200136
Harald Weltef5430362012-06-17 12:25:53 +0800137/* Establish a connection (from the BSS) to the SGSN */
138struct gprs_nsvc *gprs_ns_nsip_connect(struct gprs_ns_inst *nsi,
139 struct sockaddr_in *dest,
140 uint16_t nsei, uint16_t nsvci);
141
142
Harald Weltef030b212010-04-26 19:18:54 +0200143struct sockaddr_in;
144
Harald Weltef030b212010-04-26 19:18:54 +0200145/* main function for higher layers (BSSGP) to send NS messages */
Harald Welte24a655f2010-04-30 19:54:29 +0200146int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
Harald Weltef030b212010-04-26 19:18:54 +0200147
Harald Welte834f26d2010-05-11 06:20:54 +0200148int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause);
149int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause);
150int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc);
Harald Welte3771d092010-04-30 20:26:32 +0200151
Harald Welteb3ee2652010-05-19 14:38:50 +0200152/* Listen for incoming GPRS packets via NS/FR/GRE */
Harald Welte7fb05232010-05-19 15:09:09 +0200153int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi);
Harald Welte3771d092010-04-30 20:26:32 +0200154
Harald Weltef5430362012-06-17 12:25:53 +0800155struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci);
156void gprs_nsvc_delete(struct gprs_nsvc *nsvc);
157struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei);
158struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200159
Harald Welte731d1fc2010-05-14 11:53:08 +0000160/* Initiate a RESET procedure (including timer start, ...)*/
Holger Hans Peter Freyther5617d992010-05-23 21:18:01 +0800161void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
Harald Welte731d1fc2010-05-14 11:53:08 +0000162
Harald Welte2bffac52010-05-12 15:55:23 +0000163/* Add NS-specific VTY stuff */
164int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
165
Holger Hans Peter Freyther4a90d222010-06-14 22:11:40 +0800166#define NS_ALLOC_SIZE 2048
Harald Welteba4c6662010-05-19 15:38:10 +0200167#define NS_ALLOC_HEADROOM 20
168static inline struct msgb *gprs_ns_msgb_alloc(void)
169{
170 return msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM, "GPRS/NS");
171}
Harald Welteb3ee2652010-05-19 14:38:50 +0200172
Harald Welte4fcdd762012-06-16 16:40:42 +0800173enum signal_ns {
174 S_NS_RESET,
175 S_NS_BLOCK,
176 S_NS_UNBLOCK,
177 S_NS_ALIVE_EXP, /* Tns-alive expired more than N times */
178};
179
180struct ns_signal_data {
181 struct gprs_nsvc *nsvc;
182 uint8_t cause;
183};
184
Harald Weltecca49632012-06-16 17:45:59 +0800185void gprs_ns_set_log_ss(int ss);
186
Harald Weltea9f23c82011-11-23 15:01:31 +0100187/*! }@ */
188
Harald Welte9ba50052010-03-14 15:45:01 +0800189#endif