rsp.c (251f39fe42dae863bd24e30864e6b66076ba076d) | rsp.c (637d85a7cdfe4240a56da7d70cf95cca65ea21d3) |
---|---|
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 * --- 11 unchanged lines hidden (view full) --- 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 | 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 * --- 11 unchanged lines hidden (view full) --- 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 |
28#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ 29 |
|
28#include <linux/types.h> 29#include <linux/interrupt.h> 30#include <linux/bitops.h> 31#include <linux/skbuff.h> 32 33#include "../nfc.h" 34#include <net/nfc/nci.h> 35#include <net/nfc/nci_core.h> 36 37/* Handle NCI Response packets */ 38 39static void nci_core_reset_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 40{ 41 struct nci_core_reset_rsp *rsp = (void *) skb->data; 42 | 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/* Handle NCI Response packets */ 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 |
43 nfc_dbg("entry, status 0x%x", rsp->status); | 45 pr_debug("status 0x%x\n", rsp->status); |
44 | 46 |
45 if (rsp->status == NCI_STATUS_OK) | 47 if (rsp->status == NCI_STATUS_OK) { |
46 ndev->nci_ver = rsp->nci_ver; | 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 } |
|
47 | 52 |
48 nfc_dbg("nci_ver 0x%x", ndev->nci_ver); 49 | |
50 nci_req_complete(ndev, rsp->status); 51} 52 53static void nci_core_init_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 54{ 55 struct nci_core_init_rsp_1 *rsp_1 = (void *) skb->data; 56 struct nci_core_init_rsp_2 *rsp_2; 57 | 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 |
58 nfc_dbg("entry, status 0x%x", rsp_1->status); | 61 pr_debug("status 0x%x\n", rsp_1->status); |
59 60 if (rsp_1->status != NCI_STATUS_OK) | 62 63 if (rsp_1->status != NCI_STATUS_OK) |
61 return; | 64 goto exit; |
62 63 ndev->nfcc_features = __le32_to_cpu(rsp_1->nfcc_features); 64 ndev->num_supported_rf_interfaces = rsp_1->num_supported_rf_interfaces; 65 66 if (ndev->num_supported_rf_interfaces > | 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 > |
67 NCI_MAX_SUPPORTED_RF_INTERFACES) { | 70 NCI_MAX_SUPPORTED_RF_INTERFACES) { |
68 ndev->num_supported_rf_interfaces = 69 NCI_MAX_SUPPORTED_RF_INTERFACES; 70 } 71 72 memcpy(ndev->supported_rf_interfaces, 73 rsp_1->supported_rf_interfaces, 74 ndev->num_supported_rf_interfaces); 75 | 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 |
76 rsp_2 = (void *) (skb->data + 6 + ndev->num_supported_rf_interfaces); | 79 rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces); |
77 78 ndev->max_logical_connections = 79 rsp_2->max_logical_connections; 80 ndev->max_routing_table_size = 81 __le16_to_cpu(rsp_2->max_routing_table_size); | 80 81 ndev->max_logical_connections = 82 rsp_2->max_logical_connections; 83 ndev->max_routing_table_size = 84 __le16_to_cpu(rsp_2->max_routing_table_size); |
82 ndev->max_control_packet_payload_length = 83 rsp_2->max_control_packet_payload_length; 84 ndev->rf_sending_buffer_size = 85 __le16_to_cpu(rsp_2->rf_sending_buffer_size); 86 ndev->rf_receiving_buffer_size = 87 __le16_to_cpu(rsp_2->rf_receiving_buffer_size); 88 ndev->manufacturer_id = 89 __le16_to_cpu(rsp_2->manufacturer_id); | 85 ndev->max_ctrl_pkt_payload_len = 86 rsp_2->max_ctrl_pkt_payload_len; 87 ndev->max_size_for_large_params = 88 __le16_to_cpu(rsp_2->max_size_for_large_params); 89 ndev->manufact_id = 90 rsp_2->manufact_id; 91 ndev->manufact_specific_info = 92 __le32_to_cpu(rsp_2->manufact_specific_info); |
90 | 93 |
91 nfc_dbg("nfcc_features 0x%x", 92 ndev->nfcc_features); 93 nfc_dbg("num_supported_rf_interfaces %d", 94 ndev->num_supported_rf_interfaces); 95 nfc_dbg("supported_rf_interfaces[0] 0x%x", 96 ndev->supported_rf_interfaces[0]); 97 nfc_dbg("supported_rf_interfaces[1] 0x%x", 98 ndev->supported_rf_interfaces[1]); 99 nfc_dbg("supported_rf_interfaces[2] 0x%x", 100 ndev->supported_rf_interfaces[2]); 101 nfc_dbg("supported_rf_interfaces[3] 0x%x", 102 ndev->supported_rf_interfaces[3]); 103 nfc_dbg("max_logical_connections %d", 104 ndev->max_logical_connections); 105 nfc_dbg("max_routing_table_size %d", 106 ndev->max_routing_table_size); 107 nfc_dbg("max_control_packet_payload_length %d", 108 ndev->max_control_packet_payload_length); 109 nfc_dbg("rf_sending_buffer_size %d", 110 ndev->rf_sending_buffer_size); 111 nfc_dbg("rf_receiving_buffer_size %d", 112 ndev->rf_receiving_buffer_size); 113 nfc_dbg("manufacturer_id 0x%x", 114 ndev->manufacturer_id); | 94 pr_debug("nfcc_features 0x%x\n", 95 ndev->nfcc_features); 96 pr_debug("num_supported_rf_interfaces %d\n", 97 ndev->num_supported_rf_interfaces); 98 pr_debug("supported_rf_interfaces[0] 0x%x\n", 99 ndev->supported_rf_interfaces[0]); 100 pr_debug("supported_rf_interfaces[1] 0x%x\n", 101 ndev->supported_rf_interfaces[1]); 102 pr_debug("supported_rf_interfaces[2] 0x%x\n", 103 ndev->supported_rf_interfaces[2]); 104 pr_debug("supported_rf_interfaces[3] 0x%x\n", 105 ndev->supported_rf_interfaces[3]); 106 pr_debug("max_logical_connections %d\n", 107 ndev->max_logical_connections); 108 pr_debug("max_routing_table_size %d\n", 109 ndev->max_routing_table_size); 110 pr_debug("max_ctrl_pkt_payload_len %d\n", 111 ndev->max_ctrl_pkt_payload_len); 112 pr_debug("max_size_for_large_params %d\n", 113 ndev->max_size_for_large_params); 114 pr_debug("manufact_id 0x%x\n", 115 ndev->manufact_id); 116 pr_debug("manufact_specific_info 0x%x\n", 117 ndev->manufact_specific_info); |
115 | 118 |
119exit: |
|
116 nci_req_complete(ndev, rsp_1->status); 117} 118 | 120 nci_req_complete(ndev, rsp_1->status); 121} 122 |
119static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, 120 struct sk_buff *skb) 121{ 122 struct nci_core_conn_create_rsp *rsp = (void *) skb->data; 123 124 nfc_dbg("entry, status 0x%x", rsp->status); 125 126 if (rsp->status != NCI_STATUS_OK) 127 return; 128 129 ndev->max_pkt_payload_size = rsp->max_pkt_payload_size; 130 ndev->initial_num_credits = rsp->initial_num_credits; 131 ndev->conn_id = rsp->conn_id; 132 133 atomic_set(&ndev->credits_cnt, ndev->initial_num_credits); 134 135 nfc_dbg("max_pkt_payload_size %d", ndev->max_pkt_payload_size); 136 nfc_dbg("initial_num_credits %d", ndev->initial_num_credits); 137 nfc_dbg("conn_id %d", ndev->conn_id); 138} 139 | |
140static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev, 141 struct sk_buff *skb) 142{ 143 __u8 status = skb->data[0]; 144 | 123static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev, 124 struct sk_buff *skb) 125{ 126 __u8 status = skb->data[0]; 127 |
145 nfc_dbg("entry, status 0x%x", status); | 128 pr_debug("status 0x%x\n", status); |
146 147 nci_req_complete(ndev, status); 148} 149 150static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 151{ 152 __u8 status = skb->data[0]; 153 | 129 130 nci_req_complete(ndev, status); 131} 132 133static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 134{ 135 __u8 status = skb->data[0]; 136 |
154 nfc_dbg("entry, status 0x%x", status); | 137 pr_debug("status 0x%x\n", status); |
155 156 if (status == NCI_STATUS_OK) 157 set_bit(NCI_DISCOVERY, &ndev->flags); 158 159 nci_req_complete(ndev, status); 160} 161 162static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev, 163 struct sk_buff *skb) 164{ 165 __u8 status = skb->data[0]; 166 | 138 139 if (status == NCI_STATUS_OK) 140 set_bit(NCI_DISCOVERY, &ndev->flags); 141 142 nci_req_complete(ndev, status); 143} 144 145static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev, 146 struct sk_buff *skb) 147{ 148 __u8 status = skb->data[0]; 149 |
167 nfc_dbg("entry, status 0x%x", status); | 150 pr_debug("status 0x%x\n", status); |
168 169 clear_bit(NCI_DISCOVERY, &ndev->flags); 170 171 nci_req_complete(ndev, status); 172} 173 174void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 175{ 176 __u16 rsp_opcode = nci_opcode(skb->data); 177 178 /* we got a rsp, stop the cmd timer */ 179 del_timer(&ndev->cmd_timer); 180 | 151 152 clear_bit(NCI_DISCOVERY, &ndev->flags); 153 154 nci_req_complete(ndev, status); 155} 156 157void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 158{ 159 __u16 rsp_opcode = nci_opcode(skb->data); 160 161 /* we got a rsp, stop the cmd timer */ 162 del_timer(&ndev->cmd_timer); 163 |
181 nfc_dbg("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d", 182 nci_pbf(skb->data), 183 nci_opcode_gid(rsp_opcode), 184 nci_opcode_oid(rsp_opcode), 185 nci_plen(skb->data)); | 164 pr_debug("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n", 165 nci_pbf(skb->data), 166 nci_opcode_gid(rsp_opcode), 167 nci_opcode_oid(rsp_opcode), 168 nci_plen(skb->data)); |
186 187 /* strip the nci control header */ 188 skb_pull(skb, NCI_CTRL_HDR_SIZE); 189 190 switch (rsp_opcode) { 191 case NCI_OP_CORE_RESET_RSP: 192 nci_core_reset_rsp_packet(ndev, skb); 193 break; 194 195 case NCI_OP_CORE_INIT_RSP: 196 nci_core_init_rsp_packet(ndev, skb); 197 break; 198 | 169 170 /* strip the nci control header */ 171 skb_pull(skb, NCI_CTRL_HDR_SIZE); 172 173 switch (rsp_opcode) { 174 case NCI_OP_CORE_RESET_RSP: 175 nci_core_reset_rsp_packet(ndev, skb); 176 break; 177 178 case NCI_OP_CORE_INIT_RSP: 179 nci_core_init_rsp_packet(ndev, skb); 180 break; 181 |
199 case NCI_OP_CORE_CONN_CREATE_RSP: 200 nci_core_conn_create_rsp_packet(ndev, skb); 201 break; 202 | |
203 case NCI_OP_RF_DISCOVER_MAP_RSP: 204 nci_rf_disc_map_rsp_packet(ndev, skb); 205 break; 206 207 case NCI_OP_RF_DISCOVER_RSP: 208 nci_rf_disc_rsp_packet(ndev, skb); 209 break; 210 211 case NCI_OP_RF_DEACTIVATE_RSP: 212 nci_rf_deactivate_rsp_packet(ndev, skb); 213 break; 214 215 default: | 182 case NCI_OP_RF_DISCOVER_MAP_RSP: 183 nci_rf_disc_map_rsp_packet(ndev, skb); 184 break; 185 186 case NCI_OP_RF_DISCOVER_RSP: 187 nci_rf_disc_rsp_packet(ndev, skb); 188 break; 189 190 case NCI_OP_RF_DEACTIVATE_RSP: 191 nci_rf_deactivate_rsp_packet(ndev, skb); 192 break; 193 194 default: |
216 nfc_err("unknown rsp opcode 0x%x", rsp_opcode); | 195 pr_err("unknown rsp opcode 0x%x\n", rsp_opcode); |
217 break; 218 } 219 220 kfree_skb(skb); 221 222 /* trigger the next cmd */ 223 atomic_set(&ndev->cmd_cnt, 1); 224 if (!skb_queue_empty(&ndev->cmd_q)) 225 queue_work(ndev->cmd_wq, &ndev->cmd_work); 226} | 196 break; 197 } 198 199 kfree_skb(skb); 200 201 /* trigger the next cmd */ 202 atomic_set(&ndev->cmd_cnt, 1); 203 if (!skb_queue_empty(&ndev->cmd_q)) 204 queue_work(ndev->cmd_wq, &ndev->cmd_work); 205} |