1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*******************************************************************************
3  * Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG
4  * All rights reserved.
5  ******************************************************************************/
6 
7 #ifndef IFAPI_IO_H
8 #define IFAPI_IO_H
9 
10 #include <stdio.h>
11 #include <stdbool.h>
12 #include "tss2_common.h"
13 #include "tss2_fapi.h"
14 
15 typedef struct IFAPI_IO {
16     FILE *stream;
17     short pollevents;
18     const char *char_buffer;
19     char *char_rbuffer;
20     size_t buffer_length;
21     size_t buffer_idx;
22 } IFAPI_IO;
23 
24 #ifdef TEST_FAPI_ASYNC
25 #define _IFAPI_IO_RETRIES 1
26 #else /* TEST_FAPI_ASYNC */
27 #define _IFAPI_IO_RETRIES 0
28 #endif /* TEST_FAPI_ASYNC */
29 
30 static int _ifapi_io_retry __attribute__((unused)) = _IFAPI_IO_RETRIES;
31 
32 #define IFAPI_IO_STREAM context->io.stream
33 #define IFAPI_IO_BUFF context->io.char_buffer
34 #define IFAPI_IO_RBUFF context->io.char_rbuffer
35 #define IFAPI_IO_BUFFLEN context->io.buffer_length
36 #define IFAPI_IO_BUFFIDX context->io.buffer_idx
37 
38 TSS2_RC
39 ifapi_io_read_async(
40     struct IFAPI_IO *io,
41     const char *filename);
42 
43 TSS2_RC
44 ifapi_io_read_finish(
45     struct IFAPI_IO *io,
46     uint8_t **buffer,
47     size_t *length);
48 
49 TSS2_RC
50 ifapi_io_write_async(
51     struct IFAPI_IO *io,
52     const char *filename,
53     const uint8_t *buffer,
54     size_t length);
55 
56 TSS2_RC
57 ifapi_io_write_finish(
58     struct IFAPI_IO *io);
59 
60 TSS2_RC
61 ifapi_io_check_file_writeable(
62     const char *file);
63 
64 TSS2_RC
65 ifapi_io_check_create_dir(
66     const char *dirname, int mode);
67 
68 TSS2_RC
69 ifapi_io_remove_file(
70     const char *file);
71 
72 TSS2_RC
73 ifapi_io_remove_directories(
74     const char *dirname,
75     const char *keystore_path,
76     const char *sub_dir);
77 
78 TSS2_RC
79 ifapi_io_dirfiles(
80     const char *dirname,
81     char ***files,
82     size_t *numfiles);
83 
84 TSS2_RC
85 ifapi_io_dirfiles_all(
86     const char *searchPath,
87     char ***pathlist,
88     size_t *numPaths);
89 
90 bool
91 ifapi_io_path_exists(const char *path);
92 
93 TSS2_RC
94 ifapi_io_poll(IFAPI_IO * io);
95 
96 TSS2_RC
97 ifapi_io_poll_handles(IFAPI_IO *io, FAPI_POLL_HANDLE **handles, size_t *num_handles);
98 
99 #endif /* IFAPI_IO_H */
100