33 #ifndef __APPS_INCLUDE_NETUTILS_WEBSOCKET_H 34 #define __APPS_INCLUDE_NETUTILS_WEBSOCKET_H 41 #include <netinet/in.h> 42 #include <apps/netutils/wslay/wslay.h> 43 #include <tinyara/wqueue.h> 45 #include "tls/config.h" 46 #include "tls/entropy.h" 47 #include "tls/ctr_drbg.h" 48 #include "tls/certs.h" 52 #include "tls/error.h" 53 #include "tls/debug.h" 54 #include "tls/ssl_cache.h" 56 #define WEBSOCKET_DEBUG_PRINT 58 #if defined(WEBSOCKET_DEBUG_PRINT) 59 #define WEBSOCKET_DEBUG ndbg 61 #define WEBSOCKET_DEBUG(...) do { } while (0) 71 #define WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" 76 #define WEBSOCKET_STACKSIZE (1024 * 10) 80 #define WEBSOCKET_PRI 100 84 #define WEBSOCKET_SCHED_POLICY SCHED_RR 88 #define WEBSOCKET_WQ LPWORK 93 #define WEBSOCKET_CLIENT_KEY_LEN (24) 97 #define WEBSOCKET_ACCEPT_KEY_LEN (29) 101 #define WEBSOCKET_HANDSHAKE_HEADER_SIZE (2048) 108 #ifdef CONFIG_HW_RSA_SIGN 109 #define WEBSOCKET_SERVERNAME "ARTIK051_dev" 111 #define WEBSOCKET_SERVERNAME "localhost" 117 #define WEBSOCKET_SOCK_RCV_TIMEOUT (5 * 1000) //mili second 121 #define WEBSOCKET_SERVER_CHECK_INTERVAL (500) //mili second 125 #define WEBSOCKET_SERVER_TIMEOUT (3 * 60 * 1000) //mili second 130 #define WEBSOCKET_HANDLER_TIMEOUT (300) //mili second 135 #define WEBSOCKET_MAX_PING_IGNORE (3) //times 139 #define WEBSOCKET_PING_INTERVAL (20 * 100) //MSEC_PER_TICK 144 #define WEBSOCKET_MAX_LENGTH_QUEUE (100 * 1024) 148 #define WEBSOCKET_MAX_NUMBER_QUEUE (20) 153 #define WEBSOCKET_MAX_CLIENT (3) 163 #define websocket_context_ptr wslay_event_context_ptr 168 #define websocket_cb_t struct wslay_event_callbacks 182 #define websocket_frame_t struct wslay_event_msg 196 #define websocket_fragmented_frame_t struct wslay_event_fragmented_msg 212 #define websocket_on_msg_arg struct wslay_event_on_msg_recv_arg 227 #define websocket_recv_start_arg struct wslay_event_on_frame_recv_start_arg 240 #define websocket_recv_chunk_arg struct wslay_event_on_frame_recv_chunk_arg 251 #define WEBSOCKET_CHECK_NOT_CTRL_FRAME(x) (!(((x) >> 3) & 1)) 258 #define WEBSOCKET_CHECK_TEXT_FRAME(x) (((uint8_t)(x)) == ((uint8_t)(WEBSOCKET_TEXT_FRAME))) 265 #define WEBSOCKET_CHECK_BINARY_FRAME(x) (((uint8_t)(x)) == ((uint8_t)(WEBSOCKET_BINARY_FRAME))) 272 #define WEBSOCKET_CHECK_CTRL_CLOSE(x) (((uint8_t)(x)) == ((uint8_t)(WEBSOCKET_CONNECTION_CLOSE))) 279 #define WEBSOCKET_CHECK_CTRL_PING(x) (((uint8_t)(x)) == ((uint8_t)(WEBSOCKET_PING))) 286 #define WEBSOCKET_CHECK_CTRL_PONG(x) (((uint8_t)(x)) == ((uint8_t)(WEBSOCKET_PONG))) 376 struct work_s time_worker;
399 #define EXTERN extern "C" 402 #define EXTERN extern
websocket number of max state.
websocket_return_t websocket_server_init(websocket_t *server)
websocket_server_init
websocket context init fail
websocket_cb_t * cb
Each server of client should define callbacks to use websocket functions.
int ping_cnt
Counter for ping message without receiving pong.
websocket_return_t websocket_queue_close(websocket_t *websocket, const char *close_message)
websocket_queue_close() closes the websocket.
void websocket_set_error(websocket_t *websocket, int val)
websocket_set_error() sets an error number to websocket context.
int state
0 - closed 1 - running
int fd
Each server or client has own socket fd.
#define websocket_context_ptr
Websocket context pointer wrapper.
a control frame to close websocket
void websocket_update_state(websocket_t *websocket, int state)
websocket_update_state() changes websocket state.
mbedtls_ssl_config * tls_conf
TLS Initial configuration structure.
void websocket_create_accept_key(unsigned char *dst, size_t dlen, const unsigned char *src, size_t slen)
websocket_create_accept_key
websocket_return_t websocket_queue_ping(websocket_t *websocket)
websocket_queue_ping() is used to send a websocket ping message.
websocket_return_t websocket_queue_msg(websocket_t *websocket, websocket_frame_t *tx_frame)
structure to manage websocket client/server
pthread_attr_t thread_attr
Websocket event handler thread attribute.
data structure to use in callbacks.
websocket_context_ptr ctx
Websocket context to manage event queue, errors and configurations.
Structure of pthread attr configuration.
#define websocket_frame_t
Websocket structure wrapper to send a frame.
websocket_state
websocket states
int tls_enabled
TLS enable flag (1 - enable, 0 - disable)
int websocket_count_table(void)
websocket_count_table() returns amount of working websocket server.
void websocket_register_cb(websocket_t *websocket, websocket_cb_t *cb)
websocket_register_cb() changes a websocket callback structure in a websocket context.
http_server_state_t state
websocket_socket_error
websocket socket error codes
websocket_t * websocket_find_table(void)
websocket_find_table() returns websocket_t * to manage websocket server.
websocket_opcode
websocket operation code.
websocket_return_t
websocket return definitions
websocket_return_t websocket_server_open(websocket_t *server)
websocket_server_open() initiates websocket server.
#define websocket_cb_t
Websocket structure wrapper to carry call back pointers.
websocket_return_t websocket_client_open(websocket_t *client, char *addr, char *port, char *path)
websocket_client_open() initiates websocket client ready to send and receive websocket message...
pthread_t thread_id
Websocket event handler thread ID.
mbedtls_net_context tls_net
Contain network file descriptor.
mbedtls_ssl_context * tls_ssl
Handling all tls context informations.
websocket_io_flag
websocket io flags