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 |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <errno.h> |
| 29 | #include <time.h> |
| 30 | #include <netinet/in.h> |
| 31 | |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 32 | #include <osmocore/msgb.h> |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 33 | #include <openbsc/debug.h> |
| 34 | #include <openbsc/gsm_data.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 35 | #include <osmocore/gsm_utils.h> |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 36 | #include <openbsc/gsm_subscriber.h> |
| 37 | #include <openbsc/gsm_04_08.h> |
| 38 | #include <openbsc/abis_rsl.h> |
| 39 | #include <openbsc/chan_alloc.h> |
| 40 | #include <openbsc/signal.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 41 | #include <osmocore/talloc.h> |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 42 | #include <openbsc/transaction.h> |
Harald Welte | f8189fe | 2009-12-20 17:04:40 +0100 | [diff] [blame] | 43 | #include <openbsc/rtp_proxy.h> |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 44 | |
| 45 | struct bsc_handover { |
| 46 | struct llist_head list; |
| 47 | |
| 48 | struct gsm_lchan *old_lchan; |
| 49 | struct gsm_lchan *new_lchan; |
| 50 | |
| 51 | struct timer_list T3103; |
| 52 | |
| 53 | u_int8_t ho_ref; |
| 54 | }; |
| 55 | |
| 56 | static LLIST_HEAD(bsc_handovers); |
| 57 | |
| 58 | static struct bsc_handover *bsc_ho_by_new_lchan(struct gsm_lchan *new_lchan) |
| 59 | { |
| 60 | struct bsc_handover *ho; |
| 61 | |
| 62 | llist_for_each_entry(ho, &bsc_handovers, list) { |
| 63 | if (ho->new_lchan == new_lchan) |
| 64 | return ho; |
| 65 | } |
| 66 | |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | static struct bsc_handover *bsc_ho_by_old_lchan(struct gsm_lchan *old_lchan) |
| 71 | { |
| 72 | struct bsc_handover *ho; |
| 73 | |
| 74 | llist_for_each_entry(ho, &bsc_handovers, list) { |
| 75 | if (ho->old_lchan == old_lchan) |
| 76 | return ho; |
| 77 | } |
| 78 | |
| 79 | return NULL; |
| 80 | } |
| 81 | |
| 82 | /* Hand over the specified logical channel to the specified new BTS. |
| 83 | * This is the main entry point for the actual handover algorithm, |
| 84 | * after it has decided it wants to initiate HO to a specific BTS */ |
| 85 | int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts) |
| 86 | { |
| 87 | struct gsm_lchan *new_lchan; |
| 88 | struct bsc_handover *ho; |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 89 | static u_int8_t ho_ref; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 90 | int rc; |
| 91 | |
Harald Welte | aef376f | 2009-12-17 22:23:21 +0100 | [diff] [blame] | 92 | /* don't attempt multiple handovers for the same lchan at |
| 93 | * the same time */ |
| 94 | if (bsc_ho_by_old_lchan(old_lchan)) |
| 95 | return -EBUSY; |
| 96 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 97 | DEBUGP(DHO, "(old_lchan on BTS %u, new BTS %u)\n", |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 98 | old_lchan->ts->trx->bts->nr, bts->nr); |
| 99 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 100 | counter_inc(bts->network->stats.handover.attempted); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 101 | |
Holger Hans Peter Freyther | bac7ff7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 102 | if (!old_lchan->conn) { |
| 103 | LOGP(DHO, LOGL_ERROR, "Old lchan lacks connection data.\n"); |
| 104 | return -ENOSPC; |
| 105 | } |
| 106 | |
Holger Hans Peter Freyther | db39203 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 107 | new_lchan = lchan_alloc(bts, old_lchan->type, 0); |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 108 | if (!new_lchan) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 109 | LOGP(DHO, LOGL_NOTICE, "No free channel\n"); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 110 | counter_inc(bts->network->stats.handover.no_channel); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 111 | return -ENOSPC; |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 112 | } |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 113 | |
| 114 | ho = talloc_zero(NULL, struct bsc_handover); |
| 115 | if (!ho) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 116 | LOGP(DHO, LOGL_FATAL, "Out of Memory\n"); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 117 | lchan_free(new_lchan); |
| 118 | return -ENOMEM; |
| 119 | } |
| 120 | ho->old_lchan = old_lchan; |
| 121 | ho->new_lchan = new_lchan; |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 122 | ho->ho_ref = ho_ref++; |
| 123 | |
| 124 | /* copy some parameters from old lchan */ |
| 125 | memcpy(&new_lchan->encr, &old_lchan->encr, sizeof(new_lchan->encr)); |
| 126 | new_lchan->ms_power = old_lchan->ms_power; |
| 127 | new_lchan->bs_power = old_lchan->bs_power; |
| 128 | new_lchan->rsl_cmode = old_lchan->rsl_cmode; |
| 129 | new_lchan->tch_mode = old_lchan->tch_mode; |
Holger Hans Peter Freyther | bac7ff7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 130 | |
| 131 | new_lchan->conn = old_lchan->conn; |
| 132 | new_lchan->conn->ho_lchan = new_lchan; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 133 | |
| 134 | /* FIXME: do we have a better idea of the timing advance? */ |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 135 | rc = rsl_chan_activate_lchan(new_lchan, RSL_ACT_INTER_ASYNC, 0, |
| 136 | ho->ho_ref); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 137 | if (rc < 0) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 138 | LOGP(DHO, LOGL_ERROR, "could not activate channel\n"); |
Holger Hans Peter Freyther | bac7ff7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 139 | new_lchan->conn->ho_lchan = NULL; |
Harald Welte | 96c0b08 | 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 | 599056d | 2010-04-10 00:16:04 +0200 | [diff] [blame] | 145 | rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ); |
Harald Welte | 96c0b08 | 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 | df5f724 | 2010-06-30 12:58:14 +0800 | [diff] [blame] | 152 | void bsc_clear_handover(struct gsm_subscriber_connection *conn) |
| 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; |
| 169 | lchan_release(ho->new_lchan, 0, 1); |
| 170 | |
| 171 | bsc_del_timer(&ho->T3103); |
| 172 | llist_del(&ho->list); |
| 173 | talloc_free(ho); |
| 174 | } |
| 175 | |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 176 | /* T3103 expired: Handover has failed without HO COMPLETE or HO FAIL */ |
| 177 | static void ho_T3103_cb(void *_ho) |
| 178 | { |
| 179 | struct bsc_handover *ho = _ho; |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 180 | struct gsm_network *net = ho->new_lchan->ts->trx->bts->network; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 181 | |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 182 | DEBUGP(DHO, "HO T3103 expired\n"); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 183 | counter_inc(net->stats.handover.timeout); |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 184 | |
Holger Hans Peter Freyther | b93d08c | 2010-06-30 13:04:13 +0800 | [diff] [blame] | 185 | ho->new_lchan->conn->ho_lchan = NULL; |
| 186 | ho->new_lchan->conn = NULL; |
| 187 | lchan_release(ho->new_lchan, 0, 1); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 188 | llist_del(&ho->list); |
| 189 | talloc_free(ho); |
| 190 | } |
| 191 | |
| 192 | /* RSL has acknowledged activation of the new lchan */ |
| 193 | static int ho_chan_activ_ack(struct gsm_lchan *new_lchan) |
| 194 | { |
| 195 | struct bsc_handover *ho; |
| 196 | int rc; |
| 197 | |
Harald Welte | fedc19e | 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 | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 200 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | fedc19e | 2009-12-18 14:50:08 +0100 | [diff] [blame] | 201 | if (!ho) |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 202 | return -ENODEV; |
Harald Welte | fedc19e | 2009-12-18 14:50:08 +0100 | [diff] [blame] | 203 | |
| 204 | DEBUGP(DHO, "handover activate ack, send HO Command\n"); |
Harald Welte | 96c0b08 | 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 | |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 209 | rc = 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] | 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 | 6d8220c | 2009-12-18 11:49:03 +0100 | [diff] [blame] | 214 | ho->T3103.data = ho; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 215 | bsc_schedule_timer(&ho->T3103, 10, 0); |
| 216 | |
Harald Welte | f8189fe | 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 | 96c0b08 | 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 | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 230 | if (!ho) { |
| 231 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 232 | return -ENODEV; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 233 | } |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 234 | |
| 235 | llist_del(&ho->list); |
| 236 | talloc_free(ho); |
| 237 | |
| 238 | /* FIXME: maybe we should try to allocate a new LCHAN here? */ |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | /* GSM 04.08 HANDOVER COMPLETE has been received on new channel */ |
| 244 | static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan) |
| 245 | { |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 246 | struct gsm_network *net = new_lchan->ts->trx->bts->network; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 247 | struct bsc_handover *ho; |
| 248 | |
| 249 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 250 | if (!ho) { |
| 251 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 252 | return -ENODEV; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 253 | } |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 254 | |
Harald Welte | 58eeaba | 2009-12-25 23:02:50 +0100 | [diff] [blame] | 255 | 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] | 256 | "%u->%u\n", subscr_name(ho->old_lchan->conn->subscr), |
Harald Welte | 58eeaba | 2009-12-25 23:02:50 +0100 | [diff] [blame] | 257 | ho->old_lchan->ts->trx->bts->nr, new_lchan->ts->trx->bts->nr, |
| 258 | ho->old_lchan->ts->trx->arfcn, new_lchan->ts->trx->arfcn); |
| 259 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 260 | counter_inc(net->stats.handover.completed); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 261 | |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 262 | bsc_del_timer(&ho->T3103); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 263 | |
Holger Hans Peter Freyther | bac7ff7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 264 | /* Replace the ho lchan with the primary one */ |
| 265 | if (ho->old_lchan != new_lchan->conn->lchan) |
| 266 | LOGP(DHO, LOGL_ERROR, "Primary lchan changed during handover.\n"); |
| 267 | |
| 268 | if (new_lchan != new_lchan->conn->ho_lchan) |
| 269 | LOGP(DHO, LOGL_ERROR, "Handover channel changed during this handover.\n"); |
| 270 | |
| 271 | new_lchan->conn->ho_lchan = NULL; |
| 272 | new_lchan->conn->lchan = new_lchan; |
| 273 | ho->old_lchan->conn = NULL; |
Harald Welte | f8c5070 | 2009-12-17 17:14:43 +0100 | [diff] [blame] | 274 | |
Holger Hans Peter Freyther | 68914a0 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 275 | rsl_lchan_set_state(ho->old_lchan, LCHAN_S_INACTIVE); |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 276 | lchan_release(ho->old_lchan, 0, 1); |
Harald Welte | 83c5981 | 2009-12-21 13:29:19 +0100 | [diff] [blame] | 277 | |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 278 | /* do something to re-route the actual speech frames ! */ |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 279 | |
Harald Welte | 83c5981 | 2009-12-21 13:29:19 +0100 | [diff] [blame] | 280 | llist_del(&ho->list); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 281 | talloc_free(ho); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | /* GSM 04.08 HANDOVER FAIL has been received */ |
| 287 | static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan) |
| 288 | { |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 289 | struct gsm_network *net = old_lchan->ts->trx->bts->network; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 290 | struct bsc_handover *ho; |
| 291 | |
| 292 | ho = bsc_ho_by_old_lchan(old_lchan); |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 293 | if (!ho) { |
| 294 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 295 | return -ENODEV; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 296 | } |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 297 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 298 | counter_inc(net->stats.handover.failed); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 299 | |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 300 | bsc_del_timer(&ho->T3103); |
| 301 | llist_del(&ho->list); |
Holger Hans Peter Freyther | bac7ff7 | 2010-06-30 12:40:10 +0800 | [diff] [blame] | 302 | |
| 303 | /* release the channel and forget about it */ |
| 304 | ho->new_lchan->conn->ho_lchan = NULL; |
| 305 | ho->new_lchan->conn = NULL; |
| 306 | lchan_release(ho->new_lchan, 0, 1); |
| 307 | |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 308 | talloc_free(ho); |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | /* GSM 08.58 HANDOVER DETECT has been received */ |
| 314 | static int ho_rsl_detect(struct gsm_lchan *new_lchan) |
| 315 | { |
| 316 | struct bsc_handover *ho; |
| 317 | |
Harald Welte | bc2e539 | 2009-12-18 11:52:03 +0100 | [diff] [blame] | 318 | ho = bsc_ho_by_new_lchan(new_lchan); |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 319 | if (!ho) { |
| 320 | LOGP(DHO, LOGL_ERROR, "unable to find HO record\n"); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 321 | return -ENODEV; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 322 | } |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 323 | |
| 324 | /* FIXME: do we actually want to do something here ? */ |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Harald Welte | f8189fe | 2009-12-20 17:04:40 +0100 | [diff] [blame] | 329 | static int ho_ipac_crcx_ack(struct gsm_lchan *new_lchan) |
| 330 | { |
| 331 | struct bsc_handover *ho; |
| 332 | struct rtp_socket *old_rs, *new_rs, *other_rs; |
| 333 | |
| 334 | ho = bsc_ho_by_new_lchan(new_lchan); |
| 335 | if (!ho) { |
Harald Welte | 49afbc3 | 2009-12-24 13:27:02 +0100 | [diff] [blame] | 336 | /* it is perfectly normal, we have CRCX even in non-HO cases */ |
| 337 | return 0; |
Harald Welte | f8189fe | 2009-12-20 17:04:40 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if (ipacc_rtp_direct) { |
| 341 | LOGP(DHO, LOGL_ERROR, "unable to handover in direct RTP mode\n"); |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /* RTP Proxy mode */ |
| 346 | new_rs = new_lchan->abis_ip.rtp_socket; |
| 347 | old_rs = ho->old_lchan->abis_ip.rtp_socket; |
| 348 | |
| 349 | if (!new_rs) { |
| 350 | LOGP(DHO, LOGL_ERROR, "no RTP socket for new_lchan\n"); |
| 351 | return -EIO; |
| 352 | } |
| 353 | |
| 354 | rsl_ipacc_mdcx_to_rtpsock(new_lchan); |
| 355 | |
| 356 | if (!old_rs) { |
| 357 | LOGP(DHO, LOGL_ERROR, "no RTP socekt for old_lchan\n"); |
| 358 | return -EIO; |
| 359 | } |
| 360 | |
| 361 | /* copy rx_action and reference to other sock */ |
| 362 | new_rs->rx_action = old_rs->rx_action; |
| 363 | new_rs->tx_action = old_rs->tx_action; |
| 364 | new_rs->transmit = old_rs->transmit; |
| 365 | |
| 366 | switch (ho->old_lchan->abis_ip.rtp_socket->rx_action) { |
| 367 | case RTP_PROXY: |
| 368 | other_rs = old_rs->proxy.other_sock; |
| 369 | rtp_socket_proxy(new_rs, other_rs); |
| 370 | /* delete reference to other end socket to prevent |
| 371 | * rtp_socket_free() from removing the inverse reference */ |
| 372 | old_rs->proxy.other_sock = NULL; |
| 373 | break; |
| 374 | case RTP_RECV_UPSTREAM: |
| 375 | new_rs->receive = old_rs->receive; |
| 376 | break; |
| 377 | case RTP_NONE: |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 384 | static int ho_logic_sig_cb(unsigned int subsys, unsigned int signal, |
| 385 | void *handler_data, void *signal_data) |
| 386 | { |
| 387 | struct gsm_lchan *lchan; |
| 388 | |
| 389 | switch (subsys) { |
| 390 | case SS_LCHAN: |
| 391 | lchan = signal_data; |
| 392 | switch (signal) { |
| 393 | case S_LCHAN_ACTIVATE_ACK: |
| 394 | return ho_chan_activ_ack(lchan); |
| 395 | case S_LCHAN_ACTIVATE_NACK: |
| 396 | return ho_chan_activ_nack(lchan); |
| 397 | case S_LCHAN_HANDOVER_DETECT: |
| 398 | return ho_rsl_detect(lchan); |
| 399 | case S_LCHAN_HANDOVER_COMPL: |
| 400 | return ho_gsm48_ho_compl(lchan); |
| 401 | case S_LCHAN_HANDOVER_FAIL: |
| 402 | return ho_gsm48_ho_fail(lchan); |
| 403 | } |
| 404 | break; |
Harald Welte | f8189fe | 2009-12-20 17:04:40 +0100 | [diff] [blame] | 405 | case SS_ABISIP: |
| 406 | lchan = signal_data; |
| 407 | switch (signal) { |
| 408 | case S_ABISIP_CRCX_ACK: |
| 409 | return ho_ipac_crcx_ack(lchan); |
| 410 | break; |
| 411 | } |
| 412 | break; |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static __attribute__((constructor)) void on_dso_load_ho_logic(void) |
| 421 | { |
| 422 | register_signal_handler(SS_LCHAN, ho_logic_sig_cb, NULL); |
Harald Welte | f8189fe | 2009-12-20 17:04:40 +0100 | [diff] [blame] | 423 | register_signal_handler(SS_ABISIP, ho_logic_sig_cb, NULL); |
Harald Welte | 96c0b08 | 2009-11-29 22:56:14 +0100 | [diff] [blame] | 424 | } |