blob: 799629ee9dbfb402e85ec531f74748d65faf0ad5 [file] [log] [blame]
Harald Welte3cfa4502015-12-25 15:33:41 +01001/* RANAP interface for a core-network node */
2
3/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include <unistd.h>
22#include <errno.h>
23#include <string.h>
24
25#include <osmocom/core/utils.h>
26#include <osmocom/core/logging.h>
27
Neels Hofmeyr96979af2016-01-05 15:19:44 +010028#include <osmocom/ranap/ranap_common.h>
29#include <osmocom/ranap/ranap_ies_defs.h>
Harald Weltecee5a282015-12-26 08:43:31 +010030#include "ranap_common_cn.h"
Harald Welte3cfa4502015-12-25 15:33:41 +010031
Harald Weltecee5a282015-12-26 08:43:31 +010032#include "hnbgw.h"
Harald Welte3cfa4502015-12-25 15:33:41 +010033
34static int cn_ranap_rx_initiating_msg_co(void *ctx, RANAP_InitiatingMessage_t *imsg,
35 ranap_message *message)
36{
37 int rc = 0;
38
39 message->procedureCode = imsg->procedureCode;
40 message->criticality = imsg->criticality;
41
42 DEBUGP(DRANAP, "Rx CO IM (%s)\n",
43 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
44
45 switch (imsg->procedureCode) {
46 case RANAP_ProcedureCode_id_InitialUE_Message:
47 rc = ranap_decode_initialue_messageies(&message->msg.initialUE_MessageIEs, &imsg->value);
48 break;
49 case RANAP_ProcedureCode_id_DirectTransfer:
50 rc = ranap_decode_directtransferies(&message->msg.directTransferIEs, &imsg->value);
51 break;
52 case RANAP_ProcedureCode_id_RAB_ReleaseRequest:
53 /* RNC requests the release of RAB */
54 rc = ranap_decode_rab_releaserequesties(&message->msg.raB_ReleaseRequestIEs, &imsg->value);
55 break;
56 case RANAP_ProcedureCode_id_Iu_ReleaseRequest:
57 /* RNC requests the release of Iu */
58 rc = ranap_decode_iu_releaserequesties(&message->msg.iu_ReleaseRequestIEs, &imsg->value);
59 break;
60 case RANAP_ProcedureCode_id_ErrorIndication:
61 rc = ranap_decode_errorindicationies(&message->msg.errorIndicationIEs, &imsg->value);
62 break;
63 case RANAP_ProcedureCode_id_RAB_ModifyRequest:
64 rc = ranap_decode_rab_modifyrequesties(&message->msg.raB_ModifyRequestIEs, &imsg->value);
65 break;
66 default:
67 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
68 "Procedure %s (CO, IM) from RNC, ignoring\n",
69 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
70 rc = -1;
71 break;
72 }
73
74 return rc;
75}
76
77static int cn_ranap_rx_successful_msg_co(void *ctx, RANAP_SuccessfulOutcome_t *imsg,
78 ranap_message *message)
79{
80 int rc = 0;
81
82 message->procedureCode = imsg->procedureCode;
83 message->criticality = imsg->criticality;
84
Harald Weltea31e63a2015-12-28 13:19:35 +010085 DEBUGP(DRANAP, "Rx CO SO (%s)\n",
Harald Welte3cfa4502015-12-25 15:33:41 +010086 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
87
88 switch (imsg->procedureCode) {
89 case RANAP_ProcedureCode_id_RAB_Assignment:
90 /* RAB assignment response */
91 rc = ranap_decode_rab_assignmentresponseies(&message->msg.raB_AssignmentResponseIEs, &imsg->value);
92 break;
93 case RANAP_ProcedureCode_id_SecurityModeControl:
94 /* Security Mode Complete */
95 rc = ranap_decode_securitymodecompleteies(&message->msg.securityModeCompleteIEs, &imsg->value);
96 break;
97 case RANAP_ProcedureCode_id_Iu_Release:
98 /* Iu release Complete; confirmation of CN-initiated release */
99 rc = ranap_decode_iu_releasecompleteies(&message->msg.iu_ReleaseCompleteIEs, &imsg->value);
100 break;
101 default:
102 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
103 "Procedure %s (SO) from RNC, ignoring\n",
104 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
105 rc = -1;
106 break;
107 }
108
109 return rc;
110}
111
Harald Welte7bccc982015-12-28 14:44:49 +0100112static int cn_ranap_rx_outcome_msg_co(void *ctx, RANAP_Outcome_t *imsg,
113 ranap_message *message)
114{
115 int rc = 0;
116
117 message->procedureCode = imsg->procedureCode;
118 message->criticality = imsg->criticality;
119
120 DEBUGP(DRANAP, "Rx CO O (%s)\n",
121 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
122
123 switch (imsg->procedureCode) {
124 case RANAP_ProcedureCode_id_RAB_Assignment:
125 /* RAB assignment response */
126 rc = ranap_decode_rab_assignmentresponseies(&message->msg.raB_AssignmentResponseIEs, &imsg->value);
127 break;
128 default:
129 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
130 "Procedure %s (O) from RNC, ignoring\n",
131 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
132 rc = -1;
133 break;
134 }
135
136 return rc;
137}
138
Harald Welte3cfa4502015-12-25 15:33:41 +0100139static int _cn_ranap_rx_co(void *ctx, RANAP_RANAP_PDU_t *pdu, ranap_message *message)
140{
141 int rc = 0;
142
143 switch (pdu->present) {
144 case RANAP_RANAP_PDU_PR_initiatingMessage:
145 rc = cn_ranap_rx_initiating_msg_co(ctx, &pdu->choice.initiatingMessage, message);
146 break;
147 case RANAP_RANAP_PDU_PR_successfulOutcome:
148 rc = cn_ranap_rx_successful_msg_co(ctx, &pdu->choice.successfulOutcome, message);
149 break;
150 case RANAP_RANAP_PDU_PR_unsuccessfulOutcome:
151 LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP "
152 "unsuccessful outcome procedure %s (CO) from RNC, ignoring\n",
153 get_value_string(ranap_procedure_code_vals,
154 pdu->choice.unsuccessfulOutcome.procedureCode));
155 rc = -1;
156 break;
Harald Welte7bccc982015-12-28 14:44:49 +0100157 case RANAP_RANAP_PDU_PR_outcome:
158 rc = cn_ranap_rx_outcome_msg_co(ctx, &pdu->choice.successfulOutcome, message);
159 break;
Harald Welte3cfa4502015-12-25 15:33:41 +0100160 default:
161 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
162 "presence %s (CO) from RNC, ignoring\n",
163 get_value_string(ranap_presence_vals, pdu->present));
164 rc = -1;
165 break;
166 }
167
168 return rc;
169}
170
171/* receive a connection-oriented RANAP message and call
172 * cn_ranap_handle_co() with the resulting ranap_message struct */
173int cn_ranap_rx_co(void *ctx, uint8_t *data, size_t len)
174{
175 RANAP_RANAP_PDU_t *pdu = NULL;
176 ranap_message message;
177 asn_dec_rval_t dec_ret;
178 int rc;
179
180 memset(&message, 0, sizeof(message));
181
Harald Welte3cfa4502015-12-25 15:33:41 +0100182 dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu,
183 data, len, 0, 0);
184 if (dec_ret.code != RC_OK) {
185 LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n");
186 return rc;
187 }
188
189 message.direction = pdu->present;
190
191 rc = _cn_ranap_rx_co(ctx, pdu, &message);
192
193 if (rc == 0)
194 cn_ranap_handle_co(ctx, &message);
Harald Welte49287972015-12-29 19:00:35 +0100195 else
196 LOGP(DRANAP, LOGL_ERROR, "Not calling cn_ranap_handle_co() due to rc=%d\n", rc);
Harald Welte3cfa4502015-12-25 15:33:41 +0100197
198 ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
199
200 return rc;
201}
202
203static int cn_ranap_rx_initiating_msg_cl(void *ctx, RANAP_InitiatingMessage_t *imsg,
204 ranap_message *message)
205{
206 int rc;
207
208 message->procedureCode = imsg->procedureCode;
209 message->criticality = imsg->criticality;
210
211 DEBUGP(DRANAP, "Rx CL IM (%s)\n",
212 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
213
214 switch (imsg->procedureCode) {
215 case RANAP_ProcedureCode_id_Reset:
216 /* Reset request */
217 rc = ranap_decode_reseties(&message->msg.resetIEs, &imsg->value);
218 break;
219 case RANAP_ProcedureCode_id_OverloadControl: /* Overload ind */
220 rc = ranap_decode_overloadies(&message->msg.overloadIEs, &imsg->value);
221 break;
222 case RANAP_ProcedureCode_id_ErrorIndication: /* Error ind */
223 rc = ranap_decode_errorindicationies(&message->msg.errorIndicationIEs, &imsg->value);
224 break;
225 case RANAP_ProcedureCode_id_ResetResource: /* request */
226 rc = ranap_decode_resetresourceies(&message->msg.resetResourceIEs, &imsg->value);
227 break;
228 case RANAP_ProcedureCode_id_InformationTransfer:
229 rc = ranap_decode_informationtransferindicationies(&message->msg.informationTransferIndicationIEs, &imsg->value);
230 break;
231 case RANAP_ProcedureCode_id_DirectInformationTransfer:
232 rc = ranap_decode_directinformationtransferies(&message->msg.directInformationTransferIEs, &imsg->value);
233 break;
234 case RANAP_ProcedureCode_id_UplinkInformationExchange:
235 rc = ranap_decode_uplinkinformationexchangerequesties(&message->msg.uplinkInformationExchangeRequestIEs, &imsg->value);
236 break;
237 default:
238 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
239 "Procedure %s (CL, IM) from RNC, ignoring\n",
240 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
241 break;
242 }
243}
244
245static int cn_ranap_rx_successful_msg_cl(void *ctx, RANAP_SuccessfulOutcome_t *imsg,
246 ranap_message *message)
247{
248 int rc;
249
250 message->procedureCode = imsg->procedureCode;
251 message->criticality = imsg->criticality;
252
253 DEBUGP(DRANAP, "Rx CL SO (%s)\n",
254 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
255
256 switch (imsg->procedureCode) {
257 case RANAP_ProcedureCode_id_Reset: /* Reset acknowledge */
258 rc = ranap_decode_resetacknowledgeies(&message->msg.resetAcknowledgeIEs, &imsg->value);
259 break;
260 case RANAP_ProcedureCode_id_ResetResource: /* response */
261 rc = ranap_decode_resetresourceacknowledgeies(&message->msg.resetResourceAcknowledgeIEs, &imsg->value);
262 case RANAP_ProcedureCode_id_InformationTransfer:
263 rc = ranap_decode_resetresourceacknowledgeies(&message->msg.resetResourceAcknowledgeIEs, &imsg->value);
264 break;
265 case RANAP_ProcedureCode_id_DirectInformationTransfer:
266 rc = ranap_decode_informationtransferconfirmationies(&message->msg.informationTransferConfirmationIEs, &imsg->value);
267 break;
268 case RANAP_ProcedureCode_id_UplinkInformationExchange:
269 rc = ranap_decode_uplinkinformationexchangeresponseies(&message->msg.uplinkInformationExchangeResponseIEs, &imsg->value);
270 break;
271 default:
272 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
273 "Procedure %s (CL, SO) from RNC, ignoring\n",
274 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
275 break;
276 }
277}
278
279static int _cn_ranap_rx_cl(void *ctx, RANAP_RANAP_PDU_t *pdu, ranap_message *message)
280{
281 int rc;
282
283 switch (pdu->present) {
284 case RANAP_RANAP_PDU_PR_initiatingMessage:
285 rc = cn_ranap_rx_initiating_msg_cl(ctx, &pdu->choice.initiatingMessage,
286 message);
287 break;
288 case RANAP_RANAP_PDU_PR_successfulOutcome:
289 rc = cn_ranap_rx_successful_msg_cl(ctx, &pdu->choice.successfulOutcome,
290 message);
291 break;
292 case RANAP_RANAP_PDU_PR_unsuccessfulOutcome:
293 LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP "
294 "unsuccessful outcome procedure %s (CL) from RNC, ignoring\n",
295 get_value_string(ranap_procedure_code_vals,
296 pdu->choice.unsuccessfulOutcome.procedureCode));
297 break;
298 default:
299 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
300 "presence %s (CL) from RNC, ignoring\n",
301 get_value_string(ranap_presence_vals, pdu->present));
302 break;
303 }
304}
305
306/* receive a connection-oriented RANAP message and call
307 * cn_ranap_handle_co() with the resulting ranap_message struct */
308int cn_ranap_rx_cl(void *ctx, uint8_t *data, size_t len)
309{
310 RANAP_RANAP_PDU_t *pdu = NULL;
311 ranap_message message;
312 asn_dec_rval_t dec_ret;
313 int rc;
314
315 memset(&message, 0, sizeof(message));
316
Harald Welte3cfa4502015-12-25 15:33:41 +0100317 dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu,
318 data, len, 0, 0);
319 if (dec_ret.code != RC_OK) {
320 LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n");
321 return rc;
322 }
323
324 message.direction = pdu->present;
325
326 rc = _cn_ranap_rx_cl(ctx, pdu, &message);
327
328 if (rc == 0)
329 cn_ranap_handle_cl(ctx, &message);
Harald Welte49287972015-12-29 19:00:35 +0100330 else
331 LOGP(DRANAP, LOGL_ERROR, "Not calling cn_ranap_handle_cl() due to rc=%d\n", rc);
Harald Welte3cfa4502015-12-25 15:33:41 +0100332
333 ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
334
335 return rc;
336}