1 /*
2  * Copyright (c) 2020 InnBlue
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* Generic header files required by the TFTPC Module. */
8 #include <zephyr/kernel.h>
9 #include <errno.h>
10 #include <zephyr/net/socket.h>
11 #include <zephyr/net/tftp.h>
12 
13 /* Defines for creating static arrays for TFTP communication. */
14 #define TFTP_MAX_MODE_SIZE       8
15 #define TFTP_REQ_RETX            CONFIG_TFTPC_REQUEST_RETRANSMITS
16 
17 /* Maximum filename size allowed by the TFTP Client. This is used as
18  * an upper bound in the "make_request" function to ensure that there
19  * are no buffer overflows. The complete "tftpc_buffer" has the size of
20  * "TFTPC_MAX_BUF_SIZE" which is used when creating a request. From this
21  * total size, we need 2 bytes for request info, 2 dummy NULL bytes and
22  * "TFTP_MAX_MODE_SIZE" for mode info. Everything else can be used for
23  * filename.
24  */
25 #define TFTP_MAX_FILENAME_SIZE   (TFTPC_MAX_BUF_SIZE - TFTP_MAX_MODE_SIZE - 4)
26 
27 /* TFTP Opcodes. */
28 #define READ_REQUEST             0x1
29 #define WRITE_REQUEST            0x2
30 #define DATA_OPCODE              0x3
31 #define ACK_OPCODE               0x4
32 #define ERROR_OPCODE             0x5
33 
34 /* Error Codes */
35 
36 /** Not defined, see error message (if any). */
37 #define TFTP_ERROR_UNDEF               0
38 /** File not found. */
39 #define TFTP_ERROR_NO_FILE             1
40 /** Access violation. */
41 #define TFTP_ERROR_ACCESS              2
42 /** Disk full or allocation exceeded. */
43 #define TFTP_ERROR_DISK_FULL           3
44 /** Illegal TFTP operation. */
45 #define TFTP_ERROR_ILLEGAL_OP          4
46 /** Unknown transfer ID. */
47 #define TFTP_ERROR_UNKNOWN_TRANSFER_ID 5
48 /** File already exists. */
49 #define TFTP_ERROR_FILE_EXISTS         6
50 /** No such user. */
51 #define TFTP_ERROR_NO_USER             7
52 
53 struct tftphdr_ack {
54 	uint16_t opcode;
55 	uint16_t block;
56 };
57