Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 1 | /* hnb-gw specific code for RUA (Ranap User Adaption) */ |
| 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 | |
| 21 | |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 22 | #include <osmocom/core/msgb.h> |
| 23 | #include <osmocom/core/utils.h> |
Harald Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 24 | #include <osmocom/netif/stream.h> |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 25 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 26 | #include <osmocom/sigtran/sccp_sap.h> |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 27 | #include <osmocom/sigtran/sccp_helpers.h> |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 28 | |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 29 | #include <unistd.h> |
| 30 | #include <errno.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | #include "asn1helpers.h" |
| 34 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 35 | #include <osmocom/iuh/hnbgw.h> |
| 36 | #include <osmocom/iuh/hnbgw_ranap.h> |
Neels Hofmeyr | 8345792 | 2016-08-26 23:56:44 +0200 | [diff] [blame] | 37 | #include <osmocom/rua/rua_common.h> |
| 38 | #include <osmocom/rua/rua_ies_defs.h> |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 39 | #include <osmocom/iuh/context_map.h> |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 40 | #include <osmocom/hnbap/CN-DomainIndicator.h> |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 41 | |
Neels Hofmeyr | c361431 | 2017-07-03 14:34:38 +0200 | [diff] [blame] | 42 | static const char *cn_domain_indicator_to_str(CN_DomainIndicator_t cN_DomainIndicator) |
| 43 | { |
| 44 | switch (cN_DomainIndicator) { |
| 45 | case RUA_CN_DomainIndicator_cs_domain: |
| 46 | return "IuCS"; |
| 47 | case RUA_CN_DomainIndicator_ps_domain: |
| 48 | return "IuPS"; |
| 49 | default: |
| 50 | return "(unknown-domain)"; |
| 51 | } |
| 52 | } |
| 53 | |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 54 | static int hnbgw_rua_tx(struct hnb_context *ctx, struct msgb *msg) |
| 55 | { |
| 56 | if (!msg) |
| 57 | return -EINVAL; |
| 58 | |
Harald Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 59 | msgb_sctp_ppid(msg) = IUH_PPI_RUA; |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 60 | osmo_stream_srv_send(ctx->conn, msg); |
| 61 | |
| 62 | return 0; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 65 | int rua_tx_udt(struct hnb_context *hnb, const uint8_t *data, unsigned int len) |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 66 | { |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 67 | RUA_ConnectionlessTransfer_t out; |
| 68 | RUA_ConnectionlessTransferIEs_t ies; |
| 69 | struct msgb *msg; |
| 70 | int rc; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 71 | |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 72 | memset(&ies, 0, sizeof(ies)); |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 73 | ies.ranaP_Message.buf = (uint8_t *) data; |
| 74 | ies.ranaP_Message.size = len; |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 75 | |
| 76 | /* FIXME: msgb_free(msg)? ownership not yet clear */ |
| 77 | |
| 78 | memset(&out, 0, sizeof(out)); |
| 79 | rc = rua_encode_connectionlesstransferies(&out, &ies); |
| 80 | if (rc < 0) |
| 81 | return rc; |
| 82 | |
| 83 | msg = rua_generate_initiating_message(RUA_ProcedureCode_id_ConnectionlessTransfer, |
| 84 | RUA_Criticality_reject, |
| 85 | &asn_DEF_RUA_ConnectionlessTransfer, |
| 86 | &out); |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 87 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out); |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 88 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 89 | DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 90 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 91 | return hnbgw_rua_tx(hnb, msg); |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 94 | int rua_tx_dt(struct hnb_context *hnb, int is_ps, uint32_t context_id, |
| 95 | const uint8_t *data, unsigned int len) |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 96 | { |
| 97 | RUA_DirectTransfer_t out; |
| 98 | RUA_DirectTransferIEs_t ies; |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 99 | uint32_t ctxidbuf; |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 100 | struct msgb *msg; |
| 101 | int rc; |
| 102 | |
| 103 | memset(&ies, 0, sizeof(ies)); |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 104 | if (is_ps) |
| 105 | ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; |
| 106 | else |
| 107 | ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; |
| 108 | asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); |
| 109 | ies.ranaP_Message.buf = (uint8_t *) data; |
| 110 | ies.ranaP_Message.size = len; |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 111 | |
| 112 | /* FIXME: msgb_free(msg)? ownership not yet clear */ |
| 113 | |
| 114 | memset(&out, 0, sizeof(out)); |
| 115 | rc = rua_encode_directtransferies(&out, &ies); |
| 116 | if (rc < 0) |
| 117 | return rc; |
| 118 | |
| 119 | msg = rua_generate_initiating_message(RUA_ProcedureCode_id_DirectTransfer, |
| 120 | RUA_Criticality_reject, |
| 121 | &asn_DEF_RUA_DirectTransfer, |
| 122 | &out); |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 123 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out); |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 124 | |
Harald Welte | 5bea800 | 2015-12-26 23:40:31 +0100 | [diff] [blame] | 125 | DEBUGP(DRUA, "transmitting RUA (cn=%s) payload of %u bytes\n", |
| 126 | is_ps ? "ps" : "cs", msgb_length(msg)); |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 127 | |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 128 | return hnbgw_rua_tx(hnb, msg); |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 131 | int rua_tx_disc(struct hnb_context *hnb, int is_ps, uint32_t context_id, |
| 132 | const RUA_Cause_t *cause, const uint8_t *data, unsigned int len) |
| 133 | { |
| 134 | RUA_Disconnect_t out; |
| 135 | RUA_DisconnectIEs_t ies; |
| 136 | struct msgb *msg; |
| 137 | uint32_t ctxidbuf; |
| 138 | int rc; |
| 139 | |
| 140 | memset(&ies, 0, sizeof(ies)); |
| 141 | if (is_ps) |
| 142 | ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; |
| 143 | else |
| 144 | ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; |
| 145 | asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); |
| 146 | memcpy(&ies.cause, cause, sizeof(ies.cause)); |
| 147 | if (data && len) { |
| 148 | ies.presenceMask |= DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT; |
| 149 | ies.ranaP_Message.buf = (uint8_t *) data; |
| 150 | ies.ranaP_Message.size = len; |
| 151 | } |
| 152 | |
| 153 | /* FIXME: msgb_free(msg)? ownership not yet clear */ |
| 154 | |
| 155 | memset(&out, 0, sizeof(out)); |
| 156 | rc = rua_encode_disconnecties(&out, &ies); |
| 157 | if (rc < 0) |
| 158 | return rc; |
| 159 | |
| 160 | msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Disconnect, |
| 161 | RUA_Criticality_reject, |
| 162 | &asn_DEF_RUA_Disconnect, |
| 163 | &out); |
| 164 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out); |
| 165 | |
Harald Welte | 5bea800 | 2015-12-26 23:40:31 +0100 | [diff] [blame] | 166 | DEBUGP(DRUA, "transmitting RUA (cn=%s) payload of %u bytes\n", |
| 167 | is_ps ? "ps" : "cs", msgb_length(msg)); |
| 168 | |
Harald Welte | cd5e981 | 2015-12-23 22:14:16 +0100 | [diff] [blame] | 169 | |
| 170 | return hnbgw_rua_tx(hnb, msg); |
| 171 | } |
| 172 | |
| 173 | |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 174 | |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 175 | /* forward a RUA message to the SCCP User API to SCCP */ |
| 176 | static int rua_to_scu(struct hnb_context *hnb, |
| 177 | CN_DomainIndicator_t cN_DomainIndicator, |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 178 | enum osmo_scu_prim_type type, |
| 179 | uint32_t context_id, uint32_t cause, |
| 180 | const uint8_t *data, unsigned int len) |
| 181 | { |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 182 | struct msgb *msg; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 183 | struct osmo_scu_prim *prim; |
| 184 | struct hnbgw_context_map *map; |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 185 | struct hnbgw_cnlink *cn = hnb->gw->sccp.cnlink; |
| 186 | struct osmo_sccp_addr *remote_addr; |
| 187 | bool is_ps; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 188 | int rc; |
| 189 | |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 190 | switch (cN_DomainIndicator) { |
| 191 | case RUA_CN_DomainIndicator_cs_domain: |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 192 | remote_addr = &hnb->gw->sccp.iucs_remote_addr; |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 193 | is_ps = false; |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 194 | break; |
| 195 | case RUA_CN_DomainIndicator_ps_domain: |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 196 | remote_addr = &hnb->gw->sccp.iups_remote_addr; |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 197 | is_ps = true; |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 198 | break; |
| 199 | default: |
| 200 | LOGP(DRUA, LOGL_ERROR, "Unsupported Domain %u\n", |
| 201 | cN_DomainIndicator); |
| 202 | return -1; |
| 203 | } |
| 204 | |
Harald Welte | 4928797 | 2015-12-29 19:00:35 +0100 | [diff] [blame] | 205 | if (!cn) { |
| 206 | DEBUGP(DRUA, "CN=NULL, discarding message\n"); |
| 207 | return 0; |
| 208 | } |
| 209 | |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 210 | msg = msgb_alloc(1500, "rua_to_sccp"); |
| 211 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 212 | prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim)); |
| 213 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, type, PRIM_OP_REQUEST, msg); |
| 214 | |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 215 | map = context_map_alloc_by_hnb(hnb, context_id, is_ps, cn); |
| 216 | OSMO_ASSERT(map); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 217 | |
Neels Hofmeyr | c361431 | 2017-07-03 14:34:38 +0200 | [diff] [blame] | 218 | DEBUGP(DRUA, "rua_to_scu() %s to %s, rua_ctx_id %u scu_conn_id %u\n", |
| 219 | cn_domain_indicator_to_str(cN_DomainIndicator), |
| 220 | osmo_sccp_addr_dump(remote_addr), |
| 221 | map->rua_ctx_id, map->scu_conn_id); |
| 222 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 223 | /* add primitive header */ |
| 224 | switch (type) { |
| 225 | case OSMO_SCU_PRIM_N_CONNECT: |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 226 | prim->u.connect.called_addr = *remote_addr; |
| 227 | prim->u.connect.calling_addr = cn->gw->sccp.local_addr; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 228 | prim->u.connect.sccp_class = 2; |
| 229 | prim->u.connect.conn_id = map->scu_conn_id; |
Neels Hofmeyr | 54e6e1f | 2017-07-03 17:29:28 +0200 | [diff] [blame] | 230 | /* Two separate logs because of osmo_sccp_addr_dump(). */ |
| 231 | DEBUGP(DRUA, "RUA to SCCP N_CONNECT: called_addr:%s\n", |
| 232 | osmo_sccp_addr_dump(&prim->u.connect.called_addr)); |
| 233 | DEBUGP(DRUA, "RUA to SCCP N_CONNECT: calling_addr:%s\n", |
| 234 | osmo_sccp_addr_dump(&prim->u.connect.calling_addr)); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 235 | break; |
| 236 | case OSMO_SCU_PRIM_N_DATA: |
| 237 | prim->u.data.conn_id = map->scu_conn_id; |
| 238 | break; |
| 239 | case OSMO_SCU_PRIM_N_DISCONNECT: |
| 240 | prim->u.disconnect.conn_id = map->scu_conn_id; |
| 241 | prim->u.disconnect.cause = cause; |
| 242 | break; |
| 243 | case OSMO_SCU_PRIM_N_UNITDATA: |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 244 | prim->u.unitdata.called_addr = *remote_addr; |
| 245 | prim->u.unitdata.calling_addr = cn->gw->sccp.local_addr; |
Neels Hofmeyr | 54e6e1f | 2017-07-03 17:29:28 +0200 | [diff] [blame] | 246 | /* Two separate logs because of osmo_sccp_addr_dump(). */ |
| 247 | DEBUGP(DRUA, "RUA to SCCP N_UNITDATA: called_addr:%s\n", |
| 248 | osmo_sccp_addr_dump(&prim->u.unitdata.called_addr)); |
| 249 | DEBUGP(DRUA, "RUA to SCCP N_UNITDATA: calling_addr:%s\n", |
| 250 | osmo_sccp_addr_dump(&prim->u.unitdata.calling_addr)); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 251 | break; |
| 252 | default: |
| 253 | return -EINVAL; |
| 254 | } |
| 255 | |
| 256 | /* add optional data section, if needed */ |
| 257 | if (data && len) { |
| 258 | msg->l2h = msgb_put(msg, len); |
| 259 | memcpy(msg->l2h, data, len); |
| 260 | } |
| 261 | |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 262 | rc = osmo_sccp_user_sap_down(cn->sccp_user, &prim->oph); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 263 | |
| 264 | return rc; |
| 265 | } |
| 266 | |
| 267 | static uint32_t rua_to_scu_cause(RUA_Cause_t *in) |
| 268 | { |
| 269 | /* FIXME: Implement this! */ |
| 270 | #if 0 |
| 271 | switch (in->present) { |
| 272 | case RUA_Cause_PR_NOTHING: |
| 273 | break; |
| 274 | case RUA_Cause_PR_radioNetwork: |
| 275 | switch (in->choice.radioNetwork) { |
| 276 | case RUA_CauseRadioNetwork_normal: |
| 277 | case RUA_CauseRadioNetwork_connect_failed: |
| 278 | case RUA_CauseRadioNetwork_network_release: |
| 279 | case RUA_CauseRadioNetwork_unspecified: |
| 280 | } |
| 281 | break; |
| 282 | case RUA_Cause_PR_transport: |
| 283 | switch (in->choice.transport) { |
| 284 | case RUA_CauseTransport_transport_resource_unavailable: |
| 285 | break; |
| 286 | case RUA_CauseTransport_unspecified: |
| 287 | break; |
| 288 | } |
| 289 | break; |
| 290 | case RUA_Cause_PR_protocol: |
| 291 | switch (in->choice.protocol) { |
| 292 | case RUA_CauseProtocol_transfer_syntax_error: |
| 293 | break; |
| 294 | case RUA_CauseProtocol_abstract_syntax_error_reject: |
| 295 | break; |
| 296 | case RUA_CauseProtocol_abstract_syntax_error_ignore_and_notify: |
| 297 | break; |
| 298 | case RUA_CauseProtocol_message_not_compatible_with_receiver_state: |
| 299 | break; |
| 300 | case RUA_CauseProtocol_semantic_error: |
| 301 | break; |
| 302 | case RUA_CauseProtocol_unspecified: |
| 303 | break; |
| 304 | case RUA_CauseProtocol_abstract_syntax_error_falsely_constructed_message: |
| 305 | break; |
| 306 | } |
| 307 | break; |
| 308 | case RUA_Cause_PR_misc: |
| 309 | switch (in->choice.misc) { |
| 310 | case RUA_CauseMisc_processing_overload: |
| 311 | break; |
| 312 | case RUA_CauseMisc_hardware_failure: |
| 313 | break; |
| 314 | case RUA_CauseMisc_o_and_m_intervention: |
| 315 | break; |
| 316 | case RUA_CauseMisc_unspecified: |
| 317 | break; |
| 318 | } |
| 319 | break; |
| 320 | default: |
| 321 | break; |
| 322 | } |
| 323 | #else |
| 324 | return 0; |
| 325 | #endif |
| 326 | |
| 327 | } |
| 328 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 329 | static int rua_rx_init_connect(struct msgb *msg, ANY_t *in) |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 330 | { |
| 331 | RUA_ConnectIEs_t ies; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 332 | struct hnb_context *hnb = msg->dst; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 333 | uint32_t context_id; |
| 334 | int rc; |
| 335 | |
| 336 | rc = rua_decode_connecties(&ies, in); |
| 337 | if (rc < 0) |
| 338 | return rc; |
| 339 | |
Harald Welte | b0de906 | 2015-12-24 14:10:17 +0100 | [diff] [blame] | 340 | context_id = asn1bitstr_to_u24(&ies.context_ID); |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 341 | |
Neels Hofmeyr | c361431 | 2017-07-03 14:34:38 +0200 | [diff] [blame] | 342 | DEBUGP(DRUA, "RUA %s Connect.req(ctx=0x%x, %s)\n", |
| 343 | cn_domain_indicator_to_str(ies.cN_DomainIndicator), |
| 344 | context_id, |
| 345 | ies.establishment_Cause == RUA_Establishment_Cause_emergency_call |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 346 | ? "emergency" : "normal"); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 347 | |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 348 | rc = rua_to_scu(hnb, ies.cN_DomainIndicator, OSMO_SCU_PRIM_N_CONNECT, |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 349 | context_id, 0, ies.ranaP_Message.buf, |
| 350 | ies.ranaP_Message.size); |
| 351 | /* FIXME: what to do with the asn1c-allocated memory */ |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 352 | rua_free_connecties(&ies); |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 353 | |
| 354 | return rc; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 357 | static int rua_rx_init_disconnect(struct msgb *msg, ANY_t *in) |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 358 | { |
| 359 | RUA_DisconnectIEs_t ies; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 360 | struct hnb_context *hnb = msg->dst; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 361 | uint32_t context_id; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 362 | uint32_t scu_cause; |
| 363 | uint8_t *ranap_data = NULL; |
| 364 | unsigned int ranap_len = 0; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 365 | int rc; |
| 366 | |
| 367 | rc = rua_decode_disconnecties(&ies, in); |
| 368 | if (rc < 0) |
| 369 | return rc; |
| 370 | |
Harald Welte | b0de906 | 2015-12-24 14:10:17 +0100 | [diff] [blame] | 371 | context_id = asn1bitstr_to_u24(&ies.context_ID); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 372 | scu_cause = rua_to_scu_cause(&ies.cause); |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 373 | |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 374 | DEBUGP(DRUA, "RUA Disconnect.req(ctx=0x%x,cause=%s)\n", context_id, |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 375 | rua_cause_str(&ies.cause)); |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 376 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 377 | if (ies.presenceMask & DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT) { |
| 378 | ranap_data = ies.ranaP_Message.buf; |
| 379 | ranap_len = ies.ranaP_Message.size; |
| 380 | } |
| 381 | |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 382 | rc = rua_to_scu(hnb, ies.cN_DomainIndicator, |
| 383 | OSMO_SCU_PRIM_N_DISCONNECT, |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 384 | context_id, scu_cause, ranap_data, ranap_len); |
Neels Hofmeyr | fe87809 | 2016-11-25 13:13:31 +0100 | [diff] [blame] | 385 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 386 | /* FIXME: what to do with the asn1c-allocated memory */ |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 387 | rua_free_disconnecties(&ies); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 388 | |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 389 | return rc; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 392 | static int rua_rx_init_dt(struct msgb *msg, ANY_t *in) |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 393 | { |
| 394 | RUA_DirectTransferIEs_t ies; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 395 | struct hnb_context *hnb = msg->dst; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 396 | uint32_t context_id; |
| 397 | int rc; |
| 398 | |
| 399 | rc = rua_decode_directtransferies(&ies, in); |
| 400 | if (rc < 0) |
| 401 | return rc; |
| 402 | |
Harald Welte | b0de906 | 2015-12-24 14:10:17 +0100 | [diff] [blame] | 403 | context_id = asn1bitstr_to_u24(&ies.context_ID); |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 404 | |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 405 | DEBUGP(DRUA, "RUA Data.req(ctx=0x%x)\n", context_id); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 406 | |
Neels Hofmeyr | 12ed975 | 2017-07-03 16:33:14 +0200 | [diff] [blame] | 407 | rc = rua_to_scu(hnb, |
| 408 | ies.cN_DomainIndicator, |
| 409 | OSMO_SCU_PRIM_N_DATA, |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 410 | context_id, 0, ies.ranaP_Message.buf, |
| 411 | ies.ranaP_Message.size); |
Neels Hofmeyr | fe87809 | 2016-11-25 13:13:31 +0100 | [diff] [blame] | 412 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 413 | /* FIXME: what to do with the asn1c-allocated memory */ |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 414 | rua_free_directtransferies(&ies); |
Harald Welte | 0f0ea81 | 2015-09-11 18:58:28 +0200 | [diff] [blame] | 415 | |
| 416 | return rc; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 419 | static int rua_rx_init_udt(struct msgb *msg, ANY_t *in) |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 420 | { |
| 421 | RUA_ConnectionlessTransferIEs_t ies; |
| 422 | int rc; |
| 423 | |
| 424 | rc = rua_decode_connectionlesstransferies(&ies, in); |
| 425 | if (rc < 0) |
| 426 | return rc; |
| 427 | |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 428 | DEBUGP(DRUA, "RUA UData.req()\n"); |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 429 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 430 | /* according tot the spec, we can primarily receive Overload, |
| 431 | * Reset, Reset ACK, Error Indication, reset Resource, Reset |
| 432 | * Resurce Acknowledge as connecitonless RANAP. There are some |
| 433 | * more messages regarding Information Transfer, Direct |
| 434 | * Information Transfer and Uplink Information Trnansfer that we |
| 435 | * can ignore. In either case, it is RANAP that we need to |
| 436 | * decode... */ |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 437 | rc = hnbgw_ranap_rx(msg, ies.ranaP_Message.buf, ies.ranaP_Message.size); |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 438 | rua_free_connectionlesstransferies(&ies); |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 439 | |
| 440 | return rc; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 443 | |
| 444 | static int rua_rx_init_err_ind(struct msgb *msg, ANY_t *in) |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 445 | { |
| 446 | RUA_ErrorIndicationIEs_t ies; |
| 447 | int rc; |
| 448 | |
| 449 | rc = rua_decode_errorindicationies(&ies, in); |
| 450 | if (rc < 0) |
| 451 | return rc; |
| 452 | |
Harald Welte | 831e1ee | 2015-12-25 10:28:55 +0100 | [diff] [blame] | 453 | LOGP(DRUA, LOGL_ERROR, "RUA UData.ErrorInd(%s)\n", |
| 454 | rua_cause_str(&ies.cause)); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 455 | |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 456 | rua_free_errorindicationies(&ies); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 457 | return rc; |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 458 | } |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 459 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 460 | static int rua_rx_initiating_msg(struct msgb *msg, RUA_InitiatingMessage_t *imsg) |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 461 | { |
| 462 | int rc; |
| 463 | |
| 464 | switch (imsg->procedureCode) { |
| 465 | case RUA_ProcedureCode_id_Connect: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 466 | rc = rua_rx_init_connect(msg, &imsg->value); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 467 | break; |
| 468 | case RUA_ProcedureCode_id_DirectTransfer: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 469 | rc = rua_rx_init_dt(msg, &imsg->value); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 470 | break; |
| 471 | case RUA_ProcedureCode_id_Disconnect: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 472 | rc = rua_rx_init_disconnect(msg, &imsg->value); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 473 | break; |
| 474 | case RUA_ProcedureCode_id_ConnectionlessTransfer: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 475 | rc = rua_rx_init_udt(msg, &imsg->value); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 476 | break; |
| 477 | case RUA_ProcedureCode_id_ErrorIndication: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 478 | rc = rua_rx_init_err_ind(msg, &imsg->value); |
Harald Welte | 64b4ebe | 2015-09-10 19:29:59 +0200 | [diff] [blame] | 479 | break; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 480 | case RUA_ProcedureCode_id_privateMessage: |
Neels Hofmeyr | 2b5021f | 2016-11-25 13:25:38 +0100 | [diff] [blame] | 481 | LOGP(DRUA, LOGL_NOTICE, |
| 482 | "Unhandled: RUA Initiating Msg: Private Msg\n"); |
| 483 | rc = 0; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 484 | break; |
| 485 | default: |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 486 | LOGP(DRUA, LOGL_NOTICE, "Unknown RUA Procedure %lu\n", |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 487 | imsg->procedureCode); |
| 488 | rc = -1; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 489 | } |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 490 | |
| 491 | return rc; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 492 | } |
| 493 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 494 | static int rua_rx_successful_outcome_msg(struct msgb *msg, RUA_SuccessfulOutcome_t *in) |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 495 | { |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 496 | /* FIXME */ |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 497 | LOGP(DRUA, LOGL_NOTICE, "Unexpected RUA Sucessful Outcome\n"); |
| 498 | return -1; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 499 | } |
| 500 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 501 | static int rua_rx_unsuccessful_outcome_msg(struct msgb *msg, RUA_UnsuccessfulOutcome_t *in) |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 502 | { |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 503 | /* FIXME */ |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 504 | LOGP(DRUA, LOGL_NOTICE, "Unexpected RUA Unsucessful Outcome\n"); |
| 505 | return -1; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 509 | static int _hnbgw_rua_rx(struct msgb *msg, RUA_RUA_PDU_t *pdu) |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 510 | { |
| 511 | int rc; |
| 512 | |
| 513 | /* it's a bit odd that we can't dispatch on procedure code, but |
| 514 | * that's not possible */ |
| 515 | switch (pdu->present) { |
| 516 | case RUA_RUA_PDU_PR_initiatingMessage: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 517 | rc = rua_rx_initiating_msg(msg, &pdu->choice.initiatingMessage); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 518 | break; |
| 519 | case RUA_RUA_PDU_PR_successfulOutcome: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 520 | rc = rua_rx_successful_outcome_msg(msg, &pdu->choice.successfulOutcome); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 521 | break; |
| 522 | case RUA_RUA_PDU_PR_unsuccessfulOutcome: |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 523 | rc = rua_rx_unsuccessful_outcome_msg(msg, &pdu->choice.unsuccessfulOutcome); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 524 | break; |
| 525 | default: |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 526 | LOGP(DRUA, LOGL_NOTICE, "Unknown RUA presence %u\n", pdu->present); |
| 527 | rc = -1; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 528 | } |
Harald Welte | 37166a2 | 2015-12-24 10:12:09 +0100 | [diff] [blame] | 529 | |
| 530 | return rc; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | int hnbgw_rua_rx(struct hnb_context *hnb, struct msgb *msg) |
| 534 | { |
| 535 | RUA_RUA_PDU_t _pdu, *pdu = &_pdu; |
| 536 | asn_dec_rval_t dec_ret; |
| 537 | int rc; |
| 538 | |
| 539 | /* decode and handle to _hnbgw_hnbap_rx() */ |
| 540 | |
| 541 | memset(pdu, 0, sizeof(*pdu)); |
| 542 | dec_ret = aper_decode(NULL, &asn_DEF_RUA_RUA_PDU, (void **) &pdu, |
| 543 | msg->data, msgb_length(msg), 0, 0); |
| 544 | if (dec_ret.code != RC_OK) { |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 545 | LOGP(DRUA, LOGL_ERROR, "Error in ASN.1 decode\n"); |
Neels Hofmeyr | a6a68e6 | 2016-11-25 13:21:02 +0100 | [diff] [blame] | 546 | return -1; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 549 | rc = _hnbgw_rua_rx(msg, pdu); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 550 | |
| 551 | return rc; |
| 552 | } |
| 553 | |
| 554 | |
| 555 | int hnbgw_rua_init(void) |
| 556 | { |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 557 | return 0; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 558 | } |