Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 1 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 2 | #include "asn1helpers.h" |
| 3 | #include "iu_helpers.h" |
| 4 | |
| 5 | #include "ranap_common.h" |
| 6 | #include "ranap_ies_defs.h" |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 7 | |
| 8 | /* This is just some non-compiling work in progress code to generate the |
| 9 | * minimum set of RANAP messages that the core network side needs to send |
| 10 | * towards the RNC */ |
| 11 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 12 | static long *new_long(long in) |
| 13 | { |
| 14 | long *out = CALLOC(1, sizeof(long)); |
| 15 | *out = in; |
| 16 | return out; |
| 17 | } |
| 18 | |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 19 | int ranap_tx_dt(uint8_t sapi, const uint8_t *nas, unsigned int nas_len) |
| 20 | { |
| 21 | RANAP_DirectTransferIEs_t ies; |
| 22 | RANAP_DirectTransfer_t dt; |
| 23 | struct msgb *msg; |
| 24 | int rc; |
| 25 | |
| 26 | memset(&ies, 0, sizeof(ies)); |
| 27 | |
| 28 | /* only SAPI optional field shall be present for CN->RNC */ |
| 29 | ies.presenceMask = DIRECTTRANSFERIES_RANAP_SAPI_PRESENT; |
| 30 | |
| 31 | if (sapi == 3) |
| 32 | ies.sapi = RANAP_SAPI_sapi_3; |
| 33 | else |
| 34 | ies.sapi = RANAP_SAPI_sapi_0; |
| 35 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 36 | ies.nas_pdu.buf = (uint8_t *) nas; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 37 | ies.nas_pdu.size = nas_len; |
| 38 | |
| 39 | rc = ranap_encode_directtransferies(&dt, &ies); |
| 40 | |
| 41 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_DirectTransfer, |
| 42 | RANAP_Criticality_reject, |
| 43 | &asn_DEF_RANAP_DirectTransfer, |
| 44 | &dt); |
| 45 | /* FIXME: Hand that to RUA or SCCP */ |
| 46 | } |
| 47 | |
| 48 | static const enum RANAP_IntegrityProtectionAlgorithm ip_alg[2] = { |
| 49 | RANAP_IntegrityProtectionAlgorithm_standard_UMTS_integrity_algorithm_UIA1, |
| 50 | RANAP_IntegrityProtectionAlgorithm_standard_UMTS_integrity_algorithm_UIA2, |
| 51 | }; |
| 52 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 53 | static const RANAP_EncryptionAlgorithm_t enc_alg[2] = { |
| 54 | RANAP_EncryptionAlgorithm_standard_UMTS_encryption_algorith_UEA1, |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 55 | RANAP_EncryptionAlgorithm_standard_UMTS_encryption_algorithm_UEA2, |
| 56 | }; |
| 57 | |
| 58 | int ranap_tx_sec_mod_cmd(void) |
| 59 | { |
| 60 | RANAP_SecurityModeCommandIEs_t ies; |
| 61 | RANAP_SecurityModeCommand_t out; |
| 62 | struct msgb *msg; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 63 | int i, rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 64 | |
| 65 | memset(&ies, 0, sizeof(ies)); |
| 66 | |
| 67 | ies.presenceMask = SECURITYMODECOMMANDIES_RANAP_ENCRYPTIONINFORMATION_PRESENT; |
| 68 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 69 | for (i = 0; i < ARRAY_SIZE(ip_alg); i++) { |
| 70 | /* needs to be dynamically allocated, as |
| 71 | * SET_OF_free() will call FREEMEM() on it */ |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 72 | RANAP_IntegrityProtectionAlgorithm_t *alg = CALLOC(1, sizeof(*alg)); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 73 | *alg = ip_alg[i]; |
| 74 | ASN_SEQUENCE_ADD(&ies.integrityProtectionInformation.permittedAlgorithms, alg); |
| 75 | } |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 76 | |
| 77 | ies.integrityProtectionInformation.key; /* FIXME */ |
| 78 | if (0) { |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 79 | for (i = 0; i < ARRAY_SIZE(ip_alg); i++) { |
| 80 | /* needs to be dynamically allocated, as |
| 81 | * SET_OF_free() will call FREEMEM() on it */ |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 82 | RANAP_EncryptionAlgorithm_t *alg = CALLOC(1, sizeof(*alg)); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 83 | *alg = enc_alg[i]; |
| 84 | ASN_SEQUENCE_ADD(&ies.encryptionInformation.permittedAlgorithms, alg); |
| 85 | } |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 86 | ies.encryptionInformation.key; /* FIXME */ |
| 87 | } |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 88 | |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 89 | ies.keyStatus = RANAP_KeyStatus_new; /* FIXME */ |
| 90 | |
| 91 | rc = ranap_encode_securitymodecommandies(&out, &ies); |
| 92 | |
| 93 | asn_sequence_empty(&ies.integrityProtectionInformation.permittedAlgorithms); |
| 94 | asn_sequence_empty(&ies.encryptionInformation.permittedAlgorithms); |
| 95 | |
| 96 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_SecurityModeControl, |
| 97 | RANAP_Criticality_reject, |
| 98 | &asn_DEF_RANAP_SecurityModeCommand, |
| 99 | &out); |
| 100 | } |
| 101 | |
| 102 | int ranap_tx_common_id(const char *imsi) |
| 103 | { |
| 104 | RANAP_CommonID_IEs_t ies; |
| 105 | RANAP_CommonID_t out; |
| 106 | struct msgb *msg; |
| 107 | int rc; |
| 108 | |
| 109 | memset(&ies, 0, sizeof(ies)); |
| 110 | |
| 111 | if (imsi) { |
| 112 | ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_iMSI; |
| 113 | ies.permanentNAS_UE_ID.choice.iMSI; /* FIXME */ |
| 114 | } else |
| 115 | ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_NOTHING; |
| 116 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 117 | rc = ranap_encode_commonid_ies(&out, &ies); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 118 | |
| 119 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_CommonID, |
| 120 | RANAP_Criticality_ignore, |
| 121 | &asn_DEF_RANAP_CommonID, |
| 122 | &out); |
| 123 | } |
| 124 | |
| 125 | int ranap_tx_iu_rel_cmd(RANAP_Cause_t cause) |
| 126 | { |
| 127 | RANAP_Iu_ReleaseCommandIEs_t ies; |
| 128 | RANAP_Iu_ReleaseCommand_t out; |
| 129 | struct msgb *msg; |
| 130 | int rc; |
| 131 | |
| 132 | memset(&ies, 0, sizeof(ies)); |
| 133 | |
| 134 | ies.cause = cause; |
| 135 | |
| 136 | rc = ranap_encode_iu_releasecommandies(&out, &ies); |
| 137 | |
| 138 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Iu_Release, |
| 139 | RANAP_Criticality_reject, |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 140 | &asn_DEF_RANAP_Iu_ReleaseCommand, |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 141 | &out); |
| 142 | } |
| 143 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 144 | int ranap_tx_paging_cmd(const char *imsi, uint32_t *tmsi, int is_ps, uint32_t cause) |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 145 | { |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 146 | RANAP_PagingIEs_t ies; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 147 | RANAP_Paging_t out; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 148 | struct msgb *msg; |
| 149 | uint8_t *imsi_buf = CALLOC(1, 16); |
| 150 | int rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 151 | |
| 152 | memset(&ies, 0, sizeof(ies)); |
| 153 | |
| 154 | if (is_ps) |
| 155 | ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_ps_domain; |
| 156 | else |
| 157 | ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_cs_domain; |
| 158 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 159 | rc = encode_iu_imsi(imsi_buf, 16, imsi); |
| 160 | ies.permanentNAS_UE_ID.present = RANAP_PermanentNAS_UE_ID_PR_iMSI; |
| 161 | ies.permanentNAS_UE_ID.choice.iMSI.buf = imsi_buf; |
| 162 | ies.permanentNAS_UE_ID.choice.iMSI.size = rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 163 | |
| 164 | if (tmsi) { |
| 165 | ies.presenceMask |= PAGINGIES_RANAP_TEMPORARYUE_ID_PRESENT; |
| 166 | if (is_ps) { |
| 167 | ies.temporaryUE_ID.present = RANAP_TemporaryUE_ID_PR_p_TMSI; |
| 168 | ies.temporaryUE_ID.choice.tMSI; |
| 169 | } else { |
| 170 | ies.temporaryUE_ID.present = RANAP_TemporaryUE_ID_PR_tMSI; |
| 171 | ies.temporaryUE_ID.choice.p_TMSI; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (cause) { |
| 176 | ies.presenceMask |= PAGINGIES_RANAP_PAGINGCAUSE_PRESENT; |
| 177 | ies.pagingCause = cause; |
| 178 | } |
| 179 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 180 | rc = ranap_encode_pagingies(&out, &ies); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 181 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 182 | msg = ranap_generate_initiating_message(RANAP_ProcedureCode_id_Paging, |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 183 | RANAP_Criticality_reject, |
| 184 | &asn_DEF_RANAP_Paging, |
| 185 | &out); |
| 186 | } |
| 187 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 188 | static RANAP_SDU_ErrorRatio_t *new_sdu_error_ratio(long mantissa, long exponent) |
| 189 | { |
| 190 | RANAP_SDU_ErrorRatio_t *err = CALLOC(1, sizeof(*err)); |
| 191 | |
| 192 | err->mantissa = mantissa; |
| 193 | err->exponent = exponent; |
| 194 | |
| 195 | return err; |
| 196 | } |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 197 | |
| 198 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 199 | static RANAP_SDU_FormatInformationParameterItem_t * |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 200 | new_format_info_pars(long sdu_size) |
| 201 | { |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 202 | RANAP_SDU_FormatInformationParameterItem_t *fmti = CALLOC(1, sizeof(*fmti)); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 203 | fmti->subflowSDU_Size = new_long(sdu_size); |
| 204 | return fmti; |
| 205 | } |
| 206 | |
| 207 | enum sdu_par_profile { |
| 208 | SDUPAR_P_VOICE0, |
| 209 | SDUPAR_P_VOICE1, |
| 210 | SDUPAR_P_VOICE2, |
| 211 | SDUPAR_P_DATA, |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 212 | }; |
| 213 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 214 | /* See Chapter 5 of TS 26.102 */ |
| 215 | static RANAP_SDU_ParameterItem_t *new_sdu_par_item(enum sdu_par_profile profile) |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 216 | { |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 217 | RANAP_SDU_ParameterItem_t *sdui = CALLOC(1, sizeof(*sdui)); |
| 218 | RANAP_SDU_FormatInformationParameters_t *fmtip = CALLOC(1, sizeof(*fmtip)); |
| 219 | RANAP_SDU_FormatInformationParameterItem_t *fmti; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 220 | |
| 221 | switch (profile) { |
| 222 | case SDUPAR_P_VOICE0: |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 223 | sdui->sDU_ErrorRatio = new_sdu_error_ratio(1, 5); |
| 224 | sdui->residualBitErrorRatio.mantissa = 1; |
| 225 | sdui->residualBitErrorRatio.exponent = 6; |
| 226 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_yes; |
| 227 | sdui->sDU_FormatInformationParameters = fmtip; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 228 | fmti = new_format_info_pars(81); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 229 | ASN_SEQUENCE_ADD(fmtip, fmti); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 230 | fmti = new_format_info_pars(39); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 231 | ASN_SEQUENCE_ADD(fmtip, fmti); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 232 | /* FIXME: could be 10 SDU descriptors for AMR! */ |
| 233 | break; |
| 234 | case SDUPAR_P_VOICE1: |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 235 | sdui->residualBitErrorRatio.mantissa = 1; |
| 236 | sdui->residualBitErrorRatio.exponent = 3; |
| 237 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no_error_detection_consideration; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 238 | fmti = new_format_info_pars(103); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 239 | ASN_SEQUENCE_ADD(fmtip, fmti); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 240 | fmti = new_format_info_pars(0); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 241 | ASN_SEQUENCE_ADD(fmtip, fmti); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 242 | /* FIXME: could be 10 SDU descriptors for AMR! */ |
| 243 | break; |
| 244 | case SDUPAR_P_VOICE2: |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 245 | sdui->residualBitErrorRatio.mantissa = 5; |
| 246 | sdui->residualBitErrorRatio.exponent = 3; |
| 247 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no_error_detection_consideration; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 248 | fmti = new_format_info_pars(60); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 249 | ASN_SEQUENCE_ADD(fmtip, fmti); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 250 | fmti = new_format_info_pars(0); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 251 | ASN_SEQUENCE_ADD(fmtip, fmti); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 252 | /* FIXME: could be 10 SDU descriptors for AMR! */ |
| 253 | break; |
| 254 | case SDUPAR_P_DATA: |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 255 | sdui->sDU_ErrorRatio = new_sdu_error_ratio(1, 4); |
| 256 | sdui->residualBitErrorRatio.mantissa = 1; |
| 257 | sdui->residualBitErrorRatio.exponent = 5; |
| 258 | sdui->deliveryOfErroneousSDU = RANAP_DeliveryOfErroneousSDU_no; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 259 | break; |
| 260 | } |
| 261 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 262 | return sdui; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static RANAP_AllocationOrRetentionPriority_t * |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 266 | new_alloc_ret_prio(RANAP_PriorityLevel_t level, int capability, int vulnerability, |
| 267 | int queueing_allowed) |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 268 | { |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 269 | RANAP_AllocationOrRetentionPriority_t *arp = CALLOC(1, sizeof(*arp)); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 270 | |
| 271 | arp->priorityLevel = level; |
| 272 | |
| 273 | if (capability) |
| 274 | arp->pre_emptionCapability = RANAP_Pre_emptionCapability_may_trigger_pre_emption; |
| 275 | else |
| 276 | arp->pre_emptionCapability = RANAP_Pre_emptionCapability_shall_not_trigger_pre_emption; |
| 277 | |
| 278 | if (vulnerability) |
| 279 | arp->pre_emptionVulnerability = RANAP_Pre_emptionVulnerability_pre_emptable; |
| 280 | else |
| 281 | arp->pre_emptionVulnerability = RANAP_Pre_emptionVulnerability_not_pre_emptable; |
| 282 | |
| 283 | if (queueing_allowed) |
| 284 | arp->queuingAllowed = RANAP_QueuingAllowed_queueing_allowed; |
| 285 | else |
| 286 | arp->queuingAllowed = RANAP_QueuingAllowed_queueing_not_allowed; |
| 287 | |
| 288 | return arp; |
| 289 | } |
| 290 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 291 | /* See Chapter 5 of TS 26.102 */ |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 292 | static RANAP_RAB_Parameters_t *new_rab_par_voice(void) |
| 293 | { |
| 294 | RANAP_RAB_Parameters_t *rab = CALLOC(1, sizeof(*rab)); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 295 | RANAP_SDU_ParameterItem_t *sdui; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 296 | |
| 297 | rab->trafficClass = RANAP_TrafficClass_conversational; |
| 298 | rab->rAB_AsymmetryIndicator = RANAP_RAB_AsymmetryIndicator_symmetric_bidirectional; |
| 299 | |
| 300 | ASN_SEQUENCE_ADD(&rab->maxBitrate, new_long(12200)); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 301 | rab->guaranteedBitRate = CALLOC(1, sizeof(*rab->guaranteedBitRate)); |
| 302 | ASN_SEQUENCE_ADD(&rab->guaranteedBitRate, new_long(12200)); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 303 | rab->deliveryOrder = RANAP_DeliveryOrder_delivery_order_requested; |
| 304 | rab->maxSDU_Size = 244; |
| 305 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 306 | RANAP_SDU_Parameters_t *sdup = CALLOC(1, sizeof(*sdup)); |
| 307 | ASN_SEQUENCE_ADD(&sdup->list, sdui); |
| 308 | |
| 309 | sdui = new_sdu_par_item(SDUPAR_P_VOICE0); |
| 310 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
| 311 | sdui = new_sdu_par_item(SDUPAR_P_VOICE1); |
| 312 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
| 313 | sdui = new_sdu_par_item(SDUPAR_P_VOICE2); |
| 314 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 315 | |
| 316 | rab->transferDelay = new_long(80); |
| 317 | rab->allocationOrRetentionPriority = new_alloc_ret_prio(RANAP_PriorityLevel_no_priority, 0, 1, 0); |
| 318 | |
| 319 | rab->sourceStatisticsDescriptor = new_long(RANAP_SourceStatisticsDescriptor_speech); |
| 320 | |
| 321 | return rab; |
| 322 | } |
| 323 | |
| 324 | static RANAP_RAB_Parameters_t *new_rab_par_data(void) |
| 325 | { |
| 326 | RANAP_RAB_Parameters_t *rab = CALLOC(1, sizeof(*rab)); |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 327 | RANAP_SDU_ParameterItem_t *sdui; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 328 | |
| 329 | rab->trafficClass = RANAP_TrafficClass_background; |
| 330 | rab->rAB_AsymmetryIndicator = RANAP_RAB_AsymmetryIndicator_asymmetric_bidirectional; |
| 331 | |
| 332 | ASN_SEQUENCE_ADD(&rab->maxBitrate, new_long(16000000)); |
| 333 | ASN_SEQUENCE_ADD(&rab->maxBitrate, new_long(8000000)); |
| 334 | rab->deliveryOrder = RANAP_DeliveryOrder_delivery_order_requested; |
| 335 | rab->maxSDU_Size = 8000; |
| 336 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 337 | sdui = new_sdu_par_item(SDUPAR_P_DATA); |
| 338 | ASN_SEQUENCE_ADD(&rab->sDU_Parameters, sdui); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 339 | |
| 340 | rab->allocationOrRetentionPriority = new_alloc_ret_prio(RANAP_PriorityLevel_no_priority, 0, 0, 0); |
| 341 | |
| 342 | /* FIXME: RAB-Parameter-ExtendedMaxBitrateList for 42Mbps? */ |
| 343 | |
| 344 | return rab; |
| 345 | } |
| 346 | |
| 347 | static RANAP_TransportLayerInformation_t *new_transp_info_rtp(uint32_t ip, uint16_t port) |
| 348 | { |
| 349 | RANAP_TransportLayerInformation_t *tli = CALLOC(1, sizeof(*tli)); |
| 350 | uint32_t *ipbuf = CALLOC(1, sizeof(*ipbuf)); |
| 351 | uint8_t binding_id[4]; |
| 352 | |
| 353 | binding_id[0] = port >> 8; |
| 354 | binding_id[1] = port & 0xff; |
| 355 | binding_id[2] = binding_id[3] = 0; |
| 356 | |
| 357 | asn1_u32_to_bitstring(&tli->transportLayerAddress, ipbuf, htonl(ip)); |
| 358 | tli->iuTransportAssociation.present = RANAP_IuTransportAssociation_PR_bindingID; |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 359 | OCTET_STRING_fromBuf(&tli->iuTransportAssociation.choice.bindingID, |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 360 | (const char *) binding_id, sizeof(binding_id)); |
| 361 | |
| 362 | return tli; |
| 363 | } |
| 364 | |
| 365 | static RANAP_TransportLayerInformation_t *new_transp_info_gtp(uint32_t ip, uint32_t tei) |
| 366 | { |
| 367 | RANAP_TransportLayerInformation_t *tli = CALLOC(1, sizeof(*tli)); |
| 368 | uint32_t *ipbuf = CALLOC(1, sizeof(*ipbuf)); |
| 369 | uint32_t binding_buf = htonl(tei); |
| 370 | |
| 371 | asn1_u32_to_bitstring(&tli->transportLayerAddress, ipbuf, htonl(ip)); |
| 372 | tli->iuTransportAssociation.present = RANAP_IuTransportAssociation_PR_gTP_TEI; |
| 373 | OCTET_STRING_fromBuf(&tli->iuTransportAssociation.choice.bindingID, |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 374 | (const char *) &binding_buf, sizeof(binding_buf)); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 375 | |
| 376 | return tli; |
| 377 | } |
| 378 | |
| 379 | static RANAP_UserPlaneInformation_t *new_upi(long mode, uint8_t mode_versions) |
| 380 | { |
| 381 | RANAP_UserPlaneInformation_t *upi = CALLOC(1, sizeof(*upi)); |
| 382 | uint8_t *buf = CALLOC(1, sizeof(*buf)); |
| 383 | |
| 384 | *buf = mode_versions; |
| 385 | |
| 386 | upi->userPlaneMode = mode; |
| 387 | upi->uP_ModeVersions.buf = buf; |
| 388 | upi->uP_ModeVersions.size = 1; |
| 389 | upi->uP_ModeVersions.bits_unused = 0; |
| 390 | |
| 391 | return upi; |
| 392 | } |
| 393 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 394 | |
| 395 | static void assign_new_ra_id(RANAP_RAB_ID_t *id, uint8_t rab_id) |
| 396 | { |
| 397 | uint8_t *buf = CALLOC(1, sizeof(*buf)); |
| 398 | *buf = rab_id << 3; |
| 399 | |
| 400 | id->buf = buf; |
| 401 | id->size = 1; |
| 402 | id->bits_unused = 0; |
| 403 | } |
| 404 | |
| 405 | int ranap_tx_rab_assign_voice(uint8_t rab_id, uint32_t rtp_ip, uint16_t rtp_port) |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 406 | { |
| 407 | RANAP_ProtocolIE_FieldPair_t *pair; |
| 408 | RANAP_RAB_AssignmentRequestIEs_t ies; |
| 409 | RANAP_RAB_AssignmentRequest_t out; |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 410 | int rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 411 | |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 412 | memset(&ies, 0, sizeof(ies)); |
| 413 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 414 | /* only assingnment is present, no release */ |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 415 | ies.presenceMask = RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_SETUPORMODIFYLIST_PRESENT; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 416 | |
| 417 | RANAP_RAB_SetupOrModifyItemFirst_t first; |
| 418 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 419 | assign_new_ra_id(&first.rAB_ID, rab_id); |
| 420 | //first.nAS_SynchronisationIndicator = FIXME; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 421 | first.rAB_Parameters = new_rab_par_voice(); |
| 422 | first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_support_mode_for_predefined_SDU_sizes, 1); /* 2? */ |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 423 | first.transportLayerInformation = new_transp_info_rtp(rtp_ip, rtp_port); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 424 | |
| 425 | RANAP_RAB_SetupOrModifyItemSecond_t second; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 426 | memset(&second, 0, sizeof(second)); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 427 | |
| 428 | pair = ranap_new_ie_pair(RANAP_ProtocolIE_ID_id_RAB_SetupOrModifyItem, |
| 429 | RANAP_Criticality_reject, |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 430 | &asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first, |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 431 | RANAP_Criticality_ignore, |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 432 | &asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second); |
| 433 | |
| 434 | ASN_SEQUENCE_ADD(&ies.raB_SetupOrModifyList.list, pair); |
| 435 | |
| 436 | rc = ranap_encode_rab_assignmentrequesties(&out, &ies); |
| 437 | } |
| 438 | |
| 439 | int ranap_tx_rab_assign_data(uint8_t rab_id, uint32_t gtp_ip, uint16_t gtp_port) |
| 440 | { |
| 441 | RANAP_ProtocolIE_FieldPair_t *pair; |
| 442 | RANAP_RAB_AssignmentRequestIEs_t ies; |
| 443 | RANAP_RAB_AssignmentRequest_t out; |
| 444 | RANAP_DataVolumeReportingIndication_t *dat_vol_ind = CALLOC(1, sizeof(*dat_vol_ind)); |
| 445 | int rc; |
| 446 | |
| 447 | memset(&ies, 0, sizeof(ies)); |
| 448 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 449 | /* only assingnment is present, no release */ |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 450 | ies.presenceMask = RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_SETUPORMODIFYLIST_PRESENT; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 451 | |
| 452 | RANAP_RAB_SetupOrModifyItemFirst_t first; |
| 453 | |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 454 | assign_new_ra_id(&first.rAB_ID, rab_id); |
| 455 | //first.nAS_SynchronisationIndicator = FIXME; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 456 | first.rAB_Parameters = new_rab_par_data(); |
| 457 | first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_transparent_mode, 1); |
| 458 | first.transportLayerInformation = new_transp_info_rtp(gtp_ip, gtp_port); |
| 459 | |
| 460 | RANAP_RAB_SetupOrModifyItemSecond_t second; |
| 461 | memset(&second, 0, sizeof(second)); |
| 462 | second.pDP_TypeInformation = CALLOC(1, sizeof(*second.pDP_TypeInformation)); |
| 463 | ASN_SEQUENCE_ADD(&second.pDP_TypeInformation, new_long(RANAP_PDP_Type_ipv4)); |
| 464 | *dat_vol_ind = RANAP_DataVolumeReportingIndication_do_not_report; |
| 465 | second.dataVolumeReportingIndication = dat_vol_ind; |
| 466 | second.dl_GTP_PDU_SequenceNumber = new_long(0); |
| 467 | second.ul_GTP_PDU_SequenceNumber = new_long(0); |
| 468 | |
| 469 | pair = ranap_new_ie_pair(RANAP_ProtocolIE_ID_id_RAB_SetupOrModifyItem, |
| 470 | RANAP_Criticality_reject, |
| 471 | &asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first, |
| 472 | RANAP_Criticality_ignore, |
| 473 | &asn_DEF_RANAP_RAB_SetupOrModifyItemSecond, &second); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 474 | |
| 475 | ASN_SEQUENCE_ADD(&ies.raB_SetupOrModifyList.list, pair); |
| 476 | |
| 477 | rc = ranap_encode_rab_assignmentrequesties(&out, &ies); |
| 478 | } |