Make MAD Application Identifiers (AID) structure public as MadAid.

- Changed mad_get_aid() and mad_set_aid() ABI;
  - Update unit test;
This commit is contained in:
Romain Tartiere 2009-12-21 03:02:15 +00:00
parent 00ca4579c9
commit c7b8574e23
3 changed files with 35 additions and 28 deletions

29
mad.c
View file

@ -32,21 +32,16 @@
#include <mad.h>
struct aid {
uint8_t function_cluster_code;
uint8_t application_code;
};
struct mad_sector_0x00 {
uint8_t crc;
uint8_t info;
struct aid aids[15];
MadAid aids[15];
};
struct mad_sector_0x10 {
uint8_t crc;
uint8_t info;
struct aid aids[23];
MadAid aids[23];
};
struct mad {
@ -289,7 +284,7 @@ mad_set_card_publisher_sector(Mad mad, MifareSectorNumber cps)
* Get the provided sector's application identifier.
*/
int
mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code, uint8_t *application_code)
mad_get_aid(Mad mad, MifareSectorNumber sector, MadAid *aid)
{
if (sector > 0x27) {
errno = EINVAL;
@ -302,11 +297,11 @@ mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code,
return -1;
}
*function_cluster_code = mad->sector_0x10.aids[sector - 0x0f - 1].function_cluster_code;
*application_code = mad->sector_0x10.aids[sector - 0x0f - 1].application_code;
aid->function_cluster_code = mad->sector_0x10.aids[sector - 0x0f - 1].function_cluster_code;
aid->application_code = mad->sector_0x10.aids[sector - 0x0f - 1].application_code;
} else {
*function_cluster_code = mad->sector_0x00.aids[sector - 1].function_cluster_code;
*application_code = mad->sector_0x00.aids[sector - 1].application_code;
aid->function_cluster_code = mad->sector_0x00.aids[sector - 1].function_cluster_code;
aid->application_code = mad->sector_0x00.aids[sector - 1].application_code;
}
return 0;
@ -316,7 +311,7 @@ mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code,
* Set the provided sector's application identifier.
*/
int
mad_set_aid(Mad mad, MifareSectorNumber sector, uint8_t function_cluster_code, uint8_t application_code)
mad_set_aid(Mad mad, MifareSectorNumber sector, MadAid aid)
{
if (sector > 0x27) {
errno = EINVAL;
@ -328,11 +323,11 @@ mad_set_aid(Mad mad, MifareSectorNumber sector, uint8_t function_cluster_code, u
errno = EINVAL;
return -1;
}
mad->sector_0x00.aids[sector - 0x0f - 1].function_cluster_code = function_cluster_code;
mad->sector_0x00.aids[sector - 0x0f - 1].application_code = application_code;
mad->sector_0x00.aids[sector - 0x0f - 1].function_cluster_code = aid.function_cluster_code;
mad->sector_0x00.aids[sector - 0x0f - 1].application_code = aid.application_code;
} else {
mad->sector_0x00.aids[sector - 1].function_cluster_code = function_cluster_code;
mad->sector_0x00.aids[sector - 1].application_code = application_code;
mad->sector_0x00.aids[sector - 1].function_cluster_code = aid.function_cluster_code;
mad->sector_0x00.aids[sector - 1].application_code = aid.application_code;
}
return 0;

10
mad.h
View file

@ -23,6 +23,12 @@
typedef uint8_t MifareSectorNumber;
struct mad_aid {
uint8_t function_cluster_code;
uint8_t application_code;
};
typedef struct mad_aid MadAid;
struct mad;
typedef struct mad *Mad;
@ -33,8 +39,8 @@ int mad_get_version (Mad mad);
void mad_set_version (Mad mad, uint8_t version);
MifareSectorNumber mad_get_card_publisher_sector(Mad mad);
int mad_set_card_publisher_sector(Mad mad, MifareSectorNumber cps);
int mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code, uint8_t *application_code);
int mad_set_aid(Mad mad, MifareSectorNumber sector, uint8_t function_cluster_code, uint8_t application_code);
int mad_get_aid(Mad mad, MifareSectorNumber sector, MadAid *aid);
int mad_set_aid(Mad mad, MifareSectorNumber sector, MadAid aid);
void mad_free (Mad mad);
#endif /* !__MIFARE_APPLICATION_DIRECTORY_H__ */

View file

@ -23,19 +23,25 @@ DEFINE_TEST(mad)
assertEqualInt (res, -1);
assertEqualInt (13, mad_get_card_publisher_sector (mad));
uint8_t fcc, ac;
res = mad_get_aid (mad, 3, &fcc, &ac);
assertEqualInt (res, 0);
assertEqualInt (fcc, 0);
assertEqualInt (ac, 0);
MadAid aid = {
.function_cluster_code = 0,
.application_code = 0
};
res = mad_set_aid (mad, 3, 0xc0, 0x42);
res = mad_get_aid (mad, 3, &aid);
assertEqualInt (res, 0);
assertEqualInt (aid.function_cluster_code, 0);
assertEqualInt (aid.application_code, 0);
aid.function_cluster_code = 0xc0;
aid.application_code = 0x42;
res = mad_set_aid (mad, 3, aid);
assertEqualInt (res, 0);
res = mad_get_aid (mad, 3, &fcc, &ac);
res = mad_get_aid (mad, 3, &aid);
assertEqualInt (res, 0);
assertEqualInt (fcc, 0xc0);
assertEqualInt (ac, 0x42);
assertEqualInt (aid.function_cluster_code, 0xc0);
assertEqualInt (aid.application_code, 0x42);
mad_free (mad);
}