大致的启动参数如下:

service wpa_supplicant /vendor/bin/hw/wpa_supplicant \
    -O/data/vendor/wifi/wpa/sockets \
    -ip2p0 -Dnl80211 -c/data/vendor/wifi/wpa/p2p_supplicant.conf \
    -e/data/misc/wifi/entropy.bin -N \         
    -iwlan0 -Dnl80211 -c/data/vendor/wifi/wpa/wpa_supplicant.conf \                                                   
    -g@android:wpa_wlan0 -ddd       
    # we will start as root and wpa_supplicant will switch to user wifi                                             
    # after setting up the capabilities required for WEXT
    # user wifi                              
    # group wifi inet keystore                            
    interface android.hardware.wifi.supplicant@1.0::ISupplicant default
    interface android.hardware.wifi.supplicant@1.1::ISupplicant default
    class main                            
    socket wpa_wlan0 dgram 660 wifi wifi         
    disabled                                               
    oneshot

 

参数介绍如下:

  -b = optional bridge interface name
  -B = run daemon in the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -g = global ctrl_interface
  -G = global ctrl_interface group
  -h = show this help text
  -i = interface name
  -I = additional configuration file
  -K = include keys (passwords, etc.) in debug output
  -L = show license (BSD)
  -m = Configuration file for the P2P Device interface
  -N = start describing new interface
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -t = include timestamp in debug messages
  -v = show version
  -W = wait for a control interface monitor before starting
 

启动过程介绍:

第一步:解析wpa_supplcant的启动参数

第二步:初始化global接口

第三步:添加wlan0和p2p0接口,这里有个坑,启动参数最好把p2p0接口放在前面,wlan0接口放在后面,不然可能出现如下错误:

01-01 07:13:22.610  5858  5858 D wpa_supplicant: Using existing control interface directory.
01-01 07:13:22.610  5858  5858 D wpa_supplicant: ctrl_iface bind(PF_UNIX) failed: Address already in use
01-01 07:13:22.610  5858  5858 I wpa_supplicant: ctrl_iface exists and seems to be in use - cannot override it
01-01 07:13:22.610  5858  5858 I wpa_supplicant: Delete '/data/vendor/wifi/wpa/sockets/wlan0' manually if it is not used anymore
01-01 07:13:22.610  5858  5858 E wpa_supplicant: Failed to initialize control interface '/data/vendor/wifi/wpa/sockets'.
01-01 07:13:22.610  5858  5858 E wpa_supplicant: You may have another wpa_supplicant process already running or the file was
01-01 07:13:22.610  5858  5858 E wpa_supplicant: left by an unclean termination of wpa_supplicant in which case you will need
01-01 07:13:22.610  5858  5858 E wpa_supplicant: to manually remove this file before starting wpa_supplicant again.
01-01 07:13:22.611  5858  5858 D wpa_supplicant: Failed to add interface wlan0

具体原因见wpa_supplicant:因为wlan0接口先加载,并且没有配置p2p_disabled=1,所以wlan接口就进行了p2p的初始化,hidl那边就会判断wlan0接口是p2p接口

然后android的hal层那边会调用到wpa_supplicant, 发现wlan0不是sta,返回null,然后继续add_interface,所以出错

第四步:运行几个核心线程开始工作

 

第五步:初始化android hal:SupplicantStaIfaceHal(用来监听supplicant的变化),如下2行主要决定使用的工具以及对应的版本

interface android.hardware.wifi.supplicant@1.0::ISupplicant default
interface android.hardware.wifi.supplicant@1.1::ISupplicant default

如果没有上面的信息,运行的时候会报如下错误:

01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950): Failed to get ISupplicant
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950): java.util.NoSuchElementException
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at android.os.HwBinder.getService(Native Method)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at android.os.HwBinder.getService(HwBinder.java:91)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at android.hardware.wifi.supplicant.V1_0.ISupplicant.getService(ISupplicant.java:48)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at android.hardware.wifi.supplicant.V1_0.ISupplicant.getService(ISupplicant.java:52)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at com.android.server.wifi.SupplicantStaIfaceHal.getSupplicantMockable(SupplicantStaIfaceHal.java:541)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at com.android.server.wifi.SupplicantStaIfaceHal.initSupplicantService(SupplicantStaIfaceHal.java:244)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at com.android.server.wifi.SupplicantStaIfaceHal.access$200(SupplicantStaIfaceHal.java:88)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at com.android.server.wifi.SupplicantStaIfaceHal$1.onRegistration(SupplicantStaIfaceHal.java:120)
01-01 00:00:02.934 E/SupplicantStaIfaceHal( 1950):     at android.hidl.manager.V1_0.IServiceNotification$Stub.onTransact(IServiceNotification.java:389)
01-01 00:00:02.935 E/SupplicantStaIfaceHal( 1950): Got null ISupplicant service. Stopping supplicant HIDL startup
01-01 00:00:02.935 E/SupplicantStaIfaceHal( 1950): initalizing ISupplicant failed.

 

 

 

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐