blob: 497265e54bcc43078a061b87317898e32229f1a5 [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 {
23 NS2_VC_MODE_BLOCKRESET, /* The VC will use RESET/BLOCK/UNBLOCK to start the connection and do ALIVE/ACK */
24 NS2_VC_MODE_ALIVE, /* The will only use ALIVE/ACK */
25};
26
27/*! Osmocom NS primitives according to 48.016 5.2 Service primitves */
28enum gprs_ns2_prim {
29 PRIM_NS_UNIT_DATA,
30 PRIM_NS_CONGESTION,
31 PRIM_NS_STATUS,
32};
33
34/*! Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves */
35enum gprs_ns2_congestion_cause {
36 NS_CONG_CAUSE_BACKWARD_BEGIN,
37 NS_CONG_CAUSE_BACKWARD_END,
38 NS_CONG_CAUSE_FORWARD_BEGIN,
39 NS_CONG_CAUSE_FORWARD_END,
40};
41
42/*! Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves */
43enum gprs_ns2_affecting_cause {
44 NS_AFF_CAUSE_VC_FAILURE,
45 NS_AFF_CAUSE_VC_RECOVERY,
46 NS_AFF_CAUSE_FAILURE,
47 NS_AFF_CAUSE_RECOVERY,
48 /* osmocom own causes */
49 NS_AFF_CAUSE_SNS_CONFIGURED,
50 NS_AFF_CAUSE_SNS_FAILURE,
51};
52
53/*! Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves */
54enum gprs_ns2_change_ip_endpoint {
55 NS_ENDPOINT_NO_CHANGE,
56 NS_ENDPOINT_REQUEST_CHANGE,
57 NS_ENDPOINT_CONFIRM_CHANGE,
58};
59
60struct osmo_gprs_ns2_prim {
61 struct osmo_prim_hdr oph;
62
63 uint16_t nsei;
64 uint16_t bvci;
65
66 union {
67 struct {
68 enum gprs_ns2_change_ip_endpoint change;
69 /* TODO: implement resource distribution
70 * add place holder for the link selector */
71 long long _resource_distribution_placeholder1;
72 long long _resource_distribution_placeholder2;
73 long long _resource_distribution_placeholder3;
74 } unitdata;
75 struct {
76 enum gprs_ns2_congestion_cause cause;
77 } congestion;
78 struct {
79 enum gprs_ns2_affecting_cause cause;
80 /* 48.016 5.2.2.6 transfer capability */
81 int transfer;
Alexander Couzensda0a2852020-10-01 23:24:07 +020082 /* osmocom specific */
83 /* Persistent NSE/NSVC are configured by vty */
84 bool persistent;
85 /* Only true on the first time it's available.
86 * Allow the BSSGP layer to reset persistent NSE */
87 bool first;
Alexander Couzens6a161492020-07-12 13:45:50 +020088 } status;
89 } u;
90};
91
92/* instance */
93struct gprs_ns2_inst *gprs_ns2_instantiate(void *ctx, osmo_prim_cb cb, void *cb_data);
94void gprs_ns2_free(struct gprs_ns2_inst *inst);
95int gprs_ns2_dynamic_create_nse(struct gprs_ns2_inst *nsi, bool create_nse);
96
97/* Entrypoint for primitives from the NS USER */
98int gprs_ns2_recv_prim(struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph);
99
Alexander Couzens6cb5d5f2020-10-11 23:23:31 +0200100/*! a callback to iterate over all NSVC */
101typedef int (*gprs_ns2_foreach_nsvc_cb)(struct gprs_ns2_vc *nsvc, void *ctx);
102
103int gprs_ns2_nse_foreach_nsvc(struct gprs_ns2_nse *nse,
104 gprs_ns2_foreach_nsvc_cb cb, void *cb_data);
Alexander Couzens6a161492020-07-12 13:45:50 +0200105struct gprs_ns2_nse *gprs_ns2_nse_by_nsei(struct gprs_ns2_inst *nsi, uint16_t nsei);
106struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nsei);
Alexander Couzens05e7f7d2020-10-11 19:51:46 +0200107uint16_t gprs_ns2_nse_nsei(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200108void gprs_ns2_free_nse(struct gprs_ns2_nse *nse);
Alexander Couzens4b6c8af2020-10-11 20:15:25 +0200109void gprs_ns2_free_nses(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200110
111/* create vc */
112void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc);
113struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci);
114
115/* IP VL driver */
116int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700117 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200118 int dscp,
119 struct gprs_ns2_vc_bind **result);
Alexander Couzens4f608452020-10-11 18:41:24 +0200120struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
121 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200122void gprs_ns2_bind_set_mode(struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode);
123
124/* create a VC connection */
125struct gprs_ns2_vc *gprs_ns2_ip_connect(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700126 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200127 struct gprs_ns2_nse *nse,
128 uint16_t nsvci);
129
130struct gprs_ns2_vc *gprs_ns2_ip_connect2(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 uint16_t nsei,
133 uint16_t nsvci);
134struct gprs_ns2_vc *gprs_ns2_ip_connect_inactive(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700135 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200136 struct gprs_ns2_nse *nse,
137 uint16_t nsvci);
138
139void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind);
Alexander Couzens896fcd52020-10-11 19:52:36 +0200140void gprs_ns2_free_binds(struct gprs_ns2_inst *nsi);
Alexander Couzens6a161492020-07-12 13:45:50 +0200141
142/* create a VC SNS connection */
143int gprs_ns2_ip_connect_sns(struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700144 const struct osmo_sockaddr *remote,
Alexander Couzens6a161492020-07-12 13:45:50 +0200145 uint16_t nsei);
Alexander Couzens125298f2020-10-11 21:22:42 +0200146const struct osmo_sockaddr *gprs_ns2_nse_sns_remote(struct gprs_ns2_nse *nse);
Alexander Couzens6a161492020-07-12 13:45:50 +0200147
Alexander Couzensd33512b2020-10-11 21:42:11 +0200148const struct osmo_sockaddr *gprs_ns2_ip_vc_remote(const struct gprs_ns2_vc *nsvc);
Alexander Couzens979f5f52020-10-11 21:01:48 +0200149const struct osmo_sockaddr *gprs_ns2_ip_vc_local(const struct gprs_ns2_vc *nsvc);
Alexander Couzensd420ea92020-10-12 01:11:05 +0200150bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc,
151 const struct osmo_sockaddr *local,
152 const struct osmo_sockaddr *remote,
153 uint16_t nsvci);
Alexander Couzens9a4cf272020-10-11 20:48:04 +0200154const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200155int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind);
156int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp);
Alexander Couzens38b19e82020-09-23 23:56:37 +0200157struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
Alexander Couzens6a161492020-07-12 13:45:50 +0200158 struct gprs_ns2_vc_bind *bind,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700159 const struct osmo_sockaddr *saddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200160
161int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700162 const struct osmo_sockaddr *local,
Alexander Couzens6a161492020-07-12 13:45:50 +0200163 int dscp,
164 struct gprs_ns2_vc_bind **result);
165int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind);
166
Alexander Couzens38b19e82020-09-23 23:56:37 +0200167struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_nse(
168 struct gprs_ns2_nse *nse,
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700169 const struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200170void gprs_ns2_start_alive_all_nsvcs(struct gprs_ns2_nse *nse);
171const char *gprs_ns2_cause_str(int cause);
172const char *gprs_ns2_ll_str(struct gprs_ns2_vc *nsvc);
173char *gprs_ns2_ll_str_buf(char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc);
174char *gprs_ns2_ll_str_c(const void *ctx, struct gprs_ns2_vc *nsvc);
175
176/* vty */
Vadim Yanitskiya07f25e2020-10-09 21:47:01 +0700177int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi,
178 const struct osmo_sockaddr_str *default_bind);
Alexander Couzens6a161492020-07-12 13:45:50 +0200179int gprs_ns2_vty_create();
Daniel Willmann4fb27a82020-09-25 15:39:46 +0200180void gprs_ns2_vty_force_vc_mode(bool force, enum gprs_ns2_vc_mode mode, const char *reason);
Alexander Couzens6a161492020-07-12 13:45:50 +0200181
182
183/*! @} */