Explorar el Código

update: AP地址需要兼容AT固件

1. 工厂是通过AT固件写入AP地址的
2. 只写入了AP地址, 没有写入STA地址

策略:
1. 检测到AP合法但STA不合法,使用AP覆盖到STA
2. 如果STA也不合法, 从UNIQUE_ID生成MAC
3. AP地址需要强行覆盖到hostapd的mac指针,该操作需要在wpa_supplicant_init之后, ap创建之前执行
Wendal Chen hace 2 años
padre
commit
c14e73f949
Se han modificado 3 ficheros con 50 adiciones y 12 borrados
  1. 28 3
      app/main.c
  2. 18 8
      app/network/luat_wlan_air101.c
  3. 4 1
      platform/drivers/efuse/wm_efuse.c

+ 28 - 3
app/main.c

@@ -174,6 +174,18 @@ void UserMain(void){
 #endif
 
 
+#ifdef LUAT_USE_WLAN
+	u8 tmpmac[8] = {0};
+	tls_ft_param_get(CMD_WIFI_MACAP, tmpmac, 6);
+	extern u8 *hostapd_get_mac(void);
+	u8* macptr = hostapd_get_mac();
+	//LLOGD("default AP MAC %02X:%02X:%02X:%02X:%02X:%02X", macptr[0], macptr[1], macptr[2], macptr[3], macptr[4], macptr[5]);
+	memcpy(macptr, tmpmac, 6);
+	LLOGD("AP MAC %02X:%02X:%02X:%02X:%02X:%02X", macptr[0], macptr[1], macptr[2], macptr[3], macptr[4], macptr[5]);
+	tls_ft_param_get(CMD_WIFI_MACAP, tmpmac, 6);
+	LLOGD("STA MAC %02X:%02X:%02X:%02X:%02X:%02X", macptr[0], macptr[1], macptr[2], macptr[3], macptr[4], macptr[5]);
+#endif
+
 
 // 如要使用psram,启用以下代码,并重新编译sdk
 #ifdef LUAT_USE_PSRAM
@@ -227,6 +239,7 @@ void sys_mac_init() {
 	luat_log_set_uart_port(1);
 #endif
     u8 mac_addr[6] = {0};
+	u8 ap_mac[6] = {0};
     char unique_id [20] = {0};
     tls_fls_read_unique_id(unique_id);
 	int ret = 0;
@@ -250,11 +263,12 @@ void sys_mac_init() {
 #endif
 
 #ifdef LUAT_USE_WLAN
-	ret = tls_get_mac_addr(mac_addr);
+	ret = tls_ft_param_get(CMD_WIFI_MAC, mac_addr, 6);
+	tls_ft_param_get(CMD_WIFI_MACAP, ap_mac, 6);
 	LLOGD("tls_get_mac_addr ret %d %02X%02X%02X%02X%02X%02X", ret, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
     int mac_ok = 1;
     if (!memcmp(mac_addr, default_mac, 6)) {
-        mac_ok = 0; // 0C0B47011078
+        mac_ok = 0;
     }
     else {
         mac_ok = 1;
@@ -265,8 +279,14 @@ void sys_mac_init() {
                 break;
             }
         }
-        
     }
+	if (!mac_ok) {
+		tls_ft_param_get(CMD_WIFI_MACAP, ap_mac, 6);
+		if (memcmp(ap_mac, default_mac, 6)) {
+       		mac_ok = 1;
+			tls_set_mac_addr(ap_mac);
+    	}
+	}
 	if (!mac_ok) { // 看来是默认MAC, 那就改一下吧
 		if (unique_id[1] == 0x10){
 			memcpy(mac_addr, unique_id + 12, 6);
@@ -285,6 +305,11 @@ void sys_mac_init() {
         
         tls_set_mac_addr(mac_addr);
 	}
+	if (!memcmp(ap_mac, default_mac, 6)) {
+		memcpy(ap_mac, mac_addr, 6);
+		tls_ft_param_get(CMD_WIFI_MACAP, ap_mac, 6);
+	}
+
     // printf("WIFI %02X:%02X:%02X:%02X:%02X:%02X\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
 #endif
 }

+ 18 - 8
app/network/luat_wlan_air101.c

@@ -277,22 +277,32 @@ int luat_wlan_smartconfig_stop(void) {
 
 // 数据类
 int luat_wlan_get_mac(int id, char* mac) {
-    (void)id;
-    tls_get_mac_addr((u8*)mac);
+    if (id == 0)
+        tls_get_mac_addr((u8*)mac);
+    else
+        tls_ft_param_get(CMD_WIFI_MACAP, mac, 6);
     return 0;
 }
 
 int luat_wlan_set_mac(int id, const char* mac_addr) {
-    (void)id;
     u8 mac[8] = {0};
-    if (tls_get_mac_addr(mac) == 0 && memcmp(mac_addr, mac, 6) == 0) {
+    int ret = 0;
+    if (id == 0) {
+        tls_get_mac_addr(mac);
+    }
+    else {
+        tls_ft_param_get(CMD_WIFI_MACAP, mac, 6);
+    }
+    if (memcmp(mac_addr, mac, 6) == 0) {
         // 完全相同, 不需要设置
         return 0;
     }
-    // LLOGD("set mac %02X%02X%02X%02X%02X%02X", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
-    int ret = tls_set_mac_addr((u8*)mac_addr);
-    if (ret)
-        LLOGD("tls_set_mac_addr %d", ret);
+    if (id == 0) {
+        ret = tls_set_mac_addr(mac);
+    }
+    else {
+        ret = tls_ft_param_set(CMD_WIFI_MACAP, mac, 6);
+    }
     return ret;
 }
 

+ 4 - 1
platform/drivers/efuse/wm_efuse.c

@@ -347,9 +347,12 @@ int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
 			memcpy((unsigned char *)&gftParamVer1.ft_ext1.adc_cal_param, data, len);
 		break;
 		
-		case CMD_WIFI_MAC:	/*MAC*/
+		case CMD_WIFI_MAC:	/*STA MAC*/
 			memcpy(gftParam->wifi_mac_addr, (unsigned char *)data, len);
 		break;
+		case CMD_WIFI_MACAP:	/*AP MAC*/
+			memcpy(gftParam->wifi_macap_addr, (unsigned char *)data, len);
+		break;
 
 		case CMD_BT_MAC:	/*BT MAC*/
 			memcpy(gftParam->bt_mac_addr, (unsigned char *)data, len);