Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / service / easy-setup / enrollee / linux / wifi / networkhandler.c
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 "LINUX ES"
30
31 const char *gSsid = "DLNA_LISMORE1";
32 const char *gPass = "dlna@010203";
33 char *gIpAddress;
34 ESEnrolleeNetworkEventCallback 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,
52                                                         ESEnrolleeNetworkEventCallback cb)
53 {
54     OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
55     gPass = pass;
56     gSsid = ssid;
57     gNetworkEventCb = cb;
58     start();
59 }
60
61 ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
62 {
63     if (targetType == CT_ADAPTER_IP)
64     {
65         info->type = CT_ADAPTER_IP;
66         info->ipaddr = gIpAddress;
67         if (strlen(gSsid) <= MAXSSIDLEN)
68         {
69             OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
70             return ES_OK;
71         }
72         else
73         {
74             return ES_ERROR;
75         }
76     }
77
78     return ES_ERROR;
79 }
80