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

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