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.
22 #include <vconf-keys.h>
27 #include "wifi-state.h"
28 #include "wifi-scan.h"
29 #include "wifi-background-scan.h"
31 void netconfig_wifi_bgscan_start(const char *interface_name, gboolean immediate_scan)
33 wifi_tech_state_e wifi_tech_state;
34 wifi_service_state_e wifi_service_state;
35 int ug_state = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
36 guint bg_mode = WIFI_BGSCAN_MODE_EXPONENTIAL;
38 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
40 if (netconfig_wifi_bgscan_get_timer_id(interface_name) > 0)
41 netconfig_wifi_bgscan_stop_timer(interface_name);
43 wifi_tech_state = wifi_state_get_technology_state(interface_name);
44 wifi_service_state = wifi_state_get_service_state(interface_name);
45 DBG("[%s] Wi-Fi tech state [%s] service state [%s]", interface_name,
46 _convert_wifi_technology_state_to_string(wifi_tech_state),
47 _convert_wifi_service_state_to_string(wifi_service_state));
49 if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED)
52 bg_mode = netconfig_wifi_bgscan_get_mode(interface_name);
54 if (wifi_service_state == NETCONFIG_WIFI_CONNECTED &&
55 (bg_mode == WIFI_BGSCAN_MODE_EXPONENTIAL ||
56 (bg_mode == WIFI_BGSCAN_MODE_PERIODIC &&
57 ug_state != VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)))
60 DBG("[%s] Wi-Fi background scan started or re-started(%d)",
61 interface_name, immediate_scan);
63 netconfig_wifi_bgscan_start_timer(interface_name, immediate_scan);
66 void netconfig_wifi_bgscan_stop(const char *interface_name)
68 netconfig_wifi_bgscan_stop_timer(interface_name);
71 void netconfig_wifi_bgscan_restart(const gchar *interface_name)
73 int pm_state = VCONFKEY_PM_STATE_NORMAL;
75 /* In case of LCD off, we don't need Wi-Fi scan right now */
76 netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
77 if (pm_state >= VCONFKEY_PM_STATE_LCDOFF)
78 netconfig_wifi_bgscan_start(interface_name, FALSE);
80 netconfig_wifi_bgscan_start(interface_name, TRUE);
83 gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context,
84 const gchar *ifname, guint scan_mode)
88 old_mode = netconfig_wifi_bgscan_get_mode(ifname);
89 if (old_mode == scan_mode) {
90 wifi_complete_set_bgscan(wifi, context);
94 if (netconfig_wifi_bgscan_set_mode(ifname, scan_mode) != TRUE) {
95 ERR("Invalid mode [%d]", scan_mode);
96 netconfig_error_invalid_parameter(context);
100 INFO("[%s] Wi-Fi scan mode is changed [%d]", ifname, scan_mode);
102 netconfig_wifi_bgscan_restart(ifname);
104 wifi_complete_set_bgscan(wifi, context);
108 gboolean handle_set_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context,
109 const gchar *ifname, const gchar *mode, guint interval)
111 guint old_interval = 0;
114 if (g_strcmp0(mode, "Periodic") == 0) {
115 old_interval = netconfig_wifi_bgscan_get_periodic_interval(ifname);
116 } else if (g_strcmp0(mode, "Exponential") == 0) {
117 old_interval = netconfig_wifi_bgscan_get_exp_interval(ifname);
119 ERR("invalid mode %s", mode);
120 netconfig_error_invalid_parameter(context);
124 if (old_interval == interval) {
125 wifi_complete_set_bgscan_interval(wifi, context);
129 if (g_strcmp0(mode, "Periodic") == 0)
130 rv = netconfig_wifi_bgscan_set_periodic_interval(ifname, interval);
132 rv = netconfig_wifi_bgscan_set_exp_interval(ifname, interval);
135 netconfig_error_invalid_parameter(context);
139 INFO("[%s] Wi-Fi periodic scan interval is changed to [%d] from [%d]",
140 ifname, interval, old_interval);
142 netconfig_wifi_bgscan_restart(ifname);
144 wifi_complete_set_bgscan_interval(wifi, context);
148 gboolean handle_get_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context,
149 const gchar *ifname, const gchar *mode)
151 guint bgscan_interval = 0;
153 if (g_strcmp0(mode, "Periodic") == 0) {
154 bgscan_interval = netconfig_wifi_bgscan_get_periodic_interval(ifname);
155 } else if (g_strcmp0(mode, "Exponential") == 0) {
156 bgscan_interval = netconfig_wifi_bgscan_get_exp_interval(ifname);
158 ERR("invalid mode %s", mode);
159 netconfig_error_invalid_parameter(context);
163 wifi_complete_get_bgscan_interval(wifi, context, bgscan_interval);
167 gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context,
170 netconfig_wifi_bgscan_set_pause(ifname, FALSE);
172 wifi_complete_resume_bgscan(wifi, context);
176 gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context,
179 netconfig_wifi_bgscan_set_pause(ifname, TRUE);
181 wifi_complete_pause_bgscan(wifi, context);
185 gboolean handle_reset_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context,
188 netconfig_wifi_bgscan_set_exp_interval(ifname, SCAN_EXPONENTIAL_MIN);
190 wifi_complete_reset_bgscan_interval(wifi, context);
194 gboolean handle_get_autoscan(Wifi *wifi, GDBusMethodInvocation *context,
198 gboolean autoscan = 0;
200 autoscan = netconfig_wifi_bgscan_is_paused(ifname);
202 wifi_complete_get_autoscan(wifi, context, autoscan);
206 gboolean handle_get_autoscanmode(Wifi *wifi, GDBusMethodInvocation *context,
209 guint autoscanmode = 0;
211 autoscanmode = netconfig_wifi_bgscan_get_mode(ifname);
213 wifi_complete_get_autoscanmode(wifi, context, autoscanmode);