summaryrefslogtreecommitdiffstats
path: root/nexus/WifiController.cpp
diff options
context:
space:
mode:
authorSan Mehat <san@google.com>2009-05-07 11:37:10 -0700
committerSan Mehat <san@google.com>2009-05-09 10:33:18 -0700
commit1441e769b2767e212a3d905bee2fd3535b484ff2 (patch)
tree726f46620c2e9c4063ed9ecdd7e0cafcb6b6005e /nexus/WifiController.cpp
parentb3779558dcfbe99f0b9c1ef796e3728edad25672 (diff)
downloadsystem_core-1441e769b2767e212a3d905bee2fd3535b484ff2.zip
system_core-1441e769b2767e212a3d905bee2fd3535b484ff2.tar.gz
system_core-1441e769b2767e212a3d905bee2fd3535b484ff2.tar.bz2
nexus: Implement wifi scanner and fix a lot of bugs
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'nexus/WifiController.cpp')
-rw-r--r--nexus/WifiController.cpp79
1 files changed, 50 insertions, 29 deletions
diff --git a/nexus/WifiController.cpp b/nexus/WifiController.cpp
index 8a7e33f..806141c 100644
--- a/nexus/WifiController.cpp
+++ b/nexus/WifiController.cpp
@@ -21,6 +21,8 @@
#include "Supplicant.h"
#include "WifiController.h"
+#include "WifiScanner.h"
+#include "NetworkManager.h"
WifiController::WifiController(char *modpath, char *modname, char *modargs) :
Controller("WIFI") {
@@ -29,6 +31,7 @@ WifiController::WifiController(char *modpath, char *modname, char *modargs) :
strncpy(mModuleArgs, modargs, sizeof(mModuleArgs));
mSupplicant = new Supplicant();
+ mScanner = new WifiScanner(mSupplicant, 10);
mCurrentScanMode = 0;
}
@@ -42,26 +45,36 @@ int WifiController::stop() {
}
int WifiController::enable() {
- if (!isPoweredUp() && powerUp()) {
- LOGE("Powerup failed (%s)", strerror(errno));
- return -1;
+ if (!isPoweredUp()) {
+ sendStatusBroadcast("POWERING_UP");
+ if (powerUp()) {
+ LOGE("Powerup failed (%s)", strerror(errno));
+ return -1;
+ }
}
-
+
if (mModuleName[0] != '\0' && !isKernelModuleLoaded(mModuleName)) {
+ sendStatusBroadcast("LOADING_DRIVER");
if (loadKernelModule(mModulePath, mModuleArgs)) {
LOGE("Kernel module load failed (%s)", strerror(errno));
goto out_powerdown;
}
}
- if (loadFirmware()) {
- LOGE("Firmware load failed (%s)", strerror(errno));
- goto out_powerdown;
+ if (!isFirmwareLoaded()) {
+ sendStatusBroadcast("LOADING_FIRMWARE");
+ if (loadFirmware()) {
+ LOGE("Firmware load failed (%s)", strerror(errno));
+ goto out_powerdown;
+ }
}
- if (!mSupplicant->isStarted() && mSupplicant->start()) {
- LOGE("Supplicant start failed (%s)", strerror(errno));
- goto out_unloadmodule;
+ if (!mSupplicant->isStarted()) {
+ sendStatusBroadcast("STARTING_SUPPLICANT");
+ if (mSupplicant->start()) {
+ LOGE("Supplicant start failed (%s)", strerror(errno));
+ goto out_unloadmodule;
+ }
}
return 0;
@@ -80,24 +93,38 @@ out_powerdown:
return -1;
}
+void WifiController::sendStatusBroadcast(const char *msg) {
+ char tmp[255];
+
+ sprintf(tmp, "WIFI_STATUS:%s", msg);
+ NetworkManager::Instance()->getBroadcaster()->sendBroadcast(tmp);
+}
+
int WifiController::disable() {
- LOGD("disable()");
- if (mSupplicant->isStarted() && mSupplicant->stop()) {
- LOGE("Supplicant stop failed (%s)", strerror(errno));
- return -1;
- }
+ if (mSupplicant->isStarted()) {
+ sendStatusBroadcast("STOPPING_SUPPLICANT");
+ if (mSupplicant->stop()) {
+ LOGE("Supplicant stop failed (%s)", strerror(errno));
+ return -1;
+ }
+ } else
+ LOGW("disable(): Supplicant not running?");
if (mModuleName[0] != '\0' && isKernelModuleLoaded(mModuleName)) {
+ sendStatusBroadcast("UNLOADING_DRIVER");
if (unloadKernelModule(mModuleName)) {
LOGE("Unable to unload module (%s)", strerror(errno));
return -1;
}
}
- if (isPoweredUp() && powerDown()) {
- LOGE("Powerdown failed (%s)", strerror(errno));
- return -1;
+ if (isPoweredUp()) {
+ sendStatusBroadcast("POWERING_DOWN");
+ if (powerDown()) {
+ LOGE("Powerdown failed (%s)", strerror(errno));
+ return -1;
+ }
}
return 0;
}
@@ -106,7 +133,7 @@ int WifiController::loadFirmware() {
return 0;
}
-int WifiController::setScanMode(int mode) {
+int WifiController::setScanMode(uint32_t mode) {
int rc = 0;
if (mCurrentScanMode == mode)
@@ -114,21 +141,15 @@ int WifiController::setScanMode(int mode) {
if (!(mode & SCAN_ENABLE_MASK)) {
if (mCurrentScanMode & SCAN_REPEAT_MASK)
- stopPeriodicScan();
+ mScanner->stopPeriodicScan();
} else if (mode & SCAN_REPEAT_MASK)
- rc = startPeriodicScan();
+ rc = mScanner->startPeriodicScan(mode & SCAN_ACTIVE_MASK);
else
rc = mSupplicant->triggerScan(mode & SCAN_ACTIVE_MASK);
return rc;
}
-int WifiController::startPeriodicScan() {
- errno = -ENOSYS;
- return -1;
-}
-
-int WifiController::stopPeriodicScan() {
- errno = -ENOSYS;
- return -1;
+ScanResultCollection *WifiController::createScanResults() {
+ return mSupplicant->createLatestScanResults();
}