From 4d4a06afcbc6ca1a2056ab2e4973b454eba59de3 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 12 Aug 2010 18:29:31 +0800 Subject: split easytool into multiple files, add database of MRT station names --- easytool/Makefile | 13 +++++++ easytool/data.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ easytool/easycard.h | 13 +++++++ easytool/easytool.c | 38 ++----------------- easytool/utils.c | 23 ++++++++++++ easytool/utils.h | 10 +++++ 6 files changed, 166 insertions(+), 34 deletions(-) create mode 100644 easytool/Makefile create mode 100644 easytool/data.c create mode 100644 easytool/easycard.h create mode 100644 easytool/utils.c create mode 100644 easytool/utils.h diff --git a/easytool/Makefile b/easytool/Makefile new file mode 100644 index 0000000..fc5a5e1 --- /dev/null +++ b/easytool/Makefile @@ -0,0 +1,13 @@ + +CFLAGS=-g -Wall + +all: easytool + +clean: + @rm -f *.o easytool + +easytool: easytool.o data.o utils.o + $(CC) $(LDFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $^ diff --git a/easytool/data.c b/easytool/data.c new file mode 100644 index 0000000..87de407 --- /dev/null +++ b/easytool/data.c @@ -0,0 +1,103 @@ + +#include +#include +#include +#include +#include + +#include "utils.h" +#include "easycard.h" + +/* Taipei MRT station name / ID mapping */ +/* Result of http://web.trtc.com.tw/e/stationdetail.asp?ID=XX */ +const struct value_string taipei_mrt_stn_id[] = { + { 7, "Songshan Airport" }, + { 8, "Zhongshan Junior Highschool" }, + { 9, "Nanjing East Road" }, + { 10, "Zhongxiao Fuxing" }, + { 11, "Daan" }, + { 12, "Technology Building" }, + { 13, "Liuzhangli" }, + { 14, "Linguang" }, + { 15, "Xinhai" }, + { 16, "Wanfang Hospital" }, + { 17, "Wanfang Community" }, + { 18, "Muzha" }, + { 19, "Taipei Zoo" }, + { 21, "Dazhi" }, + { 22, "Jiannan Road" }, + { 23, "Xihu" }, + { 24, "Gangquian" }, + { 25, "Wende" }, + { 26, "Neihu" }, + { 27, "Dahu Park" }, + { 28, "Huzhou" }, + { 29, "Donghu" }, + { 30, "Nangang Software Park" }, + { 31, "Nangang Exhibition Center" }, + { 32, "Xiaobitan" }, + { 33, "Xindian" }, + { 34, "Xindian City Office" }, + { 35, "Quizhang" }, + { 36, "Dapinglin" }, + { 37, "Jingmei" }, + { 38, "Wanlong" }, + { 39, "Gongguan" }, + { 40, "Taipower Building" }, + { 41, "Guting" }, + { 42, "CKS Memorial Hall" }, + { 43, "Xiaonanmen" }, + { 45, "Dingxi" }, + { 46, "Yongan Market" }, + { 47, "Jingan" }, + { 48, "Nanshijiao" }, + { 50, "NTU Hospital" }, + { 51, "Taipei Main Station" }, + { 53, "Zhongshan" }, + { 54, "Shuanglian" }, + { 55, "Minquan West Road" }, + { 56, "Yuanshan" }, + { 57, "Jiantan" }, + { 58, "Shilin" }, + { 59, "Zhishan" }, + { 60, "Mingde" }, + { 61, "Shipai" }, + { 62, "Qilan" }, + { 63, "Qiyan" }, + { 64, "Beitou" }, + { 65, "Xinbeitou" }, + { 66, "Fuxinggang" }, + { 67, "Zhongyi" }, + { 68, "Guandu" }, + { 69, "Zhuwei" }, + { 70, "Hongshulin" }, + { 71, "Danshui" }, + { 77, "Yongning" }, + { 78, "Tucheng" }, + { 79, "Haishan" }, + { 80, "Far Eastern Hospital" }, + { 81, "Fuzhong" }, + { 82, "Banqiao" }, + { 83, "Xinpu" }, + { 84, "Jiangzicui" }, + { 85, "Longshan Temple" }, + { 86, "Ximen" }, + { 88, "Shandao Temple" }, + { 89, "Zhongxiao Xinsheng" }, + { 91, "Zhongxiao Dunhua" }, + { 92, "SYS Memorial Hall" }, + { 93, "Taipei City Hall" }, + { 94, "Yongchun" }, + { 95, "Houshanpi" }, + { 96, "Kunyang" }, + { 97, "Nangang" }, + { 0, NULL } +}; + +/* Easycard Transaction Type names */ +const struct value_string easy_tt_names[] = { + { EASY_TT_MRT_ENTER, "Enter MRT Stn" }, + { EASY_TT_MRT_EXIT, "Leave MRT Stn" }, + { EASY_TT_PURCHASE, "Shop Purchase" }, + { 0, NULL } +}; diff --git a/easytool/easycard.h b/easytool/easycard.h new file mode 100644 index 0000000..b4d4afc --- /dev/null +++ b/easytool/easycard.h @@ -0,0 +1,13 @@ +#ifndef EASYCARD_H +#define EASYCARD_H + +#include "utils.h" + +#define EASY_TT_MRT_ENTER 0x00 +#define EASY_TT_MRT_EXIT 0x11 +#define EASY_TT_PURCHASE 0x20 + +extern const struct value_string easy_tt_names[]; +extern const struct value_string taipei_mrt_stn_id[]; + +#endif /* EASYCARD_H */ diff --git a/easytool/easytool.c b/easytool/easytool.c index 5a77997..52a6c53 100644 --- a/easytool/easytool.c +++ b/easytool/easytool.c @@ -10,30 +10,12 @@ #include #include +#include + #include #include -struct value_string { - unsigned int value; - const char *str; -}; - -static char namebuf[255]; -const char *get_value_string(const struct value_string *vs, uint32_t val) -{ - int i; - - for (i = 0;; i++) { - if (vs[i].value == 0 && vs[i].str == NULL) - break; - if (vs[i].value == val) - return vs[i].str; - } - - snprintf(namebuf, sizeof(namebuf), "unknown 0x%x", val); - return namebuf; -} - +#include "easycard.h" struct { int fd; @@ -85,17 +67,6 @@ static void parse_acc_bits(struct acc_bits_parsed *abp, uint8_t *acc_bits) } } -#define EASY_TT_MRT_ENTER 0x00 -#define EASY_TT_MRT_EXIT 0x11 -#define EASY_TT_PURCHASE 0x20 - -struct value_string easy_tt_names[] = { - { EASY_TT_MRT_ENTER, "Enter MRT Stn" }, - { EASY_TT_MRT_EXIT, "Leave MRT Stn" }, - { EASY_TT_PURCHASE, "Shop Purchase" }, - { 0, NULL } -}; - /* storage of a transaction log record on the transponder itself */ struct easy_log_rec { uint8_t unknown[2]; @@ -122,7 +93,7 @@ static void dump_easy_log(const struct easy_log_rec *elr) elr->amount, elr->remaining); } -static dump_mfcl(mifare_tag *mft) +static void dump_mfcl(mifare_tag *mft) { unsigned int sect; @@ -150,7 +121,6 @@ static dump_mfcl(mifare_tag *mft) } } - int main(int argc, char **argv) { struct stat st; diff --git a/easytool/utils.c b/easytool/utils.c new file mode 100644 index 0000000..ab8fb72 --- /dev/null +++ b/easytool/utils.c @@ -0,0 +1,23 @@ + +#include +#include +#include +#include + +#include "utils.h" + +static char namebuf[255]; +const char *get_value_string(const struct value_string *vs, uint32_t val) +{ + int i; + + for (i = 0;; i++) { + if (vs[i].value == 0 && vs[i].str == NULL) + break; + if (vs[i].value == val) + return vs[i].str; + } + + snprintf(namebuf, sizeof(namebuf), "unknown 0x%x", val); + return namebuf; +} diff --git a/easytool/utils.h b/easytool/utils.h new file mode 100644 index 0000000..ee446cd --- /dev/null +++ b/easytool/utils.h @@ -0,0 +1,10 @@ +#ifndef UTILS_H +#define UTILS_H + +struct value_string { + unsigned int value; + const char *str; +}; +const char *get_value_string(const struct value_string *vs, uint32_t val); + +#endif -- cgit v1.2.3