chg: 'sm raw' - implemented 'r' don't read reply

This commit is contained in:
Chris 2018-07-05 21:10:21 +02:00
commit 36d774506c
5 changed files with 23 additions and 20 deletions

View file

@ -1028,7 +1028,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
break;
}
case CMD_SMART_RAW: {
SmartCardRaw(c->arg[0], c->d.asBytes);
SmartCardRaw(c->arg[0], c->arg[1], c->d.asBytes);
break;
}
case CMD_SMART_UPLOAD: {

View file

@ -15,7 +15,6 @@ int usage_sm_raw(void) {
PrintAndLogEx(NORMAL, "Usage: sc raw [h|r|c] d <0A 0B 0C ... hex>");
PrintAndLogEx(NORMAL, " h : this help");
PrintAndLogEx(NORMAL, " r : do not read response");
PrintAndLogEx(NORMAL, " c : calculate and append CRC");
PrintAndLogEx(NORMAL, " d <bytes> : bytes to send");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
@ -42,11 +41,16 @@ int CmdSmartRaw(const char *Cmd) {
int hexlen = 0;
uint8_t cmdp = 0;
bool errors = false;
bool errors = false, reply = true;
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'r':
reply = false;
cmdp++;
break;
case 'd': {
switch (param_gethex_to_eol(Cmd, cmdp+1, data, sizeof(data), &hexlen)) {
case 1:
@ -74,19 +78,20 @@ int CmdSmartRaw(const char *Cmd) {
//Validations
if (errors || cmdp == 0 ) return usage_sm_raw();
UsbCommand c = {CMD_SMART_RAW, {hexlen, 0, 0}};
UsbCommand c = {CMD_SMART_RAW, {0, hexlen, 0}};
memcpy(c.d.asBytes, data, hexlen );
clearCommandBuffer();
SendCommand(&c);
// reading response from smart card
UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
PrintAndLogEx(WARNING, "smart card response failed");
return 1;
if ( reply ) {
UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
PrintAndLogEx(WARNING, "smart card response failed");
return 1;
}
PrintAndLogEx(SUCCESS,"resp: %s", sprint_hex(resp.d.asBytes, resp.arg[0]));
}
PrintAndLogEx(SUCCESS,"resp: %s", sprint_hex(resp.d.asBytes, resp.arg[0]));
return 0;;
}
int CmdSmartUpgrade(const char *Cmd) {

View file

@ -502,8 +502,7 @@ uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base)
return deflt;
}
int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt)
{
int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt) {
int bg, en, i;
uint32_t temp;
@ -514,7 +513,7 @@ int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt)
if (en - bg + 1 != hexcnt) return 1;
for(i = 0; i < hexcnt; i += 2) {
if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1])) ) return 1;
if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1])) ) return 1;
sscanf((char[]){line[bg + i], line[bg + i + 1], 0}, "%X", &temp);
data[i / 2] = temp & 0xff;
@ -522,8 +521,7 @@ int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt)
return 0;
}
int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt)
{
int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt) {
int bg, en, i;
uint32_t temp;

View file

@ -525,7 +525,7 @@ void SmartCardAtr(void) {
cmd_send(CMD_ACK, len, 0, 0, resp, sizeof(smart_card_atr_t));
}
void SmartCardRaw( uint64_t arg0, uint8_t *data ) {
void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
#define ISO7618_MAX_FRAME 255
StartTicks();
I2C_Reset_EnterMainProgram();
@ -550,7 +550,7 @@ void SmartCardRaw( uint64_t arg0, uint8_t *data ) {
// start [C0 02] A0 A4 00 00 02 stop
// asBytes = A0 A4 00 00 02
// arg0 = len 5
I2C_BufferWrite(data, arg0, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN);
I2C_BufferWrite(data, arg1, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN);
// read response
// start [C0 03 start C1 len aa bb cc stop]

View file

@ -37,7 +37,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
// generice functions
void SmartCardAtr(void);
void SmartCardRaw(uint64_t arg0, uint8_t *data);
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data);
void SmartCardUpgrade(uint64_t arg0);
void I2C_print_status(void);