Files
story/docs/device-protocol-c/vl_protocol.h
T
Codex Local bf1233d5df
ci / verify (push) Canceled after 0s
feat: expand companion platform, device controls, and memoir workflows
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
2026-10-08 10:06:44 +08:00

34 lines
1.9 KiB
C

#ifndef VL_PROTOCOL_H
#define VL_PROTOCOL_H
#include <stddef.h>
#include <stdint.h>
#include "mbedtls/md.h"
/* All functions return 0 on success, nonzero on failure. Not board firmware.
* String outputs include NUL, binary outputs do not. Never transmit the NUL.
* Caller owns buffers; inputs/outputs must not overlap. */
int vl_key_from_hex(const char *hex, uint8_t key[32]);
/* rng must fill ALL n bytes from the hardware/OS secure RNG; return 0 or fail. */
typedef int (*vl_rng_fn)(void *context, uint8_t *bytes, size_t n);
int vl_nonce(vl_rng_fn rng, void *context, char out[23]);
int vl_uuid4(vl_rng_fn rng, void *context, char out[37]);
int vl_sha256_hex(const void *bytes, size_t length, char out[65]);
int vl_http_sign(const uint8_t key[32], const char *method, const char *path,
const char *device_id, const char *key_version,
const char *timestamp_ms, const char *nonce,
const char *request_id, const void *body, size_t body_length,
char signature_hex[65]);
int vl_ble_pack(const void *json_utf8, size_t length,
uint8_t *frame, size_t capacity, size_t *frame_length);
/* Stream OTA bytes with bounded memory. Always call mbedtls_md_free after
* begin, even if an update/finish fails. Do not begin twice on a live context. */
int vl_sha256_begin(mbedtls_md_context_t *context);
int vl_sha256_update(mbedtls_md_context_t *context, const void *bytes, size_t n);
int vl_sha256_finish(mbedtls_md_context_t *context, char out[65]);
/* Read already downloaded bytes (e.g. flash/file): 0=success, *n=0 means EOF.
* On each call write at most capacity bytes; return nonzero on I/O failure. */
typedef int (*vl_read_fn)(void *context, uint8_t *out, size_t capacity, size_t *n);
int vl_ota_verify(vl_read_fn read, void *context, uint64_t expected_size,
const char *expected_sha256);
#endif