2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <vconf-keys.h>
26 #include "wifi-power.h"
27 #include "wifi-state.h"
28 #include "network-dpm.h"
29 #include "network-state.h"
31 #define NETCONFIG_SIGNAL_DPM_WIFI "DPMWifi"
32 #define NETCONFIG_SIGNAL_DPM_WIFI_PROFILE "DPMWifiProfile"
34 static int dpm_policy_wifi = 1;
35 static int dpm_policy_wifi_profile = 1;
37 static void __netconfig_dpm_notify_result(const char *sig_name, const char *key)
41 GVariantBuilder *builder = NULL;
42 GDBusConnection *connection = NULL;
44 const char *prop_key = "key";
46 INFO("[Signal] %s %s", sig_name, key);
48 connection = netdbus_get_connection();
49 if (connection == NULL) {
50 ERR("Failed to get GDBus Connection");
54 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
55 g_variant_builder_add(builder, "{sv}", prop_key, g_variant_new_string(key));
56 params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
58 g_variant_builder_unref(builder);
60 reply = g_dbus_connection_emit_signal(connection,
62 NETCONFIG_NETWORK_PATH,
63 NETCONFIG_NETWORK_INTERFACE,
70 ERR("Failed to send signal [%s]", error->message);
76 INFO("Sent signal (%s), key (%s)", sig_name, key);
80 void netconfig_dpm_init(void)
82 INFO("DPM initialized");
86 void netconfig_dpm_deinit(void)
88 INFO("DPM deinitialized");
92 int netconfig_dpm_update_from_wifi(void)
94 GSList *list = wifi_state_get_device_list();
96 INFO("DPM update from wifi [%d]", dpm_policy_wifi);
98 if (!dpm_policy_wifi) {
99 for ( ; list; list = list->next) {
100 wifi_device_data_s *device_data = list->data;
101 if (device_data->powered == TRUE) {
102 int err = wifi_power_off(device_data->interface_name);
104 if (err == -EINPROGRESS)
105 ERR("wifi power off : InProgress");
106 else if (err == -EALREADY)
107 ERR("wifi power off : AlreadyExists");
108 else if (err == -EPERM)
109 ERR("wifi power off : PermissionDenied");
111 ERR("wifi power off : WifiDriverFailed");
113 DBG("wifi power off : ErrorNone");
117 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_OFF_BY_AIRPLANE, 0, TRUE);
118 netconfig_send_restriction_to_net_popup("Wi-Fi unavailable", "toast_popup", "wifi");
121 return dpm_policy_wifi;
124 int netconfig_dpm_update_from_wifi_profile(void)
126 INFO("DPM update from wifi profile [%d]", dpm_policy_wifi_profile);
127 return dpm_policy_wifi_profile;
130 gboolean handle_device_policy_set_wifi(
132 GDBusMethodInvocation *context,
135 INFO("DPM device policy wifi changed : [%d -> %d]",
136 dpm_policy_wifi, state);
138 dpm_policy_wifi = state;
139 netconfig_dpm_update_from_wifi();
140 __netconfig_dpm_notify_result(NETCONFIG_SIGNAL_DPM_WIFI,
141 state ? "allowed" : "disallowed");
143 network_complete_device_policy_set_wifi(object, context);
147 gboolean handle_device_policy_get_wifi(
149 GDBusMethodInvocation *context)
151 INFO("Successfully get wifi device policy [%d]",
154 network_complete_device_policy_get_wifi(object,
155 context, dpm_policy_wifi);
159 gboolean handle_device_policy_set_wifi_profile(
161 GDBusMethodInvocation *context,
164 INFO("DPM device policy wifi profile changed : [%d -> %d]",
165 dpm_policy_wifi_profile, state);
167 dpm_policy_wifi_profile = state;
168 netconfig_dpm_update_from_wifi_profile();
169 __netconfig_dpm_notify_result(NETCONFIG_SIGNAL_DPM_WIFI_PROFILE,
170 state ? "allowed" : "disallowed");
172 network_complete_device_policy_set_wifi_profile(object, context);
176 gboolean handle_device_policy_get_wifi_profile(
178 GDBusMethodInvocation *context)
180 INFO("Successfully get wifi profile device policy [%d]",
181 dpm_policy_wifi_profile);
183 network_complete_device_policy_get_wifi(object,
184 context, dpm_policy_wifi_profile);