libcoap 4.3.5-develop-ea01661
Loading...
Searching...
No Matches
coap_ws_internal.h
Go to the documentation of this file.
1/*
2 * coap_ws_internal.h -- WebSockets Transport Layer Support for libcoap
3 *
4 * Copyright (C) 2023-2025 Olaf Bergmann <bergmann@tzi.org>
5 * Copyright (C) 2023-2025 Jon Shallow <supjps-libcoap@jpshallow.com>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 *
9 * This file is part of the CoAP library libcoap. Please see README for terms
10 * of use.
11 */
12
18#ifndef COAP_WS_INTERNAL_H_
19#define COAP_WS_INTERNAL_H_
20
21#include "coap_internal.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
35/* Frame size: Min Header + (Opt) Ext payload length + (Opt) Masking key */
36#define COAP_MAX_FS (2 + 8 + 4)
37
41typedef struct coap_ws_state_t {
43 uint8_t up;
44 uint8_t seen_first;
45 uint8_t seen_host;
46 uint8_t seen_upg;
47 uint8_t seen_conn;
48 uint8_t seen_key;
49 uint8_t seen_proto;
50 uint8_t seen_ver;
51 uint8_t sent_close;
52 uint8_t recv_close;
53 uint16_t close_reason;
55 int hdr_ofs;
57 uint8_t mask_key[4];
58 uint32_t http_ofs;
59 uint8_t http_hdr[160];
60 size_t data_ofs;
61 size_t data_size;
62 uint8_t key[16];
64
65/*
66 * WebSockets Frame
67 *
68 * 0 1 2 3
69 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
70 * +-+-+-+-+-------+-+-------------+-------------------------------+
71 * |F|R|R|R| opcode|M| Payload len | Extended payload length |
72 * |I|S|S|S| (4) |A| (7) | (16/64) |
73 * |N|V|V|V| |S| | (if payload len==126/127) |
74 * | |1|2|3| |K| | |
75 * +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
76 * | Extended payload length continued, if payload len == 127 |
77 * + - - - - - - - - - - - - - - - +-------------------------------+
78 * | |Masking-key, if MASK set to 1 |
79 * +-------------------------------+-------------------------------+
80 * | Masking-key (continued) | Payload Data |
81 * +-------------------------------- - - - - - - - - - - - - - - - +
82 * : Payload Data continued ... :
83 * + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
84 * | Payload Data continued ... |
85 * +---------------------------------------------------------------+
86 */
87
88#define WS_B0_FIN_BIT 0x80
89#define WS_B0_RSV_MASK 0x70
90#define WS_B0_OP_MASK 0x0f
91
92#define WS_B1_MASK_BIT 0x80
93#define WS_B1_LEN_MASK 0x7f
94
103
118 const uint8_t *data, size_t datalen);
119
133ssize_t coap_ws_read(coap_session_t *session, uint8_t *data,
134 size_t datalen);
135
149
156
159#ifdef __cplusplus
160}
161#endif
162
163#endif /* COAP_WS_INTERNAL_H */
Pulls together all the internal only header files.
coap_session_type_t
coap_session_type_t values
void coap_ws_establish(coap_session_t *session)
Layer function interface for layer below WebSockets accept/connect being established.
coap_ws_opcode_t
ssize_t coap_ws_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for websockets data transmission.
void coap_ws_close(coap_session_t *session)
Layer function interface for WebSockets close for a session.
#define COAP_MAX_FS
ssize_t coap_ws_read(coap_session_t *session, uint8_t *data, size_t datalen)
Function interface for websockets data receiving.
@ WS_OP_TEXT
@ WS_OP_CLOSE
@ WS_OP_PONG
@ WS_OP_PING
@ WS_OP_BINARY
@ WS_OP_CONT
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
WebSockets session state.
uint8_t up
WebSockets established.
uint8_t recv_close
Close has been received.
uint8_t key[16]
Random, but agreed key value.
uint8_t seen_host
Seen Host: HTTP header (server)
uint8_t seen_ver
Seen version: HTTP header (server)
uint8_t seen_key
Seen Key: HTTP header.
uint16_t close_reason
Reason for closing.
size_t data_ofs
Offset into user provided buffer.
uint8_t http_hdr[160]
(Partial) HTTP header
uint8_t seen_conn
Seen Connection: HTTP header.
size_t data_size
Data size as indicated by WebSocket frame.
uint8_t seen_upg
Seen Upgrade: HTTP header.
uint32_t http_ofs
Current offset into http_hdr.
int all_hdr_in
Frame header available.
int hdr_ofs
Current offset into rd_header.
uint8_t sent_close
Close has been sent.
coap_session_type_t state
Client or Server.
uint8_t rd_header[COAP_MAX_FS]
(Partial) frame
uint8_t seen_proto
Seen Protocol: HTTP header.
uint8_t mask_key[4]
Masking key.
uint8_t seen_first
Seen first request/response HTTP header.