No.27814 作者:tubage 邮件:tubage21@elong.com ID:11635 登陆:1次 文章数:3篇 最后登陆IP:61.186.110.246 最后登陆:2003/5/11 9:56:59 注册:2003/4/28 16:16:08 财富:109 发帖时间:2003/4/28 16:25:43 发贴者IP:61.186.109.145 标题:tubage:大家帮忙看一下 摘要:No.27814大家帮忙看一下 这是我用rtl8019as上网的程序 我想知道怎么样在这上面加TCP和UDP的程序进行解包和压包。可以的话请您发到我的邮箱tubage21@elong.com _______________________________________________ #include "rtlregs.h" #define NIC_PAGE_SIZE 256 #define NIC_START_PAGE 0x40 #define NIC_STOP_PAGE 0x80 #define NIC_TX_PAGES 6 #define NIC_TX_BUFFERS 2 #define NIC_FIRST_TX_PAGE NIC_START_PAGE #define NIC_FIRST_RX_PAGE (NIC_FIRST_TX_PAGE + NIC_TX_PAGES * NIC_TX_BUFFERS) #define TX_PAGES 12 static void NicCompleteDma(void) { u_char i; nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2); for(i = 0; i <= 20; i++) if(nic_read(NIC_PG0_ISR) & NIC_ISR_RDC) break; nic_write(NIC_PG0_ISR, NIC_ISR_RDC); } void NicRemovePacket(void) { struct nic_pkt_header_struct hdr; u_short count; u_char *buf; u_char nextpg; u_char bnry; u_char curr; u_short i; u_char ict; bnry = nic_read(NIC_PG0_BNRY) + 1; if(bnry > = NIC_STOP_PAGE) bnry = NIC_FIRST_RX_PAGE; nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 | NIC_CR_PS0); curr = nic_read(NIC_PG1_CURR); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2); if(bnry == curr) return; nic_write(NIC_PG0_RBCR0, sizeof(struct nic_pkt_header_struct)); nic_write(NIC_PG0_RBCR1, 0); nic_write(NIC_PG0_RSAR0, 0); nic_write(NIC_PG0_RSAR1, bnry); buf = (u_char *)&hdr; nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD0); for(i = 0; i < sizeof(struct nic_pkt_header_struct); i++) *buf++ = nic_read(NIC_IOPORT); NicCompleteDma(); count = hdr.ph_size - sizeof(struct nic_pkt_header_struct); nic_write(NIC_PG0_RBCR0, count); nic_write(NIC_PG0_RBCR1, count > > 8); nic_write(NIC_PG0_RSAR0, sizeof(struct nic_pkt_header_struct)); nic_write(NIC_PG0_RSAR1, bnry); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD0); for(i = 0; i < count; i++) ict = nic_read(NIC_IOPORT); NicCompleteDma(); ict = ict; nextpg = hdr.ph_nextpg - 1; if(nextpg < NIC_FIRST_RX_PAGE) nextpg = NIC_STOP_PAGE - 1; nic_write(NIC_PG0_BNRY, nextpg); } unsigned int NicGetPacket(u_char *pkt1) { struct nic_pkt_header_struct hdr; u_short count; u_char *buf; u_char nextpg; u_char bnry; u_char curr; u_short i; buf = (u_char *)&hdr; bnry = nic_read(NIC_PG0_BNRY) + 1; if(bnry > = NIC_STOP_PAGE) bnry = NIC_FIRST_RX_PAGE; nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 | NIC_CR_PS0); curr = nic_read(NIC_PG1_CURR); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2); if(bnry == curr) return 0; nic_write(NIC_PG0_RBCR0, sizeof(struct nic_pkt_header_struct)); nic_write(NIC_PG0_RBCR1, 0); nic_write(NIC_PG0_RSAR0, 0); nic_write(NIC_PG0_RSAR1, bnry); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD0); for(i = 0; i < sizeof(struct nic_pkt_header_struct); i++) *buf++ = nic_read(NIC_IOPORT); NicCompleteDma(); count = hdr.ph_size - sizeof(struct nic_pkt_header_struct); nic_write(NIC_PG0_RBCR0, count); nic_write(NIC_PG0_RBCR1, count > > 8); nic_write(NIC_PG0_RSAR0, sizeof(struct nic_pkt_header_struct)); nic_write(NIC_PG0_RSAR1, bnry); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD0); for (i = 0; i < count; i++) *pkt1++ = nic_read(NIC_IOPORT); NicCompleteDma(); nextpg = hdr.ph_nextpg - 1; if(nextpg < NIC_FIRST_RX_PAGE) nextpg = NIC_STOP_PAGE - 1; nic_write(NIC_PG0_BNRY, nextpg); return count; } int NicPutPacket(u_char *data, u_short sz) { u_short i; u_char *p; u_char padding = 0; u_short sz1=sz; if(sz1 > = 0x0600) return -1; if(sz1 < 60) { padding = (u_char)(60 - sz1); sz1 = 60; } nic_write(NIC_PG0_RBCR0, sz1); nic_write(NIC_PG0_RBCR1, sz1 > > 8); nic_write(NIC_PG0_RSAR0, 0); nic_write(NIC_PG0_RSAR1, NIC_FIRST_TX_PAGE); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD1); p = data; for(i = 0; i < sz; i++) nic_write(NIC_IOPORT, *p++); for(i = 0; i < padding; i++) nic_write(NIC_IOPORT, 0); NicCompleteDma(); nic_write(NIC_PG0_TBCR0, (sz1 & 0xff)); nic_write(NIC_PG0_TBCR1, ((sz1 > > 8) & 0xff)); nic_write(NIC_PG0_TPSR, NIC_FIRST_TX_PAGE); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_TXP | NIC_CR_RD2); return 0; } int NicInit(unsigned char *mac) { u_char i; u_char j; for(j = 0; j < 10; j++) { if(nic_read(NIC_PG0_ISR) & NIC_ISR_RST) break; nic_write(NIC_RESET, nic_read(NIC_RESET)); for(i = 0; i < 255; i++) { if(nic_read(NIC_PG0_ISR) & NIC_ISR_RST) break; } } nic_write(NIC_PG0_IMR, 0); nic_write(NIC_PG0_ISR, 0xff); nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1); nic_write(NIC_PG3_EECR, NIC_EECR_E ......
>>返回讨论的主题
|