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 | 8345792 | 2016-08-26 23:56:44 +0200 | [diff] [blame] | 31 | #include <osmocom/hnbap/hnbap_common.h> |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 32 | #include <osmocom/ranap/iu_helpers.h> |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame] | 33 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 34 | #include <osmocom/iuh/hnbgw.h> |
Neels Hofmeyr | 8345792 | 2016-08-26 23:56:44 +0200 | [diff] [blame] | 35 | #include <osmocom/hnbap/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 | |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 117 | static 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 | |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame^] | 127 | /* Copy the identity over to the reject message */ |
| 128 | switch (ue_id->present) { |
| 129 | case UE_Identity_PR_tMSILAI: |
| 130 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id tMSI %d %s\n", |
| 131 | ue_id->choice.tMSILAI.tMSI.size, |
| 132 | osmo_hexdump(ue_id->choice.tMSILAI.tMSI.buf, |
| 133 | ue_id->choice.tMSILAI.tMSI.size)); |
| 134 | |
| 135 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id pLMNID %d %s\n", |
| 136 | ue_id->choice.tMSILAI.lAI.pLMNID.size, |
| 137 | osmo_hexdump(ue_id->choice.tMSILAI.lAI.pLMNID.buf, |
| 138 | ue_id->choice.tMSILAI.lAI.pLMNID.size)); |
| 139 | |
| 140 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id lAC %d %s\n", |
| 141 | ue_id->choice.tMSILAI.lAI.lAC.size, |
| 142 | osmo_hexdump(ue_id->choice.tMSILAI.lAI.lAC.buf, |
| 143 | ue_id->choice.tMSILAI.lAI.lAC.size)); |
| 144 | |
| 145 | BIT_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.tMSI, |
| 146 | ue_id->choice.tMSILAI.tMSI.buf, |
| 147 | ue_id->choice.tMSILAI.tMSI.size * 8 |
| 148 | - ue_id->choice.tMSILAI.tMSI.bits_unused); |
| 149 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.lAI.pLMNID, |
| 150 | ue_id->choice.tMSILAI.lAI.pLMNID.buf, |
| 151 | ue_id->choice.tMSILAI.lAI.pLMNID.size); |
| 152 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.lAI.lAC, |
| 153 | ue_id->choice.tMSILAI.lAI.lAC.buf, |
| 154 | ue_id->choice.tMSILAI.lAI.lAC.size); |
| 155 | break; |
| 156 | |
| 157 | case UE_Identity_PR_pTMSIRAI: |
| 158 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id pTMSI %d %s\n", |
| 159 | ue_id->choice.pTMSIRAI.pTMSI.size, |
| 160 | osmo_hexdump(ue_id->choice.pTMSIRAI.pTMSI.buf, |
| 161 | ue_id->choice.pTMSIRAI.pTMSI.size)); |
| 162 | |
| 163 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id pLMNID %d %s\n", |
| 164 | ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size, |
| 165 | osmo_hexdump(ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.buf, |
| 166 | ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size)); |
| 167 | |
| 168 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id lAC %d %s\n", |
| 169 | ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size, |
| 170 | osmo_hexdump(ue_id->choice.pTMSIRAI.rAI.lAI.lAC.buf, |
| 171 | ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size)); |
| 172 | |
| 173 | LOGP(DHNBAP, LOGL_DEBUG, "REJ UE_Id rAC %d %s\n", |
| 174 | ue_id->choice.pTMSIRAI.rAI.rAC.size, |
| 175 | osmo_hexdump(ue_id->choice.pTMSIRAI.rAI.rAC.buf, |
| 176 | ue_id->choice.pTMSIRAI.rAI.rAC.size)); |
| 177 | |
| 178 | BIT_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.pTMSI, |
| 179 | ue_id->choice.pTMSIRAI.pTMSI.buf, |
| 180 | ue_id->choice.pTMSIRAI.pTMSI.size * 8 |
| 181 | - ue_id->choice.pTMSIRAI.pTMSI.bits_unused); |
| 182 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.pLMNID, |
| 183 | ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.buf, |
| 184 | ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size); |
| 185 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.lAC, |
| 186 | ue_id->choice.pTMSIRAI.rAI.lAI.lAC.buf, |
| 187 | ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size); |
| 188 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.rAI.rAC, |
| 189 | ue_id->choice.pTMSIRAI.rAI.rAC.buf, |
| 190 | ue_id->choice.pTMSIRAI.rAI.rAC.size); |
| 191 | break; |
| 192 | |
| 193 | default: |
| 194 | LOGP(DHNBAP, LOGL_ERROR, "Cannot compose UE Register Reject:" |
| 195 | " unsupported UE ID (present=%d)\n", ue_id->present); |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 196 | return -1; |
| 197 | } |
| 198 | |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame^] | 199 | LOGP(DHNBAP, LOGL_ERROR, "Rejecting UE Register Request:" |
| 200 | " TMSI identity registration is switched off\n"); |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 201 | |
| 202 | reject.cause.present = Cause_PR_radioNetwork; |
| 203 | reject.cause.choice.radioNetwork = CauseRadioNetwork_invalid_UE_identity; |
| 204 | |
| 205 | memset(&reject_out, 0, sizeof(reject_out)); |
| 206 | rc = hnbap_encode_ueregisterrejecties(&reject_out, &reject); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame^] | 207 | if (rc < 0) |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 208 | return rc; |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 209 | |
| 210 | msg = hnbap_generate_unsuccessful_outcome(ProcedureCode_id_UERegister, |
| 211 | Criticality_reject, |
| 212 | &asn_DEF_UERegisterReject, |
| 213 | &reject_out); |
| 214 | |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame^] | 215 | /* Free copied identity IEs */ |
| 216 | switch (ue_id->present) { |
| 217 | case UE_Identity_PR_tMSILAI: |
| 218 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, |
| 219 | &reject.uE_Identity.choice.tMSILAI.tMSI); |
| 220 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 221 | &reject.uE_Identity.choice.tMSILAI.lAI.pLMNID); |
| 222 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 223 | &reject.uE_Identity.choice.tMSILAI.lAI.lAC); |
| 224 | break; |
| 225 | |
| 226 | case UE_Identity_PR_pTMSIRAI: |
| 227 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, |
| 228 | &reject.uE_Identity.choice.pTMSIRAI.pTMSI); |
| 229 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 230 | &reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.pLMNID); |
| 231 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 232 | &reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.lAC); |
| 233 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 234 | &reject.uE_Identity.choice.pTMSIRAI.rAI.rAC); |
| 235 | break; |
| 236 | |
| 237 | default: |
| 238 | /* should never happen after above switch() */ |
| 239 | break; |
| 240 | } |
| 241 | |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 242 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterReject, &reject_out); |
| 243 | |
| 244 | return hnbgw_hnbap_tx(hnb, msg); |
| 245 | } |
| 246 | |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 247 | static int hnbgw_rx_hnb_deregister(struct hnb_context *ctx, ANY_t *in) |
| 248 | { |
| 249 | HNBDe_RegisterIEs_t ies; |
| 250 | int rc; |
| 251 | |
| 252 | rc = hnbap_decode_hnbde_registeries(&ies, in); |
| 253 | if (rc < 0) |
| 254 | return rc; |
| 255 | |
Neels Hofmeyr | 9246cc9 | 2016-04-25 14:47:26 +0200 | [diff] [blame] | 256 | DEBUGP(DHNBAP, "HNB-DE-REGISTER cause=%ld\n", |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 257 | ies.cause); |
| 258 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 259 | hnbap_free_hnbde_registeries(&ies); |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 260 | hnb_context_release(ctx); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 265 | 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] | 266 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 267 | HNBRegisterRequestIEs_t ies; |
| 268 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 269 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 270 | rc = hnbap_decode_hnbregisterrequesties(&ies, in); |
| 271 | if (rc < 0) |
| 272 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 273 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 274 | /* copy all identity parameters from the message to ctx */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 275 | asn1_strncpy(ctx->identity_info, &ies.hnB_Identity.hNB_Identity_Info, |
| 276 | sizeof(ctx->identity_info)); |
| 277 | ctx->id.lac = asn1str_to_u16(&ies.lac); |
| 278 | ctx->id.sac = asn1str_to_u16(&ies.sac); |
| 279 | ctx->id.rac = asn1str_to_u8(&ies.rac); |
Daniel Willmann | d6a45b4 | 2015-12-08 13:55:17 +0100 | [diff] [blame] | 280 | ctx->id.cid = asn1bitstr_to_u28(&ies.cellIdentity); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 281 | //ctx->id.mcc FIXME |
| 282 | //ctx->id.mnc FIXME |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 283 | |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 284 | DEBUGP(DHNBAP, "HNB-REGISTER-REQ from %s\n", ctx->identity_info); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 285 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 286 | /* Send HNBRegisterAccept */ |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 287 | rc = hnbgw_tx_hnb_register_acc(ctx); |
| 288 | hnbap_free_hnbregisterrequesties(&ies); |
| 289 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 292 | 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] | 293 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 294 | UERegisterRequestIEs_t ies; |
| 295 | struct ue_context *ue; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 296 | char imsi[16]; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 297 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 298 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 299 | rc = hnbap_decode_ueregisterrequesties(&ies, in); |
| 300 | if (rc < 0) |
| 301 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 302 | |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 303 | switch (ies.uE_Identity.present) { |
| 304 | case UE_Identity_PR_iMSI: |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 305 | ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 306 | ies.uE_Identity.choice.iMSI.size); |
| 307 | break; |
| 308 | case UE_Identity_PR_iMSIDS41: |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 309 | ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSIDS41.buf, |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 310 | ies.uE_Identity.choice.iMSIDS41.size); |
| 311 | break; |
| 312 | case UE_Identity_PR_iMSIESN: |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 313 | 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] | 314 | ies.uE_Identity.choice.iMSIESN.iMSIDS41.size); |
| 315 | break; |
| 316 | default: |
Neels Hofmeyr | 9246cc9 | 2016-04-25 14:47:26 +0200 | [diff] [blame] | 317 | LOGP(DHNBAP, LOGL_NOTICE, "UE-REGISTER-REQ without IMSI\n"); |
| 318 | /* TODO: this is probably a TMSI registration. Store TMSIs |
| 319 | * and look them up to accept UE Registration. */ |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 320 | rc = hnbgw_tx_ue_register_rej_tmsi(ctx, &ies.uE_Identity); |
Neels Hofmeyr | b248c8c | 2016-04-25 14:51:27 +0200 | [diff] [blame] | 321 | hnbap_free_ueregisterrequesties(&ies); |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 322 | return rc; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 323 | } |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 324 | |
Harald Welte | 706213a | 2015-12-25 10:33:09 +0100 | [diff] [blame] | 325 | 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] | 326 | ies.uE_Identity.present, imsi, ies.registration_Cause); |
| 327 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 328 | ue = ue_context_by_imsi(ctx->gw, imsi); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 329 | if (!ue) |
| 330 | ue = ue_context_alloc(ctx, imsi); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 331 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 332 | hnbap_free_ueregisterrequesties(&ies); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 333 | /* Send UERegisterAccept */ |
| 334 | return hnbgw_tx_ue_register_acc(ue); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 337 | static int hnbgw_rx_ue_deregister(struct hnb_context *ctx, ANY_t *in) |
| 338 | { |
| 339 | UEDe_RegisterIEs_t ies; |
| 340 | struct ue_context *ue; |
| 341 | int rc; |
| 342 | uint32_t ctxid; |
| 343 | |
| 344 | rc = hnbap_decode_uede_registeries(&ies, in); |
| 345 | if (rc < 0) |
| 346 | return rc; |
| 347 | |
| 348 | ctxid = asn1bitstr_to_u24(&ies.context_ID); |
| 349 | |
Harald Welte | 706213a | 2015-12-25 10:33:09 +0100 | [diff] [blame] | 350 | DEBUGP(DHNBAP, "UE-DE-REGISTER context=%ld cause=%s\n", |
Harald Welte | 2963ee2 | 2015-12-25 10:32:37 +0100 | [diff] [blame] | 351 | ctxid, hnbap_cause_str(&ies.cause)); |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 352 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 353 | ue = ue_context_by_id(ctx->gw, ctxid); |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 354 | if (ue) |
| 355 | ue_context_free(ue); |
| 356 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 357 | hnbap_free_uede_registeries(&ies); |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 361 | static int hnbgw_rx_err_ind(struct hnb_context *hnb, ANY_t *in) |
| 362 | { |
| 363 | ErrorIndicationIEs_t ies; |
| 364 | int rc; |
| 365 | |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 366 | rc = hnbap_decode_errorindicationies(&ies, in); |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 367 | if (rc < 0) |
| 368 | return rc; |
| 369 | |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 370 | LOGP(DHNBAP, LOGL_NOTICE, "HNBAP ERROR.ind, cause: %s\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 371 | hnbap_cause_str(&ies.cause)); |
| 372 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 373 | hnbap_free_errorindicationies(&ies); |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 377 | 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] | 378 | { |
| 379 | int rc; |
| 380 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 381 | switch (imsg->procedureCode) { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 382 | case ProcedureCode_id_HNBRegister: /* 8.2 */ |
| 383 | rc = hnbgw_rx_hnb_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 384 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 385 | case ProcedureCode_id_HNBDe_Register: /* 8.3 */ |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 386 | rc = hnbgw_rx_hnb_deregister(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 387 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 388 | case ProcedureCode_id_UERegister: /* 8.4 */ |
| 389 | rc = hnbgw_rx_ue_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 390 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 391 | case ProcedureCode_id_UEDe_Register: /* 8.5 */ |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 392 | rc = hnbgw_rx_ue_deregister(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 393 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 394 | case ProcedureCode_id_ErrorIndication: /* 8.6 */ |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 395 | rc = hnbgw_rx_err_ind(hnb, &imsg->value); |
| 396 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 397 | case ProcedureCode_id_TNLUpdate: /* 8.9 */ |
| 398 | case ProcedureCode_id_HNBConfigTransfer: /* 8.10 */ |
| 399 | case ProcedureCode_id_RelocationComplete: /* 8.11 */ |
| 400 | case ProcedureCode_id_U_RNTIQuery: /* 8.12 */ |
| 401 | case ProcedureCode_id_privateMessage: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 402 | LOGP(DHNBAP, LOGL_NOTICE, "Unimplemented HNBAP Procedure %ld\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 403 | imsg->procedureCode); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 404 | break; |
| 405 | default: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 406 | LOGP(DHNBAP, LOGL_NOTICE, "Unknown HNBAP Procedure %ld\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 407 | imsg->procedureCode); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 408 | break; |
| 409 | } |
| 410 | } |
| 411 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 412 | 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] | 413 | { |
| 414 | |
| 415 | } |
| 416 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 417 | 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] | 418 | { |
| 419 | |
| 420 | } |
| 421 | |
| 422 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 423 | 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] | 424 | { |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 425 | int rc = 0; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 426 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 427 | /* it's a bit odd that we can't dispatch on procedure code, but |
| 428 | * that's not possible */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 429 | switch (pdu->present) { |
| 430 | case HNBAP_PDU_PR_initiatingMessage: |
| 431 | rc = hnbgw_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 432 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 433 | case HNBAP_PDU_PR_successfulOutcome: |
| 434 | rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->choice.successfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 435 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 436 | case HNBAP_PDU_PR_unsuccessfulOutcome: |
| 437 | rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->choice.unsuccessfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 438 | break; |
| 439 | default: |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 440 | LOGP(DHNBAP, LOGL_NOTICE, "Unknown HNBAP Presence %u\n", |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 441 | pdu->present); |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 442 | rc = -1; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 443 | } |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 444 | |
| 445 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 446 | } |
| 447 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 448 | int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 449 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 450 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 451 | asn_dec_rval_t dec_ret; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 452 | int rc; |
| 453 | |
| 454 | /* decode and handle to _hnbgw_hnbap_rx() */ |
| 455 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 456 | memset(pdu, 0, sizeof(*pdu)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 457 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 458 | msg->data, msgb_length(msg), 0, 0); |
| 459 | if (dec_ret.code != RC_OK) { |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 460 | LOGP(DHNBAP, LOGL_ERROR, "Error in ASN.1 decode\n"); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 461 | return rc; |
| 462 | } |
| 463 | |
| 464 | rc = _hnbgw_hnbap_rx(hnb, pdu); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 465 | |
Daniel Willmann | 59d17d8 | 2015-12-17 17:56:56 +0100 | [diff] [blame] | 466 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_PDU, pdu); |
| 467 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 468 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
| 472 | int hnbgw_hnbap_init(void) |
| 473 | { |
| 474 | |
| 475 | } |