CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
host_api_usb.cpp
Go to the documentation of this file.
1
5
8#include "usb_badge/usb_cdc.h"
9
10extern "C" void* plg_get_active_plugin(void);
11
12namespace {
13bool allowed() {
14 auto* p = static_cast<cdc::plugin_manager::Plugin*>(plg_get_active_plugin());
15 return p && p->manifest().capabilities.usb_cdc;
16}
17} // namespace
18
19extern "C" {
20
21int host_usb_cdc_write(const uint8_t* data, size_t len)
22{
23 if (!data && len) return HOST_ERR_INVALID_ARG;
24 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
25 if (len == 0) return HOST_OK;
26 size_t written = usb_cdc_write(data, len);
27 return written == len ? HOST_OK : HOST_ERR_GENERIC;
28}
29
30} // extern "C"
Owned WAMR module instance + per-plugin state.
const PluginManifest & manifest() const noexcept
Definition Plugin.h:88
int host_usb_cdc_write(const uint8_t *data, size_t len)
Write raw bytes to the USB-CDC TX stream.
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_ERR_NO_CAPABILITY
Definition host_api.h:40
#define HOST_OK
Definition host_api.h:37
#define HOST_ERR_INVALID_ARG
Definition host_api.h:39
#define HOST_ERR_GENERIC
Definition host_api.h:38
void * plg_get_active_plugin(void)
size_t usb_cdc_write(const uint8_t *data, size_t len)
Writes byte buffer to USB CDC endpoint.
Definition usb_cdc.cpp:206