import gsm0502_calc_paging_group() from openbsc
[osmocom-bb.git] / src / gsm / rsl.c
1 /* 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
4 /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
5  *
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
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <errno.h>
27
28 #include <osmocom/gsm/tlv.h>
29 #include <osmocom/gsm/rsl.h>
30
31 #define RSL_ALLOC_SIZE          200
32 #define RSL_ALLOC_HEADROOM      56
33
34 void rsl_init_rll_hdr(struct abis_rsl_rll_hdr *dh, uint8_t msg_type)
35 {
36         dh->c.msg_discr = ABIS_RSL_MDISC_RLL;
37         dh->c.msg_type = msg_type;
38         dh->ie_chan = RSL_IE_CHAN_NR;
39         dh->ie_link_id = RSL_IE_LINK_IDENT;
40 }
41
42 void rsl_init_cchan_hdr(struct abis_rsl_cchan_hdr *ch, uint8_t msg_type)
43 {
44         ch->c.msg_discr = ABIS_RSL_MDISC_COM_CHAN;
45         ch->c.msg_type = msg_type;
46         ch->ie_chan = RSL_IE_CHAN_NR;
47 }
48
49 const struct tlv_definition rsl_att_tlvdef = {
50         .def = {
51                 [RSL_IE_CHAN_NR]                = { TLV_TYPE_TV },
52                 [RSL_IE_LINK_IDENT]             = { TLV_TYPE_TV },
53                 [RSL_IE_ACT_TYPE]               = { TLV_TYPE_TV },
54                 [RSL_IE_BS_POWER]               = { TLV_TYPE_TV },
55                 [RSL_IE_CHAN_IDENT]             = { TLV_TYPE_TLV },
56                 [RSL_IE_CHAN_MODE]              = { TLV_TYPE_TLV },
57                 [RSL_IE_ENCR_INFO]              = { TLV_TYPE_TLV },
58                 [RSL_IE_FRAME_NUMBER]           = { TLV_TYPE_FIXED, 2 },
59                 [RSL_IE_HANDO_REF]              = { TLV_TYPE_TV },
60                 [RSL_IE_L1_INFO]                = { TLV_TYPE_FIXED, 2 },
61                 [RSL_IE_L3_INFO]                = { TLV_TYPE_TL16V },
62                 [RSL_IE_MS_IDENTITY]            = { TLV_TYPE_TLV },
63                 [RSL_IE_MS_POWER]               = { TLV_TYPE_TV },
64                 [RSL_IE_PAGING_GROUP]           = { TLV_TYPE_TV },
65                 [RSL_IE_PAGING_LOAD]            = { TLV_TYPE_FIXED, 2 },
66                 [RSL_IE_PYHS_CONTEXT]           = { TLV_TYPE_TLV },
67                 [RSL_IE_ACCESS_DELAY]           = { TLV_TYPE_TV },
68                 [RSL_IE_RACH_LOAD]              = { TLV_TYPE_TLV },
69                 [RSL_IE_REQ_REFERENCE]          = { TLV_TYPE_FIXED, 3 },
70                 [RSL_IE_RELEASE_MODE]           = { TLV_TYPE_TV },
71                 [RSL_IE_RESOURCE_INFO]          = { TLV_TYPE_TLV },
72                 [RSL_IE_RLM_CAUSE]              = { TLV_TYPE_TLV },
73                 [RSL_IE_STARTNG_TIME]           = { TLV_TYPE_FIXED, 2 },
74                 [RSL_IE_TIMING_ADVANCE]         = { TLV_TYPE_TV },
75                 [RSL_IE_UPLINK_MEAS]            = { TLV_TYPE_TLV },
76                 [RSL_IE_CAUSE]                  = { TLV_TYPE_TLV },
77                 [RSL_IE_MEAS_RES_NR]            = { TLV_TYPE_TV },
78                 [RSL_IE_MSG_ID]                 = { TLV_TYPE_TV },
79                 [RSL_IE_SYSINFO_TYPE]           = { TLV_TYPE_TV },
80                 [RSL_IE_MS_POWER_PARAM]         = { TLV_TYPE_TLV },
81                 [RSL_IE_BS_POWER_PARAM]         = { TLV_TYPE_TLV },
82                 [RSL_IE_PREPROC_PARAM]          = { TLV_TYPE_TLV },
83                 [RSL_IE_PREPROC_MEAS]           = { TLV_TYPE_TLV },
84                 [RSL_IE_IMM_ASS_INFO]           = { TLV_TYPE_TLV },
85                 [RSL_IE_SMSCB_INFO]             = { TLV_TYPE_FIXED, 23 },
86                 [RSL_IE_MS_TIMING_OFFSET]       = { TLV_TYPE_TV },
87                 [RSL_IE_ERR_MSG]                = { TLV_TYPE_TLV },
88                 [RSL_IE_FULL_BCCH_INFO]         = { TLV_TYPE_TLV },
89                 [RSL_IE_CHAN_NEEDED]            = { TLV_TYPE_TV },
90                 [RSL_IE_CB_CMD_TYPE]            = { TLV_TYPE_TV },
91                 [RSL_IE_SMSCB_MSG]              = { TLV_TYPE_TLV },
92                 [RSL_IE_FULL_IMM_ASS_INFO]      = { TLV_TYPE_TLV },
93                 [RSL_IE_SACCH_INFO]             = { TLV_TYPE_TLV },
94                 [RSL_IE_CBCH_LOAD_INFO]         = { TLV_TYPE_TV },
95                 [RSL_IE_SMSCB_CHAN_INDICATOR]   = { TLV_TYPE_TV },
96                 [RSL_IE_GROUP_CALL_REF]         = { TLV_TYPE_TLV },
97                 [RSL_IE_CHAN_DESC]              = { TLV_TYPE_TLV },
98                 [RSL_IE_NCH_DRX_INFO]           = { TLV_TYPE_TLV },
99                 [RSL_IE_CMD_INDICATOR]          = { TLV_TYPE_TLV },
100                 [RSL_IE_EMLPP_PRIO]             = { TLV_TYPE_TV },
101                 [RSL_IE_UIC]                    = { TLV_TYPE_TLV },
102                 [RSL_IE_MAIN_CHAN_REF]          = { TLV_TYPE_TV },
103                 [RSL_IE_MR_CONFIG]              = { TLV_TYPE_TLV },
104                 [RSL_IE_MR_CONTROL]             = { TLV_TYPE_TV },
105                 [RSL_IE_SUP_CODEC_TYPES]        = { TLV_TYPE_TLV },
106                 [RSL_IE_CODEC_CONFIG]           = { TLV_TYPE_TLV },
107                 [RSL_IE_RTD]                    = { TLV_TYPE_TV },
108                 [RSL_IE_TFO_STATUS]             = { TLV_TYPE_TV },
109                 [RSL_IE_LLP_APDU]               = { TLV_TYPE_TLV },
110                 [RSL_IE_SIEMENS_MRPCI]          = { TLV_TYPE_TV },
111                 [RSL_IE_IPAC_PROXY_UDP]         = { TLV_TYPE_FIXED, 2 },
112                 [RSL_IE_IPAC_BSCMPL_TOUT]       = { TLV_TYPE_TV },
113                 [RSL_IE_IPAC_REMOTE_IP]         = { TLV_TYPE_FIXED, 4 },
114                 [RSL_IE_IPAC_REMOTE_PORT]       = { TLV_TYPE_FIXED, 2 },
115                 [RSL_IE_IPAC_RTP_PAYLOAD]       = { TLV_TYPE_TV },
116                 [RSL_IE_IPAC_LOCAL_PORT]        = { TLV_TYPE_FIXED, 2 },
117                 [RSL_IE_IPAC_SPEECH_MODE]       = { TLV_TYPE_TV },
118                 [RSL_IE_IPAC_LOCAL_IP]          = { TLV_TYPE_FIXED, 4 },
119                 [RSL_IE_IPAC_CONN_ID]           = { TLV_TYPE_FIXED, 2 },
120                 [RSL_IE_IPAC_RTP_CSD_FMT]       = { TLV_TYPE_TV },
121                 [RSL_IE_IPAC_RTP_JIT_BUF]       = { TLV_TYPE_FIXED, 2 },
122                 [RSL_IE_IPAC_RTP_COMPR]         = { TLV_TYPE_TV },
123                 [RSL_IE_IPAC_RTP_PAYLOAD2]      = { TLV_TYPE_TV },
124                 [RSL_IE_IPAC_RTP_MPLEX]         = { TLV_TYPE_FIXED, 8 },
125                 [RSL_IE_IPAC_RTP_MPLEX_ID]      = { TLV_TYPE_TV },
126         },
127 };
128
129 /* encode channel number as per Section 9.3.1 */
130 uint8_t rsl_enc_chan_nr(uint8_t type, uint8_t subch, uint8_t timeslot)
131 {
132         uint8_t ret;
133
134         ret = (timeslot & 0x07) | type;
135
136         switch (type) {
137         case RSL_CHAN_Lm_ACCHs:
138                 subch &= 0x01;
139                 break;
140         case RSL_CHAN_SDCCH4_ACCH:
141                 subch &= 0x03;
142                 break;
143         case RSL_CHAN_SDCCH8_ACCH:
144                 subch &= 0x07;
145                 break;
146         default:
147                 /* no subchannels allowed */
148                 subch = 0x00;
149                 break;
150         }
151         ret |= (subch << 3);
152
153         return ret;
154 }
155
156 int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *timeslot)
157 {
158         *timeslot = chan_nr & 0x7;
159
160         if ((chan_nr & 0xf8) == RSL_CHAN_Bm_ACCHs) {
161                 *type = RSL_CHAN_Bm_ACCHs;
162                 *subch = 0;
163         } else if ((chan_nr & 0xf0) == RSL_CHAN_Lm_ACCHs) {
164                 *type = RSL_CHAN_Lm_ACCHs;
165                 *subch = (chan_nr >> 3) & 0x1;
166         } else if ((chan_nr & 0xe0) == RSL_CHAN_SDCCH4_ACCH) {
167                 *type = RSL_CHAN_SDCCH4_ACCH;
168                 *subch = (chan_nr >> 3) & 0x3;
169         } else if ((chan_nr & 0xc0) == RSL_CHAN_SDCCH8_ACCH) {
170                 *type = RSL_CHAN_SDCCH8_ACCH;
171                 *subch = (chan_nr >> 3) & 0x7;
172         } else if ((chan_nr & 0xf8) == RSL_CHAN_BCCH) {
173                 *type = RSL_CHAN_BCCH;
174                 *subch = 0;
175         } else if ((chan_nr & 0xf8) == RSL_CHAN_RACH) {
176                 *type = RSL_CHAN_RACH;
177                 *subch = 0;
178         } else if ((chan_nr & 0xf8) == RSL_CHAN_PCH_AGCH) {
179                 *type = RSL_CHAN_PCH_AGCH;
180                 *subch = 0;
181         } else
182                 return -EINVAL;
183
184         return 0;
185 }
186
187 const char *rsl_chan_nr_str(uint8_t chan_nr)
188 {
189         static char str[20];
190         int ts = chan_nr & 7;
191         uint8_t cbits = chan_nr >> 3;
192
193         if (cbits == 0x01)
194                 sprintf(str, "TCH/F on TS%d", ts);
195         else if ((cbits & 0x1e) == 0x02)
196                 sprintf(str, "TCH/H(%u) on TS%d", cbits & 0x01, ts);
197         else if ((cbits & 0x1c) == 0x04)
198                 sprintf(str, "SDCCH/4(%u) on TS%d", cbits & 0x03, ts);
199         else if ((cbits & 0x18) == 0x08)
200                 sprintf(str, "SDCCH/8(%u) on TS%d", cbits & 0x07, ts);
201         else if (cbits == 0x10)
202                 sprintf(str, "BCCH on TS%d", ts);
203         else if (cbits == 0x11)
204                 sprintf(str, "RACH on TS%d", ts);
205         else if (cbits == 0x12)
206                 sprintf(str, "PCH/AGCH on TS%d", ts);
207         else
208                 sprintf(str, "UNKNOWN on TS%d", ts);
209
210         return str;
211 }
212
213 static const struct value_string rsl_err_vals[] = {
214         { RSL_ERR_RADIO_IF_FAIL,        "Radio Interface Failure" },
215         { RSL_ERR_RADIO_LINK_FAIL,      "Radio Link Failure" },
216         { RSL_ERR_HANDOVER_ACC_FAIL,    "Handover Access Failure" },
217         { RSL_ERR_TALKER_ACC_FAIL,      "Talker Access Failure" },
218         { RSL_ERR_OM_INTERVENTION,      "O&M Intervention" },
219         { RSL_ERR_NORMAL_UNSPEC,        "Normal event, unspecified" },
220         { RSL_ERR_T_MSRFPCI_EXP,        "Siemens: T_MSRFPCI Expired" },
221         { RSL_ERR_EQUIPMENT_FAIL,       "Equipment Failure" },
222         { RSL_ERR_RR_UNAVAIL,           "Radio Resource not available" },
223         { RSL_ERR_TERR_CH_FAIL,         "Terrestrial Channel Failure" },
224         { RSL_ERR_CCCH_OVERLOAD,        "CCCH Overload" },
225         { RSL_ERR_ACCH_OVERLOAD,        "ACCH Overload" },
226         { RSL_ERR_PROCESSOR_OVERLOAD,   "Processor Overload" },
227         { RSL_ERR_RES_UNAVAIL,          "Resource not available, unspecified" },
228         { RSL_ERR_TRANSC_UNAVAIL,       "Transcoding not available" },
229         { RSL_ERR_SERV_OPT_UNAVAIL,     "Service or Option not available" },
230         { RSL_ERR_ENCR_UNIMPL,          "Encryption algorithm not implemented" },
231         { RSL_ERR_SERV_OPT_UNIMPL,      "Service or Option not implemented" },
232         { RSL_ERR_RCH_ALR_ACTV_ALLOC,   "Radio channel already activated" },
233         { RSL_ERR_INVALID_MESSAGE,      "Invalid Message, unspecified" },
234         { RSL_ERR_MSG_DISCR,            "Message Discriminator Error" },
235         { RSL_ERR_MSG_TYPE,             "Message Type Error" },
236         { RSL_ERR_MSG_SEQ,              "Message Sequence Error" },
237         { RSL_ERR_IE_ERROR,             "General IE error" },
238         { RSL_ERR_MAND_IE_ERROR,        "Mandatory IE error" },
239         { RSL_ERR_OPT_IE_ERROR,         "Optional IE error" },
240         { RSL_ERR_IE_NONEXIST,          "IE non-existent" },
241         { RSL_ERR_IE_LENGTH,            "IE length error" },
242         { RSL_ERR_IE_CONTENT,           "IE content error" },
243         { RSL_ERR_PROTO,                "Protocol error, unspecified" },
244         { RSL_ERR_INTERWORKING,         "Interworking error, unspecified" },
245         { 0,                            NULL }
246 };
247
248 const char *rsl_err_name(uint8_t err)
249 {
250         return get_value_string(rsl_err_vals, err);
251 }
252
253 /* Names for Radio Link Layer Management */
254 static const struct value_string rsl_msgt_names[] = {
255         { RSL_MT_DATA_REQ,              "DATA_REQ" },
256         { RSL_MT_DATA_IND,              "DATA_IND" },
257         { RSL_MT_ERROR_IND,             "ERROR_IND" },
258         { RSL_MT_EST_REQ,               "EST_REQ" },
259         { RSL_MT_EST_CONF,              "EST_CONF" },
260         { RSL_MT_EST_IND,               "EST_IND" },
261         { RSL_MT_REL_REQ,               "REL_REQ" },
262         { RSL_MT_REL_CONF,              "REL_CONF" },
263         { RSL_MT_REL_IND,               "REL_IND" },
264         { RSL_MT_UNIT_DATA_REQ,         "UNIT_DATA_REQ" },
265         { RSL_MT_UNIT_DATA_IND,         "UNIT_DATA_IND" },
266         { RSL_MT_SUSP_REQ,              "SUSP_REQ" },
267         { RSL_MT_SUSP_CONF,             "SUSP_CONF" },
268         { RSL_MT_RES_REQ,               "RES_REQ" },
269         { RSL_MT_RECON_REQ,             "RECON_REQ" },
270
271         { RSL_MT_BCCH_INFO,             "BCCH_INFO" },
272         { RSL_MT_CCCH_LOAD_IND,         "CCCH_LOAD_IND" },
273         { RSL_MT_CHAN_RQD,              "CHAN_RQD" },
274         { RSL_MT_DELETE_IND,            "DELETE_IND" },
275         { RSL_MT_PAGING_CMD,            "PAGING_CMD" },
276         { RSL_MT_IMMEDIATE_ASSIGN_CMD,  "IMM_ASS_CMD" },
277         { RSL_MT_SMS_BC_REQ,            "SMS_BC_REQ" },
278         { RSL_MT_CHAN_CONF,             "CHAN_CONF" },
279
280         { RSL_MT_RF_RES_IND,            "RF_RES_IND" },
281         { RSL_MT_SACCH_FILL,            "SACCH_FILL" },
282         { RSL_MT_OVERLOAD,              "OVERLOAD" },
283         { RSL_MT_ERROR_REPORT,          "ERROR_REPORT" },
284         { RSL_MT_SMS_BC_CMD,            "SMS_BC_CMD" },
285         { RSL_MT_CBCH_LOAD_IND,         "CBCH_LOAD_IND" },
286         { RSL_MT_NOT_CMD,               "NOTIFY_CMD" },
287
288         { RSL_MT_CHAN_ACTIV,            "CHAN_ACTIV" },
289         { RSL_MT_CHAN_ACTIV_ACK,        "CHAN_ACTIV_ACK" },
290         { RSL_MT_CHAN_ACTIV_NACK,       "CHAN_ACTIV_NACK" },
291         { RSL_MT_CONN_FAIL,             "CONN_FAIL" },
292         { RSL_MT_DEACTIVATE_SACCH,      "DEACTIVATE_SACCH" },
293         { RSL_MT_ENCR_CMD,              "ENCR_CMD" },
294         { RSL_MT_HANDO_DET,             "HANDOVER_DETECT" },
295         { RSL_MT_MEAS_RES,              "MEAS_RES" },
296         { RSL_MT_MODE_MODIFY_REQ,       "MODE_MODIFY_REQ" },
297         { RSL_MT_MODE_MODIFY_ACK,       "MODE_MODIFY_ACK" },
298         { RSL_MT_MODE_MODIFY_NACK,      "MODE_MODIFY_NACK" },
299         { RSL_MT_PHY_CONTEXT_REQ,       "PHY_CONTEXT_REQ" },
300         { RSL_MT_PHY_CONTEXT_CONF,      "PHY_CONTEXT_CONF" },
301         { RSL_MT_RF_CHAN_REL,           "RF_CHAN_REL" },
302         { RSL_MT_MS_POWER_CONTROL,      "MS_POWER_CONTROL" },
303         { RSL_MT_BS_POWER_CONTROL,      "BS_POWER_CONTROL" },
304         { RSL_MT_PREPROC_CONFIG,        "PREPROC_CONFIG" },
305         { RSL_MT_PREPROC_MEAS_RES,      "PREPROC_MEAS_RES" },
306         { RSL_MT_RF_CHAN_REL_ACK,       "RF_CHAN_REL_ACK" },
307         { RSL_MT_SACCH_INFO_MODIFY,     "SACCH_INFO_MODIFY" },
308         { RSL_MT_TALKER_DET,            "TALKER_DETECT" },
309         { RSL_MT_LISTENER_DET,          "LISTENER_DETECT" },
310         { RSL_MT_REMOTE_CODEC_CONF_REP, "REM_CODEC_CONF_REP" },
311         { RSL_MT_RTD_REP,               "RTD_REQ" },
312         { RSL_MT_PRE_HANDO_NOTIF,       "HANDO_NOTIF" },
313         { RSL_MT_MR_CODEC_MOD_REQ,      "CODEC_MOD_REQ" },
314         { RSL_MT_MR_CODEC_MOD_ACK,      "CODEC_MOD_ACK" },
315         { RSL_MT_MR_CODEC_MOD_NACK,     "CODEC_MOD_NACK" },
316         { RSL_MT_MR_CODEC_MOD_PER,      "CODEC_MODE_PER" },
317         { RSL_MT_TFO_REP,               "TFO_REP" },
318         { RSL_MT_TFO_MOD_REQ,           "TFO_MOD_REQ" },
319         { RSL_MT_LOCATION_INFO,         "LOCATION_INFO" },
320         { 0,                            NULL }
321 };
322
323
324 const char *rsl_msg_name(uint8_t msg_type)
325 {
326         return get_value_string(rsl_msgt_names, msg_type);
327 }
328
329 static const struct value_string rsl_rlm_cause_strs[] = {
330         { RLL_CAUSE_T200_EXPIRED,       "Timer T200 expired (N200+1) times" },
331         { RLL_CAUSE_REEST_REQ,          "Re-establishment request" },
332         { RLL_CAUSE_UNSOL_UA_RESP,      "Unsolicited UA response" },
333         { RLL_CAUSE_UNSOL_DM_RESP,      "Unsolicited DM response" },
334         { RLL_CAUSE_UNSOL_DM_RESP_MF,   "Unsolicited DM response, multiple frame" },
335         { RLL_CAUSE_UNSOL_SPRV_RESP,    "Unsolicited supervisory response" },
336         { RLL_CAUSE_SEQ_ERR,            "Sequence Error" },
337         { RLL_CAUSE_UFRM_INC_PARAM,     "U-Frame with incorrect parameters" },
338         { RLL_CAUSE_SFRM_INC_PARAM,     "S-Frame with incorrect parameters" },
339         { RLL_CAUSE_IFRM_INC_MBITS,     "I-Frame with incorrect use of M bit" },
340         { RLL_CAUSE_IFRM_INC_LEN,       "I-Frame with incorrect length" },
341         { RLL_CAUSE_FRM_UNIMPL,         "Fraeme not implemented" },
342         { RLL_CAUSE_SABM_MF,            "SABM command, multiple frame established state" },
343         { RLL_CAUSE_SABM_INFO_NOTALL,   "SABM frame with information not allowed in this state" },
344         { 0,                            NULL },
345 };
346
347 const char *rsl_rlm_cause_name(uint8_t err)
348 {
349         return get_value_string(rsl_rlm_cause_strs, err);
350 }
351
352 /* Section 3.3.2.3 TS 05.02. I think this looks like a table */
353 int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
354 {
355         switch (ccch_conf) {
356         case RSL_BCCH_CCCH_CONF_1_NC:
357                 return 1;
358         case RSL_BCCH_CCCH_CONF_1_C:
359                 return 1;
360         case RSL_BCCH_CCCH_CONF_2_NC:
361                 return 2;
362         case RSL_BCCH_CCCH_CONF_3_NC:
363                 return 3;
364         case RSL_BCCH_CCCH_CONF_4_NC:
365                 return 4;
366         default:
367                 return -1;
368         }
369 }
370
371 /* Section 3.3.2.3 TS 05.02 */
372 int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
373 {
374         switch (ccch_conf) {
375         case RSL_BCCH_CCCH_CONF_1_NC:
376                 return 0;
377         case RSL_BCCH_CCCH_CONF_1_C:
378                 return 1;
379         case RSL_BCCH_CCCH_CONF_2_NC:
380                 return 0;
381         case RSL_BCCH_CCCH_CONF_3_NC:
382                 return 0;
383         case RSL_BCCH_CCCH_CONF_4_NC:
384                 return 0;
385         default:
386                 return -1;
387         }
388 }
389
390 /* Push a RSL RLL header */
391 void rsl_rll_push_hdr(struct msgb *msg, uint8_t msg_type, uint8_t chan_nr,
392                       uint8_t link_id, int transparent)
393 {
394         struct abis_rsl_rll_hdr *rh;
395
396         rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
397         rsl_init_rll_hdr(rh, msg_type);
398         if (transparent)
399                 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
400         rh->chan_nr = chan_nr;
401         rh->link_id = link_id;
402
403         /* set the l2 header pointer */
404         msg->l2h = (uint8_t *)rh;
405 }
406
407 /* Push a RSL RLL header with L3_INFO IE */
408 void rsl_rll_push_l3(struct msgb *msg, uint8_t msg_type, uint8_t chan_nr,
409                      uint8_t link_id, int transparent)
410 {
411         uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg);
412
413         /* construct a RSLms RLL message (DATA INDICATION, UNIT DATA
414          * INDICATION) and send it off via RSLms */
415
416         /* Push the L3 IE tag and lengh */
417         msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
418
419         /* Then push the RSL header */
420         rsl_rll_push_hdr(msg, msg_type, chan_nr, link_id, transparent);
421 }
422
423 struct msgb *rsl_rll_simple(uint8_t msg_type, uint8_t chan_nr,
424                             uint8_t link_id, int transparent)
425 {
426         struct abis_rsl_rll_hdr *rh;
427         struct msgb *msg;
428
429         msg = msgb_alloc_headroom(RSL_ALLOC_SIZE+RSL_ALLOC_HEADROOM,
430                                   RSL_ALLOC_HEADROOM, "rsl_rll_simple");
431
432         if (!msg)
433                 return NULL;
434
435         /* put the RSL header */
436         rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
437         rsl_init_rll_hdr(rh, msg_type);
438         if (transparent)
439                 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
440         rh->chan_nr = chan_nr;
441         rh->link_id = link_id;
442
443         /* set the l2 header pointer */
444         msg->l2h = (uint8_t *)rh;
445
446         return msg;
447 }