blob: 7ac65c576fd2f77e66f33bef98152ccfd1d83927 [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 Welteb4630602009-05-01 15:43:22 +000049#include <openbsc/signal.h>
Harald Welte52b1f982008-12-23 20:25:15 +000050
51/* global pointer to the gsm network data structure */
Harald Welte879c85a2009-05-01 15:00:20 +000052static struct gsm_network *gsmnet;
Harald Welte52b1f982008-12-23 20:25:15 +000053
Holger Freytherefde7fb2008-12-28 14:14:56 +000054/* MCC and MNC for the Location Area Identifier */
55static int MCC = 1;
56static int MNC = 1;
Holger Freyther0a173bf2009-04-22 22:07:07 +000057static int LAC = 1;
Harald Welte98981882009-01-06 18:59:11 +000058static int ARFCN = HARDCODED_ARFCN;
Holger Freytherdda22c12009-04-22 22:07:31 +000059static int cardnr = 0;
Holger Freytherb5c00f52009-04-22 22:08:07 +000060static int release_l2 = 0;
Harald Welte8c1d0e42009-02-15 03:38:12 +000061static enum gsm_bts_type BTS_TYPE = GSM_BTS_TYPE_BS11;
Holger Freytherbde36102008-12-28 22:51:39 +000062static const char *database_name = "hlr.sqlite3";
Holger Freytherefde7fb2008-12-28 14:14:56 +000063
Harald Welte52b1f982008-12-23 20:25:15 +000064/* The following definitions are for OM and NM packets that we cannot yet
65 * generate by code but we just pass on */
66
67// BTS Site Manager, SET ATTRIBUTES
68
69/*
70 Object Class: BTS Site Manager
71 Instance 1: FF
72 Instance 2: FF
73 Instance 3: FF
74SET ATTRIBUTES
75 sAbisExternalTime: 2007/09/08 14:36:11
76 omLAPDRelTimer: 30sec
77 shortLAPDIntTimer: 5sec
78 emergencyTimer1: 10 minutes
79 emergencyTimer2: 0 minutes
80*/
81
82unsigned char msg_1[] =
83{
Harald Weltecd993872009-02-15 16:16:28 +000084 0xD0, 0x00, 0xFF, 0xFF, 0xFF,
Harald Welte110c0ab2009-05-23 16:27:05 +000085 NM_ATT_BS11_ABIS_EXT_TIME, 0x07,
86 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE,
87 0x02,
88 0x00, 0x1E,
89 NM_ATT_BS11_SH_LAPD_INT_TIMER,
90 0x01, 0x05,
Harald Weltecd993872009-02-15 16:16:28 +000091 0x42, 0x02, 0x00, 0x0A,
92 0x44, 0x02, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +000093};
94
95// BTS, SET BTS ATTRIBUTES
96
97/*
98 Object Class: BTS
99 BTS relat. Number: 0
100 Instance 2: FF
101 Instance 3: FF
102SET BTS ATTRIBUTES
103 bsIdentityCode / BSIC:
104 PLMN_colour_code: 7h
105 BS_colour_code: 7h
106 BTS Air Timer T3105: 4 ,unit 10 ms
107 btsIsHopping: FALSE
Harald Welte83282292009-02-01 16:22:19 +0000108 periodCCCHLoadIndication: 1sec
Holger Freyther3b910432009-02-11 00:43:48 +0000109 thresholdCCCHLoadIndication: 0%
Harald Welte52b1f982008-12-23 20:25:15 +0000110 cellAllocationNumber: 00h = GSM 900
111 enableInterferenceClass: 00h = Disabled
112 fACCHQual: 6 (FACCH stealing flags minus 1)
113 intaveParameter: 31 SACCH multiframes
114 interferenceLevelBoundaries:
115 Interference Boundary 1: 0Ah
116 Interference Boundary 2: 0Fh
117 Interference Boundary 3: 14h
118 Interference Boundary 4: 19h
119 Interference Boundary 5: 1Eh
120 mSTxPwrMax: 11
121 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
122 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
123 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
124 30=33dBm, 31=32dBm
125 ny1:
126 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
127 powerOutputThresholds:
128 Out Power Fault Threshold: -10 dB
129 Red Out Power Threshold: - 6 dB
130 Excessive Out Power Threshold: 5 dB
131 rACHBusyThreshold: -127 dBm
132 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
133 rfResourceIndicationPeriod: 125 SACCH multiframes
134 T200:
135 SDCCH: 044 in 5 ms
136 FACCH/Full rate: 031 in 5 ms
137 FACCH/Half rate: 041 in 5 ms
138 SACCH with TCH SAPI0: 090 in 10 ms
139 SACCH with SDCCH: 090 in 10 ms
140 SDCCH with SAPI3: 090 in 5 ms
141 SACCH with TCH SAPI3: 135 in 10 ms
142 tSync: 9000 units of 10 msec
143 tTrau: 9000 units of 10 msec
144 enableUmLoopTest: 00h = disabled
145 enableExcessiveDistance: 00h = Disabled
146 excessiveDistance: 64km
147 hoppingMode: 00h = baseband hopping
148 cellType: 00h = Standard Cell
149 BCCH ARFCN / bCCHFrequency: 1
150*/
151
152unsigned char msg_2[] =
153{
Harald Welte110c0ab2009-05-23 16:27:05 +0000154 0x41, NM_OC_BTS, 0x00, 0xFF, 0xFF,
Harald Welte060f6df2009-05-23 17:50:53 +0000155 NM_ATT_BSIC, HARDCODED_BSIC,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000156 NM_ATT_BTS_AIR_TIMER, 0x04,
Harald Weltecd993872009-02-15 16:16:28 +0000157 NM_ATT_BS11_BTSLS_HOPPING, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000158 NM_ATT_CCCH_L_I_P, 0x01,
159 NM_ATT_CCCH_L_T, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000160 NM_ATT_BS11_CELL_ALLOC_NR, 0x00,
161 NM_ATT_BS11_ENA_INTERF_CLASS, 0x00,
162 NM_ATT_BS11_FACCH_QUAL, 0x06,
Harald Weltefe609d82009-05-23 18:14:31 +0000163 /* interference avg. period in numbers of SACCH multifr */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000164 NM_ATT_INTAVE_PARAM, 0x1F,
165 NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B,
166 NM_ATT_CCCH_L_T, 0x23,
167 NM_ATT_GSM_TIME, 0x28, 0x00,
168 NM_ATT_ADM_STATE, 0x03,
169 NM_ATT_RACH_B_THRESH, 0x7F,
170 NM_ATT_LDAVG_SLOTS, 0x00, 0xFA,
Harald Weltecd993872009-02-15 16:16:28 +0000171 NM_ATT_BS11_RF_RES_IND_PER, 0x7D,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000172 NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87,
Harald Weltecd993872009-02-15 16:16:28 +0000173 NM_ATT_BS11_TSYNC, 0x23, 0x28,
174 NM_ATT_BS11_TTRAU, 0x23, 0x28,
175 NM_ATT_TEST_DUR, 0x01, 0x00,
176 NM_ATT_OUTST_ALARM, 0x01, 0x00,
177 NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40,
178 NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00,
179 NM_ATT_BS11_PLL, 0x01, 0x00,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000180 NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/,
Harald Welte52b1f982008-12-23 20:25:15 +0000181};
182
183// Handover Recognition, SET ATTRIBUTES
184
185/*
186Illegal Contents GSM Formatted O&M Msg
187 Object Class: Handover Recognition
188 BTS relat. Number: 0
189 Instance 2: FF
190 Instance 3: FF
191SET ATTRIBUTES
192 enableDelayPowerBudgetHO: 00h = Disabled
193 enableDistanceHO: 00h = Disabled
194 enableInternalInterCellHandover: 00h = Disabled
195 enableInternalIntraCellHandover: 00h = Disabled
196 enablePowerBudgetHO: 00h = Disabled
197 enableRXLEVHO: 00h = Disabled
198 enableRXQUALHO: 00h = Disabled
199 hoAveragingDistance: 8 SACCH multiframes
200 hoAveragingLev:
201 A_LEV_HO: 8 SACCH multiframes
202 W_LEV_HO: 1 SACCH multiframes
203 hoAveragingPowerBudget: 16 SACCH multiframes
204 hoAveragingQual:
205 A_QUAL_HO: 8 SACCH multiframes
206 W_QUAL_HO: 2 SACCH multiframes
207 hoLowerThresholdLevDL: (10 - 110) dBm
208 hoLowerThresholdLevUL: (5 - 110) dBm
209 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
210 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
211 hoThresholdLevDLintra : (20 - 110) dBm
212 hoThresholdLevULintra: (20 - 110) dBm
213 hoThresholdMsRangeMax: 20 km
214 nCell: 06h
215 timerHORequest: 3 ,unit 2 SACCH multiframes
216*/
217
218unsigned char msg_3[] =
219{
Harald Welte110c0ab2009-05-23 16:27:05 +0000220 0xD0, NM_OC_BS11_HANDOVER, 0x00, 0xFF, 0xFF,
Harald Weltecd993872009-02-15 16:16:28 +0000221 0xD0, 0x00,
222 0x64, 0x00,
223 0x67, 0x00,
224 0x68, 0x00,
225 0x6A, 0x00,
226 0x6C, 0x00,
227 0x6D, 0x00,
228 0x6F, 0x08,
229 0x70, 0x08, 0x01,
230 0x71, 0x10, 0x10, 0x10,
231 0x72, 0x08, 0x02,
232 0x73, 0x0A,
233 0x74, 0x05,
234 0x75, 0x06,
235 0x76, 0x06,
236 0x78, 0x14,
237 0x79, 0x14,
238 0x7A, 0x14,
239 0x7D, 0x06,
240 0x92, 0x03, 0x20, 0x01, 0x00,
241 0x45, 0x01, 0x00,
242 0x48, 0x01, 0x00,
243 0x5A, 0x01, 0x00,
244 0x5B, 0x01, 0x05,
245 0x5E, 0x01, 0x1A,
246 0x5F, 0x01, 0x20,
247 0x9D, 0x01, 0x00,
248 0x47, 0x01, 0x00,
249 0x5C, 0x01, 0x64,
250 0x5D, 0x01, 0x1E,
251 0x97, 0x01, 0x20,
252 0xF7, 0x01, 0x3C,
Harald Welte52b1f982008-12-23 20:25:15 +0000253};
254
255// Power Control, SET ATTRIBUTES
256
257/*
258 Object Class: Power Control
259 BTS relat. Number: 0
260 Instance 2: FF
261 Instance 3: FF
262SET ATTRIBUTES
263 enableMsPowerControl: 00h = Disabled
264 enablePowerControlRLFW: 00h = Disabled
265 pcAveragingLev:
266 A_LEV_PC: 4 SACCH multiframes
267 W_LEV_PC: 1 SACCH multiframes
268 pcAveragingQual:
269 A_QUAL_PC: 4 SACCH multiframes
270 W_QUAL_PC: 2 SACCH multiframes
271 pcLowerThresholdLevDL: 0Fh
272 pcLowerThresholdLevUL: 0Ah
273 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
274 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
275 pcRLFThreshold: 0Ch
276 pcUpperThresholdLevDL: 14h
277 pcUpperThresholdLevUL: 0Fh
278 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
279 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
280 powerConfirm: 2 ,unit 2 SACCH multiframes
281 powerControlInterval: 2 ,unit 2 SACCH multiframes
282 powerIncrStepSize: 02h = 4 dB
283 powerRedStepSize: 01h = 2 dB
284 radioLinkTimeoutBs: 64 SACCH multiframes
285 enableBSPowerControl: 00h = disabled
286*/
287
288unsigned char msg_4[] =
289{
Harald Welte110c0ab2009-05-23 16:27:05 +0000290 0xD0, NM_OC_BS11_PWR_CTRL, 0x00, 0xFF, 0xFF,
Harald Weltecd993872009-02-15 16:16:28 +0000291 NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00,
292 NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00,
293 0x7E, 0x04, 0x01,
294 0x7F, 0x04, 0x02,
295 0x80, 0x0F,
296 0x81, 0x0A,
297 0x82, 0x05,
298 0x83, 0x05,
299 0x84, 0x0C,
300 0x85, 0x14,
301 0x86, 0x0F,
302 0x87, 0x04,
303 0x88, 0x04,
304 0x89, 0x02,
305 0x8A, 0x02,
306 0x8B, 0x02,
307 0x8C, 0x01,
308 0x8D, 0x40,
309 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
Harald Welte52b1f982008-12-23 20:25:15 +0000310};
311
312
313// Transceiver, SET TRX ATTRIBUTES (TRX 0)
314
315/*
316 Object Class: Transceiver
317 BTS relat. Number: 0
318 Tranceiver number: 0
319 Instance 3: FF
320SET TRX ATTRIBUTES
321 aRFCNList (HEX): 0001
Harald Weltecd993872009-02-15 16:16:28 +0000322 txPwrMaxReduction: 00h = 30dB
Harald Welte52b1f982008-12-23 20:25:15 +0000323 radioMeasGran: 254 SACCH multiframes
324 radioMeasRep: 01h = enabled
325 memberOfEmergencyConfig: 01h = TRUE
326 trxArea: 00h = TRX doesn't belong to a concentric cell
327*/
328
329unsigned char msg_6[] =
330{
Harald Welte110c0ab2009-05-23 16:27:05 +0000331 0x44, NM_OC_RADIO_CARRIER, 0x00, 0x00, 0xFF,
Harald Weltecd993872009-02-15 16:16:28 +0000332 NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/,
Harald Welte311d0cf2009-02-17 17:45:59 +0000333 NM_ATT_RF_MAXPOWR_R, 0x00,
Harald Weltecd993872009-02-15 16:16:28 +0000334 NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0xFE,
335 NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01,
336 NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01,
337 NM_ATT_BS11_TRX_AREA, 0x01, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000338};
339
Harald Welte8c1d0e42009-02-15 03:38:12 +0000340static unsigned char nanobts_attr_bts[] = {
341 NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73,
Harald Weltefe609d82009-05-23 18:14:31 +0000342 /* interference avg. period in numbers of SACCH multifr */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000343 NM_ATT_INTAVE_PARAM, 0x06,
344 NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10,
345 NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
346 NM_ATT_MAX_TA, 0x3f,
Harald Welte311d0cf2009-02-17 17:45:59 +0000347 NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */
348 NM_ATT_CCCH_L_T, 10, /* percent */
349 NM_ATT_CCCH_L_I_P, 1, /* seconds */
Harald Weltefe609d82009-05-23 18:14:31 +0000350 NM_ATT_RACH_B_THRESH, 10, /* busy threshold in - dBm */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000351 NM_ATT_LDAVG_SLOTS, 0x03, 0xe8,
Harald Weltefe609d82009-05-23 18:14:31 +0000352 NM_ATT_BTS_AIR_TIMER, 128, /* miliseconds */
353 NM_ATT_NY1, 10, /* 10 retransmissions of physical config */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000354 NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
Harald Welte060f6df2009-05-23 17:50:53 +0000355 NM_ATT_BSIC, HARDCODED_BSIC,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000356};
Harald Welte52b1f982008-12-23 20:25:15 +0000357
Harald Welte8c1d0e42009-02-15 03:38:12 +0000358static unsigned char nanobts_attr_radio[] = {
Harald Welte311d0cf2009-02-17 17:45:59 +0000359 NM_ATT_RF_MAXPOWR_R, 0x0c,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000360 NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
361};
362
Harald Welte5c1e4582009-02-15 11:57:29 +0000363static unsigned char nanobts_attr_e0[] = {
364 0x85, 0x00,
365 0x81, 0x0b, 0xbb, /* TCP PORT for RSL */
366};
367
Harald Welteb4630602009-05-01 15:43:22 +0000368/* Callback function to be called whenever we get a GSM 12.21 state change event */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000369int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
370 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
371{
372 struct gsm_bts *bts;
373 struct gsm_bts_trx *trx;
374 struct gsm_bts_trx_ts *ts;
375
376 /* This is currently only required on nanoBTS */
377
378 switch (evt) {
379 case EVT_STATECHG_OPER:
380 switch (obj_class) {
381 case NM_OC_SITE_MANAGER:
382 bts = container_of(obj, struct gsm_bts, site_mgr);
383 if (old_state->operational != 2 && new_state->operational == 2) {
384 abis_nm_opstart(bts, NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff);
385 }
386 break;
387 case NM_OC_BTS:
388 bts = obj;
389 if (new_state->availability == 5) {
390 abis_nm_set_bts_attr(bts, nanobts_attr_bts,
391 sizeof(nanobts_attr_bts));
392 abis_nm_opstart(bts, NM_OC_BTS,
Harald Welte191280d2009-05-01 13:20:04 +0000393 bts->bts_nr, 0xff, 0xff);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000394 abis_nm_chg_adm_state(bts, NM_OC_BTS,
Harald Welte191280d2009-05-01 13:20:04 +0000395 bts->bts_nr, 0xff, 0xff,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000396 NM_STATE_UNLOCKED);
397 }
398 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000399 case NM_OC_CHANNEL:
400 ts = obj;
401 trx = ts->trx;
402 if (new_state->availability == 5) {
403 if (ts->nr == 0 && trx == trx->bts->c0)
Harald Weltee1bd2412009-02-15 14:40:09 +0000404 abis_nm_set_channel_attr(ts, NM_CHANC_BCCH_CBCH);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000405 else
406 abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull);
407 abis_nm_opstart(trx->bts, NM_OC_CHANNEL,
Harald Welte191280d2009-05-01 13:20:04 +0000408 trx->bts->bts_nr, trx->nr, ts->nr);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000409 abis_nm_chg_adm_state(trx->bts, NM_OC_CHANNEL,
Harald Welte191280d2009-05-01 13:20:04 +0000410 trx->bts->bts_nr, trx->nr, ts->nr,
Harald Welte8c1d0e42009-02-15 03:38:12 +0000411 NM_STATE_UNLOCKED);
412 }
413 break;
Harald Weltea994a482009-05-01 15:54:23 +0000414 default:
Harald Welte8c1d0e42009-02-15 03:38:12 +0000415 break;
416 }
417 break;
Harald Weltea994a482009-05-01 15:54:23 +0000418 default:
419 //DEBUGP(DMM, "Unhandled state change in %s:%d\n", __func__, __LINE__);
Holger Freytherff9592f2009-03-09 16:17:14 +0000420 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000421 }
422 return 0;
423}
424
Harald Welteb4630602009-05-01 15:43:22 +0000425/* Callback function to be called every time we receive a 12.21 SW activated report */
426static int sw_activ_rep(struct msgb *mb)
427{
428 struct abis_om_fom_hdr *foh = msgb_l3(mb);
429 struct gsm_bts_trx *trx = mb->trx;
430
431 switch (foh->obj_class) {
432 case NM_OC_BASEB_TRANSC:
433 /* TRX software is active, tell it to initiate RSL Link */
434 abis_nm_ipaccess_msg(trx->bts, 0xe0, NM_OC_BASEB_TRANSC,
435 trx->bts->bts_nr, trx->nr, 0xff,
436 nanobts_attr_e0, sizeof(nanobts_attr_e0));
437 abis_nm_opstart(trx->bts, NM_OC_BASEB_TRANSC,
438 trx->bts->bts_nr, trx->nr, 0xff);
439 abis_nm_chg_adm_state(trx->bts, NM_OC_BASEB_TRANSC,
440 trx->bts->bts_nr, trx->nr, 0xff,
441 NM_STATE_UNLOCKED);
442 break;
443 case NM_OC_RADIO_CARRIER:
444 abis_nm_set_radio_attr(trx, nanobts_attr_radio,
445 sizeof(nanobts_attr_radio));
446 abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER,
447 trx->bts->bts_nr, trx->nr, 0xff);
448 abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER,
449 trx->bts->bts_nr, trx->nr, 0xff,
450 NM_STATE_UNLOCKED);
451 break;
452 }
453 return 0;
454}
455
456/* Callback function to be called every time we receive a signal from NM */
457static int nm_sig_cb(unsigned int subsys, unsigned int signal,
458 void *handler_data, void *signal_data)
459{
460 switch (signal) {
461 case S_NM_SW_ACTIV_REP:
462 return sw_activ_rep(signal_data);
463 default:
464 break;
465 }
466 return 0;
467}
468
Harald Welte8c1d0e42009-02-15 03:38:12 +0000469static void bootstrap_om_nanobts(struct gsm_bts *bts)
470{
Harald Weltee1bd2412009-02-15 14:40:09 +0000471 /* We don't do callback based bootstrapping, but event driven (see above) */
Harald Welte8c1d0e42009-02-15 03:38:12 +0000472}
473
474static void bootstrap_om_bs11(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000475{
476 struct gsm_bts_trx *trx = &bts->trx[0];
477
478 /* stop sending event reports */
479 abis_nm_event_reports(bts, 0);
480
481 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000482 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000483
Harald Welte702d8702008-12-26 20:25:35 +0000484 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000485 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte702d8702008-12-26 20:25:35 +0000486
487 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000488 abis_nm_bs11_reset_resource(bts);
Harald Welte702d8702008-12-26 20:25:35 +0000489
490 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000491 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte702d8702008-12-26 20:25:35 +0000492
Harald Welte52b1f982008-12-23 20:25:15 +0000493 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
494 abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */
495 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
496 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
497
498 /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */
499 abis_nm_conn_terr_sign(trx, 0, 1, 0xff);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000500 set_ts_e1link(&trx->ts[0], 0, 1, 0xff);
Harald Welte52b1f982008-12-23 20:25:15 +0000501 abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */
502
503 /* Use TEI 1 for signalling */
504 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01);
505 abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000506
507#ifdef HAVE_TRX1
Harald Welte52b1f982008-12-23 20:25:15 +0000508 /* TRX 1 */
509 abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff);
510 /* FIXME: TRX ATTRIBUTE */
511 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02);
512#endif
513
514 /* SET CHANNEL ATTRIBUTE TS1 */
Harald Welte23887b62009-02-18 03:37:20 +0000515 abis_nm_set_channel_attr(&trx->ts[1], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000516 /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000517 set_ts_e1link(&trx->ts[1], 0, 2, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000518 abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1);
519
520 /* SET CHANNEL ATTRIBUTE TS2 */
Harald Welte23887b62009-02-18 03:37:20 +0000521 abis_nm_set_channel_attr(&trx->ts[2], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000522 /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000523 set_ts_e1link(&trx->ts[2], 0, 2, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000524 abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2);
525
526 /* SET CHANNEL ATTRIBUTE TS3 */
Harald Welte23887b62009-02-18 03:37:20 +0000527 abis_nm_set_channel_attr(&trx->ts[3], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000528 /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000529 set_ts_e1link(&trx->ts[3], 0, 2, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000530 abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3);
531
532 /* SET CHANNEL ATTRIBUTE TS4 */
Harald Welte23887b62009-02-18 03:37:20 +0000533 abis_nm_set_channel_attr(&trx->ts[4], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000534 /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000535 set_ts_e1link(&trx->ts[4], 0, 3, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000536 abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0);
537
538 /* SET CHANNEL ATTRIBUTE TS5 */
Harald Welte23887b62009-02-18 03:37:20 +0000539 abis_nm_set_channel_attr(&trx->ts[5], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000540 /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000541 set_ts_e1link(&trx->ts[5], 0, 3, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000542 abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1);
543
544 /* SET CHANNEL ATTRIBUTE TS6 */
Harald Welte23887b62009-02-18 03:37:20 +0000545 abis_nm_set_channel_attr(&trx->ts[6], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000546 /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000547 set_ts_e1link(&trx->ts[6], 0, 3, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000548 abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2);
549
550 /* SET CHANNEL ATTRIBUTE TS7 */
Harald Welte23887b62009-02-18 03:37:20 +0000551 abis_nm_set_channel_attr(&trx->ts[7], NM_CHANC_TCHFull);
Harald Welte52b1f982008-12-23 20:25:15 +0000552 /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000553 set_ts_e1link(&trx->ts[7], 0, 3, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000554 abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3);
555
556 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000557 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000558
559 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000560 abis_nm_bs11_reset_resource(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000561
562 /* restart sending event reports */
563 abis_nm_event_reports(bts, 1);
564}
565
Harald Welte8c1d0e42009-02-15 03:38:12 +0000566static void bootstrap_om(struct gsm_bts *bts)
567{
Harald Welteedb37782009-05-01 14:59:07 +0000568 fprintf(stdout, "bootstrapping OML for BTS %u\n", bts->nr);
Harald Welte8c1d0e42009-02-15 03:38:12 +0000569
570 switch (bts->type) {
571 case GSM_BTS_TYPE_BS11:
572 bootstrap_om_bs11(bts);
573 break;
574 case GSM_BTS_TYPE_NANOBTS_900:
575 case GSM_BTS_TYPE_NANOBTS_1800:
576 bootstrap_om_nanobts(bts);
577 break;
578 default:
579 fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type);
580 }
581}
582
Harald Welted1252502009-01-01 01:50:32 +0000583static int shutdown_om(struct gsm_bts *bts)
584{
585 /* stop sending event reports */
586 abis_nm_event_reports(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000587
Harald Welted1252502009-01-01 01:50:32 +0000588 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000589 abis_nm_bs11_db_transmission(bts, 1);
Harald Welted1252502009-01-01 01:50:32 +0000590
591 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000592 abis_nm_bs11_db_transmission(bts, 0);
Harald Welted1252502009-01-01 01:50:32 +0000593
594 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000595 abis_nm_bs11_reset_resource(bts);
Harald Welted1252502009-01-01 01:50:32 +0000596
597 return 0;
598}
599
600static int shutdown_net(struct gsm_network *net)
601{
602 int i;
603 for (i = 0; i < net->num_bts; i++) {
604 int rc;
605 rc = shutdown_om(&net->bts[i]);
606 if (rc < 0)
607 return rc;
608 }
609
610 return 0;
611}
Harald Welte52b1f982008-12-23 20:25:15 +0000612
613struct bcch_info {
614 u_int8_t type;
615 u_int8_t len;
616 const u_int8_t *data;
617};
618
619/*
620SYSTEM INFORMATION TYPE 1
621 Cell channel description
622 Format-ID bit map 0
623 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
624 RACH Control Parameters
625 maximum 7 retransmissions
626 8 slots used to spread transmission
627 cell not barred for access
628 call reestablishment not allowed
629 Access Control Class = 0000
630*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000631static u_int8_t si1[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000632 /* header */0x55, 0x06, 0x19,
633 /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
634 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,
635 /* rach */0xD5, 0x00, 0x00,
636 /* s1 reset*/0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000637};
638
639/*
640 SYSTEM INFORMATION TYPE 2
641 Neighbour Cells Description
642 EXT-IND: Carries the complete BA
643 BA-IND = 0
644 Format-ID bit map 0
645 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
646 NCC permitted (NCC) = FF
647 RACH Control Parameters
648 maximum 7 retransmissions
649 8 slots used to spread transmission
650 cell not barred for access
651 call reestablishment not allowed
652 Access Control Class = 0000
653*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000654static u_int8_t si2[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000655 /* header */0x59, 0x06, 0x1A,
656 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
657 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
658 /* ncc */0xFF,
659 /* rach*/0xD5, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +0000660};
661
662/*
663SYSTEM INFORMATION TYPE 3
664 Cell identity = 00001 (1h)
665 Location area identification
666 Mobile Country Code (MCC): 001
667 Mobile Network Code (MNC): 01
668 Location Area Code (LAC): 00001 (1h)
669 Control Channel Description
670 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
671 0 blocks reserved for access grant
672 1 channel used for CCCH, with SDCCH
673 5 multiframes period for PAGING REQUEST
674 Time-out T3212 = 0
675 Cell Options BCCH
676 Power control indicator: not set
677 MSs shall not use uplink DTX
678 Radio link timeout = 36
679 Cell Selection Parameters
680 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
Harald Welte3b2ec422008-12-29 04:11:14 +0000681 max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max)
Harald Welte52b1f982008-12-23 20:25:15 +0000682 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
683 Half rate support (NECI): New establishment causes are not supported
684 min.RX signal level for MS = 0
685 RACH Control Parameters
686 maximum 7 retransmissions
687 8 slots used to spread transmission
688 cell not barred for access
689 call reestablishment not allowed
690 Access Control Class = 0000
691 SI 3 Rest Octets
692 Cell Bar Qualify (CBQ): 0
693 Cell Reselect Offset = 0 dB
694 Temporary Offset = 0 dB
695 Penalty Time = 20 s
696 System Information 2ter Indicator (2TI): 0 = not available
697 Early Classmark Sending Control (ECSC): 0 = forbidden
698 Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
699*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000700static u_int8_t si3[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000701 /* header */0x49, 0x06, 0x1B,
702 /* cell */0x00, 0x01,
703 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
704 /* desc */0x01, 0x03, 0x00,
705 /* option*/0x28,
706 /* selection*/0x62, 0x00,
707 /* rach */0xD5, 0x00, 0x00,
708 /* reset*/0x80, 0x00, 0x00, 0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000709};
710
711/*
712SYSTEM INFORMATION TYPE 4
713 Location area identification
714 Mobile Country Code (MCC): 001
715 Mobile Network Code (MNC): 01
716 Location Area Code (LAC): 00001 (1h)
717 Cell Selection Parameters
718 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
719 max.TX power level MS may use for CCH = 2
720 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
721 Half rate support (NECI): New establishment causes are not supported
722 min.RX signal level for MS = 0
723 RACH Control Parameters
724 maximum 7 retransmissions
725 8 slots used to spread transmission
726 cell not barred for access
727 call reestablishment not allowed
728 Access Control Class = 0000
729 Channel Description
730 Type = SDCCH/4[2]
731 Timeslot Number: 0
732 Training Sequence Code: 7h
733 ARFCN: 1
734 SI Rest Octets
735 Cell Bar Qualify (CBQ): 0
736 Cell Reselect Offset = 0 dB
737 Temporary Offset = 0 dB
738 Penalty Time = 20 s
739*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000740static u_int8_t si4[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000741 /* header */0x41, 0x06, 0x1C,
742 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
743 /* sel */0x62, 0x00,
744 /* rach*/0xD5, 0x00, 0x00,
745 /* var */0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000746 0x2B, 0x2B, 0x2B
747};
748
749/*
750 SYSTEM INFORMATION TYPE 5
751 Neighbour Cells Description
752 EXT-IND: Carries the complete BA
753 BA-IND = 0
754 Format-ID bit map 0
755 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
756*/
757
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000758static u_int8_t si5[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000759 /* header without l2 len*/0x06, 0x1D,
760 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
761 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000762};
763
764// SYSTEM INFORMATION TYPE 6
765
766/*
767SACCH FILLING
768 System Info Type: SYSTEM INFORMATION 6
769 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
770
771SYSTEM INFORMATION TYPE 6
772 Cell identity = 00001 (1h)
773 Location area identification
774 Mobile Country Code (MCC): 001
775 Mobile Network Code (MNC): 01
776 Location Area Code (LAC): 00001 (1h)
777 Cell Options SACCH
778 Power control indicator: not set
779 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
780 Radio link timeout = 36
781 NCC permitted (NCC) = FF
782*/
783
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000784static u_int8_t si6[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000785 /* header */0x06, 0x1E,
786 /* cell id*/ 0x00, 0x01,
787 /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01,
788 /* options */ 0x28,
789 /* ncc */ 0xFF,
Harald Welte52b1f982008-12-23 20:25:15 +0000790};
791
792
793
794static const struct bcch_info bcch_infos[] = {
795 {
796 .type = RSL_SYSTEM_INFO_1,
797 .len = sizeof(si1),
798 .data = si1,
799 }, {
800 .type = RSL_SYSTEM_INFO_2,
801 .len = sizeof(si2),
802 .data = si2,
803 }, {
804 .type = RSL_SYSTEM_INFO_3,
805 .len = sizeof(si3),
806 .data = si3,
807 }, {
808 .type = RSL_SYSTEM_INFO_4,
809 .len = sizeof(si4),
810 .data = si4,
811 },
812};
813
Holger Freyther24287b62008-12-28 16:32:41 +0000814static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1)
815static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2)
816static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3)
817static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4)
Harald Welte104604e2008-12-28 16:36:11 +0000818static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5)
819static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6)
Holger Freyther24287b62008-12-28 16:32:41 +0000820
Harald Welte52b1f982008-12-23 20:25:15 +0000821/* set all system information types */
Harald Weltee79769b2009-02-07 00:48:17 +0000822static int set_system_infos(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000823{
824 int i;
825
826 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
Harald Weltee79769b2009-02-07 00:48:17 +0000827 rsl_bcch_info(trx, bcch_infos[i].type,
Harald Welte52b1f982008-12-23 20:25:15 +0000828 bcch_infos[i].data,
829 bcch_infos[i].len);
830 }
Harald Weltee79769b2009-02-07 00:48:17 +0000831 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
832 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
Harald Weltead384642008-12-26 10:20:07 +0000833
834 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000835}
836
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000837/*
838 * Patch the various SYSTEM INFORMATION tables to update
839 * the LAI
840 */
841static void patch_tables(struct gsm_bts *bts)
842{
Harald Welte110c0ab2009-05-23 16:27:05 +0000843 u_int8_t arfcn_low = bts->trx[0].arfcn & 0xff;
844 u_int8_t arfcn_high = (bts->trx[0].arfcn >> 8) & 0x0f;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000845 /* covert the raw packet to the struct */
846 struct gsm48_system_information_type_3 *type_3 =
847 (struct gsm48_system_information_type_3*)&si3;
848 struct gsm48_system_information_type_4 *type_4 =
849 (struct gsm48_system_information_type_4*)&si4;
850 struct gsm48_system_information_type_6 *type_6 =
851 (struct gsm48_system_information_type_6*)&si6;
Harald Welteb84e2f42008-12-28 23:42:04 +0000852 struct gsm48_loc_area_id lai;
853
854 gsm0408_generate_lai(&lai, bts->network->country_code,
Harald Welte110c0ab2009-05-23 16:27:05 +0000855 bts->network->network_code,
856 bts->location_area_code);
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000857
858 /* assign the MCC and MNC */
Harald Welteb84e2f42008-12-28 23:42:04 +0000859 type_3->lai = lai;
860 type_4->lai = lai;
861 type_6->lai = lai;
Harald Welte98981882009-01-06 18:59:11 +0000862
Harald Welte94009322009-02-15 15:38:42 +0000863 /* patch ARFCN into BTS Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000864 msg_2[74] &= 0xf0;
865 msg_2[74] |= arfcn_high;
866 msg_2[75] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000867 nanobts_attr_bts[42] &= 0xf0;
868 nanobts_attr_bts[42] |= arfcn_high;
869 nanobts_attr_bts[43] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000870
Harald Welte94009322009-02-15 15:38:42 +0000871 /* patch ARFCN into TRX Attributes */
Harald Welte98981882009-01-06 18:59:11 +0000872 msg_6[7] &= 0xf0;
873 msg_6[7] |= arfcn_high;
874 msg_6[8] = arfcn_low;
Harald Welte94009322009-02-15 15:38:42 +0000875 nanobts_attr_radio[5] &= 0xf0;
876 nanobts_attr_radio[5] |= arfcn_high;
877 nanobts_attr_radio[6] = arfcn_low;
Harald Welte98981882009-01-06 18:59:11 +0000878
879 type_4->data[2] &= 0xf0;
880 type_4->data[2] |= arfcn_high;
881 type_4->data[3] = arfcn_low;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000882
883 /* patch Control Channel Description 10.5.2.11 */
884 type_3->control_channel_desc = bts->chan_desc;
Harald Welte78f2f502009-05-23 16:56:52 +0000885
886 /* patch BSIC */
887 msg_2[6] = bts->bsic;
888 nanobts_attr_bts[sizeof(nanobts_attr_bts)-1] = bts->bsic;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000889}
890
891
Harald Weltee79769b2009-02-07 00:48:17 +0000892static void bootstrap_rsl(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000893{
Harald Welteedb37782009-05-01 14:59:07 +0000894 fprintf(stdout, "bootstrapping RSL for BTS/TRX (%u/%u) "
895 "using MCC=%u MNC=%u\n", trx->nr, trx->bts->nr, MCC, MNC);
Harald Weltee79769b2009-02-07 00:48:17 +0000896 set_system_infos(trx);
Harald Welte52b1f982008-12-23 20:25:15 +0000897}
898
Harald Welte1fa60c82009-02-09 18:13:26 +0000899void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
Harald Weltead384642008-12-26 10:20:07 +0000900{
901 switch (event) {
Harald Welte1fa60c82009-02-09 18:13:26 +0000902 case EVT_E1_TEI_UP:
903 switch (type) {
904 case E1INP_SIGN_OML:
905 bootstrap_om(trx->bts);
906 break;
907 case E1INP_SIGN_RSL:
908 bootstrap_rsl(trx);
909 break;
910 default:
911 break;
912 }
Harald Weltead384642008-12-26 10:20:07 +0000913 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000914 case EVT_E1_TEI_DN:
915 fprintf(stderr, "Lost some E1 TEI link\n");
916 /* FIXME: deal with TEI or L1 link loss */
Harald Weltead384642008-12-26 10:20:07 +0000917 break;
918 default:
Harald Weltead384642008-12-26 10:20:07 +0000919 break;
920 }
921}
922
Harald Welteedb37782009-05-01 14:59:07 +0000923static int bootstrap_bts(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000924{
Holger Freyther0a173bf2009-04-22 22:07:07 +0000925 bts->location_area_code = LAC;
Harald Welte98981882009-01-06 18:59:11 +0000926 bts->trx[0].arfcn = ARFCN;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000927
928 /* Control Channel Description */
929 memset(&bts->chan_desc, 0, sizeof(struct gsm48_control_channel_descr));
Harald Welte41fbf442009-02-24 22:34:22 +0000930 bts->chan_desc.att = 1;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000931 bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
932 bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
933 bts->chan_desc.t3212 = 0;
934
Harald Welte98981882009-01-06 18:59:11 +0000935 patch_tables(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000936
Holger Freyther1fd34142009-02-09 23:42:03 +0000937 paging_init(bts);
Harald Welte38c2f132009-01-06 23:10:57 +0000938
Harald Welteedb37782009-05-01 14:59:07 +0000939 return 0;
940}
941
942static int bootstrap_network(void)
943{
944 struct gsm_bts *bts;
945
946 /* initialize our data structures */
947 gsmnet = gsm_network_init(2, BTS_TYPE, MCC, MNC);
948 if (!gsmnet)
949 return -ENOMEM;
950
951 gsmnet->name_long = "OpenBSC";
952 gsmnet->name_short = "OpenBSC";
953
954 bts = &gsmnet->bts[0];
955 bootstrap_bts(bts);
956
Holger Freyther36650b82009-04-19 06:35:16 +0000957 if (db_init(database_name, gsmnet)) {
Holger Freytheref7f7ce2009-04-19 06:35:12 +0000958 printf("DB: Failed to init database. Please check the option settings.\n");
959 return -1;
960 }
961 printf("DB: Database initialized.\n");
962
963 if (db_prepare()) {
964 printf("DB: Failed to prepare database.\n");
965 return -1;
966 }
967 printf("DB: Database prepared.\n");
968
Holger Freyther219518d2009-01-02 22:04:43 +0000969 telnet_init(gsmnet, 4242);
Harald Weltead384642008-12-26 10:20:07 +0000970
Harald Welteb4630602009-05-01 15:43:22 +0000971 register_signal_handler(SS_NM, nm_sig_cb, NULL);
972
Harald Welte1fa60c82009-02-09 18:13:26 +0000973 /* E1 mISDN input setup */
Harald Welteedb37782009-05-01 14:59:07 +0000974 if (BTS_TYPE == GSM_BTS_TYPE_BS11) {
975 gsmnet->num_bts = 1;
Holger Freytherb5c00f52009-04-22 22:08:07 +0000976 return e1_config(bts, cardnr, release_l2);
Harald Welteedb37782009-05-01 14:59:07 +0000977 } else {
978 /* FIXME: do this dynamic */
979 bts->ip_access.site_id = 1801;
980 bts->ip_access.bts_id = 0;
981 bts = &gsmnet->bts[1];
982 bootstrap_bts(bts);
983 bts->ip_access.site_id = 1800;
984 bts->ip_access.bts_id = 0;
Harald Weltecf559782009-05-01 15:43:49 +0000985 return ipaccess_setup(gsmnet);
Harald Welteedb37782009-05-01 14:59:07 +0000986 }
Harald Welte52b1f982008-12-23 20:25:15 +0000987}
Harald Weltef6b7a902008-12-26 00:05:11 +0000988
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000989static void create_pcap_file(char *file)
990{
991 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
992 int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
993
994 if (fd < 0) {
995 perror("Failed to open file for pcap");
996 return;
997 }
998
Holger Freyther0469cf62009-03-31 12:14:16 +0000999 e1_set_pcap_fd(fd);
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001000}
1001
Holger Freytherb332f612008-12-27 12:46:51 +00001002static void print_usage()
1003{
1004 printf("Usage: bsc_hack\n");
1005}
1006
1007static void print_help()
1008{
1009 printf(" Some useful help...\n");
1010 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
Holger Freytherefde7fb2008-12-28 14:14:56 +00001011 printf(" -s --disable-color\n");
1012 printf(" -n --network-code number(MNC) \n");
1013 printf(" -c --country-code number (MCC) \n");
Holger Freyther0a173bf2009-04-22 22:07:07 +00001014 printf(" -L --location-area-code number (LAC) \n");
Harald Welte98981882009-01-06 18:59:11 +00001015 printf(" -f --arfcn number The frequency ARFCN\n");
Holger Freytherbde36102008-12-28 22:51:39 +00001016 printf(" -l --database db-name The database to use\n");
Holger Freyther89824fc2008-12-30 16:18:18 +00001017 printf(" -a --authorize-everyone Allow everyone into the network.\n");
Holger Freythere97f7fb2008-12-31 18:52:11 +00001018 printf(" -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n");
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001019 printf(" -p --pcap file The filename of the pcap file\n");
Harald Weltee1bd2412009-02-15 14:40:09 +00001020 printf(" -t --bts-type type The BTS type (bs11, nanobts900, nanobts1800)\n");
Holger Freytherdda22c12009-04-22 22:07:31 +00001021 printf(" -C --cardnr number For bs11 select E1 card number other than 0\n");
Holger Freytherb5c00f52009-04-22 22:08:07 +00001022 printf(" -R --release-l2 Releases mISDN layer 2 after exit, to unload driver.\n");
Holger Freytherb332f612008-12-27 12:46:51 +00001023 printf(" -h --help this text\n");
1024}
1025
1026static void handle_options(int argc, char** argv)
1027{
1028 while (1) {
1029 int option_index = 0, c;
1030 static struct option long_options[] = {
1031 {"help", 0, 0, 'h'},
1032 {"debug", 1, 0, 'd'},
Holger Freytherefde7fb2008-12-28 14:14:56 +00001033 {"disable-color", 0, 0, 's'},
1034 {"network-code", 1, 0, 'n'},
1035 {"country-code", 1, 0, 'c'},
Holger Freyther0a173bf2009-04-22 22:07:07 +00001036 {"location-area-code", 1, 0, 'L'},
Holger Freytherbde36102008-12-28 22:51:39 +00001037 {"database", 1, 0, 'l'},
Holger Freyther89824fc2008-12-30 16:18:18 +00001038 {"authorize-everyone", 0, 0, 'a'},
Holger Freythere97f7fb2008-12-31 18:52:11 +00001039 {"reject-cause", 1, 0, 'r'},
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001040 {"pcap", 1, 0, 'p'},
Harald Welte98981882009-01-06 18:59:11 +00001041 {"arfcn", 1, 0, 'f'},
Harald Welte8c1d0e42009-02-15 03:38:12 +00001042 {"bts-type", 1, 0, 't'},
Holger Freytherdda22c12009-04-22 22:07:31 +00001043 {"cardnr", 1, 0, 'C'},
Holger Freytherb5c00f52009-04-22 22:08:07 +00001044 {"release-l2", 0, 0, 'R'},
Holger Freytherb332f612008-12-27 12:46:51 +00001045 {0, 0, 0, 0}
1046 };
1047
Holger Freytherb5c00f52009-04-22 22:08:07 +00001048 c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:C:RL:",
Holger Freytherb332f612008-12-27 12:46:51 +00001049 long_options, &option_index);
1050 if (c == -1)
1051 break;
1052
1053 switch (c) {
1054 case 'h':
1055 print_usage();
1056 print_help();
1057 exit(0);
Holger Freytherefde7fb2008-12-28 14:14:56 +00001058 case 's':
Holger Freytherb332f612008-12-27 12:46:51 +00001059 debug_use_color(0);
1060 break;
1061 case 'd':
1062 debug_parse_category_mask(optarg);
1063 break;
Holger Freytherefde7fb2008-12-28 14:14:56 +00001064 case 'n':
1065 MNC = atoi(optarg);
1066 break;
1067 case 'c':
1068 MCC = atoi(optarg);
1069 break;
Holger Freyther0a173bf2009-04-22 22:07:07 +00001070 case 'L':
1071 LAC = atoi(optarg);
1072 break;
Harald Welte98981882009-01-06 18:59:11 +00001073 case 'f':
1074 ARFCN = atoi(optarg);
1075 break;
Harald Welte8965da42009-01-06 18:09:02 +00001076 case 'l':
Holger Freytherbde36102008-12-28 22:51:39 +00001077 database_name = strdup(optarg);
1078 break;
Holger Freyther89824fc2008-12-30 16:18:18 +00001079 case 'a':
1080 gsm0408_allow_everyone(1);
1081 break;
Holger Freythere97f7fb2008-12-31 18:52:11 +00001082 case 'r':
1083 gsm0408_set_reject_cause(atoi(optarg));
1084 break;
Holger Freyther9a3ee0f2009-01-02 00:40:15 +00001085 case 'p':
1086 create_pcap_file(optarg);
1087 break;
Harald Welte8c1d0e42009-02-15 03:38:12 +00001088 case 't':
1089 BTS_TYPE = parse_btstype(optarg);
1090 break;
Holger Freytherdda22c12009-04-22 22:07:31 +00001091 case 'C':
1092 cardnr = atoi(optarg);
1093 break;
Holger Freytherb5c00f52009-04-22 22:08:07 +00001094 case 'R':
1095 release_l2 = 1;
1096 break;
Holger Freytherb332f612008-12-27 12:46:51 +00001097 default:
1098 /* ignore */
1099 break;
1100 }
1101 }
1102}
1103
Harald Welted1252502009-01-01 01:50:32 +00001104static void signal_handler(int signal)
1105{
1106 fprintf(stdout, "signal %u received\n", signal);
1107
1108 switch (signal) {
1109 case SIGHUP:
1110 case SIGABRT:
1111 shutdown_net(gsmnet);
1112 break;
1113 default:
1114 break;
1115 }
1116}
1117
Harald Weltef6b7a902008-12-26 00:05:11 +00001118int main(int argc, char **argv)
1119{
Harald Welte1fa60c82009-02-09 18:13:26 +00001120 int rc;
1121
Holger Freytherb332f612008-12-27 12:46:51 +00001122 /* parse options */
1123 handle_options(argc, argv);
1124
Harald Welte65ccf882009-02-24 22:36:20 +00001125 /* seed the PRNG */
1126 srand(time(NULL));
1127
Harald Welte1fa60c82009-02-09 18:13:26 +00001128 rc = bootstrap_network();
1129 if (rc < 0)
1130 exit(1);
Harald Weltef6b7a902008-12-26 00:05:11 +00001131
Harald Welted1252502009-01-01 01:50:32 +00001132 signal(SIGHUP, &signal_handler);
1133 signal(SIGABRT, &signal_handler);
1134
Harald Weltef6b7a902008-12-26 00:05:11 +00001135 while (1) {
Harald Welte04d3c922009-05-23 06:07:04 +00001136 bsc_select_main(0);
Harald Weltef6b7a902008-12-26 00:05:11 +00001137 }
1138}