Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 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 |
Jeff Kirsher | 98b32de | 2013-12-06 08:56:16 -0800 | [diff] [blame] | 23 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 24 | * |
| 25 | */ |
| 26 | |
Samuel Ortiz | 52858b5 | 2011-12-14 16:43:05 +0100 | [diff] [blame] | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 28 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 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 | |
| 40 | static 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 | |
Joe Perches | 24bf330 | 2011-11-29 11:37:35 -0800 | [diff] [blame] | 44 | pr_debug("status 0x%x\n", rsp->status); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 45 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 46 | if (rsp->status == NCI_STATUS_OK) { |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 47 | ndev->nci_ver = rsp->nci_ver; |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 48 | pr_debug("nci_ver 0x%x, config_status 0x%x\n", |
| 49 | rsp->nci_ver, rsp->config_status); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 50 | } |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 51 | |
| 52 | nci_req_complete(ndev, rsp->status); |
| 53 | } |
| 54 | |
| 55 | static 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 | |
Joe Perches | 24bf330 | 2011-11-29 11:37:35 -0800 | [diff] [blame] | 60 | pr_debug("status 0x%x\n", rsp_1->status); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 61 | |
| 62 | if (rsp_1->status != NCI_STATUS_OK) |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 63 | goto exit; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 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 > |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 69 | NCI_MAX_SUPPORTED_RF_INTERFACES) { |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 70 | ndev->num_supported_rf_interfaces = |
| 71 | NCI_MAX_SUPPORTED_RF_INTERFACES; |
| 72 | } |
| 73 | |
| 74 | memcpy(ndev->supported_rf_interfaces, |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 75 | rsp_1->supported_rf_interfaces, |
| 76 | ndev->num_supported_rf_interfaces); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 77 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 78 | rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 79 | |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 80 | ndev->max_logical_connections = rsp_2->max_logical_connections; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 81 | ndev->max_routing_table_size = |
| 82 | __le16_to_cpu(rsp_2->max_routing_table_size); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 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); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 87 | ndev->manufact_id = |
| 88 | rsp_2->manufact_id; |
| 89 | ndev->manufact_specific_info = |
| 90 | __le32_to_cpu(rsp_2->manufact_specific_info); |
| 91 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 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); |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 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); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 116 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 117 | exit: |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 118 | nci_req_complete(ndev, rsp_1->status); |
| 119 | } |
| 120 | |
Ilan Elias | 7e03523 | 2012-08-15 11:46:22 +0300 | [diff] [blame] | 121 | static 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 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 131 | static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev, |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 132 | struct sk_buff *skb) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 133 | { |
| 134 | __u8 status = skb->data[0]; |
| 135 | |
Joe Perches | 24bf330 | 2011-11-29 11:37:35 -0800 | [diff] [blame] | 136 | pr_debug("status 0x%x\n", status); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 137 | |
| 138 | nci_req_complete(ndev, status); |
| 139 | } |
| 140 | |
| 141 | static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) |
| 142 | { |
Christophe Ricard | 4aeee68 | 2015-02-01 22:26:08 +0100 | [diff] [blame] | 143 | struct nci_conn_info *conn_info; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 144 | __u8 status = skb->data[0]; |
| 145 | |
Joe Perches | 24bf330 | 2011-11-29 11:37:35 -0800 | [diff] [blame] | 146 | pr_debug("status 0x%x\n", status); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 147 | |
Christophe Ricard | 4aeee68 | 2015-02-01 22:26:08 +0100 | [diff] [blame] | 148 | if (status == NCI_STATUS_OK) { |
Ilan Elias | 8939e47 | 2012-01-18 13:16:12 +0200 | [diff] [blame] | 149 | atomic_set(&ndev->state, NCI_DISCOVERY); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 150 | |
Christophe Ricard | 12bdf27 | 2015-02-03 19:48:04 +0100 | [diff] [blame] | 151 | conn_info = ndev->rf_conn_info; |
Christophe Ricard | 4aeee68 | 2015-02-01 22:26:08 +0100 | [diff] [blame] | 152 | if (!conn_info) { |
| 153 | conn_info = devm_kzalloc(&ndev->nfc_dev->dev, |
| 154 | sizeof(struct nci_conn_info), |
| 155 | GFP_KERNEL); |
| 156 | if (!conn_info) { |
| 157 | status = NCI_STATUS_REJECTED; |
| 158 | goto exit; |
| 159 | } |
| 160 | conn_info->conn_id = NCI_STATIC_RF_CONN_ID; |
| 161 | INIT_LIST_HEAD(&conn_info->list); |
| 162 | list_add(&conn_info->list, &ndev->conn_info_list); |
Christophe Ricard | 12bdf27 | 2015-02-03 19:48:04 +0100 | [diff] [blame] | 163 | ndev->rf_conn_info = conn_info; |
Christophe Ricard | 4aeee68 | 2015-02-01 22:26:08 +0100 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | exit: |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 168 | nci_req_complete(ndev, status); |
| 169 | } |
| 170 | |
Ilan Elias | 019c4fb | 2012-01-18 13:16:14 +0200 | [diff] [blame] | 171 | static void nci_rf_disc_select_rsp_packet(struct nci_dev *ndev, |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 172 | struct sk_buff *skb) |
Ilan Elias | 019c4fb | 2012-01-18 13:16:14 +0200 | [diff] [blame] | 173 | { |
| 174 | __u8 status = skb->data[0]; |
| 175 | |
| 176 | pr_debug("status 0x%x\n", status); |
| 177 | |
| 178 | /* Complete the request on intf_activated_ntf or generic_error_ntf */ |
| 179 | if (status != NCI_STATUS_OK) |
| 180 | nci_req_complete(ndev, status); |
| 181 | } |
| 182 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 183 | static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev, |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 184 | struct sk_buff *skb) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 185 | { |
| 186 | __u8 status = skb->data[0]; |
| 187 | |
Joe Perches | 24bf330 | 2011-11-29 11:37:35 -0800 | [diff] [blame] | 188 | pr_debug("status 0x%x\n", status); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 189 | |
Ilan Elias | bd7e01b | 2012-01-08 11:21:53 +0200 | [diff] [blame] | 190 | /* If target was active, complete the request only in deactivate_ntf */ |
| 191 | if ((status != NCI_STATUS_OK) || |
Samuel Ortiz | eb9bc6e | 2012-03-05 01:03:54 +0100 | [diff] [blame] | 192 | (atomic_read(&ndev->state) != NCI_POLL_ACTIVE)) { |
Ilan Elias | 019c4fb | 2012-01-18 13:16:14 +0200 | [diff] [blame] | 193 | nci_clear_target_list(ndev); |
Ilan Elias | 8939e47 | 2012-01-18 13:16:12 +0200 | [diff] [blame] | 194 | atomic_set(&ndev->state, NCI_IDLE); |
Ilan Elias | bd7e01b | 2012-01-08 11:21:53 +0200 | [diff] [blame] | 195 | nci_req_complete(ndev, status); |
Ilan Elias | 8939e47 | 2012-01-18 13:16:12 +0200 | [diff] [blame] | 196 | } |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 197 | } |
| 198 | |
Christophe Ricard | af9c8aa | 2015-02-01 22:26:10 +0100 | [diff] [blame] | 199 | static void nci_nfcee_discover_rsp_packet(struct nci_dev *ndev, |
| 200 | struct sk_buff *skb) |
| 201 | { |
| 202 | struct nci_nfcee_discover_rsp *discover_rsp; |
| 203 | |
| 204 | if (skb->len != 2) { |
| 205 | nci_req_complete(ndev, NCI_STATUS_NFCEE_PROTOCOL_ERROR); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | discover_rsp = (struct nci_nfcee_discover_rsp *)skb->data; |
| 210 | |
| 211 | if (discover_rsp->status != NCI_STATUS_OK || |
| 212 | discover_rsp->num_nfcee == 0) |
| 213 | nci_req_complete(ndev, discover_rsp->status); |
| 214 | } |
| 215 | |
Christophe Ricard | f7f793f | 2015-02-01 22:26:11 +0100 | [diff] [blame] | 216 | static void nci_nfcee_mode_set_rsp_packet(struct nci_dev *ndev, |
| 217 | struct sk_buff *skb) |
| 218 | { |
| 219 | __u8 status = skb->data[0]; |
| 220 | |
| 221 | pr_debug("status 0x%x\n", status); |
| 222 | nci_req_complete(ndev, status); |
| 223 | } |
| 224 | |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 225 | static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, |
| 226 | struct sk_buff *skb) |
| 227 | { |
| 228 | __u8 status = skb->data[0]; |
Christophe Ricard | 9b8d1a4 | 2016-04-30 09:12:51 +0200 | [diff] [blame] | 229 | struct nci_conn_info *conn_info = NULL; |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 230 | struct nci_core_conn_create_rsp *rsp; |
| 231 | |
| 232 | pr_debug("status 0x%x\n", status); |
| 233 | |
| 234 | if (status == NCI_STATUS_OK) { |
| 235 | rsp = (struct nci_core_conn_create_rsp *)skb->data; |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 236 | |
Christophe Ricard | 15d4a8d | 2015-02-03 19:48:07 +0100 | [diff] [blame] | 237 | conn_info = devm_kzalloc(&ndev->nfc_dev->dev, |
| 238 | sizeof(*conn_info), GFP_KERNEL); |
| 239 | if (!conn_info) { |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 240 | status = NCI_STATUS_REJECTED; |
| 241 | goto exit; |
| 242 | } |
| 243 | |
Christophe Ricard | 9b8d1a4 | 2016-04-30 09:12:51 +0200 | [diff] [blame] | 244 | conn_info->dest_params = devm_kzalloc(&ndev->nfc_dev->dev, |
| 245 | sizeof(struct dest_spec_params), |
| 246 | GFP_KERNEL); |
| 247 | if (!conn_info->dest_params) { |
| 248 | status = NCI_STATUS_REJECTED; |
| 249 | goto free_conn_info; |
| 250 | } |
| 251 | |
| 252 | conn_info->dest_type = ndev->cur_dest_type; |
| 253 | conn_info->dest_params->id = ndev->cur_params.id; |
| 254 | conn_info->dest_params->protocol = ndev->cur_params.protocol; |
Christophe Ricard | 15d4a8d | 2015-02-03 19:48:07 +0100 | [diff] [blame] | 255 | conn_info->conn_id = rsp->conn_id; |
| 256 | |
| 257 | /* Note: data_exchange_cb and data_exchange_cb_context need to |
| 258 | * be specify out of nci_core_conn_create_rsp_packet |
| 259 | */ |
| 260 | |
| 261 | INIT_LIST_HEAD(&conn_info->list); |
| 262 | list_add(&conn_info->list, &ndev->conn_info_list); |
| 263 | |
Christophe Ricard | 9b8d1a4 | 2016-04-30 09:12:51 +0200 | [diff] [blame] | 264 | if (ndev->cur_params.id == ndev->hci_dev->nfcee_id) |
Christophe Ricard | 15d4a8d | 2015-02-03 19:48:07 +0100 | [diff] [blame] | 265 | ndev->hci_dev->conn_info = conn_info; |
| 266 | |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 267 | conn_info->conn_id = rsp->conn_id; |
| 268 | conn_info->max_pkt_payload_len = rsp->max_ctrl_pkt_payload_len; |
Christophe Ricard | 3ba5c84 | 2015-02-03 19:48:06 +0100 | [diff] [blame] | 269 | atomic_set(&conn_info->credits_cnt, rsp->credits_cnt); |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Christophe Ricard | 9b8d1a4 | 2016-04-30 09:12:51 +0200 | [diff] [blame] | 272 | free_conn_info: |
| 273 | if (status == NCI_STATUS_REJECTED) |
| 274 | devm_kfree(&ndev->nfc_dev->dev, conn_info); |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 275 | exit: |
Christophe Ricard | 9b8d1a4 | 2016-04-30 09:12:51 +0200 | [diff] [blame] | 276 | |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 277 | nci_req_complete(ndev, status); |
| 278 | } |
| 279 | |
| 280 | static void nci_core_conn_close_rsp_packet(struct nci_dev *ndev, |
| 281 | struct sk_buff *skb) |
| 282 | { |
Christophe Ricard | 15d4a8d | 2015-02-03 19:48:07 +0100 | [diff] [blame] | 283 | struct nci_conn_info *conn_info; |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 284 | __u8 status = skb->data[0]; |
| 285 | |
| 286 | pr_debug("status 0x%x\n", status); |
Christophe Ricard | 15d4a8d | 2015-02-03 19:48:07 +0100 | [diff] [blame] | 287 | if (status == NCI_STATUS_OK) { |
Christophe Ricard | de5ea85 | 2016-04-30 09:12:50 +0200 | [diff] [blame] | 288 | conn_info = nci_get_conn_info_by_conn_id(ndev, |
| 289 | ndev->cur_conn_id); |
Christophe Ricard | 15d4a8d | 2015-02-03 19:48:07 +0100 | [diff] [blame] | 290 | if (conn_info) { |
| 291 | list_del(&conn_info->list); |
| 292 | devm_kfree(&ndev->nfc_dev->dev, conn_info); |
| 293 | } |
| 294 | } |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 295 | nci_req_complete(ndev, status); |
| 296 | } |
| 297 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 298 | void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) |
| 299 | { |
| 300 | __u16 rsp_opcode = nci_opcode(skb->data); |
| 301 | |
| 302 | /* we got a rsp, stop the cmd timer */ |
| 303 | del_timer(&ndev->cmd_timer); |
| 304 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 305 | pr_debug("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n", |
| 306 | nci_pbf(skb->data), |
| 307 | nci_opcode_gid(rsp_opcode), |
| 308 | nci_opcode_oid(rsp_opcode), |
| 309 | nci_plen(skb->data)); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 310 | |
| 311 | /* strip the nci control header */ |
| 312 | skb_pull(skb, NCI_CTRL_HDR_SIZE); |
| 313 | |
Samuel Ortiz | b6355e9 | 2015-06-06 13:16:37 +0200 | [diff] [blame] | 314 | if (nci_opcode_gid(rsp_opcode) == NCI_GID_PROPRIETARY) { |
| 315 | if (nci_prop_rsp_packet(ndev, rsp_opcode, skb) == -ENOTSUPP) { |
| 316 | pr_err("unsupported rsp opcode 0x%x\n", |
| 317 | rsp_opcode); |
| 318 | } |
| 319 | |
| 320 | goto end; |
| 321 | } |
| 322 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 323 | switch (rsp_opcode) { |
| 324 | case NCI_OP_CORE_RESET_RSP: |
| 325 | nci_core_reset_rsp_packet(ndev, skb); |
| 326 | break; |
| 327 | |
| 328 | case NCI_OP_CORE_INIT_RSP: |
| 329 | nci_core_init_rsp_packet(ndev, skb); |
| 330 | break; |
| 331 | |
Ilan Elias | 7e03523 | 2012-08-15 11:46:22 +0300 | [diff] [blame] | 332 | case NCI_OP_CORE_SET_CONFIG_RSP: |
| 333 | nci_core_set_config_rsp_packet(ndev, skb); |
| 334 | break; |
| 335 | |
Christophe Ricard | 736bb95 | 2015-02-01 22:26:12 +0100 | [diff] [blame] | 336 | case NCI_OP_CORE_CONN_CREATE_RSP: |
| 337 | nci_core_conn_create_rsp_packet(ndev, skb); |
| 338 | break; |
| 339 | |
| 340 | case NCI_OP_CORE_CONN_CLOSE_RSP: |
| 341 | nci_core_conn_close_rsp_packet(ndev, skb); |
| 342 | break; |
| 343 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 344 | case NCI_OP_RF_DISCOVER_MAP_RSP: |
| 345 | nci_rf_disc_map_rsp_packet(ndev, skb); |
| 346 | break; |
| 347 | |
| 348 | case NCI_OP_RF_DISCOVER_RSP: |
| 349 | nci_rf_disc_rsp_packet(ndev, skb); |
| 350 | break; |
| 351 | |
Ilan Elias | 019c4fb | 2012-01-18 13:16:14 +0200 | [diff] [blame] | 352 | case NCI_OP_RF_DISCOVER_SELECT_RSP: |
| 353 | nci_rf_disc_select_rsp_packet(ndev, skb); |
| 354 | break; |
| 355 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 356 | case NCI_OP_RF_DEACTIVATE_RSP: |
| 357 | nci_rf_deactivate_rsp_packet(ndev, skb); |
| 358 | break; |
| 359 | |
Christophe Ricard | af9c8aa | 2015-02-01 22:26:10 +0100 | [diff] [blame] | 360 | case NCI_OP_NFCEE_DISCOVER_RSP: |
| 361 | nci_nfcee_discover_rsp_packet(ndev, skb); |
| 362 | break; |
| 363 | |
Christophe Ricard | f7f793f | 2015-02-01 22:26:11 +0100 | [diff] [blame] | 364 | case NCI_OP_NFCEE_MODE_SET_RSP: |
| 365 | nci_nfcee_mode_set_rsp_packet(ndev, skb); |
| 366 | break; |
| 367 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 368 | default: |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 369 | pr_err("unknown rsp opcode 0x%x\n", rsp_opcode); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | |
Robert Dolca | 0a97a3c | 2015-10-22 12:11:38 +0300 | [diff] [blame] | 373 | nci_core_rsp_packet(ndev, rsp_opcode, skb); |
Samuel Ortiz | b6355e9 | 2015-06-06 13:16:37 +0200 | [diff] [blame] | 374 | end: |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 375 | kfree_skb(skb); |
| 376 | |
| 377 | /* trigger the next cmd */ |
| 378 | atomic_set(&ndev->cmd_cnt, 1); |
| 379 | if (!skb_queue_empty(&ndev->cmd_q)) |
| 380 | queue_work(ndev->cmd_wq, &ndev->cmd_work); |
| 381 | } |