From d6c6796670a5e566977b13d542020fb8cc88e6cf Mon Sep 17 00:00:00 2001 From: San Mehat Date: Mon, 22 Jun 2009 10:39:36 -0700 Subject: [PATCH] nexus: Rename onInterfaceStarted -> onInterfaceConnected and add Dhcp start/stop control Signed-off-by: San Mehat --- nexus/IControllerHandler.h | 4 ++-- nexus/NetworkManager.cpp | 21 +++++++++++------ nexus/NetworkManager.h | 9 ++++--- nexus/WifiController.cpp | 48 ++++++++++++++++++-------------------- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/nexus/IControllerHandler.h b/nexus/IControllerHandler.h index 92d015f43..f7be39cea 100644 --- a/nexus/IControllerHandler.h +++ b/nexus/IControllerHandler.h @@ -22,8 +22,8 @@ class InterfaceConfig; class IControllerHandler { public: - virtual void onInterfaceStarted(Controller *c, const InterfaceConfig *cfg) = 0; - virtual void onInterfaceStopping(Controller *c, const char *name) = 0; + virtual void onInterfaceConnected(Controller *c, const InterfaceConfig *cfg) = 0; + virtual void onInterfaceDisconnected(Controller *c, const char *name) = 0; }; #endif diff --git a/nexus/NetworkManager.cpp b/nexus/NetworkManager.cpp index 2f13a408e..7450b951b 100644 --- a/nexus/NetworkManager.cpp +++ b/nexus/NetworkManager.cpp @@ -23,6 +23,7 @@ #include "NetworkManager.h" #include "InterfaceConfig.h" +#include "DhcpClient.h" NetworkManager *NetworkManager::sInstance = NULL; @@ -36,6 +37,7 @@ NetworkManager::NetworkManager(PropertyManager *propMngr) { mBroadcaster = NULL; mControllers = new ControllerCollection(); mPropMngr = propMngr; + mDhcp = new DhcpClient(this); } NetworkManager::~NetworkManager() { @@ -89,8 +91,8 @@ Controller *NetworkManager::findController(const char *name) { return NULL; } -void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cfg) { - LOGD("Interface %s started by controller %s", c->getBoundInterface(), c->getName()); +void NetworkManager::onInterfaceConnected(Controller *c, const InterfaceConfig *cfg) { + LOGD("Controller %s interface %s connected", c->getName(), c->getBoundInterface()); // Look up the interface @@ -98,9 +100,9 @@ void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cf } if (cfg) { - if (cfg->getUseDhcp()) { - // Launch DHCP thread - } else { + if (cfg->getUseDhcp() && mDhcp->start(c->getBoundInterface())) { + LOGE("DHCP start failed"); + } else if (!cfg->getUseDhcp()) { // Static configuration } } else { @@ -109,6 +111,11 @@ void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cf } } -void NetworkManager::onInterfaceStopping(Controller *c, const char *name) { - LOGD("Interface %s stopped by controller %s", name, c->getName()); +void NetworkManager::onInterfaceDisconnected(Controller *c, const char *name) { + LOGD("Controller %s interface %s disconnected", c->getName(), name); + + // If we have a DHCP request out on this interface then stop it + if (1) { + mDhcp->stop(); + } } diff --git a/nexus/NetworkManager.h b/nexus/NetworkManager.h index edc80c9b5..44f3417fd 100644 --- a/nexus/NetworkManager.h +++ b/nexus/NetworkManager.h @@ -22,10 +22,12 @@ #include "Controller.h" #include "PropertyManager.h" #include "IControllerHandler.h" +#include "IDhcpEventHandlers.h" class InterfaceConfig; +class DhcpClient; -class NetworkManager : public IControllerHandler { +class NetworkManager : public IControllerHandler, public IDhcpEventHandlers { private: static NetworkManager *sInstance; @@ -33,6 +35,7 @@ private: ControllerCollection *mControllers; SocketListener *mBroadcaster; PropertyManager *mPropMngr; + DhcpClient *mDhcp; public: virtual ~NetworkManager(); @@ -55,7 +58,7 @@ private: NetworkManager(PropertyManager *propMngr); - void onInterfaceStarted(Controller *c, const InterfaceConfig *cfg); - void onInterfaceStopping(Controller *c, const char *name); + void onInterfaceConnected(Controller *c, const InterfaceConfig *cfg); + void onInterfaceDisconnected(Controller *c, const char *name); }; #endif diff --git a/nexus/WifiController.cpp b/nexus/WifiController.cpp index b7bd6edad..ef5ecae17 100644 --- a/nexus/WifiController.cpp +++ b/nexus/WifiController.cpp @@ -279,33 +279,31 @@ void WifiController::onAssociatedEvent(SupplicantAssociatedEvent *evt) { void WifiController::onConnectedEvent(SupplicantConnectedEvent *evt) { LOGD("onConnectedEvent(%s, %d)", evt->getBssid(), evt->getReassociated()); - if (!evt->getReassociated()) { - SupplicantStatus *ss = mSupplicant->getStatus(); - WifiNetwork *wn; + SupplicantStatus *ss = mSupplicant->getStatus(); + WifiNetwork *wn; - if (ss->getWpaState() != SupplicantState::COMPLETED) { - char tmp[32]; + if (ss->getWpaState() != SupplicantState::COMPLETED) { + char tmp[32]; - LOGW("onConnected() with SupplicantState = %s!", - SupplicantState::toString(ss->getWpaState(), tmp, - sizeof(tmp))); - return; - } - - if (ss->getId() == -1) { - LOGW("onConnected() with id = -1!"); - return; - } - - if (!(wn = mSupplicant->lookupNetwork(ss->getId()))) { - LOGW("Error looking up connected network id %d (%s)", - ss->getId(), strerror(errno)); - return; - } - - delete ss; - mHandlers->onInterfaceStarted(this, wn->getIfaceCfg()); + LOGW("onConnected() with SupplicantState = %s!", + SupplicantState::toString(ss->getWpaState(), tmp, + sizeof(tmp))); + return; } + + if (ss->getId() == -1) { + LOGW("onConnected() with id = -1!"); + return; + } + + if (!(wn = mSupplicant->lookupNetwork(ss->getId()))) { + LOGW("Error looking up connected network id %d (%s)", + ss->getId(), strerror(errno)); + return; + } + + delete ss; + mHandlers->onInterfaceConnected(this, wn->getIfaceCfg()); } void WifiController::onScanResultsEvent(SupplicantScanResultsEvent *evt) { @@ -373,7 +371,7 @@ void WifiController::onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent * } void WifiController::onDisconnectedEvent(SupplicantDisconnectedEvent *evt) { - LOGD("onDisconnectedEvent()"); + mHandlers->onInterfaceDisconnected(this, getBoundInterface()); } #if 0