blob: f8e3b5699a240aa62aa77c17c386ac62340bf882 [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
Harald Weltee4cbb3f2011-01-01 15:25:50 +01008 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
Harald Welteaf086782010-05-11 10:01:17 +020010 * (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
Harald Weltee4cbb3f2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welteaf086782010-05-11 10:01:17 +020016 *
Harald Weltee4cbb3f2011-01-01 15:25:50 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welteaf086782010-05-11 10:01:17 +020019 *
20 */
21
22#include <errno.h>
23#include <stdint.h>
24
25#include <netinet/in.h>
26
27#include <osmocore/msgb.h>
28#include <osmocore/tlv.h>
29#include <osmocore/talloc.h>
30
31#include <openbsc/debug.h>
32#include <openbsc/gsm_data.h>
33#include <openbsc/gprs_bssgp.h>
34#include <openbsc/gprs_ns.h>
35
36struct gprs_ns_inst *bssgp_nsi;
37
38/* BSSGP Protocol specific, not implementation specific */
39/* FIXME: This needs to go into libosmocore after finished */
40
41/* Chapter 11.3.9 / Table 11.10: Cause coding */
42static const struct value_string bssgp_cause_strings[] = {
43 { BSSGP_CAUSE_PROC_OVERLOAD, "Processor overload" },
44 { BSSGP_CAUSE_EQUIP_FAIL, "Equipment Failure" },
45 { BSSGP_CAUSE_TRASIT_NET_FAIL, "Transit netowkr service failure" },
46 { BSSGP_CAUSE_CAPA_GREATER_0KPBS,"Transmission capacity modified" },
47 { BSSGP_CAUSE_UNKNOWN_MS, "Unknown MS" },
48 { BSSGP_CAUSE_UNKNOWN_BVCI, "Unknown BVCI" },
49 { BSSGP_CAUSE_CELL_TRAF_CONG, "Cell traffic congestion" },
50 { BSSGP_CAUSE_SGSN_CONG, "SGSN congestion" },
51 { BSSGP_CAUSE_OML_INTERV, "O&M intervention" },
52 { BSSGP_CAUSE_BVCI_BLOCKED, "BVCI blocked" },
53 { BSSGP_CAUSE_PFC_CREATE_FAIL, "PFC create failure" },
54 { BSSGP_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" },
55 { BSSGP_CAUSE_INV_MAND_INF, "Invalid mandatory information" },
56 { BSSGP_CAUSE_MISSING_MAND_IE, "Missing mandatory IE" },
57 { BSSGP_CAUSE_MISSING_COND_IE, "Missing conditional IE" },
58 { BSSGP_CAUSE_UNEXP_COND_IE, "Unexpected conditional IE" },
59 { BSSGP_CAUSE_COND_IE_ERR, "Conditional IE error" },
60 { BSSGP_CAUSE_PDU_INCOMP_STATE, "PDU incompatible with protocol state" },
61 { BSSGP_CAUSE_PROTO_ERR_UNSPEC, "Protocol error - unspecified" },
62 { BSSGP_CAUSE_PDU_INCOMP_FEAT, "PDU not compatible with feature set" },
63 { 0, NULL },
64};
65
66const char *bssgp_cause_str(enum gprs_bssgp_cause cause)
67{
68 return get_value_string(bssgp_cause_strings, cause);
69}
70
71
72struct msgb *bssgp_msgb_alloc(void)
73{
74 return msgb_alloc_headroom(4096, 128, "BSSGP");
75}
76
77/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
78int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
79 uint16_t bvci, uint16_t ns_bvci)
80{
81 struct msgb *msg = bssgp_msgb_alloc();
82 struct bssgp_normal_hdr *bgph =
83 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
84 uint16_t _bvci;
85
86 msgb_nsei(msg) = nsei;
87 msgb_bvci(msg) = ns_bvci;
88
89 bgph->pdu_type = pdu_type;
90 _bvci = htons(bvci);
91 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
92
93 return gprs_ns_sendmsg(bssgp_nsi, msg);
94}
95
96/* Chapter 10.4.14: Status */
97int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
98{
99 struct msgb *msg = bssgp_msgb_alloc();
100 struct bssgp_normal_hdr *bgph =
101 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
102
Holger Hans Peter Freyther8e2e78e2010-06-08 16:05:20 +0800103 LOGP(DBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Tx STATUS, cause=%s\n",
Harald Weltecfb545a2010-06-03 21:30:57 +0200104 bvci ? *bvci : 0, bssgp_cause_str(cause));
Harald Welteaf086782010-05-11 10:01:17 +0200105 msgb_nsei(msg) = msgb_nsei(orig_msg);
106 msgb_bvci(msg) = 0;
107
108 bgph->pdu_type = BSSGP_PDUT_STATUS;
109 msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
110 if (bvci) {
111 uint16_t _bvci = htons(*bvci);
112 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
113 }
114 if (orig_msg)
115 msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR,
116 msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));
117
118 return gprs_ns_sendmsg(bssgp_nsi, msg);
119}