blob: 7bc1712f3784e69247f8fd7a15fbfb79116b17f5 [file] [log] [blame]
Harald Welted284cd92010-03-01 21:58:31 +01001/* GSM Radio Signalling Link messages on the A-bis interface
2 * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */
3
Harald Welteeb8bf392010-03-04 10:32:09 +01004/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welted284cd92010-03-01 21:58:31 +01005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
Harald Welteecf9dd02010-03-04 14:27:48 +010024#include <stdint.h>
25#include <errno.h>
26
Harald Welted284cd92010-03-01 21:58:31 +010027#include <osmocore/tlv.h>
28#include <osmocore/rsl.h>
29
Harald Welteeb8bf392010-03-04 10:32:09 +010030#define RSL_ALLOC_SIZE 200
31#define RSL_ALLOC_HEADROOM 56
32
Harald Welted284cd92010-03-01 21:58:31 +010033void rsl_init_rll_hdr(struct abis_rsl_rll_hdr *dh, uint8_t msg_type)
34{
35 dh->c.msg_discr = ABIS_RSL_MDISC_RLL;
36 dh->c.msg_type = msg_type;
37 dh->ie_chan = RSL_IE_CHAN_NR;
38 dh->ie_link_id = RSL_IE_LINK_IDENT;
39}
40
Harald Welte6eb7d6c2010-07-13 13:48:13 +020041void rsl_init_cchan_hdr(struct abis_rsl_cchan_hdr *ch, uint8_t msg_type)
42{
43 ch->c.msg_discr = ABIS_RSL_MDISC_COM_CHAN;
44 ch->c.msg_type = msg_type;
45 ch->ie_chan = RSL_IE_CHAN_NR;
46}
47
Harald Welted284cd92010-03-01 21:58:31 +010048const struct tlv_definition rsl_att_tlvdef = {
49 .def = {
50 [RSL_IE_CHAN_NR] = { TLV_TYPE_TV },
51 [RSL_IE_LINK_IDENT] = { TLV_TYPE_TV },
52 [RSL_IE_ACT_TYPE] = { TLV_TYPE_TV },
53 [RSL_IE_BS_POWER] = { TLV_TYPE_TV },
54 [RSL_IE_CHAN_IDENT] = { TLV_TYPE_TLV },
55 [RSL_IE_CHAN_MODE] = { TLV_TYPE_TLV },
56 [RSL_IE_ENCR_INFO] = { TLV_TYPE_TLV },
57 [RSL_IE_FRAME_NUMBER] = { TLV_TYPE_FIXED, 2 },
58 [RSL_IE_HANDO_REF] = { TLV_TYPE_TV },
59 [RSL_IE_L1_INFO] = { TLV_TYPE_FIXED, 2 },
60 [RSL_IE_L3_INFO] = { TLV_TYPE_TL16V },
61 [RSL_IE_MS_IDENTITY] = { TLV_TYPE_TLV },
62 [RSL_IE_MS_POWER] = { TLV_TYPE_TV },
63 [RSL_IE_PAGING_GROUP] = { TLV_TYPE_TV },
64 [RSL_IE_PAGING_LOAD] = { TLV_TYPE_FIXED, 2 },
65 [RSL_IE_PYHS_CONTEXT] = { TLV_TYPE_TLV },
66 [RSL_IE_ACCESS_DELAY] = { TLV_TYPE_TV },
67 [RSL_IE_RACH_LOAD] = { TLV_TYPE_TLV },
68 [RSL_IE_REQ_REFERENCE] = { TLV_TYPE_FIXED, 3 },
69 [RSL_IE_RELEASE_MODE] = { TLV_TYPE_TV },
70 [RSL_IE_RESOURCE_INFO] = { TLV_TYPE_TLV },
71 [RSL_IE_RLM_CAUSE] = { TLV_TYPE_TLV },
72 [RSL_IE_STARTNG_TIME] = { TLV_TYPE_FIXED, 2 },
73 [RSL_IE_TIMING_ADVANCE] = { TLV_TYPE_TV },
74 [RSL_IE_UPLINK_MEAS] = { TLV_TYPE_TLV },
75 [RSL_IE_CAUSE] = { TLV_TYPE_TLV },
76 [RSL_IE_MEAS_RES_NR] = { TLV_TYPE_TV },
77 [RSL_IE_MSG_ID] = { TLV_TYPE_TV },
78 [RSL_IE_SYSINFO_TYPE] = { TLV_TYPE_TV },
79 [RSL_IE_MS_POWER_PARAM] = { TLV_TYPE_TLV },
80 [RSL_IE_BS_POWER_PARAM] = { TLV_TYPE_TLV },
81 [RSL_IE_PREPROC_PARAM] = { TLV_TYPE_TLV },
82 [RSL_IE_PREPROC_MEAS] = { TLV_TYPE_TLV },
83 [RSL_IE_IMM_ASS_INFO] = { TLV_TYPE_TLV },
84 [RSL_IE_SMSCB_INFO] = { TLV_TYPE_FIXED, 23 },
85 [RSL_IE_MS_TIMING_OFFSET] = { TLV_TYPE_TV },
86 [RSL_IE_ERR_MSG] = { TLV_TYPE_TLV },
87 [RSL_IE_FULL_BCCH_INFO] = { TLV_TYPE_TLV },
88 [RSL_IE_CHAN_NEEDED] = { TLV_TYPE_TV },
89 [RSL_IE_CB_CMD_TYPE] = { TLV_TYPE_TV },
90 [RSL_IE_SMSCB_MSG] = { TLV_TYPE_TLV },
91 [RSL_IE_FULL_IMM_ASS_INFO] = { TLV_TYPE_TLV },
92 [RSL_IE_SACCH_INFO] = { TLV_TYPE_TLV },
93 [RSL_IE_CBCH_LOAD_INFO] = { TLV_TYPE_TV },
94 [RSL_IE_SMSCB_CHAN_INDICATOR] = { TLV_TYPE_TV },
95 [RSL_IE_GROUP_CALL_REF] = { TLV_TYPE_TLV },
96 [RSL_IE_CHAN_DESC] = { TLV_TYPE_TLV },
97 [RSL_IE_NCH_DRX_INFO] = { TLV_TYPE_TLV },
98 [RSL_IE_CMD_INDICATOR] = { TLV_TYPE_TLV },
99 [RSL_IE_EMLPP_PRIO] = { TLV_TYPE_TV },
100 [RSL_IE_UIC] = { TLV_TYPE_TLV },
101 [RSL_IE_MAIN_CHAN_REF] = { TLV_TYPE_TV },
102 [RSL_IE_MR_CONFIG] = { TLV_TYPE_TLV },
103 [RSL_IE_MR_CONTROL] = { TLV_TYPE_TV },
104 [RSL_IE_SUP_CODEC_TYPES] = { TLV_TYPE_TLV },
105 [RSL_IE_CODEC_CONFIG] = { TLV_TYPE_TLV },
106 [RSL_IE_RTD] = { TLV_TYPE_TV },
107 [RSL_IE_TFO_STATUS] = { TLV_TYPE_TV },
108 [RSL_IE_LLP_APDU] = { TLV_TYPE_TLV },
109 [RSL_IE_SIEMENS_MRPCI] = { TLV_TYPE_TV },
110 [RSL_IE_IPAC_PROXY_UDP] = { TLV_TYPE_FIXED, 2 },
111 [RSL_IE_IPAC_BSCMPL_TOUT] = { TLV_TYPE_TV },
112 [RSL_IE_IPAC_REMOTE_IP] = { TLV_TYPE_FIXED, 4 },
113 [RSL_IE_IPAC_REMOTE_PORT] = { TLV_TYPE_FIXED, 2 },
114 [RSL_IE_IPAC_RTP_PAYLOAD] = { TLV_TYPE_TV },
115 [RSL_IE_IPAC_LOCAL_PORT] = { TLV_TYPE_FIXED, 2 },
116 [RSL_IE_IPAC_SPEECH_MODE] = { TLV_TYPE_TV },
117 [RSL_IE_IPAC_LOCAL_IP] = { TLV_TYPE_FIXED, 4 },
118 [RSL_IE_IPAC_CONN_ID] = { TLV_TYPE_FIXED, 2 },
119 [RSL_IE_IPAC_RTP_CSD_FMT] = { TLV_TYPE_TV },
120 [RSL_IE_IPAC_RTP_JIT_BUF] = { TLV_TYPE_FIXED, 2 },
121 [RSL_IE_IPAC_RTP_COMPR] = { TLV_TYPE_TV },
122 [RSL_IE_IPAC_RTP_PAYLOAD2] = { TLV_TYPE_TV },
123 [RSL_IE_IPAC_RTP_MPLEX] = { TLV_TYPE_FIXED, 8 },
124 [RSL_IE_IPAC_RTP_MPLEX_ID] = { TLV_TYPE_TV },
125 },
126};
127
128/* encode channel number as per Section 9.3.1 */
129uint8_t rsl_enc_chan_nr(uint8_t type, uint8_t subch, uint8_t timeslot)
130{
131 uint8_t ret;
132
133 ret = (timeslot & 0x07) | type;
134
135 switch (type) {
136 case RSL_CHAN_Lm_ACCHs:
137 subch &= 0x01;
138 break;
139 case RSL_CHAN_SDCCH4_ACCH:
Harald Welte098cd4b2010-03-04 10:12:50 +0100140 subch &= 0x03;
Harald Welted284cd92010-03-01 21:58:31 +0100141 break;
142 case RSL_CHAN_SDCCH8_ACCH:
143 subch &= 0x07;
144 break;
145 default:
146 /* no subchannels allowed */
147 subch = 0x00;
148 break;
149 }
150 ret |= (subch << 3);
151
152 return ret;
153}
154
Harald Welteecf9dd02010-03-04 14:27:48 +0100155int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *timeslot)
156{
157 *timeslot = chan_nr & 0x7;
158
159 if ((chan_nr & 0xf8) == RSL_CHAN_Bm_ACCHs) {
160 *type = RSL_CHAN_Bm_ACCHs;
161 *subch = 0;
162 } else if ((chan_nr & 0xf0) == RSL_CHAN_Lm_ACCHs) {
163 *type = RSL_CHAN_Lm_ACCHs;
164 *subch = (chan_nr >> 3) & 0x1;
165 } else if ((chan_nr & 0xe0) == RSL_CHAN_SDCCH4_ACCH) {
166 *type = RSL_CHAN_SDCCH4_ACCH;
167 *subch = (chan_nr >> 3) & 0x3;
168 } else if ((chan_nr & 0xc0) == RSL_CHAN_SDCCH8_ACCH) {
169 *type = RSL_CHAN_SDCCH8_ACCH;
170 *subch = (chan_nr >> 3) & 0x7;
Harald Welte6fec5142010-03-04 14:30:15 +0100171 } else if ((chan_nr & 0xf8) == RSL_CHAN_BCCH) {
Harald Welteecf9dd02010-03-04 14:27:48 +0100172 *type = RSL_CHAN_BCCH;
173 *subch = 0;
Harald Welte6fec5142010-03-04 14:30:15 +0100174 } else if ((chan_nr & 0xf8) == RSL_CHAN_RACH) {
Harald Welteecf9dd02010-03-04 14:27:48 +0100175 *type = RSL_CHAN_RACH;
176 *subch = 0;
Harald Welte6fec5142010-03-04 14:30:15 +0100177 } else if ((chan_nr & 0xf8) == RSL_CHAN_PCH_AGCH) {
Harald Welteecf9dd02010-03-04 14:27:48 +0100178 *type = RSL_CHAN_PCH_AGCH;
179 *subch = 0;
180 } else
181 return -EINVAL;
182
183 return 0;
184}
185
Harald Weltee9e190a2010-03-25 11:44:57 +0800186static const struct value_string rsl_err_vals[] = {
187 { RSL_ERR_RADIO_IF_FAIL, "Radio Interface Failure" },
188 { RSL_ERR_RADIO_LINK_FAIL, "Radio Link Failure" },
189 { RSL_ERR_HANDOVER_ACC_FAIL, "Handover Access Failure" },
190 { RSL_ERR_TALKER_ACC_FAIL, "Talker Access Failure" },
191 { RSL_ERR_OM_INTERVENTION, "O&M Intervention" },
192 { RSL_ERR_NORMAL_UNSPEC, "Normal event, unspecified" },
193 { RSL_ERR_T_MSRFPCI_EXP, "Siemens: T_MSRFPCI Expired" },
194 { RSL_ERR_EQUIPMENT_FAIL, "Equipment Failure" },
195 { RSL_ERR_RR_UNAVAIL, "Radio Resource not available" },
196 { RSL_ERR_TERR_CH_FAIL, "Terrestrial Channel Failure" },
197 { RSL_ERR_CCCH_OVERLOAD, "CCCH Overload" },
198 { RSL_ERR_ACCH_OVERLOAD, "ACCH Overload" },
199 { RSL_ERR_PROCESSOR_OVERLOAD, "Processor Overload" },
200 { RSL_ERR_RES_UNAVAIL, "Resource not available, unspecified" },
201 { RSL_ERR_TRANSC_UNAVAIL, "Transcoding not available" },
202 { RSL_ERR_SERV_OPT_UNAVAIL, "Service or Option not available" },
203 { RSL_ERR_ENCR_UNIMPL, "Encryption algorithm not implemented" },
204 { RSL_ERR_SERV_OPT_UNIMPL, "Service or Option not implemented" },
205 { RSL_ERR_RCH_ALR_ACTV_ALLOC, "Radio channel already activated" },
206 { RSL_ERR_INVALID_MESSAGE, "Invalid Message, unspecified" },
207 { RSL_ERR_MSG_DISCR, "Message Discriminator Error" },
208 { RSL_ERR_MSG_TYPE, "Message Type Error" },
209 { RSL_ERR_MSG_SEQ, "Message Sequence Error" },
210 { RSL_ERR_IE_ERROR, "General IE error" },
211 { RSL_ERR_MAND_IE_ERROR, "Mandatory IE error" },
212 { RSL_ERR_OPT_IE_ERROR, "Optional IE error" },
213 { RSL_ERR_IE_NONEXIST, "IE non-existent" },
214 { RSL_ERR_IE_LENGTH, "IE length error" },
215 { RSL_ERR_IE_CONTENT, "IE content error" },
216 { RSL_ERR_PROTO, "Protocol error, unspecified" },
217 { RSL_ERR_INTERWORKING, "Interworking error, unspecified" },
218 { 0, NULL }
Harald Welted284cd92010-03-01 21:58:31 +0100219};
220
Harald Welte52b4abd2010-03-25 12:11:38 +0800221const char *rsl_err_name(uint8_t err)
222{
223 return get_value_string(rsl_err_vals, err);
224}
225
226static const struct value_string rsl_rlm_cause_strs[] = {
Harald Welted284cd92010-03-01 21:58:31 +0100227 { RLL_CAUSE_T200_EXPIRED, "Timer T200 expired (N200+1) times" },
228 { RLL_CAUSE_REEST_REQ, "Re-establishment request" },
229 { RLL_CAUSE_UNSOL_UA_RESP, "Unsolicited UA response" },
230 { RLL_CAUSE_UNSOL_DM_RESP, "Unsolicited DM response" },
231 { RLL_CAUSE_UNSOL_DM_RESP_MF, "Unsolicited DM response, multiple frame" },
232 { RLL_CAUSE_UNSOL_SPRV_RESP, "Unsolicited supervisory response" },
233 { RLL_CAUSE_SEQ_ERR, "Sequence Error" },
234 { RLL_CAUSE_UFRM_INC_PARAM, "U-Frame with incorrect parameters" },
235 { RLL_CAUSE_SFRM_INC_PARAM, "S-Frame with incorrect parameters" },
236 { RLL_CAUSE_IFRM_INC_MBITS, "I-Frame with incorrect use of M bit" },
237 { RLL_CAUSE_IFRM_INC_LEN, "I-Frame with incorrect length" },
238 { RLL_CAUSE_FRM_UNIMPL, "Fraeme not implemented" },
239 { RLL_CAUSE_SABM_MF, "SABM command, multiple frame established state" },
240 { RLL_CAUSE_SABM_INFO_NOTALL, "SABM frame with information not allowed in this state" },
241 { 0, NULL },
242};
243
Harald Welte52b4abd2010-03-25 12:11:38 +0800244const char *rsl_rlm_cause_name(uint8_t err)
Harald Welted284cd92010-03-01 21:58:31 +0100245{
Harald Welte52b4abd2010-03-25 12:11:38 +0800246 return get_value_string(rsl_rlm_cause_strs, err);
Harald Welted284cd92010-03-01 21:58:31 +0100247}
248
249/* Section 3.3.2.3 TS 05.02. I think this looks like a table */
250int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
251{
252 switch (ccch_conf) {
253 case RSL_BCCH_CCCH_CONF_1_NC:
254 return 1;
255 case RSL_BCCH_CCCH_CONF_1_C:
256 return 1;
257 case RSL_BCCH_CCCH_CONF_2_NC:
258 return 2;
259 case RSL_BCCH_CCCH_CONF_3_NC:
260 return 3;
261 case RSL_BCCH_CCCH_CONF_4_NC:
262 return 4;
263 default:
264 return -1;
265 }
266}
267
268/* Section 3.3.2.3 TS 05.02 */
269int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
270{
271 switch (ccch_conf) {
272 case RSL_BCCH_CCCH_CONF_1_NC:
273 return 0;
274 case RSL_BCCH_CCCH_CONF_1_C:
275 return 1;
276 case RSL_BCCH_CCCH_CONF_2_NC:
277 return 0;
278 case RSL_BCCH_CCCH_CONF_3_NC:
279 return 0;
280 case RSL_BCCH_CCCH_CONF_4_NC:
281 return 0;
282 default:
283 return -1;
284 }
285}
Harald Weltef08eabf2010-03-02 21:59:20 +0100286
Harald Welte6eb7d6c2010-07-13 13:48:13 +0200287/* Push a RSL RLL header */
288void rsl_rll_push_hdr(struct msgb *msg, uint8_t msg_type, uint8_t chan_nr,
289 uint8_t link_id, int transparent)
Harald Weltef08eabf2010-03-02 21:59:20 +0100290{
Harald Weltef08eabf2010-03-02 21:59:20 +0100291 struct abis_rsl_rll_hdr *rh;
292
Harald Weltef08eabf2010-03-02 21:59:20 +0100293 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
294 rsl_init_rll_hdr(rh, msg_type);
Harald Welteeb8bf392010-03-04 10:32:09 +0100295 if (transparent)
296 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
Harald Weltef08eabf2010-03-02 21:59:20 +0100297 rh->chan_nr = chan_nr;
298 rh->link_id = link_id;
299
300 /* set the l2 header pointer */
301 msg->l2h = (uint8_t *)rh;
Harald Weltef08eabf2010-03-02 21:59:20 +0100302}
303
Harald Welte6eb7d6c2010-07-13 13:48:13 +0200304/* Push a RSL RLL header with L3_INFO IE */
305void rsl_rll_push_l3(struct msgb *msg, uint8_t msg_type, uint8_t chan_nr,
306 uint8_t link_id, int transparent)
307{
308 uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg);
309
310 /* construct a RSLms RLL message (DATA INDICATION, UNIT DATA
311 * INDICATION) and send it off via RSLms */
312
313 /* Push the L3 IE tag and lengh */
314 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
315
316 /* Then push the RSL header */
317 rsl_rll_push_hdr(msg, msg_type, chan_nr, link_id, transparent);
318}
319
Harald Weltef08eabf2010-03-02 21:59:20 +0100320struct msgb *rsl_rll_simple(uint8_t msg_type, uint8_t chan_nr,
Harald Welteeb8bf392010-03-04 10:32:09 +0100321 uint8_t link_id, int transparent)
Harald Weltef08eabf2010-03-02 21:59:20 +0100322{
323 struct abis_rsl_rll_hdr *rh;
Harald Welteeb8bf392010-03-04 10:32:09 +0100324 struct msgb *msg;
325
326 msg = msgb_alloc_headroom(RSL_ALLOC_SIZE+RSL_ALLOC_HEADROOM,
327 RSL_ALLOC_HEADROOM, "rsl_rll_simple");
Harald Weltef08eabf2010-03-02 21:59:20 +0100328
329 if (!msg)
330 return NULL;
331
332 /* put the RSL header */
333 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
334 rsl_init_rll_hdr(rh, msg_type);
Harald Welteeb8bf392010-03-04 10:32:09 +0100335 if (transparent)
336 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
Harald Weltef08eabf2010-03-02 21:59:20 +0100337 rh->chan_nr = chan_nr;
338 rh->link_id = link_id;
339
340 /* set the l2 header pointer */
341 msg->l2h = (uint8_t *)rh;
342
343 return msg;
344}