📄 uip_arch.c
字号:
#include "uip.h"
#include "uip_arch.h"
#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define IP_PROTO_TCP 6
/*-----------------------------------------------------------------------------------*/
void
uip_add32(u8_t *op32, u16_t op16)
{
uip_acc32[3] = op32[3] + (op16 & 0xff);
uip_acc32[2] = op32[2] + (op16 >> 8);
uip_acc32[1] = op32[1];
uip_acc32[0] = op32[0];
if(uip_acc32[2] < (op16 >> 8)) {
++uip_acc32[1];
if(uip_acc32[1] == 0) {
++uip_acc32[0];
}
}
if(uip_acc32[3] < (op16 & 0xff)) {
++uip_acc32[2];
if(uip_acc32[2] == 0) {
++uip_acc32[1];
if(uip_acc32[1] == 0) {
++uip_acc32[0];
}
}
}
}
/********************************************************************************/
/* function : chksum() */
/* created : hw-chen */
/* descript : calculate checksum */
/********************************************************************************/
u16_t uip_chksum(u16_t sum, u16_t * buffer, u16_t size)
{ u16_t i,length;
u32_t cksum;
length=size>>0x1;
cksum =0x0;
cksum+=sum;
for(i=0x0; i<length; i++)
{ cksum+=buffer[i];
}
if(size&0x1)
{ cksum+=buffer[i]&0xFF00;
}
cksum =(cksum>>16)+(cksum&0xFFFF);
cksum+=(cksum>>16);
return (u16_t)cksum;
}
/********************************************************************************/
/* function : uip_ipchksum() */
/* created : hw-chen */
/* descript : calculate ip layer checksum */
/********************************************************************************/
u16_t uip_ipchksum(void)
{ return uip_chksum(0x0,(u16_t*)&uip_buf[UIP_LLH_LEN], 20);
}
/********************************************************************************/
/* 定义TCP伪首部 */
/********************************************************************************/
typedef struct _sd_hdr st_tsd_hdr;
struct _sd_hdr
{ u16_t srcaddr[0x2];
u16_t dstaddr[0x2];
u8_t rsvd;
u8_t protocol; //* 协议类型
u16_t lenth; //* TCP长度
};
/********************************************************************************/
/* function : uip_tcpchksum() */
/* created : hw-chen */
/* descript : TCP头部校验和 */
/********************************************************************************/
u16_t uip_tcpchksum(void)
{ st_tsd_hdr tsd_header;
u16_t length;
u16_t tmp;
u16_t sum1;
u16_t sum2;
tmp=BUF->len[0x0];
tmp<<=0x8;
tmp+=BUF->len[0x1];
length=HTONS(tmp)-20;
tsd_header.srcaddr[0] = BUF->srcipaddr[0x0];
tsd_header.srcaddr[1] = BUF->srcipaddr[0x1];
tsd_header.dstaddr[0] = BUF->destipaddr[0x0];
tsd_header.dstaddr[1] = BUF->destipaddr[0x1];
tsd_header.rsvd = 0x0;
tsd_header.protocol = 0x6;
tsd_header.lenth = HTONS(length);
sum1=uip_chksum(0x0,(u16_t*)&tsd_header,sizeof(st_tsd_hdr));
sum2=uip_chksum(sum1,(u16_t*)(&uip_buf[20+UIP_LLH_LEN]),length);
return sum2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -