OSDN Git Service

Clean up softap interface
authorIrfan Sheriff <isheriff@google.com>
Fri, 15 Jun 2012 23:11:31 +0000 (16:11 -0700)
committerIrfan Sheriff <isheriff@google.com>
Tue, 19 Jun 2012 22:37:57 +0000 (15:37 -0700)
Remove old IOCTL based interface

Change-Id: I5c46964d025848ce8a0e0195ff213ccd8b33d508

Android.mk
CommandListener.cpp
SoftapController.cpp
SoftapController.h

index 655038d..cdaa184 100644 (file)
@@ -42,10 +42,6 @@ LOCAL_CFLAGS := -Werror=format
 LOCAL_SHARED_LIBRARIES := libstlport libsysutils libcutils libnetutils \
                           libcrypto libhardware_legacy libmdnssd
 
-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
index 97e2fa2..56b72b2 100644 (file)
@@ -757,11 +757,7 @@ int CommandListener::SoftapCmd::runCommand(SocketClient *cli,
         return 0;
     }
 
-    if (!strcmp(argv[1], "start")) {
-        rc = sSoftapCtrl->startDriver(argv[2]);
-    } else if (!strcmp(argv[1], "stop")) {
-        rc = sSoftapCtrl->stopDriver(argv[2]);
-    } else if (!strcmp(argv[1], "startap")) {
+    if (!strcmp(argv[1], "startap")) {
         rc = sSoftapCtrl->startSoftap();
     } else if (!strcmp(argv[1], "stopap")) {
         rc = sSoftapCtrl->stopSoftap();
index ce41544..c4dcc7f 100644 (file)
@@ -48,7 +48,6 @@ SoftapController::SoftapController() {
     mSock = socket(AF_INET, SOCK_DGRAM, 0);
     if (mSock < 0)
         ALOGE("Failed to open socket");
-    memset(mIface, 0, sizeof(mIface));
 }
 
 SoftapController::~SoftapController() {
@@ -56,118 +55,6 @@ SoftapController::~SoftapController() {
         close(mSock);
 }
 
-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;
-    int i, j, ret;
-    int cmd = 0, sub_cmd = 0;
-
-    strncpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
-    wrq.u.data.pointer = tBuf;
-    wrq.u.data.length = sizeof(tBuf) / sizeof(struct iw_priv_args);
-    wrq.u.data.flags = 0;
-    if ((ret = ioctl(mSock, SIOCGIWPRIV, &wrq)) < 0) {
-        ALOGE("SIOCGIPRIV failed: %d", ret);
-        return ret;
-    }
-
-    priv_ptr = (struct iw_priv_args *)wrq.u.data.pointer;
-    for(i=0; i < wrq.u.data.length;i++) {
-        if (strcmp(priv_ptr[i].name, fname) == 0) {
-            cmd = priv_ptr[i].cmd;
-            break;
-        }
-    }
-
-    if (i == wrq.u.data.length) {
-        ALOGE("iface:%s, fname: %s - function not supported", iface, fname);
-        return -1;
-    }
-
-    if (cmd < SIOCDEVPRIVATE) {
-        for(j=0; j < i; j++) {
-            if ((priv_ptr[j].set_args == priv_ptr[i].set_args) &&
-                (priv_ptr[j].get_args == priv_ptr[i].get_args) &&
-                (priv_ptr[j].name[0] == '\0'))
-                break;
-        }
-        if (j == i) {
-            ALOGE("iface:%s, fname: %s - invalid private ioctl", iface, fname);
-            return -1;
-        }
-        sub_cmd = cmd;
-        cmd = priv_ptr[j].cmd;
-    }
-
-    strncpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
-    if ((buflen == 0) && (*mBuf != 0))
-        wrq.u.data.length = strlen(mBuf) + 1;
-    else
-        wrq.u.data.length = buflen;
-    wrq.u.data.pointer = mBuf;
-    wrq.u.data.flags = sub_cmd;
-    ret = ioctl(mSock, cmd, &wrq);
-    return ret;
-#endif
-}
-
-int SoftapController::startDriver(char *iface) {
-    int ret;
-
-    if (mSock < 0) {
-        ALOGE("Softap driver start - failed to open socket");
-        return -1;
-    }
-    if (!iface || (iface[0] == '\0')) {
-        ALOGD("Softap driver start - wrong interface");
-        iface = mIface;
-    }
-
-    *mBuf = 0;
-    ret = setCommand(iface, "START");
-    if (ret < 0) {
-        ALOGE("Softap driver start: %d", ret);
-        return ret;
-    }
-#ifdef HAVE_HOSTAPD
-    ifc_init();
-    ret = ifc_up(iface);
-    ifc_close();
-#endif
-    usleep(AP_DRIVER_START_DELAY);
-    ALOGD("Softap driver start: %d", ret);
-    return ret;
-}
-
-int SoftapController::stopDriver(char *iface) {
-    int ret;
-
-    if (mSock < 0) {
-        ALOGE("Softap driver stop - failed to open socket");
-        return -1;
-    }
-    if (!iface || (iface[0] == '\0')) {
-        ALOGD("Softap driver stop - wrong interface");
-        iface = mIface;
-    }
-    *mBuf = 0;
-#ifdef HAVE_HOSTAPD
-    ifc_init();
-    ret = ifc_down(iface);
-    ifc_close();
-    if (ret < 0) {
-        ALOGE("Softap %s down: %d", iface, ret);
-    }
-#endif
-    ret = setCommand(iface, "STOP");
-    ALOGD("Softap driver stop: %d", ret);
-    return ret;
-}
-
 int SoftapController::startSoftap() {
     pid_t pid = 1;
     int ret = 0;
@@ -180,90 +67,64 @@ int SoftapController::startSoftap() {
         ALOGE("Softap startap - failed to open socket");
         return -1;
     }
-#ifdef HAVE_HOSTAPD
+
     if ((pid = fork()) < 0) {
         ALOGE("fork failed (%s)", strerror(errno));
         return -1;
     }
-#endif
+
     if (!pid) {
-#ifdef HAVE_HOSTAPD
         ensure_entropy_file_exists();
         if (execl("/system/bin/hostapd", "/system/bin/hostapd",
                   "-e", WIFI_ENTROPY_FILE,
                   HOSTAPD_CONF_FILE, (char *) NULL)) {
             ALOGE("execl failed (%s)", strerror(errno));
         }
-#endif
         ALOGE("Should never get here!");
         return -1;
     } else {
-        *mBuf = 0;
-        ret = setCommand(mIface, "AP_BSS_START");
-        if (ret) {
-            ALOGE("Softap startap - failed: %d", ret);
-        }
-        else {
-           mPid = pid;
-           ALOGD("Softap startap - Ok");
-           usleep(AP_BSS_START_DELAY);
-        }
+        mPid = pid;
+        ALOGD("Softap startap - Ok");
+        usleep(AP_BSS_START_DELAY);
     }
     return ret;
 
 }
 
 int SoftapController::stopSoftap() {
-    int ret;
 
     if (mPid == 0) {
         ALOGE("Softap already stopped");
         return 0;
     }
 
-#ifdef HAVE_HOSTAPD
     ALOGD("Stopping Softap service");
     kill(mPid, SIGTERM);
     waitpid(mPid, NULL, 0);
-#endif
+
     if (mSock < 0) {
         ALOGE("Softap stopap - failed to open socket");
         return -1;
     }
-    *mBuf = 0;
-    ret = setCommand(mIface, "AP_BSS_STOP");
     mPid = 0;
-    ALOGD("Softap service stopped: %d", ret);
+    ALOGD("Softap service stopped");
     usleep(AP_BSS_STOP_DELAY);
-    return ret;
+    return 0;
 }
 
 bool SoftapController::isSoftapStarted() {
     return (mPid != 0 ? true : false);
 }
 
-int SoftapController::addParam(int pos, const char *cmd, const char *arg)
-{
-    if (pos < 0)
-        return pos;
-    if ((unsigned)(pos + strlen(cmd) + strlen(arg) + 1) >= sizeof(mBuf)) {
-        ALOGE("Command line is too big");
-        return -1;
-    }
-    pos += sprintf(&mBuf[pos], "%s=%s,", cmd, arg);
-    return pos;
-}
-
 /*
  * Arguments:
  *      argv[2] - wlan interface
- *      argv[3] - softap interface
- *      argv[4] - SSID
- *     argv[5] - Security
- *     argv[6] - Key
- *     argv[7] - Channel
- *     argv[8] - Preamble
- *     argv[9] - Max SCB
+ *      argv[3] - SSID
+ *     argv[4] - Security
+ *     argv[5] - Key
+ *     argv[6] - Channel
+ *     argv[7] - Preamble
+ *     argv[8] - Max SCB
  */
 int SoftapController::setSoftap(int argc, char *argv[]) {
     char psk_str[2*SHA256_DIGEST_LENGTH+1];
@@ -279,15 +140,13 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
         return -1;
     }
 
-    strncpy(mIface, argv[3], sizeof(mIface));
     iface = argv[2];
 
-#ifdef HAVE_HOSTAPD
     char *wbuf = NULL;
     char *fbuf = NULL;
 
-    if (argc > 4) {
-        ssid = argv[4];
+    if (argc > 3) {
+        ssid = argv[3];
     } else {
         ssid = (char *)"AndroidAP";
     }
@@ -296,14 +155,14 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
             "/data/misc/wifi/hostapd\nssid=%s\nchannel=6\nieee80211n=1\n",
             iface, ssid);
 
-    if (argc > 5) {
-        if (!strcmp(argv[5], "wpa-psk")) {
-            generatePsk(ssid, argv[6], psk_str);
+    if (argc > 4) {
+        if (!strcmp(argv[4], "wpa-psk")) {
+            generatePsk(ssid, argv[5], psk_str);
             asprintf(&fbuf, "%swpa=1\nwpa_pairwise=TKIP CCMP\nwpa_psk=%s\n", wbuf, psk_str);
-        } else if (!strcmp(argv[5], "wpa2-psk")) {
-            generatePsk(ssid, argv[6], psk_str);
+        } else if (!strcmp(argv[4], "wpa2-psk")) {
+            generatePsk(ssid, argv[5], psk_str);
             asprintf(&fbuf, "%swpa=2\nrsn_pairwise=CCMP\nwpa_psk=%s\n", wbuf, psk_str);
-        } else if (!strcmp(argv[5], "open")) {
+        } else if (!strcmp(argv[4], "open")) {
             asprintf(&fbuf, "%s", wbuf);
         }
     } else {
@@ -340,57 +199,6 @@ int SoftapController::setSoftap(int argc, char *argv[]) {
         return -1;
     }
 
-#else
-    /* Create command line */
-    i = addParam(i, "ASCII_CMD", "AP_CFG");
-    if (argc > 4) {
-        ssid = argv[4];
-    } else {
-        ssid = (char *)"AndroidAP";
-    }
-    i = addParam(i, "SSID", ssid);
-    if (argc > 5) {
-        i = addParam(i, "SEC", argv[5]);
-    } else {
-        i = addParam(i, "SEC", "open");
-    }
-    if (argc > 6) {
-        generatePsk(ssid, argv[6], psk_str);
-        i = addParam(i, "KEY", psk_str);
-    } else {
-        i = addParam(i, "KEY", "12345678");
-    }
-    if (argc > 7) {
-        i = addParam(i, "CHANNEL", argv[7]);
-    } else {
-        i = addParam(i, "CHANNEL", "6");
-    }
-    if (argc > 8) {
-        i = addParam(i, "PREAMBLE", argv[8]);
-    } else {
-        i = addParam(i, "PREAMBLE", "0");
-    }
-    if (argc > 9) {
-        i = addParam(i, "MAX_SCB", argv[9]);
-    } else {
-        i = addParam(i, "MAX_SCB", "8");
-    }
-    if ((i < 0) || ((unsigned)(i + 4) >= sizeof(mBuf))) {
-        ALOGE("Softap set - command is too big");
-        return i;
-    }
-    sprintf(&mBuf[i], "END");
-
-    /* system("iwpriv eth0 WL_AP_CFG ASCII_CMD=AP_CFG,SSID=\"AndroidAP\",SEC=\"open\",KEY=12345,CHANNEL=1,PREAMBLE=0,MAX_SCB=8,END"); */
-    ret = setCommand(iface, "AP_SET_CFG");
-    if (ret) {
-        ALOGE("Softap set - failed: %d", ret);
-    }
-    else {
-        ALOGD("Softap set - Ok");
-        usleep(AP_SET_CFG_DELAY);
-    }
-#endif
     return ret;
 }
 
@@ -439,12 +247,7 @@ 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) {
         ALOGE("Softap fwReload - failed: %d", ret);
     }
@@ -456,19 +259,6 @@ int SoftapController::fwReloadSoftap(int argc, char *argv[])
 
 int SoftapController::clientsSoftap(char **retbuf)
 {
-    int ret;
-
-    if (mSock < 0) {
-        ALOGE("Softap clients - failed to open socket");
-        return -1;
-    }
-    *mBuf = 0;
-    ret = setCommand(mIface, "AP_GET_STA_LIST", SOFTAP_MAX_BUFFER_SIZE);
-    if (ret) {
-        ALOGE("Softap clients - failed: %d", ret);
-    } else {
-        asprintf(retbuf, "Softap clients:%s", mBuf);
-        ALOGD("Softap clients:%s", mBuf);
-    }
-    return ret;
+    /* TODO: implement over hostapd */
+    return 0;
 }
index 0d275d2..57241b9 100644 (file)
@@ -27,8 +27,6 @@
 #define AP_DRIVER_START_DELAY  800000
 
 class SoftapController {
-    char mBuf[SOFTAP_MAX_BUFFER_SIZE];
-    char mIface[IFNAMSIZ];
     pid_t mPid;
     int mSock;
 
@@ -38,8 +36,6 @@ public:
     SoftapController();
     virtual ~SoftapController();
 
-    int startDriver(char *iface);
-    int stopDriver(char *iface);
     int startSoftap();
     int stopSoftap();
     bool isSoftapStarted();