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