Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | #ifndef _GPRS_NS_H |
| 2 | #define _GPRS_NS_H |
| 3 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
| 5 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 6 | /* Our Implementation */ |
| 7 | #include <netinet/in.h> |
Pablo Neira Ayuso | 136f453 | 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 | 8645e10 | 2012-06-16 16:09:52 +0800 | [diff] [blame] | 12 | #include <osmocom/gprs/gprs_msgb.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 13 | |
Harald Welte | d24566a | 2012-06-17 13:12:51 +0800 | [diff] [blame] | 14 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
| 15 | |
Harald Welte | ea4647d | 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 | 2eb6e2c | 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 | ea4647d | 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 | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 37 | #define NSE_S_BLOCKED 0x0001 |
| 38 | #define NSE_S_ALIVE 0x0002 |
| 39 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 40 | /*! \brief Osmocom NS link layer types */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 41 | enum gprs_ns_ll { |
Harald Welte | 914660d | 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 | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 47 | /*! \brief Osmoco NS events */ |
Harald Welte | b77c697 | 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 | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 53 | /*! \brief Osmocom GPRS callback function type */ |
Harald Welte | b77c697 | 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 | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 55 | struct msgb *msg, uint16_t bvci); |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 56 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 57 | /*! \brief An instance of the NS protocol stack */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 58 | struct gprs_ns_inst { |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 59 | /*! \brief callback to the user for incoming UNIT DATA IND */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 60 | gprs_ns_cb_t *cb; |
| 61 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 62 | /*! \brief linked lists of all NSVC in this instance */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 63 | struct llist_head gprs_nsvcs; |
| 64 | |
Harald Welte | 914660d | 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 | 9aa97fc | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 67 | struct gprs_nsvc *unknown_nsvc; |
| 68 | |
Harald Welte | ea4647d | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 69 | uint16_t timeout[NS_TIMERS_COUNT]; |
| 70 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 71 | /*! \brief NS-over-IP specific bits */ |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 72 | struct { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 73 | struct osmo_fd fd; |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 74 | uint32_t local_ip; |
| 75 | uint16_t local_port; |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 76 | } nsip; |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 77 | /*! \brief NS-over-FR-over-GRE-over-IP specific bits */ |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 78 | struct { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 79 | struct osmo_fd fd; |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 80 | uint32_t local_ip; |
Holger Hans Peter Freyther | 3e60348 | 2012-03-02 14:14:33 +0100 | [diff] [blame] | 81 | unsigned int enabled:1; |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 82 | } frgre; |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Harald Welte | 05b320a | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 85 | enum nsvc_timer_mode { |
| 86 | /* standard timers */ |
| 87 | NSVC_TIMER_TNS_TEST, |
| 88 | NSVC_TIMER_TNS_ALIVE, |
Harald Welte | 199d9df | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 89 | NSVC_TIMER_TNS_RESET, |
| 90 | _NSVC_TIMER_NR, |
Harald Welte | 05b320a | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 93 | /*! \brief Structure representing a single NS-VC */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 94 | struct gprs_nsvc { |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 95 | /*! \brief list of NS-VCs within NS Instance */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 96 | struct llist_head list; |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 97 | /*! \brief pointer to NS Instance */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 98 | struct gprs_ns_inst *nsi; |
| 99 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 100 | uint16_t nsei; /*! \brief end-to-end significance */ |
| 101 | uint16_t nsvci; /*! \brief uniquely identifies NS-VC at SGSN */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 102 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 103 | uint32_t state; |
| 104 | uint32_t remote_state; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 105 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 106 | struct osmo_timer_list timer; |
Harald Welte | 05b320a | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 107 | enum nsvc_timer_mode timer_mode; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 108 | int alive_retries; |
| 109 | |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 110 | unsigned int remote_end_is_sgsn:1; |
| 111 | unsigned int persistent:1; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 112 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 113 | struct rate_ctr_group *ctrg; |
| 114 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 115 | /*! \brief which link-layer are we based on? */ |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 116 | enum gprs_ns_ll ll; |
| 117 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 118 | union { |
| 119 | struct { |
| 120 | struct sockaddr_in bts_addr; |
| 121 | } ip; |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 122 | struct { |
| 123 | struct sockaddr_in bts_addr; |
| 124 | } frgre; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 125 | }; |
| 126 | }; |
| 127 | |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 128 | /* Create a new NS protocol instance */ |
Harald Welte | a6a20b4 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 129 | struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 130 | |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 131 | /* Destroy a NS protocol instance */ |
| 132 | void gprs_ns_destroy(struct gprs_ns_inst *nsi); |
| 133 | |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 134 | /* Listen for incoming GPRS packets via NS/UDP */ |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 135 | int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi); |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 136 | |
Harald Welte | e6599ee | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 137 | /* Establish a connection (from the BSS) to the SGSN */ |
| 138 | struct 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 Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 143 | struct sockaddr_in; |
| 144 | |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 145 | /* main function for higher layers (BSSGP) to send NS messages */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 146 | int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg); |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 147 | |
Harald Welte | 99e3248 | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 148 | int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause); |
| 149 | int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause); |
| 150 | int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 151 | |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 152 | /* Listen for incoming GPRS packets via NS/FR/GRE */ |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 153 | int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 154 | |
Harald Welte | e6599ee | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 155 | struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci); |
| 156 | void gprs_nsvc_delete(struct gprs_nsvc *nsvc); |
| 157 | struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei); |
| 158 | struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 159 | |
Harald Welte | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 160 | /* Initiate a RESET procedure (including timer start, ...)*/ |
Holger Hans Peter Freyther | 83e0b3f | 2010-05-23 21:18:01 +0800 | [diff] [blame] | 161 | void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause); |
Harald Welte | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 162 | |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 163 | /* Add NS-specific VTY stuff */ |
| 164 | int gprs_ns_vty_init(struct gprs_ns_inst *nsi); |
| 165 | |
Holger Hans Peter Freyther | 2844144 | 2010-06-14 22:11:40 +0800 | [diff] [blame] | 166 | #define NS_ALLOC_SIZE 2048 |
Harald Welte | e4860d7 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 167 | #define NS_ALLOC_HEADROOM 20 |
| 168 | static inline struct msgb *gprs_ns_msgb_alloc(void) |
| 169 | { |
| 170 | return msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM, "GPRS/NS"); |
| 171 | } |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 172 | |
Harald Welte | a6a20b4 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 173 | enum 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 | |
| 180 | struct ns_signal_data { |
| 181 | struct gprs_nsvc *nsvc; |
| 182 | uint8_t cause; |
| 183 | }; |
| 184 | |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 185 | void gprs_ns_set_log_ss(int ss); |
| 186 | |
Harald Welte | 914660d | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 187 | /*! }@ */ |
| 188 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 189 | #endif |