From e9a64fb51e1b21f2d552c2eb9e85569a3fbce4c8 Mon Sep 17 00:00:00 2001 From: Marc-Andre Servant Date: Tue, 30 Apr 2024 13:39:26 -0400 Subject: [PATCH 1/2] bugfix: setRxFilters() now sets a pass-all filter if the filter list is oversized and would be rejected by the kernel. --- CO_driver.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/CO_driver.c b/CO_driver.c index 4a96bd5..64d806e 100644 --- a/CO_driver.c +++ b/CO_driver.c @@ -149,18 +149,33 @@ static CO_ReturnError_t setRxFilters(CO_CANmodule_t *CANmodule) if (count == 0) { /* No filter is set, disable RX */ return disableRx(CANmodule); - } - - retval = CO_ERROR_NO; - for (i = 0; i < CANmodule->CANinterfaceCount; i ++) { - int ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER, - rxFiltersCpy, sizeof(struct can_filter) * count); - if(ret < 0){ - log_printf(LOG_ERR, CAN_FILTER_FAILED, - CANmodule->CANinterfaces[i].ifName); - log_printf(LOG_DEBUG, DBG_ERRNO, "setsockopt()"); - retval = CO_ERROR_SYSCALL; - } + } else if (count > CAN_RAW_FILTER_MAX) { + /* Too many filters for the hardware to handle, filtering will be done in software. */ + struct can_filter passAllFilter = { .can_id = 0, .can_mask = 0 }; + + retval = CO_ERROR_NO; + for (i = 0; i < CANmodule->CANinterfaceCount; i ++) { + int ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER, + &passAllFilter, sizeof(struct can_filter)); + if(ret < 0){ + log_printf(LOG_ERR, CAN_FILTER_FAILED, + CANmodule->CANinterfaces[i].ifName); + log_printf(LOG_DEBUG, DBG_ERRNO, "setsockopt()"); + retval = CO_ERROR_SYSCALL; + } + } + } else { + retval = CO_ERROR_NO; + for (i = 0; i < CANmodule->CANinterfaceCount; i ++) { + int ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER, + rxFiltersCpy, sizeof(struct can_filter) * count); + if(ret < 0){ + log_printf(LOG_ERR, CAN_FILTER_FAILED, + CANmodule->CANinterfaces[i].ifName); + log_printf(LOG_DEBUG, DBG_ERRNO, "setsockopt()"); + retval = CO_ERROR_SYSCALL; + } + } } return retval; From ca63e104a4112a9260c05fb9cf2099d9f52c396d Mon Sep 17 00:00:00 2001 From: Marc-Andre Servant Date: Tue, 30 Apr 2024 15:13:03 -0400 Subject: [PATCH 2/2] Fix indent --- CO_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CO_driver.c b/CO_driver.c index 64d806e..cccdf1f 100644 --- a/CO_driver.c +++ b/CO_driver.c @@ -166,7 +166,7 @@ static CO_ReturnError_t setRxFilters(CO_CANmodule_t *CANmodule) } } else { retval = CO_ERROR_NO; - for (i = 0; i < CANmodule->CANinterfaceCount; i ++) { + for (i = 0; i < CANmodule->CANinterfaceCount; i ++) { int ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER, rxFiltersCpy, sizeof(struct can_filter) * count); if(ret < 0){