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