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