Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "auth_token_providerImpl.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
std::string rfid_to_string(char const rfid[], size_t length) {
|
||||
std::stringstream ss;
|
||||
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
ss << std::setfill('0') << std::setw(2) << std::uppercase << std::hex << static_cast<uint16_t>(rfid[i]);
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
};
|
||||
|
||||
namespace module {
|
||||
namespace main {
|
||||
|
||||
void auth_token_providerImpl::init() {
|
||||
if (config.disable_nfc_rfid) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::filesystem::path config_path = mod->info.paths.etc / "libnfc_config";
|
||||
EVLOG_info << "Using configuration path " << config_path << " to look for 'libnfc-nci.conf' and 'libnfc-nxp.conf'";
|
||||
try {
|
||||
this->nfc_handler = std::make_unique<NfcHandler>(config_path);
|
||||
} catch (const std::exception& e) {
|
||||
EVLOG_error << "Failed to initialize libnfc handler: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void auth_token_providerImpl::new_rfid_token_callback(char* uid, size_t length, NfcHandler::Protocol protocol) {
|
||||
|
||||
// debounce
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const auto debounce_interval = std::chrono::milliseconds(config.token_debounce_interval_ms);
|
||||
|
||||
if (now < this->last_rfid_submit + debounce_interval) {
|
||||
// nothing to do, just debounce
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid == nullptr || length == 0 || length > 32) {
|
||||
// NOTE (aw): invalid data?, can this even happen?
|
||||
// NOTE (aw): we should probably log here?
|
||||
return;
|
||||
}
|
||||
|
||||
// convert token to string and publish ist
|
||||
types::authorization::ProvidedIdToken token;
|
||||
|
||||
token.id_token.type = [](NfcHandler::Protocol const in) {
|
||||
switch (in) {
|
||||
case NfcHandler::Protocol::ISO_IEC_15693:
|
||||
return types::authorization::IdTokenType::ISO15693;
|
||||
case NfcHandler::Protocol::MIFARE:
|
||||
return types::authorization::IdTokenType::ISO14443;
|
||||
case NfcHandler::Protocol::UNKNOWN:
|
||||
return types::authorization::IdTokenType::Local;
|
||||
}
|
||||
|
||||
// FIXME (aw): default would be unknown, what to do here?
|
||||
// choosing Local here, although this is not the proper way
|
||||
return types::authorization::IdTokenType::Local;
|
||||
}(protocol);
|
||||
token.id_token.value = rfid_to_string(uid, length);
|
||||
token.authorization_type = types::authorization::AuthorizationType::RFID;
|
||||
|
||||
if (config.debug) {
|
||||
EVLOG_info << "Publishing new rfid/nfc token: " << token;
|
||||
}
|
||||
this->publish_provided_token(token);
|
||||
|
||||
this->last_rfid_submit = now;
|
||||
}
|
||||
|
||||
void auth_token_providerImpl::ready() {
|
||||
if (this->nfc_handler) {
|
||||
this->nfc_handler->start(
|
||||
[this](auto&&... args) { this->new_rfid_token_callback(std::forward<decltype(args)>(args)...); });
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace main
|
||||
} // namespace module
|
||||
@@ -0,0 +1,71 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef MAIN_AUTH_TOKEN_PROVIDER_IMPL_HPP
|
||||
#define MAIN_AUTH_TOKEN_PROVIDER_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/auth_token_provider/Implementation.hpp>
|
||||
|
||||
#include "../PN7160TokenProvider.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
#include "libnfc_handler.hpp"
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace main {
|
||||
|
||||
struct Conf {
|
||||
int token_debounce_interval_ms;
|
||||
bool disable_nfc_rfid;
|
||||
bool debug;
|
||||
};
|
||||
|
||||
class auth_token_providerImpl : public auth_token_providerImplBase {
|
||||
public:
|
||||
auth_token_providerImpl() = delete;
|
||||
auth_token_providerImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<PN7160TokenProvider>& mod,
|
||||
Conf& config) :
|
||||
auth_token_providerImplBase(ev, "main"), mod(mod), config(config){};
|
||||
|
||||
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
|
||||
// insert your public definitions here
|
||||
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
|
||||
|
||||
protected:
|
||||
// no commands defined for this interface
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<PN7160TokenProvider>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
|
||||
std::unique_ptr<NfcHandler> nfc_handler{nullptr};
|
||||
|
||||
void new_rfid_token_callback(char*, size_t, NfcHandler::Protocol);
|
||||
|
||||
std::chrono::steady_clock::time_point last_rfid_submit{};
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
};
|
||||
|
||||
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1
|
||||
// insert other definitions here
|
||||
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1
|
||||
|
||||
} // namespace main
|
||||
} // namespace module
|
||||
|
||||
#endif // MAIN_AUTH_TOKEN_PROVIDER_IMPL_HPP
|
||||
@@ -0,0 +1,90 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include <cstdio>
|
||||
#include <iomanip>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
extern "C" {
|
||||
#include <linux_nfc_api.h>
|
||||
#include <linux_nfc_api_compatibility.h>
|
||||
}
|
||||
|
||||
#include "libnfc_handler.hpp"
|
||||
|
||||
// NOTE (aw): access to this variable is not thread safe
|
||||
// but for the current "one-shot" use, this should not be necessary
|
||||
static NfcHandler* nfc_handler_instance{nullptr};
|
||||
static nfcTagCallback_t nfc_callbacks;
|
||||
|
||||
NfcHandler::NfcHandler(const std::filesystem::path& config_path) {
|
||||
// we could have also used a singleton instance,
|
||||
if (nfc_handler_instance) {
|
||||
throw std::runtime_error("Only one nfc handler instance allowed");
|
||||
}
|
||||
|
||||
setConfigPath(config_path.c_str());
|
||||
|
||||
InitializeLogLevel();
|
||||
|
||||
if (doInitialize() != 0) {
|
||||
throw std::runtime_error("Failed to initialize libnfc_nci library");
|
||||
}
|
||||
|
||||
nfc_callbacks.onTagArrival = [](nfc_tag_info_t* tag_info) { nfc_handler_instance->on_tag_arrival(tag_info); };
|
||||
|
||||
nfc_callbacks.onTagDeparture = []() { nfc_handler_instance->on_tag_departure(); };
|
||||
|
||||
nfc_handler_instance = this;
|
||||
}
|
||||
|
||||
bool NfcHandler::start(Callback callback_) {
|
||||
if (this->callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->callback = std::move(callback_);
|
||||
|
||||
registerTagCallback(&nfc_callbacks);
|
||||
// enable discovery in reader-only mody, no host-routing/host-card-emulation and force a restart
|
||||
// doEnableDiscovery (int technologies_mask,
|
||||
// int reader_only_mode,
|
||||
// int enable_host_routing,
|
||||
// int restart)
|
||||
doEnableDiscovery(DEFAULT_NFA_TECH_MASK, 0x01, 0x0, 0x1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NfcHandler::on_tag_arrival(void* tag_info_) {
|
||||
// unfortunately, typedefs can't be forward declared, therefor we need to do it here
|
||||
const auto tag_info = reinterpret_cast<nfc_tag_info_t*>(tag_info_);
|
||||
|
||||
const auto protocol = [](tNFC_PROTOCOL const in) {
|
||||
if (in == NFA_PROTOCOL_MIFARE) {
|
||||
return Protocol::MIFARE;
|
||||
} else if (in == NFA_PROTOCOL_15693) {
|
||||
return Protocol::ISO_IEC_15693;
|
||||
}
|
||||
|
||||
return Protocol::UNKNOWN;
|
||||
}(tag_info->protocol);
|
||||
|
||||
if (this->callback) {
|
||||
this->callback(tag_info->uid, tag_info->uid_length, protocol);
|
||||
} else {
|
||||
// this should not happen
|
||||
// assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void NfcHandler::on_tag_departure() {
|
||||
// handle tag departure
|
||||
}
|
||||
|
||||
NfcHandler::~NfcHandler() {
|
||||
disableDiscovery();
|
||||
deregisterTagCallback();
|
||||
doDeinitialize();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <generated/interfaces/auth_token_provider/Implementation.hpp>
|
||||
|
||||
class NfcHandler {
|
||||
public:
|
||||
enum class Protocol {
|
||||
UNKNOWN,
|
||||
MIFARE,
|
||||
ISO_IEC_15693,
|
||||
};
|
||||
|
||||
using Callback = std::function<void(char* uid, size_t length, Protocol)>;
|
||||
|
||||
NfcHandler(const std::filesystem::path& config_path);
|
||||
~NfcHandler();
|
||||
|
||||
bool start(Callback);
|
||||
|
||||
private:
|
||||
void on_tag_arrival(void* pTagInfo);
|
||||
void on_tag_departure();
|
||||
|
||||
Callback callback{nullptr};
|
||||
};
|
||||
Reference in New Issue
Block a user