Holger Hans Peter Freyther | d2c8558 | 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 | 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 |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <openbsc/bsc_api.h> |
| 26 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 27 | #include <openbsc/transaction.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 | |
| 51 | /* TODO: do better */ |
| 52 | return BSC_API_CONN_POL_ACCEPT; |
| 53 | } |
| 54 | |
Holger Hans Peter Freyther | 767ff3c | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 55 | 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] | 56 | { |
| 57 | gsm0408_dispatch(conn, msg); |
| 58 | } |
| 59 | |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 60 | static struct bsc_api msc_handler = { |
| 61 | .sapi_n_reject = msc_sapi_n_reject, |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 62 | .clear_request = msc_clear_request, |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 63 | .compl_l3 = msc_compl_l3, |
| 64 | .dtap = msc_dtap, |
Holger Hans Peter Freyther | d2c8558 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct bsc_api *msc_bsc_api() { |
| 68 | return &msc_handler; |
| 69 | } |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 70 | |
| 71 | /* lchan release handling */ |
| 72 | void msc_release_connection(struct gsm_subscriber_connection *conn) |
| 73 | { |
| 74 | struct gsm_trans *trans; |
| 75 | |
| 76 | /* skip when we are in release, e.g. due an error */ |
| 77 | if (conn->in_release) |
| 78 | return; |
| 79 | |
| 80 | /* skip releasing of silent calls as they have no transaction */ |
| 81 | if (conn->silent_call) |
| 82 | return; |
| 83 | |
| 84 | /* check if there is a pending operation */ |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 85 | if (conn->loc_operation || conn->sec_operation || conn->anch_operation) |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 86 | return; |
| 87 | |
| 88 | llist_for_each_entry(trans, &conn->bts->network->trans_list, entry) { |
| 89 | if (trans->conn == conn) |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | /* no more connections, asking to release the channel */ |
| 94 | conn->in_release = 1; |
| 95 | gsm0808_clear(conn); |
Holger Hans Peter Freyther | 7d85564 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 96 | subscr_con_free(conn); |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 97 | } |