From 4a11da5aa8864a831d0c0238afe8d141e786cceb Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Thu, 28 Dec 2023 14:29:46 -0800 Subject: [PATCH] Change configuration macro checks to use value instead of definedness --- CHANGELOG.md | 1 + src/QNEthernet.cpp | 2 +- src/QNEthernet.h | 4 ++-- src/QNEthernetFrame.cpp | 2 +- src/QNEthernetFrame.h | 2 +- src/arch/cc.h | 2 +- src/default_altcp_functions.cpp | 4 ++-- src/lwip_driver.h | 2 +- src/lwip_hooks.h | 2 +- src/lwip_t41.c | 24 ++++++++++++------------ src/lwip_unsupported.c | 2 +- src/security/RandomDevice.cpp | 2 +- src/security/entropy.c | 2 +- src/security/entropy.h | 2 +- src/sys_arch.cpp | 8 ++++---- 15 files changed, 31 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a38bdbe..8b4be348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ and this project adheres to disable DHCP. * Disabled waiting in `EthernetClient::close()` for altcp clients because it's not defined. +* Changed configuration macro checks to use value instead of definedness. ### Fixed * Fixed a `printf` conversion specifier in the _RandomNumbers_ example. This was diff --git a/src/QNEthernet.cpp b/src/QNEthernet.cpp index 2d7065b2..afb54b47 100644 --- a/src/QNEthernet.cpp +++ b/src/QNEthernet.cpp @@ -533,7 +533,7 @@ bool EthernetClass::setMACAddressAllowed(const uint8_t mac[6], if (netif_ == nullptr) { return false; } -#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE +#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE return enet_set_mac_address_allowed(mac, flag); #else return flag; // Can't disallow MAC addresses diff --git a/src/QNEthernet.h b/src/QNEthernet.h index c0532097..8d266130 100644 --- a/src/QNEthernet.h +++ b/src/QNEthernet.h @@ -94,7 +94,7 @@ class EthernetClass final { // Returns whether promiscuous mode is enabled. static constexpr bool isPromiscuousMode() { -#ifdef QNETHERNET_ENABLE_PROMISCUOUS_MODE +#if QNETHERNET_ENABLE_PROMISCUOUS_MODE return true; #else return false; @@ -408,7 +408,7 @@ class EthernetClass final { // Instance for interacting with the library. STATIC_INIT_DECL(EthernetClass, Ethernet); -#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE +#if QNETHERNET_ENABLE_CUSTOM_WRITE // stdout output. extern Print *stdoutPrint; diff --git a/src/QNEthernetFrame.cpp b/src/QNEthernetFrame.cpp index 7414efa3..a68705a1 100644 --- a/src/QNEthernetFrame.cpp +++ b/src/QNEthernetFrame.cpp @@ -4,7 +4,7 @@ // QNEthernetFrame.cpp contains an EthernetFrame implementation. // This file is part of the QNEthernet library. -#ifdef QNETHERNET_ENABLE_RAW_FRAME_SUPPORT +#if QNETHERNET_ENABLE_RAW_FRAME_SUPPORT #include "QNEthernetFrame.h" diff --git a/src/QNEthernetFrame.h b/src/QNEthernetFrame.h index ec8e4b9a..95f71c86 100644 --- a/src/QNEthernetFrame.h +++ b/src/QNEthernetFrame.h @@ -7,7 +7,7 @@ #ifndef QNETHERNET_ETHERNETFRAME_H_ #define QNETHERNET_ETHERNETFRAME_H_ -#ifdef QNETHERNET_ENABLE_RAW_FRAME_SUPPORT +#if QNETHERNET_ENABLE_RAW_FRAME_SUPPORT // C++ includes #include diff --git a/src/arch/cc.h b/src/arch/cc.h index 67499d96..82eba061 100644 --- a/src/arch/cc.h +++ b/src/arch/cc.h @@ -26,7 +26,7 @@ } while (0) extern void qnethernet_stdio_flush(int file); -#ifndef QNETHERNET_LWIP_MEMORY_IN_RAM1 +#if !QNETHERNET_LWIP_MEMORY_IN_RAM1 #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \ u8_t variable_name[(size)] DMAMEM __attribute__((aligned(MEM_ALIGNMENT))) #else diff --git a/src/default_altcp_functions.cpp b/src/default_altcp_functions.cpp index 3bce60b1..6434e77b 100644 --- a/src/default_altcp_functions.cpp +++ b/src/default_altcp_functions.cpp @@ -7,7 +7,7 @@ #include "lwip/opt.h" -#if LWIP_ALTCP && defined(QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS) +#if LWIP_ALTCP && QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS #include #include @@ -31,4 +31,4 @@ __attribute__((weak)) std::function qnethernet_altcp_free_allocator = [](const altcp_allocator_t &allocator) {}; -#endif // LWIP_ALTCP && defined(QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS) +#endif // LWIP_ALTCP && QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS diff --git a/src/lwip_driver.h b/src/lwip_driver.h index 70af4605..2a982581 100644 --- a/src/lwip_driver.h +++ b/src/lwip_driver.h @@ -97,7 +97,7 @@ bool phy_link_is_crossover(); // This adds any extra padding bytes given by ETH_PAD_SIZE. bool enet_output_frame(const uint8_t *frame, size_t len); -#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE +#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE // For joining and leaving multicast groups; these call // enet_set_mac_address_allowed() with the MAC addresses related to the given diff --git a/src/lwip_hooks.h b/src/lwip_hooks.h index a109483d..af79ffc8 100644 --- a/src/lwip_hooks.h +++ b/src/lwip_hooks.h @@ -11,7 +11,7 @@ #include "lwip/netif.h" #include "lwip/pbuf.h" -#ifdef QNETHERNET_ENABLE_RAW_FRAME_SUPPORT +#if QNETHERNET_ENABLE_RAW_FRAME_SUPPORT #define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(p, netif) \ unknown_eth_protocol((p), (netif)) diff --git a/src/lwip_t41.c b/src/lwip_t41.c index 6d86d9ca..a23da5f8 100644 --- a/src/lwip_t41.c +++ b/src/lwip_t41.c @@ -173,7 +173,7 @@ // Payload(1500) + FCS(4) #define BUF_SIZE (((ETH_PAD_SIZE + 6 + 6 + 2 + 2 + 2 + 1500 + 4) + 63) & ~63) -#ifndef QNETHERNET_BUFFERS_IN_RAM1 +#if !QNETHERNET_BUFFERS_IN_RAM1 #define MULTIPLE_OF_32(x) (((x) + 31) & ~31) #define BUFFER_DMAMEM DMAMEM #else @@ -639,7 +639,7 @@ static void low_level_init() { | ENET_RCR_PADEN // Padding is removed | ENET_RCR_RMII_MODE | ENET_RCR_FCE // Flow control enable -#ifdef QNETHERNET_ENABLE_PROMISCUOUS_MODE +#if QNETHERNET_ENABLE_PROMISCUOUS_MODE | ENET_RCR_PROM // Promiscuous mode #endif // QNETHERNET_ENABLE_PROMISCUOUS_MODE | ENET_RCR_MII_MODE; @@ -761,7 +761,7 @@ static struct pbuf *low_level_input(volatile enetbufferdesc_t *pBD) { } else { p = pbuf_alloc(PBUF_RAW, pBD->length, PBUF_POOL); if (p) { -#ifndef QNETHERNET_BUFFERS_IN_RAM1 +#if !QNETHERNET_BUFFERS_IN_RAM1 arm_dcache_delete(pBD->buffer, MULTIPLE_OF_32(p->tot_len)); #endif // !QNETHERNET_BUFFERS_IN_RAM1 pbuf_take(p, pBD->buffer, p->tot_len); @@ -832,7 +832,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) { LINK_STATS_INC(link.drop); return ERR_BUF; } -#ifndef QNETHERNET_BUFFERS_IN_RAM1 +#if !QNETHERNET_BUFFERS_IN_RAM1 arm_dcache_flush_delete(pBD->buffer, MULTIPLE_OF_32(copied)); #endif // !QNETHERNET_BUFFERS_IN_RAM1 update_bufdesc(pBD, copied); @@ -952,7 +952,7 @@ static inline int check_link_status(int state) { return 0; } -#if LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE) +#if LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE // Multicast filter for letting the hardware know which packets to let in. static err_t multicast_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action) { @@ -973,7 +973,7 @@ static err_t multicast_filter(struct netif *netif, const ip4_addr_t *group, // ERR_USE seems like the best fit of the choices // Next best seems to be ERR_IF } -#endif // LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE) +#endif // LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE // -------------------------------------------------------------------------- // Public Interface @@ -1013,7 +1013,7 @@ bool enet_has_hardware() { return (s_initState != kInitStateNoHardware); } -#ifdef QNETHERNET_INTERNAL_END_STOPS_ALL +#if QNETHERNET_INTERNAL_END_STOPS_ALL // Removes the current netif, if any. static void remove_netif() { if (s_isNetifAdded) { @@ -1070,10 +1070,10 @@ bool enet_init(const uint8_t mac[ETH_HWADDR_LEN], autoip_set_struct(&s_netif, &s_autoip); #endif // LWIP_AUTOIP -#if LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE) +#if LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE // Multicast filtering, to allow desired multicast packets in netif_set_igmp_mac_filter(&s_netif, &multicast_filter); -#endif // LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE) +#endif // LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE } else { // Just set the MAC address @@ -1100,7 +1100,7 @@ void enet_deinit() { // is restarted after calling end(), so gate the following two blocks with a // macro for now -#ifdef QNETHERNET_INTERNAL_END_STOPS_ALL +#if QNETHERNET_INTERNAL_END_STOPS_ALL remove_netif(); // TODO: This also causes issues (see notes in enet_init()) if (s_initState == kInitStateInitialized) { @@ -1208,7 +1208,7 @@ bool enet_output_frame(const uint8_t *frame, size_t len) { volatile enetbufferdesc_t *pBD = get_bufdesc(); memcpy((uint8_t *)pBD->buffer + ETH_PAD_SIZE, frame, len); -#ifndef QNETHERNET_BUFFERS_IN_RAM1 +#if !QNETHERNET_BUFFERS_IN_RAM1 arm_dcache_flush_delete(pBD->buffer, MULTIPLE_OF_32(len + ETH_PAD_SIZE)); #endif // !QNETHERNET_BUFFERS_IN_RAM1 update_bufdesc(pBD, len + ETH_PAD_SIZE); @@ -1220,7 +1220,7 @@ bool enet_output_frame(const uint8_t *frame, size_t len) { // MAC Address Filtering // -------------------------------------------------------------------------- -#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE +#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE // CRC-32 routine for computing the 4-byte FCS for multicast lookup. static uint32_t crc32(uint32_t crc, const uint8_t *data, size_t len) { diff --git a/src/lwip_unsupported.c b/src/lwip_unsupported.c index 72d5a00f..45ff4c12 100644 --- a/src/lwip_unsupported.c +++ b/src/lwip_unsupported.c @@ -57,7 +57,7 @@ bool enet_output_frame(const uint8_t *frame, size_t len) { // MAC Address Filtering // -------------------------------------------------------------------------- -#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE +#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE bool enet_set_mac_address_allowed(const uint8_t *mac, bool allow) { return false; diff --git a/src/security/RandomDevice.cpp b/src/security/RandomDevice.cpp index 011a80fa..20fc7361 100644 --- a/src/security/RandomDevice.cpp +++ b/src/security/RandomDevice.cpp @@ -8,7 +8,7 @@ #include -#if defined(__IMXRT1062__) && !defined(QNETHERNET_USE_ENTROPY_LIB) +#if defined(__IMXRT1062__) && !QNETHERNET_USE_ENTROPY_LIB #include "entropy.h" diff --git a/src/security/entropy.c b/src/security/entropy.c index f520d4e3..b3036978 100644 --- a/src/security/entropy.c +++ b/src/security/entropy.c @@ -5,7 +5,7 @@ // This file is part of the QNEthernet library. #if defined(__IMXRT1062__) -#if !defined(QNETHERNET_USE_ENTROPY_LIB) +#if !QNETHERNET_USE_ENTROPY_LIB #include "entropy.h" diff --git a/src/security/entropy.h b/src/security/entropy.h index d2fae856..f5ae4908 100644 --- a/src/security/entropy.h +++ b/src/security/entropy.h @@ -8,7 +8,7 @@ #define QNETHERNET_SECURITY_ENTROPY_H_ #if defined(__IMXRT1062__) -#if !defined(QNETHERNET_USE_ENTROPY_LIB) +#if !QNETHERNET_USE_ENTROPY_LIB #ifdef __cplusplus extern "C" { diff --git a/src/sys_arch.cpp b/src/sys_arch.cpp index 3e70ca49..5324fdd6 100644 --- a/src/sys_arch.cpp +++ b/src/sys_arch.cpp @@ -8,7 +8,7 @@ #include // C++ includes -#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE +#if QNETHERNET_ENABLE_CUSTOM_WRITE #include #endif // QNETHERNET_ENABLE_CUSTOM_WRITE #include @@ -72,7 +72,7 @@ const char *lwip_strerr(err_t err) { // stdio // -------------------------------------------------------------------------- -#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE +#if QNETHERNET_ENABLE_CUSTOM_WRITE // The user program can set these to something initialized. For example, // `&Serial`, after `Serial.begin(speed)`. @@ -96,7 +96,7 @@ extern "C" { // Gets the Print* for the given file descriptor. static inline Print *getPrint(int file) { switch (file) { -#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE +#if QNETHERNET_ENABLE_CUSTOM_WRITE case STDOUT_FILENO: return ::qindesign::network::stdoutPrint; case STDERR_FILENO: @@ -113,7 +113,7 @@ static inline Print *getPrint(int file) { } } -#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE +#if QNETHERNET_ENABLE_CUSTOM_WRITE // Define this function to provide expanded stdio output behaviour. // See: https://forum.pjrc.com/threads/28473-Quick-Guide-Using-printf()-on-Teensy-ARM