36#include <sys/socket.h>
42#ifdef LOSCFG_NET_LWIP_SACK_TFTP
45 "TFTP transfer finish\n",
46 "Error while creating UDP socket\n",
47 "Error while binding to the UDP socket\n",
48 "Error returned by select() system call\n",
49 "Error while receiving data from the peer\n",
50 "Error while sending data to the peer\n",
51 "Requested file is not found\n",
52 "This is the error sent by the server when hostname cannot be resolved\n",
53 "Input parameters passed to TFTP interfaces are invalid\n",
54 "Error detected in TFTP packet or the error received from the TFTP server\n",
55 "Error during packet synhronization while sending or unexpected packet is received\n",
56 "File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes\n",
57 "File name length greater than 256\n",
58 "Hostname IP is not valid\n",
59 "TFTP server returned file access error\n",
60 "TFTP server returned error signifying that the DISK is full to write\n",
61 "TFTP server returned error signifying that the file exist\n",
62 "The source file name do not exisits\n",
63 "Memory allocaion failed in TFTP client\n",
66 "File create error\n",
68 "Max time expired while waiting for file to be recived\n",
69 "Error when the received packet is less than 4bytes(error length) or greater than 512bytes\n",
70 "Returned by TFTP server for protocol user error\n",
71 "The destination file path length greater than 256\n",
72 "Returned by TFTP server for undefined transfer ID\n",
73 "IOCTL function failed at TFTP client while setting the socket to non-block\n",
77#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
82 u32_t ulRemoteAddr = IPADDR_NONE;
83 const u16_t usTftpServPort = 69;
85 s8_t *szLocalFileName = NULL;
86 s8_t *szRemoteFileName = NULL;
90 if (argc < 1 || argv == NULL) {
95 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
100 if (strcmp(argv[i],
"-p") == 0) {
106 if (strcmp(argv[i],
"-g") == 0) {
112 if (strcmp(argv[i],
"-l") == 0 && ((i + 1) < argc)) {
113 szLocalFileName = (s8_t *)argv[i + 1];
118 if (strcmp(argv[i],
"-r") == 0 && ((i + 1) < argc)) {
119 szRemoteFileName = (s8_t *)argv[i + 1];
124 if ((i + 1) == argc) {
132 if (ulRemoteAddr == IPADDR_NONE || szLocalFileName == NULL || szRemoteFileName == NULL) {
138 TRANSFER_MODE_BINARY, szRemoteFileName, szLocalFileName);
141 TRANSFER_MODE_BINARY, szLocalFileName, szRemoteFileName);
144 LWIP_ASSERT(
"TFTP UNKNOW ERROR!", ret < ARRAY_SIZE(
TftpError));
152 PRINTK(
"usage:\nTransfer a file from/to tftp server\n");
153 PRINTK(
"tftp <-g/-p> -l FullPathLocalFile -r RemoteFile Host\n");
157#ifdef LOSCFG_SHELL_CMD_DEBUG
@ CMD_TYPE_EX
不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。
SHELLCMD_ENTRY(tftp_shellcmd, CMD_TYPE_EX, "tftp", XARGS,(CmdCallBackFunc)(uintptr_t) osShellTftp)
static char * TftpError[]
u32_t osShellTftp(int argc, const char **argv)
static int tcpip_init_finish
in_addr_t inet_addr(const char *cp)
u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr, u16_t usTftpServPort, u8_t ucTftpTransMode, s8_t *szSrcFileName, s8_t *szDestDirPath)
u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr, u16_t usTftpServPort, u8_t ucTftpTransMode, s8_t *szSrcFileName, s8_t *szDestDirPath)
u32_t(* CmdCallBackFunc)(u32_t argc, const char **argv)