blob: 8115d87199d3610c9e90046aaeb367914d108c32 [file] [log] [blame]
Harald Welte8470bf22008-12-25 23:28:35 +00001/* GSM Channel allocation routines
2 *
3 * (C) 2008 by Harald Welte <laforge@gnumonks.org>
Holger Freythere64a7a32009-02-06 21:55:37 +00004 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <errno.h>
28
29#include <openbsc/gsm_data.h>
30#include <openbsc/chan_alloc.h>
Harald Welte4b634542008-12-27 01:55:51 +000031#include <openbsc/abis_nm.h>
Holger Freyther67b4b9a2009-01-01 03:46:11 +000032#include <openbsc/abis_rsl.h>
Holger Freytherc6ea9db2008-12-30 19:18:21 +000033#include <openbsc/debug.h>
Holger Freyther7c19f742009-06-06 13:54:35 +000034#include <openbsc/signal.h>
Holger Freytherc6ea9db2008-12-30 19:18:21 +000035
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +080036#include <osmocore/talloc.h>
37
Harald Weltef85497c2009-01-01 00:33:20 +000038static void auto_release_channel(void *_lchan);
Harald Welte8470bf22008-12-25 23:28:35 +000039
Harald Welte4c704542009-12-24 10:10:16 +010040static int ts_is_usable(struct gsm_bts_trx_ts *ts)
41{
42 /* FIXME: How does this behave for BS-11 ? */
43 if (is_ipaccess_bts(ts->trx->bts)) {
Sylvain Munaut1f6c11f2010-01-02 16:32:17 +010044 if (!nm_is_running(&ts->nm_state))
Harald Welte4c704542009-12-24 10:10:16 +010045 return 0;
46 }
47
48 return 1;
49}
50
Harald Welte (local)82ff3972009-12-28 16:36:28 +010051int trx_is_usable(struct gsm_bts_trx *trx)
Harald Welte4c704542009-12-24 10:10:16 +010052{
53 /* FIXME: How does this behave for BS-11 ? */
54 if (is_ipaccess_bts(trx->bts)) {
Sylvain Munaut1f6c11f2010-01-02 16:32:17 +010055 if (!nm_is_running(&trx->nm_state) ||
56 !nm_is_running(&trx->bb_transc.nm_state))
Harald Welte4c704542009-12-24 10:10:16 +010057 return 0;
58 }
59
60 return 1;
61}
62
Harald Welte8470bf22008-12-25 23:28:35 +000063struct gsm_bts_trx_ts *ts_c0_alloc(struct gsm_bts *bts,
64 enum gsm_phys_chan_config pchan)
65{
Harald Weltee441d9c2009-06-21 16:17:15 +020066 struct gsm_bts_trx *trx = bts->c0;
Harald Welte8470bf22008-12-25 23:28:35 +000067 struct gsm_bts_trx_ts *ts = &trx->ts[0];
68
69 if (pchan != GSM_PCHAN_CCCH &&
70 pchan != GSM_PCHAN_CCCH_SDCCH4)
71 return NULL;
72
73 if (ts->pchan != GSM_PCHAN_NONE)
74 return NULL;
75
76 ts->pchan = pchan;
77
78 return ts;
79}
80
Harald Welte4bfdfe72009-06-10 23:11:52 +080081/* Allocate a physical channel (TS) */
Harald Welte8470bf22008-12-25 23:28:35 +000082struct gsm_bts_trx_ts *ts_alloc(struct gsm_bts *bts,
83 enum gsm_phys_chan_config pchan)
84{
Harald Welte88367262009-08-10 13:25:55 +020085 int j;
86 struct gsm_bts_trx *trx;
87
88 llist_for_each_entry(trx, &bts->trx_list, list) {
Harald Welte75a983f2008-12-27 21:34:06 +000089 int from, to;
90
Harald Welte4c704542009-12-24 10:10:16 +010091 if (!trx_is_usable(trx))
92 continue;
93
Harald Welte75a983f2008-12-27 21:34:06 +000094 /* the following constraints are pure policy,
95 * no requirement to put this restriction in place */
Harald Welted46299d2009-07-29 16:46:37 +020096 if (trx == bts->c0) {
97 /* On the first TRX we run one CCCH and one SDCCH8 */
98 switch (pchan) {
99 case GSM_PCHAN_CCCH:
100 case GSM_PCHAN_CCCH_SDCCH4:
101 from = 0; to = 0;
102 break;
Harald Welted46299d2009-07-29 16:46:37 +0200103 case GSM_PCHAN_TCH_F:
104 case GSM_PCHAN_TCH_H:
Harald Welte89e9d592009-08-09 22:01:26 +0200105 from = 1; to = 7;
Harald Welted46299d2009-07-29 16:46:37 +0200106 break;
Harald Welte89e9d592009-08-09 22:01:26 +0200107 case GSM_PCHAN_SDCCH8_SACCH8C:
Harald Welted46299d2009-07-29 16:46:37 +0200108 default:
109 return NULL;
110 }
111 } else {
112 /* Every secondary TRX is configured for TCH/F
113 * and TCH/H only */
114 switch (pchan) {
Harald Welte89e9d592009-08-09 22:01:26 +0200115 case GSM_PCHAN_SDCCH8_SACCH8C:
116 from = 1; to = 1;
Harald Welted46299d2009-07-29 16:46:37 +0200117 case GSM_PCHAN_TCH_F:
118 case GSM_PCHAN_TCH_H:
Harald Welte89e9d592009-08-09 22:01:26 +0200119 from = 1; to = 7;
Harald Welted46299d2009-07-29 16:46:37 +0200120 break;
121 default:
122 return NULL;
123 }
Harald Welte75a983f2008-12-27 21:34:06 +0000124 }
125
126 for (j = from; j <= to; j++) {
Harald Welte8470bf22008-12-25 23:28:35 +0000127 struct gsm_bts_trx_ts *ts = &trx->ts[j];
Harald Welte4c704542009-12-24 10:10:16 +0100128
129 if (!ts_is_usable(ts))
130 continue;
131
Harald Welte8470bf22008-12-25 23:28:35 +0000132 if (ts->pchan == GSM_PCHAN_NONE) {
133 ts->pchan = pchan;
Harald Welte4b634542008-12-27 01:55:51 +0000134 /* set channel attribute on OML */
Harald Welte21bd3a52009-08-10 12:21:22 +0200135 abis_nm_set_channel_attr(ts, abis_nm_chcomb4pchan(pchan));
Harald Welte8470bf22008-12-25 23:28:35 +0000136 return ts;
137 }
138 }
139 }
140 return NULL;
141}
142
143/* Free a physical channel (TS) */
144void ts_free(struct gsm_bts_trx_ts *ts)
145{
146 ts->pchan = GSM_PCHAN_NONE;
147}
148
149static const u_int8_t subslots_per_pchan[] = {
150 [GSM_PCHAN_NONE] = 0,
151 [GSM_PCHAN_CCCH] = 0,
152 [GSM_PCHAN_CCCH_SDCCH4] = 4,
153 [GSM_PCHAN_TCH_F] = 1,
154 [GSM_PCHAN_TCH_H] = 2,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800155 [GSM_PCHAN_SDCCH8_SACCH8C] = 8,
Harald Welteb908cb72009-12-22 13:09:29 +0100156 /* FIXME: what about dynamic TCH_F_TCH_H ? */
Harald Weltec0d83b02010-03-28 15:58:03 +0800157 [GSM_PCHAN_TCH_F_PDCH] = 1,
Harald Welte8470bf22008-12-25 23:28:35 +0000158};
159
160static struct gsm_lchan *
Harald Weltefc0d9522009-08-10 13:46:55 +0200161_lc_find_trx(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan)
Harald Welte8470bf22008-12-25 23:28:35 +0000162{
Harald Welte8470bf22008-12-25 23:28:35 +0000163 struct gsm_bts_trx_ts *ts;
Harald Welte88367262009-08-10 13:25:55 +0200164 int j, ss;
165
Harald Welte4c704542009-12-24 10:10:16 +0100166 if (!trx_is_usable(trx))
167 return NULL;
168
Harald Weltefc0d9522009-08-10 13:46:55 +0200169 for (j = 0; j < 8; j++) {
170 ts = &trx->ts[j];
Harald Welte4c704542009-12-24 10:10:16 +0100171 if (!ts_is_usable(ts))
172 continue;
Harald Weltec0d83b02010-03-28 15:58:03 +0800173 /* ip.access dynamic TCH/F + PDCH combination */
174 if (ts->pchan == GSM_PCHAN_TCH_F_PDCH &&
175 pchan == GSM_PCHAN_TCH_F) {
176 /* we can only consider such a dynamic channel
177 * if the PDCH is currently inactive */
178 if (ts->flags & TS_F_PDCH_MODE)
179 continue;
180 } else if (ts->pchan != pchan)
Harald Weltefc0d9522009-08-10 13:46:55 +0200181 continue;
182 /* check if all sub-slots are allocated yet */
183 for (ss = 0; ss < subslots_per_pchan[pchan]; ss++) {
184 struct gsm_lchan *lc = &ts->lchan[ss];
Harald Welte (local)3e460312009-12-27 18:12:29 +0100185 if (lc->type == GSM_LCHAN_NONE &&
186 lc->state == LCHAN_S_NONE)
Harald Weltefc0d9522009-08-10 13:46:55 +0200187 return lc;
Harald Welte8470bf22008-12-25 23:28:35 +0000188 }
189 }
Harald Weltec0d83b02010-03-28 15:58:03 +0800190
Harald Weltefc0d9522009-08-10 13:46:55 +0200191 return NULL;
192}
193
194static struct gsm_lchan *
195_lc_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
196{
197 struct gsm_bts_trx *trx;
198 struct gsm_bts_trx_ts *ts;
199 struct gsm_lchan *lc;
200
201 if (bts->chan_alloc_reverse) {
202 llist_for_each_entry_reverse(trx, &bts->trx_list, list) {
203 lc = _lc_find_trx(trx, pchan);
204 if (lc)
205 return lc;
206 }
207 } else {
208 llist_for_each_entry(trx, &bts->trx_list, list) {
209 lc = _lc_find_trx(trx, pchan);
210 if (lc)
211 return lc;
212 }
213 }
214
Harald Welte8470bf22008-12-25 23:28:35 +0000215 /* we cannot allocate more of these */
216 if (pchan == GSM_PCHAN_CCCH_SDCCH4)
217 return NULL;
218
219 /* if we've reached here, we need to allocate a new physical
220 * channel for the logical channel type requested */
221 ts = ts_alloc(bts, pchan);
222 if (!ts) {
223 /* no more radio resources */
224 return NULL;
225 }
226 return &ts->lchan[0];
227}
228
229/* Allocate a logical channel */
230struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type)
231{
232 struct gsm_lchan *lchan = NULL;
Harald Welte65676fe2009-08-10 14:44:24 +0200233 enum gsm_phys_chan_config first, second;
Harald Welte8470bf22008-12-25 23:28:35 +0000234
235 switch (type) {
236 case GSM_LCHAN_SDCCH:
Harald Welte65676fe2009-08-10 14:44:24 +0200237 if (bts->chan_alloc_reverse) {
238 first = GSM_PCHAN_SDCCH8_SACCH8C;
239 second = GSM_PCHAN_CCCH_SDCCH4;
240 } else {
241 first = GSM_PCHAN_CCCH_SDCCH4;
242 second = GSM_PCHAN_SDCCH8_SACCH8C;
243 }
244
245 lchan = _lc_find_bts(bts, first);
Harald Welte8470bf22008-12-25 23:28:35 +0000246 if (lchan == NULL)
Harald Welte65676fe2009-08-10 14:44:24 +0200247 lchan = _lc_find_bts(bts, second);
Harald Welte8470bf22008-12-25 23:28:35 +0000248 break;
249 case GSM_LCHAN_TCH_F:
Harald Weltefc0d9522009-08-10 13:46:55 +0200250 lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
Harald Welte8470bf22008-12-25 23:28:35 +0000251 break;
252 case GSM_LCHAN_TCH_H:
Harald Weltefc0d9522009-08-10 13:46:55 +0200253 lchan =_lc_find_bts(bts, GSM_PCHAN_TCH_H);
Harald Welte210c8502009-12-12 20:58:20 +0100254 /* If we don't have TCH/H available, fall-back to TCH/F */
Harald Welte487e6be2009-12-12 21:16:38 +0100255 if (!lchan) {
Harald Welte210c8502009-12-12 20:58:20 +0100256 lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
Harald Welte487e6be2009-12-12 21:16:38 +0100257 type = GSM_LCHAN_TCH_F;
258 }
Harald Welte8470bf22008-12-25 23:28:35 +0000259 break;
260 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100261 LOGP(DRLL, LOGL_ERROR, "Unknown gsm_chan_t %u\n", type);
Harald Welte8470bf22008-12-25 23:28:35 +0000262 }
263
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000264 if (lchan) {
Harald Welte8470bf22008-12-25 23:28:35 +0000265 lchan->type = type;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000266
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100267 /* clear sapis */
Holger Hans Peter Freyther45b02432009-11-18 22:59:51 +0100268 memset(lchan->sapis, 0, ARRAY_SIZE(lchan->sapis));
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100269
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100270 /* clear multi rate config */
271 memset(&lchan->mr_conf, 0, sizeof(lchan->mr_conf));
272
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100273 /* clear per MSC/BSC data */
274 memset(&lchan->conn, 0, sizeof(lchan->conn));
275
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000276 /* Configure the time and start it so it will be closed */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100277 lchan->conn.lchan = lchan;
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100278 lchan->conn.bts = lchan->ts->trx->bts;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100279 lchan->conn.release_timer.cb = auto_release_channel;
280 lchan->conn.release_timer.data = lchan;
281 bsc_schedule_timer(&lchan->conn.release_timer, LCHAN_RELEASE_TIMEOUT);
282
Harald Weltec0d83b02010-03-28 15:58:03 +0800283 } else {
284 struct challoc_signal_data sig;
285 sig.bts = bts;
286 sig.type = type;
287 dispatch_signal(SS_CHALLOC, S_CHALLOC_ALLOC_FAIL, &sig);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000288 }
Harald Welte8470bf22008-12-25 23:28:35 +0000289
290 return lchan;
291}
292
293/* Free a logical channel */
294void lchan_free(struct gsm_lchan *lchan)
295{
Harald Weltec0d83b02010-03-28 15:58:03 +0800296 struct challoc_signal_data sig;
Harald Welted12b0fd2009-12-15 21:36:05 +0100297 int i;
298
Harald Weltec0d83b02010-03-28 15:58:03 +0800299 sig.type = lchan->type;
Harald Welte8470bf22008-12-25 23:28:35 +0000300 lchan->type = GSM_LCHAN_NONE;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100301 if (lchan->conn.subscr) {
302 subscr_put(lchan->conn.subscr);
303 lchan->conn.subscr = NULL;
Holger Freyther12aa50d2009-01-01 18:02:05 +0000304 }
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000305
Holger Freyther7c19f742009-06-06 13:54:35 +0000306 /* We might kill an active channel... */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100307 if (lchan->conn.use_count != 0) {
Holger Freyther7c19f742009-06-06 13:54:35 +0000308 dispatch_signal(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, lchan);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100309 lchan->conn.use_count = 0;
Harald Weltec627afc2009-01-09 21:39:17 +0000310 }
311
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000312 /* stop the timer */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100313 bsc_del_timer(&lchan->conn.release_timer);
Sylvain Munautf77af1f2009-12-21 01:11:25 +0100314 bsc_del_timer(&lchan->T3101);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000315
Harald Welted12b0fd2009-12-15 21:36:05 +0100316 /* clear cached measuement reports */
317 lchan->meas_rep_idx = 0;
318 for (i = 0; i < ARRAY_SIZE(lchan->meas_rep); i++) {
319 lchan->meas_rep[i].flags = 0;
320 lchan->meas_rep[i].nr = 0;
321 }
Harald Weltef7c28b02009-12-21 13:30:17 +0100322 for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++)
323 lchan->neigh_meas[i].arfcn = 0;
Harald Welted12b0fd2009-12-15 21:36:05 +0100324
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +0800325 if (lchan->rqd_ref) {
326 talloc_free(lchan->rqd_ref);
327 lchan->rqd_ref = NULL;
328 lchan->rqd_ta = 0;
329 }
330
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100331 lchan->conn.silent_call = 0;
Harald Welte83579ca2009-12-29 11:17:18 +0100332
Harald Weltec0d83b02010-03-28 15:58:03 +0800333 sig.lchan = lchan;
334 sig.bts = lchan->ts->trx->bts;
335 dispatch_signal(SS_CHALLOC, S_CHALLOC_FREED, &sig);
336
Harald Welte8470bf22008-12-25 23:28:35 +0000337 /* FIXME: ts_free() the timeslot, if we're the last logical
338 * channel using it */
339}
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000340
Holger Hans Peter Freyther135f7972010-04-15 11:21:02 +0200341/*
342 * There was an error with the TRX and we need to forget
343 * any state so that a lchan can be allocated again after
344 * the trx is fully usable.
Holger Hans Peter Freytherf7a1c232010-06-22 12:19:06 +0800345 *
346 * This should be called after lchan_free to force a channel
347 * be available for allocation again. This means that this
348 * method will stop the "delay after error"-timer and set the
349 * state to LCHAN_S_NONE.
Holger Hans Peter Freyther135f7972010-04-15 11:21:02 +0200350 */
351void lchan_reset(struct gsm_lchan *lchan)
352{
353 bsc_del_timer(&lchan->T3101);
Holger Hans Peter Freytherde4b0a22010-06-08 12:12:26 +0800354 bsc_del_timer(&lchan->T3111);
355 bsc_del_timer(&lchan->error_timer);
Holger Hans Peter Freyther135f7972010-04-15 11:21:02 +0200356
357 lchan->type = GSM_LCHAN_NONE;
358 lchan->state = LCHAN_S_NONE;
359}
360
361
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000362/* Consider releasing the channel now */
363int lchan_auto_release(struct gsm_lchan *lchan)
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000364{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100365 if (lchan->conn.use_count > 0) {
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000366 return 0;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000367 }
368
Holger Freythere64a7a32009-02-06 21:55:37 +0000369 /* Assume we have GSM04.08 running and send a release */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100370 if (lchan->conn.subscr) {
Holger Freythere64a7a32009-02-06 21:55:37 +0000371 gsm48_send_rr_release(lchan);
372 }
373
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000374 /* spoofed? message */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100375 if (lchan->conn.use_count < 0)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100376 LOGP(DRLL, LOGL_ERROR, "Channel count is negative: %d\n",
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100377 lchan->conn.use_count);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000378
Harald Welte (local)0b114142009-12-28 23:22:43 +0100379 DEBUGP(DRLL, "%s Recycling Channel\n", gsm_lchan_name(lchan));
Holger Hans Peter Freyther63d18b52010-04-10 00:14:55 +0200380 rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ);
Holger Hans Peter Freyther4f5848d2010-06-08 11:57:45 +0800381 rsl_release_request(lchan, 0, 0);
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000382 return 1;
383}
384
385/* Auto release the channel when the use count is zero */
386static void auto_release_channel(void *_lchan)
387{
388 struct gsm_lchan *lchan = _lchan;
389
390 if (!lchan_auto_release(lchan))
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100391 bsc_schedule_timer(&lchan->conn.release_timer, LCHAN_RELEASE_TIMEOUT);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000392}
393
Holger Hans Peter Freytherea01ca72010-06-16 13:05:35 +0800394static struct gsm_lchan* lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr) {
Harald Weltee441d9c2009-06-21 16:17:15 +0200395 struct gsm_bts_trx *trx;
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +0200396 int ts_no, lchan_no;
Holger Freytherd0e38c32009-01-04 03:48:30 +0000397
Harald Weltee441d9c2009-06-21 16:17:15 +0200398 llist_for_each_entry(trx, &bts->trx_list, list) {
Holger Freytherd0e38c32009-01-04 03:48:30 +0000399 for (ts_no = 0; ts_no < 8; ++ts_no) {
400 for (lchan_no = 0; lchan_no < TS_MAX_LCHAN; ++lchan_no) {
401 struct gsm_lchan *lchan =
Harald Weltee441d9c2009-06-21 16:17:15 +0200402 &trx->ts[ts_no].lchan[lchan_no];
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100403 if (subscr == lchan->conn.subscr)
Holger Freytherd0e38c32009-01-04 03:48:30 +0000404 return lchan;
405 }
406 }
407 }
408
409 return NULL;
410}
Harald Welte1a6f7982009-08-09 18:52:33 +0200411
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +0800412struct gsm_subscriber_connection *connection_for_subscr(struct gsm_subscriber *subscr)
Harald Welte1a6f7982009-08-09 18:52:33 +0200413{
414 struct gsm_bts *bts;
415 struct gsm_network *net = subscr->net;
416 struct gsm_lchan *lchan;
417
418 llist_for_each_entry(bts, &net->bts_list, list) {
419 lchan = lchan_find(bts, subscr);
420 if (lchan)
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +0800421 return &lchan->conn;
Harald Welte1a6f7982009-08-09 18:52:33 +0200422 }
423
Holger Hans Peter Freytherba925872009-10-27 10:42:53 +0100424 return NULL;
Harald Welte1a6f7982009-08-09 18:52:33 +0200425}
Harald Welteb908cb72009-12-22 13:09:29 +0100426
427void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts)
428{
429 struct gsm_bts_trx *trx;
430
431 llist_for_each_entry(trx, &bts->trx_list, list) {
432 int i;
433
434 /* skip administratively deactivated tranxsceivers */
Sylvain Munaut1f6c11f2010-01-02 16:32:17 +0100435 if (!nm_is_running(&trx->nm_state) ||
436 !nm_is_running(&trx->bb_transc.nm_state))
Harald Welteb908cb72009-12-22 13:09:29 +0100437 continue;
438
439 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
440 struct gsm_bts_trx_ts *ts = &trx->ts[i];
441 struct load_counter *pl = &cl->pchan[ts->pchan];
442 int j;
443
444 /* skip administratively deactivated timeslots */
Sylvain Munaut1f6c11f2010-01-02 16:32:17 +0100445 if (!nm_is_running(&ts->nm_state))
Harald Welteb908cb72009-12-22 13:09:29 +0100446 continue;
447
448 for (j = 0; j < subslots_per_pchan[ts->pchan]; j++) {
449 struct gsm_lchan *lchan = &ts->lchan[j];
450
451 pl->total++;
452
453 switch (lchan->state) {
454 case LCHAN_S_NONE:
455 break;
456 default:
457 pl->used++;
458 break;
459 }
460 }
461 }
462 }
463}
464
465void network_chan_load(struct pchan_load *pl, struct gsm_network *net)
466{
467 struct gsm_bts *bts;
468
469 memset(pl, 0, sizeof(*pl));
470
471 llist_for_each_entry(bts, &net->bts_list, list)
472 bts_chan_load(pl, bts);
473}