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> |
| 24 | |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 25 | #include "ranap_common.h" |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 26 | #include "hnbgw.h" |
| 27 | |
| 28 | extern int asn1_xer_print; |
| 29 | |
Harald Welte | 3d39f84 | 2015-12-25 09:40:07 +0100 | [diff] [blame] | 30 | static const struct value_string ranap_cause_radio_vals[] = { |
| 31 | { RANAP_CauseRadioNetwork_rab_pre_empted, "RAB pre-empted" }, |
| 32 | { RANAP_CauseRadioNetwork_trelocoverall_expiry, "Treloc_overall expiry" }, |
| 33 | { RANAP_CauseRadioNetwork_trelocprep_expiry, "Treloc_prep expiry" }, |
| 34 | { RANAP_CauseRadioNetwork_treloccomplete_expiry,"Treloc_complete expiry" }, |
| 35 | { RANAP_CauseRadioNetwork_tqueing_expiry, "Tqueueing expiry" }, |
| 36 | { RANAP_CauseRadioNetwork_relocation_triggered, "Relocation triggered" }, |
| 37 | { RANAP_CauseRadioNetwork_trellocalloc_expiry, "Treloc_alloc expiry" }, |
| 38 | { RANAP_CauseRadioNetwork_unable_to_establish_during_relocation, |
| 39 | "unable to establish during relocation" }, |
| 40 | { RANAP_CauseRadioNetwork_unknown_target_rnc, |
| 41 | "unknown target RNC" }, |
| 42 | { RANAP_CauseRadioNetwork_relocation_cancelled, "Relocation cancelled" }, |
| 43 | { RANAP_CauseRadioNetwork_successful_relocation, "Successful relocation" }, |
| 44 | { RANAP_CauseRadioNetwork_requested_ciphering_and_or_integrity_protection_algorithms_not_supported, |
| 45 | "requested ciph. and/or int. prot. algorithms not supported" }, |
| 46 | { RANAP_CauseRadioNetwork_conflict_with_already_existing_integrity_protection_and_or_ciphering_information, |
| 47 | "conflict with existing int. prot. and/or ciph. information" }, |
| 48 | { RANAP_CauseRadioNetwork_failure_in_the_radio_interface_procedure, |
| 49 | "failure in the radio interface procedure" }, |
| 50 | { RANAP_CauseRadioNetwork_release_due_to_utran_generated_reason, |
| 51 | "release due to UTRAN generated reason" }, |
| 52 | { RANAP_CauseRadioNetwork_user_inactivity, "user inactivity" }, |
| 53 | { RANAP_CauseRadioNetwork_time_critical_relocation, |
| 54 | "time critical relocation" }, |
| 55 | { RANAP_CauseRadioNetwork_requested_traffic_class_not_available, |
| 56 | "requested traffic class not available" }, |
| 57 | { RANAP_CauseRadioNetwork_invalid_rab_parameters_value, |
| 58 | "invalid RAB parameters value" }, |
| 59 | { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_not_available, |
| 60 | "requested max. bit-rate not available" }, |
| 61 | { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_not_available, |
| 62 | "requested guaranteed bit-rate not available" }, |
| 63 | { RANAP_CauseRadioNetwork_requested_transfer_delay_not_achievable, |
| 64 | "requested transfer delay not achievable" }, |
| 65 | { RANAP_CauseRadioNetwork_invalid_rab_parameters_combination, |
| 66 | "invalid RAB parameters combination" }, |
| 67 | { RANAP_CauseRadioNetwork_condition_violation_for_sdu_parameters, |
| 68 | "condition violation for SDU parameters" }, |
| 69 | { RANAP_CauseRadioNetwork_condition_violation_for_traffic_handling_priority, |
| 70 | "condition violation for traffic handling priority" }, |
| 71 | { RANAP_CauseRadioNetwork_condition_violation_for_guaranteed_bit_rate, |
| 72 | "condition violation for guaranteed bit-rate" }, |
| 73 | { RANAP_CauseRadioNetwork_user_plane_versions_not_supported, |
| 74 | "user-plane versions not supported" }, |
| 75 | { RANAP_CauseRadioNetwork_iu_up_failure, "Iu-UP failure" }, |
| 76 | { RANAP_CauseRadioNetwork_relocation_failure_in_target_CN_RNC_or_target_system, |
| 77 | "relocation failure in target CN/RNC or target system" }, |
| 78 | { RANAP_CauseRadioNetwork_invalid_RAB_ID, "Invalid RAB ID" }, |
| 79 | { RANAP_CauseRadioNetwork_no_remaining_rab, "No remaining RAB" }, |
| 80 | { RANAP_CauseRadioNetwork_interaction_with_other_procedure, |
| 81 | "interaction with other procedure" }, |
| 82 | { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_for_dl_not_available, |
| 83 | "requested maximum bit-rate for DL not available" }, |
| 84 | { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_for_ul_not_available, |
| 85 | "requested maximum bit-rate for UL not available" }, |
| 86 | { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_for_dl_not_available, |
| 87 | "requested guaranteed bit-rate for DL not available" }, |
| 88 | { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_for_ul_not_available, |
| 89 | "requested guaranteed bit-rate for UL not available" }, |
| 90 | { RANAP_CauseRadioNetwork_repeated_integrity_checking_failure, |
| 91 | "repeated integrity checking failure" }, |
| 92 | { RANAP_CauseRadioNetwork_requested_request_type_not_supported, |
| 93 | "requested request type not supported" }, |
| 94 | { RANAP_CauseRadioNetwork_request_superseded, "request superseded" }, |
| 95 | { RANAP_CauseRadioNetwork_release_due_to_UE_generated_signalling_connection_release, |
| 96 | "release due to UE-generated signalling connection release" }, |
| 97 | { RANAP_CauseRadioNetwork_resource_optimisation_relocation, |
| 98 | "resource optimisation relocation" }, |
| 99 | { RANAP_CauseRadioNetwork_requested_information_not_available, |
| 100 | "requested information not available" }, |
| 101 | { RANAP_CauseRadioNetwork_relocation_desirable_for_radio_reasons, |
| 102 | "relocation desirable for radio reasons" }, |
| 103 | { RANAP_CauseRadioNetwork_relocation_not_supported_in_target_RNC_or_target_system, |
| 104 | "relocation not supported in target RNC or target system" }, |
| 105 | { RANAP_CauseRadioNetwork_directed_retry, "directed retry" }, |
| 106 | { RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost, |
| 107 | "radio connection with UE lost" }, |
| 108 | { RANAP_CauseRadioNetwork_rNC_unable_to_establish_all_RFCs, |
| 109 | "RNC unable to establish al RFCs" }, |
| 110 | { RANAP_CauseRadioNetwork_deciphering_keys_not_available, |
| 111 | "de-ciphering keys not available" }, |
| 112 | { RANAP_CauseRadioNetwork_dedicated_assistance_data_not_available, |
| 113 | "dedicated assistance data not available" }, |
| 114 | { RANAP_CauseRadioNetwork_relocation_target_not_allowed, |
| 115 | "relocation target not allowed" }, |
| 116 | { RANAP_CauseRadioNetwork_location_reporting_congestion, |
| 117 | "relocation reporting congestion" }, |
| 118 | { RANAP_CauseRadioNetwork_reduce_load_in_serving_cell, |
| 119 | "reduce load in serving cell" }, |
| 120 | { RANAP_CauseRadioNetwork_no_radio_resources_available_in_target_cell, |
| 121 | "no radio resources available in target cell" }, |
| 122 | { RANAP_CauseRadioNetwork_gERAN_Iumode_failure, |
| 123 | "GERAN Iu-Mode failure" }, |
| 124 | { RANAP_CauseRadioNetwork_access_restricted_due_to_shared_networks, |
| 125 | "access restricted due to shared networks" }, |
| 126 | { RANAP_CauseRadioNetwork_incoming_relocation_not_supported_due_to_PUESBINE_feature, |
| 127 | "incoming relocation not supported due to PUESBINE feature" }, |
| 128 | { RANAP_CauseRadioNetwork_traffic_load_in_the_target_cell_higher_than_in_the_source_cell, |
| 129 | "traffic load in the target cell higher than in the source cell" }, |
| 130 | { RANAP_CauseRadioNetwork_mBMS_no_multicast_service_for_this_UE, |
| 131 | "MBMS: no multicast service for this UE" }, |
| 132 | { RANAP_CauseRadioNetwork_mBMS_unknown_UE_ID, "MBMS: unknown UE ID" }, |
| 133 | { RANAP_CauseRadioNetwork_successful_MBMS_session_start_no_data_bearer_necessary, |
| 134 | "successful MBMS session start; no data bearer necessarry" }, |
| 135 | { RANAP_CauseRadioNetwork_mBMS_superseded_due_to_NNSF, |
| 136 | "MBMS superseded due to NNSF" }, |
| 137 | { RANAP_CauseRadioNetwork_mBMS_UE_linking_already_done, |
| 138 | "MBMS: UE linking already done" }, |
| 139 | { RANAP_CauseRadioNetwork_mBMS_UE_de_linking_failure_no_existing_UE_linking, |
| 140 | "MBMS: UE de-linking failure; no existing UE linking" }, |
| 141 | { RANAP_CauseRadioNetwork_tMGI_unknown, "TMGI unknown" }, |
| 142 | { 0, NULL } |
| 143 | }; |
| 144 | |
| 145 | static const struct value_string ranap_cause_transm_vals[] = { |
| 146 | { RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure, |
| 147 | "signalling transport resource failure" }, |
| 148 | { RANAP_CauseTransmissionNetwork_iu_transport_connection_failed_to_establish, |
| 149 | "Iu transport connection failed to establish" }, |
| 150 | { 0, NULL } |
| 151 | }; |
| 152 | |
| 153 | static const struct value_string ranap_cause_nas_vals[] = { |
| 154 | { RANAP_CauseNAS_user_restriction_start_indication, |
| 155 | "user restriction; start indication" }, |
| 156 | { RANAP_CauseNAS_user_restriction_end_indication, |
| 157 | "user restriction; stop indication" }, |
| 158 | { RANAP_CauseNAS_normal_release, |
| 159 | "normal release" }, |
| 160 | { RANAP_CauseNAS_csg_subscription_expiry, |
| 161 | "CSG subscription expiry" }, |
| 162 | { 0, NULL } |
| 163 | }; |
| 164 | |
| 165 | static const struct value_string ranap_cause_prot_vals[] = { |
| 166 | { RANAP_CauseProtocol_transfer_syntax_error, |
| 167 | "transfer sytax error" }, |
| 168 | { RANAP_CauseProtocol_semantic_error, |
| 169 | "semantic error" }, |
| 170 | { RANAP_CauseProtocol_message_not_compatible_with_receiver_state, |
| 171 | "message not compatible with receiver state" }, |
| 172 | { RANAP_CauseProtocol_abstract_syntax_error_reject, |
| 173 | "syntax error: reject" }, |
| 174 | { RANAP_CauseProtocol_abstract_syntax_error_ignore_and_notify, |
| 175 | "syntax error: ignore and notify" }, |
| 176 | { RANAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message, |
| 177 | "syntax error: falsely constructed message" }, |
| 178 | { 0, NULL } |
| 179 | }; |
| 180 | |
| 181 | static const struct value_string ranap_cause_misc_vals[] = { |
| 182 | { RANAP_CauseMisc_om_intervention, "OAM intervention" }, |
| 183 | { RANAP_CauseMisc_no_resource_available, "no resource available" }, |
| 184 | { RANAP_CauseMisc_unspecified_failure, "unspecified failure" }, |
| 185 | { RANAP_CauseMisc_network_optimisation, "network optimisation" }, |
| 186 | { 0, NULL } |
| 187 | }; |
| 188 | |
| 189 | char *ranap_cause_str(const RANAP_Cause_t *cause) |
| 190 | { |
| 191 | static char buf[128]; |
| 192 | |
| 193 | switch (cause->present) { |
| 194 | case RANAP_Cause_PR_radioNetwork: |
| 195 | snprintf(buf, sizeof(buf), "radio(%s)", |
| 196 | get_value_string(ranap_cause_radio_vals, |
| 197 | cause->choice.radioNetwork)); |
| 198 | break; |
| 199 | case RANAP_Cause_PR_transmissionNetwork: |
| 200 | snprintf(buf, sizeof(buf), "transmission(%s)", |
| 201 | get_value_string(ranap_cause_transm_vals, |
| 202 | cause->choice.transmissionNetwork)); |
| 203 | break; |
| 204 | case RANAP_Cause_PR_nAS: |
| 205 | snprintf(buf, sizeof(buf), "nas(%s)", |
| 206 | get_value_string(ranap_cause_nas_vals, |
| 207 | cause->choice.nAS)); |
| 208 | break; |
| 209 | case RANAP_Cause_PR_protocol: |
| 210 | snprintf(buf, sizeof(buf), "protocol(%s)", |
| 211 | get_value_string(ranap_cause_prot_vals, |
| 212 | cause->choice.protocol)); |
| 213 | break; |
| 214 | case RANAP_Cause_PR_misc: |
| 215 | snprintf(buf, sizeof(buf), "misc(%s)", |
| 216 | get_value_string(ranap_cause_misc_vals, |
| 217 | cause->choice.misc)); |
| 218 | break; |
| 219 | case RANAP_Cause_PR_non_Standard: |
| 220 | snprintf(buf, sizeof(buf), "non-standard(%u)", |
| 221 | cause->choice.non_Standard); |
| 222 | break; |
| 223 | default: |
| 224 | strcpy(buf, "unknown"); |
| 225 | break; |
| 226 | } |
| 227 | return buf; |
| 228 | } |
| 229 | |
| 230 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 231 | static struct msgb *ranap_msgb_alloc(void) |
| 232 | { |
| 233 | return msgb_alloc(1024, "RANAP Tx"); |
| 234 | } |
| 235 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 236 | static struct msgb *_ranap_gen_msg(RANAP_RANAP_PDU_t *pdu) |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 237 | { |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 238 | struct msgb *msg = ranap_msgb_alloc(); |
| 239 | asn_enc_rval_t rval; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 240 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 241 | if (!msg) |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 242 | return NULL; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 243 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 244 | rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, pdu, |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 245 | msg->data, msgb_tailroom(msg)); |
| 246 | if (rval.encoded < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 247 | LOGP(DRANAP, LOGL_ERROR, "Error encoding type: %s\n", |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 248 | rval.failed_type->name); |
| 249 | |
| 250 | } |
| 251 | |
| 252 | msgb_put(msg, rval.encoded/8); |
| 253 | |
| 254 | return msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 255 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 256 | |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 257 | struct msgb *ranap_generate_initiating_message(e_RANAP_ProcedureCode procedureCode, |
| 258 | RANAP_Criticality_t criticality, |
| 259 | asn_TYPE_descriptor_t *td, void *sptr) |
| 260 | { |
| 261 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 262 | struct msgb *msg; |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 263 | int rc; |
| 264 | |
| 265 | memset(&pdu, 0, sizeof(pdu)); |
| 266 | |
| 267 | pdu.present = RANAP_RANAP_PDU_PR_initiatingMessage; |
| 268 | pdu.choice.initiatingMessage.procedureCode = procedureCode; |
| 269 | pdu.choice.initiatingMessage.criticality = criticality; |
| 270 | rc = ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr); |
| 271 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 272 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 273 | return NULL; |
| 274 | } |
| 275 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 276 | msg = _ranap_gen_msg(&pdu); |
| 277 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 278 | |
| 279 | return msg; |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 282 | struct msgb *ranap_generate_successful_outcome( |
| 283 | e_RANAP_ProcedureCode procedureCode, |
| 284 | RANAP_Criticality_t criticality, |
| 285 | asn_TYPE_descriptor_t * td, |
| 286 | void *sptr) |
| 287 | { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 288 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 289 | struct msgb *msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 290 | int rc; |
| 291 | |
| 292 | memset(&pdu, 0, sizeof(pdu)); |
Harald Welte | 8dacb07 | 2015-12-16 20:27:14 +0100 | [diff] [blame] | 293 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 294 | pdu.present = RANAP_RANAP_PDU_PR_successfulOutcome; |
| 295 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 296 | pdu.choice.successfulOutcome.criticality = criticality; |
| 297 | rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); |
| 298 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 299 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 300 | return NULL; |
| 301 | } |
| 302 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 303 | msg = _ranap_gen_msg(&pdu); |
| 304 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 305 | |
| 306 | return msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 309 | struct msgb *ranap_generate_unsuccessful_outcome( |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 310 | e_RANAP_ProcedureCode procedureCode, |
| 311 | RANAP_Criticality_t criticality, |
| 312 | asn_TYPE_descriptor_t * td, |
| 313 | void *sptr) |
| 314 | { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 315 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 316 | struct msgb *msg; |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 317 | int rc; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 318 | |
| 319 | memset(&pdu, 0, sizeof(pdu)); |
| 320 | |
| 321 | pdu.present = RANAP_RANAP_PDU_PR_unsuccessfulOutcome; |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 322 | pdu.choice.unsuccessfulOutcome.procedureCode = procedureCode; |
| 323 | pdu.choice.unsuccessfulOutcome.criticality = criticality; |
| 324 | rc = ANY_fromType_aper(&pdu.choice.unsuccessfulOutcome.value, td, sptr); |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 325 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 326 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | cbaaeef | 2015-12-16 20:17:26 +0100 | [diff] [blame] | 327 | return NULL; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 330 | msg = _ranap_gen_msg(&pdu); |
| 331 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 332 | |
| 333 | return msg; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 334 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 335 | |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 336 | struct msgb *ranap_generate_outcome( |
| 337 | e_RANAP_ProcedureCode procedureCode, |
| 338 | RANAP_Criticality_t criticality, |
| 339 | asn_TYPE_descriptor_t * td, |
| 340 | void *sptr) |
| 341 | { |
| 342 | RANAP_RANAP_PDU_t pdu; |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 343 | struct msgb *msg; |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 344 | int rc; |
| 345 | |
| 346 | memset(&pdu, 0, sizeof(pdu)); |
| 347 | |
| 348 | pdu.present = RANAP_RANAP_PDU_PR_outcome; |
| 349 | pdu.choice.outcome.procedureCode = procedureCode; |
| 350 | pdu.choice.outcome.criticality = criticality; |
| 351 | rc = ANY_fromType_aper(&pdu.choice.outcome.value, td, sptr); |
| 352 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 353 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 354 | return NULL; |
| 355 | } |
| 356 | |
Harald Welte | 2676554 | 2015-12-18 13:33:00 +0100 | [diff] [blame] | 357 | msg = _ranap_gen_msg(&pdu); |
| 358 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu); |
| 359 | |
| 360 | return msg; |
Harald Welte | c16117a | 2015-12-16 20:30:11 +0100 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 364 | RANAP_IE_t *ranap_new_ie(RANAP_ProtocolIE_ID_t id, |
| 365 | RANAP_Criticality_t criticality, |
| 366 | asn_TYPE_descriptor_t * type, void *sptr) |
| 367 | { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 368 | RANAP_IE_t *buff; |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 369 | int rc; |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 370 | |
Harald Welte | 9c397d4 | 2015-12-18 13:33:20 +0100 | [diff] [blame] | 371 | if ((buff = CALLOC(1, sizeof(*buff))) == NULL) { |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 372 | // Possible error on malloc |
| 373 | return NULL; |
| 374 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 375 | |
| 376 | buff->id = id; |
| 377 | buff->criticality = criticality; |
| 378 | |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 379 | rc = ANY_fromType_aper(&buff->value, type, sptr); |
| 380 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 381 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 382 | FREEMEM(buff); |
| 383 | return NULL; |
| 384 | } |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 385 | |
| 386 | if (asn1_xer_print) |
| 387 | if (xer_fprint(stdout, &asn_DEF_RANAP_IE, buff) < 0) { |
Harald Welte | 6293913 | 2015-12-18 14:57:04 +0100 | [diff] [blame] | 388 | FREEMEM(buff); |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 389 | return NULL; |
| 390 | } |
| 391 | |
| 392 | return buff; |
| 393 | } |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 394 | |
| 395 | RANAP_ProtocolIE_FieldPair_t *ranap_new_ie_pair(RANAP_ProtocolIE_ID_t id, |
| 396 | RANAP_Criticality_t criticality1, |
| 397 | asn_TYPE_descriptor_t *type1, void *sptr1, |
| 398 | RANAP_Criticality_t criticality2, |
| 399 | asn_TYPE_descriptor_t *type2, void *sptr2) |
| 400 | { |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 401 | RANAP_ProtocolIE_FieldPair_t *buff; |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 402 | int rc; |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 403 | |
Harald Welte | 9c397d4 | 2015-12-18 13:33:20 +0100 | [diff] [blame] | 404 | if ((buff = CALLOC(1, sizeof(*buff))) == NULL) { |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 405 | // Possible error on malloc |
| 406 | return NULL; |
| 407 | } |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 408 | |
| 409 | buff->id = id; |
| 410 | buff->firstCriticality = criticality1; |
| 411 | buff->secondCriticality = criticality2; |
| 412 | |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 413 | rc = ANY_fromType_aper(&buff->firstValue, type1, sptr1); |
| 414 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 415 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 416 | FREEMEM(buff); |
| 417 | return NULL; |
| 418 | } |
| 419 | |
| 420 | rc = ANY_fromType_aper(&buff->secondValue, type2, sptr2); |
| 421 | if (rc < 0) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 422 | LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
Harald Welte | 1623278 | 2015-12-18 17:22:04 +0100 | [diff] [blame] | 423 | ASN_STRUCT_FREE(asn_DEF_RANAP_ProtocolIE_FieldPair, buff); |
Harald Welte | 04329dc | 2015-12-18 15:17:21 +0100 | [diff] [blame] | 424 | return NULL; |
| 425 | } |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 426 | |
| 427 | if (asn1_xer_print) |
Harald Welte | 6293913 | 2015-12-18 14:57:04 +0100 | [diff] [blame] | 428 | if (xer_fprint(stdout, &asn_DEF_RANAP_ProtocolIE_FieldPair, buff) < 0) { |
Harald Welte | 1623278 | 2015-12-18 17:22:04 +0100 | [diff] [blame] | 429 | ASN_STRUCT_FREE(asn_DEF_RANAP_ProtocolIE_FieldPair, buff); |
Harald Welte | ace1d24 | 2015-12-16 23:07:19 +0100 | [diff] [blame] | 430 | return NULL; |
| 431 | } |
| 432 | |
| 433 | return buff; |
| 434 | } |