Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* A hackish minimal BSC (+MSC +HLR) implementation */ |
| 2 | |
| 3 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | 219518d | 2009-01-02 22:04:43 +0000 | [diff] [blame] | 4 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 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 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 23 | #include <unistd.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdarg.h> |
| 27 | #include <time.h> |
| 28 | #include <string.h> |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 29 | #include <errno.h> |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 30 | #include <signal.h> |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 31 | #include <fcntl.h> |
| 32 | #include <sys/stat.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 33 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 34 | #define _GNU_SOURCE |
| 35 | #include <getopt.h> |
| 36 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 37 | #include <openbsc/db.h> |
| 38 | #include <openbsc/timer.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 39 | #include <openbsc/gsm_data.h> |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 40 | #include <openbsc/gsm_04_08.h> |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 41 | #include <openbsc/select.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 42 | #include <openbsc/abis_rsl.h> |
| 43 | #include <openbsc/abis_nm.h> |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 44 | #include <openbsc/debug.h> |
Holger Freyther | 5677ae3 | 2008-12-27 09:41:03 +0000 | [diff] [blame] | 45 | #include <openbsc/misdn.h> |
Holger Freyther | 219518d | 2009-01-02 22:04:43 +0000 | [diff] [blame] | 46 | #include <openbsc/telnet_interface.h> |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 47 | #include <openbsc/paging.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 48 | #include <openbsc/e1_input.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 49 | |
| 50 | /* global pointer to the gsm network data structure */ |
| 51 | static struct gsm_network *gsmnet; |
| 52 | |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 53 | /* MCC and MNC for the Location Area Identifier */ |
| 54 | static int MCC = 1; |
| 55 | static int MNC = 1; |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 56 | static int ARFCN = HARDCODED_ARFCN; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 57 | static enum gsm_bts_type BTS_TYPE = GSM_BTS_TYPE_BS11; |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 58 | static const char *database_name = "hlr.sqlite3"; |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 59 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 60 | /* The following definitions are for OM and NM packets that we cannot yet |
| 61 | * generate by code but we just pass on */ |
| 62 | |
| 63 | // BTS Site Manager, SET ATTRIBUTES |
| 64 | |
| 65 | /* |
| 66 | Object Class: BTS Site Manager |
| 67 | Instance 1: FF |
| 68 | Instance 2: FF |
| 69 | Instance 3: FF |
| 70 | SET ATTRIBUTES |
| 71 | sAbisExternalTime: 2007/09/08 14:36:11 |
| 72 | omLAPDRelTimer: 30sec |
| 73 | shortLAPDIntTimer: 5sec |
| 74 | emergencyTimer1: 10 minutes |
| 75 | emergencyTimer2: 0 minutes |
| 76 | */ |
| 77 | |
| 78 | unsigned char msg_1[] = |
| 79 | { |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 80 | 0xD0, 0x00, 0xFF, 0xFF, 0xFF, |
| 81 | NM_ATT_BS11_ABIS_EXT_TIME, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24, 0x0B, 0xCE, |
| 82 | 0x02, 0x00, 0x1E, |
| 83 | 0xE8, 0x01, 0x05, |
| 84 | 0x42, 0x02, 0x00, 0x0A, |
| 85 | 0x44, 0x02, 0x00, 0x00 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | // BTS, SET BTS ATTRIBUTES |
| 89 | |
| 90 | /* |
| 91 | Object Class: BTS |
| 92 | BTS relat. Number: 0 |
| 93 | Instance 2: FF |
| 94 | Instance 3: FF |
| 95 | SET BTS ATTRIBUTES |
| 96 | bsIdentityCode / BSIC: |
| 97 | PLMN_colour_code: 7h |
| 98 | BS_colour_code: 7h |
| 99 | BTS Air Timer T3105: 4 ,unit 10 ms |
| 100 | btsIsHopping: FALSE |
Harald Welte | 8328229 | 2009-02-01 16:22:19 +0000 | [diff] [blame] | 101 | periodCCCHLoadIndication: 1sec |
Holger Freyther | 3b91043 | 2009-02-11 00:43:48 +0000 | [diff] [blame] | 102 | thresholdCCCHLoadIndication: 0% |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 103 | cellAllocationNumber: 00h = GSM 900 |
| 104 | enableInterferenceClass: 00h = Disabled |
| 105 | fACCHQual: 6 (FACCH stealing flags minus 1) |
| 106 | intaveParameter: 31 SACCH multiframes |
| 107 | interferenceLevelBoundaries: |
| 108 | Interference Boundary 1: 0Ah |
| 109 | Interference Boundary 2: 0Fh |
| 110 | Interference Boundary 3: 14h |
| 111 | Interference Boundary 4: 19h |
| 112 | Interference Boundary 5: 1Eh |
| 113 | mSTxPwrMax: 11 |
| 114 | GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm |
| 115 | DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm |
| 116 | PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm |
| 117 | 30=33dBm, 31=32dBm |
| 118 | ny1: |
| 119 | Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20 |
| 120 | powerOutputThresholds: |
| 121 | Out Power Fault Threshold: -10 dB |
| 122 | Red Out Power Threshold: - 6 dB |
| 123 | Excessive Out Power Threshold: 5 dB |
| 124 | rACHBusyThreshold: -127 dBm |
| 125 | rACHLoadAveragingSlots: 250 ,number of RACH burst periods |
| 126 | rfResourceIndicationPeriod: 125 SACCH multiframes |
| 127 | T200: |
| 128 | SDCCH: 044 in 5 ms |
| 129 | FACCH/Full rate: 031 in 5 ms |
| 130 | FACCH/Half rate: 041 in 5 ms |
| 131 | SACCH with TCH SAPI0: 090 in 10 ms |
| 132 | SACCH with SDCCH: 090 in 10 ms |
| 133 | SDCCH with SAPI3: 090 in 5 ms |
| 134 | SACCH with TCH SAPI3: 135 in 10 ms |
| 135 | tSync: 9000 units of 10 msec |
| 136 | tTrau: 9000 units of 10 msec |
| 137 | enableUmLoopTest: 00h = disabled |
| 138 | enableExcessiveDistance: 00h = Disabled |
| 139 | excessiveDistance: 64km |
| 140 | hoppingMode: 00h = baseband hopping |
| 141 | cellType: 00h = Standard Cell |
| 142 | BCCH ARFCN / bCCHFrequency: 1 |
| 143 | */ |
| 144 | |
| 145 | unsigned char msg_2[] = |
| 146 | { |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 147 | 0x41, 0x01, 0x00, 0xFF, 0xFF, |
| 148 | NM_ATT_BSIC, 0x3F, |
| 149 | NM_ATT_BTS_AIR_TIMER, 0x04, |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 150 | NM_ATT_BS11_BTSLS_HOPPING, 0x00, |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 151 | NM_ATT_CCCH_L_I_P, 0x01, |
| 152 | NM_ATT_CCCH_L_T, 0x00, |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 153 | NM_ATT_BS11_CELL_ALLOC_NR, 0x00, |
| 154 | NM_ATT_BS11_ENA_INTERF_CLASS, 0x00, |
| 155 | NM_ATT_BS11_FACCH_QUAL, 0x06, |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 156 | NM_ATT_INTAVE_PARAM, 0x1F, |
| 157 | NM_ATT_INTERF_BOUND, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B, |
| 158 | NM_ATT_CCCH_L_T, 0x23, |
| 159 | NM_ATT_GSM_TIME, 0x28, 0x00, |
| 160 | NM_ATT_ADM_STATE, 0x03, |
| 161 | NM_ATT_RACH_B_THRESH, 0x7F, |
| 162 | NM_ATT_LDAVG_SLOTS, 0x00, 0xFA, |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 163 | NM_ATT_BS11_RF_RES_IND_PER, 0x7D, |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 164 | NM_ATT_T200, 0x2C, 0x1F, 0x29, 0x5A, 0x5A, 0x5A, 0x87, |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 165 | NM_ATT_BS11_TSYNC, 0x23, 0x28, |
| 166 | NM_ATT_BS11_TTRAU, 0x23, 0x28, |
| 167 | NM_ATT_TEST_DUR, 0x01, 0x00, |
| 168 | NM_ATT_OUTST_ALARM, 0x01, 0x00, |
| 169 | NM_ATT_BS11_EXCESSIVE_DISTANCE, 0x01, 0x40, |
| 170 | NM_ATT_BS11_HOPPING_MODE, 0x01, 0x00, |
| 171 | NM_ATT_BS11_PLL, 0x01, 0x00, |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 172 | NM_ATT_BCCH_ARFCN, 0x00, HARDCODED_ARFCN/*0x01*/, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | // Handover Recognition, SET ATTRIBUTES |
| 176 | |
| 177 | /* |
| 178 | Illegal Contents GSM Formatted O&M Msg |
| 179 | Object Class: Handover Recognition |
| 180 | BTS relat. Number: 0 |
| 181 | Instance 2: FF |
| 182 | Instance 3: FF |
| 183 | SET ATTRIBUTES |
| 184 | enableDelayPowerBudgetHO: 00h = Disabled |
| 185 | enableDistanceHO: 00h = Disabled |
| 186 | enableInternalInterCellHandover: 00h = Disabled |
| 187 | enableInternalIntraCellHandover: 00h = Disabled |
| 188 | enablePowerBudgetHO: 00h = Disabled |
| 189 | enableRXLEVHO: 00h = Disabled |
| 190 | enableRXQUALHO: 00h = Disabled |
| 191 | hoAveragingDistance: 8 SACCH multiframes |
| 192 | hoAveragingLev: |
| 193 | A_LEV_HO: 8 SACCH multiframes |
| 194 | W_LEV_HO: 1 SACCH multiframes |
| 195 | hoAveragingPowerBudget: 16 SACCH multiframes |
| 196 | hoAveragingQual: |
| 197 | A_QUAL_HO: 8 SACCH multiframes |
| 198 | W_QUAL_HO: 2 SACCH multiframes |
| 199 | hoLowerThresholdLevDL: (10 - 110) dBm |
| 200 | hoLowerThresholdLevUL: (5 - 110) dBm |
| 201 | hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8% |
| 202 | hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8% |
| 203 | hoThresholdLevDLintra : (20 - 110) dBm |
| 204 | hoThresholdLevULintra: (20 - 110) dBm |
| 205 | hoThresholdMsRangeMax: 20 km |
| 206 | nCell: 06h |
| 207 | timerHORequest: 3 ,unit 2 SACCH multiframes |
| 208 | */ |
| 209 | |
| 210 | unsigned char msg_3[] = |
| 211 | { |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 212 | 0xD0, 0xA1, 0x00, 0xFF, 0xFF, |
| 213 | 0xD0, 0x00, |
| 214 | 0x64, 0x00, |
| 215 | 0x67, 0x00, |
| 216 | 0x68, 0x00, |
| 217 | 0x6A, 0x00, |
| 218 | 0x6C, 0x00, |
| 219 | 0x6D, 0x00, |
| 220 | 0x6F, 0x08, |
| 221 | 0x70, 0x08, 0x01, |
| 222 | 0x71, 0x10, 0x10, 0x10, |
| 223 | 0x72, 0x08, 0x02, |
| 224 | 0x73, 0x0A, |
| 225 | 0x74, 0x05, |
| 226 | 0x75, 0x06, |
| 227 | 0x76, 0x06, |
| 228 | 0x78, 0x14, |
| 229 | 0x79, 0x14, |
| 230 | 0x7A, 0x14, |
| 231 | 0x7D, 0x06, |
| 232 | 0x92, 0x03, 0x20, 0x01, 0x00, |
| 233 | 0x45, 0x01, 0x00, |
| 234 | 0x48, 0x01, 0x00, |
| 235 | 0x5A, 0x01, 0x00, |
| 236 | 0x5B, 0x01, 0x05, |
| 237 | 0x5E, 0x01, 0x1A, |
| 238 | 0x5F, 0x01, 0x20, |
| 239 | 0x9D, 0x01, 0x00, |
| 240 | 0x47, 0x01, 0x00, |
| 241 | 0x5C, 0x01, 0x64, |
| 242 | 0x5D, 0x01, 0x1E, |
| 243 | 0x97, 0x01, 0x20, |
| 244 | 0xF7, 0x01, 0x3C, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | // Power Control, SET ATTRIBUTES |
| 248 | |
| 249 | /* |
| 250 | Object Class: Power Control |
| 251 | BTS relat. Number: 0 |
| 252 | Instance 2: FF |
| 253 | Instance 3: FF |
| 254 | SET ATTRIBUTES |
| 255 | enableMsPowerControl: 00h = Disabled |
| 256 | enablePowerControlRLFW: 00h = Disabled |
| 257 | pcAveragingLev: |
| 258 | A_LEV_PC: 4 SACCH multiframes |
| 259 | W_LEV_PC: 1 SACCH multiframes |
| 260 | pcAveragingQual: |
| 261 | A_QUAL_PC: 4 SACCH multiframes |
| 262 | W_QUAL_PC: 2 SACCH multiframes |
| 263 | pcLowerThresholdLevDL: 0Fh |
| 264 | pcLowerThresholdLevUL: 0Ah |
| 265 | pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4% |
| 266 | pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4% |
| 267 | pcRLFThreshold: 0Ch |
| 268 | pcUpperThresholdLevDL: 14h |
| 269 | pcUpperThresholdLevUL: 0Fh |
| 270 | pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2% |
| 271 | pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2% |
| 272 | powerConfirm: 2 ,unit 2 SACCH multiframes |
| 273 | powerControlInterval: 2 ,unit 2 SACCH multiframes |
| 274 | powerIncrStepSize: 02h = 4 dB |
| 275 | powerRedStepSize: 01h = 2 dB |
| 276 | radioLinkTimeoutBs: 64 SACCH multiframes |
| 277 | enableBSPowerControl: 00h = disabled |
| 278 | */ |
| 279 | |
| 280 | unsigned char msg_4[] = |
| 281 | { |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 282 | 0xD0, 0xA2, 0x00, 0xFF, 0xFF, |
| 283 | NM_ATT_BS11_ENA_MS_PWR_CTRL, 0x00, |
| 284 | NM_ATT_BS11_ENA_PWR_CTRL_RLFW, 0x00, |
| 285 | 0x7E, 0x04, 0x01, |
| 286 | 0x7F, 0x04, 0x02, |
| 287 | 0x80, 0x0F, |
| 288 | 0x81, 0x0A, |
| 289 | 0x82, 0x05, |
| 290 | 0x83, 0x05, |
| 291 | 0x84, 0x0C, |
| 292 | 0x85, 0x14, |
| 293 | 0x86, 0x0F, |
| 294 | 0x87, 0x04, |
| 295 | 0x88, 0x04, |
| 296 | 0x89, 0x02, |
| 297 | 0x8A, 0x02, |
| 298 | 0x8B, 0x02, |
| 299 | 0x8C, 0x01, |
| 300 | 0x8D, 0x40, |
| 301 | 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | |
| 305 | // Transceiver, SET TRX ATTRIBUTES (TRX 0) |
| 306 | |
| 307 | /* |
| 308 | Object Class: Transceiver |
| 309 | BTS relat. Number: 0 |
| 310 | Tranceiver number: 0 |
| 311 | Instance 3: FF |
| 312 | SET TRX ATTRIBUTES |
| 313 | aRFCNList (HEX): 0001 |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 314 | txPwrMaxReduction: 00h = 30dB |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 315 | radioMeasGran: 254 SACCH multiframes |
| 316 | radioMeasRep: 01h = enabled |
| 317 | memberOfEmergencyConfig: 01h = TRUE |
| 318 | trxArea: 00h = TRX doesn't belong to a concentric cell |
| 319 | */ |
| 320 | |
| 321 | unsigned char msg_6[] = |
| 322 | { |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 323 | 0x44, 0x02, 0x00, 0x00, 0xFF, |
| 324 | NM_ATT_ARFCN_LIST, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/, |
Harald Welte | 311d0cf | 2009-02-17 17:45:59 +0000 | [diff] [blame] | 325 | NM_ATT_RF_MAXPOWR_R, 0x00, |
Harald Welte | cd99387 | 2009-02-15 16:16:28 +0000 | [diff] [blame] | 326 | NM_ATT_BS11_RADIO_MEAS_GRAN, 0x01, 0xFE, |
| 327 | NM_ATT_BS11_RADIO_MEAS_REP, 0x01, 0x01, |
| 328 | NM_ATT_BS11_EMRG_CFG_MEMBER, 0x01, 0x01, |
| 329 | NM_ATT_BS11_TRX_AREA, 0x01, 0x00, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 332 | static unsigned char nanobts_attr_bts[] = { |
| 333 | NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, |
| 334 | NM_ATT_INTAVE_PARAM, 0x06, |
| 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, |
Harald Welte | 311d0cf | 2009-02-17 17:45:59 +0000 | [diff] [blame] | 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 */ |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 341 | NM_ATT_RACH_B_THRESH, 0x0a, |
| 342 | NM_ATT_LDAVG_SLOTS, 0x03, 0xe8, |
| 343 | NM_ATT_BTS_AIR_TIMER, 0x80, |
| 344 | NM_ATT_NY1, 0x0a, |
| 345 | NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 346 | NM_ATT_BSIC, 0x20, |
| 347 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 348 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 349 | static unsigned char nanobts_attr_radio[] = { |
Harald Welte | 311d0cf | 2009-02-17 17:45:59 +0000 | [diff] [blame] | 350 | NM_ATT_RF_MAXPOWR_R, 0x0c, |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 351 | NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 352 | }; |
| 353 | |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 354 | static unsigned char nanobts_attr_e0[] = { |
| 355 | 0x85, 0x00, |
| 356 | 0x81, 0x0b, 0xbb, /* TCP PORT for RSL */ |
| 357 | }; |
| 358 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 359 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 360 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 361 | { |
| 362 | struct gsm_bts *bts; |
| 363 | struct gsm_bts_trx *trx; |
| 364 | struct gsm_bts_trx_ts *ts; |
| 365 | |
| 366 | /* This is currently only required on nanoBTS */ |
| 367 | |
| 368 | switch (evt) { |
| 369 | case EVT_STATECHG_OPER: |
| 370 | switch (obj_class) { |
| 371 | case NM_OC_SITE_MANAGER: |
| 372 | bts = container_of(obj, struct gsm_bts, site_mgr); |
| 373 | if (old_state->operational != 2 && new_state->operational == 2) { |
| 374 | abis_nm_opstart(bts, NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 375 | } |
| 376 | break; |
| 377 | case NM_OC_BTS: |
| 378 | bts = obj; |
| 379 | if (new_state->availability == 5) { |
| 380 | abis_nm_set_bts_attr(bts, nanobts_attr_bts, |
| 381 | sizeof(nanobts_attr_bts)); |
| 382 | abis_nm_opstart(bts, NM_OC_BTS, |
| 383 | bts->nr, 0xff, 0xff); |
| 384 | abis_nm_chg_adm_state(bts, NM_OC_BTS, |
| 385 | bts->nr, 0xff, 0xff, |
| 386 | NM_STATE_UNLOCKED); |
| 387 | } |
| 388 | break; |
| 389 | case NM_OC_RADIO_CARRIER: |
| 390 | trx = obj; |
| 391 | if (new_state->availability == 3) { |
| 392 | abis_nm_set_radio_attr(trx, nanobts_attr_radio, |
| 393 | sizeof(nanobts_attr_radio)); |
| 394 | abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER, |
| 395 | trx->bts->nr, trx->nr, 0xff); |
| 396 | abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER, |
| 397 | trx->bts->nr, trx->nr, 0xff, |
| 398 | NM_STATE_UNLOCKED); |
| 399 | } |
| 400 | break; |
| 401 | case NM_OC_CHANNEL: |
| 402 | ts = obj; |
| 403 | trx = ts->trx; |
| 404 | if (new_state->availability == 5) { |
| 405 | if (ts->nr == 0 && trx == trx->bts->c0) |
Harald Welte | e1bd241 | 2009-02-15 14:40:09 +0000 | [diff] [blame] | 406 | abis_nm_set_channel_attr(ts, NM_CHANC_BCCH_CBCH); |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 407 | else |
| 408 | abis_nm_set_channel_attr(ts, NM_CHANC_TCHFull); |
| 409 | abis_nm_opstart(trx->bts, NM_OC_CHANNEL, |
| 410 | trx->bts->nr, trx->nr, ts->nr); |
| 411 | abis_nm_chg_adm_state(trx->bts, NM_OC_CHANNEL, |
| 412 | trx->bts->nr, trx->nr, ts->nr, |
| 413 | NM_STATE_UNLOCKED); |
| 414 | } |
| 415 | break; |
| 416 | case NM_OC_BASEB_TRANSC: |
| 417 | trx = container_of(obj, struct gsm_bts_trx, bb_transc); |
| 418 | if (new_state->availability == 5) { |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 419 | abis_nm_ipaccess_msg(trx->bts, 0xe0, NM_OC_BASEB_TRANSC, |
| 420 | trx->bts->nr, trx->nr, 0xff, |
| 421 | nanobts_attr_e0, sizeof(nanobts_attr_e0)); |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 422 | abis_nm_opstart(trx->bts, NM_OC_BASEB_TRANSC, |
| 423 | trx->bts->nr, trx->nr, 0xff); |
| 424 | abis_nm_chg_adm_state(trx->bts, NM_OC_BASEB_TRANSC, |
| 425 | trx->bts->nr, trx->nr, 0xff, |
| 426 | NM_STATE_UNLOCKED); |
| 427 | } |
| 428 | break; |
| 429 | } |
| 430 | break; |
| 431 | } |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | static void bootstrap_om_nanobts(struct gsm_bts *bts) |
| 436 | { |
Harald Welte | e1bd241 | 2009-02-15 14:40:09 +0000 | [diff] [blame] | 437 | /* We don't do callback based bootstrapping, but event driven (see above) */ |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static void bootstrap_om_bs11(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 441 | { |
| 442 | struct gsm_bts_trx *trx = &bts->trx[0]; |
| 443 | |
| 444 | /* stop sending event reports */ |
| 445 | abis_nm_event_reports(bts, 0); |
| 446 | |
| 447 | /* begin DB transmission */ |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 448 | abis_nm_bs11_db_transmission(bts, 1); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 449 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 450 | /* end DB transmission */ |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 451 | abis_nm_bs11_db_transmission(bts, 0); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 452 | |
| 453 | /* Reset BTS Site manager resource */ |
Harald Welte | 7837489 | 2009-01-18 19:09:22 +0000 | [diff] [blame] | 454 | abis_nm_bs11_reset_resource(bts); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 455 | |
| 456 | /* begin DB transmission */ |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 457 | abis_nm_bs11_db_transmission(bts, 1); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 458 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 459 | abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/ |
| 460 | abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */ |
| 461 | abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */ |
| 462 | abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */ |
| 463 | |
| 464 | /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */ |
| 465 | abis_nm_conn_terr_sign(trx, 0, 1, 0xff); |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 466 | set_ts_e1link(&trx->ts[0], 0, 1, 0xff); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 467 | abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */ |
| 468 | |
| 469 | /* Use TEI 1 for signalling */ |
| 470 | abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01); |
| 471 | abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH); |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 472 | |
| 473 | #ifdef HAVE_TRX1 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 474 | /* TRX 1 */ |
| 475 | abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff); |
| 476 | /* FIXME: TRX ATTRIBUTE */ |
| 477 | abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02); |
| 478 | #endif |
| 479 | |
| 480 | /* SET CHANNEL ATTRIBUTE TS1 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 481 | abis_nm_set_channel_attr(&trx->ts[1], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 482 | /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 483 | set_ts_e1link(&trx->ts[1], 0, 2, 1); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 484 | abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1); |
| 485 | |
| 486 | /* SET CHANNEL ATTRIBUTE TS2 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 487 | abis_nm_set_channel_attr(&trx->ts[2], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 488 | /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 489 | set_ts_e1link(&trx->ts[2], 0, 2, 2); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 490 | abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2); |
| 491 | |
| 492 | /* SET CHANNEL ATTRIBUTE TS3 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 493 | abis_nm_set_channel_attr(&trx->ts[3], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 494 | /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 495 | set_ts_e1link(&trx->ts[3], 0, 2, 3); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 496 | abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3); |
| 497 | |
| 498 | /* SET CHANNEL ATTRIBUTE TS4 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 499 | abis_nm_set_channel_attr(&trx->ts[4], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 500 | /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 501 | set_ts_e1link(&trx->ts[4], 0, 3, 0); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 502 | abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0); |
| 503 | |
| 504 | /* SET CHANNEL ATTRIBUTE TS5 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 505 | abis_nm_set_channel_attr(&trx->ts[5], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 506 | /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 507 | set_ts_e1link(&trx->ts[5], 0, 3, 1); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 508 | abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1); |
| 509 | |
| 510 | /* SET CHANNEL ATTRIBUTE TS6 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 511 | abis_nm_set_channel_attr(&trx->ts[6], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 512 | /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 513 | set_ts_e1link(&trx->ts[6], 0, 3, 2); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 514 | abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2); |
| 515 | |
| 516 | /* SET CHANNEL ATTRIBUTE TS7 */ |
Harald Welte | 23887b6 | 2009-02-18 03:37:20 +0000 | [diff] [blame] | 517 | abis_nm_set_channel_attr(&trx->ts[7], NM_CHANC_TCHFull); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 518 | /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */ |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 519 | set_ts_e1link(&trx->ts[7], 0, 3, 3); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 520 | abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3); |
| 521 | |
| 522 | /* end DB transmission */ |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 523 | abis_nm_bs11_db_transmission(bts, 0); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 524 | |
| 525 | /* Reset BTS Site manager resource */ |
Harald Welte | 7837489 | 2009-01-18 19:09:22 +0000 | [diff] [blame] | 526 | abis_nm_bs11_reset_resource(bts); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 527 | |
| 528 | /* restart sending event reports */ |
| 529 | abis_nm_event_reports(bts, 1); |
| 530 | } |
| 531 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 532 | static void bootstrap_om(struct gsm_bts *bts) |
| 533 | { |
| 534 | fprintf(stdout, "bootstrapping OML\n"); |
| 535 | |
| 536 | switch (bts->type) { |
| 537 | case GSM_BTS_TYPE_BS11: |
| 538 | bootstrap_om_bs11(bts); |
| 539 | break; |
| 540 | case GSM_BTS_TYPE_NANOBTS_900: |
| 541 | case GSM_BTS_TYPE_NANOBTS_1800: |
| 542 | bootstrap_om_nanobts(bts); |
| 543 | break; |
| 544 | default: |
| 545 | fprintf(stderr, "Unable to bootstrap OML: Unknown BTS type %d\n", bts->type); |
| 546 | } |
| 547 | } |
| 548 | |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 549 | static int shutdown_om(struct gsm_bts *bts) |
| 550 | { |
| 551 | /* stop sending event reports */ |
| 552 | abis_nm_event_reports(bts, 0); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 553 | |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 554 | /* begin DB transmission */ |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 555 | abis_nm_bs11_db_transmission(bts, 1); |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 556 | |
| 557 | /* end DB transmission */ |
Harald Welte | 05188ee | 2009-01-18 11:39:08 +0000 | [diff] [blame] | 558 | abis_nm_bs11_db_transmission(bts, 0); |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 559 | |
| 560 | /* Reset BTS Site manager resource */ |
Harald Welte | 7837489 | 2009-01-18 19:09:22 +0000 | [diff] [blame] | 561 | abis_nm_bs11_reset_resource(bts); |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int shutdown_net(struct gsm_network *net) |
| 567 | { |
| 568 | int i; |
| 569 | for (i = 0; i < net->num_bts; i++) { |
| 570 | int rc; |
| 571 | rc = shutdown_om(&net->bts[i]); |
| 572 | if (rc < 0) |
| 573 | return rc; |
| 574 | } |
| 575 | |
| 576 | return 0; |
| 577 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 578 | |
| 579 | struct bcch_info { |
| 580 | u_int8_t type; |
| 581 | u_int8_t len; |
| 582 | const u_int8_t *data; |
| 583 | }; |
| 584 | |
| 585 | /* |
| 586 | SYSTEM INFORMATION TYPE 1 |
| 587 | Cell channel description |
| 588 | Format-ID bit map 0 |
| 589 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 |
| 590 | RACH Control Parameters |
| 591 | maximum 7 retransmissions |
| 592 | 8 slots used to spread transmission |
| 593 | cell not barred for access |
| 594 | call reestablishment not allowed |
| 595 | Access Control Class = 0000 |
| 596 | */ |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 597 | static u_int8_t si1[] = { |
Holger Freyther | 4d50547 | 2008-12-28 16:32:42 +0000 | [diff] [blame] | 598 | /* header */0x55, 0x06, 0x19, |
| 599 | /* ccdesc */0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 600 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/, |
| 601 | /* rach */0xD5, 0x00, 0x00, |
| 602 | /* s1 reset*/0x2B |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 603 | }; |
| 604 | |
| 605 | /* |
| 606 | SYSTEM INFORMATION TYPE 2 |
| 607 | Neighbour Cells Description |
| 608 | EXT-IND: Carries the complete BA |
| 609 | BA-IND = 0 |
| 610 | Format-ID bit map 0 |
| 611 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 612 | NCC permitted (NCC) = FF |
| 613 | RACH Control Parameters |
| 614 | maximum 7 retransmissions |
| 615 | 8 slots used to spread transmission |
| 616 | cell not barred for access |
| 617 | call reestablishment not allowed |
| 618 | Access Control Class = 0000 |
| 619 | */ |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 620 | static u_int8_t si2[] = { |
Holger Freyther | 4d50547 | 2008-12-28 16:32:42 +0000 | [diff] [blame] | 621 | /* header */0x59, 0x06, 0x1A, |
| 622 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 623 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 624 | /* ncc */0xFF, |
| 625 | /* rach*/0xD5, 0x00, 0x00 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 626 | }; |
| 627 | |
| 628 | /* |
| 629 | SYSTEM INFORMATION TYPE 3 |
| 630 | Cell identity = 00001 (1h) |
| 631 | Location area identification |
| 632 | Mobile Country Code (MCC): 001 |
| 633 | Mobile Network Code (MNC): 01 |
| 634 | Location Area Code (LAC): 00001 (1h) |
| 635 | Control Channel Description |
| 636 | Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach |
| 637 | 0 blocks reserved for access grant |
| 638 | 1 channel used for CCCH, with SDCCH |
| 639 | 5 multiframes period for PAGING REQUEST |
| 640 | Time-out T3212 = 0 |
| 641 | Cell Options BCCH |
| 642 | Power control indicator: not set |
| 643 | MSs shall not use uplink DTX |
| 644 | Radio link timeout = 36 |
| 645 | Cell Selection Parameters |
| 646 | Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection |
Harald Welte | 3b2ec42 | 2008-12-29 04:11:14 +0000 | [diff] [blame] | 647 | max.TX power level MS may use for CCH = 2 <- according to GSM05.05 39dBm (max) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 648 | Additional Reselect Parameter Indication (ACS) = only SYSTEM INFO 4: The SI rest octets, if present, shall be used to derive the value of PI and possibly C2 parameters |
| 649 | Half rate support (NECI): New establishment causes are not supported |
| 650 | min.RX signal level for MS = 0 |
| 651 | RACH Control Parameters |
| 652 | maximum 7 retransmissions |
| 653 | 8 slots used to spread transmission |
| 654 | cell not barred for access |
| 655 | call reestablishment not allowed |
| 656 | Access Control Class = 0000 |
| 657 | SI 3 Rest Octets |
| 658 | Cell Bar Qualify (CBQ): 0 |
| 659 | Cell Reselect Offset = 0 dB |
| 660 | Temporary Offset = 0 dB |
| 661 | Penalty Time = 20 s |
| 662 | System Information 2ter Indicator (2TI): 0 = not available |
| 663 | Early Classmark Sending Control (ECSC): 0 = forbidden |
| 664 | Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH |
| 665 | */ |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 666 | static u_int8_t si3[] = { |
Holger Freyther | 4d50547 | 2008-12-28 16:32:42 +0000 | [diff] [blame] | 667 | /* header */0x49, 0x06, 0x1B, |
| 668 | /* cell */0x00, 0x01, |
| 669 | /* lai */0x00, 0xF1, 0x10, 0x00, 0x01, |
| 670 | /* desc */0x01, 0x03, 0x00, |
| 671 | /* option*/0x28, |
| 672 | /* selection*/0x62, 0x00, |
| 673 | /* rach */0xD5, 0x00, 0x00, |
| 674 | /* reset*/0x80, 0x00, 0x00, 0x2B |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 675 | }; |
| 676 | |
| 677 | /* |
| 678 | SYSTEM INFORMATION TYPE 4 |
| 679 | Location area identification |
| 680 | Mobile Country Code (MCC): 001 |
| 681 | Mobile Network Code (MNC): 01 |
| 682 | Location Area Code (LAC): 00001 (1h) |
| 683 | Cell Selection Parameters |
| 684 | Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection |
| 685 | max.TX power level MS may use for CCH = 2 |
| 686 | Additional Reselect Parameter Indication (ACS) = only SYSTEM INFO 4: The SI rest octets, if present, shall be used to derive the value of PI and possibly C2 parameters |
| 687 | Half rate support (NECI): New establishment causes are not supported |
| 688 | min.RX signal level for MS = 0 |
| 689 | RACH Control Parameters |
| 690 | maximum 7 retransmissions |
| 691 | 8 slots used to spread transmission |
| 692 | cell not barred for access |
| 693 | call reestablishment not allowed |
| 694 | Access Control Class = 0000 |
| 695 | Channel Description |
| 696 | Type = SDCCH/4[2] |
| 697 | Timeslot Number: 0 |
| 698 | Training Sequence Code: 7h |
| 699 | ARFCN: 1 |
| 700 | SI Rest Octets |
| 701 | Cell Bar Qualify (CBQ): 0 |
| 702 | Cell Reselect Offset = 0 dB |
| 703 | Temporary Offset = 0 dB |
| 704 | Penalty Time = 20 s |
| 705 | */ |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 706 | static u_int8_t si4[] = { |
Holger Freyther | 4d50547 | 2008-12-28 16:32:42 +0000 | [diff] [blame] | 707 | /* header */0x41, 0x06, 0x1C, |
| 708 | /* lai */0x00, 0xF1, 0x10, 0x00, 0x01, |
| 709 | /* sel */0x62, 0x00, |
| 710 | /* rach*/0xD5, 0x00, 0x00, |
| 711 | /* var */0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 712 | 0x2B, 0x2B, 0x2B |
| 713 | }; |
| 714 | |
| 715 | /* |
| 716 | SYSTEM INFORMATION TYPE 5 |
| 717 | Neighbour Cells Description |
| 718 | EXT-IND: Carries the complete BA |
| 719 | BA-IND = 0 |
| 720 | Format-ID bit map 0 |
| 721 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 722 | */ |
| 723 | |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 724 | static u_int8_t si5[] = { |
Holger Freyther | 4d50547 | 2008-12-28 16:32:42 +0000 | [diff] [blame] | 725 | /* header without l2 len*/0x06, 0x1D, |
| 726 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 727 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 728 | }; |
| 729 | |
| 730 | // SYSTEM INFORMATION TYPE 6 |
| 731 | |
| 732 | /* |
| 733 | SACCH FILLING |
| 734 | System Info Type: SYSTEM INFORMATION 6 |
| 735 | L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF |
| 736 | |
| 737 | SYSTEM INFORMATION TYPE 6 |
| 738 | Cell identity = 00001 (1h) |
| 739 | Location area identification |
| 740 | Mobile Country Code (MCC): 001 |
| 741 | Mobile Network Code (MNC): 01 |
| 742 | Location Area Code (LAC): 00001 (1h) |
| 743 | Cell Options SACCH |
| 744 | Power control indicator: not set |
| 745 | MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H. |
| 746 | Radio link timeout = 36 |
| 747 | NCC permitted (NCC) = FF |
| 748 | */ |
| 749 | |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 750 | static u_int8_t si6[] = { |
Holger Freyther | 4d50547 | 2008-12-28 16:32:42 +0000 | [diff] [blame] | 751 | /* header */0x06, 0x1E, |
| 752 | /* cell id*/ 0x00, 0x01, |
| 753 | /* lai */ 0x00, 0xF1, 0x10, 0x00, 0x01, |
| 754 | /* options */ 0x28, |
| 755 | /* ncc */ 0xFF, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 756 | }; |
| 757 | |
| 758 | |
| 759 | |
| 760 | static const struct bcch_info bcch_infos[] = { |
| 761 | { |
| 762 | .type = RSL_SYSTEM_INFO_1, |
| 763 | .len = sizeof(si1), |
| 764 | .data = si1, |
| 765 | }, { |
| 766 | .type = RSL_SYSTEM_INFO_2, |
| 767 | .len = sizeof(si2), |
| 768 | .data = si2, |
| 769 | }, { |
| 770 | .type = RSL_SYSTEM_INFO_3, |
| 771 | .len = sizeof(si3), |
| 772 | .data = si3, |
| 773 | }, { |
| 774 | .type = RSL_SYSTEM_INFO_4, |
| 775 | .len = sizeof(si4), |
| 776 | .data = si4, |
| 777 | }, |
| 778 | }; |
| 779 | |
Holger Freyther | 24287b6 | 2008-12-28 16:32:41 +0000 | [diff] [blame] | 780 | static_assert(sizeof(si1) == sizeof(struct gsm48_system_information_type_1), type1) |
| 781 | static_assert(sizeof(si2) == sizeof(struct gsm48_system_information_type_2), type2) |
| 782 | static_assert(sizeof(si3) == sizeof(struct gsm48_system_information_type_3), type3) |
| 783 | static_assert(sizeof(si4) >= sizeof(struct gsm48_system_information_type_4), type4) |
Harald Welte | 104604e | 2008-12-28 16:36:11 +0000 | [diff] [blame] | 784 | static_assert(sizeof(si5) == sizeof(struct gsm48_system_information_type_5), type5) |
| 785 | static_assert(sizeof(si6) >= sizeof(struct gsm48_system_information_type_6), type6) |
Holger Freyther | 24287b6 | 2008-12-28 16:32:41 +0000 | [diff] [blame] | 786 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 787 | /* set all system information types */ |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 788 | static int set_system_infos(struct gsm_bts_trx *trx) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 789 | { |
| 790 | int i; |
| 791 | |
| 792 | for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) { |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 793 | rsl_bcch_info(trx, bcch_infos[i].type, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 794 | bcch_infos[i].data, |
| 795 | bcch_infos[i].len); |
| 796 | } |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 797 | rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si5, sizeof(si5)); |
| 798 | rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si6, sizeof(si6)); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 799 | |
| 800 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 803 | /* |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 804 | * Inform anyone... |
| 805 | */ |
| 806 | static void bsc_hack_channel_allocated(struct gsm_lchan *lchan) { |
| 807 | } |
| 808 | |
| 809 | /* |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 810 | * Patch the various SYSTEM INFORMATION tables to update |
| 811 | * the LAI |
| 812 | */ |
| 813 | static void patch_tables(struct gsm_bts *bts) |
| 814 | { |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 815 | u_int8_t arfcn_low = ARFCN & 0xff; |
| 816 | u_int8_t arfcn_high = (ARFCN >> 8) & 0x0f; |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 817 | /* covert the raw packet to the struct */ |
| 818 | struct gsm48_system_information_type_3 *type_3 = |
| 819 | (struct gsm48_system_information_type_3*)&si3; |
| 820 | struct gsm48_system_information_type_4 *type_4 = |
| 821 | (struct gsm48_system_information_type_4*)&si4; |
| 822 | struct gsm48_system_information_type_6 *type_6 = |
| 823 | (struct gsm48_system_information_type_6*)&si6; |
Harald Welte | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 824 | struct gsm48_loc_area_id lai; |
| 825 | |
| 826 | gsm0408_generate_lai(&lai, bts->network->country_code, |
| 827 | bts->network->network_code, bts->location_area_code); |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 828 | |
| 829 | /* assign the MCC and MNC */ |
Harald Welte | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 830 | type_3->lai = lai; |
| 831 | type_4->lai = lai; |
| 832 | type_6->lai = lai; |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 833 | |
Harald Welte | 9400932 | 2009-02-15 15:38:42 +0000 | [diff] [blame] | 834 | /* patch ARFCN into BTS Attributes */ |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 835 | msg_2[74] &= 0xf0; |
| 836 | msg_2[74] |= arfcn_high; |
| 837 | msg_2[75] = arfcn_low; |
Harald Welte | 9400932 | 2009-02-15 15:38:42 +0000 | [diff] [blame] | 838 | nanobts_attr_bts[42] &= 0xf0; |
| 839 | nanobts_attr_bts[42] |= arfcn_high; |
| 840 | nanobts_attr_bts[43] = arfcn_low; |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 841 | |
Harald Welte | 9400932 | 2009-02-15 15:38:42 +0000 | [diff] [blame] | 842 | /* patch ARFCN into TRX Attributes */ |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 843 | msg_6[7] &= 0xf0; |
| 844 | msg_6[7] |= arfcn_high; |
| 845 | msg_6[8] = arfcn_low; |
Harald Welte | 9400932 | 2009-02-15 15:38:42 +0000 | [diff] [blame] | 846 | nanobts_attr_radio[5] &= 0xf0; |
| 847 | nanobts_attr_radio[5] |= arfcn_high; |
| 848 | nanobts_attr_radio[6] = arfcn_low; |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 849 | |
| 850 | type_4->data[2] &= 0xf0; |
| 851 | type_4->data[2] |= arfcn_high; |
| 852 | type_4->data[3] = arfcn_low; |
Holger Freyther | 1adb4ff | 2009-02-04 00:04:52 +0000 | [diff] [blame] | 853 | |
| 854 | /* patch Control Channel Description 10.5.2.11 */ |
| 855 | type_3->control_channel_desc = bts->chan_desc; |
Holger Freyther | b9ddfd0 | 2008-12-28 16:32:45 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 859 | static void bootstrap_rsl(struct gsm_bts_trx *trx) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 860 | { |
Harald Welte | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 861 | fprintf(stdout, "bootstrapping RSL MCC=%u MNC=%u\n", MCC, MNC); |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 862 | set_system_infos(trx); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 865 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 866 | { |
| 867 | switch (event) { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 868 | case EVT_E1_TEI_UP: |
| 869 | switch (type) { |
| 870 | case E1INP_SIGN_OML: |
| 871 | bootstrap_om(trx->bts); |
| 872 | break; |
| 873 | case E1INP_SIGN_RSL: |
| 874 | bootstrap_rsl(trx); |
| 875 | break; |
| 876 | default: |
| 877 | break; |
| 878 | } |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 879 | break; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 880 | case EVT_E1_TEI_DN: |
| 881 | fprintf(stderr, "Lost some E1 TEI link\n"); |
| 882 | /* FIXME: deal with TEI or L1 link loss */ |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 883 | break; |
| 884 | default: |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 885 | break; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | static int bootstrap_network(void) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 890 | { |
| 891 | struct gsm_bts *bts; |
| 892 | |
| 893 | /* initialize our data structures */ |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 894 | gsmnet = gsm_network_init(1, BTS_TYPE, MCC, MNC); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 895 | if (!gsmnet) |
| 896 | return -ENOMEM; |
Harald Welte | f5cbab7 | 2008-12-30 18:00:15 +0000 | [diff] [blame] | 897 | |
Harald Welte | fd2fb45 | 2009-02-21 13:00:57 +0000 | [diff] [blame] | 898 | gsmnet->name_long = "OpenBSC"; |
| 899 | gsmnet->name_short = "OpenBSC"; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 900 | bts = &gsmnet->bts[0]; |
| 901 | bts->location_area_code = 1; |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 902 | bts->trx[0].arfcn = ARFCN; |
Holger Freyther | 1adb4ff | 2009-02-04 00:04:52 +0000 | [diff] [blame] | 903 | |
| 904 | /* Control Channel Description */ |
| 905 | memset(&bts->chan_desc, 0, sizeof(struct gsm48_control_channel_descr)); |
| 906 | bts->chan_desc.att = 0; |
| 907 | bts->chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C; |
| 908 | bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5; |
| 909 | bts->chan_desc.t3212 = 0; |
| 910 | |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 911 | patch_tables(bts); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 912 | |
Holger Freyther | 1fd3414 | 2009-02-09 23:42:03 +0000 | [diff] [blame] | 913 | paging_init(bts); |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 914 | bts->paging.channel_allocated = bsc_hack_channel_allocated; |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 915 | |
Holger Freyther | 219518d | 2009-01-02 22:04:43 +0000 | [diff] [blame] | 916 | telnet_init(gsmnet, 4242); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 917 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 918 | /* E1 mISDN input setup */ |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 919 | if (BTS_TYPE == GSM_BTS_TYPE_BS11) |
| 920 | return e1_config(bts); |
| 921 | else |
| 922 | return ia_config(bts); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 923 | } |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 924 | |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 925 | static void create_pcap_file(char *file) |
| 926 | { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 927 | #if 0 |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 928 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
| 929 | int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode); |
| 930 | |
| 931 | if (fd < 0) { |
| 932 | perror("Failed to open file for pcap"); |
| 933 | return; |
| 934 | } |
| 935 | |
| 936 | mi_set_pcap_fd(fd); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 937 | #else |
| 938 | fprintf(stderr, "PCAP support currently disabled!!\n"); |
| 939 | #endif |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 942 | static void print_usage() |
| 943 | { |
| 944 | printf("Usage: bsc_hack\n"); |
| 945 | } |
| 946 | |
| 947 | static void print_help() |
| 948 | { |
| 949 | printf(" Some useful help...\n"); |
| 950 | printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n"); |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 951 | printf(" -s --disable-color\n"); |
| 952 | printf(" -n --network-code number(MNC) \n"); |
| 953 | printf(" -c --country-code number (MCC) \n"); |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 954 | printf(" -f --arfcn number The frequency ARFCN\n"); |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 955 | printf(" -l --database db-name The database to use\n"); |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 956 | printf(" -a --authorize-everyone Allow everyone into the network.\n"); |
Holger Freyther | e97f7fb | 2008-12-31 18:52:11 +0000 | [diff] [blame] | 957 | printf(" -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n"); |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 958 | printf(" -p --pcap file The filename of the pcap file\n"); |
Harald Welte | e1bd241 | 2009-02-15 14:40:09 +0000 | [diff] [blame] | 959 | printf(" -t --bts-type type The BTS type (bs11, nanobts900, nanobts1800)\n"); |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 960 | printf(" -h --help this text\n"); |
| 961 | } |
| 962 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 963 | static const char *bts_types[] = { |
| 964 | [GSM_BTS_TYPE_UNKNOWN] = "unknown", |
| 965 | [GSM_BTS_TYPE_BS11] = "bs11", |
| 966 | [GSM_BTS_TYPE_NANOBTS_900] = "nanobts900", |
| 967 | [GSM_BTS_TYPE_NANOBTS_1800] = "nanobts1800", |
| 968 | }; |
| 969 | |
| 970 | enum gsm_bts_type parse_btstype(char *arg) |
| 971 | { |
| 972 | int i; |
| 973 | for (i = 0; i < ARRAY_SIZE(bts_types); i++) { |
| 974 | if (!strcmp(arg, bts_types[i])) |
| 975 | return i; |
| 976 | } |
Harald Welte | e1bd241 | 2009-02-15 14:40:09 +0000 | [diff] [blame] | 977 | return GSM_BTS_TYPE_BS11; /* Default: BS11 */ |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 980 | static void handle_options(int argc, char** argv) |
| 981 | { |
| 982 | while (1) { |
| 983 | int option_index = 0, c; |
| 984 | static struct option long_options[] = { |
| 985 | {"help", 0, 0, 'h'}, |
| 986 | {"debug", 1, 0, 'd'}, |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 987 | {"disable-color", 0, 0, 's'}, |
| 988 | {"network-code", 1, 0, 'n'}, |
| 989 | {"country-code", 1, 0, 'c'}, |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 990 | {"database", 1, 0, 'l'}, |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 991 | {"authorize-everyone", 0, 0, 'a'}, |
Holger Freyther | e97f7fb | 2008-12-31 18:52:11 +0000 | [diff] [blame] | 992 | {"reject-cause", 1, 0, 'r'}, |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 993 | {"pcap", 1, 0, 'p'}, |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 994 | {"arfcn", 1, 0, 'f'}, |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 995 | {"bts-type", 1, 0, 't'}, |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 996 | {0, 0, 0, 0} |
| 997 | }; |
| 998 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 999 | c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:", |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 1000 | long_options, &option_index); |
| 1001 | if (c == -1) |
| 1002 | break; |
| 1003 | |
| 1004 | switch (c) { |
| 1005 | case 'h': |
| 1006 | print_usage(); |
| 1007 | print_help(); |
| 1008 | exit(0); |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 1009 | case 's': |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 1010 | debug_use_color(0); |
| 1011 | break; |
| 1012 | case 'd': |
| 1013 | debug_parse_category_mask(optarg); |
| 1014 | break; |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 1015 | case 'n': |
| 1016 | MNC = atoi(optarg); |
| 1017 | break; |
| 1018 | case 'c': |
| 1019 | MCC = atoi(optarg); |
| 1020 | break; |
Harald Welte | 9898188 | 2009-01-06 18:59:11 +0000 | [diff] [blame] | 1021 | case 'f': |
| 1022 | ARFCN = atoi(optarg); |
| 1023 | break; |
Harald Welte | 8965da4 | 2009-01-06 18:09:02 +0000 | [diff] [blame] | 1024 | case 'l': |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 1025 | database_name = strdup(optarg); |
| 1026 | break; |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 1027 | case 'a': |
| 1028 | gsm0408_allow_everyone(1); |
| 1029 | break; |
Holger Freyther | e97f7fb | 2008-12-31 18:52:11 +0000 | [diff] [blame] | 1030 | case 'r': |
| 1031 | gsm0408_set_reject_cause(atoi(optarg)); |
| 1032 | break; |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 1033 | case 'p': |
| 1034 | create_pcap_file(optarg); |
| 1035 | break; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 1036 | case 't': |
| 1037 | BTS_TYPE = parse_btstype(optarg); |
| 1038 | break; |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 1039 | default: |
| 1040 | /* ignore */ |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
| 1044 | } |
| 1045 | |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 1046 | static void signal_handler(int signal) |
| 1047 | { |
| 1048 | fprintf(stdout, "signal %u received\n", signal); |
| 1049 | |
| 1050 | switch (signal) { |
| 1051 | case SIGHUP: |
| 1052 | case SIGABRT: |
| 1053 | shutdown_net(gsmnet); |
| 1054 | break; |
| 1055 | default: |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 1060 | int main(int argc, char **argv) |
| 1061 | { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 1062 | int rc; |
| 1063 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 1064 | /* parse options */ |
| 1065 | handle_options(argc, argv); |
| 1066 | |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 1067 | if (db_init(database_name)) { |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 1068 | printf("DB: Failed to init database. Please check the option settings.\n"); |
| 1069 | return 1; |
| 1070 | } |
| 1071 | printf("DB: Database initialized.\n"); |
| 1072 | |
| 1073 | if (db_prepare()) { |
| 1074 | printf("DB: Failed to prepare database.\n"); |
| 1075 | return 1; |
| 1076 | } |
| 1077 | printf("DB: Database prepared.\n"); |
| 1078 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 1079 | rc = bootstrap_network(); |
| 1080 | if (rc < 0) |
| 1081 | exit(1); |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 1082 | |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 1083 | signal(SIGHUP, &signal_handler); |
| 1084 | signal(SIGABRT, &signal_handler); |
| 1085 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 1086 | while (1) { |
| 1087 | bsc_select_main(); |
| 1088 | } |
| 1089 | } |