blob: e610ebf7ad4af06216dc648cc36b3cf028010bb4 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*
Harald Weltee08da972017-11-13 01:00:26 +09002 * (C) 2008-2017 by Harald Welte <laforge@gnumonks.org>
3 * (C) 2013 by Holger Freyther <holger@freyther.de>
4 * (C) 2014-2016 by sysmocom - s.f.m.c. GmbH
Harald Welted284cd92010-03-01 21:58:31 +01005 *
6 * All Rights Reserved
7 *
Harald Weltee08da972017-11-13 01:00:26 +09008 * SPDX-License-Identifier: GPL-2.0+
9 *
Harald Welted284cd92010-03-01 21:58:31 +010010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 */
25
Harald Welteecf9dd02010-03-04 14:27:48 +010026#include <stdint.h>
Harald Welte40481e82010-07-30 11:40:32 +020027#include <stdio.h>
Harald Welteecf9dd02010-03-04 14:27:48 +010028#include <errno.h>
29
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010030#include <osmocom/gsm/tlv.h>
31#include <osmocom/gsm/rsl.h>
Harald Welted284cd92010-03-01 21:58:31 +010032
Harald Welte8f2c7e52011-08-17 18:52:03 +020033/*! \addtogroup rsl
34 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020035 * GSM Radio Signalling Link messages on the A-bis interface.
36 * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0.
37 *
38 * \file rsl.c */
Harald Welte8f2c7e52011-08-17 18:52:03 +020039
Neels Hofmeyr87e45502017-06-20 00:17:59 +020040/*! Size for RSL \ref msgb_alloc */
Harald Welteeb8bf392010-03-04 10:32:09 +010041#define RSL_ALLOC_SIZE 200
Neels Hofmeyr87e45502017-06-20 00:17:59 +020042/*! Headroom size for RSL \ref msgb_alloc */
Harald Welteeb8bf392010-03-04 10:32:09 +010043#define RSL_ALLOC_HEADROOM 56
44
Neels Hofmeyr87e45502017-06-20 00:17:59 +020045/*! Initialize a RSL RLL header
Harald Welte96e2a002017-06-12 21:44:18 +020046 * \param[out] dh Caller-allocated RSL RLL header
47 * \param[in] msg_type Message Type */
Harald Welted284cd92010-03-01 21:58:31 +010048void rsl_init_rll_hdr(struct abis_rsl_rll_hdr *dh, uint8_t msg_type)
49{
50 dh->c.msg_discr = ABIS_RSL_MDISC_RLL;
51 dh->c.msg_type = msg_type;
52 dh->ie_chan = RSL_IE_CHAN_NR;
53 dh->ie_link_id = RSL_IE_LINK_IDENT;
54}
55
Neels Hofmeyr87e45502017-06-20 00:17:59 +020056/*! Initialize a RSL Common Channel header
Harald Welte96e2a002017-06-12 21:44:18 +020057 * \param[out] ch Caller-allocated RSL Common Channel Header
58 * \param[in] msg_type Message Type */
Harald Welte6eb7d6c2010-07-13 13:48:13 +020059void rsl_init_cchan_hdr(struct abis_rsl_cchan_hdr *ch, uint8_t msg_type)
60{
61 ch->c.msg_discr = ABIS_RSL_MDISC_COM_CHAN;
62 ch->c.msg_type = msg_type;
63 ch->ie_chan = RSL_IE_CHAN_NR;
64}
65
Neels Hofmeyr87e45502017-06-20 00:17:59 +020066/* TLV parser definition for RSL */
Harald Welted284cd92010-03-01 21:58:31 +010067const struct tlv_definition rsl_att_tlvdef = {
68 .def = {
69 [RSL_IE_CHAN_NR] = { TLV_TYPE_TV },
70 [RSL_IE_LINK_IDENT] = { TLV_TYPE_TV },
71 [RSL_IE_ACT_TYPE] = { TLV_TYPE_TV },
72 [RSL_IE_BS_POWER] = { TLV_TYPE_TV },
73 [RSL_IE_CHAN_IDENT] = { TLV_TYPE_TLV },
74 [RSL_IE_CHAN_MODE] = { TLV_TYPE_TLV },
75 [RSL_IE_ENCR_INFO] = { TLV_TYPE_TLV },
76 [RSL_IE_FRAME_NUMBER] = { TLV_TYPE_FIXED, 2 },
77 [RSL_IE_HANDO_REF] = { TLV_TYPE_TV },
78 [RSL_IE_L1_INFO] = { TLV_TYPE_FIXED, 2 },
79 [RSL_IE_L3_INFO] = { TLV_TYPE_TL16V },
80 [RSL_IE_MS_IDENTITY] = { TLV_TYPE_TLV },
81 [RSL_IE_MS_POWER] = { TLV_TYPE_TV },
82 [RSL_IE_PAGING_GROUP] = { TLV_TYPE_TV },
83 [RSL_IE_PAGING_LOAD] = { TLV_TYPE_FIXED, 2 },
84 [RSL_IE_PYHS_CONTEXT] = { TLV_TYPE_TLV },
85 [RSL_IE_ACCESS_DELAY] = { TLV_TYPE_TV },
86 [RSL_IE_RACH_LOAD] = { TLV_TYPE_TLV },
87 [RSL_IE_REQ_REFERENCE] = { TLV_TYPE_FIXED, 3 },
88 [RSL_IE_RELEASE_MODE] = { TLV_TYPE_TV },
89 [RSL_IE_RESOURCE_INFO] = { TLV_TYPE_TLV },
90 [RSL_IE_RLM_CAUSE] = { TLV_TYPE_TLV },
91 [RSL_IE_STARTNG_TIME] = { TLV_TYPE_FIXED, 2 },
92 [RSL_IE_TIMING_ADVANCE] = { TLV_TYPE_TV },
93 [RSL_IE_UPLINK_MEAS] = { TLV_TYPE_TLV },
94 [RSL_IE_CAUSE] = { TLV_TYPE_TLV },
95 [RSL_IE_MEAS_RES_NR] = { TLV_TYPE_TV },
96 [RSL_IE_MSG_ID] = { TLV_TYPE_TV },
97 [RSL_IE_SYSINFO_TYPE] = { TLV_TYPE_TV },
98 [RSL_IE_MS_POWER_PARAM] = { TLV_TYPE_TLV },
99 [RSL_IE_BS_POWER_PARAM] = { TLV_TYPE_TLV },
100 [RSL_IE_PREPROC_PARAM] = { TLV_TYPE_TLV },
101 [RSL_IE_PREPROC_MEAS] = { TLV_TYPE_TLV },
102 [RSL_IE_IMM_ASS_INFO] = { TLV_TYPE_TLV },
103 [RSL_IE_SMSCB_INFO] = { TLV_TYPE_FIXED, 23 },
104 [RSL_IE_MS_TIMING_OFFSET] = { TLV_TYPE_TV },
105 [RSL_IE_ERR_MSG] = { TLV_TYPE_TLV },
106 [RSL_IE_FULL_BCCH_INFO] = { TLV_TYPE_TLV },
107 [RSL_IE_CHAN_NEEDED] = { TLV_TYPE_TV },
108 [RSL_IE_CB_CMD_TYPE] = { TLV_TYPE_TV },
109 [RSL_IE_SMSCB_MSG] = { TLV_TYPE_TLV },
110 [RSL_IE_FULL_IMM_ASS_INFO] = { TLV_TYPE_TLV },
111 [RSL_IE_SACCH_INFO] = { TLV_TYPE_TLV },
112 [RSL_IE_CBCH_LOAD_INFO] = { TLV_TYPE_TV },
113 [RSL_IE_SMSCB_CHAN_INDICATOR] = { TLV_TYPE_TV },
114 [RSL_IE_GROUP_CALL_REF] = { TLV_TYPE_TLV },
115 [RSL_IE_CHAN_DESC] = { TLV_TYPE_TLV },
116 [RSL_IE_NCH_DRX_INFO] = { TLV_TYPE_TLV },
117 [RSL_IE_CMD_INDICATOR] = { TLV_TYPE_TLV },
118 [RSL_IE_EMLPP_PRIO] = { TLV_TYPE_TV },
119 [RSL_IE_UIC] = { TLV_TYPE_TLV },
120 [RSL_IE_MAIN_CHAN_REF] = { TLV_TYPE_TV },
121 [RSL_IE_MR_CONFIG] = { TLV_TYPE_TLV },
122 [RSL_IE_MR_CONTROL] = { TLV_TYPE_TV },
123 [RSL_IE_SUP_CODEC_TYPES] = { TLV_TYPE_TLV },
124 [RSL_IE_CODEC_CONFIG] = { TLV_TYPE_TLV },
125 [RSL_IE_RTD] = { TLV_TYPE_TV },
126 [RSL_IE_TFO_STATUS] = { TLV_TYPE_TV },
127 [RSL_IE_LLP_APDU] = { TLV_TYPE_TLV },
128 [RSL_IE_SIEMENS_MRPCI] = { TLV_TYPE_TV },
129 [RSL_IE_IPAC_PROXY_UDP] = { TLV_TYPE_FIXED, 2 },
130 [RSL_IE_IPAC_BSCMPL_TOUT] = { TLV_TYPE_TV },
131 [RSL_IE_IPAC_REMOTE_IP] = { TLV_TYPE_FIXED, 4 },
132 [RSL_IE_IPAC_REMOTE_PORT] = { TLV_TYPE_FIXED, 2 },
133 [RSL_IE_IPAC_RTP_PAYLOAD] = { TLV_TYPE_TV },
134 [RSL_IE_IPAC_LOCAL_PORT] = { TLV_TYPE_FIXED, 2 },
135 [RSL_IE_IPAC_SPEECH_MODE] = { TLV_TYPE_TV },
136 [RSL_IE_IPAC_LOCAL_IP] = { TLV_TYPE_FIXED, 4 },
137 [RSL_IE_IPAC_CONN_ID] = { TLV_TYPE_FIXED, 2 },
138 [RSL_IE_IPAC_RTP_CSD_FMT] = { TLV_TYPE_TV },
139 [RSL_IE_IPAC_RTP_JIT_BUF] = { TLV_TYPE_FIXED, 2 },
140 [RSL_IE_IPAC_RTP_COMPR] = { TLV_TYPE_TV },
141 [RSL_IE_IPAC_RTP_PAYLOAD2] = { TLV_TYPE_TV },
142 [RSL_IE_IPAC_RTP_MPLEX] = { TLV_TYPE_FIXED, 8 },
143 [RSL_IE_IPAC_RTP_MPLEX_ID] = { TLV_TYPE_TV },
144 },
145};
146
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200147/*! Encode channel number as per Section 9.3.1
Harald Welte96e2a002017-06-12 21:44:18 +0200148 * \param[in] Channel Type (RSL_CHAN_...)
149 * \param[in] subch Sub-Channel within Channel
150 * \param[in] timeslot Air interface timeslot
151 * \returns RSL Channel Number (TS 08.58 9.3.1) */
Harald Welted284cd92010-03-01 21:58:31 +0100152uint8_t rsl_enc_chan_nr(uint8_t type, uint8_t subch, uint8_t timeslot)
153{
154 uint8_t ret;
155
156 ret = (timeslot & 0x07) | type;
157
158 switch (type) {
159 case RSL_CHAN_Lm_ACCHs:
160 subch &= 0x01;
161 break;
162 case RSL_CHAN_SDCCH4_ACCH:
Harald Welte098cd4b2010-03-04 10:12:50 +0100163 subch &= 0x03;
Harald Welted284cd92010-03-01 21:58:31 +0100164 break;
165 case RSL_CHAN_SDCCH8_ACCH:
166 subch &= 0x07;
167 break;
168 default:
169 /* no subchannels allowed */
170 subch = 0x00;
171 break;
172 }
173 ret |= (subch << 3);
174
175 return ret;
176}
177
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200178/*! Decode RSL channel number
Harald Welte8f2c7e52011-08-17 18:52:03 +0200179 * \param[in] chan_nr Channel Number
180 * \param[out] type Channel Type
181 * \param[out] subch Sub-channel Number
182 * \param[out] timeslot Timeslot
183 */
Harald Welteecf9dd02010-03-04 14:27:48 +0100184int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *timeslot)
185{
186 *timeslot = chan_nr & 0x7;
187
188 if ((chan_nr & 0xf8) == RSL_CHAN_Bm_ACCHs) {
189 *type = RSL_CHAN_Bm_ACCHs;
190 *subch = 0;
191 } else if ((chan_nr & 0xf0) == RSL_CHAN_Lm_ACCHs) {
192 *type = RSL_CHAN_Lm_ACCHs;
193 *subch = (chan_nr >> 3) & 0x1;
194 } else if ((chan_nr & 0xe0) == RSL_CHAN_SDCCH4_ACCH) {
195 *type = RSL_CHAN_SDCCH4_ACCH;
196 *subch = (chan_nr >> 3) & 0x3;
197 } else if ((chan_nr & 0xc0) == RSL_CHAN_SDCCH8_ACCH) {
198 *type = RSL_CHAN_SDCCH8_ACCH;
199 *subch = (chan_nr >> 3) & 0x7;
Harald Welte6fec5142010-03-04 14:30:15 +0100200 } else if ((chan_nr & 0xf8) == RSL_CHAN_BCCH) {
Harald Welteecf9dd02010-03-04 14:27:48 +0100201 *type = RSL_CHAN_BCCH;
202 *subch = 0;
Harald Welte6fec5142010-03-04 14:30:15 +0100203 } else if ((chan_nr & 0xf8) == RSL_CHAN_RACH) {
Harald Welteecf9dd02010-03-04 14:27:48 +0100204 *type = RSL_CHAN_RACH;
205 *subch = 0;
Harald Welte6fec5142010-03-04 14:30:15 +0100206 } else if ((chan_nr & 0xf8) == RSL_CHAN_PCH_AGCH) {
Harald Welteecf9dd02010-03-04 14:27:48 +0100207 *type = RSL_CHAN_PCH_AGCH;
208 *subch = 0;
Harald Weltea8a8d392017-07-30 15:16:18 +0200209 } else if ((chan_nr & 0xf8) == RSL_CHAN_OSMO_PDCH) {
210 *type = RSL_CHAN_OSMO_PDCH;
211 *subch = 0;
Harald Welteecf9dd02010-03-04 14:27:48 +0100212 } else
213 return -EINVAL;
214
215 return 0;
216}
217
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200218/*! Get human-readable string for RSL channel number */
Sylvain Munaut27af0752010-07-25 12:25:17 +0200219const char *rsl_chan_nr_str(uint8_t chan_nr)
220{
221 static char str[20];
222 int ts = chan_nr & 7;
223 uint8_t cbits = chan_nr >> 3;
224
225 if (cbits == 0x01)
226 sprintf(str, "TCH/F on TS%d", ts);
227 else if ((cbits & 0x1e) == 0x02)
228 sprintf(str, "TCH/H(%u) on TS%d", cbits & 0x01, ts);
229 else if ((cbits & 0x1c) == 0x04)
230 sprintf(str, "SDCCH/4(%u) on TS%d", cbits & 0x03, ts);
231 else if ((cbits & 0x18) == 0x08)
232 sprintf(str, "SDCCH/8(%u) on TS%d", cbits & 0x07, ts);
233 else if (cbits == 0x10)
234 sprintf(str, "BCCH on TS%d", ts);
235 else if (cbits == 0x11)
236 sprintf(str, "RACH on TS%d", ts);
237 else if (cbits == 0x12)
238 sprintf(str, "PCH/AGCH on TS%d", ts);
Pau Espin Pedrol10f07da2019-02-18 17:59:37 +0100239 else if (cbits == 0x18)
240 sprintf(str, "PDCH on TS%d", ts);
Sylvain Munaut27af0752010-07-25 12:25:17 +0200241 else
242 sprintf(str, "UNKNOWN on TS%d", ts);
243
244 return str;
245}
246
Harald Weltee9e190a2010-03-25 11:44:57 +0800247static const struct value_string rsl_err_vals[] = {
248 { RSL_ERR_RADIO_IF_FAIL, "Radio Interface Failure" },
249 { RSL_ERR_RADIO_LINK_FAIL, "Radio Link Failure" },
250 { RSL_ERR_HANDOVER_ACC_FAIL, "Handover Access Failure" },
251 { RSL_ERR_TALKER_ACC_FAIL, "Talker Access Failure" },
252 { RSL_ERR_OM_INTERVENTION, "O&M Intervention" },
253 { RSL_ERR_NORMAL_UNSPEC, "Normal event, unspecified" },
254 { RSL_ERR_T_MSRFPCI_EXP, "Siemens: T_MSRFPCI Expired" },
255 { RSL_ERR_EQUIPMENT_FAIL, "Equipment Failure" },
256 { RSL_ERR_RR_UNAVAIL, "Radio Resource not available" },
257 { RSL_ERR_TERR_CH_FAIL, "Terrestrial Channel Failure" },
258 { RSL_ERR_CCCH_OVERLOAD, "CCCH Overload" },
259 { RSL_ERR_ACCH_OVERLOAD, "ACCH Overload" },
260 { RSL_ERR_PROCESSOR_OVERLOAD, "Processor Overload" },
261 { RSL_ERR_RES_UNAVAIL, "Resource not available, unspecified" },
262 { RSL_ERR_TRANSC_UNAVAIL, "Transcoding not available" },
263 { RSL_ERR_SERV_OPT_UNAVAIL, "Service or Option not available" },
264 { RSL_ERR_ENCR_UNIMPL, "Encryption algorithm not implemented" },
265 { RSL_ERR_SERV_OPT_UNIMPL, "Service or Option not implemented" },
266 { RSL_ERR_RCH_ALR_ACTV_ALLOC, "Radio channel already activated" },
267 { RSL_ERR_INVALID_MESSAGE, "Invalid Message, unspecified" },
268 { RSL_ERR_MSG_DISCR, "Message Discriminator Error" },
269 { RSL_ERR_MSG_TYPE, "Message Type Error" },
270 { RSL_ERR_MSG_SEQ, "Message Sequence Error" },
271 { RSL_ERR_IE_ERROR, "General IE error" },
272 { RSL_ERR_MAND_IE_ERROR, "Mandatory IE error" },
273 { RSL_ERR_OPT_IE_ERROR, "Optional IE error" },
274 { RSL_ERR_IE_NONEXIST, "IE non-existent" },
275 { RSL_ERR_IE_LENGTH, "IE length error" },
276 { RSL_ERR_IE_CONTENT, "IE content error" },
277 { RSL_ERR_PROTO, "Protocol error, unspecified" },
278 { RSL_ERR_INTERWORKING, "Interworking error, unspecified" },
279 { 0, NULL }
Harald Welted284cd92010-03-01 21:58:31 +0100280};
281
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200282/*! Get human-readable name for RSL Error */
Harald Welte52b4abd2010-03-25 12:11:38 +0800283const char *rsl_err_name(uint8_t err)
284{
285 return get_value_string(rsl_err_vals, err);
286}
287
Harald Weltecf7e5da2011-06-23 20:43:13 +0200288/* Names for Radio Link Layer Management */
289static const struct value_string rsl_msgt_names[] = {
290 { RSL_MT_DATA_REQ, "DATA_REQ" },
291 { RSL_MT_DATA_IND, "DATA_IND" },
292 { RSL_MT_ERROR_IND, "ERROR_IND" },
293 { RSL_MT_EST_REQ, "EST_REQ" },
294 { RSL_MT_EST_CONF, "EST_CONF" },
295 { RSL_MT_EST_IND, "EST_IND" },
296 { RSL_MT_REL_REQ, "REL_REQ" },
297 { RSL_MT_REL_CONF, "REL_CONF" },
298 { RSL_MT_REL_IND, "REL_IND" },
299 { RSL_MT_UNIT_DATA_REQ, "UNIT_DATA_REQ" },
300 { RSL_MT_UNIT_DATA_IND, "UNIT_DATA_IND" },
301 { RSL_MT_SUSP_REQ, "SUSP_REQ" },
302 { RSL_MT_SUSP_CONF, "SUSP_CONF" },
303 { RSL_MT_RES_REQ, "RES_REQ" },
304 { RSL_MT_RECON_REQ, "RECON_REQ" },
305
306 { RSL_MT_BCCH_INFO, "BCCH_INFO" },
307 { RSL_MT_CCCH_LOAD_IND, "CCCH_LOAD_IND" },
308 { RSL_MT_CHAN_RQD, "CHAN_RQD" },
309 { RSL_MT_DELETE_IND, "DELETE_IND" },
310 { RSL_MT_PAGING_CMD, "PAGING_CMD" },
311 { RSL_MT_IMMEDIATE_ASSIGN_CMD, "IMM_ASS_CMD" },
312 { RSL_MT_SMS_BC_REQ, "SMS_BC_REQ" },
313 { RSL_MT_CHAN_CONF, "CHAN_CONF" },
314
315 { RSL_MT_RF_RES_IND, "RF_RES_IND" },
316 { RSL_MT_SACCH_FILL, "SACCH_FILL" },
317 { RSL_MT_OVERLOAD, "OVERLOAD" },
318 { RSL_MT_ERROR_REPORT, "ERROR_REPORT" },
319 { RSL_MT_SMS_BC_CMD, "SMS_BC_CMD" },
320 { RSL_MT_CBCH_LOAD_IND, "CBCH_LOAD_IND" },
321 { RSL_MT_NOT_CMD, "NOTIFY_CMD" },
322
323 { RSL_MT_CHAN_ACTIV, "CHAN_ACTIV" },
324 { RSL_MT_CHAN_ACTIV_ACK, "CHAN_ACTIV_ACK" },
325 { RSL_MT_CHAN_ACTIV_NACK, "CHAN_ACTIV_NACK" },
326 { RSL_MT_CONN_FAIL, "CONN_FAIL" },
327 { RSL_MT_DEACTIVATE_SACCH, "DEACTIVATE_SACCH" },
328 { RSL_MT_ENCR_CMD, "ENCR_CMD" },
329 { RSL_MT_HANDO_DET, "HANDOVER_DETECT" },
330 { RSL_MT_MEAS_RES, "MEAS_RES" },
331 { RSL_MT_MODE_MODIFY_REQ, "MODE_MODIFY_REQ" },
332 { RSL_MT_MODE_MODIFY_ACK, "MODE_MODIFY_ACK" },
333 { RSL_MT_MODE_MODIFY_NACK, "MODE_MODIFY_NACK" },
334 { RSL_MT_PHY_CONTEXT_REQ, "PHY_CONTEXT_REQ" },
335 { RSL_MT_PHY_CONTEXT_CONF, "PHY_CONTEXT_CONF" },
336 { RSL_MT_RF_CHAN_REL, "RF_CHAN_REL" },
337 { RSL_MT_MS_POWER_CONTROL, "MS_POWER_CONTROL" },
338 { RSL_MT_BS_POWER_CONTROL, "BS_POWER_CONTROL" },
339 { RSL_MT_PREPROC_CONFIG, "PREPROC_CONFIG" },
340 { RSL_MT_PREPROC_MEAS_RES, "PREPROC_MEAS_RES" },
341 { RSL_MT_RF_CHAN_REL_ACK, "RF_CHAN_REL_ACK" },
342 { RSL_MT_SACCH_INFO_MODIFY, "SACCH_INFO_MODIFY" },
343 { RSL_MT_TALKER_DET, "TALKER_DETECT" },
344 { RSL_MT_LISTENER_DET, "LISTENER_DETECT" },
345 { RSL_MT_REMOTE_CODEC_CONF_REP, "REM_CODEC_CONF_REP" },
346 { RSL_MT_RTD_REP, "RTD_REQ" },
347 { RSL_MT_PRE_HANDO_NOTIF, "HANDO_NOTIF" },
348 { RSL_MT_MR_CODEC_MOD_REQ, "CODEC_MOD_REQ" },
349 { RSL_MT_MR_CODEC_MOD_ACK, "CODEC_MOD_ACK" },
350 { RSL_MT_MR_CODEC_MOD_NACK, "CODEC_MOD_NACK" },
351 { RSL_MT_MR_CODEC_MOD_PER, "CODEC_MODE_PER" },
352 { RSL_MT_TFO_REP, "TFO_REP" },
353 { RSL_MT_TFO_MOD_REQ, "TFO_MOD_REQ" },
354 { RSL_MT_LOCATION_INFO, "LOCATION_INFO" },
355 { 0, NULL }
356};
357
358
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200359/*! Get human-readable string for RSL Message Type */
Harald Weltecf7e5da2011-06-23 20:43:13 +0200360const char *rsl_msg_name(uint8_t msg_type)
361{
362 return get_value_string(rsl_msgt_names, msg_type);
363}
364
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200365/*! ip.access specific */
Harald Weltea24026a2011-09-02 12:26:50 +0200366static const struct value_string rsl_ipac_msgt_names[] = {
367 { RSL_MT_IPAC_PDCH_ACT, "IPAC_PDCH_ACT" },
368 { RSL_MT_IPAC_PDCH_ACT_ACK, "IPAC_PDCH_ACT_ACK" },
369 { RSL_MT_IPAC_PDCH_ACT_NACK, "IPAC_PDCH_ACT_NACK" },
370 { RSL_MT_IPAC_PDCH_DEACT, "IPAC_PDCH_DEACT" },
371 { RSL_MT_IPAC_PDCH_DEACT_ACK, "IPAC_PDCH_DEACT_ACK" },
372 { RSL_MT_IPAC_PDCH_DEACT_NACK, "IPAC_PDCH_DEACT_NACK" },
373 { RSL_MT_IPAC_CONNECT_MUX, "IPAC_CONNECT_MUX" },
374 { RSL_MT_IPAC_CONNECT_MUX_ACK, "IPAC_CONNECT_MUX_ACK" },
375 { RSL_MT_IPAC_CONNECT_MUX_NACK, "IPAC_CONNECT_MUX_NACK" },
376 { RSL_MT_IPAC_BIND_MUX, "IPAC_BIND_MUX" },
377 { RSL_MT_IPAC_BIND_MUX_ACK, "IPAC_BIND_MUX_ACK" },
378 { RSL_MT_IPAC_BIND_MUX_NACK, "IPAC_BIND_MUX_NACK" },
379 { RSL_MT_IPAC_DISC_MUX, "IPAC_DISC_MUX" },
380 { RSL_MT_IPAC_DISC_MUX_ACK, "IPAC_DISC_MUX_ACK" },
381 { RSL_MT_IPAC_DISC_MUX_NACK, "IPAC_DISC_MUX_NACK" },
382 { RSL_MT_IPAC_CRCX, "IPAC_CRCX" },
383 { RSL_MT_IPAC_CRCX_ACK, "IPAC_CRCX_ACK" },
384 { RSL_MT_IPAC_CRCX_NACK, "IPAC_CRCX_NACK" },
385 { RSL_MT_IPAC_MDCX, "IPAC_MDCX" },
386 { RSL_MT_IPAC_MDCX_ACK, "IPAC_MDCX_ACK" },
387 { RSL_MT_IPAC_MDCX_NACK, "IPAC_MDCX_NACK" },
388 { RSL_MT_IPAC_DLCX_IND, "IPAC_DLCX_IND" },
389 { RSL_MT_IPAC_DLCX, "IPAC_DLCX" },
390 { RSL_MT_IPAC_DLCX_ACK, "IPAC_DLCX_ACK" },
391 { RSL_MT_IPAC_DLCX_NACK, "IPAC_DLCX_NACK" },
Minh-Quang Nguyen2ff597e2017-02-02 13:44:25 -0500392 { RSL_MT_IPAC_DIR_RETR_ENQ, "IPAC_DIR_RETR_ENQ" },
Harald Weltea24026a2011-09-02 12:26:50 +0200393 { 0, NULL }
394};
395
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200396/*! Get human-readable name of ip.access RSL msg type */
Harald Weltea24026a2011-09-02 12:26:50 +0200397const char *rsl_ipac_msg_name(uint8_t msg_type)
398{
399 return get_value_string(rsl_ipac_msgt_names, msg_type);
400}
401
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200402/*! Get human-readable name of standard or ip.access RSL msg type.
Neels Hofmeyr0167e3f2016-06-06 18:10:38 +0200403 * If msg_type is a standard RSL message type, return its human-readable name.
404 * Otherwise return rsl_ipac_msg_name(msg_type). */
405const char *rsl_or_ipac_msg_name(uint8_t msg_type)
406{
407 const char *str = get_value_string_or_null(rsl_msgt_names, msg_type);
408 if (str)
409 return str;
410 return rsl_ipac_msg_name(msg_type);
411}
412
Harald Welte52b4abd2010-03-25 12:11:38 +0800413static const struct value_string rsl_rlm_cause_strs[] = {
Harald Welted284cd92010-03-01 21:58:31 +0100414 { RLL_CAUSE_T200_EXPIRED, "Timer T200 expired (N200+1) times" },
415 { RLL_CAUSE_REEST_REQ, "Re-establishment request" },
416 { RLL_CAUSE_UNSOL_UA_RESP, "Unsolicited UA response" },
417 { RLL_CAUSE_UNSOL_DM_RESP, "Unsolicited DM response" },
418 { RLL_CAUSE_UNSOL_DM_RESP_MF, "Unsolicited DM response, multiple frame" },
419 { RLL_CAUSE_UNSOL_SPRV_RESP, "Unsolicited supervisory response" },
420 { RLL_CAUSE_SEQ_ERR, "Sequence Error" },
421 { RLL_CAUSE_UFRM_INC_PARAM, "U-Frame with incorrect parameters" },
422 { RLL_CAUSE_SFRM_INC_PARAM, "S-Frame with incorrect parameters" },
423 { RLL_CAUSE_IFRM_INC_MBITS, "I-Frame with incorrect use of M bit" },
424 { RLL_CAUSE_IFRM_INC_LEN, "I-Frame with incorrect length" },
Holger Hans Peter Freyther9ac45372013-06-11 17:54:56 +0200425 { RLL_CAUSE_FRM_UNIMPL, "Frame not implemented" },
Harald Welted284cd92010-03-01 21:58:31 +0100426 { RLL_CAUSE_SABM_MF, "SABM command, multiple frame established state" },
427 { RLL_CAUSE_SABM_INFO_NOTALL, "SABM frame with information not allowed in this state" },
428 { 0, NULL },
429};
430
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200431/*! Get human-readable string for RLM cause */
Harald Welte52b4abd2010-03-25 12:11:38 +0800432const char *rsl_rlm_cause_name(uint8_t err)
Harald Welted284cd92010-03-01 21:58:31 +0100433{
Harald Welte52b4abd2010-03-25 12:11:38 +0800434 return get_value_string(rsl_rlm_cause_strs, err);
Harald Welted284cd92010-03-01 21:58:31 +0100435}
436
437/* Section 3.3.2.3 TS 05.02. I think this looks like a table */
438int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
439{
440 switch (ccch_conf) {
441 case RSL_BCCH_CCCH_CONF_1_NC:
442 return 1;
443 case RSL_BCCH_CCCH_CONF_1_C:
444 return 1;
445 case RSL_BCCH_CCCH_CONF_2_NC:
446 return 2;
447 case RSL_BCCH_CCCH_CONF_3_NC:
448 return 3;
449 case RSL_BCCH_CCCH_CONF_4_NC:
450 return 4;
451 default:
452 return -1;
453 }
454}
455
456/* Section 3.3.2.3 TS 05.02 */
457int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
458{
459 switch (ccch_conf) {
460 case RSL_BCCH_CCCH_CONF_1_NC:
461 return 0;
462 case RSL_BCCH_CCCH_CONF_1_C:
463 return 1;
464 case RSL_BCCH_CCCH_CONF_2_NC:
465 return 0;
466 case RSL_BCCH_CCCH_CONF_3_NC:
467 return 0;
468 case RSL_BCCH_CCCH_CONF_4_NC:
469 return 0;
470 default:
471 return -1;
472 }
473}
Harald Weltef08eabf2010-03-02 21:59:20 +0100474
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200475/*! Push a RSL RLL header onto an existing msgb
Harald Welte96e2a002017-06-12 21:44:18 +0200476 * \param msg Message Buffer to which RLL header shall be pushed
477 * \param[in] msg_type RSL Message Type
478 * \param[in] chan_nr RSL Channel Number
479 * \param[in] link_id RSL Link Identifier
480 * \param[in] transparent Transparent to BTS (1) or not (0) */
Harald Welte6eb7d6c2010-07-13 13:48:13 +0200481void rsl_rll_push_hdr(struct msgb *msg, uint8_t msg_type, uint8_t chan_nr,
482 uint8_t link_id, int transparent)
Harald Weltef08eabf2010-03-02 21:59:20 +0100483{
Harald Weltef08eabf2010-03-02 21:59:20 +0100484 struct abis_rsl_rll_hdr *rh;
485
Harald Weltef08eabf2010-03-02 21:59:20 +0100486 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
487 rsl_init_rll_hdr(rh, msg_type);
Harald Welteeb8bf392010-03-04 10:32:09 +0100488 if (transparent)
489 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
Harald Weltef08eabf2010-03-02 21:59:20 +0100490 rh->chan_nr = chan_nr;
491 rh->link_id = link_id;
492
493 /* set the l2 header pointer */
494 msg->l2h = (uint8_t *)rh;
Harald Weltef08eabf2010-03-02 21:59:20 +0100495}
496
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200497/*! Wrap msgb in L3 Info IE and push a RSL RLL header
Harald Welte96e2a002017-06-12 21:44:18 +0200498 * \param[in] msg Message Buffer to which L3 Header shall be appended
499 * \param[in] msg_type RSL Message Type
500 * \param[in] chan_hr RSL Channel Number
501 * \param[in] link_id Link Identififer
502 * \param[in] transparent Transparent to BTS (1) or not (0) */
Harald Welte6eb7d6c2010-07-13 13:48:13 +0200503void rsl_rll_push_l3(struct msgb *msg, uint8_t msg_type, uint8_t chan_nr,
504 uint8_t link_id, int transparent)
505{
506 uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg);
507
508 /* construct a RSLms RLL message (DATA INDICATION, UNIT DATA
509 * INDICATION) and send it off via RSLms */
510
511 /* Push the L3 IE tag and lengh */
512 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
513
514 /* Then push the RSL header */
515 rsl_rll_push_hdr(msg, msg_type, chan_nr, link_id, transparent);
516}
517
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200518/*! Create msgb with RSL RLL header
Harald Welte96e2a002017-06-12 21:44:18 +0200519 * \param[in] msg_type RSL Message Type
520 * \param[in] chan_nr RSL Channel Number
521 * \param[in] link_id RSL Link Identifier
522 * \param[in] transparent Transparent to BTS (1) or not (0)
523 * \returns callee-allocated msgb; NULL on error */
Harald Weltef08eabf2010-03-02 21:59:20 +0100524struct msgb *rsl_rll_simple(uint8_t msg_type, uint8_t chan_nr,
Harald Welteeb8bf392010-03-04 10:32:09 +0100525 uint8_t link_id, int transparent)
Harald Weltef08eabf2010-03-02 21:59:20 +0100526{
527 struct abis_rsl_rll_hdr *rh;
Harald Welteeb8bf392010-03-04 10:32:09 +0100528 struct msgb *msg;
529
530 msg = msgb_alloc_headroom(RSL_ALLOC_SIZE+RSL_ALLOC_HEADROOM,
531 RSL_ALLOC_HEADROOM, "rsl_rll_simple");
Harald Weltef08eabf2010-03-02 21:59:20 +0100532
533 if (!msg)
534 return NULL;
535
536 /* put the RSL header */
537 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
538 rsl_init_rll_hdr(rh, msg_type);
Harald Welteeb8bf392010-03-04 10:32:09 +0100539 if (transparent)
540 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
Harald Weltef08eabf2010-03-02 21:59:20 +0100541 rh->chan_nr = chan_nr;
542 rh->link_id = link_id;
543
544 /* set the l2 header pointer */
545 msg->l2h = (uint8_t *)rh;
546
547 return msg;
548}
Harald Welte8f2c7e52011-08-17 18:52:03 +0200549
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200550/*! TLV parser definitions for IPA embedded IEs */
Harald Weltefad57522015-12-13 11:56:36 +0100551const struct tlv_definition rsl_ipac_eie_tlvdef = {
552 .def = {
553 [RSL_IPAC_EIE_RXLEV] = { TLV_TYPE_TV },
554 [RSL_IPAC_EIE_RXQUAL] = { TLV_TYPE_TV },
555 [RSL_IPAC_EIE_FREQ_ERR] = { TLV_TYPE_FIXED, 2 },
556 [RSL_IPAC_EIE_TIMING_ERR] = { TLV_TYPE_TV },
557 [RSL_IPAC_EIE_MEAS_AVG_CFG] = { TLV_TYPE_TLV },
558 [RSL_IPAC_EIE_BS_PWR_CTL] = { TLV_TYPE_FIXED, 3 },
559 [RSL_IPAC_EIE_MS_PWR_CTL] = { TLV_TYPE_FIXED, 3 },
560 [RSL_IPAC_EIE_HANDO_THRESH] = { TLV_TYPE_FIXED, 6 },
561 [RSL_IPAC_EIE_NCELL_DEFAULTS] = { TLV_TYPE_FIXED, 3 },
562 [RSL_IPAC_EIE_NCELL_LIST] = { TLV_TYPE_TLV },
563 [RSL_IPAC_EIE_PC_THRESH_COMP] = { TLV_TYPE_FIXED, 10 },
564 [RSL_IPAC_EIE_HO_THRESH_COMP] = { TLV_TYPE_FIXED, 10 },
565 [RSL_IPAC_EIE_HO_CAUSE] = { TLV_TYPE_TLV },
566 [RSL_IPAC_EIE_HO_CANDIDATES] = { TLV_TYPE_TLV },
567 [RSL_IPAC_EIE_NCELL_BA_CHG_LIST]= { TLV_TYPE_TLV },
568 [RSL_IPAC_EIE_NUM_OF_MS] = { TLV_TYPE_TV },
569 [RSL_IPAC_EIE_HO_CAND_EXT] = { TLV_TYPE_TLV },
570 [RSL_IPAC_EIE_NCELL_DEF_EXT] = { TLV_TYPE_TLV },
571 [RSL_IPAC_EIE_NCELL_LIST_EXT] = { TLV_TYPE_TLV },
572 [RSL_IPAC_EIE_MASTER_KEY] = { TLV_TYPE_TLV },
573 [RSL_IPAC_EIE_MASTER_SALT] = { TLV_TYPE_TLV },
Minh-Quang Nguyen17a87482016-09-02 11:28:31 -0400574 [RSL_IPAC_EIE_MEAS_TRANS_RES] = {TLV_TYPE_TV},
575 [RSL_IPAC_EIE_3G_HO_PARAM] = { TLV_TYPE_TLV },
576 [RSL_IPAC_EIE_3G_NCELL_LIST] = { TLV_TYPE_TLV },
577 [RSL_IPAC_EIE_SDCCH_CTL_PARAM] = { TLV_TYPE_TV },
578 [RSL_IPAC_EIE_AMR_CONV_THRESH] = { TLV_TYPE_FIXED, 9 },
Harald Weltefad57522015-12-13 11:56:36 +0100579 },
580};
581
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200582/*! String names of RSL Channel Activation Types */
Neels Hofmeyr47390762016-07-18 23:54:01 +0200583const struct value_string rsl_act_type_names[] = {
584 { RSL_ACT_TYPE_INITIAL, "INITIAL" },
585 { RSL_ACT_TYPE_REACT, "REACT" },
586 { RSL_ACT_INTRA_IMM_ASS, "INTRA_IMM_ASS" },
587 { RSL_ACT_INTRA_NORM_ASS, "INTRA_NORM_ASS" },
588 { RSL_ACT_INTER_ASYNC, "INTER_ASYNC" },
589 { RSL_ACT_INTER_SYNC, "INTER_SYNC" },
590 { RSL_ACT_SECOND_ADD, "SECOND_ADD" },
591 { RSL_ACT_SECOND_MULTI, "SECOND_MULTI" },
592 { RSL_ACT_OSMO_PDCH, "OSMO_PDCH" },
593 { 0, NULL }
594};
595
Sylvain Munautdca7d2c2012-04-18 21:53:23 +0200596/*! @} */