Holger Hans Peter Freyther | 4d61417 | 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 | 22e9ac3 | 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 | 0e3e88e | 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 | 22e9ac3 | 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 | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 13 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 22e9ac3 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 14 | * |
Harald Welte | 0e3e88e | 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 | 22e9ac3 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <openbsc/osmo_bsc.h> |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 21 | #include <openbsc/osmo_msc_data.h> |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 22 | #include <openbsc/debug.h> |
| 23 | |
Harald Welte | 8b1713a | 2011-03-23 18:26:56 +0100 | [diff] [blame] | 24 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
| 25 | #include <osmocom/gsm/gsm0808.h> |
Holger Hans Peter Freyther | a62919e | 2010-11-04 11:59:41 +0100 | [diff] [blame] | 26 | |
Holger Hans Peter Freyther | 326a124 | 2011-06-09 14:44:47 +0200 | [diff] [blame] | 27 | #include <osmocom/sccp/sccp.h> |
| 28 | |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 29 | #define return_when_not_connected(conn) \ |
| 30 | if (!conn->sccp_con) {\ |
| 31 | LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \ |
| 32 | return; \ |
| 33 | } |
| 34 | |
| 35 | #define return_when_not_connected_val(conn, ret) \ |
| 36 | if (!conn->sccp_con) {\ |
| 37 | LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \ |
| 38 | return ret; \ |
| 39 | } |
Holger Hans Peter Freyther | 22e9ac3 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 40 | |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 41 | #define queue_msg_or_return(resp) \ |
| 42 | if (!resp) { \ |
| 43 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate response.\n"); \ |
| 44 | return; \ |
| 45 | } \ |
Holger Hans Peter Freyther | 1f334cc | 2010-11-10 09:31:41 +0100 | [diff] [blame] | 46 | bsc_queue_for_msc(conn->sccp_con, resp); |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 47 | |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 48 | static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause); |
| 49 | static int complete_layer3(struct gsm_subscriber_connection *conn, |
| 50 | struct msgb *msg, struct osmo_msc_data *msc); |
| 51 | |
Holger Hans Peter Freyther | 5e84584 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 52 | static uint16_t get_network_code_for_msc(struct osmo_msc_data *msc) |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 53 | { |
Holger Hans Peter Freyther | 5e84584 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 54 | if (msc->core_ncc != -1) |
| 55 | return msc->core_ncc; |
| 56 | return msc->network->network_code; |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Holger Hans Peter Freyther | 5e84584 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 59 | static uint16_t get_country_code_for_msc(struct osmo_msc_data *msc) |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 60 | { |
Holger Hans Peter Freyther | 5e84584 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 61 | if (msc->core_mcc != -1) |
| 62 | return msc->core_mcc; |
| 63 | return msc->network->country_code; |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 66 | static void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
| 67 | { |
Holger Hans Peter Freyther | 313324e | 2010-11-04 12:28:32 +0100 | [diff] [blame] | 68 | struct msgb *resp; |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 69 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 313324e | 2010-11-04 12:28:32 +0100 | [diff] [blame] | 70 | |
Harald Welte | 98833af | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 71 | LOGP(DMSC, LOGL_NOTICE, "Tx MSC SAPI N REJECT DLCI=0x%02x\n", dlci); |
| 72 | |
Holger Hans Peter Freyther | 313324e | 2010-11-04 12:28:32 +0100 | [diff] [blame] | 73 | resp = gsm0808_create_sapi_reject(dlci); |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 74 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, |
| 78 | struct msgb *msg, uint8_t chosen_encr) |
| 79 | { |
Holger Hans Peter Freyther | a62919e | 2010-11-04 11:59:41 +0100 | [diff] [blame] | 80 | struct msgb *resp; |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 81 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | a62919e | 2010-11-04 11:59:41 +0100 | [diff] [blame] | 82 | |
| 83 | LOGP(DMSC, LOGL_DEBUG, "CIPHER MODE COMPLETE from MS, forwarding to MSC\n"); |
| 84 | resp = gsm0808_create_cipher_complete(msg, chosen_encr); |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 85 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 86 | } |
| 87 | |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 88 | /* |
| 89 | * Instruct to reserve data for a new connectiom, create the complete |
| 90 | * layer three message, send it to open the connection. |
| 91 | */ |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 92 | static int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 93 | uint16_t chosen_channel) |
| 94 | { |
Holger Hans Peter Freyther | 508e662 | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 95 | struct osmo_msc_data *msc; |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 96 | |
Harald Welte | 98833af | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 97 | LOGP(DMSC, LOGL_INFO, "Tx MSC COMPL L3\n"); |
| 98 | |
Holger Hans Peter Freyther | 508e662 | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 99 | /* find the MSC link we want to use */ |
Holger Hans Peter Freyther | e592cb1 | 2011-06-07 19:57:02 +0200 | [diff] [blame] | 100 | msc = bsc_find_msc(conn, msg); |
Holger Hans Peter Freyther | 508e662 | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 101 | if (!msc) { |
| 102 | LOGP(DMSC, LOGL_ERROR, "Failed to find a MSC for a connection.\n"); |
| 103 | return -1; |
| 104 | } |
| 105 | |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 106 | return complete_layer3(conn, msg, msc); |
| 107 | } |
| 108 | |
| 109 | static int complete_layer3(struct gsm_subscriber_connection *conn, |
| 110 | struct msgb *msg, struct osmo_msc_data *msc) |
| 111 | { |
| 112 | struct msgb *resp; |
| 113 | uint16_t network_code; |
| 114 | uint16_t country_code; |
| 115 | |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 116 | /* allocate resource for a new connection */ |
Holger Hans Peter Freyther | 508e662 | 2011-06-07 11:40:20 +0200 | [diff] [blame] | 117 | if (bsc_create_new_connection(conn, msc) != 0) |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 118 | return BSC_API_CONN_POL_REJECT; |
| 119 | |
Holger Hans Peter Freyther | 5e84584 | 2011-06-04 14:51:51 +0200 | [diff] [blame] | 120 | network_code = get_network_code_for_msc(conn->sccp_con->msc); |
| 121 | country_code = get_country_code_for_msc(conn->sccp_con->msc); |
| 122 | |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 123 | bsc_scan_bts_msg(conn, msg); |
| 124 | resp = gsm0808_create_layer3(msg, network_code, country_code, |
| 125 | conn->bts->location_area_code, |
| 126 | conn->bts->cell_identity); |
| 127 | if (!resp) { |
| 128 | LOGP(DMSC, LOGL_DEBUG, "Failed to create layer3 message.\n"); |
Holger Hans Peter Freyther | 326a124 | 2011-06-09 14:44:47 +0200 | [diff] [blame] | 129 | sccp_connection_free(conn->sccp_con->sccp); |
Holger Hans Peter Freyther | 288b80a | 2010-11-06 20:15:17 +0100 | [diff] [blame] | 130 | bsc_delete_connection(conn->sccp_con); |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 131 | return BSC_API_CONN_POL_REJECT; |
Holger Hans Peter Freyther | b408d79 | 2010-11-05 11:21:18 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Holger Hans Peter Freyther | 288b80a | 2010-11-06 20:15:17 +0100 | [diff] [blame] | 134 | if (bsc_open_connection(conn->sccp_con, resp) != 0) { |
Holger Hans Peter Freyther | 326a124 | 2011-06-09 14:44:47 +0200 | [diff] [blame] | 135 | sccp_connection_free(conn->sccp_con->sccp); |
Holger Hans Peter Freyther | 288b80a | 2010-11-06 20:15:17 +0100 | [diff] [blame] | 136 | bsc_delete_connection(conn->sccp_con); |
Holger Hans Peter Freyther | 9c61b2a | 2010-11-05 19:48:47 +0100 | [diff] [blame] | 137 | msgb_free(resp); |
| 138 | return BSC_API_CONN_POL_REJECT; |
| 139 | } |
| 140 | |
| 141 | return BSC_API_CONN_POL_ACCEPT; |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 142 | } |
| 143 | |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 144 | /* |
| 145 | * Plastic surgery... we want to give up the current connection |
| 146 | */ |
| 147 | static int move_to_msc(struct gsm_subscriber_connection *_conn, |
| 148 | struct msgb *msg, struct osmo_msc_data *msc) |
| 149 | { |
| 150 | struct osmo_bsc_sccp_con *old_con = _conn->sccp_con; |
| 151 | |
| 152 | /* |
| 153 | * 1. Give up the old connection. |
| 154 | * This happens by sending a clear request to the MSC, |
| 155 | * it should end with the MSC releasing the connection. |
| 156 | */ |
| 157 | old_con->conn = NULL; |
| 158 | bsc_clear_request(_conn, 0); |
| 159 | |
| 160 | /* |
| 161 | * 2. Attempt to create a new connection to the local |
| 162 | * MSC. If it fails the caller will need to handle this |
| 163 | * properly. |
| 164 | */ |
| 165 | _conn->sccp_con = NULL; |
| 166 | if (complete_layer3(_conn, msg, msc) != BSC_API_CONN_POL_ACCEPT) { |
| 167 | gsm0808_clear(_conn); |
| 168 | subscr_con_free(_conn); |
| 169 | return 1; |
| 170 | } |
| 171 | |
| 172 | return 2; |
| 173 | } |
| 174 | |
| 175 | static int handle_cc_setup(struct gsm_subscriber_connection *conn, |
| 176 | struct msgb *msg) |
| 177 | { |
| 178 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 179 | uint8_t pdisc = gh->proto_discr & 0x0f; |
| 180 | uint8_t mtype = gh->msg_type & 0xbf; |
| 181 | |
| 182 | struct osmo_msc_data *msc; |
| 183 | struct gsm_mncc_number called; |
| 184 | struct tlv_parsed tp; |
| 185 | unsigned payload_len; |
| 186 | |
| 187 | char _dest_nr[35]; |
| 188 | |
| 189 | /* |
| 190 | * Do we have a setup message here? if not return fast. |
| 191 | */ |
| 192 | if (pdisc != GSM48_PDISC_CC || mtype != GSM48_MT_CC_SETUP) |
| 193 | return 0; |
| 194 | |
| 195 | payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 196 | |
| 197 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 198 | if (!TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 199 | LOGP(DMSC, LOGL_ERROR, "Called BCD not present in setup.\n"); |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | memset(&called, 0, sizeof(called)); |
| 204 | gsm48_decode_called(&called, |
| 205 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD) - 1); |
| 206 | |
Holger Hans Peter Freyther | cba5609 | 2011-09-30 16:24:27 +0200 | [diff] [blame] | 207 | if (called.plan != 1 && called.plan != 0) |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 208 | return 0; |
| 209 | |
Holger Hans Peter Freyther | cba5609 | 2011-09-30 16:24:27 +0200 | [diff] [blame] | 210 | if (called.plan == 1 && called.type == 1) { |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 211 | _dest_nr[0] = _dest_nr[1] = '0'; |
| 212 | memcpy(_dest_nr + 2, called.number, sizeof(called.number)); |
| 213 | } else |
| 214 | memcpy(_dest_nr, called.number, sizeof(called.number)); |
| 215 | |
| 216 | /* |
| 217 | * Check if the connection should be moved... |
| 218 | */ |
| 219 | llist_for_each_entry(msc, &conn->bts->network->bsc_data->mscs, entry) { |
| 220 | if (msc->type != MSC_CON_TYPE_LOCAL) |
| 221 | continue; |
| 222 | if (!msc->local_pref) |
| 223 | continue; |
| 224 | if (regexec(&msc->local_pref_reg, _dest_nr, 0, NULL, 0) != 0) |
| 225 | continue; |
| 226 | |
| 227 | return move_to_msc(conn, msg, msc); |
| 228 | } |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | |
Holger Hans Peter Freyther | 767ff3c | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 234 | static void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 235 | { |
Holger Hans Peter Freyther | 3623d6b | 2010-11-04 12:24:05 +0100 | [diff] [blame] | 236 | struct msgb *resp; |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 237 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 3623d6b | 2010-11-04 12:24:05 +0100 | [diff] [blame] | 238 | |
Harald Welte | 98833af | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 239 | LOGP(DMSC, LOGL_INFO, "Tx MSC DTAP LINK_ID=0x%02x\n", link_id); |
| 240 | |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 241 | /* |
| 242 | * We might want to move this connection to a new MSC. Ask someone |
| 243 | * to handle it. If it was handled we will return. |
| 244 | */ |
Holger Hans Peter Freyther | 54f4ad9 | 2011-06-27 21:29:03 +0200 | [diff] [blame] | 245 | if (handle_cc_setup(conn, msg) >= 1) |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 246 | return; |
| 247 | |
Holger Hans Peter Freyther | b408d79 | 2010-11-05 11:21:18 +0100 | [diff] [blame] | 248 | bsc_scan_bts_msg(conn, msg); |
Holger Hans Peter Freyther | 260440b | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 249 | |
| 250 | |
Holger Hans Peter Freyther | 3623d6b | 2010-11-04 12:24:05 +0100 | [diff] [blame] | 251 | resp = gsm0808_create_dtap(msg, link_id); |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 252 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 253 | } |
| 254 | |
Holger Hans Peter Freyther | 8dd01ef | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 255 | static void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause, |
| 256 | uint8_t chosen_channel, uint8_t encr_alg_id, |
| 257 | uint8_t speech_model) |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 258 | { |
Holger Hans Peter Freyther | 03a61d1 | 2010-11-04 12:09:45 +0100 | [diff] [blame] | 259 | struct msgb *resp; |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 260 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | 03a61d1 | 2010-11-04 12:09:45 +0100 | [diff] [blame] | 261 | |
Harald Welte | 98833af | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 262 | LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN COMPL\n"); |
| 263 | |
Holger Hans Peter Freyther | 03a61d1 | 2010-11-04 12:09:45 +0100 | [diff] [blame] | 264 | resp = gsm0808_create_assignment_completed(rr_cause, chosen_channel, |
| 265 | encr_alg_id, speech_model); |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 266 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 267 | } |
| 268 | |
Holger Hans Peter Freyther | 9ff6568 | 2010-11-05 10:37:17 +0100 | [diff] [blame] | 269 | static void bsc_assign_fail(struct gsm_subscriber_connection *conn, |
| 270 | uint8_t cause, uint8_t *rr_cause) |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 271 | { |
Holger Hans Peter Freyther | cfa3747 | 2010-11-05 10:59:45 +0100 | [diff] [blame] | 272 | struct msgb *resp; |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 273 | return_when_not_connected(conn); |
Holger Hans Peter Freyther | cfa3747 | 2010-11-05 10:59:45 +0100 | [diff] [blame] | 274 | |
Harald Welte | 98833af | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 275 | LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN FAIL\n"); |
| 276 | |
Holger Hans Peter Freyther | cfa3747 | 2010-11-05 10:59:45 +0100 | [diff] [blame] | 277 | resp = gsm0808_create_assignment_failure(cause, rr_cause); |
Holger Hans Peter Freyther | 5f2184c | 2010-11-05 11:02:28 +0100 | [diff] [blame] | 278 | queue_msg_or_return(resp); |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 279 | } |
| 280 | |
Holger Hans Peter Freyther | 0aa55a3 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 281 | static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 282 | { |
Holger Hans Peter Freyther | 97f5a1a | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 283 | struct osmo_bsc_sccp_con *sccp; |
Holger Hans Peter Freyther | ef2d1bf | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 284 | struct msgb *resp; |
Holger Hans Peter Freyther | b6d7014 | 2010-11-03 19:03:35 +0100 | [diff] [blame] | 285 | return_when_not_connected_val(conn, 1); |
Holger Hans Peter Freyther | ef2d1bf | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 286 | |
Harald Welte | 98833af | 2011-07-12 00:05:11 +0200 | [diff] [blame] | 287 | LOGP(DMSC, LOGL_INFO, "Tx MSC CLEAR REQUEST\n"); |
| 288 | |
Holger Hans Peter Freyther | 97f5a1a | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 289 | /* |
| 290 | * Remove the connection from BSC<->SCCP part, the SCCP part |
| 291 | * will either be cleared by channel release or MSC disconnect |
| 292 | */ |
| 293 | sccp = conn->sccp_con; |
| 294 | sccp->conn = NULL; |
| 295 | conn->sccp_con = NULL; |
| 296 | |
Holger Hans Peter Freyther | ef2d1bf | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 297 | resp = gsm0808_create_clear_rqst(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE); |
| 298 | if (!resp) { |
| 299 | LOGP(DMSC, LOGL_ERROR, "Failed to allocate response.\n"); |
Holger Hans Peter Freyther | 97f5a1a | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 300 | return 1; |
Holger Hans Peter Freyther | ef2d1bf | 2010-11-04 12:47:06 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Holger Hans Peter Freyther | 97f5a1a | 2011-08-06 14:52:56 +0200 | [diff] [blame] | 303 | bsc_queue_for_msc(sccp, resp); |
| 304 | return 1; |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 305 | } |
| 306 | |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 307 | static void bsc_cm_update(struct gsm_subscriber_connection *conn, |
| 308 | const uint8_t *cm2, uint8_t cm2_len, |
| 309 | const uint8_t *cm3, uint8_t cm3_len) |
| 310 | { |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 311 | struct msgb *resp; |
Holger Hans Peter Freyther | 93b0a14 | 2012-03-16 11:49:46 +0100 | [diff] [blame] | 312 | return_when_not_connected(conn); |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 313 | |
| 314 | resp = gsm0808_create_classmark_update(cm2, cm2_len, cm3, cm3_len); |
| 315 | |
| 316 | queue_msg_or_return(resp); |
| 317 | } |
| 318 | |
Holger Hans Peter Freyther | ce6d3d7 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 319 | static void bsc_mr_config(struct gsm_subscriber_connection *conn, |
| 320 | struct gsm48_multi_rate_conf *conf) |
| 321 | { |
| 322 | struct osmo_msc_data *msc; |
| 323 | |
| 324 | if (!conn->sccp_con) { |
| 325 | LOGP(DMSC, LOGL_ERROR, |
| 326 | "No msc data available on conn %p. Audio will be broken.\n", |
| 327 | conn); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | msc = conn->sccp_con->msc; |
| 332 | |
| 333 | conf->ver = 1; |
| 334 | conf->icmi = 1; |
| 335 | |
| 336 | /* maybe gcc see's it is copy of _one_ byte */ |
| 337 | conf->m4_75 = msc->amr_conf.m4_75; |
| 338 | conf->m5_15 = msc->amr_conf.m5_15; |
| 339 | conf->m5_90 = msc->amr_conf.m5_90; |
| 340 | conf->m6_70 = msc->amr_conf.m6_70; |
| 341 | conf->m7_40 = msc->amr_conf.m7_40; |
| 342 | conf->m7_95 = msc->amr_conf.m7_95; |
| 343 | conf->m10_2 = msc->amr_conf.m10_2; |
| 344 | conf->m12_2 = msc->amr_conf.m12_2; |
| 345 | } |
| 346 | |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 347 | static struct bsc_api bsc_handler = { |
| 348 | .sapi_n_reject = bsc_sapi_n_reject, |
| 349 | .cipher_mode_compl = bsc_cipher_mode_compl, |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 350 | .compl_l3 = bsc_compl_l3, |
| 351 | .dtap = bsc_dtap, |
| 352 | .assign_compl = bsc_assign_compl, |
| 353 | .assign_fail = bsc_assign_fail, |
| 354 | .clear_request = bsc_clear_request, |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 355 | .classmark_chg = bsc_cm_update, |
Holger Hans Peter Freyther | ce6d3d7 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 356 | .mr_config = bsc_mr_config, |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 357 | }; |
| 358 | |
Holger Hans Peter Freyther | 22e9ac3 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 359 | struct bsc_api *osmo_bsc_api() |
| 360 | { |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 361 | return &bsc_handler; |
Holger Hans Peter Freyther | 22e9ac3 | 2010-07-05 16:02:04 +0800 | [diff] [blame] | 362 | } |