blob: bfb12d9dc8ae735daa0c67c3826594a66f2c549a [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>
Alexander Couzens6a161492020-07-12 13:45:50 +02009#include <osmocom/gprs/protocol/gsm_08_16.h>
10#include <osmocom/gprs/gprs_ns2.h>
11
Harald Weltef2949742021-01-20 14:54:14 +010012#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 Couzens6cf65d92021-01-18 17:55:35 +010018#define LOGNSVC_SS(ss, nsvc, lvl, fmt, args ...) \
Harald Weltef2949742021-01-20 14:54:14 +010019 do { \
20 if ((nsvc)->nsvci_is_valid) { \
Alexander Couzens6cf65d92021-01-18 17:55:35 +010021 LOGP(ss, lvl, "NSE(%05u)-NSVC(%05u) " fmt, \
Harald Weltef2949742021-01-20 14:54:14 +010022 (nsvc)->nse->nsei, (nsvc)->nsvci, ## args); \
23 } else { \
Alexander Couzens6cf65d92021-01-18 17:55:35 +010024 LOGP(ss, lvl, "NSE(%05u)-NSVC(none) " fmt, \
Harald Weltef2949742021-01-20 14:54:14 +010025 (nsvc)->nse->nsei, ## args); \
26 } \
27 } while (0)
28
Alexander Couzens6cf65d92021-01-18 17:55:35 +010029#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 Willmannefa64f92021-07-09 20:35:00 +020041#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 Couzens6cf65d92021-01-18 17:55:35 +010055
Alexander Couzens6a161492020-07-12 13:45:50 +020056struct osmo_fsm_inst;
57struct tlv_parsed;
58struct vty;
59
60struct gprs_ns2_vc_driver;
61struct gprs_ns2_vc_bind;
62
Alexander Couzens1f3193d2021-06-05 22:08:11 +020063#define NS_TIMERS_COUNT 11
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|tsns-procedures-retries)"
Alexander Couzens6a161492020-07-12 13:45:50 +020065#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 Couzens90ee9632020-12-07 06:18:32 +010073 "SNS Provision Timer (Tsns-prov) timeout\n" \
74 "SNS Size number of retries\n" \
75 "SNS Config number of retries\n" \
Alexander Couzens1f3193d2021-06-05 22:08:11 +020076 "SNS Procedures number of retries\n" \
Alexander Couzens6a161492020-07-12 13:45:50 +020077
78/* Educated guess - LLC user payload is 1500 bytes plus possible headers */
79#define NS_ALLOC_SIZE 3072
80#define NS_ALLOC_HEADROOM 20
81
82enum ns2_timeout {
83 NS_TOUT_TNS_BLOCK,
84 NS_TOUT_TNS_BLOCK_RETRIES,
85 NS_TOUT_TNS_RESET,
86 NS_TOUT_TNS_RESET_RETRIES,
87 NS_TOUT_TNS_TEST,
88 NS_TOUT_TNS_ALIVE,
89 NS_TOUT_TNS_ALIVE_RETRIES,
90 NS_TOUT_TSNS_PROV,
Alexander Couzens90ee9632020-12-07 06:18:32 +010091 NS_TOUT_TSNS_SIZE_RETRIES,
92 NS_TOUT_TSNS_CONFIG_RETRIES,
Alexander Couzens1f3193d2021-06-05 22:08:11 +020093 NS_TOUT_TSNS_PROCEDURES_RETRIES,
Alexander Couzens6a161492020-07-12 13:45:50 +020094};
95
96enum nsvc_timer_mode {
97 /* standard timers */
98 NSVC_TIMER_TNS_TEST,
99 NSVC_TIMER_TNS_ALIVE,
100 NSVC_TIMER_TNS_RESET,
101 _NSVC_TIMER_NR,
102};
103
Harald Welte76346072021-01-31 11:54:02 +0100104enum ns2_vc_stat {
Alexander Couzens6a161492020-07-12 13:45:50 +0200105 NS_STAT_ALIVE_DELAY,
106};
107
Harald Welte76346072021-01-31 11:54:02 +0100108enum ns2_bind_stat {
109 NS2_BIND_STAT_BACKLOG_LEN,
110};
111
Alexander Couzens6a161492020-07-12 13:45:50 +0200112/*! Osmocom NS2 VC create status */
Alexander Couzensba5a9922021-01-25 16:03:23 +0100113enum ns2_cs {
114 NS2_CS_CREATED, /*!< A NSVC object has been created */
115 NS2_CS_FOUND, /*!< A NSVC object has been found */
116 NS2_CS_REJECTED, /*!< Rejected and answered message */
117 NS2_CS_SKIPPED, /*!< Skipped message */
118 NS2_CS_ERROR, /*!< Failed to process message */
Alexander Couzens6a161492020-07-12 13:45:50 +0200119};
120
Harald Welte3d5eaee2021-01-30 21:33:02 +0100121enum ns_ctr {
122 NS_CTR_PKTS_IN,
123 NS_CTR_PKTS_OUT,
Harald Weltef22ae5a2021-01-30 22:01:28 +0100124 NS_CTR_PKTS_OUT_DROP,
Harald Welte3d5eaee2021-01-30 21:33:02 +0100125 NS_CTR_BYTES_IN,
126 NS_CTR_BYTES_OUT,
Harald Weltef22ae5a2021-01-30 22:01:28 +0100127 NS_CTR_BYTES_OUT_DROP,
Harald Welte3d5eaee2021-01-30 21:33:02 +0100128 NS_CTR_BLOCKED,
Harald Welteb40bf8b2021-01-30 22:43:01 +0100129 NS_CTR_UNBLOCKED,
Harald Welte3d5eaee2021-01-30 21:33:02 +0100130 NS_CTR_DEAD,
131 NS_CTR_REPLACED,
132 NS_CTR_NSEI_CHG,
133 NS_CTR_INV_VCI,
134 NS_CTR_INV_NSEI,
135 NS_CTR_LOST_ALIVE,
136 NS_CTR_LOST_RESET,
137};
Alexander Couzens6a161492020-07-12 13:45:50 +0200138
139#define NSE_S_BLOCKED 0x0001
140#define NSE_S_ALIVE 0x0002
141#define NSE_S_RESET 0x0004
142
143#define NS_DESC_B(st) ((st) & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED")
144#define NS_DESC_A(st) ((st) & NSE_S_ALIVE ? "ALIVE" : "DEAD")
145#define NS_DESC_R(st) ((st) & NSE_S_RESET ? "RESET" : "UNRESET")
146
147/*! An instance of the NS protocol stack */
148struct gprs_ns2_inst {
149 /*! callback to the user for incoming UNIT DATA IND */
150 osmo_prim_cb cb;
151
152 /*! callback data */
153 void *cb_data;
154
155 /*! linked lists of all NSVC binds (e.g. IPv4 bind, but could be also E1 */
156 struct llist_head binding;
157
158 /*! linked lists of all NSVC in this instance */
159 struct llist_head nse;
160
Alexander Couzens6a161492020-07-12 13:45:50 +0200161 uint16_t timeout[NS_TIMERS_COUNT];
162
163 /*! workaround for rate counter until rate counter accepts char str as index */
Harald Welte97ccbf72021-01-31 11:49:19 +0100164 uint32_t nsvc_rate_ctr_idx;
Harald Welte76346072021-01-31 11:54:02 +0100165 uint32_t bind_rate_ctr_idx;
Harald Welte53a2fde2020-12-01 22:21:14 +0100166
167 /*! libmnl netlink socket for link state monitoring */
168 struct osmo_mnl *linkmon_mnl;
Alexander Couzens6a161492020-07-12 13:45:50 +0200169};
170
Harald Welte53a2fde2020-12-01 22:21:14 +0100171
Alexander Couzens6a161492020-07-12 13:45:50 +0200172/*! Structure repesenting a NSE. The BSS/PCU will only have a single NSE, while SGSN has one for each BSS/PCU */
173struct gprs_ns2_nse {
174 uint16_t nsei;
175
176 /*! entry back to ns2_inst */
177 struct gprs_ns2_inst *nsi;
178
179 /*! llist entry for gprs_ns2_inst */
180 struct llist_head list;
181
182 /*! llist head to hold all nsvc */
183 struct llist_head nsvc;
184
Alexander Couzens8a2a1a42020-12-26 18:00:17 +0100185 /*! count all active NSVCs */
186 int nsvc_count;
Alexander Couzensfc3dd1f2020-11-19 00:41:47 +0100187
Alexander Couzens6a161492020-07-12 13:45:50 +0200188 /*! true if this NSE was created by VTY or pcu socket) */
189 bool persistent;
190
Alexander Couzensda0a2852020-10-01 23:24:07 +0200191 /*! true if this NSE wasn't yet alive at all.
192 * Will be true after the first status ind with NS_AFF_CAUSE_RECOVERY */
193 bool first;
194
Alexander Couzens6a161492020-07-12 13:45:50 +0200195 /*! true if this NSE has at least one alive VC */
196 bool alive;
197
Alexander Couzensaac90162020-11-19 02:44:04 +0100198 /*! which link-layer are we based on? */
199 enum gprs_ns2_ll ll;
200
Alexander Couzensd923cff2020-12-01 01:03:52 +0100201 /*! which dialect does this NSE speaks? */
202 enum gprs_ns2_dialect dialect;
203
Alexander Couzens6a161492020-07-12 13:45:50 +0200204 struct osmo_fsm_inst *bss_sns_fi;
Harald Welte3221f872021-01-18 14:58:51 +0100205
Alexander Couzense052c412021-02-15 02:10:57 +0100206 /*! sum of all the data weight of _alive_ NS-VCs */
Harald Welte3221f872021-01-18 14:58:51 +0100207 uint32_t sum_data_weight;
208
Alexander Couzense052c412021-02-15 02:10:57 +0100209 /*! sum of all the signalling weight of _alive_ NS-VCs */
Harald Welte3221f872021-01-18 14:58:51 +0100210 uint32_t sum_sig_weight;
Alexander Couzens4f1128f2021-01-20 17:42:48 +0100211
212 /*! MTU of a NS PDU. This is the lowest MTU of all NSVCs */
213 uint16_t mtu;
Harald Welte5b034fb2021-03-04 14:16:49 +0100214
215 /*! are we implementing the SGSN role? */
216 bool ip_sns_role_sgsn;
Daniel Willmannefa64f92021-07-09 20:35:00 +0200217
218 /*! NSE-wide statistics */
219 struct rate_ctr_group *ctrg;
Alexander Couzens41589a32021-07-19 03:40:02 +0200220
221 /*! recursive anchor */
222 bool freed;
Alexander Couzens2c64c252021-09-05 23:15:29 +0200223
224 /*! when the NSE became alive or dead */
225 struct timespec ts_alive_change;
Alexander Couzens6a161492020-07-12 13:45:50 +0200226};
227
228/*! Structure representing a single NS-VC */
229struct gprs_ns2_vc {
230 /*! list of NS-VCs within NSE */
231 struct llist_head list;
232
233 /*! list of NS-VCs within bind, bind is the owner! */
234 struct llist_head blist;
235
236 /*! pointer to NS Instance */
237 struct gprs_ns2_nse *nse;
238
239 /*! pointer to NS VL bind. bind own the memory of this instance */
240 struct gprs_ns2_vc_bind *bind;
241
242 /*! true if this NS was created by VTY or pcu socket) */
243 bool persistent;
244
245 /*! uniquely identifies NS-VC if VC contains nsvci */
246 uint16_t nsvci;
247
248 /*! signalling weight. 0 = don't use for signalling (BVCI == 0)*/
249 uint8_t sig_weight;
250
Alexander Couzensfc3dd1f2020-11-19 00:41:47 +0100251 /*! signalling packet counter for the load sharing function */
252 uint8_t sig_counter;
253
254 /*! data weight. 0 = don't use for user data (BVCI != 0) */
Alexander Couzens6a161492020-07-12 13:45:50 +0200255 uint8_t data_weight;
256
257 /*! can be used by the bind/driver of the virtual circuit. e.g. ipv4/ipv6/frgre/e1 */
258 void *priv;
259
260 bool nsvci_is_valid;
Harald Weltec962a2e2021-03-05 08:09:08 +0100261 /*! should this NS-VC only be used for SNS-SIZE and SNS-CONFIG? */
Alexander Couzens6a161492020-07-12 13:45:50 +0200262 bool sns_only;
263
264 struct rate_ctr_group *ctrg;
265 struct osmo_stat_item_group *statg;
266
Alexander Couzens6a161492020-07-12 13:45:50 +0200267 enum gprs_ns2_vc_mode mode;
268
269 struct osmo_fsm_inst *fi;
Alexander Couzens41589a32021-07-19 03:40:02 +0200270
271 /*! recursive anchor */
272 bool freed;
Alexander Couzensca5ce0d2021-09-05 23:15:56 +0200273
274 /*! when the NSVC became alive or dead */
275 struct timespec ts_alive_change;
Alexander Couzens6a161492020-07-12 13:45:50 +0200276};
277
278/*! Structure repesenting a bind instance. E.g. IPv4 listen port. */
279struct gprs_ns2_vc_bind {
Alexander Couzensaaa55a62020-12-03 06:02:03 +0100280 /*! unique name */
281 const char *name;
Alexander Couzens6a161492020-07-12 13:45:50 +0200282 /*! list entry in nsi */
283 struct llist_head list;
284 /*! list of all VC */
285 struct llist_head nsvc;
286 /*! driver private structure */
287 void *priv;
288 /*! a pointer back to the nsi */
289 struct gprs_ns2_inst *nsi;
290 struct gprs_ns2_vc_driver *driver;
291
Alexander Couzensd923cff2020-12-01 01:03:52 +0100292 bool accept_ipaccess;
293 bool accept_sns;
Alexander Couzens6a161492020-07-12 13:45:50 +0200294
Alexander Couzens1c8785d2020-12-17 06:58:53 +0100295 /*! transfer capability in mbit */
296 int transfer_capability;
297
Alexander Couzens4f1128f2021-01-20 17:42:48 +0100298 /*! MTU of a NS PDU on this bind. */
299 uint16_t mtu;
300
Alexander Couzensaac90162020-11-19 02:44:04 +0100301 /*! which link-layer are we based on? */
302 enum gprs_ns2_ll ll;
303
Alexander Couzens6a161492020-07-12 13:45:50 +0200304 /*! send a msg over a VC */
305 int (*send_vc)(struct gprs_ns2_vc *nsvc, struct msgb *msg);
306
307 /*! free the vc priv data */
308 void (*free_vc)(struct gprs_ns2_vc *nsvc);
Alexander Couzens6a161492020-07-12 13:45:50 +0200309
Alexander Couzens22f34712020-10-02 02:34:39 +0200310 /*! allow to show information for the vty */
311 void (*dump_vty)(const struct gprs_ns2_vc_bind *bind,
312 struct vty *vty, bool stats);
Harald Welte76346072021-01-31 11:54:02 +0100313
Alexander Couzensc4704762021-02-08 23:13:12 +0100314 /*! the IP-SNS signalling weight when doing dynamic configuration */
315 uint8_t sns_sig_weight;
316 /*! the IP-SNS data weight when doing dynamic configuration */
317 uint8_t sns_data_weight;
318
Harald Welte76346072021-01-31 11:54:02 +0100319 struct osmo_stat_item_group *statg;
Alexander Couzens41589a32021-07-19 03:40:02 +0200320
321 /*! recursive anchor */
322 bool freed;
Alexander Couzens22f34712020-10-02 02:34:39 +0200323};
Alexander Couzens6a161492020-07-12 13:45:50 +0200324
325struct gprs_ns2_vc_driver {
326 const char *name;
327 void *priv;
328 void (*free_bind)(struct gprs_ns2_vc_bind *driver);
329};
330
Alexander Couzens175eb7b2021-07-20 18:41:14 +0200331enum ns2_sns_event {
332 NS2_SNS_EV_REQ_SELECT_ENDPOINT, /*!< Select a SNS endpoint from the list */
333 NS2_SNS_EV_RX_SIZE,
334 NS2_SNS_EV_RX_SIZE_ACK,
335 NS2_SNS_EV_RX_CONFIG,
336 NS2_SNS_EV_RX_CONFIG_END, /*!< SNS-CONFIG with end flag received */
337 NS2_SNS_EV_RX_CONFIG_ACK,
338 NS2_SNS_EV_RX_ADD,
339 NS2_SNS_EV_RX_DELETE,
340 NS2_SNS_EV_RX_CHANGE_WEIGHT,
341 NS2_SNS_EV_RX_ACK, /*!< Rx of SNS-ACK (response to ADD/DELETE/CHG_WEIGHT */
342 NS2_SNS_EV_REQ_NO_NSVC, /*!< no more NS-VC remaining (all dead) */
Alexander Couzens83f06ce2021-08-06 19:50:09 +0200343 NS2_SNS_EV_REQ_FREE_NSVCS, /*!< free all NS-VCs */
Alexander Couzens175eb7b2021-07-20 18:41:14 +0200344 NS2_SNS_EV_REQ_NSVC_ALIVE, /*!< a NS-VC became alive */
345 NS2_SNS_EV_REQ_ADD_BIND, /*!< add a new local bind to this NSE */
346 NS2_SNS_EV_REQ_DELETE_BIND, /*!< remove a local bind from this NSE */
Alexander Couzens1f3193d2021-06-05 22:08:11 +0200347 NS2_SNS_EV_REQ_CHANGE_WEIGHT, /*!< a bind changed its weight */
Alexander Couzens175eb7b2021-07-20 18:41:14 +0200348};
349
Alexander Couzensba5a9922021-01-25 16:03:23 +0100350enum ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind,
Alexander Couzens6a161492020-07-12 13:45:50 +0200351 struct msgb *msg,
Harald Welte7d0daac2021-03-02 23:08:43 +0100352 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200353 const char *logname,
354 struct msgb **reject,
355 struct gprs_ns2_vc **success);
356
Alexander Couzensffd49d02020-09-24 00:47:17 +0200357int ns2_recv_vc(struct gprs_ns2_vc *nsvc,
Alexander Couzens6a161492020-07-12 13:45:50 +0200358 struct msgb *msg);
359
360struct gprs_ns2_vc *ns2_vc_alloc(struct gprs_ns2_vc_bind *bind,
361 struct gprs_ns2_nse *nse,
Alexander Couzensd923cff2020-12-01 01:03:52 +0100362 bool initiater,
Harald Welte603f4042020-11-29 17:39:19 +0100363 enum gprs_ns2_vc_mode vc_mode,
364 const char *id);
Alexander Couzens6a161492020-07-12 13:45:50 +0200365
Alexander Couzensf0746592021-07-20 19:05:45 +0200366void ns2_free_nsvcs(struct gprs_ns2_nse *nse);
Harald Weltec3aa8f92021-01-31 11:41:34 +0100367int ns2_bind_alloc(struct gprs_ns2_inst *nsi, const char *name,
368 struct gprs_ns2_vc_bind **result);
369
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100370struct msgb *ns2_msgb_alloc(void);
Alexander Couzens6a161492020-07-12 13:45:50 +0200371
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100372void ns2_sns_write_vty(struct vty *vty, const struct gprs_ns2_nse *nse);
373void 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 +0200374void ns2_prim_status_ind(struct gprs_ns2_nse *nse,
Daniel Willmann15c09a82020-11-03 23:05:43 +0100375 struct gprs_ns2_vc *nsvc,
Alexander Couzensbf95f0f2020-10-01 22:56:03 +0200376 uint16_t bvci,
Alexander Couzens6a161492020-07-12 13:45:50 +0200377 enum gprs_ns2_affecting_cause cause);
378void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive);
Alexander Couzens4f1128f2021-01-20 17:42:48 +0100379void ns2_nse_update_mtu(struct gprs_ns2_nse *nse);
Harald Welte06d9bf92021-03-05 10:20:11 +0100380int ns2_nse_set_dialect(struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect);
Alexander Couzens6a161492020-07-12 13:45:50 +0200381
382/* message */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100383int ns2_validate(struct gprs_ns2_vc *nsvc,
384 uint8_t pdu_type,
385 struct msgb *msg,
386 struct tlv_parsed *tp,
387 uint8_t *cause);
Alexander Couzens6a161492020-07-12 13:45:50 +0200388
389/* SNS messages */
390int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause,
391 const struct gprs_ns_ie_ip4_elem *ip4_elems,
392 unsigned int num_ip4_elems,
393 const struct gprs_ns_ie_ip6_elem *ip6_elems,
394 unsigned int num_ip6_elems);
395int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag,
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_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
401int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_nsvc,
402 int ip4_ep_nr, int ip6_ep_nr);
403int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
404
Alexander Couzens27a55922021-02-27 01:08:35 +0100405int ns2_tx_sns_add(struct gprs_ns2_vc *nsvc,
406 uint8_t trans_id,
407 const struct gprs_ns_ie_ip4_elem *ip4_elems,
408 unsigned int num_ip4_elems,
409 const struct gprs_ns_ie_ip6_elem *ip6_elems,
410 unsigned int num_ip6_elems);
411int ns2_tx_sns_change_weight(struct gprs_ns2_vc *nsvc,
412 uint8_t trans_id,
413 const struct gprs_ns_ie_ip4_elem *ip4_elems,
414 unsigned int num_ip4_elems,
415 const struct gprs_ns_ie_ip6_elem *ip6_elems,
416 unsigned int num_ip6_elems);
417int ns2_tx_sns_del(struct gprs_ns2_vc *nsvc,
418 uint8_t trans_id,
419 const struct gprs_ns_ie_ip4_elem *ip4_elems,
420 unsigned int num_ip4_elems,
421 const struct gprs_ns_ie_ip6_elem *ip6_elems,
422 unsigned int num_ip6_elems);
423
Alexander Couzens6a161492020-07-12 13:45:50 +0200424/* transmit message over a VC */
425int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause);
426int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc);
427
428int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause);
429int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc);
430
431int ns2_tx_unblock(struct gprs_ns2_vc *nsvc);
432int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc);
433
434int ns2_tx_alive(struct gprs_ns2_vc *nsvc);
435int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc);
436
437int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc,
438 uint16_t bvci, uint8_t sducontrol,
439 struct msgb *msg);
440
441int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause,
442 uint16_t bvci, struct msgb *orig_msg);
443
444/* driver */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100445struct gprs_ns2_vc *ns2_ip_bind_connect(struct gprs_ns2_vc_bind *bind,
446 struct gprs_ns2_nse *nse,
447 const struct osmo_sockaddr *remote);
Alexander Couzense769f522020-12-07 07:37:07 +0100448int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote);
449struct gprs_ns2_vc_bind *ns2_ip_get_bind_by_index(struct gprs_ns2_inst *nsi,
450 struct osmo_sockaddr *remote,
451 int index);
Alexander Couzens6a161492020-07-12 13:45:50 +0200452
453/* sns */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100454int ns2_sns_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200455struct osmo_fsm_inst *ns2_sns_bss_fsm_alloc(struct gprs_ns2_nse *nse,
456 const char *id);
Harald Welte4f127462021-03-02 20:49:10 +0100457struct osmo_fsm_inst *ns2_sns_sgsn_fsm_alloc(struct gprs_ns2_nse *nse, const char *id);
Alexander Couzensbe7cecc2021-02-03 18:25:27 +0100458void ns2_sns_replace_nsvc(struct gprs_ns2_vc *nsvc);
459void ns2_sns_notify_alive(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, bool alive);
Alexander Couzensc4704762021-02-08 23:13:12 +0100460void ns2_sns_update_weights(struct gprs_ns2_vc_bind *bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200461
462/* vc */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100463struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc,
Alexander Couzens6a161492020-07-12 13:45:50 +0200464 const char *id, bool initiate);
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100465int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc);
466int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc);
467int ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
468int ns2_vc_is_alive(struct gprs_ns2_vc *nsvc);
469int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc);
Alexander Couzens47afc422021-01-17 20:12:46 +0100470int ns2_vc_block(struct gprs_ns2_vc *nsvc);
Alexander Couzens27e58732021-03-21 17:12:08 +0100471int ns2_vc_reset(struct gprs_ns2_vc *nsvc);
Alexander Couzens47afc422021-01-17 20:12:46 +0100472int ns2_vc_unblock(struct gprs_ns2_vc *nsvc);
Alexander Couzens75b61882021-03-21 16:18:17 +0100473void ns2_vty_dump_nsvc(struct vty *vty, struct gprs_ns2_vc *nsvc, bool stats);
Alexander Couzens6a161492020-07-12 13:45:50 +0200474
Alexander Couzens6a161492020-07-12 13:45:50 +0200475/* nse */
476void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked);
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100477enum gprs_ns2_vc_mode ns2_dialect_to_vc_mode(enum gprs_ns2_dialect dialect);
Alexander Couzens1c8785d2020-12-17 06:58:53 +0100478int ns2_count_transfer_cap(struct gprs_ns2_nse *nse,
479 uint16_t bvci);
Harald Welted164ef82021-03-04 22:29:17 +0100480
481/* vty */
482int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse);