Softap: Add 'clients' command
Change-Id: I3694a0b2b570e0925b7f807f133e6fa5d95c3ac2
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/CommandListener.cpp b/CommandListener.cpp
index 41fdf0a..3f35d9c 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -588,6 +588,7 @@
int CommandListener::SoftapCmd::runCommand(SocketClient *cli,
int argc, char **argv) {
int rc = 0, flag = 0;
+ char *retbuf = NULL;
if (argc < 2) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Missing argument", false);
@@ -604,13 +605,18 @@
rc = sSoftapCtrl->stopSoftap();
} else if (!strcmp(argv[1], "fwreload")) {
rc = sSoftapCtrl->fwReloadSoftap(argc, argv);
+ } else if (!strcmp(argv[1], "clients")) {
+ rc = sSoftapCtrl->clientsSoftap(&retbuf);
+ if (!rc) {
+ cli->sendMsg(ResponseCode::CommandOkay, retbuf, false);
+ free(retbuf);
+ return 0;
+ }
} else if (!strcmp(argv[1], "status")) {
- char *tmp = NULL;
-
- asprintf(&tmp, "Softap service %s",
+ asprintf(&retbuf, "Softap service %s",
(sSoftapCtrl->isSoftapStarted() ? "started" : "stopped"));
- cli->sendMsg(ResponseCode::SoftapStatusResult, tmp, false);
- free(tmp);
+ cli->sendMsg(ResponseCode::SoftapStatusResult, retbuf, false);
+ free(retbuf);
return 0;
} else if (!strcmp(argv[1], "set")) {
rc = sSoftapCtrl->setSoftap(argc, argv);
diff --git a/SoftapController.cpp b/SoftapController.cpp
index 1f42214..6039761 100644
--- a/SoftapController.cpp
+++ b/SoftapController.cpp
@@ -51,7 +51,7 @@
close(mSock);
}
-int SoftapController::setCommand(char *iface, const char *fname) {
+int SoftapController::setCommand(char *iface, const char *fname, unsigned buflen) {
char tBuf[SOFTAP_MAX_BUFFER_SIZE];
struct iwreq wrq;
struct iw_priv_args *priv_ptr;
@@ -96,10 +96,10 @@
}
strncpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
- if (*mBuf != 0)
+ if ((buflen == 0) && (*mBuf != 0))
wrq.u.data.length = strlen(mBuf) + 1;
else
- wrq.u.data.length = 0;
+ wrq.u.data.length = buflen;
wrq.u.data.pointer = mBuf;
wrq.u.data.flags = sub_cmd;
ret = ioctl(mSock, cmd, &wrq);
@@ -348,3 +348,22 @@
}
return ret;
}
+
+int SoftapController::clientsSoftap(char **retbuf)
+{
+ int ret;
+
+ if (mSock < 0) {
+ LOGE("Softap clients - failed to open socket");
+ return -1;
+ }
+ *mBuf = 0;
+ ret = setCommand(mIface, "AP_GET_STA_LIST", SOFTAP_MAX_BUFFER_SIZE);
+ if (ret) {
+ LOGE("Softap clients - failed: %d", ret);
+ } else {
+ asprintf(retbuf, "Softap clients:%s", mBuf);
+ LOGD("Softap clients:%s", mBuf);
+ }
+ return ret;
+}
diff --git a/SoftapController.h b/SoftapController.h
index 60236f8..7801577 100644
--- a/SoftapController.h
+++ b/SoftapController.h
@@ -34,7 +34,7 @@
int mSock;
int addParam(int pos, const char *cmd, const char *arg);
- int setCommand(char *iface, const char *fname);
+ int setCommand(char *iface, const char *fname, unsigned buflen=0);
public:
SoftapController();
virtual ~SoftapController();
@@ -46,6 +46,7 @@
bool isSoftapStarted();
int setSoftap(int argc, char *argv[]);
int fwReloadSoftap(int argc, char *argv[]);
+ int clientsSoftap(char **retbuf);
};
#endif