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