new_func_wifi_2

Change-Id: I2d61e39dacb155df5e9af72f3eacb704a2c58935
diff --git a/mbtk/libmbtk_lib/wifi/sta_cli.c b/mbtk/libmbtk_lib/wifi/sta_cli.c
index 316d70f..0cf37fd 100644
--- a/mbtk/libmbtk_lib/wifi/sta_cli.c
+++ b/mbtk/libmbtk_lib/wifi/sta_cli.c
@@ -16,6 +16,8 @@
 

 #include "sta_cli.h"

 #include "sta_ctrl.h"

+#include "mbtk_log.h"

+

 //#include "sta_log.h"

 //#include "mbtk_string.h"

 

@@ -83,14 +85,14 @@
         fgets(ssid,200,fd_tmp); 

         pclose(fd_tmp);

         if(strlen(ssid) > 0){

-           printf("test 100:%s, len:%d\n", ssid, strlen(ssid));

+           LOGE("test 100:%s, len:%d\n", ssid, strlen(ssid));

             

         }else{// Open wpa_supplicant

-            printf("test 101:%s\n", ssid);

+            LOGE("test 101:%s\n", ssid);

         }

     }else{

        

-            printf("test 102:%s\n");

+            LOGE("test 102:%s\n");

     }

 

     return 0;

@@ -107,20 +109,47 @@
         fgets(psk,200,fd_tmp);

         pclose(fd_tmp);

         if(strlen(psk) > 0){

-           printf("test 100:%s\n", psk);

+           LOGE("test 100:%s\n", psk);

             

         }else{// Open wpa_supplicant

-            printf("test 101:%s\n", psk);

+            LOGE("test 101:%s\n", psk);

         }

     }else{

        

-            printf("test 102:%s\n");

+            LOGE("test 102:%s\n");

     }

 

     return 0;

 }

 

 

+int sta_cli_ssid_set(char *ssid)

+{

+

+    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);

+    

+    

+    return 0;

+}

+

+int sta_cli_psk_set(char *psk)

+{

+

+    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);

+    

+    

+    return 0;

+}

+

+

+

+

 

 static char*

 sta_cli_ssid_process

@@ -135,7 +164,7 @@
     int i;

     for (i = 0; i < strlen(ssid); i++){

         if (!isascii(ssid[i])){

-            //printf("0x%02x\n",(unsigned char)ssid[i]);

+            //LOGE("0x%02x\n",(unsigned char)ssid[i]);

             //return 0;

             ascii = 0;

             break;

@@ -149,7 +178,7 @@
     }else{

 		int pos = 0;

         for (i = 0; i < strlen(ssid); i++){

-            printf("0x%02x\n",(unsigned char)ssid[i]);

+            LOGE("0x%02x\n",(unsigned char)ssid[i]);

         	snprintf(result + pos,len - pos,

                 "%02x",(unsigned char)ssid[i]);

 			pos += 2;

@@ -173,13 +202,13 @@
 

     if((sock=socket(AF_INET,SOCK_STREAM,0))<0)

     {

-        printf("socket:errno(%d)\n",errno);

+        LOGE("socket:errno(%d)\n",errno);

         return NULL;

     }

     strcpy(ifreq.ifr_name,ifname);

     if(ioctl(sock,SIOCGIFHWADDR,&ifreq) <0)

     {

-		printf("ioctl:errno(%d)\n",errno);

+		LOGE("ioctl:errno(%d)\n",errno);

         return NULL;

     }

     snprintf(mac,mac_len,

@@ -268,12 +297,12 @@
     buf[len] = '\0';

     if(sta_cli_conn_fd != -1){

         if(write(sta_cli_conn_fd,buf,len) != len){

-            printf("Send open msg to client fail.\n");

+            LOGE("Send open msg to client fail.\n");

         }else{

-            printf("Send open msg to client success.\n");

+            LOGE("Send open msg to client success.\n");

         }

     }else{

-        printf("No client connected.\n");

+        LOGE("No client connected.\n");

     }

 	sta_should_send_connected_msg = FALSE;

 }

@@ -285,16 +314,16 @@
     char *msg

 )

 {

-    printf("cmd_id = %d,[%s]\n",sta_cli_cmd_id,msg);

+    LOGE("cmd_id = %d,[%s]\n",sta_cli_cmd_id,msg);

 

 //    if(sta_cli_conn_fd != -1){

 //        if(write(sta_cli_conn_fd,msg,strlen(msg)) != strlen(msg)){

-//            printf("Send msg to client fail.\n");

+//            LOGE("Send msg to client fail.\n");

 //        }else{

-//            printf("Send msg to client success.\n");

+//            LOGE("Send msg to client success.\n");

 //        }

 //    }else{

-//        printf("No client connected.\n");

+//        LOGE("No client connected.\n");

 //    }

 

 	// Send msg(CMD_OPEN_SUCCESS) to wifi_server.

@@ -321,12 +350,12 @@
             if(sta_cli_conn_fd != -1){

 				usleep(500);

                 if(write(sta_cli_conn_fd,buf,len) != len){

-                    printf("Send msg to client fail.\n");

+                    LOGE("Send msg to client fail.\n");

                 }else{

-                    printf("Send msg to client success.\n");

+                    LOGE("Send msg to client success.\n");

                 }

             }else{

-                printf("No client connected.\n");

+                LOGE("No client connected.\n");

             }

         }

         return;

@@ -346,12 +375,12 @@
 	        buf[len] = '\0';

 	        if(sta_cli_conn_fd != -1){

 	            if(write(sta_cli_conn_fd,buf,len) != len){

-	                printf("Send msg to client fail.\n");

+	                LOGE("Send msg to client fail.\n");

 	            }else{

-	                printf("Send msg to client success.\n");

+	                LOGE("Send msg to client success.\n");

 	            }

 	        }else{

-	            printf("No client connected.\n");

+	            LOGE("No client connected.\n");

 	        }

 			//sta_connected = FALSE;

 			//pthread_mutex_unlock(&sta_mutex);

@@ -371,7 +400,7 @@
         case CMD_ID_SCAN:

         {

             if(str_contains(msg, "CTRL-EVENT-SCAN-RESULTS")){

-                printf("Start resume thread.\n");

+                LOGE("Start resume thread.\n");

                 pthread_mutex_lock(&mutex);

                 pthread_cond_signal(&cond);

                 //pthread_cond_broadcast(&cond);

@@ -380,7 +409,7 @@
             break;

         }

         default:

-            printf("cmd_id[%d] unknown.\n",sta_cli_cmd_id);

+            LOGE("cmd_id[%d] unknown.\n",sta_cli_cmd_id);

             break;

     }

 }

@@ -394,14 +423,14 @@
     struct timeval now_1;

     struct timespec outtime;

     int thread_id = pthread_self();

-    printf("Thread(%ld) pause.\n",thread_id);

+    LOGE("Thread(%ld) pause.\n",thread_id);

     pthread_mutex_lock(&mutex);

     gettimeofday(&now_1, NULL);

     outtime.tv_sec = now_1.tv_sec + time / 1000;

     outtime.tv_nsec = now_1.tv_usec * 1000;

     pthread_cond_timedwait(&cond, &mutex, &outtime);

     pthread_mutex_unlock(&mutex);

-    printf("Thread(%ld) resume.\n",thread_id);

+    LOGE("Thread(%ld) resume.\n",thread_id);

 }

 

 static bool

@@ -451,7 +480,7 @@
 )

 {

 	char *data_base = data;

-    printf("SCAN:\n%s\n",reply);

+    LOGE("SCAN:\n%s\n",reply);

     bzero(data,len);

     const char *ptr = reply;

     bool start = FALSE;

@@ -488,7 +517,7 @@
         }

     }

 

-    printf("SCAN 0:\n%s\n",data_base);

+    LOGE("SCAN 0:\n%s\n",data_base);

 

 	// Delete empty ssid line.

 	char *tmp = (char*)calloc(len,1);

@@ -497,16 +526,16 @@
 

 	char *ptr_pre = tmp;

 	ptr = strstr(ptr_pre,"\r\n");

-	printf("line:%s\n",ptr == NULL?"NULL":ptr);

+	LOGE("line:%s\n",ptr == NULL?"NULL":ptr);

 	char ssid[STA_BUF_SIZE] = {0};

 	char *p;

 	while(ptr)

 	{

-		printf("Get line.\n");

+		LOGE("Get line.\n");

 		// Get ssid.

 		if(*(ptr - 1) == ',') // No ssid

 		{

-			printf("Delete one line.\n");

+			LOGE("Delete one line.\n");

 		}else{

 			char s[STA_BUF_SIZE] = {0};

 			p = ptr - 1;

@@ -516,10 +545,10 @@
 			}

 			p += 2;

 			memcpy(s,p,len);

-			printf("ssid = %s;s = %s\n",ssid,s);

+			LOGE("ssid = %s;s = %s\n",ssid,s);

 			if(str_contains(ssid,s))

 			{

-				printf("Jump the same ssid:%s\n",s);

+				LOGE("Jump the same ssid:%s\n",s);

 				ptr_pre = ptr + 2;

 				ptr = strstr(ptr_pre,"\r\n");

 				continue;

@@ -531,18 +560,18 @@
 			memcpy(ssid + strlen(ssid),s,len);

 

 			memcpy(data_base + strlen(data_base),ptr_pre,ptr + 2 - ptr_pre);

-			printf("Copy ssid:\"%s\"\n",s);

+			LOGE("Copy ssid:\"%s\"\n",s);

 		}

 		ptr_pre = ptr + 2;

 		ptr = strstr(ptr_pre,"\r\n");

 	}

 

-	printf("Scan parse end.\n");

+	LOGE("Scan parse end.\n");

 

 	free(tmp);

 	tmp = NULL;

 

-	printf("SCAN 1:\n%s\n",data_base);

+	LOGE("SCAN 1:\n%s\n",data_base);

 

     return STA_ERR_SUCCESS;

 }

@@ -555,7 +584,7 @@
     size_t data_len

 )

 {

-    printf("STATUS:\n%s\n",reply);

+    LOGE("STATUS:\n%s\n",reply);

 

     bzero(data,data_len);

 

@@ -597,7 +626,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get own MAC address.\n");

+			LOGE("Not get own MAC address.\n");

 		}

 

 		// net_id

@@ -612,7 +641,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get net id.\n");

+			LOGE("Not get net id.\n");

 		}

 

 		// ssid

@@ -627,7 +656,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get ssid.\n");

+			LOGE("Not get ssid.\n");

 		}

 

 		// freq

@@ -644,7 +673,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get freq.\n");

+			LOGE("Not get freq.\n");

 		}

 

 		// auth

@@ -679,13 +708,13 @@
 				}else{

 					memcpy(data + len,",",1);

 					len += 1;

-					printf("Not get group_cipher.\n");

+					LOGE("Not get group_cipher.\n");

 				}

 			}

 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get key_mgmt.\n");

+			LOGE("Not get key_mgmt.\n");

 		}

 

 		// mac_ap

@@ -705,7 +734,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get IP.\n");

+			LOGE("Not get IP.\n");

 		}

 	}else{

 		memcpy(data + len,"0",1);

@@ -723,7 +752,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get MAC address.\n");

+			LOGE("Not get MAC address.\n");

 		}

 

 		memcpy(data + len,",,,,,,,",7);

@@ -734,7 +763,7 @@
 	len += 2;

 	data[len] = '\0';

 

-    printf("STATUS:\n%s\n",data);

+    LOGE("STATUS:\n%s\n",data);

 #undef BUF_SIZE

     return STA_ERR_SUCCESS;

 }

@@ -747,7 +776,7 @@
     size_t len

 )

 {

-    printf("MIB:\n%s\n",reply);

+    LOGE("MIB:\n%s\n",reply);

 

     memcpy(data,reply,strlen(reply));

 

@@ -762,7 +791,7 @@
     size_t len

 )

 {

-    printf("LIST_NETWORK:\n%s\n",reply);

+    LOGE("LIST_NETWORK:\n%s\n",reply);

 

     bzero(data,len);

     const char *ptr = reply;

@@ -808,7 +837,7 @@
 

     //memcpy(data,reply,strlen(reply));

 

-    printf("LIST_NETWORK:\n%s\n",data);

+    LOGE("LIST_NETWORK:\n%s\n",data);

 

     return STA_ERR_SUCCESS;

 }

@@ -823,17 +852,17 @@
     if(err == STA_ERR_SUCCESS){

         if(strncmp(cmd,STA_CMD_SCAN,strlen(STA_CMD_SCAN)) == 0

             && strncmp(sta_cli_cmd_reply,STA_TAG_CMD_FAIL_BUSY,strlen(STA_TAG_CMD_FAIL_BUSY)) == 0){

-            printf("\"%s\" busy.\n",cmd);

+            LOGE("\"%s\" busy.\n",cmd);

             return STA_ERR_SUCCESS;

         }

 

         if(strncmp(sta_cli_cmd_reply,STA_TAG_CMD_FAIL,strlen(STA_TAG_CMD_FAIL)) == 0){

-            printf("\"%s\" fail.\n",cmd);

+            LOGE("\"%s\" fail.\n",cmd);

             return STA_ERR_UNKNOWN;

         }

-        printf("[%s]:\n%s\n",cmd,sta_cli_cmd_reply);

+        LOGE("[%s]:\n%s\n",cmd,sta_cli_cmd_reply);

     }else{

-        printf("[%s]:FAIL\n",cmd);

+        LOGE("[%s]:FAIL\n",cmd);

     }

     return err;

 }

@@ -864,17 +893,17 @@
                     data,

                     len);

             }else{

-                printf("SCAN_RESULTS cmd fail.\n");

+                LOGE("SCAN_RESULTS cmd fail.\n");

                 return STA_ERR_UNKNOWN;

             }

         }else{

             sta_cli_cmd_id = CMD_ID_NON;

-            printf("SCAN cmd fail.\n");

+            LOGE("SCAN cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("SCAN cmd fail.\n");

+        LOGE("SCAN cmd fail.\n");

         return err;

     }

 }

@@ -910,11 +939,11 @@
 			ptr++; // Point to flag.

 

 			memcpy(flag,ptr,len);

-			printf("%s : %s\n",ssid,flag);

+			LOGE("%s : %s\n",ssid,flag);

 			return flag;

 		}

     }else{

-		printf("SCAN_RESULTS cmd fail.");

+		LOGE("SCAN_RESULTS cmd fail.");

 		return NULL;

     }

     return NULL;

@@ -938,7 +967,7 @@
             data,

             len);

     }else{

-        printf("STATUS cmd fail.\n");

+        LOGE("STATUS cmd fail.\n");

         return err;

     }

 }

@@ -960,7 +989,7 @@
             data,

             len);

     }else{

-        printf("MIB cmd fail.\n");

+        LOGE("MIB cmd fail.\n");

         return err;

     }

 }

@@ -978,12 +1007,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("RECONFIGURE cmd fail.\n");

+            LOGE("RECONFIGURE cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("RECONFIGURE cmd fail.\n");

+        LOGE("RECONFIGURE cmd fail.\n");

         return err;

     }

 }

@@ -1001,12 +1030,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("DISCONNECT cmd fail.\n");

+            LOGE("DISCONNECT cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("DISCONNECT cmd fail.\n");

+        LOGE("DISCONNECT cmd fail.\n");

         return err;

     }

 }

@@ -1024,12 +1053,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("RECONNECT cmd fail.\n");

+            LOGE("RECONNECT cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("RECONNECT cmd fail.\n");

+        LOGE("RECONNECT cmd fail.\n");

         return err;

     }

 }

@@ -1048,12 +1077,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("SAVE_CONFIG cmd fail.\n");

+            LOGE("SAVE_CONFIG cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("SAVE_CONFIG cmd fail.\n");

+        LOGE("SAVE_CONFIG cmd fail.\n");

         return err;

     }

 }

@@ -1064,7 +1093,7 @@
 	char *c

 )

 {

-	printf("cmd = %s\n",c);

+	LOGE("cmd = %s\n",c);

 	char *ptr = c;

 

     sta_cli_cmd_id = CMD_ID_SET_NETWORK;

@@ -1088,22 +1117,22 @@
 	    if(STA_ERR_SUCCESS == err){

 	        if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

 	            //return STA_ERR_SUCCESS;

-	            printf("Success:%s\n",cmd);

+	            LOGE("Success:%s\n",cmd);

 	        }else{

-	            printf("Fail:%s\n",cmd);

+	            LOGE("Fail:%s\n",cmd);

 				sta_cli_cmd_id = CMD_ID_NON;

 	            return STA_ERR_UNKNOWN;

 	        }

 	    }else{

 	        sta_cli_cmd_id = CMD_ID_NON;

-	        printf("Fail:%s\n",cmd);

+	        LOGE("Fail:%s\n",cmd);

 	        return err;

 	    }

 

 		if(ptr == NULL)

 			break;

 

-		printf("ptr = %s",ptr);

+		LOGE("ptr = %s",ptr);

 

 		index = str_indexof(ptr,"#");

 		bzero(cmd,100);

@@ -1129,26 +1158,26 @@
     const char *flag

 )

 {

-	printf("cmd = %s\n",cmd);

+	LOGE("cmd = %s\n",cmd);

 	char buf[500];

-    printf("test11\n");

+    LOGE("test11\n");

 	int index = str_indexof(cmd," psk ");

-    printf("test12\n");

+    LOGE("test12\n");

 	int net_id = atoi(cmd + strlen(STA_CMD_SET_NETWORK) + 1);

-    printf("test13\n");

+    LOGE("test13\n");

 	if(index > 0){ // Is set "psk"

-	    printf("test14\n");

+	    LOGE("test14\n");

 		char psk[64] = {0};

 		int start = index + 5; // " psk "

 		if(*(cmd + start) == '"')

 		{

-		    printf("test15\n");

+		    LOGE("test15\n");

 			memcpy(psk,cmd + start + 1,strlen(cmd) - start - 2);

 		}else{

-            printf("test16\n");

+            LOGE("test16\n");

 			memcpy(psk,cmd + start,strlen(cmd) - start);

 		}

-		printf("psk = %s\n",psk);

+		LOGE("psk = %s\n",psk);

 

 		// Set to OPEN (No psk)

 		// SET_NETWORK <net_id> key_mgmt NONE

@@ -1212,7 +1241,7 @@
 	}

 	else // SSID

 	{

-	    printf("test21\n");

+	    LOGE("test21\n");

 		index = str_indexof(cmd," ssid ");

 		char ssid[STA_BUF_SIZE] = {0};

 		int start = index + 6; // " ssid "

@@ -1222,12 +1251,12 @@
 		}else{

 			memcpy(ssid,cmd + start,strlen(cmd) - start);

 		}

-		printf("ssid = %s\n",ssid);

+		LOGE("ssid = %s\n",ssid);

 

 

 		//char ssid_result[STA_SSID_MAX_LEN + 1];

 		//sta_cli_ssid_process(ssid,ssid_result,STA_SSID_MAX_LEN + 2 + 1);

-       // printf("test22, ssid_result: %s\n", ssid_result);

+       // LOGE("test22, ssid_result: %s\n", ssid_result);

 		char cmd_result[STA_BUF_SIZE];

 		int size = snprintf(cmd_result,STA_BUF_SIZE,

 			"%s %d ssid %s",

@@ -1235,7 +1264,7 @@
 			net_id,

 			ssid);

 		cmd_result[size] = '\0';

-		printf("cmd = %s\n",cmd_result);

+		LOGE("cmd = %s\n",cmd_result);

 

 		return sta_cli_cmd_set_network_process(cmd);

 	}

@@ -1269,11 +1298,11 @@
             tmp--;

         }

 

-        printf("GET_NETWORK:%s.\n",value);

+        LOGE("GET_NETWORK:%s.\n",value);

         return STA_ERR_SUCCESS;

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("GET_NETWORK cmd fail.\n");

+        LOGE("GET_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1291,12 +1320,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("REMOVE_NETWORK cmd fail.\n");

+            LOGE("REMOVE_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("REMOVE_NETWORK cmd fail.\n");

+        LOGE("REMOVE_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1308,17 +1337,17 @@
     const char *cmd

 )

 {

-	printf("cmd = %s\n",cmd);

+	LOGE("cmd = %s\n",cmd);

     sta_cli_cmd_id = CMD_ID_ADD_NETWORK;

     sta_err_enum err = sta_cli_process_cmd(STA_CMD_ADD_NETWORK);

-    printf("test1\n");

+    LOGE("test1\n");

     if(STA_ERR_SUCCESS == err){

         sta_cli_cmd_id = CMD_ID_NON;

         int net_id = atoi(sta_cli_cmd_reply);

-        printf("test2\n");

+        LOGE("test2\n");

         if(net_id >= 0){ // Add network success.

             // Point to ssid

-            printf("test3\n");

+            LOGE("test3\n");

             /*

             const char *ptr = cmd + strlen(STA_CMD_ADD_NETWORK) + 1;

 

@@ -1331,7 +1360,7 @@
 

 

             char ssid[STA_BUF_SIZE] = {0};

-            printf("test4\n");

+            LOGE("test4\n");

             memcpy(ssid,ptr,pass_ptr - ptr - 1);

             */

 

@@ -1339,7 +1368,7 @@
             char ssid[STA_BUF_SIZE] = {'\0'};

             char psk[STA_BUF_SIZE] = {'\0'};

             int len = 0;

-            printf("test5\n");

+            LOGE("test5\n");

 

             sta_cli_ssid_get(ssid);

             len = strlen(ssid);

@@ -1355,12 +1384,12 @@
                 STA_CMD_SET_NETWORK,

                 net_id,

                 ssid);

-            printf("test6\n");

+            LOGE("test6\n");

             buf[size] = '\0';

 

          

             err = sta_cli_cmd_set_network(buf,NULL);

-            printf("test7\n");

+            LOGE("test7\n");

             if(STA_ERR_SUCCESS == err){

 				char flag[50];

 				sta_cli_flag_get(ssid,flag,50);

@@ -1388,11 +1417,11 @@
 

             return err;

         }else{

-            printf("ADD_NETWORK cmd fail.\n");

+            LOGE("ADD_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

-        printf("ADD_NETWORK cmd fail.\n");

+        LOGE("ADD_NETWORK cmd fail.\n");

         sta_cli_cmd_id = CMD_ID_NON;

         return err;

     }

@@ -1411,12 +1440,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("DISABLE_NETWORK cmd fail.\n");

+            LOGE("DISABLE_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("DISABLE_NETWORK cmd fail.\n");

+        LOGE("DISABLE_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1434,12 +1463,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("ENABLE_NETWORK cmd fail.\n");

+            LOGE("ENABLE_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("ENABLE_NETWORK cmd fail.\n");

+        LOGE("ENABLE_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1457,12 +1486,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("SELECT_NETWORK cmd fail.\n");

+            LOGE("SELECT_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("SELECT_NETWORK cmd fail.\n");

+        LOGE("SELECT_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1484,7 +1513,7 @@
             data,

             len);

     }else{

-        printf("LIST_NETWORKS cmd fail.\n");

+        LOGE("LIST_NETWORKS cmd fail.\n");

         return err;

     }

 }

@@ -1502,12 +1531,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("REASSOCIATE cmd fail.\n");

+            LOGE("REASSOCIATE cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("REASSOCIATE cmd fail.\n");

+        LOGE("REASSOCIATE cmd fail.\n");

         return err;

     }

 }

@@ -1525,12 +1554,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("REATTACH cmd fail.\n");

+            LOGE("REATTACH cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("REATTACH cmd fail.\n");

+        LOGE("REATTACH cmd fail.\n");

         return err;

     }

 }

@@ -1543,7 +1572,7 @@
 {

     sta_err_enum result = STA_ERR_SUCCESS;

     if((result = sta_ctrl_driver_init(TRUE)) != STA_ERR_SUCCESS){

-        printf("Driver init fail(%d).\n",result);

+        LOGE("Driver init fail(%d).\n",result);

         return result;

     }

 

@@ -1551,7 +1580,7 @@
         "/etc/wifi/wpa_supplicant.conf",

         "wlan0",

         sta_cli_wpa_msg_cb)) != STA_ERR_SUCCESS){

-        printf("wpa_supplicant init fail(%d).\n",result);

+        LOGE("wpa_supplicant init fail(%d).\n",result);

         return result;

     }

 	//pthread_mutex_init(&sta_mutex,NULL);

@@ -1566,12 +1595,12 @@
 {

     sta_err_enum result = STA_ERR_SUCCESS;

     if((result = sta_ctrl_wpa_deinit()) != STA_ERR_SUCCESS){

-        printf("sta_ctrl_wpa_deinit fail(%d).",result);

+        LOGE("sta_ctrl_wpa_deinit fail(%d).",result);

         return result;

     }

 

     if((result = sta_ctrl_driver_init(FALSE)) != STA_ERR_SUCCESS){

-        printf("Driver close fail(%d).\n",result);

+        LOGE("Driver close fail(%d).\n",result);

         return result;

     }

 	//pthread_mutex_destroy(&sta_mutex);

@@ -1594,7 +1623,7 @@
     size_t reply_len

 )

 {

-	printf("cmd:%s\n",cmd);

+	LOGE("cmd:%s\n",cmd);

     bzero(reply,reply_len);

     sta_err_enum err = STA_ERR_UNKNOWN;

     if(strncmp(cmd,(STA_CMD_OPEN),strlen(STA_CMD_OPEN)) == 0){

@@ -1637,9 +1666,7 @@
         err = sta_cli_cmd_scan(cmd, data,STA_BUF_SIZE);

         if(err == STA_ERR_SUCCESS){

             snprintf(reply,reply_len,

-                "%s-%s-%s"STA_CMD_SEPARATED,

-                STA_TAG_CMD,

-                cmd,

+                "%s"STA_CMD_SEPARATED,

                 data);

         }else{

             snprintf(reply,reply_len,

@@ -1721,7 +1748,7 @@
 #endif

 		if(err == STA_ERR_SUCCESS)

 		{

-			printf("sta_cli_cmd_disconnect success.\n");

+			LOGE("sta_cli_cmd_disconnect success.\n");

 			//pthread_mutex_lock(&sta_mutex);

 			//if(sta_connected)

 			//{

@@ -1739,7 +1766,7 @@
 							mac_ap,

 							STA_MAC_LEN + 1)) // Disconnected.

 						{

-							printf("Disconnected success.\n");

+							LOGE("Disconnected success.\n");

 							snprintf(reply,reply_len,

 								"%s-%s-%s"STA_CMD_SEPARATED,

 								STA_TAG_CMD,

@@ -1748,18 +1775,18 @@
 							ok = TRUE;

 							break;

 						}else{ // Connected.

-							printf("Not disconnected.Try again(STATUS).\n");

+							LOGE("Not disconnected.Try again(STATUS).\n");

 							usleep(500);

 						}

 				    }else{

-				        printf("STATUS cmd fail.\n");

+				        LOGE("STATUS cmd fail.\n");

 				        break;

 				    }

 				}

 

 				if(!ok) // fail

 				{

-					printf("Disconnect fail.\n");

+					LOGE("Disconnect fail.\n");

 		            snprintf(reply,reply_len,

 		                "%s-%s-%s:%d"STA_CMD_SEPARATED,

 		                STA_TAG_CMD,

@@ -1771,7 +1798,7 @@
 			//}

 			//pthread_mutex_unlock(&sta_mutex);

 		}else{

-			printf("sta_cli_cmd_disconnect fail.\n");

+			LOGE("sta_cli_cmd_disconnect fail.\n");

             snprintf(reply,reply_len,

                 "%s-%s-%s:%d"STA_CMD_SEPARATED,

                 STA_TAG_CMD,

@@ -1999,7 +2026,7 @@
                 err);

         }

     }else{

-        printf("Unknown cmd:%s\n",cmd);

+        LOGE("Unknown cmd:%s\n",cmd);

         return FALSE;

     }

     return TRUE;

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;

 }