1 //****************************************************************
\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
7 // Licensed under the Apache License, Version 2.0 (the "License");
\r
8 // you may not use this file except in compliance with the License.
\r
9 // You may obtain a copy of the License at
\r
11 // http://www.apache.org/licenses/LICENSE-2.0
\r
13 // Unless required by applicable law or agreed to in writing, software
\r
14 // distributed under the License is distributed on an "AS IS" BASIS,
\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 // See the License for the specific language governing permissions and
\r
17 // limitations under the License.
\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
21 #ifndef OC_CLOUD_PROVISIONING_CXX_H_
\r
22 #define OC_CLOUD_PROVISIONING_CXX_H_
\r
27 #include "occloudprovisioning.h"
\r
29 #include "../csdk/security/provisioning/include/cloud/occloudprovisioning.h"
\r
32 #include "OCPlatform_impl.h"
\r
33 #include "CAManager.h"
\r
37 typedef std::function<void(OCStackResult result, void *data)> ResponseCallBack;
\r
38 typedef std::function<void(OCStackResult result, std::string aclId)> AclIdResponseCallBack;
\r
41 * Context to be passed to the underlying stack. This is passed back as argument
\r
42 * to the callback function
\r
44 struct CloudProvisionContext
\r
46 ResponseCallBack callback;
\r
47 CloudProvisionContext(ResponseCallBack cb) : callback(cb){}
\r
52 AclIdResponseCallBack callback;
\r
53 AclIdContext(AclIdResponseCallBack cb) : callback(cb){}
\r
56 class OCCloudProvisioning
\r
60 OCDevAddr m_devAddr;
\r
64 * API to construct the CloudProvisioning
\r
65 * @param ipAddr address of the cloud server
\r
66 * @param port port of the cloud server
\r
68 OCCloudProvisioning(std::string& ipAddr, uint16_t port);
\r
69 ~OCCloudProvisioning();
\r
71 void setIpAddr(std::string& ipAddr)
\r
73 memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);
\r
76 void setPort(uint16_t port)
\r
78 m_devAddr.port = port;
\r
82 * API to Request a certificate from the cloud
\r
83 * @param callback function called by the stack on completion of request
\r
84 * @return ::OC_STACK_OK on Success and other values otherwise
\r
86 OCStackResult requestCertificate(ResponseCallBack callback);
\r
89 * API to get ACL ID for the device
\r
90 * @param deviceId device ID for which the Acl ID is requested
\r
91 * @param callback function called by the stack on completion of request
\r
92 * @return ::OC_STACK_OK on Success and other values otherwise
\r
94 OCStackResult getAclIdByDevice(const std::string& deviceId, AclIdResponseCallBack callback);
\r
97 * API to get ACL information about the given Acl ID
\r
98 * @param aclId ACL ID for which the Acl information is requested
\r
99 * @param callback function called by the stack on completion of request
\r
100 * @return ::OC_STACK_OK on Success and other values otherwise
\r
102 OCStackResult getIndividualAclInfo(const std::string& aclId, ResponseCallBack callback);
\r
105 * API to get certificate revocation list
\r
106 * @param callback function called by the stack on completion of request
\r
107 * @return ::OC_STACK_OK on Success and other values otherwise
\r
109 OCStackResult getCRL(ResponseCallBack callback);
\r
112 * API to post the certificate revocation list to cloud
\r
113 * @param thisUpdate thisUpdate [mandatory param]
\r
114 * @param nextUpdate nextUpdate [mandatory param]
\r
115 * @param crl revocation list [optional]
\r
116 * @param serialNumbers [optional]
\r
117 * @param callback function called by the stack on completion of request
\r
118 * @return ::OC_STACK_OK on Success and other values otherwise
\r
120 OCStackResult postCRL(const std::string& thisUpdate,
\r
121 const std::string& nextUpdate,
\r
122 const OCByteString *crl,
\r
123 const stringArray_t *serialNumbers,
\r
124 ResponseCallBack callback);
\r
127 * Common callback wrapper for all the callback functions.
\r
128 * @param ctx user context passed to the request API
\r
129 * @param result result of the request performed
\r
130 * @param data response data
\r
132 static void callbackWrapper(void* ctx, OCStackResult result, void* data);
\r
135 * Callback wrapper for Acl ID get request
\r
136 * @param ctx user context passed to the request API
\r
137 * @param result result of the request performed
\r
138 * @param data AclID for the device
\r
140 static void aclIdResponseWrapper(void* ctx, OCStackResult result, void* data);
\r
143 #endif //OC_CLOUD_PROVISIONING_CXX_H_
\r