blob: 0ca64d37f2bafa91c9babcc6eaf9f89b754927b3 [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
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020035#include <osmocom/iuh/hnbgw.h>
36#include <osmocom/iuh/hnbgw_ranap.h>
Neels Hofmeyr83457922016-08-26 23:56:44 +020037#include <osmocom/rua/rua_common.h>
38#include <osmocom/rua/rua_ies_defs.h>
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020039#include <osmocom/iuh/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;
Daniel Willmann6480cad2016-01-06 18:06:26 +010047 osmo_stream_srv_send(ctx->conn, msg);
48
49 return 0;
Harald Welte318e4d52015-09-10 18:47:08 +020050}
51
Harald Weltecd5e9812015-12-23 22:14:16 +010052int rua_tx_udt(struct hnb_context *hnb, const uint8_t *data, unsigned int len)
Harald Welte64b4ebe2015-09-10 19:29:59 +020053{
Harald Weltee2e5d4d2015-09-10 23:49:45 +020054 RUA_ConnectionlessTransfer_t out;
55 RUA_ConnectionlessTransferIEs_t ies;
56 struct msgb *msg;
57 int rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +020058
Harald Weltee2e5d4d2015-09-10 23:49:45 +020059 memset(&ies, 0, sizeof(ies));
Harald Weltecd5e9812015-12-23 22:14:16 +010060 ies.ranaP_Message.buf = (uint8_t *) data;
61 ies.ranaP_Message.size = len;
Harald Weltee2e5d4d2015-09-10 23:49:45 +020062
63 /* FIXME: msgb_free(msg)? ownership not yet clear */
64
65 memset(&out, 0, sizeof(out));
66 rc = rua_encode_connectionlesstransferies(&out, &ies);
67 if (rc < 0)
68 return rc;
69
70 msg = rua_generate_initiating_message(RUA_ProcedureCode_id_ConnectionlessTransfer,
71 RUA_Criticality_reject,
72 &asn_DEF_RUA_ConnectionlessTransfer,
73 &out);
Harald Weltecd5e9812015-12-23 22:14:16 +010074 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out);
Harald Weltee2e5d4d2015-09-10 23:49:45 +020075
Harald Weltec4338de2015-12-24 00:40:52 +010076 DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg));
Harald Weltee2e5d4d2015-09-10 23:49:45 +020077
Harald Weltec4338de2015-12-24 00:40:52 +010078 return hnbgw_rua_tx(hnb, msg);
Harald Welte64b4ebe2015-09-10 19:29:59 +020079}
80
Harald Weltecd5e9812015-12-23 22:14:16 +010081int rua_tx_dt(struct hnb_context *hnb, int is_ps, uint32_t context_id,
82 const uint8_t *data, unsigned int len)
Harald Welte0f0ea812015-09-11 18:58:28 +020083{
84 RUA_DirectTransfer_t out;
85 RUA_DirectTransferIEs_t ies;
Harald Weltecd5e9812015-12-23 22:14:16 +010086 uint32_t ctxidbuf;
Harald Welte0f0ea812015-09-11 18:58:28 +020087 struct msgb *msg;
88 int rc;
89
90 memset(&ies, 0, sizeof(ies));
Harald Weltecd5e9812015-12-23 22:14:16 +010091 if (is_ps)
92 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain;
93 else
94 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain;
95 asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id);
96 ies.ranaP_Message.buf = (uint8_t *) data;
97 ies.ranaP_Message.size = len;
Harald Welte0f0ea812015-09-11 18:58:28 +020098
99 /* FIXME: msgb_free(msg)? ownership not yet clear */
100
101 memset(&out, 0, sizeof(out));
102 rc = rua_encode_directtransferies(&out, &ies);
103 if (rc < 0)
104 return rc;
105
106 msg = rua_generate_initiating_message(RUA_ProcedureCode_id_DirectTransfer,
107 RUA_Criticality_reject,
108 &asn_DEF_RUA_DirectTransfer,
109 &out);
Harald Weltecd5e9812015-12-23 22:14:16 +0100110 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out);
Harald Welte0f0ea812015-09-11 18:58:28 +0200111
Harald Welte5bea8002015-12-26 23:40:31 +0100112 DEBUGP(DRUA, "transmitting RUA (cn=%s) payload of %u bytes\n",
113 is_ps ? "ps" : "cs", msgb_length(msg));
Harald Welte0f0ea812015-09-11 18:58:28 +0200114
Harald Weltecd5e9812015-12-23 22:14:16 +0100115 return hnbgw_rua_tx(hnb, msg);
Harald Welte0f0ea812015-09-11 18:58:28 +0200116}
117
Harald Weltecd5e9812015-12-23 22:14:16 +0100118int rua_tx_disc(struct hnb_context *hnb, int is_ps, uint32_t context_id,
119 const RUA_Cause_t *cause, const uint8_t *data, unsigned int len)
120{
121 RUA_Disconnect_t out;
122 RUA_DisconnectIEs_t ies;
123 struct msgb *msg;
124 uint32_t ctxidbuf;
125 int rc;
126
127 memset(&ies, 0, sizeof(ies));
128 if (is_ps)
129 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain;
130 else
131 ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain;
132 asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id);
133 memcpy(&ies.cause, cause, sizeof(ies.cause));
134 if (data && len) {
135 ies.presenceMask |= DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT;
136 ies.ranaP_Message.buf = (uint8_t *) data;
137 ies.ranaP_Message.size = len;
138 }
139
140 /* FIXME: msgb_free(msg)? ownership not yet clear */
141
142 memset(&out, 0, sizeof(out));
143 rc = rua_encode_disconnecties(&out, &ies);
144 if (rc < 0)
145 return rc;
146
147 msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Disconnect,
148 RUA_Criticality_reject,
149 &asn_DEF_RUA_Disconnect,
150 &out);
151 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out);
152
Harald Welte5bea8002015-12-26 23:40:31 +0100153 DEBUGP(DRUA, "transmitting RUA (cn=%s) payload of %u bytes\n",
154 is_ps ? "ps" : "cs", msgb_length(msg));
155
Harald Weltecd5e9812015-12-23 22:14:16 +0100156
157 return hnbgw_rua_tx(hnb, msg);
158}
159
160
Harald Welte0f0ea812015-09-11 18:58:28 +0200161
Harald Weltec4338de2015-12-24 00:40:52 +0100162/* forward a RUA message to the SCCP User API to SCCP/SUA */
163static int rua_to_scu(struct hnb_context *hnb, struct hnbgw_cnlink *cn,
164 enum osmo_scu_prim_type type,
165 uint32_t context_id, uint32_t cause,
166 const uint8_t *data, unsigned int len)
167{
168 struct msgb *msg = msgb_alloc(1500, "rua_to_sua");
169 struct osmo_scu_prim *prim;
170 struct hnbgw_context_map *map;
171 int rc;
172
Harald Welte49287972015-12-29 19:00:35 +0100173 if (!cn) {
174 DEBUGP(DRUA, "CN=NULL, discarding message\n");
175 return 0;
176 }
177
Harald Weltec4338de2015-12-24 00:40:52 +0100178 prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
179 osmo_prim_init(&prim->oph, SCCP_SAP_USER, type, PRIM_OP_REQUEST, msg);
180
181 map = context_map_alloc_by_hnb(hnb, context_id, cn);
182
183 /* add primitive header */
184 switch (type) {
185 case OSMO_SCU_PRIM_N_CONNECT:
186 prim->u.connect.called_addr;
187 prim->u.connect.calling_addr;
188 prim->u.connect.sccp_class = 2;
189 prim->u.connect.conn_id = map->scu_conn_id;
190 break;
191 case OSMO_SCU_PRIM_N_DATA:
192 prim->u.data.conn_id = map->scu_conn_id;
193 break;
194 case OSMO_SCU_PRIM_N_DISCONNECT:
195 prim->u.disconnect.conn_id = map->scu_conn_id;
196 prim->u.disconnect.cause = cause;
197 break;
198 case OSMO_SCU_PRIM_N_UNITDATA:
199 prim->u.unitdata.called_addr;
200 prim->u.unitdata.calling_addr;
201 break;
202 default:
203 return -EINVAL;
204 }
205
206 /* add optional data section, if needed */
207 if (data && len) {
208 msg->l2h = msgb_put(msg, len);
209 memcpy(msg->l2h, data, len);
210 }
211
212 rc = osmo_sua_user_link_down(cn->sua_link, &prim->oph);
213
214 return rc;
215}
216
217static uint32_t rua_to_scu_cause(RUA_Cause_t *in)
218{
219 /* FIXME: Implement this! */
220#if 0
221 switch (in->present) {
222 case RUA_Cause_PR_NOTHING:
223 break;
224 case RUA_Cause_PR_radioNetwork:
225 switch (in->choice.radioNetwork) {
226 case RUA_CauseRadioNetwork_normal:
227 case RUA_CauseRadioNetwork_connect_failed:
228 case RUA_CauseRadioNetwork_network_release:
229 case RUA_CauseRadioNetwork_unspecified:
230 }
231 break;
232 case RUA_Cause_PR_transport:
233 switch (in->choice.transport) {
234 case RUA_CauseTransport_transport_resource_unavailable:
235 break;
236 case RUA_CauseTransport_unspecified:
237 break;
238 }
239 break;
240 case RUA_Cause_PR_protocol:
241 switch (in->choice.protocol) {
242 case RUA_CauseProtocol_transfer_syntax_error:
243 break;
244 case RUA_CauseProtocol_abstract_syntax_error_reject:
245 break;
246 case RUA_CauseProtocol_abstract_syntax_error_ignore_and_notify:
247 break;
248 case RUA_CauseProtocol_message_not_compatible_with_receiver_state:
249 break;
250 case RUA_CauseProtocol_semantic_error:
251 break;
252 case RUA_CauseProtocol_unspecified:
253 break;
254 case RUA_CauseProtocol_abstract_syntax_error_falsely_constructed_message:
255 break;
256 }
257 break;
258 case RUA_Cause_PR_misc:
259 switch (in->choice.misc) {
260 case RUA_CauseMisc_processing_overload:
261 break;
262 case RUA_CauseMisc_hardware_failure:
263 break;
264 case RUA_CauseMisc_o_and_m_intervention:
265 break;
266 case RUA_CauseMisc_unspecified:
267 break;
268 }
269 break;
270 default:
271 break;
272 }
273#else
274 return 0;
275#endif
276
277}
278
Harald Welte350814a2015-09-10 22:32:15 +0200279static int rua_rx_init_connect(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200280{
281 RUA_ConnectIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100282 struct hnb_context *hnb = msg->dst;
283 struct hnbgw_cnlink *cn;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200284 uint32_t context_id;
285 int rc;
286
287 rc = rua_decode_connecties(&ies, in);
288 if (rc < 0)
289 return rc;
290
Harald Welteb0de9062015-12-24 14:10:17 +0100291 context_id = asn1bitstr_to_u24(&ies.context_ID);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200292
Harald Weltec4338de2015-12-24 00:40:52 +0100293 /* route to CS (MSC) or PS (SGSN) domain */
294 switch (ies.cN_DomainIndicator) {
295 case RUA_CN_DomainIndicator_cs_domain:
296 cn = hnb->gw->cnlink_cs;
297 break;
298 case RUA_CN_DomainIndicator_ps_domain:
299 cn = hnb->gw->cnlink_ps;
300 break;
Harald Welte5bea8002015-12-26 23:40:31 +0100301 default:
302 LOGP(DRUA, LOGL_ERROR, "Unsupported Domain %u\n",
303 ies.cN_DomainIndicator);
Daniel Willmann11e912a2016-01-07 13:19:30 +0100304 rua_free_connecties(&ies);
Harald Welte5bea8002015-12-26 23:40:31 +0100305 return -1;
Harald Weltec4338de2015-12-24 00:40:52 +0100306 }
307
Harald Welte37166a22015-12-24 10:12:09 +0100308 DEBUGP(DRUA, "RUA Connect.req(ctx=0x%x, %s)\n", context_id,
Harald Welte64b4ebe2015-09-10 19:29:59 +0200309 ies.establishment_Cause == RUA_Establishment_Cause_emergency_call
310 ? "emergency" : "normal");
Harald Weltec4338de2015-12-24 00:40:52 +0100311
312 rc = rua_to_scu(hnb, cn, OSMO_SCU_PRIM_N_CONNECT,
313 context_id, 0, ies.ranaP_Message.buf,
314 ies.ranaP_Message.size);
315 /* FIXME: what to do with the asn1c-allocated memory */
Daniel Willmann11e912a2016-01-07 13:19:30 +0100316 rua_free_connecties(&ies);
Harald Welte0f0ea812015-09-11 18:58:28 +0200317
318 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200319}
320
Harald Welte350814a2015-09-10 22:32:15 +0200321static int rua_rx_init_disconnect(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200322{
323 RUA_DisconnectIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100324 struct hnb_context *hnb = msg->dst;
325 struct hnbgw_cnlink *cn;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200326 uint32_t context_id;
Harald Weltec4338de2015-12-24 00:40:52 +0100327 uint32_t scu_cause;
328 uint8_t *ranap_data = NULL;
329 unsigned int ranap_len = 0;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200330 int rc;
331
332 rc = rua_decode_disconnecties(&ies, in);
333 if (rc < 0)
334 return rc;
335
Harald Welteb0de9062015-12-24 14:10:17 +0100336 context_id = asn1bitstr_to_u24(&ies.context_ID);
Harald Weltec4338de2015-12-24 00:40:52 +0100337 scu_cause = rua_to_scu_cause(&ies.cause);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200338
Harald Welte37166a22015-12-24 10:12:09 +0100339 DEBUGP(DRUA, "RUA Disconnect.req(ctx=0x%x,cause=%s)\n", context_id,
Harald Welte64b4ebe2015-09-10 19:29:59 +0200340 rua_cause_str(&ies.cause));
Harald Welte0f0ea812015-09-11 18:58:28 +0200341
Harald Weltec4338de2015-12-24 00:40:52 +0100342 /* route to CS (MSC) or PS (SGSN) domain */
343 switch (ies.cN_DomainIndicator) {
344 case RUA_CN_DomainIndicator_cs_domain:
345 cn = hnb->gw->cnlink_cs;
346 break;
347 case RUA_CN_DomainIndicator_ps_domain:
348 cn = hnb->gw->cnlink_ps;
349 break;
Neels Hofmeyrfe878092016-11-25 13:13:31 +0100350 default:
351 LOGP(DRUA, LOGL_ERROR, "Invalid CN_DomainIndicator: %u\n",
352 ies.cN_DomainIndicator);
353 rc = -1;
354 goto error_free;
Harald Weltec4338de2015-12-24 00:40:52 +0100355 }
356
357 if (ies.presenceMask & DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT) {
358 ranap_data = ies.ranaP_Message.buf;
359 ranap_len = ies.ranaP_Message.size;
360 }
361
362 rc = rua_to_scu(hnb, cn, OSMO_SCU_PRIM_N_DISCONNECT,
363 context_id, scu_cause, ranap_data, ranap_len);
Neels Hofmeyrfe878092016-11-25 13:13:31 +0100364
365error_free:
Harald Weltec4338de2015-12-24 00:40:52 +0100366 /* FIXME: what to do with the asn1c-allocated memory */
Daniel Willmann11e912a2016-01-07 13:19:30 +0100367 rua_free_disconnecties(&ies);
Harald Weltec4338de2015-12-24 00:40:52 +0100368
Harald Welte0f0ea812015-09-11 18:58:28 +0200369 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200370}
371
Harald Welte350814a2015-09-10 22:32:15 +0200372static int rua_rx_init_dt(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200373{
374 RUA_DirectTransferIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100375 struct hnb_context *hnb = msg->dst;
376 struct hnbgw_cnlink *cn;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200377 uint32_t context_id;
378 int rc;
379
380 rc = rua_decode_directtransferies(&ies, in);
381 if (rc < 0)
382 return rc;
383
Harald Welteb0de9062015-12-24 14:10:17 +0100384 context_id = asn1bitstr_to_u24(&ies.context_ID);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200385
Harald Welte37166a22015-12-24 10:12:09 +0100386 DEBUGP(DRUA, "RUA Data.req(ctx=0x%x)\n", context_id);
Harald Weltec4338de2015-12-24 00:40:52 +0100387
388 /* route to CS (MSC) or PS (SGSN) domain */
389 switch (ies.cN_DomainIndicator) {
390 case RUA_CN_DomainIndicator_cs_domain:
391 cn = hnb->gw->cnlink_cs;
392 break;
393 case RUA_CN_DomainIndicator_ps_domain:
394 cn = hnb->gw->cnlink_ps;
395 break;
Neels Hofmeyrfe878092016-11-25 13:13:31 +0100396 default:
397 LOGP(DRUA, LOGL_ERROR, "Invalid CN_DomainIndicator: %u\n",
398 ies.cN_DomainIndicator);
399 rc = -1;
400 goto error_free;
Harald Weltec4338de2015-12-24 00:40:52 +0100401 }
402
403 rc = rua_to_scu(hnb, cn, OSMO_SCU_PRIM_N_DATA,
404 context_id, 0, ies.ranaP_Message.buf,
405 ies.ranaP_Message.size);
Neels Hofmeyrfe878092016-11-25 13:13:31 +0100406
407error_free:
Harald Weltec4338de2015-12-24 00:40:52 +0100408 /* FIXME: what to do with the asn1c-allocated memory */
Daniel Willmann11e912a2016-01-07 13:19:30 +0100409 rua_free_directtransferies(&ies);
Harald Welte0f0ea812015-09-11 18:58:28 +0200410
411 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200412
413}
414
Harald Welte350814a2015-09-10 22:32:15 +0200415static int rua_rx_init_udt(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200416{
417 RUA_ConnectionlessTransferIEs_t ies;
Harald Weltec4338de2015-12-24 00:40:52 +0100418 RUA_CN_DomainIndicator_t domain;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200419 int rc;
420
421 rc = rua_decode_connectionlesstransferies(&ies, in);
422 if (rc < 0)
423 return rc;
424
Harald Welte37166a22015-12-24 10:12:09 +0100425 DEBUGP(DRUA, "RUA UData.req()\n");
Harald Welte64b4ebe2015-09-10 19:29:59 +0200426
Harald Weltec4338de2015-12-24 00:40:52 +0100427 /* according tot the spec, we can primarily receive Overload,
428 * Reset, Reset ACK, Error Indication, reset Resource, Reset
429 * Resurce Acknowledge as connecitonless RANAP. There are some
430 * more messages regarding Information Transfer, Direct
431 * Information Transfer and Uplink Information Trnansfer that we
432 * can ignore. In either case, it is RANAP that we need to
433 * decode... */
Harald Welte350814a2015-09-10 22:32:15 +0200434 rc = hnbgw_ranap_rx(msg, ies.ranaP_Message.buf, ies.ranaP_Message.size);
Daniel Willmann11e912a2016-01-07 13:19:30 +0100435 rua_free_connectionlesstransferies(&ies);
Harald Welte350814a2015-09-10 22:32:15 +0200436
437 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200438}
439
Harald Welte350814a2015-09-10 22:32:15 +0200440
441static int rua_rx_init_err_ind(struct msgb *msg, ANY_t *in)
Harald Welte64b4ebe2015-09-10 19:29:59 +0200442{
443 RUA_ErrorIndicationIEs_t ies;
444 int rc;
445
446 rc = rua_decode_errorindicationies(&ies, in);
447 if (rc < 0)
448 return rc;
449
Harald Welte831e1ee2015-12-25 10:28:55 +0100450 LOGP(DRUA, LOGL_ERROR, "RUA UData.ErrorInd(%s)\n",
451 rua_cause_str(&ies.cause));
Harald Weltec4338de2015-12-24 00:40:52 +0100452
Daniel Willmann11e912a2016-01-07 13:19:30 +0100453 rua_free_errorindicationies(&ies);
Harald Weltec4338de2015-12-24 00:40:52 +0100454 return rc;
Harald Welte64b4ebe2015-09-10 19:29:59 +0200455}
Harald Welte318e4d52015-09-10 18:47:08 +0200456
Harald Welte350814a2015-09-10 22:32:15 +0200457static int rua_rx_initiating_msg(struct msgb *msg, RUA_InitiatingMessage_t *imsg)
Harald Welte318e4d52015-09-10 18:47:08 +0200458{
459 int rc;
460
461 switch (imsg->procedureCode) {
462 case RUA_ProcedureCode_id_Connect:
Harald Welte350814a2015-09-10 22:32:15 +0200463 rc = rua_rx_init_connect(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200464 break;
465 case RUA_ProcedureCode_id_DirectTransfer:
Harald Welte350814a2015-09-10 22:32:15 +0200466 rc = rua_rx_init_dt(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200467 break;
468 case RUA_ProcedureCode_id_Disconnect:
Harald Welte350814a2015-09-10 22:32:15 +0200469 rc = rua_rx_init_disconnect(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200470 break;
471 case RUA_ProcedureCode_id_ConnectionlessTransfer:
Harald Welte350814a2015-09-10 22:32:15 +0200472 rc = rua_rx_init_udt(msg, &imsg->value);
Harald Welte318e4d52015-09-10 18:47:08 +0200473 break;
474 case RUA_ProcedureCode_id_ErrorIndication:
Harald Welte350814a2015-09-10 22:32:15 +0200475 rc = rua_rx_init_err_ind(msg, &imsg->value);
Harald Welte64b4ebe2015-09-10 19:29:59 +0200476 break;
Harald Welte318e4d52015-09-10 18:47:08 +0200477 case RUA_ProcedureCode_id_privateMessage:
Neels Hofmeyr2b5021f2016-11-25 13:25:38 +0100478 LOGP(DRUA, LOGL_NOTICE,
479 "Unhandled: RUA Initiating Msg: Private Msg\n");
480 rc = 0;
Harald Welte318e4d52015-09-10 18:47:08 +0200481 break;
482 default:
Harald Welte37166a22015-12-24 10:12:09 +0100483 LOGP(DRUA, LOGL_NOTICE, "Unknown RUA Procedure %u\n",
484 imsg->procedureCode);
485 rc = -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200486 }
Harald Welte37166a22015-12-24 10:12:09 +0100487
488 return rc;
Harald Welte318e4d52015-09-10 18:47:08 +0200489}
490
Harald Welte350814a2015-09-10 22:32:15 +0200491static int rua_rx_successful_outcome_msg(struct msgb *msg, RUA_SuccessfulOutcome_t *in)
Harald Welte318e4d52015-09-10 18:47:08 +0200492{
Harald Weltec4338de2015-12-24 00:40:52 +0100493 /* FIXME */
Harald Welte37166a22015-12-24 10:12:09 +0100494 LOGP(DRUA, LOGL_NOTICE, "Unexpected RUA Sucessful Outcome\n");
495 return -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200496}
497
Harald Welte350814a2015-09-10 22:32:15 +0200498static int rua_rx_unsuccessful_outcome_msg(struct msgb *msg, RUA_UnsuccessfulOutcome_t *in)
Harald Welte318e4d52015-09-10 18:47:08 +0200499{
Harald Weltec4338de2015-12-24 00:40:52 +0100500 /* FIXME */
Harald Welte37166a22015-12-24 10:12:09 +0100501 LOGP(DRUA, LOGL_NOTICE, "Unexpected RUA Unsucessful Outcome\n");
502 return -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200503}
504
505
Harald Welte350814a2015-09-10 22:32:15 +0200506static int _hnbgw_rua_rx(struct msgb *msg, RUA_RUA_PDU_t *pdu)
Harald Welte318e4d52015-09-10 18:47:08 +0200507{
508 int rc;
509
510 /* it's a bit odd that we can't dispatch on procedure code, but
511 * that's not possible */
512 switch (pdu->present) {
513 case RUA_RUA_PDU_PR_initiatingMessage:
Harald Welte350814a2015-09-10 22:32:15 +0200514 rc = rua_rx_initiating_msg(msg, &pdu->choice.initiatingMessage);
Harald Welte318e4d52015-09-10 18:47:08 +0200515 break;
516 case RUA_RUA_PDU_PR_successfulOutcome:
Harald Welte350814a2015-09-10 22:32:15 +0200517 rc = rua_rx_successful_outcome_msg(msg, &pdu->choice.successfulOutcome);
Harald Welte318e4d52015-09-10 18:47:08 +0200518 break;
519 case RUA_RUA_PDU_PR_unsuccessfulOutcome:
Harald Welte350814a2015-09-10 22:32:15 +0200520 rc = rua_rx_unsuccessful_outcome_msg(msg, &pdu->choice.unsuccessfulOutcome);
Harald Welte318e4d52015-09-10 18:47:08 +0200521 break;
522 default:
Harald Welte37166a22015-12-24 10:12:09 +0100523 LOGP(DRUA, LOGL_NOTICE, "Unknown RUA presence %u\n", pdu->present);
524 rc = -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200525 }
Harald Welte37166a22015-12-24 10:12:09 +0100526
527 return rc;
Harald Welte318e4d52015-09-10 18:47:08 +0200528}
529
530int hnbgw_rua_rx(struct hnb_context *hnb, struct msgb *msg)
531{
532 RUA_RUA_PDU_t _pdu, *pdu = &_pdu;
533 asn_dec_rval_t dec_ret;
534 int rc;
535
536 /* decode and handle to _hnbgw_hnbap_rx() */
537
538 memset(pdu, 0, sizeof(*pdu));
539 dec_ret = aper_decode(NULL, &asn_DEF_RUA_RUA_PDU, (void **) &pdu,
540 msg->data, msgb_length(msg), 0, 0);
541 if (dec_ret.code != RC_OK) {
Harald Weltef42317b2015-12-23 15:36:31 +0100542 LOGP(DRUA, LOGL_ERROR, "Error in ASN.1 decode\n");
Neels Hofmeyra6a68e62016-11-25 13:21:02 +0100543 return -1;
Harald Welte318e4d52015-09-10 18:47:08 +0200544 }
545
Harald Welte350814a2015-09-10 22:32:15 +0200546 rc = _hnbgw_rua_rx(msg, pdu);
Harald Welte318e4d52015-09-10 18:47:08 +0200547
548 return rc;
549}
550
551
552int hnbgw_rua_init(void)
553{
Harald Weltec4338de2015-12-24 00:40:52 +0100554 return 0;
Harald Welte318e4d52015-09-10 18:47:08 +0200555}