reformatted sources, added start of bootp protocol implementation
This commit is contained in:
1
Makefile
1
Makefile
@@ -100,6 +100,7 @@ CSRCS= \
|
||||
ip.c \
|
||||
udp.c \
|
||||
arp.c \
|
||||
bootp.c \
|
||||
\
|
||||
basflash.c \
|
||||
basflash_start.c
|
||||
|
||||
58
include/bootp.h
Normal file
58
include/bootp.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* File: bootp.h
|
||||
* Purpose: BOOTP definitions.
|
||||
*
|
||||
* Notes:
|
||||
*/
|
||||
|
||||
#ifndef _BOOTP_H_
|
||||
#define _BOOTP_H_
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/*
|
||||
* This data definition is defined for Ethernet only!
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t type; /* bootp operation type */
|
||||
uint8_t htype; /* hardware type */
|
||||
uint8_t hlen; /* hardware address length */
|
||||
uint8_t hops; /* hops */
|
||||
uint32_t xid; /* transaction identifier */
|
||||
uint16_t secs; /* seconds since trying to boot */
|
||||
uint16_t flags; /* only broadcast flag in use */
|
||||
uint32_t cl_addr; /* client ip address. Set to all 0 on request */
|
||||
uint32_t yi_addr; /* this field contains the new IP */
|
||||
uint32_t gi_addr; /* gateway address */
|
||||
uint8_t ch_addr[16]; /* client hw address */
|
||||
uint8_t sname[64]; /* server name */
|
||||
uint8_t file[128]; /* name of bootfile */
|
||||
uint8_t vend[64]; /* vendor specific (see below) */
|
||||
} bootp_frame_hdr;
|
||||
|
||||
#define BOOTP_HDR_LEN sizeof(bootp_frame_hdr)
|
||||
|
||||
/* possible values for type field */
|
||||
#define BOOTP_TYPE_BOOTREQUEST 1
|
||||
#define BOOTP_TYPE_BOOTREPLY 2
|
||||
|
||||
/* values for hardware type - we only use ethernet */
|
||||
#define BOOTP_HTYPE_ETHERNET 1
|
||||
|
||||
/* values for hlen - again only ethernet defined */
|
||||
#define BOOTP_HLEN_ETHERNET 6
|
||||
|
||||
/* values for flags - only broadcast flag in use */
|
||||
#define BOOTP_FLAGS_BROADCAST 1
|
||||
|
||||
#define BOOTP_TIMEOUT (1) /* Timeout in seconds */
|
||||
|
||||
/* Protocol Header information */
|
||||
#define BOOTP_HDR_OFFSET ETH_HDR_LEN
|
||||
|
||||
extern void bootp_request(NIF *, uint8_t *);
|
||||
extern void bootp_handler(NIF *, NBUF *);
|
||||
//extern void bootp_init(BOOTP_INFO *);
|
||||
|
||||
#endif /* _BOOTP_H_ */
|
||||
199
net/bootp.c
199
net/bootp.c
@@ -1,33 +1,190 @@
|
||||
#include "bas_types.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static bool bootp_initialized = false;
|
||||
|
||||
/*
|
||||
* bootp client state
|
||||
* File: arp.c
|
||||
* Purpose: Address Resolution Protocol routines.
|
||||
*
|
||||
* Notes:
|
||||
*/
|
||||
|
||||
struct bootp_client
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t mode;
|
||||
uint8_t socket_handle;
|
||||
uint16_t timer_handle;
|
||||
uint16_t boot_secs;
|
||||
};
|
||||
#include "net.h"
|
||||
#include "bootp.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static struct bootp_client client;
|
||||
#define TIMER_NETWORK 0
|
||||
|
||||
int bootpc_init(int mode)
|
||||
void bootp_request(NIF *nif, uint8_t *pa)
|
||||
{
|
||||
if (bootp_initialized)
|
||||
/*
|
||||
* This function broadcasts a BOOTP request for the protocol
|
||||
* address "pa"
|
||||
*/
|
||||
uint8_t *addr;
|
||||
NBUF *pNbuf;
|
||||
bootp_frame_hdr *bootpframe;
|
||||
int i, result;
|
||||
|
||||
pNbuf = nbuf_alloc();
|
||||
if (pNbuf == NULL)
|
||||
{
|
||||
return true;
|
||||
#if defined(DEBUG_PRINT)
|
||||
xprintf("%s: arp_request couldn't allocate Tx buffer\r\n", __FUNCTION__);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
bootpframe = (bootp_frame_hdr *) &pNbuf->data[BOOTP_HDR_OFFSET];
|
||||
|
||||
/* Build the BOOTP request packet */
|
||||
bootpframe->type = BOOTP_TYPE_BOOTREQUEST;
|
||||
bootpframe->htype = BOOTP_HTYPE_ETHERNET;
|
||||
bootpframe->hlen = BOOTP_HLEN_ETHERNET;
|
||||
bootpframe->hops = 0;
|
||||
bootpframe->xid = 0x1234;
|
||||
bootpframe->secs = 1;
|
||||
bootpframe->flags = BOOTP_FLAGS_BROADCAST;
|
||||
bootpframe->cl_addr = 0x0;
|
||||
bootpframe->yi_addr = 0x0;
|
||||
bootpframe->gi_addr = 0x0;
|
||||
|
||||
addr = &nif->hwa[0];
|
||||
for (i = 0; i < 6; i++)
|
||||
bootpframe->ch_addr[i] = addr[i];
|
||||
|
||||
pNbuf->length = BOOTP_HDR_LEN;
|
||||
|
||||
/* Send the BOOTP request */
|
||||
result = nif->send(nif, nif->broadcast, nif->hwa, ETH_FRM_IP, pNbuf);
|
||||
|
||||
if (result == 0)
|
||||
nbuf_free(pNbuf);
|
||||
}
|
||||
|
||||
void bootp_handler(NIF *nif, NBUF *pNbuf)
|
||||
{
|
||||
/*
|
||||
* ARP protocol handler
|
||||
*/
|
||||
uint8_t *addr;
|
||||
bootp_frame_hdr *rx_bootpframe, *tx_bootpframe;
|
||||
|
||||
rx_bootpframe = (bootp_frame_hdr *) &pNbuf->data[pNbuf->offset];
|
||||
|
||||
#ifdef _NOT_USED_
|
||||
/*
|
||||
* Check for an appropriate ARP packet
|
||||
*/
|
||||
if ((pNbuf->length < ARP_HDR_LEN) ||
|
||||
(rx_arpframe->ar_hrd != ETHERNET) ||
|
||||
(rx_arpframe->ar_hln != 6) ||
|
||||
(rx_arpframe->ar_pro != ETH_FRM_IP) ||
|
||||
(rx_arpframe->ar_pln != 4))
|
||||
{
|
||||
nbuf_free(pNbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* get socket handle
|
||||
* Check to see if it was addressed to me - if it was, keep this
|
||||
* ARP entry in the table permanently; if not, mark it so that it
|
||||
* can be displaced later if necessary
|
||||
*/
|
||||
client.socket_handle = udp_getsocket
|
||||
addr = ip_get_myip(nif_get_protocol_info(nif,ETH_FRM_IP));
|
||||
if ((rx_arpframe->ar_tpa[0] == addr[0]) &&
|
||||
(rx_arpframe->ar_tpa[1] == addr[1]) &&
|
||||
(rx_arpframe->ar_tpa[2] == addr[2]) &&
|
||||
(rx_arpframe->ar_tpa[3] == addr[3]) )
|
||||
{
|
||||
longevity = ARP_ENTRY_PERM;
|
||||
}
|
||||
else
|
||||
longevity = ARP_ENTRY_TEMP;
|
||||
|
||||
/*
|
||||
* Add ARP info into the table
|
||||
*/
|
||||
arp_merge(arptab,
|
||||
rx_arpframe->ar_pro,
|
||||
rx_arpframe->ar_hln,
|
||||
&rx_arpframe->ar_sha[0],
|
||||
rx_arpframe->ar_pln,
|
||||
&rx_arpframe->ar_spa[0],
|
||||
longevity
|
||||
);
|
||||
|
||||
switch (rx_arpframe->opcode)
|
||||
{
|
||||
case ARP_REQUEST:
|
||||
/*
|
||||
* Check to see if request is directed to me
|
||||
*/
|
||||
if ((rx_arpframe->ar_tpa[0] == addr[0]) &&
|
||||
(rx_arpframe->ar_tpa[1] == addr[1]) &&
|
||||
(rx_arpframe->ar_tpa[2] == addr[2]) &&
|
||||
(rx_arpframe->ar_tpa[3] == addr[3]) )
|
||||
{
|
||||
/*
|
||||
* Reuse the current network buffer to assemble an ARP reply
|
||||
*/
|
||||
tx_arpframe = (arp_frame_hdr *)&pNbuf->data[ARP_HDR_OFFSET];
|
||||
|
||||
/*
|
||||
* Build new ARP frame from the received data
|
||||
*/
|
||||
tx_arpframe->ar_hrd = ETHERNET;
|
||||
tx_arpframe->ar_pro = ETH_FRM_IP;
|
||||
tx_arpframe->ar_hln = 6;
|
||||
tx_arpframe->ar_pln = 4;
|
||||
tx_arpframe->opcode = ARP_REPLY;
|
||||
tx_arpframe->ar_tha[0] = rx_arpframe->ar_sha[0];
|
||||
tx_arpframe->ar_tha[1] = rx_arpframe->ar_sha[1];
|
||||
tx_arpframe->ar_tha[2] = rx_arpframe->ar_sha[2];
|
||||
tx_arpframe->ar_tha[3] = rx_arpframe->ar_sha[3];
|
||||
tx_arpframe->ar_tha[4] = rx_arpframe->ar_sha[4];
|
||||
tx_arpframe->ar_tha[5] = rx_arpframe->ar_sha[5];
|
||||
tx_arpframe->ar_tpa[0] = rx_arpframe->ar_spa[0];
|
||||
tx_arpframe->ar_tpa[1] = rx_arpframe->ar_spa[1];
|
||||
tx_arpframe->ar_tpa[2] = rx_arpframe->ar_spa[2];
|
||||
tx_arpframe->ar_tpa[3] = rx_arpframe->ar_spa[3];
|
||||
|
||||
/*
|
||||
* Now copy in the new information
|
||||
*/
|
||||
addr = &nif->hwa[0];
|
||||
tx_arpframe->ar_sha[0] = addr[0];
|
||||
tx_arpframe->ar_sha[1] = addr[1];
|
||||
tx_arpframe->ar_sha[2] = addr[2];
|
||||
tx_arpframe->ar_sha[3] = addr[3];
|
||||
tx_arpframe->ar_sha[4] = addr[4];
|
||||
tx_arpframe->ar_sha[5] = addr[5];
|
||||
|
||||
addr = ip_get_myip(nif_get_protocol_info(nif,ETH_FRM_IP));
|
||||
tx_arpframe->ar_spa[0] = addr[0];
|
||||
tx_arpframe->ar_spa[1] = addr[1];
|
||||
tx_arpframe->ar_spa[2] = addr[2];
|
||||
tx_arpframe->ar_spa[3] = addr[3];
|
||||
|
||||
/*
|
||||
* Save the length of my packet in the buffer structure
|
||||
*/
|
||||
pNbuf->length = ARP_HDR_LEN;
|
||||
|
||||
nif->send(nif,
|
||||
&tx_arpframe->ar_tha[0],
|
||||
&tx_arpframe->ar_sha[0],
|
||||
ETH_FRM_ARP,
|
||||
pNbuf);
|
||||
}
|
||||
else
|
||||
nbuf_free(pNbuf);
|
||||
break;
|
||||
case ARP_REPLY:
|
||||
/*
|
||||
* The ARP Reply case is already taken care of
|
||||
*/
|
||||
default:
|
||||
nbuf_free(pNbuf);
|
||||
break;
|
||||
}
|
||||
#endif /* _NOT_USED_ */
|
||||
return;
|
||||
}
|
||||
|
||||
10
net/fec.c
10
net/fec.c
@@ -28,8 +28,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
FEC_EVENT_LOG fec_log[2];
|
||||
|
||||
/********************************************************************/
|
||||
@@ -555,9 +553,6 @@ void fec_rx_start(uint8_t ch, int8_t *rxbd)
|
||||
channel = dma_set_channel(DMA_FEC_RX(ch),
|
||||
(ch == 0) ? fec0_rx_frame : fec1_rx_frame);
|
||||
|
||||
/*
|
||||
* Start the Rx DMA task
|
||||
*/
|
||||
/*
|
||||
* Start the Rx DMA task
|
||||
*/
|
||||
@@ -729,6 +724,7 @@ void fec_rx_frame(uint8_t ch, NIF *nif)
|
||||
#ifdef DEBUG_PRINT
|
||||
xprintf("nbuf_alloc() failed\n");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Can't allocate a new network buffer, so we
|
||||
* have to trash the received data and reuse the buffer
|
||||
@@ -811,12 +807,14 @@ void fec_rx_frame(uint8_t ch, NIF *nif)
|
||||
void fec0_rx_frame(void)
|
||||
{
|
||||
extern NIF nif1;
|
||||
|
||||
fec_rx_frame(0, &nif1);
|
||||
}
|
||||
|
||||
void fec1_rx_frame(void)
|
||||
{
|
||||
extern NIF nif1;
|
||||
|
||||
fec_rx_frame(1, &nif1);
|
||||
}
|
||||
|
||||
@@ -1078,6 +1076,7 @@ int fec1_send(NIF *nif, uint8_t *dst, uint8_t *src, uint16_t type, NBUF *nbuf)
|
||||
{
|
||||
return fec_send(1, nif, dst, src, type, nbuf);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/*
|
||||
* Enable interrupts on the selected FEC
|
||||
@@ -1387,5 +1386,4 @@ void fec_eth_stop(uint8_t ch)
|
||||
*/
|
||||
set_ipl(level);
|
||||
}
|
||||
/********************************************************************/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user