aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/nfc
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/nfc')
-rw-r--r--Documentation/nfc/nfc-hci.txt129
1 files changed, 103 insertions, 26 deletions
diff --git a/Documentation/nfc/nfc-hci.txt b/Documentation/nfc/nfc-hci.txt
index 89a339c9b079..0686c9e211c2 100644
--- a/Documentation/nfc/nfc-hci.txt
+++ b/Documentation/nfc/nfc-hci.txt
@@ -17,10 +17,12 @@ HCI
17HCI registers as an nfc device with NFC Core. Requests coming from userspace are 17HCI registers as an nfc device with NFC Core. Requests coming from userspace are
18routed through netlink sockets to NFC Core and then to HCI. From this point, 18routed through netlink sockets to NFC Core and then to HCI. From this point,
19they are translated in a sequence of HCI commands sent to the HCI layer in the 19they are translated in a sequence of HCI commands sent to the HCI layer in the
20host controller (the chip). The sending context blocks while waiting for the 20host controller (the chip). Commands can be executed synchronously (the sending
21response to arrive. 21context blocks waiting for response) or asynchronously (the response is returned
22from HCI Rx context).
22HCI events can also be received from the host controller. They will be handled 23HCI events can also be received from the host controller. They will be handled
23and a translation will be forwarded to NFC Core as needed. 24and a translation will be forwarded to NFC Core as needed. There are hooks to
25let the HCI driver handle proprietary events or override standard behavior.
24HCI uses 2 execution contexts: 26HCI uses 2 execution contexts:
25- one for executing commands : nfc_hci_msg_tx_work(). Only one command 27- one for executing commands : nfc_hci_msg_tx_work(). Only one command
26can be executing at any given moment. 28can be executing at any given moment.
@@ -33,6 +35,8 @@ The Session initialization is an HCI standard which must unfortunately
33support proprietary gates. This is the reason why the driver will pass a list 35support proprietary gates. This is the reason why the driver will pass a list
34of proprietary gates that must be part of the session. HCI will ensure all 36of proprietary gates that must be part of the session. HCI will ensure all
35those gates have pipes connected when the hci device is set up. 37those gates have pipes connected when the hci device is set up.
38In case the chip supports pre-opened gates and pseudo-static pipes, the driver
39can pass that information to HCI core.
36 40
37HCI Gates and Pipes 41HCI Gates and Pipes
38------------------- 42-------------------
@@ -46,6 +50,13 @@ without knowing the pipe connected to it.
46Driver interface 50Driver interface
47---------------- 51----------------
48 52
53A driver is generally written in two parts : the physical link management and
54the HCI management. This makes it easier to maintain a driver for a chip that
55can be connected using various phy (i2c, spi, ...)
56
57HCI Management
58--------------
59
49A driver would normally register itself with HCI and provide the following 60A driver would normally register itself with HCI and provide the following
50entry points: 61entry points:
51 62
@@ -53,58 +64,113 @@ struct nfc_hci_ops {
53 int (*open)(struct nfc_hci_dev *hdev); 64 int (*open)(struct nfc_hci_dev *hdev);
54 void (*close)(struct nfc_hci_dev *hdev); 65 void (*close)(struct nfc_hci_dev *hdev);
55 int (*hci_ready) (struct nfc_hci_dev *hdev); 66 int (*hci_ready) (struct nfc_hci_dev *hdev);
56 int (*xmit)(struct nfc_hci_dev *hdev, struct sk_buff *skb); 67 int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
57 int (*start_poll)(struct nfc_hci_dev *hdev, u32 protocols); 68 int (*start_poll) (struct nfc_hci_dev *hdev,
58 int (*target_from_gate)(struct nfc_hci_dev *hdev, u8 gate, 69 u32 im_protocols, u32 tm_protocols);
59 struct nfc_target *target); 70 int (*dep_link_up)(struct nfc_hci_dev *hdev, struct nfc_target *target,
71 u8 comm_mode, u8 *gb, size_t gb_len);
72 int (*dep_link_down)(struct nfc_hci_dev *hdev);
73 int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
74 struct nfc_target *target);
60 int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate, 75 int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,
61 struct nfc_target *target); 76 struct nfc_target *target);
62 int (*data_exchange) (struct nfc_hci_dev *hdev, 77 int (*im_transceive) (struct nfc_hci_dev *hdev,
63 struct nfc_target *target, 78 struct nfc_target *target, struct sk_buff *skb,
64 struct sk_buff *skb, struct sk_buff **res_skb); 79 data_exchange_cb_t cb, void *cb_context);
80 int (*tm_send)(struct nfc_hci_dev *hdev, struct sk_buff *skb);
65 int (*check_presence)(struct nfc_hci_dev *hdev, 81 int (*check_presence)(struct nfc_hci_dev *hdev,
66 struct nfc_target *target); 82 struct nfc_target *target);
83 int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
84 struct sk_buff *skb);
67}; 85};
68 86
69- open() and close() shall turn the hardware on and off. 87- open() and close() shall turn the hardware on and off.
70- hci_ready() is an optional entry point that is called right after the hci 88- hci_ready() is an optional entry point that is called right after the hci
71session has been set up. The driver can use it to do additional initialization 89session has been set up. The driver can use it to do additional initialization
72that must be performed using HCI commands. 90that must be performed using HCI commands.
73- xmit() shall simply write a frame to the chip. 91- xmit() shall simply write a frame to the physical link.
74- start_poll() is an optional entrypoint that shall set the hardware in polling 92- start_poll() is an optional entrypoint that shall set the hardware in polling
75mode. This must be implemented only if the hardware uses proprietary gates or a 93mode. This must be implemented only if the hardware uses proprietary gates or a
76mechanism slightly different from the HCI standard. 94mechanism slightly different from the HCI standard.
95- dep_link_up() is called after a p2p target has been detected, to finish
96the p2p connection setup with hardware parameters that need to be passed back
97to nfc core.
98- dep_link_down() is called to bring the p2p link down.
77- target_from_gate() is an optional entrypoint to return the nfc protocols 99- target_from_gate() is an optional entrypoint to return the nfc protocols
78corresponding to a proprietary gate. 100corresponding to a proprietary gate.
79- complete_target_discovered() is an optional entry point to let the driver 101- complete_target_discovered() is an optional entry point to let the driver
80perform additional proprietary processing necessary to auto activate the 102perform additional proprietary processing necessary to auto activate the
81discovered target. 103discovered target.
82- data_exchange() must be implemented by the driver if proprietary HCI commands 104- im_transceive() must be implemented by the driver if proprietary HCI commands
83are required to send data to the tag. Some tag types will require custom 105are required to send data to the tag. Some tag types will require custom
84commands, others can be written to using the standard HCI commands. The driver 106commands, others can be written to using the standard HCI commands. The driver
85can check the tag type and either do proprietary processing, or return 1 to ask 107can check the tag type and either do proprietary processing, or return 1 to ask
86for standard processing. 108for standard processing. The data exchange command itself must be sent
109asynchronously.
110- tm_send() is called to send data in the case of a p2p connection
87- check_presence() is an optional entry point that will be called regularly 111- check_presence() is an optional entry point that will be called regularly
88by the core to check that an activated tag is still in the field. If this is 112by the core to check that an activated tag is still in the field. If this is
89not implemented, the core will not be able to push tag_lost events to the user 113not implemented, the core will not be able to push tag_lost events to the user
90space 114space
115- event_received() is called to handle an event coming from the chip. Driver
116can handle the event or return 1 to let HCI attempt standard processing.
91 117
92On the rx path, the driver is responsible to push incoming HCP frames to HCI 118On the rx path, the driver is responsible to push incoming HCP frames to HCI
93using nfc_hci_recv_frame(). HCI will take care of re-aggregation and handling 119using nfc_hci_recv_frame(). HCI will take care of re-aggregation and handling
94This must be done from a context that can sleep. 120This must be done from a context that can sleep.
95 121
96SHDLC 122PHY Management
97----- 123--------------
124
125The physical link (i2c, ...) management is defined by the following struture:
126
127struct nfc_phy_ops {
128 int (*write)(void *dev_id, struct sk_buff *skb);
129 int (*enable)(void *dev_id);
130 void (*disable)(void *dev_id);
131};
132
133enable(): turn the phy on (power on), make it ready to transfer data
134disable(): turn the phy off
135write(): Send a data frame to the chip. Note that to enable higher
136layers such as an llc to store the frame for re-emission, this function must
137not alter the skb. It must also not return a positive result (return 0 for
138success, negative for failure).
139
140Data coming from the chip shall be sent directly to nfc_hci_recv_frame().
141
142LLC
143---
144
145Communication between the CPU and the chip often requires some link layer
146protocol. Those are isolated as modules managed by the HCI layer. There are
147currently two modules : nop (raw transfert) and shdlc.
148A new llc must implement the following functions:
149
150struct nfc_llc_ops {
151 void *(*init) (struct nfc_hci_dev *hdev, xmit_to_drv_t xmit_to_drv,
152 rcv_to_hci_t rcv_to_hci, int tx_headroom,
153 int tx_tailroom, int *rx_headroom, int *rx_tailroom,
154 llc_failure_t llc_failure);
155 void (*deinit) (struct nfc_llc *llc);
156 int (*start) (struct nfc_llc *llc);
157 int (*stop) (struct nfc_llc *llc);
158 void (*rcv_from_drv) (struct nfc_llc *llc, struct sk_buff *skb);
159 int (*xmit_from_hci) (struct nfc_llc *llc, struct sk_buff *skb);
160};
161
162- init() : allocate and init your private storage
163- deinit() : cleanup
164- start() : establish the logical connection
165- stop () : terminate the logical connection
166- rcv_from_drv() : handle data coming from the chip, going to HCI
167- xmit_from_hci() : handle data sent by HCI, going to the chip
98 168
99Most chips use shdlc to ensure integrity and delivery ordering of the HCP 169The llc must be registered with nfc before it can be used. Do that by
100frames between the host controller (the chip) and hosts (entities connected 170calling nfc_llc_register(const char *name, struct nfc_llc_ops *ops);
101to the chip, like the cpu). In order to simplify writing the driver, an shdlc 171
102layer is available for use by the driver. 172Again, note that the llc does not handle the physical link. It is thus very
103When used, the driver actually registers with shdlc, and shdlc will register 173easy to mix any physical link with any llc for a given chip driver.
104with HCI. HCI sees shdlc as the driver and thus send its HCP frames
105through shdlc->xmit.
106SHDLC adds a new execution context (nfc_shdlc_sm_work()) to run its state
107machine and handle both its rx and tx path.
108 174
109Included Drivers 175Included Drivers
110---------------- 176----------------
@@ -117,10 +183,12 @@ Execution Contexts
117 183
118The execution contexts are the following: 184The execution contexts are the following:
119- IRQ handler (IRQH): 185- IRQ handler (IRQH):
120fast, cannot sleep. stores incoming frames into an shdlc rx queue 186fast, cannot sleep. sends incoming frames to HCI where they are passed to
187the current llc. In case of shdlc, the frame is queued in shdlc rx queue.
121 188
122- SHDLC State Machine worker (SMW) 189- SHDLC State Machine worker (SMW)
123handles shdlc rx & tx queues. Dispatches HCI cmd responses. 190Only when llc_shdlc is used: handles shdlc rx & tx queues.
191Dispatches HCI cmd responses.
124 192
125- HCI Tx Cmd worker (MSGTXWQ) 193- HCI Tx Cmd worker (MSGTXWQ)
126Serializes execution of HCI commands. Completes execution in case of response 194Serializes execution of HCI commands. Completes execution in case of response
@@ -166,6 +234,15 @@ waiting command execution. Response processing involves invoking the completion
166callback that was provided by nfc_hci_msg_tx_work() when it sent the command. 234callback that was provided by nfc_hci_msg_tx_work() when it sent the command.
167The completion callback will then wake the syscall context. 235The completion callback will then wake the syscall context.
168 236
237It is also possible to execute the command asynchronously using this API:
238
239static int nfc_hci_execute_cmd_async(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
240 const u8 *param, size_t param_len,
241 data_exchange_cb_t cb, void *cb_context)
242
243The workflow is the same, except that the API call returns immediately, and
244the callback will be called with the result from the SMW context.
245
169Workflow receiving an HCI event or command 246Workflow receiving an HCI event or command
170------------------------------------------ 247------------------------------------------
171 248