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