4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 * \author Andrea Righi <arighi@develer.com>
35 * \brief Ethernet standard descriptors
37 * $WIZ$ module_name = "eth"
38 * $WIZ$ module_configuration = "bertos/cfg/cfg_eth.h"
39 * $WIZ$ module_supports = "at91sam7x"
45 #include <cpu/types.h>
47 #define ETH_ADDR_LEN 6
48 #define ETH_HEAD_LEN 14
49 #define ETH_DATA_LEN 1500
50 #define ETH_FRAME_LEN (ETH_HEAD_LEN + ETH_DATA_LEN)
52 #define ETH_TYPE_IP 0x0800
54 typedef union Ethernet
58 uint8_t dst[ETH_ADDR_LEN];
59 uint8_t src[ETH_ADDR_LEN];
63 uint8_t raw[ETH_FRAME_LEN];
67 * Determine if ethernet address \a addr is a all zero.
69 INLINE int eth_addrIsZero(const uint8_t *addr)
71 return !(addr[0] | addr[1] | addr[2] |
72 addr[3] | addr[4] | addr[5]);
76 * Determine if ethernet address \a addr is a multicast address.
78 INLINE int eth_addrIsMcast(const uint8_t *addr)
80 return (0x01 & addr[0]);
84 * Determine if ethernet address \a addr is locally-assigned (IEEE 802).
86 INLINE int eth_addrIsLocal(const uint8_t *addr)
88 return (0x02 & addr[0]);
92 * Determine if ethernet address \a addr is broadcast.
94 INLINE bool eth_addrIsBcast(const uint8_t *addr)
96 return (addr[0] & addr[1] & addr[2] &
97 addr[3] & addr[4] & addr[5]) == 0xff;
101 * Check if the ethernet address \a addr is not all zero, is not a multicast
102 * address, and is not broadcast.
104 INLINE bool eth_addrIsValid(const uint8_t *addr)
106 return !eth_addrIsMcast(addr) && !eth_addrIsZero(addr);
110 * Compare two ethernet addresses: \a addr1 and \a addr2, returns 0 if equal.
112 INLINE bool eth_addrCmp(const uint8_t *addr1, const uint8_t *addr2)
114 return !!((addr1[0] ^ addr2[0]) |
115 (addr1[1] ^ addr2[1]) |
116 (addr1[2] ^ addr2[2]) |
117 (addr1[3] ^ addr2[3]) |
118 (addr1[4] ^ addr2[4]) |
119 (addr1[5] ^ addr2[5]));
122 ssize_t eth_putFrame(const uint8_t *buf, size_t len);
123 void eth_sendFrame(void);
125 size_t eth_getFrameLen(void);
126 ssize_t eth_getFrame(uint8_t *buf, size_t len);
128 ssize_t eth_send(const uint8_t *buf, size_t len);
129 ssize_t eth_recv(uint8_t *buf, size_t len);
133 extern const uint8_t mac_addr[ETH_ADDR_LEN];
135 #endif /* DRV_ETH_H */