Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發實例 >> Realtek 8192cu 支持 Android Hotspot

Realtek 8192cu 支持 Android Hotspot

編輯:Android開發實例

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
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved