blob: 19ae23a06cceaf64fee5af7907a229889659cff1 [file] [log] [blame]
Harald Welteaf086782010-05-11 10:01:17 +02001/* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */
2
Harald Welte605ac5d2012-06-16 16:09:52 +08003/* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org>
Harald Welteaf086782010-05-11 10:01:17 +02004 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte7fa89c22014-10-26 20:33:09 +01008 * 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
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 Welte7fa89c22014-10-26 20:33:09 +010015 * GNU General Public License for more details.
Harald Welteaf086782010-05-11 10:01:17 +020016 *
Harald Welte7fa89c22014-10-26 20:33:09 +010017 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010018 * 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
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010027#include <osmocom/core/msgb.h>
28#include <osmocom/gsm/tlv.h>
29#include <osmocom/core/talloc.h>
Harald Welte73952e32012-06-16 14:59:56 +080030#include <osmocom/gprs/gprs_bssgp.h>
31#include <osmocom/gprs/gprs_ns.h>
Harald Welteaf086782010-05-11 10:01:17 +020032
Harald Weltecca49632012-06-16 17:45:59 +080033#include "common_vty.h"
Harald Welteaf086782010-05-11 10:01:17 +020034
35struct gprs_ns_inst *bssgp_nsi;
36
37/* BSSGP Protocol specific, not implementation specific */
38/* FIXME: This needs to go into libosmocore after finished */
39
40/* Chapter 11.3.9 / Table 11.10: Cause coding */
41static const struct value_string bssgp_cause_strings[] = {
42 { BSSGP_CAUSE_PROC_OVERLOAD, "Processor overload" },
43 { BSSGP_CAUSE_EQUIP_FAIL, "Equipment Failure" },
44 { BSSGP_CAUSE_TRASIT_NET_FAIL, "Transit netowkr service failure" },
45 { BSSGP_CAUSE_CAPA_GREATER_0KPBS,"Transmission capacity modified" },
46 { BSSGP_CAUSE_UNKNOWN_MS, "Unknown MS" },
47 { BSSGP_CAUSE_UNKNOWN_BVCI, "Unknown BVCI" },
48 { BSSGP_CAUSE_CELL_TRAF_CONG, "Cell traffic congestion" },
49 { BSSGP_CAUSE_SGSN_CONG, "SGSN congestion" },
50 { BSSGP_CAUSE_OML_INTERV, "O&M intervention" },
51 { BSSGP_CAUSE_BVCI_BLOCKED, "BVCI blocked" },
52 { BSSGP_CAUSE_PFC_CREATE_FAIL, "PFC create failure" },
53 { BSSGP_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" },
54 { BSSGP_CAUSE_INV_MAND_INF, "Invalid mandatory information" },
55 { BSSGP_CAUSE_MISSING_MAND_IE, "Missing mandatory IE" },
56 { BSSGP_CAUSE_MISSING_COND_IE, "Missing conditional IE" },
57 { BSSGP_CAUSE_UNEXP_COND_IE, "Unexpected conditional IE" },
58 { BSSGP_CAUSE_COND_IE_ERR, "Conditional IE error" },
59 { BSSGP_CAUSE_PDU_INCOMP_STATE, "PDU incompatible with protocol state" },
60 { BSSGP_CAUSE_PROTO_ERR_UNSPEC, "Protocol error - unspecified" },
61 { BSSGP_CAUSE_PDU_INCOMP_FEAT, "PDU not compatible with feature set" },
62 { 0, NULL },
63};
64
65const char *bssgp_cause_str(enum gprs_bssgp_cause cause)
66{
67 return get_value_string(bssgp_cause_strings, cause);
68}
69
70
71struct msgb *bssgp_msgb_alloc(void)
72{
Jacob Erlbecka39e2de2014-09-23 13:28:24 +020073 struct msgb *msg = msgb_alloc_headroom(4096, 128, "BSSGP");
Jacob Erlbecka84db612015-04-09 14:22:22 +020074
75 /* TODO: Add handling of msg == NULL to this function and to all callers */
76 OSMO_ASSERT(msg != NULL);
77
Jacob Erlbecka39e2de2014-09-23 13:28:24 +020078 msgb_bssgph(msg) = msg->data;
79 return msg;
Harald Welteaf086782010-05-11 10:01:17 +020080}
81
Jacob Erlbeckf78ec5c2015-11-17 09:53:23 +010082struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name)
83{
84 struct libgb_msgb_cb *old_cb, *new_cb;
85 struct msgb *new_msg;
86
87 new_msg = msgb_copy(msg, name);
88 if (!new_msg)
89 return NULL;
90
91 /* copy GB specific data */
92 old_cb = LIBGB_MSGB_CB(msg);
93 new_cb = LIBGB_MSGB_CB(new_msg);
94
95 if (old_cb->bssgph)
96 new_cb->bssgph = new_msg->_data + (old_cb->bssgph - msg->_data);
97 if (old_cb->llch)
98 new_cb->llch = new_msg->_data + (old_cb->llch - msg->_data);
99
100 /* bssgp_cell_id is a pointer into the old msgb, so we need to make
101 * it a pointer into the new msgb */
102 if (old_cb->bssgp_cell_id)
103 new_cb->bssgp_cell_id = new_msg->_data +
104 (old_cb->bssgp_cell_id - msg->_data);
105 new_cb->nsei = old_cb->nsei;
106 new_cb->bvci = old_cb->bvci;
107 new_cb->tlli = old_cb->tlli;
108
109 return new_msg;
110}
111
Harald Welteaf086782010-05-11 10:01:17 +0200112/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
113int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
114 uint16_t bvci, uint16_t ns_bvci)
115{
116 struct msgb *msg = bssgp_msgb_alloc();
117 struct bssgp_normal_hdr *bgph =
118 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
119 uint16_t _bvci;
120
121 msgb_nsei(msg) = nsei;
122 msgb_bvci(msg) = ns_bvci;
123
124 bgph->pdu_type = pdu_type;
125 _bvci = htons(bvci);
126 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
127
128 return gprs_ns_sendmsg(bssgp_nsi, msg);
129}
130
131/* Chapter 10.4.14: Status */
132int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
133{
134 struct msgb *msg = bssgp_msgb_alloc();
135 struct bssgp_normal_hdr *bgph =
136 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
137
Jacob Erlbecka7165772014-09-23 13:28:21 +0200138 /* GSM 08.18, 10.4.14.1: The BVCI must be included if (and only if) the
139 cause is either "BVCI blocked" or "BVCI unknown" */
140 if (cause == BSSGP_CAUSE_UNKNOWN_BVCI || cause == BSSGP_CAUSE_BVCI_BLOCKED) {
141 if (bvci == NULL)
142 LOGP(DBSSGP, LOGL_ERROR, "BSSGP Tx STATUS, cause=%s: "
143 "missing conditional BVCI\n",
144 bssgp_cause_str(cause));
145 } else {
146 if (bvci != NULL)
147 LOGP(DBSSGP, LOGL_ERROR, "BSSGP Tx STATUS, cause=%s: "
148 "unexpected conditional BVCI\n",
149 bssgp_cause_str(cause));
150 }
151
Holger Hans Peter Freyther8e2e78e2010-06-08 16:05:20 +0800152 LOGP(DBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Tx STATUS, cause=%s\n",
Harald Weltecfb545a2010-06-03 21:30:57 +0200153 bvci ? *bvci : 0, bssgp_cause_str(cause));
Harald Welteaf086782010-05-11 10:01:17 +0200154 msgb_nsei(msg) = msgb_nsei(orig_msg);
155 msgb_bvci(msg) = 0;
156
157 bgph->pdu_type = BSSGP_PDUT_STATUS;
158 msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
159 if (bvci) {
160 uint16_t _bvci = htons(*bvci);
161 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
162 }
Harald Welted83d1b62011-07-16 13:45:10 +0200163 msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR,
164 msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));
Harald Welteaf086782010-05-11 10:01:17 +0200165
166 return gprs_ns_sendmsg(bssgp_nsi, msg);
167}