Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 1 | /* ip.access nanoBTS configuration tool */ |
| 2 | |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2009-2010 by Holger Hans Peter Freyther |
| 5 | * (C) 2009-2010 by On Waves |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <unistd.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <getopt.h> |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 29 | #include <errno.h> |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 30 | #include <sys/fcntl.h> |
| 31 | #include <sys/stat.h> |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 32 | #include <sys/types.h> |
| 33 | |
| 34 | #include <sys/socket.h> |
| 35 | #include <netinet/in.h> |
| 36 | #include <arpa/inet.h> |
| 37 | |
| 38 | |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 39 | #include <osmocore/select.h> |
| 40 | #include <osmocore/timer.h> |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 41 | #include <openbsc/ipaccess.h> |
| 42 | #include <openbsc/gsm_data.h> |
| 43 | #include <openbsc/e1_input.h> |
| 44 | #include <openbsc/abis_nm.h> |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 45 | #include <openbsc/signal.h> |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 46 | #include <openbsc/debug.h> |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 47 | #include <openbsc/network_listen.h> |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 48 | #include <osmocore/talloc.h> |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 49 | |
| 50 | static struct gsm_network *gsmnet; |
| 51 | |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 52 | static int net_listen_testnr; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 53 | static int restart; |
| 54 | static char *prim_oml_ip; |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 55 | static char *bts_ip_addr, *bts_ip_mask, *bts_ip_gw; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 56 | static char *unit_id; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 57 | static u_int16_t nv_flags; |
| 58 | static u_int16_t nv_mask; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 59 | static char *software = NULL; |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 60 | static int sw_load_state = 0; |
Holger Hans Peter Freyther | 2e83782 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 61 | static int oml_state = 0; |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 62 | static int dump_files = 0; |
Holger Hans Peter Freyther | ff9d8b4 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 63 | static char *firmware_analysis = NULL; |
Holger Hans Peter Freyther | 5fbf5f4 | 2010-05-12 16:44:01 +0800 | [diff] [blame] | 64 | static int found_trx = 0; |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 65 | |
| 66 | struct sw_load { |
| 67 | u_int8_t file_id[255]; |
| 68 | u_int8_t file_id_len; |
| 69 | |
| 70 | u_int8_t file_version[255]; |
| 71 | u_int8_t file_version_len; |
| 72 | }; |
| 73 | |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 74 | static void *tall_ctx_config = NULL; |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 75 | static struct sw_load *sw_load1 = NULL; |
| 76 | static struct sw_load *sw_load2 = NULL; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | static u_int8_t prim_oml_attr[] = { 0x95, 0x00, 7, 0x88, 192, 168, 100, 11, 0x00, 0x00 }; |
| 80 | static u_int8_t unit_id_attr[] = { 0x91, 0x00, 9, '2', '3', '4', '2', '/' , '0', '/', '0', 0x00 }; |
| 81 | */ |
| 82 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 83 | /* |
| 84 | * Callback function for NACK on the OML NM |
| 85 | * |
| 86 | * Currently we send the config requests but don't check the |
| 87 | * result. The nanoBTS will send us a NACK when we did something the |
| 88 | * BTS didn't like. |
| 89 | */ |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 90 | static int ipacc_msg_nack(u_int8_t mt) |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 91 | { |
| 92 | fprintf(stderr, "Failure to set attribute. This seems fatal\n"); |
| 93 | exit(-1); |
| 94 | return 0; |
| 95 | } |
| 96 | |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 97 | static void check_restart_or_exit(struct gsm_bts_trx *trx) |
Holger Hans Peter Freyther | ebead59 | 2010-05-12 23:16:59 +0800 | [diff] [blame] | 98 | { |
| 99 | if (restart) { |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 100 | abis_nm_ipaccess_restart(trx); |
Holger Hans Peter Freyther | ebead59 | 2010-05-12 23:16:59 +0800 | [diff] [blame] | 101 | } else { |
| 102 | exit(0); |
| 103 | } |
| 104 | } |
| 105 | |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 106 | static int ipacc_msg_ack(u_int8_t mt, struct gsm_bts_trx *trx) |
Holger Hans Peter Freyther | 086ffa5 | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 107 | { |
| 108 | if (sw_load_state == 1) { |
| 109 | fprintf(stderr, "The new software is activaed.\n"); |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 110 | check_restart_or_exit(trx); |
Holger Hans Peter Freyther | 2e83782 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 111 | } else if (oml_state == 1) { |
Harald Welte | 8c21c07 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 112 | fprintf(stderr, "Set the NV Attributes.\n"); |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 113 | check_restart_or_exit(trx); |
Holger Hans Peter Freyther | 086ffa5 | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Harald Welte | a0b0f36 | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 119 | static const uint8_t phys_conf_min[] = { 0x02 }; |
| 120 | |
| 121 | static uint16_t build_physconf(uint8_t *physconf_buf, const struct rxlev_stats *st) |
| 122 | { |
| 123 | uint16_t *whitelist = (uint16_t *) (physconf_buf + 4); |
| 124 | int num_arfcn; |
| 125 | unsigned int arfcnlist_size; |
| 126 | |
| 127 | /* Create whitelist from rxlevels */ |
| 128 | physconf_buf[0] = phys_conf_min[0]; |
| 129 | physconf_buf[1] = NM_IPAC_EIE_ARFCN_WHITE; |
| 130 | num_arfcn = ipac_rxlevstat2whitelist(whitelist, st); |
| 131 | arfcnlist_size = num_arfcn; // * 2; |
| 132 | *((uint16_t *) (physconf_buf+2)) = htons(arfcnlist_size); |
| 133 | printf("pc_buf (%s)\n", hexdump(physconf_buf, arfcnlist_size+4)); |
| 134 | return arfcnlist_size+4; |
| 135 | } |
Harald Welte | 887deab | 2010-03-06 11:38:05 +0100 | [diff] [blame] | 136 | |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 137 | static int nwl_sig_cb(unsigned int subsys, unsigned int signal, |
| 138 | void *handler_data, void *signal_data) |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 139 | { |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 140 | struct gsm_bts_trx *trx; |
Harald Welte | a0b0f36 | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 141 | uint8_t physconf_buf[2*NUM_ARFCNS+16]; |
| 142 | uint16_t physconf_len; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 143 | |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 144 | switch (signal) { |
| 145 | case S_IPAC_NWL_COMPLETE: |
| 146 | trx = signal_data; |
Harald Welte | 887deab | 2010-03-06 11:38:05 +0100 | [diff] [blame] | 147 | DEBUGP(DNM, "received S_IPAC_NWL_COMPLETE signal\n"); |
Harald Welte | a0b0f36 | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 148 | switch (trx->ipaccess.test_nr) { |
| 149 | case NM_IPACC_TESTNO_CHAN_USAGE: |
| 150 | /* Dump RxLev results */ |
| 151 | rxlev_stat_dump(&trx->ipaccess.rxlev_stat); |
| 152 | /* Create whitelist from results */ |
| 153 | physconf_len = build_physconf(physconf_buf, |
| 154 | &trx->ipaccess.rxlev_stat); |
| 155 | /* Start next test abbout BCCH channel usage */ |
| 156 | ipac_nwl_test_start(trx, NM_IPACC_TESTNO_BCCH_CHAN_USAGE, |
| 157 | physconf_buf, physconf_len); |
| 158 | break; |
| 159 | case NM_IPACC_TESTNO_BCCH_CHAN_USAGE: |
| 160 | /* Dump BCCH RxLev results */ |
| 161 | rxlev_stat_dump(&trx->ipaccess.rxlev_stat); |
| 162 | /* Create whitelist from results */ |
| 163 | physconf_len = build_physconf(physconf_buf, |
| 164 | &trx->ipaccess.rxlev_stat); |
| 165 | /* Start next test about BCCH info */ |
| 166 | ipac_nwl_test_start(trx, NM_IPACC_TESTNO_BCCH_INFO, |
| 167 | physconf_buf, physconf_len); |
| 168 | break; |
| 169 | case NM_IPAC_EIE_BCCH_INFO: |
| 170 | /* re-start full process with CHAN_USAGE */ |
| 171 | DEBUGP(DNM, "starting next test cycle\n"); |
| 172 | ipac_nwl_test_start(trx, net_listen_testnr, phys_conf_min, |
| 173 | sizeof(phys_conf_min)); |
| 174 | break; |
| 175 | } |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 176 | break; |
| 177 | } |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 181 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 182 | void *handler_data, void *signal_data) |
| 183 | { |
Holger Hans Peter Freyther | 2e83782 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 184 | struct ipacc_ack_signal_data *ipacc_data; |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 185 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 186 | switch (signal) { |
| 187 | case S_NM_IPACC_NACK: |
Holger Hans Peter Freyther | 2e83782 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 188 | ipacc_data = signal_data; |
| 189 | return ipacc_msg_nack(ipacc_data->msg_type); |
Holger Hans Peter Freyther | 086ffa5 | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 190 | case S_NM_IPACC_ACK: |
Holger Hans Peter Freyther | 2e83782 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 191 | ipacc_data = signal_data; |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 192 | return ipacc_msg_ack(ipacc_data->msg_type, ipacc_data->trx); |
Holger Hans Peter Freyther | 1356c08 | 2009-12-30 09:00:01 +0100 | [diff] [blame] | 193 | case S_NM_IPACC_RESTART_ACK: |
| 194 | printf("The BTS has acked the restart. Exiting.\n"); |
| 195 | exit(0); |
| 196 | break; |
| 197 | case S_NM_IPACC_RESTART_NACK: |
| 198 | printf("The BTS has nacked the restart. Exiting.\n"); |
| 199 | exit(0); |
| 200 | break; |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 201 | default: |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 208 | /* callback function passed to the ABIS OML code */ |
| 209 | static int percent; |
| 210 | static int percent_old; |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 211 | static int swload_cbfn(unsigned int hook, unsigned int event, struct msgb *_msg, |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 212 | void *data, void *param) |
| 213 | { |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 214 | struct msgb *msg; |
Holger Hans Peter Freyther | d6adf5e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 215 | struct gsm_bts_trx *trx; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 216 | |
| 217 | if (hook != GSM_HOOK_NM_SWLOAD) |
| 218 | return 0; |
| 219 | |
Holger Hans Peter Freyther | d6adf5e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 220 | trx = (struct gsm_bts_trx *) data; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 221 | |
| 222 | switch (event) { |
| 223 | case NM_MT_LOAD_INIT_ACK: |
| 224 | fprintf(stdout, "Software Load Initiate ACK\n"); |
| 225 | break; |
| 226 | case NM_MT_LOAD_INIT_NACK: |
| 227 | fprintf(stderr, "ERROR: Software Load Initiate NACK\n"); |
| 228 | exit(5); |
| 229 | break; |
| 230 | case NM_MT_LOAD_END_ACK: |
| 231 | fprintf(stderr, "LOAD END ACK..."); |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 232 | /* now make it the default */ |
| 233 | sw_load_state = 1; |
| 234 | |
| 235 | msg = msgb_alloc(1024, "sw: nvattr"); |
| 236 | msg->l2h = msgb_put(msg, 3); |
| 237 | msg->l3h = &msg->l2h[3]; |
| 238 | |
| 239 | /* activate software */ |
| 240 | if (sw_load1) { |
| 241 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
| 242 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw_load1->file_id_len, sw_load1->file_id); |
| 243 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw_load1->file_version_len, |
| 244 | sw_load1->file_version); |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 245 | } |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 246 | |
| 247 | if (sw_load2) { |
| 248 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
Holger Hans Peter Freyther | e519896 | 2009-12-29 11:12:00 +0100 | [diff] [blame] | 249 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw_load2->file_id_len, sw_load2->file_id); |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 250 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw_load2->file_version_len, |
| 251 | sw_load2->file_version); |
| 252 | } |
| 253 | |
| 254 | /* fill in the data */ |
| 255 | msg->l2h[0] = NM_ATT_IPACC_CUR_SW_CFG; |
| 256 | msg->l2h[1] = msgb_l3len(msg) >> 8; |
| 257 | msg->l2h[2] = msgb_l3len(msg) & 0xff; |
| 258 | printf("Foo l2h: %p l3h: %p... length l2: %u l3: %u\n", msg->l2h, msg->l3h, msgb_l2len(msg), msgb_l3len(msg)); |
Holger Hans Peter Freyther | d6adf5e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 259 | abis_nm_ipaccess_set_nvattr(trx, msg->l2h, msgb_l2len(msg)); |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 260 | msgb_free(msg); |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 261 | break; |
| 262 | case NM_MT_LOAD_END_NACK: |
| 263 | fprintf(stderr, "ERROR: Software Load End NACK\n"); |
| 264 | exit(3); |
| 265 | break; |
| 266 | case NM_MT_ACTIVATE_SW_NACK: |
| 267 | fprintf(stderr, "ERROR: Activate Software NACK\n"); |
| 268 | exit(4); |
| 269 | break; |
| 270 | case NM_MT_ACTIVATE_SW_ACK: |
| 271 | break; |
| 272 | case NM_MT_LOAD_SEG_ACK: |
Holger Hans Peter Freyther | d6adf5e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 273 | percent = abis_nm_software_load_status(trx->bts); |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 274 | if (percent > percent_old) |
| 275 | printf("Software Download Progress: %d%%\n", percent); |
| 276 | percent_old = percent; |
| 277 | break; |
Holger Hans Peter Freyther | c7aabca | 2009-12-28 12:23:02 +0100 | [diff] [blame] | 278 | case NM_MT_LOAD_ABORT: |
| 279 | fprintf(stderr, "ERROR: Load aborted by the BTS.\n"); |
| 280 | exit(6); |
| 281 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 282 | } |
| 283 | return 0; |
| 284 | } |
| 285 | |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 286 | static void nv_put_ip_if_cfg(struct msgb *nmsg, uint32_t ip, uint32_t mask) |
| 287 | { |
| 288 | msgb_put_u8(nmsg, NM_ATT_IPACC_IP_IF_CFG); |
| 289 | |
| 290 | msgb_put_u32(nmsg, ip); |
| 291 | msgb_put_u32(nmsg, mask); |
| 292 | } |
| 293 | |
| 294 | static void nv_put_gw_cfg(struct msgb *nmsg, uint32_t addr, uint32_t mask, uint32_t gw) |
| 295 | { |
| 296 | msgb_put_u8(nmsg, NM_ATT_IPACC_IP_GW_CFG); |
| 297 | msgb_put_u32(nmsg, addr); |
| 298 | msgb_put_u32(nmsg, mask); |
| 299 | msgb_put_u32(nmsg, gw); |
| 300 | } |
| 301 | |
| 302 | static void nv_put_unit_id(struct msgb *nmsg, const char *unit_id) |
| 303 | { |
| 304 | msgb_tl16v_put(nmsg, NM_ATT_IPACC_UNIT_ID, strlen(unit_id)+1, |
| 305 | (const uint8_t *)unit_id); |
| 306 | } |
| 307 | |
| 308 | static void nv_put_prim_oml(struct msgb *nmsg, uint32_t ip, uint16_t port) |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 309 | { |
| 310 | int len; |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 311 | |
| 312 | /* 0x88 + IP + port */ |
| 313 | len = 1 + sizeof(ip) + sizeof(port); |
| 314 | |
| 315 | msgb_put_u8(nmsg, NM_ATT_IPACC_PRIM_OML_CFG_LIST); |
| 316 | msgb_put_u16(nmsg, len); |
| 317 | |
| 318 | msgb_put_u8(nmsg, 0x88); |
| 319 | |
| 320 | /* IP address */ |
| 321 | msgb_put_u32(nmsg, ip); |
| 322 | |
| 323 | /* port number */ |
| 324 | msgb_put_u16(nmsg, port); |
| 325 | } |
| 326 | |
| 327 | static void nv_put_flags(struct msgb *nmsg, uint16_t nv_flags, uint16_t nv_mask) |
| 328 | { |
| 329 | msgb_put_u8(nmsg, NM_ATT_IPACC_NV_FLAGS); |
| 330 | msgb_put_u16(nmsg, sizeof(nv_flags) + sizeof(nv_mask)); |
| 331 | msgb_put_u8(nmsg, nv_flags & 0xff); |
| 332 | msgb_put_u8(nmsg, nv_mask & 0xff); |
| 333 | msgb_put_u8(nmsg, nv_flags >> 8); |
| 334 | msgb_put_u8(nmsg, nv_mask >> 8); |
| 335 | } |
| 336 | |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 337 | /* human-readable names for the ip.access nanoBTS NVRAM Flags */ |
| 338 | static const struct value_string ipa_nvflag_strs[] = { |
| 339 | { 0x0001, "static-ip" }, |
| 340 | { 0x0002, "static-gw" }, |
| 341 | { 0x0004, "no-dhcp-vsi" }, |
| 342 | { 0x0008, "dhcp-enabled" }, |
| 343 | { 0x0040, "led-disabled" }, |
| 344 | { 0x0100, "secondary-oml-enabled" }, |
| 345 | { 0x0200, "diag-enabled" }, |
| 346 | { 0x0400, "cli-enabled" }, |
| 347 | { 0x0800, "http-enabled" }, |
| 348 | { 0x1000, "post-enabled" }, |
| 349 | { 0x2000, "snmp-enabled" }, |
| 350 | { 0, NULL } |
| 351 | }; |
| 352 | |
| 353 | /* set the flags in flags/mask according to a string-identified flag and 'enable' */ |
| 354 | static int ipa_nvflag_set(uint16_t *flags, uint16_t *mask, const char *name, int en) |
| 355 | { |
| 356 | int rc; |
| 357 | rc = get_string_value(ipa_nvflag_strs, name); |
| 358 | if (rc < 0) |
| 359 | return rc; |
| 360 | |
| 361 | *mask |= rc; |
| 362 | if (en) |
| 363 | *flags |= rc; |
| 364 | else |
| 365 | *flags &= ~rc; |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 370 | static void bootstrap_om(struct gsm_bts_trx *trx) |
| 371 | { |
Harald Welte | 8c21c07 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 372 | struct msgb *nmsg = msgb_alloc(1024, "nested msgb"); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 373 | int need_to_set_attr = 0; |
| 374 | int len; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 375 | |
Holger Hans Peter Freyther | 5fbf5f4 | 2010-05-12 16:44:01 +0800 | [diff] [blame] | 376 | printf("OML link established using TRX %d\n", trx->nr); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 377 | |
| 378 | if (unit_id) { |
| 379 | len = strlen(unit_id); |
Harald Welte | 8c21c07 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 380 | if (len > nmsg->data_len-10) |
| 381 | goto out_err; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 382 | printf("setting Unit ID to '%s'\n", unit_id); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 383 | nv_put_unit_id(nmsg, unit_id); |
| 384 | need_to_set_attr = 1; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 385 | } |
| 386 | if (prim_oml_ip) { |
| 387 | struct in_addr ia; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 388 | |
| 389 | if (!inet_aton(prim_oml_ip, &ia)) { |
| 390 | fprintf(stderr, "invalid IP address: %s\n", |
| 391 | prim_oml_ip); |
Harald Welte | 8c21c07 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 392 | goto out_err; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Harald Welte | 4802b88 | 2009-04-30 16:23:45 +0000 | [diff] [blame] | 395 | printf("setting primary OML link IP to '%s'\n", inet_ntoa(ia)); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 396 | nv_put_prim_oml(nmsg, ntohl(ia.s_addr), 0); |
| 397 | need_to_set_attr = 1; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 398 | } |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 399 | if (nv_mask) { |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 400 | printf("setting NV Flags/Mask to 0x%04x/0x%04x\n", |
| 401 | nv_flags, nv_mask); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 402 | nv_put_flags(nmsg, nv_flags, nv_mask); |
| 403 | need_to_set_attr = 1; |
| 404 | } |
| 405 | if (bts_ip_addr && bts_ip_mask) { |
| 406 | struct in_addr ia_addr, ia_mask; |
| 407 | |
| 408 | if (!inet_aton(bts_ip_addr, &ia_addr)) { |
| 409 | fprintf(stderr, "invalid IP address: %s\n", |
| 410 | bts_ip_addr); |
| 411 | goto out_err; |
| 412 | } |
| 413 | |
| 414 | if (!inet_aton(bts_ip_mask, &ia_mask)) { |
| 415 | fprintf(stderr, "invalid IP address: %s\n", |
| 416 | bts_ip_mask); |
| 417 | goto out_err; |
| 418 | } |
| 419 | |
| 420 | printf("setting static IP Address/Mask\n"); |
| 421 | nv_put_ip_if_cfg(nmsg, ntohl(ia_addr.s_addr), ntohl(ia_mask.s_addr)); |
| 422 | need_to_set_attr = 1; |
| 423 | } |
| 424 | if (bts_ip_gw) { |
| 425 | struct in_addr ia_gw; |
| 426 | |
| 427 | if (!inet_aton(bts_ip_gw, &ia_gw)) { |
| 428 | fprintf(stderr, "invalid IP address: %s\n", |
| 429 | bts_ip_gw); |
| 430 | goto out_err; |
| 431 | } |
| 432 | |
| 433 | printf("setting static IP Gateway\n"); |
| 434 | /* we only set the default gateway with zero addr/mask */ |
| 435 | nv_put_gw_cfg(nmsg, 0, 0, ntohl(ia_gw.s_addr)); |
| 436 | need_to_set_attr = 1; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 437 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 438 | |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 439 | if (need_to_set_attr) { |
| 440 | abis_nm_ipaccess_set_nvattr(trx, nmsg->head, nmsg->len); |
| 441 | oml_state = 1; |
| 442 | } |
Harald Welte | 8c21c07 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 443 | |
Holger Hans Peter Freyther | 2e83782 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 444 | if (restart && !prim_oml_ip && !software) { |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 445 | printf("restarting BTS\n"); |
Holger Hans Peter Freyther | 52fd4e4 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 446 | abis_nm_ipaccess_restart(trx); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 447 | } |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 448 | |
Harald Welte | 8c21c07 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 449 | out_err: |
| 450 | msgb_free(nmsg); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
| 454 | { |
| 455 | switch (event) { |
| 456 | case EVT_E1_TEI_UP: |
| 457 | switch (type) { |
| 458 | case E1INP_SIGN_OML: |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 459 | break; |
| 460 | case E1INP_SIGN_RSL: |
| 461 | /* FIXME */ |
| 462 | break; |
| 463 | default: |
| 464 | break; |
| 465 | } |
| 466 | break; |
| 467 | case EVT_E1_TEI_DN: |
| 468 | fprintf(stderr, "Lost some E1 TEI link\n"); |
| 469 | /* FIXME: deal with TEI or L1 link loss */ |
| 470 | break; |
| 471 | default: |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
Holger Hans Peter Freyther | aa0db80 | 2010-05-13 00:37:48 +0800 | [diff] [blame] | 477 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state, |
| 478 | struct abis_om_obj_inst *obj_inst) |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 479 | { |
Holger Hans Peter Freyther | 5fbf5f4 | 2010-05-12 16:44:01 +0800 | [diff] [blame] | 480 | if (obj_class == NM_OC_BASEB_TRANSC) { |
| 481 | if (!found_trx && obj_inst->trx_nr != 0xff) { |
| 482 | struct gsm_bts_trx *trx = container_of(obj, struct gsm_bts_trx, bb_transc); |
| 483 | bootstrap_om(trx); |
| 484 | found_trx = 1; |
| 485 | } |
| 486 | } else if (evt == EVT_STATECHG_OPER && |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 487 | obj_class == NM_OC_RADIO_CARRIER && |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 488 | new_state->availability == 3) { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 489 | struct gsm_bts_trx *trx = obj; |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 490 | |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 491 | if (net_listen_testnr) |
Harald Welte | a0b0f36 | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 492 | ipac_nwl_test_start(trx, net_listen_testnr, |
| 493 | phys_conf_min, sizeof(phys_conf_min)); |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 494 | else if (software) { |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 495 | int rc; |
| 496 | printf("Attempting software upload with '%s'\n", software); |
Holger Hans Peter Freyther | d6adf5e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 497 | rc = abis_nm_software_load(trx->bts, trx->nr, software, 19, 0, swload_cbfn, trx); |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 498 | if (rc < 0) { |
| 499 | fprintf(stderr, "Failed to start software load\n"); |
| 500 | exit(-3); |
| 501 | } |
| 502 | } |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 503 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
Holger Hans Peter Freyther | f7dbd58 | 2009-12-30 09:31:31 +0100 | [diff] [blame] | 507 | static struct sw_load *create_swload(struct sdp_header *header) |
| 508 | { |
| 509 | struct sw_load *load; |
| 510 | |
| 511 | load = talloc_zero(tall_ctx_config, struct sw_load); |
| 512 | |
| 513 | strncpy((char *)load->file_id, header->firmware_info.sw_part, 20); |
| 514 | load->file_id_len = strlen(header->firmware_info.sw_part) + 1; |
| 515 | |
| 516 | strncpy((char *)load->file_version, header->firmware_info.version, 20); |
| 517 | load->file_version_len = strlen(header->firmware_info.version) + 1; |
| 518 | |
| 519 | return load; |
| 520 | } |
| 521 | |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 522 | static int find_sw_load_params(const char *filename) |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 523 | { |
| 524 | struct stat stat; |
| 525 | struct sdp_header *header; |
| 526 | struct llist_head *entry; |
| 527 | int fd; |
| 528 | void *tall_firm_ctx = 0; |
| 529 | |
| 530 | entry = talloc_zero(tall_firm_ctx, struct llist_head); |
| 531 | INIT_LLIST_HEAD(entry); |
| 532 | |
| 533 | fd = open(filename, O_RDONLY); |
| 534 | if (!fd) { |
| 535 | perror("nada"); |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 536 | return -1; |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* verify the file */ |
| 540 | if (fstat(fd, &stat) == -1) { |
| 541 | perror("Can not stat the file"); |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 542 | return -1; |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | ipaccess_analyze_file(fd, stat.st_size, 0, entry); |
| 546 | if (close(fd) != 0) { |
| 547 | perror("Close failed.\n"); |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 548 | return -1; |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /* try to find what we are looking for */ |
| 552 | llist_for_each_entry(header, entry, entry) { |
| 553 | if (ntohs(header->firmware_info.more_more_magic) == 0x1000) { |
Holger Hans Peter Freyther | f7dbd58 | 2009-12-30 09:31:31 +0100 | [diff] [blame] | 554 | sw_load1 = create_swload(header); |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 555 | } else if (ntohs(header->firmware_info.more_more_magic) == 0x2001) { |
Holger Hans Peter Freyther | f7dbd58 | 2009-12-30 09:31:31 +0100 | [diff] [blame] | 556 | sw_load2 = create_swload(header); |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 560 | if (!sw_load1 || !sw_load2) { |
| 561 | fprintf(stderr, "Did not find data.\n"); |
| 562 | talloc_free(tall_firm_ctx); |
| 563 | return -1; |
| 564 | } |
| 565 | |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 566 | talloc_free(tall_firm_ctx); |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 567 | return 0; |
Holger Hans Peter Freyther | f9811de | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 570 | static void dump_entry(struct sdp_header_item *sub_entry, int part, int fd) |
| 571 | { |
| 572 | int out_fd; |
| 573 | int copied; |
| 574 | char filename[4096]; |
| 575 | off_t target; |
| 576 | |
| 577 | if (!dump_files) |
| 578 | return; |
| 579 | |
| 580 | if (sub_entry->header_entry.something1 == 0) |
| 581 | return; |
| 582 | |
| 583 | snprintf(filename, sizeof(filename), "part.%d", part++); |
| 584 | out_fd = open(filename, O_WRONLY | O_CREAT, 0660); |
| 585 | if (out_fd < 0) { |
| 586 | perror("Can not dump firmware"); |
| 587 | return; |
| 588 | } |
| 589 | |
Holger Hans Peter Freyther | d859a24 | 2010-03-22 11:50:30 +0100 | [diff] [blame] | 590 | target = sub_entry->absolute_offset + ntohl(sub_entry->header_entry.start) + 4; |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 591 | if (lseek(fd, target, SEEK_SET) != target) { |
| 592 | perror("seek failed"); |
| 593 | close(out_fd); |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | for (copied = 0; copied < ntohl(sub_entry->header_entry.length); ++copied) { |
| 598 | char c; |
| 599 | if (read(fd, &c, sizeof(c)) != sizeof(c)) { |
| 600 | perror("copy failed"); |
| 601 | break; |
| 602 | } |
| 603 | |
| 604 | if (write(out_fd, &c, sizeof(c)) != sizeof(c)) { |
| 605 | perror("write failed"); |
| 606 | break; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | close(out_fd); |
| 611 | } |
| 612 | |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 613 | static void analyze_firmware(const char *filename) |
| 614 | { |
| 615 | struct stat stat; |
| 616 | struct sdp_header *header; |
| 617 | struct sdp_header_item *sub_entry; |
| 618 | struct llist_head *entry; |
| 619 | int fd; |
| 620 | void *tall_firm_ctx = 0; |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 621 | int part = 0; |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 622 | |
| 623 | entry = talloc_zero(tall_firm_ctx, struct llist_head); |
| 624 | INIT_LLIST_HEAD(entry); |
| 625 | |
| 626 | printf("Opening possible firmware '%s'\n", filename); |
| 627 | fd = open(filename, O_RDONLY); |
| 628 | if (!fd) { |
| 629 | perror("nada"); |
| 630 | return; |
| 631 | } |
| 632 | |
| 633 | /* verify the file */ |
| 634 | if (fstat(fd, &stat) == -1) { |
| 635 | perror("Can not stat the file"); |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | ipaccess_analyze_file(fd, stat.st_size, 0, entry); |
| 640 | |
| 641 | llist_for_each_entry(header, entry, entry) { |
| 642 | printf("Printing header information:\n"); |
| 643 | printf("more_more_magic: 0x%x\n", ntohs(header->firmware_info.more_more_magic)); |
| 644 | printf("header_length: %u\n", ntohl(header->firmware_info.header_length)); |
| 645 | printf("file_length: %u\n", ntohl(header->firmware_info.file_length)); |
| 646 | printf("sw_part: %.20s\n", header->firmware_info.sw_part); |
| 647 | printf("text1: %.64s\n", header->firmware_info.text1); |
| 648 | printf("time: %.12s\n", header->firmware_info.time); |
| 649 | printf("date: %.14s\n", header->firmware_info.date); |
| 650 | printf("text2: %.10s\n", header->firmware_info.text2); |
| 651 | printf("version: %.20s\n", header->firmware_info.version); |
| 652 | printf("subitems...\n"); |
| 653 | |
| 654 | llist_for_each_entry(sub_entry, &header->header_list, entry) { |
| 655 | printf("\tsomething1: %u\n", sub_entry->header_entry.something1); |
| 656 | printf("\ttext1: %.64s\n", sub_entry->header_entry.text1); |
| 657 | printf("\ttime: %.12s\n", sub_entry->header_entry.time); |
| 658 | printf("\tdate: %.14s\n", sub_entry->header_entry.date); |
| 659 | printf("\ttext2: %.10s\n", sub_entry->header_entry.text2); |
| 660 | printf("\tversion: %.20s\n", sub_entry->header_entry.version); |
| 661 | printf("\tlength: %u\n", ntohl(sub_entry->header_entry.length)); |
| 662 | printf("\taddr1: 0x%x\n", ntohl(sub_entry->header_entry.addr1)); |
| 663 | printf("\taddr2: 0x%x\n", ntohl(sub_entry->header_entry.addr2)); |
| 664 | printf("\tstart: 0x%x\n", ntohl(sub_entry->header_entry.start)); |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 665 | printf("\tabs. offset: 0x%lx\n", sub_entry->absolute_offset); |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 666 | printf("\n\n"); |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 667 | |
| 668 | dump_entry(sub_entry, part++, fd); |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 669 | } |
| 670 | printf("\n\n"); |
| 671 | } |
| 672 | |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 673 | if (close(fd) != 0) { |
| 674 | perror("Close failed.\n"); |
| 675 | return; |
| 676 | } |
| 677 | |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 678 | talloc_free(tall_firm_ctx); |
| 679 | } |
| 680 | |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 681 | static void print_usage(void) |
| 682 | { |
| 683 | printf("Usage: ipaccess-config\n"); |
| 684 | } |
| 685 | |
| 686 | static void print_help(void) |
| 687 | { |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 688 | #if 0 |
| 689 | printf("Commmands for reading from the BTS:\n"); |
| 690 | printf(" -D --dump\t\t\tDump the BTS configuration\n"); |
| 691 | printf("\n"); |
| 692 | #endif |
| 693 | printf("Commmands for writing to the BTS:\n"); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 694 | printf(" -u --unit-id UNIT_ID\t\tSet the Unit ID of the BTS\n"); |
| 695 | printf(" -o --oml-ip IP\t\tSet primary OML IP (IP of your BSC)\n"); |
| 696 | printf(" -i --ip-address IP/MASK\tSet static IP address + netmask of BTS\n"); |
| 697 | printf(" -g --ip-gateway IP\t\tSet static IP gateway of BTS\n"); |
| 698 | printf(" -r --restart\t\t\tRestart the BTS (after other operations)\n"); |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 699 | printf(" -n --nvram-flags FLAGS/MASK\tSet NVRAM attributes\n"); |
| 700 | printf(" -S --nvattr-set FLAG\tSet one additional NVRAM attribute\n"); |
| 701 | printf(" -U --nvattr-unset FLAG\tSet one additional NVRAM attribute\n"); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 702 | printf(" -l --listen TESTNR\t\tPerform specified test number\n"); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 703 | printf(" -s --stream-id ID\t\tSet the IPA Stream Identifier for OML\n"); |
| 704 | printf(" -d --software FIRMWARE\tDownload firmware into BTS\n"); |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 705 | printf("\n"); |
| 706 | printf("Miscellaneous commands:\n"); |
| 707 | printf(" -h --help\t\t\tthis text\n"); |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 708 | printf(" -f --firmware FIRMWARE\tProvide firmware information\n"); |
| 709 | printf(" -w --write-firmware\t\tThis will dump the firmware parts to the filesystem. Use with -f.\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 710 | } |
| 711 | |
Holger Hans Peter Freyther | e15ad48 | 2010-05-14 02:54:40 +0800 | [diff] [blame] | 712 | extern void bts_model_nanobts_init(); |
| 713 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 714 | int main(int argc, char **argv) |
| 715 | { |
| 716 | struct gsm_bts *bts; |
| 717 | struct sockaddr_in sin; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 718 | int rc, option_index = 0, stream_id = 0xff; |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 719 | struct log_target *stderr_target; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 720 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 721 | log_init(&log_info); |
| 722 | stderr_target = log_target_create_stderr(); |
| 723 | log_add_target(stderr_target); |
| 724 | log_set_all_filter(stderr_target, 1); |
| 725 | log_set_log_level(stderr_target, 0); |
| 726 | log_parse_category_mask(stderr_target, "DNM,0"); |
Harald Welte | a855d1f | 2010-01-10 18:37:38 +0100 | [diff] [blame] | 727 | bts_model_nanobts_init(); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 728 | |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 729 | printf("ipaccess-config (C) 2009-2010 by Harald Welte and others\n"); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 730 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 731 | |
| 732 | while (1) { |
| 733 | int c; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 734 | unsigned long ul; |
| 735 | char *slash; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 736 | static struct option long_options[] = { |
| 737 | { "unit-id", 1, 0, 'u' }, |
| 738 | { "oml-ip", 1, 0, 'o' }, |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 739 | { "ip-address", 1, 0, 'i' }, |
| 740 | { "ip-gateway", 1, 0, 'g' }, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 741 | { "restart", 0, 0, 'r' }, |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 742 | { "nvram-flags", 1, 0, 'n' }, |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 743 | { "nvattr-set", 1, 0, 'S' }, |
| 744 | { "nvattr-unset", 1, 0, 'U' }, |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 745 | { "help", 0, 0, 'h' }, |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 746 | { "listen", 1, 0, 'l' }, |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 747 | { "stream-id", 1, 0, 's' }, |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 748 | { "software", 1, 0, 'd' }, |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 749 | { "firmware", 1, 0, 'f' }, |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 750 | { "write-firmware", 0, 0, 'w' }, |
Holger Hans Peter Freyther | 7d45ea4 | 2010-04-20 22:22:00 +0800 | [diff] [blame] | 751 | { 0, 0, 0, 0 }, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 752 | }; |
| 753 | |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 754 | c = getopt_long(argc, argv, "u:o:i:g:rn:S:U:l:hs:d:f:w", long_options, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 755 | &option_index); |
| 756 | |
| 757 | if (c == -1) |
| 758 | break; |
| 759 | |
| 760 | switch (c) { |
| 761 | case 'u': |
| 762 | unit_id = optarg; |
| 763 | break; |
| 764 | case 'o': |
| 765 | prim_oml_ip = optarg; |
| 766 | break; |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 767 | case 'i': |
| 768 | slash = strchr(optarg, '/'); |
| 769 | if (!slash) |
| 770 | exit(2); |
| 771 | bts_ip_addr = optarg; |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 772 | *slash = 0; |
Harald Welte | 0aef73e | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 773 | bts_ip_mask = slash+1; |
| 774 | break; |
| 775 | case 'g': |
| 776 | bts_ip_gw = optarg; |
| 777 | break; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 778 | case 'r': |
| 779 | restart = 1; |
| 780 | break; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 781 | case 'n': |
| 782 | slash = strchr(optarg, '/'); |
| 783 | if (!slash) |
| 784 | exit(2); |
| 785 | ul = strtoul(optarg, NULL, 16); |
| 786 | nv_flags = ul & 0xffff; |
| 787 | ul = strtoul(slash+1, NULL, 16); |
| 788 | nv_mask = ul & 0xffff; |
| 789 | break; |
Harald Welte | 0f43dbc | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 790 | case 'S': |
| 791 | if (ipa_nvflag_set(&nv_flags, &nv_mask, optarg, 1) < 0) |
| 792 | exit(2); |
| 793 | break; |
| 794 | case 'U': |
| 795 | if (ipa_nvflag_set(&nv_flags, &nv_mask, optarg, 0) < 0) |
| 796 | exit(2); |
| 797 | break; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 798 | case 'l': |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 799 | net_listen_testnr = atoi(optarg); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 800 | break; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 801 | case 's': |
| 802 | stream_id = atoi(optarg); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 803 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 804 | case 'd': |
| 805 | software = strdup(optarg); |
Holger Hans Peter Freyther | 6e79b54 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 806 | if (find_sw_load_params(optarg) != 0) |
| 807 | exit(0); |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 808 | break; |
Holger Hans Peter Freyther | dade898 | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 809 | case 'f': |
Holger Hans Peter Freyther | ff9d8b4 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 810 | firmware_analysis = optarg; |
| 811 | break; |
Holger Hans Peter Freyther | 38722cc | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 812 | case 'w': |
| 813 | dump_files = 1; |
| 814 | break; |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 815 | case 'h': |
| 816 | print_usage(); |
| 817 | print_help(); |
| 818 | exit(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 819 | } |
| 820 | }; |
| 821 | |
Holger Hans Peter Freyther | ff9d8b4 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 822 | if (firmware_analysis) |
| 823 | analyze_firmware(firmware_analysis); |
| 824 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 825 | if (optind >= argc) { |
Holger Hans Peter Freyther | ff9d8b4 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 826 | /* only warn if we have not done anything else */ |
| 827 | if (!firmware_analysis) |
| 828 | fprintf(stderr, "you have to specify the IP address of the BTS. Use --help for more information\n"); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 829 | exit(2); |
| 830 | } |
| 831 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 832 | gsmnet = gsm_network_init(1, 1, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 833 | if (!gsmnet) |
| 834 | exit(1); |
| 835 | |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 836 | bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_NANOBTS, HARDCODED_TSC, |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 837 | HARDCODED_BSIC); |
Harald Welte (local) | 93f4207 | 2009-12-28 23:15:36 +0100 | [diff] [blame] | 838 | /* ip.access supports up to 4 chained TRX */ |
| 839 | gsm_bts_trx_alloc(bts); |
| 840 | gsm_bts_trx_alloc(bts); |
| 841 | gsm_bts_trx_alloc(bts); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 842 | bts->oml_tei = stream_id; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 843 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 844 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | 549faad | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 845 | register_signal_handler(SS_IPAC_NWL, nwl_sig_cb, NULL); |
| 846 | |
| 847 | ipac_nwl_init(); |
| 848 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 849 | printf("Trying to connect to ip.access BTS ...\n"); |
| 850 | |
| 851 | memset(&sin, 0, sizeof(sin)); |
| 852 | sin.sin_family = AF_INET; |
| 853 | inet_aton(argv[optind], &sin.sin_addr); |
| 854 | rc = ia_config_connect(bts, &sin); |
| 855 | if (rc < 0) { |
| 856 | perror("Error connecting to the BTS"); |
| 857 | exit(1); |
| 858 | } |
| 859 | |
| 860 | while (1) { |
Harald Welte | 04d3c92 | 2009-05-23 06:07:04 +0000 | [diff] [blame] | 861 | rc = bsc_select_main(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 862 | if (rc < 0) |
| 863 | exit(3); |
| 864 | } |
| 865 | |
| 866 | exit(0); |
| 867 | } |
| 868 | |