summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/socketcan
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-03-21 12:21:11 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2016-04-06 05:44:48 +0000
commit96d291cbdefb8f0d731eb32b0c1cca613b6006c3 (patch)
tree2d58a175cb6690734085406326506bb898df198f /src/plugins/canbus/socketcan
parent04b75569f36eec14662505a08bf8c1d565cb10fe (diff)
Make socketcan backend compile on pre 3.6 kernels
The CanFD implementation was introduced by the Linux 3.6 kernel. This change makes the socketcan backend compile on the older Linux kernel build platforms. If a socketcan backend was compiled against the most recent kernel headers but run on an ancient kernel, the missing support is dynamically detected by virtue of returned error code from ioctl et al. Task-number: QTBUG-51932 Change-Id: I5c3601877fa6e882f24d7fa3588dae473a325b9b Reviewed-by: Rolf Eike Beer <eb@emlix.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins/canbus/socketcan')
-rw-r--r--src/plugins/canbus/socketcan/socketcanbackend.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/plugins/canbus/socketcan/socketcanbackend.cpp b/src/plugins/canbus/socketcan/socketcanbackend.cpp
index 122b546..48a2aaf 100644
--- a/src/plugins/canbus/socketcan/socketcanbackend.cpp
+++ b/src/plugins/canbus/socketcan/socketcanbackend.cpp
@@ -48,6 +48,30 @@
#include <sys/ioctl.h>
#include <sys/time.h>
+#ifndef CANFD_MTU
+// CANFD support was added by Linux kernel 3.6
+// For prior kernels we redefine the missing defines here
+// they are taken from linux/can/raw.h & linux/can.h
+
+enum {
+ CAN_RAW_FD_FRAMES = 5
+};
+
+#define CAN_MAX_DLEN 8
+#define CANFD_MAX_DLEN 64
+struct canfd_frame {
+ canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
+ __u8 len; /* frame payload length in byte */
+ __u8 flags; /* additional flags for CAN FD */
+ __u8 __res0; /* reserved / padding */
+ __u8 __res1; /* reserved / padding */
+ __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
+};
+#define CAN_MTU (sizeof(struct can_frame))
+#define CANFD_MTU (sizeof(struct canfd_frame))
+
+#endif
+
QT_BEGIN_NAMESPACE
SocketCanBackend::SocketCanBackend(const QString &name) :