2020-04-22 01:40:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 InnBlue
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Generic header files required by the TFTPC Module. */
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2020-04-22 01:40:18 +02:00
|
|
|
#include <errno.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/net/socket.h>
|
2023-02-10 01:39:19 +01:00
|
|
|
#include <zephyr/net/tftp.h>
|
2020-04-22 01:40:18 +02:00
|
|
|
|
|
|
|
/* Defines for creating static arrays for TFTP communication. */
|
|
|
|
#define TFTP_MAX_MODE_SIZE 8
|
|
|
|
#define TFTP_REQ_RETX CONFIG_TFTPC_REQUEST_RETRANSMITS
|
|
|
|
|
|
|
|
/* Maximum filename size allowed by the TFTP Client. This is used as
|
|
|
|
* an upper bound in the "make_request" function to ensure that there
|
|
|
|
* are no buffer overflows. The complete "tftpc_buffer" has the size of
|
|
|
|
* "TFTPC_MAX_BUF_SIZE" which is used when creating a request. From this
|
|
|
|
* total size, we need 2 bytes for request info, 2 dummy NULL bytes and
|
|
|
|
* "TFTP_MAX_MODE_SIZE" for mode info. Everything else can be used for
|
|
|
|
* filename.
|
|
|
|
*/
|
|
|
|
#define TFTP_MAX_FILENAME_SIZE (TFTPC_MAX_BUF_SIZE - TFTP_MAX_MODE_SIZE - 4)
|
|
|
|
|
|
|
|
/* TFTP Opcodes. */
|
|
|
|
#define READ_REQUEST 0x1
|
|
|
|
#define WRITE_REQUEST 0x2
|
|
|
|
#define DATA_OPCODE 0x3
|
|
|
|
#define ACK_OPCODE 0x4
|
|
|
|
#define ERROR_OPCODE 0x5
|
|
|
|
|
2021-06-27 21:34:26 +02:00
|
|
|
/* Error Codes */
|
|
|
|
|
|
|
|
/** Not defined, see error message (if any). */
|
|
|
|
#define TFTP_ERROR_UNDEF 0
|
|
|
|
/** File not found. */
|
|
|
|
#define TFTP_ERROR_NO_FILE 1
|
|
|
|
/** Access violation. */
|
|
|
|
#define TFTP_ERROR_ACCESS 2
|
|
|
|
/** Disk full or allocation exceeded. */
|
|
|
|
#define TFTP_ERROR_DISK_FULL 3
|
|
|
|
/** Illegal TFTP operation. */
|
|
|
|
#define TFTP_ERROR_ILLEGAL_OP 4
|
|
|
|
/** Unknown transfer ID. */
|
|
|
|
#define TFTP_ERROR_UNKNOWN_TRANSFER_ID 5
|
|
|
|
/** File already exists. */
|
|
|
|
#define TFTP_ERROR_FILE_EXISTS 6
|
|
|
|
/** No such user. */
|
|
|
|
#define TFTP_ERROR_NO_USER 7
|
|
|
|
|
|
|
|
struct tftphdr_ack {
|
|
|
|
uint16_t opcode;
|
|
|
|
uint16_t block;
|
|
|
|
};
|