nfc.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2011 Instituto Nokia de Tecnologia
  3. *
  4. * Authors:
  5. * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
  6. * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the
  20. * Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __LINUX_NFC_H
  24. #define __LINUX_NFC_H
  25. #include <linux/types.h>
  26. #include <linux/socket.h>
  27. #define NFC_GENL_NAME "nfc"
  28. #define NFC_GENL_VERSION 1
  29. #define NFC_GENL_MCAST_EVENT_NAME "events"
  30. /**
  31. * enum nfc_commands - supported nfc commands
  32. *
  33. * @NFC_CMD_UNSPEC: unspecified command
  34. *
  35. * @NFC_CMD_GET_DEVICE: request information about a device (requires
  36. * %NFC_ATTR_DEVICE_INDEX) or dump request to get a list of all nfc devices
  37. * @NFC_CMD_DEV_UP: turn on the nfc device
  38. * (requires %NFC_ATTR_DEVICE_INDEX)
  39. * @NFC_CMD_DEV_DOWN: turn off the nfc device
  40. * (requires %NFC_ATTR_DEVICE_INDEX)
  41. * @NFC_CMD_START_POLL: start polling for targets using the given protocols
  42. * (requires %NFC_ATTR_DEVICE_INDEX and %NFC_ATTR_PROTOCOLS)
  43. * @NFC_CMD_STOP_POLL: stop polling for targets (requires
  44. * %NFC_ATTR_DEVICE_INDEX)
  45. * @NFC_CMD_GET_TARGET: dump all targets found by the previous poll (requires
  46. * %NFC_ATTR_DEVICE_INDEX)
  47. * @NFC_EVENT_TARGETS_FOUND: event emitted when a new target is found
  48. * (it sends %NFC_ATTR_DEVICE_INDEX)
  49. * @NFC_EVENT_DEVICE_ADDED: event emitted when a new device is registred
  50. * (it sends %NFC_ATTR_DEVICE_NAME, %NFC_ATTR_DEVICE_INDEX and
  51. * %NFC_ATTR_PROTOCOLS)
  52. * @NFC_EVENT_DEVICE_REMOVED: event emitted when a device is removed
  53. * (it sends %NFC_ATTR_DEVICE_INDEX)
  54. */
  55. enum nfc_commands {
  56. NFC_CMD_UNSPEC,
  57. NFC_CMD_GET_DEVICE,
  58. NFC_CMD_DEV_UP,
  59. NFC_CMD_DEV_DOWN,
  60. NFC_CMD_DEP_LINK_UP,
  61. NFC_CMD_DEP_LINK_DOWN,
  62. NFC_CMD_START_POLL,
  63. NFC_CMD_STOP_POLL,
  64. NFC_CMD_GET_TARGET,
  65. NFC_EVENT_TARGETS_FOUND,
  66. NFC_EVENT_DEVICE_ADDED,
  67. NFC_EVENT_DEVICE_REMOVED,
  68. /* private: internal use only */
  69. __NFC_CMD_AFTER_LAST
  70. };
  71. #define NFC_CMD_MAX (__NFC_CMD_AFTER_LAST - 1)
  72. /**
  73. * enum nfc_attrs - supported nfc attributes
  74. *
  75. * @NFC_ATTR_UNSPEC: unspecified attribute
  76. *
  77. * @NFC_ATTR_DEVICE_INDEX: index of nfc device
  78. * @NFC_ATTR_DEVICE_NAME: device name, max 8 chars
  79. * @NFC_ATTR_PROTOCOLS: nfc protocols - bitwise or-ed combination from
  80. * NFC_PROTO_*_MASK constants
  81. * @NFC_ATTR_TARGET_INDEX: index of the nfc target
  82. * @NFC_ATTR_TARGET_SENS_RES: NFC-A targets extra information such as NFCID
  83. * @NFC_ATTR_TARGET_SEL_RES: NFC-A targets extra information (useful if the
  84. * target is not NFC-Forum compliant)
  85. * @NFC_ATTR_TARGET_NFCID1: NFC-A targets identifier, max 10 bytes
  86. * @NFC_ATTR_TARGET_SENSB_RES: NFC-B targets extra information, max 12 bytes
  87. * @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes
  88. * @NFC_ATTR_COMM_MODE: Passive or active mode
  89. * @NFC_ATTR_RF_MODE: Initiator or target
  90. */
  91. enum nfc_attrs {
  92. NFC_ATTR_UNSPEC,
  93. NFC_ATTR_DEVICE_INDEX,
  94. NFC_ATTR_DEVICE_NAME,
  95. NFC_ATTR_PROTOCOLS,
  96. NFC_ATTR_TARGET_INDEX,
  97. NFC_ATTR_TARGET_SENS_RES,
  98. NFC_ATTR_TARGET_SEL_RES,
  99. NFC_ATTR_TARGET_NFCID1,
  100. NFC_ATTR_TARGET_SENSB_RES,
  101. NFC_ATTR_TARGET_SENSF_RES,
  102. NFC_ATTR_COMM_MODE,
  103. NFC_ATTR_RF_MODE,
  104. NFC_ATTR_DEVICE_POWERED,
  105. /* private: internal use only */
  106. __NFC_ATTR_AFTER_LAST
  107. };
  108. #define NFC_ATTR_MAX (__NFC_ATTR_AFTER_LAST - 1)
  109. #define NFC_DEVICE_NAME_MAXSIZE 8
  110. #define NFC_NFCID1_MAXSIZE 10
  111. #define NFC_SENSB_RES_MAXSIZE 12
  112. #define NFC_SENSF_RES_MAXSIZE 18
  113. /* NFC protocols */
  114. #define NFC_PROTO_JEWEL 1
  115. #define NFC_PROTO_MIFARE 2
  116. #define NFC_PROTO_FELICA 3
  117. #define NFC_PROTO_ISO14443 4
  118. #define NFC_PROTO_NFC_DEP 5
  119. #define NFC_PROTO_MAX 6
  120. /* NFC communication modes */
  121. #define NFC_COMM_ACTIVE 0
  122. #define NFC_COMM_PASSIVE 1
  123. /* NFC RF modes */
  124. #define NFC_RF_INITIATOR 0
  125. #define NFC_RF_TARGET 1
  126. /* NFC protocols masks used in bitsets */
  127. #define NFC_PROTO_JEWEL_MASK (1 << NFC_PROTO_JEWEL)
  128. #define NFC_PROTO_MIFARE_MASK (1 << NFC_PROTO_MIFARE)
  129. #define NFC_PROTO_FELICA_MASK (1 << NFC_PROTO_FELICA)
  130. #define NFC_PROTO_ISO14443_MASK (1 << NFC_PROTO_ISO14443)
  131. #define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP)
  132. struct sockaddr_nfc {
  133. sa_family_t sa_family;
  134. __u32 dev_idx;
  135. __u32 target_idx;
  136. __u32 nfc_protocol;
  137. };
  138. #define NFC_LLCP_MAX_SERVICE_NAME 63
  139. struct sockaddr_nfc_llcp {
  140. sa_family_t sa_family;
  141. __u32 dev_idx;
  142. __u32 target_idx;
  143. __u32 nfc_protocol;
  144. __u8 dsap; /* Destination SAP, if known */
  145. __u8 ssap; /* Source SAP to be bound to */
  146. char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
  147. size_t service_name_len;
  148. };
  149. /* NFC socket protocols */
  150. #define NFC_SOCKPROTO_RAW 0
  151. #define NFC_SOCKPROTO_LLCP 1
  152. #define NFC_SOCKPROTO_MAX 2
  153. #define NFC_HEADER_SIZE 1
  154. #endif /*__LINUX_NFC_H */