Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement uwb simulator driver dispatch handling for the LRP DDI #58

Merged
merged 19 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if (NOF_USE_VCPKG)
find_package(nlohmann_json CONFIG ${VERSION_NLOHMANN_JSON} REQUIRED)
find_package(magic_enum CONFIG ${VERSION_MAGIC_ENUM} REQUIRED)
find_package(CLI11 CONFIG ${VERSION_CLI11} REQUIRED)
find_package(plog CONFIG ${VERSION_PLOG} REQUIRED)
find_package(plog CONFIG REQUIRED)
else()
set(JSON_ImplicitConversions OFF)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v${VERSION_NLOHMANN_JSON}/json.tar.xz)
Expand Down
13 changes: 7 additions & 6 deletions lib/uwb/include/uwb/protocols/fira/FiraDevice.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ enum class UwbSessionType {
RangingSession,
TestMode,
};
enum class UwbSessionState {
Initialized,
Deinitialized,
Active,
Idle,
};
enum class UwbSessionReasonCode {
StateChangeWithSessionManagementCommands,
MaxRangignRoundRetryCountReached,
Expand Down Expand Up @@ -339,7 +345,7 @@ struct UwbDeviceInfoVendor
virtual ~UwbDeviceInfoVendor() = default;
};

struct UwbDeviceInfo
struct UwbDeviceInfoInformation
{
UwbVersion VersionUwb;
UwbVersion VersionUci;
Expand All @@ -363,11 +369,6 @@ enum class UwbApplicationConfigurationParameterType {
struct UwbApplicationConfigurationParameter
{};

struct UwbSessionState
{
uint32_t Id;
};

struct UwbStatusMulticastList
{
uint16_t ControleeMacAddress; // why is this uint16_t? TODO: replace with uwb::UwbMacAddress
Expand Down
7 changes: 5 additions & 2 deletions windows/devices/uwb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ target_sources(uwbcxadapter
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/UwbCxAdapter.cxx
${CMAKE_CURRENT_LIST_DIR}/UwbAppConfiguration.cxx
${CMAKE_CURRENT_LIST_DIR}/UwbCxAdapterDdiLrp.cxx
PUBLIC
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxAdapter.hxx
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbAppConfiguration.hxx
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxAdapter.hxx
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxAdapterDdiLrp.hxx
)

target_include_directories(uwbcxadapter
Expand All @@ -29,8 +31,9 @@ target_link_libraries(uwbcxadapter
)

list(APPEND UWBCXADAPTER_PUBLIC_HEADERS
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxAdapter.hxx
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbAppConfiguration.hxx
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxAdapter.hxx
${UWBCXADAPTER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxAdapterDdiLrp.hxx
)

set_target_properties(uwbcxadapter PROPERTIES FOLDER windows/devices/uwb)
Expand Down
106 changes: 106 additions & 0 deletions windows/devices/uwb/UwbCxAdapterDdiLrp.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

#include <algorithm>
#include <functional>
#include <stdexcept>
#include <type_traits>
#include <unordered_map>
#include <variant>

#include <windows/devices/uwb/UwbCxAdapterDdiLrp.hxx>

using namespace ::uwb::protocol::fira;

UWB_STATUS
windows::devices::uwb::ddi::lrp::From(const UwbStatus& uwbStatus)
{
static const std::unordered_map<UwbStatusGeneric, UWB_STATUS> StatusMapGeneric{
{ UwbStatusGeneric::Ok, UWB_STATUS_OK },
{ UwbStatusGeneric::Rejected, UWB_STATUS_REJECTED },
{ UwbStatusGeneric::Failed, UWB_STATUS_FAILED },
{ UwbStatusGeneric::SyntaxError, UWB_STATUS_SYNTAX_ERROR },
{ UwbStatusGeneric::InvalidParameter, UWB_STATUS_INVALID_PARAM },
{ UwbStatusGeneric::InvalidRange, UWB_STATUS_INVALID_RANGE },
{ UwbStatusGeneric::InvalidMessageSize, UWB_STATUS_INVALID_MESSAGE_SIZE },
{ UwbStatusGeneric::UnknownGid, UWB_STATUS_UNKNOWN_GID },
{ UwbStatusGeneric::UnknownOid, UWB_STATUS_UNKNOWN_OID },
{ UwbStatusGeneric::ReadOnly, UWB_STATUS_READ_ONLY },
{ UwbStatusGeneric::CommandRetry, UWB_STATUS_COMMAND_RETRY },
};
static const std::unordered_map<UwbStatusSession, UWB_STATUS> StatusMapSession{
{ UwbStatusSession::NotExist, UWB_STATUS_ERROR_SESSION_NOT_EXIST },
{ UwbStatusSession::Duplicate, UWB_STATUS_ERROR_SESSION_DUPLICATE },
{ UwbStatusSession::Active, UWB_STATUS_ERROR_SESSION_ACTIVE },
{ UwbStatusSession::MaxSessionsExceeded, UWB_STATUS_ERROR_MAX_SESSIONS_EXCEEDED },
{ UwbStatusSession::NotConfigured, UWB_STATUS_ERROR_SESSION_NOT_CONFIGURED },
{ UwbStatusSession::ActiveSessionsOngoing, UWB_STATUS_ERROR_ACTIVE_SESSIONS_ONGOING },
{ UwbStatusSession::MulticastListFull, UWB_STATUS_ERROR_MULTICAST_LIST_FULL },
{ UwbStatusSession::AddressNotFound, UWB_STATUS_ERROR_ADDRESS_NOT_FOUND },
{ UwbStatusSession::AddressAlreadyPresent, UWB_STATUS_ERROR_ADDRESS_ALREADY_PRESENT },
};
static const std::unordered_map<UwbStatusRanging, UWB_STATUS> StatusMapRanging{
{ UwbStatusRanging::TxFailed, UWB_STATUS_RANGING_TX_FAILED },
{ UwbStatusRanging::RxTimeout, UWB_STATUS_RANGING_RX_TIMEOUT },
{ UwbStatusRanging::RxPhyDecodingFailed, UWB_STATUS_RANGING_RX_PHY_DEC_FAILED },
{ UwbStatusRanging::RxPhyToaFailed, UWB_STATUS_RANGING_RX_PHY_TOA_FAILED },
{ UwbStatusRanging::RxPhyStsFailed, UWB_STATUS_RANGING_RX_PHY_STS_FAILED },
{ UwbStatusRanging::MacDecodingFailed, UWB_STATUS_RANGING_RX_MAC_DEC_FAILED },
{ UwbStatusRanging::RxMacIeDecodingFailed, UWB_STATUS_RANGING_RX_MAC_IE_DEC_FAILED },
{ UwbStatusRanging::RxMacIeMissing, UWB_STATUS_RANGING_RX_MAC_IE_MISSING },
};

UWB_STATUS status = UWB_STATUS_FAILED;

std::visit([&status](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, UwbStatusGeneric>) {
status = StatusMapGeneric.at(arg);
} else if constexpr (std::is_same_v<T, UwbStatusSession>) {
status = StatusMapSession.at(arg);
} else if constexpr (std::is_same_v<T, UwbStatusRanging>) {
status = StatusMapRanging.at(arg);
} else {
throw std::runtime_error("unknown UwbStatus variant value encountered");
}
},
uwbStatus);

return status;
}

UWB_SESSION_STATE
windows::devices::uwb::ddi::lrp::From(const UwbSessionState uwbSessionState)
{
switch (uwbSessionState) {
case UwbSessionState::Initialized:
return UWB_SESSION_STATE_INIT;
case UwbSessionState::Deinitialized:
return UWB_SESSION_STATE_DEINIT;
case UwbSessionState::Active:
return UWB_SESSION_STATE_ACTIVE;
case UwbSessionState::Idle:
return UWB_SESSION_STATE_IDLE;
}

throw std::runtime_error("unknown enumeration value");
}

UWB_DEVICE_INFO
windows::devices::uwb::ddi::lrp::From(const UwbDeviceInfoInformation& uwbDeviceInfo)
{
UWB_DEVICE_INFO deviceInfo{};
deviceInfo.size = sizeof deviceInfo;
deviceInfo.status = From(uwbDeviceInfo.Status);
deviceInfo.vendorSpecificInfoLength = 0;
// TODO: fill in remaining fields
return deviceInfo;
}

UWB_DEVICE_CAPABILITIES
windows::devices::uwb::ddi::lrp::From(const UwbDeviceCapabilities& /*uwbDeviceCapabilities*/)
{
UWB_DEVICE_CAPABILITIES deviceCapabilities{};
deviceCapabilities.size = sizeof deviceCapabilities;
deviceCapabilities.capabilityParamsCount = 0;
// TODO: implement this properly
return deviceCapabilities;
}
3 changes: 1 addition & 2 deletions windows/devices/uwb/UwbDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <stdexcept>
#include <unordered_map>

#include <UwbCxLrpDeviceGlue.h>

#include <windows/devices/uwb/UwbCxDdiLrp.hxx>
#include <windows/devices/uwb/UwbDevice.hxx>
#include <windows/devices/uwb/UwbSession.hxx>

Expand Down
2 changes: 1 addition & 1 deletion windows/devices/uwb/UwbSession.cxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

#include <UwbCxLrpDeviceGlue.h>
#include <wil/result.h>

#include <algorithm>
#include <memory>
#include <numeric>

#include <windows/devices/uwb/UwbCxAdapter.hxx>
#include <windows/devices/uwb/UwbCxDdiLrp.hxx>
#include <windows/devices/uwb/UwbSession.hxx>

using namespace windows::devices::uwb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include <vector>

#include <uwb/protocols/fira/UwbConfiguration.hxx>

#include <UwbCxLrpDeviceGlue.h>
#include <windows/devices/uwb/UwbCxDdiLrp.hxx>

namespace windows::devices::uwb
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

#ifndef UWB_CX_ADAPTER_DDI_LRP_HXX
#define UWB_CX_ADAPTER_DDI_LRP_HXX

#include <uwb/protocols/fira/FiraDevice.hxx>
#include <windows/devices/uwb/UwbCxDdiLrp.hxx>

/**
* @brief Define LRP DDI conversion functionality as free functions in a
* namespace.
*
* The namespace name is intended to be used explicitly in the
* function call, which can help identify the type of conversion being done.
* This allows usage such as:
*
* UwbStatus uwbStatus = GetStatus();
* UWB_STATUS ddiStatus = uwb::ddi::lrp::From(uwbStatus);
*/
namespace windows::devices::uwb::ddi::lrp
{
/**
* @brief Converts UwbStatus to UWB_STATUS.
*
* @param uwbStatus
* @return UWB_STATUS
*/
UWB_STATUS
From(const ::uwb::protocol::fira::UwbStatus &uwbStatus);

/**
* @brief Converts UwbSessionState to UWB_SESSION_STATE.
*
* @param uwbSessionState
* @return UWB_SESSION_STATE
*/
UWB_SESSION_STATE
From(const ::uwb::protocol::fira::UwbSessionState uwbSessionState);

/**
* @brief Converts UwbDeviceInfoInformation to UWB_DEVICE_INFO.
*
* @param uwbDeviceInfo
* @return UWB_DEVICE_INFO
*/
UWB_DEVICE_INFO
From(const ::uwb::protocol::fira::UwbDeviceInfoInformation &uwbDeviceInfo);

/**
* @brief Converts UwbDeviceCapabilities to UWB_DEVICE_CAPABILITIES.
*
* @param uwbDeviceCapabilities
* @return UWB_DEVICE_CAPABILITIES
*/
UWB_DEVICE_CAPABILITIES
From(const ::uwb::protocol::fira::UwbDeviceCapabilities &uwbDeviceCapabilities);

} // namespace windows::devices::uwb::ddi::lrp

#endif // UWB_CX_ADAPTER_DDI_LRP_HXX
9 changes: 5 additions & 4 deletions windows/drivers/uwb/cx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
add_library(uwbcx-driver INTERFACE)

set(UWBCXDRIVER_DIR_PUBLIC_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/include)
set(UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX ${UWBCXDRIVER_DIR_PUBLIC_INCLUDE})
set(UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX ${UWBCXDRIVER_DIR_PUBLIC_INCLUDE}/windows/devices/uwb)

target_sources(uwbcx-driver
INTERFACE
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxDdiLrp.hxx
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxLrpDevice.h
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxLrpDeviceGlue.h
)

target_include_directories(uwbcx-driver
INTERFACE
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE}
)

list(APPEND UWBCXDRIVER_PUBLIC_HEADERS
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxDdiLrp.hxx
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxLrpDevice.h
${UWBCXDRIVER_DIR_PUBLIC_INCLUDE_PREFIX}/UwbCxLrpDeviceGlue.h
)

set_target_properties(uwbcx-driver PROPERTIES FOLDER windows/devices/uwb)
Expand All @@ -26,4 +26,5 @@ set_target_properties(uwbcx-driver PROPERTIES PUBLIC_HEADER "${UWBCXDRIVER_PUBLI
install(
TARGETS uwbcx-driver
EXPORT uwbcx-driver
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/windows/devices/uwb
)
12 changes: 0 additions & 12 deletions windows/drivers/uwb/cx/include/UwbCxLrpDeviceGlue.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#ifndef UWBCX_DDI_LRP_HXX
#define UWBCX_DDI_LRP_HXX

// NB: This must come before any other Windows include
#include <stdint.h>
#include <windows.h>
#include <winioctl.h>

#include <windows/devices/uwb/UwbCxLrpDevice.h>

#endif // UWBCX_DDI_LRP_HXX
10 changes: 5 additions & 5 deletions windows/drivers/uwb/simulator/UwbSimulatorDdiCallbacksLrp.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct UwbSimulatorDdiCallbacksLrp
* @return UwbStatus
*/
virtual UwbStatus
DeviceGetInformation(UwbDeviceInfo &deviceInfo) = 0;
DeviceGetInformation(UwbDeviceInfoInformation &deviceInfo) = 0;

/**
* @brief
Expand Down Expand Up @@ -126,7 +126,7 @@ struct UwbSimulatorDdiCallbacksLrp
* @return UwbStatus
*/
virtual UwbStatus
SessionGetState(uint32_t sessionId, UwbSessionState *sessionState) = 0;
SessionGetState(uint32_t sessionId, UwbSessionState &sessionState) = 0;

/**
* @brief
Expand Down Expand Up @@ -166,9 +166,9 @@ struct UwbSimulatorDdiCallbacksLrp
SessionGetRangingCount(uint32_t sessionId, uint32_t *rangingCount) = 0;

/**
* @brief
*
* @param notificationData
* @brief
*
* @param notificationData
*/
virtual void
UwbNotification(UwbNotificationData notificationData) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ UwbSimulatorDdiCallbacksLrpNoop::DeviceReset()
}

UwbStatus
UwbSimulatorDdiCallbacksLrpNoop::DeviceGetInformation(UwbDeviceInfo &deviceInfo)
UwbSimulatorDdiCallbacksLrpNoop::DeviceGetInformation(UwbDeviceInfoInformation &deviceInfo)
{
deviceInfo = {};
return UwbStatusOk;
Expand Down Expand Up @@ -72,7 +72,7 @@ UwbSimulatorDdiCallbacksLrpNoop::GetSessionCount(uint32_t * /* sessionCount */)
}

UwbStatus
UwbSimulatorDdiCallbacksLrpNoop::SessionGetState(uint32_t /* sessionId */, UwbSessionState * /* sessionState */)
UwbSimulatorDdiCallbacksLrpNoop::SessionGetState(uint32_t /* sessionId */, UwbSessionState & /* sessionState */)
{
return UwbStatusOk;
}
Expand Down Expand Up @@ -104,5 +104,4 @@ UwbSimulatorDdiCallbacksLrpNoop::SessionGetRangingCount(uint32_t /* sessionId */
void
UwbSimulatorDdiCallbacksLrpNoop::UwbNotification(UwbNotificationData notificationData)
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct UwbSimulatorDdiCallbacksLrpNoop :
DeviceReset() override;

virtual UwbStatus
DeviceGetInformation(UwbDeviceInfo &deviceInfo) override;
DeviceGetInformation(UwbDeviceInfoInformation &deviceInfo) override;

virtual UwbStatus
DeviceGetCapabilities(UwbDeviceCapabilities &deviceCapabilities) override;
Expand All @@ -43,7 +43,7 @@ struct UwbSimulatorDdiCallbacksLrpNoop :
GetSessionCount(uint32_t *sessionCount) override;

virtual UwbStatus
SessionGetState(uint32_t sessionId, UwbSessionState *sessionState) override;
SessionGetState(uint32_t sessionId, UwbSessionState &sessionState) override;

virtual UwbStatus
SessionUpdateControllerMulticastList(const std::vector<UwbMacAddress> &controlees) override;
Expand Down
Loading