Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | #ifndef _GPRS_NS_H |
| 2 | #define _GPRS_NS_H |
| 3 | |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
| 5 | |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 6 | /* Our Implementation */ |
| 7 | #include <netinet/in.h> |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 8 | #include <osmocom/core/linuxlist.h> |
| 9 | #include <osmocom/core/msgb.h> |
| 10 | #include <osmocom/core/timer.h> |
| 11 | #include <osmocom/core/select.h> |
Harald Welte | 605ac5d | 2012-06-16 16:09:52 +0800 | [diff] [blame] | 12 | #include <osmocom/gprs/gprs_msgb.h> |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 13 | |
Harald Welte | 8648e49 | 2012-06-17 13:12:51 +0800 | [diff] [blame] | 14 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
| 15 | |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 16 | #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 Freyther | 887934e | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 24 | "Alive Timer (Tns-alive) timeout\n" \ |
| 25 | "Alive Timer (Tns-alive) number of retries\n" |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 26 | |
| 27 | enum 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 Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 37 | #define NSE_S_BLOCKED 0x0001 |
| 38 | #define NSE_S_ALIVE 0x0002 |
| 39 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 40 | /*! \brief Osmocom NS link layer types */ |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 41 | enum gprs_ns_ll { |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 42 | 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 Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 47 | /*! \brief Osmoco NS events */ |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 48 | enum gprs_ns_evt { |
| 49 | GPRS_NS_EVT_UNIT_DATA, |
| 50 | }; |
| 51 | |
| 52 | struct gprs_nsvc; |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 53 | /*! \brief Osmocom GPRS callback function type */ |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 54 | typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 55 | struct msgb *msg, uint16_t bvci); |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 56 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 57 | /*! \brief An instance of the NS protocol stack */ |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 58 | struct gprs_ns_inst { |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 59 | /*! \brief callback to the user for incoming UNIT DATA IND */ |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 60 | gprs_ns_cb_t *cb; |
| 61 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 62 | /*! \brief linked lists of all NSVC in this instance */ |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 63 | struct llist_head gprs_nsvcs; |
| 64 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 65 | /*! \brief a NSVC object that's needed to deal with packets for |
| 66 | * unknown NSVC */ |
Harald Welte | dd1c83c | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 67 | struct gprs_nsvc *unknown_nsvc; |
| 68 | |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 69 | uint16_t timeout[NS_TIMERS_COUNT]; |
| 70 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 71 | /*! \brief NS-over-IP specific bits */ |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 72 | struct { |
Pablo Neira Ayuso | bfadfb7 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 73 | struct osmo_fd fd; |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 74 | uint32_t local_ip; |
| 75 | uint16_t local_port; |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 76 | int dscp; |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 77 | } nsip; |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 78 | /*! \brief NS-over-FR-over-GRE-over-IP specific bits */ |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 79 | struct { |
Pablo Neira Ayuso | bfadfb7 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 80 | struct osmo_fd fd; |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 81 | uint32_t local_ip; |
Holger Hans Peter Freyther | 1e57eb6 | 2012-03-02 14:14:33 +0100 | [diff] [blame] | 82 | unsigned int enabled:1; |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 83 | } frgre; |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 86 | enum nsvc_timer_mode { |
| 87 | /* standard timers */ |
| 88 | NSVC_TIMER_TNS_TEST, |
| 89 | NSVC_TIMER_TNS_ALIVE, |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 90 | NSVC_TIMER_TNS_RESET, |
| 91 | _NSVC_TIMER_NR, |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 94 | /*! \brief Structure representing a single NS-VC */ |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 95 | struct gprs_nsvc { |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 96 | /*! \brief list of NS-VCs within NS Instance */ |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 97 | struct llist_head list; |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 98 | /*! \brief pointer to NS Instance */ |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 99 | struct gprs_ns_inst *nsi; |
| 100 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 101 | uint16_t nsei; /*! \brief end-to-end significance */ |
| 102 | uint16_t nsvci; /*! \brief uniquely identifies NS-VC at SGSN */ |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 103 | |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 104 | uint32_t state; |
| 105 | uint32_t remote_state; |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 106 | |
Pablo Neira Ayuso | 2b15952 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 107 | struct osmo_timer_list timer; |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 108 | enum nsvc_timer_mode timer_mode; |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 109 | int alive_retries; |
| 110 | |
Harald Welte | 2bffac5 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 111 | unsigned int remote_end_is_sgsn:1; |
| 112 | unsigned int persistent:1; |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 113 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 114 | struct rate_ctr_group *ctrg; |
| 115 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 116 | /*! \brief which link-layer are we based on? */ |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 117 | enum gprs_ns_ll ll; |
| 118 | |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 119 | union { |
| 120 | struct { |
| 121 | struct sockaddr_in bts_addr; |
| 122 | } ip; |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 123 | struct { |
| 124 | struct sockaddr_in bts_addr; |
| 125 | } frgre; |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 126 | }; |
| 127 | }; |
| 128 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 129 | /* Create a new NS protocol instance */ |
Harald Welte | 4fcdd76 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 130 | struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 131 | |
Holger Hans Peter Freyther | c62a1bf | 2013-07-02 09:10:11 +0200 | [diff] [blame] | 132 | /* Close a NS protocol instance */ |
| 133 | void gprs_ns_close(struct gprs_ns_inst *nsi); |
| 134 | |
| 135 | /* Close and Destroy a NS protocol instance */ |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 136 | void gprs_ns_destroy(struct gprs_ns_inst *nsi); |
| 137 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 138 | /* Listen for incoming GPRS packets via NS/UDP */ |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 139 | int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 140 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 141 | /* Establish a connection (from the BSS) to the SGSN */ |
| 142 | struct gprs_nsvc *gprs_ns_nsip_connect(struct gprs_ns_inst *nsi, |
| 143 | struct sockaddr_in *dest, |
| 144 | uint16_t nsei, uint16_t nsvci); |
| 145 | |
| 146 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 147 | struct sockaddr_in; |
| 148 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 149 | /* main function for higher layers (BSSGP) to send NS messages */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 150 | int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 151 | |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 152 | int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause); |
| 153 | int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause); |
| 154 | int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc); |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 155 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 156 | /* Listen for incoming GPRS packets via NS/FR/GRE */ |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 157 | int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi); |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 158 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 159 | struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci); |
| 160 | void gprs_nsvc_delete(struct gprs_nsvc *nsvc); |
| 161 | struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei); |
| 162 | struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 163 | |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 164 | /* Initiate a RESET procedure (including timer start, ...)*/ |
Holger Hans Peter Freyther | 5617d99 | 2010-05-23 21:18:01 +0800 | [diff] [blame] | 165 | void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause); |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 166 | |
Harald Welte | 2bffac5 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 167 | /* Add NS-specific VTY stuff */ |
| 168 | int gprs_ns_vty_init(struct gprs_ns_inst *nsi); |
| 169 | |
Holger Hans Peter Freyther | 4a90d22 | 2010-06-14 22:11:40 +0800 | [diff] [blame] | 170 | #define NS_ALLOC_SIZE 2048 |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 171 | #define NS_ALLOC_HEADROOM 20 |
| 172 | static inline struct msgb *gprs_ns_msgb_alloc(void) |
| 173 | { |
| 174 | return msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM, "GPRS/NS"); |
| 175 | } |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 176 | |
Harald Welte | 4fcdd76 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 177 | enum signal_ns { |
| 178 | S_NS_RESET, |
| 179 | S_NS_BLOCK, |
| 180 | S_NS_UNBLOCK, |
| 181 | S_NS_ALIVE_EXP, /* Tns-alive expired more than N times */ |
| 182 | }; |
| 183 | |
| 184 | struct ns_signal_data { |
| 185 | struct gprs_nsvc *nsvc; |
| 186 | uint8_t cause; |
| 187 | }; |
| 188 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 189 | void gprs_ns_set_log_ss(int ss); |
| 190 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 191 | /*! }@ */ |
| 192 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 193 | #endif |