|
@@ -4,6 +4,7 @@
|
|
|
|
|
|
#include <nfc/nfc.h>
|
|
#include <nfc/nfc.h>
|
|
#include <freefare.h>
|
|
#include <freefare.h>
|
|
|
|
+#include "color.h"
|
|
|
|
|
|
MifareClassicKey SecretKey[] = { 0x00, 0x01, 0x31, 0xB9, 0x3F, 0x28 };
|
|
MifareClassicKey SecretKey[] = { 0x00, 0x01, 0x31, 0xB9, 0x3F, 0x28 };
|
|
MifareClassicBlock data_read4;
|
|
MifareClassicBlock data_read4;
|
|
@@ -26,52 +27,55 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
|
|
|
|
|
|
nfc_init(&context);
|
|
nfc_init(&context);
|
|
if(context == NULL) {
|
|
if(context == NULL) {
|
|
- printf("[x] Unable to init libnf\n");
|
|
|
|
|
|
+ printf("[x] Unable to init libnfc !\n");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
pnd = nfc_open(context, NULL);
|
|
pnd = nfc_open(context, NULL);
|
|
if (pnd == NULL) {
|
|
if (pnd == NULL) {
|
|
- printf("[x] Unable to open NFC device\n");
|
|
|
|
|
|
+ printf("[x] Unable to open NFC device !\n");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
- printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
|
|
|
|
-
|
|
|
|
- //tags = freefare_get_tags(pnd);
|
|
|
|
- while(!tags) {
|
|
|
|
- printf("Hey, i'm Waiting for my tag...\n");
|
|
|
|
|
|
+
|
|
|
|
+ tags = freefare_get_tags(pnd);
|
|
|
|
+ printf("NFC reader: "ANSI_COLOR_GREEN"%s"ANSI_COLOR_RESET" opened and waiting for a tag\n", nfc_device_get_name(pnd));
|
|
|
|
+
|
|
|
|
+ while(*tags == NULL) {
|
|
|
|
+ printf(".");
|
|
|
|
+ fflush(stdout);
|
|
sleep(1);
|
|
sleep(1);
|
|
tags = freefare_get_tags(pnd);
|
|
tags = freefare_get_tags(pnd);
|
|
}
|
|
}
|
|
|
|
+ printf("\n");
|
|
|
|
|
|
for(i=0; tags[i]; i++) {
|
|
for(i=0; tags[i]; i++) {
|
|
switch(freefare_get_tag_type(tags[i])) {
|
|
switch(freefare_get_tag_type(tags[i])) {
|
|
case MIFARE_CLASSIC_1K:
|
|
case MIFARE_CLASSIC_1K:
|
|
- printf("=> Tag number %u with UID %s type Mifare 1k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
|
|
|
|
|
|
+ printf("=> Tag number "ANSI_COLOR_YELLOW"%u"ANSI_COLOR_RESET" with UID "ANSI_COLOR_YELLOW"%s"ANSI_COLOR_RESET" type Mifare 1k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
|
|
break;
|
|
break;
|
|
|
|
|
|
case MIFARE_MINI:
|
|
case MIFARE_MINI:
|
|
- printf("=> Tag number %u with UID %s type Mifare Mini 0.3k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
|
|
|
|
|
|
+ printf("=> Tag number "ANSI_COLOR_YELLOW"%u"ANSI_COLOR_RESET" with UID "ANSI_COLOR_YELLOW"%s"ANSI_COLOR_RESET" type Mifare Mini 0.3k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
- printf("[x] Wrong tag Mr Dugland !\n");
|
|
|
|
|
|
+ printf(ANSI_COLOR_RED"[x] Wrong tag Mr Dugland !\n"ANSI_COLOR_RESET);
|
|
break;
|
|
break;
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- printf("=> Trying to authenticate with SecretKey %.2x %.2x %.2x %.2x %.2x %.2x ...\n", SecretKey[0][0], SecretKey[0][1], SecretKey[0][2], SecretKey[0][3], SecretKey[0][4], SecretKey[0][5]);
|
|
|
|
|
|
+ printf("=> Trying to authenticate with SecretKey "ANSI_COLOR_YELLOW"%.2x %.2x %.2x %.2x %.2x %.2x"ANSI_COLOR_RESET" ...\n", SecretKey[0][0], SecretKey[0][1], SecretKey[0][2], SecretKey[0][3], SecretKey[0][4], SecretKey[0][5]);
|
|
|
|
|
|
if(mifare_classic_connect(tags[i]) == OPERATION_OK) {
|
|
if(mifare_classic_connect(tags[i]) == OPERATION_OK) {
|
|
- printf("=> Mifare tag connected !\n");
|
|
|
|
|
|
+ printf(ANSI_COLOR_GREEN"=> Mifare tag connected !\n"ANSI_COLOR_RESET);
|
|
}
|
|
}
|
|
- else printf("Non ca chie dans la colle mais grave, ton tag est moisi\n");
|
|
|
|
|
|
+ else printf(ANSI_COLOR_RED"Non ca chie dans la colle mais grave, ton tag est moisi\n"ANSI_COLOR_RESET);
|
|
|
|
|
|
if(mifare_classic_authenticate(tags[i], 5, SecretKey[0], MFC_KEY_A) == OPERATION_OK) {
|
|
if(mifare_classic_authenticate(tags[i], 5, SecretKey[0], MFC_KEY_A) == OPERATION_OK) {
|
|
- printf("=> Tag authenticated !\n");
|
|
|
|
|
|
+ printf(ANSI_COLOR_GREEN"=> Tag authenticated !\n"ANSI_COLOR_RESET);
|
|
}
|
|
}
|
|
- else printf("Non ca chie dans la colle mais grave, check ta clé\n");
|
|
|
|
|
|
+ else printf(ANSI_COLOR_RED"Non ca chie dans la colle mais grave, check ta clé\n"ANSI_COLOR_RESET);
|
|
|
|
|
|
if(coins != 0 && buy_date != NULL && expire_date != NULL) {
|
|
if(coins != 0 && buy_date != NULL && expire_date != NULL) {
|
|
|
|
|
|
@@ -99,9 +103,10 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
|
|
|
|
|
|
if(mifare_classic_write(tags[i], 5, &data_read5) == OPERATION_OK) {
|
|
if(mifare_classic_write(tags[i], 5, &data_read5) == OPERATION_OK) {
|
|
if(mifare_classic_read(tags[i], 5, &data_read5) == OPERATION_OK) {
|
|
if(mifare_classic_read(tags[i], 5, &data_read5) == OPERATION_OK) {
|
|
- printf("=> %.2d credits found now !\n", data_read5[7]);
|
|
|
|
|
|
+ printf("=> "ANSI_COLOR_GREEN"%.2d"ANSI_COLOR_RESET" credits found now !\n", data_read5[7]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ printf("Reading a second time to check...\n");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -109,12 +114,12 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
|
|
&&
|
|
&&
|
|
(mifare_classic_read(tags[i], 4, &data_read4) == OPERATION_OK) )
|
|
(mifare_classic_read(tags[i], 4, &data_read4) == OPERATION_OK) )
|
|
{
|
|
{
|
|
- printf(" => INFOS\n");
|
|
|
|
- printf(" => Company Serial :\t%.2x %.2x %.2x %.2x\n", data_read4[0], data_read4[1], data_read4[2], data_read4[3]);
|
|
|
|
- printf(" => Credits :\t\t%.2d\n", data_read5[7]);
|
|
|
|
- printf(" => Buy date :\t\t%.2d/%.2d/%.2d\n", data_read5[0], data_read5[1], data_read5[2]);
|
|
|
|
- printf(" => Expiration date :\t%.2d/%.2d/%.2d\n", data_read5[3], data_read5[4], data_read5[5]);
|
|
|
|
- //printf(" => Card keeped :");
|
|
|
|
|
|
+ printf(ANSI_COLOR_YELLOW"=-=-=-=-=-=-=- INFOS -=-=-=-=-=-=-=-=\n"ANSI_COLOR_RESET);
|
|
|
|
+ printf(" => Company Serial :\t"ANSI_COLOR_YELLOW"%.2x %.2x %.2x %.2x\n"ANSI_COLOR_RESET, data_read4[0], data_read4[1], data_read4[2], data_read4[3]);
|
|
|
|
+ printf(" => Credits :\t\t"ANSI_COLOR_YELLOW"%.2d\n"ANSI_COLOR_RESET, data_read5[7]);
|
|
|
|
+ printf(" => Buy date :\t\t"ANSI_COLOR_YELLOW"%.2d/%.2d/%.2d\n"ANSI_COLOR_RESET, data_read5[0], data_read5[1], data_read5[2]);
|
|
|
|
+ printf(" => Expiration date :\t"ANSI_COLOR_YELLOW"%.2d/%.2d/%.2d\n"ANSI_COLOR_RESET, data_read5[3], data_read5[4], data_read5[5]);
|
|
|
|
+ //printf(" => Card keeped :\t");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -137,13 +142,11 @@ int main(int argc, const char **argv) {
|
|
printf("RFID Poolset Read/Write !\n");
|
|
printf("RFID Poolset Read/Write !\n");
|
|
printf("=========================\n");
|
|
printf("=========================\n");
|
|
|
|
|
|
- if(argc == 1)
|
|
|
|
- show_menu();
|
|
|
|
- //else coins = atoi(argv[1]);
|
|
|
|
if (strcmp(argv[1], "--read") == 0)
|
|
if (strcmp(argv[1], "--read") == 0)
|
|
rw_tag(NULL, NULL, NULL);
|
|
rw_tag(NULL, NULL, NULL);
|
|
|
|
|
|
- if (strcmp(argv[1], "--write") == 0)
|
|
|
|
|
|
+ else if (strcmp(argv[1], "--write") == 0)
|
|
rw_tag(atoi(argv[2]), argv[3], argv[4]);
|
|
rw_tag(atoi(argv[2]), argv[3], argv[4]);
|
|
-
|
|
|
|
|
|
+ else
|
|
|
|
+ show_menu();
|
|
}
|
|
}
|