Add support for error, RTR, and EFF frames

Error frames, remote transmission request, and extended format frames
require some changes to the way that we set up our sockets.

Bug: 142655821
Bug: 144774939
Test: manual
Change-Id: I06212cb852d480c1c7093e8c509ca8aa9f85f81f
diff --git a/automotive/can/1.0/default/libnetdevice/can.cpp b/automotive/can/1.0/default/libnetdevice/can.cpp
index 87617dd..6452d9b 100644
--- a/automotive/can/1.0/default/libnetdevice/can.cpp
+++ b/automotive/can/1.0/default/libnetdevice/can.cpp
@@ -24,12 +24,16 @@
 #include <android-base/unique_fd.h>
 
 #include <linux/can.h>
+#include <linux/can/error.h>
 #include <linux/can/netlink.h>
+#include <linux/can/raw.h>
 
 namespace android {
 namespace netdevice {
 namespace can {
 
+static constexpr can_err_mask_t kErrMask = CAN_ERR_MASK;
+
 base::unique_fd socket(const std::string& ifname) {
     struct sockaddr_can addr = {};
     addr.can_family = AF_CAN;
@@ -45,6 +49,11 @@
         return {};
     }
 
+    if (setsockopt(sock.get(), SOL_CAN_RAW, CAN_RAW_ERR_FILTER, &kErrMask, sizeof(kErrMask)) < 0) {
+        LOG(ERROR) << "Can't receive error frames, CAN setsockpt failed: " << strerror(errno);
+        return {};
+    }
+
     if (0 != fcntl(sock.get(), F_SETFL, O_RDWR | O_NONBLOCK)) {
         LOG(ERROR) << "Couldn't put CAN socket in non-blocking mode";
         return {};