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; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | static u_int8_t prim_oml_attr[] = { 0x95, 0x00, 7, 0x88, 192, 168, 100, 11, 0x00, 0x00 }; |
| 57 | static u_int8_t unit_id_attr[] = { 0x91, 0x00, 9, '2', '3', '4', '2', '/' , '0', '/', '0', 0x00 }; |
| 58 | */ |
| 59 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 60 | /* |
| 61 | * Callback function for NACK on the OML NM |
| 62 | * |
| 63 | * Currently we send the config requests but don't check the |
| 64 | * result. The nanoBTS will send us a NACK when we did something the |
| 65 | * BTS didn't like. |
| 66 | */ |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 67 | static int ipacc_msg_nack(u_int8_t mt) |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 68 | { |
| 69 | fprintf(stderr, "Failure to set attribute. This seems fatal\n"); |
| 70 | exit(-1); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 74 | struct ipacc_ferr_elem { |
| 75 | int16_t freq_err; |
| 76 | u_int8_t freq_qual; |
| 77 | u_int8_t arfcn; |
| 78 | } __attribute__((packed)); |
| 79 | |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 80 | struct ipacc_cusage_elem { |
| 81 | u_int16_t arfcn:10, |
| 82 | rxlev:6; |
| 83 | } __attribute__ ((packed)); |
| 84 | |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 85 | static int test_rep(void *_msg) |
| 86 | { |
| 87 | struct msgb *msg = _msg; |
| 88 | struct abis_om_fom_hdr *foh = msgb_l3(msg); |
| 89 | u_int16_t test_rep_len, ferr_list_len; |
| 90 | struct ipacc_ferr_elem *ife; |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 91 | struct ipac_bcch_info binfo; |
| 92 | int i, rc; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 93 | |
| 94 | DEBUGP(DNM, "TEST REPORT: "); |
| 95 | |
| 96 | if (foh->data[0] != NM_ATT_TEST_NO || |
| 97 | foh->data[2] != NM_ATT_TEST_REPORT) |
| 98 | return -EINVAL; |
| 99 | |
| 100 | DEBUGPC(DNM, "test_no=0x%02x ", foh->data[1]); |
| 101 | /* data[2] == NM_ATT_TEST_REPORT */ |
| 102 | /* data[3..4]: test_rep_len */ |
| 103 | test_rep_len = ntohs(*(u_int16_t *) &foh->data[3]); |
| 104 | /* data[5]: ip.access test result */ |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 105 | DEBUGPC(DNM, "test_res=%s\n", ipacc_testres_name(foh->data[5])); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 106 | |
| 107 | /* data[6]: ip.access nested IE. 3 == freq_err_list */ |
| 108 | switch (foh->data[6]) { |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 109 | case NM_IPAC_EIE_FREQ_ERR_LIST: |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 110 | /* data[7..8]: length of ferr_list */ |
| 111 | ferr_list_len = ntohs(*(u_int16_t *) &foh->data[7]); |
| 112 | |
| 113 | /* data[9...]: frequency error list elements */ |
| 114 | for (i = 0; i < ferr_list_len; i+= sizeof(*ife)) { |
| 115 | ife = (struct ipacc_ferr_elem *) (foh->data + 9 + i); |
| 116 | DEBUGP(DNM, "==> ARFCN %4u, Frequency Error %6hd\n", |
| 117 | ife->arfcn, ntohs(ife->freq_err)); |
| 118 | } |
| 119 | break; |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 120 | case NM_IPAC_EIE_CHAN_USE_LIST: |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 121 | /* data[7..8]: length of ferr_list */ |
| 122 | ferr_list_len = ntohs(*(u_int16_t *) &foh->data[7]); |
| 123 | |
| 124 | /* data[9...]: channel usage list elements */ |
| 125 | for (i = 0; i < ferr_list_len; i+= 2) { |
| 126 | u_int16_t *cu_ptr = (u_int16_t *)(foh->data + 9 + i); |
| 127 | u_int16_t cu = ntohs(*cu_ptr); |
| 128 | DEBUGP(DNM, "==> ARFCN %4u, RxLev %2u\n", |
| 129 | cu & 0x3ff, cu >> 10); |
| 130 | } |
| 131 | break; |
Harald Welte | cf01b8f | 2009-11-13 14:43:15 +0100 | [diff] [blame] | 132 | case NM_IPAC_EIE_BCCH_INFO_TYPE: |
| 133 | break; |
| 134 | case NM_IPAC_EIE_BCCH_INFO: |
| 135 | rc = ipac_parse_bcch_info(&binfo, foh->data+6); |
| 136 | if (rc < 0) { |
| 137 | DEBUGP(DNM, "BCCH Info parsing failed\n"); |
| 138 | break; |
| 139 | } |
| 140 | DEBUGP(DNM, "==> ARFCN %u, RxLev %2u, RxQual %2u: %3d-%d, LAC %d CI %d\n", |
| 141 | binfo.arfcn, binfo.rx_lev, binfo.rx_qual, |
| 142 | binfo.cgi.mcc, binfo.cgi.mnc, |
| 143 | binfo.cgi.lac, binfo.cgi.ci); |
| 144 | break; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 145 | default: |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 152 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 153 | void *handler_data, void *signal_data) |
| 154 | { |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 155 | u_int8_t *msg_type; |
| 156 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 157 | switch (signal) { |
| 158 | case S_NM_IPACC_NACK: |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 159 | msg_type = signal_data; |
| 160 | return ipacc_msg_nack(*msg_type); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 161 | case S_NM_TEST_REP: |
| 162 | return test_rep(signal_data); |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 163 | default: |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 170 | /* callback function passed to the ABIS OML code */ |
| 171 | static int percent; |
| 172 | static int percent_old; |
| 173 | static int swload_cbfn(unsigned int hook, unsigned int event, struct msgb *msg, |
| 174 | void *data, void *param) |
| 175 | { |
| 176 | struct gsm_bts *bts; |
| 177 | |
| 178 | if (hook != GSM_HOOK_NM_SWLOAD) |
| 179 | return 0; |
| 180 | |
| 181 | bts = (struct gsm_bts *) data; |
| 182 | |
| 183 | switch (event) { |
| 184 | case NM_MT_LOAD_INIT_ACK: |
| 185 | fprintf(stdout, "Software Load Initiate ACK\n"); |
| 186 | break; |
| 187 | case NM_MT_LOAD_INIT_NACK: |
| 188 | fprintf(stderr, "ERROR: Software Load Initiate NACK\n"); |
| 189 | exit(5); |
| 190 | break; |
| 191 | case NM_MT_LOAD_END_ACK: |
| 192 | fprintf(stderr, "LOAD END ACK..."); |
| 193 | #if 0 |
| 194 | if (data) { |
| 195 | /* we did a safety load and must activate it */ |
| 196 | abis_nm_software_activate(g_bts, fname_safety, |
| 197 | swload_cbfn, bts); |
| 198 | sleep(5); |
| 199 | } |
| 200 | #endif |
| 201 | break; |
| 202 | case NM_MT_LOAD_END_NACK: |
| 203 | fprintf(stderr, "ERROR: Software Load End NACK\n"); |
| 204 | exit(3); |
| 205 | break; |
| 206 | case NM_MT_ACTIVATE_SW_NACK: |
| 207 | fprintf(stderr, "ERROR: Activate Software NACK\n"); |
| 208 | exit(4); |
| 209 | break; |
| 210 | case NM_MT_ACTIVATE_SW_ACK: |
| 211 | break; |
| 212 | case NM_MT_LOAD_SEG_ACK: |
| 213 | percent = abis_nm_software_load_status(bts); |
| 214 | if (percent > percent_old) |
| 215 | printf("Software Download Progress: %d%%\n", percent); |
| 216 | percent_old = percent; |
| 217 | break; |
Holger Hans Peter Freyther | c7aabca | 2009-12-28 12:23:02 +0100 | [diff] [blame^] | 218 | case NM_MT_LOAD_ABORT: |
| 219 | fprintf(stderr, "ERROR: Load aborted by the BTS.\n"); |
| 220 | exit(6); |
| 221 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 222 | } |
| 223 | return 0; |
| 224 | } |
| 225 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 226 | static void bootstrap_om(struct gsm_bts *bts) |
| 227 | { |
| 228 | int len; |
| 229 | static u_int8_t buf[1024]; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 230 | u_int8_t *cur = buf; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 231 | |
| 232 | printf("OML link established\n"); |
| 233 | |
| 234 | if (unit_id) { |
| 235 | len = strlen(unit_id); |
| 236 | if (len > sizeof(buf)-10) |
| 237 | return; |
| 238 | buf[0] = NM_ATT_IPACC_UNIT_ID; |
| 239 | buf[1] = (len+1) >> 8; |
| 240 | buf[2] = (len+1) & 0xff; |
| 241 | memcpy(buf+3, unit_id, len); |
| 242 | buf[3+len] = 0; |
| 243 | printf("setting Unit ID to '%s'\n", unit_id); |
| 244 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len+1); |
| 245 | } |
| 246 | if (prim_oml_ip) { |
| 247 | struct in_addr ia; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 248 | |
| 249 | if (!inet_aton(prim_oml_ip, &ia)) { |
| 250 | fprintf(stderr, "invalid IP address: %s\n", |
| 251 | prim_oml_ip); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | /* 0x88 + IP + port */ |
| 256 | len = 1 + sizeof(ia) + 2; |
| 257 | |
Harald Welte | 0efe9b7 | 2009-07-12 09:33:54 +0200 | [diff] [blame] | 258 | *cur++ = NM_ATT_IPACC_PRIM_OML_CFG_LIST; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 259 | *cur++ = (len) >> 8; |
| 260 | *cur++ = (len) & 0xff; |
| 261 | *cur++ = 0x88; |
| 262 | memcpy(cur, &ia, sizeof(ia)); |
| 263 | cur += sizeof(ia); |
| 264 | *cur++ = 0; |
| 265 | *cur++ = 0; |
Harald Welte | 4802b88 | 2009-04-30 16:23:45 +0000 | [diff] [blame] | 266 | printf("setting primary OML link IP to '%s'\n", inet_ntoa(ia)); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 267 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len); |
| 268 | } |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 269 | if (nv_mask) { |
| 270 | len = 4; |
| 271 | |
| 272 | *cur++ = NM_ATT_IPACC_NV_FLAGS; |
| 273 | *cur++ = (len) >> 8; |
| 274 | *cur++ = (len) & 0xff; |
| 275 | *cur++ = nv_flags & 0xff; |
| 276 | *cur++ = nv_mask & 0xff; |
| 277 | *cur++ = nv_flags >> 8; |
| 278 | *cur++ = nv_mask >> 8; |
| 279 | printf("setting NV Flags/Mask to 0x%04x/0x%04x\n", |
| 280 | nv_flags, nv_mask); |
| 281 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len); |
| 282 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 283 | |
| 284 | if (restart) { |
| 285 | printf("restarting BTS\n"); |
| 286 | abis_nm_ipaccess_restart(bts); |
| 287 | } |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 288 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
| 292 | { |
| 293 | switch (event) { |
| 294 | case EVT_E1_TEI_UP: |
| 295 | switch (type) { |
| 296 | case E1INP_SIGN_OML: |
| 297 | bootstrap_om(trx->bts); |
| 298 | break; |
| 299 | case E1INP_SIGN_RSL: |
| 300 | /* FIXME */ |
| 301 | break; |
| 302 | default: |
| 303 | break; |
| 304 | } |
| 305 | break; |
| 306 | case EVT_E1_TEI_DN: |
| 307 | fprintf(stderr, "Lost some E1 TEI link\n"); |
| 308 | /* FIXME: deal with TEI or L1 link loss */ |
| 309 | break; |
| 310 | default: |
| 311 | break; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 316 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 317 | { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 318 | if (evt == EVT_STATECHG_OPER && |
| 319 | obj_class == NM_OC_RADIO_CARRIER && |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 320 | new_state->availability == 3) { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 321 | struct gsm_bts_trx *trx = obj; |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 322 | |
| 323 | if (net_listen_testnr) { |
| 324 | u_int8_t phys_config[] = { 0x02, 0x0a, 0x00, 0x01, 0x02 }; |
| 325 | abis_nm_perform_test(trx->bts, 2, 0, 0, 0xff, |
| 326 | net_listen_testnr, 1, |
| 327 | phys_config, sizeof(phys_config)); |
| 328 | } else if (software) { |
| 329 | int rc; |
| 330 | printf("Attempting software upload with '%s'\n", software); |
| 331 | rc = abis_nm_software_load(trx->bts, software, 19, 0, swload_cbfn, trx->bts); |
| 332 | if (rc < 0) { |
| 333 | fprintf(stderr, "Failed to start software load\n"); |
| 334 | exit(-3); |
| 335 | } |
| 336 | } |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 337 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 341 | static void print_usage(void) |
| 342 | { |
| 343 | printf("Usage: ipaccess-config\n"); |
| 344 | } |
| 345 | |
| 346 | static void print_help(void) |
| 347 | { |
| 348 | printf(" -u --unit-id UNIT_ID\n"); |
| 349 | printf(" -o --oml-ip ip\n"); |
| 350 | printf(" -r --restart\n"); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 351 | printf(" -n flags/mask\tSet NVRAM attributes.\n"); |
Holger Hans Peter Freyther | 057fec5 | 2009-11-16 19:53:08 +0100 | [diff] [blame] | 352 | printf(" -l --listen testnr \tPerform specified test number\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 353 | printf(" -h --help this text\n"); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 354 | printf(" -s --stream-id ID\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 357 | int main(int argc, char **argv) |
| 358 | { |
| 359 | struct gsm_bts *bts; |
| 360 | struct sockaddr_in sin; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 361 | int rc, option_index = 0, stream_id = 0xff; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 362 | struct debug_target *stderr_target; |
| 363 | |
| 364 | debug_init(); |
| 365 | stderr_target = debug_target_create_stderr(); |
| 366 | debug_add_target(stderr_target); |
| 367 | debug_set_all_filter(stderr_target, 1); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 368 | |
| 369 | printf("ipaccess-config (C) 2009 by Harald Welte\n"); |
| 370 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 371 | |
| 372 | while (1) { |
| 373 | int c; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 374 | unsigned long ul; |
| 375 | char *slash; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 376 | static struct option long_options[] = { |
| 377 | { "unit-id", 1, 0, 'u' }, |
| 378 | { "oml-ip", 1, 0, 'o' }, |
| 379 | { "restart", 0, 0, 'r' }, |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 380 | { "help", 0, 0, 'h' }, |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 381 | { "listen", 1, 0, 'l' }, |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 382 | { "stream-id", 1, 0, 's' }, |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 383 | { "software", 1, 0, 'd' }, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 384 | }; |
| 385 | |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 386 | 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] | 387 | &option_index); |
| 388 | |
| 389 | if (c == -1) |
| 390 | break; |
| 391 | |
| 392 | switch (c) { |
| 393 | case 'u': |
| 394 | unit_id = optarg; |
| 395 | break; |
| 396 | case 'o': |
| 397 | prim_oml_ip = optarg; |
| 398 | break; |
| 399 | case 'r': |
| 400 | restart = 1; |
| 401 | break; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 402 | case 'n': |
| 403 | slash = strchr(optarg, '/'); |
| 404 | if (!slash) |
| 405 | exit(2); |
| 406 | ul = strtoul(optarg, NULL, 16); |
| 407 | nv_flags = ul & 0xffff; |
| 408 | ul = strtoul(slash+1, NULL, 16); |
| 409 | nv_mask = ul & 0xffff; |
| 410 | break; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 411 | case 'l': |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 412 | net_listen_testnr = atoi(optarg); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 413 | break; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 414 | case 's': |
| 415 | stream_id = atoi(optarg); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 416 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 417 | case 'd': |
| 418 | software = strdup(optarg); |
| 419 | break; |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 420 | case 'h': |
| 421 | print_usage(); |
| 422 | print_help(); |
| 423 | exit(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 424 | } |
| 425 | }; |
| 426 | |
| 427 | if (optind >= argc) { |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 428 | 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] | 429 | exit(2); |
| 430 | } |
| 431 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 432 | gsmnet = gsm_network_init(1, 1, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 433 | if (!gsmnet) |
| 434 | exit(1); |
| 435 | |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 436 | bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_NANOBTS, HARDCODED_TSC, |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 437 | HARDCODED_BSIC); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 438 | bts->oml_tei = stream_id; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 439 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 440 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 441 | printf("Trying to connect to ip.access BTS ...\n"); |
| 442 | |
| 443 | memset(&sin, 0, sizeof(sin)); |
| 444 | sin.sin_family = AF_INET; |
| 445 | inet_aton(argv[optind], &sin.sin_addr); |
| 446 | rc = ia_config_connect(bts, &sin); |
| 447 | if (rc < 0) { |
| 448 | perror("Error connecting to the BTS"); |
| 449 | exit(1); |
| 450 | } |
| 451 | |
| 452 | while (1) { |
Harald Welte | 04d3c92 | 2009-05-23 06:07:04 +0000 | [diff] [blame] | 453 | rc = bsc_select_main(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 454 | if (rc < 0) |
| 455 | exit(3); |
| 456 | } |
| 457 | |
| 458 | exit(0); |
| 459 | } |
| 460 | |