blob: f5c4ec65e1427d10c29d4d54c5a1466461874ff3 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* GSM Channel allocation routines
2 *
3 * (C) 2008 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 *
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>
31#include <openbsc/abis_nm.h>
32#include <openbsc/abis_rsl.h>
33#include <openbsc/debug.h>
34#include <openbsc/signal.h>
35
Holger Hans Peter Freytherc08f6f02010-06-22 12:11:59 +080036#include <osmocore/talloc.h>
37
Harald Welte59b04682009-06-10 05:40:52 +080038static void auto_release_channel(void *_lchan);
39
Harald Welteedc7b2f2009-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 Munautca3e04f2010-01-02 16:32:17 +010044 if (!nm_is_running(&ts->nm_state))
Harald Welteedc7b2f2009-12-24 10:10:16 +010045 return 0;
46 }
47
48 return 1;
49}
50
Harald Welte (local)43db2bf2009-12-28 16:36:28 +010051int trx_is_usable(struct gsm_bts_trx *trx)
Harald Welteedc7b2f2009-12-24 10:10:16 +010052{
53 /* FIXME: How does this behave for BS-11 ? */
54 if (is_ipaccess_bts(trx->bts)) {
Sylvain Munautca3e04f2010-01-02 16:32:17 +010055 if (!nm_is_running(&trx->nm_state) ||
56 !nm_is_running(&trx->bb_transc.nm_state))
Harald Welteedc7b2f2009-12-24 10:10:16 +010057 return 0;
58 }
59
60 return 1;
61}
62
Harald Welte59b04682009-06-10 05:40:52 +080063struct gsm_bts_trx_ts *ts_c0_alloc(struct gsm_bts *bts,
64 enum gsm_phys_chan_config pchan)
65{
Harald Weltee712a5f2009-06-21 16:17:15 +020066 struct gsm_bts_trx *trx = bts->c0;
Harald Welte59b04682009-06-10 05:40:52 +080067 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 Welte03740842009-06-10 23:11:52 +080081/* Allocate a physical channel (TS) */
Harald Welte59b04682009-06-10 05:40:52 +080082struct gsm_bts_trx_ts *ts_alloc(struct gsm_bts *bts,
83 enum gsm_phys_chan_config pchan)
84{
Harald Welte351ff122009-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 Welte59b04682009-06-10 05:40:52 +080089 int from, to;
90
Harald Welteedc7b2f2009-12-24 10:10:16 +010091 if (!trx_is_usable(trx))
92 continue;
93
Harald Welte59b04682009-06-10 05:40:52 +080094 /* the following constraints are pure policy,
95 * no requirement to put this restriction in place */
Harald Welte3a9c2c02009-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 Welte3a9c2c02009-07-29 16:46:37 +0200103 case GSM_PCHAN_TCH_F:
104 case GSM_PCHAN_TCH_H:
Harald Welte7f863f52009-08-09 22:01:26 +0200105 from = 1; to = 7;
Harald Welte3a9c2c02009-07-29 16:46:37 +0200106 break;
Harald Welte7f863f52009-08-09 22:01:26 +0200107 case GSM_PCHAN_SDCCH8_SACCH8C:
Harald Welte3a9c2c02009-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 Welte7f863f52009-08-09 22:01:26 +0200115 case GSM_PCHAN_SDCCH8_SACCH8C:
116 from = 1; to = 1;
Harald Welte3a9c2c02009-07-29 16:46:37 +0200117 case GSM_PCHAN_TCH_F:
118 case GSM_PCHAN_TCH_H:
Harald Welte7f863f52009-08-09 22:01:26 +0200119 from = 1; to = 7;
Harald Welte3a9c2c02009-07-29 16:46:37 +0200120 break;
121 default:
122 return NULL;
123 }
Harald Welte59b04682009-06-10 05:40:52 +0800124 }
125
126 for (j = from; j <= to; j++) {
127 struct gsm_bts_trx_ts *ts = &trx->ts[j];
Harald Welteedc7b2f2009-12-24 10:10:16 +0100128
129 if (!ts_is_usable(ts))
130 continue;
131
Harald Welte59b04682009-06-10 05:40:52 +0800132 if (ts->pchan == GSM_PCHAN_NONE) {
133 ts->pchan = pchan;
134 /* set channel attribute on OML */
Harald Welte35cd5e92009-08-10 12:21:22 +0200135 abis_nm_set_channel_attr(ts, abis_nm_chcomb4pchan(pchan));
Harald Welte59b04682009-06-10 05:40:52 +0800136 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 Welte03740842009-06-10 23:11:52 +0800155 [GSM_PCHAN_SDCCH8_SACCH8C] = 8,
Harald Weltefe96f382009-12-22 13:09:29 +0100156 /* FIXME: what about dynamic TCH_F_TCH_H ? */
Harald Welte8f725442010-03-28 15:58:03 +0800157 [GSM_PCHAN_TCH_F_PDCH] = 1,
Harald Welte59b04682009-06-10 05:40:52 +0800158};
159
160static struct gsm_lchan *
Harald Welteceb3c042009-08-10 13:46:55 +0200161_lc_find_trx(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan)
Harald Welte59b04682009-06-10 05:40:52 +0800162{
Harald Welte59b04682009-06-10 05:40:52 +0800163 struct gsm_bts_trx_ts *ts;
Harald Welte351ff122009-08-10 13:25:55 +0200164 int j, ss;
165
Harald Welteedc7b2f2009-12-24 10:10:16 +0100166 if (!trx_is_usable(trx))
167 return NULL;
168
Harald Welteceb3c042009-08-10 13:46:55 +0200169 for (j = 0; j < 8; j++) {
170 ts = &trx->ts[j];
Harald Welteedc7b2f2009-12-24 10:10:16 +0100171 if (!ts_is_usable(ts))
172 continue;
Harald Welte8f725442010-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 Welteceb3c042009-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)c3be50c2009-12-27 18:12:29 +0100185 if (lc->type == GSM_LCHAN_NONE &&
186 lc->state == LCHAN_S_NONE)
Harald Welteceb3c042009-08-10 13:46:55 +0200187 return lc;
Harald Welte59b04682009-06-10 05:40:52 +0800188 }
189 }
Harald Welte8f725442010-03-28 15:58:03 +0800190
Harald Welteceb3c042009-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 Welte59b04682009-06-10 05:40:52 +0800215 /* 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 Welteaf86c0f2009-08-10 14:44:24 +0200233 enum gsm_phys_chan_config first, second;
Harald Welte59b04682009-06-10 05:40:52 +0800234
235 switch (type) {
236 case GSM_LCHAN_SDCCH:
Harald Welteaf86c0f2009-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 Welte59b04682009-06-10 05:40:52 +0800246 if (lchan == NULL)
Harald Welteaf86c0f2009-08-10 14:44:24 +0200247 lchan = _lc_find_bts(bts, second);
Harald Welte59b04682009-06-10 05:40:52 +0800248 break;
249 case GSM_LCHAN_TCH_F:
Harald Welteceb3c042009-08-10 13:46:55 +0200250 lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
Harald Welte59b04682009-06-10 05:40:52 +0800251 break;
252 case GSM_LCHAN_TCH_H:
Harald Welteceb3c042009-08-10 13:46:55 +0200253 lchan =_lc_find_bts(bts, GSM_PCHAN_TCH_H);
Harald Welte12503372009-12-12 20:58:20 +0100254 /* If we don't have TCH/H available, fall-back to TCH/F */
Harald Welte5ea9e8e2009-12-12 21:16:38 +0100255 if (!lchan) {
Harald Welte12503372009-12-12 20:58:20 +0100256 lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
Harald Welte5ea9e8e2009-12-12 21:16:38 +0100257 type = GSM_LCHAN_TCH_F;
258 }
Harald Welte59b04682009-06-10 05:40:52 +0800259 break;
260 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100261 LOGP(DRLL, LOGL_ERROR, "Unknown gsm_chan_t %u\n", type);
Harald Welte59b04682009-06-10 05:40:52 +0800262 }
263
264 if (lchan) {
265 lchan->type = type;
Harald Welte59b04682009-06-10 05:40:52 +0800266
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +0100267 /* clear sapis */
Holger Hans Peter Freyther29afdc42009-11-18 22:59:51 +0100268 memset(lchan->sapis, 0, ARRAY_SIZE(lchan->sapis));
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +0100269
Holger Hans Peter Freyther3cce58f2009-11-18 22:57:02 +0100270 /* clear multi rate config */
271 memset(&lchan->mr_conf, 0, sizeof(lchan->mr_conf));
272
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100273 /* clear per MSC/BSC data */
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800274 if (lchan->conn) {
275 LOGP(DRLL, LOGL_ERROR, "lchan->conn should be NULL.\n");
276 subscr_con_free(lchan->conn);
277 }
Harald Welte8f725442010-03-28 15:58:03 +0800278 } else {
279 struct challoc_signal_data sig;
280 sig.bts = bts;
281 sig.type = type;
282 dispatch_signal(SS_CHALLOC, S_CHALLOC_ALLOC_FAIL, &sig);
Harald Welte59b04682009-06-10 05:40:52 +0800283 }
284
285 return lchan;
286}
287
288/* Free a logical channel */
289void lchan_free(struct gsm_lchan *lchan)
290{
Harald Welte8f725442010-03-28 15:58:03 +0800291 struct challoc_signal_data sig;
Harald Weltef9476812009-12-15 21:36:05 +0100292 int i;
293
Harald Welte8f725442010-03-28 15:58:03 +0800294 sig.type = lchan->type;
Harald Welte59b04682009-06-10 05:40:52 +0800295 lchan->type = GSM_LCHAN_NONE;
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800296
297
298 if (lchan->conn) {
299 if (lchan->conn->subscr) {
300 subscr_put(lchan->conn->subscr);
301 lchan->conn->subscr = NULL;
302 }
303
304 /* We might kill an active channel... */
305 if (lchan->conn->use_count != 0) {
306 dispatch_signal(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, lchan);
307 lchan->conn->use_count = 0;
308 }
309 /* stop the timer */
310 bsc_del_timer(&lchan->conn->release_timer);
Harald Welte59b04682009-06-10 05:40:52 +0800311 }
312
Harald Welte59b04682009-06-10 05:40:52 +0800313
314 /* stop the timer */
Sylvain Munautfe787f02009-12-21 01:11:25 +0100315 bsc_del_timer(&lchan->T3101);
Harald Welte59b04682009-06-10 05:40:52 +0800316
Harald Weltef9476812009-12-15 21:36:05 +0100317 /* clear cached measuement reports */
318 lchan->meas_rep_idx = 0;
319 for (i = 0; i < ARRAY_SIZE(lchan->meas_rep); i++) {
320 lchan->meas_rep[i].flags = 0;
321 lchan->meas_rep[i].nr = 0;
322 }
Harald Welte92d88912009-12-21 13:30:17 +0100323 for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++)
324 lchan->neigh_meas[i].arfcn = 0;
Harald Weltef9476812009-12-15 21:36:05 +0100325
Holger Hans Peter Freytherc08f6f02010-06-22 12:11:59 +0800326 if (lchan->rqd_ref) {
327 talloc_free(lchan->rqd_ref);
328 lchan->rqd_ref = NULL;
329 lchan->rqd_ta = 0;
330 }
331
Harald Welte8f725442010-03-28 15:58:03 +0800332 sig.lchan = lchan;
333 sig.bts = lchan->ts->trx->bts;
334 dispatch_signal(SS_CHALLOC, S_CHALLOC_FREED, &sig);
335
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800336 if (lchan->conn) {
337 subscr_con_free(lchan->conn);
338 lchan->conn = NULL;
339 }
340
Harald Welte59b04682009-06-10 05:40:52 +0800341 /* FIXME: ts_free() the timeslot, if we're the last logical
342 * channel using it */
343}
344
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200345/*
346 * There was an error with the TRX and we need to forget
347 * any state so that a lchan can be allocated again after
348 * the trx is fully usable.
Holger Hans Peter Freyther66a3c772010-06-22 12:19:06 +0800349 *
350 * This should be called after lchan_free to force a channel
351 * be available for allocation again. This means that this
352 * method will stop the "delay after error"-timer and set the
353 * state to LCHAN_S_NONE.
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200354 */
355void lchan_reset(struct gsm_lchan *lchan)
356{
357 bsc_del_timer(&lchan->T3101);
Holger Hans Peter Freytherfb036222010-06-08 12:12:26 +0800358 bsc_del_timer(&lchan->T3111);
359 bsc_del_timer(&lchan->error_timer);
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200360
361 lchan->type = GSM_LCHAN_NONE;
362 lchan->state = LCHAN_S_NONE;
363}
364
365
Harald Welte59b04682009-06-10 05:40:52 +0800366/* Consider releasing the channel now */
367int lchan_auto_release(struct gsm_lchan *lchan)
368{
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800369 if (!lchan->conn)
370 return 0;
371
372 if (lchan->conn->use_count > 0) {
Harald Welte59b04682009-06-10 05:40:52 +0800373 return 0;
374 }
375
376 /* Assume we have GSM04.08 running and send a release */
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800377 if (lchan->conn->subscr) {
Harald Welte59b04682009-06-10 05:40:52 +0800378 gsm48_send_rr_release(lchan);
379 }
380
381 /* spoofed? message */
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800382 if (lchan->conn->use_count < 0)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100383 LOGP(DRLL, LOGL_ERROR, "Channel count is negative: %d\n",
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800384 lchan->conn->use_count);
Harald Welte59b04682009-06-10 05:40:52 +0800385
Harald Welte (local)0a77fa12009-12-28 23:22:43 +0100386 DEBUGP(DRLL, "%s Recycling Channel\n", gsm_lchan_name(lchan));
Holger Hans Peter Freyther79a62f42010-04-10 00:14:55 +0200387 rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ);
Holger Hans Peter Freytherbcea9a72010-06-08 11:57:45 +0800388 rsl_release_request(lchan, 0, 0);
Harald Welte59b04682009-06-10 05:40:52 +0800389 return 1;
390}
391
392/* Auto release the channel when the use count is zero */
393static void auto_release_channel(void *_lchan)
394{
395 struct gsm_lchan *lchan = _lchan;
396
397 if (!lchan_auto_release(lchan))
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800398 bsc_schedule_timer(&lchan->conn->release_timer, LCHAN_RELEASE_TIMEOUT);
Harald Welte59b04682009-06-10 05:40:52 +0800399}
400
Holger Hans Peter Freyther8bf60d42010-06-16 13:05:35 +0800401static struct gsm_lchan* lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr) {
Harald Weltee712a5f2009-06-21 16:17:15 +0200402 struct gsm_bts_trx *trx;
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +0200403 int ts_no, lchan_no;
Harald Welte59b04682009-06-10 05:40:52 +0800404
Harald Weltee712a5f2009-06-21 16:17:15 +0200405 llist_for_each_entry(trx, &bts->trx_list, list) {
Harald Welte59b04682009-06-10 05:40:52 +0800406 for (ts_no = 0; ts_no < 8; ++ts_no) {
407 for (lchan_no = 0; lchan_no < TS_MAX_LCHAN; ++lchan_no) {
408 struct gsm_lchan *lchan =
Harald Weltee712a5f2009-06-21 16:17:15 +0200409 &trx->ts[ts_no].lchan[lchan_no];
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800410 if (lchan->conn && subscr == lchan->conn->subscr)
Harald Welte59b04682009-06-10 05:40:52 +0800411 return lchan;
412 }
413 }
414 }
415
416 return NULL;
417}
Harald Welteaa60edb2009-08-09 18:52:33 +0200418
Holger Hans Peter Freyther2f4af772010-06-16 13:23:55 +0800419struct gsm_subscriber_connection *connection_for_subscr(struct gsm_subscriber *subscr)
Harald Welteaa60edb2009-08-09 18:52:33 +0200420{
421 struct gsm_bts *bts;
422 struct gsm_network *net = subscr->net;
423 struct gsm_lchan *lchan;
424
425 llist_for_each_entry(bts, &net->bts_list, list) {
426 lchan = lchan_find(bts, subscr);
427 if (lchan)
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800428 return lchan->conn;
Harald Welteaa60edb2009-08-09 18:52:33 +0200429 }
430
Holger Hans Peter Freyther3265b1a2009-10-27 10:42:53 +0100431 return NULL;
Harald Welteaa60edb2009-08-09 18:52:33 +0200432}
Harald Weltefe96f382009-12-22 13:09:29 +0100433
434void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts)
435{
436 struct gsm_bts_trx *trx;
437
438 llist_for_each_entry(trx, &bts->trx_list, list) {
439 int i;
440
441 /* skip administratively deactivated tranxsceivers */
Sylvain Munautca3e04f2010-01-02 16:32:17 +0100442 if (!nm_is_running(&trx->nm_state) ||
443 !nm_is_running(&trx->bb_transc.nm_state))
Harald Weltefe96f382009-12-22 13:09:29 +0100444 continue;
445
446 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
447 struct gsm_bts_trx_ts *ts = &trx->ts[i];
448 struct load_counter *pl = &cl->pchan[ts->pchan];
449 int j;
450
451 /* skip administratively deactivated timeslots */
Sylvain Munautca3e04f2010-01-02 16:32:17 +0100452 if (!nm_is_running(&ts->nm_state))
Harald Weltefe96f382009-12-22 13:09:29 +0100453 continue;
454
455 for (j = 0; j < subslots_per_pchan[ts->pchan]; j++) {
456 struct gsm_lchan *lchan = &ts->lchan[j];
457
458 pl->total++;
459
460 switch (lchan->state) {
461 case LCHAN_S_NONE:
462 break;
463 default:
464 pl->used++;
465 break;
466 }
467 }
468 }
469 }
470}
471
472void network_chan_load(struct pchan_load *pl, struct gsm_network *net)
473{
474 struct gsm_bts *bts;
475
476 memset(pl, 0, sizeof(*pl));
477
478 llist_for_each_entry(bts, &net->bts_list, list)
479 bts_chan_load(pl, bts);
480}
Holger Hans Peter Freyther1a95fa82010-06-28 15:47:12 +0800481
482struct gsm_subscriber_connection *subscr_con_allocate(struct gsm_lchan *lchan)
483{
484 struct gsm_subscriber_connection *conn;
485
486 conn = talloc_zero(lchan->ts->trx->bts, struct gsm_subscriber_connection);
487 if (!conn)
488 return NULL;
489
490 /* Configure the time and start it so it will be closed */
491 conn->lchan = lchan;
492 conn->bts = lchan->ts->trx->bts;
493 conn->release_timer.cb = auto_release_channel;
494 conn->release_timer.data = lchan;
495 bsc_schedule_timer(&conn->release_timer, LCHAN_RELEASE_TIMEOUT);
496
497 lchan->conn = conn;
498 return conn;
499}
500
501/* TODO: move subscriber put here... */
502void subscr_con_free(struct gsm_subscriber_connection *conn)
503{
504 struct gsm_lchan *lchan;
505
506
507 if (!conn)
508 return;
509
510 lchan = conn->lchan;
511 talloc_free(conn);
512
513 if (lchan)
514 lchan->conn = NULL;
515}