Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 1 | /* main MSC management code... */ |
| 2 | |
| 3 | /* |
| 4 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 5 | * (C) 2010 by On-Waves |
Holger Hans Peter Freyther | 43b0909 | 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 | 9af6ddf | 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 | 43b0909 | 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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 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 | 43b0909 | 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 | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 26 | #include <openbsc/transaction.h> |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 27 | |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 28 | #include <openbsc/gsm_04_11.h> |
| 29 | |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 30 | static void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 31 | { |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 32 | int sapi = dlci & 0x7; |
| 33 | |
| 34 | if (sapi == UM_SAPI_SMS) |
| 35 | gsm411_sapi_n_reject(conn); |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 36 | } |
| 37 | |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 38 | static int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Hans Peter Freyther | f6fb3ef | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 39 | { |
| 40 | gsm0408_clear_request(conn, cause); |
Holger Hans Peter Freyther | 182c81f | 2010-12-29 16:28:33 +0100 | [diff] [blame] | 41 | if (conn->put_channel) { |
| 42 | conn->put_channel = 0; |
| 43 | subscr_put_channel(conn->subscr); |
| 44 | } |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 45 | return 1; |
Holger Hans Peter Freyther | f6fb3ef | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 46 | } |
| 47 | |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 48 | static int msc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 49 | uint16_t chosen_channel) |
| 50 | { |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 51 | gsm0408_new_conn(conn); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 52 | gsm0408_dispatch(conn, msg); |
| 53 | |
| 54 | /* TODO: do better */ |
| 55 | return BSC_API_CONN_POL_ACCEPT; |
| 56 | } |
| 57 | |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 58 | static void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 59 | { |
| 60 | gsm0408_dispatch(conn, msg); |
| 61 | } |
| 62 | |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 63 | static struct bsc_api msc_handler = { |
| 64 | .sapi_n_reject = msc_sapi_n_reject, |
Holger Hans Peter Freyther | f6fb3ef | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 65 | .clear_request = msc_clear_request, |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 66 | .compl_l3 = msc_compl_l3, |
| 67 | .dtap = msc_dtap, |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | struct bsc_api *msc_bsc_api() { |
| 71 | return &msc_handler; |
| 72 | } |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 73 | |
| 74 | /* lchan release handling */ |
| 75 | void msc_release_connection(struct gsm_subscriber_connection *conn) |
| 76 | { |
| 77 | struct gsm_trans *trans; |
| 78 | |
| 79 | /* skip when we are in release, e.g. due an error */ |
| 80 | if (conn->in_release) |
| 81 | return; |
| 82 | |
| 83 | /* skip releasing of silent calls as they have no transaction */ |
| 84 | if (conn->silent_call) |
| 85 | return; |
| 86 | |
| 87 | /* check if there is a pending operation */ |
Holger Hans Peter Freyther | 02d39b2 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 88 | if (conn->loc_operation || conn->sec_operation || conn->anch_operation) |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 89 | return; |
| 90 | |
| 91 | llist_for_each_entry(trans, &conn->bts->network->trans_list, entry) { |
| 92 | if (trans->conn == conn) |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | /* no more connections, asking to release the channel */ |
| 97 | conn->in_release = 1; |
| 98 | gsm0808_clear(conn); |
Holger Hans Peter Freyther | 182c81f | 2010-12-29 16:28:33 +0100 | [diff] [blame] | 99 | if (conn->put_channel) { |
| 100 | conn->put_channel = 0; |
| 101 | subscr_put_channel(conn->subscr); |
| 102 | } |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 103 | subscr_con_free(conn); |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 104 | } |