summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-08-15 11:11:27 +0800
committerHarald Welte <laforge@gnumonks.org>2010-08-15 11:11:27 +0800
commit43efa12e9fb6df6320ffb7e261145d313f19d1f3 (patch)
tree900a638ef7c217387082c27af9004fbc30feae9b
parentab6aa10e6625bca5f15f9de775ff7dc51eb825a7 (diff)
print full transaction log, including recharge-section, better formatting
-rw-r--r--easytool/data.c6
-rw-r--r--easytool/easycard.c61
-rw-r--r--easytool/easycard.h6
-rw-r--r--easytool/easytool.c31
-rw-r--r--easytool/mifare_classic.h6
-rw-r--r--easytool/utils.h2
6 files changed, 79 insertions, 33 deletions
diff --git a/easytool/data.c b/easytool/data.c
index 35897d5..9b20930 100644
--- a/easytool/data.c
+++ b/easytool/data.c
@@ -117,9 +117,9 @@ const struct value_string taipei_mrt_stn_id[] = {
/* Easycard Transaction Type names */
const struct value_string easy_tt_names[] = {
- { EASY_TT_MRT_ENTER, "Enter MRT Stn" },
- { EASY_TT_MRT_REENTER, "ReEnter MRT Stn" },
- { EASY_TT_MRT_EXIT, "Leave MRT Stn" },
+ { EASY_TT_MRT_ENTER, "Enter MRT" },
+ { EASY_TT_MRT_REENTER, "ReEnter MRT" },
+ { EASY_TT_MRT_EXIT, "Leave MRT" },
{ EASY_TT_PURCHASE, "Shop Purchase" },
{ EASY_TT_RECHARGE, "Recharge" },
{ 0, NULL }
diff --git a/easytool/easycard.c b/easytool/easycard.c
index 1f9572d..26a1430 100644
--- a/easytool/easycard.c
+++ b/easytool/easycard.c
@@ -88,3 +88,64 @@ char *easy_asc_timestamp(const uint8_t *timestamp)
return tsbuf;
}
+static const struct mfcl_addr easy_trans_log_addrs[] = {
+ { .sector = 2, .block = 2, },
+
+ /* first block of sector 3 is not a log record */
+ { .sector = 3, .block = 1, },
+ { .sector = 3, .block = 2, },
+
+ { .sector = 4, .block = 0, },
+ { .sector = 4, .block = 1, },
+ { .sector = 4, .block = 2, },
+
+ { .sector = 5, .block = 0, },
+ { .sector = 5, .block = 1, },
+ { .sector = 5, .block = 2, },
+};
+
+void easy_dump_log_rec(const struct easy_log_rec *elr)
+{
+ /* Skip empty records */
+ if (!elr->timestamp)
+ return;
+
+ printf("%s | %02x | %4u NTD | %4u NTD | %-15s",
+ easy_asc_timestamp(elr->timestamp),
+ elr->trans_id, elr->amount, elr->remaining,
+ get_value_string(easy_tt_names, elr->trans_type));
+ switch (elr->trans_type) {
+ case EASY_TT_MRT_ENTER:
+ case EASY_TT_MRT_REENTER:
+ case EASY_TT_MRT_EXIT:
+ case EASY_TT_RECHARGE:
+ printf(" | %s\n",
+ get_value_string(taipei_mrt_stn_id,
+ elr->station_code));
+ break;
+ default:
+ printf("\n");
+ }
+}
+
+void easy_dump_log(mifare_tag *mft)
+{
+ unsigned int i;
+
+ /* "2010-01-01 01:01 | TID| Amount | Balance | */
+ puts("Timestamp | TID| Amount | Balance | Type | MRT Station");
+ puts("---------------------------------------------------------------------------");
+
+ for (i = 0; i < ARRAY_SIZE(easy_trans_log_addrs); i++) {
+ unsigned int sect = easy_trans_log_addrs[i].sector;
+ unsigned int block = easy_trans_log_addrs[i].block;
+ unsigned int block_base = sect * 4;
+ void *data = mft->amb[block_base+block].mbd.abtData;
+
+#if 0
+ printf("Dumping Sector %u Block %u (0x%x)\n", sect, block,
+ (block_base+sect)*16);
+#endif
+ easy_dump_log_rec(data);
+ }
+}
diff --git a/easytool/easycard.h b/easytool/easycard.h
index b47dee9..fb4d93d 100644
--- a/easytool/easycard.h
+++ b/easytool/easycard.h
@@ -44,10 +44,16 @@ struct easy_log_rec {
} __attribute__ ((packed));
time_t easy_timestamp2time(const uint8_t *easy_ts);
+char *easy_asc_timestamp(const uint8_t *timestamp);
/* apply a telta (positive or negative) to a EasyCard log record */
int easy_update_log_rec(struct easy_log_rec *elr, int16_t delta);
/* apply a delta to the 'sum of day' record in Sector 15 Block 2 */
int easy_update_sum_of_day(struct easy_sect15blk2 *s15b2, int16_t delta);
+void easy_dump_log_rec(const struct easy_log_rec *elr);
+
+typedef mifare_tag;
+void easy_dump_log(mifare_tag *mft);
+
#endif /* EASYCARD_H */
diff --git a/easytool/easytool.c b/easytool/easytool.c
index 35735fa..cb9fe30 100644
--- a/easytool/easytool.c
+++ b/easytool/easytool.c
@@ -54,24 +54,6 @@ struct {
mifare_tag *mft;
} global;
-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) {
- case EASY_TT_MRT_ENTER:
- case EASY_TT_MRT_REENTER:
- case EASY_TT_MRT_EXIT:
- printf("\tMRT Station %s\n",
- get_value_string(taipei_mrt_stn_id,
- elr->station_code));
- break;
- }
-}
-
static void dump_acc_bits(const struct acc_bits_parsed *abp)
{
uint8_t block;
@@ -107,7 +89,6 @@ static void dump_mfcl(mifare_tag *mft)
static void dump_easycard(mifare_tag *mft)
{
- unsigned int sect;
mifare_block_manufacturer *manuf = &mft->amb[0].mbm;
struct mfcl_value_block *val =
(struct mfcl_value_block *) mft->amb[8].mbd.abtData;
@@ -127,17 +108,7 @@ static void dump_easycard(mifare_tag *mft)
printf("\nTransaction Log:\n");
/* dump the transaction log */
- for (sect = 3; sect < 6; sect++) {
- unsigned int block_base = sect * 4;
- unsigned int i;
- for (i = 0; i < 3; i++) {
- void *data = mft->amb[block_base+i].mbd.abtData;
- /* first block of sector 3 is not a log record */
- if (sect == 3 && i == 0)
- continue;
- dump_easy_log(data);
- }
- }
+ easy_dump_log(mft);
}
static void print_help(void)
diff --git a/easytool/mifare_classic.h b/easytool/mifare_classic.h
index f04f32f..d27a34e 100644
--- a/easytool/mifare_classic.h
+++ b/easytool/mifare_classic.h
@@ -21,4 +21,10 @@ struct mfcl_value_block {
uint8_t addr[4];
} __attribute__ ((packed));
+struct mfcl_addr {
+ uint8_t sector;
+ uint8_t block;
+};
+
+
#endif
diff --git a/easytool/utils.h b/easytool/utils.h
index ee446cd..0ff0ad7 100644
--- a/easytool/utils.h
+++ b/easytool/utils.h
@@ -1,6 +1,8 @@
#ifndef UTILS_H
#define UTILS_H
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
struct value_string {
unsigned int value;
const char *str;
personal git repositories of Harald Welte. Your mileage may vary