0aa74b56316acf911f6c0c67e2528199c35ebb6a
[platform/upstream/iotivity.git] / service / easy-setup / enrollee / linux / wifi / networkhandler.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 #include "networkhandler.h"
22
23 #include <unistd.h>
24
25 #include "logger.h"
26 #include "easysetup.h"
27 #include "oic_string.h"
28
29 #define LOG_TAG "TIZEN ES"
30
31 const char *gSsid = "DLNA_LISMORE1";
32 const char *gPass = "dlna@010203";
33 char *gIpAddress;
34 NetworkEventCallback gNetworkEventCb;
35
36 /*
37  * All the functions defined in this file are stub functions to be implemented by the end user of
38  * Easysetup Enrollee applications.
39  */
40 static void ESActivateWifi()
41 {
42
43 }
44
45 static void start()
46 {
47     OIC_LOG(INFO, LOG_TAG, "START");
48     ESActivateWifi();
49 }
50
51 void ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
52 {
53     OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
54     gPass = pass;
55     gSsid = ssid;
56     gNetworkEventCb = cb;
57     start();
58 }
59
60 ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
61 {
62     if (targetType == CT_ADAPTER_IP)
63     {
64         info->type = CT_ADAPTER_IP;
65         info->ipaddr = gIpAddress;
66         if (strlen(gSsid) <= MAXSSIDLEN)
67         {
68             OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
69             return ES_OK;
70         }
71         else
72         {
73             return ES_ERROR;
74         }
75     }
76
77     return ES_ERROR;
78 }
79