28 #ifndef AWS_IOT_PROVISIONING_INTERNAL_H_ 29 #define AWS_IOT_PROVISIONING_INTERNAL_H_ 32 #include "iot_config.h" 41 #include "iot_serializer.h" 52 #if AWS_IOT_PROVISIONING_ENABLE_ASSERTS == 1 53 #ifndef AwsIotProvisioning_Assert 54 #ifdef Iot_DefaultAssert 55 #define AwsIotProvisioning_Assert( expression ) Iot_DefaultAssert( expression ) 57 #error "Asserts are enabled for MQTT, but AwsIotProvisioning_Assert is not defined" 61 #define AwsIotProvisioning_Assert( expression ) 65 #ifdef AWS_IOT_LOG_LEVEL_PROVISIONING 66 #define LIBRARY_LOG_LEVEL AWS_IOT_LOG_LEVEL_PROVISIONING 68 #ifdef IOT_LOG_LEVEL_GLOBAL 69 #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_GLOBAL 71 #define LIBRARY_LOG_LEVEL IOT_LOG_NONE 75 #define LIBRARY_LOG_NAME ( "Provisioning" ) 82 #define CREATE_KEYS_AND_CERTIFICATE_OPERATION_LOG "CREATE KEYS AND CERTIFICATE" 83 #define CREATE_CERT_FROM_CSR_OPERATION_LOG "CREATE CERTIFICATE FROM CSR" 84 #define REGISTER_THING_OPERATION_LOG "REGISTER DEVICE" 94 #ifndef AWS_IOT_PROVISIONING_FORMAT 95 #define AWS_IOT_PROVISIONING_FORMAT AWS_IOT_PROVISIONING_FORMAT_CBOR 99 #if AWS_IOT_PROVISIONING_FORMAT == AWS_IOT_PROVISIONING_FORMAT_JSON 100 #error "AWS_IOT_PROVISIONING_FORMAT_JSON is not supported." 106 #if AWS_IOT_PROVISIONING_FORMAT == AWS_IOT_PROVISIONING_FORMAT_CBOR 107 #define PROVISIONING_FORMAT "cbor" 109 #error "AWS_IOT_PROVISIONING_FORMAT must be AWS_IOT_PROVISIONING_FORMAT_CBOR." 116 #if IOT_STATIC_MEMORY_ONLY == 1 124 #define AwsIotProvisioning_MallocPayload Iot_MallocMessageBuffer 130 #define AwsIotProvisioning_FreePayload Iot_FreeMessageBuffer 138 #define AwsIotProvisioning_MallocString Iot_MallocMessageBuffer 145 #define AwsIotProvisioning_FreeString Iot_FreeMessageBuffer 153 #define AwsIotProvisioning_MallocDeviceConfigurationList Iot_MallocMessageBuffer 160 #define AwsIotProvisioning_FreeDeviceConfigurationList Iot_FreeMessageBuffer 164 #ifndef AwsIotProvisioning_MallocPayload 165 #ifdef Iot_DefaultMalloc 166 #define AwsIotProvisioning_MallocPayload Iot_DefaultMalloc 168 #error "No malloc function defined for AwsIotProvisioning_MallocPayload" 172 #ifndef AwsIotProvisioning_FreePayload 173 #ifdef Iot_DefaultFree 174 #define AwsIotProvisioning_FreePayload Iot_DefaultFree 176 #error "No Free function defined for AwsIotProvisioning_FreePayload" 180 #ifndef AwsIotProvisioning_MallocString 181 #ifdef Iot_DefaultMalloc 182 #define AwsIotProvisioning_MallocString Iot_DefaultMalloc 184 #error "No malloc function defined for AwsIotProvisioning_MallocString" 188 #ifndef AwsIotProvisioning_FreeString 189 #ifdef Iot_DefaultFree 190 #define AwsIotProvisioning_FreeString Iot_DefaultFree 192 #error "No Free function defined for AwsIotProvisioning_FreeString" 196 #ifndef AwsIotProvisioning_MallocDeviceConfigurationList 197 #ifdef Iot_DefaultMalloc 198 #define AwsIotProvisioning_MallocDeviceConfigurationList Iot_DefaultMalloc 200 #error "No malloc function defined for AwsIotProvisioning_MallocDeviceConfigurationList" 204 #ifndef AwsIotProvisioning_FreeDeviceConfigurationList 205 #ifdef Iot_DefaultFree 206 #define AwsIotProvisioning_FreeDeviceConfigurationList Iot_DefaultFree 208 #error "No Free function defined for AwsIotProvisioning_FreeDeviceConfigurationList" 220 #ifndef AWS_IOT_PROVISIONING_DEFAULT_MQTT_TIMEOUT_MS 221 #define AWS_IOT_PROVISIONING_DEFAULT_MQTT_TIMEOUT_MS ( 5000 ) 231 #define PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_RESPONSE_TOPIC_FILTER \ 232 "$aws/certificates/create/"PROVISIONING_FORMAT 237 #define PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_RESPONSE_TOPIC_FILTER_LENGTH \ 238 ( ( uint16_t ) ( sizeof( PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_RESPONSE_TOPIC_FILTER ) - 1 ) ) 244 #define PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_RESPONSE_MAX_TOPIC_LENGTH \ 245 ( PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_RESPONSE_TOPIC_FILTER_LENGTH + sizeof( AWS_IOT_REJECTED_SUFFIX ) ) 252 #define PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_REQUEST_TOPIC \ 253 "$aws/certificates/create/"PROVISIONING_FORMAT 258 #define PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_REQUEST_TOPIC_LENGTH \ 259 ( ( uint16_t ) ( sizeof( PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_REQUEST_TOPIC ) - 1 ) ) 267 #define PROVISIONING_CREATE_CERT_FROM_CSR_RESPONSE_TOPIC_FILTER \ 268 "$aws/certificates/create-from-csr/"PROVISIONING_FORMAT 273 #define PROVISIONING_CREATE_CERT_FROM_CSR_RESPONSE_TOPIC_FILTER_LENGTH \ 274 ( ( uint16_t ) ( sizeof( PROVISIONING_CREATE_CERT_FROM_CSR_RESPONSE_TOPIC_FILTER ) - 1 ) ) 280 #define PROVISIONING_CREATE_CERT_FROM_CSR_RESPONSE_MAX_TOPIC_LENGTH \ 281 ( PROVISIONING_CREATE_CERT_FROM_CSR_RESPONSE_TOPIC_FILTER_LENGTH + sizeof( AWS_IOT_REJECTED_SUFFIX ) ) 288 #define PROVISIONING_CREATE_CERT_FROM_CSR_REQUEST_TOPIC \ 289 "$aws/certificates/create-from-csr/"PROVISIONING_FORMAT 294 #define PROVISIONING_CREATE_CERT_FROM_CSR_REQUEST_TOPIC_LENGTH \ 295 ( ( uint16_t ) ( sizeof( PROVISIONING_CREATE_CERT_FROM_CSR_REQUEST_TOPIC ) - 1 ) ) 301 #define PROVISIONING_CREATE_CERT_FROM_CSR_REQUEST_PAYLOAD_PEM_STRING "certificateSigningRequest" 307 #define PROVISIONING_SERVER_RESPONSE_PAYLOAD_CERTIFICATE_PEM_STRING "certificatePem" 313 #define PROVISIONING_SERVER_RESPONSE_PAYLOAD_CERTIFICATE_ID_STRING "certificateId" 319 #define PROVISIONING_CREATE_KEYS_AND_CERTIFICATE_RESPONSE_PAYLOAD_PRIVATE_KEY_STRING "privateKey" 325 #define PROVISIONING_SERVER_RESPONSE_PAYLOAD_CERTIFICATE_TOKEN_KEY_STRING "certificateOwnershipToken" 330 #define PROVISIONING_REGISTER_THING_TOPICS_COMMON_PREFIX \ 331 "$aws/provisioning-templates/" 337 #define PROVISIONING_REGISTER_THING_TOPICS_COMMON_PREFIX_LENGTH \ 338 ( ( uint16_t ) ( sizeof( PROVISIONING_REGISTER_THING_TOPICS_COMMON_PREFIX ) - 1 ) ) 344 #define PROVISIONING_MAX_TEMPLATE_NAME_LENGTH ( 36 ) 349 #define PROVISIONING_REGISTER_THING_TOPICS_COMMON_SUFFIX "/provision/"PROVISIONING_FORMAT 354 #define PROVISIONING_REGISTER_THING_TOPICS_COMMON_SUFFIX_LENGTH \ 355 ( ( uint16_t ) ( sizeof( PROVISIONING_REGISTER_THING_TOPICS_COMMON_SUFFIX ) - 1 ) ) 361 #define PROVISIONING_REGISTER_THING_REQUEST_TOPIC_LENGTH \ 362 ( PROVISIONING_REGISTER_THING_TOPICS_COMMON_PREFIX_LENGTH + PROVISIONING_MAX_TEMPLATE_NAME_LENGTH + \ 363 PROVISIONING_REGISTER_THING_TOPICS_COMMON_SUFFIX_LENGTH ) 372 #define PROVISIONING_REGISTER_THING_REQUEST_PAYLOAD_CERTIFICATE_ID_STRING "certificateId" 380 #define PROVISIONING_REGISTER_THING_REQUEST_PAYLOAD_CERTIFICATE_TOKEN_STRING "certificateOwnershipToken" 389 #define PROVISIONING_REGISTER_THING_REQUEST_PAYLOAD_PARAMETERS_STRING "parameters" 394 #define PROVISIONING_REGISTER_THING_RESPONSE_TOPIC_FILTER_LENGTH \ 395 ( PROVISIONING_REGISTER_THING_TOPICS_COMMON_PREFIX_LENGTH + PROVISIONING_MAX_TEMPLATE_NAME_LENGTH + \ 396 PROVISIONING_REGISTER_THING_TOPICS_COMMON_SUFFIX_LENGTH ) 402 #define PROVISIONING_REGISTER_THING_RESPONSE_MAX_TOPIC_LENGTH \ 403 ( PROVISIONING_REGISTER_THING_RESPONSE_TOPIC_FILTER_LENGTH + sizeof( AWS_IOT_REJECTED_SUFFIX ) ) 411 #define PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_DEVICE_CONFIGURATION_STRING "deviceConfiguration" 419 #define PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_THING_NAME_STRING "thingName" 426 #define PROVISIONING_REJECTED_RESPONSE_STATUS_CODE_STRING "statusCode" 433 #define PROVISIONING_REJECTED_RESPONSE_ERROR_CODE_STRING "errorCode" 440 #define PROVISIONING_REJECTED_RESPONSE_ERROR_MESSAGE_STRING "errorMessage" 447 typedef enum _provisioningOperationType
461 typedef union _provisioningCallbackInfo
483 const uint8_t * responsePayload,
484 size_t responsePayloadLength,
490 typedef struct _provisioningOperationInfo
500 typedef struct _provisioningOperation
534 size_t templateNameLength,
535 char * pTopicFilterBuffer );
549 const uint8_t * pResponsePayload,
550 size_t payloadLength,
568 const uint8_t * pResponsePayload,
569 size_t payloadLength,
584 const uint8_t * pResponsePayload,
585 size_t responsePayloadLength,
599 size_t * pBufferSize );
618 size_t * pPayloadSize );
633 uint8_t * pSerializationBuffer,
634 size_t pBufferSize );
650 uint8_t ** pSerializationBuffer,
651 size_t * pBufferSize );
AwsIotProvisioningError_t(* _provisioningServerResponseParser)(AwsIotStatus_t responseType, const uint8_t *responsePayload, size_t responsePayloadLength, const _provisioningCallbackInfo_t *userCallback)
Functor for parsing response payload received from AWS IoT Core. Parser that will de-serialize the se...
Definition: aws_iot_provisioning_internal.h:482
AwsIotProvisioningError_t _AwsIotProvisioning_ParseKeysAndCertificateResponse(AwsIotStatus_t responseType, const uint8_t *pResponsePayload, size_t payloadLength, const _provisioningCallbackInfo_t *userCallbackInfo)
Parses the response received from the server for device credentials, and invokes the provided user-ca...
Definition: aws_iot_provisioning_parser.c:312
AwsIotProvisioningError_t _AwsIotProvisioning_SerializeCreateCertFromCsrRequestPayload(const char *pCertificateSigningRequest, size_t csrLength, uint8_t *pSerializationBuffer, size_t pBufferSize)
Serializes payload data for the request to the MQTT CreateCertificateFromCsr service API...
Definition: aws_iot_provisioning_serializer.c:527
AwsIotProvisioningError_t
Return codes of Provisioning functions.
Definition: aws_iot_provisioning_types.h:54
AwsIotProvisioningRegisterThingCallbackInfo_t registerThingCallback
The user-callback passed to AwsIotProvisioning_RegisterThing.
Definition: aws_iot_provisioning_internal.h:470
_provisioningOperationType_t
Enumerations representing each of the Provisioning library's API functions.
Definition: aws_iot_provisioning_internal.h:447
AwsIotProvisioningError_t _AwsIotProvisioning_ParseRegisterThingResponse(AwsIotStatus_t responseType, const uint8_t *pResponsePayload, size_t responsePayloadLength, const _provisioningCallbackInfo_t *userCallbackInfo)
Parses the response payload received from the server for device provisioning, and invokes the provide...
Definition: aws_iot_provisioning_parser.c:554
const IotSerializerDecodeInterface_t * _pAwsIotProvisioningDecoder
Pointer to the decoder utility that will be used for de-serialization of payload data in the library...
Definition: aws_iot_provisioning_api.c:72
uint32_t _AwsIotProvisioningMqttTimeoutMs
Timeout for MQTT operations that will be used for communicating with the fleet provisioning APIs of t...
Definition: aws_iot_provisioning_api.c:105
User-specific callback information for handling server response for the Provisioning CreateKeysAndCer...
Definition: aws_iot_provisioning_types.h:424
Union representing either of the 2 Provisioning operation APIs' callbacks.
Definition: aws_iot_provisioning_internal.h:461
const IotSerializerEncodeInterface_t * _pAwsIotProvisioningEncoder
Pointer to the encoder utility that will be used for serialization of payload data in the library...
Definition: aws_iot_provisioning_api.c:66
User-specific callback information for handling server response for the Provisioning RegisterThing se...
Definition: aws_iot_provisioning_types.h:498
AwsIotProvisioningError_t _AwsIotProvisioning_SerializeCreateKeysAndCertificateRequestPayload(uint8_t **pSerializationBuffer, size_t *pBufferSize)
Serializes payload data for MQTT request to the Fleet Provisioning CreateKeysAndCertificate API on AW...
Definition: aws_iot_provisioning_serializer.c:359
AwsIotProvisioningError_t _AwsIotProvisioning_CalculateCertFromCsrPayloadSize(const char *pCertificateSigningRequest, size_t csrLength, size_t *pPayloadSize)
Calculates the payload size of serializing the passed Certificate-Signing Request data for the MQTT C...
Definition: aws_iot_provisioning_serializer.c:480
_provisioningCallbackInfo_t userCallback
User-provided callback to be called on receiving a response from the server.
Definition: aws_iot_provisioning_internal.h:493
IotSemaphore_t responseReceivedSem
Binary sempahore used for notifying arrival of server response in the synchronous API functions AwsIo...
Definition: aws_iot_provisioning_internal.h:506
AwsIotProvisioningError_t _AwsIotProvisioning_SerializeRegisterThingRequestPayload(const AwsIotProvisioningRegisterThingRequestInfo_t *pRequestData, uint8_t **pSerializationBuffer, size_t *pBufferSize)
Serializes payload data for MQTT request to the Provisioning RegisterThing service API...
Definition: aws_iot_provisioning_serializer.c:567
Definition: aws_iot_provisioning_internal.h:449
Internal structure representing a single Provisioning operation.
Definition: aws_iot_provisioning_internal.h:500
Definition: aws_iot_provisioning_internal.h:450
_provisioningOperationInfo_t info
The Provisioning operation object.
Definition: aws_iot_provisioning_internal.h:502
User-facing functions of the Provisioning library.
size_t _AwsIotProvisioning_GenerateRegisterThingTopicFilter(const char *pTemplateName, size_t templateNameLength, char *pTopicFilterBuffer)
Utility for generating the request/response MQTT topic filter string for the ProvisioningDevice servi...
Definition: aws_iot_provisioning_serializer.c:606
uint32_t semReferenceCount
An atomic reference counter for safeguarding semaphore access across thread contexts.
Definition: aws_iot_provisioning_internal.h:503
AwsIotProvisioningError_t status
Status of operation.
Definition: aws_iot_provisioning_internal.h:492
AwsIotProvisioningCreateCertFromCsrCallbackInfo_t createCertFromCsrCallback
The user-callback passed to AwsIotProvisioning_CreateCertificateFromCsr.
Definition: aws_iot_provisioning_internal.h:467
Internal structure representing the data of an Provisioning operation.
Definition: aws_iot_provisioning_internal.h:490
AwsIotProvisioningError_t _AwsIotProvisioning_ParseCsrResponse(AwsIotStatus_t responseType, const uint8_t *pResponsePayload, size_t payloadLength, const _provisioningCallbackInfo_t *userCallbackInfo)
Parses the response from the server received on a Certificate-Signing Request, and invokes the provid...
Definition: aws_iot_provisioning_parser.c:441
AwsIotProvisioningCreateKeysAndCertificateCallbackInfo_t createKeysAndCertificateCallback
The user-callback passed to AwsIotProvisioning_CreateKeysAndCertificate.
Definition: aws_iot_provisioning_internal.h:464
Aggregates information required for sending a request to the AWS IoT Core service for provisioning a ...
Definition: aws_iot_provisioning_types.h:238
User-specific callback information for handling server response of the Provisioning CreateCertificate...
Definition: aws_iot_provisioning_types.h:348