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