//==========================================================================
|
//==========================================================================
|
//
|
//
|
// tests/tftp_client_test.c
|
// tests/tftp_client_test.c
|
//
|
//
|
// Simple TFTP client test
|
// Simple TFTP client test
|
//
|
//
|
//==========================================================================
|
//==========================================================================
|
//####BSDCOPYRIGHTBEGIN####
|
//####BSDCOPYRIGHTBEGIN####
|
//
|
//
|
// -------------------------------------------
|
// -------------------------------------------
|
//
|
//
|
// Portions of this software may have been derived from OpenBSD or other sources,
|
// Portions of this software may have been derived from OpenBSD or other sources,
|
// and are covered by the appropriate copyright disclaimers included herein.
|
// and are covered by the appropriate copyright disclaimers included herein.
|
//
|
//
|
// -------------------------------------------
|
// -------------------------------------------
|
//
|
//
|
//####BSDCOPYRIGHTEND####
|
//####BSDCOPYRIGHTEND####
|
//==========================================================================
|
//==========================================================================
|
//#####DESCRIPTIONBEGIN####
|
//#####DESCRIPTIONBEGIN####
|
//
|
//
|
// Author(s): gthomas
|
// Author(s): gthomas
|
// Contributors: gthomas
|
// Contributors: gthomas
|
// Date: 2000-04-07
|
// Date: 2000-04-07
|
// Purpose:
|
// Purpose:
|
// Description:
|
// Description:
|
//
|
//
|
//
|
//
|
//####DESCRIPTIONEND####
|
//####DESCRIPTIONEND####
|
//
|
//
|
//==========================================================================
|
//==========================================================================
|
// TFTP test code
|
// TFTP test code
|
|
|
#include <network.h>
|
#include <network.h>
|
#include <tftp_support.h>
|
#include <tftp_support.h>
|
|
|
// Note: the TFTP client calls need at least (SEGSIZE==512)+4
|
// Note: the TFTP client calls need at least (SEGSIZE==512)+4
|
// additional bytes of workspace, thus the padding.
|
// additional bytes of workspace, thus the padding.
|
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL+0x1000)
|
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL+0x1000)
|
static char stack[STACK_SIZE];
|
static char stack[STACK_SIZE];
|
static cyg_thread thread_data;
|
static cyg_thread thread_data;
|
static cyg_handle_t thread_handle;
|
static cyg_handle_t thread_handle;
|
|
|
#define min(x,y) (x<y ? x : y)
|
#define min(x,y) (x<y ? x : y)
|
|
|
extern void
|
extern void
|
cyg_test_exit(void);
|
cyg_test_exit(void);
|
|
|
void
|
void
|
pexit(char *s)
|
pexit(char *s)
|
{
|
{
|
perror(s);
|
perror(s);
|
cyg_test_exit();
|
cyg_test_exit();
|
}
|
}
|
|
|
static char buf[32*1024];
|
static char buf[32*1024];
|
|
|
#define GETFILE "/tftpboot/tftp_get"
|
#define GETFILE "/tftpboot/tftp_get"
|
#define PUTFILE "/tftpboot/tftp_put"
|
#define PUTFILE "/tftpboot/tftp_put"
|
|
|
static void
|
static void
|
tftp_test(struct bootp *bp)
|
tftp_test(struct bootp *bp)
|
{
|
{
|
int res, err, len;
|
int res, err, len;
|
struct sockaddr_in host;
|
struct sockaddr_in host;
|
|
|
memset((char *)&host, 0, sizeof(host));
|
memset((char *)&host, 0, sizeof(host));
|
host.sin_len = sizeof(host);
|
host.sin_len = sizeof(host);
|
host.sin_family = AF_INET;
|
host.sin_family = AF_INET;
|
host.sin_addr = bp->bp_siaddr;
|
host.sin_addr = bp->bp_siaddr;
|
host.sin_port = 0;
|
host.sin_port = 0;
|
diag_printf("Trying tftp_get %s %16s...\n", GETFILE, inet_ntoa(host.sin_addr));
|
diag_printf("Trying tftp_get %s %16s...\n", GETFILE, inet_ntoa(host.sin_addr));
|
res = tftp_get( GETFILE, &host, buf, sizeof(buf), TFTP_OCTET, &err);
|
res = tftp_get( GETFILE, &host, buf, sizeof(buf), TFTP_OCTET, &err);
|
diag_printf("res = %d, err = %d\n", res, err);
|
diag_printf("res = %d, err = %d\n", res, err);
|
if (res > 0) {
|
if (res > 0) {
|
diag_dump_buf(buf, min(res,1024));
|
diag_dump_buf(buf, min(res,1024));
|
}
|
}
|
len = res;
|
len = res;
|
diag_printf("Trying tftp_put %d %16s, length %d\n",
|
diag_printf("Trying tftp_put %d %16s, length %d\n",
|
PUTFILE, inet_ntoa(host.sin_addr), len);
|
PUTFILE, inet_ntoa(host.sin_addr), len);
|
res = tftp_put( PUTFILE, &host, buf, len, TFTP_OCTET, &err);
|
res = tftp_put( PUTFILE, &host, buf, len, TFTP_OCTET, &err);
|
diag_printf("put - res: %d\n", res);
|
diag_printf("put - res: %d\n", res);
|
}
|
}
|
|
|
void
|
void
|
net_test(cyg_addrword_t param)
|
net_test(cyg_addrword_t param)
|
{
|
{
|
diag_printf("Start TFTP test\n");
|
diag_printf("Start TFTP test\n");
|
init_all_network_interfaces();
|
init_all_network_interfaces();
|
#ifdef CYGHWR_NET_DRIVER_ETH0
|
#ifdef CYGHWR_NET_DRIVER_ETH0
|
if (eth0_up) {
|
if (eth0_up) {
|
tftp_test(ð0_bootp_data);
|
tftp_test(ð0_bootp_data);
|
}
|
}
|
#endif
|
#endif
|
#ifdef CYGHWR_NET_DRIVER_ETH1
|
#ifdef CYGHWR_NET_DRIVER_ETH1
|
if (eth1_up) {
|
if (eth1_up) {
|
tftp_test(ð1_bootp_data);
|
tftp_test(ð1_bootp_data);
|
}
|
}
|
#endif
|
#endif
|
cyg_test_exit();
|
cyg_test_exit();
|
}
|
}
|
|
|
void
|
void
|
cyg_start(void)
|
cyg_start(void)
|
{
|
{
|
// Create a main thread, so we can run the scheduler and have time 'pass'
|
// Create a main thread, so we can run the scheduler and have time 'pass'
|
cyg_thread_create(10, // Priority - just a number
|
cyg_thread_create(10, // Priority - just a number
|
net_test, // entry
|
net_test, // entry
|
0, // entry parameter
|
0, // entry parameter
|
"Network test", // Name
|
"Network test", // Name
|
&stack[0], // Stack
|
&stack[0], // Stack
|
STACK_SIZE, // Size
|
STACK_SIZE, // Size
|
&thread_handle, // Handle
|
&thread_handle, // Handle
|
&thread_data // Thread data structure
|
&thread_data // Thread data structure
|
);
|
);
|
cyg_thread_resume(thread_handle); // Start it
|
cyg_thread_resume(thread_handle); // Start it
|
cyg_scheduler_start();
|
cyg_scheduler_start();
|
}
|
}
|
|
|