web_socket.h
Go to the documentation of this file.
1 /**
2  * @file web_socket.h
3  * @brief WebSocket API (client and server)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _WEB_SOCKET_H
32 #define _WEB_SOCKET_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/socket.h"
37 
38 //WebSocket support
39 #ifndef WEB_SOCKET_SUPPORT
40  #define WEB_SOCKET_SUPPORT DISABLED
41 #elif (WEB_SOCKET_SUPPORT != ENABLED && WEB_SOCKET_SUPPORT != DISABLED)
42  #error WEB_SOCKET_SUPPORT parameter is not valid
43 #endif
44 
45 //Number of WebSockets that can be opened simultaneously
46 #ifndef WEB_SOCKET_MAX_COUNT
47  #define WEB_SOCKET_MAX_COUNT 4
48 #elif (WEB_SOCKET_MAX_COUNT < 1)
49  #error WEB_SOCKET_MAX_COUNT parameter is not valid
50 #endif
51 
52 //Support for WebSocket connections over TLS
53 #ifndef WEB_SOCKET_TLS_SUPPORT
54  #define WEB_SOCKET_TLS_SUPPORT DISABLED
55 #elif (WEB_SOCKET_TLS_SUPPORT != ENABLED && WEB_SOCKET_TLS_SUPPORT != DISABLED)
56  #error WEB_SOCKET_TLS_SUPPORT parameter is not valid
57 #endif
58 
59 //Basic access authentication support
60 #ifndef WEB_SOCKET_BASIC_AUTH_SUPPORT
61  #define WEB_SOCKET_BASIC_AUTH_SUPPORT DISABLED
62 #elif (WEB_SOCKET_BASIC_AUTH_SUPPORT != ENABLED && WEB_SOCKET_BASIC_AUTH_SUPPORT != DISABLED)
63  #error WEB_SOCKET_BASIC_AUTH_SUPPORT parameter is not valid
64 #endif
65 
66 //Digest access authentication support
67 #ifndef WEB_SOCKET_DIGEST_AUTH_SUPPORT
68  #define WEB_SOCKET_DIGEST_AUTH_SUPPORT DISABLED
69 #elif (WEB_SOCKET_DIGEST_AUTH_SUPPORT != ENABLED && WEB_SOCKET_DIGEST_AUTH_SUPPORT != DISABLED)
70  #error WEB_SOCKET_DIGEST_AUTH_SUPPORT parameter is not valid
71 #endif
72 
73 //Maximum number of connection attempts
74 #ifndef WEB_SOCKET_MAX_CONN_RETRIES
75  #define WEB_SOCKET_MAX_CONN_RETRIES 3
76 #elif (WEB_SOCKET_MAX_CONN_RETRIES < 1)
77  #error WEB_SOCKET_MAX_CONN_RETRIES parameter is not valid
78 #endif
79 
80 //Size of the WebSocket buffer
81 #ifndef WEB_SOCKET_BUFFER_SIZE
82  #define WEB_SOCKET_BUFFER_SIZE 1024
83 #elif (WEB_SOCKET_BUFFER_SIZE < 128)
84  #error WEB_SOCKET_BUFFER_SIZE parameter is not valid
85 #endif
86 
87 //Maximum length of the hostname
88 #ifndef WEB_SOCKET_HOST_MAX_LEN
89  #define WEB_SOCKET_HOST_MAX_LEN 32
90 #elif (WEB_SOCKET_HOST_MAX_LEN < 1)
91  #error WEB_SOCKET_HOST_MAX_LEN parameter is not valid
92 #endif
93 
94 //Maximum length of the origin header field
95 #ifndef WEB_SOCKET_ORIGIN_MAX_LEN
96  #define WEB_SOCKET_ORIGIN_MAX_LEN 16
97 #elif (WEB_SOCKET_ORIGIN_MAX_LEN < 1)
98  #error WEB_SOCKET_ORIGIN_MAX_LEN parameter is not valid
99 #endif
100 
101 //Maximum length of the sub-protocol
102 #ifndef WEB_SOCKET_SUB_PROTOCOL_MAX_LEN
103  #define WEB_SOCKET_SUB_PROTOCOL_MAX_LEN 8
104 #elif (WEB_SOCKET_SUB_PROTOCOL_MAX_LEN < 1)
105  #error WEB_SOCKET_SUB_PROTOCOL_MAX_LEN parameter is not valid
106 #endif
107 
108 //Maximum length of the URI
109 #ifndef WEB_SOCKET_URI_MAX_LEN
110  #define WEB_SOCKET_URI_MAX_LEN 32
111 #elif (WEB_SOCKET_URI_MAX_LEN < 1)
112  #error WEB_SOCKET_URI_MAX_LEN parameter is not valid
113 #endif
114 
115 //Maximum length of the query string
116 #ifndef WEB_SOCKET_QUERY_STRING_MAX_LEN
117  #define WEB_SOCKET_QUERY_STRING_MAX_LEN 32
118 #elif (WEB_SOCKET_QUERY_STRING_MAX_LEN < 1)
119  #error WEB_SOCKET_QUERY_STRING_MAX_LEN parameter is not valid
120 #endif
121 
122 //Maximum length of the realm
123 #ifndef WEB_SOCKET_REALM_MAX_LEN
124  #define WEB_SOCKET_REALM_MAX_LEN 32
125 #elif (WEB_SOCKET_REALM_MAX_LEN < 1)
126  #error WEB_SOCKET_REALM_MAX_LEN parameter is not valid
127 #endif
128 
129 //Maximum length of the user name
130 #ifndef WEB_SOCKET_USERNAME_MAX_LEN
131  #define WEB_SOCKET_USERNAME_MAX_LEN 16
132 #elif (WEB_SOCKET_USERNAME_MAX_LEN < 1)
133  #error WEB_SOCKET_USERNAME_MAX_LEN parameter is not valid
134 #endif
135 
136 //Maximum length of the password
137 #ifndef WEB_SOCKET_PASSWORD_MAX_LEN
138  #define WEB_SOCKET_PASSWORD_MAX_LEN 16
139 #elif (WEB_SOCKET_PASSWORD_MAX_LEN < 1)
140  #error WEB_SOCKET_PASSWORD_MAX_LEN parameter is not valid
141 #endif
142 
143 //Maximum length of the nonce
144 #ifndef WEB_SOCKET_NONCE_MAX_LEN
145  #define WEB_SOCKET_NONCE_MAX_LEN 32
146 #elif (WEB_SOCKET_NONCE_MAX_LEN < 1)
147  #error WEB_SOCKET_NONCE_MAX_LEN parameter is not valid
148 #endif
149 
150 //Maximum length of the opaque parameter
151 #ifndef WEB_SOCKET_OPAQUE_MAX_LEN
152  #define WEB_SOCKET_OPAQUE_MAX_LEN 32
153 #elif (WEB_SOCKET_OPAQUE_MAX_LEN < 1)
154  #error WEB_SOCKET_OPAQUE_MAX_LEN parameter is not valid
155 #endif
156 
157 //Cnonce size
158 #ifndef WEB_SOCKET_CNONCE_SIZE
159  #define WEB_SOCKET_CNONCE_SIZE 16
160 #elif (WEB_SOCKET_CNONCE_SIZE < 1)
161  #error WEB_SOCKET_CNONCE_SIZE parameter is not valid
162 #endif
163 
164 //TLS supported?
165 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
166  #include "core/crypto.h"
167  #include "tls.h"
168 #endif
169 
170 //Client key size
171 #define WEB_SOCKET_CLIENT_KEY_SIZE 24
172 //Server key size
173 #define WEB_SOCKET_SERVER_KEY_SIZE 28
174 
175 //Forward declaration of WebSocket structure
176 struct _WebSocket;
177 #define WebSocket struct _WebSocket
178 
179 //C++ guard
180 #ifdef __cplusplus
181 extern "C" {
182 #endif
183 
184 
185 /**
186  * @brief WebSocket endpoint types
187  **/
188 
189 typedef enum
190 {
194 
195 
196 /**
197  * @brief HTTP version numbers
198  **/
199 
200 typedef enum
201 {
204  WS_HTTP_VERSION_1_1 = 0x0101
206 
207 
208 /**
209  * @brief Authentication schemes
210  **/
211 
212 typedef enum
213 {
216  WS_AUTH_MODE_DIGEST = 0x02
218 
219 
220 /**
221  * @brief WebSocket states
222  **/
223 
224 typedef enum
225 {
238 
239 
240 /**
241  * @brief WebSocket sub-states
242  **/
243 
244 typedef enum
245 {
247  //Handshake decoding
251  //WebSocket frame decoding
256 
257 
258 /**
259  * @brief WebSocket frame types
260  **/
261 
262 typedef enum
263 {
269  WS_FRAME_TYPE_PONG = 0x0A
271 
272 
273 /**
274  * @brief WebSocket status codes
275  **/
276 
277 typedef enum
278 {
292 
293 
294 //CC-RX, CodeWarrior or Win32 compiler?
295 #if defined(__CCRX__)
296  #pragma pack
297 #elif defined(__CWCC__) || defined(_WIN32)
298  #pragma pack(push, 1)
299 #endif
300 
301 
302 /**
303  * @brief WebSocket frame
304  **/
305 
307 {
308 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
309  uint8_t fin : 1; //0
310  uint8_t reserved : 3;
311  uint8_t opcode : 4;
312  uint8_t mask : 1; //1
313  uint8_t payloadLen : 7;
314 #else
315  uint8_t opcode : 4; //0
316  uint8_t reserved : 3;
317  uint8_t fin : 1;
318  uint8_t payloadLen : 7; //1
319  uint8_t mask : 1;
320 #endif
321  uint8_t extPayloadLen[]; //2
323 
324 
325 //CC-RX, CodeWarrior or Win32 compiler?
326 #if defined(__CCRX__)
327  #pragma unpack
328 #elif defined(__CWCC__) || defined(_WIN32)
329  #pragma pack(pop)
330 #endif
331 
332 
333 /**
334  * @brief Random data generation callback function
335  **/
336 
337 typedef error_t (*WebSocketRandCallback)(uint8_t *data, size_t length);
338 
339 
340 //TLS supported?
341 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
342 
343 /**
344  * @brief TLS initialization callback function
345  **/
346 
349 
350 #endif
351 
352 
353 /**
354  * @brief Authentication context
355  **/
356 
357 typedef struct
358 {
365 #if (WEB_SOCKET_DIGEST_AUTH_SUPPORT == ENABLED)
366  uint32_t nc;
371 #endif
373 
374 
375 /**
376  * @brief Handshake context
377  **/
378 
379 typedef struct
380 {
392 
393 
394 /**
395  * @brief Frame encoding/decoding context
396  **/
397 
398 typedef struct
399 {
400  WebSocketSubState state; ///FSM state
401  WebSocketFrameType dataFrameType; ///<Data frame type
402  WebSocketFrameType controlFrameType; ///<Control frame type
403  bool_t fin; ///<Final fragment in a message
404  bool_t mask; ///<Defines whether the payload data is masked
405  uint8_t maskingKey[4]; ///<Masking key
406  size_t payloadLen; ///<Payload length
407  size_t payloadPos; ///<Current position
408  uint8_t buffer[WEB_SOCKET_BUFFER_SIZE]; ///<Data buffer
409  size_t bufferLen; ///<Length of the data buffer
410  size_t bufferPos; ///<Current position
412 
413 
414 /**
415  * @brief UTF-8 decoding context
416  **/
417 
418 typedef struct
419 {
422  uint32_t utf8CodePoint;
424 
425 
426 /**
427  * @brief Structure describing a WebSocket
428  **/
429 
431 {
432  WebSocketEndpoint endpoint; ///<Endpoint type (client or server)
433  WebSocketState state; ///<WebSocket connection state
434  uint16_t statusCode;
437  char_t host[WEB_SOCKET_HOST_MAX_LEN + 1]; ///<Domain name of the server (for virtual hosting)
442  systime_t timeout; ///<timeout value for blocking operations
443  NetInterface *interface; ///<Underlying network interface
444  Socket *socket; ///<Underlying TCP socket
445 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
446  TlsContext *tlsContext; ///<TLS context
447  TlsSessionState tlsSession; ///<TLS session state
448  WebSocketTlsInitCallback tlsInitCallback; ///<TLS initialization callback function
449  void *tlsInitParam; ///<Opaque pointer passed to the TLS initialization callback function
450 #endif
451 #if (WEB_SOCKET_BASIC_AUTH_SUPPORT == ENABLED || WEB_SOCKET_DIGEST_AUTH_SUPPORT == ENABLED)
453 #endif
458 };
459 
460 
461 //Random data generation callback function
463 
464 //WebSocket related functions
465 error_t webSocketInit(void);
466 
468 
469 WebSocket *webSocketOpen(void);
471 
472 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
473 
475 
477  WebSocketTlsInitCallback callback);
478 
479 #endif
480 
481 error_t webSocketSetTimeout(WebSocket *webSocket, systime_t timeout);
482 
483 error_t webSocketSetHost(WebSocket *webSocket, const char_t *host);
484 error_t webSocketSetOrigin(WebSocket *webSocket, const char_t *origin);
485 error_t webSocketSetSubProtocol(WebSocket *webSocket, const char_t *subProtocol);
486 
487 error_t webSocketSetAuthInfo(WebSocket *webSocket, const char_t *username,
488  const char_t *password, uint_t allowedAuthModes);
489 
491 
492 error_t webSocketConnect(WebSocket *webSocket, const IpAddr *serverIpAddr,
493  uint16_t serverPort, const char_t *uri);
494 
495 error_t webSocketSetClientKey(WebSocket *webSocket, const char_t *clientKey);
498 
500  uint_t statusCode, const char_t *message);
501 
502 error_t webSocketSend(WebSocket *webSocket, const void *data,
503  size_t length, WebSocketFrameType type, size_t *written);
504 
505 error_t webSocketSendEx(WebSocket *webSocket, const void *data, size_t length,
506  WebSocketFrameType type, size_t *written, bool_t firstFrag, bool_t lastFrag);
507 
508 error_t webSocketReceive(WebSocket *webSocket, void *data,
509  size_t size, WebSocketFrameType *type, size_t *received);
510 
511 error_t webSocketReceiveEx(WebSocket *webSocket, void *data, size_t size,
512  WebSocketFrameType *type, size_t *received, bool_t *firstFrag, bool_t *lastFrag);
513 
516 void webSocketClose(WebSocket *webSocket);
517 
518 //C++ guard
519 #ifdef __cplusplus
520 }
521 #endif
522 
523 #endif
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:65
uint8_t message[]
Definition: chap.h:154
uint8_t type
Definition: coap_common.h:176
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
int bool_t
Definition: compiler_port.h:53
General definitions for cryptographic algorithms.
uint8_t opcode
Definition: dns_common.h:188
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
uint32_t systime_t
System time.
Socket API.
#define Socket
Definition: socket.h:36
Structure describing a WebSocket.
Definition: web_socket.h:431
char_t uri[WEB_SOCKET_URI_MAX_LEN+1]
Definition: web_socket.h:440
systime_t timestamp
Definition: web_socket.h:435
WebSocketFrameContext txContext
Definition: web_socket.h:455
char_t origin[WEB_SOCKET_ORIGIN_MAX_LEN+1]
Definition: web_socket.h:438
WebSocketEndpoint endpoint
Endpoint type (client or server)
Definition: web_socket.h:432
WebSocketUtf8Context utf8Context
Definition: web_socket.h:457
WebSocketHandshakeContext handshakeContext
Definition: web_socket.h:454
TlsContext * tlsContext
TLS context.
Definition: web_socket.h:446
WebSocketTlsInitCallback tlsInitCallback
TLS initialization callback function.
Definition: web_socket.h:448
char_t queryString[WEB_SOCKET_QUERY_STRING_MAX_LEN+1]
Definition: web_socket.h:441
WebSocketAuthContext authContext
Definition: web_socket.h:452
char_t host[WEB_SOCKET_HOST_MAX_LEN+1]
Domain name of the server (for virtual hosting)
Definition: web_socket.h:437
WebSocketState state
WebSocket connection state.
Definition: web_socket.h:433
void * tlsInitParam
Opaque pointer passed to the TLS initialization callback function.
Definition: web_socket.h:449
WebSocketFrameContext rxContext
Definition: web_socket.h:456
char_t subProtocol[WEB_SOCKET_SUB_PROTOCOL_MAX_LEN+1]
Definition: web_socket.h:439
systime_t timeout
timeout value for blocking operations
Definition: web_socket.h:442
Socket * socket
Underlying TCP socket.
Definition: web_socket.h:444
TlsSessionState tlsSession
TLS session state.
Definition: web_socket.h:447
uint16_t statusCode
Definition: web_socket.h:434
NetInterface * interface
Underlying network interface.
Definition: web_socket.h:443
uint_t retryCount
Definition: web_socket.h:436
IP network address.
Definition: ip.h:79
TLS session state.
Definition: tls.h:2021
Authentication context.
Definition: web_socket.h:358
WebSocketAuthMode requiredAuthMode
Definition: web_socket.h:360
WebSocketAuthMode selectedAuthMode
Definition: web_socket.h:361
Frame encoding/decoding context.
Definition: web_socket.h:399
WebSocketFrameType controlFrameType
Control frame type.
Definition: web_socket.h:402
bool_t mask
Defines whether the payload data is masked.
Definition: web_socket.h:404
size_t bufferPos
Current position.
Definition: web_socket.h:410
size_t payloadLen
Payload length.
Definition: web_socket.h:406
size_t bufferLen
Length of the data buffer.
Definition: web_socket.h:409
WebSocketFrameType dataFrameType
FSM state.
Definition: web_socket.h:401
bool_t fin
Final fragment in a message.
Definition: web_socket.h:403
WebSocketSubState state
Definition: web_socket.h:400
size_t payloadPos
Current position.
Definition: web_socket.h:407
Handshake context.
Definition: web_socket.h:380
UTF-8 decoding context.
Definition: web_socket.h:419
uint32_t utf8CodePoint
Definition: web_socket.h:422
uint8_t length
Definition: tcp.h:368
TLS (Transport Layer Security)
#define TlsContext
Definition: tls.h:36
error_t webSocketSendEx(WebSocket *webSocket, const void *data, size_t length, WebSocketFrameType type, size_t *written, bool_t firstFrag, bool_t lastFrag)
Transmit data over the WebSocket connection.
Definition: web_socket.c:991
#define WEB_SOCKET_OPAQUE_MAX_LEN
Definition: web_socket.h:152
error_t webSocketRegisterTlsInitCallback(WebSocket *webSocket, WebSocketTlsInitCallback callback)
Register TLS initialization callback function.
Definition: web_socket.c:233
WebSocketHttpVersion
HTTP version numbers.
Definition: web_socket.h:201
@ WS_HTTP_VERSION_0_9
Definition: web_socket.h:202
@ WS_HTTP_VERSION_1_1
Definition: web_socket.h:204
@ WS_HTTP_VERSION_1_0
Definition: web_socket.h:203
error_t webSocketSendErrorResponse(WebSocket *webSocket, uint_t statusCode, const char_t *message)
Send HTTP error response to the client.
Definition: web_socket.c:895
error_t webSocketSendServerHandshake(WebSocket *webSocket)
Send server's handshake.
Definition: web_socket.c:832
WebSocketAuthMode
Authentication schemes.
Definition: web_socket.h:213
@ WS_AUTH_MODE_BASIC
Definition: web_socket.h:215
@ WS_AUTH_MODE_NONE
Definition: web_socket.h:214
@ WS_AUTH_MODE_DIGEST
Definition: web_socket.h:216
error_t webSocketConnect(WebSocket *webSocket, const IpAddr *serverIpAddr, uint16_t serverPort, const char_t *uri)
Establish a WebSocket connection.
Definition: web_socket.c:422
WebSocket * webSocketUpgradeSecureSocket(Socket *socket, TlsContext *tlsContext)
Upgrade a secure socket to a secure WebSocket.
Definition: web_socket.c:194
error_t webSocketSetClientKey(WebSocket *webSocket, const char_t *clientKey)
Set client's key.
Definition: web_socket.c:677
error_t webSocketSend(WebSocket *webSocket, const void *data, size_t length, WebSocketFrameType type, size_t *written)
Transmit data over the WebSocket connection.
Definition: web_socket.c:970
WebSocketRandCallback webSockRandCallback
Definition: web_socket.c:52
#define WEB_SOCKET_NONCE_MAX_LEN
Definition: web_socket.h:145
uint8_t fin
Definition: web_socket.h:317
#define WEB_SOCKET_PASSWORD_MAX_LEN
Definition: web_socket.h:138
#define WEB_SOCKET_BUFFER_SIZE
Definition: web_socket.h:82
#define WEB_SOCKET_SUB_PROTOCOL_MAX_LEN
Definition: web_socket.h:103
WebSocket * webSocketUpgradeSocket(Socket *socket)
Upgrade a socket to a WebSocket.
Definition: web_socket.c:155
#define WEB_SOCKET_ORIGIN_MAX_LEN
Definition: web_socket.h:96
WebSocketFrameType
WebSocket frame types.
Definition: web_socket.h:263
@ WS_FRAME_TYPE_PING
Definition: web_socket.h:268
@ WS_FRAME_TYPE_BINARY
Definition: web_socket.h:266
@ WS_FRAME_TYPE_PONG
Definition: web_socket.h:269
@ WS_FRAME_TYPE_TEXT
Definition: web_socket.h:265
@ WS_FRAME_TYPE_CONTINUATION
Definition: web_socket.h:264
@ WS_FRAME_TYPE_CLOSE
Definition: web_socket.h:267
error_t webSocketInit(void)
WebSocket related initialization.
Definition: web_socket.c:60
#define WEB_SOCKET_USERNAME_MAX_LEN
Definition: web_socket.h:131
WebSocket * webSocketOpen(void)
Create a WebSocket.
Definition: web_socket.c:95
error_t webSocketSetTimeout(WebSocket *webSocket, systime_t timeout)
Set timeout value for blocking operations.
Definition: web_socket.c:257
uint8_t extPayloadLen[]
Definition: web_socket.h:321
error_t webSocketSetSubProtocol(WebSocket *webSocket, const char_t *subProtocol)
Set the sub-protocol header field.
Definition: web_socket.c:332
error_t webSocketShutdown(WebSocket *webSocket)
Gracefully close a WebSocket connection.
Definition: web_socket.c:1470
error_t webSocketSetAuthInfo(WebSocket *webSocket, const char_t *username, const char_t *password, uint_t allowedAuthModes)
Set authentication information.
Definition: web_socket.c:359
WebSocketState
WebSocket states.
Definition: web_socket.h:225
@ WS_STATE_CLOSING_RX
Definition: web_socket.h:235
@ WS_STATE_CLOSED
Definition: web_socket.h:227
@ WS_STATE_SERVER_RESP_BODY
Definition: web_socket.h:232
@ WS_STATE_CLOSING_TX
Definition: web_socket.h:234
@ WS_STATE_UNUSED
Definition: web_socket.h:226
@ WS_STATE_CONNECTING
Definition: web_socket.h:229
@ WS_STATE_INIT
Definition: web_socket.h:228
@ WS_STATE_CLIENT_HANDSHAKE
Definition: web_socket.h:230
@ WS_STATE_OPEN
Definition: web_socket.h:233
@ WS_STATE_SHUTDOWN
Definition: web_socket.h:236
@ WS_STATE_SERVER_HANDSHAKE
Definition: web_socket.h:231
error_t webSocketParseClientHandshake(WebSocket *webSocket)
Parse client's handshake.
Definition: web_socket.c:743
uint8_t mask
Definition: web_socket.h:319
error_t webSocketReceiveEx(WebSocket *webSocket, void *data, size_t size, WebSocketFrameType *type, size_t *received, bool_t *firstFrag, bool_t *lastFrag)
Receive data from a WebSocket connection.
Definition: web_socket.c:1178
#define WEB_SOCKET_CNONCE_SIZE
Definition: web_socket.h:159
void webSocketClose(WebSocket *webSocket)
Close a WebSocket connection.
Definition: web_socket.c:1590
#define WEB_SOCKET_QUERY_STRING_MAX_LEN
Definition: web_socket.h:117
error_t webSocketReceive(WebSocket *webSocket, void *data, size_t size, WebSocketFrameType *type, size_t *received)
Receive data from a WebSocket connection.
Definition: web_socket.c:1155
#define WebSocket
Definition: web_socket.h:177
#define WEB_SOCKET_HOST_MAX_LEN
Definition: web_socket.h:89
#define WEB_SOCKET_SERVER_KEY_SIZE
Definition: web_socket.h:173
error_t webSocketRegisterRandCallback(WebSocketRandCallback callback)
Register RNG callback function.
Definition: web_socket.c:76
error_t(* WebSocketTlsInitCallback)(WebSocket *webSocket, TlsContext *tlsContext)
TLS initialization callback function.
Definition: web_socket.h:347
error_t webSocketSetHost(WebSocket *webSocket, const char_t *host)
Set the domain name of the server (for virtual hosting)
Definition: web_socket.c:282
bool_t webSocketIsRxReady(WebSocket *webSocket)
Check whether some data is available in the receive buffer.
Definition: web_socket.c:1445
typedef __packed_struct
WebSocket frame.
Definition: web_socket.h:307
uint8_t reserved
Definition: web_socket.h:316
WebSocketStatusCode
WebSocket status codes.
Definition: web_socket.h:278
@ WS_STATUS_CODE_POLICY_VIOLATION
Definition: web_socket.h:286
@ WS_STATUS_CODE_INTERNAL_ERROR
Definition: web_socket.h:289
@ WS_STATUS_CODE_PROTOCOL_ERROR
Definition: web_socket.h:281
@ WS_STATUS_CODE_NO_STATUS_RCVD
Definition: web_socket.h:283
@ WS_STATUS_CODE_GOING_AWAY
Definition: web_socket.h:280
@ WS_STATUS_CODE_INVALID_PAYLOAD_DATA
Definition: web_socket.h:285
@ WS_STATUS_CODE_TLS_HANDSHAKE
Definition: web_socket.h:290
@ WS_STATUS_CODE_MANDATORY_EXT
Definition: web_socket.h:288
@ WS_STATUS_CODE_UNSUPPORTED_DATA
Definition: web_socket.h:282
@ WS_STATUS_CODE_MESSAGE_TOO_BIG
Definition: web_socket.h:287
@ WS_STATUS_CODE_NORMAL_CLOSURE
Definition: web_socket.h:279
@ WS_STATUS_CODE_ABNORMAL_CLOSURE
Definition: web_socket.h:284
#define WEB_SOCKET_URI_MAX_LEN
Definition: web_socket.h:110
WebSocketSubState
WebSocket sub-states.
Definition: web_socket.h:245
@ WS_SUB_STATE_FRAME_EXT_HEADER
Definition: web_socket.h:253
@ WS_SUB_STATE_FRAME_PAYLOAD
Definition: web_socket.h:254
@ WS_SUB_STATE_HANDSHAKE_LWSP
Definition: web_socket.h:250
@ WS_SUB_STATE_HANDSHAKE_LEADING_LINE
Definition: web_socket.h:248
@ WS_SUB_STATE_INIT
Definition: web_socket.h:246
@ WS_SUB_STATE_FRAME_HEADER
Definition: web_socket.h:252
@ WS_SUB_STATE_HANDSHAKE_HEADER_FIELD
Definition: web_socket.h:249
error_t(* WebSocketRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
Definition: web_socket.h:337
uint8_t payloadLen
Definition: web_socket.h:318
#define WEB_SOCKET_REALM_MAX_LEN
Definition: web_socket.h:124
WebSocketEndpoint
WebSocket endpoint types.
Definition: web_socket.h:190
@ WS_ENDPOINT_SERVER
Definition: web_socket.h:192
@ WS_ENDPOINT_CLIENT
Definition: web_socket.h:191
#define WEB_SOCKET_CLIENT_KEY_SIZE
Definition: web_socket.h:171
error_t webSocketSetOrigin(WebSocket *webSocket, const char_t *origin)
Set the origin header field.
Definition: web_socket.c:307
WebSocketFrame
Definition: web_socket.h:322
error_t webSocketBindToInterface(WebSocket *webSocket, NetInterface *interface)
Bind the WebSocket to a particular network interface.
Definition: web_socket.c:398