|
9 | 9 |
|
10 | 10 | libspdm_get_spdm_response_func libspdm_get_response_func_via_request_code(uint8_t request_code) |
11 | 11 | { |
12 | | - size_t index; |
13 | | - |
14 | | - typedef struct { |
15 | | - uint8_t request_response_code; |
16 | | - libspdm_get_spdm_response_func get_response_func; |
17 | | - } libspdm_get_response_struct_t; |
18 | | - |
19 | | - libspdm_get_response_struct_t get_response_struct[] = { |
20 | | - { SPDM_GET_VERSION, libspdm_get_response_version }, |
21 | | - { SPDM_GET_CAPABILITIES, libspdm_get_response_capabilities }, |
22 | | - { SPDM_NEGOTIATE_ALGORITHMS, libspdm_get_response_algorithms }, |
23 | | - |
24 | | - #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP |
25 | | - { SPDM_GET_DIGESTS, libspdm_get_response_digests }, |
26 | | - { SPDM_GET_CERTIFICATE, libspdm_get_response_certificate }, |
27 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */ |
28 | | - |
29 | | - #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP |
30 | | - { SPDM_CHALLENGE, libspdm_get_response_challenge_auth }, |
31 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/ |
32 | | - |
33 | | - #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP |
34 | | - { SPDM_GET_MEASUREMENTS, libspdm_get_response_measurements }, |
35 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/ |
36 | | - |
37 | | - #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP |
38 | | - { SPDM_GET_MEASUREMENT_EXTENSION_LOG, libspdm_get_response_measurement_extension_log }, |
39 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */ |
40 | | - |
41 | | - #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP |
42 | | - { SPDM_KEY_EXCHANGE, libspdm_get_response_key_exchange }, |
43 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/ |
44 | | - |
45 | | - #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP |
46 | | - { SPDM_PSK_EXCHANGE, libspdm_get_response_psk_exchange }, |
47 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/ |
48 | | - |
49 | | - #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP |
50 | | - { SPDM_GET_ENCAPSULATED_REQUEST, libspdm_get_response_encapsulated_request }, |
51 | | - { SPDM_DELIVER_ENCAPSULATED_RESPONSE, libspdm_get_response_encapsulated_response_ack }, |
52 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */ |
53 | | - |
54 | | - #if LIBSPDM_RESPOND_IF_READY_SUPPORT |
55 | | - { SPDM_RESPOND_IF_READY, libspdm_get_response_respond_if_ready }, |
56 | | - #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */ |
57 | | - |
58 | | - #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP |
59 | | - { SPDM_FINISH, libspdm_get_response_finish }, |
60 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/ |
61 | | - |
62 | | - #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP |
63 | | - { SPDM_PSK_FINISH, libspdm_get_response_psk_finish }, |
64 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/ |
65 | | - |
66 | | - #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) |
67 | | - { SPDM_END_SESSION, libspdm_get_response_end_session }, |
68 | | - { SPDM_HEARTBEAT, libspdm_get_response_heartbeat }, |
69 | | - { SPDM_KEY_UPDATE, libspdm_get_response_key_update }, |
70 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/ |
71 | | - |
72 | | - #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP |
73 | | - { SPDM_GET_ENDPOINT_INFO, libspdm_get_response_endpoint_info }, |
74 | | - #endif /*LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP*/ |
75 | | - |
76 | | - #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP |
77 | | - { SPDM_GET_CSR, libspdm_get_response_csr }, |
78 | | - #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/ |
79 | | - |
80 | | - #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP |
81 | | - { SPDM_SET_CERTIFICATE, libspdm_get_response_set_certificate }, |
82 | | - #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/ |
83 | | - |
84 | | - #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP |
85 | | - { SPDM_GET_KEY_PAIR_INFO, libspdm_get_response_key_pair_info }, |
86 | | - #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/ |
87 | | - |
88 | | - #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP |
89 | | - { SPDM_SET_KEY_PAIR_INFO, libspdm_get_response_set_key_pair_info_ack }, |
90 | | - #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/ |
| 12 | + switch (request_code) { |
| 13 | + case SPDM_GET_VERSION: return libspdm_get_response_version; |
| 14 | + case SPDM_GET_CAPABILITIES: return libspdm_get_response_capabilities; |
| 15 | + case SPDM_NEGOTIATE_ALGORITHMS: return libspdm_get_response_algorithms; |
| 16 | + |
| 17 | + #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP |
| 18 | + case SPDM_GET_DIGESTS: return libspdm_get_response_digests; |
| 19 | + case SPDM_GET_CERTIFICATE: return libspdm_get_response_certificate; |
| 20 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */ |
| 21 | + |
| 22 | + #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP |
| 23 | + case SPDM_CHALLENGE: return libspdm_get_response_challenge_auth; |
| 24 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/ |
| 25 | + |
| 26 | + #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP |
| 27 | + case SPDM_GET_MEASUREMENTS: return libspdm_get_response_measurements; |
| 28 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/ |
| 29 | + |
| 30 | + #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP |
| 31 | + case SPDM_GET_MEASUREMENT_EXTENSION_LOG: return libspdm_get_response_measurement_extension_log; |
| 32 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */ |
| 33 | + |
| 34 | + #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP |
| 35 | + case SPDM_KEY_EXCHANGE: return libspdm_get_response_key_exchange; |
| 36 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/ |
| 37 | + |
| 38 | + #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP |
| 39 | + case SPDM_PSK_EXCHANGE: return libspdm_get_response_psk_exchange; |
| 40 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/ |
| 41 | + |
| 42 | + #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP |
| 43 | + case SPDM_GET_ENCAPSULATED_REQUEST: return libspdm_get_response_encapsulated_request; |
| 44 | + case SPDM_DELIVER_ENCAPSULATED_RESPONSE: return libspdm_get_response_encapsulated_response_ack; |
| 45 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */ |
| 46 | + |
| 47 | + #if LIBSPDM_RESPOND_IF_READY_SUPPORT |
| 48 | + case SPDM_RESPOND_IF_READY: return libspdm_get_response_respond_if_ready; |
| 49 | + #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */ |
| 50 | + |
| 51 | + #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP |
| 52 | + case SPDM_FINISH: return libspdm_get_response_finish; |
| 53 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/ |
| 54 | + |
| 55 | + #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP |
| 56 | + case SPDM_PSK_FINISH: return libspdm_get_response_psk_finish; |
| 57 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/ |
| 58 | + |
| 59 | + #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) |
| 60 | + case SPDM_END_SESSION: return libspdm_get_response_end_session; |
| 61 | + case SPDM_HEARTBEAT: return libspdm_get_response_heartbeat; |
| 62 | + case SPDM_KEY_UPDATE: return libspdm_get_response_key_update; |
| 63 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/ |
| 64 | + |
| 65 | + #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP |
| 66 | + case SPDM_GET_ENDPOINT_INFO: return libspdm_get_response_endpoint_info; |
| 67 | + #endif /*LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP*/ |
| 68 | + |
| 69 | + #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP |
| 70 | + case SPDM_GET_CSR: return libspdm_get_response_csr; |
| 71 | + #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/ |
| 72 | + |
| 73 | + #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP |
| 74 | + case SPDM_SET_CERTIFICATE: return libspdm_get_response_set_certificate; |
| 75 | + #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP*/ |
| 76 | + |
| 77 | + #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP |
| 78 | + case SPDM_GET_KEY_PAIR_INFO: return libspdm_get_response_key_pair_info; |
| 79 | + #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/ |
| 80 | + |
| 81 | + #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP |
| 82 | + case SPDM_SET_KEY_PAIR_INFO: return libspdm_get_response_set_key_pair_info_ack; |
| 83 | + #endif /*LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/ |
91 | 84 |
|
92 | | - #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP |
93 | | - { SPDM_CHUNK_GET, libspdm_get_response_chunk_get}, |
94 | | - { SPDM_CHUNK_SEND, libspdm_get_response_chunk_send}, |
95 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */ |
| 85 | + #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP |
| 86 | + case SPDM_CHUNK_GET: return libspdm_get_response_chunk_get; |
| 87 | + case SPDM_CHUNK_SEND: return libspdm_get_response_chunk_send; |
| 88 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */ |
96 | 89 |
|
97 | | - #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP |
98 | | - { SPDM_GET_SUPPORTED_EVENT_TYPES, libspdm_get_response_supported_event_types }, |
99 | | - { SPDM_SUBSCRIBE_EVENT_TYPES, libspdm_get_response_subscribe_event_types_ack }, |
100 | | - #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */ |
| 90 | + #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP |
| 91 | + case SPDM_GET_SUPPORTED_EVENT_TYPES: return libspdm_get_response_supported_event_types; |
| 92 | + case SPDM_SUBSCRIBE_EVENT_TYPES: return libspdm_get_response_subscribe_event_types_ack; |
| 93 | + #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */ |
101 | 94 |
|
102 | | - #if LIBSPDM_EVENT_RECIPIENT_SUPPORT |
103 | | - { SPDM_SEND_EVENT, libspdm_get_response_event_ack }, |
104 | | - #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */ |
| 95 | + #if LIBSPDM_EVENT_RECIPIENT_SUPPORT |
| 96 | + case SPDM_SEND_EVENT: return libspdm_get_response_event_ack; |
| 97 | + #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */ |
105 | 98 |
|
106 | | - #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES |
107 | | - { SPDM_VENDOR_DEFINED_REQUEST, libspdm_get_vendor_defined_response }, |
108 | | - #endif /*LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES*/ |
109 | | - }; |
| 99 | + #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES |
| 100 | + case SPDM_VENDOR_DEFINED_REQUEST: return libspdm_get_vendor_defined_response; |
| 101 | + #endif /*LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES*/ |
110 | 102 |
|
111 | | - for (index = 0; index < LIBSPDM_ARRAY_SIZE(get_response_struct); index++) { |
112 | | - if (request_code == get_response_struct[index].request_response_code) { |
113 | | - return get_response_struct[index].get_response_func; |
114 | | - } |
| 103 | + default: return NULL; |
115 | 104 | } |
116 | | - return NULL; |
117 | 105 | } |
118 | 106 |
|
119 | 107 | /** |
|
0 commit comments