Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1 | /*! \file gprs_ns2_internal.h */ |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <stdbool.h> |
| 6 | #include <stdint.h> |
| 7 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 8 | #include <osmocom/core/logging.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 9 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
| 10 | #include <osmocom/gprs/gprs_ns2.h> |
| 11 | |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 12 | #define LOGNSE(nse, lvl, fmt, args ...) \ |
| 13 | LOGP(DLNS, lvl, "NSE(%05u) " fmt, (nse)->nsei, ## args) |
| 14 | |
| 15 | #define LOGBIND(bind, lvl, fmt, args ...) \ |
| 16 | LOGP(DLNS, lvl, "BIND(%s) " fmt, (bind)->name, ## args) |
| 17 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 18 | #define LOGNSVC_SS(ss, nsvc, lvl, fmt, args ...) \ |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 19 | do { \ |
| 20 | if ((nsvc)->nsvci_is_valid) { \ |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 21 | LOGP(ss, lvl, "NSE(%05u)-NSVC(%05u) " fmt, \ |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 22 | (nsvc)->nse->nsei, (nsvc)->nsvci, ## args); \ |
| 23 | } else { \ |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 24 | LOGP(ss, lvl, "NSE(%05u)-NSVC(none) " fmt, \ |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 25 | (nsvc)->nse->nsei, ## args); \ |
| 26 | } \ |
| 27 | } while (0) |
| 28 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 29 | #define LOGNSVC(nsvc, lvl, fmt, args ...) \ |
| 30 | LOGNSVC_SS(DLNS, nsvc, lvl, fmt, ## args) |
| 31 | |
| 32 | #define LOG_NS_SIGNAL(nsvc, direction, pdu_type, lvl, fmt, args ...) \ |
| 33 | LOGNSVC_SS(DLNSSIGNAL, nsvc, lvl, "%s %s" fmt, direction, get_value_string(gprs_ns_pdu_strings, pdu_type), ## args) |
| 34 | |
| 35 | #define LOG_NS_DATA(nsvc, direction, pdu_type, lvl, fmt, args ...) \ |
| 36 | LOGNSVC_SS(DLNSDATA, nsvc, lvl, "%s %s" fmt, direction, get_value_string(gprs_ns_pdu_strings, pdu_type), ## args) |
| 37 | |
| 38 | #define LOG_NS_RX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Rx", pdu_type, LOGL_INFO, "\n") |
| 39 | #define LOG_NS_TX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Tx", pdu_type, LOGL_INFO, "\n") |
| 40 | |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 41 | #define RATE_CTR_INC_NS(nsvc, ctr) \ |
| 42 | do { \ |
| 43 | struct gprs_ns2_vc *_nsvc = (nsvc); \ |
| 44 | rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr)); \ |
| 45 | rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr)); \ |
| 46 | } while (0) |
| 47 | |
| 48 | #define RATE_CTR_ADD_NS(nsvc, ctr, val) \ |
| 49 | do { \ |
| 50 | struct gprs_ns2_vc *_nsvc = (nsvc); \ |
| 51 | rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr), val); \ |
| 52 | rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr), val); \ |
| 53 | } while (0) |
| 54 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 55 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 56 | struct osmo_fsm_inst; |
| 57 | struct tlv_parsed; |
| 58 | struct vty; |
| 59 | |
| 60 | struct gprs_ns2_vc_driver; |
| 61 | struct gprs_ns2_vc_bind; |
| 62 | |
Alexander Couzens | 90ee963 | 2020-12-07 06:18:32 +0100 | [diff] [blame] | 63 | #define NS_TIMERS_COUNT 10 |
Harald Welte | 3a44d17 | 2020-12-16 12:02:51 +0100 | [diff] [blame] | 64 | #define NS_TIMERS "(tns-block|tns-block-retries|tns-reset|tns-reset-retries|tns-test|tns-alive|tns-alive-retries|tsns-prov|tsns-size-retries|tsns-config-retries)" |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 65 | #define NS_TIMERS_HELP \ |
| 66 | "(un)blocking Timer (Tns-block) timeout\n" \ |
| 67 | "(un)blocking Timer (Tns-block) number of retries\n" \ |
| 68 | "Reset Timer (Tns-reset) timeout\n" \ |
| 69 | "Reset Timer (Tns-reset) number of retries\n" \ |
| 70 | "Test Timer (Tns-test) timeout\n" \ |
| 71 | "Alive Timer (Tns-alive) timeout\n" \ |
| 72 | "Alive Timer (Tns-alive) number of retries\n" \ |
Alexander Couzens | 90ee963 | 2020-12-07 06:18:32 +0100 | [diff] [blame] | 73 | "SNS Provision Timer (Tsns-prov) timeout\n" \ |
| 74 | "SNS Size number of retries\n" \ |
| 75 | "SNS Config number of retries\n" \ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 76 | |
| 77 | /* Educated guess - LLC user payload is 1500 bytes plus possible headers */ |
| 78 | #define NS_ALLOC_SIZE 3072 |
| 79 | #define NS_ALLOC_HEADROOM 20 |
| 80 | |
| 81 | enum ns2_timeout { |
| 82 | NS_TOUT_TNS_BLOCK, |
| 83 | NS_TOUT_TNS_BLOCK_RETRIES, |
| 84 | NS_TOUT_TNS_RESET, |
| 85 | NS_TOUT_TNS_RESET_RETRIES, |
| 86 | NS_TOUT_TNS_TEST, |
| 87 | NS_TOUT_TNS_ALIVE, |
| 88 | NS_TOUT_TNS_ALIVE_RETRIES, |
| 89 | NS_TOUT_TSNS_PROV, |
Alexander Couzens | 90ee963 | 2020-12-07 06:18:32 +0100 | [diff] [blame] | 90 | NS_TOUT_TSNS_SIZE_RETRIES, |
| 91 | NS_TOUT_TSNS_CONFIG_RETRIES, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | enum nsvc_timer_mode { |
| 95 | /* standard timers */ |
| 96 | NSVC_TIMER_TNS_TEST, |
| 97 | NSVC_TIMER_TNS_ALIVE, |
| 98 | NSVC_TIMER_TNS_RESET, |
| 99 | _NSVC_TIMER_NR, |
| 100 | }; |
| 101 | |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 102 | enum ns2_vc_stat { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 103 | NS_STAT_ALIVE_DELAY, |
| 104 | }; |
| 105 | |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 106 | enum ns2_bind_stat { |
| 107 | NS2_BIND_STAT_BACKLOG_LEN, |
| 108 | }; |
| 109 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 110 | /*! Osmocom NS2 VC create status */ |
Alexander Couzens | ba5a992 | 2021-01-25 16:03:23 +0100 | [diff] [blame] | 111 | enum ns2_cs { |
| 112 | NS2_CS_CREATED, /*!< A NSVC object has been created */ |
| 113 | NS2_CS_FOUND, /*!< A NSVC object has been found */ |
| 114 | NS2_CS_REJECTED, /*!< Rejected and answered message */ |
| 115 | NS2_CS_SKIPPED, /*!< Skipped message */ |
| 116 | NS2_CS_ERROR, /*!< Failed to process message */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 117 | }; |
| 118 | |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 119 | enum ns_ctr { |
| 120 | NS_CTR_PKTS_IN, |
| 121 | NS_CTR_PKTS_OUT, |
Harald Welte | f22ae5a | 2021-01-30 22:01:28 +0100 | [diff] [blame] | 122 | NS_CTR_PKTS_OUT_DROP, |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 123 | NS_CTR_BYTES_IN, |
| 124 | NS_CTR_BYTES_OUT, |
Harald Welte | f22ae5a | 2021-01-30 22:01:28 +0100 | [diff] [blame] | 125 | NS_CTR_BYTES_OUT_DROP, |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 126 | NS_CTR_BLOCKED, |
Harald Welte | b40bf8b | 2021-01-30 22:43:01 +0100 | [diff] [blame] | 127 | NS_CTR_UNBLOCKED, |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 128 | NS_CTR_DEAD, |
| 129 | NS_CTR_REPLACED, |
| 130 | NS_CTR_NSEI_CHG, |
| 131 | NS_CTR_INV_VCI, |
| 132 | NS_CTR_INV_NSEI, |
| 133 | NS_CTR_LOST_ALIVE, |
| 134 | NS_CTR_LOST_RESET, |
| 135 | }; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 136 | |
| 137 | #define NSE_S_BLOCKED 0x0001 |
| 138 | #define NSE_S_ALIVE 0x0002 |
| 139 | #define NSE_S_RESET 0x0004 |
| 140 | |
| 141 | #define NS_DESC_B(st) ((st) & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED") |
| 142 | #define NS_DESC_A(st) ((st) & NSE_S_ALIVE ? "ALIVE" : "DEAD") |
| 143 | #define NS_DESC_R(st) ((st) & NSE_S_RESET ? "RESET" : "UNRESET") |
| 144 | |
| 145 | /*! An instance of the NS protocol stack */ |
| 146 | struct gprs_ns2_inst { |
| 147 | /*! callback to the user for incoming UNIT DATA IND */ |
| 148 | osmo_prim_cb cb; |
| 149 | |
| 150 | /*! callback data */ |
| 151 | void *cb_data; |
| 152 | |
| 153 | /*! linked lists of all NSVC binds (e.g. IPv4 bind, but could be also E1 */ |
| 154 | struct llist_head binding; |
| 155 | |
| 156 | /*! linked lists of all NSVC in this instance */ |
| 157 | struct llist_head nse; |
| 158 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 159 | uint16_t timeout[NS_TIMERS_COUNT]; |
| 160 | |
| 161 | /*! workaround for rate counter until rate counter accepts char str as index */ |
Harald Welte | 97ccbf7 | 2021-01-31 11:49:19 +0100 | [diff] [blame] | 162 | uint32_t nsvc_rate_ctr_idx; |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 163 | uint32_t bind_rate_ctr_idx; |
Harald Welte | 53a2fde | 2020-12-01 22:21:14 +0100 | [diff] [blame] | 164 | |
| 165 | /*! libmnl netlink socket for link state monitoring */ |
| 166 | struct osmo_mnl *linkmon_mnl; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
Harald Welte | 53a2fde | 2020-12-01 22:21:14 +0100 | [diff] [blame] | 169 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 170 | /*! Structure repesenting a NSE. The BSS/PCU will only have a single NSE, while SGSN has one for each BSS/PCU */ |
| 171 | struct gprs_ns2_nse { |
| 172 | uint16_t nsei; |
| 173 | |
| 174 | /*! entry back to ns2_inst */ |
| 175 | struct gprs_ns2_inst *nsi; |
| 176 | |
| 177 | /*! llist entry for gprs_ns2_inst */ |
| 178 | struct llist_head list; |
| 179 | |
| 180 | /*! llist head to hold all nsvc */ |
| 181 | struct llist_head nsvc; |
| 182 | |
Alexander Couzens | 8a2a1a4 | 2020-12-26 18:00:17 +0100 | [diff] [blame] | 183 | /*! count all active NSVCs */ |
| 184 | int nsvc_count; |
Alexander Couzens | fc3dd1f | 2020-11-19 00:41:47 +0100 | [diff] [blame] | 185 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 186 | /*! true if this NSE was created by VTY or pcu socket) */ |
| 187 | bool persistent; |
| 188 | |
Alexander Couzens | da0a285 | 2020-10-01 23:24:07 +0200 | [diff] [blame] | 189 | /*! true if this NSE wasn't yet alive at all. |
| 190 | * Will be true after the first status ind with NS_AFF_CAUSE_RECOVERY */ |
| 191 | bool first; |
| 192 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 193 | /*! true if this NSE has at least one alive VC */ |
| 194 | bool alive; |
| 195 | |
Alexander Couzens | aac9016 | 2020-11-19 02:44:04 +0100 | [diff] [blame] | 196 | /*! which link-layer are we based on? */ |
| 197 | enum gprs_ns2_ll ll; |
| 198 | |
Alexander Couzens | d923cff | 2020-12-01 01:03:52 +0100 | [diff] [blame] | 199 | /*! which dialect does this NSE speaks? */ |
| 200 | enum gprs_ns2_dialect dialect; |
| 201 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 202 | struct osmo_fsm_inst *bss_sns_fi; |
Harald Welte | 3221f87 | 2021-01-18 14:58:51 +0100 | [diff] [blame] | 203 | |
Alexander Couzens | e052c41 | 2021-02-15 02:10:57 +0100 | [diff] [blame] | 204 | /*! sum of all the data weight of _alive_ NS-VCs */ |
Harald Welte | 3221f87 | 2021-01-18 14:58:51 +0100 | [diff] [blame] | 205 | uint32_t sum_data_weight; |
| 206 | |
Alexander Couzens | e052c41 | 2021-02-15 02:10:57 +0100 | [diff] [blame] | 207 | /*! sum of all the signalling weight of _alive_ NS-VCs */ |
Harald Welte | 3221f87 | 2021-01-18 14:58:51 +0100 | [diff] [blame] | 208 | uint32_t sum_sig_weight; |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 209 | |
| 210 | /*! MTU of a NS PDU. This is the lowest MTU of all NSVCs */ |
| 211 | uint16_t mtu; |
Harald Welte | 5b034fb | 2021-03-04 14:16:49 +0100 | [diff] [blame] | 212 | |
| 213 | /*! are we implementing the SGSN role? */ |
| 214 | bool ip_sns_role_sgsn; |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 215 | |
| 216 | /*! NSE-wide statistics */ |
| 217 | struct rate_ctr_group *ctrg; |
Alexander Couzens | 41589a3 | 2021-07-19 03:40:02 +0200 | [diff] [blame] | 218 | |
| 219 | /*! recursive anchor */ |
| 220 | bool freed; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | /*! Structure representing a single NS-VC */ |
| 224 | struct gprs_ns2_vc { |
| 225 | /*! list of NS-VCs within NSE */ |
| 226 | struct llist_head list; |
| 227 | |
| 228 | /*! list of NS-VCs within bind, bind is the owner! */ |
| 229 | struct llist_head blist; |
| 230 | |
| 231 | /*! pointer to NS Instance */ |
| 232 | struct gprs_ns2_nse *nse; |
| 233 | |
| 234 | /*! pointer to NS VL bind. bind own the memory of this instance */ |
| 235 | struct gprs_ns2_vc_bind *bind; |
| 236 | |
| 237 | /*! true if this NS was created by VTY or pcu socket) */ |
| 238 | bool persistent; |
| 239 | |
| 240 | /*! uniquely identifies NS-VC if VC contains nsvci */ |
| 241 | uint16_t nsvci; |
| 242 | |
| 243 | /*! signalling weight. 0 = don't use for signalling (BVCI == 0)*/ |
| 244 | uint8_t sig_weight; |
| 245 | |
Alexander Couzens | fc3dd1f | 2020-11-19 00:41:47 +0100 | [diff] [blame] | 246 | /*! signalling packet counter for the load sharing function */ |
| 247 | uint8_t sig_counter; |
| 248 | |
| 249 | /*! data weight. 0 = don't use for user data (BVCI != 0) */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 250 | uint8_t data_weight; |
| 251 | |
| 252 | /*! can be used by the bind/driver of the virtual circuit. e.g. ipv4/ipv6/frgre/e1 */ |
| 253 | void *priv; |
| 254 | |
| 255 | bool nsvci_is_valid; |
Harald Welte | c962a2e | 2021-03-05 08:09:08 +0100 | [diff] [blame] | 256 | /*! should this NS-VC only be used for SNS-SIZE and SNS-CONFIG? */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 257 | bool sns_only; |
| 258 | |
| 259 | struct rate_ctr_group *ctrg; |
| 260 | struct osmo_stat_item_group *statg; |
| 261 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 262 | enum gprs_ns2_vc_mode mode; |
| 263 | |
| 264 | struct osmo_fsm_inst *fi; |
Alexander Couzens | 41589a3 | 2021-07-19 03:40:02 +0200 | [diff] [blame] | 265 | |
| 266 | /*! recursive anchor */ |
| 267 | bool freed; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | /*! Structure repesenting a bind instance. E.g. IPv4 listen port. */ |
| 271 | struct gprs_ns2_vc_bind { |
Alexander Couzens | aaa55a6 | 2020-12-03 06:02:03 +0100 | [diff] [blame] | 272 | /*! unique name */ |
| 273 | const char *name; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 274 | /*! list entry in nsi */ |
| 275 | struct llist_head list; |
| 276 | /*! list of all VC */ |
| 277 | struct llist_head nsvc; |
| 278 | /*! driver private structure */ |
| 279 | void *priv; |
| 280 | /*! a pointer back to the nsi */ |
| 281 | struct gprs_ns2_inst *nsi; |
| 282 | struct gprs_ns2_vc_driver *driver; |
| 283 | |
Alexander Couzens | d923cff | 2020-12-01 01:03:52 +0100 | [diff] [blame] | 284 | bool accept_ipaccess; |
| 285 | bool accept_sns; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 286 | |
Alexander Couzens | 1c8785d | 2020-12-17 06:58:53 +0100 | [diff] [blame] | 287 | /*! transfer capability in mbit */ |
| 288 | int transfer_capability; |
| 289 | |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 290 | /*! MTU of a NS PDU on this bind. */ |
| 291 | uint16_t mtu; |
| 292 | |
Alexander Couzens | aac9016 | 2020-11-19 02:44:04 +0100 | [diff] [blame] | 293 | /*! which link-layer are we based on? */ |
| 294 | enum gprs_ns2_ll ll; |
| 295 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 296 | /*! send a msg over a VC */ |
| 297 | int (*send_vc)(struct gprs_ns2_vc *nsvc, struct msgb *msg); |
| 298 | |
| 299 | /*! free the vc priv data */ |
| 300 | void (*free_vc)(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 301 | |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 302 | /*! allow to show information for the vty */ |
| 303 | void (*dump_vty)(const struct gprs_ns2_vc_bind *bind, |
| 304 | struct vty *vty, bool stats); |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 305 | |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 306 | /*! the IP-SNS signalling weight when doing dynamic configuration */ |
| 307 | uint8_t sns_sig_weight; |
| 308 | /*! the IP-SNS data weight when doing dynamic configuration */ |
| 309 | uint8_t sns_data_weight; |
| 310 | |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 311 | struct osmo_stat_item_group *statg; |
Alexander Couzens | 41589a3 | 2021-07-19 03:40:02 +0200 | [diff] [blame] | 312 | |
| 313 | /*! recursive anchor */ |
| 314 | bool freed; |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 315 | }; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 316 | |
| 317 | struct gprs_ns2_vc_driver { |
| 318 | const char *name; |
| 319 | void *priv; |
| 320 | void (*free_bind)(struct gprs_ns2_vc_bind *driver); |
| 321 | }; |
| 322 | |
Alexander Couzens | 175eb7b | 2021-07-20 18:41:14 +0200 | [diff] [blame] | 323 | enum ns2_sns_event { |
| 324 | NS2_SNS_EV_REQ_SELECT_ENDPOINT, /*!< Select a SNS endpoint from the list */ |
| 325 | NS2_SNS_EV_RX_SIZE, |
| 326 | NS2_SNS_EV_RX_SIZE_ACK, |
| 327 | NS2_SNS_EV_RX_CONFIG, |
| 328 | NS2_SNS_EV_RX_CONFIG_END, /*!< SNS-CONFIG with end flag received */ |
| 329 | NS2_SNS_EV_RX_CONFIG_ACK, |
| 330 | NS2_SNS_EV_RX_ADD, |
| 331 | NS2_SNS_EV_RX_DELETE, |
| 332 | NS2_SNS_EV_RX_CHANGE_WEIGHT, |
| 333 | NS2_SNS_EV_RX_ACK, /*!< Rx of SNS-ACK (response to ADD/DELETE/CHG_WEIGHT */ |
| 334 | NS2_SNS_EV_REQ_NO_NSVC, /*!< no more NS-VC remaining (all dead) */ |
| 335 | NS2_SNS_EV_REQ_NSVC_ALIVE, /*!< a NS-VC became alive */ |
| 336 | NS2_SNS_EV_REQ_ADD_BIND, /*!< add a new local bind to this NSE */ |
| 337 | NS2_SNS_EV_REQ_DELETE_BIND, /*!< remove a local bind from this NSE */ |
| 338 | }; |
| 339 | |
Alexander Couzens | ba5a992 | 2021-01-25 16:03:23 +0100 | [diff] [blame] | 340 | enum ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 341 | struct msgb *msg, |
Harald Welte | 7d0daac | 2021-03-02 23:08:43 +0100 | [diff] [blame] | 342 | const struct osmo_sockaddr *remote, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 343 | const char *logname, |
| 344 | struct msgb **reject, |
| 345 | struct gprs_ns2_vc **success); |
| 346 | |
Alexander Couzens | ffd49d0 | 2020-09-24 00:47:17 +0200 | [diff] [blame] | 347 | int ns2_recv_vc(struct gprs_ns2_vc *nsvc, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 348 | struct msgb *msg); |
| 349 | |
| 350 | struct gprs_ns2_vc *ns2_vc_alloc(struct gprs_ns2_vc_bind *bind, |
| 351 | struct gprs_ns2_nse *nse, |
Alexander Couzens | d923cff | 2020-12-01 01:03:52 +0100 | [diff] [blame] | 352 | bool initiater, |
Harald Welte | 603f404 | 2020-11-29 17:39:19 +0100 | [diff] [blame] | 353 | enum gprs_ns2_vc_mode vc_mode, |
| 354 | const char *id); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 355 | |
Harald Welte | c3aa8f9 | 2021-01-31 11:41:34 +0100 | [diff] [blame] | 356 | int ns2_bind_alloc(struct gprs_ns2_inst *nsi, const char *name, |
| 357 | struct gprs_ns2_vc_bind **result); |
| 358 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 359 | struct msgb *ns2_msgb_alloc(void); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 360 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 361 | void ns2_sns_write_vty(struct vty *vty, const struct gprs_ns2_nse *nse); |
| 362 | void ns2_sns_dump_vty(struct vty *vty, const char *prefix, const struct gprs_ns2_nse *nse, bool stats); |
Alexander Couzens | bf95f0f | 2020-10-01 22:56:03 +0200 | [diff] [blame] | 363 | void ns2_prim_status_ind(struct gprs_ns2_nse *nse, |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 364 | struct gprs_ns2_vc *nsvc, |
Alexander Couzens | bf95f0f | 2020-10-01 22:56:03 +0200 | [diff] [blame] | 365 | uint16_t bvci, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 366 | enum gprs_ns2_affecting_cause cause); |
| 367 | void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive); |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 368 | void ns2_nse_update_mtu(struct gprs_ns2_nse *nse); |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 369 | int ns2_nse_set_dialect(struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 370 | |
| 371 | /* message */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 372 | int ns2_validate(struct gprs_ns2_vc *nsvc, |
| 373 | uint8_t pdu_type, |
| 374 | struct msgb *msg, |
| 375 | struct tlv_parsed *tp, |
| 376 | uint8_t *cause); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 377 | |
| 378 | /* SNS messages */ |
| 379 | int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause, |
| 380 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 381 | unsigned int num_ip4_elems, |
| 382 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 383 | unsigned int num_ip6_elems); |
| 384 | int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag, |
| 385 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 386 | unsigned int num_ip4_elems, |
| 387 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 388 | unsigned int num_ip6_elems); |
| 389 | int ns2_tx_sns_config_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause); |
| 390 | int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_nsvc, |
| 391 | int ip4_ep_nr, int ip6_ep_nr); |
| 392 | int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause); |
| 393 | |
Alexander Couzens | 27a5592 | 2021-02-27 01:08:35 +0100 | [diff] [blame] | 394 | int ns2_tx_sns_add(struct gprs_ns2_vc *nsvc, |
| 395 | uint8_t trans_id, |
| 396 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 397 | unsigned int num_ip4_elems, |
| 398 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 399 | unsigned int num_ip6_elems); |
| 400 | int ns2_tx_sns_change_weight(struct gprs_ns2_vc *nsvc, |
| 401 | uint8_t trans_id, |
| 402 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 403 | unsigned int num_ip4_elems, |
| 404 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 405 | unsigned int num_ip6_elems); |
| 406 | int ns2_tx_sns_del(struct gprs_ns2_vc *nsvc, |
| 407 | uint8_t trans_id, |
| 408 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 409 | unsigned int num_ip4_elems, |
| 410 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 411 | unsigned int num_ip6_elems); |
| 412 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 413 | /* transmit message over a VC */ |
| 414 | int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause); |
| 415 | int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc); |
| 416 | |
| 417 | int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause); |
| 418 | int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc); |
| 419 | |
| 420 | int ns2_tx_unblock(struct gprs_ns2_vc *nsvc); |
| 421 | int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc); |
| 422 | |
| 423 | int ns2_tx_alive(struct gprs_ns2_vc *nsvc); |
| 424 | int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc); |
| 425 | |
| 426 | int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc, |
| 427 | uint16_t bvci, uint8_t sducontrol, |
| 428 | struct msgb *msg); |
| 429 | |
| 430 | int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause, |
| 431 | uint16_t bvci, struct msgb *orig_msg); |
| 432 | |
| 433 | /* driver */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 434 | struct gprs_ns2_vc *ns2_ip_bind_connect(struct gprs_ns2_vc_bind *bind, |
| 435 | struct gprs_ns2_nse *nse, |
| 436 | const struct osmo_sockaddr *remote); |
Alexander Couzens | e769f52 | 2020-12-07 07:37:07 +0100 | [diff] [blame] | 437 | int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote); |
| 438 | struct gprs_ns2_vc_bind *ns2_ip_get_bind_by_index(struct gprs_ns2_inst *nsi, |
| 439 | struct osmo_sockaddr *remote, |
| 440 | int index); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 441 | |
| 442 | /* sns */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 443 | int ns2_sns_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 444 | struct osmo_fsm_inst *ns2_sns_bss_fsm_alloc(struct gprs_ns2_nse *nse, |
| 445 | const char *id); |
Harald Welte | 4f12746 | 2021-03-02 20:49:10 +0100 | [diff] [blame] | 446 | struct osmo_fsm_inst *ns2_sns_sgsn_fsm_alloc(struct gprs_ns2_nse *nse, const char *id); |
Alexander Couzens | be7cecc | 2021-02-03 18:25:27 +0100 | [diff] [blame] | 447 | void ns2_sns_replace_nsvc(struct gprs_ns2_vc *nsvc); |
| 448 | void ns2_sns_notify_alive(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, bool alive); |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 449 | void ns2_sns_update_weights(struct gprs_ns2_vc_bind *bind); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 450 | |
| 451 | /* vc */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 452 | struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 453 | const char *id, bool initiate); |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 454 | int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc); |
| 455 | int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc); |
| 456 | int ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp); |
| 457 | int ns2_vc_is_alive(struct gprs_ns2_vc *nsvc); |
| 458 | int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 459 | int ns2_vc_block(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 460 | int ns2_vc_reset(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 461 | int ns2_vc_unblock(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 75b6188 | 2021-03-21 16:18:17 +0100 | [diff] [blame] | 462 | void ns2_vty_dump_nsvc(struct vty *vty, struct gprs_ns2_vc *nsvc, bool stats); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 463 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 464 | /* nse */ |
| 465 | void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked); |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 466 | enum gprs_ns2_vc_mode ns2_dialect_to_vc_mode(enum gprs_ns2_dialect dialect); |
Alexander Couzens | 1c8785d | 2020-12-17 06:58:53 +0100 | [diff] [blame] | 467 | int ns2_count_transfer_cap(struct gprs_ns2_nse *nse, |
| 468 | uint16_t bvci); |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 469 | |
| 470 | /* vty */ |
| 471 | int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse); |