aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/nfc
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2012-04-18 14:17:13 -0400
committerJohn W. Linville <linville@tuxdriver.com>2012-04-18 14:27:48 -0400
commit59ef43e681d103a51c3727dad0315e093f07ec61 (patch)
tree87f6320f1440ce3ce6c0c15ad3cef8bc98186f88 /include/net/nfc
parent91fbe33034c184c6a60e31c2207a2f7ec2f180dc (diff)
parentb5abcf0219263f4e961dca71cbe26e06c5b0ee68 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next into for-davem
Conflicts: drivers/net/wireless/iwlwifi/iwl-testmode.c include/net/nfc/nfc.h net/nfc/netlink.c net/wireless/nl80211.c
Diffstat (limited to 'include/net/nfc')
-rw-r--r--include/net/nfc/hci.h198
-rw-r--r--include/net/nfc/nfc.h12
-rw-r--r--include/net/nfc/shdlc.h104
3 files changed, 313 insertions, 1 deletions
diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h
new file mode 100644
index 000000000000..aca65a5a9d0d
--- /dev/null
+++ b/include/net/nfc/hci.h
@@ -0,0 +1,198 @@
1/*
2 * Copyright (C) 2011 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifndef __NET_HCI_H
21#define __NET_HCI_H
22
23#include <linux/skbuff.h>
24
25#include <net/nfc/nfc.h>
26
27struct nfc_hci_dev;
28
29struct nfc_hci_ops {
30 int (*open) (struct nfc_hci_dev *hdev);
31 void (*close) (struct nfc_hci_dev *hdev);
32 int (*hci_ready) (struct nfc_hci_dev *hdev);
33 int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
34 int (*start_poll) (struct nfc_hci_dev *hdev, u32 protocols);
35 int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
36 struct nfc_target *target);
37 int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,
38 struct nfc_target *target);
39 int (*data_exchange) (struct nfc_hci_dev *hdev,
40 struct nfc_target *target,
41 struct sk_buff *skb, struct sk_buff **res_skb);
42};
43
44#define NFC_HCI_MAX_CUSTOM_GATES 15
45struct nfc_hci_init_data {
46 u8 gate_count;
47 u8 gates[NFC_HCI_MAX_CUSTOM_GATES];
48 char session_id[9];
49};
50
51typedef int (*xmit) (struct sk_buff *skb, void *cb_data);
52
53#define NFC_HCI_MAX_GATES 256
54
55struct nfc_hci_dev {
56 struct nfc_dev *ndev;
57
58 u32 max_data_link_payload;
59
60 struct mutex msg_tx_mutex;
61
62 struct list_head msg_tx_queue;
63
64 struct workqueue_struct *msg_tx_wq;
65 struct work_struct msg_tx_work;
66
67 struct timer_list cmd_timer;
68 struct hci_msg *cmd_pending_msg;
69
70 struct sk_buff_head rx_hcp_frags;
71
72 struct workqueue_struct *msg_rx_wq;
73 struct work_struct msg_rx_work;
74
75 struct sk_buff_head msg_rx_queue;
76
77 struct nfc_hci_ops *ops;
78
79 struct nfc_hci_init_data init_data;
80
81 void *clientdata;
82
83 u8 gate2pipe[NFC_HCI_MAX_GATES];
84
85 bool poll_started;
86 struct nfc_target *targets;
87 int target_count;
88
89 u8 sw_romlib;
90 u8 sw_patch;
91 u8 sw_flashlib_major;
92 u8 sw_flashlib_minor;
93
94 u8 hw_derivative;
95 u8 hw_version;
96 u8 hw_mpw;
97 u8 hw_software;
98 u8 hw_bsid;
99};
100
101/* hci device allocation */
102struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
103 struct nfc_hci_init_data *init_data,
104 u32 protocols,
105 int tx_headroom,
106 int tx_tailroom,
107 int max_link_payload);
108void nfc_hci_free_device(struct nfc_hci_dev *hdev);
109
110int nfc_hci_register_device(struct nfc_hci_dev *hdev);
111void nfc_hci_unregister_device(struct nfc_hci_dev *hdev);
112
113void nfc_hci_set_clientdata(struct nfc_hci_dev *hdev, void *clientdata);
114void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev);
115
116/* Host IDs */
117#define NFC_HCI_HOST_CONTROLLER_ID 0x00
118#define NFC_HCI_TERMINAL_HOST_ID 0x01
119#define NFC_HCI_UICC_HOST_ID 0x02
120
121/* Host Controller Gates and registry indexes */
122#define NFC_HCI_ADMIN_GATE 0x00
123#define NFC_HCI_ADMIN_SESSION_IDENTITY 0x01
124#define NFC_HCI_ADMIN_MAX_PIPE 0x02
125#define NFC_HCI_ADMIN_WHITELIST 0x03
126#define NFC_HCI_ADMIN_HOST_LIST 0x04
127
128#define NFC_HCI_LOOPBACK_GATE 0x04
129
130#define NFC_HCI_ID_MGMT_GATE 0x05
131#define NFC_HCI_ID_MGMT_VERSION_SW 0x01
132#define NFC_HCI_ID_MGMT_VERSION_HW 0x03
133#define NFC_HCI_ID_MGMT_VENDOR_NAME 0x04
134#define NFC_HCI_ID_MGMT_MODEL_ID 0x05
135#define NFC_HCI_ID_MGMT_HCI_VERSION 0x02
136#define NFC_HCI_ID_MGMT_GATES_LIST 0x06
137
138#define NFC_HCI_LINK_MGMT_GATE 0x06
139#define NFC_HCI_LINK_MGMT_REC_ERROR 0x01
140
141#define NFC_HCI_RF_READER_B_GATE 0x11
142#define NFC_HCI_RF_READER_B_PUPI 0x03
143#define NFC_HCI_RF_READER_B_APPLICATION_DATA 0x04
144#define NFC_HCI_RF_READER_B_AFI 0x02
145#define NFC_HCI_RF_READER_B_HIGHER_LAYER_RESPONSE 0x01
146#define NFC_HCI_RF_READER_B_HIGHER_LAYER_DATA 0x05
147
148#define NFC_HCI_RF_READER_A_GATE 0x13
149#define NFC_HCI_RF_READER_A_UID 0x02
150#define NFC_HCI_RF_READER_A_ATQA 0x04
151#define NFC_HCI_RF_READER_A_APPLICATION_DATA 0x05
152#define NFC_HCI_RF_READER_A_SAK 0x03
153#define NFC_HCI_RF_READER_A_FWI_SFGT 0x06
154#define NFC_HCI_RF_READER_A_DATARATE_MAX 0x01
155
156#define NFC_HCI_TYPE_A_SEL_PROT(x) (((x) & 0x60) >> 5)
157#define NFC_HCI_TYPE_A_SEL_PROT_MIFARE 0
158#define NFC_HCI_TYPE_A_SEL_PROT_ISO14443 1
159#define NFC_HCI_TYPE_A_SEL_PROT_DEP 2
160#define NFC_HCI_TYPE_A_SEL_PROT_ISO14443_DEP 3
161
162/* Generic events */
163#define NFC_HCI_EVT_HCI_END_OF_OPERATION 0x01
164#define NFC_HCI_EVT_POST_DATA 0x02
165#define NFC_HCI_EVT_HOT_PLUG 0x03
166
167/* Reader RF gates events */
168#define NFC_HCI_EVT_READER_REQUESTED 0x10
169#define NFC_HCI_EVT_END_OPERATION 0x11
170
171/* Reader Application gate events */
172#define NFC_HCI_EVT_TARGET_DISCOVERED 0x10
173
174/* receiving messages from lower layer */
175void nfc_hci_resp_received(struct nfc_hci_dev *hdev, u8 result,
176 struct sk_buff *skb);
177void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
178 struct sk_buff *skb);
179void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
180 struct sk_buff *skb);
181void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb);
182
183/* connecting to gates and sending hci instructions */
184int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate);
185int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate);
186int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev);
187int nfc_hci_get_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
188 struct sk_buff **skb);
189int nfc_hci_set_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
190 const u8 *param, size_t param_len);
191int nfc_hci_send_cmd(struct nfc_hci_dev *hdev, u8 gate, u8 cmd,
192 const u8 *param, size_t param_len, struct sk_buff **skb);
193int nfc_hci_send_response(struct nfc_hci_dev *hdev, u8 gate, u8 response,
194 const u8 *param, size_t param_len);
195int nfc_hci_send_event(struct nfc_hci_dev *hdev, u8 gate, u8 event,
196 const u8 *param, size_t param_len);
197
198#endif /* __NET_HCI_H */
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index 79955a238ccc..9a2505a5b8de 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -62,10 +62,12 @@ struct nfc_ops {
62 int (*data_exchange)(struct nfc_dev *dev, u32 target_idx, 62 int (*data_exchange)(struct nfc_dev *dev, u32 target_idx,
63 struct sk_buff *skb, data_exchange_cb_t cb, 63 struct sk_buff *skb, data_exchange_cb_t cb,
64 void *cb_context); 64 void *cb_context);
65 int (*check_presence)(struct nfc_dev *dev, u32 target_idx);
65}; 66};
66 67
67#define NFC_TARGET_IDX_ANY -1 68#define NFC_TARGET_IDX_ANY -1
68#define NFC_MAX_GT_LEN 48 69#define NFC_MAX_GT_LEN 48
70#define NFC_TARGET_IDX_NONE 0xffffffff
69 71
70struct nfc_target { 72struct nfc_target {
71 u32 idx; 73 u32 idx;
@@ -78,6 +80,8 @@ struct nfc_target {
78 u8 sensb_res[NFC_SENSB_RES_MAXSIZE]; 80 u8 sensb_res[NFC_SENSB_RES_MAXSIZE];
79 u8 sensf_res_len; 81 u8 sensf_res_len;
80 u8 sensf_res[NFC_SENSF_RES_MAXSIZE]; 82 u8 sensf_res[NFC_SENSF_RES_MAXSIZE];
83 u8 hci_reader_gate;
84 u8 logical_idx;
81}; 85};
82 86
83struct nfc_genl_data { 87struct nfc_genl_data {
@@ -87,6 +91,7 @@ struct nfc_genl_data {
87 91
88struct nfc_dev { 92struct nfc_dev {
89 unsigned int idx; 93 unsigned int idx;
94 u32 target_next_idx;
90 struct nfc_target *targets; 95 struct nfc_target *targets;
91 int n_targets; 96 int n_targets;
92 int targets_generation; 97 int targets_generation;
@@ -94,7 +99,7 @@ struct nfc_dev {
94 struct device dev; 99 struct device dev;
95 bool dev_up; 100 bool dev_up;
96 bool polling; 101 bool polling;
97 bool remote_activated; 102 u32 activated_target_idx;
98 bool dep_link_up; 103 bool dep_link_up;
99 u32 dep_rf_mode; 104 u32 dep_rf_mode;
100 struct nfc_genl_data genl_data; 105 struct nfc_genl_data genl_data;
@@ -103,6 +108,10 @@ struct nfc_dev {
103 int tx_headroom; 108 int tx_headroom;
104 int tx_tailroom; 109 int tx_tailroom;
105 110
111 struct timer_list check_pres_timer;
112 struct workqueue_struct *check_pres_wq;
113 struct work_struct check_pres_work;
114
106 struct nfc_ops *ops; 115 struct nfc_ops *ops;
107}; 116};
108#define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev) 117#define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev)
@@ -181,6 +190,7 @@ int nfc_set_remote_general_bytes(struct nfc_dev *dev,
181 190
182int nfc_targets_found(struct nfc_dev *dev, 191int nfc_targets_found(struct nfc_dev *dev,
183 struct nfc_target *targets, int ntargets); 192 struct nfc_target *targets, int ntargets);
193int nfc_target_lost(struct nfc_dev *dev, u32 target_idx);
184 194
185int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, 195int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
186 u8 comm_mode, u8 rf_mode); 196 u8 comm_mode, u8 rf_mode);
diff --git a/include/net/nfc/shdlc.h b/include/net/nfc/shdlc.h
new file mode 100644
index 000000000000..1071987d0408
--- /dev/null
+++ b/include/net/nfc/shdlc.h
@@ -0,0 +1,104 @@
1/*
2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifndef __NFC_SHDLC_H
21#define __NFC_SHDLC_H
22
23struct nfc_shdlc;
24
25struct nfc_shdlc_ops {
26 int (*open) (struct nfc_shdlc *shdlc);
27 void (*close) (struct nfc_shdlc *shdlc);
28 int (*hci_ready) (struct nfc_shdlc *shdlc);
29 int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb);
30 int (*start_poll) (struct nfc_shdlc *shdlc, u32 protocols);
31 int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate,
32 struct nfc_target *target);
33 int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate,
34 struct nfc_target *target);
35 int (*data_exchange) (struct nfc_shdlc *shdlc,
36 struct nfc_target *target,
37 struct sk_buff *skb, struct sk_buff **res_skb);
38};
39
40enum shdlc_state {
41 SHDLC_DISCONNECTED = 0,
42 SHDLC_CONNECTING = 1,
43 SHDLC_NEGOCIATING = 2,
44 SHDLC_CONNECTED = 3
45};
46
47struct nfc_shdlc {
48 struct mutex state_mutex;
49 enum shdlc_state state;
50 int hard_fault;
51
52 struct nfc_hci_dev *hdev;
53
54 wait_queue_head_t *connect_wq;
55 int connect_tries;
56 int connect_result;
57 struct timer_list connect_timer;/* aka T3 in spec 10.6.1 */
58
59 u8 w; /* window size */
60 bool srej_support;
61
62 struct timer_list t1_timer; /* send ack timeout */
63 bool t1_active;
64
65 struct timer_list t2_timer; /* guard/retransmit timeout */
66 bool t2_active;
67
68 int ns; /* next seq num for send */
69 int nr; /* next expected seq num for receive */
70 int dnr; /* oldest sent unacked seq num */
71
72 struct sk_buff_head rcv_q;
73
74 struct sk_buff_head send_q;
75 bool rnr; /* other side is not ready to receive */
76
77 struct sk_buff_head ack_pending_q;
78
79 struct workqueue_struct *sm_wq;
80 struct work_struct sm_work;
81
82 struct nfc_shdlc_ops *ops;
83
84 int client_headroom;
85 int client_tailroom;
86
87 void *clientdata;
88};
89
90void nfc_shdlc_recv_frame(struct nfc_shdlc *shdlc, struct sk_buff *skb);
91
92struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops,
93 struct nfc_hci_init_data *init_data,
94 u32 protocols,
95 int tx_headroom, int tx_tailroom,
96 int max_link_payload, const char *devname);
97
98void nfc_shdlc_free(struct nfc_shdlc *shdlc);
99
100void nfc_shdlc_set_clientdata(struct nfc_shdlc *shdlc, void *clientdata);
101void *nfc_shdlc_get_clientdata(struct nfc_shdlc *shdlc);
102struct nfc_hci_dev *nfc_shdlc_get_hci_dev(struct nfc_shdlc *shdlc);
103
104#endif /* __NFC_SHDLC_H */