From 8d402bc9a8041f0ed15290901e0ff5f115ed5cc0 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 29 Apr 2010 17:56:09 -0300 Subject: [PATCH] small change in the interface structure. --- include/grub/net.h | 14 ++++++++++++++ include/grub/net/interface.h | 18 ++++++++++++++---- include/grub/net/protocol.h | 33 +++++++++------------------------ net/ethernet.c | 3 ++- net/ip.c | 5 +++-- net/tftp.c | 5 +++-- net/udp.c | 5 +++-- 7 files changed, 48 insertions(+), 35 deletions(-) diff --git a/include/grub/net.h b/include/grub/net.h index 75efd51d6..f021f0e9c 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -26,8 +26,22 @@ struct grub_net_card; +typedef enum +{ + GRUB_NET_TFTP_ID, + GRUB_NET_UDP_ID, + GRUB_NET_IPV4_ID, + GRUB_NET_IPV6_ID, + GRUB_NET_ETHERNET_ID, + GRUB_NET_ARP_ID, + GRUB_NET_DHCP_ID + +}protocol_type_t; + struct grub_net_card_driver { + grub_err_t (*init) (struct grub_net_card *dev); + grub_err_t (*fini) (struct grub_net_card *dev); grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb); grub_size_t (*recv) (struct grub_net_card *dev,struct grub_net_buff *nb); }; diff --git a/include/grub/net/interface.h b/include/grub/net/interface.h index 0e11c86ba..2e0ddfcc8 100644 --- a/include/grub/net/interface.h +++ b/include/grub/net/interface.h @@ -2,16 +2,26 @@ #define GRUB_INTERFACE_HEADER #include #include -/* -extern struct grub_net_topprotocol; + +struct grub_net_protstack +{ + struct grub_net_protstack *next; + struct grub_net_protocol* prot; +}; struct grub_net_interface { struct grub_net_card *card; - struct grub_net_topprotocol* topprot; + struct grub_net_protstack* protstack; + char *path; + char *username; + char *password; + /*transport layer addres*/ struct grub_net_addr *tla; + /*internet layer addres*/ struct grub_net_addr *ila; + /*link layer addres*/ struct grub_net_addr *lla; }; -*/ + #endif diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h index 2c979481b..1efc2ab7b 100644 --- a/include/grub/net/protocol.h +++ b/include/grub/net/protocol.h @@ -4,47 +4,32 @@ #include #include #include -struct protocol_operations; + struct grub_net_protocol; struct grub_net_interface; +struct grub_net_protstack; struct grub_net_protocol { struct grub_net_protocol *next; char *name; grub_err_t (*open) (struct grub_net_interface* inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*open_confirm) (struct grub_net_interface *inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*get_payload) (struct grub_net_interface *inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*close) (struct grub_net_interface *inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*send) (struct grub_net_interface *inf , - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*recv) (struct grub_net_interface *inf , - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); }; typedef struct grub_net_protocol *grub_net_protocol_t; - -struct grub_net_interface -{ - struct grub_net_card *card; - struct grub_net_protocol* prot; - char *path; - char *username; - char *password; - /*transport layer addres*/ - struct grub_net_addr *tla; - /*internet layer addres*/ - struct grub_net_addr *ila; - /*link layer addres*/ - struct grub_net_addr *lla; -}; - void grub_protocol_register (grub_net_protocol_t prot); void grub_protocol_unregister (grub_net_protocol_t prot); #endif diff --git a/net/ethernet.c b/net/ethernet.c index fc64803e7..8c13966c1 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -6,9 +6,10 @@ #include #include #include +#include static grub_err_t -send_ethernet_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot __attribute__ ((unused)) +send_ethernet_packet (struct grub_net_interface *inf,struct grub_net_protstack *protstack __attribute__ ((unused)) ,struct grub_net_buff *nb) { diff --git a/net/ip.c b/net/ip.c index c669ff6d7..6fe58adb0 100644 --- a/net/ip.c +++ b/net/ip.c @@ -5,6 +5,7 @@ #include #include #include +#include #include struct grub_net_protocol *grub_ipv4_prot; @@ -28,7 +29,7 @@ ipchksum(void *ipv, int len) static grub_err_t -send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb ) +send_ip_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb ) { struct iphdr *iph; @@ -57,7 +58,7 @@ send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, iph->chksum = ipchksum((void *)nb->head, sizeof(*iph)); - return prot->next->send(inf,prot->next,nb); + return protstack->next->prot->send(inf,protstack->next,nb); } static struct grub_net_protocol grub_ipv4_protocol = diff --git a/net/tftp.c b/net/tftp.c index fdca184e9..3f481fe58 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -8,10 +8,11 @@ #include #include #include +#include /*send read request*/ static grub_err_t -send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,struct grub_net_buff *nb) +send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protstack *protstack,struct grub_net_buff *nb) { /*Start TFTP header*/ @@ -58,7 +59,7 @@ send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,str grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); - return prot->next->send(inf,prot->next,nb); + return protstack->next->prot->send(inf,protstack->next,nb); } /* diff --git a/net/udp.c b/net/udp.c index 600eec542..2a4a7690b 100644 --- a/net/udp.c +++ b/net/udp.c @@ -3,9 +3,10 @@ #include #include #include +#include /*Assumes that there is allocated memory to the header before the buffer address. */ static grub_err_t -send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb) +send_udp_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb) { struct udphdr *udph; @@ -21,7 +22,7 @@ send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, udph->chksum = 0; udph->len = sizeof (sizeof (*udph)) + nb->end - nb->head; - return prot->next->send(inf,prot->next,nb); + return protstack->next->prot->send(inf,protstack->next,nb); } static struct grub_net_protocol grub_udp_protocol =