2 < #define TFTP_RECV_TIMEOUT CFE_HZ*5 /* ticks */
4 > //#define TFTP_RECV_TIMEOUT CFE_HZ*5 /* ticks */
5 > #define TFTP_RECV_TIMEOUT CFE_HZ*1 /* ticks */
8 > unsigned char tftpipfrom[4] = { 0xc0, 0xa8, 0x01, 0x01 };
9 > unsigned char tftpipto[4] = { 0xc0, 0xa8, 0x01, 0x01 };
10 > uint16_t ackport = 7777;
14 > extern int send_rescueack(unsigned short no, unsigned short lo);
18 > #define ip_addriszero(a) (((a)[0]|(a)[1]|(a)[2]|(a)[3]) == 0)
19 > static void ui_myshowifconfig(void)
24 > devname = (char *) net_getparam(NET_DEVNAME);
25 > if (devname == NULL) {
26 > xprintf("Network interface has not been configured\n");
29 > xprintf("Device %s: ",devname);
30 > addr = net_getparam(NET_HWADDR);
32 > xprintf(" hwaddr %a",addr);
33 > addr = net_getparam(NET_IPADDR);
35 > if (ip_addriszero(addr))
36 > xprintf(", ipaddr not set");
38 > xprintf(", ipaddr %I",addr);
40 > addr = net_getparam(NET_NETMASK);
42 > if (ip_addriszero(addr))
43 > xprintf(", mask not set");
45 > xprintf(", mask %I",addr);
49 > addr = net_getparam(NET_GATEWAY);
51 > if (ip_addriszero(addr))
52 > xprintf("gateway not set");
54 > xprintf("gateway %I",addr);
56 > addr = net_getparam(NET_NAMESERVER);
58 > if (ip_addriszero(addr))
59 > xprintf(", nameserver not set");
61 > xprintf(", nameserver %I",addr);
63 > addr = net_getparam(NET_DOMAIN);
65 > xprintf(", domain %s",addr);
72 > if (info->tftp_lastblock) {
73 > xprintf("- Last block -\n");
76 > if (info->tftp_error) {
77 > xprintf("break !! tftp_error !!\n");
78 > return CFE_ERR_TIMEOUT;
84 < if (buf == NULL) continue;
89 > xprintf("break! no netctx or timer expired ! \n");
93 > if (buf == NULL) continue;
97 > xprintf("break!! reach max retry!!\n");
101 > xprintf("- last blk -\n");
107 > uint8_t asuslink[13] = "ASUSSPACELINK";
108 > uint8_t maclink[13]="snxxxxxxxxxxx";
109 > unsigned char tftpmask[4] = { 0xff, 0xff, 0xff, 0x00 };
112 > uint8_t ipaddr[4] = { 0xc0, 0xa8, 0x01, 0x0c };
113 > uint8_t hwaddr[6] = { 0x00, 0xe0, 0x18, 0x00, 0x3e, 0xc4 };
116 < for (retries = 0; retries < tftp_max_retries; retries++) {
118 > for (retries = 0; retries < 2; retries++) {
121 > udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
122 > ackport = buf->eb_usrdata;
123 > memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
124 > info->tftp_blknum = 1;
125 > info->tftp_blklen = 0;
126 > for (i=0; i<13; i++) {
127 > if (buf->eb_ptr[i] != asuslink[i])
131 > tftpipfrom[0]=buf->eb_ptr[16];
132 > tftpipfrom[1]=buf->eb_ptr[15];
133 > tftpipfrom[2]=buf->eb_ptr[14];
134 > tftpipfrom[3]=buf->eb_ptr[13];
135 > tftpipto[0]=buf->eb_usrptr[0];
136 > tftpipto[1]=buf->eb_usrptr[1];
137 > tftpipto[2]=buf->eb_usrptr[2];
138 > tftpipto[3]=buf->eb_usrptr[3];
139 > net_setparam(NET_IPADDR,tftpipfrom);
140 > net_setparam(NET_NETMASK,tftpmask);
141 > net_setparam(NET_GATEWAY,tftpipfrom);
142 > ui_myshowifconfig();
144 > for (i=0; i<4; i++)
145 > ipaddr[i]=tftpipto[i];
146 > for (i=0; i<6; i++)
147 > hwaddr[i]=buf->eb_data[6+i];
150 > res = CFE_ERR_TIMEOUT;
153 > ebuf_append_u16_be(buf, 3);
154 > ebuf_append_u16_be(buf, 1);
155 > ebuf_append_bytes(buf,&tftpnull, 0);
156 > arp_delete(ipaddr);
157 > arp_add(ipaddr,hwaddr);
158 > udp_send(info->tftp_socket, buf, tftpipto);
161 > for (i=0; i<13; i++) {
162 > if (buf->eb_ptr[i] != maclink[i])
166 > tftpipfrom[0]=buf->eb_ptr[16];
167 > tftpipfrom[1]=buf->eb_ptr[15];
168 > tftpipfrom[2]=buf->eb_ptr[14];
169 > tftpipfrom[3]=buf->eb_ptr[13];
170 > tftpipto[0]=buf->eb_usrptr[0];
171 > tftpipto[1]=buf->eb_usrptr[1];
172 > tftpipto[2]=buf->eb_usrptr[2];
173 > tftpipto[3]=buf->eb_usrptr[3];
174 > net_setparam(NET_IPADDR,tftpipfrom);
175 > net_setparam(NET_NETMASK,tftpmask);
176 > net_setparam(NET_GATEWAY,tftpipfrom);
177 > ui_myshowifconfig();
179 > for (i=0; i<4; i++)
180 > ipaddr[i]=tftpipto[i];
181 > for (i=0; i<6; i++)
182 > hwaddr[i]=buf->eb_data[6+i];
185 > res = CFE_ERR_TIMEOUT;
188 > ebuf_append_u16_be(buf, 3);
189 > ebuf_append_u16_be(buf, 1);
190 > ebuf_append_bytes(buf,&tftpnull, 0);
191 > arp_delete(ipaddr);
192 > arp_add(ipaddr,hwaddr);
193 > udp_send(info->tftp_socket, buf, tftpipto);
196 > res = CFE_ERR_TIMEOUT;
202 > xprintf("TFTP Server.\n");
206 > xprintf("TFTP Client.\n");
211 > extern int send_rescueack(unsigned short no, unsigned short lo)
213 > ebuf_t *buf = NULL;
219 > * Open a UDP socket to the TFTP server
221 > acksocket = udp_socket(UDP_PROTO_TFTP);
222 > res = udp_bind(acksocket, 69);
226 > udp_connect(acksocket, ackport);
227 > for (i = 0; i < 1; i++) {
234 > ebuf_append_u16_be(buf, no);
235 > ebuf_append_u16_be(buf, lo);
236 > ebuf_append_bytes(buf,&tftpnull, 0);
237 > udp_send(acksocket ,buf, tftpipto);
241 > udp_close(acksocket);