Clean Debug messages
This commit is contained in:
parent
1edb7287ff
commit
3ec6213b17
8 changed files with 46 additions and 80 deletions
|
@ -56,7 +56,7 @@ grub_ofnet_open (const char *name, grub_disk_t disk)
|
|||
{
|
||||
|
||||
|
||||
if (grub_strcmp (name, "network"))
|
||||
if (grub_strcmp (name, "net"))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a net disk");
|
||||
|
||||
disk->total_sectors = U64MAXSIZE;
|
||||
|
@ -109,7 +109,7 @@ grub_ofnetfs_dir (grub_device_t device ,
|
|||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info) __attribute((unused)))
|
||||
{
|
||||
if(grub_strcmp (device->disk->name,"network"))
|
||||
if(grub_strcmp (device->disk->name,"net"))
|
||||
{
|
||||
return grub_error (GRUB_ERR_BAD_FS, "not an net filesystem");
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ grub_ofnetfs_open (struct grub_file *file , const char *name )
|
|||
//grub_addr_t addr;
|
||||
if (name[0] == '/')
|
||||
name++;
|
||||
if(grub_strcmp (file->device->disk->name,"network"))
|
||||
if(grub_strcmp (file->device->disk->name,"net"))
|
||||
{
|
||||
|
||||
return 1;
|
||||
|
@ -161,80 +161,43 @@ grub_ofnetfs_open (struct grub_file *file , const char *name )
|
|||
grub_netbuff_reserve (pack,80*1024);
|
||||
file_size = app_interface->app_prot->get_file_size(NULL,stack,pack,(char *) name);
|
||||
|
||||
|
||||
for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000)
|
||||
{
|
||||
// grub_printf("trying to claim %d bytes at 0x%x\n",file_size,found_addr);
|
||||
if (grub_claimmap (found_addr , file_size) != -1)
|
||||
break;
|
||||
}
|
||||
// grub_printf("Claimed %d bytes at 0x%x\n",file_size,found_addr);
|
||||
file->data = (void *) found_addr;
|
||||
// grub_printf("file->data = 0x%x\n",(int)file->data);
|
||||
// grub_printf("file_size = %d\n",file_size);
|
||||
// grub_printf("OPEN\n");
|
||||
|
||||
grub_netbuff_clear(pack);
|
||||
grub_netbuff_reserve (pack,80*1024);
|
||||
app_interface->app_prot->open (NULL,stack,pack,(char *) name);
|
||||
|
||||
do {
|
||||
//if (app_interface->app_prot->recv (NULL,stack,pack) == GRUB_ERR_NONE)
|
||||
// grub_printf("RECEIVE PACKET\n");
|
||||
do
|
||||
{
|
||||
grub_netbuff_clear(pack);
|
||||
grub_netbuff_reserve (pack,80*1024);
|
||||
app_interface->app_prot->recv (NULL,stack,pack);
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
// grub_printf("RECEIVED PACKET\n");
|
||||
// {
|
||||
// grub_printf("payload_size= %d\n",pack->tail - pack->data);
|
||||
// grub_printf("amount= %d\n",amount);
|
||||
// grub_printf("file_size= %d\n",file_size);
|
||||
datap = (char *)file->data + amount;
|
||||
amount += (pack->tail - pack->data);
|
||||
// grub_printf("datap = 0x%x\n",(int)datap );
|
||||
grub_memcpy(datap, pack->data, pack->tail - pack->data);
|
||||
// grub_printf("SEND ACK\n");
|
||||
|
||||
goto error;
|
||||
if ((pack->tail - pack->data))
|
||||
{
|
||||
// file->data = grub_realloc(file->data,amount + pack->tail - pack->data);
|
||||
datap = (char *)file->data + amount;
|
||||
amount += (pack->tail - pack->data);
|
||||
grub_memcpy(datap , pack->data, pack->tail - pack->data);
|
||||
}
|
||||
grub_netbuff_clear(pack);
|
||||
grub_netbuff_reserve (pack,80*1024);
|
||||
app_interface->app_prot->send_ack (NULL,stack,pack);
|
||||
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
// grub_printf("SENT ACK\n");
|
||||
//}
|
||||
// file->data = grub_realloc(file->data,amount);
|
||||
goto error;
|
||||
|
||||
}while (amount < file_size);
|
||||
// grub_printf("transfer complete\n");
|
||||
file->size = file_size;
|
||||
file->size = file_size;
|
||||
|
||||
// grub_netbuff_free(pack);
|
||||
/*Start ARP header*/
|
||||
// arp.arpr.hwtype = 0x1; /* hardware type (must be ARPHRD_ETHER) */
|
||||
// arp.arpr.protocol = 0x0800; /* protocol type (must be ETH_P_IP) */
|
||||
// arp.arpr.hwlen = 0x6; /* hardware address length (must be 6) */
|
||||
// arp.arpr.protolen = 0x4; /* protocol address length (must be 4) */
|
||||
// arp.arpr.opcode = 0x1; /* ARP opcode */
|
||||
|
||||
|
||||
/*arp.arpr.shwaddr[0] =0x0a ;
|
||||
arp.arpr.shwaddr[1] =0x11 ;
|
||||
arp.arpr.shwaddr[2] =0xbd ;
|
||||
arp.arpr.shwaddr[3] =0xe3 ;
|
||||
arp.arpr.shwaddr[4] =0xe3 ;
|
||||
arp.arpr.shwaddr[5] =0x04 ;
|
||||
arp.arpr.sipaddr = dhcp_pckt -> yiaddr; */ /* sender's IP address */
|
||||
/*arp.arpr.thwaddr[0] =0;
|
||||
arp.arpr.thwaddr[1] =0;
|
||||
arp.arpr.thwaddr[2] =0;
|
||||
arp.arpr.thwaddr[3] =0;
|
||||
arp.arpr.thwaddr[4] =0;
|
||||
arp.arpr.thwaddr[5] =0;
|
||||
arp.arpr.tipaddr = dhcp_pckt -> siaddr; */ /* target's IP address */
|
||||
/*END ARP header */
|
||||
error:
|
||||
grub_netbuff_free(pack);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#define UDP_PCKT 0x11
|
||||
#define IP_PCKT 0x0800
|
||||
#define TIMEOUT_TIME_MS 3*1000
|
||||
typedef enum
|
||||
{
|
||||
GRUB_NET_TFTP_ID,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <grub/net/netbuff.h>
|
||||
#include <grub/net/interface.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
static grub_err_t
|
||||
send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)),
|
||||
|
@ -42,6 +43,8 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__
|
|||
struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb)
|
||||
{
|
||||
struct etherhdr *eth;
|
||||
grub_uint64_t start_time, current_time;
|
||||
start_time = grub_get_time_ms();
|
||||
while (1)
|
||||
{
|
||||
get_card_packet (nb);
|
||||
|
@ -59,6 +62,9 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__
|
|||
grub_netbuff_pull(nb,sizeof(*eth));
|
||||
return 0;
|
||||
}
|
||||
current_time = grub_get_time_ms();
|
||||
if (current_time - start_time > TIMEOUT_TIME_MS)
|
||||
return grub_error (GRUB_ERR_TIMEOUT, "Time out.");
|
||||
}
|
||||
/* - get ethernet header
|
||||
- verify if the next layer is the desired one.
|
||||
|
|
|
@ -29,9 +29,7 @@ int send_card_buffer (struct grub_net_buff *pack)
|
|||
{
|
||||
|
||||
int actual;
|
||||
//grub_printf("packet size transmited: %d\n",pack->tail - pack->data);
|
||||
grub_ieee1275_write (handle,pack->data,pack->tail - pack->data,&actual);
|
||||
// grub_printf("actual transmited %d\n",actual);
|
||||
|
||||
return actual;
|
||||
}
|
||||
|
@ -50,18 +48,11 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused)))
|
|||
do
|
||||
{
|
||||
grub_ieee1275_read (handle,datap,sizeof (*eth),&actual);
|
||||
// if (actual <= 0)
|
||||
// grub_millisleep(10);
|
||||
|
||||
}while (actual <= 0);
|
||||
eth = (struct etherhdr *) datap;
|
||||
datap += sizeof(*eth);
|
||||
|
||||
// grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0],
|
||||
// eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]);
|
||||
// grub_printf("ethernet eth->src %x:%x:%x:%x:%x:%x\n",eth->src[0],eth->src[1],
|
||||
// eth->src[2],eth->src[3],eth->src[4],eth->src[5]);
|
||||
// grub_printf ("eth.type 0x%x\n",eth->type);
|
||||
|
||||
switch (eth->type)
|
||||
{
|
||||
|
@ -77,10 +68,6 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused)))
|
|||
iph = (struct iphdr *) datap;
|
||||
datap += sizeof(*iph);
|
||||
|
||||
// grub_printf("ip.src 0x%x\n",iph->src);
|
||||
// grub_printf("ip.dst 0x%x\n",iph->dest);
|
||||
// grub_printf("ip.len 0x%x\n",iph->len);
|
||||
// grub_printf("ip.protocol 0x%x\n",iph->protocol);
|
||||
|
||||
grub_ieee1275_read (handle,datap,iph->len - sizeof (*iph),&actual);
|
||||
|
||||
|
@ -89,11 +76,8 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused)))
|
|||
break;
|
||||
|
||||
case 0x86DD:
|
||||
grub_printf("!!!!!!!!!!!!!!!!!IPV6 packet received!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
||||
grub_ieee1275_read (handle,datap,sizeof (*ip6h),&actual);
|
||||
ip6h = (struct ip6hdr *) datap;
|
||||
grub_printf("ip6hdr->payload_len = %x\n",ip6h->payload_len);
|
||||
grub_printf("ip6hdr->nexthdr = %x\n",ip6h->nexthdr);
|
||||
|
||||
datap += sizeof(*ip6h);
|
||||
grub_ieee1275_read (handle,datap,ip6h->payload_len - sizeof (*ip6h),&actual);
|
||||
|
|
7
net/ip.c
7
net/ip.c
|
@ -7,6 +7,7 @@
|
|||
#include <grub/net.h>
|
||||
#include <grub/net/netbuff.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
struct grub_net_protocol *grub_ipv4_prot;
|
||||
|
||||
|
@ -65,6 +66,8 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf,
|
|||
{
|
||||
|
||||
struct iphdr *iph;
|
||||
grub_uint64_t start_time, current_time;
|
||||
start_time = grub_get_time_ms();
|
||||
while (1)
|
||||
{
|
||||
trans_net_inf->inner_layer->link_prot->recv(inf,trans_net_inf->inner_layer,nb);
|
||||
|
@ -74,6 +77,10 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf,
|
|||
grub_netbuff_pull(nb,sizeof(*iph));
|
||||
return 0;
|
||||
}
|
||||
|
||||
current_time = grub_get_time_ms();
|
||||
if (current_time - start_time > TIMEOUT_TIME_MS)
|
||||
return grub_error (GRUB_ERR_TIMEOUT, "Time out.");
|
||||
}
|
||||
/* grub_printf("ip.src 0x%x\n",iph->src);
|
||||
grub_printf("ip.dst 0x%x\n",iph->dest);
|
||||
|
|
|
@ -41,11 +41,6 @@ grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len)
|
|||
grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len)
|
||||
{
|
||||
net_buff->data -= len;
|
||||
/* grub_printf("push len =%d\n",len);
|
||||
grub_printf("pack->head =%x\n",(unsigned int)net_buff->head);
|
||||
grub_printf("pack->data =%x\n",(unsigned int)net_buff->data);
|
||||
grub_printf("pack->tail =%x\n",(unsigned int)net_buff->tail);
|
||||
grub_printf("pack->end =%x\n",(unsigned int)net_buff->end);*/
|
||||
if (net_buff->data < net_buff->head)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "push out of the packet range.");
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -87,7 +82,7 @@ struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len )
|
|||
|
||||
grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff)
|
||||
{
|
||||
grub_free (net_buff);
|
||||
grub_free (net_buff->head);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)),
|
|||
grub_netbuff_push (nb,sizeof (*tftph));
|
||||
|
||||
udp_interf = (struct udp_interf *) app_interface->data;
|
||||
udp_interf->src = TFTP_CLIENT_PORT + rrq_count++;
|
||||
udp_interf->src = TFTP_CLIENT_PORT;// + rrq_count++;
|
||||
udp_interf->dst = TFTP_SERVER_PORT;
|
||||
tftph = (struct tftphdr *) nb->data;
|
||||
|
||||
|
@ -112,6 +112,8 @@ tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)),
|
|||
|
||||
app_interface->trans_prot->send (inf,protstack->interface,nb);
|
||||
/*Receive OACK*/
|
||||
grub_netbuff_clear (nb);
|
||||
grub_netbuff_reserve (nb,80*1024);
|
||||
return app_interface->app_prot->recv(inf,protstack,nb);
|
||||
}
|
||||
|
||||
|
@ -211,6 +213,8 @@ static int tftp_file_size (struct grub_net_network_layer_interface* inf ,
|
|||
{
|
||||
|
||||
tftp_open (inf, protocol_stack,nb, filename);
|
||||
grub_netbuff_clear (nb);
|
||||
grub_netbuff_reserve (nb,80*1024);
|
||||
tftp_send_err (inf, protocol_stack,nb,"Abort transference.",0);
|
||||
|
||||
return tftp_file.size;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <grub/net/netbuff.h>
|
||||
#include <grub/net/protocol.h>
|
||||
#include <grub/net/interface.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
static grub_err_t
|
||||
send_udp_packet (struct grub_net_network_layer_interface *inf,
|
||||
|
@ -35,7 +36,8 @@ receive_udp_packet (struct grub_net_network_layer_interface *inf,
|
|||
struct udphdr *udph;
|
||||
struct udp_interf *udp_interf;
|
||||
udp_interf = (struct udp_interf *) app_trans_inf->data;
|
||||
|
||||
grub_uint64_t start_time, current_time;
|
||||
start_time = grub_get_time_ms();
|
||||
while(1)
|
||||
{
|
||||
app_trans_inf->inner_layer->net_prot->recv(inf,app_trans_inf->inner_layer,nb);
|
||||
|
@ -62,6 +64,10 @@ receive_udp_packet (struct grub_net_network_layer_interface *inf,
|
|||
|
||||
return 0;
|
||||
}
|
||||
current_time = grub_get_time_ms();
|
||||
if (current_time - start_time > TIMEOUT_TIME_MS)
|
||||
return grub_error (GRUB_ERR_TIMEOUT, "Time out.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue