summaryrefslogtreecommitdiff
path: root/easytool
diff options
context:
space:
mode:
Diffstat (limited to 'easytool')
-rw-r--r--easytool/data.c1
-rw-r--r--easytool/easycard.c2
-rw-r--r--easytool/easycard.h1
-rw-r--r--easytool/easytool.c81
4 files changed, 77 insertions, 8 deletions
diff --git a/easytool/data.c b/easytool/data.c
index 9b20930..425f0f2 100644
--- a/easytool/data.c
+++ b/easytool/data.c
@@ -118,6 +118,7 @@ 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" },
+ { EASY_TT_BUS, "Bus ride" },
{ EASY_TT_MRT_REENTER, "ReEnter MRT" },
{ EASY_TT_MRT_EXIT, "Leave MRT" },
{ EASY_TT_PURCHASE, "Shop Purchase" },
diff --git a/easytool/easycard.c b/easytool/easycard.c
index 980735d..a98c280 100644
--- a/easytool/easycard.c
+++ b/easytool/easycard.c
@@ -52,7 +52,7 @@ time_t easy_timestamp2time(const uint8_t *easy_ts)
int easy_update_log_rec(struct easy_log_rec *elr, int16_t delta)
{
int32_t sum = elr->amount + delta;
- int32_t remaining = elr->remaining = delta;
+ int32_t remaining = elr->remaining + delta;
if ((sum < 0 || sum > 0xffff) ||
(remaining < 0 || remaining > 0xffff))
diff --git a/easytool/easycard.h b/easytool/easycard.h
index 8979524..1631c60 100644
--- a/easytool/easycard.h
+++ b/easytool/easycard.h
@@ -6,6 +6,7 @@
#include "utils.h"
#define EASY_TT_MRT_ENTER 0x00
+#define EASY_TT_BUS 0x01
#define EASY_TT_MRT_REENTER 0x80
#define EASY_TT_MRT_EXIT 0x11
#define EASY_TT_PURCHASE 0x20
diff --git a/easytool/easytool.c b/easytool/easytool.c
index 67157c8..c504003 100644
--- a/easytool/easytool.c
+++ b/easytool/easytool.c
@@ -27,6 +27,7 @@
#include <fcntl.h>
#include <string.h>
#include <time.h>
+#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -41,16 +42,24 @@
/* Easycard specific includes */
#include "easycard.h"
-#define VERSION "0.03"
+#define VERSION "0.04"
#define COPYRIGHT \
"EasyTool "VERSION" (C) 2010 by Harald Welte <laforge@gnumonks.org>\n" \
"This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n" \
"Use of this software is authorized for RESEARCH PURPOSE ONLY!\n\n"
+enum mode {
+ MODE_DUMP_MFACC,
+ MODE_DUMP,
+ MODE_RECHARGE,
+ MODE_PURCHASE,
+};
+
struct {
int fd;
unsigned long size;
mifare_tag *mft;
+ enum mode mode;
} global;
static void dump_acc_bits(const struct acc_bits_parsed *abp)
@@ -128,17 +137,59 @@ static void print_help(void)
int main(int argc, char **argv)
{
struct stat st;
+ int delta = 0;
+ int option_index = 0;
+ int rc;
+ int prot, flags = O_RDONLY;
+
+ global.mode = MODE_DUMP;
printf(COPYRIGHT);
- if (argc < 2) {
+ while (1) {
+ int c;
+ static struct option long_options[] = {
+ { "dump-access-bits", 0, 0, 'a' },
+ { "alter-recharge", 1, 0, 'r' },
+ { "alter-purchase", 1, 0, 'p' },
+ { "help", 0, 0, 'h' },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "r:p:ha",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'a':
+ global.mode = MODE_DUMP_MFACC;
+ break;
+ case 'r':
+ global.mode = MODE_RECHARGE;
+ flags = O_RDWR;
+ delta = atoi(optarg);
+ break;
+ case 'p':
+ global.mode = MODE_PURCHASE;
+ flags = O_RDWR;
+ delta = atoi(optarg);
+ break;
+ case 'h':
+ print_help();
+ exit(0);
+ break;
+ }
+ };
+
+ if (argc <= optind) {
fprintf(stderr, "ERROR: You must specify the file name of "
"a mifare dump file (.mfd)\n");
print_help();
exit(2);
}
- global.fd = open(argv[1], O_RDONLY);
+ global.fd = open(argv[optind], flags);
if (global.fd < 0) {
perror("Error opening the MFD file");
exit(1);
@@ -148,15 +199,31 @@ int main(int argc, char **argv)
exit(1);
}
global.size = st.st_size;
- global.mft = mmap(NULL, global.size, PROT_READ, MAP_SHARED,
- global.fd, 0);
+
+ prot = PROT_READ;
+ if (flags == O_RDWR)
+ prot |= PROT_WRITE;
+
+ global.mft = mmap(NULL, global.size, prot, MAP_SHARED, global.fd, 0);
if (!global.mft) {
perror("Error mmap()ing the MFD file");
exit(1);
}
- //dump_mfcl(global.mft);
- dump_easycard(global.mft);
+ switch (global.mode) {
+ case MODE_DUMP_MFACC:
+ dump_mfcl(global.mft);
+ break;
+ case MODE_DUMP:
+ dump_easycard(global.mft);
+ break;
+ case MODE_RECHARGE:
+ rc = easy_alter_last_recharge(global.mft, delta);
+ break;
+ case MODE_PURCHASE:
+ rc = easy_alter_last_purchase(global.mft, delta);
+ break;
+ }
munmap(global.mft, global.size);
close(global.fd);
personal git repositories of Harald Welte. Your mileage may vary