Fix warning as error for V2
Change-Id: I70cfd971fda629011ba1be84fef15afea196d393
diff --git a/mbtk/libmbtk_lib_v2/wifi/sta_cli.c b/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
index 0cf37fd..9dbd202 100755
--- a/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
+++ b/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
@@ -12,11 +12,14 @@
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
-
+#include <ctype.h>
+#include <stdlib.h>
#include "sta_cli.h"
#include "sta_ctrl.h"
#include "mbtk_log.h"
+#include "mbtk_utils.h"
+#include "mbtk_str.h"
//#include "sta_log.h"
//#include "mbtk_string.h"
@@ -29,6 +32,7 @@
#define STA_MAC_LEN 17 // xx:xx:xx:xx:xx:xx
#define STA_SSID_MAX_LEN (32 * 5)
+bool sta_ctrl_system(const char *command);
#ifndef INFTIM
#define INFTIM (-1) /* infinite poll timeout */
@@ -66,7 +70,7 @@
static pthread_cond_t cond;
static pthread_mutex_t mutex;
static int sta_cli_conn_fd = -1;
-static char sta_cli_buf[STA_BUF_SIZE];
+//static char sta_cli_buf[STA_BUF_SIZE];
static bool sta_should_send_connected_msg = TRUE;
//static bool sta_connected = FALSE;
static bool sta_disconnectting = FALSE;
@@ -79,19 +83,20 @@
FILE *fd_tmp = NULL;
fd_tmp = popen("cat /etc/wifi/sta_network.conf | grep -w 'SSID' | cut -d '=' -f 2","r");
-
+
if(fd_tmp){
- char buf[200] = {0};
- fgets(ssid,200,fd_tmp);
+// char buf[200] = {0};
+ if(fgets(ssid,200,fd_tmp) == NULL)
+ return -1;
pclose(fd_tmp);
if(strlen(ssid) > 0){
LOGE("test 100:%s, len:%d\n", ssid, strlen(ssid));
-
+
}else{// Open wpa_supplicant
LOGE("test 101:%s\n", ssid);
}
}else{
-
+
LOGE("test 102:%s\n");
}
@@ -103,19 +108,20 @@
FILE *fd_tmp = NULL;
fd_tmp = popen("cat /etc/wifi/sta_network.conf | grep -w 'PASSWORD' | cut -d '=' -f 2","r");
-
+
if(fd_tmp){
- char buf[200] = {0};
- fgets(psk,200,fd_tmp);
+// char buf[200] = {0};
+ if(fgets(psk,200,fd_tmp) == NULL)
+ return -1;
pclose(fd_tmp);
if(strlen(psk) > 0){
LOGE("test 100:%s\n", psk);
-
+
}else{// Open wpa_supplicant
LOGE("test 101:%s\n", psk);
}
}else{
-
+
LOGE("test 102:%s\n");
}
@@ -129,9 +135,9 @@
char buf[100] = {0};
snprintf(buf, 100, "sed -i 's/SSID=.*$/SSID=%s/g' /etc/wifi/sta_network.conf", ssid);
LOGE("set ssid:%s", buf);
- system(buf);
-
-
+ mbtk_system(buf);
+
+
return 0;
}
@@ -141,16 +147,16 @@
char buf[100] = {0};
snprintf(buf, 100, "sed -i 's/PASSWORD=.*$/PASSWORD=%s/g' /etc/wifi/sta_network.conf", psk);
LOGE("set ssid:%s", buf);
- system(buf);
-
-
+ mbtk_system(buf);
+
+
return 0;
}
-
+#if 0
static char*
sta_cli_ssid_process
(
@@ -186,7 +192,7 @@
}
return result;
}
-
+#endif
static char*
sta_cli_mac_get
@@ -239,7 +245,9 @@
stream = popen("hostname","r");
if(stream != NULL)
{
- fgets(host, 100, stream);
+ if(fgets(host, 100, stream) == NULL) {
+ return NULL;
+ }
pclose(stream);
int index = str_indexof(host,"\n");
if(strlen(host) > 0
@@ -276,8 +284,7 @@
"%ld",t);
}
- snprintf(name,name_len,
- "%s-%s",host,mac);
+ snprintf(name,name_len,"%s-%s",host,mac);
return name;
}
@@ -334,8 +341,8 @@
// Connected to AP
if(str_contains(msg, "CTRL-EVENT-CONNECTED")){
//sta_connected = TRUE;
- char sta_name[100];
- sta_cli_sta_name_get(sta_name,100);
+ char sta_name[200];
+ sta_cli_sta_name_get(sta_name,200);
char cmd[200];
int size = snprintf(cmd,200,
"dhcpcd -h %s -o domain_name_servers --noipv4ll wlan0",sta_name);
@@ -524,11 +531,11 @@
memcpy(tmp,data_base,strlen(data_base));
bzero(data_base,len);
- char *ptr_pre = tmp;
+ const char *ptr_pre = tmp;
ptr = strstr(ptr_pre,"\r\n");
LOGE("line:%s\n",ptr == NULL?"NULL":ptr);
char ssid[STA_BUF_SIZE] = {0};
- char *p;
+ const char *p;
while(ptr)
{
LOGE("Get line.\n");
@@ -1090,11 +1097,11 @@
static sta_err_enum
sta_cli_cmd_set_network_process
(
- char *c
+ const char *c
)
{
LOGE("cmd = %s\n",c);
- char *ptr = c;
+ const char *ptr = c;
sta_cli_cmd_id = CMD_ID_SET_NETWORK;
sta_err_enum err = STA_ERR_SUCCESS;
@@ -1373,12 +1380,12 @@
sta_cli_ssid_get(ssid);
len = strlen(ssid);
ssid[len - 1] = '\0';
-
+
sta_cli_psk_get(psk);
len = strlen(psk);
psk[len - 1] = '\0';
-
+
int size = snprintf(buf,STA_BUF_SIZE,
"%s %d ssid \"%s\"",
STA_CMD_SET_NETWORK,
@@ -1387,7 +1394,7 @@
LOGE("test6\n");
buf[size] = '\0';
-
+
err = sta_cli_cmd_set_network(buf,NULL);
LOGE("test7\n");
if(STA_ERR_SUCCESS == err){