new_func_wifi_2
Change-Id: I2d61e39dacb155df5e9af72f3eacb704a2c58935
diff --git a/mbtk/libmbtk_lib/wifi/sta_ctrl.c b/mbtk/libmbtk_lib/wifi/sta_ctrl.c
index 66c55f5..e5e24aa 100644
--- a/mbtk/libmbtk_lib/wifi/sta_ctrl.c
+++ b/mbtk/libmbtk_lib/wifi/sta_ctrl.c
@@ -10,6 +10,8 @@
#include "wpa_ctrl.h"
#include "sta_ctrl.h"
+#include "mbtk_log.h"
+
//#include "sta_log.h"
#define WPA_SUPPLICANT_LOG_FILE "/data/wpa_supplicant.log"
@@ -54,7 +56,7 @@
static void
sta_ctrl_wpa_req_cb(char *msg, size_t len)
{
- printf("%s\n", msg);
+ LOGE("%s\n", msg);
}
bool
@@ -66,17 +68,17 @@
int result = TRUE;
FILE *stream = NULL;
- printf("system call: %s\n", command);
+ LOGE("system call: %s\n", command);
stream = popen( command, "w" );
if( stream == NULL )
{
- printf("system command failed\n");
+ LOGE("system command failed\n");
result = FALSE;
}
else if( 0 > pclose( stream ) )
{
- printf("pclose command failed\n");
+ LOGE("pclose command failed\n");
}
return result;
@@ -110,7 +112,7 @@
pclose(cmd);
}
pid = atoi(pid_s);
- printf("%s pid =%d\n", name,pid);
+ LOGE("%s pid =%d\n", name,pid);
/* If pid is zero we break from while*/
if(pid == 0)
{
@@ -119,7 +121,7 @@
}
}
- printf("PID still running after waiting 2 second.\n");
+ LOGE("PID still running after waiting 2 second.\n");
result = FALSE;
exit_end:
#undef PROCESS_KILL_RETRY
@@ -145,14 +147,14 @@
}
int pid = atoi(pid_s);
- printf("%s pid =%d\n", name,pid);
+ LOGE("%s pid =%d\n", name,pid);
/* If pid is zero we break from while*/
if(pid == 0)
{
- printf("%s not runnig.\n",name);
+ LOGE("%s not runnig.\n",name);
return FALSE;
}else{
- printf("%s is runnig.\n",name);
+ LOGE("%s is runnig.\n",name);
return TRUE;
}
}
@@ -161,7 +163,7 @@
static void*
sta_ctrl_event_thread_run( void *arg )
{
- printf("Thread[%ld] run().\n",pthread_self());
+ LOGE("Thread[%ld] run().\n",pthread_self());
int nready;
struct epoll_event ev_sock,ev_pipe,events[20];
@@ -178,9 +180,9 @@
if(!sta_event_thread_is_running){
break;
}
- printf("epoll_wait waitting...\n",nready);
+ LOGE("epoll_wait waitting...\n",nready);
nready = epoll_wait(epfd,events,20,-1);
- printf("epoll_wait return.(count = %d)\n",nready);
+ LOGE("epoll_wait return.(count = %d)\n",nready);
int i;
for(i=0;i<nready;++i) {
if (events[i].events & EPOLLIN) {// Read
@@ -191,7 +193,7 @@
&& events[i].data.fd == wpa_ctrl_get_fd(sta_mon_conn)){
sta_ctrl_recv_event();
}else if(events[i].data.fd == sta_ctrl_pipe_fd[0]){
- printf("Thread end.[fd = %d]\n",events[i].data.fd);
+ LOGE("Thread end.[fd = %d]\n",events[i].data.fd);
// End thread
char buf_end[10] = {0};
if(read(sta_ctrl_pipe_fd[0],buf_end,10) > 0
@@ -200,23 +202,23 @@
break;
}
}else{
- printf("No such fd[%d].\n",events[i].data.fd);
+ LOGE("No such fd[%d].\n",events[i].data.fd);
}
} else {
- printf("event error.\n");
+ LOGE("event error.\n");
}
}
}
close(epfd);
- printf("Thread exit.\n");
+ LOGE("Thread exit.\n");
return ((void*)0);
}
static sta_err_enum
sta_ctrl_close_connection(void)
{
- printf("start.\n");
+ LOGE("start.\n");
if (sta_ctrl_conn == NULL)
return STA_ERR_UNKNOWN;
@@ -231,7 +233,7 @@
sta_mon_conn = NULL;
}
- printf("end.\n");
+ LOGE("end.\n");
return STA_ERR_SUCCESS;
}
@@ -247,14 +249,14 @@
char ctrl_path[100] = {0};
result = sta_ctrl_conf_file_parse("ctrl_interface", ctrl_path);
if(STA_ERR_SUCCESS != result){
- printf("sta_ctrl_conf_file_parse() fail(%d).\n",result);
+ LOGE("sta_ctrl_conf_file_parse() fail(%d).\n",result);
return result;
}
snprintf(ctrl_path + strlen(ctrl_path),10,
"/%s",
sta_ctrl_ifname);
- printf("ctrl_path = \"%s\"\n",ctrl_path);
+ LOGE("ctrl_path = \"%s\"\n",ctrl_path);
sta_ctrl_conn = wpa_ctrl_open(ctrl_path);
if (sta_ctrl_conn == NULL) {
@@ -270,7 +272,7 @@
if (wpa_ctrl_attach(sta_mon_conn) == 0) {
sta_ctrl_attached = 1;
} else {
- printf("Warning: Failed to attach to "
+ LOGE("Warning: Failed to attach to "
"wpa_supplicant.\n");
sta_ctrl_close_connection();
return STA_ERR_UNKNOWN;
@@ -283,10 +285,10 @@
sta_ctrl_event_thread_run,
NULL);
if( ret != 0 ) {
- printf( "Create thread error!\n");
+ LOGE( "Create thread error!\n");
}
}else{
- printf("sta_event_thread is running.\n");
+ LOGE("sta_event_thread is running.\n");
return STA_ERR_UNKNOWN;
}
return result;
@@ -305,10 +307,10 @@
static void
sta_ctrl_recv_event(void)
{
- printf("start.\n");
+ LOGE("start.\n");
if (sta_ctrl_conn == NULL) {
sta_ctrl_reconnect();
- printf("sta_ctrl_conn == NULL:end.\n");
+ LOGE("sta_ctrl_conn == NULL:end.\n");
return;
}
@@ -317,22 +319,22 @@
size_t len = sizeof(buf) - 1;
if (wpa_ctrl_recv(sta_mon_conn, buf, &len) == 0) {
buf[len] = '\0';
- printf("<<%s>>\n",buf);
+ LOGE("<<%s>>\n",buf);
if(sta_ctrl_msg)
sta_ctrl_msg(buf);
} else {
- printf("Could not read pending message.\n");
+ LOGE("Could not read pending message.\n");
break;
}
}
if (wpa_ctrl_pending(sta_mon_conn) < 0) {
- printf("Connection to wpa_supplicant lost - trying to "
+ LOGE("Connection to wpa_supplicant lost - trying to "
"reconnect\n");
sta_ctrl_reconnect();
}
- printf("end.\n");
+ LOGE("end.\n");
}
static sta_err_enum
@@ -345,7 +347,7 @@
sta_err_enum result = STA_ERR_UNKNOWN;
FILE *fd = fopen(sta_ctrl_conf_file_path,"r");
if(!fd){
- printf("Open file(%s) fail(%d).\n",sta_ctrl_conf_file_path,errno);
+ LOGE("Open file(%s) fail(%d).\n",sta_ctrl_conf_file_path,errno);
return STA_ERR_UNKNOWN;
}
@@ -399,19 +401,19 @@
&reply_len,
sta_ctrl_wpa_req_cb);
if (ret == -2) {
- printf("command timed out.\n");
+ LOGE("command timed out.\n");
result = STA_ERR_TIMEOUT;
goto end_fail;
} else if (ret < 0) {
- printf("command failed.\n");
+ LOGE("command failed.\n");
result = STA_ERR_UNKNOWN;
goto end_fail;
} else {
reply[reply_len] = '\0';
- printf("1:%s\n", reply);
+ LOGE("1:%s\n", reply);
if(reply_len > 0 && reply[reply_len - 1] != '\n')
- printf("\n");
+ LOGE("\n");
}
end_success:
@@ -434,7 +436,7 @@
if(open){
fd_tmp = popen("/etc/wifi/mbtk_wifi_driver.sh sta start","r");
}else{
- fd_tmp = popen("/etc/wifi/mbtk_wifi_driver.sh driver_rmmod","r");
+ fd_tmp = popen("/etc/wifi/mbtk_wifi_driver.sh sta stop","r");
}
if(fd_tmp){
@@ -442,13 +444,13 @@
fgets(buf,200,fd_tmp);
pclose(fd_tmp);
if(strlen(buf) > 0){
- printf("Driver %s fail.(%s)\n",(open?"open":"close"),buf);
+ LOGE("Driver %s fail.(%s)\n",(open?"open":"close"),buf);
result = STA_ERR_DRIVER;
}else{// Open wpa_supplicant
- printf("Driver %s success.\n",(open?"open":"close"));
+ LOGE("Driver %s success.\n",(open?"open":"close"));
}
}else{
- printf("Driver %s fail.(%s)\n",(open?"open":"close"));
+ LOGE("Driver %s fail.(%s)\n",(open?"open":"close"));
result = STA_ERR_DRIVER;
}
@@ -490,7 +492,7 @@
sta_ctrl_ifname[size] = '\0';
if(pipe(sta_ctrl_pipe_fd)){
- printf("pipe() fail(%d).\n",errno);
+ LOGE("pipe() fail(%d).\n",errno);
result = STA_ERR_UNKNOWN;
goto end_fail;
}
@@ -501,7 +503,7 @@
fgets(buf,200,fd_tmp);
pclose(fd_tmp);
if(strlen(buf) > 0){
- printf("wpa_supplicant is running.(%s)\n",buf);
+ LOGE("wpa_supplicant is running.(%s)\n",buf);
}else{// Open wpa_supplicant
bzero(buf,200);
@@ -516,23 +518,23 @@
"wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wifi/wpa_supplicant.conf -B");
*/
if (sta_ctrl_system(buf)){
- printf("\"%s\" success.\n",buf);
+ LOGE("\"%s\" success.\n",buf);
sleep(1);
}else{
- printf("\"%s\" fail.\n",buf);
+ LOGE("\"%s\" fail.\n",buf);
result = STA_ERR_UNKNOWN;
goto end_fail;
}
}
}else{
- printf("\"pidof wpa_supplicant\" fail\n");
+ LOGE("\"pidof wpa_supplicant\" fail\n");
result = STA_ERR_UNKNOWN;
goto end_fail;
}
result = sta_ctrl_open_connection();
if(STA_ERR_SUCCESS != result) {
- printf("sta_ctrl_open_connection() fail(%d).\n",result);
+ LOGE("sta_ctrl_open_connection() fail(%d).\n",result);
goto end_fail;
}
@@ -564,11 +566,11 @@
write(sta_ctrl_pipe_fd[1],"0",1);
- printf("Waitting for thread(%ld) exit.\n",sta_event_thread_id);
+ LOGE("Waitting for thread(%ld) exit.\n",sta_event_thread_id);
pthread_join(sta_event_thread_id,NULL);
- printf("pthread_join() return.\n");
+ LOGE("pthread_join() return.\n");
close(sta_ctrl_pipe_fd[0]);
@@ -580,20 +582,20 @@
// Stop process wpa_supplicant
if(sta_ctrl_system("killall -15 wpa_supplicant")
&& sta_ctrl_kill_check("wpa_supplicant")){
- printf("\"killall -15 wpa_supplicant\" success.\n");
+ LOGE("\"killall -15 wpa_supplicant\" success.\n");
}else{
if(sta_ctrl_system("killall -9 wpa_supplicant")){
- printf("\"killall -9 wpa_supplicant\" success.\n");
+ LOGE("\"killall -9 wpa_supplicant\" success.\n");
}else{
- printf("\"killall -9 wpa_supplicant\" fail.\n");
+ LOGE("\"killall -9 wpa_supplicant\" fail.\n");
}
}
end_success:
- printf("sta_ctrl_wpa_deinit() end(success).\n");
+ LOGE("sta_ctrl_wpa_deinit() end(success).\n");
return result;
end_fail:
- printf("sta_ctrl_wpa_deinit() end(fail)[%s].\n",result);
+ LOGE("sta_ctrl_wpa_deinit() end(fail)[%s].\n",result);
return result;
}