libosmogb  1.4.0.160-7619
Osmocom Gb library
gprs_ns2_internal.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <stdbool.h>
6 #include <stdint.h>
7 
10 
11 struct osmo_fsm_inst;
12 struct tlv_parsed;
13 struct vty;
14 
15 struct gprs_ns2_vc_driver;
16 struct gprs_ns2_vc_bind;
17 
18 
19 
20 #define NS_TIMERS_COUNT 8
21 #define NS_TIMERS "(tns-block|tns-block-retries|tns-reset|tns-reset-retries|tns-test|tns-alive|tns-alive-retries|tsns-prov)"
22 #define NS_TIMERS_HELP \
23  "(un)blocking Timer (Tns-block) timeout\n" \
24  "(un)blocking Timer (Tns-block) number of retries\n" \
25  "Reset Timer (Tns-reset) timeout\n" \
26  "Reset Timer (Tns-reset) number of retries\n" \
27  "Test Timer (Tns-test) timeout\n" \
28  "Alive Timer (Tns-alive) timeout\n" \
29  "Alive Timer (Tns-alive) number of retries\n" \
30  "SNS Provision Timer (Tsns-prov) timeout\n"
31 
32 /* Educated guess - LLC user payload is 1500 bytes plus possible headers */
33 #define NS_ALLOC_SIZE 3072
34 #define NS_ALLOC_HEADROOM 20
35 
45 };
46 
48  /* standard timers */
53 };
54 
55 enum ns_stat {
57 };
58 
60 enum gprs_ns_ll {
64 };
65 
73 };
74 
75 
76 #define NSE_S_BLOCKED 0x0001
77 #define NSE_S_ALIVE 0x0002
78 #define NSE_S_RESET 0x0004
79 
80 #define NS_DESC_B(st) ((st) & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED")
81 #define NS_DESC_A(st) ((st) & NSE_S_ALIVE ? "ALIVE" : "DEAD")
82 #define NS_DESC_R(st) ((st) & NSE_S_RESET ? "RESET" : "UNRESET")
83 
85 struct gprs_ns2_inst {
88 
90  void *cb_data;
91 
94 
96  struct llist_head nse;
97 
99  bool create_nse;
100 
102 
104  uint32_t rate_ctr_idx;
105 };
106 
108 struct gprs_ns2_nse {
109  uint16_t nsei;
110 
113 
115  struct llist_head list;
116 
118  struct llist_head nsvc;
119 
122 
125  bool first;
126 
128  bool alive;
129 
131 };
132 
134 struct gprs_ns2_vc {
136  struct llist_head list;
137 
139  struct llist_head blist;
140 
142  struct gprs_ns2_nse *nse;
143 
146 
149 
151  uint16_t nsvci;
152 
154  uint8_t sig_weight;
155 
157  uint8_t data_weight;
158 
160  void *priv;
161 
163  bool sns_only;
164 
167 
169  enum gprs_ns_ll ll;
171 
172  struct osmo_fsm_inst *fi;
173 };
174 
178  struct llist_head list;
180  struct llist_head nsvc;
182  void *priv;
186 
188  enum gprs_ns2_vc_mode vc_mode;
189 
191  int (*send_vc)(struct gprs_ns2_vc *nsvc, struct msgb *msg);
192 
194  void (*free_vc)(struct gprs_ns2_vc *nsvc);
195 
197  void (*dump_vty)(const struct gprs_ns2_vc_bind *bind,
198  struct vty *vty, bool stats);
199 };
200 
202  const char *name;
203  void *priv;
205 };
206 
207 enum gprs_ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind,
208  struct msgb *msg,
209  const char *logname,
210  struct msgb **reject,
211  struct gprs_ns2_vc **success);
212 
213 int ns2_recv_vc(struct gprs_ns2_vc *nsvc,
214  struct msgb *msg);
215 
217  struct gprs_ns2_nse *nse,
218  bool initiater);
219 
220 struct msgb *gprs_ns2_msgb_alloc(void);
221 
222 void gprs_ns2_sns_dump_vty(struct vty *vty, const struct gprs_ns2_nse *nse, bool stats);
224  uint16_t bvci,
225  enum gprs_ns2_affecting_cause cause);
226 void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive);
227 
228 /* message */
229 int gprs_ns2_validate(struct gprs_ns2_vc *nsvc,
230  uint8_t pdu_type,
231  struct msgb *msg,
232  struct tlv_parsed *tp,
233  uint8_t *cause);
234 
235 /* SNS messages */
236 int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause,
237  const struct gprs_ns_ie_ip4_elem *ip4_elems,
238  unsigned int num_ip4_elems,
239  const struct gprs_ns_ie_ip6_elem *ip6_elems,
240  unsigned int num_ip6_elems);
241 int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag,
242  const struct gprs_ns_ie_ip4_elem *ip4_elems,
243  unsigned int num_ip4_elems,
244  const struct gprs_ns_ie_ip6_elem *ip6_elems,
245  unsigned int num_ip6_elems);
246 int ns2_tx_sns_config_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
247 int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_nsvc,
248  int ip4_ep_nr, int ip6_ep_nr);
249 int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
250 
251 /* transmit message over a VC */
252 int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause);
253 int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc);
254 
255 int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause);
256 int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc);
257 
258 int ns2_tx_unblock(struct gprs_ns2_vc *nsvc);
259 int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc);
260 
261 int ns2_tx_alive(struct gprs_ns2_vc *nsvc);
262 int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc);
263 
264 int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc,
265  uint16_t bvci, uint8_t sducontrol,
266  struct msgb *msg);
267 
268 int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause,
269  uint16_t bvci, struct msgb *orig_msg);
270 
271 /* driver */
273  struct gprs_ns2_nse *nse,
274  const struct osmo_sockaddr *remote);
275 
276 /* sns */
277 int gprs_ns2_sns_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
279  const char *id);
280 int ns2_sns_bss_fsm_start(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc,
281  const struct osmo_sockaddr *remote);
282 void ns2_sns_free_nsvc(struct gprs_ns2_vc *nsvc);
283 
284 /* vc */
285 struct osmo_fsm_inst *gprs_ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc,
286  const char *id, bool initiate);
287 int gprs_ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc);
288 int gprs_ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
289 int gprs_ns2_vc_is_alive(struct gprs_ns2_vc *nsvc);
290 int gprs_ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc);
291 
292 /* vty.c */
293 void ns2_vty_bind_apply(struct gprs_ns2_vc_bind *bind);
294 
295 /* nse */
296 void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked);
int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause, const struct gprs_ns_ie_ip4_elem *ip4_elems, unsigned int num_ip4_elems, const struct gprs_ns_ie_ip6_elem *ip6_elems, unsigned int num_ip6_elems)
Encode + Transmit a SNS-ACK as per Section 9.3.1.
Definition: gprs_ns2_message.c:483
struct msgb * gprs_ns2_msgb_alloc(void)
Allocate a message buffer for use with the NS2 stack.
Definition: gprs_ns2.c:438
Structure representing a single NS-VC.
Definition: gprs_ns2_internal.h:134
Definition: gprs_ns2_internal.h:50
int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_nsvc, int ip4_ep_nr, int ip6_ep_nr)
Encode + transmit a SNS-SIZE as per Section 9.3.7.
Definition: gprs_ns2_message.c:637
uint32_t rate_ctr_idx
workaround for rate counter until rate counter accepts char str as index
Definition: gprs_ns2_internal.h:104
void * priv
can be used by the bind/driver of the virtual circuit.
Definition: gprs_ns2_internal.h:160
bool persistent
true if this NSE was created by VTY or pcu socket)
Definition: gprs_ns2_internal.h:121
void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked)
Notify a nse about the change of a NS-VC.
Definition: gprs_ns2.c:960
int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause, uint16_t bvci, struct msgb *orig_msg)
Transmit a NS-STATUS on a given NS-VC.
Definition: gprs_ns2_message.c:426
void ns2_vty_bind_apply(struct gprs_ns2_vc_bind *bind)
ns2_vty_bind_apply will be called when a new bind is created to apply vty settings ...
Definition: gprs_ns2_vty.c:834
uint8_t sig_weight
signalling weight.
Definition: gprs_ns2_internal.h:154
Structure repesenting a bind instance.
Definition: gprs_ns2_internal.h:176
uint16_t nsvci
uniquely identifies NS-VC if VC contains nsvci
Definition: gprs_ns2_internal.h:151
Definition: gprs_ns2_internal.h:40
Structure repesenting a NSE.
Definition: gprs_ns2_internal.h:108
int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause)
Transmit a NS-RESET on a given NS-VC.
Definition: gprs_ns2_message.c:271
Definition: gprs_ns2_internal.h:42
int gprs_ns2_vc_is_alive(struct gprs_ns2_vc *nsvc)
osmo_prim_cb cb
callback to the user for incoming UNIT DATA IND
Definition: gprs_ns2_internal.h:87
int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc)
Transmit a NS-ALIVE-ACK on a given NS-VC.
Definition: gprs_ns2_message.c:381
Definition: gprs_ns2_internal.h:44
Skipped message.
Definition: gprs_ns2_internal.h:71
gprs_ns2_affecting_cause
Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves.
Definition: gprs_ns2.h:48
An instance of the NS protocol stack.
Definition: gprs_ns2_internal.h:85
uint16_t nsei
Definition: gprs_ns2_internal.h:109
int gprs_ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp)
entry point for messages from the driver/VL
Definition: gprs_ns2_vc_fsm.c:604
bool alive
true if this NSE has at least one alive VC
Definition: gprs_ns2_internal.h:128
Definition: gprs_ns2_internal.h:201
Rejected and answered message.
Definition: gprs_ns2_internal.h:70
Definition: gprs_ns2_internal.h:38
Definition: gprs_ns2_internal.h:41
struct osmo_fsm_inst * gprs_ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc, const char *id, bool initiate)
gprs_ns2_vc_fsm_alloc
Definition: gprs_ns2_vc_fsm.c:568
A NSVC object has been created.
Definition: gprs_ns2_internal.h:68
struct osmo_stat_item_group * statg
Definition: gprs_ns2_internal.h:166
int ns2_tx_sns_config_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause)
Encode + Transmit a SNS-CONFIG-ACK as per Section 9.3.5.
Definition: gprs_ns2_message.c:594
bool create_nse
create dynamic NSE on receiving packages
Definition: gprs_ns2_internal.h:99
Failed to process message.
Definition: gprs_ns2_internal.h:72
Definition: gprs_ns2_internal.h:49
struct gprs_ns2_inst * nsi
entry back to ns2_inst
Definition: gprs_ns2_internal.h:112
uint16_t timeout[NS_TIMERS_COUNT]
Definition: gprs_ns2_internal.h:101
gprs_ns2_vc_mode
Definition: gprs_ns2.h:22
Definition: gprs_ns2_internal.h:37
struct gprs_ns2_nse * nse
pointer to NS Instance
Definition: gprs_ns2_internal.h:142
struct llist_head nse
linked lists of all NSVC in this instance
Definition: gprs_ns2_internal.h:96
int gprs_ns2_validate(struct gprs_ns2_vc *nsvc, uint8_t pdu_type, struct msgb *msg, struct tlv_parsed *tp, uint8_t *cause)
Definition: gprs_ns2_message.c:152
static void free_bind(struct gprs_ns2_vc_bind *bind)
clean up all private driver state.
Definition: gprs_ns2_frgre.c:135
int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag, const struct gprs_ns_ie_ip4_elem *ip4_elems, unsigned int num_ip4_elems, const struct gprs_ns_ie_ip6_elem *ip6_elems, unsigned int num_ip6_elems)
Encode + Transmit a SNS-CONFIG as per Section 9.3.4.
Definition: gprs_ns2_message.c:541
const char * name
Definition: gprs_ns2_internal.h:202
void gprs_ns2_sns_dump_vty(struct vty *vty, const struct gprs_ns2_nse *nse, bool stats)
Dump the IP-SNS state to a vty.
Definition: gprs_ns2_sns.c:1456
NS/FR/GRE/IP.
Definition: gprs_ns2_internal.h:63
Section 10.3.2d List of IP6 Elements.
Definition: gsm_08_16.h:32
void * cb_data
callback data
Definition: gprs_ns2_internal.h:90
ns_stat
Definition: gprs_ns.c:166
void ns2_prim_status_ind(struct gprs_ns2_nse *nse, uint16_t bvci, enum gprs_ns2_affecting_cause cause)
Send a STATUS.ind primitive to the specified NS instance user.
Definition: gprs_ns2.c:347
int gprs_ns2_sns_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp)
main entry point for receiving SNS messages from the network.
Definition: gprs_ns2_sns.c:1375
Definition: gprs_ns2_internal.h:39
struct gprs_ns2_vc_driver * driver
Definition: gprs_ns2_internal.h:185
gprs_ns2_cs
Osmocom NS2 VC create status.
Definition: gprs_ns2_internal.h:67
uint16_t bvci
Definition: gprs_msgb.h:82
void * priv
Definition: gprs_ns2_internal.h:203
int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause)
Encode + Transmit a SNS-SIZE-ACK as per Section 9.3.8.
Definition: gprs_ns2_message.c:682
nsvc_timer_mode
Definition: gprs_ns.h:113
struct gprs_ns2_vc * ns2_vc_alloc(struct gprs_ns2_vc_bind *bind, struct gprs_ns2_nse *nse, bool initiater)
Allocate a NS-VC within the given bind + NSE.
Definition: gprs_ns2.c:368
struct gprs_ns2_vc * gprs_ns2_ip_bind_connect(struct gprs_ns2_vc_bind *bind, struct gprs_ns2_nse *nse, const struct osmo_sockaddr *remote)
Create new NS-VC to a given remote address.
Definition: gprs_ns2_udp.c:374
int gprs_ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc)
Start a NS-VC FSM.
Definition: gprs_ns2_vc_fsm.c:591
Definition: gprs_ns2_internal.h:52
int gprs_ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc)
is the given NS-VC unblocked?
Definition: gprs_ns2_vc_fsm.c:659
static void dump_vty(const struct gprs_ns2_vc_bind *bind, struct vty *vty, bool _stats)
Definition: gprs_ns2_udp.c:81
struct osmo_fsm_inst * fi
Definition: gprs_ns2_internal.h:172
uint8_t data_weight
signaling weight.
Definition: gprs_ns2_internal.h:157
struct gprs_ns2_inst * nsi
a pointer back to the nsi
Definition: gprs_ns2_internal.h:184
int ns2_tx_alive(struct gprs_ns2_vc *nsvc)
Transmit a NS-ALIVE on a given NS-VC.
Definition: gprs_ns2_message.c:369
uint8_t mode
Section 10.3.2c List of IP4 Elements.
Definition: gsm_08_16.h:24
Definition: gprs_ns2_internal.h:51
int(* osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx)
static void free_vc(struct gprs_ns2_vc *nsvc)
Definition: gprs_ns2_frgre.c:122
uint8_t msg[0]
bool nsvci_is_valid
Definition: gprs_ns2_internal.h:162
NS/E1.
Definition: gprs_ns2_internal.h:62
ns2_timeout
Definition: gprs_ns2_internal.h:36
int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc)
Transmit a NS-RESET-ACK on a given NS-VC.
Definition: gprs_ns2_message.c:303
gprs_ns_ll
Osmocom NS link layer types.
Definition: gprs_ns.h:53
enum gprs_ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind, struct msgb *msg, const char *logname, struct msgb **reject, struct gprs_ns2_vc **success)
Create a new NS-VC based on a [received] message.
Definition: gprs_ns2.c:630
bool first
true if this NSE wasn&#39;t yet alive at all.
Definition: gprs_ns2_internal.h:125
Definition: gprs_ns2_internal.h:43
bool sns_only
Definition: gprs_ns2_internal.h:163
GPRS Networks Service (NS) messages on the Gb interface.
NS/UDP/IP.
Definition: gprs_ns2_internal.h:61
bool persistent
true if this NS was created by VTY or pcu socket)
Definition: gprs_ns2_internal.h:148
int ns2_recv_vc(struct gprs_ns2_vc *nsvc, struct msgb *msg)
Bottom-side entry-point for received NS PDU from the driver/bind.
Definition: gprs_ns2.c:886
struct osmo_fsm_inst * bss_sns_fi
Definition: gprs_ns2_internal.h:130
int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc, uint16_t bvci, uint8_t sducontrol, struct msgb *msg)
Transmit NS-UNITDATA on a given NS-VC.
Definition: gprs_ns2_message.c:396
struct gprs_ns2_vc_bind * bind
pointer to NS VL bind.
Definition: gprs_ns2_internal.h:145
struct llist_head nsvc
list of all VC
Definition: gprs_ns2_internal.h:180
A NSVC object has been found.
Definition: gprs_ns2_internal.h:69
int ns2_sns_bss_fsm_start(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, const struct osmo_sockaddr *remote)
Start an IP-SNS FSM.
Definition: gprs_ns2_sns.c:1248
int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause)
Transmit a NS-BLOCK on a given NS-VC.
Definition: gprs_ns2_message.c:209
Definition: gprs_ns2_internal.h:56
#define NS_TIMERS_COUNT
Definition: gprs_ns2_internal.h:20
int ns2_tx_unblock(struct gprs_ns2_vc *nsvc)
Transmit a NS-UNBLOCK on a given NS-VC.
Definition: gprs_ns2_message.c:338
void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive)
void ns2_sns_free_nsvc(struct gprs_ns2_vc *nsvc)
called when a nsvc is beeing freed
Definition: gprs_ns2_sns.c:213
struct llist_head binding
linked lists of all NSVC binds (e.g.
Definition: gprs_ns2_internal.h:93
struct osmo_fsm_inst * ns2_sns_bss_fsm_alloc(struct gprs_ns2_nse *nse, const char *id)
Allocate an IP-SNS FSM for the BSS side.
Definition: gprs_ns2_sns.c:1220
struct rate_ctr_group * ctrg
Definition: gprs_ns2_internal.h:165
int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc)
Transmit a NS-BLOCK-ACK on a given NS-VC.
Definition: gprs_ns2_message.c:241
void * priv
driver private structure
Definition: gprs_ns2_internal.h:182
uint8_t pdu_type
NS PDU type.
Definition: gsm_08_16.h:200
int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc)
Transmit a NS-UNBLOCK-ACK on a given NS-VC.
Definition: gprs_ns2_message.c:354