1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
//==========================================================================
//
// tests/tftp_server_test.c
//
// Simple TFTP server test
//
//==========================================================================
// ####BSDALTCOPYRIGHTBEGIN####
// -------------------------------------------
// Portions of this software may have been derived from FreeBSD, OpenBSD,
// or other sources, and if so are covered by the appropriate copyright
// and license included herein.
// -------------------------------------------
// ####BSDALTCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2000-04-07
// Purpose:
// Description:
//
//
//####DESCRIPTIONEND####
//
//==========================================================================
// TFTP test code
#include <pkgconf/system.h>
#include <pkgconf/net.h>
#ifdef CYGBLD_DEVS_ETH_DEVICE_H // Get the device config if it exists
#include CYGBLD_DEVS_ETH_DEVICE_H // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
#endif
#ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
# ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
# include CYGTST_DEVS_ETH_TEST_NET_REALTIME
# endif
#endif
// Fill in the blanks if necessary
#ifndef TNR_OFF
# define TNR_OFF()
#endif
#ifndef TNR_ON
# define TNR_ON()
#endif
#ifndef TNR_INIT
# define TNR_INIT()
#endif
#ifndef TNR_PRINT_ACTIVITY
# define TNR_PRINT_ACTIVITY()
#endif
// ------------------------------------------------------------------------
#include <network.h>
#include <tftp_support.h>
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
static char stack[STACK_SIZE];
static cyg_thread thread_data;
static cyg_handle_t thread_handle;
extern void
cyg_test_exit(void);
void
pexit(char *s)
{
perror(s);
cyg_test_exit();
}
static void
tftp_test(struct bootp *bp)
{
int res;
int server1_id = 0;
int server2_id = 0;
int server3_id = 0;
extern struct tftpd_fileops dummy_fileops;
server1_id = tftpd_start(0, &dummy_fileops);
if (server1_id > 0) {
diag_printf("TFTP server created - id: %x\n", server1_id);
} else {
diag_printf("Couldn't create first server!\n");
}
#ifdef CYGSEM_NET_TFTPD_MULTITHREADED
server2_id = tftpd_start(0, &dummy_fileops);
if (server2_id > 0) {
diag_printf("Second TFTP server created - id: %x\n", server2_id);
} else {
diag_printf("Couldn't create a second server!\n");
}
#if CYGNUM_NET_TFTPD_MULTITHREADED_PORTS > 1
server3_id = tftpd_start(1025, &dummy_fileops);
if (server3_id > 0) {
diag_printf("Third TFTP server created - id: %x\n", server3_id);
} else {
diag_printf("Couldn't create a third server!\n");
}
#endif //CYGNUM_NET_TFTPD_MULTITHREADED_PORTS > 1
#else //CYGSEM_NET_TFTPD_MULTITHREADED
server2_id = tftpd_start(1025, &dummy_fileops);
if (server2_id > 0) {
diag_printf("Second TFTP server created - id: %x\n", server2_id);
} else {
diag_printf("Couldn't create a second server!\n");
}
#endif //!CYGSEM_NET_TFTPD_MULTITHREADED
// Only let the server run for 5 minutes
cyg_thread_delay(2*100); // let the tftpd start up first
TNR_ON();
cyg_thread_delay(5*60*100);
TNR_OFF();
if (server1_id > 0) {
res = tftpd_stop(server1_id);
diag_printf("TFTP server - id: %x stopped - res: %d\n", server1_id, res);
}
if (server2_id > 0) {
res = tftpd_stop(server2_id);
diag_printf("TFTP server - id: %x stopped - res: %d\n", server2_id, res);
}
if (server3_id > 0) {
res = tftpd_stop(server2_id);
diag_printf("TFTP server - id: %x stopped - res: %d\n", server2_id, res);
}
}
void
net_test(cyg_addrword_t param)
{
diag_printf("Start TFTP server test\n");
init_all_network_interfaces();
TNR_INIT();
#ifdef CYGHWR_NET_DRIVER_ETH0
if (eth0_up) {
tftp_test(ð0_bootp_data);
}
#else
if ( 0 ) ;
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
else if (eth1_up) {
tftp_test(ð1_bootp_data);
}
#endif
TNR_PRINT_ACTIVITY();
cyg_test_exit();
}
void
cyg_start(void)
{
// Create a main thread, so we can run the scheduler and have time 'pass'
cyg_thread_create(10, // Priority - just a number
net_test, // entry
0, // entry parameter
"Network test", // Name
&stack[0], // Stack
STACK_SIZE, // Size
&thread_handle, // Handle
&thread_data // Thread data structure
);
cyg_thread_resume(thread_handle); // Start it
cyg_scheduler_start();
}
// EOF tftp_server_test.c
|