说明
wpa_supplicant: 连接、配置WIFI的工具
AP: Access Point简称,一般翻译为“无线访问节点”
本次修改主要是为了方便生产测试PCBA, 我们可以在相关文件中添加工厂AP列表, 这样机器在开机后即可连上列表中的网络了
修改源码
diff --git a/ReadMe.txt b/ReadMe.txt
new file mode 100755
index 0000000..75ebffd
--- /dev/null
+++ b/ReadMe.txt
@@ -0,0 +1,28 @@
+支持默认 AP 连接功能:
+需要两个文件:
+ 1. init.connectivity.rc:
+ service p2p_supp_rtl /system/bin/wpa_supplicant \
+ -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
+ -e/data/misc/wifi/entropy.bin -N \
+ -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
+ -A/system/etc/wifi/wpa_supplicant_defconfig_ap.conf \ // -A 指定默认ap信息
+ -O/data/misc/wifi/sockets \
+ -g@android:wpa_wlan0
+ class main
+ socket wpa_wlan0 dgram 660 wifi wifi
+ disabled
+ oneshot
+
+ // 默认 AP 配置文件. 核心逻辑: 将下列配置合并入 wpa_supplicant.conf
+ 2. wpa_supplicant_defconfig_ap.conf
+ network={
+ ssid="CXH-001"
+ psk="88886666"
+ key_mgmt=WPA-PSK
+ }
+
+ network={
+ ssid="TFD"
+ psk="toufengda"
+ key_mgmt=WPA-PSK
+ }
diff --git a/wpa_supplicant/main.c b/wpa_supplicant/main.c
old mode 100644
new mode 100755
index 1c93306..889aebe
--- a/wpa_supplicant/main.c
+++ b/wpa_supplicant/main.c
@@ -175,7 +175,7 @@ int main(int argc, char *argv[])
for (;;) {
c = getopt(argc, argv,
- "b:Bc:C:D:de:f:g:G:hi:I:KLm:No:O:p:P:qsTtuvW");
+ "b:Bc:C:D:de:f:g:G:hi:I:A:KLm:No:O:p:P:qsTtuvW");
if (c < 0)
break;
switch (c) {
@@ -228,6 +228,9 @@ int main(int argc, char *argv[])
case 'I':
iface->confanother = optarg;
break;
+ case 'A':
+ iface->confdefap = optarg;
+ break;
case 'K':
params.wpa_debug_show_keys++;
break;
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
old mode 100644
new mode 100755
index 722294d..94f64eb
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -55,6 +55,10 @@
#include "wpas_kay.h"
#include "mesh.h"
+#ifdef ANDROID
+#include <cutils/properties.h>
+#endif /* ANDROID */
+
const char *const wpa_supplicant_version =
"wpa_supplicant v" VERSION_STR "\n"
"Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi> and contributors";
@@ -429,6 +433,9 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
os_free(wpa_s->confanother);
wpa_s->confanother = NULL;
+ os_free(wpa_s->confdefap);
+ wpa_s->confdefap = NULL;
+
wpa_sm_set_eapol(wpa_s->wpa, NULL);
eapol_sm_deinit(wpa_s->eapol);
wpa_s->eapol = NULL;
@@ -4031,7 +4038,8 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
{
struct wpa_driver_capa capa;
int capa_res;
-
+ char isAlreadyConfig[PROPERTY_VALUE_MAX];
+
wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
"'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
iface->confname ? iface->confname : "N/A",
@@ -4062,6 +4070,23 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
wpa_s->confanother = os_rel2abs_path(iface->confanother);
wpa_config_read(wpa_s->confanother, wpa_s->conf);
+ // Modify Tower 20190418, custom ap defconfig.
+ wpa_s->confdefap = os_rel2abs_path(iface->confdefap);
+#ifdef ANDROID
+ if (wpa_s->confdefap != NULL) {
+ if (property_get("persist.sys.wifi.config", isAlreadyConfig, "0") != 0) {
+ int out = atoi(isAlreadyConfig);
+ if (!out) {
+ wpa_printf(MSG_ERROR, "init wifi define ap\n");
+ wpa_config_read(wpa_s->confdefap, wpa_s->conf);
+ property_set("persist.sys.wifi.config", "1");
+ } else {
+ wpa_printf(MSG_ERROR, "already config wifi default ap\n");
+ }
+ }
+ }
+#endif
+
/*
* Override ctrl_interface and driver_param if set on command
* line.
@@ -4090,7 +4115,7 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
wpa_printf(MSG_ERROR, "\nNo configuration found.");
return -1;
}
-
+
if (iface->ifname == NULL) {
wpa_printf(MSG_ERROR, "\nInterface name is required.");
return -1;
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
old mode 100644
new mode 100755
index 4f63456..cdd1540
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -67,6 +67,14 @@ struct wpa_interface {
const char *confanother;
/**
+ * confdefap - Additional configuration def ap (file or profile) name
+ *
+ * This can also be %NULL when the additional configuration file is not
+ * used.
+ */
+ const char *confdefap;
+
+ /**
* ctrl_interface - Control interface parameter
*
* If a configuration file is not used, this variable can be used to
@@ -447,6 +455,7 @@ struct wpa_supplicant {
char *confname;
char *confanother;
+ char *confdefap;
struct wpa_config *conf;
int countermeasures;