NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
file_integrity_core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef FILE_INTEGRITY_CORE_H_
27 #define FILE_INTEGRITY_CORE_H_
28 
29 #include <doca_buf.h>
30 #include <doca_buf_inventory.h>
31 #include <doca_ctx.h>
32 #include <doca_sha.h>
33 
34 #include "comch_utils.h"
35 
36 #include <samples/common.h>
37 
38 #define MAX_FILE_NAME 255 /* Max file name */
39 
40 /* File integrity running mode */
42  NO_VALID_INPUT = 0, /* CLI argument is not valid */
43  CLIENT, /* Run app as client */
44  SERVER /* Run app as server */
45 };
46 
47 /* State of the file transfer on the doca comch control path */
49  TRANSFER_IDLE, /* No transfer has started */
50  TRANSFER_IN_PROGRESS, /* File transfer is under way */
51  TRANSFER_COMPLETE, /* File transfer is complete */
52  TRANSFER_ERROR, /* An error was detected in file transfer */
53 };
54 
55 struct server_runtime_data {
56  /* Async file data */
57  uint32_t expected_file_chunks; /* Number of chunks file should be sent in */
58  uint32_t received_file_chunks; /* Current number of chunks received */
59  uint32_t received_file_length; /* Current length of file data received */
60  uint32_t expected_sha_len; /* Length of expected SHA byte array */
61  uint8_t *expected_sha; /* Expected SHA of file */
62 
63  /* Async SHA data */
64  char *sha_src_data; /* Raw data buffer containing data to send to SHA */
65  struct doca_buf *sha_src_buf; /* Doca_buf wrapping sha_src_data */
66  struct doca_sha_task_hash *sha_hash_task; /* Single task for doing a full SHA */
67  struct doca_sha_task_partial_hash *sha_partial_hash_task; /* Single task for use in partial SHA */
68  struct program_core_objects *sha_state; /* Core state of SHA context */
69  size_t active_sha_tasks; /* Variable indicating number of active tasks */
70  int fd; /* File descriptor for writing data to */
71 };
72 
74  uint32_t total_file_chunks; /* Number of chunks the file will be sent across */
75  uint8_t sha_data[]; /* Expected SHA of transferred file */
76 };
77 
78 /* File integrity configuration struct */
80  enum file_integrity_mode mode; /* Mode of operation */
81  char file_path[MAX_FILE_NAME]; /* Input file path */
82  char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Comm Channel DOCA device PCI address */
83  char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]; /* Comm Channel DOCA device representor PCI address */
84  int timeout; /* Application timeout in seconds */
85  struct server_runtime_data server_data; /* Data populated on server side during file transmission */
86  enum transfer_state state; /* Indicator of completion of a file transfer */
87 };
88 
89 /*
90  * Initialize application resources
91  *
92  * @app_cfg [in]: application config struct
93  * @state [out]: application core object struct
94  * @sha_ctx [out]: context of SHA library
95  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
96  */
98  struct program_core_objects *state,
99  struct doca_sha **sha_ctx);
100 
101 /*
102  * Clean all application resources
103  *
104  * @state [in]: application core object struct
105  * @sha_ctx [in]: context of SHA library
106  */
107 void file_integrity_cleanup(struct program_core_objects *state, struct doca_sha *sha_ctx);
108 
109 /*
110  * Run client logic
111  *
112  * @comch_cfg [in]: comch configuration object
113  * @cfg [in]: application config struct
114  * @state [in]: application core object struct
115  * @sha_ctx [in]: context of SHA library
116  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
117  */
119  struct file_integrity_config *cfg,
120  struct program_core_objects *state,
121  struct doca_sha *sha_ctx);
122 
123 /*
124  * Run server logic
125  *
126  * @comch_cfg [in]: comch configuration object
127  * @cfg [in]: application config struct
128  * @state [in]: application core object struct
129  * @sha_ctx [in]: context of SHA library
130  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
131  */
133  struct file_integrity_config *cfg,
134  struct program_core_objects *state,
135  struct doca_sha *sha_ctx);
136 
137 /*
138  * Register the command line parameters for the application
139  *
140  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
141  */
143 
144 /*
145  * Callback event for client messages
146  *
147  * @event [in]: message receive event
148  * @recv_buffer [in]: array of bytes containing the message data
149  * @msg_len [in]: number of bytes in the recv_buffer
150  * @comch_connection [in]: comm channel connection over which the event occurred
151  */
152 void client_recv_event_cb(struct doca_comch_event_msg_recv *event,
153  uint8_t *recv_buffer,
154  uint32_t msg_len,
155  struct doca_comch_connection *comch_connection);
156 
157 /*
158  * Callback event for server messages
159  *
160  * @event [in]: message receive event
161  * @recv_buffer [in]: array of bytes containing the message data
162  * @msg_len [in]: number of bytes in the recv_buffer
163  * @comch_connection [in]: comm channel connection over which the event occurred
164  */
165 void server_recv_event_cb(struct doca_comch_event_msg_recv *event,
166  uint8_t *recv_buffer,
167  uint32_t msg_len,
168  struct doca_comch_connection *comch_connection);
169 
170 #endif /* FILE_INTEGRITY_CORE_H_ */
doca_error_t register_file_integrity_params(void)
void file_integrity_cleanup(struct program_core_objects *state, struct doca_sha *sha_ctx)
file_integrity_mode
@ CLIENT
@ SERVER
@ NO_VALID_INPUT
doca_error_t file_integrity_server(struct comch_cfg *comch_cfg, struct file_integrity_config *cfg, struct program_core_objects *state, struct doca_sha *sha_ctx)
doca_error_t file_integrity_init(struct file_integrity_config *app_cfg, struct program_core_objects *state, struct doca_sha **sha_ctx)
doca_error_t file_integrity_client(struct comch_cfg *comch_cfg, struct file_integrity_config *cfg, struct program_core_objects *state, struct doca_sha *sha_ctx)
void server_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void client_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
@ TRANSFER_ERROR
@ TRANSFER_COMPLETE
@ TRANSFER_IN_PROGRESS
@ TRANSFER_IDLE
#define MAX_FILE_NAME
static struct app_gpu_cfg app_cfg
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:665
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
enum doca_error doca_error_t
DOCA API return codes.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
enum transfer_state state
char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]
char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
struct server_runtime_data server_data
enum file_integrity_mode mode
char file_path[MAX_FILE_NAME]
struct doca_sha_task_partial_hash * sha_partial_hash_task
struct doca_buf * sha_src_buf
struct doca_sha_task_hash * sha_hash_task
struct program_core_objects * sha_state