blob: 7029c0796fa64ad617d9eabceb9aa09607dd4ac0 [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
35/*! Osmocom NS primitives according to 48.016 5.2 Service primitves */
36enum gprs_ns2_prim {
37 PRIM_NS_UNIT_DATA,
38 PRIM_NS_CONGESTION,
39 PRIM_NS_STATUS,
40};
41
Alexander Couzens0ab028c2020-11-04 02:41:44 +010042extern const struct value_string gprs_ns2_prim_strs[];
Alexander Couzens2498f1d2020-10-27 01:09:01 +010043
44/*! Obtain a human-readable string for NS primitives */
45static inline const char *gprs_ns2_prim_str(enum gprs_ns2_prim val)
Alexander Couzens0ab028c2020-11-04 02:41:44 +010046{ return get_value_string(gprs_ns2_prim_strs, val); }
Alexander Couzens2498f1d2020-10-27 01:09:01 +010047
Alexander Couzens6a161492020-07-12 13:45:50 +020048/*! Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves */
49enum gprs_ns2_congestion_cause {
50 NS_CONG_CAUSE_BACKWARD_BEGIN,
51 NS_CONG_CAUSE_BACKWARD_END,
52 NS_CONG_CAUSE_FORWARD_BEGIN,
53 NS_CONG_CAUSE_FORWARD_END,
54};
55
56/*! Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves */
57enum gprs_ns2_affecting_cause {
58 NS_AFF_CAUSE_VC_FAILURE,
59 NS_AFF_CAUSE_VC_RECOVERY,
60 NS_AFF_CAUSE_FAILURE,
61 NS_AFF_CAUSE_RECOVERY,
62 /* osmocom own causes */
63 NS_AFF_CAUSE_SNS_CONFIGURED,
64 NS_AFF_CAUSE_SNS_FAILURE,
65};
66
Alexander Couzens2498f1d2020-10-27 01:09:01 +010067extern const struct value_string gprs_ns2_aff_cause_prim_strs[];
68
69/*! Obtain a human-readable string for NS affective cause in primitives */
70static inline const char *gprs_ns2_aff_cause_prim_str(enum gprs_ns2_affecting_cause val)
71{ return get_value_string(gprs_ns2_aff_cause_prim_strs, val); }
72
Alexander Couzens6a161492020-07-12 13:45:50 +020073/*! Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves */
74enum gprs_ns2_change_ip_endpoint {
75 NS_ENDPOINT_NO_CHANGE,
76 NS_ENDPOINT_REQUEST_CHANGE,
77 NS_ENDPOINT_CONFIRM_CHANGE,
78};
79
Alexander Couzensb3b837c2020-10-27 15:12:25 +010080extern const struct value_string gprs_ns2_cause_strs[];
81
82/*! Obtain a human-readable string for NS primitives */
83static inline const char *gprs_ns2_cause_str(enum ns_cause val)
84{ return get_value_string(gprs_ns2_cause_strs, val); }
85
Alexander Couzens6a161492020-07-12 13:45:50 +020086struct osmo_gprs_ns2_prim {
87 struct osmo_prim_hdr oph;
88
89 uint16_t nsei;
90 uint16_t bvci;
91
92 union {
93 struct {
94 enum gprs_ns2_change_ip_endpoint change;
Alexander Couzensfc3dd1f2020-11-19 00:41:47 +010095 uint32_t link_selector;
Alexander Couzens6a161492020-07-12 13:45:50 +020096 /* TODO: implement resource distribution
97 * add place holder for the link selector */
98 long long _resource_distribution_placeholder1;
99 long long _resource_distribution_placeholder2;
100 long long _resource_distribution_placeholder3;
101 } unitdata;
102 struct {
103 enum gprs_ns2_congestion_cause cause;
104 } congestion;
105 struct {
106 enum gprs_ns2_affecting_cause cause;
Daniel Willmann15c09a82020-11-03 23:05:43 +0100107 char *nsvc;
Alexander Couzens6a161492020-07-12 13:45:50 +0200108 /* 48.016 5.2.2.6 transfer capability */
109 int transfer;
Alexander Couzensda0a2852020-10-01 23:24:07 +0200110 /* osmocom specific */
111 /* Persistent NSE/NSVC are configured by vty */
112 bool persistent;
113 /* Only true on the first time it's available.
114 * Allow the BSSGP layer to reset persistent NSE */
115 bool first;
Alexander Couzens6a161492020-07-12 13:45:50 +0200116 } status;
117 } u;
118};
119
120/* instance */
121struct gprs_ns2_inst *gprs_ns2_instantiate(void *ctx, osmo_prim_cb cb, void *cb_data);
122void gprs_ns2_free(struct gprs_ns2_inst *inst);
123int gprs_ns2_dynamic_create_nse(struct gprs_ns2_inst *nsi, bool create_nse);
124
125/* Entrypoint for primitives from the NS USER */
126int gprs_ns2_recv_prim(struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph);
127
Alexander Couzens6cb5d5f2020-10-11 23:23:31 +0200128/*! a callback to iterate over all NSVC */
129typedef int (*gprs_ns2_foreach_nsvc_cb)(struct gprs_ns2_vc *nsvc, void *ctx);
130
131int gprs_ns2_nse_foreach_nsvc(struct gprs_ns2_nse *nse,
132 gprs_ns2_foreach_nsvc_cb cb, void *cb_data);
Alexander Couzens6a161492020-07-12 13:45:50 +0200133struct gprs_ns2_nse *gprs_ns2_nse_by_nsei(struct gprs_ns2_inst *nsi, uint16_t nsei);
134struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nsei);
Alexander Couzens05e7f7d2020-10-11 19:51:46 +0200135uint16_t gprs_ns2_nse_nsei(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200136void gprs_ns2_free_nse(struct gprs_ns2_nse *nse);
Alexander Couzens4b6c8af2020-10-11 20:15:25 +0200137void gprs_ns2_free_nses(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200138
139/* create vc */
140void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc);
141struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci);
142
143/* IP VL driver */
144int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700145 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200146 int dscp,
147 struct gprs_ns2_vc_bind **result);
Alexander Couzens4f608452020-10-11 18:41:24 +0200148struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
149 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200150void gprs_ns2_bind_set_mode(struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode);
151
Alexander Couzens841817e2020-11-19 00:41:29 +0100152/* FR VL driver */
153struct gprs_ns2_vc_bind *gprs_ns2_fr_bind_by_netif(
154 struct gprs_ns2_inst *nsi,
155 const char *netif);
156const char *gprs_ns2_fr_bind_netif(struct gprs_ns2_vc_bind *bind);
157int gprs_ns2_fr_bind(struct gprs_ns2_inst *nsi,
158 const char *netif,
159 struct osmo_fr_network *fr_network,
160 enum osmo_fr_role fr_role,
161 struct gprs_ns2_vc_bind **result);
162int gprs_ns2_is_fr_bind(struct gprs_ns2_vc_bind *bind);
163struct gprs_ns2_vc *gprs_ns2_fr_nsvc_by_dlci(struct gprs_ns2_vc_bind *bind, uint16_t dlci);
164struct gprs_ns2_vc *gprs_ns2_fr_connect(struct gprs_ns2_vc_bind *bind,
165 uint16_t nsei,
166 uint16_t nsvci,
167 uint16_t dlci);
168
Alexander Couzens6a161492020-07-12 13:45:50 +0200169/* create a VC connection */
170struct gprs_ns2_vc *gprs_ns2_ip_connect(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700171 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200172 struct gprs_ns2_nse *nse,
173 uint16_t nsvci);
174
175struct gprs_ns2_vc *gprs_ns2_ip_connect2(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700176 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200177 uint16_t nsei,
178 uint16_t nsvci);
179struct gprs_ns2_vc *gprs_ns2_ip_connect_inactive(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700180 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200181 struct gprs_ns2_nse *nse,
182 uint16_t nsvci);
183
184void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind);
Alexander Couzens896fcd52020-10-11 19:52:36 +0200185void gprs_ns2_free_binds(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200186
187/* create a VC SNS connection */
188int gprs_ns2_ip_connect_sns(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700189 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200190 uint16_t nsei);
Alexander Couzens125298f2020-10-11 21:22:42 +0200191const struct osmo_sockaddr *gprs_ns2_nse_sns_remote(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200192
Alexander Couzensd33512b2020-10-11 21:42:11 +0200193const struct osmo_sockaddr *gprs_ns2_ip_vc_remote(const struct gprs_ns2_vc *nsvc);
Alexander Couzens979f5f52020-10-11 21:01:48 +0200194const struct osmo_sockaddr *gprs_ns2_ip_vc_local(const struct gprs_ns2_vc *nsvc);
Alexander Couzensd420ea92020-10-12 01:11:05 +0200195bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc,
196 const struct osmo_sockaddr *local,
197 const struct osmo_sockaddr *remote,
198 uint16_t nsvci);
Alexander Couzens9a4cf272020-10-11 20:48:04 +0200199const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200200int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind);
201int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp);
Alexander Couzens38b19e82020-09-23 23:56:37 +0200202struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
Alexander Couzens6a161492020-07-12 13:45:50 +0200203 struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700204 const struct osmo_sockaddr *saddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200205
206int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700207 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200208 int dscp,
209 struct gprs_ns2_vc_bind **result);
210int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind);
Alexander Couzens841817e2020-11-19 00:41:29 +0100211uint16_t gprs_ns2_fr_nsvc_dlci(struct gprs_ns2_vc *nsvc);
Alexander Couzens6a161492020-07-12 13:45:50 +0200212
Alexander Couzens38b19e82020-09-23 23:56:37 +0200213struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_nse(
214 struct gprs_ns2_nse *nse,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700215 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200216void gprs_ns2_start_alive_all_nsvcs(struct gprs_ns2_nse *nse);
Daniel Willmannf1286542020-11-03 23:03:33 +0100217
218/* VC information */
Alexander Couzens6a161492020-07-12 13:45:50 +0200219const char *gprs_ns2_ll_str(struct gprs_ns2_vc *nsvc);
220char *gprs_ns2_ll_str_buf(char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc);
221char *gprs_ns2_ll_str_c(const void *ctx, struct gprs_ns2_vc *nsvc);
Daniel Willmannf1286542020-11-03 23:03:33 +0100222const char *gprs_ns2_nsvc_state_name(struct gprs_ns2_vc *nsvc);
Alexander Couzens6a161492020-07-12 13:45:50 +0200223
224/* vty */
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700225int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi,
226 const struct osmo_sockaddr_str *default_bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200227int gprs_ns2_vty_create();
Daniel Willmann4fb27a82020-09-25 15:39:46 +0200228void gprs_ns2_vty_force_vc_mode(bool force, enum gprs_ns2_vc_mode mode, const char *reason);
Alexander Couzens6a161492020-07-12 13:45:50 +0200229
230
231/*! @} */