int main(int argc, char *argv[]) { struct radius_ctx ctx; struct hostapd_radius_server *srv; if (os_program_init()) return -1; hostapd_logger_register_cb(hostapd_logger_cb); os_memset(&ctx, 0, sizeof(ctx)); inet_aton("127.0.0.1", &ctx.own_ip_addr); if (eloop_init()) { printf("Failed to initialize event loop\n"); return -1; } srv = os_zalloc(sizeof(*srv)); if (srv == NULL) return -1; srv->addr.af = AF_INET; srv->port = 1812; if (hostapd_parse_ip_addr("127.0.0.1", &srv->addr) < 0) { printf("Failed to parse IP address\n"); return -1; } srv->shared_secret = (u8 *) os_strdup("radius"); srv->shared_secret_len = 6; ctx.conf.auth_server = ctx.conf.auth_servers = srv; ctx.conf.num_auth_servers = 1; ctx.conf.msg_dumps = 1; ctx.radius = radius_client_init(&ctx, &ctx.conf); if (ctx.radius == NULL) { printf("Failed to initialize RADIUS client\n"); return -1; } if (radius_client_register(ctx.radius, RADIUS_AUTH, receive_auth, &ctx) < 0) { printf("Failed to register RADIUS authentication handler\n"); return -1; } eloop_register_timeout(0, 0, start_example, &ctx, NULL); eloop_run(); radius_client_deinit(ctx.radius); os_free(srv->shared_secret); os_free(srv); eloop_destroy(); os_program_deinit(); return 0; }
static void hostapd_cli_cleanup(void) { hostapd_cli_close_connection(); if (pid_file) os_daemonize_terminate(pid_file); os_program_deinit(); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, CMDLINE lpCmdLine, int nShowCmd) { int i; struct wpa_interface *ifaces, *iface; int iface_count, exitcode = -1; struct wpa_params params; struct wpa_global *global; if (os_program_init()) return -1; os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_MSGDUMP; params.wpa_debug_use_file = 1; params.wpa_debug_show_keys = 1; iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); if (ifaces == NULL) return -1; iface_count = 1; iface->confname = "default"; iface->driver = "ndis"; iface->ifname = ""; exitcode = 0; global = wpa_supplicant_init(¶ms); if (global == NULL) { printf("Failed to initialize wpa_supplicant\n"); exitcode = -1; } for (i = 0; exitcode == 0 && i < iface_count; i++) { if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { if (iface_count == 1 && (params.ctrl_interface || params.dbus_ctrl_interface)) break; exitcode = -1; break; } if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) exitcode = -1; } if (exitcode == 0) exitcode = wpa_supplicant_run(global); wpa_supplicant_deinit(global); os_free(ifaces); os_program_deinit(); return exitcode; }
int main(int argc, char *argv[]) { struct wpa_supplicant wpa_s; int ret = -1; struct wpabuf *buf = NULL, *ndef = NULL; char txt[1000]; if (os_program_init()) return -1; random_init(NULL); os_memset(&wpa_s, 0, sizeof(wpa_s)); wpa_s.conf = os_zalloc(sizeof(*wpa_s.conf)); if (wpa_s.conf == NULL) goto fail; buf = wpas_wps_nfc_token(&wpa_s, 0); if (buf == NULL) goto fail; ndef = ndef_build_wifi(buf); if (ndef == NULL) goto fail; wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(buf), wpabuf_len(buf)); printf("#WPS=%s\n", txt); wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(ndef), wpabuf_len(ndef)); printf("#NDEF=%s\n", txt); printf("wps_nfc_dev_pw_id=%d\n", wpa_s.conf->wps_nfc_dev_pw_id); print_bin("wps_nfc_dh_pubkey", wpa_s.conf->wps_nfc_dh_pubkey); print_bin("wps_nfc_dh_privkey", wpa_s.conf->wps_nfc_dh_privkey); print_bin("wps_nfc_dev_pw", wpa_s.conf->wps_nfc_dev_pw); ret = 0; fail: wpabuf_free(ndef); wpabuf_free(buf); wpa_config_free(wpa_s.conf); random_deinit(); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { struct wpa wpa; if (os_program_init()) return -1; os_memset(&wpa, 0, sizeof(wpa)); os_memset(wpa.auth_addr, 0x12, ETH_ALEN); os_memset(wpa.supp_addr, 0x32, ETH_ALEN); os_memset(wpa.psk, 0x44, PMK_LEN); wpa_debug_level = 0; wpa_debug_show_keys = 1; if (eloop_init()) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } if (auth_init_group(&wpa) < 0) return -1; if (supp_init(&wpa) < 0) return -1; if (auth_init(&wpa) < 0) return -1; wpa_printf(MSG_DEBUG, "Starting eloop"); eloop_run(); wpa_printf(MSG_DEBUG, "eloop done"); deinit(&wpa); eloop_destroy(); os_program_deinit(); return 0; }
int main(int argc, char *argv[]) { int s; struct sockaddr_un addr; int ret = 0; if (os_program_init()) return -1; s = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (s < 0) { perror("socket"); return -1; } os_memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; os_strlcpy(addr.sun_path + 1, WLANTEST_SOCK_NAME, sizeof(addr.sun_path) - 1); if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("connect"); close(s); return -1; } if (argc > 1) { ret = ctrl_command(s, argc - 1, &argv[1]); if (ret < 0) printf("FAIL\n"); } else { wlantest_cli_interactive(s); } close(s); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; int ret = 1; size_t i, j; int c, debug = 0; const char *log_file = NULL; const char *entropy_file = NULL; char **bss_config = NULL, **tmp_bss; size_t num_bss_configs = 0; #ifdef CONFIG_DEBUG_LINUX_TRACING int enable_trace_dbg = 0; #endif /* CONFIG_DEBUG_LINUX_TRACING */ if (os_program_init()) return -1; os_memset(&interfaces, 0, sizeof(interfaces)); interfaces.reload_config = hostapd_reload_config; interfaces.config_read_cb = hostapd_config_read; interfaces.for_each_interface = hostapd_for_each_interface; interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; interfaces.driver_init = hostapd_driver_init; interfaces.global_iface_path = NULL; interfaces.global_iface_name = NULL; interfaces.global_ctrl_sock = -1; wpa_supplicant_event = hostapd_wpa_event; for (;;) { c = getopt(argc, argv, "b:Bde:f:hKP:Ttu:g:G:v::"); if (c < 0) break; switch (c) { case 'h': usage(); break; case 'd': debug++; if (wpa_debug_level > 0) wpa_debug_level--; break; case 'B': daemonize++; break; case 'e': entropy_file = optarg; break; case 'f': log_file = optarg; break; case 'K': wpa_debug_show_keys++; break; case 'P': os_free(pid_file); pid_file = os_rel2abs_path(optarg); break; case 't': wpa_debug_timestamp++; break; #ifdef CONFIG_DEBUG_LINUX_TRACING case 'T': enable_trace_dbg = 1; break; #endif /* CONFIG_DEBUG_LINUX_TRACING */ case 'v': if (optarg) exit(!has_feature(optarg)); show_version(); exit(1); break; case 'g': if (hostapd_get_global_ctrl_iface(&interfaces, optarg)) return -1; break; case 'G': if (hostapd_get_ctrl_iface_group(&interfaces, optarg)) return -1; break; case 'b': tmp_bss = os_realloc_array(bss_config, num_bss_configs + 1, sizeof(char *)); if (tmp_bss == NULL) goto out; bss_config = tmp_bss; bss_config[num_bss_configs++] = optarg; break; #ifdef CONFIG_WPS case 'u': return gen_uuid(optarg); #endif /* CONFIG_WPS */ default: usage(); break; } } if (optind == argc && interfaces.global_iface_path == NULL && num_bss_configs == 0) usage(); wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); if (log_file) wpa_debug_open_file(log_file); #ifdef CONFIG_DEBUG_LINUX_TRACING if (enable_trace_dbg) { int tret = wpa_debug_open_linux_tracing(); if (tret) { wpa_printf(MSG_ERROR, "Failed to enable trace logging"); return -1; } } #endif /* CONFIG_DEBUG_LINUX_TRACING */ interfaces.count = argc - optind; if (interfaces.count || num_bss_configs) { interfaces.iface = os_calloc(interfaces.count + num_bss_configs, sizeof(struct hostapd_iface *)); if (interfaces.iface == NULL) { wpa_printf(MSG_ERROR, "malloc failed"); return -1; } } if (hostapd_global_init(&interfaces, entropy_file)) { wpa_printf(MSG_ERROR, "Failed to initilize global context"); return -1; } /* Allocate and parse configuration for full interface files */ for (i = 0; i < interfaces.count; i++) { interfaces.iface[i] = hostapd_interface_init(&interfaces, argv[optind + i], debug); if (!interfaces.iface[i]) { wpa_printf(MSG_ERROR, "Failed to initialize interface"); goto out; } } /* Allocate and parse configuration for per-BSS files */ for (i = 0; i < num_bss_configs; i++) { struct hostapd_iface *iface; char *fname; wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]); fname = os_strchr(bss_config[i], ':'); if (fname == NULL) { wpa_printf(MSG_ERROR, "Invalid BSS config identifier '%s'", bss_config[i]); goto out; } *fname++ = '\0'; iface = hostapd_interface_init_bss(&interfaces, bss_config[i], fname, debug); if (iface == NULL) goto out; for (j = 0; j < interfaces.count; j++) { if (interfaces.iface[j] == iface) break; } if (j == interfaces.count) { struct hostapd_iface **tmp; tmp = os_realloc_array(interfaces.iface, interfaces.count + 1, sizeof(struct hostapd_iface *)); if (tmp == NULL) { hostapd_interface_deinit_free(iface); goto out; } interfaces.iface = tmp; interfaces.iface[interfaces.count++] = iface; } } /* * Enable configured interfaces. Depending on channel configuration, * this may complete full initialization before returning or use a * callback mechanism to complete setup in case of operations like HT * co-ex scans, ACS, or DFS are needed to determine channel parameters. * In such case, the interface will be enabled from eloop context within * hostapd_global_run(). */ interfaces.terminate_on_error = interfaces.count; for (i = 0; i < interfaces.count; i++) { if (hostapd_driver_init(interfaces.iface[i]) || hostapd_setup_interface(interfaces.iface[i])) goto out; } hostapd_global_ctrl_iface_init(&interfaces); if (hostapd_global_run(&interfaces, daemonize, pid_file)) { wpa_printf(MSG_ERROR, "Failed to start eloop"); goto out; } ret = 0; out: hostapd_global_ctrl_iface_deinit(&interfaces); /* Deinitialize all interfaces */ for (i = 0; i < interfaces.count; i++) { if (!interfaces.iface[i]) continue; interfaces.iface[i]->driver_ap_teardown = !!(interfaces.iface[i]->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); hostapd_interface_deinit_free(interfaces.iface[i]); } os_free(interfaces.iface); hostapd_global_deinit(pid_file); os_free(pid_file); if (log_file) wpa_debug_close_file(); wpa_debug_close_linux_tracing(); os_free(bss_config); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { struct wpa_supplicant wpa_s; int ret = 1; u8 bssid[ETH_ALEN]; struct preauth_test_data preauth_test; if (os_program_init()) return -1; os_memset(&preauth_test, 0, sizeof(preauth_test)); wpa_debug_level = 0; wpa_debug_show_keys = 1; if (argc != 4) { printf("usage: preauth_test <conf> <target MAC address> " "<ifname>\n"); return -1; } if (hwaddr_aton(argv[2], bssid)) { printf("Failed to parse target address '%s'.\n", argv[2]); return -1; } if (eap_register_methods()) { wpa_printf(MSG_ERROR, "Failed to register EAP methods"); return -1; } #ifdef WAPI if (eloop_init(&wpa_s)) { #else if (eloop_init()) { #endif wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } os_memset(&wpa_s, 0, sizeof(wpa_s)); wpa_s.conf = wpa_config_read(argv[1]); if (wpa_s.conf == NULL) { printf("Failed to parse configuration file '%s'.\n", argv[1]); return -1; } if (wpa_s.conf->ssid == NULL) { printf("No networks defined.\n"); return -1; } wpa_init_conf(&wpa_s, argv[3]); wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s); if (wpa_s.ctrl_iface == NULL) { printf("Failed to initialize control interface '%s'.\n" "You may have another preauth_test process already " "running or the file was\n" "left by an unclean termination of preauth_test in " "which case you will need\n" "to manually remove this file before starting " "preauth_test again.\n", wpa_s.conf->ctrl_interface); return -1; } if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid)) return -1; if (rsn_preauth_init(wpa_s.wpa, bssid, &wpa_s.conf->ssid->eap)) return -1; eloop_register_timeout(30, 0, eapol_test_timeout, &preauth_test, NULL); eloop_register_timeout(0, 100000, eapol_test_poll, &wpa_s, NULL); eloop_register_signal_terminate(eapol_test_terminate, &wpa_s); eloop_register_signal_reconfig(eapol_test_terminate, &wpa_s); eloop_run(); if (preauth_test.auth_timed_out) ret = -2; else { ret = pmksa_cache_set_current(wpa_s.wpa, NULL, bssid, NULL, 0) ? 0 : -3; } test_eapol_clean(&wpa_s); eap_peer_unregister_methods(); eloop_destroy(); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { int c; #if 0 /* WAS */ struct wpa_interface *ifaces, *iface; int iface_count; #endif /* WAS */ int exitcode = 1; struct wpa_params params; struct wpa_global *global; #ifdef MODIFIED_BY_SONY #ifndef CONFIG_NATIVE_WINDOWS setvbuf(stdout, 0, _IOLBF, 0); setvbuf(stderr, 0, _IOLBF, 0); #else /* CONFIG_NATIVE_WINDOWS */ setbuf(stdout, 0); setbuf(stderr, 0); #endif /* CONFIG_NATIVE_WINDOWS */ #endif /* MODIFIED_BY_SONY */ if (os_program_init()) return 1; os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_INFO; #if 0 /* WAS */ iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); if (ifaces == NULL) return 1; iface_count = 1; #endif /* WAS */ wpa_supplicant_fd_workaround(); for (;;) { #ifndef WPS_OPT_NFC #if 0 /* WAS */ c = getopt(argc, argv, "b:Bc:C:D:dg:hi:KLNp:P:qtuvwW"); #else c = getopt(argc, argv, "BC:dg:hKLp:P:qtuvwW"); #endif #else /* WPS_OPT_NFC */ #if 0 /* WAS */ c = getopt(argc, argv, "b:Bc:C:D:dg:hi:KLn:Np:P:qtuvwW"); #else c = getopt(argc, argv, "BC:dg:hKLn:p:P:qtuvwW"); #endif #endif /* WPS_OPT_NFC */ if (c < 0) break; switch (c) { #if 0 /* WAS */ case 'b': iface->bridge_ifname = optarg; break; #endif /* WAS */ case 'B': params.daemonize++; break; #if 0 /* WAS */ case 'c': iface->confname = optarg; break; #endif /* WAS */ #if 0 /* WAS */ case 'C': iface->ctrl_interface = optarg; break; #endif /* WAS */ #if 0 /* WAS */ case 'D': iface->driver = optarg; break; #endif /* WAS */ case 'd': #ifdef CONFIG_NO_STDOUT_DEBUG printf("Debugging disabled with " "CONFIG_NO_STDOUT_DEBUG=y build time " "option.\n"); goto out; #else /* CONFIG_NO_STDOUT_DEBUG */ params.wpa_debug_level--; break; #endif /* CONFIG_NO_STDOUT_DEBUG */ case 'g': params.ctrl_interface = optarg; break; case 'h': usage(); exitcode = 0; goto out; #if 0 /* WAS */ case 'i': iface->ifname = optarg; break; #endif /* WAS */ case 'K': params.wpa_debug_show_keys++; break; case 'L': license(); exitcode = 0; goto out; #if 0 /* WAS */ case 'p': iface->driver_param = optarg; break; #endif /* WAS */ case 'P': os_free(params.pid_file); params.pid_file = os_rel2abs_path(optarg); break; case 'q': params.wpa_debug_level++; break; case 't': params.wpa_debug_timestamp++; break; #ifdef CONFIG_CTRL_IFACE_DBUS case 'u': params.dbus_ctrl_interface = 1; break; #endif /* CONFIG_CTRL_IFACE_DBUS */ case 'v': printf("%s\n", wpa_supplicant_version); #ifdef MODIFIED_BY_SONY printf("%s\n", modified_by_sony_version); #endif /* MODIFIED_BY_SONY */ exitcode = 0; goto out; case 'w': params.wait_for_interface++; break; case 'W': params.wait_for_monitor++; break; #ifdef WPS_OPT_NFC case 'n': iface->nfcname = optarg; break; #endif /* WPS_OPT_NFC */ #if 0 /* WAS */ case 'N': iface_count++; iface = os_realloc(ifaces, iface_count * sizeof(struct wpa_interface)); if (iface == NULL) goto out; ifaces = iface; iface = &ifaces[iface_count - 1]; os_memset(iface, 0, sizeof(*iface)); break; #endif /* WAS */ default: usage(); exitcode = 0; goto out; } } exitcode = 0; global = wpa_supplicant_init(¶ms); if (global == NULL) { printf("Failed to initialize wpa_supplicant\n"); exitcode = 1; goto out; } #if 0 /* WAS */ for (i = 0; exitcode == 0 && i < iface_count; i++) { if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { if (iface_count == 1 && (params.ctrl_interface || params.dbus_ctrl_interface)) break; usage(); exitcode = 1; break; } if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) exitcode = 1; } #endif /* WAS */ /* One or more topology files may be specified * (one should be enough, but...) */ if (argv[optind] == NULL) { printf("Need topology file as argument, or use -h for help\n"); exitcode = 1; goto out; } if (wpa_supplicant_config_read_topology_files(global, argv+optind)) { exitcode = 1; } if (exitcode == 0) exitcode = wpa_supplicant_run(global); wpa_supplicant_deinit(global); out: #if 0 /* WAS */ os_free(ifaces); #endif /* WAS */ os_free(params.pid_file); os_program_deinit(); return (exitcode != 0); }
int main(int argc, char *argv[]) { int c, i; int ret = -1; char *pid_file = NULL; int daemonize = 0; char *ctrl_dir = "/var/run/wpa_priv"; struct wpa_priv_interface *interfaces = NULL, *iface; if (os_program_init()) return -1; wpa_priv_fd_workaround(); for (;;) { c = getopt(argc, argv, "Bc:dP:"); if (c < 0) break; switch (c) { case 'B': daemonize++; break; case 'c': ctrl_dir = optarg; break; case 'd': wpa_debug_level--; break; case 'P': pid_file = os_rel2abs_path(optarg); break; default: usage(); goto out; } } if (optind >= argc) { usage(); goto out; } wpa_printf(MSG_DEBUG, "wpa_priv control directory: '%s'", ctrl_dir); if (eloop_init(NULL)) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); goto out; } for (i = optind; i < argc; i++) { wpa_printf(MSG_DEBUG, "Adding driver:interface %s", argv[i]); iface = wpa_priv_interface_init(ctrl_dir, argv[i]); if (iface == NULL) goto out; iface->next = interfaces; interfaces = iface; } if (daemonize && os_daemonize(pid_file)) goto out; eloop_register_signal_terminate(wpa_priv_terminate, NULL); eloop_run(); ret = 0; out: iface = interfaces; while (iface) { struct wpa_priv_interface *prev = iface; iface = iface->next; wpa_priv_interface_deinit(prev); } eloop_destroy(); os_daemonize_terminate(pid_file); os_free(pid_file); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { struct wpa_supplicant wpa_s; int c, ret = 1, wait_for_monitor = 0, save_config = 0; char *as_addr = "127.0.0.1"; int as_port = 1812; char *as_secret = "radius"; char *cli_addr = NULL; char *conf = NULL; int timeout = 30; char *pos; struct extra_radius_attr *p = NULL, *p1; if (os_program_init()) return -1; hostapd_logger_register_cb(hostapd_logger_cb); os_memset(&eapol_test, 0, sizeof(eapol_test)); eapol_test.connect_info = "CONNECT 11Mbps 802.11b"; os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN); wpa_debug_level = 0; wpa_debug_show_keys = 1; for (;;) { c = getopt(argc, argv, "a:A:c:C:M:nN:o:p:r:s:St:W"); if (c < 0) break; switch (c) { case 'a': as_addr = optarg; break; case 'A': cli_addr = optarg; break; case 'c': conf = optarg; break; case 'C': eapol_test.connect_info = optarg; break; case 'M': if (hwaddr_aton(optarg, eapol_test.own_addr)) { usage(); return -1; } break; case 'n': eapol_test.no_mppe_keys++; break; case 'o': if (eapol_test.server_cert_file) fclose(eapol_test.server_cert_file); eapol_test.server_cert_file = fopen(optarg, "w"); if (eapol_test.server_cert_file == NULL) { printf("Could not open '%s' for writing\n", optarg); return -1; } break; case 'p': as_port = atoi(optarg); break; case 'r': eapol_test.eapol_test_num_reauths = atoi(optarg); break; case 's': as_secret = optarg; break; case 'S': save_config++; break; case 't': timeout = atoi(optarg); break; case 'W': wait_for_monitor++; break; case 'N': p1 = os_zalloc(sizeof(p1)); if (p1 == NULL) break; if (!p) eapol_test.extra_attrs = p1; else p->next = p1; p = p1; p->type = atoi(optarg); pos = os_strchr(optarg, ':'); if (pos == NULL) { p->syntax = 'n'; p->data = NULL; break; } pos++; if (pos[0] == '\0' || pos[1] != ':') { printf("Incorrect format of attribute " "specification\n"); break; } p->syntax = pos[0]; p->data = pos + 2; break; default: usage(); return -1; } } if (argc > optind && os_strcmp(argv[optind], "scard") == 0) { return scard_test(); } if (argc > optind && os_strcmp(argv[optind], "sim") == 0) { return scard_get_triplets(argc - optind - 1, &argv[optind + 1]); } if (conf == NULL) { usage(); printf("Configuration file is required.\n"); return -1; } if (eap_register_methods()) { wpa_printf(MSG_ERROR, "Failed to register EAP methods"); return -1; } if (eloop_init()) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } os_memset(&wpa_s, 0, sizeof(wpa_s)); eapol_test.wpa_s = &wpa_s; wpa_s.conf = wpa_config_read(conf); if (wpa_s.conf == NULL) { printf("Failed to parse configuration file '%s'.\n", conf); return -1; } if (wpa_s.conf->ssid == NULL) { printf("No networks defined.\n"); return -1; } wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret, cli_addr); wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s); if (wpa_s.ctrl_iface == NULL) { printf("Failed to initialize control interface '%s'.\n" "You may have another eapol_test process already " "running or the file was\n" "left by an unclean termination of eapol_test in " "which case you will need\n" "to manually remove this file before starting " "eapol_test again.\n", wpa_s.conf->ctrl_interface); return -1; } if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid)) return -1; if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid)) return -1; if (wait_for_monitor) wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface); eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test, NULL); eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL); eloop_register_signal_terminate(eapol_test_terminate, &wpa_s); eloop_register_signal_reconfig(eapol_test_terminate, &wpa_s); eloop_run(); eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL); eloop_cancel_timeout(eapol_sm_reauth, &eapol_test, NULL); if (eapol_test_compare_pmk(&eapol_test) == 0 || eapol_test.no_mppe_keys) ret = 0; if (eapol_test.auth_timed_out) ret = -2; if (eapol_test.radius_access_reject_received) ret = -3; if (save_config) wpa_config_write(conf, wpa_s.conf); test_eapol_clean(&eapol_test, &wpa_s); eap_peer_unregister_methods(); #ifdef CONFIG_AP eap_server_unregister_methods(); #endif /* CONFIG_AP */ eloop_destroy(); if (eapol_test.server_cert_file) fclose(eapol_test.server_cert_file); printf("MPPE keys OK: %d mismatch: %d\n", eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch); if (eapol_test.num_mppe_mismatch) ret = -4; if (ret) printf("FAILURE\n"); else printf("SUCCESS\n"); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; int ret = 1; size_t i; int c, debug = 0, daemonize = 0; char *pid_file = NULL; const char *log_file = NULL; const char *entropy_file = NULL; if (os_program_init()) return -1; os_memset(&interfaces, 0, sizeof(interfaces)); interfaces.reload_config = hostapd_reload_config; interfaces.config_read_cb = hostapd_config_read; interfaces.for_each_interface = hostapd_for_each_interface; interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; interfaces.driver_init = hostapd_driver_init; interfaces.global_iface_path = NULL; interfaces.global_iface_name = NULL; interfaces.global_ctrl_sock = -1; wpa_supplicant_event = hostapd_wpa_event; for (;;) { c = getopt(argc, argv, "Bde:f:hKP:tg:v::"); if (c < 0) break; switch (c) { case 'h': usage(); break; case 'd': debug++; if (wpa_debug_level > 0) wpa_debug_level--; break; case 'B': daemonize++; break; case 'e': entropy_file = optarg; break; case 'f': log_file = optarg; break; case 'K': wpa_debug_show_keys++; break; case 'P': os_free(pid_file); pid_file = os_rel2abs_path(optarg); break; case 't': wpa_debug_timestamp++; break; case 'v': if (optarg) exit(!has_feature(optarg)); show_version(); exit(1); break; case 'g': hostapd_get_global_ctrl_iface(&interfaces, optarg); break; default: usage(); break; } } if (optind == argc && interfaces.global_iface_path == NULL) usage(); wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); if (log_file) wpa_debug_open_file(log_file); interfaces.count = argc - optind; if (interfaces.count) { interfaces.iface = os_calloc(interfaces.count, sizeof(struct hostapd_iface *)); if (interfaces.iface == NULL) { wpa_printf(MSG_ERROR, "malloc failed"); return -1; } } if (hostapd_global_init(&interfaces, entropy_file)) return -1; /* Initialize interfaces */ for (i = 0; i < interfaces.count; i++) { interfaces.iface[i] = hostapd_interface_init(&interfaces, argv[optind + i], debug); if (!interfaces.iface[i]) goto out; } hostapd_global_ctrl_iface_init(&interfaces); if (hostapd_global_run(&interfaces, daemonize, pid_file)) goto out; ret = 0; out: hostapd_global_ctrl_iface_deinit(&interfaces); /* Deinitialize all interfaces */ for (i = 0; i < interfaces.count; i++) hostapd_interface_deinit_free(interfaces.iface[i]); os_free(interfaces.iface); hostapd_global_deinit(pid_file); os_free(pid_file); if (log_file) wpa_debug_close_file(); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { struct wpa_supplicant wpa_s; int c, ret = 1, wait_for_monitor = 0, save_config = 0; char *as_addr = "127.0.0.1"; int as_port = 1812; char *as_secret = "radius"; char *conf = NULL; int timeout = 30; if (os_program_init()) return -1; os_memset(&eapol_test, 0, sizeof(eapol_test)); eapol_test.connect_info = "CONNECT 11Mbps 802.11b"; os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN); wpa_debug_level = 0; wpa_debug_show_keys = 1; for (;;) { c = getopt(argc, argv, "a:c:C:M:np:r:s:St:W"); if (c < 0) break; switch (c) { case 'a': as_addr = optarg; break; case 'c': conf = optarg; break; case 'C': eapol_test.connect_info = optarg; break; case 'M': if (hwaddr_aton(optarg, eapol_test.own_addr)) { usage(); return -1; } break; case 'n': eapol_test.no_mppe_keys++; break; case 'p': as_port = atoi(optarg); break; case 'r': eapol_test.eapol_test_num_reauths = atoi(optarg); break; case 's': as_secret = optarg; break; case 'S': save_config++; break; case 't': timeout = atoi(optarg); break; case 'W': wait_for_monitor++; break; default: usage(); return -1; } } if (argc > optind && os_strcmp(argv[optind], "scard") == 0) { return scard_test(); } if (argc > optind && os_strcmp(argv[optind], "sim") == 0) { return scard_get_triplets(argc - optind - 1, &argv[optind + 1]); } if (conf == NULL) { usage(); printf("Configuration file is required.\n"); return -1; } if (eap_peer_register_methods()) { wpa_printf(MSG_ERROR, "Failed to register EAP methods"); return -1; } if (eloop_init(&wpa_s)) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } os_memset(&wpa_s, 0, sizeof(wpa_s)); eapol_test.wpa_s = &wpa_s; wpa_s.conf = wpa_config_read(conf); if (wpa_s.conf == NULL) { printf("Failed to parse configuration file '%s'.\n", conf); return -1; } if (wpa_s.conf->ssid == NULL) { printf("No networks defined.\n"); return -1; } wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret); wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s); if (wpa_s.ctrl_iface == NULL) { printf("Failed to initialize control interface '%s'.\n" "You may have another eapol_test process already " "running or the file was\n" "left by an unclean termination of eapol_test in " "which case you will need\n" "to manually remove this file before starting " "eapol_test again.\n", wpa_s.conf->ctrl_interface); return -1; } if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid)) return -1; if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid)) return -1; if (wait_for_monitor) wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface); eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test, NULL); eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL); eloop_register_signal_terminate(eapol_test_terminate, NULL); eloop_register_signal_reconfig(eapol_test_terminate, NULL); eloop_run(); if (eapol_test_compare_pmk(&eapol_test) == 0 || eapol_test.no_mppe_keys) ret = 0; if (eapol_test.auth_timed_out) ret = -2; if (eapol_test.radius_access_reject_received) ret = -3; if (save_config) wpa_config_write(conf, wpa_s.conf); test_eapol_clean(&eapol_test, &wpa_s); eap_peer_unregister_methods(); eloop_destroy(); printf("MPPE keys OK: %d mismatch: %d\n", eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch); if (eapol_test.num_mppe_mismatch) ret = -4; if (ret) printf("FAILURE\n"); else printf("SUCCESS\n"); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { int c, i; struct wpa_interface *ifaces, *iface; int iface_count, exitcode = -1; struct wpa_params params; struct wpa_global *global; char supp_dbg[PROPERTY_VALUE_MAX] = {'\0'}; //CONN-FY-WIFI-PortingSupplicantDebugTool if (os_program_init()) return -1; os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_INFO; iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); if (ifaces == NULL) return -1; iface_count = 1; wpa_supplicant_fd_workaround(1); for (;;) { c = getopt(argc, argv, "b:Bc:C:D:de:f:g:G:hi:I:KLm:No:O:p:P:qsS:TtuvW"); if (c < 0) break; switch (c) { case 'b': iface->bridge_ifname = optarg; break; case 'B': params.daemonize++; break; case 'c': iface->confname = optarg; break; case 'C': iface->ctrl_interface = optarg; break; case 'D': iface->driver = optarg; break; case 'd': #ifdef CONFIG_NO_STDOUT_DEBUG printf("Debugging disabled with " "CONFIG_NO_STDOUT_DEBUG=y build time " "option.\n"); goto out; #else /* CONFIG_NO_STDOUT_DEBUG */ params.wpa_debug_level--; break; #endif /* CONFIG_NO_STDOUT_DEBUG */ case 'e': params.entropy_file = optarg; break; #ifdef CONFIG_DEBUG_FILE case 'f': params.wpa_debug_file_path = optarg; break; #endif /* CONFIG_DEBUG_FILE */ case 'g': params.ctrl_interface = optarg; break; case 'G': params.ctrl_interface_group = optarg; break; case 'h': usage(); exitcode = 0; goto out; case 'i': iface->ifname = optarg; break; case 'I': iface->confanother = optarg; break; case 'K': params.wpa_debug_show_keys++; break; case 'L': license(); exitcode = 0; goto out; #ifdef CONFIG_P2P case 'm': iface->conf_p2p_dev = optarg; break; #endif /* CONFIG_P2P */ case 'o': params.override_driver = optarg; break; case 'O': params.override_ctrl_interface = optarg; break; case 'p': iface->driver_param = optarg; break; case 'P': os_free(params.pid_file); params.pid_file = os_rel2abs_path(optarg); break; case 'q': params.wpa_debug_level++; break; #ifdef CONFIG_DEBUG_SYSLOG case 's': params.wpa_debug_syslog++; break; #endif /* CONFIG_DEBUG_SYSLOG */ case 'S': params.first_scan_delay_msec = atoi(optarg); break; #ifdef CONFIG_DEBUG_LINUX_TRACING case 'T': params.wpa_debug_tracing++; break; #endif /* CONFIG_DEBUG_LINUX_TRACING */ case 't': params.wpa_debug_timestamp++; break; #ifdef CONFIG_DBUS case 'u': params.dbus_ctrl_interface = 1; break; #endif /* CONFIG_DBUS */ case 'v': printf("%s\n", wpa_supplicant_version); exitcode = 0; goto out; case 'W': params.wait_for_monitor++; break; case 'N': iface_count++; iface = os_realloc_array(ifaces, iface_count, sizeof(struct wpa_interface)); if (iface == NULL) goto out; ifaces = iface; iface = &ifaces[iface_count - 1]; os_memset(iface, 0, sizeof(*iface)); break; default: usage(); exitcode = 0; goto out; } } //CONN-FY-WIFI-PortingSupplicantDebugTool++ property_get("persist.supp.dbg", supp_dbg, "false"); if (strcmp(supp_dbg, "true") == 0) { params.wpa_debug_level = MSG_EXCESSIVE; wpa_printf(MSG_INFO, "persist.supp.dbg true debug level MSG_EXCESSIVE"); } else { params.wpa_debug_level = MSG_INFO; wpa_printf(MSG_INFO, "persist.supp.dbg false debug level MSG_INFO"); } //CONN-FY-WIFI-PortingSupplicantDebugTool-- exitcode = 0; global = wpa_supplicant_init(¶ms); if (global == NULL) { wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant"); exitcode = -1; goto out; } else { wpa_printf(MSG_INFO, "Successfully initialized " "wpa_supplicant"); } for (i = 0; exitcode == 0 && i < iface_count; i++) { struct wpa_supplicant *wpa_s; if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { if (iface_count == 1 && (params.ctrl_interface || params.dbus_ctrl_interface)) break; usage(); exitcode = -1; break; } wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]); if (wpa_s == NULL) { exitcode = -1; break; } #ifdef CONFIG_P2P if (wpa_s->global->p2p == NULL && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && wpas_p2p_add_p2pdev_interface(wpa_s) < 0) exitcode = -1; #endif /* CONFIG_P2P */ } if (exitcode == 0) exitcode = wpa_supplicant_run(global); wpa_supplicant_deinit(global); out: wpa_supplicant_fd_workaround(0); os_free(ifaces); os_free(params.pid_file); os_program_deinit(); return exitcode; }
int main(int argc, char *argv[]) { int c, i; struct wpa_interface *ifaces, *iface; int iface_count, exitcode = -1; struct wpa_params params; struct wpa_global *global; if (os_program_init()) return -1; os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_INFO; iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); if (ifaces == NULL) return -1; iface_count = 1; wpa_supplicant_fd_workaround(1); for (;;) { c = getopt(argc, argv, "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuvW"); if (c < 0) break; switch (c) { case 'b': iface->bridge_ifname = optarg; break; case 'B': params.daemonize++; break; case 'c': iface->confname = optarg; break; case 'C': iface->ctrl_interface = optarg; break; case 'D': iface->driver = optarg; break; case 'd': #ifdef CONFIG_NO_STDOUT_DEBUG printf("Debugging disabled with " "CONFIG_NO_STDOUT_DEBUG=y build time " "option.\n"); goto out; #else /* CONFIG_NO_STDOUT_DEBUG */ params.wpa_debug_level--; break; #endif /* CONFIG_NO_STDOUT_DEBUG */ case 'e': params.entropy_file = optarg; break; #ifdef CONFIG_DEBUG_FILE case 'f': params.wpa_debug_file_path = optarg; break; #endif /* CONFIG_DEBUG_FILE */ case 'g': params.ctrl_interface = optarg; break; case 'G': params.ctrl_interface_group = optarg; break; case 'h': usage(); exitcode = 0; goto out; case 'i': iface->ifname = optarg; break; case 'I': iface->confanother = optarg; break; case 'K': params.wpa_debug_show_keys++; break; case 'L': license(); exitcode = 0; goto out; #ifdef CONFIG_P2P case 'm': params.conf_p2p_dev = optarg; break; #endif /* CONFIG_P2P */ case 'o': params.override_driver = optarg; break; case 'O': params.override_ctrl_interface = optarg; break; case 'p': iface->driver_param = optarg; break; case 'P': os_free(params.pid_file); params.pid_file = os_rel2abs_path(optarg); break; case 'q': params.wpa_debug_level++; break; #ifdef CONFIG_DEBUG_SYSLOG case 's': params.wpa_debug_syslog++; break; #endif /* CONFIG_DEBUG_SYSLOG */ #ifdef CONFIG_DEBUG_LINUX_TRACING case 'T': params.wpa_debug_tracing++; break; #endif /* CONFIG_DEBUG_LINUX_TRACING */ case 't': params.wpa_debug_timestamp++; break; #ifdef CONFIG_CTRL_IFACE_DBUS_NEW case 'u': params.dbus_ctrl_interface = 1; break; #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */ case 'v': printf("%s\n", wpa_supplicant_version); exitcode = 0; goto out; case 'W': params.wait_for_monitor++; break; #ifdef CONFIG_MATCH_IFACE case 'M': params.match_iface_count++; iface = os_realloc_array(params.match_ifaces, params.match_iface_count, sizeof(struct wpa_interface)); if (!iface) goto out; params.match_ifaces = iface; iface = ¶ms.match_ifaces[params.match_iface_count - 1]; os_memset(iface, 0, sizeof(*iface)); break; #endif /* CONFIG_MATCH_IFACE */ case 'N': iface_count++; iface = os_realloc_array(ifaces, iface_count, sizeof(struct wpa_interface)); if (iface == NULL) goto out; ifaces = iface; iface = &ifaces[iface_count - 1]; os_memset(iface, 0, sizeof(*iface)); break; default: usage(); exitcode = 0; goto out; } } exitcode = 0; global = wpa_supplicant_init(¶ms); if (global == NULL) { wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant"); exitcode = -1; goto out; } else { wpa_printf(MSG_INFO, "Successfully initialized " "wpa_supplicant"); } if (fst_global_init()) { wpa_printf(MSG_ERROR, "Failed to initialize FST"); exitcode = -1; goto out; } #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE) if (!fst_global_add_ctrl(fst_ctrl_cli)) wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl"); #endif for (i = 0; exitcode == 0 && i < iface_count; i++) { struct wpa_supplicant *wpa_s; if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { if (iface_count == 1 && (params.ctrl_interface || #ifdef CONFIG_MATCH_IFACE params.match_iface_count || #endif /* CONFIG_MATCH_IFACE */ params.dbus_ctrl_interface)) break; usage(); exitcode = -1; break; } wpa_s = wpa_supplicant_add_iface(global, &ifaces[i], NULL); if (wpa_s == NULL) { exitcode = -1; break; } } #ifdef CONFIG_MATCH_IFACE if (exitcode == 0) exitcode = wpa_supplicant_init_match(global); #endif /* CONFIG_MATCH_IFACE */ if (exitcode == 0) exitcode = wpa_supplicant_run(global); wpa_supplicant_deinit(global); fst_global_deinit(); out: wpa_supplicant_fd_workaround(0); os_free(ifaces); #ifdef CONFIG_MATCH_IFACE os_free(params.match_ifaces); #endif /* CONFIG_MATCH_IFACE */ os_free(params.pid_file); os_program_deinit(); return exitcode; }
int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; int ret = 1; size_t i; int c, debug = 0, daemonize = 0; char *pid_file = NULL; const char *log_file = NULL; if (os_program_init()) return -1; for (;;) { c = getopt(argc, argv, "Bdf:hKP:tv"); if (c < 0) break; switch (c) { case 'h': usage(); break; case 'd': debug++; if (wpa_debug_level > 0) wpa_debug_level--; break; case 'B': daemonize++; break; case 'f': log_file = optarg; break; case 'K': wpa_debug_show_keys++; break; case 'P': os_free(pid_file); pid_file = os_rel2abs_path(optarg); break; case 't': wpa_debug_timestamp++; break; case 'v': show_version(); exit(1); break; default: usage(); break; } } if (optind == argc) usage(); wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); if (log_file) wpa_debug_open_file(log_file); interfaces.count = argc - optind; interfaces.iface = os_malloc(interfaces.count * sizeof(struct hostapd_iface *)); if (interfaces.iface == NULL) { wpa_printf(MSG_ERROR, "malloc failed\n"); return -1; } if (hostapd_global_init(&interfaces)) return -1; /* Initialize interfaces */ for (i = 0; i < interfaces.count; i++) { interfaces.iface[i] = hostapd_interface_init(&interfaces, argv[optind + i], debug); if (!interfaces.iface[i]) goto out; } if (hostapd_global_run(&interfaces, daemonize, pid_file)) goto out; ret = 0; out: /* Deinitialize all interfaces */ for (i = 0; i < interfaces.count; i++) hostapd_interface_deinit_free(interfaces.iface[i]); os_free(interfaces.iface); hostapd_global_deinit(pid_file); os_free(pid_file); if (log_file) wpa_debug_close_file(); os_program_deinit(); return ret; }
int main(int argc, char *argv[]) { int c; const char *read_file = NULL; const char *read_wired_file = NULL; const char *write_file = NULL; const char *ifname = NULL; const char *ifname_wired = NULL; struct wlantest wt; int ctrl_iface = 0; wpa_debug_level = MSG_INFO; wpa_debug_show_keys = 1; if (os_program_init()) return -1; wlantest_init(&wt); for (;;) { c = getopt(argc, argv, "cdf:hi:I:p:P:qr:R:w:W:"); if (c < 0) break; switch (c) { case 'c': ctrl_iface = 1; break; case 'd': if (wpa_debug_level > 0) wpa_debug_level--; break; case 'f': if (add_pmk_file(&wt, optarg) < 0) return -1; break; case 'h': usage(); return 0; case 'i': ifname = optarg; break; case 'I': ifname_wired = optarg; break; case 'p': add_passphrase(&wt, optarg); break; case 'P': add_secret(&wt, optarg); break; case 'q': wpa_debug_level++; break; case 'r': read_file = optarg; break; case 'R': read_wired_file = optarg; break; case 'w': write_file = optarg; break; case 'W': if (add_wep(&wt, optarg) < 0) return -1; break; default: usage(); return -1; } } if (ifname == NULL && ifname_wired == NULL && read_file == NULL && read_wired_file == NULL) { usage(); return 0; } if (eloop_init()) return -1; if (write_file && write_pcap_init(&wt, write_file) < 0) return -1; if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0) return -1; if (read_file && read_cap_file(&wt, read_file) < 0) return -1; if (ifname && monitor_init(&wt, ifname) < 0) return -1; if (ifname_wired && monitor_init_wired(&wt, ifname_wired) < 0) return -1; if (ctrl_iface && ctrl_init(&wt) < 0) return -1; eloop_register_signal_terminate(wlantest_terminate, &wt); eloop_run(); wpa_printf(MSG_INFO, "Processed: rx_mgmt=%u rx_ctrl=%u rx_data=%u " "fcs_error=%u", wt.rx_mgmt, wt.rx_ctrl, wt.rx_data, wt.fcs_error); wlantest_deinit(&wt); eloop_destroy(); os_program_deinit(); return 0; }
static int wpa_supplicant_thread(void) { int exitcode; struct wpa_params params; struct wpa_global *global; HKEY hk, ihk; DWORD val, buflen, i; LONG ret; if (os_program_init()) return -1; os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_INFO; ret = RegOpenKeyEx(WPA_KEY_ROOT, WPA_KEY_PREFIX, 0, KEY_QUERY_VALUE, &hk); if (ret != ERROR_SUCCESS) { printf("Could not open wpa_supplicant registry key\n"); return -1; } buflen = sizeof(val); ret = RegQueryValueEx(hk, TEXT("debug_level"), NULL, NULL, (LPBYTE) &val, &buflen); if (ret == ERROR_SUCCESS && buflen == sizeof(val)) { params.wpa_debug_level = val; } buflen = sizeof(val); ret = RegQueryValueEx(hk, TEXT("debug_show_keys"), NULL, NULL, (LPBYTE) &val, &buflen); if (ret == ERROR_SUCCESS && buflen == sizeof(val)) { params.wpa_debug_show_keys = val; } buflen = sizeof(val); ret = RegQueryValueEx(hk, TEXT("debug_timestamp"), NULL, NULL, (LPBYTE) &val, &buflen); if (ret == ERROR_SUCCESS && buflen == sizeof(val)) { params.wpa_debug_timestamp = val; } buflen = sizeof(val); ret = RegQueryValueEx(hk, TEXT("debug_use_file"), NULL, NULL, (LPBYTE) &val, &buflen); if (ret == ERROR_SUCCESS && buflen == sizeof(val) && val) { params.wpa_debug_file_path = "\\Temp\\wpa_supplicant-log.txt"; } exitcode = 0; global = wpa_supplicant_init(¶ms); if (global == NULL) { printf("Failed to initialize wpa_supplicant\n"); exitcode = -1; } ret = RegOpenKeyEx(hk, TEXT("interfaces"), 0, KEY_ENUMERATE_SUB_KEYS, &ihk); RegCloseKey(hk); if (ret != ERROR_SUCCESS) { printf("Could not open wpa_supplicant interfaces registry " "key\n"); return -1; } for (i = 0; ; i++) { TCHAR name[255]; DWORD namelen; namelen = 255; ret = RegEnumKeyEx(ihk, i, name, &namelen, NULL, NULL, NULL, NULL); if (ret == ERROR_NO_MORE_ITEMS) break; if (ret != ERROR_SUCCESS) { printf("RegEnumKeyEx failed: 0x%x\n", (unsigned int) ret); break; } if (namelen >= 255) namelen = 255 - 1; name[namelen] = '\0'; wpa_printf(MSG_DEBUG, "interface %d: %s\n", (int) i, name); if (read_interface(global, ihk, name) < 0) exitcode = -1; } RegCloseKey(ihk); if (exitcode == 0) exitcode = wpa_supplicant_run(global); wpa_supplicant_deinit(global); os_program_deinit(); return exitcode; }
int main(int argc, char *argv[]) { int c, i; struct wpa_interface *ifaces, *iface; int iface_count, exitcode = -1; struct wpa_params params; struct wpa_global *global; if (os_program_init()) return -1; os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_INFO; iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); if (ifaces == NULL) return -1; iface_count = 1; wpa_supplicant_fd_workaround(); for (;;) { c = getopt(argc, argv, "b:Bc:C:D:dg:hi:KLNp:P:qtuvwW"); if (c < 0) break; switch (c) { case 'b': iface->bridge_ifname = optarg; break; case 'B': params.daemonize++; break; case 'c': iface->confname = optarg; break; case 'C': iface->ctrl_interface = optarg; break; case 'D': iface->driver = optarg; break; case 'd': #ifdef CONFIG_NO_STDOUT_DEBUG printf("Debugging disabled with " "CONFIG_NO_STDOUT_DEBUG=y build time " "option.\n"); goto out; #else /* CONFIG_NO_STDOUT_DEBUG */ params.wpa_debug_level--; break; #endif /* CONFIG_NO_STDOUT_DEBUG */ case 'g': params.ctrl_interface = optarg; break; case 'h': usage(); goto out; case 'i': iface->ifname = optarg; break; case 'K': params.wpa_debug_show_keys++; break; case 'L': license(); goto out; case 'p': iface->driver_param = optarg; break; case 'P': os_free(params.pid_file); params.pid_file = os_rel2abs_path(optarg); break; case 'q': params.wpa_debug_level++; break; case 't': params.wpa_debug_timestamp++; break; #ifdef CONFIG_CTRL_IFACE_DBUS case 'u': params.dbus_ctrl_interface = 1; break; #endif /* CONFIG_CTRL_IFACE_DBUS */ case 'v': printf("%s\n", wpa_supplicant_version); goto out; case 'w': params.wait_for_interface++; break; case 'W': params.wait_for_monitor++; break; case 'N': iface_count++; iface = os_realloc(ifaces, iface_count * sizeof(struct wpa_interface)); if (iface == NULL) goto out; ifaces = iface; iface = &ifaces[iface_count - 1]; os_memset(iface, 0, sizeof(*iface)); break; default: usage(); goto out; } } exitcode = 0; global = wpa_supplicant_init(¶ms); if (global == NULL) { printf("Failed to initialize wpa_supplicant\n"); exitcode = -1; goto out; } for (i = 0; exitcode == 0 && i < iface_count; i++) { if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { if (iface_count == 1 && (params.ctrl_interface || params.dbus_ctrl_interface)) break; usage(); exitcode = -1; break; } if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) exitcode = -1; } if (exitcode == 0) exitcode = wpa_supplicant_run(global); wpa_supplicant_deinit(global); out: os_free(ifaces); os_free(params.pid_file); os_program_deinit(); return exitcode; }
int main(int argc, char *argv[]) { int i, j; int c, res, ret = -1; const char *global_wpa_s_ctrl_intf = NULL; const char *wrapd_ctrl_intf = NULL; const char *vma_conf_file = NULL; const char *wpa_s_conf_file = NULL; const char *add_psta_addr = NULL; const char *remove_psta_addr = NULL; int daemonize = 0; int hostapd_num = 0; int list_psta_addr = 0; int do_mat = 0; int do_isolation = 0; int do_timer = 0; int conn_cnt = 0; int slave_mode = 0; char msg[128] = {0}; if (os_program_init()) return -1; for (i = 0; i < HOSTAPD_CNT; i ++) { ap_ifname[i] = NULL; wrapd_hostapd_conn[i] = NULL; } for (;;) { c = getopt(argc, argv, "g:a:p:w:A:R:BLMSITc:v:d:h"); if (c < 0) break; switch (c) { case 'g': wrapd_ctrl_intf = optarg; break; case 'w': global_wpa_s_ctrl_intf = optarg; break; case 'a': if (hostapd_num >= HOSTAPD_CNT) { usage(); goto out; } ap_ifname[hostapd_num ++] = os_strdup(optarg); break; case 'p': mpsta_ifname = os_strdup(optarg); break; case 'd': dbdc_ifname = os_strdup(optarg); break; case 'B': daemonize++; break; case 'A': add_psta_addr = optarg; break; case 'R': remove_psta_addr = optarg; break; case 'L': list_psta_addr = 1; break; case 'M': do_mat = 1; break; case 'I': do_isolation = 1; break; case 'S': slave_mode = 1; break; case 'T': do_timer = 1; break; case 'c': wpa_s_conf_file = optarg; break; case 'v': vma_conf_file = optarg; break; case 'h': usage(); ret = 0; goto out; default: usage(); goto out; } } for (i = 0; i < hostapd_num - 1; i ++) { for (j = i + 1; j < hostapd_num; j ++) { if (os_strcmp(ap_ifname[i], ap_ifname[j]) == 0) { wrapd_printf("duplicated ap_ifname[%d] of ap_ifname[%d]", i, j); goto out; } } } if(NULL == wrapd_ctrl_intf) wrapd_ctrl_intf = wrapd_ctrl_iface_path; if (slave_mode) { if(add_psta_addr) { if (do_mat) { if (dbdc_ifname) { wrapd_printf("Invalid MAT option, DBDC is enabled"); goto out; } res = os_snprintf(msg, sizeof(msg),"ETH_PSTA_ADD MAT %s %s", ap_ifname[0], add_psta_addr); } else res = os_snprintf(msg, sizeof(msg),"ETH_PSTA_ADD %s %s", ap_ifname[0], add_psta_addr); if (res < 0 || res >= sizeof(msg)){ wrapd_printf("Fail to build ETH_PSTA_ADD msg"); goto out; } wrapd_send_msg(msg, 128, wrapd_ctrl_intf); ret = 0; goto out; } else if (remove_psta_addr) { res = os_snprintf(msg, sizeof(msg),"ETH_PSTA_REMOVE %s", remove_psta_addr); if (res < 0 || res >= sizeof(msg)){ wrapd_printf("Fail to build ETH_PSTA_REMOVE msg"); goto out; } wrapd_send_msg(msg, (16 + 17), wrapd_ctrl_intf); ret = 0; goto out; } else if (list_psta_addr) { wrapd_send_msg("PSTA_LIST", 9, wrapd_ctrl_intf); ret = 0; goto out; } } if(NULL == global_wpa_s_ctrl_intf) global_wpa_s_ctrl_intf = global_wpa_s_ctrl_iface_path; if (eloop_init()) { wrapd_printf("Failed to initialize event loop"); goto out; } wrapd_handle = wrapd_conn_to_global_wpa_s(global_wpa_s_ctrl_intf, wpa_s_conf_file, do_isolation, do_timer); if (wrapd_handle == NULL) goto out; wrapd_conn = wrapd_ctrl_open(wrapd_ctrl_intf, wrapd_handle); for (i = 0; i < HOSTAPD_CNT; i ++) { if(ap_ifname[i]) { for (conn_cnt = 0; conn_cnt < HOSTAPD_CONN_TIMES; conn_cnt ++) { wrapd_hostapd_conn[i] = wrapd_conn_to_hostapd(ap_ifname[i]); if (wrapd_hostapd_conn[i]) { wrapd_printf("WRAP hostapd(%s) connected", ap_ifname[i]); break; } os_sleep(1, 0); } if(wrapd_hostapd_conn[i]) { if (wpa_ctrl_attach((struct wpa_ctrl *)wrapd_hostapd_conn[i]) != 0) { wrapd_printf("Failed to attach to WRAP hostapd(%s)", ap_ifname[i]);; goto out; } wrapd_printf("WRAP hostapd(%s) attached", ap_ifname[i]); eloop_register_read_sock(wrapd_hostapd_conn[i]->sock, wrapd_hostapd_ctrl_iface_receive, wrapd_handle, (void *)ap_ifname[i]); } else { wrapd_printf("WRAP hostapd(%s) not exists", ap_ifname[i]); } } } if(mpsta_ifname == NULL) { wrapd_printf("Failed to connect to MPSTA wpa_s - mpsta_ifname == NULL"); goto out; } for (conn_cnt = 0; conn_cnt < WPA_S_CONN_TIMES; conn_cnt ++) { /* * Delay to ensure scan doesn't overlap with ht40 intol acs scan, else will cause * scan to fail and will take more time for MPSTA to associate. * EV 131644 */ if(conn_cnt == 0) os_sleep(3, 0); wrapd_wpa_s_conn = wrapd_conn_to_mpsta_wpa_s(mpsta_ifname); if (wrapd_wpa_s_conn) { wrapd_printf("MPSTA wpa_s(%s) connected", mpsta_ifname); break; } os_sleep(1, 0); } if(wrapd_wpa_s_conn) { if (wpa_ctrl_attach((struct wpa_ctrl *)wrapd_wpa_s_conn) != 0) { wrapd_printf("Failed to attach to MPSTA wpa_s(%s)", mpsta_ifname); goto out; } wrapd_printf("MPSTA wpa_s(%s) attached", mpsta_ifname); eloop_register_read_sock(wrapd_wpa_s_conn->sock, wrapd_wpa_s_ctrl_iface_receive, wrapd_handle, NULL); } else { wrapd_printf("MPSTA wpa_s(%s) not exists", mpsta_ifname); } if (vma_conf_file) { wrapd_load_vma_list(vma_conf_file, wrapd_handle); } if (daemonize && os_daemonize(NULL)) { wrapd_printf("daemon"); goto out; } eloop_run(); out: for (i = 0; i < HOSTAPD_CNT; i ++) { if (ap_ifname[i]) os_free(ap_ifname[i]); if (wrapd_hostapd_conn[i]) wpa_ctrl_close((struct wpa_ctrl *)wrapd_hostapd_conn[i]); } if (dbdc_ifname) os_free(dbdc_ifname); if (mpsta_ifname) os_free(mpsta_ifname); if (wrapd_wpa_s_conn) wpa_ctrl_close((struct wpa_ctrl *)wrapd_wpa_s_conn); os_program_deinit(); return ret; }