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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
/*
* NEARDAL (Neard Abstraction Library)
*
* Copyright 2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2
* as published by the Free Software Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*!
* @file neardal.h
*
* @brief Defines main NEARDAL apis and data types.
* @author Frederic PAUT, Intel Corporation
* @version 0.1
*
******************************************************************************/
#ifndef NEARDAL_H
#define NEARDAL_H
#include "neardal_errors.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*!
* @addtogroup NEARDAL_COMMON_TYPES Types
* @ingroup NEARDAL_COMMON
* @{
*/
/*!
* @brief NEARDAL Adapter client properties
* release with (@link neardal_free_adapter @endlink)
**/
typedef struct {
/*! \brief DBus interface adapter name (as identifier) */
char *name;
/*! \brief Neard adapter NFC radio mode */
char *mode;
/*! \brief Neard adapter polling already active ? */
short polling;
/*! \brief Neard adapter powered ? */
short powered;
/*! \brief Number of supported protocols */
int nbProtocols;
/*! \brief Neard adapter supported protocols list */
char **protocols;
/*! \brief Number of tags managed by this adapter */
int nbTags;
/*! \brief Neard adapter tags list */
char **tags;
/*! \brief Number of devices managed by this adapter */
int nbDevs;
/*! \brief Neard adapter devices list */
char **devs;
} neardal_adapter;
/*!
* @brief NEARDAL Tag client properties.
* release with (@link neardal_free_tag @endlink)
*/
typedef struct {
/*! @brief DBus interface tag name (as identifier) */
const char *name;
/*! @brief Number of records in tag */
int nbRecords;
/*! @brief tag records list */
char **records;
/*! @brief Number of supported 'types' in tag */
int nbTagTypes;
/*! @brief types list */
char **tagType;
/*! @brief tag type */
const char *type;
/*! @brief Read-Only flag (is tag writable?) */
short readOnly;
} neardal_tag;
/*!
* @brief NEARDAL Device client properties.
* release with (@link neardal_free_device @endlink)
*/
typedef struct {
/*! @brief DBus interface tag name (as identifier) */
const char *name;
/*! @brief Number of records in device */
int nbRecords;
/*! @brief device records list */
char **records;
} neardal_dev;
/*!
* @brief NEARDAL Record client properties.
* release with (@link neardal_free_record @endlink)
*/
typedef struct {
/*! @brief DBus interface name (as identifier) */
const char *name;
/*! @brief The character encoding */
const char *encoding;
/*! @brief The ISO/IANA language code (For example "en" or "jp") */
const char *language;
/*! @brief 'Action' Save, Edit, Download... */
const char *action;
/*! @brief The NDEF record type name ("SmartPoster", "Text", "URI",
* "HandoverRequest", "HandoverSelect", "HandoverCarrier" */
const char *type;
/*! @brief human readable representation of a text or title record. */
const char *representation;
/*! @brief the complete URI, including the scheme and the resource */
const char *uri;
/*! @brief URI object size */
unsigned int uriObjSize;
/*! @brief The URI object MIME type */
const char *mime;
/*! @brief The Handover Carrier (e.g. bluetooth) */
const char *carrier;
} neardal_record;
/* @}*/
/*! @brief NEARDAL Callbacks
* @addtogroup NEARDAL_CALLBACK CALLBACKS
* @{
*/
/**
* @brief Callback prototype for 'NEARDAL adapter added/removed'
*
* @param adpName DBus interface adapter name (as identifier=dbus object path)
* @param user_data Client user data
**/
typedef void (*adapter_cb) (const char *adpName, void *user_data);
/**
* @brief Callback prototype for 'NEARDAL adapter property changed'
*
* @param adpName DBus interface adapter name (as identifier=dbus object path)
* @param propName Property name
* @param value Property value
* @param user_data Client user data
**/
typedef void (*adapter_prop_cb) (char *adpName, char *propName, void *value,
void *user_data);
/** @brief NEARDAL Tag Callbacks (TagFound/Lost)
*/
/**
* @brief Callback prototype for 'NEARDAL tag found/lost'
*
* @param tagName DBus interface tag name (as identifier=dbus object path)
* @param user_data Client user data
**/
typedef void (*tag_cb) (const char *tagName, void *user_data);
/** @brief NEARDAL Device Callbacks (Device Found/Lost)
*/
/**
* @brief Callback prototype for 'NEARDAL device found/lost'
*
* @param devName DBus interface dev name (as identifier=dbus object path)
* @param user_data Client user data
**/
typedef void (*dev_cb) (const char *devName, void *user_data);
/** @brief NEARDAL Record Callbacks ('RecordFound')
*/
/**
* @brief Callback prototype for 'NEARDAL record found'
*
* @param rcdName DBus interface record name (as identifier=dbus object path)
* @param user_data Client user data
**/
typedef void (*record_cb) (const char *rcdName, void *user_data);
/**
* @brief Callback prototype for a registered tag type
*
* @param rcdArray array of records path (as identifier=dbus object path)
* @param rcdLen number of records path in rcdArray
* @param ndefArray array of raw NDEF data
* @param ndefLen number of bytes in ndefArray
* @param user_data Client user data
**/
typedef void (*ndef_agent_cb) (unsigned char **rcdArray, unsigned int rcdLen,
unsigned char *ndefArray, unsigned int ndefLen,
void *user_data);
/**
* @brief Callback prototype to cleanup agent user data. Gets called when
* Neard unregisters the agent.
*
* @param user_data Client user data
**/
typedef void (*ndef_agent_free_cb) (void *user_data);
/**
* @brief Pointer to function used to release oob data generated by callback
* @link oob_req_agent_cb @endlink
**/
typedef void (*freeFunc) (void *ptr);
/**
* @brief Callback prototype to get Out Of Band data from the handover agent
*
* @param blobEIR EIR blob as described in Bluetooth Core
* Specification 4.0 (Vol 3, Part C, chapter 8.1.6). Used by SSP capable
* devices
*
* @param blobSize EIR blob size (in bytes)
* @param oobData Out Of Band data returned (as an array of bytes) used to
* build a Handover Request or Select message (oobData* will be never null)
* @param oobDataSize Out Of Band data size returned (oobDataSize* will be
* never null)
* @param freeFunc Free function to release oobData
* @param user_data Client user data
**/
typedef void (*oob_req_agent_cb) (unsigned char *blobEIR,
unsigned int blobSize,
unsigned char **oobData,
unsigned int *oobDataSize, freeFunc *freeF,
void *user_data);
/**
* @brief Callback prototype to to pass remote Out Of Band data to agent to
* start handover
*
* @param blobEIR EIR blob as described in Bluetooth Core
* Specification 4.0 (Vol 3, Part C, chapter 8.1.6). Used by SSP capable
* devices
*
* @param blobSize EIR blob size (in bytes)
* @param user_data Client user data
**/
typedef void (*oob_push_agent_cb) (unsigned char *blobEIR,
unsigned int blobSize, void *user_data);
/**
* @brief Callback prototype to cleanup agent user data. Gets called when
* Neard unregisters the agent.
*
* @param user_data Client user data
**/
typedef void (*oob_agent_free_cb) (void *user_data);
/* @}*/
/*! @brief NEARDAL APIs
* @note NEARDAL lib exported functions
* @addtogroup NEARDAL_APIS APIs
* @{
*/
/*! \fn void neardal_destroy()
* \brief destroy NEARDAL object instance, disconnect Neard Dbus connection,
* unregister Neard's events
*/
void neardal_destroy();
/*! @brief NEARDAL Properties identifiers
* @addtogroup NEARDAL_POLLING_MODE
* @{ */
#define NEARD_ADP_MODE_INITIATOR 0
#define NEARD_ADP_MODE_TARGET 1
#define NEARD_ADP_MODE_DUAL 2
/* @}*/
/*! \fn errorCode_t neardal_start_poll_loop(char *adpName, int mode)
* \brief Request Neard to start polling on specific NEARDAL adapter with
* specific mode
* \param adpName : DBus interface adapter name (as identifier=dbus object
* path)
* \param mode : Polling mode (see @link NEARDAL_POLLING_MODE @endlink ...)
* @return errorCode_t error code
*/
errorCode_t neardal_start_poll_loop(char *adpName, int mode);
/*! \fn errorCode_t neardal_start_poll(char *adpName)
* \brief Request Neard to start polling on specific NEARDAL adapter in
* Initiator mode
* \param adpName : DBus interface adapter name (as identifier=dbus object path)
* @return errorCode_t error code
*/
#define neardal_start_poll(adpName) neardal_start_poll_loop(adpName, \
NEARD_ADP_MODE_INITIATOR);
/*! \fn errorCode_t neardal_stop_poll(char *adpName)
* \brief Request Neard to stop polling on specific NEARDAL adapter
* \param adpName : DBus interface adapter name (as identifier=dbus object path)
* @return errorCode_t error code
*/
errorCode_t neardal_stop_poll(char *adpName);
/*! \fn errorCode_t neardal_get_adapters(char ***array, int *len)
* @brief get an array of NEARDAL adapters present
*
* @param array array of DBus interface adapter name (as identifier=dbus
* object path). release with @link neardal_free_adapter @endlink(& )
* @param len (optional), number of adapters
* @return errorCode_t error code
**/
errorCode_t neardal_get_adapters(char ***array, int *len);
/*! \fn errorCode_t neardal_get_devices(char *adpName, char ***array, int *len)
* @brief get an array of NEARDAL devices present
*
* @param adpName adapter name (identifier) on which devices list must be
* retrieve
* @param array array of DBus interface device name (as identifier=dbus object
* path), release with @link neardal_free_device @endlink(& )
* @param len (optional), number of devs
* @return errorCode_t error code
**/
errorCode_t neardal_get_devices(char *adpName, char ***array, int *len);
/*! \fn errorCode_t neardal_get_tags(char *adpName, char ***array, int *len)
* @brief get an array of NEARDAL tags present
*
* @param adpName adapter name (identifier) on which tags list must be
* retrieve
* @param array array of DBus interface tag name (as identifier=dbus object
* path), release with @link neardal_free_tag @endlink(& )
* @param len (optional), number of tags
* @return errorCode_t error code
**/
errorCode_t neardal_get_tags(char *adpName, char ***array, int *len);
/*! \fn errorCode_t neardal_get_records(char *tagName, char ***array, int *len)
* @brief get an array of NEARDAL records present
*
* @param tagName tag name (identifier) on which records list must be
* retrieve
* @param array array of DBus interface record name (as identifier=dbus object
* path), release with @link neardal_free_record @endlink(& )
* @param len (optional), number of records
* @return errorCode_t error code
**/
errorCode_t neardal_get_records(char *tagName, char ***array, int *len);
/*! @brief NEARDAL Properties identifiers
* @addtogroup NEARDAL_CALLBACK Defines
* @{ */
#define NEARD_ADP_PROP_POWERED 0
/* @}*/
/*! \fn errorCode_t neardal_get_adapter_properties(const char* adpName,
* neardal_adapter **adapter)
* @brief Get properties of a specific NEARDAL adapter
*
* @param adpName DBus interface adapter name (as identifier=dbus object path)
* @param adapter Pointer on pointer of client adapter struct to store datas
* @return errorCode_t error code
**/
errorCode_t neardal_get_adapter_properties(const char *adpName,
neardal_adapter **adapter);
/*! \fn void neardal_free_adapter(neardal_adapter * adapter)
* @brief Release memory allocated for properties of an adapter
*
* @param adapter Pointer on client adapter struct where datas are stored
* @return nothing
**/
void neardal_free_adapter(neardal_adapter *adapter);
/*! \fn errorCode_t neardal_set_adapter_properties(const char* adpName,
* int adpPropId, void * value)
* @brief Set a property on a specific NEARDAL adapter
*
* @param adpName DBus interface adapter name (as identifier=dbus object path)
* @param adpPropId Adapter Property Identifier (see NEARD_ADP_PROP_ ...)
* @param value Value
* @return errorCode_t error code
**/
errorCode_t neardal_set_adapter_property(const char *adpName,
int adpPropId, void *value);
/*! \fn errorCode_t neardal_set_cb_adapter_added( adapter_cb cb_adp_added,
* void * user_data)
* @brief setup a client callback for 'NEARDAL adapter added'. cb_adp_added = NULL
* to remove actual callback
*
* @param cb_adp_added Client callback 'adapter added'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_adapter_added(adapter_cb cb_adp_added,
void *user_data);
/*! \fn errorCode_t neardal_set_cb_adapter_removed(adapter_cb cb_adp_removed,
* void * user_data)
* @brief setup a client callback for 'NEARDAL adapter removed'.
* cb_adp_removed = NULL to remove actual callback
*
* @param cb_adp_removed Client callback 'adapter removed'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_adapter_removed(adapter_cb cb_adp_removed,
void *user_data);
/*! \fn errorCode_t neardal_set_cb_adapter_property_changed(
* adapter_prop_cb cb_adp_property_changed,
* void *user_data)
* @brief setup a client callback for 'NEARDAL Adapter Property Changed'.
* cb_adp_property_changed = NULL to remove actual callback.
*
* @param cb_adp_property_changed Client callback 'Adapter Property Changed'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_adapter_property_changed(
adapter_prop_cb cb_adp_property_changed,
void *user_data);
/*! \fn errorCode_t neardal_get_tag_properties(const char* tagName,
* neardal_tag **tag)
* @brief Get properties of a specific NEARDAL tag
*
* @param tagName tag name (identifier) on which properties must be retrieve
* @param tag Pointer on pointer of client tag struct to store datas
* @return errorCode_t error code
**/
errorCode_t neardal_get_tag_properties(const char *tagName,
neardal_tag **tag);
/*! \fn errorCode_t neardal_tag_write(neardal_record *record)
* @brief Write NDEF record to an NFC tag
*
* @param record Pointer on client record used to create NDEF record
* @return errorCode_t error code
**/
errorCode_t neardal_tag_write(neardal_record *record);
/*! \fn void neardal_free_tag(neardal_tag *tag)
* @brief Release memory allocated for properties of a tag
*
* @param tag Pointer on client tag struct where datas are stored
* @return nothing
**/
void neardal_free_tag(neardal_tag *tag);
/*! \fn errorCode_t neardal_set_cb_tag_found(tag_cb cb_tag_found,
* void * user_data)
* @brief setup a client callback for 'NEARDAL tag found'.
* cb_tag_found = NULL to remove actual callback.
*
* @param cb_tag_found Client callback 'tag found'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_tag_found(tag_cb cb_tag_found,
void *user_data);
/*! \fn errorCode_t neardal_set_cb_tag_lost(tag_cb cb_tag_lost,
* void * user_data)
* @brief setup a client callback for 'NEARDAL tag lost'.
* cb_tag_lost = NULL to remove actual callback.
*
* @param cb_tag_lost Client callback 'tag lost'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_tag_lost(tag_cb cb_tag_lost,
void *user_data);
/*! \fn errorCode_t neardal_get_dev_properties(const char* devName,
* neardal_dev **dev)
* @brief Get properties of a specific NEARDAL dev
*
* @param devName dev name (identifier) on which properties must be retrieve
* @param dev Pointer on pointer of client dev struct to store datas
* @return errorCode_t error code
**/
errorCode_t neardal_get_dev_properties(const char *devName,
neardal_dev **dev);
/*! \fn errorCode_t neardal_dev_push(neardal_record *record)
* @brief Create and push NDEF record to an NFC device
*
* @param record Pointer on client record used to create NDEF record
* @return errorCode_t error code
**/
errorCode_t neardal_dev_push(neardal_record *record);
/*! \fn void neardal_free_device(neardal_dev *dev)
* @brief Release memory allocated for properties of a dev
*
* @param dev Pointer on client dev struct where datas are stored
* @return nothing
**/
void neardal_free_device(neardal_dev *dev);
/*! \fn errorCode_t neardal_set_cb_dev_found(dev_cb cb_dev_found,
* void * user_data)
* @brief setup a client callback for 'NEARDAL dev found'.
* cb_dev_found = NULL to remove actual callback.
*
* @param cb_dev_found Client callback 'dev found'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_dev_found(dev_cb cb_dev_found,
void *user_data);
/*! \fn errorCode_t neardal_set_cb_dev_lost(dev_cb cb_dev_lost,
* void * user_data)
* @brief setup a client callback for 'NEARDAL dev lost'.
* cb_dev_lost = NULL to remove actual callback.
*
* @param cb_dev_lost Client callback 'dev lost'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_dev_lost(dev_cb cb_dev_lost,
void *user_data);
/*! \fn errorCode_t neardal_get_record_properties(const char *recordName,
* neardal_record **record)
* @brief Get properties of a specific NEARDAL tag record
*
* @param recordName DBus interface record name (as identifier=dbus object path)
* @param record Pointer on pointer of client record struct to store datas
* @return errorCode_t error code
**/
errorCode_t neardal_get_record_properties(const char *recordName,
neardal_record **record);
/*! \fn void neardal_free_record(neardal_record *record)
* @brief Release memory allocated for properties of a record
*
* @param record Pointer on client tag struct where datas are stored
* @return nothing
**/
void neardal_free_record(neardal_record *record);
/*! \fn errorCode_t neardal_set_cb_record_found( record_cb cb_rcd_found,
* void * user_data)
* @brief Setup a client callback for 'NEARDAL tag record found'.
* cb_rcd_found = NULL to remove actual callback
*
* @param cb_rcd_found Client callback 'record found'
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_set_cb_record_found(record_cb cb_rcd_found,
void *user_data);
/*! \fn errorCode_t neardal_agent_set_NDEF_cb(char *tagType, agent_cb cb_agent,
* void *user_data)
* @brief register or unregister a callback to handle a record macthing
* a registered tag type. This callback will received the whole NDEF as a raw
* byte stream and the records object paths.
* If the callback is null, the agent is unregistered.
* @param tagType tag type to register
* @param cb_ndef_agent Client callback for the registered tag type
* @param cb_ndef_release_agent Client callback to cleanup agent user data
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_agent_set_NDEF_cb(char *tagType
, ndef_agent_cb cb_ndef_agent
, ndef_agent_free_cb cb_ndef_release_agent
, void *user_data);
/*! \fn errorCode_t neardal_agent_set_handover_cb(
* oob_push_agent_cb cb_oob_push_agent
* , oob_req_agent_cb cb_oob_req_agent
, void *user_data)
* @brief register or unregister two callbacks to handle handover connection.
* If one of this callback is null, the agent is unregistered.
* @param cb_oob_push_agent used to pass remote Out Of Band data
* @param cb_oob_req_agent used to get Out Of Band data
* @param cb_oob_release_agent used to cleanup agent user data
* @param user_data Client user data
* @return errorCode_t error code
**/
errorCode_t neardal_agent_set_handover_cb(oob_push_agent_cb cb_oob_push_agent
, oob_req_agent_cb cb_oob_req_agent
, oob_agent_free_cb cb_oob_release_agent
, void *user_data);
/*! @fn errorCode_t neardal_free_array(char ***array)
*
* @brief free memory used by array of adapters/tags/device or records
*
* @param array array (of adapters/tags/devices or records)
* @return errorCode_t error code
*
**/
errorCode_t neardal_free_array(char ***array);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* NEARDAL_H */
|