1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
29
30#include <linux/types.h>
31#include <linux/interrupt.h>
32#include <linux/bitops.h>
33#include <linux/skbuff.h>
34
35#include "../nfc.h"
36#include <net/nfc/nci.h>
37#include <net/nfc/nci_core.h>
38
39
40
41static void nci_core_reset_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
42{
43 struct nci_core_reset_rsp *rsp = (void *) skb->data;
44
45 pr_debug("status 0x%x\n", rsp->status);
46
47 if (rsp->status == NCI_STATUS_OK) {
48 ndev->nci_ver = rsp->nci_ver;
49 pr_debug("nci_ver 0x%x, config_status 0x%x\n",
50 rsp->nci_ver, rsp->config_status);
51 }
52
53 nci_req_complete(ndev, rsp->status);
54}
55
56static void nci_core_init_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
57{
58 struct nci_core_init_rsp_1 *rsp_1 = (void *) skb->data;
59 struct nci_core_init_rsp_2 *rsp_2;
60
61 pr_debug("status 0x%x\n", rsp_1->status);
62
63 if (rsp_1->status != NCI_STATUS_OK)
64 goto exit;
65
66 ndev->nfcc_features = __le32_to_cpu(rsp_1->nfcc_features);
67 ndev->num_supported_rf_interfaces = rsp_1->num_supported_rf_interfaces;
68
69 if (ndev->num_supported_rf_interfaces >
70 NCI_MAX_SUPPORTED_RF_INTERFACES) {
71 ndev->num_supported_rf_interfaces =
72 NCI_MAX_SUPPORTED_RF_INTERFACES;
73 }
74
75 memcpy(ndev->supported_rf_interfaces,
76 rsp_1->supported_rf_interfaces,
77 ndev->num_supported_rf_interfaces);
78
79 rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
80
81 ndev->max_logical_connections = rsp_2->max_logical_connections;
82 ndev->max_routing_table_size =
83 __le16_to_cpu(rsp_2->max_routing_table_size);
84 ndev->max_ctrl_pkt_payload_len =
85 rsp_2->max_ctrl_pkt_payload_len;
86 ndev->max_size_for_large_params =
87 __le16_to_cpu(rsp_2->max_size_for_large_params);
88 ndev->manufact_id =
89 rsp_2->manufact_id;
90 ndev->manufact_specific_info =
91 __le32_to_cpu(rsp_2->manufact_specific_info);
92
93 pr_debug("nfcc_features 0x%x\n",
94 ndev->nfcc_features);
95 pr_debug("num_supported_rf_interfaces %d\n",
96 ndev->num_supported_rf_interfaces);
97 pr_debug("supported_rf_interfaces[0] 0x%x\n",
98 ndev->supported_rf_interfaces[0]);
99 pr_debug("supported_rf_interfaces[1] 0x%x\n",
100 ndev->supported_rf_interfaces[1]);
101 pr_debug("supported_rf_interfaces[2] 0x%x\n",
102 ndev->supported_rf_interfaces[2]);
103 pr_debug("supported_rf_interfaces[3] 0x%x\n",
104 ndev->supported_rf_interfaces[3]);
105 pr_debug("max_logical_connections %d\n",
106 ndev->max_logical_connections);
107 pr_debug("max_routing_table_size %d\n",
108 ndev->max_routing_table_size);
109 pr_debug("max_ctrl_pkt_payload_len %d\n",
110 ndev->max_ctrl_pkt_payload_len);
111 pr_debug("max_size_for_large_params %d\n",
112 ndev->max_size_for_large_params);
113 pr_debug("manufact_id 0x%x\n",
114 ndev->manufact_id);
115 pr_debug("manufact_specific_info 0x%x\n",
116 ndev->manufact_specific_info);
117
118exit:
119 nci_req_complete(ndev, rsp_1->status);
120}
121
122static void nci_core_set_config_rsp_packet(struct nci_dev *ndev,
123 struct sk_buff *skb)
124{
125 struct nci_core_set_config_rsp *rsp = (void *) skb->data;
126
127 pr_debug("status 0x%x\n", rsp->status);
128
129 nci_req_complete(ndev, rsp->status);
130}
131
132static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev,
133 struct sk_buff *skb)
134{
135 __u8 status = skb->data[0];
136
137 pr_debug("status 0x%x\n", status);
138
139 nci_req_complete(ndev, status);
140}
141
142static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
143{
144 __u8 status = skb->data[0];
145
146 pr_debug("status 0x%x\n", status);
147
148 if (status == NCI_STATUS_OK)
149 atomic_set(&ndev->state, NCI_DISCOVERY);
150
151 nci_req_complete(ndev, status);
152}
153
154static void nci_rf_disc_select_rsp_packet(struct nci_dev *ndev,
155 struct sk_buff *skb)
156{
157 __u8 status = skb->data[0];
158
159 pr_debug("status 0x%x\n", status);
160
161
162 if (status != NCI_STATUS_OK)
163 nci_req_complete(ndev, status);
164}
165
166static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
167 struct sk_buff *skb)
168{
169 __u8 status = skb->data[0];
170
171 pr_debug("status 0x%x\n", status);
172
173
174 if ((status != NCI_STATUS_OK) ||
175 (atomic_read(&ndev->state) != NCI_POLL_ACTIVE)) {
176 nci_clear_target_list(ndev);
177 atomic_set(&ndev->state, NCI_IDLE);
178 nci_req_complete(ndev, status);
179 }
180}
181
182void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
183{
184 __u16 rsp_opcode = nci_opcode(skb->data);
185
186
187 del_timer(&ndev->cmd_timer);
188
189 pr_debug("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
190 nci_pbf(skb->data),
191 nci_opcode_gid(rsp_opcode),
192 nci_opcode_oid(rsp_opcode),
193 nci_plen(skb->data));
194
195
196 skb_pull(skb, NCI_CTRL_HDR_SIZE);
197
198 switch (rsp_opcode) {
199 case NCI_OP_CORE_RESET_RSP:
200 nci_core_reset_rsp_packet(ndev, skb);
201 break;
202
203 case NCI_OP_CORE_INIT_RSP:
204 nci_core_init_rsp_packet(ndev, skb);
205 break;
206
207 case NCI_OP_CORE_SET_CONFIG_RSP:
208 nci_core_set_config_rsp_packet(ndev, skb);
209 break;
210
211 case NCI_OP_RF_DISCOVER_MAP_RSP:
212 nci_rf_disc_map_rsp_packet(ndev, skb);
213 break;
214
215 case NCI_OP_RF_DISCOVER_RSP:
216 nci_rf_disc_rsp_packet(ndev, skb);
217 break;
218
219 case NCI_OP_RF_DISCOVER_SELECT_RSP:
220 nci_rf_disc_select_rsp_packet(ndev, skb);
221 break;
222
223 case NCI_OP_RF_DEACTIVATE_RSP:
224 nci_rf_deactivate_rsp_packet(ndev, skb);
225 break;
226
227 default:
228 pr_err("unknown rsp opcode 0x%x\n", rsp_opcode);
229 break;
230 }
231
232 kfree_skb(skb);
233
234
235 atomic_set(&ndev->cmd_cnt, 1);
236 if (!skb_queue_empty(&ndev->cmd_q))
237 queue_work(ndev->cmd_wq, &ndev->cmd_work);
238}
239