blob: 46e9e45b46a234da173898833bf0690857015ea0 [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;
Harald Welte98981882009-01-06 18:59:11 +000056static int ARFCN = HARDCODED_ARFCN;
Harald Welte8c1d0e42009-02-15 03:38:12 +000057static enum gsm_bts_type BTS_TYPE = GSM_BTS_TYPE_BS11;
Holger Freytherbde36102008-12-28 22:51:39 +000058static const char *database_name = "hlr.sqlite3";
Holger Freytherefde7fb2008-12-28 14:14:56 +000059
Harald Welte52b1f982008-12-23 20:25:15 +000060/* The following definitions are for OM and NM packets that we cannot yet
61 * generate by code but we just pass on */
62
63// BTS Site Manager, SET ATTRIBUTES
64
65/*
66 Object Class: BTS Site Manager
67 Instance 1: FF
68 Instance 2: FF
69 Instance 3: FF
70SET ATTRIBUTES
71 sAbisExternalTime: 2007/09/08 14:36:11
72 omLAPDRelTimer: 30sec
73 shortLAPDIntTimer: 5sec
74 emergencyTimer1: 10 minutes
75 emergencyTimer2: 0 minutes
76*/
77
78unsigned char msg_1[] =
79{
Harald Weltecd993872009-02-15 16:16:28 +000080 0xD0, 0x00, 0xFF, 0xFF, 0xFF,
81 NM_ATT_BS11_ABIS_EXT_TIME, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE,
82 0x02, 0x00, 0x1E,
83 0xE8, 0x01, 0x05,
84 0x42, 0x02, 0x00, 0x0A,
85 0x44, 0x02, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +000086};
87
88// BTS, SET BTS ATTRIBUTES
89
90/*
91 Object Class: BTS
92 BTS relat. Number: 0
93 Instance 2: FF
94 Instance 3: FF
95SET BTS ATTRIBUTES
96 bsIdentityCode / BSIC:
97 PLMN_colour_code: 7h
98 BS_colour_code: 7h
99 BTS Air Timer T3105: 4 ,unit 10 ms
100 btsIsHopping: FALSE
Harald Welte83282292009-02-01 16:22:19 +0000101 periodCCCHLoadIndication: 1sec
Holger Freyther3b910432009-02-11 00:43:48 +0000102 thresholdCCCHLoadIndication: 0%
Harald Welte52b1f982008-12-23 20:25:15 +0000103 cellAllocationNumber: 00h = GSM 900
104 enableInterferenceClass: 00h = Disabled
105 fACCHQual: 6 (FACCH stealing flags minus 1)
106 intaveParameter: 31 SACCH multiframes
107 interferenceLevelBoundaries:
108 Interference Boundary 1: 0Ah
109 Interference Boundary 2: 0Fh
110 Interference Boundary 3: 14h
111 Interference Boundary 4: 19h
112 Interference Boundary 5: 1Eh
113 mSTxPwrMax: 11
114 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
115 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
116 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
117 30=33dBm, 31=32dBm
118 ny1:
119 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
120 powerOutputThresholds:
121 Out Power Fault Threshold: -10 dB
122 Red Out Power Threshold: - 6 dB
123 Excessive Out Power Threshold: 5 dB
124 rACHBusyThreshold: -127 dBm
125 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
126 rfResourceIndicationPeriod: 125 SACCH multiframes
127 T200:
128 SDCCH: 044 in 5 ms
129 FACCH/Full rate: 031 in 5 ms
130 FACCH/Half rate: 041 in 5 ms
131 SACCH with TCH SAPI0: 090 in 10 ms
132 SACCH with SDCCH: 090 in 10 ms
133 SDCCH with SAPI3: 090 in 5 ms
134 SACCH with TCH SAPI3: 135 in 10 ms
135 tSync: 9000 units of 10 msec
136 tTrau: 9000 units of 10 msec
137 enableUmLoopTest: 00h = disabled
138 enableExcessiveDistance: 00h = Disabled
139 excessiveDistance: 64km
140 hoppingMode: 00h = baseband hopping
141 cellType: 00h = Standard Cell
142 BCCH ARFCN / bCCHFrequency: 1
143*/
144
145unsigned char msg_2[] =
146{
Harald Welte8c1d0e42009-02-15 03:38:12 +0000147 0x41, 0x01, 0x00, 0xFF, 0xFF,
148 NM_ATT_BSIC, 0x3F,
149 NM_ATT_BTS_AIR_TIMER, 0x04,
Harald Weltecd993872009-02-15 16:16:28 +0000150 NM_ATT_BS11_BTSLS_HOPPING, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000151 NM_ATT_CCCH_L_I_P, 0x01,
152 NM_ATT_CCCH_L_T, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000153 NM_ATT_BS11_CELL_ALLOC_NR, 0x00,
154 NM_ATT_BS11_ENA_INTERF_CLASS, 0x00,
155 NM_ATT_BS11_FACCH_QUAL, 0x06,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000156 NM_ATT_INTAVE_PARAM, 0x1F,
157 NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B,
158 NM_ATT_CCCH_L_T, 0x23,
159 NM_ATT_GSM_TIME, 0x28, 0x00,
160 NM_ATT_ADM_STATE, 0x03,
161 NM_ATT_RACH_B_THRESH, 0x7F,
162 NM_ATT_LDAVG_SLOTS, 0x00, 0xFA,
Harald Weltecd993872009-02-15 16:16:28 +0000163 NM_ATT_BS11_RF_RES_IND_PER, 0x7D,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000164 NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87,
Harald Weltecd993872009-02-15 16:16:28 +0000165 NM_ATT_BS11_TSYNC, 0x23, 0x28,
166 NM_ATT_BS11_TTRAU, 0x23, 0x28,
167 NM_ATT_TEST_DUR, 0x01, 0x00,
168 NM_ATT_OUTST_ALARM, 0x01, 0x00,
169 NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40,
170 NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00,
171 NM_ATT_BS11_PLL, 0x01, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000172 NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/,
Harald Welte52b1f982008-12-23 20:25:15 +0000173};
174
175// Handover Recognition, SET ATTRIBUTES
176
177/*
178Illegal Contents GSM Formatted O&M Msg
179 Object Class: Handover Recognition
180 BTS relat. Number: 0
181 Instance 2: FF
182 Instance 3: FF
183SET ATTRIBUTES
184 enableDelayPowerBudgetHO: 00h = Disabled
185 enableDistanceHO: 00h = Disabled
186 enableInternalInterCellHandover: 00h = Disabled
187 enableInternalIntraCellHandover: 00h = Disabled
188 enablePowerBudgetHO: 00h = Disabled
189 enableRXLEVHO: 00h = Disabled
190 enableRXQUALHO: 00h = Disabled
191 hoAveragingDistance: 8 SACCH multiframes
192 hoAveragingLev:
193 A_LEV_HO: 8 SACCH multiframes
194 W_LEV_HO: 1 SACCH multiframes
195 hoAveragingPowerBudget: 16 SACCH multiframes
196 hoAveragingQual:
197 A_QUAL_HO: 8 SACCH multiframes
198 W_QUAL_HO: 2 SACCH multiframes
199 hoLowerThresholdLevDL: (10 - 110) dBm
200 hoLowerThresholdLevUL: (5 - 110) dBm
201 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
202 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
203 hoThresholdLevDLintra : (20 - 110) dBm
204 hoThresholdLevULintra: (20 - 110) dBm
205 hoThresholdMsRangeMax: 20 km
206 nCell: 06h
207 timerHORequest: 3 ,unit 2 SACCH multiframes
208*/
209
210unsigned char msg_3[] =
211{
Harald Weltecd993872009-02-15 16:16:28 +0000212 0xD0, 0xA1, 0x00, 0xFF, 0xFF,
213 0xD0, 0x00,
214 0x64, 0x00,
215 0x67, 0x00,
216 0x68, 0x00,
217 0x6A, 0x00,
218 0x6C, 0x00,
219 0x6D, 0x00,
220 0x6F, 0x08,
221 0x70, 0x08, 0x01,
222 0x71, 0x10, 0x10, 0x10,
223 0x72, 0x08, 0x02,
224 0x73, 0x0A,
225 0x74, 0x05,
226 0x75, 0x06,
227 0x76, 0x06,
228 0x78, 0x14,
229 0x79, 0x14,
230 0x7A, 0x14,
231 0x7D, 0x06,
232 0x92, 0x03, 0x20, 0x01, 0x00,
233 0x45, 0x01, 0x00,
234 0x48, 0x01, 0x00,
235 0x5A, 0x01, 0x00,
236 0x5B, 0x01, 0x05,
237 0x5E, 0x01, 0x1A,
238 0x5F, 0x01, 0x20,
239 0x9D, 0x01, 0x00,
240 0x47, 0x01, 0x00,
241 0x5C, 0x01, 0x64,
242 0x5D, 0x01, 0x1E,
243 0x97, 0x01, 0x20,
244 0xF7, 0x01, 0x3C,
Harald Welte52b1f982008-12-23 20:25:15 +0000245};
246
247// Power Control, SET ATTRIBUTES
248
249/*
250 Object Class: Power Control
251 BTS relat. Number: 0
252 Instance 2: FF
253 Instance 3: FF
254SET ATTRIBUTES
255 enableMsPowerControl: 00h = Disabled
256 enablePowerControlRLFW: 00h = Disabled
257 pcAveragingLev:
258 A_LEV_PC: 4 SACCH multiframes
259 W_LEV_PC: 1 SACCH multiframes
260 pcAveragingQual:
261 A_QUAL_PC: 4 SACCH multiframes
262 W_QUAL_PC: 2 SACCH multiframes
263 pcLowerThresholdLevDL: 0Fh
264 pcLowerThresholdLevUL: 0Ah
265 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
266 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
267 pcRLFThreshold: 0Ch
268 pcUpperThresholdLevDL: 14h
269 pcUpperThresholdLevUL: 0Fh
270 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
271 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
272 powerConfirm: 2 ,unit 2 SACCH multiframes
273 powerControlInterval: 2 ,unit 2 SACCH multiframes
274 powerIncrStepSize: 02h = 4 dB
275 powerRedStepSize: 01h = 2 dB
276 radioLinkTimeoutBs: 64 SACCH multiframes
277 enableBSPowerControl: 00h = disabled
278*/
279
280unsigned char msg_4[] =
281{
Harald Weltecd993872009-02-15 16:16:28 +0000282 0xD0, 0xA2, 0x00, 0xFF, 0xFF,
283 NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00,
284 NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00,
285 0x7E, 0x04, 0x01,
286 0x7F, 0x04, 0x02,
287 0x80, 0x0F,
288 0x81, 0x0A,
289 0x82, 0x05,
290 0x83, 0x05,
291 0x84, 0x0C,
292 0x85, 0x14,
293 0x86, 0x0F,
294 0x87, 0x04,
295 0x88, 0x04,
296 0x89, 0x02,
297 0x8A, 0x02,
298 0x8B, 0x02,
299 0x8C, 0x01,
300 0x8D, 0x40,
301 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
Harald Welte52b1f982008-12-23 20:25:15 +0000302};
303
304
305// Transceiver, SET TRX ATTRIBUTES (TRX 0)
306
307/*
308 Object Class: Transceiver
309 BTS relat. Number: 0
310 Tranceiver number: 0
311 Instance 3: FF
312SET TRX ATTRIBUTES
313 aRFCNList (HEX): 0001
Harald Weltecd993872009-02-15 16:16:28 +0000314 txPwrMaxReduction: 00h = 30dB
Harald Welte52b1f982008-12-23 20:25:15 +0000315 radioMeasGran: 254 SACCH multiframes
316 radioMeasRep: 01h = enabled
317 memberOfEmergencyConfig: 01h = TRUE
318 trxArea: 00h = TRX doesn't belong to a concentric cell
319*/
320
321unsigned char msg_6[] =
322{
Harald Weltecd993872009-02-15 16:16:28 +0000323 0x44, 0x02, 0x00, 0x00, 0xFF,
324 NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/,
Harald Welte311d0cf2009-02-17 17:45:59 +0000325 NM_ATT_RF_MAXPOWR_R, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000326 NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0xFE,
327 NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01,
328 NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01,
329 NM_ATT_BS11_TRX_AREA, 0x01, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000330};
331
Harald Welte8c1d0e42009-02-15 03:38:12 +0000332static unsigned char nanobts_attr_bts[] = {
333 NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73,
334 NM_ATT_INTAVE_PARAM, 0x06,
335 NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10,
336 NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
337 NM_ATT_MAX_TA, 0x3f,
Harald Welte311d0cf2009-02-17 17:45:59 +0000338 NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */
339 NM_ATT_CCCH_L_T, 10, /* percent */
340 NM_ATT_CCCH_L_I_P, 1, /* seconds */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000341 NM_ATT_RACH_B_THRESH, 0x0a,
342 NM_ATT_LDAVG_SLOTS, 0x03, 0xe8,
343 NM_ATT_BTS_AIR_TIMER, 0x80,
344 NM_ATT_NY1, 0x0a,
345 NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
346 NM_ATT_BSIC, 0x20,
347};
Harald Welte52b1f982008-12-23 20:25:15 +0000348
Harald Welte8c1d0e42009-02-15 03:38:12 +0000349static unsigned char nanobts_attr_radio[] = {
Harald Welte311d0cf2009-02-17 17:45:59 +0000350 NM_ATT_RF_MAXPOWR_R, 0x0c,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000351 NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
352};
353
Harald Welte5c1e4582009-02-15 11:57:29 +0000354static unsigned char nanobts_attr_e0[] = {
355 0x85, 0x00,
356 0x81, 0x0b, 0xbb, /* TCP PORT for RSL */
357};
358
Harald Welte8c1d0e42009-02-15 03:38:12 +0000359int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
360 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
361{
362 struct gsm_bts *bts;
363 struct gsm_bts_trx *trx;
364 struct gsm_bts_trx_ts *ts;
365
366 /* This is currently only required on nanoBTS */
367
368 switch (evt) {
369 case EVT_STATECHG_OPER:
370 switch (obj_class) {
371 case NM_OC_SITE_MANAGER:
372 bts = container_of(obj, struct gsm_bts, site_mgr);
373 if (old_state->operational != 2 && new_state->operational == 2) {
374 abis_nm_opstart(bts, NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
375 }
376 break;
377 case NM_OC_BTS:
378 bts = obj;
379 if (new_state->availability == 5) {
380 abis_nm_set_bts_attr(bts, nanobts_attr_bts,
381 sizeof(nanobts_attr_bts));
382 abis_nm_opstart(bts, NM_OC_BTS,
383 bts->nr, 0xff, 0xff);
384 abis_nm_chg_adm_state(bts, NM_OC_BTS,
385 bts->nr, 0xff, 0xff,
386 NM_STATE_UNLOCKED);
387 }
388 break;
389 case NM_OC_RADIO_CARRIER:
390 trx = obj;
391 if (new_state->availability == 3) {
392 abis_nm_set_radio_attr(trx, nanobts_attr_radio,
393 sizeof(nanobts_attr_radio));
394 abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER,
395 trx->bts->nr, trx->nr, 0xff);
396 abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER,
397 trx->bts->nr, trx->nr, 0xff,
398 NM_STATE_UNLOCKED);
399 }
400 break;
401 case NM_OC_CHANNEL:
402 ts = obj;
403 trx = ts->trx;
404 if (new_state->availability == 5) {
405 if (ts->nr == 0 && trx == trx->bts->c0)
Harald Weltee1bd2412009-02-15 14:40:09 +0000406 abis_nm_set_channel_attr(ts, NM_CHANC_BCCH_CBCH);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000407 else
408 abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull);
409 abis_nm_opstart(trx->bts, NM_OC_CHANNEL,
410 trx->bts->nr, trx->nr, ts->nr);
411 abis_nm_chg_adm_state(trx->bts, NM_OC_CHANNEL,
412 trx->bts->nr, trx->nr, ts->nr,
413 NM_STATE_UNLOCKED);
414 }
415 break;
416 case NM_OC_BASEB_TRANSC:
417 trx = container_of(obj, struct gsm_bts_trx, bb_transc);
418 if (new_state->availability == 5) {
Harald Welte5c1e4582009-02-15 11:57:29 +0000419 abis_nm_ipaccess_msg(trx->bts, 0xe0, NM_OC_BASEB_TRANSC,
420 trx->bts->nr, trx->nr, 0xff,
421 nanobts_attr_e0, sizeof(nanobts_attr_e0));
Harald Welte8c1d0e42009-02-15 03:38:12 +0000422 abis_nm_opstart(trx->bts, NM_OC_BASEB_TRANSC,
423 trx->bts->nr, trx->nr, 0xff);
424 abis_nm_chg_adm_state(trx->bts, NM_OC_BASEB_TRANSC,
425 trx->bts->nr, trx->nr, 0xff,
426 NM_STATE_UNLOCKED);
427 }
428 break;
429 }
430 break;
Holger Freytherff9592f2009-03-09 16:17:14 +0000431 case EVT_STATECHG_ADM:
432 DEBUGP(DMM, "Unhandled state change in %s:%d\n", __func__, __LINE__);
433 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000434 }
435 return 0;
436}
437
438static void bootstrap_om_nanobts(struct gsm_bts *bts)
439{
Harald Weltee1bd2412009-02-15 14:40:09 +0000440 /* We don't do callback based bootstrapping, but event driven (see above) */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000441}
442
443static void bootstrap_om_bs11(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000444{
445 struct gsm_bts_trx *trx = &bts->trx[0];
446
447 /* stop sending event reports */
448 abis_nm_event_reports(bts, 0);
449
450 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000451 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000452
Harald Welte702d8702008-12-26 20:25:35 +0000453 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000454 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte702d8702008-12-26 20:25:35 +0000455
456 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000457 abis_nm_bs11_reset_resource(bts);
Harald Welte702d8702008-12-26 20:25:35 +0000458
459 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000460 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte702d8702008-12-26 20:25:35 +0000461
Harald Welte52b1f982008-12-23 20:25:15 +0000462 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
463 abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */
464 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
465 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
466
467 /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */
468 abis_nm_conn_terr_sign(trx, 0, 1, 0xff);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000469 set_ts_e1link(&trx->ts[0], 0, 1, 0xff);
Harald Welte52b1f982008-12-23 20:25:15 +0000470 abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */
471
472 /* Use TEI 1 for signalling */
473 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01);
474 abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000475
476#ifdef HAVE_TRX1
Harald Welte52b1f982008-12-23 20:25:15 +0000477 /* TRX 1 */
478 abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff);
479 /* FIXME: TRX ATTRIBUTE */
480 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02);
481#endif
482
483 /* SET CHANNEL ATTRIBUTE TS1 */
Harald Welte23887b62009-02-18 03:37:20 +0000484 abis_nm_set_channel_attr(&trx->ts[1], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000485 /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000486 set_ts_e1link(&trx->ts[1], 0, 2, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000487 abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1);
488
489 /* SET CHANNEL ATTRIBUTE TS2 */
Harald Welte23887b62009-02-18 03:37:20 +0000490 abis_nm_set_channel_attr(&trx->ts[2], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000491 /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000492 set_ts_e1link(&trx->ts[2], 0, 2, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000493 abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2);
494
495 /* SET CHANNEL ATTRIBUTE TS3 */
Harald Welte23887b62009-02-18 03:37:20 +0000496 abis_nm_set_channel_attr(&trx->ts[3], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000497 /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000498 set_ts_e1link(&trx->ts[3], 0, 2, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000499 abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3);
500
501 /* SET CHANNEL ATTRIBUTE TS4 */
Harald Welte23887b62009-02-18 03:37:20 +0000502 abis_nm_set_channel_attr(&trx->ts[4], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000503 /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000504 set_ts_e1link(&trx->ts[4], 0, 3, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000505 abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0);
506
507 /* SET CHANNEL ATTRIBUTE TS5 */
Harald Welte23887b62009-02-18 03:37:20 +0000508 abis_nm_set_channel_attr(&trx->ts[5], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000509 /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000510 set_ts_e1link(&trx->ts[5], 0, 3, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000511 abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1);
512
513 /* SET CHANNEL ATTRIBUTE TS6 */
Harald Welte23887b62009-02-18 03:37:20 +0000514 abis_nm_set_channel_attr(&trx->ts[6], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000515 /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000516 set_ts_e1link(&trx->ts[6], 0, 3, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000517 abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2);
518
519 /* SET CHANNEL ATTRIBUTE TS7 */
Harald Welte23887b62009-02-18 03:37:20 +0000520 abis_nm_set_channel_attr(&trx->ts[7], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000521 /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000522 set_ts_e1link(&trx->ts[7], 0, 3, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000523 abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3);
524
525 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000526 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000527
528 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000529 abis_nm_bs11_reset_resource(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000530
531 /* restart sending event reports */
532 abis_nm_event_reports(bts, 1);
533}
534
Harald Welte8c1d0e42009-02-15 03:38:12 +0000535static void bootstrap_om(struct gsm_bts *bts)
536{
537 fprintf(stdout, "bootstrapping OML\n");
538
539 switch (bts->type) {
540 case GSM_BTS_TYPE_BS11:
541 bootstrap_om_bs11(bts);
542 break;
543 case GSM_BTS_TYPE_NANOBTS_900:
544 case GSM_BTS_TYPE_NANOBTS_1800:
545 bootstrap_om_nanobts(bts);
546 break;
547 default:
548 fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type);
549 }
550}
551
Harald Welted1252502009-01-01 01:50:32 +0000552static int shutdown_om(struct gsm_bts *bts)
553{
554 /* stop sending event reports */
555 abis_nm_event_reports(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000556
Harald Welted1252502009-01-01 01:50:32 +0000557 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000558 abis_nm_bs11_db_transmission(bts, 1);
Harald Welted1252502009-01-01 01:50:32 +0000559
560 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000561 abis_nm_bs11_db_transmission(bts, 0);
Harald Welted1252502009-01-01 01:50:32 +0000562
563 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000564 abis_nm_bs11_reset_resource(bts);
Harald Welted1252502009-01-01 01:50:32 +0000565
566 return 0;
567}
568
569static int shutdown_net(struct gsm_network *net)
570{
571 int i;
572 for (i = 0; i < net->num_bts; i++) {
573 int rc;
574 rc = shutdown_om(&net->bts[i]);
575 if (rc < 0)
576 return rc;
577 }
578
579 return 0;
580}
Harald Welte52b1f982008-12-23 20:25:15 +0000581
582struct bcch_info {
583 u_int8_t type;
584 u_int8_t len;
585 const u_int8_t *data;
586};
587
588/*
589SYSTEM INFORMATION TYPE 1
590 Cell channel description
591 Format-ID bit map 0
592 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
593 RACH Control Parameters
594 maximum 7 retransmissions
595 8 slots used to spread transmission
596 cell not barred for access
597 call reestablishment not allowed
598 Access Control Class = 0000
599*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000600static u_int8_t si1[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000601 /* header */0x55, 0x06, 0x19,
602 /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
603 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,
604 /* rach */0xD5, 0x00, 0x00,
605 /* s1 reset*/0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000606};
607
608/*
609 SYSTEM INFORMATION TYPE 2
610 Neighbour Cells Description
611 EXT-IND: Carries the complete BA
612 BA-IND = 0
613 Format-ID bit map 0
614 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
615 NCC permitted (NCC) = FF
616 RACH Control Parameters
617 maximum 7 retransmissions
618 8 slots used to spread transmission
619 cell not barred for access
620 call reestablishment not allowed
621 Access Control Class = 0000
622*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000623static u_int8_t si2[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000624 /* header */0x59, 0x06, 0x1A,
625 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
626 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
627 /* ncc */0xFF,
628 /* rach*/0xD5, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +0000629};
630
631/*
632SYSTEM INFORMATION TYPE 3
633 Cell identity = 00001 (1h)
634 Location area identification
635 Mobile Country Code (MCC): 001
636 Mobile Network Code (MNC): 01
637 Location Area Code (LAC): 00001 (1h)
638 Control Channel Description
639 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
640 0 blocks reserved for access grant
641 1 channel used for CCCH, with SDCCH
642 5 multiframes period for PAGING REQUEST
643 Time-out T3212 = 0
644 Cell Options BCCH
645 Power control indicator: not set
646 MSs shall not use uplink DTX
647 Radio link timeout = 36
648 Cell Selection Parameters
649 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
Harald Welte3b2ec422008-12-29 04:11:14 +0000650 max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max)
Harald Welte52b1f982008-12-23 20:25:15 +0000651 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
652 Half rate support (NECI): New establishment causes are not supported
653 min.RX signal level for MS = 0
654 RACH Control Parameters
655 maximum 7 retransmissions
656 8 slots used to spread transmission
657 cell not barred for access
658 call reestablishment not allowed
659 Access Control Class = 0000
660 SI 3 Rest Octets
661 Cell Bar Qualify (CBQ): 0
662 Cell Reselect Offset = 0 dB
663 Temporary Offset = 0 dB
664 Penalty Time = 20 s
665 System Information 2ter Indicator (2TI): 0 = not available
666 Early Classmark Sending Control (ECSC): 0 = forbidden
667 Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
668*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000669static u_int8_t si3[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000670 /* header */0x49, 0x06, 0x1B,
671 /* cell */0x00, 0x01,
672 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
673 /* desc */0x01, 0x03, 0x00,
674 /* option*/0x28,
675 /* selection*/0x62, 0x00,
676 /* rach */0xD5, 0x00, 0x00,
677 /* reset*/0x80, 0x00, 0x00, 0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000678};
679
680/*
681SYSTEM INFORMATION TYPE 4
682 Location area identification
683 Mobile Country Code (MCC): 001
684 Mobile Network Code (MNC): 01
685 Location Area Code (LAC): 00001 (1h)
686 Cell Selection Parameters
687 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
688 max.TX power level MS may use for CCH = 2
689 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
690 Half rate support (NECI): New establishment causes are not supported
691 min.RX signal level for MS = 0
692 RACH Control Parameters
693 maximum 7 retransmissions
694 8 slots used to spread transmission
695 cell not barred for access
696 call reestablishment not allowed
697 Access Control Class = 0000
698 Channel Description
699 Type = SDCCH/4[2]
700 Timeslot Number: 0
701 Training Sequence Code: 7h
702 ARFCN: 1
703 SI Rest Octets
704 Cell Bar Qualify (CBQ): 0
705 Cell Reselect Offset = 0 dB
706 Temporary Offset = 0 dB
707 Penalty Time = 20 s
708*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000709static u_int8_t si4[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000710 /* header */0x41, 0x06, 0x1C,
711 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
712 /* sel */0x62, 0x00,
713 /* rach*/0xD5, 0x00, 0x00,
714 /* var */0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000715 0x2B, 0x2B, 0x2B
716};
717
718/*
719 SYSTEM INFORMATION TYPE 5
720 Neighbour Cells Description
721 EXT-IND: Carries the complete BA
722 BA-IND = 0
723 Format-ID bit map 0
724 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
725*/
726
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000727static u_int8_t si5[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000728 /* header without l2 len*/0x06, 0x1D,
729 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
730 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000731};
732
733// SYSTEM INFORMATION TYPE 6
734
735/*
736SACCH FILLING
737 System Info Type: SYSTEM INFORMATION 6
738 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
739
740SYSTEM INFORMATION TYPE 6
741 Cell identity = 00001 (1h)
742 Location area identification
743 Mobile Country Code (MCC): 001
744 Mobile Network Code (MNC): 01
745 Location Area Code (LAC): 00001 (1h)
746 Cell Options SACCH
747 Power control indicator: not set
748 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
749 Radio link timeout = 36
750 NCC permitted (NCC) = FF
751*/
752
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000753static u_int8_t si6[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000754 /* header */0x06, 0x1E,
755 /* cell id*/ 0x00, 0x01,
756 /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01,
757 /* options */ 0x28,
758 /* ncc */ 0xFF,
Harald Welte52b1f982008-12-23 20:25:15 +0000759};
760
761
762
763static const struct bcch_info bcch_infos[] = {
764 {
765 .type = RSL_SYSTEM_INFO_1,
766 .len = sizeof(si1),
767 .data = si1,
768 }, {
769 .type = RSL_SYSTEM_INFO_2,
770 .len = sizeof(si2),
771 .data = si2,
772 }, {
773 .type = RSL_SYSTEM_INFO_3,
774 .len = sizeof(si3),
775 .data = si3,
776 }, {
777 .type = RSL_SYSTEM_INFO_4,
778 .len = sizeof(si4),
779 .data = si4,
780 },
781};
782
Holger Freyther24287b62008-12-28 16:32:41 +0000783static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1)
784static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2)
785static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3)
786static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4)
Harald Welte104604e2008-12-28 16:36:11 +0000787static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5)
788static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6)
Holger Freyther24287b62008-12-28 16:32:41 +0000789
Harald Welte52b1f982008-12-23 20:25:15 +0000790/* set all system information types */
Harald Weltee79769b2009-02-07 00:48:17 +0000791static int set_system_infos(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000792{
793 int i;
794
795 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
Harald Weltee79769b2009-02-07 00:48:17 +0000796 rsl_bcch_info(trx, bcch_infos[i].type,
Harald Welte52b1f982008-12-23 20:25:15 +0000797 bcch_infos[i].data,
798 bcch_infos[i].len);
799 }
Harald Weltee79769b2009-02-07 00:48:17 +0000800 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
801 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
Harald Weltead384642008-12-26 10:20:07 +0000802
803 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000804}
805
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000806/*
807 * Patch the various SYSTEM INFORMATION tables to update
808 * the LAI
809 */
810static void patch_tables(struct gsm_bts *bts)
811{
Harald Welte98981882009-01-06 18:59:11 +0000812 u_int8_t arfcn_low = ARFCN & 0xff;
813 u_int8_t arfcn_high = (ARFCN >> 8) & 0x0f;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000814 /* covert the raw packet to the struct */
815 struct gsm48_system_information_type_3 *type_3 =
816 (struct gsm48_system_information_type_3*)&si3;
817 struct gsm48_system_information_type_4 *type_4 =
818 (struct gsm48_system_information_type_4*)&si4;
819 struct gsm48_system_information_type_6 *type_6 =
820 (struct gsm48_system_information_type_6*)&si6;
Harald Welteb84e2f42008-12-28 23:42:04 +0000821 struct gsm48_loc_area_id lai;
822
823 gsm0408_generate_lai(&lai, bts->network->country_code,
824 bts->network->network_code, bts->location_area_code);
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000825
826 /* assign the MCC and MNC */
Harald Welteb84e2f42008-12-28 23:42:04 +0000827 type_3->lai = lai;
828 type_4->lai = lai;
829 type_6->lai = lai;
Harald Welte98981882009-01-06 18:59:11 +0000830
Harald Welte94009322009-02-15 15:38:42 +0000831 /* patch ARFCN into BTS Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000832 msg_2[74] &= 0xf0;
833 msg_2[74] |= arfcn_high;
834 msg_2[75] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000835 nanobts_attr_bts[42] &= 0xf0;
836 nanobts_attr_bts[42] |= arfcn_high;
837 nanobts_attr_bts[43] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000838
Harald Welte94009322009-02-15 15:38:42 +0000839 /* patch ARFCN into TRX Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000840 msg_6[7] &= 0xf0;
841 msg_6[7] |= arfcn_high;
842 msg_6[8] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000843 nanobts_attr_radio[5] &= 0xf0;
844 nanobts_attr_radio[5] |= arfcn_high;
845 nanobts_attr_radio[6] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000846
847 type_4->data[2] &= 0xf0;
848 type_4->data[2] |= arfcn_high;
849 type_4->data[3] = arfcn_low;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000850
851 /* patch Control Channel Description 10.5.2.11 */
852 type_3->control_channel_desc = bts->chan_desc;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000853}
854
855
Harald Weltee79769b2009-02-07 00:48:17 +0000856static void bootstrap_rsl(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000857{
Harald Welteb84e2f42008-12-28 23:42:04 +0000858 fprintf(stdout, "bootstrapping RSL MCC=%u MNC=%u\n", MCC, MNC);
Harald Weltee79769b2009-02-07 00:48:17 +0000859 set_system_infos(trx);
Harald Welte52b1f982008-12-23 20:25:15 +0000860}
861
Harald Welte1fa60c82009-02-09 18:13:26 +0000862void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
Harald Weltead384642008-12-26 10:20:07 +0000863{
864 switch (event) {
Harald Welte1fa60c82009-02-09 18:13:26 +0000865 case EVT_E1_TEI_UP:
866 switch (type) {
867 case E1INP_SIGN_OML:
868 bootstrap_om(trx->bts);
869 break;
870 case E1INP_SIGN_RSL:
871 bootstrap_rsl(trx);
872 break;
873 default:
874 break;
875 }
Harald Weltead384642008-12-26 10:20:07 +0000876 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000877 case EVT_E1_TEI_DN:
878 fprintf(stderr, "Lost some E1 TEI link\n");
879 /* FIXME: deal with TEI or L1 link loss */
Harald Weltead384642008-12-26 10:20:07 +0000880 break;
881 default:
Harald Weltead384642008-12-26 10:20:07 +0000882 break;
883 }
884}
885
886static int bootstrap_network(void)
Harald Welte52b1f982008-12-23 20:25:15 +0000887{
888 struct gsm_bts *bts;
889
890 /* initialize our data structures */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000891 gsmnet = gsm_network_init(1, BTS_TYPE, MCC, MNC);
Harald Weltead384642008-12-26 10:20:07 +0000892 if (!gsmnet)
893 return -ENOMEM;
Harald Weltef5cbab72008-12-30 18:00:15 +0000894
Harald Weltefd2fb452009-02-21 13:00:57 +0000895 gsmnet->name_long = "OpenBSC";
896 gsmnet->name_short = "OpenBSC";
Harald Welte52b1f982008-12-23 20:25:15 +0000897 bts = &gsmnet->bts[0];
898 bts->location_area_code = 1;
Harald Welte98981882009-01-06 18:59:11 +0000899 bts->trx[0].arfcn = ARFCN;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000900
901 /* Control Channel Description */
902 memset(&bts->chan_desc, 0, sizeof(struct gsm48_control_channel_descr));
Harald Welte41fbf442009-02-24 22:34:22 +0000903 bts->chan_desc.att = 1;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000904 bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
905 bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
906 bts->chan_desc.t3212 = 0;
907
Harald Welte98981882009-01-06 18:59:11 +0000908 patch_tables(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000909
Holger Freyther1fd34142009-02-09 23:42:03 +0000910 paging_init(bts);
Harald Welte38c2f132009-01-06 23:10:57 +0000911
Holger Freyther36650b82009-04-19 06:35:16 +0000912 if (db_init(database_name, gsmnet)) {
Holger Freytheref7f7ce2009-04-19 06:35:12 +0000913 printf("DB: Failed to init database. Please check the option settings.\n");
914 return -1;
915 }
916 printf("DB: Database initialized.\n");
917
918 if (db_prepare()) {
919 printf("DB: Failed to prepare database.\n");
920 return -1;
921 }
922 printf("DB: Database prepared.\n");
923
Holger Freyther219518d2009-01-02 22:04:43 +0000924 telnet_init(gsmnet, 4242);
Harald Weltead384642008-12-26 10:20:07 +0000925
Harald Welte1fa60c82009-02-09 18:13:26 +0000926 /* E1 mISDN input setup */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000927 if (BTS_TYPE == GSM_BTS_TYPE_BS11)
928 return e1_config(bts);
929 else
930 return ia_config(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000931}
Harald Weltef6b7a902008-12-26 00:05:11 +0000932
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000933static void create_pcap_file(char *file)
934{
935 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
936 int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
937
938 if (fd < 0) {
939 perror("Failed to open file for pcap");
940 return;
941 }
942
Holger Freyther0469cf62009-03-31 12:14:16 +0000943 e1_set_pcap_fd(fd);
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000944}
945
Holger Freytherb332f612008-12-27 12:46:51 +0000946static void print_usage()
947{
948 printf("Usage: bsc_hack\n");
949}
950
951static void print_help()
952{
953 printf(" Some useful help...\n");
954 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
Holger Freytherefde7fb2008-12-28 14:14:56 +0000955 printf(" -s --disable-color\n");
956 printf(" -n --network-code number(MNC) \n");
957 printf(" -c --country-code number (MCC) \n");
Harald Welte98981882009-01-06 18:59:11 +0000958 printf(" -f --arfcn number The frequency ARFCN\n");
Holger Freytherbde36102008-12-28 22:51:39 +0000959 printf(" -l --database db-name The database to use\n");
Holger Freyther89824fc2008-12-30 16:18:18 +0000960 printf(" -a --authorize-everyone Allow everyone into the network.\n");
Holger Freythere97f7fb2008-12-31 18:52:11 +0000961 printf(" -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n");
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000962 printf(" -p --pcap file The filename of the pcap file\n");
Harald Weltee1bd2412009-02-15 14:40:09 +0000963 printf(" -t --bts-type type The BTS type (bs11, nanobts900, nanobts1800)\n");
Holger Freytherb332f612008-12-27 12:46:51 +0000964 printf(" -h --help this text\n");
965}
966
967static void handle_options(int argc, char** argv)
968{
969 while (1) {
970 int option_index = 0, c;
971 static struct option long_options[] = {
972 {"help", 0, 0, 'h'},
973 {"debug", 1, 0, 'd'},
Holger Freytherefde7fb2008-12-28 14:14:56 +0000974 {"disable-color", 0, 0, 's'},
975 {"network-code", 1, 0, 'n'},
976 {"country-code", 1, 0, 'c'},
Holger Freytherbde36102008-12-28 22:51:39 +0000977 {"database", 1, 0, 'l'},
Holger Freyther89824fc2008-12-30 16:18:18 +0000978 {"authorize-everyone", 0, 0, 'a'},
Holger Freythere97f7fb2008-12-31 18:52:11 +0000979 {"reject-cause", 1, 0, 'r'},
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000980 {"pcap", 1, 0, 'p'},
Harald Welte98981882009-01-06 18:59:11 +0000981 {"arfcn", 1, 0, 'f'},
Harald Welte8c1d0e42009-02-15 03:38:12 +0000982 {"bts-type", 1, 0, 't'},
Holger Freytherb332f612008-12-27 12:46:51 +0000983 {0, 0, 0, 0}
984 };
985
Harald Welte8c1d0e42009-02-15 03:38:12 +0000986 c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:",
Holger Freytherb332f612008-12-27 12:46:51 +0000987 long_options, &option_index);
988 if (c == -1)
989 break;
990
991 switch (c) {
992 case 'h':
993 print_usage();
994 print_help();
995 exit(0);
Holger Freytherefde7fb2008-12-28 14:14:56 +0000996 case 's':
Holger Freytherb332f612008-12-27 12:46:51 +0000997 debug_use_color(0);
998 break;
999 case 'd':
1000 debug_parse_category_mask(optarg);
1001 break;
Holger Freytherefde7fb2008-12-28 14:14:56 +00001002 case 'n':
1003 MNC = atoi(optarg);
1004 break;
1005 case 'c':
1006 MCC = atoi(optarg);
1007 break;
Harald Welte98981882009-01-06 18:59:11 +00001008 case 'f':
1009 ARFCN = atoi(optarg);
1010 break;
Harald Welte8965da42009-01-06 18:09:02 +00001011 case 'l':
Holger Freytherbde36102008-12-28 22:51:39 +00001012 database_name = strdup(optarg);
1013 break;
Holger Freyther89824fc2008-12-30 16:18:18 +00001014 case 'a':
1015 gsm0408_allow_everyone(1);
1016 break;
Holger Freythere97f7fb2008-12-31 18:52:11 +00001017 case 'r':
1018 gsm0408_set_reject_cause(atoi(optarg));
1019 break;
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001020 case 'p':
1021 create_pcap_file(optarg);
1022 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +00001023 case 't':
1024 BTS_TYPE = parse_btstype(optarg);
1025 break;
Holger Freytherb332f612008-12-27 12:46:51 +00001026 default:
1027 /* ignore */
1028 break;
1029 }
1030 }
1031}
1032
Harald Welted1252502009-01-01 01:50:32 +00001033static void signal_handler(int signal)
1034{
1035 fprintf(stdout, "signal %u received\n", signal);
1036
1037 switch (signal) {
1038 case SIGHUP:
1039 case SIGABRT:
1040 shutdown_net(gsmnet);
1041 break;
1042 default:
1043 break;
1044 }
1045}
1046
Harald Weltef6b7a902008-12-26 00:05:11 +00001047int main(int argc, char **argv)
1048{
Harald Welte1fa60c82009-02-09 18:13:26 +00001049 int rc;
1050
Holger Freytherb332f612008-12-27 12:46:51 +00001051 /* parse options */
1052 handle_options(argc, argv);
1053
Harald Welte65ccf882009-02-24 22:36:20 +00001054 /* seed the PRNG */
1055 srand(time(NULL));
1056
Harald Welte1fa60c82009-02-09 18:13:26 +00001057 rc = bootstrap_network();
1058 if (rc < 0)
1059 exit(1);
Harald Weltef6b7a902008-12-26 00:05:11 +00001060
Harald Welted1252502009-01-01 01:50:32 +00001061 signal(SIGHUP, &signal_handler);
1062 signal(SIGABRT, &signal_handler);
1063
Harald Weltef6b7a902008-12-26 00:05:11 +00001064 while (1) {
1065 bsc_select_main();
1066 }
1067}