Realtek 8192cu 支持 Android Hotspot

Android 2.2 开始增加了WiFi Hotspot,可将Android设备作为无线热点、向其他WiFi设备共享网络连接,参考 Sharing your mobile data connection

前面,我将 Realtek 8192cu 驱动移植到 Android 2.2。Realtek 8192cu 驱动包中也包含了一个 hostapd 的实现以及Android SoftapController实现,通过以下步骤,可以在Android上实现SoftAP

1、在init.rc中增加hostapd服务

service hostapd /system/bin/hostapd_wps /data/misc/wifi/hostapd.conf
group wifi inet
disabled
oneshot

2、移植Realtek的hostapd实现

将驱动包中的external\hostapd-0.6.9_rtl 复制到Android 的external/ 目录下。需要修改 external/hostapd-0.6.9_rtl/hostapd/Android.mk,在文件接近末尾处,增删如下所示的几行

OBJS_c = hostapd/hostapd_cli.c src/common/wpa_ctrl.c src/utils/os_$(CONFIG_OS).c
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd_cli
#LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS_c))
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)

OBJS_c = hostapd/hostapd_wps.c
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd_wps
#LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS_c))
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_MODULE := hostapd
#LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_SHARED_LIBRARIES += $(LIBS)
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS))
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)

local_target_dir := $(TARGET_OUT)/etc/wifi
include $(CLEAR_VARS)
LOCAL_MODULE := hostapd.conf
#LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(local_target_dir)
LOCAL_SRC_FILES := hostapd$(HOSTAPD_VER)/hostapd/hostapd.conf.android
include $(BUILD_PREBUILT)

OBJS_c = src/common/wpa_ctrl.c src/utils/os_$(CONFIG_OS).c
include $(CLEAR_VARS)
LOCAL_MODULE = libhostapd_client
LOCAL_PRELINK_MODULE := false
#LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS = $(L_CFLAGS)
LOCAL_SRC_FILES := $(addprefix hostapd$(HOSTAPD_VER)/,$(OBJS_c))
LOCAL_C_INCLUDES = $(INCLUDES)
LOCAL_SHARED_LIBRARIES := libc libcutils
LOCAL_COPY_HEADERS_TO := libhostapd_client
LOCAL_COPY_HEADERS := hostapd$(HOSTAPD_VER)/src/common/wpa_ctrl.h
include $(BUILD_SHARED_LIBRARY

3、移植Realtek的SoftapController实现

将Realtek驱动包中system\netd\ 目录下的Android.mk、SoftapController_realtek.cpp 2个文件复制/覆盖到 Android 源码 system/netd/ 目录下

修改 Android 源码 frameworks/base/core/res/res/values/config.xml 文件,找到下面2个字符串数组,分别增加如下几个item:

    <!-- List of regexpressions describing the interface (if any) that represent tetherable
Wifi interfaces. If the device doesn't want to support tethering over Wifi this
should be empty. An example would be "softap.*"
-->
<string-array translatable="false" name="config_tether_wifi_regexs">
<item>"wlap0"</item>
</string-array>

<!-- Regex array of allowable upstream ifaces for tethering - for example if you want
tethering on a new interface called "foo2" add <item>"foo\\d"</item> to the array
-->
<string-array translatable="false" name="config_tether_upstream_regexs">
<item>"ppp\\d"</item>
<item>"eth\\d"</item>
<item>"wlan\\d"</item>
</string-array>


Android运行后,通过Settings->Wireless & Networks->Portable hotspot 启用“Portable Wi-Fi hotspot”,并可通过 Portable Wi-Fi hotspot settings->Configure Wi-Fi hotspot 设置SSID、安全性等。我这边看到支持Open、WPA2 PSK 2种安全选项

Hotspot启动后,其它WiFi设备就可以连接上来

android.net.wifi.WifiManager 类有几个关于SoftAP的隐藏接口,应用程序可以通过反射来调用:

  • isWifiApEnabled
  • setWifiApEnabled
  • getWifiApState
  • getWifiApConfiguration
  • setWifiApConfiguration




posted on 2011-10-15 22:02  bye_passer  阅读(5567)  评论(0编辑  收藏  举报

导航