Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 1 | /* 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 Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 25 | #include <osmocom/ranap/iu_helpers.h> |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 26 | |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 27 | #include <osmocom/ranap/ranap_common.h> |
| 28 | #include <osmocom/ranap/ranap_ies_defs.h> |
| 29 | #include <osmocom/ranap/ranap_msg_factory.h> |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 30 | |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 31 | #define DRANAP _ranap_DRANAP |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 32 | |
| 33 | /*! \brief allocate a new long and assing a value to it */ |
| 34 | static long *new_long(long in) |
| 35 | { |
| 36 | long *out = CALLOC(1, sizeof(long)); |
| 37 | *out = in; |
| 38 | return out; |
| 39 | } |
| 40 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 41 | /*! \brief generate RANAP RESET message */ |
| 42 | struct msgb *ranap_new_msg_reset(RANAP_CN_DomainIndicator_t domain, |
Harald Welte | 1cdb81d | 2016-01-01 16:21:05 +0100 | [diff] [blame] | 43 | const RANAP_Cause_t *cause) |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 44 | { |
| 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 */ |
| 74 | struct 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 Welte | 74157f6 | 2016-01-01 16:43:59 +0100 | [diff] [blame] | 89 | OCTET_STRING_noalloc(&ies.globalRNC_ID.pLMNidentity, |
Harald Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 90 | rnc_id->pLMNidentity.buf, |
| 91 | rnc_id->pLMNidentity.size); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 92 | 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 Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 115 | /*! \brief generate RANAP INITIAL UE message */ |
| 116 | struct 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 Welte | 74157f6 | 2016-01-01 16:43:59 +0100 | [diff] [blame] | 133 | 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 Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 135 | |
Harald Welte | 74157f6 | 2016-01-01 16:43:59 +0100 | [diff] [blame] | 136 | 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 Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 139 | |
Harald Welte | 74157f6 | 2016-01-01 16:43:59 +0100 | [diff] [blame] | 140 | OCTET_STRING_noalloc(&ies.nas_pdu, nas_pdu, nas_len); |
Harald Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 141 | asn1_u24_to_bitstring(&ies.iuSigConId, &ctxidbuf, conn_id); |
Harald Welte | 74157f6 | 2016-01-01 16:43:59 +0100 | [diff] [blame] | 142 | OCTET_STRING_noalloc(&ies.globalRNC_ID.pLMNidentity, rnc_id->pLMNidentity.buf, rnc_id->pLMNidentity.size); |
Harald Welte | ea98b6f | 2015-12-24 15:09:06 +0100 | [diff] [blame] | 143 | 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, |
| 153 | RANAP_Criticality_reject, |
| 154 | &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 Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 164 | /*! \brief generate RANAP DIRECT TRANSFER message */ |
| 165 | struct 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 Welte | 74157f6 | 2016-01-01 16:43:59 +0100 | [diff] [blame] | 183 | /* Avoid copying + later freeing of OCTET STRING */ |
| 184 | OCTET_STRING_noalloc(&ies.nas_pdu, nas, nas_len); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 185 | |
| 186 | /* ies -> dt */ |
| 187 | rc = ranap_encode_directtransferies(&dt, &ies); |
| 188 | |
| 189 | /* dt -> msg */ |
| 190 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_DirectTransfer, |
| 191 | RANAP_Criticality_reject, |
| 192 | &asn_DEF_RANAP_DirectTransfer, |
| 193 | &dt); |
| 194 | |
| 195 | /* release dynamic allocations attached to dt */ |
| 196 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_DirectTransfer, &dt); |
| 197 | |
| 198 | return msg; |
| 199 | } |
| 200 | |
| 201 | static const enum RANAP_IntegrityProtectionAlgorithm ip_alg[2] = { |
| 202 | RANAP_IntegrityProtectionAlgorithm_standard_UMTS_integrity_algorithm_UIA1, |
| 203 | RANAP_IntegrityProtectionAlgorithm_standard_UMTS_integrity_algorithm_UIA2, |
| 204 | }; |
| 205 | |
| 206 | static const RANAP_EncryptionAlgorithm_t enc_alg[2] = { |
| 207 | RANAP_EncryptionAlgorithm_standard_UMTS_encryption_algorith_UEA1, |
| 208 | RANAP_EncryptionAlgorithm_standard_UMTS_encryption_algorithm_UEA2, |
| 209 | }; |
| 210 | |
| 211 | /*! \brief generate RANAP SECURITY MODE COMMAND message */ |
Daniel Willmann | f44d12c | 2016-04-20 10:16:37 +0200 | [diff] [blame] | 212 | struct msgb *ranap_new_msg_sec_mod_cmd(const uint8_t *ik, const uint8_t *ck, enum RANAP_KeyStatus status) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 213 | { |
| 214 | RANAP_SecurityModeCommandIEs_t ies; |
| 215 | RANAP_SecurityModeCommand_t out; |
| 216 | struct msgb *msg; |
| 217 | int i, rc; |
| 218 | |
| 219 | memset(&ies, 0, sizeof(ies)); |
| 220 | memset(&out, 0, sizeof(out)); |
| 221 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 222 | for (i = 0; i < ARRAY_SIZE(ip_alg); i++) { |
| 223 | /* needs to be dynamically allocated, as |
| 224 | * SET_OF_free() will call FREEMEM() on it */ |
| 225 | RANAP_IntegrityProtectionAlgorithm_t *alg = CALLOC(1, sizeof(*alg)); |
| 226 | *alg = ip_alg[i]; |
| 227 | ASN_SEQUENCE_ADD(&ies.integrityProtectionInformation.permittedAlgorithms, alg); |
| 228 | } |
| 229 | |
| 230 | BIT_STRING_fromBuf(&ies.integrityProtectionInformation.key, ik, 16*8); |
| 231 | |
| 232 | if (ck) { |
Harald Welte | 2cf0d8f | 2015-12-28 13:13:47 +0100 | [diff] [blame] | 233 | ies.presenceMask = SECURITYMODECOMMANDIES_RANAP_ENCRYPTIONINFORMATION_PRESENT; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 234 | for (i = 0; i < ARRAY_SIZE(ip_alg); i++) { |
| 235 | /* needs to be dynamically allocated, as |
| 236 | * SET_OF_free() will call FREEMEM() on it */ |
| 237 | RANAP_EncryptionAlgorithm_t *alg = CALLOC(1, sizeof(*alg)); |
| 238 | *alg = enc_alg[i]; |
| 239 | ASN_SEQUENCE_ADD(&ies.encryptionInformation.permittedAlgorithms, alg); |
| 240 | } |
| 241 | BIT_STRING_fromBuf(&ies.encryptionInformation.key, ck, 16*8); |
| 242 | } |
| 243 | |
Daniel Willmann | f44d12c | 2016-04-20 10:16:37 +0200 | [diff] [blame] | 244 | ies.keyStatus = status; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 245 | |
| 246 | /* ies -> out */ |
| 247 | rc = ranap_encode_securitymodecommandies(&out, &ies); |
| 248 | |
| 249 | /* release dynamic allocations attached to ies */ |
| 250 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_IntegrityProtectionInformation, &ies.integrityProtectionInformation); |
Harald Welte | 2cf0d8f | 2015-12-28 13:13:47 +0100 | [diff] [blame] | 251 | if (ck) |
| 252 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_EncryptionInformation, &ies.encryptionInformation); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 253 | |
| 254 | /* out -> msg */ |
| 255 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_SecurityModeControl, |
| 256 | RANAP_Criticality_reject, |
| 257 | &asn_DEF_RANAP_SecurityModeCommand, |
| 258 | &out); |
| 259 | |
| 260 | /* release dynamic allocations attached to out */ |
| 261 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_SecurityModeCommand, &out); |
| 262 | |
| 263 | return msg; |
| 264 | } |
| 265 | |
Neels Hofmeyr | 7e760acc | 2016-04-19 01:41:17 +0200 | [diff] [blame] | 266 | /*! \brief generate RANAP SECURITY MODE COMPLETE message */ |
Neels Hofmeyr | a9f5566 | 2016-04-19 01:21:41 +0200 | [diff] [blame] | 267 | struct msgb *ranap_new_msg_sec_mod_compl( |
| 268 | RANAP_ChosenIntegrityProtectionAlgorithm_t chosen_ip_alg, |
| 269 | RANAP_ChosenEncryptionAlgorithm_t chosen_enc_alg) |
| 270 | { |
| 271 | RANAP_SecurityModeCompleteIEs_t ies; |
| 272 | RANAP_SecurityModeComplete_t out; |
| 273 | struct msgb *msg; |
| 274 | int i, rc; |
| 275 | |
| 276 | memset(&ies, 0, sizeof(ies)); |
| 277 | memset(&out, 0, sizeof(out)); |
| 278 | |
| 279 | ies.presenceMask = SECURITYMODECOMPLETEIES_RANAP_CHOSENENCRYPTIONALGORITHM_PRESENT; |
| 280 | ies.chosenIntegrityProtectionAlgorithm = chosen_ip_alg; |
| 281 | ies.chosenEncryptionAlgorithm = chosen_enc_alg; |
| 282 | |
| 283 | /* ies -> out */ |
| 284 | rc = ranap_encode_securitymodecompleteies(&out, &ies); |
| 285 | |
| 286 | /* out -> msg */ |
| 287 | msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_SecurityModeControl, |
| 288 | RANAP_Criticality_reject, |
| 289 | &asn_DEF_RANAP_SecurityModeComplete, |
| 290 | &out); |
| 291 | |
| 292 | /* release dynamic allocations attached to out */ |
| 293 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_SecurityModeComplete, &out); |
| 294 | |
| 295 | return msg; |
| 296 | } |
| 297 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 298 | /*! \brief generate RANAP COMMON ID message */ |
| 299 | struct msgb *ranap_new_msg_common_id(const char *imsi) |
| 300 | { |
| 301 | RANAP_CommonID_IEs_t ies; |
| 302 | RANAP_CommonID_t out; |
| 303 | struct msgb *msg; |
| 304 | int rc; |
| 305 | |
| 306 | memset(&ies, 0, sizeof(ies)); |
| 307 | memset(&out, 0, sizeof(out)); |
| 308 | |
| 309 | if (imsi) { |
| 310 | uint8_t *imsi_buf = CALLOC(1, 16); |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 311 | rc = ranap_imsi_encode(imsi_buf, 16, imsi); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 312 | ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_iMSI; |
| 313 | ies.permanentNAS_UE_ID.choice.iMSI.buf = imsi_buf; |
| 314 | ies.permanentNAS_UE_ID.choice.iMSI.size = rc; |
| 315 | } else |
| 316 | ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_NOTHING; |
| 317 | |
| 318 | /* ies -> out */ |
| 319 | rc = ranap_encode_commonid_ies(&out, &ies); |
| 320 | /* release dynamic allocations attached to ies */ |
| 321 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, &ies.permanentNAS_UE_ID); |
| 322 | if (rc < 0) |
| 323 | return NULL; |
| 324 | |
| 325 | /* out -> msg */ |
| 326 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_CommonID, |
| 327 | RANAP_Criticality_ignore, |
| 328 | &asn_DEF_RANAP_CommonID, |
| 329 | &out); |
| 330 | |
| 331 | /* release dynamic allocations attached to out */ |
| 332 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_CommonID, &out); |
| 333 | |
| 334 | return msg; |
| 335 | } |
| 336 | |
| 337 | /*! \brief generate RANAP IU RELEASE COMMAND message */ |
| 338 | struct msgb *ranap_new_msg_iu_rel_cmd(const RANAP_Cause_t *cause_in) |
| 339 | { |
| 340 | RANAP_Iu_ReleaseCommandIEs_t ies; |
| 341 | RANAP_Iu_ReleaseCommand_t out; |
| 342 | struct msgb *msg; |
| 343 | int rc; |
| 344 | |
| 345 | memset(&ies, 0, sizeof(ies)); |
| 346 | memset(&out, 0, sizeof(out)); |
| 347 | |
| 348 | memcpy(&ies.cause, cause_in, sizeof(ies.cause)); |
| 349 | |
| 350 | /* ies -> out */ |
| 351 | rc = ranap_encode_iu_releasecommandies(&out, &ies); |
| 352 | if (rc < 0) |
| 353 | return NULL; |
| 354 | |
| 355 | /* out -> msg */ |
| 356 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_Release, |
| 357 | RANAP_Criticality_reject, |
| 358 | &asn_DEF_RANAP_Iu_ReleaseCommand, |
| 359 | &out); |
| 360 | |
| 361 | /* release dynamic allocations attached to out */ |
| 362 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseCommand, &out); |
| 363 | |
| 364 | return msg; |
| 365 | } |
| 366 | |
Neels Hofmeyr | f6e16b7 | 2016-04-19 02:32:05 +0200 | [diff] [blame] | 367 | /*! \brief generate RAPAP IU RELEASE COMPLETE message */ |
| 368 | struct msgb *ranap_new_msg_iu_rel_compl(void) |
| 369 | { |
| 370 | RANAP_Iu_ReleaseCompleteIEs_t ies; |
| 371 | RANAP_Iu_ReleaseComplete_t out; |
| 372 | struct msgb *msg; |
| 373 | int rc; |
| 374 | |
| 375 | memset(&ies, 0, sizeof(ies)); |
| 376 | memset(&out, 0, sizeof(out)); |
| 377 | |
| 378 | /* ies -> out */ |
| 379 | rc = ranap_encode_iu_releasecompleteies(&out, &ies); |
| 380 | if (rc < 0) |
| 381 | return NULL; |
| 382 | |
| 383 | /* out -> msg */ |
| 384 | msg = ranap_generate_successful_outcome(RANAP_ProcedureCode_id_Iu_Release, |
| 385 | RANAP_Criticality_reject, |
| 386 | &asn_DEF_RANAP_Iu_ReleaseComplete, |
| 387 | &out); |
| 388 | |
| 389 | /* release dynamic allocations attached to out */ |
| 390 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseComplete, &out); |
| 391 | |
| 392 | return msg; |
| 393 | } |
| 394 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 395 | /*! \brief generate RANAP PAGING COMMAND message */ |
| 396 | struct msgb *ranap_new_msg_paging_cmd(const char *imsi, const uint32_t *tmsi, int is_ps, uint32_t cause) |
| 397 | { |
| 398 | RANAP_PagingIEs_t ies; |
| 399 | RANAP_Paging_t out; |
| 400 | struct msgb *msg; |
| 401 | uint8_t *imsi_buf = CALLOC(1, 16); |
| 402 | int rc; |
| 403 | |
| 404 | memset(&ies, 0, sizeof(ies)); |
| 405 | memset(&out, 0, sizeof(out)); |
| 406 | |
| 407 | /* put together the 'ies' */ |
| 408 | if (is_ps) |
| 409 | ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_ps_domain; |
| 410 | else |
| 411 | ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_cs_domain; |
| 412 | |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 413 | rc = ranap_imsi_encode(imsi_buf, 16, imsi); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 414 | ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_iMSI; |
| 415 | ies.permanentNAS_UE_ID.choice.iMSI.buf = imsi_buf; |
| 416 | ies.permanentNAS_UE_ID.choice.iMSI.size = rc; |
| 417 | |
| 418 | if (tmsi) { |
| 419 | uint32_t *tmsi_buf = CALLOC(1, sizeof(*tmsi_buf)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 420 | ies.presenceMask |= PAGINGIES_RANAP_TEMPORARYUE_ID_PRESENT; |
| 421 | if (is_ps) { |
| 422 | ies.temporaryUE_ID.present = RANAP_TemporaryUE_ID_PR_p_TMSI; |
Daniel Willmann | a9cf70f | 2016-05-04 13:50:43 +0200 | [diff] [blame] | 423 | asn1_u32_to_str(&ies.temporaryUE_ID.choice.tMSI, tmsi_buf, *tmsi); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 424 | } else { |
| 425 | ies.temporaryUE_ID.present = RANAP_TemporaryUE_ID_PR_tMSI; |
Daniel Willmann | a9cf70f | 2016-05-04 13:50:43 +0200 | [diff] [blame] | 426 | asn1_u32_to_str(&ies.temporaryUE_ID.choice.p_TMSI, tmsi_buf, *tmsi); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | if (cause) { |
| 431 | ies.presenceMask |= PAGINGIES_RANAP_PAGINGCAUSE_PRESENT; |
| 432 | ies.pagingCause = cause; |
| 433 | } |
| 434 | |
| 435 | /* ies -> out */ |
| 436 | rc = ranap_encode_pagingies(&out, &ies); |
| 437 | /* release dynamic allocation attached to ies */ |
| 438 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_PermanentNAS_UE_ID, &ies.permanentNAS_UE_ID); |
| 439 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_TemporaryUE_ID, &ies.temporaryUE_ID); |
| 440 | if (rc < 0) |
| 441 | return NULL; |
| 442 | |
| 443 | /* out -> msg */ |
| 444 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Paging, |
| 445 | RANAP_Criticality_reject, |
| 446 | &asn_DEF_RANAP_Paging, |
| 447 | &out); |
| 448 | |
| 449 | /* release dynamic allocations attached to out */ |
| 450 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Paging, &out); |
| 451 | |
| 452 | return msg; |
| 453 | } |
| 454 | |
| 455 | static RANAP_SDU_ErrorRatio_t *new_sdu_error_ratio(long mantissa, long exponent) |
| 456 | { |
| 457 | RANAP_SDU_ErrorRatio_t *err = CALLOC(1, sizeof(*err)); |
| 458 | |
| 459 | err->mantissa = mantissa; |
| 460 | err->exponent = exponent; |
| 461 | |
| 462 | return err; |
| 463 | } |
| 464 | |
| 465 | |
| 466 | static RANAP_SDU_FormatInformationParameterItem_t * |
| 467 | new_format_info_pars(long sdu_size) |
| 468 | { |
| 469 | RANAP_SDU_FormatInformationParameterItem_t *fmti = CALLOC(1, sizeof(*fmti)); |
| 470 | fmti->subflowSDU_Size = new_long(sdu_size); |
| 471 | return fmti; |
| 472 | } |
| 473 | |
| 474 | enum sdu_par_profile { |
| 475 | SDUPAR_P_VOICE0, |
| 476 | SDUPAR_P_VOICE1, |
| 477 | SDUPAR_P_VOICE2, |
| 478 | SDUPAR_P_DATA, |
| 479 | }; |
| 480 | |
| 481 | /* See Chapter 5 of TS 26.102 */ |
| 482 | static RANAP_SDU_ParameterItem_t *new_sdu_par_item(enum sdu_par_profile profile) |
| 483 | { |
| 484 | RANAP_SDU_ParameterItem_t *sdui = CALLOC(1, sizeof(*sdui)); |
| 485 | RANAP_SDU_FormatInformationParameters_t *fmtip = CALLOC(1, sizeof(*fmtip)); |
| 486 | RANAP_SDU_FormatInformationParameterItem_t *fmti; |
| 487 | |
| 488 | switch (profile) { |
| 489 | case SDUPAR_P_VOICE0: |
| 490 | sdui->sDU_ErrorRatio = new_sdu_error_ratio(1, 5); |
| 491 | sdui->residualBitErrorRatio.mantissa = 1; |
| 492 | sdui->residualBitErrorRatio.exponent = 6; |
| 493 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_yes; |
| 494 | sdui->sDU_FormatInformationParameters = fmtip; |
| 495 | fmti = new_format_info_pars(81); |
| 496 | ASN_SEQUENCE_ADD(fmtip, fmti); |
| 497 | fmti = new_format_info_pars(39); |
| 498 | ASN_SEQUENCE_ADD(fmtip, fmti); |
| 499 | /* FIXME: could be 10 SDU descriptors for AMR! */ |
| 500 | break; |
| 501 | case SDUPAR_P_VOICE1: |
| 502 | sdui->residualBitErrorRatio.mantissa = 1; |
| 503 | sdui->residualBitErrorRatio.exponent = 3; |
| 504 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no_error_detection_consideration; |
| 505 | sdui->sDU_FormatInformationParameters = fmtip; |
| 506 | fmti = new_format_info_pars(103); |
| 507 | ASN_SEQUENCE_ADD(fmtip, fmti); |
| 508 | fmti = new_format_info_pars(0); |
| 509 | ASN_SEQUENCE_ADD(fmtip, fmti); |
| 510 | /* FIXME: could be 10 SDU descriptors for AMR! */ |
| 511 | break; |
| 512 | case SDUPAR_P_VOICE2: |
| 513 | sdui->residualBitErrorRatio.mantissa = 5; |
| 514 | sdui->residualBitErrorRatio.exponent = 3; |
| 515 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no_error_detection_consideration; |
| 516 | sdui->sDU_FormatInformationParameters = fmtip; |
| 517 | fmti = new_format_info_pars(60); |
| 518 | ASN_SEQUENCE_ADD(fmtip, fmti); |
| 519 | fmti = new_format_info_pars(0); |
| 520 | ASN_SEQUENCE_ADD(fmtip, fmti); |
| 521 | /* FIXME: could be 10 SDU descriptors for AMR! */ |
| 522 | break; |
| 523 | case SDUPAR_P_DATA: |
| 524 | sdui->sDU_ErrorRatio = new_sdu_error_ratio(1, 4); |
| 525 | sdui->residualBitErrorRatio.mantissa = 1; |
| 526 | sdui->residualBitErrorRatio.exponent = 5; |
| 527 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no; |
| 528 | FREEMEM(fmtip); |
| 529 | break; |
| 530 | } |
| 531 | |
| 532 | return sdui; |
| 533 | } |
| 534 | |
| 535 | static RANAP_AllocationOrRetentionPriority_t * |
| 536 | new_alloc_ret_prio(RANAP_PriorityLevel_t level, int capability, int vulnerability, |
| 537 | int queueing_allowed) |
| 538 | { |
| 539 | RANAP_AllocationOrRetentionPriority_t *arp = CALLOC(1, sizeof(*arp)); |
| 540 | |
| 541 | arp->priorityLevel = level; |
| 542 | |
| 543 | if (capability) |
| 544 | arp->pre_emptionCapability = RANAP_Pre_emptionCapability_may_trigger_pre_emption; |
| 545 | else |
| 546 | arp->pre_emptionCapability = RANAP_Pre_emptionCapability_shall_not_trigger_pre_emption; |
| 547 | |
| 548 | if (vulnerability) |
| 549 | arp->pre_emptionVulnerability = RANAP_Pre_emptionVulnerability_pre_emptable; |
| 550 | else |
| 551 | arp->pre_emptionVulnerability = RANAP_Pre_emptionVulnerability_not_pre_emptable; |
| 552 | |
| 553 | if (queueing_allowed) |
| 554 | arp->queuingAllowed = RANAP_QueuingAllowed_queueing_allowed; |
| 555 | else |
| 556 | arp->queuingAllowed = RANAP_QueuingAllowed_queueing_not_allowed; |
| 557 | |
| 558 | return arp; |
| 559 | } |
| 560 | |
| 561 | /* See Chapter 5 of TS 26.102 */ |
Neels Hofmeyr | 8e29b23 | 2017-01-23 16:36:11 +0100 | [diff] [blame] | 562 | static RANAP_RAB_Parameters_t *new_rab_par_voice(long bitrate_guaranteed, |
| 563 | long bitrate_max) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 564 | { |
| 565 | RANAP_RAB_Parameters_t *rab = CALLOC(1, sizeof(*rab)); |
| 566 | RANAP_SDU_ParameterItem_t *sdui; |
| 567 | |
| 568 | rab->trafficClass = RANAP_TrafficClass_conversational; |
| 569 | rab->rAB_AsymmetryIndicator = RANAP_RAB_AsymmetryIndicator_symmetric_bidirectional; |
| 570 | |
Neels Hofmeyr | 8e29b23 | 2017-01-23 16:36:11 +0100 | [diff] [blame] | 571 | ASN_SEQUENCE_ADD(&rab->maxBitrate.list, new_long(bitrate_max)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 572 | rab->guaranteedBitRate = CALLOC(1, sizeof(*rab->guaranteedBitRate)); |
Neels Hofmeyr | 8e29b23 | 2017-01-23 16:36:11 +0100 | [diff] [blame] | 573 | ASN_SEQUENCE_ADD(rab->guaranteedBitRate, new_long(bitrate_guaranteed)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 574 | rab->deliveryOrder = RANAP_DeliveryOrder_delivery_order_requested; |
| 575 | rab->maxSDU_Size = 244; |
| 576 | |
| 577 | sdui = new_sdu_par_item(SDUPAR_P_VOICE0); |
| 578 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
| 579 | sdui = new_sdu_par_item(SDUPAR_P_VOICE1); |
| 580 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
| 581 | sdui = new_sdu_par_item(SDUPAR_P_VOICE2); |
| 582 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
| 583 | |
| 584 | rab->transferDelay = new_long(80); |
| 585 | rab->allocationOrRetentionPriority = new_alloc_ret_prio(RANAP_PriorityLevel_no_priority, 0, 1, 0); |
| 586 | |
| 587 | rab->sourceStatisticsDescriptor = new_long(RANAP_SourceStatisticsDescriptor_speech); |
| 588 | |
| 589 | return rab; |
| 590 | } |
| 591 | |
Neels Hofmeyr | ad14ff9 | 2017-01-23 15:06:40 +0100 | [diff] [blame] | 592 | static RANAP_NAS_SynchronisationIndicator_t *new_rab_nas_sync_ind(int val) |
| 593 | { |
| 594 | uint8_t val_buf = (val / 10) << 4; |
| 595 | RANAP_NAS_SynchronisationIndicator_t *nsi = CALLOC(1, sizeof(*nsi)); |
| 596 | BIT_STRING_fromBuf(nsi, &val_buf, 4); |
| 597 | return nsi; |
| 598 | } |
| 599 | |
Harald Welte | 05ac677 | 2015-12-29 19:09:52 +0100 | [diff] [blame] | 600 | static RANAP_RAB_Parameters_t *new_rab_par_data(uint32_t dl_max_bitrate, uint32_t ul_max_bitrate) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 601 | { |
| 602 | RANAP_RAB_Parameters_t *rab = CALLOC(1, sizeof(*rab)); |
| 603 | RANAP_SDU_ParameterItem_t *sdui; |
| 604 | |
| 605 | rab->trafficClass = RANAP_TrafficClass_background; |
| 606 | rab->rAB_AsymmetryIndicator = RANAP_RAB_AsymmetryIndicator_asymmetric_bidirectional; |
| 607 | |
Harald Welte | 05ac677 | 2015-12-29 19:09:52 +0100 | [diff] [blame] | 608 | ASN_SEQUENCE_ADD(&rab->maxBitrate.list, new_long(dl_max_bitrate)); |
| 609 | ASN_SEQUENCE_ADD(&rab->maxBitrate.list, new_long(ul_max_bitrate)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 610 | rab->deliveryOrder = RANAP_DeliveryOrder_delivery_order_requested; |
| 611 | rab->maxSDU_Size = 8000; |
| 612 | |
| 613 | sdui = new_sdu_par_item(SDUPAR_P_DATA); |
| 614 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
| 615 | |
| 616 | rab->allocationOrRetentionPriority = new_alloc_ret_prio(RANAP_PriorityLevel_no_priority, 0, 0, 0); |
| 617 | |
Harald Welte | bb289e3 | 2016-05-01 15:20:56 +0200 | [diff] [blame] | 618 | RANAP_ProtocolExtensionField_t *pxf = CALLOC(1, sizeof(*pxf)); |
| 619 | pxf->id = RANAP_ProtocolIE_ID_id_RAB_Parameter_ExtendedMaxBitrateList; |
| 620 | pxf->criticality = RANAP_Criticality_ignore; |
| 621 | |
| 622 | RANAP_RAB_Parameter_ExtendedMaxBitrateList_t *rab_mbrlist = CALLOC(1, sizeof(*rab_mbrlist)); |
| 623 | RANAP_ExtendedMaxBitrate_t *xmbr = CALLOC(1, sizeof(*xmbr)); |
| 624 | *xmbr = 42000000; |
| 625 | ASN_SEQUENCE_ADD(&rab_mbrlist->list, xmbr); |
| 626 | |
| 627 | ANY_fromType_aper(&pxf->value, &asn_DEF_RANAP_RAB_Parameter_ExtendedMaxBitrateList, rab_mbrlist); |
| 628 | |
| 629 | ASN_STRUCT_FREE(asn_DEF_RANAP_RAB_Parameter_ExtendedMaxBitrateList, rab_mbrlist); |
| 630 | |
| 631 | rab->iE_Extensions = CALLOC(1, sizeof(*rab->iE_Extensions)); |
| 632 | ASN_SEQUENCE_ADD(&rab->iE_Extensions->list, pxf); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 633 | |
| 634 | return rab; |
| 635 | } |
| 636 | |
Neels Hofmeyr | edf1367 | 2016-04-23 13:50:46 +0200 | [diff] [blame] | 637 | static void new_transp_layer_addr(BIT_STRING_t *out, uint32_t ip, bool use_x213_nsap) |
Harald Welte | bfe49a2 | 2015-12-28 13:14:52 +0100 | [diff] [blame] | 638 | { |
| 639 | uint8_t *buf; |
| 640 | unsigned int len; |
| 641 | |
| 642 | if (use_x213_nsap) { |
Neels Hofmeyr | 135bc06 | 2017-01-23 16:49:20 +0100 | [diff] [blame] | 643 | len = 160/8; |
Harald Welte | bfe49a2 | 2015-12-28 13:14:52 +0100 | [diff] [blame] | 644 | buf = CALLOC(len, sizeof(uint8_t)); |
| 645 | buf[0] = 0x35; /* AFI For IANA ICP */ |
| 646 | buf[1] = 0x00; /* See A.5.2.1.2.7 of X.213 */ |
| 647 | buf[2] = 0x01; |
| 648 | *(uint32_t *)&buf[3] = ntohl(ip); |
| 649 | } else { |
| 650 | len = 4; |
| 651 | buf = CALLOC(len, sizeof(uint8_t)); |
Neels Hofmeyr | f098c7a | 2016-04-23 14:51:03 +0200 | [diff] [blame] | 652 | *(uint32_t *)buf = ntohl(ip); |
Harald Welte | bfe49a2 | 2015-12-28 13:14:52 +0100 | [diff] [blame] | 653 | } |
| 654 | out->buf = buf; |
| 655 | out->size = len; |
| 656 | out->bits_unused = 0; |
| 657 | } |
| 658 | |
Neels Hofmeyr | f6673b7 | 2016-09-08 15:39:18 +0200 | [diff] [blame] | 659 | static RANAP_TransportLayerInformation_t *new_transp_info_rtp(uint32_t ip, uint16_t port, |
| 660 | bool use_x213_nsap) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 661 | { |
| 662 | RANAP_TransportLayerInformation_t *tli = CALLOC(1, sizeof(*tli)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 663 | uint8_t binding_id[4]; |
| 664 | |
| 665 | binding_id[0] = port >> 8; |
| 666 | binding_id[1] = port & 0xff; |
| 667 | binding_id[2] = binding_id[3] = 0; |
| 668 | |
Neels Hofmeyr | f6673b7 | 2016-09-08 15:39:18 +0200 | [diff] [blame] | 669 | new_transp_layer_addr(&tli->transportLayerAddress, ip, use_x213_nsap); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 670 | tli->iuTransportAssociation.present = RANAP_IuTransportAssociation_PR_bindingID; |
| 671 | OCTET_STRING_fromBuf(&tli->iuTransportAssociation.choice.bindingID, |
| 672 | (const char *) binding_id, sizeof(binding_id)); |
| 673 | |
| 674 | return tli; |
| 675 | } |
| 676 | |
Neels Hofmeyr | edf1367 | 2016-04-23 13:50:46 +0200 | [diff] [blame] | 677 | static RANAP_TransportLayerInformation_t *new_transp_info_gtp(uint32_t ip, uint32_t tei, |
| 678 | bool use_x213_nsap) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 679 | { |
| 680 | RANAP_TransportLayerInformation_t *tli = CALLOC(1, sizeof(*tli)); |
Harald Welte | 01de8d7 | 2015-12-29 19:10:48 +0100 | [diff] [blame] | 681 | uint32_t binding_buf = htonl(tei); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 682 | |
Neels Hofmeyr | edf1367 | 2016-04-23 13:50:46 +0200 | [diff] [blame] | 683 | new_transp_layer_addr(&tli->transportLayerAddress, ip, use_x213_nsap); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 684 | tli->iuTransportAssociation.present = RANAP_IuTransportAssociation_PR_gTP_TEI; |
Harald Welte | 01de8d7 | 2015-12-29 19:10:48 +0100 | [diff] [blame] | 685 | OCTET_STRING_fromBuf(&tli->iuTransportAssociation.choice.gTP_TEI, |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 686 | (const char *) &binding_buf, sizeof(binding_buf)); |
| 687 | |
| 688 | return tli; |
| 689 | } |
| 690 | |
| 691 | static RANAP_UserPlaneInformation_t *new_upi(long mode, uint8_t mode_versions) |
| 692 | { |
| 693 | RANAP_UserPlaneInformation_t *upi = CALLOC(1, sizeof(*upi)); |
| 694 | uint16_t *buf = CALLOC(1, sizeof(*buf)); |
| 695 | |
Daniel Willmann | 49f99cd | 2016-01-26 09:37:22 +0100 | [diff] [blame] | 696 | *buf = ntohs(mode_versions); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 697 | |
| 698 | upi->userPlaneMode = mode; |
Harald Welte | f9c9aa5 | 2015-12-24 15:39:00 +0100 | [diff] [blame] | 699 | upi->uP_ModeVersions.buf = (uint8_t *) buf; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 700 | upi->uP_ModeVersions.size = sizeof(*buf); |
| 701 | upi->uP_ModeVersions.bits_unused = 0; |
| 702 | |
| 703 | return upi; |
| 704 | } |
| 705 | |
| 706 | |
| 707 | static void assign_new_ra_id(RANAP_RAB_ID_t *id, uint8_t rab_id) |
| 708 | { |
| 709 | uint8_t *buf = CALLOC(1, sizeof(*buf)); |
Harald Welte | 0a3eafe | 2015-12-19 02:38:09 +0100 | [diff] [blame] | 710 | *buf = rab_id; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 711 | |
| 712 | id->buf = buf; |
| 713 | id->size = 1; |
| 714 | id->bits_unused = 0; |
| 715 | } |
| 716 | |
Neels Hofmeyr | 74b0565 | 2016-09-09 01:25:22 +0200 | [diff] [blame] | 717 | /*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for CS (voice). |
| 718 | * See 3GPP TS 25.413 8.2. |
Neels Hofmeyr | e90f13e | 2017-11-20 17:18:03 +0100 | [diff] [blame] | 719 | * RAB ID: 3GPP TS 25.413 9.2.1.2. |
| 720 | * \param rtp_ip MGW's RTP IPv4 address in *network* byte order. |
Neels Hofmeyr | 74b0565 | 2016-09-09 01:25:22 +0200 | [diff] [blame] | 721 | */ |
Neels Hofmeyr | f6673b7 | 2016-09-08 15:39:18 +0200 | [diff] [blame] | 722 | struct msgb *ranap_new_msg_rab_assign_voice(uint8_t rab_id, uint32_t rtp_ip, |
| 723 | uint16_t rtp_port, |
| 724 | bool use_x213_nsap) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 725 | { |
| 726 | RANAP_ProtocolIE_FieldPair_t *pair; |
| 727 | RANAP_RAB_AssignmentRequestIEs_t ies; |
| 728 | RANAP_RAB_AssignmentRequest_t out; |
| 729 | struct msgb *msg; |
| 730 | int rc; |
| 731 | |
| 732 | memset(&ies, 0, sizeof(ies)); |
| 733 | memset(&out, 0, sizeof(out)); |
| 734 | |
| 735 | /* only assingnment is present, no release */ |
| 736 | ies.presenceMask = RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_SETUPORMODIFYLIST_PRESENT; |
| 737 | |
| 738 | /* put together the 'First' part */ |
| 739 | RANAP_RAB_SetupOrModifyItemFirst_t first; |
| 740 | memset(&first, 0, sizeof(first)); |
| 741 | assign_new_ra_id(&first.rAB_ID, rab_id); |
Neels Hofmeyr | ad14ff9 | 2017-01-23 15:06:40 +0100 | [diff] [blame] | 742 | first.nAS_SynchronisationIndicator = new_rab_nas_sync_ind(60); |
Neels Hofmeyr | 8e29b23 | 2017-01-23 16:36:11 +0100 | [diff] [blame] | 743 | first.rAB_Parameters = new_rab_par_voice(6700, 12200); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 744 | first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_support_mode_for_predefined_SDU_sizes, 1); /* 2? */ |
Neels Hofmeyr | f6673b7 | 2016-09-08 15:39:18 +0200 | [diff] [blame] | 745 | first.transportLayerInformation = new_transp_info_rtp(rtp_ip, rtp_port, |
| 746 | use_x213_nsap); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 747 | |
| 748 | /* put together the 'Second' part */ |
| 749 | RANAP_RAB_SetupOrModifyItemSecond_t second; |
| 750 | memset(&second, 0, sizeof(second)); |
| 751 | |
| 752 | /* Build an IE Pair out of first and second part: |
| 753 | * (first, second) -> pair */ |
| 754 | pair = ranap_new_ie_pair(RANAP_ProtocolIE_ID_id_RAB_SetupOrModifyItem, |
| 755 | RANAP_Criticality_reject, |
| 756 | &asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first, |
| 757 | RANAP_Criticality_ignore, |
| 758 | &asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second); |
| 759 | |
| 760 | /* the pair has been made, we can release any of its elements */ |
| 761 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first); |
| 762 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second); |
| 763 | |
Harald Welte | b7f67c4 | 2015-12-19 02:36:52 +0100 | [diff] [blame] | 764 | RANAP_ProtocolIE_ContainerPair_t *container_pair = CALLOC(1, sizeof(*container_pair)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 765 | /* Add the pair to the list of IEs of the RAB ass.req */ |
Harald Welte | b7f67c4 | 2015-12-19 02:36:52 +0100 | [diff] [blame] | 766 | ASN_SEQUENCE_ADD(container_pair, pair); |
| 767 | ASN_SEQUENCE_ADD(&ies.raB_SetupOrModifyList.list, container_pair); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 768 | |
| 769 | /* encode the IEs into the actual assignment request: |
| 770 | * ies -> out */ |
| 771 | rc = ranap_encode_rab_assignmentrequesties(&out, &ies); |
| 772 | /* 'out' has been generated, we can now release the input */ |
| 773 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyList, |
| 774 | &ies.raB_SetupOrModifyList); |
| 775 | if (rc < 0) |
| 776 | return NULL; |
| 777 | |
| 778 | /* generate an Initiating Mesasage: out -> msg */ |
| 779 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_Assignment, |
| 780 | RANAP_Criticality_reject, |
| 781 | &asn_DEF_RANAP_RAB_AssignmentRequest, &out); |
| 782 | |
| 783 | /* 'msg' has been generated, we cann now release the input 'out' */ |
| 784 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_AssignmentRequest, &out); |
| 785 | |
| 786 | return msg; |
| 787 | } |
| 788 | |
Neels Hofmeyr | e90f13e | 2017-11-20 17:18:03 +0100 | [diff] [blame] | 789 | /*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for PS (data) |
| 790 | * \param gtp_ip SGSN's GTP IPv4 address in *network* byte order. */ |
Neels Hofmeyr | edf1367 | 2016-04-23 13:50:46 +0200 | [diff] [blame] | 791 | struct msgb *ranap_new_msg_rab_assign_data(uint8_t rab_id, uint32_t gtp_ip, |
| 792 | uint32_t gtp_tei, bool use_x213_nsap) |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 793 | { |
| 794 | RANAP_ProtocolIE_FieldPair_t *pair; |
| 795 | RANAP_RAB_AssignmentRequestIEs_t ies; |
| 796 | RANAP_RAB_AssignmentRequest_t out; |
| 797 | RANAP_DataVolumeReportingIndication_t *dat_vol_ind; |
| 798 | struct msgb *msg; |
| 799 | int rc; |
| 800 | |
| 801 | memset(&ies, 0, sizeof(ies)); |
| 802 | memset(&out, 0, sizeof(out)); |
| 803 | |
| 804 | /* only assingnment is present, no release */ |
| 805 | ies.presenceMask = RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_SETUPORMODIFYLIST_PRESENT; |
| 806 | |
| 807 | /* put together the 'First' part */ |
| 808 | RANAP_RAB_SetupOrModifyItemFirst_t first; |
| 809 | memset(&first, 0, sizeof(first)); |
| 810 | assign_new_ra_id(&first.rAB_ID, rab_id); |
| 811 | //first.nAS_SynchronisationIndicator = FIXME; |
Harald Welte | 05ac677 | 2015-12-29 19:09:52 +0100 | [diff] [blame] | 812 | |
| 813 | first.rAB_Parameters = new_rab_par_data(1600000, 800000); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 814 | first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_transparent_mode, 1); |
Neels Hofmeyr | edf1367 | 2016-04-23 13:50:46 +0200 | [diff] [blame] | 815 | first.transportLayerInformation = new_transp_info_gtp(gtp_ip, gtp_tei, |
| 816 | use_x213_nsap); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 817 | |
| 818 | /* put together the 'Second' part */ |
| 819 | RANAP_RAB_SetupOrModifyItemSecond_t second; |
| 820 | memset(&second, 0, sizeof(second)); |
| 821 | second.pDP_TypeInformation = CALLOC(1, sizeof(*second.pDP_TypeInformation)); |
| 822 | ASN_SEQUENCE_ADD(second.pDP_TypeInformation, new_long(RANAP_PDP_Type_ipv4)); |
| 823 | dat_vol_ind = CALLOC(1, sizeof(*dat_vol_ind)); |
| 824 | *dat_vol_ind = RANAP_DataVolumeReportingIndication_do_not_report; |
| 825 | second.dataVolumeReportingIndication = dat_vol_ind; |
| 826 | second.dl_GTP_PDU_SequenceNumber = new_long(0); |
| 827 | second.ul_GTP_PDU_SequenceNumber = new_long(0); |
| 828 | |
| 829 | /* Build an IE Pair out of first and second part: |
| 830 | * (first, second) -> pair */ |
| 831 | pair = ranap_new_ie_pair(RANAP_ProtocolIE_ID_id_RAB_SetupOrModifyItem, |
| 832 | RANAP_Criticality_reject, |
| 833 | &asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, |
| 834 | &first, RANAP_Criticality_ignore, |
| 835 | &asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, |
| 836 | &second); |
| 837 | |
| 838 | /* the pair has been made, we can release any of its elements */ |
| 839 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first); |
| 840 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second); |
| 841 | |
Harald Welte | b7f67c4 | 2015-12-19 02:36:52 +0100 | [diff] [blame] | 842 | RANAP_ProtocolIE_ContainerPair_t *container_pair = CALLOC(1, sizeof(*container_pair)); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 843 | /* Add the pair to the list of IEs of the RAB ass.req */ |
Neels Hofmeyr | 9246cc9 | 2016-04-25 14:47:26 +0200 | [diff] [blame] | 844 | ASN_SEQUENCE_ADD(&container_pair->list, pair); |
Harald Welte | b7f67c4 | 2015-12-19 02:36:52 +0100 | [diff] [blame] | 845 | /* Add the pair to the list of IEs of the RAB ass.req */ |
| 846 | ASN_SEQUENCE_ADD(&ies.raB_SetupOrModifyList.list, container_pair); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 847 | |
| 848 | /* encode the IEs into the actual assignment request: |
| 849 | * ies -> out */ |
| 850 | rc = ranap_encode_rab_assignmentrequesties(&out, &ies); |
| 851 | /* 'out' has been generated, we can now release the input */ |
| 852 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyList, |
| 853 | &ies.raB_SetupOrModifyList); |
| 854 | if (rc < 0) |
| 855 | return NULL; |
| 856 | |
| 857 | /* generate an Initiating Mesasage: out -> msg */ |
| 858 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_Assignment, |
| 859 | RANAP_Criticality_reject, |
| 860 | &asn_DEF_RANAP_RAB_AssignmentRequest, &out); |
| 861 | |
| 862 | /* 'msg' has been generated, we cann now release the input 'out' */ |
| 863 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_AssignmentRequest, &out); |
| 864 | |
| 865 | return msg; |
| 866 | } |
Harald Welte | 37223d8 | 2016-01-01 16:18:55 +0100 | [diff] [blame] | 867 | |
| 868 | struct msgb *ranap_new_msg_iu_rel_req(const RANAP_Cause_t *cause) |
| 869 | { |
| 870 | RANAP_Iu_ReleaseRequestIEs_t ies; |
| 871 | RANAP_Iu_ReleaseRequest_t out; |
| 872 | struct msgb *msg; |
| 873 | int rc; |
| 874 | |
| 875 | memset(&ies, 0, sizeof(ies)); |
| 876 | memset(&out, 0, sizeof(out)); |
| 877 | |
| 878 | memcpy(&ies.cause, cause, sizeof(ies.cause)); |
| 879 | |
| 880 | rc = ranap_encode_iu_releaserequesties(&out, &ies); |
| 881 | if (rc < 0) |
| 882 | return NULL; |
| 883 | |
| 884 | /* encode the output into the msgb */ |
| 885 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_ReleaseRequest, |
| 886 | RANAP_Criticality_reject, |
| 887 | &asn_DEF_RANAP_Iu_ReleaseRequest, &out); |
| 888 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_Iu_ReleaseRequest, &out); |
| 889 | |
| 890 | return msg; |
| 891 | } |
| 892 | |
| 893 | struct msgb *ranap_new_msg_rab_rel_req(uint8_t rab_id, const RANAP_Cause_t *cause) |
| 894 | { |
| 895 | RANAP_RAB_ReleaseItemIEs_t item_ies; |
| 896 | RANAP_RAB_ReleaseRequestIEs_t ies; |
| 897 | RANAP_RAB_ReleaseRequest_t out; |
| 898 | struct msgb *msg; |
| 899 | int rc; |
| 900 | |
| 901 | memset(&item_ies, 0, sizeof(item_ies)); |
| 902 | memset(&ies, 0, sizeof(ies)); |
| 903 | memset(&out, 0, sizeof(out)); |
| 904 | |
| 905 | /* put together the ReleaseItem */ |
| 906 | assign_new_ra_id(&item_ies.raB_ReleaseItem.rAB_ID, rab_id); |
| 907 | memcpy(&item_ies.raB_ReleaseItem.cause, cause, sizeof(item_ies.raB_ReleaseItem.cause)); |
| 908 | |
| 909 | /* add to the list */ |
| 910 | rc = ranap_encode_rab_releaseitemies(&ies.raB_ReleaseList, &item_ies); |
| 911 | if (rc < 0) |
| 912 | return NULL; |
| 913 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseItem, &item_ies.raB_ReleaseItem); |
| 914 | |
| 915 | /* encoe the list IEs into the output */ |
| 916 | rc = ranap_encode_rab_releaserequesties(&out, &ies); |
| 917 | if (rc < 0) |
| 918 | return NULL; |
| 919 | /* 'out' has been generated, we can release the input */ |
| 920 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseList, &ies.raB_ReleaseList); |
| 921 | |
| 922 | /* encode the output into the msgb */ |
| 923 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_RAB_ReleaseRequest, |
| 924 | RANAP_Criticality_reject, |
| 925 | &asn_DEF_RANAP_RAB_ReleaseRequest, &out); |
| 926 | |
| 927 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseRequest, &out); |
| 928 | |
| 929 | return msg; |
| 930 | } |