18#ifdef BUILDING_ARCADE_SECRMAN
19#define CARD_AUTH_KEY_CHANGE_CMDNUM 3
20#define MODNAME "secrman_for_arcade"
22#define CARD_AUTH_KEY_CHANGE_CMDNUM 1
23#define MODNAME "secrman_special"
35static void _printf(
const char *format, ...);
45static loadfile_elf_load_proc_callback_t loadfile_elf_load_proc;
46static loadfile_check_valid_ee_elf_callback_t loadfile_check_valid_ee_elf;
47static loadfile_elf_get_program_header_callback_t loadfile_elf_get_program_header;
48static loadfile_elf_load_alloc_buffer_from_heap_callback_t loadfile_elf_load_alloc_buffer_from_heap;
49static loadfile_elf_load_dealloc_buffer_from_heap_callback_t loadfile_elf_load_dealloc_buffer_from_heap;
52static int card_decrypt(
int port,
int slot,
void *buffer);
53static int func_00000bfc(
void *dest,
unsigned int size);
62static void RegisterSecrCallbackHandlers(
void);
63static int card_encrypt(
int port,
int slot,
void *buffer);
64static unsigned short int GetHeaderLength(
const void *buffer);
65static int secr_set_header(
int mode,
int cnum,
int arg2,
void *buffer);
67static unsigned int get_BitTableOffset(
const void *buffer);
68static int func_00000b5c(
const void *block,
unsigned int size);
71static int scePreEncryptKbit(
void *kbit);
74static int scePreEncryptKc(
void *kc);
75static int func_00000d14(
void *icvps2);
76static int Uses_ICVPS2(
const void *buffer);
80static void _printf(
const char *format, ...){
86static int card_decrypt(
int port,
int slot,
void *buffer)
88 if (GetMcCommandHandler() == NULL) {
92 _printf(
"card decrypt start\n");
94 if (card_auth(port, slot, 0xF1, 0x40) == 0) {
98 _printf(
"card decrypt 0x40\n");
100 if (card_auth_write(port, slot, buffer, 0xF1, 0x41) == 0) {
104 _printf(
"card decrypt 0x41\n");
106 if (card_auth(port, slot, 0xF1, 0x42) == 0) {
110 _printf(
"card decrypt 0x42\n");
112 if (card_auth_read(port, slot, buffer, 0xF1, 0x43) == 0) {
116 _printf(
"card decrypt 0x43\n");
122int SecrCardBootHeader(
int port,
int slot,
void *buffer,
SecrBitTable_t *BitTable, s32 *pSize)
124 unsigned char Kbit[16], Kc[16];
128 if (GetMcCommandHandler() == NULL) {
129 _printf(
"mcCommand isn't assigned\n");
133 get_Kbit(buffer, Kbit);
136 if (card_decrypt(port, slot, Kbit) == 0) {
140 if (card_decrypt(port, slot, &Kbit[8]) == 0) {
144 if (card_decrypt(port, slot, Kc) == 0) {
148 if (card_decrypt(port, slot, &Kc[8]) == 0) {
152 store_kc(buffer, Kc);
153 store_kbit(buffer, Kbit);
155 if ((cnum = McDeviceIDToCNum(port, slot)) < 0) {
159 if (secr_set_header(1, cnum, 0, buffer) == 0) {
160 _printf(
"Set Header failed\n");
164 if ((BitTableSize = Read_BIT(BitTable)) == 0) {
165 _printf(
"Cannot read BIT\n");
170 *pSize = BitTableSize;
179static int func_00000bfc(
void *dest,
unsigned int size)
181 if (func_00001c98(size) == 0) {
196 if (func_00001b00(dest, 0x10) == 0) {
200 dest = (
void *)((u8 *)dest + 0x10);
202 if (func_00001b00(dest, size) == 0) {
213int SecrCardBootBlock(
void *src,
void *dest,
unsigned int size)
215 if (func_00000b5c(src, size) == 0) {
219 if (func_00000bfc(dest, size) == 0) {
227void *SecrCardBootFile(
int port,
int slot,
void *buffer)
230 unsigned int offset, i;
232 BitTableData = (
SecrBitTable_t *)((u8 *)buffer + get_BitTableOffset(buffer));
233 if (SecrCardBootHeader(port, slot, buffer, BitTableData, NULL) == 0) {
234 _printf(
"SecrCardBootFile: Cannot decrypt header\n");
239 for (i = 0; i < BitTableData->header.
block_count; i++) {
241 if (!SecrCardBootBlock((
void *)((u8 *)buffer + offset), (
void *)((u8 *)buffer + offset), BitTableData->
blocks[i].
size)) {
242 _printf(
"SecrCardBootFile: failed\n");
249 return (
void *)((u8 *)buffer + GetHeaderLength(buffer));
253int SecrDiskBootHeader(
void *buffer,
SecrBitTable_t *BitTable, s32 *pSize)
257 if (secr_set_header(0, 0, 0, buffer) == 0) {
258 _printf(
"Set Header failed\n");
262 if ((BitTableSize = Read_BIT(BitTable)) == 0) {
263 _printf(
"Cannot read BIT\n");
268 *pSize = BitTableSize;
275int SecrDiskBootBlock(
void *src,
void *dest,
unsigned int size)
277 if (func_00000b5c(src, size) == 0) {
280 if (func_00000bfc(dest, size) == 0) {
288void *SecrDiskBootFile(
void *buffer)
291 unsigned int offset, i;
293 BitTableData = (
SecrBitTable_t *)((u8 *)buffer + get_BitTableOffset(buffer));
294 if (SecrDiskBootHeader(buffer, BitTableData, NULL) == 0) {
295 _printf(
"SecrDiskBootFile: Cannot decrypt header\n");
300 for (i = 0; i < BitTableData->header.
block_count; i++) {
302 if (!SecrDiskBootBlock((
void *)((u8 *)buffer + offset), (
void *)((u8 *)buffer + offset), BitTableData->
blocks[i].
size)) {
303 _printf(
"SecrDiskBootFile: failed\n");
310 return (
void *)((u8 *)buffer + GetHeaderLength(buffer));
319 unsigned short int HeaderLength;
322 if (lseek(fd, 0, SEEK_SET) != 0) {
330 HeaderLength = GetHeaderLength(&header);
331 if ((HeaderBuffer = loadfile_elf_load_alloc_buffer_from_heap(HeaderLength)) == NULL) {
335 if (lseek(fd, 0, SEEK_SET) != 0) {
336 loadfile_elf_load_dealloc_buffer_from_heap(HeaderBuffer);
340 if (read(fd, HeaderBuffer, HeaderLength) != HeaderLength) {
341 loadfile_elf_load_dealloc_buffer_from_heap(HeaderBuffer);
345 BitTableData = (
SecrBitTable_t *)((
unsigned int)HeaderBuffer + get_BitTableOffset(HeaderBuffer));
348 header_result = SecrCardBootHeader(port, slot, HeaderBuffer, BitTableData, NULL);
349 }
else if (device == 1) {
350 header_result = SecrDiskBootHeader(HeaderBuffer, BitTableData, NULL);
355 if (header_result != 1) {
356 loadfile_elf_load_dealloc_buffer_from_heap(HeaderBuffer);
370 unsigned int i, PayloadLength, excess;
372 unsigned int ExcessBlockNum;
373 void *BlockExcessRegionPtr;
376 printf(
"secrman_loadfile_read_callback_common:\n"
377 "\tModloadUnk2->ring_buffer_index:\t%d\n"
378 "\tModloadUnk2->read_buffer_offset:\t%d\n"
379 "\tModloadUnk2->read_buffer_length:\t%d\n", allocate_info->ring_buffer_index, allocate_info->read_buffer_offset, allocate_info->read_buffer_length);
382 entry = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index];
383 entry->buffer_offset = allocate_info->read_buffer_offset;
393 printf(
"WIP function 0x0000306c: can't partially decrypt block.\n");
399 BlockExcessRegionPtr = (
void *)((u8 *)(entry->buffer_base) + excess);
405 excess = allocate_info->read_buffer_length;
412 if (((
unsigned int)read(fd, entry->buffer_base, excess)) != excess) {
416 allocate_info->read_buffer_offset += excess;
418 for (; ExcessBlockNum < i; BlockExcessRegionPtr = (
void *)((u8 *)BlockExcessRegionPtr +
ModloadBitTableDescriptor->blocks[ExcessBlockNum].
size), ExcessBlockNum++) {
433 return secrman_loadfile_read_callback_common(fd, allocate_info, (
const struct ModloadBitTableDescriptor *)read_callback_userdata, &SecrCardBootBlock);
453 if (loadfile_check_valid_ee_elf(allocate_info, flhs) != 0) {
454 printf(
"don't get elf header\n");
458 if (loadfile_elf_get_program_header(allocate_info, flhs) != 0) {
459 printf(
"don't get program header\n");
464 printf(
"load elf error\n");
469 *result_out = flhs->elf_header.e_entry;
470 *result_module_out = 0;
478 return secrman_load_kelf_common(allocate_info, flhs, port, slot, result_out, result_module_out, 0, &secrman_loadfile_read_callback_card);
484 return secrman_loadfile_read_callback_common(fd, allocate_info, (
const struct ModloadBitTableDescriptor *)read_callback_userdata, &SecrDiskBootBlock);
490 return secrman_load_kelf_common(allocate_info, flhs, 0, 0, result_out, result_module_out, 1, &secrman_loadfile_read_callback_disk);
496 loadfile_elf_load_proc = callbackinfo->elf_load_proc;
497 loadfile_check_valid_ee_elf = callbackinfo->check_valid_ee_elf;
498 loadfile_elf_get_program_header = callbackinfo->elf_get_program_header;
499 loadfile_elf_load_alloc_buffer_from_heap = callbackinfo->elf_load_alloc_buffer_from_heap;
500 loadfile_elf_load_dealloc_buffer_from_heap = callbackinfo->elf_load_dealloc_buffer_from_heap;
502 callbackinfo->load_kelf_from_card = &secrman_load_kelf_from_card;
503 callbackinfo->load_kelf_from_disk = &secrman_load_kelf_from_disk;
507static void RegisterSecrCallbackHandlers(
void)
509 SetSecrmanCallbacks(&SecrCardBootFile, &SecrDiskBootFile, &SecrGetLoadfileCallbacks);
513int _start(
int argc,
char *argv[])
524 fd = open(
"rom0:ROMVER", O_RDONLY);
525 lseek(fd, 5, SEEK_SET);
532 if (RegisterLibraryEntries(&_exp_secrman) != 0) {
533 return MODULE_NO_RESIDENT_END;
537 RegisterSecrCallbackHandlers();
539 return MODULE_RESIDENT_END;
543int _exit(
int argc,
char *argv[])
548 return MODULE_NO_RESIDENT_END;
552void SecrSetMcCommandHandler(McCommandHandler_t handler)
554 SetMcCommandHandler(handler);
558void SecrSetMcDevIDHandler(McDevIDHandler_t handler)
560 SetMcDevIDHandler(handler);
565int SecrAuthCard(
int port,
int slot,
int cnum)
567 unsigned char MechaChallenge2[8], CardIV[8], CardMaterial[8], CardNonce[8], MechaChallenge1[8], MechaChallenge3[8], CardResponse1[8], CardResponse2[8], CardResponse3[8];
569 if (GetMcCommandHandler() == NULL) {
570 _printf(
"mcCommand isn't assigned\n");
574 _printf(
"SecrAuthCard start\n");
576 memset(MechaChallenge1, 0,
sizeof(MechaChallenge1));
578 if (card_auth_60(port, slot) == 0) {
582 _printf(
"card auth 0x60\n");
584 if (mechacon_auth_80(cnum) == 0) {
588 _printf(
"mechacon auth 0x80\n");
599 card_auth_key_change(port, slot, CARD_AUTH_KEY_CHANGE_CMDNUM)) == 0) {
600 card_auth_60(port, slot);
604 _printf(
"card auth key change\n");
606 if (card_auth(port, slot, 0xF0, 0x00) == 0) {
607 card_auth_60(port, slot);
611 _printf(
"card auth 0x00\n");
613 if (mechacon_auth_81(cnum) == 0) {
614 card_auth_60(port, slot);
618 _printf(
"mechacon auth 0x81\n");
620 if (card_auth_read(port, slot, CardIV, 0xF0, 0x01) == 0) {
624 _printf(
"card auth 0x01\n");
626 if (card_auth_read(port, slot, CardMaterial, 0xF0, 0x02) == 0) {
630 _printf(
"card auth 0x02\n");
632 if (mechacon_auth_82(CardIV, CardMaterial) == 0) {
636 _printf(
"mechacon auth 0x82\n");
638 if (card_auth(port, slot, 0xF0, 0x03) == 0) {
642 _printf(
"card auth 0x03\n");
644 if (card_auth_read(port, slot, CardNonce, 0xF0, 0x04) == 0) {
648 _printf(
"card auth 0x04\n");
650 if (mechacon_auth_83(CardNonce) == 0) {
654 _printf(
"mechacon auth 0x83\n");
656 if (card_auth(port, slot, 0xF0, 0x05) == 0) {
660 _printf(
"card auth 0x05\n");
662 if (pol_cal_cmplt() == 0) {
666 _printf(
"mechacon auth 0x8f\n");
668 if (mechacon_auth_84(MechaChallenge1, MechaChallenge2) == 0) {
672 _printf(
"mechacon auth 0x84\n");
674 if (mechacon_auth_85(&MechaChallenge2[4], MechaChallenge3) == 0) {
678 _printf(
"mechacon auth 0x85\n");
680 if (card_auth_write(port, slot, MechaChallenge3, 0xF0, 0x06) == 0) {
684 _printf(
"card auth 0x06\n");
686 if (card_auth_write(port, slot, MechaChallenge2, 0xF0, 0x07) == 0) {
690 _printf(
"card auth 0x07\n");
692 if (card_auth(port, slot, 0xF0, 0x08) == 0) {
696 _printf(
"card auth 0x08\n");
698 if (card_auth2(port, slot, 0xF0, 0x09) == 0) {
702 _printf(
"card auth 0x09\n");
704 if (card_auth(port, slot, 0xF0, 0x0A) == 0) {
708 _printf(
"card auth 0x0a\n");
710 if (card_auth_write(port, slot, MechaChallenge1, 0xF0, 0x0B) == 0) {
714 _printf(
"card auth 0x0b\n");
716 if (card_auth(port, slot, 0xF0, 0x0C) == 0) {
720 _printf(
"card auth 0x0c\n");
722 if (card_auth2(port, slot, 0xF0, 0x0D) == 0) {
726 _printf(
"card auth 0x0d\n");
728 if (card_auth(port, slot, 0xF0, 0x0E) == 0) {
732 _printf(
"card auth 0x0e\n");
734 if (card_auth_read(port, slot, CardResponse1, 0xF0, 0x0F) == 0) {
738 _printf(
"card auth 0x0f\n");
740 if (card_auth(port, slot, 0xF0, 0x10) == 0) {
744 _printf(
"card auth 0x10\n");
746 if (card_auth_read(port, slot, CardResponse2, 0xF0, 0x11) == 0) {
750 _printf(
"card auth 0x11\n");
752 if (mechacon_auth_86(CardResponse1, CardResponse2) == 0) {
756 _printf(
"mechacon auth 0x86\n");
758 if (card_auth(port, slot, 0xF0, 0x12) == 0) {
762 _printf(
"card auth 0x12\n");
764 if (card_auth_read(port, slot, CardResponse3, 0xF0, 0x13) == 0) {
768 _printf(
"card auth 0x13\n");
770 if (mechacon_auth_87(CardResponse3) == 0) {
774 _printf(
"mechacon auth 0x87\n");
776 if (pol_cal_cmplt() == 0) {
780 _printf(
"mechacon auth 0x8f\n");
782 if (card_auth(port, slot, 0xF0, 0x14) == 0) {
786 _printf(
"card auth 0x14\n");
788 if (mechacon_auth_88() == 0) {
792 _printf(
"mechacon auth 0x88\n");
797 card_auth_60(port, slot);
798 mechacon_auth_80(cnum);
804void SecrResetAuthCard(
int port,
int slot,
int cnum)
806 card_auth_60(port, slot);
807 mechacon_auth_80(cnum);
811static unsigned short int GetHeaderLength(
const void *buffer)
817static int secr_set_header(
int mode,
int cnum,
int arg2,
void *buffer)
819 unsigned short int HeaderLength;
821 HeaderLength = GetHeaderLength(buffer);
822 _printf(
"header length %d\n", HeaderLength);
823 if (write_HD_start(mode, cnum, arg2, HeaderLength) == 0) {
824 _printf(
"secr_set_header: fail write_HD_start\n");
828 while (HeaderLength > 0) {
829 int write_data_result;
831 if (HeaderLength >= 0x10) {
832 write_data_result = write_data(buffer, 0x10);
833 buffer = (
void *)((u8 *)buffer + 0x10);
834 HeaderLength -= 0x10;
836 write_data_result = write_data(buffer, HeaderLength);
840 if (write_data_result == 0) {
841 _printf(
"secr_set_header: fail write_data\n");
846 if (pol_cal_cmplt() == 0) {
847 _printf(
"secr_set_header: fail pol_cal_cmplt\n");
857 unsigned short int BitLength;
858 unsigned short int DataToCopy;
860 if (get_BIT_length(&BitLength) == 0) {
864 DataToCopy = BitLength;
866 while (DataToCopy != 0) {
867 if (DataToCopy >= 0x10) {
868 if (func_00001b00(BitTable, 0x10) == 0) {
874 if (func_00001b00(BitTable, DataToCopy) == 0) {
885int SecrDownloadHeader(
int port,
int slot,
void *buffer,
SecrBitTable_t *BitTable, s32 *pSize)
890 if (GetMcCommandHandler() == NULL) {
891 _printf(
"mcCommand isn't assigned\n");
895 if ((cnum = McDeviceIDToCNum(port, slot)) < 0) {
896 _printf(
"invalid cnum '%d'\n", cnum);
899 if (secr_set_header(2, cnum, 0, buffer) == 0) {
903 if ((size = Read_BIT(BitTable)) == 0) {
915static unsigned int get_BitTableOffset(
const void *buffer)
922 if ((header->
flags & 1) != 0)
923 offset += ((
const unsigned char *)buffer)[offset] + 1;
924 if ((header->
flags & 0xF000) == 0)
926 return (offset + 0x20);
930static int func_00000b5c(
const void *block,
unsigned int size)
932 if (mechacon_set_block_size(size) == 0) {
937 if (write_data(block, 0x10) == 0) {
940 block = (
const void *)((
const u8 *)block + 0x10);
944 if (pol_cal_cmplt() == 0) {
952int SecrDownloadBlock(
void *block,
unsigned int size)
954 if (func_00000b5c(block, size) != 1) {
962static int scePreEncryptKbit(
void *kbit)
964 if (_PreEncryptKbit1(kbit) == 0) {
968 if (_PreEncryptKbit2((
void *)((u8 *)kbit + 8)) != 1) {
977static int scePreEncryptKc(
void *kc)
979 if (_PreEncryptKc1(kc) == 0) {
983 if (_PreEncryptKc2((
void *)((u8 *)kc + 8)) != 1) {
991static int card_encrypt(
int port,
int slot,
void *buffer)
993 if (GetMcCommandHandler() == NULL) {
997 _printf(
"card encrypt start\n");
999 if (card_auth(port, slot, 0xF2, 0x50) == 0) {
1003 _printf(
"card encrypt 0x50\n");
1005 if (card_auth_write(port, slot, buffer, 0xF2, 0x51) == 0) {
1009 _printf(
"card encrypt 0x51\n");
1011 if (card_auth(port, slot, 0xF2, 0x52) == 0) {
1015 _printf(
"card encrypt 0x52\n");
1017 if (card_auth_read(port, slot, buffer, 0xF2, 0x53) == 0) {
1021 _printf(
"card encrypt 0x53\n");
1027int SecrDownloadGetKbit(
int port,
int slot,
void *kbit)
1029 if (scePreEncryptKbit(kbit) == 0) {
1033 if (card_encrypt(port, slot, kbit) == 0) {
1037 if (card_encrypt(port, slot, (
void *)((u8 *)kbit + 8)) == 0) {
1045int SecrDownloadGetKc(
int port,
int slot,
void *kc)
1047 if (scePreEncryptKc(kc) == 0) {
1051 if (card_encrypt(port, slot, kc) == 0) {
1055 if (card_encrypt(port, slot, (
void *)((u8 *)kc + 8)) == 0) {
1063static int func_00000d14(
void *icvps2)
1065 if (func_00001ed8(icvps2) == 0) {
1073int SecrDownloadGetICVPS2(
void *icvps2)
1075 if (func_00000d14(icvps2) == 0) {
1083static int Uses_ICVPS2(
const void *buffer)
1089void *SecrDownloadFile(
int port,
int slot,
void *buffer)
1092 unsigned char kbit[16], kcontent[16];
1093 unsigned int offset, i;
1095 _printf(
"SecrDownloadFile start\n");
1096 get_BitTableOffset(buffer);
1097 if (SecrDownloadHeader(port, slot, buffer, &BitTableData, NULL) == 0) {
1098 _printf(
"SecrDownloadFile: Cannot encrypt header\n");
1103 for (i = 0; i < BitTableData.header.
block_count; i++) {
1105 if (!SecrDownloadBlock((
void *)((u8 *)buffer + offset), BitTableData.
blocks[i].
size)) {
1106 _printf(
"SecrDownloadFile: failed\n");
1113 if (SecrDownloadGetKbit(port, slot, kbit) == 0) {
1114 _printf(
"SecrDownloadFile: Cannot get kbit\n");
1117 if (SecrDownloadGetKc(port, slot, kcontent) == 0) {
1118 _printf(
"SecrDownloadFile: Cannot get kc\n");
1122 store_kbit(buffer, kbit);
1123 store_kc(buffer, kcontent);
1125 if (Uses_ICVPS2(buffer) == 1) {
1126 unsigned char icvps2[8];
1128 if (SecrDownloadGetICVPS2(icvps2) == 0) {
1129 _printf(
"SecrDownloadFile: Cannot get icvps2\n");
1133 store_icvps2(buffer, icvps2);
1136 _printf(
"SecrDownloadFile complete\n");
1141#ifdef BUILDING_ARCADE_SECRMAN
1144int SecrAuthDongle(
int port,
int slot,
int cnum)
1157 if (GetMcCommandHandler() == NULL) {
1158 _printf(
"mcCommand isn't assigned\n");
1162 _printf(
"SecrAuthDongle start\n");
1164 memset(MechaChallenge1, 0,
sizeof(MechaChallenge1));
1166 if (card_auth_60(port, slot) == 0) {
1170 _printf(
"dongle auth 0x60\n");
1172 if (mechacon_auth_80(cnum) == 0) {
1176 _printf(
"mechacon auth 0x80\n");
1183 if (card_auth(port, slot, 0xF0, 0x00) == 0) {
1184 card_auth_60(port, slot);
1188 _printf(
"dongle auth 0x00\n");
1190 if (mechacon_auth_81(cnum | 0x40) == 0) {
1191 card_auth_60(port, slot);
1195 _printf(
"mechacon auth 0x81\n");
1197 if (card_auth_read(port, slot, CardIV, 0xF0, 0x01) == 0) {
1201 _printf(
"dongle auth 0x01\n");
1203 if (card_auth_read(port, slot, CardMaterial, 0xF0, 0x02) == 0) {
1207 _printf(
"dongle auth 0x02\n");
1209 if (mechacon_auth_82(CardIV, CardMaterial) == 0) {
1213 _printf(
"mechacon auth 0x82\n");
1215 if (card_auth(port, slot, 0xF0, 0x03) == 0) {
1219 _printf(
"dongle auth 0x03\n");
1221 if (card_auth_read(port, slot, CardNonce, 0xF0, 0x04) == 0) {
1225 _printf(
"dongle auth 0x04\n");
1227 if (mechacon_auth_83(CardNonce) == 0) {
1231 _printf(
"mechacon auth 0x83\n");
1233 if (card_auth(port, slot, 0xF0, 0x05) == 0) {
1237 _printf(
"dongle auth 0x05\n");
1239 if (pol_cal_cmplt() == 0) {
1243 _printf(
"mechacon auth 0x8f\n");
1245 if (mechacon_auth_84(MechaChallenge1, MechaChallenge2) == 0) {
1249 _printf(
"mechacon auth 0x84\n");
1251 if (mechacon_auth_85(&MechaChallenge2[4], MechaChallenge3) == 0) {
1255 _printf(
"mechacon auth 0x85\n");
1257 if (card_auth_write(port, slot, MechaChallenge3, 0xF0, 0x06) == 0) {
1261 _printf(
"dongle auth 0x06\n");
1263 if (card_auth_write(port, slot, MechaChallenge2, 0xF0, 0x07) == 0) {
1267 _printf(
"dongle auth 0x07\n");
1269 if (card_auth(port, slot, 0xF0, 0x08) == 0) {
1273 _printf(
"dongle auth 0x08\n");
1275 if (card_auth2(port, slot, 0xF0, 0x09) == 0) {
1279 _printf(
"dongle auth 0x09\n");
1281 if (card_auth(port, slot, 0xF0, 0x0A) == 0) {
1285 _printf(
"dongle auth 0x0a\n");
1287 if (card_auth_write(port, slot, MechaChallenge1, 0xF0, 0x0B) == 0) {
1291 _printf(
"dongle auth 0x0b\n");
1293 if (card_auth(port, slot, 0xF0, 0x0C) == 0) {
1297 _printf(
"dongle auth 0x0c\n");
1299 if (card_auth2(port, slot, 0xF0, 0x0D) == 0) {
1303 _printf(
"dongle auth 0x0d\n");
1305 if (card_auth(port, slot, 0xF0, 0x0E) == 0) {
1309 _printf(
"dongle auth 0x0e\n");
1312 if (card_auth_read(port, slot, CardResponse1, 0xF0, 0x0F) == 0) {
1316 _printf(
"dongle auth 0x0f\n");
1318 if (card_auth(port, slot, 0xF0, 0x10) == 0) {
1322 _printf(
"dongle auth 0x10\n");
1324 if (card_auth_read(port, slot, CardResponse2, 0xF0, 0x11) == 0) {
1328 _printf(
"dongle auth 0x11\n");
1330 if (mechacon_auth_86(CardResponse1, CardResponse2) == 0) {
1334 _printf(
"mechacon auth 0x86\n");
1336 if (card_auth(port, slot, 0xF0, 0x12) == 0) {
1340 _printf(
"dongle auth 0x12\n");
1342 if (card_auth_read(port, slot, CardResponse3, 0xF0, 0x13) == 0) {
1346 _printf(
"dongle auth 0x13\n");
1348 if (mechacon_auth_87(CardResponse3) == 0) {
1352 _printf(
"mechacon auth 0x87\n");
1354 if (pol_cal_cmplt() == 0) {
1358 _printf(
"mechacon auth 0x8f\n");
1360 if (card_auth(port, slot, 0xF0, 0x14) == 0) {
1364 _printf(
"card auth 0x14\n");
1366 if (mechacon_auth_88() == 0) {
1370 _printf(
"mechacon auth 0x88!\n");
1375 card_auth_60(port, slot);
1376 mechacon_auth_80(cnum);
struct KELF_Header SecrKELFHeader_t
SecrBitBlockData_t blocks[63]
struct SecrBitBlockData SecrBitBlockData_t