@@ -37,7 +37,7 @@ int cmd_extras() {
37
37
}
38
38
#endif
39
39
//check button (if enabled)
40
- if (wait_button_pressed () == true) {
40
+ if (wait_button_pressed () == true) {
41
41
return SW_SECURE_MESSAGE_EXEC_ERROR ();
42
42
}
43
43
if (P1 (apdu ) == 0xA ) { //datetime operations
@@ -243,30 +243,44 @@ int cmd_extras() {
243
243
else {
244
244
uint8_t tmp [PHY_MAX_SIZE ];
245
245
memset (tmp , 0 , sizeof (tmp ));
246
+ uint16_t opts = 0 ;
246
247
if (file_has_data (ef_phy )) {
247
248
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
+ }
248
252
}
249
253
if (P2 (apdu ) == PHY_VID ) { // VIDPID
250
254
if (apdu .nc != 4 ) {
251
255
return SW_WRONG_LENGTH ();
252
256
}
253
257
memcpy (tmp + PHY_VID , apdu .data , 4 );
258
+ opts |= PHY_OPT_VPID ;
254
259
}
255
260
else if (P2 (apdu ) == PHY_LED_GPIO || P2 (apdu ) == PHY_LED_MODE ) {
256
261
if (apdu .nc != 1 ) {
257
262
return SW_WRONG_LENGTH ();
258
263
}
259
264
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
+ }
260
271
}
261
272
else if (P2 (apdu ) == PHY_OPTS ) {
262
273
if (apdu .nc != 2 ) {
263
274
return SW_WRONG_LENGTH ();
264
275
}
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 );
266
278
}
267
279
else {
268
280
return SW_INCORRECT_P1P2 ();
269
281
}
282
+ tmp [PHY_OPTS ] = opts >> 8 ;
283
+ tmp [PHY_OPTS + 1 ] = opts & 0xff ;
270
284
file_put_data (ef_phy , tmp , sizeof (tmp ));
271
285
low_flash_available ();
272
286
}
0 commit comments