2010-04-27 21:05:35 +00:00
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/net/ethernet.h>
|
|
|
|
#include <grub/net/ip.h>
|
|
|
|
#include <grub/net/arp.h>
|
|
|
|
#include <grub/net/ieee1275/interface.h>
|
|
|
|
#include <grub/net/netbuff.h>
|
2010-04-29 20:56:09 +00:00
|
|
|
#include <grub/net/interface.h>
|
2010-06-21 22:15:45 +00:00
|
|
|
#include <grub/net.h>
|
2010-06-29 09:50:15 +00:00
|
|
|
#include <grub/time.h>
|
2010-08-13 17:42:16 +00:00
|
|
|
#include <grub/net/arp.h>
|
2010-04-27 21:05:35 +00:00
|
|
|
|
|
|
|
static grub_err_t
|
2010-06-21 22:15:45 +00:00
|
|
|
send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)),
|
2010-08-13 17:42:16 +00:00
|
|
|
struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb,
|
|
|
|
struct grub_net_addr target_addr, grub_uint16_t ethertype)
|
2010-04-27 21:05:35 +00:00
|
|
|
{
|
|
|
|
|
2010-06-21 22:15:45 +00:00
|
|
|
struct etherhdr *eth;
|
|
|
|
|
|
|
|
grub_netbuff_push (nb,sizeof(*eth));
|
2010-04-27 21:05:35 +00:00
|
|
|
eth = (struct etherhdr *) nb->data;
|
2010-08-13 17:42:16 +00:00
|
|
|
grub_memcpy(eth->dst, target_addr.addr, target_addr.len);
|
|
|
|
grub_memcpy(eth->src, bootp_pckt->chaddr, 6);
|
|
|
|
eth->type = ethertype;
|
2010-06-21 22:15:45 +00:00
|
|
|
|
|
|
|
return send_card_buffer(nb);
|
|
|
|
// return inf->card->driver->send(inf->card,nb);
|
2010-04-27 21:05:35 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 22:15:45 +00:00
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)),
|
2010-08-13 17:42:16 +00:00
|
|
|
struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb,
|
|
|
|
grub_uint16_t ethertype)
|
2010-04-27 21:05:35 +00:00
|
|
|
{
|
2010-06-21 22:15:45 +00:00
|
|
|
struct etherhdr *eth;
|
2010-06-29 09:50:15 +00:00
|
|
|
grub_uint64_t start_time, current_time;
|
2010-07-29 21:17:01 +00:00
|
|
|
struct llchdr *llch;
|
|
|
|
struct snaphdr *snaph;
|
|
|
|
grub_uint16_t type;
|
2010-06-29 09:50:15 +00:00
|
|
|
start_time = grub_get_time_ms();
|
2010-07-29 21:17:01 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
get_card_packet (nb);
|
|
|
|
eth = (struct etherhdr *) nb->data;
|
|
|
|
type = eth->type;
|
|
|
|
grub_netbuff_pull(nb,sizeof (*eth));
|
|
|
|
// grub_printf("ethernet type 58 %x\n",type);
|
|
|
|
// grub_printf("ethernet eth->type 58 %x\n",type);
|
|
|
|
if (eth->type <=1500)
|
|
|
|
{
|
|
|
|
llch = (struct llchdr *) nb->data;
|
|
|
|
type = llch->dsap & LLCADDRMASK;
|
|
|
|
|
|
|
|
if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3)
|
|
|
|
{
|
|
|
|
grub_netbuff_pull (nb,sizeof(*llch));
|
|
|
|
snaph = (struct snaphdr *) nb->data;
|
|
|
|
type = snaph->type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-13 17:42:16 +00:00
|
|
|
/* ARP packet */
|
|
|
|
if (type == ARP_ETHERTYPE)
|
|
|
|
{
|
|
|
|
arp_receive(inf, net_link_inf, nb);
|
|
|
|
if (ethertype == ARP_ETHERTYPE)
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
/* IP packet */
|
|
|
|
else if(type == IP_ETHERTYPE && ethertype == IP_ETHERTYPE)
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
2010-07-29 21:17:01 +00:00
|
|
|
current_time = grub_get_time_ms ();
|
2010-06-29 09:50:15 +00:00
|
|
|
if (current_time - start_time > TIMEOUT_TIME_MS)
|
|
|
|
return grub_error (GRUB_ERR_TIMEOUT, "Time out.");
|
2010-06-21 22:15:45 +00:00
|
|
|
}
|
|
|
|
/* - get ethernet header
|
|
|
|
- verify if the next layer is the desired one.
|
|
|
|
- if not. get another packet.
|
|
|
|
- remove ethernet header from buffer*/
|
2010-08-13 17:42:16 +00:00
|
|
|
return GRUB_ERR_NONE;
|
2010-06-21 22:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct grub_net_link_layer_protocol grub_ethernet_protocol =
|
|
|
|
{
|
|
|
|
.name = "ethernet",
|
|
|
|
.id = GRUB_NET_ETHERNET_ID,
|
2010-08-13 17:42:16 +00:00
|
|
|
.type = ARPHRD_ETHERNET,
|
2010-06-21 22:15:45 +00:00
|
|
|
.send = send_ethernet_packet,
|
|
|
|
.recv = recv_ethernet_packet
|
2010-04-27 21:05:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void ethernet_ini(void)
|
|
|
|
{
|
2010-06-21 22:15:45 +00:00
|
|
|
grub_net_link_layer_protocol_register (&grub_ethernet_protocol);
|
2010-04-27 21:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ethernet_fini(void)
|
|
|
|
{
|
2010-06-21 22:15:45 +00:00
|
|
|
grub_net_link_layer_protocol_unregister (&grub_ethernet_protocol);
|
2010-04-27 21:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|