nexus: Rename onInterfaceStarted -> onInterfaceConnected and add Dhcp start/stop control
Signed-off-by: San Mehat <san@google.com>
diff --git a/nexus/IControllerHandler.h b/nexus/IControllerHandler.h
index 92d015f..f7be39c 100644
--- a/nexus/IControllerHandler.h
+++ b/nexus/IControllerHandler.h
@@ -22,8 +22,8 @@
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 2f13a40..7450b95 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 @@
mBroadcaster = NULL;
mControllers = new ControllerCollection();
mPropMngr = propMngr;
+ mDhcp = new DhcpClient(this);
}
NetworkManager::~NetworkManager() {
@@ -89,8 +91,8 @@
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 @@
}
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::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 edc80c9..44f3417 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 @@
ControllerCollection *mControllers;
SocketListener *mBroadcaster;
PropertyManager *mPropMngr;
+ DhcpClient *mDhcp;
public:
virtual ~NetworkManager();
@@ -55,7 +58,7 @@
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 b7bd6ed..ef5ecae 100644
--- a/nexus/WifiController.cpp
+++ b/nexus/WifiController.cpp
@@ -279,33 +279,31 @@
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::onDisconnectedEvent(SupplicantDisconnectedEvent *evt) {
- LOGD("onDisconnectedEvent()");
+ mHandlers->onInterfaceDisconnected(this, getBoundInterface());
}
#if 0