Authentication for ACardEmulator/TCardEmulator

secure sending and with high priority
This commit is contained in:
Jan-Christopher Pien
2016-10-11 21:54:29 +02:00
committed by Frank Morgner
parent 45273626eb
commit 9c758ffda0
10 changed files with 117 additions and 191 deletions

View File

@@ -1,4 +1,5 @@
#include "tcardemulator.h"
#include "sap_app.h"
#include <service_app.h>
#include <nfc.h>
#include <dlog.h>
@@ -10,45 +11,30 @@ typedef struct appdata {
} appdata_s;
//unsigned char *rapdu = NULL;
//size_t rapdu_length = 0;
//gboolean rapdu_received = FALSE;
static void
hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
unsigned char *apdu, unsigned int apdu_len, void *user_data)
{
static void hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event, unsigned char *apdu, unsigned int apdu_len, void *user_data) {
switch (event) {
case NFC_HCE_EVENT_DEACTIVATED:
// 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();
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();
if (!agent_connected) {
find_peers();
}
break;
case NFC_HCE_EVENT_APDU_RECEIVED:
// rapdu_received = FALSE;
dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_APDU_RECEIVED event on NFC handle %d", handle);
send_data(handle, apdu, apdu_len);
// size_t count_apdu = 0;
// while (!rapdu_received && count_apdu < 10) {
// dlog_print(DLOG_INFO, LOG_TAG, "waiting for response");
// usleep(100);
// count_apdu++;
// }
// nfc_hce_send_apdu_response(handle, rapdu, rapdu_length);
// rapdu_received = FALSE;
if (agent_connected) {
send_data(handle, apdu, apdu_len);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "couldn't send message on SAP channel because agent is not connected");
}
break;
default:
// Error handling
dlog_print(DLOG_DEBUG, LOG_TAG, "received unknown event on NFC handle %d", handle);
break;
}
}
@@ -75,9 +61,7 @@ void send_apdu_response(nfc_se_h handle, unsigned char *resp, unsigned int resp_
}
}
bool
service_app_create(void *data)
{
bool service_app_create(void *data) {
int ret = NFC_ERROR_NONE;
bool r = false;
nfc_se_card_emulation_mode_type_e ce_type;
@@ -122,9 +106,7 @@ err:
return r;
}
void
service_app_terminate(void *data)
{
void service_app_terminate(void *data) {
int ret = NFC_ERROR_NONE;
nfc_manager_unset_hce_event_cb();
@@ -137,43 +119,26 @@ service_app_terminate(void *data)
terminate_service_connection();
// free(rapdu);
// rapdu = NULL;
// rapdu_length = 0;
// rapdu_received = FALSE;
return;
}
void
service_app_control(app_control_h app_control, void *data)
{
// Todo: add your code here
void service_app_control(app_control_h app_control, void *data) {
return;
}
void
service_app_low_memory(void *data)
{
// Todo: add your code here
void service_app_low_memory(void *data) {
service_app_terminate(&data);
return;
}
void
service_app_low_battery(void *data)
{
// Todo: add your code here
void service_app_low_battery(void *data) {
service_app_terminate(&data);
return;
}
int
main(int argc, char* argv[])
{
int main(int argc, char* argv[]) {
appdata_s ad = {};
service_app_event_callback_s event_callback;
@@ -184,20 +149,5 @@ main(int argc, char* argv[])
event_callback.low_memory = service_app_low_memory;
event_callback.low_battery = service_app_low_battery;
//#if 1
// initialize_sap();
// find_peers();
// rapdu_received = FALSE;
// unsigned char apdu[] = {0x00, 0xa4, 0x00, 0x00};
// send_data(apdu, sizeof apdu);
// size_t count = 0;
// while (!rapdu_received && count < 10) {
// dlog_print(DLOG_INFO, LOG_TAG, "waiting for response");
// usleep(100);
// count++;
// }
//#endif
return svc_app_main(argc, argv, &event_callback, &ad);
}