Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1 | /* GSM Channel allocation routines |
| 2 | * |
| 3 | * (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | e64a7a3 | 2009-02-06 21:55:37 +0000 | [diff] [blame] | 4 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 17 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <errno.h> |
| 27 | |
Neels Hofmeyr | c016479 | 2017-09-04 15:15:32 +0200 | [diff] [blame] | 28 | #include <osmocom/bsc/chan_alloc.h> |
| 29 | #include <osmocom/bsc/abis_nm.h> |
| 30 | #include <osmocom/bsc/abis_rsl.h> |
| 31 | #include <osmocom/bsc/debug.h> |
Neels Hofmeyr | c016479 | 2017-09-04 15:15:32 +0200 | [diff] [blame] | 32 | #include <osmocom/bsc/signal.h> |
| 33 | #include <osmocom/bsc/gsm_04_08_utils.h> |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 34 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 35 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 5ba05f4 | 2010-06-22 12:11:59 +0800 | [diff] [blame] | 36 | |
Andreas Eversberg | 7c41cd1 | 2013-06-02 10:36:53 +0200 | [diff] [blame] | 37 | bool ts_is_usable(const struct gsm_bts_trx_ts *ts) |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 38 | { |
Max | 6e4f184 | 2018-01-07 16:45:42 +0100 | [diff] [blame] | 39 | if (!trx_is_usable(ts->trx)) |
| 40 | return false; |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 41 | |
Neels Hofmeyr | c6926d0 | 2016-07-14 02:51:13 +0200 | [diff] [blame] | 42 | /* If a TCH/F_PDCH TS is busy changing, it is already taken or not |
Neels Hofmeyr | 832afa3 | 2016-06-14 13:12:00 +0200 | [diff] [blame] | 43 | * yet available. */ |
| 44 | if (ts->pchan == GSM_PCHAN_TCH_F_PDCH) { |
| 45 | if (ts->flags & TS_F_PDCH_PENDING_MASK) |
Max | d0ff694 | 2017-11-29 12:45:34 +0100 | [diff] [blame] | 46 | return false; |
Neels Hofmeyr | 832afa3 | 2016-06-14 13:12:00 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 49 | /* If a dynamic channel is busy changing, it is already taken or not |
| 50 | * yet available. */ |
| 51 | if (ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH) { |
| 52 | if (ts->dyn.pchan_is != ts->dyn.pchan_want) |
Max | d0ff694 | 2017-11-29 12:45:34 +0100 | [diff] [blame] | 53 | return false; |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Max | d0ff694 | 2017-11-29 12:45:34 +0100 | [diff] [blame] | 56 | return true; |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Max | d0ff694 | 2017-11-29 12:45:34 +0100 | [diff] [blame] | 59 | bool trx_is_usable(const struct gsm_bts_trx *trx) |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 60 | { |
| 61 | /* FIXME: How does this behave for BS-11 ? */ |
| 62 | if (is_ipaccess_bts(trx->bts)) { |
Harald Welte | d64c0bc | 2011-05-30 12:07:53 +0200 | [diff] [blame] | 63 | if (!nm_is_running(&trx->mo.nm_state) || |
| 64 | !nm_is_running(&trx->bb_transc.mo.nm_state)) |
Max | d0ff694 | 2017-11-29 12:45:34 +0100 | [diff] [blame] | 65 | return false; |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Max | d0ff694 | 2017-11-29 12:45:34 +0100 | [diff] [blame] | 68 | return true; |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Andreas Eversberg | df65c9a | 2013-05-30 10:29:36 +0200 | [diff] [blame] | 71 | static int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan) |
| 72 | { |
| 73 | struct gsm_bts_trx_ts *ts; |
| 74 | int j, ss; |
| 75 | int count = 0; |
| 76 | |
| 77 | if (!trx_is_usable(trx)) |
| 78 | return 0; |
| 79 | |
| 80 | for (j = 0; j < ARRAY_SIZE(trx->ts); j++) { |
| 81 | enum gsm_phys_chan_config ts_pchan_is; |
| 82 | ts = &trx->ts[j]; |
| 83 | if (!ts_is_usable(ts)) |
| 84 | continue; |
| 85 | |
| 86 | ts_pchan_is = ts_pchan(ts); |
| 87 | |
| 88 | if (ts_pchan_is == GSM_PCHAN_PDCH) { |
| 89 | /* Dynamic timeslots in PDCH mode will become TCH if needed. */ |
| 90 | switch (ts->pchan) { |
| 91 | case GSM_PCHAN_TCH_F_PDCH: |
| 92 | if (pchan == GSM_PCHAN_TCH_F) |
| 93 | count++; |
| 94 | continue; |
| 95 | |
| 96 | case GSM_PCHAN_TCH_F_TCH_H_PDCH: |
| 97 | if (pchan == GSM_PCHAN_TCH_F) |
| 98 | count++; |
| 99 | else if (pchan == GSM_PCHAN_TCH_H) |
| 100 | count += 2; |
| 101 | continue; |
| 102 | |
| 103 | default: |
| 104 | /* Not dynamic, not applicable. */ |
| 105 | continue; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (ts_pchan_is != pchan) |
| 110 | continue; |
| 111 | /* check if all sub-slots are allocated yet */ |
| 112 | for (ss = 0; ss < ts_subslots(ts); ss++) { |
| 113 | struct gsm_lchan *lc = &ts->lchan[ss]; |
| 114 | if (lc->type == GSM_LCHAN_NONE && |
| 115 | lc->state == LCHAN_S_NONE) |
| 116 | count++; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return count; |
| 121 | } |
| 122 | |
| 123 | /* Count number of free TS of given pchan type */ |
| 124 | int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan) |
| 125 | { |
| 126 | struct gsm_bts_trx *trx; |
| 127 | int count = 0; |
| 128 | |
| 129 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 130 | count += trx_count_free_ts(trx, pchan); |
| 131 | |
| 132 | return count; |
| 133 | } |
| 134 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 135 | static struct gsm_lchan * |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 136 | _lc_find_trx(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan, |
| 137 | enum gsm_phys_chan_config dyn_as_pchan) |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 138 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 139 | struct gsm_bts_trx_ts *ts; |
Andreas Eversberg | 0434efa | 2013-10-11 13:05:16 +0200 | [diff] [blame] | 140 | int j, start, stop, dir, ss; |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 141 | int check_subslots; |
Harald Welte | 8836726 | 2009-08-10 13:25:55 +0200 | [diff] [blame] | 142 | |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 143 | if (!trx_is_usable(trx)) |
| 144 | return NULL; |
| 145 | |
Andreas Eversberg | 0434efa | 2013-10-11 13:05:16 +0200 | [diff] [blame] | 146 | if (trx->bts->chan_alloc_reverse) { |
| 147 | /* check TS 7..0 */ |
| 148 | start = 7; |
| 149 | stop = -1; |
| 150 | dir = -1; |
| 151 | } else { |
| 152 | /* check TS 0..7 */ |
| 153 | start = 0; |
| 154 | stop = 8; |
| 155 | dir = 1; |
| 156 | } |
| 157 | |
| 158 | for (j = start; j != stop; j += dir) { |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 159 | ts = &trx->ts[j]; |
Harald Welte | 4c70454 | 2009-12-24 10:10:16 +0100 | [diff] [blame] | 160 | if (!ts_is_usable(ts)) |
| 161 | continue; |
Neels Hofmeyr | a668525 | 2016-06-06 12:53:25 +0200 | [diff] [blame] | 162 | if (ts->pchan != pchan) |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 163 | continue; |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Allocation for fully dynamic timeslots |
| 167 | * (does not apply for ip.access style GSM_PCHAN_TCH_F_PDCH) |
| 168 | * |
| 169 | * Note the special nature of a dynamic timeslot in PDCH mode: |
| 170 | * in PDCH mode, typically, lchan->type is GSM_LCHAN_NONE and |
| 171 | * lchan->state is LCHAN_S_NONE -- an otherwise unused slot |
| 172 | * becomes PDCH implicitly. In the same sense, this channel |
| 173 | * allocator will never be asked to find an available PDCH |
| 174 | * slot; only TCH/F or TCH/H will be requested, and PDCH mode |
| 175 | * means that it is available for switchover. |
| 176 | * |
| 177 | * A dynamic timeslot in PDCH mode may be switched to TCH/F or |
| 178 | * TCH/H. If a dyn TS is already in TCH/F or TCH/H mode, it |
| 179 | * means that it is in use and its mode can't be switched. |
| 180 | * |
| 181 | * The logic concerning channels for TCH/F is trivial: there is |
| 182 | * only one channel, so a dynamic TS in TCH/F mode is already |
| 183 | * taken and not available for allocation. For TCH/H, we need |
| 184 | * to check whether a dynamic timeslot is already in TCH/H mode |
| 185 | * and whether one of the two channels is still available. |
| 186 | */ |
Neels Hofmeyr | e14f4b9 | 2016-12-05 16:48:36 +0100 | [diff] [blame] | 187 | switch (pchan) { |
| 188 | case GSM_PCHAN_TCH_F_TCH_H_PDCH: |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 189 | if (ts->dyn.pchan_is != ts->dyn.pchan_want) { |
| 190 | /* The TS's mode is being switched. Not |
| 191 | * available anymore/yet. */ |
| 192 | DEBUGP(DRLL, "%s already in switchover\n", |
| 193 | gsm_ts_and_pchan_name(ts)); |
| 194 | continue; |
| 195 | } |
| 196 | if (ts->dyn.pchan_is == GSM_PCHAN_PDCH) { |
| 197 | /* This slot is available. Still check for |
| 198 | * error states to be sure; in all cases the |
| 199 | * first lchan will be used. */ |
| 200 | if (ts->lchan->state != LCHAN_S_NONE |
| 201 | && ts->lchan->state != LCHAN_S_ACTIVE) |
| 202 | continue; |
| 203 | return ts->lchan; |
| 204 | } |
Neels Hofmeyr | e14f4b9 | 2016-12-05 16:48:36 +0100 | [diff] [blame] | 205 | if (ts->dyn.pchan_is != dyn_as_pchan) |
| 206 | /* not applicable. */ |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 207 | continue; |
Neels Hofmeyr | e14f4b9 | 2016-12-05 16:48:36 +0100 | [diff] [blame] | 208 | /* The requested type matches the dynamic timeslot's |
| 209 | * current mode. A channel may still be available |
| 210 | * (think TCH/H). */ |
| 211 | check_subslots = ts_subslots(ts); |
| 212 | break; |
| 213 | |
Neels Hofmeyr | 8825c69 | 2016-12-05 16:50:47 +0100 | [diff] [blame] | 214 | case GSM_PCHAN_TCH_F_PDCH: |
| 215 | /* Available for voice when in PDCH mode */ |
| 216 | if (ts_pchan(ts) != GSM_PCHAN_PDCH) |
| 217 | continue; |
| 218 | /* Subslots of a PDCH ts don't need to be checked. */ |
| 219 | return ts->lchan; |
| 220 | |
Neels Hofmeyr | e14f4b9 | 2016-12-05 16:48:36 +0100 | [diff] [blame] | 221 | default: |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 222 | /* Not a dynamic channel, there is only one pchan kind: */ |
Neels Hofmeyr | 5486025 | 2016-07-29 18:13:38 +0200 | [diff] [blame] | 223 | check_subslots = ts_subslots(ts); |
Neels Hofmeyr | e14f4b9 | 2016-12-05 16:48:36 +0100 | [diff] [blame] | 224 | break; |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* Is a sub-slot still available? */ |
| 228 | for (ss = 0; ss < check_subslots; ss++) { |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 229 | struct gsm_lchan *lc = &ts->lchan[ss]; |
Harald Welte (local) | 3e46031 | 2009-12-27 18:12:29 +0100 | [diff] [blame] | 230 | if (lc->type == GSM_LCHAN_NONE && |
| 231 | lc->state == LCHAN_S_NONE) |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 232 | return lc; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 235 | |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | static struct gsm_lchan * |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 240 | _lc_dyn_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan, |
| 241 | enum gsm_phys_chan_config dyn_as_pchan) |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 242 | { |
| 243 | struct gsm_bts_trx *trx; |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 244 | struct gsm_lchan *lc; |
| 245 | |
| 246 | if (bts->chan_alloc_reverse) { |
| 247 | llist_for_each_entry_reverse(trx, &bts->trx_list, list) { |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 248 | lc = _lc_find_trx(trx, pchan, dyn_as_pchan); |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 249 | if (lc) |
| 250 | return lc; |
| 251 | } |
| 252 | } else { |
| 253 | llist_for_each_entry(trx, &bts->trx_list, list) { |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 254 | lc = _lc_find_trx(trx, pchan, dyn_as_pchan); |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 255 | if (lc) |
| 256 | return lc; |
| 257 | } |
| 258 | } |
| 259 | |
Harald Welte | f86852c | 2015-01-01 12:46:26 +0100 | [diff] [blame] | 260 | return NULL; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 263 | static struct gsm_lchan * |
| 264 | _lc_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan) |
| 265 | { |
| 266 | return _lc_dyn_find_bts(bts, pchan, GSM_PCHAN_NONE); |
| 267 | } |
| 268 | |
Neels Hofmeyr | a668525 | 2016-06-06 12:53:25 +0200 | [diff] [blame] | 269 | /* Allocate a logical channel. |
| 270 | * |
Neels Hofmeyr | c6926d0 | 2016-07-14 02:51:13 +0200 | [diff] [blame] | 271 | * Dynamic channel types: we always prefer a dedicated TS, and only pick + |
| 272 | * switch a dynamic TS if no pure TS of the requested PCHAN is available. |
| 273 | * |
| 274 | * TCH_F/PDCH: if we pick a PDCH ACT style dynamic TS as TCH/F channel, PDCH |
| 275 | * will be disabled in rsl_chan_activate_lchan(); there is no need to check |
| 276 | * whether PDCH mode is currently active, here. |
Neels Hofmeyr | a668525 | 2016-06-06 12:53:25 +0200 | [diff] [blame] | 277 | */ |
Holger Hans Peter Freyther | 457c2a8 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 278 | struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type, |
| 279 | int allow_bigger) |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 280 | { |
| 281 | struct gsm_lchan *lchan = NULL; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 282 | enum gsm_phys_chan_config first, first_cbch, second, second_cbch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 283 | |
| 284 | switch (type) { |
| 285 | case GSM_LCHAN_SDCCH: |
Harald Welte | 65676fe | 2009-08-10 14:44:24 +0200 | [diff] [blame] | 286 | if (bts->chan_alloc_reverse) { |
| 287 | first = GSM_PCHAN_SDCCH8_SACCH8C; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 288 | first_cbch = GSM_PCHAN_SDCCH8_SACCH8C_CBCH; |
Harald Welte | 65676fe | 2009-08-10 14:44:24 +0200 | [diff] [blame] | 289 | second = GSM_PCHAN_CCCH_SDCCH4; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 290 | second_cbch = GSM_PCHAN_CCCH_SDCCH4_CBCH; |
Harald Welte | 65676fe | 2009-08-10 14:44:24 +0200 | [diff] [blame] | 291 | } else { |
| 292 | first = GSM_PCHAN_CCCH_SDCCH4; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 293 | first_cbch = GSM_PCHAN_CCCH_SDCCH4_CBCH; |
Harald Welte | 65676fe | 2009-08-10 14:44:24 +0200 | [diff] [blame] | 294 | second = GSM_PCHAN_SDCCH8_SACCH8C; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 295 | second_cbch = GSM_PCHAN_SDCCH8_SACCH8C_CBCH; |
Harald Welte | 65676fe | 2009-08-10 14:44:24 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | lchan = _lc_find_bts(bts, first); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 299 | if (lchan == NULL) |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 300 | lchan = _lc_find_bts(bts, first_cbch); |
| 301 | if (lchan == NULL) |
Harald Welte | 65676fe | 2009-08-10 14:44:24 +0200 | [diff] [blame] | 302 | lchan = _lc_find_bts(bts, second); |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 303 | if (lchan == NULL) |
| 304 | lchan = _lc_find_bts(bts, second_cbch); |
Holger Hans Peter Freyther | 457c2a8 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 305 | |
| 306 | /* allow to assign bigger channels */ |
| 307 | if (allow_bigger) { |
| 308 | if (lchan == NULL) { |
| 309 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H); |
Neels Hofmeyr | f5713a5 | 2016-06-06 12:57:22 +0200 | [diff] [blame] | 310 | if (lchan) |
| 311 | type = GSM_LCHAN_TCH_H; |
Holger Hans Peter Freyther | 457c2a8 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | if (lchan == NULL) { |
| 315 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F); |
Neels Hofmeyr | f5713a5 | 2016-06-06 12:57:22 +0200 | [diff] [blame] | 316 | if (lchan) |
| 317 | type = GSM_LCHAN_TCH_F; |
Holger Hans Peter Freyther | 457c2a8 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 318 | } |
Neels Hofmeyr | a668525 | 2016-06-06 12:53:25 +0200 | [diff] [blame] | 319 | |
| 320 | /* try dynamic TCH/F_PDCH */ |
| 321 | if (lchan == NULL) { |
| 322 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F_PDCH); |
| 323 | /* TCH/F_PDCH will be used as TCH/F */ |
| 324 | if (lchan) |
| 325 | type = GSM_LCHAN_TCH_F; |
| 326 | } |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 327 | |
| 328 | /* try fully dynamic TCH/F_TCH/H_PDCH */ |
| 329 | if (lchan == NULL) { |
| 330 | lchan = _lc_dyn_find_bts(bts, GSM_PCHAN_TCH_F_TCH_H_PDCH, |
| 331 | GSM_PCHAN_TCH_H); |
| 332 | if (lchan) |
| 333 | type = GSM_LCHAN_TCH_H; |
| 334 | } |
| 335 | /* |
| 336 | * No need to check fully dynamic channels for TCH/F: |
| 337 | * if no TCH/H was available, neither will be TCH/F. |
| 338 | */ |
Holger Hans Peter Freyther | 457c2a8 | 2010-09-06 08:58:42 +0800 | [diff] [blame] | 339 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 340 | break; |
| 341 | case GSM_LCHAN_TCH_F: |
Harald Welte | fc0d952 | 2009-08-10 13:46:55 +0200 | [diff] [blame] | 342 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F); |
Harald Welte | a4c63b0 | 2014-05-18 22:23:26 +0200 | [diff] [blame] | 343 | /* If we don't have TCH/F available, fall-back to TCH/H */ |
| 344 | if (!lchan) { |
| 345 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H); |
Neels Hofmeyr | f5713a5 | 2016-06-06 12:57:22 +0200 | [diff] [blame] | 346 | if (lchan) |
| 347 | type = GSM_LCHAN_TCH_H; |
Harald Welte | a4c63b0 | 2014-05-18 22:23:26 +0200 | [diff] [blame] | 348 | } |
Neels Hofmeyr | a668525 | 2016-06-06 12:53:25 +0200 | [diff] [blame] | 349 | /* If we don't have TCH/H either, try dynamic TCH/F_PDCH */ |
| 350 | if (!lchan) { |
| 351 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F_PDCH); |
| 352 | /* TCH/F_PDCH used as TCH/F -- here, type is already |
| 353 | * set to GSM_LCHAN_TCH_F, but for clarity's sake... */ |
| 354 | if (lchan) |
| 355 | type = GSM_LCHAN_TCH_F; |
| 356 | } |
Neels Hofmeyr | 5f0c71b | 2016-07-23 20:15:28 +0200 | [diff] [blame] | 357 | |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 358 | /* Try fully dynamic TCH/F_TCH/H_PDCH as TCH/F... */ |
Neels Hofmeyr | 5f0c71b | 2016-07-23 20:15:28 +0200 | [diff] [blame] | 359 | if (!lchan && bts->network->dyn_ts_allow_tch_f) { |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 360 | lchan = _lc_dyn_find_bts(bts, |
| 361 | GSM_PCHAN_TCH_F_TCH_H_PDCH, |
| 362 | GSM_PCHAN_TCH_F); |
| 363 | if (lchan) |
| 364 | type = GSM_LCHAN_TCH_F; |
| 365 | } |
| 366 | /* ...and as TCH/H. */ |
| 367 | if (!lchan) { |
| 368 | lchan = _lc_dyn_find_bts(bts, |
| 369 | GSM_PCHAN_TCH_F_TCH_H_PDCH, |
| 370 | GSM_PCHAN_TCH_H); |
| 371 | if (lchan) |
| 372 | type = GSM_LCHAN_TCH_H; |
| 373 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 374 | break; |
| 375 | case GSM_LCHAN_TCH_H: |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 376 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H); |
Harald Welte | 210c850 | 2009-12-12 20:58:20 +0100 | [diff] [blame] | 377 | /* If we don't have TCH/H available, fall-back to TCH/F */ |
Harald Welte | 487e6be | 2009-12-12 21:16:38 +0100 | [diff] [blame] | 378 | if (!lchan) { |
Harald Welte | 210c850 | 2009-12-12 20:58:20 +0100 | [diff] [blame] | 379 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F); |
Neels Hofmeyr | f5713a5 | 2016-06-06 12:57:22 +0200 | [diff] [blame] | 380 | if (lchan) |
| 381 | type = GSM_LCHAN_TCH_F; |
Harald Welte | 487e6be | 2009-12-12 21:16:38 +0100 | [diff] [blame] | 382 | } |
Neels Hofmeyr | fdd9ad7 | 2016-07-14 03:01:24 +0200 | [diff] [blame] | 383 | /* No dedicated TCH/x available -- try fully dynamic |
| 384 | * TCH/F_TCH/H_PDCH */ |
| 385 | if (!lchan) { |
| 386 | lchan = _lc_dyn_find_bts(bts, |
| 387 | GSM_PCHAN_TCH_F_TCH_H_PDCH, |
| 388 | GSM_PCHAN_TCH_H); |
| 389 | if (lchan) |
| 390 | type = GSM_LCHAN_TCH_H; |
| 391 | } |
| 392 | /* |
| 393 | * No need to check TCH/F_TCH/H_PDCH channels for TCH/F: |
| 394 | * if no TCH/H was available, neither will be TCH/F. |
| 395 | */ |
Neels Hofmeyr | a668525 | 2016-06-06 12:53:25 +0200 | [diff] [blame] | 396 | /* If we don't have TCH/F either, try dynamic TCH/F_PDCH */ |
| 397 | if (!lchan) { |
| 398 | lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F_PDCH); |
| 399 | if (lchan) |
| 400 | type = GSM_LCHAN_TCH_F; |
| 401 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 402 | break; |
| 403 | default: |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 404 | LOGP(DRLL, LOGL_ERROR, "Unknown gsm_chan_t %u\n", type); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 407 | if (lchan) { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 408 | lchan->type = type; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 409 | |
Neels Hofmeyr | d1c0e37 | 2016-07-25 12:33:02 +0200 | [diff] [blame] | 410 | LOGP(DRLL, LOGL_INFO, "%s Allocating lchan=%u as %s\n", |
| 411 | gsm_ts_and_pchan_name(lchan->ts), |
| 412 | lchan->nr, gsm_lchant_name(lchan->type)); |
| 413 | |
Andreas Eversberg | 970b434 | 2013-06-01 16:46:39 +0200 | [diff] [blame] | 414 | /* reset measurement report counter and index */ |
| 415 | lchan->meas_rep_count = 0; |
| 416 | lchan->meas_rep_idx = 0; |
| 417 | |
Holger Hans Peter Freyther | 5ba6f48 | 2009-10-28 14:23:39 +0100 | [diff] [blame] | 418 | /* clear sapis */ |
Holger Hans Peter Freyther | 45b0243 | 2009-11-18 22:59:51 +0100 | [diff] [blame] | 419 | memset(lchan->sapis, 0, ARRAY_SIZE(lchan->sapis)); |
Holger Hans Peter Freyther | 5ba6f48 | 2009-10-28 14:23:39 +0100 | [diff] [blame] | 420 | |
Holger Hans Peter Freyther | ea52802 | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 421 | /* clear multi rate config */ |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 422 | memset(&lchan->mr_ms_lv, 0, sizeof(lchan->mr_ms_lv)); |
| 423 | memset(&lchan->mr_bts_lv, 0, sizeof(lchan->mr_bts_lv)); |
Holger Hans Peter Freyther | 454140e | 2014-12-28 12:08:28 +0100 | [diff] [blame] | 424 | lchan->broken_reason = ""; |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 425 | } else { |
| 426 | struct challoc_signal_data sig; |
Neels Hofmeyr | d1c0e37 | 2016-07-25 12:33:02 +0200 | [diff] [blame] | 427 | |
| 428 | LOGP(DRLL, LOGL_ERROR, "Failed to allocate %s channel\n", |
| 429 | gsm_lchant_name(type)); |
| 430 | |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 431 | sig.bts = bts; |
| 432 | sig.type = type; |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 433 | osmo_signal_dispatch(SS_CHALLOC, S_CHALLOC_ALLOC_FAIL, &sig); |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 434 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 435 | |
| 436 | return lchan; |
| 437 | } |
| 438 | |
| 439 | /* Free a logical channel */ |
| 440 | void lchan_free(struct gsm_lchan *lchan) |
| 441 | { |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 442 | struct challoc_signal_data sig; |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 443 | int i; |
| 444 | |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 445 | sig.type = lchan->type; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 446 | lchan->type = GSM_LCHAN_NONE; |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 447 | |
| 448 | |
| 449 | if (lchan->conn) { |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 450 | struct lchan_signal_data sig; |
| 451 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 452 | /* We might kill an active channel... */ |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 453 | sig.lchan = lchan; |
| 454 | sig.mr = NULL; |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 455 | osmo_signal_dispatch(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, &sig); |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 456 | } |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 457 | |
| 458 | /* stop the timer */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 459 | osmo_timer_del(&lchan->T3101); |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 460 | |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 461 | /* clear cached measuement reports */ |
| 462 | lchan->meas_rep_idx = 0; |
| 463 | for (i = 0; i < ARRAY_SIZE(lchan->meas_rep); i++) { |
| 464 | lchan->meas_rep[i].flags = 0; |
| 465 | lchan->meas_rep[i].nr = 0; |
| 466 | } |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 467 | for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++) |
| 468 | lchan->neigh_meas[i].arfcn = 0; |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 469 | |
Holger Hans Peter Freyther | 5ba05f4 | 2010-06-22 12:11:59 +0800 | [diff] [blame] | 470 | if (lchan->rqd_ref) { |
| 471 | talloc_free(lchan->rqd_ref); |
| 472 | lchan->rqd_ref = NULL; |
| 473 | lchan->rqd_ta = 0; |
| 474 | } |
| 475 | |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 476 | sig.lchan = lchan; |
| 477 | sig.bts = lchan->ts->trx->bts; |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 478 | osmo_signal_dispatch(SS_CHALLOC, S_CHALLOC_FREED, &sig); |
Harald Welte | c0d83b0 | 2010-03-28 15:58:03 +0800 | [diff] [blame] | 479 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 480 | if (lchan->conn) { |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 481 | LOGP(DRLL, LOGL_ERROR, "the subscriber connection should be gone.\n"); |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 482 | lchan->conn = NULL; |
| 483 | } |
| 484 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 485 | /* FIXME: ts_free() the timeslot, if we're the last logical |
| 486 | * channel using it */ |
| 487 | } |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 488 | |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 489 | /* |
| 490 | * There was an error with the TRX and we need to forget |
| 491 | * any state so that a lchan can be allocated again after |
| 492 | * the trx is fully usable. |
Holger Hans Peter Freyther | f7a1c23 | 2010-06-22 12:19:06 +0800 | [diff] [blame] | 493 | * |
| 494 | * This should be called after lchan_free to force a channel |
| 495 | * be available for allocation again. This means that this |
| 496 | * method will stop the "delay after error"-timer and set the |
| 497 | * state to LCHAN_S_NONE. |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 498 | */ |
| 499 | void lchan_reset(struct gsm_lchan *lchan) |
| 500 | { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 501 | osmo_timer_del(&lchan->T3101); |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 502 | osmo_timer_del(&lchan->T3109); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 503 | osmo_timer_del(&lchan->T3111); |
| 504 | osmo_timer_del(&lchan->error_timer); |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 505 | |
| 506 | lchan->type = GSM_LCHAN_NONE; |
Max | dc10ce9 | 2017-09-06 18:20:36 +0200 | [diff] [blame] | 507 | rsl_lchan_set_state(lchan, LCHAN_S_NONE); |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 510 | /* Drive the release process of the lchan */ |
Holger Hans Peter Freyther | 8582535 | 2011-12-27 22:24:17 +0100 | [diff] [blame] | 511 | static void _lchan_handle_release(struct gsm_lchan *lchan, |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 512 | int sacch_deact, int mode) |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 513 | { |
Holger Hans Peter Freyther | 8582535 | 2011-12-27 22:24:17 +0100 | [diff] [blame] | 514 | /* Release all SAPIs on the local end and continue */ |
| 515 | rsl_release_sapis_from(lchan, 1, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 516 | |
Holger Hans Peter Freyther | 8582535 | 2011-12-27 22:24:17 +0100 | [diff] [blame] | 517 | /* |
| 518 | * Shall we send a RR Release, start T3109 and wait for the |
| 519 | * release indication from the BTS or just take it down (e.g. |
| 520 | * on assignment requests) |
| 521 | */ |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 522 | if (sacch_deact) { |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 523 | gsm48_send_rr_release(lchan); |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 524 | |
| 525 | /* Deactivate the SACCH on the BTS side */ |
| 526 | rsl_deact_sacch(lchan); |
| 527 | rsl_start_t3109(lchan); |
Holger Hans Peter Freyther | 006e3d8 | 2012-12-25 23:45:14 +0100 | [diff] [blame] | 528 | } else if (lchan->sapis[0] == LCHAN_SAPI_UNUSED) { |
| 529 | rsl_direct_rf_release(lchan); |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 530 | } else { |
Holger Hans Peter Freyther | 8582535 | 2011-12-27 22:24:17 +0100 | [diff] [blame] | 531 | rsl_release_request(lchan, 0, mode); |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 532 | } |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 533 | } |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 534 | |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 535 | /* Consider releasing the channel now */ |
Holger Hans Peter Freyther | 5ca825e | 2012-12-06 12:01:38 +0100 | [diff] [blame] | 536 | int lchan_release(struct gsm_lchan *lchan, int sacch_deact, enum rsl_rel_mode mode) |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 537 | { |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 538 | DEBUGP(DRLL, "%s starting release sequence\n", gsm_lchan_name(lchan)); |
Holger Hans Peter Freyther | 63d18b5 | 2010-04-10 00:14:55 +0200 | [diff] [blame] | 539 | rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ); |
Holger Hans Peter Freyther | 4b85a32 | 2010-07-29 17:09:36 +0800 | [diff] [blame] | 540 | |
Holger Hans Peter Freyther | abf962b | 2010-11-14 16:04:46 +0100 | [diff] [blame] | 541 | lchan->conn = NULL; |
Holger Hans Peter Freyther | 8582535 | 2011-12-27 22:24:17 +0100 | [diff] [blame] | 542 | _lchan_handle_release(lchan, sacch_deact, mode); |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 543 | return 1; |
| 544 | } |
| 545 | |
Neels Hofmeyr | 2afffd5 | 2016-09-25 17:01:20 +0200 | [diff] [blame] | 546 | void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts) |
Harald Welte | b908cb7 | 2009-12-22 13:09:29 +0100 | [diff] [blame] | 547 | { |
| 548 | struct gsm_bts_trx *trx; |
| 549 | |
| 550 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 551 | int i; |
| 552 | |
| 553 | /* skip administratively deactivated tranxsceivers */ |
Harald Welte | d64c0bc | 2011-05-30 12:07:53 +0200 | [diff] [blame] | 554 | if (!nm_is_running(&trx->mo.nm_state) || |
| 555 | !nm_is_running(&trx->bb_transc.mo.nm_state)) |
Harald Welte | b908cb7 | 2009-12-22 13:09:29 +0100 | [diff] [blame] | 556 | continue; |
| 557 | |
| 558 | for (i = 0; i < ARRAY_SIZE(trx->ts); i++) { |
| 559 | struct gsm_bts_trx_ts *ts = &trx->ts[i]; |
| 560 | struct load_counter *pl = &cl->pchan[ts->pchan]; |
| 561 | int j; |
Neels Hofmeyr | 3673380 | 2016-07-29 18:10:59 +0200 | [diff] [blame] | 562 | int subslots; |
Harald Welte | b908cb7 | 2009-12-22 13:09:29 +0100 | [diff] [blame] | 563 | |
| 564 | /* skip administratively deactivated timeslots */ |
Harald Welte | d64c0bc | 2011-05-30 12:07:53 +0200 | [diff] [blame] | 565 | if (!nm_is_running(&ts->mo.nm_state)) |
Harald Welte | b908cb7 | 2009-12-22 13:09:29 +0100 | [diff] [blame] | 566 | continue; |
| 567 | |
Neels Hofmeyr | 3673380 | 2016-07-29 18:10:59 +0200 | [diff] [blame] | 568 | subslots = ts_subslots(ts); |
| 569 | for (j = 0; j < subslots; j++) { |
Harald Welte | b908cb7 | 2009-12-22 13:09:29 +0100 | [diff] [blame] | 570 | struct gsm_lchan *lchan = &ts->lchan[j]; |
| 571 | |
| 572 | pl->total++; |
| 573 | |
| 574 | switch (lchan->state) { |
| 575 | case LCHAN_S_NONE: |
| 576 | break; |
| 577 | default: |
| 578 | pl->used++; |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | void network_chan_load(struct pchan_load *pl, struct gsm_network *net) |
| 587 | { |
| 588 | struct gsm_bts *bts; |
| 589 | |
| 590 | memset(pl, 0, sizeof(*pl)); |
| 591 | |
| 592 | llist_for_each_entry(bts, &net->bts_list, list) |
Neels Hofmeyr | 2afffd5 | 2016-09-25 17:01:20 +0200 | [diff] [blame] | 593 | bts_chan_load(pl, bts); |
Harald Welte | b908cb7 | 2009-12-22 13:09:29 +0100 | [diff] [blame] | 594 | } |
Neels Hofmeyr | 2afffd5 | 2016-09-25 17:01:20 +0200 | [diff] [blame] | 595 | |