mirror of
https://github.com/dimoniche/solarium.vlad.git
synced 2026-01-30 04:53:30 +03:00
Запись прошла
This commit is contained in:
parent
c3df51d298
commit
2aab75693e
@ -737,16 +737,32 @@ void AppVladEventProcess(CPU_INT32U event)
|
||||
|
||||
uint8_t block = 4;
|
||||
uint8_t len = 18;
|
||||
uint8_t buffer1[18];
|
||||
uint8_t buffer1[18]= {
|
||||
0x01, 0x02, 0x03, 0x04, // 1, 2, 3, 4,
|
||||
0x05, 0x06, 0x07, 0x08, // 5, 6, 7, 8,
|
||||
0x09, 0x0a, 0xff, 0x0b, // 9, 10, 255, 11,
|
||||
0x0c, 0x0d, 0x0e, 0x0f // 12, 13, 14, 15
|
||||
};
|
||||
uint8_t buffer2[18];
|
||||
|
||||
status_code status = pcd_authenticate(PICC_CMD_MF_AUTH_KEY_A, 4, &key, get_uid());
|
||||
if (status != STATUS_OK) {
|
||||
return;
|
||||
}
|
||||
status = mifare_read(block, buffer1, &len);
|
||||
|
||||
status = (status_code)mifare_write(block, buffer1, 16);
|
||||
if (status != STATUS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
status = mifare_read(block, buffer2, &len);
|
||||
if (status != STATUS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
picc_halt_a();
|
||||
pcd_stop_cryptol();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -325,10 +325,6 @@ pcd_communicate_tith_picc(uint8_t command, uint8_t wait_irq, uint8_t *send_data,
|
||||
return STATUS_OK;
|
||||
} // End pcd_communicate_tith_picc()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for communicating with PICCs
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -388,6 +384,94 @@ 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()
|
||||
|
||||
/**
|
||||
* Wrapper for MIFARE protocol communication.
|
||||
* Adds CRC_A, executes the Transceive command and checks that the response is MF_ACK or a timeout.
|
||||
*
|
||||
* @return STATUS_OK on success, STATUS_??? otherwise.
|
||||
*/
|
||||
status_code pcd_mifare_transceive( uint8_t *sendData, ///< Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A.
|
||||
uint8_t sendLen, ///< Number of bytes in sendData.
|
||||
bool acceptTimeout ///< True => A timeout is also success
|
||||
) {
|
||||
status_code result;
|
||||
uint8_t cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A.
|
||||
|
||||
// Sanity check
|
||||
if (sendData == NULL || sendLen > 16) {
|
||||
return STATUS_INVALID;
|
||||
}
|
||||
|
||||
// Copy sendData[] to cmdBuffer[] and add CRC_A
|
||||
memcpy(cmdBuffer, sendData, sendLen);
|
||||
result = pcd_calculate_crc(cmdBuffer, sendLen, &cmdBuffer[sendLen]);
|
||||
if (result != STATUS_OK) {
|
||||
return result;
|
||||
}
|
||||
sendLen += 2;
|
||||
|
||||
// Transceive the data, store the reply in cmdBuffer[]
|
||||
uint8_t waitIRq = 0x30; // RxIRq and IdleIRq
|
||||
uint8_t cmdBufferSize = sizeof(cmdBuffer);
|
||||
uint8_t validBits = 0;
|
||||
result = pcd_communicate_tith_picc(PCD_Transceive, waitIRq, cmdBuffer, sendLen, cmdBuffer, &cmdBufferSize, &validBits, 0, false);
|
||||
if (acceptTimeout && result == STATUS_TIMEOUT) {
|
||||
return STATUS_OK;
|
||||
}
|
||||
if (result != STATUS_OK) {
|
||||
return result;
|
||||
}
|
||||
// The PICC must reply with a 4 bit ACK
|
||||
if (cmdBufferSize != 1 || validBits != 4) {
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if (cmdBuffer[0] != MF_ACK) {
|
||||
return STATUS_MIFARE_NACK;
|
||||
}
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes 16 bytes to the active PICC.
|
||||
*
|
||||
* For MIFARE Classic the sector containing the block must be authenticated before calling this function.
|
||||
*
|
||||
* For MIFARE Ultralight the operation is called "COMPATIBILITY WRITE".
|
||||
* Even though 16 bytes are transferred to the Ultralight PICC, only the least significant 4 bytes (bytes 0 to 3)
|
||||
* are written to the specified address. It is recommended to set the remaining bytes 04h to 0Fh to all logic 0.
|
||||
* *
|
||||
* @return STATUS_OK on success, STATUS_??? otherwise.
|
||||
*/
|
||||
status_code mifare_write(uint8_t blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to.
|
||||
uint8_t *buffer, ///< The 16 bytes to write to the PICC
|
||||
uint8_t bufferSize ///< Buffer size, must be at least 16 bytes. Exactly 16 bytes are written.
|
||||
) {
|
||||
status_code result;
|
||||
|
||||
// Sanity check
|
||||
if (buffer == NULL|| bufferSize < 16) {
|
||||
return STATUS_NO_ROOM;
|
||||
}
|
||||
|
||||
// Mifare Classic protocol requires two communications to perform a write.
|
||||
// Step 1: Tell the PICC we want to write to block blockAddr.
|
||||
uint8_t cmdBuffer[2];
|
||||
cmdBuffer[0] = PICC_CMD_MF_WRITE;
|
||||
cmdBuffer[1] = blockAddr;
|
||||
result = pcd_mifare_transceive(cmdBuffer, 2, false); // Adds CRC_A and checks that the response is MF_ACK.
|
||||
if (result != STATUS_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Step 2: Transfer the data
|
||||
result = pcd_mifare_transceive(buffer, bufferSize, false); // Adds CRC_A and checks that the response is MF_ACK.
|
||||
if (result != STATUS_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return STATUS_OK;
|
||||
} // End MIFARE_Write()
|
||||
|
||||
/**
|
||||
* Clears the bits given in mask from register reg.
|
||||
*/
|
||||
|
||||
@ -216,6 +216,7 @@ 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);
|
||||
status_code mifare_write(uint8_t blockAddr, uint8_t *buffer, uint8_t bufferSize);
|
||||
void pcd_clear_register_bit_mask(pcd_register reg, uint8_t mask);
|
||||
void pcd_stop_cryptol();
|
||||
status_code picc_select( uid_struct *uid, uint8_t valid_bits);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -50,7 +50,7 @@
|
||||
<MemConfigValue>C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\CONFIG\debugger\NXP\LPC2368.ddf</MemConfigValue>
|
||||
</PlDriver>
|
||||
<DebugChecksum>
|
||||
<Checksum>1659803731</Checksum>
|
||||
<Checksum>2582529319</Checksum>
|
||||
</DebugChecksum>
|
||||
<Exceptions>
|
||||
<StopOnUncaught>_ 0</StopOnUncaught>
|
||||
@ -87,7 +87,8 @@
|
||||
<Bp1>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\rfid-spi.c}.321.7" 0 0 1 "" 0 "" 0</Bp1>
|
||||
<Bp2>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\rfid-spi.c}.190.3" 0 0 1 "" 0 "" 0</Bp2>
|
||||
<Bp3>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.738.31" 0 0 1 "" 0 "" 0</Bp3>
|
||||
<Count>4</Count>
|
||||
<Bp4>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.763.23" 0 0 1 "" 0 "" 0</Bp4>
|
||||
<Count>5</Count>
|
||||
</Breakpoints2>
|
||||
<TermIOLog>
|
||||
<LoggingEnabled>_ 0</LoggingEnabled>
|
||||
|
||||
File diff suppressed because one or more lines are too long
3698
sk-mlpc2368.dep
3698
sk-mlpc2368.dep
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user