libosmogb  0.12.0.47-7c74
Osmocom Gb library
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>
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 
46 #define NS_DESC_B(st) ((st) & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED")
47 #define NS_DESC_A(st) ((st) & NSE_S_ALIVE ? "ALIVE" : "DEAD")
48 #define NS_DESC_R(st) ((st) & NSE_S_RESET ? "RESET" : "UNRESET")
49 
51 enum gprs_ns_ll {
55 };
56 
60 };
61 
63 enum gprs_ns_cs {
69 };
70 
71 struct gprs_nsvc;
73 typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
74  struct msgb *msg, uint16_t bvci);
75 
77 struct gprs_ns_inst {
80 
83 
87 
89 
91  struct {
92  struct osmo_fd fd;
93  uint32_t local_ip;
94  uint16_t local_port;
95  uint32_t remote_ip;
96  uint16_t remote_port;
97  int dscp;
98  } nsip;
100  struct {
101  struct osmo_fd fd;
102  uint32_t local_ip;
103  unsigned int enabled:1;
104  } frgre;
105 };
106 
108  /* standard timers */
113 };
114 
116 struct gprs_nsvc {
118  struct llist_head list;
120  struct gprs_ns_inst *nsi;
121 
122  uint16_t nsei;
123  uint16_t nsvci;
125  uint32_t state;
126  uint32_t remote_state;
127 
128  struct osmo_timer_list timer;
129  enum nsvc_timer_mode timer_mode;
130  struct timeval timer_started;
132 
133  unsigned int remote_end_is_sgsn:1;
134  unsigned int persistent:1;
135  unsigned int nsvci_is_valid:1;
136 
139 
141  enum gprs_ns_ll ll;
142 
145  union {
146  struct {
147  struct sockaddr_in bts_addr;
148  } ip;
149  struct {
150  struct sockaddr_in bts_addr;
151  } frgre;
152  };
153 };
154 
155 /* Create a new NS protocol instance */
156 struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx);
157 
158 /* Close a NS protocol instance */
159 void gprs_ns_close(struct gprs_ns_inst *nsi);
160 
161 /* Close and Destroy a NS protocol instance */
162 void gprs_ns_destroy(struct gprs_ns_inst *nsi);
163 
164 /* Listen for incoming GPRS packets via NS/UDP */
165 int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi);
166 
167 /* Establish a connection (from the BSS) to the SGSN */
169  struct sockaddr_in *dest,
170  uint16_t nsei, uint16_t nsvci);
171 
172 
173 struct sockaddr_in;
174 
175 /* main function for higher layers (BSSGP) to send NS messages */
176 int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
177 
178 int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause);
179 int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause);
180 int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc);
181 
182 /* Listen for incoming GPRS packets via NS/FR/GRE */
183 int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi);
184 
185 struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci);
186 void gprs_nsvc_delete(struct gprs_nsvc *nsvc);
187 struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei);
188 struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci);
189 
190 /* Initiate a RESET procedure (including timer start, ...)*/
191 int gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
192 
193 /* Add NS-specific VTY stuff */
194 int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
195 
196 /* Resturn peer info as string (NOTE: the buffer is allocated statically) */
197 const char *gprs_ns_ll_str(const struct gprs_nsvc *nsvc);
198 
199 /* Copy the link layer info from other into nsvc */
200 void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other);
201 
202 /* Clear the link layer info (will never match a real link then) */
203 void gprs_ns_ll_clear(struct gprs_nsvc *nsvc);
204 
205 struct msgb *gprs_ns_msgb_alloc(void);
206 
207 enum signal_ns {
211  S_NS_ALIVE_EXP, /* Tns-alive expired more than N times */
212  S_NS_REPLACED, /* nsvc object is replaced (sets old_nsvc) */
213  S_NS_MISMATCH, /* got an unexpected IE (sets msg, pdu_type, ie_type) */
214 };
215 
216 extern const struct value_string gprs_ns_signal_ns_names[];
217 const char *gprs_ns_cause_str(enum ns_cause cause);
218 
220  struct gprs_nsvc *nsvc;
222  uint8_t cause;
223  uint8_t pdu_type;
224  uint8_t ie_type;
225  struct msgb *msg;
226 };
227 
228 void gprs_ns_set_log_ss(int ss);
229 
230 char *gprs_nsvc_state_append(char *s, struct gprs_nsvc *nsvc);
231 
Definition: gprs_ns.h:213
signal_ns
Definition: gprs_ns.h:207
Definition: gprs_ns.h:211
Definition: gprs_ns.h:109
NS/FR/GRE/IP.
Definition: gprs_ns.h:54
struct msgb * gprs_ns_msgb_alloc(void)
Definition: gprs_ns.c:174
uint32_t remote_ip
Definition: gprs_ns.h:95
Structure representing a single NS-VC.
Definition: gprs_ns.h:116
void gprs_ns_destroy(struct gprs_ns_inst *nsi)
Destroy an entire NS instance.
Definition: gprs_ns.c:1495
int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc)
Transmit a NS-UNBLOCK on a given NS-VC.
Definition: gprs_ns.c:554
unsigned int persistent
Definition: gprs_ns.h:134
uint16_t nsei
Definition: gprs_ns.h:122
struct gprs_ns_inst * nsi
pointer to NS Instance
Definition: gprs_ns.h:120
void gprs_ns_close(struct gprs_ns_inst *nsi)
Definition: gprs_ns.c:1471
NS/UDP/IP.
Definition: gprs_ns.h:52
gprs_ns_cs
Osmocom NS VC create status.
Definition: gprs_ns.h:63
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:728
uint32_t local_ip
Definition: gprs_ns.h:93
int dscp
Definition: gprs_ns.h:97
Definition: gprs_ns.h:219
struct llist_head gprs_nsvcs
linked lists of all NSVC in this instance
Definition: gprs_ns.h:82
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:522
uint16_t remote_port
Definition: gprs_ns.h:96
struct gprs_ns_inst * gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx)
Create a new GPRS NS instance.
Definition: gprs_ns.c:1447
unsigned int nsvci_is_valid
Definition: gprs_ns.h:135
NS/E1.
Definition: gprs_ns.h:53
struct gprs_nsvc * unknown_nsvc
a NSVC object that&#39;s needed to deal with packets for unknown NSVC
Definition: gprs_ns.h:86
gprs_ns_cb_t * cb
callback to the user for incoming UNIT DATA IND
Definition: gprs_ns.h:79
struct gprs_nsvc * gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
Definition: gprs_ns.c:262
Definition: gprs_ns.h:59
Skipped message.
Definition: gprs_ns.h:67
Definition: gprs_ns.h:111
An instance of the NS protocol stack.
Definition: gprs_ns.h:77
void gprs_ns_set_log_ss(int ss)
Definition: gprs_ns.c:1703
struct msgb * msg
Definition: gprs_ns.h:225
Definition: gprs_ns.h:209
void gprs_nsvc_delete(struct gprs_nsvc *nsvc)
Delete given NS-VC.
Definition: gprs_ns.c:286
const char * gprs_ns_ll_str(const struct gprs_nsvc *nsvc)
Definition: gprs_ns.c:1176
gprs_ns_evt
Osmoco NS events.
Definition: gprs_ns.h:58
struct rate_ctr_group * ctrg
Definition: gprs_ns.h:137
Definition: gprs_ns.h:36
A NSVC object has been found.
Definition: gprs_ns.h:65
int gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause)
Initiate a RESET procedure.
Definition: gprs_ns.c:1654
const struct value_string gprs_ns_signal_ns_names[]
Definition: gprs_ns.c:159
uint16_t nsei
Definition: gprs_msgb.h:80
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:1686
struct gprs_nsvc * nsvc
Definition: gprs_ns.h:220
int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi)
Create a listening socket for GPRS NS/UDP/IP.
Definition: gprs_ns.c:1597
Definition: gprs_ns.h:208
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:222
Definition: gprs_ns.h:110
uint16_t local_port
Definition: gprs_ns.h:94
uint16_t bvci
Definition: gprs_msgb.h:81
void gprs_ns_ll_clear(struct gprs_nsvc *nsvc)
Definition: gprs_ns.c:1215
Definition: gprs_ns.h:37
nsvc_timer_mode
Definition: gprs_ns.h:107
uint16_t timeout[NS_TIMERS_COUNT]
Definition: gprs_ns.h:88
#define NS_TIMERS_COUNT
Definition: gprs_ns.h:17
struct osmo_fd fd
Definition: gprs_ns.h:92
unsigned int enabled
Definition: gprs_ns.h:103
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:73
uint16_t nsvci
end-to-end significance
Definition: gprs_ns.h:123
uint32_t remote_state
Definition: gprs_ns.h:126
uint8_t pdu_type
Definition: gprs_ns.h:223
char * gprs_nsvc_state_append(char *s, struct gprs_nsvc *nsvc)
Append the nsvc state to a talloc string.
Definition: gprs_ns.c:1716
A NSVC object has been created.
Definition: gprs_ns.h:64
Definition: gprs_ns.h:34
Rejected and answered message.
Definition: gprs_ns.h:66
unsigned int remote_end_is_sgsn
Definition: gprs_ns.h:133
uint8_t cause
Definition: gprs_ns.h:222
int alive_retries
Definition: gprs_ns.h:131
ns_cause
NS Cause (TS 08.16, Section 10.3.2, Table 13)
Definition: gsm_08_16.h:63
void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other)
Definition: gprs_ns.c:1199
const char * gprs_ns_cause_str(enum ns_cause cause)
Obtain a human-readable string for NS cause value.
Definition: gprs_ns.c:372
uint32_t state
uniquely identifies NS-VC at SGSN
Definition: gprs_ns.h:125
struct gprs_nsvc * old_nsvc
Definition: gprs_ns.h:221
int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi)
Definition: gprs_ns_frgre.c:326
Definition: gprs_ns.h:39
uint8_t ie_type
Definition: gprs_ns.h:224
Definition: gprs_ns.h:33
gprs_ns_ll
Osmocom NS link layer types.
Definition: gprs_ns.h:51
GPRS Networks Service (NS) messages on the Gb interface.
Definition: gprs_ns.h:35
struct gprs_ns_inst::@2 nsip
NS-over-IP specific bits.
Definition: gprs_ns.h:38
Definition: gprs_ns.h:210
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:436
struct osmo_stat_item_group * statg
Definition: gprs_ns.h:138
int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
Definition: gprs_ns_vty.c:600
Definition: gprs_ns.h:212
Failed to process message.
Definition: gprs_ns.h:68
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:207
Definition: gprs_ns.h:112
struct gprs_ns_inst::@3 frgre
NS-over-FR-over-GRE-over-IP specific bits.