Merge "Add dbus method for getting wifi passphrase" into tizen
[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(const char *interface_name, gint32 *enabled)
31 {
32         GVariant *reply, *var = NULL;
33         gboolean value;
34         gboolean result = FALSE;
35
36         reply = netconfig_supplicant_invoke_dbus_interface_property_get(interface_name, "Passpoint");
37         if (reply == NULL) {
38                 ERR("Error!!! Failed to get passpoint property");
39                 return FALSE;
40         }
41
42         g_variant_get(reply, "(v)", &var);
43
44         if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
45                 value = g_variant_get_int32(var);
46                 if (value == TRUE)
47                         *enabled = 1;
48                 else
49                         *enabled = 0;
50
51                 result = TRUE;
52         }
53
54         if (var)
55                 g_variant_unref(var);
56
57         g_variant_unref(reply);
58
59         return result;
60 }
61
62 static gboolean netconfig_wifi_set_passpoint(const char *interface_name, gint32 enable)
63 {
64         gint32 value = enable ? 1 : 0;
65         gboolean result = FALSE;
66
67         result = netconfig_supplicant_invoke_dbus_interface_property_set(interface_name,
68                         "Passpoint", g_variant_new_int32(value), NULL);
69         if (result == FALSE)
70                 ERR("Fail to set passpoint enable[%d]", enable);
71
72         return result;
73 }
74 #endif
75
76 gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context,
77                 const char *ifname)
78 {
79         gint32 enable = 0;
80         g_return_val_if_fail(wifi != NULL, TRUE);
81
82 #if defined TIZEN_WLAN_PASSPOINT
83         netconfig_wifi_get_passpoint(ifname, &enable);;
84 #else
85         enable = 0;
86 #endif
87         wifi_complete_get_passpoint(wifi, context, enable);
88         return TRUE;
89 }
90
91 gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context,
92                 const char *ifname, gint enable)
93 {
94         g_return_val_if_fail(wifi != NULL, TRUE);
95
96 #if defined TIZEN_WLAN_PASSPOINT
97         netconfig_wifi_set_passpoint(ifname, enable);
98 #endif
99         wifi_complete_set_passpoint(wifi, context);
100         return TRUE;
101 }