blob: 2ae2dbf5ad68a1b5e7726e982afd809cb3dad100 [file] [log] [blame]
Harald Weltef8db61b2015-12-18 17:29:59 +01001/* high-level RANAP messsage generation code */
2
3/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include <osmocom/core/utils.h>
22#include <osmocom/core/msgb.h>
23
24#include "asn1helpers.h"
Neels Hofmeyr96979af2016-01-05 15:19:44 +010025#include <osmocom/ranap/iu_helpers.h>
Harald Weltef8db61b2015-12-18 17:29:59 +010026
Neels Hofmeyr96979af2016-01-05 15:19:44 +010027#include <osmocom/ranap/ranap_common.h>
28#include <osmocom/ranap/ranap_ies_defs.h>
29#include <osmocom/ranap/ranap_msg_factory.h>
Harald Weltef8db61b2015-12-18 17:29:59 +010030
Harald Weltebdf3fd12016-01-03 17:04:09 +010031#define DRANAP _ranap_DRANAP
Harald Weltef8db61b2015-12-18 17:29:59 +010032
33/*! \brief allocate a new long and assing a value to it */
34static long *new_long(long in)
35{
36 long *out = CALLOC(1, sizeof(long));
37 *out = in;
38 return out;
39}
40
Harald Weltec4338de2015-12-24 00:40:52 +010041/*! \brief generate RANAP RESET message */
42struct msgb *ranap_new_msg_reset(RANAP_CN_DomainIndicator_t domain,
Harald Welte1cdb81d2016-01-01 16:21:05 +010043 const RANAP_Cause_t *cause)
Harald Weltec4338de2015-12-24 00:40:52 +010044{
45 RANAP_ResetIEs_t ies;
46 RANAP_Reset_t out;
47 struct msgb *msg;
48 int rc;
49
50 memset(&ies, 0, sizeof(ies));
51 ies.cN_DomainIndicator = domain;
52 if (cause)
53 memcpy(&ies.cause, cause, sizeof(ies.cause));
54
55 memset(&out, 0, sizeof(out));
56 rc = ranap_encode_reseties(&out, &ies);
57 if (rc < 0) {
58 LOGP(DRANAP, LOGL_ERROR, "error encoding reset IEs: %d\n", rc);
59 return NULL;
60 }
61
62 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Reset,
63 RANAP_Criticality_reject,
64 &asn_DEF_RANAP_Reset,
65 &out);
66
67 /* release dynamic allocations attached to dt */
68 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Reset, &out);
69
70 return msg;
71}
72
73/*! \brief generate RANAP RESET ACK message */
74struct msgb *ranap_new_msg_reset_ack(RANAP_CN_DomainIndicator_t domain,
75 RANAP_GlobalRNC_ID_t *rnc_id)
76{
77 RANAP_ResetAcknowledgeIEs_t ies;
78 RANAP_ResetAcknowledge_t out;
79 struct msgb *msg;
80 int rc;
81
82 memset(&ies, 0, sizeof(ies));
83 ies.cN_DomainIndicator = domain;
84
85 /* The RNC shall include the globalRNC_ID in the RESET
86 * ACKNOWLEDGE message to the CN */
87 if (rnc_id) {
88 ies.presenceMask = RESETACKNOWLEDGEIES_RANAP_GLOBALRNC_ID_PRESENT;
Harald Welte74157f62016-01-01 16:43:59 +010089 OCTET_STRING_noalloc(&ies.globalRNC_ID.pLMNidentity,
Harald Welteea98b6f2015-12-24 15:09:06 +010090 rnc_id->pLMNidentity.buf,
91 rnc_id->pLMNidentity.size);
Harald Weltec4338de2015-12-24 00:40:52 +010092 ies.globalRNC_ID.rNC_ID = rnc_id->rNC_ID;
93 }
94
95 /* FIXME: Do we need criticalityDiagnostics */
96
97 memset(&out, 0, sizeof(out));
98 rc = ranap_encode_resetacknowledgeies(&out, &ies);
99 if (rc < 0) {
100 LOGP(DRANAP, LOGL_ERROR, "error encoding reset ack IEs: %d\n", rc);
101 return NULL;
102 }
103
104 msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_Reset,
105 RANAP_Criticality_reject,
106 &asn_DEF_RANAP_ResetAcknowledge,
107 &out);
108
109 /* release dynamic allocations attached to dt */
110 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_ResetAcknowledge, &out);
111
112 return msg;
113}
114
Harald Welteea98b6f2015-12-24 15:09:06 +0100115/*! \brief generate RANAP INITIAL UE message */
116struct msgb *ranap_new_msg_initial_ue(uint32_t conn_id, int is_ps,
117 RANAP_GlobalRNC_ID_t *rnc_id,
118 uint8_t *nas_pdu, unsigned int nas_len)
119{
120 RANAP_InitialUE_MessageIEs_t ies;
121 RANAP_InitialUE_Message_t out;
122 struct msgb *msg;
123 uint32_t ctxidbuf;
124 int rc;
125 uint16_t buf0 = 0x2342;
126
127 memset(&ies, 0, sizeof(ies));
128 if (is_ps)
129 ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_ps_domain;
130 else
131 ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_cs_domain;
132
Harald Welte74157f62016-01-01 16:43:59 +0100133 OCTET_STRING_noalloc(&ies.lai.pLMNidentity, rnc_id->pLMNidentity.buf, rnc_id->pLMNidentity.size);
134 OCTET_STRING_noalloc(&ies.lai.lAC, (uint8_t *)&buf0, sizeof(buf0));
Harald Welteea98b6f2015-12-24 15:09:06 +0100135
Harald Welte74157f62016-01-01 16:43:59 +0100136 OCTET_STRING_noalloc(&ies.sai.pLMNidentity, rnc_id->pLMNidentity.buf, rnc_id->pLMNidentity.size);
137 OCTET_STRING_noalloc(&ies.sai.lAC, (uint8_t *)&buf0, sizeof(buf0));
138 OCTET_STRING_noalloc(&ies.sai.sAC, (uint8_t *)&buf0, sizeof(buf0));
Harald Welteea98b6f2015-12-24 15:09:06 +0100139
Harald Welte74157f62016-01-01 16:43:59 +0100140 OCTET_STRING_noalloc(&ies.nas_pdu, nas_pdu, nas_len);
Harald Welteea98b6f2015-12-24 15:09:06 +0100141 asn1_u24_to_bitstring(&ies.iuSigConId, &ctxidbuf, conn_id);
Harald Welte74157f62016-01-01 16:43:59 +0100142 OCTET_STRING_noalloc(&ies.globalRNC_ID.pLMNidentity, rnc_id->pLMNidentity.buf, rnc_id->pLMNidentity.size);
Harald Welteea98b6f2015-12-24 15:09:06 +0100143 ies.globalRNC_ID.rNC_ID = rnc_id->rNC_ID;
144
145 memset(&out, 0, sizeof(out));
146 rc = ranap_encode_initialue_messageies(&out, &ies);
147 if (rc < 0) {
148 LOGP(DRANAP, LOGL_ERROR, "error encoding initial UE IEs: %d\n", rc);
149 return NULL;
150 }
151
152 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_InitialUE_Message,
Harald Welte11b1dde2019-04-20 22:37:14 +0200153 RANAP_Criticality_ignore,
Harald Welteea98b6f2015-12-24 15:09:06 +0100154 &asn_DEF_RANAP_InitialUE_Message,
155 &out);
156
157 /* release dynamic allocations attached to dt */
158 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_InitialUE_Message, &out);
159
160 return msg;
161}
162
163
Harald Weltef8db61b2015-12-18 17:29:59 +0100164/*! \brief generate RANAP DIRECT TRANSFER message */
165struct msgb *ranap_new_msg_dt(uint8_t sapi, const uint8_t *nas, unsigned int nas_len)
166{
167 RANAP_DirectTransferIEs_t ies;
168 RANAP_DirectTransfer_t dt;
169 struct msgb *msg;
170 int rc;
171
172 memset(&ies, 0, sizeof(ies));
173 memset(&dt, 0, sizeof(dt));
174
175 /* only SAPI optional field shall be present for CN->RNC */
176 ies.presenceMask = DIRECTTRANSFERIES_RANAP_SAPI_PRESENT;
177
178 if (sapi == 3)
179 ies.sapi = RANAP_SAPI_sapi_3;
180 else
181 ies.sapi = RANAP_SAPI_sapi_0;
182
Harald Welte74157f62016-01-01 16:43:59 +0100183 /* Avoid copying + later freeing of OCTET STRING */
184 OCTET_STRING_noalloc(&ies.nas_pdu, nas, nas_len);
Harald Weltef8db61b2015-12-18 17:29:59 +0100185
186 /* ies -> dt */
187 rc = ranap_encode_directtransferies(&dt, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100188 if (rc < 0) {
189 LOGP(DRANAP, LOGL_ERROR, "error encoding direct transfer IEs: %d\n", rc);
190 return NULL;
191 }
Harald Weltef8db61b2015-12-18 17:29:59 +0100192
193 /* dt -> msg */
194 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_DirectTransfer,
Harald Welte11b1dde2019-04-20 22:37:14 +0200195 RANAP_Criticality_ignore,
Harald Weltef8db61b2015-12-18 17:29:59 +0100196 &asn_DEF_RANAP_DirectTransfer,
197 &dt);
198
199 /* release dynamic allocations attached to dt */
200 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_DirectTransfer, &dt);
201
202 return msg;
203}
204
205static const enum RANAP_IntegrityProtectionAlgorithm ip_alg[2] = {
206 RANAP_IntegrityProtectionAlgorithm_standard_UMTS_integrity_algorithm_UIA1,
207 RANAP_IntegrityProtectionAlgorithm_standard_UMTS_integrity_algorithm_UIA2,
208};
209
210static const RANAP_EncryptionAlgorithm_t enc_alg[2] = {
211 RANAP_EncryptionAlgorithm_standard_UMTS_encryption_algorith_UEA1,
212 RANAP_EncryptionAlgorithm_standard_UMTS_encryption_algorithm_UEA2,
213};
214
215/*! \brief generate RANAP SECURITY MODE COMMAND message */
Daniel Willmannf44d12c2016-04-20 10:16:37 +0200216struct msgb *ranap_new_msg_sec_mod_cmd(const uint8_t *ik, const uint8_t *ck, enum RANAP_KeyStatus status)
Harald Weltef8db61b2015-12-18 17:29:59 +0100217{
218 RANAP_SecurityModeCommandIEs_t ies;
219 RANAP_SecurityModeCommand_t out;
220 struct msgb *msg;
221 int i, rc;
222
223 memset(&ies, 0, sizeof(ies));
224 memset(&out, 0, sizeof(out));
225
Harald Weltef8db61b2015-12-18 17:29:59 +0100226 for (i = 0; i < ARRAY_SIZE(ip_alg); i++) {
227 /* needs to be dynamically allocated, as
228 * SET_OF_free() will call FREEMEM() on it */
229 RANAP_IntegrityProtectionAlgorithm_t *alg = CALLOC(1, sizeof(*alg));
230 *alg = ip_alg[i];
231 ASN_SEQUENCE_ADD(&ies.integrityProtectionInformation.permittedAlgorithms, alg);
232 }
233
234 BIT_STRING_fromBuf(&ies.integrityProtectionInformation.key, ik, 16*8);
235
236 if (ck) {
Harald Welte2cf0d8f2015-12-28 13:13:47 +0100237 ies.presenceMask = SECURITYMODECOMMANDIES_RANAP_ENCRYPTIONINFORMATION_PRESENT;
Harald Weltef8db61b2015-12-18 17:29:59 +0100238 for (i = 0; i < ARRAY_SIZE(ip_alg); i++) {
239 /* needs to be dynamically allocated, as
240 * SET_OF_free() will call FREEMEM() on it */
241 RANAP_EncryptionAlgorithm_t *alg = CALLOC(1, sizeof(*alg));
242 *alg = enc_alg[i];
243 ASN_SEQUENCE_ADD(&ies.encryptionInformation.permittedAlgorithms, alg);
244 }
245 BIT_STRING_fromBuf(&ies.encryptionInformation.key, ck, 16*8);
246 }
247
Daniel Willmannf44d12c2016-04-20 10:16:37 +0200248 ies.keyStatus = status;
Harald Weltef8db61b2015-12-18 17:29:59 +0100249
250 /* ies -> out */
251 rc = ranap_encode_securitymodecommandies(&out, &ies);
252
253 /* release dynamic allocations attached to ies */
254 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_IntegrityProtectionInformation, &ies.integrityProtectionInformation);
Harald Welte2cf0d8f2015-12-28 13:13:47 +0100255 if (ck)
256 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_EncryptionInformation, &ies.encryptionInformation);
Harald Weltef8db61b2015-12-18 17:29:59 +0100257
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100258 if (rc < 0) {
259 LOGP(DRANAP, LOGL_ERROR, "error encoding security mode command IEs: %d\n", rc);
260 return NULL;
261 }
262
Harald Weltef8db61b2015-12-18 17:29:59 +0100263 /* out -> msg */
264 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_SecurityModeControl,
265 RANAP_Criticality_reject,
266 &asn_DEF_RANAP_SecurityModeCommand,
267 &out);
268
269 /* release dynamic allocations attached to out */
270 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_SecurityModeCommand, &out);
271
272 return msg;
273}
274
Neels Hofmeyr7e760acc2016-04-19 01:41:17 +0200275/*! \brief generate RANAP SECURITY MODE COMPLETE message */
Neels Hofmeyra9f55662016-04-19 01:21:41 +0200276struct msgb *ranap_new_msg_sec_mod_compl(
277 RANAP_ChosenIntegrityProtectionAlgorithm_t chosen_ip_alg,
278 RANAP_ChosenEncryptionAlgorithm_t chosen_enc_alg)
279{
280 RANAP_SecurityModeCompleteIEs_t ies;
281 RANAP_SecurityModeComplete_t out;
282 struct msgb *msg;
Philipp Maieraa8d48c2017-12-19 17:48:38 +0100283 int rc;
Neels Hofmeyra9f55662016-04-19 01:21:41 +0200284
285 memset(&ies, 0, sizeof(ies));
286 memset(&out, 0, sizeof(out));
287
288 ies.presenceMask = SECURITYMODECOMPLETEIES_RANAP_CHOSENENCRYPTIONALGORITHM_PRESENT;
289 ies.chosenIntegrityProtectionAlgorithm = chosen_ip_alg;
290 ies.chosenEncryptionAlgorithm = chosen_enc_alg;
291
292 /* ies -> out */
293 rc = ranap_encode_securitymodecompleteies(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100294 if (rc < 0) {
295 LOGP(DRANAP, LOGL_ERROR, "error encoding security mode complete IEs: %d\n", rc);
296 return NULL;
297 }
Neels Hofmeyra9f55662016-04-19 01:21:41 +0200298
299 /* out -> msg */
300 msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_SecurityModeControl,
301 RANAP_Criticality_reject,
302 &asn_DEF_RANAP_SecurityModeComplete,
303 &out);
304
305 /* release dynamic allocations attached to out */
306 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_SecurityModeComplete, &out);
307
308 return msg;
309}
310
Harald Weltef8db61b2015-12-18 17:29:59 +0100311/*! \brief generate RANAP COMMON ID message */
312struct msgb *ranap_new_msg_common_id(const char *imsi)
313{
314 RANAP_CommonID_IEs_t ies;
315 RANAP_CommonID_t out;
316 struct msgb *msg;
317 int rc;
318
319 memset(&ies, 0, sizeof(ies));
320 memset(&out, 0, sizeof(out));
321
322 if (imsi) {
323 uint8_t *imsi_buf = CALLOC(1, 16);
Harald Welte056984f2016-01-03 16:31:31 +0100324 rc = ranap_imsi_encode(imsi_buf, 16, imsi);
Harald Weltef8db61b2015-12-18 17:29:59 +0100325 ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_iMSI;
326 ies.permanentNAS_UE_ID.choice.iMSI.buf = imsi_buf;
327 ies.permanentNAS_UE_ID.choice.iMSI.size = rc;
328 } else
329 ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_NOTHING;
330
331 /* ies -> out */
332 rc = ranap_encode_commonid_ies(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100333
Harald Weltef8db61b2015-12-18 17:29:59 +0100334 /* release dynamic allocations attached to ies */
335 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, &ies.permanentNAS_UE_ID);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100336
337 if (rc < 0) {
338 LOGP(DRANAP, LOGL_ERROR, "error encoding common id IEs: %d\n", rc);
Harald Weltef8db61b2015-12-18 17:29:59 +0100339 return NULL;
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100340 }
Harald Weltef8db61b2015-12-18 17:29:59 +0100341
342 /* out -> msg */
343 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_CommonID,
344 RANAP_Criticality_ignore,
345 &asn_DEF_RANAP_CommonID,
346 &out);
347
348 /* release dynamic allocations attached to out */
349 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_CommonID, &out);
350
351 return msg;
352}
353
354/*! \brief generate RANAP IU RELEASE COMMAND message */
355struct msgb *ranap_new_msg_iu_rel_cmd(const RANAP_Cause_t *cause_in)
356{
357 RANAP_Iu_ReleaseCommandIEs_t ies;
358 RANAP_Iu_ReleaseCommand_t out;
359 struct msgb *msg;
360 int rc;
361
362 memset(&ies, 0, sizeof(ies));
363 memset(&out, 0, sizeof(out));
364
365 memcpy(&ies.cause, cause_in, sizeof(ies.cause));
366
367 /* ies -> out */
368 rc = ranap_encode_iu_releasecommandies(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100369 if (rc < 0) {
370 LOGP(DRANAP, LOGL_ERROR, "error encoding release command IEs: %d\n", rc);
Harald Weltef8db61b2015-12-18 17:29:59 +0100371 return NULL;
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100372 }
Harald Weltef8db61b2015-12-18 17:29:59 +0100373
374 /* out -> msg */
375 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_Release,
376 RANAP_Criticality_reject,
377 &asn_DEF_RANAP_Iu_ReleaseCommand,
378 &out);
379
380 /* release dynamic allocations attached to out */
381 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseCommand, &out);
382
383 return msg;
384}
385
Neels Hofmeyrf6e16b72016-04-19 02:32:05 +0200386/*! \brief generate RAPAP IU RELEASE COMPLETE message */
387struct msgb *ranap_new_msg_iu_rel_compl(void)
388{
389 RANAP_Iu_ReleaseCompleteIEs_t ies;
390 RANAP_Iu_ReleaseComplete_t out;
391 struct msgb *msg;
392 int rc;
393
394 memset(&ies, 0, sizeof(ies));
395 memset(&out, 0, sizeof(out));
396
397 /* ies -> out */
398 rc = ranap_encode_iu_releasecompleteies(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100399 if (rc < 0) {
400 LOGP(DRANAP, LOGL_ERROR, "error encoding release complete IEs: %d\n", rc);
Neels Hofmeyrf6e16b72016-04-19 02:32:05 +0200401 return NULL;
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100402 }
Neels Hofmeyrf6e16b72016-04-19 02:32:05 +0200403
404 /* out -> msg */
405 msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_Iu_Release,
406 RANAP_Criticality_reject,
407 &asn_DEF_RANAP_Iu_ReleaseComplete,
408 &out);
409
410 /* release dynamic allocations attached to out */
411 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseComplete, &out);
412
413 return msg;
414}
415
Harald Weltef8db61b2015-12-18 17:29:59 +0100416/*! \brief generate RANAP PAGING COMMAND message */
417struct msgb *ranap_new_msg_paging_cmd(const char *imsi, const uint32_t *tmsi, int is_ps, uint32_t cause)
418{
419 RANAP_PagingIEs_t ies;
420 RANAP_Paging_t out;
421 struct msgb *msg;
422 uint8_t *imsi_buf = CALLOC(1, 16);
423 int rc;
424
425 memset(&ies, 0, sizeof(ies));
426 memset(&out, 0, sizeof(out));
427
428 /* put together the 'ies' */
429 if (is_ps)
430 ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_ps_domain;
431 else
432 ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_cs_domain;
433
Harald Welte056984f2016-01-03 16:31:31 +0100434 rc = ranap_imsi_encode(imsi_buf, 16, imsi);
Harald Weltef8db61b2015-12-18 17:29:59 +0100435 ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_iMSI;
436 ies.permanentNAS_UE_ID.choice.iMSI.buf = imsi_buf;
437 ies.permanentNAS_UE_ID.choice.iMSI.size = rc;
438
439 if (tmsi) {
440 uint32_t *tmsi_buf = CALLOC(1, sizeof(*tmsi_buf));
Harald Weltef8db61b2015-12-18 17:29:59 +0100441 ies.presenceMask |= PAGINGIES_RANAP_TEMPORARYUE_ID_PRESENT;
442 if (is_ps) {
443 ies.temporaryUE_ID.present = RANAP_TemporaryUE_ID_PR_p_TMSI;
Daniel Willmanna9cf70f2016-05-04 13:50:43 +0200444 asn1_u32_to_str(&ies.temporaryUE_ID.choice.tMSI, tmsi_buf, *tmsi);
Harald Weltef8db61b2015-12-18 17:29:59 +0100445 } else {
446 ies.temporaryUE_ID.present = RANAP_TemporaryUE_ID_PR_tMSI;
Daniel Willmanna9cf70f2016-05-04 13:50:43 +0200447 asn1_u32_to_str(&ies.temporaryUE_ID.choice.p_TMSI, tmsi_buf, *tmsi);
Harald Weltef8db61b2015-12-18 17:29:59 +0100448 }
449 }
450
451 if (cause) {
452 ies.presenceMask |= PAGINGIES_RANAP_PAGINGCAUSE_PRESENT;
453 ies.pagingCause = cause;
454 }
455
456 /* ies -> out */
457 rc = ranap_encode_pagingies(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100458
Harald Weltef8db61b2015-12-18 17:29:59 +0100459 /* release dynamic allocation attached to ies */
460 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, &ies.permanentNAS_UE_ID);
461 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_TemporaryUE_ID, &ies.temporaryUE_ID);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100462
463 if (rc < 0) {
464 LOGP(DRANAP, LOGL_ERROR, "error encoding paging IEs: %d\n", rc);
Harald Weltef8db61b2015-12-18 17:29:59 +0100465 return NULL;
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100466 }
Harald Weltef8db61b2015-12-18 17:29:59 +0100467
468 /* out -> msg */
469 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Paging,
Harald Welte11b1dde2019-04-20 22:37:14 +0200470 RANAP_Criticality_ignore,
Harald Weltef8db61b2015-12-18 17:29:59 +0100471 &asn_DEF_RANAP_Paging,
472 &out);
473
474 /* release dynamic allocations attached to out */
475 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Paging, &out);
476
477 return msg;
478}
479
480static RANAP_SDU_ErrorRatio_t *new_sdu_error_ratio(long mantissa, long exponent)
481{
482 RANAP_SDU_ErrorRatio_t *err = CALLOC(1, sizeof(*err));
483
484 err->mantissa = mantissa;
485 err->exponent = exponent;
486
487 return err;
488}
489
490
491static RANAP_SDU_FormatInformationParameterItem_t *
492new_format_info_pars(long sdu_size)
493{
494 RANAP_SDU_FormatInformationParameterItem_t *fmti = CALLOC(1, sizeof(*fmti));
495 fmti->subflowSDU_Size = new_long(sdu_size);
496 return fmti;
497}
498
499enum sdu_par_profile {
500 SDUPAR_P_VOICE0,
501 SDUPAR_P_VOICE1,
502 SDUPAR_P_VOICE2,
503 SDUPAR_P_DATA,
504};
505
506/* See Chapter 5 of TS 26.102 */
507static RANAP_SDU_ParameterItem_t *new_sdu_par_item(enum sdu_par_profile profile)
508{
509 RANAP_SDU_ParameterItem_t *sdui = CALLOC(1, sizeof(*sdui));
510 RANAP_SDU_FormatInformationParameters_t *fmtip = CALLOC(1, sizeof(*fmtip));
511 RANAP_SDU_FormatInformationParameterItem_t *fmti;
512
513 switch (profile) {
514 case SDUPAR_P_VOICE0:
515 sdui->sDU_ErrorRatio = new_sdu_error_ratio(1, 5);
516 sdui->residualBitErrorRatio.mantissa = 1;
517 sdui->residualBitErrorRatio.exponent = 6;
518 sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_yes;
519 sdui->sDU_FormatInformationParameters = fmtip;
520 fmti = new_format_info_pars(81);
521 ASN_SEQUENCE_ADD(fmtip, fmti);
522 fmti = new_format_info_pars(39);
523 ASN_SEQUENCE_ADD(fmtip, fmti);
524 /* FIXME: could be 10 SDU descriptors for AMR! */
525 break;
526 case SDUPAR_P_VOICE1:
527 sdui->residualBitErrorRatio.mantissa = 1;
528 sdui->residualBitErrorRatio.exponent = 3;
529 sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no_error_detection_consideration;
530 sdui->sDU_FormatInformationParameters = fmtip;
531 fmti = new_format_info_pars(103);
532 ASN_SEQUENCE_ADD(fmtip, fmti);
533 fmti = new_format_info_pars(0);
534 ASN_SEQUENCE_ADD(fmtip, fmti);
535 /* FIXME: could be 10 SDU descriptors for AMR! */
536 break;
537 case SDUPAR_P_VOICE2:
538 sdui->residualBitErrorRatio.mantissa = 5;
539 sdui->residualBitErrorRatio.exponent = 3;
540 sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no_error_detection_consideration;
541 sdui->sDU_FormatInformationParameters = fmtip;
542 fmti = new_format_info_pars(60);
543 ASN_SEQUENCE_ADD(fmtip, fmti);
544 fmti = new_format_info_pars(0);
545 ASN_SEQUENCE_ADD(fmtip, fmti);
546 /* FIXME: could be 10 SDU descriptors for AMR! */
547 break;
548 case SDUPAR_P_DATA:
549 sdui->sDU_ErrorRatio = new_sdu_error_ratio(1, 4);
550 sdui->residualBitErrorRatio.mantissa = 1;
551 sdui->residualBitErrorRatio.exponent = 5;
552 sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no;
553 FREEMEM(fmtip);
554 break;
555 }
556
557 return sdui;
558}
559
560static RANAP_AllocationOrRetentionPriority_t *
561new_alloc_ret_prio(RANAP_PriorityLevel_t level, int capability, int vulnerability,
562 int queueing_allowed)
563{
564 RANAP_AllocationOrRetentionPriority_t *arp = CALLOC(1, sizeof(*arp));
565
566 arp->priorityLevel = level;
567
568 if (capability)
569 arp->pre_emptionCapability = RANAP_Pre_emptionCapability_may_trigger_pre_emption;
570 else
571 arp->pre_emptionCapability = RANAP_Pre_emptionCapability_shall_not_trigger_pre_emption;
572
573 if (vulnerability)
574 arp->pre_emptionVulnerability = RANAP_Pre_emptionVulnerability_pre_emptable;
575 else
576 arp->pre_emptionVulnerability = RANAP_Pre_emptionVulnerability_not_pre_emptable;
577
578 if (queueing_allowed)
579 arp->queuingAllowed = RANAP_QueuingAllowed_queueing_allowed;
580 else
581 arp->queuingAllowed = RANAP_QueuingAllowed_queueing_not_allowed;
582
583 return arp;
584}
585
586/* See Chapter 5 of TS 26.102 */
Neels Hofmeyr8e29b232017-01-23 16:36:11 +0100587static RANAP_RAB_Parameters_t *new_rab_par_voice(long bitrate_guaranteed,
588 long bitrate_max)
Harald Weltef8db61b2015-12-18 17:29:59 +0100589{
590 RANAP_RAB_Parameters_t *rab = CALLOC(1, sizeof(*rab));
591 RANAP_SDU_ParameterItem_t *sdui;
592
593 rab->trafficClass = RANAP_TrafficClass_conversational;
594 rab->rAB_AsymmetryIndicator = RANAP_RAB_AsymmetryIndicator_symmetric_bidirectional;
595
Neels Hofmeyr8e29b232017-01-23 16:36:11 +0100596 ASN_SEQUENCE_ADD(&rab->maxBitrate.list, new_long(bitrate_max));
Harald Weltef8db61b2015-12-18 17:29:59 +0100597 rab->guaranteedBitRate = CALLOC(1, sizeof(*rab->guaranteedBitRate));
Neels Hofmeyr8e29b232017-01-23 16:36:11 +0100598 ASN_SEQUENCE_ADD(rab->guaranteedBitRate, new_long(bitrate_guaranteed));
Harald Weltef8db61b2015-12-18 17:29:59 +0100599 rab->deliveryOrder = RANAP_DeliveryOrder_delivery_order_requested;
600 rab->maxSDU_Size = 244;
601
602 sdui = new_sdu_par_item(SDUPAR_P_VOICE0);
603 ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui);
604 sdui = new_sdu_par_item(SDUPAR_P_VOICE1);
605 ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui);
606 sdui = new_sdu_par_item(SDUPAR_P_VOICE2);
607 ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui);
608
609 rab->transferDelay = new_long(80);
610 rab->allocationOrRetentionPriority = new_alloc_ret_prio(RANAP_PriorityLevel_no_priority, 0, 1, 0);
611
612 rab->sourceStatisticsDescriptor = new_long(RANAP_SourceStatisticsDescriptor_speech);
613
614 return rab;
615}
616
Neels Hofmeyrad14ff92017-01-23 15:06:40 +0100617static RANAP_NAS_SynchronisationIndicator_t *new_rab_nas_sync_ind(int val)
618{
619 uint8_t val_buf = (val / 10) << 4;
620 RANAP_NAS_SynchronisationIndicator_t *nsi = CALLOC(1, sizeof(*nsi));
621 BIT_STRING_fromBuf(nsi, &val_buf, 4);
622 return nsi;
623}
624
Harald Welte05ac6772015-12-29 19:09:52 +0100625static RANAP_RAB_Parameters_t *new_rab_par_data(uint32_t dl_max_bitrate, uint32_t ul_max_bitrate)
Harald Weltef8db61b2015-12-18 17:29:59 +0100626{
627 RANAP_RAB_Parameters_t *rab = CALLOC(1, sizeof(*rab));
628 RANAP_SDU_ParameterItem_t *sdui;
629
630 rab->trafficClass = RANAP_TrafficClass_background;
631 rab->rAB_AsymmetryIndicator = RANAP_RAB_AsymmetryIndicator_asymmetric_bidirectional;
632
Harald Welte05ac6772015-12-29 19:09:52 +0100633 ASN_SEQUENCE_ADD(&rab->maxBitrate.list, new_long(dl_max_bitrate));
634 ASN_SEQUENCE_ADD(&rab->maxBitrate.list, new_long(ul_max_bitrate));
Harald Weltef8db61b2015-12-18 17:29:59 +0100635 rab->deliveryOrder = RANAP_DeliveryOrder_delivery_order_requested;
636 rab->maxSDU_Size = 8000;
637
638 sdui = new_sdu_par_item(SDUPAR_P_DATA);
639 ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui);
640
641 rab->allocationOrRetentionPriority = new_alloc_ret_prio(RANAP_PriorityLevel_no_priority, 0, 0, 0);
642
Harald Weltebb289e32016-05-01 15:20:56 +0200643 RANAP_ProtocolExtensionField_t *pxf = CALLOC(1, sizeof(*pxf));
644 pxf->id = RANAP_ProtocolIE_ID_id_RAB_Parameter_ExtendedMaxBitrateList;
645 pxf->criticality = RANAP_Criticality_ignore;
646
647 RANAP_RAB_Parameter_ExtendedMaxBitrateList_t *rab_mbrlist = CALLOC(1, sizeof(*rab_mbrlist));
648 RANAP_ExtendedMaxBitrate_t *xmbr = CALLOC(1, sizeof(*xmbr));
649 *xmbr = 42000000;
650 ASN_SEQUENCE_ADD(&rab_mbrlist->list, xmbr);
651
652 ANY_fromType_aper(&pxf->value, &asn_DEF_RANAP_RAB_Parameter_ExtendedMaxBitrateList, rab_mbrlist);
653
654 ASN_STRUCT_FREE(asn_DEF_RANAP_RAB_Parameter_ExtendedMaxBitrateList, rab_mbrlist);
655
656 rab->iE_Extensions = CALLOC(1, sizeof(*rab->iE_Extensions));
657 ASN_SEQUENCE_ADD(&rab->iE_Extensions->list, pxf);
Harald Weltef8db61b2015-12-18 17:29:59 +0100658
659 return rab;
660}
661
Neels Hofmeyredf13672016-04-23 13:50:46 +0200662static void new_transp_layer_addr(BIT_STRING_t *out, uint32_t ip, bool use_x213_nsap)
Harald Weltebfe49a22015-12-28 13:14:52 +0100663{
664 uint8_t *buf;
665 unsigned int len;
Neels Hofmeyr54df0a12017-11-18 21:00:41 +0100666 uint32_t ip_h = ntohl(ip);
Harald Weltebfe49a22015-12-28 13:14:52 +0100667
668 if (use_x213_nsap) {
Neels Hofmeyr135bc062017-01-23 16:49:20 +0100669 len = 160/8;
Harald Weltebfe49a22015-12-28 13:14:52 +0100670 buf = CALLOC(len, sizeof(uint8_t));
671 buf[0] = 0x35; /* AFI For IANA ICP */
672 buf[1] = 0x00; /* See A.5.2.1.2.7 of X.213 */
673 buf[2] = 0x01;
Neels Hofmeyr54df0a12017-11-18 21:00:41 +0100674 memcpy(&buf[3], &ip_h, sizeof(ip_h));
Harald Weltebfe49a22015-12-28 13:14:52 +0100675 } else {
Neels Hofmeyr54df0a12017-11-18 21:00:41 +0100676 len = sizeof(ip_h);
Harald Weltebfe49a22015-12-28 13:14:52 +0100677 buf = CALLOC(len, sizeof(uint8_t));
Neels Hofmeyr54df0a12017-11-18 21:00:41 +0100678 memcpy(buf, &ip_h, sizeof(ip_h));
Harald Weltebfe49a22015-12-28 13:14:52 +0100679 }
680 out->buf = buf;
681 out->size = len;
682 out->bits_unused = 0;
683}
684
Neels Hofmeyrf6673b72016-09-08 15:39:18 +0200685static RANAP_TransportLayerInformation_t *new_transp_info_rtp(uint32_t ip, uint16_t port,
686 bool use_x213_nsap)
Harald Weltef8db61b2015-12-18 17:29:59 +0100687{
688 RANAP_TransportLayerInformation_t *tli = CALLOC(1, sizeof(*tli));
Harald Weltef8db61b2015-12-18 17:29:59 +0100689 uint8_t binding_id[4];
690
691 binding_id[0] = port >> 8;
692 binding_id[1] = port & 0xff;
693 binding_id[2] = binding_id[3] = 0;
694
Neels Hofmeyrf6673b72016-09-08 15:39:18 +0200695 new_transp_layer_addr(&tli->transportLayerAddress, ip, use_x213_nsap);
Harald Weltef8db61b2015-12-18 17:29:59 +0100696 tli->iuTransportAssociation.present = RANAP_IuTransportAssociation_PR_bindingID;
697 OCTET_STRING_fromBuf(&tli->iuTransportAssociation.choice.bindingID,
698 (const char *) binding_id, sizeof(binding_id));
699
700 return tli;
701}
702
Neels Hofmeyredf13672016-04-23 13:50:46 +0200703static RANAP_TransportLayerInformation_t *new_transp_info_gtp(uint32_t ip, uint32_t tei,
704 bool use_x213_nsap)
Harald Weltef8db61b2015-12-18 17:29:59 +0100705{
706 RANAP_TransportLayerInformation_t *tli = CALLOC(1, sizeof(*tli));
Harald Welte01de8d72015-12-29 19:10:48 +0100707 uint32_t binding_buf = htonl(tei);
Harald Weltef8db61b2015-12-18 17:29:59 +0100708
Neels Hofmeyredf13672016-04-23 13:50:46 +0200709 new_transp_layer_addr(&tli->transportLayerAddress, ip, use_x213_nsap);
Harald Weltef8db61b2015-12-18 17:29:59 +0100710 tli->iuTransportAssociation.present = RANAP_IuTransportAssociation_PR_gTP_TEI;
Harald Welte01de8d72015-12-29 19:10:48 +0100711 OCTET_STRING_fromBuf(&tli->iuTransportAssociation.choice.gTP_TEI,
Harald Weltef8db61b2015-12-18 17:29:59 +0100712 (const char *) &binding_buf, sizeof(binding_buf));
713
714 return tli;
715}
716
717static RANAP_UserPlaneInformation_t *new_upi(long mode, uint8_t mode_versions)
718{
719 RANAP_UserPlaneInformation_t *upi = CALLOC(1, sizeof(*upi));
720 uint16_t *buf = CALLOC(1, sizeof(*buf));
721
Daniel Willmann49f99cd2016-01-26 09:37:22 +0100722 *buf = ntohs(mode_versions);
Harald Weltef8db61b2015-12-18 17:29:59 +0100723
724 upi->userPlaneMode = mode;
Harald Weltef9c9aa52015-12-24 15:39:00 +0100725 upi->uP_ModeVersions.buf = (uint8_t *) buf;
Harald Weltef8db61b2015-12-18 17:29:59 +0100726 upi->uP_ModeVersions.size = sizeof(*buf);
727 upi->uP_ModeVersions.bits_unused = 0;
728
729 return upi;
730}
731
732
733static void assign_new_ra_id(RANAP_RAB_ID_t *id, uint8_t rab_id)
734{
735 uint8_t *buf = CALLOC(1, sizeof(*buf));
Harald Welte0a3eafe2015-12-19 02:38:09 +0100736 *buf = rab_id;
Harald Weltef8db61b2015-12-18 17:29:59 +0100737
738 id->buf = buf;
739 id->size = 1;
740 id->bits_unused = 0;
741}
742
Neels Hofmeyr74b05652016-09-09 01:25:22 +0200743/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for CS (voice).
744 * See 3GPP TS 25.413 8.2.
Neels Hofmeyre90f13e2017-11-20 17:18:03 +0100745 * RAB ID: 3GPP TS 25.413 9.2.1.2.
746 * \param rtp_ip MGW's RTP IPv4 address in *network* byte order.
Neels Hofmeyr74b05652016-09-09 01:25:22 +0200747 */
Neels Hofmeyrf6673b72016-09-08 15:39:18 +0200748struct msgb *ranap_new_msg_rab_assign_voice(uint8_t rab_id, uint32_t rtp_ip,
749 uint16_t rtp_port,
750 bool use_x213_nsap)
Harald Weltef8db61b2015-12-18 17:29:59 +0100751{
752 RANAP_ProtocolIE_FieldPair_t *pair;
753 RANAP_RAB_AssignmentRequestIEs_t ies;
754 RANAP_RAB_AssignmentRequest_t out;
755 struct msgb *msg;
756 int rc;
757
758 memset(&ies, 0, sizeof(ies));
759 memset(&out, 0, sizeof(out));
760
761 /* only assingnment is present, no release */
762 ies.presenceMask = RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_SETUPORMODIFYLIST_PRESENT;
763
764 /* put together the 'First' part */
765 RANAP_RAB_SetupOrModifyItemFirst_t first;
766 memset(&first, 0, sizeof(first));
767 assign_new_ra_id(&first.rAB_ID, rab_id);
Neels Hofmeyrad14ff92017-01-23 15:06:40 +0100768 first.nAS_SynchronisationIndicator = new_rab_nas_sync_ind(60);
Neels Hofmeyr8e29b232017-01-23 16:36:11 +0100769 first.rAB_Parameters = new_rab_par_voice(6700, 12200);
Harald Weltef8db61b2015-12-18 17:29:59 +0100770 first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_support_mode_for_predefined_SDU_sizes, 1); /* 2? */
Neels Hofmeyrf6673b72016-09-08 15:39:18 +0200771 first.transportLayerInformation = new_transp_info_rtp(rtp_ip, rtp_port,
772 use_x213_nsap);
Harald Weltef8db61b2015-12-18 17:29:59 +0100773
774 /* put together the 'Second' part */
775 RANAP_RAB_SetupOrModifyItemSecond_t second;
776 memset(&second, 0, sizeof(second));
777
778 /* Build an IE Pair out of first and second part:
779 * (first, second) -> pair */
780 pair = ranap_new_ie_pair(RANAP_ProtocolIE_ID_id_RAB_SetupOrModifyItem,
781 RANAP_Criticality_reject,
782 &asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first,
783 RANAP_Criticality_ignore,
784 &asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second);
785
786 /* the pair has been made, we can release any of its elements */
787 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first);
788 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second);
789
Harald Welteb7f67c42015-12-19 02:36:52 +0100790 RANAP_ProtocolIE_ContainerPair_t *container_pair = CALLOC(1, sizeof(*container_pair));
Harald Weltef8db61b2015-12-18 17:29:59 +0100791 /* Add the pair to the list of IEs of the RAB ass.req */
Harald Welteb7f67c42015-12-19 02:36:52 +0100792 ASN_SEQUENCE_ADD(container_pair, pair);
793 ASN_SEQUENCE_ADD(&ies.raB_SetupOrModifyList.list, container_pair);
Harald Weltef8db61b2015-12-18 17:29:59 +0100794
795 /* encode the IEs into the actual assignment request:
796 * ies -> out */
797 rc = ranap_encode_rab_assignmentrequesties(&out, &ies);
798 /* 'out' has been generated, we can now release the input */
799 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyList,
800 &ies.raB_SetupOrModifyList);
801 if (rc < 0)
802 return NULL;
803
804 /* generate an Initiating Mesasage: out -> msg */
805 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_Assignment,
806 RANAP_Criticality_reject,
807 &asn_DEF_RANAP_RAB_AssignmentRequest, &out);
808
809 /* 'msg' has been generated, we cann now release the input 'out' */
810 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_AssignmentRequest, &out);
811
812 return msg;
813}
814
Neels Hofmeyre90f13e2017-11-20 17:18:03 +0100815/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for PS (data)
816 * \param gtp_ip SGSN's GTP IPv4 address in *network* byte order. */
Neels Hofmeyredf13672016-04-23 13:50:46 +0200817struct msgb *ranap_new_msg_rab_assign_data(uint8_t rab_id, uint32_t gtp_ip,
818 uint32_t gtp_tei, bool use_x213_nsap)
Harald Weltef8db61b2015-12-18 17:29:59 +0100819{
820 RANAP_ProtocolIE_FieldPair_t *pair;
821 RANAP_RAB_AssignmentRequestIEs_t ies;
822 RANAP_RAB_AssignmentRequest_t out;
823 RANAP_DataVolumeReportingIndication_t *dat_vol_ind;
824 struct msgb *msg;
825 int rc;
826
827 memset(&ies, 0, sizeof(ies));
828 memset(&out, 0, sizeof(out));
829
830 /* only assingnment is present, no release */
831 ies.presenceMask = RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_SETUPORMODIFYLIST_PRESENT;
832
833 /* put together the 'First' part */
834 RANAP_RAB_SetupOrModifyItemFirst_t first;
835 memset(&first, 0, sizeof(first));
836 assign_new_ra_id(&first.rAB_ID, rab_id);
837 //first.nAS_SynchronisationIndicator = FIXME;
Harald Welte05ac6772015-12-29 19:09:52 +0100838
839 first.rAB_Parameters = new_rab_par_data(1600000, 800000);
Harald Weltef8db61b2015-12-18 17:29:59 +0100840 first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_transparent_mode, 1);
Neels Hofmeyredf13672016-04-23 13:50:46 +0200841 first.transportLayerInformation = new_transp_info_gtp(gtp_ip, gtp_tei,
842 use_x213_nsap);
Harald Weltef8db61b2015-12-18 17:29:59 +0100843
844 /* put together the 'Second' part */
845 RANAP_RAB_SetupOrModifyItemSecond_t second;
846 memset(&second, 0, sizeof(second));
847 second.pDP_TypeInformation = CALLOC(1, sizeof(*second.pDP_TypeInformation));
848 ASN_SEQUENCE_ADD(second.pDP_TypeInformation, new_long(RANAP_PDP_Type_ipv4));
849 dat_vol_ind = CALLOC(1, sizeof(*dat_vol_ind));
850 *dat_vol_ind = RANAP_DataVolumeReportingIndication_do_not_report;
851 second.dataVolumeReportingIndication = dat_vol_ind;
852 second.dl_GTP_PDU_SequenceNumber = new_long(0);
853 second.ul_GTP_PDU_SequenceNumber = new_long(0);
854
855 /* Build an IE Pair out of first and second part:
856 * (first, second) -> pair */
857 pair = ranap_new_ie_pair(RANAP_ProtocolIE_ID_id_RAB_SetupOrModifyItem,
858 RANAP_Criticality_reject,
859 &asn_DEF_RANAP_RAB_SetupOrModifyItemFirst,
860 &first, RANAP_Criticality_ignore,
861 &asn_DEF_RANAP_RAB_SetupOrModifyItemSecond,
862 &second);
863
864 /* the pair has been made, we can release any of its elements */
865 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first);
866 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second);
867
Harald Welteb7f67c42015-12-19 02:36:52 +0100868 RANAP_ProtocolIE_ContainerPair_t *container_pair = CALLOC(1, sizeof(*container_pair));
Harald Weltef8db61b2015-12-18 17:29:59 +0100869 /* Add the pair to the list of IEs of the RAB ass.req */
Neels Hofmeyr9246cc92016-04-25 14:47:26 +0200870 ASN_SEQUENCE_ADD(&container_pair->list, pair);
Harald Welteb7f67c42015-12-19 02:36:52 +0100871 /* Add the pair to the list of IEs of the RAB ass.req */
872 ASN_SEQUENCE_ADD(&ies.raB_SetupOrModifyList.list, container_pair);
Harald Weltef8db61b2015-12-18 17:29:59 +0100873
874 /* encode the IEs into the actual assignment request:
875 * ies -> out */
876 rc = ranap_encode_rab_assignmentrequesties(&out, &ies);
877 /* 'out' has been generated, we can now release the input */
878 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyList,
879 &ies.raB_SetupOrModifyList);
880 if (rc < 0)
881 return NULL;
882
883 /* generate an Initiating Mesasage: out -> msg */
884 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_Assignment,
885 RANAP_Criticality_reject,
886 &asn_DEF_RANAP_RAB_AssignmentRequest, &out);
887
888 /* 'msg' has been generated, we cann now release the input 'out' */
889 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_AssignmentRequest, &out);
890
891 return msg;
892}
Harald Welte37223d82016-01-01 16:18:55 +0100893
894struct msgb *ranap_new_msg_iu_rel_req(const RANAP_Cause_t *cause)
895{
896 RANAP_Iu_ReleaseRequestIEs_t ies;
897 RANAP_Iu_ReleaseRequest_t out;
898 struct msgb *msg;
899 int rc;
900
901 memset(&ies, 0, sizeof(ies));
902 memset(&out, 0, sizeof(out));
903
904 memcpy(&ies.cause, cause, sizeof(ies.cause));
905
906 rc = ranap_encode_iu_releaserequesties(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100907 if (rc < 0) {
908 LOGP(DRANAP, LOGL_ERROR, "error encoding release request IEs: %d\n", rc);
909 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseRequest, &out);
Harald Welte37223d82016-01-01 16:18:55 +0100910 return NULL;
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100911 }
Harald Welte37223d82016-01-01 16:18:55 +0100912
913 /* encode the output into the msgb */
914 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_ReleaseRequest,
Harald Welte11b1dde2019-04-20 22:37:14 +0200915 RANAP_Criticality_ignore,
Harald Welte37223d82016-01-01 16:18:55 +0100916 &asn_DEF_RANAP_Iu_ReleaseRequest, &out);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100917
Harald Welte37223d82016-01-01 16:18:55 +0100918 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseRequest, &out);
919
920 return msg;
921}
922
923struct msgb *ranap_new_msg_rab_rel_req(uint8_t rab_id, const RANAP_Cause_t *cause)
924{
925 RANAP_RAB_ReleaseItemIEs_t item_ies;
926 RANAP_RAB_ReleaseRequestIEs_t ies;
927 RANAP_RAB_ReleaseRequest_t out;
928 struct msgb *msg;
929 int rc;
930
931 memset(&item_ies, 0, sizeof(item_ies));
932 memset(&ies, 0, sizeof(ies));
933 memset(&out, 0, sizeof(out));
934
935 /* put together the ReleaseItem */
936 assign_new_ra_id(&item_ies.raB_ReleaseItem.rAB_ID, rab_id);
937 memcpy(&item_ies.raB_ReleaseItem.cause, cause, sizeof(item_ies.raB_ReleaseItem.cause));
938
939 /* add to the list */
940 rc = ranap_encode_rab_releaseitemies(&ies.raB_ReleaseList, &item_ies);
941 if (rc < 0)
942 return NULL;
943 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseItem, &item_ies.raB_ReleaseItem);
944
945 /* encoe the list IEs into the output */
946 rc = ranap_encode_rab_releaserequesties(&out, &ies);
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100947
Harald Welte37223d82016-01-01 16:18:55 +0100948 /* 'out' has been generated, we can release the input */
949 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseList, &ies.raB_ReleaseList);
950
Philipp Maier1eb19cf2017-12-19 17:46:36 +0100951 if (rc < 0) {
952 LOGP(DRANAP, LOGL_ERROR, "error encoding release request IEs: %d\n", rc);
953 return NULL;
954 }
955
Harald Welte37223d82016-01-01 16:18:55 +0100956 /* encode the output into the msgb */
957 msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_ReleaseRequest,
Harald Welte11b1dde2019-04-20 22:37:14 +0200958 RANAP_Criticality_ignore,
Harald Welte37223d82016-01-01 16:18:55 +0100959 &asn_DEF_RANAP_RAB_ReleaseRequest, &out);
960
961 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseRequest, &out);
962
963 return msg;
964}