|
@@ -93,13 +93,25 @@ static void res_free(result_t *res)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+static int udhcpc_start(int on)
|
|
|
|
|
+{
|
|
|
|
|
+ char tmp[200],path[100];
|
|
|
|
|
+
|
|
|
|
|
+ sprintf(path, "/var/run/udhcpc_%s.pid", WLAN_IFNAME);
|
|
|
|
|
+ if(on) {
|
|
|
|
|
+ sprintf(tmp, "udhcpc -R -b -t 1 -A 1 -i %s -p %s", WLAN_IFNAME, path);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ sprintf(tmp, "kill $(cat %s)", path);
|
|
|
|
|
+ }
|
|
|
|
|
+ return system(tmp);
|
|
|
|
|
+}
|
|
|
static int sta_start(ap_info_t *info, int on)
|
|
static int sta_start(ap_info_t *info, int on)
|
|
|
{
|
|
{
|
|
|
int r,ipv,mask=24;
|
|
int r,ipv,mask=24;
|
|
|
char tmp[400],txt[200];
|
|
char tmp[400],txt[200];
|
|
|
|
|
|
|
|
//https://www.cnblogs.com/lidabo/p/5076560.html
|
|
//https://www.cnblogs.com/lidabo/p/5076560.html
|
|
|
- r = system("killall wpa_supplicant");
|
|
|
|
|
if(on) {
|
|
if(on) {
|
|
|
snprintf(txt, sizeof(txt), "ctrl_interface=/var/run/wpa_supplicant\n"
|
|
snprintf(txt, sizeof(txt), "ctrl_interface=/var/run/wpa_supplicant\n"
|
|
|
"network={\n"
|
|
"network={\n"
|
|
@@ -110,15 +122,17 @@ static int sta_start(ap_info_t *info, int on)
|
|
|
sprintf(tmp, "echo '%s' > %s", txt, STA_CONF);
|
|
sprintf(tmp, "echo '%s' > %s", txt, STA_CONF);
|
|
|
r = system(tmp);
|
|
r = system(tmp);
|
|
|
|
|
|
|
|
|
|
+ r = system("killall wpa_supplicant");
|
|
|
|
|
+
|
|
|
sprintf(tmp, "wpa_supplicant -B -i %s -c %s", WLAN_IFNAME, STA_CONF);
|
|
sprintf(tmp, "wpa_supplicant -B -i %s -c %s", WLAN_IFNAME, STA_CONF);
|
|
|
r = system(tmp);
|
|
r = system(tmp);
|
|
|
|
|
|
|
|
- sprintf(tmp, "udhcpc -R -b -i %s", WLAN_IFNAME);
|
|
|
|
|
- r = system(tmp);
|
|
|
|
|
|
|
+ r = udhcpc_start(1);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
r = system("wpa_cli disconnect");
|
|
r = system("wpa_cli disconnect");
|
|
|
- r = system("killall wpa_supplicant udhcpc");
|
|
|
|
|
|
|
+ r = system("killall wpa_supplicant");
|
|
|
|
|
+ r = udhcpc_start(0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
return r;
|