From: jk.pu Date: Tue, 1 Dec 2015 10:40:22 +0000 (+0900) Subject: [Web device API] add additional tutorial for NFC HCE. X-Git-Tag: tizen_3.0/TD_SYNC/20161201~295^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c8fb3df91052b7beef7931133f86fde76eed394;p=sdk%2Fonline-doc.git [Web device API] add additional tutorial for NFC HCE. Change-Id: I463aa1d0efa962de4814ced38232446db63c598c Signed-off-by: jk.pu --- diff --git a/org.tizen.guides/html/web/tizen/communication/nfc_w.htm b/org.tizen.guides/html/web/tizen/communication/nfc_w.htm index d2873d3..4e9d877 100644 --- a/org.tizen.guides/html/web/tizen/communication/nfc_w.htm +++ b/org.tizen.guides/html/web/tizen/communication/nfc_w.htm @@ -78,7 +78,9 @@

You can launch NFC applications based on the NDEF message content using the application control functionalities. For example, if the application control with the http://tizen.org/appcontrol/operation/nfc/wellknown operation is defined in the config.xml file and an NFC-enabled device reads an NFC tag or receives an NDEF message whose first NDEF record has a record type (tnf value) set as NFC_RECORD_TNF_WELL_KNOWN, the NFC application is launched.

-

NFC applications can also be launched by the transaction of the card emulation functionality. NFC devices can communicate with point of sales (POS) terminals using the card emulation functionality to, for example, make a payment. If the application control with the http://tizen.org/appcontrol/operation/nfc/transaction operation is defined in the config.xml file and a transaction caused by the card emulation functionality occurs, the NFC application is launched.

+

NFC applications can also be launched by the transaction of the card emulation functionality. NFC devices can communicate with point of sales (POS) terminals using the card emulation functionality to, for example, make a payment. If the application control with the http://tizen.org/appcontrol/operation/nfc/transaction or http://tizen.org/appcontrol/operation/nfc/off_host_apdu_service operation is defined in the config.xml file and a secure element transaction occurs, the NFC application is launched.

+

NFC applications can also be launched by the transaction of the HCE functionality. NFC application can communicate with point of sales (POS) terminals using the HCE functionality to, for example, make a payment. If the application control with the http://tizen.org/appcontrol/operation/nfc/host_apdu_service operation is defined in the config.xml file and a HCE transaction occurs, the NFC application is launched.

+

The system sends the http://tizen.org/appcontrol/operation/nfc/card_emulation/default_changed application control event when the default wallet is changed. For example, in Setting > NFC > Set Default Wallet App, if the default wallet is changed, an application control with this operation is sent to the selected application (wallet).

The following table lists the NFC operations, scheme and mime.

- + @@ -140,6 +142,21 @@ + + + + + + + + + + + + + + +
@@ -87,7 +89,7 @@
OperationSchemeURI scheme MIME
NULL
http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_serviceNULLNULL
http://tizen.org/appcontrol/operation/nfc/card_emulation/off_host_apdu_serviceNULLNULL
http://tizen.org/appcontrol/operation/nfc/card_emulation/default_changedNULLNULL

* The <protocol_code> and <scheme> must be in sync. See NFCForum-TS-RTD_URI_1.0 and NFC RTD (Record Type Definition) documentation on the NFC forum.

@@ -181,4 +198,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga - \ No newline at end of file + diff --git a/org.tizen.tutorials/html/web/tizen/communication/nfc_tutorial_w.htm b/org.tizen.tutorials/html/web/tizen/communication/nfc_tutorial_w.htm index 8aa79fa..7cdad48 100644 --- a/org.tizen.tutorials/html/web/tizen/communication/nfc_tutorial_w.htm +++ b/org.tizen.tutorials/html/web/tizen/communication/nfc_tutorial_w.htm @@ -262,6 +262,54 @@ adapter.cardEmulationMode = "OFF";

Learning how to detect NFC HCE (host-based card emulation) events and manage AID (Application ID) is a basic NFC management skill:

    +
  1. Specify an AID value for receiving HCE transaction events:

    +
      +
    1. +

      To tell the platform which AID groups are requested by application, a metadata element must be included in the config.xml file:

      +
      +<?xml version="1.0" encoding="utf-8"?>
      +<widget xmlns:tizen="http://tizen.org/ns/wdigets" xmlns="http://www.w3.org/ns/widgets"
      +           id="http://yourdomain/basicapp"" version="1.0.0" viewmodes="maximized" >
      +   <profile name="wearable" />
      +   <tizen:application id="ZmAk4fxZWY.basicapp" package="ZmAk4fxZWY" required_version="2.3.1"/>
      +      <icon src=icon.png"/>
      +      <name>basicapp</name>
      +      <metadata key="http://tizen.org/metadata/nfc_cardemulation"
      +                value="/res/wgt/wallet.xml"/>
      +</widget>
      +
      +
      • The metadata element must contain the key and value attributes.
      • +
      • The key attribute must be http://tizen.org/metadata/nfc_cardemulation.
      • +
      • The value attribute must contain the AID XML file path. +

        The value attribute is a relative path starting from the application root path.

      • +
      +
    2. +
    3. The metadata element points to an AID XML file. The following is an example of the file with an AID declaration:

      +
      +<?xml version="1.0" encoding="utf-8"?>
      +<application name="ZmAk4fxZWY.basicapp">
      +   <wallet>
      +      <aid-group category="payment">
      +         <aid aid="325041592E5359532E4444463031"
      +              se_type="hce" unlock="false" power="sleep"/>
      +      </aid-group>
      +   </wallet>
      +</application>
      +
      +
      • The application element must contain a name attribute with an application name.
      • +
      • The application element must contain one or more wallet element, each of which must contain one or more aid-group element.
      • +
      • The aid-group element is required to contain a category attribute with the payment or other value.
      • +
      • Each aid-group element must contain one or more aid element, each of which contains a single AID. The aid-group can have as many aid elements as you want.
      • +
      • The aid element must contain the aid, se_type, unlock, and power attributes.
      • +
      • The se_type attribute must contain hce, ese, or uicc. The se_type value can be added later.
      • +
      • The unlock attribute must contain one of the following: +
        • true: The card cannot work when the device is locked.
        • +
        • false: The card can work when the device is locked.
      • +
      • The power must contain one of the following: +
        • on: The card can work when the device is on.
        • +
        • off: The card can work when the device is off.
        • +
        • sleep: The card can work when the device is in the sleep mode.
      • +
  2. Declare the required variables and obtain the NFCAdapter object (in mobile and wearable applications) using the getDefaultAdapter() method of the NFCManager interface (in mobile and wearable applications).

    To enable NFC card emulation, change the value of the cardEmulationMode attribute.

    @@ -270,8 +318,18 @@ var adapter = tizen.nfc.getDefaultAdapter();
     
     adapter.cardEmulationMode = "ALWAYS_ON";
     
  3. -
  4. Use the addHCEEventListener() method of the NFCAdapter interface to register a listener to detect the HCE event: +
  5. To detect the HCE event, use the addHCEEventListener() method of the NFCAdapter interface to register a listener.

    Use the sendHostAPDUResponse() method of the NFCAdapter interface to send a host APDU (Application Protocol Data Unit is defined in the ISO/IEC 7816-4 specification) response to a Contactless Front-end.

    +var successCB = function()
    +{
    +   console.log("Sending APDU response was successful.");
    +};
    +
    +var errorCB = function()
    +{
    +   console.log("Sending APDU response failed.");
    +};
    +
     hceListenerId = adapter.addHCEEventListener(function(event_data)
     {
        if (event_data.eventType =="ACTIVATED")
    @@ -285,31 +343,11 @@ hceListenerId = adapter.addHCEEventListener(function(event_data)
        else if (event_data.eventType =="APDU_RECEIVED")
        {
          console.log("APDU received");
    +     var apdu_response= [0x00,0xA4,0x04,0x00,0x04,0x11,0x12, 0x13, 0x14];
    +     adapter.sendHostAPDUResponse(apdu_response, successCB, errorCB);
        }
     });
     
  6. -
  7. Use the sendHostAPDUResponse() method of the NFCAdapter interface to send a host APDU (Application Protocol Data Unit is defined in the ISO/IEC 7816-4 specification) response to a Contactless Front-end: -
    -try 
    -{
    -   var successCB = function() 
    -   {
    -     console.log("Sending APDU response was successful.");
    -   };
    -
    -   var errorCB = function() 
    -   {
    -     console.log("Sending APDU response failed.");
    -   };
    -
    -   var apdu_response= [0x00,0xA4,0x04,0x00,0x04,0x11,0x12, 0x13, 0x14];
    -   adapter.sendHostAPDUResponse(apdu_response, successCB, errorCB);
    -} 
    -catch (err) 
    -{
    -   console.log(err.name + ":" + err.message);
    -}
    -
  8. To register an AID for a specific category and secure element type, use the registerAID() method of the NFCAdapter interface:
     try 
    @@ -367,15 +405,15 @@ adapter.cardEmulationMode = "OFF";
     
     
     
    -