add wifi func

Change-Id: I79282e7c2c5303298a49410c7bae62e0e5b17a91
diff --git a/mbtk/include/mbtk/mbtk_wifi_ap.h b/mbtk/include/mbtk/mbtk_wifi_ap.h
index 9522e70..3c5b53c 100644
--- a/mbtk/include/mbtk/mbtk_wifi_ap.h
+++ b/mbtk/include/mbtk/mbtk_wifi_ap.h
@@ -11,6 +11,9 @@
 #define SETTING_SPLIT_CHAR		'='	

 #define ACL_DENY_FILE "/etc/wifi/hostapd.deny"

 #define ACL_ACCEPT_FILE "/etc/wifi/hostapd.accept"

+#define DHCP_PATH "/tmp/dhcp.leases"

+#define DEF_INTERFACE "wlan0"

+

 

 

 

@@ -25,6 +28,24 @@
 unsigned long long tx_dropped; 

 } mbtk_wifi_pkt_stats_t;

 

+typedef struct

+{

+char addr[16];

+char macaddr[18]; 

+char name[20]; 

+char ifname[18]; 

+int uptime; 

+} mbtk_lanhost_t;

+

+

+typedef struct

+{

+ int array_len; 

+ mbtk_lanhost_t array[32]; 

+} mbtk_lanhost_ts;

+

+

+

 

 int mbtk_wifi_get_setting(const char *path, const char *key, char *value, int value_max_len);

 int mbtk_wifi_set_setting(const char *path, const char *key, const char *value);

@@ -33,6 +54,8 @@
 int mbtk_wifi_set_file(const char *path, const char *value);

 int mbtk_wifi_get_file(const char *path, char *value, int value_max_len);

 int mbtk_wifi_get_pkt(mbtk_wifi_pkt_stats_t* pkt_stat);

+int mbtk_wifi_get_dhcp(mbtk_lanhost_ts* lanhost_arr);

+int mbkt_wifi_get_uptime(mbtk_lanhost_ts* lanhost_arr);

 

 

 

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;

+}

+