RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / net / ref
blob7aac86eb6d15285af05c857b1139d1a45603ada5
1 92c92,99
2 < #define TFTP_RECV_TIMEOUT     CFE_HZ*5        /* ticks */
3 ---
4 > //#define TFTP_RECV_TIMEOUT   CFE_HZ*5        /* ticks */
5 > #define TFTP_RECV_TIMEOUT     CFE_HZ*1        /* ticks */
6
7 > #ifdef RESCUE_MODE
8 > unsigned char tftpipfrom[4] = { 0xc0, 0xa8, 0x01, 0x01 };
9 > unsigned char tftpipto[4] = { 0xc0, 0xa8, 0x01, 0x01 };
10 > uint16_t ackport = 7777;
11 > #endif
12 126a134,136
13 > #ifdef RESCUE_MODE
14 > extern int send_rescueack(unsigned short no, unsigned short lo);
15 > #endif
16 151a162,214
17 > #ifdef RESCUE_MODE
18 > #define ip_addriszero(a) (((a)[0]|(a)[1]|(a)[2]|(a)[3]) == 0)
19 > static void ui_myshowifconfig(void)
20 > {
21 >         char *devname;
22 >         uint8_t *addr;
23
24 >         devname = (char *) net_getparam(NET_DEVNAME);
25 >         if (devname == NULL) {
26 >                 xprintf("Network interface has not been configured\n");
27 >                 return;
28 >         }
29 >         xprintf("Device %s: ",devname);
30 >         addr = net_getparam(NET_HWADDR);
31 >         if (addr)
32 >                 xprintf(" hwaddr %a",addr);
33 >         addr = net_getparam(NET_IPADDR);
34 >         if (addr) {
35 >                 if (ip_addriszero(addr))
36 >                         xprintf(", ipaddr not set");
37 >                 else
38 >                         xprintf(", ipaddr %I",addr);
39 >         }
40 >         addr = net_getparam(NET_NETMASK);
41 >         if (addr) {
42 >                 if (ip_addriszero(addr))
43 >                         xprintf(", mask not set");
44 >                 else
45 >                         xprintf(", mask %I",addr);
46 >         }
47 >         xprintf("\n");
48 >         xprintf("        ");
49 >         addr = net_getparam(NET_GATEWAY);
50 >         if (addr) {
51 >                 if (ip_addriszero(addr))
52 >                         xprintf("gateway not set");
53 >                 else
54 >                         xprintf("gateway %I",addr);
55 >         }
56 >         addr = net_getparam(NET_NAMESERVER);
57 >         if (addr) {
58 >                 if (ip_addriszero(addr))
59 >                         xprintf(", nameserver not set");
60 >         else
61 >                 xprintf(", nameserver %I",addr);
62 >         }
63 >         addr = net_getparam(NET_DOMAIN);
64 >         if (addr) {
65 >                 xprintf(", domain %s",addr);
66 >         }
67 >         xprintf("\n");
68 > }
69 > #endif
70 311a375,384
71 > #ifdef RESCUE_MODE
72 >     if (info->tftp_lastblock) {
73 >         xprintf("- Last block -\n");
74 >         return 1;
75 >     }
76 >     if (info->tftp_error) {
77 >         xprintf("break !! tftp_error !!\n");
78 >         return CFE_ERR_TIMEOUT;
79 >     }
80 > #else
81 313a387
82 > #endif
83 337c411,419
84 <       if (buf == NULL) continue;
85 ---
86 > #ifdef RESCUE_MODE
87 >         if (!buf)
88 >         {
89 >                 xprintf("break! no netctx or timer expired ! \n");
90 >                 continue;
91 >         }
92 > #else
93 >         if (buf == NULL) continue;
94 > #endif
95 370a453,455
96 > #ifdef RESCUE_MODE
97 >         xprintf("break!! reach max retry!!\n");
98 > #endif
99 375a461,463
100 > #ifdef RESCUE_MODE
101 >         xprintf("- last blk -\n");
102 > #endif
103 413d500
105 490a578,586
106 > #ifdef RESCUE_MODE
107 >         uint8_t asuslink[13] = "ASUSSPACELINK";
108 >         uint8_t maclink[13]="snxxxxxxxxxxx";
109 >         unsigned char tftpmask[4] = { 0xff, 0xff, 0xff, 0x00 };
110 >         int i;
111 >         char tftpnull;
112 >         uint8_t ipaddr[4] = { 0xc0, 0xa8, 0x01, 0x0c };
113 >         uint8_t hwaddr[6] = { 0x00, 0xe0, 0x18, 0x00, 0x3e, 0xc4 };
114 > #endif
115 510c606
116 <     for (retries = 0; retries < tftp_max_retries; retries++) {
118 >     for (retries = 0; retries < 2; retries++) {
119 530a627,704
120 > #ifdef RESCUE_MODE
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])
128 >                                                 break;
129 >                          }
130 >                          if (i==13) {
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();
143 >                                         net_setnetvars();
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];
148 >                                         buf = udp_alloc();
149 >                                         if (!buf) {
150 >                                                 res = CFE_ERR_TIMEOUT;
151 >                                                 break;
152 >                                         }
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);
159 >                                 }
160 >                                 else {
161 >                                         for (i=0; i<13; i++) {
162 >                                                 if (buf->eb_ptr[i] != maclink[i])
163 >                                                         break;
164 >                                         }
165 >                                         if (i==13) {
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();
178 >                                                 net_setnetvars();
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];
183 >                                                 buf = udp_alloc();
184 >                                                 if (!buf) {
185 >                                                         res = CFE_ERR_TIMEOUT;
186 >                                                 break;
187 >                                         }
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);
194 >                                 }
195 >                         }
196 >                         res = CFE_ERR_TIMEOUT;
197 > #else
198 535a710
199 > #endif
200 691a867,869
201 > #ifdef RESCUE_MODE
202 >         xprintf("TFTP Server.\n");
203 > #endif
204 694a873,875
205 > #ifdef RESCUE_MODE
206 >         xprintf("TFTP Client.\n");
207 > #endif
208 909a1091,1127
210 > #ifdef RESCUE_MODE
211 > extern int send_rescueack(unsigned short no, unsigned short lo)
212 > {
213 >         ebuf_t *buf = NULL;
214 >         int acksocket;
215 >         char tftpnull;
216 >         int res, i;
218 >         /*
219 >          * Open a UDP socket to the TFTP server
220 >          */
221 >         acksocket = udp_socket(UDP_PROTO_TFTP);
222 >         res = udp_bind(acksocket, 69);
223 >         if (res < 0) {
224 >                 return res;
225 >         }
226 >         udp_connect(acksocket, ackport);
227 >         for (i = 0; i < 1; i++) {
228 >                 buf = udp_alloc();
229 >                 if (!buf)
230 >                         return -1;
231 >                 /*
232 >                  * Send the data
233 >                  */
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);
238 >         }
239 >         if (buf)
240 >                 udp_free(buf);
241 >         udp_close(acksocket);
242 >         return 0;
243 > }
244 > #endif