Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1 | /* Implementation of RANAP messages to/from an MSC via an Iu-CS interface. |
| 2 | * This keeps direct RANAP dependencies out of libmsc. */ |
| 3 | |
| 4 | /* (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "../../bscconfig.h" |
| 24 | |
| 25 | #ifdef BUILD_IU |
| 26 | |
| 27 | #include <osmocom/core/logging.h> |
| 28 | |
| 29 | #include <osmocom/ranap/ranap_ies_defs.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 30 | #include <osmocom/ranap/iu_client.h> |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 31 | #include <osmocom/ranap/RANAP_IuTransportAssociation.h> |
| 32 | #include <osmocom/ranap/iu_helpers.h> |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 33 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 34 | #include <osmocom/msc/debug.h> |
| 35 | #include <osmocom/msc/gsm_data.h> |
| 36 | #include <osmocom/msc/gsm_subscriber.h> |
| 37 | #include <osmocom/msc/iucs.h> |
| 38 | #include <osmocom/msc/vlr.h> |
| 39 | #include <osmocom/msc/iucs_ranap.h> |
| 40 | #include <osmocom/msc/osmo_msc.h> |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 41 | #include <osmocom/msc/msc_mgcp.h> |
| 42 | |
| 43 | #include <asn1c/asn1helpers.h> |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 44 | |
| 45 | /* To continue authorization after a Security Mode Complete */ |
| 46 | int gsm0408_authorize(struct gsm_subscriber_connection *conn); |
| 47 | |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 48 | static int iucs_rx_rab_assign(struct gsm_subscriber_connection *conn, RANAP_RAB_SetupOrModifiedItemIEs_t * setup_ies) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 49 | { |
| 50 | uint8_t rab_id; |
| 51 | RANAP_RAB_SetupOrModifiedItem_t *item = &setup_ies->raB_SetupOrModifiedItem; |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 52 | RANAP_TransportLayerAddress_t *transp_layer_addr; |
| 53 | RANAP_IuTransportAssociation_t *transp_assoc; |
| 54 | uint16_t port = 0; |
| 55 | int rc; |
| 56 | char addr[INET_ADDRSTRLEN]; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 57 | |
| 58 | rab_id = item->rAB_ID.buf[0]; |
| 59 | |
| 60 | LOGP(DIUCS, LOGL_NOTICE, |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 61 | "Received RAB assignment event for %s rab_id=%hhd\n", vlr_subscr_name(conn->vsub), rab_id); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 62 | |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 63 | if (item->iuTransportAssociation && item->transportLayerAddress) { |
| 64 | transp_layer_addr = item->transportLayerAddress; |
| 65 | transp_assoc = item->iuTransportAssociation; |
| 66 | |
| 67 | rc = ranap_transp_assoc_decode(&port, transp_assoc); |
| 68 | if (rc != 0) { |
| 69 | LOGP(DIUCS, LOGL_ERROR, |
| 70 | "Unable to decode RTP port in RAB assignment (%s rab_id=%hhd)\n", |
| 71 | vlr_subscr_name(conn->vsub), rab_id); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | rc = ranap_transp_layer_addr_decode(addr, sizeof(addr), transp_layer_addr); |
| 76 | if (rc != 0) { |
| 77 | LOGP(DIUCS, LOGL_ERROR, |
| 78 | "Unable to decode IP-Address in RAB assignment (%s rab_id=%hhd)\n", |
| 79 | vlr_subscr_name(conn->vsub), rab_id); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | return msc_mgcp_ass_complete(conn, port, addr); |
| 84 | } |
| 85 | |
| 86 | LOGP(DIUCS, LOGL_ERROR, |
| 87 | "RAB assignment lacks RTP connection information. (%s rab_id=%hhd)\n", |
| 88 | vlr_subscr_name(conn->vsub), rab_id); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | int iucs_rx_sec_mode_compl(struct gsm_subscriber_connection *conn, |
| 93 | RANAP_SecurityModeCompleteIEs_t *ies) |
| 94 | { |
| 95 | OSMO_ASSERT(conn->via_ran == RAN_UTRAN_IU); |
| 96 | |
| 97 | /* TODO evalute ies */ |
| 98 | |
| 99 | msc_rx_sec_mode_compl(conn); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | int iucs_rx_ranap_event(struct gsm_network *network, |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 104 | struct ranap_ue_conn_ctx *ue_ctx, int type, void *data) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 105 | { |
| 106 | struct gsm_subscriber_connection *conn; |
| 107 | |
| 108 | conn = subscr_conn_lookup_iu(network, ue_ctx); |
| 109 | |
| 110 | if (!conn) { |
| 111 | LOGP(DRANAP, LOGL_ERROR, "Cannot find subscriber for IU event %u\n", type); |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | switch (type) { |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 116 | case RANAP_IU_EVENT_IU_RELEASE: |
| 117 | case RANAP_IU_EVENT_LINK_INVALIDATED: |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 118 | LOGP(DIUCS, LOGL_INFO, "IuCS release for %s\n", |
| 119 | vlr_subscr_name(conn->vsub)); |
| 120 | msc_subscr_conn_close(conn, 0); |
| 121 | return 0; |
| 122 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 123 | case RANAP_IU_EVENT_SECURITY_MODE_COMPLETE: |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 124 | LOGP(DIUCS, LOGL_INFO, "IuCS security mode complete for %s\n", |
| 125 | vlr_subscr_name(conn->vsub)); |
| 126 | return iucs_rx_sec_mode_compl(conn, |
| 127 | (RANAP_SecurityModeCompleteIEs_t*)data); |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 128 | case RANAP_IU_EVENT_RAB_ASSIGN: |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 129 | return iucs_rx_rab_assign(conn, |
| 130 | (RANAP_RAB_SetupOrModifiedItemIEs_t*)data); |
| 131 | default: |
| 132 | LOGP(DIUCS, LOGL_NOTICE, "Unknown message received:" |
| 133 | " RANAP event: %i\n", type); |
| 134 | return -1; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | #endif /* BUILD_IU */ |