blob: a166956b0d35a92566b8797497a8345b0c7de0f1 [file] [log] [blame]
Harald Welte24a655f2010-04-30 19:54:29 +02001/* GPRS Networks Service (NS) messages on the Gb interfacebvci = msgb_bvci(msg);
Harald Welte9ba50052010-03-14 15:45:01 +08002 * 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05) */
3
Harald Weltef030b212010-04-26 19:18:54 +02004/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte9ba50052010-03-14 15:45:01 +08005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24/* Some introduction into NS: NS is used typically on top of frame relay,
25 * but in the ip.access world it is encapsulated in UDP packets. It serves
26 * as an intermediate shim betwen BSSGP and the underlying medium. It doesn't
27 * do much, apart from providing congestion notification and status indication.
28 *
29 * Terms:
30 * NS Network Service
31 * NSVC NS Virtual Connection
32 * NSEI NS Entity Identifier
33 * NSVL NS Virtual Link
34 * NSVLI NS Virtual Link Identifier
35 * BVC BSSGP Virtual Connection
36 * BVCI BSSGP Virtual Connection Identifier
37 * NSVCG NS Virtual Connection Goup
38 * Blocked NS-VC cannot be used for user traffic
39 * Alive Ability of a NS-VC to provide communication
40 *
41 * There can be multiple BSSGP virtual connections over one (group of) NSVC's. BSSGP will
42 * therefore identify the BSSGP virtual connection by a BVCI passed down to NS.
43 * NS then has to firgure out which NSVC's are responsible for this BVCI.
44 * Those mappings are administratively configured.
45 */
46
47#include <stdlib.h>
48#include <unistd.h>
49#include <errno.h>
Harald Welte8f9a3ee2010-05-02 11:26:34 +020050#include <stdint.h>
Harald Welte9ba50052010-03-14 15:45:01 +080051
52#include <arpa/inet.h>
53
54#include <openbsc/gsm_data.h>
55#include <osmocore/msgb.h>
56#include <osmocore/tlv.h>
57#include <osmocore/talloc.h>
Harald Weltef030b212010-04-26 19:18:54 +020058#include <osmocore/select.h>
Harald Welte9ba50052010-03-14 15:45:01 +080059#include <openbsc/debug.h>
Harald Welte834f26d2010-05-11 06:20:54 +020060#include <openbsc/signal.h>
Harald Welte9ba50052010-03-14 15:45:01 +080061#include <openbsc/gprs_ns.h>
62#include <openbsc/gprs_bssgp.h>
63
64#define NS_ALLOC_SIZE 1024
65
66static const struct tlv_definition ns_att_tlvdef = {
67 .def = {
68 [NS_IE_CAUSE] = { TLV_TYPE_TvLV, 0 },
69 [NS_IE_VCI] = { TLV_TYPE_TvLV, 0 },
70 [NS_IE_PDU] = { TLV_TYPE_TvLV, 0 },
71 [NS_IE_BVCI] = { TLV_TYPE_TvLV, 0 },
72 [NS_IE_NSEI] = { TLV_TYPE_TvLV, 0 },
73 },
74};
75
Harald Weltef030b212010-04-26 19:18:54 +020076/* Lookup struct gprs_nsvc based on NSVCI */
77static struct gprs_nsvc *nsvc_by_nsvci(struct gprs_ns_inst *nsi,
Harald Welte8f9a3ee2010-05-02 11:26:34 +020078 uint16_t nsvci)
Harald Weltef030b212010-04-26 19:18:54 +020079{
80 struct gprs_nsvc *nsvc;
81 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
82 if (nsvc->nsvci == nsvci)
83 return nsvc;
84 }
85 return NULL;
86}
87
Harald Welte24a655f2010-04-30 19:54:29 +020088/* Lookup struct gprs_nsvc based on NSVCI */
89static struct gprs_nsvc *nsvc_by_nsei(struct gprs_ns_inst *nsi,
Harald Welte8f9a3ee2010-05-02 11:26:34 +020090 uint16_t nsei)
Harald Welte24a655f2010-04-30 19:54:29 +020091{
92 struct gprs_nsvc *nsvc;
93 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
94 if (nsvc->nsei == nsei)
95 return nsvc;
96 }
97 return NULL;
98}
99
100
Harald Weltef030b212010-04-26 19:18:54 +0200101/* Lookup struct gprs_nsvc based on remote peer socket addr */
102static struct gprs_nsvc *nsvc_by_rem_addr(struct gprs_ns_inst *nsi,
103 struct sockaddr_in *sin)
104{
105 struct gprs_nsvc *nsvc;
106 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Welte38407ef2010-05-12 11:56:39 +0000107 if (nsvc->ip.bts_addr.sin_addr.s_addr ==
108 sin->sin_addr.s_addr &&
109 nsvc->ip.bts_addr.sin_port == sin->sin_port)
Harald Weltef030b212010-04-26 19:18:54 +0200110 return nsvc;
111 }
112 return NULL;
113}
114
Harald Welte69a4cf22010-05-03 20:55:10 +0200115static void gprs_ns_timer_cb(void *data);
116
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200117static struct gprs_nsvc *nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
Harald Weltef030b212010-04-26 19:18:54 +0200118{
119 struct gprs_nsvc *nsvc;
120
121 nsvc = talloc_zero(nsi, struct gprs_nsvc);
122 nsvc->nsvci = nsvci;
123 /* before RESET procedure: BLOCKED and DEAD */
124 nsvc->state = NSE_S_BLOCKED;
125 nsvc->nsi = nsi;
Harald Welte69a4cf22010-05-03 20:55:10 +0200126 nsvc->timer.cb = gprs_ns_timer_cb;
127 nsvc->timer.data = nsvc;
128
Harald Weltef030b212010-04-26 19:18:54 +0200129 llist_add(&nsvc->list, &nsi->gprs_nsvcs);
130
131 return nsvc;
132}
Harald Welte9ba50052010-03-14 15:45:01 +0800133
Harald Welte2fc725d2010-05-11 10:15:26 +0200134static void ns_dispatch_signal(struct gprs_nsvc *nsvc, unsigned int signal,
Harald Welte834f26d2010-05-11 06:20:54 +0200135 uint8_t cause)
136{
137 struct ns_signal_data nssd;
138
139 nssd.nsvc = nsvc;
140 nssd.cause = cause;
141
142 dispatch_signal(SS_NS, signal, &nssd);
143}
144
Harald Welte9ba50052010-03-14 15:45:01 +0800145/* Section 10.3.2, Table 13 */
Harald Welte2577d412010-05-02 09:37:45 +0200146static const struct value_string ns_cause_str[] = {
147 { NS_CAUSE_TRANSIT_FAIL, "Transit network failure" },
148 { NS_CAUSE_OM_INTERVENTION, "O&M intervention" },
149 { NS_CAUSE_EQUIP_FAIL, "Equipment failure" },
150 { NS_CAUSE_NSVC_BLOCKED, "NS-VC blocked" },
151 { NS_CAUSE_NSVC_UNKNOWN, "NS-VC unknown" },
152 { NS_CAUSE_BVCI_UNKNOWN, "BVCI unknown" },
153 { NS_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" },
154 { NS_CAUSE_PDU_INCOMP_PSTATE, "PDU not compatible with protocol state" },
Harald Welte69a4cf22010-05-03 20:55:10 +0200155 { NS_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" },
Harald Welte2577d412010-05-02 09:37:45 +0200156 { NS_CAUSE_INVAL_ESSENT_IE, "Invalid essential IE" },
157 { NS_CAUSE_MISSING_ESSENT_IE, "Missing essential IE" },
158 { 0, NULL }
Harald Welte9ba50052010-03-14 15:45:01 +0800159};
160
Harald Welte2577d412010-05-02 09:37:45 +0200161const char *gprs_ns_cause_str(enum ns_cause cause)
Harald Welte9ba50052010-03-14 15:45:01 +0800162{
Harald Welte2577d412010-05-02 09:37:45 +0200163 return get_value_string(ns_cause_str, cause);
Harald Welte9ba50052010-03-14 15:45:01 +0800164}
165
Harald Welte24a655f2010-04-30 19:54:29 +0200166static int nsip_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg);
Harald Weltef030b212010-04-26 19:18:54 +0200167
Harald Welte24a655f2010-04-30 19:54:29 +0200168static int gprs_ns_tx(struct gprs_nsvc *nsvc, struct msgb *msg)
Harald Welte9ba50052010-03-14 15:45:01 +0800169{
Harald Weltef030b212010-04-26 19:18:54 +0200170 int ret;
171
172 switch (nsvc->nsi->ll) {
173 case GPRS_NS_LL_UDP:
Harald Welte24a655f2010-04-30 19:54:29 +0200174 ret = nsip_sendmsg(nsvc, msg);
Harald Weltef030b212010-04-26 19:18:54 +0200175 break;
176 default:
Harald Welteb8a6a832010-05-11 05:54:22 +0200177 LOGP(DNS, LOGL_ERROR, "unsupported NS linklayer %u\n", nsvc->nsi->ll);
Harald Weltef030b212010-04-26 19:18:54 +0200178 msgb_free(msg);
179 ret = -EIO;
180 break;
181 }
182 return ret;
Harald Welte9ba50052010-03-14 15:45:01 +0800183}
184
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200185static int gprs_ns_tx_simple(struct gprs_nsvc *nsvc, uint8_t pdu_type)
Harald Welte9ba50052010-03-14 15:45:01 +0800186{
187 struct msgb *msg = msgb_alloc(NS_ALLOC_SIZE, "GPRS/NS");
188 struct gprs_ns_hdr *nsh;
189
190 if (!msg)
191 return -ENOMEM;
192
193 nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
194
195 nsh->pdu_type = pdu_type;
196
Harald Welte24a655f2010-04-30 19:54:29 +0200197 return gprs_ns_tx(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800198}
199
Harald Welte834f26d2010-05-11 06:20:54 +0200200int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause)
Harald Welte69a4cf22010-05-03 20:55:10 +0200201{
202 struct msgb *msg = msgb_alloc(NS_ALLOC_SIZE, "GPRS/NS");
203 struct gprs_ns_hdr *nsh;
Harald Welte69a4cf22010-05-03 20:55:10 +0200204 uint16_t nsvci = htons(nsvc->nsvci);
205 uint16_t nsei = htons(nsvc->nsei);
206
207 if (!msg)
208 return -ENOMEM;
209
210 nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
211 nsh->pdu_type = NS_PDUT_RESET;
212
213 msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause);
214 msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *) &nsvci);
215 msgb_tvlv_put(msg, NS_IE_NSEI, 2, (uint8_t *) &nsei);
216
217 return gprs_ns_tx(nsvc, msg);
218
219}
220
Harald Weltec1402a62010-05-12 11:48:44 +0200221int gprs_ns_tx_status(struct gprs_nsvc *nsvc, uint8_t cause,
222 uint16_t bvci, struct msgb *orig_msg)
223{
224 struct msgb *msg = msgb_alloc(NS_ALLOC_SIZE, "GPRS/NS");
225 struct gprs_ns_hdr *nsh;
226 uint16_t nsvci = htons(nsvc->nsvci);
227
228 bvci = htons(bvci);
229
230 if (!msg)
231 return -ENOMEM;
232
233 nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
234 nsh->pdu_type = NS_PDUT_STATUS;
235
236 msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause);
237
238 /* Section 9.2.7.1: Static conditions for NS-VCI */
239 if (cause == NS_CAUSE_NSVC_BLOCKED ||
240 cause == NS_CAUSE_NSVC_UNKNOWN)
241 msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *)&nsvci);
242
243 /* Section 9.2.7.2: Static conditions for NS PDU */
244 switch (cause) {
245 case NS_CAUSE_SEM_INCORR_PDU:
246 case NS_CAUSE_PDU_INCOMP_PSTATE:
247 case NS_CAUSE_PROTO_ERR_UNSPEC:
248 case NS_CAUSE_INVAL_ESSENT_IE:
249 case NS_CAUSE_MISSING_ESSENT_IE:
250 msgb_tvlv_put(msg, NS_IE_PDU, msgb_l2len(orig_msg),
251 orig_msg->l2h);
252 break;
253 default:
254 break;
255 }
256
257 /* Section 9.2.7.3: Static conditions for BVCI */
258 if (cause == NS_CAUSE_BVCI_UNKNOWN)
259 msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *)&bvci);
260
261 return gprs_ns_tx(nsvc, msg);
262}
263
Harald Welte834f26d2010-05-11 06:20:54 +0200264int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause)
265{
266 struct msgb *msg = msgb_alloc(NS_ALLOC_SIZE, "GPRS/NS");
267 struct gprs_ns_hdr *nsh;
268 uint16_t nsvci = htons(nsvc->nsvci);
269
270 if (!msg)
271 return -ENOMEM;
272
273 /* be conservative and mark it as blocked even now! */
274 nsvc->state |= NSE_S_BLOCKED;
275
276 nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
277 nsh->pdu_type = NS_PDUT_BLOCK;
278
279 msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause);
280 msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *) &nsvci);
281
282 return gprs_ns_tx(nsvc, msg);
283}
284
285int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc)
286{
287 return gprs_ns_tx_simple(nsvc, NS_PDUT_UNBLOCK);
288}
289
Harald Welte9ba50052010-03-14 15:45:01 +0800290#define NS_ALIVE_RETRIES 10 /* after 3 failed retransmit we declare BTS as dead */
291
Harald Welte69a4cf22010-05-03 20:55:10 +0200292static const uint8_t timer_mode_tout[_NSVC_TIMER_NR] = {
293 [NSVC_TIMER_TNS_RESET] = 60,
294 [NSVC_TIMER_TNS_ALIVE] = 3,
295 [NSVC_TIMER_TNS_TEST] = 30,
296};
297
298static void nsvc_start_timer(struct gprs_nsvc *nsvc, enum nsvc_timer_mode mode)
299{
300 nsvc->alive_retries = 0;
301
302 if (bsc_timer_pending(&nsvc->timer))
303 bsc_del_timer(&nsvc->timer);
304
305 nsvc->timer_mode = mode;
306 bsc_schedule_timer(&nsvc->timer, timer_mode_tout[mode], 0);
307}
308
Harald Welte80405452010-05-03 20:16:13 +0200309static void gprs_ns_timer_cb(void *data)
Harald Welte9ba50052010-03-14 15:45:01 +0800310{
311 struct gprs_nsvc *nsvc = data;
312
Harald Welte80405452010-05-03 20:16:13 +0200313 switch (nsvc->timer_mode) {
314 case NSVC_TIMER_TNS_ALIVE:
Harald Welte9ba50052010-03-14 15:45:01 +0800315 /* Tns-alive case: we expired without response ! */
316 nsvc->alive_retries++;
317 if (nsvc->alive_retries > NS_ALIVE_RETRIES) {
318 /* mark as dead and blocked */
319 nsvc->state = NSE_S_BLOCKED;
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200320 LOGP(DNS, LOGL_NOTICE,
321 "NSEI=%u Tns-alive expired more then "
Harald Welte69a4cf22010-05-03 20:55:10 +0200322 "%u times, blocking NS-VC\n", nsvc->nsei,
323 NS_ALIVE_RETRIES);
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200324 ns_dispatch_signal(nsvc, S_NS_BLOCK, NS_CAUSE_NSVC_BLOCKED);
Harald Welte9ba50052010-03-14 15:45:01 +0800325 return;
326 }
Harald Welte69a4cf22010-05-03 20:55:10 +0200327 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_ALIVE);
Harald Welte80405452010-05-03 20:16:13 +0200328 break;
329 case NSVC_TIMER_TNS_TEST:
Harald Welte9ba50052010-03-14 15:45:01 +0800330 /* Tns-test case: send NS-ALIVE PDU */
Harald Weltec5478482010-03-18 00:01:43 +0800331 gprs_ns_tx_simple(nsvc, NS_PDUT_ALIVE);
Harald Welte9ba50052010-03-14 15:45:01 +0800332 /* start Tns-alive timer */
Harald Welte69a4cf22010-05-03 20:55:10 +0200333 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_ALIVE);
334 break;
335 case NSVC_TIMER_TNS_RESET:
336 /* Chapter 7.3: Re-send the RESET */
Harald Welte570fb832010-05-03 21:05:24 +0200337 gprs_ns_tx_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
Harald Weltec1402a62010-05-12 11:48:44 +0200338 /* Re-start Tns-reset timer */
Harald Welte69a4cf22010-05-03 20:55:10 +0200339 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_RESET);
Harald Welte80405452010-05-03 20:16:13 +0200340 break;
Harald Welte2fc725d2010-05-11 10:15:26 +0200341 case _NSVC_TIMER_NR:
342 break;
Harald Welte9ba50052010-03-14 15:45:01 +0800343 }
Harald Welte9ba50052010-03-14 15:45:01 +0800344}
345
346/* Section 9.2.6 */
Harald Weltec5478482010-03-18 00:01:43 +0800347static int gprs_ns_tx_reset_ack(struct gprs_nsvc *nsvc)
Harald Welte9ba50052010-03-14 15:45:01 +0800348{
349 struct msgb *msg = msgb_alloc(NS_ALLOC_SIZE, "GPRS/NS");
350 struct gprs_ns_hdr *nsh;
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200351 uint16_t nsvci, nsei;
Harald Welte9ba50052010-03-14 15:45:01 +0800352
353 if (!msg)
354 return -ENOMEM;
355
Harald Weltec5478482010-03-18 00:01:43 +0800356 nsvci = htons(nsvc->nsvci);
357 nsei = htons(nsvc->nsei);
Harald Welte9ba50052010-03-14 15:45:01 +0800358
359 nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
360
361 nsh->pdu_type = NS_PDUT_RESET_ACK;
362
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200363 LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS RESET ACK (NSVCI=%u)\n",
Harald Weltebbc9fac2010-05-03 18:54:12 +0200364 nsvc->nsei, nsvc->nsvci);
Harald Weltec5478482010-03-18 00:01:43 +0800365
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200366 msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *)&nsvci);
367 msgb_tvlv_put(msg, NS_IE_NSEI, 2, (uint8_t *)&nsei);
Harald Welte9ba50052010-03-14 15:45:01 +0800368
Harald Welte24a655f2010-04-30 19:54:29 +0200369 return gprs_ns_tx(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800370}
371
Harald Welte24a655f2010-04-30 19:54:29 +0200372/* Section 9.2.10: transmit side / NS-UNITDATA-REQUEST primitive */
373int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg)
Harald Welte9ba50052010-03-14 15:45:01 +0800374{
Harald Welte24a655f2010-04-30 19:54:29 +0200375 struct gprs_nsvc *nsvc;
Harald Welte9ba50052010-03-14 15:45:01 +0800376 struct gprs_ns_hdr *nsh;
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200377 uint16_t bvci = msgb_bvci(msg);
Harald Welte24a655f2010-04-30 19:54:29 +0200378
379 nsvc = nsvc_by_nsei(nsi, msgb_nsei(msg));
380 if (!nsvc) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200381 LOGP(DNS, LOGL_ERROR, "Unable to resolve NSEI %u "
Harald Weltebbc9fac2010-05-03 18:54:12 +0200382 "to NS-VC!\n", msgb_nsei(msg));
Harald Welte24a655f2010-04-30 19:54:29 +0200383 return -EINVAL;
384 }
Harald Welte9ba50052010-03-14 15:45:01 +0800385
Harald Welte69a4cf22010-05-03 20:55:10 +0200386 if (!(nsvc->state & NSE_S_ALIVE)) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200387 LOGP(DNS, LOGL_ERROR, "NSEI=%u is not alive, cannot send\n",
Harald Welte69a4cf22010-05-03 20:55:10 +0200388 nsvc->nsei);
389 return -EBUSY;
390 }
391 if (nsvc->state & NSE_S_BLOCKED) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200392 LOGP(DNS, LOGL_ERROR, "NSEI=%u is blocked, cannot send\n",
Harald Welte69a4cf22010-05-03 20:55:10 +0200393 nsvc->nsei);
394 return -EBUSY;
395 }
396
Harald Welte9ba50052010-03-14 15:45:01 +0800397 nsh = (struct gprs_ns_hdr *) msgb_push(msg, sizeof(*nsh) + 3);
398 if (!nsh) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200399 LOGP(DNS, LOGL_ERROR, "Not enough headroom for NS header\n");
Harald Welte9ba50052010-03-14 15:45:01 +0800400 return -EIO;
401 }
402
403 nsh->pdu_type = NS_PDUT_UNITDATA;
404 /* spare octet in data[0] */
405 nsh->data[1] = bvci >> 8;
406 nsh->data[2] = bvci & 0xff;
407
Harald Welte24a655f2010-04-30 19:54:29 +0200408 return gprs_ns_tx(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800409}
410
411/* Section 9.2.10: receive side */
Harald Welte24a655f2010-04-30 19:54:29 +0200412static int gprs_ns_rx_unitdata(struct gprs_nsvc *nsvc, struct msgb *msg)
Harald Welte9ba50052010-03-14 15:45:01 +0800413{
414 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *)msg->l2h;
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200415 uint16_t bvci;
Harald Welte9ba50052010-03-14 15:45:01 +0800416
Harald Weltec1402a62010-05-12 11:48:44 +0200417 if (nsvc->state & NSE_S_BLOCKED)
418 return gprs_ns_tx_status(nsvc, NS_CAUSE_NSVC_BLOCKED,
419 0, msg);
420
Harald Welte9ba50052010-03-14 15:45:01 +0800421 /* spare octet in data[0] */
422 bvci = nsh->data[1] << 8 | nsh->data[2];
Harald Welteec19c102010-05-02 09:50:42 +0200423 msgb_bssgph(msg) = &nsh->data[3];
Harald Welte30bc19a2010-05-02 11:19:37 +0200424 msgb_bvci(msg) = bvci;
Harald Welte9ba50052010-03-14 15:45:01 +0800425
426 /* call upper layer (BSSGP) */
Harald Weltef030b212010-04-26 19:18:54 +0200427 return nsvc->nsi->cb(GPRS_NS_EVT_UNIT_DATA, nsvc, msg, bvci);
Harald Welte9ba50052010-03-14 15:45:01 +0800428}
429
430/* Section 9.2.7 */
Harald Welte24a655f2010-04-30 19:54:29 +0200431static int gprs_ns_rx_status(struct gprs_nsvc *nsvc, struct msgb *msg)
Harald Welte9ba50052010-03-14 15:45:01 +0800432{
Harald Weltef030b212010-04-26 19:18:54 +0200433 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
Harald Welte9ba50052010-03-14 15:45:01 +0800434 struct tlv_parsed tp;
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200435 uint8_t cause;
Harald Welte9ba50052010-03-14 15:45:01 +0800436 int rc;
437
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200438 LOGP(DNS, LOGL_INFO, "NSEI=%u NS STATUS ", nsvc->nsei);
Harald Welte9ba50052010-03-14 15:45:01 +0800439
440 rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, msgb_l2len(msg), 0, 0);
441
442 if (!TLVP_PRESENT(&tp, NS_IE_CAUSE)) {
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200443 LOGPC(DNS, LOGL_INFO, "missing cause IE\n");
Harald Welte9ba50052010-03-14 15:45:01 +0800444 return -EINVAL;
445 }
446
447 cause = *TLVP_VAL(&tp, NS_IE_CAUSE);
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200448 LOGPC(DNS, LOGL_INFO, "cause=%s\n", gprs_ns_cause_str(cause));
Harald Welte9ba50052010-03-14 15:45:01 +0800449
450 return 0;
451}
452
453/* Section 7.3 */
Harald Welte24a655f2010-04-30 19:54:29 +0200454static int gprs_ns_rx_reset(struct gprs_nsvc *nsvc, struct msgb *msg)
Harald Welte9ba50052010-03-14 15:45:01 +0800455{
456 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
Harald Welte9ba50052010-03-14 15:45:01 +0800457 struct tlv_parsed tp;
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200458 uint8_t *cause;
459 uint16_t *nsvci, *nsei;
Harald Welte9ba50052010-03-14 15:45:01 +0800460 int rc;
461
Harald Welte9ba50052010-03-14 15:45:01 +0800462 rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, msgb_l2len(msg), 0, 0);
463
464 if (!TLVP_PRESENT(&tp, NS_IE_CAUSE) ||
465 !TLVP_PRESENT(&tp, NS_IE_VCI) ||
466 !TLVP_PRESENT(&tp, NS_IE_NSEI)) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200467 LOGP(DNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n");
Harald Weltec1402a62010-05-12 11:48:44 +0200468 gprs_ns_tx_status(nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800469 return -EINVAL;
470 }
471
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200472 cause = (uint8_t *) TLVP_VAL(&tp, NS_IE_CAUSE);
473 nsvci = (uint16_t *) TLVP_VAL(&tp, NS_IE_VCI);
474 nsei = (uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI);
Harald Welte9ba50052010-03-14 15:45:01 +0800475
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200476 LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS RESET (NSVCI=%u, cause=%s)\n",
Harald Weltebbc9fac2010-05-03 18:54:12 +0200477 nsvc->nsvci, nsvc->nsei, gprs_ns_cause_str(*cause));
478
Harald Weltec1402a62010-05-12 11:48:44 +0200479 /* Mark NS-VC as blocked and alive */
Harald Weltec5478482010-03-18 00:01:43 +0800480 nsvc->state = NSE_S_BLOCKED | NSE_S_ALIVE;
Harald Weltee8b9ca22010-05-11 18:18:31 +0200481
Harald Weltec5478482010-03-18 00:01:43 +0800482 nsvc->nsei = ntohs(*nsei);
483 nsvc->nsvci = ntohs(*nsvci);
Harald Welte9ba50052010-03-14 15:45:01 +0800484
Harald Welte9ba50052010-03-14 15:45:01 +0800485 /* start the test procedure */
Harald Welte69a4cf22010-05-03 20:55:10 +0200486 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_ALIVE);
Harald Welte9ba50052010-03-14 15:45:01 +0800487
Harald Welte834f26d2010-05-11 06:20:54 +0200488 /* inform interested parties about the fact that this NSVC
489 * has received RESET */
Harald Welte2fc725d2010-05-11 10:15:26 +0200490 ns_dispatch_signal(nsvc, S_NS_RESET, *cause);
Harald Welte834f26d2010-05-11 06:20:54 +0200491
Harald Weltec5478482010-03-18 00:01:43 +0800492 return gprs_ns_tx_reset_ack(nsvc);
Harald Welte9ba50052010-03-14 15:45:01 +0800493}
494
Harald Welte834f26d2010-05-11 06:20:54 +0200495static int gprs_ns_rx_block(struct gprs_nsvc *nsvc, struct msgb *msg)
496{
497 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
498 struct tlv_parsed tp;
499 uint8_t *cause;
500 int rc;
501
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200502 LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS BLOCK\n", nsvc->nsei);
Harald Welte834f26d2010-05-11 06:20:54 +0200503
504 nsvc->state |= NSE_S_BLOCKED;
505
506 rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, msgb_l2len(msg), 0, 0);
507
508 if (!TLVP_PRESENT(&tp, NS_IE_CAUSE) ||
509 !TLVP_PRESENT(&tp, NS_IE_VCI)) {
Harald Welte834f26d2010-05-11 06:20:54 +0200510 LOGP(DNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n");
Harald Weltec1402a62010-05-12 11:48:44 +0200511 gprs_ns_tx_status(nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0, msg);
Harald Welte834f26d2010-05-11 06:20:54 +0200512 return -EINVAL;
513 }
514
515 cause = (uint8_t *) TLVP_VAL(&tp, NS_IE_CAUSE);
516 //nsvci = (uint16_t *) TLVP_VAL(&tp, NS_IE_VCI);
517
Harald Welte2fc725d2010-05-11 10:15:26 +0200518 ns_dispatch_signal(nsvc, S_NS_BLOCK, *cause);
Harald Welte834f26d2010-05-11 06:20:54 +0200519
520 return gprs_ns_tx_simple(nsvc, NS_PDUT_BLOCK_ACK);
521}
522
Harald Welte9ba50052010-03-14 15:45:01 +0800523/* main entry point, here incoming NS frames enter */
Harald Weltef030b212010-04-26 19:18:54 +0200524int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
525 struct sockaddr_in *saddr)
Harald Welte9ba50052010-03-14 15:45:01 +0800526{
527 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
Harald Weltef030b212010-04-26 19:18:54 +0200528 struct gprs_nsvc *nsvc;
Harald Welte9ba50052010-03-14 15:45:01 +0800529 int rc = 0;
530
Harald Weltef030b212010-04-26 19:18:54 +0200531 /* look up the NSVC based on source address */
532 nsvc = nsvc_by_rem_addr(nsi, saddr);
533 if (!nsvc) {
Harald Welte9a392932010-05-11 18:30:37 +0200534 struct tlv_parsed tp;
535 uint16_t nsei;
Harald Weltef030b212010-04-26 19:18:54 +0200536 /* Only the RESET procedure creates a new NSVC */
Harald Weltebbc9fac2010-05-03 18:54:12 +0200537 if (nsh->pdu_type != NS_PDUT_RESET) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200538 LOGP(DNS, LOGL_INFO, "Ignoring NS PDU type 0x%0x "
Harald Weltebba902d2010-05-11 18:38:36 +0200539 "from %s:%u for non-existing NS-VC\n",
540 nsh->pdu_type, inet_ntoa(saddr->sin_addr),
541 ntohs(saddr->sin_port));
Harald Weltec1402a62010-05-12 11:48:44 +0200542 /* FIXME: send STATUS (but we have no NSVC!) */
Harald Welte570fb832010-05-03 21:05:24 +0200543 //gprs_ns_tx_reset(nsvc, NS_CAUSE_NSVC_UNKNOWN);
Harald Weltef030b212010-04-26 19:18:54 +0200544 return -EIO;
Harald Weltebbc9fac2010-05-03 18:54:12 +0200545 }
Harald Welte9a392932010-05-11 18:30:37 +0200546 rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data,
547 msgb_l2len(msg), 0, 0);
548 if (!TLVP_PRESENT(&tp, NS_IE_CAUSE) ||
549 !TLVP_PRESENT(&tp, NS_IE_VCI) ||
550 !TLVP_PRESENT(&tp, NS_IE_NSEI)) {
Harald Welte9a392932010-05-11 18:30:37 +0200551 LOGP(DNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n");
Harald Weltec1402a62010-05-12 11:48:44 +0200552 gprs_ns_tx_status(nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0,
553 msg);
Harald Welte9a392932010-05-11 18:30:37 +0200554 return -EINVAL;
555 }
556 nsei = ntohs(*(uint16_t *)TLVP_VAL(&tp, NS_IE_NSEI));
557 /* Check if we already know this NSEI, the remote end might
558 * simply have changed addresses, or it is a SGSN */
559 nsvc = nsvc_by_nsei(nsi, nsei);
560 if (!nsvc) {
561 LOGP(DNS, LOGL_INFO, "Creating NS-VC for BSS at %s:%u\n",
562 inet_ntoa(saddr->sin_addr), ntohs(saddr->sin_port));
563 nsvc = nsvc_create(nsi, 0xffff);
Harald Welte9a392932010-05-11 18:30:37 +0200564 }
Harald Welte2b7d4652010-05-11 18:40:45 +0200565 /* Update the remote peer IP address/port */
566 nsvc->ip.bts_addr = *saddr;
Harald Weltebbc9fac2010-05-03 18:54:12 +0200567 } else
568 msgb_nsei(msg) = nsvc->nsei;
Harald Weltec5478482010-03-18 00:01:43 +0800569
Harald Welte9ba50052010-03-14 15:45:01 +0800570 switch (nsh->pdu_type) {
571 case NS_PDUT_ALIVE:
572 /* remote end inquires whether we're still alive,
573 * we need to respond with ALIVE_ACK */
Harald Weltec5478482010-03-18 00:01:43 +0800574 rc = gprs_ns_tx_simple(nsvc, NS_PDUT_ALIVE_ACK);
Harald Welte9ba50052010-03-14 15:45:01 +0800575 break;
576 case NS_PDUT_ALIVE_ACK:
577 /* stop Tns-alive */
Harald Welte80405452010-05-03 20:16:13 +0200578 bsc_del_timer(&nsvc->timer);
Harald Welte9ba50052010-03-14 15:45:01 +0800579 /* start Tns-test */
Harald Welte69a4cf22010-05-03 20:55:10 +0200580 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_TEST);
Harald Welte7fb7e612010-05-03 21:11:22 +0200581 if (nsvc->remote_end_is_sgsn) {
582 /* FIXME: this should be one level higher */
583 if (nsvc->state & NSE_S_BLOCKED)
Harald Weltec1402a62010-05-12 11:48:44 +0200584 rc = gprs_ns_tx_unblock(nsvc);
Harald Welte7fb7e612010-05-03 21:11:22 +0200585 }
Harald Welte9ba50052010-03-14 15:45:01 +0800586 break;
587 case NS_PDUT_UNITDATA:
588 /* actual user data */
Harald Welte24a655f2010-04-30 19:54:29 +0200589 rc = gprs_ns_rx_unitdata(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800590 break;
591 case NS_PDUT_STATUS:
Harald Welte24a655f2010-04-30 19:54:29 +0200592 rc = gprs_ns_rx_status(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800593 break;
594 case NS_PDUT_RESET:
Harald Welte24a655f2010-04-30 19:54:29 +0200595 rc = gprs_ns_rx_reset(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800596 break;
597 case NS_PDUT_RESET_ACK:
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200598 LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS RESET ACK\n", nsvc->nsei);
Harald Weltec1402a62010-05-12 11:48:44 +0200599 /* mark NS-VC as blocked + active */
600 nsvc->state = NSE_S_BLOCKED | NSE_S_ALIVE;
Harald Weltef030b212010-04-26 19:18:54 +0200601 nsvc->remote_state = NSE_S_BLOCKED | NSE_S_ALIVE;
Harald Welte69a4cf22010-05-03 20:55:10 +0200602 if (nsvc->remote_end_is_sgsn) {
603 /* stop RESET timer */
604 bsc_del_timer(&nsvc->timer);
Harald Weltec1402a62010-05-12 11:48:44 +0200605 /* Initiate TEST proc.: Send ALIVE and start timer */
Harald Welte570fb832010-05-03 21:05:24 +0200606 rc = gprs_ns_tx_simple(nsvc, NS_PDUT_ALIVE);
607 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_ALIVE);
Harald Welte69a4cf22010-05-03 20:55:10 +0200608 }
Harald Welte9ba50052010-03-14 15:45:01 +0800609 break;
610 case NS_PDUT_UNBLOCK:
611 /* Section 7.2: unblocking procedure */
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200612 LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS UNBLOCK\n", nsvc->nsei);
Harald Welte9ba50052010-03-14 15:45:01 +0800613 nsvc->state &= ~NSE_S_BLOCKED;
Harald Welte834f26d2010-05-11 06:20:54 +0200614 ns_dispatch_signal(nsvc, S_NS_UNBLOCK, 0);
Harald Weltec5478482010-03-18 00:01:43 +0800615 rc = gprs_ns_tx_simple(nsvc, NS_PDUT_UNBLOCK_ACK);
Harald Welte9ba50052010-03-14 15:45:01 +0800616 break;
617 case NS_PDUT_UNBLOCK_ACK:
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200618 LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS UNBLOCK ACK\n", nsvc->nsei);
Harald Weltec1402a62010-05-12 11:48:44 +0200619 /* mark NS-VC as unblocked + active */
620 nsvc->state = NSE_S_ALIVE;
Harald Weltef030b212010-04-26 19:18:54 +0200621 nsvc->remote_state = NSE_S_ALIVE;
Harald Welte9ba50052010-03-14 15:45:01 +0800622 break;
623 case NS_PDUT_BLOCK:
Harald Welte834f26d2010-05-11 06:20:54 +0200624 rc = gprs_ns_rx_block(nsvc, msg);
Harald Welte9ba50052010-03-14 15:45:01 +0800625 break;
626 case NS_PDUT_BLOCK_ACK:
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200627 LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS BLOCK ACK\n", nsvc->nsei);
Harald Weltef030b212010-04-26 19:18:54 +0200628 /* mark remote NS-VC as blocked + active */
629 nsvc->remote_state = NSE_S_BLOCKED | NSE_S_ALIVE;
Harald Welte9ba50052010-03-14 15:45:01 +0800630 break;
631 default:
Harald Weltee4ecc8c2010-05-12 00:16:57 +0200632 LOGP(DNS, LOGL_NOTICE, "NSEI=%u Rx Unknown NS PDU type 0x%02x\n",
Harald Weltebbc9fac2010-05-03 18:54:12 +0200633 nsvc->nsei, nsh->pdu_type);
Harald Welte9ba50052010-03-14 15:45:01 +0800634 rc = -EINVAL;
635 break;
636 }
637 return rc;
638}
639
Harald Weltef030b212010-04-26 19:18:54 +0200640struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb)
641{
642 struct gprs_ns_inst *nsi = talloc_zero(tall_bsc_ctx, struct gprs_ns_inst);
643
644 nsi->cb = cb;
645 INIT_LLIST_HEAD(&nsi->gprs_nsvcs);
646
Harald Welte3771d092010-04-30 20:26:32 +0200647 return nsi;
Harald Weltef030b212010-04-26 19:18:54 +0200648}
649
650void gprs_ns_destroy(struct gprs_ns_inst *nsi)
651{
652 /* FIXME: clear all timers */
653
654 /* recursively free the NSI and all its NSVCs */
655 talloc_free(nsi);
656}
657
658
659/* NS-over-IP code, according to 3GPP TS 48.016 Chapter 6.2
660 * We don't support Size Procedure, Configuration Procedure, ChangeWeight Procedure */
661
662/* Read a single NS-over-IP message */
663static struct msgb *read_nsip_msg(struct bsc_fd *bfd, int *error,
664 struct sockaddr_in *saddr)
665{
666 struct msgb *msg = msgb_alloc(NS_ALLOC_SIZE, "Abis/IP/GPRS-NS");
667 int ret = 0;
668 socklen_t saddr_len = sizeof(*saddr);
669
670 if (!msg) {
671 *error = -ENOMEM;
672 return NULL;
673 }
674
675 ret = recvfrom(bfd->fd, msg->data, NS_ALLOC_SIZE, 0,
676 (struct sockaddr *)saddr, &saddr_len);
677 if (ret < 0) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200678 LOGP(DNS, LOGL_ERROR, "recv error %s during NSIP recv\n",
Harald Weltebbc9fac2010-05-03 18:54:12 +0200679 strerror(errno));
Harald Weltef030b212010-04-26 19:18:54 +0200680 msgb_free(msg);
681 *error = ret;
682 return NULL;
683 } else if (ret == 0) {
684 msgb_free(msg);
685 *error = ret;
686 return NULL;
687 }
688
689 msg->l2h = msg->data;
690 msgb_put(msg, ret);
691
692 return msg;
693}
694
695static int handle_nsip_read(struct bsc_fd *bfd)
696{
697 int error;
698 struct sockaddr_in saddr;
699 struct gprs_ns_inst *nsi = bfd->data;
700 struct msgb *msg = read_nsip_msg(bfd, &error, &saddr);
701
702 if (!msg)
703 return error;
704
705 return gprs_ns_rcvmsg(nsi, msg, &saddr);
706}
707
708static int handle_nsip_write(struct bsc_fd *bfd)
709{
710 /* FIXME: actually send the data here instead of nsip_sendmsg() */
711 return -EIO;
712}
713
Harald Welte24a655f2010-04-30 19:54:29 +0200714int nsip_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg)
Harald Weltef030b212010-04-26 19:18:54 +0200715{
716 int rc;
717 struct gprs_ns_inst *nsi = nsvc->nsi;
718 struct sockaddr_in *daddr = &nsvc->ip.bts_addr;
719
720 rc = sendto(nsi->nsip.fd.fd, msg->data, msg->len, 0,
721 (struct sockaddr *)daddr, sizeof(*daddr));
722
723 talloc_free(msg);
724
725 return rc;
726}
727
728/* UDP Port 23000 carries the LLC-in-BSSGP-in-NS protocol stack */
729static int nsip_fd_cb(struct bsc_fd *bfd, unsigned int what)
730{
731 int rc = 0;
732
733 if (what & BSC_FD_READ)
734 rc = handle_nsip_read(bfd);
735 if (what & BSC_FD_WRITE)
736 rc = handle_nsip_write(bfd);
737
738 return rc;
739}
740
741
742/* FIXME: this is currently in input/ipaccess.c */
Harald Welte8f9a3ee2010-05-02 11:26:34 +0200743extern int make_sock(struct bsc_fd *bfd, int proto, uint16_t port,
Harald Weltef030b212010-04-26 19:18:54 +0200744 int (*cb)(struct bsc_fd *fd, unsigned int what));
745
746/* Listen for incoming GPRS packets */
747int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port)
748{
749 int ret;
750
751 ret = make_sock(&nsi->nsip.fd, IPPROTO_UDP, udp_port, nsip_fd_cb);
752 if (ret < 0)
753 return ret;
754
755 nsi->ll = GPRS_NS_LL_UDP;
756 nsi->nsip.fd.data = nsi;
757
758 return ret;
759}
Harald Welte3771d092010-04-30 20:26:32 +0200760
761/* Establish a connection (from the BSS) to the SGSN */
762struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,
Harald Welte1203de32010-05-01 11:28:43 +0200763 struct sockaddr_in *dest, uint16_t nsei,
764 uint16_t nsvci)
Harald Welte3771d092010-04-30 20:26:32 +0200765{
766 struct gprs_nsvc *nsvc;
767
768 nsvc = nsvc_by_rem_addr(nsi, dest);
Harald Welte38407ef2010-05-12 11:56:39 +0000769 if (!nsvc)
Harald Welte3771d092010-04-30 20:26:32 +0200770 nsvc = nsvc_create(nsi, nsvci);
Harald Welte38407ef2010-05-12 11:56:39 +0000771 nsvc->ip.bts_addr = *dest;
Harald Welte1203de32010-05-01 11:28:43 +0200772 nsvc->nsei = nsei;
773 nsvc->nsvci = nsvci;
Harald Welte3771d092010-04-30 20:26:32 +0200774 nsvc->remote_end_is_sgsn = 1;
775
776 /* Initiate a RESET procedure */
Harald Weltec1402a62010-05-12 11:48:44 +0200777 /* Mark NS-VC locally as blocked and dead */
778 nsvc->state = NSE_S_BLOCKED;
779 /* Send NS-RESET PDU */
Harald Welte570fb832010-05-03 21:05:24 +0200780 if (gprs_ns_tx_reset(nsvc, NS_CAUSE_OM_INTERVENTION) < 0) {
Harald Welteb8a6a832010-05-11 05:54:22 +0200781 LOGP(DNS, LOGL_ERROR, "NSEI=%u, error resetting NS-VC\n",
Harald Welte69a4cf22010-05-03 20:55:10 +0200782 nsei);
783 }
Harald Weltec1402a62010-05-12 11:48:44 +0200784 /* Start Tns-reset */
Harald Welte69a4cf22010-05-03 20:55:10 +0200785 nsvc_start_timer(nsvc, NSVC_TIMER_TNS_RESET);
Harald Welte3771d092010-04-30 20:26:32 +0200786
787 return nsvc;
788}