Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / easy-setup / enrollee / arduino / onboarding.cpp
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 /**
22  * @file
23  *
24  * This file has methods for on-boarding the Enrollee device.
25  * This will contain template methods that will have core business logic & negotiation algorithm
26  * on various on-boarding methods.
27  */
28
29 #include "easysetup.h"
30 #include "softap.h"
31 #include "onboarding.h"
32
33 #include "logger.h"
34 #include "resourcehandler.h"
35
36 /**
37  * @var ES_ENROLLEE_TAG
38  * @brief Logging tag for module name.
39  */
40 #define ES_ENROLLEE_TAG "ES_SOFTAP"
41
42 /**
43  * It will return true on-boarding type is soft AP
44  */
45 bool ESSoftapOnboarding()
46 {
47     // TODO: To be changed based on user config. Current version, hardcoded to SoftAp onboarding
48     return true;
49 }
50
51 /**
52  * It will return true on-boarding type is BLE
53  */
54 bool ESBleOnboarding()
55 {
56     //BLE onboarding is not supported with current version.
57     return false;
58 }
59
60 /**
61  * It will do onboarding based on the user's configuration.
62  */
63 bool ESOnboard(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb)
64 {
65     OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "ESOnboard IN");
66
67     if (ESSoftapOnboarding())
68     {
69         OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting to Mediator SoftAp");
70         ConnectToWiFiNetwork(ssid, passwd, cb);
71         return true;
72     }
73     else if (ESBleOnboarding())
74     {
75         OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Ble onboarding is not supported");
76         // TODO:
77         return false;
78     }
79     else
80     {
81         // TODO:
82         OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Invalid onboarding option");
83         return false;
84     }
85 }
86