Quellcode durchsuchen

Add TFTP server README.

armink vor 8 Jahren
Ursprung
Commit
222bbeb4de
7 geänderte Dateien mit 264 neuen und 2 gelöschten Zeilen
  1. BIN
      images/tftpd_cfg.png
  2. BIN
      images/tftpd_get.png
  3. BIN
      images/tftpd_put.png
  4. 63 1
      tftp/README.md
  5. 107 0
      tftp/tftp_opts.h
  6. 0 1
      tftp/tftp_port.c
  7. 94 0
      tftp/tftp_server.h

BIN
images/tftpd_cfg.png


BIN
images/tftpd_get.png


BIN
images/tftpd_put.png


+ 63 - 1
tftp/README.md

@@ -1 +1,63 @@
-Coming soon...
+# TFTP:简单文件传输协议
+
+## 1、介绍
+
+[TFTP](https://baike.baidu.com/item/TFTP) (Trivial File Transfer Protocol, 简单文件传输协议)是 TCP/IP 协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务,端口号为 **69** ,比传统的 FTP 协议要轻量级很多,适用于小型的嵌入式产品上。
+
+RT-Thread 目前支持的是 TFTP 服务器。
+
+## 2、使用
+
+### 2.1 安装 TFTP 客户端
+
+安装文件位于 `/tools/Tftpd64-4.60-setup.exe` ,使用 TFTP 前,请先安装该软件。
+
+### 2.2 启动 TFTP 服务器
+
+在传输文件前,需要在 RT-Thread 上使用 Finsh/MSH 命令来启动 TFTP 服务器,大致效果如下:
+
+```
+msh />tftp_server
+TFTP server start successfully.
+msh />
+```
+
+### 2.3 传输文件
+
+打开刚安装的 `Tftpd64` 软件,按如下操作进行配置:
+
+- 1、选择 `Tftp Client` ;
+- 2、在 `Server interfaces` 下拉框中,务必选择好与 RT-Thread 处于同一网段的网卡;
+- 3、填写 TFTP 服务器的 IP 地址。可以使用 `ifconfig` 命令查看;
+- 4、填写 TFTP 服务器端口号,默认: `69` 
+
+![tftpd_cfg](../images/tftpd_cfg.png)
+
+#### 2.3.1 发送文件到 RT-Thread
+
+- 1、在 `Tftpd64` 软件中,选择好要发送文件;
+- 2、`Remote File` 是服务器端保存文件的路径(包括文件名),选项支持相对路径和绝对路径。由于 RT-Thread 默认开启 `DFS_USING_WORKDIR` 选项,此时相对路径是基于 Finsh/MSH 当前进入的目录。所以,使用相对路径时,务必提前切换好目录;
+- 3、点击 `Put` 按钮即可。
+
+如下图所示,将文件发送至 Finsh/MSH 当前进入的目录下,这里使用的是 **相对路径** :
+
+![tftpd_put](../images/tftpd_put.png)
+
+> 注意:如果 `DFS_USING_WORKDIR` 未开启,同时 `Remote File` 为空,文件会将保存至根路径下。
+
+#### 2.3.2 从 RT-Thread 接收文件
+
+- 1、在 `Tftpd64` 软件中,填写好要接收保存的文件路径(包含文件名);
+- 2、`Remote File` 是服务器端待接收回来的文件路径(包括文件名),选项支持相对路径和绝对路径。由于 RT-Thread 默认开启 `DFS_USING_WORKDIR` 选项,此时相对路径是基于 Finsh/MSH 当前进入的目录。所以,使用相对路径时,务必提前切换好目录;
+- 3、点击 `Get` 按钮即可。
+
+如下所示,将 `/web_root/image.jpg` 保存到本地,这里使用的是 **绝对路径** :
+
+```
+msh /web_root>ls           ##查看文件是否存在
+Directory /web_root:
+image.jpg           10559                    
+msh /web_root>
+```
+
+![tftpd_get](../images/tftpd_get.png)

+ 107 - 0
tftp/tftp_opts.h

@@ -0,0 +1,107 @@
+/****************************************************************//**
+ *
+ * @file tftp_opts.h
+ *
+ * @author   Logan Gunthorpe <logang@deltatee.com>
+ *
+ * @brief    Trivial File Transfer Protocol (RFC 1350) implementation options
+ *
+ * Copyright (c) Deltatee Enterprises Ltd. 2013
+ * All rights reserved.
+ *
+ ********************************************************************/
+
+/* 
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * Author: Logan Gunthorpe <logang@deltatee.com>
+ *
+ */
+
+#ifndef LWIP_HDR_APPS_TFTP_OPTS_H
+#define LWIP_HDR_APPS_TFTP_OPTS_H
+
+#include <rtthread.h>
+
+/**
+ * @defgroup tftp_opts Options
+ * @ingroup tftp
+ * @{
+ */
+
+/**
+ * Enable TFTP debug messages
+ */
+#if !defined TFTP_DEBUG
+#define TFTP_DEBUG            LWIP_DBG_ON
+#endif
+
+/**
+ * TFTP server port
+ */
+#if defined PKG_NETUTILS_TFTP_PORT
+#define TFTP_PORT             PKG_NETUTILS_TFTP_PORT
+#elif !defined TFTP_PORT
+#define TFTP_PORT             69
+#endif
+
+/**
+ * TFTP timeout
+ */
+#if !defined TFTP_TIMEOUT_MSECS
+#define TFTP_TIMEOUT_MSECS    10000
+#endif
+
+/**
+ * Max. number of retries when a file is read from server
+ */
+#if !defined TFTP_MAX_RETRIES
+#define TFTP_MAX_RETRIES      5
+#endif
+
+/**
+ * TFTP timer cyclic interval
+ */
+#if !defined TFTP_TIMER_MSECS
+#define TFTP_TIMER_MSECS      50
+#endif
+
+/**
+ * Max. length of TFTP filename
+ */
+#if !defined TFTP_MAX_FILENAME_LEN
+#define TFTP_MAX_FILENAME_LEN 20
+#endif
+
+/**
+ * Max. length of TFTP mode
+ */
+#if !defined TFTP_MAX_MODE_LEN
+#define TFTP_MAX_MODE_LEN     7
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* LWIP_HDR_APPS_TFTP_OPTS_H */

+ 0 - 1
tftp/tftp_port.c

@@ -22,7 +22,6 @@
  * 2017-08-17     armink       first version.
  */
 
-
 #include <rtthread.h>
 #include <dfs_posix.h>
 #include <lwip/apps/tftp_server.h>

+ 94 - 0
tftp/tftp_server.h

@@ -0,0 +1,94 @@
+/****************************************************************//**
+ *
+ * @file tftp_server.h
+ *
+ * @author   Logan Gunthorpe <logang@deltatee.com>
+ *
+ * @brief    Trivial File Transfer Protocol (RFC 1350)
+ *
+ * Copyright (c) Deltatee Enterprises Ltd. 2013
+ * All rights reserved.
+ *
+ ********************************************************************/
+
+/* 
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * Author: Logan Gunthorpe <logang@deltatee.com>
+ *
+ */
+
+#ifndef LWIP_HDR_APPS_TFTP_SERVER_H
+#define LWIP_HDR_APPS_TFTP_SERVER_H
+
+#include "tftp_opts.h"
+#include "lwip/err.h"
+#include "lwip/pbuf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @ingroup tftp
+ * TFTP context containing callback functions for TFTP transfers
+ */
+struct tftp_context {
+  /**
+   * Open file for read/write.
+   * @param fname Filename
+   * @param mode Mode string from TFTP RFC 1350 (netascii, octet, mail)
+   * @param write Flag indicating read (0) or write (!= 0) access
+   * @returns File handle supplied to other functions
+   */
+  void* (*open)(const char* fname, const char* mode, u8_t write);
+  /**
+   * Close file handle
+   * @param handle File handle returned by open()
+   */
+  void (*close)(void* handle);
+  /**
+   * Read from file 
+   * @param handle File handle returned by open()
+   * @param buf Target buffer to copy read data to
+   * @param bytes Number of bytes to copy to buf
+   * @returns &gt;= 0: Success; &lt; 0: Error
+   */
+  int (*read)(void* handle, void* buf, int bytes);
+  /**
+   * Write to file
+   * @param handle File handle returned by open()
+   * @param pbuf PBUF adjusted such that payload pointer points
+   *             to the beginning of write data. In other words,
+   *             TFTP headers are stripped off.
+   * @returns &gt;= 0: Success; &lt; 0: Error
+   */
+  int (*write)(void* handle, struct pbuf* p);
+};
+
+err_t tftp_init(const struct tftp_context* ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LWIP_HDR_APPS_TFTP_SERVER_H */