RTEMS 6.1-rc1
tftpfs_interactions.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
14/*
15 * Copyright (C) 2022 embedded brains GmbH & Co. KG
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef _TFTPFS_INTERACTIONS_H
40#define _TFTPFS_INTERACTIONS_H
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#define NO_BLOCK_SIZE_OPTION 0
47#define NO_WINDOW_SIZE_OPTION 0
48#define DO_NOT_WAIT_FOR_ANY_TIMEOUT UINT32_MAX
49
56/*
57 * These functions append an interaction to the list of expected interactions.
58 * For example, _Tftp_Add_interaction_socket() "means":
59 *
60 * * As next interaction, expect that the TFTP client calls function
61 * socket().
62 * * Expect (i.e. check) that this socket() call will get parameter values
63 * as provided by its parameters `domain`, `type` and `protocol`.
64 * * This call to socket() shall return value of parameter `result`
65 * to the TFTP client.
66 *
67 * The interactions with functions sendto() and recvfrom() are a bit more
68 * complicated because specific packets are expected to be received or sent.
69 * For example, _Tftp_Add_interaction_send_rrq() appends an interaction
70 * where the TFTP client is expected to call sendto() with an RRQ (Read
71 * Request) packet. _Tftp_Add_interaction_recv_data() appends an interaction
72 * where the TFTP client is expected to call recvfrom() and as result it
73 * receives a data packet (which the interaction writes into the buffer
74 * which the TFTP client provides as parameter in its the recvfrom() call).
75 */
76
77void _Tftp_Add_interaction_socket(
78 int domain,
79 int type,
80 int protocol,
81 int result
82);
83
84void _Tftp_Add_interaction_close( int fd, int result );
85
86void _Tftp_Add_interaction_bind( int fd, int family, int result );
87
88void _Tftp_Add_interaction_send_rrq(
89 int fd,
90 const char *filename,
91 uint16_t dest_port,
92 const char *dest_addr_str,
93 uint16_t block_size,
94 uint16_t window_size,
95 bool result
96);
97
98void _Tftp_Add_interaction_send_wrq(
99 int fd,
100 const char *filename,
101 uint16_t dest_port,
102 const char *dest_addr_str,
103 uint16_t block_size,
104 uint16_t window_size,
105 bool result
106);
107
108void _Tftp_Add_interaction_send_ack(
109 int fd,
110 uint16_t block_num,
111 uint16_t dest_port,
112 const char *dest_addr_str,
113 bool result
114);
115
116void _Tftp_Add_interaction_send_data(
117 int fd,
118 uint16_t block_num,
119 size_t start,
120 size_t len,
121 uint8_t (*get_data)( size_t pos ),
122 uint16_t dest_port,
123 const char *dest_addr_str,
124 bool result
125);
126
127void _Tftp_Add_interaction_send_error(
128 int fd,
129 uint16_t error_code,
130 uint16_t dest_port,
131 const char *dest_addr_str,
132 bool result
133);
134
135/*
136 * _Tftp_Add_interaction_recv_data() permits only a boolean result.
137 * The TFTP client code does not check `errno` and always behaves as if
138 * a return of -1 indicates a timeout. Hence
139 * _Tftp_Add_interaction_recv_data() permits only a boolean result
140 * and no special value to distinct timeouts from other errors.
141 */
142void _Tftp_Add_interaction_recv_data(
143 int fd,
144 uint32_t timeout_ms,
145 uint16_t src_port,
146 const char *src_addr_str,
147 uint16_t block_num,
148 size_t start,
149 size_t len,
150 uint8_t (*get_data)( size_t pos ),
151 bool result
152);
153
154void _Tftp_Add_interaction_recv_ack(
155 int fd,
156 uint32_t timeout_ms,
157 uint16_t src_port,
158 const char *src_addr_str,
159 uint16_t block_num,
160 bool result
161);
162
163void _Tftp_Add_interaction_recv_oack(
164 int fd,
165 uint32_t timeout_ms,
166 uint16_t src_port,
167 const char *src_addr_str,
168 const char *options,
169 size_t options_size,
170 bool result
171);
172
173void _Tftp_Add_interaction_recv_error(
174 int fd,
175 uint32_t timeout_ms,
176 uint16_t src_port,
177 const char *src_addr_str,
178 uint16_t error_code,
179 const char *err_msg,
180 bool result
181);
182
183/*
184 * The TFTP client receives a "raw" packet.
185 *
186 * Test tests use this function to trigger packet format errors such as:
187 *
188 * * Too short packets,
189 * * Strings without 0-byte at their end
190 * * Wrong op-codes
191 */
192void _Tftp_Add_interaction_recv_raw(
193 int fd,
194 uint32_t timeout_ms,
195 uint16_t src_port,
196 const char *src_addr_str,
197 size_t len,
198 const uint8_t *bytes,
199 bool result
200);
201
202void _Tftp_Add_interaction_recv_nothing(
203 int fd,
204 uint32_t timeout_ms
205);
206
209#ifdef __cplusplus
210}
211#endif
212
213#endif /* _TFTPFS_INTERACTIONS_H */