@@ -196,6 +196,96 @@ static struct pldm_cmd pldm_base_get_types = {
.handler = base_get_types_handler,
};
+/*
+ * Extended error codes defined for the Base command set.
+ */
+#define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83
+#define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84
+
+/*
+ * GetPLDMCommands (0x05)
+ * The GetPLDMCommands command can be used to discover the PLDM command
+ * capabilities supported by aPLDM terminus for a specific PLDM Type and
+ * version as a responder.
+ */
+static int base_get_commands_handler(const struct pldm_rx_data *req)
+{
+ char response_msg[PKT_SIZE(struct pldm_get_commands_resp)];
+ bitmap_elem_t cmd_map[BITMAP_ELEMS(256)];
+ const struct pldm_type *type;
+ const struct pldm_cmd *iter;
+ size_t payload_len;
+ ver32_t version;
+ uint8_t type_id;
+ int rc;
+
+ payload_len = req->msg_len - sizeof(struct pldm_msg_hdr);
+ rc = decode_get_commands_req(req->msg, payload_len,
+ &type_id, &version);
+ if (rc) {
+ prlog(PR_ERR, "Failed to decode GetPLDMCommands request, rc = %d", rc);
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command, PLDM_ERROR);
+ return OPAL_INTERNAL_ERROR;
+ }
+
+ type = find_type(type_id);
+ if (!type) {
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command,
+ INVALID_PLDM_TYPE_IN_REQUEST_DATA);
+ return OPAL_PARAMETER;
+ }
+
+ if (memcmp(&type->version, &version, sizeof(version))) {
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command,
+ INVALID_PLDM_VERSION_IN_REQUEST_DATA);
+ return OPAL_PARAMETER;
+ }
+
+ /*
+ * build the supported type list from the registered type
+ * handlers
+ */
+ memset(cmd_map, 0, sizeof(cmd_map));
+ list_for_each(&type->commands, iter, link)
+ bitmap_set_bit(cmd_map, iter->pldm_cmd_id);
+
+ /* fix the endian */
+ for (int i = 0; i < BITMAP_ELEMS(256); i++)
+ cmd_map[i] = cpu_to_le64(cmd_map[i]);
+
+ memset(response_msg, 0, sizeof(response_msg));
+
+ /* create a PLDM response message for GetPLDMCommands */
+ rc = encode_get_commands_resp(req->hdrinf.instance,
+ PLDM_SUCCESS,
+ (bitfield8_t *)cmd_map,
+ (struct pldm_msg *)response_msg);
+ if (rc != PLDM_SUCCESS) {
+ prlog(PR_ERR, "Encode GetPLDMCommands Error, rc: %d\n", rc);
+ pldm_cc_resp(req, req->hdrinf.pldm_type,
+ req->hdrinf.command, PLDM_ERROR);
+ return OPAL_PARAMETER;
+ }
+
+ /* send PLDM message over MCTP */
+ rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg));
+ if (rc) {
+ prlog(PR_ERR, "Failed to send GetPLDMCommands response, rc = %d\n", rc);
+ return OPAL_HARDWARE;
+ }
+
+ return OPAL_SUCCESS;
+}
+
+static struct pldm_cmd pldm_base_get_commands = {
+ .name = "PLDM_GET_PLDM_COMMANDS",
+ .pldm_cmd_id = PLDM_GET_PLDM_COMMANDS,
+ .handler = base_get_commands_handler,
+};
+
int pldm_rx_handle_request(struct pldm_rx_data *rx)
{
const struct pldm_type *t;
@@ -233,6 +323,7 @@ int pldm_mctp_responder_init(void)
pldm_add_type(&pldm_base_type);
pldm_add_cmd(&pldm_base_type, &pldm_base_get_tid);
pldm_add_cmd(&pldm_base_type, &pldm_base_get_types);
+ pldm_add_cmd(&pldm_base_type, &pldm_base_get_commands);
return OPAL_SUCCESS;
}