Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 2 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3 | * 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 Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 25 | #include <openbsc/gsm_data.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 26 | |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 27 | void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr, |
| 28 | u_int8_t e1_ts, u_int8_t e1_ts_ss) |
| 29 | { |
| 30 | ts->e1_link.e1_nr = e1_nr; |
| 31 | ts->e1_link.e1_ts = e1_ts; |
| 32 | ts->e1_link.e1_ts_ss = e1_ts_ss; |
| 33 | } |
| 34 | |
Harald Welte | a72c98e | 2009-01-04 16:10:38 +0000 | [diff] [blame] | 35 | static const char *pchan_names[] = { |
| 36 | [GSM_PCHAN_NONE] = "NONE", |
| 37 | [GSM_PCHAN_CCCH] = "CCCH", |
| 38 | [GSM_PCHAN_CCCH_SDCCH4] = "CCCH+SDCCH4", |
| 39 | [GSM_PCHAN_TCH_F] = "TCH/F", |
| 40 | [GSM_PCHAN_TCH_H] = "TCH/H", |
| 41 | [GSM_PCHAN_SDCCH8_SACCH8C] = "SDCCH8", |
| 42 | [GSM_PCHAN_UNKNOWN] = "UNKNOWN", |
| 43 | }; |
| 44 | |
| 45 | const char *gsm_pchan_name(enum gsm_phys_chan_config c) |
| 46 | { |
| 47 | if (c >= ARRAY_SIZE(pchan_names)) |
| 48 | return "INVALID"; |
| 49 | |
| 50 | return pchan_names[c]; |
| 51 | } |
| 52 | |
| 53 | static const char *lchan_names[] = { |
| 54 | [GSM_LCHAN_NONE] = "NONE", |
| 55 | [GSM_LCHAN_SDCCH] = "SDCCH", |
| 56 | [GSM_LCHAN_TCH_F] = "TCH/F", |
| 57 | [GSM_LCHAN_TCH_H] = "TCH/H", |
| 58 | [GSM_LCHAN_UNKNOWN] = "UNKNOWN", |
| 59 | }; |
| 60 | |
| 61 | const char *gsm_lchan_name(enum gsm_chan_t c) |
| 62 | { |
| 63 | if (c >= ARRAY_SIZE(lchan_names)) |
| 64 | return "INVALID"; |
| 65 | |
| 66 | return lchan_names[c]; |
| 67 | } |
| 68 | |
| 69 | static const char *chreq_names[] = { |
| 70 | [GSM_CHREQ_REASON_EMERG] = "EMERGENCY", |
| 71 | [GSM_CHREQ_REASON_PAG] = "PAGING", |
| 72 | [GSM_CHREQ_REASON_CALL] = "CALL", |
| 73 | [GSM_CHREQ_REASON_LOCATION_UPD] = "LOCATION_UPDATE", |
| 74 | [GSM_CHREQ_REASON_OTHER] = "OTHER", |
| 75 | }; |
| 76 | |
| 77 | const char *gsm_chreq_name(enum gsm_chreq_reason_t c) |
| 78 | { |
| 79 | if (c >= ARRAY_SIZE(chreq_names)) |
| 80 | return "INVALID"; |
| 81 | |
| 82 | return chreq_names[c]; |
| 83 | } |
| 84 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 85 | struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type, |
| 86 | u_int16_t country_code, u_int16_t network_code) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 87 | { |
| 88 | int i; |
| 89 | struct gsm_network *net; |
| 90 | |
| 91 | if (num_bts > GSM_MAX_BTS) |
| 92 | return NULL; |
| 93 | |
| 94 | net = malloc(sizeof(*net)); |
| 95 | if (!net) |
| 96 | return NULL; |
| 97 | memset(net, 0, sizeof(*net)); |
| 98 | |
| 99 | net->country_code = country_code; |
| 100 | net->network_code = network_code; |
| 101 | net->num_bts = num_bts; |
| 102 | |
| 103 | for (i = 0; i < num_bts; i++) { |
| 104 | struct gsm_bts *bts = &net->bts[i]; |
| 105 | int j; |
| 106 | |
| 107 | bts->network = net; |
| 108 | bts->nr = i; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 109 | bts->type = bts_type; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 110 | |
| 111 | for (j = 0; j < BTS_MAX_TRX; j++) { |
| 112 | struct gsm_bts_trx *trx = &bts->trx[j]; |
| 113 | int k; |
| 114 | |
| 115 | trx->bts = bts; |
| 116 | trx->nr = j; |
| 117 | |
| 118 | for (k = 0; k < 8; k++) { |
| 119 | struct gsm_bts_trx_ts *ts = &trx->ts[k]; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 120 | int l; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 121 | |
| 122 | ts->trx = trx; |
| 123 | ts->nr = k; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 124 | ts->pchan = GSM_PCHAN_NONE; |
| 125 | |
| 126 | for (l = 0; l < TS_MAX_LCHAN; l++) { |
| 127 | struct gsm_lchan *lchan; |
| 128 | lchan = &ts->lchan[l]; |
| 129 | |
| 130 | lchan->ts = ts; |
| 131 | lchan->nr = l; |
| 132 | lchan->type = GSM_LCHAN_NONE; |
| 133 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | bts->num_trx = 1; /* FIXME */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 138 | #ifdef HAVE_TRX1 |
| 139 | bts->num_trx++; |
| 140 | #endif |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 141 | bts->c0 = &bts->trx[0]; |
| 142 | bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 143 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 144 | return net; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 145 | } |
Harald Welte | 23a6863 | 2009-02-19 17:06:42 +0000 | [diff] [blame] | 146 | |
| 147 | static char ts2str[255]; |
| 148 | |
| 149 | char *gsm_ts_name(struct gsm_bts_trx_ts *ts) |
| 150 | { |
| 151 | snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d)", |
| 152 | ts->trx->bts->nr, ts->trx->nr, ts->nr); |
| 153 | |
| 154 | return ts2str; |
| 155 | } |