Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3aff2d1d authored by San Mehat's avatar San Mehat
Browse files

Nexus: Clean up supplicant events, protocol, and continue plumbing



    - Create SupplicantEvent classes for events
    - New SupplicantEventFactory for creating events
    - Extract Controller -> NetworkManager callbacks into IControllerHandler
    - Move ScanResult handling from Supplicant -> WifiController
    - Plumb more 'onConnected()' code
    - Instead of re-creating NetworkList every-time, merge in
      new entries
    - Extract SupplicantListener -> Supplicant callbacks into
      ISupplicantEventHandler
    - Move SupplicantListener callback handling to WifiController
    - Add unlocked version of lookupNetwork()
    - Save supplicant config after setting a WifiNetwork variable
    - Move property registration from WifiNetwork -> Supplicant
    - Change wifi enable broadcast messages
    - Add 3 new events: 'onAssociating', 'onAssociated', 'onConnectionTimeout'
    - Add support for handling KeyManagement

Signed-off-by: default avatarSan Mehat <san@google.com>
parent 669a7011
Loading
Loading
Loading
Loading
+29 −20
Original line number Diff line number Diff line
@@ -24,7 +24,16 @@ LOCAL_SRC_FILES:= \
                  OpenVpnController.cpp                \
                  InterfaceConfig.cpp                  \
                  PropertyManager.cpp                  \
                  SupplicantState.cpp 
                  SupplicantState.cpp                  \
                  SupplicantEventFactory.cpp           \
                  SupplicantConnectedEvent.cpp         \
                  SupplicantAssociatingEvent.cpp       \
                  SupplicantAssociatedEvent.cpp        \
                  SupplicantStateChangeEvent.cpp       \
                  SupplicantScanResultsEvent.cpp       \
                  SupplicantConnectionTimeoutEvent.cpp \
                  SupplicantDisconnectedEvent.cpp      \
                  SupplicantStatus.cpp

LOCAL_MODULE:= nexus

+23 −37
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ CommandListener::WifiCreateNetworkCmd::WifiCreateNetworkCmd() :
                 NexusCommand("wifi_create_network") {
}

int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli, char *data) {
int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli,
                                                      int argc, char **argv) {
    NetworkManager *nm = NetworkManager::Instance();
    WifiController *wc = (WifiController *) nm->findController("WIFI");
    WifiNetwork *wn;
@@ -72,11 +73,12 @@ CommandListener::WifiRemoveNetworkCmd::WifiRemoveNetworkCmd() :
                 NexusCommand("wifi_remove_network") {
}

int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli, char *data) {
int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli,
                                                      int argc, char **argv) {
    NetworkManager *nm = NetworkManager::Instance();
    WifiController *wc = (WifiController *) nm->findController("WIFI");

    if (wc->removeNetwork(atoi(data)))
    if (wc->removeNetwork(atoi(argv[1])))
        cli->sendMsg(ErrorCode::OperationFailed, "Failed to remove network", true);
    else {
        cli->sendMsg(ErrorCode::CommandOkay, "Network removed.", false);
@@ -88,7 +90,8 @@ CommandListener::WifiScanResultsCmd::WifiScanResultsCmd() :
                 NexusCommand("wifi_scan_results") {
}

int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *data) {
int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli,
                                                    int argc, char **argv) {
    NetworkManager *nm = NetworkManager::Instance();
    WifiController *wc = (WifiController *) nm->findController("WIFI");

@@ -114,7 +117,8 @@ CommandListener::WifiListNetworksCmd::WifiListNetworksCmd() :
                 NexusCommand("wifi_list_networks") {
}

int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli, char *data) {
int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli,
                                                     int argc, char **argv) {
    NetworkManager *nm = NetworkManager::Instance();
    WifiController *wc = (WifiController *) nm->findController("WIFI");

@@ -144,23 +148,19 @@ CommandListener::GetCmd::GetCmd() :
                 NexusCommand("get") {
}

int CommandListener::GetCmd::runCommand(SocketClient *cli, char *data) {
    char *next = data;
    char *propname;
int CommandListener::GetCmd::runCommand(SocketClient *cli, int argc, char **argv) {
    char val[Property::ValueMaxSize];

    if (!(propname = strsep(&next, ":")))
        goto out_inval;

    char pb[Property::NameMaxSize + 6];
    snprintf(pb, sizeof(pb), "%s:", propname);

    if (!NetworkManager::Instance()->getPropMngr()->get(propname,
                                                        &pb[strlen(pb)],
                                                        sizeof(pb) - strlen(pb))) {
    if (!NetworkManager::Instance()->getPropMngr()->get(argv[1],
                                                        val,
                                                        sizeof(val))) {
        goto out_inval;
    }

    cli->sendMsg(ErrorCode::PropertyRead, pb, false);
    char *tmp;
    asprintf(&tmp, "%s %s", argv[1], val);
    cli->sendMsg(ErrorCode::PropertyRead, tmp, false);
    free(tmp);

    cli->sendMsg(ErrorCode::CommandOkay, "Property read.", false);
    return 0;
@@ -174,23 +174,9 @@ CommandListener::SetCmd::SetCmd() :
                 NexusCommand("set") {
}

int CommandListener::SetCmd::runCommand(SocketClient *cli, char *data) {
    char *bword;
    char *last;
    char propname[Property::NameMaxSize];
    char propval[Property::ValueMaxSize];

    if (!(bword = strtok_r(data, ":", &last)))
        goto out_inval;

    strncpy(propname, bword, sizeof(propname));

    if (!(bword = strtok_r(NULL, ":", &last)))
        goto out_inval;

    strncpy(propval, bword, sizeof(propval));

    if (NetworkManager::Instance()->getPropMngr()->set(propname, propval))
int CommandListener::SetCmd::runCommand(SocketClient *cli, int argc,
                                        char **argv) {
    if (NetworkManager::Instance()->getPropMngr()->set(argv[1], argv[2]))
        goto out_inval;

    cli->sendMsg(ErrorCode::CommandOkay, "Property set.", false);
@@ -206,7 +192,7 @@ CommandListener::ListCmd::ListCmd() :
                 NexusCommand("list") {
}

int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) {
int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **argv) {
    android::List<char *> *pc;

    if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList())) {
@@ -227,7 +213,7 @@ int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) {
        }

        char *buf;
        if (asprintf(&buf, "%s:%s", (*it), p_v) < 0) {
        if (asprintf(&buf, "%s %s", (*it), p_v) < 0) {
            LOGE("Failed to allocate memory");
            free((*it));
            continue;
+8 −8
Original line number Diff line number Diff line
@@ -31,56 +31,56 @@ private:
    public:
        WifiScanCmd();
        virtual ~WifiScanCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class WifiScanResultsCmd : public NexusCommand {
    public:
        WifiScanResultsCmd();
        virtual ~WifiScanResultsCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class WifiCreateNetworkCmd : public NexusCommand {
    public:
        WifiCreateNetworkCmd();
        virtual ~WifiCreateNetworkCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class WifiRemoveNetworkCmd : public NexusCommand {
    public:
        WifiRemoveNetworkCmd();
        virtual ~WifiRemoveNetworkCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class WifiListNetworksCmd : public NexusCommand {
    public:
        WifiListNetworksCmd();
        virtual ~WifiListNetworksCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class SetCmd : public NexusCommand {
    public:
        SetCmd();
        virtual ~SetCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class GetCmd : public NexusCommand {
    public:
        GetCmd();
        virtual ~GetCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class ListCmd : public NexusCommand {
    public:
        ListCmd();
        virtual ~ListCmd() {}
        int runCommand(SocketClient *c, char *data);
        int runCommand(SocketClient *c, int argc, char ** argv);
    };
};

+3 −1
Original line number Diff line number Diff line
@@ -34,9 +34,11 @@
extern "C" int init_module(void *, unsigned int, const char *);
extern "C" int delete_module(const char *, unsigned int);

Controller::Controller(const char *name, PropertyManager *propMngr) {
Controller::Controller(const char *name, PropertyManager *propMngr,
                       IControllerHandler *handlers) {
    mPropMngr = propMngr;
    mName = strdup(name);
    mHandlers = handlers;
    mBoundInterface = NULL;
}

+4 −2
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@
#include <utils/List.h>

class PropertyManager;
class IControllerHandler;

#include "PropertyManager.h"
#include "IPropertyProvider.h"

class Controller : public IPropertyProvider {
private:
    /*
     * Name of this controller - WIFI/VPN/USBNET/BTNET/BTDUN/LOOP/etc
     */
@@ -42,9 +42,11 @@ private:

protected:
    PropertyManager *mPropMngr;
    IControllerHandler *mHandlers;
    
public:
    Controller(const char *name, PropertyManager *propMngr);
    Controller(const char *name, PropertyManager *propMngr,
               IControllerHandler *handlers);
    virtual ~Controller();

    virtual int start();
Loading