#include <functional>
#include <map>
+#include <vector>
#include <stdint.h>
#include <glib.h>
#include "FollowupConfig.h"
#include "DataPathConfig.h"
#include "DataPathEndConfig.h"
+#include "RttConfig.h"
+
#include "NanDefinitions.h"
#include "NanEventCallback.h"
#include "NanHalEventCallbackHandler.h"
+#include "RttEventCallback.h"
+#include "RttHalEventCallbackHandler.h"
+
#include "interface/wifi_hal.h"
#include "interface/wifi_nan.h"
std::string getWifiInterfaceName();
NanError registerCallbackHandler(const NanEventCallback& userCallbacks);
+ NanError registerRttCallbackHandler(const RttEventCallback& userCallbacks);
+
void getCapabilities(void);
void setEnabled(bool enabled);
void createDataPathInterface(const std::string& dataPathIfaceName);
void deleteDataPathInterface(const std::string& dataPathIfaceName);
+ void requestRttRange(std::vector<std::shared_ptr<RttConfig>> rttConfigs);
+
private:
void loadHalLibrary(std::string libraryPath);
std::shared_ptr<DataPathConfig> config);
NanDataPathEndRequest *convertDataPathEndConfigToLegacyRequest(
std::shared_ptr<DataPathEndConfig> config);
+ wifi_rtt_config *convertRttConfigToLegacyConfig(std::shared_ptr<RttConfig> config);
+
NanError convertLegacyErrorToNanError(wifi_error error);
void printLog(NanDataPathInitiatorRequest *config);
NanHalEventCallbackHandler mEventHandler;
NanEventCallback mUserCallbacks;
+ RttHalEventCallbackHandler mRttEventHandler;
+ RttEventCallback mRttUserCallbacks;
+
wifi_hal_fn mFunctionTable;
wifi_handle mWifiHandle;
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include "NanConfig.h"
+#include "NanDefinitions.h"
+
+NAN_NAMESPACE_BEGIN
+
+enum {
+ RTT_TYPE_1_SIDED = 0,
+ RTT_TYPE_2_SIDED,
+ RTT_TYPE_MAX
+};
+
+enum {
+ RTT_DEVICE_TYPE_AP = 0,
+ RTT_DEVICE_TYPE_STA,
+ RTT_DEVICE_TYPE_P2P_GO,
+ RTT_DEVICE_TYPE_P2P_CLIENT,
+ RTT_DEVICE_TYPE_NAN,
+ RTT_DEVICE_TYPE_MAX
+};
+
+typedef struct {
+ uint32_t width;
+ uint32_t centerFreq;
+ uint32_t centerFreq0;
+ uint32_t centerFreq1;
+} RttChannelInfo;
+
+class RttConfig : public NanConfig
+{
+public:
+ uint8_t addr[NAN_MAC_ADDR_LEN];
+ uint32_t rttType; // wifi_rtt_type
+ uint32_t deviceType; // rtt_peer_type
+ RttChannelInfo channel;
+ uint32_t burstPeriod;
+ uint32_t numBurst;
+ uint32_t numFramesPerBurst;
+ uint32_t numRetriesPerRttFrame;
+ uint32_t numRetriesPerFtmr;
+ uint32_t burstDuration;
+
+ bool requestLCI;
+ bool requestLCR;
+
+ uint32_t preamble; // wifi_rtt_preamble
+ uint32_t bandwidth; // wifi_rtt_bw
+
+ virtual ~RttConfig() {}
+
+ void setDefaultValues();
+ static std::shared_ptr<RttConfig> createDefaultConfig();
+
+ inline const char *convertRttTypeToString(int type);
+ inline const char *convertDeviceTypeToString(int type);
+ void logConfigurations();
+};
+
+NAN_NAMESPACE_END
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <functional>
+
+#include "RttResult.h"
+#include "NanError.h"
+
+NAN_NAMESPACE_BEGIN
+
+struct RttEventCallback {
+ std::function<void(uint16_t, std::vector<RttResult>)> on_notify_rtt_results;
+};
+
+NAN_NAMESPACE_END
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 __RTT_HAL_EVENT_CALLBACK_HANDLER_H__
+#define __RTT_HAL_EVENT_CALLBACK_HANDLER_H__
+
+#include "RttEventCallback.h"
+#include "NanDefinitions.h"
+
+#include "interface/rtt.h"
+
+NAN_NAMESPACE_BEGIN
+
+class RttHalEventCallbackHandler
+{
+public:
+ RttHalEventCallbackHandler();
+ virtual ~RttHalEventCallbackHandler();
+
+ void registerUserCallbacks(const RttEventCallback& userCallbacks);
+ wifi_rtt_event_handler getRttEventHandler();
+
+private:
+ wifi_rtt_event_handler mCallbacks;
+};
+
+NAN_NAMESPACE_END
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include "NanDefinitions.h"
+#include "NanError.h"
+
+NAN_NAMESPACE_BEGIN
+
+class RttResult
+{
+public:
+ // TODO
+ uint8_t addr[8];
+ uint32_t numMeasurement;
+};
+
+NAN_NAMESPACE_END
${CMAKE_SOURCE_DIR}/src/FollowupConfig.cpp
${CMAKE_SOURCE_DIR}/src/DataPathConfig.cpp
${CMAKE_SOURCE_DIR}/src/DataPathEndConfig.cpp
+ ${CMAKE_SOURCE_DIR}/src/RttConfig.cpp
+ ${CMAKE_SOURCE_DIR}/src/RttHalEventCallbackHandler.cpp
${CMAKE_SOURCE_DIR}/src/TlvUtils.cpp
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/interface/generated-code.c
#include <thread>
#include <fstream>
+#include <vector>
+
#include <glib.h>
#include <dlfcn.h>
#include "PublishConfig.h"
#include "NanLog.h"
#include "NanUtils.h"
+#include "RttEventCallback.h"
#include "interface/wifi_hal.h"
#include "interface/wifi_nan.h"
+#include "interface/rtt.h"
using namespace std;
NAN_NAMESPACE_USE;
return NAN_ERROR_NONE;
}
+NanError NanHal::registerRttCallbackHandler(const RttEventCallback& userCallbacks)
+{
+ mRttEventHandler.registerUserCallbacks(userCallbacks);
+ mRttUserCallbacks = userCallbacks;
+ return NAN_ERROR_NONE;
+}
+
void NanHal::getCapabilities(void)
{
__NAN_LOG_FUNC_ENTER__;
__NAN_LOG_FUNC_EXIT__;
}
+//void NanHal::requestRttRange(vector<std::shared_ptr<RttConfig>> rttConfigs, uint32_t numConfigs)
+void NanHal::requestRttRange(std::vector<std::shared_ptr<RttConfig>> rttConfigs)
+{
+ __NAN_LOG_FUNC_ENTER__;
+ wifi_error ret = WIFI_ERROR_NONE;
+ //NanError error = NAN_ERROR_NONE;
+ std::vector<wifi_rtt_config> configs;
+
+ for (std::shared_ptr<RttConfig> & rttConfig : rttConfigs) {
+ wifi_rtt_config *config = convertRttConfigToLegacyConfig(rttConfig);
+ if (config == nullptr) {
+ NAN_LOGE("Failed to convert from RttConfig to wifi_rtt_config");
+ // TODO: Error handling
+ __NAN_LOG_FUNC_EXIT__;
+ return;
+ }
+ configs.push_back(*config);
+ }
+
+ uint16_t transactionId = nextTransactionId();
+ wifi_rtt_event_handler callbacks = mRttEventHandler.getRttEventHandler();
+
+ // TODO: implement event handler
+ ret = mFunctionTable.wifi_rtt_range_request(transactionId,
+ getWifiIfaceHandle(mWifiInterfaceName),
+ configs.size(), configs.data(), callbacks);
+
+ __NAN_LOG_FUNC_EXIT__;
+}
+
void NanHal::runEventLoop()
{
NAN_LOGI("Run NAN event loop");
return ndpEndReq;
}
+wifi_rtt_config *NanHal::convertRttConfigToLegacyConfig(std::shared_ptr<RttConfig> config)
+{
+ wifi_rtt_config *rttConfig = (wifi_rtt_config *)calloc(1, sizeof(wifi_rtt_config));
+
+ if (!rttConfig) {
+ NAN_LOGE("Out of memory");
+ return nullptr;
+ }
+
+ memcpy(&rttConfig->addr, config->addr, NAN_MAC_ADDR_LEN);
+ rttConfig->type = (wifi_rtt_type)config->rttType;
+ rttConfig->peer = (rtt_peer_type)config->deviceType;
+
+ //rttConfig->channel;
+ rttConfig->burst_period = config->burstPeriod;
+
+ rttConfig->num_burst = config->numBurst;
+ rttConfig->num_frames_per_burst = config->numFramesPerBurst;
+ rttConfig->num_retries_per_rtt_frame = config->numRetriesPerRttFrame;
+ rttConfig->num_retries_per_ftmr = config->numRetriesPerFtmr;
+
+ rttConfig->LCI_request = config->requestLCI;
+ rttConfig->LCR_request = config->requestLCR;
+ rttConfig->burst_duration = config->burstDuration;
+ rttConfig->preamble = (wifi_rtt_preamble)config->preamble;
+ rttConfig->bw = (wifi_rtt_bw)config->bandwidth;
+
+ return rttConfig;
+}
+
NanError NanHal::convertLegacyErrorToNanError(wifi_error error)
{
switch (error)
on_notify_dp_respond_response = userCallbacks.on_notify_dp_respond_response;
on_notify_dp_terminate_response = userCallbacks.on_notify_dp_terminate_response;
- // TODO: Register events
+ // Register events
on_notify_disabled_event = userCallbacks.on_notify_disabled_event;
on_notify_discovery_result = userCallbacks.on_notify_discovery_result;
on_notify_followup_event = userCallbacks.on_notify_followup_event;
void NanServiceProvider::registerCallbacks()
{
NanEventCallback callbacks;
+ RttEventCallback rttCallbacks;
callbacks.on_notify_enable_response
= [=](uint16_t transactionId, NanError error) {
receiveSessionTerminatedEvent(subscribeId, error);
};
+ rttCallbacks.on_notify_rtt_results
+ = [=](uint16_t rttId, std::vector<RttResult> results) {
+ // TODO
+ NAN_LOGI("rtt results callback");
+ };
+
mHal->registerCallbackHandler(callbacks);
+ mHal->registerRttCallbackHandler(rttCallbacks);
}
void NanServiceProvider::setEnabled(bool enabled)
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 "RttConfig.h"
+#include "NanLog.h"
+#include "NanUtils.h"
+
+NAN_NAMESPACE_USE;
+
+void RttConfig::setDefaultValues()
+{
+ rttType = RTT_TYPE_1_SIDED;
+ deviceType = RTT_DEVICE_TYPE_AP;
+
+// channel.width = 0;
+// channel.center_freq = 0;
+// channel.center_freq0 = 0;
+// channel.center_freq1 = 0;
+
+ burstPeriod = 0;
+ numBurst = 0;
+ numFramesPerBurst = 8; // NAN: 5, Others: 8
+ numRetriesPerRttFrame = 0;
+ numRetriesPerFtmr = 0;
+ burstDuration = 15;
+
+ requestLCI = false;
+ requestLCR = false;
+
+ preamble = 0x2; // WIFI_RTT_PREAMBLE_HT
+ bandwidth = 0x04; // WIFI_RTT_BW_20
+}
+
+std::shared_ptr<RttConfig> RttConfig::createDefaultConfig()
+{
+ std::shared_ptr<RttConfig> config(new RttConfig);
+ config->setDefaultValues();
+ return config;
+}
+
+const char *RttConfig::convertRttTypeToString(int type)
+{
+ switch (type) {
+ case RTT_TYPE_1_SIDED:
+ return "1-sided";
+ case RTT_TYPE_2_SIDED:
+ return "2-sided";
+ case RTT_TYPE_MAX:
+ default:
+ return "Unknown Type";
+ }
+ return "Unknown Type";
+}
+
+const char *RttConfig::convertDeviceTypeToString(int type)
+{
+ switch (type) {
+ case RTT_DEVICE_TYPE_AP:
+ return "AP";
+ case RTT_DEVICE_TYPE_STA:
+ return "Station";
+ case RTT_DEVICE_TYPE_P2P_GO:
+ return "P2P GO";
+ case RTT_DEVICE_TYPE_P2P_CLIENT:
+ return "P2P Client";
+ case RTT_DEVICE_TYPE_NAN:
+ return "NAN";
+ case RTT_DEVICE_TYPE_MAX:
+ default:
+ return "Unknown Type";
+ }
+ return "Unknown Type";
+}
+
+void RttConfig::logConfigurations()
+{
+ NAN_LOGD("RttConfig");
+ NAN_LOGD("\t- peer address: %x:%x:%x:%x:%x:%x",
+ addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
+ NAN_LOGD("\t- rtt type: %s", convertRttTypeToString(rttType));
+ NAN_LOGD("\t- peer type: %s", convertDeviceTypeToString(deviceType));
+ NAN_LOGD("\t- burst info: period[%d] num[%d] frames per burst[%d] \
+ retries per rtt[%d] retries per ftmr[%d] duration[%d]",
+ burstPeriod, numBurst, numFramesPerBurst,
+ numRetriesPerRttFrame, numRetriesPerFtmr, burstDuration);
+ NAN_LOGD("\t- requestLCI: %s", requestLCI ? "yes" : "no");
+ NAN_LOGD("\t- requestLCR: %s", requestLCR ? "yes" : "no");
+ NAN_LOGD("\t- preamble: %x", preamble);
+ NAN_LOGD("\t- bandwidth: %x", bandwidth);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 <functional>
+#include <vector>
+#include <glib.h>
+
+#include "RttHalEventCallbackHandler.h"
+#include "RttEventCallback.h"
+#include "RttResult.h"
+
+#include "NanLog.h"
+
+#include "interface/wifi_hal.h"
+#include "interface/rtt.h"
+
+NAN_NAMESPACE_USE;
+
+/* Callbacks for NAN Interface */
+std::function<void(uint16_t, std::vector<RttResult>)> on_notify_rtt_results;
+
+void onRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result *rtt_result[])
+{
+ __NAN_LOG_FUNC_ENTER__;
+ // attachEventSource();
+ __NAN_LOG_FUNC_EXIT__;
+}
+
+void raiseRttResultsEvent()
+{
+ __NAN_LOG_FUNC_ENTER__;
+ if (!on_notify_rtt_results)
+ return;
+
+// on_notify_rtt_results(req_id, results);
+
+ __NAN_LOG_FUNC_EXIT__;
+}
+
+// Public methods
+RttHalEventCallbackHandler::RttHalEventCallbackHandler()
+{
+ __NAN_LOG_FUNC_ENTER__;
+
+ mCallbacks.on_rtt_results = onRttResults;
+
+ __NAN_LOG_FUNC_EXIT__;
+}
+
+RttHalEventCallbackHandler::~RttHalEventCallbackHandler()
+{
+ __NAN_LOG_FUNC_ENTER__;
+ __NAN_LOG_FUNC_EXIT__;
+}
+
+void RttHalEventCallbackHandler::registerUserCallbacks(const RttEventCallback& userCallbacks)
+{
+ __NAN_LOG_FUNC_ENTER__;
+
+ on_notify_rtt_results = userCallbacks.on_notify_rtt_results;
+
+ __NAN_LOG_FUNC_EXIT__;
+}
+
+wifi_rtt_event_handler RttHalEventCallbackHandler::getRttEventHandler()
+{
+ return mCallbacks;
+}