blob: fddc896a51d7b0bfd82281801d7ac37d25a5bb68 [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>
10
11struct osmo_sockaddr;
Alexander Couzens1fac6f72020-10-01 19:08:38 +020012struct osmo_sockaddr_str;
Alexander Couzens6a161492020-07-12 13:45:50 +020013
14struct gprs_ns2_inst;
15struct gprs_ns2_nse;
16struct gprs_ns2_vc;
17struct gprs_ns2_vc_bind;
18struct gprs_ns2_vc_driver;
19struct gprs_ns_ie_ip4_elem;
20struct gprs_ns_ie_ip6_elem;
21
22enum gprs_ns2_vc_mode {
Harald Weltefa2d66c2020-10-17 13:09:34 +020023 /*! The VC will use RESET/BLOCK/UNBLOCK to start the connection and do ALIVE/ACK.
24 * This is what is needed for Frame Relay transport, and if you use a R97/R99 Gb
25 * interface over an IP transport (never standardized by 3GPP) */
26 NS2_VC_MODE_BLOCKRESET,
27 /*! The VC will only use ALIVE/ACK (no RESET/BLOCK/UNBLOCK), which is for Gb-IP
28 * interface compliant to 3GPP Rel=4 or later. */
29 NS2_VC_MODE_ALIVE,
Alexander Couzens6a161492020-07-12 13:45:50 +020030};
31
32/*! Osmocom NS primitives according to 48.016 5.2 Service primitves */
33enum gprs_ns2_prim {
34 PRIM_NS_UNIT_DATA,
35 PRIM_NS_CONGESTION,
36 PRIM_NS_STATUS,
37};
38
39/*! Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves */
40enum gprs_ns2_congestion_cause {
41 NS_CONG_CAUSE_BACKWARD_BEGIN,
42 NS_CONG_CAUSE_BACKWARD_END,
43 NS_CONG_CAUSE_FORWARD_BEGIN,
44 NS_CONG_CAUSE_FORWARD_END,
45};
46
47/*! Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves */
48enum gprs_ns2_affecting_cause {
49 NS_AFF_CAUSE_VC_FAILURE,
50 NS_AFF_CAUSE_VC_RECOVERY,
51 NS_AFF_CAUSE_FAILURE,
52 NS_AFF_CAUSE_RECOVERY,
53 /* osmocom own causes */
54 NS_AFF_CAUSE_SNS_CONFIGURED,
55 NS_AFF_CAUSE_SNS_FAILURE,
56};
57
58/*! Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves */
59enum gprs_ns2_change_ip_endpoint {
60 NS_ENDPOINT_NO_CHANGE,
61 NS_ENDPOINT_REQUEST_CHANGE,
62 NS_ENDPOINT_CONFIRM_CHANGE,
63};
64
65struct osmo_gprs_ns2_prim {
66 struct osmo_prim_hdr oph;
67
68 uint16_t nsei;
69 uint16_t bvci;
70
71 union {
72 struct {
73 enum gprs_ns2_change_ip_endpoint change;
74 /* TODO: implement resource distribution
75 * add place holder for the link selector */
76 long long _resource_distribution_placeholder1;
77 long long _resource_distribution_placeholder2;
78 long long _resource_distribution_placeholder3;
79 } unitdata;
80 struct {
81 enum gprs_ns2_congestion_cause cause;
82 } congestion;
83 struct {
84 enum gprs_ns2_affecting_cause cause;
85 /* 48.016 5.2.2.6 transfer capability */
86 int transfer;
Alexander Couzensda0a2852020-10-01 23:24:07 +020087 /* osmocom specific */
88 /* Persistent NSE/NSVC are configured by vty */
89 bool persistent;
90 /* Only true on the first time it's available.
91 * Allow the BSSGP layer to reset persistent NSE */
92 bool first;
Alexander Couzens6a161492020-07-12 13:45:50 +020093 } status;
94 } u;
95};
96
97/* instance */
98struct gprs_ns2_inst *gprs_ns2_instantiate(void *ctx, osmo_prim_cb cb, void *cb_data);
99void gprs_ns2_free(struct gprs_ns2_inst *inst);
100int gprs_ns2_dynamic_create_nse(struct gprs_ns2_inst *nsi, bool create_nse);
101
102/* Entrypoint for primitives from the NS USER */
103int gprs_ns2_recv_prim(struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph);
104
Alexander Couzens6cb5d5f2020-10-11 23:23:31 +0200105/*! a callback to iterate over all NSVC */
106typedef int (*gprs_ns2_foreach_nsvc_cb)(struct gprs_ns2_vc *nsvc, void *ctx);
107
108int gprs_ns2_nse_foreach_nsvc(struct gprs_ns2_nse *nse,
109 gprs_ns2_foreach_nsvc_cb cb, void *cb_data);
Alexander Couzens6a161492020-07-12 13:45:50 +0200110struct gprs_ns2_nse *gprs_ns2_nse_by_nsei(struct gprs_ns2_inst *nsi, uint16_t nsei);
111struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nsei);
Alexander Couzens05e7f7d2020-10-11 19:51:46 +0200112uint16_t gprs_ns2_nse_nsei(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200113void gprs_ns2_free_nse(struct gprs_ns2_nse *nse);
Alexander Couzens4b6c8af2020-10-11 20:15:25 +0200114void gprs_ns2_free_nses(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200115
116/* create vc */
117void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc);
118struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci);
119
120/* IP VL driver */
121int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700122 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200123 int dscp,
124 struct gprs_ns2_vc_bind **result);
Alexander Couzens4f608452020-10-11 18:41:24 +0200125struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
126 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200127void gprs_ns2_bind_set_mode(struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode);
128
129/* create a VC connection */
130struct gprs_ns2_vc *gprs_ns2_ip_connect(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700131 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200132 struct gprs_ns2_nse *nse,
133 uint16_t nsvci);
134
135struct gprs_ns2_vc *gprs_ns2_ip_connect2(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700136 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200137 uint16_t nsei,
138 uint16_t nsvci);
139struct gprs_ns2_vc *gprs_ns2_ip_connect_inactive(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700140 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200141 struct gprs_ns2_nse *nse,
142 uint16_t nsvci);
143
144void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind);
Alexander Couzens896fcd52020-10-11 19:52:36 +0200145void gprs_ns2_free_binds(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200146
147/* create a VC SNS connection */
148int gprs_ns2_ip_connect_sns(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700149 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200150 uint16_t nsei);
Alexander Couzens125298f2020-10-11 21:22:42 +0200151const struct osmo_sockaddr *gprs_ns2_nse_sns_remote(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200152
Alexander Couzensd33512b2020-10-11 21:42:11 +0200153const struct osmo_sockaddr *gprs_ns2_ip_vc_remote(const struct gprs_ns2_vc *nsvc);
Alexander Couzens979f5f52020-10-11 21:01:48 +0200154const struct osmo_sockaddr *gprs_ns2_ip_vc_local(const struct gprs_ns2_vc *nsvc);
Alexander Couzensd420ea92020-10-12 01:11:05 +0200155bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc,
156 const struct osmo_sockaddr *local,
157 const struct osmo_sockaddr *remote,
158 uint16_t nsvci);
Alexander Couzens9a4cf272020-10-11 20:48:04 +0200159const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200160int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind);
161int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp);
Alexander Couzens38b19e82020-09-23 23:56:37 +0200162struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
Alexander Couzens6a161492020-07-12 13:45:50 +0200163 struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700164 const struct osmo_sockaddr *saddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200165
166int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700167 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200168 int dscp,
169 struct gprs_ns2_vc_bind **result);
170int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind);
171
Alexander Couzens38b19e82020-09-23 23:56:37 +0200172struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_nse(
173 struct gprs_ns2_nse *nse,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700174 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200175void gprs_ns2_start_alive_all_nsvcs(struct gprs_ns2_nse *nse);
176const char *gprs_ns2_cause_str(int cause);
177const char *gprs_ns2_ll_str(struct gprs_ns2_vc *nsvc);
178char *gprs_ns2_ll_str_buf(char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc);
179char *gprs_ns2_ll_str_c(const void *ctx, struct gprs_ns2_vc *nsvc);
180
181/* vty */
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700182int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi,
183 const struct osmo_sockaddr_str *default_bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200184int gprs_ns2_vty_create();
Daniel Willmann4fb27a82020-09-25 15:39:46 +0200185void gprs_ns2_vty_force_vc_mode(bool force, enum gprs_ns2_vc_mode mode, const char *reason);
Alexander Couzens6a161492020-07-12 13:45:50 +0200186
187
188/*! @} */