replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / pmutility.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 _PM_UTILITY_H_
22 #define _PM_UTILITY_H_
23
24 #include <stdbool.h>
25 #include "ocstack.h"
26 #include "pmtypes.h"
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32
33 #define DEFAULT_SECURE_PORT 5684
34
35 #define COAPS_PREFIX "coaps://"
36 #define COAP_PREFIX "coap://"
37 #define COAPS_QUERY "coaps://%s:%d%s"
38 #define COAP_QUERY "coap://%s:%d%s"
39
40 #define COAP_TCP_PREFIX "coap+tcp://"
41 #define COAP_TCP_QUERY "coap+tcp://%s:%d%s"
42 #define COAPS_TCP_PREFIX "coaps+tcp://"
43 #define COAPS_TCP_QUERY "coaps+tcp://%s:%d%s"
44
45 /**
46  * Discover owned/unowned device in the specified endpoint/deviceID.
47  * It will return the found device even though timeout is not exceeded.
48  *
49  * @param[in] waittime           Timeout in seconds
50  * @param[in] deviceID           deviceID of target device.
51  * @param[out] ppFoundDevice     OCProvisionDev_t of found device
52  *
53  * @return OC_STACK_OK on success otherwise error.\n
54  *         OC_STACK_INVALID_PARAM when deviceID is NULL or ppFoundDevice is not initailized.
55  */
56 OCStackResult PMSingleDeviceDiscovery(unsigned short waittime, const OicUuid_t* deviceID,
57                                  OCProvisionDev_t **ppFoundDevice);
58
59 /**
60  * Discover owned/unowned device in the specified endpoint/MAC address.
61  * It will return the found device even though timeout is not exceeded.
62  *
63  * @param[in] waittime           Timeout in seconds.
64  * @param[in] deviceID           deviceID of target device.
65  * @param[in] hostAddress       MAC address of target device.
66  * @param[in] connType       ConnectivityType for discovery.
67  * @param[out] ppFoundDevice     OCProvisionDev_t of found device.
68  *
69  * @return OC_STACK_OK on success otherwise error.
70  *         OC_STACK_INVALID_PARAM when deviceID is NULL or ppFoundDevice is not initailized.
71  */
72 OCStackResult PMSingleDeviceDiscoveryInUnicast(unsigned short waittime, const OicUuid_t* deviceID,
73                         const char* hostAddress, OCConnectivityType connType,
74                         OCProvisionDev_t **ppFoundDevice);
75
76 /**
77  * Discover owned/unowned devices in the same IP subnet. .
78  *
79  * @param[in] waittime      Timeout in seconds.
80  * @param[in] isOwned       bool flag for owned / unowned discovery
81  * @param[in] ppList        List of OCProvisionDev_t.
82  *
83  * @return OC_STACK_OK on success otherwise error.
84  */
85 OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisionDev_t **ppList);
86
87 #ifdef MULTIPLE_OWNER
88 /**
89  * Discover multiple OTM enabled devices in the same IP subnet.
90  *
91  * @param[in] waittime      Timeout in seconds.
92  * @param[in] isMultipleOwned       bool flag for MOT enabled / multiple owned discovery
93  * @param[in] ppDevicesList        List of OCProvisionDev_t.
94  *
95  * @return OC_STACK_OK on success otherwise error.
96  */
97 OCStackResult PMMultipleOwnerDeviceDiscovery(unsigned short waittime, bool isMultipleOwned, OCProvisionDev_t **ppDevicesList);
98 #endif //MULTIPLE_OWNER
99
100 /**
101  * This function deletes list of provision target devices
102  *
103  * @param[in] pList         List of OCProvisionDev_t.
104  */
105 void PMDeleteDeviceList(OCProvisionDev_t *pList);
106
107 /**
108  * Timeout implementation for secure discovery. When performing secure discovery,
109  * we should wait a certain period of time for getting response of each devices.
110  *
111  * @param[in]  waittime  Timeout in seconds.
112  * @param[in]  waitForStackResponse if true timeout function will call OCProcess while waiting.
113  * @return OC_STACK_OK on success otherwise error.
114  */
115 OCStackResult PMTimeout(unsigned short waittime, bool waitForStackResponse);
116
117 /**
118  * Function to clone OCProvisionDev_t
119  *
120  * @param[in] src pointer of OCProvisionDev_t to be copied.
121  *
122  * @return copied OCProvisionDev_t on success otherwise NULL.
123  */
124 OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src);
125
126
127 /**
128  * Function to generate qurey for coap/coaps request.
129  *
130  * @param[in] isSeucre Choose whether to encrypt the payload.
131  * @param[in] address Network address of remote device
132  * @param[in] port Port number
133  * @param[in] connType Connectivity type of remote device
134  * @param[in,out] buffer A buffer to save the query.
135  * @param[in] bufferSize Size of buffer
136  * @param[in] uri The resource URI
137  *
138  * @return true on success
139  */
140 bool PMGenerateQuery(bool isSecure,
141                      const char* address, uint16_t port,
142                      OCConnectivityType connType,
143                      char* buffer, size_t bufferSize, const char* uri);
144
145 /**
146  * Function to print OCProvisionDev_t for debug purpose.
147  *
148  * @param[in] pDev Pointer to OCProvisionDev_t. It's information will be printed by OIC_LOG_XX
149  *
150  */
151 void PMPrintOCProvisionDev(const OCProvisionDev_t* pDev);
152
153 /** Function to delete matched UUID from the UUIDlist.
154  *
155  * @param[in] pUuidList a pointer to UUID list.
156  * @param[in] targetId  a pointer to UUID to be deleted in the list.
157  *
158  * @return true when deletion is happened, false when no deletion is occured. In case either of
159  * two arguments is null it will return false.
160  */
161 bool PMDeleteFromUUIDList(OCUuidList_t **pUuidList, OicUuid_t *targetId);
162
163 #ifdef __cplusplus
164 }
165 #endif
166 #endif //_PM_UTILITY_H_