netlink: Add target selection API
authorSamuel Ortiz <sameo@linux.intel.com>
Fri, 29 Apr 2011 22:12:26 +0000 (00:12 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 21 Oct 2011 06:54:02 +0000 (23:54 -0700)
include/types.h
src/near.h
src/netlink.c

index fd8d790..09b45ad 100644 (file)
@@ -33,5 +33,6 @@
 typedef int    near_bool_t;
 typedef unsigned char  near_uint8_t;
 typedef unsigned short near_uint16_t;
+typedef unsigned int   near_uint32_t;
 
 #endif
index c4253b0..5133097 100644 (file)
@@ -98,6 +98,11 @@ int __near_tag_read(struct near_target *target, void *buf, size_t length);
 int __near_netlink_get_adapters(void);
 int __near_netlink_start_poll(int idx, guint32 protocols);
 int __near_netlink_stop_poll(int idx);
+int __near_netlink_activate_target(near_uint32_t adapter_idx,
+                                       near_uint32_t target_idx,
+                                       near_uint32_t protocol);
+int __near_netlink_deactivate_target(near_uint32_t adapter_idx,
+                                       near_uint32_t target_idx);
 int __near_netlink_init(void);
 void __near_netlink_cleanup(void);
 
index 65540d7..77d1fdf 100644 (file)
@@ -242,6 +242,76 @@ nla_put_failure:
        return err;
 }
 
+int __near_netlink_activate_target(near_uint32_t adapter_idx,
+                                       near_uint32_t target_idx,
+                                       near_uint32_t protocol)
+{
+       struct nl_msg *msg;
+       void *hdr;
+       int family, err = 0;
+
+       DBG("");
+
+       msg = nlmsg_alloc();
+       if (msg == NULL)
+               return -ENOMEM;
+
+       family = genl_family_get_id(nfc_state->nlnfc);
+
+       hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0,
+                       NLM_F_REQUEST, NFC_CMD_ACTIVATE_TARGET,
+                       NFC_GENL_VERSION);
+       if (hdr == NULL) {
+               err = -EINVAL;
+               goto nla_put_failure;
+       }
+
+       NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, adapter_idx);
+       NLA_PUT_U32(msg, NFC_ATTR_TARGET_INDEX, target_idx);
+       NLA_PUT_U32(msg, NFC_ATTR_PROTOCOLS, protocol);
+
+       err = nl_send_msg(nfc_state->nl_sock, msg, NULL, NULL);
+
+nla_put_failure:
+       nlmsg_free(msg);
+
+       return err;
+}
+
+int __near_netlink_deactivate_target(near_uint32_t adapter_idx,
+                                       near_uint32_t target_idx)
+{
+       struct nl_msg *msg;
+       void *hdr;
+       int family, err = 0;
+
+       DBG("");
+
+       msg = nlmsg_alloc();
+       if (msg == NULL)
+               return -ENOMEM;
+
+       family = genl_family_get_id(nfc_state->nlnfc);
+
+       hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0,
+                       NLM_F_REQUEST, NFC_CMD_DEACTIVATE_TARGET,
+                       NFC_GENL_VERSION);
+       if (hdr == NULL) {
+               err = -EINVAL;
+               goto nla_put_failure;
+       }
+
+       NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, adapter_idx);
+       NLA_PUT_U32(msg, NFC_ATTR_TARGET_INDEX, target_idx);
+
+       err = nl_send_msg(nfc_state->nl_sock, msg, NULL, NULL);
+
+nla_put_failure:
+       nlmsg_free(msg);
+
+       return err;
+}
+
 static int no_seq_check(struct nl_msg *n, void *arg)
 {
        DBG("");