|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Inbound TCP listener for plugins (the server side the client socket API lacks). A plugin picks the port; the firmware binds/listens and accepts connections from the plugin tick task, handing each accepted socket to the plugin, which drives it through the existing host_socket_read/write/ close (the fd is adopted into the shared socket-slot pool). More...
#include "plugin_manager/host_api.h"#include "plugin_manager/Plugin.h"#include "plugin_manager/PluginManager.h"#include "cdc_log.h"#include "lwip/sockets.h"#include <cerrno>#include <cstring>#include <fcntl.h>#include <unistd.h>Go to the source code of this file.
Functions | |
| void * | plg_get_active_plugin (void) |
| int | plg_socket_adopt (int fd, void *owner) |
| int | host_net_listen (uint16_t port, uint32_t action_id) |
| Start a TCP listener on port; fires action_id while clients wait. | |
| int | host_net_accept (void) |
| Take the next accepted connection as a socket handle for host_socket_read/write/close. | |
| int | host_net_close (uint16_t port) |
| Stop the listener (pass 0 or the listening port). Closes pending un-accepted connections. | |
| void | plg_net_pump (void) |
| void | plg_net_on_unload (void *plugin) |
Inbound TCP listener for plugins (the server side the client socket API lacks). A plugin picks the port; the firmware binds/listens and accepts connections from the plugin tick task, handing each accepted socket to the plugin, which drives it through the existing host_socket_read/write/ close (the fd is adopted into the shared socket-slot pool).
No dedicated task: the listen socket is non-blocking and plg_net_pump() (plugin tick task) accepts pending connections, enqueues them and fires the plugin's action; the handler then calls host_net_accept(). Everything runs on the tick task, so no locking is needed. The listen socket is transparently re-opened after an accept error (covering a WiFi/socket drop across light sleep). One listener per plugin (v1). WiFi must be up (host_wifi_request) for clients to reach the badge; bind succeeds regardless and accept just waits.
Definition in file host_api_net.cpp.
| void * plg_get_active_plugin | ( | void | ) |
Definition at line 24 of file plugin_log_bridge.cpp.
Referenced by host_net_accept(), and host_net_listen().
| void plg_net_on_unload | ( | void * | plugin | ) |
Definition at line 168 of file host_api_net.cpp.
| void plg_net_pump | ( | void | ) |
Definition at line 141 of file host_api_net.cpp.
References cdc::plugin_manager::PluginManager::dispatchActionTo(), cdc::plugin_manager::PluginManager::instance(), LOG_I, and TAG.
Referenced by cdc::plugin_manager::PluginManager::dispatchTick().
| int plg_socket_adopt | ( | int | fd, |
| void * | owner ) |
Definition at line 216 of file host_api_socket.cpp.
References cdc::plugin_manager::SlotTable< T, N >::allocate(), HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, and HOST_SOCK_TCP.
Referenced by host_net_accept().