android2.3 wifi

来源:互联网 发布:淘宝二手自行车怎么样 编辑:程序博客网 时间:2024/06/05 16:14
谨为调试记录。
1. 在\device\samsung\smdkv210\BoardConfig.mk中添加:

#wifi
BOARD_WIFI_LIBRARIES := true
WPA_BUILD_SUPPLICANT := true
BOARD_WPA_SUPPLICANT_DRIVER := WEXT
CONFIG_CTRL_IFACE := y
DRIVER_BUILT_IN := true
WPA_SUPPLICANT_VERSION := VER_0_5_X

2.\device\samsung\smdkv210\init.rc

添加wpa_supplicant启动服务:

service wpa_supplicant /system/bin/wpa_supplicant -Dwext -iwlan0 -c /data/misc/wifi/wpa_supplicant.conf
    socket wpa_wlan0 dgram 0666 wifi wifi
    disabled
    oneshot

service dhcpcd /system/bin/logwrapper /system/bin/dhcpcd -o domain_name_servers -ABKL
     disabled
     oneshot
     group system dhcp

on property:init.svc.wpa_supplicant=stopped
     stop dhcpcd

3.\external\wpa_supplicant\Android.mk

将以下的注释去掉,修改成如下:
local_target_dir := $(TARGET_OUT)/etc/wifi
include $(CLEAR_VARS)
LOCAL_MODULE := wpa_supplicant.conf
LOCAL_MODULE_TAGS := user
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(local_target_dir)
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

修改此处后编译,在/system/etc/下才会生成有wifi/wpa_supplicant.conf。

4.\hardware\libhardware_legacy\wifi\wifi.c

需修改三个函数,相关修改如下:

int wifi_load_driver()
{
#if 0    //驱动已经编译进内核,无需再加载
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (check_driver_loaded()) {
        return 0;
    }

    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
        return -1;

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
        usleep(WIFI_DRIVER_LOADER_DELAY);
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0)
                return 0;
            else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else   // 直接把wlan.driver.status状态设置为ok状态
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}

int wifi_unload_driver()
{
#if 0   // 无需卸载驱动
   int count = 20; /* wait at most 10 seconds for completion */

    if (rmmod(DRIVER_MODULE_NAME) == 0) {
     while (count-- > 0) {
         if (!check_driver_loaded())
          break;
             usleep(500000);
     }
     if (count) {
             return 0;
     }
     return -1;
    } else
        return -1;

#else   //直接把驱动状态设置为已卸载
    property_set(DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif      
}

int wifi_connect_to_supplicant()
{
    char ifname[256];
    char supp_status[PROPERTY_VALUE_MAX] = {'\0'};

    /* Make sure supplicant is running */
    if (!property_get(SUPP_PROP_NAME, supp_status, NULL)
            || strcmp(supp_status, "running") != 0) {
        LOGE("Supplicant not running, cannot connect");
        return -1;
    }

    property_get("wifi.interface", iface, WIFI_TEST_INTERFACE);

   // if (access(IFACE_DIR, F_OK) == 0) {  //wifi接口直接设置为wlan0即可
    //    snprintf(ifname, sizeof(ifname), "%s/%s", IFACE_DIR, iface);
   // } else {
        strlcpy(ifname, iface, sizeof(ifname));
   // }

编译烧写后,打开wifi,能扫描到wifi热点,但是在连接wifi的时候总是在提示正在获取IP地址后又显示disconnect了。
查看log:

D/WifiStateTracker(   80): DhcpHandler: DHCP request started
E/dhcpcd  (  686): read_interface: No such device
I/logwrapper(  685): /system/bin/dhcpcd terminated by exit(0)
I/wpa_supplicant(  433): CTRL-EVENT-SCAN-RESULTS  Ready
I/wpa_supplicant(  433): CTRL-EVENT-SCAN-RESULTS  Ready
D/dalvikvm(  425): GC_CONCURRENT freed 516K, 49% free 3253K/6279K, external 1239K/1751K, paused 2ms+3ms
I/WifiStateTracker(   80): DhcpHandler: DHCP request failed: Timed out waiting for dhcpcd to start
I/wpa_supplicant(  433): CTRL-EVENT-STATE-CHANGE id=0 state=8
V/WifiMonitor(   80): Event [CTRL-EVENT-STATE-CHANGE id=0 state=8]
V/WifiStateTracker(   80): Changing supplicant state: COMPLETED ==> DORMANT
D/WifiStateTracker(   80): Reset connections and stopping DHCP
D/WifiStateTracker(   80): Disabling interface
E/ConnectivityService(   80): Attempt to connect to WIFI failed.

初步分析是在分配IP的时候找不到wlan0接口,就是没能识别得到。故可在init.rc中直接setprop设置wifi接口。
故还需做如下补充。
5. device\samsung\smdkv210\init.rc

    setprop wifi.interface wlan0
    setprop wlan.interface wlan0
    setprop wlan.driver.status ok
原创粉丝点击