blob: 10667295bc85279572ff35e0780abf45dbdb45ce [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;
Holger Freytherb5c00f52009-04-22 22:08:07 +000059static int release_l2 = 0;
Harald Welte8c1d0e42009-02-15 03:38:12 +000060static enum gsm_bts_type BTS_TYPE = GSM_BTS_TYPE_BS11;
Holger Freytherbde36102008-12-28 22:51:39 +000061static const char *database_name = "hlr.sqlite3";
Holger Freytherefde7fb2008-12-28 14:14:56 +000062
Harald Welte52b1f982008-12-23 20:25:15 +000063/* The following definitions are for OM and NM packets that we cannot yet
64 * generate by code but we just pass on */
65
66// BTS Site Manager, SET ATTRIBUTES
67
68/*
69 Object Class: BTS Site Manager
70 Instance 1: FF
71 Instance 2: FF
72 Instance 3: FF
73SET ATTRIBUTES
74 sAbisExternalTime: 2007/09/08 14:36:11
75 omLAPDRelTimer: 30sec
76 shortLAPDIntTimer: 5sec
77 emergencyTimer1: 10 minutes
78 emergencyTimer2: 0 minutes
79*/
80
81unsigned char msg_1[] =
82{
Harald Weltecd993872009-02-15 16:16:28 +000083 0xD0, 0x00, 0xFF, 0xFF, 0xFF,
84 NM_ATT_BS11_ABIS_EXT_TIME, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE,
85 0x02, 0x00, 0x1E,
86 0xE8, 0x01, 0x05,
87 0x42, 0x02, 0x00, 0x0A,
88 0x44, 0x02, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +000089};
90
91// BTS, SET BTS ATTRIBUTES
92
93/*
94 Object Class: BTS
95 BTS relat. Number: 0
96 Instance 2: FF
97 Instance 3: FF
98SET BTS ATTRIBUTES
99 bsIdentityCode / BSIC:
100 PLMN_colour_code: 7h
101 BS_colour_code: 7h
102 BTS Air Timer T3105: 4 ,unit 10 ms
103 btsIsHopping: FALSE
Harald Welte83282292009-02-01 16:22:19 +0000104 periodCCCHLoadIndication: 1sec
Holger Freyther3b910432009-02-11 00:43:48 +0000105 thresholdCCCHLoadIndication: 0%
Harald Welte52b1f982008-12-23 20:25:15 +0000106 cellAllocationNumber: 00h = GSM 900
107 enableInterferenceClass: 00h = Disabled
108 fACCHQual: 6 (FACCH stealing flags minus 1)
109 intaveParameter: 31 SACCH multiframes
110 interferenceLevelBoundaries:
111 Interference Boundary 1: 0Ah
112 Interference Boundary 2: 0Fh
113 Interference Boundary 3: 14h
114 Interference Boundary 4: 19h
115 Interference Boundary 5: 1Eh
116 mSTxPwrMax: 11
117 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
118 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
119 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
120 30=33dBm, 31=32dBm
121 ny1:
122 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
123 powerOutputThresholds:
124 Out Power Fault Threshold: -10 dB
125 Red Out Power Threshold: - 6 dB
126 Excessive Out Power Threshold: 5 dB
127 rACHBusyThreshold: -127 dBm
128 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
129 rfResourceIndicationPeriod: 125 SACCH multiframes
130 T200:
131 SDCCH: 044 in 5 ms
132 FACCH/Full rate: 031 in 5 ms
133 FACCH/Half rate: 041 in 5 ms
134 SACCH with TCH SAPI0: 090 in 10 ms
135 SACCH with SDCCH: 090 in 10 ms
136 SDCCH with SAPI3: 090 in 5 ms
137 SACCH with TCH SAPI3: 135 in 10 ms
138 tSync: 9000 units of 10 msec
139 tTrau: 9000 units of 10 msec
140 enableUmLoopTest: 00h = disabled
141 enableExcessiveDistance: 00h = Disabled
142 excessiveDistance: 64km
143 hoppingMode: 00h = baseband hopping
144 cellType: 00h = Standard Cell
145 BCCH ARFCN / bCCHFrequency: 1
146*/
147
148unsigned char msg_2[] =
149{
Harald Welte8c1d0e42009-02-15 03:38:12 +0000150 0x41, 0x01, 0x00, 0xFF, 0xFF,
151 NM_ATT_BSIC, 0x3F,
152 NM_ATT_BTS_AIR_TIMER, 0x04,
Harald Weltecd993872009-02-15 16:16:28 +0000153 NM_ATT_BS11_BTSLS_HOPPING, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000154 NM_ATT_CCCH_L_I_P, 0x01,
155 NM_ATT_CCCH_L_T, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000156 NM_ATT_BS11_CELL_ALLOC_NR, 0x00,
157 NM_ATT_BS11_ENA_INTERF_CLASS, 0x00,
158 NM_ATT_BS11_FACCH_QUAL, 0x06,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000159 NM_ATT_INTAVE_PARAM, 0x1F,
160 NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B,
161 NM_ATT_CCCH_L_T, 0x23,
162 NM_ATT_GSM_TIME, 0x28, 0x00,
163 NM_ATT_ADM_STATE, 0x03,
164 NM_ATT_RACH_B_THRESH, 0x7F,
165 NM_ATT_LDAVG_SLOTS, 0x00, 0xFA,
Harald Weltecd993872009-02-15 16:16:28 +0000166 NM_ATT_BS11_RF_RES_IND_PER, 0x7D,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000167 NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87,
Harald Weltecd993872009-02-15 16:16:28 +0000168 NM_ATT_BS11_TSYNC, 0x23, 0x28,
169 NM_ATT_BS11_TTRAU, 0x23, 0x28,
170 NM_ATT_TEST_DUR, 0x01, 0x00,
171 NM_ATT_OUTST_ALARM, 0x01, 0x00,
172 NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40,
173 NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00,
174 NM_ATT_BS11_PLL, 0x01, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000175 NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/,
Harald Welte52b1f982008-12-23 20:25:15 +0000176};
177
178// Handover Recognition, SET ATTRIBUTES
179
180/*
181Illegal Contents GSM Formatted O&M Msg
182 Object Class: Handover Recognition
183 BTS relat. Number: 0
184 Instance 2: FF
185 Instance 3: FF
186SET ATTRIBUTES
187 enableDelayPowerBudgetHO: 00h = Disabled
188 enableDistanceHO: 00h = Disabled
189 enableInternalInterCellHandover: 00h = Disabled
190 enableInternalIntraCellHandover: 00h = Disabled
191 enablePowerBudgetHO: 00h = Disabled
192 enableRXLEVHO: 00h = Disabled
193 enableRXQUALHO: 00h = Disabled
194 hoAveragingDistance: 8 SACCH multiframes
195 hoAveragingLev:
196 A_LEV_HO: 8 SACCH multiframes
197 W_LEV_HO: 1 SACCH multiframes
198 hoAveragingPowerBudget: 16 SACCH multiframes
199 hoAveragingQual:
200 A_QUAL_HO: 8 SACCH multiframes
201 W_QUAL_HO: 2 SACCH multiframes
202 hoLowerThresholdLevDL: (10 - 110) dBm
203 hoLowerThresholdLevUL: (5 - 110) dBm
204 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
205 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
206 hoThresholdLevDLintra : (20 - 110) dBm
207 hoThresholdLevULintra: (20 - 110) dBm
208 hoThresholdMsRangeMax: 20 km
209 nCell: 06h
210 timerHORequest: 3 ,unit 2 SACCH multiframes
211*/
212
213unsigned char msg_3[] =
214{
Harald Weltecd993872009-02-15 16:16:28 +0000215 0xD0, 0xA1, 0x00, 0xFF, 0xFF,
216 0xD0, 0x00,
217 0x64, 0x00,
218 0x67, 0x00,
219 0x68, 0x00,
220 0x6A, 0x00,
221 0x6C, 0x00,
222 0x6D, 0x00,
223 0x6F, 0x08,
224 0x70, 0x08, 0x01,
225 0x71, 0x10, 0x10, 0x10,
226 0x72, 0x08, 0x02,
227 0x73, 0x0A,
228 0x74, 0x05,
229 0x75, 0x06,
230 0x76, 0x06,
231 0x78, 0x14,
232 0x79, 0x14,
233 0x7A, 0x14,
234 0x7D, 0x06,
235 0x92, 0x03, 0x20, 0x01, 0x00,
236 0x45, 0x01, 0x00,
237 0x48, 0x01, 0x00,
238 0x5A, 0x01, 0x00,
239 0x5B, 0x01, 0x05,
240 0x5E, 0x01, 0x1A,
241 0x5F, 0x01, 0x20,
242 0x9D, 0x01, 0x00,
243 0x47, 0x01, 0x00,
244 0x5C, 0x01, 0x64,
245 0x5D, 0x01, 0x1E,
246 0x97, 0x01, 0x20,
247 0xF7, 0x01, 0x3C,
Harald Welte52b1f982008-12-23 20:25:15 +0000248};
249
250// Power Control, SET ATTRIBUTES
251
252/*
253 Object Class: Power Control
254 BTS relat. Number: 0
255 Instance 2: FF
256 Instance 3: FF
257SET ATTRIBUTES
258 enableMsPowerControl: 00h = Disabled
259 enablePowerControlRLFW: 00h = Disabled
260 pcAveragingLev:
261 A_LEV_PC: 4 SACCH multiframes
262 W_LEV_PC: 1 SACCH multiframes
263 pcAveragingQual:
264 A_QUAL_PC: 4 SACCH multiframes
265 W_QUAL_PC: 2 SACCH multiframes
266 pcLowerThresholdLevDL: 0Fh
267 pcLowerThresholdLevUL: 0Ah
268 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
269 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
270 pcRLFThreshold: 0Ch
271 pcUpperThresholdLevDL: 14h
272 pcUpperThresholdLevUL: 0Fh
273 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
274 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
275 powerConfirm: 2 ,unit 2 SACCH multiframes
276 powerControlInterval: 2 ,unit 2 SACCH multiframes
277 powerIncrStepSize: 02h = 4 dB
278 powerRedStepSize: 01h = 2 dB
279 radioLinkTimeoutBs: 64 SACCH multiframes
280 enableBSPowerControl: 00h = disabled
281*/
282
283unsigned char msg_4[] =
284{
Harald Weltecd993872009-02-15 16:16:28 +0000285 0xD0, 0xA2, 0x00, 0xFF, 0xFF,
286 NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00,
287 NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00,
288 0x7E, 0x04, 0x01,
289 0x7F, 0x04, 0x02,
290 0x80, 0x0F,
291 0x81, 0x0A,
292 0x82, 0x05,
293 0x83, 0x05,
294 0x84, 0x0C,
295 0x85, 0x14,
296 0x86, 0x0F,
297 0x87, 0x04,
298 0x88, 0x04,
299 0x89, 0x02,
300 0x8A, 0x02,
301 0x8B, 0x02,
302 0x8C, 0x01,
303 0x8D, 0x40,
304 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
Harald Welte52b1f982008-12-23 20:25:15 +0000305};
306
307
308// Transceiver, SET TRX ATTRIBUTES (TRX 0)
309
310/*
311 Object Class: Transceiver
312 BTS relat. Number: 0
313 Tranceiver number: 0
314 Instance 3: FF
315SET TRX ATTRIBUTES
316 aRFCNList (HEX): 0001
Harald Weltecd993872009-02-15 16:16:28 +0000317 txPwrMaxReduction: 00h = 30dB
Harald Welte52b1f982008-12-23 20:25:15 +0000318 radioMeasGran: 254 SACCH multiframes
319 radioMeasRep: 01h = enabled
320 memberOfEmergencyConfig: 01h = TRUE
321 trxArea: 00h = TRX doesn't belong to a concentric cell
322*/
323
324unsigned char msg_6[] =
325{
Harald Weltecd993872009-02-15 16:16:28 +0000326 0x44, 0x02, 0x00, 0x00, 0xFF,
327 NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/,
Harald Welte311d0cf2009-02-17 17:45:59 +0000328 NM_ATT_RF_MAXPOWR_R, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000329 NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0xFE,
330 NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01,
331 NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01,
332 NM_ATT_BS11_TRX_AREA, 0x01, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000333};
334
Harald Welte8c1d0e42009-02-15 03:38:12 +0000335static unsigned char nanobts_attr_bts[] = {
336 NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73,
337 NM_ATT_INTAVE_PARAM, 0x06,
338 NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10,
339 NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
340 NM_ATT_MAX_TA, 0x3f,
Harald Welte311d0cf2009-02-17 17:45:59 +0000341 NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */
342 NM_ATT_CCCH_L_T, 10, /* percent */
343 NM_ATT_CCCH_L_I_P, 1, /* seconds */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000344 NM_ATT_RACH_B_THRESH, 0x0a,
345 NM_ATT_LDAVG_SLOTS, 0x03, 0xe8,
346 NM_ATT_BTS_AIR_TIMER, 0x80,
347 NM_ATT_NY1, 0x0a,
348 NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
349 NM_ATT_BSIC, 0x20,
350};
Harald Welte52b1f982008-12-23 20:25:15 +0000351
Harald Welte8c1d0e42009-02-15 03:38:12 +0000352static unsigned char nanobts_attr_radio[] = {
Harald Welte311d0cf2009-02-17 17:45:59 +0000353 NM_ATT_RF_MAXPOWR_R, 0x0c,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000354 NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
355};
356
Harald Welte5c1e4582009-02-15 11:57:29 +0000357static unsigned char nanobts_attr_e0[] = {
358 0x85, 0x00,
359 0x81, 0x0b, 0xbb, /* TCP PORT for RSL */
360};
361
Harald Welte8c1d0e42009-02-15 03:38:12 +0000362int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
363 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
364{
365 struct gsm_bts *bts;
366 struct gsm_bts_trx *trx;
367 struct gsm_bts_trx_ts *ts;
368
369 /* This is currently only required on nanoBTS */
370
371 switch (evt) {
372 case EVT_STATECHG_OPER:
373 switch (obj_class) {
374 case NM_OC_SITE_MANAGER:
375 bts = container_of(obj, struct gsm_bts, site_mgr);
376 if (old_state->operational != 2 && new_state->operational == 2) {
377 abis_nm_opstart(bts, NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
378 }
379 break;
380 case NM_OC_BTS:
381 bts = obj;
382 if (new_state->availability == 5) {
383 abis_nm_set_bts_attr(bts, nanobts_attr_bts,
384 sizeof(nanobts_attr_bts));
385 abis_nm_opstart(bts, NM_OC_BTS,
386 bts->nr, 0xff, 0xff);
387 abis_nm_chg_adm_state(bts, NM_OC_BTS,
388 bts->nr, 0xff, 0xff,
389 NM_STATE_UNLOCKED);
390 }
391 break;
392 case NM_OC_RADIO_CARRIER:
393 trx = obj;
394 if (new_state->availability == 3) {
395 abis_nm_set_radio_attr(trx, nanobts_attr_radio,
396 sizeof(nanobts_attr_radio));
397 abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER,
398 trx->bts->nr, trx->nr, 0xff);
399 abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER,
400 trx->bts->nr, trx->nr, 0xff,
401 NM_STATE_UNLOCKED);
402 }
403 break;
404 case NM_OC_CHANNEL:
405 ts = obj;
406 trx = ts->trx;
407 if (new_state->availability == 5) {
408 if (ts->nr == 0 && trx == trx->bts->c0)
Harald Weltee1bd2412009-02-15 14:40:09 +0000409 abis_nm_set_channel_attr(ts, NM_CHANC_BCCH_CBCH);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000410 else
411 abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull);
412 abis_nm_opstart(trx->bts, NM_OC_CHANNEL,
413 trx->bts->nr, trx->nr, ts->nr);
414 abis_nm_chg_adm_state(trx->bts, NM_OC_CHANNEL,
415 trx->bts->nr, trx->nr, ts->nr,
416 NM_STATE_UNLOCKED);
417 }
418 break;
419 case NM_OC_BASEB_TRANSC:
420 trx = container_of(obj, struct gsm_bts_trx, bb_transc);
421 if (new_state->availability == 5) {
Harald Welte5c1e4582009-02-15 11:57:29 +0000422 abis_nm_ipaccess_msg(trx->bts, 0xe0, NM_OC_BASEB_TRANSC,
423 trx->bts->nr, trx->nr, 0xff,
424 nanobts_attr_e0, sizeof(nanobts_attr_e0));
Harald Welte8c1d0e42009-02-15 03:38:12 +0000425 abis_nm_opstart(trx->bts, NM_OC_BASEB_TRANSC,
426 trx->bts->nr, trx->nr, 0xff);
427 abis_nm_chg_adm_state(trx->bts, NM_OC_BASEB_TRANSC,
428 trx->bts->nr, trx->nr, 0xff,
429 NM_STATE_UNLOCKED);
430 }
431 break;
432 }
433 break;
Holger Freytherff9592f2009-03-09 16:17:14 +0000434 case EVT_STATECHG_ADM:
435 DEBUGP(DMM, "Unhandled state change in %s:%d\n", __func__, __LINE__);
436 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000437 }
438 return 0;
439}
440
441static void bootstrap_om_nanobts(struct gsm_bts *bts)
442{
Harald Weltee1bd2412009-02-15 14:40:09 +0000443 /* We don't do callback based bootstrapping, but event driven (see above) */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000444}
445
446static void bootstrap_om_bs11(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000447{
448 struct gsm_bts_trx *trx = &bts->trx[0];
449
450 /* stop sending event reports */
451 abis_nm_event_reports(bts, 0);
452
453 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000454 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000455
Harald Welte702d8702008-12-26 20:25:35 +0000456 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000457 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte702d8702008-12-26 20:25:35 +0000458
459 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000460 abis_nm_bs11_reset_resource(bts);
Harald Welte702d8702008-12-26 20:25:35 +0000461
462 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000463 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte702d8702008-12-26 20:25:35 +0000464
Harald Welte52b1f982008-12-23 20:25:15 +0000465 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
466 abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */
467 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
468 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
469
470 /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */
471 abis_nm_conn_terr_sign(trx, 0, 1, 0xff);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000472 set_ts_e1link(&trx->ts[0], 0, 1, 0xff);
Harald Welte52b1f982008-12-23 20:25:15 +0000473 abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */
474
475 /* Use TEI 1 for signalling */
476 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01);
477 abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000478
479#ifdef HAVE_TRX1
Harald Welte52b1f982008-12-23 20:25:15 +0000480 /* TRX 1 */
481 abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff);
482 /* FIXME: TRX ATTRIBUTE */
483 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02);
484#endif
485
486 /* SET CHANNEL ATTRIBUTE TS1 */
Harald Welte23887b62009-02-18 03:37:20 +0000487 abis_nm_set_channel_attr(&trx->ts[1], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000488 /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000489 set_ts_e1link(&trx->ts[1], 0, 2, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000490 abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1);
491
492 /* SET CHANNEL ATTRIBUTE TS2 */
Harald Welte23887b62009-02-18 03:37:20 +0000493 abis_nm_set_channel_attr(&trx->ts[2], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000494 /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000495 set_ts_e1link(&trx->ts[2], 0, 2, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000496 abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2);
497
498 /* SET CHANNEL ATTRIBUTE TS3 */
Harald Welte23887b62009-02-18 03:37:20 +0000499 abis_nm_set_channel_attr(&trx->ts[3], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000500 /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000501 set_ts_e1link(&trx->ts[3], 0, 2, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000502 abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3);
503
504 /* SET CHANNEL ATTRIBUTE TS4 */
Harald Welte23887b62009-02-18 03:37:20 +0000505 abis_nm_set_channel_attr(&trx->ts[4], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000506 /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000507 set_ts_e1link(&trx->ts[4], 0, 3, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000508 abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0);
509
510 /* SET CHANNEL ATTRIBUTE TS5 */
Harald Welte23887b62009-02-18 03:37:20 +0000511 abis_nm_set_channel_attr(&trx->ts[5], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000512 /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000513 set_ts_e1link(&trx->ts[5], 0, 3, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000514 abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1);
515
516 /* SET CHANNEL ATTRIBUTE TS6 */
Harald Welte23887b62009-02-18 03:37:20 +0000517 abis_nm_set_channel_attr(&trx->ts[6], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000518 /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000519 set_ts_e1link(&trx->ts[6], 0, 3, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000520 abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2);
521
522 /* SET CHANNEL ATTRIBUTE TS7 */
Harald Welte23887b62009-02-18 03:37:20 +0000523 abis_nm_set_channel_attr(&trx->ts[7], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000524 /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000525 set_ts_e1link(&trx->ts[7], 0, 3, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000526 abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3);
527
528 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000529 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000530
531 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000532 abis_nm_bs11_reset_resource(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000533
534 /* restart sending event reports */
535 abis_nm_event_reports(bts, 1);
536}
537
Harald Welte8c1d0e42009-02-15 03:38:12 +0000538static void bootstrap_om(struct gsm_bts *bts)
539{
540 fprintf(stdout, "bootstrapping OML\n");
541
542 switch (bts->type) {
543 case GSM_BTS_TYPE_BS11:
544 bootstrap_om_bs11(bts);
545 break;
546 case GSM_BTS_TYPE_NANOBTS_900:
547 case GSM_BTS_TYPE_NANOBTS_1800:
548 bootstrap_om_nanobts(bts);
549 break;
550 default:
551 fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type);
552 }
553}
554
Harald Welted1252502009-01-01 01:50:32 +0000555static int shutdown_om(struct gsm_bts *bts)
556{
557 /* stop sending event reports */
558 abis_nm_event_reports(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000559
Harald Welted1252502009-01-01 01:50:32 +0000560 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000561 abis_nm_bs11_db_transmission(bts, 1);
Harald Welted1252502009-01-01 01:50:32 +0000562
563 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000564 abis_nm_bs11_db_transmission(bts, 0);
Harald Welted1252502009-01-01 01:50:32 +0000565
566 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000567 abis_nm_bs11_reset_resource(bts);
Harald Welted1252502009-01-01 01:50:32 +0000568
569 return 0;
570}
571
572static int shutdown_net(struct gsm_network *net)
573{
574 int i;
575 for (i = 0; i < net->num_bts; i++) {
576 int rc;
577 rc = shutdown_om(&net->bts[i]);
578 if (rc < 0)
579 return rc;
580 }
581
582 return 0;
583}
Harald Welte52b1f982008-12-23 20:25:15 +0000584
585struct bcch_info {
586 u_int8_t type;
587 u_int8_t len;
588 const u_int8_t *data;
589};
590
591/*
592SYSTEM INFORMATION TYPE 1
593 Cell channel description
594 Format-ID bit map 0
595 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
596 RACH Control Parameters
597 maximum 7 retransmissions
598 8 slots used to spread transmission
599 cell not barred for access
600 call reestablishment not allowed
601 Access Control Class = 0000
602*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000603static u_int8_t si1[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000604 /* header */0x55, 0x06, 0x19,
605 /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
606 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,
607 /* rach */0xD5, 0x00, 0x00,
608 /* s1 reset*/0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000609};
610
611/*
612 SYSTEM INFORMATION TYPE 2
613 Neighbour Cells Description
614 EXT-IND: Carries the complete BA
615 BA-IND = 0
616 Format-ID bit map 0
617 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
618 NCC permitted (NCC) = FF
619 RACH Control Parameters
620 maximum 7 retransmissions
621 8 slots used to spread transmission
622 cell not barred for access
623 call reestablishment not allowed
624 Access Control Class = 0000
625*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000626static u_int8_t si2[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000627 /* header */0x59, 0x06, 0x1A,
628 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
629 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
630 /* ncc */0xFF,
631 /* rach*/0xD5, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +0000632};
633
634/*
635SYSTEM INFORMATION TYPE 3
636 Cell identity = 00001 (1h)
637 Location area identification
638 Mobile Country Code (MCC): 001
639 Mobile Network Code (MNC): 01
640 Location Area Code (LAC): 00001 (1h)
641 Control Channel Description
642 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
643 0 blocks reserved for access grant
644 1 channel used for CCCH, with SDCCH
645 5 multiframes period for PAGING REQUEST
646 Time-out T3212 = 0
647 Cell Options BCCH
648 Power control indicator: not set
649 MSs shall not use uplink DTX
650 Radio link timeout = 36
651 Cell Selection Parameters
652 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
Harald Welte3b2ec422008-12-29 04:11:14 +0000653 max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max)
Harald Welte52b1f982008-12-23 20:25:15 +0000654 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
655 Half rate support (NECI): New establishment causes are not supported
656 min.RX signal level for MS = 0
657 RACH Control Parameters
658 maximum 7 retransmissions
659 8 slots used to spread transmission
660 cell not barred for access
661 call reestablishment not allowed
662 Access Control Class = 0000
663 SI 3 Rest Octets
664 Cell Bar Qualify (CBQ): 0
665 Cell Reselect Offset = 0 dB
666 Temporary Offset = 0 dB
667 Penalty Time = 20 s
668 System Information 2ter Indicator (2TI): 0 = not available
669 Early Classmark Sending Control (ECSC): 0 = forbidden
670 Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
671*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000672static u_int8_t si3[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000673 /* header */0x49, 0x06, 0x1B,
674 /* cell */0x00, 0x01,
675 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
676 /* desc */0x01, 0x03, 0x00,
677 /* option*/0x28,
678 /* selection*/0x62, 0x00,
679 /* rach */0xD5, 0x00, 0x00,
680 /* reset*/0x80, 0x00, 0x00, 0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000681};
682
683/*
684SYSTEM INFORMATION TYPE 4
685 Location area identification
686 Mobile Country Code (MCC): 001
687 Mobile Network Code (MNC): 01
688 Location Area Code (LAC): 00001 (1h)
689 Cell Selection Parameters
690 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
691 max.TX power level MS may use for CCH = 2
692 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
693 Half rate support (NECI): New establishment causes are not supported
694 min.RX signal level for MS = 0
695 RACH Control Parameters
696 maximum 7 retransmissions
697 8 slots used to spread transmission
698 cell not barred for access
699 call reestablishment not allowed
700 Access Control Class = 0000
701 Channel Description
702 Type = SDCCH/4[2]
703 Timeslot Number: 0
704 Training Sequence Code: 7h
705 ARFCN: 1
706 SI Rest Octets
707 Cell Bar Qualify (CBQ): 0
708 Cell Reselect Offset = 0 dB
709 Temporary Offset = 0 dB
710 Penalty Time = 20 s
711*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000712static u_int8_t si4[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000713 /* header */0x41, 0x06, 0x1C,
714 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
715 /* sel */0x62, 0x00,
716 /* rach*/0xD5, 0x00, 0x00,
717 /* var */0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000718 0x2B, 0x2B, 0x2B
719};
720
721/*
722 SYSTEM INFORMATION TYPE 5
723 Neighbour Cells Description
724 EXT-IND: Carries the complete BA
725 BA-IND = 0
726 Format-ID bit map 0
727 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
728*/
729
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000730static u_int8_t si5[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000731 /* header without l2 len*/0x06, 0x1D,
732 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
733 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000734};
735
736// SYSTEM INFORMATION TYPE 6
737
738/*
739SACCH FILLING
740 System Info Type: SYSTEM INFORMATION 6
741 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
742
743SYSTEM INFORMATION TYPE 6
744 Cell identity = 00001 (1h)
745 Location area identification
746 Mobile Country Code (MCC): 001
747 Mobile Network Code (MNC): 01
748 Location Area Code (LAC): 00001 (1h)
749 Cell Options SACCH
750 Power control indicator: not set
751 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
752 Radio link timeout = 36
753 NCC permitted (NCC) = FF
754*/
755
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000756static u_int8_t si6[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000757 /* header */0x06, 0x1E,
758 /* cell id*/ 0x00, 0x01,
759 /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01,
760 /* options */ 0x28,
761 /* ncc */ 0xFF,
Harald Welte52b1f982008-12-23 20:25:15 +0000762};
763
764
765
766static const struct bcch_info bcch_infos[] = {
767 {
768 .type = RSL_SYSTEM_INFO_1,
769 .len = sizeof(si1),
770 .data = si1,
771 }, {
772 .type = RSL_SYSTEM_INFO_2,
773 .len = sizeof(si2),
774 .data = si2,
775 }, {
776 .type = RSL_SYSTEM_INFO_3,
777 .len = sizeof(si3),
778 .data = si3,
779 }, {
780 .type = RSL_SYSTEM_INFO_4,
781 .len = sizeof(si4),
782 .data = si4,
783 },
784};
785
Holger Freyther24287b62008-12-28 16:32:41 +0000786static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1)
787static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2)
788static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3)
789static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4)
Harald Welte104604e2008-12-28 16:36:11 +0000790static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5)
791static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6)
Holger Freyther24287b62008-12-28 16:32:41 +0000792
Harald Welte52b1f982008-12-23 20:25:15 +0000793/* set all system information types */
Harald Weltee79769b2009-02-07 00:48:17 +0000794static int set_system_infos(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000795{
796 int i;
797
798 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
Harald Weltee79769b2009-02-07 00:48:17 +0000799 rsl_bcch_info(trx, bcch_infos[i].type,
Harald Welte52b1f982008-12-23 20:25:15 +0000800 bcch_infos[i].data,
801 bcch_infos[i].len);
802 }
Harald Weltee79769b2009-02-07 00:48:17 +0000803 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
804 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
Harald Weltead384642008-12-26 10:20:07 +0000805
806 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000807}
808
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000809/*
810 * Patch the various SYSTEM INFORMATION tables to update
811 * the LAI
812 */
813static void patch_tables(struct gsm_bts *bts)
814{
Harald Welte98981882009-01-06 18:59:11 +0000815 u_int8_t arfcn_low = ARFCN & 0xff;
816 u_int8_t arfcn_high = (ARFCN >> 8) & 0x0f;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000817 /* covert the raw packet to the struct */
818 struct gsm48_system_information_type_3 *type_3 =
819 (struct gsm48_system_information_type_3*)&si3;
820 struct gsm48_system_information_type_4 *type_4 =
821 (struct gsm48_system_information_type_4*)&si4;
822 struct gsm48_system_information_type_6 *type_6 =
823 (struct gsm48_system_information_type_6*)&si6;
Harald Welteb84e2f42008-12-28 23:42:04 +0000824 struct gsm48_loc_area_id lai;
825
826 gsm0408_generate_lai(&lai, bts->network->country_code,
827 bts->network->network_code, bts->location_area_code);
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000828
829 /* assign the MCC and MNC */
Harald Welteb84e2f42008-12-28 23:42:04 +0000830 type_3->lai = lai;
831 type_4->lai = lai;
832 type_6->lai = lai;
Harald Welte98981882009-01-06 18:59:11 +0000833
Harald Welte94009322009-02-15 15:38:42 +0000834 /* patch ARFCN into BTS Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000835 msg_2[74] &= 0xf0;
836 msg_2[74] |= arfcn_high;
837 msg_2[75] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000838 nanobts_attr_bts[42] &= 0xf0;
839 nanobts_attr_bts[42] |= arfcn_high;
840 nanobts_attr_bts[43] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000841
Harald Welte94009322009-02-15 15:38:42 +0000842 /* patch ARFCN into TRX Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000843 msg_6[7] &= 0xf0;
844 msg_6[7] |= arfcn_high;
845 msg_6[8] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000846 nanobts_attr_radio[5] &= 0xf0;
847 nanobts_attr_radio[5] |= arfcn_high;
848 nanobts_attr_radio[6] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000849
850 type_4->data[2] &= 0xf0;
851 type_4->data[2] |= arfcn_high;
852 type_4->data[3] = arfcn_low;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000853
854 /* patch Control Channel Description 10.5.2.11 */
855 type_3->control_channel_desc = bts->chan_desc;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000856}
857
858
Harald Weltee79769b2009-02-07 00:48:17 +0000859static void bootstrap_rsl(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000860{
Harald Welteb84e2f42008-12-28 23:42:04 +0000861 fprintf(stdout, "bootstrapping RSL MCC=%u MNC=%u\n", MCC, MNC);
Harald Weltee79769b2009-02-07 00:48:17 +0000862 set_system_infos(trx);
Harald Welte52b1f982008-12-23 20:25:15 +0000863}
864
Harald Welte1fa60c82009-02-09 18:13:26 +0000865void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
Harald Weltead384642008-12-26 10:20:07 +0000866{
867 switch (event) {
Harald Welte1fa60c82009-02-09 18:13:26 +0000868 case EVT_E1_TEI_UP:
869 switch (type) {
870 case E1INP_SIGN_OML:
871 bootstrap_om(trx->bts);
872 break;
873 case E1INP_SIGN_RSL:
874 bootstrap_rsl(trx);
875 break;
876 default:
877 break;
878 }
Harald Weltead384642008-12-26 10:20:07 +0000879 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000880 case EVT_E1_TEI_DN:
881 fprintf(stderr, "Lost some E1 TEI link\n");
882 /* FIXME: deal with TEI or L1 link loss */
Harald Weltead384642008-12-26 10:20:07 +0000883 break;
884 default:
Harald Weltead384642008-12-26 10:20:07 +0000885 break;
886 }
887}
888
889static int bootstrap_network(void)
Harald Welte52b1f982008-12-23 20:25:15 +0000890{
891 struct gsm_bts *bts;
892
893 /* initialize our data structures */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000894 gsmnet = gsm_network_init(1, BTS_TYPE, MCC, MNC);
Harald Weltead384642008-12-26 10:20:07 +0000895 if (!gsmnet)
896 return -ENOMEM;
Harald Weltef5cbab72008-12-30 18:00:15 +0000897
Harald Weltefd2fb452009-02-21 13:00:57 +0000898 gsmnet->name_long = "OpenBSC";
899 gsmnet->name_short = "OpenBSC";
Harald Welte52b1f982008-12-23 20:25:15 +0000900 bts = &gsmnet->bts[0];
Holger Freyther0a173bf2009-04-22 22:07:07 +0000901 bts->location_area_code = LAC;
Harald Welte98981882009-01-06 18:59:11 +0000902 bts->trx[0].arfcn = ARFCN;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000903
904 /* Control Channel Description */
905 memset(&bts->chan_desc, 0, sizeof(struct gsm48_control_channel_descr));
Harald Welte41fbf442009-02-24 22:34:22 +0000906 bts->chan_desc.att = 1;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000907 bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
908 bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
909 bts->chan_desc.t3212 = 0;
910
Harald Welte98981882009-01-06 18:59:11 +0000911 patch_tables(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000912
Holger Freyther1fd34142009-02-09 23:42:03 +0000913 paging_init(bts);
Harald Welte38c2f132009-01-06 23:10:57 +0000914
Holger Freyther36650b82009-04-19 06:35:16 +0000915 if (db_init(database_name, gsmnet)) {
Holger Freytheref7f7ce2009-04-19 06:35:12 +0000916 printf("DB: Failed to init database. Please check the option settings.\n");
917 return -1;
918 }
919 printf("DB: Database initialized.\n");
920
921 if (db_prepare()) {
922 printf("DB: Failed to prepare database.\n");
923 return -1;
924 }
925 printf("DB: Database prepared.\n");
926
Holger Freyther219518d2009-01-02 22:04:43 +0000927 telnet_init(gsmnet, 4242);
Harald Weltead384642008-12-26 10:20:07 +0000928
Harald Welte1fa60c82009-02-09 18:13:26 +0000929 /* E1 mISDN input setup */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000930 if (BTS_TYPE == GSM_BTS_TYPE_BS11)
Holger Freytherb5c00f52009-04-22 22:08:07 +0000931 return e1_config(bts, cardnr, release_l2);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000932 else
933 return ia_config(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000934}
Harald Weltef6b7a902008-12-26 00:05:11 +0000935
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000936static void create_pcap_file(char *file)
937{
938 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
939 int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
940
941 if (fd < 0) {
942 perror("Failed to open file for pcap");
943 return;
944 }
945
Holger Freyther0469cf62009-03-31 12:14:16 +0000946 e1_set_pcap_fd(fd);
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000947}
948
Holger Freytherb332f612008-12-27 12:46:51 +0000949static void print_usage()
950{
951 printf("Usage: bsc_hack\n");
952}
953
954static void print_help()
955{
956 printf(" Some useful help...\n");
957 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
Holger Freytherefde7fb2008-12-28 14:14:56 +0000958 printf(" -s --disable-color\n");
959 printf(" -n --network-code number(MNC) \n");
960 printf(" -c --country-code number (MCC) \n");
Holger Freyther0a173bf2009-04-22 22:07:07 +0000961 printf(" -L --location-area-code number (LAC) \n");
Harald Welte98981882009-01-06 18:59:11 +0000962 printf(" -f --arfcn number The frequency ARFCN\n");
Holger Freytherbde36102008-12-28 22:51:39 +0000963 printf(" -l --database db-name The database to use\n");
Holger Freyther89824fc2008-12-30 16:18:18 +0000964 printf(" -a --authorize-everyone Allow everyone into the network.\n");
Holger Freythere97f7fb2008-12-31 18:52:11 +0000965 printf(" -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n");
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000966 printf(" -p --pcap file The filename of the pcap file\n");
Harald Weltee1bd2412009-02-15 14:40:09 +0000967 printf(" -t --bts-type type The BTS type (bs11, nanobts900, nanobts1800)\n");
Holger Freytherdda22c12009-04-22 22:07:31 +0000968 printf(" -C --cardnr number For bs11 select E1 card number other than 0\n");
Holger Freytherb5c00f52009-04-22 22:08:07 +0000969 printf(" -R --release-l2 Releases mISDN layer 2 after exit, to unload driver.\n");
Holger Freytherb332f612008-12-27 12:46:51 +0000970 printf(" -h --help this text\n");
971}
972
973static void handle_options(int argc, char** argv)
974{
975 while (1) {
976 int option_index = 0, c;
977 static struct option long_options[] = {
978 {"help", 0, 0, 'h'},
979 {"debug", 1, 0, 'd'},
Holger Freytherefde7fb2008-12-28 14:14:56 +0000980 {"disable-color", 0, 0, 's'},
981 {"network-code", 1, 0, 'n'},
982 {"country-code", 1, 0, 'c'},
Holger Freyther0a173bf2009-04-22 22:07:07 +0000983 {"location-area-code", 1, 0, 'L'},
Holger Freytherbde36102008-12-28 22:51:39 +0000984 {"database", 1, 0, 'l'},
Holger Freyther89824fc2008-12-30 16:18:18 +0000985 {"authorize-everyone", 0, 0, 'a'},
Holger Freythere97f7fb2008-12-31 18:52:11 +0000986 {"reject-cause", 1, 0, 'r'},
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000987 {"pcap", 1, 0, 'p'},
Harald Welte98981882009-01-06 18:59:11 +0000988 {"arfcn", 1, 0, 'f'},
Harald Welte8c1d0e42009-02-15 03:38:12 +0000989 {"bts-type", 1, 0, 't'},
Holger Freytherdda22c12009-04-22 22:07:31 +0000990 {"cardnr", 1, 0, 'C'},
Holger Freytherb5c00f52009-04-22 22:08:07 +0000991 {"release-l2", 0, 0, 'R'},
Holger Freytherb332f612008-12-27 12:46:51 +0000992 {0, 0, 0, 0}
993 };
994
Holger Freytherb5c00f52009-04-22 22:08:07 +0000995 c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:C:RL:",
Holger Freytherb332f612008-12-27 12:46:51 +0000996 long_options, &option_index);
997 if (c == -1)
998 break;
999
1000 switch (c) {
1001 case 'h':
1002 print_usage();
1003 print_help();
1004 exit(0);
Holger Freytherefde7fb2008-12-28 14:14:56 +00001005 case 's':
Holger Freytherb332f612008-12-27 12:46:51 +00001006 debug_use_color(0);
1007 break;
1008 case 'd':
1009 debug_parse_category_mask(optarg);
1010 break;
Holger Freytherefde7fb2008-12-28 14:14:56 +00001011 case 'n':
1012 MNC = atoi(optarg);
1013 break;
1014 case 'c':
1015 MCC = atoi(optarg);
1016 break;
Holger Freyther0a173bf2009-04-22 22:07:07 +00001017 case 'L':
1018 LAC = atoi(optarg);
1019 break;
Harald Welte98981882009-01-06 18:59:11 +00001020 case 'f':
1021 ARFCN = atoi(optarg);
1022 break;
Harald Welte8965da42009-01-06 18:09:02 +00001023 case 'l':
Holger Freytherbde36102008-12-28 22:51:39 +00001024 database_name = strdup(optarg);
1025 break;
Holger Freyther89824fc2008-12-30 16:18:18 +00001026 case 'a':
1027 gsm0408_allow_everyone(1);
1028 break;
Holger Freythere97f7fb2008-12-31 18:52:11 +00001029 case 'r':
1030 gsm0408_set_reject_cause(atoi(optarg));
1031 break;
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001032 case 'p':
1033 create_pcap_file(optarg);
1034 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +00001035 case 't':
1036 BTS_TYPE = parse_btstype(optarg);
1037 break;
Holger Freytherdda22c12009-04-22 22:07:31 +00001038 case 'C':
1039 cardnr = atoi(optarg);
1040 break;
Holger Freytherb5c00f52009-04-22 22:08:07 +00001041 case 'R':
1042 release_l2 = 1;
1043 break;
Holger Freytherb332f612008-12-27 12:46:51 +00001044 default:
1045 /* ignore */
1046 break;
1047 }
1048 }
1049}
1050
Harald Welted1252502009-01-01 01:50:32 +00001051static void signal_handler(int signal)
1052{
1053 fprintf(stdout, "signal %u received\n", signal);
1054
1055 switch (signal) {
1056 case SIGHUP:
1057 case SIGABRT:
1058 shutdown_net(gsmnet);
1059 break;
1060 default:
1061 break;
1062 }
1063}
1064
Harald Weltef6b7a902008-12-26 00:05:11 +00001065int main(int argc, char **argv)
1066{
Harald Welte1fa60c82009-02-09 18:13:26 +00001067 int rc;
1068
Holger Freytherb332f612008-12-27 12:46:51 +00001069 /* parse options */
1070 handle_options(argc, argv);
1071
Harald Welte65ccf882009-02-24 22:36:20 +00001072 /* seed the PRNG */
1073 srand(time(NULL));
1074
Harald Welte1fa60c82009-02-09 18:13:26 +00001075 rc = bootstrap_network();
1076 if (rc < 0)
1077 exit(1);
Harald Weltef6b7a902008-12-26 00:05:11 +00001078
Harald Welted1252502009-01-01 01:50:32 +00001079 signal(SIGHUP, &signal_handler);
1080 signal(SIGABRT, &signal_handler);
1081
Harald Weltef6b7a902008-12-26 00:05:11 +00001082 while (1) {
1083 bsc_select_main();
1084 }
1085}