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