blob: 445dd850a4112e7405aa24175aab8843cca14e48 [file] [log] [blame]
Harald Welte77847ad2015-10-06 22:07:04 +02001/* 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 Welteac9c0242015-09-10 21:18:16 +020021#include <stdint.h>
22
23#include <osmocom/core/msgb.h>
Harald Welte37704d92015-12-26 08:42:31 +010024#include <osmocom/gsm/gsm48.h>
Harald Welteac9c0242015-09-10 21:18:16 +020025
Harald Welteace1d242015-12-16 23:07:19 +010026#include "ranap_common.h"
Harald Welteac9c0242015-09-10 21:18:16 +020027#include "hnbgw.h"
28
29extern int asn1_xer_print;
30
Harald Welteefef6fb2015-12-25 15:35:01 +010031const struct value_string ranap_presence_vals[5] = {
32 { RANAP_RANAP_PDU_PR_initiatingMessage, "Initiating" },
33 { RANAP_RANAP_PDU_PR_successfulOutcome, "Successful Outcome" },
34 { RANAP_RANAP_PDU_PR_unsuccessfulOutcome, "Unsuccessful Outcome" },
35 { RANAP_RANAP_PDU_PR_outcome, "(Intermediate) Outcome" },
36 { 0, NULL }
37};
38
39const struct value_string ranap_procedure_code_vals[48] = {
40 { RANAP_ProcedureCode_id_RAB_Assignment, "RAB Assignment" },
41 { RANAP_ProcedureCode_id_Iu_Release, "Iu Release" },
42 { RANAP_ProcedureCode_id_RelocationPreparation, "Relocation Preparation" },
43 { RANAP_ProcedureCode_id_RelocationResourceAllocation, "Relocation Resource Allocation" },
44 { RANAP_ProcedureCode_id_RelocationCancel, "Relocation Cancel" },
45 { RANAP_ProcedureCode_id_SRNS_ContextTransfer, "SRNS Context Transfer" },
46 { RANAP_ProcedureCode_id_SecurityModeControl, "Security Mode Control" },
47 { RANAP_ProcedureCode_id_DataVolumeReport, "Data Volume Report" },
48 { RANAP_ProcedureCode_id_Reset, "Reset" },
49 { RANAP_ProcedureCode_id_RAB_ReleaseRequest, "RAB Release Request" },
50 { RANAP_ProcedureCode_id_Iu_ReleaseRequest, "Iu Release Request" },
51 { RANAP_ProcedureCode_id_RelocationDetect, "Relocation Detect" },
52 { RANAP_ProcedureCode_id_RelocationComplete, "Relocation Complete" },
53 { RANAP_ProcedureCode_id_Paging, "Paging" },
54 { RANAP_ProcedureCode_id_CommonID, "Common ID" },
55 { RANAP_ProcedureCode_id_CN_InvokeTrace, "CN Invoke Trace" },
56 { RANAP_ProcedureCode_id_LocationReportingControl, "Location Reporting Control" },
57 { RANAP_ProcedureCode_id_LocationReport, "Location Report" },
58 { RANAP_ProcedureCode_id_InitialUE_Message, "Initial UE Message" },
59 { RANAP_ProcedureCode_id_DirectTransfer, "Direct Transfer" },
60 { RANAP_ProcedureCode_id_OverloadControl, "Overload Control" },
61 { RANAP_ProcedureCode_id_ErrorIndication, "Error Indication" },
62 { RANAP_ProcedureCode_id_SRNS_DataForward, "SRNS Data Forward" },
63 { RANAP_ProcedureCode_id_ForwardSRNS_Context, "Forward SRNS Context" },
64 { RANAP_ProcedureCode_id_privateMessage, "Private Message" },
65 { RANAP_ProcedureCode_id_CN_DeactivateTrace, "CN Deactivate Trace" },
66 { RANAP_ProcedureCode_id_ResetResource, "Reset Resource" },
67 { RANAP_ProcedureCode_id_RANAP_Relocation, "RANAP Relocation" },
68 { RANAP_ProcedureCode_id_RAB_ModifyRequest, "RAB Modify Request" },
69 { RANAP_ProcedureCode_id_LocationRelatedData, "Location Related Data" },
70 { RANAP_ProcedureCode_id_InformationTransfer, "Information Transfer" },
71 { RANAP_ProcedureCode_id_UESpecificInformation, "UE Specific Information" },
72 { RANAP_ProcedureCode_id_UplinkInformationExchange, "Uplink Information Transfer" },
73 { RANAP_ProcedureCode_id_DirectInformationTransfer, "Direct Information Transfer" },
74 { RANAP_ProcedureCode_id_MBMSSessionStart, "MBMS Session Start" },
75 { RANAP_ProcedureCode_id_MBMSSessionUpdate, "MBMS Session Update" },
76 { RANAP_ProcedureCode_id_MBMSSessionStop, "MBMS Session Stop" },
77 { RANAP_ProcedureCode_id_MBMSUELinking, "MBMS UE Linking" },
78 { RANAP_ProcedureCode_id_MBMSRegistration, "MBMS Registration" },
79 { RANAP_ProcedureCode_id_MBMSCNDe_Registration_Procedure, "MBMS CN De-Registration" },
80 { RANAP_ProcedureCode_id_MBMSRABEstablishmentIndication, "MBMS RAB Establishment Indication" },
81 { RANAP_ProcedureCode_id_MBMSRABRelease, "MBMS RAB Release" },
82 { RANAP_ProcedureCode_id_enhancedRelocationComplete, "Enhanced Relocation Complete" },
83 { RANAP_ProcedureCode_id_enhancedRelocationCompleteConfirm, "Enhanced Relocation Complete Confirm" },
84 { RANAP_ProcedureCode_id_RANAPenhancedRelocation, "RANAP Enhanced Relocation" },
85 { RANAP_ProcedureCode_id_SRVCCPreparation, "SRVCC Preparation" },
86 { RANAP_ProcedureCode_id_UeRadioCapabilityMatch, "UE Radio Capability Match" },
87 { 0, NULL }
88};
89
Harald Welte3d39f842015-12-25 09:40:07 +010090static const struct value_string ranap_cause_radio_vals[] = {
91 { RANAP_CauseRadioNetwork_rab_pre_empted, "RAB pre-empted" },
92 { RANAP_CauseRadioNetwork_trelocoverall_expiry, "Treloc_overall expiry" },
93 { RANAP_CauseRadioNetwork_trelocprep_expiry, "Treloc_prep expiry" },
94 { RANAP_CauseRadioNetwork_treloccomplete_expiry,"Treloc_complete expiry" },
95 { RANAP_CauseRadioNetwork_tqueing_expiry, "Tqueueing expiry" },
96 { RANAP_CauseRadioNetwork_relocation_triggered, "Relocation triggered" },
97 { RANAP_CauseRadioNetwork_trellocalloc_expiry, "Treloc_alloc expiry" },
98 { RANAP_CauseRadioNetwork_unable_to_establish_during_relocation,
99 "unable to establish during relocation" },
100 { RANAP_CauseRadioNetwork_unknown_target_rnc,
101 "unknown target RNC" },
102 { RANAP_CauseRadioNetwork_relocation_cancelled, "Relocation cancelled" },
103 { RANAP_CauseRadioNetwork_successful_relocation, "Successful relocation" },
104 { RANAP_CauseRadioNetwork_requested_ciphering_and_or_integrity_protection_algorithms_not_supported,
105 "requested ciph. and/or int. prot. algorithms not supported" },
106 { RANAP_CauseRadioNetwork_conflict_with_already_existing_integrity_protection_and_or_ciphering_information,
107 "conflict with existing int. prot. and/or ciph. information" },
108 { RANAP_CauseRadioNetwork_failure_in_the_radio_interface_procedure,
109 "failure in the radio interface procedure" },
110 { RANAP_CauseRadioNetwork_release_due_to_utran_generated_reason,
111 "release due to UTRAN generated reason" },
112 { RANAP_CauseRadioNetwork_user_inactivity, "user inactivity" },
113 { RANAP_CauseRadioNetwork_time_critical_relocation,
114 "time critical relocation" },
115 { RANAP_CauseRadioNetwork_requested_traffic_class_not_available,
116 "requested traffic class not available" },
117 { RANAP_CauseRadioNetwork_invalid_rab_parameters_value,
118 "invalid RAB parameters value" },
119 { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_not_available,
120 "requested max. bit-rate not available" },
121 { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_not_available,
122 "requested guaranteed bit-rate not available" },
123 { RANAP_CauseRadioNetwork_requested_transfer_delay_not_achievable,
124 "requested transfer delay not achievable" },
125 { RANAP_CauseRadioNetwork_invalid_rab_parameters_combination,
126 "invalid RAB parameters combination" },
127 { RANAP_CauseRadioNetwork_condition_violation_for_sdu_parameters,
128 "condition violation for SDU parameters" },
129 { RANAP_CauseRadioNetwork_condition_violation_for_traffic_handling_priority,
130 "condition violation for traffic handling priority" },
131 { RANAP_CauseRadioNetwork_condition_violation_for_guaranteed_bit_rate,
132 "condition violation for guaranteed bit-rate" },
133 { RANAP_CauseRadioNetwork_user_plane_versions_not_supported,
134 "user-plane versions not supported" },
135 { RANAP_CauseRadioNetwork_iu_up_failure, "Iu-UP failure" },
136 { RANAP_CauseRadioNetwork_relocation_failure_in_target_CN_RNC_or_target_system,
137 "relocation failure in target CN/RNC or target system" },
138 { RANAP_CauseRadioNetwork_invalid_RAB_ID, "Invalid RAB ID" },
139 { RANAP_CauseRadioNetwork_no_remaining_rab, "No remaining RAB" },
140 { RANAP_CauseRadioNetwork_interaction_with_other_procedure,
141 "interaction with other procedure" },
142 { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_for_dl_not_available,
143 "requested maximum bit-rate for DL not available" },
144 { RANAP_CauseRadioNetwork_requested_maximum_bit_rate_for_ul_not_available,
145 "requested maximum bit-rate for UL not available" },
146 { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_for_dl_not_available,
147 "requested guaranteed bit-rate for DL not available" },
148 { RANAP_CauseRadioNetwork_requested_guaranteed_bit_rate_for_ul_not_available,
149 "requested guaranteed bit-rate for UL not available" },
150 { RANAP_CauseRadioNetwork_repeated_integrity_checking_failure,
151 "repeated integrity checking failure" },
152 { RANAP_CauseRadioNetwork_requested_request_type_not_supported,
153 "requested request type not supported" },
154 { RANAP_CauseRadioNetwork_request_superseded, "request superseded" },
155 { RANAP_CauseRadioNetwork_release_due_to_UE_generated_signalling_connection_release,
156 "release due to UE-generated signalling connection release" },
157 { RANAP_CauseRadioNetwork_resource_optimisation_relocation,
158 "resource optimisation relocation" },
159 { RANAP_CauseRadioNetwork_requested_information_not_available,
160 "requested information not available" },
161 { RANAP_CauseRadioNetwork_relocation_desirable_for_radio_reasons,
162 "relocation desirable for radio reasons" },
163 { RANAP_CauseRadioNetwork_relocation_not_supported_in_target_RNC_or_target_system,
164 "relocation not supported in target RNC or target system" },
165 { RANAP_CauseRadioNetwork_directed_retry, "directed retry" },
166 { RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost,
167 "radio connection with UE lost" },
168 { RANAP_CauseRadioNetwork_rNC_unable_to_establish_all_RFCs,
169 "RNC unable to establish al RFCs" },
170 { RANAP_CauseRadioNetwork_deciphering_keys_not_available,
171 "de-ciphering keys not available" },
172 { RANAP_CauseRadioNetwork_dedicated_assistance_data_not_available,
173 "dedicated assistance data not available" },
174 { RANAP_CauseRadioNetwork_relocation_target_not_allowed,
175 "relocation target not allowed" },
176 { RANAP_CauseRadioNetwork_location_reporting_congestion,
177 "relocation reporting congestion" },
178 { RANAP_CauseRadioNetwork_reduce_load_in_serving_cell,
179 "reduce load in serving cell" },
180 { RANAP_CauseRadioNetwork_no_radio_resources_available_in_target_cell,
181 "no radio resources available in target cell" },
182 { RANAP_CauseRadioNetwork_gERAN_Iumode_failure,
183 "GERAN Iu-Mode failure" },
184 { RANAP_CauseRadioNetwork_access_restricted_due_to_shared_networks,
185 "access restricted due to shared networks" },
186 { RANAP_CauseRadioNetwork_incoming_relocation_not_supported_due_to_PUESBINE_feature,
187 "incoming relocation not supported due to PUESBINE feature" },
188 { RANAP_CauseRadioNetwork_traffic_load_in_the_target_cell_higher_than_in_the_source_cell,
189 "traffic load in the target cell higher than in the source cell" },
190 { RANAP_CauseRadioNetwork_mBMS_no_multicast_service_for_this_UE,
191 "MBMS: no multicast service for this UE" },
192 { RANAP_CauseRadioNetwork_mBMS_unknown_UE_ID, "MBMS: unknown UE ID" },
193 { RANAP_CauseRadioNetwork_successful_MBMS_session_start_no_data_bearer_necessary,
194 "successful MBMS session start; no data bearer necessarry" },
195 { RANAP_CauseRadioNetwork_mBMS_superseded_due_to_NNSF,
196 "MBMS superseded due to NNSF" },
197 { RANAP_CauseRadioNetwork_mBMS_UE_linking_already_done,
198 "MBMS: UE linking already done" },
199 { RANAP_CauseRadioNetwork_mBMS_UE_de_linking_failure_no_existing_UE_linking,
200 "MBMS: UE de-linking failure; no existing UE linking" },
201 { RANAP_CauseRadioNetwork_tMGI_unknown, "TMGI unknown" },
202 { 0, NULL }
203};
204
205static const struct value_string ranap_cause_transm_vals[] = {
206 { RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure,
207 "signalling transport resource failure" },
208 { RANAP_CauseTransmissionNetwork_iu_transport_connection_failed_to_establish,
209 "Iu transport connection failed to establish" },
210 { 0, NULL }
211};
212
213static const struct value_string ranap_cause_nas_vals[] = {
214 { RANAP_CauseNAS_user_restriction_start_indication,
215 "user restriction; start indication" },
216 { RANAP_CauseNAS_user_restriction_end_indication,
217 "user restriction; stop indication" },
218 { RANAP_CauseNAS_normal_release,
219 "normal release" },
220 { RANAP_CauseNAS_csg_subscription_expiry,
221 "CSG subscription expiry" },
222 { 0, NULL }
223};
224
225static const struct value_string ranap_cause_prot_vals[] = {
226 { RANAP_CauseProtocol_transfer_syntax_error,
227 "transfer sytax error" },
228 { RANAP_CauseProtocol_semantic_error,
229 "semantic error" },
230 { RANAP_CauseProtocol_message_not_compatible_with_receiver_state,
231 "message not compatible with receiver state" },
232 { RANAP_CauseProtocol_abstract_syntax_error_reject,
233 "syntax error: reject" },
234 { RANAP_CauseProtocol_abstract_syntax_error_ignore_and_notify,
235 "syntax error: ignore and notify" },
236 { RANAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message,
237 "syntax error: falsely constructed message" },
238 { 0, NULL }
239};
240
241static const struct value_string ranap_cause_misc_vals[] = {
242 { RANAP_CauseMisc_om_intervention, "OAM intervention" },
243 { RANAP_CauseMisc_no_resource_available, "no resource available" },
244 { RANAP_CauseMisc_unspecified_failure, "unspecified failure" },
245 { RANAP_CauseMisc_network_optimisation, "network optimisation" },
246 { 0, NULL }
247};
248
249char *ranap_cause_str(const RANAP_Cause_t *cause)
250{
251 static char buf[128];
252
253 switch (cause->present) {
254 case RANAP_Cause_PR_radioNetwork:
255 snprintf(buf, sizeof(buf), "radio(%s)",
256 get_value_string(ranap_cause_radio_vals,
257 cause->choice.radioNetwork));
258 break;
259 case RANAP_Cause_PR_transmissionNetwork:
260 snprintf(buf, sizeof(buf), "transmission(%s)",
261 get_value_string(ranap_cause_transm_vals,
262 cause->choice.transmissionNetwork));
263 break;
264 case RANAP_Cause_PR_nAS:
265 snprintf(buf, sizeof(buf), "nas(%s)",
266 get_value_string(ranap_cause_nas_vals,
267 cause->choice.nAS));
268 break;
269 case RANAP_Cause_PR_protocol:
270 snprintf(buf, sizeof(buf), "protocol(%s)",
271 get_value_string(ranap_cause_prot_vals,
272 cause->choice.protocol));
273 break;
274 case RANAP_Cause_PR_misc:
275 snprintf(buf, sizeof(buf), "misc(%s)",
276 get_value_string(ranap_cause_misc_vals,
277 cause->choice.misc));
278 break;
279 case RANAP_Cause_PR_non_Standard:
280 snprintf(buf, sizeof(buf), "non-standard(%u)",
281 cause->choice.non_Standard);
282 break;
283 default:
284 strcpy(buf, "unknown");
285 break;
286 }
287 return buf;
288}
289
290
Harald Welteac9c0242015-09-10 21:18:16 +0200291static struct msgb *ranap_msgb_alloc(void)
292{
293 return msgb_alloc(1024, "RANAP Tx");
294}
295
Harald Welte8dacb072015-12-16 20:27:14 +0100296static struct msgb *_ranap_gen_msg(RANAP_RANAP_PDU_t *pdu)
Harald Welteac9c0242015-09-10 21:18:16 +0200297{
Harald Weltecbaaeef2015-12-16 20:17:26 +0100298 struct msgb *msg = ranap_msgb_alloc();
299 asn_enc_rval_t rval;
Harald Welteac9c0242015-09-10 21:18:16 +0200300
Harald Welte8dacb072015-12-16 20:27:14 +0100301 if (!msg)
Harald Weltecbaaeef2015-12-16 20:17:26 +0100302 return NULL;
Harald Welteac9c0242015-09-10 21:18:16 +0200303
Harald Welte8dacb072015-12-16 20:27:14 +0100304 rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, pdu,
Harald Weltecbaaeef2015-12-16 20:17:26 +0100305 msg->data, msgb_tailroom(msg));
306 if (rval.encoded < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100307 LOGP(DRANAP, LOGL_ERROR, "Error encoding type: %s\n",
Harald Weltecbaaeef2015-12-16 20:17:26 +0100308 rval.failed_type->name);
309
310 }
311
312 msgb_put(msg, rval.encoded/8);
313
314 return msg;
Harald Welteac9c0242015-09-10 21:18:16 +0200315}
Harald Welteac9c0242015-09-10 21:18:16 +0200316
Harald Welte8dacb072015-12-16 20:27:14 +0100317struct msgb *ranap_generate_initiating_message(e_RANAP_ProcedureCode procedureCode,
318 RANAP_Criticality_t criticality,
319 asn_TYPE_descriptor_t *td, void *sptr)
320{
321 RANAP_RANAP_PDU_t pdu;
Harald Welte26765542015-12-18 13:33:00 +0100322 struct msgb *msg;
Harald Welte8dacb072015-12-16 20:27:14 +0100323 int rc;
324
325 memset(&pdu, 0, sizeof(pdu));
326
327 pdu.present = RANAP_RANAP_PDU_PR_initiatingMessage;
328 pdu.choice.initiatingMessage.procedureCode = procedureCode;
329 pdu.choice.initiatingMessage.criticality = criticality;
330 rc = ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr);
331 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100332 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Welte8dacb072015-12-16 20:27:14 +0100333 return NULL;
334 }
335
Harald Welte26765542015-12-18 13:33:00 +0100336 msg = _ranap_gen_msg(&pdu);
337 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu);
338
339 return msg;
Harald Welte8dacb072015-12-16 20:27:14 +0100340}
341
Harald Welteac9c0242015-09-10 21:18:16 +0200342struct msgb *ranap_generate_successful_outcome(
343 e_RANAP_ProcedureCode procedureCode,
344 RANAP_Criticality_t criticality,
345 asn_TYPE_descriptor_t * td,
346 void *sptr)
347{
Harald Welteac9c0242015-09-10 21:18:16 +0200348 RANAP_RANAP_PDU_t pdu;
Harald Welte26765542015-12-18 13:33:00 +0100349 struct msgb *msg;
Harald Welteac9c0242015-09-10 21:18:16 +0200350 int rc;
351
352 memset(&pdu, 0, sizeof(pdu));
Harald Welte8dacb072015-12-16 20:27:14 +0100353
Harald Welteac9c0242015-09-10 21:18:16 +0200354 pdu.present = RANAP_RANAP_PDU_PR_successfulOutcome;
355 pdu.choice.successfulOutcome.procedureCode = procedureCode;
356 pdu.choice.successfulOutcome.criticality = criticality;
357 rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
358 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100359 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Welteac9c0242015-09-10 21:18:16 +0200360 return NULL;
361 }
362
Harald Welte26765542015-12-18 13:33:00 +0100363 msg = _ranap_gen_msg(&pdu);
364 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu);
365
366 return msg;
Harald Welteac9c0242015-09-10 21:18:16 +0200367}
368
Harald Weltecbaaeef2015-12-16 20:17:26 +0100369struct msgb *ranap_generate_unsuccessful_outcome(
Harald Welteac9c0242015-09-10 21:18:16 +0200370 e_RANAP_ProcedureCode procedureCode,
371 RANAP_Criticality_t criticality,
372 asn_TYPE_descriptor_t * td,
373 void *sptr)
374{
Harald Welteac9c0242015-09-10 21:18:16 +0200375 RANAP_RANAP_PDU_t pdu;
Harald Welte26765542015-12-18 13:33:00 +0100376 struct msgb *msg;
Harald Weltecbaaeef2015-12-16 20:17:26 +0100377 int rc;
Harald Welteac9c0242015-09-10 21:18:16 +0200378
379 memset(&pdu, 0, sizeof(pdu));
380
381 pdu.present = RANAP_RANAP_PDU_PR_unsuccessfulOutcome;
Harald Weltec16117a2015-12-16 20:30:11 +0100382 pdu.choice.unsuccessfulOutcome.procedureCode = procedureCode;
383 pdu.choice.unsuccessfulOutcome.criticality = criticality;
384 rc = ANY_fromType_aper(&pdu.choice.unsuccessfulOutcome.value, td, sptr);
Harald Weltecbaaeef2015-12-16 20:17:26 +0100385 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100386 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Weltecbaaeef2015-12-16 20:17:26 +0100387 return NULL;
Harald Welteac9c0242015-09-10 21:18:16 +0200388 }
389
Harald Welte26765542015-12-18 13:33:00 +0100390 msg = _ranap_gen_msg(&pdu);
391 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu);
392
393 return msg;
Harald Welteac9c0242015-09-10 21:18:16 +0200394}
Harald Welteac9c0242015-09-10 21:18:16 +0200395
Harald Weltec16117a2015-12-16 20:30:11 +0100396struct msgb *ranap_generate_outcome(
397 e_RANAP_ProcedureCode procedureCode,
398 RANAP_Criticality_t criticality,
399 asn_TYPE_descriptor_t * td,
400 void *sptr)
401{
402 RANAP_RANAP_PDU_t pdu;
Harald Welte26765542015-12-18 13:33:00 +0100403 struct msgb *msg;
Harald Weltec16117a2015-12-16 20:30:11 +0100404 int rc;
405
406 memset(&pdu, 0, sizeof(pdu));
407
408 pdu.present = RANAP_RANAP_PDU_PR_outcome;
409 pdu.choice.outcome.procedureCode = procedureCode;
410 pdu.choice.outcome.criticality = criticality;
411 rc = ANY_fromType_aper(&pdu.choice.outcome.value, td, sptr);
412 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100413 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Weltec16117a2015-12-16 20:30:11 +0100414 return NULL;
415 }
416
Harald Welte26765542015-12-18 13:33:00 +0100417 msg = _ranap_gen_msg(&pdu);
418 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, &pdu);
419
420 return msg;
Harald Weltec16117a2015-12-16 20:30:11 +0100421}
422
423
Harald Welteac9c0242015-09-10 21:18:16 +0200424RANAP_IE_t *ranap_new_ie(RANAP_ProtocolIE_ID_t id,
425 RANAP_Criticality_t criticality,
426 asn_TYPE_descriptor_t * type, void *sptr)
427{
Harald Welteac9c0242015-09-10 21:18:16 +0200428 RANAP_IE_t *buff;
Harald Welte04329dc2015-12-18 15:17:21 +0100429 int rc;
Harald Welteac9c0242015-09-10 21:18:16 +0200430
Harald Welte9c397d42015-12-18 13:33:20 +0100431 if ((buff = CALLOC(1, sizeof(*buff))) == NULL) {
Harald Welteac9c0242015-09-10 21:18:16 +0200432 // Possible error on malloc
433 return NULL;
434 }
Harald Welteac9c0242015-09-10 21:18:16 +0200435
436 buff->id = id;
437 buff->criticality = criticality;
438
Harald Welte04329dc2015-12-18 15:17:21 +0100439 rc = ANY_fromType_aper(&buff->value, type, sptr);
440 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100441 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Welte04329dc2015-12-18 15:17:21 +0100442 FREEMEM(buff);
443 return NULL;
444 }
Harald Welteac9c0242015-09-10 21:18:16 +0200445
446 if (asn1_xer_print)
447 if (xer_fprint(stdout, &asn_DEF_RANAP_IE, buff) < 0) {
Harald Welte62939132015-12-18 14:57:04 +0100448 FREEMEM(buff);
Harald Welteac9c0242015-09-10 21:18:16 +0200449 return NULL;
450 }
451
452 return buff;
453}
Harald Welteace1d242015-12-16 23:07:19 +0100454
455RANAP_ProtocolIE_FieldPair_t *ranap_new_ie_pair(RANAP_ProtocolIE_ID_t id,
456 RANAP_Criticality_t criticality1,
457 asn_TYPE_descriptor_t *type1, void *sptr1,
458 RANAP_Criticality_t criticality2,
459 asn_TYPE_descriptor_t *type2, void *sptr2)
460{
Harald Welteace1d242015-12-16 23:07:19 +0100461 RANAP_ProtocolIE_FieldPair_t *buff;
Harald Welte04329dc2015-12-18 15:17:21 +0100462 int rc;
Harald Welteace1d242015-12-16 23:07:19 +0100463
Harald Welte9c397d42015-12-18 13:33:20 +0100464 if ((buff = CALLOC(1, sizeof(*buff))) == NULL) {
Harald Welteace1d242015-12-16 23:07:19 +0100465 // Possible error on malloc
466 return NULL;
467 }
Harald Welteace1d242015-12-16 23:07:19 +0100468
469 buff->id = id;
470 buff->firstCriticality = criticality1;
471 buff->secondCriticality = criticality2;
472
Harald Welte04329dc2015-12-18 15:17:21 +0100473 rc = ANY_fromType_aper(&buff->firstValue, type1, sptr1);
474 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100475 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Welte04329dc2015-12-18 15:17:21 +0100476 FREEMEM(buff);
477 return NULL;
478 }
479
480 rc = ANY_fromType_aper(&buff->secondValue, type2, sptr2);
481 if (rc < 0) {
Harald Weltef42317b2015-12-23 15:36:31 +0100482 LOGP(DRANAP, LOGL_ERROR, "Error in ANY_fromType_aper\n");
Harald Welte16232782015-12-18 17:22:04 +0100483 ASN_STRUCT_FREE(asn_DEF_RANAP_ProtocolIE_FieldPair, buff);
Harald Welte04329dc2015-12-18 15:17:21 +0100484 return NULL;
485 }
Harald Welteace1d242015-12-16 23:07:19 +0100486
487 if (asn1_xer_print)
Harald Welte62939132015-12-18 14:57:04 +0100488 if (xer_fprint(stdout, &asn_DEF_RANAP_ProtocolIE_FieldPair, buff) < 0) {
Harald Welte16232782015-12-18 17:22:04 +0100489 ASN_STRUCT_FREE(asn_DEF_RANAP_ProtocolIE_FieldPair, buff);
Harald Welteace1d242015-12-16 23:07:19 +0100490 return NULL;
491 }
492
493 return buff;
494}
Harald Welte37704d92015-12-26 08:42:31 +0100495
496int ranap_parse_lai(struct gprs_ra_id *ra_id, const RANAP_LAI_t *lai)
497{
498 uint8_t *ptr = lai->pLMNidentity.buf;
499
500 /* TS 25.413 9.2.3.55 */
501 if (lai->pLMNidentity.size != 3)
502 return -1;
503
504 ra_id->mcc = (ptr[0] & 0xF) * 100 +
505 (ptr[0] >> 4) * 10 +
506 (ptr[1] & 0xF);
507 ra_id->mnc = (ptr[2] & 0xF) +
508 (ptr[2] >> 4) * 10;
509 if ((ptr[1] >> 4) != 0xF)
510 ra_id->mnc += (ptr[1] >> 4) * 100;
511
512 ra_id->lac = asn1str_to_u16(&lai->lAC);
513
514 /* TS 25.413 9.2.3.6 */
515 if (ra_id->lac == 0 || ra_id->lac == 0xfffe)
516 return -1;
517
518 return 0;
519}