OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [services/] [arp.c] - Blame information for rev 816

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
/*
2
 * (C) Copyright 2000
3
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4
 *
5
 * See file CREDITS for list of people who contributed to this
6
 * project.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License as
10
 * published by the Free Software Foundation; either version 2 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21
 * MA 02111-1307 USA
22
 */
23
 
24
#include "common.h"
25
#include "support.h"
26
#include "net.h"
27
#include "bootp.h"
28
#include "tftp.h"
29
#include "arp.h"
30 140 julius
#include "string.h"
31 2 marcus.erl
 
32 406 julius
#define TIMEOUT         5       /* Seconds before trying ARP again */
33
#define TIMEOUT_COUNT   1       /* # of timeouts before giving up  */
34
#define DEBUG                   // jb
35
static void ArpHandler(unsigned char *pkt, unsigned dest, unsigned src,
36
                       unsigned len);
37 2 marcus.erl
static void ArpTimeout(void);
38
 
39 406 julius
int ArpTry = 0;
40 2 marcus.erl
 
41
/*
42
 *      Handle a ARP received packet.
43
 */
44
static void
45
ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len)
46
{
47
        /* Check if the frame is really an ARP reply */
48 406 julius
        if (memcmp(NetServerEther, NetBcastAddr, 6) != 0) {
49 2 marcus.erl
#ifdef  DEBUG
50
                printf("Got good ARP - start TFTP\n");
51
#endif
52 406 julius
                TftpStart();
53 2 marcus.erl
        }
54
}
55
 
56
/*
57
 *      Timeout on ARP request.
58
 */
59 406 julius
static void ArpTimeout(void)
60 2 marcus.erl
{
61
        if (ArpTry >= TIMEOUT_COUNT) {
62
                printf("\nRetry count exceeded; starting again\n");
63 406 julius
                NetStartAgain();
64 2 marcus.erl
        } else {
65 406 julius
                NetSetTimeout(TIMEOUT * TICKS_PER_SEC, ArpTimeout);
66
                ArpRequest();
67 2 marcus.erl
        }
68
}
69
 
70 406 julius
void ArpRequest(void)
71 2 marcus.erl
{
72
        int i;
73
        volatile unsigned char *pkt;
74 406 julius
        ARP_t *arp;
75 2 marcus.erl
#ifdef  DEBUG
76
        printf("ARP broadcast %d\n", ++ArpTry);
77 406 julius
#endif
78
        // NetTxPacket is a char* to global buffer used for constructing 
79
        // a packet to send.
80
        pkt = NetTxPacket;
81 2 marcus.erl
 
82 406 julius
        // Setup an ethernet header for ARP protocol in packet
83 2 marcus.erl
        NetSetEther(pkt, NetBcastAddr, PROT_ARP);
84
        pkt += ETHER_HDR_SIZE;
85
 
86 406 julius
        arp = (ARP_t *) pkt;
87 2 marcus.erl
 
88
        arp->ar_hrd = ARP_ETHER;
89
        arp->ar_pro = PROT_IP;
90
        arp->ar_hln = 6;
91
        arp->ar_pln = 4;
92 406 julius
        arp->ar_op = ARPOP_REQUEST;
93 140 julius
        NetCopyEther(&arp->ar_data[0], NetOurEther);     /* source ET addr */
94 406 julius
        //*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP;   /* source IP addr */
95
        memcpy(&arp->ar_data[6], (unsigned char *)&NetOurIP, 4);
96
 
97
        for (i = 10; i < 16; ++i) {
98
                arp->ar_data[i] = 0;     /* dest ET addr = 0 */
99 2 marcus.erl
        }
100
 
101 406 julius
        if ((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {
102
                //*(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP;
103
                memcpy(&arp->ar_data[16], (unsigned char *)&NetOurGatewayIP,
104
                       sizeof(IPaddr_t));
105 2 marcus.erl
        } else {
106 406 julius
                //*((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP;
107
                memcpy(&arp->ar_data[16], (unsigned char *)&NetServerIP,
108
                       sizeof(IPaddr_t));
109 2 marcus.erl
        }
110
 
111
        NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
112
 
113
        NetSetTimeout(TIMEOUT * TICKS_PER_SEC, ArpTimeout);
114
        NetSetHandler(ArpHandler);
115
}

powered by: WebSVN 2.1.0

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