be7a4ffcd166d0d66c05edf3396159fa40bf87ed
[platform/upstream/iotivity.git] / service / easy-setup / sdk / 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         if (ESSoftapAtEnrollee())
69         {
70             OC_LOG(DEBUG, ES_ENROLLEE_TAG, "Create softap at enrollee");
71             ESCreateSoftap(ssid, passwd, cb);
72         }
73         else
74         {
75             OC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting to SoftAp");
76             ConnectToWiFiNetwork(ssid, passwd, cb);
77         }
78         return true;
79     }
80     else if (ESBleOnboarding())
81     {
82         OC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Ble onboarding is not supported");
83         // TODO:
84         return false;
85     }
86     else
87     {
88         // TODO:
89         OC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Invalid onboarding option");
90         return false;
91     }
92 }
93