nexus: Rollup update for nexus

nexus: Change field separator from : to ' '

Signed-off-by: San Mehat <san@google.com>

nexus: Add some prototypes for stuff to come

Signed-off-by: San Mehat <san@google.com>

nexus: Add some TODOs

Signed-off-by: San Mehat <san@google.com>

libsysutils: Put a proper token parser into the FrameworkListener which
supports minimal \ escapes and quotes

Signed-off-by: San Mehat <san@google.com>

nexus: Fix a lot of bugs

Signed-off-by: San Mehat <san@google.com>

libsysutils: Remove some debugging
Signed-off-by: San Mehat <san@google.com>

nexus: Send broadcasts for supplicant state changes

Signed-off-by: San Mehat <san@google.com>

nexus: Plumb DHCP listener state changes to NetworkManager

Signed-off-by: San Mehat <san@google.com>

nexus: Make the SupplicantState strings more parsable

Signed-off-by: San Mehat <san@google.com>

nexus: Broadcast a message when dhcp state changes.

Signed-off-by: San Mehat <san@google.com>

nexus: Add a few new response codes

Signed-off-by: San Mehat <san@google.com>

nexus: Rename ErrorCode -> ResponseCode

Signed-off-by: San Mehat <san@google.com>

nexus: Add DHCP event broadcasting. Also adds the framework for
tracking supplicant 'searching-for-AP' state

Signed-off-by: San Mehat <san@google.com>

nexus: REmove WifiScanner

Signed-off-by: San Mehat <san@google.com>

nexus: Change the way scanning works. scanmode can now be selected
independantly of triggering a scan. Also adds rxfilter support

Signed-off-by: San Mehat <san@google.com>

nexus: Add support for configuring bluetooth coexistence scanning and modes

Signed-off-by: San Mehat <san@google.com>

nexus: use case insensitive match for property names

Signed-off-by: San Mehat <san@google.com>

nexus: Rollup of a bunch of stuff:
    - 'list' command now takes an argument to match against
    - InterfaceConfig has been moved into the Controller base (for now)
    - DhcpClient now has some rudimentry locking
    - process 'ADDRINFO' messages from dhcpcd
    - Drop tertiary dns

Signed-off-by: San Mehat <san@google.com>

nexus: Clean up some of the supplicant variable parsing and add 'wifi.current'

Signed-off-by: San Mehat <san@google.com>

nexus: Add driver-stop/start, initial suspend support

Signed-off-by: San Mehat <san@google.com>

nexus: Add Controller suspend/resume callbacks, as well as locking

Signed-off-by: San Mehat <san@google.com>

nexus: Make ARP probing configurable for DhcpClient

Signed-off-by: San Mehat <san@google.com>

nexus: Add linkspeed / rssi retrieval

Signed-off-by: San Mehat <san@google.com>

nexus: Add WifiStatusPoller to track RSSI/linkspeed when associated

Signed-off-by: San Mehat <san@google.com>

nexus: Disable some debugging and add 'wifi.netcount' property

Signed-off-by: San Mehat <san@google.com>

nexus: Replace the hackish property system with something more flexible with namespaces

Signed-off-by: San Mehat <san@google.com>

libsysutils: Fix a few bugs in SocketListener

Signed-off-by: San Mehat <san@google.com>

nexus: PropertyManager: Add array support

Signed-off-by: San Mehat <san@google.com>

nexus: Clean up properties
Signed-off-by: San Mehat <san@google.com>

nexus: WifiController: Change name of 'CurrentNetwork' property

Signed-off-by: San Mehat <san@google.com>
diff --git a/nexus/InterfaceConfig.cpp b/nexus/InterfaceConfig.cpp
index 66861d0..832cbca 100644
--- a/nexus/InterfaceConfig.cpp
+++ b/nexus/InterfaceConfig.cpp
@@ -23,147 +23,72 @@
 #include "InterfaceConfig.h"
 #include "NetworkManager.h"
 
-const char *InterfaceConfig::PropertyNames[] = { "dhcp", "ip",
-                                                 "netmask",
-                                                 "gateway", "dns1", "dns2",
-                                                 "dns3", '\0' };
-
-InterfaceConfig::InterfaceConfig(const char *prop_prefix) {
-    mPropPrefix = strdup(prop_prefix);
-    mUseDhcp = true;
-    registerProperties();
+InterfaceConfig::InterfaceConfig(bool propertiesReadOnly) {
+    mStaticProperties.propIp = new IPV4AddressPropertyHelper("Addr", propertiesReadOnly, &mIp);
+    mStaticProperties.propNetmask = new IPV4AddressPropertyHelper("Netmask", propertiesReadOnly, &mNetmask);
+    mStaticProperties.propGateway = new IPV4AddressPropertyHelper("Gateway", propertiesReadOnly, &mGateway);
+    mStaticProperties.propBroadcast = new IPV4AddressPropertyHelper("Broadcast", propertiesReadOnly, &mBroadcast);
+    mStaticProperties.propDns = new InterfaceDnsProperty(this, propertiesReadOnly);
 }
 
 InterfaceConfig::~InterfaceConfig() {
-    unregisterProperties();
-    free(mPropPrefix);
+    delete mStaticProperties.propIp;
+    delete mStaticProperties.propNetmask;
+    delete mStaticProperties.propGateway;
+    delete mStaticProperties.propBroadcast;
+    delete mStaticProperties.propDns;
 }
 
-InterfaceConfig::InterfaceConfig(const char *prop_prefix,
-                    const char *ip, const char *nm,
-                    const char *gw, const char *dns1, const char *dns2,
-                    const char *dns3) {
-    mPropPrefix = strdup(prop_prefix);
-    mUseDhcp = false;
-
-    if (!inet_aton(ip, &mIp))
-        LOGW("Unable to parse ip (%s)", ip);
-    if (!inet_aton(nm, &mNetmask))
-        LOGW("Unable to parse netmask (%s)", nm);
-    if (!inet_aton(gw, &mGateway))
-        LOGW("Unable to parse gateway (%s)", gw);
-    if (!inet_aton(dns1, &mDns1))
-        LOGW("Unable to parse dns1 (%s)", dns1);
-    if (!inet_aton(dns2, &mDns2))
-        LOGW("Unable to parse dns2 (%s)", dns2);
-    if (!inet_aton(dns3, &mDns3))
-        LOGW("Unable to parse dns3 (%s)", dns3);
-    registerProperties();
+void InterfaceConfig::setIp(struct in_addr *addr) {
+    memcpy(&mIp, addr, sizeof(struct in_addr));
 }
 
-InterfaceConfig::InterfaceConfig(const char *prop_prefix,
-                    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) {
-    mPropPrefix = strdup(prop_prefix);
-    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));
-    registerProperties();
+void InterfaceConfig::setNetmask(struct in_addr *addr) {
+    memcpy(&mNetmask, addr, sizeof(struct in_addr));
 }
 
-int InterfaceConfig::registerProperties() {
-    for (const char **p = InterfaceConfig::PropertyNames; *p != '\0'; p++) {
-        char *tmp;
-        asprintf(&tmp, "%s.if.%s", mPropPrefix, *p);
+void InterfaceConfig::setGateway(struct in_addr *addr) {
+    memcpy(&mGateway, addr, sizeof(struct in_addr));
+}
 
-        if (NetworkManager::Instance()->getPropMngr()->registerProperty(tmp,
-                                                                        this)) {
-            free(tmp);
-            return -1;
-        }
-        free(tmp);
-    }
+void InterfaceConfig::setBroadcast(struct in_addr *addr) {
+    memcpy(&mBroadcast, addr, sizeof(struct in_addr));
+}
+
+void InterfaceConfig::setDns(int idx, struct in_addr *addr) {
+    memcpy(&mDns[idx], addr, sizeof(struct in_addr));
+}
+
+int InterfaceConfig::attachProperties(PropertyManager *pm, const char *nsName) {
+    pm->attachProperty(nsName, mStaticProperties.propIp);
+    pm->attachProperty(nsName, mStaticProperties.propNetmask);
+    pm->attachProperty(nsName, mStaticProperties.propGateway);
+    pm->attachProperty(nsName, mStaticProperties.propBroadcast);
+    pm->attachProperty(nsName, mStaticProperties.propDns);
     return 0;
 }
 
-int InterfaceConfig::unregisterProperties() {
-    for (const char **p = InterfaceConfig::PropertyNames; *p != '\0'; p++) {
-        char *tmp;
-        asprintf(&tmp, "%s.if.%s", mPropPrefix, *p);
-
-        if (NetworkManager::Instance()->getPropMngr()->unregisterProperty(tmp))
-            LOGW("Unable to remove property '%s' (%s)", tmp, strerror(errno));
-        free(tmp);
-    }
+int InterfaceConfig::detachProperties(PropertyManager *pm, const char *nsName) {
+    pm->detachProperty(nsName, mStaticProperties.propIp);
+    pm->detachProperty(nsName, mStaticProperties.propNetmask);
+    pm->detachProperty(nsName, mStaticProperties.propGateway);
+    pm->detachProperty(nsName, mStaticProperties.propBroadcast);
+    pm->detachProperty(nsName, mStaticProperties.propDns);
     return 0;
 }
 
-int InterfaceConfig::set(const char *name, const char *value) {
-    const char *n;
+InterfaceConfig::InterfaceDnsProperty::InterfaceDnsProperty(InterfaceConfig *c,
+                                                            bool ro) :
+                 IPV4AddressProperty("Dns", ro, 2) {
+    mCfg = c;
+}
 
-    for (n = &name[strlen(name)]; *n != '.'; n--);
-    n++;
-
-    if (!strcasecmp(n, "name")) {
-        errno = EROFS;
-        return -1;
-    } else if (!strcasecmp(n, "ip") && !inet_aton(value, &mIp))
-        goto out_inval;
-    else if (!strcasecmp(n, "dhcp"))
-        mUseDhcp = (atoi(value) == 0 ? false : true);
-    else if (!strcasecmp(n, "netmask") && !inet_aton(value, &mNetmask))
-        goto out_inval;
-    else if (!strcasecmp(n, "gateway") && !inet_aton(value, &mGateway))
-        goto out_inval;
-    else if (!strcasecmp(n, "dns1") && !inet_aton(value, &mDns1))
-        goto out_inval;
-    else if (!strcasecmp(n, "dns2") && !inet_aton(value, &mDns2))
-        goto out_inval;
-    else if (!strcasecmp(n, "dns3") && !inet_aton(value, &mDns3))
-        goto out_inval;
-    else {
-        errno = ENOENT;
-        return -1;
-    }
-
+int InterfaceConfig::InterfaceDnsProperty::set(int idx, struct in_addr *value) {
+    memcpy(&mCfg->mDns[idx], value, sizeof(struct in_addr));
     return 0;
-
-out_inval:
-    errno = EINVAL;
-    return -1;
+}
+int InterfaceConfig::InterfaceDnsProperty::get(int idx, struct in_addr *buf) {
+    memcpy(buf, &mCfg->mDns[idx], sizeof(struct in_addr));
+    return 0;
 }
 
-const char *InterfaceConfig::get(const char *name, char *buffer, size_t max) {
-    const char *n;
-
-    for (n = &name[strlen(name)]; *n != '.'; n--);
-    n++;
-
-    if (!strcasecmp(n, "ip"))
-        strncpy(buffer, inet_ntoa(mIp), max);
-    else if (!strcasecmp(n, "dhcp"))
-        snprintf(buffer, max, "%d", mUseDhcp);
-    else if (!strcasecmp(n, "netmask"))
-        strncpy(buffer, inet_ntoa(mNetmask), max);
-    else if (!strcasecmp(n, "gateway"))
-        strncpy(buffer, inet_ntoa(mGateway), max);
-    else if (!strcasecmp(n, "dns1"))
-        strncpy(buffer, inet_ntoa(mDns1), max);
-    else if (!strcasecmp(n, "dns2"))
-        strncpy(buffer, inet_ntoa(mDns2), max);
-    else if (!strcasecmp(n, "dns3"))
-        strncpy(buffer, inet_ntoa(mDns3), max);
-    else {
-        strncpy(buffer, "(internal error)", max);
-        errno = ENOENT;
-        return NULL;
-    }
-    return buffer;
-}