Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 314187
b: refs/heads/master
c: fc40a8c
h: refs/heads/master
i:
  314185: 39b2288
  314183: f22ebc9
v: v3
  • Loading branch information
Samuel Ortiz committed Jun 4, 2012
1 parent 9e8994e commit 66beb48
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ad3823cef650bdc1ca9e7bf1a01b87ad3c0425de
refs/heads/master: fc40a8c1a06ab7db45da790693dd9802612a055c
27 changes: 25 additions & 2 deletions trunk/drivers/nfc/pn533.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ struct pn533_cmd_jump_dep_response {
#define PN533_INIT_TARGET_PASSIVE 0x1
#define PN533_INIT_TARGET_DEP 0x2

#define PN533_INIT_TARGET_RESP_FRAME_MASK 0x3
#define PN533_INIT_TARGET_RESP_ACTIVE 0x1
#define PN533_INIT_TARGET_RESP_DEP 0x4

struct pn533_cmd_init_target {
u8 mode;
u8 mifare[6];
Expand Down Expand Up @@ -1128,10 +1132,13 @@ static int pn533_init_target_frame(struct pn533_frame *frame,
return 0;
}

#define ATR_REQ_GB_OFFSET 17
static int pn533_init_target_complete(struct pn533 *dev, void *arg,
u8 *params, int params_len)
{
struct pn533_cmd_init_target_response *resp;
u8 frame, comm_mode = NFC_COMM_PASSIVE, *gb;
size_t gb_len;

nfc_dev_dbg(&dev->interface->dev, "%s", __func__);

Expand All @@ -1143,11 +1150,27 @@ static int pn533_init_target_complete(struct pn533 *dev, void *arg,
return params_len;
}

if (params_len < ATR_REQ_GB_OFFSET + 1)
return -EINVAL;

resp = (struct pn533_cmd_init_target_response *) params;

nfc_dev_dbg(&dev->interface->dev, "Target mode 0x%x\n", resp->mode);
nfc_dev_dbg(&dev->interface->dev, "Target mode 0x%x param len %d\n",
resp->mode, params_len);

return 0;
frame = resp->mode & PN533_INIT_TARGET_RESP_FRAME_MASK;
if (frame == PN533_INIT_TARGET_RESP_ACTIVE)
comm_mode = NFC_COMM_ACTIVE;

/* Again, only DEP */
if ((resp->mode & PN533_INIT_TARGET_RESP_DEP) == 0)
return -EOPNOTSUPP;

gb = resp->cmd + ATR_REQ_GB_OFFSET;
gb_len = params_len - (ATR_REQ_GB_OFFSET + 1);

return nfc_tm_activated(dev->nfc_dev, NFC_PROTO_NFC_DEP_MASK,
comm_mode, gb, gb_len);
}

static int pn533_init_target(struct nfc_dev *nfc_dev, u32 protocols)
Expand Down
7 changes: 7 additions & 0 deletions trunk/include/linux/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
* %NFC_ATTR_PROTOCOLS)
* @NFC_EVENT_DEVICE_REMOVED: event emitted when a device is removed
* (it sends %NFC_ATTR_DEVICE_INDEX)
* @NFC_EVENT_TM_ACTIVATED: event emitted when the adapter is activated in
* target mode.
* @NFC_EVENT_DEVICE_DEACTIVATED: event emitted when the adapter is deactivated
* from target mode.
*/
enum nfc_commands {
NFC_CMD_UNSPEC,
Expand All @@ -71,6 +75,8 @@ enum nfc_commands {
NFC_EVENT_DEVICE_ADDED,
NFC_EVENT_DEVICE_REMOVED,
NFC_EVENT_TARGET_LOST,
NFC_EVENT_TM_ACTIVATED,
NFC_EVENT_TM_DEACTIVATED,
/* private: internal use only */
__NFC_CMD_AFTER_LAST
};
Expand Down Expand Up @@ -122,6 +128,7 @@ enum nfc_attrs {
#define NFC_NFCID1_MAXSIZE 10
#define NFC_SENSB_RES_MAXSIZE 12
#define NFC_SENSF_RES_MAXSIZE 18
#define NFC_GB_MAXSIZE 48

/* NFC protocols */
#define NFC_PROTO_JEWEL 1
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/net/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx);
int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
u8 comm_mode, u8 rf_mode);

int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
u8 *gb, size_t gb_len);
int nfc_tm_deactivated(struct nfc_dev *dev);

#endif /* __NET_NFC_H */
35 changes: 35 additions & 0 deletions trunk/net/nfc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,41 @@ u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len)
}
EXPORT_SYMBOL(nfc_get_local_general_bytes);

int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
u8 *gb, size_t gb_len)
{
int rc;

device_lock(&dev->dev);

dev->polling = false;

if (gb != NULL) {
rc = nfc_set_remote_general_bytes(dev, gb, gb_len);
if (rc < 0)
goto out;
}

if (protocol == NFC_PROTO_NFC_DEP_MASK)
nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET);

rc = nfc_genl_tm_activated(dev, protocol);

out:
device_unlock(&dev->dev);

return rc;
}
EXPORT_SYMBOL(nfc_tm_activated);

int nfc_tm_deactivated(struct nfc_dev *dev)
{
dev->dep_link_up = false;

return nfc_genl_tm_deactivated(dev);
}
EXPORT_SYMBOL(nfc_tm_deactivated);

/**
* nfc_alloc_send_skb - allocate a skb for data exchange responses
*
Expand Down
62 changes: 62 additions & 0 deletions trunk/net/nfc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,68 @@ int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
return -EMSGSIZE;
}

int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
{
struct sk_buff *msg;
void *hdr;

msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;

hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
NFC_EVENT_TM_ACTIVATED);
if (!hdr)
goto free_msg;

if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
goto nla_put_failure;
if (nla_put_u32(msg, NFC_ATTR_TM_PROTOCOLS, protocol))
goto nla_put_failure;

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

nla_put_failure:
genlmsg_cancel(msg, hdr);
free_msg:
nlmsg_free(msg);
return -EMSGSIZE;
}

int nfc_genl_tm_deactivated(struct nfc_dev *dev)
{
struct sk_buff *msg;
void *hdr;

msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;

hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
NFC_EVENT_TM_DEACTIVATED);
if (!hdr)
goto free_msg;

if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
goto nla_put_failure;

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

nla_put_failure:
genlmsg_cancel(msg, hdr);
free_msg:
nlmsg_free(msg);
return -EMSGSIZE;
}

int nfc_genl_device_added(struct nfc_dev *dev)
{
struct sk_buff *msg;
Expand Down
3 changes: 3 additions & 0 deletions trunk/net/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
u8 comm_mode, u8 rf_mode);
int nfc_genl_dep_link_down_event(struct nfc_dev *dev);

int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol);
int nfc_genl_tm_deactivated(struct nfc_dev *dev);

struct nfc_dev *nfc_get_device(unsigned int idx);

static inline void nfc_put_device(struct nfc_dev *dev)
Expand Down

0 comments on commit 66beb48

Please sign in to comment.