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