Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 1 | /* (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 2 | * (C) 2009-2011 by On-Waves |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 13 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 14 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <openbsc/osmo_bsc.h> |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 21 | #include <openbsc/osmo_msc_data.h> |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 22 | #include <openbsc/debug.h> |
| 23 | |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 24 | #include <openbsc/gsm_04_80.h> |
| 25 | |
Harald Welte | d36ff76 | 2011-03-23 18:26:56 +0100 | [diff] [blame] | 26 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
| 27 | #include <osmocom/gsm/gsm0808.h> |
Holger Hans Peter Freyther | 2d2c910 | 2010-11-04 11:59:41 +0100 | [diff] [blame] | 28 | |
Holger Hans Peter Freyther | 9b9a171 | 2011-06-09 14:44:47 +0200 | [diff] [blame] | 29 | #include <osmocom/sccp/sccp.h> |
| 30 | |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 31 | #define return_when_not_connected(conn) \ |
| 32 | if (!conn->sccp_con) {\ |
| 33 | LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \ |
| 34 | return; \ |
| 35 | } |
| 36 | |
| 37 | #define return_when_not_connected_val(conn, ret) \ |
| 38 | if (!conn->sccp_con) {\ |
| 39 | LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \ |
| 40 | return ret; \ |
| 41 | } |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 42 | |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 43 | #define queue_msg_or_return(resp) \ |
| 44 | if (!resp) { \ |
| 45 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate response.\n"); \ |
| 46 | return; \ |
| 47 | } \ |
Holger Hans Peter Freyther | 863a55d | 2010-11-10 09:31:41 +0100 | [diff] [blame] | 48 | bsc_queue_for_msc(conn->sccp_con, resp); |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 49 | |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 50 | static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause); |
| 51 | static int complete_layer3(struct gsm_subscriber_connection *conn, |
| 52 | struct msgb *msg, struct osmo_msc_data *msc); |
| 53 | |
Holger Hans Peter Freyther | 4cdb050 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 54 | static uint16_t get_network_code_for_msc(struct osmo_msc_data *msc) |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 55 | { |
Holger Hans Peter Freyther | 4cdb050 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 56 | if (msc->core_ncc != -1) |
| 57 | return msc->core_ncc; |
| 58 | return msc->network->network_code; |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Holger Hans Peter Freyther | 4cdb050 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 61 | static uint16_t get_country_code_for_msc(struct osmo_msc_data *msc) |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 62 | { |
Holger Hans Peter Freyther | 4cdb050 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 63 | if (msc->core_mcc != -1) |
| 64 | return msc->core_mcc; |
| 65 | return msc->network->country_code; |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 68 | static void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
| 69 | { |
Holger Hans Peter Freyther | c8166f3 | 2010-11-04 12:28:32 +0100 | [diff] [blame] | 70 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 71 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | c8166f3 | 2010-11-04 12:28:32 +0100 | [diff] [blame] | 72 | |
Harald Welte | 7d33bdf | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 73 | LOGP(DMSC, LOGL_NOTICE, "Tx MSC SAPI N REJECT DLCI=0x%02x\n", dlci); |
| 74 | |
Holger Hans Peter Freyther | c8166f3 | 2010-11-04 12:28:32 +0100 | [diff] [blame] | 75 | resp = gsm0808_create_sapi_reject(dlci); |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 76 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, |
| 80 | struct msgb *msg, uint8_t chosen_encr) |
| 81 | { |
Holger Hans Peter Freyther | 2d2c910 | 2010-11-04 11:59:41 +0100 | [diff] [blame] | 82 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 83 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 2d2c910 | 2010-11-04 11:59:41 +0100 | [diff] [blame] | 84 | |
| 85 | LOGP(DMSC, LOGL_DEBUG, "CIPHER MODE COMPLETE from MS, forwarding to MSC\n"); |
| 86 | resp = gsm0808_create_cipher_complete(msg, chosen_encr); |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 87 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 88 | } |
| 89 | |
Holger Hans Peter Freyther | 28e183f | 2013-10-31 13:35:28 +0100 | [diff] [blame] | 90 | static void bsc_send_ussd_notification(struct gsm_subscriber_connection *conn, |
| 91 | struct msgb *msg, const char *text) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 92 | { |
| 93 | struct gsm48_hdr *gh; |
| 94 | int8_t pdisc; |
| 95 | uint8_t mtype; |
| 96 | int drop_message = 1; |
| 97 | |
| 98 | if (!text) |
| 99 | return; |
| 100 | |
| 101 | if (!msg || msgb_l3len(msg) < sizeof(*gh)) |
| 102 | return; |
| 103 | |
| 104 | gh = msgb_l3(msg); |
| 105 | pdisc = gh->proto_discr & 0x0f; |
| 106 | mtype = gh->msg_type & 0xbf; |
| 107 | |
| 108 | /* Is CM service request? */ |
| 109 | if (pdisc == GSM48_PDISC_MM && mtype == GSM48_MT_MM_CM_SERV_REQ) { |
| 110 | struct gsm48_service_request *cm; |
| 111 | |
| 112 | cm = (struct gsm48_service_request *) &gh->data[0]; |
| 113 | |
| 114 | /* Is type SMS or call? */ |
| 115 | if (cm->cm_service_type == GSM48_CMSERV_SMS) |
| 116 | drop_message = 0; |
| 117 | else if (cm->cm_service_type == GSM48_CMSERV_MO_CALL_PACKET) |
| 118 | drop_message = 0; |
| 119 | } |
| 120 | |
| 121 | if (drop_message) { |
Holger Hans Peter Freyther | 28e183f | 2013-10-31 13:35:28 +0100 | [diff] [blame] | 122 | LOGP(DMSC, LOGL_DEBUG, "Skipping (not sending) USSD message: '%s'\n", text); |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | |
| 126 | LOGP(DMSC, LOGL_INFO, "Sending USSD message: '%s'\n", text); |
| 127 | gsm0480_send_ussdNotify(conn, 1, text); |
| 128 | gsm0480_send_releaseComplete(conn); |
| 129 | } |
| 130 | |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 131 | /* |
| 132 | * Instruct to reserve data for a new connectiom, create the complete |
| 133 | * layer three message, send it to open the connection. |
| 134 | */ |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 135 | static int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 136 | uint16_t chosen_channel) |
| 137 | { |
Holger Hans Peter Freyther | 354c87c | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 138 | struct osmo_msc_data *msc; |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 139 | |
Harald Welte | 7d33bdf | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 140 | LOGP(DMSC, LOGL_INFO, "Tx MSC COMPL L3\n"); |
| 141 | |
Holger Hans Peter Freyther | 354c87c | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 142 | /* find the MSC link we want to use */ |
Holger Hans Peter Freyther | 076af1c | 2011-06-07 19:57:02 +0200 | [diff] [blame] | 143 | msc = bsc_find_msc(conn, msg); |
Holger Hans Peter Freyther | 354c87c | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 144 | if (!msc) { |
| 145 | LOGP(DMSC, LOGL_ERROR, "Failed to find a MSC for a connection.\n"); |
Holger Hans Peter Freyther | 28e183f | 2013-10-31 13:35:28 +0100 | [diff] [blame] | 146 | bsc_send_ussd_notification(conn, msg, conn->bts->network->bsc_data->ussd_no_msc_txt); |
Holger Hans Peter Freyther | 354c87c | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 147 | return -1; |
| 148 | } |
| 149 | |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 150 | return complete_layer3(conn, msg, msc); |
| 151 | } |
| 152 | |
| 153 | static int complete_layer3(struct gsm_subscriber_connection *conn, |
| 154 | struct msgb *msg, struct osmo_msc_data *msc) |
| 155 | { |
| 156 | struct msgb *resp; |
| 157 | uint16_t network_code; |
| 158 | uint16_t country_code; |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 159 | enum bsc_con ret; |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 160 | |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 161 | /* allocate resource for a new connection */ |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 162 | ret = bsc_create_new_connection(conn, msc); |
| 163 | |
| 164 | if (ret != BSC_CON_SUCCESS) { |
| 165 | /* allocation has failed */ |
| 166 | if (ret == BSC_CON_REJECT_NO_LINK) |
Holger Hans Peter Freyther | 28e183f | 2013-10-31 13:35:28 +0100 | [diff] [blame] | 167 | bsc_send_ussd_notification(conn, msg, msc->ussd_msc_lost_txt); |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 168 | else if (ret == BSC_CON_REJECT_RF_GRACE) |
Holger Hans Peter Freyther | 28e183f | 2013-10-31 13:35:28 +0100 | [diff] [blame] | 169 | bsc_send_ussd_notification(conn, msg, msc->ussd_grace_txt); |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 170 | |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 171 | return BSC_API_CONN_POL_REJECT; |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* check return value, if failed check msg for and send USSD */ |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 175 | |
Holger Hans Peter Freyther | 4cdb050 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 176 | network_code = get_network_code_for_msc(conn->sccp_con->msc); |
| 177 | country_code = get_country_code_for_msc(conn->sccp_con->msc); |
| 178 | |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 179 | bsc_scan_bts_msg(conn, msg); |
| 180 | resp = gsm0808_create_layer3(msg, network_code, country_code, |
| 181 | conn->bts->location_area_code, |
| 182 | conn->bts->cell_identity); |
| 183 | if (!resp) { |
| 184 | LOGP(DMSC, LOGL_DEBUG, "Failed to create layer3 message.\n"); |
Holger Hans Peter Freyther | 9b9a171 | 2011-06-09 14:44:47 +0200 | [diff] [blame] | 185 | sccp_connection_free(conn->sccp_con->sccp); |
Holger Hans Peter Freyther | 7e90108 | 2010-11-06 20:15:17 +0100 | [diff] [blame] | 186 | bsc_delete_connection(conn->sccp_con); |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 187 | return BSC_API_CONN_POL_REJECT; |
Holger Hans Peter Freyther | 5bb874d | 2010-11-05 11:21:18 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Holger Hans Peter Freyther | 7e90108 | 2010-11-06 20:15:17 +0100 | [diff] [blame] | 190 | if (bsc_open_connection(conn->sccp_con, resp) != 0) { |
Holger Hans Peter Freyther | 9b9a171 | 2011-06-09 14:44:47 +0200 | [diff] [blame] | 191 | sccp_connection_free(conn->sccp_con->sccp); |
Holger Hans Peter Freyther | 7e90108 | 2010-11-06 20:15:17 +0100 | [diff] [blame] | 192 | bsc_delete_connection(conn->sccp_con); |
Holger Hans Peter Freyther | 9b17c76 | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 193 | msgb_free(resp); |
| 194 | return BSC_API_CONN_POL_REJECT; |
| 195 | } |
| 196 | |
| 197 | return BSC_API_CONN_POL_ACCEPT; |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 198 | } |
| 199 | |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 200 | /* |
| 201 | * Plastic surgery... we want to give up the current connection |
| 202 | */ |
| 203 | static int move_to_msc(struct gsm_subscriber_connection *_conn, |
| 204 | struct msgb *msg, struct osmo_msc_data *msc) |
| 205 | { |
| 206 | struct osmo_bsc_sccp_con *old_con = _conn->sccp_con; |
| 207 | |
| 208 | /* |
| 209 | * 1. Give up the old connection. |
| 210 | * This happens by sending a clear request to the MSC, |
| 211 | * it should end with the MSC releasing the connection. |
| 212 | */ |
| 213 | old_con->conn = NULL; |
| 214 | bsc_clear_request(_conn, 0); |
| 215 | |
| 216 | /* |
| 217 | * 2. Attempt to create a new connection to the local |
| 218 | * MSC. If it fails the caller will need to handle this |
| 219 | * properly. |
| 220 | */ |
| 221 | _conn->sccp_con = NULL; |
| 222 | if (complete_layer3(_conn, msg, msc) != BSC_API_CONN_POL_ACCEPT) { |
| 223 | gsm0808_clear(_conn); |
| 224 | subscr_con_free(_conn); |
| 225 | return 1; |
| 226 | } |
| 227 | |
| 228 | return 2; |
| 229 | } |
| 230 | |
| 231 | static int handle_cc_setup(struct gsm_subscriber_connection *conn, |
| 232 | struct msgb *msg) |
| 233 | { |
| 234 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 235 | uint8_t pdisc = gh->proto_discr & 0x0f; |
| 236 | uint8_t mtype = gh->msg_type & 0xbf; |
| 237 | |
| 238 | struct osmo_msc_data *msc; |
| 239 | struct gsm_mncc_number called; |
| 240 | struct tlv_parsed tp; |
| 241 | unsigned payload_len; |
| 242 | |
| 243 | char _dest_nr[35]; |
| 244 | |
| 245 | /* |
| 246 | * Do we have a setup message here? if not return fast. |
| 247 | */ |
| 248 | if (pdisc != GSM48_PDISC_CC || mtype != GSM48_MT_CC_SETUP) |
| 249 | return 0; |
| 250 | |
| 251 | payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 252 | |
| 253 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 254 | if (!TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 255 | LOGP(DMSC, LOGL_ERROR, "Called BCD not present in setup.\n"); |
| 256 | return -1; |
| 257 | } |
| 258 | |
| 259 | memset(&called, 0, sizeof(called)); |
| 260 | gsm48_decode_called(&called, |
| 261 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD) - 1); |
| 262 | |
Holger Hans Peter Freyther | 0b19d55 | 2011-09-30 16:24:27 +0200 | [diff] [blame] | 263 | if (called.plan != 1 && called.plan != 0) |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 264 | return 0; |
| 265 | |
Holger Hans Peter Freyther | 0b19d55 | 2011-09-30 16:24:27 +0200 | [diff] [blame] | 266 | if (called.plan == 1 && called.type == 1) { |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 267 | _dest_nr[0] = _dest_nr[1] = '0'; |
| 268 | memcpy(_dest_nr + 2, called.number, sizeof(called.number)); |
| 269 | } else |
| 270 | memcpy(_dest_nr, called.number, sizeof(called.number)); |
| 271 | |
| 272 | /* |
| 273 | * Check if the connection should be moved... |
| 274 | */ |
| 275 | llist_for_each_entry(msc, &conn->bts->network->bsc_data->mscs, entry) { |
| 276 | if (msc->type != MSC_CON_TYPE_LOCAL) |
| 277 | continue; |
| 278 | if (!msc->local_pref) |
| 279 | continue; |
| 280 | if (regexec(&msc->local_pref_reg, _dest_nr, 0, NULL, 0) != 0) |
| 281 | continue; |
| 282 | |
| 283 | return move_to_msc(conn, msg, msc); |
| 284 | } |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 290 | static void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 291 | { |
Holger Hans Peter Freyther | 58f2cf6 | 2010-11-04 12:24:05 +0100 | [diff] [blame] | 292 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 293 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 58f2cf6 | 2010-11-04 12:24:05 +0100 | [diff] [blame] | 294 | |
Harald Welte | 7d33bdf | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 295 | LOGP(DMSC, LOGL_INFO, "Tx MSC DTAP LINK_ID=0x%02x\n", link_id); |
| 296 | |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 297 | /* |
| 298 | * We might want to move this connection to a new MSC. Ask someone |
| 299 | * to handle it. If it was handled we will return. |
| 300 | */ |
Holger Hans Peter Freyther | c7db4dc | 2011-06-27 21:29:03 +0200 | [diff] [blame] | 301 | if (handle_cc_setup(conn, msg) >= 1) |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 302 | return; |
| 303 | |
Holger Hans Peter Freyther | 5bb874d | 2010-11-05 11:21:18 +0100 | [diff] [blame] | 304 | bsc_scan_bts_msg(conn, msg); |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 305 | |
| 306 | |
Holger Hans Peter Freyther | 58f2cf6 | 2010-11-04 12:24:05 +0100 | [diff] [blame] | 307 | resp = gsm0808_create_dtap(msg, link_id); |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 308 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 309 | } |
| 310 | |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 311 | static void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause, |
| 312 | uint8_t chosen_channel, uint8_t encr_alg_id, |
| 313 | uint8_t speech_model) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 314 | { |
Holger Hans Peter Freyther | da488ae | 2010-11-04 12:09:45 +0100 | [diff] [blame] | 315 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 316 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | da488ae | 2010-11-04 12:09:45 +0100 | [diff] [blame] | 317 | |
Harald Welte | 7d33bdf | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 318 | LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN COMPL\n"); |
| 319 | |
Holger Hans Peter Freyther | da488ae | 2010-11-04 12:09:45 +0100 | [diff] [blame] | 320 | resp = gsm0808_create_assignment_completed(rr_cause, chosen_channel, |
| 321 | encr_alg_id, speech_model); |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 322 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 323 | } |
| 324 | |
Holger Hans Peter Freyther | 45b575f | 2010-11-05 10:37:17 +0100 | [diff] [blame] | 325 | static void bsc_assign_fail(struct gsm_subscriber_connection *conn, |
| 326 | uint8_t cause, uint8_t *rr_cause) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 327 | { |
Holger Hans Peter Freyther | e46f1d6 | 2010-11-05 10:59:45 +0100 | [diff] [blame] | 328 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 329 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | e46f1d6 | 2010-11-05 10:59:45 +0100 | [diff] [blame] | 330 | |
Harald Welte | 7d33bdf | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 331 | LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN FAIL\n"); |
| 332 | |
Holger Hans Peter Freyther | e46f1d6 | 2010-11-05 10:59:45 +0100 | [diff] [blame] | 333 | resp = gsm0808_create_assignment_failure(cause, rr_cause); |
Holger Hans Peter Freyther | 46c5ab3 | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 334 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 335 | } |
| 336 | |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 337 | static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 338 | { |
Holger Hans Peter Freyther | 80c37bd | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 339 | struct osmo_bsc_sccp_con *sccp; |
Holger Hans Peter Freyther | c2b3270 | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 340 | struct msgb *resp; |
Holger Hans Peter Freyther | 7225fd1 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 341 | return_when_not_connected_val(conn, 1); |
Holger Hans Peter Freyther | c2b3270 | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 342 | |
Harald Welte | 7d33bdf | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 343 | LOGP(DMSC, LOGL_INFO, "Tx MSC CLEAR REQUEST\n"); |
| 344 | |
Holger Hans Peter Freyther | 80c37bd | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 345 | /* |
| 346 | * Remove the connection from BSC<->SCCP part, the SCCP part |
| 347 | * will either be cleared by channel release or MSC disconnect |
| 348 | */ |
| 349 | sccp = conn->sccp_con; |
| 350 | sccp->conn = NULL; |
| 351 | conn->sccp_con = NULL; |
| 352 | |
Holger Hans Peter Freyther | c2b3270 | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 353 | resp = gsm0808_create_clear_rqst(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE); |
| 354 | if (!resp) { |
| 355 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate response.\n"); |
Holger Hans Peter Freyther | 80c37bd | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 356 | return 1; |
Holger Hans Peter Freyther | c2b3270 | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Holger Hans Peter Freyther | 80c37bd | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 359 | bsc_queue_for_msc(sccp, resp); |
| 360 | return 1; |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 361 | } |
| 362 | |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 363 | static void bsc_cm_update(struct gsm_subscriber_connection *conn, |
| 364 | const uint8_t *cm2, uint8_t cm2_len, |
| 365 | const uint8_t *cm3, uint8_t cm3_len) |
| 366 | { |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 367 | struct msgb *resp; |
Holger Hans Peter Freyther | dc3389f | 2012-03-16 11:49:46 +0100 | [diff] [blame] | 368 | return_when_not_connected(conn); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 369 | |
| 370 | resp = gsm0808_create_classmark_update(cm2, cm2_len, cm3, cm3_len); |
| 371 | |
| 372 | queue_msg_or_return(resp); |
| 373 | } |
| 374 | |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 375 | static void bsc_mr_config(struct gsm_subscriber_connection *conn, |
| 376 | struct gsm48_multi_rate_conf *conf) |
| 377 | { |
| 378 | struct osmo_msc_data *msc; |
| 379 | |
| 380 | if (!conn->sccp_con) { |
| 381 | LOGP(DMSC, LOGL_ERROR, |
| 382 | "No msc data available on conn %p. Audio will be broken.\n", |
| 383 | conn); |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | msc = conn->sccp_con->msc; |
| 388 | |
| 389 | conf->ver = 1; |
| 390 | conf->icmi = 1; |
| 391 | |
| 392 | /* maybe gcc see's it is copy of _one_ byte */ |
| 393 | conf->m4_75 = msc->amr_conf.m4_75; |
| 394 | conf->m5_15 = msc->amr_conf.m5_15; |
| 395 | conf->m5_90 = msc->amr_conf.m5_90; |
| 396 | conf->m6_70 = msc->amr_conf.m6_70; |
| 397 | conf->m7_40 = msc->amr_conf.m7_40; |
| 398 | conf->m7_95 = msc->amr_conf.m7_95; |
| 399 | conf->m10_2 = msc->amr_conf.m10_2; |
| 400 | conf->m12_2 = msc->amr_conf.m12_2; |
| 401 | } |
| 402 | |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 403 | static struct bsc_api bsc_handler = { |
| 404 | .sapi_n_reject = bsc_sapi_n_reject, |
| 405 | .cipher_mode_compl = bsc_cipher_mode_compl, |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 406 | .compl_l3 = bsc_compl_l3, |
| 407 | .dtap = bsc_dtap, |
| 408 | .assign_compl = bsc_assign_compl, |
| 409 | .assign_fail = bsc_assign_fail, |
| 410 | .clear_request = bsc_clear_request, |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 411 | .classmark_chg = bsc_cm_update, |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 412 | .mr_config = bsc_mr_config, |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 413 | }; |
| 414 | |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 415 | struct bsc_api *osmo_bsc_api() |
| 416 | { |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 417 | return &bsc_handler; |
Holger Hans Peter Freyther | 4f448c9 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 418 | } |