Documentation

Peripheral Device

The following functions are used when OSDP is used in PD mode. The library returns a single opaque pointer of type osdp_t where it maintains all internal data. All applications consuming this library must pass this context pointer to all API calls.

Device Lifecycle Management

The PD is described to osdp_pd_setup with an osdp_pd_info_t structure.

typedefosdp_t
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.

functionosdp_pd_setup
osdp_t * osdp_pd_setup(struct osdp_channel *channel, 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
channelPointer to channel ops used for this PD context.
infoPointer to info struct populated by application.
Returns
OSDPContext on success
NULLon errors
functionosdp_pd_refresh
void osdp_pd_refresh(osdp_t *ctx)

Periodic refresh method. Must be called by the application at least once every 50ms to meet OSDP timing requirements.

Parameters
ctxOSDP context
functionosdp_pd_teardown
void osdp_pd_teardown(osdp_t *ctx)

Cleanup all osdp resources. The context pointer is no longer valid after this call.

Parameters
ctxOSDP context

PD Capabilities

See PD capabilities for the full list of function codes and compliance levels a PD can advertise.

structosdp_pd_cap

PD capability structure. Each PD capability has a 3 byte representation.

Members
enum osdp_pd_cap_function_code_e 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
enumosdp_pd_cap_function_code_e

Various PD capability function codes.

Values
OSDP_PD_CAP_UNUSED
Dummy.
OSDP_PD_CAP_CONTACT_STATUS_MONITORING
This function indicates the ability to monitor the status of a switch using a two-wire electrical connection between the PD and the switch. The on/off position of the switch indicates the state of an external device. The PD may simply resolve all circuit states to an open/closed status, or it may implement supervision of the monitoring circuit. A supervised circuit is able to indicate circuit fault status in addition to open/closed status.
OSDP_PD_CAP_OUTPUT_CONTROL
This function provides a switched output, typically in the form of a relay. The Output has two states: active or inactive. The Control Panel (CP) can directly set the Output's state, or, if the PD supports timed operations, the CP can specify a time period for the activation of the Output.
OSDP_PD_CAP_CARD_DATA_FORMAT
This capability indicates the form of the card data is presented to the Control Panel.
OSDP_PD_CAP_READER_LED_CONTROL
This capability indicates the presence of and type of LEDs.
OSDP_PD_CAP_READER_AUDIBLE_OUTPUT
This capability indicates the presence of and type of an Audible Annunciator (buzzer or similar tone generator)
OSDP_PD_CAP_READER_TEXT_OUTPUT
This capability indicates that the PD supports a text display emulating character-based display terminals.
OSDP_PD_CAP_TIME_KEEPING
This capability indicates that the type of date and time awareness or time keeping ability of the PD.
OSDP_PD_CAP_CHECK_CHARACTER_SUPPORT
All PDs must be able to support the checksum mode. This capability indicates if the PD is capable of supporting CRC mode.
OSDP_PD_CAP_COMMUNICATION_SECURITY
This capability indicates the extent to which the PD supports communication security (Secure Channel Communication)
OSDP_PD_CAP_RECEIVE_BUFFERSIZE
This capability indicates the maximum size single message the PD can receive.
OSDP_PD_CAP_LARGEST_COMBINED_MESSAGE_SIZE
This capability indicates the maximum size multi-part message which the PD can handle.
OSDP_PD_CAP_SMART_CARD_SUPPORT
This capability indicates whether the PD supports the transparent mode used for communicating directly with a smart card.
OSDP_PD_CAP_READERS
This capability indicates the number of credential reader devices present. Compliance levels are bit fields to be assigned as needed.
OSDP_PD_CAP_BIOMETRICS
This capability indicates the ability of the reader to handle biometric input
OSDP_PD_CAP_SECURE_PIN_ENTRY
This capability indicates if the reader is capable of supporting Secure Pin Entry (SPE) for smart cards
OSDP_PD_CAP_OSDP_VERSION
This capability indicates the version of OSDP the PD supports Compliance Levels: 0 - Unspecified 1 - IEC 60839-11-5 2 - SIA OSDP 2.2
OSDP_PD_CAP_SENTINEL
Capability Sentinel
functionosdp_pd_set_capabilities
void osdp_pd_set_capabilities(osdp_t *ctx, const struct osdp_pd_cap *cap)

Set PD's capabilities.

Parameters
ctxOSDP context
cappointer to array of cap (struct osdp_pd_cap) terminated by a capability with cap->function_code set to OSDP_PD_CAP_SENTINEL.

Commands

typedefpd_command_callback_t
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.

Parameters
argpointer that will was passed to the arg param of osdp_pd_set_command_callback.
cmdpointer to the received command.
Returns
0if LibOSDP must send an osdp_ACK response.
-veif LibOSDP must send an osdp_NAK response.
+veis reserved.
functionosdp_pd_set_command_callback
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
ctxOSDP context
cbThe callback function's pointer
argA 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.

Info

For CMD_MFG, callback return values use normal ACK/NAK behavior (negative return → NAK, non-negative return → ACK). Any manufacturer-specific reply payload must be sent asynchronously by submitting an OSDP_EVENT_MFGREP event with osdp_pd_submit_event.

Events

When a PD app has an event (card read, key press, etc.) to report to the CP, it creates the corresponding event structure and calls osdp_pd_submit_event to deliver it to the CP on the next osdp_POLL command.

functionosdp_pd_submit_event
int osdp_pd_submit_event(osdp_t *ctx, const struct osdp_event *event)

Submit PD events to CP. These events are delivered to the CP as a response to a future POLL command. A successful return does not mean CP received it, it only means LibOSDP accepted this submission.

Parameters
ctxOSDP context
eventpointer to event struct. Must be filled by application.
Returns
0on success
-1on failure
Event lifetime — queued by reference

An accepted event is queued by reference; LibOSDP does not copy it. The event you pass must stay alive and unmodified from a successful submission until the library is done with it. An event that lives on the stack of a function that returns (a command callback, say), or one reused for a second submission while the first is still queued, corrupts the queue.

Ownership returns to your application when the event completion callback fires for that pointer (register it with osdp_pd_set_event_completion_callback). Every accepted event is reported exactly once — including those dropped by osdp_pd_flush_events (OSDP_COMPLETION_FLUSHED) and osdp_pd_teardown (OSDP_COMPLETION_ABORTED) — so a heap-allocated event should be freed in that callback. On a -1 return the event was never queued and is yours to reuse at once.

functionosdp_pd_flush_events
int osdp_pd_flush_events(osdp_t *ctx)

Deletes all events from the PD's event queue.

Parameters
ctxOSDP context
Returns
intint Count of events dequeued.

Event Completion

Register a completion callback to learn when each submitted event leaves your ownership. The outcome is reported as an osdp_completion_status.

typedefpd_event_completion_callback_t
typedef void(* pd_event_completion_callback_t) (void *arg, const struct osdp_event *ev, enum osdp_completion_status status)

Callback for PD event completion notifications.

functionosdp_pd_set_event_completion_callback
void osdp_pd_set_event_completion_callback(osdp_t *ctx, pd_event_completion_callback_t cb, void *arg)

Set callback method for PD event completion.

Parameters
ctxOSDP context
cbCallback function pointer
argOpaque pointer passed as first callback argument

Refer to the event structure document for more information on how to populate the event structure.

Deprecated

osdp_pd_notify_event is retained for backward compatibility; new code should use osdp_pd_submit_event instead.

functionosdp_pd_notify_event
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
ctxOSDP context
eventpointer to event struct. Must be filled by application.
Returns
0on success
-1on failure