Select Git revision
Forked from
Nettle / nettle
Source project has a limited visibility.
api.h 1.72 KiB
#ifndef API_H
#define API_H
#include <sys/types.h>
#include <msgpack.hpp>
#include <cstdint>
#include <string>
#define MSG_HDR(name, def_op) \
struct name : public rpc_msg {\
name() : rpc_msg{def_op} {}
#define SERIALISE(...) \
MSGPACK_DEFINE(op, __VA_ARGS__)
namespace blue
{
// API result codes
constexpr uint32_t OP_SUCCESS = 0x0000;
constexpr uint32_t OP_FAIL = 0x0001;
constexpr uint32_t OP_BUSY = 0x0002;
constexpr size_t MAX_RPC_MSG_SIZE = 4096;
// Header for all messages to easily extract the op field.
struct rpc_msg
{
uint32_t op;
MSGPACK_DEFINE(op);
};
// Scanning
constexpr uint32_t OP_SCAN_START = 0x0001;
MSG_HDR(msg_scan_reply, OP_SCAN_START)
uint32_t result;
SERIALISE(result);
};
constexpr uint32_t OP_SCAN_ITEM = 0x0002;
MSG_HDR(msg_scan_item, OP_SCAN_ITEM)
std::string name;
SERIALISE(name);
};
constexpr uint32_t OP_SCAN_DONE = 0x0003;
// Pairing
constexpr uint32_t OP_PAIR_REQUEST = 0x0004;
MSG_HDR(msg_pair_request, OP_PAIR_REQUEST)
std::string name;
SERIALISE(name);
};
constexpr uint32_t OP_PAIR_START = 0x0005;
constexpr uint32_t OP_PAIR_UNKNOWN = 0x0006;
constexpr uint32_t OP_PAIR_ERROR = 0x0007;
// Listing paired devices
constexpr uint32_t OP_LIST_PAIRS_REQUEST = 0x0008;
constexpr uint32_t OP_LIST_PAIRS_ITEM = 0x0009;
MSG_HDR(msg_pair_item, OP_LIST_PAIRS_ITEM)
std::string name;
SERIALISE(name);
};
constexpr uint32_t OP_LIST_PAIRS_DONE = 0x000A;
constexpr uint32_t OP_LIST_PAIRS_ERROR = 0x000B;
// Set device PIN
constexpr uint32_t OP_SET_DEVICE_PIN = 0x000C;
MSG_HDR(msg_set_pin_request, OP_SET_DEVICE_PIN)
std::string name;
std::string pin;
SERIALISE(name, pin);
};
constexpr uint32_t OP_SET_DEVICE_PIN_UNKNOWN = 0x000D;
constexpr uint32_t OP_SET_DEVICE_PIN_TOO_LONG = 0x000E;
}
#endif // API_H