Implement the size field.

This commit is contained in:
Manoel R. Abranches 2010-07-29 18:17:01 -03:00
parent 17ef14c916
commit 7c978f0690
2 changed files with 58 additions and 31 deletions

View file

@ -1,11 +1,31 @@
#ifndef GRUB_NET_ETHERNET_HEADER #ifndef GRUB_NET_ETHERNET_HEADER
#define GRUB_NET_ETHERNET_HEADER 1 #define GRUB_NET_ETHERNET_HEADER 1
#include <grub/misc.h> #include <grub/misc.h>
struct etherhdr { #define LLCADDRMASK 0x7f
struct etherhdr
{
grub_uint8_t dst[6]; grub_uint8_t dst[6];
grub_uint8_t src[6]; grub_uint8_t src[6];
grub_uint16_t type; grub_uint16_t type;
} __attribute__ ((packed)) ; } __attribute__ ((packed));
#define PCP (x) x & 0xe000
#define CFI (x) x & 0x1000
#define VID (x) x & 0x0fff
struct llchdr
{
grub_uint8_t dsap;
grub_uint8_t ssap;
grub_uint8_t ctrl;
} __attribute__ ((packed));
struct snaphdr
{
grub_uint8_t oui[3];
grub_uint16_t type;
} __attribute__ ((packed));
void ethernet_ini(void); void ethernet_ini(void);
void ethernet_fini(void); void ethernet_fini(void);

View file

@ -18,19 +18,13 @@ send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__
grub_netbuff_push (nb,sizeof(*eth)); grub_netbuff_push (nb,sizeof(*eth));
eth = (struct etherhdr *) nb->data; eth = (struct etherhdr *) nb->data;
eth->dst[0] =0x00; eth->dst[0] = 0x00;
eth->dst[1] =0x11; eth->dst[1] = 0x11;
eth->dst[2] =0x25; eth->dst[2] = 0x25;
eth->dst[3] =0xca; eth->dst[3] = 0xca;
eth->dst[4] =0x1f; eth->dst[4] = 0x1f;
eth->dst[5] =0x01; eth->dst[5] = 0x01;
eth->src[0] =0x0a; grub_memcpy (eth->src, bootp_pckt -> chaddr,6);
eth->src[1] =0x11;
eth->src[2] =0xbd;
eth->src[3] =0xe3;
eth->src[4] =0xe3;
eth->src[5] =0x04;
eth->type = 0x0800; eth->type = 0x0800;
return send_card_buffer(nb); return send_card_buffer(nb);
@ -44,25 +38,38 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__
{ {
struct etherhdr *eth; struct etherhdr *eth;
grub_uint64_t start_time, current_time; grub_uint64_t start_time, current_time;
struct llchdr *llch;
struct snaphdr *snaph;
grub_uint16_t type;
start_time = grub_get_time_ms(); start_time = grub_get_time_ms();
while (1) while (1)
{ {
get_card_packet (nb); get_card_packet (nb);
eth = (struct etherhdr *) nb->data; eth = (struct etherhdr *) nb->data;
/*change for grub_memcmp*/ type = eth->type;
if( eth->src[0] == 0x00 && eth->src[1] == 0x11 && eth->src[2] == 0x25 && grub_netbuff_pull(nb,sizeof (*eth));
eth->src[3] == 0xca && eth->src[4] == 0x1f && eth->src[5] == 0x01 && eth->type == 0x800) // grub_printf("ethernet type 58 %x\n",type);
// grub_printf("ethernet eth->type 58 %x\n",type);
if (eth->type <=1500)
{ {
//grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0], llch = (struct llchdr *) nb->data;
// eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]); type = llch->dsap & LLCADDRMASK;
// 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]); if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3)
//grub_printf("ethernet eth->type 0x%x\n",eth->type); {
//grub_printf("out from ethernet\n"); grub_netbuff_pull (nb,sizeof(*llch));
grub_netbuff_pull(nb,sizeof(*eth)); snaph = (struct snaphdr *) nb->data;
return 0; type = snaph->type;
} }
current_time = grub_get_time_ms(); }
/*change for grub_memcmp*/
//if( eth->src[0] == 0x00 && eth->src[1] == 0x11 && eth->src[2] == 0x25 &&
// eth->src[3] == 0xca && eth->src[4] == 0x1f && eth->src[5] == 0x01 && type == 0x800)
if(type == 0x800)
return 0;
current_time = grub_get_time_ms ();
if (current_time - start_time > TIMEOUT_TIME_MS) if (current_time - start_time > TIMEOUT_TIME_MS)
return grub_error (GRUB_ERR_TIMEOUT, "Time out."); return grub_error (GRUB_ERR_TIMEOUT, "Time out.");
} }