From 5111118db700f7cd0763fd261f59c580725c18a1 Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 28 Sep 2022 09:43:00 -0700 Subject: [PATCH] drivers: Disallow FD frames when not in FD Mode for mcan Currently, if you send an FD frame with the mcan driver, but FD mode was not enabled, the hardware will only send the first 8 bytes of the frame, but still with a DLC of FD length. This results in some very weird behavior on the bus, dependning on what other devices are doing. Add a check to ensure an FD send only occurs with FD enabled. Signed-off-by: Thad House --- drivers/can/can_mcan.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/can/can_mcan.c b/drivers/can/can_mcan.c index e1969513d88a7..b89a7cd84b2c7 100644 --- a/drivers/can/can_mcan.c +++ b/drivers/can/can_mcan.c @@ -841,6 +841,16 @@ int can_mcan_send(const struct device *dev, return -ENETUNREACH; } + if (frame->fd && (can->cccr & CAN_MCAN_CCCR_FDOE) == 0) { + LOG_ERR("fd flag set without fd mode enabled."); + return -EINVAL; + } + + if (frame->brs && (can->cccr & CAN_MCAN_CCCR_BRSE) == 0) { + LOG_ERR("brs flag set without fd brs mode enabled."); + return -EINVAL; + } + ret = k_sem_take(&data->tx_sem, timeout); if (ret != 0) { return -EAGAIN;