From 8254959a5cf877241504529d2fd1ce6563834f0d Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Fri, 25 Jun 2021 16:44:45 +0900 Subject: [PATCH] Add new feature and 2 enum values for USB secure element Change-Id: I66bdcf6b977be5ed74bda2b4b711037cce5d4687 Signed-off-by: Jihoon Jung --- doc/mobile/smartcard_doc.h | 4 +++ doc/wearable/smartcard_doc.h | 4 +++ include/SEService.h | 6 ++++ include/smartcard.h | 2 ++ include/smartcard_debug.h | 9 +++++- src/ClientChannel.cpp | 2 +- src/ClientGDBus.cpp | 2 +- src/Reader.cpp | 2 +- src/SEService.cpp | 54 +++++++++++++++++++++++++++++++++-- src/Session.cpp | 2 +- src/smartcard.c | 5 +++- test/smartcard_unit_test.c | 67 +++++++++++++++++++++++++++++++++++++++++++- unittest/utc-smartcard.c | 5 +++- 13 files changed, 153 insertions(+), 11 deletions(-) diff --git a/doc/mobile/smartcard_doc.h b/doc/mobile/smartcard_doc.h index ced1cc2..a69d697 100644 --- a/doc/mobile/smartcard_doc.h +++ b/doc/mobile/smartcard_doc.h @@ -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 @@ -115,6 +117,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 @@ -137,6 +140,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 diff --git a/doc/wearable/smartcard_doc.h b/doc/wearable/smartcard_doc.h index ced1cc2..a69d697 100644 --- a/doc/wearable/smartcard_doc.h +++ b/doc/wearable/smartcard_doc.h @@ -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 @@ -115,6 +117,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 @@ -137,6 +140,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 diff --git a/include/SEService.h b/include/SEService.h index 8efea8b..96faa9c 100644 --- a/include/SEService.h +++ b/include/SEService.h @@ -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, diff --git a/include/smartcard.h b/include/smartcard.h index 687202a..201617a 100644 --- a/include/smartcard.h +++ b/include/smartcard.h @@ -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; /** diff --git a/include/smartcard_debug.h b/include/smartcard_debug.h index c3ed73e..5ebffec 100644 --- a/include/smartcard_debug.h +++ b/include/smartcard_debug.h @@ -17,6 +17,13 @@ #ifndef __TIZEN_CAPI_NETWORK_SMARTCARD_DEBUG_H__ #define __TIZEN_CAPI_NETWORK_SMARTCARD_DEBUG_H__ +#include + +#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__ */ diff --git a/src/ClientChannel.cpp b/src/ClientChannel.cpp index ba4673f..678eb7f 100755 --- a/src/ClientChannel.cpp +++ b/src/ClientChannel.cpp @@ -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" diff --git a/src/ClientGDBus.cpp b/src/ClientGDBus.cpp index 90c7373..7eb9013 100755 --- a/src/ClientGDBus.cpp +++ b/src/ClientGDBus.cpp @@ -21,7 +21,7 @@ /* local header */ #include "smartcard-types.h" -#include "Debug.h" +#include "smartcard_debug.h" #include "ByteArray.h" #include "ClientGDBus.h" diff --git a/src/Reader.cpp b/src/Reader.cpp index b4d0ddc..5750849 100755 --- a/src/Reader.cpp +++ b/src/Reader.cpp @@ -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" diff --git a/src/SEService.cpp b/src/SEService.cpp index bdd951d..f45487f 100644 --- a/src/SEService.cpp +++ b/src/SEService.cpp @@ -22,7 +22,7 @@ #include /* 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++; } } diff --git a/src/Session.cpp b/src/Session.cpp index d14f59d..266ee61 100755 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -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" diff --git a/src/smartcard.c b/src/smartcard.c index f25f943..099a7d8 100755 --- a/src/smartcard.c +++ b/src/smartcard.c @@ -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; diff --git a/test/smartcard_unit_test.c b/test/smartcard_unit_test.c index 6729b19..8e45c57 100644 --- a/test/smartcard_unit_test.c +++ b/test/smartcard_unit_test.c @@ -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); } diff --git a/unittest/utc-smartcard.c b/unittest/utc-smartcard.c index f0cb6d7..4261633 100755 --- a/unittest/utc-smartcard.c +++ b/unittest/utc-smartcard.c @@ -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; -- 2.7.4