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> |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 40 | #include <osmocom/msc/msc_mgcp.h> |
| 41 | |
| 42 | #include <asn1c/asn1helpers.h> |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 43 | |
| 44 | /* To continue authorization after a Security Mode Complete */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 45 | int gsm0408_authorize(struct ran_conn *conn); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 46 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 47 | static int iucs_rx_rab_assign(struct ran_conn *conn, RANAP_RAB_SetupOrModifiedItemIEs_t * setup_ies) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 48 | { |
| 49 | uint8_t rab_id; |
| 50 | RANAP_RAB_SetupOrModifiedItem_t *item = &setup_ies->raB_SetupOrModifiedItem; |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 51 | RANAP_TransportLayerAddress_t *transp_layer_addr; |
| 52 | RANAP_IuTransportAssociation_t *transp_assoc; |
| 53 | uint16_t port = 0; |
| 54 | int rc; |
| 55 | char addr[INET_ADDRSTRLEN]; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 56 | |
| 57 | rab_id = item->rAB_ID.buf[0]; |
| 58 | |
| 59 | LOGP(DIUCS, LOGL_NOTICE, |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 60 | "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] | 61 | |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 62 | if (item->iuTransportAssociation && item->transportLayerAddress) { |
| 63 | transp_layer_addr = item->transportLayerAddress; |
| 64 | transp_assoc = item->iuTransportAssociation; |
| 65 | |
| 66 | rc = ranap_transp_assoc_decode(&port, transp_assoc); |
| 67 | if (rc != 0) { |
| 68 | LOGP(DIUCS, LOGL_ERROR, |
| 69 | "Unable to decode RTP port in RAB assignment (%s rab_id=%hhd)\n", |
| 70 | vlr_subscr_name(conn->vsub), rab_id); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | rc = ranap_transp_layer_addr_decode(addr, sizeof(addr), transp_layer_addr); |
| 75 | if (rc != 0) { |
| 76 | LOGP(DIUCS, LOGL_ERROR, |
| 77 | "Unable to decode IP-Address in RAB assignment (%s rab_id=%hhd)\n", |
| 78 | vlr_subscr_name(conn->vsub), rab_id); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | return msc_mgcp_ass_complete(conn, port, addr); |
| 83 | } |
| 84 | |
| 85 | LOGP(DIUCS, LOGL_ERROR, |
| 86 | "RAB assignment lacks RTP connection information. (%s rab_id=%hhd)\n", |
| 87 | vlr_subscr_name(conn->vsub), rab_id); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 91 | int iucs_rx_sec_mode_compl(struct ran_conn *conn, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 92 | RANAP_SecurityModeCompleteIEs_t *ies) |
| 93 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 94 | OSMO_ASSERT(conn->via_ran == OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 95 | |
| 96 | /* TODO evalute ies */ |
| 97 | |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 98 | ran_conn_rx_sec_mode_compl(conn); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | int iucs_rx_ranap_event(struct gsm_network *network, |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 103 | struct ranap_ue_conn_ctx *ue_ctx, int type, void *data) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 104 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 105 | struct ran_conn *conn; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 106 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 107 | conn = ran_conn_lookup_iu(network, ue_ctx); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 108 | |
| 109 | if (!conn) { |
| 110 | LOGP(DRANAP, LOGL_ERROR, "Cannot find subscriber for IU event %u\n", type); |
| 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | switch (type) { |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 115 | case RANAP_IU_EVENT_IU_RELEASE: |
| 116 | case RANAP_IU_EVENT_LINK_INVALIDATED: |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 117 | LOGP(DIUCS, LOGL_INFO, "IuCS release for %s\n", |
| 118 | vlr_subscr_name(conn->vsub)); |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 119 | ran_conn_rx_iu_release_complete(conn); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 120 | return 0; |
| 121 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 122 | case RANAP_IU_EVENT_SECURITY_MODE_COMPLETE: |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 123 | LOGP(DIUCS, LOGL_INFO, "IuCS security mode complete for %s\n", |
| 124 | vlr_subscr_name(conn->vsub)); |
| 125 | return iucs_rx_sec_mode_compl(conn, |
| 126 | (RANAP_SecurityModeCompleteIEs_t*)data); |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 127 | case RANAP_IU_EVENT_RAB_ASSIGN: |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 128 | return iucs_rx_rab_assign(conn, |
| 129 | (RANAP_RAB_SetupOrModifiedItemIEs_t*)data); |
| 130 | default: |
| 131 | LOGP(DIUCS, LOGL_NOTICE, "Unknown message received:" |
| 132 | " RANAP event: %i\n", type); |
| 133 | return -1; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | #endif /* BUILD_IU */ |