#include <connman/driver.h>
#include <connman/log.h>
+struct ethernet_data {
+ int index;
+ short flags;
+};
+
static GStaticMutex ethernet_mutex = G_STATIC_MUTEX_INIT;
static GSList *ethernet_list = NULL;
DBG("parent %p name %s", parent, parent->name);
- element = connman_element_create();
+ element = connman_element_create(NULL);
+ if (element == NULL)
+ return;
element->type = type;
- element->netdev.index = parent->netdev.index;
- element->netdev.name = g_strdup(parent->netdev.name);
+ element->index = parent->index;
connman_element_register(element, parent);
}
for (list = ethernet_list; list; list = list->next) {
struct connman_element *element = list->data;
+ struct ethernet_data *ethernet;
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ ethernet = connman_element_get_data(element);
+ if (ethernet == NULL)
continue;
- if (element->netdev.index != msg->ifi_index)
+ if (ethernet->index != msg->ifi_index)
continue;
- if ((element->netdev.flags & IFF_RUNNING) ==
- (msg->ifi_flags & IFF_RUNNING))
+ if ((ethernet->flags & IFF_RUNNING) ==
+ (msg->ifi_flags & IFF_RUNNING))
continue;
- element->netdev.flags = msg->ifi_flags;
+ ethernet->flags = msg->ifi_flags;
- if (msg->ifi_flags & IFF_RUNNING) {
+ if (ethernet->flags & IFF_RUNNING) {
DBG("carrier on");
create_element(element, CONNMAN_ELEMENT_TYPE_DHCP);
return TRUE;
}
-static GIOChannel *channel = NULL;
+static GIOChannel *channel;
static int rtnl_request(void)
{
(struct sockaddr *) &addr, sizeof(addr));
}
-static int iface_up(struct connman_element *element)
+static int iface_up(struct ethernet_data *ethernet)
{
struct ifreq ifr;
int sk, err;
- DBG("element %p", element);
+ DBG("index %d flags %d", ethernet->index, ethernet->flags);
sk = socket(PF_INET, SOCK_DGRAM, 0);
if (sk < 0)
return -errno;
memset(&ifr, 0, sizeof(ifr));
- ifr.ifr_ifindex = element->netdev.index;
+ ifr.ifr_ifindex = ethernet->index;
if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
err = -errno;
return err;
}
-static int iface_down(struct connman_element *element)
+static int iface_down(struct ethernet_data *ethernet)
{
struct ifreq ifr;
int sk, err;
- DBG("element %p", element);
+ DBG("index %d flags %d", ethernet->index, ethernet->flags);
sk = socket(PF_INET, SOCK_DGRAM, 0);
if (sk < 0)
return -errno;
memset(&ifr, 0, sizeof(ifr));
- ifr.ifr_ifindex = element->netdev.index;
+ ifr.ifr_ifindex = ethernet->index;
if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
err = -errno;
static int ethernet_probe(struct connman_element *element)
{
+ struct ethernet_data *ethernet;
+
DBG("element %p name %s", element, element->name);
+ ethernet = g_try_new0(struct ethernet_data, 1);
+ if (ethernet == NULL)
+ return -ENOMEM;
+
g_static_mutex_lock(ðernet_mutex);
ethernet_list = g_slist_append(ethernet_list, element);
g_static_mutex_unlock(ðernet_mutex);
- iface_up(element);
+ connman_element_set_data(element, ethernet);
+
+ ethernet->index = element->index;
+
+ iface_up(ethernet);
rtnl_request();
static void ethernet_remove(struct connman_element *element)
{
+ struct ethernet_data *ethernet = connman_element_get_data(element);
+
DBG("element %p name %s", element, element->name);
- iface_down(element);
+ connman_element_set_data(element, NULL);
+
+ iface_down(ethernet);
g_static_mutex_lock(ðernet_mutex);
ethernet_list = g_slist_remove(ethernet_list, element);
g_static_mutex_unlock(ðernet_mutex);
+
+ g_free(ethernet);
}
static struct connman_driver ethernet_driver = {
g_io_channel_shutdown(channel, TRUE, NULL);
g_io_channel_unref(channel);
-
- channel = NULL;
}
static int ethernet_init(void)
if (state == STATE_COMPLETED) {
struct connman_element *dhcp;
- dhcp = connman_element_create();
+ dhcp = connman_element_create(NULL);
dhcp->type = CONNMAN_ELEMENT_TYPE_DHCP;
- dhcp->netdev.index = element->netdev.index;
- dhcp->netdev.name = g_strdup(element->netdev.name);
+ dhcp->index = element->index;
dhcp_element = dhcp;
element = find_element(data, network->identifier);
if (element == NULL) {
- element = connman_element_create();
+ element = connman_element_create(temp);
element->type = CONNMAN_ELEMENT_TYPE_NETWORK;
- element->name = temp;
+ element->index = parent->index;
element->network.identifier = g_strdup(network->identifier);
- element->netdev.index = parent->netdev.index;
- element->netdev.name = g_strdup(parent->netdev.name);
-
data->list = g_slist_append(data->list, element);
connman_element_add_static_property(element, "SSID",
DBUS_TYPE_STRING, &network->identifier);
connman_element_register(element, parent);
- } else
- g_free(temp);
+ }
g_static_mutex_unlock(&data->mutex);
+
+ g_free(temp);
}
static struct supplicant_callback wifi_callback = {