• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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);
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 
76 TSS2_RC
77 ifapi_io_dirfiles(
78     const char *dirname,
79     char ***files,
80     size_t *numfiles);
81 
82 TSS2_RC
83 ifapi_io_dirfiles_all(
84     const char *searchPath,
85     char ***pathlist,
86     size_t *numPaths);
87 
88 bool
89 ifapi_io_path_exists(const char *path);
90 
91 TSS2_RC
92 ifapi_io_poll(IFAPI_IO * io);
93 
94 TSS2_RC
95 ifapi_io_poll_handles(IFAPI_IO *io, FAPI_POLL_HANDLE **handles, size_t *num_handles);
96 
97 #endif /* IFAPI_IO_H */
98