SELECT works

This commit is contained in:
merlokk 2019-01-24 17:57:42 +02:00
parent 4e0dc15dfd
commit ad9186c13b
2 changed files with 18 additions and 29 deletions

View File

@ -104,37 +104,24 @@ void rblock_acknowledge()
// Selects application. Returns 1 if success, 0 otherwise
int select_applet(uint8_t * aid, int len)
{
if (memcmp(aid,AID_NDEF_TYPE_4,sizeof(AID_NDEF_TYPE_4)) == 0)
if (memcmp(aid,AID_FIDO,sizeof(AID_FIDO)) == 0)
{
NFC_STATE.selected_applet = APP_NDEF_TYPE_4;
return 1;
} else if (memcmp(aid,AID_NDEF_MIFARE_TYPE_4,sizeof(AID_NDEF_MIFARE_TYPE_4)) == 0)
{
NFC_STATE.selected_applet = APP_MIFARE_TYPE_4;
return 1;
} else if (memcmp(aid,AID_CAPABILITY_CONTAINER,sizeof(AID_CAPABILITY_CONTAINER)) == 0)
{
NFC_STATE.selected_applet = APP_CAPABILITY_CONTAINER;
return 1;
} else if (memcmp(aid,AID_NDEF_TAG,sizeof(AID_NDEF_TAG)) == 0)
{
NFC_STATE.selected_applet = APP_NDEF_TAG;
NFC_STATE.selected_applet = APP_FIDO;
return 1;
}
return 0;
}
void nfc_process_iblock(uint8_t * buf, int len)
{
APDU_HEADER * apdu = (APDU_HEADER *)(buf+1);
APDU_HEADER * apdu = (APDU_HEADER *)(buf + 1);
uint8_t * payload = buf + 1 + 5;
uint8_t plen = apdu->lc;
int selected;
uint8_t res[32];
printf1(TAG_NFC,">> "); dump_hex1(TAG_NFC,buf,len);
printf1(TAG_NFC,">> ");
dump_hex1(TAG_NFC, buf, len);
// TODO this needs to be organized better
switch(apdu->ins)
@ -162,13 +149,12 @@ void nfc_process_iblock(uint8_t * buf, int len)
selected = select_applet(payload, plen);
if (selected)
{
// block = buf[0] & 1;
// block = NFC_STATE.block_num;
// block = !block;
// NFC_STATE.block_num = block;
res[0] = NFC_CMD_IBLOCK | (buf[0] & 1);
res[1] = APDU_STATUS_SUCCESS>>8;
res[0] = NFC_CMD_IBLOCK | (buf[0] & 3);
res[1] = APDU_STATUS_SUCCESS >> 8;
res[2] = APDU_STATUS_SUCCESS & 0xff;
nfc_write_frame(res, 3);
printf1(TAG_NFC,"<< "); dump_hex1(TAG_NFC,res, 3);
@ -231,8 +217,8 @@ void nfc_process_block(uint8_t * buf, int len)
}
else if (IS_IBLOCK(buf[0]))
{
nfc_process_iblock(buf,len);
printf1(TAG_NFC, "NFC_CMD_IBLOCK\r\n");
nfc_process_iblock(buf, len);
}
else if (IS_RBLOCK(buf[0]))
{

View File

@ -34,14 +34,15 @@ typedef struct
#define NFC_CMD_PPSS 0xd0
#define IS_PPSS_CMD(x) (((x) & 0xf0) == NFC_CMD_PPSS)
#define NFC_CMD_IBLOCK 0x02
#define IS_IBLOCK(x) (((x) & 0xe2) == NFC_CMD_IBLOCK)
#define NFC_CMD_RBLOCK 0xa2
#define IS_RBLOCK(x) (((x) & 0xe6) == NFC_CMD_RBLOCK)
#define NFC_CMD_SBLOCK 0xc2
#define IS_SBLOCK(x) (((x) & 0xc7) == NFC_CMD_SBLOCK)
#define NFC_CMD_IBLOCK 0x00
#define IS_IBLOCK(x) ( (((x) & 0xc0) == NFC_CMD_IBLOCK) && (((x) & 0x02) == 0x02) )
#define NFC_CMD_RBLOCK 0x80
#define IS_RBLOCK(x) ( (((x) & 0xc0) == NFC_CMD_RBLOCK) && (((x) & 0x02) == 0x02) )
#define NFC_CMD_SBLOCK 0xc0
#define IS_SBLOCK(x) ( (((x) & 0xc0) == NFC_CMD_SBLOCK) && (((x) & 0x02) == 0x02) )
#define NFC_SBLOCK_DESELECT 0x30
#define NFC_SBLOCK_DESELECT 0x32
#define NFC_SBLOCK_WTX 0xf2
#define APDU_INS_SELECT 0xA4
#define APDU_INS_READ_BINARY 0xB0
@ -50,6 +51,7 @@ typedef struct
#define AID_NDEF_MIFARE_TYPE_4 "\xD2\x76\x00\x00\x85\x01\x00"
#define AID_CAPABILITY_CONTAINER "\xE1\x03"
#define AID_NDEF_TAG "\x11\x11"
#define AID_FIDO "\xa0\x00\x00\x06\x47\x2f\x00\x01"
typedef enum
{
@ -57,6 +59,7 @@ typedef enum
APP_MIFARE_TYPE_4,
APP_CAPABILITY_CONTAINER,
APP_NDEF_TAG,
APP_FIDO,
} APPLETS;
#define APDU_STATUS_SUCCESS 0x9000