Peripheral Device
The following functions are used when OSDP is to be used in pd mode. The library
returns a single opaque pointer of type osdp_t
where it maintains all it’s
internal data. All applications consuming this library must pass this context
pointer all API calls.
Device lifecycle management
-
typedef void osdp_t
To keep the OSDP internal data structures from polluting the exposed headers, they are typedefed to void before sending them to the upper layers. This level of abstraction looked reasonable as technically no one should attempt to modify it outside of the LibOSDP and their definition may change at any time.
-
osdp_t *osdp_pd_setup(const osdp_pd_info_t *info)
This method is used to setup a device in PD mode. Application must store the returned context pointer and pass it back to all OSDP functions intact.
- Parameters:
info – Pointer to info struct populated by application.
- Return values:
OSDP – Context on success
NULL – on errors
PD Capabilities
-
struct osdp_pd_cap
PD capability structure. Each PD capability has a 3 byte representation.
Public Members
-
uint8_t function_code
Capability function code. See osdp_pd_cap_function_code_e
-
uint8_t compliance_level
A function_code dependent number that indicates what the PD can do with this capability.
-
uint8_t num_items
Number of such capability entities in PD
-
uint8_t function_code
-
void osdp_pd_set_capabilities(osdp_t *ctx, const struct osdp_pd_cap *cap)
Set PD’s capabilities.
- Parameters:
ctx – OSDP context
cap – pointer to array of cap (
struct osdp_pd_cap
) terminated by a capability with cap->function_code set to 0.
Commands
-
typedef int (*pd_command_callback_t)(void *arg, struct osdp_cmd *cmd)
Callback for PD command notifications. After it has been registered with
osdp_pd_set_command_callback
, this method is invoked when the PD receives a command from the CP.- Param arg:
pointer that will was passed to the arg param of
osdp_pd_set_command_callback
.- Param cmd:
pointer to the received command.
- Retval 0:
if LibOSDP must send a
osdp_ACK
response- Retval -ve:
if LibOSDP must send a
osdp_NAK
response- Retval +ve:
and modify the passed
struct osdp_cmd *cmd
if LibOSDP must send a specific response. This is useful for sending manufacturer specific replyosdp_MFGREP
.
-
void osdp_pd_set_command_callback(osdp_t *ctx, pd_command_callback_t cb, void *arg)
Set callback method for PD command notification. This callback is invoked when the PD receives a command from the CP.
- Parameters:
ctx – OSDP context
cb – The callback function’s pointer
arg – A pointer that will be passed as the first argument of
cb
Refer to the command structure document for more information on how the
cmd
structure is framed.
Events
When a PD app has some event (card read, key press, etc.,) to be reported to the
CP, it creates the corresponding event structure and calls
osdp_pd_notify_event
to deliver it to the CP on the next osdp_POLL command.
-
int osdp_pd_notify_event(osdp_t *ctx, const struct osdp_event *event)
API to notify PD events to CP. These events are sent to the CP as an alternate response to a POLL command.
- Parameters:
ctx – OSDP context
event – pointer to event struct. Must be filled by application.
- Return values:
0 – on success
-1 – on failure
-
int osdp_pd_flush_events(osdp_t *ctx)
Deletes all events from the PD’s event queue.
- Parameters:
ctx – OSDP context
- Returns:
int Count of events dequeued.
Refer to the event structure document for more information on how to
populate the event
structure for these function.