-static unsigned int GetProxmarkState(void)
-{
- unsigned int state = 0;
-
- UsbCommand c;
- c.cmd = CMD_DEVICE_INFO;
- SendCommand(&c, FALSE);
-
- UsbCommand resp;
- ReceiveCommand(&resp);
- /* Three cases:
- * 1. The old bootrom code will ignore CMD_DEVICE_INFO, but respond with an ACK
- * 2. The old os code will respond with CMD_DEBUG_PRINT_STRING and "unknown command"
- * 3. The new bootrom and os codes will respond with CMD_DEVICE_INFO and flags
- */
-
- switch(resp.cmd) {
- case CMD_ACK:
- state = DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM;
- break;
- case CMD_DEBUG_PRINT_STRING:
- state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
- break;
- case CMD_DEVICE_INFO:
- state = resp.arg[0];
- break;
- default:
- fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd);
- exit(-1);
- break;
- }
-
-#if 0
- if(state & DEVICE_INFO_FLAG_BOOTROM_PRESENT) printf("New bootrom present\n");
- if(state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT) printf("New osimage present\n");
- if(state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM) printf("Currently in bootrom\n");
- if(state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) printf("Currently in OS\n");
-#endif
-
- return state;
-}
-
-static unsigned int EnterFlashState(void)
-{
- unsigned int state = GetProxmarkState();
-
- if(state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM) {
- /* Already in flash state, we're done. */
- return state;
- }
-
- if(state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
- fprintf(stderr,"Entering flash-mode...\n");
- UsbCommand c;
- bzero(&c, sizeof(c));
-
- if( (state & DEVICE_INFO_FLAG_BOOTROM_PRESENT) && (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT) ) {
- /* New style handover: Send CMD_START_FLASH, which will reset the board and
- * enter the bootrom on the next boot.
- */
- c.cmd = CMD_START_FLASH;
- SendCommand(&c, FALSE);
- fprintf(stderr,"(You don't have to do anything. Press and release the button only if you want to abort)\n");
- fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
- } else {
- /* Old style handover: Ask the user to press the button, then reset the board */
- c.cmd = CMD_HARDWARE_RESET;
- SendCommand(&c, FALSE);
- fprintf(stderr,"(Press and hold down button NOW if your bootloader requires it)\n");
- fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
- }
-
- CloseProxmark();