Linux NFC User Mode Stack
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 {
103  /*
104  * \brief NDEF text: NFC Forum well-known type + RTD: 0x54
105  */
107  /*
108  * \brief Handover Select package
109  */
111  /*
112  * \brief Handover Request package
113  */
115  /*
116  * \brief not able to decode directly
117  */
120 
124 typedef enum {
138 
142 typedef enum {
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;
187 
191 typedef struct
192 {
196  int is_ndef;
197 
201  unsigned int current_ndef_length;
202 
206  unsigned int max_ndef_length;
207 
212 }ndef_info_t;
213 
217 typedef struct
218 {
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;
248 
252 typedef struct
253 {
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;
283 
287 typedef struct
288 {
292  int has_wifi;
296  unsigned char *ndef;
300  unsigned int ndef_length;
302 
306 typedef struct
307 {
311  nfc_btoob_request_t bluetooth;
317 
321 typedef struct
322 {
332 
336 typedef struct {
341  void (*onTagArrival) (nfc_tag_info_t *pTagInfo);
342 
346  void (*onTagDeparture) (void);
348 
352 typedef struct {
356  void (*onDeviceArrival) ();
357 
361  void (*onDeviceDeparture) (void);
362 
368  void (*onMessageReceived)(unsigned char *message, unsigned int length);
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);
385 
389 typedef struct {
393  void (*onHostCardEmulationActivated) ();
394 
398  void (*onHostCardEmulationDeactivated) ();
399 
405  void (*onDataReceived)(unsigned char *data, unsigned int data_length);
407 
411 typedef struct {
418  void (*onHandoverRequestReceived)(unsigned char *msg, unsigned int length);
425  void (*onHandoverSelectReceived)(unsigned char *msg, unsigned int length);
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 
614 
619 extern int nfcManager_getFwVersion();
620 
626 extern int nfcSnep_registerClientCallback(nfcSnepClientCallback_t *client_callback);
627 
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 
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
friendly NDEF Type Name
Definition: linux_nfc_api.h:98
nfc_btoob_pairing_t bluetooth
Bluetooth Handover select.
int has_wifi
indicates it has wifi request
indicates the carrier power state is unknown
unsigned char * ndef
Handover Carrier Configuration record.
int ndef_readHandoverSelectInfo(unsigned char *ndef_buff, unsigned int ndef_buff_length, nfc_handover_select_t *info)
read handover select message from NDEF data.
int nfcHce_sendCommand(unsigned char *command, unsigned int command_length)
Send Apdu to remote reader.
nfc_handover_cps_t
Handover Carrier Power State definitions.
int nfcHo_sendSelectError(unsigned int reason, unsigned int data)
Send Handover select error to remote device.
unsigned char * ndef
Handover Carrier Configuration record.
nfc_handover_cps_t power_state
Handover Carrier Power State.
void nfcHce_registerHceCallback(nfcHostCardEmulationCallback_t *callback)
Register a callback functions for host card emulation.
NDEF text: NFC Forum well-known type + RTD: 0x55.
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.
int ndef_readHandoverRequestInfo(unsigned char *ndef_buff, unsigned int ndef_buff_length, nfc_handover_request_t *info)
read handover request message from NDEF data.
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.
int nfcTag_isNdef(unsigned int handle, ndef_info_t *info)
Check if the tag is Ndef formated.
void nfcManager_deregisterTagCallback()
Deregister a tag callback functions.
unsigned char * ssid
Wifi network ssid.
NFC handover select record structure definition.
NFC tag information structure definition.
NFC SNEP server callback function structure definition.
struct nfc_btoob_pairing_t nfc_btoob_request_t
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.
unsigned char * device_name
Handover Carrier Data Reference name.
int is_writable
The flags to indicate if writing a Ndef message is supprted.
void nfcHce_deregisterHceCallback()
Deregister the host card emulation callback.
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.
unsigned int current_ndef_length
Existing Ndef message length.
unsigned int technology
indicates the technology of tag
int nfcTag_writeNdef(unsigned int handle, unsigned char *ndef_buffer, unsigned int ndef_buffer_length)
Write ndef message to tag.
NFC handover bluetooth record structure definition.
unsigned char tNFC_PROTOCOL
Definition: linux_nfc_api.h:83
int nfcManager_getFwVersion()
Return FW version.
int is_ndef
The flags to indicate if it contains ndef record.
indicates the carrier is currently on
int nfcSnep_registerClientCallback(nfcSnepClientCallback_t *client_callback)
Register a callback functions for snep client.
int nfcTag_switchRF(unsigned int handle, int is_frame_rf)
Switch RF interface for ISO-DEP and MifareClassic tag.
unsigned int key_length
Wifi netwrok key length.
void nfcManager_disableDiscovery()
Stop polling and listening for devices.
nfc_handover_bt_type_t type
Handover bluetooth carrier configuration record type.
int nfcTag_makeReadOnly(unsigned int handle)
Make the tag read-only.
indicates the carrier is in the process of activation
tNFC_PROTOCOL protocol
activated protocol
unsigned int ndef_length
Handover Carrier Configuration record length.
void nfcSnep_deregisterClientCallback()
Deregister a callback functions for snep client.
unsigned int ndef_length
Handover Carrier Configuration record length.
int nfcHo_sendSelectRecord(unsigned char *message, unsigned int length)
Send Handover Select Message to remote device.
unsigned char * ndef
Handover Carrier Configuration record.
void nfcHo_deregisterCallback()
Deregister the handover callback.
unsigned char * key
Wifi netwrok key.
nfc_handover_cps_t power_state
Handover Carrier Power State.
int nfcManager_doDeinitialize()
de-initialize nfc stack.
int ndef_createUri(char *uri, unsigned char *out_ndef_buff, unsigned int out_ndef_buff_length)
Create a new NDEF Record containing a URI.
unsigned int device_name_length
Handover Carrier Data Reference name length.
int nfcManager_doInitialize()
initialize nfc stack.
NFC Tag callback function structure definition.
int nfcSnep_putMessage(unsigned char *msg, unsigned int length)
put a snep message to remote snep server.
nfc_handover_bt_type_t
Bluetooth Handover Cofiguration Type Name.
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.
indicates this is not a handover bluetooth record
indicates the carrier is currently off
NFC handover request record structure definition.
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.
NFC SNEP client callback function structure definition.
unsigned int max_ndef_length
Max Ndef message length can be written.
Handover callback functions structure definition.
void nfcManager_registerTagCallback(nfcTagCallback_t *callback)
Register a tag callback functions.
Host card emulation callback function structure definition.
unsigned int ndef_length
Handover Carrier Configuration record length.
indicates NFC Forum handover BLE record
NFC Forum handover bluetooth record.
unsigned int uid_length
the uid length
NFC wifi handover select record structure definition.
void nfcManager_enableDiscovery(int technologies_masks, int reader_only_mode, int enable_host_routing, int restart)
Start nfc discovery.
unsigned int ssid_length
Wifi network ssid length.
int nfcHo_registerCallback(nfcHandoverCallback_t *callback)
Register the handover callback.
nfc_btoob_request_t bluetooth
Bluetooth Handover request.
NFC NDEF Message information structure definition.
int nfcManager_isNfcActive()
nfc_wifi_request_t wifi
Wifi Handover request.
void nfcSnep_stopServer()
Stop senp server.
unsigned int handle
the handle of tag
NFC wifi handover request record structure definition.
nfc_wifi_pairing_t wifi
Wifi Handover select.
int nfcSnep_startServer(nfcSnepServerCallback_t *server_callback)
Start a snep server to receive snep message.
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.