Skip to content

Commit fdc41e5

Browse files
committed
Add support for PHY command to store and change VIDPID and LED no. dynamically on reboot.
Signed-off-by: Pol Henarejos <[email protected]>
1 parent 5d0dc21 commit fdc41e5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/hsm/cmd_extras.c

+34
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,40 @@ int cmd_extras() {
195195
}
196196
}
197197
}
198+
#ifndef ENABLE_EMULATION
199+
else if (P1(apdu) == 0x1B) { // Set PHY
200+
if (apdu.nc == 0) {
201+
if (file_has_data(ef_phy)) {
202+
res_APDU_size = file_get_size(ef_phy);
203+
memcpy(res_APDU, file_get_data(ef_phy), res_APDU_size);
204+
}
205+
}
206+
else {
207+
uint8_t tmp[PHY_MAX_SIZE];
208+
memset(tmp, 0, sizeof(tmp));
209+
if (file_has_data(ef_phy)) {
210+
memcpy(tmp, file_get_data(ef_phy), MIN(sizeof(tmp), file_get_size(ef_phy)));
211+
}
212+
if (P2(apdu) == PHY_VID) { // VIDPID
213+
if (apdu.nc != 4) {
214+
return SW_WRONG_LENGTH();
215+
}
216+
memcpy(tmp + PHY_VID, apdu.data, 4);
217+
}
218+
else if (P2(apdu) == PHY_LED_GPIO || P2(apdu) == PHY_LED_MODE) {
219+
if (apdu.nc != 1) {
220+
return SW_WRONG_LENGTH();
221+
}
222+
tmp[P2(apdu)] = apdu.data[0];
223+
}
224+
else {
225+
return SW_INCORRECT_P1P2();
226+
}
227+
flash_write_data_to_file(ef_phy, tmp, sizeof(tmp));
228+
low_flash_available();
229+
}
230+
}
231+
#endif
198232
else {
199233
return SW_INCORRECT_P1P2();
200234
}

0 commit comments

Comments
 (0)