summaryrefslogtreecommitdiffstats
path: root/testsuites/fstests/tftpfs/tftpfs_interactions.h
blob: 732a542e99b554a08eabe540af2bb576f624c05d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup RTEMSTestSuiteTestsTFTPFS
 *
 * @brief This header file provides functions used to
 *   implement network interactions of the UDP network fake for tftpfs tests.
 *
 * Definitions and declarations of data structures and functions.
 */

/*
 * Copyright (C) 2022 embedded brains GmbH & Co. KG
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _TFTPFS_INTERACTIONS_H
#define _TFTPFS_INTERACTIONS_H

#ifdef __cplusplus
extern "C" {
#endif

#define NO_BLOCK_SIZE_OPTION 0
#define NO_WINDOW_SIZE_OPTION 0
#define DO_NOT_WAIT_FOR_ANY_TIMEOUT UINT32_MAX

/**
 * @addtogroup RTEMSTestSuiteTestsTFTPFS
 *
 * @{
 */

/*
 * These functions append an interaction to the list of expected interactions.
 * For example, _Tftp_Add_interaction_socket() "means":
 *
 *   * As next interaction, expect that the TFTP client calls function
 *     socket().
 *   * Expect (i.e. check) that this socket() call will get parameter values
 *     as provided by its parameters `domain`, `type` and `protocol`.
 *   * This call to socket() shall return value of parameter  `result`
 *     to the TFTP client.
 *
 * The interactions with functions sendto() and recvfrom() are a bit more
 * complicated because specific packets are expected to be received or sent.
 * For example, _Tftp_Add_interaction_send_rrq() appends an interaction
 * where the TFTP client is expected to call sendto() with an RRQ (Read
 * Request) packet.  _Tftp_Add_interaction_recv_data() appends an interaction
 * where the TFTP client is expected to call recvfrom() and as result it
 * receives a data packet (which the interaction writes into the buffer
 * which the TFTP client provides as parameter in its the recvfrom() call).
 */

void _Tftp_Add_interaction_socket(
  int domain,
  int type,
  int protocol,
  int result
);

void _Tftp_Add_interaction_close( int fd, int result );

void _Tftp_Add_interaction_bind( int fd, int family, int result );

void _Tftp_Add_interaction_send_rrq(
  int fd,
  const char *filename,
  uint16_t dest_port,
  const char *dest_addr_str,
  uint16_t block_size,
  uint16_t window_size,
  bool result
);

void _Tftp_Add_interaction_send_wrq(
  int fd,
  const char *filename,
  uint16_t dest_port,
  const char *dest_addr_str,
  uint16_t block_size,
  uint16_t window_size,
  bool result
);

void _Tftp_Add_interaction_send_ack(
  int fd,
  uint16_t block_num,
  uint16_t dest_port,
  const char *dest_addr_str,
  bool result
);

void _Tftp_Add_interaction_send_data(
  int fd,
  uint16_t block_num,
  size_t start,
  size_t len,
  uint8_t (*get_data)( size_t pos ),
  uint16_t dest_port,
  const char *dest_addr_str,
  bool result
);

void _Tftp_Add_interaction_send_error(
  int fd,
  uint16_t error_code,
  uint16_t dest_port,
  const char *dest_addr_str,
  bool result
);

/*
 * _Tftp_Add_interaction_recv_data() permits only a boolean result.
 * The TFTP client code does not check `errno` and always behaves as if
 * a return of -1 indicates a timeout.  Hence
 * _Tftp_Add_interaction_recv_data() permits only a boolean result
 * and no special value to distinct timeouts from other errors.
 */
void _Tftp_Add_interaction_recv_data(
  int fd,
  uint32_t timeout_ms,
  uint16_t src_port,
  const char *src_addr_str,
  uint16_t block_num,
  size_t start,
  size_t len,
  uint8_t (*get_data)( size_t pos ),
  bool result
);

void _Tftp_Add_interaction_recv_ack(
  int fd,
  uint32_t timeout_ms,
  uint16_t src_port,
  const char *src_addr_str,
  uint16_t block_num,
  bool result
);

void _Tftp_Add_interaction_recv_oack(
  int fd,
  uint32_t timeout_ms,
  uint16_t src_port,
  const char *src_addr_str,
  const char *options,
  size_t options_size,
  bool result
);

void _Tftp_Add_interaction_recv_error(
  int fd,
  uint32_t timeout_ms,
  uint16_t src_port,
  const char *src_addr_str,
  uint16_t error_code,
  const char *err_msg,
  bool result
);

/*
 * The TFTP client receives a "raw" packet.
 *
 * Test tests use this function to trigger packet format errors such as:
 *
 *   * Too short packets,
 *   * Strings without 0-byte at their end
 *   * Wrong op-codes
 */
void _Tftp_Add_interaction_recv_raw(
  int fd,
  uint32_t timeout_ms,
  uint16_t src_port,
  const char *src_addr_str,
  size_t len,
  const uint8_t *bytes,
  bool result
);

void _Tftp_Add_interaction_recv_nothing(
  int fd,
  uint32_t timeout_ms
);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* _TFTPFS_INTERACTIONS_H */