|
@@ -6,7 +6,8 @@
|
|
|
#include <freefare.h>
|
|
|
|
|
|
MifareClassicKey SecretKey[] = { 0x00, 0x01, 0x31, 0xB9, 0x3F, 0x28 };
|
|
|
-MifareClassicBlock data_read;
|
|
|
+MifareClassicBlock data_read4;
|
|
|
+MifareClassicBlock data_read5;
|
|
|
|
|
|
void show_menu(){
|
|
|
printf("How it works? So easy !\n");
|
|
@@ -20,7 +21,7 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
|
|
|
|
|
|
nfc_context *context; //init libnfc
|
|
|
nfc_device *pnd; //trouver un lecteur
|
|
|
- FreefareTag *tags = NULL; //stockage des tags
|
|
|
+ FreefareTag *tags = NULL; //stockage des tags
|
|
|
int i, nbsect;
|
|
|
|
|
|
nfc_init(&context);
|
|
@@ -38,7 +39,7 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
|
|
|
|
|
|
//tags = freefare_get_tags(pnd);
|
|
|
while(!tags) {
|
|
|
- printf("Waiting for Mifare 1k...\n");
|
|
|
+ printf("Hey, i'm Waiting for my tag...\n");
|
|
|
sleep(1);
|
|
|
tags = freefare_get_tags(pnd);
|
|
|
}
|
|
@@ -47,65 +48,80 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
|
|
|
switch(freefare_get_tag_type(tags[i])) {
|
|
|
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("=> 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]);
|
|
|
+ break;
|
|
|
|
|
|
- if(mifare_classic_connect(tags[i]) == OPERATION_OK) {
|
|
|
- printf("=> Mifare tag connected !\n");
|
|
|
- }
|
|
|
- else printf("Non ca chie dans la colle mais grave, ton tag est moisi\n");
|
|
|
-
|
|
|
- if(mifare_classic_authenticate(tags[i], 5, SecretKey[0], MFC_KEY_A) == OPERATION_OK) {
|
|
|
- printf("=> Tag authenticated !\n");
|
|
|
- }
|
|
|
- else printf("Non ca chie dans la colle mais grave, check ta clé\n");
|
|
|
-
|
|
|
- if(coins != 0 && buy_date != NULL && expire_date != NULL) {
|
|
|
-
|
|
|
- char *token;
|
|
|
- token = strtok (buy_date,"/");
|
|
|
- int j=0;
|
|
|
- while (token != NULL) {
|
|
|
- printf ("%s ", token);
|
|
|
- data_read[j] = atoi(token);
|
|
|
- j++;
|
|
|
- token = strtok (NULL, "/");
|
|
|
- }
|
|
|
-
|
|
|
- token = strtok (expire_date, "/");
|
|
|
- while (token != NULL) {
|
|
|
- printf ("%s ", token);
|
|
|
- data_read[j] = atoi(token);
|
|
|
- j++;
|
|
|
- token = strtok (NULL, "/");
|
|
|
- }
|
|
|
- data_read[6] = 0;
|
|
|
- data_read[7] = coins;
|
|
|
-
|
|
|
- printf("=> Writing new datas...\n");
|
|
|
-
|
|
|
- if(mifare_classic_write(tags[i], 5, &data_read) == OPERATION_OK) {
|
|
|
- if(mifare_classic_read(tags[i], 5, &data_read) == OPERATION_OK) {
|
|
|
- printf("=> %.2d credits found now !\n", data_read[7]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if(mifare_classic_read(tags[i], 5, &data_read) == OPERATION_OK) {
|
|
|
- printf(" => Infos\n");
|
|
|
- printf(" => credits :\t\t%.2d\n", data_read[7]);
|
|
|
- printf(" => buy date :\t\t%.2d/%.2d/%.2d\n", data_read[0], data_read[1], data_read[2]);
|
|
|
- printf(" => expire date :\t%.2d/%.2d/%.2d\n", data_read[3], data_read[4], data_read[5]);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- mifare_classic_disconnect(tags[i]);
|
|
|
+ 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]) );
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- printf("[x] Wrong tag Mr Dugland !");
|
|
|
+ printf("[x] Wrong tag Mr Dugland !\n");
|
|
|
+ break;
|
|
|
+ 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]);
|
|
|
+
|
|
|
+ if(mifare_classic_connect(tags[i]) == OPERATION_OK) {
|
|
|
+ printf("=> Mifare tag connected !\n");
|
|
|
+ }
|
|
|
+ else printf("Non ca chie dans la colle mais grave, ton tag est moisi\n");
|
|
|
+
|
|
|
+ if(mifare_classic_authenticate(tags[i], 5, SecretKey[0], MFC_KEY_A) == OPERATION_OK) {
|
|
|
+ printf("=> Tag authenticated !\n");
|
|
|
+ }
|
|
|
+ else printf("Non ca chie dans la colle mais grave, check ta clé\n");
|
|
|
+
|
|
|
+ if(coins != 0 && buy_date != NULL && expire_date != NULL) {
|
|
|
+
|
|
|
+ char *token;
|
|
|
+ token = strtok (buy_date,"/");
|
|
|
+ int j=0;
|
|
|
+ while (token != NULL) {
|
|
|
+ printf ("%s ", token);
|
|
|
+ data_read5[j] = atoi(token);
|
|
|
+ j++;
|
|
|
+ token = strtok (NULL, "/");
|
|
|
+ }
|
|
|
+
|
|
|
+ token = strtok (expire_date, "/");
|
|
|
+ while (token != NULL) {
|
|
|
+ printf ("%s ", token);
|
|
|
+ data_read5[j] = atoi(token);
|
|
|
+ j++;
|
|
|
+ token = strtok (NULL, "/");
|
|
|
+ }
|
|
|
+ data_read5[6] = 0;
|
|
|
+ data_read5[7] = coins;
|
|
|
+
|
|
|
+ printf("=> Writing new datas...\n");
|
|
|
+
|
|
|
+ if(mifare_classic_write(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]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if( (mifare_classic_read(tags[i], 5, &data_read5) == 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 :");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ mifare_classic_disconnect(tags[i]);
|
|
|
break;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
freefare_free_tags(tags);
|
|
|
nfc_close(pnd);
|