From: Samuel Ortiz <sameo@linux.intel.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: Lauro Ramos Venancio <lauro.venancio@openbossa.org>,
Aloisio Almeida Jr <aloisio.almeida@openbossa.org>,
Ilan Elias <ilane@ti.com>,
linux-wireless@vger.kernel.org, linux-nfc@lists.01.org,
Samuel Ortiz <sameo@linux.intel.com>
Subject: [PATCH 08/29] NFC: Implement pn533 target mode polling loop
Date: Wed, 6 Jun 2012 12:16:25 +0200 [thread overview]
Message-ID: <1338977806-30279-9-git-send-email-sameo@linux.intel.com> (raw)
In-Reply-To: <1338977806-30279-1-git-send-email-sameo@linux.intel.com>
We only want to support p2p target mode for now, no host card emulation.
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
---
drivers/nfc/pn533.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 104 insertions(+), 5 deletions(-)
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c
index 38a523c..605a08a 100644
--- a/drivers/nfc/pn533.c
+++ b/drivers/nfc/pn533.c
@@ -74,6 +74,8 @@ MODULE_DEVICE_TABLE(usb, pn533_table);
#define PN533_CMD_IN_RELEASE 0x52
#define PN533_CMD_IN_JUMP_FOR_DEP 0x56
+#define PN533_CMD_TG_INIT_AS_TARGET 0x8c
+
#define PN533_CMD_RESPONSE(cmd) (cmd + 1)
/* PN533 Return codes */
@@ -253,6 +255,25 @@ struct pn533_cmd_jump_dep_response {
u8 gt[];
} __packed;
+
+/* PN533_TG_INIT_AS_TARGET */
+#define PN533_INIT_TARGET_PASSIVE 0x1
+#define PN533_INIT_TARGET_DEP 0x2
+
+struct pn533_cmd_init_target {
+ u8 mode;
+ u8 mifare[6];
+ u8 felica[18];
+ u8 nfcid3[10];
+ u8 gb_len;
+ u8 gb[];
+} __packed;
+
+struct pn533_cmd_init_target_response {
+ u8 mode;
+ u8 cmd[];
+} __packed;
+
struct pn533 {
struct usb_device *udev;
struct usb_interface *interface;
@@ -1078,11 +1099,88 @@ stop_poll:
return 0;
}
-static int pn533_init_target(struct nfc_dev *nfc_dev, u32 protocols)
+static int pn533_init_target_frame(struct pn533_frame *frame,
+ u8 *gb, size_t gb_len)
{
+ struct pn533_cmd_init_target *cmd;
+ size_t cmd_len;
+
+ cmd_len = sizeof(struct pn533_cmd_init_target) + gb_len + 1;
+ cmd = kzalloc(cmd_len, GFP_KERNEL);
+ if (cmd == NULL)
+ return -ENOMEM;
+
+ pn533_tx_frame_init(frame, PN533_CMD_TG_INIT_AS_TARGET);
+
+ /* DEP support only */
+ cmd->mode |= PN533_INIT_TARGET_DEP;
+ get_random_bytes(cmd->nfcid3, 10);
+ cmd->gb_len = gb_len;
+ memcpy(cmd->gb, gb, gb_len);
+ /* Len Tk */
+ cmd->gb[gb_len] = 0;
+
+ memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), cmd, cmd_len);
+ frame->datalen += cmd_len;
+
+ pn533_tx_frame_finish(frame);
+
return 0;
}
+static int pn533_init_target_complete(struct pn533 *dev, void *arg,
+ u8 *params, int params_len)
+{
+ struct pn533_cmd_init_target_response *resp;
+
+ nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
+
+ if (params_len < 0) {
+ nfc_dev_err(&dev->interface->dev,
+ "Error %d when starting as a target",
+ params_len);
+
+ return params_len;
+ }
+
+ resp = (struct pn533_cmd_init_target_response *) params;
+
+ nfc_dev_dbg(&dev->interface->dev, "Target mode 0x%x\n", resp->mode);
+
+ return 0;
+}
+
+static int pn533_init_target(struct nfc_dev *nfc_dev, u32 protocols)
+{
+ struct pn533 *dev = nfc_get_drvdata(nfc_dev);
+ u8 *gb;
+ size_t gb_len;
+ int rc;
+
+ pn533_poll_reset_mod_list(dev);
+
+ gb = nfc_get_local_general_bytes(nfc_dev, &gb_len);
+ if (gb == NULL)
+ return -ENOMEM;
+
+ rc = pn533_init_target_frame(dev->out_frame, gb, gb_len);
+ if (rc < 0)
+ return rc;
+
+ rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
+ dev->in_maxlen,
+ pn533_init_target_complete,
+ NULL, GFP_KERNEL);
+
+ if (rc)
+ nfc_dev_err(&dev->interface->dev,
+ "Error %d when trying to initiate as a target", rc);
+
+ dev->poll_mod_count++;
+
+ return rc;
+}
+
static int pn533_start_im_poll(struct nfc_dev *nfc_dev, u32 protocols)
{
struct pn533 *dev = nfc_get_drvdata(nfc_dev);
@@ -1146,12 +1244,13 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev,
return -EBUSY;
}
- if (!tm_protocols)
+ if (im_protocols)
return pn533_start_im_poll(nfc_dev, im_protocols);
- else if (!im_protocols)
+
+ if (tm_protocols)
return pn533_init_target(nfc_dev, tm_protocols);
- else
- return -EINVAL;
+
+ return -EINVAL;
}
static void pn533_stop_poll(struct nfc_dev *nfc_dev)
--
1.7.9.1
next prev parent reply other threads:[~2012-06-06 10:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-06 10:16 [PATCH 00/29] NFC updates for 3.6 Samuel Ortiz
2012-06-06 10:16 ` [PATCH 01/29] NFC: Take a reference on the LLCP local pointer when creating a socket Samuel Ortiz
2012-06-06 10:16 ` [PATCH 02/29] NFC: Socket linked list Samuel Ortiz
2012-06-06 10:16 ` [PATCH 03/29] NFC: Move LLCP receiver window value to socket structure Samuel Ortiz
2012-06-06 10:16 ` [PATCH 04/29] NFC: Move LLCP MIU extension " Samuel Ortiz
2012-06-06 10:16 ` [PATCH 05/29] NFC: LLCP's MIUX is 10 bytes long, not 7 Samuel Ortiz
2012-06-06 10:16 ` [PATCH 06/29] NFC: Export LLCP general bytes getter Samuel Ortiz
2012-06-06 10:16 ` [PATCH 07/29] NFC: Add target mode protocols to the polling loop startup routine Samuel Ortiz
2012-06-06 10:16 ` Samuel Ortiz [this message]
2012-06-06 10:16 ` [PATCH 09/29] NFC: Add target mode activation netlink event Samuel Ortiz
2012-06-06 10:16 ` [PATCH 10/29] NFC: Set the NFC device RF mode appropriately Samuel Ortiz
2012-06-06 10:16 ` [PATCH 11/29] NFC: Introduce target mode tx ops Samuel Ortiz
2012-06-06 10:16 ` [PATCH 12/29] NFC: Introduce target mode rx data callback Samuel Ortiz
2012-06-06 10:16 ` [PATCH 13/29] NFC: Implement the pn533 target mode data fetching routine Samuel Ortiz
2012-06-06 10:16 ` [PATCH 14/29] NFC: Implement the pn533 target mode Tx op Samuel Ortiz
2012-06-06 10:16 ` [PATCH 15/29] NFC: Don't hold a NULL connecting LLCP socket lock Samuel Ortiz
2012-06-06 10:16 ` [PATCH 16/29] NFC: Call the DEP link down ops even when in target mode Samuel Ortiz
2012-06-06 10:16 ` [PATCH 17/29] NFC: Reset poll mod list when stopping pn533 poll Samuel Ortiz
2012-06-06 10:16 ` [PATCH 18/29] NFC: Unregister device if pn533 initial configuration fails Samuel Ortiz
2012-06-06 10:16 ` [PATCH 19/29] NFC: Configure pn533 RF timings Samuel Ortiz
2012-06-06 10:16 ` [PATCH 20/29] NFC: Add passive initiator data for pn533 Samuel Ortiz
2012-06-06 10:16 ` [PATCH 21/29] NFC: Add type A and type F parameters for pn533 target mode Samuel Ortiz
2012-06-06 10:16 ` [PATCH 22/29] NFC: Implement pn533 polling loop Samuel Ortiz
2012-06-06 10:16 ` [PATCH 23/29] NFC: Requeue lost LLCP frames Samuel Ortiz
2012-06-06 10:16 ` [PATCH 24/29] NFC: Send a receiver ready frame only to reply to an I frame Samuel Ortiz
2012-06-06 10:16 ` [PATCH 25/29] NFC: Switch to Initiator mode when getting NFC_ATTR_PROTOCOLS Samuel Ortiz
2012-06-06 10:16 ` [PATCH 26/29] NFC: Destroy LLCP timout workqueue when releasing the link Samuel Ortiz
2012-06-06 10:16 ` [PATCH 27/29] NFC: Set the proper baud rate when trying to activate pn533 targets Samuel Ortiz
2012-06-06 10:16 ` [PATCH 28/29] NFC: Convert pn533 from semaphore to mutex Samuel Ortiz
2012-06-06 10:16 ` [PATCH 29/29] NFC: Monitor pn533 target mode Samuel Ortiz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338977806-30279-9-git-send-email-sameo@linux.intel.com \
--to=sameo@linux.intel.com \
--cc=aloisio.almeida@openbossa.org \
--cc=ilane@ti.com \
--cc=lauro.venancio@openbossa.org \
--cc=linux-nfc@lists.01.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).