Implement RTT Hal
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 20 Jul 2020 12:01:21 +0000 (21:01 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 20 Jul 2020 12:01:21 +0000 (21:01 +0900)
include/NanHal.h
include/RttConfig.h [new file with mode: 0644]
include/RttEventCallback.h [new file with mode: 0644]
include/RttHalEventCallbackHandler.h [new file with mode: 0644]
include/RttResult.h [new file with mode: 0644]
src/CMakeLists.txt
src/NanHal.cpp
src/NanHalEventCallbackHandler.cpp
src/NanServiceProvider.cpp
src/RttConfig.cpp [new file with mode: 0644]
src/RttHalEventCallbackHandler.cpp [new file with mode: 0644]

index 303ea4107e25f7eb97d6e3bec06d24dbacf31489..ccd948019279ef58970141e02f1a7067624fdbc3 100644 (file)
@@ -19,6 +19,7 @@
 
 #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"
 
@@ -50,6 +56,8 @@ public:
 
        std::string getWifiInterfaceName();
        NanError registerCallbackHandler(const NanEventCallback& userCallbacks);
+       NanError registerRttCallbackHandler(const RttEventCallback& userCallbacks);
+
        void getCapabilities(void);
 
        void setEnabled(bool enabled);
@@ -72,6 +80,8 @@ public:
        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);
 
@@ -99,6 +109,8 @@ private:
                        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);
@@ -107,6 +119,9 @@ private:
        NanHalEventCallbackHandler mEventHandler;
        NanEventCallback mUserCallbacks;
 
+       RttHalEventCallbackHandler mRttEventHandler;
+       RttEventCallback mRttUserCallbacks;
+
        wifi_hal_fn mFunctionTable;
        wifi_handle mWifiHandle;
 
diff --git a/include/RttConfig.h b/include/RttConfig.h
new file mode 100644 (file)
index 0000000..6391b10
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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
diff --git a/include/RttEventCallback.h b/include/RttEventCallback.h
new file mode 100644 (file)
index 0000000..9e3d08f
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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
diff --git a/include/RttHalEventCallbackHandler.h b/include/RttHalEventCallbackHandler.h
new file mode 100644 (file)
index 0000000..b30d420
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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
diff --git a/include/RttResult.h b/include/RttResult.h
new file mode 100644 (file)
index 0000000..18d1145
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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
index 1498533d67435465d869996ccb1e3d9deed7e859..442ce8d053943002f159a7b242545818cfd8b1bc 100644 (file)
@@ -44,6 +44,8 @@ SET(SRCS
        ${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
index 44f0c379a1334753a30e49023f823c20e78dda6c..7c82f5c682e07e44f2ac2cf167bfe1887c557cba 100644 (file)
@@ -17,6 +17,8 @@
 #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;
@@ -120,6 +124,13 @@ NanError NanHal::registerCallbackHandler(const NanEventCallback& userCallbacks)
        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__;
@@ -549,6 +560,36 @@ void NanHal::deleteDataPathInterface(const std::string& dataPathIfaceName)
        __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");
@@ -1111,6 +1152,36 @@ NanDataPathEndRequest *NanHal::convertDataPathEndConfigToLegacyRequest(std::shar
        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)
index 3a1b0b75028fcf650670455c5ce08e94fcc2e41e..9437ba006f980c872bc5bd4c0c24ba9dbbdb628e 100644 (file)
@@ -687,7 +687,7 @@ void NanHalEventCallbackHandler::registerUserCallbacks(const NanEventCallback& u
        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;
index b9ef1455a4265514298c73d7b0988ceb1e86b829..8ac1e8c051d235f1728b8306ec28596faf973c9f 100644 (file)
@@ -52,6 +52,7 @@ void NanServiceProvider::init()
 void NanServiceProvider::registerCallbacks()
 {
        NanEventCallback callbacks;
+       RttEventCallback rttCallbacks;
 
        callbacks.on_notify_enable_response
                = [=](uint16_t transactionId, NanError error) {
@@ -158,7 +159,14 @@ void NanServiceProvider::registerCallbacks()
                        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)
diff --git a/src/RttConfig.cpp b/src/RttConfig.cpp
new file mode 100644 (file)
index 0000000..1ebe6f6
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * 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);
+}
diff --git a/src/RttHalEventCallbackHandler.cpp b/src/RttHalEventCallbackHandler.cpp
new file mode 100644 (file)
index 0000000..cccdf9f
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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;
+}