From 45273626eb8d500d5aa35927b37292c9fceb2788 Mon Sep 17 00:00:00 2001 From: Jan-Christopher Pien <101@janchristopherpien.de> Date: Mon, 10 Oct 2016 22:25:33 +0200 Subject: [PATCH] Register AIDs (stub) --- TCardEmulator/inc/tcardemulator.h | 2 ++ TCardEmulator/src/sap.c | 6 ++++++ TCardEmulator/src/tcardemulator.c | 28 +++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/TCardEmulator/inc/tcardemulator.h b/TCardEmulator/inc/tcardemulator.h index 521baf9..62c9665 100644 --- a/TCardEmulator/inc/tcardemulator.h +++ b/TCardEmulator/inc/tcardemulator.h @@ -10,6 +10,7 @@ #include #include #include +#include //extern unsigned char *rapdu; //extern size_t rapdu_length; @@ -23,5 +24,6 @@ gboolean find_peers(); gboolean request_service_connection(void); gboolean terminate_service_connection(void); gboolean send_data(nfc_se_h nfc_handle, void *message, unsigned int message_len); +GSList* request_installed_aids(); #endif /* __tcardemulator_H__ */ diff --git a/TCardEmulator/src/sap.c b/TCardEmulator/src/sap.c index 1a06c94..82aec7e 100644 --- a/TCardEmulator/src/sap.c +++ b/TCardEmulator/src/sap.c @@ -5,6 +5,7 @@ #include #include #include +#include #define HELLO_ACCESSORY_PROFILE_ID "/com/vsmcartcard" #define HELLO_ACCESSORY_CHANNELID 104 @@ -309,6 +310,11 @@ gboolean find_peers() return TRUE; } +GSList* request_installed_aids() { + GSList* aid_list = g_slist_append(NULL, "A000000397425446590201"); + return aid_list; +} + static void on_agent_initialized(sap_agent_h agent, sap_agent_initialized_result_e result, void *user_data) diff --git a/TCardEmulator/src/tcardemulator.c b/TCardEmulator/src/tcardemulator.c index 80ba95d..cce0a7f 100644 --- a/TCardEmulator/src/tcardemulator.c +++ b/TCardEmulator/src/tcardemulator.c @@ -4,6 +4,7 @@ #include #include #include +#include typedef struct appdata { @@ -22,14 +23,14 @@ hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event, // Do something when NFC_HCE_EVENT_DEACTIVATED event arrives // When the event arrives, apdu and apdu len is NULL and 0 dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_DEACTIVATED event on NFC handle %d", handle); - terminate_service_connection(); + //terminate_service_connection(); break; case NFC_HCE_EVENT_ACTIVATED: // Do something when NFC_HCE_EVENT_ACTIVATED event arrives // When the event arrives, apdu and apdu len is NULL and 0 dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_ACTIVATED event on NFC handle %d", handle); - find_peers(); + //find_peers(); break; case NFC_HCE_EVENT_APDU_RECEIVED: @@ -52,9 +53,26 @@ hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event, } } +void register_aid(gpointer data, gpointer user_data) { + int result = nfc_se_register_aid(NFC_SE_TYPE_HCE, NFC_CARD_EMULATION_CATEGORY_OTHER, data); + if (result != NFC_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "nfc_se_register_aid for aid %s failed: %d", data, result); + } else { + dlog_print(DLOG_DEBUG, LOG_TAG, "nfc_se_register_aid for aid %s succeeded.", data); + } +} + +void install_aids() { + GSList* aid_list = request_installed_aids(); + g_slist_foreach(aid_list, register_aid, NULL); +} + void send_apdu_response(nfc_se_h handle, unsigned char *resp, unsigned int resp_len) { dlog_print(DLOG_DEBUG, LOG_TAG, "sending data to nfc handle: %d", handle); - nfc_hce_send_apdu_response(handle, resp, resp_len); + int result = nfc_hce_send_apdu_response(handle, resp, resp_len); + if (result != NFC_ERROR_NONE) { + dlog_print(DLOG_DEBUG, LOG_TAG, "error sending data to nfc handle %d: ", handle); + } } bool @@ -94,6 +112,10 @@ service_app_create(void *data) initialize_sap(); + find_peers(); + + install_aids(); + r = true; err: