Holger Hans Peter Freyther | cad370f | 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> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 24 | #include <osmocore/gsm_utils.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 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> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 31 | #include <openbsc/system_information.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 32 | #include <openbsc/paging.h> |
| 33 | #include <openbsc/signal.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 34 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 35 | |
| 36 | /* global pointer to the gsm network data structure */ |
| 37 | extern struct gsm_network *bsc_gsmnet; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 38 | |
| 39 | static void patch_nm_tables(struct gsm_bts *bts); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 40 | |
| 41 | /* The following definitions are for OM and NM packets that we cannot yet |
| 42 | * generate by code but we just pass on */ |
| 43 | |
| 44 | // BTS Site Manager, SET ATTRIBUTES |
| 45 | |
| 46 | /* |
| 47 | Object Class: BTS Site Manager |
| 48 | Instance 1: FF |
| 49 | Instance 2: FF |
| 50 | Instance 3: FF |
| 51 | SET ATTRIBUTES |
| 52 | sAbisExternalTime: 2007/09/08 14:36:11 |
| 53 | omLAPDRelTimer: 30sec |
| 54 | shortLAPDIntTimer: 5sec |
| 55 | emergencyTimer1: 10 minutes |
| 56 | emergencyTimer2: 0 minutes |
| 57 | */ |
| 58 | |
| 59 | unsigned char msg_1[] = |
| 60 | { |
| 61 | NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, 0xFF, 0xFF, 0xFF, |
| 62 | NM_ATT_BS11_ABIS_EXT_TIME, 0x07, |
| 63 | 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE, |
| 64 | 0x02, |
| 65 | 0x00, 0x1E, |
| 66 | NM_ATT_BS11_SH_LAPD_INT_TIMER, |
| 67 | 0x01, 0x05, |
| 68 | 0x42, 0x02, 0x00, 0x0A, |
| 69 | 0x44, 0x02, 0x00, 0x00 |
| 70 | }; |
| 71 | |
| 72 | // BTS, SET BTS ATTRIBUTES |
| 73 | |
| 74 | /* |
| 75 | Object Class: BTS |
| 76 | BTS relat. Number: 0 |
| 77 | Instance 2: FF |
| 78 | Instance 3: FF |
| 79 | SET BTS ATTRIBUTES |
| 80 | bsIdentityCode / BSIC: |
| 81 | PLMN_colour_code: 7h |
| 82 | BS_colour_code: 7h |
| 83 | BTS Air Timer T3105: 4 ,unit 10 ms |
| 84 | btsIsHopping: FALSE |
| 85 | periodCCCHLoadIndication: 1sec |
| 86 | thresholdCCCHLoadIndication: 0% |
| 87 | cellAllocationNumber: 00h = GSM 900 |
| 88 | enableInterferenceClass: 00h = Disabled |
| 89 | fACCHQual: 6 (FACCH stealing flags minus 1) |
| 90 | intaveParameter: 31 SACCH multiframes |
| 91 | interferenceLevelBoundaries: |
| 92 | Interference Boundary 1: 0Ah |
| 93 | Interference Boundary 2: 0Fh |
| 94 | Interference Boundary 3: 14h |
| 95 | Interference Boundary 4: 19h |
| 96 | Interference Boundary 5: 1Eh |
| 97 | mSTxPwrMax: 11 |
| 98 | GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm |
| 99 | DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm |
| 100 | PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm |
| 101 | 30=33dBm, 31=32dBm |
| 102 | ny1: |
| 103 | Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20 |
| 104 | powerOutputThresholds: |
| 105 | Out Power Fault Threshold: -10 dB |
| 106 | Red Out Power Threshold: - 6 dB |
| 107 | Excessive Out Power Threshold: 5 dB |
| 108 | rACHBusyThreshold: -127 dBm |
| 109 | rACHLoadAveragingSlots: 250 ,number of RACH burst periods |
| 110 | rfResourceIndicationPeriod: 125 SACCH multiframes |
| 111 | T200: |
| 112 | SDCCH: 044 in 5 ms |
| 113 | FACCH/Full rate: 031 in 5 ms |
| 114 | FACCH/Half rate: 041 in 5 ms |
| 115 | SACCH with TCH SAPI0: 090 in 10 ms |
| 116 | SACCH with SDCCH: 090 in 10 ms |
| 117 | SDCCH with SAPI3: 090 in 5 ms |
| 118 | SACCH with TCH SAPI3: 135 in 10 ms |
| 119 | tSync: 9000 units of 10 msec |
| 120 | tTrau: 9000 units of 10 msec |
| 121 | enableUmLoopTest: 00h = disabled |
| 122 | enableExcessiveDistance: 00h = Disabled |
| 123 | excessiveDistance: 64km |
| 124 | hoppingMode: 00h = baseband hopping |
| 125 | cellType: 00h = Standard Cell |
| 126 | BCCH ARFCN / bCCHFrequency: 1 |
| 127 | */ |
| 128 | |
| 129 | static unsigned char bs11_attr_bts[] = |
| 130 | { |
| 131 | NM_ATT_BSIC, HARDCODED_BSIC, |
| 132 | NM_ATT_BTS_AIR_TIMER, 0x04, |
| 133 | NM_ATT_BS11_BTSLS_HOPPING, 0x00, |
| 134 | NM_ATT_CCCH_L_I_P, 0x01, |
| 135 | NM_ATT_CCCH_L_T, 0x00, |
| 136 | NM_ATT_BS11_CELL_ALLOC_NR, NM_BS11_CANR_GSM, |
| 137 | NM_ATT_BS11_ENA_INTERF_CLASS, 0x01, |
| 138 | NM_ATT_BS11_FACCH_QUAL, 0x06, |
| 139 | /* interference avg. period in numbers of SACCH multifr */ |
| 140 | NM_ATT_INTAVE_PARAM, 0x1F, |
| 141 | NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B, |
| 142 | NM_ATT_CCCH_L_T, 0x23, |
| 143 | NM_ATT_GSM_TIME, 0x28, 0x00, |
| 144 | NM_ATT_ADM_STATE, 0x03, |
| 145 | NM_ATT_RACH_B_THRESH, 0x7F, |
| 146 | NM_ATT_LDAVG_SLOTS, 0x00, 0xFA, |
| 147 | NM_ATT_BS11_RF_RES_IND_PER, 0x7D, |
| 148 | NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87, |
| 149 | NM_ATT_BS11_TSYNC, 0x23, 0x28, |
| 150 | NM_ATT_BS11_TTRAU, 0x23, 0x28, |
| 151 | NM_ATT_TEST_DUR, 0x01, 0x00, |
| 152 | NM_ATT_OUTST_ALARM, 0x01, 0x00, |
| 153 | NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40, |
| 154 | NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00, |
| 155 | NM_ATT_BS11_PLL, 0x01, 0x00, |
| 156 | NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/, |
| 157 | }; |
| 158 | |
| 159 | // Handover Recognition, SET ATTRIBUTES |
| 160 | |
| 161 | /* |
| 162 | Illegal Contents GSM Formatted O&M Msg |
| 163 | Object Class: Handover Recognition |
| 164 | BTS relat. Number: 0 |
| 165 | Instance 2: FF |
| 166 | Instance 3: FF |
| 167 | SET ATTRIBUTES |
| 168 | enableDelayPowerBudgetHO: 00h = Disabled |
| 169 | enableDistanceHO: 00h = Disabled |
| 170 | enableInternalInterCellHandover: 00h = Disabled |
| 171 | enableInternalIntraCellHandover: 00h = Disabled |
| 172 | enablePowerBudgetHO: 00h = Disabled |
| 173 | enableRXLEVHO: 00h = Disabled |
| 174 | enableRXQUALHO: 00h = Disabled |
| 175 | hoAveragingDistance: 8 SACCH multiframes |
| 176 | hoAveragingLev: |
| 177 | A_LEV_HO: 8 SACCH multiframes |
| 178 | W_LEV_HO: 1 SACCH multiframes |
| 179 | hoAveragingPowerBudget: 16 SACCH multiframes |
| 180 | hoAveragingQual: |
| 181 | A_QUAL_HO: 8 SACCH multiframes |
| 182 | W_QUAL_HO: 2 SACCH multiframes |
| 183 | hoLowerThresholdLevDL: (10 - 110) dBm |
| 184 | hoLowerThresholdLevUL: (5 - 110) dBm |
| 185 | hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8% |
| 186 | hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8% |
| 187 | hoThresholdLevDLintra : (20 - 110) dBm |
| 188 | hoThresholdLevULintra: (20 - 110) dBm |
| 189 | hoThresholdMsRangeMax: 20 km |
| 190 | nCell: 06h |
| 191 | timerHORequest: 3 ,unit 2 SACCH multiframes |
| 192 | */ |
| 193 | |
| 194 | unsigned char msg_3[] = |
| 195 | { |
| 196 | NM_MT_BS11_SET_ATTR, NM_OC_BS11_HANDOVER, 0x00, 0xFF, 0xFF, |
| 197 | 0xD0, 0x00, /* enableDelayPowerBudgetHO */ |
| 198 | 0x64, 0x00, /* enableDistanceHO */ |
| 199 | 0x67, 0x00, /* enableInternalInterCellHandover */ |
| 200 | 0x68, 0x00, /* enableInternalInterCellHandover */ |
| 201 | 0x6A, 0x00, /* enablePowerBudgetHO */ |
| 202 | 0x6C, 0x00, /* enableRXLEVHO */ |
| 203 | 0x6D, 0x00, /* enableRXQUALHO */ |
| 204 | 0x6F, 0x08, /* hoAveragingDistance */ |
| 205 | 0x70, 0x08, 0x01, /* hoAveragingLev */ |
| 206 | 0x71, 0x10, 0x10, 0x10, |
| 207 | 0x72, 0x08, 0x02, /* hoAveragingQual */ |
| 208 | 0x73, 0x0A, /* hoLowerThresholdLevDL */ |
| 209 | 0x74, 0x05, /* hoLowerThresholdLevUL */ |
| 210 | 0x75, 0x06, /* hoLowerThresholdQualDL */ |
| 211 | 0x76, 0x06, /* hoLowerThresholdQualUL */ |
| 212 | 0x78, 0x14, /* hoThresholdLevDLintra */ |
| 213 | 0x79, 0x14, /* hoThresholdLevULintra */ |
| 214 | 0x7A, 0x14, /* hoThresholdMsRangeMax */ |
| 215 | 0x7D, 0x06, /* nCell */ |
| 216 | NM_ATT_BS11_TIMER_HO_REQUEST, 0x03, |
| 217 | 0x20, 0x01, 0x00, |
| 218 | 0x45, 0x01, 0x00, |
| 219 | 0x48, 0x01, 0x00, |
| 220 | 0x5A, 0x01, 0x00, |
| 221 | 0x5B, 0x01, 0x05, |
| 222 | 0x5E, 0x01, 0x1A, |
| 223 | 0x5F, 0x01, 0x20, |
| 224 | 0x9D, 0x01, 0x00, |
| 225 | 0x47, 0x01, 0x00, |
| 226 | 0x5C, 0x01, 0x64, |
| 227 | 0x5D, 0x01, 0x1E, |
| 228 | 0x97, 0x01, 0x20, |
| 229 | 0xF7, 0x01, 0x3C, |
| 230 | }; |
| 231 | |
| 232 | // Power Control, SET ATTRIBUTES |
| 233 | |
| 234 | /* |
| 235 | Object Class: Power Control |
| 236 | BTS relat. Number: 0 |
| 237 | Instance 2: FF |
| 238 | Instance 3: FF |
| 239 | SET ATTRIBUTES |
| 240 | enableMsPowerControl: 00h = Disabled |
| 241 | enablePowerControlRLFW: 00h = Disabled |
| 242 | pcAveragingLev: |
| 243 | A_LEV_PC: 4 SACCH multiframes |
| 244 | W_LEV_PC: 1 SACCH multiframes |
| 245 | pcAveragingQual: |
| 246 | A_QUAL_PC: 4 SACCH multiframes |
| 247 | W_QUAL_PC: 2 SACCH multiframes |
| 248 | pcLowerThresholdLevDL: 0Fh |
| 249 | pcLowerThresholdLevUL: 0Ah |
| 250 | pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4% |
| 251 | pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4% |
| 252 | pcRLFThreshold: 0Ch |
| 253 | pcUpperThresholdLevDL: 14h |
| 254 | pcUpperThresholdLevUL: 0Fh |
| 255 | pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2% |
| 256 | pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2% |
| 257 | powerConfirm: 2 ,unit 2 SACCH multiframes |
| 258 | powerControlInterval: 2 ,unit 2 SACCH multiframes |
| 259 | powerIncrStepSize: 02h = 4 dB |
| 260 | powerRedStepSize: 01h = 2 dB |
| 261 | radioLinkTimeoutBs: 64 SACCH multiframes |
| 262 | enableBSPowerControl: 00h = disabled |
| 263 | */ |
| 264 | |
| 265 | unsigned char msg_4[] = |
| 266 | { |
| 267 | NM_MT_BS11_SET_ATTR, NM_OC_BS11_PWR_CTRL, 0x00, 0xFF, 0xFF, |
| 268 | NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00, |
| 269 | NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00, |
| 270 | 0x7E, 0x04, 0x01, /* pcAveragingLev */ |
| 271 | 0x7F, 0x04, 0x02, /* pcAveragingQual */ |
| 272 | 0x80, 0x0F, /* pcLowerThresholdLevDL */ |
| 273 | 0x81, 0x0A, /* pcLowerThresholdLevUL */ |
| 274 | 0x82, 0x05, /* pcLowerThresholdQualDL */ |
| 275 | 0x83, 0x05, /* pcLowerThresholdQualUL */ |
| 276 | 0x84, 0x0C, /* pcRLFThreshold */ |
| 277 | 0x85, 0x14, /* pcUpperThresholdLevDL */ |
| 278 | 0x86, 0x0F, /* pcUpperThresholdLevUL */ |
| 279 | 0x87, 0x04, /* pcUpperThresholdQualDL */ |
| 280 | 0x88, 0x04, /* pcUpperThresholdQualUL */ |
| 281 | 0x89, 0x02, /* powerConfirm */ |
| 282 | 0x8A, 0x02, /* powerConfirmInterval */ |
| 283 | 0x8B, 0x02, /* powerIncrStepSize */ |
| 284 | 0x8C, 0x01, /* powerRedStepSize */ |
| 285 | 0x8D, 0x40, /* radioLinkTimeoutBs */ |
| 286 | 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl |
| 287 | }; |
| 288 | |
| 289 | |
| 290 | // Transceiver, SET TRX ATTRIBUTES (TRX 0) |
| 291 | |
| 292 | /* |
| 293 | Object Class: Transceiver |
| 294 | BTS relat. Number: 0 |
| 295 | Tranceiver number: 0 |
| 296 | Instance 3: FF |
| 297 | SET TRX ATTRIBUTES |
| 298 | aRFCNList (HEX): 0001 |
| 299 | txPwrMaxReduction: 00h = 30dB |
| 300 | radioMeasGran: 254 SACCH multiframes |
| 301 | radioMeasRep: 01h = enabled |
| 302 | memberOfEmergencyConfig: 01h = TRUE |
| 303 | trxArea: 00h = TRX doesn't belong to a concentric cell |
| 304 | */ |
| 305 | |
| 306 | static unsigned char bs11_attr_radio[] = |
| 307 | { |
| 308 | NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/, |
| 309 | NM_ATT_RF_MAXPOWR_R, 0x00, |
| 310 | NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0x05, |
| 311 | NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01, |
| 312 | NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01, |
| 313 | NM_ATT_BS11_TRX_AREA, 0x01, 0x00, |
| 314 | }; |
| 315 | |
| 316 | static unsigned char nanobts_attr_bts[] = { |
| 317 | NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, |
| 318 | /* interference avg. period in numbers of SACCH multifr */ |
| 319 | NM_ATT_INTAVE_PARAM, 0x06, |
| 320 | /* conn fail based on SACCH error rate */ |
| 321 | NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10, |
| 322 | NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8, |
| 323 | NM_ATT_MAX_TA, 0x3f, |
| 324 | NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */ |
| 325 | NM_ATT_CCCH_L_T, 10, /* percent */ |
| 326 | NM_ATT_CCCH_L_I_P, 1, /* seconds */ |
| 327 | NM_ATT_RACH_B_THRESH, 10, /* busy threshold in - dBm */ |
| 328 | NM_ATT_LDAVG_SLOTS, 0x03, 0xe8, /* rach load averaging 1000 slots */ |
| 329 | NM_ATT_BTS_AIR_TIMER, 128, /* miliseconds */ |
| 330 | NM_ATT_NY1, 10, /* 10 retransmissions of physical config */ |
| 331 | NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 332 | NM_ATT_BSIC, HARDCODED_BSIC, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 333 | NM_ATT_IPACC_CGI, 0, 7, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x00, 0x00, |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 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 | |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 341 | static unsigned char nanobts_attr_nse[] = { |
| 342 | NM_ATT_IPACC_NSEI, 0, 2, 0x03, 0x9d, /* NSEI 925 */ |
| 343 | NM_ATT_IPACC_NS_CFG, 0, 7, 3, /* (un)blocking timer (Tns-block) */ |
| 344 | 3, /* (un)blocking retries */ |
| 345 | 3, /* reset timer (Tns-reset) */ |
| 346 | 3, /* reset retries */ |
| 347 | 30, /* test timer (Tns-test) */ |
| 348 | 3, /* alive timer (Tns-alive) */ |
| 349 | 10, /* alive retrires */ |
| 350 | NM_ATT_IPACC_BSSGP_CFG, 0, 11, |
| 351 | 3, /* blockimg timer (T1) */ |
| 352 | 3, /* blocking retries */ |
| 353 | 3, /* unblocking retries */ |
| 354 | 3, /* reset timer */ |
| 355 | 3, /* reset retries */ |
| 356 | 10, /* suspend timer (T3) in 100ms */ |
| 357 | 3, /* suspend retries */ |
| 358 | 10, /* resume timer (T4) in 100ms */ |
| 359 | 3, /* resume retries */ |
| 360 | 10, /* capability update timer (T5) */ |
| 361 | 3, /* capability update retries */ |
| 362 | }; |
| 363 | |
| 364 | static unsigned char nanobts_attr_cell[] = { |
| 365 | NM_ATT_IPACC_RAC, 0, 1, 1, /* routing area code */ |
| 366 | NM_ATT_IPACC_GPRS_PAGING_CFG, 0, 2, |
| 367 | 5, /* repeat time (50ms) */ |
| 368 | 3, /* repeat count */ |
| 369 | NM_ATT_IPACC_BVCI, 0, 2, 0x03, 0x9d, /* BVCI 925 */ |
| 370 | NM_ATT_IPACC_RLC_CFG, 0, 9, |
| 371 | 20, /* T3142 */ |
| 372 | 5, /* T3169 */ |
| 373 | 5, /* T3191 */ |
| 374 | 200, /* T3193 */ |
| 375 | 5, /* T3195 */ |
| 376 | 10, /* N3101 */ |
| 377 | 4, /* N3103 */ |
| 378 | 8, /* N3105 */ |
| 379 | 15, /* RLC CV countdown */ |
| 380 | NM_ATT_IPACC_CODING_SCHEMES, 0, 2, 0x0f, 0x00, |
| 381 | NM_ATT_IPACC_RLC_CFG_2, 0, 5, |
| 382 | 0x00, 250, |
| 383 | 0x00, 250, |
| 384 | 2, /* MCS2 */ |
| 385 | #if 0 |
| 386 | /* EDGE model only, breaks older models. |
| 387 | * Should inquire the BTS capabilities */ |
| 388 | NM_ATT_IPACC_RLC_CFG_3, 0, 1, |
| 389 | 2, /* MCS2 */ |
| 390 | #endif |
| 391 | }; |
| 392 | |
| 393 | static unsigned char nanobts_attr_nsvc0[] = { |
| 394 | NM_ATT_IPACC_NSVCI, 0, 2, 0x03, 0x9d, /* 925 */ |
| 395 | NM_ATT_IPACC_NS_LINK_CFG, 0, 8, |
| 396 | 0x59, 0xd8, /* remote udp port (23000) */ |
| 397 | 192, 168, 100, 11, /* remote ip address */ |
| 398 | 0x59, 0xd8, /* local udp port (23000) */ |
| 399 | }; |
| 400 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 401 | /* Callback function to be called whenever we get a GSM 12.21 state change event */ |
| 402 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 403 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 404 | { |
| 405 | struct gsm_bts *bts; |
| 406 | struct gsm_bts_trx *trx; |
| 407 | struct gsm_bts_trx_ts *ts; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 408 | struct gsm_bts_gprs_nsvc *nsvc; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 409 | |
Harald Welte | 9c913c4 | 2009-10-20 17:31:00 +0200 | [diff] [blame] | 410 | /* This event-driven BTS setup is currently only required on nanoBTS */ |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 411 | |
Harald Welte | 9c913c4 | 2009-10-20 17:31:00 +0200 | [diff] [blame] | 412 | /* EVT_STATECHG_ADM is called after we call chg_adm_state() and would create |
| 413 | * endless loop */ |
| 414 | if (evt != EVT_STATECHG_OPER) |
| 415 | return 0; |
| 416 | |
| 417 | switch (obj_class) { |
| 418 | case NM_OC_SITE_MANAGER: |
| 419 | bts = container_of(obj, struct gsm_bts, site_mgr); |
Sylvain Munaut | da1b134 | 2009-12-18 17:45:45 +0100 | [diff] [blame] | 420 | if ((new_state->operational == 2 && |
| 421 | new_state->availability == NM_AVSTATE_OK) || |
| 422 | (new_state->operational == 1 && |
| 423 | new_state->availability == NM_AVSTATE_OFF_LINE)) |
Harald Welte | 9c913c4 | 2009-10-20 17:31:00 +0200 | [diff] [blame] | 424 | abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff); |
| 425 | break; |
| 426 | case NM_OC_BTS: |
| 427 | bts = obj; |
| 428 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 429 | patch_nm_tables(bts); |
| 430 | abis_nm_set_bts_attr(bts, nanobts_attr_bts, |
| 431 | sizeof(nanobts_attr_bts)); |
| 432 | abis_nm_chg_adm_state(bts, obj_class, |
| 433 | bts->bts_nr, 0xff, 0xff, |
| 434 | NM_STATE_UNLOCKED); |
| 435 | abis_nm_opstart(bts, obj_class, |
| 436 | bts->bts_nr, 0xff, 0xff); |
| 437 | } |
| 438 | break; |
| 439 | case NM_OC_CHANNEL: |
| 440 | ts = obj; |
| 441 | trx = ts->trx; |
| 442 | if (new_state->operational == 1 && |
| 443 | new_state->availability == NM_AVSTATE_DEPENDENCY) { |
Harald Welte | c696d2f | 2009-10-26 20:14:33 +0100 | [diff] [blame] | 444 | patch_nm_tables(trx->bts); |
Harald Welte | cfb781c | 2009-10-24 09:09:05 +0200 | [diff] [blame] | 445 | enum abis_nm_chan_comb ccomb = |
| 446 | abis_nm_chcomb4pchan(ts->pchan); |
| 447 | abis_nm_set_channel_attr(ts, ccomb); |
Harald Welte | 9c913c4 | 2009-10-20 17:31:00 +0200 | [diff] [blame] | 448 | abis_nm_chg_adm_state(trx->bts, obj_class, |
| 449 | trx->bts->bts_nr, trx->nr, ts->nr, |
| 450 | NM_STATE_UNLOCKED); |
| 451 | abis_nm_opstart(trx->bts, obj_class, |
| 452 | trx->bts->bts_nr, trx->nr, ts->nr); |
| 453 | } |
| 454 | break; |
| 455 | case NM_OC_RADIO_CARRIER: |
| 456 | trx = obj; |
| 457 | if (new_state->operational == 1 && |
Harald Welte | 9c913c4 | 2009-10-20 17:31:00 +0200 | [diff] [blame] | 458 | new_state->availability == NM_AVSTATE_OK) |
| 459 | abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr, |
| 460 | trx->nr, 0xff); |
| 461 | break; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 462 | case NM_OC_GPRS_NSE: |
| 463 | bts = container_of(obj, struct gsm_bts, gprs.nse); |
Harald Welte | 1c5fd6c | 2010-03-14 23:33:36 +0800 | [diff] [blame] | 464 | if (!bts->gprs.enabled) |
| 465 | break; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 466 | if (new_state->availability == 5) { |
| 467 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 468 | 0xff, 0xff, nanobts_attr_nse, |
| 469 | sizeof(nanobts_attr_nse)); |
| 470 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 471 | 0xff, 0xff); |
| 472 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 473 | 0xff, 0xff, NM_STATE_UNLOCKED); |
| 474 | } |
| 475 | break; |
| 476 | case NM_OC_GPRS_CELL: |
| 477 | bts = container_of(obj, struct gsm_bts, gprs.cell); |
Harald Welte | 1c5fd6c | 2010-03-14 23:33:36 +0800 | [diff] [blame] | 478 | if (!bts->gprs.enabled) |
| 479 | break; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 480 | if (new_state->availability == 5) { |
| 481 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 482 | 0, 0xff, nanobts_attr_cell, |
| 483 | sizeof(nanobts_attr_cell)); |
| 484 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 485 | 0, 0xff); |
| 486 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 487 | 0, 0xff, NM_STATE_UNLOCKED); |
| 488 | } |
| 489 | break; |
| 490 | case NM_OC_GPRS_NSVC: |
| 491 | nsvc = obj; |
| 492 | bts = nsvc->bts; |
Harald Welte | 1c5fd6c | 2010-03-14 23:33:36 +0800 | [diff] [blame] | 493 | if (!bts->gprs.enabled) |
| 494 | break; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 495 | /* We skip NSVC1 since we only use NSVC0 */ |
| 496 | if (nsvc->id == 1) |
| 497 | break; |
| 498 | if (new_state->availability == NM_AVSTATE_OFF_LINE) { |
| 499 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 500 | nsvc->id, 0xff, |
| 501 | nanobts_attr_nsvc0, |
| 502 | sizeof(nanobts_attr_nsvc0)); |
| 503 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 504 | nsvc->id, 0xff); |
| 505 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 506 | nsvc->id, 0xff, |
| 507 | NM_STATE_UNLOCKED); |
| 508 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 509 | default: |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 510 | break; |
| 511 | } |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* Callback function to be called every time we receive a 12.21 SW activated report */ |
| 516 | static int sw_activ_rep(struct msgb *mb) |
| 517 | { |
| 518 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Harald Welte | f509340 | 2009-10-19 21:47:54 +0200 | [diff] [blame] | 519 | struct gsm_bts *bts = mb->trx->bts; |
| 520 | struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, foh->obj_inst.trx_nr); |
| 521 | |
Harald Welte | 053ade5 | 2009-12-23 18:24:31 +0100 | [diff] [blame] | 522 | if (!trx) |
| 523 | return -EINVAL; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 524 | |
| 525 | switch (foh->obj_class) { |
Holger Hans Peter Freyther | 7622a99 | 2009-11-19 19:18:29 +0100 | [diff] [blame] | 526 | case NM_OC_BASEB_TRANSC: |
| 527 | abis_nm_chg_adm_state(trx->bts, foh->obj_class, |
| 528 | trx->bts->bts_nr, trx->nr, 0xff, |
| 529 | NM_STATE_UNLOCKED); |
| 530 | abis_nm_opstart(trx->bts, foh->obj_class, |
| 531 | trx->bts->bts_nr, trx->nr, 0xff); |
| 532 | /* TRX software is active, tell it to initiate RSL Link */ |
| 533 | abis_nm_ipaccess_rsl_connect(trx, 0, 3003, trx->rsl_tei); |
| 534 | break; |
Holger Hans Peter Freyther | 1c8b480 | 2009-11-11 11:54:24 +0100 | [diff] [blame] | 535 | case NM_OC_RADIO_CARRIER: { |
| 536 | /* |
| 537 | * Locking the radio carrier will make it go |
| 538 | * offline again and we would come here. The |
| 539 | * framework should determine that there was |
| 540 | * no change and avoid recursion. |
| 541 | * |
| 542 | * This code is here to make sure that on start |
| 543 | * a TRX remains locked. |
| 544 | */ |
Holger Hans Peter Freyther | 677bb2f | 2009-12-31 03:05:52 +0100 | [diff] [blame] | 545 | int rc_state = trx->nm_state.administrative; |
Holger Hans Peter Freyther | 7622a99 | 2009-11-19 19:18:29 +0100 | [diff] [blame] | 546 | /* Patch ARFCN into radio attribute */ |
| 547 | nanobts_attr_radio[5] &= 0xf0; |
| 548 | nanobts_attr_radio[5] |= trx->arfcn >> 8; |
| 549 | nanobts_attr_radio[6] = trx->arfcn & 0xff; |
| 550 | abis_nm_set_radio_attr(trx, nanobts_attr_radio, |
| 551 | sizeof(nanobts_attr_radio)); |
| 552 | abis_nm_chg_adm_state(trx->bts, foh->obj_class, |
| 553 | trx->bts->bts_nr, trx->nr, 0xff, |
Holger Hans Peter Freyther | 1c8b480 | 2009-11-11 11:54:24 +0100 | [diff] [blame] | 554 | rc_state); |
Holger Hans Peter Freyther | 7622a99 | 2009-11-19 19:18:29 +0100 | [diff] [blame] | 555 | abis_nm_opstart(trx->bts, foh->obj_class, trx->bts->bts_nr, |
| 556 | trx->nr, 0xff); |
| 557 | break; |
Holger Hans Peter Freyther | 1c8b480 | 2009-11-11 11:54:24 +0100 | [diff] [blame] | 558 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /* Callback function for NACK on the OML NM */ |
Harald Welte | 6a21c73 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 564 | static int oml_msg_nack(u_int8_t mt) |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 565 | { |
| 566 | if (mt == NM_MT_SET_BTS_ATTR_NACK) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 567 | LOGP(DNM, LOGL_FATAL, "Failed to set BTS attributes. That is fatal. " |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 568 | "Was the bts type and frequency properly specified?\n"); |
| 569 | exit(-1); |
| 570 | } |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | /* Callback function to be called every time we receive a signal from NM */ |
| 576 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 577 | void *handler_data, void *signal_data) |
| 578 | { |
Harald Welte | 6a21c73 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 579 | u_int8_t *msg_type; |
| 580 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 581 | switch (signal) { |
| 582 | case S_NM_SW_ACTIV_REP: |
| 583 | return sw_activ_rep(signal_data); |
| 584 | case S_NM_NACK: |
Harald Welte | 6a21c73 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 585 | msg_type = signal_data; |
| 586 | return oml_msg_nack(*msg_type); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 587 | default: |
| 588 | break; |
| 589 | } |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static void bootstrap_om_nanobts(struct gsm_bts *bts) |
| 594 | { |
| 595 | /* We don't do callback based bootstrapping, but event driven (see above) */ |
| 596 | } |
| 597 | |
| 598 | static void nm_reconfig_ts(struct gsm_bts_trx_ts *ts) |
| 599 | { |
| 600 | enum abis_nm_chan_comb ccomb = abis_nm_chcomb4pchan(ts->pchan); |
| 601 | struct gsm_e1_subslot *e1l = &ts->e1_link; |
| 602 | |
| 603 | abis_nm_set_channel_attr(ts, ccomb); |
| 604 | |
| 605 | if (is_ipaccess_bts(ts->trx->bts)) |
| 606 | return; |
| 607 | |
| 608 | switch (ts->pchan) { |
| 609 | case GSM_PCHAN_TCH_F: |
| 610 | case GSM_PCHAN_TCH_H: |
| 611 | abis_nm_conn_terr_traf(ts, e1l->e1_nr, e1l->e1_ts, |
| 612 | e1l->e1_ts_ss); |
| 613 | break; |
| 614 | default: |
| 615 | break; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | static void nm_reconfig_trx(struct gsm_bts_trx *trx) |
| 620 | { |
| 621 | struct gsm_e1_subslot *e1l = &trx->rsl_e1_link; |
| 622 | int i; |
| 623 | |
| 624 | patch_nm_tables(trx->bts); |
| 625 | |
| 626 | switch (trx->bts->type) { |
| 627 | case GSM_BTS_TYPE_BS11: |
| 628 | /* FIXME: discover this by fetching an attribute */ |
| 629 | #if 0 |
| 630 | trx->nominal_power = 15; /* 15dBm == 30mW PA configuration */ |
| 631 | #else |
| 632 | trx->nominal_power = 24; /* 24dBm == 250mW PA configuration */ |
| 633 | #endif |
| 634 | abis_nm_conn_terr_sign(trx, e1l->e1_nr, e1l->e1_ts, |
| 635 | e1l->e1_ts_ss); |
| 636 | abis_nm_establish_tei(trx->bts, trx->nr, e1l->e1_nr, |
| 637 | e1l->e1_ts, e1l->e1_ts_ss, trx->rsl_tei); |
| 638 | |
| 639 | /* Set Radio Attributes */ |
| 640 | if (trx == trx->bts->c0) |
| 641 | abis_nm_set_radio_attr(trx, bs11_attr_radio, |
| 642 | sizeof(bs11_attr_radio)); |
| 643 | else { |
| 644 | u_int8_t trx1_attr_radio[sizeof(bs11_attr_radio)]; |
| 645 | u_int8_t arfcn_low = trx->arfcn & 0xff; |
| 646 | u_int8_t arfcn_high = (trx->arfcn >> 8) & 0x0f; |
| 647 | memcpy(trx1_attr_radio, bs11_attr_radio, |
| 648 | sizeof(trx1_attr_radio)); |
| 649 | |
| 650 | /* patch ARFCN into TRX Attributes */ |
| 651 | trx1_attr_radio[2] &= 0xf0; |
| 652 | trx1_attr_radio[2] |= arfcn_high; |
| 653 | trx1_attr_radio[3] = arfcn_low; |
| 654 | |
| 655 | abis_nm_set_radio_attr(trx, trx1_attr_radio, |
| 656 | sizeof(trx1_attr_radio)); |
| 657 | } |
| 658 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 659 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 97be68a | 2009-10-19 21:47:31 +0200 | [diff] [blame] | 660 | switch (trx->bts->band) { |
| 661 | case GSM_BAND_850: |
| 662 | case GSM_BAND_900: |
| 663 | trx->nominal_power = 20; |
| 664 | break; |
| 665 | case GSM_BAND_1800: |
| 666 | case GSM_BAND_1900: |
| 667 | trx->nominal_power = 23; |
| 668 | break; |
Holger Hans Peter Freyther | 604326f | 2009-10-22 15:46:16 +0200 | [diff] [blame] | 669 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 670 | LOGP(DNM, LOGL_ERROR, "Unsupported nanoBTS GSM band %s\n", |
Harald Welte | 97be68a | 2009-10-19 21:47:31 +0200 | [diff] [blame] | 671 | gsm_band_name(trx->bts->band)); |
| 672 | break; |
| 673 | } |
| 674 | break; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 675 | default: |
| 676 | break; |
| 677 | } |
| 678 | |
| 679 | for (i = 0; i < TRX_NR_TS; i++) |
| 680 | nm_reconfig_ts(&trx->ts[i]); |
| 681 | } |
| 682 | |
| 683 | static void nm_reconfig_bts(struct gsm_bts *bts) |
| 684 | { |
| 685 | struct gsm_bts_trx *trx; |
| 686 | |
| 687 | switch (bts->type) { |
| 688 | case GSM_BTS_TYPE_BS11: |
Harald Welte | 238cd5a | 2009-12-14 17:49:52 +0100 | [diff] [blame] | 689 | patch_nm_tables(bts); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 690 | abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/ |
| 691 | abis_nm_set_bts_attr(bts, bs11_attr_bts, sizeof(bs11_attr_bts)); |
| 692 | abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */ |
| 693 | abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */ |
| 694 | break; |
| 695 | default: |
| 696 | break; |
| 697 | } |
| 698 | |
| 699 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 700 | nm_reconfig_trx(trx); |
| 701 | } |
| 702 | |
| 703 | static void bootstrap_om_bs11(struct gsm_bts *bts) |
| 704 | { |
| 705 | /* stop sending event reports */ |
| 706 | abis_nm_event_reports(bts, 0); |
| 707 | |
| 708 | /* begin DB transmission */ |
| 709 | abis_nm_bs11_db_transmission(bts, 1); |
| 710 | |
| 711 | /* end DB transmission */ |
| 712 | abis_nm_bs11_db_transmission(bts, 0); |
| 713 | |
| 714 | /* Reset BTS Site manager resource */ |
| 715 | abis_nm_bs11_reset_resource(bts); |
| 716 | |
| 717 | /* begin DB transmission */ |
| 718 | abis_nm_bs11_db_transmission(bts, 1); |
| 719 | |
| 720 | /* reconfigure BTS with all TRX and all TS */ |
| 721 | nm_reconfig_bts(bts); |
| 722 | |
| 723 | /* end DB transmission */ |
| 724 | abis_nm_bs11_db_transmission(bts, 0); |
| 725 | |
| 726 | /* Reset BTS Site manager resource */ |
| 727 | abis_nm_bs11_reset_resource(bts); |
| 728 | |
| 729 | /* restart sending event reports */ |
| 730 | abis_nm_event_reports(bts, 1); |
| 731 | } |
| 732 | |
| 733 | static void bootstrap_om(struct gsm_bts *bts) |
| 734 | { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 735 | LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for BTS %u\n", bts->nr); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 736 | |
| 737 | switch (bts->type) { |
| 738 | case GSM_BTS_TYPE_BS11: |
| 739 | bootstrap_om_bs11(bts); |
| 740 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 741 | case GSM_BTS_TYPE_NANOBTS: |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 742 | bootstrap_om_nanobts(bts); |
| 743 | break; |
| 744 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 745 | LOGP(DNM, LOGL_ERROR, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
| 749 | static int shutdown_om(struct gsm_bts *bts) |
| 750 | { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 751 | LOGP(DNM, LOGL_NOTICE, "shutting down OML for BTS %u\n", bts->nr); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 752 | |
| 753 | /* stop sending event reports */ |
| 754 | abis_nm_event_reports(bts, 0); |
| 755 | |
| 756 | /* begin DB transmission */ |
| 757 | abis_nm_bs11_db_transmission(bts, 1); |
| 758 | |
| 759 | /* end DB transmission */ |
| 760 | abis_nm_bs11_db_transmission(bts, 0); |
| 761 | |
| 762 | /* Reset BTS Site manager resource */ |
| 763 | abis_nm_bs11_reset_resource(bts); |
| 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | int bsc_shutdown_net(struct gsm_network *net) |
| 769 | { |
| 770 | struct gsm_bts *bts; |
| 771 | |
| 772 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 773 | int rc; |
| 774 | rc = shutdown_om(bts); |
| 775 | if (rc < 0) |
| 776 | return rc; |
| 777 | } |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 782 | /* set all system information types */ |
| 783 | static int set_system_infos(struct gsm_bts_trx *trx) |
| 784 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 785 | int i, rc; |
| 786 | u_int8_t si_tmp[23]; |
Harald Welte | 36e5a79 | 2009-12-21 23:12:19 +0100 | [diff] [blame] | 787 | struct gsm_bts *bts = trx->bts; |
| 788 | |
| 789 | bts->si_common.cell_sel_par.ms_txpwr_max_ccch = |
| 790 | ms_pwr_ctl_lvl(bts->band, bts->ms_max_power); |
| 791 | bts->si_common.cell_sel_par.neci = bts->network->neci; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 792 | |
| 793 | if (trx == trx->bts->c0) { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 794 | for (i = 1; i <= 4; i++) { |
| 795 | rc = gsm_generate_si(si_tmp, trx->bts, i); |
| 796 | if (rc < 0) |
| 797 | goto err_out; |
Harald Welte | d7f3648 | 2009-12-19 21:29:00 +0100 | [diff] [blame] | 798 | DEBUGP(DRR, "SI%2u: %s\n", i, hexdump(si_tmp, rc)); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 799 | rsl_bcch_info(trx, i, si_tmp, sizeof(si_tmp)); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 800 | } |
Harald Welte | 1c5fd6c | 2010-03-14 23:33:36 +0800 | [diff] [blame] | 801 | if (bts->gprs.enabled) { |
| 802 | i = 13; |
| 803 | rc = gsm_generate_si(si_tmp, trx->bts, RSL_SYSTEM_INFO_13); |
| 804 | if (rc < 0) |
| 805 | goto err_out; |
| 806 | DEBUGP(DRR, "SI%2u: %s\n", i, hexdump(si_tmp, rc)); |
| 807 | rsl_bcch_info(trx, RSL_SYSTEM_INFO_13, si_tmp, rc); |
| 808 | } |
Harald Welte | 28fc963 | 2009-12-21 17:02:32 +0100 | [diff] [blame] | 809 | } |
| 810 | |
Harald Welte | d7f3648 | 2009-12-19 21:29:00 +0100 | [diff] [blame] | 811 | i = 5; |
| 812 | rc = gsm_generate_si(si_tmp, trx->bts, RSL_SYSTEM_INFO_5); |
| 813 | if (rc < 0) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 814 | goto err_out; |
Harald Welte | d7f3648 | 2009-12-19 21:29:00 +0100 | [diff] [blame] | 815 | DEBUGP(DRR, "SI%2u: %s\n", i, hexdump(si_tmp, rc)); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 816 | rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si_tmp, rc); |
| 817 | |
Harald Welte | d7f3648 | 2009-12-19 21:29:00 +0100 | [diff] [blame] | 818 | i = 6; |
| 819 | rc = gsm_generate_si(si_tmp, trx->bts, RSL_SYSTEM_INFO_6); |
| 820 | if (rc < 0) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 821 | goto err_out; |
Harald Welte | d7f3648 | 2009-12-19 21:29:00 +0100 | [diff] [blame] | 822 | DEBUGP(DRR, "SI%2u: %s\n", i, hexdump(si_tmp, rc)); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 823 | rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si_tmp, rc); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 824 | |
| 825 | return 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 826 | err_out: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 827 | LOGP(DRR, LOGL_ERROR, "Cannot generate SI %u for BTS %u, most likely " |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 828 | "a problem with neighbor cell list generation\n", |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 829 | i, trx->bts->nr); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 830 | return rc; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* |
| 834 | * Patch the various SYSTEM INFORMATION tables to update |
| 835 | * the LAI |
| 836 | */ |
| 837 | static void patch_nm_tables(struct gsm_bts *bts) |
| 838 | { |
| 839 | u_int8_t arfcn_low = bts->c0->arfcn & 0xff; |
| 840 | u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f; |
| 841 | |
| 842 | /* patch ARFCN into BTS Attributes */ |
| 843 | bs11_attr_bts[69] &= 0xf0; |
| 844 | bs11_attr_bts[69] |= arfcn_high; |
| 845 | bs11_attr_bts[70] = arfcn_low; |
| 846 | nanobts_attr_bts[42] &= 0xf0; |
| 847 | nanobts_attr_bts[42] |= arfcn_high; |
| 848 | nanobts_attr_bts[43] = arfcn_low; |
| 849 | |
| 850 | /* patch ARFCN into TRX Attributes */ |
| 851 | bs11_attr_radio[2] &= 0xf0; |
| 852 | bs11_attr_radio[2] |= arfcn_high; |
| 853 | bs11_attr_radio[3] = arfcn_low; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 854 | |
| 855 | /* patch BSIC */ |
| 856 | bs11_attr_bts[1] = bts->bsic; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 857 | nanobts_attr_bts[sizeof(nanobts_attr_bts)-11] = bts->bsic; |
| 858 | |
| 859 | /* patch CGI */ |
| 860 | abis_nm_ipaccess_cgi(nanobts_attr_bts+sizeof(nanobts_attr_bts)-7, bts); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 861 | |
| 862 | /* patch the power reduction */ |
| 863 | bs11_attr_radio[5] = bts->c0->max_power_red / 2; |
| 864 | nanobts_attr_radio[1] = bts->c0->max_power_red / 2; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 865 | |
Harald Welte | 4a048c5 | 2010-03-22 11:48:36 +0800 | [diff] [blame] | 866 | /* patch NSEI */ |
| 867 | nanobts_attr_nse[3] = bts->gprs.nse.nsei >> 8; |
| 868 | nanobts_attr_nse[4] = bts->gprs.nse.nsei & 0xff; |
| 869 | |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 870 | /* patch NSVCI */ |
| 871 | nanobts_attr_nsvc0[3] = bts->gprs.nsvc[0].nsvci >> 8; |
| 872 | nanobts_attr_nsvc0[4] = bts->gprs.nsvc[0].nsvci & 0xff; |
| 873 | |
Harald Welte | 410575a | 2010-03-14 23:30:30 +0800 | [diff] [blame] | 874 | /* patch IP address as SGSN IP */ |
| 875 | *(u_int16_t *)(nanobts_attr_nsvc0+8) = |
| 876 | htons(bts->gprs.nsvc[0].remote_port); |
| 877 | *(u_int32_t *)(nanobts_attr_nsvc0+10) = |
| 878 | htonl(bts->gprs.nsvc[0].remote_ip); |
| 879 | *(u_int16_t *)(nanobts_attr_nsvc0+14) = |
| 880 | htons(bts->gprs.nsvc[0].local_port); |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 881 | |
| 882 | /* patch BVCI */ |
| 883 | nanobts_attr_cell[12] = bts->gprs.cell.bvci >> 8; |
| 884 | nanobts_attr_cell[13] = bts->gprs.cell.bvci & 0xff; |
| 885 | /* patch RAC */ |
| 886 | nanobts_attr_cell[3] = bts->gprs.rac; |
| 887 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 888 | } |
| 889 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 890 | static void bootstrap_rsl(struct gsm_bts_trx *trx) |
| 891 | { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 892 | LOGP(DRSL, LOGL_NOTICE, "bootstrapping RSL for BTS/TRX (%u/%u) " |
Harald Welte | 424873e | 2009-12-24 13:39:34 +0100 | [diff] [blame] | 893 | "on ARFCN %u using MCC=%u MNC=%u LAC=%u CID=%u BSIC=%u TSC=%u\n", |
| 894 | trx->bts->nr, trx->nr, trx->arfcn, bsc_gsmnet->country_code, |
| 895 | bsc_gsmnet->network_code, trx->bts->location_area_code, |
| 896 | trx->bts->cell_identity, trx->bts->bsic, trx->bts->tsc); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 897 | set_system_infos(trx); |
| 898 | } |
| 899 | |
| 900 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
| 901 | { |
| 902 | switch (event) { |
| 903 | case EVT_E1_TEI_UP: |
| 904 | switch (type) { |
| 905 | case E1INP_SIGN_OML: |
| 906 | bootstrap_om(trx->bts); |
| 907 | break; |
| 908 | case E1INP_SIGN_RSL: |
| 909 | bootstrap_rsl(trx); |
| 910 | break; |
| 911 | default: |
| 912 | break; |
| 913 | } |
| 914 | break; |
| 915 | case EVT_E1_TEI_DN: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 916 | LOGP(DMI, LOGL_NOTICE, "Lost some E1 TEI link\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 917 | /* FIXME: deal with TEI or L1 link loss */ |
| 918 | break; |
| 919 | default: |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | static int bootstrap_bts(struct gsm_bts *bts) |
| 925 | { |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 926 | switch (bts->band) { |
| 927 | case GSM_BAND_1800: |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 928 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 929 | LOGP(DNM, LOGL_ERROR, "GSM1800 channel must be between 512-885.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 930 | return -EINVAL; |
| 931 | } |
| 932 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 933 | case GSM_BAND_1900: |
| 934 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 935 | LOGP(DNM, LOGL_ERROR, "GSM1900 channel must be between 512-810.\n"); |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 936 | return -EINVAL; |
| 937 | } |
| 938 | break; |
| 939 | case GSM_BAND_900: |
Holger Hans Peter Freyther | 2ba2b33 | 2010-02-09 15:44:14 +0100 | [diff] [blame] | 940 | if (bts->c0->arfcn < 1 || |
| 941 | (bts->c0->arfcn > 124 && bts->c0->arfcn < 955) || |
| 942 | bts->c0->arfcn > 1023) { |
| 943 | LOGP(DNM, LOGL_ERROR, "GSM900 channel must be between 1-124, 955-1023.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 944 | return -EINVAL; |
| 945 | } |
| 946 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 947 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 948 | LOGP(DNM, LOGL_ERROR, "Unsupported frequency band.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 949 | return -EINVAL; |
| 950 | } |
| 951 | |
Harald Welte | 395cb6b | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 952 | if (bts->network->auth_policy == GSM_AUTH_POLICY_ACCEPT_ALL && |
Harald Welte | 8c973ba | 2009-12-21 23:08:18 +0100 | [diff] [blame] | 953 | !bts->si_common.rach_control.cell_bar) |
Harald Welte | 36ab545 | 2009-12-21 23:36:45 +0100 | [diff] [blame] | 954 | LOGP(DNM, LOGL_ERROR, "\nWARNING: You are running an 'accept-all' " |
Harald Welte | 395cb6b | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 955 | "network on a BTS that is not barred. This " |
| 956 | "configuration is likely to interfere with production " |
| 957 | "GSM networks and should only be used in a RF " |
| 958 | "shielded environment such as a faraday cage!\n\n"); |
| 959 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 960 | /* Control Channel Description */ |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 961 | bts->si_common.chan_desc.att = 1; |
| 962 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C; |
| 963 | bts->si_common.chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 964 | /* T3212 is set from vty/config */ |
| 965 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 966 | /* some defaults for our system information */ |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 967 | bts->si_common.cell_options.radio_link_timeout = 2; /* 12 */ |
| 968 | bts->si_common.cell_options.dtx = 2; /* MS shall not use upplink DTX */ |
| 969 | bts->si_common.cell_options.pwrc = 0; /* PWRC not set */ |
| 970 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 971 | bts->si_common.cell_sel_par.acs = 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 972 | |
| 973 | bts->si_common.ncc_permitted = 0xff; |
| 974 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 975 | paging_init(bts); |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, int, void *), |
| 981 | const char *config_file) |
| 982 | { |
| 983 | struct gsm_bts *bts; |
| 984 | int rc; |
| 985 | |
| 986 | /* initialize our data structures */ |
| 987 | bsc_gsmnet = gsm_network_init(1, 1, mncc_recv); |
| 988 | if (!bsc_gsmnet) |
| 989 | return -ENOMEM; |
| 990 | |
| 991 | bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 992 | bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 993 | |
| 994 | telnet_init(bsc_gsmnet, 4242); |
| 995 | rc = vty_read_config_file(config_file); |
| 996 | if (rc < 0) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 997 | LOGP(DNM, LOGL_FATAL, "Failed to parse the config file: '%s'\n", config_file); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 998 | return rc; |
| 999 | } |
| 1000 | |
| 1001 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
| 1002 | |
| 1003 | llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) { |
| 1004 | bootstrap_bts(bts); |
| 1005 | if (!is_ipaccess_bts(bts)) |
| 1006 | rc = e1_reconfig_bts(bts); |
| 1007 | |
| 1008 | if (rc < 0) |
| 1009 | exit (1); |
| 1010 | } |
| 1011 | |
| 1012 | /* initialize nanoBTS support omce */ |
| 1013 | rc = ipaccess_setup(bsc_gsmnet); |
| 1014 | |
| 1015 | return 0; |
| 1016 | } |