Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 1 | /* ip.access nanoBTS configuration tool */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 4 | * (C) 2009 by Holger Hans Peter Freyther |
| 5 | * (C) 2009 by On Waves |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <unistd.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <getopt.h> |
| 29 | #include <sys/types.h> |
| 30 | |
| 31 | #include <sys/socket.h> |
| 32 | #include <netinet/in.h> |
| 33 | #include <arpa/inet.h> |
| 34 | |
| 35 | |
| 36 | #include <openbsc/select.h> |
| 37 | #include <openbsc/timer.h> |
| 38 | #include <openbsc/ipaccess.h> |
| 39 | #include <openbsc/gsm_data.h> |
| 40 | #include <openbsc/e1_input.h> |
| 41 | #include <openbsc/abis_nm.h> |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 42 | #include <openbsc/signal.h> |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 43 | #include <openbsc/debug.h> |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 44 | |
| 45 | static struct gsm_network *gsmnet; |
| 46 | |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 47 | static int net_listen_testnr; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 48 | static int restart; |
| 49 | static char *prim_oml_ip; |
| 50 | static char *unit_id; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 51 | static u_int16_t nv_flags; |
| 52 | static u_int16_t nv_mask; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 53 | static char *software = NULL; |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 54 | static int sw_load_state = 0; |
| 55 | |
| 56 | struct sw_load { |
| 57 | u_int8_t file_id[255]; |
| 58 | u_int8_t file_id_len; |
| 59 | |
| 60 | u_int8_t file_version[255]; |
| 61 | u_int8_t file_version_len; |
| 62 | }; |
| 63 | |
| 64 | static struct sw_load *sw_load1 = NULL; |
| 65 | static struct sw_load *sw_load2 = NULL; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | static u_int8_t prim_oml_attr[] = { 0x95, 0x00, 7, 0x88, 192, 168, 100, 11, 0x00, 0x00 }; |
| 69 | static u_int8_t unit_id_attr[] = { 0x91, 0x00, 9, '2', '3', '4', '2', '/' , '0', '/', '0', 0x00 }; |
| 70 | */ |
| 71 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 72 | /* |
| 73 | * Callback function for NACK on the OML NM |
| 74 | * |
| 75 | * Currently we send the config requests but don't check the |
| 76 | * result. The nanoBTS will send us a NACK when we did something the |
| 77 | * BTS didn't like. |
| 78 | */ |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 79 | static int ipacc_msg_nack(u_int8_t mt) |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 80 | { |
| 81 | fprintf(stderr, "Failure to set attribute. This seems fatal\n"); |
| 82 | exit(-1); |
| 83 | return 0; |
| 84 | } |
| 85 | |
Holger Hans Peter Freyther | 086ffa5 | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 86 | static int ipacc_msg_ack(u_int8_t mt) |
| 87 | { |
| 88 | if (sw_load_state == 1) { |
| 89 | fprintf(stderr, "The new software is activaed.\n"); |
| 90 | exit(0); |
| 91 | } |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 96 | struct ipacc_ferr_elem { |
| 97 | int16_t freq_err; |
| 98 | u_int8_t freq_qual; |
| 99 | u_int8_t arfcn; |
| 100 | } __attribute__((packed)); |
| 101 | |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 102 | struct ipacc_cusage_elem { |
| 103 | u_int16_t arfcn:10, |
| 104 | rxlev:6; |
| 105 | } __attribute__ ((packed)); |
| 106 | |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 107 | static int test_rep(void *_msg) |
| 108 | { |
| 109 | struct msgb *msg = _msg; |
| 110 | struct abis_om_fom_hdr *foh = msgb_l3(msg); |
| 111 | u_int16_t test_rep_len, ferr_list_len; |
| 112 | struct ipacc_ferr_elem *ife; |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 113 | struct ipac_bcch_info binfo; |
| 114 | int i, rc; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 115 | |
| 116 | DEBUGP(DNM, "TEST REPORT: "); |
| 117 | |
| 118 | if (foh->data[0] != NM_ATT_TEST_NO || |
| 119 | foh->data[2] != NM_ATT_TEST_REPORT) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | DEBUGPC(DNM, "test_no=0x%02x ", foh->data[1]); |
| 123 | /* data[2] == NM_ATT_TEST_REPORT */ |
| 124 | /* data[3..4]: test_rep_len */ |
| 125 | test_rep_len = ntohs(*(u_int16_t *) &foh->data[3]); |
| 126 | /* data[5]: ip.access test result */ |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 127 | DEBUGPC(DNM, "test_res=%s\n", ipacc_testres_name(foh->data[5])); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 128 | |
| 129 | /* data[6]: ip.access nested IE. 3 == freq_err_list */ |
| 130 | switch (foh->data[6]) { |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 131 | case NM_IPAC_EIE_FREQ_ERR_LIST: |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 132 | /* data[7..8]: length of ferr_list */ |
| 133 | ferr_list_len = ntohs(*(u_int16_t *) &foh->data[7]); |
| 134 | |
| 135 | /* data[9...]: frequency error list elements */ |
| 136 | for (i = 0; i < ferr_list_len; i+= sizeof(*ife)) { |
| 137 | ife = (struct ipacc_ferr_elem *) (foh->data + 9 + i); |
| 138 | DEBUGP(DNM, "==> ARFCN %4u, Frequency Error %6hd\n", |
| 139 | ife->arfcn, ntohs(ife->freq_err)); |
| 140 | } |
| 141 | break; |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 142 | case NM_IPAC_EIE_CHAN_USE_LIST: |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 143 | /* data[7..8]: length of ferr_list */ |
| 144 | ferr_list_len = ntohs(*(u_int16_t *) &foh->data[7]); |
| 145 | |
| 146 | /* data[9...]: channel usage list elements */ |
| 147 | for (i = 0; i < ferr_list_len; i+= 2) { |
| 148 | u_int16_t *cu_ptr = (u_int16_t *)(foh->data + 9 + i); |
| 149 | u_int16_t cu = ntohs(*cu_ptr); |
| 150 | DEBUGP(DNM, "==> ARFCN %4u, RxLev %2u\n", |
| 151 | cu & 0x3ff, cu >> 10); |
| 152 | } |
| 153 | break; |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 154 | case NM_IPAC_EIE_BCCH_INFO_TYPE: |
| 155 | break; |
| 156 | case NM_IPAC_EIE_BCCH_INFO: |
| 157 | rc = ipac_parse_bcch_info(&binfo, foh->data+6); |
| 158 | if (rc < 0) { |
| 159 | DEBUGP(DNM, "BCCH Info parsing failed\n"); |
| 160 | break; |
| 161 | } |
| 162 | DEBUGP(DNM, "==> ARFCN %u, RxLev %2u, RxQual %2u: %3d-%d, LAC %d CI %d\n", |
| 163 | binfo.arfcn, binfo.rx_lev, binfo.rx_qual, |
| 164 | binfo.cgi.mcc, binfo.cgi.mnc, |
| 165 | binfo.cgi.lac, binfo.cgi.ci); |
| 166 | break; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 167 | default: |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 174 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 175 | void *handler_data, void *signal_data) |
| 176 | { |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 177 | u_int8_t *msg_type; |
| 178 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 179 | switch (signal) { |
| 180 | case S_NM_IPACC_NACK: |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 181 | msg_type = signal_data; |
| 182 | return ipacc_msg_nack(*msg_type); |
Holger Hans Peter Freyther | 086ffa5 | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 183 | case S_NM_IPACC_ACK: |
| 184 | msg_type = signal_data; |
| 185 | return ipacc_msg_ack(*msg_type); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 186 | case S_NM_TEST_REP: |
| 187 | return test_rep(signal_data); |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 188 | default: |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 195 | /* callback function passed to the ABIS OML code */ |
| 196 | static int percent; |
| 197 | static int percent_old; |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 198 | static int swload_cbfn(unsigned int hook, unsigned int event, struct msgb *_msg, |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 199 | void *data, void *param) |
| 200 | { |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 201 | struct msgb *msg; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 202 | struct gsm_bts *bts; |
| 203 | |
| 204 | if (hook != GSM_HOOK_NM_SWLOAD) |
| 205 | return 0; |
| 206 | |
| 207 | bts = (struct gsm_bts *) data; |
| 208 | |
| 209 | switch (event) { |
| 210 | case NM_MT_LOAD_INIT_ACK: |
| 211 | fprintf(stdout, "Software Load Initiate ACK\n"); |
| 212 | break; |
| 213 | case NM_MT_LOAD_INIT_NACK: |
| 214 | fprintf(stderr, "ERROR: Software Load Initiate NACK\n"); |
| 215 | exit(5); |
| 216 | break; |
| 217 | case NM_MT_LOAD_END_ACK: |
| 218 | fprintf(stderr, "LOAD END ACK..."); |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 219 | /* now make it the default */ |
| 220 | sw_load_state = 1; |
| 221 | |
| 222 | msg = msgb_alloc(1024, "sw: nvattr"); |
| 223 | msg->l2h = msgb_put(msg, 3); |
| 224 | msg->l3h = &msg->l2h[3]; |
| 225 | |
| 226 | /* activate software */ |
| 227 | if (sw_load1) { |
| 228 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
| 229 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw_load1->file_id_len, sw_load1->file_id); |
| 230 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw_load1->file_version_len, |
| 231 | sw_load1->file_version); |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 232 | } |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 233 | |
| 234 | if (sw_load2) { |
| 235 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
Holger Hans Peter Freyther | e519896 | 2009-12-29 11:12:00 +0100 | [diff] [blame] | 236 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw_load2->file_id_len, sw_load2->file_id); |
Holger Hans Peter Freyther | 0b864db | 2009-12-28 12:18:37 +0100 | [diff] [blame] | 237 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw_load2->file_version_len, |
| 238 | sw_load2->file_version); |
| 239 | } |
| 240 | |
| 241 | /* fill in the data */ |
| 242 | msg->l2h[0] = NM_ATT_IPACC_CUR_SW_CFG; |
| 243 | msg->l2h[1] = msgb_l3len(msg) >> 8; |
| 244 | msg->l2h[2] = msgb_l3len(msg) & 0xff; |
| 245 | printf("Foo l2h: %p l3h: %p... length l2: %u l3: %u\n", msg->l2h, msg->l3h, msgb_l2len(msg), msgb_l3len(msg)); |
| 246 | abis_nm_ipaccess_set_nvattr(bts, msg->l2h, msgb_l2len(msg)); |
| 247 | msgb_free(msg); |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 248 | break; |
| 249 | case NM_MT_LOAD_END_NACK: |
| 250 | fprintf(stderr, "ERROR: Software Load End NACK\n"); |
| 251 | exit(3); |
| 252 | break; |
| 253 | case NM_MT_ACTIVATE_SW_NACK: |
| 254 | fprintf(stderr, "ERROR: Activate Software NACK\n"); |
| 255 | exit(4); |
| 256 | break; |
| 257 | case NM_MT_ACTIVATE_SW_ACK: |
| 258 | break; |
| 259 | case NM_MT_LOAD_SEG_ACK: |
| 260 | percent = abis_nm_software_load_status(bts); |
| 261 | if (percent > percent_old) |
| 262 | printf("Software Download Progress: %d%%\n", percent); |
| 263 | percent_old = percent; |
| 264 | break; |
Holger Hans Peter Freyther | c7aabca | 2009-12-28 12:23:02 +0100 | [diff] [blame] | 265 | case NM_MT_LOAD_ABORT: |
| 266 | fprintf(stderr, "ERROR: Load aborted by the BTS.\n"); |
| 267 | exit(6); |
| 268 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 269 | } |
| 270 | return 0; |
| 271 | } |
| 272 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 273 | static void bootstrap_om(struct gsm_bts *bts) |
| 274 | { |
| 275 | int len; |
| 276 | static u_int8_t buf[1024]; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 277 | u_int8_t *cur = buf; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 278 | |
| 279 | printf("OML link established\n"); |
| 280 | |
| 281 | if (unit_id) { |
| 282 | len = strlen(unit_id); |
| 283 | if (len > sizeof(buf)-10) |
| 284 | return; |
| 285 | buf[0] = NM_ATT_IPACC_UNIT_ID; |
| 286 | buf[1] = (len+1) >> 8; |
| 287 | buf[2] = (len+1) & 0xff; |
| 288 | memcpy(buf+3, unit_id, len); |
| 289 | buf[3+len] = 0; |
| 290 | printf("setting Unit ID to '%s'\n", unit_id); |
| 291 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len+1); |
| 292 | } |
| 293 | if (prim_oml_ip) { |
| 294 | struct in_addr ia; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 295 | |
| 296 | if (!inet_aton(prim_oml_ip, &ia)) { |
| 297 | fprintf(stderr, "invalid IP address: %s\n", |
| 298 | prim_oml_ip); |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | /* 0x88 + IP + port */ |
| 303 | len = 1 + sizeof(ia) + 2; |
| 304 | |
Harald Welte | 0efe9b7 | 2009-07-12 09:33:54 +0200 | [diff] [blame] | 305 | *cur++ = NM_ATT_IPACC_PRIM_OML_CFG_LIST; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 306 | *cur++ = (len) >> 8; |
| 307 | *cur++ = (len) & 0xff; |
| 308 | *cur++ = 0x88; |
| 309 | memcpy(cur, &ia, sizeof(ia)); |
| 310 | cur += sizeof(ia); |
| 311 | *cur++ = 0; |
| 312 | *cur++ = 0; |
Harald Welte | 4802b88 | 2009-04-30 16:23:45 +0000 | [diff] [blame] | 313 | printf("setting primary OML link IP to '%s'\n", inet_ntoa(ia)); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 314 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len); |
| 315 | } |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 316 | if (nv_mask) { |
| 317 | len = 4; |
| 318 | |
| 319 | *cur++ = NM_ATT_IPACC_NV_FLAGS; |
| 320 | *cur++ = (len) >> 8; |
| 321 | *cur++ = (len) & 0xff; |
| 322 | *cur++ = nv_flags & 0xff; |
| 323 | *cur++ = nv_mask & 0xff; |
| 324 | *cur++ = nv_flags >> 8; |
| 325 | *cur++ = nv_mask >> 8; |
| 326 | printf("setting NV Flags/Mask to 0x%04x/0x%04x\n", |
| 327 | nv_flags, nv_mask); |
| 328 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len); |
| 329 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 330 | |
| 331 | if (restart) { |
| 332 | printf("restarting BTS\n"); |
| 333 | abis_nm_ipaccess_restart(bts); |
| 334 | } |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 335 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
| 339 | { |
| 340 | switch (event) { |
| 341 | case EVT_E1_TEI_UP: |
| 342 | switch (type) { |
| 343 | case E1INP_SIGN_OML: |
| 344 | bootstrap_om(trx->bts); |
| 345 | break; |
| 346 | case E1INP_SIGN_RSL: |
| 347 | /* FIXME */ |
| 348 | break; |
| 349 | default: |
| 350 | break; |
| 351 | } |
| 352 | break; |
| 353 | case EVT_E1_TEI_DN: |
| 354 | fprintf(stderr, "Lost some E1 TEI link\n"); |
| 355 | /* FIXME: deal with TEI or L1 link loss */ |
| 356 | break; |
| 357 | default: |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 363 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 364 | { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 365 | if (evt == EVT_STATECHG_OPER && |
| 366 | obj_class == NM_OC_RADIO_CARRIER && |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 367 | new_state->availability == 3) { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 368 | struct gsm_bts_trx *trx = obj; |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 369 | |
| 370 | if (net_listen_testnr) { |
| 371 | u_int8_t phys_config[] = { 0x02, 0x0a, 0x00, 0x01, 0x02 }; |
| 372 | abis_nm_perform_test(trx->bts, 2, 0, 0, 0xff, |
| 373 | net_listen_testnr, 1, |
| 374 | phys_config, sizeof(phys_config)); |
| 375 | } else if (software) { |
| 376 | int rc; |
| 377 | printf("Attempting software upload with '%s'\n", software); |
| 378 | rc = abis_nm_software_load(trx->bts, software, 19, 0, swload_cbfn, trx->bts); |
| 379 | if (rc < 0) { |
| 380 | fprintf(stderr, "Failed to start software load\n"); |
| 381 | exit(-3); |
| 382 | } |
| 383 | } |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 384 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 388 | static void print_usage(void) |
| 389 | { |
| 390 | printf("Usage: ipaccess-config\n"); |
| 391 | } |
| 392 | |
| 393 | static void print_help(void) |
| 394 | { |
| 395 | printf(" -u --unit-id UNIT_ID\n"); |
| 396 | printf(" -o --oml-ip ip\n"); |
| 397 | printf(" -r --restart\n"); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 398 | printf(" -n flags/mask\tSet NVRAM attributes.\n"); |
Holger Hans Peter Freyther | 057fec5 | 2009-11-16 19:53:08 +0100 | [diff] [blame] | 399 | printf(" -l --listen testnr \tPerform specified test number\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 400 | printf(" -h --help this text\n"); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 401 | printf(" -s --stream-id ID\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 404 | int main(int argc, char **argv) |
| 405 | { |
| 406 | struct gsm_bts *bts; |
| 407 | struct sockaddr_in sin; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 408 | int rc, option_index = 0, stream_id = 0xff; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 409 | struct debug_target *stderr_target; |
| 410 | |
| 411 | debug_init(); |
| 412 | stderr_target = debug_target_create_stderr(); |
| 413 | debug_add_target(stderr_target); |
| 414 | debug_set_all_filter(stderr_target, 1); |
Harald Welte (local) | 93f4207 | 2009-12-28 23:15:36 +0100 | [diff] [blame] | 415 | debug_set_log_level(stderr_target, 0); |
| 416 | debug_parse_category_mask(stderr_target, "DNM,0"); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 417 | |
| 418 | printf("ipaccess-config (C) 2009 by Harald Welte\n"); |
| 419 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 420 | |
| 421 | while (1) { |
| 422 | int c; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 423 | unsigned long ul; |
| 424 | char *slash; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 425 | static struct option long_options[] = { |
| 426 | { "unit-id", 1, 0, 'u' }, |
| 427 | { "oml-ip", 1, 0, 'o' }, |
| 428 | { "restart", 0, 0, 'r' }, |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 429 | { "help", 0, 0, 'h' }, |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 430 | { "listen", 1, 0, 'l' }, |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 431 | { "stream-id", 1, 0, 's' }, |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 432 | { "software", 1, 0, 'd' }, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 433 | }; |
| 434 | |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 435 | c = getopt_long(argc, argv, "u:o:rn:l:hs:d:", long_options, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 436 | &option_index); |
| 437 | |
| 438 | if (c == -1) |
| 439 | break; |
| 440 | |
| 441 | switch (c) { |
| 442 | case 'u': |
| 443 | unit_id = optarg; |
| 444 | break; |
| 445 | case 'o': |
| 446 | prim_oml_ip = optarg; |
| 447 | break; |
| 448 | case 'r': |
| 449 | restart = 1; |
| 450 | break; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 451 | case 'n': |
| 452 | slash = strchr(optarg, '/'); |
| 453 | if (!slash) |
| 454 | exit(2); |
| 455 | ul = strtoul(optarg, NULL, 16); |
| 456 | nv_flags = ul & 0xffff; |
| 457 | ul = strtoul(slash+1, NULL, 16); |
| 458 | nv_mask = ul & 0xffff; |
| 459 | break; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 460 | case 'l': |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 461 | net_listen_testnr = atoi(optarg); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 462 | break; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 463 | case 's': |
| 464 | stream_id = atoi(optarg); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 465 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 466 | case 'd': |
| 467 | software = strdup(optarg); |
| 468 | break; |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 469 | case 'h': |
| 470 | print_usage(); |
| 471 | print_help(); |
| 472 | exit(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 473 | } |
| 474 | }; |
| 475 | |
| 476 | if (optind >= argc) { |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 477 | fprintf(stderr, "you have to specify the IP address of the BTS. Use --help for more information\n"); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 478 | exit(2); |
| 479 | } |
| 480 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 481 | gsmnet = gsm_network_init(1, 1, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 482 | if (!gsmnet) |
| 483 | exit(1); |
| 484 | |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 485 | bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_NANOBTS, HARDCODED_TSC, |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 486 | HARDCODED_BSIC); |
Harald Welte (local) | 93f4207 | 2009-12-28 23:15:36 +0100 | [diff] [blame] | 487 | /* ip.access supports up to 4 chained TRX */ |
| 488 | gsm_bts_trx_alloc(bts); |
| 489 | gsm_bts_trx_alloc(bts); |
| 490 | gsm_bts_trx_alloc(bts); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 491 | bts->oml_tei = stream_id; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 492 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 493 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 494 | printf("Trying to connect to ip.access BTS ...\n"); |
| 495 | |
| 496 | memset(&sin, 0, sizeof(sin)); |
| 497 | sin.sin_family = AF_INET; |
| 498 | inet_aton(argv[optind], &sin.sin_addr); |
| 499 | rc = ia_config_connect(bts, &sin); |
| 500 | if (rc < 0) { |
| 501 | perror("Error connecting to the BTS"); |
| 502 | exit(1); |
| 503 | } |
| 504 | |
| 505 | while (1) { |
Harald Welte | 04d3c92 | 2009-05-23 06:07:04 +0000 | [diff] [blame] | 506 | rc = bsc_select_main(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 507 | if (rc < 0) |
| 508 | exit(3); |
| 509 | } |
| 510 | |
| 511 | exit(0); |
| 512 | } |
| 513 | |