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