OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [services/] [net.c] - Diff between revs 2 and 140

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 140
Line 121... Line 121...
NetLoop(proto_t protocol)
NetLoop(proto_t protocol)
{
{
#if 1
#if 1
        if (!NetTxPacket) {
        if (!NetTxPacket) {
                int     i;
                int     i;
 
    printf("NetTxPacket begin setup\n");
                /*
                /*
                 *      Setup packet buffers, aligned correctly.
                 *      Setup packet buffers, aligned correctly.
                 */
                 */
                NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
                NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
                NetTxPacket -= (unsigned long)NetTxPacket % PKTALIGN;
                NetTxPacket -= (unsigned long)NetTxPacket % PKTALIGN;
Line 159... Line 159...
                        return 0;
                        return 0;
                }
                }
 
 
                /* always use ARP to get server ethernet address */
                /* always use ARP to get server ethernet address */
                ArpTry = 0;
                ArpTry = 0;
 
 
                ArpRequest ();
                ArpRequest ();
 
 
#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
        } else if (protocol == DHCP) {
        } else if (protocol == DHCP) {
                if (net_check_prereq (protocol) != 0) {
                if (net_check_prereq (protocol) != 0) {
Line 228... Line 229...
 
 
                /*
                /*
                 *      Check for a timeout, and run the timeout handler
                 *      Check for a timeout, and run the timeout handler
                 *      if we have one.
                 *      if we have one.
                 */
                 */
                if (timeHandler && (get_timer(0) > timeValue)) {
    /*
                        thand_f *x;
      if (timeHandler && (get_timer(0) > timeValue)) {
 
      thand_f *x;
                        x = timeHandler;
 
                        timeHandler = (thand_f *)0;
 
                        (*x)();
 
                }
 
 
 
 
      x = timeHandler;
 
      timeHandler = (thand_f *)0;
 
      (*x)();
 
      }
 
    */
 
 
                switch (NetState) {
                switch (NetState) {
 
 
                case NETLOOP_RESTART:
                case NETLOOP_RESTART:
                        goto restart;
                        goto restart;
 
 
                case NETLOOP_SUCCESS:
                case NETLOOP_SUCCESS:
                        if (NetBootFileXferSize > 0) {
                        if (NetBootFileXferSize > 0) {
                                printf("Bytes transferred = %ld (%lx hex)\n",
        printf("Bytes transferred = %ld (0x%lx)\n",
                                        NetBootFileXferSize,
                                        NetBootFileXferSize,
                                        NetBootFileXferSize);
                                        NetBootFileXferSize);
 
#ifdef TFTP_CALC_CHKSUM
 
        printf("CHKSUM: 0x%lx\n", TFTP_CHKSUM);
 
#endif
                        }
                        }
                        eth_halt();
                        eth_halt();
                        return NetBootFileXferSize;
                        return NetBootFileXferSize;
 
 
                case NETLOOP_FAIL:
                case NETLOOP_FAIL:
Line 297... Line 302...
void
void
NetSendPacket(volatile unsigned char * pkt, int len)
NetSendPacket(volatile unsigned char * pkt, int len)
{
{
 
 
#if OC_LAN==1
#if OC_LAN==1
  unsigned char *p;
  unsigned char *p = (unsigned char *)0;
 
  while (p == (unsigned char*) 0)
  p = eth_get_tx_buf();
  p = eth_get_tx_buf();
 
 
  memcpy(p, (void *)pkt, len);
  memcpy(p, (void *)pkt, len);
  eth_send(p, len);
  eth_send(p, len);
#else if SMC91111_LAN==1
#else if SMC91111_LAN==1
  eth_send(pkt, len);
  eth_send(pkt, len);
#endif
#endif
Line 316... Line 322...
{
{
        Ethernet_t *et;
        Ethernet_t *et;
        IP_t    *ip;
        IP_t    *ip;
        ARP_t   *arp;
        ARP_t   *arp;
        int     x;
        int     x;
 
  IPaddr_t ip_to_check; // Used as a temp variable to check IP
 
 
        NetRxPkt = pkt;
        NetRxPkt = pkt;
        NetRxPktLen = len;
        NetRxPktLen = len;
        et = (Ethernet_t *)pkt;
        et = (Ethernet_t *)pkt;
 
 
Line 373... Line 379...
                }
                }
                if (arp->ar_pln != 4) {
                if (arp->ar_pln != 4) {
                        return;
                        return;
                }
                }
 
 
 
    memcpy((void*) &ip_to_check, (void*)&arp->ar_data[16],
 
           sizeof(IPaddr_t));
                if (NetOurIP == 0 ||
                if (NetOurIP == 0 ||
                    *((IPaddr_t *)&arp->ar_data[16]) != NetOurIP) {
        ip_to_check != NetOurIP) {
                        return;
                        return;
                }
                }
 
 
                switch (SWAP16(arp->ar_op)) {
                switch (SWAP16(arp->ar_op)) {
                case ARPOP_REQUEST:             /* reply with our IP address    */
                case ARPOP_REQUEST:             /* reply with our IP address    */
Line 387... Line 395...
#endif
#endif
                        NetSetEther((unsigned char *)et, et->et_src, PROT_ARP);
                        NetSetEther((unsigned char *)et, et->et_src, PROT_ARP);
                        arp->ar_op = SWAP16(ARPOP_REPLY);
                        arp->ar_op = SWAP16(ARPOP_REPLY);
                        NetCopyEther(&arp->ar_data[10], &arp->ar_data[0]);
                        NetCopyEther(&arp->ar_data[10], &arp->ar_data[0]);
                        NetCopyEther(&arp->ar_data[0], NetOurEther);
                        NetCopyEther(&arp->ar_data[0], NetOurEther);
                        *(IPaddr_t *)(&arp->ar_data[16]) =
      //*(IPaddr_t *)(&arp->ar_data[16]) = *(IPaddr_t *)(&arp->ar_data[6]);
                                                *(IPaddr_t *)(&arp->ar_data[6]);
      memcpy((void*)&arp->ar_data[16],(void*) &arp->ar_data[6],
                        *(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP;
             sizeof(IPaddr_t));
                        NetSendPacket((unsigned char *)et,((unsigned char *)arp-pkt)+ARP_HDR_SIZE);
      //*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP;
 
      memcpy((void*)&arp->ar_data[6],(void*) &NetOurIP,
 
             sizeof(IPaddr_t));
 
 
 
      NetSendPacket((unsigned char *)et,
 
                    ((unsigned char *)arp-pkt)+ARP_HDR_SIZE);
                        return;
                        return;
                case ARPOP_REPLY:               /* set TFTP server eth addr     */
                case ARPOP_REPLY:               /* set TFTP server eth addr     */
#ifdef ET_DEBUG
#ifdef ET_DEBUG
                        printf("Got ARP REPLY, set server/gtwy eth addr\n");
                        printf("Got ARP REPLY, set server/gtwy eth addr\n");
#endif
#endif
Line 423... Line 436...
                        (SWAP16(arp->ar_pro) != PROT_IP)     ||
                        (SWAP16(arp->ar_pro) != PROT_IP)     ||
                        (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
                        (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
 
 
                        printf("invalid RARP header\n");
                        printf("invalid RARP header\n");
                } else {
                } else {
                        NetOurIP = *((IPaddr_t *)&arp->ar_data[16]);
      //NetOurIP = *((IPaddr_t *)&arp->ar_data[16]);
                        NetServerIP = *((IPaddr_t *)&arp->ar_data[6]);
      memcpy((void*) &NetOurIP, (void*) &arp->ar_data[16],
 
             sizeof(IPaddr_t));
 
      //NetServerIP = *((IPaddr_t *)&arp->ar_data[6]);
 
      memcpy((void*) &NetServerIP,(void*) &arp->ar_data[6],
 
             sizeof(IPaddr_t));
 
 
                        NetCopyEther(NetServerEther, &arp->ar_data[0]);
                        NetCopyEther(NetServerEther, &arp->ar_data[0]);
 
 
                        (*packetHandler)(0,0,0,0);
                        (*packetHandler)(0,0,0,0);
                }
                }
                break;
                break;
Line 454... Line 472...
                }
                }
                if (ip->ip_off & SWAP16c(0x1fff)) { /* Can't deal w/ fragments */
                if (ip->ip_off & SWAP16c(0x1fff)) { /* Can't deal w/ fragments */
                        return;
                        return;
                }
                }
                if (!NetCksumOk((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
                if (!NetCksumOk((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
                        printf("checksum bad\n");
      //printf("checksum bad\n");
                        return;
                        return;
                }
                }
 
 
 
    memcpy((void*)&ip_to_check,(void*)&ip->ip_dst, sizeof (IPaddr_t));
 
 
                if (NetOurIP &&
                if (NetOurIP &&
                    ip->ip_dst != NetOurIP &&
        ip_to_check != NetOurIP &&
                    ip->ip_dst != 0xFFFFFFFF) {
        ip_to_check != 0xFFFFFFFF) {
                        return;
                        return;
                }
                }
                /*
                /*
                 * watch for ICMP host redirects
                 * watch for ICMP host redirects
                 *
                 *
Line 553... Line 574...
{
{
        unsigned long   xsum;
        unsigned long   xsum;
 
 
        xsum = 0;
        xsum = 0;
        while (len-- > 0)
        while (len-- > 0)
                xsum += *((unsigned short *)ptr)++;
    {
 
      xsum += (*((unsigned short *)ptr));
 
      ptr += sizeof(short);
 
    }
 
 
        xsum = (xsum & 0xffff) + (xsum >> 16);
        xsum = (xsum & 0xffff) + (xsum >> 16);
        xsum = (xsum & 0xffff) + (xsum >> 16);
        xsum = (xsum & 0xffff) + (xsum >> 16);
        return (xsum & 0xffff);
        return (xsum & 0xffff);
}
}
 
 
Line 606... Line 631...
        ip->ip_id    = SWAP16(NetIPID++);
        ip->ip_id    = SWAP16(NetIPID++);
        ip->ip_off   = SWAP16c(0x4000); /* No fragmentation */
        ip->ip_off   = SWAP16c(0x4000); /* No fragmentation */
        ip->ip_ttl   = 255;
        ip->ip_ttl   = 255;
        ip->ip_p     = 17;              /* UDP */
        ip->ip_p     = 17;              /* UDP */
        ip->ip_sum   = 0;
        ip->ip_sum   = 0;
        ip->ip_src   = NetOurIP;
  //ip->ip_src   = NetOurIP;
        ip->ip_dst   = dest;
  memcpy((void*)&ip->ip_src,(void*) &NetOurIP,
 
        sizeof(IPaddr_t));
 
  //ip->ip_dst   = dest;
 
  memcpy((void*)&ip->ip_dst,(void*) &dest,
 
        sizeof(IPaddr_t));
        ip->udp_src  = SWAP16(sport);
        ip->udp_src  = SWAP16(sport);
        ip->udp_dst  = SWAP16(dport);
        ip->udp_dst  = SWAP16(dport);
        ip->udp_len  = SWAP16(8 + len);
        ip->udp_len  = SWAP16(8 + len);
        ip->udp_xsum = 0;
        ip->udp_xsum = 0;
        ip->ip_sum   = ~NetCksum((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2);
        ip->ip_sum   = ~NetCksum((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.