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