7#ifndef ZEPHYR_INCLUDE_SHELL_WEBSOCKET_H_
8#define ZEPHYR_INCLUDE_SHELL_WEBSOCKET_H_
19#define SHELL_WEBSOCKET_SERVICE_COUNT CONFIG_SHELL_WEBSOCKET_BACKEND_COUNT
24 char buf[CONFIG_SHELL_WEBSOCKET_LINE_BUF_SIZE];
68#define GET_WS_NAME(_service) ws_ctx_##_service
69#define GET_WS_SHELL_NAME(_name) shell_websocket_##_name
70#define GET_WS_TRANSPORT_NAME(_service) transport_shell_ws_##_service
71#define GET_WS_DETAIL_NAME(_service) ws_res_detail_##_service
73#define SHELL_WEBSOCKET_DEFINE(_service) \
74 static struct shell_websocket GET_WS_NAME(_service); \
75 static struct shell_transport GET_WS_TRANSPORT_NAME(_service) = { \
76 .api = &shell_websocket_transport_api, \
77 .ctx = &GET_WS_NAME(_service), \
80#define SHELL_WS_PORT_NAME(_service) http_service_##_service
81#define SHELL_WS_BUF_NAME(_service) ws_recv_buffer_##_service
82#define SHELL_WS_TEMP_RECV_BUF_SIZE 256
84#define DEFINE_WEBSOCKET_HTTP_SERVICE(_service) \
85 uint8_t SHELL_WS_BUF_NAME(_service)[SHELL_WS_TEMP_RECV_BUF_SIZE]; \
86 struct http_resource_detail_websocket \
87 GET_WS_DETAIL_NAME(_service) = { \
89 .type = HTTP_RESOURCE_TYPE_WEBSOCKET, \
92 .bitmask_of_supported_http_methods = BIT(HTTP_GET), \
94 .cb = shell_websocket_setup, \
95 .data_buffer = SHELL_WS_BUF_NAME(_service), \
96 .data_buffer_len = sizeof(SHELL_WS_BUF_NAME(_service)), \
97 .user_data = &GET_WS_NAME(_service), \
99 HTTP_RESOURCE_DEFINE(ws_resource_##_service, _service, \
100 "/" CONFIG_SHELL_WEBSOCKET_ENDPOINT_URL, \
101 &GET_WS_DETAIL_NAME(_service))
103#define DEFINE_WEBSOCKET_SERVICE(_service) \
104 SHELL_WEBSOCKET_DEFINE(_service); \
105 SHELL_DEFINE(shell_websocket_##_service, \
106 CONFIG_SHELL_WEBSOCKET_PROMPT, \
107 &GET_WS_TRANSPORT_NAME(_service), \
108 CONFIG_SHELL_WEBSOCKET_LOG_MESSAGE_QUEUE_SIZE, \
109 CONFIG_SHELL_WEBSOCKET_LOG_MESSAGE_QUEUE_TIMEOUT, \
110 SHELL_FLAG_OLF_CRLF); \
111 DEFINE_WEBSOCKET_HTTP_SERVICE(_service)
113#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
115#define WEBSOCKET_CONSOLE_DEFINE(_service, _sec_tag_list, _sec_tag_list_size) \
116 static uint16_t SHELL_WS_PORT_NAME(_service) = \
117 CONFIG_SHELL_WEBSOCKET_PORT; \
118 HTTPS_SERVICE_DEFINE(_service, \
119 CONFIG_SHELL_WEBSOCKET_IP_ADDR, \
120 &SHELL_WS_PORT_NAME(_service), \
121 SHELL_WEBSOCKET_SERVICE_COUNT, \
122 SHELL_WEBSOCKET_SERVICE_COUNT, \
125 _sec_tag_list_size); \
126 DEFINE_WEBSOCKET_SERVICE(_service); \
131#define WEBSOCKET_CONSOLE_DEFINE(_service, _sec_tag_list, _sec_tag_list_size) \
132 static uint16_t SHELL_WS_PORT_NAME(_service) = \
133 CONFIG_SHELL_WEBSOCKET_PORT; \
134 HTTP_SERVICE_DEFINE(_service, \
135 CONFIG_SHELL_WEBSOCKET_IP_ADDR, \
136 &SHELL_WS_PORT_NAME(_service), \
137 SHELL_WEBSOCKET_SERVICE_COUNT, \
138 SHELL_WEBSOCKET_SERVICE_COUNT, \
140 DEFINE_WEBSOCKET_SERVICE(_service)
144#define WEBSOCKET_CONSOLE_ENABLE(_service) \
145 (void)shell_websocket_enable(&GET_WS_SHELL_NAME(_service))
void(* shell_transport_handler_t)(enum shell_transport_evt evt, void *context)
Definition shell.h:624
BSD Sockets compatible API definitions.
#define CONFIG_SHELL_CMD_BUFF_SIZE
Definition shell.h:34
int shell_websocket_enable(const struct shell *sh)
int shell_websocket_setup(int ws_socket, void *user_data)
const struct shell_transport_api shell_websocket_transport_api
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Mutex Structure.
Definition kernel.h:2994
A structure used to submit work after a delay.
Definition kernel.h:3985
A structure holding internal state for a pending synchronous operation on a work item or queue.
Definition kernel.h:4068
Unified shell transport interface.
Definition shell.h:646
Line buffer structure.
Definition shell_websocket.h:22
char buf[CONFIG_SHELL_WEBSOCKET_LINE_BUF_SIZE]
Line buffer.
Definition shell_websocket.h:24
uint16_t len
Current line length.
Definition shell_websocket.h:27
WEBSOCKET-based shell transport.
Definition shell_websocket.h:31
void * shell_context
Context registered by shell.
Definition shell_websocket.h:36
struct shell_websocket_line_buf line_out
Buffer for outgoing line.
Definition shell_websocket.h:39
struct k_work_sync work_sync
Definition shell_websocket.h:58
size_t rx_len
Number of data bytes within the input buffer.
Definition shell_websocket.h:48
struct zsock_pollfd fds[1]
Array for sockets used by the websocket service.
Definition shell_websocket.h:42
struct k_work_delayable send_work
The delayed work is used to send non-lf terminated output that has been around for "too long".
Definition shell_websocket.h:57
shell_transport_handler_t shell_handler
Handler function registered by shell.
Definition shell_websocket.h:33
struct k_mutex rx_lock
Mutex protecting the input buffer access.
Definition shell_websocket.h:51
bool output_lock
If set, no output is sent to the WEBSOCKET client.
Definition shell_websocket.h:61
uint8_t rx_buf[CONFIG_SHELL_CMD_BUFF_SIZE]
Input buffer.
Definition shell_websocket.h:45
Shell instance internals.
Definition shell.h:890
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:31