Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1 | /* Siemens BS-11 microBTS configuration tool */ |
| 2 | |
Harald Welte | 4ec2b1d | 2010-12-14 13:14:32 +0100 | [diff] [blame] | 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 6 | * This software is based on ideas (but not code) of BS11Config |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 7 | * (C) 2009 by Dieter Spaar <spaar@mirider.augusta.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <unistd.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <errno.h> |
| 28 | #include <string.h> |
| 29 | #include <getopt.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <signal.h> |
| 32 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 33 | #include <sys/stat.h> |
| 34 | |
| 35 | #include <openbsc/gsm_data.h> |
| 36 | #include <openbsc/abis_nm.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 37 | #include <osmocom/core/msgb.h> |
| 38 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 39 | #include <openbsc/debug.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 40 | #include <osmocom/core/select.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 41 | #include <openbsc/rs232.h> |
| 42 | |
| 43 | /* state of our bs11_config application */ |
| 44 | enum bs11cfg_state { |
| 45 | STATE_NONE, |
| 46 | STATE_LOGON_WAIT, |
| 47 | STATE_LOGON_ACK, |
| 48 | STATE_SWLOAD, |
| 49 | STATE_QUERY, |
| 50 | }; |
| 51 | static enum bs11cfg_state bs11cfg_state = STATE_NONE; |
Daniel Willmann | b04c503 | 2010-01-07 01:27:50 +0100 | [diff] [blame] | 52 | static char *command, *value; |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 53 | struct osmo_timer_list status_timer; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 54 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 55 | static const uint8_t obj_li_attr[] = { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 56 | NM_ATT_BS11_BIT_ERR_THESH, 0x09, 0x00, |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 57 | NM_ATT_BS11_L1_PROT_TYPE, 0x00, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 58 | NM_ATT_BS11_LINE_CFG, 0x00, |
| 59 | }; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 60 | static const uint8_t obj_bbsig0_attr[] = { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 61 | NM_ATT_BS11_RSSI_OFFS, 0x02, 0x00, 0x00, |
| 62 | NM_ATT_BS11_DIVERSITY, 0x01, 0x00, |
| 63 | }; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 64 | static const uint8_t obj_pa0_attr[] = { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 65 | NM_ATT_BS11_TXPWR, 0x01, BS11_TRX_POWER_GSM_30mW, |
| 66 | }; |
| 67 | static const char *trx1_password = "1111111111"; |
| 68 | #define TEI_OML 25 |
| 69 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 70 | static const uint8_t too_fast[] = { 0x12, 0x80, 0x00, 0x00, 0x02, 0x02 }; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 71 | |
Harald Welte | 51d2a59 | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 72 | static struct log_target *stderr_target; |
Holger Hans Peter Freyther | c8d862e | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 73 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 74 | /* dummy function to keep gsm_data.c happy */ |
| 75 | struct counter *counter_alloc(const char *name) |
| 76 | { |
| 77 | return NULL; |
| 78 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 79 | |
| 80 | int handle_serial_msg(struct msgb *rx_msg); |
| 81 | |
| 82 | /* create all objects for an initial configuration */ |
| 83 | static int create_objects(struct gsm_bts *bts) |
| 84 | { |
| 85 | fprintf(stdout, "Crating Objects for minimal config\n"); |
| 86 | abis_nm_bs11_create_object(bts, BS11_OBJ_LI, 0, sizeof(obj_li_attr), |
| 87 | obj_li_attr); |
| 88 | abis_nm_bs11_create_object(bts, BS11_OBJ_GPSU, 0, 0, NULL); |
| 89 | abis_nm_bs11_create_object(bts, BS11_OBJ_ALCO, 0, 0, NULL); |
| 90 | abis_nm_bs11_create_object(bts, BS11_OBJ_CCLK, 0, 0, NULL); |
| 91 | abis_nm_bs11_create_object(bts, BS11_OBJ_BBSIG, 0, |
| 92 | sizeof(obj_bbsig0_attr), obj_bbsig0_attr); |
| 93 | abis_nm_bs11_create_object(bts, BS11_OBJ_PA, 0, |
| 94 | sizeof(obj_pa0_attr), obj_pa0_attr); |
| 95 | abis_nm_bs11_create_envaBTSE(bts, 0); |
| 96 | abis_nm_bs11_create_envaBTSE(bts, 1); |
| 97 | abis_nm_bs11_create_envaBTSE(bts, 2); |
| 98 | abis_nm_bs11_create_envaBTSE(bts, 3); |
| 99 | |
| 100 | abis_nm_bs11_conn_oml_tei(bts, 0, 1, 0xff, TEI_OML); |
| 101 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 102 | abis_nm_bs11_set_trx_power(bts->c0, BS11_TRX_POWER_GSM_30mW); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 103 | |
| 104 | sleep(1); |
| 105 | |
| 106 | abis_nm_bs11_set_trx1_pw(bts, trx1_password); |
| 107 | |
| 108 | sleep(1); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int create_trx1(struct gsm_bts *bts) |
| 114 | { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 115 | uint8_t bbsig1_attr[sizeof(obj_bbsig0_attr)+12]; |
| 116 | uint8_t *cur = bbsig1_attr; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 117 | struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, 1); |
| 118 | |
| 119 | if (!trx) |
| 120 | trx = gsm_bts_trx_alloc(bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 121 | |
| 122 | fprintf(stdout, "Crating Objects for TRX1\n"); |
| 123 | |
| 124 | abis_nm_bs11_set_trx1_pw(bts, trx1_password); |
| 125 | |
| 126 | sleep(1); |
| 127 | |
| 128 | cur = tlv_put(cur, NM_ATT_BS11_PASSWORD, 10, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 129 | (uint8_t *)trx1_password); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 130 | memcpy(cur, obj_bbsig0_attr, sizeof(obj_bbsig0_attr)); |
| 131 | abis_nm_bs11_create_object(bts, BS11_OBJ_BBSIG, 1, |
| 132 | sizeof(bbsig1_attr), bbsig1_attr); |
| 133 | abis_nm_bs11_create_object(bts, BS11_OBJ_PA, 1, |
| 134 | sizeof(obj_pa0_attr), obj_pa0_attr); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 135 | abis_nm_bs11_set_trx_power(trx, BS11_TRX_POWER_GSM_30mW); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static char *serial_port = "/dev/ttyUSB0"; |
| 141 | static char *fname_safety = "BTSBMC76.SWI"; |
| 142 | static char *fname_software = "HS011106.SWL"; |
| 143 | static int delay_ms = 0; |
| 144 | static int win_size = 8; |
| 145 | static int param_disconnect = 0; |
| 146 | static int param_restart = 0; |
| 147 | static int param_forced = 0; |
| 148 | static struct gsm_bts *g_bts; |
| 149 | |
| 150 | static int file_is_readable(const char *fname) |
| 151 | { |
| 152 | int rc; |
| 153 | struct stat st; |
| 154 | |
| 155 | rc = stat(fname, &st); |
| 156 | if (rc < 0) |
| 157 | return 0; |
| 158 | |
| 159 | if (S_ISREG(st.st_mode) && (st.st_mode & S_IRUSR)) |
| 160 | return 1; |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int percent; |
| 166 | static int percent_old; |
| 167 | |
| 168 | /* callback function passed to the ABIS OML code */ |
| 169 | static int swload_cbfn(unsigned int hook, unsigned int event, struct msgb *msg, |
| 170 | void *data, void *param) |
| 171 | { |
| 172 | if (hook != GSM_HOOK_NM_SWLOAD) |
| 173 | return 0; |
| 174 | |
| 175 | switch (event) { |
| 176 | case NM_MT_LOAD_INIT_ACK: |
| 177 | fprintf(stdout, "Software Load Initiate ACK\n"); |
| 178 | break; |
| 179 | case NM_MT_LOAD_INIT_NACK: |
| 180 | fprintf(stderr, "ERROR: Software Load Initiate NACK\n"); |
| 181 | exit(5); |
| 182 | break; |
| 183 | case NM_MT_LOAD_END_ACK: |
| 184 | if (data) { |
| 185 | /* we did a safety load and must activate it */ |
| 186 | abis_nm_software_activate(g_bts, fname_safety, |
| 187 | swload_cbfn, g_bts); |
| 188 | sleep(5); |
| 189 | } |
| 190 | break; |
| 191 | case NM_MT_LOAD_END_NACK: |
| 192 | fprintf(stderr, "ERROR: Software Load End NACK\n"); |
| 193 | exit(3); |
| 194 | break; |
| 195 | case NM_MT_ACTIVATE_SW_NACK: |
| 196 | fprintf(stderr, "ERROR: Activate Software NACK\n"); |
| 197 | exit(4); |
| 198 | break; |
| 199 | case NM_MT_ACTIVATE_SW_ACK: |
| 200 | bs11cfg_state = STATE_NONE; |
| 201 | |
| 202 | break; |
| 203 | case NM_MT_LOAD_SEG_ACK: |
| 204 | percent = abis_nm_software_load_status(g_bts); |
| 205 | if (percent > percent_old) |
| 206 | printf("Software Download Progress: %d%%\n", percent); |
| 207 | percent_old = percent; |
| 208 | break; |
| 209 | } |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static const char *bs11_link_state[] = { |
| 214 | [0x00] = "Down", |
| 215 | [0x01] = "Up", |
| 216 | [0x02] = "Restoring", |
| 217 | }; |
| 218 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 219 | static const char *linkstate_name(uint8_t linkstate) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 220 | { |
| 221 | if (linkstate > ARRAY_SIZE(bs11_link_state)) |
| 222 | return "Unknown"; |
| 223 | |
| 224 | return bs11_link_state[linkstate]; |
| 225 | } |
| 226 | |
| 227 | static const char *mbccu_load[] = { |
| 228 | [0] = "No Load", |
| 229 | [1] = "Load BTSCAC", |
| 230 | [2] = "Load BTSDRX", |
| 231 | [3] = "Load BTSBBX", |
| 232 | [4] = "Load BTSARC", |
| 233 | [5] = "Load", |
| 234 | }; |
| 235 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 236 | static const char *mbccu_load_name(uint8_t linkstate) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 237 | { |
| 238 | if (linkstate > ARRAY_SIZE(mbccu_load)) |
| 239 | return "Unknown"; |
| 240 | |
| 241 | return mbccu_load[linkstate]; |
| 242 | } |
| 243 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 244 | static const char *bts_phase_name(uint8_t phase) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 245 | { |
| 246 | switch (phase) { |
| 247 | case BS11_STATE_WARM_UP: |
| 248 | case BS11_STATE_WARM_UP_2: |
| 249 | return "Warm Up"; |
| 250 | break; |
| 251 | case BS11_STATE_LOAD_SMU_SAFETY: |
| 252 | return "Load SMU Safety"; |
| 253 | break; |
| 254 | case BS11_STATE_LOAD_SMU_INTENDED: |
| 255 | return "Load SMU Intended"; |
| 256 | break; |
| 257 | case BS11_STATE_LOAD_MBCCU: |
| 258 | return "Load MBCCU"; |
| 259 | break; |
| 260 | case BS11_STATE_SOFTWARE_RQD: |
| 261 | return "Software required"; |
| 262 | break; |
| 263 | case BS11_STATE_WAIT_MIN_CFG: |
| 264 | case BS11_STATE_WAIT_MIN_CFG_2: |
| 265 | return "Wait minimal config"; |
| 266 | break; |
| 267 | case BS11_STATE_MAINTENANCE: |
| 268 | return "Maintenance"; |
| 269 | break; |
| 270 | case BS11_STATE_NORMAL: |
| 271 | return "Normal"; |
| 272 | break; |
| 273 | case BS11_STATE_ABIS_LOAD: |
| 274 | return "Abis load"; |
| 275 | break; |
| 276 | default: |
| 277 | return "Unknown"; |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 282 | static const char *trx_power_name(uint8_t pwr) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 283 | { |
| 284 | switch (pwr) { |
| 285 | case BS11_TRX_POWER_GSM_2W: |
| 286 | return "2W (GSM)"; |
| 287 | case BS11_TRX_POWER_GSM_250mW: |
| 288 | return "250mW (GSM)"; |
| 289 | case BS11_TRX_POWER_GSM_80mW: |
| 290 | return "80mW (GSM)"; |
| 291 | case BS11_TRX_POWER_GSM_30mW: |
| 292 | return "30mW (GSM)"; |
| 293 | case BS11_TRX_POWER_DCS_3W: |
| 294 | return "3W (DCS)"; |
| 295 | case BS11_TRX_POWER_DCS_1W6: |
| 296 | return "1.6W (DCS)"; |
| 297 | case BS11_TRX_POWER_DCS_500mW: |
| 298 | return "500mW (DCS)"; |
| 299 | case BS11_TRX_POWER_DCS_160mW: |
| 300 | return "160mW (DCS)"; |
| 301 | default: |
| 302 | return "unknown value"; |
| 303 | } |
| 304 | } |
| 305 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 306 | static const char *pll_mode_name(uint8_t mode) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 307 | { |
| 308 | switch (mode) { |
| 309 | case BS11_LI_PLL_LOCKED: |
| 310 | return "E1 Locked"; |
| 311 | case BS11_LI_PLL_STANDALONE: |
| 312 | return "Standalone"; |
| 313 | default: |
| 314 | return "unknown"; |
| 315 | } |
| 316 | } |
| 317 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 318 | static const char *cclk_acc_name(uint8_t acc) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 319 | { |
| 320 | switch (acc) { |
| 321 | case 0: |
| 322 | /* Out of the demanded +/- 0.05ppm */ |
| 323 | return "Medium"; |
| 324 | case 1: |
| 325 | /* Synchronized with Abis, within demanded tolerance +/- 0.05ppm */ |
| 326 | return "High"; |
| 327 | default: |
| 328 | return "unknown"; |
| 329 | } |
| 330 | } |
| 331 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 332 | static const char *bport_lcfg_name(uint8_t lcfg) |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 333 | { |
| 334 | switch (lcfg) { |
| 335 | case BS11_LINE_CFG_STAR: |
| 336 | return "Star"; |
| 337 | case BS11_LINE_CFG_MULTIDROP: |
| 338 | return "Multi-Drop"; |
| 339 | default: |
| 340 | return "unknown"; |
| 341 | } |
| 342 | } |
| 343 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 344 | static const char *obj_name(struct abis_om_fom_hdr *foh) |
| 345 | { |
| 346 | static char retbuf[256]; |
| 347 | |
| 348 | retbuf[0] = 0; |
| 349 | |
| 350 | switch (foh->obj_class) { |
| 351 | case NM_OC_BS11: |
| 352 | strcat(retbuf, "BS11 "); |
| 353 | switch (foh->obj_inst.bts_nr) { |
| 354 | case BS11_OBJ_PA: |
| 355 | sprintf(retbuf+strlen(retbuf), "Power Amplifier %d ", |
| 356 | foh->obj_inst.ts_nr); |
| 357 | break; |
| 358 | case BS11_OBJ_LI: |
| 359 | sprintf(retbuf+strlen(retbuf), "Line Interface "); |
| 360 | break; |
| 361 | case BS11_OBJ_CCLK: |
| 362 | sprintf(retbuf+strlen(retbuf), "CCLK "); |
| 363 | break; |
| 364 | } |
| 365 | break; |
| 366 | case NM_OC_SITE_MANAGER: |
| 367 | strcat(retbuf, "SITE MANAGER "); |
| 368 | break; |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 369 | case NM_OC_BS11_BPORT: |
| 370 | sprintf(retbuf+strlen(retbuf), "BPORT%u ", |
| 371 | foh->obj_inst.bts_nr); |
| 372 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 373 | } |
| 374 | return retbuf; |
| 375 | } |
| 376 | |
| 377 | static void print_state(struct tlv_parsed *tp) |
| 378 | { |
| 379 | if (TLVP_PRESENT(tp, NM_ATT_BS11_BTS_STATE)) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 380 | uint8_t phase, mbccu; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 381 | if (TLVP_LEN(tp, NM_ATT_BS11_BTS_STATE) >= 1) { |
| 382 | phase = *TLVP_VAL(tp, NM_ATT_BS11_BTS_STATE); |
| 383 | printf("PHASE: %u %-20s ", phase & 0xf, |
| 384 | bts_phase_name(phase)); |
| 385 | } |
| 386 | if (TLVP_LEN(tp, NM_ATT_BS11_BTS_STATE) >= 2) { |
| 387 | mbccu = *(TLVP_VAL(tp, NM_ATT_BS11_BTS_STATE)+1); |
| 388 | printf("MBCCU0: %-11s MBCCU1: %-11s ", |
| 389 | mbccu_load_name(mbccu & 0xf), mbccu_load_name(mbccu >> 4)); |
| 390 | } |
| 391 | } |
| 392 | if (TLVP_PRESENT(tp, NM_ATT_BS11_E1_STATE) && |
| 393 | TLVP_LEN(tp, NM_ATT_BS11_E1_STATE) >= 1) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 394 | uint8_t e1_state = *TLVP_VAL(tp, NM_ATT_BS11_E1_STATE); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 395 | printf("Abis-link: %-9s ", linkstate_name(e1_state & 0xf)); |
| 396 | } |
| 397 | printf("\n"); |
| 398 | } |
| 399 | |
| 400 | static int print_attr(struct tlv_parsed *tp) |
| 401 | { |
| 402 | if (TLVP_PRESENT(tp, NM_ATT_BS11_ESN_PCB_SERIAL)) { |
| 403 | printf("\tBS-11 ESN PCB Serial Number: %s\n", |
| 404 | TLVP_VAL(tp, NM_ATT_BS11_ESN_PCB_SERIAL)); |
| 405 | } |
| 406 | if (TLVP_PRESENT(tp, NM_ATT_BS11_ESN_HW_CODE_NO)) { |
| 407 | printf("\tBS-11 ESN Hardware Code Number: %s\n", |
| 408 | TLVP_VAL(tp, NM_ATT_BS11_ESN_HW_CODE_NO)+6); |
| 409 | } |
| 410 | if (TLVP_PRESENT(tp, NM_ATT_BS11_ESN_FW_CODE_NO)) { |
| 411 | printf("\tBS-11 ESN Firmware Code Number: %s\n", |
| 412 | TLVP_VAL(tp, NM_ATT_BS11_ESN_FW_CODE_NO)+6); |
| 413 | } |
| 414 | #if 0 |
| 415 | if (TLVP_PRESENT(tp, NM_ATT_BS11_BOOT_SW_VERS)) { |
| 416 | printf("BS-11 Boot Software Version: %s\n", |
| 417 | TLVP_VAL(tp, NM_ATT_BS11_BOOT_SW_VERS)+6); |
| 418 | } |
| 419 | #endif |
| 420 | if (TLVP_PRESENT(tp, NM_ATT_ABIS_CHANNEL) && |
| 421 | TLVP_LEN(tp, NM_ATT_ABIS_CHANNEL) >= 3) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 422 | const uint8_t *chan = TLVP_VAL(tp, NM_ATT_ABIS_CHANNEL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 423 | printf("\tE1 Channel: Port=%u Timeslot=%u ", |
| 424 | chan[0], chan[1]); |
| 425 | if (chan[2] == 0xff) |
| 426 | printf("(Full Slot)\n"); |
| 427 | else |
| 428 | printf("Subslot=%u\n", chan[2]); |
| 429 | } |
| 430 | if (TLVP_PRESENT(tp, NM_ATT_TEI)) |
| 431 | printf("\tTEI: %d\n", *TLVP_VAL(tp, NM_ATT_TEI)); |
| 432 | if (TLVP_PRESENT(tp, NM_ATT_BS11_TXPWR) && |
| 433 | TLVP_LEN(tp, NM_ATT_BS11_TXPWR) >= 1) { |
| 434 | printf("\tTRX Power: %s\n", |
| 435 | trx_power_name(*TLVP_VAL(tp, NM_ATT_BS11_TXPWR))); |
| 436 | } |
| 437 | if (TLVP_PRESENT(tp, NM_ATT_BS11_PLL_MODE) && |
| 438 | TLVP_LEN(tp, NM_ATT_BS11_PLL_MODE) >= 1) { |
| 439 | printf("\tPLL Mode: %s\n", |
| 440 | pll_mode_name(*TLVP_VAL(tp, NM_ATT_BS11_PLL_MODE))); |
| 441 | } |
| 442 | if (TLVP_PRESENT(tp, NM_ATT_BS11_PLL) && |
| 443 | TLVP_LEN(tp, NM_ATT_BS11_PLL) >= 4) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 444 | const uint8_t *vp = TLVP_VAL(tp, NM_ATT_BS11_PLL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 445 | printf("\tPLL Set Value=%d, Work Value=%d\n", |
| 446 | vp[0] << 8 | vp[1], vp[2] << 8 | vp[3]); |
| 447 | } |
| 448 | if (TLVP_PRESENT(tp, NM_ATT_BS11_CCLK_ACCURACY) && |
| 449 | TLVP_LEN(tp, NM_ATT_BS11_CCLK_ACCURACY) >= 1) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 450 | const uint8_t *acc = TLVP_VAL(tp, NM_ATT_BS11_CCLK_ACCURACY); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 451 | printf("\tCCLK Accuracy: %s (%d)\n", cclk_acc_name(*acc), *acc); |
| 452 | } |
| 453 | if (TLVP_PRESENT(tp, NM_ATT_BS11_CCLK_TYPE) && |
| 454 | TLVP_LEN(tp, NM_ATT_BS11_CCLK_TYPE) >= 1) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 455 | const uint8_t *acc = TLVP_VAL(tp, NM_ATT_BS11_CCLK_TYPE); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 456 | printf("\tCCLK Type=%d\n", *acc); |
| 457 | } |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 458 | if (TLVP_PRESENT(tp, NM_ATT_BS11_LINE_CFG) && |
| 459 | TLVP_LEN(tp, NM_ATT_BS11_LINE_CFG) >= 1) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 460 | const uint8_t *lcfg = TLVP_VAL(tp, NM_ATT_BS11_LINE_CFG); |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 461 | printf("\tLine Configuration: %s (%d)\n", |
| 462 | bport_lcfg_name(*lcfg), *lcfg); |
| 463 | } |
| 464 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 465 | |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static void cmd_query(void) |
| 471 | { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 472 | struct gsm_bts_trx *trx = g_bts->c0; |
| 473 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 474 | bs11cfg_state = STATE_QUERY; |
| 475 | abis_nm_bs11_get_serno(g_bts); |
| 476 | abis_nm_bs11_get_oml_tei_ts(g_bts); |
| 477 | abis_nm_bs11_get_pll_mode(g_bts); |
| 478 | abis_nm_bs11_get_cclk(g_bts); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 479 | abis_nm_bs11_get_trx_power(trx); |
| 480 | trx = gsm_bts_trx_num(g_bts, 1); |
| 481 | if (trx) |
| 482 | abis_nm_bs11_get_trx_power(trx); |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 483 | abis_nm_bs11_get_bport_line_cfg(g_bts, 0); |
| 484 | abis_nm_bs11_get_bport_line_cfg(g_bts, 1); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 485 | sleep(1); |
| 486 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 487 | command = NULL; |
| 488 | } |
| 489 | |
| 490 | /* handle a response from the BTS to a GET STATE command */ |
| 491 | static int handle_state_resp(enum abis_bs11_phase state) |
| 492 | { |
| 493 | int rc = 0; |
| 494 | |
| 495 | switch (state) { |
| 496 | case BS11_STATE_WARM_UP: |
| 497 | case BS11_STATE_LOAD_SMU_SAFETY: |
| 498 | case BS11_STATE_LOAD_SMU_INTENDED: |
| 499 | case BS11_STATE_LOAD_MBCCU: |
| 500 | break; |
| 501 | case BS11_STATE_SOFTWARE_RQD: |
| 502 | bs11cfg_state = STATE_SWLOAD; |
| 503 | /* send safety load. Use g_bts as private 'param' |
| 504 | * argument, so our swload_cbfn can distinguish |
| 505 | * a safety load from a regular software */ |
| 506 | if (file_is_readable(fname_safety)) |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 507 | rc = abis_nm_software_load(g_bts, 0xff, fname_safety, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 508 | win_size, param_forced, |
| 509 | swload_cbfn, g_bts); |
| 510 | else |
| 511 | fprintf(stderr, "No valid Safety Load file \"%s\"\n", |
| 512 | fname_safety); |
| 513 | break; |
| 514 | case BS11_STATE_WAIT_MIN_CFG: |
| 515 | case BS11_STATE_WAIT_MIN_CFG_2: |
| 516 | bs11cfg_state = STATE_SWLOAD; |
| 517 | rc = create_objects(g_bts); |
| 518 | break; |
| 519 | case BS11_STATE_MAINTENANCE: |
| 520 | if (command) { |
| 521 | if (!strcmp(command, "disconnect")) |
| 522 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 523 | else if (!strcmp(command, "reconnect")) |
| 524 | rc = abis_nm_bs11_bsc_disconnect(g_bts, 1); |
| 525 | else if (!strcmp(command, "software") |
| 526 | && bs11cfg_state != STATE_SWLOAD) { |
| 527 | bs11cfg_state = STATE_SWLOAD; |
| 528 | /* send software (FIXME: over A-bis?) */ |
| 529 | if (file_is_readable(fname_software)) |
| 530 | rc = abis_nm_bs11_load_swl(g_bts, fname_software, |
| 531 | win_size, param_forced, |
| 532 | swload_cbfn); |
| 533 | else |
| 534 | fprintf(stderr, "No valid Software file \"%s\"\n", |
| 535 | fname_software); |
| 536 | } else if (!strcmp(command, "delete-trx1")) { |
| 537 | printf("Locing BBSIG and PA objects of TRX1\n"); |
| 538 | abis_nm_chg_adm_state(g_bts, NM_OC_BS11, |
| 539 | BS11_OBJ_BBSIG, 0, 1, |
| 540 | NM_STATE_LOCKED); |
| 541 | abis_nm_chg_adm_state(g_bts, NM_OC_BS11, |
| 542 | BS11_OBJ_PA, 0, 1, |
| 543 | NM_STATE_LOCKED); |
| 544 | sleep(1); |
| 545 | printf("Deleting BBSIG and PA objects of TRX1\n"); |
| 546 | abis_nm_bs11_delete_object(g_bts, BS11_OBJ_BBSIG, 1); |
| 547 | abis_nm_bs11_delete_object(g_bts, BS11_OBJ_PA, 1); |
| 548 | sleep(1); |
| 549 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 550 | command = NULL; |
| 551 | } else if (!strcmp(command, "create-trx1")) { |
| 552 | create_trx1(g_bts); |
| 553 | sleep(1); |
| 554 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 555 | command = NULL; |
| 556 | } else if (!strcmp(command, "pll-e1-locked")) { |
| 557 | abis_nm_bs11_set_pll_locked(g_bts, 1); |
| 558 | sleep(1); |
| 559 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 560 | command = NULL; |
| 561 | } else if (!strcmp(command, "pll-standalone")) { |
| 562 | abis_nm_bs11_set_pll_locked(g_bts, 0); |
| 563 | sleep(1); |
| 564 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 565 | command = NULL; |
Daniel Willmann | b04c503 | 2010-01-07 01:27:50 +0100 | [diff] [blame] | 566 | } else if (!strcmp(command, "pll-setvalue")) { |
| 567 | abis_nm_bs11_set_pll(g_bts, atoi(value)); |
| 568 | sleep(1); |
| 569 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 570 | command = NULL; |
| 571 | } else if (!strcmp(command, "pll-workvalue")) { |
| 572 | /* To set the work value we need to login as FIELD */ |
| 573 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 574 | sleep(1); |
| 575 | abis_nm_bs11_infield_logon(g_bts, 1); |
| 576 | sleep(1); |
| 577 | abis_nm_bs11_set_pll(g_bts, atoi(value)); |
| 578 | sleep(1); |
| 579 | abis_nm_bs11_infield_logon(g_bts, 0); |
| 580 | command = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 581 | } else if (!strcmp(command, "oml-tei")) { |
| 582 | abis_nm_bs11_conn_oml_tei(g_bts, 0, 1, 0xff, TEI_OML); |
| 583 | command = NULL; |
| 584 | } else if (!strcmp(command, "restart")) { |
| 585 | abis_nm_bs11_restart(g_bts); |
| 586 | command = NULL; |
| 587 | } else if (!strcmp(command, "query")) { |
| 588 | cmd_query(); |
Daniel Willmann | 5655afe | 2009-08-10 11:49:36 +0200 | [diff] [blame] | 589 | } else if (!strcmp(command, "create-bport1")) { |
| 590 | abis_nm_bs11_create_bport(g_bts, 1); |
| 591 | sleep(1); |
| 592 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 593 | command = NULL; |
| 594 | } else if (!strcmp(command, "delete-bport1")) { |
| 595 | abis_nm_chg_adm_state(g_bts, NM_OC_BS11_BPORT, 1, 0xff, 0xff, NM_STATE_LOCKED); |
| 596 | sleep(1); |
| 597 | abis_nm_bs11_delete_bport(g_bts, 1); |
| 598 | sleep(1); |
| 599 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 600 | command = NULL; |
| 601 | } else if (!strcmp(command, "bport0-star")) { |
| 602 | abis_nm_bs11_set_bport_line_cfg(g_bts, 0, BS11_LINE_CFG_STAR); |
| 603 | sleep(1); |
| 604 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 605 | command = NULL; |
| 606 | } else if (!strcmp(command, "bport0-multidrop")) { |
| 607 | abis_nm_bs11_set_bport_line_cfg(g_bts, 0, BS11_LINE_CFG_MULTIDROP); |
| 608 | sleep(1); |
| 609 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 610 | command = NULL; |
Harald Welte | 3103720 | 2010-12-14 12:35:59 +0100 | [diff] [blame] | 611 | } else if (!strcmp(command, "bport1-multidrop")) { |
| 612 | abis_nm_bs11_set_bport_line_cfg(g_bts, 1, BS11_LINE_CFG_MULTIDROP); |
| 613 | sleep(1); |
| 614 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 615 | command = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 616 | } |
Harald Welte | 3103720 | 2010-12-14 12:35:59 +0100 | [diff] [blame] | 617 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 618 | } |
| 619 | break; |
| 620 | case BS11_STATE_NORMAL: |
| 621 | if (command) { |
| 622 | if (!strcmp(command, "reconnect")) |
| 623 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 624 | else if (!strcmp(command, "disconnect")) |
| 625 | abis_nm_bs11_bsc_disconnect(g_bts, 0); |
| 626 | else if (!strcmp(command, "query")) { |
| 627 | cmd_query(); |
| 628 | } |
| 629 | } else if (param_disconnect) { |
| 630 | param_disconnect = 0; |
| 631 | abis_nm_bs11_bsc_disconnect(g_bts, 0); |
| 632 | if (param_restart) { |
| 633 | param_restart = 0; |
| 634 | abis_nm_bs11_restart(g_bts); |
| 635 | } |
| 636 | } |
| 637 | break; |
| 638 | default: |
| 639 | break; |
| 640 | } |
| 641 | return rc; |
| 642 | } |
| 643 | |
| 644 | /* handle a fully-received message/packet from the RS232 port */ |
| 645 | int handle_serial_msg(struct msgb *rx_msg) |
| 646 | { |
| 647 | struct abis_om_hdr *oh; |
| 648 | struct abis_om_fom_hdr *foh; |
| 649 | struct tlv_parsed tp; |
| 650 | int rc = -1; |
| 651 | |
| 652 | #if 0 |
| 653 | if (rx_msg->len < LAPD_HDR_LEN |
| 654 | + sizeof(struct abis_om_fom_hdr) |
| 655 | + sizeof(struct abis_om_hdr)) { |
| 656 | if (!memcmp(rx_msg->data + 2, too_fast, |
| 657 | sizeof(too_fast))) { |
| 658 | fprintf(stderr, "BS11 tells us we're too " |
| 659 | "fast, try --delay bigger than %u\n", |
| 660 | delay_ms); |
| 661 | return -E2BIG; |
| 662 | } else |
| 663 | fprintf(stderr, "unknown BS11 message\n"); |
| 664 | } |
| 665 | #endif |
| 666 | |
| 667 | oh = (struct abis_om_hdr *) msgb_l2(rx_msg); |
| 668 | foh = (struct abis_om_fom_hdr *) oh->data; |
| 669 | switch (foh->msg_type) { |
| 670 | case NM_MT_BS11_LMT_LOGON_ACK: |
| 671 | printf("LMT LOGON: ACK\n\n"); |
| 672 | if (bs11cfg_state == STATE_NONE) |
| 673 | bs11cfg_state = STATE_LOGON_ACK; |
| 674 | rc = abis_nm_bs11_get_state(g_bts); |
| 675 | break; |
| 676 | case NM_MT_BS11_LMT_LOGOFF_ACK: |
| 677 | printf("LMT LOGOFF: ACK\n"); |
| 678 | exit(0); |
| 679 | break; |
| 680 | case NM_MT_BS11_GET_STATE_ACK: |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 681 | rc = abis_nm_tlv_parse(&tp, g_bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 682 | print_state(&tp); |
| 683 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_BTS_STATE) && |
| 684 | TLVP_LEN(&tp, NM_ATT_BS11_BTS_STATE) >= 1) |
| 685 | rc = handle_state_resp(*TLVP_VAL(&tp, NM_ATT_BS11_BTS_STATE)); |
| 686 | break; |
| 687 | case NM_MT_GET_ATTR_RESP: |
| 688 | printf("\n%sATTRIBUTES:\n", obj_name(foh)); |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 689 | abis_nm_tlv_parse(&tp, g_bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 690 | rc = print_attr(&tp); |
| 691 | //hexdump(foh->data, oh->length-sizeof(*foh)); |
| 692 | break; |
| 693 | case NM_MT_BS11_SET_ATTR_ACK: |
| 694 | printf("SET ATTRIBUTE ObjClass=0x%02x ObjInst=(%d,%d,%d) ACK\n", |
| 695 | foh->obj_class, foh->obj_inst.bts_nr, |
| 696 | foh->obj_inst.trx_nr, foh->obj_inst.ts_nr); |
| 697 | rc = 0; |
| 698 | break; |
| 699 | case NM_MT_BS11_SET_ATTR_NACK: |
| 700 | printf("SET ATTRIBUTE ObjClass=0x%02x ObjInst=(%d,%d,%d) NACK\n", |
| 701 | foh->obj_class, foh->obj_inst.bts_nr, |
| 702 | foh->obj_inst.trx_nr, foh->obj_inst.ts_nr); |
| 703 | break; |
Harald Welte | d2791a9 | 2010-12-14 13:34:35 +0100 | [diff] [blame] | 704 | case NM_MT_GET_ATTR_NACK: |
| 705 | printf("\n%sGET ATTR NACK\n", obj_name(foh)); |
| 706 | break; |
| 707 | case NM_MT_BS11_CREATE_OBJ_ACK: |
| 708 | printf("\n%sCREATE OBJECT ACK\n", obj_name(foh)); |
| 709 | break; |
| 710 | case NM_MT_BS11_CREATE_OBJ_NACK: |
| 711 | printf("\n%sCREATE OBJECT NACK\n", obj_name(foh)); |
| 712 | break; |
| 713 | case NM_MT_BS11_DELETE_OBJ_ACK: |
| 714 | printf("\n%sDELETE OBJECT ACK\n", obj_name(foh)); |
| 715 | break; |
| 716 | case NM_MT_BS11_DELETE_OBJ_NACK: |
| 717 | printf("\n%sDELETE OBJECT NACK\n", obj_name(foh)); |
| 718 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 719 | default: |
| 720 | rc = abis_nm_rcvmsg(rx_msg); |
| 721 | } |
| 722 | if (rc < 0) { |
| 723 | perror("ERROR in main loop"); |
| 724 | //break; |
| 725 | } |
| 726 | if (rc == 1) |
| 727 | return rc; |
| 728 | |
| 729 | switch (bs11cfg_state) { |
| 730 | case STATE_NONE: |
| 731 | abis_nm_bs11_factory_logon(g_bts, 1); |
| 732 | break; |
| 733 | case STATE_LOGON_ACK: |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 734 | osmo_timer_schedule(&status_timer, 5, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 735 | break; |
| 736 | default: |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | return rc; |
| 741 | } |
| 742 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 743 | void status_timer_cb(void *data) |
| 744 | { |
| 745 | abis_nm_bs11_get_state(g_bts); |
| 746 | } |
| 747 | |
| 748 | static void print_banner(void) |
| 749 | { |
Harald Welte | 4ec2b1d | 2010-12-14 13:14:32 +0100 | [diff] [blame] | 750 | printf("bs11_config (C) 2009-2010 by Harald Welte and Dieter Spaar\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 751 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 752 | } |
| 753 | |
| 754 | static void print_help(void) |
| 755 | { |
| 756 | printf("bs11_config [options] [command]\n"); |
| 757 | printf("\nSupported options:\n"); |
| 758 | printf("\t-h --help\t\t\tPrint this help text\n"); |
| 759 | printf("\t-p --port </dev/ttyXXX>\t\tSpecify serial port\n"); |
| 760 | printf("\t-s --software <file>\t\tSpecify Software file\n"); |
| 761 | printf("\t-S --safety <file>\t\tSpecify Safety Load file\n"); |
Daniel Willmann | b956052 | 2010-01-07 01:26:32 +0100 | [diff] [blame] | 762 | printf("\t-d --delay <ms>\t\t\tSpecify delay in milliseconds\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 763 | printf("\t-D --disconnect\t\t\tDisconnect BTS from BSC\n"); |
| 764 | printf("\t-w --win-size <num>\t\tSpecify Window Size\n"); |
| 765 | printf("\t-f --forced\t\t\tForce Software Load\n"); |
| 766 | printf("\nSupported commands:\n"); |
Daniel Willmann | b956052 | 2010-01-07 01:26:32 +0100 | [diff] [blame] | 767 | printf("\tquery\t\t\tQuery the BS-11 about serial number and configuration\n"); |
| 768 | printf("\tdisconnect\t\tDisconnect A-bis link (go into administrative state)\n"); |
| 769 | printf("\tresconnect\t\tReconnect A-bis link (go into normal state)\n"); |
| 770 | printf("\trestart\t\t\tRestart the BTS\n"); |
| 771 | printf("\tsoftware\t\tDownload Software (only in administrative state)\n"); |
| 772 | printf("\tcreate-trx1\t\tCreate objects for TRX1 (Danger: Your BS-11 might overheat)\n"); |
| 773 | printf("\tdelete-trx1\t\tDelete objects for TRX1\n"); |
| 774 | printf("\tpll-e1-locked\t\tSet the PLL to be locked to E1 clock\n"); |
| 775 | printf("\tpll-standalone\t\tSet the PLL to be in standalone mode\n"); |
Daniel Willmann | b04c503 | 2010-01-07 01:27:50 +0100 | [diff] [blame] | 776 | printf("\tpll-setvalue <value>\tSet the PLL set value\n"); |
| 777 | printf("\tpll-workvalue <value>\tSet the PLL work value\n"); |
Daniel Willmann | b956052 | 2010-01-07 01:26:32 +0100 | [diff] [blame] | 778 | printf("\toml-tei\t\t\tSet OML E1 TS and TEI\n"); |
| 779 | printf("\tbport0-star\t\tSet BPORT0 line config to star\n"); |
Harald Welte | d9ba6f1 | 2010-12-14 13:28:43 +0100 | [diff] [blame] | 780 | printf("\tbport0-multidrop\tSet BPORT0 line config to multidrop\n"); |
| 781 | printf("\tbport1-multidrop\tSet BPORT1 line config to multidrop\n"); |
Daniel Willmann | b956052 | 2010-01-07 01:26:32 +0100 | [diff] [blame] | 782 | printf("\tcreate-bport1\t\tCreate BPORT1 object\n"); |
| 783 | printf("\tdelete-bport1\t\tDelete BPORT1 object\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static void handle_options(int argc, char **argv) |
| 787 | { |
| 788 | int option_index = 0; |
| 789 | print_banner(); |
| 790 | |
| 791 | while (1) { |
| 792 | int c; |
| 793 | static struct option long_options[] = { |
| 794 | { "help", 0, 0, 'h' }, |
| 795 | { "port", 1, 0, 'p' }, |
| 796 | { "software", 1, 0, 's' }, |
| 797 | { "safety", 1, 0, 'S' }, |
| 798 | { "delay", 1, 0, 'd' }, |
| 799 | { "disconnect", 0, 0, 'D' }, |
| 800 | { "win-size", 1, 0, 'w' }, |
| 801 | { "forced", 0, 0, 'f' }, |
| 802 | { "restart", 0, 0, 'r' }, |
| 803 | { "debug", 1, 0, 'b'}, |
| 804 | }; |
| 805 | |
| 806 | c = getopt_long(argc, argv, "hp:s:S:td:Dw:fra:", |
| 807 | long_options, &option_index); |
| 808 | |
| 809 | if (c == -1) |
| 810 | break; |
| 811 | |
| 812 | switch (c) { |
| 813 | case 'h': |
| 814 | print_help(); |
| 815 | exit(0); |
| 816 | case 'p': |
| 817 | serial_port = optarg; |
| 818 | break; |
| 819 | case 'b': |
Harald Welte | 51d2a59 | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 820 | log_parse_category_mask(stderr_target, optarg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 821 | break; |
| 822 | case 's': |
| 823 | fname_software = optarg; |
| 824 | break; |
| 825 | case 'S': |
| 826 | fname_safety = optarg; |
| 827 | break; |
| 828 | case 'd': |
| 829 | delay_ms = atoi(optarg); |
| 830 | break; |
| 831 | case 'w': |
| 832 | win_size = atoi(optarg); |
| 833 | break; |
| 834 | case 'D': |
| 835 | param_disconnect = 1; |
| 836 | break; |
| 837 | case 'f': |
| 838 | param_forced = 1; |
| 839 | break; |
| 840 | case 'r': |
| 841 | param_disconnect = 1; |
| 842 | param_restart = 1; |
| 843 | break; |
| 844 | default: |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | if (optind < argc) |
| 849 | command = argv[optind]; |
Daniel Willmann | b04c503 | 2010-01-07 01:27:50 +0100 | [diff] [blame] | 850 | if (optind+1 < argc) |
| 851 | value = argv[optind+1]; |
| 852 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static int num_sigint; |
| 856 | |
| 857 | static void signal_handler(int signal) |
| 858 | { |
| 859 | fprintf(stdout, "\nsignal %u received\n", signal); |
| 860 | |
| 861 | switch (signal) { |
| 862 | case SIGINT: |
| 863 | num_sigint++; |
| 864 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 865 | if (num_sigint >= 3) |
| 866 | exit(0); |
| 867 | break; |
| 868 | } |
| 869 | } |
| 870 | |
Holger Hans Peter Freyther | 6e19077 | 2010-05-23 21:05:01 +0800 | [diff] [blame] | 871 | extern int bts_model_bs11_init(void); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 872 | int main(int argc, char **argv) |
| 873 | { |
| 874 | struct gsm_network *gsmnet; |
| 875 | int rc; |
| 876 | |
Harald Welte | 51d2a59 | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 877 | log_init(&log_info); |
| 878 | stderr_target = log_target_create_stderr(); |
| 879 | log_add_target(stderr_target); |
| 880 | log_set_all_filter(stderr_target, 1); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 881 | handle_options(argc, argv); |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 882 | bts_model_bs11_init(); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 883 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 884 | gsmnet = gsm_network_init(1, 1, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 885 | if (!gsmnet) { |
| 886 | fprintf(stderr, "Unable to allocate gsm network\n"); |
| 887 | exit(1); |
| 888 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 889 | g_bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_BS11, HARDCODED_TSC, |
| 890 | HARDCODED_BSIC); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 891 | |
| 892 | rc = rs232_setup(serial_port, delay_ms, g_bts); |
| 893 | if (rc < 0) { |
| 894 | fprintf(stderr, "Problem setting up serial port\n"); |
| 895 | exit(1); |
| 896 | } |
| 897 | |
| 898 | signal(SIGINT, &signal_handler); |
| 899 | |
| 900 | abis_nm_bs11_factory_logon(g_bts, 1); |
| 901 | //abis_nm_bs11_get_serno(g_bts); |
| 902 | |
| 903 | status_timer.cb = status_timer_cb; |
| 904 | |
| 905 | while (1) { |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame^] | 906 | osmo_select_main(0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 910 | |
| 911 | exit(0); |
| 912 | } |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 913 | |
| 914 | /* dummy to be able to compile */ |
| 915 | void gsm_net_update_ctype(struct gsm_network *net) |
| 916 | { |
| 917 | } |