Fixed some coverity
[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, *var = NULL;
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         g_variant_get(reply, "(v)", &var);
44
45         if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
46                 value = g_variant_get_int32(var);
47                 if (value == TRUE)
48                         *enabled = 1;
49                 else
50                         *enabled = 0;
51
52                 result = TRUE;
53         }
54
55         if (var)
56                 g_variant_unref(var);
57
58         g_variant_unref(reply);
59
60         return result;
61 }
62
63 static gboolean netconfig_wifi_set_passpoint(gint32 enable)
64 {
65         gint32 value = enable ? 1 : 0;
66         gboolean result = FALSE;
67
68         result = netconfig_supplicant_invoke_dbus_interface_property_set(
69                         SUPPLICANT_IFACE_INTERFACE, "Passpoint",
70                         g_variant_new_int32(value), NULL);
71         if (result == FALSE)
72                 ERR("Fail to set passpoint enable[%d]", enable);
73
74         return result;
75 }
76 #endif
77
78 gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context)
79 {
80         gint32 enable = 0;
81         g_return_val_if_fail(wifi != NULL, TRUE);
82
83 #if defined TIZEN_WLAN_PASSPOINT
84         if (netconfig_wifi_get_passpoint(&enable)) {
85                 wifi_complete_get_passpoint(wifi, context, enable);
86                 return TRUE;
87         }
88         wifi_complete_get_passpoint(wifi, context, enable);
89         return TRUE;
90 #else
91         enable = 0;
92         wifi_complete_get_passpoint(wifi, context, enable);
93         return TRUE;
94 #endif
95 }
96
97 gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context, gint enable)
98 {
99         g_return_val_if_fail(wifi != NULL, TRUE);
100
101 #if defined TIZEN_WLAN_PASSPOINT
102         netconfig_wifi_set_passpoint(enable);
103 #endif
104         wifi_complete_set_passpoint(wifi, context);
105         return TRUE;
106 }