add -y flag to mifare-classic-write-ndef
write without confirmation
This commit is contained in:
parent
f86ad5a183
commit
14219ab145
1 changed files with 21 additions and 4 deletions
|
@ -48,6 +48,12 @@ struct mifare_classic_key_and_type {
|
||||||
MifareClassicKeyType type;
|
MifareClassicKeyType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool interactive;
|
||||||
|
} write_options = {
|
||||||
|
.interactive = true
|
||||||
|
};
|
||||||
|
|
||||||
const MifareClassicKey default_keyb = {
|
const MifareClassicKey default_keyb = {
|
||||||
0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7
|
0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7
|
||||||
};
|
};
|
||||||
|
@ -121,6 +127,7 @@ usage(char *progname)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "usage: %s -i FILE\n", progname);
|
fprintf (stderr, "usage: %s -i FILE\n", progname);
|
||||||
fprintf (stderr, "\nOptions:\n");
|
fprintf (stderr, "\nOptions:\n");
|
||||||
|
fprintf (stderr, " -y Do not ask for confirmation\n");
|
||||||
fprintf (stderr, " -i Use FILE as NDEF message to write on card (\"-\" = stdin)\n");
|
fprintf (stderr, " -i Use FILE as NDEF message to write on card (\"-\" = stdin)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +142,15 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
char *ndef_input = NULL;
|
char *ndef_input = NULL;
|
||||||
while ((ch = getopt (argc, argv, "hi:")) != -1) {
|
while ((ch = getopt (argc, argv, "hyi:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
|
case 'y':
|
||||||
|
write_options.interactive = false;
|
||||||
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
ndef_input = optarg;
|
ndef_input = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -230,10 +240,17 @@ main(int argc, char *argv[])
|
||||||
char *tag_uid = freefare_get_tag_uid (tags[i]);
|
char *tag_uid = freefare_get_tag_uid (tags[i]);
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
|
|
||||||
printf ("Found %s with UID %s. Write NDEF [yN] ", freefare_get_tag_friendly_name (tags[i]), tag_uid);
|
printf ("Found %s with UID %s. ", freefare_get_tag_friendly_name (tags[i]), tag_uid);
|
||||||
fgets (buffer, BUFSIZ, stdin);
|
|
||||||
bool write_ndef = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
|
||||||
|
|
||||||
|
bool write_ndef = true;
|
||||||
|
if (write_options.interactive) {
|
||||||
|
printf ("Write NDEF [yN] ");
|
||||||
|
fgets (buffer, BUFSIZ, stdin);
|
||||||
|
write_ndef = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
|
} else {
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (int n = 0; n < 40; n++) {
|
for (int n = 0; n < 40; n++) {
|
||||||
memcpy(card_write_keys[n].key, transport_key, sizeof (transport_key));
|
memcpy(card_write_keys[n].key, transport_key, sizeof (transport_key));
|
||||||
card_write_keys[n].type = MFC_KEY_A;
|
card_write_keys[n].type = MFC_KEY_A;
|
||||||
|
|
Loading…
Reference in a new issue