Jonathan Santos | 03fd8d0 | 2011-05-25 13:54:02 -0400 | [diff] [blame^] | 1 | /* main MSC management code... */ |
| 2 | |
| 3 | /* |
| 4 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * (C) 2010 by On-Waves |
| 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 Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 18 | * |
| 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/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <openbsc/bsc_api.h> |
| 25 | #include <openbsc/debug.h> |
| 26 | #include <openbsc/transaction.h> |
| 27 | |
| 28 | #include <openbsc/gsm_04_11.h> |
| 29 | |
| 30 | static void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
| 31 | { |
| 32 | int sapi = dlci & 0x7; |
| 33 | |
| 34 | if (sapi == UM_SAPI_SMS) |
| 35 | gsm411_sapi_n_reject(conn); |
| 36 | } |
| 37 | |
| 38 | static int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
| 39 | { |
| 40 | gsm0408_clear_request(conn, cause); |
| 41 | if (conn->put_channel) { |
| 42 | conn->put_channel = 0; |
| 43 | subscr_put_channel(conn->subscr); |
| 44 | } |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | static int msc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, |
| 49 | uint16_t chosen_channel) |
| 50 | { |
| 51 | gsm0408_new_conn(conn); |
| 52 | gsm0408_dispatch(conn, msg); |
| 53 | |
| 54 | /* TODO: do better */ |
| 55 | return BSC_API_CONN_POL_ACCEPT; |
| 56 | } |
| 57 | |
| 58 | static void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
| 59 | { |
| 60 | gsm0408_dispatch(conn, msg); |
| 61 | } |
| 62 | |
| 63 | static struct bsc_api msc_handler = { |
| 64 | .sapi_n_reject = msc_sapi_n_reject, |
| 65 | .clear_request = msc_clear_request, |
| 66 | .compl_l3 = msc_compl_l3, |
| 67 | .dtap = msc_dtap, |
| 68 | }; |
| 69 | |
| 70 | struct bsc_api *msc_bsc_api() { |
| 71 | return &msc_handler; |
| 72 | } |
| 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 */ |
| 88 | if (conn->loc_operation || conn->sec_operation || conn->anch_operation) |
| 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); |
| 99 | if (conn->put_channel) { |
| 100 | conn->put_channel = 0; |
| 101 | subscr_put_channel(conn->subscr); |
| 102 | } |
| 103 | subscr_con_free(conn); |
| 104 | } |