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