blob: 0b3ea1fdff2f2a108bdc61e2788c170c706ca8eb [file] [log] [blame]
Alexander Couzens6a161492020-07-12 13:45:50 +02001/*! \file gprs_ns2.h */
2
3
4#pragma once
5
6#include <stdint.h>
7#include <netinet/in.h>
8
9#include <osmocom/core/prim.h>
Alexander Couzensb3b837c2020-10-27 15:12:25 +010010#include <osmocom/gprs/protocol/gsm_08_16.h>
Alexander Couzens841817e2020-11-19 00:41:29 +010011#include <osmocom/gprs/frame_relay.h>
Alexander Couzens6a161492020-07-12 13:45:50 +020012
13struct osmo_sockaddr;
Alexander Couzens1fac6f72020-10-01 19:08:38 +020014struct osmo_sockaddr_str;
Alexander Couzens841817e2020-11-19 00:41:29 +010015struct osmo_fr_network;
Alexander Couzens6a161492020-07-12 13:45:50 +020016
17struct gprs_ns2_inst;
18struct gprs_ns2_nse;
19struct gprs_ns2_vc;
20struct gprs_ns2_vc_bind;
21struct gprs_ns2_vc_driver;
22struct gprs_ns_ie_ip4_elem;
23struct gprs_ns_ie_ip6_elem;
24
25enum gprs_ns2_vc_mode {
Harald Weltefa2d66c2020-10-17 13:09:34 +020026 /*! The VC will use RESET/BLOCK/UNBLOCK to start the connection and do ALIVE/ACK.
27 * This is what is needed for Frame Relay transport, and if you use a R97/R99 Gb
28 * interface over an IP transport (never standardized by 3GPP) */
29 NS2_VC_MODE_BLOCKRESET,
30 /*! The VC will only use ALIVE/ACK (no RESET/BLOCK/UNBLOCK), which is for Gb-IP
31 * interface compliant to 3GPP Rel=4 or later. */
32 NS2_VC_MODE_ALIVE,
Alexander Couzens6a161492020-07-12 13:45:50 +020033};
34
Alexander Couzensd923cff2020-12-01 01:03:52 +010035enum gprs_ns2_dialect {
36 NS2_DIALECT_UNDEF,
37 NS2_DIALECT_STATIC_ALIVE,
38 NS2_DIALECT_STATIC_RESETBLOCK,
39 NS2_DIALECT_IPACCESS,
40 NS2_DIALECT_SNS,
41};
42
Alexander Couzens24a14ac2020-11-19 02:34:49 +010043/*! Osmocom NS link layer types */
44enum gprs_ns2_ll {
45 GPRS_NS2_LL_UDP, /*!< NS/UDP/IP */
Alexander Couzens24a14ac2020-11-19 02:34:49 +010046 GPRS_NS2_LL_FR, /*!< NS/FR */
47 GPRS_NS2_LL_FR_GRE, /*!< NS/FR/GRE/IP */
48};
49
Alexander Couzens6a161492020-07-12 13:45:50 +020050/*! Osmocom NS primitives according to 48.016 5.2 Service primitves */
51enum gprs_ns2_prim {
52 PRIM_NS_UNIT_DATA,
53 PRIM_NS_CONGESTION,
54 PRIM_NS_STATUS,
55};
56
Alexander Couzens0ab028c2020-11-04 02:41:44 +010057extern const struct value_string gprs_ns2_prim_strs[];
Harald Weltea24e7ee2020-11-29 17:38:48 +010058extern const struct value_string gprs_ns2_lltype_strs[];
Alexander Couzens2498f1d2020-10-27 01:09:01 +010059
60/*! Obtain a human-readable string for NS primitives */
61static inline const char *gprs_ns2_prim_str(enum gprs_ns2_prim val)
Alexander Couzens0ab028c2020-11-04 02:41:44 +010062{ return get_value_string(gprs_ns2_prim_strs, val); }
Alexander Couzens2498f1d2020-10-27 01:09:01 +010063
Harald Weltea24e7ee2020-11-29 17:38:48 +010064/*! Obtain a human-readable string for NS link-layer type */
65static inline const char *gprs_ns2_lltype_str(enum gprs_ns2_ll val)
66{ return get_value_string(gprs_ns2_lltype_strs, val); }
67
Alexander Couzens6a161492020-07-12 13:45:50 +020068/*! Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves */
69enum gprs_ns2_congestion_cause {
70 NS_CONG_CAUSE_BACKWARD_BEGIN,
71 NS_CONG_CAUSE_BACKWARD_END,
72 NS_CONG_CAUSE_FORWARD_BEGIN,
73 NS_CONG_CAUSE_FORWARD_END,
74};
75
76/*! Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves */
77enum gprs_ns2_affecting_cause {
78 NS_AFF_CAUSE_VC_FAILURE,
79 NS_AFF_CAUSE_VC_RECOVERY,
80 NS_AFF_CAUSE_FAILURE,
81 NS_AFF_CAUSE_RECOVERY,
82 /* osmocom own causes */
83 NS_AFF_CAUSE_SNS_CONFIGURED,
84 NS_AFF_CAUSE_SNS_FAILURE,
Alexander Couzense769f522020-12-07 07:37:07 +010085 NS_AFF_CAUSE_SNS_NO_ENDPOINTS,
Alexander Couzens6a161492020-07-12 13:45:50 +020086};
87
Alexander Couzens2498f1d2020-10-27 01:09:01 +010088extern const struct value_string gprs_ns2_aff_cause_prim_strs[];
89
90/*! Obtain a human-readable string for NS affective cause in primitives */
91static inline const char *gprs_ns2_aff_cause_prim_str(enum gprs_ns2_affecting_cause val)
92{ return get_value_string(gprs_ns2_aff_cause_prim_strs, val); }
93
Alexander Couzens6a161492020-07-12 13:45:50 +020094/*! Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves */
95enum gprs_ns2_change_ip_endpoint {
96 NS_ENDPOINT_NO_CHANGE,
97 NS_ENDPOINT_REQUEST_CHANGE,
98 NS_ENDPOINT_CONFIRM_CHANGE,
99};
100
Alexander Couzensb3b837c2020-10-27 15:12:25 +0100101extern const struct value_string gprs_ns2_cause_strs[];
102
103/*! Obtain a human-readable string for NS primitives */
104static inline const char *gprs_ns2_cause_str(enum ns_cause val)
105{ return get_value_string(gprs_ns2_cause_strs, val); }
106
Alexander Couzens6a161492020-07-12 13:45:50 +0200107struct osmo_gprs_ns2_prim {
108 struct osmo_prim_hdr oph;
109
110 uint16_t nsei;
111 uint16_t bvci;
112
113 union {
114 struct {
115 enum gprs_ns2_change_ip_endpoint change;
Alexander Couzensfc3dd1f2020-11-19 00:41:47 +0100116 uint32_t link_selector;
Alexander Couzens6a161492020-07-12 13:45:50 +0200117 /* TODO: implement resource distribution
118 * add place holder for the link selector */
119 long long _resource_distribution_placeholder1;
120 long long _resource_distribution_placeholder2;
121 long long _resource_distribution_placeholder3;
122 } unitdata;
123 struct {
124 enum gprs_ns2_congestion_cause cause;
125 } congestion;
126 struct {
127 enum gprs_ns2_affecting_cause cause;
Daniel Willmann15c09a82020-11-03 23:05:43 +0100128 char *nsvc;
Alexander Couzens6a161492020-07-12 13:45:50 +0200129 /* 48.016 5.2.2.6 transfer capability */
130 int transfer;
Alexander Couzensda0a2852020-10-01 23:24:07 +0200131 /* osmocom specific */
132 /* Persistent NSE/NSVC are configured by vty */
133 bool persistent;
134 /* Only true on the first time it's available.
135 * Allow the BSSGP layer to reset persistent NSE */
136 bool first;
Alexander Couzens6a161492020-07-12 13:45:50 +0200137 } status;
138 } u;
139};
140
141/* instance */
142struct gprs_ns2_inst *gprs_ns2_instantiate(void *ctx, osmo_prim_cb cb, void *cb_data);
143void gprs_ns2_free(struct gprs_ns2_inst *inst);
144int gprs_ns2_dynamic_create_nse(struct gprs_ns2_inst *nsi, bool create_nse);
145
146/* Entrypoint for primitives from the NS USER */
147int gprs_ns2_recv_prim(struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph);
148
Alexander Couzens6cb5d5f2020-10-11 23:23:31 +0200149/*! a callback to iterate over all NSVC */
150typedef int (*gprs_ns2_foreach_nsvc_cb)(struct gprs_ns2_vc *nsvc, void *ctx);
151
152int gprs_ns2_nse_foreach_nsvc(struct gprs_ns2_nse *nse,
153 gprs_ns2_foreach_nsvc_cb cb, void *cb_data);
Alexander Couzens6a161492020-07-12 13:45:50 +0200154struct gprs_ns2_nse *gprs_ns2_nse_by_nsei(struct gprs_ns2_inst *nsi, uint16_t nsei);
Alexander Couzensaac90162020-11-19 02:44:04 +0100155struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nsei,
Alexander Couzensd923cff2020-12-01 01:03:52 +0100156 enum gprs_ns2_ll linklayer,
157 enum gprs_ns2_dialect dialect);
Alexander Couzens05e7f7d2020-10-11 19:51:46 +0200158uint16_t gprs_ns2_nse_nsei(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200159void gprs_ns2_free_nse(struct gprs_ns2_nse *nse);
Alexander Couzens4b6c8af2020-10-11 20:15:25 +0200160void gprs_ns2_free_nses(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200161
162/* create vc */
163void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc);
Alexander Couzens47558792020-12-06 03:16:11 +0100164void gprs_ns2_free_nsvcs(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200165struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci);
166
Alexander Couzensaaa55a62020-12-03 06:02:03 +0100167/* generic VL driver */
168struct gprs_ns2_vc_bind *gprs_ns2_bind_by_name(struct gprs_ns2_inst *nsi,
169 const char *name);
170
Alexander Couzens6a161492020-07-12 13:45:50 +0200171/* IP VL driver */
172int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
Alexander Couzensaaa55a62020-12-03 06:02:03 +0100173 const char *name,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700174 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200175 int dscp,
176 struct gprs_ns2_vc_bind **result);
Alexander Couzens4f608452020-10-11 18:41:24 +0200177struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
178 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200179
Alexander Couzens841817e2020-11-19 00:41:29 +0100180/* FR VL driver */
181struct gprs_ns2_vc_bind *gprs_ns2_fr_bind_by_netif(
182 struct gprs_ns2_inst *nsi,
183 const char *netif);
184const char *gprs_ns2_fr_bind_netif(struct gprs_ns2_vc_bind *bind);
Alexander Couzensc782cec2020-12-10 04:10:25 +0100185enum osmo_fr_role gprs_ns2_fr_bind_role(struct gprs_ns2_vc_bind *bind);
Alexander Couzens841817e2020-11-19 00:41:29 +0100186int gprs_ns2_fr_bind(struct gprs_ns2_inst *nsi,
Alexander Couzensaaa55a62020-12-03 06:02:03 +0100187 const char *name,
Alexander Couzens841817e2020-11-19 00:41:29 +0100188 const char *netif,
189 struct osmo_fr_network *fr_network,
190 enum osmo_fr_role fr_role,
191 struct gprs_ns2_vc_bind **result);
192int gprs_ns2_is_fr_bind(struct gprs_ns2_vc_bind *bind);
193struct gprs_ns2_vc *gprs_ns2_fr_nsvc_by_dlci(struct gprs_ns2_vc_bind *bind, uint16_t dlci);
194struct gprs_ns2_vc *gprs_ns2_fr_connect(struct gprs_ns2_vc_bind *bind,
Alexander Couzensebcbd722020-12-03 06:11:39 +0100195 struct gprs_ns2_nse *nse,
196 uint16_t nsvci,
197 uint16_t dlci);
198struct gprs_ns2_vc *gprs_ns2_fr_connect2(struct gprs_ns2_vc_bind *bind,
Alexander Couzens841817e2020-11-19 00:41:29 +0100199 uint16_t nsei,
200 uint16_t nsvci,
201 uint16_t dlci);
202
Alexander Couzens6a161492020-07-12 13:45:50 +0200203/* create a VC connection */
204struct gprs_ns2_vc *gprs_ns2_ip_connect(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700205 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200206 struct gprs_ns2_nse *nse,
207 uint16_t nsvci);
208
209struct gprs_ns2_vc *gprs_ns2_ip_connect2(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700210 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200211 uint16_t nsei,
Alexander Couzensd923cff2020-12-01 01:03:52 +0100212 uint16_t nsvci,
213 enum gprs_ns2_dialect dialect);
Alexander Couzens6a161492020-07-12 13:45:50 +0200214struct gprs_ns2_vc *gprs_ns2_ip_connect_inactive(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700215 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200216 struct gprs_ns2_nse *nse,
217 uint16_t nsvci);
218
219void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind);
Alexander Couzens896fcd52020-10-11 19:52:36 +0200220void gprs_ns2_free_binds(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200221
222/* create a VC SNS connection */
Alexander Couzense769f522020-12-07 07:37:07 +0100223int gprs_ns2_sns_count(struct gprs_ns2_nse *nse);
224int gprs_ns2_sns_add_endpoint(struct gprs_ns2_nse *nse,
225 const struct osmo_sockaddr *saddr);
226int gprs_ns2_sns_del_endpoint(struct gprs_ns2_nse *nse,
227 const struct osmo_sockaddr *saddr);
Alexander Couzens125298f2020-10-11 21:22:42 +0200228const struct osmo_sockaddr *gprs_ns2_nse_sns_remote(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200229
Alexander Couzensd33512b2020-10-11 21:42:11 +0200230const struct osmo_sockaddr *gprs_ns2_ip_vc_remote(const struct gprs_ns2_vc *nsvc);
Alexander Couzens979f5f52020-10-11 21:01:48 +0200231const struct osmo_sockaddr *gprs_ns2_ip_vc_local(const struct gprs_ns2_vc *nsvc);
Alexander Couzensd420ea92020-10-12 01:11:05 +0200232bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc,
233 const struct osmo_sockaddr *local,
234 const struct osmo_sockaddr *remote,
235 uint16_t nsvci);
Alexander Couzens9a4cf272020-10-11 20:48:04 +0200236const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200237int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind);
238int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp);
Alexander Couzens38b19e82020-09-23 23:56:37 +0200239struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
Alexander Couzens6a161492020-07-12 13:45:50 +0200240 struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700241 const struct osmo_sockaddr *saddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200242
243int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
Alexander Couzensaaa55a62020-12-03 06:02:03 +0100244 const char *name,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700245 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200246 int dscp,
247 struct gprs_ns2_vc_bind **result);
248int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind);
Alexander Couzens22c26e02020-12-10 04:10:07 +0100249uint16_t gprs_ns2_fr_nsvc_dlci(const struct gprs_ns2_vc *nsvc);
Alexander Couzens6a161492020-07-12 13:45:50 +0200250
Alexander Couzens38b19e82020-09-23 23:56:37 +0200251struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_nse(
252 struct gprs_ns2_nse *nse,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700253 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200254void gprs_ns2_start_alive_all_nsvcs(struct gprs_ns2_nse *nse);
Daniel Willmannf1286542020-11-03 23:03:33 +0100255
256/* VC information */
Alexander Couzens6a161492020-07-12 13:45:50 +0200257const char *gprs_ns2_ll_str(struct gprs_ns2_vc *nsvc);
258char *gprs_ns2_ll_str_buf(char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc);
259char *gprs_ns2_ll_str_c(const void *ctx, struct gprs_ns2_vc *nsvc);
Daniel Willmannf1286542020-11-03 23:03:33 +0100260const char *gprs_ns2_nsvc_state_name(struct gprs_ns2_vc *nsvc);
Alexander Couzens6a161492020-07-12 13:45:50 +0200261
262/* vty */
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700263int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi,
264 const struct osmo_sockaddr_str *default_bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200265int gprs_ns2_vty_create();
Alexander Couzens6a161492020-07-12 13:45:50 +0200266
267/*! @} */