summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2011-07-22 11:12:58 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-22 11:12:58 -0700
commit8ab120320313522050a34f45982942c08880350a (patch)
treeae04a73e15105b30508f6fb65fabd0084c54a5b8
parentbfa7466b328101a8b04807f26e85c84526c9a774 (diff)
parent389f8d1550880f3bc67ade3e93f2ddb767e64092 (diff)
downloadnetd-8ab120320313522050a34f45982942c08880350a.tar.gz
Merge "softap: Add hostapd support if BOARD_HOSTAPD_DRIVER is set"
-rw-r--r--Android.mk4
-rw-r--r--SoftapController.cpp53
2 files changed, 47 insertions, 10 deletions
diff --git a/Android.mk b/Android.mk
index 5460ab43..2004eba3 100644
--- a/Android.mk
+++ b/Android.mk
@@ -35,6 +35,10 @@ LOCAL_CFLAGS :=
LOCAL_SHARED_LIBRARIES := libstlport libsysutils libcutils libnetutils \
libcrypto libhardware_legacy
+ifneq ($(BOARD_HOSTAPD_DRIVER),)
+ LOCAL_CFLAGS += -DHAVE_HOSTAPD
+endif
+
ifeq ($(BOARD_HAVE_BLUETOOTH),true)
LOCAL_SHARED_LIBRARIES := $(LOCAL_SHARED_LIBRARIES) libbluedroid
LOCAL_CFLAGS := $(LOCAL_CFLAGS) -DHAVE_BLUETOOTH
diff --git a/SoftapController.cpp b/SoftapController.cpp
index aee120f9..9e99017e 100644
--- a/SoftapController.cpp
+++ b/SoftapController.cpp
@@ -35,6 +35,7 @@
#define LOG_TAG "SoftapController"
#include <cutils/log.h>
+#include <netutils/ifc.h>
#include "wifi.h"
#include "SoftapController.h"
@@ -53,6 +54,9 @@ SoftapController::~SoftapController() {
}
int SoftapController::setCommand(char *iface, const char *fname, unsigned buflen) {
+#ifdef HAVE_HOSTAPD
+ return 0;
+#else
char tBuf[SOFTAP_MAX_BUFFER_SIZE];
struct iwreq wrq;
struct iw_priv_args *priv_ptr;
@@ -105,6 +109,7 @@ int SoftapController::setCommand(char *iface, const char *fname, unsigned buflen
wrq.u.data.flags = sub_cmd;
ret = ioctl(mSock, cmd, &wrq);
return ret;
+#endif
}
int SoftapController::startDriver(char *iface) {
@@ -121,6 +126,15 @@ int SoftapController::startDriver(char *iface) {
*mBuf = 0;
ret = setCommand(iface, "START");
+ if (ret < 0) {
+ LOGE("Softap driver start: %d", ret);
+ return ret;
+ }
+#ifdef HAVE_HOSTAPD
+ ifc_init();
+ ret = ifc_up(iface);
+ ifc_close();
+#endif
usleep(AP_DRIVER_START_DELAY);
LOGD("Softap driver start: %d", ret);
return ret;
@@ -138,6 +152,15 @@ int SoftapController::stopDriver(char *iface) {
iface = mIface;
}
*mBuf = 0;
+#ifdef HAVE_HOSTAPD
+ ifc_init();
+ ret = ifc_down(iface);
+ ifc_close();
+ if (ret < 0) {
+ LOGE("Softap %s down: %d", iface, ret);
+ return ret;
+ }
+#endif
ret = setCommand(iface, "STOP");
LOGD("Softap driver stop: %d", ret);
return ret;
@@ -155,16 +178,21 @@ int SoftapController::startSoftap() {
LOGE("Softap startap - failed to open socket");
return -1;
}
-#if 0
- if ((pid = fork()) < 0) {
+#ifdef HAVE_HOSTAPD
+ if ((pid = fork()) < 0) {
LOGE("fork failed (%s)", strerror(errno));
return -1;
}
#endif
- /* system("iwpriv wl0.1 AP_BSS_START"); */
if (!pid) {
- /* start hostapd */
- return ret;
+#ifdef HAVE_HOSTAPD
+ if (execl("/system/bin/hostapd", "/system/bin/hostapd", "-B",
+ "/data/misc/wifi/hostapd.conf", (char *) NULL)) {
+ LOGE("execl failed (%s)", strerror(errno));
+ }
+#endif
+ LOGE("Should never get here!");
+ return -1;
} else {
*mBuf = 0;
ret = setCommand(mIface, "AP_BSS_START");
@@ -188,17 +216,18 @@ int SoftapController::stopSoftap() {
LOGE("Softap already stopped");
return 0;
}
+
+#ifdef HAVE_HOSTAPD
+ LOGD("Stopping Softap service");
+ kill(mPid, SIGTERM);
+ waitpid(mPid, NULL, 0);
+#endif
if (mSock < 0) {
LOGE("Softap stopap - failed to open socket");
return -1;
}
*mBuf = 0;
ret = setCommand(mIface, "AP_BSS_STOP");
-#if 0
- LOGD("Stopping Softap service");
- kill(mPid, SIGTERM);
- waitpid(mPid, NULL, 0);
-#endif
mPid = 0;
LOGD("Softap service stopped: %d", ret);
usleep(AP_BSS_STOP_DELAY);
@@ -339,8 +368,12 @@ int SoftapController::fwReloadSoftap(int argc, char *argv[])
}
if (!fwpath)
return -1;
+#ifdef HAVE_HOSTAPD
+ ret = wifi_change_fw_path((const char *)fwpath);
+#else
sprintf(mBuf, "FW_PATH=%s", fwpath);
ret = setCommand(iface, "WL_FW_RELOAD");
+#endif
if (ret) {
LOGE("Softap fwReload - failed: %d", ret);
}