blob: def7ffffa41a6752b8779e15fcc29e1796a3f7e4 [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 Weltea72c98e2009-01-04 16:10:38 +000027static const char *pchan_names[] = {
28 [GSM_PCHAN_NONE] = "NONE",
29 [GSM_PCHAN_CCCH] = "CCCH",
30 [GSM_PCHAN_CCCH_SDCCH4] = "CCCH+SDCCH4",
31 [GSM_PCHAN_TCH_F] = "TCH/F",
32 [GSM_PCHAN_TCH_H] = "TCH/H",
33 [GSM_PCHAN_SDCCH8_SACCH8C] = "SDCCH8",
34 [GSM_PCHAN_UNKNOWN] = "UNKNOWN",
35};
36
37const char *gsm_pchan_name(enum gsm_phys_chan_config c)
38{
39 if (c >= ARRAY_SIZE(pchan_names))
40 return "INVALID";
41
42 return pchan_names[c];
43}
44
45static const char *lchan_names[] = {
46 [GSM_LCHAN_NONE] = "NONE",
47 [GSM_LCHAN_SDCCH] = "SDCCH",
48 [GSM_LCHAN_TCH_F] = "TCH/F",
49 [GSM_LCHAN_TCH_H] = "TCH/H",
50 [GSM_LCHAN_UNKNOWN] = "UNKNOWN",
51};
52
53const char *gsm_lchan_name(enum gsm_chan_t c)
54{
55 if (c >= ARRAY_SIZE(lchan_names))
56 return "INVALID";
57
58 return lchan_names[c];
59}
60
61static const char *chreq_names[] = {
62 [GSM_CHREQ_REASON_EMERG] = "EMERGENCY",
63 [GSM_CHREQ_REASON_PAG] = "PAGING",
64 [GSM_CHREQ_REASON_CALL] = "CALL",
65 [GSM_CHREQ_REASON_LOCATION_UPD] = "LOCATION_UPDATE",
66 [GSM_CHREQ_REASON_OTHER] = "OTHER",
67};
68
69const char *gsm_chreq_name(enum gsm_chreq_reason_t c)
70{
71 if (c >= ARRAY_SIZE(chreq_names))
72 return "INVALID";
73
74 return chreq_names[c];
75}
76
Harald Welteb84e2f42008-12-28 23:42:04 +000077struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code,
78 u_int16_t network_code)
Harald Welte52b1f982008-12-23 20:25:15 +000079{
80 int i;
81 struct gsm_network *net;
82
83 if (num_bts > GSM_MAX_BTS)
84 return NULL;
85
86 net = malloc(sizeof(*net));
87 if (!net)
88 return NULL;
89 memset(net, 0, sizeof(*net));
90
91 net->country_code = country_code;
92 net->network_code = network_code;
93 net->num_bts = num_bts;
94
95 for (i = 0; i < num_bts; i++) {
96 struct gsm_bts *bts = &net->bts[i];
97 int j;
98
99 bts->network = net;
100 bts->nr = i;
101
102 for (j = 0; j < BTS_MAX_TRX; j++) {
103 struct gsm_bts_trx *trx = &bts->trx[j];
104 int k;
105
106 trx->bts = bts;
107 trx->nr = j;
108
109 for (k = 0; k < 8; k++) {
110 struct gsm_bts_trx_ts *ts = &trx->ts[k];
Harald Welte8470bf22008-12-25 23:28:35 +0000111 int l;
Harald Welte52b1f982008-12-23 20:25:15 +0000112
113 ts->trx = trx;
114 ts->nr = k;
Harald Welte8470bf22008-12-25 23:28:35 +0000115 ts->pchan = GSM_PCHAN_NONE;
116
117 for (l = 0; l < TS_MAX_LCHAN; l++) {
118 struct gsm_lchan *lchan;
119 lchan = &ts->lchan[l];
120
121 lchan->ts = ts;
122 lchan->nr = l;
123 lchan->type = GSM_LCHAN_NONE;
124 }
Harald Welte52b1f982008-12-23 20:25:15 +0000125 }
126 }
127
128 bts->num_trx = 1; /* FIXME */
Harald Welte702d8702008-12-26 20:25:35 +0000129 bts->c0 = &bts->trx[0];
130 bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
Harald Welte52b1f982008-12-23 20:25:15 +0000131 }
Harald Welte8470bf22008-12-25 23:28:35 +0000132 return net;
Harald Welte52b1f982008-12-23 20:25:15 +0000133}