Skip to content

Commit 9a7be98

Browse files
committed
Settings proper phy options
Signed-off-by: Pol Henarejos <[email protected]>
1 parent c4a08af commit 9a7be98

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/hsm/cmd_extras.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int cmd_extras() {
3737
}
3838
#endif
3939
//check button (if enabled)
40-
if (wait_button_pressed() == true) {
40+
if (wait_button_pressed() == true) {
4141
return SW_SECURE_MESSAGE_EXEC_ERROR();
4242
}
4343
if (P1(apdu) == 0xA) { //datetime operations
@@ -243,30 +243,44 @@ int cmd_extras() {
243243
else {
244244
uint8_t tmp[PHY_MAX_SIZE];
245245
memset(tmp, 0, sizeof(tmp));
246+
uint16_t opts = 0;
246247
if (file_has_data(ef_phy)) {
247248
memcpy(tmp, file_get_data(ef_phy), MIN(sizeof(tmp), file_get_size(ef_phy)));
249+
if (file_get_size(ef_phy) >= 8) {
250+
opts = (tmp[PHY_OPTS] << 8) | tmp[PHY_OPTS + 1];
251+
}
248252
}
249253
if (P2(apdu) == PHY_VID) { // VIDPID
250254
if (apdu.nc != 4) {
251255
return SW_WRONG_LENGTH();
252256
}
253257
memcpy(tmp + PHY_VID, apdu.data, 4);
258+
opts |= PHY_OPT_VPID;
254259
}
255260
else if (P2(apdu) == PHY_LED_GPIO || P2(apdu) == PHY_LED_MODE) {
256261
if (apdu.nc != 1) {
257262
return SW_WRONG_LENGTH();
258263
}
259264
tmp[P2(apdu)] = apdu.data[0];
265+
if (P2(apdu) == PHY_LED_GPIO) {
266+
opts |= PHY_OPT_GPIO;
267+
}
268+
else if (P2(apdu) == PHY_LED_MODE) {
269+
opts |= PHY_OPT_LED;
270+
}
260271
}
261272
else if (P2(apdu) == PHY_OPTS) {
262273
if (apdu.nc != 2) {
263274
return SW_WRONG_LENGTH();
264275
}
265-
memcpy(tmp + PHY_OPTS, apdu.data, 2);
276+
uint16_t opt = (apdu.data[0] << 8) | apdu.data[1];
277+
opts = (opts & ~PHY_OPT_MASK) | (opt & PHY_OPT_MASK);
266278
}
267279
else {
268280
return SW_INCORRECT_P1P2();
269281
}
282+
tmp[PHY_OPTS] = opts >> 8;
283+
tmp[PHY_OPTS + 1] = opts & 0xff;
270284
file_put_data(ef_phy, tmp, sizeof(tmp));
271285
low_flash_available();
272286
}

0 commit comments

Comments
 (0)