Switching to new style.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
|
||||
#include "sc_hsm.h"
|
||||
|
||||
int cmd_read_binary()
|
||||
{
|
||||
int cmd_read_binary() {
|
||||
uint16_t fid = 0x0;
|
||||
uint32_t offset = 0;
|
||||
uint8_t ins = INS(apdu), p1 = P1(apdu), p2 = P2(apdu);
|
||||
@@ -26,26 +25,30 @@ int cmd_read_binary()
|
||||
|
||||
if ((ins & 0x1) == 0) {
|
||||
if ((p1 & 0x80) != 0) {
|
||||
if (!(ef = search_by_fid(p1&0x1f, NULL, SPECIFY_EF))) {
|
||||
if (!(ef = search_by_fid(p1 & 0x1f, NULL, SPECIFY_EF))) {
|
||||
return SW_FILE_NOT_FOUND();
|
||||
}
|
||||
offset = p2;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
offset = make_uint16_t(p1, p2) & 0x7fff;
|
||||
ef = currentEF;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (p1 == 0 && (p2 & 0xE0) == 0 && (p2 & 0x1f) != 0 && (p2 & 0x1f) != 0x1f) {
|
||||
if (!(ef = search_by_fid(p2&0x1f, NULL, SPECIFY_EF))) {
|
||||
if (!(ef = search_by_fid(p2 & 0x1f, NULL, SPECIFY_EF))) {
|
||||
return SW_FILE_NOT_FOUND();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint16_t file_id = make_uint16_t(p1, p2); // & 0x7fff;
|
||||
if (file_id == 0x0) {
|
||||
ef = currentEF;
|
||||
} else if (!(ef =
|
||||
search_by_fid(file_id, NULL,
|
||||
SPECIFY_EF)) && !(ef = search_dynamic_file(file_id))) {
|
||||
}
|
||||
else if (!(ef =
|
||||
search_by_fid(file_id, NULL,
|
||||
SPECIFY_EF)) && !(ef = search_dynamic_file(file_id))) {
|
||||
return SW_FILE_NOT_FOUND();
|
||||
}
|
||||
|
||||
@@ -55,7 +58,7 @@ int cmd_read_binary()
|
||||
|
||||
offset = 0;
|
||||
for (int d = 0; d < apdu.data[1]; d++) {
|
||||
offset |= apdu.data[2+d]<<(apdu.data[1]-1-d)*8;
|
||||
offset |= apdu.data[2 + d] << (apdu.data[1] - 1 - d) * 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,27 +72,28 @@ int cmd_read_binary()
|
||||
if (offset > data_len) {
|
||||
return SW_WRONG_P1P2();
|
||||
}
|
||||
uint16_t maxle = data_len-offset;
|
||||
uint16_t maxle = data_len - offset;
|
||||
if (apdu.ne > maxle) {
|
||||
apdu.ne = maxle;
|
||||
}
|
||||
if (offset) {
|
||||
memmove(res_APDU, res_APDU+offset, res_APDU_size-offset);
|
||||
memmove(res_APDU, res_APDU + offset, res_APDU_size - offset);
|
||||
//res_APDU += offset;
|
||||
res_APDU_size -= offset;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint16_t data_len = file_get_size(ef);
|
||||
if (offset > data_len) {
|
||||
return SW_WRONG_P1P2();
|
||||
}
|
||||
|
||||
uint16_t maxle = data_len-offset;
|
||||
uint16_t maxle = data_len - offset;
|
||||
if (apdu.ne > maxle) {
|
||||
apdu.ne = maxle;
|
||||
}
|
||||
memcpy(res_APDU, file_get_data(ef)+offset, data_len-offset);
|
||||
res_APDU_size = data_len-offset;
|
||||
memcpy(res_APDU, file_get_data(ef) + offset, data_len - offset);
|
||||
res_APDU_size = data_len - offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user