netd: softap: Add FW reload processing

Change-Id: I731c2e390187c0fa5f69779cd25d8f2388ee511e
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/Android.mk b/Android.mk
index 4274443..faff1ce 100644
--- a/Android.mk
+++ b/Android.mk
@@ -31,6 +31,13 @@
                     $(LOCAL_PATH)/../bluetooth/bluez-clean-headers
 
 LOCAL_CFLAGS := -DINTERNAL_SHA1 -DCONFIG_CRYPTO_INTERNAL -DCONFIG_NO_T_PRF -DCONFIG_NO_TLS_PRF
+ifdef WIFI_DRIVER_FW_STA_PATH
+LOCAL_CFLAGS += -DWIFI_DRIVER_FW_STA_PATH=\"$(WIFI_DRIVER_FW_STA_PATH)\"
+endif
+ifdef WIFI_DRIVER_FW_AP_PATH
+LOCAL_CFLAGS += -DWIFI_DRIVER_FW_AP_PATH=\"$(WIFI_DRIVER_FW_AP_PATH)\"
+endif
+
 LOCAL_SHARED_LIBRARIES := libsysutils libcutils libnetutils
 
 ifeq ($(BOARD_HAVE_BLUETOOTH),true)
diff --git a/CommandListener.cpp b/CommandListener.cpp
index e65f783..f1a592e 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -510,7 +510,7 @@
 
 int CommandListener::SoftapCmd::runCommand(SocketClient *cli,
                                         int argc, char **argv) {
-    int rc = 0;
+    int rc = 0, flag = 0;
 
     if (argc < 2) {
         cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Missing argument", false);
@@ -521,6 +521,8 @@
         rc = sSoftapCtrl->startSoftap();
     } else if (!strcmp(argv[1], "stop")) {
         rc = sSoftapCtrl->stopSoftap();
+    } else if (!strcmp(argv[1], "fwreload")) {
+        rc = sSoftapCtrl->fwReloadSoftap(argc, argv);
     } else if (!strcmp(argv[1], "status")) {
         char *tmp = NULL;
 
diff --git a/SoftapController.cpp b/SoftapController.cpp
index 352c353..392f11b 100644
--- a/SoftapController.cpp
+++ b/SoftapController.cpp
@@ -258,3 +258,53 @@
     }
     return ret;
 }
+
+/*
+ * Arguments:
+ *	argv[2] - interface name
+ *	argv[3] - AP or STA
+ */
+int SoftapController::fwReloadSoftap(int argc, char *argv[])
+{
+    struct iwreq wrq;
+    int fnum, ret, i = 0;
+    char *iface;
+
+    if (mSock < 0) {
+        LOGE("Softap fwrealod - failed to open socket");
+        return -1;
+    }
+    if (argc < 4) {
+        LOGE("Softap fwreload - missing arguments");
+        return -1;
+    }
+
+    iface = argv[2];
+    fnum = getPrivFuncNum(iface, "WL_FW_RELOAD");
+    if (fnum < 0) {
+        LOGE("Softap fwReload - function not supported");
+        return -1;
+    }
+
+    if (strcmp(argv[3], "AP") == 0) {
+#ifdef WIFI_DRIVER_FW_AP_PATH
+        sprintf(mBuf, "FW_PATH=%s", WIFI_DRIVER_FW_AP_PATH);
+#endif
+    } else {
+#ifdef WIFI_DRIVER_FW_STA_PATH
+        sprintf(mBuf, "FW_PATH=%s", WIFI_DRIVER_FW_STA_PATH);
+#endif
+    }
+    strncpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
+    wrq.u.data.length = strlen(mBuf) + 1;
+    wrq.u.data.pointer = mBuf;
+    wrq.u.data.flags = 0;
+    ret = ioctl(mSock, fnum, &wrq);
+    if (ret) {
+        LOGE("Softap fwReload - failed: %d", ret);
+    }
+    else {
+        LOGD("Softap fwReload - Ok");
+    }
+    return ret;
+}
diff --git a/SoftapController.h b/SoftapController.h
index c42b1fa..ae0e007 100644
--- a/SoftapController.h
+++ b/SoftapController.h
@@ -39,6 +39,7 @@
     int stopSoftap();
     bool isSoftapStarted();
     int setSoftap(int argc, char *argv[]);
+    int fwReloadSoftap(int argc, char *argv[]);
 };
 
 #endif