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