参考了一篇 Android 下移植WIFI 驱动 ,记录下来 。

英文原文 : http://blog.linuxconsulting.ro/2010/04/porting-wifi-drivers-to-android.html

1. android 中WIFI如何工作


3. 设置wpa_supplicant  使其可以debug

 默认情况 wpa_supplicant 设置为MSG_INFO ,不能告知很多信息

为了能够获得更多的信息 :

a. 修改common.c 设置 wpa_debug_level = MSG_DEBUG
b. 修改common.h  change #define wpa_printf from if ((level) >= MSG_INFO) to if ((level) >= MSG_DEBUG)

4. 为你的设备配置合适的wpa_supplicant.conf

因为此wpa_supplicant.conf 会为android 指定相应的 control socket(ctr_interface). 此文件应该通过 AndroidBoad.mk 复制到  $(TARGET_OUT_ETC)/wifi (通常是/system/etc/wifi/wpa_supplicant.conf )。此文件 位置会被 用在 来自 init.rc的 wpa_supplicant service。wpa_supplicant 可以被配置成两种不同的方式 :一个是 在 android namespace 中 使用private socket , 此socket 有 socket_local_client_connect()function in wpa_ctrl.c 创建;另一个是 使用 标准的 unix socket。注意 此


wpa_supplicant.conf 最低要求配置 :

--android private socket :

ctrl_interface = wlan0

update_config = 1

--- unix standed socket :

ctrl_interface = DIR = /data/system/wpa_supplicant GROUP = wifi

undate_config = 1


根据 自己的设备 有可能需要加上 : ap_scan = 1

如果 AP association  问题  应当 ap_scan = 0  以让 设备自己连接 而不是wpa_supplicant .

如果 希望 wpa_supplicant 连接到 non-WPA 或者 wireless networks  (默认情况跳过了 这些) 添加:

network = { key_mgmt = NONE}

5. 拥有从 init.rc 创建的 正确的权限 和 路径 

不正确的权限会导致 wpa_supplicant 不能够创建或打开 control socket 并且 连接不到 libhardware_legacy/wifi/wifi.c

或者 出现如下错误:

E/WifiHW  (  ): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": No such file or directory will appear.

由于Google 修改了wpa_supplicant  以wifi user/group 运行

同样 wpa_supplicant 应当 属于wifi user/group ,这是因为 wpa_supplicant 要修改这个文件,如果你的系统有 /system 却只有只读权限 ,

使用地址像 :data/misc/wifi/wpa_supplicant.conf 。(这个有些不明白 所以翻译也混乱。 原文:Also wpa_supplicant.conf should belong to wifi user/group because wpa_supplicant will want to modify this file. If your system has /system as read-only use a location like /data/misc/wifi/wpa_supplicant.conf and modify wpa_supplicant service in init.rc with new location. 
Make sure the paths are correctly created in init.rc:

give wpa_supplicant change root permission!

  修改在 init.rc 中  wpa_supplicant service 重新定位 确保 路径能够在init.rc 中 正确的创建。
例如:

mkdir /system/etc/wifi 0770 wifi wifi 
chmod 0770 /system/etc/wifi 
chmod 0660 /system/etc/wifi/wpa_supplicant.conf 
chown wifi wifi /system/etc/wifi/wpa_supplicant.conf 
#wpa_supplicant control socket for android wifi.c (android private socket) 
mkdir /data/misc/wifi 0770 wifi wifi 
mkdir /data/misc/wifi/sockets 0770 wifi wifi 
chmod 0770 /data/misc/wifi 
chmod 0660 /data/misc/wifi/wpa_supplicant.conf 
chown wifi wifi /data/misc/wifi 
chown wifi wifi /data/misc/wifi/wpa_supplicant.conf


如果使用 unix standard socket 则 添加:

# wpa_supplicant socket (unix socket mode) 
mkdir /data/system/wpa_supplicant 0771 wifi wifi 
chmod 0771 /data/system/wpa_supplicant 
chown wifi wifi /data/system/wpa_supplicant

注意如果使用android private socket  则 不要添加 unix standard socket , 如果加上了, hardware/libhardware_legacy/wifi/wifi.c check for existence of the /data/system/wpa_supplicant folder and will pass a wrong interface name towpa_ctrl_open() function. 而导致 wpa_supplicant 不起作用
6. 确保 wpa_supplicant and dhcpcd 起来了 (在init.rc 文件中)

For wpa_supplicant the init.rc startup like should be depending on which path you chosen: 
- 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 

- Unix standard socket: 

service wpa_supplicant /system/bin/wpa_supplicant -dd -Dwext -iwlan0 -c /system/etc/wifi/wpa_supplicant.conf 
group system wifi inet 
disabled 
oneshot

如果wifi driver 创建了另一个wifi interface with other name than wlan0, 相应的要修改上面的代码。


dhcpcd starting from init.rc 

service dhcpcd /system/bin/dhcpcd wlan0 
group system dhcp 
disabled 
oneshot

7. 编辑驱动 (以模块形式/编进内核形式)

首先确保  在kernel 中 CONFIG_PACKET and CONFIG_NET_RADIO (wireless extensions) 是 enabled

-- kernel module :

  Define in your BoardConfig.mk :

   1. WIFI_DRIVER_MODULE_PATH :=/system/lib/modules/wlan.ko " (path to the module to be loaded )
   2.  WIFI_DRIVER_MODULE_NAME:= " wlan0" (the name of the network interface that the driver creates)
   3. WIFI_DRIVER_MODULE_ARG:= "nohwcrypt" (any arguments that you want to pass to the driver on insmod)

-- build in kernel

      1)在hardware/libhardware_legacy/wifi/wifi.c要修改interface名字,
     2)在init.rc中添加:
        setprop wifi.interface "wlan0"
     3)在hardware/libhardware_legacy/wifi/wifi.c中当insmod/rmmod时,
        直接return 0。


到这发现已经有人 翻译过此篇文章,后面就不写了。

补充 :

设置dhcpcd.conf
  
  /system/etc/dhcpcd/dhcpcd.conf的配置为:
      interface wlan0
      option subnet_mask, routers, domain_name_servers  

更多相关文章

  1. Android(安卓)使用Okhttp进行文件下载
  2. android webview 使用以及一些异常处理及上传文件问题
  3. Android(安卓)开发调试工具的使用总结
  4. Cocos2d-x for android 使用Box2d报错解决
  5. 在Android模拟机上跑javaeye android 客户端
  6. Android(安卓)Launcher 如何去掉主菜单,所有应用摆在桌面,类似小米
  7. 箭头函数的基础使用
  8. NPM 和webpack 的基础使用
  9. Python list sort方法的具体使用

随机推荐

  1. 注册中心 Eureka 源码解析 —— StringCa
  2. 基于ssm框架实现民宿管理系统
  3. 【从0到1学习边缘容器系列-4】弱网环境利
  4. 分布式作业 Elastic-Job-Lite 源码分析
  5. 分布式作业系统 Elastic-Job-Lite 源码分
  6. IP地址与子网的作用和组成
  7. java 中 String s = "" 与 new String()
  8. 子网掩码的进制转换
  9. vtp实验
  10. 共享文件夹