blob: ed81954df3fc2bcf240a61c8157ddbbf33b782d7 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00002 *
Harald Welte52b1f982008-12-23 20:25:15 +00003 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21
22#include <stdlib.h>
23#include <string.h>
24
Harald Welte8470bf22008-12-25 23:28:35 +000025#include <openbsc/gsm_data.h>
Harald Welte52b1f982008-12-23 20:25:15 +000026
Harald Welteb84e2f42008-12-28 23:42:04 +000027struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code,
28 u_int16_t network_code)
Harald Welte52b1f982008-12-23 20:25:15 +000029{
30 int i;
31 struct gsm_network *net;
32
33 if (num_bts > GSM_MAX_BTS)
34 return NULL;
35
36 net = malloc(sizeof(*net));
37 if (!net)
38 return NULL;
39 memset(net, 0, sizeof(*net));
40
41 net->country_code = country_code;
42 net->network_code = network_code;
43 net->num_bts = num_bts;
44
45 for (i = 0; i < num_bts; i++) {
46 struct gsm_bts *bts = &net->bts[i];
47 int j;
48
49 bts->network = net;
50 bts->nr = i;
51
52 for (j = 0; j < BTS_MAX_TRX; j++) {
53 struct gsm_bts_trx *trx = &bts->trx[j];
54 int k;
55
56 trx->bts = bts;
57 trx->nr = j;
58
59 for (k = 0; k < 8; k++) {
60 struct gsm_bts_trx_ts *ts = &trx->ts[k];
Harald Welte8470bf22008-12-25 23:28:35 +000061 int l;
Harald Welte52b1f982008-12-23 20:25:15 +000062
63 ts->trx = trx;
64 ts->nr = k;
Harald Welte8470bf22008-12-25 23:28:35 +000065 ts->pchan = GSM_PCHAN_NONE;
66
67 for (l = 0; l < TS_MAX_LCHAN; l++) {
68 struct gsm_lchan *lchan;
69 lchan = &ts->lchan[l];
70
71 lchan->ts = ts;
72 lchan->nr = l;
73 lchan->type = GSM_LCHAN_NONE;
74 }
Harald Welte52b1f982008-12-23 20:25:15 +000075 }
76 }
77
78 bts->num_trx = 1; /* FIXME */
Harald Welte702d8702008-12-26 20:25:35 +000079 bts->c0 = &bts->trx[0];
80 bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
Harald Welte52b1f982008-12-23 20:25:15 +000081 }
Harald Welte8470bf22008-12-25 23:28:35 +000082 return net;
Harald Welte52b1f982008-12-23 20:25:15 +000083}