Zephyr Project API  3.4.0
A Scalable Open Source RTOS
tftp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 InnBlue
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_NET_TFTP_H_
13#define ZEPHYR_INCLUDE_NET_TFTP_H_
14
15#include <zephyr/kernel.h>
16#include <zephyr/net/socket.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
28#define TFTP_BLOCK_SIZE 512
29
34#define TFTP_HEADER_SIZE 4
35
36/* Maximum amount of data that can be sent or received */
37#define TFTPC_MAX_BUF_SIZE (TFTP_BLOCK_SIZE + TFTP_HEADER_SIZE)
38
39/* TFTP Client Error codes. */
40#define TFTPC_SUCCESS 0
41#define TFTPC_DUPLICATE_DATA -1
42#define TFTPC_BUFFER_OVERFLOW -2
43#define TFTPC_UNKNOWN_FAILURE -3
44#define TFTPC_REMOTE_ERROR -4
45#define TFTPC_RETRIES_EXHAUSTED -5
46
57
63};
64
69};
70
73 char *msg;
74 int code;
75};
76
84
87};
88
90struct tftp_evt {
93
96};
97
106typedef void (*tftp_callback_t)(const struct tftp_evt *evt);
107
115struct tftpc {
118
121
124};
125
126/* @brief This function gets data from a "file" on the remote server.
127 *
128 * @param client Client information of type @ref tftpc.
129 * @param remote_file Name of the remote file to get.
130 * @param mode TFTP Client "mode" setting.
131 *
132 * @return The size of data being received if the operation completed successfully.
133 * TFTPC_BUFFER_OVERFLOW if the file is larger than the user buffer.
134 * TFTPC_REMOTE_ERROR if the server failed to process our request.
135 * TFTPC_RETRIES_EXHAUSTED if the client timed out waiting for server.
136 * -EINVAL if `client` is NULL.
137 *
138 * @note This function blocks until the transfer is completed or network error happens. The
139 * integrity of the `client` structure must be ensured until the function returns.
140 */
142 const char *remote_file, const char *mode);
143
144/* @brief This function puts data to a "file" on the remote server.
145 *
146 * @param client Client information of type @ref tftpc.
147 * @param remote_file Name of the remote file to put.
148 * @param mode TFTP Client "mode" setting.
149 * @param user_buf Data buffer containing the data to put.
150 * @param user_buf_size Length of the data to put.
151 *
152 * @return The size of data being sent if the operation completed successfully.
153 * TFTPC_REMOTE_ERROR if the server failed to process our request.
154 * TFTPC_RETRIES_EXHAUSTED if the client timed out waiting for server.
155 * -EINVAL if `client` or `user_buf` is NULL or if `user_buf_size` is zero.
156 *
157 * @note This function blocks until the transfer is completed or network error happens. The
158 * integrity of the `client` structure must be ensured until the function returns.
159 */
161 const char *remote_file, const char *mode,
162 const uint8_t *user_buf, uint32_t user_buf_size);
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif /* ZEPHYR_INCLUDE_NET_TFTP_H_ */
Public kernel APIs.
struct k_thread client
Definition: main.c:31
BSD Sockets compatible API definitions.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Definition: net_ip.h:347
Parameters for data event.
Definition: tftp.h:66
uint32_t len
Definition: tftp.h:68
uint8_t * data_ptr
Definition: tftp.h:67
Parameters for error event.
Definition: tftp.h:72
char * msg
Definition: tftp.h:73
int code
Definition: tftp.h:74
Defines TFTP asynchronous event notified to the application.
Definition: tftp.h:90
enum tftp_evt_type type
Definition: tftp.h:92
union tftp_evt_param param
Definition: tftp.h:95
TFTP client definition to maintain information relevant to the client.
Definition: tftp.h:115
tftp_callback_t callback
Definition: tftp.h:120
struct sockaddr server
Definition: tftp.h:117
uint8_t tftp_buf[(512+4)]
Definition: tftp.h:123
int tftp_get(struct tftpc *client, const char *remote_file, const char *mode)
tftp_evt_type
TFTP Asynchronous Events notified to the application from the module through the callback registered ...
Definition: tftp.h:51
@ TFTP_EVT_ERROR
Definition: tftp.h:62
@ TFTP_EVT_DATA
Definition: tftp.h:56
#define TFTPC_MAX_BUF_SIZE
Definition: tftp.h:37
int tftp_put(struct tftpc *client, const char *remote_file, const char *mode, const uint8_t *user_buf, uint32_t user_buf_size)
void(* tftp_callback_t)(const struct tftp_evt *evt)
TFTP event notification callback registered by the application.
Definition: tftp.h:106
Defines event parameters notified along with asynchronous events to the application.
Definition: tftp.h:81
struct tftp_error_param error
Definition: tftp.h:86
struct tftp_data_param data
Definition: tftp.h:83