add wifi func

Change-Id: I79282e7c2c5303298a49410c7bae62e0e5b17a91
diff --git a/mbtk/libmbtk_lib/wifi/mbtk_wifi_ap.c b/mbtk/libmbtk_lib/wifi/mbtk_wifi_ap.c
index 3b4de85..2c19e1c 100644
--- a/mbtk/libmbtk_lib/wifi/mbtk_wifi_ap.c
+++ b/mbtk/libmbtk_lib/wifi/mbtk_wifi_ap.c
@@ -272,6 +272,8 @@
 int mbtk_wifi_get_file(const char *path, char *value, int value_max_len)

 {

     FILE *file;

+    char buf[SETTING_LINE_MAX_LEN] = {0};

+    int len = 0;

     

     file = fopen(path, "r");

     if (!file) 

@@ -279,10 +281,16 @@
         return -1;

     }

 

-    if(NULL == fgets(value, value_max_len, file))

+    while(NULL != fgets(buf, SETTING_LINE_MAX_LEN, file))

     {

-        fclose(file);

-        return -1;

+        LOGD("mbtk_wifi_get_file:%s\n", buf);

+        len += strlen(buf);

+        if(len > value_max_len)

+        {

+            break;

+        }

+        strncat(value, buf, strlen(buf));

+        LOGD("value:%s\n", value);

     }

 

 

@@ -341,4 +349,95 @@
     return 0;

 }

 

+int mbtk_wifi_get_dhcp(mbtk_lanhost_ts* lanhost_arr)

+{

+    if(NULL == lanhost_arr)

+    {

+        return -1;

+    }

+    

+    int lanhost_num = 0;

+    int i = 0;

+    char* ptr = NULL;

+    FILE *file;

+    char buf[SETTING_LINE_MAX_LEN] = {0};

+

+    file = fopen(DHCP_PATH, "r");

+    if (!file) 

+    {

+        return -1;

+    }

+

+    lanhost_arr->array_len = 0;

+    while(NULL != fgets(buf, SETTING_LINE_MAX_LEN, file))

+    {

+        LOGD("mbtk_wifi_get_file:%s\n", buf);

+        ptr = buf;

+        

+        for(i = 0; i < 4; i++)

+        {

+            lanhost_arr->array[lanhost_num].name[i] = *ptr;

+            ptr++;

+        }

+

+        LOGD("mbtk_wifi_get_file name:%s\n", lanhost_arr->array[lanhost_num].name);

+

+        for(i = 0; i < 17; i++)

+        {

+            ptr++;

+            lanhost_arr->array[lanhost_num].macaddr[i]= *ptr;

+        }

+

+        LOGD("mbtk_wifi_get_file mac:%s\n", lanhost_arr->array[lanhost_num].macaddr);

+        ptr++;

+        for(i = 0; i < 15; i++)

+        {

+            ptr++;

+            lanhost_arr->array[lanhost_num].addr[i]= *ptr;

+        }

+        LOGD("mbtk_wifi_get_file addr:%s\n", lanhost_arr->array[lanhost_num].addr);

+        memcpy(lanhost_arr->array[lanhost_num].ifname, DEF_INTERFACE, strlen(DEF_INTERFACE));

+        lanhost_num++;

+          

+    }

+

+

+    fclose(file);

+

+    return 0;

+}

+

+int mbkt_wifi_get_uptime(mbtk_lanhost_ts* lanhost_arr)

+{

+    

+    if(NULL == lanhost_arr)

+    {

+        return -1;

+    }

+

+    unsigned long long connected_time = 0; 

+    char buf[1024] = {0};

+    int i = 0;

+    FILE* fp = NULL;

+

+    lanhost_arr->array_len = 0;

+    fp = popen("hostapd_cli all_sta | grep connected_time", "r");

+    while(NULL != fgets(buf, 1024, fp))

+    {

+        if(0 > sscanf(buf, "connected_time=%llu", &connected_time))

+        {

+            return -1;

+        }

+

+        LOGD("qser wifi connected_time%llu", connected_time);

+        lanhost_arr->array[i].uptime = connected_time;

+        lanhost_arr->array_len++;

+        connected_time = 0;

+        i++;

+    }

+    pclose(fp);

+

+   return 0;

+}

+