Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 1 | /* (C) 2017 by Sysmocom s.f.m.c. GmbH |
Harald Welte | c9e7859 | 2018-02-09 01:42:50 +0100 | [diff] [blame] | 2 | * (C) 2018 by Harald Welte <laforge@gnumonks.org> |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * Author: Philipp Maier |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <osmocom/core/utils.h> |
| 23 | #include <osmocom/core/msgb.h> |
| 24 | #include <osmocom/core/logging.h> |
| 25 | #include <osmocom/sigtran/sccp_helpers.h> |
| 26 | #include <osmocom/sccp/sccp_types.h> |
| 27 | #include <osmocom/gsm/gsm0808.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 28 | #include <osmocom/gsm/gsm48.h> |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 29 | #include <osmocom/gsm/gsm0808_utils.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 30 | #include <osmocom/msc/debug.h> |
| 31 | #include <osmocom/msc/gsm_data.h> |
| 32 | #include <osmocom/msc/a_iface_bssap.h> |
| 33 | #include <osmocom/msc/a_iface.h> |
| 34 | #include <osmocom/msc/osmo_msc.h> |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 35 | #include <osmocom/core/byteswap.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 36 | #include <osmocom/msc/a_reset.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 37 | #include <osmocom/msc/transaction.h> |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 38 | #include <osmocom/msc/msc_mgcp.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 39 | |
| 40 | #include <errno.h> |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 41 | |
| 42 | #define IP_V4_ADDR_LEN 4 |
| 43 | |
| 44 | /* |
| 45 | * Helper functions to lookup and allocate subscribers |
| 46 | */ |
| 47 | |
| 48 | /* Allocate a new subscriber connection */ |
| 49 | static struct gsm_subscriber_connection *subscr_conn_allocate_a(const struct a_conn_info *a_conn_info, |
| 50 | struct gsm_network *network, |
| 51 | uint16_t lac, struct osmo_sccp_user *scu, int conn_id) |
| 52 | { |
| 53 | struct gsm_subscriber_connection *conn; |
| 54 | |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 55 | LOGP(DMSC, LOGL_DEBUG, "Allocating A-Interface subscriber conn: lac %i, conn_id %i\n", lac, conn_id); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 56 | |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 57 | conn = msc_subscr_conn_alloc(network, RAN_GERAN_A, lac); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 58 | if (!conn) |
| 59 | return NULL; |
| 60 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 61 | conn->a.conn_id = conn_id; |
| 62 | conn->a.scu = scu; |
| 63 | |
| 64 | /* Also backup the calling address of the BSC, this allows us to |
| 65 | * identify later which BSC is responsible for this subscriber connection */ |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 66 | memcpy(&conn->a.bsc_addr, &a_conn_info->bsc->bsc_addr, sizeof(conn->a.bsc_addr)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 67 | |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 68 | LOGPCONN(conn, LOGL_DEBUG, "A-Interface subscriber connection successfully allocated!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 69 | return conn; |
| 70 | } |
| 71 | |
| 72 | /* Return an existing A subscriber connection record for the given |
| 73 | * connection IDs, or return NULL if not found. */ |
| 74 | static struct gsm_subscriber_connection *subscr_conn_lookup_a(const struct gsm_network *network, int conn_id) |
| 75 | { |
| 76 | struct gsm_subscriber_connection *conn; |
| 77 | |
| 78 | OSMO_ASSERT(network); |
| 79 | |
| 80 | DEBUGP(DMSC, "Looking for A subscriber: conn_id %i\n", conn_id); |
| 81 | |
| 82 | /* FIXME: log_subscribers() is defined in iucs.c as static inline, if |
| 83 | * maybe this function should be public to reach it from here? */ |
| 84 | /* log_subscribers(network); */ |
| 85 | |
| 86 | llist_for_each_entry(conn, &network->subscr_conns, entry) { |
| 87 | if (conn->via_ran == RAN_GERAN_A && conn->a.conn_id == conn_id) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 88 | LOGPCONN(conn, LOGL_DEBUG, "Found A subscriber for conn_id %i\n", conn_id); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 89 | return conn; |
| 90 | } |
| 91 | } |
| 92 | DEBUGP(DMSC, "No A subscriber found for conn_id %i\n", conn_id); |
| 93 | return NULL; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * BSSMAP handling for UNITDATA |
| 98 | */ |
| 99 | |
| 100 | /* Endpoint to handle BSSMAP reset */ |
| 101 | static void bssmap_rx_reset(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 102 | { |
| 103 | struct gsm_network *network = a_conn_info->network; |
| 104 | struct osmo_ss7_instance *ss7; |
| 105 | |
| 106 | ss7 = osmo_ss7_instance_find(network->a.cs7_instance); |
| 107 | OSMO_ASSERT(ss7); |
| 108 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 109 | LOGP(DBSSAP, LOGL_NOTICE, "Rx BSSMAP RESET from BSC %s, sending RESET ACK\n", |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 110 | osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr)); |
| 111 | osmo_sccp_tx_unitdata_msg(scu, &a_conn_info->bsc->msc_addr, &a_conn_info->bsc->bsc_addr, |
| 112 | gsm0808_create_reset_ack()); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 113 | |
| 114 | /* Make sure all orphand subscriber connections will be cleard */ |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 115 | a_clear_all(scu, &a_conn_info->bsc->bsc_addr); |
| 116 | |
| 117 | if (!a_conn_info->bsc->reset) |
| 118 | a_start_reset(a_conn_info->bsc, true); |
Harald Welte | 4de0115 | 2018-03-18 22:20:34 +0100 | [diff] [blame] | 119 | |
| 120 | /* Treat an incoming RESET like an ACK to any RESET request we may have just sent. |
| 121 | * After all, what we wanted is the A interface to be reset, which we now know has happened. */ |
| 122 | a_reset_ack_confirm(a_conn_info->bsc->reset); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* Endpoint to handle BSSMAP reset acknowlegement */ |
| 126 | static void bssmap_rx_reset_ack(const struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, |
| 127 | struct msgb *msg) |
| 128 | { |
| 129 | |
| 130 | struct gsm_network *network = a_conn_info->network; |
| 131 | struct osmo_ss7_instance *ss7; |
| 132 | |
| 133 | ss7 = osmo_ss7_instance_find(network->a.cs7_instance); |
| 134 | OSMO_ASSERT(ss7); |
| 135 | |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 136 | if (a_conn_info->bsc->reset == NULL) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 137 | LOGP(DBSSAP, LOGL_ERROR, "Received RESET ACK from an unknown BSC %s, ignoring...\n", |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 138 | osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr)); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 139 | return; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 142 | LOGP(DBSSAP, LOGL_NOTICE, "Received RESET ACK from BSC %s\n", |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 143 | osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 144 | |
| 145 | /* Confirm that we managed to get the reset ack message |
| 146 | * towards the connection reset logic */ |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 147 | a_reset_ack_confirm(a_conn_info->bsc->reset); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* Handle UNITDATA BSSMAP messages */ |
| 151 | static void bssmap_rcvmsg_udt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 152 | { |
| 153 | /* Note: When in the MSC role, RESET ACK is the only valid message that |
| 154 | * can be received via UNITDATA */ |
| 155 | |
| 156 | if (msgb_l3len(msg) < 1) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 157 | LOGP(DBSSAP, LOGL_NOTICE, "Error: No data received -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 161 | LOGP(DBSSAP, LOGL_DEBUG, "Rx BSSMAP UDT %s\n", gsm0808_bssmap_name(msg->l3h[0])); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 162 | |
| 163 | switch (msg->l3h[0]) { |
| 164 | case BSS_MAP_MSG_RESET: |
| 165 | bssmap_rx_reset(scu, a_conn_info, msg); |
| 166 | break; |
| 167 | case BSS_MAP_MSG_RESET_ACKNOWLEDGE: |
| 168 | bssmap_rx_reset_ack(scu, a_conn_info, msg); |
| 169 | break; |
| 170 | default: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 171 | LOGP(DBSSAP, LOGL_NOTICE, "Unimplemented message format: %s -- message discarded!\n", |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 172 | gsm0808_bssmap_name(msg->l3h[0])); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| 176 | /* Receive incoming connection less data messages via sccp */ |
Neels Hofmeyr | c1d6925 | 2017-12-18 04:06:04 +0100 | [diff] [blame] | 177 | void a_sccp_rx_udt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 178 | { |
| 179 | /* Note: The only valid message type that can be received |
| 180 | * via UNITDATA are BSS Management messages */ |
| 181 | struct bssmap_header *bs; |
| 182 | |
| 183 | OSMO_ASSERT(scu); |
| 184 | OSMO_ASSERT(a_conn_info); |
| 185 | OSMO_ASSERT(msg); |
| 186 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 187 | LOGP(DBSSAP, LOGL_DEBUG, "Rx BSSMAP UDT: %s\n", msgb_hexdump_l2(msg)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 188 | |
| 189 | if (msgb_l2len(msg) < sizeof(*bs)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 190 | LOGP(DBSSAP, LOGL_ERROR, "Error: Header is too short -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
| 194 | bs = (struct bssmap_header *)msgb_l2(msg); |
| 195 | if (bs->length < msgb_l2len(msg) - sizeof(*bs)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 196 | LOGP(DBSSAP, LOGL_ERROR, "Error: Message is too short -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 197 | return; |
| 198 | } |
| 199 | |
| 200 | switch (bs->type) { |
| 201 | case BSSAP_MSG_BSS_MANAGEMENT: |
| 202 | msg->l3h = &msg->l2h[sizeof(struct bssmap_header)]; |
| 203 | bssmap_rcvmsg_udt(scu, a_conn_info, msg); |
| 204 | break; |
| 205 | default: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 206 | LOGP(DBSSAP, LOGL_ERROR, |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 207 | "Error: Unimplemented message type: %s -- message discarded!\n", gsm0808_bssmap_name(bs->type)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * BSSMAP handling for connection oriented data |
| 213 | */ |
| 214 | |
| 215 | /* Endpoint to handle BSSMAP clear request */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 216 | static int bssmap_rx_clear_rqst(struct gsm_subscriber_connection *conn, |
| 217 | struct msgb *msg, struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 218 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 219 | int rc; |
| 220 | struct msgb *msg_resp; |
| 221 | uint8_t cause; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 222 | |
Harald Welte | 3528446 | 2018-02-09 01:31:29 +0100 | [diff] [blame] | 223 | LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP CLEAR REQUEST\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 224 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 225 | if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 226 | LOGP(DBSSAP, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 227 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 228 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 229 | cause = TLVP_VAL(tp, GSM0808_IE_CAUSE)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 230 | |
| 231 | /* Respond with clear command */ |
| 232 | msg_resp = gsm0808_create_clear_command(GSM0808_CAUSE_CALL_CONTROL); |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 233 | rc = osmo_sccp_tx_data_msg(conn->a.scu, conn->a.conn_id, msg_resp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 234 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 235 | msc_clear_request(conn, cause); |
| 236 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 237 | return rc; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* Endpoint to handle BSSMAP clear complete */ |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 241 | static int bssmap_rx_clear_complete(struct osmo_sccp_user *scu, |
| 242 | const struct a_conn_info *a_conn_info, struct msgb *msg) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 243 | { |
| 244 | int rc; |
| 245 | |
Pau Espin Pedrol | 9f055f5 | 2018-02-14 14:11:58 +0100 | [diff] [blame] | 246 | LOGP(DMSC, LOGL_INFO, "Rx BSSMAP CLEAR COMPLETE, releasing SCCP connection\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 247 | rc = osmo_sccp_tx_disconn(scu, a_conn_info->conn_id, |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 248 | NULL, SCCP_RELEASE_CAUSE_END_USER_ORIGINATED); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 249 | |
| 250 | /* Remove the record from the list with active connections. */ |
| 251 | a_delete_bsc_con(a_conn_info->conn_id); |
| 252 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 253 | return rc; |
| 254 | } |
| 255 | |
| 256 | /* Endpoint to handle layer 3 complete messages */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 257 | static int bssmap_rx_l3_compl(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, |
| 258 | struct msgb *msg, struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 259 | { |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 260 | struct gsm0808_cell_id_list2 cil; |
| 261 | uint16_t lac = 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 262 | uint8_t data_length; |
| 263 | const uint8_t *data; |
| 264 | int rc; |
| 265 | |
| 266 | struct gsm_network *network = a_conn_info->network; |
| 267 | struct gsm_subscriber_connection *conn; |
| 268 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 269 | LOGP(DBSSAP, LOGL_INFO, "Rx BSSMAP COMPLETE L3 INFO (conn_id=%i)\n", a_conn_info->conn_id); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 270 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 271 | if (!TLVP_PRESENT(tp, GSM0808_IE_CELL_IDENTIFIER)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 272 | LOGP(DBSSAP, LOGL_ERROR, "Mandatory CELL IDENTIFIER not present -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 273 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 274 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 275 | if (!TLVP_PRESENT(tp, GSM0808_IE_LAYER_3_INFORMATION)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 276 | LOGP(DBSSAP, LOGL_ERROR, "Mandatory LAYER 3 INFORMATION not present -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 277 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 280 | /* Parse Cell ID element -- this should yield a cell identifier "list" with 1 element. */ |
| 281 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 282 | data_length = TLVP_LEN(tp, GSM0808_IE_CELL_IDENTIFIER); |
| 283 | data = TLVP_VAL(tp, GSM0808_IE_CELL_IDENTIFIER); |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 284 | if (gsm0808_dec_cell_id_list2(&cil, data, data_length) < 0 || cil.id_list_len != 1) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 285 | LOGP(DBSSAP, LOGL_ERROR, |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 286 | "Unable to parse element CELL IDENTIFIER -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 287 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 288 | } |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 289 | |
| 290 | /* Determine the LAC which we will use for this subscriber. */ |
| 291 | switch (cil.id_discr) { |
| 292 | case CELL_IDENT_WHOLE_GLOBAL: { |
| 293 | const struct osmo_cell_global_id *id = &cil.id_list[0].global; |
| 294 | if (osmo_plmn_cmp(&id->lai.plmn, &network->plmn) != 0) { |
| 295 | LOGP(DBSSAP, LOGL_ERROR, |
| 296 | "WHOLE GLOBAL CELL IDENTIFIER does not match network MCC/MNC -- discarding message!\n"); |
| 297 | return -EINVAL; |
| 298 | } |
| 299 | lac = id->lai.lac; |
| 300 | break; |
| 301 | } |
| 302 | case CELL_IDENT_LAC_AND_CI: { |
| 303 | const struct osmo_lac_and_ci_id *id = &cil.id_list[0].lac_and_ci; |
| 304 | lac = id->lac; |
| 305 | break; |
| 306 | } |
| 307 | case CELL_IDENT_LAI_AND_LAC: { |
| 308 | const struct osmo_location_area_id *id = &cil.id_list[0].lai_and_lac; |
| 309 | if (osmo_plmn_cmp(&id->plmn, &network->plmn) != 0) { |
| 310 | LOGP(DBSSAP, LOGL_ERROR, |
| 311 | "LAI AND LAC CELL IDENTIFIER does not match network MCC/MNC -- discarding message!\n"); |
| 312 | return -EINVAL; |
| 313 | } |
| 314 | lac = id->lac; |
| 315 | break; |
| 316 | } |
| 317 | case CELL_IDENT_LAC: |
| 318 | lac = cil.id_list[0].lac; |
| 319 | break; |
| 320 | |
| 321 | case CELL_IDENT_CI: |
| 322 | case CELL_IDENT_NO_CELL: |
| 323 | case CELL_IDENT_BSS: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 324 | LOGP(DBSSAP, LOGL_ERROR, |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 325 | "CELL IDENTIFIER does not specify a LAC -- discarding message!\n"); |
| 326 | return -EINVAL; |
| 327 | |
| 328 | default: |
| 329 | LOGP(DBSSAP, LOGL_ERROR, |
| 330 | "Unable to parse element CELL IDENTIFIER (unknown cell identification discriminator 0x%x) " |
| 331 | "-- discarding message!\n", cil.id_discr); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 332 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 333 | } |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 334 | |
| 335 | /* Parse Layer 3 Information element */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 336 | msg->l3h = (uint8_t*)TLVP_VAL(tp, GSM0808_IE_LAYER_3_INFORMATION); |
Pau Espin Pedrol | 02a79d8 | 2017-12-15 18:55:43 +0100 | [diff] [blame] | 337 | msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_INFORMATION)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 338 | |
Harald Welte | 5060f56 | 2018-03-18 21:55:37 +0100 | [diff] [blame] | 339 | if (msgb_l3len(msg) < sizeof(struct gsm48_hdr)) { |
| 340 | LOGP(DBSSAP, LOGL_ERROR, "COMPL_L3 with too short L3 (%d) -- discarding\n", |
| 341 | msgb_l3len(msg)); |
| 342 | return -ENODATA; |
| 343 | } |
| 344 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 345 | /* Create new subscriber context */ |
Stefan Sperling | be7e069 | 2018-03-14 14:00:00 +0100 | [diff] [blame] | 346 | conn = subscr_conn_allocate_a(a_conn_info, network, lac, scu, a_conn_info->conn_id); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 347 | |
| 348 | /* Handover location update to the MSC code */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 349 | rc = msc_compl_l3(conn, msg, 0); |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 350 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 351 | if (rc == MSC_CONN_ACCEPT) { |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 352 | LOGP(DMSC, LOGL_INFO, "User has been accepted by MSC.\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 353 | return 0; |
| 354 | } else if (rc == MSC_CONN_REJECT) |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 355 | LOGP(DMSC, LOGL_INFO, "User has been rejected by MSC.\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 356 | else |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 357 | LOGP(DMSC, LOGL_INFO, "User has been rejected by MSC (unknown error)\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 358 | |
| 359 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /* Endpoint to handle BSSMAP classmark update */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 363 | static int bssmap_rx_classmark_upd(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 364 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 365 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 366 | const uint8_t *cm2 = NULL; |
| 367 | const uint8_t *cm3 = NULL; |
| 368 | uint8_t cm2_len = 0; |
| 369 | uint8_t cm3_len = 0; |
| 370 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 371 | LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP CLASSMARK UPDATE\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 372 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 373 | if (!TLVP_PRESENT(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 374 | LOGPCONN(conn, LOGL_ERROR, "Mandatory Classmark Information Type 2 not present -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 375 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 376 | } |
| 377 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 378 | cm2 = TLVP_VAL(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2); |
| 379 | cm2_len = TLVP_LEN(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 380 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 381 | if (TLVP_PRESENT(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3)) { |
| 382 | cm3 = TLVP_VAL(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3); |
| 383 | cm3_len = TLVP_LEN(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* Inform MSC about the classmark change */ |
| 387 | msc_classmark_chg(conn, cm2, cm2_len, cm3, cm3_len); |
| 388 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 389 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* Endpoint to handle BSSMAP cipher mode complete */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 393 | static int bssmap_rx_ciph_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 394 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 395 | { |
| 396 | /* FIXME: The field GSM0808_IE_LAYER_3_MESSAGE_CONTENTS is optional by |
| 397 | * means of the specification. So there can be messages without L3 info. |
| 398 | * In this case, the code will crash becrause msc_cipher_mode_compl() |
| 399 | * is not able to deal with msg = NULL and apperently |
| 400 | * msc_cipher_mode_compl() was never meant to be used without L3 data. |
| 401 | * This needs to be discussed further! */ |
| 402 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 403 | uint8_t alg_id = 1; |
| 404 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 405 | LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP CIPHER MODE COMPLETE\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 406 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 407 | if (TLVP_PRESENT(tp, GSM0808_IE_CHOSEN_ENCR_ALG)) { |
| 408 | alg_id = TLVP_VAL(tp, GSM0808_IE_CHOSEN_ENCR_ALG)[0] - 1; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 409 | } |
| 410 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 411 | if (TLVP_PRESENT(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS)) { |
| 412 | msg->l3h = (uint8_t*)TLVP_VAL(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS); |
Pau Espin Pedrol | 02a79d8 | 2017-12-15 18:55:43 +0100 | [diff] [blame] | 413 | msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 414 | } else { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 415 | msg = NULL; |
| 416 | } |
| 417 | |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 418 | /* Hand over cipher mode complete message to the MSC */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 419 | msc_cipher_mode_compl(conn, msg, alg_id); |
| 420 | |
| 421 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* Endpoint to handle BSSMAP cipher mode reject */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 425 | static int bssmap_rx_ciph_rej(struct gsm_subscriber_connection *conn, |
| 426 | struct msgb *msg, struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 427 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 428 | uint8_t cause; |
| 429 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 430 | LOGPCONN(conn, LOGL_NOTICE, "RX BSSMAP CIPHER MODE REJECT\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 431 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 432 | if (!TLVP_PRESENT(tp, BSS_MAP_MSG_CIPHER_MODE_REJECT)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 433 | LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 434 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 435 | } |
| 436 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 437 | cause = TLVP_VAL(tp, BSS_MAP_MSG_CIPHER_MODE_REJECT)[0]; |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 438 | LOGPCONN(conn, LOGL_NOTICE, "Cipher mode rejection cause: %i\n", cause); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 439 | |
| 440 | /* FIXME: Can we do something meaningful here? e.g. report to the |
| 441 | * msc code somehow that the cipher mode command has failed. */ |
| 442 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 443 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /* Endpoint to handle BSSMAP assignment failure */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 447 | static int bssmap_rx_ass_fail(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 448 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 449 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 450 | uint8_t cause; |
| 451 | uint8_t *rr_cause_ptr = NULL; |
| 452 | uint8_t rr_cause; |
| 453 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 454 | LOGPCONN(conn, LOGL_NOTICE, "Rx BSSMAP ASSIGNMENT FAILURE message\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 455 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 456 | if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 457 | LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 458 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 459 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 460 | cause = TLVP_VAL(tp, GSM0808_IE_CAUSE)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 461 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 462 | if (TLVP_PRESENT(tp, GSM0808_IE_RR_CAUSE)) { |
| 463 | rr_cause = TLVP_VAL(tp, GSM0808_IE_RR_CAUSE)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 464 | rr_cause_ptr = &rr_cause; |
| 465 | } |
| 466 | |
| 467 | /* FIXME: In AoIP, the Assignment failure will carry also an optional |
| 468 | * Codec List (BSS Supported) element. It has to be discussed if we |
| 469 | * can ignore this element. If not, The msc_assign_fail() function |
| 470 | * call has to change. However msc_assign_fail() does nothing in the |
| 471 | * end. So probably we can just leave it as it is. Even for AoIP */ |
| 472 | |
| 473 | /* Inform the MSC about the assignment failure event */ |
| 474 | msc_assign_fail(conn, cause, rr_cause_ptr); |
| 475 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 476 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* Endpoint to handle sapi "n" reject */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 480 | static int bssmap_rx_sapi_n_rej(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 481 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 482 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 483 | uint8_t dlci; |
| 484 | |
Harald Welte | 3528446 | 2018-02-09 01:31:29 +0100 | [diff] [blame] | 485 | LOGPCONN(conn, LOGL_NOTICE, "Rx BSSMAP SAPI-N-REJECT message\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 486 | |
| 487 | /* Note: The MSC code seems not to care about the cause code, but by |
| 488 | * the specification it is mandatory, so we check its presence. See |
| 489 | * also 3GPP TS 48.008 3.2.1.34 SAPI "n" REJECT */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 490 | if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 491 | LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 492 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 493 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 494 | if (!TLVP_PRESENT(tp, GSM0808_IE_DLCI)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 495 | LOGPCONN(conn, LOGL_ERROR, "DLCI is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 496 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 497 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 498 | dlci = TLVP_VAL(tp, GSM0808_IE_DLCI)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 499 | |
| 500 | /* Inform the MSC about the sapi "n" reject event */ |
| 501 | msc_sapi_n_reject(conn, dlci); |
| 502 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 503 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* Endpoint to handle assignment complete */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 507 | static int bssmap_rx_ass_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 508 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 509 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 510 | struct sockaddr_storage rtp_addr; |
| 511 | struct sockaddr_in *rtp_addr_in; |
| 512 | int rc; |
| 513 | |
Harald Welte | 3528446 | 2018-02-09 01:31:29 +0100 | [diff] [blame] | 514 | LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP ASSIGNMENT COMPLETE message\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 515 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 516 | if (!TLVP_PRESENT(tp, GSM0808_IE_AOIP_TRASP_ADDR)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 517 | LOGPCONN(conn, LOGL_ERROR, "AoIP transport identifier missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 518 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /* Decode AoIP transport address element */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 522 | rc = gsm0808_dec_aoip_trasp_addr(&rtp_addr, TLVP_VAL(tp, GSM0808_IE_AOIP_TRASP_ADDR), |
| 523 | TLVP_LEN(tp, GSM0808_IE_AOIP_TRASP_ADDR)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 524 | if (rc < 0) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 525 | LOGPCONN(conn, LOGL_ERROR, "Unable to decode aoip transport address.\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 526 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /* use address / port supplied with the AoIP |
| 530 | * transport address element */ |
| 531 | if (rtp_addr.ss_family == AF_INET) { |
| 532 | rtp_addr_in = (struct sockaddr_in *)&rtp_addr; |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 533 | msc_mgcp_ass_complete(conn, osmo_ntohs(rtp_addr_in->sin_port), inet_ntoa(rtp_addr_in->sin_addr)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 534 | } else { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 535 | LOGPCONN(conn, LOGL_ERROR, "Unsopported addressing scheme. (supports only IPV4)\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 536 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* FIXME: Seems to be related to authentication or, |
| 540 | encryption. Is this really in the right place? */ |
| 541 | msc_rx_sec_mode_compl(conn); |
| 542 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 543 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* Handle incoming connection oriented BSSMAP messages */ |
| 547 | static int rx_bssmap(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 548 | { |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 549 | struct gsm_subscriber_connection *conn; |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 550 | struct tlv_parsed tp; |
Pau Espin Pedrol | 7555928 | 2018-02-14 14:12:24 +0100 | [diff] [blame] | 551 | int rc; |
Neels Hofmeyr | ae73d2b | 2018-04-01 20:58:08 +0200 | [diff] [blame] | 552 | uint8_t msg_type; |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 553 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 554 | if (msgb_l3len(msg) < 1) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 555 | LOGP(DBSSAP, LOGL_NOTICE, "Error: No data received -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 556 | return -1; |
| 557 | } |
Neels Hofmeyr | ae73d2b | 2018-04-01 20:58:08 +0200 | [diff] [blame] | 558 | msg_type = msg->l3h[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 559 | |
Pau Espin Pedrol | 7555928 | 2018-02-14 14:12:24 +0100 | [diff] [blame] | 560 | rc = tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 1, msgb_l3len(msg) - 1, 0, 0); |
| 561 | if (rc < 0) { |
| 562 | LOGP(DBSSAP, LOGL_ERROR, "Failed parsing TLV -- discarding message! %s\n", |
| 563 | osmo_hexdump(msg->l3h, msgb_l3len(msg))); |
| 564 | return -EINVAL; |
| 565 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 566 | |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 567 | /* Only message types allowed without a 'conn' */ |
Neels Hofmeyr | ae73d2b | 2018-04-01 20:58:08 +0200 | [diff] [blame] | 568 | switch (msg_type) { |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 569 | case BSS_MAP_MSG_COMPLETE_LAYER_3: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 570 | return bssmap_rx_l3_compl(scu, a_conn_info, msg, &tp); |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 571 | case BSS_MAP_MSG_CLEAR_COMPLETE: |
| 572 | return bssmap_rx_clear_complete(scu, a_conn_info, msg); |
| 573 | default: |
| 574 | break; |
| 575 | } |
| 576 | |
| 577 | conn = subscr_conn_lookup_a(a_conn_info->network, a_conn_info->conn_id); |
| 578 | if (!conn) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 579 | LOGP(DBSSAP, LOGL_ERROR, "Couldn't find subscr_conn for conn_id=%d\n", a_conn_info->conn_id); |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 580 | return -EINVAL; |
| 581 | } |
| 582 | |
Neels Hofmeyr | ae73d2b | 2018-04-01 20:58:08 +0200 | [diff] [blame] | 583 | LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP DT1 %s\n", gsm0808_bssmap_name(msg_type)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 584 | |
Neels Hofmeyr | ae73d2b | 2018-04-01 20:58:08 +0200 | [diff] [blame] | 585 | switch (msg_type) { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 586 | case BSS_MAP_MSG_CLEAR_RQST: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 587 | return bssmap_rx_clear_rqst(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 588 | case BSS_MAP_MSG_CLASSMARK_UPDATE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 589 | return bssmap_rx_classmark_upd(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 590 | case BSS_MAP_MSG_CIPHER_MODE_COMPLETE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 591 | return bssmap_rx_ciph_compl(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 592 | case BSS_MAP_MSG_CIPHER_MODE_REJECT: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 593 | return bssmap_rx_ciph_rej(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 594 | case BSS_MAP_MSG_ASSIGMENT_FAILURE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 595 | return bssmap_rx_ass_fail(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 596 | case BSS_MAP_MSG_SAPI_N_REJECT: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 597 | return bssmap_rx_sapi_n_rej(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 598 | case BSS_MAP_MSG_ASSIGMENT_COMPLETE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 599 | return bssmap_rx_ass_compl(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 600 | default: |
Neels Hofmeyr | ae73d2b | 2018-04-01 20:58:08 +0200 | [diff] [blame] | 601 | LOGPCONN(conn, LOGL_ERROR, "Unimplemented msg type: %s\n", gsm0808_bssmap_name(msg_type)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 602 | return -EINVAL; |
| 603 | } |
| 604 | |
| 605 | return -EINVAL; |
| 606 | } |
| 607 | |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 608 | /* Endpoint to handle regular BSSAP DTAP messages. No ownership of 'msg' is passed on! */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 609 | static int rx_dtap(const struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 610 | { |
| 611 | struct gsm_network *network = a_conn_info->network; |
| 612 | struct gsm_subscriber_connection *conn; |
Harald Welte | 0e2fa5d | 2018-04-09 16:35:01 +0200 | [diff] [blame^] | 613 | struct dtap_header *dtap = (struct dtap_header *) msg->l2h; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 614 | |
| 615 | conn = subscr_conn_lookup_a(network, a_conn_info->conn_id); |
| 616 | if (!conn) { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 617 | return -EINVAL; |
| 618 | } |
| 619 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 620 | LOGPCONN(conn, LOGL_DEBUG, "Rx DTAP %s\n", msgb_hexdump_l2(msg)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 621 | |
| 622 | /* msc_dtap expects the dtap payload in l3h */ |
| 623 | msg->l3h = msg->l2h + 3; |
Harald Welte | 0e2fa5d | 2018-04-09 16:35:01 +0200 | [diff] [blame^] | 624 | OMSC_LINKID_CB(msg) = dtap->link_id; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 625 | |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 626 | /* Forward dtap payload into the msc */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 627 | msc_dtap(conn, conn->a.conn_id, msg); |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 632 | /* Handle incoming connection oriented messages. No ownership of 'msg' is passed on! */ |
Neels Hofmeyr | c1d6925 | 2017-12-18 04:06:04 +0100 | [diff] [blame] | 633 | int a_sccp_rx_dt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 634 | { |
| 635 | OSMO_ASSERT(scu); |
| 636 | OSMO_ASSERT(a_conn_info); |
| 637 | OSMO_ASSERT(msg); |
| 638 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 639 | if (msgb_l2len(msg) < sizeof(struct bssmap_header)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 640 | LOGP(DBSSAP, LOGL_NOTICE, "The header is too short -- discarding message!\n"); |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 641 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | switch (msg->l2h[0]) { |
| 645 | case BSSAP_MSG_BSS_MANAGEMENT: |
| 646 | msg->l3h = &msg->l2h[sizeof(struct bssmap_header)]; |
| 647 | return rx_bssmap(scu, a_conn_info, msg); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 648 | case BSSAP_MSG_DTAP: |
| 649 | return rx_dtap(scu, a_conn_info, msg); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 650 | default: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 651 | LOGP(DBSSAP, LOGL_ERROR, "Unimplemented BSSAP msg type: %s\n", gsm0808_bssap_name(msg->l2h[0])); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 652 | return -EINVAL; |
| 653 | } |
| 654 | |
| 655 | return -EINVAL; |
| 656 | } |