Merge tizen_5.0 codes into tizen_4.0
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / internal / ownershiptransfermanager.h
1 /* *****************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\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
10  *\r
11  *     http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
18  *\r
19  * *****************************************************************/\r
20 \r
21 #ifndef OTM_OWNERSHIPTRANSFERMANAGER_H_\r
22 #define OTM_OWNERSHIPTRANSFERMANAGER_H_\r
23 \r
24 #include "pmtypes.h"\r
25 #include "ocstack.h"\r
26 #include "octypes.h"\r
27 #include "securevirtualresourcetypes.h"\r
28 \r
29 #ifdef __cplusplus\r
30 extern "C" {\r
31 #endif // __cplusplus\r
32 \r
33 #define OXM_STRING_MAX_LENGTH 32\r
34 #define WRONG_PIN_MAX_ATTEMP 1\r
35 \r
36 typedef struct OTMCallbackData OTMCallbackData_t;\r
37 typedef struct OTMContext OTMContext_t;\r
38 \r
39 /**\r
40  * Do ownership transfer for the unowned devices.\r
41  *\r
42  * @param[in] ctx Application context would be returned in result callback\r
43  * @param[in] selectedDeviceList linked list of ownership transfer candidate devices.\r
44  * @param[in] resultCB Result callback function to be invoked when ownership transfer finished.\r
45  * @return OC_STACK_OK in case of success and other value otherwise.\r
46  */\r
47 OCStackResult OTMDoOwnershipTransfer(void* ctx,\r
48                                      OCProvisionDev_t* selectedDeviceList, OCProvisionResultCB resultCB);\r
49 \r
50 OCStackResult OTMDoCustomOwnershipTransfer(void* ctx,\r
51                                      OCProvisionDev_t* selectedDeviceList, OCProvisionResultCB resultCB,\r
52                                      const OicSecOxm_t method);\r
53 \r
54 /**\r
55  * API to set a allow status of OxM\r
56  *\r
57  * @param[in] oxm Owership transfer method (ref. OicSecOxm_t)\r
58  * @param[in] allowStatus allow status (true = allow, false = not allow)\r
59  *\r
60  * @return OC_STACK_OK in case of success and other value otherwise.\r
61  */\r
62 OCStackResult OTMSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus);\r
63 \r
64 \r
65 /*\r
66  *Callback for load secret for temporal secure session\r
67  *\r
68  * e.g) in case of PIN based, input the pin through this callback\r
69  *       in case of X.509 based, input the certificate through this callback\r
70  */\r
71 typedef OCStackResult (*OTMLoadSecret)(OTMContext_t* otmCtx);\r
72 \r
73 /*\r
74  * Callback for create secure channel using secret inputed from OTMLoadSecret callback\r
75  */\r
76 typedef OCStackResult (*OTMCreateSecureSession)(OTMContext_t* otmCtx);\r
77 \r
78 /*\r
79  * Callback for creating CoAP payload.\r
80  */\r
81 typedef OCStackResult (*OTMCreatePayloadCallback)(OTMContext_t* otmCtx, uint8_t **payload,\r
82                                                   size_t *size);\r
83 \r
84 /*\r
85  * Callback for selecting OTM.\r
86  */\r
87 typedef OicSecOxm_t (*OTMSelectMethodCallback)(const OicSecOxm_t* otmList, const uint32_t len);\r
88 \r
89 /**\r
90  * Required callback for performing ownership transfer\r
91  */\r
92 struct OTMCallbackData\r
93 {\r
94     OTMLoadSecret loadSecretCB;\r
95     OTMCreateSecureSession createSecureSessionCB;\r
96     OTMCreatePayloadCallback createSelectOxmPayloadCB;\r
97     OTMCreatePayloadCallback createOwnerTransferPayloadCB;\r
98     OTMSelectMethodCallback selectOTMCB;\r
99 };\r
100 \r
101 /**\r
102  * Context for ownership transfer(OT)\r
103  */\r
104 struct OTMContext{\r
105     void* userCtx;                            /**< Context for user.*/\r
106     OCProvisionDev_t* selectedDeviceInfo;     /**< Selected device info for OT. */\r
107     OicUuid_t subIdForPinOxm;                 /**< Subject Id which uses PIN based OTM. */\r
108     OCProvisionResultCB ctxResultCallback;    /**< Function pointer to store result callback. */\r
109     OCProvisionResult_t* ctxResultArray;      /**< Result array having result of all device. */\r
110     size_t ctxResultArraySize;                /**< No of elements in result array. */\r
111     bool ctxHasError;                         /**< Does OT process have any error. */\r
112     OCDoHandle ocDoHandle;                    /** <A handle for latest request message*/\r
113     OTMCallbackData_t otmCallback; /**< OTM callbacks to perform the OT/MOT. **/\r
114     int attemptCnt;\r
115 };\r
116 \r
117 // TODO: Remove this OTMSetOwnershipTransferCallbackData, Please see the jira ticket IOT-1484\r
118 /**\r
119  * Set the callbacks for ownership transfer\r
120  *\r
121  * @param[in] oxm Ownership transfer method\r
122  * @param[in] callbackData the implementation of the ownership transfer function for each step.\r
123  * @return OC_STACK_OK in case of success and other value otherwise.\r
124  */\r
125 OCStackResult OTMSetOwnershipTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData);\r
126 \r
127 /**\r
128  * API to assign the OTMCallback for each OxM.\r
129  *\r
130  * @param[out] callbacks Instance of OTMCallback_t\r
131  * @param[in] oxm Ownership transfer method\r
132  * @return  OC_STACK_OK on success\r
133  */\r
134 OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks);\r
135 \r
136 /**\r
137  * Function to save the result of provisioning.\r
138  *\r
139  * @param[in,out] otmCtx   Context value of ownership transfer.\r
140  * @param[in] res   result of provisioning\r
141  */\r
142 void SetResult(OTMContext_t* otmCtx, const OCStackResult res);\r
143 \r
144 /**\r
145  * Function to select appropriate security provisioning method.\r
146  *\r
147  * @param[in] supportedMethods   Array of supported methods\r
148  * @param[in] numberOfMethods   number of supported methods\r
149  * @param[out]  selectedMethod         Selected methods\r
150  * @param[in] ownerType type of owner device (SUPER_OWNER or SUB_OWNER)\r
151  * @return  OC_STACK_OK on success\r
152  */\r
153 OCStackResult OTMSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethods,\r
154         size_t numberOfMethods, OicSecOxm_t *selectedMethod, OwnerType_t ownerType);\r
155 \r
156 /**\r
157  * This function configures SVR DB as self-ownership.\r
158  *\r
159  *@return OC_STACK_OK in case of successful configue and other value otherwise.\r
160  */\r
161 OCStackResult ConfigSelfOwnership(void);\r
162 \r
163 /**\r
164  * API to terminate the OTM process when terminating OCStack\r
165  */\r
166 void OTMTerminate();\r
167 \r
168 #ifdef __cplusplus\r
169 }\r
170 #endif\r
171 #endif //OTM_OWNERSHIPTRANSFERMANAGER_H_\r