From: Hugo Villeneuve Date: Wed, 5 Nov 2025 05:13:56 +0000 (-0500) Subject: Add kernel/U-Boot compatibility header file X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=aa8b857f0794f172123f80e717fd64b6f69e76e9;p=mtlv.git Add kernel/U-Boot compatibility header file Signed-off-by: Hugo Villeneuve --- diff --git a/src/linux-compat.h b/src/linux-compat.h new file mode 100644 index 0000000..ebe6984 --- /dev/null +++ b/src/linux-compat.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __LINUX_COMPAT_H_ +#define __LINUX_COMPAT_H_ + +#include +#include +#include +#include +#include + +#include "kernel.h" + +#define be16_to_cpu(x) be16toh(x) +#define cpu_to_be16(x) htobe16(x) + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; +typedef unsigned long ulong; + +#define simple_strtoul strtoul + +void log_err(const char *format, ...); +void log_fail(const char *format, ...); +#define log_debug printf + +static inline ulong hextoul(const char *cp, char **endp) +{ + return strtoul(cp, endp, 16); +} + +/* From U-Boot net-common.h */ + +/** + * is_zero_ethaddr - Determine if give Ethernet address is all zeros. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is all zeroes. + */ +static inline int is_zero_ethaddr(const u8 *addr) +{ + return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); +} + +/** + * is_multicast_ethaddr - Determine if the Ethernet address is a multicast. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a multicast address. + * By definition the broadcast address is also a multicast address. + */ +static inline int is_multicast_ethaddr(const u8 *addr) +{ + return 0x01 & addr[0]; +} + +/* + * is_valid_ethaddr - Determine if the given Ethernet address is valid + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not + * a multicast address, and is not FF:FF:FF:FF:FF:FF. + * + * Return true if the address is valid. + */ +static inline int is_valid_ethaddr(const u8 *addr) +{ + /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to + * explicitly check for it here. */ + return !is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr); +} + +#endif /* __LINUX_COMPAT_H_ */