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 {
45 
50 typedef struct
51 {
52  struct
53  {
54  az_span global_device_endpoint;
55  az_span id_scope;
56  az_span registration_id;
58  } _internal;
60 
70 
89  az_span global_device_hostname,
90  az_span id_scope,
91  az_span registration_id,
92  az_iot_provisioning_client_options const* options);
93 
110  az_iot_provisioning_client const* client,
111  char* mqtt_user_name,
112  size_t mqtt_user_name_size,
113  size_t* out_mqtt_user_name_length);
114 
131  az_iot_provisioning_client const* client,
132  char* mqtt_client_id,
133  size_t mqtt_client_id_size,
134  size_t* out_mqtt_client_id_length);
135 
136 /*
137  *
138  * SAS Token APIs
139  *
140  * Use the following APIs when the Shared Access Key is available to the application or stored
141  * within a Hardware Security Module. The APIs are not necessary if X509 Client Certificate
142  * Authentication is used.
143  *
144  * The TPM Asymmetric Device Provisioning protocol is not supported on the MQTT protocol. TPMs can
145  * still be used to securely store and perform HMAC-SHA256 operations for SAS tokens.
146  */
147 
168  az_iot_provisioning_client const* client,
169  uint64_t token_expiration_epoch_time,
170  az_span signature,
171  az_span* out_signature);
172 
199  az_iot_provisioning_client const* client,
200  az_span base64_hmac_sha256_signature,
201  uint64_t token_expiration_epoch_time,
202  az_span key_name,
203  char* mqtt_password,
204  size_t mqtt_password_size,
205  size_t* out_mqtt_password_length);
206 
207 /*
208  *
209  * Register APIs
210  *
211  * Use the following APIs when the Shared Access Key is available to the application or stored
212  * within a Hardware Security Module. The APIs are not necessary if X509 Client Certificate
213  * Authentication is used.
214  */
215 
220 #define AZ_IOT_PROVISIONING_CLIENT_REGISTER_SUBSCRIBE_TOPIC "$dps/registrations/res/#"
221 
227 typedef struct
228 {
234 
239 
244 
249 
254 
259 
265 
270 typedef enum
271 {
280 
281  // Device assignment operation complete.
286 
291 
297 
302 typedef struct
303 {
308 
309  // Avoid using enum as the first field within structs, to allow for { 0 } initialization.
310  // This is a workaround for IAR compiler warning [Pe188]: enumerated type mixed with another type.
311 
318 
323 
328 
335 
352  az_iot_provisioning_client const* client,
353  az_span received_topic,
354  az_span received_payload,
356 
371 {
372  return (operation_status > AZ_IOT_PROVISIONING_STATUS_ASSIGNING);
373 }
374 
395  az_iot_provisioning_client const* client,
396  char* mqtt_topic,
397  size_t mqtt_topic_size,
398  size_t* out_mqtt_topic_length);
399 
420  az_iot_provisioning_client const* client,
421  az_span operation_id,
422  char* mqtt_topic,
423  size_t mqtt_topic_size,
424  size_t* out_mqtt_topic_length);
425 
426 #include <azure/core/_az_cfg_suffix.h>
427 
428 #endif // _az_IOT_PROVISIONING_CLIENT_H
az_iot_provisioning_client_registration_state
The registration operation state.
Definition: az_iot_provisioning_client.h:228
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:307
az_iot_provisioning_client_register_response::operation_status
az_iot_provisioning_client_operation_status operation_status
Definition: az_iot_provisioning_client.h:322
az_iot_provisioning_client_registration_state::error_message
az_span error_message
Definition: az_iot_provisioning_client.h:253
az_iot_provisioning_client_register_response::registration_state
az_iot_provisioning_client_registration_state registration_state
Definition: az_iot_provisioning_client.h:333
az_iot_provisioning_client
Azure IoT Provisioning Client.
Definition: az_iot_provisioning_client.h:51
AZ_IOT_PROVISIONING_STATUS_ASSIGNED
@ AZ_IOT_PROVISIONING_STATUS_ASSIGNED
Definition: az_iot_provisioning_client.h:285
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_result
int32_t az_result
The type represents the various success and error conditions.
Definition: az_result.h:46
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_registration_state::extended_error_code
uint32_t extended_error_code
Definition: az_iot_provisioning_client.h:248
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:303
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:369
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:263
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:271
AZ_IOT_PROVISIONING_STATUS_UNASSIGNED
@ AZ_IOT_PROVISIONING_STATUS_UNASSIGNED
Definition: az_iot_provisioning_client.h:275
AZ_IOT_PROVISIONING_STATUS_ASSIGNING
@ AZ_IOT_PROVISIONING_STATUS_ASSIGNING
Definition: az_iot_provisioning_client.h:279
az_span.h
An az_span represents a contiguous byte buffer and is used for string manipulations,...
az_iot_provisioning_client_options::user_agent
az_span user_agent
Definition: az_iot_provisioning_client.h:43
az_iot_provisioning_client_registration_state::device_id
az_span device_id
Definition: az_iot_provisioning_client.h:238
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_STATUS_DISABLED
@ AZ_IOT_PROVISIONING_STATUS_DISABLED
Definition: az_iot_provisioning_client.h:295
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_STATUS_FAILED
@ AZ_IOT_PROVISIONING_STATUS_FAILED
Definition: az_iot_provisioning_client.h:290
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:317
az_iot_provisioning_client_registration_state::error_tracking_id
az_span error_tracking_id
Definition: az_iot_provisioning_client.h:258
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:243
az_iot_status
az_iot_status
Azure IoT service status codes.
Definition: az_iot_common.h:75
az_iot_provisioning_client_register_response::retry_after_seconds
uint32_t retry_after_seconds
Definition: az_iot_provisioning_client.h:327
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:233
az_span
Represents a "view" over a byte buffer that represents a contiguous region of memory....
Definition: az_span.h:33