diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 0659113d2..b09cd4caa 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -325,8 +325,8 @@ extern struct version_information version_information; /* bootrom version information is pointed to from _bootphase1_version_pointer */ extern char *_bootphase1_version_pointer, _flash_start, _flash_end, _bootrom_start, _bootrom_end, __data_src_start__; void SendVersion(void) { - char temp[PM3_CMD_DATA_SIZE]; /* Limited data payload in USB packets */ - char VersionString[PM3_CMD_DATA_SIZE] = { '\0' }; + char temp[PM3_CMD_DATA_SIZE - 12]; /* Limited data payload in USB packets */ + char VersionString[PM3_CMD_DATA_SIZE - 12] = { '\0' }; /* Try to find the bootrom version information. Expect to find a pointer at * symbol _bootphase1_version_pointer, perform slight sanity checks on the @@ -357,7 +357,21 @@ void SendVersion(void) { // Send Chip ID and used flash memory uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start; uint32_t compressed_data_section_size = common_area.arg1; - reply_old(CMD_ACK, *(AT91C_DBGU_CIDR), text_and_rodata_section_size + compressed_data_section_size, 0, VersionString, strlen(VersionString)); + + struct p { + uint32_t id; + uint32_t section_size; + uint32_t versionstr_len; + char versionstr[PM3_CMD_DATA_SIZE - 12]; + } PACKED; + + struct p payload; + payload.id = *(AT91C_DBGU_CIDR); + payload.section_size = text_and_rodata_section_size + compressed_data_section_size; + payload.versionstr_len = strlen(VersionString); + memcpy(payload.versionstr, VersionString, strlen(VersionString)); + + reply_ng(CMD_VERSION, PM3_SUCCESS, (uint8_t*)&payload, 12 + strlen(VersionString)); } // measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time. @@ -551,7 +565,7 @@ at the same place! :-) */ #define LIGHT_LEVELS 20 -void ListenReaderField(int limit) { +void ListenReaderField(uint8_t limit) { #define LF_ONLY 1 #define HF_ONLY 2 #define REPORT_CHANGE 10 // report new values only if they have changed at least by REPORT_CHANGE @@ -1271,7 +1285,9 @@ static void PacketReceived(PacketCommandNG *packet) { break; case CMD_LISTEN_READER_FIELD: - ListenReaderField(packet->oldarg[0]); + if (packet->length != sizeof(uint8_t) ) + break; + ListenReaderField(packet->data.asBytes[0]); break; case CMD_FPGA_MAJOR_MODE_OFF: // ## FPGA Control @@ -1346,7 +1362,9 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_READ_MEM: - ReadMem(packet->oldarg[0]); + if (packet->length != sizeof(uint32_t)) + break; + ReadMem(packet->data.asDwords[0]); break; #ifdef WITH_FLASH case CMD_FLASHMEM_SET_SPIBAUDRATE: @@ -1517,11 +1535,11 @@ static void PacketReceived(PacketCommandNG *packet) { #endif case CMD_SET_LF_DIVISOR: FpgaDownloadAndGo(FPGA_BITSTREAM_LF); - FpgaSendCommand(FPGA_CMD_SET_DIVISOR, packet->oldarg[0]); + FpgaSendCommand(FPGA_CMD_SET_DIVISOR, packet->data.asBytes[0]); break; case CMD_SET_ADC_MUX: - switch (packet->oldarg[0]) { + switch (packet->data.asBytes[0]) { case 0: SetAdcMuxFor(GPIO_MUXSEL_LOPKD); break; diff --git a/armsrc/apps.h b/armsrc/apps.h index 045dc907b..c37ac7c67 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -62,7 +62,7 @@ void print_result(char *name, uint8_t *buf, size_t len); //void PrintToSendBuffer(void); void ToSendStuffBit(int b); void ToSendReset(void); -void ListenReaderField(int limit); +void ListenReaderField(uint8_t limit); extern int ToSendMax; extern uint8_t ToSend[]; diff --git a/client/cmdhw.c b/client/cmdhw.c index f5b6f94ab..e57899019 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -24,6 +24,7 @@ static int CmdHelp(const char *Cmd); static int usage_hw_detectreader(void) { PrintAndLogEx(NORMAL, "Start to detect presences of reader field"); + PrintAndLogEx(NORMAL, "press pm3 button to change modes and finally exit"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: hw detectreader [h] "); PrintAndLogEx(NORMAL, "Options:"); @@ -349,7 +350,7 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) { } static int CmdDetectReader(const char *Cmd) { - uint16_t arg = 0; + uint8_t arg = 0; char c = toupper(Cmd[0]); switch (c) { case 'L': @@ -365,7 +366,7 @@ static int CmdDetectReader(const char *Cmd) { } clearCommandBuffer(); - SendCommandMIX(CMD_LISTEN_READER_FIELD, arg, 0, 0, NULL, 0); + SendCommandNG(CMD_LISTEN_READER_FIELD, (uint8_t *)&arg, sizeof(arg)); return PM3_SUCCESS; } @@ -388,14 +389,16 @@ static int CmdLCD(const char *Cmd) { } static int CmdLCDReset(const char *Cmd) { + (void)Cmd; // Cmd is not used so far clearCommandBuffer(); - SendCommandMIX(CMD_LCD_RESET, strtol(Cmd, NULL, 0), 0, 0, NULL, 0); + SendCommandNG(CMD_LCD_RESET, NULL, 0); return PM3_SUCCESS; } static int CmdReadmem(const char *Cmd) { + uint32_t address = strtol(Cmd, NULL, 0); clearCommandBuffer(); - SendCommandMIX(CMD_READ_MEM, strtol(Cmd, NULL, 0), 0, 0, NULL, 0); + SendCommandNG(CMD_READ_MEM, (uint8_t *)&address, sizeof(address)); return PM3_SUCCESS; } @@ -412,15 +415,15 @@ static int CmdReset(const char *Cmd) { * 600kHz. */ static int CmdSetDivisor(const char *Cmd) { - uint16_t arg = strtol(Cmd, NULL, 0); + uint8_t arg = param_get8ex(Cmd, 0, 95, 10); - if (arg < 19 || arg > 255) { + if (arg < 19) { PrintAndLogEx(ERR, "divisor must be between 19 and 255"); return PM3_EINVARG; } // 12 000 000 (12Mhz) clearCommandBuffer(); - SendCommandMIX(CMD_SET_LF_DIVISOR, arg, 0, 0, NULL, 0); + SendCommandNG(CMD_SET_LF_DIVISOR, (uint8_t *)&arg, sizeof(arg)); PrintAndLogEx(SUCCESS, "Divisor set, expected %.1f kHz", ((double)12000 / (arg + 1))); return PM3_SUCCESS; } @@ -444,7 +447,7 @@ static int CmdSetMux(const char *Cmd) { return PM3_EINVARG; } clearCommandBuffer(); - SendCommandMIX(CMD_SET_ADC_MUX, arg, 0, 0, NULL, 0); + SendCommandNG(CMD_SET_ADC_MUX, (uint8_t *)&arg, sizeof(arg)); return PM3_SUCCESS; } @@ -585,7 +588,7 @@ void pm3_version(bool verbose) { SendCommandNG(CMD_VERSION, NULL, 0); - if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { + if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? @@ -599,8 +602,19 @@ void pm3_version(bool verbose) { PrintAndLogEx(NORMAL, " FPC USART for developer support: %s", _GREEN_("present")); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, (char *)resp.data.asBytes); - lookupChipID(resp.oldarg[0], resp.oldarg[1]); + + struct p { + uint32_t id; + uint32_t section_size; + uint32_t versionstr_len; + char versionstr[PM3_CMD_DATA_SIZE - 12]; + } PACKED; + + struct p *payload = (struct p *)&resp.data.asBytes; + + PrintAndLogEx(NORMAL, payload->versionstr); + + lookupChipID(payload->id, payload->section_size); } PrintAndLogEx(NORMAL, "\n"); }