aboutsummaryrefslogtreecommitdiff
path: root/package/neard/neard-fix-missing-linux-nfc-header.patch
blob: b04c5daff856910b09b1da279695765cbd913a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
Add a private copy of <linux/nfc.h>

The addition of the <linux/nfc.h> header in the kernel sources is
moderately recent, and therefore, a number of toolchains don't have
this header.

As a workaround until all reasonable toolchains get this header
included, add a configure check in neard to test whether this header
is available or not, and if not, use our own private copy of it.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,8 @@
 AC_SUBST(NETLINK_CFLAGS)
 AC_SUBST(NETLINK_LIBS)
 
+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>])
+
 AC_ARG_ENABLE(test, AC_HELP_STRING([--enable-test],
 					[enable test/example scripts]),
 					[enable_test=${enableval}])
Index: b/src/near.h
===================================================================
--- a/src/near.h
+++ b/src/near.h
@@ -23,7 +23,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "linux-nfc.h"
+#endif
 
 #include <glib.h>
 
Index: b/src/linux-nfc.h
===================================================================
--- /dev/null
+++ b/src/linux-nfc.h
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2011 Instituto Nokia de Tecnologia
+ *
+ * Authors:
+ *    Lauro Ramos Venancio <lauro.venancio@openbossa.org>
+ *    Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LINUX_NFC_H
+#define __LINUX_NFC_H
+
+#include <linux/types.h>
+#include <linux/socket.h>
+
+#define NFC_GENL_NAME "nfc"
+#define NFC_GENL_VERSION 1
+
+#define NFC_GENL_MCAST_EVENT_NAME "events"
+
+/**
+ * enum nfc_commands - supported nfc commands
+ *
+ * @NFC_CMD_UNSPEC: unspecified command
+ *
+ * @NFC_CMD_GET_DEVICE: request information about a device (requires
+ *	%NFC_ATTR_DEVICE_INDEX) or dump request to get a list of all nfc devices
+ * @NFC_CMD_DEV_UP: turn on the nfc device
+ *	(requires %NFC_ATTR_DEVICE_INDEX)
+ * @NFC_CMD_DEV_DOWN: turn off the nfc device
+ *	(requires %NFC_ATTR_DEVICE_INDEX)
+ * @NFC_CMD_START_POLL: start polling for targets using the given protocols
+ *	(requires %NFC_ATTR_DEVICE_INDEX and %NFC_ATTR_PROTOCOLS)
+ * @NFC_CMD_STOP_POLL: stop polling for targets (requires
+ *	%NFC_ATTR_DEVICE_INDEX)
+ * @NFC_CMD_GET_TARGET: dump all targets found by the previous poll (requires
+ *	%NFC_ATTR_DEVICE_INDEX)
+ * @NFC_EVENT_TARGETS_FOUND: event emitted when a new target is found
+ *	(it sends %NFC_ATTR_DEVICE_INDEX)
+ * @NFC_EVENT_DEVICE_ADDED: event emitted when a new device is registred
+ *	(it sends %NFC_ATTR_DEVICE_NAME, %NFC_ATTR_DEVICE_INDEX and
+ *	%NFC_ATTR_PROTOCOLS)
+ * @NFC_EVENT_DEVICE_REMOVED: event emitted when a device is removed
+ *	(it sends %NFC_ATTR_DEVICE_INDEX)
+ * @NFC_EVENT_TM_ACTIVATED: event emitted when the adapter is activated in
+ *      target mode.
+ * @NFC_EVENT_DEVICE_DEACTIVATED: event emitted when the adapter is deactivated
+ *      from target mode.
+ */
+enum nfc_commands {
+	NFC_CMD_UNSPEC,
+	NFC_CMD_GET_DEVICE,
+	NFC_CMD_DEV_UP,
+	NFC_CMD_DEV_DOWN,
+	NFC_CMD_DEP_LINK_UP,
+	NFC_CMD_DEP_LINK_DOWN,
+	NFC_CMD_START_POLL,
+	NFC_CMD_STOP_POLL,
+	NFC_CMD_GET_TARGET,
+	NFC_EVENT_TARGETS_FOUND,
+	NFC_EVENT_DEVICE_ADDED,
+	NFC_EVENT_DEVICE_REMOVED,
+	NFC_EVENT_TARGET_LOST,
+	NFC_EVENT_TM_ACTIVATED,
+	NFC_EVENT_TM_DEACTIVATED,
+/* private: internal use only */
+	__NFC_CMD_AFTER_LAST
+};
+#define NFC_CMD_MAX (__NFC_CMD_AFTER_LAST - 1)
+
+/**
+ * enum nfc_attrs - supported nfc attributes
+ *
+ * @NFC_ATTR_UNSPEC: unspecified attribute
+ *
+ * @NFC_ATTR_DEVICE_INDEX: index of nfc device
+ * @NFC_ATTR_DEVICE_NAME: device name, max 8 chars
+ * @NFC_ATTR_PROTOCOLS: nfc protocols - bitwise or-ed combination from
+ *	NFC_PROTO_*_MASK constants
+ * @NFC_ATTR_TARGET_INDEX: index of the nfc target
+ * @NFC_ATTR_TARGET_SENS_RES: NFC-A targets extra information such as NFCID
+ * @NFC_ATTR_TARGET_SEL_RES: NFC-A targets extra information (useful if the
+ *	target is not NFC-Forum compliant)
+ * @NFC_ATTR_TARGET_NFCID1: NFC-A targets identifier, max 10 bytes
+ * @NFC_ATTR_TARGET_SENSB_RES: NFC-B targets extra information, max 12 bytes
+ * @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes
+ * @NFC_ATTR_COMM_MODE: Passive or active mode
+ * @NFC_ATTR_RF_MODE: Initiator or target
+ * @NFC_ATTR_IM_PROTOCOLS: Initiator mode protocols to poll for
+ * @NFC_ATTR_TM_PROTOCOLS: Target mode protocols to listen for
+ */
+enum nfc_attrs {
+	NFC_ATTR_UNSPEC,
+	NFC_ATTR_DEVICE_INDEX,
+	NFC_ATTR_DEVICE_NAME,
+	NFC_ATTR_PROTOCOLS,
+	NFC_ATTR_TARGET_INDEX,
+	NFC_ATTR_TARGET_SENS_RES,
+	NFC_ATTR_TARGET_SEL_RES,
+	NFC_ATTR_TARGET_NFCID1,
+	NFC_ATTR_TARGET_SENSB_RES,
+	NFC_ATTR_TARGET_SENSF_RES,
+	NFC_ATTR_COMM_MODE,
+	NFC_ATTR_RF_MODE,
+	NFC_ATTR_DEVICE_POWERED,
+	NFC_ATTR_IM_PROTOCOLS,
+	NFC_ATTR_TM_PROTOCOLS,
+/* private: internal use only */
+	__NFC_ATTR_AFTER_LAST
+};
+#define NFC_ATTR_MAX (__NFC_ATTR_AFTER_LAST - 1)
+
+#define NFC_DEVICE_NAME_MAXSIZE 8
+#define NFC_NFCID1_MAXSIZE 10
+#define NFC_SENSB_RES_MAXSIZE 12
+#define NFC_SENSF_RES_MAXSIZE 18
+#define NFC_GB_MAXSIZE        48
+
+/* NFC protocols */
+#define NFC_PROTO_JEWEL		1
+#define NFC_PROTO_MIFARE	2
+#define NFC_PROTO_FELICA	3
+#define NFC_PROTO_ISO14443	4
+#define NFC_PROTO_NFC_DEP	5
+#define NFC_PROTO_ISO14443_B	6
+
+#define NFC_PROTO_MAX		7
+
+/* NFC communication modes */
+#define NFC_COMM_ACTIVE  0
+#define NFC_COMM_PASSIVE 1
+
+/* NFC RF modes */
+#define NFC_RF_INITIATOR 0
+#define NFC_RF_TARGET    1
+#define NFC_RF_NONE      2
+
+/* NFC protocols masks used in bitsets */
+#define NFC_PROTO_JEWEL_MASK      (1 << NFC_PROTO_JEWEL)
+#define NFC_PROTO_MIFARE_MASK     (1 << NFC_PROTO_MIFARE)
+#define NFC_PROTO_FELICA_MASK	  (1 << NFC_PROTO_FELICA)
+#define NFC_PROTO_ISO14443_MASK	  (1 << NFC_PROTO_ISO14443)
+#define NFC_PROTO_NFC_DEP_MASK	  (1 << NFC_PROTO_NFC_DEP)
+#define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
+
+struct sockaddr_nfc {
+	sa_family_t sa_family;
+	__u32 dev_idx;
+	__u32 target_idx;
+	__u32 nfc_protocol;
+};
+
+#define NFC_LLCP_MAX_SERVICE_NAME 63
+struct sockaddr_nfc_llcp {
+	sa_family_t sa_family;
+	__u32 dev_idx;
+	__u32 target_idx;
+	__u32 nfc_protocol;
+	__u8 dsap; /* Destination SAP, if known */
+	__u8 ssap; /* Source SAP to be bound to */
+	char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
+	size_t service_name_len;
+};
+
+/* NFC socket protocols */
+#define NFC_SOCKPROTO_RAW	0
+#define NFC_SOCKPROTO_LLCP	1
+#define NFC_SOCKPROTO_MAX	2
+
+#define NFC_HEADER_SIZE 1
+
+/**
+ * Pseudo-header info for raw socket packets
+ * First byte is the adapter index
+ * Second byte contains flags
+ *  - 0x01 - Direction (0=RX, 1=TX)
+ *  - 0x02-0x80 - Reserved
+ **/
+#define NFC_LLCP_RAW_HEADER_SIZE	2
+#define NFC_LLCP_DIRECTION_RX		0x00
+#define NFC_LLCP_DIRECTION_TX		0x01
+
+#endif /*__LINUX_NFC_H */
Index: b/plugins/mifare.c
===================================================================
--- a/plugins/mifare.c
+++ b/plugins/mifare.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/p2p.c
===================================================================
--- a/plugins/p2p.c
+++ b/plugins/p2p.c
@@ -30,7 +30,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/handover.c
===================================================================
--- a/plugins/handover.c
+++ b/plugins/handover.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/types.h>
 #include <near/log.h>
Index: b/plugins/nfctype1.c
===================================================================
--- a/plugins/nfctype1.c
+++ b/plugins/nfctype1.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/nfctype2.c
===================================================================
--- a/plugins/nfctype2.c
+++ b/plugins/nfctype2.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/nfctype3.c
===================================================================
--- a/plugins/nfctype3.c
+++ b/plugins/nfctype3.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/nfctype4.c
===================================================================
--- a/plugins/nfctype4.c
+++ b/plugins/nfctype4.c
@@ -30,7 +30,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/npp.c
===================================================================
--- a/plugins/npp.c
+++ b/plugins/npp.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/snep.c
===================================================================
--- a/plugins/snep.c
+++ b/plugins/snep.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/snep-core.c
===================================================================
--- a/plugins/snep-core.c
+++ b/plugins/snep-core.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>
Index: b/plugins/snep-validation.c
===================================================================
--- a/plugins/snep-validation.c
+++ b/plugins/snep-validation.c
@@ -29,7 +29,11 @@
 #include <sys/socket.h>
 
 #include <linux/socket.h>
+#ifdef HAVE_LINUX_NFC_H
 #include <linux/nfc.h>
+#else
+#include "../src/linux-nfc.h"
+#endif
 
 #include <near/plugin.h>
 #include <near/log.h>