blob: 566ac4cf7f661a48c5ac8ea21804714daf3897b9 [file] [log] [blame]
Harald Welteaf086782010-05-11 10:01:17 +02001/* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */
2
3/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <errno.h>
24#include <stdint.h>
25
26#include <netinet/in.h>
27
28#include <osmocore/msgb.h>
29#include <osmocore/tlv.h>
30#include <osmocore/talloc.h>
31
32#include <openbsc/debug.h>
33#include <openbsc/gsm_data.h>
34#include <openbsc/gprs_bssgp.h>
35#include <openbsc/gprs_ns.h>
36
37struct gprs_ns_inst *bssgp_nsi;
38
39/* BSSGP Protocol specific, not implementation specific */
40/* FIXME: This needs to go into libosmocore after finished */
41
42/* Chapter 11.3.9 / Table 11.10: Cause coding */
43static const struct value_string bssgp_cause_strings[] = {
44 { BSSGP_CAUSE_PROC_OVERLOAD, "Processor overload" },
45 { BSSGP_CAUSE_EQUIP_FAIL, "Equipment Failure" },
46 { BSSGP_CAUSE_TRASIT_NET_FAIL, "Transit netowkr service failure" },
47 { BSSGP_CAUSE_CAPA_GREATER_0KPBS,"Transmission capacity modified" },
48 { BSSGP_CAUSE_UNKNOWN_MS, "Unknown MS" },
49 { BSSGP_CAUSE_UNKNOWN_BVCI, "Unknown BVCI" },
50 { BSSGP_CAUSE_CELL_TRAF_CONG, "Cell traffic congestion" },
51 { BSSGP_CAUSE_SGSN_CONG, "SGSN congestion" },
52 { BSSGP_CAUSE_OML_INTERV, "O&M intervention" },
53 { BSSGP_CAUSE_BVCI_BLOCKED, "BVCI blocked" },
54 { BSSGP_CAUSE_PFC_CREATE_FAIL, "PFC create failure" },
55 { BSSGP_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" },
56 { BSSGP_CAUSE_INV_MAND_INF, "Invalid mandatory information" },
57 { BSSGP_CAUSE_MISSING_MAND_IE, "Missing mandatory IE" },
58 { BSSGP_CAUSE_MISSING_COND_IE, "Missing conditional IE" },
59 { BSSGP_CAUSE_UNEXP_COND_IE, "Unexpected conditional IE" },
60 { BSSGP_CAUSE_COND_IE_ERR, "Conditional IE error" },
61 { BSSGP_CAUSE_PDU_INCOMP_STATE, "PDU incompatible with protocol state" },
62 { BSSGP_CAUSE_PROTO_ERR_UNSPEC, "Protocol error - unspecified" },
63 { BSSGP_CAUSE_PDU_INCOMP_FEAT, "PDU not compatible with feature set" },
64 { 0, NULL },
65};
66
67const char *bssgp_cause_str(enum gprs_bssgp_cause cause)
68{
69 return get_value_string(bssgp_cause_strings, cause);
70}
71
72
73struct msgb *bssgp_msgb_alloc(void)
74{
75 return msgb_alloc_headroom(4096, 128, "BSSGP");
76}
77
78/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
79int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
80 uint16_t bvci, uint16_t ns_bvci)
81{
82 struct msgb *msg = bssgp_msgb_alloc();
83 struct bssgp_normal_hdr *bgph =
84 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
85 uint16_t _bvci;
86
87 msgb_nsei(msg) = nsei;
88 msgb_bvci(msg) = ns_bvci;
89
90 bgph->pdu_type = pdu_type;
91 _bvci = htons(bvci);
92 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
93
94 return gprs_ns_sendmsg(bssgp_nsi, msg);
95}
96
97/* Chapter 10.4.14: Status */
98int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
99{
100 struct msgb *msg = bssgp_msgb_alloc();
101 struct bssgp_normal_hdr *bgph =
102 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
103
Harald Weltecfb545a2010-06-03 21:30:57 +0200104 DEBUGP(DBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Tx STATUS, cause=%s\n",
105 bvci ? *bvci : 0, bssgp_cause_str(cause));
Harald Welteaf086782010-05-11 10:01:17 +0200106 msgb_nsei(msg) = msgb_nsei(orig_msg);
107 msgb_bvci(msg) = 0;
108
109 bgph->pdu_type = BSSGP_PDUT_STATUS;
110 msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
111 if (bvci) {
112 uint16_t _bvci = htons(*bvci);
113 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
114 }
115 if (orig_msg)
116 msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR,
117 msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));
118
119 return gprs_ns_sendmsg(bssgp_nsi, msg);
120}