mirror of
https://github.com/dimoniche/solarium.vlad.git
synced 2026-01-30 04:53:30 +03:00
Обмен с картой запустился
This commit is contained in:
parent
4acafbaea8
commit
bb3e477d29
@ -94,6 +94,8 @@ static void AppTaskStart (void *p_arg)
|
||||
SpiInit();
|
||||
#endif
|
||||
|
||||
OSTimeDly(50);
|
||||
|
||||
#ifdef CONFIG_SPI_ENABLE
|
||||
pcd_initialization();
|
||||
#endif
|
||||
|
||||
@ -678,16 +678,6 @@ void UserAppTask(void *p_arg)
|
||||
PrintSolariumPassMenu();
|
||||
}
|
||||
|
||||
// Look for new cards
|
||||
if (!picc_is_new_card_present() ) {
|
||||
break;
|
||||
}
|
||||
// Select one of the cards
|
||||
if (!picc_read_card_serial()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case EVENT_KEY_STAR:
|
||||
|
||||
|
||||
@ -622,6 +622,18 @@ void AppVladEventProcess(CPU_INT32U event)
|
||||
current_discount = CalcCurrentDiscount(SystemTime);
|
||||
}
|
||||
|
||||
// Look for new cards
|
||||
if (picc_is_new_card_present() ) {
|
||||
int y = 0;
|
||||
y++;
|
||||
y--;
|
||||
break;
|
||||
}
|
||||
// Select one of the cards
|
||||
//if (!picc_read_card_serial()) {
|
||||
// break;
|
||||
//}
|
||||
|
||||
#if APP_DEBUG
|
||||
if ((SystemTime % 30) == 0)
|
||||
{
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "cpu.h"
|
||||
#include "spi.h"
|
||||
#include <intrinsics.h>
|
||||
|
||||
OS_EVENT *SpiLock = NULL;
|
||||
|
||||
@ -15,6 +16,14 @@ unsigned char SpiExchange(unsigned char spi, unsigned char ch)
|
||||
return SSP0DR;
|
||||
}
|
||||
|
||||
void us_delay_spi(unsigned long x)
|
||||
{
|
||||
while (x--)
|
||||
{
|
||||
for (int i=0; i<10; i++) __no_operation();
|
||||
}
|
||||
}
|
||||
|
||||
void SpiInit(void)
|
||||
{
|
||||
// on spi power
|
||||
@ -68,9 +77,24 @@ void SpiInit(void)
|
||||
SSP0IMSC = 0;
|
||||
SSP0DMACR = 0;
|
||||
|
||||
PINSEL1_bit.P0_26 = 0x0;
|
||||
PINMODE1_bit.P0_26 = 0;
|
||||
FIO0MASK_bit.P0_26 = 0;
|
||||
FIO0DIR_bit.P0_26 = 1;
|
||||
FIO0SET_bit.P0_26 = 1;
|
||||
|
||||
if (!SpiLock) SpiLock = OSSemCreate(1);
|
||||
}
|
||||
|
||||
void mfr_reset_up()
|
||||
{
|
||||
FIO0SET_bit.P0_26 = 1;
|
||||
}
|
||||
|
||||
void mfr_reset_down()
|
||||
{
|
||||
FIO0CLR_bit.P0_26 = 1;
|
||||
}
|
||||
|
||||
unsigned char spi_selectChip(unsigned char spi)
|
||||
{
|
||||
|
||||
@ -12,5 +12,8 @@ extern unsigned char SpiExchange(unsigned char spi, unsigned char ch);
|
||||
extern void spi_getSem();
|
||||
extern void spi_freeSem();
|
||||
|
||||
extern void mfr_reset_up();
|
||||
extern void mfr_reset_down();
|
||||
extern void us_delay_spi(unsigned long x);
|
||||
|
||||
#endif //#ifndef __SPI_H__
|
||||
@ -52,7 +52,7 @@ read_mfrc522(uint8_t dev_cmd)
|
||||
spi_selectChip(MFRC522_SPI);
|
||||
|
||||
SpiExchange(MFRC522_SPI, ((dev_cmd << 1) & 0x7e) | 0x80);
|
||||
SpiExchange(MFRC522_SPI, ret);
|
||||
ret = SpiExchange(MFRC522_SPI, 0x00);
|
||||
|
||||
spi_unselectChip(MFRC522_SPI);
|
||||
spi_freeSem();
|
||||
@ -72,6 +72,7 @@ void read_fifo_mfrc522( pcd_register reg, uint8_t count, uint8_t *values, uint8_
|
||||
//Serial.print(F("Reading ")); Serial.print(count); Serial.println(F(" bytes from register."));
|
||||
uint8_t index = 0; // Index in values array.
|
||||
uint8_t ret = 0;
|
||||
uint8_t address = 0x80 | reg;
|
||||
|
||||
spi_selectChip(MFRC522_SPI);
|
||||
|
||||
@ -82,7 +83,7 @@ void read_fifo_mfrc522( pcd_register reg, uint8_t count, uint8_t *values, uint8_
|
||||
uint8_t mask = (0xFF << rx_align) & 0xFF;
|
||||
// Read value and tell that we want to read the same address again.
|
||||
uint8_t value;
|
||||
ret = read_mfrc522(reg);
|
||||
ret = read_mfrc522(address);
|
||||
value=ret;
|
||||
// Apply mask to both current value of values[0] and the new data in value.
|
||||
values[0] = (values[0] & ~mask) | (value & mask);
|
||||
@ -90,12 +91,12 @@ void read_fifo_mfrc522( pcd_register reg, uint8_t count, uint8_t *values, uint8_
|
||||
}
|
||||
|
||||
while (index < count) {
|
||||
ret = read_mfrc522(reg);
|
||||
ret = read_mfrc522(address);
|
||||
values[index] = ret; // Read value and tell that we want to read the same address again.
|
||||
index++;
|
||||
}
|
||||
|
||||
ret = read_mfrc522(reg);
|
||||
ret = read_mfrc522(0);
|
||||
values[index] = ret; // Read value and tell that we want to read the same address again.
|
||||
|
||||
spi_unselectChip(MFRC522_SPI); // Release slave again
|
||||
@ -174,7 +175,7 @@ pcd_calculate_crc(uint8_t *data, uint8_t length, uint8_t *result)
|
||||
}
|
||||
}
|
||||
// 89ms passed and nothing happend. Communication with the MFRC522 might be down.
|
||||
printf("89ms passed and nothing happend.\n");
|
||||
//printf("89ms passed and nothing happend.\n");
|
||||
return STATUS_TIMEOUT;
|
||||
} // End pcd_calculate_crc()
|
||||
|
||||
@ -182,7 +183,7 @@ pcd_calculate_crc(uint8_t *data, uint8_t length, uint8_t *result)
|
||||
/**
|
||||
* Performs a soft reset on the MFRC522 chip and waits for it to be ready again.
|
||||
*/
|
||||
bool
|
||||
void
|
||||
pcd_reset()
|
||||
{
|
||||
write_mfrc522(CommandReg, PCD_SoftReset); // Issue the SoftReset command.
|
||||
@ -192,17 +193,11 @@ pcd_reset()
|
||||
|
||||
//BUSYWAIT_UNTIL_ABS(RTIMER_NOW(), US_TO_RTIMERTICKS(1000));
|
||||
// Wait for the PowerDown bit in CommandReg to be cleared
|
||||
int wait=0;
|
||||
while (read_mfrc522(CommandReg) & (1<<4))
|
||||
{
|
||||
// PCD still restarting - unlikely after waiting 50ms, but better safe than sorry.
|
||||
if(wait==1000)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
wait++;
|
||||
}
|
||||
return 1;
|
||||
uint8_t count = 0;
|
||||
do {
|
||||
// Wait for the PowerDown bit in CommandReg to be cleared (max 3x50ms)
|
||||
us_delay_spi(50000);
|
||||
} while ((read_mfrc522(CommandReg) & (1 << 4)) && (++count) < 3);
|
||||
} // End pcd_reset()
|
||||
|
||||
/**
|
||||
@ -335,7 +330,7 @@ status_code
|
||||
pcd_transceive_data(uint8_t *send_data, uint8_t send_len, uint8_t *back_data, uint8_t *back_len, uint8_t *valid_bits, uint8_t rx_align, bool check_crc)
|
||||
{
|
||||
uint8_t wait_irq = 0x30; // RxIRq and IdleIRq
|
||||
uint8_t result = pcd_communicate_tith_picc(PCD_Transceive, wait_irq, send_data, send_len, back_data, back_len, valid_bits, rx_align, check_crc);
|
||||
status_code result = (status_code)pcd_communicate_tith_picc(PCD_Transceive, wait_irq, send_data, send_len, back_data, back_len, valid_bits, rx_align, check_crc);
|
||||
return result;
|
||||
} // End pcd_transceive_data()
|
||||
|
||||
@ -380,9 +375,6 @@ mifare_read( uint8_t blockAddr,uint8_t *buffer,uint8_t *bufferSize)
|
||||
return pcd_transceive_data(buffer, 4, buffer, bufferSize, NULL, 0, true);
|
||||
} // End mifare_read()
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Clears the bits given in mask from register reg.
|
||||
*/
|
||||
@ -394,8 +386,6 @@ pcd_clear_register_bit_mask(pcd_register reg, uint8_t mask)
|
||||
write_mfrc522(reg, tmp & (~mask)); // clear bit mask
|
||||
} // End pcd_clear_register_bit_mask()
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Used to exit the PCD from its authenticated state.
|
||||
* Remember to call this function after communicating with an authenticated PICC - otherwise no new communications can start.
|
||||
@ -407,10 +397,6 @@ pcd_stop_cryptol()
|
||||
pcd_clear_register_bit_mask(Status2Reg, 0x08); // Status2Reg[7..0] bits are: TempSensClear I2CForceHS reserved reserved MFCrypto1On ModemState[2:0]
|
||||
} // End pcd_stop_cryptol()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
status_code
|
||||
picc_select( uid_struct *uid, uint8_t valid_bits)
|
||||
{
|
||||
@ -421,7 +407,7 @@ picc_select( uid_struct *uid, uint8_t valid_bits)
|
||||
uint8_t count;
|
||||
uint8_t index;
|
||||
uint8_t uid_index; // The first index in uid->uidByte[] that is used in the current Cascade Level.
|
||||
uint8_t current_level_known_bits; // The number of known uid_struct bits in the current Cascade Level.
|
||||
int8_t current_level_known_bits; // The number of known uid_struct bits in the current Cascade Level.
|
||||
uint8_t buffer[9]; // The SELECT/ANTICOLLISION commands uses a 7 byte standard frame + 2 bytes CRC_A
|
||||
uint8_t bufferUsed; // The number of bytes used in the buffer, ie the number of bytes to transfer to the FIFO.
|
||||
uint8_t rx_align; // Used in BitFramingReg. Defines the bit position for the first bit received.
|
||||
@ -483,7 +469,7 @@ picc_select( uid_struct *uid, uint8_t valid_bits)
|
||||
use_cascade_tag = false; // Never used in CL3.
|
||||
break;
|
||||
default:
|
||||
printf("INTERNAL ERROR");
|
||||
//printf("INTERNAL ERROR");
|
||||
return STATUS_INTERNAL_ERROR;
|
||||
break;
|
||||
}
|
||||
@ -686,7 +672,7 @@ picc_halt_a()
|
||||
void
|
||||
picc_get_type_name(picc_type piccType)
|
||||
{
|
||||
switch (piccType)
|
||||
/*switch (piccType)
|
||||
{
|
||||
case PICC_TYPE_ISO_14443_4: printf("PICC compliant with ISO/IEC 14443-4\n"); break;
|
||||
case PICC_TYPE_ISO_18092: printf("PICC compliant with ISO/IEC 18092 (NFC)\n");break;
|
||||
@ -700,7 +686,7 @@ picc_get_type_name(picc_type piccType)
|
||||
case PICC_TYPE_NOT_COMPLETE: printf("SAK indicates uid_struct is not complete.\n");break;
|
||||
case PICC_TYPE_UNKNOWN:
|
||||
default: printf("Unknown type\n");
|
||||
}
|
||||
}*/
|
||||
} // End picc_get_type_name()
|
||||
|
||||
|
||||
@ -732,7 +718,7 @@ picc_reqa_or_wupa( uint8_t command, uint8_t *bufferATQA, uint8_t *bufferSize)
|
||||
}
|
||||
if (*bufferSize != 2 || valid_bits != 0)
|
||||
{ // ATQA must be exactly 16 bits.
|
||||
printf("STATUS_ERROR: %x\n", STATUS_ERROR);
|
||||
//printf("STATUS_ERROR: %x\n", STATUS_ERROR);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
return STATUS_OK;
|
||||
@ -790,29 +776,6 @@ picc_read_card_serial()
|
||||
return (result == STATUS_OK);
|
||||
} // End
|
||||
|
||||
uint32_t
|
||||
picc_dump_details_to_serial(uid_struct *uid)
|
||||
{
|
||||
// UID!!!
|
||||
uint32_t card_uid=0;
|
||||
uint8_t i;
|
||||
for (i = 0; i < uid->size; i++) {
|
||||
card_uid=(uid->uidByte[i] | (card_uid << 8));
|
||||
}
|
||||
|
||||
// SAK -slave acknowledge
|
||||
printf("\nCard SAK: ");
|
||||
if(uid->sak < 0x10)
|
||||
printf("0\n");
|
||||
printf("%x\n",uid->sak);
|
||||
|
||||
// (suggested) PICC type
|
||||
picc_type piccType = picc_get_type(uid->sak);
|
||||
printf("PICC type: ");
|
||||
picc_get_type_name(piccType);
|
||||
return card_uid;
|
||||
} // End picc_dump_details_to_serial()
|
||||
|
||||
status_code
|
||||
pcd_authenticate (uint8_t command, uint8_t blockAddr, MIFARE_Key *key, uid_struct *uid)
|
||||
{
|
||||
@ -839,351 +802,6 @@ pcd_authenticate (uint8_t command, uint8_t blockAddr, MIFARE_Key *key, uid_struc
|
||||
return pcd_communicate_tith_picc(pcd_mf_authent, wait_irq, &send_data[0], sizeof(send_data), NULL, NULL, NULL, 0, false);
|
||||
} // End pcd_authenticate()
|
||||
|
||||
|
||||
/**
|
||||
* Returns a __FlashStringHelper pointer to a status code name.
|
||||
*
|
||||
* @return const __FlashStringHelper *
|
||||
*/
|
||||
void
|
||||
get_status_code_name (status_code code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case STATUS_OK: printf("Success.\n"); break;
|
||||
case STATUS_ERROR: printf("Error in communication.\n"); break;
|
||||
case STATUS_COLLISION: printf("Collission detected.\n"); break;
|
||||
case STATUS_TIMEOUT: printf("Timeout in communication.\n"); break;
|
||||
case STATUS_NO_ROOM: printf("A buffer is not big enough."); break;
|
||||
case STATUS_INTERNAL_ERROR: printf("Internal error in the code. Should not happen.\n"); break;
|
||||
case STATUS_INVALID: printf("Invalid argument.\n"); break;
|
||||
case STATUS_CRC_WRONG: printf("The CRC_A does not match.\n"); break;
|
||||
case STATUS_MIFARE_NACK: printf("A MIFARE PICC responded with NAK.\n"); break;
|
||||
default: printf("Unknown error\n");
|
||||
}
|
||||
} // End get_status_code_name()
|
||||
|
||||
|
||||
/**
|
||||
* Dumps memory contents of a sector of a MIFARE Classic PICC.
|
||||
* Uses pcd_authenticate(), mifare_read() and pcd_stop_cryptol.
|
||||
* Always uses PICC_CMD_MF_AUTH_KEY_A because only Key A can always read the sector trailer access bits.
|
||||
*/
|
||||
void
|
||||
picc_dump_mifare_classic_sector_to_serial (uid_struct *uid, MIFARE_Key *key, uint8_t sector)
|
||||
{
|
||||
status_code status;
|
||||
uint8_t firstBlock; // Address of lowest address to dump actually last block dumped)
|
||||
uint8_t no_of_blocks; // Number of blocks in sector
|
||||
bool isSectorTrailer; // Set to true while handling the "last" (ie highest address) in the sector.
|
||||
|
||||
// The access bits are stored in a peculiar fashion.
|
||||
// There are four groups:
|
||||
// g[3] Access bits for the sector trailer, block 3 (for sectors 0-31) or block 15 (for sectors 32-39)
|
||||
// g[2] Access bits for block 2 (for sectors 0-31) or blocks 10-14 (for sectors 32-39)
|
||||
// g[1] Access bits for block 1 (for sectors 0-31) or blocks 5-9 (for sectors 32-39)
|
||||
// g[0] Access bits for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39)
|
||||
// Each group has access bits [C1 C2 C3]. In this code C1 is MSB and C3 is LSB.
|
||||
// The four CX bits are stored together in a nible cx and an inverted nible cx_.
|
||||
uint8_t c1, c2, c3; // Nibbles
|
||||
uint8_t c1_, c2_, c3_; // Inverted nibbles
|
||||
bool invertedError; // True if one of the inverted nibbles did not match
|
||||
uint8_t g[4]; // Access bits for each of the four groups.
|
||||
uint8_t group; // 0-3 - active group for access bits
|
||||
bool firstInGroup; // True for the first block dumped in the group
|
||||
|
||||
// Determine position and size of sector.
|
||||
if (sector < 32)
|
||||
{ // Sectors 0..31 has 4 blocks each
|
||||
no_of_blocks = 4;
|
||||
firstBlock = sector * no_of_blocks;
|
||||
}
|
||||
else if (sector < 40)
|
||||
{ // Sectors 32-39 has 16 blocks each
|
||||
no_of_blocks = 16;
|
||||
firstBlock = 128 + (sector - 32) * no_of_blocks;
|
||||
}
|
||||
else
|
||||
{ // Illegal input, no MIFARE Classic PICC has more than 40 sectors.
|
||||
return;
|
||||
}
|
||||
|
||||
// Dump blocks, highest address first.
|
||||
uint8_t byteCount,index;
|
||||
uint8_t buffer[18];
|
||||
uint8_t blockAddr;
|
||||
isSectorTrailer = true;
|
||||
invertedError = false; // Avoid "unused variable" warning.
|
||||
int8_t blockOffset;
|
||||
for (blockOffset = no_of_blocks - 1; blockOffset >= 0; blockOffset--)
|
||||
{
|
||||
blockAddr = firstBlock + blockOffset;
|
||||
// Sector number - only on first line
|
||||
if (isSectorTrailer)
|
||||
{
|
||||
if(sector < 10)
|
||||
printf(" "); // Pad with spaces
|
||||
else
|
||||
printf(" "); // Pad with spaces
|
||||
printf("%x",sector);
|
||||
printf(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
// Block number
|
||||
if(blockAddr < 10)
|
||||
printf(" "); // Pad with spaces
|
||||
else
|
||||
{
|
||||
if(blockAddr < 100)
|
||||
printf(" "); // Pad with spaces
|
||||
else
|
||||
printf(" "); // Pad with spaces
|
||||
}
|
||||
printf("%x",blockAddr);
|
||||
printf(" ");
|
||||
// Establish encrypted communications before reading the first block
|
||||
if (isSectorTrailer)
|
||||
{
|
||||
status = pcd_authenticate(PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid);
|
||||
if (status != STATUS_OK)
|
||||
{
|
||||
printf("pcd_authenticate() failed: ");
|
||||
get_status_code_name(status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Read block
|
||||
byteCount = sizeof(buffer);
|
||||
status = mifare_read(blockAddr, buffer, &byteCount);
|
||||
if (status != STATUS_OK)
|
||||
{
|
||||
printf("mifare_read() failed: ");
|
||||
get_status_code_name(status);
|
||||
continue;
|
||||
}
|
||||
// Dump data
|
||||
|
||||
for ( index = 0; index < 16; index++)
|
||||
{
|
||||
if(buffer[index] < 0x10)
|
||||
printf(" 0");
|
||||
else
|
||||
printf(" ");
|
||||
printf("%x",buffer[index]);
|
||||
if ((index % 4) == 3)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
// Parse sector trailer data
|
||||
if (isSectorTrailer)
|
||||
{
|
||||
c1 = buffer[7] >> 4;
|
||||
c2 = buffer[8] & 0xF;
|
||||
c3 = buffer[8] >> 4;
|
||||
c1_ = buffer[6] & 0xF;
|
||||
c2_ = buffer[6] >> 4;
|
||||
c3_ = buffer[7] & 0xF;
|
||||
invertedError = (c1 != (~c1_ & 0xF)) || (c2 != (~c2_ & 0xF)) || (c3 != (~c3_ & 0xF));
|
||||
g[0] = ((c1 & 1) << 2) | ((c2 & 1) << 1) | ((c3 & 1) << 0);
|
||||
g[1] = ((c1 & 2) << 1) | ((c2 & 2) << 0) | ((c3 & 2) >> 1);
|
||||
g[2] = ((c1 & 4) << 0) | ((c2 & 4) >> 1) | ((c3 & 4) >> 2);
|
||||
g[3] = ((c1 & 8) >> 1) | ((c2 & 8) >> 2) | ((c3 & 8) >> 3);
|
||||
isSectorTrailer = false;
|
||||
}
|
||||
|
||||
// Which access group is this block in?
|
||||
if (no_of_blocks == 4)
|
||||
{
|
||||
group = blockOffset;
|
||||
firstInGroup = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
group = blockOffset / 5;
|
||||
firstInGroup = (group == 3) || (group != (blockOffset + 1) / 5);
|
||||
}
|
||||
|
||||
if (firstInGroup)
|
||||
{
|
||||
// Print access bits
|
||||
printf(" [ ");
|
||||
printf("%d ",(g[group] >> 2) & 1);
|
||||
printf("%d ",(g[group] >> 1) & 1);
|
||||
printf("%d ",(g[group] >> 0) & 1);
|
||||
printf("] \n");
|
||||
if (invertedError) {
|
||||
printf(" Inverted access bits did not match!\n ");
|
||||
}
|
||||
}
|
||||
|
||||
if (group != 3 && (g[group] == 1 || g[group] == 6))
|
||||
{ // Not a sector trailer, a value block
|
||||
int32_t value;
|
||||
value = ((int32_t)(buffer[3]<<24) | (int32_t)(buffer[2]<<16) | (int32_t)(buffer[1]<<8) | (int32_t)buffer[0]);
|
||||
//printf(" Value=0x"); printf("[%"PRIu32"]\n",value);
|
||||
//printf(" Adr=0x"); printf("%x\n",buffer[12]);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} // End picc_dump_mifare_classic_sector_to_serial()
|
||||
|
||||
|
||||
/**
|
||||
* Dumps memory contents of a MIFARE Ultralight PICC.
|
||||
*/
|
||||
void
|
||||
picc_dump_mifare_ultralight_to_serial()
|
||||
{
|
||||
status_code status;
|
||||
uint8_t byteCount;
|
||||
uint8_t buffer[18];
|
||||
uint8_t page,offset,index,i;
|
||||
|
||||
printf("Page 0 1 2 3\n");
|
||||
// Try the mpages of the original Ultralight. Ultralight C has more pages.
|
||||
for ( page = 0; page < 16; page +=4)
|
||||
{ // Read returns data for 4 pages at a time.
|
||||
// Read pages
|
||||
byteCount = sizeof(buffer);
|
||||
status = mifare_read(page, buffer, &byteCount);
|
||||
if (status != STATUS_OK)
|
||||
{
|
||||
printf("mifare_read() failed: ");
|
||||
get_status_code_name(status);
|
||||
break;
|
||||
}
|
||||
// Dump data
|
||||
for (offset = 0; offset < 4; offset++)
|
||||
{
|
||||
i = page + offset;
|
||||
if(i < 10)
|
||||
printf(" "); // Pad with spaces
|
||||
else
|
||||
printf(" "); // Pad with spaces
|
||||
printf("%x",i);
|
||||
printf(" ");
|
||||
for (index = 0; index < 4; index++)
|
||||
{
|
||||
i = 4 * offset + index;
|
||||
if(buffer[i] < 0x10)
|
||||
printf(" 0");
|
||||
else
|
||||
printf(" ");
|
||||
printf("%x",buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
} // End picc_dump_mifare_ultralight_to_serial()
|
||||
|
||||
|
||||
/**
|
||||
* Dumps memory contents of a MIFARE Classic PICC.
|
||||
* On success the PICC is halted after dumping the data.
|
||||
*/
|
||||
void
|
||||
picc_dump_mifare_classic_to_serial( uid_struct *uid, picc_type piccType, MIFARE_Key *key)
|
||||
{
|
||||
uint8_t no_of_sectors = 0,i;
|
||||
switch (piccType)
|
||||
{
|
||||
case PICC_TYPE_MIFARE_MINI:
|
||||
// Has 5 sectors * 4 blocks/sector * 16 bytes/block = 320 bytes.
|
||||
no_of_sectors = 5;
|
||||
break;
|
||||
|
||||
case PICC_TYPE_MIFARE_1K:
|
||||
// Has 16 sectors * 4 blocks/sector * 16 bytes/block = 1024 bytes.
|
||||
no_of_sectors = 16;
|
||||
break;
|
||||
|
||||
case PICC_TYPE_MIFARE_4K:
|
||||
// Has (32 sectors * 4 blocks/sector + 8 sectors * 16 blocks/sector) * 16 bytes/block = 4096 bytes.
|
||||
no_of_sectors = 40;
|
||||
break;
|
||||
|
||||
default: // Should not happen. Ignore.
|
||||
break;
|
||||
}
|
||||
|
||||
// Dump sectors, highest address first.
|
||||
if (no_of_sectors)
|
||||
{
|
||||
printf("Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits\n");
|
||||
for (i = no_of_sectors - 1; i >= 0; i--)
|
||||
{
|
||||
picc_dump_mifare_classic_sector_to_serial(uid, key, i);
|
||||
}
|
||||
}
|
||||
picc_halt_a(); // Halt the PICC before stopping the encrypted session.
|
||||
pcd_stop_cryptol();
|
||||
} // End picc_dump_mifare_classic_to_serial()
|
||||
|
||||
uint32_t
|
||||
picc_dump_to_serial(uid_struct *uid)
|
||||
{
|
||||
|
||||
|
||||
// Dump UID, SAK and Type
|
||||
return picc_dump_details_to_serial(uid);
|
||||
} // End picc_dump_to_serial()
|
||||
|
||||
/*--------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void picc_dump_contents(uid_struct *uid)
|
||||
{
|
||||
MIFARE_Key key;
|
||||
uint8_t i;
|
||||
|
||||
picc_type piccType = picc_get_type(uid->sak);
|
||||
switch (piccType) {
|
||||
case PICC_TYPE_MIFARE_MINI:
|
||||
case PICC_TYPE_MIFARE_1K:
|
||||
case PICC_TYPE_MIFARE_4K:
|
||||
// All keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
|
||||
|
||||
for ( i = 0; i < 6; i++) {
|
||||
key.keyByte[i] = 0xFF;
|
||||
}
|
||||
picc_dump_mifare_classic_to_serial(uid, piccType, &key);
|
||||
break;
|
||||
|
||||
case PICC_TYPE_MIFARE_UL:
|
||||
picc_dump_mifare_ultralight_to_serial();
|
||||
break;
|
||||
|
||||
case PICC_TYPE_ISO_14443_4:
|
||||
printf("----------------------1\n");
|
||||
break;
|
||||
case PICC_TYPE_MIFARE_DESFIRE:
|
||||
printf("----------------------2\n");
|
||||
break;
|
||||
case PICC_TYPE_ISO_18092:
|
||||
printf("----------------------3\n");
|
||||
break;
|
||||
case PICC_TYPE_MIFARE_PLUS:
|
||||
printf("----------------------4\n");
|
||||
break;
|
||||
case PICC_TYPE_TNP3XXX:
|
||||
printf("Dumping memory contents not implemented for that PICC type.");
|
||||
break;
|
||||
|
||||
case PICC_TYPE_UNKNOWN:
|
||||
case PICC_TYPE_NOT_COMPLETE:
|
||||
default:
|
||||
break; printf(" No memory dump here \n");
|
||||
}
|
||||
|
||||
picc_halt_a(); // Already done if it was a MIFARE Classic PICC.
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
antenna_on()
|
||||
{
|
||||
@ -1201,12 +819,16 @@ antenna_on()
|
||||
bool
|
||||
pcd_initialization()
|
||||
{
|
||||
printf("pcd_initialization()\n");
|
||||
//printf("pcd_initialization()\n");
|
||||
|
||||
mfr_reset_down();
|
||||
us_delay_spi(2);
|
||||
mfr_reset_up();
|
||||
|
||||
us_delay_spi(50000);
|
||||
|
||||
pcd_reset();
|
||||
|
||||
if(pcd_reset()==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Reset baud rates
|
||||
write_mfrc522(TxModeReg, 0x00);
|
||||
write_mfrc522(RxModeReg, 0xb0);
|
||||
@ -1226,7 +848,7 @@ pcd_initialization()
|
||||
write_mfrc522(FIFOLevelReg,0x00);
|
||||
antenna_on(); // Enable the antenna driver pins TX1 and TX2 (they were disabled by the reset)
|
||||
|
||||
printf("initialization Done()\n");
|
||||
//printf("initialization Done()\n");
|
||||
|
||||
return 1;
|
||||
} // End pcd_initialization() */
|
||||
|
||||
@ -212,7 +212,7 @@ void read_fifo_mfrc522( pcd_register reg, uint8_t count, uint8_t *values, uint8_
|
||||
picc_type picc_get_type(uint8_t sak);
|
||||
void pcd_set_register_bit_mask(pcd_register reg, uint8_t mask);
|
||||
status_code pcd_calculate_crc(uint8_t *data, uint8_t length, uint8_t *result);
|
||||
bool pcd_reset();
|
||||
void pcd_reset();
|
||||
status_code pcd_communicate_tith_picc(uint8_t command, uint8_t wait_irq, uint8_t *send_data, uint8_t send_len, uint8_t *back_data, uint8_t *back_len, uint8_t *valid_bits, uint8_t rx_align, bool check_crc);
|
||||
status_code pcd_transceive_data(uint8_t *send_data, uint8_t send_len, uint8_t *back_data, uint8_t *back_len, uint8_t *valid_bits, uint8_t rx_align, bool check_crc);
|
||||
status_code mifare_read( uint8_t blockAddr,uint8_t *buffer,uint8_t *bufferSize);
|
||||
@ -225,13 +225,9 @@ status_code picc_reqa_or_wupa( uint8_t command, uint8_t *bufferATQA, uint8_t *bu
|
||||
status_code picc_request_a( uint8_t *bufferATQA,uint8_t *bufferSize);
|
||||
bool picc_is_new_card_present();
|
||||
bool picc_read_card_serial();
|
||||
uint32_t picc_dump_details_to_serial(uid_struct *uid);
|
||||
status_code pcd_authenticate (uint8_t command, uint8_t blockAddr, MIFARE_Key *key, uid_struct *uid);
|
||||
void get_status_code_name (status_code code);
|
||||
void picc_dump_mifare_classic_sector_to_serial (uid_struct *uid, MIFARE_Key *key, uint8_t sector);
|
||||
void picc_dump_mifare_ultralight_to_serial();
|
||||
void picc_dump_mifare_classic_to_serial( uid_struct *uid, picc_type piccType, MIFARE_Key *key);
|
||||
uint32_t picc_dump_to_serial(uid_struct *uid);
|
||||
|
||||
void antenna_on();
|
||||
bool pcd_initialization();
|
||||
#endif
|
||||
@ -25,7 +25,7 @@ if not "%~1" == "" goto debugFile
|
||||
|
||||
@echo on
|
||||
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" --backend -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" --backend -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
|
||||
@echo off
|
||||
goto end
|
||||
@ -34,7 +34,7 @@ goto end
|
||||
|
||||
@echo on
|
||||
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" "--debug_file=%~1" --backend -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" "--debug_file=%~1" --backend -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
|
||||
@echo off
|
||||
:end
|
||||
@ -23,9 +23,9 @@
|
||||
|
||||
if ($debugfile -eq "")
|
||||
{
|
||||
& "C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" --backend -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
& "C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" --backend -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
}
|
||||
else
|
||||
{
|
||||
& "C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" --debug_file=$debugfile --backend -f "C:\git_work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
& "C:\Program Files\IAR Systems\Embedded Workbench 9.0\common\bin\cspybat" -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.general.xcl" --debug_file=$debugfile --backend -f "C:\work\solarium.vlad\settings\sk-mlpc2368.Solarium_Vlad.driver.xcl"
|
||||
}
|
||||
|
||||
@ -12,7 +12,11 @@
|
||||
|
||||
"--device=LPC2368"
|
||||
|
||||
"--multicore_nr_of_cores=1"
|
||||
"--drv_communication=USB0"
|
||||
|
||||
"--drv_interface_speed=auto"
|
||||
|
||||
"--jlink_initial_speed=1000"
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\bin\armPROC.dll"
|
||||
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\bin\armSIM2.dll"
|
||||
"C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\bin\armJLINK.dll"
|
||||
|
||||
"C:\git_work\solarium.vlad\Solarium Vlad\Exe\sk_mlpc2368.out"
|
||||
"C:\work\solarium.vlad\Solarium Vlad\Exe\sk_mlpc2368.out"
|
||||
|
||||
--plugin="C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\bin\armbat.dll"
|
||||
|
||||
--device_macro="C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\config\debugger\NXP\LPC23xx.dmac"
|
||||
|
||||
--flash_loader="C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\config\flashloader\NXP\FlashNXPLPC512K2.board"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -30,12 +30,6 @@
|
||||
<SumEnabled>0</SumEnabled>
|
||||
<ShowTimeSum>1</ShowTimeSum>
|
||||
</DataLog>
|
||||
<DisassembleMode>
|
||||
<mode>0</mode>
|
||||
</DisassembleMode>
|
||||
<Breakpoints2>
|
||||
<Count>0</Count>
|
||||
</Breakpoints2>
|
||||
<Interrupts>
|
||||
<Enabled>1</Enabled>
|
||||
</Interrupts>
|
||||
@ -46,13 +40,76 @@
|
||||
<TypeViol>0</TypeViol>
|
||||
<Stop>1</Stop>
|
||||
</MemConfig>
|
||||
<Aliases>
|
||||
<Count>0</Count>
|
||||
<SuppressDialog>0</SuppressDialog>
|
||||
</Aliases>
|
||||
<Simulator>
|
||||
<Freq>10000000</Freq>
|
||||
<FreqHi>0</FreqHi>
|
||||
<MultiCoreRunAll>1</MultiCoreRunAll>
|
||||
</Simulator>
|
||||
<PlDriver>
|
||||
<MemConfigValue>C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\CONFIG\debugger\NXP\LPC2368.ddf</MemConfigValue>
|
||||
<FirstRun>0</FirstRun>
|
||||
</PlDriver>
|
||||
<DebugChecksum>
|
||||
<Checksum>904050673</Checksum>
|
||||
</DebugChecksum>
|
||||
<Exceptions>
|
||||
<StopOnUncaught>_ 0</StopOnUncaught>
|
||||
<StopOnThrow>_ 0</StopOnThrow>
|
||||
</Exceptions>
|
||||
<Disassembly>
|
||||
<MixedMode>1</MixedMode>
|
||||
<InstrCount>0</InstrCount>
|
||||
</Disassembly>
|
||||
<CallStack>
|
||||
<ShowArgs>0</ShowArgs>
|
||||
</CallStack>
|
||||
<JLinkDriver>
|
||||
<WatchCond>_ 0</WatchCond>
|
||||
<Watch0>_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0</Watch0>
|
||||
<Watch1>_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0</Watch1>
|
||||
<jlinkResetStyle>12</jlinkResetStyle>
|
||||
<jlinkResetStrategy>0</jlinkResetStrategy>
|
||||
<LeaveTargetRunning>_ 0</LeaveTargetRunning>
|
||||
<CStepIntDis>_ 0</CStepIntDis>
|
||||
</JLinkDriver>
|
||||
<ArmDriver>
|
||||
<EnableCache>0</EnableCache>
|
||||
</ArmDriver>
|
||||
<DriverProfiling>
|
||||
<Enabled>0</Enabled>
|
||||
<Mode>1</Mode>
|
||||
<Graph>0</Graph>
|
||||
<Symbiont>0</Symbiont>
|
||||
</DriverProfiling>
|
||||
<CallStackLog>
|
||||
<Enabled>0</Enabled>
|
||||
</CallStackLog>
|
||||
<CallStackStripe>
|
||||
<ShowTiming>1</ShowTiming>
|
||||
</CallStackStripe>
|
||||
<Trace2>
|
||||
<Enabled>0</Enabled>
|
||||
<ShowSource>0</ShowSource>
|
||||
</Trace2>
|
||||
<LogFile>
|
||||
<LoggingEnabled>_ 0</LoggingEnabled>
|
||||
<LogFile>_ ""</LogFile>
|
||||
<Category>_ 0</Category>
|
||||
</LogFile>
|
||||
<DisassembleMode>
|
||||
<mode>0</mode>
|
||||
</DisassembleMode>
|
||||
<Breakpoints2>
|
||||
<Bp0>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.628.19" 0 0 1 "" 0 "" 0</Bp0>
|
||||
<Bp1>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.626.21" 0 0 1 "" 0 "" 0</Bp1>
|
||||
<Count>2</Count>
|
||||
</Breakpoints2>
|
||||
<Aliases>
|
||||
<Count>0</Count>
|
||||
<SuppressDialog>0</SuppressDialog>
|
||||
</Aliases>
|
||||
<TermIOLog>
|
||||
<LoggingEnabled>_ 0</LoggingEnabled>
|
||||
<LogFile>_ ""</LogFile>
|
||||
</TermIOLog>
|
||||
</settings>
|
||||
|
||||
File diff suppressed because one or more lines are too long
4884
sk-mlpc2368.dep
4884
sk-mlpc2368.dep
File diff suppressed because it is too large
Load Diff
@ -6136,7 +6136,7 @@
|
||||
</option>
|
||||
<option>
|
||||
<name>OCDynDriverList</name>
|
||||
<state>ARMSIM_ID</state>
|
||||
<state>JLINK_ID</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>OCLastSavedByProductVersion</name>
|
||||
@ -6934,7 +6934,7 @@
|
||||
</option>
|
||||
<option>
|
||||
<name>CCJLinkInterfaceRadio</name>
|
||||
<state>1</state>
|
||||
<state>0</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCJLinkResetList</name>
|
||||
|
||||
@ -4721,7 +4721,7 @@
|
||||
</option>
|
||||
<option>
|
||||
<name>CCOptLevel</name>
|
||||
<state>1</state>
|
||||
<state>0</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCOptStrategy</name>
|
||||
@ -4730,7 +4730,7 @@
|
||||
</option>
|
||||
<option>
|
||||
<name>CCOptLevelSlave</name>
|
||||
<state>1</state>
|
||||
<state>0</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCPosIndRopi</name>
|
||||
@ -5021,7 +5021,7 @@
|
||||
<data>
|
||||
<extensions></extensions>
|
||||
<cmdline></cmdline>
|
||||
<hasPrio>16</hasPrio>
|
||||
<hasPrio>1</hasPrio>
|
||||
<buildSequence>inputOutputBased</buildSequence>
|
||||
</data>
|
||||
</settings>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user