Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / provisioningmanager.h
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * *****************************************************************/
20
21 #ifndef SP_PROVISION_API_H
22 #define SP_PROVISION_API_H
23
24 #include "ocstack.h"
25 #include "securevirtualresourcetypes.h"
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 /**
33  * Error Code.
34  */
35 typedef enum
36 {
37     SP_RESULT_SUCCESS = 0,
38     SP_RESULT_INVALID_PARAM,
39     SP_RESULT_MEM_ALLOCATION_FAIL,
40     SP_RESULT_INTERNAL_ERROR,
41     SP_RESULT_TIMEOUT,
42     SP_RESULT_CONN_INVALID_PARAM,
43     SP_RESULT_CONN_ADAPTER_NOT_ENABLED,
44     SP_RESULT_CONN_SERVER_STARTED_ALREADY,
45     SP_RESULT_CONN_SERVER_NOT_STARTED,
46     SP_RESULT_CONN_DESTINATION_NOT_REACHABLE,
47     SP_RESULT_CONN_SOCKET_OPERATION_FAILED,
48     SP_RESULT_CONN_SEND_FAILED,
49     SP_RESULT_CONN_RECEIVE_FAILED,
50     SP_RESULT_CONN_MEMORY_ALLOC_FAILED,
51     SP_RESULT_CONN_REQUEST_TIMEOUT,
52     SP_RESULT_CONN_DESTINATION_DISCONNECTED,
53     SP_RESULT_CONN_STATUS_FAILED,
54     SP_RESULT_CONN_NOT_SUPPORTED
55
56 } SPResult;
57
58 typedef struct SPTargetDeviceInfo SPTargetDeviceInfo_t;
59 typedef struct SPDevInfo SPDevInfo_t;
60
61 /**
62  * Device Info structure.
63  */
64 struct SPTargetDeviceInfo
65 {
66     OCDevAddr endpoint;             /**< target address **/
67     OicSecPstat_t *pstat;           /**< Pointer to target's pstat resource. **/
68     OicSecDoxm_t *doxm;             /**< Pointer to target's doxm resource. **/
69     uint16_t securePort;            /**< Secure port **/
70     SPTargetDeviceInfo_t *next;     /**< Next pointer. **/
71 };
72
73 /**
74  * Owned target device info
75  */
76 struct SPDevInfo
77 {
78     OCDevAddr endpoint;             /**< target address **/
79     OicUuid_t deviceId;             /**< Device ID. **/
80     SPDevInfo_t *next;              /**< Next pointer. **/
81 };
82
83 /**
84  * The function is responsible for discovery of device is current subnet. It will list
85  * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
86  * OCMode.
87  *
88  * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
89  *                    client before returning the list of devices.
90  * @param[out] list List of provision candidate devices.
91  * @return SP_SUCCESS in case of success and other value otherwise.
92  */
93 SPResult SPProvisioningDiscovery(unsigned short timeout,
94                                  SPTargetDeviceInfo_t **list);
95
96 /**
97  * The function is reponsible for following activities:
98  * - Send post to /oic/sec/doxm resource with selected ownership transfer method
99  * - Get pstat resource of target device to enumerate supported operation modes.
100  * - Select and let the target device know the selected methods.
101  * - Initiate anon handshake and save owner PSK
102  * - Update doxm resource of target device with ownership info.
103  *
104  * @param[in] timeout  Timeout value in secs till which call REST request will wait before
105  *                     returning error in case of 0 function will wait till success.
106  * @param[in] selectedDeviceInfo Device information.
107  * @return SP_SUCCESS in case of success and other value otherwise.
108  */
109 SPResult SPInitProvisionContext(unsigned short timeout,
110                                 SPTargetDeviceInfo_t *selectedDeviceInfo);
111
112 /**
113  * Function to send ACL information to resource.
114  *
115  * @param[in] timeout Timeout value in secs till which call to REST request will wait before
116  *                     returning error in case of 0 function will wait till success.
117  * @param[in] selectedDeviceInfo Selected target device.
118  * @param[in] acl ACL to provision
119  * @return  SP_SUCCESS in case of success and other value otherwise.
120  */
121 SPResult SPProvisionACL(unsigned short timeout, const SPTargetDeviceInfo_t *selectedDeviceInfo,
122                         OicSecAcl_t *acl);
123
124 /**
125  * Function to send credential information to list of resources.
126  *
127  * @param[in] timeout Timeout value in secs till which call to REST request will wait before
128  *                    returning error in case of 0 function will wait till success.
129  * @param[in] type Type of credentials to be provisioned to the device.
130  * @param[in] pDevList List of devices to be provisioned with the specified credential.
131  *
132  * @return  SP_SUCCESS in case of success and other value otherwise.
133  */
134 SPResult SPProvisionCredentials(unsigned short timeout, OicSecCredType_t type,
135                                 const SPDevInfo_t *pDevList);
136
137 /**
138  * Function to confirm the ACL post request to check  whether its updated at
139  * resource server end properly or not.
140  *
141  * @param[in] timeout Timeout value in seconds till which call REST request will wait
142  *                     before returning error in case of 0 function will wait till success.
143  * @param[in] context Provisioning context
144  * @return  SP_SUCCESS on success
145  */
146 SPResult SPFinalizeProvisioning(unsigned short timeout,
147                                 SPTargetDeviceInfo_t *selectedDeviceInfo);
148
149 /**
150  * Function to end Provisioning session.
151  *
152  * @return  SP_SUCCESS on success
153  */
154 SPResult SPTerminateProvisioning();
155
156 #ifdef __cplusplus
157 }
158 #endif
159 #endif //SP_PROVISION_API_H