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 | |
| 297 | static const char *obj_name(struct abis_om_fom_hdr *foh) |
| 298 | { |
| 299 | static char retbuf[256]; |
| 300 | |
| 301 | retbuf[0] = 0; |
| 302 | |
| 303 | switch (foh->obj_class) { |
| 304 | case NM_OC_BS11: |
| 305 | strcat(retbuf, "BS11 "); |
| 306 | switch (foh->obj_inst.bts_nr) { |
| 307 | case BS11_OBJ_PA: |
| 308 | sprintf(retbuf+strlen(retbuf), "Power Amplifier %d ", |
| 309 | foh->obj_inst.ts_nr); |
| 310 | break; |
| 311 | } |
| 312 | break; |
| 313 | case NM_OC_SITE_MANAGER: |
| 314 | strcat(retbuf, "SITE MANAGER "); |
| 315 | break; |
| 316 | } |
| 317 | return retbuf; |
| 318 | } |
| 319 | |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 320 | static void print_state(struct tlv_parsed *tp) |
| 321 | { |
| 322 | if (TLVP_PRESENT(tp, NM_ATT_BS11_BTS_STATE)) { |
| 323 | u_int8_t phase, mbccu; |
| 324 | if (TLVP_LEN(tp, NM_ATT_BS11_BTS_STATE) >= 1) { |
| 325 | phase = *TLVP_VAL(tp, NM_ATT_BS11_BTS_STATE); |
| 326 | printf("PHASE: %u %-20s ", phase & 0xf, |
| 327 | bts_phase_name(phase)); |
| 328 | } |
| 329 | if (TLVP_LEN(tp, NM_ATT_BS11_BTS_STATE) >= 2) { |
| 330 | mbccu = *(TLVP_VAL(tp, NM_ATT_BS11_BTS_STATE)+1); |
| 331 | printf("MBCCU0: %-11s MBCCU1: %-11s ", |
| 332 | mbccu_load_name(mbccu & 0xf), mbccu_load_name(mbccu >> 4)); |
| 333 | } |
| 334 | } |
| 335 | if (TLVP_PRESENT(tp, NM_ATT_BS11_E1_STATE) && |
| 336 | TLVP_LEN(tp, NM_ATT_BS11_E1_STATE) >= 1) { |
| 337 | u_int8_t e1_state = *TLVP_VAL(tp, NM_ATT_BS11_E1_STATE); |
| 338 | printf("Abis-link: %-9s ", linkstate_name(e1_state & 0xf)); |
| 339 | } |
| 340 | printf("\n"); |
| 341 | } |
| 342 | |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 343 | static int print_attr(struct tlv_parsed *tp) |
| 344 | { |
| 345 | if (TLVP_PRESENT(tp, NM_ATT_BS11_ESN_PCB_SERIAL)) { |
| 346 | printf("\tBS-11 ESN PCB Serial Number: %s\n", |
| 347 | TLVP_VAL(tp, NM_ATT_BS11_ESN_PCB_SERIAL)); |
| 348 | } |
| 349 | if (TLVP_PRESENT(tp, NM_ATT_BS11_ESN_HW_CODE_NO)) { |
| 350 | printf("\tBS-11 ESN Hardware Code Number: %s\n", |
| 351 | TLVP_VAL(tp, NM_ATT_BS11_ESN_HW_CODE_NO)+6); |
| 352 | } |
| 353 | if (TLVP_PRESENT(tp, NM_ATT_BS11_ESN_FW_CODE_NO)) { |
| 354 | printf("\tBS-11 ESN Firmware Code Number: %s\n", |
| 355 | TLVP_VAL(tp, NM_ATT_BS11_ESN_FW_CODE_NO)+6); |
| 356 | } |
| 357 | #if 0 |
| 358 | if (TLVP_PRESENT(tp, NM_ATT_BS11_BOOT_SW_VERS)) { |
| 359 | printf("BS-11 Boot Software Version: %s\n", |
| 360 | TLVP_VAL(tp, NM_ATT_BS11_BOOT_SW_VERS)+6); |
| 361 | } |
| 362 | #endif |
| 363 | if (TLVP_PRESENT(tp, NM_ATT_ABIS_CHANNEL) && |
| 364 | TLVP_LEN(tp, NM_ATT_ABIS_CHANNEL) >= 3) { |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 365 | const u_int8_t *chan = TLVP_VAL(tp, NM_ATT_ABIS_CHANNEL); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 366 | printf("\tE1 Channel: Port=%u Timeslot=%u ", |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 367 | chan[0], chan[1]); |
| 368 | if (chan[2] == 0xff) |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 369 | printf("(Full Slot)\n"); |
| 370 | else |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 371 | printf("Subslot=%u\n", chan[2]); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 372 | } |
| 373 | if (TLVP_PRESENT(tp, NM_ATT_TEI)) |
| 374 | printf("\tTEI: %d\n", *TLVP_VAL(tp, NM_ATT_TEI)); |
| 375 | if (TLVP_PRESENT(tp, NM_ATT_BS11_TXPWR) && |
| 376 | TLVP_LEN(tp, NM_ATT_BS11_TXPWR) >= 1) { |
| 377 | printf("\tTRX Power: %s\n", |
| 378 | trx_power_name(*TLVP_VAL(tp, NM_ATT_BS11_TXPWR))); |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 384 | static void cmd_query(void) |
| 385 | { |
| 386 | bs11cfg_state = STATE_QUERY; |
| 387 | abis_nm_bs11_get_serno(g_bts); |
| 388 | abis_nm_bs11_get_oml_tei_ts(g_bts); |
| 389 | abis_nm_bs11_get_trx_power(&g_bts->trx[0]); |
| 390 | abis_nm_bs11_get_trx_power(&g_bts->trx[1]); |
| 391 | sleep(5); |
| 392 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 393 | command = NULL; |
| 394 | } |
| 395 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 396 | /* handle a response from the BTS to a GET STATE command */ |
| 397 | static int handle_state_resp(enum abis_bs11_phase state) |
| 398 | { |
| 399 | int rc = 0; |
| 400 | |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 401 | switch (state) { |
| 402 | case BS11_STATE_WARM_UP: |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 403 | case BS11_STATE_LOAD_SMU_SAFETY: |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 404 | case BS11_STATE_LOAD_SMU_INTENDED: |
Harald Welte | 268bb40 | 2009-02-01 19:11:56 +0000 | [diff] [blame] | 405 | case BS11_STATE_LOAD_MBCCU: |
| 406 | break; |
| 407 | case BS11_STATE_SOFTWARE_RQD: |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 408 | bs11cfg_state = STATE_SWLOAD; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 409 | /* send safety load. Use g_bts as private 'param' |
| 410 | * argument, so our swload_cbfn can distinguish |
| 411 | * a safety load from a regular software */ |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 412 | if (file_is_readable(fname_safety)) |
Harald Welte | 623d531 | 2009-01-29 21:14:05 +0000 | [diff] [blame] | 413 | rc = abis_nm_software_load(g_bts, fname_safety, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 414 | win_size, param_forced, |
| 415 | swload_cbfn, g_bts); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 416 | else |
Harald Welte | 071f34d | 2009-01-29 09:24:38 +0000 | [diff] [blame] | 417 | fprintf(stderr, "No valid Safety Load file \"%s\"\n", |
| 418 | fname_safety); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 419 | break; |
| 420 | case BS11_STATE_WAIT_MIN_CFG: |
| 421 | case BS11_STATE_WAIT_MIN_CFG_2: |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 422 | bs11cfg_state = STATE_SWLOAD; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 423 | rc = create_objects(g_bts); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 424 | break; |
| 425 | case BS11_STATE_MAINTENANCE: |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 426 | if (command) { |
| 427 | if (!strcmp(command, "disconnect")) |
Harald Welte | f80b7d3 | 2009-02-19 03:11:13 +0000 | [diff] [blame] | 428 | abis_nm_bs11_factory_logon(g_bts, 0); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 429 | else if (!strcmp(command, "reconnect")) |
| 430 | rc = abis_nm_bs11_bsc_disconnect(g_bts, 1); |
| 431 | else if (!strcmp(command, "software") |
| 432 | && bs11cfg_state != STATE_SWLOAD) { |
| 433 | bs11cfg_state = STATE_SWLOAD; |
| 434 | /* send software (FIXME: over A-bis?) */ |
| 435 | if (file_is_readable(fname_software)) |
| 436 | rc = abis_nm_bs11_load_swl(g_bts, fname_software, |
| 437 | win_size, param_forced, |
| 438 | swload_cbfn); |
| 439 | else |
| 440 | fprintf(stderr, "No valid Software file \"%s\"\n", |
| 441 | fname_software); |
| 442 | } else if (!strcmp(command, "delete-trx1")) { |
| 443 | abis_nm_bs11_delete_object(g_bts, BS11_OBJ_BBSIG, 1); |
| 444 | abis_nm_bs11_delete_object(g_bts, BS11_OBJ_PA, 1); |
Harald Welte | f80b7d3 | 2009-02-19 03:11:13 +0000 | [diff] [blame] | 445 | sleep(5); |
| 446 | abis_nm_bs11_factory_logon(g_bts, 0); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 447 | command = NULL; |
| 448 | } else if (!strcmp(command, "create-trx1")) { |
| 449 | create_trx1(g_bts); |
Harald Welte | f80b7d3 | 2009-02-19 03:11:13 +0000 | [diff] [blame] | 450 | sleep(5); |
| 451 | abis_nm_bs11_factory_logon(g_bts, 0); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 452 | command = NULL; |
Harald Welte | b6c92ae | 2009-02-21 20:15:32 +0000 | [diff] [blame] | 453 | } else if (!strcmp(command, "oml-tei")) { |
| 454 | 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] | 455 | command = NULL; |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 456 | } else if (!strcmp(command, "restart")) { |
| 457 | abis_nm_bs11_restart(g_bts); |
| 458 | command = NULL; |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 459 | } else if (!strcmp(command, "query")) { |
| 460 | cmd_query(); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 461 | } |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 462 | } |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 463 | break; |
| 464 | case BS11_STATE_NORMAL: |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 465 | if (command) { |
| 466 | if (!strcmp(command, "reconnect")) |
Harald Welte | f80b7d3 | 2009-02-19 03:11:13 +0000 | [diff] [blame] | 467 | abis_nm_bs11_factory_logon(g_bts, 0); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 468 | else if (!strcmp(command, "disconnect")) |
| 469 | abis_nm_bs11_bsc_disconnect(g_bts, 0); |
| 470 | else if (!strcmp(command, "query")) { |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 471 | cmd_query(); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 472 | } |
| 473 | } else if (param_disconnect) { |
Harald Welte | 1cbfaf5 | 2009-02-05 19:30:22 +0000 | [diff] [blame] | 474 | param_disconnect = 0; |
| 475 | abis_nm_bs11_bsc_disconnect(g_bts, 0); |
| 476 | if (param_restart) { |
| 477 | param_restart = 0; |
| 478 | abis_nm_bs11_restart(g_bts); |
| 479 | } |
| 480 | } |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 481 | break; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 482 | default: |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 483 | break; |
| 484 | } |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 485 | return rc; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 488 | /* handle a fully-received message/packet from the RS232 port */ |
Harald Welte | c12d52b | 2009-02-01 21:39:06 +0000 | [diff] [blame] | 489 | int handle_serial_msg(struct msgb *rx_msg) |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 490 | { |
| 491 | struct abis_om_hdr *oh; |
| 492 | struct abis_om_fom_hdr *foh; |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 493 | struct tlv_parsed tp; |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 494 | int rc = -1; |
| 495 | |
Harald Welte | c12d52b | 2009-02-01 21:39:06 +0000 | [diff] [blame] | 496 | #if 0 |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 497 | if (rx_msg->len < LAPD_HDR_LEN |
| 498 | + sizeof(struct abis_om_fom_hdr) |
| 499 | + sizeof(struct abis_om_hdr)) { |
| 500 | if (!memcmp(rx_msg->data + 2, too_fast, |
| 501 | sizeof(too_fast))) { |
| 502 | fprintf(stderr, "BS11 tells us we're too " |
| 503 | "fast, try --delay bigger than %u\n", |
| 504 | delay_ms); |
| 505 | return -E2BIG; |
| 506 | } else |
| 507 | fprintf(stderr, "unknown BS11 message\n"); |
| 508 | } |
Harald Welte | c12d52b | 2009-02-01 21:39:06 +0000 | [diff] [blame] | 509 | #endif |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 510 | |
| 511 | oh = (struct abis_om_hdr *) msgb_l2(rx_msg); |
| 512 | foh = (struct abis_om_fom_hdr *) oh->data; |
| 513 | switch (foh->msg_type) { |
Harald Welte | 043d04a | 2009-01-29 23:15:30 +0000 | [diff] [blame] | 514 | case NM_MT_BS11_LMT_LOGON_ACK: |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 515 | printf("LMT LOGON: ACK\n\n"); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 516 | if (bs11cfg_state == STATE_NONE) |
| 517 | bs11cfg_state = STATE_LOGON_ACK; |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 518 | rc = abis_nm_bs11_get_state(g_bts); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 519 | break; |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 520 | case NM_MT_BS11_LMT_LOGOFF_ACK: |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 521 | printf("LMT LOGOFF: ACK\n"); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 522 | exit(0); |
| 523 | break; |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 524 | case NM_MT_BS11_GET_STATE_ACK: |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 525 | rc = abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 526 | print_state(&tp); |
| 527 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_BTS_STATE) && |
| 528 | TLVP_LEN(&tp, NM_ATT_BS11_BTS_STATE) >= 1) |
| 529 | rc = handle_state_resp(*TLVP_VAL(&tp, NM_ATT_BS11_BTS_STATE)); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 530 | break; |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 531 | case NM_MT_GET_ATTR_RESP: |
| 532 | printf("\n%s ATTRIBUTES:\n", obj_name(foh)); |
| 533 | abis_nm_tlv_parse(&tp, foh->data, oh->length-sizeof(*foh)); |
| 534 | rc = print_attr(&tp); |
| 535 | //hexdump(foh->data, oh->length-sizeof(*foh)); |
| 536 | break; |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 537 | case NM_MT_BS11_SET_ATTR_ACK: |
| 538 | printf("SET ATTRIBUTE ACK\n"); |
| 539 | break; |
| 540 | case NM_MT_BS11_SET_ATTR_NACK: |
| 541 | printf("SET ATTRIBUTE NACK\n"); |
| 542 | break; |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 543 | default: |
| 544 | rc = abis_nm_rcvmsg(rx_msg); |
| 545 | } |
| 546 | if (rc < 0) { |
| 547 | perror("ERROR in main loop"); |
| 548 | //break; |
| 549 | } |
| 550 | if (rc == 1) |
| 551 | return rc; |
| 552 | |
| 553 | switch (bs11cfg_state) { |
| 554 | case STATE_NONE: |
| 555 | abis_nm_bs11_factory_logon(g_bts, 1); |
| 556 | break; |
| 557 | case STATE_LOGON_ACK: |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 558 | schedule_timer(&status_timer, 5, 0); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 559 | break; |
| 560 | default: |
| 561 | break; |
| 562 | } |
| 563 | |
| 564 | return rc; |
| 565 | } |
| 566 | |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 567 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 568 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 569 | { |
| 570 | return 0; |
| 571 | } |
| 572 | |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 573 | void status_timer_cb(void *data) |
| 574 | { |
| 575 | abis_nm_bs11_get_state(g_bts); |
| 576 | } |
| 577 | |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 578 | static void print_banner(void) |
| 579 | { |
| 580 | printf("bs11_config (C) 2009 by Harald Welte and Dieter Spaar\n"); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 581 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | static void print_help(void) |
| 585 | { |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 586 | printf("bs11_config [options] [command]\n"); |
| 587 | printf("\nSupported options:\n"); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 588 | printf("\t-h --help\t\t\tPrint this help text\n"); |
| 589 | printf("\t-p --port </dev/ttyXXX>\t\tSpecify serial port\n"); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 590 | printf("\t-s --software <file>\t\tSpecify Software file\n"); |
| 591 | printf("\t-S --safety <file>\t\tSpecify Safety Load file\n"); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 592 | printf("\t-d --delay <ms>\t\tSpecify delay in milliseconds\n"); |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 593 | printf("\t-D --disconnect\t\t\tDisconnect BTS from BSC\n"); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 594 | printf("\t-w --win-size <num>\t\tSpecify Window Size\n"); |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 595 | printf("\t-f --forced\t\t\tForce Software Load\n"); |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 596 | printf("\nSupported commands:\n"); |
| 597 | printf("\tquery\t\tQuery the BS-11 about serial number and configuration\n"); |
| 598 | printf("\tdisconnect\tDisconnect A-bis link (go into administrative state)\n"); |
| 599 | printf("\tresconnect\tReconnect A-bis link (go into normal state)\n"); |
| 600 | printf("\trestart\t\tRestart the BTS\n"); |
| 601 | printf("\tsoftware\tDownload Software (only in administrative state)\n"); |
| 602 | printf("\tcreate-trx1\tCreate objects for TRX1 (Danger: Your BS-11 might overheat)\n"); |
| 603 | printf("\tdelete-trx1\tDelete objects for TRX1\n"); |
Harald Welte | 074d873 | 2009-02-21 20:41:12 +0000 | [diff] [blame] | 604 | printf("\toml-tei\tSet OML E1 TS and TEI\n"); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void handle_options(int argc, char **argv) |
| 608 | { |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 609 | int option_index = 0; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 610 | print_banner(); |
| 611 | |
| 612 | while (1) { |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 613 | int c; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 614 | static struct option long_options[] = { |
| 615 | { "help", 0, 0, 'h' }, |
| 616 | { "port", 1, 0, 'p' }, |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 617 | { "software", 1, 0, 's' }, |
| 618 | { "safety", 1, 0, 'S' }, |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 619 | { "delay", 1, 0, 'd' }, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 620 | { "disconnect", 0, 0, 'D' }, |
Harald Welte | 623d531 | 2009-01-29 21:14:05 +0000 | [diff] [blame] | 621 | { "win-size", 1, 0, 'w' }, |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 622 | { "forced", 0, 0, 'f' }, |
Harald Welte | 1cbfaf5 | 2009-02-05 19:30:22 +0000 | [diff] [blame] | 623 | { "restart", 0, 0, 'r' }, |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 624 | }; |
| 625 | |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 626 | c = getopt_long(argc, argv, "hp:s:S:td:Dw:fra:", |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 627 | long_options, &option_index); |
| 628 | |
| 629 | if (c == -1) |
| 630 | break; |
| 631 | |
| 632 | switch (c) { |
| 633 | case 'h': |
| 634 | print_help(); |
| 635 | exit(0); |
| 636 | case 'p': |
| 637 | serial_port = optarg; |
| 638 | break; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 639 | case 's': |
| 640 | fname_software = optarg; |
| 641 | break; |
| 642 | case 'S': |
| 643 | fname_safety = optarg; |
| 644 | break; |
Harald Welte | 3b8ba21 | 2009-01-29 12:27:58 +0000 | [diff] [blame] | 645 | case 'd': |
| 646 | delay_ms = atoi(optarg); |
| 647 | break; |
Harald Welte | 623d531 | 2009-01-29 21:14:05 +0000 | [diff] [blame] | 648 | case 'w': |
| 649 | win_size = atoi(optarg); |
| 650 | break; |
Harald Welte | 3ffd137 | 2009-02-01 22:15:49 +0000 | [diff] [blame] | 651 | case 'D': |
| 652 | param_disconnect = 1; |
| 653 | break; |
| 654 | case 'f': |
| 655 | param_forced = 1; |
| 656 | break; |
Harald Welte | 1cbfaf5 | 2009-02-05 19:30:22 +0000 | [diff] [blame] | 657 | case 'r': |
| 658 | param_disconnect = 1; |
| 659 | param_restart = 1; |
| 660 | break; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 661 | default: |
| 662 | break; |
| 663 | } |
| 664 | } |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 665 | if (optind < argc) |
| 666 | command = argv[optind]; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Harald Welte | 7ed1a64 | 2009-02-02 14:45:49 +0000 | [diff] [blame] | 669 | static int num_sigint; |
| 670 | |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 671 | static void signal_handler(int signal) |
| 672 | { |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 673 | fprintf(stdout, "\nsignal %u received\n", signal); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 674 | |
| 675 | switch (signal) { |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 676 | case SIGINT: |
Harald Welte | 7ed1a64 | 2009-02-02 14:45:49 +0000 | [diff] [blame] | 677 | num_sigint++; |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 678 | abis_nm_bs11_factory_logon(g_bts, 0); |
Harald Welte | 7ed1a64 | 2009-02-02 14:45:49 +0000 | [diff] [blame] | 679 | if (num_sigint >= 3) |
| 680 | exit(0); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 681 | break; |
| 682 | } |
| 683 | } |
| 684 | |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 685 | int main(int argc, char **argv) |
| 686 | { |
| 687 | struct gsm_network *gsmnet; |
Harald Welte | f186c46 | 2009-01-29 08:45:19 +0000 | [diff] [blame] | 688 | int rc; |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 689 | |
| 690 | handle_options(argc, argv); |
| 691 | |
Harald Welte | 0313394 | 2009-02-18 19:51:53 +0000 | [diff] [blame] | 692 | gsmnet = gsm_network_init(1, 1, 1, GSM_BTS_TYPE_BS11); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 693 | if (!gsmnet) { |
| 694 | fprintf(stderr, "Unable to allocate gsm network\n"); |
| 695 | exit(1); |
| 696 | } |
| 697 | g_bts = &gsmnet->bts[0]; |
| 698 | |
Harald Welte | 7ed1a64 | 2009-02-02 14:45:49 +0000 | [diff] [blame] | 699 | rc = rs232_setup(serial_port, delay_ms); |
| 700 | if (rc < 0) { |
| 701 | fprintf(stderr, "Problem setting up serial port\n"); |
| 702 | exit(1); |
| 703 | } |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 704 | |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 705 | signal(SIGINT, &signal_handler); |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 706 | |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 707 | abis_nm_bs11_factory_logon(g_bts, 1); |
Harald Welte | 5e4d1b3 | 2009-02-01 13:36:56 +0000 | [diff] [blame] | 708 | //abis_nm_bs11_get_serno(g_bts); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 709 | |
Harald Welte | fb81ae9 | 2009-02-19 02:59:17 +0000 | [diff] [blame] | 710 | status_timer.cb = status_timer_cb; |
| 711 | |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 712 | while (1) { |
Harald Welte | 14f0934 | 2009-01-29 19:28:38 +0000 | [diff] [blame] | 713 | bsc_select_main(); |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | abis_nm_bs11_factory_logon(g_bts, 0); |
| 717 | |
Harald Welte | 61e42ad | 2009-01-18 19:10:46 +0000 | [diff] [blame] | 718 | exit(0); |
| 719 | } |