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