LCOV - code coverage report
Current view: top level - os_stub/spdm_device_secret_lib_sample - endpointinfo.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.9 % 33 31
Test Date: 2025-06-29 08:09:00 Functions: 100.0 % 1 1

            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           76 : 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           76 :     LIBSPDM_ASSERT(endpoint_info_size != NULL);
      39           76 :     LIBSPDM_ASSERT(endpoint_info != NULL);
      40              : 
      41           76 :     switch (sub_code) {
      42           76 :     case SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER:
      43           76 :         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           76 :         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           66 :         *endpoint_info_size = ep_info_size;
      54              : 
      55           66 :         ptr = (uint8_t *)endpoint_info;
      56           66 :         device_class_identifier = (spdm_endpoint_info_device_class_identifier_t *) ptr;
      57           66 :         device_class_identifier->num_identifiers = 1;
      58              : 
      59           66 :         ptr += sizeof(spdm_endpoint_info_device_class_identifier_t);
      60           66 :         identifier = (spdm_endpoint_info_device_class_identifier_element_t *) ptr;
      61           66 :         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           66 :         identifier->svh.id = 0x0;
      66           66 :         identifier->svh.vendor_id_len = 0x0;
      67              :         /* DMTF does not have a Vendor ID registry*/
      68           66 :         ptr += sizeof(spdm_endpoint_info_device_class_identifier_element_t);
      69              : 
      70              :         /* a fake sub id for structure sample*/
      71           66 :         num_sub_ids = (uint8_t *) ptr;
      72           66 :         *num_sub_ids = 1;
      73              : 
      74           66 :         ptr += sizeof(uint8_t);
      75           66 :         subordinate_id = (spdm_endpoint_info_device_class_identifier_subordinate_id_t *) ptr;
      76           66 :         subordinate_id->sub_id_len = 0x3;
      77              : 
      78           66 :         ptr += sizeof(spdm_endpoint_info_device_class_identifier_subordinate_id_t);
      79           66 :         sub_identifier = (uint8_t *) ptr;
      80           66 :         sub_identifier[0] = 0x12;
      81           66 :         sub_identifier[1] = 0x34;
      82           66 :         sub_identifier[2] = 0x56;
      83              : 
      84           66 :         break;
      85            0 :     default:
      86            0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
      87              :     }
      88           66 :     return LIBSPDM_STATUS_SUCCESS;
      89              : }
      90              : 
      91              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
        

Generated by: LCOV version 2.0-1