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-2023 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.2.4
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 //CodeWarrior or Win32 compiler?
295 #if defined(__CWCC__) || defined(_WIN32)
296  #pragma pack(push, 1)
297 #endif
298 
299 
300 /**
301  * @brief WebSocket frame
302  **/
303 
304 typedef __start_packed struct
305 {
306 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
307  uint8_t fin : 1; //0
308  uint8_t reserved : 3;
309  uint8_t opcode : 4;
310  uint8_t mask : 1; //1
311  uint8_t payloadLen : 7;
312 #else
313  uint8_t opcode : 4; //0
314  uint8_t reserved : 3;
315  uint8_t fin : 1;
316  uint8_t payloadLen : 7; //1
317  uint8_t mask : 1;
318 #endif
319  uint8_t extPayloadLen[]; //2
321 
322 
323 //CodeWarrior or Win32 compiler?
324 #if defined(__CWCC__) || defined(_WIN32)
325  #pragma pack(pop)
326 #endif
327 
328 
329 /**
330  * @brief Random data generation callback function
331  **/
332 
333 typedef error_t (*WebSocketRandCallback)(uint8_t *data, size_t length);
334 
335 
336 //TLS supported?
337 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
338 
339 /**
340  * @brief TLS initialization callback function
341  **/
342 
345 
346 #endif
347 
348 
349 /**
350  * @brief Authentication context
351  **/
352 
353 typedef struct
354 {
361 #if (WEB_SOCKET_DIGEST_AUTH_SUPPORT == ENABLED)
362  uint32_t nc;
367 #endif
369 
370 
371 /**
372  * @brief Handshake context
373  **/
374 
375 typedef struct
376 {
388 
389 
390 /**
391  * @brief Frame encoding/decoding context
392  **/
393 
394 typedef struct
395 {
396  WebSocketSubState state; ///FSM state
397  WebSocketFrameType dataFrameType; ///<Data frame type
398  WebSocketFrameType controlFrameType; ///<Control frame type
399  bool_t fin; ///<Final fragment in a message
400  bool_t mask; ///<Defines whether the payload data is masked
401  uint8_t maskingKey[4]; ///<Masking key
402  size_t payloadLen; ///<Payload length
403  size_t payloadPos; ///<Current position
404  uint8_t buffer[WEB_SOCKET_BUFFER_SIZE]; ///<Data buffer
405  size_t bufferLen; ///<Length of the data buffer
406  size_t bufferPos; ///<Current position
408 
409 
410 /**
411  * @brief UTF-8 decoding context
412  **/
413 
414 typedef struct
415 {
418  uint32_t utf8CodePoint;
420 
421 
422 /**
423  * @brief Structure describing a WebSocket
424  **/
425 
427 {
428  WebSocketEndpoint endpoint; ///<Endpoint type (client or server)
429  WebSocketState state; ///<WebSocket connection state
430  uint16_t statusCode;
433  char_t host[WEB_SOCKET_HOST_MAX_LEN + 1]; ///<Domain name of the server (for virtual hosting)
438  systime_t timeout; ///<timeout value for blocking operations
439  NetInterface *interface; ///<Underlying network interface
440  Socket *socket; ///<Underlying TCP socket
441 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
442  TlsContext *tlsContext; ///<TLS context
443  TlsSessionState tlsSession; ///<TLS session state
444  WebSocketTlsInitCallback tlsInitCallback; ///<TLS initialization callback function
445  void *tlsInitParam; ///<Opaque pointer passed to the TLS initialization callback function
446 #endif
447 #if (WEB_SOCKET_BASIC_AUTH_SUPPORT == ENABLED || WEB_SOCKET_DIGEST_AUTH_SUPPORT == ENABLED)
449 #endif
454 };
455 
456 
457 //Random data generation callback function
459 
460 //WebSocket related functions
461 error_t webSocketInit(void);
462 
464 
465 WebSocket *webSocketOpen(void);
467 
468 #if (WEB_SOCKET_TLS_SUPPORT == ENABLED)
469 
471 
473  WebSocketTlsInitCallback callback);
474 
475 #endif
476 
477 error_t webSocketSetTimeout(WebSocket *webSocket, systime_t timeout);
478 
479 error_t webSocketSetHost(WebSocket *webSocket, const char_t *host);
480 error_t webSocketSetOrigin(WebSocket *webSocket, const char_t *origin);
481 error_t webSocketSetSubProtocol(WebSocket *webSocket, const char_t *subProtocol);
482 
483 error_t webSocketSetAuthInfo(WebSocket *webSocket, const char_t *username,
484  const char_t *password, uint_t allowedAuthModes);
485 
487 
488 error_t webSocketConnect(WebSocket *webSocket, const IpAddr *serverIpAddr,
489  uint16_t serverPort, const char_t *uri);
490 
491 error_t webSocketSetClientKey(WebSocket *webSocket, const char_t *clientKey);
494 
496  uint_t statusCode, const char_t *message);
497 
498 error_t webSocketSend(WebSocket *webSocket, const void *data,
499  size_t length, WebSocketFrameType type, size_t *written);
500 
501 error_t webSocketSendEx(WebSocket *webSocket, const void *data, size_t length,
502  WebSocketFrameType type, size_t *written, bool_t firstFrag, bool_t lastFrag);
503 
504 error_t webSocketReceive(WebSocket *webSocket, void *data,
505  size_t size, WebSocketFrameType *type, size_t *received);
506 
507 error_t webSocketReceiveEx(WebSocket *webSocket, void *data, size_t size,
508  WebSocketFrameType *type, size_t *received, bool_t *firstFrag, bool_t *lastFrag);
509 
512 void webSocketClose(WebSocket *webSocket);
513 
514 //C++ guard
515 #ifdef __cplusplus
516 }
517 #endif
518 
519 #endif
uint8_t payloadLen
Definition: web_socket.h:316
@ WS_STATE_CLOSED
Definition: web_socket.h:227
#define WEB_SOCKET_BUFFER_SIZE
Definition: web_socket.h:82
uint8_t length
Definition: coap_common.h:193
@ WS_STATUS_CODE_GOING_AWAY
Definition: web_socket.h:280
@ WS_STATUS_CODE_UNSUPPORTED_DATA
Definition: web_socket.h:282
error_t webSocketSetAuthInfo(WebSocket *webSocket, const char_t *username, const char_t *password, uint_t allowedAuthModes)
Set authentication information.
Definition: web_socket.c:347
@ WS_STATUS_CODE_TLS_HANDSHAKE
Definition: web_socket.h:290
NetInterface * interface
Underlying network interface.
Definition: web_socket.h:439
void * tlsInitParam
Opaque pointer passed to the TLS initialization callback function.
Definition: web_socket.h:445
WebSocket * webSocketUpgradeSocket(Socket *socket)
Upgrade a socket to a WebSocket.
Definition: web_socket.c:155
WebSocketUtf8Context utf8Context
Definition: web_socket.h:453
int bool_t
Definition: compiler_port.h:53
@ WS_AUTH_MODE_NONE
Definition: web_socket.h:214
bool_t mask
Defines whether the payload data is masked.
Definition: web_socket.h:400
uint8_t data[]
Definition: ethernet.h:220
#define WEB_SOCKET_CLIENT_KEY_SIZE
Definition: web_socket.h:171
@ WS_SUB_STATE_FRAME_PAYLOAD
Definition: web_socket.h:254
IP network address.
Definition: ip.h:79
error_t webSocketSetSubProtocol(WebSocket *webSocket, const char_t *subProtocol)
Set the sub-protocol header field.
Definition: web_socket.c:324
WebSocket * webSocketUpgradeSecureSocket(Socket *socket, TlsContext *tlsContext)
Upgrade a secure socket to a secure WebSocket.
Definition: web_socket.c:194
@ WS_HTTP_VERSION_1_0
Definition: web_socket.h:203
#define WEB_SOCKET_HOST_MAX_LEN
Definition: web_socket.h:89
__start_packed struct @0 WebSocketFrame
WebSocket frame.
WebSocketHttpVersion
HTTP version numbers.
Definition: web_socket.h:201
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:1160
error_t webSocketSendServerHandshake(WebSocket *webSocket)
Send server's handshake.
Definition: web_socket.c:814
@ WS_STATUS_CODE_NO_STATUS_RCVD
Definition: web_socket.h:283
WebSocketTlsInitCallback tlsInitCallback
TLS initialization callback function.
Definition: web_socket.h:444
error_t(* WebSocketRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
Definition: web_socket.h:333
#define WEB_SOCKET_SUB_PROTOCOL_MAX_LEN
Definition: web_socket.h:103
#define WEB_SOCKET_ORIGIN_MAX_LEN
Definition: web_socket.h:96
@ WS_STATE_CLOSING_TX
Definition: web_socket.h:234
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:973
error_t webSocketShutdown(WebSocket *webSocket)
Gracefully close a WebSocket connection.
Definition: web_socket.c:1440
#define WEB_SOCKET_CNONCE_SIZE
Definition: web_socket.h:159
char_t host[WEB_SOCKET_HOST_MAX_LEN+1]
Domain name of the server (for virtual hosting)
Definition: web_socket.h:433
WebSocketEndpoint endpoint
Endpoint type (client or server)
Definition: web_socket.h:428
error_t webSocketSetHost(WebSocket *webSocket, const char_t *host)
Set the domain name of the server (for virtual hosting)
Definition: web_socket.c:282
@ WS_STATE_INIT
Definition: web_socket.h:228
WebSocketEndpoint
WebSocket endpoint types.
Definition: web_socket.h:190
uint16_t statusCode
Definition: web_socket.h:430
@ WS_HTTP_VERSION_0_9
Definition: web_socket.h:202
error_t webSocketRegisterTlsInitCallback(WebSocket *webSocket, WebSocketTlsInitCallback callback)
Register TLS initialization callback function.
Definition: web_socket.c:233
error_t webSocketParseClientHandshake(WebSocket *webSocket)
Parse client's handshake.
Definition: web_socket.c:725
WebSocketFrameType controlFrameType
Control frame type.
Definition: web_socket.h:398
WebSocketFrameContext txContext
Definition: web_socket.h:451
@ WS_AUTH_MODE_BASIC
Definition: web_socket.h:215
uint8_t reserved
Definition: web_socket.h:314
bool_t webSocketIsRxReady(WebSocket *webSocket)
Check whether some data is available in the receive buffer.
Definition: web_socket.c:1415
@ WS_SUB_STATE_HANDSHAKE_HEADER_FIELD
Definition: web_socket.h:249
WebSocketAuthMode selectedAuthMode
Definition: web_socket.h:357
@ WS_SUB_STATE_FRAME_HEADER
Definition: web_socket.h:252
#define WEB_SOCKET_NONCE_MAX_LEN
Definition: web_socket.h:145
char_t type
TlsContext * tlsContext
TLS context.
Definition: web_socket.h:442
size_t bufferLen
Length of the data buffer.
Definition: web_socket.h:405
#define TlsContext
Definition: tls.h:36
size_t payloadPos
Current position.
Definition: web_socket.h:403
error_t
Error codes.
Definition: error.h:43
Frame encoding/decoding context.
Definition: web_socket.h:395
error_t(* WebSocketTlsInitCallback)(WebSocket *webSocket, TlsContext *tlsContext)
TLS initialization callback function.
Definition: web_socket.h:343
uint8_t opcode
Definition: web_socket.h:313
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:63
uint16_t statusCode
WebSocketFrameType
WebSocket frame types.
Definition: web_socket.h:263
uint32_t utf8CodePoint
Definition: web_socket.h:418
WebSocketState state
WebSocket connection state.
Definition: web_socket.h:429
@ WS_STATE_UNUSED
Definition: web_socket.h:226
@ WS_FRAME_TYPE_PING
Definition: web_socket.h:268
#define NetInterface
Definition: net.h:36
@ WS_AUTH_MODE_DIGEST
Definition: web_socket.h:216
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:1137
char_t subProtocol[WEB_SOCKET_SUB_PROTOCOL_MAX_LEN+1]
Definition: web_socket.h:435
Handshake context.
Definition: web_socket.h:376
systime_t timeout
timeout value for blocking operations
Definition: web_socket.h:438
@ WS_FRAME_TYPE_TEXT
Definition: web_socket.h:265
@ WS_ENDPOINT_SERVER
Definition: web_socket.h:192
UTF-8 decoding context.
Definition: web_socket.h:415
Socket * socket
Underlying TCP socket.
Definition: web_socket.h:440
General definitions for cryptographic algorithms.
WebSocketFrameType dataFrameType
FSM state.
Definition: web_socket.h:397
__start_packed struct _Ipv4Header __end_packed
error_t webSocketConnect(WebSocket *webSocket, const IpAddr *serverIpAddr, uint16_t serverPort, const char_t *uri)
Establish a WebSocket connection.
Definition: web_socket.c:404
size_t payloadLen
Payload length.
Definition: web_socket.h:402
uint8_t mask
Definition: web_socket.h:317
@ WS_STATUS_CODE_MESSAGE_TOO_BIG
Definition: web_socket.h:287
@ WS_STATUS_CODE_ABNORMAL_CLOSURE
Definition: web_socket.h:284
WebSocketAuthMode requiredAuthMode
Definition: web_socket.h:356
@ WS_FRAME_TYPE_PONG
Definition: web_socket.h:269
@ WS_STATUS_CODE_INTERNAL_ERROR
Definition: web_socket.h:289
WebSocketState
WebSocket states.
Definition: web_socket.h:225
@ WS_ENDPOINT_CLIENT
Definition: web_socket.h:191
#define WebSocket
Definition: web_socket.h:177
@ WS_SUB_STATE_HANDSHAKE_LEADING_LINE
Definition: web_socket.h:248
Authentication context.
Definition: web_socket.h:354
error_t webSocketBindToInterface(WebSocket *webSocket, NetInterface *interface)
Bind the WebSocket to a particular network interface.
Definition: web_socket.c:380
TlsSessionState tlsSession
TLS session state.
Definition: web_socket.h:443
char_t queryString[WEB_SOCKET_QUERY_STRING_MAX_LEN+1]
Definition: web_socket.h:437
@ WS_FRAME_TYPE_CLOSE
Definition: web_socket.h:267
@ WS_STATUS_CODE_POLICY_VIOLATION
Definition: web_socket.h:286
char_t uri[WEB_SOCKET_URI_MAX_LEN+1]
Definition: web_socket.h:436
WebSocket * webSocketOpen(void)
Create a WebSocket.
Definition: web_socket.c:95
WebSocketSubState state
Definition: web_socket.h:396
uint32_t systime_t
System time.
error_t webSocketSetClientKey(WebSocket *webSocket, const char_t *clientKey)
Set client's key.
Definition: web_socket.c:659
systime_t timestamp
Definition: web_socket.h:431
@ WS_SUB_STATE_INIT
Definition: web_socket.h:246
error_t webSocketSendErrorResponse(WebSocket *webSocket, uint_t statusCode, const char_t *message)
Send HTTP error response to the client.
Definition: web_socket.c:877
Structure describing a WebSocket.
Definition: web_socket.h:427
char char_t
Definition: compiler_port.h:48
WebSocketStatusCode
WebSocket status codes.
Definition: web_socket.h:278
#define WEB_SOCKET_PASSWORD_MAX_LEN
Definition: web_socket.h:138
#define WEB_SOCKET_OPAQUE_MAX_LEN
Definition: web_socket.h:152
@ WS_STATE_CONNECTING
Definition: web_socket.h:229
TLS session state.
Definition: tls.h:1965
@ WS_STATUS_CODE_INVALID_PAYLOAD_DATA
Definition: web_socket.h:285
error_t webSocketInit(void)
WebSocket related initialization.
Definition: web_socket.c:60
WebSocketAuthMode
Authentication schemes.
Definition: web_socket.h:213
uint8_t extPayloadLen[]
Definition: web_socket.h:319
@ WS_FRAME_TYPE_CONTINUATION
Definition: web_socket.h:264
#define Socket
Definition: socket.h:36
@ WS_STATE_SERVER_RESP_BODY
Definition: web_socket.h:232
bool_t fin
Final fragment in a message.
Definition: web_socket.h:399
@ WS_STATE_SHUTDOWN
Definition: web_socket.h:236
uint8_t message[]
Definition: chap.h:152
WebSocketAuthContext authContext
Definition: web_socket.h:448
@ WS_STATE_CLIENT_HANDSHAKE
Definition: web_socket.h:230
TLS (Transport Layer Security)
@ WS_SUB_STATE_FRAME_EXT_HEADER
Definition: web_socket.h:253
Socket API.
@ WS_STATUS_CODE_MANDATORY_EXT
Definition: web_socket.h:288
@ WS_SUB_STATE_HANDSHAKE_LWSP
Definition: web_socket.h:250
#define WEB_SOCKET_QUERY_STRING_MAX_LEN
Definition: web_socket.h:117
@ WS_STATE_SERVER_HANDSHAKE
Definition: web_socket.h:231
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:952
#define WEB_SOCKET_SERVER_KEY_SIZE
Definition: web_socket.h:173
@ WS_STATUS_CODE_PROTOCOL_ERROR
Definition: web_socket.h:281
size_t bufferPos
Current position.
Definition: web_socket.h:406
uint8_t fin
Definition: web_socket.h:315
error_t webSocketSetOrigin(WebSocket *webSocket, const char_t *origin)
Set the origin header field.
Definition: web_socket.c:303
@ WS_STATE_CLOSING_RX
Definition: web_socket.h:235
char_t origin[WEB_SOCKET_ORIGIN_MAX_LEN+1]
Definition: web_socket.h:434
uint_t retryCount
Definition: web_socket.h:432
unsigned int uint_t
Definition: compiler_port.h:50
WebSocketSubState
WebSocket sub-states.
Definition: web_socket.h:245
WebSocketRandCallback webSockRandCallback
Definition: web_socket.c:52
TCP/IP stack core.
@ WS_HTTP_VERSION_1_1
Definition: web_socket.h:204
#define WEB_SOCKET_URI_MAX_LEN
Definition: web_socket.h:110
WebSocketFrameContext rxContext
Definition: web_socket.h:452
@ WS_STATUS_CODE_NORMAL_CLOSURE
Definition: web_socket.h:279
#define WEB_SOCKET_REALM_MAX_LEN
Definition: web_socket.h:124
WebSocketHandshakeContext handshakeContext
Definition: web_socket.h:450
#define WEB_SOCKET_USERNAME_MAX_LEN
Definition: web_socket.h:131
error_t webSocketRegisterRandCallback(WebSocketRandCallback callback)
Register RNG callback function.
Definition: web_socket.c:76
@ WS_FRAME_TYPE_BINARY
Definition: web_socket.h:266
void webSocketClose(WebSocket *webSocket)
Close a WebSocket connection.
Definition: web_socket.c:1556
@ WS_STATE_OPEN
Definition: web_socket.h:233
error_t webSocketSetTimeout(WebSocket *webSocket, systime_t timeout)
Set timeout value for blocking operations.
Definition: web_socket.c:257