blob: a7ed58501cdd99a3afb1c598f5c6b99dfa1f1698 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* A hackish minimal BSC (+MSC +HLR) implementation */
2
3/* (C) 2008 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;
Holger Freytherbde36102008-12-28 22:51:39 +000057static const char *database_name = "hlr.sqlite3";
Holger Freytherefde7fb2008-12-28 14:14:56 +000058
Harald Welte52b1f982008-12-23 20:25:15 +000059/* The following definitions are for OM and NM packets that we cannot yet
60 * generate by code but we just pass on */
61
62// BTS Site Manager, SET ATTRIBUTES
63
64/*
65 Object Class: BTS Site Manager
66 Instance 1: FF
67 Instance 2: FF
68 Instance 3: FF
69SET ATTRIBUTES
70 sAbisExternalTime: 2007/09/08 14:36:11
71 omLAPDRelTimer: 30sec
72 shortLAPDIntTimer: 5sec
73 emergencyTimer1: 10 minutes
74 emergencyTimer2: 0 minutes
75*/
76
77unsigned char msg_1[] =
78{
79 0xD0, 0x00, 0xFF, 0xFF, 0xFF, 0x91, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24,
80 0x0B, 0xCE, 0x02, 0x00, 0x1E, 0xE8, 0x01, 0x05, 0x42, 0x02, 0x00, 0x0A, 0x44,
81 0x02, 0x00, 0x00
82};
83
84// BTS, SET BTS ATTRIBUTES
85
86/*
87 Object Class: BTS
88 BTS relat. Number: 0
89 Instance 2: FF
90 Instance 3: FF
91SET BTS ATTRIBUTES
92 bsIdentityCode / BSIC:
93 PLMN_colour_code: 7h
94 BS_colour_code: 7h
95 BTS Air Timer T3105: 4 ,unit 10 ms
96 btsIsHopping: FALSE
Harald Welte83282292009-02-01 16:22:19 +000097 periodCCCHLoadIndication: 1sec
Harald Welte0bbb8b22009-02-06 12:49:11 +000098 thresholdCCCHLoadIndication: 50%
Harald Welte52b1f982008-12-23 20:25:15 +000099 cellAllocationNumber: 00h = GSM 900
100 enableInterferenceClass: 00h = Disabled
101 fACCHQual: 6 (FACCH stealing flags minus 1)
102 intaveParameter: 31 SACCH multiframes
103 interferenceLevelBoundaries:
104 Interference Boundary 1: 0Ah
105 Interference Boundary 2: 0Fh
106 Interference Boundary 3: 14h
107 Interference Boundary 4: 19h
108 Interference Boundary 5: 1Eh
109 mSTxPwrMax: 11
110 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
111 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
112 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
113 30=33dBm, 31=32dBm
114 ny1:
115 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
116 powerOutputThresholds:
117 Out Power Fault Threshold: -10 dB
118 Red Out Power Threshold: - 6 dB
119 Excessive Out Power Threshold: 5 dB
120 rACHBusyThreshold: -127 dBm
121 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
122 rfResourceIndicationPeriod: 125 SACCH multiframes
123 T200:
124 SDCCH: 044 in 5 ms
125 FACCH/Full rate: 031 in 5 ms
126 FACCH/Half rate: 041 in 5 ms
127 SACCH with TCH SAPI0: 090 in 10 ms
128 SACCH with SDCCH: 090 in 10 ms
129 SDCCH with SAPI3: 090 in 5 ms
130 SACCH with TCH SAPI3: 135 in 10 ms
131 tSync: 9000 units of 10 msec
132 tTrau: 9000 units of 10 msec
133 enableUmLoopTest: 00h = disabled
134 enableExcessiveDistance: 00h = Disabled
135 excessiveDistance: 64km
136 hoppingMode: 00h = baseband hopping
137 cellType: 00h = Standard Cell
138 BCCH ARFCN / bCCHFrequency: 1
139*/
140
141unsigned char msg_2[] =
142{
143 0x41, 0x01, 0x00, 0xFF, 0xFF, 0x09, 0x3F, 0x0A, 0x04, 0x61, 0x00, 0x0B,
Harald Welte0bbb8b22009-02-06 12:49:11 +0000144 0x01, 0x0C, 0x32, 0x62, 0x00, 0x66, 0x00, 0x6E, 0x06, 0x18, 0x1F, 0x19,
Harald Welte52b1f982008-12-23 20:25:15 +0000145 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B, 0x0B, 0x23, 0x14, 0x28, 0x00, 0x04,
146 0x03, 0x2A, 0x7F, 0x2B, 0x00, 0xFA, 0x8F, 0x7D, 0x33, 0x2C, 0x1F, 0x29,
147 0x5A, 0x5A, 0x5A, 0x87, 0x94, 0x23, 0x28, 0x95, 0x23, 0x28, 0x35, 0x01,
148 0x00, 0x46, 0x01, 0x00, 0x58, 0x01, 0x40, 0xC5, 0x01, 0x00, 0xF2, 0x01,
149 0x00, 0x08, 0x00, HARDCODED_ARFCN/*0x01*/,
150};
151
152// Handover Recognition, SET ATTRIBUTES
153
154/*
155Illegal Contents GSM Formatted O&M Msg
156 Object Class: Handover Recognition
157 BTS relat. Number: 0
158 Instance 2: FF
159 Instance 3: FF
160SET ATTRIBUTES
161 enableDelayPowerBudgetHO: 00h = Disabled
162 enableDistanceHO: 00h = Disabled
163 enableInternalInterCellHandover: 00h = Disabled
164 enableInternalIntraCellHandover: 00h = Disabled
165 enablePowerBudgetHO: 00h = Disabled
166 enableRXLEVHO: 00h = Disabled
167 enableRXQUALHO: 00h = Disabled
168 hoAveragingDistance: 8 SACCH multiframes
169 hoAveragingLev:
170 A_LEV_HO: 8 SACCH multiframes
171 W_LEV_HO: 1 SACCH multiframes
172 hoAveragingPowerBudget: 16 SACCH multiframes
173 hoAveragingQual:
174 A_QUAL_HO: 8 SACCH multiframes
175 W_QUAL_HO: 2 SACCH multiframes
176 hoLowerThresholdLevDL: (10 - 110) dBm
177 hoLowerThresholdLevUL: (5 - 110) dBm
178 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
179 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
180 hoThresholdLevDLintra : (20 - 110) dBm
181 hoThresholdLevULintra: (20 - 110) dBm
182 hoThresholdMsRangeMax: 20 km
183 nCell: 06h
184 timerHORequest: 3 ,unit 2 SACCH multiframes
185*/
186
187unsigned char msg_3[] =
188{
189 0xD0, 0xA1, 0x00, 0xFF, 0xFF, 0xD0, 0x00, 0x64, 0x00, 0x67, 0x00, 0x68,
190 0x00, 0x6A, 0x00, 0x6C, 0x00, 0x6D, 0x00, 0x6F, 0x08, 0x70, 0x08, 0x01,
191 0x71, 0x10, 0x10, 0x10, 0x72, 0x08, 0x02, 0x73, 0x0A, 0x74, 0x05, 0x75,
192 0x06, 0x76, 0x06, 0x78, 0x14, 0x79, 0x14, 0x7A, 0x14, 0x7D, 0x06, 0x92,
193 0x03, 0x20, 0x01, 0x00, 0x45, 0x01, 0x00, 0x48, 0x01, 0x00, 0x5A, 0x01,
194 0x00, 0x5B, 0x01, 0x05, 0x5E, 0x01, 0x1A, 0x5F, 0x01, 0x20, 0x9D, 0x01,
195 0x00, 0x47, 0x01, 0x00, 0x5C, 0x01, 0x64, 0x5D, 0x01, 0x1E, 0x97, 0x01,
196 0x20, 0xF7, 0x01, 0x3C,
197};
198
199// Power Control, SET ATTRIBUTES
200
201/*
202 Object Class: Power Control
203 BTS relat. Number: 0
204 Instance 2: FF
205 Instance 3: FF
206SET ATTRIBUTES
207 enableMsPowerControl: 00h = Disabled
208 enablePowerControlRLFW: 00h = Disabled
209 pcAveragingLev:
210 A_LEV_PC: 4 SACCH multiframes
211 W_LEV_PC: 1 SACCH multiframes
212 pcAveragingQual:
213 A_QUAL_PC: 4 SACCH multiframes
214 W_QUAL_PC: 2 SACCH multiframes
215 pcLowerThresholdLevDL: 0Fh
216 pcLowerThresholdLevUL: 0Ah
217 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
218 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
219 pcRLFThreshold: 0Ch
220 pcUpperThresholdLevDL: 14h
221 pcUpperThresholdLevUL: 0Fh
222 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
223 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
224 powerConfirm: 2 ,unit 2 SACCH multiframes
225 powerControlInterval: 2 ,unit 2 SACCH multiframes
226 powerIncrStepSize: 02h = 4 dB
227 powerRedStepSize: 01h = 2 dB
228 radioLinkTimeoutBs: 64 SACCH multiframes
229 enableBSPowerControl: 00h = disabled
230*/
231
232unsigned char msg_4[] =
233{
234 0xD0, 0xA2, 0x00, 0xFF, 0xFF, 0x69, 0x00, 0x6B, 0x00, 0x7E, 0x04, 0x01,
235 0x7F, 0x04, 0x02, 0x80, 0x0F, 0x81, 0x0A, 0x82, 0x05, 0x83, 0x05, 0x84,
236 0x0C, 0x85, 0x14, 0x86, 0x0F, 0x87, 0x04, 0x88, 0x04, 0x89, 0x02, 0x8A,
237 0x02, 0x8B, 0x02, 0x8C, 0x01, 0x8D, 0x40, 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
238};
239
240
241// Transceiver, SET TRX ATTRIBUTES (TRX 0)
242
243/*
244 Object Class: Transceiver
245 BTS relat. Number: 0
246 Tranceiver number: 0
247 Instance 3: FF
248SET TRX ATTRIBUTES
249 aRFCNList (HEX): 0001
250 txPwrMaxReduction: 00h = 0dB
251 radioMeasGran: 254 SACCH multiframes
252 radioMeasRep: 01h = enabled
253 memberOfEmergencyConfig: 01h = TRUE
254 trxArea: 00h = TRX doesn't belong to a concentric cell
255*/
256
257unsigned char msg_6[] =
258{
259 0x44, 0x02, 0x00, 0x00, 0xFF, 0x05, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/, 0x2D,
260 0x00, 0xDC, 0x01, 0xFE, 0xDD, 0x01, 0x01, 0x9B, 0x01, 0x01, 0x9F, 0x01, 0x00,
261};
262
263
264static void bootstrap_om(struct gsm_bts *bts)
265{
266 struct gsm_bts_trx *trx = &bts->trx[0];
267
Harald Weltead384642008-12-26 10:20:07 +0000268 fprintf(stdout, "bootstrapping OML\n");
269
Harald Welte52b1f982008-12-23 20:25:15 +0000270 /* stop sending event reports */
271 abis_nm_event_reports(bts, 0);
272
273 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000274 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000275
Harald Welte702d8702008-12-26 20:25:35 +0000276 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000277 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte702d8702008-12-26 20:25:35 +0000278
279 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000280 abis_nm_bs11_reset_resource(bts);
Harald Welte702d8702008-12-26 20:25:35 +0000281
282 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000283 abis_nm_bs11_db_transmission(bts, 1);
Harald Welte702d8702008-12-26 20:25:35 +0000284
Harald Welte52b1f982008-12-23 20:25:15 +0000285 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
286 abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */
287 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
288 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
289
290 /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */
291 abis_nm_conn_terr_sign(trx, 0, 1, 0xff);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000292 set_ts_e1link(&trx->ts[0], 0, 1, 0xff);
Harald Welte52b1f982008-12-23 20:25:15 +0000293 abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */
294
295 /* Use TEI 1 for signalling */
296 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01);
297 abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH);
Harald Weltecd06bfb2009-02-10 17:33:56 +0000298
299#ifdef HAVE_TRX1
Harald Welte52b1f982008-12-23 20:25:15 +0000300 /* TRX 1 */
301 abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff);
302 /* FIXME: TRX ATTRIBUTE */
303 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02);
304#endif
305
306 /* SET CHANNEL ATTRIBUTE TS1 */
307 abis_nm_set_channel_attr(&trx->ts[1], 0x09);
308 /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000309 set_ts_e1link(&trx->ts[1], 0, 2, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000310 abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1);
311
312 /* SET CHANNEL ATTRIBUTE TS2 */
313 abis_nm_set_channel_attr(&trx->ts[2], 0x09);
314 /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000315 set_ts_e1link(&trx->ts[2], 0, 2, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000316 abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2);
317
318 /* SET CHANNEL ATTRIBUTE TS3 */
319 abis_nm_set_channel_attr(&trx->ts[3], 0x09);
320 /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000321 set_ts_e1link(&trx->ts[3], 0, 2, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000322 abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3);
323
324 /* SET CHANNEL ATTRIBUTE TS4 */
325 abis_nm_set_channel_attr(&trx->ts[4], 0x09);
326 /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000327 set_ts_e1link(&trx->ts[4], 0, 3, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000328 abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0);
329
330 /* SET CHANNEL ATTRIBUTE TS5 */
331 abis_nm_set_channel_attr(&trx->ts[5], 0x09);
332 /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000333 set_ts_e1link(&trx->ts[5], 0, 3, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000334 abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1);
335
336 /* SET CHANNEL ATTRIBUTE TS6 */
337 abis_nm_set_channel_attr(&trx->ts[6], 0x09);
338 /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000339 set_ts_e1link(&trx->ts[6], 0, 3, 2);
Harald Welte52b1f982008-12-23 20:25:15 +0000340 abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2);
341
342 /* SET CHANNEL ATTRIBUTE TS7 */
343 abis_nm_set_channel_attr(&trx->ts[7], 0x09);
344 /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */
Harald Weltecd06bfb2009-02-10 17:33:56 +0000345 set_ts_e1link(&trx->ts[7], 0, 3, 3);
Harald Welte52b1f982008-12-23 20:25:15 +0000346 abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3);
347
348 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000349 abis_nm_bs11_db_transmission(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000350
351 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000352 abis_nm_bs11_reset_resource(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000353
354 /* restart sending event reports */
355 abis_nm_event_reports(bts, 1);
356}
357
Harald Welted1252502009-01-01 01:50:32 +0000358static int shutdown_om(struct gsm_bts *bts)
359{
360 /* stop sending event reports */
361 abis_nm_event_reports(bts, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000362
Harald Welted1252502009-01-01 01:50:32 +0000363 /* begin DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000364 abis_nm_bs11_db_transmission(bts, 1);
Harald Welted1252502009-01-01 01:50:32 +0000365
366 /* end DB transmission */
Harald Welte05188ee2009-01-18 11:39:08 +0000367 abis_nm_bs11_db_transmission(bts, 0);
Harald Welted1252502009-01-01 01:50:32 +0000368
369 /* Reset BTS Site manager resource */
Harald Welte78374892009-01-18 19:09:22 +0000370 abis_nm_bs11_reset_resource(bts);
Harald Welted1252502009-01-01 01:50:32 +0000371
372 return 0;
373}
374
375static int shutdown_net(struct gsm_network *net)
376{
377 int i;
378 for (i = 0; i < net->num_bts; i++) {
379 int rc;
380 rc = shutdown_om(&net->bts[i]);
381 if (rc < 0)
382 return rc;
383 }
384
385 return 0;
386}
Harald Welte52b1f982008-12-23 20:25:15 +0000387
388struct bcch_info {
389 u_int8_t type;
390 u_int8_t len;
391 const u_int8_t *data;
392};
393
394/*
395SYSTEM INFORMATION TYPE 1
396 Cell channel description
397 Format-ID bit map 0
398 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
399 RACH Control Parameters
400 maximum 7 retransmissions
401 8 slots used to spread transmission
402 cell not barred for access
403 call reestablishment not allowed
404 Access Control Class = 0000
405*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000406static u_int8_t si1[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000407 /* header */0x55, 0x06, 0x19,
408 /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,
410 /* rach */0xD5, 0x00, 0x00,
411 /* s1 reset*/0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000412};
413
414/*
415 SYSTEM INFORMATION TYPE 2
416 Neighbour Cells Description
417 EXT-IND: Carries the complete BA
418 BA-IND = 0
419 Format-ID bit map 0
420 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
421 NCC permitted (NCC) = FF
422 RACH Control Parameters
423 maximum 7 retransmissions
424 8 slots used to spread transmission
425 cell not barred for access
426 call reestablishment not allowed
427 Access Control Class = 0000
428*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000429static u_int8_t si2[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000430 /* header */0x59, 0x06, 0x1A,
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
433 /* ncc */0xFF,
434 /* rach*/0xD5, 0x00, 0x00
Harald Welte52b1f982008-12-23 20:25:15 +0000435};
436
437/*
438SYSTEM INFORMATION TYPE 3
439 Cell identity = 00001 (1h)
440 Location area identification
441 Mobile Country Code (MCC): 001
442 Mobile Network Code (MNC): 01
443 Location Area Code (LAC): 00001 (1h)
444 Control Channel Description
445 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
446 0 blocks reserved for access grant
447 1 channel used for CCCH, with SDCCH
448 5 multiframes period for PAGING REQUEST
449 Time-out T3212 = 0
450 Cell Options BCCH
451 Power control indicator: not set
452 MSs shall not use uplink DTX
453 Radio link timeout = 36
454 Cell Selection Parameters
455 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
Harald Welte3b2ec422008-12-29 04:11:14 +0000456 max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max)
Harald Welte52b1f982008-12-23 20:25:15 +0000457 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
458 Half rate support (NECI): New establishment causes are not supported
459 min.RX signal level for MS = 0
460 RACH Control Parameters
461 maximum 7 retransmissions
462 8 slots used to spread transmission
463 cell not barred for access
464 call reestablishment not allowed
465 Access Control Class = 0000
466 SI 3 Rest Octets
467 Cell Bar Qualify (CBQ): 0
468 Cell Reselect Offset = 0 dB
469 Temporary Offset = 0 dB
470 Penalty Time = 20 s
471 System Information 2ter Indicator (2TI): 0 = not available
472 Early Classmark Sending Control (ECSC): 0 = forbidden
473 Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
474*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000475static u_int8_t si3[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000476 /* header */0x49, 0x06, 0x1B,
477 /* cell */0x00, 0x01,
478 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
479 /* desc */0x01, 0x03, 0x00,
480 /* option*/0x28,
481 /* selection*/0x62, 0x00,
482 /* rach */0xD5, 0x00, 0x00,
483 /* reset*/0x80, 0x00, 0x00, 0x2B
Harald Welte52b1f982008-12-23 20:25:15 +0000484};
485
486/*
487SYSTEM INFORMATION TYPE 4
488 Location area identification
489 Mobile Country Code (MCC): 001
490 Mobile Network Code (MNC): 01
491 Location Area Code (LAC): 00001 (1h)
492 Cell Selection Parameters
493 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
494 max.TX power level MS may use for CCH = 2
495 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
496 Half rate support (NECI): New establishment causes are not supported
497 min.RX signal level for MS = 0
498 RACH Control Parameters
499 maximum 7 retransmissions
500 8 slots used to spread transmission
501 cell not barred for access
502 call reestablishment not allowed
503 Access Control Class = 0000
504 Channel Description
505 Type = SDCCH/4[2]
506 Timeslot Number: 0
507 Training Sequence Code: 7h
508 ARFCN: 1
509 SI Rest Octets
510 Cell Bar Qualify (CBQ): 0
511 Cell Reselect Offset = 0 dB
512 Temporary Offset = 0 dB
513 Penalty Time = 20 s
514*/
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000515static u_int8_t si4[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000516 /* header */0x41, 0x06, 0x1C,
517 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
518 /* sel */0x62, 0x00,
519 /* rach*/0xD5, 0x00, 0x00,
520 /* var */0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000521 0x2B, 0x2B, 0x2B
522};
523
524/*
525 SYSTEM INFORMATION TYPE 5
526 Neighbour Cells Description
527 EXT-IND: Carries the complete BA
528 BA-IND = 0
529 Format-ID bit map 0
530 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
531*/
532
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000533static u_int8_t si5[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000534 /* header without l2 len*/0x06, 0x1D,
535 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
536 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Welte52b1f982008-12-23 20:25:15 +0000537};
538
539// SYSTEM INFORMATION TYPE 6
540
541/*
542SACCH FILLING
543 System Info Type: SYSTEM INFORMATION 6
544 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
545
546SYSTEM INFORMATION TYPE 6
547 Cell identity = 00001 (1h)
548 Location area identification
549 Mobile Country Code (MCC): 001
550 Mobile Network Code (MNC): 01
551 Location Area Code (LAC): 00001 (1h)
552 Cell Options SACCH
553 Power control indicator: not set
554 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
555 Radio link timeout = 36
556 NCC permitted (NCC) = FF
557*/
558
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000559static u_int8_t si6[] = {
Holger Freyther4d505472008-12-28 16:32:42 +0000560 /* header */0x06, 0x1E,
561 /* cell id*/ 0x00, 0x01,
562 /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01,
563 /* options */ 0x28,
564 /* ncc */ 0xFF,
Harald Welte52b1f982008-12-23 20:25:15 +0000565};
566
567
568
569static const struct bcch_info bcch_infos[] = {
570 {
571 .type = RSL_SYSTEM_INFO_1,
572 .len = sizeof(si1),
573 .data = si1,
574 }, {
575 .type = RSL_SYSTEM_INFO_2,
576 .len = sizeof(si2),
577 .data = si2,
578 }, {
579 .type = RSL_SYSTEM_INFO_3,
580 .len = sizeof(si3),
581 .data = si3,
582 }, {
583 .type = RSL_SYSTEM_INFO_4,
584 .len = sizeof(si4),
585 .data = si4,
586 },
587};
588
Holger Freyther24287b62008-12-28 16:32:41 +0000589static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1)
590static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2)
591static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3)
592static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4)
Harald Welte104604e2008-12-28 16:36:11 +0000593static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5)
594static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6)
Holger Freyther24287b62008-12-28 16:32:41 +0000595
Harald Welte52b1f982008-12-23 20:25:15 +0000596/* set all system information types */
Harald Weltee79769b2009-02-07 00:48:17 +0000597static int set_system_infos(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000598{
599 int i;
600
601 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
Harald Weltee79769b2009-02-07 00:48:17 +0000602 rsl_bcch_info(trx, bcch_infos[i].type,
Harald Welte52b1f982008-12-23 20:25:15 +0000603 bcch_infos[i].data,
604 bcch_infos[i].len);
605 }
Harald Weltee79769b2009-02-07 00:48:17 +0000606 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
607 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
Harald Weltead384642008-12-26 10:20:07 +0000608
609 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000610}
611
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000612/*
Harald Welte38c2f132009-01-06 23:10:57 +0000613 * Inform anyone...
614 */
615static void bsc_hack_channel_allocated(struct gsm_lchan *lchan) {
616}
617
618/*
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000619 * Patch the various SYSTEM INFORMATION tables to update
620 * the LAI
621 */
622static void patch_tables(struct gsm_bts *bts)
623{
Harald Welte98981882009-01-06 18:59:11 +0000624 u_int8_t arfcn_low = ARFCN & 0xff;
625 u_int8_t arfcn_high = (ARFCN >> 8) & 0x0f;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000626 /* covert the raw packet to the struct */
627 struct gsm48_system_information_type_3 *type_3 =
628 (struct gsm48_system_information_type_3*)&si3;
629 struct gsm48_system_information_type_4 *type_4 =
630 (struct gsm48_system_information_type_4*)&si4;
631 struct gsm48_system_information_type_6 *type_6 =
632 (struct gsm48_system_information_type_6*)&si6;
Harald Welteb84e2f42008-12-28 23:42:04 +0000633 struct gsm48_loc_area_id lai;
634
635 gsm0408_generate_lai(&lai, bts->network->country_code,
636 bts->network->network_code, bts->location_area_code);
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000637
638 /* assign the MCC and MNC */
Harald Welteb84e2f42008-12-28 23:42:04 +0000639 type_3->lai = lai;
640 type_4->lai = lai;
641 type_6->lai = lai;
Harald Welte98981882009-01-06 18:59:11 +0000642
643 /* patch ARFCN */
644 msg_2[74] &= 0xf0;
645 msg_2[74] |= arfcn_high;
646 msg_2[75] = arfcn_low;
647
648 msg_6[7] &= 0xf0;
649 msg_6[7] |= arfcn_high;
650 msg_6[8] = arfcn_low;
651
652 type_4->data[2] &= 0xf0;
653 type_4->data[2] |= arfcn_high;
654 type_4->data[3] = arfcn_low;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000655
656 /* patch Control Channel Description 10.5.2.11 */
657 type_3->control_channel_desc = bts->chan_desc;
Holger Freytherb9ddfd02008-12-28 16:32:45 +0000658}
659
660
Harald Weltee79769b2009-02-07 00:48:17 +0000661static void bootstrap_rsl(struct gsm_bts_trx *trx)
Harald Welte52b1f982008-12-23 20:25:15 +0000662{
Harald Welteb84e2f42008-12-28 23:42:04 +0000663 fprintf(stdout, "bootstrapping RSL MCC=%u MNC=%u\n", MCC, MNC);
Harald Weltee79769b2009-02-07 00:48:17 +0000664 set_system_infos(trx);
Harald Welte52b1f982008-12-23 20:25:15 +0000665}
666
Harald Welte1fa60c82009-02-09 18:13:26 +0000667void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
Harald Weltead384642008-12-26 10:20:07 +0000668{
669 switch (event) {
Harald Welte1fa60c82009-02-09 18:13:26 +0000670 case EVT_E1_TEI_UP:
671 switch (type) {
672 case E1INP_SIGN_OML:
673 bootstrap_om(trx->bts);
674 break;
675 case E1INP_SIGN_RSL:
676 bootstrap_rsl(trx);
677 break;
678 default:
679 break;
680 }
Harald Weltead384642008-12-26 10:20:07 +0000681 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000682 case EVT_E1_TEI_DN:
683 fprintf(stderr, "Lost some E1 TEI link\n");
684 /* FIXME: deal with TEI or L1 link loss */
Harald Weltead384642008-12-26 10:20:07 +0000685 break;
686 default:
Harald Weltead384642008-12-26 10:20:07 +0000687 break;
688 }
689}
690
691static int bootstrap_network(void)
Harald Welte52b1f982008-12-23 20:25:15 +0000692{
693 struct gsm_bts *bts;
694
695 /* initialize our data structures */
Holger Freytherefde7fb2008-12-28 14:14:56 +0000696 gsmnet = gsm_network_init(1, MCC, MNC);
Harald Weltead384642008-12-26 10:20:07 +0000697 if (!gsmnet)
698 return -ENOMEM;
Harald Weltef5cbab72008-12-30 18:00:15 +0000699
700 gsmnet->name_short = "25C3";
701 gsmnet->name_long = "25C3 GSM";
Harald Welte52b1f982008-12-23 20:25:15 +0000702 bts = &gsmnet->bts[0];
703 bts->location_area_code = 1;
Harald Welte98981882009-01-06 18:59:11 +0000704 bts->trx[0].arfcn = ARFCN;
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000705
706 /* Control Channel Description */
707 memset(&bts->chan_desc, 0, sizeof(struct gsm48_control_channel_descr));
708 bts->chan_desc.att = 0;
709 bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
710 bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
711 bts->chan_desc.t3212 = 0;
712
Harald Welte98981882009-01-06 18:59:11 +0000713 patch_tables(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000714
Holger Freyther1fd34142009-02-09 23:42:03 +0000715 paging_init(bts);
Holger Freytherceb59b72009-02-06 18:54:00 +0000716 bts->paging.channel_allocated = bsc_hack_channel_allocated;
Harald Welte38c2f132009-01-06 23:10:57 +0000717
Holger Freyther219518d2009-01-02 22:04:43 +0000718 telnet_init(gsmnet, 4242);
Harald Weltead384642008-12-26 10:20:07 +0000719
Harald Welte1fa60c82009-02-09 18:13:26 +0000720 /* E1 mISDN input setup */
721 return e1_config(bts);
Harald Welte52b1f982008-12-23 20:25:15 +0000722}
Harald Weltef6b7a902008-12-26 00:05:11 +0000723
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000724static void create_pcap_file(char *file)
725{
Harald Welte1fa60c82009-02-09 18:13:26 +0000726#if 0
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000727 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
728 int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
729
730 if (fd < 0) {
731 perror("Failed to open file for pcap");
732 return;
733 }
734
735 mi_set_pcap_fd(fd);
Harald Welte1fa60c82009-02-09 18:13:26 +0000736#else
737 fprintf(stderr, "PCAP support currently disabled!!\n");
738#endif
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000739}
740
Holger Freytherb332f612008-12-27 12:46:51 +0000741static void print_usage()
742{
743 printf("Usage: bsc_hack\n");
744}
745
746static void print_help()
747{
748 printf(" Some useful help...\n");
749 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
Holger Freytherefde7fb2008-12-28 14:14:56 +0000750 printf(" -s --disable-color\n");
751 printf(" -n --network-code number(MNC) \n");
752 printf(" -c --country-code number (MCC) \n");
Harald Welte98981882009-01-06 18:59:11 +0000753 printf(" -f --arfcn number The frequency ARFCN\n");
Holger Freytherbde36102008-12-28 22:51:39 +0000754 printf(" -l --database db-name The database to use\n");
Holger Freyther89824fc2008-12-30 16:18:18 +0000755 printf(" -a --authorize-everyone Allow everyone into the network.\n");
Holger Freythere97f7fb2008-12-31 18:52:11 +0000756 printf(" -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n");
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000757 printf(" -p --pcap file The filename of the pcap file\n");
Holger Freytherb332f612008-12-27 12:46:51 +0000758 printf(" -h --help this text\n");
759}
760
761static void handle_options(int argc, char** argv)
762{
763 while (1) {
764 int option_index = 0, c;
765 static struct option long_options[] = {
766 {"help", 0, 0, 'h'},
767 {"debug", 1, 0, 'd'},
Holger Freytherefde7fb2008-12-28 14:14:56 +0000768 {"disable-color", 0, 0, 's'},
769 {"network-code", 1, 0, 'n'},
770 {"country-code", 1, 0, 'c'},
Holger Freytherbde36102008-12-28 22:51:39 +0000771 {"database", 1, 0, 'l'},
Holger Freyther89824fc2008-12-30 16:18:18 +0000772 {"authorize-everyone", 0, 0, 'a'},
Holger Freythere97f7fb2008-12-31 18:52:11 +0000773 {"reject-cause", 1, 0, 'r'},
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000774 {"pcap", 1, 0, 'p'},
Harald Welte98981882009-01-06 18:59:11 +0000775 {"arfcn", 1, 0, 'f'},
Holger Freytherb332f612008-12-27 12:46:51 +0000776 {0, 0, 0, 0}
777 };
778
Harald Welte98981882009-01-06 18:59:11 +0000779 c = getopt_long(argc, argv, "hc:n:d:sar:p:f:",
Holger Freytherb332f612008-12-27 12:46:51 +0000780 long_options, &option_index);
781 if (c == -1)
782 break;
783
784 switch (c) {
785 case 'h':
786 print_usage();
787 print_help();
788 exit(0);
Holger Freytherefde7fb2008-12-28 14:14:56 +0000789 case 's':
Holger Freytherb332f612008-12-27 12:46:51 +0000790 debug_use_color(0);
791 break;
792 case 'd':
793 debug_parse_category_mask(optarg);
794 break;
Holger Freytherefde7fb2008-12-28 14:14:56 +0000795 case 'n':
796 MNC = atoi(optarg);
797 break;
798 case 'c':
799 MCC = atoi(optarg);
800 break;
Harald Welte98981882009-01-06 18:59:11 +0000801 case 'f':
802 ARFCN = atoi(optarg);
803 break;
Harald Welte8965da42009-01-06 18:09:02 +0000804 case 'l':
Holger Freytherbde36102008-12-28 22:51:39 +0000805 database_name = strdup(optarg);
806 break;
Holger Freyther89824fc2008-12-30 16:18:18 +0000807 case 'a':
808 gsm0408_allow_everyone(1);
809 break;
Holger Freythere97f7fb2008-12-31 18:52:11 +0000810 case 'r':
811 gsm0408_set_reject_cause(atoi(optarg));
812 break;
Holger Freyther9a3ee0f2009-01-02 00:40:15 +0000813 case 'p':
814 create_pcap_file(optarg);
815 break;
Holger Freytherb332f612008-12-27 12:46:51 +0000816 default:
817 /* ignore */
818 break;
819 }
820 }
821}
822
Harald Welted1252502009-01-01 01:50:32 +0000823static void signal_handler(int signal)
824{
825 fprintf(stdout, "signal %u received\n", signal);
826
827 switch (signal) {
828 case SIGHUP:
829 case SIGABRT:
830 shutdown_net(gsmnet);
831 break;
832 default:
833 break;
834 }
835}
836
Harald Weltef6b7a902008-12-26 00:05:11 +0000837int main(int argc, char **argv)
838{
Harald Welte1fa60c82009-02-09 18:13:26 +0000839 int rc;
840
Holger Freytherb332f612008-12-27 12:46:51 +0000841 /* parse options */
842 handle_options(argc, argv);
843
Holger Freytherbde36102008-12-28 22:51:39 +0000844 if (db_init(database_name)) {
Harald Welte75a983f2008-12-27 21:34:06 +0000845 printf("DB: Failed to init database. Please check the option settings.\n");
846 return 1;
847 }
848 printf("DB: Database initialized.\n");
849
850 if (db_prepare()) {
851 printf("DB: Failed to prepare database.\n");
852 return 1;
853 }
854 printf("DB: Database prepared.\n");
855
Harald Welte1fa60c82009-02-09 18:13:26 +0000856 rc = bootstrap_network();
857 if (rc < 0)
858 exit(1);
Harald Weltef6b7a902008-12-26 00:05:11 +0000859
Harald Welted1252502009-01-01 01:50:32 +0000860 signal(SIGHUP, &signal_handler);
861 signal(SIGABRT, &signal_handler);
862
Harald Weltef6b7a902008-12-26 00:05:11 +0000863 while (1) {
864 bsc_select_main();
865 }
866}