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