From: Samuel Ortiz Date: Fri, 29 Apr 2011 22:12:26 +0000 (+0200) Subject: netlink: Add target selection API X-Git-Tag: 0.1~175 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=342ac097b32cb5ae27bd471eb4b3a4c424f4ed0b;p=platform%2Fupstream%2Fneard.git netlink: Add target selection API --- diff --git a/include/types.h b/include/types.h index fd8d790..09b45ad 100644 --- a/include/types.h +++ b/include/types.h @@ -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 diff --git a/src/near.h b/src/near.h index c4253b0..5133097 100644 --- a/src/near.h +++ b/src/near.h @@ -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); diff --git a/src/netlink.c b/src/netlink.c index 65540d7..77d1fdf 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -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("");