Azure SDK for Embedded C
az_iot_provisioning_client.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
17 #ifndef _az_IOT_PROVISIONING_CLIENT_H
18 #define _az_IOT_PROVISIONING_CLIENT_H
19 
20 #include <azure/core/az_result.h>
21 #include <azure/core/az_span.h>
23 
24 #include <stdbool.h>
25 #include <stdint.h>
26 
27 #include <azure/core/_az_cfg_prefix.h>
28 
32 #define AZ_IOT_PROVISIONING_SERVICE_VERSION "2019-03-31"
33 
38 typedef struct
39 {
43 
48 typedef struct
49 {
50  struct
51  {
52  az_span global_device_endpoint;
53  az_span id_scope;
54  az_span registration_id;
56  } _internal;
58 
67 
83  az_span global_device_hostname,
84  az_span id_scope,
85  az_span registration_id,
86  az_iot_provisioning_client_options const* options);
87 
101  az_iot_provisioning_client const* client,
102  char* mqtt_user_name,
103  size_t mqtt_user_name_size,
104  size_t* out_mqtt_user_name_length);
105 
119  az_iot_provisioning_client const* client,
120  char* mqtt_client_id,
121  size_t mqtt_client_id_size,
122  size_t* out_mqtt_client_id_length);
123 
124 /*
125  *
126  * SAS Token APIs
127  *
128  * Use the following APIs when the Shared Access Key is available to the application or stored
129  * within a Hardware Security Module. The APIs are not necessary if X509 Client Certificate
130  * Authentication is used.
131  *
132  * The TPM Asymmetric Device Provisioning protocol is not supported on the MQTT protocol. TPMs can
133  * still be used to securely store and perform HMAC-SHA256 operations for SAS tokens.
134  */
135 
152  az_iot_provisioning_client const* client,
153  uint64_t token_expiration_epoch_time,
154  az_span signature,
155  az_span* out_signature);
156 
179  az_iot_provisioning_client const* client,
180  az_span base64_hmac_sha256_signature,
181  uint64_t token_expiration_epoch_time,
182  az_span key_name,
183  char* mqtt_password,
184  size_t mqtt_password_size,
185  size_t* out_mqtt_password_length);
186 
187 /*
188  *
189  * Register APIs
190  *
191  * Use the following APIs when the Shared Access Key is available to the application or stored
192  * within a Hardware Security Module. The APIs are not necessary if X509 Client Certificate
193  * Authentication is used.
194  */
195 
200 #define AZ_IOT_PROVISIONING_CLIENT_REGISTER_SUBSCRIBE_TOPIC "$dps/registrations/res/#"
201 
207 typedef struct
208 {
216  az_span
219 
224 typedef struct
225 {
243 
256  az_iot_provisioning_client const* client,
257  az_span received_topic,
258  az_span received_payload,
260 
265 typedef enum
266 {
267  // Device assignment in progress.
268  AZ_IOT_PROVISIONING_STATUS_UNASSIGNED,
269  AZ_IOT_PROVISIONING_STATUS_ASSIGNING,
270 
271  // Device assignment operation complete.
272  AZ_IOT_PROVISIONING_STATUS_ASSIGNED,
273  AZ_IOT_PROVISIONING_STATUS_FAILED,
274  AZ_IOT_PROVISIONING_STATUS_DISABLED,
276 
289  az_iot_provisioning_client_operation_status* out_operation_status);
290 
303 {
304  return (operation_status > AZ_IOT_PROVISIONING_STATUS_ASSIGNING);
305 }
306 
324  az_iot_provisioning_client const* client,
325  char* mqtt_topic,
326  size_t mqtt_topic_size,
327  size_t* out_mqtt_topic_length);
328 
345  az_iot_provisioning_client const* client,
346  az_span operation_id,
347  char* mqtt_topic,
348  size_t mqtt_topic_size,
349  size_t* out_mqtt_topic_length);
350 
351 #include <azure/core/_az_cfg_suffix.h>
352 
353 #endif
az_iot_provisioning_client_registration_state
The registration operation state.
Definition: az_iot_provisioning_client.h:208
az_result.h
Definition of az_result and helper functions.
az_iot_provisioning_client_register_response::operation_id
az_span operation_id
Definition: az_iot_provisioning_client.h:230
az_iot_provisioning_client_registration_state::error_message
az_span error_message
Definition: az_iot_provisioning_client.h:214
az_iot_provisioning_client
Azure IoT Provisioning Client.
Definition: az_iot_provisioning_client.h:49
az_result
az_result
The type represents the various success and error conditions.
Definition: az_result.h:53
az_iot_provisioning_client_get_user_name
AZ_NODISCARD az_result az_iot_provisioning_client_get_user_name(az_iot_provisioning_client const *client, char *mqtt_user_name, size_t mqtt_user_name_size, size_t *out_mqtt_user_name_length)
Gets the MQTT user name.
az_iot_provisioning_client_parse_operation_status
AZ_NODISCARD az_result az_iot_provisioning_client_parse_operation_status(az_iot_provisioning_client_register_response *response, az_iot_provisioning_client_operation_status *out_operation_status)
Returns the az_iot_provisioning_client_operation_status of a az_iot_provisioning_client_register_resp...
az_iot_provisioning_client_query_status_get_publish_topic
AZ_NODISCARD az_result az_iot_provisioning_client_query_status_get_publish_topic(az_iot_provisioning_client const *client, az_span operation_id, char *mqtt_topic, size_t mqtt_topic_size, size_t *out_mqtt_topic_length)
Gets the MQTT topic that must be used to submit a Register Status request.
az_iot_provisioning_client_register_response::operation_status
az_span operation_status
Definition: az_iot_provisioning_client.h:231
az_iot_provisioning_client_registration_state::extended_error_code
uint32_t extended_error_code
Definition: az_iot_provisioning_client.h:213
az_iot_provisioning_client_register_get_publish_topic
AZ_NODISCARD az_result az_iot_provisioning_client_register_get_publish_topic(az_iot_provisioning_client const *client, char *mqtt_topic, size_t mqtt_topic_size, size_t *out_mqtt_topic_length)
Gets the MQTT topic that must be used to submit a Register request.
az_iot_provisioning_client_register_response
Register or query operation response.
Definition: az_iot_provisioning_client.h:225
az_iot_provisioning_client_operation_complete
AZ_INLINE bool az_iot_provisioning_client_operation_complete(az_iot_provisioning_client_operation_status operation_status)
Checks if the status indicates that the service has an authoritative result of the register operation...
Definition: az_iot_provisioning_client.h:301
az_iot_provisioning_client_sas_get_password
AZ_NODISCARD az_result az_iot_provisioning_client_sas_get_password(az_iot_provisioning_client const *client, az_span base64_hmac_sha256_signature, uint64_t token_expiration_epoch_time, az_span key_name, char *mqtt_password, size_t mqtt_password_size, size_t *out_mqtt_password_length)
Gets the MQTT password.
az_iot_provisioning_client_registration_state::error_timestamp
az_span error_timestamp
Definition: az_iot_provisioning_client.h:217
az_iot_provisioning_client_parse_received_topic_and_payload
AZ_NODISCARD az_result az_iot_provisioning_client_parse_received_topic_and_payload(az_iot_provisioning_client const *client, az_span received_topic, az_span received_payload, az_iot_provisioning_client_register_response *out_response)
Attempts to parse a received message's topic.
az_iot_provisioning_client_operation_status
az_iot_provisioning_client_operation_status
Azure IoT Provisioning Service operation status.
Definition: az_iot_provisioning_client.h:266
az_span.h
An az_span represents a contiguous byte buffer and is used for string manipulations,...
az_iot_provisioning_client_register_response::registration_result
az_iot_provisioning_client_registration_state registration_result
Definition: az_iot_provisioning_client.h:239
az_iot_provisioning_client_options::user_agent
az_span user_agent
Definition: az_iot_provisioning_client.h:40
az_iot_provisioning_client_registration_state::device_id
az_span device_id
Definition: az_iot_provisioning_client.h:211
az_iot_provisioning_client_options_default
AZ_NODISCARD az_iot_provisioning_client_options az_iot_provisioning_client_options_default()
Gets the default Azure IoT Provisioning Client options.
az_iot_provisioning_client_init
AZ_NODISCARD az_result az_iot_provisioning_client_init(az_iot_provisioning_client *client, az_span global_device_hostname, az_span id_scope, az_span registration_id, az_iot_provisioning_client_options const *options)
Initializes an Azure IoT Provisioning Client.
az_iot_provisioning_client_options
Azure IoT Provisioning Client options.
Definition: az_iot_provisioning_client.h:39
az_iot_provisioning_client_register_response::status
az_iot_status status
Definition: az_iot_provisioning_client.h:226
az_iot_provisioning_client_registration_state::error_tracking_id
az_span error_tracking_id
Definition: az_iot_provisioning_client.h:215
az_iot_provisioning_client_sas_get_signature
AZ_NODISCARD az_result az_iot_provisioning_client_sas_get_signature(az_iot_provisioning_client const *client, uint64_t token_expiration_epoch_time, az_span signature, az_span *out_signature)
Gets the Shared Access clear-text signature.
az_iot_provisioning_client_get_client_id
AZ_NODISCARD az_result az_iot_provisioning_client_get_client_id(az_iot_provisioning_client const *client, char *mqtt_client_id, size_t mqtt_client_id_size, size_t *out_mqtt_client_id_length)
Gets the MQTT client id.
az_iot_provisioning_client_registration_state::error_code
az_iot_status error_code
Definition: az_iot_provisioning_client.h:212
az_iot_status
az_iot_status
Azure IoT service status codes.
Definition: az_iot_common.h:39
az_iot_provisioning_client_register_response::retry_after_seconds
uint32_t retry_after_seconds
Definition: az_iot_provisioning_client.h:237
az_iot_common.h
Azure IoT common definitions.
az_iot_provisioning_client_registration_state::assigned_hub_hostname
az_span assigned_hub_hostname
Definition: az_iot_provisioning_client.h:209
az_span
Represents a "view" over a byte buffer that represents a contiguous region of memory....
Definition: az_span.h:33