blob: 57cd50eeddcceabbe28b2a8b6424e7a4df30d74a [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>
40#include <osmocom/msc/osmo_msc.h>
Philipp Maier621ba032017-11-07 17:19:25 +010041#include <osmocom/msc/msc_mgcp.h>
42
43#include <asn1c/asn1helpers.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020044
45/* To continue authorization after a Security Mode Complete */
46int gsm0408_authorize(struct gsm_subscriber_connection *conn);
47
Philipp Maier621ba032017-11-07 17:19:25 +010048static int iucs_rx_rab_assign(struct gsm_subscriber_connection *conn, RANAP_RAB_SetupOrModifiedItemIEs_t * setup_ies)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020049{
50 uint8_t rab_id;
51 RANAP_RAB_SetupOrModifiedItem_t *item = &setup_ies->raB_SetupOrModifiedItem;
Philipp Maier621ba032017-11-07 17:19:25 +010052 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 Hofmeyr84da6b12016-05-20 21:59:55 +020057
58 rab_id = item->rAB_ID.buf[0];
59
60 LOGP(DIUCS, LOGL_NOTICE,
Philipp Maier621ba032017-11-07 17:19:25 +010061 "Received RAB assignment event for %s rab_id=%hhd\n", vlr_subscr_name(conn->vsub), rab_id);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020062
Philipp Maier621ba032017-11-07 17:19:25 +010063 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 Hofmeyr84da6b12016-05-20 21:59:55 +020089 return 0;
90}
91
92int 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
103int iucs_rx_ranap_event(struct gsm_network *network,
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200104 struct ranap_ue_conn_ctx *ue_ctx, int type, void *data)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200105{
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 Hofmeyr00e82d62017-07-05 15:19:52 +0200116 case RANAP_IU_EVENT_IU_RELEASE:
117 case RANAP_IU_EVENT_LINK_INVALIDATED:
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200118 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 Hofmeyr00e82d62017-07-05 15:19:52 +0200123 case RANAP_IU_EVENT_SECURITY_MODE_COMPLETE:
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200124 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 Hofmeyr00e82d62017-07-05 15:19:52 +0200128 case RANAP_IU_EVENT_RAB_ASSIGN:
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200129 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 */