int start_auth(const char *prefix, int wan_up) { char tmp[100]; const char *wan_proto = nvram_safe_get(strcat_r(prefix, "proto", tmp)); const char *wan_auth = nvram_safe_get(strcat_r(prefix, "auth_x", tmp)); int ret = 0; if (strcmp(wan_proto, "static") == 0 || strcmp(wan_proto, "dhcp") == 0) { #ifdef __CONFIG_EAPOL__ if (strcmp(wan_auth, "eap-md5") == 0 && !wan_up) ret = start_wpa_supplicant(prefix, 1); #endif #ifdef __CONFIG_TELENET__ if (strcmp(wan_auth, "telenet") == 0 && wan_up) ret = start_lanauth(prefix, 1); #endif #ifdef __CONFIG_CONVEX__ if (strcmp(wan_auth, "convex") == 0 && wan_up) ret = start_authcli(prefix, 1); #endif } /* TODO: ugly, remake bigpond as auth, not wan proto */ if (strcmp(wan_proto, "bigpond") == 0) { if (wan_up) { stop_bpalogin(); ret = start_bpalogin(); } } return ret; }
int setup_ethernetinterface(struct config_interfaces * cur) { int retries = 1; struct config_ssid *match = cur->ssids; /* * If 8021.1X, run the supplicant stuff the same as wireless. * If not using 8021.1X, just go straight to dhclient. */ printf("%s\n", cur->if_name); if (!connection_active(cur->if_name, 0)) { char command [50]; snprintf(command, sizeof(command), "ifconfig %s up\n", config->if_name); printf("%s\n", command); system(command); printf("try bringing up interface\n"); /* * Check if a password has been set; if yes, we want to use * the supplicant. */ if (match->ssid_pass[0] == '\0') strlcpy(match->ssid_auth, "none", sizeof(match->ssid_auth)); else strlcpy(match->ssid_auth, "802.1x", sizeof(match->ssid_auth)); /* * Remove wireless settings from wireless interface before * trying ethernet. */ cleanup_interface(cur, 1); if (strcmp(cur->ssids->ssid_auth, "802.1x") == 0) { /* Do supplicant stuff. */ if (!cur->supplicant_pid) cur->supplicant_pid = start_wpa_supplicant(cur->if_name, cur->supplicant_pid, 0); sleep(3); config_wpa_supplicant(cur->if_name, match, 1); } if (cur->ipv6_auto) set_ipv6_auto(cur->if_name); start_dhclient(cur->if_name); if (connection_active(cur->if_name, 0)) { /* * If we are successfully connected to the network * and we don't need additional auth, then we are good. */ if (internet_connectivity_check(match) == 1) return 1; /* All is ok, sleep. */ } } else { /* * If we are successfully connected to the network, * then we are good. Otherwise try another connection. */ if (internet_connectivity_check(match) == 1) return 1; /* All is ok, sleep. */ } return 0; }
void check_wpa_sup_died() { int status , pid; for (struct config_interfaces * cur = config; cur; cur = cur->next) { pid = waitpid(cur->supplicant_pid, &status, WNOHANG); if (pid != supplicant_pid) continue; if (!WIFEXITED(status) && !WIFSIGNALED(status)) continue; printf("wpa_supplicant DEADED\n"); start_wpa_supplicant(cur->if_name, 0, !(strcmp(mediatype(cur->if_name), "Ethernet") == 0)); } }
int restart_auth(int unit) { char tmp[100]; char prefix[] = "wanXXXXXXXXXX_"; char *wan_proto, *wan_auth; int ret = -1; snprintf(prefix, sizeof(prefix), "wan%d_", unit); wan_proto = nvram_safe_get(strcat_r(prefix, "proto", tmp)); if (strcmp(wan_proto, "static") != 0 && strcmp(wan_proto, "dhcp") != 0) return -1; wan_auth = nvram_safe_get(strcat_r(prefix, "auth_x", tmp)); #ifdef RTCONFIG_EAPOL if (strcmp(wan_auth, "8021x-md5") == 0) ret = start_wpa_supplicant(unit, 1); #endif _dprintf("%s:: done\n", __func__); return ret; }
int setup_wlaninterface(struct config_interfaces * target) { int retries = 1, res = 0; struct config_ssid *match, *all = all_matching_network(target); char *if_name = target->if_name; match = all; if (!match) return 0; if (network_matches(if_name, match)) { printf("already using matched ssid, we do nothing\n"); clear_ssid(all); return 1; } while (match) { printf("setting up network: %s\n", match->ssid_name); set_network_id((char *) match->ssid_name, if_name); printf("%s\n", match->ssid_auth); update_status(CONNECTING, match->ssid_name); if (strcmp(match->ssid_auth, "802.1x") == 0) { printf("do 8021x stuff\n"); if (!target->supplicant_pid) target->supplicant_pid = start_wpa_supplicant(target->if_name, target->supplicant_pid, 1); cleanup_interface(target, 8); set_bssid((char *) match->ssid_bssid, if_name, 1); set_wpa8021x(if_name, 1); sleep(3); config_wpa_supplicant(if_name, match, 1); } else if (strcmp(match->ssid_auth, "wpa") == 0) { printf("do wpa stuff\n"); cleanup_interface(target, 4); set_psk_key((char *) match->ssid_name, (char *) match->ssid_pass, if_name, 1); } else if (strcmp(match->ssid_auth, "wep") == 0) { printf("do wep stuff\n"); cleanup_interface(target, 2); set_wep_key((char *) match->ssid_pass, if_name, 1); } else if (strcmp(match->ssid_auth, "none") == 0) { printf("no security has been set\n"); cleanup_interface(target, 1); } if (target->ipv6_auto) set_ipv6_auto(if_name); start_dhclient(if_name); while (retries != 0) { if (connection_active(if_name, 1)) { /* * If we are successfully connected to the network * and we don't need additional auth, then we are good. */ sleep(1); res = internet_connectivity_check(match); if (res == 1) { update_status(CONNECTED, match->ssid_name); return 1; } else if (res == 2) { /* * This is a hotspot; run user-defined command * or open default web browser. */ if (!config->additional_auth_exec) hotspot(match); return 1; } else { printf("not active, waiting...\n"); sleep(5); retries--; } } } match = match->next; retries = 1; } clear_ssid(all); return res; }