summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/include/vboot_api.h4
-rw-r--r--firmware/lib/vboot_ui.c12
-rw-r--r--firmware/lib/vboot_ui_menu.c8
-rw-r--r--tests/vboot_api_kernel2_tests.c70
-rw-r--r--tests/vboot_detach_menu_tests.c48
5 files changed, 73 insertions, 69 deletions
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 904e5a20..0d3addff 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -717,8 +717,12 @@ VbError_t VbExDisplayDebugInfo(const char *info_str);
/*****************************************************************************/
/* Keyboard and switches */
+/* Key code for CTRL + letter */
+#define VB_KEY_CTRL(letter) (letter & 0x1f)
+
/* Key codes for required non-printable-ASCII characters. */
enum VbKeyCode_t {
+ VB_KEY_ENTER = '\r',
VB_KEY_ESC = 0x1b,
VB_KEY_UP = 0x100,
VB_KEY_DOWN = 0x101,
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index a866e10b..57e546a2 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -113,7 +113,7 @@ int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags)
if (VbWantShutdown(ctx, key))
return -1;
switch (key) {
- case '\r':
+ case VB_KEY_ENTER:
/* If we require a trusted keyboard for confirmation,
* but the keyboard may be faked (for instance, a USB
* device), beep and keep waiting.
@@ -317,7 +317,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
case 0:
/* nothing pressed */
break;
- case '\r':
+ case VB_KEY_ENTER:
/* Only disable virtual dev switch if allowed by GBB */
if (!(sd->gbb_flags &
VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM))
@@ -375,14 +375,14 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
return VBERROR_LOAD_KERNEL_RECOVERY;
}
break;
- case 0x04:
+ case VB_KEY_CTRL('D'):
/* Ctrl+D = dismiss warning; advance to timeout */
VB2_DEBUG("VbBootDeveloper() - "
"user pressed Ctrl+D; skip delay\n");
ctrl_d_pressed = 1;
goto fallout;
break;
- case 0x0c:
+ case VB_KEY_CTRL('L'):
VB2_DEBUG("VbBootDeveloper() - "
"user pressed Ctrl+L; Try alt firmware\n");
if (allow_legacy) {
@@ -400,7 +400,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
* The Ctrl-Enter is special for Lumpy test purpose;
* fall through to Ctrl+U handler.
*/
- case 0x15:
+ case VB_KEY_CTRL('U'):
/* Ctrl+U = try USB boot, or beep if failure */
VB2_DEBUG("VbBootDeveloper() - "
"user pressed Ctrl+U; try USB\n");
@@ -557,7 +557,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx)
* - not already in dev mode
* - user forced recovery mode
*/
- if (key == 0x04 &&
+ if (key == VB_KEY_CTRL('D') &&
shared->flags & VBSD_HONOR_VIRT_DEV_SWITCH &&
!(shared->flags & VBSD_BOOT_DEV_SWITCH_ON) &&
(shared->flags & VBSD_BOOT_REC_SWITCH_ON)) {
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index c0246462..e269d237 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -463,7 +463,7 @@ static VbError_t vb2_handle_menu_input(struct vb2_context *ctx,
vb2_draw_current_screen(ctx);
break;
case VB_BUTTON_POWER_SHORT_PRESS:
- case '\r':
+ case VB_KEY_ENTER:
/* Menuless screens shut down on power button press. */
if (!menus[current_menu].size)
return VBERROR_SHUTDOWN_REQUESTED;
@@ -753,16 +753,16 @@ static VbError_t vb2_developer_menu(struct vb2_context *ctx)
switch (key) {
case VB_BUTTON_VOL_DOWN_LONG_PRESS:
- case 'D' & 0x1f:
+ case VB_KEY_CTRL('D'):
/* Ctrl+D = boot from internal disk */
ret = boot_disk_action(ctx);
break;
- case 'L' & 0x1f:
+ case VB_KEY_CTRL('L'):
/* Ctrl+L = boot alternative bootloader */
ret = enter_altfw_menu(ctx);
break;
case VB_BUTTON_VOL_UP_LONG_PRESS:
- case 'U' & 0x1f:
+ case VB_KEY_CTRL('U'):
/* Ctrl+U = boot from USB or SD card */
ret = boot_usb_action(ctx);
break;
diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c
index 2f1dee90..9b887597 100644
--- a/tests/vboot_api_kernel2_tests.c
+++ b/tests/vboot_api_kernel2_tests.c
@@ -222,7 +222,7 @@ static void VbUserConfirmsTest(void)
TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Shutdown requested");
ResetMocks();
- mock_keypress[0] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
TEST_EQ(VbUserConfirms(&ctx, 0), 1, "Enter");
ResetMocks();
@@ -241,13 +241,13 @@ static void VbUserConfirmsTest(void)
TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Space ignored");
ResetMocks();
- mock_keypress[0] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_MUST_TRUST_KEYBOARD),
1, "Enter with trusted keyboard");
ResetMocks();
- mock_keypress[0] = '\r'; /* untrusted */
+ mock_keypress[0] = VB_KEY_ENTER; /* untrusted */
mock_keypress[1] = ' ';
TEST_EQ(VbUserConfirms(&ctx,
VB_CONFIRM_SPACE_MEANS_NO |
@@ -262,7 +262,7 @@ static void VbUserConfirmsTest(void)
1, "Recovery button");
ResetMocks();
- mock_keypress[0] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
mock_keypress[1] = 'y';
mock_keypress[2] = 'z';
mock_keypress[3] = ' ';
@@ -390,7 +390,7 @@ static void VbBootDevTest(void)
ResetMocks();
shared->flags = VBSD_HONOR_VIRT_DEV_SWITCH | VBSD_BOOT_DEV_SWITCH_ON;
mock_keypress[0] = ' ';
- mock_keypress[1] = '\r';
+ mock_keypress[1] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED,
"Space = tonorm");
TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING,
@@ -419,16 +419,16 @@ static void VbBootDevTest(void)
/* Enter doesn't by default */
ResetMocks();
shared->flags = VBSD_HONOR_VIRT_DEV_SWITCH | VBSD_BOOT_DEV_SWITCH_ON;
- mock_keypress[0] = '\r';
- mock_keypress[1] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
+ mock_keypress[1] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloper(&ctx), 1002, "Enter ignored");
/* Enter does if GBB flag set */
ResetMocks();
shared->flags = VBSD_HONOR_VIRT_DEV_SWITCH | VBSD_BOOT_DEV_SWITCH_ON;
sd->gbb_flags |= VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM;
- mock_keypress[0] = '\r';
- mock_keypress[1] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
+ mock_keypress[1] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED,
"Enter = tonorm");
@@ -437,7 +437,7 @@ static void VbBootDevTest(void)
shared->flags = VBSD_HONOR_VIRT_DEV_SWITCH | VBSD_BOOT_DEV_SWITCH_ON;
sd->gbb_flags |= VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON;
mock_keypress[0] = ' ';
- mock_keypress[1] = '\r';
+ mock_keypress[1] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloper(&ctx), 1002,
"Can't tonorm gbb-dev");
@@ -464,7 +464,7 @@ static void VbBootDevTest(void)
/* Ctrl+D dismisses warning */
ResetMocks();
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+D");
TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0,
" recovery reason");
@@ -473,14 +473,14 @@ static void VbBootDevTest(void)
/* Ctrl+D doesn't boot legacy even if GBB flag is set */
ResetMocks();
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
sd->gbb_flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY;
TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+D");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
/* Ctrl+L tries legacy boot mode only if enabled */
ResetMocks();
- mock_keypress[0] = 0x0c;
+ mock_keypress[0] = VB_KEY_CTRL('L');
TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+L normal");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
@@ -488,7 +488,7 @@ static void VbBootDevTest(void)
ResetMocks();
shutdown_request_calls_left = 1000;
sd->gbb_flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = 0x0c;
+ mock_keypress[0] = VB_KEY_CTRL('L');
TEST_EQ(VbBootDeveloper(&ctx), VBERROR_SHUTDOWN_REQUESTED,
"Ctrl+L force legacy");
TEST_EQ(vbexlegacy_called, 0, " try legacy");
@@ -496,7 +496,7 @@ static void VbBootDevTest(void)
/* Enter altfw menu and select firmware 0 */
ResetMocks();
sd->gbb_flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = 0x0c;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = '0';
TEST_EQ(VbBootDeveloper(&ctx), 1002,
"Ctrl+L force legacy");
@@ -506,7 +506,7 @@ static void VbBootDevTest(void)
/* Enter altfw menu and then exit it */
ResetMocks();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = 0x0c;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = VB_KEY_ESC;
TEST_EQ(VbBootDeveloper(&ctx), 1002,
"Ctrl+L nv legacy");
@@ -515,7 +515,7 @@ static void VbBootDevTest(void)
/* Enter altfw menu and select firmware 0 */
ResetMocks();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = 0x0c;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = '0';
TEST_EQ(VbBootDeveloper(&ctx), 1002,
"Ctrl+L nv legacy");
@@ -525,7 +525,7 @@ static void VbBootDevTest(void)
/* Enter altfw menu and select firmware 0 */
ResetMocks();
VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY;
- mock_keypress[0] = 0x0c;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = '0';
TEST_EQ(VbBootDeveloper(&ctx), 1002,
"Ctrl+L fwmp legacy");
@@ -566,34 +566,34 @@ static void VbBootDevTest(void)
/* Ctrl+U boots USB only if enabled */
ResetMocks();
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+U normal");
/* Ctrl+U enabled, with good USB boot */
ResetMocks();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
vbtlk_retval = VBERROR_SUCCESS - VB_DISK_FLAG_REMOVABLE;
TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U USB");
/* Ctrl+U enabled via GBB */
ResetMocks();
sd->gbb_flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_USB;
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
vbtlk_retval = VBERROR_SUCCESS - VB_DISK_FLAG_REMOVABLE;
TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U force USB");
/* Ctrl+U enabled via FWMP */
ResetMocks();
VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_USB;
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
vbtlk_retval = VBERROR_SUCCESS - VB_DISK_FLAG_REMOVABLE;
TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U force USB");
/* If no USB, eventually times out and tries fixed disk */
ResetMocks();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+U enabled");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0,
@@ -603,8 +603,8 @@ static void VbBootDevTest(void)
/* If dev mode is disabled, goes to TONORM screen repeatedly */
ResetMocks();
VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT;
- mock_keypress[0] = '\x1b'; /* Just causes TONORM again */
- mock_keypress[1] = '\r';
+ mock_keypress[0] = VB_KEY_ESC; /* Just causes TONORM again */
+ mock_keypress[1] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED,
"FWMP dev disabled");
TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM,
@@ -763,7 +763,7 @@ static void VbBootRecTest(void)
ResetMocks();
shared->flags = VBSD_HONOR_VIRT_DEV_SWITCH | VBSD_BOOT_REC_SWITCH_ON;
shutdown_request_calls_left = 100;
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
trust_ec = 0;
TEST_EQ(VbBootRecovery(&ctx),
VBERROR_SHUTDOWN_REQUESTED,
@@ -777,7 +777,7 @@ static void VbBootRecTest(void)
VBSD_BOOT_DEV_SWITCH_ON;
trust_ec = 1;
shutdown_request_calls_left = 100;
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
TEST_EQ(VbBootRecovery(&ctx),
VBERROR_SHUTDOWN_REQUESTED,
"Ctrl+D ignored if already in dev mode");
@@ -789,7 +789,7 @@ static void VbBootRecTest(void)
shared->flags = VBSD_HONOR_VIRT_DEV_SWITCH;
trust_ec = 1;
shutdown_request_calls_left = 100;
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
TEST_EQ(VbBootRecovery(&ctx),
VBERROR_SHUTDOWN_REQUESTED,
"Ctrl+D ignored if recovery not manually triggered");
@@ -801,7 +801,7 @@ static void VbBootRecTest(void)
shared->flags = VBSD_BOOT_REC_SWITCH_ON;
trust_ec = 1;
shutdown_request_calls_left = 100;
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
TEST_EQ(VbBootRecovery(&ctx),
VBERROR_SHUTDOWN_REQUESTED,
"Ctrl+D ignored if no virtual dev switch");
@@ -816,7 +816,7 @@ static void VbBootRecTest(void)
shared->flags = VBSD_BOOT_REC_SWITCH_ON;
trust_ec = 1;
shutdown_request_calls_left = 100;
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
mock_switches[0] = VB_INIT_FLAG_REC_BUTTON_PRESSED;
TEST_EQ(VbBootRecovery(&ctx),
VBERROR_SHUTDOWN_REQUESTED,
@@ -830,7 +830,7 @@ static void VbBootRecTest(void)
shutdown_request_calls_left = 100;
vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
trust_ec = 1;
- mock_keypress[0] = 0x04;
+ mock_keypress[0] = VB_KEY_CTRL('D');
mock_keypress[1] = ' ';
TEST_EQ(VbBootRecovery(&ctx),
VBERROR_SHUTDOWN_REQUESTED,
@@ -849,8 +849,8 @@ static void VbBootRecTest(void)
shutdown_request_calls_left = 100;
vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
trust_ec = 1;
- mock_keypress[0] = 0x04;
- mock_keypress[1] = '\r';
+ mock_keypress[0] = VB_KEY_CTRL('D');
+ mock_keypress[1] = VB_KEY_ENTER;
mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
TEST_EQ(VbBootRecovery(&ctx), VBERROR_EC_REBOOT_TO_RO_REQUIRED,
"Ctrl+D todev confirm");
@@ -862,8 +862,8 @@ static void VbBootRecTest(void)
shutdown_request_calls_left = 100;
vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE;
trust_ec = 1;
- mock_keypress[0] = 0x04;
- mock_keypress[1] = '\r';
+ mock_keypress[0] = VB_KEY_CTRL('D');
+ mock_keypress[1] = VB_KEY_ENTER;
mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
virtdev_retval = VBERROR_SIMULATED;
TEST_EQ(VbBootRecovery(&ctx),
diff --git a/tests/vboot_detach_menu_tests.c b/tests/vboot_detach_menu_tests.c
index a9034b33..68a8a2c2 100644
--- a/tests/vboot_detach_menu_tests.c
+++ b/tests/vboot_detach_menu_tests.c
@@ -456,7 +456,7 @@ static void VbBootDevTest(void)
/* Pressing ENTER is equivalent to power button. */
ResetMocksForDeveloper();
- mock_keypress[0] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
"dev warning menu: ENTER is power button");
TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
@@ -469,7 +469,7 @@ static void VbBootDevTest(void)
/* ENTER functionality is unaffected by GBB flag in detachable UI. */
ResetMocksForDeveloper();
sd->gbb_flags |= GBB_FLAG_ENTER_TRIGGERS_TONORM;
- mock_keypress[0] = '\r';
+ mock_keypress[0] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SHUTDOWN_REQUESTED,
"dev warning menu: ENTER unaffected by GBB");
TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU,
@@ -568,7 +568,7 @@ static void VbBootDevTest(void)
/* Ctrl+D dismisses warning */
ResetMocksForDeveloper();
- mock_keypress[0] = 'D' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('D');
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+D");
TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0,
" recovery reason");
@@ -583,7 +583,7 @@ static void VbBootDevTest(void)
/* Ctrl+D doesn't boot legacy even if GBB flag is set */
ResetMocksForDeveloper();
- mock_keypress[0] = 'D' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('D');
sd->gbb_flags |= GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY;
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+D");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
@@ -605,7 +605,7 @@ static void VbBootDevTest(void)
/* Ctrl+L tries legacy boot mode only if enabled */
ResetMocksForDeveloper();
- mock_keypress[0] = 'L' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('L');
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+L normal");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery");
@@ -625,7 +625,7 @@ static void VbBootDevTest(void)
/* Ctrl+L boots legacy if enabled by GBB flag */
ResetMocksForDeveloper();
sd->gbb_flags |= GBB_FLAG_FORCE_DEV_BOOT_LEGACY;
- mock_keypress[0] = 'L' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
"Ctrl+L force legacy");
@@ -644,7 +644,7 @@ static void VbBootDevTest(void)
/* Ctrl+L boots legacy if enabled by NVRAM */
ResetMocksForDeveloper();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1);
- mock_keypress[0] = 'L' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
"Ctrl+L nv legacy");
@@ -663,7 +663,7 @@ static void VbBootDevTest(void)
/* Ctrl+L boots legacy if enabled by FWMP */
ResetMocksForDeveloper();
VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY;
- mock_keypress[0] = 'L' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('L');
mock_keypress[1] = VB_BUTTON_POWER_SHORT_PRESS;
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
"Ctrl+L fwmp legacy");
@@ -683,7 +683,7 @@ static void VbBootDevTest(void)
/* Ctrl+U boots USB only if enabled */
ResetMocksForDeveloper();
- mock_keypress[0] = 'U' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('U');
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
"Ctrl+U not enabled");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
@@ -704,7 +704,7 @@ static void VbBootDevTest(void)
/* Ctrl+U enabled, with good USB boot */
ResetMocksForDeveloper();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
- mock_keypress[0] = 'U' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('U');
vbtlk_retval[0] = VBERROR_SUCCESS - VB_DISK_FLAG_REMOVABLE;
TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SUCCESS, "Ctrl+U USB");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
@@ -720,7 +720,7 @@ static void VbBootDevTest(void)
/* Ctrl+U enabled, without valid USB */
ResetMocksForDeveloper();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
- mock_keypress[0] = 'U' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('U');
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
"Ctrl+U without valid USB");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
@@ -740,7 +740,7 @@ static void VbBootDevTest(void)
/* Ctrl+U enabled via GBB */
ResetMocksForDeveloper();
sd->gbb_flags |= GBB_FLAG_FORCE_DEV_BOOT_USB;
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
vbtlk_retval[0] = VBERROR_SUCCESS - VB_DISK_FLAG_REMOVABLE;
TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SUCCESS, "Ctrl+U force USB");
TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
@@ -753,7 +753,7 @@ static void VbBootDevTest(void)
/* Ctrl+U enabled via FWMP */
ResetMocksForDeveloper();
VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_USB;
- mock_keypress[0] = 0x15;
+ mock_keypress[0] = VB_KEY_CTRL('U');
vbtlk_retval[0] = VBERROR_SUCCESS - VB_DISK_FLAG_REMOVABLE;
TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_SUCCESS, "Ctrl+U force USB");
TEST_NEQ(audio_looping_calls_left, 0, " aborts audio");
@@ -766,7 +766,7 @@ static void VbBootDevTest(void)
/* If no valid USB, eventually times out and tries fixed disk */
ResetMocksForDeveloper();
vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1);
- mock_keypress[0] = 'U' & 0x1f;
+ mock_keypress[0] = VB_KEY_CTRL('U');
TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed,
"Ctrl+U failed - no USB");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
@@ -1148,13 +1148,13 @@ static void VbBootDevTest(void)
VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT;
audio_looping_calls_left = 1; /* Confirm audio doesn't tick down. */
i = 0;
- mock_keypress[i++] = 'D' & 0x1f; /* Just stays on TONORM and flashes */
- mock_keypress[i++] = 'U' & 0x1f; /* same */
- mock_keypress[i++] = 'L' & 0x1f; /* same */
+ mock_keypress[i++] = VB_KEY_CTRL('D'); /* Just stays on TONORM and flashes */
+ mock_keypress[i++] = VB_KEY_CTRL('U'); /* same */
+ mock_keypress[i++] = VB_KEY_CTRL('L'); /* same */
mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS; /* same */
mock_keypress[i++] = VB_BUTTON_VOL_DOWN_LONG_PRESS; /* same */
mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS; /* noop */
- mock_keypress[i++] = '\r';
+ mock_keypress[i++] = VB_KEY_ENTER;
TEST_EQ(VbBootDeveloperMenu(&ctx), VBERROR_REBOOT_REQUIRED,
"FWMP dev disabled");
TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 1,
@@ -1457,11 +1457,11 @@ static void VbBootRecTest(void)
ResetMocks();
i = 0;
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = 'D' & 0x1f;
+ mock_keypress[i++] = VB_KEY_CTRL('D');
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = 'U' & 0x1f;
+ mock_keypress[i++] = VB_KEY_CTRL('U');
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = 'L' & 0x1f;
+ mock_keypress[i++] = VB_KEY_CTRL('L');
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
mock_keypress[i++] = VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS;
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
@@ -1485,11 +1485,11 @@ static void VbBootRecTest(void)
ResetMocksForManualRecovery();
i = 0;
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = 'D' & 0x1f;
+ mock_keypress[i++] = VB_KEY_CTRL('D');
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = 'U' & 0x1f;
+ mock_keypress[i++] = VB_KEY_CTRL('U');
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
- mock_keypress[i++] = 'L' & 0x1f;
+ mock_keypress[i++] = VB_KEY_CTRL('L');
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;
mock_keypress[i++] = VB_BUTTON_VOL_UP_LONG_PRESS;
mock_keypress[i] = VB_KEY_FLAG_TRUSTED_KEYBOARD;