blob: 5246b81473f3719c09713418a5f4d3a65cf2b678 [file] [log] [blame]
Harald Welte77847ad2015-10-06 22:07:04 +02001/* hnb-gw specific code for HNBAP */
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 Welteba43de42015-08-29 20:33:16 +020021#include <osmocom/core/msgb.h>
Harald Welteb3dae302015-08-30 12:20:09 +020022#include <osmocom/core/utils.h>
Harald Welte10dfc5a2015-09-11 01:34:45 +020023#include <osmocom/gsm/gsm48.h>
Harald Welteffa7c0a2015-12-23 00:03:41 +010024#include <osmocom/netif/stream.h>
Harald Welteba43de42015-08-29 20:33:16 +020025
Harald Welteb3dae302015-08-30 12:20:09 +020026#include <unistd.h>
Harald Welteee77cff2015-08-30 16:57:53 +020027#include <errno.h>
Harald Welteb3dae302015-08-30 12:20:09 +020028#include <string.h>
29
Harald Welte30afef32015-08-30 12:28:29 +020030#include "asn1helpers.h"
Neels Hofmeyr96979af2016-01-05 15:19:44 +010031#include <osmocom/ranap/iu_helpers.h>
Harald Welte30afef32015-08-30 12:28:29 +020032
Harald Welteba43de42015-08-29 20:33:16 +020033#include "hnbgw.h"
Harald Welte27f9c4a2015-08-30 22:47:18 +020034#include "hnbap_common.h"
35#include "hnbap_ies_defs.h"
Harald Welteba43de42015-08-29 20:33:16 +020036
Harald Welteee77cff2015-08-30 16:57:53 +020037#define IU_MSG_NUM_IES 32
38#define IU_MSG_NUM_EXT_IES 32
39
Harald Welte27f9c4a2015-08-30 22:47:18 +020040static int hnbgw_hnbap_tx(struct hnb_context *ctx, struct msgb *msg)
Harald Welteee77cff2015-08-30 16:57:53 +020041{
Harald Welte7b54e322015-09-07 22:41:45 +020042 if (!msg)
43 return -EINVAL;
44
Harald Welteffa7c0a2015-12-23 00:03:41 +010045 msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
Daniel Willmann6480cad2016-01-06 18:06:26 +010046 osmo_stream_srv_send(ctx->conn, msg);
47
48 return 0;
Harald Welte27f9c4a2015-08-30 22:47:18 +020049}
Harald Welteee77cff2015-08-30 16:57:53 +020050
Harald Welte27f9c4a2015-08-30 22:47:18 +020051static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx)
52{
53 HNBRegisterAccept_t accept_out;
54 struct msgb *msg;
55 int rc;
56
57 /* Single required response IE: RNC-ID */
58 HNBRegisterAcceptIEs_t accept = {
59 .rnc_id = ctx->gw->config.rnc_id
60 };
61
62 /* encode the Information Elements */
Harald Welte2204f9d2015-09-07 21:10:50 +020063 memset(&accept_out, 0, sizeof(accept_out));
Harald Welte27f9c4a2015-08-30 22:47:18 +020064 rc = hnbap_encode_hnbregisteraccepties(&accept_out, &accept);
65 if (rc < 0) {
66 return rc;
Harald Welteee77cff2015-08-30 16:57:53 +020067 }
68
Harald Welte27f9c4a2015-08-30 22:47:18 +020069 /* generate a successfull outcome PDU */
70 msg = hnbap_generate_successful_outcome(ProcedureCode_id_HNBRegister,
71 Criticality_reject,
72 &asn_DEF_HNBRegisterAccept,
73 &accept_out);
Harald Welteee77cff2015-08-30 16:57:53 +020074
Daniel Willmann59d17d82015-12-17 17:56:56 +010075 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBRegisterAccept, &accept_out);
76
Harald Welte27f9c4a2015-08-30 22:47:18 +020077 return hnbgw_hnbap_tx(ctx, msg);
Harald Welteee77cff2015-08-30 16:57:53 +020078}
79
80
Harald Welte27f9c4a2015-08-30 22:47:18 +020081static int hnbgw_tx_ue_register_acc(struct ue_context *ue)
Harald Welteba43de42015-08-29 20:33:16 +020082{
Harald Welte27f9c4a2015-08-30 22:47:18 +020083 UERegisterAccept_t accept_out;
84 UERegisterAcceptIEs_t accept;
85 struct msgb *msg;
Harald Welte10dfc5a2015-09-11 01:34:45 +020086 uint8_t encoded_imsi[10];
Daniel Willmann92247312015-12-09 19:04:33 +010087 uint32_t ctx_id;
Harald Welte10dfc5a2015-09-11 01:34:45 +020088 size_t encoded_imsi_len;
Harald Welte27f9c4a2015-08-30 22:47:18 +020089 int rc;
Harald Welteba43de42015-08-29 20:33:16 +020090
Harald Welte056984f2016-01-03 16:31:31 +010091 encoded_imsi_len = ranap_imsi_encode(encoded_imsi,
Harald Welte1d2c39d2015-09-11 17:49:37 +020092 sizeof(encoded_imsi), ue->imsi);
Harald Welte10dfc5a2015-09-11 01:34:45 +020093
Harald Welte2204f9d2015-09-07 21:10:50 +020094 memset(&accept, 0, sizeof(accept));
Harald Welte10dfc5a2015-09-11 01:34:45 +020095 accept.uE_Identity.present = UE_Identity_PR_iMSI;
Harald Welte1d2c39d2015-09-11 17:49:37 +020096 OCTET_STRING_fromBuf(&accept.uE_Identity.choice.iMSI,
97 (const char *)encoded_imsi, encoded_imsi_len);
Daniel Willmann92247312015-12-09 19:04:33 +010098 asn1_u24_to_bitstring(&accept.context_ID, &ctx_id, ue->context_id);
Harald Welteba43de42015-08-29 20:33:16 +020099
Harald Welte2204f9d2015-09-07 21:10:50 +0200100 memset(&accept_out, 0, sizeof(accept_out));
Harald Welte27f9c4a2015-08-30 22:47:18 +0200101 rc = hnbap_encode_ueregisteraccepties(&accept_out, &accept);
102 if (rc < 0) {
103 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200104 }
Harald Welte27f9c4a2015-08-30 22:47:18 +0200105
106 msg = hnbap_generate_successful_outcome(ProcedureCode_id_UERegister,
107 Criticality_reject,
108 &asn_DEF_UERegisterAccept,
109 &accept_out);
Daniel Willmann541e4292015-12-22 16:25:29 +0100110
111 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, &accept.uE_Identity.choice.iMSI);
112 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterAccept, &accept_out);
113
Harald Welte27f9c4a2015-08-30 22:47:18 +0200114 return hnbgw_hnbap_tx(ue->hnb, msg);
Harald Welteba43de42015-08-29 20:33:16 +0200115}
116
Neels Hofmeyr1a0bb512016-04-25 14:55:35 +0200117static int hnbgw_tx_ue_register_rej_tmsi(struct hnb_context *hnb, UE_Identity_t *ue_id)
118{
119 UERegisterReject_t reject_out;
120 UERegisterRejectIEs_t reject;
121 struct msgb *msg;
122 int rc;
123
124 memset(&reject, 0, sizeof(reject));
125 reject.uE_Identity.present = ue_id->present;
126
127 if (ue_id->present != UE_Identity_PR_tMSILAI) {
128 LOGP(DHNBAP, LOGL_ERROR, "Trying to reject UE Register without IMSI: only rejects of UE_Identity_PR_tMSILAI supported so far.\n");
129 return -1;
130 }
131
132 LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id tMSI %d %s\n",
133 ue_id->choice.tMSILAI.tMSI.size,
134 osmo_hexdump(ue_id->choice.tMSILAI.tMSI.buf,
135 ue_id->choice.tMSILAI.tMSI.size));
136
137 LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id pLMNID %d %s\n",
138 ue_id->choice.tMSILAI.lAI.pLMNID.size,
139 osmo_hexdump(ue_id->choice.tMSILAI.lAI.pLMNID.buf,
140 ue_id->choice.tMSILAI.lAI.pLMNID.size));
141
142 LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id lAC %d %s\n",
143 ue_id->choice.tMSILAI.lAI.lAC.size,
144 osmo_hexdump(ue_id->choice.tMSILAI.lAI.lAC.buf,
145 ue_id->choice.tMSILAI.lAI.lAC.size));
146
147 BIT_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.tMSI,
148 ue_id->choice.tMSILAI.tMSI.buf,
149 ue_id->choice.tMSILAI.tMSI.size * 8
150 - ue_id->choice.tMSILAI.tMSI.bits_unused);
151 OCTET_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.lAI.pLMNID,
152 ue_id->choice.tMSILAI.lAI.pLMNID.buf,
153 ue_id->choice.tMSILAI.lAI.pLMNID.size);
154 OCTET_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.lAI.lAC,
155 ue_id->choice.tMSILAI.lAI.lAC.buf,
156 ue_id->choice.tMSILAI.lAI.lAC.size);
157
158 reject.cause.present = Cause_PR_radioNetwork;
159 reject.cause.choice.radioNetwork = CauseRadioNetwork_invalid_UE_identity;
160
161 memset(&reject_out, 0, sizeof(reject_out));
162 rc = hnbap_encode_ueregisterrejecties(&reject_out, &reject);
163 if (rc < 0) {
164 return rc;
165 }
166
167 msg = hnbap_generate_unsuccessful_outcome(ProcedureCode_id_UERegister,
168 Criticality_reject,
169 &asn_DEF_UERegisterReject,
170 &reject_out);
171
172 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, &reject.uE_Identity.choice.tMSILAI.tMSI);
173 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, &reject.uE_Identity.choice.tMSILAI.lAI.pLMNID);
174 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, &reject.uE_Identity.choice.tMSILAI.lAI.lAC);
175 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterReject, &reject_out);
176
177 return hnbgw_hnbap_tx(hnb, msg);
178}
179
Daniel Willmannb433b972016-01-06 18:08:21 +0100180static int hnbgw_rx_hnb_deregister(struct hnb_context *ctx, ANY_t *in)
181{
182 HNBDe_RegisterIEs_t ies;
183 int rc;
184
185 rc = hnbap_decode_hnbde_registeries(&ies, in);
186 if (rc < 0)
187 return rc;
188
Neels Hofmeyr9246cc92016-04-25 14:47:26 +0200189 DEBUGP(DHNBAP, "HNB-DE-REGISTER cause=%ld\n",
Daniel Willmannb433b972016-01-06 18:08:21 +0100190 ies.cause);
191
Daniel Willmannd10002c2016-01-07 12:27:41 +0100192 hnbap_free_hnbde_registeries(&ies);
Daniel Willmannb433b972016-01-06 18:08:21 +0100193 hnb_context_release(ctx);
194
195 return 0;
196}
197
Harald Welte27f9c4a2015-08-30 22:47:18 +0200198static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, ANY_t *in)
Harald Welteba43de42015-08-29 20:33:16 +0200199{
Harald Welte27f9c4a2015-08-30 22:47:18 +0200200 HNBRegisterRequestIEs_t ies;
201 int rc;
Harald Welteba43de42015-08-29 20:33:16 +0200202
Harald Welte27f9c4a2015-08-30 22:47:18 +0200203 rc = hnbap_decode_hnbregisterrequesties(&ies, in);
204 if (rc < 0)
205 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200206
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200207 /* copy all identity parameters from the message to ctx */
Harald Welte27f9c4a2015-08-30 22:47:18 +0200208 asn1_strncpy(ctx->identity_info, &ies.hnB_Identity.hNB_Identity_Info,
209 sizeof(ctx->identity_info));
210 ctx->id.lac = asn1str_to_u16(&ies.lac);
211 ctx->id.sac = asn1str_to_u16(&ies.sac);
212 ctx->id.rac = asn1str_to_u8(&ies.rac);
Daniel Willmannd6a45b42015-12-08 13:55:17 +0100213 ctx->id.cid = asn1bitstr_to_u28(&ies.cellIdentity);
Harald Welteb3dae302015-08-30 12:20:09 +0200214 //ctx->id.mcc FIXME
215 //ctx->id.mnc FIXME
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200216
Daniel Willmannbded9842015-12-17 11:51:17 +0100217 DEBUGP(DHNBAP, "HNB-REGISTER-REQ from %s\n", ctx->identity_info);
Harald Welteee77cff2015-08-30 16:57:53 +0200218
Harald Welte27f9c4a2015-08-30 22:47:18 +0200219 /* Send HNBRegisterAccept */
Daniel Willmannd10002c2016-01-07 12:27:41 +0100220 rc = hnbgw_tx_hnb_register_acc(ctx);
221 hnbap_free_hnbregisterrequesties(&ies);
222 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200223}
224
Harald Welte27f9c4a2015-08-30 22:47:18 +0200225static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, ANY_t *in)
Harald Welteba43de42015-08-29 20:33:16 +0200226{
Harald Welte27f9c4a2015-08-30 22:47:18 +0200227 UERegisterRequestIEs_t ies;
228 struct ue_context *ue;
Harald Welte10dfc5a2015-09-11 01:34:45 +0200229 char imsi[16];
Harald Welte27f9c4a2015-08-30 22:47:18 +0200230 int rc;
Harald Welteba43de42015-08-29 20:33:16 +0200231
Harald Welte27f9c4a2015-08-30 22:47:18 +0200232 rc = hnbap_decode_ueregisterrequesties(&ies, in);
233 if (rc < 0)
234 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200235
Harald Welte10dfc5a2015-09-11 01:34:45 +0200236 switch (ies.uE_Identity.present) {
237 case UE_Identity_PR_iMSI:
Harald Welte056984f2016-01-03 16:31:31 +0100238 ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf,
Harald Welte10dfc5a2015-09-11 01:34:45 +0200239 ies.uE_Identity.choice.iMSI.size);
240 break;
241 case UE_Identity_PR_iMSIDS41:
Harald Welte056984f2016-01-03 16:31:31 +0100242 ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSIDS41.buf,
Harald Welte10dfc5a2015-09-11 01:34:45 +0200243 ies.uE_Identity.choice.iMSIDS41.size);
244 break;
245 case UE_Identity_PR_iMSIESN:
Harald Welte056984f2016-01-03 16:31:31 +0100246 ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSIESN.iMSIDS41.buf,
Harald Welte10dfc5a2015-09-11 01:34:45 +0200247 ies.uE_Identity.choice.iMSIESN.iMSIDS41.size);
248 break;
249 default:
Neels Hofmeyr9246cc92016-04-25 14:47:26 +0200250 LOGP(DHNBAP, LOGL_NOTICE, "UE-REGISTER-REQ without IMSI\n");
251 /* TODO: this is probably a TMSI registration. Store TMSIs
252 * and look them up to accept UE Registration. */
Neels Hofmeyr1a0bb512016-04-25 14:55:35 +0200253 rc = hnbgw_tx_ue_register_rej_tmsi(ctx, &ies.uE_Identity);
Neels Hofmeyrb248c8c2016-04-25 14:51:27 +0200254 hnbap_free_ueregisterrequesties(&ies);
Neels Hofmeyr1a0bb512016-04-25 14:55:35 +0200255 return rc;
Harald Welte10dfc5a2015-09-11 01:34:45 +0200256 }
Harald Welteb534e5c2015-09-11 00:15:16 +0200257
Harald Welte706213a2015-12-25 10:33:09 +0100258 DEBUGP(DHNBAP, "UE-REGISTER-REQ ID_type=%d imsi=%s cause=%ld\n",
Harald Welte10dfc5a2015-09-11 01:34:45 +0200259 ies.uE_Identity.present, imsi, ies.registration_Cause);
260
Harald Weltec4338de2015-12-24 00:40:52 +0100261 ue = ue_context_by_imsi(ctx->gw, imsi);
Harald Welte10dfc5a2015-09-11 01:34:45 +0200262 if (!ue)
263 ue = ue_context_alloc(ctx, imsi);
Harald Welte27f9c4a2015-08-30 22:47:18 +0200264
Daniel Willmannd10002c2016-01-07 12:27:41 +0100265 hnbap_free_ueregisterrequesties(&ies);
Harald Welte27f9c4a2015-08-30 22:47:18 +0200266 /* Send UERegisterAccept */
267 return hnbgw_tx_ue_register_acc(ue);
Harald Welteba43de42015-08-29 20:33:16 +0200268}
269
Daniel Willmannefceb182015-12-15 20:30:12 +0100270static int hnbgw_rx_ue_deregister(struct hnb_context *ctx, ANY_t *in)
271{
272 UEDe_RegisterIEs_t ies;
273 struct ue_context *ue;
274 int rc;
275 uint32_t ctxid;
276
277 rc = hnbap_decode_uede_registeries(&ies, in);
278 if (rc < 0)
279 return rc;
280
281 ctxid = asn1bitstr_to_u24(&ies.context_ID);
282
Harald Welte706213a2015-12-25 10:33:09 +0100283 DEBUGP(DHNBAP, "UE-DE-REGISTER context=%ld cause=%s\n",
Harald Welte2963ee22015-12-25 10:32:37 +0100284 ctxid, hnbap_cause_str(&ies.cause));
Daniel Willmannefceb182015-12-15 20:30:12 +0100285
Harald Weltec4338de2015-12-24 00:40:52 +0100286 ue = ue_context_by_id(ctx->gw, ctxid);
Daniel Willmannefceb182015-12-15 20:30:12 +0100287 if (ue)
288 ue_context_free(ue);
289
Daniel Willmannd10002c2016-01-07 12:27:41 +0100290 hnbap_free_uede_registeries(&ies);
Daniel Willmannefceb182015-12-15 20:30:12 +0100291 return 0;
292}
293
Harald Welte3af1db82015-09-11 17:03:16 +0200294static int hnbgw_rx_err_ind(struct hnb_context *hnb, ANY_t *in)
295{
296 ErrorIndicationIEs_t ies;
297 int rc;
298
Harald Welte1d2c39d2015-09-11 17:49:37 +0200299 rc = hnbap_decode_errorindicationies(&ies, in);
Harald Welte3af1db82015-09-11 17:03:16 +0200300 if (rc < 0)
301 return rc;
302
Daniel Willmannbded9842015-12-17 11:51:17 +0100303 LOGP(DHNBAP, LOGL_NOTICE, "HNBAP ERROR.ind, cause: %s\n",
Harald Welte3af1db82015-09-11 17:03:16 +0200304 hnbap_cause_str(&ies.cause));
305
Daniel Willmannd10002c2016-01-07 12:27:41 +0100306 hnbap_free_errorindicationies(&ies);
Harald Welte3af1db82015-09-11 17:03:16 +0200307 return 0;
308}
309
Harald Welte27f9c4a2015-08-30 22:47:18 +0200310static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, InitiatingMessage_t *imsg)
Harald Welteba43de42015-08-29 20:33:16 +0200311{
312 int rc;
313
Harald Welteb3dae302015-08-30 12:20:09 +0200314 switch (imsg->procedureCode) {
Harald Welte27f9c4a2015-08-30 22:47:18 +0200315 case ProcedureCode_id_HNBRegister: /* 8.2 */
316 rc = hnbgw_rx_hnb_register_req(hnb, &imsg->value);
Harald Welteba43de42015-08-29 20:33:16 +0200317 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200318 case ProcedureCode_id_HNBDe_Register: /* 8.3 */
Daniel Willmannb433b972016-01-06 18:08:21 +0100319 rc = hnbgw_rx_hnb_deregister(hnb, &imsg->value);
Harald Welteba43de42015-08-29 20:33:16 +0200320 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200321 case ProcedureCode_id_UERegister: /* 8.4 */
322 rc = hnbgw_rx_ue_register_req(hnb, &imsg->value);
Harald Welteba43de42015-08-29 20:33:16 +0200323 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200324 case ProcedureCode_id_UEDe_Register: /* 8.5 */
Daniel Willmannefceb182015-12-15 20:30:12 +0100325 rc = hnbgw_rx_ue_deregister(hnb, &imsg->value);
Harald Welteba43de42015-08-29 20:33:16 +0200326 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200327 case ProcedureCode_id_ErrorIndication: /* 8.6 */
Harald Welte3af1db82015-09-11 17:03:16 +0200328 rc = hnbgw_rx_err_ind(hnb, &imsg->value);
329 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200330 case ProcedureCode_id_TNLUpdate: /* 8.9 */
331 case ProcedureCode_id_HNBConfigTransfer: /* 8.10 */
332 case ProcedureCode_id_RelocationComplete: /* 8.11 */
333 case ProcedureCode_id_U_RNTIQuery: /* 8.12 */
334 case ProcedureCode_id_privateMessage:
Daniel Willmannbded9842015-12-17 11:51:17 +0100335 LOGP(DHNBAP, LOGL_NOTICE, "Unimplemented HNBAP Procedure %ld\n",
Harald Welte3af1db82015-09-11 17:03:16 +0200336 imsg->procedureCode);
Harald Welteba43de42015-08-29 20:33:16 +0200337 break;
338 default:
Daniel Willmannbded9842015-12-17 11:51:17 +0100339 LOGP(DHNBAP, LOGL_NOTICE, "Unknown HNBAP Procedure %ld\n",
Harald Welte3af1db82015-09-11 17:03:16 +0200340 imsg->procedureCode);
Harald Welteba43de42015-08-29 20:33:16 +0200341 break;
342 }
343}
344
Harald Welte27f9c4a2015-08-30 22:47:18 +0200345static int hnbgw_rx_successful_outcome_msg(struct hnb_context *hnb, SuccessfulOutcome_t *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200346{
347
348}
349
Harald Welte27f9c4a2015-08-30 22:47:18 +0200350static int hnbgw_rx_unsuccessful_outcome_msg(struct hnb_context *hnb, UnsuccessfulOutcome_t *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200351{
352
353}
354
355
Harald Welte27f9c4a2015-08-30 22:47:18 +0200356static int _hnbgw_hnbap_rx(struct hnb_context *hnb, HNBAP_PDU_t *pdu)
Harald Welteba43de42015-08-29 20:33:16 +0200357{
Daniel Willmann5f810f42015-12-17 17:57:51 +0100358 int rc = 0;
Harald Welteb3dae302015-08-30 12:20:09 +0200359
Harald Welteba43de42015-08-29 20:33:16 +0200360 /* it's a bit odd that we can't dispatch on procedure code, but
361 * that's not possible */
Harald Welte27f9c4a2015-08-30 22:47:18 +0200362 switch (pdu->present) {
363 case HNBAP_PDU_PR_initiatingMessage:
364 rc = hnbgw_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage);
Harald Welteba43de42015-08-29 20:33:16 +0200365 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200366 case HNBAP_PDU_PR_successfulOutcome:
367 rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->choice.successfulOutcome);
Harald Welteba43de42015-08-29 20:33:16 +0200368 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200369 case HNBAP_PDU_PR_unsuccessfulOutcome:
370 rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->choice.unsuccessfulOutcome);
Harald Welteba43de42015-08-29 20:33:16 +0200371 break;
372 default:
Daniel Willmannbded9842015-12-17 11:51:17 +0100373 LOGP(DHNBAP, LOGL_NOTICE, "Unknown HNBAP Presence %u\n",
Harald Welte3af1db82015-09-11 17:03:16 +0200374 pdu->present);
Daniel Willmann5f810f42015-12-17 17:57:51 +0100375 rc = -1;
Harald Welteba43de42015-08-29 20:33:16 +0200376 }
Daniel Willmann5f810f42015-12-17 17:57:51 +0100377
378 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200379}
380
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200381int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200382{
Harald Welte27f9c4a2015-08-30 22:47:18 +0200383 HNBAP_PDU_t _pdu, *pdu = &_pdu;
384 asn_dec_rval_t dec_ret;
Harald Welteee77cff2015-08-30 16:57:53 +0200385 int rc;
386
387 /* decode and handle to _hnbgw_hnbap_rx() */
388
Harald Welte2204f9d2015-09-07 21:10:50 +0200389 memset(pdu, 0, sizeof(*pdu));
Harald Welte27f9c4a2015-08-30 22:47:18 +0200390 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
391 msg->data, msgb_length(msg), 0, 0);
392 if (dec_ret.code != RC_OK) {
Daniel Willmannbded9842015-12-17 11:51:17 +0100393 LOGP(DHNBAP, LOGL_ERROR, "Error in ASN.1 decode\n");
Harald Welteee77cff2015-08-30 16:57:53 +0200394 return rc;
395 }
396
397 rc = _hnbgw_hnbap_rx(hnb, pdu);
Harald Welteee77cff2015-08-30 16:57:53 +0200398
Daniel Willmann59d17d82015-12-17 17:56:56 +0100399 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_PDU, pdu);
400
Harald Welteee77cff2015-08-30 16:57:53 +0200401 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200402}
403
404
405int hnbgw_hnbap_init(void)
406{
407
408}