Make Style and remove some comments.

This commit is contained in:
Thomas Sutter 2019-10-17 13:48:34 +02:00
parent 97f85ba50a
commit 376e367d45
4 changed files with 49 additions and 49 deletions

View file

@ -365,14 +365,14 @@ void SendStatus(void) {
Dbprintf(" Slow clock..............%d Hz", (16 * MAINCK) / mainf); Dbprintf(" Slow clock..............%d Hz", (16 * MAINCK) / mainf);
uint32_t delta_time = 0; uint32_t delta_time = 0;
uint32_t start_time = GetTickCount(); uint32_t start_time = GetTickCount();
#define SLCK_CHECK_MS 50 #define SLCK_CHECK_MS 50
SpinDelay(SLCK_CHECK_MS); SpinDelay(SLCK_CHECK_MS);
delta_time = GetTickCountDelta(start_time); delta_time = GetTickCountDelta(start_time);
if ((delta_time < SLCK_CHECK_MS - 1) || (delta_time > SLCK_CHECK_MS + 1)) { if ((delta_time < SLCK_CHECK_MS - 1) || (delta_time > SLCK_CHECK_MS + 1)) {
// error > 2% with SLCK_CHECK_MS=50 // error > 2% with SLCK_CHECK_MS=50
Dbprintf(_RED_(" Slow Clock speed change detected, TIA needed")); Dbprintf(_RED_(" Slow Clock speed change detected, TIA needed"));
Dbprintf(_YELLOW_(" Slow Clock actual speed seems closer to %d kHz"), Dbprintf(_YELLOW_(" Slow Clock actual speed seems closer to %d kHz"),
(16 * MAINCK / 1000) / mainf * delta_time / SLCK_CHECK_MS); (16 * MAINCK / 1000) / mainf * delta_time / SLCK_CHECK_MS);
} }
DbpString(_BLUE_("Installed StandAlone Mode")); DbpString(_BLUE_("Installed StandAlone Mode"));
ModInfo(); ModInfo();

View file

@ -14,17 +14,17 @@
// FeliCa timings // FeliCa timings
// minimum time between the start bits of consecutive transfers from reader to tag: 6800 carrier (13.56MHz) cycles // minimum time between the start bits of consecutive transfers from reader to tag: 6800 carrier (13.56MHz) cycles
#ifndef FELICA_REQUEST_GUARD_TIME #ifndef FELICA_REQUEST_GUARD_TIME
# define FELICA_REQUEST_GUARD_TIME (6800/16 + 1) // 426 # define FELICA_REQUEST_GUARD_TIME (6800/16 + 1)
#endif #endif
// FRAME DELAY TIME 2672 carrier cycles // FRAME DELAY TIME 2672 carrier cycles
#ifndef FELICA_FRAME_DELAY_TIME #ifndef FELICA_FRAME_DELAY_TIME
# define FELICA_FRAME_DELAY_TIME (2672/16 + 1) // 168 # define FELICA_FRAME_DELAY_TIME (2672/16 + 1)
#endif #endif
#ifndef DELAY_AIR2ARM_AS_READER #ifndef DELAY_AIR2ARM_AS_READER
#define DELAY_AIR2ARM_AS_READER (3 + 16 + 8 + 8*16 + 4*16 - 8*16) // 27 + 128 + 64 - 128 = 91 #define DELAY_AIR2ARM_AS_READER (3 + 16 + 8 + 8*16 + 4*16 - 8*16)
#endif #endif
#ifndef DELAY_ARM2AIR_AS_READER #ifndef DELAY_ARM2AIR_AS_READER
#define DELAY_ARM2AIR_AS_READER (4*16 + 8*16 + 8 + 8 + 1) // 64 + 128 + 17 = 209 #define DELAY_ARM2AIR_AS_READER (4*16 + 8*16 + 8 + 8 + 1)
#endif #endif
// CRC skips two first sync bits in data buffer // CRC skips two first sync bits in data buffer
@ -203,10 +203,10 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
// 0xff = system code service // 0xff = system code service
// 0xff = system code service // 0xff = system code service
// 0x00 = request code // 0x00 = request code
// b7 = automatic switching of data rate // b7 = automatic switching of data rate
// b6-b2 = reserved // b6-b2 = reserved
// b1 = fc/32 (414kbps) // b1 = fc/32 (414kbps)
// b0 = fc/64 (212kbps) // b0 = fc/64 (212kbps)
// 0x00 = timeslot // 0x00 = timeslot
// 0x09 0x21 = crc // 0x09 0x21 = crc
static uint8_t poll[10] = {0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xFF, 0xFF, 0x00, 0x00, 0x09, 0x21}; static uint8_t poll[10] = {0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xFF, 0xFF, 0x00, 0x00, 0x09, 0x21};
@ -228,22 +228,22 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
} while (--len); } while (--len);
// timed-out // timed-out
if (len == 0){ if (len == 0) {
if (DBGLEVEL > 3) if (DBGLEVEL > 3)
Dbprintf("Error: Time out card selection!"); Dbprintf("Error: Time out card selection!");
return 1; return 1;
} }
// wrong answer // wrong answer
if (FelicaFrame.framebytes[3] != FELICA_POLL_ACK){ if (FelicaFrame.framebytes[3] != FELICA_POLL_ACK) {
if (DBGLEVEL > 3) if (DBGLEVEL > 3)
Dbprintf("Error: Wrong answer selecting card!"); Dbprintf("Error: Wrong answer selecting card!");
return 2; return 2;
} }
// VALIDATE CRC residue is 0, hence if crc is a value it failed. // VALIDATE CRC residue is 0, hence if crc is a value it failed.
if (!check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2)){ if (!check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2)) {
if (DBGLEVEL > 3){ if (DBGLEVEL > 3) {
Dbprintf("Error: CRC check failed!"); Dbprintf("Error: CRC check failed!");
Dbprintf("CRC check was done on Frame: "); Dbprintf("CRC check was done on Frame: ");
Dbhexdump(FelicaFrame.len - 2, FelicaFrame.framebytes + 2, 0); Dbhexdump(FelicaFrame.len - 2, FelicaFrame.framebytes + 2, 0);
@ -263,7 +263,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
memcpy(card->uid, card->IDm + 2, 6); memcpy(card->uid, card->IDm + 2, 6);
memcpy(card->iccode, card->PMm, 2); memcpy(card->iccode, card->PMm, 2);
memcpy(card->mrt, card->PMm + 2, 6); memcpy(card->mrt, card->PMm + 2, 6);
if (DBGLEVEL > 3){ if (DBGLEVEL > 3) {
Dbprintf("Received Frame: "); Dbprintf("Received Frame: ");
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0); Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
} }
@ -366,7 +366,7 @@ static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing,
} }
// sending data with sync bytes // sending data with sync bytes
c = 0; c = 0;
if (DBGLEVEL > 3){ if (DBGLEVEL > 3) {
Dbprintf("Sending frame:"); Dbprintf("Sending frame:");
Dbhexdump(len, frame, 0); Dbhexdump(len, frame, 0);
} }
@ -490,7 +490,7 @@ static void iso18092_setup(uint8_t fpga_minor_mode) {
LED_D_ON(); LED_D_ON();
} }
void felica_reset_frame_mode(){ void felica_reset_frame_mode() {
switch_off(); switch_off();
//Resetting Frame mode (First set in fpgaloader.c) //Resetting Frame mode (First set in fpgaloader.c)
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
@ -515,7 +515,7 @@ void felica_sendraw(PacketCommandNG *c) {
if ((param & FELICA_CONNECT)) if ((param & FELICA_CONNECT))
if (DBGLEVEL > 3) Dbprintf("Clear trace"); if (DBGLEVEL > 3) Dbprintf("Clear trace");
clear_trace(); clear_trace();
set_tracing(true); set_tracing(true);
iso18092_setup(FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD); iso18092_setup(FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD);
@ -526,13 +526,13 @@ void felica_sendraw(PacketCommandNG *c) {
if (!(param & FELICA_NO_SELECT)) { if (!(param & FELICA_NO_SELECT)) {
arg0 = felica_select_card(&card); arg0 = felica_select_card(&card);
reply_mix(CMD_ACK, arg0, sizeof(card.uid), 0, &card, sizeof(felica_card_select_t)); reply_mix(CMD_ACK, arg0, sizeof(card.uid), 0, &card, sizeof(felica_card_select_t));
if (arg0 > 0){ if (arg0 > 0) {
Dbprintf("Error: Failed selecting card! "); Dbprintf("Error: Failed selecting card! ");
felica_reset_frame_mode(); felica_reset_frame_mode();
return; return;
} }
} }
}else{ } else {
if (DBGLEVEL > 3) Dbprintf("No card selection"); if (DBGLEVEL > 3) Dbprintf("No card selection");
} }
@ -566,11 +566,11 @@ void felica_sendraw(PacketCommandNG *c) {
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0); Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
}; };
uint32_t result = reply_mix(CMD_ACK, FelicaFrame.len, arg0, 0, FelicaFrame.framebytes, FelicaFrame.len); uint32_t result = reply_mix(CMD_ACK, FelicaFrame.len, arg0, 0, FelicaFrame.framebytes, FelicaFrame.len);
if(result){ if (result) {
Dbprintf("Reply to Client Error Code: %i", result); Dbprintf("Reply to Client Error Code: %i", result);
} }
} }
if ((param & FELICA_NO_DISCONNECT)){ if ((param & FELICA_NO_DISCONNECT)) {
Dbprintf("Disconnect"); Dbprintf("Disconnect");
} }
if (DBGLEVEL > 3) if (DBGLEVEL > 3)
@ -756,7 +756,7 @@ void felica_sim_lite(uint64_t uid) {
DbpString("Felica Lite-S sim end"); DbpString("Felica Lite-S sim end");
} }
void felica_dump(){ void felica_dump() {
uint8_t ndef[8]; uint8_t ndef[8];
uint8_t poll[10] = { 0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21}; // B24D0600FFFF00000921 uint8_t poll[10] = { 0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21}; // B24D0600FFFF00000921
iso18092_setup(FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD); iso18092_setup(FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD);
@ -773,7 +773,7 @@ void felica_dump(){
} }
} }
void felica_send_request_service(uint8_t *request_service){ void felica_send_request_service(uint8_t *request_service) {
uint8_t len = sizeof(request_service) / sizeof((request_service)[0]); uint8_t len = sizeof(request_service) / sizeof((request_service)[0]);
Dbprintf("Send Service Request - len: d%", len); Dbprintf("Send Service Request - len: d%", len);
TransmitFor18092_AsReader(request_service, len, NULL, 1, 0); TransmitFor18092_AsReader(request_service, len, NULL, 1, 0);
@ -787,14 +787,14 @@ void felica_send_request_service(uint8_t *request_service){
// When the specified Area or Service exists, the card returns Key Version. // When the specified Area or Service exists, the card returns Key Version.
// When the specified Area or Service does not exist, the card returns FFFFh as Key Version. // When the specified Area or Service does not exist, the card returns FFFFh as Key Version.
*/ */
uint8_t * felica_create_request_service_frame(uint8_t nodeNumber, uint8_t *idm){ uint8_t *felica_create_request_service_frame(uint8_t nodeNumber, uint8_t *idm) {
if(nodeNumber < 1 && nodeNumber > 32){ if (nodeNumber < 1 && nodeNumber > 32) {
Dbprintf("Node number out of range: 1 <= %d <= 32 - set node number to 1"); Dbprintf("Node number out of range: 1 <= %d <= 32 - set node number to 1");
nodeNumber = 1; nodeNumber = 1;
} }
// Sync 2-Byte, Length 1-Byte, CMD 1-Byte, IDm 8-Byte, nodeNumber 1 <= n <= 32 1-Byte, Node Code List <Little Endian> // Sync 2-Byte, Length 1-Byte, CMD 1-Byte, IDm 8-Byte, nodeNumber 1 <= n <= 32 1-Byte, Node Code List <Little Endian>
uint8_t *request_service = BigBuf_malloc(sizeof(uint8_t)*11); uint8_t *request_service = BigBuf_malloc(sizeof(uint8_t) * 11);
//{ 0xb2, 0x4d, 0x06, FELICA_REQSRV_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21}; //{ 0xb2, 0x4d, 0x06, FELICA_REQSRV_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21};
request_service[0] = 0xb2; //Sync request_service[0] = 0xb2; //Sync
request_service[1] = 0x4d; //Sync request_service[1] = 0x4d; //Sync
request_service[2] = 0x0B; // Length request_service[2] = 0x0B; // Length
@ -813,18 +813,18 @@ uint8_t * felica_create_request_service_frame(uint8_t nodeNumber, uint8_t *idm){
} }
// Create Frame for authentication1 CMD // Create Frame for authentication1 CMD
void felica_create_authentication1_frame(){ void felica_create_authentication1_frame() {
} }
// Create Frame for authentication2 CMD // Create Frame for authentication2 CMD
void felica_create_authentication2_frame(){ void felica_create_authentication2_frame() {
} }
// Create a Frame for Read without encryption CMD as Payload // Create a Frame for Read without encryption CMD as Payload
void felica_create_read_block_frame(uint16_t blockNr){ void felica_create_read_block_frame(uint16_t blockNr) {
if(blockNr < 1 || blockNr > 567){ if (blockNr < 1 || blockNr > 567) {
Dbprintf("Block number out of range!"); Dbprintf("Block number out of range!");
return; return;
} }
@ -842,7 +842,7 @@ void felica_create_read_block_frame(uint16_t blockNr){
// CRC // CRC
} }
void felica_read_block(uint8_t *idm, uint16_t blockNr){ void felica_read_block(uint8_t *idm, uint16_t blockNr) {
} }

View file

@ -24,6 +24,6 @@ void felica_create_authentication1_frame();
void felica_create_authentication2_frame(); void felica_create_authentication2_frame();
void felica_send_request_service(uint8_t *request_service); void felica_send_request_service(uint8_t *request_service);
void felica_reset_frame_mode(); void felica_reset_frame_mode();
uint8_t * felica_create_request_service_frame(uint8_t nodeNumber, uint8_t *idm); uint8_t *felica_create_request_service_frame(uint8_t nodeNumber, uint8_t *idm);
#endif #endif

View file

@ -406,7 +406,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
} }
uint32_t tracelen = resp.oldarg[1]; uint32_t tracelen = resp.oldarg[1];
if (tracelen == 0){ if (tracelen == 0) {
PrintAndLogEx(WARNING, "\nNo trace data! Maybe not a FeliCa Lite card?"); PrintAndLogEx(WARNING, "\nNo trace data! Maybe not a FeliCa Lite card?");
return 1; return 1;
} }
@ -557,11 +557,11 @@ static int CmdHFFelicaCmdRaw(const char *Cmd) {
SendCommandMIX(CMD_HF_FELICA_COMMAND, flags, (datalen & 0xFFFF) | (uint32_t)(numbits << 16), 0, data, datalen); SendCommandMIX(CMD_HF_FELICA_COMMAND, flags, (datalen & 0xFFFF) | (uint32_t)(numbits << 16), 0, data, datalen);
if (reply) { if (reply) {
if (active_select){ if (active_select) {
PrintAndLogEx(NORMAL, "Active select wait for FeliCa."); PrintAndLogEx(NORMAL, "Active select wait for FeliCa.");
waitCmdFelica(1); waitCmdFelica(1);
} }
if (datalen > 0){ if (datalen > 0) {
waitCmdFelica(0); waitCmdFelica(0);
} }
} }
@ -618,7 +618,7 @@ int readFelicaUid(bool verbose) {
} }
int dump(const char *Cmd){ int dump(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
char ctmp = tolower(param_getchar(Cmd, 0)); char ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_hf_felica_dumplite(); if (ctmp == 'h') return usage_hf_felica_dumplite();
@ -629,16 +629,16 @@ int dump(const char *Cmd){
} }
static command_t CommandTable[] = { static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"}, {"help", CmdHelp, AlwaysAvailable, "This help"},
{"list", CmdHFFelicaList, AlwaysAvailable, "List ISO 18092/FeliCa history"}, {"list", CmdHFFelicaList, AlwaysAvailable, "List ISO 18092/FeliCa history"},
{"reader", CmdHFFelicaReader, IfPm3Felica, "Act like an ISO18092/FeliCa reader"}, {"reader", CmdHFFelicaReader, IfPm3Felica, "Act like an ISO18092/FeliCa reader"},
// {"sim", CmdHFFelicaSim, IfPm3Felica, "<UID> -- Simulate ISO 18092/FeliCa tag"}, // {"sim", CmdHFFelicaSim, IfPm3Felica, "<UID> -- Simulate ISO 18092/FeliCa tag"},
{"sniff", CmdHFFelicaSniff, IfPm3Felica, "sniff ISO 18092/Felica traffic"}, {"sniff", CmdHFFelicaSniff, IfPm3Felica, "sniff ISO 18092/Felica traffic"},
{"raw", CmdHFFelicaCmdRaw, IfPm3Felica, "Send raw hex data to tag"}, {"raw", CmdHFFelicaCmdRaw, IfPm3Felica, "Send raw hex data to tag"},
{"dump", CmdHFFelicaDump, IfPm3Felica, "Wait for and try dumping Felica"}, {"dump", CmdHFFelicaDump, IfPm3Felica, "Wait for and try dumping Felica"},
{"litesim", CmdHFFelicaSimLite, IfPm3Felica, "<NDEF2> - only reply to poll request"}, {"litesim", CmdHFFelicaSimLite, IfPm3Felica, "<NDEF2> - only reply to poll request"},
{"litedump", CmdHFFelicaDumpLite, IfPm3Felica, "Wait for and try dumping FelicaLite"}, {"litedump", CmdHFFelicaDumpLite, IfPm3Felica, "Wait for and try dumping FelicaLite"},
{NULL, NULL, NULL, NULL} {NULL, NULL, NULL, NULL}
}; };
static int CmdHelp(const char *Cmd) { static int CmdHelp(const char *Cmd) {