LCOV - code coverage report
Current view: top level - library/spdm_requester_lib - libspdm_req_handle_error_response.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.1 % 223 172
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-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 "internal/libspdm_requester_lib.h"
       8              : 
       9              : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
      10              : /**
      11              :  * This function sends RESPOND_IF_READY and receives an expected SPDM response.
      12              :  *
      13              :  * @param  spdm_context            A pointer to the SPDM context.
      14              :  * @param  response_size           The size of the response.
      15              :  *                                 On input, it means the size in bytes of response data buffer.
      16              :  *                                 On output, it means the size in bytes of copied response data
      17              :  *                                 buffer if LIBSPDM_STATUS_SUCCESS is returned.
      18              :  * @param  response                The SPDM response message.
      19              :  * @param  expected_response_code  Indicate the expected response code.
      20              :  **/
      21           29 : static libspdm_return_t libspdm_requester_respond_if_ready(libspdm_context_t *spdm_context,
      22              :                                                            const uint32_t *session_id,
      23              :                                                            size_t *response_size,
      24              :                                                            void **response,
      25              :                                                            uint8_t expected_response_code)
      26              : {
      27              :     libspdm_return_t status;
      28              :     spdm_response_if_ready_request_t *spdm_request;
      29              :     size_t spdm_request_size;
      30              :     spdm_message_header_t *spdm_response;
      31              :     uint8_t *message;
      32              :     size_t message_size;
      33              :     size_t transport_header_size;
      34              : 
      35              :     /* the response might be in response buffer in normal SPDM message
      36              :      * or it is in scratch buffer in case of secure SPDM message
      37              :      * the response buffer is in acquired state, so we release it*/
      38           29 :     libspdm_release_receiver_buffer (spdm_context);
      39              : 
      40              :     /* now we can get sender buffer */
      41           29 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
      42           29 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
      43           29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
      44            0 :         return status;
      45              :     }
      46           29 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
      47              :                     spdm_context->local_context.capability.transport_tail_size);
      48           29 :     spdm_request = (void *)(message + transport_header_size);
      49           29 :     spdm_request_size = message_size - transport_header_size -
      50           29 :                         spdm_context->local_context.capability.transport_tail_size;
      51              : 
      52           29 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_response_if_ready_request_t));
      53           29 :     spdm_context->crypto_request = true;
      54           29 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
      55           29 :     spdm_request->header.request_response_code = SPDM_RESPOND_IF_READY;
      56           29 :     spdm_request->header.param1 = spdm_context->error_data.request_code;
      57           29 :     spdm_request->header.param2 = spdm_context->error_data.token;
      58           29 :     spdm_request_size = sizeof(spdm_response_if_ready_request_t);
      59           29 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
      60           29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
      61            0 :         libspdm_release_sender_buffer (spdm_context);
      62              :         /* need acquire response buffer, so that the caller can release it */
      63            0 :         status = libspdm_acquire_receiver_buffer (spdm_context, response_size, response);
      64            0 :         return status;
      65              :     }
      66           29 :     libspdm_release_sender_buffer (spdm_context);
      67           29 :     spdm_request = (void *)spdm_context->last_spdm_request;
      68              : 
      69              :     /* receive
      70              :      * do not release response buffer in case of error, because caller will release it*/
      71              : 
      72           29 :     status = libspdm_acquire_receiver_buffer (spdm_context, response_size, response);
      73           29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
      74            0 :         return status;
      75              :     }
      76           29 :     LIBSPDM_ASSERT (*response_size >= transport_header_size);
      77              : 
      78           29 :     status = libspdm_receive_spdm_response(spdm_context, session_id,
      79              :                                            response_size, response);
      80           29 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
      81            0 :         return status;
      82              :     }
      83           29 :     spdm_response = (void *)(*response);
      84           29 :     if (*response_size < sizeof(spdm_message_header_t)) {
      85            0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
      86              :     }
      87           29 :     if (spdm_response->spdm_version != spdm_request->header.spdm_version) {
      88            0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
      89              :     }
      90           29 :     if (spdm_response->request_response_code == SPDM_ERROR) {
      91           16 :         status = libspdm_handle_simple_error_response(spdm_context, spdm_response->param1);
      92           16 :         return status;
      93              :     }
      94           13 :     if (spdm_response->request_response_code != expected_response_code) {
      95            0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
      96              :     }
      97              : 
      98           13 :     return LIBSPDM_STATUS_SUCCESS;
      99              : }
     100              : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
     101              : 
     102          428 : libspdm_return_t libspdm_handle_simple_error_response(libspdm_context_t *spdm_context,
     103              :                                                       uint8_t error_code)
     104              : {
     105              :     spdm_set_certificate_request_t *last_spdm_request;
     106              : 
     107          428 :     if (error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
     108           18 :         return LIBSPDM_STATUS_NOT_READY_PEER;
     109              :     }
     110              : 
     111          410 :     if (error_code == SPDM_ERROR_CODE_BUSY) {
     112           44 :         return LIBSPDM_STATUS_BUSY_PEER;
     113              :     }
     114              : 
     115          366 :     last_spdm_request = (void *)spdm_context->last_spdm_request;
     116          366 :     if ((last_spdm_request->header.request_response_code == SPDM_SET_CERTIFICATE) ||
     117          365 :         (last_spdm_request->header.request_response_code == SPDM_GET_CSR)) {
     118              : 
     119            4 :         if (error_code == SPDM_ERROR_CODE_RESET_REQUIRED) {
     120            4 :             if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) &&
     121            2 :                 !libspdm_is_capabilities_flag_supported(
     122              :                     spdm_context, true, 0,
     123              :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP)) {
     124            1 :                 return LIBSPDM_STATUS_ERROR_PEER;
     125              :             }
     126              :             /* CERT_INSTALL_RESET_CAP for a 1.2 Responder is not checked because it was not defined
     127              :              * in SPDM 1.2.0. */
     128            3 :             return LIBSPDM_STATUS_RESET_REQUIRED_PEER;
     129              :         }
     130              :     }
     131              : 
     132          362 :     if (last_spdm_request->header.request_response_code == SPDM_SET_KEY_PAIR_INFO) {
     133            1 :         if (error_code == SPDM_ERROR_CODE_RESET_REQUIRED) {
     134            1 :             if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_14) &&
     135            1 :                 !libspdm_is_capabilities_flag_supported(
     136              :                     spdm_context, true, 0,
     137              :                     SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_RESET_CAP)) {
     138            0 :                 return LIBSPDM_STATUS_ERROR_PEER;
     139              :             }
     140            1 :             return LIBSPDM_STATUS_RESET_REQUIRED_PEER;
     141              :         }
     142              :     }
     143              : 
     144          361 :     if (error_code == SPDM_ERROR_CODE_REQUEST_RESYNCH) {
     145           23 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
     146           23 :         return LIBSPDM_STATUS_RESYNCH_PEER;
     147              :     }
     148              : 
     149          338 :     return LIBSPDM_STATUS_ERROR_PEER;
     150              : }
     151              : 
     152              : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
     153              : /**
     154              :  * This function handles RESPONSE_NOT_READY error code.
     155              :  *
     156              :  * @param  spdm_context            A pointer to the SPDM context.
     157              :  * @param  response_size           The size of the response.
     158              :  *                                 On input, it means the size in bytes of response data buffer.
     159              :  *                                 On output, it means the size in bytes of copied response data
     160              :  *                                 buffer if LIBSPDM_STATUS_SUCCESS is returned.
     161              :  * @param  response                The SPDM response message.
     162              :  * @param  original_request_code   Indicate the original request code.
     163              :  * @param  expected_response_code  Indicate the expected response code.
     164              :  **/
     165           29 : static libspdm_return_t libspdm_handle_response_not_ready(libspdm_context_t *spdm_context,
     166              :                                                           const uint32_t *session_id,
     167              :                                                           size_t *response_size,
     168              :                                                           void **response,
     169              :                                                           uint8_t original_request_code,
     170              :                                                           uint8_t expected_response_code)
     171              : {
     172              :     spdm_error_response_t *spdm_response;
     173              :     spdm_error_data_response_not_ready_t *extend_error_data;
     174              : 
     175           29 :     if (*response_size < sizeof(spdm_error_response_t) +
     176              :         sizeof(spdm_error_data_response_not_ready_t)) {
     177            0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
     178              :     }
     179              : 
     180           29 :     spdm_response = *response;
     181           29 :     extend_error_data = (spdm_error_data_response_not_ready_t *)(spdm_response + 1);
     182           29 :     LIBSPDM_ASSERT(spdm_response->header.request_response_code == SPDM_ERROR);
     183           29 :     LIBSPDM_ASSERT(spdm_response->header.param1 == SPDM_ERROR_CODE_RESPONSE_NOT_READY);
     184              : 
     185           29 :     if (extend_error_data->request_code != original_request_code) {
     186            0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
     187              :     }
     188           29 :     if (extend_error_data->rd_tm <= 1) {
     189            0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
     190              :     }
     191           29 :     if (extend_error_data->rd_exponent > LIBSPDM_MAX_RDT_EXPONENT) {
     192            0 :         return LIBSPDM_STATUS_INVALID_MSG_FIELD;
     193              :     }
     194              : 
     195           29 :     spdm_context->error_data.rd_exponent = extend_error_data->rd_exponent;
     196           29 :     spdm_context->error_data.request_code = extend_error_data->request_code;
     197           29 :     spdm_context->error_data.token = extend_error_data->token;
     198           29 :     spdm_context->error_data.rd_tm = extend_error_data->rd_tm;
     199              : 
     200           29 :     libspdm_sleep((uint64_t)1 << extend_error_data->rd_exponent);
     201              : 
     202           29 :     return libspdm_requester_respond_if_ready(spdm_context, session_id,
     203              :                                               response_size, response,
     204              :                                               expected_response_code);
     205              : }
     206              : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
     207              : 
     208              : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
     209            8 : libspdm_return_t libspdm_handle_error_large_response(
     210              :     libspdm_context_t *spdm_context,
     211              :     const uint32_t *session_id,
     212              :     size_t *inout_response_size,
     213              :     void *inout_response,
     214              :     size_t response_capacity)
     215              : {
     216              :     libspdm_return_t status;
     217              :     uint8_t chunk_handle;
     218              :     spdm_error_response_t* error_response;
     219              :     spdm_error_data_large_response_t* extend_error_data;
     220              : 
     221              :     spdm_chunk_get_request_t* spdm_request;
     222              :     spdm_chunk_get_request_14_t* spdm_request_14;
     223              :     size_t spdm_request_size;
     224              :     spdm_chunk_response_response_t* spdm_response;
     225              :     spdm_chunk_response_response_14_t* spdm_response_14;
     226              :     uint8_t* message;
     227              :     size_t message_size;
     228              :     size_t transport_header_size;
     229              : 
     230              :     uint8_t* scratch_buffer;
     231              :     size_t scratch_buffer_size;
     232              :     uint32_t chunk_seq_no;
     233              :     uint8_t* chunk_ptr;
     234              :     uint8_t* large_response;
     235              :     size_t large_response_capacity;
     236              :     size_t large_response_size;
     237              :     size_t large_response_size_so_far;
     238              :     uint64_t max_chunk_data_transfer_size;
     239              : 
     240            8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
     241            0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
     242              :     }
     243              : 
     244              :     /* Fail if requester or responder does not support chunk cap */
     245            8 :     if (!libspdm_is_capabilities_flag_supported(
     246              :             spdm_context, true,
     247              :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
     248              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
     249            0 :         return LIBSPDM_STATUS_ERROR_PEER;
     250              :     }
     251              : 
     252            8 :     if (*inout_response_size < sizeof(spdm_error_response_t) +
     253              :         sizeof(spdm_error_data_large_response_t)) {
     254            0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
     255              :     }
     256              : 
     257            8 :     error_response = inout_response;
     258            8 :     extend_error_data =
     259              :         (spdm_error_data_large_response_t*)(error_response + 1);
     260            8 :     chunk_handle = extend_error_data->handle;
     261              : 
     262              :     /* now we can get sender buffer */
     263            8 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     264              : 
     265            8 :     libspdm_get_scratch_buffer(spdm_context, (void**)&scratch_buffer, &scratch_buffer_size);
     266              : 
     267              :     /* The first section of the scratch
     268              :      * buffer may be used for other purposes. Use only after that section. */
     269            8 :     large_response = scratch_buffer + libspdm_get_scratch_buffer_large_message_offset(spdm_context);
     270            8 :     large_response_capacity = libspdm_get_scratch_buffer_large_message_capacity(spdm_context);
     271              : 
     272              :     /* Temporary send/receive buffers for chunking are in the scratch space */
     273            8 :     message = scratch_buffer + libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context);
     274            8 :     message_size = libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context);
     275              : 
     276            8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14) {
     277              :         /* chunk seq no wrap not considered in spdm 1.4+ */
     278            7 :         max_chunk_data_transfer_size =
     279            7 :             ((size_t) spdm_context->local_context.capability.data_transfer_size
     280            7 :              - sizeof(spdm_chunk_response_response_t)) * 65536 - sizeof(uint32_t);
     281              :     }
     282              : 
     283            8 :     libspdm_zero_mem(large_response, large_response_capacity);
     284            8 :     large_response_size = 0;
     285            8 :     large_response_size_so_far = 0;
     286            8 :     chunk_seq_no = 0;
     287              : 
     288              :     do {
     289        65615 :         LIBSPDM_ASSERT(message_size >= transport_header_size);
     290              : 
     291        65615 :         spdm_request = (spdm_chunk_get_request_t*)(void*) (message + transport_header_size);
     292        65615 :         spdm_request_size = message_size - transport_header_size;
     293        65615 :         if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14) {
     294        65606 :             LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_chunk_get_request_t));
     295        65606 :             spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
     296        65606 :             spdm_request->header.request_response_code = SPDM_CHUNK_GET;
     297        65606 :             spdm_request->header.param1 = 0;
     298        65606 :             spdm_request->header.param2 = chunk_handle;
     299        65606 :             spdm_request->chunk_seq_no = (uint16_t) chunk_seq_no;
     300        65606 :             spdm_request_size = sizeof(spdm_chunk_get_request_t);
     301              : 
     302        65606 :             if ((uint16_t) chunk_seq_no == 0 && large_response_size_so_far != 0) {
     303              :                 /* chunk_seq_no wrapped */
     304            1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     305            2 :                 break;
     306              :             }
     307              :         } else {
     308            9 :             LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_chunk_get_request_14_t));
     309            9 :             spdm_request_14 = (spdm_chunk_get_request_14_t*)spdm_request;
     310            9 :             spdm_request_14->header.spdm_version = libspdm_get_connection_version(spdm_context);
     311            9 :             spdm_request_14->header.request_response_code = SPDM_CHUNK_GET;
     312            9 :             spdm_request_14->header.param1 = 0;
     313            9 :             spdm_request_14->header.param2 = chunk_handle;
     314            9 :             spdm_request_14->chunk_seq_no = chunk_seq_no;
     315            9 :             spdm_request_size = sizeof(spdm_chunk_get_request_14_t);
     316              :         }
     317              : 
     318              : 
     319        65614 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
     320              :                        "CHUNK_GET Handle %d SeqNo %d\n", chunk_handle, chunk_seq_no));
     321              : 
     322        65614 :         status = libspdm_send_spdm_request(spdm_context, session_id,
     323              :                                            spdm_request_size, spdm_request);
     324              : 
     325        65614 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     326            0 :             break;
     327              :         }
     328              : 
     329        65614 :         libspdm_zero_mem(message, message_size);
     330        65614 :         void* response = message;
     331        65614 :         size_t response_size = message_size;
     332              : 
     333        65614 :         status = libspdm_receive_spdm_response(
     334              :             spdm_context, session_id,
     335              :             &response_size, &response);
     336              : 
     337        65614 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     338            0 :             break;
     339              :         }
     340        65614 :         spdm_response = (void*) (response);
     341        65614 :         if (spdm_response->header.request_response_code == SPDM_ERROR) {
     342            0 :             status = libspdm_handle_simple_error_response(spdm_context,
     343            0 :                                                           spdm_response->header.param1);
     344            0 :             break;
     345              :         }
     346        65614 :         if (spdm_response->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
     347            0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     348            0 :             break;
     349              :         }
     350        65614 :         if (spdm_response->header.request_response_code != SPDM_CHUNK_RESPONSE) {
     351            0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     352            0 :             break;
     353              :         }
     354              : 
     355              :         LIBSPDM_ASSERT(sizeof(spdm_chunk_response_response_t) == sizeof(spdm_chunk_response_response_14_t));
     356        65614 :         if (chunk_seq_no == 0) {
     357              : 
     358            8 :             if (response_size
     359            8 :                 < (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t))) {
     360            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     361            0 :                 break;
     362              :             }
     363            8 :             if (response_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
     364            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     365            0 :                 break;
     366              :             }
     367              : 
     368            8 :             if (spdm_response->chunk_size
     369              :                 < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
     370              :                 - sizeof(spdm_chunk_response_response_t)
     371              :                 - sizeof(uint32_t)) {
     372            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     373            0 :                 break;
     374              :             }
     375              : 
     376            8 :             large_response_size = *(uint32_t*) (spdm_response + 1);
     377            8 :             chunk_ptr = (uint8_t*) (((uint32_t*) (spdm_response + 1)) + 1);
     378              : 
     379            8 :             if (spdm_response->chunk_size > large_response_size) {
     380            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     381            0 :                 break;
     382              :             }
     383            8 :             if (large_response_size > spdm_context->local_context.capability.max_spdm_msg_size) {
     384            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     385            0 :                 break;
     386              :             }
     387            8 :             if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14
     388            7 :                 && large_response_size > max_chunk_data_transfer_size) {
     389            1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     390            1 :                 break;
     391              :             }
     392            7 :             if (large_response_size <= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
     393            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     394            0 :                 break;
     395              :             }
     396              :         } else {
     397        65606 :             if (response_size < sizeof(spdm_chunk_response_response_t)) {
     398            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     399            0 :                 break;
     400              :             }
     401        65606 :             if (spdm_response->chunk_size + large_response_size_so_far > large_response_size) {
     402            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     403            0 :                 break;
     404              :             }
     405              : 
     406        65606 :             if (!(spdm_response->header.param1 & SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK)) {
     407        65600 :                 if (response_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
     408            0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     409            0 :                     break;
     410              :                 }
     411        65600 :                 if (spdm_response->chunk_size
     412              :                     < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
     413              :                     - sizeof(spdm_chunk_response_response_t)) {
     414            0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     415            0 :                     break;
     416              :                 }
     417              :             }
     418              : 
     419        65606 :             chunk_ptr = (uint8_t*) (spdm_response + 1);
     420              :         }
     421        65613 :         if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14) {
     422        65604 :             if (spdm_response->chunk_seq_no != (uint16_t) chunk_seq_no) {
     423            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     424            0 :                 break;
     425              :             }
     426              :         } else {
     427            9 :             spdm_response_14 = (spdm_chunk_response_response_14_t*)spdm_response;
     428            9 :             if (spdm_response_14->chunk_seq_no != chunk_seq_no) {
     429            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     430            0 :                 break;
     431              :             }
     432              :         }
     433              : 
     434        65613 :         libspdm_copy_mem(large_response + large_response_size_so_far,
     435              :                          large_response_size - large_response_size_so_far,
     436        65613 :                          chunk_ptr, spdm_response->chunk_size);
     437              : 
     438        65613 :         large_response_size_so_far += spdm_response->chunk_size;
     439              : 
     440        65613 :         chunk_seq_no++;
     441              : 
     442        65613 :     } while (LIBSPDM_STATUS_IS_SUCCESS(status)
     443        65613 :              && large_response_size_so_far < large_response_size
     444       131220 :              && !(spdm_response->header.param1 & SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK));
     445              : 
     446              : 
     447            8 :     if (LIBSPDM_STATUS_IS_SUCCESS(status)) {
     448            6 :         if (large_response_size_so_far != large_response_size) {
     449            0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     450            6 :         } else if (large_response_size <= response_capacity) {
     451            6 :             libspdm_copy_mem(inout_response, response_capacity,
     452              :                              large_response, large_response_size);
     453            6 :             *inout_response_size = large_response_size;
     454              : 
     455            6 :             LIBSPDM_INTERNAL_DUMP_HEX(large_response, large_response_size);
     456              :         }
     457              :     }
     458              : 
     459            8 :     return status;
     460              : }
     461              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
     462              : 
     463          393 : libspdm_return_t libspdm_handle_error_response_main(
     464              :     libspdm_context_t *spdm_context, const uint32_t *session_id,
     465              :     size_t *response_size, void **response,
     466              :     uint8_t original_request_code, uint8_t expected_response_code)
     467              : {
     468              :     spdm_message_header_t *spdm_response;
     469              : 
     470          393 :     spdm_response = *response;
     471          393 :     LIBSPDM_ASSERT(spdm_response->request_response_code == SPDM_ERROR);
     472              : 
     473          393 :     if ((spdm_response->param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) && (session_id != NULL)) {
     474            5 :         libspdm_free_session_id(spdm_context, *session_id);
     475            5 :         return LIBSPDM_STATUS_SESSION_MSG_ERROR;
     476          388 :     } else if (spdm_response->param1 == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
     477              :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
     478           29 :         return libspdm_handle_response_not_ready(spdm_context, session_id,
     479              :                                                  response_size, response,
     480              :                                                  original_request_code,
     481              :                                                  expected_response_code);
     482              :         #else
     483              :         return LIBSPDM_STATUS_NOT_READY_PEER;
     484              :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
     485              :     } else {
     486          359 :         return libspdm_handle_simple_error_response(spdm_context, spdm_response->param1);
     487              :     }
     488              : }
        

Generated by: LCOV version 2.0-1