Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 1 | /* Handover Decision making for Inter-BTS (Intra-BSC) Handover. This |
| 2 | * only implements the handover algorithm/decision, but not execution |
| 3 | * of it */ |
| 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 <stdlib.h> |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include <openbsc/msgb.h> |
| 29 | #include <openbsc/debug.h> |
| 30 | #include <openbsc/gsm_data.h> |
| 31 | #include <openbsc/meas_rep.h> |
| 32 | #include <openbsc/signal.h> |
| 33 | #include <openbsc/talloc.h> |
| 34 | #include <openbsc/handover.h> |
| 35 | |
| 36 | static int handover_to_arfcn_bsic(struct gsm_lchan *lchan, |
| 37 | u_int16_t arfcn, u_int8_t bsic) |
| 38 | { |
| 39 | struct gsm_bts *new_bts; |
| 40 | |
| 41 | /* resolve the gsm_bts structure for the best neighbor */ |
| 42 | new_bts = gsm_bts_neighbor(lchan->ts->trx->bts, arfcn, bsic); |
| 43 | if (!new_bts) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 44 | LOGP(DHO, LOGL_NOTICE, "unable to determine neighbor BTS " |
| 45 | "for ARFCN %u BSIC %u ?!?\n", arfcn, bsic); |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | /* and actually try to handover to that cell */ |
| 50 | return bsc_handover_start(lchan, new_bts); |
| 51 | } |
| 52 | |
| 53 | #define RXLEV_HYST 3 |
| 54 | |
| 55 | /* process an already parsed measurement report */ |
| 56 | static int process_meas_rep(struct gsm_meas_rep *mr) |
| 57 | { |
| 58 | struct gsm_meas_rep_cell *mr_cell = NULL; |
| 59 | unsigned int best_better_db; |
| 60 | int i; |
| 61 | |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 62 | /* FIXME: implement actual averaging over multiple measurement |
| 63 | * reports */ |
| 64 | |
| 65 | /* find the best cell in this report that is at least RXLEV_HYST |
| 66 | * better than the current serving cell */ |
| 67 | for (i = 0; i < mr->num_cell; i++) { |
| 68 | unsigned int better; |
| 69 | if (mr->cell[i].rxlev < mr->dl.full.rx_lev + RXLEV_HYST) |
| 70 | continue; |
| 71 | |
| 72 | better = mr->cell[i].rxlev - mr->dl.full.rx_lev; |
| 73 | if (better > best_better_db) { |
| 74 | mr_cell = &mr->cell[i]; |
| 75 | best_better_db = better; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (mr_cell) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 80 | LOGP(DHO, LOGL_INFO, "Cell on ARFCN %u is better, starting " |
| 81 | "handover\n", mr_cell->arfcn); |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 82 | return handover_to_arfcn_bsic(mr->lchan, mr_cell->arfcn, |
| 83 | mr_cell->bsic); |
| 84 | } |
| 85 | |
| 86 | DEBUGPC(DHO, "No better cell\n"); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static int ho_dec_sig_cb(unsigned int subsys, unsigned int signal, |
| 91 | void *handler_data, void *signal_data) |
| 92 | { |
| 93 | struct gsm_meas_rep *mr; |
| 94 | |
| 95 | if (subsys != SS_LCHAN) |
| 96 | return 0; |
| 97 | |
| 98 | switch (signal) { |
| 99 | case S_LCHAN_MEAS_REP: |
| 100 | mr = signal_data; |
| 101 | process_meas_rep(mr); |
| 102 | break; |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | void on_dso_load_ho_dec(void) |
| 109 | { |
| 110 | register_signal_handler(SS_LCHAN, ho_dec_sig_cb, NULL); |
| 111 | } |