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