# @brief CMakeLists for tef-simulator daemon unit
#
+SET(DAEMONCTL_PATH ${DAEMON_PATH}/daemonctl)
+
PKG_CHECK_MODULES(DAEMON_DEPS REQUIRED
cynara-client
cynara-session
${DAEMON_PATH}/inc/ResponseCommands
# TODO move TABinaryManager headers to inc directory
${DAEMON_PATH}/src/TABinaryManager/
+ ${DAEMONCTL_PATH}/inc
${TEF_SIMULATOR_INCLUDE_PATH}/include
${LOG_PATH}
${OSAL_PATH}
--- /dev/null
+/**
+ * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief Command types for the control socket
+ */
+
+#ifndef _CONTROLCOMMAND_H
+#define _CONTROLCOMMAND_H
+
+#include <cstdint>
+#include "tee_client_api.h"
+
+enum ControlCommand : uint32_t {
+ CTL_SET_PORT,
+};
+
+enum ControlCommandReply : uint32_t {
+ CTL_SET_PORT_REPLY,
+ CTL_INVALID_CMD_REPLY,
+};
+
+enum ControlReplyStatus : uint32_t {
+ CTL_REPLY_SUCCESS,
+ CTL_REPLY_TA_NOT_FOUND,
+};
+
+struct SetPortControlCommand {
+ TEEC_UUID uuid;
+ uint32_t port;
+};
+
+struct SetPortControlCommandReply {
+ enum ControlReplyStatus status;
+};
+
+#endif /* _CONTROLCOMMAND_H */
--- /dev/null
+/**
+ * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * @author Igor Kotrasinski (i.kotrasinsk@partner@samsung.com)
+ * @brief Handler for data coming over TEEC socket
+ */
+
+#ifndef _CONTROLCONNECTIONHANDLER_H
+#define _CONTROLCONNECTIONHANDLER_H
+
+#include <cstdint>
+#include <boost/system/error_code.hpp>
+#include "IConnectionHandler.h"
+#include "ControlCommand.h"
+#include "TABinaryManager.h"
+
+
+class ControlConnectionHandler: public IConnectionHandler<enum ControlCommand>
+{
+public:
+ void setWriter(IConnectionWriter<enum ControlCommand> &writer) override;
+ void handleConnect(int sock) override;
+ int32_t getDataSize(enum ControlCommand cmd) override;
+ void handleRead(enum ControlCommand header, std::vector<char> &data) override;
+ void handleReadError(boost::system::error_code e) override;
+private:
+ TABinaryManager *getBinaryManager();
+ IConnectionWriter<enum ControlCommand> *m_writer;
+ void handleSetPortCommand(std::vector<char> &data);
+ void handleInvalidCommand();
+ void handleConnectionClosed();
+};
+
+#endif /* _CONTROLCONNECTIONHANDLER_H */
--- /dev/null
+/**
+ * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * @author Igor Kotrasinski (i.kotrasinsk@partner@samsung.com)
+ * @brief ControlConnectionHandler class
+ */
+
+#include <cstring>
+#include <boost/asio.hpp>
+#include "log.h"
+#include "ControlConnectionHandler.h"
+#include "IConnectionWriter.h"
+
+void ControlConnectionHandler::setWriter(IConnectionWriter<enum ControlCommand> &writer)
+{
+ this->m_writer = &writer;
+}
+
+void ControlConnectionHandler::handleConnect(int sock)
+{
+ return;
+}
+
+int32_t ControlConnectionHandler::getDataSize(enum ControlCommand cmd)
+{
+ LOGD(SIM_DAEMON, "Control command received: %d", (uint32_t)cmd);
+ switch(cmdData) {
+ case CTL_SET_PORT:
+ return sizeof(SetPortControlCommand);
+ default:
+ LOGE(SIM_DAEMON, "Invalid command received!");
+ return -1;
+ }
+}
+
+void ControlConnectionHandler::handleRead(enum ControlCommand header,
+ std::vector<char> &data)
+{
+ switch(header) {
+ case CTL_SET_PORT:
+ handleSetPortCommand(data);
+ break;
+ default:
+ handleInvalidCommand();
+ break;
+ }
+}
+
+void ControlConnectionHandler::handleReadError(boost::system::error_code e)
+{
+ LOGE(SIM_DAEMON, "Error in reading from the control socket: Response returned with error code %d, message %s",
+ e.value(), e.category().name());
+}
+
+void ControlConnectionHandler::handleConnectionClosed() {}
+
+TABinaryManager *ControlConnectionHandler::getBinaryManager()
+{
+ return TABinaryManager::getInstance();
+}
+
+void ControlConnectionHandler::handleSetPortCommand(std::vector<char> &data)
+{
+ struct SetPortControlCommand cmd;
+ struct SetPortControlCommandReply reply;
+ TABinaryManager *binaryManager;
+ int ret;
+
+ std::memcpy(&cmd, data.data(), sizeof(cmd));
+ std::string portString = std::to_string(cmd.port);
+ binaryManager = getBinaryManager();
+ std::string uuidString = binaryManager.getUUIDAsString(data.uuid);
+
+ ret = binaryManager.setPort(uuidString, portString);
+ if (!ret) {
+ reply.status = CTL_REPLY_SUCCESS;
+ LOGI(SIM_DAEMON, "Set debug port of UUID %s to %s",
+ uuidString.c_str(), portString.c_str());
+ } else {
+ reply.status = CTL_REPLY_TA_NOT_FOUND;
+ LOGE(SIM_DAEMON, "Failed to set debug port of UUID %s to %s - TA not found",
+ uuidString.c_str(), portString.c_str());
+ }
+ m_writer->write(CTL_SET_PORT_REPLY, (char *) reply, sizeof(reply));
+}
+
+void ControlConnectionHandler::handleInvalidCommand()
+{
+ m_writer->write(CTL_INVALID_CMD_REPLY, nullptr, 0);
+}