ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
wave.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file wave.h
6 * @brief IEEE 1609 WAVE (WSMP + 1609.2 security envelope) codec (PROTOCORE_ENABLE_WAVE).
7 *
8 * IEEE 1609 (WAVE - Wireless Access in Vehicular Environments) is the radio stack that carries the
9 * J2735 V2X messages (services/transportation/j2735). This codec provides the two framing layers below J2735:
10 *
11 * - **1609.3 WSMP** (WAVE Short Message Protocol): a compact header - version/subtype, a
12 * transmit-power/channel WAVE-element block, a PSID (Provider Service Identifier, a variable-length
13 * p-encoded integer identifying the application, e.g. BSM/SPaT), and a length - then the payload.
14 * - **1609.2** secured-message envelope: `protocolVersion(3) + contentType` header that wraps a signed
15 * or unsecured-data payload (the full signature/cert machinery is the crypto layer on top).
16 *
17 * This builds/parses the WSMP header + PSID p-encoding and the 1609.2 envelope header. Pure, zero heap,
18 * no stdlib, host-testable; the DSRC / C-V2X radio is an external module.
19 */
20
21#ifndef PROTOCORE_WAVE_H
22#define PROTOCORE_WAVE_H
23
24#include "protocore_config.h" // the entry point: protocore_types.h for the widths
25
26#if PROTOCORE_ENABLE_WAVE
27
29
30// WSMP / 1609.2 versions + content types + PSIDs: wire values, so integer constants in a struct.
31#define WSMP_VERSION 0x03 ///< WSMP version (in the low nibble of byte 0).
32#define WAVE_16092_VERSION 0x03 ///< 1609.2 protocolVersion.
33#define WAVE_16092_UNSECURED 0x00 ///< content type: unsecuredData.
34#define WAVE_16092_SIGNED 0x01 ///< content type: signedData.
35// Common PSIDs (Provider Service Identifiers).
36#define WAVE_PSID_BSM 0x20 ///< vehicle safety (BSM), PSID 0x20.
37#define WAVE_PSID_SPAT 0x8002 ///< signal phase and timing.
38#define WAVE_PSID_MAP 0x8003 ///< map data.
39
40/**
41 * @brief Encode a PSID as a P-encoded (variable-length) integer.
42 *
43 * The PSID length is signalled by the top bits of the first octet: 1 octet if < 0x80, 2 if < 0x4000,
44 * 3 if < 0x200000, 4 up to 0x0FFFFFFF. The 4-octet form's tag takes the top four bits, so a PSID
45 * above that has no encoding. @return octets written (1..4), or 0 if it will not fit.
46 */
47size_t protocore_wave_encode_psid(uint32_t psid, uint8_t *out, size_t cap);
48
49/** @brief Decode a P-encoded PSID. @return octets consumed (1..4), or 0 if malformed; sets @p psid. */
50size_t protocore_wave_decode_psid(const uint8_t *in, size_t len, uint32_t *psid);
51
52/**
53 * @brief Build a WSMP data frame: WSMP header (version + PSID + a 1-byte length) then the payload.
54 * @param psid the Provider Service Identifier.
55 * @param payload the WSM payload (e.g. a 1609.2-wrapped J2735 message).
56 * @param payload_len 0..255.
57 * @return the frame length, or 0 on overflow / bad args.
58 */
59size_t protocore_wsmp_build(uint32_t psid, const uint8_t *payload, size_t payload_len, uint8_t *out, size_t cap);
60
61/** @brief A parsed WSMP frame (payload points into the input). */
62typedef struct
63{
64 uint32_t psid;
65 const uint8_t *payload;
66 size_t payload_len;
67} WsmpFrame;
68
69/** @brief Parse a WSMP data frame. @return true if well-formed. */
70proto_bool protocore_wsmp_parse(const uint8_t *frame, size_t len, WsmpFrame *out);
71
72/**
73 * @brief Build a 1609.2 secured-message envelope header + payload: [version][contentType][payload...].
74 * @param content_type WAVE_16092_UNSECURED / WAVE_16092_SIGNED.
75 * @return the length written (2 + payload_len), or 0 on overflow.
76 */
77size_t protocore_wave_1609dot2_wrap(uint8_t content_type, const uint8_t *payload, size_t payload_len, uint8_t *out,
78 size_t cap);
79
81
82#endif // PROTOCORE_ENABLE_WAVE
83
84#endif // PROTOCORE_WAVE_H
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97