Skip to content

Commit

Permalink
NFC Digital: Implement driver commands mechanism
Browse files Browse the repository at this point in the history
This implements the mechanism used to send commands to the driver in
initiator mode through in_send_cmd().

Commands are serialized and sent to the driver by using a work item
on the system workqueue. Responses are handled asynchronously by
another work item. Once the digital stack receives the response through
the command_complete callback, the next command is sent to the driver.

This also implements the polling mechanism. It's handled by a work item
cycling on all supported protocols. The start poll command for a given
protocol is sent to the driver using the mechanism described above.
The process continues until a peer is discovered or stop_poll is
called. This patch implements the poll function for NFC-A that sends a
SENS_REQ command and waits for the SENS_RES response.

Signed-off-by: Thierry Escande <thierry.escande@linux.intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Thierry Escande authored and Samuel Ortiz committed Sep 25, 2013
1 parent 4b10884 commit 59ee236
Show file tree
Hide file tree
Showing 5 changed files with 452 additions and 8 deletions.
25 changes: 25 additions & 0 deletions include/net/nfc/digital.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ struct nfc_digital_ops {
void (*abort_cmd)(struct nfc_digital_dev *ddev);
};

#define NFC_DIGITAL_POLL_MODE_COUNT_MAX 6 /* 106A, 212F, and 424F in & tg */

typedef int (*digital_poll_t)(struct nfc_digital_dev *ddev, u8 rf_tech);

struct digital_poll_tech {
u8 rf_tech;
digital_poll_t poll_func;
};

/**
* Driver capabilities - bit mask made of the following values
*
Expand All @@ -168,6 +177,22 @@ struct nfc_digital_dev {

u32 driver_capabilities;
void *driver_data;

struct digital_poll_tech poll_techs[NFC_DIGITAL_POLL_MODE_COUNT_MAX];
u8 poll_tech_count;
u8 poll_tech_index;
struct mutex poll_lock;

struct work_struct cmd_work;
struct work_struct cmd_complete_work;
struct list_head cmd_queue;
struct mutex cmd_lock;

struct work_struct poll_work;

u8 curr_protocol;
u8 curr_rf_tech;
u8 curr_nfc_dep_pni;
};

struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
Expand Down
2 changes: 1 addition & 1 deletion net/nfc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ obj-$(CONFIG_NFC_DIGITAL) += nfc_digital.o
nfc-objs := core.o netlink.o af_nfc.o rawsock.o llcp_core.o llcp_commands.o \
llcp_sock.o

nfc_digital-objs := digital_core.o
nfc_digital-objs := digital_core.o digital_technology.o
29 changes: 29 additions & 0 deletions net/nfc/digital.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,33 @@
#define PROTOCOL_ERR(req) pr_err("%s:%d: NFC Digital Protocol error: %s\n", \
__func__, __LINE__, req)

#define DIGITAL_CMD_IN_SEND 0
#define DIGITAL_CMD_TG_SEND 1
#define DIGITAL_CMD_TG_LISTEN 2
#define DIGITAL_CMD_TG_LISTEN_MDAA 3

#define DIGITAL_MAX_HEADER_LEN 7
#define DIGITAL_CRC_LEN 2

struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
unsigned int len);

int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
struct sk_buff *skb, u16 timeout,
nfc_digital_cmd_complete_t cmd_cb, void *cb_context);

int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
static inline int digital_in_send_cmd(struct nfc_digital_dev *ddev,
struct sk_buff *skb, u16 timeout,
nfc_digital_cmd_complete_t cmd_cb,
void *cb_context)
{
return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, timeout, cmd_cb,
cb_context);
}

void digital_poll_next_tech(struct nfc_digital_dev *ddev);

int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech);

#endif /* __DIGITAL_H */
Loading

0 comments on commit 59ee236

Please sign in to comment.