Loading nexus/CommandListener.cpp +24 −19 Original line number Diff line number Diff line Loading @@ -47,11 +47,11 @@ CommandListener::WifiEnableCmd::WifiEnableCmd() : int CommandListener::WifiEnableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("WIFI"); char buffer[32]; sprintf(buffer, "WIFI_ENABLE:%d", (c->enable() ? errno : 0)); cli->sendMsg(buffer); if (c->enable()) cli->sendMsg(400, "Failed to enable wifi", true); else cli->sendMsg(200, "Wifi Enabled", false); return 0; } Loading @@ -61,10 +61,11 @@ CommandListener::WifiDisableCmd::WifiDisableCmd() : int CommandListener::WifiDisableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("WIFI"); char buffer[32]; sprintf(buffer, "WIFI_DISABLE:%d", (c->disable() ? errno : 0)); cli->sendMsg(buffer); if (c->disable()) cli->sendMsg(400, "Failed to disable wifi", true); else cli->sendMsg(200, "Wifi Disabled", false); return 0; } Loading @@ -77,7 +78,6 @@ int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) { WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI"); char buffer[32]; int mode = 0; char *bword, *last; Loading @@ -93,8 +93,11 @@ int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) { mode = atoi(bword); sprintf(buffer, "WIFI_SCAN:%d", (wc->setScanMode(mode) ? errno : 0)); cli->sendMsg(buffer); if (wc->setScanMode(mode)) cli->sendMsg(400, "Failed to set scan mode", true); else cli->sendMsg(200, "Scan mode set", false); return 0; } Loading @@ -112,16 +115,16 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *dat char buffer[256]; for(it = src->begin(); it != src->end(); ++it) { sprintf(buffer, "WIFI_SCAN_RESULT:%s:%u:%d:%s:%s", sprintf(buffer, "%s:%u:%d:%s:%s", (*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(), (*it)->getFlags(), (*it)->getSsid()); cli->sendMsg(buffer); cli->sendMsg(125, buffer, false); delete (*it); it = src->erase(it); } delete src; cli->sendMsg("WIFI_SCAN_RESULT:0"); cli->sendMsg(200, "Scan results complete", false); return 0; } Loading @@ -134,10 +137,11 @@ CommandListener::VpnEnableCmd::VpnEnableCmd() : int CommandListener::VpnEnableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("VPN"); char buffer[32]; sprintf(buffer, "VPN_ENABLE:%d", (c->enable() ? errno : 0)); cli->sendMsg(buffer); if (c->enable()) cli->sendMsg(400, "Failed to enable VPN", true); else cli->sendMsg(200, "VPN enabled", false); return 0; } Loading @@ -147,9 +151,10 @@ CommandListener::VpnDisableCmd::VpnDisableCmd() : int CommandListener::VpnDisableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("VPN"); char buffer[32]; sprintf(buffer, "VPN_DISABLE:%d", (c->disable() ? errno : 0)); cli->sendMsg(buffer); if (c->disable()) cli->sendMsg(400, "Failed to disable VPN", true); else cli->sendMsg(200, "VPN disabled", false); return 0; } nexus/ScanResult.cpp +41 −17 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <stdlib.h> #include <ctype.h> #define LOG_TAG "ScanResult" #include <cutils/log.h> Loading @@ -24,30 +25,53 @@ ScanResult::ScanResult() { } ScanResult::ScanResult(char *rawResult) { char *tok, *next = NULL; char *p = rawResult, *q = rawResult; char tmp[255]; if (!(tok = strtok_r(rawResult, "\t", &next))) goto out_bad; mBssid = strdup(tok); // BSSID for (q = p; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mBssid = strdup(tmp); ++q; if (!(tok = strtok_r(NULL, "\t", &next))) goto out_bad; mFreq = atoi(tok); // FREQ for (p = q; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mFreq = atoi(tmp); ++q; if (!(tok = strtok_r(NULL, "\t", &next))) goto out_bad; mLevel = atoi(tok); // LEVEL for (p = q; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mLevel = atoi(tmp); ++q; if (!(tok = strtok_r(rawResult, "\t", &next))) goto out_bad; mFlags = strdup(tok); // FLAGS for (p = q; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mFlags = strdup(tmp); ++q; if (!(tok = strtok_r(rawResult, "\t", &next))) goto out_bad; mSsid = strdup(tok); // XXX: For some reason Supplicant sometimes sends a double-tab here. // haven't had time to dig into it ... if (*q == '\t') q++; return; for (p = q; *q != '\t'; ++q) { if (*q == '\0') break; } strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mSsid = strdup(tmp); ++q; return; out_bad: LOGW("Malformatted scan result (%s)", rawResult); } Loading nexus/Supplicant.cpp +64 −7 Original line number Diff line number Diff line Loading @@ -15,12 +15,16 @@ */ #include <stdlib.h> #include <sys/types.h> #include <fcntl.h> #include <errno.h> #define LOG_TAG "Supplicant" #include <cutils/log.h> #include <cutils/properties.h> #include "private/android_filesystem_config.h" #undef HAVE_LIBC_SYSTEM_PROPERTIES #ifdef HAVE_LIBC_SYSTEM_PROPERTIES Loading @@ -41,6 +45,9 @@ #define DRIVER_PROP_NAME "wlan.driver.status" #define SUPPLICANT_NAME "wpa_supplicant" #define SUPP_PROP_NAME "init.svc.wpa_supplicant" #define SUPP_CONFIG_TEMPLATE "/system/etc/wifi/wpa_supplicant.conf" #define SUPP_CONFIG_FILE "/data/misc/wifi/wpa_supplicant.conf" Supplicant::Supplicant() { mCtrl = NULL; Loading @@ -55,7 +62,10 @@ Supplicant::Supplicant() { } int Supplicant::start() { // XXX: Validate supplicant config file if (setupConfig()) { LOGW("Unable to setup supplicant.conf"); } char status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; Loading @@ -66,7 +76,6 @@ int Supplicant::start() { if (property_get(SUPP_PROP_NAME, status, NULL) && !strcmp(status, "running")) { LOGD("Supplicant already started"); } else { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES pi = __system_property_find(SUPP_PROP_NAME); Loading @@ -93,7 +102,7 @@ int Supplicant::start() { } #else if (property_get(SUPP_PROP_NAME, status, NULL)) { if (strcmp(status, "running") == 0) if (!strcmp(status, "running")) break; } #endif Loading Loading @@ -348,9 +357,9 @@ int Supplicant::onScanResultsEvent(SupplicantEvent *evt) { while((linep = strtok_r(NULL, "\n", &linep_next))) mLatestScanResults->push_back(new ScanResult(linep)); char tmp[32]; sprintf(tmp, "WIFI_SCAN_RESULTS_READY:%d", mLatestScanResults->size()); NetworkManager::Instance()->getBroadcaster()->sendBroadcast(tmp); char tmp[128]; sprintf(tmp, "%d scan results ready", mLatestScanResults->size()); NetworkManager::Instance()->getBroadcaster()->sendBroadcast(600, tmp, false); pthread_mutex_unlock(&mLatestScanResultsLock); free(reply); } else { Loading Loading @@ -403,4 +412,52 @@ ScanResultCollection *Supplicant::createLatestScanResults() { pthread_mutex_unlock(&mLatestScanResultsLock); return d; }; } int Supplicant::setupConfig() { char buf[2048]; int srcfd, destfd; int nread; if (access(SUPP_CONFIG_FILE, R_OK|W_OK) == 0) { return 0; } else if (errno != ENOENT) { LOGE("Cannot access \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); return -1; } srcfd = open(SUPP_CONFIG_TEMPLATE, O_RDONLY); if (srcfd < 0) { LOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno)); return -1; } destfd = open(SUPP_CONFIG_FILE, O_CREAT|O_WRONLY, 0660); if (destfd < 0) { close(srcfd); LOGE("Cannot create \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); return -1; } while ((nread = read(srcfd, buf, sizeof(buf))) != 0) { if (nread < 0) { LOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno)); close(srcfd); close(destfd); unlink(SUPP_CONFIG_FILE); return -1; } write(destfd, buf, nread); } close(destfd); close(srcfd); if (chown(SUPP_CONFIG_FILE, AID_SYSTEM, AID_WIFI) < 0) { LOGE("Error changing group ownership of %s to %d: %s", SUPP_CONFIG_FILE, AID_WIFI, strerror(errno)); unlink(SUPP_CONFIG_FILE); return -1; } return 0; } nexus/Supplicant.h +1 −0 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ public: private: int connectToSupplicant(); int sendCommand(const char *cmd, char *reply, size_t *reply_len); int setupConfig(); }; #endif nexus/TiwlanWifiController.cpp +1 −10 Original line number Diff line number Diff line Loading @@ -67,15 +67,6 @@ int TiwlanWifiController::loadFirmware() { } bool TiwlanWifiController::isFirmwareLoaded() { char driver_status[PROPERTY_VALUE_MAX]; if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) { if (!strcmp(driver_status, "ok")) return true; else { LOGD("Driver status '%s'", driver_status); return false; } } LOGW("Unable to get property '%s'", DRIVER_PROP_NAME); // Always load the firmware return false; } Loading
nexus/CommandListener.cpp +24 −19 Original line number Diff line number Diff line Loading @@ -47,11 +47,11 @@ CommandListener::WifiEnableCmd::WifiEnableCmd() : int CommandListener::WifiEnableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("WIFI"); char buffer[32]; sprintf(buffer, "WIFI_ENABLE:%d", (c->enable() ? errno : 0)); cli->sendMsg(buffer); if (c->enable()) cli->sendMsg(400, "Failed to enable wifi", true); else cli->sendMsg(200, "Wifi Enabled", false); return 0; } Loading @@ -61,10 +61,11 @@ CommandListener::WifiDisableCmd::WifiDisableCmd() : int CommandListener::WifiDisableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("WIFI"); char buffer[32]; sprintf(buffer, "WIFI_DISABLE:%d", (c->disable() ? errno : 0)); cli->sendMsg(buffer); if (c->disable()) cli->sendMsg(400, "Failed to disable wifi", true); else cli->sendMsg(200, "Wifi Disabled", false); return 0; } Loading @@ -77,7 +78,6 @@ int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) { WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI"); char buffer[32]; int mode = 0; char *bword, *last; Loading @@ -93,8 +93,11 @@ int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) { mode = atoi(bword); sprintf(buffer, "WIFI_SCAN:%d", (wc->setScanMode(mode) ? errno : 0)); cli->sendMsg(buffer); if (wc->setScanMode(mode)) cli->sendMsg(400, "Failed to set scan mode", true); else cli->sendMsg(200, "Scan mode set", false); return 0; } Loading @@ -112,16 +115,16 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *dat char buffer[256]; for(it = src->begin(); it != src->end(); ++it) { sprintf(buffer, "WIFI_SCAN_RESULT:%s:%u:%d:%s:%s", sprintf(buffer, "%s:%u:%d:%s:%s", (*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(), (*it)->getFlags(), (*it)->getSsid()); cli->sendMsg(buffer); cli->sendMsg(125, buffer, false); delete (*it); it = src->erase(it); } delete src; cli->sendMsg("WIFI_SCAN_RESULT:0"); cli->sendMsg(200, "Scan results complete", false); return 0; } Loading @@ -134,10 +137,11 @@ CommandListener::VpnEnableCmd::VpnEnableCmd() : int CommandListener::VpnEnableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("VPN"); char buffer[32]; sprintf(buffer, "VPN_ENABLE:%d", (c->enable() ? errno : 0)); cli->sendMsg(buffer); if (c->enable()) cli->sendMsg(400, "Failed to enable VPN", true); else cli->sendMsg(200, "VPN enabled", false); return 0; } Loading @@ -147,9 +151,10 @@ CommandListener::VpnDisableCmd::VpnDisableCmd() : int CommandListener::VpnDisableCmd::runCommand(SocketClient *cli, char *data) { Controller *c = NetworkManager::Instance()->findController("VPN"); char buffer[32]; sprintf(buffer, "VPN_DISABLE:%d", (c->disable() ? errno : 0)); cli->sendMsg(buffer); if (c->disable()) cli->sendMsg(400, "Failed to disable VPN", true); else cli->sendMsg(200, "VPN disabled", false); return 0; }
nexus/ScanResult.cpp +41 −17 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <stdlib.h> #include <ctype.h> #define LOG_TAG "ScanResult" #include <cutils/log.h> Loading @@ -24,30 +25,53 @@ ScanResult::ScanResult() { } ScanResult::ScanResult(char *rawResult) { char *tok, *next = NULL; char *p = rawResult, *q = rawResult; char tmp[255]; if (!(tok = strtok_r(rawResult, "\t", &next))) goto out_bad; mBssid = strdup(tok); // BSSID for (q = p; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mBssid = strdup(tmp); ++q; if (!(tok = strtok_r(NULL, "\t", &next))) goto out_bad; mFreq = atoi(tok); // FREQ for (p = q; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mFreq = atoi(tmp); ++q; if (!(tok = strtok_r(NULL, "\t", &next))) goto out_bad; mLevel = atoi(tok); // LEVEL for (p = q; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mLevel = atoi(tmp); ++q; if (!(tok = strtok_r(rawResult, "\t", &next))) goto out_bad; mFlags = strdup(tok); // FLAGS for (p = q; *q != '\t'; ++q); strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mFlags = strdup(tmp); ++q; if (!(tok = strtok_r(rawResult, "\t", &next))) goto out_bad; mSsid = strdup(tok); // XXX: For some reason Supplicant sometimes sends a double-tab here. // haven't had time to dig into it ... if (*q == '\t') q++; return; for (p = q; *q != '\t'; ++q) { if (*q == '\0') break; } strncpy(tmp, p, (q - p)); tmp[q-p] = '\0'; mSsid = strdup(tmp); ++q; return; out_bad: LOGW("Malformatted scan result (%s)", rawResult); } Loading
nexus/Supplicant.cpp +64 −7 Original line number Diff line number Diff line Loading @@ -15,12 +15,16 @@ */ #include <stdlib.h> #include <sys/types.h> #include <fcntl.h> #include <errno.h> #define LOG_TAG "Supplicant" #include <cutils/log.h> #include <cutils/properties.h> #include "private/android_filesystem_config.h" #undef HAVE_LIBC_SYSTEM_PROPERTIES #ifdef HAVE_LIBC_SYSTEM_PROPERTIES Loading @@ -41,6 +45,9 @@ #define DRIVER_PROP_NAME "wlan.driver.status" #define SUPPLICANT_NAME "wpa_supplicant" #define SUPP_PROP_NAME "init.svc.wpa_supplicant" #define SUPP_CONFIG_TEMPLATE "/system/etc/wifi/wpa_supplicant.conf" #define SUPP_CONFIG_FILE "/data/misc/wifi/wpa_supplicant.conf" Supplicant::Supplicant() { mCtrl = NULL; Loading @@ -55,7 +62,10 @@ Supplicant::Supplicant() { } int Supplicant::start() { // XXX: Validate supplicant config file if (setupConfig()) { LOGW("Unable to setup supplicant.conf"); } char status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; Loading @@ -66,7 +76,6 @@ int Supplicant::start() { if (property_get(SUPP_PROP_NAME, status, NULL) && !strcmp(status, "running")) { LOGD("Supplicant already started"); } else { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES pi = __system_property_find(SUPP_PROP_NAME); Loading @@ -93,7 +102,7 @@ int Supplicant::start() { } #else if (property_get(SUPP_PROP_NAME, status, NULL)) { if (strcmp(status, "running") == 0) if (!strcmp(status, "running")) break; } #endif Loading Loading @@ -348,9 +357,9 @@ int Supplicant::onScanResultsEvent(SupplicantEvent *evt) { while((linep = strtok_r(NULL, "\n", &linep_next))) mLatestScanResults->push_back(new ScanResult(linep)); char tmp[32]; sprintf(tmp, "WIFI_SCAN_RESULTS_READY:%d", mLatestScanResults->size()); NetworkManager::Instance()->getBroadcaster()->sendBroadcast(tmp); char tmp[128]; sprintf(tmp, "%d scan results ready", mLatestScanResults->size()); NetworkManager::Instance()->getBroadcaster()->sendBroadcast(600, tmp, false); pthread_mutex_unlock(&mLatestScanResultsLock); free(reply); } else { Loading Loading @@ -403,4 +412,52 @@ ScanResultCollection *Supplicant::createLatestScanResults() { pthread_mutex_unlock(&mLatestScanResultsLock); return d; }; } int Supplicant::setupConfig() { char buf[2048]; int srcfd, destfd; int nread; if (access(SUPP_CONFIG_FILE, R_OK|W_OK) == 0) { return 0; } else if (errno != ENOENT) { LOGE("Cannot access \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); return -1; } srcfd = open(SUPP_CONFIG_TEMPLATE, O_RDONLY); if (srcfd < 0) { LOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno)); return -1; } destfd = open(SUPP_CONFIG_FILE, O_CREAT|O_WRONLY, 0660); if (destfd < 0) { close(srcfd); LOGE("Cannot create \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); return -1; } while ((nread = read(srcfd, buf, sizeof(buf))) != 0) { if (nread < 0) { LOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno)); close(srcfd); close(destfd); unlink(SUPP_CONFIG_FILE); return -1; } write(destfd, buf, nread); } close(destfd); close(srcfd); if (chown(SUPP_CONFIG_FILE, AID_SYSTEM, AID_WIFI) < 0) { LOGE("Error changing group ownership of %s to %d: %s", SUPP_CONFIG_FILE, AID_WIFI, strerror(errno)); unlink(SUPP_CONFIG_FILE); return -1; } return 0; }
nexus/Supplicant.h +1 −0 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ public: private: int connectToSupplicant(); int sendCommand(const char *cmd, char *reply, size_t *reply_len); int setupConfig(); }; #endif
nexus/TiwlanWifiController.cpp +1 −10 Original line number Diff line number Diff line Loading @@ -67,15 +67,6 @@ int TiwlanWifiController::loadFirmware() { } bool TiwlanWifiController::isFirmwareLoaded() { char driver_status[PROPERTY_VALUE_MAX]; if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) { if (!strcmp(driver_status, "ok")) return true; else { LOGD("Driver status '%s'", driver_status); return false; } } LOGW("Unable to get property '%s'", DRIVER_PROP_NAME); // Always load the firmware return false; }