blob: 3e68d780803c8697d124f146e1d74c748cdd5ea5 [file] [log] [blame]
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +02001/* A hackish minimal BSC (+MSC +HLR) implementation */
2
3/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * 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
23#include <openbsc/gsm_data.h>
24#include <openbsc/gsm_utils.h>
25#include <openbsc/gsm_04_08.h>
26#include <openbsc/abis_rsl.h>
27#include <openbsc/abis_nm.h>
28#include <openbsc/debug.h>
29#include <openbsc/misdn.h>
30#include <openbsc/telnet_interface.h>
31#include <openbsc/paging.h>
32#include <openbsc/signal.h>
33#include <openbsc/talloc.h>
34
35/* global pointer to the gsm network data structure */
36extern struct gsm_network *bsc_gsmnet;
37extern int ipacc_rtp_direct;
38
39static void patch_nm_tables(struct gsm_bts *bts);
40static void patch_si_tables(struct gsm_bts *bts);
41
42/* The following definitions are for OM and NM packets that we cannot yet
43 * generate by code but we just pass on */
44
45// BTS Site Manager, SET ATTRIBUTES
46
47/*
48 Object Class: BTS Site Manager
49 Instance 1: FF
50 Instance 2: FF
51 Instance 3: FF
52SET ATTRIBUTES
53 sAbisExternalTime: 2007/09/08 14:36:11
54 omLAPDRelTimer: 30sec
55 shortLAPDIntTimer: 5sec
56 emergencyTimer1: 10 minutes
57 emergencyTimer2: 0 minutes
58*/
59
60unsigned char msg_1[] =
61{
62 NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, 0xFF, 0xFF, 0xFF,
63 NM_ATT_BS11_ABIS_EXT_TIME, 0x07,
64 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE,
65 0x02,
66 0x00, 0x1E,
67 NM_ATT_BS11_SH_LAPD_INT_TIMER,
68 0x01, 0x05,
69 0x42, 0x02, 0x00, 0x0A,
70 0x44, 0x02, 0x00, 0x00
71};
72
73// BTS, SET BTS ATTRIBUTES
74
75/*
76 Object Class: BTS
77 BTS relat. Number: 0
78 Instance 2: FF
79 Instance 3: FF
80SET BTS ATTRIBUTES
81 bsIdentityCode / BSIC:
82 PLMN_colour_code: 7h
83 BS_colour_code: 7h
84 BTS Air Timer T3105: 4 ,unit 10 ms
85 btsIsHopping: FALSE
86 periodCCCHLoadIndication: 1sec
87 thresholdCCCHLoadIndication: 0%
88 cellAllocationNumber: 00h = GSM 900
89 enableInterferenceClass: 00h = Disabled
90 fACCHQual: 6 (FACCH stealing flags minus 1)
91 intaveParameter: 31 SACCH multiframes
92 interferenceLevelBoundaries:
93 Interference Boundary 1: 0Ah
94 Interference Boundary 2: 0Fh
95 Interference Boundary 3: 14h
96 Interference Boundary 4: 19h
97 Interference Boundary 5: 1Eh
98 mSTxPwrMax: 11
99 GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm
100 DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
101 PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm
102 30=33dBm, 31=32dBm
103 ny1:
104 Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20
105 powerOutputThresholds:
106 Out Power Fault Threshold: -10 dB
107 Red Out Power Threshold: - 6 dB
108 Excessive Out Power Threshold: 5 dB
109 rACHBusyThreshold: -127 dBm
110 rACHLoadAveragingSlots: 250 ,number of RACH burst periods
111 rfResourceIndicationPeriod: 125 SACCH multiframes
112 T200:
113 SDCCH: 044 in 5 ms
114 FACCH/Full rate: 031 in 5 ms
115 FACCH/Half rate: 041 in 5 ms
116 SACCH with TCH SAPI0: 090 in 10 ms
117 SACCH with SDCCH: 090 in 10 ms
118 SDCCH with SAPI3: 090 in 5 ms
119 SACCH with TCH SAPI3: 135 in 10 ms
120 tSync: 9000 units of 10 msec
121 tTrau: 9000 units of 10 msec
122 enableUmLoopTest: 00h = disabled
123 enableExcessiveDistance: 00h = Disabled
124 excessiveDistance: 64km
125 hoppingMode: 00h = baseband hopping
126 cellType: 00h = Standard Cell
127 BCCH ARFCN / bCCHFrequency: 1
128*/
129
130static unsigned char bs11_attr_bts[] =
131{
132 NM_ATT_BSIC, HARDCODED_BSIC,
133 NM_ATT_BTS_AIR_TIMER, 0x04,
134 NM_ATT_BS11_BTSLS_HOPPING, 0x00,
135 NM_ATT_CCCH_L_I_P, 0x01,
136 NM_ATT_CCCH_L_T, 0x00,
137 NM_ATT_BS11_CELL_ALLOC_NR, NM_BS11_CANR_GSM,
138 NM_ATT_BS11_ENA_INTERF_CLASS, 0x01,
139 NM_ATT_BS11_FACCH_QUAL, 0x06,
140 /* interference avg. period in numbers of SACCH multifr */
141 NM_ATT_INTAVE_PARAM, 0x1F,
142 NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B,
143 NM_ATT_CCCH_L_T, 0x23,
144 NM_ATT_GSM_TIME, 0x28, 0x00,
145 NM_ATT_ADM_STATE, 0x03,
146 NM_ATT_RACH_B_THRESH, 0x7F,
147 NM_ATT_LDAVG_SLOTS, 0x00, 0xFA,
148 NM_ATT_BS11_RF_RES_IND_PER, 0x7D,
149 NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87,
150 NM_ATT_BS11_TSYNC, 0x23, 0x28,
151 NM_ATT_BS11_TTRAU, 0x23, 0x28,
152 NM_ATT_TEST_DUR, 0x01, 0x00,
153 NM_ATT_OUTST_ALARM, 0x01, 0x00,
154 NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40,
155 NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00,
156 NM_ATT_BS11_PLL, 0x01, 0x00,
157 NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/,
158};
159
160// Handover Recognition, SET ATTRIBUTES
161
162/*
163Illegal Contents GSM Formatted O&M Msg
164 Object Class: Handover Recognition
165 BTS relat. Number: 0
166 Instance 2: FF
167 Instance 3: FF
168SET ATTRIBUTES
169 enableDelayPowerBudgetHO: 00h = Disabled
170 enableDistanceHO: 00h = Disabled
171 enableInternalInterCellHandover: 00h = Disabled
172 enableInternalIntraCellHandover: 00h = Disabled
173 enablePowerBudgetHO: 00h = Disabled
174 enableRXLEVHO: 00h = Disabled
175 enableRXQUALHO: 00h = Disabled
176 hoAveragingDistance: 8 SACCH multiframes
177 hoAveragingLev:
178 A_LEV_HO: 8 SACCH multiframes
179 W_LEV_HO: 1 SACCH multiframes
180 hoAveragingPowerBudget: 16 SACCH multiframes
181 hoAveragingQual:
182 A_QUAL_HO: 8 SACCH multiframes
183 W_QUAL_HO: 2 SACCH multiframes
184 hoLowerThresholdLevDL: (10 - 110) dBm
185 hoLowerThresholdLevUL: (5 - 110) dBm
186 hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8%
187 hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8%
188 hoThresholdLevDLintra : (20 - 110) dBm
189 hoThresholdLevULintra: (20 - 110) dBm
190 hoThresholdMsRangeMax: 20 km
191 nCell: 06h
192 timerHORequest: 3 ,unit 2 SACCH multiframes
193*/
194
195unsigned char msg_3[] =
196{
197 NM_MT_BS11_SET_ATTR, NM_OC_BS11_HANDOVER, 0x00, 0xFF, 0xFF,
198 0xD0, 0x00, /* enableDelayPowerBudgetHO */
199 0x64, 0x00, /* enableDistanceHO */
200 0x67, 0x00, /* enableInternalInterCellHandover */
201 0x68, 0x00, /* enableInternalInterCellHandover */
202 0x6A, 0x00, /* enablePowerBudgetHO */
203 0x6C, 0x00, /* enableRXLEVHO */
204 0x6D, 0x00, /* enableRXQUALHO */
205 0x6F, 0x08, /* hoAveragingDistance */
206 0x70, 0x08, 0x01, /* hoAveragingLev */
207 0x71, 0x10, 0x10, 0x10,
208 0x72, 0x08, 0x02, /* hoAveragingQual */
209 0x73, 0x0A, /* hoLowerThresholdLevDL */
210 0x74, 0x05, /* hoLowerThresholdLevUL */
211 0x75, 0x06, /* hoLowerThresholdQualDL */
212 0x76, 0x06, /* hoLowerThresholdQualUL */
213 0x78, 0x14, /* hoThresholdLevDLintra */
214 0x79, 0x14, /* hoThresholdLevULintra */
215 0x7A, 0x14, /* hoThresholdMsRangeMax */
216 0x7D, 0x06, /* nCell */
217 NM_ATT_BS11_TIMER_HO_REQUEST, 0x03,
218 0x20, 0x01, 0x00,
219 0x45, 0x01, 0x00,
220 0x48, 0x01, 0x00,
221 0x5A, 0x01, 0x00,
222 0x5B, 0x01, 0x05,
223 0x5E, 0x01, 0x1A,
224 0x5F, 0x01, 0x20,
225 0x9D, 0x01, 0x00,
226 0x47, 0x01, 0x00,
227 0x5C, 0x01, 0x64,
228 0x5D, 0x01, 0x1E,
229 0x97, 0x01, 0x20,
230 0xF7, 0x01, 0x3C,
231};
232
233// Power Control, SET ATTRIBUTES
234
235/*
236 Object Class: Power Control
237 BTS relat. Number: 0
238 Instance 2: FF
239 Instance 3: FF
240SET ATTRIBUTES
241 enableMsPowerControl: 00h = Disabled
242 enablePowerControlRLFW: 00h = Disabled
243 pcAveragingLev:
244 A_LEV_PC: 4 SACCH multiframes
245 W_LEV_PC: 1 SACCH multiframes
246 pcAveragingQual:
247 A_QUAL_PC: 4 SACCH multiframes
248 W_QUAL_PC: 2 SACCH multiframes
249 pcLowerThresholdLevDL: 0Fh
250 pcLowerThresholdLevUL: 0Ah
251 pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4%
252 pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4%
253 pcRLFThreshold: 0Ch
254 pcUpperThresholdLevDL: 14h
255 pcUpperThresholdLevUL: 0Fh
256 pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2%
257 pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2%
258 powerConfirm: 2 ,unit 2 SACCH multiframes
259 powerControlInterval: 2 ,unit 2 SACCH multiframes
260 powerIncrStepSize: 02h = 4 dB
261 powerRedStepSize: 01h = 2 dB
262 radioLinkTimeoutBs: 64 SACCH multiframes
263 enableBSPowerControl: 00h = disabled
264*/
265
266unsigned char msg_4[] =
267{
268 NM_MT_BS11_SET_ATTR, NM_OC_BS11_PWR_CTRL, 0x00, 0xFF, 0xFF,
269 NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00,
270 NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00,
271 0x7E, 0x04, 0x01, /* pcAveragingLev */
272 0x7F, 0x04, 0x02, /* pcAveragingQual */
273 0x80, 0x0F, /* pcLowerThresholdLevDL */
274 0x81, 0x0A, /* pcLowerThresholdLevUL */
275 0x82, 0x05, /* pcLowerThresholdQualDL */
276 0x83, 0x05, /* pcLowerThresholdQualUL */
277 0x84, 0x0C, /* pcRLFThreshold */
278 0x85, 0x14, /* pcUpperThresholdLevDL */
279 0x86, 0x0F, /* pcUpperThresholdLevUL */
280 0x87, 0x04, /* pcUpperThresholdQualDL */
281 0x88, 0x04, /* pcUpperThresholdQualUL */
282 0x89, 0x02, /* powerConfirm */
283 0x8A, 0x02, /* powerConfirmInterval */
284 0x8B, 0x02, /* powerIncrStepSize */
285 0x8C, 0x01, /* powerRedStepSize */
286 0x8D, 0x40, /* radioLinkTimeoutBs */
287 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl
288};
289
290
291// Transceiver, SET TRX ATTRIBUTES (TRX 0)
292
293/*
294 Object Class: Transceiver
295 BTS relat. Number: 0
296 Tranceiver number: 0
297 Instance 3: FF
298SET TRX ATTRIBUTES
299 aRFCNList (HEX): 0001
300 txPwrMaxReduction: 00h = 30dB
301 radioMeasGran: 254 SACCH multiframes
302 radioMeasRep: 01h = enabled
303 memberOfEmergencyConfig: 01h = TRUE
304 trxArea: 00h = TRX doesn't belong to a concentric cell
305*/
306
307static unsigned char bs11_attr_radio[] =
308{
309 NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/,
310 NM_ATT_RF_MAXPOWR_R, 0x00,
311 NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0x05,
312 NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01,
313 NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01,
314 NM_ATT_BS11_TRX_AREA, 0x01, 0x00,
315};
316
317static unsigned char nanobts_attr_bts[] = {
318 NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73,
319 /* interference avg. period in numbers of SACCH multifr */
320 NM_ATT_INTAVE_PARAM, 0x06,
321 /* conn fail based on SACCH error rate */
322 NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10,
323 NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
324 NM_ATT_MAX_TA, 0x3f,
325 NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */
326 NM_ATT_CCCH_L_T, 10, /* percent */
327 NM_ATT_CCCH_L_I_P, 1, /* seconds */
328 NM_ATT_RACH_B_THRESH, 10, /* busy threshold in - dBm */
329 NM_ATT_LDAVG_SLOTS, 0x03, 0xe8, /* rach load averaging 1000 slots */
330 NM_ATT_BTS_AIR_TIMER, 128, /* miliseconds */
331 NM_ATT_NY1, 10, /* 10 retransmissions of physical config */
332 NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
333 NM_ATT_BSIC, HARDCODED_BSIC,
334};
335
336static unsigned char nanobts_attr_radio[] = {
337 NM_ATT_RF_MAXPOWR_R, 0x0c, /* number of -2dB reduction steps / Pn */
338 NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
339};
340
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200341/* Callback function to be called whenever we get a GSM 12.21 state change event */
342int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
343 struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
344{
345 struct gsm_bts *bts;
346 struct gsm_bts_trx *trx;
347 struct gsm_bts_trx_ts *ts;
348
Harald Welte8406ec22009-10-20 17:31:00 +0200349 /* This event-driven BTS setup is currently only required on nanoBTS */
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200350
Harald Welte8406ec22009-10-20 17:31:00 +0200351 /* EVT_STATECHG_ADM is called after we call chg_adm_state() and would create
352 * endless loop */
353 if (evt != EVT_STATECHG_OPER)
354 return 0;
355
356 switch (obj_class) {
357 case NM_OC_SITE_MANAGER:
358 bts = container_of(obj, struct gsm_bts, site_mgr);
359 if (new_state->operational == 2 &&
360 new_state->availability == NM_AVSTATE_OK)
361 abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff);
362 break;
363 case NM_OC_BTS:
364 bts = obj;
365 if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
366 patch_nm_tables(bts);
367 abis_nm_set_bts_attr(bts, nanobts_attr_bts,
368 sizeof(nanobts_attr_bts));
369 abis_nm_chg_adm_state(bts, obj_class,
370 bts->bts_nr, 0xff, 0xff,
371 NM_STATE_UNLOCKED);
372 abis_nm_opstart(bts, obj_class,
373 bts->bts_nr, 0xff, 0xff);
374 }
375 break;
376 case NM_OC_CHANNEL:
377 ts = obj;
378 trx = ts->trx;
379 if (new_state->operational == 1 &&
380 new_state->availability == NM_AVSTATE_DEPENDENCY) {
381 if (ts->nr == 0 && trx == trx->bts->c0)
382 abis_nm_set_channel_attr(ts, NM_CHANC_BCCHComb);
383 else
384 abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull);
385 abis_nm_chg_adm_state(trx->bts, obj_class,
386 trx->bts->bts_nr, trx->nr, ts->nr,
387 NM_STATE_UNLOCKED);
388 abis_nm_opstart(trx->bts, obj_class,
389 trx->bts->bts_nr, trx->nr, ts->nr);
390 }
391 break;
392 case NM_OC_RADIO_CARRIER:
393 trx = obj;
394 if (new_state->operational == 1 &&
395 new_state->availability == NM_AVSTATE_OFF_LINE) {
396 /* Patch ARFCN into radio attribute */
397 nanobts_attr_radio[5] &= 0xf0;
398 nanobts_attr_radio[5] |= trx->arfcn >> 8;
399 nanobts_attr_radio[6] = trx->arfcn & 0xff;
400 abis_nm_set_radio_attr(trx, nanobts_attr_radio,
401 sizeof(nanobts_attr_radio));
402 abis_nm_chg_adm_state(trx->bts, obj_class,
403 trx->bts->bts_nr, trx->nr, 0xff,
404 NM_STATE_UNLOCKED);
405 abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr,
406 trx->nr, 0xff);
407 }
408 if (new_state->operational == 1 &&
409 new_state->availability == NM_AVSTATE_OK)
410 abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr,
411 trx->nr, 0xff);
412 break;
413 case NM_OC_BASEB_TRANSC:
414 trx = container_of(obj, struct gsm_bts_trx, bb_transc);
415 if (new_state->operational == 1 &&
416 new_state->availability == NM_AVSTATE_DEPENDENCY) {
417 abis_nm_chg_adm_state(trx->bts, obj_class,
418 trx->bts->bts_nr, trx->nr, 0xff,
419 NM_STATE_UNLOCKED);
420 abis_nm_opstart(trx->bts, obj_class,
421 trx->bts->bts_nr, trx->nr, 0xff);
422 /* TRX software is active, tell it to initiate RSL Link */
423 abis_nm_ipaccess_rsl_connect(trx, 0, 3003, trx->rsl_tei);
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200424 }
425 break;
426 default:
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200427 break;
428 }
429 return 0;
430}
431
432/* Callback function to be called every time we receive a 12.21 SW activated report */
433static int sw_activ_rep(struct msgb *mb)
434{
435 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Harald Welted004a642009-10-19 21:47:54 +0200436 struct gsm_bts *bts = mb->trx->bts;
437 struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, foh->obj_inst.trx_nr);
438
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200439
440 switch (foh->obj_class) {
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200441 }
442 return 0;
443}
444
445/* Callback function for NACK on the OML NM */
446static int oml_msg_nack(int mt)
447{
448 if (mt == NM_MT_SET_BTS_ATTR_NACK) {
449 fprintf(stderr, "Failed to set BTS attributes. That is fatal. "
450 "Was the bts type and frequency properly specified?\n");
451 exit(-1);
452 }
453
454 return 0;
455}
456
457/* Callback function to be called every time we receive a signal from NM */
458static int nm_sig_cb(unsigned int subsys, unsigned int signal,
459 void *handler_data, void *signal_data)
460{
461 switch (signal) {
462 case S_NM_SW_ACTIV_REP:
463 return sw_activ_rep(signal_data);
464 case S_NM_NACK:
465 return oml_msg_nack((int)signal_data);
466 default:
467 break;
468 }
469 return 0;
470}
471
472static void bootstrap_om_nanobts(struct gsm_bts *bts)
473{
474 /* We don't do callback based bootstrapping, but event driven (see above) */
475}
476
477static void nm_reconfig_ts(struct gsm_bts_trx_ts *ts)
478{
479 enum abis_nm_chan_comb ccomb = abis_nm_chcomb4pchan(ts->pchan);
480 struct gsm_e1_subslot *e1l = &ts->e1_link;
481
482 abis_nm_set_channel_attr(ts, ccomb);
483
484 if (is_ipaccess_bts(ts->trx->bts))
485 return;
486
487 switch (ts->pchan) {
488 case GSM_PCHAN_TCH_F:
489 case GSM_PCHAN_TCH_H:
490 abis_nm_conn_terr_traf(ts, e1l->e1_nr, e1l->e1_ts,
491 e1l->e1_ts_ss);
492 break;
493 default:
494 break;
495 }
496}
497
498static void nm_reconfig_trx(struct gsm_bts_trx *trx)
499{
500 struct gsm_e1_subslot *e1l = &trx->rsl_e1_link;
501 int i;
502
503 patch_nm_tables(trx->bts);
504
505 switch (trx->bts->type) {
506 case GSM_BTS_TYPE_BS11:
507 /* FIXME: discover this by fetching an attribute */
508#if 0
509 trx->nominal_power = 15; /* 15dBm == 30mW PA configuration */
510#else
511 trx->nominal_power = 24; /* 24dBm == 250mW PA configuration */
512#endif
513 abis_nm_conn_terr_sign(trx, e1l->e1_nr, e1l->e1_ts,
514 e1l->e1_ts_ss);
515 abis_nm_establish_tei(trx->bts, trx->nr, e1l->e1_nr,
516 e1l->e1_ts, e1l->e1_ts_ss, trx->rsl_tei);
517
518 /* Set Radio Attributes */
519 if (trx == trx->bts->c0)
520 abis_nm_set_radio_attr(trx, bs11_attr_radio,
521 sizeof(bs11_attr_radio));
522 else {
523 u_int8_t trx1_attr_radio[sizeof(bs11_attr_radio)];
524 u_int8_t arfcn_low = trx->arfcn & 0xff;
525 u_int8_t arfcn_high = (trx->arfcn >> 8) & 0x0f;
526 memcpy(trx1_attr_radio, bs11_attr_radio,
527 sizeof(trx1_attr_radio));
528
529 /* patch ARFCN into TRX Attributes */
530 trx1_attr_radio[2] &= 0xf0;
531 trx1_attr_radio[2] |= arfcn_high;
532 trx1_attr_radio[3] = arfcn_low;
533
534 abis_nm_set_radio_attr(trx, trx1_attr_radio,
535 sizeof(trx1_attr_radio));
536 }
537 break;
Mike Habene2d82272009-10-02 12:19:34 +0100538 case GSM_BTS_TYPE_NANOBTS:
Harald Welteaf7b2fa2009-10-19 21:47:31 +0200539 switch (trx->bts->band) {
540 case GSM_BAND_850:
541 case GSM_BAND_900:
542 trx->nominal_power = 20;
543 break;
544 case GSM_BAND_1800:
545 case GSM_BAND_1900:
546 trx->nominal_power = 23;
547 break;
548 dedfault:
549 fprintf(stderr, "Unsupported nanoBTS GSM band %s\n",
550 gsm_band_name(trx->bts->band));
551 break;
552 }
553 break;
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200554 default:
555 break;
556 }
557
558 for (i = 0; i < TRX_NR_TS; i++)
559 nm_reconfig_ts(&trx->ts[i]);
560}
561
562static void nm_reconfig_bts(struct gsm_bts *bts)
563{
564 struct gsm_bts_trx *trx;
565
566 switch (bts->type) {
567 case GSM_BTS_TYPE_BS11:
568 abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/
569 abis_nm_set_bts_attr(bts, bs11_attr_bts, sizeof(bs11_attr_bts));
570 abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */
571 abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */
572 break;
573 default:
574 break;
575 }
576
577 llist_for_each_entry(trx, &bts->trx_list, list)
578 nm_reconfig_trx(trx);
579}
580
581static void bootstrap_om_bs11(struct gsm_bts *bts)
582{
583 /* stop sending event reports */
584 abis_nm_event_reports(bts, 0);
585
586 /* begin DB transmission */
587 abis_nm_bs11_db_transmission(bts, 1);
588
589 /* end DB transmission */
590 abis_nm_bs11_db_transmission(bts, 0);
591
592 /* Reset BTS Site manager resource */
593 abis_nm_bs11_reset_resource(bts);
594
595 /* begin DB transmission */
596 abis_nm_bs11_db_transmission(bts, 1);
597
598 /* reconfigure BTS with all TRX and all TS */
599 nm_reconfig_bts(bts);
600
601 /* end DB transmission */
602 abis_nm_bs11_db_transmission(bts, 0);
603
604 /* Reset BTS Site manager resource */
605 abis_nm_bs11_reset_resource(bts);
606
607 /* restart sending event reports */
608 abis_nm_event_reports(bts, 1);
609}
610
611static void bootstrap_om(struct gsm_bts *bts)
612{
613 fprintf(stdout, "bootstrapping OML for BTS %u\n", bts->nr);
614
615 switch (bts->type) {
616 case GSM_BTS_TYPE_BS11:
617 bootstrap_om_bs11(bts);
618 break;
Mike Habene2d82272009-10-02 12:19:34 +0100619 case GSM_BTS_TYPE_NANOBTS:
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200620 bootstrap_om_nanobts(bts);
621 break;
622 default:
623 fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type);
624 }
625}
626
627static int shutdown_om(struct gsm_bts *bts)
628{
629 fprintf(stdout, "shutting down OML for BTS %u\n", bts->nr);
630
631 /* stop sending event reports */
632 abis_nm_event_reports(bts, 0);
633
634 /* begin DB transmission */
635 abis_nm_bs11_db_transmission(bts, 1);
636
637 /* end DB transmission */
638 abis_nm_bs11_db_transmission(bts, 0);
639
640 /* Reset BTS Site manager resource */
641 abis_nm_bs11_reset_resource(bts);
642
643 return 0;
644}
645
646int bsc_shutdown_net(struct gsm_network *net)
647{
648 struct gsm_bts *bts;
649
650 llist_for_each_entry(bts, &net->bts_list, list) {
651 int rc;
652 rc = shutdown_om(bts);
653 if (rc < 0)
654 return rc;
655 }
656
657 return 0;
658}
659
660struct bcch_info {
661 u_int8_t type;
662 u_int8_t len;
663 const u_int8_t *data;
664};
665
666/*
667SYSTEM INFORMATION TYPE 1
668 Cell channel description
669 Format-ID bit map 0
670 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
671 RACH Control Parameters
672 maximum 7 retransmissions
673 8 slots used to spread transmission
674 cell not barred for access
675 call reestablishment not allowed
676 Access Control Class = 0000
677*/
678static u_int8_t si1[] = {
679 /* header */0x55, 0x06, 0x19,
680 /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
681 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,
682 /* rach */0xD5, 0x04, 0x00,
683 /* s1 reset*/0x2B
684};
685
686/*
687 SYSTEM INFORMATION TYPE 2
688 Neighbour Cells Description
689 EXT-IND: Carries the complete BA
690 BA-IND = 0
691 Format-ID bit map 0
692 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
693 NCC permitted (NCC) = FF
694 RACH Control Parameters
695 maximum 7 retransmissions
696 8 slots used to spread transmission
697 cell not barred for access
698 call reestablishment not allowed
699 Access Control Class = 0000
700*/
701static u_int8_t si2[] = {
702 /* header */0x59, 0x06, 0x1A,
703 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
704 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
705 /* ncc */0xFF,
706 /* rach*/0xD5, 0x04, 0x00
707};
708
709/*
710SYSTEM INFORMATION TYPE 3
711 Cell identity = 00001 (1h)
712 Location area identification
713 Mobile Country Code (MCC): 001
714 Mobile Network Code (MNC): 01
715 Location Area Code (LAC): 00001 (1h)
716 Control Channel Description
717 Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach
718 0 blocks reserved for access grant
719 1 channel used for CCCH, with SDCCH
720 5 multiframes period for PAGING REQUEST
721 Time-out T3212 = 0
722 Cell Options BCCH
723 Power control indicator: not set
724 MSs shall not use uplink DTX
725 Radio link timeout = 36
726 Cell Selection Parameters
727 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
728 max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max)
729 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
730 Half rate support (NECI): New establishment causes are not supported
731 min.RX signal level for MS = 0
732 RACH Control Parameters
733 maximum 7 retransmissions
734 8 slots used to spread transmission
735 cell not barred for access
736 call reestablishment not allowed
737 Access Control Class = 0000
738 SI 3 Rest Octets (not present)
739*/
740static u_int8_t si3[] = {
741 /* header */0x49, 0x06, 0x1B,
742 /* cell */0x00, 0x01,
743 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
744 /* desc */0x01, 0x03, 0x00,
745 /* option*/0x28,
746 /* selection*/0x62, 0x00,
747 /* rach */0xD5, 0x04, 0x00,
748 /* rest */ 0x2B, 0x2B, 0x2B, 0x2B
749};
750
751/*
752SYSTEM INFORMATION TYPE 4
753 Location area identification
754 Mobile Country Code (MCC): 001
755 Mobile Network Code (MNC): 01
756 Location Area Code (LAC): 00001 (1h)
757 Cell Selection Parameters
758 Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection
759 max.TX power level MS may use for CCH = 2
760 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
761 Half rate support (NECI): New establishment causes are not supported
762 min.RX signal level for MS = 0
763 RACH Control Parameters
764 maximum 7 retransmissions
765 8 slots used to spread transmission
766 cell not barred for access
767 call reestablishment not allowed
768 Access Control Class = 0000
769 CBCH Channel Description
770 Type = SDCCH/4[2]
771 Timeslot Number: 0
772 Training Sequence Code: 7h
773 ARFCN: 1
774 SI Rest Octets (not present)
775*/
776static u_int8_t si4[] = {
777 /* header */0x41, 0x06, 0x1C,
778 /* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
779 /* sel */0x62, 0x00,
780 /* rach*/0xD5, 0x04, 0x00,
781 /* cbch chan desc */ 0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/,
782 /* rest octets */ 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B
783};
784
785/*
786 SYSTEM INFORMATION TYPE 5
787 Neighbour Cells Description
788 EXT-IND: Carries the complete BA
789 BA-IND = 0
790 Format-ID bit map 0
791 CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
792*/
793
794static u_int8_t si5[] = {
795 /* header without l2 len*/0x06, 0x1D,
796 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
797 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
798};
799
800// SYSTEM INFORMATION TYPE 6
801
802/*
803SACCH FILLING
804 System Info Type: SYSTEM INFORMATION 6
805 L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF
806
807SYSTEM INFORMATION TYPE 6
808 Cell identity = 00001 (1h)
809 Location area identification
810 Mobile Country Code (MCC): 001
811 Mobile Network Code (MNC): 01
812 Location Area Code (LAC): 00001 (1h)
813 Cell Options SACCH
814 Power control indicator: not set
815 MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H.
816 Radio link timeout = 36
817 NCC permitted (NCC) = FF
818*/
819
820static u_int8_t si6[] = {
821 /* header */0x06, 0x1E,
822 /* cell id*/ 0x00, 0x01,
823 /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01,
824 /* options */ 0x28,
825 /* ncc */ 0xFF,
826};
827
828
829
830static const struct bcch_info bcch_infos[] = {
831 {
832 .type = RSL_SYSTEM_INFO_1,
833 .len = sizeof(si1),
834 .data = si1,
835 }, {
836 .type = RSL_SYSTEM_INFO_2,
837 .len = sizeof(si2),
838 .data = si2,
839 }, {
840 .type = RSL_SYSTEM_INFO_3,
841 .len = sizeof(si3),
842 .data = si3,
843 }, {
844 .type = RSL_SYSTEM_INFO_4,
845 .len = sizeof(si4),
846 .data = si4,
847 },
848};
849
850static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1)
851static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2)
852static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3)
853static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4)
854static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5)
855static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6)
856
857/* set all system information types */
858static int set_system_infos(struct gsm_bts_trx *trx)
859{
860 int i;
861
862 if (trx == trx->bts->c0) {
863 for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) {
864 rsl_bcch_info(trx, bcch_infos[i].type,
865 bcch_infos[i].data,
866 bcch_infos[i].len);
867 }
868 }
869 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5));
870 rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6));
871
872 return 0;
873}
874
875/*
876 * Patch the various SYSTEM INFORMATION tables to update
877 * the LAI
878 */
879static void patch_nm_tables(struct gsm_bts *bts)
880{
881 u_int8_t arfcn_low = bts->c0->arfcn & 0xff;
882 u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f;
883
884 /* patch ARFCN into BTS Attributes */
885 bs11_attr_bts[69] &= 0xf0;
886 bs11_attr_bts[69] |= arfcn_high;
887 bs11_attr_bts[70] = arfcn_low;
888 nanobts_attr_bts[42] &= 0xf0;
889 nanobts_attr_bts[42] |= arfcn_high;
890 nanobts_attr_bts[43] = arfcn_low;
891
892 /* patch ARFCN into TRX Attributes */
893 bs11_attr_radio[2] &= 0xf0;
894 bs11_attr_radio[2] |= arfcn_high;
895 bs11_attr_radio[3] = arfcn_low;
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200896
897 /* patch BSIC */
898 bs11_attr_bts[1] = bts->bsic;
899 nanobts_attr_bts[sizeof(nanobts_attr_bts)-1] = bts->bsic;
900
901 /* patch the power reduction */
902 bs11_attr_radio[5] = bts->c0->max_power_red / 2;
903 nanobts_attr_radio[1] = bts->c0->max_power_red / 2;
904}
905
906/*
907 * Patch the various SYSTEM INFORMATION tables to update
908 * the LAI
909 */
910static void patch_si_tables(struct gsm_bts *bts)
911{
912 u_int8_t arfcn_low = bts->c0->arfcn & 0xff;
913 u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f;
914
915 /* covert the raw packet to the struct */
916 struct gsm48_system_information_type_1 *type_1 =
917 (struct gsm48_system_information_type_1*)&si1;
918 struct gsm48_system_information_type_2 *type_2 =
919 (struct gsm48_system_information_type_2*)&si2;
920 struct gsm48_system_information_type_3 *type_3 =
921 (struct gsm48_system_information_type_3*)&si3;
922 struct gsm48_system_information_type_4 *type_4 =
923 (struct gsm48_system_information_type_4*)&si4;
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200924 struct gsm48_system_information_type_6 *type_6 =
925 (struct gsm48_system_information_type_6*)&si6;
926 struct gsm48_loc_area_id lai;
927
928 gsm0408_generate_lai(&lai, bts->network->country_code,
929 bts->network->network_code,
930 bts->location_area_code);
931
932 /* assign the MCC and MNC */
933 type_3->lai = lai;
934 type_4->lai = lai;
935 type_6->lai = lai;
936
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200937 /* set the CI */
938 type_3->cell_identity = htons(bts->cell_identity);
939 type_6->cell_identity = htons(bts->cell_identity);
940
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200941 type_4->data[2] &= 0xf0;
942 type_4->data[2] |= arfcn_high;
943 type_4->data[3] = arfcn_low;
944
945 /* patch Control Channel Description 10.5.2.11 */
946 type_3->control_channel_desc = bts->chan_desc;
947
948 /* patch TSC */
949 si4[15] &= ~0xe0;
950 si4[15] |= (bts->tsc & 7) << 5;
951
952 /* patch MS max power for CCH */
953 type_4->cell_sel_par.ms_txpwr_max_ccch =
954 ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
955
956 if (bts->cell_barred) {
957 type_1->rach_control.cell_bar = 1;
958 type_2->rach_control.cell_bar = 1;
959 type_3->rach_control.cell_bar = 1;
960 type_4->rach_control.cell_bar = 1;
961 } else {
962 type_1->rach_control.cell_bar = 0;
963 type_2->rach_control.cell_bar = 0;
964 type_3->rach_control.cell_bar = 0;
965 type_4->rach_control.cell_bar = 0;
966 }
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +0200967}
968
969
970static void bootstrap_rsl(struct gsm_bts_trx *trx)
971{
972 fprintf(stdout, "bootstrapping RSL for BTS/TRX (%u/%u) "
973 "using MCC=%u MNC=%u BSIC=%u TSC=%u\n",
974 trx->bts->nr, trx->nr, bsc_gsmnet->country_code,
975 bsc_gsmnet->network_code, trx->bts->bsic, trx->bts->tsc);
976 patch_si_tables(trx->bts);
977 set_system_infos(trx);
978}
979
980void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
981{
982 switch (event) {
983 case EVT_E1_TEI_UP:
984 switch (type) {
985 case E1INP_SIGN_OML:
986 bootstrap_om(trx->bts);
987 break;
988 case E1INP_SIGN_RSL:
989 bootstrap_rsl(trx);
990 break;
991 default:
992 break;
993 }
994 break;
995 case EVT_E1_TEI_DN:
996 fprintf(stderr, "Lost some E1 TEI link\n");
997 /* FIXME: deal with TEI or L1 link loss */
998 break;
999 default:
1000 break;
1001 }
1002}
1003
1004static int bootstrap_bts(struct gsm_bts *bts)
1005{
Mike Habene2d82272009-10-02 12:19:34 +01001006 switch (bts->band) {
1007 case GSM_BAND_1800:
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +02001008 if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) {
1009 fprintf(stderr, "GSM1800 channel must be between 512-885.\n");
1010 return -EINVAL;
1011 }
1012 break;
Mike Habene2d82272009-10-02 12:19:34 +01001013 case GSM_BAND_1900:
1014 if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) {
1015 fprintf(stderr, "GSM1900 channel must be between 512-810.\n");
1016 return -EINVAL;
1017 }
1018 break;
1019 case GSM_BAND_900:
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +02001020 if (bts->c0->arfcn < 1 || bts->c0->arfcn > 124) {
1021 fprintf(stderr, "GSM900 channel must be between 1-124.\n");
1022 return -EINVAL;
1023 }
1024 break;
Mike Habene2d82272009-10-02 12:19:34 +01001025 default:
1026 fprintf(stderr, "Unsupported frequency band.\n");
Holger Hans Peter Freyther8b457fb2009-08-17 06:55:10 +02001027 return -EINVAL;
1028 }
1029
1030 /* Control Channel Description */
1031 bts->chan_desc.att = 1;
1032 bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
1033 bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
1034 /* T3212 is set from vty/config */
1035
1036 paging_init(bts);
1037
1038 return 0;
1039}
1040
1041int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, int, void *),
1042 const char *config_file)
1043{
1044 struct gsm_bts *bts;
1045 int rc;
1046
1047 /* initialize our data structures */
1048 bsc_gsmnet = gsm_network_init(1, 1, mncc_recv);
1049 if (!bsc_gsmnet)
1050 return -ENOMEM;
1051
1052 bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC");
1053 bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC");
1054
1055 telnet_init(bsc_gsmnet, 4242);
1056 rc = vty_read_config_file(config_file);
1057 if (rc < 0) {
1058 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
1059 return rc;
1060 }
1061
1062 register_signal_handler(SS_NM, nm_sig_cb, NULL);
1063
1064 llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) {
1065 bootstrap_bts(bts);
1066 if (!is_ipaccess_bts(bts))
1067 rc = e1_reconfig_bts(bts);
1068
1069 if (rc < 0)
1070 exit (1);
1071 }
1072
1073 /* initialize nanoBTS support omce */
1074 rc = ipaccess_setup(bsc_gsmnet);
1075
1076 return 0;
1077}