blob: 961a5c5718d42936c1ef44d734943594594e5dcb [file] [log] [blame]
Harald Welte77847ad2015-10-06 22:07:04 +02001/* hnb-gw specific code for RUA (Ranap User Adaption) */
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
Harald Welte318e4d52015-09-10 18:47:08 +020022#include <osmocom/core/msgb.h>
23#include <osmocom/core/utils.h>
Harald Welteffa7c0a2015-12-23 00:03:41 +010024#include <osmocom/netif/stream.h>
Harald Welte318e4d52015-09-10 18:47:08 +020025
Harald Weltec4338de2015-12-24 00:40:52 +010026#include <osmocom/sigtran/sccp_sap.h>
27#include <osmocom/sigtran/sua.h>
28
Harald Welte318e4d52015-09-10 18:47:08 +020029#include <unistd.h>
30#include <errno.h>
31#include <string.h>
32
33#include "asn1helpers.h"
34
35#include "hnbgw.h"
Harald Welte350814a2015-09-10 22:32:15 +020036#include "hnbgw_ranap.h"
Harald Welte318e4d52015-09-10 18:47:08 +020037#include "rua_common.h"
38#include "rua_ies_defs.h"
Harald Weltec4338de2015-12-24 00:40:52 +010039#include "context_map.h"
Harald Welte318e4d52015-09-10 18:47:08 +020040
41static int hnbgw_rua_tx(struct hnb_context *ctx, struct msgb *msg)
42{
43 if (!msg)
44 return -EINVAL;
45
Harald Welteffa7c0a2015-12-23 00:03:41 +010046 msgb_sctp_ppid(msg) = IUH_PPI_RUA;
Harald Welte318e4d52015-09-10 18:47:08 +020047 return osmo_wqueue_enqueue(&ctx->wqueue, msg);
48}
49
Harald Weltecd5e9812015-12-23 22:14:16 +010050int rua_tx_udt(struct hnb_context *hnb, const uint8_t *data, unsigned int len)
Harald Welte64b4ebe2015-09-10 19:29:59 +020051{
Harald Weltee2e5d4d2015-09-10 23:49:45 +020052 RUA_ConnectionlessTransfer_t out;
53 RUA_ConnectionlessTransferIEs_t ies;
54 struct msgb *msg;
55 int rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +020056
Harald Weltee2e5d4d2015-09-10 23:49:45 +020057 memset(&ies, 0, sizeof(ies));
Harald Weltecd5e9812015-12-23 22:14:16 +010058 ies.ranaP_Message.buf = (uint8_t *) data;
59 ies.ranaP_Message.size = len;
Harald Weltee2e5d4d2015-09-10 23:49:45 +020060
61 /* FIXME: msgb_free(msg)? ownership not yet clear */
62
63 memset(&out, 0, sizeof(out));
64 rc = rua_encode_connectionlesstransferies(&out, &ies);
65 if (rc < 0)
66 return rc;
67
68 msg = rua_generate_initiating_message(RUA_ProcedureCode_id_ConnectionlessTransfer,
69 RUA_Criticality_reject,
70 &asn_DEF_RUA_ConnectionlessTransfer,
71 &out);
Harald Weltecd5e9812015-12-23 22:14:16 +010072 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out);
Harald Weltee2e5d4d2015-09-10 23:49:45 +020073
Harald Weltec4338de2015-12-24 00:40:52 +010074 DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg));
Harald Weltee2e5d4d2015-09-10 23:49:45 +020075
Harald Weltec4338de2015-12-24 00:40:52 +010076 return hnbgw_rua_tx(hnb, msg);
Harald Welte64b4ebe2015-09-10 19:29:59 +020077}
78
Harald Weltecd5e9812015-12-23 22:14:16 +010079int rua_tx_dt(struct hnb_context *hnb, int is_ps, uint32_t context_id,
80 const uint8_t *data, unsigned int len)
Harald Welte0f0ea812015-09-11 18:58:28 +020081{
82 RUA_DirectTransfer_t out;
83 RUA_DirectTransferIEs_t ies;
Harald Weltecd5e9812015-12-23 22:14:16 +010084 uint32_t ctxidbuf;
Harald Welte0f0ea812015-09-11 18:58:28 +020085 struct msgb *msg;
86 int rc;
87
88 memset(&ies, 0, sizeof(ies));
Harald Weltecd5e9812015-12-23 22:14:16 +010089 if (is_ps)
90 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain;
91 else
92 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain;
93 asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id);
94 ies.ranaP_Message.buf = (uint8_t *) data;
95 ies.ranaP_Message.size = len;
Harald Welte0f0ea812015-09-11 18:58:28 +020096
97 /* FIXME: msgb_free(msg)? ownership not yet clear */
98
99 memset(&out, 0, sizeof(out));
100 rc = rua_encode_directtransferies(&out, &ies);
101 if (rc < 0)
102 return rc;
103
104 msg = rua_generate_initiating_message(RUA_ProcedureCode_id_DirectTransfer,
105 RUA_Criticality_reject,
106 &asn_DEF_RUA_DirectTransfer,
107 &out);
Harald Weltecd5e9812015-12-23 22:14:16 +0100108 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out);
Harald Welte0f0ea812015-09-11 18:58:28 +0200109
Harald Welte5bea8002015-12-26 23:40:31 +0100110 DEBUGP(DRUA, "transmitting RUA (cn=%s) payload of %u bytes\n",
111 is_ps ? "ps" : "cs", msgb_length(msg));
Harald Welte0f0ea812015-09-11 18:58:28 +0200112
Harald Weltecd5e9812015-12-23 22:14:16 +0100113 return hnbgw_rua_tx(hnb, msg);
Harald Welte0f0ea812015-09-11 18:58:28 +0200114}
115
Harald Weltecd5e9812015-12-23 22:14:16 +0100116int rua_tx_disc(struct hnb_context *hnb, int is_ps, uint32_t context_id,
117 const RUA_Cause_t *cause, const uint8_t *data, unsigned int len)
118{
119 RUA_Disconnect_t out;
120 RUA_DisconnectIEs_t ies;
121 struct msgb *msg;
122 uint32_t ctxidbuf;
123 int rc;
124
125 memset(&ies, 0, sizeof(ies));
126 if (is_ps)
127 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain;
128 else
129 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain;
130 asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id);
131 memcpy(&ies.cause, cause, sizeof(ies.cause));
132 if (data && len) {
133 ies.presenceMask |= DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT;
134 ies.ranaP_Message.buf = (uint8_t *) data;
135 ies.ranaP_Message.size = len;
136 }
137
138 /* FIXME: msgb_free(msg)? ownership not yet clear */
139
140 memset(&out, 0, sizeof(out));
141 rc = rua_encode_disconnecties(&out, &ies);
142 if (rc < 0)
143 return rc;
144
145 msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Disconnect,
146 RUA_Criticality_reject,
147 &asn_DEF_RUA_Disconnect,
148 &out);
149 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out);
150
Harald Welte5bea8002015-12-26 23:40:31 +0100151 DEBUGP(DRUA, "transmitting RUA (cn=%s) payload of %u bytes\n",
152 is_ps ? "ps" : "cs", msgb_length(msg));
153
Harald Weltecd5e9812015-12-23 22:14:16 +0100154
155 return hnbgw_rua_tx(hnb, msg);
156}
157
158
Harald Welte0f0ea812015-09-11 18:58:28 +0200159
Harald Weltec4338de2015-12-24 00:40:52 +0100160/* forward a RUA message to the SCCP User API to SCCP/SUA */
161static int rua_to_scu(struct hnb_context *hnb, struct hnbgw_cnlink *cn,
162 enum osmo_scu_prim_type type,
163 uint32_t context_id, uint32_t cause,
164 const uint8_t *data, unsigned int len)
165{
166 struct msgb *msg = msgb_alloc(1500, "rua_to_sua");
167 struct osmo_scu_prim *prim;
168 struct hnbgw_context_map *map;
169 int rc;
170
171 prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
172 osmo_prim_init(&prim->oph, SCCP_SAP_USER, type, PRIM_OP_REQUEST, msg);
173
174 map = context_map_alloc_by_hnb(hnb, context_id, cn);
175
176 /* add primitive header */
177 switch (type) {
178 case OSMO_SCU_PRIM_N_CONNECT:
179 prim->u.connect.called_addr;
180 prim->u.connect.calling_addr;
181 prim->u.connect.sccp_class = 2;
182 prim->u.connect.conn_id = map->scu_conn_id;
183 break;
184 case OSMO_SCU_PRIM_N_DATA:
185 prim->u.data.conn_id = map->scu_conn_id;
186 break;
187 case OSMO_SCU_PRIM_N_DISCONNECT:
188 prim->u.disconnect.conn_id = map->scu_conn_id;
189 prim->u.disconnect.cause = cause;
190 break;
191 case OSMO_SCU_PRIM_N_UNITDATA:
192 prim->u.unitdata.called_addr;
193 prim->u.unitdata.calling_addr;
194 break;
195 default:
196 return -EINVAL;
197 }
198
199 /* add optional data section, if needed */
200 if (data && len) {
201 msg->l2h = msgb_put(msg, len);
202 memcpy(msg->l2h, data, len);
203 }
204
205 rc = osmo_sua_user_link_down(cn->sua_link, &prim->oph);
206
207 return rc;
208}
209
210static uint32_t rua_to_scu_cause(RUA_Cause_t *in)
211{
212 /* FIXME: Implement this! */
213#if 0
214 switch (in->present) {
215 case RUA_Cause_PR_NOTHING:
216 break;
217 case RUA_Cause_PR_radioNetwork:
218 switch (in->choice.radioNetwork) {
219 case RUA_CauseRadioNetwork_normal:
220 case RUA_CauseRadioNetwork_connect_failed:
221 case RUA_CauseRadioNetwork_network_release:
222 case RUA_CauseRadioNetwork_unspecified:
223 }
224 break;
225 case RUA_Cause_PR_transport:
226 switch (in->choice.transport) {
227 case RUA_CauseTransport_transport_resource_unavailable:
228 break;
229 case RUA_CauseTransport_unspecified:
230 break;
231 }
232 break;
233 case RUA_Cause_PR_protocol:
234 switch (in->choice.protocol) {
235 case RUA_CauseProtocol_transfer_syntax_error:
236 break;
237 case RUA_CauseProtocol_abstract_syntax_error_reject:
238 break;
239 case RUA_CauseProtocol_abstract_syntax_error_ignore_and_notify:
240 break;
241 case RUA_CauseProtocol_message_not_compatible_with_receiver_state:
242 break;
243 case RUA_CauseProtocol_semantic_error:
244 break;
245 case RUA_CauseProtocol_unspecified:
246 break;
247 case RUA_CauseProtocol_abstract_syntax_error_falsely_constructed_message:
248 break;
249 }
250 break;
251 case RUA_Cause_PR_misc:
252 switch (in->choice.misc) {
253 case RUA_CauseMisc_processing_overload:
254 break;
255 case RUA_CauseMisc_hardware_failure:
256 break;
257 case RUA_CauseMisc_o_and_m_intervention:
258 break;
259 case RUA_CauseMisc_unspecified:
260 break;
261 }
262 break;
263 default:
264 break;
265 }
266#else
267 return 0;
268#endif
269
270}
271
Harald Welte350814a2015-09-10 22:32:15 +0200272static int rua_rx_init_connect(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200273{
274 RUA_ConnectIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100275 struct hnb_context *hnb = msg->dst;
276 struct hnbgw_cnlink *cn;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200277 uint32_t context_id;
278 int rc;
279
280 rc = rua_decode_connecties(&ies, in);
281 if (rc < 0)
282 return rc;
283
Harald Welteb0de9062015-12-24 14:10:17 +0100284 context_id = asn1bitstr_to_u24(&ies.context_ID);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200285
Harald Weltec4338de2015-12-24 00:40:52 +0100286 /* route to CS (MSC) or PS (SGSN) domain */
287 switch (ies.cN_DomainIndicator) {
288 case RUA_CN_DomainIndicator_cs_domain:
289 cn = hnb->gw->cnlink_cs;
290 break;
291 case RUA_CN_DomainIndicator_ps_domain:
292 cn = hnb->gw->cnlink_ps;
293 break;
Harald Welte5bea8002015-12-26 23:40:31 +0100294 default:
295 LOGP(DRUA, LOGL_ERROR, "Unsupported Domain %u\n",
296 ies.cN_DomainIndicator);
297 return -1;
Harald Weltec4338de2015-12-24 00:40:52 +0100298 }
299
Harald Welte37166a22015-12-24 10:12:09 +0100300 DEBUGP(DRUA, "RUA Connect.req(ctx=0x%x, %s)\n", context_id,
Harald Welte64b4ebe2015-09-10 19:29:59 +0200301 ies.establishment_Cause == RUA_Establishment_Cause_emergency_call
302 ? "emergency" : "normal");
Harald Weltec4338de2015-12-24 00:40:52 +0100303
304 rc = rua_to_scu(hnb, cn, OSMO_SCU_PRIM_N_CONNECT,
305 context_id, 0, ies.ranaP_Message.buf,
306 ies.ranaP_Message.size);
307 /* FIXME: what to do with the asn1c-allocated memory */
Harald Welte0f0ea812015-09-11 18:58:28 +0200308
309 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200310}
311
Harald Welte350814a2015-09-10 22:32:15 +0200312static int rua_rx_init_disconnect(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200313{
314 RUA_DisconnectIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100315 struct hnb_context *hnb = msg->dst;
316 struct hnbgw_cnlink *cn;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200317 uint32_t context_id;
Harald Weltec4338de2015-12-24 00:40:52 +0100318 uint32_t scu_cause;
319 uint8_t *ranap_data = NULL;
320 unsigned int ranap_len = 0;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200321 int rc;
322
323 rc = rua_decode_disconnecties(&ies, in);
324 if (rc < 0)
325 return rc;
326
Harald Welteb0de9062015-12-24 14:10:17 +0100327 context_id = asn1bitstr_to_u24(&ies.context_ID);
Harald Weltec4338de2015-12-24 00:40:52 +0100328 scu_cause = rua_to_scu_cause(&ies.cause);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200329
Harald Welte37166a22015-12-24 10:12:09 +0100330 DEBUGP(DRUA, "RUA Disconnect.req(ctx=0x%x,cause=%s)\n", context_id,
Harald Welte64b4ebe2015-09-10 19:29:59 +0200331 rua_cause_str(&ies.cause));
Harald Welte0f0ea812015-09-11 18:58:28 +0200332
Harald Weltec4338de2015-12-24 00:40:52 +0100333 /* route to CS (MSC) or PS (SGSN) domain */
334 switch (ies.cN_DomainIndicator) {
335 case RUA_CN_DomainIndicator_cs_domain:
336 cn = hnb->gw->cnlink_cs;
337 break;
338 case RUA_CN_DomainIndicator_ps_domain:
339 cn = hnb->gw->cnlink_ps;
340 break;
341 }
342
343 if (ies.presenceMask & DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT) {
344 ranap_data = ies.ranaP_Message.buf;
345 ranap_len = ies.ranaP_Message.size;
346 }
347
348 rc = rua_to_scu(hnb, cn, OSMO_SCU_PRIM_N_DISCONNECT,
349 context_id, scu_cause, ranap_data, ranap_len);
350 /* FIXME: what to do with the asn1c-allocated memory */
351
Harald Welte0f0ea812015-09-11 18:58:28 +0200352 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200353}
354
Harald Welte350814a2015-09-10 22:32:15 +0200355static int rua_rx_init_dt(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200356{
357 RUA_DirectTransferIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100358 struct hnb_context *hnb = msg->dst;
359 struct hnbgw_cnlink *cn;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200360 uint32_t context_id;
361 int rc;
362
363 rc = rua_decode_directtransferies(&ies, in);
364 if (rc < 0)
365 return rc;
366
Harald Welteb0de9062015-12-24 14:10:17 +0100367 context_id = asn1bitstr_to_u24(&ies.context_ID);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200368
Harald Welte37166a22015-12-24 10:12:09 +0100369 DEBUGP(DRUA, "RUA Data.req(ctx=0x%x)\n", context_id);
Harald Weltec4338de2015-12-24 00:40:52 +0100370
371 /* route to CS (MSC) or PS (SGSN) domain */
372 switch (ies.cN_DomainIndicator) {
373 case RUA_CN_DomainIndicator_cs_domain:
374 cn = hnb->gw->cnlink_cs;
375 break;
376 case RUA_CN_DomainIndicator_ps_domain:
377 cn = hnb->gw->cnlink_ps;
378 break;
379 }
380
381 rc = rua_to_scu(hnb, cn, OSMO_SCU_PRIM_N_DATA,
382 context_id, 0, ies.ranaP_Message.buf,
383 ies.ranaP_Message.size);
384 /* FIXME: what to do with the asn1c-allocated memory */
Harald Welte0f0ea812015-09-11 18:58:28 +0200385
386 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200387
388}
389
Harald Welte350814a2015-09-10 22:32:15 +0200390static int rua_rx_init_udt(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200391{
392 RUA_ConnectionlessTransferIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100393 RUA_CN_DomainIndicator_t domain;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200394 int rc;
395
396 rc = rua_decode_connectionlesstransferies(&ies, in);
397 if (rc < 0)
398 return rc;
399
Harald Welte37166a22015-12-24 10:12:09 +0100400 DEBUGP(DRUA, "RUA UData.req()\n");
Harald Welte64b4ebe2015-09-10 19:29:59 +0200401
Harald Weltec4338de2015-12-24 00:40:52 +0100402 /* according tot the spec, we can primarily receive Overload,
403 * Reset, Reset ACK, Error Indication, reset Resource, Reset
404 * Resurce Acknowledge as connecitonless RANAP. There are some
405 * more messages regarding Information Transfer, Direct
406 * Information Transfer and Uplink Information Trnansfer that we
407 * can ignore. In either case, it is RANAP that we need to
408 * decode... */
Harald Welte350814a2015-09-10 22:32:15 +0200409 rc = hnbgw_ranap_rx(msg, ies.ranaP_Message.buf, ies.ranaP_Message.size);
Harald Welte350814a2015-09-10 22:32:15 +0200410
411 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200412}
413
Harald Welte350814a2015-09-10 22:32:15 +0200414
415static int rua_rx_init_err_ind(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200416{
417 RUA_ErrorIndicationIEs_t ies;
418 int rc;
419
420 rc = rua_decode_errorindicationies(&ies, in);
421 if (rc < 0)
422 return rc;
423
Harald Welte831e1ee2015-12-25 10:28:55 +0100424 LOGP(DRUA, LOGL_ERROR, "RUA UData.ErrorInd(%s)\n",
425 rua_cause_str(&ies.cause));
Harald Weltec4338de2015-12-24 00:40:52 +0100426
427 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200428}
Harald Welte318e4d52015-09-10 18:47:08 +0200429
Harald Welte350814a2015-09-10 22:32:15 +0200430static int rua_rx_initiating_msg(struct msgb *msg, RUA_InitiatingMessage_t *imsg)
Harald Welte318e4d52015-09-10 18:47:08 +0200431{
432 int rc;
433
434 switch (imsg->procedureCode) {
435 case RUA_ProcedureCode_id_Connect:
Harald Welte350814a2015-09-10 22:32:15 +0200436 rc = rua_rx_init_connect(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200437 break;
438 case RUA_ProcedureCode_id_DirectTransfer:
Harald Welte350814a2015-09-10 22:32:15 +0200439 rc = rua_rx_init_dt(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200440 break;
441 case RUA_ProcedureCode_id_Disconnect:
Harald Welte350814a2015-09-10 22:32:15 +0200442 rc = rua_rx_init_disconnect(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200443 break;
444 case RUA_ProcedureCode_id_ConnectionlessTransfer:
Harald Welte350814a2015-09-10 22:32:15 +0200445 rc = rua_rx_init_udt(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200446 break;
447 case RUA_ProcedureCode_id_ErrorIndication:
Harald Welte350814a2015-09-10 22:32:15 +0200448 rc = rua_rx_init_err_ind(msg, &imsg->value);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200449 break;
Harald Welte318e4d52015-09-10 18:47:08 +0200450 case RUA_ProcedureCode_id_privateMessage:
451 break;
452 default:
Harald Welte37166a22015-12-24 10:12:09 +0100453 LOGP(DRUA, LOGL_NOTICE, "Unknown RUA Procedure %u\n",
454 imsg->procedureCode);
455 rc = -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200456 }
Harald Welte37166a22015-12-24 10:12:09 +0100457
458 return rc;
Harald Welte318e4d52015-09-10 18:47:08 +0200459}
460
Harald Welte350814a2015-09-10 22:32:15 +0200461static int rua_rx_successful_outcome_msg(struct msgb *msg, RUA_SuccessfulOutcome_t *in)
Harald Welte318e4d52015-09-10 18:47:08 +0200462{
Harald Weltec4338de2015-12-24 00:40:52 +0100463 /* FIXME */
Harald Welte37166a22015-12-24 10:12:09 +0100464 LOGP(DRUA, LOGL_NOTICE, "Unexpected RUA Sucessful Outcome\n");
465 return -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200466}
467
Harald Welte350814a2015-09-10 22:32:15 +0200468static int rua_rx_unsuccessful_outcome_msg(struct msgb *msg, RUA_UnsuccessfulOutcome_t *in)
Harald Welte318e4d52015-09-10 18:47:08 +0200469{
Harald Weltec4338de2015-12-24 00:40:52 +0100470 /* FIXME */
Harald Welte37166a22015-12-24 10:12:09 +0100471 LOGP(DRUA, LOGL_NOTICE, "Unexpected RUA Unsucessful Outcome\n");
472 return -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200473}
474
475
Harald Welte350814a2015-09-10 22:32:15 +0200476static int _hnbgw_rua_rx(struct msgb *msg, RUA_RUA_PDU_t *pdu)
Harald Welte318e4d52015-09-10 18:47:08 +0200477{
478 int rc;
479
480 /* it's a bit odd that we can't dispatch on procedure code, but
481 * that's not possible */
482 switch (pdu->present) {
483 case RUA_RUA_PDU_PR_initiatingMessage:
Harald Welte350814a2015-09-10 22:32:15 +0200484 rc = rua_rx_initiating_msg(msg, &pdu->choice.initiatingMessage);
Harald Welte318e4d52015-09-10 18:47:08 +0200485 break;
486 case RUA_RUA_PDU_PR_successfulOutcome:
Harald Welte350814a2015-09-10 22:32:15 +0200487 rc = rua_rx_successful_outcome_msg(msg, &pdu->choice.successfulOutcome);
Harald Welte318e4d52015-09-10 18:47:08 +0200488 break;
489 case RUA_RUA_PDU_PR_unsuccessfulOutcome:
Harald Welte350814a2015-09-10 22:32:15 +0200490 rc = rua_rx_unsuccessful_outcome_msg(msg, &pdu->choice.unsuccessfulOutcome);
Harald Welte318e4d52015-09-10 18:47:08 +0200491 break;
492 default:
Harald Welte37166a22015-12-24 10:12:09 +0100493 LOGP(DRUA, LOGL_NOTICE, "Unknown RUA presence %u\n", pdu->present);
494 rc = -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200495 }
Harald Welte37166a22015-12-24 10:12:09 +0100496
497 return rc;
Harald Welte318e4d52015-09-10 18:47:08 +0200498}
499
500int hnbgw_rua_rx(struct hnb_context *hnb, struct msgb *msg)
501{
502 RUA_RUA_PDU_t _pdu, *pdu = &_pdu;
503 asn_dec_rval_t dec_ret;
504 int rc;
505
506 /* decode and handle to _hnbgw_hnbap_rx() */
507
508 memset(pdu, 0, sizeof(*pdu));
509 dec_ret = aper_decode(NULL, &asn_DEF_RUA_RUA_PDU, (void **) &pdu,
510 msg->data, msgb_length(msg), 0, 0);
511 if (dec_ret.code != RC_OK) {
Harald Weltef42317b2015-12-23 15:36:31 +0100512 LOGP(DRUA, LOGL_ERROR, "Error in ASN.1 decode\n");
Harald Welte318e4d52015-09-10 18:47:08 +0200513 return rc;
514 }
515
Harald Welte350814a2015-09-10 22:32:15 +0200516 rc = _hnbgw_rua_rx(msg, pdu);
Harald Welte318e4d52015-09-10 18:47:08 +0200517
518 return rc;
519}
520
521
522int hnbgw_rua_init(void)
523{
Harald Weltec4338de2015-12-24 00:40:52 +0100524 return 0;
Harald Welte318e4d52015-09-10 18:47:08 +0200525}