Go to the documentation of this file.
32 #define TRACE_LEVEL WEB_SOCKET_TRACE_LEVEL
43 #if (WEB_SOCKET_SUPPORT == ENABLED)
63 txContext = &webSocket->txContext;
123 frame->payloadLen = 126;
129 txContext->
bufferLen +=
sizeof(uint16_t);
135 frame->payloadLen = 127;
141 txContext->
bufferLen +=
sizeof(uint64_t);
147 TRACE_DEBUG(
" Reserved = %u\r\n", frame->reserved);
163 txContext->
bufferLen +=
sizeof(uint32_t);
189 rxContext = &webSocket->rxContext;
200 frame->opcode != *
type)
208 if(frame->payloadLen == 126)
215 n +=
sizeof(uint16_t);
217 else if(frame->payloadLen == 127)
224 n +=
sizeof(uint64_t);
235 TRACE_DEBUG(
" Reserved = %u\r\n", frame->reserved);
249 n +=
sizeof(uint32_t);
257 webSocket->utf8Context.utf8CharSize = 0;
258 webSocket->utf8Context.utf8CharIndex = 0;
259 webSocket->utf8Context.utf8CodePoint = 0;
265 if(frame->reserved != 0)
326 *((uint8_t *) frame +
n + j) ^= rxContext->
maskingKey[k];
332 statusCode =
LOAD16BE((uint8_t *) frame +
n);
341 webSocket->statusCode = statusCode;
356 (uint8_t *) frame +
n + 2, k, k))
365 webSocket->handshakeContext.closingFrameReceived =
TRUE;
379 if(frame->payloadLen > 125)
392 if(frame->payloadLen > 125)
403 rxContext->
mask = frame->mask;
415 rxContext->
fin = frame->fin;
466 TRACE_DEBUG(
" Status Code = %u\r\n", webSocket->statusCode);
469 p = webSocket->txContext.buffer + webSocket->txContext.bufferLen;
472 p[0] =
MSB(webSocket->statusCode);
473 p[1] =
LSB(webSocket->statusCode);
479 p[0] ^= webSocket->txContext.maskingKey[0];
480 p[1] ^= webSocket->txContext.maskingKey[1];
484 webSocket->txContext.bufferLen +=
sizeof(uint16_t);
error_t webSocketFormatFrameHeader(WebSocket *webSocket, bool_t fin, WebSocketFrameType type, size_t payloadLen)
Format WebSocket frame header.
error_t webSocketFormatCloseFrame(WebSocket *webSocket)
Format a Close frame.
bool_t mask
Defines whether the payload data is masked.
uint8_t maskingKey[4]
Masking key.
@ ERROR_UNEXPECTED_MESSAGE
WebSocket API (client and server)
bool_t webSocketCheckUtf8Stream(WebSocketUtf8Context *context, const uint8_t *data, size_t length, size_t remaining)
Check whether a an UTF-8 stream is valid.
Helper functions for WebSockets.
@ WS_STATUS_CODE_NO_STATUS_RCVD
WebSocketFrameType controlFrameType
Control frame type.
WebSocket frame parsing and formatting.
#define osMemcpy(dest, src, length)
size_t bufferLen
Length of the data buffer.
Frame encoding/decoding context.
bool_t webSocketCheckStatusCode(uint16_t statusCode)
Check whether a status code is valid.
WebSocketFrameType
WebSocket frame types.
@ ERROR_FAILURE
Generic error code.
WebSocketRandCallback webSockRandCallback
WebSocketFrameType dataFrameType
FSM state.
size_t payloadLen
Payload length.
error_t webSocketParseFrameHeader(WebSocket *webSocket, const WebSocketFrame *frame, WebSocketFrameType *type)
Parse WebSocket frame header.
#define TRACE_DEBUG_ARRAY(p, a, n)
@ WS_STATUS_CODE_INVALID_PAYLOAD_DATA
uint8_t buffer[WEB_SOCKET_BUFFER_SIZE]
Data buffer.
@ WS_FRAME_TYPE_CONTINUATION
bool_t fin
Final fragment in a message.
@ WS_STATUS_CODE_PROTOCOL_ERROR
WebSocket transport layer.
size_t bufferPos
Current position.
@ WS_STATUS_CODE_NORMAL_CLOSURE