IoTivity-Lite
|
A facitility to securely provision and preconfigure devices. More...
Modules | |
Support for multiple DPS endpoint addresses | |
Macros | |
#define | PLGD_DPS_URI "/plgd/dps" |
Configuration resource. More... | |
Typedefs | |
typedef struct plgd_dps_context_t | plgd_dps_context_t |
typedef void(* | plgd_dps_on_status_change_cb_t) (plgd_dps_context_t *ctx, plgd_dps_status_t status, void *data) |
A function pointer for handling the dps status. More... | |
typedef void(* | plgd_dps_print_log_fn_t) (oc_log_level_t level, const char *file, int line, const char *func_name, const char *format,...) |
Custom logging function. More... | |
typedef bool(* | plgd_dps_schedule_action_cb_t) (plgd_dps_context_t *ctx, plgd_dps_status_t action, uint8_t retry_count, uint64_t *delay, uint16_t *timeout, void *user_data) |
Callback invoked by the dps manager when the dps wants to schedule an action. More... | |
Enumerations | |
enum | { PLGD_DPS_MAX_RETRY_VALUES_SIZE = 8 } |
enum | plgd_dps_dhcp_set_values_t { PLGD_DPS_DHCP_SET_VALUES_ERROR = -1 , PLGD_DPS_DHCP_SET_VALUES_NOT_CHANGED = 0 , PLGD_DPS_DHCP_SET_VALUES_UPDATED = 1 , PLGD_DPS_DHCP_SET_VALUES_NEED_REPROVISION } |
DPS dhcp plgd_dps_dhcp_set_values_from_vendor_encapsulated_options return values. More... | |
enum | plgd_dps_error_t { PLGD_DPS_OK = 0 , PLGD_DPS_ERROR_RESPONSE = 1 , PLGD_DPS_ERROR_CONNECT = 2 , PLGD_DPS_ERROR_GET_CREDENTIALS = 3 , PLGD_DPS_ERROR_GET_ACLS = 4 , PLGD_DPS_ERROR_SET_CLOUD = 5 , PLGD_DPS_ERROR_START_CLOUD = 6 , PLGD_DPS_ERROR_GET_OWNER = 7 , PLGD_DPS_ERROR_GET_TIME = 8 } |
DPS errors. More... | |
enum | plgd_dps_status_t { PLGD_DPS_INITIALIZED = 1 << 0 , PLGD_DPS_GET_CREDENTIALS = 1 << 1 , PLGD_DPS_HAS_CREDENTIALS = 1 << 2 , PLGD_DPS_GET_ACLS = 1 << 3 , PLGD_DPS_HAS_ACLS = 1 << 4 , PLGD_DPS_GET_CLOUD = 1 << 6 , PLGD_DPS_HAS_CLOUD = 1 << 7 , PLGD_DPS_CLOUD_STARTED = 1 << 8 , PLGD_DPS_RENEW_CREDENTIALS = 1 << 9 , PLGD_DPS_GET_OWNER = 1 << 10 , PLGD_DPS_HAS_OWNER = 1 << 11 , PLGD_DPS_GET_TIME = 1 << 12 , PLGD_DPS_HAS_TIME = 1 << 13 , PLGD_DPS_TRANSIENT_FAILURE = 1 << 29 , PLGD_DPS_FAILURE = 1 << 30 } |
DPS provisioning status flags. More... | |
Functions | |
bool | plgd_cloud_manager_start (const plgd_dps_context_t *ctx) |
Start cloud manager with previously set server and callbacks. More... | |
uint8_t | plgd_dps_dhcp_get_vendor_encapsulated_option_code_dps_certificate_fingerprint (const plgd_dps_context_t *ctx) |
Get the vendor encapsulated option code for the DPS certificate fingerprint. More... | |
uint8_t | plgd_dps_dhcp_get_vendor_encapsulated_option_code_dps_endpoint (const plgd_dps_context_t *ctx) |
Get the vendor encapsulated option code for the DPS endpoint. More... | |
plgd_dps_dhcp_set_values_t | plgd_dps_dhcp_set_values_from_vendor_encapsulated_options (plgd_dps_context_t *ctx, const uint8_t *vendor_encapsulated_options, size_t vendor_encapsulated_options_size) |
Set DPS endpoint and certificate fingerprint that will be used in establishment of secure connection. More... | |
void | plgd_dps_dhcp_set_vendor_encapsulated_option_code_dps_certificate_fingerprint (plgd_dps_context_t *ctx, uint8_t code) |
Set the vendor encapsulated option code for the DPS certificate fingerprint. More... | |
void | plgd_dps_dhcp_set_vendor_encapsulated_option_code_dps_endpoint (plgd_dps_context_t *ctx, uint8_t code) |
Set the vendor encapsulated option code for the DPS endpoint. More... | |
void | plgd_dps_force_reprovision (plgd_dps_context_t *ctx) |
Force all steps of the provisioning process to be executed. More... | |
int | plgd_dps_get_certificate_fingerprint (const plgd_dps_context_t *ctx, mbedtls_md_type_t *md_type, uint8_t *buffer, size_t buffer_size) |
Copy certificate fingerprint of the DPS service to output buffer. More... | |
plgd_cloud_status_observer_configuration_t | plgd_dps_get_cloud_observer_configuration (const plgd_dps_context_t *ctx) |
Get cloud observer configuration. More... | |
plgd_dps_context_t * | plgd_dps_get_context (size_t device) |
Get context for given device. More... | |
size_t | plgd_dps_get_device (const plgd_dps_context_t *ctx) |
Get device from context. More... | |
plgd_dps_error_t | plgd_dps_get_last_error (const plgd_dps_context_t *ctx) |
Get last provisioning error. More... | |
plgd_dps_print_log_fn_t | plgd_dps_get_log_fn (void) 1 |
Get global logging function. More... | |
uint32_t | plgd_dps_get_provision_status (const plgd_dps_context_t *ctx) |
Get provision status. More... | |
bool | plgd_dps_get_skip_verify (const plgd_dps_context_t *ctx) |
Get skip verify value from context. More... | |
bool | plgd_dps_has_been_provisioned_since_reset (const plgd_dps_context_t *ctx) |
Check whether the device has been provisioned at least once since the last DPS reset initiated by a factory reset or by setting the endpoint to an empty value in the DPS resource. More... | |
bool | plgd_dps_has_forced_reprovision (const plgd_dps_context_t *ctx) |
Check if force reprovision flag is set. More... | |
ssize_t | plgd_dps_hex_string_to_bytes (const char *hex_string, size_t hex_string_size, uint8_t *buffer, size_t buffer_size) |
Convert isc-dhcp leases file vendor encapsulated options to byte array. More... | |
int | plgd_dps_init (void) |
Allocate and initialize data. More... | |
oc_log_level_t | plgd_dps_log_get_level (void) |
Get log level of the global logger. More... | |
void | plgd_dps_log_set_level (oc_log_level_t level) |
Set log level of the global logger, logs with lower importance will be ignored. More... | |
bool | plgd_dps_manager_is_started (const plgd_dps_context_t *ctx) |
Check whether DPS manager has been started. More... | |
int | plgd_dps_manager_restart (plgd_dps_context_t *ctx) |
Restart DPS manager to provision device by given server. More... | |
int | plgd_dps_manager_start (plgd_dps_context_t *ctx) |
Start DPS manager to provision device. More... | |
void | plgd_dps_manager_stop (plgd_dps_context_t *ctx) |
Stop DPS manager. More... | |
int | plgd_dps_on_factory_reset (plgd_dps_context_t *ctx) |
Clean-up of DPS provisioning on factory reset. More... | |
uint16_t | plgd_dps_pki_get_expiring_limit (const plgd_dps_context_t *ctx) |
Get expiring-in limit of DPS certificates. More... | |
void | plgd_dps_pki_set_expiring_limit (plgd_dps_context_t *ctx, uint16_t expiring_limit) |
Set expiring-in limit of DPS certificates. More... | |
bool | plgd_dps_set_certificate_fingerprint (plgd_dps_context_t *ctx, mbedtls_md_type_t md_type, const uint8_t *fingerprint, size_t size) |
Set certificate fingerprint of the provisioning server. More... | |
bool | plgd_dps_set_cloud_observer_configuration (plgd_dps_context_t *ctx, uint8_t max_retry_count, uint8_t retry_interval_s) |
Configure cloud observer. More... | |
void | plgd_dps_set_configuration_resource (plgd_dps_context_t *ctx, bool create) |
Controls whether a dps client creates configuration resource for managing dps client via COAPs API. More... | |
void | plgd_dps_set_log_fn (plgd_dps_print_log_fn_t log_fn) |
Set global logging function. More... | |
void | plgd_dps_set_manager_callbacks (plgd_dps_context_t *ctx, plgd_dps_manager_callbacks_t callbacks) |
Set DPS manager callbacks. More... | |
bool | plgd_dps_set_retry_configuration (plgd_dps_context_t *ctx, const uint8_t cfg[], size_t cfg_size) |
Configure retry counter. More... | |
void | plgd_dps_set_schedule_action (plgd_dps_context_t *ctx, plgd_dps_schedule_action_cb_t on_schedule_action, void *user_data) |
Set a custom scheduler for actions in the cloud manager. More... | |
void | plgd_dps_set_skip_verify (plgd_dps_context_t *ctx, bool skip_verify) |
Controls whether a dps client verifies the device provision service's certificate chain against trust anchor in the device. More... | |
void | plgd_dps_shutdown (void) |
Stop all devices and deallocate data. More... | |
int | plgs_dps_get_retry_configuration (const plgd_dps_context_t *ctx, uint8_t *buffer, size_t buffer_size) |
Get retry counter configuration. More... | |
A facitility to securely provision and preconfigure devices.
#define PLGD_DPS_URI "/plgd/dps" |
Configuration resource.
Description:
typedef void(* plgd_dps_on_status_change_cb_t) (plgd_dps_context_t *ctx, plgd_dps_status_t status, void *data) |
A function pointer for handling the dps status.
ctx | dps context |
status | Current status of the dps. |
data | user data provided to the callback |
typedef void(* plgd_dps_print_log_fn_t) (oc_log_level_t level, const char *file, int line, const char *func_name, const char *format,...) |
Custom logging function.
level | log level of the message |
file | file of the log message call |
line | line of the log message call in file |
func_name | function name in which the log message call is invoked |
format | format of the log message |
typedef bool(* plgd_dps_schedule_action_cb_t) (plgd_dps_context_t *ctx, plgd_dps_status_t action, uint8_t retry_count, uint64_t *delay, uint16_t *timeout, void *user_data) |
Callback invoked by the dps manager when the dps wants to schedule an action.
ctx | dps context |
action | One of PLGD_DPS_GET actions or PLGD_DPS_RENEW_CREDENTIALS to schedule, or 0 for reinitialization. |
retry_count | Retries count - 0 means the first attempt to perform the action. |
delay | Delay the action in milliseconds before executing it. |
timeout | Timeout in seconds for the action. |
user_data | User data passed from the caller. |
anonymous enum |
DPS dhcp plgd_dps_dhcp_set_values_from_vendor_encapsulated_options return values.
enum plgd_dps_error_t |
DPS errors.
enum plgd_dps_status_t |
DPS provisioning status flags.
bool plgd_cloud_manager_start | ( | const plgd_dps_context_t * | ctx | ) |
Start cloud manager with previously set server and callbacks.
ctx | dps context (cannot be NULL) |
uint8_t plgd_dps_dhcp_get_vendor_encapsulated_option_code_dps_certificate_fingerprint | ( | const plgd_dps_context_t * | ctx | ) |
Get the vendor encapsulated option code for the DPS certificate fingerprint.
Used during call plgd_dps_set_dhcp_vendor_encapsulated_option_code_dps_certificate_fingerprint.
ctx | dps context (cannot be NULL) |
uint8_t plgd_dps_dhcp_get_vendor_encapsulated_option_code_dps_endpoint | ( | const plgd_dps_context_t * | ctx | ) |
Get the vendor encapsulated option code for the DPS endpoint.
Used during call plgd_dps_set_dhcp_vendor_encapsulated_option_code_dps_certificate_fingerprint.
ctx | dps context (cannot be NULL) |
plgd_dps_dhcp_set_values_t plgd_dps_dhcp_set_values_from_vendor_encapsulated_options | ( | plgd_dps_context_t * | ctx, |
const uint8_t * | vendor_encapsulated_options, | ||
size_t | vendor_encapsulated_options_size | ||
) |
Set DPS endpoint and certificate fingerprint that will be used in establishment of secure connection.
ctx | dps context (cannot be NULL) |
vendor_encapsulated_options | vendor encapsulated options in byte array |
vendor_encapsulated_options_size | vendor encapsulated options size in byte array |
void plgd_dps_dhcp_set_vendor_encapsulated_option_code_dps_certificate_fingerprint | ( | plgd_dps_context_t * | ctx, |
uint8_t | code | ||
) |
Set the vendor encapsulated option code for the DPS certificate fingerprint.
Used during call plgd_dps_set_dhcp_vendor_encapsulated_option_code_dps_certificate_fingerprint.
ctx | dps context (cannot be NULL) |
code | vendor encapsulated option code for the DPS certificate fingerprint. |
void plgd_dps_dhcp_set_vendor_encapsulated_option_code_dps_endpoint | ( | plgd_dps_context_t * | ctx, |
uint8_t | code | ||
) |
Set the vendor encapsulated option code for the DPS endpoint.
Used during call plgd_dps_set_dhcp_vendor_encapsulated_option_code_dps_certificate_fingerprint.
ctx | dps context (cannot be NULL) |
code | vendor encapsulated option code for the DPS endpoint |
void plgd_dps_force_reprovision | ( | plgd_dps_context_t * | ctx | ) |
Force all steps of the provisioning process to be executed.
A step that was successfully executed stores data in the storage and on the next start this data is still valid the step would be automatically skipped.
ctx | dps context (cannot be NULL) |
int plgd_dps_get_certificate_fingerprint | ( | const plgd_dps_context_t * | ctx, |
mbedtls_md_type_t * | md_type, | ||
uint8_t * | buffer, | ||
size_t | buffer_size | ||
) |
Copy certificate fingerprint of the DPS service to output buffer.
ctx | dps context (cannot be NULL) | |
[out] | md_type | hash algorithm used for fingerprint |
[out] | buffer | output buffer (cannot be NULL and must be large enough to contain the endpoint in a string format) |
buffer_size | size of output buffer |
plgd_cloud_status_observer_configuration_t plgd_dps_get_cloud_observer_configuration | ( | const plgd_dps_context_t * | ctx | ) |
Get cloud observer configuration.
ctx | dps context (cannot be NULL) |
plgd_dps_context_t* plgd_dps_get_context | ( | size_t | device | ) |
Get context for given device.
size_t plgd_dps_get_device | ( | const plgd_dps_context_t * | ctx | ) |
Get device from context.
ctx | dps context (cannot be NULL) |
plgd_dps_error_t plgd_dps_get_last_error | ( | const plgd_dps_context_t * | ctx | ) |
Get last provisioning error.
ctx | dps context (cannot be NULL) |
plgd_dps_print_log_fn_t plgd_dps_get_log_fn | ( | void | ) |
Get global logging function.
uint32_t plgd_dps_get_provision_status | ( | const plgd_dps_context_t * | ctx | ) |
Get provision status.
ctx | dps context (cannot be NULL) |
bool plgd_dps_get_skip_verify | ( | const plgd_dps_context_t * | ctx | ) |
Get skip verify
value from context.
ctx | dps context (cannot be NULL) |
skip verify
is enabled skip verify
is disabledbool plgd_dps_has_been_provisioned_since_reset | ( | const plgd_dps_context_t * | ctx | ) |
Check whether the device has been provisioned at least once since the last DPS reset initiated by a factory reset or by setting the endpoint to an empty value in the DPS resource.
ctx | dps context (cannot be NULL) |
bool plgd_dps_has_forced_reprovision | ( | const plgd_dps_context_t * | ctx | ) |
Check if force reprovision flag is set.
ctx | dps context (cannot be NULL) |
ssize_t plgd_dps_hex_string_to_bytes | ( | const char * | hex_string, |
size_t | hex_string_size, | ||
uint8_t * | buffer, | ||
size_t | buffer_size | ||
) |
Convert isc-dhcp leases file vendor encapsulated options to byte array.
hex_string | input hex string (cannot be NULL) in format "01:a:3:14" or "010a0314" |
hex_string_size | vendor encapsulated options size in dhcp leases file. |
buffer | output buffer into which the byte array will be copied or NULL to get the needed size |
buffer_size | size of the output buffer |
int plgd_dps_init | ( | void | ) |
Allocate and initialize data.
oc_log_level_t plgd_dps_log_get_level | ( | void | ) |
Get log level of the global logger.
It is thread safe.
void plgd_dps_log_set_level | ( | oc_log_level_t | level | ) |
Set log level of the global logger, logs with lower importance will be ignored.
It is thread safe.
level | Log level |
bool plgd_dps_manager_is_started | ( | const plgd_dps_context_t * | ctx | ) |
Check whether DPS manager has been started.
ctx | dps context (cannot be NULL) |
int plgd_dps_manager_restart | ( | plgd_dps_context_t * | ctx | ) |
Restart DPS manager to provision device by given server.
A convenience function equivalent to calling plgd_dps_manager_stop and plgd_dps_manager_start.
ctx | dps context (cannot be NULL) |
int plgd_dps_manager_start | ( | plgd_dps_context_t * | ctx | ) |
Start DPS manager to provision device.
Setup context, global session handlers and start DPS manager.
Starting DPS also starts the retry mechanism, which will remain active until the device is successfully provisioned. If a provisioning step fails, it will be tried again after a time interval. The time interval depends on the retry counter (which is incremented on each retry) and uses the following values [ 10, 20, 40, 80, 120 ] in seconds. Meaning that the first retry is scheduled after 10 seconds after a failure, the second retry after 20 seconds, etc. After the interval reaches the maximal value (120 seconds) it resets back to the first value (10 seconds).
ctx | dps context (cannot be NULL) |
void plgd_dps_manager_stop | ( | plgd_dps_context_t * | ctx | ) |
Stop DPS manager.
Deregister handlers, clear context, stop DPS manager, close connection to DPS endpoint and remove identity certificates retrieved from DPS endpoint.
ctx | dps context (cannot be NULL) |
int plgd_dps_on_factory_reset | ( | plgd_dps_context_t * | ctx | ) |
Clean-up of DPS provisioning on factory reset.
The function must be called from the factory reset handler to clean-up data that has been invalidated by a factory reset. The clean-up includes:
ctx | dps context (cannot be NULL) |
uint16_t plgd_dps_pki_get_expiring_limit | ( | const plgd_dps_context_t * | ctx | ) |
Get expiring-in limit of DPS certificates.
ctx | dps context (cannot be NULL) |
void plgd_dps_pki_set_expiring_limit | ( | plgd_dps_context_t * | ctx, |
uint16_t | expiring_limit | ||
) |
Set expiring-in limit of DPS certificates.
If a certificate's valid-to timestamp is within the expiring-in limit (current time < valid_to and current time + expiring-in limit > valid_to) then the certificate is considered as expiring. Expiring certificates are not accepted during the get credentials step of DPS provisioning. If a expiring certificates is received then the step is retried to receive a newer certificate with longer expiration.
ctx | dps context (cannot be NULL) |
expiring_limit | limit value in seconds |
bool plgd_dps_set_certificate_fingerprint | ( | plgd_dps_context_t * | ctx, |
mbedtls_md_type_t | md_type, | ||
const uint8_t * | fingerprint, | ||
size_t | size | ||
) |
Set certificate fingerprint of the provisioning server.
If the fingerprint is set then the DPS client will verify the fingerprint of the provisioning server certificate during the TLS handshake. If any certificate matching the fingerprint in the chain is found then the handshake is successful.
ctx | dps context (cannot be NULL) |
md_type | hash algorithm used for fingerprint |
fingerprint | fingerprint of the provisioning server certificate |
size | size of the fingerprint |
bool plgd_dps_set_cloud_observer_configuration | ( | plgd_dps_context_t * | ctx, |
uint8_t | max_retry_count, | ||
uint8_t | retry_interval_s | ||
) |
Configure cloud observer.
ctx | dps context (cannot be NULL) |
max_retry_count | maximal number of retries, set to 0 to disable cloud status observer |
retry_interval_s | retry interval in seconds (must be >0) |
void plgd_dps_set_configuration_resource | ( | plgd_dps_context_t * | ctx, |
bool | create | ||
) |
Controls whether a dps client creates configuration resource for managing dps client via COAPs API.
ctx | dps context (cannot be NULL) |
create | set true for creating resource. set false to free memory of created resource. |
void plgd_dps_set_log_fn | ( | plgd_dps_print_log_fn_t | log_fn | ) |
Set global logging function.
void plgd_dps_set_manager_callbacks | ( | plgd_dps_context_t * | ctx, |
plgd_dps_manager_callbacks_t | callbacks | ||
) |
Set DPS manager callbacks.
ctx | dps context (cannot be NULL) |
callbacks | callbacks with data |
Example of plgd_dps_on_status_change_cb_t function:
Example of oc_cloud_cb_t function:
bool plgd_dps_set_retry_configuration | ( | plgd_dps_context_t * | ctx, |
const uint8_t | cfg[], | ||
size_t | cfg_size | ||
) |
Configure retry counter.
ctx | dps context (cannot be NULL) |
cfg | array with new timeout values (must have [1, PLGD_DPS_MAX_RETRY_VALUES_SIZE> number of non-zero values) |
cfg_size | size of the array with timeout values |
void plgd_dps_set_schedule_action | ( | plgd_dps_context_t * | ctx, |
plgd_dps_schedule_action_cb_t | on_schedule_action, | ||
void * | user_data | ||
) |
Set a custom scheduler for actions in the cloud manager.
By default, the cloud manager uses its own scheduler.
This function allows you to set a custom scheduler to define delay and timeout for actions.
ctx | Cloud context to update. Must not be NULL. |
on_schedule_action | Callback invoked by the cloud manager when the cloud wants to schedule an action. |
user_data | User data passed from the caller to be provided during the callback. |
ctx
) must not be NULL. void plgd_dps_set_skip_verify | ( | plgd_dps_context_t * | ctx, |
bool | skip_verify | ||
) |
Controls whether a dps client verifies the device provision service's certificate chain against trust anchor in the device.
To set skip verify, it must be called before plgd_dps_manager_start.
ctx | dps context (cannot be NULL) |
skip_verify | skip verification of the DPS service |
void plgd_dps_shutdown | ( | void | ) |
Stop all devices and deallocate data.
int plgs_dps_get_retry_configuration | ( | const plgd_dps_context_t * | ctx, |
uint8_t * | buffer, | ||
size_t | buffer_size | ||
) |
Get retry counter configuration.
ctx | dps context (cannot be NULL) | |
[out] | buffer | output buffer into which the configuration will be copied (cannot be NULL, and must be large enough to contain the current configuration) |
buffer_size | size of the output buffer |