diff options
| author | San Mehat <san@google.com> | 2009-05-22 13:58:06 -0700 |
|---|---|---|
| committer | San Mehat <san@google.com> | 2009-05-29 15:26:00 -0700 |
| commit | 192331d9060763b92f7989124bedbd136689d735 (patch) | |
| tree | 308fb209da08727edf3f25c52fb0c599d756272e /nexus | |
| parent | 03f0d27f6c49530a91402ed42f8ca4b2fda04b9f (diff) | |
| download | system_core-192331d9060763b92f7989124bedbd136689d735.zip system_core-192331d9060763b92f7989124bedbd136689d735.tar.gz system_core-192331d9060763b92f7989124bedbd136689d735.tar.bz2 | |
nexus: Add ListCmd to CommandListener
Signed-off-by: San Mehat <san@google.com>
nexus: Add InterfaceConfig and flesh out some more flow
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'nexus')
| -rw-r--r-- | nexus/Android.mk | 1 | ||||
| -rw-r--r-- | nexus/CommandListener.cpp | 8 | ||||
| -rw-r--r-- | nexus/CommandListener.h | 7 | ||||
| -rw-r--r-- | nexus/InterfaceConfig.cpp | 67 | ||||
| -rw-r--r-- | nexus/InterfaceConfig.h | 58 | ||||
| -rw-r--r-- | nexus/NetworkManager.cpp | 20 | ||||
| -rw-r--r-- | nexus/NetworkManager.h | 14 |
7 files changed, 168 insertions, 7 deletions
diff --git a/nexus/Android.mk b/nexus/Android.mk index df170b8..61240d5 100644 --- a/nexus/Android.mk +++ b/nexus/Android.mk @@ -22,6 +22,7 @@ LOCAL_SRC_FILES:= \ WifiScanner.cpp \ WifiNetwork.cpp \ OpenVpnController.cpp \ + InterfaceConfig.cpp \ LOCAL_MODULE:= nexus diff --git a/nexus/CommandListener.cpp b/nexus/CommandListener.cpp index 5b03357..e2edc77 100644 --- a/nexus/CommandListener.cpp +++ b/nexus/CommandListener.cpp @@ -202,3 +202,11 @@ out_inval: cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set property.", true); return 0; } + +CommandListener::ListCmd::ListCmd() : + NexusCommand("list") { +} + +int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) { + return 0; +} diff --git a/nexus/CommandListener.h b/nexus/CommandListener.h index 6973aaa..b44d3ec 100644 --- a/nexus/CommandListener.h +++ b/nexus/CommandListener.h @@ -74,6 +74,13 @@ private: virtual ~GetCmd() {} int runCommand(SocketClient *c, char *data); }; + + class ListCmd : public NexusCommand { + public: + ListCmd(); + virtual ~ListCmd() {} + int runCommand(SocketClient *c, char *data); + }; }; #endif diff --git a/nexus/InterfaceConfig.cpp b/nexus/InterfaceConfig.cpp new file mode 100644 index 0000000..89936f8 --- /dev/null +++ b/nexus/InterfaceConfig.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <string.h> + +#define LOG_TAG "InterfaceConfig" +#include <cutils/log.h> + +#include "InterfaceConfig.h" + +InterfaceConfig::InterfaceConfig(const char *name) { + mName = strdup(name); + mUseDhcp = true; +} + +InterfaceConfig::~InterfaceConfig() { + free(mName); +} + +InterfaceConfig::InterfaceConfig(const char *name, const char *ip, const char *nm, + const char *gw, const char *dns1, const char *dns2, + const char *dns3) { + mName = strdup(name); + mUseDhcp = false; + + if (!inet_aton(ip, &mIp)) + LOGW("Unable to parse ip (%s)", ip); + if (!inet_aton(nm, &mIp)) + LOGW("Unable to parse netmask (%s)", nm); + if (!inet_aton(gw, &mIp)) + LOGW("Unable to parse gateway (%s)", gw); + if (!inet_aton(dns1, &mIp)) + LOGW("Unable to parse dns1 (%s)", dns1); + if (!inet_aton(dns2, &mIp)) + LOGW("Unable to parse dns2 (%s)", dns2); + if (!inet_aton(dns3, &mIp)) + LOGW("Unable to parse dns3 (%s)", dns3); +} + +InterfaceConfig::InterfaceConfig(const char *name, const struct in_addr *ip, + const struct in_addr *nm, const struct in_addr *gw, + const struct in_addr *dns1, const struct in_addr *dns2, + const struct in_addr *dns3) { + mName = strdup(name); + mUseDhcp = false; + + memcpy(&mIp, ip, sizeof(struct in_addr)); + memcpy(&mNetmask, nm, sizeof(struct in_addr)); + memcpy(&mGateway, gw, sizeof(struct in_addr)); + memcpy(&mDns1, dns1, sizeof(struct in_addr)); + memcpy(&mDns2, dns2, sizeof(struct in_addr)); + memcpy(&mDns3, dns3, sizeof(struct in_addr)); +} + diff --git a/nexus/InterfaceConfig.h b/nexus/InterfaceConfig.h new file mode 100644 index 0000000..1426e99 --- /dev/null +++ b/nexus/InterfaceConfig.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _INTERFACE_CONFIG_H +#define _INTERFACE_CONFIG_H + +#include <netinet/in.h> +#include <arpa/inet.h> + +class InterfaceConfig { +private: + char *mName; + bool mUseDhcp; + struct in_addr mIp; + struct in_addr mNetmask; + struct in_addr mGateway; + struct in_addr mDns1; + struct in_addr mDns2; + struct in_addr mDns3; + +public: + InterfaceConfig(const char *name); + InterfaceConfig(const char *name, const char *ip, const char *nm, + const char *gw, const char *dns1, const char *dns2, + const char *dns3); + + InterfaceConfig(const char *name, const struct in_addr *ip, + const struct in_addr *nm, const struct in_addr *gw, + const struct in_addr *dns1, const struct in_addr *dns2, + const struct in_addr *dns3); + + virtual ~InterfaceConfig(); + + const char *getName() const { return mName; } + bool getUseDhcp() const { return mUseDhcp; } + const struct in_addr &getIp() const { return mIp; } + const struct in_addr &getNetmask() const { return mNetmask; } + const struct in_addr &getGateway() const { return mGateway; } + const struct in_addr &getDns1() const { return mDns1; } + const struct in_addr &getDns2() const { return mDns2; } + const struct in_addr &getDns3() const { return mDns3; } +}; + + +#endif diff --git a/nexus/NetworkManager.cpp b/nexus/NetworkManager.cpp index 022d7f8..49b0210 100644 --- a/nexus/NetworkManager.cpp +++ b/nexus/NetworkManager.cpp @@ -21,6 +21,7 @@ #include <cutils/log.h> #include "NetworkManager.h" +#include "InterfaceConfig.h" NetworkManager *NetworkManager::sInstance = NULL; @@ -150,12 +151,23 @@ const PropertyCollection &NetworkManager::getProperties() { return *mProperties; } -int NetworkManager::onInterfaceCreated(Controller *c, char *name) { - LOGD("Interface %s created by controller %s", name, c->getName()); +int NetworkManager::onInterfaceStart(Controller *c, const InterfaceConfig *cfg) { + LOGD("Interface %s started by controller %s", cfg->getName(), c->getName()); + + // Look up the interface + + if (0) { // already started? + errno = EADDRINUSE; + return -1; + } + + if (cfg->getUseDhcp()) { + } else { + } return 0; } -int NetworkManager::onInterfaceDestroyed(Controller *c, char *name) { - LOGD("Interface %s destroyed by controller %s", name, c->getName()); +int NetworkManager::onInterfaceStop(Controller *c, const char *name) { + LOGD("Interface %s stopped by controller %s", name, c->getName()); return 0; } diff --git a/nexus/NetworkManager.h b/nexus/NetworkManager.h index bd00849..e8564ca 100644 --- a/nexus/NetworkManager.h +++ b/nexus/NetworkManager.h @@ -21,6 +21,8 @@ #include "Controller.h" #include "PropertyCollection.h" +class InterfaceConfig; + class NetworkManager { private: static NetworkManager *sInstance; @@ -57,9 +59,15 @@ private: NetworkManager(); public: -// XXX: Extract these into an interface - int onInterfaceCreated(Controller *c, char *name); - int onInterfaceDestroyed(Controller *c, char *name); + /* + * Called from a controller when an interface is available/ready for use. + * 'cfg' contains information on how this interface should be configured. + */ + int onInterfaceStart(Controller *c, const InterfaceConfig *cfg); + /* + * Called from a controller when an interface should be shut down + */ + int onInterfaceStop(Controller *c, const char *name); }; #endif |
