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