blob: 7ac77e564aaefb70544f5e94a53a704a0570232b [file] [log] [blame]
Alexander Couzens6a161492020-07-12 13:45:50 +02001/*! \file gprs_ns2_internal.h */
2
3#pragma once
4
5#include <stdbool.h>
6#include <stdint.h>
7
Alexander Couzens6cf65d92021-01-18 17:55:35 +01008#include <osmocom/core/logging.h>
Daniel Willmannfa3a9ce2022-11-21 19:27:18 +01009#include <osmocom/core/rate_ctr.h>
Alexander Couzens6a161492020-07-12 13:45:50 +020010#include <osmocom/gprs/protocol/gsm_08_16.h>
11#include <osmocom/gprs/gprs_ns2.h>
12
Harald Weltef2949742021-01-20 14:54:14 +010013#define LOGNSE(nse, lvl, fmt, args ...) \
14 LOGP(DLNS, lvl, "NSE(%05u) " fmt, (nse)->nsei, ## args)
15
16#define LOGBIND(bind, lvl, fmt, args ...) \
17 LOGP(DLNS, lvl, "BIND(%s) " fmt, (bind)->name, ## args)
18
Alexander Couzens6cf65d92021-01-18 17:55:35 +010019#define LOGNSVC_SS(ss, nsvc, lvl, fmt, args ...) \
Harald Weltef2949742021-01-20 14:54:14 +010020 do { \
21 if ((nsvc)->nsvci_is_valid) { \
Alexander Couzens6cf65d92021-01-18 17:55:35 +010022 LOGP(ss, lvl, "NSE(%05u)-NSVC(%05u) " fmt, \
Harald Weltef2949742021-01-20 14:54:14 +010023 (nsvc)->nse->nsei, (nsvc)->nsvci, ## args); \
24 } else { \
Alexander Couzens6cf65d92021-01-18 17:55:35 +010025 LOGP(ss, lvl, "NSE(%05u)-NSVC(none) " fmt, \
Harald Weltef2949742021-01-20 14:54:14 +010026 (nsvc)->nse->nsei, ## args); \
27 } \
28 } while (0)
29
Alexander Couzens6cf65d92021-01-18 17:55:35 +010030#define LOGNSVC(nsvc, lvl, fmt, args ...) \
31 LOGNSVC_SS(DLNS, nsvc, lvl, fmt, ## args)
32
33#define LOG_NS_SIGNAL(nsvc, direction, pdu_type, lvl, fmt, args ...) \
34 LOGNSVC_SS(DLNSSIGNAL, nsvc, lvl, "%s %s" fmt, direction, get_value_string(gprs_ns_pdu_strings, pdu_type), ## args)
35
36#define LOG_NS_DATA(nsvc, direction, pdu_type, lvl, fmt, args ...) \
37 LOGNSVC_SS(DLNSDATA, nsvc, lvl, "%s %s" fmt, direction, get_value_string(gprs_ns_pdu_strings, pdu_type), ## args)
38
39#define LOG_NS_RX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Rx", pdu_type, LOGL_INFO, "\n")
40#define LOG_NS_TX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Tx", pdu_type, LOGL_INFO, "\n")
41
Daniel Willmannefa64f92021-07-09 20:35:00 +020042#define RATE_CTR_INC_NS(nsvc, ctr) \
43 do { \
44 struct gprs_ns2_vc *_nsvc = (nsvc); \
45 rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr)); \
46 rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr)); \
47 } while (0)
48
49#define RATE_CTR_ADD_NS(nsvc, ctr, val) \
50 do { \
51 struct gprs_ns2_vc *_nsvc = (nsvc); \
52 rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr), val); \
53 rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr), val); \
54 } while (0)
55
Alexander Couzens6cf65d92021-01-18 17:55:35 +010056
Alexander Couzens6a161492020-07-12 13:45:50 +020057struct osmo_fsm_inst;
58struct tlv_parsed;
59struct vty;
60
61struct gprs_ns2_vc_driver;
62struct gprs_ns2_vc_bind;
63
Alexander Couzens1f3193d2021-06-05 22:08:11 +020064#define NS_TIMERS_COUNT 11
65#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|tsns-procedures-retries)"
Alexander Couzens6a161492020-07-12 13:45:50 +020066#define NS_TIMERS_HELP \
67 "(un)blocking Timer (Tns-block) timeout\n" \
68 "(un)blocking Timer (Tns-block) number of retries\n" \
69 "Reset Timer (Tns-reset) timeout\n" \
70 "Reset Timer (Tns-reset) number of retries\n" \
71 "Test Timer (Tns-test) timeout\n" \
72 "Alive Timer (Tns-alive) timeout\n" \
73 "Alive Timer (Tns-alive) number of retries\n" \
Alexander Couzens90ee9632020-12-07 06:18:32 +010074 "SNS Provision Timer (Tsns-prov) timeout\n" \
75 "SNS Size number of retries\n" \
76 "SNS Config number of retries\n" \
Alexander Couzens1f3193d2021-06-05 22:08:11 +020077 "SNS Procedures number of retries\n" \
Alexander Couzens6a161492020-07-12 13:45:50 +020078
79/* Educated guess - LLC user payload is 1500 bytes plus possible headers */
80#define NS_ALLOC_SIZE 3072
81#define NS_ALLOC_HEADROOM 20
82
Daniel Willmann3236fdf2023-08-29 16:24:56 +020083#define NS_DEFAULT_TXQUEUE_MAX_LENGTH 128
84
Alexander Couzens6a161492020-07-12 13:45:50 +020085enum ns2_timeout {
86 NS_TOUT_TNS_BLOCK,
87 NS_TOUT_TNS_BLOCK_RETRIES,
88 NS_TOUT_TNS_RESET,
89 NS_TOUT_TNS_RESET_RETRIES,
90 NS_TOUT_TNS_TEST,
91 NS_TOUT_TNS_ALIVE,
92 NS_TOUT_TNS_ALIVE_RETRIES,
93 NS_TOUT_TSNS_PROV,
Alexander Couzens90ee9632020-12-07 06:18:32 +010094 NS_TOUT_TSNS_SIZE_RETRIES,
95 NS_TOUT_TSNS_CONFIG_RETRIES,
Alexander Couzens1f3193d2021-06-05 22:08:11 +020096 NS_TOUT_TSNS_PROCEDURES_RETRIES,
Alexander Couzens6a161492020-07-12 13:45:50 +020097};
98
99enum nsvc_timer_mode {
100 /* standard timers */
101 NSVC_TIMER_TNS_TEST,
102 NSVC_TIMER_TNS_ALIVE,
103 NSVC_TIMER_TNS_RESET,
104 _NSVC_TIMER_NR,
105};
106
Harald Welte76346072021-01-31 11:54:02 +0100107enum ns2_vc_stat {
Alexander Couzens6a161492020-07-12 13:45:50 +0200108 NS_STAT_ALIVE_DELAY,
109};
110
Harald Welte76346072021-01-31 11:54:02 +0100111enum ns2_bind_stat {
112 NS2_BIND_STAT_BACKLOG_LEN,
113};
114
Alexander Couzens6a161492020-07-12 13:45:50 +0200115/*! Osmocom NS2 VC create status */
Alexander Couzensba5a9922021-01-25 16:03:23 +0100116enum ns2_cs {
117 NS2_CS_CREATED, /*!< A NSVC object has been created */
118 NS2_CS_FOUND, /*!< A NSVC object has been found */
119 NS2_CS_REJECTED, /*!< Rejected and answered message */
120 NS2_CS_SKIPPED, /*!< Skipped message */
121 NS2_CS_ERROR, /*!< Failed to process message */
Alexander Couzens6a161492020-07-12 13:45:50 +0200122};
123
Harald Welte3d5eaee2021-01-30 21:33:02 +0100124enum ns_ctr {
125 NS_CTR_PKTS_IN,
126 NS_CTR_PKTS_OUT,
Harald Weltef22ae5a2021-01-30 22:01:28 +0100127 NS_CTR_PKTS_OUT_DROP,
Harald Welte3d5eaee2021-01-30 21:33:02 +0100128 NS_CTR_BYTES_IN,
129 NS_CTR_BYTES_OUT,
Harald Weltef22ae5a2021-01-30 22:01:28 +0100130 NS_CTR_BYTES_OUT_DROP,
Harald Welte3d5eaee2021-01-30 21:33:02 +0100131 NS_CTR_BLOCKED,
Harald Welteb40bf8b2021-01-30 22:43:01 +0100132 NS_CTR_UNBLOCKED,
Harald Welte3d5eaee2021-01-30 21:33:02 +0100133 NS_CTR_DEAD,
134 NS_CTR_REPLACED,
135 NS_CTR_NSEI_CHG,
136 NS_CTR_INV_VCI,
137 NS_CTR_INV_NSEI,
138 NS_CTR_LOST_ALIVE,
139 NS_CTR_LOST_RESET,
140};
Alexander Couzens6a161492020-07-12 13:45:50 +0200141
142#define NSE_S_BLOCKED 0x0001
143#define NSE_S_ALIVE 0x0002
144#define NSE_S_RESET 0x0004
145
146#define NS_DESC_B(st) ((st) & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED")
147#define NS_DESC_A(st) ((st) & NSE_S_ALIVE ? "ALIVE" : "DEAD")
148#define NS_DESC_R(st) ((st) & NSE_S_RESET ? "RESET" : "UNRESET")
149
150/*! An instance of the NS protocol stack */
151struct gprs_ns2_inst {
152 /*! callback to the user for incoming UNIT DATA IND */
153 osmo_prim_cb cb;
154
155 /*! callback data */
156 void *cb_data;
157
158 /*! linked lists of all NSVC binds (e.g. IPv4 bind, but could be also E1 */
159 struct llist_head binding;
160
161 /*! linked lists of all NSVC in this instance */
162 struct llist_head nse;
163
Alexander Couzens6a161492020-07-12 13:45:50 +0200164 uint16_t timeout[NS_TIMERS_COUNT];
165
166 /*! workaround for rate counter until rate counter accepts char str as index */
Harald Welte97ccbf72021-01-31 11:49:19 +0100167 uint32_t nsvc_rate_ctr_idx;
Harald Welte76346072021-01-31 11:54:02 +0100168 uint32_t bind_rate_ctr_idx;
Daniel Willmann3236fdf2023-08-29 16:24:56 +0200169
170 uint32_t txqueue_max_length;
Alexander Couzens6a161492020-07-12 13:45:50 +0200171};
172
Harald Welte53a2fde2020-12-01 22:21:14 +0100173
Alexander Couzens6a161492020-07-12 13:45:50 +0200174/*! Structure repesenting a NSE. The BSS/PCU will only have a single NSE, while SGSN has one for each BSS/PCU */
175struct gprs_ns2_nse {
176 uint16_t nsei;
177
178 /*! entry back to ns2_inst */
179 struct gprs_ns2_inst *nsi;
180
181 /*! llist entry for gprs_ns2_inst */
182 struct llist_head list;
183
184 /*! llist head to hold all nsvc */
185 struct llist_head nsvc;
186
Alexander Couzens8a2a1a42020-12-26 18:00:17 +0100187 /*! count all active NSVCs */
188 int nsvc_count;
Alexander Couzensfc3dd1f2020-11-19 00:41:47 +0100189
Alexander Couzens6a161492020-07-12 13:45:50 +0200190 /*! true if this NSE was created by VTY or pcu socket) */
191 bool persistent;
192
Alexander Couzensda0a2852020-10-01 23:24:07 +0200193 /*! true if this NSE wasn't yet alive at all.
194 * Will be true after the first status ind with NS_AFF_CAUSE_RECOVERY */
195 bool first;
196
Alexander Couzens6a161492020-07-12 13:45:50 +0200197 /*! true if this NSE has at least one alive VC */
198 bool alive;
199
Alexander Couzensaac90162020-11-19 02:44:04 +0100200 /*! which link-layer are we based on? */
201 enum gprs_ns2_ll ll;
202
Alexander Couzensd923cff2020-12-01 01:03:52 +0100203 /*! which dialect does this NSE speaks? */
204 enum gprs_ns2_dialect dialect;
205
Alexander Couzens6a161492020-07-12 13:45:50 +0200206 struct osmo_fsm_inst *bss_sns_fi;
Harald Welte3221f872021-01-18 14:58:51 +0100207
Alexander Couzense052c412021-02-15 02:10:57 +0100208 /*! sum of all the data weight of _alive_ NS-VCs */
Harald Welte3221f872021-01-18 14:58:51 +0100209 uint32_t sum_data_weight;
210
Alexander Couzense052c412021-02-15 02:10:57 +0100211 /*! sum of all the signalling weight of _alive_ NS-VCs */
Harald Welte3221f872021-01-18 14:58:51 +0100212 uint32_t sum_sig_weight;
Alexander Couzens4f1128f2021-01-20 17:42:48 +0100213
214 /*! MTU of a NS PDU. This is the lowest MTU of all NSVCs */
215 uint16_t mtu;
Harald Welte5b034fb2021-03-04 14:16:49 +0100216
217 /*! are we implementing the SGSN role? */
218 bool ip_sns_role_sgsn;
Daniel Willmannefa64f92021-07-09 20:35:00 +0200219
220 /*! NSE-wide statistics */
221 struct rate_ctr_group *ctrg;
Alexander Couzens41589a32021-07-19 03:40:02 +0200222
223 /*! recursive anchor */
224 bool freed;
Alexander Couzens2c64c252021-09-05 23:15:29 +0200225
226 /*! when the NSE became alive or dead */
227 struct timespec ts_alive_change;
Alexander Couzens6a161492020-07-12 13:45:50 +0200228};
229
230/*! Structure representing a single NS-VC */
231struct gprs_ns2_vc {
232 /*! list of NS-VCs within NSE */
233 struct llist_head list;
234
235 /*! list of NS-VCs within bind, bind is the owner! */
236 struct llist_head blist;
237
238 /*! pointer to NS Instance */
239 struct gprs_ns2_nse *nse;
240
241 /*! pointer to NS VL bind. bind own the memory of this instance */
242 struct gprs_ns2_vc_bind *bind;
243
244 /*! true if this NS was created by VTY or pcu socket) */
245 bool persistent;
246
247 /*! uniquely identifies NS-VC if VC contains nsvci */
248 uint16_t nsvci;
249
250 /*! signalling weight. 0 = don't use for signalling (BVCI == 0)*/
251 uint8_t sig_weight;
252
Alexander Couzensfc3dd1f2020-11-19 00:41:47 +0100253 /*! signalling packet counter for the load sharing function */
254 uint8_t sig_counter;
255
256 /*! data weight. 0 = don't use for user data (BVCI != 0) */
Alexander Couzens6a161492020-07-12 13:45:50 +0200257 uint8_t data_weight;
258
259 /*! can be used by the bind/driver of the virtual circuit. e.g. ipv4/ipv6/frgre/e1 */
260 void *priv;
261
262 bool nsvci_is_valid;
Harald Weltec962a2e2021-03-05 08:09:08 +0100263 /*! should this NS-VC only be used for SNS-SIZE and SNS-CONFIG? */
Alexander Couzens6a161492020-07-12 13:45:50 +0200264 bool sns_only;
265
266 struct rate_ctr_group *ctrg;
267 struct osmo_stat_item_group *statg;
268
Alexander Couzens6a161492020-07-12 13:45:50 +0200269 enum gprs_ns2_vc_mode mode;
270
271 struct osmo_fsm_inst *fi;
Alexander Couzens41589a32021-07-19 03:40:02 +0200272
273 /*! recursive anchor */
274 bool freed;
Alexander Couzensca5ce0d2021-09-05 23:15:56 +0200275
arehbein0d9b6b02022-10-27 18:28:52 +0200276 /*! if blocked by O&M/vty */
277 bool om_blocked;
278
Alexander Couzensca5ce0d2021-09-05 23:15:56 +0200279 /*! when the NSVC became alive or dead */
280 struct timespec ts_alive_change;
Alexander Couzens6a161492020-07-12 13:45:50 +0200281};
282
283/*! Structure repesenting a bind instance. E.g. IPv4 listen port. */
284struct gprs_ns2_vc_bind {
Alexander Couzensaaa55a62020-12-03 06:02:03 +0100285 /*! unique name */
286 const char *name;
Alexander Couzens6a161492020-07-12 13:45:50 +0200287 /*! list entry in nsi */
288 struct llist_head list;
289 /*! list of all VC */
290 struct llist_head nsvc;
291 /*! driver private structure */
292 void *priv;
293 /*! a pointer back to the nsi */
294 struct gprs_ns2_inst *nsi;
295 struct gprs_ns2_vc_driver *driver;
296
Alexander Couzensd923cff2020-12-01 01:03:52 +0100297 bool accept_ipaccess;
298 bool accept_sns;
Alexander Couzens6a161492020-07-12 13:45:50 +0200299
Alexander Couzens1c8785d2020-12-17 06:58:53 +0100300 /*! transfer capability in mbit */
301 int transfer_capability;
302
Alexander Couzens4f1128f2021-01-20 17:42:48 +0100303 /*! MTU of a NS PDU on this bind. */
304 uint16_t mtu;
305
Alexander Couzensaac90162020-11-19 02:44:04 +0100306 /*! which link-layer are we based on? */
307 enum gprs_ns2_ll ll;
308
Alexander Couzens6a161492020-07-12 13:45:50 +0200309 /*! send a msg over a VC */
310 int (*send_vc)(struct gprs_ns2_vc *nsvc, struct msgb *msg);
311
312 /*! free the vc priv data */
313 void (*free_vc)(struct gprs_ns2_vc *nsvc);
Alexander Couzens6a161492020-07-12 13:45:50 +0200314
Alexander Couzens22f34712020-10-02 02:34:39 +0200315 /*! allow to show information for the vty */
316 void (*dump_vty)(const struct gprs_ns2_vc_bind *bind,
317 struct vty *vty, bool stats);
Harald Welte76346072021-01-31 11:54:02 +0100318
Alexander Couzensc4704762021-02-08 23:13:12 +0100319 /*! the IP-SNS signalling weight when doing dynamic configuration */
320 uint8_t sns_sig_weight;
321 /*! the IP-SNS data weight when doing dynamic configuration */
322 uint8_t sns_data_weight;
323
Harald Welte76346072021-01-31 11:54:02 +0100324 struct osmo_stat_item_group *statg;
Alexander Couzens41589a32021-07-19 03:40:02 +0200325
326 /*! recursive anchor */
327 bool freed;
Alexander Couzens22f34712020-10-02 02:34:39 +0200328};
Alexander Couzens6a161492020-07-12 13:45:50 +0200329
330struct gprs_ns2_vc_driver {
331 const char *name;
332 void *priv;
333 void (*free_bind)(struct gprs_ns2_vc_bind *driver);
334};
335
Alexander Couzens175eb7b2021-07-20 18:41:14 +0200336enum ns2_sns_event {
337 NS2_SNS_EV_REQ_SELECT_ENDPOINT, /*!< Select a SNS endpoint from the list */
338 NS2_SNS_EV_RX_SIZE,
339 NS2_SNS_EV_RX_SIZE_ACK,
340 NS2_SNS_EV_RX_CONFIG,
341 NS2_SNS_EV_RX_CONFIG_END, /*!< SNS-CONFIG with end flag received */
342 NS2_SNS_EV_RX_CONFIG_ACK,
343 NS2_SNS_EV_RX_ADD,
344 NS2_SNS_EV_RX_DELETE,
345 NS2_SNS_EV_RX_CHANGE_WEIGHT,
346 NS2_SNS_EV_RX_ACK, /*!< Rx of SNS-ACK (response to ADD/DELETE/CHG_WEIGHT */
347 NS2_SNS_EV_REQ_NO_NSVC, /*!< no more NS-VC remaining (all dead) */
Alexander Couzens83f06ce2021-08-06 19:50:09 +0200348 NS2_SNS_EV_REQ_FREE_NSVCS, /*!< free all NS-VCs */
Alexander Couzens175eb7b2021-07-20 18:41:14 +0200349 NS2_SNS_EV_REQ_NSVC_ALIVE, /*!< a NS-VC became alive */
350 NS2_SNS_EV_REQ_ADD_BIND, /*!< add a new local bind to this NSE */
351 NS2_SNS_EV_REQ_DELETE_BIND, /*!< remove a local bind from this NSE */
Alexander Couzens1f3193d2021-06-05 22:08:11 +0200352 NS2_SNS_EV_REQ_CHANGE_WEIGHT, /*!< a bind changed its weight */
Alexander Couzens175eb7b2021-07-20 18:41:14 +0200353};
354
Alexander Couzensba5a9922021-01-25 16:03:23 +0100355enum ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind,
Alexander Couzens6a161492020-07-12 13:45:50 +0200356 struct msgb *msg,
Harald Welte7d0daac2021-03-02 23:08:43 +0100357 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200358 const char *logname,
359 struct msgb **reject,
360 struct gprs_ns2_vc **success);
361
Alexander Couzensffd49d02020-09-24 00:47:17 +0200362int ns2_recv_vc(struct gprs_ns2_vc *nsvc,
Alexander Couzens6a161492020-07-12 13:45:50 +0200363 struct msgb *msg);
364
365struct gprs_ns2_vc *ns2_vc_alloc(struct gprs_ns2_vc_bind *bind,
366 struct gprs_ns2_nse *nse,
Alexander Couzensd923cff2020-12-01 01:03:52 +0100367 bool initiater,
Harald Welte603f4042020-11-29 17:39:19 +0100368 enum gprs_ns2_vc_mode vc_mode,
369 const char *id);
Alexander Couzens6a161492020-07-12 13:45:50 +0200370
Alexander Couzensf0746592021-07-20 19:05:45 +0200371void ns2_free_nsvcs(struct gprs_ns2_nse *nse);
Harald Weltec3aa8f92021-01-31 11:41:34 +0100372int ns2_bind_alloc(struct gprs_ns2_inst *nsi, const char *name,
373 struct gprs_ns2_vc_bind **result);
374
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100375struct msgb *ns2_msgb_alloc(void);
Alexander Couzens6a161492020-07-12 13:45:50 +0200376
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100377void ns2_sns_write_vty(struct vty *vty, const struct gprs_ns2_nse *nse);
378void ns2_sns_dump_vty(struct vty *vty, const char *prefix, const struct gprs_ns2_nse *nse, bool stats);
Alexander Couzensbf95f0f2020-10-01 22:56:03 +0200379void ns2_prim_status_ind(struct gprs_ns2_nse *nse,
Daniel Willmann15c09a82020-11-03 23:05:43 +0100380 struct gprs_ns2_vc *nsvc,
Alexander Couzensbf95f0f2020-10-01 22:56:03 +0200381 uint16_t bvci,
Alexander Couzens6a161492020-07-12 13:45:50 +0200382 enum gprs_ns2_affecting_cause cause);
383void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive);
Alexander Couzens4f1128f2021-01-20 17:42:48 +0100384void ns2_nse_update_mtu(struct gprs_ns2_nse *nse);
Harald Welte06d9bf92021-03-05 10:20:11 +0100385int ns2_nse_set_dialect(struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect);
Alexander Couzens6a161492020-07-12 13:45:50 +0200386
387/* message */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100388int ns2_validate(struct gprs_ns2_vc *nsvc,
389 uint8_t pdu_type,
390 struct msgb *msg,
391 struct tlv_parsed *tp,
392 uint8_t *cause);
Alexander Couzens6a161492020-07-12 13:45:50 +0200393
394/* SNS messages */
395int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause,
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);
400int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag,
401 const struct gprs_ns_ie_ip4_elem *ip4_elems,
402 unsigned int num_ip4_elems,
403 const struct gprs_ns_ie_ip6_elem *ip6_elems,
404 unsigned int num_ip6_elems);
405int ns2_tx_sns_config_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
406int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_nsvc,
407 int ip4_ep_nr, int ip6_ep_nr);
408int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
409
Alexander Couzens27a55922021-02-27 01:08:35 +0100410int ns2_tx_sns_add(struct gprs_ns2_vc *nsvc,
411 uint8_t trans_id,
412 const struct gprs_ns_ie_ip4_elem *ip4_elems,
413 unsigned int num_ip4_elems,
414 const struct gprs_ns_ie_ip6_elem *ip6_elems,
415 unsigned int num_ip6_elems);
416int ns2_tx_sns_change_weight(struct gprs_ns2_vc *nsvc,
417 uint8_t trans_id,
418 const struct gprs_ns_ie_ip4_elem *ip4_elems,
419 unsigned int num_ip4_elems,
420 const struct gprs_ns_ie_ip6_elem *ip6_elems,
421 unsigned int num_ip6_elems);
422int ns2_tx_sns_del(struct gprs_ns2_vc *nsvc,
423 uint8_t trans_id,
424 const struct gprs_ns_ie_ip4_elem *ip4_elems,
425 unsigned int num_ip4_elems,
426 const struct gprs_ns_ie_ip6_elem *ip6_elems,
427 unsigned int num_ip6_elems);
428
Alexander Couzens6a161492020-07-12 13:45:50 +0200429/* transmit message over a VC */
Alexander Couzens67cfc5d2021-09-07 01:10:38 +0200430int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause, uint16_t *nsvci);
431int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc, uint16_t *nsvci);
Alexander Couzens6a161492020-07-12 13:45:50 +0200432
433int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause);
434int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc);
435
436int ns2_tx_unblock(struct gprs_ns2_vc *nsvc);
437int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc);
438
439int ns2_tx_alive(struct gprs_ns2_vc *nsvc);
440int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc);
441
442int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc,
443 uint16_t bvci, uint8_t sducontrol,
444 struct msgb *msg);
445
446int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause,
Alexander Couzensd802f9a2021-09-23 16:19:32 +0200447 uint16_t bvci, struct msgb *orig_msg, uint16_t *nsvci);
Alexander Couzens6a161492020-07-12 13:45:50 +0200448
449/* driver */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100450struct gprs_ns2_vc *ns2_ip_bind_connect(struct gprs_ns2_vc_bind *bind,
451 struct gprs_ns2_nse *nse,
452 const struct osmo_sockaddr *remote);
Alexander Couzense769f522020-12-07 07:37:07 +0100453int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote);
454struct gprs_ns2_vc_bind *ns2_ip_get_bind_by_index(struct gprs_ns2_inst *nsi,
455 struct osmo_sockaddr *remote,
456 int index);
Daniel Willmann3236fdf2023-08-29 16:24:56 +0200457void ns2_ip_set_txqueue_max_length(struct gprs_ns2_vc_bind *bind, unsigned int max_length);
Alexander Couzens6a161492020-07-12 13:45:50 +0200458
459/* sns */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100460int ns2_sns_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200461struct osmo_fsm_inst *ns2_sns_bss_fsm_alloc(struct gprs_ns2_nse *nse,
462 const char *id);
Harald Welte4f127462021-03-02 20:49:10 +0100463struct osmo_fsm_inst *ns2_sns_sgsn_fsm_alloc(struct gprs_ns2_nse *nse, const char *id);
Alexander Couzensbe7cecc2021-02-03 18:25:27 +0100464void ns2_sns_replace_nsvc(struct gprs_ns2_vc *nsvc);
465void ns2_sns_notify_alive(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, bool alive);
Alexander Couzensc4704762021-02-08 23:13:12 +0100466void ns2_sns_update_weights(struct gprs_ns2_vc_bind *bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200467
468/* vc */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100469struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc,
Alexander Couzens6a161492020-07-12 13:45:50 +0200470 const char *id, bool initiate);
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100471int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc);
472int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc);
473int ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
474int ns2_vc_is_alive(struct gprs_ns2_vc *nsvc);
475int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc);
Alexander Couzens47afc422021-01-17 20:12:46 +0100476int ns2_vc_block(struct gprs_ns2_vc *nsvc);
Alexander Couzens27e58732021-03-21 17:12:08 +0100477int ns2_vc_reset(struct gprs_ns2_vc *nsvc);
Alexander Couzens47afc422021-01-17 20:12:46 +0100478int ns2_vc_unblock(struct gprs_ns2_vc *nsvc);
Alexander Couzens75b61882021-03-21 16:18:17 +0100479void ns2_vty_dump_nsvc(struct vty *vty, struct gprs_ns2_vc *nsvc, bool stats);
Alexander Couzens6a161492020-07-12 13:45:50 +0200480
Alexander Couzens6a161492020-07-12 13:45:50 +0200481/* nse */
482void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked);
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100483enum gprs_ns2_vc_mode ns2_dialect_to_vc_mode(enum gprs_ns2_dialect dialect);
Alexander Couzens1c8785d2020-12-17 06:58:53 +0100484int ns2_count_transfer_cap(struct gprs_ns2_nse *nse,
485 uint16_t bvci);
Harald Welted164ef82021-03-04 22:29:17 +0100486
487/* vty */
488int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse);