Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 1 | /* 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 */ |
| 36 | extern struct gsm_network *bsc_gsmnet; |
| 37 | extern int ipacc_rtp_direct; |
| 38 | |
| 39 | static void patch_nm_tables(struct gsm_bts *bts); |
| 40 | static 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 |
| 52 | SET 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 | |
| 60 | unsigned 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 |
| 80 | SET 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 | |
| 130 | static 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 | /* |
| 163 | Illegal Contents GSM Formatted O&M Msg |
| 164 | Object Class: Handover Recognition |
| 165 | BTS relat. Number: 0 |
| 166 | Instance 2: FF |
| 167 | Instance 3: FF |
| 168 | SET 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 | |
| 195 | unsigned 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 |
| 240 | SET 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 | |
| 266 | unsigned 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 |
| 298 | SET 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 | |
| 307 | static 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 | |
| 317 | static 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 | |
| 336 | static 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 | |
| 341 | static unsigned char nanobts_attr_e0[] = { |
| 342 | NM_ATT_IPACC_STREAM_ID, 0x00, |
| 343 | NM_ATT_IPACC_DST_IP_PORT, 0x0b, 0xbb, /* TCP PORT for RSL */ |
| 344 | }; |
| 345 | |
| 346 | /* Callback function to be called whenever we get a GSM 12.21 state change event */ |
| 347 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 348 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 349 | { |
| 350 | struct gsm_bts *bts; |
| 351 | struct gsm_bts_trx *trx; |
| 352 | struct gsm_bts_trx_ts *ts; |
| 353 | |
| 354 | /* This is currently only required on nanoBTS */ |
| 355 | |
| 356 | switch (evt) { |
| 357 | case EVT_STATECHG_OPER: |
| 358 | switch (obj_class) { |
| 359 | case NM_OC_SITE_MANAGER: |
| 360 | bts = container_of(obj, struct gsm_bts, site_mgr); |
| 361 | if (old_state->operational != 2 && new_state->operational == 2) { |
| 362 | abis_nm_opstart(bts, NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 363 | } |
| 364 | break; |
| 365 | case NM_OC_BTS: |
| 366 | bts = obj; |
Harald Welte | 4d0481d | 2009-10-08 20:53:42 +0200 | [diff] [blame^] | 367 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 368 | patch_nm_tables(bts); |
| 369 | abis_nm_set_bts_attr(bts, nanobts_attr_bts, |
| 370 | sizeof(nanobts_attr_bts)); |
| 371 | abis_nm_opstart(bts, NM_OC_BTS, |
| 372 | bts->bts_nr, 0xff, 0xff); |
| 373 | abis_nm_chg_adm_state(bts, NM_OC_BTS, |
| 374 | bts->bts_nr, 0xff, 0xff, |
| 375 | NM_STATE_UNLOCKED); |
| 376 | } |
| 377 | break; |
| 378 | case NM_OC_CHANNEL: |
| 379 | ts = obj; |
| 380 | trx = ts->trx; |
Harald Welte | 4d0481d | 2009-10-08 20:53:42 +0200 | [diff] [blame^] | 381 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 382 | if (ts->nr == 0 && trx == trx->bts->c0) |
| 383 | abis_nm_set_channel_attr(ts, NM_CHANC_BCCHComb); |
| 384 | else |
| 385 | abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull); |
| 386 | abis_nm_opstart(trx->bts, NM_OC_CHANNEL, |
| 387 | trx->bts->bts_nr, trx->nr, ts->nr); |
| 388 | abis_nm_chg_adm_state(trx->bts, NM_OC_CHANNEL, |
| 389 | trx->bts->bts_nr, trx->nr, ts->nr, |
| 390 | NM_STATE_UNLOCKED); |
| 391 | } |
| 392 | break; |
| 393 | default: |
| 394 | break; |
| 395 | } |
| 396 | break; |
| 397 | default: |
| 398 | //DEBUGP(DMM, "Unhandled state change in %s:%d\n", __func__, __LINE__); |
| 399 | break; |
| 400 | } |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | /* Callback function to be called every time we receive a 12.21 SW activated report */ |
| 405 | static int sw_activ_rep(struct msgb *mb) |
| 406 | { |
| 407 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 408 | struct gsm_bts_trx *trx = mb->trx; |
| 409 | |
| 410 | switch (foh->obj_class) { |
| 411 | case NM_OC_BASEB_TRANSC: |
| 412 | /* TRX software is active, tell it to initiate RSL Link */ |
| 413 | abis_nm_ipaccess_msg(trx->bts, 0xe0, NM_OC_BASEB_TRANSC, |
| 414 | trx->bts->bts_nr, trx->nr, 0xff, |
| 415 | nanobts_attr_e0, sizeof(nanobts_attr_e0)); |
| 416 | abis_nm_opstart(trx->bts, NM_OC_BASEB_TRANSC, |
| 417 | trx->bts->bts_nr, trx->nr, 0xff); |
| 418 | abis_nm_chg_adm_state(trx->bts, NM_OC_BASEB_TRANSC, |
| 419 | trx->bts->bts_nr, trx->nr, 0xff, |
| 420 | NM_STATE_UNLOCKED); |
| 421 | break; |
| 422 | case NM_OC_RADIO_CARRIER: |
| 423 | patch_nm_tables(trx->bts); |
| 424 | abis_nm_set_radio_attr(trx, nanobts_attr_radio, |
| 425 | sizeof(nanobts_attr_radio)); |
| 426 | abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER, |
| 427 | trx->bts->bts_nr, trx->nr, 0xff); |
| 428 | abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER, |
| 429 | trx->bts->bts_nr, trx->nr, 0xff, |
| 430 | NM_STATE_UNLOCKED); |
| 431 | break; |
| 432 | } |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* Callback function for NACK on the OML NM */ |
| 437 | static int oml_msg_nack(int mt) |
| 438 | { |
| 439 | if (mt == NM_MT_SET_BTS_ATTR_NACK) { |
| 440 | fprintf(stderr, "Failed to set BTS attributes. That is fatal. " |
| 441 | "Was the bts type and frequency properly specified?\n"); |
| 442 | exit(-1); |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | /* Callback function to be called every time we receive a signal from NM */ |
| 449 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 450 | void *handler_data, void *signal_data) |
| 451 | { |
| 452 | switch (signal) { |
| 453 | case S_NM_SW_ACTIV_REP: |
| 454 | return sw_activ_rep(signal_data); |
| 455 | case S_NM_NACK: |
| 456 | return oml_msg_nack((int)signal_data); |
| 457 | default: |
| 458 | break; |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static void bootstrap_om_nanobts(struct gsm_bts *bts) |
| 464 | { |
| 465 | /* We don't do callback based bootstrapping, but event driven (see above) */ |
| 466 | } |
| 467 | |
| 468 | static void nm_reconfig_ts(struct gsm_bts_trx_ts *ts) |
| 469 | { |
| 470 | enum abis_nm_chan_comb ccomb = abis_nm_chcomb4pchan(ts->pchan); |
| 471 | struct gsm_e1_subslot *e1l = &ts->e1_link; |
| 472 | |
| 473 | abis_nm_set_channel_attr(ts, ccomb); |
| 474 | |
| 475 | if (is_ipaccess_bts(ts->trx->bts)) |
| 476 | return; |
| 477 | |
| 478 | switch (ts->pchan) { |
| 479 | case GSM_PCHAN_TCH_F: |
| 480 | case GSM_PCHAN_TCH_H: |
| 481 | abis_nm_conn_terr_traf(ts, e1l->e1_nr, e1l->e1_ts, |
| 482 | e1l->e1_ts_ss); |
| 483 | break; |
| 484 | default: |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | static void nm_reconfig_trx(struct gsm_bts_trx *trx) |
| 490 | { |
| 491 | struct gsm_e1_subslot *e1l = &trx->rsl_e1_link; |
| 492 | int i; |
| 493 | |
| 494 | patch_nm_tables(trx->bts); |
| 495 | |
| 496 | switch (trx->bts->type) { |
| 497 | case GSM_BTS_TYPE_BS11: |
| 498 | /* FIXME: discover this by fetching an attribute */ |
| 499 | #if 0 |
| 500 | trx->nominal_power = 15; /* 15dBm == 30mW PA configuration */ |
| 501 | #else |
| 502 | trx->nominal_power = 24; /* 24dBm == 250mW PA configuration */ |
| 503 | #endif |
| 504 | abis_nm_conn_terr_sign(trx, e1l->e1_nr, e1l->e1_ts, |
| 505 | e1l->e1_ts_ss); |
| 506 | abis_nm_establish_tei(trx->bts, trx->nr, e1l->e1_nr, |
| 507 | e1l->e1_ts, e1l->e1_ts_ss, trx->rsl_tei); |
| 508 | |
| 509 | /* Set Radio Attributes */ |
| 510 | if (trx == trx->bts->c0) |
| 511 | abis_nm_set_radio_attr(trx, bs11_attr_radio, |
| 512 | sizeof(bs11_attr_radio)); |
| 513 | else { |
| 514 | u_int8_t trx1_attr_radio[sizeof(bs11_attr_radio)]; |
| 515 | u_int8_t arfcn_low = trx->arfcn & 0xff; |
| 516 | u_int8_t arfcn_high = (trx->arfcn >> 8) & 0x0f; |
| 517 | memcpy(trx1_attr_radio, bs11_attr_radio, |
| 518 | sizeof(trx1_attr_radio)); |
| 519 | |
| 520 | /* patch ARFCN into TRX Attributes */ |
| 521 | trx1_attr_radio[2] &= 0xf0; |
| 522 | trx1_attr_radio[2] |= arfcn_high; |
| 523 | trx1_attr_radio[3] = arfcn_low; |
| 524 | |
| 525 | abis_nm_set_radio_attr(trx, trx1_attr_radio, |
| 526 | sizeof(trx1_attr_radio)); |
| 527 | } |
| 528 | break; |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 529 | case GSM_BTS_TYPE_NANOBTS: |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 530 | trx->nominal_power = 20; |
| 531 | default: |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | for (i = 0; i < TRX_NR_TS; i++) |
| 536 | nm_reconfig_ts(&trx->ts[i]); |
| 537 | } |
| 538 | |
| 539 | static void nm_reconfig_bts(struct gsm_bts *bts) |
| 540 | { |
| 541 | struct gsm_bts_trx *trx; |
| 542 | |
| 543 | switch (bts->type) { |
| 544 | case GSM_BTS_TYPE_BS11: |
| 545 | abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/ |
| 546 | abis_nm_set_bts_attr(bts, bs11_attr_bts, sizeof(bs11_attr_bts)); |
| 547 | abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */ |
| 548 | abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */ |
| 549 | break; |
| 550 | default: |
| 551 | break; |
| 552 | } |
| 553 | |
| 554 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 555 | nm_reconfig_trx(trx); |
| 556 | } |
| 557 | |
| 558 | static void bootstrap_om_bs11(struct gsm_bts *bts) |
| 559 | { |
| 560 | /* stop sending event reports */ |
| 561 | abis_nm_event_reports(bts, 0); |
| 562 | |
| 563 | /* begin DB transmission */ |
| 564 | abis_nm_bs11_db_transmission(bts, 1); |
| 565 | |
| 566 | /* end DB transmission */ |
| 567 | abis_nm_bs11_db_transmission(bts, 0); |
| 568 | |
| 569 | /* Reset BTS Site manager resource */ |
| 570 | abis_nm_bs11_reset_resource(bts); |
| 571 | |
| 572 | /* begin DB transmission */ |
| 573 | abis_nm_bs11_db_transmission(bts, 1); |
| 574 | |
| 575 | /* reconfigure BTS with all TRX and all TS */ |
| 576 | nm_reconfig_bts(bts); |
| 577 | |
| 578 | /* end DB transmission */ |
| 579 | abis_nm_bs11_db_transmission(bts, 0); |
| 580 | |
| 581 | /* Reset BTS Site manager resource */ |
| 582 | abis_nm_bs11_reset_resource(bts); |
| 583 | |
| 584 | /* restart sending event reports */ |
| 585 | abis_nm_event_reports(bts, 1); |
| 586 | } |
| 587 | |
| 588 | static void bootstrap_om(struct gsm_bts *bts) |
| 589 | { |
| 590 | fprintf(stdout, "bootstrapping OML for BTS %u\n", bts->nr); |
| 591 | |
| 592 | switch (bts->type) { |
| 593 | case GSM_BTS_TYPE_BS11: |
| 594 | bootstrap_om_bs11(bts); |
| 595 | break; |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 596 | case GSM_BTS_TYPE_NANOBTS: |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 597 | bootstrap_om_nanobts(bts); |
| 598 | break; |
| 599 | default: |
| 600 | fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | static int shutdown_om(struct gsm_bts *bts) |
| 605 | { |
| 606 | fprintf(stdout, "shutting down OML for BTS %u\n", bts->nr); |
| 607 | |
| 608 | /* stop sending event reports */ |
| 609 | abis_nm_event_reports(bts, 0); |
| 610 | |
| 611 | /* begin DB transmission */ |
| 612 | abis_nm_bs11_db_transmission(bts, 1); |
| 613 | |
| 614 | /* end DB transmission */ |
| 615 | abis_nm_bs11_db_transmission(bts, 0); |
| 616 | |
| 617 | /* Reset BTS Site manager resource */ |
| 618 | abis_nm_bs11_reset_resource(bts); |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | int bsc_shutdown_net(struct gsm_network *net) |
| 624 | { |
| 625 | struct gsm_bts *bts; |
| 626 | |
| 627 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 628 | int rc; |
| 629 | rc = shutdown_om(bts); |
| 630 | if (rc < 0) |
| 631 | return rc; |
| 632 | } |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | struct bcch_info { |
| 638 | u_int8_t type; |
| 639 | u_int8_t len; |
| 640 | const u_int8_t *data; |
| 641 | }; |
| 642 | |
| 643 | /* |
| 644 | SYSTEM INFORMATION TYPE 1 |
| 645 | Cell channel description |
| 646 | Format-ID bit map 0 |
| 647 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 |
| 648 | RACH Control Parameters |
| 649 | maximum 7 retransmissions |
| 650 | 8 slots used to spread transmission |
| 651 | cell not barred for access |
| 652 | call reestablishment not allowed |
| 653 | Access Control Class = 0000 |
| 654 | */ |
| 655 | static u_int8_t si1[] = { |
| 656 | /* header */0x55, 0x06, 0x19, |
| 657 | /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 658 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/, |
| 659 | /* rach */0xD5, 0x04, 0x00, |
| 660 | /* s1 reset*/0x2B |
| 661 | }; |
| 662 | |
| 663 | /* |
| 664 | SYSTEM INFORMATION TYPE 2 |
| 665 | Neighbour Cells Description |
| 666 | EXT-IND: Carries the complete BA |
| 667 | BA-IND = 0 |
| 668 | Format-ID bit map 0 |
| 669 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 670 | NCC permitted (NCC) = FF |
| 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 | */ |
| 678 | static u_int8_t si2[] = { |
| 679 | /* header */0x59, 0x06, 0x1A, |
| 680 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 681 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 682 | /* ncc */0xFF, |
| 683 | /* rach*/0xD5, 0x04, 0x00 |
| 684 | }; |
| 685 | |
| 686 | /* |
| 687 | SYSTEM INFORMATION TYPE 3 |
| 688 | Cell identity = 00001 (1h) |
| 689 | Location area identification |
| 690 | Mobile Country Code (MCC): 001 |
| 691 | Mobile Network Code (MNC): 01 |
| 692 | Location Area Code (LAC): 00001 (1h) |
| 693 | Control Channel Description |
| 694 | Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach |
| 695 | 0 blocks reserved for access grant |
| 696 | 1 channel used for CCCH, with SDCCH |
| 697 | 5 multiframes period for PAGING REQUEST |
| 698 | Time-out T3212 = 0 |
| 699 | Cell Options BCCH |
| 700 | Power control indicator: not set |
| 701 | MSs shall not use uplink DTX |
| 702 | Radio link timeout = 36 |
| 703 | Cell Selection Parameters |
| 704 | Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection |
| 705 | max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max) |
| 706 | 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 |
| 707 | Half rate support (NECI): New establishment causes are not supported |
| 708 | min.RX signal level for MS = 0 |
| 709 | RACH Control Parameters |
| 710 | maximum 7 retransmissions |
| 711 | 8 slots used to spread transmission |
| 712 | cell not barred for access |
| 713 | call reestablishment not allowed |
| 714 | Access Control Class = 0000 |
| 715 | SI 3 Rest Octets (not present) |
| 716 | */ |
| 717 | static u_int8_t si3[] = { |
| 718 | /* header */0x49, 0x06, 0x1B, |
| 719 | /* cell */0x00, 0x01, |
| 720 | /* lai */0x00, 0xF1, 0x10, 0x00, 0x01, |
| 721 | /* desc */0x01, 0x03, 0x00, |
| 722 | /* option*/0x28, |
| 723 | /* selection*/0x62, 0x00, |
| 724 | /* rach */0xD5, 0x04, 0x00, |
| 725 | /* rest */ 0x2B, 0x2B, 0x2B, 0x2B |
| 726 | }; |
| 727 | |
| 728 | /* |
| 729 | SYSTEM INFORMATION TYPE 4 |
| 730 | Location area identification |
| 731 | Mobile Country Code (MCC): 001 |
| 732 | Mobile Network Code (MNC): 01 |
| 733 | Location Area Code (LAC): 00001 (1h) |
| 734 | Cell Selection Parameters |
| 735 | Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection |
| 736 | max.TX power level MS may use for CCH = 2 |
| 737 | 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 |
| 738 | Half rate support (NECI): New establishment causes are not supported |
| 739 | min.RX signal level for MS = 0 |
| 740 | RACH Control Parameters |
| 741 | maximum 7 retransmissions |
| 742 | 8 slots used to spread transmission |
| 743 | cell not barred for access |
| 744 | call reestablishment not allowed |
| 745 | Access Control Class = 0000 |
| 746 | CBCH Channel Description |
| 747 | Type = SDCCH/4[2] |
| 748 | Timeslot Number: 0 |
| 749 | Training Sequence Code: 7h |
| 750 | ARFCN: 1 |
| 751 | SI Rest Octets (not present) |
| 752 | */ |
| 753 | static u_int8_t si4[] = { |
| 754 | /* header */0x41, 0x06, 0x1C, |
| 755 | /* lai */0x00, 0xF1, 0x10, 0x00, 0x01, |
| 756 | /* sel */0x62, 0x00, |
| 757 | /* rach*/0xD5, 0x04, 0x00, |
| 758 | /* cbch chan desc */ 0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, |
| 759 | /* rest octets */ 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B |
| 760 | }; |
| 761 | |
| 762 | /* |
| 763 | SYSTEM INFORMATION TYPE 5 |
| 764 | Neighbour Cells Description |
| 765 | EXT-IND: Carries the complete BA |
| 766 | BA-IND = 0 |
| 767 | Format-ID bit map 0 |
| 768 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 769 | */ |
| 770 | |
| 771 | static u_int8_t si5[] = { |
| 772 | /* header without l2 len*/0x06, 0x1D, |
| 773 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 774 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 775 | }; |
| 776 | |
| 777 | // SYSTEM INFORMATION TYPE 6 |
| 778 | |
| 779 | /* |
| 780 | SACCH FILLING |
| 781 | System Info Type: SYSTEM INFORMATION 6 |
| 782 | L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF |
| 783 | |
| 784 | SYSTEM INFORMATION TYPE 6 |
| 785 | Cell identity = 00001 (1h) |
| 786 | Location area identification |
| 787 | Mobile Country Code (MCC): 001 |
| 788 | Mobile Network Code (MNC): 01 |
| 789 | Location Area Code (LAC): 00001 (1h) |
| 790 | Cell Options SACCH |
| 791 | Power control indicator: not set |
| 792 | MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H. |
| 793 | Radio link timeout = 36 |
| 794 | NCC permitted (NCC) = FF |
| 795 | */ |
| 796 | |
| 797 | static u_int8_t si6[] = { |
| 798 | /* header */0x06, 0x1E, |
| 799 | /* cell id*/ 0x00, 0x01, |
| 800 | /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01, |
| 801 | /* options */ 0x28, |
| 802 | /* ncc */ 0xFF, |
| 803 | }; |
| 804 | |
| 805 | |
| 806 | |
| 807 | static const struct bcch_info bcch_infos[] = { |
| 808 | { |
| 809 | .type = RSL_SYSTEM_INFO_1, |
| 810 | .len = sizeof(si1), |
| 811 | .data = si1, |
| 812 | }, { |
| 813 | .type = RSL_SYSTEM_INFO_2, |
| 814 | .len = sizeof(si2), |
| 815 | .data = si2, |
| 816 | }, { |
| 817 | .type = RSL_SYSTEM_INFO_3, |
| 818 | .len = sizeof(si3), |
| 819 | .data = si3, |
| 820 | }, { |
| 821 | .type = RSL_SYSTEM_INFO_4, |
| 822 | .len = sizeof(si4), |
| 823 | .data = si4, |
| 824 | }, |
| 825 | }; |
| 826 | |
| 827 | static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1) |
| 828 | static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2) |
| 829 | static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3) |
| 830 | static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4) |
| 831 | static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5) |
| 832 | static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6) |
| 833 | |
| 834 | /* set all system information types */ |
| 835 | static int set_system_infos(struct gsm_bts_trx *trx) |
| 836 | { |
| 837 | int i; |
| 838 | |
| 839 | if (trx == trx->bts->c0) { |
| 840 | for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) { |
| 841 | rsl_bcch_info(trx, bcch_infos[i].type, |
| 842 | bcch_infos[i].data, |
| 843 | bcch_infos[i].len); |
| 844 | } |
| 845 | } |
| 846 | rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5)); |
| 847 | rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6)); |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Patch the various SYSTEM INFORMATION tables to update |
| 854 | * the LAI |
| 855 | */ |
| 856 | static void patch_nm_tables(struct gsm_bts *bts) |
| 857 | { |
| 858 | u_int8_t arfcn_low = bts->c0->arfcn & 0xff; |
| 859 | u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f; |
| 860 | |
| 861 | /* patch ARFCN into BTS Attributes */ |
| 862 | bs11_attr_bts[69] &= 0xf0; |
| 863 | bs11_attr_bts[69] |= arfcn_high; |
| 864 | bs11_attr_bts[70] = arfcn_low; |
| 865 | nanobts_attr_bts[42] &= 0xf0; |
| 866 | nanobts_attr_bts[42] |= arfcn_high; |
| 867 | nanobts_attr_bts[43] = arfcn_low; |
| 868 | |
| 869 | /* patch ARFCN into TRX Attributes */ |
| 870 | bs11_attr_radio[2] &= 0xf0; |
| 871 | bs11_attr_radio[2] |= arfcn_high; |
| 872 | bs11_attr_radio[3] = arfcn_low; |
| 873 | nanobts_attr_radio[5] &= 0xf0; |
| 874 | nanobts_attr_radio[5] |= arfcn_high; |
| 875 | nanobts_attr_radio[6] = arfcn_low; |
| 876 | |
| 877 | /* patch BSIC */ |
| 878 | bs11_attr_bts[1] = bts->bsic; |
| 879 | nanobts_attr_bts[sizeof(nanobts_attr_bts)-1] = bts->bsic; |
| 880 | |
| 881 | /* patch the power reduction */ |
| 882 | bs11_attr_radio[5] = bts->c0->max_power_red / 2; |
| 883 | nanobts_attr_radio[1] = bts->c0->max_power_red / 2; |
| 884 | } |
| 885 | |
| 886 | /* |
| 887 | * Patch the various SYSTEM INFORMATION tables to update |
| 888 | * the LAI |
| 889 | */ |
| 890 | static void patch_si_tables(struct gsm_bts *bts) |
| 891 | { |
| 892 | u_int8_t arfcn_low = bts->c0->arfcn & 0xff; |
| 893 | u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f; |
| 894 | |
| 895 | /* covert the raw packet to the struct */ |
| 896 | struct gsm48_system_information_type_1 *type_1 = |
| 897 | (struct gsm48_system_information_type_1*)&si1; |
| 898 | struct gsm48_system_information_type_2 *type_2 = |
| 899 | (struct gsm48_system_information_type_2*)&si2; |
| 900 | struct gsm48_system_information_type_3 *type_3 = |
| 901 | (struct gsm48_system_information_type_3*)&si3; |
| 902 | struct gsm48_system_information_type_4 *type_4 = |
| 903 | (struct gsm48_system_information_type_4*)&si4; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 904 | struct gsm48_system_information_type_6 *type_6 = |
| 905 | (struct gsm48_system_information_type_6*)&si6; |
| 906 | struct gsm48_loc_area_id lai; |
| 907 | |
| 908 | gsm0408_generate_lai(&lai, bts->network->country_code, |
| 909 | bts->network->network_code, |
| 910 | bts->location_area_code); |
| 911 | |
| 912 | /* assign the MCC and MNC */ |
| 913 | type_3->lai = lai; |
| 914 | type_4->lai = lai; |
| 915 | type_6->lai = lai; |
| 916 | |
Holger Hans Peter Freyther | c4a49e3 | 2009-08-21 14:44:12 +0200 | [diff] [blame] | 917 | /* set the CI */ |
| 918 | type_3->cell_identity = htons(bts->cell_identity); |
| 919 | type_6->cell_identity = htons(bts->cell_identity); |
| 920 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 921 | type_4->data[2] &= 0xf0; |
| 922 | type_4->data[2] |= arfcn_high; |
| 923 | type_4->data[3] = arfcn_low; |
| 924 | |
| 925 | /* patch Control Channel Description 10.5.2.11 */ |
| 926 | type_3->control_channel_desc = bts->chan_desc; |
| 927 | |
| 928 | /* patch TSC */ |
| 929 | si4[15] &= ~0xe0; |
| 930 | si4[15] |= (bts->tsc & 7) << 5; |
| 931 | |
| 932 | /* patch MS max power for CCH */ |
| 933 | type_4->cell_sel_par.ms_txpwr_max_ccch = |
| 934 | ms_pwr_ctl_lvl(bts->band, bts->ms_max_power); |
| 935 | |
| 936 | if (bts->cell_barred) { |
| 937 | type_1->rach_control.cell_bar = 1; |
| 938 | type_2->rach_control.cell_bar = 1; |
| 939 | type_3->rach_control.cell_bar = 1; |
| 940 | type_4->rach_control.cell_bar = 1; |
| 941 | } else { |
| 942 | type_1->rach_control.cell_bar = 0; |
| 943 | type_2->rach_control.cell_bar = 0; |
| 944 | type_3->rach_control.cell_bar = 0; |
| 945 | type_4->rach_control.cell_bar = 0; |
| 946 | } |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
| 950 | static void bootstrap_rsl(struct gsm_bts_trx *trx) |
| 951 | { |
| 952 | fprintf(stdout, "bootstrapping RSL for BTS/TRX (%u/%u) " |
| 953 | "using MCC=%u MNC=%u BSIC=%u TSC=%u\n", |
| 954 | trx->bts->nr, trx->nr, bsc_gsmnet->country_code, |
| 955 | bsc_gsmnet->network_code, trx->bts->bsic, trx->bts->tsc); |
| 956 | patch_si_tables(trx->bts); |
| 957 | set_system_infos(trx); |
| 958 | } |
| 959 | |
| 960 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
| 961 | { |
| 962 | switch (event) { |
| 963 | case EVT_E1_TEI_UP: |
| 964 | switch (type) { |
| 965 | case E1INP_SIGN_OML: |
| 966 | bootstrap_om(trx->bts); |
| 967 | break; |
| 968 | case E1INP_SIGN_RSL: |
| 969 | bootstrap_rsl(trx); |
| 970 | break; |
| 971 | default: |
| 972 | break; |
| 973 | } |
| 974 | break; |
| 975 | case EVT_E1_TEI_DN: |
| 976 | fprintf(stderr, "Lost some E1 TEI link\n"); |
| 977 | /* FIXME: deal with TEI or L1 link loss */ |
| 978 | break; |
| 979 | default: |
| 980 | break; |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | static int bootstrap_bts(struct gsm_bts *bts) |
| 985 | { |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 986 | switch (bts->band) { |
| 987 | case GSM_BAND_1800: |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 988 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) { |
| 989 | fprintf(stderr, "GSM1800 channel must be between 512-885.\n"); |
| 990 | return -EINVAL; |
| 991 | } |
| 992 | break; |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 993 | case GSM_BAND_1900: |
| 994 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) { |
| 995 | fprintf(stderr, "GSM1900 channel must be between 512-810.\n"); |
| 996 | return -EINVAL; |
| 997 | } |
| 998 | break; |
| 999 | case GSM_BAND_900: |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 1000 | if (bts->c0->arfcn < 1 || bts->c0->arfcn > 124) { |
| 1001 | fprintf(stderr, "GSM900 channel must be between 1-124.\n"); |
| 1002 | return -EINVAL; |
| 1003 | } |
| 1004 | break; |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 1005 | default: |
| 1006 | fprintf(stderr, "Unsupported frequency band.\n"); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 1007 | return -EINVAL; |
| 1008 | } |
| 1009 | |
| 1010 | /* Control Channel Description */ |
| 1011 | bts->chan_desc.att = 1; |
| 1012 | bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C; |
| 1013 | bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5; |
| 1014 | /* T3212 is set from vty/config */ |
| 1015 | |
| 1016 | paging_init(bts); |
| 1017 | |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
| 1021 | int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, int, void *), |
| 1022 | const char *config_file) |
| 1023 | { |
| 1024 | struct gsm_bts *bts; |
| 1025 | int rc; |
| 1026 | |
| 1027 | /* initialize our data structures */ |
| 1028 | bsc_gsmnet = gsm_network_init(1, 1, mncc_recv); |
| 1029 | if (!bsc_gsmnet) |
| 1030 | return -ENOMEM; |
| 1031 | |
| 1032 | bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 1033 | bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 1034 | |
| 1035 | telnet_init(bsc_gsmnet, 4242); |
| 1036 | rc = vty_read_config_file(config_file); |
| 1037 | if (rc < 0) { |
| 1038 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 1039 | return rc; |
| 1040 | } |
| 1041 | |
| 1042 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
| 1043 | |
| 1044 | llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) { |
| 1045 | bootstrap_bts(bts); |
| 1046 | if (!is_ipaccess_bts(bts)) |
| 1047 | rc = e1_reconfig_bts(bts); |
| 1048 | |
| 1049 | if (rc < 0) |
| 1050 | exit (1); |
| 1051 | } |
| 1052 | |
| 1053 | /* initialize nanoBTS support omce */ |
| 1054 | rc = ipaccess_setup(bsc_gsmnet); |
| 1055 | |
| 1056 | return 0; |
| 1057 | } |