Documentation changed
authorJihoon Jung <jh8801.jung@samsung.com>
Mon, 31 Aug 2015 10:51:09 +0000 (19:51 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Mon, 31 Aug 2015 10:51:28 +0000 (19:51 +0900)
- Chapter changed : HCE -> Card emulation
- Chapter added : NFC Application control
- content added
Signed-off-by: Ji-hoon Jung <jh8801.jung@samsung.com>
Change-Id: If599604e2b14a1da4af1be181974a6b00f4b2e7e

org.tizen.guides/html/native/network/nfc_n.htm
org.tizen.tutorials/html/native/network/nfc_tutorial_n.htm

index 77c0b17..041ea86 100644 (file)
        </li>\r
 </ul>\r
 \r
-<p>NFC applications can be launched by a card emulation transaction using the application control functionalities. NFC devices can communicate with the point of sales (POS) terminals using the card emulation functionality to, for example, make a payment.</p> \r
-<p>If an application control with a following operation is defined in the configuration file and an event caused by the card emulation functionality occurs, the NFC application is launched:</p>\r
-<ul>\r
-<li><span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/transaction</span>\r
-<p>A transaction caused by the card emulation functionality occurs.</p>\r
-</li>\r
-<li><span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/default_changed</span>\r
-<p>The user selects a default wallet in Tap&amp;Pay.</p>\r
-</li>\r
-<li><span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service</span>\r
-<p>A host APDU service (HCE) APDU event occurs.</p>\r
-</li>\r
-<li><span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/off_host_apdu_service</span>\r
-<p>An off-host APDU service (eSE, UICC) APDU event occurs.</p>\r
-</li>\r
-</ul>\r
-\r
-\r
 <script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>\r
 <script type="text/javascript" src="../../scripts/showhide.js"></script>\r
 </div></div></div>\r
index 034c18c..e9a939d 100644 (file)
@@ -29,7 +29,8 @@
                                        <li><a href="#enable">Enabling and Disabling NFC</a></li>
                                        <li><a href="#work">Working with NFC</a></li>
                                        <li><a href="#get">Getting a Cached NFC Message</a></li>
-                                       <li><a href="#hce">Using the HCE Feature</a></li>
+                                       <li><a href="#cardemulation">Using the Card_Emulation Feature</a></li>
+                                       <li><a href="#appcontrol">NFC Application Control</a></li>
                                </ul>
                        </li>
                        <li>NFC P2P bump
                                <p>Initialize NFC asynchronously, set the NFC tag filter, and register all necessary NFC callbacks.</p></li>
                                <li><a href="#get">Getting a Cached NFC Message</a>
                                <p>Initialize NFC synchronously and get a cached NFC message.</p></li>
-                               <li><a href="#hce">Using the HCE Feature</a>
-                               <p>Create a host-based card emulation (HCE) application.</p></li>
+                               <li><a href="#cardemulation">Using the Card_Emulation Feature</a>
+                               <p>Create a Card Emulation application.</p></li>
+                               <li><a href="#appcontrol">NFC Application Control</a>
+                               <p>Using NFC Application Control.</p></li>
                        </ul>   
                </li>
                <li>NFC P2P bump
@@ -93,8 +96,8 @@
 <p>In the NFC tutorial, the NFC API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__NETWORK__NFC__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__NETWORK__NFC__MODULE.html">wearable</a> applications) is used to write an application which initializes the NFC adapter and registers callbacks called in case of each connection scenario, so the user is able to work with NFC manually. By connecting your device to the other NFC point (tag, device, or sales terminal), you can invoke the specified callback registered earlier. The second scenario of this tutorial shows how to get the message cached by NFC.</p>
 
 <p>To initialize NFC:</p>
-<ol><li>
-<p>To use the functions and data types of the NFC API, include the <span style="font-family: Courier New,Courier,monospace">&lt;nfc.h&gt;</span> header file in your application:</p>
+<ol>
+<li><p>To use the functions and data types of the NFC API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__NETWORK__NFC__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__NETWORK__NFC__MODULE.html">wearable</a> applications), include the <span style="font-family: Courier New,Courier,monospace">&lt;nfc.h&gt;</span> header file in your application:</p>
 <pre class="prettyprint">
 #include &lt;nfc.h&gt;
 </pre></li>
@@ -281,8 +284,7 @@ if (NFC_ERROR_NONE != error_code) // Error occurred</pre>
 
 <pre class="prettyprint">static void on_nfc_tag_read_completed(int error_code, nfc_ndef_message_h message, void *user_data)
 {
-&nbsp;&nbsp;&nbsp;if (!found_error(NFC_ERROR_NONE, &quot;nfc_manager_set_activation&quot;, error_code))
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nfc_ndef_message_read_cb(clone_message(message));
+&nbsp;&nbsp;&nbsp;nfc_ndef_message_read_cb(clone_message(message));
 }</pre>
 <p>If there was no error (<span style="font-family: Courier New,Courier,monospace;">error_code == NFC_ERROR_NONE</span>), you can operate on the retrieved message. To present how to use other NFC API functionality, 2 additional functions have been presented. Firstly, clone the message by calling the <span style="font-family: Courier New,Courier,monospace;">clone_message()</span> function: </p>
 <pre class="prettyprint">static nfc_ndef_message_h clone_message(nfc_ndef_message_h msg)
@@ -521,11 +523,11 @@ if (NFC_ERROR_NONE != error_code) // Error occurred</pre>
 }</pre></li>
 <li>Clean up at the application end.</li></ol>
 
- <h2 id="hce" name="hce">Using the HCE Feature</h2>
+ <h2 id="cardemulation" name="cardemulation">Using the Card Emulation Feature</h2>
 
-<p>To create a host-based card emulation (HCE) application:</p>
+<p>To create a Card Emulation application:</p>
 
-<ol><li>Initialize the HCE application:
+<ol><li>Initialize the Card Emulation application:
 <ol type="a">
 <li>
 <p>To initialize NFC, use the <span style="font-family: Courier New,Courier,monospace;">nfc_manager_initialize()</span> function: </p>
@@ -564,9 +566,55 @@ else
 &nbsp;&nbsp;&nbsp;return false;
 }
 </pre></li>
-<li>Specify a &quot;AID&quot; value for the application in the <span style="font-family: Courier New,Courier,monospace;">tizen-manifest.xml</span> file.</li>
+<li><p>Specify a &quot;AID&quot; value for the application. Next two step is required.</p>
+<br/>
+<p>1. To tell the platform which AIDs groups are requested by application, a metadata must be included in the manifest file.</p>
+<pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+&lt;manifest xmlns=&quot;http://tizen.org/ns/packages&quot; api-version=&quot;2.3.1&quot; package=&quot;org.tizen.basicuiapplication&quot; version=&quot;1.0.0&quot;&gt;
+&nbsp;&nbsp;&nbsp;&lt;profile name="wearable" /&gt;
+&nbsp;&nbsp;&nbsp;&lt;ui-application appid="org.tizen.basicuiapplication" exec="basicuiapplication" type="capp" multiple="false" taskmanage="true" nodisplay="false"&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;icon&gt;basicuiapplication.png&lt;/icon&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;basicuiapplication&lt;/label&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;metadata key="http://tizen.org/metadata/nfc_cardemulation" value="/shared/res/wallet.xml"/&gt;
+&nbsp;&nbsp;&nbsp;&lt;/ui-application&gt;
+&lt;/manifest&gt;
+</pre>
+<ul><li>The &lt;metadata&gt; is required to contain a &lt;key&gt; and &lt;value&gt; attribute. </li>
+<li> &lt;key&gt; attribute must be "http://tizen.org/metadata/nfc_cardemulation".</li>
+<li> &lt;value&gt; attribute contain the AID xml file path.</li>
+<p>&lt;value&gt; attribute is a relative path starting from the app root path.</p>
+</ul>
+<br/>
+<p>2. meta-data tag points to an AID xml file. An example of this file with AID declaration is shown below :</p>
+<pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+   &lt;application name = &quot;org.tizen.basicuiapplication&quot;&gt;
+      &lt;wallet&gt;
+        &lt;aid-group category = &quot;payment&quot;&gt;
+                &lt;aid aid = &quot;325041592E5359532E4444463031&quot; se_type = &quot;hce&quot; unlock = &quot;false&quot; power = &quot;sleep&quot;/&gt;
+        &lt;/aid-group&gt;
+      &lt;/wallet&gt;
+   &lt;/application&gt;
+</pre>
+<ul><li>The &lt;application&gt; is required to contain a &lt;name&gt; attribute that contains a application name.</li>
+<li>The &lt;application&gt; must contain one or more &lt;wallet&gt; tags.</li>
+<li>Each &lt;wallet&gt; must contain one or more &lt;aid-group&gt; tags. </li>
+<li>The &lt;aid-group&gt; is required to contain a &lt;category&gt; attribute that contains &lt;payment&gt; or &lt;other&gt;.</li>
+<li>Each &lt;aid-group&gt; must contain one or more &lt;aid&gt; tags, each of which contains a single AID.</li>
+<li>The&lt;aid-group&gt; can have as much as you want aid</li>
+<li>The &lt;aid&gt; is required to contain a &lt;aid&gt;, &lt;se_type&gt;, &lt;unlock&gt;, &lt;power&gt; attribute.</li>
+<li>The &lt;se_type&gt; must contains &quot;hce&quot; or &quot;ese&quot; or &quot;uicc&quot;. se_type value can be added later.</li>
+<li>The &lt;unlock&gt; must contains &quot;true&quot; or &quot;false&quot;.</li>
+<ul><li>&quot;true&quot; mean &quot;Card can't work, when device is locked.&quot;</li>
+<li>&quot;false&quot; mean &quot;Card can work, when device is locked.&quot;</li></ul>
+<li>The &lt;power&gt; must contains &quot;on&quot; or &quot;off&quot; or &quot;sleep&quot;.</li>
+<ul><li>&quot;on&quot; mean &quot;Card can work, when device is on.&quot;</li>
+<li>&quot;off&quot; mean &quot;Card can work, when device is off.&quot;</li>
+<li>&quot;sleep&quot; mean &quot;Card can work, when device is sleep.&quot;</li></ul>
+</li>
 <li>The <span style="font-family: Courier New,Courier,monospace;">http://tizen.org/privilege/nfc.cardemulation</span> privilege is required for the HCE API. Add the privilege to the <span style="font-family: Courier New,Courier,monospace;">tizen-manifest.xml</span> file.</li></ol></li>
 
+<li>To create a Host based Card Emulation (HCE) application :
+<ol type="a">
 <li>Define HCE event handling.
 <p>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.</p>
 <p>Use the <span style="font-family: Courier New,Courier,monospace;">nfc_hce_send_apdu_response()</span> 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.</p>
@@ -699,7 +747,7 @@ if (ret != NFC_ERROR_NONE)
   
 &nbsp;&nbsp;&nbsp;return false;
 }
-</pre></li>
+<p>When an application receives an app-control event, application can receive the aid value using the &quot;data&quot; appcontrol extra key.</p></li>
 </ul></li>
 <li>When HCE operations are no longer needed, deinitialize the resources:
 <pre class="prettyprint">int ret = NFC_ERROR_NONE;
@@ -713,7 +761,7 @@ if (ret != NFC_ERROR_NONE)
 }
 </pre></li></ol>
 
-<p>The following example shows the entire sample code:</p>
+<p>The following example shows the entire HCE application sample code:</p>
 
 <pre class="prettyprint">
 #include &lt;service_app.h&gt;
@@ -851,8 +899,117 @@ int main(int argc, char* argv[])
 
 &nbsp;&nbsp;&nbsp;return service_app_main(argc, argv, &amp;event_callback, ad);
 }
+</pre></ol>
+
+<h2 id="appcontrol" name="appcontrol">NFC Application Control</h2>
+  <p>NFC application controls are kinds of event sent by the system to applications when NFC-based payment transaction occurs.</p>
+  <p>To receive these events, you are required to define the application control information in the <strong>Application Control</strong> tab of the manifest editor.</p>
+
+  <p> The platform supports the following application controls for NFC applications: </p>
+  <p> <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/default_changed</span> and <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service</span> and <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/off_host_apdu_service</span> operations.</p>
+
+<h3>default_changed operation</h3>
+  <p>The application control with <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/default_changed</span> is sent by the system when the default wallet is changed.</p><p>For example, in <strong>Setting &gt; NFC &gt; Set Default Wallet App</strong>, if the default wallet is changed, an application control with this operation will be sent to the selected application (wallet).</p>
+
+  <p>You have to define the <span style="font-family: Courier New,Courier,monospace">app_control_cb()</span> callback and register it to <span style="font-family: Courier New,Courier,monospace">ui_app_lifecycle_callback::app_control</span>.</p>
+  <br/>
+
+<h3>host_apdu_service operation</h3>
+  <p>The application control with <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service</span> operation is sent by the system when HCE event occurs.</p> <p>For example, when a mobile device receives Host based apdu (HCE) event from POS terminal, an application control with this operation will be sent to NFC applications. </p>
+<p>You can get the target AID information using app_control_get_extra_data() with "data" key. </p>
+
+  <p>You have to define the <span style="font-family: Courier New,Courier,monospace">app_control_cb()</span> callback and register it to <span style="font-family: Courier New,Courier,monospace">ui_app_lifecycle_callback::app_control</span>.</p>
+
+  <p>The following table shows the information comes packaged when the <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service</span> operation is launching.</p>
+  <table border="1">
+   <caption>
+     Table: host_apdu_service extra key
+   </caption>
+
+    <tbody>
+    <tr>
+     <th style="text-align:center;margin-left:auto;margin-right:auto;">Extra key</th>
+     <th style="text-align:center;margin-left:auto;margin-right:auto;">Description</th>
+    </tr>
+    <tr>
+     <td><span style="font-family: Courier New,Courier,monospace">data</span></td>
+     <td>Target AID key</td>
+    </tr>
+   </tbody>
+  </table>
+<br/>
+<h3>off_host_apdu_service operation</h3>
+  <p>The application control with <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/off_host_apdu_service</span> operation is sent by the system when SE transaction occurs.</p><p>For example, when a mobile device receives Off-Host apdu event from POS terminal, an application control with this operation will be sent to NFC applications.</p>
+<p>You can get the target AID information using app_control_get_extra_data() with "data" key.</p>
+
+  <p>You have to define the <span style="font-family: Courier New,Courier,monospace">app_control_cb()</span> callback and register it to <span style="font-family: Courier New,Courier,monospace">ui_app_lifecycle_callback::app_control</span>.</p>
+
+  <p>The following table shows the information comes packaged when the <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/nfc/card_emulation/off_host_apdu_service</span> operation is launching.</p>
+  <table border="1">
+   <caption>
+     Table: off_host_apdu_service extra key
+   </caption>
+
+    <tbody>
+    <tr>
+     <th style="text-align:center;margin-left:auto;margin-right:auto;">Extra key</th>
+     <th style="text-align:center;margin-left:auto;margin-right:auto;">Description</th>
+    </tr>
+    <tr>
+     <td><span style="font-family: Courier New,Courier,monospace">data</span></td>
+     <td>Target AID key</td>
+    </tr>
+   </tbody>
+  </table>
+ <br/>
+<h3>Application control example</h3>
+<p>To tell the platform which application is register the opeartion, a operation must be included in the manifest file.</p>
+<pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+&lt;manifest xmlns=&quot;http://tizen.org/ns/packages&quot; api-version=&quot;2.3.1&quot; package=&quot;org.tizen.basicuiapplication&quot; version=&quot;1.0.0&quot;&gt;
+&nbsp;&nbsp;&nbsp;&lt;profile name="wearable" /&gt;
+&nbsp;&nbsp;&nbsp;&lt;ui-application appid="org.tizen.basicuiapplication" exec="basicuiapplication" type="capp" multiple="false" taskmanage="true" nodisplay="false"&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;icon&gt;basicuiapplication.png&lt;/icon&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;basicuiapplication&lt;/label&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;app-control&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;operation name=&quot;http://tizen.org/appcontrol/operation/nfc/card_emulation/default_changed&quot;/&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;operation name=&quot;http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service&quot;/&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;operation name=&quot;http://tizen.org/appcontrol/operation/nfc/card_emulation/off_host_apdu_service&quot;/&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/app-control&gt;
+&nbsp;&nbsp;&nbsp;&lt;/ui-application&gt;
+&lt;/manifest&gt;
 </pre>
+<p>The code of the NFC application control is presented below: </p>
+<pre class="prettyprint">
+...
+bool service_app_control(app_control_h service, void *data)
+{
+&nbsp;&nbsp;&nbsp;struct _appdata *ad = user_data;
+&nbsp;&nbsp;&nbsp;char *operation, *aid;
+&nbsp;&nbsp;&nbsp;int ret = 0;
+
+&nbsp;&nbsp;&nbsp;app_control_get_operation(service, &amp;operation);
+&nbsp;&nbsp;&nbsp;if ((strncmp(operation, NFC_APPCONTROL_STRING, strlen(NFC_APPCONTROL_STRING)) == 0)) {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dlog_print(DLOG_INFO, "HCETESTAPP", "nfc appcontrol operation : [%s]", operation);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;app_control_get_extra_data(service, "data", &amp;aid);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dlog_print(DLOG_INFO, "HCETESTAPP", "nfc appcontrol uri : [%s]", aid);
+&nbsp;&nbsp;&nbsp;}
+}
+...
 
+int main(int argc, char* argv[])
+{
+&nbsp;&nbsp;&nbsp;char ad[50] = {0,};
+&nbsp;&nbsp;&nbsp;service_app_event_callback_s event_callback;
+
+&nbsp;&nbsp;&nbsp;event_callback.create = service_app_create;
+&nbsp;&nbsp;&nbsp;event_callback.terminate = service_app_terminate;
+&nbsp;&nbsp;&nbsp;event_callback.app_control = service_app_control;
+&nbsp;&nbsp;&nbsp;event_callback.low_memory = service_app_low_memory_callback;
+&nbsp;&nbsp;&nbsp;event_callback.low_battery = service_app_low_battery_callback;
+
+&nbsp;&nbsp;&nbsp;return service_app_main(argc, argv, &amp;event_callback, ad);
+}
+</pre>
 
  <h2 id="init_p2p" name="init_p2p">Initializing NFC P2P</h2>
 
@@ -952,16 +1109,16 @@ nfc_ndef_record_get_text(ndef_record, &amp;email);</pre>
 <p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
 </div>
 
-  <script type="text/javascript">\r
-var _gaq = _gaq || [];\r
-_gaq.push(['_setAccount', 'UA-25976949-1']);\r
-_gaq.push(['_trackPageview']);\r
-(function() {\r
-var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r
-ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r
-var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r
-})();\r
+  <script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
 </script>
 
  </body>
-</html>
+</html>
\ No newline at end of file