| 49 | #endif |
| 50 | |
| 51 | bool autoFlash(flasher* f) { |
| 52 | f->getFirmwareMD5(); |
| 53 | |
| 54 | if (f->findTagByMD5()) { |
| 55 | // this tag currently contains original firmware, found its fingerprint |
| 56 | cmdSerial.printf("Found original firmware tag, recognized its fingerprint (%s)\r\n", f->md5char); |
| 57 | f->readInfoBlock(); |
| 58 | f->getFirmwareMac(); |
| 59 | f->prepareInfoBlock(); |
| 60 | f->writeInfoBlock(); |
| 61 | cmdSerial.printf("Attempting to perform a flash...\r\n"); |
| 62 | if (f->writeFlashFromPack("/Tag_FW_Pack.bin", f->tagtype)) { |
| 63 | cmdSerial.printf("Successfully flashed the tag!\r\n"); |
| 64 | return true; |
| 65 | } else { |
| 66 | cmdSerial.printf("Couldn't flash the tag, for some reason...\r\n"); |
| 67 | } |
| 68 | } else if (f->getInfoBlockMD5()) { |
| 69 | // did find an infoblock MD5 that looks valid |
| 70 | if (f->findTagByMD5()) { |
| 71 | // did find the md5 in the database |
| 72 | cmdSerial.printf("Found an already-flashed tag, recognized its fingerprint (%s)\r\n", f->md5char); |
| 73 | f->getInfoBlockMac(); |
| 74 | f->getInfoBlockType(); |
| 75 | f->readInfoBlock(); |
| 76 | cmdSerial.printf("Attempting to perform a flash...\r\n"); |
| 77 | if (f->writeFlashFromPack("/Tag_FW_Pack.bin", f->tagtype)) { |
| 78 | cmdSerial.printf("Successfully flashed the tag!\r\n"); |
| 79 | return true; |
| 80 | } else { |
| 81 | cmdSerial.printf("Couldn't flash the tag, for some reason...\r\n"); |
| 82 | } |
| 83 | } else { |
| 84 | // couldn't find the md5 from the infoblock |
| 85 | cmdSerial.printf("Found an already-flashed tag, but we couldn't find its fingerprint (%s) in the database\r\n", f->md5char); |
| 86 | return false; |
| 87 | } |
| 88 | } else { |
| 89 | // We couldn't recognize the tag from it's fingerprint... |
| 90 | cmdSerial.printf("Found a tag but didn't recognize its fingerprint\r\n", f->md5char); |
| 91 | f->backupFlash(); |
| 92 | cmdSerial.printf("Saved this MD5 binary to filesystem\r\n"); |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | void sendFlasherAnswer(uint8_t answer_cmd, uint8_t* ans_buff, uint32_t len, uint8_t transportType) { |
| 98 | uint8_t* answer_buffer = (uint8_t*)calloc(3 + 2 + 2 + len + 2 + 13, 1); |
no test coverage detected