From e7e234a9488a80e645a49bf1646f95c4ba2c7204 Mon Sep 17 00:00:00 2001 From: Donghyun Lee Date: Thu, 17 Sep 2015 16:46:57 +0900 Subject: [PATCH] update nfc_tutorial_n.htm --- .../html/native/network/nfc_tutorial_n.htm | 653 +++++++++++++-------- 1 file changed, 395 insertions(+), 258 deletions(-) diff --git a/org.tizen.tutorials/html/native/network/nfc_tutorial_n.htm b/org.tizen.tutorials/html/native/network/nfc_tutorial_n.htm index 8f2d3f5..d816418 100644 --- a/org.tizen.tutorials/html/native/network/nfc_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/network/nfc_tutorial_n.htm @@ -72,7 +72,6 @@

Create a card emulation application.

  • Using the NFC Application Control

    Use the NFC application control to manage events.

  • -
  • NFC P2P bump @@ -104,23 +103,29 @@
  • Check whether the device you want to work with supports NFC. This can be done by calling the nfc_manager_is_supported() function. It takes no parameters and it simply returns true if NFC is supported on the device and false otherwise.

    -
    void Network_NFC_startup(void)
    +
    +void 
    +Network_NFC_startup(void)
     {
        gmainloop = g_main_loop_new(NULL, FALSE);
        bool is_nfc_supported = nfc_manager_is_supported();
        if (!is_nfc_supported)
           dlog_print(DLOG_INFO, LOG_TAG, "is_nfc_supported NOT SUPPORTED");
    -}
    +} +

    The gmainloop, which is being created here, is used to wait for the results of calling asynchronous functions.

  • When the work with NFC is finished, the nfc_manager_deinitialize() function must be called to clear the environment.

    -
    void Network_NFC_cleanup(void)
    +
    +void 
    +Network_NFC_cleanup(void)
     {
        g_main_loop_unref (gmainloop);
        nfc_manager_deinitialize();
    -}
  • +} +

    Enabling and Disabling NFC

    @@ -133,7 +138,8 @@ #include <app_control.h> #include <dlog.h> -int nfc_onoff_operation(void) +int +nfc_onoff_operation(void) {    int ret = 0;    app_control_h service = NULL; @@ -163,230 +169,285 @@ int nfc_onoff_operation(void)    }    return 0; -} +} +

    Working with NFC

    -

    To work with NFC manually, you need to:

    - -
    1. Initialize NFC
    2. -
    3. Register for notifications
    4. -
    5. Work with NFC manually
    6. -
    7. Clean up at the end
    +

    To work with NFC manually, you need to initialize NFC, register for notifications, and work with NFC manually.

    -

    Initializing NFC

    +
      +
    1. To initialize NFC:

      -
      1. -

        The first function to be used is nfc_manager_initialize().

        -
        int error_code = NFC_ERROR_NONE;
        +
          +
        1. +

          Call the nfc_manager_initialize() function to start the initialization:

          +
          +int error_code = NFC_ERROR_NONE;
           
           error_code = nfc_manager_initialize();
           if (NFC_ERROR_NONE != error_code) // Error occurred
           
           g_timeout_add(1000, timeout_func, gmainloop);
          -g_main_loop_run(gmainloop);
          +g_main_loop_run(gmainloop); +
        -

        After calling the nfc_manager_initialize() function run gmainloop to wait for the result of the initialization. It is closed when the time set in the g_timeout_add function elapses. This time is in milliseconds so the timeout_func is called after 1 second passes.

      2. +

        Run gmainloop to wait for the result of the initialization. It is closed when the time set in the g_timeout_add() function elapses. This time is in milliseconds so the timeout_func is called after 1 second passes.

        -
      3. When the initialization is finished, call the nfc_manager_set_activation_changed_cb() function. The function registers the callback that is invoked every time the activation state of NFC changes. The parameters are:

        -
        • Activation state changed callback
        • -
        • Data passed to the callback
        -
        error_code = nfc_manager_set_activation_changed_cb(on_nfc_activation_changed, NULL);
        +
      4. When the initialization is finished, call the nfc_manager_set_activation_changed_cb() function. The function registers the callback that is invoked every time the activation state of NFC changes. The parameters are the activation state changed callback and the data passed to the callback.

        +
        +error_code = nfc_manager_set_activation_changed_cb(on_nfc_activation_changed, NULL);
        +
        -

        The code of the on_nfc_activation_changed callback is simple and looks like this:

        -
        static void on_nfc_activation_changed(bool activated, void *user_data)
        +

        In this example the on_nfc_activation_changed() callback only informs the user that the activation state has changed.

        +
        +static void 
        +on_nfc_activation_changed(bool activated, void *user_data)
         {
            if (activated)
               dlog_print(DLOG_INFO, LOG_TAG, "NFC activated");
            else
               dlog_print(DLOG_INFO, LOG_TAG, "NFC deactivated");
        -}
        -

        So in our example, this callback only informs the user that the activation state has changed.

      5. - - -
      6. After this step, the nfc_manager_set_tag_filter() function is used. It declares the tag filtering option. Use a bit operation of the type nfc_tag_filter_e to specify the type of filtering. The default value is NFC_TAG_FILTER_ALL_ENABLE, which means that all tag types are enabled.

        -
        nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
      7. +} + + -
      8. You need to register callback functions to receive discovery notifications for tag, NDEF, peer-to-peer, secure element, and secure element transaction events. To register a callback function for receiving tag discovery notifications, use the nfc_manager_set_tag_discovered_cb() function. The first argument is the on_nfc_tag_discovered() callback function described later in the tutorial. The second argument is a user data parameter. In our case, that parameter is not needed and you can pass a NULL value to the function. In the same way, register NDEF, peer-to-peer, secure element, and secure element transaction event notifications using:

        -
        • Use the nfc_manager_set_ndef_discovered_cb() function to register an NDEF event notifications with the on_nfc_ndef_discovered() callback function
        • -
        • nfc_manager_set_p2p_target_discovered_cb() to register peer-to-peer event notifications with the on_nfc_p2p_target_discovered() callback function
        • -
        • nfc_manager_set_se_event_cb() to register secure element event notifications with the on_nfc_se_event() callback function
        • -
        • nfc_manager_set_se_transaction_event_cb() to register secure element transaction event notifications with the on_nfc_se_transaction_event() callback function
        +
      9. Use the nfc_manager_set_tag_filter() function to declare the tag filtering option. Use a bit operation of the nfc_tag_filter_e type to specify the type of filtering. The default value is NFC_TAG_FILTER_ALL_ENABLE, which means that all tag types are enabled.

        +
        +nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
        +
      10. -
        error_code = nfc_manager_set_tag_discovered_cb(on_nfc_tag_discovered, NULL);
        +
      11. Register callback functions to receive discovery notifications for tag, NDEF, peer-to-peer, secure element, and secure element transaction events. To register a callback function for receiving tag discovery notifications, use the nfc_manager_set_tag_discovered_cb() function. The first argument is the on_nfc_tag_discovered() callback function described later in the tutorial. The second argument is a user data parameter. In this case, that parameter is not needed and you can pass a NULL value to the function.

        +
        +error_code = nfc_manager_set_tag_discovered_cb(on_nfc_tag_discovered, NULL);
         if (NFC_ERROR_NONE != error_code) // Error occurred
        -
        +
        +

        In the same way, register NDEF, peer-to-peer, secure element, and secure element transaction event notifications using:

        +
        • Use the nfc_manager_set_ndef_discovered_cb() function to register an NDEF event notifications with the on_nfc_ndef_discovered() callback function: +
           error_code = nfc_manager_set_ndef_discovered_cb(on_nfc_ndef_discovered, NULL);
           if (NFC_ERROR_NONE != error_code) // Error occurred
          -
          +
          +
        • +
        • Use the nfc_manager_set_p2p_target_discovered_cb() function to register peer-to-peer event notifications with the on_nfc_p2p_target_discovered() callback function: +
           error_code = nfc_manager_set_p2p_target_discovered_cb(on_nfc_p2p_target_discovered, NULL);
           if (NFC_ERROR_NONE != error_code) // Error occurred
          -
          +
        • +
        • Use the nfc_manager_set_se_event_cb() function to register secure element event notifications with the on_nfc_se_event() callback function: +
           error_code = nfc_manager_set_se_event_cb(on_nfc_se_event, NULL);
           if (NFC_ERROR_NONE != error_code) // Error occurred
          -
          +
        • +
        • Use the nfc_manager_set_se_transaction_event_cb() function to register secure element transaction event notifications with the on_nfc_se_transaction_event() callback function: +
           error_code = nfc_manager_set_se_transaction_event_cb(NFC_SE_TYPE_ESE, on_nfc_se_transaction_event, NULL);
          -if (NFC_ERROR_NONE != error_code) // Error occurred
        • - -
        • Check whether system handling for tag and target discovery is enabled or disabled. By default it is enabled. Use the nfc_manager_is_system_handler_enabled() function to check the current state. If the function returns FALSE, enable system handling using the nfc_manager_set_system_handler_enable() function and pass the TRUE value as an input parameter.

          - -
          if (nfc_manager_is_system_handler_enabled() != true)
          -   nfc_manager_set_system_handler_enable(true);
      +if (NFC_ERROR_NONE != error_code) // Error occurred +
    2. + -

      Working with NFC Manually

      +
    3. Use the nfc_manager_is_system_handler_enabled() function to check whether system handling for tag and target discovery is enabled. By default it is enabled. If the function returns FALSE, enable system handling using the nfc_manager_set_system_handler_enable() function and pass the TRUE value as an input parameter.

      +
      +if (nfc_manager_is_system_handler_enabled() != true)
      +   nfc_manager_set_system_handler_enable(true);
      +
    + +
  • To work with NFC manually

    After initializing NFC, you can start using NFC on the device. You can connect to other devices, resulting in launching the code from the registered callbacks.

    +
  • +

    Getting a Cached NFC Message

    To get a cached NFC message:

    1. Initialize NFC. -

      To initialize NFC, the nfc_manager_initialize() function can be used, as shown in Initializing NFC.

    2. -
    3. Set the NFC tag filter. -

      Setting the NFC tag filter (as shown in Working with NFC Tags). Just as a reminder, setting the tag filter is possible by using the nfc_manager_set_tag_filter() function.

      -
      nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
    4. -
    5. Enable the NFC system handler. -

      Before getting the cached message, enable the system handler:

      -
      if (nfc_manager_is_system_handler_enabled() != true)
      -   nfc_manager_set_system_handler_enable(true);
    6. -
    7. Get the cached message. -

      Get the cached message by calling the nfc_manager_get_cached_message() function. Pass a variable of the nfc_ndef_message_h type, which is fulfilled with the cached message by the function.

      -
      nfc_ndef_message_h message = NULL;
      +

      To initialize NFC, the nfc_manager_initialize() function can be used, as shown in Initializing NFC.

    8. +
    9. Set the NFC tag filter with the nfc_manager_set_tag_filter() function: +
      +nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
      +
    10. +
    11. Enable the NFC system handler: +
      +if (nfc_manager_is_system_handler_enabled() != true)
      +   nfc_manager_set_system_handler_enable(true);
      +
    12. +
    13. Get the cached message by calling the nfc_manager_get_cached_message() function. Pass a variable of the nfc_ndef_message_h type, which is fulfilled with the cached message by the function. +
      +nfc_ndef_message_h message = NULL;
       
       error_code = nfc_manager_get_cached_message(&message);
      -if (NFC_ERROR_NONE != error_code) // Error occurred
      -

      After getting the message, get the detailed information from the message as it was described before. To do this, check whether there were any errors and whether the message is not NULL.

      -
      if (message != NULL)
      +if (NFC_ERROR_NONE != error_code) // Error occurred
      +
      +

      After getting the message, get the detailed information from the message as it was described earlier. To do this, check whether there were any errors and whether the message is not NULL.

      +
      +if (message != NULL)
       {
          on_nfc_ndef_discovered(clone_message(message), NULL);
      -}
    14. -
    15. Clean up at the application end.
    +} + +
  • Clean up at the application end.
  • +

    Using the Card Emulation Feature

    @@ -532,7 +624,8 @@ if (NFC_ERROR_NONE != error_code) // Error occurred
    1. To initialize NFC, use the nfc_manager_initialize() function:

      -
      int ret = NFC_ERROR_NONE;
      +
      +int ret = NFC_ERROR_NONE;
       
       ret = nfc_manager_initialize();
       
      @@ -546,7 +639,8 @@ if (ret != NFC_ERROR_NONE)
       
    2. Use the app control to enable NFC.
    3. Make sure that card emulation is enabled. If not, enable it. -
      nfc_se_card_emulation_mode_type_e ce_type;
      +
      +nfc_se_card_emulation_mode_type_e ce_type;
       
       ret = nfc_se_get_card_emulation_mode(&ce_type);
       
      @@ -568,7 +662,7 @@ else
       }
       
    4. Specify an AID value for the application:

      -
        +
        1. To tell the platform which AID groups are requested by application, a metadata element must be included in the manifest file:

          @@ -624,8 +718,10 @@ else
           

          The application must be able to handle an HCE event from the NFC reader. Define and register a callback that is triggered when data arrives from the NFC reader.

          Use the nfc_hce_send_apdu_response() function to send a response to the NFC reader. The actual data moving between the NFC reader and the application can be anything. The APDU protocol only defines as a promise between the application producer and NFC reader.

          -
          static void _hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
          -                          unsigned char *apdu, unsigned int apdu_len, void *user_data)
          +
          +static void 
          +_hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
          +              unsigned char *apdu, unsigned int apdu_len, void *user_data)
           {
              switch (event)
              {
          @@ -694,7 +790,8 @@ else
              dlog_print(DLOG_ERROR, LOG_TAG, "nfc_se_is_activated_handler_for_aid is failed : %d", ret);
           }
           
          -ret = nfc_se_is_activated_handler_for_category(NFC_SE_TYPE_HCE, NFC_CARD_EMULATION_CATEGORY_PAYMENT,
          +ret = nfc_se_is_activated_handler_for_category(NFC_SE_TYPE_HCE, 
          +                                               NFC_CARD_EMULATION_CATEGORY_PAYMENT,
                                                          &is_activated_handler);
           
           if (ret != NFC_ERROR_NONE)
          @@ -738,7 +835,9 @@ if (ret != NFC_ERROR_NONE)
           }
           
        2. To check whether the application has a registered AID (including a registered AID at the install time), use the nfc_se_foreach_registered_aids() function (the callback is called for each AID value separately): -
          static void _registered_aid_cb(nfc_se_type_e se_type, const char *aid, bool read_only, void *user_data)
          +
          +static void 
          +_registered_aid_cb(nfc_se_type_e se_type, const char *aid, bool read_only, void *user_data)
           {
              dlog_print(DLOG_INFO, LOG_TAG, "registered_aids callback is called");
              // Do something
          @@ -748,7 +847,7 @@ ret = nfc_se_foreach_registered_aids(NFC_SE_TYPE_HCE, NFC_CARD_EMULATION_CATEGOR
           
           if (ret != NFC_ERROR_NONE)
           {
          -    dlog_print(DLOG_ERROR, LOG_TAG, "nfc_se_foreach_registered_aids failed : %d", ret);
          +   dlog_print(DLOG_ERROR, LOG_TAG, "nfc_se_foreach_registered_aids failed : %d", ret);
             
              return false;
           }
          @@ -756,7 +855,8 @@ if (ret != NFC_ERROR_NONE)
           

          When an application receives an app control event, the application can receive the AID value using the data app control extra key.

        3. When HCE operations are no longer needed, deinitialize the resources: -
          int ret = NFC_ERROR_NONE;
          +
          +int ret = NFC_ERROR_NONE;
           
           nfc_manager_unset_hce_event_cb();
           
          @@ -779,8 +879,9 @@ if (ret != NFC_ERROR_NONE)
           #include <nfc.h>
           #include <dlog.h>
           
          -static void _hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
          -                          unsigned char *apdu, unsigned int apdu_len, void *user_data)
          +static void 
          +_hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
          +              unsigned char *apdu, unsigned int apdu_len, void *user_data)
           {
              switch (event)
              {
          @@ -812,7 +913,8 @@ static void _hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
              }
           }
           
          -bool service_app_create(void *data)
          +bool 
          +service_app_create(void *data)
           {
              int ret = NFC_ERROR_NONE;
              nfc_se_card_emulation_mode_type_e ce_type;
          @@ -859,7 +961,8 @@ bool service_app_create(void *data)
              return true;
           }
           
          -void service_app_terminate(void *data)
          +void 
          +service_app_terminate(void *data)
           {
              int ret = NFC_ERROR_NONE;
           
          @@ -874,14 +977,16 @@ void service_app_terminate(void *data)
              return;
           }
           
          -void service_app_control(app_control_h app_control, void *data)
          +void 
          +service_app_control(app_control_h app_control, void *data)
           {
              // Todo: add your code here
           	
              return;
           }
           
          -void service_app_low_memory_callback(void *data)
          +void 
          +service_app_low_memory_callback(void *data)
           {
              // Todo: add your code here
              service_app_exit();
          @@ -889,7 +994,8 @@ void service_app_low_memory_callback(void *data)
              return;
           }
           
          -void service_app_low_battery_callback(void *data)
          +void 
          +service_app_low_battery_callback(void *data)
           {
              // Todo: add your code here
              service_app_exit();
          @@ -897,7 +1003,8 @@ void service_app_low_battery_callback(void *data)
              return;
           }
           
          -int main(int argc, char* argv[])
          +int 
          +main(int argc, char* argv[])
           {
              char ad[50] = {0,};
              service_app_event_callback_s event_callback;
          @@ -957,7 +1064,7 @@ int main(int argc, char* argv[])
           

          The following example shows the NFC application control code:

          -#define NFC_APPCONTROL_STRING "http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service"
          +#define NFC_APPCONTROL_STRING "http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service"
           
           bool 
           service_app_control(app_control_h service, void *data)
          @@ -995,35 +1102,44 @@ main(int argc, char* argv[])
           
           

          To initialize NFC P2P:

            -
          1. Make sure you have 2 target devices that support the NFC P2P mode. Note that the device screen should be unlocked to use NFC.

          2. +
          3. Make sure you have 2 target devices that support the NFC P2P mode. Note that the device screen must be unlocked to use NFC.

          4. To use the functions and data types of the NFC API (in mobile and wearable applications), include the <nfc.h> header file in your application:

             #include <nfc.h>
             
          5. To start using the NFC API, initialize the API by calling the nfc_manager_initialize() function: -
            nfc_manager_initialize();
          6. +
            +nfc_manager_initialize();
            +
          7. After the initialization of the API manager, ensure that NFC is supported and activated on the device. The nfc_manager_is_supported() function checks whether NFC is supported. The nfc_manager_is_activated() function gets the NFC activation state.

            -
            if (!nfc_manager_is_supported()) 
            +
            +if (!nfc_manager_is_supported()) 
             {
                // Report error, end the application
             }
             if (!nfc_manager_is_activated()) 
             {
                // Report error, switch on NFC
            -}
          8. +} +
        4. At the end of the application life-cycle, call the nfc_manager_deinitialize() function. It releases all resources of the NFC manager and disconnects the session between it and your application.

          -
          nfc_manager_deinitialize();
        +
        +nfc_manager_deinitialize();
        +

      Sending and Receiving a Message through NFC P2P

      To send and receive messages using the NFC P2P mode (a simple NDEF message containing a business card (name, phone number, and e-mail address) of the device owner is prepared and exchanged with the second device):

      1. Prepare the NDEF message. -

        An NDEF message consists of several NDEF records. A record payload type is determined by two values: the TNF (Type Name Format) and type. There are a few TNFs and related types of the NDEF records, like text record, URI record, and MIME record. In this tutorial, only text records are used.

        -

        The sample message in this tutorial contains a name, phone number, and e-mail address of the device owner. Values can be stored in a file or taken from the UI of the application – in this tutorial getting values has been omitted.

        -

        To create a text record, use the nfc_ndef_record_create_text() function. Its arguments are a record handle, the text to store, the language code (for example en-US or ko-KR), and the encoding type. The following example creates 3 records for a name, phone number, and e-mail address:

        -
        nfc_ndef_record_h ndef_name_record = NULL;
        +
          +
        1. +

          An NDEF message consists of several NDEF records. A record payload type is determined by two values: the TNF (Type Name Format) and type. There are a few TNFs and related types of the NDEF records, such as text record, URI record, and MIME record. In this example, only text records are used.

          +

          The sample message in this example contains a name, phone number, and e-mail address of the device owner. Values can be stored in a file or taken from the UI of the application - in this example getting values has been omitted.

          +

          To create a text record, use the nfc_ndef_record_create_text() function. The parameters are a record handle, the text to store, the language code (for example en-US or ko-KR), and the encoding type. The following example creates 3 records for a name, phone number, and e-mail address.

          +
          +nfc_ndef_record_h ndef_name_record = NULL;
           nfc_ndef_record_h ndef_phone_record = NULL;
           nfc_ndef_record_h ndef_email_record = NULL;
           
          @@ -1033,35 +1149,55 @@ const char *email = "john.doe@tizen.org";
           
           nfc_ndef_record_create_text(&ndef_name_record, name, "en-US", NFC_ENCODE_UTF_8);
           nfc_ndef_record_create_text(&ndef_phone_record, phone, "en-US", NFC_ENCODE_UTF_8);
          -nfc_ndef_record_create_text(&ndef_email_record, email, "en-US", NFC_ENCODE_UTF_8);
          -

          When the records are created, they should be appended to a message. Before that, create and initialize an NDEF message using the nfc_ndef_message_create() function. As an argument, pass a handle to the created message.

          -
          nfc_ndef_message_h ndef_message = NULL;
          -nfc_ndef_message_create(&ndef_message);
          +nfc_ndef_record_create_text(&ndef_email_record, email, "en-US", NFC_ENCODE_UTF_8); +
        +
      2. +
      3. +

        When the records are created, they must be appended to a message. Before that, create and initialize an NDEF message using the nfc_ndef_message_create() function. Pass a handle to the created message as the parameter.

        +
        +nfc_ndef_message_h ndef_message = NULL;
        +nfc_ndef_message_create(&ndef_message);
        +
        +
      4. +
      5. Append the created records to the message using the nfc_ndef_message_append_record() function. This function appends the record with the next index. To insert a record at the specified index, use the nfc_ndef_message_insert_record() function instead.

        -
        nfc_ndef_message_append_record(ndef_message, ndef_name_record);
        +
        +nfc_ndef_message_append_record(ndef_message, ndef_name_record);
         nfc_ndef_message_append_record(ndef_message, ndef_phone_record);
        -nfc_ndef_message_append_record(ndef_message, ndef_email_record);
      6. +nfc_ndef_message_append_record(ndef_message, ndef_email_record); + +
      +
    5. Notify the application about the discovered P2P target. -

      To exchange messages using P2P, firstly register a callback for receiving notifications about discovered P2P targets using the nfc_manager_set_p2p_target_discovered_cb() function. When the P2P target is discovered, the callback provides a handle to that device and information on whether it is attached or detached.

      -
      nfc_manager_set_p2p_target_discovered_cb(on_target_discovered, NULL);
    6. +

      To exchange messages using P2P, first register a callback for receiving notifications about discovered P2P targets using the nfc_manager_set_p2p_target_discovered_cb() function. When the P2P target is discovered, the callback provides a handle to that device and information on whether it is attached or detached.

      +
      +nfc_manager_set_p2p_target_discovered_cb(on_target_discovered, NULL);
      +
    7. Notify the application about the received data. -

      In this tutorial, both devices receive and send a message to each other, so when another P2P target is attached, register a callback for receiving notifications about received data from this device. Use the nfc_p2p_set_data_received_cb() function (the best way is to place this code in the callback called after the P2P device is discovered). Specify the peer target handle – it was provided by the previously set callback.

      -
      nfc_p2p_set_data_received_cb(target, on_p2p_data_received, NULL);
      +

      In this example, both devices receive and send a message to each other, so when another P2P target is attached, register a callback for receiving notifications about received data from this device. Use the nfc_p2p_set_data_received_cb() function (the best way is to place this code in the callback called after the P2P device is discovered). Specify the peer target handle that was provided by the previously set callback.

      +
      +nfc_p2p_set_data_received_cb(target, on_p2p_data_received, NULL);
      +
    8. Send a message to another device.

      When another P2P device is attached, send the prepared message to it. You can use the nfc_p2p_send() function if you do not want to check permissions. Provide a target handle and a sent message handle. You can also set a callback called when the sending is completed.

      -
      nfc_p2p_send(target, ndef_message, NULL, NULL);
    9. +
      +nfc_p2p_send(target, ndef_message, NULL, NULL);
      +
    10. Receive a message from another device.

      When the callback about receive data is called, the device receives a message from another device. The callback provides a handle to the received message and a handle to the message source.

      -

      Get the number of records in the received message using the nfc_ndef_message_get_record_count() function. In this example, the number should be 3, since there are 3 records a name, phone number, and e-mail address.

      -
      int count;
      -nfc_ndef_message_get_record_count(message, &count);
      +

      Get the number of records in the received message using the nfc_ndef_message_get_record_count() function. In this example, the number must be 3, since there are 3 records a name, phone number, and e-mail address.

      +
      +int count;
      +nfc_ndef_message_get_record_count(message, &count);
      +

      To get a specified record from the message, use the nfc_ndef_message_get_record() function. Specify a message handle, a record index, and a handle to store the obtained record. When the text record is obtained, get the stored text using the nfc_ndef_record_get_text() function. In the tutorial, there are 3 text records to obtain.

      -
      nfc_ndef_record_h ndef_record;
      +
      +nfc_ndef_record_h ndef_record;
       
       char *name = NULL;
       nfc_ndef_message_get_record(message, 0, &ndef_record);
      @@ -1073,10 +1209,11 @@ nfc_ndef_record_get_text(ndef_record, &phone);
       
       char *email = NULL;
       nfc_ndef_message_get_record(message, 2, &ndef_record);
      -nfc_ndef_record_get_text(ndef_record, &email);
      -

      Then you can use obtained values to create, for example, a new contact.

      +nfc_ndef_record_get_text(ndef_record, &email); +
      +

      You can use the obtained values to create, for example, a new contact.

      -

      Note that depending on the record type, some obtained values should be freed and others should not. For example, you should free the obtained text from a text record. See the documentation to know how to get the payload of other types of records.

    +

    Note that depending on the record type, some obtained values must be freed and others must not. For example, you must free the obtained text from a text record. See the documentation to know how to get the payload of other types of records.

    @@ -1101,4 +1238,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga - + \ No newline at end of file -- 2.7.4