MTK平台固定WIFI地址

可以在工模WIFI测试中添加以下patch

Index: vendor/mediatek/proprietary/factory/src/factory.cpp
===================================================================
--- vendor/mediatek/proprietary/factory/src/factory.cpp (revision 668)
+++ vendor/mediatek/proprietary/factory/src/factory.cpp (revision 669)
@@ -72,6 +72,7 @@
 
 #define MAX_RETRY_COUNT 20
 #define MAX_MODEM_INDEX 3
+extern "C" int write_wifi_addr(void);
 
 static item_t ftm_menu_items[] = {
     //item(ITEM_MUI_TEST,"Mini-UI Test"),
@@ -375,6 +376,99 @@
 }
 //tony end
 #endif
+
+static void GetRandomValue(unsigned char   string[6]);
+static void GetRandomValue(unsigned char  string[6])
+{
+    int iRandom = 0;
+    int fd = 0;
+    unsigned long seed;
+    
+    LOGD("Enable random generation\n");
+    
+    /* initialize random seed */
+    srand (time(NULL));
+    iRandom = rand();
+    LOGD("iRandom = [%d]", iRandom);
+    string[0] = (((iRandom>>24|iRandom>>16) & (0xFE)) | (0x02)); /* must use private bit(1) and no BCMC bit 0 */
+    string[0] =0x80;
+    /* second seed */
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    srand (tv.tv_usec);
+    iRandom = rand();
+    LOGD("iRandom = [%d]", iRandom);
+    string[1] = ((iRandom>>8) & 0xFF);
+     string[1] = 0x0c;
+    
+    /* third seed */
+    fd = open("/dev/urandom", O_RDONLY);
+    if (fd > 0){
+        if (read(fd, &seed, sizeof(unsigned long)) > 0){
+            srand (seed);
+            iRandom = rand();
+        }
+        close(fd);
+    }
+    
+    LOGD("iRandom = [%d]", iRandom);
+    string[5] = (iRandom & 0xFF);
+    
+    return;
+}
+
+static int WriteBDAddrToNvram(unsigned char  * ucBDAddr)
+{
+    F_ID wifi_nvram_fd = {0};
+    int rec_size = 0;
+    int rec_num = 0;
+    wifi_nvram_fd = NVM_GetFileDesc(AP_CFG_RDEB_FILE_WIFI_LID, &rec_size, &rec_num, ISWRITE);
+    if(wifi_nvram_fd.iFileDesc < 0){
+        LOGE("Open WIFI NVRAM fails errno %d\n", errno);
+        return -1;
+    }
+    
+    if(rec_num != 1){
+        LOGE("Unexpected record num %d\n", rec_num);
+        NVM_CloseFileDesc(wifi_nvram_fd);
+        return -1;
+    }
+    
+    if(rec_size != sizeof(WIFI_CFG_PARAM_STRUCT)){
+        LOGE("Unexpected record size %d ap_nvram_btradio_mt6610_struct %d\n",
+                 rec_size, sizeof(WIFI_CFG_PARAM_STRUCT));
+        NVM_CloseFileDesc(wifi_nvram_fd);
+        return -1;
+    }
+    
+    lseek(wifi_nvram_fd.iFileDesc, 4, 0);
+    
+    /* Update BD address */
+    if (write(wifi_nvram_fd.iFileDesc, ucBDAddr, 6) < 0){
+        LOGE("Write WIFI NVRAM fails errno %d\n", errno);
+        NVM_CloseFileDesc(wifi_nvram_fd);
+        return -1;
+    }
+
+    NVM_CloseFileDesc(wifi_nvram_fd);
+    return  0;
+}
+
+int write_wifi_addr(void)
+{
+    unsigned char addr[6];     
+    GetRandomValue(addr);
+        WriteBDAddrToNvram(addr);
+    /*backup data to nv bin region */
+       if( FileOp_BackupToBinRegion_All())
+       {
+        LOGE("FileOp_BackupToBinRegion_All errno \n");
+        return -1;
+    }
+    return 0;
+}
+
 static int item_test_report(item_t *items, char *buf, int bufsz)
 {
 
Index: vendor/mediatek/proprietary/factory/src/test/ftm_wifi.c
===================================================================
--- vendor/mediatek/proprietary/factory/src/test/ftm_wifi.c (revision 668)
+++ vendor/mediatek/proprietary/factory/src/test/ftm_wifi.c (revision 669)
@@ -40,6 +40,8 @@
 #include "miniui.h"
 #include "ftm.h"
 
+extern int write_wifi_addr(void);
+
 #ifdef FEATURE_FTM_WIFI
 
 #define TAG                 "[FT_WIFI] "
@@ -277,7 +279,7 @@
     int curStatus = -1; //disconnect
 
     LOGD(TAG "%s new\n", __FUNCTION__);
-
+    write_wifi_addr();
     memset(&wififm->info[0], 0, sizeof(wififm->info));
     memset(&wififm->info[0], '\n', 10);
     



推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 105,085评论 12 126
  • 01 “哎……有没有什么暑假兼职推荐。” “投简历啊!” “工资太低了,又没有地方住。” “那你回家呀,做一条精致...
    一叶秋刀鱼阅读 164评论 1 1
  • 就叫帅小飞吧阅读 102评论 0 0
  • 小鲁有百草园,我也有,她的名字叫初夏微雨百草园。把新鲜的小花,轻轻剪下,养在有水的小玻璃瓶里,我又有了一个桌上小花...
    杰西卡武阅读 62评论 0 1
  • 适配器模式将一个类的接口,转化成客户期望的另一个接口,适配器让原本不兼容的类可以合作无闻。 适配器和proxy的区...
    freezml阅读 25评论 0 0