android之wifi移植全过程(二)

2013/09/06 10:38
阅读数 2.5K
六、android的wifi移植。
     现在底层的都通了,接下来就把wifi移植到android系统中。
     1.提供固件firmware给驱动。
        WIFI需要的firmware要复制到/etc/firmware。   或者复制到WIFI驱动指定的位置,然后WIFI驱动会自动加载。
        在此把wifi模块提供的sd8686.bin sd8686_helper.bin放到out/target/product/fs100/system/etc/firmware目录下。
        其实,和上面放目录是一样的。
    
     2.修改自己定制的BoardConfig.mk,使能wpa_supplicant。
       修改vendor/farsight/fs100/BoardConfig.mk:                                                       
          把BOARD_WPA_SUPPLICANT_DRIVER :=true                                                          
          改为BOARD_WPA_SUPPLICANT_DRIVER := WEXT                                                                                                                                                
          目的是:把driver_wext.c作为wpa_supplicant的driver。wpa_supplicant通过它去与内核的wifi驱动打交道。
       修改external/wpa_supplicant/Android.mk                                                           
           把WPA_BUILD_SUPPLICANT :=false                                                               
           改为WPA_BUILD_SUPPLICANT := true                                                         
          默认使用驱动driver_wext.c。                                                                   
          如果使用定制的wpa_supplicant驱动(例如 madwifi),可以设置:                                     
          BOARD_WPA_SUPPLICANT_DRIVER := MADWIFI
           
                                                                  
      3.使wpa_supplicant打印更多的调试信息
    wpa_supplicant默认信息显示的等级为SG_INFO,为了输出更多信息,可修改: 
        修改external/wpa_supplicant/common.c                                  
            把int wpa_debug_level = MSG_INFO;                                 
            改为:int wpa_debug_level = MSG_DEBUG;                            
        修改external/wpa_supplicant/common.h                                  
            把宏定义#define wpa_printf(level, ...)中的if ((level) >= MSG_INFO)
            改为if ((level) >= MSG_DEBUG)
      4.提供一个合适的wpa_supplicant.conf
        修改 wpa_supplicant.conf:                                                                                                                 
           把external/wpa_supplicant/wpa_supplicant.conf拷贝到out/target/product/fs100/system/etc/wifi/目录下,
           并把:ctrl_interface=DIR=/data/misc/wifi/wpa_supplicant GROUP=wifi                                 
           改为:                                                                                             
           ctrl_interface=wlan0                                                                               
      5.修改init.rc配置路径和权限
        A)配置init.rc文件修改out/target/product/fs100/root/init.rc, 让wifi用户拥有相关的权限,
          在 #give system access to wpa_supplicant.conf for backup and restore后面增加:
             #add by liyulei 2011-11-19                                                                                                                       
             mkdir /data/misc/wifi/sockets 0777 wifi wifi                                                                                                           
        chown wifi wifi /data/misc/wifi                                                                                                                   
             chown wifi wifi /data/misc/wifi/wpa_supplicant.conf                                                                                                           
             #for dhcp                                                                                                                                      
             mkdir /data/misc/dhcp 0777 dhcp dhcp                                                                                                    
             chmod 0770 /data/misc/dhcp                                                                                                             
             #end add                                                                                                                                                      
        B)注释原有环境变量#export PATH
          改 为:                                                                                                                             
         export PATH /sbin:/system/sbin:/system/bin:/system/xbin                                                                                       
          #above modified by liyulei 2011-11-19                                                                                                                            
      6. 确保wpa_supplicant和dhcpcd是通过init.c起来的。
         配置init.rc文件修改out/target/product/fs100/root/init.rc, 在末尾添加:                                       
             #add by liyulei 2011-11-19
             for wifi Android private socket                                             
             service wpa_supplicant /system/bin/wpa_supplicant -dd -Dwext -iwlan0 -c/system/etc/wifi/wpa_supplicant.conf
                     socket wpa_wlan0 dgram 660 wifi wifi                              
                     group system wifi inet                                                   
                     disabled                                                              
                     oneshot                                                                
             #for dhcp                                                                          
             service dhcpcd /system/bin/dhcpcd wlan0                                          
                     group system dhcp                                                           
                     disabled                                                                           
                     oneshot                                                                       
             #end add。                                                                                                
   7.设置驱动以模块方式加载
   拷贝内核生成的drivers/net/wireless/libertas/libertas_sdio驱动模块
   到out/target/product/fs100/system/lib/modules/目录下。
   然后修改hardware/libhardware_legacy/wifi/wifi.c                                                                       
          1)修改wifi.c中的宏:
             #define WIFI_DRIVER_MODULE_PATH            "/system/lib/modules/libertas_sdio.ko"                                                            
             #define WIFI_DRIVER_MODULE_NAME            "libertas_sdio"                                                                                       
             #define WIFI_TEST_INTERFACE              "wlan0" 
          或者,也可以这样改:
            修改vendor/farsight/fs100/BoardConfig.mk:
              WIFI_DRIVER_MODULE_PATH  ="/system/lib/modules/libertas_sdio.ko"                                                            
              WIFI_DRIVER_MODULE_NAME  ="libertas_sdio"                                                                                       
              WIFI_TEST_INTERFACE     ="wlan0" 
            和上面一样的效果。
                                                                                                           
      8.添加休眠唤醒代码:
      1)在frameworks\base\core\Jni\android_net_wifi_Wifi.cpp中添加相应的休眠唤醒函数:
      在static JNINativeMethod gWifiMethods[]结构体添加方法:
      {"moduleWakeupStatus","()Z",(void*)android_net_wifi_moduleWakeupStatus},
      {"WaitTime","(I)Z",(void*)android_net_wifi_WaitTime},
      并实现这些方法/*add by liyulei 2011-11-20*/                                                      
          static jboolean android_net_wifi_moduleWakeupStatus(JNIEnv* env, jobject clazz)  
        {                                                                                  
         return (jboolean)(::wifi_module_wakeup_status() == 0);                            
        }                                                                                  
        static jboolean android_net_wifi_WaitTime(JNIEnv* env, jobject clazz, jint waittime)
        {                                                                                  
         return (jboolean)(::wifi_module_wait_time(waittime) == 0);                       
        }                                                                                  
        /*end add by liyulei*/ 
       
        2)而相应的细体实现在wifi.c中:
         在wifi.c添加:                                                           
           /*add by caoyi 2011-10-20*/              
           int wifi_module_wakeup_status()          
              {                                     
                    return 1;                       
              }                                     
              int wifi_module_wait_time(int watiTime)    
             {                                           
                sleep(watiTime);                        
                   return  0;                                                                                                                                                    
              }                                     
           /*end add*/                              
     
      9.配置dhcpcd.conf
        修改源码目录下external/dhcpcd下的Android.mk文件
    取消注释
       -->26  include $(CLEAR_VARS)
       -->27 LOCAL_MODULE := dhcpcd.conf
       -->28 LOCAL_MODULE_TAGS := user
       -->29 LOCAL_MODULE_CLASS := ETC
       -->30 LOCAL_MODULE_PATH := $(etc_dir)
       -->31 LOCAL_SRC_FILES := android.conf
       -->32 include $(BUILD_PREBUILT)  
       然后重新编译mm,将编译产生的dhcpcd.conf放置到文件系统的目录system/etc/dhcpcd/dhcpcd.conf
        最后确定dhcpcd.conf内容有:
       interface wlan0
       option subnet_mask, routers, domain_name_servers
       option ntp_servers 
       没有的话,就修改。
         
      10.修改WifiStateTracker.java
       将frameworks/base/wifi/java/android/net/wifi/WifiStateTracker.java 里的mInterfaceName = SystemProperties.get("wifi.interface", "eth0");
       改为:
       mInterfaceName = SystemProperties.get("wifi.interface", "wlan0");
       最后重新编译mm
       编译镜像文件后烧写到开发板上就可以使用WiFi模块连接网络。
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部