blob: 88916c1797e28856238c70103ddcf0189af2b493 [file] [log] [blame]
Harald Welteaf086782010-05-11 10:01:17 +02001/* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */
2
Harald Weltebfe62e52017-05-15 12:48:30 +02003/* (C) 2009-2017 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
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010025#include <osmocom/core/msgb.h>
Harald Weltebfe62e52017-05-15 12:48:30 +020026#include <osmocom/core/byteswap.h>
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010027#include <osmocom/gsm/tlv.h>
28#include <osmocom/core/talloc.h>
Harald Welte73952e32012-06-16 14:59:56 +080029#include <osmocom/gprs/gprs_bssgp.h>
30#include <osmocom/gprs/gprs_ns.h>
Harald Welteaf086782010-05-11 10:01:17 +020031
Harald Weltecca49632012-06-16 17:45:59 +080032#include "common_vty.h"
Harald Welteaf086782010-05-11 10:01:17 +020033
34struct gprs_ns_inst *bssgp_nsi;
35
36/* BSSGP Protocol specific, not implementation specific */
37/* FIXME: This needs to go into libosmocore after finished */
38
39/* Chapter 11.3.9 / Table 11.10: Cause coding */
40static const struct value_string bssgp_cause_strings[] = {
41 { BSSGP_CAUSE_PROC_OVERLOAD, "Processor overload" },
42 { BSSGP_CAUSE_EQUIP_FAIL, "Equipment Failure" },
43 { BSSGP_CAUSE_TRASIT_NET_FAIL, "Transit netowkr service failure" },
44 { BSSGP_CAUSE_CAPA_GREATER_0KPBS,"Transmission capacity modified" },
45 { BSSGP_CAUSE_UNKNOWN_MS, "Unknown MS" },
46 { BSSGP_CAUSE_UNKNOWN_BVCI, "Unknown BVCI" },
47 { BSSGP_CAUSE_CELL_TRAF_CONG, "Cell traffic congestion" },
48 { BSSGP_CAUSE_SGSN_CONG, "SGSN congestion" },
49 { BSSGP_CAUSE_OML_INTERV, "O&M intervention" },
50 { BSSGP_CAUSE_BVCI_BLOCKED, "BVCI blocked" },
51 { BSSGP_CAUSE_PFC_CREATE_FAIL, "PFC create failure" },
52 { BSSGP_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" },
53 { BSSGP_CAUSE_INV_MAND_INF, "Invalid mandatory information" },
54 { BSSGP_CAUSE_MISSING_MAND_IE, "Missing mandatory IE" },
55 { BSSGP_CAUSE_MISSING_COND_IE, "Missing conditional IE" },
56 { BSSGP_CAUSE_UNEXP_COND_IE, "Unexpected conditional IE" },
57 { BSSGP_CAUSE_COND_IE_ERR, "Conditional IE error" },
58 { BSSGP_CAUSE_PDU_INCOMP_STATE, "PDU incompatible with protocol state" },
59 { BSSGP_CAUSE_PROTO_ERR_UNSPEC, "Protocol error - unspecified" },
60 { BSSGP_CAUSE_PDU_INCOMP_FEAT, "PDU not compatible with feature set" },
61 { 0, NULL },
62};
63
Maxc0d9a6c2016-03-09 12:29:23 +010064static const struct value_string bssgp_pdu_strings[] = {
65 { BSSGP_PDUT_DL_UNITDATA, "DL-UNITDATA" },
66 { BSSGP_PDUT_UL_UNITDATA, "UL-UNITDATA" },
67 { BSSGP_PDUT_RA_CAPABILITY, "RA-CAPABILITY" },
68 { BSSGP_PDUT_PTM_UNITDATA, "PTM-UNITDATA" },
69 { BSSGP_PDUT_PAGING_PS, "PAGING-PS" },
70 { BSSGP_PDUT_PAGING_CS, "PAGING-CS" },
71 { BSSGP_PDUT_RA_CAPA_UDPATE, "RA-CAPABILITY-UPDATE" },
72 { BSSGP_PDUT_RA_CAPA_UPDATE_ACK, "RA-CAPABILITY-UPDATE-ACK" },
73 { BSSGP_PDUT_RADIO_STATUS, "RADIO-STATUS" },
74 { BSSGP_PDUT_SUSPEND, "SUSPEND" },
75 { BSSGP_PDUT_SUSPEND_ACK, "SUSPEND-ACK" },
76 { BSSGP_PDUT_SUSPEND_NACK, "SUSPEND-NACK" },
77 { BSSGP_PDUT_RESUME, "RESUME" },
78 { BSSGP_PDUT_RESUME_ACK, "RESUME-ACK" },
79 { BSSGP_PDUT_RESUME_NACK, "RESUME-NACK" },
80 { BSSGP_PDUT_BVC_BLOCK, "BVC-BLOCK" },
81 { BSSGP_PDUT_BVC_BLOCK_ACK, "BVC-BLOCK-ACK" },
82 { BSSGP_PDUT_BVC_RESET, "BVC-RESET" },
83 { BSSGP_PDUT_BVC_RESET_ACK, "BVC-RESET-ACK" },
84 { BSSGP_PDUT_BVC_UNBLOCK, "BVC-UNBLOCK" },
85 { BSSGP_PDUT_BVC_UNBLOCK_ACK, "BVC-UNBLOCK-ACK" },
86 { BSSGP_PDUT_FLOW_CONTROL_BVC, "FLOW-CONTROL-BVC" },
87 { BSSGP_PDUT_FLOW_CONTROL_BVC_ACK, "FLOW-CONTROL-BVC-ACK" },
88 { BSSGP_PDUT_FLOW_CONTROL_MS, "FLOW-CONTROL-MS" },
89 { BSSGP_PDUT_FLOW_CONTROL_MS_ACK, "FLOW-CONTROL-MS-ACK" },
90 { BSSGP_PDUT_FLUSH_LL, "FLUSH-LL" },
91 { BSSGP_PDUT_FLUSH_LL_ACK, "FLUSH-LL-ACK" },
92 { BSSGP_PDUT_LLC_DISCARD, "LLC DISCARDED" },
93 { BSSGP_PDUT_SGSN_INVOKE_TRACE, "SGSN-INVOKE-TRACE" },
94 { BSSGP_PDUT_STATUS, "STATUS" },
95 { BSSGP_PDUT_DOWNLOAD_BSS_PFC, "DOWNLOAD-BSS-PFC" },
96 { BSSGP_PDUT_CREATE_BSS_PFC, "CREATE-BSS-PFC" },
97 { BSSGP_PDUT_CREATE_BSS_PFC_ACK, "CREATE-BSS-PFC-ACK" },
98 { BSSGP_PDUT_CREATE_BSS_PFC_NACK, "CREATE-BSS-PFC-NACK" },
99 { BSSGP_PDUT_MODIFY_BSS_PFC, "MODIFY-BSS-PFC" },
100 { BSSGP_PDUT_MODIFY_BSS_PFC_ACK, "MODIFY-BSS-PFC-ACK" },
101 { BSSGP_PDUT_DELETE_BSS_PFC, "DELETE-BSS-PFC" },
102 { BSSGP_PDUT_DELETE_BSS_PFC_ACK, "DELETE-BSS-PFC-ACK" },
103 { 0, NULL },
104};
105
Harald Welteaf086782010-05-11 10:01:17 +0200106const char *bssgp_cause_str(enum gprs_bssgp_cause cause)
107{
108 return get_value_string(bssgp_cause_strings, cause);
109}
110
Maxc0d9a6c2016-03-09 12:29:23 +0100111const char *bssgp_pdu_str(enum bssgp_pdu_type pdu)
112{
113 return get_value_string(bssgp_pdu_strings, pdu);
114}
Harald Welteaf086782010-05-11 10:01:17 +0200115
116struct msgb *bssgp_msgb_alloc(void)
117{
Jacob Erlbecka39e2de2014-09-23 13:28:24 +0200118 struct msgb *msg = msgb_alloc_headroom(4096, 128, "BSSGP");
Jacob Erlbecka84db612015-04-09 14:22:22 +0200119
120 /* TODO: Add handling of msg == NULL to this function and to all callers */
121 OSMO_ASSERT(msg != NULL);
122
Jacob Erlbecka39e2de2014-09-23 13:28:24 +0200123 msgb_bssgph(msg) = msg->data;
124 return msg;
Harald Welteaf086782010-05-11 10:01:17 +0200125}
126
Jacob Erlbeckf78ec5c2015-11-17 09:53:23 +0100127struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name)
128{
129 struct libgb_msgb_cb *old_cb, *new_cb;
130 struct msgb *new_msg;
131
132 new_msg = msgb_copy(msg, name);
133 if (!new_msg)
134 return NULL;
135
136 /* copy GB specific data */
137 old_cb = LIBGB_MSGB_CB(msg);
138 new_cb = LIBGB_MSGB_CB(new_msg);
139
140 if (old_cb->bssgph)
141 new_cb->bssgph = new_msg->_data + (old_cb->bssgph - msg->_data);
142 if (old_cb->llch)
143 new_cb->llch = new_msg->_data + (old_cb->llch - msg->_data);
144
145 /* bssgp_cell_id is a pointer into the old msgb, so we need to make
146 * it a pointer into the new msgb */
147 if (old_cb->bssgp_cell_id)
148 new_cb->bssgp_cell_id = new_msg->_data +
149 (old_cb->bssgp_cell_id - msg->_data);
150 new_cb->nsei = old_cb->nsei;
151 new_cb->bvci = old_cb->bvci;
152 new_cb->tlli = old_cb->tlli;
153
154 return new_msg;
155}
156
Harald Welteaf086782010-05-11 10:01:17 +0200157/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
158int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
159 uint16_t bvci, uint16_t ns_bvci)
160{
161 struct msgb *msg = bssgp_msgb_alloc();
162 struct bssgp_normal_hdr *bgph =
163 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
164 uint16_t _bvci;
165
166 msgb_nsei(msg) = nsei;
167 msgb_bvci(msg) = ns_bvci;
168
169 bgph->pdu_type = pdu_type;
Harald Weltebfe62e52017-05-15 12:48:30 +0200170 _bvci = osmo_htons(bvci);
Harald Welteaf086782010-05-11 10:01:17 +0200171 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
172
173 return gprs_ns_sendmsg(bssgp_nsi, msg);
174}
175
176/* Chapter 10.4.14: Status */
177int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
178{
179 struct msgb *msg = bssgp_msgb_alloc();
180 struct bssgp_normal_hdr *bgph =
181 (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
182
Jacob Erlbecka7165772014-09-23 13:28:21 +0200183 /* GSM 08.18, 10.4.14.1: The BVCI must be included if (and only if) the
184 cause is either "BVCI blocked" or "BVCI unknown" */
185 if (cause == BSSGP_CAUSE_UNKNOWN_BVCI || cause == BSSGP_CAUSE_BVCI_BLOCKED) {
186 if (bvci == NULL)
187 LOGP(DBSSGP, LOGL_ERROR, "BSSGP Tx STATUS, cause=%s: "
188 "missing conditional BVCI\n",
189 bssgp_cause_str(cause));
190 } else {
191 if (bvci != NULL)
192 LOGP(DBSSGP, LOGL_ERROR, "BSSGP Tx STATUS, cause=%s: "
193 "unexpected conditional BVCI\n",
194 bssgp_cause_str(cause));
195 }
196
Holger Hans Peter Freyther8e2e78e2010-06-08 16:05:20 +0800197 LOGP(DBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Tx STATUS, cause=%s\n",
Harald Weltecfb545a2010-06-03 21:30:57 +0200198 bvci ? *bvci : 0, bssgp_cause_str(cause));
Harald Welteaf086782010-05-11 10:01:17 +0200199 msgb_nsei(msg) = msgb_nsei(orig_msg);
200 msgb_bvci(msg) = 0;
201
202 bgph->pdu_type = BSSGP_PDUT_STATUS;
203 msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
204 if (bvci) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200205 uint16_t _bvci = osmo_htons(*bvci);
Harald Welteaf086782010-05-11 10:01:17 +0200206 msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
207 }
Harald Welted83d1b62011-07-16 13:45:10 +0200208 msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR,
209 msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));
Harald Welteaf086782010-05-11 10:01:17 +0200210
211 return gprs_ns_sendmsg(bssgp_nsi, msg);
212}