android之wifi移植全過程(二)

6、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模塊鏈接網絡。
相關文章
相關標籤/搜索