2 * Network Configuration Module
4 * Copyright (c) 2014 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.
23 #include "network-monitor.h"
24 #include "network-state.h"
25 #include "wifi-power.h"
28 #include <arpa/inet.h>
29 #include <net/route.h>
30 #include <net/ethernet.h>
34 #include <sys/ioctl.h>
36 #include <vconf-keys.h>
38 #define ETHERNET_CABLE_STATUS "/sys/class/net/eth0/carrier"
40 /* Check send notification status */
41 static gboolean g_chk_eth_send_notification = FALSE;
43 int netconfig_ethernet_cable_plugin_status_check()
47 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
48 if (0 == access(ETHERNET_CABLE_STATUS, F_OK)) {
49 fd = fopen(ETHERNET_CABLE_STATUS, "r");
51 ERR("Error! Could not open /sys/class/net/eth0/carrier file\n");
55 ERR("Error! Could not access /sys/class/net/eth0/carrier file\n");
61 rv = fscanf(fd, "%d", &ret);
63 ERR("Error! Failed to read from file, rv:[%d], error:[%s]",
64 rv, strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
70 if (!g_chk_eth_send_notification) {
71 ERR("/sys/class/net/eth0/carrier : [%d]", ret);
72 netconfig_network_notify_ethernet_cable_state("ATTACHED");
74 g_chk_eth_send_notification = TRUE;
75 } else if (ret == 0) {
76 if (g_chk_eth_send_notification) {
77 ERR("/sys/class/net/eth0/carrier : [%d]", ret);
78 netconfig_network_notify_ethernet_cable_state("DETACHED");
80 g_chk_eth_send_notification = FALSE;
87 int netconfig_get_ethernet_cable_state(int *status)
91 DBG("Error !!! Invalid Parameter\n");
95 if ((error = netconfig_ethernet_cable_plugin_status_check()) != 0) {
96 DBG("Error !!! Failed to check ethernet cable status [%d]\n", error);
100 if (g_chk_eth_send_notification == TRUE)
101 *status = 1; /* Ethernet cable Attached */
103 *status = 0; /* Ethernet cable Deattached */