9
0
Fork 0

Added basic TFTP client support

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@879 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-09-05 22:47:42 +00:00
parent fe86e5537a
commit 260da65476
9 changed files with 101 additions and 17 deletions

View File

@ -449,4 +449,5 @@
* NSH: Add ping command
* Correct IP checksum calculation in ICMP and UDP message send logic.
* NSH: Created an HTML document and a more detailed README file describing NSH.
* Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in.

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
<p>Last Updated: September 3, 2008</p>
<p>Last Updated: September 5, 2008</p>
</td>
</tr>
</table>
@ -1076,6 +1076,7 @@ nuttx-0.3.14 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
* NSH: Add ping command
* Correct IP checksum calculation in ICMP and UDP message send logic.
* NSH: Created an HTML document and a more detailed README file describing NSH.
* Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in.
pascal-0.1.3 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;

View File

@ -0,0 +1,73 @@
/****************************************************************************
* include/net/uip/tftp.h
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
****************************************************************************/
#ifndef __NET_UIP_TFTP_H
#define __NET_UIP_TFTP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
#include <arpa/inet.h>
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Public Type Definitions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
EXTERN int tftpget(const char *remote, const char *local, in_addr_t addr, boolean binary);
EXTERN int tftpput(const char *local, const char *remote, in_addr_t addr, boolean binary);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __NET_UIP_TFTP_H */

View File

@ -116,6 +116,12 @@
# endif
#endif
/* The UDP maximum packet size. This is should not be to set to more
* than CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN.
*/
#define UIP_UDP_MSS (CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN)
/* TCP configuration options */
/* The maximum number of simultaneously open TCP connections.
@ -175,10 +181,8 @@
#define UIP_MAXSYNRTX 5
/* The TCP maximum segment size.
*
* This is should not be to set to more than
* CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
/* The TCP maximum segment size. This is should not be to set to more
* than CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
*/
#define UIP_TCP_MSS (CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)

View File

@ -47,17 +47,22 @@ ifeq ($(CONFIG_NET_UDP),y)
include dhcpc/Make.defs
include dhcpd/Make.defs
include resolv/Make.defs
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
include tftpc/Make.defs
endif
endif
endif
SUBDIRS = uiplib dhcpc dhcpd resolv smtp telnetd webclient webserver
SUBDIRS = uiplib dhcpc dhcpd resolv smtp telnetd webclient webserver tftpc
ASRCS = $(UIPLIB_ASRCS) $(DHCPC_ASRCS) $(DHCPD_ASRCS) $(RESOLV_ASRCS) \
$(SMTP_ASRCS) $(TELNETD_ASRCS) $(WEBCLIENT_ASRCS) $(WEBSERVER_ASRCS)
$(SMTP_ASRCS) $(TELNETD_ASRCS) $(WEBCLIENT_ASRCS) $(WEBSERVER_ASRCS) \
$(TFTPC_ASRCS)
AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = $(UIPLIB_CSRCS) $(DHCPC_CSRCS) $(DHCPD_CSRCS) $(RESOLV_CSRCS) \
$(SMTP_CSRCS) $(TELNETD_CSRCS) $(WEBCLIENT_CSRCS) $(WEBSERVER_CSRCS)
$(SMTP_CSRCS) $(TELNETD_CSRCS) $(WEBCLIENT_CSRCS) $(WEBSERVER_CSRCS) \
$(TFTPC_CSRCS)
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
@ -65,7 +70,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libnetutils$(LIBEXT)
VPATH = uiplib:dhcpc:dhcpd:resolv:smtp:telnetd:webclient:webserver
VPATH = uiplib:dhcpc:dhcpd:resolv:smtp:telnetd:webclient:webserver:tftpc
all: $(BIN)
@ -84,7 +89,7 @@ $(BIN): $(OBJS)
ifeq ($(CONFIG_NET),y)
@$(MKDEP) --dep-path . --dep-path uiplib --dep-path dhcpc --dep-path dhcpd \
--dep-path smtp --dep-path webclient --dep-path resolv \
--dep-path telnetd --dep-path webserver \
--dep-path telnetd --dep-path webserver --dep-path tftpc \
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
endif
@touch $@

View File

@ -120,7 +120,7 @@ static inline int tftp_parsedatapacket(const ubyte *packet,
*blockno = (uint16)packet[2] << 8 | (uint16)packet[3];
return OK;
}
#if CONFIG_DEBUG
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
else if (*opcode == TFTP_ERR)
{
(void)tftp_parseerrpacket(packet);

View File

@ -142,7 +142,7 @@
* Public Data
****************************************************************************/
#if CONFIG_DEBUG
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
extern const char g_tftpcallfailed[];
extern const char g_tftpcalltimedout[];
extern const char g_tftpnomemory[];
@ -161,7 +161,7 @@ extern int tftp_sockinit(struct sockaddr_in *server, in_addr_t addr);
extern int tftp_mkreqpacket(ubyte *buffer, int opcode, const char *path, boolean binary);
extern int tftp_mkackpacket(ubyte *buffer, uint16 blockno);
extern int tftp_mkerrpacket(ubyte *buffer, uint16 errorcode, const char *errormsg);
#if CONFIG_DEBUG
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
extern int tftp_parseerrpacket(const ubyte *packet);
#endif

View File

@ -70,7 +70,7 @@
* Public Data
****************************************************************************/
#if CONFIG_DEBUG
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
const char g_tftpcallfailed[] = "%s failed: %d\n";
const char g_tftpcalltimedout[] = "%s timed out\n";
const char g_tftpnomemory[] = "%s memory allocation failure\n";
@ -217,7 +217,7 @@ int tftp_mkerrpacket(ubyte *buffer, uint16 errorcode, const char *errormsg)
*
****************************************************************************/
#ifdef CONFIG_DEBUG
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
int tftp_parseerrpacket(const ubyte *buffer)
{
uint16 opcode = (uint16)buffer[0] << 8 | (uint16)buffer[1];

View File

@ -269,7 +269,7 @@ static int tftp_rcvack(int sd, ubyte *packet, struct sockaddr_in *server,
if (opcode != TFTP_ACK)
{
nvdbg("Bad opcode%d\n");
#if CONFIG_DEBUG
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
if (opcode == TFTP_ERR)
{
(void)tftp_parseerrpacket(packet);
@ -330,7 +330,6 @@ int tftpput(const char *local, const char *remote, in_addr_t addr, boolean binar
int sd; /* Socket descriptor for socket I/O */
int fd; /* File descriptor for file I/O */
int result = ERROR; /* Assume failure */
int tmp; /* For temporary usage */
int ret; /* Generic return status */
#if CONFIG_NETUTILS_TFTP_ACKPACKETS > 1
@ -338,6 +337,7 @@ int tftpput(const char *local, const char *remote, in_addr_t addr, boolean binar
int head; /* Head index into offsets[] */
int tail; /* Tail index into offsets[] */
int hblockno; /* Block number at the head of offsets[] */
int tmp; /* For temporary usage */
#else
off_t offset; /* Offset into source file */
off_t next; /* Offset to the next block */