8a43cc99de0d8cd8fb9b6dfc6a990b71aa90acc3
[platform/core/connectivity/net-config.git] / src / wifi-passpoint.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <errno.h>
21
22 #include "log.h"
23 #include "util.h"
24 #include "neterror.h"
25 #include "netdbus.h"
26 #include "netsupplicant.h"
27 #include "wifi-passpoint.h"
28
29 #if defined TIZEN_WLAN_PASSPOINT
30 static gboolean netconfig_wifi_get_passpoint(gint32 *enabled)
31 {
32         GVariant *reply;
33         gboolean value;
34         gboolean result = FALSE;
35
36         reply = netconfig_supplicant_invoke_dbus_interface_property_get(SUPPLICANT_IFACE_INTERFACE,
37                                 "Passpoint");
38         if (reply == NULL) {
39                 ERR("Error!!! Failed to get passpoint property");
40                 return FALSE;
41         }
42
43         if (g_variant_is_of_type(reply, G_VARIANT_TYPE_INT32)) {
44                 value = g_variant_get_int32(reply);
45                 if (value == TRUE)
46                         *enabled = 1;
47                 else
48                         *enabled = 0;
49
50                 result = TRUE;
51         }
52
53         g_variant_unref(reply);
54
55         return result;
56 }
57
58 static gboolean netconfig_wifi_set_passpoint(gint32 enable)
59 {
60         gint32 value = enable ? 1 : 0;
61         gboolean result = FALSE;
62         GVariant *input_args = NULL;
63
64         input_args = g_variant_new_int32(value);
65
66         result = netconfig_supplicant_invoke_dbus_interface_property_set(
67                         SUPPLICANT_IFACE_INTERFACE, "Passpoint", input_args, NULL);
68         if (result == FALSE)
69                 ERR("Fail to set passpoint enable[%d]", enable);
70
71         return result;
72 }
73 #endif
74
75 gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context)
76 {
77         gint32 enable = 0;
78         g_return_val_if_fail(wifi != NULL, FALSE);
79
80 #if defined TIZEN_WLAN_PASSPOINT
81         if (netconfig_wifi_get_passpoint(&enable)) {
82                 wifi_complete_get_passpoint(wifi, context, enable);
83                 return TRUE;
84         }
85         wifi_complete_get_passpoint(wifi, context, enable);
86         return FALSE;
87 #else
88         enable = 0;
89         wifi_complete_get_passpoint(wifi, context, enable);
90         return TRUE;
91 #endif
92 }
93
94 gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context, gint enable)
95 {
96         gboolean result = FALSE;
97         g_return_val_if_fail(wifi != NULL, FALSE);
98
99 #if defined TIZEN_WLAN_PASSPOINT
100         result = netconfig_wifi_set_passpoint(enable);
101         wifi_complete_set_passpoint(wifi, context);
102         return result;
103 #else
104         wifi_complete_set_passpoint(wifi, context);
105         return result;
106 #endif
107 }