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 | |
| 57 | conn = talloc_zero(network, struct gsm_subscriber_connection); |
| 58 | if (!conn) |
| 59 | return NULL; |
| 60 | |
| 61 | conn->network = network; |
| 62 | conn->via_ran = RAN_GERAN_A; |
| 63 | conn->lac = lac; |
| 64 | |
| 65 | conn->a.conn_id = conn_id; |
| 66 | conn->a.scu = scu; |
| 67 | |
| 68 | /* Also backup the calling address of the BSC, this allows us to |
| 69 | * identify later which BSC is responsible for this subscriber connection */ |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 70 | 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] | 71 | |
| 72 | llist_add_tail(&conn->entry, &network->subscr_conns); |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 73 | LOGPCONN(conn, LOGL_DEBUG, "A-Interface subscriber connection successfully allocated!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 74 | return conn; |
| 75 | } |
| 76 | |
| 77 | /* Return an existing A subscriber connection record for the given |
| 78 | * connection IDs, or return NULL if not found. */ |
| 79 | static struct gsm_subscriber_connection *subscr_conn_lookup_a(const struct gsm_network *network, int conn_id) |
| 80 | { |
| 81 | struct gsm_subscriber_connection *conn; |
| 82 | |
| 83 | OSMO_ASSERT(network); |
| 84 | |
| 85 | DEBUGP(DMSC, "Looking for A subscriber: conn_id %i\n", conn_id); |
| 86 | |
| 87 | /* FIXME: log_subscribers() is defined in iucs.c as static inline, if |
| 88 | * maybe this function should be public to reach it from here? */ |
| 89 | /* log_subscribers(network); */ |
| 90 | |
| 91 | llist_for_each_entry(conn, &network->subscr_conns, entry) { |
| 92 | 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] | 93 | 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] | 94 | return conn; |
| 95 | } |
| 96 | } |
| 97 | DEBUGP(DMSC, "No A subscriber found for conn_id %i\n", conn_id); |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * BSSMAP handling for UNITDATA |
| 103 | */ |
| 104 | |
| 105 | /* Endpoint to handle BSSMAP reset */ |
| 106 | static void bssmap_rx_reset(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 107 | { |
| 108 | struct gsm_network *network = a_conn_info->network; |
| 109 | struct osmo_ss7_instance *ss7; |
| 110 | |
| 111 | ss7 = osmo_ss7_instance_find(network->a.cs7_instance); |
| 112 | OSMO_ASSERT(ss7); |
| 113 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 114 | 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] | 115 | osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr)); |
| 116 | osmo_sccp_tx_unitdata_msg(scu, &a_conn_info->bsc->msc_addr, &a_conn_info->bsc->bsc_addr, |
| 117 | gsm0808_create_reset_ack()); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 118 | |
| 119 | /* Make sure all orphand subscriber connections will be cleard */ |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 120 | a_clear_all(scu, &a_conn_info->bsc->bsc_addr); |
| 121 | |
| 122 | if (!a_conn_info->bsc->reset) |
| 123 | a_start_reset(a_conn_info->bsc, true); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* Endpoint to handle BSSMAP reset acknowlegement */ |
| 127 | static void bssmap_rx_reset_ack(const struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, |
| 128 | struct msgb *msg) |
| 129 | { |
| 130 | |
| 131 | struct gsm_network *network = a_conn_info->network; |
| 132 | struct osmo_ss7_instance *ss7; |
| 133 | |
| 134 | ss7 = osmo_ss7_instance_find(network->a.cs7_instance); |
| 135 | OSMO_ASSERT(ss7); |
| 136 | |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 137 | if (a_conn_info->bsc->reset == NULL) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 138 | 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] | 139 | osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr)); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 140 | return; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 143 | LOGP(DBSSAP, LOGL_NOTICE, "Received RESET ACK from BSC %s\n", |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 144 | osmo_sccp_addr_name(ss7, &a_conn_info->bsc->bsc_addr)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 145 | |
| 146 | /* Confirm that we managed to get the reset ack message |
| 147 | * towards the connection reset logic */ |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 148 | a_reset_ack_confirm(a_conn_info->bsc->reset); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* Handle UNITDATA BSSMAP messages */ |
| 152 | static void bssmap_rcvmsg_udt(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 153 | { |
| 154 | /* Note: When in the MSC role, RESET ACK is the only valid message that |
| 155 | * can be received via UNITDATA */ |
| 156 | |
| 157 | if (msgb_l3len(msg) < 1) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 158 | LOGP(DBSSAP, LOGL_NOTICE, "Error: No data received -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 162 | 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] | 163 | |
| 164 | switch (msg->l3h[0]) { |
| 165 | case BSS_MAP_MSG_RESET: |
| 166 | bssmap_rx_reset(scu, a_conn_info, msg); |
| 167 | break; |
| 168 | case BSS_MAP_MSG_RESET_ACKNOWLEDGE: |
| 169 | bssmap_rx_reset_ack(scu, a_conn_info, msg); |
| 170 | break; |
| 171 | default: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 172 | LOGP(DBSSAP, LOGL_NOTICE, "Unimplemented message format: %s -- message discarded!\n", |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 173 | gsm0808_bssmap_name(msg->l3h[0])); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | /* Receive incoming connection less data messages via sccp */ |
Neels Hofmeyr | c1d6925 | 2017-12-18 04:06:04 +0100 | [diff] [blame] | 178 | 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] | 179 | { |
| 180 | /* Note: The only valid message type that can be received |
| 181 | * via UNITDATA are BSS Management messages */ |
| 182 | struct bssmap_header *bs; |
| 183 | |
| 184 | OSMO_ASSERT(scu); |
| 185 | OSMO_ASSERT(a_conn_info); |
| 186 | OSMO_ASSERT(msg); |
| 187 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 188 | 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] | 189 | |
| 190 | if (msgb_l2len(msg) < sizeof(*bs)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 191 | LOGP(DBSSAP, LOGL_ERROR, "Error: Header is too short -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
| 195 | bs = (struct bssmap_header *)msgb_l2(msg); |
| 196 | if (bs->length < msgb_l2len(msg) - sizeof(*bs)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 197 | LOGP(DBSSAP, LOGL_ERROR, "Error: Message is too short -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 198 | return; |
| 199 | } |
| 200 | |
| 201 | switch (bs->type) { |
| 202 | case BSSAP_MSG_BSS_MANAGEMENT: |
| 203 | msg->l3h = &msg->l2h[sizeof(struct bssmap_header)]; |
| 204 | bssmap_rcvmsg_udt(scu, a_conn_info, msg); |
| 205 | break; |
| 206 | default: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 207 | LOGP(DBSSAP, LOGL_ERROR, |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 208 | "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] | 209 | } |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * BSSMAP handling for connection oriented data |
| 214 | */ |
| 215 | |
| 216 | /* Endpoint to handle BSSMAP clear request */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 217 | static int bssmap_rx_clear_rqst(struct gsm_subscriber_connection *conn, |
| 218 | struct msgb *msg, struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 219 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 220 | int rc; |
| 221 | struct msgb *msg_resp; |
| 222 | uint8_t cause; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 223 | |
Harald Welte | 3528446 | 2018-02-09 01:31:29 +0100 | [diff] [blame] | 224 | LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP CLEAR REQUEST\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 225 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 226 | if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 227 | LOGP(DBSSAP, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 228 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 229 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 230 | cause = TLVP_VAL(tp, GSM0808_IE_CAUSE)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 231 | |
| 232 | /* Respond with clear command */ |
| 233 | msg_resp = gsm0808_create_clear_command(GSM0808_CAUSE_CALL_CONTROL); |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 234 | 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] | 235 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 236 | msc_clear_request(conn, cause); |
| 237 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 238 | return rc; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* Endpoint to handle BSSMAP clear complete */ |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 242 | static int bssmap_rx_clear_complete(struct osmo_sccp_user *scu, |
| 243 | const struct a_conn_info *a_conn_info, struct msgb *msg) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 244 | { |
| 245 | int rc; |
| 246 | |
Pau Espin Pedrol | 9f055f5 | 2018-02-14 14:11:58 +0100 | [diff] [blame] | 247 | LOGP(DMSC, LOGL_INFO, "Rx BSSMAP CLEAR COMPLETE, releasing SCCP connection\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 248 | rc = osmo_sccp_tx_disconn(scu, a_conn_info->conn_id, |
Harald Welte | 54a10ef | 2018-02-09 00:09:16 +0100 | [diff] [blame] | 249 | NULL, SCCP_RELEASE_CAUSE_END_USER_ORIGINATED); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 250 | |
| 251 | /* Remove the record from the list with active connections. */ |
| 252 | a_delete_bsc_con(a_conn_info->conn_id); |
| 253 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 254 | return rc; |
| 255 | } |
| 256 | |
| 257 | /* Endpoint to handle layer 3 complete messages */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 258 | static int bssmap_rx_l3_compl(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, |
| 259 | struct msgb *msg, struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 260 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 261 | struct { |
| 262 | uint8_t ident; |
| 263 | struct gsm48_loc_area_id lai; |
| 264 | uint16_t ci; |
| 265 | } __attribute__ ((packed)) lai_ci; |
Neels Hofmeyr | 379d579 | 2018-02-22 04:04:54 +0100 | [diff] [blame] | 266 | struct osmo_location_area_id lai; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 267 | uint8_t data_length; |
| 268 | const uint8_t *data; |
| 269 | int rc; |
| 270 | |
| 271 | struct gsm_network *network = a_conn_info->network; |
| 272 | struct gsm_subscriber_connection *conn; |
| 273 | |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 274 | 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] | 275 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 276 | if (!TLVP_PRESENT(tp, GSM0808_IE_CELL_IDENTIFIER)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 277 | LOGP(DBSSAP, LOGL_ERROR, "Mandatory CELL IDENTIFIER not present -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 278 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 279 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 280 | if (!TLVP_PRESENT(tp, GSM0808_IE_LAYER_3_INFORMATION)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 281 | 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] | 282 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* Parse Cell ID element */ |
| 286 | /* FIXME: Encapsulate this in a parser/generator function inside |
| 287 | * libosmocore, add support for all specified cell identification |
| 288 | * discriminators (see 3GPP ts 3.2.2.17 Cell Identifier) */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 289 | data_length = TLVP_LEN(tp, GSM0808_IE_CELL_IDENTIFIER); |
| 290 | data = TLVP_VAL(tp, GSM0808_IE_CELL_IDENTIFIER); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 291 | if (sizeof(lai_ci) != data_length) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 292 | LOGP(DBSSAP, LOGL_ERROR, |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 293 | "Unable to parse element CELL IDENTIFIER (wrong field length) -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 294 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 295 | } |
| 296 | memcpy(&lai_ci, data, sizeof(lai_ci)); |
| 297 | if (lai_ci.ident != CELL_IDENT_WHOLE_GLOBAL) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 298 | LOGP(DBSSAP, LOGL_ERROR, |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 299 | "Unable to parse element CELL IDENTIFIER (wrong cell identification discriminator) -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 300 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 301 | } |
Neels Hofmeyr | 379d579 | 2018-02-22 04:04:54 +0100 | [diff] [blame] | 302 | gsm48_decode_lai2(&lai_ci.lai, &lai); |
| 303 | /* FIXME: Actually compare the MCC-MNC to the local network config?? */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 304 | |
| 305 | /* Parse Layer 3 Information element */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 306 | 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] | 307 | msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_INFORMATION)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 308 | |
| 309 | /* Create new subscriber context */ |
Neels Hofmeyr | 379d579 | 2018-02-22 04:04:54 +0100 | [diff] [blame] | 310 | conn = subscr_conn_allocate_a(a_conn_info, network, lai.lac, scu, a_conn_info->conn_id); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 311 | |
| 312 | /* Handover location update to the MSC code */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 313 | rc = msc_compl_l3(conn, msg, 0); |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 314 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 315 | if (rc == MSC_CONN_ACCEPT) { |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 316 | LOGP(DMSC, LOGL_INFO, "User has been accepted by MSC.\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 317 | return 0; |
| 318 | } else if (rc == MSC_CONN_REJECT) |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 319 | LOGP(DMSC, LOGL_INFO, "User has been rejected by MSC.\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 320 | else |
Harald Welte | f0dc1be | 2018-02-09 00:37:56 +0100 | [diff] [blame] | 321 | 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] | 322 | |
| 323 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* Endpoint to handle BSSMAP classmark update */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 327 | static int bssmap_rx_classmark_upd(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 328 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 329 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 330 | const uint8_t *cm2 = NULL; |
| 331 | const uint8_t *cm3 = NULL; |
| 332 | uint8_t cm2_len = 0; |
| 333 | uint8_t cm3_len = 0; |
| 334 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 335 | LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP CLASSMARK UPDATE\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 336 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 337 | if (!TLVP_PRESENT(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 338 | 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] | 339 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 342 | cm2 = TLVP_VAL(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2); |
| 343 | cm2_len = TLVP_LEN(tp, GSM0808_IE_CLASSMARK_INFORMATION_T2); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 344 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 345 | if (TLVP_PRESENT(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3)) { |
| 346 | cm3 = TLVP_VAL(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3); |
| 347 | cm3_len = TLVP_LEN(tp, GSM0808_IE_CLASSMARK_INFORMATION_T3); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* Inform MSC about the classmark change */ |
| 351 | msc_classmark_chg(conn, cm2, cm2_len, cm3, cm3_len); |
| 352 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 353 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* Endpoint to handle BSSMAP cipher mode complete */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 357 | static int bssmap_rx_ciph_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 358 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 359 | { |
| 360 | /* FIXME: The field GSM0808_IE_LAYER_3_MESSAGE_CONTENTS is optional by |
| 361 | * means of the specification. So there can be messages without L3 info. |
| 362 | * In this case, the code will crash becrause msc_cipher_mode_compl() |
| 363 | * is not able to deal with msg = NULL and apperently |
| 364 | * msc_cipher_mode_compl() was never meant to be used without L3 data. |
| 365 | * This needs to be discussed further! */ |
| 366 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 367 | uint8_t alg_id = 1; |
| 368 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 369 | LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP CIPHER MODE COMPLETE\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 370 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 371 | if (TLVP_PRESENT(tp, GSM0808_IE_CHOSEN_ENCR_ALG)) { |
| 372 | alg_id = TLVP_VAL(tp, GSM0808_IE_CHOSEN_ENCR_ALG)[0] - 1; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 375 | if (TLVP_PRESENT(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS)) { |
| 376 | 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] | 377 | msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_MESSAGE_CONTENTS)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 378 | } else { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 379 | msg = NULL; |
| 380 | } |
| 381 | |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 382 | /* Hand over cipher mode complete message to the MSC */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 383 | msc_cipher_mode_compl(conn, msg, alg_id); |
| 384 | |
| 385 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /* Endpoint to handle BSSMAP cipher mode reject */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 389 | static int bssmap_rx_ciph_rej(struct gsm_subscriber_connection *conn, |
| 390 | struct msgb *msg, struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 391 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 392 | uint8_t cause; |
| 393 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 394 | LOGPCONN(conn, LOGL_NOTICE, "RX BSSMAP CIPHER MODE REJECT\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 395 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 396 | if (!TLVP_PRESENT(tp, BSS_MAP_MSG_CIPHER_MODE_REJECT)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 397 | LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 398 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 401 | cause = TLVP_VAL(tp, BSS_MAP_MSG_CIPHER_MODE_REJECT)[0]; |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 402 | LOGPCONN(conn, LOGL_NOTICE, "Cipher mode rejection cause: %i\n", cause); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 403 | |
| 404 | /* FIXME: Can we do something meaningful here? e.g. report to the |
| 405 | * msc code somehow that the cipher mode command has failed. */ |
| 406 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 407 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* Endpoint to handle BSSMAP assignment failure */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 411 | static int bssmap_rx_ass_fail(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 412 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 413 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 414 | uint8_t cause; |
| 415 | uint8_t *rr_cause_ptr = NULL; |
| 416 | uint8_t rr_cause; |
| 417 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 418 | LOGPCONN(conn, LOGL_NOTICE, "Rx BSSMAP ASSIGNMENT FAILURE message\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 419 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 420 | if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 421 | LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 422 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 423 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 424 | cause = TLVP_VAL(tp, GSM0808_IE_CAUSE)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 425 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 426 | if (TLVP_PRESENT(tp, GSM0808_IE_RR_CAUSE)) { |
| 427 | rr_cause = TLVP_VAL(tp, GSM0808_IE_RR_CAUSE)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 428 | rr_cause_ptr = &rr_cause; |
| 429 | } |
| 430 | |
| 431 | /* FIXME: In AoIP, the Assignment failure will carry also an optional |
| 432 | * Codec List (BSS Supported) element. It has to be discussed if we |
| 433 | * can ignore this element. If not, The msc_assign_fail() function |
| 434 | * call has to change. However msc_assign_fail() does nothing in the |
| 435 | * end. So probably we can just leave it as it is. Even for AoIP */ |
| 436 | |
| 437 | /* Inform the MSC about the assignment failure event */ |
| 438 | msc_assign_fail(conn, cause, rr_cause_ptr); |
| 439 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 440 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /* Endpoint to handle sapi "n" reject */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 444 | static int bssmap_rx_sapi_n_rej(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 445 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 446 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 447 | uint8_t dlci; |
| 448 | |
Harald Welte | 3528446 | 2018-02-09 01:31:29 +0100 | [diff] [blame] | 449 | LOGPCONN(conn, LOGL_NOTICE, "Rx BSSMAP SAPI-N-REJECT message\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 450 | |
| 451 | /* Note: The MSC code seems not to care about the cause code, but by |
| 452 | * the specification it is mandatory, so we check its presence. See |
| 453 | * 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] | 454 | if (!TLVP_PRESENT(tp, GSM0808_IE_CAUSE)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 455 | LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 456 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 457 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 458 | if (!TLVP_PRESENT(tp, GSM0808_IE_DLCI)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 459 | LOGPCONN(conn, LOGL_ERROR, "DLCI is missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 460 | return -EINVAL; |
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 | dlci = TLVP_VAL(tp, GSM0808_IE_DLCI)[0]; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 463 | |
| 464 | /* Inform the MSC about the sapi "n" reject event */ |
| 465 | msc_sapi_n_reject(conn, dlci); |
| 466 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 467 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* Endpoint to handle assignment complete */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 471 | static int bssmap_rx_ass_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 472 | struct tlv_parsed *tp) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 473 | { |
Neels Hofmeyr | 6c8afe1 | 2017-09-04 01:03:58 +0200 | [diff] [blame] | 474 | struct mgcp_client *mgcp; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 475 | struct sockaddr_storage rtp_addr; |
| 476 | struct sockaddr_in *rtp_addr_in; |
| 477 | int rc; |
| 478 | |
Neels Hofmeyr | 6c8afe1 | 2017-09-04 01:03:58 +0200 | [diff] [blame] | 479 | mgcp = conn->network->mgw.client; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 480 | OSMO_ASSERT(mgcp); |
| 481 | |
Harald Welte | 3528446 | 2018-02-09 01:31:29 +0100 | [diff] [blame] | 482 | LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP ASSIGNMENT COMPLETE message\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 483 | |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 484 | if (!TLVP_PRESENT(tp, GSM0808_IE_AOIP_TRASP_ADDR)) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 485 | LOGPCONN(conn, LOGL_ERROR, "AoIP transport identifier missing -- discarding message!\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 486 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* Decode AoIP transport address element */ |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 490 | rc = gsm0808_dec_aoip_trasp_addr(&rtp_addr, TLVP_VAL(tp, GSM0808_IE_AOIP_TRASP_ADDR), |
| 491 | TLVP_LEN(tp, GSM0808_IE_AOIP_TRASP_ADDR)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 492 | if (rc < 0) { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 493 | LOGPCONN(conn, LOGL_ERROR, "Unable to decode aoip transport address.\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 494 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* use address / port supplied with the AoIP |
| 498 | * transport address element */ |
| 499 | if (rtp_addr.ss_family == AF_INET) { |
| 500 | rtp_addr_in = (struct sockaddr_in *)&rtp_addr; |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 501 | 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] | 502 | } else { |
Harald Welte | 6de4659 | 2018-02-09 00:53:17 +0100 | [diff] [blame] | 503 | LOGPCONN(conn, LOGL_ERROR, "Unsopported addressing scheme. (supports only IPV4)\n"); |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 504 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* FIXME: Seems to be related to authentication or, |
| 508 | encryption. Is this really in the right place? */ |
| 509 | msc_rx_sec_mode_compl(conn); |
| 510 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 511 | return 0; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /* Handle incoming connection oriented BSSMAP messages */ |
| 515 | static int rx_bssmap(struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 516 | { |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 517 | struct gsm_subscriber_connection *conn; |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 518 | struct tlv_parsed tp; |
Pau Espin Pedrol | 7555928 | 2018-02-14 14:12:24 +0100 | [diff] [blame] | 519 | int rc; |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 520 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 521 | if (msgb_l3len(msg) < 1) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 522 | LOGP(DBSSAP, LOGL_NOTICE, "Error: No data received -- discarding message!\n"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 523 | return -1; |
| 524 | } |
| 525 | |
Pau Espin Pedrol | 7555928 | 2018-02-14 14:12:24 +0100 | [diff] [blame] | 526 | rc = tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 1, msgb_l3len(msg) - 1, 0, 0); |
| 527 | if (rc < 0) { |
| 528 | LOGP(DBSSAP, LOGL_ERROR, "Failed parsing TLV -- discarding message! %s\n", |
| 529 | osmo_hexdump(msg->l3h, msgb_l3len(msg))); |
| 530 | return -EINVAL; |
| 531 | } |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 532 | |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 533 | /* Only message types allowed without a 'conn' */ |
| 534 | switch (msg->l3h[0]) { |
| 535 | case BSS_MAP_MSG_COMPLETE_LAYER_3: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 536 | return bssmap_rx_l3_compl(scu, a_conn_info, msg, &tp); |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 537 | case BSS_MAP_MSG_CLEAR_COMPLETE: |
| 538 | return bssmap_rx_clear_complete(scu, a_conn_info, msg); |
| 539 | default: |
| 540 | break; |
| 541 | } |
| 542 | |
| 543 | conn = subscr_conn_lookup_a(a_conn_info->network, a_conn_info->conn_id); |
| 544 | if (!conn) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 545 | 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] | 546 | return -EINVAL; |
| 547 | } |
| 548 | |
| 549 | LOGPCONN(conn, LOGL_DEBUG, "Rx BSSMAP DT1 %s\n", gsm0808_bssmap_name(msg->l3h[0])); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 550 | |
| 551 | switch (msg->l3h[0]) { |
| 552 | case BSS_MAP_MSG_CLEAR_RQST: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 553 | return bssmap_rx_clear_rqst(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 554 | case BSS_MAP_MSG_CLASSMARK_UPDATE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 555 | return bssmap_rx_classmark_upd(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 556 | case BSS_MAP_MSG_CIPHER_MODE_COMPLETE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 557 | return bssmap_rx_ciph_compl(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 558 | case BSS_MAP_MSG_CIPHER_MODE_REJECT: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 559 | return bssmap_rx_ciph_rej(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 560 | case BSS_MAP_MSG_ASSIGMENT_FAILURE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 561 | return bssmap_rx_ass_fail(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 562 | case BSS_MAP_MSG_SAPI_N_REJECT: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 563 | return bssmap_rx_sapi_n_rej(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 564 | case BSS_MAP_MSG_ASSIGMENT_COMPLETE: |
Pau Espin Pedrol | 31776ff | 2018-02-14 12:13:35 +0100 | [diff] [blame] | 565 | return bssmap_rx_ass_compl(conn, msg, &tp); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 566 | default: |
Harald Welte | c27ef65 | 2018-02-09 01:23:25 +0100 | [diff] [blame] | 567 | LOGPCONN(conn, LOGL_ERROR, "Unimplemented msg type: %s\n", gsm0808_bssmap_name(msg->l3h[0])); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 568 | return -EINVAL; |
| 569 | } |
| 570 | |
| 571 | return -EINVAL; |
| 572 | } |
| 573 | |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 574 | /* 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] | 575 | static int rx_dtap(const struct osmo_sccp_user *scu, const struct a_conn_info *a_conn_info, struct msgb *msg) |
| 576 | { |
| 577 | struct gsm_network *network = a_conn_info->network; |
| 578 | struct gsm_subscriber_connection *conn; |
| 579 | |
| 580 | conn = subscr_conn_lookup_a(network, a_conn_info->conn_id); |
| 581 | if (!conn) { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 582 | return -EINVAL; |
| 583 | } |
| 584 | |
Harald Welte | fb7ba91 | 2018-02-09 01:05:27 +0100 | [diff] [blame] | 585 | LOGPCONN(conn, LOGL_DEBUG, "Rx DTAP %s\n", msgb_hexdump_l2(msg)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 586 | |
| 587 | /* msc_dtap expects the dtap payload in l3h */ |
| 588 | msg->l3h = msg->l2h + 3; |
| 589 | |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 590 | /* Forward dtap payload into the msc */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 591 | msc_dtap(conn, conn->a.conn_id, msg); |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
Harald Welte | a172e9e | 2018-02-09 21:33:24 +0100 | [diff] [blame] | 596 | /* Handle incoming connection oriented messages. No ownership of 'msg' is passed on! */ |
Neels Hofmeyr | c1d6925 | 2017-12-18 04:06:04 +0100 | [diff] [blame] | 597 | 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] | 598 | { |
| 599 | OSMO_ASSERT(scu); |
| 600 | OSMO_ASSERT(a_conn_info); |
| 601 | OSMO_ASSERT(msg); |
| 602 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 603 | if (msgb_l2len(msg) < sizeof(struct bssmap_header)) { |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 604 | LOGP(DBSSAP, LOGL_NOTICE, "The header is too short -- discarding message!\n"); |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 605 | return -EINVAL; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | switch (msg->l2h[0]) { |
| 609 | case BSSAP_MSG_BSS_MANAGEMENT: |
| 610 | msg->l3h = &msg->l2h[sizeof(struct bssmap_header)]; |
| 611 | return rx_bssmap(scu, a_conn_info, msg); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 612 | case BSSAP_MSG_DTAP: |
| 613 | return rx_dtap(scu, a_conn_info, msg); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 614 | default: |
Harald Welte | 1f47744 | 2018-02-09 01:49:01 +0100 | [diff] [blame] | 615 | 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] | 616 | return -EINVAL; |
| 617 | } |
| 618 | |
| 619 | return -EINVAL; |
| 620 | } |