Esempio n. 1
0
int CmdLFPCF7931Write(const char *Cmd) {

    uint8_t ctmp = param_getchar(Cmd, 0);
    if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_write();

    uint8_t block = 0, bytepos = 0, data = 0;

    if ( param_getdec(Cmd, 0, &block) ) return usage_pcf7931_write();
    if ( param_getdec(Cmd, 1, &bytepos) ) return usage_pcf7931_write();

    if ( (block > 7) || (bytepos > 15) ) return usage_pcf7931_write();

    data  = param_get8ex(Cmd, 2, 0, 16);

    PrintAndLog("Writing block: %d", block);
    PrintAndLog("          pos: %d", bytepos);
    PrintAndLog("         data: 0x%02X", data);

    UsbCommand c = {CMD_PCF7931_WRITE, { block, bytepos, data} };
    memcpy(c.d.asDwords, configPcf.Pwd, sizeof(configPcf.Pwd) );
    c.d.asDwords[7] = (configPcf.OffsetWidth + 128);
    c.d.asDwords[8] = (configPcf.OffsetPosition + 128);
    c.d.asDwords[9] = configPcf.InitDelay;

    clearCommandBuffer();
    SendCommand(&c);
    //no ack?
    return 0;
}
Esempio n. 2
0
int CmdHFMFDesfire(const char *Cmd){
    // flush
	clearCommandBuffer();
    //WaitForResponseTimeout(CMD_ACK,NULL,100);
    CmdsParse(CommandTable, Cmd);
    return 0;
}
Esempio n. 3
0
int CmdLFNedapSim(const char *Cmd) {

	uint32_t cardnumber = 0, cn = 0;
	
	char cmdp = param_getchar(Cmd, 0);
	if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_nedap_sim();

	if (sscanf(Cmd, "%u", &cn ) != 1) return usage_lf_nedap_sim();
	
	cardnumber = (cn & 0x00FFFFFF);
	
	uint8_t bs[128];
	size_t size = sizeof(bs);
	memset(bs, 0x00, size);
	
	// NEDAP,  Biphase = 2, clock 64, inverted,  (DIPhase == inverted BIphase
	uint8_t  clk = 64, encoding = 2, separator = 0, invert = 1;
	uint16_t arg1, arg2;
	arg1 = clk << 8 | encoding;
	arg2 = invert << 8 | separator;
	
	if ( !GetNedapBits(cardnumber, bs)) {
		PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
		return 1;
	}	

	PrintAndLogEx(NORMAL, "bin  %s", sprint_bin_break(bs, 128, 32));
	PrintAndLogEx(NORMAL, "Simulating Nedap - CardNumber: %u", cardnumber );
	
	UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
	memcpy(c.d.asBytes, bs, size);
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 4
0
//This method should be called from the main sketch in loop();
void AsiMS2000::checkSerial()
{
  int inByte = 0;
  static int bufferPos = 0;
  static char commandBuffer [BUFFERSIZE];
  if(Serial1.available() > 0)
  {
    inByte = Serial1.read();
    if(bufferPos > BUFFERSIZE)
    {
      bufferPos = 0;
      bufferOverunError(commandBuffer);
      return;
    }
    
    //check for <CR> or | since arduino env can't send CR.
    if(inByte == 13 || inByte == 124)
    {
      commandBuffer[bufferPos]  = '\0';
      inputPrintln(commandBuffer);
      interpretCommand(commandBuffer);
      bufferPos =0;
    }
    else if(inByte == 10 || inByte == 27)//backspace or escape
    {
      clearCommandBuffer(commandBuffer);
      bufferPos = 0;
    }
    else if(inByte > 31)//ignore control characters
    {
      commandBuffer[bufferPos++] = inByte;
    }
  }
}
Esempio n. 5
0
void AsiMS2000::interpretCommand(char commandBuffer[])
{
    String c = String(commandBuffer);
    int s = c.indexOf(' ');
    clearCommandBuffer(commandBuffer);
    
    String base;
    if(s > 0)
    {
      base = c.substring(0,s);
      _args = c.substring(s);
#if ARDUINO>=100//toUppercase modifies string in place in 1.0
      _args.toUpperCase();
#else
      _args = _args.toUpperCase();
#endif
      
    }
    else
    {
      base = c;
    }
    
    _isQuery = isQueryCommand(c);
    isAxisInCommand();
    int commandNum = getCommandNum(base);
    if(commandNum > -1)
    {
      selectCommand(commandNum);
    }
}
Esempio n. 6
0
// fast method to just read the UID of a tag (collission detection not supported)
//		*buf	should be large enough to fit the 64bit uid
// returns 1 if suceeded
int getUID(uint8_t *buf) {

	UsbCommand resp;
	UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?

	c.d.asBytes[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
	c.d.asBytes[1] = ISO15_CMD_INVENTORY;
	c.d.asBytes[2] = 0; // mask length

	AddCrc(c.d.asBytes, 3);
	c.arg[0] = 5; // len

	uint8_t retry;
	
	// don't give up the at the first try			
	for (retry = 0; retry < 3; retry++) {

		clearCommandBuffer();
		SendCommand(&c);
		
		if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
			
			uint8_t resplen = resp.arg[0];
			if (resplen >= 12 && CheckCrc(resp.d.asBytes, 12)) {
			   memcpy(buf, resp.d.asBytes + 2, 8);
			   return 1;
			} 
		} 
	} // retry
	
	if ( retry >= 3 )
		PrintAndLogEx(WARNING, "timeout while waiting for reply.");
	
	return 0;
}
Esempio n. 7
0
//TODO: write a help text (iceman)
int CmdLegicRfSim(const char *Cmd) {
	UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}};
	sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]);
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 8
0
int CmdPyramidSim(const char *Cmd) {

	char cmdp = param_getchar(Cmd, 0);
	if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_sim();

	uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;

	uint8_t bs[128];
	size_t size = sizeof(bs);
	memset(bs, 0x00, size);

	// Pyramid uses:  fcHigh: 10, fcLow: 8, clk: 50, invert: 0
	uint64_t arg1, arg2;
	arg1 = (10 << 8) + 8;
	arg2 = 50 | 0;

	if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_pyramid_sim();

	facilitycode = (fc & 0x000000FF);
	cardnumber = (cn & 0x0000FFFF);

	if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
		PrintAndLog("Error with tag bitstream generation.");
		return 1;
	}

	PrintAndLog("Simulating Farpointe/Pyramid - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );

	UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
	memcpy(c.d.asBytes, bs, size);
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 9
0
int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) {
	UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, blockBtWidth}};
	memcpy(c.d.asBytes, data, blocksCount * blockBtWidth); 

	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 10
0
/* send a command before reading */
int CmdLFCommandRead(const char *Cmd)
{
	static char dummy[3] = {0x20,0x00,0x00};
	UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K};
	bool errors = FALSE;
	//uint8_t divisor = 95; //125khz
	uint8_t cmdp = 0;
	int strLength = 0;
	while(param_getchar(Cmd, cmdp) != 0x00)
	{
		switch(param_getchar(Cmd, cmdp))
		{
		case 'h':
			return usage_lf_cmdread();
		case 'H':
			//divisor = 88;
			dummy[1]='h';
			cmdp++;
			break;
		case 'L':
			cmdp++;
			break;
		case 'c':
			strLength = param_getstr(Cmd, cmdp+1, (char *)&c.d.asBytes);
			cmdp+=2;
			break;
		case 'd':
			c.arg[0] = param_get32ex(Cmd, cmdp+1, 0, 10);
			cmdp+=2;
			break;
		case 'z':
			c.arg[1] = param_get32ex(Cmd, cmdp+1, 0, 10);
			cmdp+=2;
			break;
		case 'o':
			c.arg[2] = param_get32ex(Cmd, cmdp+1, 0, 10);
			cmdp+=2;
			break;
		default:
			PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
			errors = 1;
			break;
		}
		if(errors) break;
	}
	// No args
	if(cmdp == 0) errors = 1;

	//Validations
	if(errors) return usage_lf_cmdread();
	
	// in case they specified 'H'
	strcpy((char *)&c.d.asBytes + strlen((char *)c.d.asBytes), dummy);

	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 11
0
// Record Activity without enabeling carrier
//helptext
int CmdHF15Record(const char *Cmd) {
	char cmdp = param_getchar(Cmd, 0);
	if (cmdp == 'h' || cmdp == 'H') return usage_15_record();
	
	UsbCommand c = {CMD_RECORD_RAW_ADC_SAMPLES_ISO_15693, {0,0,0}};
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 12
0
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {
	UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};
	clearCommandBuffer();
 	SendCommand(&c);
	UsbCommand resp;
	if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1;
	memcpy(data, resp.d.asBytes, blocksCount * 16);
	return 0;
}
Esempio n. 13
0
//TODO: write a help text (iceman)
int CmdLegicRfWrite(const char *Cmd) {
    UsbCommand c = {CMD_WRITER_LEGIC_RF};
    int res = sscanf(Cmd, " 0x%"llx" 0x%"llx, &c.arg[0], &c.arg[1]);
	if(res != 2) {
		PrintAndLog("Please specify the offset and length as two hex strings");
        return -1;
    }
	clearCommandBuffer();
    SendCommand(&c);
    return 0;
}
Esempio n. 14
0
// finds the AFI (Application Family Idendifier) of a card, by trying all values
// (There is no standard way of reading the AFI, allthough some tags support this)
// helptext
int CmdHF15Afi(const char *Cmd) {
	char cmdp = param_getchar(Cmd, 0);
	if (cmdp == 'h' || cmdp == 'H') return usage_15_findafi();

	PrintAndLogEx(NORMAL, "press pm3-button to cancel");
	
	UsbCommand c = {CMD_ISO_15693_FIND_AFI, {strtol(Cmd, NULL, 0), 0, 0}};
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 15
0
int CmdPyramidClone(const char *Cmd) {

	char cmdp = param_getchar(Cmd, 0);
	if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_clone();

	uint32_t facilitycode=0, cardnumber=0, fc = 0, cn = 0;
	uint32_t blocks[5];
	uint8_t i;
	uint8_t bs[128];
	memset(bs, 0x00, sizeof(bs));

	if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_pyramid_clone();

	facilitycode = (fc & 0x000000FF);
	cardnumber = (cn & 0x0000FFFF);
	
	if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
		PrintAndLog("Error with tag bitstream generation.");
		return 1;
	}

	//Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks
	blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<<T55x7_MAXBLOCK_SHIFT;

	if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
		blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;

	blocks[1] = bytebits_to_byte(bs,32);
	blocks[2] = bytebits_to_byte(bs+32,32);
	blocks[3] = bytebits_to_byte(bs+64,32);
	blocks[4] = bytebits_to_byte(bs+96,32);

	PrintAndLog("Preparing to clone Farpointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
	PrintAndLog("Blk | Data ");
	PrintAndLog("----+------------");
	for ( i = 0; i<5; ++i )
		PrintAndLog(" %02d | %08" PRIx32, i, blocks[i]);

	UsbCommand resp;
	UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};

	for ( i = 0; i<5; ++i ) {
		c.arg[0] = blocks[i];
		c.arg[1] = i;
		clearCommandBuffer();
		SendCommand(&c);
		if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
			PrintAndLog("Error occurred, device did not respond during write operation.");
			return -1;
		}
	}
	return 0;
}
Esempio n. 16
0
// * Acquire Samples as Reader (enables carrier, sends inquiry)
//helptext
int CmdHF15Samples(const char *Cmd) {
	char cmdp = param_getchar(Cmd, 0);
	if (cmdp == 'h' || cmdp == 'H') return usage_15_samples();

	UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693, {0,0,0}};
	clearCommandBuffer();	
	SendCommand(&c);
	
	//download samples 
	getSamples(0, false);
	return 0;
}
Esempio n. 17
0
int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){
	*key = 0;
	UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType<<8)), clear_trace, keycnt}};
	memcpy(c.d.asBytes, keyBlock, 6 * keycnt);
	clearCommandBuffer();
	SendCommand(&c);
	UsbCommand resp;
	if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) return 1;
	if ((resp.arg[0] & 0xff) != 0x01) return 2;
	*key = bytes_to_num(resp.d.asBytes, 6);
	return 0;
}
Esempio n. 18
0
int CmdPing(const char *Cmd)
{
	clearCommandBuffer();
	UsbCommand resp;
	UsbCommand c = {CMD_PING};
	SendCommand(&c);
	if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
		PrintAndLog("Ping successfull");
	}else{
		PrintAndLog("Ping failed");
	}
	return 0;
}
Esempio n. 19
0
int CmdStatus(const char *Cmd)
{
	uint8_t speed_test_buffer[USB_CMD_DATA_SIZE];
	sample_buf = speed_test_buffer;

	clearCommandBuffer();
	UsbCommand c = {CMD_STATUS};
	SendCommand(&c);
	if (!WaitForResponseTimeout(CMD_ACK,&c,1900)) {
		PrintAndLog("Status command failed. USB Speed Test timed out");
	}
	return 0;
}
Esempio n. 20
0
int CmdLFPCF7931Read(const char *Cmd) {

    uint8_t ctmp = param_getchar(Cmd, 0);
    if ( ctmp == 'H' || ctmp == 'h' ) return usage_pcf7931_read();

    UsbCommand resp;
    UsbCommand c = {CMD_PCF7931_READ, {0, 0, 0}};
    clearCommandBuffer();
    SendCommand(&c);
    if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2500) ) {
        PrintAndLog("command execution time out");
        return 1;
    }
    return 0;
}
Esempio n. 21
0
int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {
	uint8_t isOK = 0;
	UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, blockNo, 0}};	
	clearCommandBuffer();
	SendCommand(&c);
	UsbCommand resp;
	if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
		isOK  = resp.arg[0] & 0xff;
		memcpy(data, resp.d.asBytes, 16);
		if (!isOK) return 2;
	} else {
		PrintAndLog("Command execute timeout");
		return 1;
	}
	return 0;
}
Esempio n. 22
0
// Simulation is still not working very good
// helptext
int CmdHF15Sim(const char *Cmd) {
	char cmdp = param_getchar(Cmd, 0);
	if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') return usage_15_sim();

	uint8_t uid[8] = {0,0,0,0,0,0,0,0};	
	if (param_gethex(Cmd, 0, uid, 16)) {
		PrintAndLogEx(NORMAL, "UID must include 16 HEX symbols");
		return 0;
	}
	
	PrintAndLogEx(NORMAL, "Starting simulating UID %s", sprint_hex(uid, sizeof(uid)) );

	UsbCommand c = {CMD_SIMTAG_ISO_15693, {0, 0, 0}};
	memcpy(c.d.asBytes, uid, 8);
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 23
0
int CmdLegicRFRead(const char *Cmd) {
	
	// params:
	// offset in data
	// number of bytes.
	char cmdp = param_getchar(Cmd, 0);
	if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_read();
	
	int byte_count=0, offset=0;
	sscanf(Cmd, "%i %i", &offset, &byte_count);
	if(byte_count == 0) byte_count = -1;
	if(byte_count + offset > 1024) byte_count = 1024 - offset;

	UsbCommand c= {CMD_READER_LEGIC_RF, {offset, byte_count, 0}};
	clearCommandBuffer();
	SendCommand(&c);
	return 0;
}
Esempio n. 24
0
int CmdVersion(const char *Cmd)
{

	clearCommandBuffer();
	UsbCommand c = {CMD_VERSION};
	static UsbCommand resp = {0, {0, 0, 0}};

	if (resp.arg[0] == 0 && resp.arg[1] == 0) { // no cached information available
		SendCommand(&c);
		if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
			PrintAndLog("Prox/RFID mark3 RFID instrument");
			PrintAndLog((char*)resp.d.asBytes);
			lookupChipID(resp.arg[0], resp.arg[1]);
		}
	} else {
		PrintAndLog("[[[ Cached information ]]]\n");
		PrintAndLog("Prox/RFID mark3 RFID instrument");
		PrintAndLog((char*)resp.d.asBytes);
		lookupChipID(resp.arg[0], resp.arg[1]);
		PrintAndLog("");
	}
	return 0;
}
Esempio n. 25
0
int CmdLegicRfFill(const char *Cmd) {
    UsbCommand cmd = {CMD_WRITER_LEGIC_RF};
    int res = sscanf(Cmd, " 0x%"llx" 0x%"llx" 0x%"llx, &cmd.arg[0], &cmd.arg[1], &cmd.arg[2]);
    if(res != 3) {
        PrintAndLog("Please specify the offset, length and value as two hex strings");
        return -1;
    }

    int i;
    UsbCommand c = {CMD_DOWNLOADED_SIM_SAMPLES_125K, {0, 0, 0}};
    for(i = 0; i < 48; i++) {
		c.d.asBytes[i] = cmd.arg[2];
    }
	
	for(i = 0; i < 22; i++) {
		c.arg[0] = i*48;
		SendCommand(&c);
		WaitForResponse(CMD_ACK,NULL);
	}
	clearCommandBuffer();
    SendCommand(&cmd);
    return 0;
 }
Esempio n. 26
0
/**
* Data transfer from Proxmark to client. This method times out after
* ms_timeout milliseconds.
* @brief GetFromDevice
* @param memtype Type of memory to download from proxmark
* @param dest Destination address for transfer
* @param bytes number of bytes to be transferred
* @param start_index offset into Proxmark3 BigBuf[]
* @param response struct to copy last command (CMD_ACK) into
* @param ms_timeout timeout in milliseconds
* @param show_warning display message after 2 seconds
* @return true if command was returned, otherwise false
*/
bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
	
	if (dest == NULL) return false;
	if (bytes == 0) return true;

	UsbCommand resp;
	if (response == NULL)
		response = &resp;

	// clear 
	clearCommandBuffer();
			
	switch (memtype) {
		case BIG_BUF: {
			UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
			SendCommand(&c);
			return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
		}
		case BIG_BUF_EML: {
			UsbCommand c = {CMD_DOWNLOAD_EML_BIGBUF, {start_index, bytes, 0}};
			SendCommand(&c);			
			return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
		}
		case FLASH_MEM: {			
			UsbCommand c = {CMD_DOWNLOAND_FLASH_MEM, {start_index, bytes, 0}};
			SendCommand(&c);
			return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_FLASHMEM);
		}
		case SIM_MEM: {
			//UsbCommand c = {CMD_DOWNLOAND_SIM_MEM, {start_index, bytes, 0}};
			//SendCommand(&c);
			//return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM);
			return false;
		}
	}
	return false;
}
Esempio n. 27
0
int CmdHF15Raw(const char *Cmd) {

	char cmdp = param_getchar(Cmd, 0);
	if (strlen(Cmd)<3 || cmdp == 'h' || cmdp == 'H') return usage_15_raw();

	UsbCommand resp;
	UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
	int reply = 1, fast = 1, i = 0;
	bool crc = false;
	char buf[5] = "";
	uint8_t data[100];
	uint32_t datalen = 0, temp;
	
	// strip
	while (*Cmd==' ' || *Cmd=='\t') Cmd++;
	
	while (Cmd[i]!='\0') {
		if (Cmd[i]==' ' || Cmd[i]=='\t') { i++; continue; }
		if (Cmd[i]=='-') {
			switch (Cmd[i+1]) {
				case 'r': 
				case 'R': 
					reply = 0;
					break;
				case '2':
					fast = 0;
					break;
				case 'c':
				case 'C':				
					crc = true;
					break;
				default:
					PrintAndLogEx(WARNING, "Invalid option");
					return 0;
			}
			i+=2;
			continue;
		}
		if ((Cmd[i]>='0' && Cmd[i]<='9') ||
		    (Cmd[i]>='a' && Cmd[i]<='f') ||
		    (Cmd[i]>='A' && Cmd[i]<='F') ) {
		    buf[strlen(buf)+1] = 0;
		    buf[strlen(buf)] = Cmd[i];
		    i++;
		    
		    if (strlen(buf) >= 2) {
		    	sscanf(buf, "%x", &temp);
		    	data[datalen] = (uint8_t)(temp & 0xff);
		    	datalen++;
		    	*buf = 0;
		    }
		    continue;
		}
		PrintAndLogEx(WARNING, "Invalid char on input");
		return 0;
	}
	
	if (crc) {
		AddCrc(data, datalen);
		datalen += 2;
	}
	
	c.arg[0] = datalen;
	c.arg[1] = fast;
	c.arg[2] = reply;
	memcpy(c.d.asBytes, data, datalen);

	clearCommandBuffer();	
	SendCommand(&c);
	
	if (reply) {
		if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
			uint8_t len = resp.arg[0];
			PrintAndLogEx(NORMAL, "received %i octets", len);
			PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.d.asBytes, len) );
		} else {
			PrintAndLogEx(WARNING, "timeout while waiting for reply.");
		}		
	}
	return 0;
}
Esempio n. 28
0
// Reads all memory pages
// need to write to file
int CmdHF15Dump(const char*Cmd) {
	
	uint8_t fileNameLen = 0;
	char filename[FILE_PATH_SIZE] = {0};
	char * fptr = filename;
	bool errors = false;
	uint8_t cmdp = 0;
	uint8_t uid[8] = {0,0,0,0,0,0,0,0};	
	
	while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
		switch(param_getchar(Cmd, cmdp)) {
		case 'h':
		case 'H':
			return usage_15_dump();
		case 'f':
		case 'F':
			fileNameLen = param_getstr(Cmd, cmdp+1, filename, FILE_PATH_SIZE); 
			cmdp += 2;
			break;
		default:
			PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
			errors = true;
			break;
		}
	}

	//Validations
	if (errors) return usage_15_dump();
	
	if (fileNameLen < 1) {

		PrintAndLogEx(INFO, "Using UID as filename");

		if (!getUID(uid)) {
			PrintAndLogEx(WARNING, "No tag found.");
			return 1;
		}
		
		fptr += sprintf(fptr, "hf-15-"); 
		FillFileNameByUID(fptr,uid,"-dump",sizeof(uid));

	}	
	// detect blocksize from card :)
	
	PrintAndLogEx(NORMAL, "Reading memory from tag UID %s", sprintUID(NULL, uid));

	int blocknum = 0;
	uint8_t *recv = NULL;

	// memory.
	t15memory mem[256];
	
	uint8_t data[256*4] = {0};
	memset(data, 0, sizeof(data));

	UsbCommand resp;
	UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
	uint8_t *req = c.d.asBytes;
	req[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS;
	req[1] = ISO15_CMD_READ;

	// copy uid to read command
	memcpy(req+2, uid, sizeof(uid));
	
	for (int retry = 0; retry < 5; retry++) {
	
		req[10] = blocknum;
		AddCrc(req, 11);
		c.arg[0] = 13;
	
		clearCommandBuffer();
		SendCommand(&c);
				
		if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {

			uint8_t len = resp.arg[0];
			if ( len < 2 ) {
				PrintAndLogEx(FAILED, "iso15693 card select failed");
				continue;		
			}
			
			recv = resp.d.asBytes;
			
			if ( !CheckCrc(recv, len) ) {
				PrintAndLogEx(FAILED, "crc fail");
				continue;
			}

			if (recv[0] & ISO15_RES_ERROR) {
				PrintAndLogEx(FAILED, "Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1]) ); 
				break;
			}
								
			mem[blocknum].lock = resp.d.asBytes[0];
			memcpy(mem[blocknum].block, resp.d.asBytes + 1, 4);					
			memcpy(data + (blocknum * 4), resp.d.asBytes + 1, 4);
			
			retry = 0;
			blocknum++;
			
			printf("."); fflush(stdout);
		} 
	}
	PrintAndLogEx(NORMAL, "\n");

	PrintAndLogEx(NORMAL, "block#   | data         |lck| ascii");
	PrintAndLogEx(NORMAL, "---------+--------------+---+----------");	
	for (int i = 0; i < blocknum; i++) {
		PrintAndLogEx(NORMAL, "%3d/0x%02X | %s | %d | %s", i, i, sprint_hex(mem[i].block, 4 ), mem[i].lock, sprint_ascii(mem[i].block, 4) );
	}
	PrintAndLogEx(NORMAL, "\n");

	size_t datalen = blocknum * 4;
	saveFileEML(filename, "eml", data, datalen, 4);	
	saveFile(filename, "bin", data, datalen);
	return 0;
}
Esempio n. 29
0
/**
 * Commandline handling: HF15 CMD SYSINFO
 * get system information from tag/VICC
 */
int CmdHF15Info(const char *Cmd) {

	char cmdp = param_getchar(Cmd, 0);
	if (strlen(Cmd)<1 || cmdp == 'h' || cmdp == 'H') return usage_15_info();

	UsbCommand resp;
	uint8_t *recv;
	UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
	uint8_t *req = c.d.asBytes;
	char cmdbuf[100];
	char *cmd = cmdbuf;
	memset(cmdbuf, 0, sizeof(cmdbuf));
	
	strncpy(cmd, Cmd, 99);
	
	if ( !prepareHF15Cmd(&cmd, &c, ISO15_CMD_SYSINFO) )
		return 0;

	AddCrc(req,  c.arg[0]);
	c.arg[0] += 2;

	//PrintAndLogEx(NORMAL, "cmd %s", sprint_hex(c.d.asBytes, reqlen) ); 
	
	clearCommandBuffer();
	SendCommand(&c);

	if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2000) ) {
		PrintAndLogEx(NORMAL, "iso15693 card select failed");
		return 1;
	}
	
	uint32_t status = resp.arg[0];
	
	if ( status < 2 ) {
		PrintAndLogEx(NORMAL, "iso15693 card doesn't answer to systeminfo command");
		return 1;		
	}
	
	recv = resp.d.asBytes;	
	
	if ( recv[0] & ISO15_RES_ERROR ) {
		PrintAndLogEx(NORMAL, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); 
		return 3;
	}
	
	PrintAndLogEx(NORMAL, "  UID  : %s", sprintUID(NULL, recv+2));
	PrintAndLogEx(NORMAL, "  TYPE : %s", getTagInfo_15(recv+2));
	PrintAndLogEx(NORMAL, "  SYSINFO : %s", sprint_hex(recv, status-2));

	// DSFID
	if (recv[1] & 0x01) 
		PrintAndLogEx(NORMAL, "     - DSFID supported        [0x%02X]", recv[10]);
	else 
		PrintAndLogEx(NORMAL, "     - DSFID not supported");
	
	// AFI
	if (recv[1] & 0x02) 
		PrintAndLogEx(NORMAL, "     - AFI   supported        [0x%02X]", recv[11]);
	else 
		PrintAndLogEx(NORMAL, "     - AFI   not supported");

	// IC reference
	if (recv[1] & 0x08) 
		PrintAndLogEx(NORMAL, "     - IC reference supported [0x%02X]", recv[14]);
	else 
		PrintAndLogEx(NORMAL, "     - IC reference not supported");

	// memory 
	if (recv[1] & 0x04) {
		PrintAndLogEx(NORMAL, "     - Tag provides info on memory layout (vendor dependent)");
		uint8_t blocks = recv[12]+1;
		uint8_t size = (recv[13] & 0x1F);
		PrintAndLogEx(NORMAL, "           %u (or %u) bytes/blocks x %u blocks", size+1, size, blocks );
	} else {
		PrintAndLogEx(NORMAL, "     - Tag does not provide information on memory layout");
	}
	PrintAndLogEx(NORMAL, "\n");
	return 0;
}
Esempio n. 30
0
int CmdLFPac(const char *Cmd) {
	clearCommandBuffer();
	CmdsParse(CommandTable, Cmd);
	return 0;
}