summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Zhang <paulz@codeaurora.org>2014-09-16 10:40:06 +0800
committerLinux Build Service Account <lnxbuild@localhost>2014-11-04 08:45:02 -0700
commitabc9c0f4fe574ee9847f118e5d2ae8c530bac650 (patch)
treebda5540fe16f28d279500d745af797bfd8e82756
parentdd39bf9d9988e91c0c7e7d90b7e03539b0689277 (diff)
downloadandroid_system_netd-abc9c0f4fe574ee9847f118e5d2ae8c530bac650.tar.gz
android_system_netd-abc9c0f4fe574ee9847f118e5d2ae8c530bac650.tar.bz2
android_system_netd-abc9c0f4fe574ee9847f118e5d2ae8c530bac650.zip
SOFTAP: Notificate the STA (dis)connect messagestaging/cm-12.0-caf
Create a thread to poll the hostapd's message through the wpa_ctrl_* interface, and broadcast the message to the uplayer. CRs-Fixed: 685913 Change-Id: I4dd0326110c655fcd6cd5f8425be523d9e64ffa7
-rwxr-xr-xserver/Android.mk6
-rw-r--r--server/CommandListener.cpp2
-rw-r--r--server/ResponseCode.h1
-rwxr-xr-x[-rw-r--r--]server/SoftapController.cpp105
-rwxr-xr-x[-rw-r--r--]server/SoftapController.h13
5 files changed, 122 insertions, 5 deletions
diff --git a/server/Android.mk b/server/Android.mk
index cb94bc6c..fc85fa40 100755
--- a/server/Android.mk
+++ b/server/Android.mk
@@ -77,6 +77,12 @@ ifeq ($(BOARD_HAS_QCOM_WLAN), true)
LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/sdk/softap/include
endif
+ifdef WPA_SUPPLICANT_VERSION
+ LOCAL_CFLAGS += -DLIBWPA_CLIENT_EXISTS
+ LOCAL_SHARED_LIBRARIES += libwpa_client
+ LOCAL_C_INCLUDES += external/wpa_supplicant_8/src/common
+endif
+
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
diff --git a/server/CommandListener.cpp b/server/CommandListener.cpp
index ededddb2..e86c22e6 100644
--- a/server/CommandListener.cpp
+++ b/server/CommandListener.cpp
@@ -248,7 +248,7 @@ CommandListener::CommandListener() :
if (!sPppCtrl)
sPppCtrl = new PppController();
if (!sSoftapCtrl)
- sSoftapCtrl = new SoftapController();
+ sSoftapCtrl = new SoftapController(this);
if (!sBandwidthCtrl)
sBandwidthCtrl = new BandwidthController();
if (!sIdletimerCtrl)
diff --git a/server/ResponseCode.h b/server/ResponseCode.h
index 594d997b..9a822011 100644
--- a/server/ResponseCode.h
+++ b/server/ResponseCode.h
@@ -78,5 +78,6 @@ public:
static const int InterfaceAddressChange = 614;
static const int InterfaceDnsInfo = 615;
static const int RouteChange = 616;
+ static const int InterfaceMessage = 617;
};
#endif
diff --git a/server/SoftapController.cpp b/server/SoftapController.cpp
index 07c77b01..79ce618b 100644..100755
--- a/server/SoftapController.cpp
+++ b/server/SoftapController.cpp
@@ -42,15 +42,101 @@
#include "SoftapController.h"
+#ifdef LIBWPA_CLIENT_EXISTS
+#include <dirent.h>
+#include "wpa_ctrl.h"
+#endif
+
static const char HOSTAPD_CONF_FILE[] = "/data/misc/wifi/hostapd.conf";
static const char HOSTAPD_BIN_FILE[] = "/system/bin/hostapd";
-
-SoftapController::SoftapController()
- : mPid(0) {}
+#ifdef LIBWPA_CLIENT_EXISTS
+static const char HOSTAPD_UNIX_FILE[] = "/data/misc/wifi/hostapd/wlan0";
+static const char HOSTAPD_SOCKETS_DIR[] = "/data/misc/wifi/sockets";
+static const char HOSTAPD_DHCP_DIR[] = "/data/misc/dhcp";
+#endif
+
+SoftapController::SoftapController(SocketListener *sl)
+ : mPid(0) {
+ mSpsl = sl;
+}
SoftapController::~SoftapController() {
}
+#ifdef LIBWPA_CLIENT_EXISTS
+void *SoftapController::threadStart(void *obj){
+ SoftapController *me = reinterpret_cast<SoftapController *>(obj);
+ struct wpa_ctrl *ctrl;
+ int count = 0;
+
+ ALOGE("SoftapController::threadStart...");
+
+ DIR *dir=NULL;
+
+ dir = opendir(HOSTAPD_SOCKETS_DIR);
+ if(NULL == dir){
+ mkdir(HOSTAPD_SOCKETS_DIR, S_IRWXU|S_IRWXG|S_IRWXO);
+ chown(HOSTAPD_SOCKETS_DIR, AID_WIFI, AID_WIFI);
+ }else{
+ closedir(dir);
+ }
+
+ chmod(HOSTAPD_DHCP_DIR, S_IRWXU|S_IRWXG|S_IRWXO);
+
+ ctrl = wpa_ctrl_open(HOSTAPD_UNIX_FILE);
+ while ( ctrl == NULL ){
+ /*
+ * thread is used to receive sta connected msg from hostapd
+ * through wap_ctrl interface, when thread is starting up,
+ * it's possible that hostpd has sta connected to it, so
+ * decrease sleep time to 10ms to lower the ratio that
+ * miss the msg from hostapd
+ */
+ usleep(20000);
+ ctrl = wpa_ctrl_open(HOSTAPD_UNIX_FILE);
+ if (ctrl != NULL || count >= 150)
+ break;
+ count++;
+ }
+ if (count == 150 && ctrl == NULL){
+ ALOGE("Connection to hostapd Error.");
+ return NULL;
+ }
+
+ if (wpa_ctrl_attach(ctrl) !=0 ){
+ wpa_ctrl_close(ctrl);
+ ALOGE("Attach to hostapd Error.");
+ return NULL;
+ }
+
+ while(me->mHostapdFlag) {
+ int res = 0;
+ char buf[256];
+ char dest_str[300];
+ while (wpa_ctrl_pending(ctrl)) {
+ size_t len = sizeof(buf) - 1;
+ res = wpa_ctrl_recv(ctrl, buf, &len);
+ if (res == 0) {
+ buf[len] = '\0';
+ ALOGD("Get event from hostapd (%s)", buf);
+ memset(dest_str, 0x0, sizeof(dest_str));
+ snprintf(dest_str, sizeof(dest_str), "IfaceMessage active %s", buf);
+ me->mSpsl->sendBroadcast(ResponseCode::InterfaceMessage, dest_str, false);
+ }else
+ break;
+ }
+ if(res < 0)
+ break;
+ sleep(2);
+ }
+
+ wpa_ctrl_detach(ctrl);
+ wpa_ctrl_close(ctrl);
+
+ return NULL;
+}
+#endif
+
int SoftapController::startSoftap() {
pid_t pid = 1;
@@ -77,6 +163,12 @@ int SoftapController::startSoftap() {
mPid = pid;
ALOGD("SoftAP started successfully");
usleep(AP_BSS_START_DELAY);
+#ifdef LIBWPA_CLIENT_EXISTS
+ mHostapdFlag = 1;
+ if((mThreadErr = pthread_create(&mThread,NULL,SoftapController::threadStart,this)) != 0){
+ ALOGE("pthread_create failed for hostapd listen socket (%s)", strerror(errno));
+ }
+#endif
}
return ResponseCode::SoftapStatusResult;
}
@@ -88,6 +180,13 @@ int SoftapController::stopSoftap() {
return ResponseCode::SoftapStatusResult;
}
+#ifdef LIBWPA_CLIENT_EXISTS
+ mHostapdFlag = 0;
+ if(mThreadErr == 0){
+ pthread_join(mThread, NULL);
+ }
+#endif
+
ALOGD("Stopping the SoftAP service...");
kill(mPid, SIGTERM);
waitpid(mPid, NULL, 0);
diff --git a/server/SoftapController.h b/server/SoftapController.h
index 7063067b..fd539391 100644..100755
--- a/server/SoftapController.h
+++ b/server/SoftapController.h
@@ -20,6 +20,8 @@
#include <linux/in.h>
#include <net/if.h>
+#include <sysutils/SocketListener.h>
+
#define SOFTAP_MAX_BUFFER_SIZE 4096
#define AP_BSS_START_DELAY 200000
#define AP_BSS_STOP_DELAY 500000
@@ -29,7 +31,7 @@
class SoftapController {
public:
- SoftapController();
+ SoftapController(SocketListener *sl);
virtual ~SoftapController();
int startSoftap();
@@ -38,8 +40,17 @@ public:
int setSoftap(int argc, char *argv[]);
int fwReloadSoftap(int argc, char *argv[]);
private:
+ SocketListener *mSpsl;
+#ifdef LIBWPA_CLIENT_EXISTS
+ pthread_t mThread;
+ int mThreadErr;
+ int mHostapdFlag;
+#endif
pid_t mPid;
void generatePsk(char *ssid, char *passphrase, char *psk);
+#ifdef LIBWPA_CLIENT_EXISTS
+ static void *threadStart(void *obj);
+#endif
};
#endif