Allow selecting PICC level too

This commit is contained in:
Willy-JL
2025-03-15 03:05:20 +00:00
parent 799ed9fcaf
commit b05a735e8f
4 changed files with 35 additions and 32 deletions
+2 -1
View File
@@ -26,8 +26,9 @@
#define TYPE_4_TAG_ISO_STATUS_BAD_PARAMS 0x6A, 0x86
#define TYPE_4_TAG_ISO_STATUS_NO_CMD 0x68, 0x00
#define TYPE_4_TAG_ISO_RW_CHUNK_LEN (255U)
#define TYPE_4_TAG_ISO_APP_NAME_LEN (7U)
#define TYPE_4_TAG_ISO_NAME_LEN (7U)
#define TYPE_4_TAG_ISO_APP_NAME 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01
#define TYPE_4_TAG_ISO_PICC_NAME 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00
#define TYPE_4_TAG_T4T_CC_FILE_ID_LEN (2U)
#define TYPE_4_TAG_T4T_CC_FILE_ID 0xE1, 0x03
#define TYPE_4_TAG_T4T_CC_VNO (0x20)
@@ -36,7 +36,15 @@ static Type4TagError type_4_tag_listener_iso_select(
UNUSED(le);
if(p1 == TYPE_4_TAG_ISO_SELECT_P1_BY_DF_NAME) {
static const uint8_t t4t_app[TYPE_4_TAG_ISO_APP_NAME_LEN] = {TYPE_4_TAG_ISO_APP_NAME};
static const uint8_t t4t_picc[TYPE_4_TAG_ISO_NAME_LEN] = {TYPE_4_TAG_ISO_PICC_NAME};
if(lc == sizeof(t4t_picc) && memcmp(t4t_picc, data, sizeof(t4t_picc)) == 0) {
instance->state = Type4TagListenerStateSelectedPicc;
bit_buffer_append_bytes(
instance->tx_buffer, type_4_tag_success_apdu, sizeof(type_4_tag_success_apdu));
return Type4TagErrorNone;
}
static const uint8_t t4t_app[TYPE_4_TAG_ISO_NAME_LEN] = {TYPE_4_TAG_ISO_APP_NAME};
if(lc == sizeof(t4t_app) && memcmp(t4t_app, data, sizeof(t4t_app)) == 0) {
instance->state = Type4TagListenerStateSelectedApplication;
bit_buffer_append_bytes(
@@ -44,36 +52,29 @@ static Type4TagError type_4_tag_listener_iso_select(
return Type4TagErrorNone;
}
instance->state = Type4TagListenerStateIdle;
bit_buffer_append_bytes(
instance->tx_buffer, type_4_tag_not_found_apdu, sizeof(type_4_tag_not_found_apdu));
return Type4TagErrorCustomCommand;
}
} else if(
instance->state >= Type4TagListenerStateSelectedApplication &&
(p1 == TYPE_4_TAG_ISO_SELECT_P1_BY_ID || p1 == TYPE_4_TAG_ISO_SELECT_P1_BY_EF_ID)) {
static const uint8_t cc_id[TYPE_4_TAG_T4T_CC_FILE_ID_LEN] = {TYPE_4_TAG_T4T_CC_FILE_ID};
if(lc == sizeof(cc_id) && memcmp(cc_id, data, sizeof(cc_id)) == 0) {
instance->state = Type4TagListenerStateSelectedCapabilityContainer;
bit_buffer_append_bytes(
instance->tx_buffer, type_4_tag_success_apdu, sizeof(type_4_tag_success_apdu));
return Type4TagErrorNone;
}
if(instance->state >= Type4TagListenerStateSelectedApplication) {
if(p1 == TYPE_4_TAG_ISO_SELECT_P1_BY_ID || p1 == TYPE_4_TAG_ISO_SELECT_P1_BY_EF_ID) {
static const uint8_t cc_id[TYPE_4_TAG_T4T_CC_FILE_ID_LEN] = {
TYPE_4_TAG_T4T_CC_FILE_ID};
if(lc == sizeof(cc_id) && memcmp(cc_id, data, sizeof(cc_id)) == 0) {
instance->state = Type4TagListenerStateSelectedCapabilityContainer;
bit_buffer_append_bytes(
instance->tx_buffer, type_4_tag_success_apdu, sizeof(type_4_tag_success_apdu));
return Type4TagErrorNone;
}
uint8_t ndef_file_id_be[sizeof(instance->data->ndef_file_id)];
bit_lib_num_to_bytes_be(
instance->data->is_tag_specific ? instance->data->ndef_file_id :
TYPE_4_TAG_T4T_DEFAULT_FILE_ID,
sizeof(ndef_file_id_be),
ndef_file_id_be);
if(lc == sizeof(ndef_file_id_be) &&
memcmp(ndef_file_id_be, data, sizeof(ndef_file_id_be)) == 0) {
instance->state = Type4TagListenerStateSelectedNdefMessage;
bit_buffer_append_bytes(
instance->tx_buffer, type_4_tag_success_apdu, sizeof(type_4_tag_success_apdu));
return Type4TagErrorNone;
}
uint8_t ndef_file_id_be[sizeof(instance->data->ndef_file_id)];
bit_lib_num_to_bytes_be(
instance->data->is_tag_specific ? instance->data->ndef_file_id :
TYPE_4_TAG_T4T_DEFAULT_FILE_ID,
sizeof(ndef_file_id_be),
ndef_file_id_be);
if(lc == sizeof(ndef_file_id_be) &&
memcmp(ndef_file_id_be, data, sizeof(ndef_file_id_be)) == 0) {
instance->state = Type4TagListenerStateSelectedNdefMessage;
bit_buffer_append_bytes(
instance->tx_buffer, type_4_tag_success_apdu, sizeof(type_4_tag_success_apdu));
return Type4TagErrorNone;
}
}
@@ -10,6 +10,7 @@ extern "C" {
typedef enum {
Type4TagListenerStateIdle,
Type4TagListenerStateSelectedPicc,
Type4TagListenerStateSelectedApplication,
Type4TagListenerStateSelectedCapabilityContainer,
Type4TagListenerStateSelectedNdefMessage,
@@ -47,7 +47,7 @@ Type4TagError type_4_tag_poller_select_app(Type4TagPoller* instance) {
TYPE_4_TAG_ISO_SELECT_CMD,
TYPE_4_TAG_ISO_SELECT_P1_BY_DF_NAME,
TYPE_4_TAG_ISO_SELECT_P2_EMPTY,
TYPE_4_TAG_ISO_APP_NAME_LEN,
TYPE_4_TAG_ISO_NAME_LEN,
TYPE_4_TAG_ISO_APP_NAME,
TYPE_4_TAG_ISO_SELECT_LE_EMPTY,
};