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; |
| 218 | } |
| 219 | return 0; |
| 220 | } |
| 221 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 222 | static void bootstrap_om(struct gsm_bts *bts) |
| 223 | { |
| 224 | int len; |
| 225 | static u_int8_t buf[1024]; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 226 | u_int8_t *cur = buf; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 227 | |
| 228 | printf("OML link established\n"); |
| 229 | |
| 230 | if (unit_id) { |
| 231 | len = strlen(unit_id); |
| 232 | if (len > sizeof(buf)-10) |
| 233 | return; |
| 234 | buf[0] = NM_ATT_IPACC_UNIT_ID; |
| 235 | buf[1] = (len+1) >> 8; |
| 236 | buf[2] = (len+1) & 0xff; |
| 237 | memcpy(buf+3, unit_id, len); |
| 238 | buf[3+len] = 0; |
| 239 | printf("setting Unit ID to '%s'\n", unit_id); |
| 240 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len+1); |
| 241 | } |
| 242 | if (prim_oml_ip) { |
| 243 | struct in_addr ia; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 244 | |
| 245 | if (!inet_aton(prim_oml_ip, &ia)) { |
| 246 | fprintf(stderr, "invalid IP address: %s\n", |
| 247 | prim_oml_ip); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | /* 0x88 + IP + port */ |
| 252 | len = 1 + sizeof(ia) + 2; |
| 253 | |
Harald Welte | 0efe9b7 | 2009-07-12 09:33:54 +0200 | [diff] [blame] | 254 | *cur++ = NM_ATT_IPACC_PRIM_OML_CFG_LIST; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 255 | *cur++ = (len) >> 8; |
| 256 | *cur++ = (len) & 0xff; |
| 257 | *cur++ = 0x88; |
| 258 | memcpy(cur, &ia, sizeof(ia)); |
| 259 | cur += sizeof(ia); |
| 260 | *cur++ = 0; |
| 261 | *cur++ = 0; |
Harald Welte | 4802b88 | 2009-04-30 16:23:45 +0000 | [diff] [blame] | 262 | printf("setting primary OML link IP to '%s'\n", inet_ntoa(ia)); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 263 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len); |
| 264 | } |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 265 | if (nv_mask) { |
| 266 | len = 4; |
| 267 | |
| 268 | *cur++ = NM_ATT_IPACC_NV_FLAGS; |
| 269 | *cur++ = (len) >> 8; |
| 270 | *cur++ = (len) & 0xff; |
| 271 | *cur++ = nv_flags & 0xff; |
| 272 | *cur++ = nv_mask & 0xff; |
| 273 | *cur++ = nv_flags >> 8; |
| 274 | *cur++ = nv_mask >> 8; |
| 275 | printf("setting NV Flags/Mask to 0x%04x/0x%04x\n", |
| 276 | nv_flags, nv_mask); |
| 277 | abis_nm_ipaccess_set_nvattr(bts, buf, 3+len); |
| 278 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 279 | |
| 280 | if (restart) { |
| 281 | printf("restarting BTS\n"); |
| 282 | abis_nm_ipaccess_restart(bts); |
| 283 | } |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 284 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx) |
| 288 | { |
| 289 | switch (event) { |
| 290 | case EVT_E1_TEI_UP: |
| 291 | switch (type) { |
| 292 | case E1INP_SIGN_OML: |
| 293 | bootstrap_om(trx->bts); |
| 294 | break; |
| 295 | case E1INP_SIGN_RSL: |
| 296 | /* FIXME */ |
| 297 | break; |
| 298 | default: |
| 299 | break; |
| 300 | } |
| 301 | break; |
| 302 | case EVT_E1_TEI_DN: |
| 303 | fprintf(stderr, "Lost some E1 TEI link\n"); |
| 304 | /* FIXME: deal with TEI or L1 link loss */ |
| 305 | break; |
| 306 | default: |
| 307 | break; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj, |
| 312 | struct gsm_nm_state *old_state, struct gsm_nm_state *new_state) |
| 313 | { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 314 | if (evt == EVT_STATECHG_OPER && |
| 315 | obj_class == NM_OC_RADIO_CARRIER && |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 316 | new_state->availability == 3) { |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 317 | struct gsm_bts_trx *trx = obj; |
Holger Hans Peter Freyther | ab2c8b1 | 2009-12-28 07:27:43 +0100 | [diff] [blame] | 318 | |
| 319 | if (net_listen_testnr) { |
| 320 | u_int8_t phys_config[] = { 0x02, 0x0a, 0x00, 0x01, 0x02 }; |
| 321 | abis_nm_perform_test(trx->bts, 2, 0, 0, 0xff, |
| 322 | net_listen_testnr, 1, |
| 323 | phys_config, sizeof(phys_config)); |
| 324 | } else if (software) { |
| 325 | int rc; |
| 326 | printf("Attempting software upload with '%s'\n", software); |
| 327 | rc = abis_nm_software_load(trx->bts, software, 19, 0, swload_cbfn, trx->bts); |
| 328 | if (rc < 0) { |
| 329 | fprintf(stderr, "Failed to start software load\n"); |
| 330 | exit(-3); |
| 331 | } |
| 332 | } |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 333 | } |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 337 | static void print_usage(void) |
| 338 | { |
| 339 | printf("Usage: ipaccess-config\n"); |
| 340 | } |
| 341 | |
| 342 | static void print_help(void) |
| 343 | { |
| 344 | printf(" -u --unit-id UNIT_ID\n"); |
| 345 | printf(" -o --oml-ip ip\n"); |
| 346 | printf(" -r --restart\n"); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 347 | printf(" -n flags/mask\tSet NVRAM attributes.\n"); |
Holger Hans Peter Freyther | 057fec5 | 2009-11-16 19:53:08 +0100 | [diff] [blame] | 348 | printf(" -l --listen testnr \tPerform specified test number\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 349 | printf(" -h --help this text\n"); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 350 | printf(" -s --stream-id ID\n"); |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 353 | int main(int argc, char **argv) |
| 354 | { |
| 355 | struct gsm_bts *bts; |
| 356 | struct sockaddr_in sin; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 357 | int rc, option_index = 0, stream_id = 0xff; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 358 | struct debug_target *stderr_target; |
| 359 | |
| 360 | debug_init(); |
| 361 | stderr_target = debug_target_create_stderr(); |
| 362 | debug_add_target(stderr_target); |
| 363 | debug_set_all_filter(stderr_target, 1); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 364 | |
| 365 | printf("ipaccess-config (C) 2009 by Harald Welte\n"); |
| 366 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 367 | |
| 368 | while (1) { |
| 369 | int c; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 370 | unsigned long ul; |
| 371 | char *slash; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 372 | static struct option long_options[] = { |
| 373 | { "unit-id", 1, 0, 'u' }, |
| 374 | { "oml-ip", 1, 0, 'o' }, |
| 375 | { "restart", 0, 0, 'r' }, |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 376 | { "help", 0, 0, 'h' }, |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 377 | { "listen", 1, 0, 'l' }, |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 378 | { "stream-id", 1, 0, 's' }, |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 379 | { "software", 1, 0, 'd' }, |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 380 | }; |
| 381 | |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 382 | 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] | 383 | &option_index); |
| 384 | |
| 385 | if (c == -1) |
| 386 | break; |
| 387 | |
| 388 | switch (c) { |
| 389 | case 'u': |
| 390 | unit_id = optarg; |
| 391 | break; |
| 392 | case 'o': |
| 393 | prim_oml_ip = optarg; |
| 394 | break; |
| 395 | case 'r': |
| 396 | restart = 1; |
| 397 | break; |
Harald Welte | 684b1a8 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 398 | case 'n': |
| 399 | slash = strchr(optarg, '/'); |
| 400 | if (!slash) |
| 401 | exit(2); |
| 402 | ul = strtoul(optarg, NULL, 16); |
| 403 | nv_flags = ul & 0xffff; |
| 404 | ul = strtoul(slash+1, NULL, 16); |
| 405 | nv_mask = ul & 0xffff; |
| 406 | break; |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 407 | case 'l': |
Harald Welte | f1676e5 | 2009-08-10 11:39:47 +0200 | [diff] [blame] | 408 | net_listen_testnr = atoi(optarg); |
Harald Welte | c731038 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 409 | break; |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 410 | case 's': |
| 411 | stream_id = atoi(optarg); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 412 | break; |
Holger Hans Peter Freyther | f413a08 | 2009-12-28 03:11:33 +0100 | [diff] [blame] | 413 | case 'd': |
| 414 | software = strdup(optarg); |
| 415 | break; |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 416 | case 'h': |
| 417 | print_usage(); |
| 418 | print_help(); |
| 419 | exit(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 420 | } |
| 421 | }; |
| 422 | |
| 423 | if (optind >= argc) { |
Holger Hans Peter Freyther | 42b4007 | 2009-07-04 11:53:10 +0200 | [diff] [blame] | 424 | 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] | 425 | exit(2); |
| 426 | } |
| 427 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 428 | gsmnet = gsm_network_init(1, 1, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 429 | if (!gsmnet) |
| 430 | exit(1); |
| 431 | |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 432 | bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_NANOBTS, HARDCODED_TSC, |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 433 | HARDCODED_BSIC); |
Holger Hans Peter Freyther | 55aac6e | 2009-10-27 03:41:09 +0100 | [diff] [blame] | 434 | bts->oml_tei = stream_id; |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 435 | |
Holger Hans Peter Freyther | a7cd9fc | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 436 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 437 | printf("Trying to connect to ip.access BTS ...\n"); |
| 438 | |
| 439 | memset(&sin, 0, sizeof(sin)); |
| 440 | sin.sin_family = AF_INET; |
| 441 | inet_aton(argv[optind], &sin.sin_addr); |
| 442 | rc = ia_config_connect(bts, &sin); |
| 443 | if (rc < 0) { |
| 444 | perror("Error connecting to the BTS"); |
| 445 | exit(1); |
| 446 | } |
| 447 | |
| 448 | while (1) { |
Harald Welte | 04d3c92 | 2009-05-23 06:07:04 +0000 | [diff] [blame] | 449 | rc = bsc_select_main(0); |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 450 | if (rc < 0) |
| 451 | exit(3); |
| 452 | } |
| 453 | |
| 454 | exit(0); |
| 455 | } |
| 456 | |