neard-fix-missing-linux-nfc-header.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. Add a private copy of <linux/nfc.h>
  2. The addition of the <linux/nfc.h> header in the kernel sources is
  3. moderately recent, and therefore, a number of toolchains don't have
  4. this header.
  5. As a workaround until all reasonable toolchains get this header
  6. included, add a configure check in neard to test whether this header
  7. is available or not, and if not, use our own private copy of it.
  8. Since symbols from the v3.7 kernel header are used, but linux/nfc.h
  9. already exists since the v3.1 kernel, check for one of the most
  10. recently added symbols: NFC_LLCP_RAW_HEADER_SIZE.
  11. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  12. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
  13. Index: b/configure.ac
  14. ===================================================================
  15. --- a/configure.ac
  16. +++ b/configure.ac
  17. @@ -88,6 +88,12 @@
  18. AC_SUBST(NETLINK_CFLAGS)
  19. AC_SUBST(NETLINK_LIBS)
  20. +AC_TRY_COMPILE([
  21. +#include <sys/socket.h>
  22. +#include <linux/nfc.h>
  23. + ], [int err[NFC_LLCP_RAW_HEADER_SIZE-2];],
  24. + [AC_DEFINE(HAVE_LINUX_NFC_H, 1, [Defines if linux/nfc.h header is available])], [])
  25. +
  26. AC_ARG_ENABLE(test, AC_HELP_STRING([--enable-test],
  27. [enable test/example scripts]),
  28. [enable_test=${enableval}])
  29. Index: b/src/near.h
  30. ===================================================================
  31. --- a/src/near.h
  32. +++ b/src/near.h
  33. @@ -23,7 +23,11 @@
  34. #include <sys/socket.h>
  35. #include <linux/socket.h>
  36. +#ifdef HAVE_LINUX_NFC_H
  37. #include <linux/nfc.h>
  38. +#else
  39. +#include "linux-nfc.h"
  40. +#endif
  41. #include <glib.h>
  42. Index: b/src/linux-nfc.h
  43. ===================================================================
  44. --- /dev/null
  45. +++ b/src/linux-nfc.h
  46. @@ -0,0 +1,197 @@
  47. +/*
  48. + * Copyright (C) 2011 Instituto Nokia de Tecnologia
  49. + *
  50. + * Authors:
  51. + * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
  52. + * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
  53. + *
  54. + * This program is free software; you can redistribute it and/or modify
  55. + * it under the terms of the GNU General Public License as published by
  56. + * the Free Software Foundation; either version 2 of the License, or
  57. + * (at your option) any later version.
  58. + *
  59. + * This program is distributed in the hope that it will be useful,
  60. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  61. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  62. + * GNU General Public License for more details.
  63. + *
  64. + * You should have received a copy of the GNU General Public License
  65. + * along with this program; if not, write to the
  66. + * Free Software Foundation, Inc.,
  67. + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  68. + */
  69. +
  70. +#ifndef __LINUX_NFC_H
  71. +#define __LINUX_NFC_H
  72. +
  73. +#include <linux/types.h>
  74. +#include <linux/socket.h>
  75. +
  76. +#define NFC_GENL_NAME "nfc"
  77. +#define NFC_GENL_VERSION 1
  78. +
  79. +#define NFC_GENL_MCAST_EVENT_NAME "events"
  80. +
  81. +/**
  82. + * enum nfc_commands - supported nfc commands
  83. + *
  84. + * @NFC_CMD_UNSPEC: unspecified command
  85. + *
  86. + * @NFC_CMD_GET_DEVICE: request information about a device (requires
  87. + * %NFC_ATTR_DEVICE_INDEX) or dump request to get a list of all nfc devices
  88. + * @NFC_CMD_DEV_UP: turn on the nfc device
  89. + * (requires %NFC_ATTR_DEVICE_INDEX)
  90. + * @NFC_CMD_DEV_DOWN: turn off the nfc device
  91. + * (requires %NFC_ATTR_DEVICE_INDEX)
  92. + * @NFC_CMD_START_POLL: start polling for targets using the given protocols
  93. + * (requires %NFC_ATTR_DEVICE_INDEX and %NFC_ATTR_PROTOCOLS)
  94. + * @NFC_CMD_STOP_POLL: stop polling for targets (requires
  95. + * %NFC_ATTR_DEVICE_INDEX)
  96. + * @NFC_CMD_GET_TARGET: dump all targets found by the previous poll (requires
  97. + * %NFC_ATTR_DEVICE_INDEX)
  98. + * @NFC_EVENT_TARGETS_FOUND: event emitted when a new target is found
  99. + * (it sends %NFC_ATTR_DEVICE_INDEX)
  100. + * @NFC_EVENT_DEVICE_ADDED: event emitted when a new device is registred
  101. + * (it sends %NFC_ATTR_DEVICE_NAME, %NFC_ATTR_DEVICE_INDEX and
  102. + * %NFC_ATTR_PROTOCOLS)
  103. + * @NFC_EVENT_DEVICE_REMOVED: event emitted when a device is removed
  104. + * (it sends %NFC_ATTR_DEVICE_INDEX)
  105. + * @NFC_EVENT_TM_ACTIVATED: event emitted when the adapter is activated in
  106. + * target mode.
  107. + * @NFC_EVENT_DEVICE_DEACTIVATED: event emitted when the adapter is deactivated
  108. + * from target mode.
  109. + */
  110. +enum nfc_commands {
  111. + NFC_CMD_UNSPEC,
  112. + NFC_CMD_GET_DEVICE,
  113. + NFC_CMD_DEV_UP,
  114. + NFC_CMD_DEV_DOWN,
  115. + NFC_CMD_DEP_LINK_UP,
  116. + NFC_CMD_DEP_LINK_DOWN,
  117. + NFC_CMD_START_POLL,
  118. + NFC_CMD_STOP_POLL,
  119. + NFC_CMD_GET_TARGET,
  120. + NFC_EVENT_TARGETS_FOUND,
  121. + NFC_EVENT_DEVICE_ADDED,
  122. + NFC_EVENT_DEVICE_REMOVED,
  123. + NFC_EVENT_TARGET_LOST,
  124. + NFC_EVENT_TM_ACTIVATED,
  125. + NFC_EVENT_TM_DEACTIVATED,
  126. +/* private: internal use only */
  127. + __NFC_CMD_AFTER_LAST
  128. +};
  129. +#define NFC_CMD_MAX (__NFC_CMD_AFTER_LAST - 1)
  130. +
  131. +/**
  132. + * enum nfc_attrs - supported nfc attributes
  133. + *
  134. + * @NFC_ATTR_UNSPEC: unspecified attribute
  135. + *
  136. + * @NFC_ATTR_DEVICE_INDEX: index of nfc device
  137. + * @NFC_ATTR_DEVICE_NAME: device name, max 8 chars
  138. + * @NFC_ATTR_PROTOCOLS: nfc protocols - bitwise or-ed combination from
  139. + * NFC_PROTO_*_MASK constants
  140. + * @NFC_ATTR_TARGET_INDEX: index of the nfc target
  141. + * @NFC_ATTR_TARGET_SENS_RES: NFC-A targets extra information such as NFCID
  142. + * @NFC_ATTR_TARGET_SEL_RES: NFC-A targets extra information (useful if the
  143. + * target is not NFC-Forum compliant)
  144. + * @NFC_ATTR_TARGET_NFCID1: NFC-A targets identifier, max 10 bytes
  145. + * @NFC_ATTR_TARGET_SENSB_RES: NFC-B targets extra information, max 12 bytes
  146. + * @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes
  147. + * @NFC_ATTR_COMM_MODE: Passive or active mode
  148. + * @NFC_ATTR_RF_MODE: Initiator or target
  149. + * @NFC_ATTR_IM_PROTOCOLS: Initiator mode protocols to poll for
  150. + * @NFC_ATTR_TM_PROTOCOLS: Target mode protocols to listen for
  151. + */
  152. +enum nfc_attrs {
  153. + NFC_ATTR_UNSPEC,
  154. + NFC_ATTR_DEVICE_INDEX,
  155. + NFC_ATTR_DEVICE_NAME,
  156. + NFC_ATTR_PROTOCOLS,
  157. + NFC_ATTR_TARGET_INDEX,
  158. + NFC_ATTR_TARGET_SENS_RES,
  159. + NFC_ATTR_TARGET_SEL_RES,
  160. + NFC_ATTR_TARGET_NFCID1,
  161. + NFC_ATTR_TARGET_SENSB_RES,
  162. + NFC_ATTR_TARGET_SENSF_RES,
  163. + NFC_ATTR_COMM_MODE,
  164. + NFC_ATTR_RF_MODE,
  165. + NFC_ATTR_DEVICE_POWERED,
  166. + NFC_ATTR_IM_PROTOCOLS,
  167. + NFC_ATTR_TM_PROTOCOLS,
  168. +/* private: internal use only */
  169. + __NFC_ATTR_AFTER_LAST
  170. +};
  171. +#define NFC_ATTR_MAX (__NFC_ATTR_AFTER_LAST - 1)
  172. +
  173. +#define NFC_DEVICE_NAME_MAXSIZE 8
  174. +#define NFC_NFCID1_MAXSIZE 10
  175. +#define NFC_SENSB_RES_MAXSIZE 12
  176. +#define NFC_SENSF_RES_MAXSIZE 18
  177. +#define NFC_GB_MAXSIZE 48
  178. +
  179. +/* NFC protocols */
  180. +#define NFC_PROTO_JEWEL 1
  181. +#define NFC_PROTO_MIFARE 2
  182. +#define NFC_PROTO_FELICA 3
  183. +#define NFC_PROTO_ISO14443 4
  184. +#define NFC_PROTO_NFC_DEP 5
  185. +#define NFC_PROTO_ISO14443_B 6
  186. +
  187. +#define NFC_PROTO_MAX 7
  188. +
  189. +/* NFC communication modes */
  190. +#define NFC_COMM_ACTIVE 0
  191. +#define NFC_COMM_PASSIVE 1
  192. +
  193. +/* NFC RF modes */
  194. +#define NFC_RF_INITIATOR 0
  195. +#define NFC_RF_TARGET 1
  196. +#define NFC_RF_NONE 2
  197. +
  198. +/* NFC protocols masks used in bitsets */
  199. +#define NFC_PROTO_JEWEL_MASK (1 << NFC_PROTO_JEWEL)
  200. +#define NFC_PROTO_MIFARE_MASK (1 << NFC_PROTO_MIFARE)
  201. +#define NFC_PROTO_FELICA_MASK (1 << NFC_PROTO_FELICA)
  202. +#define NFC_PROTO_ISO14443_MASK (1 << NFC_PROTO_ISO14443)
  203. +#define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP)
  204. +#define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
  205. +
  206. +struct sockaddr_nfc {
  207. + sa_family_t sa_family;
  208. + __u32 dev_idx;
  209. + __u32 target_idx;
  210. + __u32 nfc_protocol;
  211. +};
  212. +
  213. +#define NFC_LLCP_MAX_SERVICE_NAME 63
  214. +struct sockaddr_nfc_llcp {
  215. + sa_family_t sa_family;
  216. + __u32 dev_idx;
  217. + __u32 target_idx;
  218. + __u32 nfc_protocol;
  219. + __u8 dsap; /* Destination SAP, if known */
  220. + __u8 ssap; /* Source SAP to be bound to */
  221. + char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
  222. + size_t service_name_len;
  223. +};
  224. +
  225. +/* NFC socket protocols */
  226. +#define NFC_SOCKPROTO_RAW 0
  227. +#define NFC_SOCKPROTO_LLCP 1
  228. +#define NFC_SOCKPROTO_MAX 2
  229. +
  230. +#define NFC_HEADER_SIZE 1
  231. +
  232. +/**
  233. + * Pseudo-header info for raw socket packets
  234. + * First byte is the adapter index
  235. + * Second byte contains flags
  236. + * - 0x01 - Direction (0=RX, 1=TX)
  237. + * - 0x02-0x80 - Reserved
  238. + **/
  239. +#define NFC_LLCP_RAW_HEADER_SIZE 2
  240. +#define NFC_LLCP_DIRECTION_RX 0x00
  241. +#define NFC_LLCP_DIRECTION_TX 0x01
  242. +
  243. +#endif /*__LINUX_NFC_H */
  244. Index: b/plugins/mifare.c
  245. ===================================================================
  246. --- a/plugins/mifare.c
  247. +++ b/plugins/mifare.c
  248. @@ -29,7 +29,11 @@
  249. #include <sys/socket.h>
  250. #include <linux/socket.h>
  251. +#ifdef HAVE_LINUX_NFC_H
  252. #include <linux/nfc.h>
  253. +#else
  254. +#include "../src/linux-nfc.h"
  255. +#endif
  256. #include <near/plugin.h>
  257. #include <near/log.h>
  258. Index: b/plugins/p2p.c
  259. ===================================================================
  260. --- a/plugins/p2p.c
  261. +++ b/plugins/p2p.c
  262. @@ -30,7 +30,11 @@
  263. #include <sys/socket.h>
  264. #include <linux/socket.h>
  265. +#ifdef HAVE_LINUX_NFC_H
  266. #include <linux/nfc.h>
  267. +#else
  268. +#include "../src/linux-nfc.h"
  269. +#endif
  270. #include <near/plugin.h>
  271. #include <near/log.h>
  272. Index: b/plugins/handover.c
  273. ===================================================================
  274. --- a/plugins/handover.c
  275. +++ b/plugins/handover.c
  276. @@ -29,7 +29,11 @@
  277. #include <sys/socket.h>
  278. #include <linux/socket.h>
  279. +#ifdef HAVE_LINUX_NFC_H
  280. #include <linux/nfc.h>
  281. +#else
  282. +#include "../src/linux-nfc.h"
  283. +#endif
  284. #include <near/types.h>
  285. #include <near/log.h>
  286. Index: b/plugins/nfctype1.c
  287. ===================================================================
  288. --- a/plugins/nfctype1.c
  289. +++ b/plugins/nfctype1.c
  290. @@ -29,7 +29,11 @@
  291. #include <sys/socket.h>
  292. #include <linux/socket.h>
  293. +#ifdef HAVE_LINUX_NFC_H
  294. #include <linux/nfc.h>
  295. +#else
  296. +#include "../src/linux-nfc.h"
  297. +#endif
  298. #include <near/plugin.h>
  299. #include <near/log.h>
  300. Index: b/plugins/nfctype2.c
  301. ===================================================================
  302. --- a/plugins/nfctype2.c
  303. +++ b/plugins/nfctype2.c
  304. @@ -29,7 +29,11 @@
  305. #include <sys/socket.h>
  306. #include <linux/socket.h>
  307. +#ifdef HAVE_LINUX_NFC_H
  308. #include <linux/nfc.h>
  309. +#else
  310. +#include "../src/linux-nfc.h"
  311. +#endif
  312. #include <near/plugin.h>
  313. #include <near/log.h>
  314. Index: b/plugins/nfctype3.c
  315. ===================================================================
  316. --- a/plugins/nfctype3.c
  317. +++ b/plugins/nfctype3.c
  318. @@ -29,7 +29,11 @@
  319. #include <sys/socket.h>
  320. #include <linux/socket.h>
  321. +#ifdef HAVE_LINUX_NFC_H
  322. #include <linux/nfc.h>
  323. +#else
  324. +#include "../src/linux-nfc.h"
  325. +#endif
  326. #include <near/plugin.h>
  327. #include <near/log.h>
  328. Index: b/plugins/nfctype4.c
  329. ===================================================================
  330. --- a/plugins/nfctype4.c
  331. +++ b/plugins/nfctype4.c
  332. @@ -30,7 +30,11 @@
  333. #include <sys/socket.h>
  334. #include <linux/socket.h>
  335. +#ifdef HAVE_LINUX_NFC_H
  336. #include <linux/nfc.h>
  337. +#else
  338. +#include "../src/linux-nfc.h"
  339. +#endif
  340. #include <near/plugin.h>
  341. #include <near/log.h>
  342. Index: b/plugins/npp.c
  343. ===================================================================
  344. --- a/plugins/npp.c
  345. +++ b/plugins/npp.c
  346. @@ -29,7 +29,11 @@
  347. #include <sys/socket.h>
  348. #include <linux/socket.h>
  349. +#ifdef HAVE_LINUX_NFC_H
  350. #include <linux/nfc.h>
  351. +#else
  352. +#include "../src/linux-nfc.h"
  353. +#endif
  354. #include <near/plugin.h>
  355. #include <near/log.h>
  356. Index: b/plugins/snep.c
  357. ===================================================================
  358. --- a/plugins/snep.c
  359. +++ b/plugins/snep.c
  360. @@ -29,7 +29,11 @@
  361. #include <sys/socket.h>
  362. #include <linux/socket.h>
  363. +#ifdef HAVE_LINUX_NFC_H
  364. #include <linux/nfc.h>
  365. +#else
  366. +#include "../src/linux-nfc.h"
  367. +#endif
  368. #include <near/plugin.h>
  369. #include <near/log.h>
  370. Index: b/plugins/snep-core.c
  371. ===================================================================
  372. --- a/plugins/snep-core.c
  373. +++ b/plugins/snep-core.c
  374. @@ -29,7 +29,11 @@
  375. #include <sys/socket.h>
  376. #include <linux/socket.h>
  377. +#ifdef HAVE_LINUX_NFC_H
  378. #include <linux/nfc.h>
  379. +#else
  380. +#include "../src/linux-nfc.h"
  381. +#endif
  382. #include <near/plugin.h>
  383. #include <near/log.h>
  384. Index: b/plugins/snep-validation.c
  385. ===================================================================
  386. --- a/plugins/snep-validation.c
  387. +++ b/plugins/snep-validation.c
  388. @@ -29,7 +29,11 @@
  389. #include <sys/socket.h>
  390. #include <linux/socket.h>
  391. +#ifdef HAVE_LINUX_NFC_H
  392. #include <linux/nfc.h>
  393. +#else
  394. +#include "../src/linux-nfc.h"
  395. +#endif
  396. #include <near/plugin.h>
  397. #include <near/log.h>