summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-08-16 13:05:13 +0800
committerHarald Welte <laforge@gnumonks.org>2010-08-16 13:05:13 +0800
commitcd534f500edd5c04fc8e68e72eae3264dfef34fd (patch)
tree715e8a27aa1330795e89adf0b6c1b207a616b87a
parent1214269f6f7ab7e8ad705ad6c990afa23284eb29 (diff)
easytool: ad getopt option parser
-rw-r--r--easytool/easytool.c63
1 files changed, 59 insertions, 4 deletions
diff --git a/easytool/easytool.c b/easytool/easytool.c
index 67157c8..75cec83 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>
@@ -125,20 +126,64 @@ static void print_help(void)
{
}
+enum mode {
+ MODE_DUMP_MFACC,
+ MODE_DUMP,
+ MODE_RECHARGE,
+ MODE_PURCHASE,
+};
+
int main(int argc, char **argv)
{
+ enum mode mode = MODE_DUMP;
+ int delta = 0;
+ int option_index = 0;
struct stat st;
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':
+ mode = MODE_DUMP_MFACC;
+ break;
+ case 'r':
+ mode = MODE_RECHARGE;
+ delta = atoi(optarg);
+ break;
+ case 'p':
+ mode = MODE_PURCHASE;
+ 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], O_RDONLY);
if (global.fd < 0) {
perror("Error opening the MFD file");
exit(1);
@@ -155,8 +200,18 @@ int main(int argc, char **argv)
exit(1);
}
- //dump_mfcl(global.mft);
- dump_easycard(global.mft);
+ switch (mode) {
+ case MODE_DUMP_MFACC:
+ dump_mfcl(global.mft);
+ break;
+ case MODE_DUMP:
+ dump_easycard(global.mft);
+ break;
+ case MODE_RECHARGE:
+ break;
+ case MODE_PURCHASE:
+ break;
+ }
munmap(global.mft, global.size);
close(global.fd);
personal git repositories of Harald Welte. Your mileage may vary