mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-16 18:11:22 +00:00
This makes it easier to add params or flags for vendor commands without changing all of the command handlers. It also reduces code size by 56 bytes. For now, existing command handlers continue to use DECLARE_VENDOR_COMMAND(). Added DECLARE_VENDOR_COMMAND_P() for handlers which take the params struct directly. The CCD command will be the first user of that, since it will have different rules for 'open' based on where the command comes from. No change to existing command behavior. BUG=b:79983505 BRANCH=cr50 TEST=gsctool -I still works Change-Id: I7ed288a9c45e381162e246b50ae88cf76e67490d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1069538 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "byteorder.h"
|
|
#include "console.h"
|
|
#include "extension.h"
|
|
#include "link_defs.h"
|
|
#include "util.h"
|
|
|
|
#define CPRINTS(format, args...) cprints(CC_EXTENSION, format, ## args)
|
|
|
|
uint32_t extension_route_command(struct vendor_cmd_params *p)
|
|
{
|
|
struct extension_command *cmd_p;
|
|
struct extension_command *end_p;
|
|
const char *why_ignore = "not found";
|
|
|
|
#ifdef DEBUG_EXTENSION
|
|
CPRINTS("%s(%d,%s)", __func__, command_code,
|
|
flags & VENDOR_CMD_FROM_USB ? "USB" : "AP");
|
|
#endif
|
|
|
|
/* Filter commands from USB */
|
|
if (p->flags & VENDOR_CMD_FROM_USB) {
|
|
switch (p->code) {
|
|
#ifdef CR50_DEV
|
|
case VENDOR_CC_IMMEDIATE_RESET:
|
|
case VENDOR_CC_INVALIDATE_INACTIVE_RW:
|
|
case VENDOR_CC_SET_BOARD_ID:
|
|
#endif /* defined(CR50_DEV) */
|
|
case EXTENSION_POST_RESET: /* Always need to reset. */
|
|
case VENDOR_CC_CCD:
|
|
case VENDOR_CC_GET_BOARD_ID:
|
|
case VENDOR_CC_RMA_CHALLENGE_RESPONSE:
|
|
case VENDOR_CC_SPI_HASH: /* Requires physical presence. */
|
|
case VENDOR_CC_TURN_UPDATE_ON:
|
|
break;
|
|
default:
|
|
/* Otherwise, we don't allow this command. */
|
|
why_ignore = "usb";
|
|
goto ignore_cmd;
|
|
}
|
|
}
|
|
|
|
#ifdef CONFIG_BOARD_ID_SUPPORT
|
|
/*
|
|
* If board ID is mismatched, allow only the commands needed to upgrade
|
|
* Cr50 firmware.
|
|
*/
|
|
if (board_id_is_mismatched()) {
|
|
switch (p->code) {
|
|
case EXTENSION_FW_UPGRADE:
|
|
case VENDOR_CC_REPORT_TPM_STATE:
|
|
case VENDOR_CC_TURN_UPDATE_ON:
|
|
case EXTENSION_POST_RESET:
|
|
break;
|
|
default:
|
|
why_ignore = "BoardID mismatch";
|
|
goto ignore_cmd;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* Find the command handler */
|
|
cmd_p = (struct extension_command *)&__extension_cmds;
|
|
end_p = (struct extension_command *)&__extension_cmds_end;
|
|
while (cmd_p != end_p) {
|
|
if (cmd_p->command_code == p->code)
|
|
return cmd_p->handler(p);
|
|
cmd_p++;
|
|
}
|
|
|
|
ignore_cmd:
|
|
/* Command not found or not allowed */
|
|
CPRINTS("%s: ignore %d: %s", __func__, p->code, why_ignore);
|
|
p->out_size = 0;
|
|
return VENDOR_RC_NO_SUCH_COMMAND;
|
|
}
|