Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2025 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include <stdarg.h>
8 : #include <stddef.h>
9 : #include <setjmp.h>
10 : #include <stdint.h>
11 : #include <stdlib.h>
12 : #include <stdio.h>
13 : #include <assert.h>
14 : #include <string.h>
15 :
16 : #include <base.h>
17 : #include "library/memlib.h"
18 : #include "spdm_device_secret_lib_internal.h"
19 : #include "internal/libspdm_common_lib.h"
20 :
21 : #ifdef LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
22 :
23 75 : libspdm_return_t libspdm_generate_device_endpoint_info(
24 : void *spdm_context,
25 : uint8_t sub_code,
26 : uint8_t request_attributes,
27 : uint32_t *endpoint_info_size,
28 : void *endpoint_info)
29 : {
30 : uint8_t *ptr;
31 : spdm_endpoint_info_device_class_identifier_t *device_class_identifier;
32 : spdm_endpoint_info_device_class_identifier_element_t *identifier;
33 : uint8_t *num_sub_ids;
34 : spdm_endpoint_info_device_class_identifier_subordinate_id_t *subordinate_id;
35 : uint8_t *sub_identifier;
36 : uint32_t ep_info_size;
37 :
38 75 : LIBSPDM_ASSERT(endpoint_info_size != NULL);
39 75 : LIBSPDM_ASSERT(endpoint_info != NULL);
40 :
41 75 : switch (sub_code) {
42 75 : case SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER:
43 75 : ep_info_size = sizeof(spdm_endpoint_info_device_class_identifier_t) +
44 : sizeof(spdm_endpoint_info_device_class_identifier_element_t) +
45 : sizeof(uint8_t) +
46 : sizeof(spdm_endpoint_info_device_class_identifier_subordinate_id_t) +
47 : 3;
48 :
49 75 : if (*endpoint_info_size < ep_info_size) {
50 10 : *endpoint_info_size = ep_info_size;
51 10 : return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
52 : }
53 65 : *endpoint_info_size = ep_info_size;
54 :
55 65 : ptr = (uint8_t *)endpoint_info;
56 65 : device_class_identifier = (spdm_endpoint_info_device_class_identifier_t *) ptr;
57 65 : device_class_identifier->num_identifiers = 1;
58 :
59 65 : ptr += sizeof(spdm_endpoint_info_device_class_identifier_t);
60 65 : identifier = (spdm_endpoint_info_device_class_identifier_element_t *) ptr;
61 65 : identifier->id_elem_length =
62 : sizeof(spdm_svh_header_t) + sizeof(uint8_t) +
63 : sizeof(spdm_endpoint_info_device_class_identifier_subordinate_id_t) + 3;
64 :
65 65 : identifier->svh.id = 0x0;
66 65 : identifier->svh.vendor_id_len = 0x0;
67 : /* DMTF does not have a Vendor ID registry*/
68 65 : ptr += sizeof(spdm_endpoint_info_device_class_identifier_element_t);
69 :
70 : /* a fake sub id for structure sample*/
71 65 : num_sub_ids = (uint8_t *) ptr;
72 65 : *num_sub_ids = 1;
73 :
74 65 : ptr += sizeof(uint8_t);
75 65 : subordinate_id = (spdm_endpoint_info_device_class_identifier_subordinate_id_t *) ptr;
76 65 : subordinate_id->sub_id_len = 0x3;
77 :
78 65 : ptr += sizeof(spdm_endpoint_info_device_class_identifier_subordinate_id_t);
79 65 : sub_identifier = (uint8_t *) ptr;
80 65 : sub_identifier[0] = 0x12;
81 65 : sub_identifier[1] = 0x34;
82 65 : sub_identifier[2] = 0x56;
83 :
84 65 : break;
85 0 : default:
86 0 : return LIBSPDM_STATUS_UNSUPPORTED_CAP;
87 : }
88 65 : return LIBSPDM_STATUS_SUCCESS;
89 : }
90 :
91 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
|