// set a config block suitable for emulating BOOL t55x7_emulate_config_block(BYTE *config, BYTE target_tagtype) { switch (target_tagtype) { case TAG_TYPE_ASK_RAW: case TAG_TYPE_FSK1_RAW: case TAG_TYPE_FSK2_RAW: case TAG_TYPE_PSK1_RAW: case TAG_TYPE_PSK2_RAW: case TAG_TYPE_PSK3_RAW: memcpy(config, T55X7_RAW_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); t55x7_create_config_block(config); return TRUE; case TAG_TYPE_AWID_26: case TAG_TYPE_HID_26: memcpy(config, T55X7_HID_26_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); return TRUE; case TAG_TYPE_FDXB: memcpy(config, T55X7_FDXB_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); return TRUE; case TAG_TYPE_INDALA_64: memcpy(config, T55X7_INDALA_64_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); return TRUE; case TAG_TYPE_INDALA_224: memcpy(config, T55X7_INDALA_224_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); return TRUE; case TAG_TYPE_EM4X02: case TAG_TYPE_UNIQUE: case TAG_TYPE_PAXTON: memcpy(config, T55X7_EM_UNIQUE_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); return TRUE; case TAG_TYPE_T55X7: memcpy(config, T55X7_DEFAULT_CONFIG_BLOCK, HEXDIGITS(T55X7_BLOCKSIZE)); return TRUE; default: return FALSE; } }
// set a config block suitable for emulating BOOL q5_emulate_config_block(BYTE *config, BYTE target_tagtype) { switch (target_tagtype) { case TAG_TYPE_ASK_RAW: case TAG_TYPE_FSK1_RAW: case TAG_TYPE_FSK2_RAW: case TAG_TYPE_PSK1_RAW: case TAG_TYPE_PSK2_RAW: case TAG_TYPE_PSK3_RAW: memcpy(config, Q5_DEFAULT_CONFIG_BLOCK, HEXDIGITS(Q5_BLOCKSIZE)); q5_create_config_block(config); return TRUE; case TAG_TYPE_AWID_26: case TAG_TYPE_HID_26: memcpy(config, Q5_HID_26_CONFIG_BLOCK, HEXDIGITS(Q5_BLOCKSIZE)); return TRUE; case TAG_TYPE_FDXB: memcpy(config, Q5_FDXB_CONFIG_BLOCK, HEXDIGITS(Q5_BLOCKSIZE)); return TRUE; case TAG_TYPE_INDALA_64: memcpy(config, Q5_INDALA_64_CONFIG_BLOCK, HEXDIGITS(Q5_BLOCKSIZE)); return TRUE; case TAG_TYPE_INDALA_224: memcpy(config, Q5_INDALA_224_CONFIG_BLOCK, HEXDIGITS(Q5_BLOCKSIZE)); return TRUE; case TAG_TYPE_EM4X02: case TAG_TYPE_Q5: case TAG_TYPE_UNIQUE: memcpy(config, Q5_DEFAULT_CONFIG_BLOCK, HEXDIGITS(Q5_BLOCKSIZE)); return TRUE; default: return FALSE; } }
BOOL vtag_write_to_tag(BYTE *pass) { unsigned int block, config_block_no; BYTE tmp[MAXBLOCKSIZE + 1]; BOOL auth= FALSE; StoredConfig tmptag; // preserve tag type memcpy(&tmptag, &RFIDlerConfig, sizeof(RFIDlerConfig)); // set real tag to vtag type if not already the same if(RFIDlerConfig.TagType != RFIDlerVTag.TagType) if(!tag_set(RFIDlerVTag.TagType)) { memcpy(&RFIDlerConfig, &tmptag, sizeof(RFIDlerConfig)); return FALSE; } // reset target tag, but don't care if we get UID as it may not be in a valid mode get_tag_uid(tmp); // re-auth if(!tag_login(block, tmp, pass)) tag_auth(block, tmp, pass); // initialise target in default mode // get config block number if(!config_block_number(&config_block_no, RFIDlerConfig.TagType)) return FALSE; // get default config block data tmp[HEXDIGITS(RFIDlerVTag.BlockSize)]= '\0'; if (!config_block(tmp, RFIDlerConfig.TagType, RFIDlerConfig.TagType)) { memcpy(&RFIDlerConfig, &tmptag, sizeof(RFIDlerConfig)); return FALSE; } // write default config if(!write_tag(config_block_no, tmp, VERIFY)) { memcpy(&RFIDlerConfig, &tmptag, sizeof(RFIDlerConfig)); return FALSE; } // reset tag again get_tag_uid(tmp); // write all VTAG blocks with valid data in them // but avoid writing config block until last as tag may stop responding tmp[HEXDIGITS(RFIDlerVTag.BlockSize)]= '\0'; for(block= 0 ; block < RFIDlerVTag.DataBlocks ; ++block) if(block != config_block_no && RFIDlerVTag.Data[HEXDIGITS(RFIDlerVTag.BlockSize * block)]) { // try to login/auth in case target tag requires it // don't care if we fail if(!(auth= tag_login(block, tmp, pass))) auth= tag_auth(block, tmp, pass); memcpy(tmp, &RFIDlerVTag.Data[HEXDIGITS(RFIDlerVTag.BlockSize * block)], HEXDIGITS(RFIDlerVTag.BlockSize)); UserMessageNum("\r\n%d: ", block); UserMessage("%s", tmp); // failure allowed as we may be trying to write locked blocks if(!write_tag(block, tmp, VERIFY)) { UserMessage("%s", " Failed!"); if(!auth) UserMessage("%s", " (Auth/Login)"); } } // write config block (no verify as some tags stop talking after config change) if(!tag_login(block, tmp, pass)) tag_auth(block, tmp, pass); tmp[HEXDIGITS(RFIDlerVTag.BlockSize)]= '\0'; memcpy(tmp, &RFIDlerVTag.Data[HEXDIGITS(RFIDlerVTag.BlockSize * config_block_no)], HEXDIGITS(RFIDlerVTag.BlockSize)); UserMessageNum("\r\n\r\n%d: ", config_block_no); UserMessage("%s", tmp); if(!write_tag(config_block_no, tmp, NO_VERIFY)) { memcpy(&RFIDlerConfig, &tmptag, sizeof(RFIDlerConfig)); return FALSE; } memcpy(&RFIDlerConfig, &tmptag, sizeof(RFIDlerConfig)); return TRUE; }
// copy real tag to vtag or set up emulation BOOL vtag_copy_from_tag(BYTE *tagtype, BYTE *pass) { BYTE tmp[MAXUID + 1], tag, copy= FALSE, i; unsigned int config_block_no, user_block_no; // set target tag type if (strlen(tagtype) == 0) { if(RFIDlerVTag.TagType == TAG_TYPE_NONE) tag= RFIDlerConfig.TagType; else tag= RFIDlerVTag.TagType; } else if(!(tag= tag_get_type(tagtype))) return FALSE; // check we've got a tag to copy if(!get_tag_uid(tmp)) return FALSE; // set vtag to desired type vtag_set_tag_from_type(tag); // if tag & vtag are the same, just copy if(RFIDlerConfig.TagType == tag) { RFIDlerVTag.EmulatedTagType= TAG_TYPE_NONE; // auth if(!tag_login(0, TmpBits, pass)) tag_auth(0, TmpBits, pass); // copy UID strcpy(RFIDlerVTag.UID, tmp); // if no data to copy, we're done. if(RFIDlerVTag.DataBlocks == 0) return TRUE; // copy data blocks for(i= 0 ; i < RFIDlerVTag.DataBlocks ; ++i) { if (!read_tag(RFIDlerVTag.Data + HEXDIGITS(i * RFIDlerVTag.BlockSize), i, i)) UserMessageNum("%d: (fail)\r\n", i); else copy= TRUE; } return copy; } // otherwise, set up emulation RFIDlerVTag.EmulatedTagType= RFIDlerConfig.TagType; strcpy(RFIDlerVTag.UID, tmp); // get config & user data block numbers if(!config_block_number(&config_block_no, tag) || !config_user_block(&user_block_no, tag)) return FALSE; // get & store config block if (!config_block(&RFIDlerVTag.Data[HEXDIGITS(RFIDlerVTag.BlockSize * config_block_no)], RFIDlerConfig.TagType, tag)) return FALSE; // copy raw hex UID to data blocks memcpy(&RFIDlerVTag.Data[HEXDIGITS(RFIDlerVTag.BlockSize * user_block_no)], RFIDlerVTag.UID, strlen(RFIDlerVTag.UID)); return TRUE; }