Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 1 | /* common RANAP 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 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | |
| 23 | #include <osmocom/core/msgb.h> |
Harald Welte | 37704d9 | 2015-12-26 08:42:31 +0100 | [diff] [blame] | 24 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 25 | |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 26 | #include <osmocom/ranap/ranap_common.h> |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 27 | |
| 28 | extern int asn1_xer_print; |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 29 | int _ranap_DRANAP = 0; |
| 30 | #define DRANAP _ranap_DRANAP |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 31 | |
Harald Welte | efef6fb | 2015-12-25 15:35:01 +0100 | [diff] [blame] | 32 | const struct value_string ranap_presence_vals[5] = { |
| 33 | { RANAP_RANAP_PDU_PR_initiatingMessage, "Initiating" }, |
| 34 | { RANAP_RANAP_PDU_PR_successfulOutcome, "Successful Outcome" }, |
| 35 | { RANAP_RANAP_PDU_PR_unsuccessfulOutcome, "Unsuccessful Outcome" }, |
| 36 | { RANAP_RANAP_PDU_PR_outcome, "(Intermediate) Outcome" }, |
| 37 | { 0, NULL } |
| 38 | }; |
| 39 | |
| 40 | const struct value_string ranap_procedure_code_vals[48] = { |
| 41 | { RANAP_ProcedureCode_id_RAB_Assignment, "RAB Assignment" }, |
| 42 | { RANAP_ProcedureCode_id_Iu_Release, "Iu Release" }, |
| 43 | { RANAP_ProcedureCode_id_RelocationPreparation, "Relocation Preparation" }, |
| 44 | { RANAP_ProcedureCode_id_RelocationResourceAllocation, "Relocation Resource Allocation" }, |
| 45 | { RANAP_ProcedureCode_id_RelocationCancel, "Relocation Cancel" }, |
| 46 | { RANAP_ProcedureCode_id_SRNS_ContextTransfer, "SRNS Context Transfer" }, |
| 47 | { RANAP_ProcedureCode_id_SecurityModeControl, "Security Mode Control" }, |
| 48 | { RANAP_ProcedureCode_id_DataVolumeReport, "Data Volume Report" }, |
| 49 | { RANAP_ProcedureCode_id_Reset, "Reset" }, |
| 50 | { RANAP_ProcedureCode_id_RAB_ReleaseRequest, "RAB Release Request" }, |
| 51 | { RANAP_ProcedureCode_id_Iu_ReleaseRequest, "Iu Release Request" }, |
| 52 | { RANAP_ProcedureCode_id_RelocationDetect, "Relocation Detect" }, |
| 53 | { RANAP_ProcedureCode_id_RelocationComplete, "Relocation Complete" }, |
| 54 | { RANAP_ProcedureCode_id_Paging, "Paging" }, |
| 55 | { RANAP_ProcedureCode_id_CommonID, "Common ID" }, |
| 56 | { RANAP_ProcedureCode_id_CN_InvokeTrace, "CN Invoke Trace" }, |
| 57 | { RANAP_ProcedureCode_id_LocationReportingControl, "Location Reporting Control" }, |
| 58 | { RANAP_ProcedureCode_id_LocationReport, "Location Report" }, |
| 59 | { RANAP_ProcedureCode_id_InitialUE_Message, "Initial UE Message" }, |
| 60 | { RANAP_ProcedureCode_id_DirectTransfer, "Direct Transfer" }, |
| 61 | { RANAP_ProcedureCode_id_OverloadControl, "Overload Control" }, |
| 62 | { RANAP_ProcedureCode_id_ErrorIndication, "Error Indication" }, |
| 63 | { RANAP_ProcedureCode_id_SRNS_DataForward, "SRNS Data Forward" }, |
| 64 | { RANAP_ProcedureCode_id_ForwardSRNS_Context, "Forward SRNS Context" }, |
| 65 | { RANAP_ProcedureCode_id_privateMessage, "Private Message" }, |
| 66 | { RANAP_ProcedureCode_id_CN_DeactivateTrace, "CN Deactivate Trace" }, |
| 67 | { RANAP_ProcedureCode_id_ResetResource, "Reset Resource" }, |
| 68 | { RANAP_ProcedureCode_id_RANAP_Relocation, "RANAP Relocation" }, |
| 69 | { RANAP_ProcedureCode_id_RAB_ModifyRequest, "RAB Modify Request" }, |
| 70 | { RANAP_ProcedureCode_id_LocationRelatedData, "Location Related Data" }, |
| 71 | { RANAP_ProcedureCode_id_InformationTransfer, "Information Transfer" }, |
| 72 | { RANAP_ProcedureCode_id_UESpecificInformation, "UE Specific Information" }, |
| 73 | { RANAP_ProcedureCode_id_UplinkInformationExchange, "Uplink Information Transfer" }, |
| 74 | { RANAP_ProcedureCode_id_DirectInformationTransfer, "Direct Information Transfer" }, |
| 75 | { RANAP_ProcedureCode_id_MBMSSessionStart, "MBMS Session Start" }, |
| 76 | { RANAP_ProcedureCode_id_MBMSSessionUpdate, "MBMS Session Update" }, |
| 77 | { RANAP_ProcedureCode_id_MBMSSessionStop, "MBMS Session Stop" }, |
| 78 | { RANAP_ProcedureCode_id_MBMSUELinking, "MBMS UE Linking" }, |
| 79 | { RANAP_ProcedureCode_id_MBMSRegistration, "MBMS Registration" }, |
| 80 | { RANAP_ProcedureCode_id_MBMSCNDe_Registration_Procedure, "MBMS CN De-Registration" }, |
| 81 | { RANAP_ProcedureCode_id_MBMSRABEstablishmentIndication, "MBMS RAB Establishment Indication" }, |
| 82 | { RANAP_ProcedureCode_id_MBMSRABRelease, "MBMS RAB Release" }, |
| 83 | { RANAP_ProcedureCode_id_enhancedRelocationComplete, "Enhanced Relocation Complete" }, |
| 84 | { RANAP_ProcedureCode_id_enhancedRelocationCompleteConfirm, "Enhanced Relocation Complete Confirm" }, |
| 85 | { RANAP_ProcedureCode_id_RANAPenhancedRelocation, "RANAP Enhanced Relocation" }, |
| 86 | { RANAP_ProcedureCode_id_SRVCCPreparation, "SRVCC Preparation" }, |
| 87 | { RANAP_ProcedureCode_id_UeRadioCapabilityMatch, "UE Radio Capability Match" }, |
| 88 | { 0, NULL } |
| 89 | }; |
| 90 | |
Harald Welte | 3d39f84 | 2015-12-25 09:40:07 +0100 | [diff] [blame] | 91 | static const struct value_string ranap_cause_radio_vals[] = { |
| 92 | { RANAP_CauseRadioNetwork_rab_pre_empted, "RAB pre-empted" }, |
| 93 | { RANAP_CauseRadioNetwork_trelocoverall_expiry, "Treloc_overall expiry" }, |
| 94 | { RANAP_CauseRadioNetwork_trelocprep_expiry, "Treloc_prep expiry" }, |
| 95 | { RANAP_CauseRadioNetwork_treloccomplete_expiry,"Treloc_complete expiry" }, |
| 96 | { RANAP_CauseRadioNetwork_tqueing_expiry, "Tqueueing expiry" }, |
| 97 | { RANAP_CauseRadioNetwork_relocation_triggered, "Relocation triggered" }, |
| 98 | { RANAP_CauseRadioNetwork_trellocalloc_expiry, "Treloc_alloc expiry" }, |
| 99 | { RANAP_CauseRadioNetwork_unable_to_establish_during_relocation, |
| 100 | "unable to establish during relocation" }, |
| 101 | { RANAP_CauseRadioNetwork_unknown_target_rnc, |
| 102 | "unknown target RNC" }, |
| 103 | { RANAP_CauseRadioNetwork_relocation_cancelled, "Relocation cancelled" }, |
| 104 | { RANAP_CauseRadioNetwork_successful_relocation, "Successful relocation" }, |
| 105 | { RANAP_CauseRadioNetwork_requested_ciphering_and_or_integrity_protection_algorithms_not_supported, |
| 106 | "requested ciph. and/or int. prot. algorithms not supported" }, |
| 107 | { RANAP_CauseRadioNetwork_conflict_with_already_existing_integrity_protection_and_or_ciphering_information, |
| 108 | "conflict with existing int. prot. and/or ciph. information" }, |
| 109 | { RANAP_CauseRadioNetwork_failure_in_the_radio_interface_procedure, |
| 110 | "failure in the radio interface procedure" }, |
| 111 | { RANAP_CauseRadioNetwork_release_due_to_utran_generated_reason, |
| 112 | "release due to UTRAN generated reason" }, |
| 113 | { RANAP_CauseRadioNetwork_user_inactivity, "user inactivity" }, |
| 114 | { RANAP_CauseRadioNetwork_time_critical_relocation, |
| 115 | "time critical relocation" }, |
| 116 | { RANAP_CauseRadioNetwork_requested_traffic_class_not_available, |
| 117 | "requested traffic class not available" }, |
| 118 | { RANAP_CauseRadioNetwork_invalid_rab_parameters_value, |
| 119 | "invalid RAB parameters value" }, |
| 120 | { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_not_available, |
| 121 | "requested max. bit-rate not available" }, |
| 122 | { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_not_available, |
| 123 | "requested guaranteed bit-rate not available" }, |
| 124 | { RANAP_CauseRadioNetwork_requested_transfer_delay_not_achievable, |
| 125 | "requested transfer delay not achievable" }, |
| 126 | { RANAP_CauseRadioNetwork_invalid_rab_parameters_combination, |
| 127 | "invalid RAB parameters combination" }, |
| 128 | { RANAP_CauseRadioNetwork_condition_violation_for_sdu_parameters, |
| 129 | "condition violation for SDU parameters" }, |
| 130 | { RANAP_CauseRadioNetwork_condition_violation_for_traffic_handling_priority, |
| 131 | "condition violation for traffic handling priority" }, |
| 132 | { RANAP_CauseRadioNetwork_condition_violation_for_guaranteed_bit_rate, |
| 133 | "condition violation for guaranteed bit-rate" }, |
| 134 | { RANAP_CauseRadioNetwork_user_plane_versions_not_supported, |
| 135 | "user-plane versions not supported" }, |
| 136 | { RANAP_CauseRadioNetwork_iu_up_failure, "Iu-UP failure" }, |
| 137 | { RANAP_CauseRadioNetwork_relocation_failure_in_target_CN_RNC_or_target_system, |
| 138 | "relocation failure in target CN/RNC or target system" }, |
| 139 | { RANAP_CauseRadioNetwork_invalid_RAB_ID, "Invalid RAB ID" }, |
| 140 | { RANAP_CauseRadioNetwork_no_remaining_rab, "No remaining RAB" }, |
| 141 | { RANAP_CauseRadioNetwork_interaction_with_other_procedure, |
| 142 | "interaction with other procedure" }, |
| 143 | { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_for_dl_not_available, |
| 144 | "requested maximum bit-rate for DL not available" }, |
| 145 | { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_for_ul_not_available, |
| 146 | "requested maximum bit-rate for UL not available" }, |
| 147 | { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_for_dl_not_available, |
| 148 | "requested guaranteed bit-rate for DL not available" }, |
| 149 | { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_for_ul_not_available, |
| 150 | "requested guaranteed bit-rate for UL not available" }, |
| 151 | { RANAP_CauseRadioNetwork_repeated_integrity_checking_failure, |
| 152 | "repeated integrity checking failure" }, |
| 153 | { RANAP_CauseRadioNetwork_requested_request_type_not_supported, |
| 154 | "requested request type not supported" }, |
| 155 | { RANAP_CauseRadioNetwork_request_superseded, "request superseded" }, |
| 156 | { RANAP_CauseRadioNetwork_release_due_to_UE_generated_signalling_connection_release, |
| 157 | "release due to UE-generated signalling connection release" }, |
| 158 | { RANAP_CauseRadioNetwork_resource_optimisation_relocation, |
| 159 | "resource optimisation relocation" }, |
| 160 | { RANAP_CauseRadioNetwork_requested_information_not_available, |
| 161 | "requested information not available" }, |
| 162 | { RANAP_CauseRadioNetwork_relocation_desirable_for_radio_reasons, |
| 163 | "relocation desirable for radio reasons" }, |
| 164 | { RANAP_CauseRadioNetwork_relocation_not_supported_in_target_RNC_or_target_system, |
| 165 | "relocation not supported in target RNC or target system" }, |
| 166 | { RANAP_CauseRadioNetwork_directed_retry, "directed retry" }, |
| 167 | { RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost, |
| 168 | "radio connection with UE lost" }, |
| 169 | { RANAP_CauseRadioNetwork_rNC_unable_to_establish_all_RFCs, |
| 170 | "RNC unable to establish al RFCs" }, |
| 171 | { RANAP_CauseRadioNetwork_deciphering_keys_not_available, |
| 172 | "de-ciphering keys not available" }, |
| 173 | { RANAP_CauseRadioNetwork_dedicated_assistance_data_not_available, |
| 174 | "dedicated assistance data not available" }, |
| 175 | { RANAP_CauseRadioNetwork_relocation_target_not_allowed, |
| 176 | "relocation target not allowed" }, |
| 177 | { RANAP_CauseRadioNetwork_location_reporting_congestion, |
| 178 | "relocation reporting congestion" }, |
| 179 | { RANAP_CauseRadioNetwork_reduce_load_in_serving_cell, |
| 180 | "reduce load in serving cell" }, |
| 181 | { RANAP_CauseRadioNetwork_no_radio_resources_available_in_target_cell, |
| 182 | "no radio resources available in target cell" }, |
| 183 | { RANAP_CauseRadioNetwork_gERAN_Iumode_failure, |
| 184 | "GERAN Iu-Mode failure" }, |
| 185 | { RANAP_CauseRadioNetwork_access_restricted_due_to_shared_networks, |
| 186 | "access restricted due to shared networks" }, |
| 187 | { RANAP_CauseRadioNetwork_incoming_relocation_not_supported_due_to_PUESBINE_feature, |
| 188 | "incoming relocation not supported due to PUESBINE feature" }, |
| 189 | { RANAP_CauseRadioNetwork_traffic_load_in_the_target_cell_higher_than_in_the_source_cell, |
| 190 | "traffic load in the target cell higher than in the source cell" }, |
| 191 | { RANAP_CauseRadioNetwork_mBMS_no_multicast_service_for_this_UE, |
| 192 | "MBMS: no multicast service for this UE" }, |
| 193 | { RANAP_CauseRadioNetwork_mBMS_unknown_UE_ID, "MBMS: unknown UE ID" }, |
| 194 | { RANAP_CauseRadioNetwork_successful_MBMS_session_start_no_data_bearer_necessary, |
| 195 | "successful MBMS session start; no data bearer necessarry" }, |
| 196 | { RANAP_CauseRadioNetwork_mBMS_superseded_due_to_NNSF, |
| 197 | "MBMS superseded due to NNSF" }, |
| 198 | { RANAP_CauseRadioNetwork_mBMS_UE_linking_already_done, |
| 199 | "MBMS: UE linking already done" }, |
| 200 | { RANAP_CauseRadioNetwork_mBMS_UE_de_linking_failure_no_existing_UE_linking, |
| 201 | "MBMS: UE de-linking failure; no existing UE linking" }, |
| 202 | { RANAP_CauseRadioNetwork_tMGI_unknown, "TMGI unknown" }, |
| 203 | { 0, NULL } |
| 204 | }; |
| 205 | |
| 206 | static const struct value_string ranap_cause_transm_vals[] = { |
| 207 | { RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure, |
| 208 | "signalling transport resource failure" }, |
| 209 | { RANAP_CauseTransmissionNetwork_iu_transport_connection_failed_to_establish, |
| 210 | "Iu transport connection failed to establish" }, |
| 211 | { 0, NULL } |
| 212 | }; |
| 213 | |
| 214 | static const struct value_string ranap_cause_nas_vals[] = { |
| 215 | { RANAP_CauseNAS_user_restriction_start_indication, |
| 216 | "user restriction; start indication" }, |
| 217 | { RANAP_CauseNAS_user_restriction_end_indication, |
| 218 | "user restriction; stop indication" }, |
| 219 | { RANAP_CauseNAS_normal_release, |
| 220 | "normal release" }, |
| 221 | { RANAP_CauseNAS_csg_subscription_expiry, |
| 222 | "CSG subscription expiry" }, |
| 223 | { 0, NULL } |
| 224 | }; |
| 225 | |
| 226 | static const struct value_string ranap_cause_prot_vals[] = { |
| 227 | { RANAP_CauseProtocol_transfer_syntax_error, |
| 228 | "transfer sytax error" }, |
| 229 | { RANAP_CauseProtocol_semantic_error, |
| 230 | "semantic error" }, |
| 231 | { RANAP_CauseProtocol_message_not_compatible_with_receiver_state, |
| 232 | "message not compatible with receiver state" }, |
| 233 | { RANAP_CauseProtocol_abstract_syntax_error_reject, |
| 234 | "syntax error: reject" }, |
| 235 | { RANAP_CauseProtocol_abstract_syntax_error_ignore_and_notify, |
| 236 | "syntax error: ignore and notify" }, |
| 237 | { RANAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message, |
| 238 | "syntax error: falsely constructed message" }, |
| 239 | { 0, NULL } |
| 240 | }; |
| 241 | |
| 242 | static const struct value_string ranap_cause_misc_vals[] = { |
| 243 | { RANAP_CauseMisc_om_intervention, "OAM intervention" }, |
| 244 | { RANAP_CauseMisc_no_resource_available, "no resource available" }, |
| 245 | { RANAP_CauseMisc_unspecified_failure, "unspecified failure" }, |
| 246 | { RANAP_CauseMisc_network_optimisation, "network optimisation" }, |
| 247 | { 0, NULL } |
| 248 | }; |
| 249 | |
| 250 | char *ranap_cause_str(const RANAP_Cause_t *cause) |
| 251 | { |
| 252 | static char buf[128]; |
| 253 | |
| 254 | switch (cause->present) { |
| 255 | case RANAP_Cause_PR_radioNetwork: |
| 256 | snprintf(buf, sizeof(buf), "radio(%s)", |
| 257 | get_value_string(ranap_cause_radio_vals, |
| 258 | cause->choice.radioNetwork)); |
| 259 | break; |
| 260 | case RANAP_Cause_PR_transmissionNetwork: |
| 261 | snprintf(buf, sizeof(buf), "transmission(%s)", |
| 262 | get_value_string(ranap_cause_transm_vals, |
| 263 | cause->choice.transmissionNetwork)); |
| 264 | break; |
| 265 | case RANAP_Cause_PR_nAS: |
| 266 | snprintf(buf, sizeof(buf), "nas(%s)", |
| 267 | get_value_string(ranap_cause_nas_vals, |
| 268 | cause->choice.nAS)); |
| 269 | break; |
| 270 | case RANAP_Cause_PR_protocol: |
| 271 | snprintf(buf, sizeof(buf), "protocol(%s)", |
| 272 | get_value_string(ranap_cause_prot_vals, |
| 273 | cause->choice.protocol)); |
| 274 | break; |
| 275 | case RANAP_Cause_PR_misc: |
| 276 | snprintf(buf, sizeof(buf), "misc(%s)", |
| 277 | get_value_string(ranap_cause_misc_vals, |
| 278 | cause->choice.misc)); |
| 279 | break; |
| 280 | case RANAP_Cause_PR_non_Standard: |
| 281 | snprintf(buf, sizeof(buf), "non-standard(%u)", |
| 282 | cause->choice.non_Standard); |
| 283 | break; |
| 284 | default: |
| 285 | strcpy(buf, "unknown"); |
| 286 | break; |
| 287 | } |
| 288 | return buf; |
| 289 | } |
| 290 | |
| 291 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 292 | static struct msgb *ranap_msgb_alloc(void) |
| 293 | { |
Harald Welte | e311ae0 | 2015-12-26 23:41:14 +0100 | [diff] [blame] | 294 | return msgb_alloc_headroom(1024+256, 256, "RANAP Tx"); |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 297 | static struct msgb *_ranap_gen_msg(RANAP_RANAP_PDU_t *pdu) |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 298 | { |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 299 | struct msgb *msg = ranap_msgb_alloc(); |
| 300 | asn_enc_rval_t rval; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 301 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 302 | if (!msg) |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 303 | return NULL; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 304 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 305 | rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, pdu, |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 306 | msg->data, msgb_tailroom(msg)); |
| 307 | if (rval.encoded < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 308 | LOGP(DRANAP, LOGL_ERROR, "Error encoding type: %s\n", |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 309 | rval.failed_type->name); |
| 310 | |
| 311 | } |
| 312 | |
| 313 | msgb_put(msg, rval.encoded/8); |
| 314 | |
| 315 | return msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 316 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 317 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 318 | struct msgb *ranap_generate_initiating_message(e_RANAP_ProcedureCode procedureCode, |
| 319 | RANAP_Criticality_t criticality, |
| 320 | asn_TYPE_descriptor_t *td, void *sptr) |
| 321 | { |
| 322 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 323 | struct msgb *msg; |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 324 | int rc; |
| 325 | |
| 326 | memset(&pdu, 0, sizeof(pdu)); |
| 327 | |
| 328 | pdu.present = RANAP_RANAP_PDU_PR_initiatingMessage; |
| 329 | pdu.choice.initiatingMessage.procedureCode = procedureCode; |
| 330 | pdu.choice.initiatingMessage.criticality = criticality; |
| 331 | rc = ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr); |
| 332 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 333 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 334 | return NULL; |
| 335 | } |
| 336 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 337 | msg = _ranap_gen_msg(&pdu); |
| 338 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 339 | |
| 340 | return msg; |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 343 | struct msgb *ranap_generate_successful_outcome( |
| 344 | e_RANAP_ProcedureCode procedureCode, |
| 345 | RANAP_Criticality_t criticality, |
| 346 | asn_TYPE_descriptor_t * td, |
| 347 | void *sptr) |
| 348 | { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 349 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 350 | struct msgb *msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 351 | int rc; |
| 352 | |
| 353 | memset(&pdu, 0, sizeof(pdu)); |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 354 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 355 | pdu.present = RANAP_RANAP_PDU_PR_successfulOutcome; |
| 356 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 357 | pdu.choice.successfulOutcome.criticality = criticality; |
| 358 | rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); |
| 359 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 360 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 361 | return NULL; |
| 362 | } |
| 363 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 364 | msg = _ranap_gen_msg(&pdu); |
| 365 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 366 | |
| 367 | return msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 370 | struct msgb *ranap_generate_unsuccessful_outcome( |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 371 | e_RANAP_ProcedureCode procedureCode, |
| 372 | RANAP_Criticality_t criticality, |
| 373 | asn_TYPE_descriptor_t * td, |
| 374 | void *sptr) |
| 375 | { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 376 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 377 | struct msgb *msg; |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 378 | int rc; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 379 | |
| 380 | memset(&pdu, 0, sizeof(pdu)); |
| 381 | |
| 382 | pdu.present = RANAP_RANAP_PDU_PR_unsuccessfulOutcome; |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 383 | pdu.choice.unsuccessfulOutcome.procedureCode = procedureCode; |
| 384 | pdu.choice.unsuccessfulOutcome.criticality = criticality; |
| 385 | rc = ANY_fromType_aper(&pdu.choice.unsuccessfulOutcome.value, td, sptr); |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 386 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 387 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 388 | return NULL; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 391 | msg = _ranap_gen_msg(&pdu); |
| 392 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 393 | |
| 394 | return msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 395 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 396 | |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 397 | struct msgb *ranap_generate_outcome( |
| 398 | e_RANAP_ProcedureCode procedureCode, |
| 399 | RANAP_Criticality_t criticality, |
| 400 | asn_TYPE_descriptor_t * td, |
| 401 | void *sptr) |
| 402 | { |
| 403 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 404 | struct msgb *msg; |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 405 | int rc; |
| 406 | |
| 407 | memset(&pdu, 0, sizeof(pdu)); |
| 408 | |
| 409 | pdu.present = RANAP_RANAP_PDU_PR_outcome; |
| 410 | pdu.choice.outcome.procedureCode = procedureCode; |
| 411 | pdu.choice.outcome.criticality = criticality; |
| 412 | rc = ANY_fromType_aper(&pdu.choice.outcome.value, td, sptr); |
| 413 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 414 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 415 | return NULL; |
| 416 | } |
| 417 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 418 | msg = _ranap_gen_msg(&pdu); |
| 419 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 420 | |
| 421 | return msg; |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 425 | RANAP_IE_t *ranap_new_ie(RANAP_ProtocolIE_ID_t id, |
| 426 | RANAP_Criticality_t criticality, |
| 427 | asn_TYPE_descriptor_t * type, void *sptr) |
| 428 | { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 429 | RANAP_IE_t *buff; |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 430 | int rc; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 431 | |
Harald Welte | 9c397d4 | 2015-12-18 13:33:20 +0100 | [diff] [blame] | 432 | if ((buff = CALLOC(1, sizeof(*buff))) == NULL) { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 433 | // Possible error on malloc |
| 434 | return NULL; |
| 435 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 436 | |
| 437 | buff->id = id; |
| 438 | buff->criticality = criticality; |
| 439 | |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 440 | rc = ANY_fromType_aper(&buff->value, type, sptr); |
| 441 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 442 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 443 | FREEMEM(buff); |
| 444 | return NULL; |
| 445 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 446 | |
| 447 | if (asn1_xer_print) |
| 448 | if (xer_fprint(stdout, &asn_DEF_RANAP_IE, buff) < 0) { |
Harald Welte | 6293913 | 2015-12-18 14:57:04 +0100 | [diff] [blame] | 449 | FREEMEM(buff); |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 450 | return NULL; |
| 451 | } |
| 452 | |
| 453 | return buff; |
| 454 | } |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 455 | |
| 456 | RANAP_ProtocolIE_FieldPair_t *ranap_new_ie_pair(RANAP_ProtocolIE_ID_t id, |
| 457 | RANAP_Criticality_t criticality1, |
| 458 | asn_TYPE_descriptor_t *type1, void *sptr1, |
| 459 | RANAP_Criticality_t criticality2, |
| 460 | asn_TYPE_descriptor_t *type2, void *sptr2) |
| 461 | { |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 462 | RANAP_ProtocolIE_FieldPair_t *buff; |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 463 | int rc; |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 464 | |
Harald Welte | 9c397d4 | 2015-12-18 13:33:20 +0100 | [diff] [blame] | 465 | if ((buff = CALLOC(1, sizeof(*buff))) == NULL) { |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 466 | // Possible error on malloc |
| 467 | return NULL; |
| 468 | } |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 469 | |
| 470 | buff->id = id; |
| 471 | buff->firstCriticality = criticality1; |
| 472 | buff->secondCriticality = criticality2; |
| 473 | |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 474 | rc = ANY_fromType_aper(&buff->firstValue, type1, sptr1); |
| 475 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 476 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 477 | FREEMEM(buff); |
| 478 | return NULL; |
| 479 | } |
| 480 | |
| 481 | rc = ANY_fromType_aper(&buff->secondValue, type2, sptr2); |
| 482 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 483 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 1623278 | 2015-12-18 17:22:04 +0100 | [diff] [blame] | 484 | ASN_STRUCT_FREE(asn_DEF_RANAP_ProtocolIE_FieldPair, buff); |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 485 | return NULL; |
| 486 | } |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 487 | |
| 488 | if (asn1_xer_print) |
Harald Welte | 6293913 | 2015-12-18 14:57:04 +0100 | [diff] [blame] | 489 | if (xer_fprint(stdout, &asn_DEF_RANAP_ProtocolIE_FieldPair, buff) < 0) { |
Harald Welte | 1623278 | 2015-12-18 17:22:04 +0100 | [diff] [blame] | 490 | ASN_STRUCT_FREE(asn_DEF_RANAP_ProtocolIE_FieldPair, buff); |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 491 | return NULL; |
| 492 | } |
| 493 | |
| 494 | return buff; |
| 495 | } |
Harald Welte | 37704d9 | 2015-12-26 08:42:31 +0100 | [diff] [blame] | 496 | |
| 497 | int ranap_parse_lai(struct gprs_ra_id *ra_id, const RANAP_LAI_t *lai) |
| 498 | { |
| 499 | uint8_t *ptr = lai->pLMNidentity.buf; |
| 500 | |
| 501 | /* TS 25.413 9.2.3.55 */ |
| 502 | if (lai->pLMNidentity.size != 3) |
| 503 | return -1; |
| 504 | |
| 505 | ra_id->mcc = (ptr[0] & 0xF) * 100 + |
| 506 | (ptr[0] >> 4) * 10 + |
| 507 | (ptr[1] & 0xF); |
| 508 | ra_id->mnc = (ptr[2] & 0xF) + |
| 509 | (ptr[2] >> 4) * 10; |
| 510 | if ((ptr[1] >> 4) != 0xF) |
| 511 | ra_id->mnc += (ptr[1] >> 4) * 100; |
| 512 | |
| 513 | ra_id->lac = asn1str_to_u16(&lai->lAC); |
| 514 | |
| 515 | /* TS 25.413 9.2.3.6 */ |
| 516 | if (ra_id->lac == 0 || ra_id->lac == 0xfffe) |
| 517 | return -1; |
| 518 | |
| 519 | return 0; |
| 520 | } |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 521 | |
| 522 | void ranap_set_log_area(int log_area) |
| 523 | { |
| 524 | _ranap_DRANAP = log_area; |
| 525 | } |
Daniel Willmann | 4870b99 | 2016-02-04 18:00:36 +0100 | [diff] [blame] | 526 | |
| 527 | int ranap_ip_from_transp_layer_addr(const BIT_STRING_t *in, uint32_t *ip) |
| 528 | { |
| 529 | uint32_t addr; |
| 530 | uint8_t x213[] = {0x35, 0x00, 0x01}; |
| 531 | |
| 532 | /* Only support IPv4 for now - plain and with x213 encapsulation */ |
| 533 | if (in->size == 4) |
| 534 | *ip = *(uint32_t *)in->buf; |
| 535 | else if ((in->size == 7) && !memcmp(in->buf, x213, sizeof(x213))) |
| 536 | *ip = htonl(*(uint32_t *)&in->buf[3]); |
| 537 | else |
| 538 | return -1; |
| 539 | |
| 540 | return 0; |
| 541 | |
| 542 | } |
Daniel Willmann | 635fac0 | 2016-02-18 13:27:36 +0100 | [diff] [blame] | 543 | |
| 544 | int ranap_decode_rab_setupormodifieditemies_fromlist( |
| 545 | RANAP_RAB_SetupOrModifiedItemIEs_t *raB_SetupOrModifiedItemIEs, |
| 546 | ANY_t *any_p) { |
| 547 | |
| 548 | RANAP_RAB_SetupOrModifiedItem_t *ranaP_RABSetupOrModifiedItem_p = NULL; |
| 549 | int decoded = 0; |
| 550 | assert(any_p != NULL); |
| 551 | assert(raB_SetupOrModifiedItemIEs != NULL); |
| 552 | |
| 553 | memset(raB_SetupOrModifiedItemIEs, 0, sizeof(RANAP_RAB_SetupOrModifiedItemIEs_t)); |
| 554 | RANAP_DEBUG("Decoding message RANAP_RAB_SetupOrModifiedItemIEs (%s:%d)\n", __FILE__, __LINE__); |
| 555 | decoded = ANY_to_type_aper(any_p, &asn_DEF_RANAP_RAB_SetupOrModifiedItem, (void**)&ranaP_RABSetupOrModifiedItem_p); |
| 556 | if (decoded < 0) { |
| 557 | RANAP_DEBUG("Decoding of IE raB_SetupOrModifiedItem failed\n"); |
| 558 | return -1; |
| 559 | } |
| 560 | if (asn1_xer_print) |
| 561 | xer_fprint(stdout, &asn_DEF_RANAP_RAB_SetupOrModifiedItem, ranaP_RABSetupOrModifiedItem_p); |
| 562 | memcpy(&raB_SetupOrModifiedItemIEs->raB_SetupOrModifiedItem, ranaP_RABSetupOrModifiedItem_p, sizeof(RANAP_RAB_SetupOrModifiedItem_t)); |
| 563 | FREEMEM(ranaP_RABSetupOrModifiedItem_p); |
| 564 | |
| 565 | return decoded; |
| 566 | } |
| 567 | |