summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2011-04-22 14:46:12 +0200
committerMarcel Holtmann <marcel@holtmann.org>2011-10-20 23:54:00 -0700
commitb667f0f6550fee6607c8fb96491271c932e9e7e7 (patch)
tree335c16e6551bdc89df6865666f9389e46c79a203
parent803eb22cf2a2600cc956cf2e5806acdfec590e14 (diff)
downloadneard-b667f0f6550fee6607c8fb96491271c932e9e7e7.tar.gz
neard-b667f0f6550fee6607c8fb96491271c932e9e7e7.tar.bz2
neard-b667f0f6550fee6607c8fb96491271c932e9e7e7.zip
netlink: Handle device addition/removal event
-rw-r--r--src/netlink.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/netlink.c b/src/netlink.c
index bdd160b..107452a 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -36,6 +36,8 @@
#include <linux/nfc.h>
+#include <types.h>
+
#include "near.h"
struct nlnfc_state {
@@ -182,6 +184,44 @@ static int no_seq_check(struct nl_msg *n, void *arg)
return NL_OK;
}
+static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, near_bool_t add)
+{
+ struct nlattr *attrs[NFC_ATTR_MAX + 1];
+ guint32 idx;
+
+ DBG("");
+
+ nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL);
+ if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ near_error("Missing device index");
+ return -ENODEV;
+ }
+
+ idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
+
+ if (add == TRUE &&
+ (attrs[NFC_ATTR_DEVICE_NAME] == NULL ||
+ attrs[NFC_ATTR_PROTOCOLS] == NULL)) {
+ near_error("Missing attributes");
+ return -EINVAL;
+ }
+
+ if (add == TRUE) {
+ char *name;
+ guint32 protocols;
+
+ name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
+ protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
+
+ return __near_adapter_add(name, idx, protocols);
+ } else {
+ __near_adapter_remove(idx);
+ }
+
+ return 0;
+}
+
static int nfc_netlink_event(struct nl_msg *n, void *arg)
{
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(n));
@@ -194,9 +234,13 @@ static int nfc_netlink_event(struct nl_msg *n, void *arg)
break;
case NFC_EVENT_DEVICE_ADDED:
DBG("Adapter added");
+ nfc_netlink_event_adapter(gnlh, TRUE);
+
break;
case NFC_EVENT_DEVICE_REMOVED:
DBG("Adapter removed");
+ nfc_netlink_event_adapter(gnlh, FALSE);
+
break;
}