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