-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support pcap capture in teeio_validator
This patch adds support to capture pcap file in teeio_validator application. The captured pcap file can be used for offline analysis by spdm-dump tool. The pcap related implementation i.e. pcap.c is based on similar implementation in spdm-emu/spdm_emu/spdm_emu_common/pcap.c. This feature is controlled by 'pcap_enable' field in [Main] section. Currently the capture is done for PCI_DOE transport layer. Separate option can be added later in [Main] section to control transport option i.e. PCIE_DOE or MCTP. Signed-off-by: Subrata Chatterjee <subrata.chatterjee@intel.com>
- Loading branch information
1 parent
67a4d41
commit cf83e93
Showing
12 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ | |
#define TEEIO_VALIDATOR_VERSION "0.2.0" | ||
|
||
#define LOGFILE "./teeio_log" | ||
#define PCAPFILE "./teeio_pcap" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright Notice: | ||
* Copyright 2021-2022 DMTF. All rights reserved. | ||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md | ||
**/ | ||
|
||
#ifndef __SPDM_PCAP_H__ | ||
#define __SPDM_PCAP_H__ | ||
|
||
bool open_pcap_packet_file(const char *pcap_file_name, uint32_t transport_layer); | ||
|
||
void close_pcap_packet_file(void); | ||
|
||
void append_pcap_packet_data(const void *header, size_t header_size, | ||
const void *data, size_t size); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright Notice: | ||
* Copyright 2021-2022 DMTF. All rights reserved. | ||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md | ||
**/ | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <time.h> | ||
#include <stdbool.h> | ||
#include <industry_standard/pcap.h> | ||
#include <industry_standard/link_type_ex.h> | ||
#include "pcap.h" | ||
#include "command.h" | ||
#include "teeio_debug.h" | ||
|
||
#define PCAP_PACKET_MAX_SIZE 0x00010000 | ||
|
||
static FILE *m_pcap_file; | ||
|
||
bool open_pcap_packet_file(const char *pcap_file_name, uint32_t transport_layer) | ||
{ | ||
pcap_global_header_t pcap_global_header; | ||
|
||
if (pcap_file_name == NULL) { | ||
return false; | ||
} | ||
|
||
pcap_global_header.magic_number = PCAP_GLOBAL_HEADER_MAGIC; | ||
pcap_global_header.version_major = PCAP_GLOBAL_HEADER_VERSION_MAJOR; | ||
pcap_global_header.version_minor = PCAP_GLOBAL_HEADER_VERSION_MINOR; | ||
pcap_global_header.this_zone = 0; | ||
pcap_global_header.sig_figs = 0; | ||
pcap_global_header.snap_len = PCAP_PACKET_MAX_SIZE; | ||
if (transport_layer == SOCKET_TRANSPORT_TYPE_MCTP) { | ||
pcap_global_header.network = LINKTYPE_MCTP; | ||
} else if (transport_layer == SOCKET_TRANSPORT_TYPE_PCI_DOE) { | ||
pcap_global_header.network = LINKTYPE_PCI_DOE; | ||
} else { | ||
return false; | ||
} | ||
|
||
if ((m_pcap_file = fopen(pcap_file_name, "wb")) == NULL) { | ||
TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "!!!Unable to open pcap file %s!!!\n", pcap_file_name)); | ||
return false; | ||
} | ||
|
||
if ((fwrite(&pcap_global_header, 1, sizeof(pcap_global_header), | ||
m_pcap_file)) != sizeof(pcap_global_header)) { | ||
TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "!!!Write pcap file error!!!\n")); | ||
close_pcap_packet_file(); | ||
return false; | ||
} | ||
|
||
fflush(m_pcap_file); | ||
return true; | ||
} | ||
|
||
void close_pcap_packet_file(void) | ||
{ | ||
if (m_pcap_file != NULL) { | ||
fclose(m_pcap_file); | ||
m_pcap_file = NULL; | ||
} | ||
} | ||
|
||
void append_pcap_packet_data(const void *header, size_t header_size, | ||
const void *data, size_t size) | ||
{ | ||
pcap_packet_header_t pcap_packet_header; | ||
size_t total_size; | ||
|
||
total_size = header_size + size; | ||
|
||
if (m_pcap_file != NULL) { | ||
time_t rawtime; | ||
time(&rawtime); | ||
|
||
pcap_packet_header.ts_sec = (uint32_t)rawtime; | ||
pcap_packet_header.ts_usec = 0; | ||
|
||
pcap_packet_header.incl_len = | ||
(uint32_t)((total_size > PCAP_PACKET_MAX_SIZE) ? | ||
PCAP_PACKET_MAX_SIZE : | ||
total_size); | ||
pcap_packet_header.orig_len = (uint32_t)total_size; | ||
|
||
if ((fwrite(&pcap_packet_header, 1, sizeof(pcap_packet_header), | ||
m_pcap_file)) != sizeof(pcap_packet_header)) { | ||
TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "!!!Write pcap file error!!!\n")); | ||
close_pcap_packet_file(); | ||
return; | ||
} | ||
|
||
if (total_size > PCAP_PACKET_MAX_SIZE) { | ||
total_size = PCAP_PACKET_MAX_SIZE; | ||
} | ||
|
||
if (header_size != 0) { | ||
if ((fwrite(header, 1, header_size, m_pcap_file)) != | ||
header_size) { | ||
TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "!!!Write pcap file error!!!\n")); | ||
close_pcap_packet_file(); | ||
return; | ||
} | ||
} | ||
|
||
if ((fwrite(data, 1, size, m_pcap_file)) != size) { | ||
TEEIO_DEBUG ((TEEIO_DEBUG_ERROR, "!!!Write pcap file error!!!\n")); | ||
close_pcap_packet_file(); | ||
return; | ||
} | ||
|
||
fflush(m_pcap_file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters