mirror of
https://gitlab.com/dm38/padavan-ng.git
synced 2024-02-13 08:34:03 +08:00
uboot: code cleaning
This commit is contained in:
@ -93,6 +93,25 @@ tapdev_init(void)
|
||||
|
||||
lasttime = 0;
|
||||
}
|
||||
|
||||
void dump_mem(int type, int len)
|
||||
{
|
||||
#if DUMP == 1
|
||||
int i;
|
||||
for(i = 0; i < len; i++)
|
||||
printf("%c", uip_buf[i]);
|
||||
if(type)
|
||||
{
|
||||
printf("\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01");
|
||||
printf("\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01");
|
||||
} else {
|
||||
printf("\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02");
|
||||
printf("\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02");
|
||||
}
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned int
|
||||
tapdev_read(void)
|
||||
@ -125,7 +144,7 @@ tapdev_read(void)
|
||||
}
|
||||
gettimeofday(&tv, &tz);
|
||||
lasttime += (tv.tv_sec - now.tv_sec) * 1000000 + (tv.tv_usec - now.tv_usec);
|
||||
|
||||
dump_mem(0, ret);
|
||||
return ret;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -163,6 +182,8 @@ tapdev_send(void)
|
||||
ret = writev(fd, iov, 2);
|
||||
}
|
||||
#endif
|
||||
dump_mem(1, ret);
|
||||
|
||||
if(ret == -1) {
|
||||
perror("tap_dev: tapdev_send: writev");
|
||||
exit(1);
|
||||
|
@ -73,18 +73,18 @@ header fields and finally send the packet back to the peer.
|
||||
|
||||
/* The IP address of this host. If it is defined to be fixed (by setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set here. Otherwise, the address */
|
||||
#if UIP_FIXEDADDR > 0
|
||||
const u16_t uip_hostaddr[2] =
|
||||
const unsigned short int uip_hostaddr[2] =
|
||||
{HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
|
||||
HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
|
||||
const u16_t uip_arp_draddr[2] =
|
||||
const unsigned short int uip_arp_draddr[2] =
|
||||
{HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
|
||||
HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
|
||||
const u16_t uip_arp_netmask[2] =
|
||||
const unsigned short int uip_arp_netmask[2] =
|
||||
{HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
|
||||
HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
|
||||
#else
|
||||
u16_t uip_hostaddr[2];
|
||||
u16_t uip_arp_draddr[2], uip_arp_netmask[2];
|
||||
unsigned short int uip_hostaddr[2];
|
||||
unsigned short int uip_arp_draddr[2], uip_arp_netmask[2];
|
||||
#endif /* UIP_FIXEDADDR */
|
||||
|
||||
u8_t uip_buf[UIP_BUFSIZE+2]; /* The packet buffer that contains
|
||||
@ -100,7 +100,7 @@ volatile u8_t *uip_urgdata; /* The uip_urgdata pointer points to
|
||||
volatile u8_t uip_urglen, uip_surglen;
|
||||
#endif /* UIP_URGDATA > 0 */
|
||||
|
||||
volatile u16_t uip_len, uip_slen;
|
||||
volatile unsigned short int uip_len, uip_slen;
|
||||
/* The uip_len is either 8 or 16 bits,
|
||||
depending on the maximum packet
|
||||
size. */
|
||||
@ -114,7 +114,7 @@ struct uip_conn *uip_conn; /* uip_conn always points to the current
|
||||
struct uip_conn uip_conns[UIP_CONNS];
|
||||
/* The uip_conns array holds all TCP
|
||||
connections. */
|
||||
u16_t uip_listenports[UIP_LISTENPORTS];
|
||||
unsigned short int uip_listenports[UIP_LISTENPORTS];
|
||||
/* The uip_listenports list all currently
|
||||
listning ports. */
|
||||
#if UIP_UDP
|
||||
@ -123,7 +123,7 @@ struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
|
||||
#endif /* UIP_UDP */
|
||||
|
||||
|
||||
static u16_t ipid; /* Ths ipid variable is an increasing
|
||||
static unsigned short int ipid; /* Ths ipid variable is an increasing
|
||||
number that is used for the IP ID
|
||||
field. */
|
||||
|
||||
@ -131,14 +131,14 @@ static u8_t iss[4]; /* The iss variable is used for the TCP
|
||||
initial sequence number. */
|
||||
|
||||
#if UIP_ACTIVE_OPEN
|
||||
static u16_t lastport; /* Keeps track of the last port used for
|
||||
static unsigned short int lastport; /* Keeps track of the last port used for
|
||||
a new connection. */
|
||||
#endif /* UIP_ACTIVE_OPEN */
|
||||
|
||||
/* Temporary variables. */
|
||||
volatile u8_t uip_acc32[4];
|
||||
static u8_t c, opt;
|
||||
static u16_t tmp16;
|
||||
static unsigned short int tmp16;
|
||||
|
||||
/* Structures and definitions. */
|
||||
#define TCP_FIN 0x01
|
||||
@ -166,11 +166,10 @@ struct uip_stats uip_stat;
|
||||
#endif /* UIP_STATISTICS == 1 */
|
||||
|
||||
#if UIP_LOGGING == 1
|
||||
#include <stdio.h>
|
||||
void uip_log(char *msg);
|
||||
#define UIP_LOG(m) uip_log(m)
|
||||
extern void puts(const char *s);
|
||||
#define UIP_LOG(m) puts(m)
|
||||
#else
|
||||
#define UIP_LOG( m )
|
||||
#define UIP_LOG(m)
|
||||
#endif /* UIP_LOGGING == 1 */
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -203,7 +202,7 @@ uip_init(void)
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if UIP_ACTIVE_OPEN
|
||||
struct uip_conn *
|
||||
uip_connect(u16_t *ripaddr, u16_t rport)
|
||||
uip_connect(unsigned short int *ripaddr, unsigned short int rport)
|
||||
{
|
||||
register struct uip_conn *conn, *cconn;
|
||||
|
||||
@ -271,7 +270,7 @@ uip_connect(u16_t *ripaddr, u16_t rport)
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if UIP_UDP
|
||||
struct uip_udp_conn *
|
||||
uip_udp_new(u16_t *ripaddr, u16_t rport)
|
||||
uip_udp_new(unsigned short int *ripaddr, unsigned short int rport)
|
||||
{
|
||||
register struct uip_udp_conn *conn;
|
||||
|
||||
@ -312,7 +311,7 @@ uip_udp_new(u16_t *ripaddr, u16_t rport)
|
||||
#endif /* UIP_UDP */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
uip_unlisten(u16_t port)
|
||||
uip_unlisten(unsigned short int port)
|
||||
{
|
||||
for(c = 0; c < UIP_LISTENPORTS; ++c) {
|
||||
if(uip_listenports[c] == port) {
|
||||
@ -323,7 +322,7 @@ uip_unlisten(u16_t port)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
uip_listen(u16_t port)
|
||||
uip_listen(unsigned short int port)
|
||||
{
|
||||
for(c = 0; c < UIP_LISTENPORTS; ++c) {
|
||||
if(uip_listenports[c] == 0) {
|
||||
@ -341,7 +340,7 @@ static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
|
||||
static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
|
||||
static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
|
||||
0x0f, 0x07, 0x03, 0x01};
|
||||
static u16_t uip_reasslen;
|
||||
static unsigned short int uip_reasslen;
|
||||
static u8_t uip_reassflags;
|
||||
#define UIP_REASS_FLAG_LASTFRAG 0x01
|
||||
static u8_t uip_reasstmr;
|
||||
@ -352,8 +351,8 @@ static u8_t uip_reasstmr;
|
||||
static u8_t
|
||||
uip_reass(void)
|
||||
{
|
||||
u16_t offset, len;
|
||||
u16_t i;
|
||||
unsigned short int offset, len;
|
||||
unsigned short int i;
|
||||
|
||||
/* If ip_reasstmr is zero, no packet is present in the buffer, so we
|
||||
write the IP header of the fragment into the reassembly
|
||||
@ -467,7 +466,7 @@ uip_reass(void)
|
||||
#endif /* UIP_REASSEMBL */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
uip_add_rcv_nxt(u16_t n)
|
||||
uip_add_rcv_nxt(unsigned short int n)
|
||||
{
|
||||
uip_add32(uip_conn->rcv_nxt, n);
|
||||
uip_conn->rcv_nxt[0] = uip_acc32[0];
|
||||
@ -693,7 +692,7 @@ uip_process(u8_t flag)
|
||||
goto drop;
|
||||
}
|
||||
|
||||
// icmp_input:
|
||||
//icmp_input:
|
||||
UIP_STAT(++uip_stat.icmp.recv);
|
||||
|
||||
/* ICMP echo (i.e., ping) processing. This is simple, we only change
|
||||
@ -978,8 +977,8 @@ uip_process(u8_t flag)
|
||||
} else if(opt == 0x02 &&
|
||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0x04) {
|
||||
/* An MSS option with the right option length. */
|
||||
tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
||||
(u16_t)uip_buf[40 + UIP_LLH_LEN + 3 + c];
|
||||
tmp16 = ((unsigned short int)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
||||
(unsigned short int)uip_buf[40 + UIP_LLH_LEN + 3 + c];
|
||||
uip_connr->initialmss = uip_connr->mss =
|
||||
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
||||
|
||||
@ -1249,7 +1248,7 @@ uip_process(u8_t flag)
|
||||
and the application will retransmit it. This is called the
|
||||
"persistent timer" and uses the retransmission mechanim.
|
||||
*/
|
||||
tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1];
|
||||
tmp16 = ((unsigned short int)BUF->wnd[0] << 8) + (unsigned short int)BUF->wnd[1];
|
||||
if(tmp16 > uip_connr->initialmss ||
|
||||
tmp16 == 0) {
|
||||
tmp16 = uip_connr->initialmss;
|
||||
@ -1272,13 +1271,13 @@ uip_process(u8_t flag)
|
||||
put into the uip_appdata and the length of the data should be
|
||||
put into uip_len. If the application don't have any data to
|
||||
send, uip_len must be set to 0. */
|
||||
if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
|
||||
if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
|
||||
uip_slen = 0;
|
||||
UIP_APPCALL();
|
||||
|
||||
appsend:
|
||||
|
||||
if(uip_flags & UIP_ABORT) {
|
||||
if(uip_flags & UIP_ABORT) {
|
||||
uip_slen = 0;
|
||||
uip_connr->tcpstateflags = CLOSED;
|
||||
BUF->flags = TCP_RST | TCP_ACK;
|
||||
@ -1294,7 +1293,7 @@ uip_process(u8_t flag)
|
||||
goto tcp_send_nodata;
|
||||
}
|
||||
|
||||
/* If uip_slen > 0, the application has data to be sent. */
|
||||
/* If uip_slen > 0, the application has data to be sent. */
|
||||
if(uip_slen > 0) {
|
||||
|
||||
/* If the connection has acknowledged data, the contents of
|
||||
@ -1312,7 +1311,7 @@ uip_process(u8_t flag)
|
||||
the mss (the minumum of the MSS and the available
|
||||
window). */
|
||||
if(uip_slen > uip_connr->mss) {
|
||||
uip_slen = uip_connr->mss;
|
||||
uip_slen = uip_connr->mss;
|
||||
}
|
||||
|
||||
/* Remember how much data we send out now so that we know
|
||||
@ -1331,7 +1330,7 @@ uip_process(u8_t flag)
|
||||
uip_connr->nrtx = 0;
|
||||
apprexmit:
|
||||
uip_appdata = uip_sappdata;
|
||||
|
||||
|
||||
/* If the application has data to be sent, or if the incoming
|
||||
packet had new data in it, we must send out a packet. */
|
||||
if(uip_slen > 0 && uip_connr->len > 0) {
|
||||
@ -1350,7 +1349,7 @@ uip_process(u8_t flag)
|
||||
goto tcp_send_noopts;
|
||||
}
|
||||
}
|
||||
goto drop;
|
||||
goto drop;
|
||||
case LAST_ACK:
|
||||
/* We can close this connection if the peer has acknowledged our
|
||||
FIN. This is indicated by the UIP_ACKDATA flag. */
|
||||
@ -1471,7 +1470,7 @@ uip_process(u8_t flag)
|
||||
BUF->tcpchksum = 0;
|
||||
BUF->tcpchksum = ~(uip_tcpchksum());
|
||||
|
||||
// ip_send_nolen:
|
||||
//ip_send_nolen:
|
||||
|
||||
BUF->vhl = 0x45;
|
||||
BUF->tos = 0;
|
||||
@ -1495,10 +1494,10 @@ uip_process(u8_t flag)
|
||||
return;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
//u16_t
|
||||
//htons(u16_t val)
|
||||
//{
|
||||
// return HTONS(val);
|
||||
//}
|
||||
/*unsigned short int
|
||||
htons(unsigned short int val)
|
||||
{
|
||||
return HTONS(val);
|
||||
}*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
@ -61,8 +61,6 @@
|
||||
|
||||
#include "uip_arp.h"
|
||||
|
||||
//#include <string.h>
|
||||
|
||||
struct arp_hdr {
|
||||
struct uip_eth_hdr ethhdr;
|
||||
u16_t hwtype;
|
||||
@ -144,7 +142,7 @@ uip_arp_init(void)
|
||||
void
|
||||
uip_arp_timer(void)
|
||||
{
|
||||
struct arp_entry *tabptr = 0;
|
||||
struct arp_entry *tabptr;
|
||||
|
||||
++arptime;
|
||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
||||
@ -284,7 +282,7 @@ uip_arp_arpin(void)
|
||||
}
|
||||
|
||||
uip_len = 0;
|
||||
|
||||
|
||||
switch(BUF->opcode) {
|
||||
case HTONS(ARP_REQUEST):
|
||||
/* ARP request. If it asked for our address, we send out a
|
||||
|
@ -480,7 +480,6 @@ void uip_log(char *msg);
|
||||
* which are big endian. The BYTE_ORDER macro should be changed to
|
||||
* reflect the CPU architecture on which uIP is to be run.
|
||||
*/
|
||||
|
||||
#ifndef LITTLE_ENDIAN
|
||||
#define LITTLE_ENDIAN 3412
|
||||
#endif /* LITTLE_ENDIAN */
|
||||
@ -488,7 +487,6 @@ void uip_log(char *msg);
|
||||
#define BIG_ENDIAN 1234
|
||||
#endif /* BIGE_ENDIAN */
|
||||
|
||||
|
||||
/**
|
||||
* The byte order of the CPU architecture on which uIP is to be run.
|
||||
*
|
||||
|
@ -17,41 +17,24 @@
|
||||
#include "../httpd/uip.h"
|
||||
#include "../httpd/uip_arp.h"
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
static int arptimer = 0;
|
||||
|
||||
void HttpdHandler(void){
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if ( uip_len == 0 ) {
|
||||
for ( i = 0; i < UIP_CONNS; i++ ) {
|
||||
uip_periodic( i );
|
||||
if ( uip_len > 0 ) {
|
||||
uip_arp_out();
|
||||
NetSendHttpd();
|
||||
}
|
||||
}
|
||||
for(i = 0; i < UIP_CONNS; i++){
|
||||
uip_periodic(i);
|
||||
|
||||
if ( ++arptimer == 20 ) {
|
||||
uip_arp_timer();
|
||||
arptimer = 0;
|
||||
}
|
||||
} else {
|
||||
if ( BUF->type == htons( UIP_ETHTYPE_IP ) ) {
|
||||
uip_arp_ipin();
|
||||
uip_input();
|
||||
if ( uip_len > 0 ) {
|
||||
uip_arp_out();
|
||||
NetSendHttpd();
|
||||
}
|
||||
} else if ( BUF->type == htons( UIP_ETHTYPE_ARP ) ) {
|
||||
uip_arp_arpin();
|
||||
if ( uip_len > 0 ) {
|
||||
NetSendHttpd();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(uip_len > 0){
|
||||
uip_arp_out();
|
||||
NetSendHttpd();
|
||||
}
|
||||
}
|
||||
|
||||
if(++arptimer == 20){
|
||||
uip_arp_timer();
|
||||
arptimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// start http daemon
|
||||
|
@ -1810,44 +1810,42 @@ IPaddr_t getenv_IPaddr (char *var)
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_HTTPD)
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
void NetSendHttpd( void ){
|
||||
volatile uchar *tmpbuf = NetTxPacket;
|
||||
int i;
|
||||
volatile uchar *tmpbuf = NetTxPacket;
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < 40 + UIP_LLH_LEN; i++ ) {
|
||||
tmpbuf[i] = uip_buf[i];
|
||||
}
|
||||
for(i = 0; i < 40 + UIP_LLH_LEN; i++){
|
||||
tmpbuf[i] = uip_buf[i];
|
||||
}
|
||||
|
||||
for( ; i < uip_len; i++ ) {
|
||||
tmpbuf[i] = uip_appdata[ i - 40 - UIP_LLH_LEN ];
|
||||
}
|
||||
for(; i < uip_len; i++){
|
||||
tmpbuf[i] = uip_appdata[i - 40 - UIP_LLH_LEN];
|
||||
}
|
||||
|
||||
eth_send( NetTxPacket, uip_len );
|
||||
eth_send(NetTxPacket, uip_len);
|
||||
}
|
||||
|
||||
void NetReceiveHttpd( volatile uchar * inpkt, int len ) {
|
||||
memcpy( uip_buf, ( const void * )inpkt, len );
|
||||
uip_len = len;
|
||||
struct uip_eth_hdr *eth_hdr = (struct uip_eth_hdr *)uip_buf;
|
||||
|
||||
if ( BUF->type == htons( UIP_ETHTYPE_IP ) ) {
|
||||
memcpy(uip_buf, (const void *)inpkt, len);
|
||||
uip_len = len;
|
||||
|
||||
uip_arp_ipin();
|
||||
uip_input();
|
||||
if(eth_hdr->type == htons(UIP_ETHTYPE_IP)){
|
||||
uip_arp_ipin();
|
||||
uip_input();
|
||||
|
||||
if ( uip_len > 0 ) {
|
||||
uip_arp_out();
|
||||
NetSendHttpd();
|
||||
}
|
||||
} else if( BUF->type == htons( UIP_ETHTYPE_ARP ) ) {
|
||||
if(uip_len > 0){
|
||||
uip_arp_out();
|
||||
NetSendHttpd();
|
||||
}
|
||||
} else if(eth_hdr->type == htons(UIP_ETHTYPE_ARP)){
|
||||
uip_arp_arpin();
|
||||
|
||||
uip_arp_arpin();
|
||||
|
||||
if ( uip_len > 0 ) {
|
||||
NetSendHttpd();
|
||||
}
|
||||
}
|
||||
if(uip_len > 0){
|
||||
NetSendHttpd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* *************************************
|
||||
@ -1925,7 +1923,7 @@ restart2:
|
||||
} else {
|
||||
ethinit_attempt++;
|
||||
eth_halt();
|
||||
udelay( 1000000 );
|
||||
milisecdelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1992,7 +1990,7 @@ restart2:
|
||||
ulong led_time = get_timer(0);
|
||||
|
||||
// infinite loop
|
||||
for ( ; ; ) {
|
||||
for (;;) {
|
||||
if (get_timer(led_time) > (CFG_HZ/5)) {
|
||||
LED_ALERT_BLINK();
|
||||
led_time = get_timer(0);
|
||||
@ -2037,10 +2035,9 @@ restart2:
|
||||
|
||||
// try to make upgrade!
|
||||
if ( do_http_upgrade( NetBootFileXferSize, webfailsafe_upgrade_type ) >= 0 ) {
|
||||
udelay( 500000 );
|
||||
milisecdelay(500);
|
||||
do_http_progress( WEBFAILSAFE_PROGRESS_UPGRADE_READY );
|
||||
udelay( 500000 );
|
||||
|
||||
milisecdelay(500);
|
||||
/* reset the board */
|
||||
do_reset( NULL, 0, 0, NULL );
|
||||
}
|
||||
|
Reference in New Issue
Block a user