Register AIDs (stub)
This commit is contained in:
committed by
Frank Morgner
parent
f2a68c95c1
commit
45273626eb
@@ -10,6 +10,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <nfc.h>
|
#include <nfc.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
//extern unsigned char *rapdu;
|
//extern unsigned char *rapdu;
|
||||||
//extern size_t rapdu_length;
|
//extern size_t rapdu_length;
|
||||||
@@ -23,5 +24,6 @@ gboolean find_peers();
|
|||||||
gboolean request_service_connection(void);
|
gboolean request_service_connection(void);
|
||||||
gboolean terminate_service_connection(void);
|
gboolean terminate_service_connection(void);
|
||||||
gboolean send_data(nfc_se_h nfc_handle, void *message, unsigned int message_len);
|
gboolean send_data(nfc_se_h nfc_handle, void *message, unsigned int message_len);
|
||||||
|
GSList* request_installed_aids();
|
||||||
|
|
||||||
#endif /* __tcardemulator_H__ */
|
#endif /* __tcardemulator_H__ */
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <nfc.h>
|
#include <nfc.h>
|
||||||
#include <sap.h>
|
#include <sap.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#define HELLO_ACCESSORY_PROFILE_ID "/com/vsmcartcard"
|
#define HELLO_ACCESSORY_PROFILE_ID "/com/vsmcartcard"
|
||||||
#define HELLO_ACCESSORY_CHANNELID 104
|
#define HELLO_ACCESSORY_CHANNELID 104
|
||||||
@@ -309,6 +310,11 @@ gboolean find_peers()
|
|||||||
return TRUE;
|
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,
|
static void on_agent_initialized(sap_agent_h agent,
|
||||||
sap_agent_initialized_result_e result,
|
sap_agent_initialized_result_e result,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <dlog.h>
|
#include <dlog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
typedef struct appdata {
|
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
|
// Do something when NFC_HCE_EVENT_DEACTIVATED event arrives
|
||||||
// When the event arrives, apdu and apdu len is NULL and 0
|
// 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);
|
dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_DEACTIVATED event on NFC handle %d", handle);
|
||||||
terminate_service_connection();
|
//terminate_service_connection();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NFC_HCE_EVENT_ACTIVATED:
|
case NFC_HCE_EVENT_ACTIVATED:
|
||||||
// Do something when NFC_HCE_EVENT_ACTIVATED event arrives
|
// Do something when NFC_HCE_EVENT_ACTIVATED event arrives
|
||||||
// When the event arrives, apdu and apdu len is NULL and 0
|
// 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);
|
dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_ACTIVATED event on NFC handle %d", handle);
|
||||||
find_peers();
|
//find_peers();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NFC_HCE_EVENT_APDU_RECEIVED:
|
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) {
|
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);
|
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
|
bool
|
||||||
@@ -94,6 +112,10 @@ service_app_create(void *data)
|
|||||||
|
|
||||||
initialize_sap();
|
initialize_sap();
|
||||||
|
|
||||||
|
find_peers();
|
||||||
|
|
||||||
|
install_aids();
|
||||||
|
|
||||||
r = true;
|
r = true;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
|||||||
Reference in New Issue
Block a user