Commit 5af38c36 authored by Dmitry Shmidt's avatar Dmitry Shmidt
Browse files

netd: Add Softap controller skeleton functions

Signed-off-by: default avatarDmitry Shmidt <dimitrysh@google.com>
parent 73ea55b5
......@@ -11,7 +11,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
main.cpp \
CommandListener.cpp \
CommandListener.cpp \
NetdCommand.cpp \
NetlinkManager.cpp \
NetlinkHandler.cpp \
......@@ -19,7 +19,8 @@ LOCAL_SRC_FILES:= \
TetherController.cpp \
NatController.cpp \
PppController.cpp \
PanController.cpp
PanController.cpp \
SoftapController.cpp
LOCAL_MODULE:= netd
......
......@@ -44,6 +44,7 @@ TetherController *CommandListener::sTetherCtrl = NULL;
NatController *CommandListener::sNatCtrl = NULL;
PppController *CommandListener::sPppCtrl = NULL;
PanController *CommandListener::sPanCtrl = NULL;
SoftapController *CommandListener::sSoftapCtrl = NULL;
CommandListener::CommandListener() :
FrameworkListener("netd") {
......@@ -54,6 +55,7 @@ CommandListener::CommandListener() :
registerCmd(new ListTtysCmd());
registerCmd(new PppdCmd());
registerCmd(new PanCmd());
registerCmd(new SoftapCmd());
if (!sTetherCtrl)
sTetherCtrl = new TetherController();
......@@ -63,6 +65,8 @@ CommandListener::CommandListener() :
sPppCtrl = new PppController();
if (!sPanCtrl)
sPanCtrl = new PanController();
if (!sSoftapCtrl)
sSoftapCtrl = new SoftapController();
}
CommandListener::InterfaceCmd::InterfaceCmd() :
......@@ -471,3 +475,44 @@ int CommandListener::PanCmd::runCommand(SocketClient *cli,
return 0;
}
CommandListener::SoftapCmd::SoftapCmd() :
NetdCommand("softap") {
}
int CommandListener::SoftapCmd::runCommand(SocketClient *cli,
int argc, char **argv) {
int rc = 0;
if (argc < 2) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Missing argument", false);
return 0;
}
if (!strcmp(argv[1], "start")) {
rc = sSoftapCtrl->startSoftap();
} else if (!strcmp(argv[1], "stop")) {
rc = sSoftapCtrl->stopSoftap();
} else if (!strcmp(argv[1], "status")) {
char *tmp = NULL;
asprintf(&tmp, "Softap service %s",
(sSoftapCtrl->isSoftapStarted() ? "started" : "stopped"));
cli->sendMsg(ResponseCode::SoftapStatusResult, tmp, false);
free(tmp);
return 0;
} else if (!strcmp(argv[1], "set")) {
rc = sSoftapCtrl->setSoftap(argc, argv);
} else {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Unknown cmd", false);
return 0;
}
if (!rc) {
cli->sendMsg(ResponseCode::CommandOkay, "Softap operation succeeded", false);
} else {
cli->sendMsg(ResponseCode::OperationFailed, "Softap operation failed", true);
}
return 0;
}
......@@ -24,12 +24,14 @@
#include "NatController.h"
#include "PppController.h"
#include "PanController.h"
#include "SoftapController.h"
class CommandListener : public FrameworkListener {
static TetherController *sTetherCtrl;
static NatController *sNatCtrl;
static PppController *sPppCtrl;
static PanController *sPanCtrl;
static SoftapController *sSoftapCtrl;
public:
CommandListener();
......@@ -37,6 +39,13 @@ public:
private:
class SoftapCmd : public NetdCommand {
public:
SoftapCmd();
virtual ~SoftapCmd() {}
int runCommand(SocketClient *c, int argc, char ** argv);
};
class InterfaceCmd : public NetdCommand {
public:
InterfaceCmd();
......
......@@ -34,6 +34,7 @@ public:
static const int IpFwdStatusResult = 211;
static const int PanStatusResult = 212;
static const int InterfaceGetCfgResult = 213;
static const int SoftapStatusResult = 214;
// 400 series - The command was accepted but the requested action
// did not take place.
......
/*
* 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 <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define LOG_TAG "SoftapController"
#include <cutils/log.h>
#include "SoftapController.h"
SoftapController::SoftapController() {
mPid = 0;
}
SoftapController::~SoftapController() {
}
int SoftapController::startSoftap() {
pid_t pid = 1;
LOGD("Softap start");
if (mPid) {
LOGE("Softap already started");
errno = EBUSY;
return -1;
}
#if 0
if ((pid = fork()) < 0) {
LOGE("fork failed (%s)", strerror(errno));
return -1;
}
#endif
if (!pid) {
LOGE("Softap Started");
return 0;
} else {
mPid = pid;
}
return 0;
}
int SoftapController::stopSoftap() {
LOGD("Softap stop");
if (mPid == 0) {
LOGE("Softap already stopped");
return 0;
}
#if 0
LOGD("Stopping Softap service");
kill(mPid, SIGTERM);
waitpid(mPid, NULL, 0);
#endif
mPid = 0;
LOGD("Softap service stopped");
return 0;
}
bool SoftapController::isSoftapStarted() {
return (mPid != 0 ? true : false);
}
int SoftapController::setSoftap(int argc, char *argv[]) {
LOGD("Softap set");
return 0;
}
/*
* 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 _SOFTAP_CONTROLLER_H
#define _SOFTAP_CONTROLLER_H
#include <linux/in.h>
#include <utils/List.h>
class SoftapController {
pid_t mPid;
public:
SoftapController();
virtual ~SoftapController();
int startSoftap();
int stopSoftap();
bool isSoftapStarted();
int setSoftap(int argc, char *argv[]);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment