1
0
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:
Maxim Anisimov
2018-10-11 09:36:40 +00:00
parent 1f6bc8ee2f
commit 9c61b01487
6 changed files with 103 additions and 107 deletions

View File

@ -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);

View File

@ -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,9 +166,8 @@ 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)
#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];
@ -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;
@ -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);
}*/
/*-----------------------------------------------------------------------------------*/
/** @} */

View File

@ -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) {

View File

@ -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.
*

View File

@ -17,16 +17,14 @@
#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;
if ( uip_len == 0 ) {
for(i = 0; i < UIP_CONNS; i++){
uip_periodic(i);
if(uip_len > 0){
uip_arp_out();
NetSendHttpd();
@ -37,21 +35,6 @@ void HttpdHandler(void){
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();
}
}
}
}
// start http daemon

View File

@ -1810,8 +1810,6 @@ 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;
@ -1828,11 +1826,12 @@ void NetSendHttpd( void ){
}
void NetReceiveHttpd( volatile uchar * inpkt, int len ) {
struct uip_eth_hdr *eth_hdr = (struct uip_eth_hdr *)uip_buf;
memcpy(uip_buf, (const void *)inpkt, len);
uip_len = len;
if ( BUF->type == htons( UIP_ETHTYPE_IP ) ) {
if(eth_hdr->type == htons(UIP_ETHTYPE_IP)){
uip_arp_ipin();
uip_input();
@ -1840,8 +1839,7 @@ void NetReceiveHttpd( volatile uchar * inpkt, int len ) {
uip_arp_out();
NetSendHttpd();
}
} else if( BUF->type == htons( UIP_ETHTYPE_ARP ) ) {
} else if(eth_hdr->type == htons(UIP_ETHTYPE_ARP)){
uip_arp_arpin();
if(uip_len > 0){
@ -1925,7 +1923,7 @@ restart2:
} else {
ethinit_attempt++;
eth_halt();
udelay( 1000000 );
milisecdelay(1000);
}
}
@ -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 );
}