pkt_sched: fq: remove useless TIME_WAIT check
[deliverable/linux.git] / net / nfc / nci / rsp.c
CommitLineData
6a2968aa
IE
1/*
2 * The NFC Controller Interface is the communication protocol between an
3 * NFC Controller (NFCC) and a Device Host (DH).
4 *
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 *
7 * Written by Ilan Elias <ilane@ti.com>
8 *
9 * Acknowledgements:
10 * This file is based on hci_event.c, which was written
11 * by Maxim Krasnyansky.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
98b32dec 23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
6a2968aa
IE
24 *
25 */
26
52858b51 27#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
ed1e0ad8 28
6a2968aa
IE
29#include <linux/types.h>
30#include <linux/interrupt.h>
31#include <linux/bitops.h>
32#include <linux/skbuff.h>
33
34#include "../nfc.h"
35#include <net/nfc/nci.h>
36#include <net/nfc/nci_core.h>
37
38/* Handle NCI Response packets */
39
40static void nci_core_reset_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
41{
42 struct nci_core_reset_rsp *rsp = (void *) skb->data;
43
24bf3304 44 pr_debug("status 0x%x\n", rsp->status);
6a2968aa 45
e8c0dacd 46 if (rsp->status == NCI_STATUS_OK) {
6a2968aa 47 ndev->nci_ver = rsp->nci_ver;
20c239c1
JP
48 pr_debug("nci_ver 0x%x, config_status 0x%x\n",
49 rsp->nci_ver, rsp->config_status);
e8c0dacd 50 }
6a2968aa
IE
51
52 nci_req_complete(ndev, rsp->status);
53}
54
55static void nci_core_init_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
56{
57 struct nci_core_init_rsp_1 *rsp_1 = (void *) skb->data;
58 struct nci_core_init_rsp_2 *rsp_2;
59
24bf3304 60 pr_debug("status 0x%x\n", rsp_1->status);
6a2968aa
IE
61
62 if (rsp_1->status != NCI_STATUS_OK)
e8c0dacd 63 goto exit;
6a2968aa
IE
64
65 ndev->nfcc_features = __le32_to_cpu(rsp_1->nfcc_features);
66 ndev->num_supported_rf_interfaces = rsp_1->num_supported_rf_interfaces;
67
68 if (ndev->num_supported_rf_interfaces >
eb9bc6e9 69 NCI_MAX_SUPPORTED_RF_INTERFACES) {
6a2968aa
IE
70 ndev->num_supported_rf_interfaces =
71 NCI_MAX_SUPPORTED_RF_INTERFACES;
72 }
73
74 memcpy(ndev->supported_rf_interfaces,
eb9bc6e9
SO
75 rsp_1->supported_rf_interfaces,
76 ndev->num_supported_rf_interfaces);
6a2968aa 77
e8c0dacd 78 rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
6a2968aa 79
eb9bc6e9 80 ndev->max_logical_connections = rsp_2->max_logical_connections;
6a2968aa
IE
81 ndev->max_routing_table_size =
82 __le16_to_cpu(rsp_2->max_routing_table_size);
e8c0dacd
IE
83 ndev->max_ctrl_pkt_payload_len =
84 rsp_2->max_ctrl_pkt_payload_len;
85 ndev->max_size_for_large_params =
86 __le16_to_cpu(rsp_2->max_size_for_large_params);
e8c0dacd
IE
87 ndev->manufact_id =
88 rsp_2->manufact_id;
89 ndev->manufact_specific_info =
90 __le32_to_cpu(rsp_2->manufact_specific_info);
91
20c239c1
JP
92 pr_debug("nfcc_features 0x%x\n",
93 ndev->nfcc_features);
94 pr_debug("num_supported_rf_interfaces %d\n",
95 ndev->num_supported_rf_interfaces);
96 pr_debug("supported_rf_interfaces[0] 0x%x\n",
97 ndev->supported_rf_interfaces[0]);
98 pr_debug("supported_rf_interfaces[1] 0x%x\n",
99 ndev->supported_rf_interfaces[1]);
100 pr_debug("supported_rf_interfaces[2] 0x%x\n",
101 ndev->supported_rf_interfaces[2]);
102 pr_debug("supported_rf_interfaces[3] 0x%x\n",
103 ndev->supported_rf_interfaces[3]);
104 pr_debug("max_logical_connections %d\n",
105 ndev->max_logical_connections);
106 pr_debug("max_routing_table_size %d\n",
107 ndev->max_routing_table_size);
108 pr_debug("max_ctrl_pkt_payload_len %d\n",
109 ndev->max_ctrl_pkt_payload_len);
110 pr_debug("max_size_for_large_params %d\n",
111 ndev->max_size_for_large_params);
20c239c1
JP
112 pr_debug("manufact_id 0x%x\n",
113 ndev->manufact_id);
114 pr_debug("manufact_specific_info 0x%x\n",
115 ndev->manufact_specific_info);
e8c0dacd
IE
116
117exit:
6a2968aa
IE
118 nci_req_complete(ndev, rsp_1->status);
119}
120
7e035230
IE
121static void nci_core_set_config_rsp_packet(struct nci_dev *ndev,
122 struct sk_buff *skb)
123{
124 struct nci_core_set_config_rsp *rsp = (void *) skb->data;
125
126 pr_debug("status 0x%x\n", rsp->status);
127
128 nci_req_complete(ndev, rsp->status);
129}
130
6a2968aa 131static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev,
eb9bc6e9 132 struct sk_buff *skb)
6a2968aa
IE
133{
134 __u8 status = skb->data[0];
135
24bf3304 136 pr_debug("status 0x%x\n", status);
6a2968aa
IE
137
138 nci_req_complete(ndev, status);
139}
140
141static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
142{
143 __u8 status = skb->data[0];
144
24bf3304 145 pr_debug("status 0x%x\n", status);
6a2968aa
IE
146
147 if (status == NCI_STATUS_OK)
8939e47f 148 atomic_set(&ndev->state, NCI_DISCOVERY);
6a2968aa
IE
149
150 nci_req_complete(ndev, status);
151}
152
019c4fba 153static void nci_rf_disc_select_rsp_packet(struct nci_dev *ndev,
eb9bc6e9 154 struct sk_buff *skb)
019c4fba
IE
155{
156 __u8 status = skb->data[0];
157
158 pr_debug("status 0x%x\n", status);
159
160 /* Complete the request on intf_activated_ntf or generic_error_ntf */
161 if (status != NCI_STATUS_OK)
162 nci_req_complete(ndev, status);
163}
164
6a2968aa 165static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
eb9bc6e9 166 struct sk_buff *skb)
6a2968aa
IE
167{
168 __u8 status = skb->data[0];
169
24bf3304 170 pr_debug("status 0x%x\n", status);
6a2968aa 171
bd7e01bc
IE
172 /* If target was active, complete the request only in deactivate_ntf */
173 if ((status != NCI_STATUS_OK) ||
eb9bc6e9 174 (atomic_read(&ndev->state) != NCI_POLL_ACTIVE)) {
019c4fba 175 nci_clear_target_list(ndev);
8939e47f 176 atomic_set(&ndev->state, NCI_IDLE);
bd7e01bc 177 nci_req_complete(ndev, status);
8939e47f 178 }
6a2968aa
IE
179}
180
181void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
182{
183 __u16 rsp_opcode = nci_opcode(skb->data);
184
185 /* we got a rsp, stop the cmd timer */
186 del_timer(&ndev->cmd_timer);
187
20c239c1
JP
188 pr_debug("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
189 nci_pbf(skb->data),
190 nci_opcode_gid(rsp_opcode),
191 nci_opcode_oid(rsp_opcode),
192 nci_plen(skb->data));
6a2968aa
IE
193
194 /* strip the nci control header */
195 skb_pull(skb, NCI_CTRL_HDR_SIZE);
196
197 switch (rsp_opcode) {
198 case NCI_OP_CORE_RESET_RSP:
199 nci_core_reset_rsp_packet(ndev, skb);
200 break;
201
202 case NCI_OP_CORE_INIT_RSP:
203 nci_core_init_rsp_packet(ndev, skb);
204 break;
205
7e035230
IE
206 case NCI_OP_CORE_SET_CONFIG_RSP:
207 nci_core_set_config_rsp_packet(ndev, skb);
208 break;
209
6a2968aa
IE
210 case NCI_OP_RF_DISCOVER_MAP_RSP:
211 nci_rf_disc_map_rsp_packet(ndev, skb);
212 break;
213
214 case NCI_OP_RF_DISCOVER_RSP:
215 nci_rf_disc_rsp_packet(ndev, skb);
216 break;
217
019c4fba
IE
218 case NCI_OP_RF_DISCOVER_SELECT_RSP:
219 nci_rf_disc_select_rsp_packet(ndev, skb);
220 break;
221
6a2968aa
IE
222 case NCI_OP_RF_DEACTIVATE_RSP:
223 nci_rf_deactivate_rsp_packet(ndev, skb);
224 break;
225
226 default:
ed1e0ad8 227 pr_err("unknown rsp opcode 0x%x\n", rsp_opcode);
6a2968aa
IE
228 break;
229 }
230
231 kfree_skb(skb);
232
233 /* trigger the next cmd */
234 atomic_set(&ndev->cmd_cnt, 1);
235 if (!skb_queue_empty(&ndev->cmd_q))
236 queue_work(ndev->cmd_wq, &ndev->cmd_work);
237}
This page took 0.181909 seconds and 5 git commands to generate.