Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1 | /* ip.access nanoBTS configuration tool */ |
| 2 | |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 69dbdee | 2011-04-11 19:32:35 +0200 | [diff] [blame] | 4 | * (C) 2009-2011 by Holger Hans Peter Freyther |
Holger Hans Peter Freyther | 5180844 | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 5 | * (C) 2009-2010 by On-Waves |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 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 |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 17 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <unistd.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <getopt.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 28 | #include <errno.h> |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/stat.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 31 | |
| 32 | #include <sys/socket.h> |
| 33 | #include <netinet/in.h> |
| 34 | #include <arpa/inet.h> |
| 35 | |
| 36 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 37 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 38 | #include <osmocom/core/select.h> |
| 39 | #include <osmocom/core/timer.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 40 | #include <openbsc/ipaccess.h> |
Neels Hofmeyr | b46b0a6 | 2016-05-14 00:57:04 +0200 | [diff] [blame] | 41 | #include <openbsc/common_bsc.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 42 | #include <osmocom/abis/e1_input.h> |
| 43 | #include <openbsc/abis_nm.h> |
| 44 | #include <openbsc/signal.h> |
| 45 | #include <openbsc/debug.h> |
| 46 | #include <openbsc/network_listen.h> |
| 47 | #include <osmocom/abis/ipaccess.h> |
| 48 | #include <openbsc/gsm_data.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 49 | #include <openbsc/abis_nm.h> |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 50 | #include <openbsc/signal.h> |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 51 | #include <openbsc/debug.h> |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 52 | #include <openbsc/network_listen.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 53 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 54 | #include <osmocom/abis/abis.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 55 | |
Holger Hans Peter Freyther | ed8cc0e | 2013-04-24 11:36:15 +0200 | [diff] [blame] | 56 | struct gsm_network *bsc_gsmnet; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 57 | |
Harald Welte | 12a721e | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 58 | static int net_listen_testnr; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 59 | static int restart; |
| 60 | static char *prim_oml_ip; |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 61 | static char *bts_ip_addr, *bts_ip_mask, *bts_ip_gw; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 62 | static char *unit_id; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 63 | static uint16_t nv_flags; |
| 64 | static uint16_t nv_mask; |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 65 | static char *software = NULL; |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 66 | static int sw_load_state = 0; |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 67 | static int oml_state = 0; |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 68 | static int dump_files = 0; |
Holger Hans Peter Freyther | 70c67d5 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 69 | static char *firmware_analysis = NULL; |
Holger Hans Peter Freyther | f39ff07 | 2010-05-12 16:44:01 +0800 | [diff] [blame] | 70 | static int found_trx = 0; |
Holger Hans Peter Freyther | 69dbdee | 2011-04-11 19:32:35 +0200 | [diff] [blame] | 71 | static int loop_tests = 0; |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 72 | |
| 73 | struct sw_load { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 74 | uint8_t file_id[255]; |
| 75 | uint8_t file_id_len; |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 76 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 77 | uint8_t file_version[255]; |
| 78 | uint8_t file_version_len; |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 81 | static void *tall_ctx_config = NULL; |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 82 | static struct sw_load *sw_load1 = NULL; |
| 83 | static struct sw_load *sw_load2 = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 84 | |
| 85 | /* |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 86 | static uint8_t prim_oml_attr[] = { 0x95, 0x00, 7, 0x88, 192, 168, 100, 11, 0x00, 0x00 }; |
| 87 | static uint8_t unit_id_attr[] = { 0x91, 0x00, 9, '2', '3', '4', '2', '/' , '0', '/', '0', 0x00 }; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 88 | */ |
| 89 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 90 | extern int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what); |
| 91 | extern struct e1inp_line_ops ipaccess_e1inp_line_ops; |
| 92 | |
| 93 | /* Actively connect to a BTS. Currently used by ipaccess-config.c */ |
| 94 | static int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa) |
| 95 | { |
| 96 | struct e1inp_ts *e1i_ts = &line->ts[0]; |
| 97 | struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd; |
| 98 | int ret, on = 1; |
| 99 | |
| 100 | bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 101 | bfd->cb = ipaccess_fd_cb; |
| 102 | bfd->when = BSC_FD_READ | BSC_FD_WRITE; |
| 103 | bfd->data = line; |
| 104 | bfd->priv_nr = E1INP_SIGN_OML; |
| 105 | |
| 106 | if (bfd->fd < 0) { |
| 107 | LOGP(DLINP, LOGL_ERROR, "could not create TCP socket.\n"); |
| 108 | return -EIO; |
| 109 | } |
| 110 | |
Harald Welte | d27ff31 | 2016-11-26 14:06:52 +0100 | [diff] [blame^] | 111 | ret = setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
| 112 | if (ret < 0) { |
| 113 | LOGP(DLINP, LOGL_ERROR, "could not set socket option\n"); |
| 114 | close(bfd->fd); |
| 115 | return -EIO; |
| 116 | } |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 117 | |
| 118 | ret = connect(bfd->fd, (struct sockaddr *) sa, sizeof(*sa)); |
| 119 | if (ret < 0) { |
| 120 | LOGP(DLINP, LOGL_ERROR, "could not connect socket\n"); |
| 121 | close(bfd->fd); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | ret = osmo_fd_register(bfd); |
| 126 | if (ret < 0) { |
| 127 | close(bfd->fd); |
| 128 | return ret; |
| 129 | } |
| 130 | return ret; |
| 131 | //return e1inp_line_register(line); |
| 132 | } |
| 133 | |
| 134 | /* configure pseudo E1 line in ip.access style and connect to BTS */ |
| 135 | static int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin) |
| 136 | { |
| 137 | struct e1inp_line *line; |
| 138 | struct e1inp_ts *sign_ts, *rsl_ts; |
| 139 | struct e1inp_sign_link *oml_link, *rsl_link; |
| 140 | |
| 141 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
| 142 | if (!line) |
| 143 | return -ENOMEM; |
| 144 | |
| 145 | line->driver = e1inp_driver_find("ipa"); |
| 146 | if (!line->driver) { |
| 147 | fprintf(stderr, "cannot `ipa' driver, giving up.\n"); |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | line->ops = &ipaccess_e1inp_line_ops; |
| 151 | |
| 152 | /* create E1 timeslots for signalling and TRAU frames */ |
| 153 | e1inp_ts_config_sign(&line->ts[1-1], line); |
| 154 | e1inp_ts_config_sign(&line->ts[2-1], line); |
| 155 | |
| 156 | /* create signalling links for TS1 */ |
| 157 | sign_ts = &line->ts[1-1]; |
| 158 | rsl_ts = &line->ts[2-1]; |
| 159 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
| 160 | bts->c0, 0xff, 0); |
| 161 | rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL, |
| 162 | bts->c0, 0, 0); |
| 163 | |
| 164 | /* create back-links from bts/trx */ |
| 165 | bts->oml_link = oml_link; |
| 166 | bts->c0->rsl_link = rsl_link; |
| 167 | |
| 168 | /* default port at BTS for incoming connections is 3006 */ |
| 169 | if (sin->sin_port == 0) |
| 170 | sin->sin_port = htons(3006); |
| 171 | |
| 172 | return ipaccess_connect(line, sin); |
| 173 | } |
| 174 | |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 175 | /* |
| 176 | * Callback function for NACK on the OML NM |
| 177 | * |
| 178 | * Currently we send the config requests but don't check the |
| 179 | * result. The nanoBTS will send us a NACK when we did something the |
| 180 | * BTS didn't like. |
| 181 | */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 182 | static int ipacc_msg_nack(uint8_t mt) |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 183 | { |
| 184 | fprintf(stderr, "Failure to set attribute. This seems fatal\n"); |
| 185 | exit(-1); |
| 186 | return 0; |
| 187 | } |
| 188 | |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 189 | static void check_restart_or_exit(struct gsm_bts_trx *trx) |
Holger Hans Peter Freyther | 98d6de0 | 2010-05-12 23:16:59 +0800 | [diff] [blame] | 190 | { |
| 191 | if (restart) { |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 192 | abis_nm_ipaccess_restart(trx); |
Holger Hans Peter Freyther | 98d6de0 | 2010-05-12 23:16:59 +0800 | [diff] [blame] | 193 | } else { |
| 194 | exit(0); |
| 195 | } |
| 196 | } |
| 197 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 198 | static int ipacc_msg_ack(uint8_t mt, struct gsm_bts_trx *trx) |
Holger Hans Peter Freyther | 257b8db | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 199 | { |
| 200 | if (sw_load_state == 1) { |
| 201 | fprintf(stderr, "The new software is activaed.\n"); |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 202 | check_restart_or_exit(trx); |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 203 | } else if (oml_state == 1) { |
Harald Welte | bfd40a8 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 204 | fprintf(stderr, "Set the NV Attributes.\n"); |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 205 | check_restart_or_exit(trx); |
Holger Hans Peter Freyther | 257b8db | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 211 | static const uint8_t phys_conf_min[] = { 0x02 }; |
| 212 | |
| 213 | static uint16_t build_physconf(uint8_t *physconf_buf, const struct rxlev_stats *st) |
| 214 | { |
| 215 | uint16_t *whitelist = (uint16_t *) (physconf_buf + 4); |
| 216 | int num_arfcn; |
| 217 | unsigned int arfcnlist_size; |
| 218 | |
| 219 | /* Create whitelist from rxlevels */ |
| 220 | physconf_buf[0] = phys_conf_min[0]; |
| 221 | physconf_buf[1] = NM_IPAC_EIE_ARFCN_WHITE; |
Harald Welte | 8b39d73 | 2010-07-22 20:12:09 +0200 | [diff] [blame] | 222 | num_arfcn = ipac_rxlevstat2whitelist(whitelist, st, 0, 100); |
Harald Welte | c294597 | 2010-07-22 18:14:58 +0200 | [diff] [blame] | 223 | arfcnlist_size = num_arfcn * 2; |
Harald Welte | 8b39d73 | 2010-07-22 20:12:09 +0200 | [diff] [blame] | 224 | *((uint16_t *) (physconf_buf+2)) = htons(arfcnlist_size); |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 225 | DEBUGP(DNM, "physconf_buf (%s)\n", osmo_hexdump(physconf_buf, arfcnlist_size+4)); |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 226 | return arfcnlist_size+4; |
| 227 | } |
Harald Welte | b31c9df | 2010-03-06 11:38:05 +0100 | [diff] [blame] | 228 | |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 229 | static int nwl_sig_cb(unsigned int subsys, unsigned int signal, |
| 230 | void *handler_data, void *signal_data) |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 231 | { |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 232 | struct gsm_bts_trx *trx; |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 233 | uint8_t physconf_buf[2*NUM_ARFCNS+16]; |
| 234 | uint16_t physconf_len; |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 235 | |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 236 | switch (signal) { |
| 237 | case S_IPAC_NWL_COMPLETE: |
| 238 | trx = signal_data; |
Harald Welte | b31c9df | 2010-03-06 11:38:05 +0100 | [diff] [blame] | 239 | DEBUGP(DNM, "received S_IPAC_NWL_COMPLETE signal\n"); |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 240 | switch (trx->ipaccess.test_nr) { |
| 241 | case NM_IPACC_TESTNO_CHAN_USAGE: |
| 242 | /* Dump RxLev results */ |
Harald Welte | ee0bd11 | 2010-07-30 22:34:25 +0200 | [diff] [blame] | 243 | //rxlev_stat_dump(&trx->ipaccess.rxlev_stat); |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 244 | /* Create whitelist from results */ |
| 245 | physconf_len = build_physconf(physconf_buf, |
| 246 | &trx->ipaccess.rxlev_stat); |
| 247 | /* Start next test abbout BCCH channel usage */ |
| 248 | ipac_nwl_test_start(trx, NM_IPACC_TESTNO_BCCH_CHAN_USAGE, |
| 249 | physconf_buf, physconf_len); |
| 250 | break; |
| 251 | case NM_IPACC_TESTNO_BCCH_CHAN_USAGE: |
| 252 | /* Dump BCCH RxLev results */ |
Harald Welte | ee0bd11 | 2010-07-30 22:34:25 +0200 | [diff] [blame] | 253 | //rxlev_stat_dump(&trx->ipaccess.rxlev_stat); |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 254 | /* Create whitelist from results */ |
| 255 | physconf_len = build_physconf(physconf_buf, |
| 256 | &trx->ipaccess.rxlev_stat); |
| 257 | /* Start next test about BCCH info */ |
| 258 | ipac_nwl_test_start(trx, NM_IPACC_TESTNO_BCCH_INFO, |
| 259 | physconf_buf, physconf_len); |
| 260 | break; |
Harald Welte | 13772e8 | 2010-07-30 22:31:44 +0200 | [diff] [blame] | 261 | case NM_IPACC_TESTNO_BCCH_INFO: |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 262 | /* re-start full process with CHAN_USAGE */ |
Holger Hans Peter Freyther | 69dbdee | 2011-04-11 19:32:35 +0200 | [diff] [blame] | 263 | if (loop_tests) { |
| 264 | DEBUGP(DNM, "starting next test cycle\n"); |
| 265 | ipac_nwl_test_start(trx, net_listen_testnr, phys_conf_min, |
| 266 | sizeof(phys_conf_min)); |
| 267 | } else { |
| 268 | exit(0); |
| 269 | } |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 270 | break; |
| 271 | } |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 272 | break; |
| 273 | } |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 277 | static int nm_state_event(int evt, uint8_t obj_class, void *obj, |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 278 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state, |
| 279 | struct abis_om_obj_inst *obj_inst); |
| 280 | |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 281 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 282 | void *handler_data, void *signal_data) |
| 283 | { |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 284 | struct ipacc_ack_signal_data *ipacc_data; |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 285 | struct nm_statechg_signal_data *nsd; |
Harald Welte | 6a21c73 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 286 | |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 287 | switch (signal) { |
| 288 | case S_NM_IPACC_NACK: |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 289 | ipacc_data = signal_data; |
| 290 | return ipacc_msg_nack(ipacc_data->msg_type); |
Holger Hans Peter Freyther | 257b8db | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 291 | case S_NM_IPACC_ACK: |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 292 | ipacc_data = signal_data; |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 293 | return ipacc_msg_ack(ipacc_data->msg_type, ipacc_data->trx); |
Holger Hans Peter Freyther | 9ef8e5a | 2009-12-30 09:00:01 +0100 | [diff] [blame] | 294 | case S_NM_IPACC_RESTART_ACK: |
| 295 | printf("The BTS has acked the restart. Exiting.\n"); |
| 296 | exit(0); |
| 297 | break; |
| 298 | case S_NM_IPACC_RESTART_NACK: |
| 299 | printf("The BTS has nacked the restart. Exiting.\n"); |
| 300 | exit(0); |
| 301 | break; |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 302 | case S_NM_STATECHG_OPER: |
| 303 | case S_NM_STATECHG_ADM: |
| 304 | nsd = signal_data; |
| 305 | nm_state_event(signal, nsd->obj_class, nsd->obj, nsd->old_state, |
| 306 | nsd->new_state, nsd->obj_inst); |
| 307 | break; |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 308 | default: |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 315 | /* callback function passed to the ABIS OML code */ |
| 316 | static int percent; |
| 317 | static int percent_old; |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 318 | static int swload_cbfn(unsigned int hook, unsigned int event, struct msgb *_msg, |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 319 | void *data, void *param) |
| 320 | { |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 321 | struct msgb *msg; |
Holger Hans Peter Freyther | faeab8e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 322 | struct gsm_bts_trx *trx; |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 323 | |
| 324 | if (hook != GSM_HOOK_NM_SWLOAD) |
| 325 | return 0; |
| 326 | |
Holger Hans Peter Freyther | faeab8e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 327 | trx = (struct gsm_bts_trx *) data; |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 328 | |
| 329 | switch (event) { |
| 330 | case NM_MT_LOAD_INIT_ACK: |
| 331 | fprintf(stdout, "Software Load Initiate ACK\n"); |
| 332 | break; |
| 333 | case NM_MT_LOAD_INIT_NACK: |
| 334 | fprintf(stderr, "ERROR: Software Load Initiate NACK\n"); |
| 335 | exit(5); |
| 336 | break; |
| 337 | case NM_MT_LOAD_END_ACK: |
| 338 | fprintf(stderr, "LOAD END ACK..."); |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 339 | /* now make it the default */ |
| 340 | sw_load_state = 1; |
| 341 | |
| 342 | msg = msgb_alloc(1024, "sw: nvattr"); |
| 343 | msg->l2h = msgb_put(msg, 3); |
| 344 | msg->l3h = &msg->l2h[3]; |
| 345 | |
| 346 | /* activate software */ |
| 347 | if (sw_load1) { |
| 348 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
| 349 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw_load1->file_id_len, sw_load1->file_id); |
| 350 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw_load1->file_version_len, |
| 351 | sw_load1->file_version); |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 352 | } |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 353 | |
| 354 | if (sw_load2) { |
| 355 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
Holger Hans Peter Freyther | f81445e | 2009-12-29 11:12:00 +0100 | [diff] [blame] | 356 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw_load2->file_id_len, sw_load2->file_id); |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 357 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw_load2->file_version_len, |
| 358 | sw_load2->file_version); |
| 359 | } |
| 360 | |
| 361 | /* fill in the data */ |
| 362 | msg->l2h[0] = NM_ATT_IPACC_CUR_SW_CFG; |
| 363 | msg->l2h[1] = msgb_l3len(msg) >> 8; |
| 364 | msg->l2h[2] = msgb_l3len(msg) & 0xff; |
| 365 | 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 | faeab8e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 366 | abis_nm_ipaccess_set_nvattr(trx, msg->l2h, msgb_l2len(msg)); |
Holger Hans Peter Freyther | 0e15b93 | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 367 | msgb_free(msg); |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 368 | break; |
| 369 | case NM_MT_LOAD_END_NACK: |
| 370 | fprintf(stderr, "ERROR: Software Load End NACK\n"); |
| 371 | exit(3); |
| 372 | break; |
| 373 | case NM_MT_ACTIVATE_SW_NACK: |
| 374 | fprintf(stderr, "ERROR: Activate Software NACK\n"); |
| 375 | exit(4); |
| 376 | break; |
| 377 | case NM_MT_ACTIVATE_SW_ACK: |
| 378 | break; |
| 379 | case NM_MT_LOAD_SEG_ACK: |
Holger Hans Peter Freyther | faeab8e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 380 | percent = abis_nm_software_load_status(trx->bts); |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 381 | if (percent > percent_old) |
| 382 | printf("Software Download Progress: %d%%\n", percent); |
| 383 | percent_old = percent; |
| 384 | break; |
Holger Hans Peter Freyther | 61f814d | 2009-12-28 12:23:02 +0100 | [diff] [blame] | 385 | case NM_MT_LOAD_ABORT: |
| 386 | fprintf(stderr, "ERROR: Load aborted by the BTS.\n"); |
| 387 | exit(6); |
| 388 | break; |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 393 | static void nv_put_ip_if_cfg(struct msgb *nmsg, uint32_t ip, uint32_t mask) |
| 394 | { |
| 395 | msgb_put_u8(nmsg, NM_ATT_IPACC_IP_IF_CFG); |
| 396 | |
| 397 | msgb_put_u32(nmsg, ip); |
| 398 | msgb_put_u32(nmsg, mask); |
| 399 | } |
| 400 | |
| 401 | static void nv_put_gw_cfg(struct msgb *nmsg, uint32_t addr, uint32_t mask, uint32_t gw) |
| 402 | { |
| 403 | msgb_put_u8(nmsg, NM_ATT_IPACC_IP_GW_CFG); |
| 404 | msgb_put_u32(nmsg, addr); |
| 405 | msgb_put_u32(nmsg, mask); |
| 406 | msgb_put_u32(nmsg, gw); |
| 407 | } |
| 408 | |
| 409 | static void nv_put_unit_id(struct msgb *nmsg, const char *unit_id) |
| 410 | { |
| 411 | msgb_tl16v_put(nmsg, NM_ATT_IPACC_UNIT_ID, strlen(unit_id)+1, |
| 412 | (const uint8_t *)unit_id); |
| 413 | } |
| 414 | |
| 415 | static void nv_put_prim_oml(struct msgb *nmsg, uint32_t ip, uint16_t port) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 416 | { |
| 417 | int len; |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 418 | |
| 419 | /* 0x88 + IP + port */ |
| 420 | len = 1 + sizeof(ip) + sizeof(port); |
| 421 | |
| 422 | msgb_put_u8(nmsg, NM_ATT_IPACC_PRIM_OML_CFG_LIST); |
| 423 | msgb_put_u16(nmsg, len); |
| 424 | |
| 425 | msgb_put_u8(nmsg, 0x88); |
| 426 | |
| 427 | /* IP address */ |
| 428 | msgb_put_u32(nmsg, ip); |
| 429 | |
| 430 | /* port number */ |
| 431 | msgb_put_u16(nmsg, port); |
| 432 | } |
| 433 | |
| 434 | static void nv_put_flags(struct msgb *nmsg, uint16_t nv_flags, uint16_t nv_mask) |
| 435 | { |
| 436 | msgb_put_u8(nmsg, NM_ATT_IPACC_NV_FLAGS); |
| 437 | msgb_put_u16(nmsg, sizeof(nv_flags) + sizeof(nv_mask)); |
| 438 | msgb_put_u8(nmsg, nv_flags & 0xff); |
| 439 | msgb_put_u8(nmsg, nv_mask & 0xff); |
| 440 | msgb_put_u8(nmsg, nv_flags >> 8); |
| 441 | msgb_put_u8(nmsg, nv_mask >> 8); |
| 442 | } |
| 443 | |
Holger Hans Peter Freyther | 657079e | 2011-04-11 20:33:05 +0200 | [diff] [blame] | 444 | /* human-readable test names for the ip.access tests */ |
| 445 | static const struct value_string ipa_test_strs[] = { |
| 446 | { 64, "ccch-usage" }, |
| 447 | { 65, "bcch-usage" }, |
| 448 | { 66, "freq-sync" }, |
| 449 | { 67, "rtp-usage" }, |
| 450 | { 68, "rtp-perf" }, |
| 451 | { 69, "gprs-ccch" }, |
| 452 | { 70, "pccch-usage" }, |
| 453 | { 71, "gprs-usage" }, |
| 454 | { 72, "esta-mf" }, |
| 455 | { 73, "uplink-mf" }, |
| 456 | { 74, "dolink-mf" }, |
| 457 | { 75, "tbf-details" }, |
| 458 | { 76, "tbf-usage" }, |
| 459 | { 77, "llc-data" }, |
| 460 | { 78, "pdch-usage" }, |
| 461 | { 79, "power-control" }, |
| 462 | { 80, "link-adaption" }, |
| 463 | { 81, "tch-usage" }, |
| 464 | { 82, "amr-mf" }, |
| 465 | { 83, "rtp-multiplex-perf" }, |
| 466 | { 84, "rtp-multiplex-usage" }, |
| 467 | { 85, "srtp-multiplex-usage" }, |
| 468 | { 86, "abis-traffic" }, |
| 469 | { 89, "gprs-multiplex-perf" }, |
| 470 | { 90, "gprs-multiplex-usage" }, |
| 471 | { 0, NULL }, |
| 472 | }; |
| 473 | |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 474 | /* human-readable names for the ip.access nanoBTS NVRAM Flags */ |
| 475 | static const struct value_string ipa_nvflag_strs[] = { |
| 476 | { 0x0001, "static-ip" }, |
| 477 | { 0x0002, "static-gw" }, |
| 478 | { 0x0004, "no-dhcp-vsi" }, |
| 479 | { 0x0008, "dhcp-enabled" }, |
| 480 | { 0x0040, "led-disabled" }, |
| 481 | { 0x0100, "secondary-oml-enabled" }, |
| 482 | { 0x0200, "diag-enabled" }, |
| 483 | { 0x0400, "cli-enabled" }, |
| 484 | { 0x0800, "http-enabled" }, |
| 485 | { 0x1000, "post-enabled" }, |
| 486 | { 0x2000, "snmp-enabled" }, |
| 487 | { 0, NULL } |
| 488 | }; |
| 489 | |
| 490 | /* set the flags in flags/mask according to a string-identified flag and 'enable' */ |
| 491 | static int ipa_nvflag_set(uint16_t *flags, uint16_t *mask, const char *name, int en) |
| 492 | { |
| 493 | int rc; |
| 494 | rc = get_string_value(ipa_nvflag_strs, name); |
| 495 | if (rc < 0) |
| 496 | return rc; |
| 497 | |
| 498 | *mask |= rc; |
| 499 | if (en) |
| 500 | *flags |= rc; |
| 501 | else |
| 502 | *flags &= ~rc; |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 507 | static void bootstrap_om(struct gsm_bts_trx *trx) |
| 508 | { |
Harald Welte | bfd40a8 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 509 | struct msgb *nmsg = msgb_alloc(1024, "nested msgb"); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 510 | int need_to_set_attr = 0; |
| 511 | int len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 512 | |
Holger Hans Peter Freyther | f39ff07 | 2010-05-12 16:44:01 +0800 | [diff] [blame] | 513 | printf("OML link established using TRX %d\n", trx->nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 514 | |
| 515 | if (unit_id) { |
| 516 | len = strlen(unit_id); |
Harald Welte | bfd40a8 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 517 | if (len > nmsg->data_len-10) |
| 518 | goto out_err; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 519 | printf("setting Unit ID to '%s'\n", unit_id); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 520 | nv_put_unit_id(nmsg, unit_id); |
| 521 | need_to_set_attr = 1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 522 | } |
| 523 | if (prim_oml_ip) { |
| 524 | struct in_addr ia; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 525 | |
| 526 | if (!inet_aton(prim_oml_ip, &ia)) { |
| 527 | fprintf(stderr, "invalid IP address: %s\n", |
| 528 | prim_oml_ip); |
Harald Welte | bfd40a8 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 529 | goto out_err; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 530 | } |
| 531 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 532 | printf("setting primary OML link IP to '%s'\n", inet_ntoa(ia)); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 533 | nv_put_prim_oml(nmsg, ntohl(ia.s_addr), 0); |
| 534 | need_to_set_attr = 1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 535 | } |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 536 | if (nv_mask) { |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 537 | printf("setting NV Flags/Mask to 0x%04x/0x%04x\n", |
| 538 | nv_flags, nv_mask); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 539 | nv_put_flags(nmsg, nv_flags, nv_mask); |
| 540 | need_to_set_attr = 1; |
| 541 | } |
| 542 | if (bts_ip_addr && bts_ip_mask) { |
| 543 | struct in_addr ia_addr, ia_mask; |
| 544 | |
| 545 | if (!inet_aton(bts_ip_addr, &ia_addr)) { |
| 546 | fprintf(stderr, "invalid IP address: %s\n", |
| 547 | bts_ip_addr); |
| 548 | goto out_err; |
| 549 | } |
| 550 | |
| 551 | if (!inet_aton(bts_ip_mask, &ia_mask)) { |
| 552 | fprintf(stderr, "invalid IP address: %s\n", |
| 553 | bts_ip_mask); |
| 554 | goto out_err; |
| 555 | } |
| 556 | |
| 557 | printf("setting static IP Address/Mask\n"); |
| 558 | nv_put_ip_if_cfg(nmsg, ntohl(ia_addr.s_addr), ntohl(ia_mask.s_addr)); |
| 559 | need_to_set_attr = 1; |
| 560 | } |
| 561 | if (bts_ip_gw) { |
| 562 | struct in_addr ia_gw; |
| 563 | |
| 564 | if (!inet_aton(bts_ip_gw, &ia_gw)) { |
| 565 | fprintf(stderr, "invalid IP address: %s\n", |
| 566 | bts_ip_gw); |
| 567 | goto out_err; |
| 568 | } |
| 569 | |
| 570 | printf("setting static IP Gateway\n"); |
| 571 | /* we only set the default gateway with zero addr/mask */ |
| 572 | nv_put_gw_cfg(nmsg, 0, 0, ntohl(ia_gw.s_addr)); |
| 573 | need_to_set_attr = 1; |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 574 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 575 | |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 576 | if (need_to_set_attr) { |
| 577 | abis_nm_ipaccess_set_nvattr(trx, nmsg->head, nmsg->len); |
| 578 | oml_state = 1; |
| 579 | } |
Harald Welte | bfd40a8 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 580 | |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 581 | if (restart && !prim_oml_ip && !software) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 582 | printf("restarting BTS\n"); |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 583 | abis_nm_ipaccess_restart(trx); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 584 | } |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 585 | |
Harald Welte | bfd40a8 | 2010-06-28 14:41:09 +0200 | [diff] [blame] | 586 | out_err: |
| 587 | msgb_free(nmsg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 588 | } |
| 589 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 590 | static int nm_state_event(int evt, uint8_t obj_class, void *obj, |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 591 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state, |
| 592 | struct abis_om_obj_inst *obj_inst) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 593 | { |
Holger Hans Peter Freyther | f39ff07 | 2010-05-12 16:44:01 +0800 | [diff] [blame] | 594 | if (obj_class == NM_OC_BASEB_TRANSC) { |
| 595 | if (!found_trx && obj_inst->trx_nr != 0xff) { |
| 596 | struct gsm_bts_trx *trx = container_of(obj, struct gsm_bts_trx, bb_transc); |
| 597 | bootstrap_om(trx); |
| 598 | found_trx = 1; |
| 599 | } |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 600 | } else if (evt == S_NM_STATECHG_OPER && |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 601 | obj_class == NM_OC_RADIO_CARRIER && |
Holger Hans Peter Freyther | f6dbf7f | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 602 | new_state->availability == 3) { |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 603 | struct gsm_bts_trx *trx = obj; |
Holger Hans Peter Freyther | f6dbf7f | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 604 | |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 605 | if (net_listen_testnr) |
Harald Welte | 432da6e | 2010-03-09 22:35:37 +0100 | [diff] [blame] | 606 | ipac_nwl_test_start(trx, net_listen_testnr, |
| 607 | phys_conf_min, sizeof(phys_conf_min)); |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 608 | else if (software) { |
Holger Hans Peter Freyther | f6dbf7f | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 609 | int rc; |
| 610 | printf("Attempting software upload with '%s'\n", software); |
Holger Hans Peter Freyther | faeab8e | 2010-05-13 00:14:46 +0800 | [diff] [blame] | 611 | rc = abis_nm_software_load(trx->bts, trx->nr, software, 19, 0, swload_cbfn, trx); |
Holger Hans Peter Freyther | f6dbf7f | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 612 | if (rc < 0) { |
| 613 | fprintf(stderr, "Failed to start software load\n"); |
| 614 | exit(-3); |
| 615 | } |
| 616 | } |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 617 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 618 | return 0; |
| 619 | } |
| 620 | |
Holger Hans Peter Freyther | 39d4c8e | 2009-12-30 09:31:31 +0100 | [diff] [blame] | 621 | static struct sw_load *create_swload(struct sdp_header *header) |
| 622 | { |
| 623 | struct sw_load *load; |
| 624 | |
| 625 | load = talloc_zero(tall_ctx_config, struct sw_load); |
| 626 | |
| 627 | strncpy((char *)load->file_id, header->firmware_info.sw_part, 20); |
| 628 | load->file_id_len = strlen(header->firmware_info.sw_part) + 1; |
| 629 | |
| 630 | strncpy((char *)load->file_version, header->firmware_info.version, 20); |
| 631 | load->file_version_len = strlen(header->firmware_info.version) + 1; |
| 632 | |
| 633 | return load; |
| 634 | } |
| 635 | |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 636 | static int find_sw_load_params(const char *filename) |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 637 | { |
| 638 | struct stat stat; |
| 639 | struct sdp_header *header; |
| 640 | struct llist_head *entry; |
| 641 | int fd; |
| 642 | void *tall_firm_ctx = 0; |
| 643 | |
| 644 | entry = talloc_zero(tall_firm_ctx, struct llist_head); |
| 645 | INIT_LLIST_HEAD(entry); |
| 646 | |
| 647 | fd = open(filename, O_RDONLY); |
| 648 | if (!fd) { |
| 649 | perror("nada"); |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 650 | return -1; |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* verify the file */ |
| 654 | if (fstat(fd, &stat) == -1) { |
| 655 | perror("Can not stat the file"); |
Holger Hans Peter Freyther | c7221d4 | 2013-07-04 18:47:44 +0200 | [diff] [blame] | 656 | close(fd); |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 657 | return -1; |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | ipaccess_analyze_file(fd, stat.st_size, 0, entry); |
| 661 | if (close(fd) != 0) { |
| 662 | perror("Close failed.\n"); |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 663 | return -1; |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /* try to find what we are looking for */ |
| 667 | llist_for_each_entry(header, entry, entry) { |
| 668 | if (ntohs(header->firmware_info.more_more_magic) == 0x1000) { |
Holger Hans Peter Freyther | 39d4c8e | 2009-12-30 09:31:31 +0100 | [diff] [blame] | 669 | sw_load1 = create_swload(header); |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 670 | } else if (ntohs(header->firmware_info.more_more_magic) == 0x2001) { |
Holger Hans Peter Freyther | 39d4c8e | 2009-12-30 09:31:31 +0100 | [diff] [blame] | 671 | sw_load2 = create_swload(header); |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 675 | if (!sw_load1 || !sw_load2) { |
| 676 | fprintf(stderr, "Did not find data.\n"); |
| 677 | talloc_free(tall_firm_ctx); |
| 678 | return -1; |
| 679 | } |
| 680 | |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 681 | talloc_free(tall_firm_ctx); |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 682 | return 0; |
Holger Hans Peter Freyther | f7f2712 | 2009-12-30 08:11:18 +0100 | [diff] [blame] | 683 | } |
| 684 | |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 685 | static void dump_entry(struct sdp_header_item *sub_entry, int part, int fd) |
| 686 | { |
| 687 | int out_fd; |
| 688 | int copied; |
| 689 | char filename[4096]; |
| 690 | off_t target; |
| 691 | |
| 692 | if (!dump_files) |
| 693 | return; |
| 694 | |
| 695 | if (sub_entry->header_entry.something1 == 0) |
| 696 | return; |
| 697 | |
| 698 | snprintf(filename, sizeof(filename), "part.%d", part++); |
| 699 | out_fd = open(filename, O_WRONLY | O_CREAT, 0660); |
| 700 | if (out_fd < 0) { |
| 701 | perror("Can not dump firmware"); |
| 702 | return; |
| 703 | } |
| 704 | |
Holger Hans Peter Freyther | c52dd36 | 2010-03-22 11:50:30 +0100 | [diff] [blame] | 705 | target = sub_entry->absolute_offset + ntohl(sub_entry->header_entry.start) + 4; |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 706 | if (lseek(fd, target, SEEK_SET) != target) { |
| 707 | perror("seek failed"); |
| 708 | close(out_fd); |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | for (copied = 0; copied < ntohl(sub_entry->header_entry.length); ++copied) { |
| 713 | char c; |
| 714 | if (read(fd, &c, sizeof(c)) != sizeof(c)) { |
| 715 | perror("copy failed"); |
| 716 | break; |
| 717 | } |
| 718 | |
| 719 | if (write(out_fd, &c, sizeof(c)) != sizeof(c)) { |
| 720 | perror("write failed"); |
| 721 | break; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | close(out_fd); |
| 726 | } |
| 727 | |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 728 | static void analyze_firmware(const char *filename) |
| 729 | { |
| 730 | struct stat stat; |
| 731 | struct sdp_header *header; |
| 732 | struct sdp_header_item *sub_entry; |
| 733 | struct llist_head *entry; |
| 734 | int fd; |
| 735 | void *tall_firm_ctx = 0; |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 736 | int part = 0; |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 737 | |
| 738 | entry = talloc_zero(tall_firm_ctx, struct llist_head); |
| 739 | INIT_LLIST_HEAD(entry); |
| 740 | |
| 741 | printf("Opening possible firmware '%s'\n", filename); |
| 742 | fd = open(filename, O_RDONLY); |
| 743 | if (!fd) { |
| 744 | perror("nada"); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | /* verify the file */ |
| 749 | if (fstat(fd, &stat) == -1) { |
| 750 | perror("Can not stat the file"); |
Holger Hans Peter Freyther | 7c45dc5 | 2013-07-14 08:37:06 +0200 | [diff] [blame] | 751 | close(fd); |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | |
| 755 | ipaccess_analyze_file(fd, stat.st_size, 0, entry); |
| 756 | |
| 757 | llist_for_each_entry(header, entry, entry) { |
| 758 | printf("Printing header information:\n"); |
| 759 | printf("more_more_magic: 0x%x\n", ntohs(header->firmware_info.more_more_magic)); |
| 760 | printf("header_length: %u\n", ntohl(header->firmware_info.header_length)); |
| 761 | printf("file_length: %u\n", ntohl(header->firmware_info.file_length)); |
| 762 | printf("sw_part: %.20s\n", header->firmware_info.sw_part); |
| 763 | printf("text1: %.64s\n", header->firmware_info.text1); |
| 764 | printf("time: %.12s\n", header->firmware_info.time); |
| 765 | printf("date: %.14s\n", header->firmware_info.date); |
| 766 | printf("text2: %.10s\n", header->firmware_info.text2); |
| 767 | printf("version: %.20s\n", header->firmware_info.version); |
| 768 | printf("subitems...\n"); |
| 769 | |
| 770 | llist_for_each_entry(sub_entry, &header->header_list, entry) { |
| 771 | printf("\tsomething1: %u\n", sub_entry->header_entry.something1); |
| 772 | printf("\ttext1: %.64s\n", sub_entry->header_entry.text1); |
| 773 | printf("\ttime: %.12s\n", sub_entry->header_entry.time); |
| 774 | printf("\tdate: %.14s\n", sub_entry->header_entry.date); |
| 775 | printf("\ttext2: %.10s\n", sub_entry->header_entry.text2); |
| 776 | printf("\tversion: %.20s\n", sub_entry->header_entry.version); |
| 777 | printf("\tlength: %u\n", ntohl(sub_entry->header_entry.length)); |
| 778 | printf("\taddr1: 0x%x\n", ntohl(sub_entry->header_entry.addr1)); |
| 779 | printf("\taddr2: 0x%x\n", ntohl(sub_entry->header_entry.addr2)); |
| 780 | printf("\tstart: 0x%x\n", ntohl(sub_entry->header_entry.start)); |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 781 | printf("\tabs. offset: 0x%lx\n", sub_entry->absolute_offset); |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 782 | printf("\n\n"); |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 783 | |
| 784 | dump_entry(sub_entry, part++, fd); |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 785 | } |
| 786 | printf("\n\n"); |
| 787 | } |
| 788 | |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 789 | if (close(fd) != 0) { |
| 790 | perror("Close failed.\n"); |
| 791 | return; |
| 792 | } |
| 793 | |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 794 | talloc_free(tall_firm_ctx); |
| 795 | } |
| 796 | |
Holger Hans Peter Freyther | 5bcfb4f | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 797 | static void print_usage(void) |
| 798 | { |
Holger Hans Peter Freyther | 9e18495 | 2013-11-11 14:30:09 +0100 | [diff] [blame] | 799 | printf("Usage: ipaccess-config IP_OF_BTS\n"); |
Holger Hans Peter Freyther | 5bcfb4f | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | static void print_help(void) |
| 803 | { |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 804 | #if 0 |
| 805 | printf("Commmands for reading from the BTS:\n"); |
| 806 | printf(" -D --dump\t\t\tDump the BTS configuration\n"); |
| 807 | printf("\n"); |
| 808 | #endif |
| 809 | printf("Commmands for writing to the BTS:\n"); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 810 | printf(" -u --unit-id UNIT_ID\t\tSet the Unit ID of the BTS\n"); |
| 811 | printf(" -o --oml-ip IP\t\tSet primary OML IP (IP of your BSC)\n"); |
| 812 | printf(" -i --ip-address IP/MASK\tSet static IP address + netmask of BTS\n"); |
| 813 | printf(" -g --ip-gateway IP\t\tSet static IP gateway of BTS\n"); |
| 814 | printf(" -r --restart\t\t\tRestart the BTS (after other operations)\n"); |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 815 | printf(" -n --nvram-flags FLAGS/MASK\tSet NVRAM attributes\n"); |
| 816 | printf(" -S --nvattr-set FLAG\tSet one additional NVRAM attribute\n"); |
| 817 | printf(" -U --nvattr-unset FLAG\tSet one additional NVRAM attribute\n"); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 818 | printf(" -l --listen TESTNR\t\tPerform specified test number\n"); |
Holger Hans Peter Freyther | 657079e | 2011-04-11 20:33:05 +0200 | [diff] [blame] | 819 | printf(" -L --Listen TEST_NAME\t\tPerform specified test\n"); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 820 | printf(" -s --stream-id ID\t\tSet the IPA Stream Identifier for OML\n"); |
| 821 | printf(" -d --software FIRMWARE\tDownload firmware into BTS\n"); |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 822 | printf("\n"); |
| 823 | printf("Miscellaneous commands:\n"); |
| 824 | printf(" -h --help\t\t\tthis text\n"); |
Holger Hans Peter Freyther | 5cf68da | 2011-04-11 20:16:52 +0200 | [diff] [blame] | 825 | printf(" -H --HELP\t\t\tPrint parameter details.\n"); |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 826 | printf(" -f --firmware FIRMWARE\tProvide firmware information\n"); |
| 827 | printf(" -w --write-firmware\t\tThis will dump the firmware parts to the filesystem. Use with -f.\n"); |
Holger Hans Peter Freyther | 69dbdee | 2011-04-11 19:32:35 +0200 | [diff] [blame] | 828 | printf(" -p --loop\t\t\tLoop the tests executed with the --listen command.\n"); |
Holger Hans Peter Freyther | 5bcfb4f | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Holger Hans Peter Freyther | 5cf68da | 2011-04-11 20:16:52 +0200 | [diff] [blame] | 831 | static void print_value_string(const struct value_string *val, int size) |
| 832 | { |
| 833 | int i; |
| 834 | |
| 835 | for (i = 0; i < size - 1; ++i) { |
| 836 | char sep = val[i + 1].str == NULL ? '.' : ','; |
| 837 | printf("%s%c ", val[i].str, sep); |
| 838 | } |
| 839 | printf("\n"); |
| 840 | } |
| 841 | |
| 842 | static void print_options(void) |
| 843 | { |
| 844 | |
| 845 | printf("Options for NVRAM (-S,-U):\n "); |
| 846 | print_value_string(&ipa_nvflag_strs[0], ARRAY_SIZE(ipa_nvflag_strs)); |
Holger Hans Peter Freyther | 657079e | 2011-04-11 20:33:05 +0200 | [diff] [blame] | 847 | |
| 848 | printf("Options for Tests (-L):\n "); |
| 849 | print_value_string(&ipa_test_strs[0], ARRAY_SIZE(ipa_test_strs)); |
Holger Hans Peter Freyther | 5cf68da | 2011-04-11 20:16:52 +0200 | [diff] [blame] | 850 | } |
| 851 | |
Holger Hans Peter Freyther | b0e4679 | 2010-05-14 02:54:40 +0800 | [diff] [blame] | 852 | extern void bts_model_nanobts_init(); |
| 853 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 854 | int main(int argc, char **argv) |
| 855 | { |
| 856 | struct gsm_bts *bts; |
| 857 | struct sockaddr_in sin; |
Holger Hans Peter Freyther | 2e021c6 | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 858 | int rc, option_index = 0, stream_id = 0xff; |
Holger Hans Peter Freyther | c8d862e | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 859 | |
Neels Hofmeyr | 906a078 | 2016-09-16 02:28:30 +0200 | [diff] [blame] | 860 | tall_ctx_config = talloc_named_const(NULL, 0, "ipaccess-config"); |
Neels Hofmeyr | 20215f1 | 2016-09-16 02:31:17 +0200 | [diff] [blame] | 861 | msgb_talloc_ctx_init(tall_ctx_config, 0); |
Neels Hofmeyr | 906a078 | 2016-09-16 02:28:30 +0200 | [diff] [blame] | 862 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 863 | osmo_init_logging(&log_info); |
| 864 | log_parse_category_mask(osmo_stderr_target, "DNM,0"); |
Harald Welte | e462019 | 2010-01-10 18:37:38 +0100 | [diff] [blame] | 865 | bts_model_nanobts_init(); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 866 | |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 867 | printf("ipaccess-config (C) 2009-2010 by Harald Welte and others\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 868 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 869 | |
| 870 | while (1) { |
| 871 | int c; |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 872 | unsigned long ul; |
| 873 | char *slash; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 874 | static struct option long_options[] = { |
| 875 | { "unit-id", 1, 0, 'u' }, |
| 876 | { "oml-ip", 1, 0, 'o' }, |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 877 | { "ip-address", 1, 0, 'i' }, |
| 878 | { "ip-gateway", 1, 0, 'g' }, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 879 | { "restart", 0, 0, 'r' }, |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 880 | { "nvram-flags", 1, 0, 'n' }, |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 881 | { "nvattr-set", 1, 0, 'S' }, |
| 882 | { "nvattr-unset", 1, 0, 'U' }, |
Holger Hans Peter Freyther | 5bcfb4f | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 883 | { "help", 0, 0, 'h' }, |
Holger Hans Peter Freyther | 5cf68da | 2011-04-11 20:16:52 +0200 | [diff] [blame] | 884 | { "HELP", 0, 0, 'H' }, |
Harald Welte | 12a721e | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 885 | { "listen", 1, 0, 'l' }, |
Holger Hans Peter Freyther | 657079e | 2011-04-11 20:33:05 +0200 | [diff] [blame] | 886 | { "Listen", 1, 0, 'L' }, |
Holger Hans Peter Freyther | 2e021c6 | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 887 | { "stream-id", 1, 0, 's' }, |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 888 | { "software", 1, 0, 'd' }, |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 889 | { "firmware", 1, 0, 'f' }, |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 890 | { "write-firmware", 0, 0, 'w' }, |
Harald Welte | a45efec | 2010-07-30 20:25:48 +0200 | [diff] [blame] | 891 | { "disable-color", 0, 0, 'c'}, |
Holger Hans Peter Freyther | 69dbdee | 2011-04-11 19:32:35 +0200 | [diff] [blame] | 892 | { "loop", 0, 0, 'p' }, |
Holger Hans Peter Freyther | 8616525 | 2010-04-20 22:22:00 +0800 | [diff] [blame] | 893 | { 0, 0, 0, 0 }, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 894 | }; |
| 895 | |
Holger Hans Peter Freyther | 657079e | 2011-04-11 20:33:05 +0200 | [diff] [blame] | 896 | c = getopt_long(argc, argv, "u:o:i:g:rn:S:U:l:L:hs:d:f:wcpH", long_options, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 897 | &option_index); |
| 898 | |
| 899 | if (c == -1) |
| 900 | break; |
| 901 | |
| 902 | switch (c) { |
| 903 | case 'u': |
| 904 | unit_id = optarg; |
| 905 | break; |
| 906 | case 'o': |
| 907 | prim_oml_ip = optarg; |
| 908 | break; |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 909 | case 'i': |
| 910 | slash = strchr(optarg, '/'); |
| 911 | if (!slash) |
| 912 | exit(2); |
| 913 | bts_ip_addr = optarg; |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 914 | *slash = 0; |
Harald Welte | ecb2b41 | 2010-06-28 15:17:57 +0200 | [diff] [blame] | 915 | bts_ip_mask = slash+1; |
| 916 | break; |
| 917 | case 'g': |
| 918 | bts_ip_gw = optarg; |
| 919 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 920 | case 'r': |
| 921 | restart = 1; |
| 922 | break; |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 923 | case 'n': |
| 924 | slash = strchr(optarg, '/'); |
| 925 | if (!slash) |
| 926 | exit(2); |
| 927 | ul = strtoul(optarg, NULL, 16); |
| 928 | nv_flags = ul & 0xffff; |
| 929 | ul = strtoul(slash+1, NULL, 16); |
| 930 | nv_mask = ul & 0xffff; |
| 931 | break; |
Harald Welte | 901c819 | 2010-06-28 15:52:56 +0200 | [diff] [blame] | 932 | case 'S': |
| 933 | if (ipa_nvflag_set(&nv_flags, &nv_mask, optarg, 1) < 0) |
| 934 | exit(2); |
| 935 | break; |
| 936 | case 'U': |
| 937 | if (ipa_nvflag_set(&nv_flags, &nv_mask, optarg, 0) < 0) |
| 938 | exit(2); |
| 939 | break; |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 940 | case 'l': |
Harald Welte | 12a721e | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 941 | net_listen_testnr = atoi(optarg); |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 942 | break; |
Holger Hans Peter Freyther | 657079e | 2011-04-11 20:33:05 +0200 | [diff] [blame] | 943 | case 'L': |
| 944 | net_listen_testnr = get_string_value(ipa_test_strs, |
| 945 | optarg); |
| 946 | if (net_listen_testnr < 0) { |
| 947 | fprintf(stderr, |
| 948 | "The test '%s' is not known. Use -H to" |
| 949 | " see available tests.\n", optarg); |
| 950 | exit(2); |
| 951 | } |
Holger Hans Peter Freyther | 8737c5b | 2013-07-04 18:51:07 +0200 | [diff] [blame] | 952 | break; |
Holger Hans Peter Freyther | 2e021c6 | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 953 | case 's': |
| 954 | stream_id = atoi(optarg); |
Holger Hans Peter Freyther | 2e021c6 | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 955 | break; |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 956 | case 'd': |
| 957 | software = strdup(optarg); |
Holger Hans Peter Freyther | 3789c12 | 2010-03-22 09:50:56 +0100 | [diff] [blame] | 958 | if (find_sw_load_params(optarg) != 0) |
| 959 | exit(0); |
Holger Hans Peter Freyther | 4b51338 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 960 | break; |
Holger Hans Peter Freyther | f3d4a1b | 2009-12-30 07:08:39 +0100 | [diff] [blame] | 961 | case 'f': |
Holger Hans Peter Freyther | 70c67d5 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 962 | firmware_analysis = optarg; |
| 963 | break; |
Holger Hans Peter Freyther | c6f57c5 | 2010-03-22 11:22:54 +0100 | [diff] [blame] | 964 | case 'w': |
| 965 | dump_files = 1; |
| 966 | break; |
Harald Welte | a45efec | 2010-07-30 20:25:48 +0200 | [diff] [blame] | 967 | case 'c': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 968 | log_set_use_color(osmo_stderr_target, 0); |
Harald Welte | a45efec | 2010-07-30 20:25:48 +0200 | [diff] [blame] | 969 | break; |
Holger Hans Peter Freyther | 69dbdee | 2011-04-11 19:32:35 +0200 | [diff] [blame] | 970 | case 'p': |
| 971 | loop_tests = 1; |
| 972 | break; |
Holger Hans Peter Freyther | 5bcfb4f | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 973 | case 'h': |
| 974 | print_usage(); |
| 975 | print_help(); |
| 976 | exit(0); |
Holger Hans Peter Freyther | 5cf68da | 2011-04-11 20:16:52 +0200 | [diff] [blame] | 977 | case 'H': |
| 978 | print_options(); |
| 979 | exit(0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 980 | } |
| 981 | }; |
| 982 | |
Holger Hans Peter Freyther | 70c67d5 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 983 | if (firmware_analysis) |
| 984 | analyze_firmware(firmware_analysis); |
| 985 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 986 | if (optind >= argc) { |
Holger Hans Peter Freyther | 70c67d5 | 2010-03-24 05:26:24 +0100 | [diff] [blame] | 987 | /* only warn if we have not done anything else */ |
| 988 | if (!firmware_analysis) |
| 989 | fprintf(stderr, "you have to specify the IP address of the BTS. Use --help for more information\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 990 | exit(2); |
| 991 | } |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 992 | libosmo_abis_init(tall_ctx_config); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 993 | |
Neels Hofmeyr | 5494c27 | 2016-05-14 00:45:26 +0200 | [diff] [blame] | 994 | bsc_gsmnet = bsc_network_init(tall_bsc_ctx, 1, 1, NULL); |
Holger Hans Peter Freyther | ed8cc0e | 2013-04-24 11:36:15 +0200 | [diff] [blame] | 995 | if (!bsc_gsmnet) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 996 | exit(1); |
| 997 | |
Harald Welte | 7bb55f3 | 2015-11-20 10:43:31 +0100 | [diff] [blame] | 998 | bts = gsm_bts_alloc_register(bsc_gsmnet, GSM_BTS_TYPE_NANOBTS, |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 999 | HARDCODED_BSIC); |
Harald Welte (local) | 1949704 | 2009-12-28 23:15:36 +0100 | [diff] [blame] | 1000 | /* ip.access supports up to 4 chained TRX */ |
| 1001 | gsm_bts_trx_alloc(bts); |
| 1002 | gsm_bts_trx_alloc(bts); |
| 1003 | gsm_bts_trx_alloc(bts); |
Holger Hans Peter Freyther | 2e021c6 | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 1004 | bts->oml_tei = stream_id; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1005 | |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 1006 | osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL); |
| 1007 | osmo_signal_register_handler(SS_IPAC_NWL, nwl_sig_cb, NULL); |
Harald Welte | 0f31775 | 2010-03-05 19:36:20 +0100 | [diff] [blame] | 1008 | |
| 1009 | ipac_nwl_init(); |
| 1010 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1011 | printf("Trying to connect to ip.access BTS ...\n"); |
| 1012 | |
| 1013 | memset(&sin, 0, sizeof(sin)); |
| 1014 | sin.sin_family = AF_INET; |
| 1015 | inet_aton(argv[optind], &sin.sin_addr); |
| 1016 | rc = ia_config_connect(bts, &sin); |
| 1017 | if (rc < 0) { |
| 1018 | perror("Error connecting to the BTS"); |
| 1019 | exit(1); |
| 1020 | } |
| 1021 | |
Holger Hans Peter Freyther | 038834b | 2010-04-26 16:02:04 +0800 | [diff] [blame] | 1022 | bts->oml_link->ts->sign.delay = 10; |
| 1023 | bts->c0->rsl_link->ts->sign.delay = 10; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1024 | while (1) { |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 1025 | rc = osmo_select_main(0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1026 | if (rc < 0) |
| 1027 | exit(3); |
| 1028 | } |
| 1029 | |
| 1030 | exit(0); |
| 1031 | } |
| 1032 | |