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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [services/] [rarp.c] - Blame information for rev 654

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 "net.h"
26
#include "bootp.h"
27
#include "rarp.h"
28
#include "tftp.h"
29
 
30
#if (CONFIG_COMMANDS & CFG_CMD_NET)
31
 
32 406 julius
#define TIMEOUT         5       /* Seconds before trying BOOTP again */
33
#define TIMEOUT_COUNT   1       /* # of timeouts before giving up    */
34 2 marcus.erl
 
35 406 julius
int RarpTry;
36 2 marcus.erl
 
37
/*
38
 *      Handle a RARP received packet.
39
 */
40
static void
41
RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
42
{
43
#ifdef  DEBUG
44
        printf("Got good RARP\n");
45
#endif
46 406 julius
        TftpStart();
47 2 marcus.erl
}
48
 
49
/*
50
 *      Timeout on BOOTP request.
51
 */
52 406 julius
static void RarpTimeout(void)
53 2 marcus.erl
{
54
        if (RarpTry >= TIMEOUT_COUNT) {
55 406 julius
                puts("\nRetry count exceeded; starting again\n");
56
                NetStartAgain();
57 2 marcus.erl
        } else {
58 406 julius
                NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
59
                RarpRequest();
60 2 marcus.erl
        }
61
}
62
 
63 406 julius
void RarpRequest(void)
64 2 marcus.erl
{
65
        int i;
66
        volatile uchar *pkt;
67 406 julius
        ARP_t *rarp;
68 2 marcus.erl
 
69
        printf("RARP broadcast %d\n", ++RarpTry);
70
        pkt = NetTxPacket;
71
 
72
        NetSetEther(pkt, NetBcastAddr, PROT_RARP);
73
        pkt += ETHER_HDR_SIZE;
74
 
75 406 julius
        rarp = (ARP_t *) pkt;
76 2 marcus.erl
 
77
        rarp->ar_hrd = ARP_ETHER;
78
        rarp->ar_pro = PROT_IP;
79
        rarp->ar_hln = 6;
80
        rarp->ar_pln = 4;
81 406 julius
        rarp->ar_op = RARPOP_REQUEST;
82 2 marcus.erl
        NetCopyEther(&rarp->ar_data[0], NetOurEther);    /* source ET addr */
83 406 julius
        *(IPaddr_t *) (&rarp->ar_data[6]) = NetOurIP;   /* source IP addr */
84
        NetCopyEther(&rarp->ar_data[10], NetOurEther);  /* dest ET addr = source ET addr ?? */
85 2 marcus.erl
        /* dest. IP addr set to broadcast */
86
        for (i = 0; i <= 3; i++) {
87
                rarp->ar_data[16 + i] = 0xff;
88
        }
89
 
90
        NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
91
 
92
        NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
93
        NetSetHandler(RarpHandler);
94
}
95
 
96
#endif /* CFG_CMD_NET */

powered by: WebSVN 2.1.0

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