Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 1 | /* Handover Logic for Inter-BTS (Intra-BSC) Handover. This does not |
| 2 | * actually implement the handover algorithm/decision, but executes a |
| 3 | * handover decision */ |
| 4 | |
| 5 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 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 |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [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. |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [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/>. |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <errno.h> |
| 28 | #include <time.h> |
| 29 | #include <netinet/in.h> |
| 30 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 31 | #include <osmocom/core/msgb.h> |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 32 | #include <openbsc/debug.h> |
| 33 | #include <openbsc/gsm_data.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 34 | #include <osmocom/gsm/gsm_utils.h> |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 35 | #include <openbsc/gsm_subscriber.h> |
| 36 | #include <openbsc/gsm_04_08.h> |
| 37 | #include <openbsc/abis_rsl.h> |
| 38 | #include <openbsc/chan_alloc.h> |
| 39 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 40 | #include <osmocom/core/talloc.h> |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 41 | #include <openbsc/transaction.h> |
| 42 | |
| 43 | struct bsc_handover { |
| 44 | struct llist_head list; |
| 45 | |
| 46 | struct gsm_lchan *old_lchan; |
| 47 | struct gsm_lchan *new_lchan; |
| 48 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 49 | struct osmo_timer_list T3103; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 50 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 51 | uint8_t ho_ref; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static LLIST_HEAD(bsc_handovers); |
| 55 | |
| 56 | static struct bsc_handover *bsc_ho_by_new_lchan(struct gsm_lchan *new_lchan) |
| 57 | { |
| 58 | struct bsc_handover *ho; |
| 59 | |
| 60 | llist_for_each_entry(ho, &bsc_handovers, list) { |
| 61 | if (ho->new_lchan == new_lchan) |
| 62 | return ho; |
| 63 | } |
| 64 | |
| 65 | return NULL; |
| 66 | } |
| 67 | |
| 68 | static struct bsc_handover *bsc_ho_by_old_lchan(struct gsm_lchan *old_lchan) |
| 69 | { |
| 70 | struct bsc_handover *ho; |
| 71 | |
| 72 | llist_for_each_entry(ho, &bsc_handovers, list) { |
| 73 | if (ho->old_lchan == old_lchan) |
| 74 | return ho; |
| 75 | } |
| 76 | |
| 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | /* Hand over the specified logical channel to the specified new BTS. |
| 81 | * This is the main entry point for the actual handover algorithm, |
| 82 | * after it has decided it wants to initiate HO to a specific BTS */ |
| 83 | int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts) |
| 84 | { |
| 85 | struct gsm_lchan *new_lchan; |
| 86 | struct bsc_handover *ho; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 87 | static uint8_t ho_ref; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 88 | int rc; |
| 89 | |
Harald Welte | 6670681 | 2009-12-17 22:23:21 +0100 | [diff] [blame] | 90 | /* don't attempt multiple handovers for the same lchan at |
| 91 | * the same time */ |
| 92 | if (bsc_ho_by_old_lchan(old_lchan)) |
| 93 | return -EBUSY; |
| 94 | |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 95 | DEBUGP(DHO, "(old_lchan on BTS %u, new BTS %u)\n", |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 96 | old_lchan->ts->trx->bts->nr, bts->nr); |
| 97 | |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 98 | osmo_counter_inc(bts->network->stats.handover.attempted); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 99 | |
Holger Hans Peter Freyther | e071ab7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 100 | if (!old_lchan->conn) { |
| 101 | LOGP(DHO, LOGL_ERROR, "Old lchan lacks connection data.\n"); |
| 102 | return -ENOSPC; |
| 103 | } |
| 104 | |
Holger Hans Peter Freyther | 457c2a8 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 105 | new_lchan = lchan_alloc(bts, old_lchan->type, 0); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 106 | if (!new_lchan) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 107 | LOGP(DHO, LOGL_NOTICE, "No free channel\n"); |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 108 | osmo_counter_inc(bts->network->stats.handover.no_channel); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 109 | return -ENOSPC; |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 110 | } |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 111 | |
Holger Hans Peter Freyther | 90cdd28 | 2010-12-21 13:29:14 +0100 | [diff] [blame] | 112 | ho = talloc_zero(tall_bsc_ctx, struct bsc_handover); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 113 | if (!ho) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 114 | LOGP(DHO, LOGL_FATAL, "Out of Memory\n"); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 115 | lchan_free(new_lchan); |
| 116 | return -ENOMEM; |
| 117 | } |
| 118 | ho->old_lchan = old_lchan; |
| 119 | ho->new_lchan = new_lchan; |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 120 | ho->ho_ref = ho_ref++; |
| 121 | |
| 122 | /* copy some parameters from old lchan */ |
| 123 | memcpy(&new_lchan->encr, &old_lchan->encr, sizeof(new_lchan->encr)); |
| 124 | new_lchan->ms_power = old_lchan->ms_power; |
| 125 | new_lchan->bs_power = old_lchan->bs_power; |
| 126 | new_lchan->rsl_cmode = old_lchan->rsl_cmode; |
| 127 | new_lchan->tch_mode = old_lchan->tch_mode; |
Holger Hans Peter Freyther | e071ab7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 128 | |
| 129 | new_lchan->conn = old_lchan->conn; |
| 130 | new_lchan->conn->ho_lchan = new_lchan; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 131 | |
| 132 | /* FIXME: do we have a better idea of the timing advance? */ |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 133 | rc = rsl_chan_activate_lchan(new_lchan, RSL_ACT_INTER_ASYNC, 0, |
| 134 | ho->ho_ref); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 135 | if (rc < 0) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 136 | LOGP(DHO, LOGL_ERROR, "could not activate channel\n"); |
Holger Hans Peter Freyther | e071ab7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 137 | new_lchan->conn->ho_lchan = NULL; |
Holger Hans Peter Freyther | c839667 | 2010-12-26 19:59:32 +0100 | [diff] [blame] | 138 | new_lchan->conn = NULL; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 139 | talloc_free(ho); |
| 140 | lchan_free(new_lchan); |
| 141 | return rc; |
| 142 | } |
| 143 | |
Holger Hans Peter Freyther | 5eec9d9 | 2010-04-10 00:16:04 +0200 | [diff] [blame] | 144 | rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 145 | llist_add(&ho->list, &bsc_handovers); |
| 146 | /* we continue in the SS_LCHAN handler / ho_chan_activ_ack */ |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 151 | void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan) |
Holger Hans Peter Freyther | f2553a6 | 2010-06-30 12:58:14 +0800 | [diff] [blame] | 152 | { |
| 153 | struct bsc_handover *ho; |
| 154 | |
| 155 | ho = bsc_ho_by_new_lchan(conn->ho_lchan); |
| 156 | |
| 157 | |
| 158 | if (!ho && conn->ho_lchan) |
| 159 | LOGP(DHO, LOGL_ERROR, "BUG: We lost some state.\n"); |
| 160 | |
| 161 | if (!ho) { |
| 162 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | conn->ho_lchan->conn = NULL; |
| 167 | conn->ho_lchan = NULL; |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 168 | |
| 169 | if (free_lchan) |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 170 | lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | f2553a6 | 2010-06-30 12:58:14 +0800 | [diff] [blame] | 171 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 172 | osmo_timer_del(&ho->T3103); |
Holger Hans Peter Freyther | f2553a6 | 2010-06-30 12:58:14 +0800 | [diff] [blame] | 173 | llist_del(&ho->list); |
| 174 | talloc_free(ho); |
| 175 | } |
| 176 | |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 177 | /* T3103 expired: Handover has failed without HO COMPLETE or HO FAIL */ |
| 178 | static void ho_T3103_cb(void *_ho) |
| 179 | { |
| 180 | struct bsc_handover *ho = _ho; |
Harald Welte | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 181 | struct gsm_network *net = ho->new_lchan->ts->trx->bts->network; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 182 | |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 183 | DEBUGP(DHO, "HO T3103 expired\n"); |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 184 | osmo_counter_inc(net->stats.handover.timeout); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 185 | |
Holger Hans Peter Freyther | d9c9f07 | 2010-06-30 13:04:13 +0800 | [diff] [blame] | 186 | ho->new_lchan->conn->ho_lchan = NULL; |
| 187 | ho->new_lchan->conn = NULL; |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 188 | lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 189 | llist_del(&ho->list); |
| 190 | talloc_free(ho); |
| 191 | } |
| 192 | |
| 193 | /* RSL has acknowledged activation of the new lchan */ |
| 194 | static int ho_chan_activ_ack(struct gsm_lchan *new_lchan) |
| 195 | { |
| 196 | struct bsc_handover *ho; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 197 | |
Harald Welte | a9fa8dc | 2009-12-18 14:50:08 +0100 | [diff] [blame] | 198 | /* we need to check if this channel activation is related to |
| 199 | * a handover at all (and if, which particular handover) */ |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 200 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | a9fa8dc | 2009-12-18 14:50:08 +0100 | [diff] [blame] | 201 | if (!ho) |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 202 | return -ENODEV; |
Harald Welte | a9fa8dc | 2009-12-18 14:50:08 +0100 | [diff] [blame] | 203 | |
| 204 | DEBUGP(DHO, "handover activate ack, send HO Command\n"); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 205 | |
| 206 | /* we can now send the 04.08 HANDOVER COMMAND to the MS |
| 207 | * using the old lchan */ |
| 208 | |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 209 | gsm48_send_ho_cmd(ho->old_lchan, new_lchan, 0, ho->ho_ref); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 210 | |
| 211 | /* start T3103. We can continue either with T3103 expiration, |
| 212 | * 04.08 HANDOVER COMPLETE or 04.08 HANDOVER FAIL */ |
| 213 | ho->T3103.cb = ho_T3103_cb; |
Harald Welte | e47f96b | 2009-12-18 11:49:03 +0100 | [diff] [blame] | 214 | ho->T3103.data = ho; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 215 | osmo_timer_schedule(&ho->T3103, 10, 0); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 216 | |
Harald Welte | a037902 | 2009-12-20 17:04:40 +0100 | [diff] [blame] | 217 | /* create a RTP connection */ |
| 218 | if (is_ipaccess_bts(new_lchan->ts->trx->bts)) |
| 219 | rsl_ipacc_crcx(new_lchan); |
| 220 | |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | /* RSL has not acknowledged activation of the new lchan */ |
| 225 | static int ho_chan_activ_nack(struct gsm_lchan *new_lchan) |
| 226 | { |
| 227 | struct bsc_handover *ho; |
| 228 | |
| 229 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 230 | if (!ho) { |
Harald Welte | 25cf824 | 2012-07-06 14:21:55 +0200 | [diff] [blame] | 231 | LOGP(DHO, LOGL_INFO, "ACT NACK: unable to find HO record\n"); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 232 | return -ENODEV; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 233 | } |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 234 | |
Holger Hans Peter Freyther | 2391b4c | 2010-12-21 13:30:17 +0100 | [diff] [blame] | 235 | new_lchan->conn->ho_lchan = NULL; |
| 236 | new_lchan->conn = NULL; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 237 | llist_del(&ho->list); |
| 238 | talloc_free(ho); |
| 239 | |
| 240 | /* FIXME: maybe we should try to allocate a new LCHAN here? */ |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | /* GSM 04.08 HANDOVER COMPLETE has been received on new channel */ |
| 246 | static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan) |
| 247 | { |
Holger Hans Peter Freyther | 9d3e2ec | 2010-12-26 20:34:26 +0100 | [diff] [blame] | 248 | struct gsm_network *net; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 249 | struct bsc_handover *ho; |
| 250 | |
| 251 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 252 | if (!ho) { |
| 253 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 254 | return -ENODEV; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 255 | } |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 256 | |
Holger Hans Peter Freyther | 9d3e2ec | 2010-12-26 20:34:26 +0100 | [diff] [blame] | 257 | net = new_lchan->ts->trx->bts->network; |
Harald Welte | 7c639a0 | 2009-12-25 23:02:50 +0100 | [diff] [blame] | 258 | LOGP(DHO, LOGL_INFO, "Subscriber %s HO from BTS %u->%u on ARFCN " |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 259 | "%u->%u\n", subscr_name(ho->old_lchan->conn->subscr), |
Harald Welte | 7c639a0 | 2009-12-25 23:02:50 +0100 | [diff] [blame] | 260 | ho->old_lchan->ts->trx->bts->nr, new_lchan->ts->trx->bts->nr, |
| 261 | ho->old_lchan->ts->trx->arfcn, new_lchan->ts->trx->arfcn); |
| 262 | |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 263 | osmo_counter_inc(net->stats.handover.completed); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 264 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 265 | osmo_timer_del(&ho->T3103); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 266 | |
Holger Hans Peter Freyther | e071ab7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 267 | /* Replace the ho lchan with the primary one */ |
| 268 | if (ho->old_lchan != new_lchan->conn->lchan) |
| 269 | LOGP(DHO, LOGL_ERROR, "Primary lchan changed during handover.\n"); |
| 270 | |
| 271 | if (new_lchan != new_lchan->conn->ho_lchan) |
| 272 | LOGP(DHO, LOGL_ERROR, "Handover channel changed during this handover.\n"); |
| 273 | |
| 274 | new_lchan->conn->ho_lchan = NULL; |
| 275 | new_lchan->conn->lchan = new_lchan; |
| 276 | ho->old_lchan->conn = NULL; |
Harald Welte | fe18d5c | 2009-12-17 17:14:43 +0100 | [diff] [blame] | 277 | |
Holger Hans Peter Freyther | 7441949 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 278 | rsl_lchan_set_state(ho->old_lchan, LCHAN_S_INACTIVE); |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 279 | lchan_release(ho->old_lchan, 0, RSL_REL_LOCAL_END); |
Harald Welte | ade773f | 2009-12-21 13:29:19 +0100 | [diff] [blame] | 280 | |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 281 | /* do something to re-route the actual speech frames ! */ |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 282 | |
Harald Welte | ade773f | 2009-12-21 13:29:19 +0100 | [diff] [blame] | 283 | llist_del(&ho->list); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 284 | talloc_free(ho); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | /* GSM 04.08 HANDOVER FAIL has been received */ |
| 290 | static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan) |
| 291 | { |
Harald Welte | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 292 | struct gsm_network *net = old_lchan->ts->trx->bts->network; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 293 | struct bsc_handover *ho; |
| 294 | |
| 295 | ho = bsc_ho_by_old_lchan(old_lchan); |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 296 | if (!ho) { |
| 297 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 298 | return -ENODEV; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 299 | } |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 300 | |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 301 | osmo_counter_inc(net->stats.handover.failed); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 302 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 303 | osmo_timer_del(&ho->T3103); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 304 | llist_del(&ho->list); |
Holger Hans Peter Freyther | e071ab7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 305 | |
| 306 | /* release the channel and forget about it */ |
| 307 | ho->new_lchan->conn->ho_lchan = NULL; |
| 308 | ho->new_lchan->conn = NULL; |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 309 | lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | e071ab7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 310 | |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 311 | talloc_free(ho); |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* GSM 08.58 HANDOVER DETECT has been received */ |
| 317 | static int ho_rsl_detect(struct gsm_lchan *new_lchan) |
| 318 | { |
| 319 | struct bsc_handover *ho; |
| 320 | |
Harald Welte | 6f7a5a7 | 2009-12-18 11:52:03 +0100 | [diff] [blame] | 321 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 322 | if (!ho) { |
| 323 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 324 | return -ENODEV; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 325 | } |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 326 | |
| 327 | /* FIXME: do we actually want to do something here ? */ |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | static int ho_logic_sig_cb(unsigned int subsys, unsigned int signal, |
| 333 | void *handler_data, void *signal_data) |
| 334 | { |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 335 | struct lchan_signal_data *lchan_data; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 336 | struct gsm_lchan *lchan; |
| 337 | |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 338 | lchan_data = signal_data; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 339 | switch (subsys) { |
| 340 | case SS_LCHAN: |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 341 | lchan = lchan_data->lchan; |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 342 | switch (signal) { |
| 343 | case S_LCHAN_ACTIVATE_ACK: |
| 344 | return ho_chan_activ_ack(lchan); |
| 345 | case S_LCHAN_ACTIVATE_NACK: |
| 346 | return ho_chan_activ_nack(lchan); |
| 347 | case S_LCHAN_HANDOVER_DETECT: |
| 348 | return ho_rsl_detect(lchan); |
| 349 | case S_LCHAN_HANDOVER_COMPL: |
| 350 | return ho_gsm48_ho_compl(lchan); |
| 351 | case S_LCHAN_HANDOVER_FAIL: |
| 352 | return ho_gsm48_ho_fail(lchan); |
| 353 | } |
| 354 | break; |
| 355 | default: |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
Holger Hans Peter Freyther | c121bb3 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 362 | struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan) |
| 363 | { |
| 364 | struct bsc_handover *ho; |
| 365 | ho = bsc_ho_by_new_lchan(new_lchan); |
| 366 | if (!ho) |
| 367 | return NULL; |
| 368 | return ho->old_lchan; |
| 369 | } |
| 370 | |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 371 | static __attribute__((constructor)) void on_dso_load_ho_logic(void) |
| 372 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 373 | osmo_signal_register_handler(SS_LCHAN, ho_logic_sig_cb, NULL); |
Harald Welte | 798418a | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 374 | } |