st-nci.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * NCI based Driver for STMicroelectronics NFC Chip
  4. *
  5. * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
  6. */
  7. #ifndef __LOCAL_ST_NCI_H_
  8. #define __LOCAL_ST_NCI_H_
  9. #include "ndlc.h"
  10. /* Define private flags: */
  11. #define ST_NCI_RUNNING 1
  12. #define ST_NCI_CORE_PROP 0x01
  13. #define ST_NCI_SET_NFC_MODE 0x02
  14. /*
  15. * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
  16. * sequence of at most 32 characters.
  17. */
  18. #define ST_NCI_ESE_MAX_LENGTH 33
  19. #define ST_NCI_DEVICE_MGNT_GATE 0x01
  20. #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
  21. #define ST_NCI_FACTORY_MODE 2
  22. struct nci_mode_set_cmd {
  23. u8 cmd_type;
  24. u8 mode;
  25. } __packed;
  26. struct nci_mode_set_rsp {
  27. u8 status;
  28. } __packed;
  29. struct st_nci_se_status {
  30. bool is_ese_present;
  31. bool is_uicc_present;
  32. };
  33. struct st_nci_se_info {
  34. struct st_nci_se_status *se_status;
  35. u8 atr[ST_NCI_ESE_MAX_LENGTH];
  36. struct completion req_completion;
  37. struct timer_list bwi_timer;
  38. int wt_timeout; /* in msecs */
  39. bool bwi_active;
  40. struct timer_list se_active_timer;
  41. bool se_active;
  42. bool xch_error;
  43. se_io_cb_t cb;
  44. void *cb_context;
  45. };
  46. /**
  47. * enum nfc_vendor_cmds - supported nfc vendor commands
  48. *
  49. * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
  50. * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
  51. * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
  52. * It does not consider any NFC_ATTR_VENDOR_DATA.
  53. * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
  54. * RF trimmings or low level drivers configurations (I2C, SPI, SWP).
  55. * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
  56. * table following RF technology, CLF mode or protocol.
  57. * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
  58. * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
  59. * level drivers configurations or RF trimmings.
  60. * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
  61. * packet can be more than 8KB.
  62. * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
  63. * configuration changes without CLF power off.
  64. * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
  65. * white list).
  66. * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
  67. * technology. When using this command to anti-collision is done.
  68. * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
  69. * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
  70. * CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
  71. * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
  72. * specific CLF command as there is no GPIO for this.
  73. * @HCI_DM_FWUPD_END: Allow to complete firmware update.
  74. * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
  75. * CLF antenna to a reference value.
  76. * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
  77. * received during a NCI_CORE_INIT_CMD.
  78. */
  79. enum nfc_vendor_cmds {
  80. FACTORY_MODE,
  81. HCI_CLEAR_ALL_PIPES,
  82. HCI_DM_PUT_DATA,
  83. HCI_DM_UPDATE_AID,
  84. HCI_DM_GET_INFO,
  85. HCI_DM_GET_DATA,
  86. HCI_DM_DIRECT_LOAD,
  87. HCI_DM_RESET,
  88. HCI_GET_PARAM,
  89. HCI_DM_FIELD_GENERATOR,
  90. LOOPBACK,
  91. HCI_DM_FWUPD_START,
  92. HCI_DM_FWUPD_END,
  93. HCI_DM_VDC_MEASUREMENT_VALUE,
  94. HCI_DM_VDC_VALUE_COMPARISON,
  95. MANUFACTURER_SPECIFIC,
  96. };
  97. struct st_nci_info {
  98. struct llt_ndlc *ndlc;
  99. unsigned long flags;
  100. struct st_nci_se_info se_info;
  101. };
  102. void st_nci_remove(struct nci_dev *ndev);
  103. int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
  104. int phy_tailroom, struct st_nci_se_status *se_status);
  105. int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
  106. void st_nci_se_deinit(struct nci_dev *ndev);
  107. int st_nci_discover_se(struct nci_dev *ndev);
  108. int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
  109. int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
  110. int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
  111. u8 *apdu, size_t apdu_length,
  112. se_io_cb_t cb, void *cb_context);
  113. int st_nci_hci_load_session(struct nci_dev *ndev);
  114. void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
  115. u8 event, struct sk_buff *skb);
  116. void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
  117. struct sk_buff *skb);
  118. int st_nci_vendor_cmds_init(struct nci_dev *ndev);
  119. #endif /* __LOCAL_ST_NCI_H_ */