1/**
2 * \file
3 * \brief TFTP library
4 */
5
6/*
7 * Copyright (c) 2015 ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15
16#ifndef TFTP_H_
17#define TFTP_H_ 1
18
19/*
20 * -------------------------------------------------------------------------------
21 * TFTP Server
22 * -------------------------------------------------------------------------------=
23 */
24
25///< server request callback function
26typedef errval_t(*tfpt_server_cb_f_t)(void);
27
28/**
29 * \brief starts the tftp server on this machine on a given port
30 *
31 * \param ip    ip address to be used
32 * \param port  port to be used
33 * \param cb    callback function called when clients connect
34 *
35 * \return  SYS_ERR_OK on success
36 *          TFTP_ERR_* on failure
37 */
38errval_t tftp_server_accept(char *ip, uint16_t port, tfpt_server_cb_f_t cb);
39
40/**
41 * \brief terminates the tftp server connection
42 *
43 * \return  SYS_ERR_OK on success
44 *          TFTP_ERR_* on failure
45 */
46errval_t tftp_server_terminate(void);
47
48/*
49 * -------------------------------------------------------------------------------
50 * TFTP Client
51 * -------------------------------------------------------------------------------=
52 */
53
54/**
55 * \brief   writes a file over tftp on the established connection
56 *
57 * \param name      name of the remote file to write
58 * \param buf       buffer containing the data
59 * \param buflen    length of the file to write
60 *
61 * \return  SYS_ERR_OK on success
62 *          TFTP_ERR_* on failure
63 */
64errval_t tftp_client_write_file(char *name, void *buf, size_t buflen);
65
66
67/**
68 * \brief   reads a file over tftp on the established connection
69 *
70 * \param path      path of the file to readf rom
71 * \param buf       buffer where to store the contents
72 * \param buflen    maximum length of the buffer
73 * \param ret_size  returns the number of bytes received
74 *
75 * \return  SYS_ERR_OK on success
76 *          TFTP_ERR_* on failure
77 */
78errval_t tftp_client_read_file(char *path, void *buf, size_t buflen, size_t *ret_size);
79
80
81/**
82 * \brief attempts to initialize a new TFTP connection to a server
83 *
84 * \returns SYS_ERR_OK on success
85 *          TFTP_ERR_* on failure
86 */
87errval_t tftp_client_connect(char *ip, uint16_t port);
88
89/**
90 * \brief terminates the connection to the tftp server
91 *
92 * \return SYS_ERR_OK on success
93 *         TFTP_ERR_* on failure
94 */
95errval_t tftp_client_disconnect(void);
96
97
98#endif
99