| Linux NFC User Mode Stack

- Main Page
- Classes
- Files

- File List
- File Members

linux_nfc_api.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright (C) 2015 NXP Semiconductors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #ifndef __LINUX_NFC_API__H__
20 #define __LINUX_NFC_API__H__
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 /* Name strings for target types. */
27 #define TARGET_TYPE_UNKNOWN -1
28 #define TARGET_TYPE_ISO14443_3A 1
29 #define TARGET_TYPE_ISO14443_3B 2
30 #define TARGET_TYPE_ISO14443_4 3
31 #define TARGET_TYPE_FELICA 4
32 #define TARGET_TYPE_ISO15693 5
33 #define TARGET_TYPE_NDEF 6
34 #define TARGET_TYPE_NDEF_FORMATABLE 7
35 #define TARGET_TYPE_MIFARE_CLASSIC 8
36 #define TARGET_TYPE_MIFARE_UL 9
37 #define TARGET_TYPE_KOVIO_BARCODE 10
38 #define TARGET_TYPE_ISO14443_3A_3B 11
39
40 /* Definitions for TECHNOLOGY_MASK */
41 #define DEFAULT_NFA_TECH_MASK (-1)
42
43 #define NFA_TECHNOLOGY_MASK_A 0x01
44
45 #define NFA_TECHNOLOGY_MASK_B 0x02
46
47 #define NFA_TECHNOLOGY_MASK_F 0x04
48
49 #define NFA_TECHNOLOGY_MASK_ISO15693 0x08
50
51 #define NFA_TECHNOLOGY_MASK_KOVIO 0x20
52
53 #define NFA_TECHNOLOGY_MASK_A_ACTIVE 0x40
54
55 #define NFA_TECHNOLOGY_MASK_F_ACTIVE 0x80
56
57 #define NFA_TECHNOLOGY_MASK_ALL 0xFF
58
59 /* NDEF Type Name Format */
61 #define NDEF_TNF_EMPTY 0
62
63 #define NDEF_TNF_WELLKNOWN 1
64
65 #define NDEF_TNF_MEDIA 2
66
67 #define NDEF_TNF_URI 3
68
69 #define NDEF_TNF_EXT 4
70
71 #define NDEF_TNF_UNKNOWN 5
72
73 #define NDEF_TNF_UNCHANGED 6
74
75 /* Supported Protocols */
76 #define NFA_PROTOCOL_UNKNOWN 0x00
77 #define NFA_PROTOCOL_T1T 0x01
78 #define NFA_PROTOCOL_T2T 0x02
79 #define NFA_PROTOCOL_T3T 0x03
80 #define NFA_PROTOCOL_ISO_DEP 0x04
81 #define NFA_PROTOCOL_15693 0x06
82 #define NFA_PROTOCOL_MIFARE 0x80
83 typedef unsigned char tNFC_PROTOCOL;
84
89 #define FLAG_HCE_SKIP_NDEF_CHECK 0x80
90
93 #define FLAG_HCE_ENABLE_HCE 0x01
94
98 typedef enum {
102 NDEF_FRIENDLY_TYPE_TEXT = 0,
103 /*
104 * \brief NDEF text: NFC Forum well-known type + RTD: 0x54
105 */
106 NDEF_FRIENDLY_TYPE_URL = 1,
107 /*
108 * \brief Handover Select package
109 */
110 NDEF_FRIENDLY_TYPE_HS = 2,
111 /*
112 * \brief Handover Request package
113 */
114 NDEF_FRIENDLY_TYPE_HR = 3,
115 /*
116 * \brief not able to decode directly
117 */
118 NDEF_FRIENDLY_TYPE_OTHER = 4,
119 }nfc_friendly_type_t;
120
124 typedef enum {
128 HANDOVER_TYPE_UNKNOWN = 0,
132 HANDOVER_TYPE_BT,
136 HANDOVER_TYPE_BLE,
137 }nfc_handover_bt_type_t;
138
142 typedef enum {
146 HANDOVER_CPS_INACTIVE = 0,
150 HANDOVER_CPS_ACTIVE = 1,
154 HANDOVER_CPS_ACTIVATING = 2,
158 HANDOVER_CPS_UNKNOWN = 3,
159 }nfc_handover_cps_t;
160
164 typedef struct
165 {
169 unsigned int technology;
173 unsigned int handle;
177 char uid[32];
181 unsigned int uid_length;
185 tNFC_PROTOCOL protocol;
186 }nfc_tag_info_t;
187
191 typedef struct
192 {
196 int is_ndef;
197
201 unsigned int current_ndef_length;
202
206 unsigned int max_ndef_length;
207
211 int is_writable;
212 }ndef_info_t;
213
217 typedef struct
218 {
222 nfc_handover_cps_t power_state;
226 nfc_handover_bt_type_t type;
230 unsigned char *ndef;
234 unsigned int ndef_length;
238 unsigned char address[6];
242 unsigned char *device_name;
246 unsigned int device_name_length;
247 }nfc_btoob_pairing_t, nfc_btoob_request_t;
248
252 typedef struct
253 {
257 nfc_handover_cps_t power_state;
261 unsigned char *ndef;
265 unsigned int ndef_length;
269 unsigned char *ssid;
273 unsigned int ssid_length;
277 unsigned char *key;
281 unsigned int key_length;
282 }nfc_wifi_pairing_t;
283
287 typedef struct
288 {
292 int has_wifi;
296 unsigned char *ndef;
300 unsigned int ndef_length;
301 }nfc_wifi_request_t;
302
306 typedef struct
307 {
311 nfc_btoob_request_t bluetooth;
315 nfc_wifi_request_t wifi;
316 }nfc_handover_request_t;
317
321 typedef struct
322 {
326 nfc_btoob_pairing_t bluetooth;
330 nfc_wifi_pairing_t wifi;
331 }nfc_handover_select_t;
332
336 typedef struct {
341 void (*onTagArrival) (nfc_tag_info_t *pTagInfo);
342
346 void (*onTagDeparture) (void);
347 }nfcTagCallback_t;
348
352 typedef struct {
356 void (*onDeviceArrival) ();
357
361 void (*onDeviceDeparture) (void);
362
368 void (*onMessageReceived)(unsigned char *message, unsigned int length);
369 }nfcSnepServerCallback_t;
370
374 typedef struct {
375 /*
376 * \brief NFC Peer Device callback function when device is detected.
377 */
378 void (*onDeviceArrival)();
379
383 void (*onDeviceDeparture) (void);
384 }nfcSnepClientCallback_t;
385
389 typedef struct {
393 void (*onHostCardEmulationActivated) ();
394
398 void (*onHostCardEmulationDeactivated) ();
399
405 void (*onDataReceived)(unsigned char *data, unsigned int data_length);
406 }nfcHostCardEmulationCallback_t;
407
411 typedef struct {
418 void (*onHandoverRequestReceived)(unsigned char *msg, unsigned int length);
425 void (*onHandoverSelectReceived)(unsigned char *msg, unsigned int length);
426 }nfcHandoverCallback_t;
427
436 extern int ndef_readText(unsigned char *ndef_buff, unsigned int ndef_buff_length, char * out_text, unsigned int out_text_length);
437
446 extern int ndef_readUrl(unsigned char *ndef_buff, unsigned int ndef_buff_length, char * out_url, unsigned int out_url_length);
447
455 extern int ndef_readHandoverSelectInfo(unsigned char *ndef_buff, unsigned int ndef_buff_length, nfc_handover_select_t *info);
456
464 extern int ndef_readHandoverRequestInfo(unsigned char *ndef_buff, unsigned int ndef_buff_length, nfc_handover_request_t *info);
465
473 extern int ndef_createUri(char *uri, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length);
474
483 extern int ndef_createText(char *language_code, char *text,
484 unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length);
485
495 extern int ndef_createMime(char *mime_type, unsigned char *mime_data, unsigned int mime_data_length,
496 unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length);
497
508 extern int ndef_createHandoverSelect(nfc_handover_cps_t cps, char *carrier_data_ref,
509 unsigned char *ndef_buff, unsigned int ndef_buff_length, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length);
510
518 extern int nfcTag_isNdef(unsigned int handle, ndef_info_t *info);
519
529 extern int nfcTag_readNdef(unsigned int handle, unsigned char *ndef_buffer, unsigned int ndef_buffer_length, nfc_friendly_type_t *friendly_ndef_type);
530
538 extern int nfcTag_writeNdef(unsigned int handle, unsigned char *ndef_buffer, unsigned int ndef_buffer_length);
539
545 extern int nfcTag_makeReadOnly(unsigned int handle);
546
553 extern int nfcTag_switchRF(unsigned int handle, int is_frame_rf);
554
565 extern int nfcTag_transceive (unsigned int handle, unsigned char *tx_buffer, int tx_buffer_length, unsigned char* rx_buffer, int rx_buffer_length, unsigned int timeout);
566
571 extern int nfcManager_doInitialize ();
572
577 extern int nfcManager_doDeinitialize ();
578
579 /*
580 * \brief Check if nfc stack is running or not.
581 * \return 1 if running, otherwise 0.
582 */
583 extern int nfcManager_isNfcActive();
584
593 extern void nfcManager_enableDiscovery (int technologies_masks,
594 int reader_only_mode, int enable_host_routing, int restart);
595
600 extern void nfcManager_disableDiscovery ();
601
607 extern void nfcManager_registerTagCallback(nfcTagCallback_t *callback);
608
613 extern void nfcManager_deregisterTagCallback();
614
619 extern int nfcManager_getFwVersion();
620
626 extern int nfcSnep_registerClientCallback(nfcSnepClientCallback_t *client_callback);
627
632 extern void nfcSnep_deregisterClientCallback();
633
639 extern int nfcSnep_startServer(nfcSnepServerCallback_t *server_callback);
640
645 extern void nfcSnep_stopServer();
646
653 extern int nfcSnep_putMessage(unsigned char* msg, unsigned int length);
654
660 extern void nfcHce_registerHceCallback(nfcHostCardEmulationCallback_t *callback);
661
666 extern void nfcHce_deregisterHceCallback();
667
674 extern int nfcHce_sendCommand(unsigned char* command, unsigned int command_length);
675
681 extern int nfcHo_registerCallback(nfcHandoverCallback_t *callback);
682
687 extern void nfcHo_deregisterCallback();
688
695 extern int nfcHo_sendSelectRecord(unsigned char *message, unsigned int length);
696
703 extern int nfcHo_sendSelectError(unsigned int reason, unsigned int data);
704
705 #ifdef __cplusplus
706 }
707 #endif
708
709 #endif //__LINUX_NFC_API__H__
nfc_friendly_type_t
nfc_friendly_type_t
friendly NDEF Type Name
Definition: linux_nfc_api.h:98
nfc_handover_select_t::bluetooth
nfc_btoob_pairing_t bluetooth
Bluetooth Handover select.
Definition: linux_nfc_api.h:326
nfc_wifi_request_t::has_wifi
int has_wifi
indicates it has wifi request
Definition: linux_nfc_api.h:292
HANDOVER_CPS_UNKNOWN
indicates the carrier power state is unknown
Definition: linux_nfc_api.h:158
nfc_wifi_pairing_t::ndef
unsigned char * ndef
Handover Carrier Configuration record.
Definition: linux_nfc_api.h:261
ndef_readHandoverSelectInfo
int ndef_readHandoverSelectInfo(unsigned char *ndef_buff, unsigned int ndef_buff_length, nfc_handover_select_t *info)
read handover select message from NDEF data.
nfcHce_sendCommand
int nfcHce_sendCommand(unsigned char *command, unsigned int command_length)
Send Apdu to remote reader.
nfc_handover_cps_t
nfc_handover_cps_t
Handover Carrier Power State definitions.
Definition: linux_nfc_api.h:142
nfcHo_sendSelectError
int nfcHo_sendSelectError(unsigned int reason, unsigned int data)
Send Handover select error to remote device.
nfc_wifi_request_t::ndef
unsigned char * ndef
Handover Carrier Configuration record.
Definition: linux_nfc_api.h:296
nfc_wifi_pairing_t::power_state
nfc_handover_cps_t power_state
Handover Carrier Power State.
Definition: linux_nfc_api.h:257
nfcHce_registerHceCallback
void nfcHce_registerHceCallback(nfcHostCardEmulationCallback_t *callback)
Register a callback functions for host card emulation.
NDEF_FRIENDLY_TYPE_TEXT
NDEF text: NFC Forum well-known type + RTD: 0x55.
Definition: linux_nfc_api.h:102
ndef_readText
int ndef_readText(unsigned char *ndef_buff, unsigned int ndef_buff_length, char *out_text, unsigned int out_text_length)
read text message from NDEF data.
ndef_readHandoverRequestInfo
int ndef_readHandoverRequestInfo(unsigned char *ndef_buff, unsigned int ndef_buff_length, nfc_handover_request_t *info)
read handover request message from NDEF data.
ndef_createText
int ndef_createText(char *language_code, char *text, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length)
Create a new NDEF Record containing a text.
nfcTag_isNdef
int nfcTag_isNdef(unsigned int handle, ndef_info_t *info)
Check if the tag is Ndef formated.
nfcManager_deregisterTagCallback
void nfcManager_deregisterTagCallback()
Deregister a tag callback functions.
nfc_wifi_pairing_t::ssid
unsigned char * ssid
Wifi network ssid.
Definition: linux_nfc_api.h:269
nfc_handover_select_t
NFC handover select record structure definition.
Definition: linux_nfc_api.h:321
nfc_tag_info_t
NFC tag information structure definition.
Definition: linux_nfc_api.h:164
nfcSnepServerCallback_t
NFC SNEP server callback function structure definition.
Definition: linux_nfc_api.h:352
nfc_btoob_request_t
struct nfc_btoob_pairing_t nfc_btoob_request_t
ndef_createMime
int ndef_createMime(char *mime_type, unsigned char *mime_data, unsigned int mime_data_length, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length)
Create a new NDEF Record containing MIME data.
nfc_btoob_pairing_t::device_name
unsigned char * device_name
Handover Carrier Data Reference name.
Definition: linux_nfc_api.h:242
ndef_info_t::is_writable
int is_writable
The flags to indicate if writing a Ndef message is supprted.
Definition: linux_nfc_api.h:211
NDEF_FRIENDLY_TYPE_HS
Definition: linux_nfc_api.h:110
nfcHce_deregisterHceCallback
void nfcHce_deregisterHceCallback()
Deregister the host card emulation callback.
nfcTag_readNdef
int nfcTag_readNdef(unsigned int handle, unsigned char *ndef_buffer, unsigned int ndef_buffer_length, nfc_friendly_type_t *friendly_ndef_type)
Read ndef message from tag.
ndef_info_t::current_ndef_length
unsigned int current_ndef_length
Existing Ndef message length.
Definition: linux_nfc_api.h:201
nfc_tag_info_t::technology
unsigned int technology
indicates the technology of tag
Definition: linux_nfc_api.h:169
nfcTag_writeNdef
int nfcTag_writeNdef(unsigned int handle, unsigned char *ndef_buffer, unsigned int ndef_buffer_length)
Write ndef message to tag.
nfc_btoob_pairing_t
NFC handover bluetooth record structure definition.
Definition: linux_nfc_api.h:217
tNFC_PROTOCOL
unsigned char tNFC_PROTOCOL
Definition: linux_nfc_api.h:83
nfcManager_getFwVersion
int nfcManager_getFwVersion()
Return FW version.
ndef_info_t::is_ndef
int is_ndef
The flags to indicate if it contains ndef record.
Definition: linux_nfc_api.h:196
HANDOVER_CPS_ACTIVE
indicates the carrier is currently on
Definition: linux_nfc_api.h:150
nfcSnep_registerClientCallback
int nfcSnep_registerClientCallback(nfcSnepClientCallback_t *client_callback)
Register a callback functions for snep client.
nfcTag_switchRF
int nfcTag_switchRF(unsigned int handle, int is_frame_rf)
Switch RF interface for ISO-DEP and MifareClassic tag.
nfc_wifi_pairing_t::key_length
unsigned int key_length
Wifi netwrok key length.
Definition: linux_nfc_api.h:281
nfcManager_disableDiscovery
void nfcManager_disableDiscovery()
Stop polling and listening for devices.
nfc_btoob_pairing_t::type
nfc_handover_bt_type_t type
Handover bluetooth carrier configuration record type.
Definition: linux_nfc_api.h:226
nfcTag_makeReadOnly
int nfcTag_makeReadOnly(unsigned int handle)
Make the tag read-only.
HANDOVER_CPS_ACTIVATING
indicates the carrier is in the process of activation
Definition: linux_nfc_api.h:154
nfc_tag_info_t::protocol
tNFC_PROTOCOL protocol
activated protocol
Definition: linux_nfc_api.h:185
nfc_wifi_request_t::ndef_length
unsigned int ndef_length
Handover Carrier Configuration record length.
Definition: linux_nfc_api.h:300
nfcSnep_deregisterClientCallback
void nfcSnep_deregisterClientCallback()
Deregister a callback functions for snep client.
nfc_wifi_pairing_t::ndef_length
unsigned int ndef_length
Handover Carrier Configuration record length.
Definition: linux_nfc_api.h:265
nfcHo_sendSelectRecord
int nfcHo_sendSelectRecord(unsigned char *message, unsigned int length)
Send Handover Select Message to remote device.
nfc_btoob_pairing_t::ndef
unsigned char * ndef
Handover Carrier Configuration record.
Definition: linux_nfc_api.h:230
nfcHo_deregisterCallback
void nfcHo_deregisterCallback()
Deregister the handover callback.
nfc_wifi_pairing_t::key
unsigned char * key
Wifi netwrok key.
Definition: linux_nfc_api.h:277
nfc_btoob_pairing_t::power_state
nfc_handover_cps_t power_state
Handover Carrier Power State.
Definition: linux_nfc_api.h:222
nfcManager_doDeinitialize
int nfcManager_doDeinitialize()
de-initialize nfc stack.
NDEF_FRIENDLY_TYPE_URL
Definition: linux_nfc_api.h:106
ndef_createUri
int ndef_createUri(char *uri, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length)
Create a new NDEF Record containing a URI.
nfc_btoob_pairing_t::device_name_length
unsigned int device_name_length
Handover Carrier Data Reference name length.
Definition: linux_nfc_api.h:246
nfcManager_doInitialize
int nfcManager_doInitialize()
initialize nfc stack.
nfcTagCallback_t
NFC Tag callback function structure definition.
Definition: linux_nfc_api.h:336
nfcSnep_putMessage
int nfcSnep_putMessage(unsigned char *msg, unsigned int length)
put a snep message to remote snep server.
NDEF_FRIENDLY_TYPE_OTHER
Definition: linux_nfc_api.h:118
nfc_handover_bt_type_t
nfc_handover_bt_type_t
Bluetooth Handover Cofiguration Type Name.
Definition: linux_nfc_api.h:124
nfcTag_transceive
int nfcTag_transceive(unsigned int handle, unsigned char *tx_buffer, int tx_buffer_length, unsigned char *rx_buffer, int rx_buffer_length, unsigned int timeout)
Send raw command to tag.
HANDOVER_TYPE_UNKNOWN
indicates this is not a handover bluetooth record
Definition: linux_nfc_api.h:128
HANDOVER_CPS_INACTIVE
indicates the carrier is currently off
Definition: linux_nfc_api.h:146
nfc_handover_request_t
NFC handover request record structure definition.
Definition: linux_nfc_api.h:306
ndef_createHandoverSelect
int ndef_createHandoverSelect(nfc_handover_cps_t cps, char *carrier_data_ref, unsigned char *ndef_buff, unsigned int ndef_buff_length, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length)
Create a new NDEF Record containing Handover Select message.
nfcSnepClientCallback_t
NFC SNEP client callback function structure definition.
Definition: linux_nfc_api.h:374
ndef_info_t::max_ndef_length
unsigned int max_ndef_length
Max Ndef message length can be written.
Definition: linux_nfc_api.h:206
nfcHandoverCallback_t
Handover callback functions structure definition.
Definition: linux_nfc_api.h:411
nfcManager_registerTagCallback
void nfcManager_registerTagCallback(nfcTagCallback_t *callback)
Register a tag callback functions.
nfcHostCardEmulationCallback_t
Host card emulation callback function structure definition.
Definition: linux_nfc_api.h:389
nfc_btoob_pairing_t::ndef_length
unsigned int ndef_length
Handover Carrier Configuration record length.
Definition: linux_nfc_api.h:234
HANDOVER_TYPE_BLE
indicates NFC Forum handover BLE record
Definition: linux_nfc_api.h:136
HANDOVER_TYPE_BT
NFC Forum handover bluetooth record.
Definition: linux_nfc_api.h:132
NDEF_FRIENDLY_TYPE_HR
Definition: linux_nfc_api.h:114
nfc_tag_info_t::uid_length
unsigned int uid_length
the uid length
Definition: linux_nfc_api.h:181
nfc_wifi_pairing_t
NFC wifi handover select record structure definition.
Definition: linux_nfc_api.h:252
nfcManager_enableDiscovery
void nfcManager_enableDiscovery(int technologies_masks, int reader_only_mode, int enable_host_routing, int restart)
Start nfc discovery.
nfc_wifi_pairing_t::ssid_length
unsigned int ssid_length
Wifi network ssid length.
Definition: linux_nfc_api.h:273
nfcHo_registerCallback
int nfcHo_registerCallback(nfcHandoverCallback_t *callback)
Register the handover callback.
nfc_handover_request_t::bluetooth
nfc_btoob_request_t bluetooth
Bluetooth Handover request.
Definition: linux_nfc_api.h:311
ndef_info_t
NFC NDEF Message information structure definition.
Definition: linux_nfc_api.h:191
nfcManager_isNfcActive
int nfcManager_isNfcActive()
nfc_handover_request_t::wifi
nfc_wifi_request_t wifi
Wifi Handover request.
Definition: linux_nfc_api.h:315
nfcSnep_stopServer
void nfcSnep_stopServer()
Stop senp server.
nfc_tag_info_t::handle
unsigned int handle
the handle of tag
Definition: linux_nfc_api.h:173
nfc_wifi_request_t
NFC wifi handover request record structure definition.
Definition: linux_nfc_api.h:287
nfc_handover_select_t::wifi
nfc_wifi_pairing_t wifi
Wifi Handover select.
Definition: linux_nfc_api.h:330
nfcSnep_startServer
int nfcSnep_startServer(nfcSnepServerCallback_t *server_callback)
Start a snep server to receive snep message.
ndef_readUrl
int ndef_readUrl(unsigned char *ndef_buff, unsigned int ndef_buff_length, char *out_url, unsigned int out_url_length)
read uri message from NDEF data.