summaryrefslogtreecommitdiff
path: root/easytool
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-08-12 20:09:10 +0800
committerHarald Welte <laforge@gnumonks.org>2010-08-12 20:09:10 +0800
commit988d75ffc49df8f0b27c940d16b3d7713e0361f3 (patch)
tree67037122e65764907a6e1b9610846603ee9c480f /easytool
parent138096b4d2595818f0c14776e46a06cfc3395f6c (diff)
add printing of card UID/number and date of issue
Diffstat (limited to 'easytool')
-rw-r--r--easytool/easytool.c62
1 files changed, 48 insertions, 14 deletions
diff --git a/easytool/easytool.c b/easytool/easytool.c
index b2436c6..efb083f 100644
--- a/easytool/easytool.c
+++ b/easytool/easytool.c
@@ -89,6 +89,12 @@ static void parse_acc_bits(struct acc_bits_parsed *abp, uint8_t *acc_bits)
}
}
+struct easy_block2sec0 {
+ uint8_t unknown[6];
+ uint8_t timestamp[3];
+ uint8_t unknown2[7];
+} __attribute__ ((packed));
+
/* storage of a transaction log record on the transponder itself */
struct easy_log_rec {
uint8_t trans_id;
@@ -103,18 +109,28 @@ struct easy_log_rec {
uint8_t unknown3[2];
} __attribute__ ((packed));
-static time_t convert_timestamp(const uint8_t *easy_ts)
+static time_t easy_timestamp2time(const uint8_t *easy_ts)
{
return (easy_ts[2] << 16 | easy_ts[1] << 8 | easy_ts[0]) << 8;
}
-static void dump_easy_log(const struct easy_log_rec *elr)
+static char tsbuf[64];
+char *easy_asc_timestamp(const uint8_t *timestamp)
{
- time_t t_time = convert_timestamp(elr->timestamp);
+ time_t t_time = easy_timestamp2time(timestamp);
struct tm *t_tm = gmtime(&t_time);
- printf("%4u-%02u-%02u %02u:%02u | %02x | %10s | Paid %4u NTD | %4u NTD remaining\n",
+ memset(tsbuf, 0, sizeof(tsbuf));
+ snprintf(tsbuf, sizeof(tsbuf), "%4u-%02u-%02u %02u:%02u",
t_tm->tm_year+1900, t_tm->tm_mon+1, t_tm->tm_mday,
- t_tm->tm_hour, t_tm->tm_min, elr->trans_id,
+ t_tm->tm_hour, t_tm->tm_min);
+ return tsbuf;
+}
+
+static void dump_easy_log(const struct easy_log_rec *elr)
+{
+ printf("%s | %02x | %10s | Paid %4u NTD | %4u NTD remaining\n",
+ easy_asc_timestamp(elr->timestamp),
+ elr->trans_id,
get_value_string(easy_tt_names, elr->trans_type),
elr->amount, elr->remaining);
switch (elr->trans_type) {
@@ -140,17 +156,34 @@ static void dump_mfcl(mifare_tag *mft)
unsigned int block_base = sect * 4;
uint8_t *access_bits = mft->amb[block_base+3].mbt.abtAccessBits;
struct acc_bits_parsed abp;
- int i;
printf("Sector %02u (base: 0x%02x) Access bits: 0x%08x\n", sect,
sect*4*16, ntohl(*((uint32_t *) access_bits)));
- //parse_acc_bits(&abp, access_bits);
- //dump_acc_bits(&abp);
- if (sect == 3 || sect == 4) {
- for (i = 0; i < 3; i++) {
- void *data = mft->amb[block_base+i].mbd.abtData;
- dump_easy_log(data);
- }
+ parse_acc_bits(&abp, access_bits);
+ dump_acc_bits(&abp);
+ }
+}
+
+static void dump_easycard(mifare_tag *mft)
+{
+ unsigned int sect;
+ mifare_block_manufacturer *manuf = &mft->amb[0].mbm;
+ struct easy_block2sec0 *b2s0 = mft->amb[4].mbd.abtData;
+ uint32_t uid = ntohl(*((uint32_t *) manuf->abtUID));
+
+ /* dump the header */
+ printf("EasyCard UID 0x%08x (%u)\n", uid, uid);
+ printf("Date of manufacture: %s\n",
+ easy_asc_timestamp(b2s0->timestamp));
+
+ /* dump the transaction log */
+ for (sect = 3; sect <=4; sect++) {
+ unsigned int block_base = sect * 4;
+ uint8_t *access_bits = mft->amb[block_base+3].mbt.abtAccessBits;
+ unsigned int i;
+ for (i = 0; i < 3; i++) {
+ void *data = mft->amb[block_base+i].mbd.abtData;
+ dump_easy_log(data);
}
}
}
@@ -176,7 +209,8 @@ int main(int argc, char **argv)
exit(1);
}
- dump_mfcl(global.mft);
+ //dump_mfcl(global.mft);
+ dump_easycard(global.mft);
munmap(global.mft, global.size);
close(global.fd);
personal git repositories of Harald Welte. Your mileage may vary