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

Commit 397cf198 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

remove obsolete code

Change-Id: I65692beb620c35b0d0679939405183626a82bd8c
parent b7286aa0
Loading
Loading
Loading
Loading

nexus/Android.mk

deleted100644 → 0
+0 −66
Original line number Diff line number Diff line
BUILD_NEXUS := false
ifeq ($(BUILD_NEXUS),true)

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES:=                                      \
                  main.cpp                             \
                  NexusCommand.cpp                     \
                  CommandListener.cpp                  \
                  Property.cpp                         \
                  PropertyManager.cpp                  \
                  InterfaceConfig.cpp                  \
                  NetworkManager.cpp                   \
                  Controller.cpp                       \
                  WifiController.cpp                   \
                  TiwlanWifiController.cpp             \
                  TiwlanEventListener.cpp              \
                  WifiNetwork.cpp                      \
                  WifiStatusPoller.cpp                 \
                  ScanResult.cpp                       \
                  Supplicant.cpp                       \
                  SupplicantEvent.cpp                  \
                  SupplicantListener.cpp               \
                  SupplicantState.cpp                  \
                  SupplicantEventFactory.cpp           \
                  SupplicantConnectedEvent.cpp         \
                  SupplicantAssociatingEvent.cpp       \
                  SupplicantAssociatedEvent.cpp        \
                  SupplicantStateChangeEvent.cpp       \
                  SupplicantScanResultsEvent.cpp       \
                  SupplicantConnectionTimeoutEvent.cpp \
                  SupplicantDisconnectedEvent.cpp      \
                  SupplicantStatus.cpp                 \
                  OpenVpnController.cpp                \
                  VpnController.cpp                    \
                  LoopController.cpp                   \
                  DhcpClient.cpp DhcpListener.cpp      \
                  DhcpState.cpp DhcpEvent.cpp          \

LOCAL_MODULE:= nexus

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

LOCAL_CFLAGS := 

LOCAL_SHARED_LIBRARIES := libsysutils libwpa_client

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_SRC_FILES:=          \
                  nexctl.c \

LOCAL_MODULE:= nexctl

LOCAL_C_INCLUDES := $(KERNEL_HEADERS)

LOCAL_CFLAGS := 

LOCAL_SHARED_LIBRARIES := libcutils

include $(BUILD_EXECUTABLE)

endif # ifeq ($(BUILD_NEXUS),true)

nexus/CommandListener.cpp

deleted100644 → 0
+0 −235
Original line number Diff line number Diff line
/*
 * 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 <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>

#define LOG_TAG "CommandListener"
#include <cutils/log.h>

#include <sysutils/SocketClient.h>

#include "CommandListener.h"
#include "Controller.h"
#include "Property.h"
#include "NetworkManager.h"
#include "WifiController.h"
#include "VpnController.h"
#include "ResponseCode.h"

CommandListener::CommandListener() :
                 FrameworkListener("nexus") {
    registerCmd(new WifiScanResultsCmd());
    registerCmd(new WifiListNetworksCmd());
    registerCmd(new WifiCreateNetworkCmd());
    registerCmd(new WifiRemoveNetworkCmd());

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

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

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

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

    if (!(wn = wc->createNetwork()))
        cli->sendMsg(ResponseCode::OperationFailed, "Failed to create network", true);
    else {
        char tmp[128];
        sprintf(tmp, "Created network id %d.", wn->getNetworkId());
        cli->sendMsg(ResponseCode::CommandOkay, tmp, false);
    }
    return 0;
}

CommandListener::WifiRemoveNetworkCmd::WifiRemoveNetworkCmd() :
                 NexusCommand("wifi_remove_network") {
}

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

    if (wc->removeNetwork(atoi(argv[1])))
        cli->sendMsg(ResponseCode::OperationFailed, "Failed to remove network", true);
    else {
        cli->sendMsg(ResponseCode::CommandOkay, "Network removed.", false);
    }
    return 0;
}

CommandListener::WifiScanResultsCmd::WifiScanResultsCmd() :
                 NexusCommand("wifi_scan_results") {
}

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

    ScanResultCollection *src = wc->createScanResults();
    ScanResultCollection::iterator it;
    char buffer[256];

    for(it = src->begin(); it != src->end(); ++it) {
        sprintf(buffer, "%s %u %d %s %s",
                (*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(),
                (*it)->getFlags(), (*it)->getSsid());
        cli->sendMsg(ResponseCode::WifiScanResult, buffer, false);
        delete (*it);
        it = src->erase(it);
    }

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

CommandListener::WifiListNetworksCmd::WifiListNetworksCmd() :
                 NexusCommand("wifi_list_networks") {
}

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

    WifiNetworkCollection *src = wc->createNetworkList();
    WifiNetworkCollection::iterator it;
    char buffer[256];

    for(it = src->begin(); it != src->end(); ++it) {
        sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid());
        cli->sendMsg(ResponseCode::WifiNetworkList, buffer, false);
        delete (*it);
    }

    delete src;
    cli->sendMsg(ResponseCode::CommandOkay, "Network listing complete.", false);
    return 0;
}

/* ------------
 * Vpn Commands
 * ------------ */

/* ----------------
 * Generic Commands
 * ---------------- */
CommandListener::GetCmd::GetCmd() :
                 NexusCommand("get") {
}

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

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

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

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

CommandListener::SetCmd::SetCmd() :
                 NexusCommand("set") {
}

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

    cli->sendMsg(ResponseCode::CommandOkay, "Property set.", false);
    return 0;

out_inval:
    errno = EINVAL;
    cli->sendMsg(ResponseCode::CommandParameterError, "Failed to set property.", true);
    return 0;
}

CommandListener::ListCmd::ListCmd() :
                 NexusCommand("list") {
}

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

    if (argc > 1)
        prefix = argv[1];

    if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList(prefix))) {
        errno = ENODATA;
        cli->sendMsg(ResponseCode::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))) {
            ALOGW("Failed to get %s (%s)", (*it), strerror(errno));
        }

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

        free((*it));
    }

    delete pc;

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

nexus/CommandListener.h

deleted100644 → 0
+0 −87
Original line number Diff line number Diff line
/*
 * 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 _COMMANDLISTENER_H__
#define _COMMANDLISTENER_H__

#include <sysutils/FrameworkListener.h>
#include "NexusCommand.h"

class CommandListener : public FrameworkListener {
public:
    CommandListener();
    virtual ~CommandListener() {}

private:

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

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

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

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

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

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

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

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

#endif

nexus/Controller.cpp

deleted100644 → 0
+0 −165
Original line number Diff line number Diff line
/*
 * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <malloc.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#define LOG_TAG "Controller"

#include <cutils/log.h>

#include "Controller.h"
#include "InterfaceConfig.h"

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,
                       IControllerHandler *handlers) {
    mPropMngr = propMngr;
    mName = strdup(name);
    mHandlers = handlers;
    mBoundInterface = NULL;
}

Controller::~Controller() {
    if (mBoundInterface)
        free(mBoundInterface);
    if (mName)
        free(mName);
}

int Controller::start() {
    return 0;
}

int Controller::stop() {
    return 0;
}

int Controller::loadKernelModule(char *modpath, const char *args) {
    void *module;
    unsigned int size;

    module = loadFile(modpath, &size);
    if (!module) {
        errno = -EIO;
        return -1;
    }

    int rc = init_module(module, size, args);
    free (module);
    return rc;
}

int Controller::unloadKernelModule(const char *modtag) {
    int rc = -1;
    int retries = 10;

    while (retries--) {
        rc = delete_module(modtag, O_NONBLOCK | O_EXCL);
        if (rc < 0 && errno == EAGAIN)
            usleep(1000*500);
        else
            break;
    }

    if (rc != 0) {
        ALOGW("Unable to unload kernel driver '%s' (%s)", modtag,
             strerror(errno));
    }
    return rc;
}

bool Controller::isKernelModuleLoaded(const char *modtag) {
    FILE *fp = fopen("/proc/modules", "r");

    if (!fp) {
        ALOGE("Unable to open /proc/modules (%s)", strerror(errno));
        return false;
    }

    char line[255];
    while(fgets(line, sizeof(line), fp)) {
        char *endTag = strchr(line, ' ');

        if (!endTag) {
            ALOGW("Unable to find tag for line '%s'", line);
            continue;
        }
        if (!strncmp(line, modtag, (endTag - line))) {
            fclose(fp);
            return true;
        }
    }

    fclose(fp);
    return false;
}

void *Controller::loadFile(char *filename, unsigned int *_size)
{
	int ret, fd;
	struct stat sb;
	ssize_t size;
	void *buffer = NULL;

	/* open the file */
	fd = open(filename, O_RDONLY);
	if (fd < 0)
		return NULL;

	/* find out how big it is */
	if (fstat(fd, &sb) < 0)
		goto bail;
	size = sb.st_size;

	/* allocate memory for it to be read into */
	buffer = malloc(size);
	if (!buffer)
		goto bail;

	/* slurp it into our buffer */
	ret = read(fd, buffer, size);
	if (ret != size)
		goto bail;

	/* let the caller know how big it is */
	*_size = size;

bail:
	close(fd);
	return buffer;
}

int Controller::bindInterface(const char *ifname) {
    mBoundInterface = strdup(ifname);
    return 0;
}

int Controller::unbindInterface(const char *ifname) {
    free(mBoundInterface);
    mBoundInterface = NULL;
    return 0;
}

nexus/Controller.h

deleted100644 → 0
+0 −69
Original line number Diff line number Diff line
/*
 * 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 _CONTROLLER_H
#define _CONTROLLER_H

#include <unistd.h>
#include <sys/types.h>

#include <utils/List.h>

class PropertyManager;
class IControllerHandler;

#include "PropertyManager.h"

class Controller {
    /*
     * Name of this controller - WIFI/VPN/USBNET/BTNET/BTDUN/LOOP/etc
     */
    char *mName;

    /*
     * Name of the system ethernet interface which this controller is
     * bound to.
     */
    char *mBoundInterface;

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

    virtual int start();
    virtual int stop();

    const char *getName() { return mName; }
    const char *getBoundInterface() { return mBoundInterface; }
    
protected:
    int loadKernelModule(char *modpath, const char *args);
    bool isKernelModuleLoaded(const char *modtag);
    int unloadKernelModule(const char *modtag);
    int bindInterface(const char *ifname);
    int unbindInterface(const char *ifname);

private:
    void *loadFile(char *filename, unsigned int *_size);
};

typedef android::List<Controller *> ControllerCollection;
#endif
Loading