blob: 6b88c7235fda09c5f81db6fb5092cd4e3f867bcf [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;
12
13struct gprs_ns2_inst;
14struct gprs_ns2_nse;
15struct gprs_ns2_vc;
16struct gprs_ns2_vc_bind;
17struct gprs_ns2_vc_driver;
18struct gprs_ns_ie_ip4_elem;
19struct gprs_ns_ie_ip6_elem;
20
21enum gprs_ns2_vc_mode {
22 NS2_VC_MODE_BLOCKRESET, /* The VC will use RESET/BLOCK/UNBLOCK to start the connection and do ALIVE/ACK */
23 NS2_VC_MODE_ALIVE, /* The will only use ALIVE/ACK */
24};
25
26/*! Osmocom NS primitives according to 48.016 5.2 Service primitves */
27enum gprs_ns2_prim {
28 PRIM_NS_UNIT_DATA,
29 PRIM_NS_CONGESTION,
30 PRIM_NS_STATUS,
31};
32
33/*! Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves */
34enum gprs_ns2_congestion_cause {
35 NS_CONG_CAUSE_BACKWARD_BEGIN,
36 NS_CONG_CAUSE_BACKWARD_END,
37 NS_CONG_CAUSE_FORWARD_BEGIN,
38 NS_CONG_CAUSE_FORWARD_END,
39};
40
41/*! Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves */
42enum gprs_ns2_affecting_cause {
43 NS_AFF_CAUSE_VC_FAILURE,
44 NS_AFF_CAUSE_VC_RECOVERY,
45 NS_AFF_CAUSE_FAILURE,
46 NS_AFF_CAUSE_RECOVERY,
47 /* osmocom own causes */
48 NS_AFF_CAUSE_SNS_CONFIGURED,
49 NS_AFF_CAUSE_SNS_FAILURE,
50};
51
52/*! Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves */
53enum gprs_ns2_change_ip_endpoint {
54 NS_ENDPOINT_NO_CHANGE,
55 NS_ENDPOINT_REQUEST_CHANGE,
56 NS_ENDPOINT_CONFIRM_CHANGE,
57};
58
59struct osmo_gprs_ns2_prim {
60 struct osmo_prim_hdr oph;
61
62 uint16_t nsei;
63 uint16_t bvci;
64
65 union {
66 struct {
67 enum gprs_ns2_change_ip_endpoint change;
68 /* TODO: implement resource distribution
69 * add place holder for the link selector */
70 long long _resource_distribution_placeholder1;
71 long long _resource_distribution_placeholder2;
72 long long _resource_distribution_placeholder3;
73 } unitdata;
74 struct {
75 enum gprs_ns2_congestion_cause cause;
76 } congestion;
77 struct {
78 enum gprs_ns2_affecting_cause cause;
79 /* 48.016 5.2.2.6 transfer capability */
80 int transfer;
81 } status;
82 } u;
83};
84
85/* instance */
86struct gprs_ns2_inst *gprs_ns2_instantiate(void *ctx, osmo_prim_cb cb, void *cb_data);
87void gprs_ns2_free(struct gprs_ns2_inst *inst);
88int gprs_ns2_dynamic_create_nse(struct gprs_ns2_inst *nsi, bool create_nse);
89
90/* Entrypoint for primitives from the NS USER */
91int gprs_ns2_recv_prim(struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph);
92
93struct gprs_ns2_nse *gprs_ns2_nse_by_nsei(struct gprs_ns2_inst *nsi, uint16_t nsei);
94struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nsei);
95void gprs_ns2_free_nse(struct gprs_ns2_nse *nse);
96
97/* create vc */
98void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc);
99struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci);
100
101/* IP VL driver */
102int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
103 struct osmo_sockaddr *local,
104 int dscp,
105 struct gprs_ns2_vc_bind **result);
106void gprs_ns2_bind_set_mode(struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode);
107
108/* create a VC connection */
109struct gprs_ns2_vc *gprs_ns2_ip_connect(struct gprs_ns2_vc_bind *bind,
110 struct osmo_sockaddr *remote,
111 struct gprs_ns2_nse *nse,
112 uint16_t nsvci);
113
114struct gprs_ns2_vc *gprs_ns2_ip_connect2(struct gprs_ns2_vc_bind *bind,
115 struct osmo_sockaddr *remote,
116 uint16_t nsei,
117 uint16_t nsvci);
118struct gprs_ns2_vc *gprs_ns2_ip_connect_inactive(struct gprs_ns2_vc_bind *bind,
119 struct osmo_sockaddr *remote,
120 struct gprs_ns2_nse *nse,
121 uint16_t nsvci);
122
123void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind);
124
125/* create a VC SNS connection */
126int gprs_ns2_ip_connect_sns(struct gprs_ns2_vc_bind *bind,
127 struct osmo_sockaddr *remote,
128 uint16_t nsei);
129
130struct osmo_sockaddr *gprs_ns2_ip_vc_sockaddr(struct gprs_ns2_vc *nsvc);
131struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind);
132int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind);
133int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp);
Alexander Couzens38b19e82020-09-23 23:56:37 +0200134struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
Alexander Couzens6a161492020-07-12 13:45:50 +0200135 struct gprs_ns2_vc_bind *bind,
Alexander Couzens38b19e82020-09-23 23:56:37 +0200136 struct osmo_sockaddr *saddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200137
138int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
139 struct osmo_sockaddr *local,
140 int dscp,
141 struct gprs_ns2_vc_bind **result);
142int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind);
143
Alexander Couzens38b19e82020-09-23 23:56:37 +0200144struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_nse(
145 struct gprs_ns2_nse *nse,
146 struct osmo_sockaddr *sockaddr);
Alexander Couzens6a161492020-07-12 13:45:50 +0200147void gprs_ns2_start_alive_all_nsvcs(struct gprs_ns2_nse *nse);
148const char *gprs_ns2_cause_str(int cause);
149const char *gprs_ns2_ll_str(struct gprs_ns2_vc *nsvc);
150char *gprs_ns2_ll_str_buf(char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc);
151char *gprs_ns2_ll_str_c(const void *ctx, struct gprs_ns2_vc *nsvc);
152
153/* vty */
154int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi);
155int gprs_ns2_vty_create();
Daniel Willmann4fb27a82020-09-25 15:39:46 +0200156void gprs_ns2_vty_force_vc_mode(bool force, enum gprs_ns2_vc_mode mode, const char *reason);
Alexander Couzens6a161492020-07-12 13:45:50 +0200157
158
159/*! @} */