]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Add interface struct for communication between protocols and protocols stack.
authorManoel R. Abranches <mrabran@br.ibm.com>
Mon, 21 Jun 2010 22:05:14 +0000 (19:05 -0300)
committerManoel R. Abranches <mrabran@br.ibm.com>
Mon, 21 Jun 2010 22:05:14 +0000 (19:05 -0300)
Changed the protocols structs to use one struct for each layer.

include/grub/net/arp.h
include/grub/net/ieee1275/interface.h
include/grub/net/interface.h
include/grub/net/netbuff.h
include/grub/net/protocol.h
include/grub/net/tftp.h
include/grub/net/type_net.h
include/grub/net/udp.h

index 0ac2ec83257e8506acf27e45528024182de8d0bb..86ae2deea640931060502afc587c9f92a69b4df7 100644 (file)
@@ -2,7 +2,7 @@
 #define GRUB_NET_ARP_HEADER    1
 
 #include <grub/net/ethernet.h>
-struct arprequest {
+struct arphdr{
     grub_int16_t hwtype;        /* hardware type (must be ARPHRD_ETHER) */
     grub_int16_t protocol;      /* protocol type (must be ETH_P_IP) */
     grub_int8_t hwlen;            /* hardware address length (must be 6) */
@@ -14,10 +14,4 @@ struct arprequest {
     grub_uint32_t tipaddr;     /* target's IP address */
 }__attribute__ ((packed));
 
-
-struct arp_pkt{
-  struct etherhdr ether;
-  struct arprequest arpr;
-} __attribute__ ((packed));
-
 #endif 
index edc242cab81e653cdc8e885f8d164a3590069747..16f624c05e9d50c21f3f39e5c01546ca828073a8 100644 (file)
@@ -4,17 +4,15 @@
 #include <grub/misc.h>
 #include <grub/ieee1275/ieee1275.h>
 #include <grub/ieee1275/ofnet.h>
+#include <grub/net/netbuff.h>
 
-grub_ofnet_t EXPORT_VAR(grub_net);
 
-grub_bootp_t EXPORT_VAR(bootp_pckt);
-grub_uint32_t get_server_ip(void);
-grub_uint32_t get_client_ip(void);
-grub_uint8_t* get_server_mac (void);
-grub_uint8_t* get_client_mac (void);
+grub_ofnet_t grub_net;
 
-int send_card_buffer (void *buffer,int buff_len);
-int get_card_buffer (void *buffer,int buff_len);
+grub_bootp_t bootp_pckt;
+
+int send_card_buffer (struct grub_net_buff *pack);
+int get_card_packet (struct grub_net_buff *pack);
 int card_open (void);
 int card_close (void);
 
index 2e0ddfcc8098bbf6963ec230f288e5c10060ea89..4d100fd75c1b88de9b94c195e93f43ecda79e03f 100644 (file)
@@ -1,27 +1,70 @@
 #ifndef GRUB_INTERFACE_HEADER
 #define GRUB_INTERFACE_HEADER
-#include <grub/net.h>
-#include <grub/net/protocol.h>
+//#include <grub/net.h>
+#include <grub/net/type_net.h>
+#include <grub/list.h>
+#include <grub/misc.h>
 
-struct grub_net_protstack
+struct grub_net_protocol_stack
 {
-  struct grub_net_protstack *next;
-  struct grub_net_protocol* prot;
+  struct grub_net_protocol_stack *next;
+  char *name;
+  grub_net_protocol_id_t id;
+  void *interface;
 };
 
-struct grub_net_interface
+struct grub_net_application_transport_interface
 {
-  struct grub_net_card *card;
-  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;
+  struct grub_net_transport_network_interface *inner_layer; 
+  void *data;
+  struct grub_net_application_layer_protocol *app_prot;
+  struct grub_net_transport_layer_protocol *trans_prot;
 };
 
+struct grub_net_transport_network_interface
+{
+  struct grub_net_network_link_interface *inner_layer; 
+  void *data;
+  struct grub_net_transport_layer_protocol *trans_prot;
+  struct grub_net_network_layer_protocol *net_prot;
+};
+
+struct grub_net_network_link_interface
+{
+  void *data;
+  struct grub_net_network_layer_protocol *net_prot;
+  struct grub_net_link_layer_protocol *link_prot;
+};
+
+
+extern struct grub_net_protocol_stack *grub_net_protocol_stacks;
+static inline void
+grub_net_stack_register (struct grub_net_protocol_stack *stack)
+{
+
+  grub_list_push (GRUB_AS_LIST_P (&grub_net_protocol_stacks),
+                 GRUB_AS_LIST (stack));
+}
+/*
+void grub_net_stack_unregister (struct grub_net_protocol_stack *stack)
+{
+  grub_list_remove (GRUB_AS_LIST_P (&grub_net_protocol_stacks),
+                   GRUB_AS_LIST (stack));
+}*/
+
+struct grub_net_protocol_stack   *grub_net_protocol_stack_get (char *name);
+
+/*
+static inline void
+grub_net_interface_application_transport_register (struct grub_net_application_transport_interface);
+static inline void
+grub_net_interface_application_transport_unregister (struct grub_net_application_transport_interface);
+static inline void
+grub_net_interface_transport_network_register (struct grub_net_transport_network_interface);
+static inline void
+grub_net_interface_transport_network_unregister (struct grub_net_transport_network_interface);
+static inline void
+grub_net_interface_network_link_register (struct grub_net_network_link_interface);
+static inline void
+grub_net_interface_network_link_unregister (struct grub_net_network_link_interface);*/
 #endif
index 7d63be1f5f8affb6ba98a9ca22fbe4878c1ba076..8ce508eadc6c28a6d0a3cac317847d7a5b14b9ec 100644 (file)
@@ -23,5 +23,8 @@ 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);
 grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len);
 grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len);
+grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
 struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len );
+grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff);
+grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
 #endif
index 1efc2ab7b832fada2960d8d535a609b6f7f40a4c..b7a3e5d3b33f5ccf80373beeffb8995000b03267 100644 (file)
 #ifndef GRUB_PROTOCOL_HEADER
 #define GRUB_PROTOCOL_HEADER
 #include <grub/err.h>
-#include <grub/net/protocol.h>
+#include <grub/net/interface.h>
 #include <grub/net/netbuff.h>
-#include <grub/net.h>
+#include <grub/net/type_net.h>
 
 struct grub_net_protocol;
-struct grub_net_interface;
-struct grub_net_protstack;
+struct grub_net_protocol_stack;
+struct grub_net_network_layer_interface;
 
-struct grub_net_protocol
+
+typedef enum grub_network_layer_protocol_id 
+{
+  GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
+} grub_network_layer_protocol_id_t;
+
+struct grub_net_application_layer_protocol
+{
+  struct grub_net_application_layer_protocol *next;
+  char *name;
+  grub_net_protocol_id_t id;
+  int (*get_file_size) (struct grub_net_network_layer_interface* inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename);
+  grub_err_t (*open) (struct grub_net_network_layer_interface* inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename);
+  grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
+  grub_err_t (*send) (struct grub_net_network_layer_interface *inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
+  grub_err_t (*recv) (struct grub_net_network_layer_interface *inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
+  grub_err_t (*close) (struct grub_net_network_layer_interface *inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
+};
+
+struct grub_net_transport_layer_protocol
+{
+  struct grub_net_transport_layer_protocol *next;
+  char *name;
+  grub_net_protocol_id_t id;
+  //grub_transport_layer_protocol_id_t id;
+  grub_err_t (*open) (struct grub_net_network_layer_interface* inf,
+             struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb);
+  grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
+  grub_err_t (*send) (struct grub_net_network_layer_interface *inf,
+             struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb);
+  grub_err_t (*recv) (struct grub_net_network_layer_interface *inf,
+             struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb);
+  grub_err_t (*close) (struct grub_net_network_layer_interface *inf,
+             struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
+};
+
+struct grub_net_network_layer_protocol
+{
+  struct grub_net_network_layer_protocol *next;
+  char *name;
+  grub_net_protocol_id_t id;
+  //grub_network_layer_protocol_id_t id;
+  grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr);
+  char * (*aton) (union grub_net_network_layer_address addr);
+  grub_err_t (*net_ntoa) (char *name,
+                         grub_net_network_layer_netaddress_t *addr);
+  char * (*net_aton) (grub_net_network_layer_netaddress_t addr);
+  int (* match_net) (grub_net_network_layer_netaddress_t net,
+                    grub_net_network_layer_address_t addr);
+  grub_err_t (*send) (struct grub_net_network_layer_interface *inf ,
+             struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb);
+  grub_err_t (*recv) (struct grub_net_network_layer_interface *inf ,
+             struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb);
+};
+
+struct grub_net_link_layer_protocol
 {
-  struct grub_net_protocol *next;
+  
+  struct grub_net_link_layer_protocol *next;
   char *name;
-  grub_err_t (*open) (struct grub_net_interface* inf,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
-  grub_err_t (*open_confirm) (struct grub_net_interface *inf,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
-  grub_err_t (*get_payload) (struct grub_net_interface *inf,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
-  grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
-  grub_err_t (*close) (struct grub_net_interface *inf,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
-  grub_err_t (*send) (struct grub_net_interface *inf ,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
-  grub_err_t (*recv) (struct grub_net_interface *inf ,
-             struct grub_net_protstack *protstack, struct grub_net_buff *nb);
+  grub_net_protocol_id_t id;
+  grub_err_t (*send) (struct grub_net_network_layer_interface *inf ,
+             struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
+  grub_err_t (*recv) (struct grub_net_network_layer_interface *inf ,
+             struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
 };
 
+extern struct grub_net_network_layer_protocol *grub_net_network_layer_protocols;
+
 typedef struct grub_net_protocol *grub_net_protocol_t;
-void grub_protocol_register (grub_net_protocol_t prot);
-void grub_protocol_unregister (grub_net_protocol_t prot);
+void grub_net_application_layer_protocol_register (struct grub_net_application_layer_protocol *prot);
+void grub_net_application_layer_protocol_unregister (struct grub_net_application_layer_protocol *prot);
+struct grub_net_application_layer_protocol *grub_net_application_layer_protocol_get (grub_net_protocol_id_t id);
+void grub_net_transport_layer_protocol_register (struct grub_net_transport_layer_protocol *prot);
+void grub_net_transport_layer_protocol_unregister (struct grub_net_transport_layer_protocol *prot);
+struct grub_net_transport_layer_protocol *grub_net_transport_layer_protocol_get (grub_net_protocol_id_t id);
+void grub_net_network_layer_protocol_register (struct grub_net_network_layer_protocol *prot);
+void grub_net_network_layer_protocol_unregister (struct grub_net_network_layer_protocol *prot);
+struct grub_net_network_layer_protocol *grub_net_network_layer_protocol_get (grub_net_protocol_id_t id);
+void grub_net_link_layer_protocol_register (struct grub_net_link_layer_protocol *prot);
+void grub_net_link_layer_protocol_unregister (struct grub_net_link_layer_protocol *prot);
+struct grub_net_link_layer_protocol *grub_net_link_layer_protocol_get (grub_net_protocol_id_t id);
 #endif
index 4148096c5355f7d64772531b74811c3e58f5ca2d..1f1c48616a923b595cd219952e0624c2f7d55c21 100644 (file)
@@ -14,7 +14,7 @@
 
 /* IP port for the TFTP server */
 #define TFTP_SERVER_PORT 69
-#define TFTP_CLIENT_PORT 2000
+#define TFTP_CLIENT_PORT 26300
 
 
 /* We define these based on what's in arpa/tftp.h. We just like our
 #define TFTP_ENOUSER 7                  /* no such user */
 #define TFTP_DEFAULT_FILENAME   "kernel"
 
-
-
-
-
  /*  * own here because this is cleaner, and maps to the same data layout.
  *   */
 struct tftphdr {
index 33f2d802dcd344a25fbd3b94c96f93d8cc2f45a8..276c50bf9a2aed9dbe87b9b9c7ff3add39e91f95 100644 (file)
@@ -1,7 +1,32 @@
 #ifndef GRUB_TYPES_NET_HEADER
 #define GRUB_TYPES_NET_HEADER  1
+#include <grub/misc.h>
+
 
 #define UDP_PCKT 0x11
 #define IP_PCKT 0x0800
+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
+}grub_net_protocol_id_t;
+
+
+typedef union grub_net_network_layer_address
+{
+  grub_uint32_t ipv4;
+} grub_net_network_layer_netaddress_t;
 
+typedef union grub_net_network_layer_netaddress
+{
+  struct {
+    grub_uint32_t base;
+    int masksize; 
+  } ipv4;
+} grub_net_network_layer_address_t;
 #endif 
index dbfcecef0adf0f07f1615b3a43caa4727d35df43..dfc1776a42e8eb84a569d2383b153b5bc435d8f5 100644 (file)
@@ -1,22 +1,23 @@
 #ifndef GRUB_NET_UDP_HEADER
 #define GRUB_NET_UDP_HEADER    1
 #include <grub/misc.h>
-/*
-typedef enum
-  {
-    GRUB_PROT_TFTP
-  } protocol_type;
-*/
 
-#define GRUB_PROT_TFTP 1 
-
-struct udphdr {
+struct udphdr
+{
   grub_uint16_t src;
   grub_uint16_t dst;
   grub_uint16_t len;
   grub_uint16_t chksum;
 } __attribute__ ((packed));
 
+struct udp_interf
+{
+  grub_uint16_t src;
+  grub_uint16_t dst;
+};
+
+
+
 void udp_ini(void);
 void udp_fini(void);
 #endif