Harald Welte | 8d77b95 | 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 |
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 | 8d77b95 | 2009-12-17 00:31:10 +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 | 8d77b95 | 2009-12-17 00:31:10 +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 | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | #include <errno.h> |
| 26 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/msgb.h> |
Neels Hofmeyr | c016479 | 2017-09-04 15:15:32 +0200 | [diff] [blame] | 28 | #include <osmocom/bsc/debug.h> |
| 29 | #include <osmocom/bsc/gsm_data.h> |
| 30 | #include <osmocom/bsc/meas_rep.h> |
| 31 | #include <osmocom/bsc/signal.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 32 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 33 | #include <osmocom/gsm/gsm_utils.h> |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 34 | |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 35 | #include <osmocom/bsc/handover.h> |
| 36 | #include <osmocom/bsc/handover_cfg.h> |
| 37 | |
Neels Hofmeyr | 1c251f0 | 2018-01-08 15:44:56 +0100 | [diff] [blame] | 38 | /* Find BTS by ARFCN and BSIC */ |
Neels Hofmeyr | 2660c04 | 2018-01-08 16:52:37 +0100 | [diff] [blame] | 39 | struct gsm_bts *bts_by_arfcn_bsic(const struct gsm_network *net, |
| 40 | uint16_t arfcn, uint8_t bsic) |
Neels Hofmeyr | ce4d88b | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 41 | { |
Neels Hofmeyr | 1c251f0 | 2018-01-08 15:44:56 +0100 | [diff] [blame] | 42 | struct gsm_bts *bts; |
Neels Hofmeyr | ce4d88b | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 43 | |
Neels Hofmeyr | 1c251f0 | 2018-01-08 15:44:56 +0100 | [diff] [blame] | 44 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 45 | if (bts->c0->arfcn == arfcn && |
| 46 | bts->bsic == bsic) |
| 47 | return bts; |
Neels Hofmeyr | ce4d88b | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 54 | /* issue handover to a cell identified by ARFCN and BSIC */ |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 55 | static int handover_to_arfcn_bsic(struct gsm_lchan *lchan, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 56 | uint16_t arfcn, uint8_t bsic) |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 57 | { |
| 58 | struct gsm_bts *new_bts; |
| 59 | |
| 60 | /* resolve the gsm_bts structure for the best neighbor */ |
Neels Hofmeyr | 1c251f0 | 2018-01-08 15:44:56 +0100 | [diff] [blame] | 61 | /* FIXME: use some better heuristics here to determine which cell |
| 62 | * using this ARFCN really is closest to the target cell. For |
| 63 | * now we simply assume that each ARFCN will only be used by one |
| 64 | * cell */ |
| 65 | new_bts = bts_by_arfcn_bsic(lchan->ts->trx->bts->network, arfcn, bsic); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 66 | if (!new_bts) { |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 67 | LOGP(DHODEC, LOGL_NOTICE, "unable to determine neighbor BTS " |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 68 | "for ARFCN %u BSIC %u ?!?\n", arfcn, bsic); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 69 | return -EINVAL; |
| 70 | } |
| 71 | |
| 72 | /* and actually try to handover to that cell */ |
Neels Hofmeyr | 45e46d2 | 2018-02-15 14:10:12 +0100 | [diff] [blame] | 73 | return bsc_handover_start(HODEC1, lchan, new_bts, lchan->type); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 76 | /* did we get a RXLEV for a given cell in the given report? */ |
| 77 | static int rxlev_for_cell_in_rep(struct gsm_meas_rep *mr, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 78 | uint16_t arfcn, uint8_t bsic) |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 79 | { |
| 80 | int i; |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 81 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 82 | for (i = 0; i < mr->num_cell; i++) { |
| 83 | struct gsm_meas_rep_cell *mrc = &mr->cell[i]; |
| 84 | |
| 85 | /* search for matching report */ |
| 86 | if (!(mrc->arfcn == arfcn && mrc->bsic == bsic)) |
| 87 | continue; |
| 88 | |
| 89 | mrc->flags |= MRC_F_PROCESSED; |
| 90 | return mrc->rxlev; |
| 91 | } |
| 92 | return -ENODEV; |
| 93 | } |
| 94 | |
| 95 | /* obtain averaged rxlev for given neighbor */ |
| 96 | static int neigh_meas_avg(struct neigh_meas_proc *nmp, int window) |
| 97 | { |
| 98 | unsigned int i, idx; |
| 99 | int avg = 0; |
| 100 | |
Andreas Eversberg | 11e31c7 | 2013-06-01 17:00:59 +0200 | [diff] [blame] | 101 | /* reduce window to the actual number of existing measurements */ |
Neels Hofmeyr | f9b8cb1 | 2017-12-05 01:03:39 +0100 | [diff] [blame] | 102 | if (window > nmp->rxlev_cnt) |
Andreas Eversberg | 11e31c7 | 2013-06-01 17:00:59 +0200 | [diff] [blame] | 103 | window = nmp->rxlev_cnt; |
| 104 | /* this should never happen */ |
Neels Hofmeyr | 186e478 | 2017-12-05 01:01:38 +0100 | [diff] [blame] | 105 | if (window <= 0) { |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 106 | LOGP(DHODEC, LOGL_ERROR, "Requested Neighbor RxLev for invalid window size of %d\n", window); |
Andreas Eversberg | 11e31c7 | 2013-06-01 17:00:59 +0200 | [diff] [blame] | 107 | return 0; |
Neels Hofmeyr | 186e478 | 2017-12-05 01:01:38 +0100 | [diff] [blame] | 108 | } |
Andreas Eversberg | 11e31c7 | 2013-06-01 17:00:59 +0200 | [diff] [blame] | 109 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 110 | idx = calc_initial_idx(ARRAY_SIZE(nmp->rxlev), |
| 111 | nmp->rxlev_cnt % ARRAY_SIZE(nmp->rxlev), |
| 112 | window); |
| 113 | |
| 114 | for (i = 0; i < window; i++) { |
| 115 | int j = (idx+i) % ARRAY_SIZE(nmp->rxlev); |
| 116 | |
| 117 | avg += nmp->rxlev[j]; |
| 118 | } |
| 119 | |
| 120 | return avg / window; |
| 121 | } |
| 122 | |
| 123 | /* find empty or evict bad neighbor */ |
| 124 | static struct neigh_meas_proc *find_evict_neigh(struct gsm_lchan *lchan) |
| 125 | { |
| 126 | int j, worst = 999999; |
Holger Hans Peter Freyther | 80352e0 | 2011-04-18 17:16:56 +0200 | [diff] [blame] | 127 | struct neigh_meas_proc *nmp_worst = NULL; |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 128 | |
| 129 | /* first try to find an empty/unused slot */ |
| 130 | for (j = 0; j < ARRAY_SIZE(lchan->neigh_meas); j++) { |
| 131 | struct neigh_meas_proc *nmp = &lchan->neigh_meas[j]; |
| 132 | if (!nmp->arfcn) |
| 133 | return nmp; |
| 134 | } |
| 135 | |
| 136 | /* no empty slot found. evict worst neighbor from list */ |
| 137 | for (j = 0; j < ARRAY_SIZE(lchan->neigh_meas); j++) { |
| 138 | struct neigh_meas_proc *nmp = &lchan->neigh_meas[j]; |
| 139 | int avg = neigh_meas_avg(nmp, MAX_WIN_NEIGH_AVG); |
Holger Hans Peter Freyther | 80352e0 | 2011-04-18 17:16:56 +0200 | [diff] [blame] | 140 | if (!nmp_worst || avg < worst) { |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 141 | worst = avg; |
| 142 | nmp_worst = nmp; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return nmp_worst; |
| 147 | } |
| 148 | |
| 149 | /* process neighbor cell measurement reports */ |
| 150 | static void process_meas_neigh(struct gsm_meas_rep *mr) |
| 151 | { |
| 152 | int i, j, idx; |
| 153 | |
| 154 | /* for each reported cell, try to update global state */ |
| 155 | for (j = 0; j < ARRAY_SIZE(mr->lchan->neigh_meas); j++) { |
| 156 | struct neigh_meas_proc *nmp = &mr->lchan->neigh_meas[j]; |
| 157 | unsigned int idx; |
| 158 | int rxlev; |
| 159 | |
| 160 | /* skip unused entries */ |
| 161 | if (!nmp->arfcn) |
| 162 | continue; |
| 163 | |
| 164 | rxlev = rxlev_for_cell_in_rep(mr, nmp->arfcn, nmp->bsic); |
| 165 | idx = nmp->rxlev_cnt % ARRAY_SIZE(nmp->rxlev); |
| 166 | if (rxlev >= 0) { |
| 167 | nmp->rxlev[idx] = rxlev; |
| 168 | nmp->last_seen_nr = mr->nr; |
| 169 | } else |
| 170 | nmp->rxlev[idx] = 0; |
| 171 | nmp->rxlev_cnt++; |
| 172 | } |
| 173 | |
| 174 | /* iterate over list of reported cells, check if we did not |
| 175 | * process all of them */ |
| 176 | for (i = 0; i < mr->num_cell; i++) { |
| 177 | struct gsm_meas_rep_cell *mrc = &mr->cell[i]; |
| 178 | struct neigh_meas_proc *nmp; |
| 179 | |
| 180 | if (mrc->flags & MRC_F_PROCESSED) |
| 181 | continue; |
| 182 | |
| 183 | nmp = find_evict_neigh(mr->lchan); |
| 184 | |
| 185 | nmp->arfcn = mrc->arfcn; |
| 186 | nmp->bsic = mrc->bsic; |
| 187 | |
Andreas Eversberg | 11e31c7 | 2013-06-01 17:00:59 +0200 | [diff] [blame] | 188 | nmp->rxlev_cnt = 0; |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 189 | idx = nmp->rxlev_cnt % ARRAY_SIZE(nmp->rxlev); |
| 190 | nmp->rxlev[idx] = mrc->rxlev; |
| 191 | nmp->rxlev_cnt++; |
| 192 | nmp->last_seen_nr = mr->nr; |
| 193 | |
| 194 | mrc->flags |= MRC_F_PROCESSED; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /* attempt to do a handover */ |
| 199 | static int attempt_handover(struct gsm_meas_rep *mr) |
| 200 | { |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 201 | struct gsm_bts *bts = mr->lchan->ts->trx->bts; |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 202 | struct neigh_meas_proc *best_cell = NULL; |
| 203 | unsigned int best_better_db = 0; |
| 204 | int i, rc; |
| 205 | |
| 206 | /* find the best cell in this report that is at least RXLEV_HYST |
| 207 | * better than the current serving cell */ |
| 208 | |
| 209 | for (i = 0; i < ARRAY_SIZE(mr->lchan->neigh_meas); i++) { |
| 210 | struct neigh_meas_proc *nmp = &mr->lchan->neigh_meas[i]; |
| 211 | int avg, better; |
| 212 | |
| 213 | /* skip empty slots */ |
| 214 | if (nmp->arfcn == 0) |
| 215 | continue; |
| 216 | |
| 217 | /* caculate average rxlev for this cell over the window */ |
Neels Hofmeyr | dd42eb9 | 2018-02-14 19:56:23 +0100 | [diff] [blame] | 218 | avg = neigh_meas_avg(nmp, ho_get_hodec1_rxlev_neigh_avg_win(bts->ho)); |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 219 | |
| 220 | /* check if hysteresis is fulfilled */ |
Neels Hofmeyr | dd42eb9 | 2018-02-14 19:56:23 +0100 | [diff] [blame] | 221 | if (avg < mr->dl.full.rx_lev + ho_get_hodec1_pwr_hysteresis(bts->ho)) |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 222 | continue; |
| 223 | |
| 224 | better = avg - mr->dl.full.rx_lev; |
| 225 | if (better > best_better_db) { |
| 226 | best_cell = nmp; |
| 227 | best_better_db = better; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (!best_cell) |
| 232 | return 0; |
| 233 | |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 234 | LOGP(DHODEC, LOGL_INFO, "%s: Cell on ARFCN %u is better: ", |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 235 | gsm_ts_name(mr->lchan->ts), best_cell->arfcn); |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 236 | if (!ho_get_ho_active(bts->ho)) { |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 237 | LOGPC(DHODEC, LOGL_INFO, "Skipping, Handover disabled\n"); |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | rc = handover_to_arfcn_bsic(mr->lchan, best_cell->arfcn, best_cell->bsic); |
| 242 | switch (rc) { |
| 243 | case 0: |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 244 | LOGPC(DHODEC, LOGL_INFO, "Starting handover: meas report number %d \n", mr->nr); |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 245 | break; |
| 246 | case -ENOSPC: |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 247 | LOGPC(DHODEC, LOGL_INFO, "No channel available\n"); |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 248 | break; |
| 249 | case -EBUSY: |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 250 | LOGPC(DHODEC, LOGL_INFO, "Handover already active\n"); |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 251 | break; |
| 252 | default: |
Andreas Eversberg | 81260a6 | 2013-07-07 09:12:17 +0200 | [diff] [blame] | 253 | LOGPC(DHODEC, LOGL_ERROR, "Unknown error\n"); |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 254 | } |
| 255 | return rc; |
| 256 | } |
| 257 | |
| 258 | /* process an already parsed measurement report and decide if we want to |
| 259 | * attempt a handover */ |
Neels Hofmeyr | 45e46d2 | 2018-02-15 14:10:12 +0100 | [diff] [blame] | 260 | static void on_measurement_report(struct gsm_meas_rep *mr) |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 261 | { |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 262 | struct gsm_bts *bts = mr->lchan->ts->trx->bts; |
Max | 8a4d2e7 | 2016-05-17 15:56:49 +0200 | [diff] [blame] | 263 | enum meas_rep_field dlev, dqual; |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 264 | int av_rxlev; |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 265 | unsigned int pwr_interval; |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 266 | |
Neels Hofmeyr | 87b5eb6 | 2017-12-07 01:55:58 +0100 | [diff] [blame] | 267 | /* If this cell does not use handover algorithm 1, then we're not responsible. */ |
| 268 | if (ho_get_algorithm(bts->ho) != 1) |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 269 | return; |
Neels Hofmeyr | 87b5eb6 | 2017-12-07 01:55:58 +0100 | [diff] [blame] | 270 | |
Harald Welte | 386cd2b | 2009-12-18 11:49:20 +0100 | [diff] [blame] | 271 | /* we currently only do handover for TCH channels */ |
| 272 | switch (mr->lchan->type) { |
| 273 | case GSM_LCHAN_TCH_F: |
| 274 | case GSM_LCHAN_TCH_H: |
| 275 | break; |
| 276 | default: |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 277 | return; |
Harald Welte | 386cd2b | 2009-12-18 11:49:20 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Max | 8a4d2e7 | 2016-05-17 15:56:49 +0200 | [diff] [blame] | 280 | if (mr->flags & MEAS_REP_F_DL_DTX) { |
| 281 | dlev = MEAS_REP_DL_RXLEV_SUB; |
| 282 | dqual = MEAS_REP_DL_RXQUAL_SUB; |
| 283 | } else { |
| 284 | dlev = MEAS_REP_DL_RXLEV_FULL; |
| 285 | dqual = MEAS_REP_DL_RXQUAL_FULL; |
| 286 | } |
| 287 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 288 | /* parse actual neighbor cell info */ |
| 289 | if (mr->num_cell > 0 && mr->num_cell < 7) |
| 290 | process_meas_neigh(mr); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 291 | |
Max | 8a4d2e7 | 2016-05-17 15:56:49 +0200 | [diff] [blame] | 292 | av_rxlev = get_meas_rep_avg(mr->lchan, dlev, |
Neels Hofmeyr | dd42eb9 | 2018-02-14 19:56:23 +0100 | [diff] [blame] | 293 | ho_get_hodec1_rxlev_avg_win(bts->ho)); |
Harald Welte | e786c32 | 2009-12-19 21:29:19 +0100 | [diff] [blame] | 294 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 295 | /* Interference HO */ |
| 296 | if (rxlev2dbm(av_rxlev) > -85 && |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 297 | meas_rep_n_out_of_m_be(mr->lchan, dqual, 3, 4, 5)) { |
| 298 | LOGPC(DHO, LOGL_INFO, "HO cause: Interference HO av_rxlev=%d dBm\n", |
| 299 | rxlev2dbm(av_rxlev)); |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 300 | attempt_handover(mr); |
| 301 | return; |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 302 | } |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 303 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 304 | /* Bad Quality */ |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 305 | if (meas_rep_n_out_of_m_be(mr->lchan, dqual, 3, 4, 5)) { |
| 306 | LOGPC(DHO, LOGL_INFO, "HO cause: Bad Quality av_rxlev=%d dBm\n", rxlev2dbm(av_rxlev)); |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 307 | attempt_handover(mr); |
| 308 | return; |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 309 | } |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 310 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 311 | /* Low Level */ |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 312 | if (rxlev2dbm(av_rxlev) <= -110) { |
| 313 | LOGPC(DHO, LOGL_INFO, "HO cause: Low Level av_rxlev=%d dBm\n", rxlev2dbm(av_rxlev)); |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 314 | attempt_handover(mr); |
| 315 | return; |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 316 | } |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 317 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 318 | /* Distance */ |
Neels Hofmeyr | dd42eb9 | 2018-02-14 19:56:23 +0100 | [diff] [blame] | 319 | if (mr->ms_l1.ta > ho_get_hodec1_max_distance(bts->ho)) { |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 320 | LOGPC(DHO, LOGL_INFO, "HO cause: Distance av_rxlev=%d dBm ta=%d \n", |
| 321 | rxlev2dbm(av_rxlev), mr->ms_l1.ta); |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 322 | attempt_handover(mr); |
| 323 | return; |
Ivan Kluchnikov | 1c8b4a5 | 2017-08-23 17:51:22 +0300 | [diff] [blame] | 324 | } |
Harald Welte | bc81450 | 2009-12-19 21:41:52 +0100 | [diff] [blame] | 325 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 326 | /* Power Budget AKA Better Cell */ |
Neels Hofmeyr | dd42eb9 | 2018-02-14 19:56:23 +0100 | [diff] [blame] | 327 | pwr_interval = ho_get_hodec1_pwr_interval(bts->ho); |
Neels Hofmeyr | b57ff5a | 2018-02-12 21:16:44 +0100 | [diff] [blame] | 328 | /* handover_cfg.h defines pwr_interval as [1..99], but since we're using it in a modulo below, |
| 329 | * assert non-zero to clarify. */ |
| 330 | OSMO_ASSERT(pwr_interval); |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 331 | if ((mr->nr % pwr_interval) == pwr_interval - 1) |
Neels Hofmeyr | 047ac0d | 2018-02-15 14:12:40 +0100 | [diff] [blame] | 332 | attempt_handover(mr); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Neels Hofmeyr | 45e46d2 | 2018-02-15 14:10:12 +0100 | [diff] [blame] | 335 | struct handover_decision_callbacks hodec1_callbacks = { |
| 336 | .hodec_id = HODEC1, |
| 337 | .on_measurement_report = on_measurement_report, |
| 338 | }; |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 339 | |
Neels Hofmeyr | c561515 | 2017-12-07 01:57:01 +0100 | [diff] [blame] | 340 | void handover_decision_1_init(void) |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 341 | { |
Neels Hofmeyr | 45e46d2 | 2018-02-15 14:10:12 +0100 | [diff] [blame] | 342 | handover_decision_callbacks_register(&hodec1_callbacks); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 343 | } |