Major changes to hf mf mifare

This commit is contained in:
martin.holst@gmail.com 2013-06-26 21:13:02 +00:00
commit e772353f72
7 changed files with 365 additions and 99 deletions

View file

@ -28,7 +28,8 @@ int CmdHF14AMifare(const char *Cmd)
UsbCommand c = {CMD_READER_MIFARE, {(uint32_t)bytes_to_num(keyBlock, 4), 0, 0}};
start:
SendCommand(&c);
clearCommandBuffer();
SendCommand(&c);
//flush queue
while (ukbhit()) getchar();
@ -41,7 +42,7 @@ start:
// wait cycle
while (true) {
printf(".");
//printf(".");
fflush(stdout);
if (ukbhit()) {
getchar();

View file

@ -27,4 +27,29 @@
int CmdHFMF(const char *Cmd);
int CmdHF14AMfDbg(const char* cmd);
int CmdHF14AMfRdBl(const char* cmd);
int CmdHF14AMfRdSc(const char* cmd);
int CmdHF14AMfDump(const char* cmd);
int CmdHF14AMfRestore(const char* cmd);
int CmdHF14AMfWrBl(const char* cmd);
int CmdHF14AMfChk(const char* cmd);
int CmdHF14AMifare(const char* cmd);
int CmdHF14AMfNested(const char* cmd);
int CmdHF14AMfSniff(const char* cmd);
int CmdHF14AMf1kSim(const char* cmd);
int CmdHF14AMfEClear(const char* cmd);
int CmdHF14AMfEGet(const char* cmd);
int CmdHF14AMfESet(const char* cmd);
int CmdHF14AMfELoad(const char* cmd);
int CmdHF14AMfESave(const char* cmd);
int CmdHF14AMfECFill(const char* cmd);
int CmdHF14AMfEKeyPrn(const char* cmd);
int CmdHF14AMfCSetUID(const char* cmd);
int CmdHF14AMfCSetBlk(const char* cmd);
int CmdHF14AMfCGetBlk(const char* cmd);
int CmdHF14AMfCGetSc(const char* cmd);
int CmdHF14AMfCLoad(const char* cmd);
int CmdHF14AMfCSave(const char* cmd);
#endif

View file

@ -25,6 +25,7 @@
#include "cmdmain.h"
#include "util.h"
unsigned int current_command = CMD_UNKNOWN;
//unsigned int received_command = CMD_UNKNOWN;
//UsbCommand current_response;
@ -64,6 +65,8 @@ int CmdQuit(const char *Cmd)
exit(0);
return 0;
}
int getCommand(UsbCommand* response);
void storeCommand(UsbCommand *command);
/**
* Waits for a certain response type. This method waits for a maximum of
* ms_timeout milliseconds for a specified response command.
@ -83,9 +86,13 @@ bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeou
// Wait until the command is received
for(size_t dm_seconds=0; dm_seconds < ms_timeout/10; dm_seconds++) {
if(getCommand(response) && response->cmd == cmd){
while(getCommand(response))
{
if(response->cmd == cmd){
//We got what we expected
return true;
}
}
msleep(10); // XXX ugh
if (dm_seconds == 200) { // Two seconds elapsed
@ -205,6 +212,19 @@ void UsbCommandReceived(UsbCommand *UC)
storeCommand(UC);
}
/**
* @brief This method should be called when sending a new command to the pm3. In case any old
* responses from previous commands are stored in the buffer, a call to this method should clear them.
* A better method could have been to have explicit command-ACKS, so we can know which ACK goes to which
* operation. Right now we'll just have to live with this.
*/
void clearCommandBuffer()
{
//This is a very simple operation
cmd_tail = cmd_head;
}
/**
* @brief storeCommand stores a USB command in a circular buffer
* @param UC

View file

@ -17,5 +17,5 @@ void UsbCommandReceived(UsbCommand *UC);
void CommandReceived(char *Cmd);
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
bool WaitForResponse(uint32_t cmd, UsbCommand* response);
void clearCommandBuffer();
#endif