1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | #ifndef PROV_DEVICE_LL_CLIENT_H
|
---|
5 | #define PROV_DEVICE_LL_CLIENT_H
|
---|
6 |
|
---|
7 | #include "umock_c/umock_c_prod.h"
|
---|
8 | #include "azure_macro_utils/macro_utils.h"
|
---|
9 | #include "azure_c_shared_utility/const_defines.h"
|
---|
10 | #include "azure_prov_client/prov_transport.h"
|
---|
11 |
|
---|
12 | #ifdef __cplusplus
|
---|
13 | extern "C" {
|
---|
14 | #endif /* __cplusplus */
|
---|
15 |
|
---|
16 | typedef struct PROV_INSTANCE_INFO_TAG* PROV_DEVICE_LL_HANDLE;
|
---|
17 |
|
---|
18 | #define PROV_DEVICE_RESULT_VALUE \
|
---|
19 | PROV_DEVICE_RESULT_OK, \
|
---|
20 | PROV_DEVICE_RESULT_INVALID_ARG, \
|
---|
21 | PROV_DEVICE_RESULT_SUCCESS, \
|
---|
22 | PROV_DEVICE_RESULT_MEMORY, \
|
---|
23 | PROV_DEVICE_RESULT_PARSING, \
|
---|
24 | PROV_DEVICE_RESULT_TRANSPORT, \
|
---|
25 | PROV_DEVICE_RESULT_INVALID_STATE, \
|
---|
26 | PROV_DEVICE_RESULT_DEV_AUTH_ERROR, \
|
---|
27 | PROV_DEVICE_RESULT_TIMEOUT, \
|
---|
28 | PROV_DEVICE_RESULT_KEY_ERROR, \
|
---|
29 | PROV_DEVICE_RESULT_ERROR, \
|
---|
30 | PROV_DEVICE_RESULT_HUB_NOT_SPECIFIED, \
|
---|
31 | PROV_DEVICE_RESULT_UNAUTHORIZED, \
|
---|
32 | PROV_DEVICE_RESULT_DISABLED
|
---|
33 |
|
---|
34 | MU_DEFINE_ENUM_WITHOUT_INVALID(PROV_DEVICE_RESULT, PROV_DEVICE_RESULT_VALUE);
|
---|
35 |
|
---|
36 | #define PROV_DEVICE_REG_STATUS_VALUES \
|
---|
37 | PROV_DEVICE_REG_STATUS_CONNECTED, \
|
---|
38 | PROV_DEVICE_REG_STATUS_REGISTERING, \
|
---|
39 | PROV_DEVICE_REG_STATUS_ASSIGNING, \
|
---|
40 | PROV_DEVICE_REG_STATUS_ASSIGNED, \
|
---|
41 | PROV_DEVICE_REG_STATUS_ERROR, \
|
---|
42 | PROV_DEVICE_REG_HUB_NOT_SPECIFIED
|
---|
43 |
|
---|
44 | MU_DEFINE_ENUM_WITHOUT_INVALID(PROV_DEVICE_REG_STATUS, PROV_DEVICE_REG_STATUS_VALUES);
|
---|
45 |
|
---|
46 | static STATIC_VAR_UNUSED const char* const PROV_REGISTRATION_ID = "registration_id";
|
---|
47 | static STATIC_VAR_UNUSED const char* const PROV_OPTION_LOG_TRACE = "logtrace";
|
---|
48 | static STATIC_VAR_UNUSED const char* const PROV_OPTION_TIMEOUT = "provisioning_timeout";
|
---|
49 |
|
---|
50 | typedef void(*PROV_DEVICE_CLIENT_REGISTER_DEVICE_CALLBACK)(PROV_DEVICE_RESULT register_result, const char* iothub_uri, const char* device_id, void* user_context);
|
---|
51 | typedef void(*PROV_DEVICE_CLIENT_REGISTER_STATUS_CALLBACK)(PROV_DEVICE_REG_STATUS reg_status, void* user_context);
|
---|
52 |
|
---|
53 | typedef const PROV_DEVICE_TRANSPORT_PROVIDER*(*PROV_DEVICE_TRANSPORT_PROVIDER_FUNCTION)(void);
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * @brief Creates a Provisioning Client for communications with the Device Provisioning Client Service
|
---|
57 | *
|
---|
58 | * @param uri The URI of the Device Provisioning Service
|
---|
59 | * @param scope_id The customer specific Id Scope
|
---|
60 | * @param protocol Function pointer for protocol implementation
|
---|
61 | *
|
---|
62 | * @return A non-NULL PROV_DEVICE_LL_HANDLE value that is used when invoking other functions
|
---|
63 | * and NULL on Failure
|
---|
64 | */
|
---|
65 | MOCKABLE_FUNCTION(, PROV_DEVICE_LL_HANDLE, Prov_Device_LL_Create, const char*, uri, const char*, scope_id, PROV_DEVICE_TRANSPORT_PROVIDER_FUNCTION, protocol);
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * @brief Disposes of resources allocated by the provisioning Client.
|
---|
69 | *
|
---|
70 | * @param handle The handle created by a call to the create function
|
---|
71 | *
|
---|
72 | */
|
---|
73 | MOCKABLE_FUNCTION(, void, Prov_Device_LL_Destroy, PROV_DEVICE_LL_HANDLE, handle);
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * @brief Asynchronous call initiates the registration of a device.
|
---|
77 | *
|
---|
78 | * @param handle The handle created by a call to the create function.
|
---|
79 | * @param register_callback The callback that gets called on registration or if an error is encountered
|
---|
80 | * @param user_context User specified context that will be provided to the callback
|
---|
81 | * @param reg_status_cb An optional registration status callback used to inform the caller of registration status
|
---|
82 | * @param status_user_ctext User specified context that will be provided to the registration status callback
|
---|
83 | *
|
---|
84 | * @return PROV_DEVICE_RESULT_OK upon success or an error code upon failure
|
---|
85 | */
|
---|
86 | MOCKABLE_FUNCTION(, PROV_DEVICE_RESULT, Prov_Device_LL_Register_Device, PROV_DEVICE_LL_HANDLE, handle, PROV_DEVICE_CLIENT_REGISTER_DEVICE_CALLBACK, register_callback, void*, user_context, PROV_DEVICE_CLIENT_REGISTER_STATUS_CALLBACK, reg_status_cb, void*, status_user_ctext);
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * @brief Api to be called by user when work (registering device) can be done
|
---|
90 | *
|
---|
91 | * @param handle The handle created by a call to the create function.
|
---|
92 | *
|
---|
93 | */
|
---|
94 | MOCKABLE_FUNCTION(, void, Prov_Device_LL_DoWork, PROV_DEVICE_LL_HANDLE, handle);
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * @brief API sets a runtime option identified by parameter optionName to a value pointed to by value
|
---|
98 | *
|
---|
99 | * @param handle The handle created by a call to the create function.
|
---|
100 | * @param optionName The name of the option to be set
|
---|
101 | * @param value A pointer to the value of the option to be set
|
---|
102 | *
|
---|
103 | * @return PROV_DEVICE_RESULT_OK upon success or an error code upon failure
|
---|
104 | */
|
---|
105 | MOCKABLE_FUNCTION(, PROV_DEVICE_RESULT, Prov_Device_LL_SetOption, PROV_DEVICE_LL_HANDLE, handle, const char*, optionName, const void*, value);
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * @brief API to get the version of the provisioning client
|
---|
109 | *
|
---|
110 | * @return The version number of the provisioning client
|
---|
111 | */
|
---|
112 | MOCKABLE_FUNCTION(, const char*, Prov_Device_LL_GetVersionString);
|
---|
113 |
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * @brief Sets the Provisioning Data that is sent to the Provisioning service
|
---|
117 | *
|
---|
118 | * @param handle The handle created by a call to the create function.
|
---|
119 | * @param json The data field that is sent to the service. Setting json to NULL will unset the value previously set
|
---|
120 | *
|
---|
121 | * @return PROV_DEVICE_RESULT_OK upon success or an error code upon failure
|
---|
122 | */
|
---|
123 | MOCKABLE_FUNCTION(, PROV_DEVICE_RESULT, Prov_Device_LL_Set_Provisioning_Payload, PROV_DEVICE_LL_HANDLE, handle, const char*, json);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * @brief Retrieves the Provisioning Data that is sent from the Provisioning service
|
---|
127 | *
|
---|
128 | * @param handle The handle created by a call to the create function.
|
---|
129 | *
|
---|
130 | * @return The data that was specified by the service
|
---|
131 | */
|
---|
132 | MOCKABLE_FUNCTION(, const char*, Prov_Device_LL_Get_Provisioning_Payload, PROV_DEVICE_LL_HANDLE, handle);
|
---|
133 |
|
---|
134 | #ifdef __cplusplus
|
---|
135 | }
|
---|
136 | #endif /* __cplusplus */
|
---|
137 |
|
---|
138 | #endif // PROV_DEVICE_LL_CLIENT_H
|
---|