SoftapController: support for Fast Session Transfer

To support Fast Session Transfer (FST), hostapd needs to
run with global control interface. Added optional support
to run it with global control interface with default
behaving as in existing functionality.

FST manager needs to run before hostapd starting running,
to achieve this calls to prepare for soft AP mode was added.

Change-Id: Ib552de30c7c200f46f08b72c819dba160bce8eba
diff --git a/server/CommandListener.cpp b/server/CommandListener.cpp
index 846ff60..f6c5c10 100644
--- a/server/CommandListener.cpp
+++ b/server/CommandListener.cpp
@@ -788,12 +788,26 @@
         qccmd = 1;
     }
     else if (!strcmp(argv[1], "startap")) {
+        rc = qsap_prepare_softap();
+        if (!rc) {
+            rc = gCtls->softapCtrl.startSoftap(qsap_is_fst_enabled());
+            if (rc != ResponseCode::SoftapStatusResult) {
+                ALOGE("failed to start SoftAP ResponseCode : %d", rc);
+                qsap_unprepare_softap();
+            }
+        } else {
+            ALOGE("qsap_prepare_softap failed");
+            rc = ResponseCode::ServiceStartFailed;
+        }
+    } else if (!strcmp(argv[1], "stopap")) {
+        rc = gCtls->softapCtrl.stopSoftap();
+        qsap_unprepare_softap();
 #else
     if (!strcmp(argv[1], "startap")) {
-#endif
         rc = gCtls->softapCtrl.startSoftap();
     } else if (!strcmp(argv[1], "stopap")) {
         rc = gCtls->softapCtrl.stopSoftap();
+#endif
     } else if (!strcmp(argv[1], "fwreload")) {
         rc = gCtls->softapCtrl.fwReloadSoftap(argc, argv);
     } else if (!strcmp(argv[1], "status")) {
diff --git a/server/SoftapController.cpp b/server/SoftapController.cpp
index 4c4599d..72b091e 100644
--- a/server/SoftapController.cpp
+++ b/server/SoftapController.cpp
@@ -51,6 +51,7 @@
 static const char HOSTAPD_CONF_FILE[]    = "/data/misc/wifi/hostapd.conf";
 static const char HOSTAPD_BIN_FILE[]    = "/system/bin/hostapd";
 static const char HOSTAPD_SOCKETS_DIR[]    = "/data/misc/wifi/sockets";
+static const char WIFI_HOSTAPD_GLOBAL_CTRL_IFACE[] = "/data/misc/wifi/hostapd/global";
 
 SoftapController::SoftapController()
     : mPid(0) {}
@@ -58,9 +59,10 @@
 SoftapController::~SoftapController() {
 }
 
-int SoftapController::startSoftap() {
+int SoftapController::startSoftap(bool global_ctrl_iface = false) {
     pid_t pid = 1;
     DIR *dir = NULL;
+    int ret;
 
     if (mPid) {
         ALOGE("SoftAP is already running");
@@ -78,9 +80,17 @@
 
     if (!pid) {
         ensure_entropy_file_exists();
-        if (execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE,
-                  "-e", WIFI_ENTROPY_FILE,
-                  HOSTAPD_CONF_FILE, (char *) NULL)) {
+        if (global_ctrl_iface) {
+            ret = execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE,
+                        "-e", WIFI_ENTROPY_FILE, "-ddd",
+                        "-g", WIFI_HOSTAPD_GLOBAL_CTRL_IFACE,
+                        HOSTAPD_CONF_FILE, (char *)NULL);
+        } else {
+            ret = execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE,
+                        "-e", WIFI_ENTROPY_FILE, HOSTAPD_CONF_FILE,
+                        (char *)NULL);
+        }
+        if (ret) {
             ALOGE("execl failed (%s)", strerror(errno));
         }
         ALOGE("SoftAP failed to start");
diff --git a/server/SoftapController.h b/server/SoftapController.h
index 68025e2..cf3a535 100644
--- a/server/SoftapController.h
+++ b/server/SoftapController.h
@@ -32,7 +32,7 @@
     SoftapController();
     virtual ~SoftapController();
 
-    int startSoftap();
+    int startSoftap(bool global_ctrl_iface);
     int stopSoftap();
     bool isSoftapStarted();
     int setSoftap(int argc, char *argv[]);