2 * Network Configuration Module
4 * Copyright (c) 2017 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.
28 #include <net/route.h>
29 #include <arpa/inet.h>
32 #include <sys/ioctl.h>
33 #include <vconf-keys.h>
34 #include <syspopup_caller.h>
36 #include <bundle_internal.h>
37 #include <eventsystem.h>
38 #include <tzplatform_config.h>
39 #include <system_info.h>
43 #ifdef USE_NETCONFIG_LOG
48 #define NETCONFIG_TAG "NETCONFIG"
49 #define __LOG(level, format, arg...) \
51 SLOG(level, NETCONFIG_TAG, format, ## arg); \
54 #define DBG(format, arg...) __LOG(LOG_DEBUG, format, ## arg)
55 #define ERR(format, arg...) __LOG(LOG_ERROR, format, ## arg)
58 const char *_headed_convert_sys_event(int event_val)
61 case SYS_EVT_NETWORK_STATUS:
62 return SYS_EVENT_NETWORK_STATUS;
63 case SYS_EVT_WIFI_STATE:
64 return SYS_EVENT_WIFI_STATE;
65 case EKEY_NETWORK_STATUS:
66 return EVT_KEY_NETWORK_STATUS;
68 return EVT_KEY_WIFI_STATE;
69 case EVAL_NETWORK_WIFI:
70 return EVT_VAL_NETWORK_WIFI;
71 case EVAL_NETWORK_CELLULAR:
72 return EVT_VAL_NETWORK_CELLULAR;
73 case EVAL_NETWORK_ETHERNET:
74 return EVT_VAL_NETWORK_ETHERNET;
76 return EVT_VAL_NETWORK_BT;
77 case EVAL_NETWORK_DISCONNECTED:
78 return EVT_VAL_NETWORK_DISCONNECTED;
79 case EVAL_WIFI_CONNECTED:
80 return EVT_VAL_WIFI_CONNECTED;
82 return EVT_VAL_WIFI_ON;
84 return EVT_VAL_WIFI_OFF;
92 void headed_pop_device_picker(void)
94 #if defined TIZEN_WEARABLE
96 app_control_h control = NULL;
98 ret = app_control_create(&control);
99 if (APP_CONTROL_ERROR_NONE != ret) {
100 DBG("failed to create app control");
104 app_control_add_extra_data(control, "viewtype", "scanlist");
106 app_control_set_app_id(control, "org.tizen.wifi");
107 ret = app_control_send_launch_request(control, NULL, NULL);
108 if (APP_CONTROL_ERROR_NONE == ret)
109 DBG("Launch request sent successfully");
111 app_control_destroy(control);
114 int wifi_ug_state = 0;
117 ret = vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
119 ERR("Failed to get vconfkey [%s] value", VCONFKEY_WIFI_UG_RUN_STATE);
121 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
126 DBG("Launch Wi-Fi device picker");
127 syspopup_launch("wifi-qs", b);
134 gboolean headed_send_notification_to_net_popup(const char * noti, const char * message)
138 static gboolean is_found_noti_exists = FALSE;
139 static gboolean is_portal_noti_exists = FALSE;
140 static gboolean is_conflict_noti_exists = FALSE;
143 ERR("Invalid notification");
147 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
148 if (is_found_noti_exists == FALSE)
151 is_found_noti_exists = FALSE;
152 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
153 if (is_found_noti_exists == TRUE)
156 is_found_noti_exists = TRUE;
157 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
158 if (is_portal_noti_exists == TRUE)
161 is_portal_noti_exists = TRUE;
162 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
163 if (is_portal_noti_exists == FALSE)
166 is_portal_noti_exists = FALSE;
167 } else if (g_strcmp0(noti, NETCONFIG_DEL_IP_CONFLICT_NOTI) == 0) {
168 if (is_conflict_noti_exists == FALSE)
171 is_conflict_noti_exists = FALSE;
172 } else if (g_strcmp0(noti, NETCONFIG_ADD_IP_CONFLICT_NOTI) == 0) {
173 if (is_conflict_noti_exists == TRUE)
176 is_conflict_noti_exists = TRUE;
180 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
182 if (message != NULL) {
183 DBG("message (%s)", message);
184 if (g_strcmp0(noti, NETCONFIG_ADD_IP_CONFLICT_NOTI) == 0)
185 bundle_add(b, "_MAC_ADDRESS_", message);
187 bundle_add(b, "_AP_NAME_", message);
190 ret = syspopup_launch("net-popup", b);
195 ERR("Unable to launch noti-popup. Err = %d", ret);
199 DBG("Successfully sent notification (%s)", noti);
203 int headed_send_message_to_net_popup(const char *title,
204 const char *content, const char *type, const char *ssid)
207 bundle *b = bundle_create();
209 bundle_add(b, "_SYSPOPUP_TITLE_", title);
210 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
211 bundle_add(b, "_SYSPOPUP_TYPE_", type);
212 bundle_add(b, "_AP_NAME_", ssid);
214 ret = syspopup_launch("net-popup", b);
221 int headed_send_restriction_to_net_popup(const char *title,
222 const char *type, const char *restriction)
225 bundle *b = bundle_create();
227 bundle_add(b, "_SYSPOPUP_TITLE_", title);
228 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
229 bundle_add(b, "_SYSPOPUP_TYPE_", type);
230 bundle_add(b, "_RESTRICTED_TYPE_", restriction);
232 ret = syspopup_launch("net-popup", b);
239 void headed_set_system_event(int sys_evt, int evt_key, int evt_val)
242 const char *sevent = _headed_convert_sys_event(sys_evt);
243 const char *ekey = _headed_convert_sys_event(evt_key);
244 const char *eval = _headed_convert_sys_event(evt_val);
246 DBG("System event set [%s : %s : %s]", sevent, ekey, eval);
249 bundle_add_str(b, ekey, eval);
250 eventsystem_send_system_event(sevent, b);
254 void headed_pop_wifi_connected_poppup(const char *ssid)
263 bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup");
264 bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
265 bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected");
266 bundle_add(b, "_AP_NAME_", ssid);
268 DBG("Launch Wi-Fi connected alert network popup");
269 syspopup_launch("net-popup", b);
275 extern struct netconfig_headed_plugin_t netconfig_headed_plugin
276 __attribute__ ((visibility("default")));
277 struct netconfig_headed_plugin_t netconfig_headed_plugin = {
278 headed_pop_device_picker,
279 headed_send_notification_to_net_popup,
280 headed_send_message_to_net_popup,
281 headed_send_restriction_to_net_popup,
282 headed_set_system_event,
283 headed_pop_wifi_connected_poppup