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.3 % 229 177
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2026 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              :     bool response_from_chunk)
     216              : {
     217              :     libspdm_return_t status;
     218              :     uint8_t chunk_handle;
     219              :     spdm_error_response_t* error_response;
     220              :     spdm_error_data_large_response_t* extend_error_data;
     221              : 
     222              :     spdm_chunk_get_request_t* spdm_request;
     223              :     spdm_chunk_get_request_14_t* spdm_request_14;
     224              :     size_t spdm_request_size;
     225              :     spdm_chunk_response_response_t* spdm_response;
     226              :     spdm_chunk_response_response_14_t* spdm_response_14;
     227              :     uint8_t* message;
     228              :     size_t message_size;
     229              :     size_t transport_header_size;
     230              : 
     231              :     uint8_t* scratch_buffer;
     232              :     size_t scratch_buffer_size;
     233              :     uint32_t chunk_seq_no;
     234              :     uint8_t* chunk_ptr;
     235              :     uint8_t* large_response;
     236              :     size_t large_response_capacity;
     237              :     size_t large_response_size;
     238              :     size_t large_response_size_so_far;
     239              :     uint64_t max_chunk_data_transfer_size;
     240              :     size_t min_large_response_size;
     241              : 
     242            8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
     243            0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
     244              :     }
     245              : 
     246              :     /* Fail if requester or responder does not support chunk cap */
     247            8 :     if (!libspdm_is_capabilities_flag_supported(
     248              :             spdm_context, true,
     249              :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
     250              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
     251            0 :         return LIBSPDM_STATUS_ERROR_PEER;
     252              :     }
     253              : 
     254            8 :     if (*inout_response_size < sizeof(spdm_error_response_t) +
     255              :         sizeof(spdm_error_data_large_response_t)) {
     256            0 :         return LIBSPDM_STATUS_INVALID_MSG_SIZE;
     257              :     }
     258              : 
     259            8 :     error_response = inout_response;
     260            8 :     extend_error_data =
     261              :         (spdm_error_data_large_response_t*)(error_response + 1);
     262            8 :     chunk_handle = extend_error_data->handle;
     263              : 
     264              :     /* now we can get sender buffer */
     265            8 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     266              : 
     267            8 :     libspdm_get_scratch_buffer(spdm_context, (void**)&scratch_buffer, &scratch_buffer_size);
     268              : 
     269              :     /* The first section of the scratch
     270              :      * buffer may be used for other purposes. Use only after that section. */
     271            8 :     large_response = scratch_buffer + libspdm_get_scratch_buffer_large_message_offset(spdm_context);
     272            8 :     large_response_capacity = libspdm_get_scratch_buffer_large_message_capacity(spdm_context);
     273              : 
     274              :     /* Temporary send/receive buffers for chunking are in the scratch space */
     275            8 :     message = scratch_buffer + libspdm_get_scratch_buffer_sender_receiver_offset(spdm_context);
     276            8 :     message_size = libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context);
     277              : 
     278            8 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14) {
     279              :         /* chunk seq no wrap not considered in spdm 1.4+ */
     280            6 :         max_chunk_data_transfer_size =
     281            6 :             ((size_t) spdm_context->local_context.capability.data_transfer_size
     282            6 :              - sizeof(spdm_chunk_response_response_t)) * 65536 - sizeof(uint32_t);
     283              :     }
     284              : 
     285            8 :     libspdm_zero_mem(large_response, large_response_capacity);
     286            8 :     large_response_size = 0;
     287            8 :     large_response_size_so_far = 0;
     288            8 :     chunk_seq_no = 0;
     289              : 
     290              :     do {
     291        65616 :         LIBSPDM_ASSERT(message_size >= transport_header_size);
     292              : 
     293        65616 :         spdm_request = (spdm_chunk_get_request_t*)(void*) (message + transport_header_size);
     294        65616 :         spdm_request_size = message_size - transport_header_size;
     295        65616 :         if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14) {
     296        65605 :             LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_chunk_get_request_t));
     297        65605 :             spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
     298        65605 :             spdm_request->header.request_response_code = SPDM_CHUNK_GET;
     299        65605 :             spdm_request->header.param1 = 0;
     300        65605 :             spdm_request->header.param2 = chunk_handle;
     301        65605 :             spdm_request->chunk_seq_no = (uint16_t) chunk_seq_no;
     302        65605 :             spdm_request_size = sizeof(spdm_chunk_get_request_t);
     303              : 
     304        65605 :             if ((uint16_t) chunk_seq_no == 0 && large_response_size_so_far != 0) {
     305              :                 /* chunk_seq_no wrapped */
     306            1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     307            2 :                 break;
     308              :             }
     309              :         } else {
     310           11 :             LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_chunk_get_request_14_t));
     311           11 :             spdm_request_14 = (spdm_chunk_get_request_14_t*)spdm_request;
     312           11 :             spdm_request_14->header.spdm_version = libspdm_get_connection_version(spdm_context);
     313           11 :             spdm_request_14->header.request_response_code = SPDM_CHUNK_GET;
     314           11 :             spdm_request_14->header.param1 = 0;
     315           11 :             spdm_request_14->header.param2 = chunk_handle;
     316           11 :             spdm_request_14->chunk_seq_no = chunk_seq_no;
     317           11 :             spdm_request_size = sizeof(spdm_chunk_get_request_14_t);
     318              :         }
     319              : 
     320              : 
     321        65615 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
     322              :                        "CHUNK_GET Handle %d SeqNo %d\n", chunk_handle, chunk_seq_no));
     323              : 
     324        65615 :         status = libspdm_send_spdm_request(spdm_context, session_id,
     325              :                                            spdm_request_size, spdm_request);
     326              : 
     327        65615 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     328            0 :             break;
     329              :         }
     330              : 
     331        65615 :         libspdm_zero_mem(message, message_size);
     332        65615 :         void* response = message;
     333        65615 :         size_t response_size = message_size;
     334              : 
     335        65615 :         status = libspdm_receive_spdm_response(
     336              :             spdm_context, session_id,
     337              :             &response_size, &response);
     338              : 
     339        65615 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     340            0 :             break;
     341              :         }
     342        65615 :         spdm_response = (void*) (response);
     343        65615 :         if (spdm_response->header.request_response_code == SPDM_ERROR) {
     344            0 :             status = libspdm_handle_simple_error_response(spdm_context,
     345            0 :                                                           spdm_response->header.param1);
     346            0 :             break;
     347              :         }
     348        65615 :         if (spdm_response->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
     349            0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     350            0 :             break;
     351              :         }
     352        65615 :         if (spdm_response->header.request_response_code != SPDM_CHUNK_RESPONSE) {
     353            0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     354            0 :             break;
     355              :         }
     356              : 
     357              :         LIBSPDM_ASSERT(sizeof(spdm_chunk_response_response_t) == sizeof(spdm_chunk_response_response_14_t));
     358        65615 :         if (chunk_seq_no == 0) {
     359              : 
     360            8 :             if (response_size
     361            8 :                 < (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t))) {
     362            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     363            0 :                 break;
     364              :             }
     365            8 :             if (response_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
     366            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     367            0 :                 break;
     368              :             }
     369              : 
     370            8 :             if (spdm_response->chunk_size
     371              :                 < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
     372              :                 - sizeof(spdm_chunk_response_response_t)
     373              :                 - sizeof(uint32_t)) {
     374            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     375            0 :                 break;
     376              :             }
     377              : 
     378            8 :             large_response_size = *(uint32_t*) (spdm_response + 1);
     379            8 :             chunk_ptr = (uint8_t*) (((uint32_t*) (spdm_response + 1)) + 1);
     380              : 
     381            8 :             if (spdm_response->chunk_size > large_response_size) {
     382            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     383            0 :                 break;
     384              :             }
     385            8 :             if (large_response_size > spdm_context->local_context.capability.max_spdm_msg_size) {
     386            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     387            0 :                 break;
     388              :             }
     389            8 :             if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14
     390            6 :                 && large_response_size > max_chunk_data_transfer_size) {
     391            1 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     392            1 :                 break;
     393              :             }
     394            7 :             if (response_from_chunk) {
     395              :                 /* If the Responder's DataTransferSize is approximately equal to MinDataTransferSize
     396              :                 * then Responder may chunk a message whose size is less than MinDataTransferSize. */
     397            1 :                 if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_14){
     398            1 :                     min_large_response_size = SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12 -
     399              :                                               sizeof(spdm_chunk_send_ack_response_14_t);
     400              :                 } else {
     401            0 :                     min_large_response_size = SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12 -
     402              :                                               sizeof(spdm_chunk_send_ack_response_t);
     403              :                 }
     404              :             } else {
     405            6 :                 min_large_response_size = SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12;
     406              :             }
     407            7 :             if (large_response_size <= min_large_response_size) {
     408            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     409            0 :                 break;
     410              :             }
     411              :         } else {
     412        65607 :             if (response_size < sizeof(spdm_chunk_response_response_t)) {
     413            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     414            0 :                 break;
     415              :             }
     416        65607 :             if (spdm_response->chunk_size + large_response_size_so_far > large_response_size) {
     417            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     418            0 :                 break;
     419              :             }
     420              : 
     421        65607 :             if (!(spdm_response->header.param1 & SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK)) {
     422        65601 :                 if (response_size < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
     423            0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     424            0 :                     break;
     425              :                 }
     426        65601 :                 if (spdm_response->chunk_size
     427              :                     < SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12
     428              :                     - sizeof(spdm_chunk_response_response_t)) {
     429            0 :                     status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     430            0 :                     break;
     431              :                 }
     432              :             }
     433              : 
     434        65607 :             chunk_ptr = (uint8_t*) (spdm_response + 1);
     435              :         }
     436        65614 :         if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_14) {
     437        65603 :             if (spdm_response->chunk_seq_no != (uint16_t) chunk_seq_no) {
     438            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     439            0 :                 break;
     440              :             }
     441              :         } else {
     442           11 :             spdm_response_14 = (spdm_chunk_response_response_14_t*)spdm_response;
     443           11 :             if (spdm_response_14->chunk_seq_no != chunk_seq_no) {
     444            0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     445            0 :                 break;
     446              :             }
     447              :         }
     448              : 
     449        65614 :         libspdm_copy_mem(large_response + large_response_size_so_far,
     450              :                          large_response_size - large_response_size_so_far,
     451        65614 :                          chunk_ptr, spdm_response->chunk_size);
     452              : 
     453        65614 :         large_response_size_so_far += spdm_response->chunk_size;
     454              : 
     455        65614 :         chunk_seq_no++;
     456              : 
     457        65614 :     } while (LIBSPDM_STATUS_IS_SUCCESS(status)
     458        65614 :              && large_response_size_so_far < large_response_size
     459       131222 :              && !(spdm_response->header.param1 & SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK));
     460              : 
     461              : 
     462            8 :     if (LIBSPDM_STATUS_IS_SUCCESS(status)) {
     463            6 :         if (large_response_size_so_far != large_response_size) {
     464            0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     465            6 :         } else if (large_response_size <= response_capacity) {
     466            6 :             libspdm_copy_mem(inout_response, response_capacity,
     467              :                              large_response, large_response_size);
     468            6 :             *inout_response_size = large_response_size;
     469              : 
     470            6 :             LIBSPDM_INTERNAL_DUMP_HEX(large_response, large_response_size);
     471            6 :             libspdm_zero_mem(large_response, large_response_size);
     472              :         }
     473              :     }
     474              : 
     475            8 :     return status;
     476              : }
     477              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
     478              : 
     479          393 : libspdm_return_t libspdm_handle_error_response_main(
     480              :     libspdm_context_t *spdm_context, const uint32_t *session_id,
     481              :     size_t *response_size, void **response,
     482              :     uint8_t original_request_code, uint8_t expected_response_code)
     483              : {
     484              :     spdm_message_header_t *spdm_response;
     485              : 
     486          393 :     spdm_response = *response;
     487          393 :     LIBSPDM_ASSERT(spdm_response->request_response_code == SPDM_ERROR);
     488              : 
     489          393 :     if ((spdm_response->param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) && (session_id != NULL)) {
     490            5 :         libspdm_free_session_id(spdm_context, *session_id);
     491            5 :         return LIBSPDM_STATUS_SESSION_MSG_ERROR;
     492          388 :     } else if (spdm_response->param1 == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
     493              :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
     494           29 :         return libspdm_handle_response_not_ready(spdm_context, session_id,
     495              :                                                  response_size, response,
     496              :                                                  original_request_code,
     497              :                                                  expected_response_code);
     498              :         #else
     499              :         return LIBSPDM_STATUS_NOT_READY_PEER;
     500              :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
     501              :     } else {
     502          359 :         return libspdm_handle_simple_error_response(spdm_context, spdm_response->param1);
     503              :     }
     504              : }
        

Generated by: LCOV version 2.0-1