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 
93  az_span global_device_hostname,
94  az_span id_scope,
95  az_span registration_id,
96  az_iot_provisioning_client_options const* options);
97 
116  az_iot_provisioning_client const* client,
117  char* mqtt_user_name,
118  size_t mqtt_user_name_size,
119  size_t* out_mqtt_user_name_length);
120 
139  az_iot_provisioning_client const* client,
140  char* mqtt_client_id,
141  size_t mqtt_client_id_size,
142  size_t* out_mqtt_client_id_length);
143 
144 /*
145  *
146  * SAS Token APIs
147  *
148  * Use the following APIs when the Shared Access Key is available to the application or stored
149  * within a Hardware Security Module. The APIs are not necessary if X509 Client Certificate
150  * Authentication is used.
151  *
152  * The TPM Asymmetric Device Provisioning protocol is not supported on the MQTT protocol. TPMs can
153  * still be used to securely store and perform HMAC-SHA256 operations for SAS tokens.
154  */
155 
178  az_iot_provisioning_client const* client,
179  uint64_t token_expiration_epoch_time,
180  az_span signature,
181  az_span* out_signature);
182 
211  az_iot_provisioning_client const* client,
212  az_span base64_hmac_sha256_signature,
213  uint64_t token_expiration_epoch_time,
214  az_span key_name,
215  char* mqtt_password,
216  size_t mqtt_password_size,
217  size_t* out_mqtt_password_length);
218 
219 /*
220  *
221  * Register APIs
222  *
223  * Use the following APIs when the Shared Access Key is available to the application or stored
224  * within a Hardware Security Module. The APIs are not necessary if X509 Client Certificate
225  * Authentication is used.
226  */
227 
232 #define AZ_IOT_PROVISIONING_CLIENT_REGISTER_SUBSCRIBE_TOPIC "$dps/registrations/res/#"
233 
239 typedef struct
240 {
246 
251 
256 
261 
266 
271 
276 
281 
283 
288 typedef enum
289 {
298 
299  // Device assignment operation complete.
304 
309 
315 
320 typedef struct
321 {
326 
327  // Avoid using enum as the first field within structs, to allow for { 0 } initialization.
328  // This is a workaround for IAR compiler warning [Pe188]: enumerated type mixed with another type.
329 
336 
341 
346 
353 
371  az_iot_provisioning_client const* client,
372  az_span received_topic,
373  az_span received_payload,
375 
390 {
391  return (operation_status > AZ_IOT_PROVISIONING_STATUS_ASSIGNING);
392 }
393 
416  az_iot_provisioning_client const* client,
417  char* mqtt_topic,
418  size_t mqtt_topic_size,
419  size_t* out_mqtt_topic_length);
420 
443  az_iot_provisioning_client const* client,
444  az_span operation_id,
445  char* mqtt_topic,
446  size_t mqtt_topic_size,
447  size_t* out_mqtt_topic_length);
448 
455 typedef struct
456 {
457  struct
458  {
460  bool unused;
461  } _internal;
463 
474 
505  az_iot_provisioning_client const* client,
506  az_span custom_payload_property,
508  uint8_t* mqtt_payload,
509  size_t mqtt_payload_size,
510  size_t* out_mqtt_payload_length);
511 
543  az_iot_provisioning_client const* client,
544  az_span custom_payload_property,
546  uint8_t* mqtt_payload,
547  size_t mqtt_payload_size,
548  size_t* out_mqtt_payload_length);
549 
550 #include <azure/core/_az_cfg_suffix.h>
551 
552 #endif // _az_IOT_PROVISIONING_CLIENT_H
az_iot_provisioning_client_registration_state
The registration operation state.
Definition: az_iot_provisioning_client.h:240
az_result.h
Definition of az_result and helper functions.
az_iot_provisioning_client_payload_options
Azure IoT Provisioning Client options for az_iot_provisioning_client_get_request_payload() and az_iot...
Definition: az_iot_provisioning_client.h:456
az_iot_provisioning_client_register_get_request_payload
AZ_NODISCARD az_result az_iot_provisioning_client_register_get_request_payload(az_iot_provisioning_client const *client, az_span custom_payload_property, az_iot_provisioning_client_payload_options const *options, uint8_t *mqtt_payload, size_t mqtt_payload_size, size_t *out_mqtt_payload_length)
Builds the optional payload for a provisioning request.
az_iot_provisioning_client_register_response::operation_id
az_span operation_id
Definition: az_iot_provisioning_client.h:325
az_iot_provisioning_client_register_response::operation_status
az_iot_provisioning_client_operation_status operation_status
Definition: az_iot_provisioning_client.h:340
az_iot_provisioning_client_registration_state::error_message
az_span error_message
Definition: az_iot_provisioning_client.h:265
az_iot_provisioning_client_register_response::registration_state
az_iot_provisioning_client_registration_state registration_state
Definition: az_iot_provisioning_client.h:351
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:303
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_get_request_payload
AZ_DEPRECATED AZ_NODISCARD az_result az_iot_provisioning_client_get_request_payload(az_iot_provisioning_client const *client, az_span custom_payload_property, az_iot_provisioning_client_payload_options const *options, uint8_t *mqtt_payload, size_t mqtt_payload_size, size_t *out_mqtt_payload_length)
Builds the optional payload for a provisioning request.
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:260
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:321
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:388
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:275
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:289
AZ_IOT_PROVISIONING_STATUS_UNASSIGNED
@ AZ_IOT_PROVISIONING_STATUS_UNASSIGNED
Definition: az_iot_provisioning_client.h:293
AZ_IOT_PROVISIONING_STATUS_ASSIGNING
@ AZ_IOT_PROVISIONING_STATUS_ASSIGNING
Definition: az_iot_provisioning_client.h:297
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:250
az_iot_provisioning_client_registration_state::payload
az_span payload
Definition: az_iot_provisioning_client.h:280
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:313
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_payload_options_default
AZ_NODISCARD az_iot_provisioning_client_payload_options az_iot_provisioning_client_payload_options_default()
Gets the default az_iot_provisioning_client_payload_options.
AZ_IOT_PROVISIONING_STATUS_FAILED
@ AZ_IOT_PROVISIONING_STATUS_FAILED
Definition: az_iot_provisioning_client.h:308
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:335
az_iot_provisioning_client_registration_state::error_tracking_id
az_span error_tracking_id
Definition: az_iot_provisioning_client.h:270
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:255
az_iot_provisioning_client_payload_options::unused
bool unused
Currently, this is unused, but needed as a placeholder since we can't have an empty struct.
Definition: az_iot_provisioning_client.h:460
az_iot_status
az_iot_status
Azure IoT service status codes.
Definition: az_iot_common.h:78
az_iot_provisioning_client_register_response::retry_after_seconds
uint32_t retry_after_seconds
Definition: az_iot_provisioning_client.h:345
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:245
az_span
Represents a "view" over a byte buffer that represents a contiguous region of memory....
Definition: az_span.h:33