1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "easysetup.h"
23 /// WiFi network info and credentials
24 char defaultSsid[] = "EasyConnect";
25 char defaultPass[] = "EasyConnect";
32 EventCallback g_cbForProvisioning = NULL;
33 EventCallback g_cbForOnboarding = NULL;
35 void EventCallbackInOnboarding(ES_RESULT event);
36 void EventCallbackInProvisioning(ES_RESULT event);
37 void EventCallbackAfterProvisioning(ES_RESULT event);
39 void EventCallbackInOnboarding(ES_RESULT event)
41 if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
43 if (g_cbForOnboarding != NULL)
45 g_cbForOnboarding(event);
50 void EventCallbackInProvisioning(ES_RESULT event)
52 ES_RESULT res = ES_OK;
54 if (event == ES_RECVTRIGGEROFPROVRES)
56 targetSsid = (char *) malloc(MAXSSIDLEN);
57 targetPass = (char *) malloc(MAXNETCREDLEN);
59 GetTargetNetworkInfoFromProvResource(targetSsid, targetPass);
61 res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
63 if (g_cbForProvisioning != NULL)
65 g_cbForProvisioning(res);
70 void EventCallbackAfterProvisioning(ES_RESULT event)
72 if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
74 if (g_cbForProvisioning != NULL)
76 g_cbForProvisioning(event);
81 ES_RESULT FindNetworkForOnboarding(NetworkType networkType, EventCallback cb)
83 if (networkType == ES_WIFI)
85 if (g_cbForOnboarding == NULL)
87 g_cbForOnboarding = cb;
90 return ConnectToWiFiNetwork(defaultSsid, defaultPass, EventCallbackInOnboarding);
94 ES_RESULT FindNetworkForOnboarding(NetworkType networkType, const char *ssid, const char *passwd,
102 if (networkType == ES_WIFI)
104 if (g_cbForOnboarding == NULL)
106 g_cbForOnboarding = cb;
109 return ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding);
113 ES_RESULT InitializeProvisioning(EventCallback cb)
121 g_cbForProvisioning = cb;
124 if (CreateProvisioningResource() != OC_STACK_OK)
129 if (CreateNetworkResource() != OC_STACK_OK)
134 RegisterResourceEventCallBack(EventCallbackInProvisioning);
136 return ES_RESOURCECREATED;