guohui 1 год назад
Родитель
Сommit
04ade39b72
1 измененных файлов с 18 добавлено и 4 удалено
  1. 18 4
      pro/src/wifi.c

+ 18 - 4
pro/src/wifi.c

@@ -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)
 {
     int r,ipv,mask=24;
     char tmp[400],txt[200];
     
     //https://www.cnblogs.com/lidabo/p/5076560.html
-    r = system("killall wpa_supplicant");
     if(on) {
         snprintf(txt, sizeof(txt), "ctrl_interface=/var/run/wpa_supplicant\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);
         r = system(tmp);
 
+        r = system("killall wpa_supplicant");
+
         sprintf(tmp, "wpa_supplicant -B -i %s -c %s", WLAN_IFNAME, STA_CONF);
         r = system(tmp);
 
-        sprintf(tmp, "udhcpc -R -b -i %s", WLAN_IFNAME);
-        r = system(tmp);
+        r = udhcpc_start(1);
     }
     else {
         r = system("wpa_cli disconnect");
-        r = system("killall wpa_supplicant udhcpc");
+        r = system("killall wpa_supplicant");
+        r = udhcpc_start(0);
     }
 
     return r;