libosmogb  0.9.6.311-c977
Osmocom Gb library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
gprs_ns.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <stdint.h>
6 
7 /* Our Implementation */
8 #include <netinet/in.h>
9 #include <osmocom/core/linuxlist.h>
10 #include <osmocom/core/msgb.h>
11 #include <osmocom/core/timer.h>
12 #include <osmocom/core/select.h>
13 #include <osmocom/gprs/gprs_msgb.h>
14 
16 
17 #define NS_TIMERS_COUNT 7
18 #define NS_TIMERS "(tns-block|tns-block-retries|tns-reset|tns-reset-retries|tns-test|tns-alive|tns-alive-retries)"
19 #define NS_TIMERS_HELP \
20  "(un)blocking Timer (Tns-block) timeout\n" \
21  "(un)blocking Timer (Tns-block) number of retries\n" \
22  "Reset Timer (Tns-reset) timeout\n" \
23  "Reset Timer (Tns-reset) number of retries\n" \
24  "Test Timer (Tns-test) timeout\n" \
25  "Alive Timer (Tns-alive) timeout\n" \
26  "Alive Timer (Tns-alive) number of retries\n"
27 
28 /* Educated guess - LLC user payload is 1500 bytes plus possible headers */
29 #define NS_ALLOC_SIZE 3072
30 #define NS_ALLOC_HEADROOM 20
31 
32 enum ns_timeout {
40 };
41 
42 #define NSE_S_BLOCKED 0x0001
43 #define NSE_S_ALIVE 0x0002
44 #define NSE_S_RESET 0x0004
45 
47 enum gprs_ns_ll {
51 };
52 
56 };
57 
59 enum gprs_ns_cs {
65 };
66 
67 struct gprs_nsvc;
69 typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
70  struct msgb *msg, uint16_t bvci);
71 
73 struct gprs_ns_inst {
76 
78  struct llist_head gprs_nsvcs;
79 
83 
85 
87  struct {
88  struct osmo_fd fd;
89  uint32_t local_ip;
90  uint16_t local_port;
91  int dscp;
92  } nsip;
94  struct {
95  struct osmo_fd fd;
96  uint32_t local_ip;
97  unsigned int enabled:1;
98  } frgre;
99 };
100 
102  /* standard timers */
107 };
108 
110 struct gprs_nsvc {
112  struct llist_head list;
114  struct gprs_ns_inst *nsi;
115 
116  uint16_t nsei;
117  uint16_t nsvci;
119  uint32_t state;
120  uint32_t remote_state;
121 
122  struct osmo_timer_list timer;
124  struct timeval timer_started;
126 
127  unsigned int remote_end_is_sgsn:1;
128  unsigned int persistent:1;
129  unsigned int nsvci_is_valid:1;
130 
131  struct rate_ctr_group *ctrg;
132  struct osmo_stat_item_group *statg;
133 
136 
137  union {
138  struct {
139  struct sockaddr_in bts_addr;
140  } ip;
141  struct {
142  struct sockaddr_in bts_addr;
143  } frgre;
144  };
145 };
146 
147 /* Create a new NS protocol instance */
148 struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx);
149 
150 /* Close a NS protocol instance */
151 void gprs_ns_close(struct gprs_ns_inst *nsi);
152 
153 /* Close and Destroy a NS protocol instance */
154 void gprs_ns_destroy(struct gprs_ns_inst *nsi);
155 
156 /* Listen for incoming GPRS packets via NS/UDP */
157 int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi);
158 
159 /* Establish a connection (from the BSS) to the SGSN */
161  struct sockaddr_in *dest,
162  uint16_t nsei, uint16_t nsvci);
163 
164 
165 struct sockaddr_in;
166 
167 /* main function for higher layers (BSSGP) to send NS messages */
168 int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
169 
170 int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause);
171 int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause);
172 int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc);
173 
174 /* Listen for incoming GPRS packets via NS/FR/GRE */
175 int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi);
176 
177 struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci);
178 void gprs_nsvc_delete(struct gprs_nsvc *nsvc);
179 struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei);
180 struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci);
181 
182 /* Initiate a RESET procedure (including timer start, ...)*/
183 int gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
184 
185 /* Add NS-specific VTY stuff */
186 int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
187 
188 /* Resturn peer info as string (NOTE: the buffer is allocated statically) */
189 const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc);
190 
191 /* Copy the link layer info from other into nsvc */
192 void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other);
193 
194 /* Clear the link layer info (will never match a real link then) */
195 void gprs_ns_ll_clear(struct gprs_nsvc *nsvc);
196 
197 struct msgb *gprs_ns_msgb_alloc(void);
198 
199 enum signal_ns {
203  S_NS_ALIVE_EXP, /* Tns-alive expired more than N times */
204  S_NS_REPLACED, /* nsvc object is replaced (sets old_nsvc) */
205  S_NS_MISMATCH, /* got an unexpected IE (sets msg, pdu_type, ie_type) */
206 };
207 
208 extern const struct value_string gprs_ns_signal_ns_names[];
209 
211  struct gprs_nsvc *nsvc;
213  uint8_t cause;
214  uint8_t pdu_type;
215  uint8_t ie_type;
216  struct msgb *msg;
217 };
218 
219 void gprs_ns_set_log_ss(int ss);
220 
struct timeval timer_started
Definition: gprs_ns.h:124
Definition: gprs_ns.h:205
signal_ns
Definition: gprs_ns.h:199
Definition: gprs_ns.h:203
Definition: gprs_ns.h:103
NS/FR/GRE/IP.
Definition: gprs_ns.h:50
struct msgb * gprs_ns_msgb_alloc(void)
Definition: gprs_ns.c:166
Structure representing a single NS-VC.
Definition: gprs_ns.h:110
void gprs_ns_destroy(struct gprs_ns_inst *nsi)
Destroy an entire NS instance.
Definition: gprs_ns.c:1459
int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc)
Transmit a NS-UNBLOCK on a given NS-VC.
Definition: gprs_ns.c:530
unsigned int persistent
Definition: gprs_ns.h:128
uint16_t nsei
Definition: gprs_ns.h:116
struct gprs_ns_inst * nsi
pointer to NS Instance
Definition: gprs_ns.h:114
void gprs_ns_close(struct gprs_ns_inst *nsi)
Definition: gprs_ns.c:1435
NS/UDP/IP.
Definition: gprs_ns.h:48
gprs_ns_cs
Osmocom NS VC create status.
Definition: gprs_ns.h:59
int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg)
High-level function for transmitting a NS-UNITDATA messsage.
Definition: gprs_ns.c:704
uint32_t local_ip
Definition: gprs_ns.h:89
int dscp
Definition: gprs_ns.h:91
Definition: gprs_ns.h:210
struct llist_head gprs_nsvcs
linked lists of all NSVC in this instance
Definition: gprs_ns.h:78
int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause)
Transmit a NS-BLOCK on a tiven NS-VC.
Definition: gprs_ns.c:498
struct gprs_ns_inst * gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx)
Create a new GPRS NS instance.
Definition: gprs_ns.c:1411
unsigned int nsvci_is_valid
Definition: gprs_ns.h:129
NS/E1.
Definition: gprs_ns.h:49
struct gprs_nsvc * unknown_nsvc
a NSVC object that's needed to deal with packets for unknown NSVC
Definition: gprs_ns.h:82
struct llist_head list
list of NS-VCs within NS Instance
Definition: gprs_ns.h:112
gprs_ns_cb_t * cb
callback to the user for incoming UNIT DATA IND
Definition: gprs_ns.h:75
struct gprs_nsvc * gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
Definition: gprs_ns.c:238
Definition: gprs_ns.h:55
Skipped message.
Definition: gprs_ns.h:63
Definition: gprs_ns.h:105
An instance of the NS protocol stack.
Definition: gprs_ns.h:73
void gprs_ns_set_log_ss(int ss)
Definition: gprs_ns.c:1644
struct msgb * msg
Definition: gprs_ns.h:216
Definition: gprs_ns.h:201
struct osmo_timer_list timer
Definition: gprs_ns.h:122
struct gprs_nsvc::@4::@7 frgre
void gprs_nsvc_delete(struct gprs_nsvc *nsvc)
Delete given NS-VC.
Definition: gprs_ns.c:262
gprs_ns_evt
Osmoco NS events.
Definition: gprs_ns.h:54
enum gprs_ns_ll ll
which link-layer are we based on?
Definition: gprs_ns.h:135
struct rate_ctr_group * ctrg
Definition: gprs_ns.h:131
Definition: gprs_ns.h:36
struct gprs_nsvc::@4::@6 ip
A NSVC object has been found.
Definition: gprs_ns.h:61
int gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause)
Initiate a RESET procedure.
Definition: gprs_ns.c:1595
const struct value_string gprs_ns_signal_ns_names[]
Definition: gprs_ns.c:151
uint16_t nsei
Definition: gprs_msgb.h:79
struct gprs_nsvc * gprs_ns_nsip_connect(struct gprs_ns_inst *nsi, struct sockaddr_in *dest, uint16_t nsei, uint16_t nsvci)
Establish a NS connection (from the BSS) to the SGSN.
Definition: gprs_ns.c:1627
struct gprs_nsvc * nsvc
Definition: gprs_ns.h:211
int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi)
Create a listening socket for GPRS NS/UDP/IP.
Definition: gprs_ns.c:1561
Definition: gprs_ns.h:200
struct gprs_nsvc * gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei)
Lookup struct gprs_nsvc based on NSEI.
Definition: gprs_ns.c:198
Definition: gprs_ns.h:104
uint16_t local_port
Definition: gprs_ns.h:90
uint16_t bvci
Definition: gprs_msgb.h:80
void gprs_ns_ll_clear(struct gprs_nsvc *nsvc)
Definition: gprs_ns.c:1179
Definition: gprs_ns.h:37
nsvc_timer_mode
Definition: gprs_ns.h:101
uint16_t timeout[NS_TIMERS_COUNT]
Definition: gprs_ns.h:84
#define NS_TIMERS_COUNT
Definition: gprs_ns.h:17
struct osmo_fd fd
Definition: gprs_ns.h:88
unsigned int enabled
Definition: gprs_ns.h:97
int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
Osmocom GPRS callback function type.
Definition: gprs_ns.h:69
uint16_t nsvci
end-to-end significance
Definition: gprs_ns.h:117
uint32_t remote_state
Definition: gprs_ns.h:120
uint8_t pdu_type
Definition: gprs_ns.h:214
A NSVC object has been created.
Definition: gprs_ns.h:60
Definition: gprs_ns.h:34
Rejected and answered message.
Definition: gprs_ns.h:62
unsigned int remote_end_is_sgsn
Definition: gprs_ns.h:127
uint8_t cause
Definition: gprs_ns.h:213
int alive_retries
Definition: gprs_ns.h:125
void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other)
Definition: gprs_ns.c:1163
uint32_t state
uniquely identifies NS-VC at SGSN
Definition: gprs_ns.h:119
struct gprs_nsvc * old_nsvc
Definition: gprs_ns.h:212
int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi)
Definition: gprs_ns_frgre.c:324
Definition: gprs_ns.h:39
uint8_t ie_type
Definition: gprs_ns.h:215
enum nsvc_timer_mode timer_mode
Definition: gprs_ns.h:123
Definition: gprs_ns.h:33
gprs_ns_ll
Osmocom NS link layer types.
Definition: gprs_ns.h:47
GPRS Networks Service (NS) messages on the Gb interface.
const char * gprs_ns_ll_str(struct gprs_nsvc *nsvc)
Definition: gprs_ns.c:1152
Definition: gprs_ns.h:35
struct sockaddr_in bts_addr
Definition: gprs_ns.h:139
struct gprs_ns_inst::@2 nsip
NS-over-IP specific bits.
Definition: gprs_ns.h:38
Definition: gprs_ns.h:202
ns_timeout
Definition: gprs_ns.h:32
int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause)
Transmit a NS-RESET on a given NSVC.
Definition: gprs_ns.c:412
struct osmo_stat_item_group * statg
Definition: gprs_ns.h:132
int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
Definition: gprs_ns_vty.c:576
Definition: gprs_ns.h:204
Failed to process message.
Definition: gprs_ns.h:64
struct gprs_nsvc * gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci)
Lookup struct gprs_nsvc based on NSVCI.
Definition: gprs_ns.c:183
Definition: gprs_ns.h:106
struct gprs_ns_inst::@3 frgre
NS-over-FR-over-GRE-over-IP specific bits.