blob: 14a192f6e5ce202997274e1b528c3b5c05c79e89 [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
28#include "ranap_common.h"
29#include "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);
195
196 ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
197
198 return rc;
199}
200
201static int cn_ranap_rx_initiating_msg_cl(void *ctx, RANAP_InitiatingMessage_t *imsg,
202 ranap_message *message)
203{
204 int rc;
205
206 message->procedureCode = imsg->procedureCode;
207 message->criticality = imsg->criticality;
208
209 DEBUGP(DRANAP, "Rx CL IM (%s)\n",
210 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
211
212 switch (imsg->procedureCode) {
213 case RANAP_ProcedureCode_id_Reset:
214 /* Reset request */
215 rc = ranap_decode_reseties(&message->msg.resetIEs, &imsg->value);
216 break;
217 case RANAP_ProcedureCode_id_OverloadControl: /* Overload ind */
218 rc = ranap_decode_overloadies(&message->msg.overloadIEs, &imsg->value);
219 break;
220 case RANAP_ProcedureCode_id_ErrorIndication: /* Error ind */
221 rc = ranap_decode_errorindicationies(&message->msg.errorIndicationIEs, &imsg->value);
222 break;
223 case RANAP_ProcedureCode_id_ResetResource: /* request */
224 rc = ranap_decode_resetresourceies(&message->msg.resetResourceIEs, &imsg->value);
225 break;
226 case RANAP_ProcedureCode_id_InformationTransfer:
227 rc = ranap_decode_informationtransferindicationies(&message->msg.informationTransferIndicationIEs, &imsg->value);
228 break;
229 case RANAP_ProcedureCode_id_DirectInformationTransfer:
230 rc = ranap_decode_directinformationtransferies(&message->msg.directInformationTransferIEs, &imsg->value);
231 break;
232 case RANAP_ProcedureCode_id_UplinkInformationExchange:
233 rc = ranap_decode_uplinkinformationexchangerequesties(&message->msg.uplinkInformationExchangeRequestIEs, &imsg->value);
234 break;
235 default:
236 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
237 "Procedure %s (CL, IM) from RNC, ignoring\n",
238 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
239 break;
240 }
241}
242
243static int cn_ranap_rx_successful_msg_cl(void *ctx, RANAP_SuccessfulOutcome_t *imsg,
244 ranap_message *message)
245{
246 int rc;
247
248 message->procedureCode = imsg->procedureCode;
249 message->criticality = imsg->criticality;
250
251 DEBUGP(DRANAP, "Rx CL SO (%s)\n",
252 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
253
254 switch (imsg->procedureCode) {
255 case RANAP_ProcedureCode_id_Reset: /* Reset acknowledge */
256 rc = ranap_decode_resetacknowledgeies(&message->msg.resetAcknowledgeIEs, &imsg->value);
257 break;
258 case RANAP_ProcedureCode_id_ResetResource: /* response */
259 rc = ranap_decode_resetresourceacknowledgeies(&message->msg.resetResourceAcknowledgeIEs, &imsg->value);
260 case RANAP_ProcedureCode_id_InformationTransfer:
261 rc = ranap_decode_resetresourceacknowledgeies(&message->msg.resetResourceAcknowledgeIEs, &imsg->value);
262 break;
263 case RANAP_ProcedureCode_id_DirectInformationTransfer:
264 rc = ranap_decode_informationtransferconfirmationies(&message->msg.informationTransferConfirmationIEs, &imsg->value);
265 break;
266 case RANAP_ProcedureCode_id_UplinkInformationExchange:
267 rc = ranap_decode_uplinkinformationexchangeresponseies(&message->msg.uplinkInformationExchangeResponseIEs, &imsg->value);
268 break;
269 default:
270 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
271 "Procedure %s (CL, SO) from RNC, ignoring\n",
272 get_value_string(ranap_procedure_code_vals, imsg->procedureCode));
273 break;
274 }
275}
276
277static int _cn_ranap_rx_cl(void *ctx, RANAP_RANAP_PDU_t *pdu, ranap_message *message)
278{
279 int rc;
280
281 switch (pdu->present) {
282 case RANAP_RANAP_PDU_PR_initiatingMessage:
283 rc = cn_ranap_rx_initiating_msg_cl(ctx, &pdu->choice.initiatingMessage,
284 message);
285 break;
286 case RANAP_RANAP_PDU_PR_successfulOutcome:
287 rc = cn_ranap_rx_successful_msg_cl(ctx, &pdu->choice.successfulOutcome,
288 message);
289 break;
290 case RANAP_RANAP_PDU_PR_unsuccessfulOutcome:
291 LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP "
292 "unsuccessful outcome procedure %s (CL) from RNC, ignoring\n",
293 get_value_string(ranap_procedure_code_vals,
294 pdu->choice.unsuccessfulOutcome.procedureCode));
295 break;
296 default:
297 LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP "
298 "presence %s (CL) from RNC, ignoring\n",
299 get_value_string(ranap_presence_vals, pdu->present));
300 break;
301 }
302}
303
304/* receive a connection-oriented RANAP message and call
305 * cn_ranap_handle_co() with the resulting ranap_message struct */
306int cn_ranap_rx_cl(void *ctx, uint8_t *data, size_t len)
307{
308 RANAP_RANAP_PDU_t *pdu = NULL;
309 ranap_message message;
310 asn_dec_rval_t dec_ret;
311 int rc;
312
313 memset(&message, 0, sizeof(message));
314
Harald Welte3cfa4502015-12-25 15:33:41 +0100315 dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu,
316 data, len, 0, 0);
317 if (dec_ret.code != RC_OK) {
318 LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n");
319 return rc;
320 }
321
322 message.direction = pdu->present;
323
324 rc = _cn_ranap_rx_cl(ctx, pdu, &message);
325
326 if (rc == 0)
327 cn_ranap_handle_cl(ctx, &message);
328
329 ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
330
331 return rc;
332}