rsp.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #include <linux/types.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/bitops.h>
  30. #include <linux/skbuff.h>
  31. #include "../nfc.h"
  32. #include <net/nfc/nci.h>
  33. #include <net/nfc/nci_core.h>
  34. /* Handle NCI Response packets */
  35. static void nci_core_reset_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
  36. {
  37. struct nci_core_reset_rsp *rsp = (void *) skb->data;
  38. nfc_dbg("entry, status 0x%x", rsp->status);
  39. if (rsp->status == NCI_STATUS_OK) {
  40. ndev->nci_ver = rsp->nci_ver;
  41. nfc_dbg("nci_ver 0x%x, config_status 0x%x",
  42. rsp->nci_ver, rsp->config_status);
  43. }
  44. nci_req_complete(ndev, rsp->status);
  45. }
  46. static void nci_core_init_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
  47. {
  48. struct nci_core_init_rsp_1 *rsp_1 = (void *) skb->data;
  49. struct nci_core_init_rsp_2 *rsp_2;
  50. nfc_dbg("entry, status 0x%x", rsp_1->status);
  51. if (rsp_1->status != NCI_STATUS_OK)
  52. goto exit;
  53. ndev->nfcc_features = __le32_to_cpu(rsp_1->nfcc_features);
  54. ndev->num_supported_rf_interfaces = rsp_1->num_supported_rf_interfaces;
  55. if (ndev->num_supported_rf_interfaces >
  56. NCI_MAX_SUPPORTED_RF_INTERFACES) {
  57. ndev->num_supported_rf_interfaces =
  58. NCI_MAX_SUPPORTED_RF_INTERFACES;
  59. }
  60. memcpy(ndev->supported_rf_interfaces,
  61. rsp_1->supported_rf_interfaces,
  62. ndev->num_supported_rf_interfaces);
  63. rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
  64. ndev->max_logical_connections =
  65. rsp_2->max_logical_connections;
  66. ndev->max_routing_table_size =
  67. __le16_to_cpu(rsp_2->max_routing_table_size);
  68. ndev->max_ctrl_pkt_payload_len =
  69. rsp_2->max_ctrl_pkt_payload_len;
  70. ndev->max_size_for_large_params =
  71. __le16_to_cpu(rsp_2->max_size_for_large_params);
  72. ndev->max_data_pkt_payload_size =
  73. rsp_2->max_data_pkt_payload_size;
  74. ndev->initial_num_credits =
  75. rsp_2->initial_num_credits;
  76. ndev->manufact_id =
  77. rsp_2->manufact_id;
  78. ndev->manufact_specific_info =
  79. __le32_to_cpu(rsp_2->manufact_specific_info);
  80. atomic_set(&ndev->credits_cnt, ndev->initial_num_credits);
  81. nfc_dbg("nfcc_features 0x%x",
  82. ndev->nfcc_features);
  83. nfc_dbg("num_supported_rf_interfaces %d",
  84. ndev->num_supported_rf_interfaces);
  85. nfc_dbg("supported_rf_interfaces[0] 0x%x",
  86. ndev->supported_rf_interfaces[0]);
  87. nfc_dbg("supported_rf_interfaces[1] 0x%x",
  88. ndev->supported_rf_interfaces[1]);
  89. nfc_dbg("supported_rf_interfaces[2] 0x%x",
  90. ndev->supported_rf_interfaces[2]);
  91. nfc_dbg("supported_rf_interfaces[3] 0x%x",
  92. ndev->supported_rf_interfaces[3]);
  93. nfc_dbg("max_logical_connections %d",
  94. ndev->max_logical_connections);
  95. nfc_dbg("max_routing_table_size %d",
  96. ndev->max_routing_table_size);
  97. nfc_dbg("max_ctrl_pkt_payload_len %d",
  98. ndev->max_ctrl_pkt_payload_len);
  99. nfc_dbg("max_size_for_large_params %d",
  100. ndev->max_size_for_large_params);
  101. nfc_dbg("max_data_pkt_payload_size %d",
  102. ndev->max_data_pkt_payload_size);
  103. nfc_dbg("initial_num_credits %d",
  104. ndev->initial_num_credits);
  105. nfc_dbg("manufact_id 0x%x",
  106. ndev->manufact_id);
  107. nfc_dbg("manufact_specific_info 0x%x",
  108. ndev->manufact_specific_info);
  109. exit:
  110. nci_req_complete(ndev, rsp_1->status);
  111. }
  112. static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev,
  113. struct sk_buff *skb)
  114. {
  115. __u8 status = skb->data[0];
  116. nfc_dbg("entry, status 0x%x", status);
  117. nci_req_complete(ndev, status);
  118. }
  119. static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
  120. {
  121. __u8 status = skb->data[0];
  122. nfc_dbg("entry, status 0x%x", status);
  123. if (status == NCI_STATUS_OK)
  124. set_bit(NCI_DISCOVERY, &ndev->flags);
  125. nci_req_complete(ndev, status);
  126. }
  127. static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
  128. struct sk_buff *skb)
  129. {
  130. __u8 status = skb->data[0];
  131. nfc_dbg("entry, status 0x%x", status);
  132. clear_bit(NCI_DISCOVERY, &ndev->flags);
  133. nci_req_complete(ndev, status);
  134. }
  135. void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
  136. {
  137. __u16 rsp_opcode = nci_opcode(skb->data);
  138. /* we got a rsp, stop the cmd timer */
  139. del_timer(&ndev->cmd_timer);
  140. nfc_dbg("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d",
  141. nci_pbf(skb->data),
  142. nci_opcode_gid(rsp_opcode),
  143. nci_opcode_oid(rsp_opcode),
  144. nci_plen(skb->data));
  145. /* strip the nci control header */
  146. skb_pull(skb, NCI_CTRL_HDR_SIZE);
  147. switch (rsp_opcode) {
  148. case NCI_OP_CORE_RESET_RSP:
  149. nci_core_reset_rsp_packet(ndev, skb);
  150. break;
  151. case NCI_OP_CORE_INIT_RSP:
  152. nci_core_init_rsp_packet(ndev, skb);
  153. break;
  154. case NCI_OP_RF_DISCOVER_MAP_RSP:
  155. nci_rf_disc_map_rsp_packet(ndev, skb);
  156. break;
  157. case NCI_OP_RF_DISCOVER_RSP:
  158. nci_rf_disc_rsp_packet(ndev, skb);
  159. break;
  160. case NCI_OP_RF_DEACTIVATE_RSP:
  161. nci_rf_deactivate_rsp_packet(ndev, skb);
  162. break;
  163. default:
  164. nfc_err("unknown rsp opcode 0x%x", rsp_opcode);
  165. break;
  166. }
  167. kfree_skb(skb);
  168. /* trigger the next cmd */
  169. atomic_set(&ndev->cmd_cnt, 1);
  170. if (!skb_queue_empty(&ndev->cmd_q))
  171. queue_work(ndev->cmd_wq, &ndev->cmd_work);
  172. }