[RK3288][Android6.0] WiFi的配置文件wpa_supplicant.conf

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

起初以为对应的是external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.conf,对比生成的文件发现是共同一目录下的wpa_supplicant_template.conf,来看文件是如何最终生成为/data/misc/wifi/wpa_supplicant.conf

system/etc/wpa_supplicant.conf的生成
hardware/broadcom/wlan/bcmdhd/config/Android.mk

hardware调用对应mk:

WIFI_DRIVER_SOCKET_IFACE := wlan0
ifeq ($(strip $(WPA_SUPPLICANT_VERSION)),VER_0_8_X)
  include external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant_conf.mk
else
......
endif

mk说明:
external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant_conf.mk

//目标文件名字
LOCAL_MODULE := wpa_supplicant.conf
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_TAGS := optional
//生成到system/etc/wifi目录下
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/wifi
include $(BUILD_SYSTEM)/base_rules.mk
//对应的模板文件
WPA_SUPPLICANT_CONF_TEMPLATE := $(LOCAL_PATH)/wpa_supplicant_template.conf
WPA_SUPPLICANT_CONF_SCRIPT := $(LOCAL_PATH)/wpa_supplicant_conf.sh
$(LOCAL_BUILT_MODULE): PRIVATE_WIFI_DRIVER_SOCKET_IFACE := $(WIFI_DRIVER_SOCKET_IFACE)
$(LOCAL_BUILT_MODULE): PRIVATE_WPA_SUPPLICANT_CONF_TEMPLATE := $(WPA_SUPPLICANT_CONF_TEMPLATE)
$(LOCAL_BUILT_MODULE): PRIVATE_WPA_SUPPLICANT_CONF_SCRIPT := $(WPA_SUPPLICANT_CONF_SCRIPT)
$(LOCAL_BUILT_MODULE) : $(WPA_SUPPLICANT_CONF_TEMPLATE) $(WPA_SUPPLICANT_CONF_SCRIPT)
    @echo Target wpa_supplicant.conf: $@
    @mkdir -p $(dir $@)
    //调用bash脚本来生成目标文件
    $(hide) WIFI_DRIVER_SOCKET_IFACE="$(PRIVATE_WIFI_DRIVER_SOCKET_IFACE)" \
        bash $(PRIVATE_WPA_SUPPLICANT_CONF_SCRIPT) $(PRIVATE_WPA_SUPPLICANT_CONF_TEMPLATE) > $@

PRIVATE_WPA_SUPPLICANT_CONF_SCRIPT对应的是wpa_supplicant_conf.sh

# Generate a wpa_supplicant.conf from the template.
# $1: the template file name
if [ -n "$WIFI_DRIVER_SOCKET_IFACE" ]
then
  sed -e 's/#.*$//' -e 's/[ \t]*$//' -e '/^$/d' < $1 | sed -e "s/wlan0/$WIFI_DRIVER_SOCKET_IFACE/"
else
  sed -e 's/#.*$//' -e 's/[ \t]*$//' -e '/^$/d' < $1
fi

注释也说得很清楚了,从template生成wpa_supplicant.conf
对比生成的/system/etc/wpa_supplicant.conf的内容是和wpa_supplicant_template.conf一样的 。

/data/misc/wifi/wpa_supplicant.conf的生成
wifi_start_supplicant -> ensure_config_file_exists
参数是SUPP_CONFIG_FILE,即/data/misc/wifi/wpa_supplicant.conf

这里先生成了/system/etc/wifi/wpa_supplicant.conf,
然后再看/data/misc/wifi/wpa_supplicant.conf的生成。

int ensure_config_file_exists(const char *config_file)
{
    ......
    //先访问wpa_supplicant.conf,存在就返回,不存在就继续往下走
    access(config_file, R_OK|W_OK);
    ......
    //如果/data/misc/wifi/wpa_supplicant.conf不存在,那么往下走
    //打开SUPP_CONFIG_TEMPLATE,即/system/etc/wifi/wpa_supplicant.conf
    TEMP_FAILURE_RETRY(open(SUPP_CONFIG_TEMPLATE, O_RDONLY));
    //创建/data/misc/wifi/wpa_supplicant.conf
    TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660));
    //读取/system/etc/wifi/wpa_supplicant.conf的内容,然后写到/data/misc/wifi/wpa_supplicant.conf中
    TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf));
    TEMP_FAILURE_RETRY(write(destfd, buf, nread));
}

还有个问题,就是会发现/data/misc/wifi/wpa_supplicant.conf的内容又会不一样,这是因为文件中有个属性
update_config=1
表示开机之后WPAS(wpa_supplicant)可以修改更新配置文件。
wpa_supplicant.conf的配置属性可参见 external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.conf ,里面写得很详细。

你可能感兴趣的:(子类__WiFi)