OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [common/] [current/] [tests/] [tftp_client_test.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tests/tftp_client_test.c
4
//
5
//      Simple TFTP client test
6
//
7
//==========================================================================
8
// ####BSDALTCOPYRIGHTBEGIN####                                             
9
// -------------------------------------------                              
10
// Portions of this software may have been derived from FreeBSD, OpenBSD,   
11
// or other sources, and if so are covered by the appropriate copyright     
12
// and license included herein.                                             
13
// -------------------------------------------                              
14
// ####BSDALTCOPYRIGHTEND####                                               
15
//==========================================================================
16
//#####DESCRIPTIONBEGIN####
17
//
18
// Author(s):    gthomas
19
// Contributors: gthomas
20
// Date:         2000-04-07
21
// Purpose:      
22
// Description:  
23
//              
24
//
25
//####DESCRIPTIONEND####
26
//
27
//==========================================================================
28
// TFTP test code
29
 
30
#include <network.h>
31
#include <tftp_support.h>
32
 
33
// Note: the TFTP client calls need at least (SEGSIZE==512)+4
34
// additional bytes of workspace, thus the padding.
35
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL+0x1000)
36
static char stack[STACK_SIZE];
37
static cyg_thread thread_data;
38
static cyg_handle_t thread_handle;
39
 
40
#define min(x,y) (x<y ? x : y)
41
 
42
extern void
43
cyg_test_exit(void);
44
 
45
void
46
pexit(char *s)
47
{
48
    perror(s);
49
    cyg_test_exit();
50
}
51
 
52
static char buf[32*1024];
53
 
54
#define GETFILE "/tftpboot/tftp_get"
55
#define PUTFILE "/tftpboot/tftp_put"
56
 
57
static void
58
tftp_test(struct bootp *bp)
59
{
60
    int res, err, len;
61
    struct sockaddr_in host;
62
#ifdef CYGPKG_NET_INET6
63
    struct sockaddr_in6 ipv6router;
64
    char server[64];
65
#endif
66
 
67
    memset((char *)&host, 0, sizeof(host));
68
    host.sin_len = sizeof(host);
69
    host.sin_family = AF_INET;
70
    host.sin_addr = bp->bp_siaddr;
71
    host.sin_port = 0;
72
    diag_printf("Trying tftp_get %s %16s...\n", GETFILE, inet_ntoa(host.sin_addr));
73
    res = tftp_get( GETFILE, &host, buf, sizeof(buf), TFTP_OCTET, &err);
74
    diag_printf("res = %d, err = %d\n", res, err);
75
    if (res > 0) {
76
        diag_dump_buf(buf, min(res,1024));
77
    }
78
    len = res;
79
    diag_printf("Trying tftp_put %s %16s, length %d\n",
80
                PUTFILE, inet_ntoa(host.sin_addr), len);
81
    res = tftp_put( PUTFILE, &host, buf, len, TFTP_OCTET, &err);
82
    diag_printf("put - res: %d\n", res);
83
 
84
#ifdef CYGPKG_NET_INET6
85
    // Wait for router solicit process to happen.
86
    if (!cyg_net_get_ipv6_advrouter(&ipv6router)) {
87
      diag_printf("No router advertisement recieved\n");
88
      cyg_test_exit();
89
    }
90
 
91
    getnameinfo((struct sockaddr *)&ipv6router,sizeof(ipv6router),
92
                server, sizeof(server), 0 ,0 ,NI_NUMERICHOST);
93
 
94
    diag_printf("Trying tftp_get %s using IPv6 from %16s...\n", GETFILE, server);
95
 
96
    res = tftp_client_get( GETFILE, server, 0, buf, sizeof(buf),
97
                           TFTP_OCTET, &err);
98
    diag_printf("IPv6 res = %d, err = %d\n", res, err);
99
    if (res > 0) {
100
        diag_dump_buf(buf, min(res,1024));
101
    }
102
    len = res;
103
    diag_printf("Trying tftp_put %s using IPv6 to %16s, length %d\n",
104
                PUTFILE, server, len);
105
    res = tftp_client_put( PUTFILE, server, 0, buf, len, TFTP_OCTET, &err);
106
    diag_printf("put - res: %d\n", res);
107
#endif
108
}
109
 
110
void
111
net_test(cyg_addrword_t param)
112
{
113
    diag_printf("Start TFTP test\n");
114
    init_all_network_interfaces();
115
#ifdef CYGHWR_NET_DRIVER_ETH0
116
    if (eth0_up) {
117
        tftp_test(&eth0_bootp_data);
118
    }
119
#endif
120
#ifdef CYGHWR_NET_DRIVER_ETH1
121
    if (eth1_up) {
122
        tftp_test(&eth1_bootp_data);
123
    }
124
#endif
125
    cyg_test_exit();
126
}
127
 
128
void
129
cyg_start(void)
130
{
131
    // Create a main thread, so we can run the scheduler and have time 'pass'
132
    cyg_thread_create(10,                // Priority - just a number
133
                      net_test,          // entry
134
                      0,                 // entry parameter
135
                      "Network test",    // Name
136
                      &stack[0],         // Stack
137
                      STACK_SIZE,        // Size
138
                      &thread_handle,    // Handle
139
                      &thread_data       // Thread data structure
140
            );
141
    cyg_thread_resume(thread_handle);  // Start it
142
    cyg_scheduler_start();
143
}
144
 
145
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.