Skip to content

Commit 339fb43

Browse files
committed
add patches for hostapd, Wi-Fi
1 parent c2451d5 commit 339fb43

4 files changed

+358
-0
lines changed

patches/install.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ cd bionic
1616
echo "Applying bionic patches..."
1717
git am $rootdirectory/device/samsung/msm7x27-common/patches/bionic/*.patch
1818
cd $rootdirectory
19+
cd system/netd
20+
echo "Applying system/netd patches..."
21+
git am $rootdirectory/device/samsung/msm7x27-common/patches/system_netd/*.patch
22+
cd $rootdirectory
23+
cd hardware/libhardware_legacy
24+
echo "Applying hardware/libhardware_legacy patches..."
25+
git am $rootdirectory/device/samsung/msm7x27-common/patches/libhardware_legacy/*.patch
26+
cd $rootdirectory
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From b558f7e2df70b9d1acc840aae7a27dff131f3844 Mon Sep 17 00:00:00 2001
2+
From: Conn O'Griofa <[email protected]>
3+
Date: Wed, 7 Nov 2012 20:09:19 -0200
4+
Subject: [PATCH] libhardware_legacy/wifi: add workaround for ar6000 driver
5+
6+
The ar6000 driver requires the interface to be brought up in order
7+
for scanning to function. Without this change, the supplicant fails
8+
on first activation of wifi, and will only connect successfully
9+
after multiple retries. This workaround is also necessary to fix
10+
Wi-Fi hotspot mode (in conjunction with another change to
11+
system/netd).
12+
13+
Backported from CM7.
14+
---
15+
wifi/wifi.c | 8 ++++++++
16+
1 file changed, 8 insertions(+)
17+
18+
diff --git a/wifi/wifi.c b/wifi/wifi.c
19+
index 119252b..023f4b6 100644
20+
--- a/wifi/wifi.c
21+
+++ b/wifi/wifi.c
22+
@@ -713,6 +713,14 @@ int wifi_start_supplicant_common(const char *config_file)
23+
serial = pi->serial;
24+
}
25+
#endif
26+
+
27+
+ /* The ar6k driver needs the interface up in order to scan! */
28+
+ if (!strncmp(DRIVER_MODULE_NAME, "ar6000", 6)) {
29+
+ ifc_init();
30+
+ ifc_up("wlan0");
31+
+ sleep(2);
32+
+ }
33+
+
34+
property_get("wifi.interface", iface, WIFI_TEST_INTERFACE);
35+
snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s:-i%s -c%s", SUPPLICANT_NAME, iface, config_file);
36+
property_set("ctl.start", daemon_cmd);
37+
--
38+
1.7.10.4
39+
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
From 4e325607f78eed6aeb0d7618325b6fe9fdce028e Mon Sep 17 00:00:00 2001
2+
From: Tanguy Pruvot <[email protected]>
3+
Date: Mon, 4 Jun 2012 23:09:53 +0200
4+
Subject: [PATCH 1/2] SoftAP: allow a hostapd service and handle the wifi channel
5+
6+
using command parameters, or the new property "wifi.ap.channel"
7+
8+
Change-Id: I91414562aee5c9f70389935f4c699b34da79f6a6
9+
---
10+
Android.mk | 4 +++
11+
SoftapController.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++-----
12+
2 files changed, 87 insertions(+), 9 deletions(-)
13+
14+
diff --git a/Android.mk b/Android.mk
15+
index c09b634..ab894cd 100644
16+
--- a/Android.mk
17+
+++ b/Android.mk
18+
@@ -52,6 +52,10 @@ ifneq ($(BOARD_HOSTAPD_DRIVER),)
19+
endif
20+
endif
21+
22+
+ifneq ($(BOARD_HOSTAPD_SERVICE_NAME),)
23+
+ LOCAL_CFLAGS += -DHOSTAPD_SERVICE_NAME=\"$(BOARD_HOSTAPD_SERVICE_NAME)\"
24+
+endif
25+
+
26+
ifneq ($(BOARD_HOSTAPD_NO_ENTROPY),)
27+
LOCAL_CFLAGS += -DHOSTAPD_NO_ENTROPY
28+
endif
29+
diff --git a/SoftapController.cpp b/SoftapController.cpp
30+
index 820811f..b9d745d 100644
31+
--- a/SoftapController.cpp
32+
+++ b/SoftapController.cpp
33+
@@ -35,6 +35,7 @@
34+
35+
#define LOG_TAG "SoftapController"
36+
#include <cutils/log.h>
37+
+#include <cutils/properties.h>
38+
#include <netutils/ifc.h>
39+
#include <private/android_filesystem_config.h>
40+
#include "wifi.h"
41+
@@ -45,8 +46,13 @@
42+
#define HOSTAPD_DRIVER_NAME "nl80211"
43+
#endif
44+
45+
+#define AP_DEFAULT_CHANNEL 5
46+
+#define AP_SOCKET_PATH "/data/misc/wifi/hostapd"
47+
+
48+
static const char HOSTAPD_CONF_FILE[] = "/data/misc/wifi/hostapd.conf";
49+
50+
+extern "C" int system_nosh(const char *command);
51+
+
52+
SoftapController::SoftapController() {
53+
mPid = 0;
54+
mSock = socket(AF_INET, SOCK_DGRAM, 0);
55+
@@ -183,6 +189,7 @@ int SoftapController::stopDriver(char *iface) {
56+
int SoftapController::startSoftap() {
57+
pid_t pid = 1;
58+
int ret = 0;
59+
+ char value[PROPERTY_VALUE_MAX];
60+
61+
if (mPid) {
62+
LOGE("Softap already started");
63+
@@ -192,6 +199,36 @@ int SoftapController::startSoftap() {
64+
LOGE("Softap startap - failed to open socket");
65+
return -1;
66+
}
67+
+#ifdef HOSTAPD_SERVICE_NAME
68+
+
69+
+#ifndef HOSTAPD_NO_ENTROPY
70+
+ ensure_entropy_file_exists();
71+
+#endif
72+
+ ret = system_nosh("/system/bin/start " HOSTAPD_SERVICE_NAME);
73+
+ pid = (ret == 0);
74+
+
75+
+ usleep(AP_BSS_START_DELAY);
76+
+ property_get("init.svc." HOSTAPD_SERVICE_NAME, value, "stopped");
77+
+ if (strcmp(value, "running") == 0) {
78+
+ LOGD("hostapd service started");
79+
+ } else {
80+
+ ret = -1;
81+
+ }
82+
+
83+
+ *mBuf = 0;
84+
+ ret = setCommand(mIface, "AP_BSS_START");
85+
+ if (ret) {
86+
+ LOGE("Softap startap - failed: %d", ret);
87+
+ }
88+
+ else {
89+
+ mPid = pid;
90+
+ LOGD("Softap started");
91+
+ usleep(AP_BSS_START_DELAY);
92+
+ }
93+
+
94+
+ return ret;
95+
+#else
96+
+
97+
#ifdef HAVE_HOSTAPD
98+
if ((pid = fork()) < 0) {
99+
LOGE("fork failed (%s)", strerror(errno));
100+
@@ -210,7 +247,7 @@ int SoftapController::startSoftap() {
101+
HOSTAPD_CONF_FILE, (char *) NULL)) {
102+
LOGE("execl failed (%s)", strerror(errno));
103+
}
104+
-#endif
105+
+#endif /* HAVE_HOSTAPD */
106+
LOGE("Should never get here!");
107+
return -1;
108+
} else {
109+
@@ -226,7 +263,7 @@ int SoftapController::startSoftap() {
110+
}
111+
}
112+
return ret;
113+
-
114+
+#endif /* HOSTAPD_SERVICE_NAME */
115+
}
116+
117+
int SoftapController::stopSoftap() {
118+
@@ -237,6 +274,25 @@ int SoftapController::stopSoftap() {
119+
return 0;
120+
}
121+
122+
+#ifdef HOSTAPD_SERVICE_NAME
123+
+ LOGD("Stopping hostapd service");
124+
+ // use the hostapd service defined in init.rc
125+
+ if (system_nosh("/system/bin/stop " HOSTAPD_SERVICE_NAME))
126+
+ {
127+
+ LOGE("stop failed (%s)", strerror(errno));
128+
+ }
129+
+ if (mSock < 0) {
130+
+ LOGE("Softap stopap - failed to open socket");
131+
+ return -1;
132+
+ }
133+
+ *mBuf = 0;
134+
+ ret = setCommand(mIface, "AP_BSS_STOP");
135+
+ mPid = 0;
136+
+ LOGD("Softap service stopped: %d", ret);
137+
+ usleep(AP_BSS_STOP_DELAY);
138+
+ return ret;
139+
+#else
140+
+
141+
#ifdef HAVE_HOSTAPD
142+
LOGD("Stopping Softap service");
143+
kill(mPid, SIGTERM);
144+
@@ -252,6 +308,7 @@ int SoftapController::stopSoftap() {
145+
LOGD("Softap service stopped: %d", ret);
146+
usleep(AP_BSS_STOP_DELAY);
147+
return ret;
148+
+#endif /* HOSTAPD_SERVICE_NAME */
149+
}
150+
151+
bool SoftapController::isSoftapStarted() {
152+
@@ -284,7 +341,7 @@ int SoftapController::addParam(int pos, const char *cmd, const char *arg)
153+
int SoftapController::setSoftap(int argc, char *argv[]) {
154+
char psk_str[2*SHA256_DIGEST_LENGTH+1];
155+
int ret = 0, i = 0, fd;
156+
- char *ssid, *iface;
157+
+ char *ssid;
158+
159+
if (mSock < 0) {
160+
LOGE("Softap set - failed to open socket");
161+
@@ -296,11 +353,11 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
162+
}
163+
164+
strncpy(mIface, argv[3], sizeof(mIface));
165+
- iface = argv[2];
166+
167+
#ifdef HAVE_HOSTAPD
168+
char *wbuf = NULL;
169+
char *fbuf = NULL;
170+
+ int channel = 0;
171+
172+
if (argc > 4) {
173+
ssid = argv[4];
174+
@@ -308,18 +365,35 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
175+
ssid = (char *)"AndroidAP";
176+
}
177+
178+
- asprintf(&wbuf, "interface=%s\ndriver=" HOSTAPD_DRIVER_NAME "\nctrl_interface="
179+
- "/data/misc/wifi/hostapd\nssid=%s\nchannel=6\n", iface, ssid);
180+
+ if (argc > 7) {
181+
+ channel = atoi(argv[7]);
182+
+ } else {
183+
+ char value[PROPERTY_VALUE_MAX];
184+
+ property_get("wifi.ap.channel", value, "0");
185+
+ channel = atoi(value);
186+
+ }
187+
+ if (channel == 0) {
188+
+ channel = AP_DEFAULT_CHANNEL;
189+
+ LOGV("No valid wifi channel specified, using default");
190+
+ }
191+
+
192+
+ asprintf(&wbuf, "interface=%s\ndriver=" HOSTAPD_DRIVER_NAME "\n"
193+
+ "ctrl_interface=" AP_SOCKET_PATH "\n"
194+
+ "ssid=%s\nchannel=%d\n", mIface, ssid, channel);
195+
+
196+
+ LOGV("%s", wbuf);
197+
198+
if (argc > 5) {
199+
if (!strcmp(argv[5], "wpa-psk")) {
200+
generatePsk(ssid, argv[6], psk_str);
201+
asprintf(&fbuf, "%swpa=1\nwpa_pairwise=TKIP CCMP\nwpa_psk=%s\n", wbuf, psk_str);
202+
- } else if (!strcmp(argv[5], "wpa2-psk")) {
203+
+ } else if (!strncmp(argv[5], "wpa2", 4)) {
204+
generatePsk(ssid, argv[6], psk_str);
205+
asprintf(&fbuf, "%swpa=2\nrsn_pairwise=CCMP\nwpa_psk=%s\n", wbuf, psk_str);
206+
} else if (!strcmp(argv[5], "open")) {
207+
asprintf(&fbuf, "%s", wbuf);
208+
+ } else {
209+
+ LOGE("Invalid softap security type '%s'!\n", argv[5]);
210+
}
211+
} else {
212+
asprintf(&fbuf, "%s", wbuf);
213+
@@ -397,7 +471,7 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
214+
sprintf(&mBuf[i], "END");
215+
216+
/* system("iwpriv eth0 WL_AP_CFG ASCII_CMD=AP_CFG,SSID=\"AndroidAP\",SEC=\"open\",KEY=12345,CHANNEL=1,PREAMBLE=0,MAX_SCB=8,END"); */
217+
- ret = setCommand(iface, "AP_SET_CFG");
218+
+ ret = setCommand(mIface, "AP_SET_CFG");
219+
if (ret) {
220+
LOGE("Softap set - failed: %d", ret);
221+
}
222+
@@ -435,7 +509,7 @@ int SoftapController::fwReloadSoftap(int argc, char *argv[])
223+
char *fwpath;
224+
225+
if (mSock < 0) {
226+
- LOGE("Softap fwrealod - failed to open socket");
227+
+ LOGE("Softap fwreload - failed to open socket");
228+
return -1;
229+
}
230+
if (argc < 4) {
231+
--
232+
1.7.10.4
233+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From f4918a5290d36966e013fdf7712603220205c452 Mon Sep 17 00:00:00 2001
2+
From: Conn O'Griofa <[email protected]>
3+
Date: Wed, 7 Nov 2012 20:23:49 -0200
4+
Subject: [PATCH 2/2] system/netd: fix hotspot using legacy hostapd binaries
5+
6+
Two changes:
7+
1. Modify SoftapController::startDriver function to ensure that the
8+
wireless interface is initialized before attempting to start the interface.
9+
This may only be needed for the ar6000 driver (which needs the interface
10+
up to be able to function).
11+
2. Add a new BoardConfig option to improve compatibility with older
12+
(v0.6 or earlier) hostapd binaries. Activate with:
13+
BOARD_HAVE_LEGACY_HOSTAPD := true
14+
---
15+
Android.mk | 4 ++++
16+
SoftapController.cpp | 15 ++++++++++-----
17+
2 files changed, 14 insertions(+), 5 deletions(-)
18+
19+
diff --git a/Android.mk b/Android.mk
20+
index ab894cd..c16cf2e 100644
21+
--- a/Android.mk
22+
+++ b/Android.mk
23+
@@ -44,6 +44,10 @@ else
24+
LOCAL_SRC_FILES += SoftapController.cpp
25+
endif
26+
27+
+ifneq ($(BOARD_HAVE_LEGACY_HOSTAPD),)
28+
+ LOCAL_CFLAGS +=-DHAVE_HOSTAPD
29+
+ LOCAL_CFLAGS +=-DHAVE_LEGACY_HOSTAPD
30+
+endif
31+
32+
ifneq ($(BOARD_HOSTAPD_DRIVER),)
33+
LOCAL_CFLAGS += -DHAVE_HOSTAPD
34+
diff --git a/SoftapController.cpp b/SoftapController.cpp
35+
index b9d745d..b594ef0 100644
36+
--- a/SoftapController.cpp
37+
+++ b/SoftapController.cpp
38+
@@ -128,6 +128,12 @@ int SoftapController::setCommand(char *iface, const char *fname, unsigned buflen
39+
int SoftapController::startDriver(char *iface) {
40+
int ret;
41+
42+
+#ifdef HAVE_HOSTAPD
43+
+ ifc_init();
44+
+ ret = ifc_up(iface);
45+
+ ifc_close();
46+
+#endif
47+
+
48+
if (mSock < 0) {
49+
LOGE("Softap driver start - failed to open socket");
50+
return -1;
51+
@@ -147,11 +153,6 @@ int SoftapController::startDriver(char *iface) {
52+
LOGE("Softap driver start: %d", ret);
53+
return ret;
54+
}
55+
-#ifdef HAVE_HOSTAPD
56+
- ifc_init();
57+
- ret = ifc_up(iface);
58+
- ifc_close();
59+
-#endif
60+
usleep(AP_DRIVER_START_DELAY);
61+
LOGD("Softap driver start: %d", ret);
62+
return ret;
63+
@@ -377,8 +378,12 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
64+
LOGV("No valid wifi channel specified, using default");
65+
}
66+
67+
+#ifdef HAVE_LEGACY_HOSTAPD
68+
+ asprintf(&wbuf, "interface=%s\nctrl_interface=" AP_SOCKET_PATH "\n"
69+
+#else
70+
asprintf(&wbuf, "interface=%s\ndriver=" HOSTAPD_DRIVER_NAME "\n"
71+
"ctrl_interface=" AP_SOCKET_PATH "\n"
72+
+#endif
73+
"ssid=%s\nchannel=%d\n", mIface, ssid, channel);
74+
75+
LOGV("%s", wbuf);
76+
--
77+
1.7.10.4
78+

0 commit comments

Comments
 (0)