diff --git a/examples/mifare-classic-format.c b/examples/mifare-classic-format.c index 30f34fd..f6fc642 100644 --- a/examples/mifare-classic-format.c +++ b/examples/mifare-classic-format.c @@ -144,19 +144,19 @@ main(int argc, char *argv[]) while ((ch = getopt (argc, argv, "fhy")) != -1) { switch (ch) { - case 'f': - format_options.fast = true; - break; - case 'h': - usage(argv[0]); - exit (EXIT_SUCCESS); - break; - case 'y': - format_options.interactive = false; - break; - default: - usage(argv[0]); - exit (EXIT_FAILURE); + case 'f': + format_options.fast = true; + break; + case 'h': + usage(argv[0]); + exit (EXIT_SUCCESS); + break; + case 'y': + format_options.interactive = false; + break; + default: + usage(argv[0]); + exit (EXIT_FAILURE); } } argc -= optind; @@ -185,11 +185,11 @@ main(int argc, char *argv[]) for (int i = 0; (!error) && tags[i]; i++) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: - case CLASSIC_4K: - break; - default: - continue; + case CLASSIC_1K: + case CLASSIC_4K: + break; + default: + continue; } char *tag_uid = freefare_get_tag_uid (tags[i]); @@ -222,19 +222,19 @@ main(int argc, char *argv[]) continue; } switch (tt) { - case CLASSIC_1K: - mod_block = 4; - if (!format_mifare_classic_1k (tags[i])) - error = 1; - break; - case CLASSIC_4K: - mod_block = 10; - if (!format_mifare_classic_4k (tags[i])) - error = 1; - break; - default: - /* Keep compiler quiet */ - break; + case CLASSIC_1K: + mod_block = 4; + if (!format_mifare_classic_1k (tags[i])) + error = 1; + break; + case CLASSIC_4K: + mod_block = 10; + if (!format_mifare_classic_4k (tags[i])) + error = 1; + break; + default: + /* Keep compiler quiet */ + break; } } diff --git a/examples/mifare-classic-write-ndef.c b/examples/mifare-classic-write-ndef.c index fb1999f..be93b78 100644 --- a/examples/mifare-classic-write-ndef.c +++ b/examples/mifare-classic-write-ndef.c @@ -150,11 +150,11 @@ main(int argc, char *argv[]) for (int i = 0; (!error) && tags[i]; i++) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: - case CLASSIC_4K: - break; - default: - continue; + case CLASSIC_1K: + case CLASSIC_4K: + break; + default: + continue; } char *tag_uid = freefare_get_tag_uid (tags[i]); @@ -166,49 +166,49 @@ main(int argc, char *argv[]) if (write_ndef) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_4K: - if (!search_sector_key (tags[i], 0x10, &(card_write_keys[0x10].key), &(card_write_keys[0x10].type))) { - error = 1; - goto error; - } - /* fallthrough */ - case CLASSIC_1K: - if (!search_sector_key (tags[i], 0x00, &(card_write_keys[0x00].key), &(card_write_keys[0x00].type))) { - error = 1; - goto error; - } - break; - default: - /* Keep compiler quiet */ - break; + case CLASSIC_4K: + if (!search_sector_key (tags[i], 0x10, &(card_write_keys[0x10].key), &(card_write_keys[0x10].type))) { + error = 1; + goto error; + } + /* fallthrough */ + case CLASSIC_1K: + if (!search_sector_key (tags[i], 0x00, &(card_write_keys[0x00].key), &(card_write_keys[0x00].type))) { + error = 1; + goto error; + } + break; + default: + /* Keep compiler quiet */ + break; } if (!error) { /* Ensure the auth key is always a B one. If not, change it! */ switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_4K: - if (card_write_keys[0x10].type != MFC_KEY_B) { - if( 0 != fix_mad_trailer_block( tags[i], 0x10, card_write_keys[0x10].key, card_write_keys[0x10].type)) { - error = 1; - goto error; - } - memcpy (&(card_write_keys[0x10].key), &default_keyb, sizeof (MifareClassicKey)); - card_write_keys[0x10].type = MFC_KEY_B; + case CLASSIC_4K: + if (card_write_keys[0x10].type != MFC_KEY_B) { + if( 0 != fix_mad_trailer_block( tags[i], 0x10, card_write_keys[0x10].key, card_write_keys[0x10].type)) { + error = 1; + goto error; } - /* fallthrough */ - case CLASSIC_1K: - if (card_write_keys[0x00].type != MFC_KEY_B) { - if( 0 != fix_mad_trailer_block( tags[i], 0x00, card_write_keys[0x00].key, card_write_keys[0x00].type)) { - error = 1; - goto error; - } - memcpy (&(card_write_keys[0x00].key), &default_keyb, sizeof (MifareClassicKey)); - card_write_keys[0x00].type = MFC_KEY_B; + memcpy (&(card_write_keys[0x10].key), &default_keyb, sizeof (MifareClassicKey)); + card_write_keys[0x10].type = MFC_KEY_B; + } + /* fallthrough */ + case CLASSIC_1K: + if (card_write_keys[0x00].type != MFC_KEY_B) { + if( 0 != fix_mad_trailer_block( tags[i], 0x00, card_write_keys[0x00].key, card_write_keys[0x00].type)) { + error = 1; + goto error; } - break; - default: - /* Keep compiler quiet */ - break; + memcpy (&(card_write_keys[0x00].key), &default_keyb, sizeof (MifareClassicKey)); + card_write_keys[0x00].type = MFC_KEY_B; + } + break; + default: + /* Keep compiler quiet */ + break; } } @@ -235,15 +235,15 @@ main(int argc, char *argv[]) MifareClassicSectorNumber max_s; switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: - max_s = 15; - break; - case CLASSIC_4K: - max_s = 39; - break; - default: - /* Keep compiler quiet */ - break; + case CLASSIC_1K: + max_s = 15; + break; + case CLASSIC_4K: + max_s = 39; + break; + default: + /* Keep compiler quiet */ + break; } MifareClassicKey transport_key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index 302c247..c150c46 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -64,16 +64,16 @@ freefare_tag_new (nfc_device_t *device, nfc_iso14443a_info_t nai) /* Allocate memory for the found MIFARE target */ switch (tag_info->type) { - case CLASSIC_1K: - case CLASSIC_4K: - tag = mifare_classic_tag_new (); - break; - case DESFIRE: - tag = mifare_desfire_tag_new (); - break; - case ULTRALIGHT: - tag = mifare_ultralight_tag_new (); - break; + case CLASSIC_1K: + case CLASSIC_4K: + tag = mifare_classic_tag_new (); + break; + case DESFIRE: + tag = mifare_desfire_tag_new (); + break; + case ULTRALIGHT: + tag = mifare_ultralight_tag_new (); + break; } if (!tag) @@ -188,16 +188,16 @@ freefare_free_tag (MifareTag tag) { if (tag) { switch (tag->tag_info->type) { - case CLASSIC_1K: - case CLASSIC_4K: - mifare_classic_tag_free (tag); - break; - case DESFIRE: - mifare_desfire_tag_free (tag); - break; - case ULTRALIGHT: - mifare_ultralight_tag_free (tag); - break; + case CLASSIC_1K: + case CLASSIC_4K: + mifare_classic_tag_free (tag); + break; + case DESFIRE: + mifare_desfire_tag_free (tag); + break; + case ULTRALIGHT: + mifare_ultralight_tag_free (tag); + break; } } } diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 0a14825..77478c6 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -724,22 +724,22 @@ mifare_desfire_get_file_settings (MifareTag tag, uint8_t file_no, struct mifare_ settings->access_rights = le16toh (raw_settings.access_rights); switch (settings->file_type) { - case MDFT_STANDARD_DATA_FILE: - case MDFT_BACKUP_DATA_FILE: - settings->settings.standard_file.file_size = le24toh (raw_settings.settings.standard_file.file_size); - break; - case MDFT_VALUE_FILE_WITH_BACKUP: - settings->settings.value_file.lower_limit = le32toh (raw_settings.settings.value_file.lower_limit); - settings->settings.value_file.upper_limit = le32toh (raw_settings.settings.value_file.upper_limit); - settings->settings.value_file.limited_credit_value = le32toh (raw_settings.settings.value_file.limited_credit_value); - settings->settings.value_file.limited_credit_enabled = raw_settings.settings.value_file.limited_credit_enabled; - break; - case MDFT_LINEAR_RECORD_FILE_WITH_BACKUP: - case MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP: - settings->settings.linear_record_file.record_size = le24toh (raw_settings.settings.linear_record_file.record_size); - settings->settings.linear_record_file.max_number_of_records = le24toh (raw_settings.settings.linear_record_file.max_number_of_records); - settings->settings.linear_record_file.current_number_of_records = le24toh (raw_settings.settings.linear_record_file.current_number_of_records); - break; + case MDFT_STANDARD_DATA_FILE: + case MDFT_BACKUP_DATA_FILE: + settings->settings.standard_file.file_size = le24toh (raw_settings.settings.standard_file.file_size); + break; + case MDFT_VALUE_FILE_WITH_BACKUP: + settings->settings.value_file.lower_limit = le32toh (raw_settings.settings.value_file.lower_limit); + settings->settings.value_file.upper_limit = le32toh (raw_settings.settings.value_file.upper_limit); + settings->settings.value_file.limited_credit_value = le32toh (raw_settings.settings.value_file.limited_credit_value); + settings->settings.value_file.limited_credit_enabled = raw_settings.settings.value_file.limited_credit_enabled; + break; + case MDFT_LINEAR_RECORD_FILE_WITH_BACKUP: + case MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP: + settings->settings.linear_record_file.record_size = le24toh (raw_settings.settings.linear_record_file.record_size); + settings->settings.linear_record_file.max_number_of_records = le24toh (raw_settings.settings.linear_record_file.max_number_of_records); + settings->settings.linear_record_file.current_number_of_records = le24toh (raw_settings.settings.linear_record_file.current_number_of_records); + break; } cached_file_settings[file_no] = *settings; diff --git a/libfreefare/mifare_desfire_authenticate.c b/libfreefare/mifare_desfire_authenticate.c index 00d38cc..146e781 100644 --- a/libfreefare/mifare_desfire_authenticate.c +++ b/libfreefare/mifare_desfire_authenticate.c @@ -106,54 +106,54 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, int com size_t edl, mdl; switch (communication_settings) { - case 0: - case 2: - res = data; - break; - case 1: - edl = padded_data_length (*nbytes); - if (!(res = assert_crypto_buffer_size (tag, edl))) - abort(); + case 0: + case 2: + res = data; + break; + case 1: + edl = padded_data_length (*nbytes); + if (!(res = assert_crypto_buffer_size (tag, edl))) + abort(); - // Fill in the crypto buffer with data ... - memcpy (res, data, *nbytes); - // ... and 0 padding - bzero ((uint8_t *)res + *nbytes, edl - *nbytes); + // Fill in the crypto buffer with data ... + memcpy (res, data, *nbytes); + // ... and 0 padding + bzero ((uint8_t *)res + *nbytes, edl - *nbytes); - mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, res, edl, MD_SEND, 1); + mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, res, edl, MD_SEND, 1); - memcpy (mac, (uint8_t *)res + edl - 8, 4); + memcpy (mac, (uint8_t *)res + edl - 8, 4); - mdl = maced_data_length (*nbytes); - if (!(res = assert_crypto_buffer_size (tag, mdl))) - abort(); + mdl = maced_data_length (*nbytes); + if (!(res = assert_crypto_buffer_size (tag, mdl))) + abort(); - memcpy (res, data, *nbytes); - memcpy ((uint8_t *)res + *nbytes, mac, 4); + memcpy (res, data, *nbytes); + memcpy ((uint8_t *)res + *nbytes, mac, 4); - *nbytes += 4; + *nbytes += 4; - break; - case 3: - edl = enciphered_data_length (*nbytes); - if (!(res = assert_crypto_buffer_size (tag, edl))) - abort(); + break; + case 3: + edl = enciphered_data_length (*nbytes); + if (!(res = assert_crypto_buffer_size (tag, edl))) + abort(); - // Fill in the crypto buffer with data ... - memcpy (res, data, *nbytes); - // ... CRC ... - append_iso14443a_crc (res, *nbytes); - // ... and 0 padding - bzero ((uint8_t *)(res) + *nbytes + 2, edl - *nbytes - 2); + // Fill in the crypto buffer with data ... + memcpy (res, data, *nbytes); + // ... CRC ... + append_iso14443a_crc (res, *nbytes); + // ... and 0 padding + bzero ((uint8_t *)(res) + *nbytes + 2, edl - *nbytes - 2); - *nbytes = edl; + *nbytes = edl; - mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, res, *nbytes, MD_SEND, 0); + mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, res, *nbytes, MD_SEND, 0); - break; - default: - res = NULL; - break; + break; + default: + res = NULL; + break; } return res; @@ -167,73 +167,73 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c void *edata; switch (communication_settings) { - case 0: - case 2: - break; - case 1: - *nbytes -= 4; + case 0: + case 2: + break; + case 1: + *nbytes -= 4; - edl = enciphered_data_length (*nbytes); - edata = malloc (edl); + edl = enciphered_data_length (*nbytes); + edata = malloc (edl); - memcpy (edata, data, *nbytes); - bzero ((uint8_t *)edata + *nbytes, edl - *nbytes); + memcpy (edata, data, *nbytes); + bzero ((uint8_t *)edata + *nbytes, edl - *nbytes); - mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, edata, edl, MD_SEND, 1); - /* ,^^^^^^^ - * No! This is not a typo! ---------------------------------' - */ + mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, edata, edl, MD_SEND, 1); + /* ,^^^^^^^ + * No! This is not a typo! ---------------------------------' + */ - if (0 != memcmp ((uint8_t *)data + *nbytes, (uint8_t *)edata + edl - 8, 4)) { - printf ("MACing not verified\n"); - *nbytes = -1; - res = NULL; - } - - free (edata); - - break; - case 3: - mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, res, *nbytes, MD_RECEIVE, 0); - - /* - * Look for the CRC and ensure it is following by NULL padding. We - * can't start by the end because the CRC is supposed to be 0 when - * verified, and accumulating 0's in it should not change it. - */ - bool verified = false; - int end_crc_pos = *nbytes - 7; // The CRC can be over two blocks - - do { - uint16_t crc; - iso14443a_crc (res, end_crc_pos, (uint8_t *)&crc); - if (!crc) { - verified = true; - for (int n = end_crc_pos; n < *nbytes; n++) { - uint8_t byte = ((uint8_t *)res)[n]; - if (!( (0x00 == byte) || ((0x80 == byte) && (n == end_crc_pos)) )) - verified = false; - } - } - if (verified) { - *nbytes = end_crc_pos - 2; - } else { - end_crc_pos++; - } - } while (!verified && (end_crc_pos < *nbytes)); - - if (!verified) { - printf ("(3)DES not verified\n"); - *nbytes = -1; - res = NULL; - } - - break; - default: - printf ("Unknown communication settings\n"); + if (0 != memcmp ((uint8_t *)data + *nbytes, (uint8_t *)edata + edl - 8, 4)) { + printf ("MACing not verified\n"); *nbytes = -1; res = NULL; - break; + } + + free (edata); + + break; + case 3: + mifare_cbc_des (MIFARE_DESFIRE (tag)->session_key, res, *nbytes, MD_RECEIVE, 0); + + /* + * Look for the CRC and ensure it is following by NULL padding. We + * can't start by the end because the CRC is supposed to be 0 when + * verified, and accumulating 0's in it should not change it. + */ + bool verified = false; + int end_crc_pos = *nbytes - 7; // The CRC can be over two blocks + + do { + uint16_t crc; + iso14443a_crc (res, end_crc_pos, (uint8_t *)&crc); + if (!crc) { + verified = true; + for (int n = end_crc_pos; n < *nbytes; n++) { + uint8_t byte = ((uint8_t *)res)[n]; + if (!( (0x00 == byte) || ((0x80 == byte) && (n == end_crc_pos)) )) + verified = false; + } + } + if (verified) { + *nbytes = end_crc_pos - 2; + } else { + end_crc_pos++; + } + } while (!verified && (end_crc_pos < *nbytes)); + + if (!verified) { + printf ("(3)DES not verified\n"); + *nbytes = -1; + res = NULL; + } + + break; + default: + printf ("Unknown communication settings\n"); + *nbytes = -1; + res = NULL; + break; } return res; @@ -252,26 +252,26 @@ mifare_des (MifareDESFireKey key, uint8_t *data, uint8_t *ivect, MifareDirection uint8_t edata[8]; switch (key->type) { - case T_DES: - if (mac) { - DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_ENCRYPT); - } else { - DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_DECRYPT); - } - memcpy (data, edata, 8); - break; - case T_3DES: - if (mac) { - DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_ENCRYPT); - DES_ecb_encrypt ((DES_cblock *) edata, (DES_cblock *) data, &(key->ks2), DES_DECRYPT); - DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_ENCRYPT); - } else { - DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_DECRYPT); - DES_ecb_encrypt ((DES_cblock *) edata, (DES_cblock *) data, &(key->ks2), DES_ENCRYPT); - DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_DECRYPT); - } - memcpy (data, edata, 8); - break; + case T_DES: + if (mac) { + DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_ENCRYPT); + } else { + DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_DECRYPT); + } + memcpy (data, edata, 8); + break; + case T_3DES: + if (mac) { + DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_ENCRYPT); + DES_ecb_encrypt ((DES_cblock *) edata, (DES_cblock *) data, &(key->ks2), DES_DECRYPT); + DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_ENCRYPT); + } else { + DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_DECRYPT); + DES_ecb_encrypt ((DES_cblock *) edata, (DES_cblock *) data, &(key->ks2), DES_ENCRYPT); + DES_ecb_encrypt ((DES_cblock *) data, (DES_cblock *) edata, &(key->ks1), DES_DECRYPT); + } + memcpy (data, edata, 8); + break; } if (direction == MD_SEND) { diff --git a/libfreefare/mifare_desfire_key.c b/libfreefare/mifare_desfire_key.c index 94b3c8e..78c569c 100644 --- a/libfreefare/mifare_desfire_key.c +++ b/libfreefare/mifare_desfire_key.c @@ -124,12 +124,12 @@ mifare_desfire_session_key_new (uint8_t rnda[8], uint8_t rndb[8], MifareDESFireK memcpy (buffer+12, rndb+4, 4); switch (authentication_key->type) { - case T_DES: - key = mifare_desfire_des_key_new_with_version (buffer); - break; - case T_3DES: - key = mifare_desfire_3des_key_new_with_version (buffer); - break; + case T_DES: + key = mifare_desfire_des_key_new_with_version (buffer); + break; + case T_3DES: + key = mifare_desfire_3des_key_new_with_version (buffer); + break; } return key; diff --git a/libfreefare/tlv.c b/libfreefare/tlv.c index 27bfa54..9111c9f 100644 --- a/libfreefare/tlv.c +++ b/libfreefare/tlv.c @@ -131,23 +131,23 @@ tlv_record_length (const uint8_t *stream, size_t *field_length_size, size_t *fie size_t fvs = 0; switch (stream[0]) { - case 0x00: - case 0xfe: - break; - case 0x01: - case 0x02: - case 0x03: - default: // FIXME Not supported. - if (stream[1] == 0xff) { - uint16_t be_size; - memcpy (&be_size, stream + 2, sizeof (uint16_t)); - fls = 3; - fvs = be16toh(be_size); - } else { - fls = 1; - fvs = stream[1]; - } - break; + case 0x00: + case 0xfe: + break; + case 0x01: + case 0x02: + case 0x03: + default: // FIXME Not supported. + if (stream[1] == 0xff) { + uint16_t be_size; + memcpy (&be_size, stream + 2, sizeof (uint16_t)); + fls = 3; + fvs = be16toh(be_size); + } else { + fls = 1; + fvs = stream[1]; + } + break; } if (field_length_size) diff --git a/test/test_mifare_desfire.c b/test/test_mifare_desfire.c index 3111884..d706839 100644 --- a/test/test_mifare_desfire.c +++ b/test/test_mifare_desfire.c @@ -60,17 +60,17 @@ test_mifare_desfire (void) MifareDESFireKey key; switch (key_version) { - case 0x00: - key = mifare_desfire_des_key_new_with_version (key_data_null); - break; - case 0xAA: - key = mifare_desfire_des_key_new_with_version (key_data_des); - break; - case 0xC7: - key = mifare_desfire_3des_key_new_with_version (key_data_3des); - break; - default: - cut_fail ("Unknown master key."); + case 0x00: + key = mifare_desfire_des_key_new_with_version (key_data_null); + break; + case 0xAA: + key = mifare_desfire_des_key_new_with_version (key_data_des); + break; + case 0xC7: + key = mifare_desfire_3des_key_new_with_version (key_data_3des); + break; + default: + cut_fail ("Unknown master key."); } cut_assert_not_null (key, cut_message ("Cannot allocate key")); @@ -294,34 +294,34 @@ test_mifare_desfire (void) cut_assert_success ("mifare_desfire_get_file_settings()"); switch (files[i]) { - case 0: - cut_assert_equal_int (MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP, settings.file_type, cut_message ("Wrong file type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); - cut_assert_equal_int (4, settings.settings.linear_record_file.record_size, cut_message ("Wrong record size")); - cut_assert_equal_int (10, settings.settings.linear_record_file.max_number_of_records, cut_message ("Wrong max number of records")); - cut_assert_equal_int (9, settings.settings.linear_record_file.current_number_of_records, cut_message ("Wrong current number of records")); - break; - case 4: - cut_assert_equal_int (MDFT_VALUE_FILE_WITH_BACKUP, settings.file_type, cut_message ("Wrong file type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); + case 0: + cut_assert_equal_int (MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP, settings.file_type, cut_message ("Wrong file type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); + cut_assert_equal_int (4, settings.settings.linear_record_file.record_size, cut_message ("Wrong record size")); + cut_assert_equal_int (10, settings.settings.linear_record_file.max_number_of_records, cut_message ("Wrong max number of records")); + cut_assert_equal_int (9, settings.settings.linear_record_file.current_number_of_records, cut_message ("Wrong current number of records")); + break; + case 4: + cut_assert_equal_int (MDFT_VALUE_FILE_WITH_BACKUP, settings.file_type, cut_message ("Wrong file type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); - cut_assert_equal_int (0, settings.settings.value_file.lower_limit, cut_message ("Wrong lower limit")); - cut_assert_equal_int (1000, settings.settings.value_file.upper_limit, cut_message ("Wrong upper limit")); - cut_assert_equal_int (97, settings.settings.value_file.limited_credit_value, cut_message ("Wrong limited_credit value")); - cut_assert_equal_int (0, settings.settings.value_file.limited_credit_enabled, cut_message ("Wrong limited_credit enable state")); - break; - case 5: - cut_assert_equal_int (MDFT_BACKUP_DATA_FILE, settings.file_type, cut_message ("Wrong file type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); - cut_assert_equal_int (64, settings.settings.standard_file.file_size, cut_message ("Wrong file size")); - break; - case 15: - cut_assert_equal_int (MDFT_STANDARD_DATA_FILE, settings.file_type, cut_message ("Wrong file type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); - cut_assert_equal_int (100, settings.settings.standard_file.file_size, cut_message ("Wrong file size")); - break; - default: - cut_fail ("Wow! Cosmic ray!"); + cut_assert_equal_int (0, settings.settings.value_file.lower_limit, cut_message ("Wrong lower limit")); + cut_assert_equal_int (1000, settings.settings.value_file.upper_limit, cut_message ("Wrong upper limit")); + cut_assert_equal_int (97, settings.settings.value_file.limited_credit_value, cut_message ("Wrong limited_credit value")); + cut_assert_equal_int (0, settings.settings.value_file.limited_credit_enabled, cut_message ("Wrong limited_credit enable state")); + break; + case 5: + cut_assert_equal_int (MDFT_BACKUP_DATA_FILE, settings.file_type, cut_message ("Wrong file type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); + cut_assert_equal_int (64, settings.settings.standard_file.file_size, cut_message ("Wrong file size")); + break; + case 15: + cut_assert_equal_int (MDFT_STANDARD_DATA_FILE, settings.file_type, cut_message ("Wrong file type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("Wrong communication settings")); + cut_assert_equal_int (100, settings.settings.standard_file.file_size, cut_message ("Wrong file size")); + break; + default: + cut_fail ("Wow! Cosmic ray!"); } res = mifare_desfire_delete_file (tag, files[i]); @@ -608,31 +608,31 @@ test_mifare_desfire (void) cut_assert_success ("mifare_desfire_get_file_settings()"); switch (files[i]) { - case 1: - cut_assert_equal_int (MDFT_LINEAR_RECORD_FILE_WITH_BACKUP, settings.file_type, cut_message ("type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("cs")); - cut_assert_equal_int (0x1324, settings.access_rights, cut_message ("access_rights")); - cut_assert_equal_int (25, settings.settings.linear_record_file.record_size, cut_message ("record_size")); - cut_assert_equal_int (4, settings.settings.linear_record_file.max_number_of_records, cut_message ("max_number_of_records")); - cut_assert_equal_int (2, settings.settings.linear_record_file.current_number_of_records, cut_message ("current_number_of_records")); - break; - case 4: - cut_assert_equal_int (MDFT_VALUE_FILE_WITH_BACKUP , settings.file_type, cut_message ("type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("cs")); - cut_assert_equal_int (0x1324, settings.access_rights, cut_message ("access_rights")); - cut_assert_equal_int (-987654321, settings.settings.value_file.lower_limit, cut_message ("lower_limit")); - cut_assert_equal_int (-1000, settings.settings.value_file.upper_limit, cut_message ("upper_limit")); - cut_assert_equal_int (0, settings.settings.value_file.limited_credit_value, cut_message ("limited_credit_value")); - cut_assert_equal_int (1, settings.settings.value_file.limited_credit_enabled, cut_message ("limited_credit_enabled")); - break; - case 14: /* std_data_file_id */ - cut_assert_equal_int (MDFT_STANDARD_DATA_FILE, settings.file_type, cut_message ("type")); - cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("cs")); - cut_assert_equal_int (0x1234, settings.access_rights, cut_message ("access_rights")); - cut_assert_equal_int (100, settings.settings.standard_file.file_size, cut_message ("size")); - break; - default: - cut_fail ("file_no"); + case 1: + cut_assert_equal_int (MDFT_LINEAR_RECORD_FILE_WITH_BACKUP, settings.file_type, cut_message ("type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("cs")); + cut_assert_equal_int (0x1324, settings.access_rights, cut_message ("access_rights")); + cut_assert_equal_int (25, settings.settings.linear_record_file.record_size, cut_message ("record_size")); + cut_assert_equal_int (4, settings.settings.linear_record_file.max_number_of_records, cut_message ("max_number_of_records")); + cut_assert_equal_int (2, settings.settings.linear_record_file.current_number_of_records, cut_message ("current_number_of_records")); + break; + case 4: + cut_assert_equal_int (MDFT_VALUE_FILE_WITH_BACKUP , settings.file_type, cut_message ("type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("cs")); + cut_assert_equal_int (0x1324, settings.access_rights, cut_message ("access_rights")); + cut_assert_equal_int (-987654321, settings.settings.value_file.lower_limit, cut_message ("lower_limit")); + cut_assert_equal_int (-1000, settings.settings.value_file.upper_limit, cut_message ("upper_limit")); + cut_assert_equal_int (0, settings.settings.value_file.limited_credit_value, cut_message ("limited_credit_value")); + cut_assert_equal_int (1, settings.settings.value_file.limited_credit_enabled, cut_message ("limited_credit_enabled")); + break; + case 14: /* std_data_file_id */ + cut_assert_equal_int (MDFT_STANDARD_DATA_FILE, settings.file_type, cut_message ("type")); + cut_assert_equal_int (MDCM_PLAIN, settings.communication_settings, cut_message ("cs")); + cut_assert_equal_int (0x1234, settings.access_rights, cut_message ("access_rights")); + cut_assert_equal_int (100, settings.settings.standard_file.file_size, cut_message ("size")); + break; + default: + cut_fail ("file_no"); }