Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 1 | /* Measurement Processing */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <errno.h> |
| 24 | |
| 25 | #include <openbsc/msgb.h> |
| 26 | #include <openbsc/debug.h> |
| 27 | #include <openbsc/gsm_data.h> |
| 28 | #include <openbsc/meas_rep.h> |
| 29 | #include <openbsc/signal.h> |
| 30 | #include <openbsc/talloc.h> |
| 31 | |
| 32 | /* process an already parsed measurement report */ |
| 33 | static int process_meas_rep(struct gsm_meas_rep *mr) |
| 34 | { |
| 35 | struct gsm_meas_rep_cell *mr_cell = NULL; |
| 36 | unsigned int best_better_db; |
| 37 | int i; |
| 38 | |
| 39 | /* FIXME: implement actual averaging over multiple measurement |
| 40 | * reports */ |
| 41 | |
| 42 | /* find the best cell in this report that is at least RXLEV_HYST |
| 43 | * better than the current serving cell */ |
| 44 | for (i = 0; i < mr->num_cell; i++) { |
| 45 | unsigned int better; |
| 46 | if (mr->cell[i].rxlev < mr->dl.full.rx_lev + RXLEV_HYST) |
| 47 | continue; |
| 48 | |
| 49 | better = mr->cell[i].rxlev - mr->dl.full.rx_lev; |
| 50 | if (better > best_better_db) { |
| 51 | mr_cell = &mr->cell[i]; |
| 52 | best_better_db = better; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if (mr_cell) |
| 57 | return handover_to_arfcn_bsic(mr->lchan, mr_cell->arfcn, |
| 58 | mr_cell->bsic); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static int meas_proc_sig_cb(unsigned int subsys, unsigned int signal, |
| 63 | void *handler_data, void *signal_data) |
| 64 | { |
| 65 | struct gsm_lchan *lchan; |
| 66 | struct gsm_meas_rep *mr; |
| 67 | |
| 68 | if (subsys != SS_LCHAN) |
| 69 | return 0; |
| 70 | |
| 71 | switch (signal) { |
| 72 | case S_LCHAN_MEAS_REP: |
| 73 | mr = signal_data; |
| 74 | process_meas_rep(mr); |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static __attribute__((constructor)) void on_dso_load_meas(void) |
| 82 | { |
| 83 | register_signal_handler(SS_LCHAN, meas_proc_sig_cb, NULL); |
| 84 | } |