replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / include / CAManager.h
1 /* ****************************************************************
2  *
3  * Copyright 2016 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 CA_MANAGER_H_
22 #define CA_MANAGER_H_
23
24 #include <OCApi.h>
25
26 namespace OC
27 {
28     /**
29     * This namespace contains the main entrance/functionality to monitoring network changes.
30     * It may be used with OC::CAManager::functionName. To set a custom callback function,
31     * the implementer must make a call to CAManager::setNetworkMonitorHandler.
32     */
33     namespace CAManager
34     {
35         /**
36          *  Data structure to provide the configuration for cautil.
37          */
38         struct CAUtilConfig
39         {
40             /** the flag for ble advertising. */
41             OCTransportBTFlags_t       bleFlag;
42
43             public:
44                 CAUtilConfig()
45                     : bleFlag(OC_DEFAULT_BT_FLAGS)
46             {}
47                 CAUtilConfig(OCTransportBTFlags_t bleFlag_)
48                     : bleFlag(bleFlag_)
49             {}
50         };
51
52         // typedef to get adapter status changes from CA.
53         typedef std::function<void(const std::string&, OCConnectivityType,
54                                    bool)> ConnectionChangedCallback;
55
56         // typedef to get connection status changes from CA.
57         typedef std::function<void(OCTransportAdapter, bool)> AdapterChangedCallback;
58
59         /**
60         * Set network monitoring handler.
61         * @param adapterHandler adapter state change handler to handle changes for
62         *                       any transport types.
63         * @param connectionHandler connection state change handler to handle changes for
64         *                          connection with remote devices.
65         * @return Returns ::OC_STACK_OK if success.
66         */
67         OCStackResult setNetworkMonitorHandler(AdapterChangedCallback adapterHandler,
68                                                ConnectionChangedCallback connectionHandler);
69
70         /**
71         * Set port number to use.
72         * @param adapter transport adapter type to assign the specified port number.
73         * @param flag transport flag information.
74         * @param port the specified port number to use.
75         * @return Returns ::OC_STACK_OK if success.
76         */
77         OCStackResult setPortNumberToAssign(OCTransportAdapter adapter,
78                                             OCTransportFlags flag, uint16_t port);
79
80         /**
81         * Get the assigned port number.
82         * @param adapter transport adapter type to get the opened port number.
83         * @param flag   transport flag information.
84         * @return Returns currently assigned port number.
85         */
86         uint16_t getAssignedPortNumber(OCTransportAdapter adapter, OCTransportFlags flag);
87
88         /**
89         * Set multicast time to live to control the scope of the multicasts.
90         * @param ttl To be set to any value from 0 to 255.
91         *            Example:
92         *            0: Are restricted to the same host.
93         *            1: Are restricted to the same subnet.
94         *            32: Are restricted to the same site.
95         *            64: Are restricted to the same region.
96         *            128: Are restricted to the same continent.
97         *            255: Are unrestricted in scope.
98         *            We cannot support region, continent and unrestricted in scope.
99         * @return Returns ::OC_STACK_OK if success.
100         */
101         OCStackResult setMulticastTTL(size_t ttl);
102
103         /**
104         * Get multicast time to live.
105         * @param ttl TTL pointer to get the stored multicast time to live.
106         * @return Returns ::OC_STACK_OK if success.
107         */
108         OCStackResult getMulticastTTL(size_t *ttl);
109
110         /**
111          * set BT configure.
112          * @param[in]  config       ::CAUtilConfig data
113          * @return Returns ::OC_STACK_OK if success.
114          */
115         OCStackResult setBTConfigure(const CAUtilConfig& config);
116
117         /**
118          * set CAUtil log preference.
119          * @param[in]  level                     ::OCLogLevel value.
120          * @param[in]  hidePrivateLogEntries     Private Log Entries.
121          *                                       Example:
122          *                                       true : hide private log.
123          *                                       false : show private log.
124          *                                       (privacy : uid, did, access token, etc)
125          */
126         void setLogLevel(OCLogLevel level, bool hidePrivateLogEntries);
127
128         //Custom advertise
129 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
130         OCStackResult setAdvertisementData(const char* data, int length);
131         OCStackResult setScanResponseData(const char* data, int length);
132 #endif
133
134         /**
135          * start BLE advertising.
136          * @return Returns ::OC_STACK_OK if success.
137          */
138         OCStackResult startLEAdvertising();
139
140         /**
141          * stop BLE advertising.
142          * @return Returns ::OC_STACK_OK if success.
143          */
144         OCStackResult stopLEAdvertising();
145
146         /**
147          * Disconnect TCP session.
148          * When there is no transmission for a long time.
149          * Some carrier Vendor is blocking data.
150          * Thur, TCP Session is cleaned through this function.
151          * @param[in]   address        Address.
152          * @param[in]   port           Port.
153          * @param[in]   flags          Transport flag.
154          * @return Returns ::OC_STACK_OK if success.
155          */
156         OCStackResult disconnectTCPSession(const char *address,
157                                            uint16_t port,
158                                            OCTransportFlags flags);
159
160         OCStackResult startCAGattServer();
161         OCStackResult stopCAGattServer();
162 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
163         /**
164          * Select the cipher suite for TLS/DTLS handshake.
165          * @param cipher  cipher suite (Note : Make sure endianness).
166          *                        TLS_RSA_WITH_AES_256_CBC_SHA256          0x3D
167          *                        TLS_RSA_WITH_AES_128_GCM_SHA256          0x009C
168          *                        TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256  0xC02B
169          *                        TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8       0xC0AE
170          *                        TLS_ECDHE_ECDSA_WITH_AES_128_CCM         0xC0AC
171          *                        TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256  0xC023
172          *                        TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384  0xC024
173          *                        TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384  0xC02C
174          *                        TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256    0xC037
175          *                        TLS_ECDH_anon_WITH_AES_128_CBC_SHA       0xC018
176          * @param adapter transport adapter type.
177          * @return Returns ::OC_STACK_OK if success.
178          */
179         OCStackResult setCipherSuite(const uint16_t cipher, OCTransportAdapter adapter);
180 #endif // defined(__WITH_DTLS__) || defined(__WITH_TLS__)
181     }
182 }
183
184 #endif // CA_MANAGER_H_
185
186
187