Tizen Native API  5.0
Peer to Peer

The peer to peer api provide functions to exchange NDEF data with peer target.

Required Header

#include <nfc.h>

Overview

The peer to peer api provides functions to exchange NDEF data with the peer target.

  • send ndef message
  • receive ndef message

Related Features

This API is related with the following features:

It is recommended to design feature related codes in your application for reliability.

You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.

To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.

More details on featuring your application can be found from Feature Element.

Functions

int nfc_p2p_set_data_received_cb (nfc_p2p_target_h target, nfc_p2p_data_received_cb callback, void *user_data)
 Registers a callback function for receiving data from NFC peer-to-peer target.
int nfc_p2p_unset_data_received_cb (nfc_p2p_target_h target)
 Unregisters the callback function.
int nfc_p2p_send (nfc_p2p_target_h target, nfc_ndef_message_h message, nfc_p2p_send_completed_cb callback, void *user_data)
 Sends data to NFC peer-to-peer target.
int nfc_snep_start_server (nfc_p2p_target_h target, const char *san, int sap, nfc_snep_event_cb callback, void *user_data)
 Start peer-to-peer server using SNEP protocol.
int nfc_snep_start_client (nfc_p2p_target_h target, const char *san, int sap, nfc_snep_event_cb callback, void *user_data)
 Start peer-to-peer client using SNEP protocol.
int nfc_snep_send_client_request (nfc_p2p_snep_h handle, nfc_snep_type_e type, nfc_ndef_message_h msg, nfc_snep_event_cb callback, void *user_data)
 Send request message to peer-to-peer client using SNEP protocol.
int nfc_snep_stop_service (nfc_p2p_target_h target, nfc_p2p_snep_h service)
 Stop snep server or client.
int nfc_snep_register_server (const char *san, int sap, nfc_snep_event_cb callback, void *user_data)
 Register peer-to-peer server using SNEP protocol.
int nfc_snep_unregister_server (const char *san, int sap)
 Unregister snep server or client.

Typedefs

typedef void * nfc_p2p_target_h
 The handle to NFC p2p target.
typedef struct _nfc_p2p_snep_s * nfc_p2p_snep_h
 The handle to NFC p2p snep instance.
typedef void(* nfc_p2p_send_completed_cb )(nfc_error_e result, void *user_data)
 Called after nfc_p2p_send() has completed.
typedef void(* nfc_p2p_data_received_cb )(nfc_p2p_target_h target, nfc_ndef_message_h message, void *user_data)
 Called after nfc_p2p_send() has completed.
typedef void(* nfc_snep_event_cb )(nfc_p2p_snep_h handle, nfc_snep_event_e event, nfc_error_e result, nfc_ndef_message_h msg, void *user_data)
 Called when SNEP event is raised.

Typedef Documentation

typedef void(* nfc_p2p_data_received_cb)(nfc_p2p_target_h target, nfc_ndef_message_h message, void *user_data)

Called after nfc_p2p_send() has completed.

Since :
2.3
Remarks:
message will be automatically destroyed when the callback function returns. (Do not release message.)
Parameters:
[in]targetThe handle to p2p target
[in]messageThe received message
[in]user_dataThe user data passed from nfc_p2p_set_recv_cb()
See also:
nfc_p2p_set_data_received_cb()
nfc_p2p_unset_data_received_cb()
typedef void(* nfc_p2p_send_completed_cb)(nfc_error_e result, void *user_data)

Called after nfc_p2p_send() has completed.

Since :
2.3
Parameters:
[in]resultThe result of function call
[in]user_dataThe user data passed from nfc_p2p_send()
See also:
nfc_p2p_send()
typedef struct _nfc_p2p_snep_s* nfc_p2p_snep_h

The handle to NFC p2p snep instance.

Since :
2.3
typedef void* nfc_p2p_target_h

The handle to NFC p2p target.

Since :
2.3
typedef void(* nfc_snep_event_cb)(nfc_p2p_snep_h handle, nfc_snep_event_e event, nfc_error_e result, nfc_ndef_message_h msg, void *user_data)

Called when SNEP event is raised.

Since :
2.3
Parameters:
[in]handleThe handle of current snep instance
[in]eventThe kind of snep event
[in]resultThe result of snep event
[in]msgThe ndef message which received from client or result of get request
[in]user_dataThe user data passed from snep apis.
See also:
nfc_snep_start_server()
nfc_snep_send_client_request()

Enumeration Type Documentation

Enumerations for SNEP event.

Since :
2.3
Enumerator:
NFC_SNEP_EVENT_STOP 

server or client stopped

NFC_SNEP_EVENT_START 

server started or client connected

NFC_SNEP_EVENT_GET 

server received get request

NFC_SNEP_EVENT_PUT 

server received put request

NFC_SNEP_EVENT_REGISTER 

service registered

NFC_SNEP_EVENT_UNREGISTER 

service unregistered

Enumerations for SNEP request type.

Since :
2.3
Enumerator:
NFC_SNEP_GET 

get request

NFC_SNEP_PUT 

put request


Function Documentation

int nfc_p2p_send ( nfc_p2p_target_h  target,
nfc_ndef_message_h  message,
nfc_p2p_send_completed_cb  callback,
void *  user_data 
)

Sends data to NFC peer-to-peer target.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]targetThe handle to peer target
[in]messageThe message to send
[in]callbackThe callback function to invoke after this function has completed
It can be null if notification is not required
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OUT_OF_MEMORYOut of memory
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_DEVICE_BUSYDevice is too busy to handle your request
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
Postcondition:
It invokes nfc_p2p_send_completed_cb() when it has completed to p2p send.
The Callback can receive error code when process is done.
See also:
nfc_p2p_send_completed_cb()
nfc_p2p_target_discovered_cb()
nfc_manager_initialize()
int nfc_p2p_set_data_received_cb ( nfc_p2p_target_h  target,
nfc_p2p_data_received_cb  callback,
void *  user_data 
)

Registers a callback function for receiving data from NFC peer-to-peer target.

Since :
2.3
Parameters:
[in]targetThe handle to peer target
[in]callbackThe callback function to invoke when an NDEF Message is discovered
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_INVALID_PARAMETERInvalid parameter
See also:
nfc_p2p_set_data_received_cb()
nfc_p2p_unset_data_received_cb()
nfc_p2p_target_discovered_cb()
nfc_manager_initialize()

Unregisters the callback function.

Since :
2.3
Parameters:
[in]targetThe handle to peer target
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_INVALID_PARAMETERInvalid parameter
See also:
nfc_p2p_set_data_received_cb()
nfc_p2p_unset_data_received_cb()
nfc_p2p_target_discovered_cb()
nfc_manager_initialize()
int nfc_snep_register_server ( const char *  san,
int  sap,
nfc_snep_event_cb  callback,
void *  user_data 
)

Register peer-to-peer server using SNEP protocol.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]sanThe name of service (service access name)
[in]sapThe number of service (service access point)
[in]callbackThe callback function to invoke after this function has completed
It can be null if notification is not required
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OUT_OF_MEMORYOut of memory
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_DEVICE_BUSYDevice is too busy to handle your request
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
Postcondition:
It invokes nfc_snep_event_cb() when snep event is occured.
The Callback can receive error code when process is done.
See also:
nfc_snep_event_cb()
nfc_manager_initialize()
int nfc_snep_send_client_request ( nfc_p2p_snep_h  handle,
nfc_snep_type_e  type,
nfc_ndef_message_h  msg,
nfc_snep_event_cb  callback,
void *  user_data 
)

Send request message to peer-to-peer client using SNEP protocol.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]handleThe handle to connected snep instance
[in]typeThe request type of snep protocol
[in]msgThe ndef message which will be sent
[in]callbackThe callback function to invoke after this function has completed
It can be null if notification is not required
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OUT_OF_MEMORYOut of memory
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_DEVICE_BUSYDevice is too busy to handle your request
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
Postcondition:
It invokes nfc_snep_event_cb() when snep event is occured.
The Callback can receive error code when process is done.
See also:
nfc_snep_event_cb()
nfc_manager_initialize()
int nfc_snep_start_client ( nfc_p2p_target_h  target,
const char *  san,
int  sap,
nfc_snep_event_cb  callback,
void *  user_data 
)

Start peer-to-peer client using SNEP protocol.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]targetThe handle to peer target
[in]sanThe name of service (service access name)
[in]sapThe number of service (service access point)
[in]callbackThe callback function to invoke after this function has completed
It can be null if notification is not required
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OUT_OF_MEMORYOut of memory
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_DEVICE_BUSYDevice is too busy to handle your request
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
Postcondition:
It invokes nfc_snep_event_cb() when snep event is occured.
The Callback can receive error code when process is done.
See also:
nfc_snep_event_cb()
nfc_snep_send_client_request()
nfc_snep_stop_service()
nfc_manager_initialize()
int nfc_snep_start_server ( nfc_p2p_target_h  target,
const char *  san,
int  sap,
nfc_snep_event_cb  callback,
void *  user_data 
)

Start peer-to-peer server using SNEP protocol.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]targetThe handle to peer target
[in]sanThe name of service (service access name)
[in]sapThe number of service (service access point)
[in]callbackThe callback function to invoke after this function has completed
It can be null if notification is not required
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OUT_OF_MEMORYOut of memory
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_DEVICE_BUSYDevice is too busy to handle your request
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
Postcondition:
It invokes nfc_snep_event_cb() when snep event is occured.
The Callback can receive error code when process is done.
See also:
nfc_snep_event_cb()
nfc_manager_initialize()
int nfc_snep_stop_service ( nfc_p2p_target_h  target,
nfc_p2p_snep_h  service 
)

Stop snep server or client.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]targetThe handle to peer target
[in]serviceThe handle which will be stopped
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
See also:
nfc_snep_event_cb()
nfc_manager_initialize()
int nfc_snep_unregister_server ( const char *  san,
int  sap 
)

Unregister snep server or client.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/nfc
Parameters:
[in]sanThe name of service (service access name)
[in]sapThe number of service (service access point)
Returns:
0 on success, otherwise a negative error value.
Return values:
NFC_ERROR_NONESuccessful
NFC_ERROR_NOT_SUPPORTEDNot supported NFC
NFC_ERROR_NOT_INITIALIZEDNot initialized NFC
NFC_ERROR_OPERATION_FAILEDOperation failed
NFC_ERROR_INVALID_PARAMETERInvalid parameter
NFC_ERROR_NOT_ACTIVATEDNFC is not activated
See also:
nfc_snep_event_cb()
nfc_manager_initialize()