blob: b0d726573ff35925f6339f10ec795c1c7b8ed27a [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>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
Harald Weltef6b7a902008-12-26 00:05:11 +000022#include <unistd.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <stdarg.h>
26#include <time.h>
27#include <string.h>
Harald Weltead384642008-12-26 10:20:07 +000028#include <errno.h>
Harald Welte52b1f982008-12-23 20:25:15 +000029
Harald Welte8470bf22008-12-25 23:28:35 +000030#include <openbsc/gsm_data.h>
Harald Weltead384642008-12-26 10:20:07 +000031#include <openbsc/select.h>
Harald Welte8470bf22008-12-25 23:28:35 +000032#include <openbsc/abis_rsl.h>
33#include <openbsc/abis_nm.h>
Harald Welte52b1f982008-12-23 20:25:15 +000034
35/* global pointer to the gsm network data structure */
36static struct gsm_network *gsmnet;
37
38/* The following definitions are for OM and NM packets that we cannot yet
39 * generate by code but we just pass on */
40
41// BTS Site Manager, SET ATTRIBUTES
42
43/*
44 Object Class: BTS Site Manager
45 Instance 1: FF
46 Instance 2: FF
47 Instance 3: FF
48SET ATTRIBUTES
49 sAbisExternalTime: 2007/09/08 14:36:11
50 omLAPDRelTimer: 30sec
51 shortLAPDIntTimer: 5sec
52 emergencyTimer1: 10 minutes
53 emergencyTimer2: 0 minutes
54*/
55
56unsigned char msg_1[] =
57{
58 0xD0, 0x00, 0xFF, 0xFF, 0xFF, 0x91, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24,
59 0x0B, 0xCE, 0x02, 0x00, 0x1E, 0xE8, 0x01, 0x05, 0x42, 0x02, 0x00, 0x0A, 0x44,
60 0x02, 0x00, 0x00
61};
62
63// BTS, SET BTS ATTRIBUTES
64
65/*
66 Object Class: BTS
67 BTS relat. Number: 0
68 Instance 2: FF
69 Instance 3: FF
70SET BTS ATTRIBUTES
71 bsIdentityCode / BSIC:
72 PLMN_colour_code: 7h
73 BS_colour_code: 7h
74 BTS Air Timer T3105: 4 ,unit 10 ms
75 btsIsHopping: FALSE
76 periodCCCHLoadIndication: 255sec
77 thresholdCCCHLoadIndication: 100%
78 cellAllocationNumber: 00h = GSM 900
79 enableInterferenceClass: 00h = Disabled
80 fACCHQual: 6 (FACCH stealing flags minus 1)
81 intaveParameter: 31 SACCH multiframes
82 interferenceLevelBoundaries:
83 Interference Boundary 1: 0Ah
84 Interference Boundary 2: 0Fh
85 Interference Boundary 3: 14h
86 Interference Boundary 4: 19h
87 Interference Boundary 5: 1Eh
88 mSTxPwrMax: 11
89 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
90 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
91 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
92 30=33dBm, 31=32dBm
93 ny1:
94 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
95 powerOutputThresholds:
96 Out Power Fault Threshold: -10 dB
97 Red Out Power Threshold: - 6 dB
98 Excessive Out Power Threshold: 5 dB
99 rACHBusyThreshold: -127 dBm
100 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
101 rfResourceIndicationPeriod: 125 SACCH multiframes
102 T200:
103 SDCCH: 044 in 5 ms
104 FACCH/Full rate: 031 in 5 ms
105 FACCH/Half rate: 041 in 5 ms
106 SACCH with TCH SAPI0: 090 in 10 ms
107 SACCH with SDCCH: 090 in 10 ms
108 SDCCH with SAPI3: 090 in 5 ms
109 SACCH with TCH SAPI3: 135 in 10 ms
110 tSync: 9000 units of 10 msec
111 tTrau: 9000 units of 10 msec
112 enableUmLoopTest: 00h = disabled
113 enableExcessiveDistance: 00h = Disabled
114 excessiveDistance: 64km
115 hoppingMode: 00h = baseband hopping
116 cellType: 00h = Standard Cell
117 BCCH ARFCN / bCCHFrequency: 1
118*/
119
120unsigned char msg_2[] =
121{
122 0x41, 0x01, 0x00, 0xFF, 0xFF, 0x09, 0x3F, 0x0A, 0x04, 0x61, 0x00, 0x0B,
123 0xFF, 0x0C, 0x64, 0x62, 0x00, 0x66, 0x00, 0x6E, 0x06, 0x18, 0x1F, 0x19,
124 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B, 0x0B, 0x23, 0x14, 0x28, 0x00, 0x04,
125 0x03, 0x2A, 0x7F, 0x2B, 0x00, 0xFA, 0x8F, 0x7D, 0x33, 0x2C, 0x1F, 0x29,
126 0x5A, 0x5A, 0x5A, 0x87, 0x94, 0x23, 0x28, 0x95, 0x23, 0x28, 0x35, 0x01,
127 0x00, 0x46, 0x01, 0x00, 0x58, 0x01, 0x40, 0xC5, 0x01, 0x00, 0xF2, 0x01,
128 0x00, 0x08, 0x00, HARDCODED_ARFCN/*0x01*/,
129};
130
131// Handover Recognition, SET ATTRIBUTES
132
133/*
134Illegal Contents GSM Formatted O&M Msg
135 Object Class: Handover Recognition
136 BTS relat. Number: 0
137 Instance 2: FF
138 Instance 3: FF
139SET ATTRIBUTES
140 enableDelayPowerBudgetHO: 00h = Disabled
141 enableDistanceHO: 00h = Disabled
142 enableInternalInterCellHandover: 00h = Disabled
143 enableInternalIntraCellHandover: 00h = Disabled
144 enablePowerBudgetHO: 00h = Disabled
145 enableRXLEVHO: 00h = Disabled
146 enableRXQUALHO: 00h = Disabled
147 hoAveragingDistance: 8 SACCH multiframes
148 hoAveragingLev:
149 A_LEV_HO: 8 SACCH multiframes
150 W_LEV_HO: 1 SACCH multiframes
151 hoAveragingPowerBudget: 16 SACCH multiframes
152 hoAveragingQual:
153 A_QUAL_HO: 8 SACCH multiframes
154 W_QUAL_HO: 2 SACCH multiframes
155 hoLowerThresholdLevDL: (10 - 110) dBm
156 hoLowerThresholdLevUL: (5 - 110) dBm
157 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
158 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
159 hoThresholdLevDLintra : (20 - 110) dBm
160 hoThresholdLevULintra: (20 - 110) dBm
161 hoThresholdMsRangeMax: 20 km
162 nCell: 06h
163 timerHORequest: 3 ,unit 2 SACCH multiframes
164*/
165
166unsigned char msg_3[] =
167{
168 0xD0, 0xA1, 0x00, 0xFF, 0xFF, 0xD0, 0x00, 0x64, 0x00, 0x67, 0x00, 0x68,
169 0x00, 0x6A, 0x00, 0x6C, 0x00, 0x6D, 0x00, 0x6F, 0x08, 0x70, 0x08, 0x01,
170 0x71, 0x10, 0x10, 0x10, 0x72, 0x08, 0x02, 0x73, 0x0A, 0x74, 0x05, 0x75,
171 0x06, 0x76, 0x06, 0x78, 0x14, 0x79, 0x14, 0x7A, 0x14, 0x7D, 0x06, 0x92,
172 0x03, 0x20, 0x01, 0x00, 0x45, 0x01, 0x00, 0x48, 0x01, 0x00, 0x5A, 0x01,
173 0x00, 0x5B, 0x01, 0x05, 0x5E, 0x01, 0x1A, 0x5F, 0x01, 0x20, 0x9D, 0x01,
174 0x00, 0x47, 0x01, 0x00, 0x5C, 0x01, 0x64, 0x5D, 0x01, 0x1E, 0x97, 0x01,
175 0x20, 0xF7, 0x01, 0x3C,
176};
177
178// Power Control, SET ATTRIBUTES
179
180/*
181 Object Class: Power Control
182 BTS relat. Number: 0
183 Instance 2: FF
184 Instance 3: FF
185SET ATTRIBUTES
186 enableMsPowerControl: 00h = Disabled
187 enablePowerControlRLFW: 00h = Disabled
188 pcAveragingLev:
189 A_LEV_PC: 4 SACCH multiframes
190 W_LEV_PC: 1 SACCH multiframes
191 pcAveragingQual:
192 A_QUAL_PC: 4 SACCH multiframes
193 W_QUAL_PC: 2 SACCH multiframes
194 pcLowerThresholdLevDL: 0Fh
195 pcLowerThresholdLevUL: 0Ah
196 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
197 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
198 pcRLFThreshold: 0Ch
199 pcUpperThresholdLevDL: 14h
200 pcUpperThresholdLevUL: 0Fh
201 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
202 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
203 powerConfirm: 2 ,unit 2 SACCH multiframes
204 powerControlInterval: 2 ,unit 2 SACCH multiframes
205 powerIncrStepSize: 02h = 4 dB
206 powerRedStepSize: 01h = 2 dB
207 radioLinkTimeoutBs: 64 SACCH multiframes
208 enableBSPowerControl: 00h = disabled
209*/
210
211unsigned char msg_4[] =
212{
213 0xD0, 0xA2, 0x00, 0xFF, 0xFF, 0x69, 0x00, 0x6B, 0x00, 0x7E, 0x04, 0x01,
214 0x7F, 0x04, 0x02, 0x80, 0x0F, 0x81, 0x0A, 0x82, 0x05, 0x83, 0x05, 0x84,
215 0x0C, 0x85, 0x14, 0x86, 0x0F, 0x87, 0x04, 0x88, 0x04, 0x89, 0x02, 0x8A,
216 0x02, 0x8B, 0x02, 0x8C, 0x01, 0x8D, 0x40, 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
217};
218
219
220// Transceiver, SET TRX ATTRIBUTES (TRX 0)
221
222/*
223 Object Class: Transceiver
224 BTS relat. Number: 0
225 Tranceiver number: 0
226 Instance 3: FF
227SET TRX ATTRIBUTES
228 aRFCNList (HEX): 0001
229 txPwrMaxReduction: 00h = 0dB
230 radioMeasGran: 254 SACCH multiframes
231 radioMeasRep: 01h = enabled
232 memberOfEmergencyConfig: 01h = TRUE
233 trxArea: 00h = TRX doesn't belong to a concentric cell
234*/
235
236unsigned char msg_6[] =
237{
238 0x44, 0x02, 0x00, 0x00, 0xFF, 0x05, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/, 0x2D,
239 0x00, 0xDC, 0x01, 0xFE, 0xDD, 0x01, 0x01, 0x9B, 0x01, 0x01, 0x9F, 0x01, 0x00,
240};
241
242
243static void bootstrap_om(struct gsm_bts *bts)
244{
245 struct gsm_bts_trx *trx = &bts->trx[0];
246
Harald Weltead384642008-12-26 10:20:07 +0000247 fprintf(stdout, "bootstrapping OML\n");
248
Harald Welte52b1f982008-12-23 20:25:15 +0000249 /* stop sending event reports */
250 abis_nm_event_reports(bts, 0);
251
252 /* begin DB transmission */
253 abis_nm_db_transmission(bts, 1);
254
255 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
256 abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */
257 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
258 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
259
260 /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */
261 abis_nm_conn_terr_sign(trx, 0, 1, 0xff);
262 abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */
263
264 /* Use TEI 1 for signalling */
265 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01);
266 abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH);
267#if 0
268 /* TRX 1 */
269 abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff);
270 /* FIXME: TRX ATTRIBUTE */
271 abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02);
272#endif
273
274 /* SET CHANNEL ATTRIBUTE TS1 */
275 abis_nm_set_channel_attr(&trx->ts[1], 0x09);
276 /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */
277 abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1);
278
279 /* SET CHANNEL ATTRIBUTE TS2 */
280 abis_nm_set_channel_attr(&trx->ts[2], 0x09);
281 /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */
282 abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2);
283
284 /* SET CHANNEL ATTRIBUTE TS3 */
285 abis_nm_set_channel_attr(&trx->ts[3], 0x09);
286 /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */
287 abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3);
288
289 /* SET CHANNEL ATTRIBUTE TS4 */
290 abis_nm_set_channel_attr(&trx->ts[4], 0x09);
291 /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */
292 abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0);
293
294 /* SET CHANNEL ATTRIBUTE TS5 */
295 abis_nm_set_channel_attr(&trx->ts[5], 0x09);
296 /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */
297 abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1);
298
299 /* SET CHANNEL ATTRIBUTE TS6 */
300 abis_nm_set_channel_attr(&trx->ts[6], 0x09);
301 /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */
302 abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2);
303
304 /* SET CHANNEL ATTRIBUTE TS7 */
305 abis_nm_set_channel_attr(&trx->ts[7], 0x09);
306 /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */
307 abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3);
308
309 /* end DB transmission */
310 abis_nm_db_transmission(bts, 0);
311
312 /* Reset BTS Site manager resource */
313 abis_nm_reset_resource(bts);
314
315 /* restart sending event reports */
316 abis_nm_event_reports(bts, 1);
317}
318
319
320
321struct bcch_info {
322 u_int8_t type;
323 u_int8_t len;
324 const u_int8_t *data;
325};
326
327/*
328SYSTEM INFORMATION TYPE 1
329 Cell channel description
330 Format-ID bit map 0
331 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
332 RACH Control Parameters
333 maximum 7 retransmissions
334 8 slots used to spread transmission
335 cell not barred for access
336 call reestablishment not allowed
337 Access Control Class = 0000
338*/
339static const u_int8_t si1[] = {
340 0x55, 0x06, 0x19, 0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,0xD5,
342 0x00, 0x00, 0x2B
343};
344
345/*
346 SYSTEM INFORMATION TYPE 2
347 Neighbour Cells Description
348 EXT-IND: Carries the complete BA
349 BA-IND = 0
350 Format-ID bit map 0
351 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
352 NCC permitted (NCC) = FF
353 RACH Control Parameters
354 maximum 7 retransmissions
355 8 slots used to spread transmission
356 cell not barred for access
357 call reestablishment not allowed
358 Access Control Class = 0000
359*/
360static const u_int8_t si2[] = {
361 0x59, 0x06, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xD5, 0x00,
363 0x00
364};
365
366/*
367SYSTEM INFORMATION TYPE 3
368 Cell identity = 00001 (1h)
369 Location area identification
370 Mobile Country Code (MCC): 001
371 Mobile Network Code (MNC): 01
372 Location Area Code (LAC): 00001 (1h)
373 Control Channel Description
374 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
375 0 blocks reserved for access grant
376 1 channel used for CCCH, with SDCCH
377 5 multiframes period for PAGING REQUEST
378 Time-out T3212 = 0
379 Cell Options BCCH
380 Power control indicator: not set
381 MSs shall not use uplink DTX
382 Radio link timeout = 36
383 Cell Selection Parameters
384 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
385 max.TX power level MS may use for CCH = 2
386 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
387 Half rate support (NECI): New establishment causes are not supported
388 min.RX signal level for MS = 0
389 RACH Control Parameters
390 maximum 7 retransmissions
391 8 slots used to spread transmission
392 cell not barred for access
393 call reestablishment not allowed
394 Access Control Class = 0000
395 SI 3 Rest Octets
396 Cell Bar Qualify (CBQ): 0
397 Cell Reselect Offset = 0 dB
398 Temporary Offset = 0 dB
399 Penalty Time = 20 s
400 System Information 2ter Indicator (2TI): 0 = not available
401 Early Classmark Sending Control (ECSC): 0 = forbidden
402 Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
403*/
404unsigned char si3[] = {
405 0x49, 0x06, 0x1B, 0x00, 0x01, 0x00, 0xF1, 0x10, 0x00, 0x01,
406 0x01, 0x03, 0x00, 0x28, 0x62, 0x00, 0xD5, 0x00, 0x00, 0x80,
407 0x00, 0x00, 0x2B
408};
409
410/*
411SYSTEM INFORMATION TYPE 4
412 Location area identification
413 Mobile Country Code (MCC): 001
414 Mobile Network Code (MNC): 01
415 Location Area Code (LAC): 00001 (1h)
416 Cell Selection Parameters
417 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
418 max.TX power level MS may use for CCH = 2
419 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
420 Half rate support (NECI): New establishment causes are not supported
421 min.RX signal level for MS = 0
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 Channel Description
429 Type = SDCCH/4[2]
430 Timeslot Number: 0
431 Training Sequence Code: 7h
432 ARFCN: 1
433 SI Rest Octets
434 Cell Bar Qualify (CBQ): 0
435 Cell Reselect Offset = 0 dB
436 Temporary Offset = 0 dB
437 Penalty Time = 20 s
438*/
439static const u_int8_t si4[] = {
440 0x41, 0x06, 0x1C, 0x00, 0xF1, 0x10, 0x00, 0x01, 0x62, 0x00,
441 0xD5, 0x00, 0x00, 0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00,
442 0x2B, 0x2B, 0x2B
443};
444
445/*
446 SYSTEM INFORMATION TYPE 5
447 Neighbour Cells Description
448 EXT-IND: Carries the complete BA
449 BA-IND = 0
450 Format-ID bit map 0
451 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
452*/
453
454static const u_int8_t si5[] = {
455 0x06, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
456 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
457};
458
459// SYSTEM INFORMATION TYPE 6
460
461/*
462SACCH FILLING
463 System Info Type: SYSTEM INFORMATION 6
464 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
465
466SYSTEM INFORMATION TYPE 6
467 Cell identity = 00001 (1h)
468 Location area identification
469 Mobile Country Code (MCC): 001
470 Mobile Network Code (MNC): 01
471 Location Area Code (LAC): 00001 (1h)
472 Cell Options SACCH
473 Power control indicator: not set
474 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
475 Radio link timeout = 36
476 NCC permitted (NCC) = FF
477*/
478
479static const u_int8_t si6[] = {
480 0x06, 0x1E, 0x00, 0x01, 0x00, 0xF1, 0x10, 0x00, 0x01, 0x28, 0xFF,
481};
482
483
484
485static const struct bcch_info bcch_infos[] = {
486 {
487 .type = RSL_SYSTEM_INFO_1,
488 .len = sizeof(si1),
489 .data = si1,
490 }, {
491 .type = RSL_SYSTEM_INFO_2,
492 .len = sizeof(si2),
493 .data = si2,
494 }, {
495 .type = RSL_SYSTEM_INFO_3,
496 .len = sizeof(si3),
497 .data = si3,
498 }, {
499 .type = RSL_SYSTEM_INFO_4,
500 .len = sizeof(si4),
501 .data = si4,
502 },
503};
504
505/* set all system information types */
506static int set_system_infos(struct gsm_bts *bts)
507{
508 int i;
509
510 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
511 rsl_bcch_info(bts, bcch_infos[i].type,
512 bcch_infos[i].data,
513 bcch_infos[i].len);
514 }
515 rsl_sacch_filling(bts, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
516 rsl_sacch_filling(bts, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
Harald Weltead384642008-12-26 10:20:07 +0000517
518 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000519}
520
521static void activate_traffic_channels(struct gsm_bts_trx *trx)
522{
523 int i;
524
525 /* channel 0 is CCCH */
526 for (i = 1; i < 8; i++)
527 rsl_chan_activate_tch_f(&trx->ts[i]);
528}
529
Harald Weltead384642008-12-26 10:20:07 +0000530static void bootstrap_rsl(struct gsm_bts *bts)
Harald Welte52b1f982008-12-23 20:25:15 +0000531{
Harald Weltead384642008-12-26 10:20:07 +0000532 fprintf(stdout, "bootstrapping RSL\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000533 set_system_infos(bts);
534
535 /* FIXME: defer this until the channels are used */
536 activate_traffic_channels(&bts->trx[0]);
537}
538
Harald Weltead384642008-12-26 10:20:07 +0000539static void mi_cb(int event, struct gsm_bts *bts)
540{
541 switch (event) {
542 case EVT_E1_OML_UP:
543 bootstrap_om(bts);
544 break;
545 case EVT_E1_RSL_UP:
546 bootstrap_rsl(bts);
547 break;
548 default:
549 /* FIXME: deal with TEI or L1 link loss */
550 break;
551 }
552}
553
554static int bootstrap_network(void)
Harald Welte52b1f982008-12-23 20:25:15 +0000555{
556 struct gsm_bts *bts;
557
558 /* initialize our data structures */
559 gsmnet = gsm_network_init(1, 1, 1);
Harald Weltead384642008-12-26 10:20:07 +0000560 if (!gsmnet)
561 return -ENOMEM;
562
Harald Welte52b1f982008-12-23 20:25:15 +0000563 bts = &gsmnet->bts[0];
564 bts->location_area_code = 1;
565 bts->trx[0].arfcn = HARDCODED_ARFCN;
566
Harald Weltead384642008-12-26 10:20:07 +0000567 if (mi_setup(bts, 0, mi_cb) < 0)
568 return -EIO;
569
570 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000571}
Harald Weltef6b7a902008-12-26 00:05:11 +0000572
573void debugp(int subsys, char *file, int line, const char *format, ...)
574{
575 char *timestr;
576 va_list ap;
577 time_t tm;
578 FILE *outfd = stderr;
579
580 va_start(ap, format);
581
582 tm = time(NULL);
583 timestr = ctime(&tm);
584 timestr[strlen(timestr)-1] = '\0';
585 fprintf(outfd, "%s <%4.4x> %s:%d ", timestr, subsys, file, line);
Harald Weltead384642008-12-26 10:20:07 +0000586 vfprintf(outfd, format, ap);
587
Harald Weltef6b7a902008-12-26 00:05:11 +0000588 va_end(ap);
Harald Weltead384642008-12-26 10:20:07 +0000589
Harald Weltef6b7a902008-12-26 00:05:11 +0000590 fflush(outfd);
591}
592
593int main(int argc, char **argv)
594{
Harald Weltef6b7a902008-12-26 00:05:11 +0000595 bootstrap_network();
596
597 while (1) {
598 bsc_select_main();
599 }
600}