Software APIs
firmware_fi.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 #include <stdbool.h>
5 
6 #include "sw/device/lib/base/status.h"
7 #include "sw/device/lib/crypto/drivers/entropy.h"
8 #include "sw/device/lib/testing/test_framework/check.h"
10 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
11 #include "sw/device/lib/ujson/ujson.h"
12 
13 // Include commands
14 #include "sw/device/tests/penetrationtests/json/commands.h"
15 #include "sw/device/tests/penetrationtests/json/crypto_fi_commands.h"
16 #include "sw/device/tests/penetrationtests/json/ibex_fi_commands.h"
17 #include "sw/device/tests/penetrationtests/json/lc_ctrl_fi_commands.h"
18 #include "sw/device/tests/penetrationtests/json/otp_fi_commands.h"
19 #include "sw/device/tests/penetrationtests/json/pentest_lib_commands.h"
20 #include "sw/device/tests/penetrationtests/json/rng_fi_commands.h"
21 #include "sw/device/tests/penetrationtests/json/rom_fi_commands.h"
22 
23 // Include handlers
24 #include "fi/crypto_fi.h"
25 #include "fi/ibex_fi.h"
26 #include "fi/lc_ctrl_fi.h"
27 #include "fi/otp_fi.h"
28 #include "fi/rng_fi.h"
29 #include "fi/rom_fi.h"
30 #include "lib/extclk_sca_fi.h"
31 #include "lib/pentest_lib.h"
32 
33 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
34 
35 status_t process_cmd(ujson_t *uj) {
36  while (true) {
37  penetrationtest_cmd_t cmd;
38  TRY(ujson_deserialize_penetrationtest_cmd_t(uj, &cmd));
39  switch (cmd) {
40  case kPenetrationtestCommandAlertInfo:
41  RESP_ERR(uj, pentest_read_rstmgr_alert_info(uj));
42  break;
43  case kPenetrationtestCommandCryptoFi:
44  RESP_ERR(uj, handle_crypto_fi(uj));
45  break;
46  case kPenetrationtestCommandExtClkScaFi:
47  RESP_ERR(uj, handle_extclk_sca_fi(uj));
48  break;
49  case kPenetrationtestCommandIbexFi:
50  RESP_ERR(uj, handle_ibex_fi(uj));
51  break;
52  case kPenetrationtestCommandLCCtrlFi:
53  RESP_ERR(uj, handle_lc_ctrl_fi(uj));
54  break;
55  case kPenetrationtestCommandOtpFi:
56  RESP_ERR(uj, handle_otp_fi(uj));
57  break;
58  case kPenetrationtestCommandRngFi:
59  RESP_ERR(uj, handle_rng_fi(uj));
60  break;
61  case kPenetrationtestCommandRomFi:
62  RESP_ERR(uj, handle_rom_fi(uj));
63  break;
64  default:
65  LOG_ERROR("Unrecognized command: %d", cmd);
66  RESP_ERR(uj, INVALID_ARGUMENT());
67  }
68  }
69 
70  return OK_STATUS();
71 }
72 
73 bool test_main(void) {
74  CHECK_STATUS_OK(entropy_complex_init());
75  ujson_t uj = ujson_ottf_console();
76  return status_ok(process_cmd(&uj));
77 }