Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 1 | /* |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 2 | * (C) 2010-2013 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010-2013 by On-Waves |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 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> |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 25 | #include <openbsc/gsm_subscriber.h> |
| 26 | #include <openbsc/paging.h> |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 27 | #include <openbsc/signal.h> |
| 28 | |
Holger Hans Peter Freyther | 3d119f1 | 2012-08-30 16:43:28 +0200 | [diff] [blame] | 29 | int bsc_grace_allow_new_connection(struct gsm_network *network, struct gsm_bts *bts) |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 30 | { |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 31 | if (bts->excl_from_rf_lock) |
Holger Hans Peter Freyther | 3d119f1 | 2012-08-30 16:43:28 +0200 | [diff] [blame] | 32 | return 1; |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 33 | return network->bsc_data->rf_ctrl->policy == S_RF_ON; |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 34 | } |
| 35 | |
Holger Hans Peter Freyther | 067ce6d | 2015-04-01 18:19:45 +0200 | [diff] [blame] | 36 | |
| 37 | static int normal_paging(struct gsm_subscriber *subscr, int chan_needed, |
| 38 | struct osmo_msc_data *msc) |
| 39 | { |
Holger Hans Peter Freyther | 4040783 | 2015-04-01 18:28:04 +0200 | [diff] [blame] | 40 | /* we can't page by lac.. we need to page everything */ |
| 41 | if (msc->core_lac != -1) { |
| 42 | struct gsm_bts *bts; |
| 43 | |
| 44 | llist_for_each_entry(bts, &msc->network->bts_list, list) |
| 45 | paging_request_bts(bts, subscr, chan_needed, NULL, msc); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Holger Hans Peter Freyther | 067ce6d | 2015-04-01 18:19:45 +0200 | [diff] [blame] | 50 | return paging_request(subscr->group->net, subscr, chan_needed, NULL, |
| 51 | msc); |
| 52 | } |
| 53 | |
| 54 | static int locked_paging(struct gsm_subscriber *subscr, int chan_needed, |
| 55 | struct osmo_msc_data *msc) |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 56 | { |
| 57 | struct gsm_bts *bts = NULL; |
| 58 | |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 59 | /* |
| 60 | * Check if there is any BTS that is on for the given lac. Start |
| 61 | * with NULL and iterate through all bts. |
| 62 | */ |
Holger Hans Peter Freyther | 4040783 | 2015-04-01 18:28:04 +0200 | [diff] [blame] | 63 | llist_for_each_entry(bts, &msc->network->bts_list, list) { |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 64 | /* |
| 65 | * continue if the BTS is not excluded from the lock |
| 66 | */ |
| 67 | if (!bts->excl_from_rf_lock) |
| 68 | continue; |
| 69 | |
Holger Hans Peter Freyther | 4040783 | 2015-04-01 18:28:04 +0200 | [diff] [blame] | 70 | /* in case of no lac patching is in place, check the BTS */ |
| 71 | if (msc->core_lac == -1 && subscr->lac != bts->location_area_code) |
| 72 | continue; |
| 73 | |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 74 | /* |
| 75 | * now page on this bts |
| 76 | */ |
| 77 | paging_request_bts(bts, subscr, chan_needed, NULL, msc); |
Holger Hans Peter Freyther | 4040783 | 2015-04-01 18:28:04 +0200 | [diff] [blame] | 78 | }; |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 79 | |
| 80 | /* All bts are either off or in the grace period */ |
| 81 | return 0; |
Holger Hans Peter Freyther | 067ce6d | 2015-04-01 18:19:45 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Try to not page if everything the cell is not on. |
| 86 | */ |
| 87 | int bsc_grace_paging_request(struct gsm_subscriber *subscr, int chan_needed, |
| 88 | struct osmo_msc_data *msc) |
| 89 | { |
| 90 | if (subscr->group->net->bsc_data->rf_ctrl->policy == S_RF_ON) |
| 91 | return normal_paging(subscr, chan_needed, msc); |
| 92 | return locked_paging(subscr, chan_needed, msc); |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 95 | static int handle_sub(struct gsm_lchan *lchan, const char *text) |
| 96 | { |
| 97 | struct gsm_subscriber_connection *conn; |
| 98 | |
| 99 | /* only send it to TCH */ |
| 100 | if (lchan->type != GSM_LCHAN_TCH_H && lchan->type != GSM_LCHAN_TCH_F) |
| 101 | return -1; |
| 102 | |
| 103 | /* only send on the primary channel */ |
| 104 | conn = lchan->conn; |
| 105 | if (!conn) |
| 106 | return -1; |
| 107 | |
| 108 | if (conn->lchan != lchan) |
| 109 | return -1; |
| 110 | |
| 111 | /* only when active */ |
| 112 | if (lchan->state != LCHAN_S_ACTIVE) |
| 113 | return -1; |
| 114 | |
| 115 | gsm0480_send_ussdNotify(conn, 0, text); |
| 116 | gsm0480_send_releaseComplete(conn); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * The place to handle the grace mode. Right now we will send |
| 123 | * USSD messages to the subscriber, in the future we might start |
| 124 | * a timer to have different modes for the grace period. |
| 125 | */ |
| 126 | static int handle_grace(struct gsm_network *network) |
| 127 | { |
| 128 | int ts_nr, lchan_nr; |
| 129 | struct gsm_bts *bts; |
| 130 | struct gsm_bts_trx *trx; |
| 131 | |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 132 | if (!network->bsc_data->mid_call_txt) |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 133 | return 0; |
| 134 | |
| 135 | llist_for_each_entry(bts, &network->bts_list, list) { |
| 136 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 137 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ++ts_nr) { |
| 138 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr]; |
| 139 | for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; ++lchan_nr) { |
| 140 | handle_sub(&ts->lchan[lchan_nr], |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 141 | network->bsc_data->mid_call_txt); |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int handle_rf_signal(unsigned int subsys, unsigned int signal, |
| 150 | void *handler_data, void *signal_data) |
| 151 | { |
| 152 | struct rf_signal_data *sig; |
| 153 | |
| 154 | if (subsys != SS_RF) |
| 155 | return -1; |
| 156 | |
| 157 | sig = signal_data; |
| 158 | |
| 159 | if (signal == S_RF_GRACE) |
| 160 | handle_grace(sig->net); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static __attribute__((constructor)) void on_dso_load_grace(void) |
| 166 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 167 | osmo_signal_register_handler(SS_RF, handle_rf_signal, NULL); |
Holger Hans Peter Freyther | bd76fab | 2010-09-16 00:20:56 +0800 | [diff] [blame] | 168 | } |