Add new feature and 2 enum values for USB secure element 70/260470/2 accepted/tizen/unified/20210727.124505 submit/tizen/20210726.012902 submit/tizen/20210726.073043
authorJihoon Jung <jh8801.jung@samsung.com>
Fri, 25 Jun 2021 07:44:45 +0000 (16:44 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Mon, 28 Jun 2021 01:27:24 +0000 (10:27 +0900)
Change-Id: I66bdcf6b977be5ed74bda2b4b711037cce5d4687
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
13 files changed:
doc/mobile/smartcard_doc.h
doc/wearable/smartcard_doc.h
include/SEService.h
include/smartcard.h
include/smartcard_debug.h
src/ClientChannel.cpp
src/ClientGDBus.cpp
src/Reader.cpp
src/SEService.cpp
src/Session.cpp
src/smartcard.c
test/smartcard_unit_test.c
unittest/utc-smartcard.c

index ced1cc2..a69d697 100644 (file)
@@ -71,6 +71,7 @@
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
@@ -93,6 +94,7 @@
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
index ced1cc2..a69d697 100644 (file)
@@ -71,6 +71,7 @@
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
@@ -93,6 +94,7 @@
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
   * - %http://tizen.org/feature/network.secure_element\n
   * - %http://tizen.org/feature/network.secure_element.ese\n
   * - %http://tizen.org/feature/network.secure_element.uicc\n
+  * - %http://tizen.org/feature/network.secure_element.usb\n
   * It is recommended to design feature related codes in your application for reliability.\n
   *
   * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
index 8efea8b..96faa9c 100644 (file)
@@ -72,6 +72,12 @@ private:
                static void reader_removed(GObject *source_object,
                        guint reader_id, gchar *reader_name,
                        gpointer user_data);
+               static void card_inserted(GObject *source_object,
+                       guint reader_id, gchar *reader_name,
+                       gpointer user_data);
+               static void card_removed(GObject *source_object,
+                       guint reader_id, gchar *reader_name,
+                       gpointer user_data);
                static void se_service_shutdown_cb(GObject *source_object,
                        GAsyncResult *res, gpointer user_data);
                static void se_service_cb(GObject *source_object,
index 687202a..201617a 100644 (file)
@@ -66,6 +66,8 @@ typedef enum {
        SMARTCARD_READER_EVENT_TYPE_IO_ERROR = 0, /**< This event notifies the application that I/O error occurs on smartcard reader */
        SMARTCARD_READER_EVENT_TYPE_INSERTED = 1, /**< This event notifies the application that smartcard reader is inserted */
        SMARTCARD_READER_EVENT_TYPE_REMOVED = 2, /**< This event notifies the application that smartcard reader is removed */
+       SMARTCARD_READER_EVENT_TYPE_CARD_INSERTED = 3, /**< This event notifies the application that smartcard reader is inserted (Since 6.5) */
+       SMARTCARD_READER_EVENT_TYPE_CARD_REMOVED = 4, /**< This event notifies the application that smartcard reader is removed (Since 6.5) */
 } smartcard_reader_event_type_e;
 
 /**
index c3ed73e..5ebffec 100644 (file)
 #ifndef __TIZEN_CAPI_NETWORK_SMARTCARD_DEBUG_H__
 #define __TIZEN_CAPI_NETWORK_SMARTCARD_DEBUG_H__
 
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "SMARTCARD_API"
+#endif
+
 #define COLOR_BLACK "\033[0;30m"
 #define COLOR_RED   "\033[0;31m"
 #define COLOR_GREEN "\033[0;32m"
@@ -73,4 +80,4 @@
                } \
        } while (0)
 
-#endif /* __TIZEN_CAPI_NETWORK_SMARTCARD_DEBUG_H__ */
\ No newline at end of file
+#endif /* __TIZEN_CAPI_NETWORK_SMARTCARD_DEBUG_H__ */
index ba4673f..678eb7f 100755 (executable)
@@ -23,7 +23,7 @@
 /* SLP library header */
 
 /* local header */
-#include "Debug.h"
+#include "smartcard_debug.h"
 #include "ClientChannel.h"
 #include "ReaderHelper.h"
 #include "APDUHelper.h"
index 90c7373..7eb9013 100755 (executable)
@@ -21,7 +21,7 @@
 
 /* local header */
 #include "smartcard-types.h"
-#include "Debug.h"
+#include "smartcard_debug.h"
 #include "ByteArray.h"
 #include "ClientGDBus.h"
 
index b4d0ddc..5750849 100755 (executable)
@@ -22,7 +22,7 @@
 /* SLP library header */
 
 /* local header */
-#include "Debug.h"
+#include "smartcard_debug.h"
 #include "Reader.h"
 #include "Session.h"
 #include "ClientGDBus.h"
index bdd951d..f45487f 100644 (file)
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 
 /* local header */
-#include "Debug.h"
+#include "smartcard_debug.h"
 #include "SEService.h"
 #include "ClientChannel.h"
 #include "Reader.h"
@@ -104,7 +104,7 @@ namespace smartcard_service_api
                _INFO("[MSG_NOTIFY_SE_INSERTED]");
 
                /* add readers */
-               reader = new (std::nothrow)Reader(service->context,
+               reader = new (std::nothrow)Reader(GUINT_TO_POINTER(service->handle),
                        reader_name, GUINT_TO_POINTER(reader_id));
 
                if (reader != NULL) {
@@ -151,6 +151,48 @@ namespace smartcard_service_api
                }
        }
 
+       void SEService::card_inserted(GObject *source_object,
+               guint reader_id, gchar *reader_name, gpointer user_data)
+       {
+               SEService *service = (SEService *)user_data;
+               size_t i;
+
+               _INFO("[MSG_NOTIFY_CARD_INSERTED]");
+
+               for (i = 0; i < service->readers.size(); i++)
+               {
+                       if (((Reader *)service->readers[i])->handle ==
+                               GUINT_TO_POINTER(reader_id))
+                       {
+                               if (service->event_handler != NULL)
+                                       service->event_handler((long)service->readers[i], 3, service->context);
+                               break;
+                       }
+               }
+       }
+
+       void SEService::card_removed(GObject *source_object,
+               guint reader_id, gchar *reader_name, gpointer user_data)
+       {
+               SEService *service = (SEService *)user_data;
+               size_t i;
+
+               _INFO("[MSG_NOTIFY_CARD_REMOVED]");
+
+               for (i = 0; i < service->readers.size(); i++)
+               {
+                       if (((Reader *)service->readers[i])->handle ==
+                               GUINT_TO_POINTER(reader_id))
+                       {
+                               _INFO("Here it is.");
+
+                               if (service->event_handler != NULL)
+                                       service->event_handler((long)service->readers[i], 4, service->context);
+                               break;
+                       }
+               }
+       }
+
        void SEService::se_service_shutdown_cb(GObject *source_object,
                GAsyncResult *res, gpointer user_data)
        {
@@ -387,6 +429,12 @@ namespace smartcard_service_api
                g_signal_connect(proxy, "reader-removed",
                                G_CALLBACK(&SEService::reader_removed), this);
 
+               g_signal_connect(proxy, "card-inserted",
+                               G_CALLBACK(&SEService::card_inserted), this);
+
+               g_signal_connect(proxy, "card-removed",
+                               G_CALLBACK(&SEService::card_removed), this);
+
                /* request reader */
                if(smartcard_service_se_service_call_se_service_sync(
                        (SmartcardServiceSeService *)proxy, &result, &handle, &readers, NULL, &error) == true) {
@@ -659,7 +707,7 @@ EXTERN_API int se_service_get_readers(se_service_h handle, int **readers, int *c
                for (i = 0; i < temp_readers.size(); i++)
                {
                        if (temp_readers[i]->isSecureElementPresent()) {
-                               (*readers)[i] = (long)temp_readers[i];
+                               (*readers)[temp] = (long)temp_readers[i];
                                temp++;
                        }
                }
index d14f59d..266ee61 100755 (executable)
@@ -23,7 +23,7 @@
 /* SLP library header */
 
 /* local header */
-#include "Debug.h"
+#include "smartcard_debug.h"
 #include "Session.h"
 #include "Reader.h"
 #include "ClientChannel.h"
index f25f943..099a7d8 100755 (executable)
@@ -30,6 +30,7 @@
 #define  SE_FEATURE "http://tizen.org/feature/network.secure_element"
 #define  SE_UICC_FEATURE "http://tizen.org/feature/network.secure_element.uicc"
 #define  SE_ESE_FEATURE "http://tizen.org/feature/network.secure_element.ese"
+#define  SE_USB_FEATURE "http://tizen.org/feature/network.secure_element.usb"
 
 #define  SMARTCARD_LOCK \
 do { \
@@ -79,12 +80,14 @@ static bool _is_smartcard_supported()
        bool is_supported_se = false;
        bool is_supported_se_uicc = false;
        bool is_supported_se_ese = false;
+       bool is_supported_se_usb = false;
 
        system_info_get_platform_bool(SE_FEATURE, &is_supported_se);
        system_info_get_platform_bool(SE_UICC_FEATURE, &is_supported_se_uicc);
        system_info_get_platform_bool(SE_ESE_FEATURE, &is_supported_se_ese);
+       system_info_get_platform_bool(SE_USB_FEATURE, &is_supported_se_usb);
 
-       if (is_supported_se && (is_supported_se_uicc || is_supported_se_ese))
+       if (is_supported_se && (is_supported_se_uicc || is_supported_se_ese || is_supported_se_usb))
                ret = true;
 
        return ret;
index 6729b19..8e45c57 100644 (file)
@@ -70,6 +70,64 @@ void tc_usage_print(void)
        }
 }
 
+void __smartcard_reader_event_cb(int reader, smartcard_reader_event_type_e event_type, void *user_data)
+{
+       int ret;
+       int session;
+       int channel;
+       int pLength;
+       int *phReaders = NULL;
+
+       unsigned char command[] = { 0xFF, 0xCA, 0x00, 0x00, 0x00 };
+       unsigned char *response = NULL;
+       int resp_len = 50;
+
+       if (event_type == SMARTCARD_READER_EVENT_TYPE_CARD_INSERTED) {
+               TC_PRT("smartcard inserted");
+
+               ret = smartcard_get_readers(&phReaders, &pLength);
+               if (ret != SMARTCARD_ERROR_NONE || pLength <= 0) {
+                       TC_PRT("smartcard_get_readers failed : %d, %d", ret, pLength);
+                       return;
+               }
+
+               for (int i = 0; i < pLength; i++) {
+                       if (phReaders[i] == reader) {
+                               ret = smartcard_reader_open_session(phReaders[i], &session);
+                               if (ret != SMARTCARD_ERROR_NONE || session <= 0) {
+                                       TC_PRT("smartcard_reader_open_session failed");
+                                       return;
+                               }
+
+                               ret = smartcard_session_open_basic_channel(session, NULL, 0, 0x00, &channel);
+                               if (ret != SMARTCARD_ERROR_NONE || channel <= 0) {
+                                       TC_PRT("smartcard_session_open_basic_channel failed");
+                                       return;
+                               }
+
+                               ret = smartcard_channel_transmit(channel, command, 5, &response, &resp_len);
+                               if (ret != SMARTCARD_ERROR_NONE) {
+                                       TC_PRT("smartcard_channel_transmit failed");
+                                       return;
+                               }
+
+                               TC_PRT("response length %d", resp_len);
+                               printf("\nAPDU : { ");
+                               for (int i = 0; i < resp_len; i++) {
+                                       printf("0x%02X ", (int)response[i]);
+                               }
+                               printf("} \n\n");
+                       }
+               }
+       } else if (event_type == SMARTCARD_READER_EVENT_TYPE_CARD_REMOVED) {
+               TC_PRT("smartcard removed");
+       } else if (event_type == SMARTCARD_READER_EVENT_TYPE_INSERTED) {
+               TC_PRT("reader inserted");
+       } else if (event_type == SMARTCARD_READER_EVENT_TYPE_REMOVED) {
+               TC_PRT("reader removed");
+       }
+}
+
 int test_input_callback(void *data)
 {
        int ret = 0;
@@ -89,6 +147,10 @@ int test_input_callback(void *data)
                                TC_PRT("smartcard initialize success");
                        else
                                TC_PRT("smartcard initialize failed");
+
+                       smartcard_reader_set_event_cb(__smartcard_reader_event_cb, NULL);
+
+                       TC_PRT("smartcard_reader_set_event_cb success");
                }
                break;
        case 2:
@@ -111,8 +173,11 @@ int test_input_callback(void *data)
 
                        if (ret == SMARTCARD_ERROR_NONE) {
                                TC_PRT("smartcard_get_readers is success");
-                               TC_PRT("reader handle : %d", phReaders[0]);
                                TC_PRT("readers length : %d", pLength);
+
+                               if (pLength > 0)
+                                       TC_PRT("reader handle : %d", phReaders[0]);
+
                        } else {
                                TC_PRT("smartcard_get_readers is failed : %d", ret);
                        }
index f0cb6d7..4261633 100755 (executable)
@@ -20,6 +20,7 @@
 #define  SE_FEATURE "http://tizen.org/feature/network.secure_element"
 #define  SE_UICC_FEATURE "http://tizen.org/feature/network.secure_element.uicc"
 #define  SE_ESE_FEATURE "http://tizen.org/feature/network.secure_element.ese"
+#define  SE_ESE_FEATURE "http://tizen.org/feature/network.secure_element.usb"
 
 bool _is_support_smartcard()
 {
@@ -27,12 +28,14 @@ bool _is_support_smartcard()
        bool is_supported_se = false;
        bool is_supported_se_uicc = false;
        bool is_supported_se_ese = false;
+       bool is_supported_se_usb = false;
 
        system_info_get_platform_bool(SE_FEATURE, &is_supported_se);
        system_info_get_platform_bool(SE_UICC_FEATURE, &is_supported_se_uicc);
        system_info_get_platform_bool(SE_ESE_FEATURE, &is_supported_se_ese);
+       system_info_get_platform_bool(SE_USB_FEATURE, &is_supported_se_usb);
 
-       if(is_supported_se && (is_supported_se_uicc || is_supported_se_ese))
+       if(is_supported_se && (is_supported_se_uicc || is_supported_se_ese || is_supported_se_usb))
                ret = true;
 
        return ret;