Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 1 | /* 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 Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 21 | #include <osmocom/core/msgb.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 22 | #include <osmocom/core/utils.h> |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 23 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 24 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 25 | #include <unistd.h> |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 26 | #include <errno.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 27 | #include <string.h> |
| 28 | |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame] | 29 | #include "asn1helpers.h" |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 30 | #include "iu_helpers.h" |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame] | 31 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 32 | #include "hnbgw.h" |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 33 | #include "hnbap_common.h" |
| 34 | #include "hnbap_ies_defs.h" |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 35 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 36 | #define IU_MSG_NUM_IES 32 |
| 37 | #define IU_MSG_NUM_EXT_IES 32 |
| 38 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 39 | static int hnbgw_hnbap_tx(struct hnb_context *ctx, struct msgb *msg) |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 40 | { |
Harald Welte | 7b54e32 | 2015-09-07 22:41:45 +0200 | [diff] [blame] | 41 | if (!msg) |
| 42 | return -EINVAL; |
| 43 | |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 44 | msgb_ppid(msg) = IUH_PPI_HNBAP; |
| 45 | return osmo_wqueue_enqueue(&ctx->wqueue, msg); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 46 | } |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 47 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 48 | static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx) |
| 49 | { |
| 50 | HNBRegisterAccept_t accept_out; |
| 51 | struct msgb *msg; |
| 52 | int rc; |
| 53 | |
| 54 | /* Single required response IE: RNC-ID */ |
| 55 | HNBRegisterAcceptIEs_t accept = { |
| 56 | .rnc_id = ctx->gw->config.rnc_id |
| 57 | }; |
| 58 | |
| 59 | /* encode the Information Elements */ |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 60 | memset(&accept_out, 0, sizeof(accept_out)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 61 | rc = hnbap_encode_hnbregisteraccepties(&accept_out, &accept); |
| 62 | if (rc < 0) { |
| 63 | return rc; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 66 | /* generate a successfull outcome PDU */ |
| 67 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_HNBRegister, |
| 68 | Criticality_reject, |
| 69 | &asn_DEF_HNBRegisterAccept, |
| 70 | &accept_out); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 71 | |
Daniel Willmann | 59d17d8 | 2015-12-17 17:56:56 +0100 | [diff] [blame] | 72 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBRegisterAccept, &accept_out); |
| 73 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 74 | return hnbgw_hnbap_tx(ctx, msg); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 78 | static int hnbgw_tx_ue_register_acc(struct ue_context *ue) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 79 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 80 | UERegisterAccept_t accept_out; |
| 81 | UERegisterAcceptIEs_t accept; |
| 82 | struct msgb *msg; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 83 | uint8_t encoded_imsi[10]; |
Daniel Willmann | 9224731 | 2015-12-09 19:04:33 +0100 | [diff] [blame] | 84 | uint32_t ctx_id; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 85 | size_t encoded_imsi_len; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 86 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 87 | |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 88 | encoded_imsi_len = encode_iu_imsi(encoded_imsi, |
| 89 | sizeof(encoded_imsi), ue->imsi); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 90 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 91 | memset(&accept, 0, sizeof(accept)); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 92 | accept.uE_Identity.present = UE_Identity_PR_iMSI; |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 93 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.iMSI, |
| 94 | (const char *)encoded_imsi, encoded_imsi_len); |
Daniel Willmann | 9224731 | 2015-12-09 19:04:33 +0100 | [diff] [blame] | 95 | asn1_u24_to_bitstring(&accept.context_ID, &ctx_id, ue->context_id); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 96 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 97 | memset(&accept_out, 0, sizeof(accept_out)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 98 | rc = hnbap_encode_ueregisteraccepties(&accept_out, &accept); |
| 99 | if (rc < 0) { |
| 100 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 101 | } |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 102 | |
| 103 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_UERegister, |
| 104 | Criticality_reject, |
| 105 | &asn_DEF_UERegisterAccept, |
| 106 | &accept_out); |
| 107 | return hnbgw_hnbap_tx(ue->hnb, msg); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 110 | static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, ANY_t *in) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 111 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 112 | HNBRegisterRequestIEs_t ies; |
| 113 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 114 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 115 | rc = hnbap_decode_hnbregisterrequesties(&ies, in); |
| 116 | if (rc < 0) |
| 117 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 118 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 119 | /* copy all identity parameters from the message to ctx */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 120 | asn1_strncpy(ctx->identity_info, &ies.hnB_Identity.hNB_Identity_Info, |
| 121 | sizeof(ctx->identity_info)); |
| 122 | ctx->id.lac = asn1str_to_u16(&ies.lac); |
| 123 | ctx->id.sac = asn1str_to_u16(&ies.sac); |
| 124 | ctx->id.rac = asn1str_to_u8(&ies.rac); |
Daniel Willmann | d6a45b4 | 2015-12-08 13:55:17 +0100 | [diff] [blame] | 125 | ctx->id.cid = asn1bitstr_to_u28(&ies.cellIdentity); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 126 | //ctx->id.mcc FIXME |
| 127 | //ctx->id.mnc FIXME |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 128 | |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 129 | DEBUGP(DHNBAP, "HNB-REGISTER-REQ from %s\n", ctx->identity_info); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 130 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 131 | /* Send HNBRegisterAccept */ |
| 132 | return hnbgw_tx_hnb_register_acc(ctx); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 135 | static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, ANY_t *in) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 136 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 137 | UERegisterRequestIEs_t ies; |
| 138 | struct ue_context *ue; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 139 | char imsi[16]; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 140 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 141 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 142 | rc = hnbap_decode_ueregisterrequesties(&ies, in); |
| 143 | if (rc < 0) |
| 144 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 145 | |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 146 | switch (ies.uE_Identity.present) { |
| 147 | case UE_Identity_PR_iMSI: |
| 148 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
| 149 | ies.uE_Identity.choice.iMSI.size); |
| 150 | break; |
| 151 | case UE_Identity_PR_iMSIDS41: |
| 152 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSIDS41.buf, |
| 153 | ies.uE_Identity.choice.iMSIDS41.size); |
| 154 | break; |
| 155 | case UE_Identity_PR_iMSIESN: |
| 156 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSIESN.iMSIDS41.buf, |
| 157 | ies.uE_Identity.choice.iMSIESN.iMSIDS41.size); |
| 158 | break; |
| 159 | default: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 160 | LOGP(DHNBAP, LOGL_NOTICE, "UE-REGISTER-REQ without IMSI?!?\n"); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 161 | return -1; |
| 162 | } |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 163 | |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 164 | DEBUGP(DHNBAP, "UE-REGSITER-REQ ID_type=%d imsi=%s cause=%ld\n", |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 165 | ies.uE_Identity.present, imsi, ies.registration_Cause); |
| 166 | |
| 167 | ue = ue_context_by_imsi(imsi); |
| 168 | if (!ue) |
| 169 | ue = ue_context_alloc(ctx, imsi); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 170 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 171 | /* Send UERegisterAccept */ |
| 172 | return hnbgw_tx_ue_register_acc(ue); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 175 | static int hnbgw_rx_ue_deregister(struct hnb_context *ctx, ANY_t *in) |
| 176 | { |
| 177 | UEDe_RegisterIEs_t ies; |
| 178 | struct ue_context *ue; |
| 179 | int rc; |
| 180 | uint32_t ctxid; |
| 181 | |
| 182 | rc = hnbap_decode_uede_registeries(&ies, in); |
| 183 | if (rc < 0) |
| 184 | return rc; |
| 185 | |
| 186 | ctxid = asn1bitstr_to_u24(&ies.context_ID); |
| 187 | |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 188 | DEBUGP(DHNBAP, "UE-DE-REGSITER context=%ld cause=%ld\n", |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 189 | ctxid, ies.cause); |
| 190 | |
| 191 | ue = ue_context_by_id(ctxid); |
| 192 | if (ue) |
| 193 | ue_context_free(ue); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 198 | static int hnbgw_rx_err_ind(struct hnb_context *hnb, ANY_t *in) |
| 199 | { |
| 200 | ErrorIndicationIEs_t ies; |
| 201 | int rc; |
| 202 | |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 203 | rc = hnbap_decode_errorindicationies(&ies, in); |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 204 | if (rc < 0) |
| 205 | return rc; |
| 206 | |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 207 | LOGP(DHNBAP, LOGL_NOTICE, "HNBAP ERROR.ind, cause: %s\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 208 | hnbap_cause_str(&ies.cause)); |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 213 | static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, InitiatingMessage_t *imsg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 214 | { |
| 215 | int rc; |
| 216 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 217 | switch (imsg->procedureCode) { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 218 | case ProcedureCode_id_HNBRegister: /* 8.2 */ |
| 219 | rc = hnbgw_rx_hnb_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 220 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 221 | case ProcedureCode_id_HNBDe_Register: /* 8.3 */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 222 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 223 | case ProcedureCode_id_UERegister: /* 8.4 */ |
| 224 | rc = hnbgw_rx_ue_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 225 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 226 | case ProcedureCode_id_UEDe_Register: /* 8.5 */ |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 227 | rc = hnbgw_rx_ue_deregister(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 228 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 229 | case ProcedureCode_id_ErrorIndication: /* 8.6 */ |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 230 | rc = hnbgw_rx_err_ind(hnb, &imsg->value); |
| 231 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 232 | case ProcedureCode_id_TNLUpdate: /* 8.9 */ |
| 233 | case ProcedureCode_id_HNBConfigTransfer: /* 8.10 */ |
| 234 | case ProcedureCode_id_RelocationComplete: /* 8.11 */ |
| 235 | case ProcedureCode_id_U_RNTIQuery: /* 8.12 */ |
| 236 | case ProcedureCode_id_privateMessage: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 237 | LOGP(DHNBAP, LOGL_NOTICE, "Unimplemented HNBAP Procedure %ld\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 238 | imsg->procedureCode); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 239 | break; |
| 240 | default: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 241 | LOGP(DHNBAP, LOGL_NOTICE, "Unknown HNBAP Procedure %ld\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 242 | imsg->procedureCode); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 243 | break; |
| 244 | } |
| 245 | } |
| 246 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 247 | static int hnbgw_rx_successful_outcome_msg(struct hnb_context *hnb, SuccessfulOutcome_t *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 248 | { |
| 249 | |
| 250 | } |
| 251 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 252 | static int hnbgw_rx_unsuccessful_outcome_msg(struct hnb_context *hnb, UnsuccessfulOutcome_t *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 253 | { |
| 254 | |
| 255 | } |
| 256 | |
| 257 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 258 | static int _hnbgw_hnbap_rx(struct hnb_context *hnb, HNBAP_PDU_t *pdu) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 259 | { |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 260 | int rc = 0; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 261 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 262 | /* it's a bit odd that we can't dispatch on procedure code, but |
| 263 | * that's not possible */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 264 | switch (pdu->present) { |
| 265 | case HNBAP_PDU_PR_initiatingMessage: |
| 266 | rc = hnbgw_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 267 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 268 | case HNBAP_PDU_PR_successfulOutcome: |
| 269 | rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->choice.successfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 270 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 271 | case HNBAP_PDU_PR_unsuccessfulOutcome: |
| 272 | rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->choice.unsuccessfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 273 | break; |
| 274 | default: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 275 | LOGP(DHNBAP, LOGL_NOTICE, "Unknown HNBAP Presence %u\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 276 | pdu->present); |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 277 | rc = -1; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 278 | } |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 279 | |
| 280 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 283 | int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 284 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 285 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 286 | asn_dec_rval_t dec_ret; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 287 | int rc; |
| 288 | |
| 289 | /* decode and handle to _hnbgw_hnbap_rx() */ |
| 290 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 291 | memset(pdu, 0, sizeof(*pdu)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 292 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 293 | msg->data, msgb_length(msg), 0, 0); |
| 294 | if (dec_ret.code != RC_OK) { |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 295 | LOGP(DHNBAP, LOGL_ERROR, "Error in ASN.1 decode\n"); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 296 | return rc; |
| 297 | } |
| 298 | |
| 299 | rc = _hnbgw_hnbap_rx(hnb, pdu); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 300 | |
Daniel Willmann | 59d17d8 | 2015-12-17 17:56:56 +0100 | [diff] [blame] | 301 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_PDU, pdu); |
| 302 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 303 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
| 307 | int hnbgw_hnbap_init(void) |
| 308 | { |
| 309 | |
| 310 | } |