libcoap 4.3.5-develop-19cef11
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-2024 Olaf Bergmann <bergmann@tzi.org>
5 * Copyright (C) 2023-2024 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
31/* Frame size: Min Header + (Opt) Ext payload length + (Opt) Masking key */
32#define COAP_MAX_FS (2 + 8 + 4)
33
37typedef struct coap_ws_state_t {
39 uint8_t up;
40 uint8_t seen_first;
41 uint8_t seen_host;
42 uint8_t seen_upg;
43 uint8_t seen_conn;
44 uint8_t seen_key;
45 uint8_t seen_proto;
46 uint8_t seen_ver;
47 uint8_t sent_close;
48 uint8_t recv_close;
49 uint16_t close_reason;
51 int hdr_ofs;
53 uint8_t mask_key[4];
54 uint32_t http_ofs;
55 uint8_t http_hdr[160];
56 size_t data_ofs;
57 size_t data_size;
58 uint8_t key[16];
60
61/*
62 * WebSockets Frame
63 *
64 * 0 1 2 3
65 * 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
66 * +-+-+-+-+-------+-+-------------+-------------------------------+
67 * |F|R|R|R| opcode|M| Payload len | Extended payload length |
68 * |I|S|S|S| (4) |A| (7) | (16/64) |
69 * |N|V|V|V| |S| | (if payload len==126/127) |
70 * | |1|2|3| |K| | |
71 * +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
72 * | Extended payload length continued, if payload len == 127 |
73 * + - - - - - - - - - - - - - - - +-------------------------------+
74 * | |Masking-key, if MASK set to 1 |
75 * +-------------------------------+-------------------------------+
76 * | Masking-key (continued) | Payload Data |
77 * +-------------------------------- - - - - - - - - - - - - - - - +
78 * : Payload Data continued ... :
79 * + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
80 * | Payload Data continued ... |
81 * +---------------------------------------------------------------+
82 */
83
84#define WS_B0_FIN_BIT 0x80
85#define WS_B0_RSV_MASK 0x70
86#define WS_B0_OP_MASK 0x0f
87
88#define WS_B1_MASK_BIT 0x80
89#define WS_B1_LEN_MASK 0x7f
90
91typedef enum {
99
114 const uint8_t *data, size_t datalen);
115
129ssize_t coap_ws_read(coap_session_t *session, uint8_t *data,
130 size_t datalen);
131
145
152
155#endif /* COAP_WS_INTERNAL_H */
Pulls together all the internal only header files.
coap_session_type_t
coap_session_type_t values
Definition: coap_session.h:44
struct coap_ws_state_t coap_ws_state_t
WebSockets session state.
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.