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> |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 23 | #include <osmocom/core/socket.h> |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 24 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 25 | #include <osmocom/netif/stream.h> |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 26 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 27 | #include <unistd.h> |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 28 | #include <errno.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 29 | #include <string.h> |
| 30 | |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame] | 31 | #include "asn1helpers.h" |
Neels Hofmeyr | 8345792 | 2016-08-26 23:56:44 +0200 | [diff] [blame] | 32 | #include <osmocom/hnbap/hnbap_common.h> |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 33 | #include <osmocom/ranap/iu_helpers.h> |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame] | 34 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 35 | #include <osmocom/iuh/hnbgw.h> |
Neels Hofmeyr | 8345792 | 2016-08-26 23:56:44 +0200 | [diff] [blame] | 36 | #include <osmocom/hnbap/hnbap_ies_defs.h> |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 37 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 38 | #define IU_MSG_NUM_IES 32 |
| 39 | #define IU_MSG_NUM_EXT_IES 32 |
| 40 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 41 | static int hnbgw_hnbap_tx(struct hnb_context *ctx, struct msgb *msg) |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 42 | { |
Harald Welte | 7b54e32 | 2015-09-07 22:41:45 +0200 | [diff] [blame] | 43 | if (!msg) |
| 44 | return -EINVAL; |
| 45 | |
Harald Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 46 | msgb_sctp_ppid(msg) = IUH_PPI_HNBAP; |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 47 | osmo_stream_srv_send(ctx->conn, msg); |
| 48 | |
| 49 | return 0; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 50 | } |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 51 | |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 52 | static int hnbgw_tx_hnb_register_rej(struct hnb_context *ctx) |
| 53 | { |
| 54 | HNBRegisterReject_t reject_out; |
| 55 | HNBRegisterRejectIEs_t reject; |
| 56 | struct msgb *msg; |
| 57 | int rc; |
| 58 | |
| 59 | reject.presenceMask = 0, |
| 60 | reject.cause.present = Cause_PR_radioNetwork; |
| 61 | reject.cause.choice.radioNetwork = CauseRadioNetwork_unspecified; |
| 62 | |
| 63 | /* encode the Information Elements */ |
| 64 | memset(&reject_out, 0, sizeof(reject_out)); |
| 65 | rc = hnbap_encode_hnbregisterrejecties(&reject_out, &reject); |
| 66 | if (rc < 0) { |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 67 | LOGHNB(ctx, DHNBAP, LOGL_ERROR, "Failure to encode HNB-REGISTER-REJECT to %s: rc=%d\n", |
| 68 | ctx->identity_info, rc); |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 69 | return rc; |
| 70 | } |
| 71 | |
| 72 | /* generate a successfull outcome PDU */ |
| 73 | msg = hnbap_generate_unsuccessful_outcome(ProcedureCode_id_HNBRegister, |
| 74 | Criticality_reject, |
| 75 | &asn_DEF_HNBRegisterReject, |
| 76 | &reject_out); |
| 77 | |
| 78 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBRegisterReject, &reject_out); |
| 79 | |
| 80 | rc = hnbgw_hnbap_tx(ctx, msg); |
| 81 | if (rc == 0) { |
| 82 | /* Tell libosmo-netif to destroy this connection when it is done |
| 83 | * sending our HNB-REGISTER-REJECT response. */ |
| 84 | osmo_stream_srv_set_flush_and_destroy(ctx->conn); |
| 85 | } else { |
| 86 | /* The message was not queued. Destroy the connection right away. */ |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 87 | hnb_context_release(ctx); |
Harald Welte | 9aad185 | 2018-10-21 11:45:26 +0200 | [diff] [blame] | 88 | return rc; |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 89 | } |
Harald Welte | 9aad185 | 2018-10-21 11:45:26 +0200 | [diff] [blame] | 90 | |
| 91 | return 0; |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 94 | static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx) |
| 95 | { |
| 96 | HNBRegisterAccept_t accept_out; |
| 97 | struct msgb *msg; |
| 98 | int rc; |
| 99 | |
| 100 | /* Single required response IE: RNC-ID */ |
| 101 | HNBRegisterAcceptIEs_t accept = { |
| 102 | .rnc_id = ctx->gw->config.rnc_id |
| 103 | }; |
| 104 | |
| 105 | /* encode the Information Elements */ |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 106 | memset(&accept_out, 0, sizeof(accept_out)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 107 | rc = hnbap_encode_hnbregisteraccepties(&accept_out, &accept); |
| 108 | if (rc < 0) { |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 109 | LOGHNB(ctx, DHNBAP, LOGL_ERROR, "Failure to encode HNB-REGISTER-ACCEPT to %s: rc=%d\n", |
| 110 | ctx->identity_info, rc); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 111 | return rc; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 114 | /* generate a successfull outcome PDU */ |
| 115 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_HNBRegister, |
| 116 | Criticality_reject, |
| 117 | &asn_DEF_HNBRegisterAccept, |
| 118 | &accept_out); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 119 | |
Daniel Willmann | 59d17d8 | 2015-12-17 17:56:56 +0100 | [diff] [blame] | 120 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBRegisterAccept, &accept_out); |
| 121 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 122 | LOGHNB(ctx, DHNBAP, LOGL_NOTICE, "Accepting HNB-REGISTER-REQ from %s\n", ctx->identity_info); |
Neels Hofmeyr | 39d7b5c | 2019-03-04 22:37:59 +0100 | [diff] [blame] | 123 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 124 | return hnbgw_hnbap_tx(ctx, msg); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 128 | static int hnbgw_tx_ue_register_acc(struct ue_context *ue) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 129 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 130 | UERegisterAccept_t accept_out; |
| 131 | UERegisterAcceptIEs_t accept; |
| 132 | struct msgb *msg; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 133 | uint8_t encoded_imsi[10]; |
Daniel Willmann | 9224731 | 2015-12-09 19:04:33 +0100 | [diff] [blame] | 134 | uint32_t ctx_id; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 135 | size_t encoded_imsi_len; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 136 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 137 | |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 138 | encoded_imsi_len = ranap_imsi_encode(encoded_imsi, |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 139 | sizeof(encoded_imsi), ue->imsi); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 140 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 141 | memset(&accept, 0, sizeof(accept)); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 142 | accept.uE_Identity.present = UE_Identity_PR_iMSI; |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 143 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.iMSI, |
| 144 | (const char *)encoded_imsi, encoded_imsi_len); |
Daniel Willmann | 9224731 | 2015-12-09 19:04:33 +0100 | [diff] [blame] | 145 | asn1_u24_to_bitstring(&accept.context_ID, &ctx_id, ue->context_id); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 146 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 147 | memset(&accept_out, 0, sizeof(accept_out)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 148 | rc = hnbap_encode_ueregisteraccepties(&accept_out, &accept); |
| 149 | if (rc < 0) { |
| 150 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 151 | } |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 152 | |
| 153 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_UERegister, |
| 154 | Criticality_reject, |
| 155 | &asn_DEF_UERegisterAccept, |
| 156 | &accept_out); |
Daniel Willmann | 541e429 | 2015-12-22 16:25:29 +0100 | [diff] [blame] | 157 | |
| 158 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, &accept.uE_Identity.choice.iMSI); |
| 159 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterAccept, &accept_out); |
| 160 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 161 | return hnbgw_hnbap_tx(ue->hnb, msg); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 164 | static int hnbgw_tx_ue_register_rej_tmsi(struct hnb_context *hnb, UE_Identity_t *ue_id) |
| 165 | { |
| 166 | UERegisterReject_t reject_out; |
| 167 | UERegisterRejectIEs_t reject; |
| 168 | struct msgb *msg; |
| 169 | int rc; |
| 170 | |
| 171 | memset(&reject, 0, sizeof(reject)); |
| 172 | reject.uE_Identity.present = ue_id->present; |
| 173 | |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 174 | /* Copy the identity over to the reject message */ |
| 175 | switch (ue_id->present) { |
| 176 | case UE_Identity_PR_tMSILAI: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 177 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id tMSI %d %s\n", ue_id->choice.tMSILAI.tMSI.size, |
| 178 | osmo_hexdump(ue_id->choice.tMSILAI.tMSI.buf, ue_id->choice.tMSILAI.tMSI.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 179 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 180 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id pLMNID %d %s\n", ue_id->choice.tMSILAI.lAI.pLMNID.size, |
| 181 | osmo_hexdump(ue_id->choice.tMSILAI.lAI.pLMNID.buf, ue_id->choice.tMSILAI.lAI.pLMNID.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 182 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 183 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id lAC %d %s\n", ue_id->choice.tMSILAI.lAI.lAC.size, |
| 184 | osmo_hexdump(ue_id->choice.tMSILAI.lAI.lAC.buf, ue_id->choice.tMSILAI.lAI.lAC.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 185 | |
| 186 | BIT_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.tMSI, |
| 187 | ue_id->choice.tMSILAI.tMSI.buf, |
| 188 | ue_id->choice.tMSILAI.tMSI.size * 8 |
| 189 | - ue_id->choice.tMSILAI.tMSI.bits_unused); |
| 190 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.lAI.pLMNID, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 191 | (const char *)ue_id->choice.tMSILAI.lAI.pLMNID.buf, |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 192 | ue_id->choice.tMSILAI.lAI.pLMNID.size); |
| 193 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.tMSILAI.lAI.lAC, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 194 | (const char *)ue_id->choice.tMSILAI.lAI.lAC.buf, |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 195 | ue_id->choice.tMSILAI.lAI.lAC.size); |
| 196 | break; |
| 197 | |
| 198 | case UE_Identity_PR_pTMSIRAI: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 199 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id pTMSI %d %s\n", ue_id->choice.pTMSIRAI.pTMSI.size, |
| 200 | osmo_hexdump(ue_id->choice.pTMSIRAI.pTMSI.buf, ue_id->choice.pTMSIRAI.pTMSI.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 201 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 202 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id pLMNID %d %s\n", ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size, |
| 203 | osmo_hexdump(ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.buf, ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 204 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 205 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id lAC %d %s\n", ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size, |
| 206 | osmo_hexdump(ue_id->choice.pTMSIRAI.rAI.lAI.lAC.buf, ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 207 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 208 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "REJ UE_Id rAC %d %s\n", ue_id->choice.pTMSIRAI.rAI.rAC.size, |
| 209 | osmo_hexdump(ue_id->choice.pTMSIRAI.rAI.rAC.buf, ue_id->choice.pTMSIRAI.rAI.rAC.size)); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 210 | |
| 211 | BIT_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.pTMSI, |
| 212 | ue_id->choice.pTMSIRAI.pTMSI.buf, |
| 213 | ue_id->choice.pTMSIRAI.pTMSI.size * 8 |
| 214 | - ue_id->choice.pTMSIRAI.pTMSI.bits_unused); |
| 215 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.pLMNID, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 216 | (const char *)ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.buf, |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 217 | ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size); |
| 218 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.lAC, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 219 | (const char *)ue_id->choice.pTMSIRAI.rAI.lAI.lAC.buf, |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 220 | ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size); |
| 221 | OCTET_STRING_fromBuf(&reject.uE_Identity.choice.pTMSIRAI.rAI.rAC, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 222 | (const char *)ue_id->choice.pTMSIRAI.rAI.rAC.buf, |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 223 | ue_id->choice.pTMSIRAI.rAI.rAC.size); |
| 224 | break; |
| 225 | |
| 226 | default: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 227 | LOGHNB(hnb, DHNBAP, LOGL_ERROR, "Cannot compose UE Register Reject:" |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 228 | " unsupported UE ID (present=%d)\n", ue_id->present); |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 229 | return -1; |
| 230 | } |
| 231 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 232 | LOGHNB(hnb, DHNBAP, LOGL_ERROR, "Rejecting UE Register Request: TMSI identity registration is switched off\n"); |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 233 | |
| 234 | reject.cause.present = Cause_PR_radioNetwork; |
| 235 | reject.cause.choice.radioNetwork = CauseRadioNetwork_invalid_UE_identity; |
| 236 | |
| 237 | memset(&reject_out, 0, sizeof(reject_out)); |
| 238 | rc = hnbap_encode_ueregisterrejecties(&reject_out, &reject); |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 239 | if (rc < 0) |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 240 | return rc; |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 241 | |
| 242 | msg = hnbap_generate_unsuccessful_outcome(ProcedureCode_id_UERegister, |
| 243 | Criticality_reject, |
| 244 | &asn_DEF_UERegisterReject, |
| 245 | &reject_out); |
| 246 | |
Neels Hofmeyr | c94ed09 | 2016-09-26 01:27:55 +0200 | [diff] [blame] | 247 | /* Free copied identity IEs */ |
| 248 | switch (ue_id->present) { |
| 249 | case UE_Identity_PR_tMSILAI: |
| 250 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, |
| 251 | &reject.uE_Identity.choice.tMSILAI.tMSI); |
| 252 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 253 | &reject.uE_Identity.choice.tMSILAI.lAI.pLMNID); |
| 254 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 255 | &reject.uE_Identity.choice.tMSILAI.lAI.lAC); |
| 256 | break; |
| 257 | |
| 258 | case UE_Identity_PR_pTMSIRAI: |
| 259 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, |
| 260 | &reject.uE_Identity.choice.pTMSIRAI.pTMSI); |
| 261 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 262 | &reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.pLMNID); |
| 263 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 264 | &reject.uE_Identity.choice.pTMSIRAI.rAI.lAI.lAC); |
| 265 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 266 | &reject.uE_Identity.choice.pTMSIRAI.rAI.rAC); |
| 267 | break; |
| 268 | |
| 269 | default: |
| 270 | /* should never happen after above switch() */ |
| 271 | break; |
| 272 | } |
| 273 | |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 274 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterReject, &reject_out); |
| 275 | |
| 276 | return hnbgw_hnbap_tx(hnb, msg); |
| 277 | } |
| 278 | |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 279 | static int hnbgw_tx_ue_register_acc_tmsi(struct hnb_context *hnb, UE_Identity_t *ue_id) |
| 280 | { |
| 281 | UERegisterAccept_t accept_out; |
| 282 | UERegisterAcceptIEs_t accept; |
| 283 | struct msgb *msg; |
| 284 | uint32_t ctx_id; |
| 285 | uint32_t tmsi = 0; |
| 286 | struct ue_context *ue; |
| 287 | int rc; |
| 288 | |
| 289 | memset(&accept, 0, sizeof(accept)); |
| 290 | accept.uE_Identity.present = ue_id->present; |
| 291 | |
| 292 | switch (ue_id->present) { |
| 293 | case UE_Identity_PR_tMSILAI: |
| 294 | BIT_STRING_fromBuf(&accept.uE_Identity.choice.tMSILAI.tMSI, |
| 295 | ue_id->choice.tMSILAI.tMSI.buf, |
| 296 | ue_id->choice.tMSILAI.tMSI.size * 8 |
| 297 | - ue_id->choice.tMSILAI.tMSI.bits_unused); |
| 298 | tmsi = *(uint32_t*)accept.uE_Identity.choice.tMSILAI.tMSI.buf; |
| 299 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.tMSILAI.lAI.pLMNID, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 300 | (const char *)ue_id->choice.tMSILAI.lAI.pLMNID.buf, |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 301 | ue_id->choice.tMSILAI.lAI.pLMNID.size); |
| 302 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.tMSILAI.lAI.lAC, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 303 | (const char *)ue_id->choice.tMSILAI.lAI.lAC.buf, |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 304 | ue_id->choice.tMSILAI.lAI.lAC.size); |
| 305 | break; |
| 306 | |
| 307 | case UE_Identity_PR_pTMSIRAI: |
| 308 | BIT_STRING_fromBuf(&accept.uE_Identity.choice.pTMSIRAI.pTMSI, |
| 309 | ue_id->choice.pTMSIRAI.pTMSI.buf, |
| 310 | ue_id->choice.pTMSIRAI.pTMSI.size * 8 |
| 311 | - ue_id->choice.pTMSIRAI.pTMSI.bits_unused); |
| 312 | tmsi = *(uint32_t*)accept.uE_Identity.choice.pTMSIRAI.pTMSI.buf; |
| 313 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.pTMSIRAI.rAI.lAI.pLMNID, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 314 | (const char *)ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.buf, |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 315 | ue_id->choice.pTMSIRAI.rAI.lAI.pLMNID.size); |
| 316 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.pTMSIRAI.rAI.lAI.lAC, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 317 | (const char *)ue_id->choice.pTMSIRAI.rAI.lAI.lAC.buf, |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 318 | ue_id->choice.pTMSIRAI.rAI.lAI.lAC.size); |
| 319 | OCTET_STRING_fromBuf(&accept.uE_Identity.choice.pTMSIRAI.rAI.rAC, |
Pau Espin Pedrol | a008b17 | 2020-03-20 20:29:22 +0100 | [diff] [blame] | 320 | (const char *)ue_id->choice.pTMSIRAI.rAI.rAC.buf, |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 321 | ue_id->choice.pTMSIRAI.rAI.rAC.size); |
| 322 | break; |
| 323 | |
| 324 | default: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 325 | LOGHNB(hnb, DHNBAP, LOGL_ERROR, "Unsupportedccept UE ID (present=%d)\n", ue_id->present); |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 326 | return -1; |
| 327 | } |
| 328 | |
| 329 | tmsi = ntohl(tmsi); |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 330 | LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "HNBAP register with TMSI %x\n", tmsi); |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 331 | |
| 332 | ue = ue_context_by_tmsi(hnb->gw, tmsi); |
| 333 | if (!ue) |
| 334 | ue = ue_context_alloc(hnb, NULL, tmsi); |
| 335 | |
| 336 | asn1_u24_to_bitstring(&accept.context_ID, &ctx_id, ue->context_id); |
| 337 | |
| 338 | memset(&accept_out, 0, sizeof(accept_out)); |
| 339 | rc = hnbap_encode_ueregisteraccepties(&accept_out, &accept); |
| 340 | if (rc < 0) |
| 341 | return rc; |
| 342 | |
| 343 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_UERegister, |
| 344 | Criticality_reject, |
| 345 | &asn_DEF_UERegisterAccept, |
| 346 | &accept_out); |
| 347 | |
| 348 | switch (ue_id->present) { |
| 349 | case UE_Identity_PR_tMSILAI: |
| 350 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, |
| 351 | &accept.uE_Identity.choice.tMSILAI.tMSI); |
| 352 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 353 | &accept.uE_Identity.choice.tMSILAI.lAI.pLMNID); |
| 354 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 355 | &accept.uE_Identity.choice.tMSILAI.lAI.lAC); |
| 356 | break; |
| 357 | |
| 358 | case UE_Identity_PR_pTMSIRAI: |
| 359 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, |
| 360 | &accept.uE_Identity.choice.pTMSIRAI.pTMSI); |
| 361 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 362 | &accept.uE_Identity.choice.pTMSIRAI.rAI.lAI.pLMNID); |
| 363 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 364 | &accept.uE_Identity.choice.pTMSIRAI.rAI.lAI.lAC); |
| 365 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, |
| 366 | &accept.uE_Identity.choice.pTMSIRAI.rAI.rAC); |
| 367 | break; |
| 368 | |
| 369 | default: |
| 370 | /* should never happen after above switch() */ |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterAccept, &accept_out); |
| 375 | |
| 376 | return hnbgw_hnbap_tx(hnb, msg); |
| 377 | } |
| 378 | |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 379 | static int hnbgw_rx_hnb_deregister(struct hnb_context *ctx, ANY_t *in) |
| 380 | { |
| 381 | HNBDe_RegisterIEs_t ies; |
| 382 | int rc; |
| 383 | |
| 384 | rc = hnbap_decode_hnbde_registeries(&ies, in); |
| 385 | if (rc < 0) |
| 386 | return rc; |
| 387 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 388 | LOGHNB(ctx, DHNBAP, LOGL_DEBUG, "HNB-DE-REGISTER cause=%s\n", hnbap_cause_str(&ies.cause)); |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 389 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 390 | hnbap_free_hnbde_registeries(&ies); |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 391 | hnb_context_release(ctx); |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 396 | 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] | 397 | { |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 398 | struct hnb_context *hnb; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 399 | HNBRegisterRequestIEs_t ies; |
| 400 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 401 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 402 | rc = hnbap_decode_hnbregisterrequesties(&ies, in); |
Neels Hofmeyr | 2293df0 | 2018-01-18 19:01:09 +0100 | [diff] [blame] | 403 | if (rc < 0) { |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 404 | LOGHNB(ctx, DHNBAP, LOGL_ERROR, "Failure to decode HNB-REGISTER-REQ from %s: rc=%d\n", |
| 405 | ctx->identity_info, rc); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 406 | return rc; |
Neels Hofmeyr | 2293df0 | 2018-01-18 19:01:09 +0100 | [diff] [blame] | 407 | } |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 408 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 409 | /* copy all identity parameters from the message to ctx */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 410 | asn1_strncpy(ctx->identity_info, &ies.hnB_Identity.hNB_Identity_Info, |
| 411 | sizeof(ctx->identity_info)); |
| 412 | ctx->id.lac = asn1str_to_u16(&ies.lac); |
| 413 | ctx->id.sac = asn1str_to_u16(&ies.sac); |
| 414 | ctx->id.rac = asn1str_to_u8(&ies.rac); |
Daniel Willmann | d6a45b4 | 2015-12-08 13:55:17 +0100 | [diff] [blame] | 415 | ctx->id.cid = asn1bitstr_to_u28(&ies.cellIdentity); |
Neels Hofmeyr | 66d6d76 | 2017-12-20 05:25:02 +0100 | [diff] [blame] | 416 | gsm48_mcc_mnc_from_bcd(ies.plmNidentity.buf, &ctx->id.mcc, &ctx->id.mnc); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 417 | |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 418 | llist_for_each_entry(hnb, &ctx->gw->hnb_list, list) { |
| 419 | if (hnb->hnb_registered && ctx != hnb && memcmp(&ctx->id, &hnb->id, sizeof(ctx->id)) == 0) { |
| 420 | struct osmo_fd *ofd = osmo_stream_srv_get_ofd(ctx->conn); |
| 421 | char *name = osmo_sock_get_name(ctx, ofd->fd); |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 422 | LOGHNB(ctx, DHNBAP, LOGL_ERROR, "rejecting HNB-REGISTER-REQ with duplicate cell identity " |
| 423 | "MCC=%u,MNC=%u,LAC=%u,RAC=%u,SAC=%u,CID=%u from %s\n", |
| 424 | ctx->id.mcc, ctx->id.mnc, ctx->id.lac, ctx->id.rac, ctx->id.sac, ctx->id.cid, name); |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 425 | talloc_free(name); |
| 426 | return hnbgw_tx_hnb_register_rej(ctx); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | ctx->hnb_registered = true; |
| 431 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 432 | LOGHNB(ctx, DHNBAP, LOGL_DEBUG, "HNB-REGISTER-REQ from %s\n", ctx->identity_info); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 433 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 434 | /* Send HNBRegisterAccept */ |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 435 | rc = hnbgw_tx_hnb_register_acc(ctx); |
| 436 | hnbap_free_hnbregisterrequesties(&ies); |
| 437 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 440 | 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] | 441 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 442 | UERegisterRequestIEs_t ies; |
| 443 | struct ue_context *ue; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 444 | char imsi[16]; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 445 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 446 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 447 | rc = hnbap_decode_ueregisterrequesties(&ies, in); |
| 448 | if (rc < 0) |
| 449 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 450 | |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 451 | switch (ies.uE_Identity.present) { |
| 452 | case UE_Identity_PR_iMSI: |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 453 | ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 454 | ies.uE_Identity.choice.iMSI.size); |
| 455 | break; |
| 456 | case UE_Identity_PR_iMSIDS41: |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 457 | ranap_bcd_decode(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSIDS41.buf, |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 458 | ies.uE_Identity.choice.iMSIDS41.size); |
| 459 | break; |
| 460 | case UE_Identity_PR_iMSIESN: |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 461 | 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] | 462 | ies.uE_Identity.choice.iMSIESN.iMSIDS41.size); |
| 463 | break; |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 464 | case UE_Identity_PR_tMSILAI: |
| 465 | case UE_Identity_PR_pTMSIRAI: |
| 466 | if (ctx->gw->config.hnbap_allow_tmsi) |
| 467 | rc = hnbgw_tx_ue_register_acc_tmsi(ctx, &ies.uE_Identity); |
| 468 | else |
| 469 | rc = hnbgw_tx_ue_register_rej_tmsi(ctx, &ies.uE_Identity); |
| 470 | /* all has been handled by TMSI, skip the IMSI code below */ |
| 471 | hnbap_free_ueregisterrequesties(&ies); |
| 472 | return rc; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 473 | default: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 474 | LOGHNB(ctx, DHNBAP, LOGL_NOTICE, "UE-REGISTER-REQ with unsupported UE Id type %d\n", |
| 475 | ies.uE_Identity.present); |
Neels Hofmeyr | b248c8c | 2016-04-25 14:51:27 +0200 | [diff] [blame] | 476 | hnbap_free_ueregisterrequesties(&ies); |
Neels Hofmeyr | 1a0bb51 | 2016-04-25 14:55:35 +0200 | [diff] [blame] | 477 | return rc; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 478 | } |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 479 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 480 | LOGHNB(ctx, DHNBAP, LOGL_DEBUG, "UE-REGISTER-REQ ID_type=%d imsi=%s cause=%ld\n", |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 481 | ies.uE_Identity.present, imsi, ies.registration_Cause); |
| 482 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 483 | ue = ue_context_by_imsi(ctx->gw, imsi); |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 484 | if (!ue) |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 485 | ue = ue_context_alloc(ctx, imsi, 0); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 486 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 487 | hnbap_free_ueregisterrequesties(&ies); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 488 | /* Send UERegisterAccept */ |
| 489 | return hnbgw_tx_ue_register_acc(ue); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 492 | static int hnbgw_rx_ue_deregister(struct hnb_context *ctx, ANY_t *in) |
| 493 | { |
| 494 | UEDe_RegisterIEs_t ies; |
| 495 | struct ue_context *ue; |
| 496 | int rc; |
| 497 | uint32_t ctxid; |
| 498 | |
| 499 | rc = hnbap_decode_uede_registeries(&ies, in); |
| 500 | if (rc < 0) |
| 501 | return rc; |
| 502 | |
| 503 | ctxid = asn1bitstr_to_u24(&ies.context_ID); |
| 504 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 505 | LOGHNB(ctx, DHNBAP, LOGL_DEBUG, "UE-DE-REGISTER context=%u cause=%s\n", ctxid, hnbap_cause_str(&ies.cause)); |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 506 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 507 | ue = ue_context_by_id(ctx->gw, ctxid); |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 508 | if (ue) |
| 509 | ue_context_free(ue); |
| 510 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 511 | hnbap_free_uede_registeries(&ies); |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 515 | static int hnbgw_rx_err_ind(struct hnb_context *hnb, ANY_t *in) |
| 516 | { |
| 517 | ErrorIndicationIEs_t ies; |
| 518 | int rc; |
| 519 | |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 520 | rc = hnbap_decode_errorindicationies(&ies, in); |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 521 | if (rc < 0) |
| 522 | return rc; |
| 523 | |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 524 | LOGHNB(hnb, DHNBAP, LOGL_NOTICE, "HNBAP ERROR.ind, cause: %s\n", hnbap_cause_str(&ies.cause)); |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 525 | |
Daniel Willmann | d10002c | 2016-01-07 12:27:41 +0100 | [diff] [blame] | 526 | hnbap_free_errorindicationies(&ies); |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 527 | return 0; |
| 528 | } |
| 529 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 530 | 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] | 531 | { |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 532 | int rc = 0; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 533 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 534 | switch (imsg->procedureCode) { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 535 | case ProcedureCode_id_HNBRegister: /* 8.2 */ |
| 536 | rc = hnbgw_rx_hnb_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 537 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 538 | case ProcedureCode_id_HNBDe_Register: /* 8.3 */ |
Daniel Willmann | b433b97 | 2016-01-06 18:08:21 +0100 | [diff] [blame] | 539 | rc = hnbgw_rx_hnb_deregister(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 540 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 541 | case ProcedureCode_id_UERegister: /* 8.4 */ |
| 542 | rc = hnbgw_rx_ue_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 543 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 544 | case ProcedureCode_id_UEDe_Register: /* 8.5 */ |
Daniel Willmann | efceb18 | 2015-12-15 20:30:12 +0100 | [diff] [blame] | 545 | rc = hnbgw_rx_ue_deregister(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 546 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 547 | case ProcedureCode_id_ErrorIndication: /* 8.6 */ |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 548 | rc = hnbgw_rx_err_ind(hnb, &imsg->value); |
| 549 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 550 | case ProcedureCode_id_TNLUpdate: /* 8.9 */ |
| 551 | case ProcedureCode_id_HNBConfigTransfer: /* 8.10 */ |
| 552 | case ProcedureCode_id_RelocationComplete: /* 8.11 */ |
| 553 | case ProcedureCode_id_U_RNTIQuery: /* 8.12 */ |
| 554 | case ProcedureCode_id_privateMessage: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 555 | LOGHNB(hnb, DHNBAP, LOGL_NOTICE, "Unimplemented HNBAP Procedure %ld\n", imsg->procedureCode); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 556 | break; |
| 557 | default: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 558 | LOGHNB(hnb, DHNBAP, LOGL_NOTICE, "Unknown HNBAP Procedure %ld\n", imsg->procedureCode); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 559 | break; |
| 560 | } |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 561 | |
| 562 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 563 | } |
| 564 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 565 | 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] | 566 | { |
Neels Hofmeyr | 02296af | 2018-01-15 23:30:06 +0100 | [diff] [blame] | 567 | /* We don't care much about HNBAP */ |
| 568 | return 0; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 571 | 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] | 572 | { |
Neels Hofmeyr | 02296af | 2018-01-15 23:30:06 +0100 | [diff] [blame] | 573 | /* We don't care much about HNBAP */ |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 574 | LOGHNB(hnb, DHNBAP, LOGL_ERROR, "Received Unsuccessful Outcome, procedureCode %ld, criticality %ld," |
| 575 | " cell mcc %u mnc %u lac %u rac %u sac %u cid %u\n", msg->procedureCode, msg->criticality, |
| 576 | hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid); |
Neels Hofmeyr | 02296af | 2018-01-15 23:30:06 +0100 | [diff] [blame] | 577 | return 0; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 581 | 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] | 582 | { |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 583 | int rc = 0; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 584 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 585 | /* it's a bit odd that we can't dispatch on procedure code, but |
| 586 | * that's not possible */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 587 | switch (pdu->present) { |
| 588 | case HNBAP_PDU_PR_initiatingMessage: |
| 589 | rc = hnbgw_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 590 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 591 | case HNBAP_PDU_PR_successfulOutcome: |
| 592 | rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->choice.successfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 593 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 594 | case HNBAP_PDU_PR_unsuccessfulOutcome: |
| 595 | rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->choice.unsuccessfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 596 | break; |
| 597 | default: |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 598 | LOGHNB(hnb, DHNBAP, LOGL_NOTICE, "Unknown HNBAP Presence %u\n", pdu->present); |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 599 | rc = -1; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 600 | } |
Daniel Willmann | 5f810f4 | 2015-12-17 17:57:51 +0100 | [diff] [blame] | 601 | |
| 602 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 605 | int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 606 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 607 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 608 | asn_dec_rval_t dec_ret; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 609 | int rc; |
| 610 | |
| 611 | /* decode and handle to _hnbgw_hnbap_rx() */ |
| 612 | |
Harald Welte | 2204f9d | 2015-09-07 21:10:50 +0200 | [diff] [blame] | 613 | memset(pdu, 0, sizeof(*pdu)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 614 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 615 | msg->data, msgb_length(msg), 0, 0); |
| 616 | if (dec_ret.code != RC_OK) { |
Harald Welte | f05c5bf | 2020-12-30 14:17:34 +0100 | [diff] [blame] | 617 | LOGHNB(hnb, DHNBAP, LOGL_ERROR, "Error in ASN.1 decode\n"); |
Neels Hofmeyr | a6a68e6 | 2016-11-25 13:21:02 +0100 | [diff] [blame] | 618 | return -1; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | rc = _hnbgw_hnbap_rx(hnb, pdu); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 622 | |
Daniel Willmann | 59d17d8 | 2015-12-17 17:56:56 +0100 | [diff] [blame] | 623 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_PDU, pdu); |
| 624 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 625 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
| 629 | int hnbgw_hnbap_init(void) |
| 630 | { |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 631 | return 0; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 632 | } |