#ifndef _OSDP_H_
#define _OSDP_H_
#include <stdint.h>
#include <stdbool.h>
#include "osdp_export.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OSDP_FLAG_ENFORCE_SECURE 0x00010000
#define OSDP_FLAG_INSTALL_MODE 0x00020000
#define OSDP_FLAG_IGN_UNSOLICITED 0x00040000
#define OSDP_FLAG_ENABLE_NOTIFICATION 0x00080000
#define OSDP_FLAG_CAPTURE_PACKETS 0x00100000
#define OSDP_FLAG_ALLOW_EMPTY_ENCRYPTED_DATA_BLOCK 0x00200000
enum osdp_pd_cap_function_code_e {
OSDP_PD_CAP_UNUSED,
OSDP_PD_CAP_CONTACT_STATUS_MONITORING,
OSDP_PD_CAP_OUTPUT_CONTROL,
OSDP_PD_CAP_CARD_DATA_FORMAT,
OSDP_PD_CAP_READER_LED_CONTROL,
OSDP_PD_CAP_READER_AUDIBLE_OUTPUT,
OSDP_PD_CAP_READER_TEXT_OUTPUT,
OSDP_PD_CAP_TIME_KEEPING,
OSDP_PD_CAP_CHECK_CHARACTER_SUPPORT,
OSDP_PD_CAP_COMMUNICATION_SECURITY,
OSDP_PD_CAP_RECEIVE_BUFFERSIZE,
OSDP_PD_CAP_LARGEST_COMBINED_MESSAGE_SIZE,
OSDP_PD_CAP_SMART_CARD_SUPPORT,
OSDP_PD_CAP_READERS,
OSDP_PD_CAP_BIOMETRICS,
OSDP_PD_CAP_SECURE_PIN_ENTRY,
OSDP_PD_CAP_OSDP_VERSION,
OSDP_PD_CAP_SENTINEL
};
enum osdp_pd_nak_code_e {
OSDP_PD_NAK_NONE,
OSDP_PD_NAK_MSG_CHK,
OSDP_PD_NAK_CMD_LEN,
OSDP_PD_NAK_CMD_UNKNOWN,
OSDP_PD_NAK_SEQ_NUM,
OSDP_PD_NAK_SC_UNSUP,
OSDP_PD_NAK_SC_COND,
OSDP_PD_NAK_BIO_TYPE,
OSDP_PD_NAK_BIO_FMT,
OSDP_PD_NAK_RECORD,
OSDP_PD_NAK_SENTINEL
};
struct osdp_pd_cap {
uint8_t function_code;
uint8_t compliance_level;
uint8_t num_items;
};
struct osdp_pd_id {
int version;
int model;
uint32_t vendor_code;
uint32_t serial_number;
uint32_t firmware_version;
};
typedef int (*osdp_read_fn_t)(void *data, uint8_t *buf, int maxlen);
typedef int (*osdp_read_pkt_fn_t)(void *data, const uint8_t **buf, int *max_len);
typedef int (*osdp_write_fn_t)(void *data, uint8_t *buf, int len);
typedef void (*osdp_flush_fn_t)(void *data);
typedef void (*osdp_close_fn_t)(void *data);
typedef void (*osdp_release_pkt_fn_t)(void *data, const uint8_t *buf);
struct osdp_channel {
void *data;
int id;
osdp_read_fn_t recv;
osdp_read_pkt_fn_t recv_pkt;
osdp_write_fn_t send;
osdp_flush_fn_t flush;
osdp_release_pkt_fn_t release_pkt;
osdp_close_fn_t close;
};
typedef struct {
const char *name;
int baud_rate;
int address;
int flags;
struct osdp_pd_id id;
const struct osdp_pd_cap *cap;
struct osdp_channel channel;
const uint8_t *scbk;
} osdp_pd_info_t;
typedef void osdp_t;
enum osdp_status_report_type {
OSDP_STATUS_REPORT_INPUT,
OSDP_STATUS_REPORT_OUTPUT,
OSDP_STATUS_REPORT_LOCAL,
OSDP_STATUS_REPORT_REMOTE,
};
#define OSDP_STATUS_REPORT_MAX_LEN 64
struct osdp_status_report {
enum osdp_status_report_type type;
int nr_entries;
uint8_t report[OSDP_STATUS_REPORT_MAX_LEN];
};
#define OSDP_CMD_TEXT_MAX_LEN 32
#define OSDP_CMD_KEYSET_KEY_MAX_LEN 32
#define OSDP_CMD_MFG_MAX_DATALEN 64
struct osdp_cmd_output {
uint8_t output_no;
uint8_t control_code;
uint16_t timer_count;
};
enum osdp_led_color_e {
OSDP_LED_COLOR_NONE,
OSDP_LED_COLOR_RED,
OSDP_LED_COLOR_GREEN,
OSDP_LED_COLOR_AMBER,
OSDP_LED_COLOR_BLUE,
OSDP_LED_COLOR_MAGENTA,
OSDP_LED_COLOR_CYAN,
OSDP_LED_COLOR_WHITE,
OSDP_LED_COLOR_SENTINEL
};
struct osdp_cmd_led_params {
uint8_t control_code;
uint8_t on_count;
uint8_t off_count;
uint8_t on_color;
uint8_t off_color;
uint16_t timer_count;
};
struct osdp_cmd_led {
uint8_t reader;
uint8_t led_number;
struct osdp_cmd_led_params temporary;
struct osdp_cmd_led_params permanent;
};
struct osdp_cmd_buzzer {
uint8_t reader;
uint8_t control_code;
uint8_t on_count;
uint8_t off_count;
uint8_t rep_count;
};
struct osdp_cmd_text {
uint8_t reader;
uint8_t control_code;
uint8_t temp_time;
uint8_t offset_row;
uint8_t offset_col;
uint8_t length;
uint8_t data[OSDP_CMD_TEXT_MAX_LEN];
};
struct osdp_cmd_comset {
uint8_t address;
uint32_t baud_rate;
};
struct osdp_cmd_keyset {
uint8_t type;
uint8_t length;
uint8_t data[OSDP_CMD_KEYSET_KEY_MAX_LEN];
};
struct osdp_cmd_mfg {
uint32_t vendor_code;
uint8_t data[OSDP_CMD_MFG_MAX_DATALEN];
uint8_t length;
};
#define OSDP_CMD_FILE_TX_FLAG_CANCEL (1UL << 31)
struct osdp_cmd_file_tx {
int id;
uint32_t flags;
};
enum osdp_cmd_e {
OSDP_CMD_OUTPUT = 1,
OSDP_CMD_LED,
OSDP_CMD_BUZZER,
OSDP_CMD_TEXT,
OSDP_CMD_KEYSET,
OSDP_CMD_COMSET,
OSDP_CMD_MFG,
OSDP_CMD_FILE_TX,
OSDP_CMD_STATUS,
OSDP_CMD_COMSET_DONE,
OSDP_CMD_SENTINEL
};
#define OSDP_CMD_FLAG_BROADCAST 0x000000001
typedef struct osdp_queue_node_s osdp_queue_node_t;
struct osdp_queue_node_s {
osdp_queue_node_t *next;
osdp_queue_node_t *prev;
};
struct osdp_cmd {
osdp_queue_node_t _node;
enum osdp_cmd_e id;
uint32_t flags;
union {
struct osdp_cmd_led led;
struct osdp_cmd_buzzer buzzer;
struct osdp_cmd_text text;
struct osdp_cmd_output output;
struct osdp_cmd_comset comset;
struct osdp_cmd_keyset keyset;
struct osdp_cmd_mfg mfg;
struct osdp_cmd_file_tx file_tx;
struct osdp_status_report status;
};
};
#define OSDP_EVENT_CARDREAD_MAX_DATALEN 64
#define OSDP_EVENT_KEYPRESS_MAX_DATALEN 64
#define OSDP_EVENT_MFGREP_MAX_DATALEN 128
enum osdp_event_cardread_format_e {
OSDP_CARD_FMT_RAW_UNSPECIFIED,
OSDP_CARD_FMT_RAW_WIEGAND,
OSDP_CARD_FMT_ASCII,
OSDP_CARD_FMT_SENTINEL
};
struct osdp_event_cardread {
int reader_no;
enum osdp_event_cardread_format_e format;
int direction;
int length;
uint8_t data[OSDP_EVENT_CARDREAD_MAX_DATALEN];
};
struct osdp_event_keypress {
int reader_no;
int length;
uint8_t data[OSDP_EVENT_KEYPRESS_MAX_DATALEN];
};
struct osdp_event_mfgrep {
uint32_t vendor_code;
uint8_t length;
uint8_t data[OSDP_EVENT_MFGREP_MAX_DATALEN];
};
enum osdp_event_notification_type {
OSDP_EVENT_NOTIFICATION_COMMAND,
OSDP_EVENT_NOTIFICATION_SC_STATUS,
OSDP_EVENT_NOTIFICATION_PD_STATUS,
};
struct osdp_event_notification {
enum osdp_event_notification_type type;
int arg0;
int arg1;
};
enum osdp_event_type {
OSDP_EVENT_CARDREAD = 1,
OSDP_EVENT_KEYPRESS,
OSDP_EVENT_MFGREP,
OSDP_EVENT_STATUS,
OSDP_EVENT_NOTIFICATION,
OSDP_EVENT_SENTINEL
};
struct osdp_event {
osdp_queue_node_t _node;
enum osdp_event_type type;
uint32_t flags;
union {
struct osdp_event_keypress keypress;
struct osdp_event_cardread cardread;
struct osdp_event_mfgrep mfgrep;
struct osdp_status_report status;
struct osdp_event_notification notif;
};
};
typedef int (*pd_command_callback_t)(void *arg, struct osdp_cmd *cmd);
typedef int (*cp_event_callback_t)(void *arg, int pd, struct osdp_event *ev);
enum osdp_completion_status {
OSDP_COMPLETION_OK = 0,
OSDP_COMPLETION_FAILED,
OSDP_COMPLETION_FLUSHED,
OSDP_COMPLETION_ABORTED,
};
typedef void (*cp_command_completion_callback_t)(void *arg, int pd,
const struct osdp_cmd *cmd,
enum osdp_completion_status status);
typedef void (*pd_event_completion_callback_t)(void *arg,
const struct osdp_event *ev,
enum osdp_completion_status status);
OSDP_EXPORT
osdp_t *osdp_pd_setup(const osdp_pd_info_t *info);
OSDP_EXPORT
void osdp_pd_refresh(osdp_t *ctx);
OSDP_EXPORT
void osdp_pd_teardown(osdp_t *ctx);
OSDP_EXPORT
void osdp_pd_set_capabilities(osdp_t *ctx, const struct osdp_pd_cap *cap);
OSDP_EXPORT
void osdp_pd_set_command_callback(osdp_t *ctx, pd_command_callback_t cb,
void *arg);
#ifdef OPT_OSDP_APP_OWNED_QUEUE_DATA
OSDP_EXPORT
void osdp_pd_set_event_completion_callback(osdp_t *ctx,
pd_event_completion_callback_t cb,
void *arg);
#endif
OSDP_DEPRECATED_EXPORT("Use osdp_pd_submit_event() instead!")
int osdp_pd_notify_event(osdp_t *ctx, const struct osdp_event *event);
OSDP_EXPORT
int osdp_pd_submit_event(osdp_t *ctx, const struct osdp_event *event);
OSDP_EXPORT
int osdp_pd_flush_events(osdp_t *ctx);
OSDP_EXPORT
osdp_t *osdp_cp_setup(int num_pd, const osdp_pd_info_t *info);
OSDP_EXPORT
int osdp_cp_add_pd(osdp_t *ctx, int num_pd, const osdp_pd_info_t *info);
OSDP_EXPORT
void osdp_cp_refresh(osdp_t *ctx);
OSDP_EXPORT
void osdp_cp_teardown(osdp_t *ctx);
OSDP_DEPRECATED_EXPORT("Use osdp_cp_submit_command() instead!")
int osdp_cp_send_command(osdp_t *ctx, int pd, const struct osdp_cmd *cmd);
OSDP_EXPORT
int osdp_cp_submit_command(osdp_t *ctx, int pd, const struct osdp_cmd *cmd);
OSDP_EXPORT
int osdp_cp_flush_commands(osdp_t *ctx, int pd);
OSDP_EXPORT
int osdp_cp_get_pd_id(const osdp_t *ctx, int pd, struct osdp_pd_id *id);
OSDP_EXPORT
int osdp_cp_get_capability(const osdp_t *ctx, int pd, struct osdp_pd_cap *cap);
OSDP_EXPORT
void osdp_cp_set_event_callback(osdp_t *ctx, cp_event_callback_t cb, void *arg);
#ifdef OPT_OSDP_APP_OWNED_QUEUE_DATA
OSDP_EXPORT
void osdp_cp_set_command_completion_callback(osdp_t *ctx,
cp_command_completion_callback_t cb,
void *arg);
#endif
OSDP_EXPORT
int osdp_cp_modify_flag(osdp_t *ctx, int pd, uint32_t flags, bool do_set);
OSDP_EXPORT
int osdp_cp_disable_pd(osdp_t *ctx, int pd);
OSDP_EXPORT
int osdp_cp_enable_pd(osdp_t *ctx, int pd);
OSDP_EXPORT
bool osdp_cp_is_pd_enabled(const osdp_t *ctx, int pd);
enum osdp_log_level_e {
OSDP_LOG_EMERG,
OSDP_LOG_ALERT,
OSDP_LOG_CRIT,
OSDP_LOG_ERROR,
OSDP_LOG_WARNING,
OSDP_LOG_NOTICE,
OSDP_LOG_INFO,
OSDP_LOG_DEBUG,
OSDP_LOG_MAX_LEVEL
};
typedef int (*osdp_log_puts_fn_t)(const char *msg);
typedef void (*osdp_log_callback_fn_t)(int log_level, const char *file,
unsigned long line, const char *msg);
OSDP_EXPORT
void osdp_logger_init(const char *name, int log_level,
osdp_log_puts_fn_t puts_fn);
OSDP_EXPORT
void osdp_set_log_callback(osdp_log_callback_fn_t cb);
OSDP_EXPORT
const char *osdp_get_version();
OSDP_EXPORT
const char *osdp_get_source_info();
OSDP_EXPORT
void osdp_get_status_mask(const osdp_t *ctx, uint8_t *bitmask);
OSDP_EXPORT
void osdp_get_sc_status_mask(const osdp_t *ctx, uint8_t *bitmask);
typedef int (*osdp_file_open_fn_t)(void *arg, int file_id, int *size);
typedef int (*osdp_file_read_fn_t)(void *arg, void *buf, int size, int offset);
typedef int (*osdp_file_write_fn_t)(void *arg, const void *buf,
int size, int offset);
typedef int (*osdp_file_close_fn_t)(void *arg);
struct osdp_file_ops {
void *arg;
osdp_file_open_fn_t open;
osdp_file_read_fn_t read;
osdp_file_write_fn_t write;
osdp_file_close_fn_t close;
};
OSDP_EXPORT
int osdp_file_register_ops(osdp_t *ctx, int pd,
const struct osdp_file_ops *ops);
OSDP_EXPORT
int osdp_get_file_tx_status(const osdp_t *ctx, int pd, int *size, int *offset);
#ifdef __cplusplus
}
#endif
#endif