blob: 8fca70cbfb065c740a872cec941e661d75ce3895 [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;
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +010076 int dscp;
Harald Welteb3ee2652010-05-19 14:38:50 +020077 } nsip;
Harald Weltea9f23c82011-11-23 15:01:31 +010078 /*! \brief NS-over-FR-over-GRE-over-IP specific bits */
Harald Welteb3ee2652010-05-19 14:38:50 +020079 struct {
Pablo Neira Ayusobfadfb72011-05-06 12:11:23 +020080 struct osmo_fd fd;
Harald Welte7fb05232010-05-19 15:09:09 +020081 uint32_t local_ip;
Holger Hans Peter Freyther1e57eb62012-03-02 14:14:33 +010082 unsigned int enabled:1;
Harald Welteb3ee2652010-05-19 14:38:50 +020083 } frgre;
Harald Welte1203de32010-05-01 11:28:43 +020084};
85
Harald Welte80405452010-05-03 20:16:13 +020086enum nsvc_timer_mode {
87 /* standard timers */
88 NSVC_TIMER_TNS_TEST,
89 NSVC_TIMER_TNS_ALIVE,
Harald Welte69a4cf22010-05-03 20:55:10 +020090 NSVC_TIMER_TNS_RESET,
91 _NSVC_TIMER_NR,
Harald Welte80405452010-05-03 20:16:13 +020092};
93
Harald Weltea9f23c82011-11-23 15:01:31 +010094/*! \brief Structure representing a single NS-VC */
Harald Welte3771d092010-04-30 20:26:32 +020095struct gprs_nsvc {
Harald Weltea9f23c82011-11-23 15:01:31 +010096 /*! \brief list of NS-VCs within NS Instance */
Harald Welte3771d092010-04-30 20:26:32 +020097 struct llist_head list;
Harald Weltea9f23c82011-11-23 15:01:31 +010098 /*! \brief pointer to NS Instance */
Harald Welte3771d092010-04-30 20:26:32 +020099 struct gprs_ns_inst *nsi;
100
Harald Weltea9f23c82011-11-23 15:01:31 +0100101 uint16_t nsei; /*! \brief end-to-end significance */
102 uint16_t nsvci; /*! \brief uniquely identifies NS-VC at SGSN */
Harald Welte3771d092010-04-30 20:26:32 +0200103
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200104 uint32_t state;
105 uint32_t remote_state;
Harald Welte3771d092010-04-30 20:26:32 +0200106
Pablo Neira Ayuso2b159522011-05-06 12:11:06 +0200107 struct osmo_timer_list timer;
Harald Welte80405452010-05-03 20:16:13 +0200108 enum nsvc_timer_mode timer_mode;
Harald Welte3771d092010-04-30 20:26:32 +0200109 int alive_retries;
110
Harald Welte2bffac52010-05-12 15:55:23 +0000111 unsigned int remote_end_is_sgsn:1;
112 unsigned int persistent:1;
Harald Welte3771d092010-04-30 20:26:32 +0200113
Harald Welte144e0292010-05-13 11:45:07 +0200114 struct rate_ctr_group *ctrg;
115
Harald Weltea9f23c82011-11-23 15:01:31 +0100116 /*! \brief which link-layer are we based on? */
Harald Welteb3ee2652010-05-19 14:38:50 +0200117 enum gprs_ns_ll ll;
118
Harald Welte3771d092010-04-30 20:26:32 +0200119 union {
120 struct {
121 struct sockaddr_in bts_addr;
122 } ip;
Harald Welteb3ee2652010-05-19 14:38:50 +0200123 struct {
124 struct sockaddr_in bts_addr;
125 } frgre;
Harald Welte3771d092010-04-30 20:26:32 +0200126 };
127};
128
Harald Weltef030b212010-04-26 19:18:54 +0200129/* Create a new NS protocol instance */
Harald Welte4fcdd762012-06-16 16:40:42 +0800130struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx);
Harald Welte9ba50052010-03-14 15:45:01 +0800131
Harald Weltef030b212010-04-26 19:18:54 +0200132/* Destroy a NS protocol instance */
133void gprs_ns_destroy(struct gprs_ns_inst *nsi);
134
Harald Welteb3ee2652010-05-19 14:38:50 +0200135/* Listen for incoming GPRS packets via NS/UDP */
Harald Welte7fb05232010-05-19 15:09:09 +0200136int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi);
Harald Weltef030b212010-04-26 19:18:54 +0200137
Harald Weltef5430362012-06-17 12:25:53 +0800138/* Establish a connection (from the BSS) to the SGSN */
139struct gprs_nsvc *gprs_ns_nsip_connect(struct gprs_ns_inst *nsi,
140 struct sockaddr_in *dest,
141 uint16_t nsei, uint16_t nsvci);
142
143
Harald Weltef030b212010-04-26 19:18:54 +0200144struct sockaddr_in;
145
Harald Weltef030b212010-04-26 19:18:54 +0200146/* main function for higher layers (BSSGP) to send NS messages */
Harald Welte24a655f2010-04-30 19:54:29 +0200147int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
Harald Weltef030b212010-04-26 19:18:54 +0200148
Harald Welte834f26d2010-05-11 06:20:54 +0200149int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause);
150int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause);
151int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc);
Harald Welte3771d092010-04-30 20:26:32 +0200152
Harald Welteb3ee2652010-05-19 14:38:50 +0200153/* Listen for incoming GPRS packets via NS/FR/GRE */
Harald Welte7fb05232010-05-19 15:09:09 +0200154int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi);
Harald Welte3771d092010-04-30 20:26:32 +0200155
Harald Weltef5430362012-06-17 12:25:53 +0800156struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci);
157void gprs_nsvc_delete(struct gprs_nsvc *nsvc);
158struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei);
159struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200160
Harald Welte731d1fc2010-05-14 11:53:08 +0000161/* Initiate a RESET procedure (including timer start, ...)*/
Holger Hans Peter Freyther5617d992010-05-23 21:18:01 +0800162void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
Harald Welte731d1fc2010-05-14 11:53:08 +0000163
Harald Welte2bffac52010-05-12 15:55:23 +0000164/* Add NS-specific VTY stuff */
165int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
166
Holger Hans Peter Freyther4a90d222010-06-14 22:11:40 +0800167#define NS_ALLOC_SIZE 2048
Harald Welteba4c6662010-05-19 15:38:10 +0200168#define NS_ALLOC_HEADROOM 20
169static inline struct msgb *gprs_ns_msgb_alloc(void)
170{
171 return msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM, "GPRS/NS");
172}
Harald Welteb3ee2652010-05-19 14:38:50 +0200173
Harald Welte4fcdd762012-06-16 16:40:42 +0800174enum signal_ns {
175 S_NS_RESET,
176 S_NS_BLOCK,
177 S_NS_UNBLOCK,
178 S_NS_ALIVE_EXP, /* Tns-alive expired more than N times */
179};
180
181struct ns_signal_data {
182 struct gprs_nsvc *nsvc;
183 uint8_t cause;
184};
185
Harald Weltecca49632012-06-16 17:45:59 +0800186void gprs_ns_set_log_ss(int ss);
187
Harald Weltea9f23c82011-11-23 15:01:31 +0100188/*! }@ */
189
Harald Welte9ba50052010-03-14 15:45:01 +0800190#endif