blob: 1e4207aec8814588699f862bd8a2e82fdf5600c2 [file] [log] [blame]
Neels Hofmeyr84da6b12016-05-20 21:59:55 +02001/* 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 Hofmeyr00e82d62017-07-05 15:19:52 +020030#include <osmocom/ranap/iu_client.h>
Philipp Maier621ba032017-11-07 17:19:25 +010031#include <osmocom/ranap/RANAP_IuTransportAssociation.h>
32#include <osmocom/ranap/iu_helpers.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020033
Neels Hofmeyr90843962017-09-04 15:04:35 +020034#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 Maier621ba032017-11-07 17:19:25 +010040#include <osmocom/msc/msc_mgcp.h>
41
42#include <asn1c/asn1helpers.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020043
44/* To continue authorization after a Security Mode Complete */
Neels Hofmeyrc036b792018-11-29 22:37:51 +010045int gsm0408_authorize(struct ran_conn *conn);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020046
Neels Hofmeyrc036b792018-11-29 22:37:51 +010047static int iucs_rx_rab_assign(struct ran_conn *conn, RANAP_RAB_SetupOrModifiedItemIEs_t * setup_ies)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020048{
49 uint8_t rab_id;
50 RANAP_RAB_SetupOrModifiedItem_t *item = &setup_ies->raB_SetupOrModifiedItem;
Philipp Maier621ba032017-11-07 17:19:25 +010051 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 Hofmeyr84da6b12016-05-20 21:59:55 +020056
57 rab_id = item->rAB_ID.buf[0];
58
59 LOGP(DIUCS, LOGL_NOTICE,
Philipp Maier621ba032017-11-07 17:19:25 +010060 "Received RAB assignment event for %s rab_id=%hhd\n", vlr_subscr_name(conn->vsub), rab_id);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020061
Philipp Maier621ba032017-11-07 17:19:25 +010062 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 Hofmeyr84da6b12016-05-20 21:59:55 +020088 return 0;
89}
90
Neels Hofmeyrc036b792018-11-29 22:37:51 +010091int iucs_rx_sec_mode_compl(struct ran_conn *conn,
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020092 RANAP_SecurityModeCompleteIEs_t *ies)
93{
Neels Hofmeyr7814a832018-12-26 00:40:18 +010094 OSMO_ASSERT(conn->via_ran == OSMO_RAT_UTRAN_IU);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020095
96 /* TODO evalute ies */
97
Neels Hofmeyr3c20a5e2018-11-30 01:08:36 +010098 ran_conn_rx_sec_mode_compl(conn);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020099 return 0;
100}
101
102int iucs_rx_ranap_event(struct gsm_network *network,
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200103 struct ranap_ue_conn_ctx *ue_ctx, int type, void *data)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200104{
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100105 struct ran_conn *conn;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200106
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100107 conn = ran_conn_lookup_iu(network, ue_ctx);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200108
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 Hofmeyr00e82d62017-07-05 15:19:52 +0200115 case RANAP_IU_EVENT_IU_RELEASE:
116 case RANAP_IU_EVENT_LINK_INVALIDATED:
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200117 LOGP(DIUCS, LOGL_INFO, "IuCS release for %s\n",
118 vlr_subscr_name(conn->vsub));
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100119 ran_conn_rx_iu_release_complete(conn);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200120 return 0;
121
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200122 case RANAP_IU_EVENT_SECURITY_MODE_COMPLETE:
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200123 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 Hofmeyr00e82d62017-07-05 15:19:52 +0200127 case RANAP_IU_EVENT_RAB_ASSIGN:
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200128 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 */