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