From aa844c538bf698eba5799526ca1d246fec9503eb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 30 Dec 2007 04:12:04 +0100 Subject: [PATCH] Add carrier detection callbacks and driver data functions --- include/iface.h | 19 ++++++++++++++++++- src/iface.c | 5 +++++ src/rtnl.c | 19 ++++++++++++++----- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/include/iface.h b/include/iface.h index 930abe79..d4eb2134 100644 --- a/include/iface.h +++ b/include/iface.h @@ -63,7 +63,6 @@ struct connman_network { }; struct connman_iface { - struct connman_iface_driver *driver; char *path; char *udi; char *sysfs; @@ -73,6 +72,9 @@ struct connman_iface { enum connman_iface_flags flags; enum connman_iface_state state; struct connman_ipv4 ipv4; + + struct connman_iface_driver *driver; + void *driver_data; }; struct connman_iface_driver { @@ -90,6 +92,7 @@ struct connman_iface_driver { int (*connect) (struct connman_iface *iface, struct connman_network *network); + void (*rtnl_carrier) (struct connman_iface *iface, int carrier); void (*rtnl_wireless) (struct connman_iface *iface, void *data, unsigned short len); }; @@ -97,9 +100,23 @@ struct connman_iface_driver { extern int connman_iface_register(struct connman_iface_driver *driver); extern void connman_iface_unregister(struct connman_iface_driver *driver); +static inline void *connman_iface_get_data(struct connman_iface *iface) +{ + return iface->driver_data; +} + +static inline void connman_iface_set_data(struct connman_iface *iface, + void *data) +{ + iface->driver_data = data; +} + extern int connman_iface_update(struct connman_iface *iface, enum connman_iface_state state); +extern void connman_iface_indicate_carrier(struct connman_iface *iface, + int carrier); + #ifdef __cplusplus } #endif diff --git a/src/iface.c b/src/iface.c index 72bc142c..a641bf33 100644 --- a/src/iface.c +++ b/src/iface.c @@ -108,6 +108,11 @@ int connman_iface_update(struct connman_iface *iface, return 0; } +void connman_iface_indicate_carrier(struct connman_iface *iface, int carrier) +{ + DBG("iface %p carrier %d", iface, carrier); +} + static DBusMessage *enable_iface(DBusConnection *conn, DBusMessage *msg, void *data) { diff --git a/src/rtnl.c b/src/rtnl.c index 726d4917..33031ffc 100644 --- a/src/rtnl.c +++ b/src/rtnl.c @@ -43,6 +43,12 @@ static inline void print_char(struct rtattr *attr, const char *name) (char *) RTA_DATA(attr)); } +static inline void print_byte(struct rtattr *attr, const char *name) +{ + printf(" attr %s (len %d) 0x%02x\n", name, RTA_PAYLOAD(attr), + *((unsigned char *) RTA_DATA(attr))); +} + static inline void print_attr(struct rtattr *attr, const char *name) { if (name) @@ -71,9 +77,12 @@ static void rtnl_link(struct nlmsghdr *hdr) if ((iface->flags & CONNMAN_IFACE_FLAG_RTNL) == 0) return; - if (iface->carrier != (msg->ifi_flags & IFF_RUNNING)) { - iface->carrier = (msg->ifi_flags & IFF_RUNNING); - DBG("carrier %s", iface->carrier ? "on" : "off"); + if (iface->carrier != ((msg->ifi_flags & IFF_RUNNING) != 0)) { + iface->carrier = ((msg->ifi_flags & IFF_RUNNING) != 0); + if (iface->driver->rtnl_carrier) + iface->driver->rtnl_carrier(iface, iface->carrier); + else + connman_iface_indicate_carrier(iface, iface->carrier); } for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes); @@ -127,10 +136,10 @@ static void rtnl_link(struct nlmsghdr *hdr) print_attr(attr, "weight"); break; case IFLA_OPERSTATE: - print_attr(attr, "operstate"); + print_byte(attr, "operstate"); break; case IFLA_LINKMODE: - print_attr(attr, "linkmode"); + print_byte(attr, "linkmode"); break; default: print_attr(attr, NULL); -- 2.34.1