Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <openbsc/osmo_bsc_grace.h> |
| 22 | #include <openbsc/osmo_bsc_rf.h> |
| 23 | #include <openbsc/osmo_msc_data.h> |
| 24 | #include <openbsc/gsm_04_80.h> |
| 25 | #include <openbsc/signal.h> |
| 26 | |
| 27 | int bsc_grace_allow_new_connection(struct gsm_network *network) |
| 28 | { |
| 29 | if (!network->msc_data->rf_ctl) |
| 30 | return 1; |
| 31 | return network->msc_data->rf_ctl->policy == S_RF_ON; |
| 32 | } |
| 33 | |
| 34 | static int handle_sub(struct gsm_lchan *lchan, const char *text) |
| 35 | { |
| 36 | struct gsm_subscriber_connection *conn; |
| 37 | |
| 38 | /* only send it to TCH */ |
| 39 | if (lchan->type != GSM_LCHAN_TCH_H && lchan->type != GSM_LCHAN_TCH_F) |
| 40 | return -1; |
| 41 | |
| 42 | /* only send on the primary channel */ |
| 43 | conn = lchan->conn; |
| 44 | if (!conn) |
| 45 | return -1; |
| 46 | |
| 47 | if (conn->lchan != lchan) |
| 48 | return -1; |
| 49 | |
| 50 | /* only when active */ |
| 51 | if (lchan->state != LCHAN_S_ACTIVE) |
| 52 | return -1; |
| 53 | |
| 54 | gsm0480_send_ussdNotify(conn, 0, text); |
| 55 | gsm0480_send_releaseComplete(conn); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * The place to handle the grace mode. Right now we will send |
| 62 | * USSD messages to the subscriber, in the future we might start |
| 63 | * a timer to have different modes for the grace period. |
| 64 | */ |
| 65 | static int handle_grace(struct gsm_network *network) |
| 66 | { |
| 67 | int ts_nr, lchan_nr; |
| 68 | struct gsm_bts *bts; |
| 69 | struct gsm_bts_trx *trx; |
| 70 | |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 71 | if (!network->msc_data->mid_call_txt) |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 72 | return 0; |
| 73 | |
| 74 | llist_for_each_entry(bts, &network->bts_list, list) { |
| 75 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 76 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ++ts_nr) { |
| 77 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr]; |
| 78 | for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; ++lchan_nr) { |
| 79 | handle_sub(&ts->lchan[lchan_nr], |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 80 | network->msc_data->mid_call_txt); |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int handle_rf_signal(unsigned int subsys, unsigned int signal, |
| 89 | void *handler_data, void *signal_data) |
| 90 | { |
| 91 | struct rf_signal_data *sig; |
| 92 | |
| 93 | if (subsys != SS_RF) |
| 94 | return -1; |
| 95 | |
| 96 | sig = signal_data; |
| 97 | |
| 98 | if (signal == S_RF_GRACE) |
| 99 | handle_grace(sig->net); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static __attribute__((constructor)) void on_dso_load_grace(void) |
| 105 | { |
| 106 | register_signal_handler(SS_RF, handle_rf_signal, NULL); |
| 107 | } |