mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Revision:
169:e3b6fe271b81
Parent:
167:e84263d55307
Child:
186:707f6e361f3e
--- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.c	Thu Jul 06 15:42:05 2017 +0100
+++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.c	Wed Jul 19 17:31:21 2017 +0100
@@ -20,6 +20,12 @@
 #include <wifi/wifi_ind.h>
 #include <osdep_service.h>
 
+extern u32 GlobalDebugEnable;
+#define WIFI_UTIL_MSG(...)     do {\
+    if (GlobalDebugEnable) \
+        printf("\r" __VA_ARGS__);\
+}while(0)
+
 int iw_ioctl(const char *ifname, unsigned long request, struct iwreq *pwrq)
 {
     memcpy(pwrq->ifr_name, ifname, 5);
@@ -36,7 +42,7 @@
     iwr.u.essid.length = 32;
 
     if (iw_ioctl(ifname, SIOCGIWESSID, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWESSID] ssid = NULL, not connected"); //do not use perror
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWESSID] ssid = NULL, not connected"); //do not use perror
         ret = -1;
     } else {
         ret = iwr.u.essid.length;
@@ -65,7 +71,7 @@
     iwr.u.essid.flags = (ssid_len != 0);
 
     if (iw_ioctl(ifname, SIOCSIWESSID, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWESSID] error");
         ret = -1;
     }
 
@@ -86,7 +92,7 @@
     }
 
     if (iw_ioctl(ifname, SIOCSIWAP, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWAP] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWAP] error");
         ret = -1;
     }
 
@@ -108,7 +114,7 @@
     iwr.u.param.value = value;
 
     if (iw_ioctl(ifname, SIOCSIWAUTH, &iwr) < 0) {
-		printf("\n\rWEXT: SIOCSIWAUTH(param %d value 0x%x) failed)", idx, value);
+		WIFI_UTIL_MSG("\n\rWEXT: SIOCSIWAUTH(param %d value 0x%x) failed)", idx, value);
     }
 
     return ret;
@@ -162,7 +168,7 @@
 
     if (iw_ioctl(ifname, SIOCSIWENCODEEXT, &iwr) < 0) {
         ret = -2;
-        printf("\n\rioctl[SIOCSIWENCODEEXT] set key fail");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWENCODEEXT] set key fail");
     }
 
     rtw_free(ext);
@@ -184,7 +190,7 @@
     iwr.u.encoding.pointer = ext;
 
     if (iw_ioctl(ifname, SIOCGIWENCODEEXT, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWENCODEEXT] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWENCODEEXT] error");
         ret = -1;
 	}
 	else
@@ -213,7 +219,7 @@
     iwr.u.passphrase.flags = (passphrase_len != 0);
 
     if (iw_ioctl(ifname, SIOCSIWPRIVPASSPHRASE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWESSID+0x1f] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWESSID+0x1f] error");
         ret = -1;
     }
 
@@ -229,7 +235,7 @@
     iwr.u.passphrase.pointer = (void *) passphrase;
 
     if (iw_ioctl(ifname, SIOCGIWPRIVPASSPHRASE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWPRIVPASSPHRASE] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWPRIVPASSPHRASE] error");
         ret = -1;
     }
     else {
@@ -292,7 +298,7 @@
     iwr.u.data.length = pindex;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error");
         ret = -1;
     }
 
@@ -330,7 +336,7 @@
     iwr.u.data.length = pindex;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error");
         ret = -1;
     }
 
@@ -367,7 +373,7 @@
     iwr.u.data.length = pindex;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error");
         ret = -1;
     }
 
@@ -400,7 +406,7 @@
     iwr.u.data.length = pindex;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error");
         ret = -1;
     }
 
@@ -434,7 +440,7 @@
     iwr.u.data.length = pindex;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error");
         ret = -1;
         goto exit;
     }
@@ -443,7 +449,7 @@
     if((para[0]==3)&&(para[1]==1))
         *lps_dtim = para[2];
     else
-        printf("\n\r%s error", __func__);
+        WIFI_UTIL_MSG("\n\r%s error", __func__);
 
 exit:
     rtw_free(para);
@@ -492,7 +498,7 @@
     iwr.u.data.length = cmd_len + 4;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_set_tos_value():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_set_tos_value():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
 
@@ -518,7 +524,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = cmd_len + 20;
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_get_tx_power():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_get_tx_power():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
 
@@ -577,7 +583,7 @@
     memset(&iwr, 0, sizeof(iwr));
     iwr.u.mode = mode;
     if (iw_ioctl(ifname, SIOCSIWMODE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWMODE] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWMODE] error");
         ret = -1;
     }
 
@@ -592,7 +598,7 @@
     memset(&iwr, 0, sizeof(iwr));
 
     if (iw_ioctl(ifname, SIOCGIWMODE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWMODE] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWMODE] error");
         ret = -1;
     }
     else
@@ -612,7 +618,7 @@
     iwr.u.essid.flags = (ssid_len != 0);
 
     if (iw_ioctl(ifname, SIOCSIWPRIVAPESSID, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error");
         ret = -1;
     }
 
@@ -629,7 +635,7 @@
     iwr.u.param.value = country_code;
 
     if (iw_ioctl(ifname, SIOCSIWPRIVCOUNTRY, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWPRIVCOUNTRY] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVCOUNTRY] error");
         ret = -1;
     }
     return ret;
@@ -643,7 +649,7 @@
     memset(&iwr, 0, sizeof(iwr));
 
     if (iw_ioctl(ifname, SIOCGIWSENS, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWSENS] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWSENS] error");
         ret = -1;
     } else {
         *rssi = 0 - iwr.u.sens.value;
@@ -675,7 +681,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = (length + length + 1) + 12;
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_set_pscan_channel():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_set_pscan_channel():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
     rtw_free(para);
@@ -692,7 +698,7 @@
     iwr.u.freq.i = ch;
 
     if (iw_ioctl(ifname, SIOCSIWFREQ, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWFREQ] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWFREQ] error");
         ret = -1;
     }
 
@@ -707,7 +713,7 @@
     memset(&iwr, 0, sizeof(iwr));
 
     if (iw_ioctl(ifname, SIOCGIWFREQ, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWFREQ] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWFREQ] error");
         ret = -1;
     }
     else
@@ -754,7 +760,7 @@
     iwr.u.data.flags = flags;
     iwr.u.data.length = buf_len;
     if (iw_ioctl(ifname, SIOCSIWSCAN, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWSCAN] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWSCAN] error");
         ret = -1;
     }
     return ret;
@@ -768,7 +774,7 @@
     iwr.u.data.pointer = buf;
     iwr.u.data.length = buf_len;
     if (iw_ioctl(ifname, SIOCGIWSCAN, &iwr) < 0) {
-        printf("\n\rioctl[SIOCGIWSCAN] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCGIWSCAN] error");
         ret = -1;
     }else
         ret = iwr.u.data.flags;
@@ -786,7 +792,7 @@
         buf_size = strlen(cmd) + 1;    // 1 : '\0'
     buf = (char*)rtw_malloc(buf_size);
     if(!buf){
-        printf("\n\rWEXT: Can't malloc memory");
+        WIFI_UTIL_MSG("\n\rWEXT: Can't malloc memory");
         return -1;
     }
     memset(buf, 0, buf_size);
@@ -797,7 +803,7 @@
     iwr.u.data.flags = 0;
 
     if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) {
-        printf("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
+        WIFI_UTIL_MSG("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
     }
     if(ret_buf){
         if(ret_len > iwr.u.data.length)
@@ -830,7 +836,7 @@
         buf_size = strlen(cmd) + 1;    // 1 : '\0'
     buf = (char*)rtw_malloc(buf_size);
     if (!buf) {
-        printf("\n\rWEXT: Can't malloc memory");
+        WIFI_UTIL_MSG("\n\rWEXT: Can't malloc memory");
         return -1;
     }
     memset(buf, 0, buf_size);
@@ -841,12 +847,12 @@
     iwr.u.data.flags = 0;
 
     if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) {
-        printf("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
+        WIFI_UTIL_MSG("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
     }
     if (show_msg && iwr.u.data.length) {
         if(iwr.u.data.length > buf_size)
-            printf("\n\rWEXT: Malloc memory is not enough");
-        printf("\n\rPrivate Message: %s", (char *) iwr.u.data.pointer);
+            WIFI_UTIL_MSG("\n\rWEXT: Malloc memory is not enough");
+        WIFI_UTIL_MSG("\n\rPrivate Message: %s", (char *) iwr.u.data.pointer);
     }
     rtw_free(buf);
     return ret;
@@ -924,7 +930,7 @@
     iwr.u.data.length = buf_len;
     iwr.u.data.flags = flags;
     if (iw_ioctl(ifname, SIOCSIWEAPOLSEND, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWEAPOLSEND] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWEAPOLSEND] error");
         ret = -1;
     }
     return ret;
@@ -940,7 +946,7 @@
     iwr.u.data.length = buf_len;
     iwr.u.data.flags = flags;
     if (iw_ioctl(ifname, SIOCSIWMGNTSEND, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWMGNTSEND] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWMGNTSEND] error");
         ret = -1;
     }
     return ret;
@@ -956,7 +962,7 @@
     iwr.u.data.length = buf_len;
     iwr.u.data.flags = flags;
     if (iw_ioctl(ifname, SIOCSIWGENIE, &iwr) < 0) {
-        printf("\n\rioctl[SIOCSIWGENIE] error");
+        WIFI_UTIL_MSG("\n\rioctl[SIOCSIWGENIE] error");
         ret = -1;
     }
     return ret;
@@ -984,7 +990,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = (4) + cmd_len;
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_set_autoreconnect():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_set_autoreconnect():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
     rtw_free(para);
@@ -1008,7 +1014,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = cmd_len;
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_get_autoreconnect():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_get_autoreconnect():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
 	*mode = *(__u8 *)(iwr.u.data.pointer);
@@ -1037,7 +1043,7 @@
 	__u8 *para = NULL;
     int cmd_len = 0;
     if(ie_num <= 0 || !cus_ie){
-        printf("\n\rwext_add_custom_ie():wrong parameter");
+        WIFI_UTIL_MSG("\n\rwext_add_custom_ie():wrong parameter");
         ret = -1;
         return ret;
     }
@@ -1056,7 +1062,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = (4)* 2 + cmd_len;// 2 input
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_add_custom_ie():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_add_custom_ie():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
     rtw_free(para);
@@ -1071,7 +1077,7 @@
 	__u8 *para = NULL;
     int cmd_len = 0;
     if(ie_index <= 0 || !cus_ie){
-        printf("\n\rwext_update_custom_ie():wrong parameter");
+        WIFI_UTIL_MSG("\n\rwext_update_custom_ie():wrong parameter");
         ret = -1;
         return ret;
     }
@@ -1090,7 +1096,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = (4)* 2 + cmd_len;// 2 input
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_update_custom_ie():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_update_custom_ie():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
     rtw_free(para);
@@ -1115,7 +1121,7 @@
     iwr.u.data.pointer = para;
     iwr.u.data.length = cmd_len;
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_del_custom_ie():ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_del_custom_ie():ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
     rtw_free(para);
@@ -1148,7 +1154,7 @@
     iwr.u.essid.length = cmd_len + 1;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_enable_forwarding(): ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_enable_forwarding(): ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
 
@@ -1176,7 +1182,7 @@
     iwr.u.essid.length = cmd_len + 1;
 
     if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
-        printf("\n\rwext_disable_forwarding(): ioctl[SIOCDEVPRIVATE] error");
+        WIFI_UTIL_MSG("\n\rwext_disable_forwarding(): ioctl[SIOCDEVPRIVATE] error");
         ret = -1;
     }
 
@@ -1260,7 +1266,7 @@
 
     mf_list_head = (struct list_head *)rtw_malloc(sizeof(struct list_head));
     if(mf_list_head == NULL){
-        printf("\n\r[ERROR] %s : can't allocate mf_list_head",__func__);
+        WIFI_UTIL_MSG("\n\r[ERROR] %s : can't allocate mf_list_head",__func__);
         return -1;
     }
 
@@ -1298,7 +1304,7 @@
 	rtw_mac_filter_list_t *mf_list_new;
     mf_list_new = (rtw_mac_filter_list_t *)rtw_malloc(sizeof(rtw_mac_filter_list_t));
     if(mf_list_new == NULL){
-        printf("\n\r[ERROR] %s : can't allocate mf_list_new",__func__);
+        WIFI_UTIL_MSG("\n\r[ERROR] %s : can't allocate mf_list_new",__func__);
         return -1;
     }
     memcpy(mf_list_new->mac_addr,hwaddr,6);