FreeCalypso > hg > freecalypso-tools
comparison target-utils/simagent/exchange.c @ 784:839bf41e7be0
simagent: X command parsing bugfix
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 13 Mar 2021 22:08:48 +0000 |
parents | c136a1a2474b |
children | 56506e9165bc |
comparison
equal
deleted
inserted
replaced
783:c136a1a2474b | 784:839bf41e7be0 |
---|---|
90 void | 90 void |
91 cmd_exchange(argstr) | 91 cmd_exchange(argstr) |
92 char *argstr; | 92 char *argstr; |
93 { | 93 { |
94 u8 cmd[260]; | 94 u8 cmd[260]; |
95 unsigned count; | |
95 int rc; | 96 int rc; |
96 | 97 |
97 if (sim_if_state != 2) { | 98 if (sim_if_state != 2) { |
98 printf("ERROR: SIM interface is not up\n"); | 99 printf("ERROR: SIM interface is not up\n"); |
99 return; | 100 return; |
100 } | 101 } |
101 rc = decode_hex_string_arg(argstr, cmd, 260); | 102 rc = decode_hex_string_arg(argstr, cmd, 260); |
102 if (rc < 0) | 103 if (rc < 0) |
103 return; | 104 return; |
104 if (rc < 5) { | 105 count = rc; |
106 if (count < 5) { | |
105 printf("ERROR: command APDU is shorter than 5 bytes\n"); | 107 printf("ERROR: command APDU is shorter than 5 bytes\n"); |
106 return; | 108 return; |
107 } | 109 } |
108 rc = flush_rx_fifo(); | 110 rc = flush_rx_fifo(); |
109 if (rc < 0) | 111 if (rc < 0) |
110 return; | 112 return; |
111 rc = send_to_sim(cmd, 5); | 113 rc = send_to_sim(cmd, 5); |
112 if (rc < 0) | 114 if (rc < 0) |
113 return; | 115 return; |
114 if (rc > 5) | 116 if (count > 5) |
115 exchange_data_out(cmd[1], cmd + 5, rc - 5); | 117 exchange_data_out(cmd[1], cmd + 5, count - 5); |
116 else | 118 else |
117 exchange_data_in(cmd[1], cmd[4]); | 119 exchange_data_in(cmd[1], cmd[4]); |
118 } | 120 } |