blob: 38fa5c45f377aa06f62bd60dd5e883d4a5b2a15a [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* A hackish minimal BSC (+MSC +HLR) implementation */
2
Harald Welte32201c12009-03-10 12:15:10 +00003/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Holger Freyther219518d2009-01-02 22:04:43 +00004 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte52b1f982008-12-23 20:25:15 +00005 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
Harald Weltef6b7a902008-12-26 00:05:11 +000023#include <unistd.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <stdarg.h>
27#include <time.h>
28#include <string.h>
Harald Weltead384642008-12-26 10:20:07 +000029#include <errno.h>
Harald Welted1252502009-01-01 01:50:32 +000030#include <signal.h>
Holger Freyther9a3ee0f2009-01-02 00:40:15 +000031#include <fcntl.h>
32#include <sys/stat.h>
Harald Welte52b1f982008-12-23 20:25:15 +000033
Holger Freytherb332f612008-12-27 12:46:51 +000034#define _GNU_SOURCE
35#include <getopt.h>
36
Harald Welte255539c2008-12-28 02:26:27 +000037#include <openbsc/db.h>
38#include <openbsc/timer.h>
Harald Welte8470bf22008-12-25 23:28:35 +000039#include <openbsc/gsm_data.h>
Harald Welte255539c2008-12-28 02:26:27 +000040#include <openbsc/gsm_04_08.h>
Harald Weltead384642008-12-26 10:20:07 +000041#include <openbsc/select.h>
Harald Welte8470bf22008-12-25 23:28:35 +000042#include <openbsc/abis_rsl.h>
43#include <openbsc/abis_nm.h>
Harald Welte702d8702008-12-26 20:25:35 +000044#include <openbsc/debug.h>
Holger Freyther5677ae32008-12-27 09:41:03 +000045#include <openbsc/misdn.h>
Holger Freyther219518d2009-01-02 22:04:43 +000046#include <openbsc/telnet_interface.h>
Harald Welte38c2f132009-01-06 23:10:57 +000047#include <openbsc/paging.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000048#include <openbsc/e1_input.h>
Harald Welte52b1f982008-12-23 20:25:15 +000049
50/* global pointer to the gsm network data structure */
51static struct gsm_network *gsmnet;
52
Holger Freytherefde7fb2008-12-28 14:14:56 +000053/* MCC and MNC for the Location Area Identifier */
54static int MCC = 1;
55static int MNC = 1;
Holger Freyther0a173bf2009-04-22 22:07:07 +000056static int LAC = 1;
Harald Welte98981882009-01-06 18:59:11 +000057static int ARFCN = HARDCODED_ARFCN;
Holger Freytherdda22c12009-04-22 22:07:31 +000058static int cardnr = 0;
Harald Welte8c1d0e42009-02-15 03:38:12 +000059static enum gsm_bts_type BTS_TYPE = GSM_BTS_TYPE_BS11;
Holger Freytherbde36102008-12-28 22:51:39 +000060static const char *database_name = "hlr.sqlite3";
Holger Freytherefde7fb2008-12-28 14:14:56 +000061
Harald Welte52b1f982008-12-23 20:25:15 +000062/* The following definitions are for OM and NM packets that we cannot yet
63 * generate by code but we just pass on */
64
65// BTS Site Manager, SET ATTRIBUTES
66
67/*
68 Object Class: BTS Site Manager
69 Instance 1: FF
70 Instance 2: FF
71 Instance 3: FF
72SET ATTRIBUTES
73 sAbisExternalTime: 2007/09/08 14:36:11
74 omLAPDRelTimer: 30sec
75 shortLAPDIntTimer: 5sec
76 emergencyTimer1: 10 minutes
77 emergencyTimer2: 0 minutes
78*/
79
80unsigned char msg_1[] =
81{
Harald Weltecd993872009-02-15 16:16:28 +000082 0xD0, 0x00, 0xFF, 0xFF, 0xFF,
83 NM_ATT_BS11_ABIS_EXT_TIME, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE,
84 0x02, 0x00, 0x1E,
85 0xE8, 0x01, 0x05,
86 0x42, 0x02, 0x00, 0x0A,
87 0x44, 0x02, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +000088};
89
90// BTS, SET BTS ATTRIBUTES
91
92/*
93 Object Class: BTS
94 BTS relat. Number: 0
95 Instance 2: FF
96 Instance 3: FF
97SET BTS ATTRIBUTES
98 bsIdentityCode / BSIC:
99 PLMN_colour_code: 7h
100 BS_colour_code: 7h
101 BTS Air Timer T3105: 4 ,unit 10 ms
102 btsIsHopping: FALSE
Harald Welte83282292009-02-01 16:22:19 +0000103 periodCCCHLoadIndication: 1sec
Holger Freyther3b910432009-02-11 00:43:48 +0000104 thresholdCCCHLoadIndication: 0%
Harald Welte52b1f982008-12-23 20:25:15 +0000105 cellAllocationNumber: 00h = GSM 900
106 enableInterferenceClass: 00h = Disabled
107 fACCHQual: 6 (FACCH stealing flags minus 1)
108 intaveParameter: 31 SACCH multiframes
109 interferenceLevelBoundaries:
110 Interference Boundary 1: 0Ah
111 Interference Boundary 2: 0Fh
112 Interference Boundary 3: 14h
113 Interference Boundary 4: 19h
114 Interference Boundary 5: 1Eh
115 mSTxPwrMax: 11
116 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
117 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
118 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
119 30=33dBm, 31=32dBm
120 ny1:
121 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
122 powerOutputThresholds:
123 Out Power Fault Threshold: -10 dB
124 Red Out Power Threshold: - 6 dB
125 Excessive Out Power Threshold: 5 dB
126 rACHBusyThreshold: -127 dBm
127 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
128 rfResourceIndicationPeriod: 125 SACCH multiframes
129 T200:
130 SDCCH: 044 in 5 ms
131 FACCH/Full rate: 031 in 5 ms
132 FACCH/Half rate: 041 in 5 ms
133 SACCH with TCH SAPI0: 090 in 10 ms
134 SACCH with SDCCH: 090 in 10 ms
135 SDCCH with SAPI3: 090 in 5 ms
136 SACCH with TCH SAPI3: 135 in 10 ms
137 tSync: 9000 units of 10 msec
138 tTrau: 9000 units of 10 msec
139 enableUmLoopTest: 00h = disabled
140 enableExcessiveDistance: 00h = Disabled
141 excessiveDistance: 64km
142 hoppingMode: 00h = baseband hopping
143 cellType: 00h = Standard Cell
144 BCCH ARFCN / bCCHFrequency: 1
145*/
146
147unsigned char msg_2[] =
148{
Harald Welte8c1d0e42009-02-15 03:38:12 +0000149 0x41, 0x01, 0x00, 0xFF, 0xFF,
150 NM_ATT_BSIC, 0x3F,
151 NM_ATT_BTS_AIR_TIMER, 0x04,
Harald Weltecd993872009-02-15 16:16:28 +0000152 NM_ATT_BS11_BTSLS_HOPPING, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000153 NM_ATT_CCCH_L_I_P, 0x01,
154 NM_ATT_CCCH_L_T, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000155 NM_ATT_BS11_CELL_ALLOC_NR, 0x00,
156 NM_ATT_BS11_ENA_INTERF_CLASS, 0x00,
157 NM_ATT_BS11_FACCH_QUAL, 0x06,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000158 NM_ATT_INTAVE_PARAM, 0x1F,
159 NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B,
160 NM_ATT_CCCH_L_T, 0x23,
161 NM_ATT_GSM_TIME, 0x28, 0x00,
162 NM_ATT_ADM_STATE, 0x03,
163 NM_ATT_RACH_B_THRESH, 0x7F,
164 NM_ATT_LDAVG_SLOTS, 0x00, 0xFA,
Harald Weltecd993872009-02-15 16:16:28 +0000165 NM_ATT_BS11_RF_RES_IND_PER, 0x7D,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000166 NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87,
Harald Weltecd993872009-02-15 16:16:28 +0000167 NM_ATT_BS11_TSYNC, 0x23, 0x28,
168 NM_ATT_BS11_TTRAU, 0x23, 0x28,
169 NM_ATT_TEST_DUR, 0x01, 0x00,
170 NM_ATT_OUTST_ALARM, 0x01, 0x00,
171 NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40,
172 NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00,
173 NM_ATT_BS11_PLL, 0x01, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000174 NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/,
Harald Welte52b1f982008-12-23 20:25:15 +0000175};
176
177// Handover Recognition, SET ATTRIBUTES
178
179/*
180Illegal Contents GSM Formatted O&M Msg
181 Object Class: Handover Recognition
182 BTS relat. Number: 0
183 Instance 2: FF
184 Instance 3: FF
185SET ATTRIBUTES
186 enableDelayPowerBudgetHO: 00h = Disabled
187 enableDistanceHO: 00h = Disabled
188 enableInternalInterCellHandover: 00h = Disabled
189 enableInternalIntraCellHandover: 00h = Disabled
190 enablePowerBudgetHO: 00h = Disabled
191 enableRXLEVHO: 00h = Disabled
192 enableRXQUALHO: 00h = Disabled
193 hoAveragingDistance: 8 SACCH multiframes
194 hoAveragingLev:
195 A_LEV_HO: 8 SACCH multiframes
196 W_LEV_HO: 1 SACCH multiframes
197 hoAveragingPowerBudget: 16 SACCH multiframes
198 hoAveragingQual:
199 A_QUAL_HO: 8 SACCH multiframes
200 W_QUAL_HO: 2 SACCH multiframes
201 hoLowerThresholdLevDL: (10 - 110) dBm
202 hoLowerThresholdLevUL: (5 - 110) dBm
203 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
204 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
205 hoThresholdLevDLintra : (20 - 110) dBm
206 hoThresholdLevULintra: (20 - 110) dBm
207 hoThresholdMsRangeMax: 20 km
208 nCell: 06h
209 timerHORequest: 3 ,unit 2 SACCH multiframes
210*/
211
212unsigned char msg_3[] =
213{
Harald Weltecd993872009-02-15 16:16:28 +0000214 0xD0, 0xA1, 0x00, 0xFF, 0xFF,
215 0xD0, 0x00,
216 0x64, 0x00,
217 0x67, 0x00,
218 0x68, 0x00,
219 0x6A, 0x00,
220 0x6C, 0x00,
221 0x6D, 0x00,
222 0x6F, 0x08,
223 0x70, 0x08, 0x01,
224 0x71, 0x10, 0x10, 0x10,
225 0x72, 0x08, 0x02,
226 0x73, 0x0A,
227 0x74, 0x05,
228 0x75, 0x06,
229 0x76, 0x06,
230 0x78, 0x14,
231 0x79, 0x14,
232 0x7A, 0x14,
233 0x7D, 0x06,
234 0x92, 0x03, 0x20, 0x01, 0x00,
235 0x45, 0x01, 0x00,
236 0x48, 0x01, 0x00,
237 0x5A, 0x01, 0x00,
238 0x5B, 0x01, 0x05,
239 0x5E, 0x01, 0x1A,
240 0x5F, 0x01, 0x20,
241 0x9D, 0x01, 0x00,
242 0x47, 0x01, 0x00,
243 0x5C, 0x01, 0x64,
244 0x5D, 0x01, 0x1E,
245 0x97, 0x01, 0x20,
246 0xF7, 0x01, 0x3C,
Harald Welte52b1f982008-12-23 20:25:15 +0000247};
248
249// Power Control, SET ATTRIBUTES
250
251/*
252 Object Class: Power Control
253 BTS relat. Number: 0
254 Instance 2: FF
255 Instance 3: FF
256SET ATTRIBUTES
257 enableMsPowerControl: 00h = Disabled
258 enablePowerControlRLFW: 00h = Disabled
259 pcAveragingLev:
260 A_LEV_PC: 4 SACCH multiframes
261 W_LEV_PC: 1 SACCH multiframes
262 pcAveragingQual:
263 A_QUAL_PC: 4 SACCH multiframes
264 W_QUAL_PC: 2 SACCH multiframes
265 pcLowerThresholdLevDL: 0Fh
266 pcLowerThresholdLevUL: 0Ah
267 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
268 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
269 pcRLFThreshold: 0Ch
270 pcUpperThresholdLevDL: 14h
271 pcUpperThresholdLevUL: 0Fh
272 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
273 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
274 powerConfirm: 2 ,unit 2 SACCH multiframes
275 powerControlInterval: 2 ,unit 2 SACCH multiframes
276 powerIncrStepSize: 02h = 4 dB
277 powerRedStepSize: 01h = 2 dB
278 radioLinkTimeoutBs: 64 SACCH multiframes
279 enableBSPowerControl: 00h = disabled
280*/
281
282unsigned char msg_4[] =
283{
Harald Weltecd993872009-02-15 16:16:28 +0000284 0xD0, 0xA2, 0x00, 0xFF, 0xFF,
285 NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00,
286 NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00,
287 0x7E, 0x04, 0x01,
288 0x7F, 0x04, 0x02,
289 0x80, 0x0F,
290 0x81, 0x0A,
291 0x82, 0x05,
292 0x83, 0x05,
293 0x84, 0x0C,
294 0x85, 0x14,
295 0x86, 0x0F,
296 0x87, 0x04,
297 0x88, 0x04,
298 0x89, 0x02,
299 0x8A, 0x02,
300 0x8B, 0x02,
301 0x8C, 0x01,
302 0x8D, 0x40,
303 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
Harald Welte52b1f982008-12-23 20:25:15 +0000304};
305
306
307// Transceiver, SET TRX ATTRIBUTES (TRX 0)
308
309/*
310 Object Class: Transceiver
311 BTS relat. Number: 0
312 Tranceiver number: 0
313 Instance 3: FF
314SET TRX ATTRIBUTES
315 aRFCNList (HEX): 0001
Harald Weltecd993872009-02-15 16:16:28 +0000316 txPwrMaxReduction: 00h = 30dB
Harald Welte52b1f982008-12-23 20:25:15 +0000317 radioMeasGran: 254 SACCH multiframes
318 radioMeasRep: 01h = enabled
319 memberOfEmergencyConfig: 01h = TRUE
320 trxArea: 00h = TRX doesn't belong to a concentric cell
321*/
322
323unsigned char msg_6[] =
324{
Harald Weltecd993872009-02-15 16:16:28 +0000325 0x44, 0x02, 0x00, 0x00, 0xFF,
326 NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/,
Harald Welte311d0cf2009-02-17 17:45:59 +0000327 NM_ATT_RF_MAXPOWR_R, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000328 NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0xFE,
329 NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01,
330 NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01,
331 NM_ATT_BS11_TRX_AREA, 0x01, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000332};
333
Harald Welte8c1d0e42009-02-15 03:38:12 +0000334static unsigned char nanobts_attr_bts[] = {
335 NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73,
336 NM_ATT_INTAVE_PARAM, 0x06,
337 NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10,
338 NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
339 NM_ATT_MAX_TA, 0x3f,
Harald Welte311d0cf2009-02-17 17:45:59 +0000340 NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */
341 NM_ATT_CCCH_L_T, 10, /* percent */
342 NM_ATT_CCCH_L_I_P, 1, /* seconds */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000343 NM_ATT_RACH_B_THRESH, 0x0a,
344 NM_ATT_LDAVG_SLOTS, 0x03, 0xe8,
345 NM_ATT_BTS_AIR_TIMER, 0x80,
346 NM_ATT_NY1, 0x0a,
347 NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
348 NM_ATT_BSIC, 0x20,
349};
Harald Welte52b1f982008-12-23 20:25:15 +0000350
Harald Welte8c1d0e42009-02-15 03:38:12 +0000351static unsigned char nanobts_attr_radio[] = {
Harald Welte311d0cf2009-02-17 17:45:59 +0000352 NM_ATT_RF_MAXPOWR_R, 0x0c,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000353 NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
354};
355
Harald Welte5c1e4582009-02-15 11:57:29 +0000356static unsigned char nanobts_attr_e0[] = {
357 0x85, 0x00,
358 0x81, 0x0b, 0xbb, /* TCP PORT for RSL */
359};
360
Harald Welte8c1d0e42009-02-15 03:38:12 +0000361int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
362 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
363{
364 struct gsm_bts *bts;
365 struct gsm_bts_trx *trx;
366 struct gsm_bts_trx_ts *ts;
367
368 /* This is currently only required on nanoBTS */
369
370 switch (evt) {
371 case EVT_STATECHG_OPER:
372 switch (obj_class) {
373 case NM_OC_SITE_MANAGER:
374 bts = container_of(obj, struct gsm_bts, site_mgr);
375 if (old_state->operational != 2 && new_state->operational == 2) {
376 abis_nm_opstart(bts, NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
377 }
378 break;
379 case NM_OC_BTS:
380 bts = obj;
381 if (new_state->availability == 5) {
382 abis_nm_set_bts_attr(bts, nanobts_attr_bts,
383 sizeof(nanobts_attr_bts));
384 abis_nm_opstart(bts, NM_OC_BTS,
385 bts->nr, 0xff, 0xff);
386 abis_nm_chg_adm_state(bts, NM_OC_BTS,
387 bts->nr, 0xff, 0xff,
388 NM_STATE_UNLOCKED);
389 }
390 break;
391 case NM_OC_RADIO_CARRIER:
392 trx = obj;
393 if (new_state->availability == 3) {
394 abis_nm_set_radio_attr(trx, nanobts_attr_radio,
395 sizeof(nanobts_attr_radio));
396 abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER,
397 trx->bts->nr, trx->nr, 0xff);
398 abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER,
399 trx->bts->nr, trx->nr, 0xff,
400 NM_STATE_UNLOCKED);
401 }
402 break;
403 case NM_OC_CHANNEL:
404 ts = obj;
405 trx = ts->trx;
406 if (new_state->availability == 5) {
407 if (ts->nr == 0 && trx == trx->bts->c0)
Harald Weltee1bd2412009-02-15 14:40:09 +0000408 abis_nm_set_channel_attr(ts, NM_CHANC_BCCH_CBCH);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000409 else
410 abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull);
411 abis_nm_opstart(trx->bts, NM_OC_CHANNEL,
412 trx->bts->nr, trx->nr, ts->nr);
413 abis_nm_chg_adm_state(trx->bts, NM_OC_CHANNEL,
414 trx->bts->nr, trx->nr, ts->nr,
415 NM_STATE_UNLOCKED);
416 }
417 break;
418 case NM_OC_BASEB_TRANSC:
419 trx = container_of(obj, struct gsm_bts_trx, bb_transc);
420 if (new_state->availability == 5) {
Harald Welte5c1e4582009-02-15 11:57:29 +0000421 abis_nm_ipaccess_msg(trx->bts, 0xe0, NM_OC_BASEB_TRANSC,
422 trx->bts->nr, trx->nr, 0xff,
423 nanobts_attr_e0, sizeof(nanobts_attr_e0));
Harald Welte8c1d0e42009-02-15 03:38:12 +0000424 abis_nm_opstart(trx->bts, NM_OC_BASEB_TRANSC,
425 trx->bts->nr, trx->nr, 0xff);
426 abis_nm_chg_adm_state(trx->bts, NM_OC_BASEB_TRANSC,
427 trx->bts->nr, trx->nr, 0xff,
428 NM_STATE_UNLOCKED);
429 }
430 break;
431 }
432 break;
Holger Freytherff9592f2009-03-09 16:17:14 +0000433 case EVT_STATECHG_ADM:
434 DEBUGP(DMM, "Unhandled state change in %s:%d\n", __func__, __LINE__);
435 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000436 }
437 return 0;
438}
439
440static void bootstrap_om_nanobts(struct gsm_bts *bts)
441{
Harald Weltee1bd2412009-02-15 14:40:09 +0000442 /* We don't do callback based bootstrapping, but event driven (see above) */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000443}
444
445static void bootstrap_om_bs11(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000446{
447 struct gsm_bts_trx *trx = &bts->trx[0];
448
449 /* stop sending event reports */
450 abis_nm_event_reports(bts, 0);
451
452 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000453 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000454
Harald Welte702d8702008-12-26 20:25:35 +0000455 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000456 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte702d8702008-12-26 20:25:35 +0000457
458 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000459 abis_nm_bs11_reset_resource(bts);
Harald Welte702d8702008-12-26 20:25:35 +0000460
461 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000462 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte702d8702008-12-26 20:25:35 +0000463
Harald Welte52b1f982008-12-23 20:25:15 +0000464 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
465 abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */
466 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
467 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
468
469 /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */
470 abis_nm_conn_terr_sign(trx, 0, 1, 0xff);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000471 set_ts_e1link(&trx->ts[0], 0, 1, 0xff);
Harald Welte52b1f982008-12-23 20:25:15 +0000472 abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */
473
474 /* Use TEI 1 for signalling */
475 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01);
476 abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000477
478#ifdef HAVE_TRX1
Harald Welte52b1f982008-12-23 20:25:15 +0000479 /* TRX 1 */
480 abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff);
481 /* FIXME: TRX ATTRIBUTE */
482 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02);
483#endif
484
485 /* SET CHANNEL ATTRIBUTE TS1 */
Harald Welte23887b62009-02-18 03:37:20 +0000486 abis_nm_set_channel_attr(&trx->ts[1], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000487 /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000488 set_ts_e1link(&trx->ts[1], 0, 2, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000489 abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1);
490
491 /* SET CHANNEL ATTRIBUTE TS2 */
Harald Welte23887b62009-02-18 03:37:20 +0000492 abis_nm_set_channel_attr(&trx->ts[2], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000493 /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000494 set_ts_e1link(&trx->ts[2], 0, 2, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000495 abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2);
496
497 /* SET CHANNEL ATTRIBUTE TS3 */
Harald Welte23887b62009-02-18 03:37:20 +0000498 abis_nm_set_channel_attr(&trx->ts[3], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000499 /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000500 set_ts_e1link(&trx->ts[3], 0, 2, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000501 abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3);
502
503 /* SET CHANNEL ATTRIBUTE TS4 */
Harald Welte23887b62009-02-18 03:37:20 +0000504 abis_nm_set_channel_attr(&trx->ts[4], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000505 /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000506 set_ts_e1link(&trx->ts[4], 0, 3, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000507 abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0);
508
509 /* SET CHANNEL ATTRIBUTE TS5 */
Harald Welte23887b62009-02-18 03:37:20 +0000510 abis_nm_set_channel_attr(&trx->ts[5], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000511 /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000512 set_ts_e1link(&trx->ts[5], 0, 3, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000513 abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1);
514
515 /* SET CHANNEL ATTRIBUTE TS6 */
Harald Welte23887b62009-02-18 03:37:20 +0000516 abis_nm_set_channel_attr(&trx->ts[6], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000517 /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000518 set_ts_e1link(&trx->ts[6], 0, 3, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000519 abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2);
520
521 /* SET CHANNEL ATTRIBUTE TS7 */
Harald Welte23887b62009-02-18 03:37:20 +0000522 abis_nm_set_channel_attr(&trx->ts[7], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000523 /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000524 set_ts_e1link(&trx->ts[7], 0, 3, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000525 abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3);
526
527 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000528 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000529
530 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000531 abis_nm_bs11_reset_resource(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000532
533 /* restart sending event reports */
534 abis_nm_event_reports(bts, 1);
535}
536
Harald Welte8c1d0e42009-02-15 03:38:12 +0000537static void bootstrap_om(struct gsm_bts *bts)
538{
539 fprintf(stdout, "bootstrapping OML\n");
540
541 switch (bts->type) {
542 case GSM_BTS_TYPE_BS11:
543 bootstrap_om_bs11(bts);
544 break;
545 case GSM_BTS_TYPE_NANOBTS_900:
546 case GSM_BTS_TYPE_NANOBTS_1800:
547 bootstrap_om_nanobts(bts);
548 break;
549 default:
550 fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type);
551 }
552}
553
Harald Welted1252502009-01-01 01:50:32 +0000554static int shutdown_om(struct gsm_bts *bts)
555{
556 /* stop sending event reports */
557 abis_nm_event_reports(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000558
Harald Welted1252502009-01-01 01:50:32 +0000559 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000560 abis_nm_bs11_db_transmission(bts, 1);
Harald Welted1252502009-01-01 01:50:32 +0000561
562 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000563 abis_nm_bs11_db_transmission(bts, 0);
Harald Welted1252502009-01-01 01:50:32 +0000564
565 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000566 abis_nm_bs11_reset_resource(bts);
Harald Welted1252502009-01-01 01:50:32 +0000567
568 return 0;
569}
570
571static int shutdown_net(struct gsm_network *net)
572{
573 int i;
574 for (i = 0; i < net->num_bts; i++) {
575 int rc;
576 rc = shutdown_om(&net->bts[i]);
577 if (rc < 0)
578 return rc;
579 }
580
581 return 0;
582}
Harald Welte52b1f982008-12-23 20:25:15 +0000583
584struct bcch_info {
585 u_int8_t type;
586 u_int8_t len;
587 const u_int8_t *data;
588};
589
590/*
591SYSTEM INFORMATION TYPE 1
592 Cell channel description
593 Format-ID bit map 0
594 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
595 RACH Control Parameters
596 maximum 7 retransmissions
597 8 slots used to spread transmission
598 cell not barred for access
599 call reestablishment not allowed
600 Access Control Class = 0000
601*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000602static u_int8_t si1[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000603 /* header */0x55, 0x06, 0x19,
604 /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
605 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,
606 /* rach */0xD5, 0x00, 0x00,
607 /* s1 reset*/0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000608};
609
610/*
611 SYSTEM INFORMATION TYPE 2
612 Neighbour Cells Description
613 EXT-IND: Carries the complete BA
614 BA-IND = 0
615 Format-ID bit map 0
616 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
617 NCC permitted (NCC) = FF
618 RACH Control Parameters
619 maximum 7 retransmissions
620 8 slots used to spread transmission
621 cell not barred for access
622 call reestablishment not allowed
623 Access Control Class = 0000
624*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000625static u_int8_t si2[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000626 /* header */0x59, 0x06, 0x1A,
627 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
629 /* ncc */0xFF,
630 /* rach*/0xD5, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +0000631};
632
633/*
634SYSTEM INFORMATION TYPE 3
635 Cell identity = 00001 (1h)
636 Location area identification
637 Mobile Country Code (MCC): 001
638 Mobile Network Code (MNC): 01
639 Location Area Code (LAC): 00001 (1h)
640 Control Channel Description
641 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
642 0 blocks reserved for access grant
643 1 channel used for CCCH, with SDCCH
644 5 multiframes period for PAGING REQUEST
645 Time-out T3212 = 0
646 Cell Options BCCH
647 Power control indicator: not set
648 MSs shall not use uplink DTX
649 Radio link timeout = 36
650 Cell Selection Parameters
651 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
Harald Welte3b2ec422008-12-29 04:11:14 +0000652 max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max)
Harald Welte52b1f982008-12-23 20:25:15 +0000653 Additional Reselect Parameter Indication (ACS) = only SYSTEM INFO 4: The SI rest octets, if present, shall be used to derive the value of PI and possibly C2 parameters
654 Half rate support (NECI): New establishment causes are not supported
655 min.RX signal level for MS = 0
656 RACH Control Parameters
657 maximum 7 retransmissions
658 8 slots used to spread transmission
659 cell not barred for access
660 call reestablishment not allowed
661 Access Control Class = 0000
662 SI 3 Rest Octets
663 Cell Bar Qualify (CBQ): 0
664 Cell Reselect Offset = 0 dB
665 Temporary Offset = 0 dB
666 Penalty Time = 20 s
667 System Information 2ter Indicator (2TI): 0 = not available
668 Early Classmark Sending Control (ECSC): 0 = forbidden
669 Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
670*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000671static u_int8_t si3[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000672 /* header */0x49, 0x06, 0x1B,
673 /* cell */0x00, 0x01,
674 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
675 /* desc */0x01, 0x03, 0x00,
676 /* option*/0x28,
677 /* selection*/0x62, 0x00,
678 /* rach */0xD5, 0x00, 0x00,
679 /* reset*/0x80, 0x00, 0x00, 0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000680};
681
682/*
683SYSTEM INFORMATION TYPE 4
684 Location area identification
685 Mobile Country Code (MCC): 001
686 Mobile Network Code (MNC): 01
687 Location Area Code (LAC): 00001 (1h)
688 Cell Selection Parameters
689 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
690 max.TX power level MS may use for CCH = 2
691 Additional Reselect Parameter Indication (ACS) = only SYSTEM INFO 4: The SI rest octets, if present, shall be used to derive the value of PI and possibly C2 parameters
692 Half rate support (NECI): New establishment causes are not supported
693 min.RX signal level for MS = 0
694 RACH Control Parameters
695 maximum 7 retransmissions
696 8 slots used to spread transmission
697 cell not barred for access
698 call reestablishment not allowed
699 Access Control Class = 0000
700 Channel Description
701 Type = SDCCH/4[2]
702 Timeslot Number: 0
703 Training Sequence Code: 7h
704 ARFCN: 1
705 SI Rest Octets
706 Cell Bar Qualify (CBQ): 0
707 Cell Reselect Offset = 0 dB
708 Temporary Offset = 0 dB
709 Penalty Time = 20 s
710*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000711static u_int8_t si4[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000712 /* header */0x41, 0x06, 0x1C,
713 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
714 /* sel */0x62, 0x00,
715 /* rach*/0xD5, 0x00, 0x00,
716 /* var */0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000717 0x2B, 0x2B, 0x2B
718};
719
720/*
721 SYSTEM INFORMATION TYPE 5
722 Neighbour Cells Description
723 EXT-IND: Carries the complete BA
724 BA-IND = 0
725 Format-ID bit map 0
726 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
727*/
728
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000729static u_int8_t si5[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000730 /* header without l2 len*/0x06, 0x1D,
731 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
732 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000733};
734
735// SYSTEM INFORMATION TYPE 6
736
737/*
738SACCH FILLING
739 System Info Type: SYSTEM INFORMATION 6
740 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
741
742SYSTEM INFORMATION TYPE 6
743 Cell identity = 00001 (1h)
744 Location area identification
745 Mobile Country Code (MCC): 001
746 Mobile Network Code (MNC): 01
747 Location Area Code (LAC): 00001 (1h)
748 Cell Options SACCH
749 Power control indicator: not set
750 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
751 Radio link timeout = 36
752 NCC permitted (NCC) = FF
753*/
754
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000755static u_int8_t si6[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000756 /* header */0x06, 0x1E,
757 /* cell id*/ 0x00, 0x01,
758 /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01,
759 /* options */ 0x28,
760 /* ncc */ 0xFF,
Harald Welte52b1f982008-12-23 20:25:15 +0000761};
762
763
764
765static const struct bcch_info bcch_infos[] = {
766 {
767 .type = RSL_SYSTEM_INFO_1,
768 .len = sizeof(si1),
769 .data = si1,
770 }, {
771 .type = RSL_SYSTEM_INFO_2,
772 .len = sizeof(si2),
773 .data = si2,
774 }, {
775 .type = RSL_SYSTEM_INFO_3,
776 .len = sizeof(si3),
777 .data = si3,
778 }, {
779 .type = RSL_SYSTEM_INFO_4,
780 .len = sizeof(si4),
781 .data = si4,
782 },
783};
784
Holger Freyther24287b62008-12-28 16:32:41 +0000785static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1)
786static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2)
787static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3)
788static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4)
Harald Welte104604e2008-12-28 16:36:11 +0000789static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5)
790static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6)
Holger Freyther24287b62008-12-28 16:32:41 +0000791
Harald Welte52b1f982008-12-23 20:25:15 +0000792/* set all system information types */
Harald Weltee79769b2009-02-07 00:48:17 +0000793static int set_system_infos(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000794{
795 int i;
796
797 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
Harald Weltee79769b2009-02-07 00:48:17 +0000798 rsl_bcch_info(trx, bcch_infos[i].type,
Harald Welte52b1f982008-12-23 20:25:15 +0000799 bcch_infos[i].data,
800 bcch_infos[i].len);
801 }
Harald Weltee79769b2009-02-07 00:48:17 +0000802 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
803 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
Harald Weltead384642008-12-26 10:20:07 +0000804
805 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000806}
807
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000808/*
809 * Patch the various SYSTEM INFORMATION tables to update
810 * the LAI
811 */
812static void patch_tables(struct gsm_bts *bts)
813{
Harald Welte98981882009-01-06 18:59:11 +0000814 u_int8_t arfcn_low = ARFCN & 0xff;
815 u_int8_t arfcn_high = (ARFCN >> 8) & 0x0f;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000816 /* covert the raw packet to the struct */
817 struct gsm48_system_information_type_3 *type_3 =
818 (struct gsm48_system_information_type_3*)&si3;
819 struct gsm48_system_information_type_4 *type_4 =
820 (struct gsm48_system_information_type_4*)&si4;
821 struct gsm48_system_information_type_6 *type_6 =
822 (struct gsm48_system_information_type_6*)&si6;
Harald Welteb84e2f42008-12-28 23:42:04 +0000823 struct gsm48_loc_area_id lai;
824
825 gsm0408_generate_lai(&lai, bts->network->country_code,
826 bts->network->network_code, bts->location_area_code);
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000827
828 /* assign the MCC and MNC */
Harald Welteb84e2f42008-12-28 23:42:04 +0000829 type_3->lai = lai;
830 type_4->lai = lai;
831 type_6->lai = lai;
Harald Welte98981882009-01-06 18:59:11 +0000832
Harald Welte94009322009-02-15 15:38:42 +0000833 /* patch ARFCN into BTS Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000834 msg_2[74] &= 0xf0;
835 msg_2[74] |= arfcn_high;
836 msg_2[75] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000837 nanobts_attr_bts[42] &= 0xf0;
838 nanobts_attr_bts[42] |= arfcn_high;
839 nanobts_attr_bts[43] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000840
Harald Welte94009322009-02-15 15:38:42 +0000841 /* patch ARFCN into TRX Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000842 msg_6[7] &= 0xf0;
843 msg_6[7] |= arfcn_high;
844 msg_6[8] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000845 nanobts_attr_radio[5] &= 0xf0;
846 nanobts_attr_radio[5] |= arfcn_high;
847 nanobts_attr_radio[6] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000848
849 type_4->data[2] &= 0xf0;
850 type_4->data[2] |= arfcn_high;
851 type_4->data[3] = arfcn_low;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000852
853 /* patch Control Channel Description 10.5.2.11 */
854 type_3->control_channel_desc = bts->chan_desc;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000855}
856
857
Harald Weltee79769b2009-02-07 00:48:17 +0000858static void bootstrap_rsl(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000859{
Harald Welteb84e2f42008-12-28 23:42:04 +0000860 fprintf(stdout, "bootstrapping RSL MCC=%u MNC=%u\n", MCC, MNC);
Harald Weltee79769b2009-02-07 00:48:17 +0000861 set_system_infos(trx);
Harald Welte52b1f982008-12-23 20:25:15 +0000862}
863
Harald Welte1fa60c82009-02-09 18:13:26 +0000864void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
Harald Weltead384642008-12-26 10:20:07 +0000865{
866 switch (event) {
Harald Welte1fa60c82009-02-09 18:13:26 +0000867 case EVT_E1_TEI_UP:
868 switch (type) {
869 case E1INP_SIGN_OML:
870 bootstrap_om(trx->bts);
871 break;
872 case E1INP_SIGN_RSL:
873 bootstrap_rsl(trx);
874 break;
875 default:
876 break;
877 }
Harald Weltead384642008-12-26 10:20:07 +0000878 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000879 case EVT_E1_TEI_DN:
880 fprintf(stderr, "Lost some E1 TEI link\n");
881 /* FIXME: deal with TEI or L1 link loss */
Harald Weltead384642008-12-26 10:20:07 +0000882 break;
883 default:
Harald Weltead384642008-12-26 10:20:07 +0000884 break;
885 }
886}
887
888static int bootstrap_network(void)
Harald Welte52b1f982008-12-23 20:25:15 +0000889{
890 struct gsm_bts *bts;
891
892 /* initialize our data structures */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000893 gsmnet = gsm_network_init(1, BTS_TYPE, MCC, MNC);
Harald Weltead384642008-12-26 10:20:07 +0000894 if (!gsmnet)
895 return -ENOMEM;
Harald Weltef5cbab72008-12-30 18:00:15 +0000896
Harald Weltefd2fb452009-02-21 13:00:57 +0000897 gsmnet->name_long = "OpenBSC";
898 gsmnet->name_short = "OpenBSC";
Harald Welte52b1f982008-12-23 20:25:15 +0000899 bts = &gsmnet->bts[0];
Holger Freyther0a173bf2009-04-22 22:07:07 +0000900 bts->location_area_code = LAC;
Harald Welte98981882009-01-06 18:59:11 +0000901 bts->trx[0].arfcn = ARFCN;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000902
903 /* Control Channel Description */
904 memset(&bts->chan_desc, 0, sizeof(struct gsm48_control_channel_descr));
Harald Welte41fbf442009-02-24 22:34:22 +0000905 bts->chan_desc.att = 1;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000906 bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
907 bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
908 bts->chan_desc.t3212 = 0;
909
Harald Welte98981882009-01-06 18:59:11 +0000910 patch_tables(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000911
Holger Freyther1fd34142009-02-09 23:42:03 +0000912 paging_init(bts);
Harald Welte38c2f132009-01-06 23:10:57 +0000913
Holger Freyther36650b82009-04-19 06:35:16 +0000914 if (db_init(database_name, gsmnet)) {
Holger Freytheref7f7ce2009-04-19 06:35:12 +0000915 printf("DB: Failed to init database. Please check the option settings.\n");
916 return -1;
917 }
918 printf("DB: Database initialized.\n");
919
920 if (db_prepare()) {
921 printf("DB: Failed to prepare database.\n");
922 return -1;
923 }
924 printf("DB: Database prepared.\n");
925
Holger Freyther219518d2009-01-02 22:04:43 +0000926 telnet_init(gsmnet, 4242);
Harald Weltead384642008-12-26 10:20:07 +0000927
Harald Welte1fa60c82009-02-09 18:13:26 +0000928 /* E1 mISDN input setup */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000929 if (BTS_TYPE == GSM_BTS_TYPE_BS11)
Holger Freytherdda22c12009-04-22 22:07:31 +0000930 return e1_config(bts, cardnr);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000931 else
932 return ia_config(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000933}
Harald Weltef6b7a902008-12-26 00:05:11 +0000934
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000935static void create_pcap_file(char *file)
936{
937 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
938 int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
939
940 if (fd < 0) {
941 perror("Failed to open file for pcap");
942 return;
943 }
944
Holger Freyther0469cf62009-03-31 12:14:16 +0000945 e1_set_pcap_fd(fd);
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000946}
947
Holger Freytherb332f612008-12-27 12:46:51 +0000948static void print_usage()
949{
950 printf("Usage: bsc_hack\n");
951}
952
953static void print_help()
954{
955 printf(" Some useful help...\n");
956 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
Holger Freytherefde7fb2008-12-28 14:14:56 +0000957 printf(" -s --disable-color\n");
958 printf(" -n --network-code number(MNC) \n");
959 printf(" -c --country-code number (MCC) \n");
Holger Freyther0a173bf2009-04-22 22:07:07 +0000960 printf(" -L --location-area-code number (LAC) \n");
Harald Welte98981882009-01-06 18:59:11 +0000961 printf(" -f --arfcn number The frequency ARFCN\n");
Holger Freytherbde36102008-12-28 22:51:39 +0000962 printf(" -l --database db-name The database to use\n");
Holger Freyther89824fc2008-12-30 16:18:18 +0000963 printf(" -a --authorize-everyone Allow everyone into the network.\n");
Holger Freythere97f7fb2008-12-31 18:52:11 +0000964 printf(" -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n");
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000965 printf(" -p --pcap file The filename of the pcap file\n");
Harald Weltee1bd2412009-02-15 14:40:09 +0000966 printf(" -t --bts-type type The BTS type (bs11, nanobts900, nanobts1800)\n");
Holger Freytherdda22c12009-04-22 22:07:31 +0000967 printf(" -C --cardnr number For bs11 select E1 card number other than 0\n");
Holger Freytherb332f612008-12-27 12:46:51 +0000968 printf(" -h --help this text\n");
969}
970
971static void handle_options(int argc, char** argv)
972{
973 while (1) {
974 int option_index = 0, c;
975 static struct option long_options[] = {
976 {"help", 0, 0, 'h'},
977 {"debug", 1, 0, 'd'},
Holger Freytherefde7fb2008-12-28 14:14:56 +0000978 {"disable-color", 0, 0, 's'},
979 {"network-code", 1, 0, 'n'},
980 {"country-code", 1, 0, 'c'},
Holger Freyther0a173bf2009-04-22 22:07:07 +0000981 {"location-area-code", 1, 0, 'L'},
Holger Freytherbde36102008-12-28 22:51:39 +0000982 {"database", 1, 0, 'l'},
Holger Freyther89824fc2008-12-30 16:18:18 +0000983 {"authorize-everyone", 0, 0, 'a'},
Holger Freythere97f7fb2008-12-31 18:52:11 +0000984 {"reject-cause", 1, 0, 'r'},
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000985 {"pcap", 1, 0, 'p'},
Harald Welte98981882009-01-06 18:59:11 +0000986 {"arfcn", 1, 0, 'f'},
Harald Welte8c1d0e42009-02-15 03:38:12 +0000987 {"bts-type", 1, 0, 't'},
Holger Freytherdda22c12009-04-22 22:07:31 +0000988 {"cardnr", 1, 0, 'C'},
Holger Freytherb332f612008-12-27 12:46:51 +0000989 {0, 0, 0, 0}
990 };
991
Holger Freytherdda22c12009-04-22 22:07:31 +0000992 c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:C:L:",
Holger Freytherb332f612008-12-27 12:46:51 +0000993 long_options, &option_index);
994 if (c == -1)
995 break;
996
997 switch (c) {
998 case 'h':
999 print_usage();
1000 print_help();
1001 exit(0);
Holger Freytherefde7fb2008-12-28 14:14:56 +00001002 case 's':
Holger Freytherb332f612008-12-27 12:46:51 +00001003 debug_use_color(0);
1004 break;
1005 case 'd':
1006 debug_parse_category_mask(optarg);
1007 break;
Holger Freytherefde7fb2008-12-28 14:14:56 +00001008 case 'n':
1009 MNC = atoi(optarg);
1010 break;
1011 case 'c':
1012 MCC = atoi(optarg);
1013 break;
Holger Freyther0a173bf2009-04-22 22:07:07 +00001014 case 'L':
1015 LAC = atoi(optarg);
1016 break;
Harald Welte98981882009-01-06 18:59:11 +00001017 case 'f':
1018 ARFCN = atoi(optarg);
1019 break;
Harald Welte8965da42009-01-06 18:09:02 +00001020 case 'l':
Holger Freytherbde36102008-12-28 22:51:39 +00001021 database_name = strdup(optarg);
1022 break;
Holger Freyther89824fc2008-12-30 16:18:18 +00001023 case 'a':
1024 gsm0408_allow_everyone(1);
1025 break;
Holger Freythere97f7fb2008-12-31 18:52:11 +00001026 case 'r':
1027 gsm0408_set_reject_cause(atoi(optarg));
1028 break;
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001029 case 'p':
1030 create_pcap_file(optarg);
1031 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +00001032 case 't':
1033 BTS_TYPE = parse_btstype(optarg);
1034 break;
Holger Freytherdda22c12009-04-22 22:07:31 +00001035 case 'C':
1036 cardnr = atoi(optarg);
1037 break;
Holger Freytherb332f612008-12-27 12:46:51 +00001038 default:
1039 /* ignore */
1040 break;
1041 }
1042 }
1043}
1044
Harald Welted1252502009-01-01 01:50:32 +00001045static void signal_handler(int signal)
1046{
1047 fprintf(stdout, "signal %u received\n", signal);
1048
1049 switch (signal) {
1050 case SIGHUP:
1051 case SIGABRT:
1052 shutdown_net(gsmnet);
1053 break;
1054 default:
1055 break;
1056 }
1057}
1058
Harald Weltef6b7a902008-12-26 00:05:11 +00001059int main(int argc, char **argv)
1060{
Harald Welte1fa60c82009-02-09 18:13:26 +00001061 int rc;
1062
Holger Freytherb332f612008-12-27 12:46:51 +00001063 /* parse options */
1064 handle_options(argc, argv);
1065
Harald Welte65ccf882009-02-24 22:36:20 +00001066 /* seed the PRNG */
1067 srand(time(NULL));
1068
Harald Welte1fa60c82009-02-09 18:13:26 +00001069 rc = bootstrap_network();
1070 if (rc < 0)
1071 exit(1);
Harald Weltef6b7a902008-12-26 00:05:11 +00001072
Harald Welted1252502009-01-01 01:50:32 +00001073 signal(SIGHUP, &signal_handler);
1074 signal(SIGABRT, &signal_handler);
1075
Harald Weltef6b7a902008-12-26 00:05:11 +00001076 while (1) {
1077 bsc_select_main();
1078 }
1079}