From 7a1757fea935cf76dc18d20809e58fe298e40427 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 22 Sep 2015 14:20:16 +0900 Subject: [PATCH] Change the Smartcard Tutorial Signed-off-by: Ji-hoon Jung Change-Id: I4c5eb923c3a69235764487e8b8c8fd7252b4832f --- .../html/native/network/smartcard_tutorial_n.htm | 87 +++++++++++++++------- 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/org.tizen.tutorials/html/native/network/smartcard_tutorial_n.htm b/org.tizen.tutorials/html/native/network/smartcard_tutorial_n.htm index d046508..60c27a9 100644 --- a/org.tizen.tutorials/html/native/network/smartcard_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/network/smartcard_tutorial_n.htm @@ -63,13 +63,33 @@

To use the SE service:

  1. +

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

    +
    +#include <smartcard.h>
    +
  2. +

    The http://tizen.org/privilege/secureelement privilege is required for the Smartcard API. Add the privilege to the tizen-manifest.xml file.

    + +
    +<?xml version="1.0" encoding="utf-8"?>
    +<manifest xmlns="http://tizen.org/ns/packages" api-version="2.3.1" package="org.tizen.basicuiapplication" version="1.0.0">
    +   <profile name="wearable" />
    +   <ui-application appid="org.tizen.basicuiapplication" exec="basicuiapplication" type="capp" multiple="false" taskmanage="true" nodisplay="false">
    +      <icon>basicuiapplication.png</icon>
    +      <label>basicuiapplication</label>
    +   </ui-application>
    +   <privileges>
    +      <privilege>http://tizen.org/privilege/secureelement</privilege>
    +   </privileges>
    +</manifest>
    +
    +

    Initialize the smart card service for use:

     int ret;
     ret = smartcard_initialize();
     
     if (ret == SMARTCARD_ERROR_NONE)
    -   TC_PRT("smartcard initialize success");
    +   TC_PRT("smartcard initialize successful");
     else
        TC_PRT("smartcard initialize failed");
     
    @@ -79,7 +99,7 @@ int ret; ret = smartcard_deinitialize(); if (ret == SMARTCARD_ERROR_NONE) -   TC_PRT("smartcard deinitialize success"); +   TC_PRT("smartcard deinitialize successful"); else    TC_PRT("smartcard deinitialize failed"); @@ -94,14 +114,19 @@ ret = smartcard_get_readers(&phReaders, &pLength); if (ret == SMARTCARD_ERROR_NONE) { -   TC_PRT("smartcard_get_readers is success"); -   TC_PRT("reader handle : %d", phReaders[0]); +   TC_PRT("smartcard_get_readers successful");    TC_PRT("readers length : %d", pLength); +   if (pLength > 0) { +      TC_PRT("reader handle : %d", phReaders[0]); +   } } else {    TC_PRT("smartcard_get_readers failed : %d", ret); } + +if(phReaders != NULL) +   free(phReaders);
@@ -113,12 +138,13 @@ else

Retrieve the name of the reader with the smartcard_reader_get_name() function:

 int ret;
+int reader = phReaders[0]; //get reader using smartcard_get_readers()
 char * pReader = NULL;
 
 ret = smartcard_reader_get_name(reader, &pReader);
 if (ret == SMARTCARD_ERROR_NONE)
 {
-   TC_PRT("smartcard_reader_get_name success");
+   TC_PRT("smartcard_reader_get_name successful");
    TC_PRT("reader name : %s", pReader);
 }
 else
@@ -137,7 +163,7 @@ bool is_present = false;
 ret = smartcard_reader_is_secure_element_present(reader, &is_present);
 if (ret == SMARTCARD_ERROR_NONE)
 {
-   TC_PRT("smartcard_reader_is_secure_element_present is success");
+   TC_PRT("smartcard_reader_is_secure_element_present successful");
    TC_PRT("reader secure element present : %d", is_present);
 }
 else
@@ -160,7 +186,7 @@ if (ret == SMARTCARD_ERROR_NONE)
    ret = smartcard_reader_close_sessions(reader);
    if (ret == SMARTCARD_ERROR_NONE)
    {
-      TC_PRT("smartcard_reader_close_sessions success");
+      TC_PRT("smartcard_reader_close_sessions successful");
    }
    else
    {
@@ -189,7 +215,7 @@ ret = smartcard_session_get_reader(session, &reader);
 ret = smartcard_reader_get_name(reader, &pReader);
 if (ret == SMARTCARD_ERROR_NONE)
 {
-   TC_PRT("smartcard_session_get_reader success");
+   TC_PRT("smartcard_session_get_reader successful");
    TC_PRT("reader name : %s", pReader);
 }
 else
@@ -199,6 +225,7 @@ else
 
  • Retrieve the answer to reset (ATR) of the SE:
    +int i;
     int ret;
     unsigned char *pAtr;
     int pLength;
    @@ -207,7 +234,7 @@ ret = smartcard_session_get_atr(session, &pAtr, &pLength);
     
     if (ret == SMARTCARD_ERROR_NONE)
     {
    -   TC_PRT("smartcard_session_get_atr success : %d", pLength);
    +   TC_PRT("smartcard_session_get_atr successful : %d", pLength);
        for (i = 0; i < pLength; i++)
           TC_PRT("%x ", (int)pAtr[i]);
     }
    @@ -227,7 +254,7 @@ int channel;
     ret = smartcard_session_open_basic_channel(session, aid, 4, 0x00, &channel);
     
     if (ret == SMARTCARD_ERROR_NONE)
    -   TC_PRT("smartcard_session_open_basic_channel is success : %d", channel);
    +   TC_PRT("smartcard_session_open_basic_channel successful : %d", channel);
     else
        TC_PRT("smartcard_session_open_basic_channel failed");
     
    @@ -235,9 +262,9 @@ else
     ret = smartcard_session_open_logical_channel(session, aid, 12, 0x04, &channel);
     
     if (ret == SMARTCARD_ERROR_NONE)
    -   TC_PRT("smartcard_session_open_basic_channel is success : %d", (channel);
    +   TC_PRT("smartcard_session_open_logical_channel successful : %d", (channel);
     else
    -   TC_PRT("smartcard_session_open_basic_channel failed : %d", ret);
    +   TC_PRT("smartcard_session_open_logical_channel failed : %d", ret);
     
  • Close all channels opened for a specific session: @@ -247,7 +274,7 @@ int ret; ret = smartcard_session_close_channels(session); if (ret == SMARTCARD_ERROR_NONE) -   TC_PRT("smartcard_session_close_channels is success"); +   TC_PRT("smartcard_session_close_channels successful"); else    TC_PRT("smartcard_session_close_channels failed"); @@ -261,14 +288,14 @@ bool is_closed; ret = smartcard_session_close(session); if (ret == SMARTCARD_ERROR_NONE) -   TC_PRT("smartcard_session_close is success"); +   TC_PRT("smartcard_session_close successful"); else    TC_PRT("smartcard_session_close failed"); ret = smartcard_session_is_closed(session, &is_closed); if (ret == SMARTCARD_ERROR_NONE && is_closed == true) -   TC_PRT("smartcard_session_is_closed is success"); +   TC_PRT("smartcard_session_is_closed successful"); else    TC_PRT("smartcard_session_is_closed failed"); @@ -291,7 +318,7 @@ if (ret == SMARTCARD_ERROR_NONE)    ret = smartcard_channel_get_session(channel, &session_handle);    if (ret == SMARTCARD_ERROR_NONE) -      TC_PRT("smartcard_channel_get_session is success: %d", session_handle); +      TC_PRT("smartcard_channel_get_session successful: %d", session_handle);    else       TC_PRT("smartcard_channel_get_session failed"); } @@ -305,7 +332,7 @@ bool is_basic; ret = smartcard_channel_is_basic_channel(channel, &is_basic); if (ret == SMARTCARD_ERROR_NONE && is_basic == false) -   TC_PRT("smartcard_channel_is_basic_channel is success"); +   TC_PRT("smartcard_channel_is_basic_channel successful"); else    TC_PRT("smartcard_channel_is_basic_channel failed");
  • @@ -318,7 +345,7 @@ if (ret == SMARTCARD_ERROR_NONE)    bool is_next = true;    ret = smartcard_channel_select_next(channel, &is_next);    if (ret == SMARTCARD_ERROR_NONE && is_next == false) -      TC_PRT("smartcard_channel_select_next is success"); +      TC_PRT("smartcard_channel_select_next successful");    else       TC_PRT("smartcard_channel_select_next failed"); } @@ -333,7 +360,7 @@ ret = smartcard_channel_get_select_response(channel, &pSelectResponse, & if (ret == SMARTCARD_ERROR_NONE) { -   TC_PRT("smartcard_channel_get_select_response is success"); +   TC_PRT("smartcard_channel_get_select_response successful");    for (i = 0; i < pLength; i++)       g_print("%x ", (int)pSelectResponse[i]); } @@ -354,7 +381,7 @@ ret = smartcard_channel_close(channel); ret = smartcard_channel_is_closed(channel, &is_close); if (ret == SMARTCARD_ERROR_NONE && is_close == true) -   TC_PRT("smartcard_channel_is_closed is success"); +   TC_PRT("smartcard_channel_is_closed successful"); else    TC_PRT("smartcard_channel_is_closed failed"); @@ -367,7 +394,7 @@ int ret; ret = smartcard_channel_close(channel); if (ret == SMARTCARD_ERROR_NONE) -   TC_PRT("smartcard_channel_close is success"); +   TC_PRT("smartcard_channel_close successful"); else    TC_PRT("smartcard_channel_close failed : %d", ret); @@ -375,11 +402,17 @@ else
  • Transmit an APDU command (as per ISO/IEC 7816-4) to the SE:
    +int i;
    +int ret;
    +int resp_len;
    +unsigned char *response = NULL;
    +unsigned char command[] = {0x00, 0x01, 0x02, 0x03};
    +
     ret = smartcard_channel_transmit(channel, command, 4, &response, &resp_len);
     
     if (ret == SMARTCARD_ERROR_NONE)
     {
    -   TC_PRT("smartcard_channel_transmit is success");
    +   TC_PRT("smartcard_channel_transmit successful");
        TC_PRT("response is ");
        for (i = 0; i < resp_len; i++)
           TC_PRT("%x ", (int)response[i]);
    @@ -403,7 +436,7 @@ if (ret == SMARTCARD_ERROR_NONE)
     
        if (ret == SMARTCARD_ERROR_NONE)
        {
    -      TC_PRT("smartcard_channel_transmit_get_response is success");
    +      TC_PRT("smartcard_channel_transmit_get_response successful");
           TC_PRT("response is ");
           for (i = 0; i < pLength; i++)
              TC_PRT("%x ", (int)ptransmitResponse[i]);
    @@ -437,7 +470,7 @@ int resp_len = 50;
     
     ret = smartcard_initialize();
     if (ret == SMARTCARD_ERROR_NONE)
    -   TC_PRT("smartcard initialize success");
    +   TC_PRT("smartcard initialize successful");
     else
        TC_PRT("smartcard initialize failed");
  • @@ -468,7 +501,7 @@ if (ret == SMARTCARD_ERROR_NONE && pLength != 0)          ret = smartcard_channel_transmit(channel, command, 4, &response, &resp_len);          if (ret == SMARTCARD_ERROR_NONE)          { -            TC_PRT("smartcard_channel_transmit is success"); +            TC_PRT("smartcard_channel_transmit successful");             TC_PRT("response is ");             for (i = 0; i < resp_len; i++)                TC_PRT("%x ", (int)response[i]); @@ -492,7 +525,7 @@ if (ret == SMARTCARD_ERROR_NONE && pLength != 0) ret = smartcard_deinitialize(); if (ret == SMARTCARD_ERROR_NONE) -   TC_PRT("smartcard deinitialize success"); +   TC_PRT("smartcard deinitialize successful"); else    TC_PRT("smartcard deinitialize failed"); @@ -523,4 +556,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga - \ No newline at end of file + -- 2.7.4