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

Commit 7c5e6139 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Merge commit 'goog/master' into merge_master

parents e26cbeac cbc92d01
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */

#include <utils/executablepath.h>
#import <Carbon/Carbon.h>
#include <unistd.h>

+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
 * SUCH DAMAGE.
 */

#include <utils/executablepath.h>
#import <Carbon/Carbon.h>
#include <unistd.h>

+5 −4
Original line number Diff line number Diff line
@@ -59,9 +59,11 @@ void FrameworkListener::registerCmd(FrameworkCommand *cmd) {
}

void FrameworkListener::dispatchCommand(SocketClient *cli, char *cmd) {
    char *cm, *last;
    char *next = cmd;
    char *cm;
    char *arg;

    if (!(cm = strtok_r(cmd, ":", &last))) {
    if (!(cm = strsep(&next, ":"))) {
        cli->sendMsg(500, "Malformatted message", false);
        return;
    }
@@ -72,8 +74,7 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *cmd) {
        FrameworkCommand *c = *i;

        if (!strcmp(cm, c->getCommand())) {
            cm += strlen(cm) +1;
            if (c->runCommand(cli, cm)) {
            if (c->runCommand(cli, next)) {
                LOGW("Handler '%s' error (%s)", c->getCommand(), strerror(errno));
            }
            return;
+4 −1
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ LOCAL_SRC_FILES:= \
                  WifiScanner.cpp          \
                  WifiNetwork.cpp          \
                  OpenVpnController.cpp    \
                  InterfaceConfig.cpp      \
                  PropertyManager.cpp      \
                  SupplicantState.cpp 

LOCAL_MODULE:= nexus

LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
LOCAL_C_INCLUDES := $(KERNEL_HEADERS) -I../../../frameworks/base/include/

LOCAL_CFLAGS := 

+77 −36
Original line number Diff line number Diff line
/*
 * Copyright (C) ErrorCode::CommandOkay8 The Android Open Source Project
 * 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.
@@ -13,6 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -26,6 +27,7 @@

#include "CommandListener.h"
#include "Controller.h"
#include "Property.h"
#include "NetworkManager.h"
#include "WifiController.h"
#include "VpnController.h"
@@ -35,31 +37,32 @@ CommandListener::CommandListener() :
                 FrameworkListener("nexus") {
    registerCmd(new WifiScanResultsCmd());
    registerCmd(new WifiListNetworksCmd());
    registerCmd(new WifiAddNetworkCmd());
    registerCmd(new WifiCreateNetworkCmd());
    registerCmd(new WifiRemoveNetworkCmd());

    registerCmd(new GetCmd());
    registerCmd(new SetCmd());
    registerCmd(new ListCmd());
}

/* -------------
 * Wifi Commands
 * ------------ */

CommandListener::WifiAddNetworkCmd::WifiAddNetworkCmd() :
                 NexusCommand("wifi_add_network") {
CommandListener::WifiCreateNetworkCmd::WifiCreateNetworkCmd() :
                 NexusCommand("wifi_create_network") {
}

int CommandListener::WifiAddNetworkCmd::runCommand(SocketClient *cli, char *data) {
int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli, char *data) {
    NetworkManager *nm = NetworkManager::Instance();
    WifiController *wc = (WifiController *) nm->findController("WIFI");
    int networkId;
    WifiNetwork *wn;

    if ((networkId = wc->addNetwork()) < 0)
        cli->sendMsg(ErrorCode::OperationFailed, "Failed to add network", true);
    if (!(wn = wc->createNetwork()))
        cli->sendMsg(ErrorCode::OperationFailed, "Failed to create network", true);
    else {
        char tmp[128];
        sprintf(tmp, "Added network id %d.", networkId);
        sprintf(tmp, "Created network id %d.", wn->getNetworkId());
        cli->sendMsg(ErrorCode::CommandOkay, tmp, false);
    }
    return 0;
@@ -103,7 +106,7 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *dat
    }

    delete src;
    cli->sendMsg(ErrorCode::CommandOkay, "Scan results complete", false);
    cli->sendMsg(ErrorCode::CommandOkay, "Scan results complete.", false);
    return 0;
}

@@ -123,7 +126,6 @@ int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli, char *da
        sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid());
        cli->sendMsg(ErrorCode::WifiNetworkList, buffer, false);
        delete (*it);
        it = src->erase(it);
    }

    delete src;
@@ -143,31 +145,28 @@ CommandListener::GetCmd::GetCmd() :
}

int CommandListener::GetCmd::runCommand(SocketClient *cli, char *data) {
    char *bword;
    char *last;
    char propname[32];
    char *next = data;
    char *propname;

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

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

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

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

    cli->sendMsg(ErrorCode::VariableRead, pb, false);
    cli->sendMsg(ErrorCode::PropertyRead, pb, false);

    cli->sendMsg(ErrorCode::CommandOkay, "Property read.", false);
    return 0;
out_inval:
    errno = EINVAL;
    cli->sendMsg(ErrorCode::CommandParameterError, "Failed to get variable.", true);
    cli->sendMsg(ErrorCode::CommandParameterError, "Failed to read property.", true);
    return 0;
}

@@ -178,8 +177,8 @@ CommandListener::SetCmd::SetCmd() :
int CommandListener::SetCmd::runCommand(SocketClient *cli, char *data) {
    char *bword;
    char *last;
    char propname[32];
    char propval[250];
    char propname[Property::NameMaxSize];
    char propval[Property::ValueMaxSize];

    if (!(bword = strtok_r(data, ":", &last)))
        goto out_inval;
@@ -191,7 +190,7 @@ int CommandListener::SetCmd::runCommand(SocketClient *cli, char *data) {

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

    if (NetworkManager::Instance()->setProperty(propname, propval))
    if (NetworkManager::Instance()->getPropMngr()->set(propname, propval))
        goto out_inval;

    cli->sendMsg(ErrorCode::CommandOkay, "Property set.", false);
@@ -202,3 +201,45 @@ 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) {
    android::List<char *> *pc;

    if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList())) {
        errno = ENODATA;
        cli->sendMsg(ErrorCode::CommandParameterError, "Failed to list properties.", true);
        return 0;
    }

    android::List<char *>::iterator it;

    for (it = pc->begin(); it != pc->end(); ++it) {
        char p_v[Property::ValueMaxSize];

        if (!NetworkManager::Instance()->getPropMngr()->get((*it),
                                                            p_v,
                                                            sizeof(p_v))) {
            LOGW("Failed to get %s (%s)", (*it), strerror(errno));
        }

        char *buf;
        if (asprintf(&buf, "%s:%s", (*it), p_v) < 0) {
            LOGE("Failed to allocate memory");
            free((*it));
            continue;
        }
        cli->sendMsg(ErrorCode::PropertyList, buf, false);
        free(buf);

        free((*it));
    }

    delete pc;

    cli->sendMsg(ErrorCode::CommandOkay, "Properties list complete.", false);
    return 0;
}
Loading