Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 1 | /* main MSC management code... */ |
| 2 | |
| 3 | /* |
Holger Hans Peter Freyther | c25021f | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 4 | * (C) 2010,2013 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 5180844 | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 5 | * (C) 2010 by On-Waves |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <openbsc/bsc_api.h> |
| 25 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 26 | #include <openbsc/transaction.h> |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 27 | #include <openbsc/db.h> |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 28 | |
Holger Hans Peter Freyther | 9f619d0 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 29 | #include <openbsc/gsm_04_11.h> |
| 30 | |
Holger Hans Peter Freyther | dfd61a3 | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 31 | static void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 32 | { |
Holger Hans Peter Freyther | 9f619d0 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 33 | int sapi = dlci & 0x7; |
| 34 | |
| 35 | if (sapi == UM_SAPI_SMS) |
| 36 | gsm411_sapi_n_reject(conn); |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 37 | } |
| 38 | |
Holger Hans Peter Freyther | 0aa55a3 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 39 | static int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 40 | { |
| 41 | gsm0408_clear_request(conn, cause); |
Holger Hans Peter Freyther | 0aa55a3 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 42 | return 1; |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 43 | } |
| 44 | |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 45 | static int msc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 46 | uint16_t chosen_channel) |
| 47 | { |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 48 | gsm0408_new_conn(conn); |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 49 | gsm0408_dispatch(conn, msg); |
| 50 | |
Holger Hans Peter Freyther | 8cb630f | 2016-02-10 10:42:20 +0100 | [diff] [blame] | 51 | /* |
| 52 | * If this is a silent call we want the channel to remain open as long as |
| 53 | * possible and this is why we accept this connection regardless of any |
| 54 | * pending transaction or ongoing operation. |
| 55 | */ |
Holger Hans Peter Freyther | f8faba7 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 56 | if (conn->silent_call) |
| 57 | return BSC_API_CONN_POL_ACCEPT; |
| 58 | if (conn->loc_operation || conn->sec_operation || conn->anch_operation) |
| 59 | return BSC_API_CONN_POL_ACCEPT; |
| 60 | if (trans_has_conn(conn)) |
| 61 | return BSC_API_CONN_POL_ACCEPT; |
Jacob Erlbeck | c8a9245 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 62 | |
| 63 | LOGP(DRR, LOGL_INFO, "MSC Complete L3: Rejecting connection.\n"); |
Holger Hans Peter Freyther | f8faba7 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 64 | return BSC_API_CONN_POL_REJECT; |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 65 | } |
| 66 | |
Holger Hans Peter Freyther | 767ff3c | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 67 | static void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 68 | { |
| 69 | gsm0408_dispatch(conn, msg); |
| 70 | } |
| 71 | |
Holger Hans Peter Freyther | 8737f4c | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 72 | static void msc_assign_compl(struct gsm_subscriber_connection *conn, |
| 73 | uint8_t rr_cause, uint8_t chosen_channel, |
| 74 | uint8_t encr_alg_id, uint8_t speec) |
| 75 | { |
Jacob Erlbeck | c8a9245 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 76 | LOGP(DRR, LOGL_DEBUG, "MSC assign complete (do nothing).\n"); |
Holger Hans Peter Freyther | 8737f4c | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void msc_assign_fail(struct gsm_subscriber_connection *conn, |
| 80 | uint8_t cause, uint8_t *rr_cause) |
| 81 | { |
Jacob Erlbeck | c8a9245 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 82 | LOGP(DRR, LOGL_DEBUG, "MSC assign failure (do nothing).\n"); |
Holger Hans Peter Freyther | 8737f4c | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 85 | static void msc_classmark_chg(struct gsm_subscriber_connection *conn, |
| 86 | const uint8_t *cm2, uint8_t cm2_len, |
| 87 | const uint8_t *cm3, uint8_t cm3_len) |
| 88 | { |
| 89 | struct gsm_subscriber *subscr = conn->subscr; |
| 90 | |
| 91 | if (subscr) { |
| 92 | subscr->equipment.classmark2_len = cm2_len; |
| 93 | memcpy(subscr->equipment.classmark2, cm2, cm2_len); |
| 94 | if (cm3) { |
| 95 | subscr->equipment.classmark3_len = cm3_len; |
| 96 | memcpy(subscr->equipment.classmark3, cm3, cm3_len); |
| 97 | } |
| 98 | db_sync_equipment(&subscr->equipment); |
| 99 | } |
| 100 | } |
| 101 | |
Harald Welte | fe01ed7 | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 102 | static void msc_ciph_m_compl(struct gsm_subscriber_connection *conn, |
| 103 | struct msgb *msg, uint8_t alg_id) |
| 104 | { |
| 105 | gsm_cbfn *cb; |
| 106 | |
| 107 | DEBUGP(DRR, "CIPHERING MODE COMPLETE\n"); |
| 108 | |
| 109 | /* Safety check */ |
| 110 | if (!conn->sec_operation) { |
| 111 | DEBUGP(DRR, "No authentication/cipher operation in progress !!!\n"); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | /* FIXME: check for MI (if any) */ |
| 116 | |
| 117 | /* Call back whatever was in progress (if anything) ... */ |
| 118 | cb = conn->sec_operation->cb; |
| 119 | if (cb) { |
Holger Hans Peter Freyther | 1a9f3ee | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 120 | cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_SUCCEEDED, |
Harald Welte | fe01ed7 | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 121 | NULL, conn, conn->sec_operation->cb_data); |
| 122 | |
| 123 | } |
| 124 | |
| 125 | /* Complete the operation */ |
| 126 | release_security_operation(conn); |
| 127 | } |
| 128 | |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 129 | |
| 130 | |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 131 | static struct bsc_api msc_handler = { |
| 132 | .sapi_n_reject = msc_sapi_n_reject, |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 133 | .compl_l3 = msc_compl_l3, |
Neels Hofmeyr | ff4a92b | 2016-12-18 23:52:38 +0100 | [diff] [blame^] | 134 | .dtap = msc_dtap, |
Holger Hans Peter Freyther | 8737f4c | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 135 | .clear_request = msc_clear_request, |
| 136 | .assign_compl = msc_assign_compl, |
| 137 | .assign_fail = msc_assign_fail, |
Harald Welte | cd4acaf | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 138 | .classmark_chg = msc_classmark_chg, |
Harald Welte | fe01ed7 | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 139 | .cipher_mode_compl = msc_ciph_m_compl, |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | struct bsc_api *msc_bsc_api() { |
| 143 | return &msc_handler; |
| 144 | } |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 145 | |
| 146 | /* lchan release handling */ |
| 147 | void msc_release_connection(struct gsm_subscriber_connection *conn) |
| 148 | { |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 149 | /* skip when we are in release, e.g. due an error */ |
| 150 | if (conn->in_release) |
| 151 | return; |
| 152 | |
| 153 | /* skip releasing of silent calls as they have no transaction */ |
| 154 | if (conn->silent_call) |
| 155 | return; |
| 156 | |
| 157 | /* check if there is a pending operation */ |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 158 | if (conn->loc_operation || conn->sec_operation || conn->anch_operation) |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 159 | return; |
| 160 | |
Holger Hans Peter Freyther | f8faba7 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 161 | if (trans_has_conn(conn)) |
| 162 | return; |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 163 | |
| 164 | /* no more connections, asking to release the channel */ |
Holger Hans Peter Freyther | c25021f | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * We had stopped the LU expire timer T3212. Now we are about |
| 168 | * to send the MS back to the idle state and this should lead |
| 169 | * to restarting the timer. Set the new expiration time. |
| 170 | */ |
| 171 | if (conn->expire_timer_stopped) |
| 172 | subscr_update_expire_lu(conn->subscr, conn->bts); |
| 173 | |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 174 | conn->in_release = 1; |
| 175 | gsm0808_clear(conn); |
Neels Hofmeyr | d07e9e7 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 176 | msc_subscr_con_free(conn); |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 177 | } |