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 | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 27 | struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code, |
| 28 | u_int16_t network_code) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 29 | { |
| 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 Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 61 | int l; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 62 | |
| 63 | ts->trx = trx; |
| 64 | ts->nr = k; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 65 | 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 Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | bts->num_trx = 1; /* FIXME */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 79 | bts->c0 = &bts->trx[0]; |
| 80 | bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 81 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 82 | return net; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 83 | } |