protocol header
parent
9368241091
commit
3851b60310
@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#define OWD_MAGIC 0x4f574454
|
||||||
|
#define OWD_VERSION 1
|
||||||
|
|
||||||
|
#define OWD_DECL_DATA_END char _data_end[0]
|
||||||
|
#define OWD_DATA_LEN(HDR) (offsetof(__typeof__(HDR), _data_end))
|
||||||
|
|
||||||
|
enum owd_msg_type {
|
||||||
|
OWD_MSG_ERR,
|
||||||
|
OWD_MSG_SYNC_REQUEST,
|
||||||
|
OWD_MSG_SYNC_RESPONSE,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum owd_error_code {
|
||||||
|
OWD_ERR_BAD_HEADER,
|
||||||
|
OWD_ERR_BAD_TYPE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct owd_timestamp {
|
||||||
|
uint32_t ts_upper;
|
||||||
|
uint32_t ts_lower;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct owdhdr {
|
||||||
|
uint32_t magic;
|
||||||
|
uint8_t version;
|
||||||
|
uint8_t msg_type;
|
||||||
|
uint16_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct owd_msg_err {
|
||||||
|
struct owdhdr hdr;
|
||||||
|
uint8_t err;
|
||||||
|
OWD_DECL_DATA_END;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct owd_msg_sync_response {
|
||||||
|
struct owdhdr hdr;
|
||||||
|
struct owd_timestamp ts;
|
||||||
|
OWD_DECL_DATA_END;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void owd_hdr_populate(struct owdhdr *hdr, uint8_t msg_type, uint16_t length) {
|
||||||
|
hdr->magic = htonl(OWD_MAGIC);
|
||||||
|
hdr->version = OWD_VERSION;
|
||||||
|
hdr->msg_type = msg_type;
|
||||||
|
hdr->length = htons(length);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue