New API function freefare_get_tag_uid().
- Deprecates mifare_classic_get_uid() and mifare_ultralight_get_uid().
This commit is contained in:
parent
85e7174a02
commit
574b068b3f
8 changed files with 45 additions and 3 deletions
|
@ -21,6 +21,7 @@ man_MANS = freefare.3 \
|
||||||
linkedman = \
|
linkedman = \
|
||||||
freefare.3 freefare_get_tags.3 \
|
freefare.3 freefare_get_tags.3 \
|
||||||
freefare.3 freefare_get_tag_type.3 \
|
freefare.3 freefare_get_tag_type.3 \
|
||||||
|
freefare.3 freefare_get_tag_uid.3 \
|
||||||
freefare.3 freefare_get_tag_friendly_name.3 \
|
freefare.3 freefare_get_tag_friendly_name.3 \
|
||||||
freefare.3 freefare_free_tags.3 \
|
freefare.3 freefare_free_tags.3 \
|
||||||
mifare_ultralight.3 mifare_ultralight_connect.3 \
|
mifare_ultralight.3 mifare_ultralight_connect.3 \
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
.Nm freefare_get_tags ,
|
.Nm freefare_get_tags ,
|
||||||
.Nm freefare_get_tag_type ,
|
.Nm freefare_get_tag_type ,
|
||||||
.Nm freefare_get_tag_friendly_name ,
|
.Nm freefare_get_tag_friendly_name ,
|
||||||
|
.Nm freefare_get_tag_uid ,
|
||||||
.Nm freefare_free_tags
|
.Nm freefare_free_tags
|
||||||
.Nd Generic target manipulation functions
|
.Nd Generic target manipulation functions
|
||||||
.\" _ _ _
|
.\" _ _ _
|
||||||
|
@ -52,6 +53,8 @@ Mifare card manipulation library (libfreefare, \-lfreefare)
|
||||||
.Fn freefare_get_tag_type "MifareTag tag"
|
.Fn freefare_get_tag_type "MifareTag tag"
|
||||||
.Ft "const char *"
|
.Ft "const char *"
|
||||||
.Fn freefare_get_tag_friendly_name "MifareTag tag"
|
.Fn freefare_get_tag_friendly_name "MifareTag tag"
|
||||||
|
.Ft "char *"
|
||||||
|
.Fn freefare_get_tag_uid "MifareTag tag"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn freefare_free_tags "MifareTag *tags"
|
.Fn freefare_free_tags "MifareTag *tags"
|
||||||
.\" ____ _ _ _
|
.\" ____ _ _ _
|
||||||
|
@ -78,7 +81,8 @@ This list has to be freed after usage using
|
||||||
Information about a given
|
Information about a given
|
||||||
.Vt MifareTag
|
.Vt MifareTag
|
||||||
can be gathered using the
|
can be gathered using the
|
||||||
.Fn freefare_get_tag_type
|
.Fn freefare_get_tag_type ,
|
||||||
|
.Fn freefare_get_tag_uid
|
||||||
and
|
and
|
||||||
.Fn freefare_get_tag_friendly_name
|
.Fn freefare_get_tag_friendly_name
|
||||||
functions.
|
functions.
|
||||||
|
|
|
@ -148,6 +148,18 @@ freefare_get_tag_friendly_name (MifareTag tag)
|
||||||
return tag->tag_info->friendly_name;
|
return tag->tag_info->friendly_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the UID of the provided tag.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
freefare_get_tag_uid (MifareTag tag)
|
||||||
|
{
|
||||||
|
char *res = malloc (2 * tag->info.szUidLen + 1);
|
||||||
|
for (int i =0; i < tag->info.szUidLen; i++)
|
||||||
|
snprintf (res + 2*i, 3, "%02x", tag->info.abtUid[i]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the provided tag list.
|
* Free the provided tag list.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -54,6 +54,7 @@ typedef unsigned char MifareUltralightPage[4];
|
||||||
MifareTag *freefare_get_tags (nfc_device_t *device);
|
MifareTag *freefare_get_tags (nfc_device_t *device);
|
||||||
enum mifare_tag_type freefare_get_tag_type (MifareTag tag);
|
enum mifare_tag_type freefare_get_tag_type (MifareTag tag);
|
||||||
const char *freefare_get_tag_friendly_name (MifareTag tag);
|
const char *freefare_get_tag_friendly_name (MifareTag tag);
|
||||||
|
char *freefare_get_tag_uid (MifareTag tag);
|
||||||
void freefare_free_tags (MifareTag *tags);
|
void freefare_free_tags (MifareTag *tags);
|
||||||
|
|
||||||
int mifare_ultralight_connect (MifareTag tag);
|
int mifare_ultralight_connect (MifareTag tag);
|
||||||
|
|
|
@ -173,7 +173,7 @@ mifare_classic_connect (MifareTag tag)
|
||||||
ASSERT_MIFARE_CLASSIC (tag);
|
ASSERT_MIFARE_CLASSIC (tag);
|
||||||
|
|
||||||
nfc_target_info_t pnti;
|
nfc_target_info_t pnti;
|
||||||
if (nfc_initiator_select_tag (tag->device, NM_ISO14443A_106, tag->info.abtUid, 4, &pnti)) {
|
if (nfc_initiator_select_tag (tag->device, NM_ISO14443A_106, tag->info.abtUid, tag->info.szUidLen, &pnti)) {
|
||||||
tag->active = 1;
|
tag->active = 1;
|
||||||
} else {
|
} else {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
|
|
|
@ -84,7 +84,7 @@ mifare_ultralight_connect (MifareTag tag)
|
||||||
ASSERT_MIFARE_ULTRALIGHT (tag);
|
ASSERT_MIFARE_ULTRALIGHT (tag);
|
||||||
|
|
||||||
nfc_target_info_t pnti;
|
nfc_target_info_t pnti;
|
||||||
if (nfc_initiator_select_tag (tag->device, NM_ISO14443A_106, tag->info.abtUid, 7, &pnti)) {
|
if (nfc_initiator_select_tag (tag->device, NM_ISO14443A_106, tag->info.abtUid, tag->info.szUidLen, &pnti)) {
|
||||||
tag->active = 1;
|
tag->active = 1;
|
||||||
for (int i = 0; i < MIFARE_ULTRALIGHT_PAGE_COUNT; i++)
|
for (int i = 0; i < MIFARE_ULTRALIGHT_PAGE_COUNT; i++)
|
||||||
MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;
|
MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;
|
||||||
|
|
|
@ -357,3 +357,15 @@ test_mifare_classic_sector_boundaries (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_mifare_classic_get_uid_freefare_get_tag_uid (void)
|
||||||
|
{
|
||||||
|
char *s1 = mifare_classic_get_uid (tag);
|
||||||
|
char *s2 = freefare_get_tag_uid (tag);
|
||||||
|
|
||||||
|
cut_assert_equal_string (s1, s2, cut_message ("UID don't match"));
|
||||||
|
|
||||||
|
free (s1);
|
||||||
|
free (s2);
|
||||||
|
}
|
||||||
|
|
|
@ -153,3 +153,15 @@ test_mifare_ultralight_get_uid (void)
|
||||||
|
|
||||||
free (uid);
|
free (uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_mifare_ultralight_get_uid_freefare_get_tag_uid (void)
|
||||||
|
{
|
||||||
|
char *s1 = mifare_ultralight_get_uid (tag);
|
||||||
|
char *s2 = freefare_get_tag_uid (tag);
|
||||||
|
|
||||||
|
cut_assert_equal_string (s1, s2, cut_message ("UID don't match"));
|
||||||
|
|
||||||
|
free (s1);
|
||||||
|
free (s2);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue