// variables for handles
uint32_t hSEService;
uint32_t seChannel;
uint32_t uiccSeReaderID = 0;
// variables for retrieving the Readers, holders of
// possible secure elements
uint32_t numberOfReaders = 0;
uint32_t *phReaders = NULL;
static int DEF_LEN = 10;
char readerName[DEF_LEN];
uint32_t len = 10;
//variables for opening and exchanging data
fcp_type_t fcpResponseType;
int32_t openResponseLen;
uint32_t exchangeResponseLen;
uint32_t nReceiveAPDUBufferSize;
uint8_t* result;
uint8_t aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50,
0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
uint32_t aid_len = sizeof(aid);
uint8_t select_file_apdu[] = { 0x00, 0xA4, 0x00, 0x0C,
0x02, 0x50, 0x31 };
uint32_t apdu_len = sizeof(select_file_apdu);
// loop variable
uint32_t i;
// Find readers we have access to
if( NFC_RESULT_SUCCESS !=
nfc_se_service_get_num_readers(&numberOfReaders) ) {
// Handle error - this is a system error
// and the app cannot continue.
...
}
// Allocate space for the readers
phReaders = (uint32_t*)malloc (sizeof(uint32_t) *
numberOfReaders);
// Get the handles for the readers
if( NFC_RESULT_SUCCESS !=
nfc_se_service_get_readers(phReaders,
&numberOfReaders) ){
// Handle error - this is a system error and the
// app cannot continue.
...
}
// Iterate through the readers to find the SIM reader
for( i = 0; i < numberOfReaders; i++ ) {
len = 10;
if( NFC_RESULT_SUCCESS !=
nfc_se_reader_get_name(phReaders[i],
readerName,
&len) ){
// Handle error - this is a system error and
// the app cannot continue.
}
if( ( len == 3 ) && (strcmp(readerName, "SIM") == 0) ) {
uiccSeReaderID = phReaders[i];
break;
}
}
// Deallocate the array for holding the readers
free(phReaders);
// Open a session with the SIM Reader
// Note: You may hold onto this session for the lifetime
// of you application.
if( NFC_RESULT_SUCCESS !=
nfc_se_reader_open_session( uiccSeReaderID,
&hSESession ) ) {
// Handle error - this is a system error and
// the app cannot continue.
...
}
// Open a channel to AID A000000063504B43532D3135
fcpResponseType = OPEN_NO_FCP_INFO;
openResponseLen = 0;
if( NFC_RESULT_SUCCESS !=
nfc_se_session_open_logical_channel( hSESession,
aid,
aid_len,
fcpResponseType,
&seChannel,
&openResponseLen )) {
// Handle error
...
else {
result = (uint8_t*)malloc (sizeof(uint8_t) *
openResponseLen);
//get the response of the open call
nReceiveAPDUBufferSize = openResponseLen;
if( NFC_RESULT_SUCCESS !=
nfc_se_channel_get_transmit_data(seChannel,
&result[0],
&nReceiveAPDUBufferSize)) {
// Handle error
...
}
// the result of the open should be 90 00
if((nReceiveAPDUBufferSize < 2) ||
((0x90 != result[nReceiveAPDUBufferSize - 2])
&& (0x00 != result[nReceiveAPDUBufferSize - 1]))) {
// Handle error
...
}
free(result);
}
if( NFC_RESULT_SUCCESS !=
nfc_se_channel_transmit_apdu( seChannel,
select_file_apdu, 7,
&exchangeResponseLen ) ) {
// Handle error
...
}
nReceiveAPDUBufferSize = exchangeResponseLen;
result = (uint8_t*)malloc (sizeof(uint8_t) *
exchangeResponseLen);
if( NFC_RESULT_SUCCESS ==
nfc_se_channel_get_transmit_data( seChannel,
&result[0],
&nReceiveAPDUBufferSize ) ) {
//Print the response
for( i = 0; i < nReceiveAPDUBufferSize - 1; i ++ ) {
printf( "0x%.2x, ", result[i] );
}
printf("0x%.2x }\n", result[nReceiveAPDUBufferSize - 1]);
}
// Free up the memory allocated
free( result );
// Close the channel
if( NFC_RESULT_SUCCESS !=
nfc_se_channel_close_channel( seChannel ) ) {
// Handle error
...
}