Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* A hackish minimal BSC (+MSC +HLR) implementation */ |
| 2 | |
| 3 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdarg.h> |
| 26 | #include <time.h> |
| 27 | #include <string.h> |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 28 | #include <errno.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 29 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 30 | #define _GNU_SOURCE |
| 31 | #include <getopt.h> |
| 32 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 33 | #include <openbsc/gsm_data.h> |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 34 | #include <openbsc/select.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 35 | #include <openbsc/abis_rsl.h> |
| 36 | #include <openbsc/abis_nm.h> |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 37 | #include <openbsc/debug.h> |
Holger Freyther | 5677ae3 | 2008-12-27 09:41:03 +0000 | [diff] [blame] | 38 | #include <openbsc/misdn.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 39 | |
| 40 | /* global pointer to the gsm network data structure */ |
| 41 | static struct gsm_network *gsmnet; |
| 42 | |
| 43 | /* The following definitions are for OM and NM packets that we cannot yet |
| 44 | * generate by code but we just pass on */ |
| 45 | |
| 46 | // BTS Site Manager, SET ATTRIBUTES |
| 47 | |
| 48 | /* |
| 49 | Object Class: BTS Site Manager |
| 50 | Instance 1: FF |
| 51 | Instance 2: FF |
| 52 | Instance 3: FF |
| 53 | SET ATTRIBUTES |
| 54 | sAbisExternalTime: 2007/09/08 14:36:11 |
| 55 | omLAPDRelTimer: 30sec |
| 56 | shortLAPDIntTimer: 5sec |
| 57 | emergencyTimer1: 10 minutes |
| 58 | emergencyTimer2: 0 minutes |
| 59 | */ |
| 60 | |
| 61 | unsigned char msg_1[] = |
| 62 | { |
| 63 | 0xD0, 0x00, 0xFF, 0xFF, 0xFF, 0x91, 0x07, 0xD7, 0x09, 0x08, 0x0E, 0x24, |
| 64 | 0x0B, 0xCE, 0x02, 0x00, 0x1E, 0xE8, 0x01, 0x05, 0x42, 0x02, 0x00, 0x0A, 0x44, |
| 65 | 0x02, 0x00, 0x00 |
| 66 | }; |
| 67 | |
| 68 | // BTS, SET BTS ATTRIBUTES |
| 69 | |
| 70 | /* |
| 71 | Object Class: BTS |
| 72 | BTS relat. Number: 0 |
| 73 | Instance 2: FF |
| 74 | Instance 3: FF |
| 75 | SET BTS ATTRIBUTES |
| 76 | bsIdentityCode / BSIC: |
| 77 | PLMN_colour_code: 7h |
| 78 | BS_colour_code: 7h |
| 79 | BTS Air Timer T3105: 4 ,unit 10 ms |
| 80 | btsIsHopping: FALSE |
| 81 | periodCCCHLoadIndication: 255sec |
| 82 | thresholdCCCHLoadIndication: 100% |
| 83 | cellAllocationNumber: 00h = GSM 900 |
| 84 | enableInterferenceClass: 00h = Disabled |
| 85 | fACCHQual: 6 (FACCH stealing flags minus 1) |
| 86 | intaveParameter: 31 SACCH multiframes |
| 87 | interferenceLevelBoundaries: |
| 88 | Interference Boundary 1: 0Ah |
| 89 | Interference Boundary 2: 0Fh |
| 90 | Interference Boundary 3: 14h |
| 91 | Interference Boundary 4: 19h |
| 92 | Interference Boundary 5: 1Eh |
| 93 | mSTxPwrMax: 11 |
| 94 | GSM range: 2=39dBm, 15=13dBm, stepsize 2 dBm |
| 95 | DCS1800 range: 0=30dBm, 15=0dBm, stepsize 2 dBm |
| 96 | PCS1900 range: 0=30dBm, 15=0dBm, stepsize 2 dBm |
| 97 | 30=33dBm, 31=32dBm |
| 98 | ny1: |
| 99 | Maximum number of repetitions for PHYSICAL INFORMATION message (GSM 04.08): 20 |
| 100 | powerOutputThresholds: |
| 101 | Out Power Fault Threshold: -10 dB |
| 102 | Red Out Power Threshold: - 6 dB |
| 103 | Excessive Out Power Threshold: 5 dB |
| 104 | rACHBusyThreshold: -127 dBm |
| 105 | rACHLoadAveragingSlots: 250 ,number of RACH burst periods |
| 106 | rfResourceIndicationPeriod: 125 SACCH multiframes |
| 107 | T200: |
| 108 | SDCCH: 044 in 5 ms |
| 109 | FACCH/Full rate: 031 in 5 ms |
| 110 | FACCH/Half rate: 041 in 5 ms |
| 111 | SACCH with TCH SAPI0: 090 in 10 ms |
| 112 | SACCH with SDCCH: 090 in 10 ms |
| 113 | SDCCH with SAPI3: 090 in 5 ms |
| 114 | SACCH with TCH SAPI3: 135 in 10 ms |
| 115 | tSync: 9000 units of 10 msec |
| 116 | tTrau: 9000 units of 10 msec |
| 117 | enableUmLoopTest: 00h = disabled |
| 118 | enableExcessiveDistance: 00h = Disabled |
| 119 | excessiveDistance: 64km |
| 120 | hoppingMode: 00h = baseband hopping |
| 121 | cellType: 00h = Standard Cell |
| 122 | BCCH ARFCN / bCCHFrequency: 1 |
| 123 | */ |
| 124 | |
| 125 | unsigned char msg_2[] = |
| 126 | { |
| 127 | 0x41, 0x01, 0x00, 0xFF, 0xFF, 0x09, 0x3F, 0x0A, 0x04, 0x61, 0x00, 0x0B, |
| 128 | 0xFF, 0x0C, 0x64, 0x62, 0x00, 0x66, 0x00, 0x6E, 0x06, 0x18, 0x1F, 0x19, |
| 129 | 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x7B, 0x0B, 0x23, 0x14, 0x28, 0x00, 0x04, |
| 130 | 0x03, 0x2A, 0x7F, 0x2B, 0x00, 0xFA, 0x8F, 0x7D, 0x33, 0x2C, 0x1F, 0x29, |
| 131 | 0x5A, 0x5A, 0x5A, 0x87, 0x94, 0x23, 0x28, 0x95, 0x23, 0x28, 0x35, 0x01, |
| 132 | 0x00, 0x46, 0x01, 0x00, 0x58, 0x01, 0x40, 0xC5, 0x01, 0x00, 0xF2, 0x01, |
| 133 | 0x00, 0x08, 0x00, HARDCODED_ARFCN/*0x01*/, |
| 134 | }; |
| 135 | |
| 136 | // Handover Recognition, SET ATTRIBUTES |
| 137 | |
| 138 | /* |
| 139 | Illegal Contents GSM Formatted O&M Msg |
| 140 | Object Class: Handover Recognition |
| 141 | BTS relat. Number: 0 |
| 142 | Instance 2: FF |
| 143 | Instance 3: FF |
| 144 | SET ATTRIBUTES |
| 145 | enableDelayPowerBudgetHO: 00h = Disabled |
| 146 | enableDistanceHO: 00h = Disabled |
| 147 | enableInternalInterCellHandover: 00h = Disabled |
| 148 | enableInternalIntraCellHandover: 00h = Disabled |
| 149 | enablePowerBudgetHO: 00h = Disabled |
| 150 | enableRXLEVHO: 00h = Disabled |
| 151 | enableRXQUALHO: 00h = Disabled |
| 152 | hoAveragingDistance: 8 SACCH multiframes |
| 153 | hoAveragingLev: |
| 154 | A_LEV_HO: 8 SACCH multiframes |
| 155 | W_LEV_HO: 1 SACCH multiframes |
| 156 | hoAveragingPowerBudget: 16 SACCH multiframes |
| 157 | hoAveragingQual: |
| 158 | A_QUAL_HO: 8 SACCH multiframes |
| 159 | W_QUAL_HO: 2 SACCH multiframes |
| 160 | hoLowerThresholdLevDL: (10 - 110) dBm |
| 161 | hoLowerThresholdLevUL: (5 - 110) dBm |
| 162 | hoLowerThresholdQualDL: 06h = 6.4% < BER < 12.8% |
| 163 | hoLowerThresholdQualUL: 06h = 6.4% < BER < 12.8% |
| 164 | hoThresholdLevDLintra : (20 - 110) dBm |
| 165 | hoThresholdLevULintra: (20 - 110) dBm |
| 166 | hoThresholdMsRangeMax: 20 km |
| 167 | nCell: 06h |
| 168 | timerHORequest: 3 ,unit 2 SACCH multiframes |
| 169 | */ |
| 170 | |
| 171 | unsigned char msg_3[] = |
| 172 | { |
| 173 | 0xD0, 0xA1, 0x00, 0xFF, 0xFF, 0xD0, 0x00, 0x64, 0x00, 0x67, 0x00, 0x68, |
| 174 | 0x00, 0x6A, 0x00, 0x6C, 0x00, 0x6D, 0x00, 0x6F, 0x08, 0x70, 0x08, 0x01, |
| 175 | 0x71, 0x10, 0x10, 0x10, 0x72, 0x08, 0x02, 0x73, 0x0A, 0x74, 0x05, 0x75, |
| 176 | 0x06, 0x76, 0x06, 0x78, 0x14, 0x79, 0x14, 0x7A, 0x14, 0x7D, 0x06, 0x92, |
| 177 | 0x03, 0x20, 0x01, 0x00, 0x45, 0x01, 0x00, 0x48, 0x01, 0x00, 0x5A, 0x01, |
| 178 | 0x00, 0x5B, 0x01, 0x05, 0x5E, 0x01, 0x1A, 0x5F, 0x01, 0x20, 0x9D, 0x01, |
| 179 | 0x00, 0x47, 0x01, 0x00, 0x5C, 0x01, 0x64, 0x5D, 0x01, 0x1E, 0x97, 0x01, |
| 180 | 0x20, 0xF7, 0x01, 0x3C, |
| 181 | }; |
| 182 | |
| 183 | // Power Control, SET ATTRIBUTES |
| 184 | |
| 185 | /* |
| 186 | Object Class: Power Control |
| 187 | BTS relat. Number: 0 |
| 188 | Instance 2: FF |
| 189 | Instance 3: FF |
| 190 | SET ATTRIBUTES |
| 191 | enableMsPowerControl: 00h = Disabled |
| 192 | enablePowerControlRLFW: 00h = Disabled |
| 193 | pcAveragingLev: |
| 194 | A_LEV_PC: 4 SACCH multiframes |
| 195 | W_LEV_PC: 1 SACCH multiframes |
| 196 | pcAveragingQual: |
| 197 | A_QUAL_PC: 4 SACCH multiframes |
| 198 | W_QUAL_PC: 2 SACCH multiframes |
| 199 | pcLowerThresholdLevDL: 0Fh |
| 200 | pcLowerThresholdLevUL: 0Ah |
| 201 | pcLowerThresholdQualDL: 05h = 3.2% < BER < 6.4% |
| 202 | pcLowerThresholdQualUL: 05h = 3.2% < BER < 6.4% |
| 203 | pcRLFThreshold: 0Ch |
| 204 | pcUpperThresholdLevDL: 14h |
| 205 | pcUpperThresholdLevUL: 0Fh |
| 206 | pcUpperThresholdQualDL: 04h = 1.6% < BER < 3.2% |
| 207 | pcUpperThresholdQualUL: 04h = 1.6% < BER < 3.2% |
| 208 | powerConfirm: 2 ,unit 2 SACCH multiframes |
| 209 | powerControlInterval: 2 ,unit 2 SACCH multiframes |
| 210 | powerIncrStepSize: 02h = 4 dB |
| 211 | powerRedStepSize: 01h = 2 dB |
| 212 | radioLinkTimeoutBs: 64 SACCH multiframes |
| 213 | enableBSPowerControl: 00h = disabled |
| 214 | */ |
| 215 | |
| 216 | unsigned char msg_4[] = |
| 217 | { |
| 218 | 0xD0, 0xA2, 0x00, 0xFF, 0xFF, 0x69, 0x00, 0x6B, 0x00, 0x7E, 0x04, 0x01, |
| 219 | 0x7F, 0x04, 0x02, 0x80, 0x0F, 0x81, 0x0A, 0x82, 0x05, 0x83, 0x05, 0x84, |
| 220 | 0x0C, 0x85, 0x14, 0x86, 0x0F, 0x87, 0x04, 0x88, 0x04, 0x89, 0x02, 0x8A, |
| 221 | 0x02, 0x8B, 0x02, 0x8C, 0x01, 0x8D, 0x40, 0x65, 0x01, 0x00 // set to 0x01 to enable BSPowerControl |
| 222 | }; |
| 223 | |
| 224 | |
| 225 | // Transceiver, SET TRX ATTRIBUTES (TRX 0) |
| 226 | |
| 227 | /* |
| 228 | Object Class: Transceiver |
| 229 | BTS relat. Number: 0 |
| 230 | Tranceiver number: 0 |
| 231 | Instance 3: FF |
| 232 | SET TRX ATTRIBUTES |
| 233 | aRFCNList (HEX): 0001 |
| 234 | txPwrMaxReduction: 00h = 0dB |
| 235 | radioMeasGran: 254 SACCH multiframes |
| 236 | radioMeasRep: 01h = enabled |
| 237 | memberOfEmergencyConfig: 01h = TRUE |
| 238 | trxArea: 00h = TRX doesn't belong to a concentric cell |
| 239 | */ |
| 240 | |
| 241 | unsigned char msg_6[] = |
| 242 | { |
| 243 | 0x44, 0x02, 0x00, 0x00, 0xFF, 0x05, 0x01, 0x00, HARDCODED_ARFCN /*0x01*/, 0x2D, |
| 244 | 0x00, 0xDC, 0x01, 0xFE, 0xDD, 0x01, 0x01, 0x9B, 0x01, 0x01, 0x9F, 0x01, 0x00, |
| 245 | }; |
| 246 | |
| 247 | |
| 248 | static void bootstrap_om(struct gsm_bts *bts) |
| 249 | { |
| 250 | struct gsm_bts_trx *trx = &bts->trx[0]; |
| 251 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 252 | fprintf(stdout, "bootstrapping OML\n"); |
| 253 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 254 | /* stop sending event reports */ |
| 255 | abis_nm_event_reports(bts, 0); |
| 256 | |
| 257 | /* begin DB transmission */ |
| 258 | abis_nm_db_transmission(bts, 1); |
| 259 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 260 | /* end DB transmission */ |
| 261 | abis_nm_db_transmission(bts, 0); |
| 262 | |
| 263 | /* Reset BTS Site manager resource */ |
| 264 | abis_nm_reset_resource(bts); |
| 265 | |
| 266 | /* begin DB transmission */ |
| 267 | abis_nm_db_transmission(bts, 1); |
| 268 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 269 | abis_nm_raw_msg(bts, sizeof(msg_1), msg_1); /* set BTS SiteMgr attr*/ |
| 270 | abis_nm_raw_msg(bts, sizeof(msg_2), msg_2); /* set BTS attr */ |
| 271 | abis_nm_raw_msg(bts, sizeof(msg_3), msg_3); /* set BTS handover attr */ |
| 272 | abis_nm_raw_msg(bts, sizeof(msg_4), msg_4); /* set BTS power control attr */ |
| 273 | |
| 274 | /* Connect signalling of bts0/trx0 to e1_0/ts1/64kbps */ |
| 275 | abis_nm_conn_terr_sign(trx, 0, 1, 0xff); |
| 276 | abis_nm_raw_msg(bts, sizeof(msg_6), msg_6); /* SET TRX ATTRIBUTES */ |
| 277 | |
| 278 | /* Use TEI 1 for signalling */ |
| 279 | abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x01); |
| 280 | abis_nm_set_channel_attr(&trx->ts[0], NM_CHANC_SDCCH_CBCH); |
| 281 | #if 0 |
| 282 | /* TRX 1 */ |
| 283 | abis_nm_conn_terr_sign(&bts->trx[1], 0, 1, 0xff); |
| 284 | /* FIXME: TRX ATTRIBUTE */ |
| 285 | abis_nm_establish_tei(bts, 0, 0, 1, 0xff, 0x02); |
| 286 | #endif |
| 287 | |
| 288 | /* SET CHANNEL ATTRIBUTE TS1 */ |
| 289 | abis_nm_set_channel_attr(&trx->ts[1], 0x09); |
| 290 | /* Connect traffic of bts0/trx0/ts1 to e1_0/ts2/b */ |
| 291 | abis_nm_conn_terr_traf(&trx->ts[1], 0, 2, 1); |
| 292 | |
| 293 | /* SET CHANNEL ATTRIBUTE TS2 */ |
| 294 | abis_nm_set_channel_attr(&trx->ts[2], 0x09); |
| 295 | /* Connect traffic of bts0/trx0/ts2 to e1_0/ts2/c */ |
| 296 | abis_nm_conn_terr_traf(&trx->ts[2], 0, 2, 2); |
| 297 | |
| 298 | /* SET CHANNEL ATTRIBUTE TS3 */ |
| 299 | abis_nm_set_channel_attr(&trx->ts[3], 0x09); |
| 300 | /* Connect traffic of bts0/trx0/ts3 to e1_0/ts2/d */ |
| 301 | abis_nm_conn_terr_traf(&trx->ts[3], 0, 2, 3); |
| 302 | |
| 303 | /* SET CHANNEL ATTRIBUTE TS4 */ |
| 304 | abis_nm_set_channel_attr(&trx->ts[4], 0x09); |
| 305 | /* Connect traffic of bts0/trx0/ts4 to e1_0/ts3/a */ |
| 306 | abis_nm_conn_terr_traf(&trx->ts[4], 0, 3, 0); |
| 307 | |
| 308 | /* SET CHANNEL ATTRIBUTE TS5 */ |
| 309 | abis_nm_set_channel_attr(&trx->ts[5], 0x09); |
| 310 | /* Connect traffic of bts0/trx0/ts5 to e1_0/ts3/b */ |
| 311 | abis_nm_conn_terr_traf(&trx->ts[5], 0, 3, 1); |
| 312 | |
| 313 | /* SET CHANNEL ATTRIBUTE TS6 */ |
| 314 | abis_nm_set_channel_attr(&trx->ts[6], 0x09); |
| 315 | /* Connect traffic of bts0/trx0/ts6 to e1_0/ts3/c */ |
| 316 | abis_nm_conn_terr_traf(&trx->ts[6], 0, 3, 2); |
| 317 | |
| 318 | /* SET CHANNEL ATTRIBUTE TS7 */ |
| 319 | abis_nm_set_channel_attr(&trx->ts[7], 0x09); |
| 320 | /* Connect traffic of bts0/trx0/ts7 to e1_0/ts3/d */ |
| 321 | abis_nm_conn_terr_traf(&trx->ts[7], 0, 3, 3); |
| 322 | |
| 323 | /* end DB transmission */ |
| 324 | abis_nm_db_transmission(bts, 0); |
| 325 | |
| 326 | /* Reset BTS Site manager resource */ |
| 327 | abis_nm_reset_resource(bts); |
| 328 | |
| 329 | /* restart sending event reports */ |
| 330 | abis_nm_event_reports(bts, 1); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | |
| 335 | struct bcch_info { |
| 336 | u_int8_t type; |
| 337 | u_int8_t len; |
| 338 | const u_int8_t *data; |
| 339 | }; |
| 340 | |
| 341 | /* |
| 342 | SYSTEM INFORMATION TYPE 1 |
| 343 | Cell channel description |
| 344 | Format-ID bit map 0 |
| 345 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 |
| 346 | RACH Control Parameters |
| 347 | maximum 7 retransmissions |
| 348 | 8 slots used to spread transmission |
| 349 | cell not barred for access |
| 350 | call reestablishment not allowed |
| 351 | Access Control Class = 0000 |
| 352 | */ |
| 353 | static const u_int8_t si1[] = { |
| 354 | 0x55, 0x06, 0x19, 0x04 /*0x00*/, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 355 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*0x01*/,0xD5, |
| 356 | 0x00, 0x00, 0x2B |
| 357 | }; |
| 358 | |
| 359 | /* |
| 360 | SYSTEM INFORMATION TYPE 2 |
| 361 | Neighbour Cells Description |
| 362 | EXT-IND: Carries the complete BA |
| 363 | BA-IND = 0 |
| 364 | Format-ID bit map 0 |
| 365 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 366 | NCC permitted (NCC) = FF |
| 367 | RACH Control Parameters |
| 368 | maximum 7 retransmissions |
| 369 | 8 slots used to spread transmission |
| 370 | cell not barred for access |
| 371 | call reestablishment not allowed |
| 372 | Access Control Class = 0000 |
| 373 | */ |
| 374 | static const u_int8_t si2[] = { |
| 375 | 0x59, 0x06, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 376 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xD5, 0x00, |
| 377 | 0x00 |
| 378 | }; |
| 379 | |
| 380 | /* |
| 381 | SYSTEM INFORMATION TYPE 3 |
| 382 | Cell identity = 00001 (1h) |
| 383 | Location area identification |
| 384 | Mobile Country Code (MCC): 001 |
| 385 | Mobile Network Code (MNC): 01 |
| 386 | Location Area Code (LAC): 00001 (1h) |
| 387 | Control Channel Description |
| 388 | Attach-detach: MSs in the cell are not allowed to apply IMSI attach /detach |
| 389 | 0 blocks reserved for access grant |
| 390 | 1 channel used for CCCH, with SDCCH |
| 391 | 5 multiframes period for PAGING REQUEST |
| 392 | Time-out T3212 = 0 |
| 393 | Cell Options BCCH |
| 394 | Power control indicator: not set |
| 395 | MSs shall not use uplink DTX |
| 396 | Radio link timeout = 36 |
| 397 | Cell Selection Parameters |
| 398 | Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection |
| 399 | max.TX power level MS may use for CCH = 2 |
| 400 | 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 |
| 401 | Half rate support (NECI): New establishment causes are not supported |
| 402 | min.RX signal level for MS = 0 |
| 403 | RACH Control Parameters |
| 404 | maximum 7 retransmissions |
| 405 | 8 slots used to spread transmission |
| 406 | cell not barred for access |
| 407 | call reestablishment not allowed |
| 408 | Access Control Class = 0000 |
| 409 | SI 3 Rest Octets |
| 410 | Cell Bar Qualify (CBQ): 0 |
| 411 | Cell Reselect Offset = 0 dB |
| 412 | Temporary Offset = 0 dB |
| 413 | Penalty Time = 20 s |
| 414 | System Information 2ter Indicator (2TI): 0 = not available |
| 415 | Early Classmark Sending Control (ECSC): 0 = forbidden |
| 416 | Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH |
| 417 | */ |
| 418 | unsigned char si3[] = { |
| 419 | 0x49, 0x06, 0x1B, 0x00, 0x01, 0x00, 0xF1, 0x10, 0x00, 0x01, |
| 420 | 0x01, 0x03, 0x00, 0x28, 0x62, 0x00, 0xD5, 0x00, 0x00, 0x80, |
| 421 | 0x00, 0x00, 0x2B |
| 422 | }; |
| 423 | |
| 424 | /* |
| 425 | SYSTEM INFORMATION TYPE 4 |
| 426 | Location area identification |
| 427 | Mobile Country Code (MCC): 001 |
| 428 | Mobile Network Code (MNC): 01 |
| 429 | Location Area Code (LAC): 00001 (1h) |
| 430 | Cell Selection Parameters |
| 431 | Cell reselect hysteresis = 6 dB RXLEV hysteresis for LA re-selection |
| 432 | max.TX power level MS may use for CCH = 2 |
| 433 | 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 |
| 434 | Half rate support (NECI): New establishment causes are not supported |
| 435 | min.RX signal level for MS = 0 |
| 436 | RACH Control Parameters |
| 437 | maximum 7 retransmissions |
| 438 | 8 slots used to spread transmission |
| 439 | cell not barred for access |
| 440 | call reestablishment not allowed |
| 441 | Access Control Class = 0000 |
| 442 | Channel Description |
| 443 | Type = SDCCH/4[2] |
| 444 | Timeslot Number: 0 |
| 445 | Training Sequence Code: 7h |
| 446 | ARFCN: 1 |
| 447 | SI Rest Octets |
| 448 | Cell Bar Qualify (CBQ): 0 |
| 449 | Cell Reselect Offset = 0 dB |
| 450 | Temporary Offset = 0 dB |
| 451 | Penalty Time = 20 s |
| 452 | */ |
| 453 | static const u_int8_t si4[] = { |
| 454 | 0x41, 0x06, 0x1C, 0x00, 0xF1, 0x10, 0x00, 0x01, 0x62, 0x00, |
| 455 | 0xD5, 0x00, 0x00, 0x64, 0x30, 0xE0, HARDCODED_ARFCN/*0x01*/, 0x80, 0x00, 0x00, |
| 456 | 0x2B, 0x2B, 0x2B |
| 457 | }; |
| 458 | |
| 459 | /* |
| 460 | SYSTEM INFORMATION TYPE 5 |
| 461 | Neighbour Cells Description |
| 462 | EXT-IND: Carries the complete BA |
| 463 | BA-IND = 0 |
| 464 | Format-ID bit map 0 |
| 465 | CA-ARFCN Bit 124...001 (Hex): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 466 | */ |
| 467 | |
| 468 | static const u_int8_t si5[] = { |
| 469 | 0x06, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 470 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 471 | }; |
| 472 | |
| 473 | // SYSTEM INFORMATION TYPE 6 |
| 474 | |
| 475 | /* |
| 476 | SACCH FILLING |
| 477 | System Info Type: SYSTEM INFORMATION 6 |
| 478 | L3 Information (Hex): 06 1E 00 01 xx xx 10 00 01 28 FF |
| 479 | |
| 480 | SYSTEM INFORMATION TYPE 6 |
| 481 | Cell identity = 00001 (1h) |
| 482 | Location area identification |
| 483 | Mobile Country Code (MCC): 001 |
| 484 | Mobile Network Code (MNC): 01 |
| 485 | Location Area Code (LAC): 00001 (1h) |
| 486 | Cell Options SACCH |
| 487 | Power control indicator: not set |
| 488 | MSs shall not use uplink DTX on a TCH-F. MS shall not use uplink DTX on TCH-H. |
| 489 | Radio link timeout = 36 |
| 490 | NCC permitted (NCC) = FF |
| 491 | */ |
| 492 | |
| 493 | static const u_int8_t si6[] = { |
| 494 | 0x06, 0x1E, 0x00, 0x01, 0x00, 0xF1, 0x10, 0x00, 0x01, 0x28, 0xFF, |
| 495 | }; |
| 496 | |
| 497 | |
| 498 | |
| 499 | static const struct bcch_info bcch_infos[] = { |
| 500 | { |
| 501 | .type = RSL_SYSTEM_INFO_1, |
| 502 | .len = sizeof(si1), |
| 503 | .data = si1, |
| 504 | }, { |
| 505 | .type = RSL_SYSTEM_INFO_2, |
| 506 | .len = sizeof(si2), |
| 507 | .data = si2, |
| 508 | }, { |
| 509 | .type = RSL_SYSTEM_INFO_3, |
| 510 | .len = sizeof(si3), |
| 511 | .data = si3, |
| 512 | }, { |
| 513 | .type = RSL_SYSTEM_INFO_4, |
| 514 | .len = sizeof(si4), |
| 515 | .data = si4, |
| 516 | }, |
| 517 | }; |
| 518 | |
| 519 | /* set all system information types */ |
| 520 | static int set_system_infos(struct gsm_bts *bts) |
| 521 | { |
| 522 | int i; |
| 523 | |
| 524 | for (i = 0; i < ARRAY_SIZE(bcch_infos); i++) { |
| 525 | rsl_bcch_info(bts, bcch_infos[i].type, |
| 526 | bcch_infos[i].data, |
| 527 | bcch_infos[i].len); |
| 528 | } |
| 529 | rsl_sacch_filling(bts, RSL_SYSTEM_INFO_5, si5, sizeof(si5)); |
| 530 | rsl_sacch_filling(bts, RSL_SYSTEM_INFO_6, si6, sizeof(si6)); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 531 | |
| 532 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static void activate_traffic_channels(struct gsm_bts_trx *trx) |
| 536 | { |
| 537 | int i; |
| 538 | |
| 539 | /* channel 0 is CCCH */ |
| 540 | for (i = 1; i < 8; i++) |
| 541 | rsl_chan_activate_tch_f(&trx->ts[i]); |
| 542 | } |
| 543 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 544 | static void bootstrap_rsl(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 545 | { |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 546 | fprintf(stdout, "bootstrapping RSL\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 547 | set_system_infos(bts); |
| 548 | |
| 549 | /* FIXME: defer this until the channels are used */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 550 | //activate_traffic_channels(&bts->trx[0]); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 553 | static void mi_cb(int event, struct gsm_bts *bts) |
| 554 | { |
| 555 | switch (event) { |
| 556 | case EVT_E1_OML_UP: |
| 557 | bootstrap_om(bts); |
| 558 | break; |
| 559 | case EVT_E1_RSL_UP: |
| 560 | bootstrap_rsl(bts); |
| 561 | break; |
| 562 | default: |
| 563 | /* FIXME: deal with TEI or L1 link loss */ |
| 564 | break; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static int bootstrap_network(void) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 569 | { |
| 570 | struct gsm_bts *bts; |
| 571 | |
| 572 | /* initialize our data structures */ |
| 573 | gsmnet = gsm_network_init(1, 1, 1); |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 574 | if (!gsmnet) |
| 575 | return -ENOMEM; |
| 576 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 577 | bts = &gsmnet->bts[0]; |
| 578 | bts->location_area_code = 1; |
| 579 | bts->trx[0].arfcn = HARDCODED_ARFCN; |
| 580 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 581 | if (mi_setup(bts, 0, mi_cb) < 0) |
| 582 | return -EIO; |
| 583 | |
| 584 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 585 | } |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 586 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 587 | static void print_usage() |
| 588 | { |
| 589 | printf("Usage: bsc_hack\n"); |
| 590 | } |
| 591 | |
| 592 | static void print_help() |
| 593 | { |
| 594 | printf(" Some useful help...\n"); |
| 595 | printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n"); |
| 596 | printf(" -n --disable-color\n"); |
| 597 | printf(" -h --help this text\n"); |
| 598 | } |
| 599 | |
| 600 | static void handle_options(int argc, char** argv) |
| 601 | { |
| 602 | while (1) { |
| 603 | int option_index = 0, c; |
| 604 | static struct option long_options[] = { |
| 605 | {"help", 0, 0, 'h'}, |
| 606 | {"debug", 1, 0, 'd'}, |
| 607 | {"disable-color", 0, 0, 'n'}, |
| 608 | {0, 0, 0, 0} |
| 609 | }; |
| 610 | |
| 611 | c = getopt_long(argc, argv, "hnd:", |
| 612 | long_options, &option_index); |
| 613 | if (c == -1) |
| 614 | break; |
| 615 | |
| 616 | switch (c) { |
| 617 | case 'h': |
| 618 | print_usage(); |
| 619 | print_help(); |
| 620 | exit(0); |
| 621 | case 'n': |
| 622 | debug_use_color(0); |
| 623 | break; |
| 624 | case 'd': |
| 625 | debug_parse_category_mask(optarg); |
| 626 | break; |
| 627 | default: |
| 628 | /* ignore */ |
| 629 | break; |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 634 | int main(int argc, char **argv) |
| 635 | { |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 636 | /* parse options */ |
| 637 | handle_options(argc, argv); |
| 638 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 639 | bootstrap_network(); |
| 640 | |
| 641 | while (1) { |
| 642 | bsc_select_main(); |
| 643 | } |
| 644 | } |