Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

eth.h

Go to the documentation of this file.
00001 /*!     \file include/net/eth.h
00002  *      \brief Ethernet driver header.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-11-09
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #ifndef ETH_H
00009 #define ETH_H
00010 
00011 #include <kernel/semaphore.h>
00012 
00013 //! IP packet type.
00014 #define ETH_FRAME_IP            0x0800
00015 //! ARP packet type.
00016 #define ETH_FRAME_ARP           0x0806
00017 //! Size of an ethernet address (a.k.a. MAC).
00018 #define ETH_ADDR_LEN            6
00019 //! Size of the ethernet header.
00020 #define ETH_HEAD_LEN            14
00021 //! Minimum ethernet packet size.
00022 #define ETH_MIN_LEN             60
00023 //! Maximum ethernet packet size.
00024 #define ETH_FRAME_LEN           1514
00025 //! Ethernet MTU (Maximum transfer unit).
00026 #define ETH_MTU                 (ETH_FRAME_LEN - ETH_HEAD_LEN)
00027 
00028 //! Send and receive buffers size.
00029 #define ETH_RECV_BUF_DIM        10
00030 
00031 //! Physical packet structure.
00032 typedef struct phys_packet
00033 {
00034         //! The packet size.
00035         size_t length;
00036         //! The packet content.
00037         uint8_t data[ETH_FRAME_LEN];
00038 } phys_packet_t;
00039 
00040 //! An ethernet buffer structure.
00041 typedef struct eth_buf
00042 {
00043         //! The packets pointers.
00044         phys_packet_t packet[ETH_RECV_BUF_DIM];
00045         //! The position of the next packet received.
00046         int     read,
00047         //! The position of the next packet to be sent.
00048                 write,
00049         //! The amount of packets in the buffer.
00050                 count;
00051         //! A mutex semaphore for the buffer.
00052         semaphore_t mutex;
00053 } eth_buf_t;
00054 
00055 /** \ingroup Network
00056  *  \defgroup NetEthernet Ethernet Layer
00057  *  The ethernet layer.
00058  *  @{
00059  */
00060 
00061 //! An ethernet packet structure.
00062 typedef struct ethernet
00063 {
00064         //! Destination MAC address.
00065         uint8_t  dst[ETH_ADDR_LEN];
00066         //! Source MAC address.
00067         uint8_t  src[ETH_ADDR_LEN];
00068         //! The packet type.
00069         uint16_t type;
00070         //! The packet content.
00071         uint8_t data[1];
00072 }  __attribute__ ((packed)) ethernet_t;
00073 
00074 // --- Prototypes ----------------------------------------------------- //
00075 
00076 void to_eth_layer(ethernet_t *packet, size_t len);
00077 int send_eth_packet(const uint8_t *to, const void *data, size_t len, uint16_t type);
00078 bool is_eth_promisc();
00079 void ifconfig(char *cmd);
00080 
00081 /** @} */ // end of NetEthernet
00082 
00083 #endif

Generated on Fri Feb 20 15:32:15 2004 for Minirighi by doxygen1.2.18