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 |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
| 27 | |
Samuel Ortiz | 52858b5 | 2011-12-14 16:43:05 +0100 | [diff] [blame] | 28 | #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 29 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 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 | #include <linux/nfc.h> |
| 39 | |
| 40 | /* Handle NCI Notification packets */ |
| 41 | |
| 42 | static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev, |
| 43 | struct sk_buff *skb) |
| 44 | { |
| 45 | struct nci_core_conn_credit_ntf *ntf = (void *) skb->data; |
| 46 | int i; |
| 47 | |
Joe Perches | 24bf330 | 2011-11-29 11:37:35 -0800 | [diff] [blame] | 48 | pr_debug("num_entries %d\n", ntf->num_entries); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 49 | |
| 50 | if (ntf->num_entries > NCI_MAX_NUM_CONN) |
| 51 | ntf->num_entries = NCI_MAX_NUM_CONN; |
| 52 | |
| 53 | /* update the credits */ |
| 54 | for (i = 0; i < ntf->num_entries; i++) { |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 55 | ntf->conn_entries[i].conn_id = |
| 56 | nci_conn_id(&ntf->conn_entries[i].conn_id); |
| 57 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 58 | pr_debug("entry[%d]: conn_id %d, credits %d\n", |
| 59 | i, ntf->conn_entries[i].conn_id, |
| 60 | ntf->conn_entries[i].credits); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 61 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 62 | if (ntf->conn_entries[i].conn_id == NCI_STATIC_RF_CONN_ID) { |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 63 | /* found static rf connection */ |
| 64 | atomic_add(ntf->conn_entries[i].credits, |
| 65 | &ndev->credits_cnt); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /* trigger the next tx */ |
| 70 | if (!skb_queue_empty(&ndev->tx_q)) |
| 71 | queue_work(ndev->tx_wq, &ndev->tx_work); |
| 72 | } |
| 73 | |
Ilan Elias | 004161c | 2011-12-20 16:57:41 +0200 | [diff] [blame] | 74 | static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev, |
| 75 | struct sk_buff *skb) |
| 76 | { |
| 77 | struct nci_core_intf_error_ntf *ntf = (void *) skb->data; |
| 78 | |
| 79 | ntf->conn_id = nci_conn_id(&ntf->conn_id); |
| 80 | |
| 81 | pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id); |
| 82 | |
| 83 | /* complete the data exchange transaction, if exists */ |
| 84 | if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags)) |
| 85 | nci_data_exchange_complete(ndev, NULL, -EIO); |
| 86 | } |
| 87 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 88 | static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev, |
| 89 | struct nci_rf_intf_activated_ntf *ntf, __u8 *data) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 90 | { |
| 91 | struct rf_tech_specific_params_nfca_poll *nfca_poll; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 92 | |
| 93 | nfca_poll = &ntf->rf_tech_specific_params.nfca_poll; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 94 | |
| 95 | nfca_poll->sens_res = __le16_to_cpu(*((__u16 *)data)); |
| 96 | data += 2; |
| 97 | |
| 98 | nfca_poll->nfcid1_len = *data++; |
| 99 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 100 | pr_debug("sens_res 0x%x, nfcid1_len %d\n", |
| 101 | nfca_poll->sens_res, nfca_poll->nfcid1_len); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 102 | |
| 103 | memcpy(nfca_poll->nfcid1, data, nfca_poll->nfcid1_len); |
| 104 | data += nfca_poll->nfcid1_len; |
| 105 | |
| 106 | nfca_poll->sel_res_len = *data++; |
| 107 | |
| 108 | if (nfca_poll->sel_res_len != 0) |
| 109 | nfca_poll->sel_res = *data++; |
| 110 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 111 | pr_debug("sel_res_len %d, sel_res 0x%x\n", |
| 112 | nfca_poll->sel_res_len, |
| 113 | nfca_poll->sel_res); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 114 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 115 | return data; |
| 116 | } |
| 117 | |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 118 | static __u8 *nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev, |
| 119 | struct nci_rf_intf_activated_ntf *ntf, __u8 *data) |
| 120 | { |
| 121 | struct rf_tech_specific_params_nfcb_poll *nfcb_poll; |
| 122 | |
| 123 | nfcb_poll = &ntf->rf_tech_specific_params.nfcb_poll; |
| 124 | |
| 125 | nfcb_poll->sensb_res_len = *data++; |
| 126 | |
| 127 | pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len); |
| 128 | |
| 129 | memcpy(nfcb_poll->sensb_res, data, nfcb_poll->sensb_res_len); |
| 130 | data += nfcb_poll->sensb_res_len; |
| 131 | |
| 132 | return data; |
| 133 | } |
| 134 | |
| 135 | static __u8 *nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev, |
| 136 | struct nci_rf_intf_activated_ntf *ntf, __u8 *data) |
| 137 | { |
| 138 | struct rf_tech_specific_params_nfcf_poll *nfcf_poll; |
| 139 | |
| 140 | nfcf_poll = &ntf->rf_tech_specific_params.nfcf_poll; |
| 141 | |
| 142 | nfcf_poll->bit_rate = *data++; |
| 143 | nfcf_poll->sensf_res_len = *data++; |
| 144 | |
| 145 | pr_debug("bit_rate %d, sensf_res_len %d\n", |
| 146 | nfcf_poll->bit_rate, nfcf_poll->sensf_res_len); |
| 147 | |
| 148 | memcpy(nfcf_poll->sensf_res, data, nfcf_poll->sensf_res_len); |
| 149 | data += nfcf_poll->sensf_res_len; |
| 150 | |
| 151 | return data; |
| 152 | } |
| 153 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 154 | static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev, |
| 155 | struct nci_rf_intf_activated_ntf *ntf, __u8 *data) |
| 156 | { |
| 157 | struct activation_params_nfca_poll_iso_dep *nfca_poll; |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 158 | struct activation_params_nfcb_poll_iso_dep *nfcb_poll; |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 159 | |
| 160 | switch (ntf->activation_rf_tech_and_mode) { |
| 161 | case NCI_NFC_A_PASSIVE_POLL_MODE: |
| 162 | nfca_poll = &ntf->activation_params.nfca_poll_iso_dep; |
| 163 | nfca_poll->rats_res_len = *data++; |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 164 | pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 165 | if (nfca_poll->rats_res_len > 0) { |
| 166 | memcpy(nfca_poll->rats_res, |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 167 | data, |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 168 | nfca_poll->rats_res_len); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 169 | } |
| 170 | break; |
| 171 | |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 172 | case NCI_NFC_B_PASSIVE_POLL_MODE: |
| 173 | nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep; |
| 174 | nfcb_poll->attrib_res_len = *data++; |
| 175 | pr_debug("attrib_res_len %d\n", |
| 176 | nfcb_poll->attrib_res_len); |
| 177 | if (nfcb_poll->attrib_res_len > 0) { |
| 178 | memcpy(nfcb_poll->attrib_res, |
| 179 | data, |
| 180 | nfcb_poll->attrib_res_len); |
| 181 | } |
| 182 | break; |
| 183 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 184 | default: |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 185 | pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", |
| 186 | ntf->activation_rf_tech_and_mode); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 187 | return -EPROTO; |
| 188 | } |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static void nci_target_found(struct nci_dev *ndev, |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 194 | struct nci_rf_intf_activated_ntf *ntf) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 195 | { |
| 196 | struct nfc_target nfc_tgt; |
| 197 | |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 198 | memset(&nfc_tgt, 0, sizeof(nfc_tgt)); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 199 | |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 200 | if (ntf->rf_protocol == NCI_RF_PROTOCOL_T2T) |
| 201 | nfc_tgt.supported_protocols = NFC_PROTO_MIFARE_MASK; |
| 202 | else if (ntf->rf_protocol == NCI_RF_PROTOCOL_ISO_DEP) |
| 203 | nfc_tgt.supported_protocols = NFC_PROTO_ISO14443_MASK; |
| 204 | else if (ntf->rf_protocol == NCI_RF_PROTOCOL_T3T) |
| 205 | nfc_tgt.supported_protocols = NFC_PROTO_FELICA_MASK; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 206 | |
| 207 | if (!(nfc_tgt.supported_protocols & ndev->poll_prots)) { |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 208 | pr_debug("the target found does not have the desired protocol\n"); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 209 | return; |
| 210 | } |
| 211 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 212 | pr_debug("new target found, supported_protocols 0x%x\n", |
| 213 | nfc_tgt.supported_protocols); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 214 | |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 215 | if (ntf->activation_rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) { |
| 216 | nfc_tgt.sens_res = |
| 217 | ntf->rf_tech_specific_params.nfca_poll.sens_res; |
| 218 | nfc_tgt.sel_res = |
| 219 | ntf->rf_tech_specific_params.nfca_poll.sel_res; |
| 220 | nfc_tgt.nfcid1_len = |
| 221 | ntf->rf_tech_specific_params.nfca_poll.nfcid1_len; |
| 222 | if (nfc_tgt.nfcid1_len > 0) { |
| 223 | memcpy(nfc_tgt.nfcid1, |
| 224 | ntf->rf_tech_specific_params.nfca_poll.nfcid1, |
| 225 | nfc_tgt.nfcid1_len); |
| 226 | } |
| 227 | } else if (ntf->activation_rf_tech_and_mode == |
| 228 | NCI_NFC_B_PASSIVE_POLL_MODE) { |
| 229 | nfc_tgt.sensb_res_len = |
| 230 | ntf->rf_tech_specific_params.nfcb_poll.sensb_res_len; |
| 231 | if (nfc_tgt.sensb_res_len > 0) { |
| 232 | memcpy(nfc_tgt.sensb_res, |
| 233 | ntf->rf_tech_specific_params.nfcb_poll.sensb_res, |
| 234 | nfc_tgt.sensb_res_len); |
| 235 | } |
| 236 | } else if (ntf->activation_rf_tech_and_mode == |
| 237 | NCI_NFC_F_PASSIVE_POLL_MODE) { |
| 238 | nfc_tgt.sensf_res_len = |
| 239 | ntf->rf_tech_specific_params.nfcf_poll.sensf_res_len; |
| 240 | if (nfc_tgt.sensf_res_len > 0) { |
| 241 | memcpy(nfc_tgt.sensf_res, |
| 242 | ntf->rf_tech_specific_params.nfcf_poll.sensf_res, |
| 243 | nfc_tgt.sensf_res_len); |
| 244 | } |
| 245 | } |
| 246 | |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 247 | ndev->target_available_prots = nfc_tgt.supported_protocols; |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 248 | ndev->max_data_pkt_payload_size = ntf->max_data_pkt_payload_size; |
| 249 | ndev->initial_num_credits = ntf->initial_num_credits; |
| 250 | |
| 251 | /* set the available credits to initial value */ |
| 252 | atomic_set(&ndev->credits_cnt, ndev->initial_num_credits); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 253 | |
| 254 | nfc_targets_found(ndev->nfc_dev, &nfc_tgt, 1); |
| 255 | } |
| 256 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 257 | static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev, |
| 258 | struct sk_buff *skb) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 259 | { |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 260 | struct nci_rf_intf_activated_ntf ntf; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 261 | __u8 *data = skb->data; |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 262 | int err = 0; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 263 | |
| 264 | clear_bit(NCI_DISCOVERY, &ndev->flags); |
| 265 | set_bit(NCI_POLL_ACTIVE, &ndev->flags); |
| 266 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 267 | ntf.rf_discovery_id = *data++; |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 268 | ntf.rf_interface = *data++; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 269 | ntf.rf_protocol = *data++; |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 270 | ntf.activation_rf_tech_and_mode = *data++; |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 271 | ntf.max_data_pkt_payload_size = *data++; |
| 272 | ntf.initial_num_credits = *data++; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 273 | ntf.rf_tech_specific_params_len = *data++; |
| 274 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 275 | pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id); |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 276 | pr_debug("rf_interface 0x%x\n", ntf.rf_interface); |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 277 | pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol); |
| 278 | pr_debug("activation_rf_tech_and_mode 0x%x\n", |
| 279 | ntf.activation_rf_tech_and_mode); |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 280 | pr_debug("max_data_pkt_payload_size 0x%x\n", |
| 281 | ntf.max_data_pkt_payload_size); |
| 282 | pr_debug("initial_num_credits 0x%x\n", ntf.initial_num_credits); |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 283 | pr_debug("rf_tech_specific_params_len %d\n", |
| 284 | ntf.rf_tech_specific_params_len); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 285 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 286 | if (ntf.rf_tech_specific_params_len > 0) { |
| 287 | switch (ntf.activation_rf_tech_and_mode) { |
| 288 | case NCI_NFC_A_PASSIVE_POLL_MODE: |
| 289 | data = nci_extract_rf_params_nfca_passive_poll(ndev, |
| 290 | &ntf, data); |
| 291 | break; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 292 | |
Ilan Elias | d5a2ca6 | 2012-01-17 11:06:43 +0200 | [diff] [blame^] | 293 | case NCI_NFC_B_PASSIVE_POLL_MODE: |
| 294 | data = nci_extract_rf_params_nfcb_passive_poll(ndev, |
| 295 | &ntf, data); |
| 296 | break; |
| 297 | |
| 298 | case NCI_NFC_F_PASSIVE_POLL_MODE: |
| 299 | data = nci_extract_rf_params_nfcf_passive_poll(ndev, |
| 300 | &ntf, data); |
| 301 | break; |
| 302 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 303 | default: |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 304 | pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", |
| 305 | ntf.activation_rf_tech_and_mode); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 306 | return; |
| 307 | } |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 308 | } |
| 309 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 310 | ntf.data_exch_rf_tech_and_mode = *data++; |
| 311 | ntf.data_exch_tx_bit_rate = *data++; |
| 312 | ntf.data_exch_rx_bit_rate = *data++; |
| 313 | ntf.activation_params_len = *data++; |
| 314 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 315 | pr_debug("data_exch_rf_tech_and_mode 0x%x\n", |
| 316 | ntf.data_exch_rf_tech_and_mode); |
| 317 | pr_debug("data_exch_tx_bit_rate 0x%x\n", |
| 318 | ntf.data_exch_tx_bit_rate); |
| 319 | pr_debug("data_exch_rx_bit_rate 0x%x\n", |
| 320 | ntf.data_exch_rx_bit_rate); |
| 321 | pr_debug("activation_params_len %d\n", |
| 322 | ntf.activation_params_len); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 323 | |
| 324 | if (ntf.activation_params_len > 0) { |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 325 | switch (ntf.rf_interface) { |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 326 | case NCI_RF_INTERFACE_ISO_DEP: |
| 327 | err = nci_extract_activation_params_iso_dep(ndev, |
| 328 | &ntf, data); |
| 329 | break; |
| 330 | |
| 331 | case NCI_RF_INTERFACE_FRAME: |
| 332 | /* no activation params */ |
| 333 | break; |
| 334 | |
| 335 | default: |
Ilan Elias | 637d85a | 2011-12-20 16:57:40 +0200 | [diff] [blame] | 336 | pr_err("unsupported rf_interface 0x%x\n", |
| 337 | ntf.rf_interface); |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 338 | return; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (!err) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 343 | nci_target_found(ndev, &ntf); |
| 344 | } |
| 345 | |
| 346 | static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev, |
| 347 | struct sk_buff *skb) |
| 348 | { |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 349 | struct nci_rf_deactivate_ntf *ntf = (void *) skb->data; |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 350 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 351 | pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 352 | |
| 353 | clear_bit(NCI_POLL_ACTIVE, &ndev->flags); |
| 354 | ndev->target_active_prot = 0; |
| 355 | |
| 356 | /* drop tx data queue */ |
| 357 | skb_queue_purge(&ndev->tx_q); |
| 358 | |
| 359 | /* drop partial rx data packet */ |
| 360 | if (ndev->rx_data_reassembly) { |
| 361 | kfree_skb(ndev->rx_data_reassembly); |
| 362 | ndev->rx_data_reassembly = 0; |
| 363 | } |
| 364 | |
| 365 | /* complete the data exchange transaction, if exists */ |
Ilan Elias | 38f04c6 | 2011-09-22 11:36:19 +0300 | [diff] [blame] | 366 | if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags)) |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 367 | nci_data_exchange_complete(ndev, NULL, -EIO); |
Ilan Elias | bd7e01b | 2012-01-08 11:21:53 +0200 | [diff] [blame] | 368 | |
| 369 | nci_req_complete(ndev, NCI_STATUS_OK); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb) |
| 373 | { |
| 374 | __u16 ntf_opcode = nci_opcode(skb->data); |
| 375 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 376 | pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n", |
| 377 | nci_pbf(skb->data), |
| 378 | nci_opcode_gid(ntf_opcode), |
| 379 | nci_opcode_oid(ntf_opcode), |
| 380 | nci_plen(skb->data)); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 381 | |
| 382 | /* strip the nci control header */ |
| 383 | skb_pull(skb, NCI_CTRL_HDR_SIZE); |
| 384 | |
| 385 | switch (ntf_opcode) { |
| 386 | case NCI_OP_CORE_CONN_CREDITS_NTF: |
| 387 | nci_core_conn_credits_ntf_packet(ndev, skb); |
| 388 | break; |
| 389 | |
Ilan Elias | 004161c | 2011-12-20 16:57:41 +0200 | [diff] [blame] | 390 | case NCI_OP_CORE_INTF_ERROR_NTF: |
| 391 | nci_core_conn_intf_error_ntf_packet(ndev, skb); |
| 392 | break; |
| 393 | |
Ilan Elias | e8c0dac | 2011-11-09 12:09:14 +0200 | [diff] [blame] | 394 | case NCI_OP_RF_INTF_ACTIVATED_NTF: |
| 395 | nci_rf_intf_activated_ntf_packet(ndev, skb); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 396 | break; |
| 397 | |
| 398 | case NCI_OP_RF_DEACTIVATE_NTF: |
| 399 | nci_rf_deactivate_ntf_packet(ndev, skb); |
| 400 | break; |
| 401 | |
| 402 | default: |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 403 | pr_err("unknown ntf opcode 0x%x\n", ntf_opcode); |
Ilan Elias | 6a2968a | 2011-09-18 11:19:35 +0300 | [diff] [blame] | 404 | break; |
| 405 | } |
| 406 | |
| 407 | kfree_skb(skb); |
| 408 | } |