Imported Upstream version 1.0.0
[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 /**
41  * Discover owned/unowned devices in the same IP subnet. .
42  *
43  * @param[in] waittime      Timeout in seconds.
44  * @param[in] isOwned       bool flag for owned / unowned discovery
45  * @param[in] ppList        List of OCProvisionDev_t.
46  *
47  * @return OC_STACK_OK on success otherwise error.
48  */
49 OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisionDev_t **ppList);
50
51 /**
52  * This function deletes list of provision target devices
53  *
54  * @param[in] pList         List of OCProvisionDev_t.
55  */
56 void PMDeleteDeviceList(OCProvisionDev_t *pList);
57
58 /**
59  * Timeout implementation for secure discovery. When performing secure discovery,
60  * we should wait a certain period of time for getting response of each devices.
61  *
62  * @param[in]  waittime  Timeout in seconds.
63  * @param[in]  waitForStackResponse if true timeout function will call OCProcess while waiting.
64  * @return OC_STACK_OK on success otherwise error.
65  */
66 OCStackResult PMTimeout(unsigned short waittime, bool waitForStackResponse);
67
68 /**
69  * Function to clone OCProvisionDev_t
70  *
71  * @param[in] src pointer of OCProvisionDev_t to be copied.
72  *
73  * @return copied OCProvisionDev_t on success otherwise NULL.
74  */
75 OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src);
76
77
78 /**
79  * Function to generate qurey for coap/coaps request.
80  *
81  * @param[in] isSeucre Choose whether to encrypt the payload.
82  * @param[in] address Network address of remote device
83  * @param[in] port Port number
84  * @param[in] connType Connectivity type of remote device
85  * @param[in,out] buffer A buffer to save the query.
86  * @param[in] bufferSize Size of buffer
87  * @param[in] uri The resource URI
88  *
89  * @return true on success
90  */
91 bool PMGenerateQuery(bool isSecure,
92                      const char* address, uint16_t port,
93                      OCConnectivityType connType,
94                      char* buffer, size_t bufferSize, const char* uri);
95
96 /**
97  * Function to print OCProvisionDev_t for debug purpose.
98  *
99  * @param[in] pDev Pointer to OCProvisionDev_t. It's information will be printed by OC_LOG_XX
100  *
101  */
102 void PMPrintOCProvisionDev(const OCProvisionDev_t* pDev);
103
104 /** Function to delete matched UUID from the UUIDlist.
105  *
106  * @param[in] pUuidList a pointer to UUID list.
107  * @param[in] targetId  a pointer to UUID to be deleted in the list.
108  *
109  * @return true when deletion is happened, false when no deletion is occured. In case either of
110  * two arguments is null it will return false.
111  */
112 bool PMDeleteFromUUIDList(OCUuidList_t *pUuidList, OicUuid_t *targetId);
113
114 #ifdef __cplusplus
115 }
116 #endif
117 #endif //_PM_UTILITY_H_