📄 udp.lst
字号:
177 1 //the code is eprom read data
178 1 STORECODE xdata * eistore;
C51 COMPILER V7.06 UDP 06/26/2004 13:41:26 PAGE 4
179 1 UCHAR xdata enet_dcode[28];
180 1
181 1 // eistore=(STORECODE data *) enet_dcode;
182 1 // the code is eprom read complite
183 1
184 1
185 1 ULONG idata sum;
186 1 UINT idata result;
187 1 UCHAR xdata * outbuf;
188 1 UDP_HEADER xdata * udp;
189 1 IP_HEADER xdata * ip;
190 1
191 1 // Allocate memory for entire outgoing message including
192 1 // eth & IP headers. Total ethernet message length is:
193 1 // 14 byte eth header + 20 byte IP header + 8 byte UDP header
194 1 // + length of this data
195 1 read_temp(0x00,28,enet_dcode);
196 1 eistore=(STORECODE xdata *) enet_dcode;
197 1
198 1 outbuf = (UCHAR xdata *)malloc(42 + len);
199 1 if (outbuf == NULL)
200 1 {
201 2 // if (debug) printf("UDP: Oops, out of memory\n");
202 2 return;
203 2 }
204 1
205 1 udp = (UDP_HEADER xdata *)(outbuf + 34);
206 1 ip = (IP_HEADER xdata *)(outbuf + 14);
207 1
208 1 // Direct message back to the senders port.
209 1 udp->dest_port = sender_udpport;
210 1 udp->source_port = port;
211 1 udp->length = 8 + len;
212 1 udp->checksum = 0;
213 1
214 1 // Fill in data
215 1 // Important do not free receive buffer prior to this
216 1 memcpy(&udp->msg_data, eistore, len);
217 1
218 1
219 1 // Compute checksum including 12 bytes of pseudoheader
220 1 // Must pre-fill 2 items in outbuf to do this
221 1 // Direct message back to senders ip address
222 1 ip->dest_ipaddr = sender_ipaddr;
223 1 ip->source_ipaddr = my_ipaddr;
224 1
225 1
226 1 // Sum source_ipaddr, dest_ipaddr, and entire UDP message
227 1 sum = (ULONG)cksum(outbuf + 26, 8 + udp->length);
228 1
229 1 // Add in the rest of pseudoheader which is
230 1 // zero, protocol id, and UDP length
231 1 sum += (ULONG)0x0011;
232 1 sum += (ULONG)udp->length;
233 1
234 1 // In case there was a carry, add it back around
235 1 result = (UINT)(sum + (sum >> 16));
236 1 udp->checksum = ~result;
237 1 // if (debug) printf("UDP: Sending msg to IP layer\n");
238 1 ip_send(outbuf, sender_ipaddr, UDP_TYPE, udp->length);
239 1 }
240 //------------------------------------------------------------------------
C51 COMPILER V7.06 UDP 06/26/2004 13:41:26 PAGE 5
241 // This handles incoming UDP messages
242 // See "TCP/IP Illustrated, Volume 1" Sect 11.1 - 11.3
243 //------------------------------------------------------------------------
244 void udp_rcve(UCHAR xdata * inbuf, UINT len)
245 { UCHAR idata i;
246 1 UINT idata result;
247 1 UDP_HEADER xdata * udp;
248 1 IP_HEADER xdata * ip;
249 1 ULONG idata sum;
250 1
251 1 UCHAR data QHYNET;
252 1 UCHAR data QHYNET2;
253 1
254 1
255 1 UCHAR xdata * mydata;
256 1 UCHAR xdata * recive_cdata;
257 1 UCHAR data wrtemp[16];
258 1 UCHAR data writetemp[28];
259 1 // Total of eth & IP headers = 34 bytes
260 1 udp = (UDP_HEADER xdata *)(inbuf + 34);
261 1 ip = (IP_HEADER xdata *)(inbuf + 14);
262 1
263 1 mydata=inbuf+42;
264 1 recive_cdata=inbuf+42;
265 1 // The IP length "len" should be the same as the redundant length
266 1 // udp->length. TCP/IP Illustrated, Vol 2, Sect 23.7 says to use the
267 1 // UDP length, unless IP length < UDP length, in which case the frame
268 1 // should be discarded.
269 1 if (len < udp->length) return;
270 1
271 1 // If the checksum is zero it means that the sender did not compute
272 1 // it and we should not try to check it.
273 1 if (udp->checksum == 0)
274 1 {
275 2 // if (debug) printf("UDP: Sender did not compute cksum\n");
276 2 }
277 1 else
278 1 {
279 2 // Compute UDP checksum including 12 byte pseudoheader
280 2 // Sum source_ipaddr, dest_ipaddr, and entire UDP message
281 2 sum = (ULONG)cksum(inbuf + 26, 8 + udp->length);
282 2
283 2 // Add in the rest of pseudoheader which is
284 2 // zero, protocol id, and UDP length
285 2 sum += (ULONG)0x0011;
286 2 sum += (ULONG)udp->length;
287 2
288 2 // In case there was a carry, add it back around
289 2 result = (UINT)(sum + (sum >> 16));
290 2
291 2 if (result != 0xFFFF)
292 2 {
293 3 // if (debug) printf("UDP: Error, bad cksum\n");
294 3 return;
295 3 }
296 2
297 2 // if (debug) printf("UDP: Msg rcvd with good cksum\n");
298 2 }
299 1
300 1 // Capture sender's port number and ip_addr
301 1 // to send return message to
302 1 sender_udpport = udp->source_port;
C51 COMPILER V7.06 UDP 06/26/2004 13:41:26 PAGE 6
303 1 sender_ipaddr = ip->source_ipaddr;
304 1
305 1 // See if any applications are on any ports
306 1 switch (udp->dest_port)
307 1 {
308 2 case ECHO_PORT:
309 2 // Pass it the payload length
310 2
311 2 udp_echo_service(inbuf, udp->length - 8);
312 2 break;
313 2 case scanip: //询部IP地址
314 2 sysconfig_udp_send(scanip, 28);
315 2 //sysconfig_udp_send(scanip, 28);
316 2 //sysconfig_udp_send(scanip, 28);
317 2 break;
318 2
319 2 case configip: //设置IP地址
320 2
321 2 memcpy(writetemp, recive_cdata, 28);
322 2
323 2 if(writetemp[27]==0x7f)
324 2 {
325 3 for(i=0;i<12;i++){wrtemp[i]=writetemp[16+i];}
326 3 write_temp(0X00,16,writetemp);
327 3 write_temp(0X10,12,wrtemp);
328 3
329 3 while(1);
330 3 }
331 2 break;
332 2 case QHY_PORT:
333 2 QHYNET=* mydata;
334 2 QHYNET2=* (mydata+1); //this is key resolution
335 2 //this is key for 7e code
336 2 //commucation
337 2 if(QHYNET==0xff){ sdbuf[1]=QHYNET2;
338 3 fu_key(QHYNET2);RSS=1;
339 3 }
340 2 udpst=1;
341 2 break;
342 2 default:break;
343 2 }
344 1 }
345
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2075 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 6 83
PDATA SIZE = ---- ----
DATA SIZE = ---- 46
IDATA SIZE = ---- 25
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -