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