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