mirror of
https://github.com/intrepidcs/intrepid-socketcan-kernel-module.git
synced 2026-09-21 16:38:39 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7924117c2a | ||
|
|
c515de3a25 | ||
|
|
a46b3c62ed | ||
|
|
8a21b53cd1 | ||
|
|
9da27da69e | ||
|
|
6bbcf1b527 | ||
|
|
668e50d08c | ||
|
|
6025ea1349 | ||
|
|
d75acfa8a5 | ||
|
|
96836cb186 | ||
|
|
03235819fc | ||
|
|
5031840429 | ||
|
|
17569a82a9 | ||
|
|
3a043ecedd | ||
|
|
b5dfcee1e1 | ||
|
|
6c061d771e | ||
|
|
408459cbe2 |
@@ -98,3 +98,7 @@ extra_certificates
|
|||||||
signing_key.priv
|
signing_key.priv
|
||||||
signing_key.x509
|
signing_key.x509
|
||||||
x509.genkey
|
x509.genkey
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
compile_commands.json
|
||||||
|
intrepid.mod
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
v2.1.0
|
||||||
|
Implement proper functionality for echoing transmits
|
||||||
|
Transmit errors are now reported properly
|
||||||
|
Transmit byte count is now reported properly
|
||||||
|
Use with icsscand >= v2.1.0 for full echo support
|
||||||
|
|
||||||
|
v2.0.5
|
||||||
|
Add support for kernels 5.9+
|
||||||
|
Tested on 5.11.0-rc5
|
||||||
|
CAN frames with length > 8 from userspace are rejected rather than truncated
|
||||||
|
|
||||||
|
v2.0.4
|
||||||
|
Ensure carrier is up on new kernels which require it
|
||||||
|
|
||||||
|
v2.0.3
|
||||||
|
Add support for kernels 5.1+
|
||||||
|
Tested on 5.3.0 (Ubuntu 19.10)
|
||||||
|
|
||||||
|
v2.0.2
|
||||||
|
Add support for older kernels
|
||||||
|
Tested working properly back to 4.4
|
||||||
|
Disabled aliasing for kernels <4.15
|
||||||
|
Required, as these kernels do not have netdevice aliasing
|
||||||
|
Use the correct format specifier for (s)size_t
|
||||||
|
Resolves a compile-time warning on 32-bit
|
||||||
|
Check the return type of copy_from_user
|
||||||
|
Resolves a compile-time warning on ARM
|
||||||
|
Standardize kernel version checking
|
||||||
|
Requires icsscand >= v2.0.1
|
||||||
|
icsscand v2.0.0 will not work with older kernels, and would display an obscure error
|
||||||
|
|
||||||
|
v2.0.1
|
||||||
|
Resolve runtime warning message on changing MTU
|
||||||
|
Reviewed our locking behavior, made tweaks where necessary
|
||||||
|
|
||||||
|
v2.0.0
|
||||||
|
Full rewrite
|
||||||
|
Initial release with CAN-FD support
|
||||||
|
Requires icsscand >= v2.0.0
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
Version 2.0.1
|
Version 2.1.0
|
||||||
|
|
||||||
This is the kernel object portion of the Intrepid Control Systems SocketCAN support. For SocketCAN to work with Intrepid devices you will need to have this kernel object loaded on your system. Once the module is built and loaded run [icsscand](https://github.com/intrepidcs/icsscand) to turn on SocketCAN support.
|
This is the kernel object portion of the Intrepid Control Systems SocketCAN support. For SocketCAN to work with Intrepid devices you will need to have this kernel object loaded on your system. Once the module is built and loaded run [icsscand](https://github.com/intrepidcs/icsscand) to turn on SocketCAN support.
|
||||||
|
|
||||||
First, install the necessary dependencies for building kernel modules.
|
First, install the necessary dependencies for building kernel modules.
|
||||||
|
|
||||||
On Ubuntu, this is acomplished by running `sudo apt install linux-headers-generic build-essential gcc git`
|
On Ubuntu, this is accomplished by running `sudo apt install linux-headers-generic build-essential gcc git`
|
||||||
|
|
||||||
Clone this repository by running `git clone https://github.com/intrepidcs/intrepid-socketcan-kernel-module.git`
|
Clone this repository by running `git clone https://github.com/intrepidcs/intrepid-socketcan-kernel-module.git`
|
||||||
|
|
||||||
|
|||||||
+139
-31
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* intrepid.c - Netdevice driver for Intrepid CAN/Ethernet devices
|
* intrepid.c - Netdevice driver for Intrepid CAN/Ethernet devices
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2019 Intrepid Control Systems, Inc.
|
* Copyright (c) 2016-2022 Intrepid Control Systems, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
@@ -56,8 +56,8 @@
|
|||||||
|
|
||||||
#define KO_DESC "Netdevice driver for Intrepid CAN/Ethernet devices"
|
#define KO_DESC "Netdevice driver for Intrepid CAN/Ethernet devices"
|
||||||
#define KO_MAJOR 2
|
#define KO_MAJOR 2
|
||||||
#define KO_MINOR 0
|
#define KO_MINOR 1
|
||||||
#define KO_PATCH 1
|
#define KO_PATCH 0
|
||||||
#define KO_VERSION str(KO_MAJOR) "." str(KO_MINOR) "." str(KO_PATCH)
|
#define KO_VERSION str(KO_MAJOR) "." str(KO_MINOR) "." str(KO_PATCH)
|
||||||
#define KO_VERSION_INT (KO_MAJOR << 16) | (KO_MINOR << 8) | KO_PATCH
|
#define KO_VERSION_INT (KO_MAJOR << 16) | (KO_MINOR << 8) | KO_PATCH
|
||||||
|
|
||||||
@@ -89,6 +89,15 @@ MODULE_VERSION(KO_VERSION);
|
|||||||
*/
|
*/
|
||||||
#define MAX_MTU CANFD_MTU
|
#define MAX_MTU CANFD_MTU
|
||||||
|
|
||||||
|
#define KERNEL_CHECKS_MTU_RANGE (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
|
||||||
|
#define KERNEL_FAULT_TAKES_VMA (LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0))
|
||||||
|
#define KERNEL_SUPPORTS_ALIASES (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
|
||||||
|
#define KERNEL_DEFINES_VM_FAULT_T (LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0))
|
||||||
|
|
||||||
|
#if KERNEL_DEFINES_VM_FAULT_T == 0
|
||||||
|
typedef int vm_fault_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct intrepid_pending_tx_info {
|
struct intrepid_pending_tx_info {
|
||||||
int tx_box_index;
|
int tx_box_index;
|
||||||
int count;
|
int count;
|
||||||
@@ -102,6 +111,7 @@ struct intrepid_netdevice {
|
|||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
int is_stopped;
|
int is_stopped;
|
||||||
unsigned char *from_user;
|
unsigned char *from_user;
|
||||||
|
uint8_t tx_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int is_open;
|
static int is_open;
|
||||||
@@ -125,6 +135,27 @@ static spinlock_t tx_box_lock;
|
|||||||
(shared_mem + (RX_BOX_SIZE * DEVICE_INDEX))
|
(shared_mem + (RX_BOX_SIZE * DEVICE_INDEX))
|
||||||
#define GET_TX_BOX(BOX_INDEX) \
|
#define GET_TX_BOX(BOX_INDEX) \
|
||||||
(shared_mem + (SHARED_MEM_SIZE / 2) + (BOX_INDEX * TX_BOX_SIZE))
|
(shared_mem + (SHARED_MEM_SIZE / 2) + (BOX_INDEX * TX_BOX_SIZE))
|
||||||
|
#define MAX_TX (0x100)
|
||||||
|
#define DESC_OFFSET (2)
|
||||||
|
|
||||||
|
static uint16_t intrepid_next_tx_description(
|
||||||
|
struct intrepid_netdevice* ics,
|
||||||
|
int* idx_out)
|
||||||
|
{
|
||||||
|
/* we offset the description so that we know 0 is not us transmitting */
|
||||||
|
uint16_t description = ics->tx_idx + DESC_OFFSET;
|
||||||
|
*idx_out = ics->tx_idx;
|
||||||
|
ics->tx_idx++;
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int intrepid_description_to_idx(uint16_t description)
|
||||||
|
{
|
||||||
|
if (description < DESC_OFFSET || description >= DESC_OFFSET + MAX_TX)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return description - DESC_OFFSET;
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns 1 when we would not have enough space to hold another message of `size` */
|
/* Returns 1 when we would not have enough space to hold another message of `size` */
|
||||||
static inline int intrepid_tx_box_no_space_for(size_t size)
|
static inline int intrepid_tx_box_no_space_for(size_t size)
|
||||||
@@ -173,16 +204,14 @@ static void intrepid_pause_all_queues(void)
|
|||||||
static netdev_tx_t intrepid_netdevice_xmit(struct sk_buff *skb, struct net_device *dev)
|
static netdev_tx_t intrepid_netdevice_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||||
{
|
{
|
||||||
int ret = NETDEV_TX_OK;
|
int ret = NETDEV_TX_OK;
|
||||||
struct net_device_stats *stats = &dev->stats;
|
|
||||||
struct intrepid_netdevice *ics = netdev_priv(dev);
|
struct intrepid_netdevice *ics = netdev_priv(dev);
|
||||||
struct canfd_frame *cf = (struct canfd_frame*)skb->data;
|
struct canfd_frame *cf = (struct canfd_frame*)skb->data;
|
||||||
bool fd = can_is_canfd_skb(skb);
|
bool fd = can_is_canfd_skb(skb);
|
||||||
bool needs_unlock = false;
|
bool needs_unlock = false;
|
||||||
|
bool consumed = false;
|
||||||
|
int tx_idx;
|
||||||
neomessage_can_t msg = {0};
|
neomessage_can_t msg = {0};
|
||||||
|
|
||||||
stats->tx_packets++;
|
|
||||||
stats->tx_bytes = cf->len;
|
|
||||||
|
|
||||||
if (can_dropped_invalid_skb(dev, skb)) {
|
if (can_dropped_invalid_skb(dev, skb)) {
|
||||||
pr_info("intrepid: dropping invalid frame on %s\n", dev->name);
|
pr_info("intrepid: dropping invalid frame on %s\n", dev->name);
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -228,16 +257,21 @@ static netdev_tx_t intrepid_netdevice_xmit(struct sk_buff *skb, struct net_devic
|
|||||||
|
|
||||||
msg.length = cf->len;
|
msg.length = cf->len;
|
||||||
msg.netid = dev->base_addr;
|
msg.netid = dev->base_addr;
|
||||||
|
msg.type = ICSNEO_NETWORK_TYPE_CAN;
|
||||||
|
|
||||||
if (intrepid_tx_box_no_space_for(sizeof(neomessage_can_t) + msg.length)) {
|
if (intrepid_tx_box_no_space_for(sizeof(neomessage_can_t) + msg.length)) {
|
||||||
/* This should never happen, the queue should be paused before this */
|
/* This should never happen, the queue should be paused before this */
|
||||||
ssize_t offset = TX_BOX_SIZE;
|
ssize_t offset = TX_BOX_SIZE;
|
||||||
offset -= (tx_box_bytes[current_tx_box] + sizeof(neomessage_can_t) + msg.length);
|
offset -= (tx_box_bytes[current_tx_box] + sizeof(neomessage_can_t) + msg.length);
|
||||||
pr_err("intrepid: %ld length message caused NETDEV_TX_BUSY (%ld)\n", msg.length, offset);
|
pr_err("intrepid: %zu length message caused NETDEV_TX_BUSY (%zd)\n", msg.length, offset);
|
||||||
ret = NETDEV_TX_BUSY;
|
ret = NETDEV_TX_BUSY;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msg.description = intrepid_next_tx_description(ics, &tx_idx);
|
||||||
|
can_put_echo_skb(skb, dev, tx_idx, msg.length);
|
||||||
|
consumed = true;
|
||||||
|
|
||||||
/* Copy the message into the usermode box */
|
/* Copy the message into the usermode box */
|
||||||
memcpy(tx_boxes[current_tx_box] + tx_box_bytes[current_tx_box], &msg, sizeof(neomessage_can_t));
|
memcpy(tx_boxes[current_tx_box] + tx_box_bytes[current_tx_box], &msg, sizeof(neomessage_can_t));
|
||||||
tx_box_bytes[current_tx_box] += sizeof(neomessage_can_t);
|
tx_box_bytes[current_tx_box] += sizeof(neomessage_can_t);
|
||||||
@@ -250,7 +284,7 @@ static netdev_tx_t intrepid_netdevice_xmit(struct sk_buff *skb, struct net_devic
|
|||||||
intrepid_pause_all_queues();
|
intrepid_pause_all_queues();
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if(ret == NETDEV_TX_OK)
|
if(ret == NETDEV_TX_OK && !consumed)
|
||||||
consume_skb(skb);
|
consume_skb(skb);
|
||||||
wake_up_interruptible(&tx_wait);
|
wake_up_interruptible(&tx_wait);
|
||||||
if(needs_unlock)
|
if(needs_unlock)
|
||||||
@@ -262,8 +296,11 @@ static int intrepid_netdevice_stop(struct net_device *dev)
|
|||||||
{
|
{
|
||||||
struct intrepid_netdevice *ics = netdev_priv(dev);
|
struct intrepid_netdevice *ics = netdev_priv(dev);
|
||||||
|
|
||||||
|
close_candev(dev);
|
||||||
|
|
||||||
spin_lock_bh(&ics->lock);
|
spin_lock_bh(&ics->lock);
|
||||||
netif_stop_queue(dev);
|
netif_stop_queue(dev);
|
||||||
|
netif_carrier_off(dev);
|
||||||
spin_unlock_bh(&ics->lock);
|
spin_unlock_bh(&ics->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -272,6 +309,7 @@ static int intrepid_netdevice_stop(struct net_device *dev)
|
|||||||
static int intrepid_netdevice_open(struct net_device *dev)
|
static int intrepid_netdevice_open(struct net_device *dev)
|
||||||
{
|
{
|
||||||
netif_start_queue(dev);
|
netif_start_queue(dev);
|
||||||
|
netif_carrier_on(dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +355,10 @@ static int intrepid_remove_can_if(int index)
|
|||||||
|
|
||||||
static int intrepid_add_can_if(struct intrepid_netdevice **result, const char *requestedName)
|
static int intrepid_add_can_if(struct intrepid_netdevice **result, const char *requestedName)
|
||||||
{
|
{
|
||||||
|
// The `requestedName` parameter is always NULL if KERNEL_SUPPORTS_ALIASES is false
|
||||||
|
#if KERNEL_SUPPORTS_ALIASES
|
||||||
size_t aliasLen = 0;
|
size_t aliasLen = 0;
|
||||||
|
#endif
|
||||||
int i;
|
int i;
|
||||||
int ret = -EPERM;
|
int ret = -EPERM;
|
||||||
struct net_device *dev = NULL;
|
struct net_device *dev = NULL;
|
||||||
@@ -336,7 +377,7 @@ static int intrepid_add_can_if(struct intrepid_netdevice **result, const char *r
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = alloc_candev(sizeof(*ics), 1);
|
dev = alloc_candev(sizeof(*ics), MAX_TX);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
pr_alert("intrepid: Could not allocate candev\n");
|
pr_alert("intrepid: Could not allocate candev\n");
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -345,23 +386,28 @@ static int intrepid_add_can_if(struct intrepid_netdevice **result, const char *r
|
|||||||
|
|
||||||
dev->base_addr = i;
|
dev->base_addr = i;
|
||||||
dev->flags |= IFF_ECHO;
|
dev->flags |= IFF_ECHO;
|
||||||
|
#if KERNEL_CHECKS_MTU_RANGE
|
||||||
dev->min_mtu = CAN_MTU;
|
dev->min_mtu = CAN_MTU;
|
||||||
dev->max_mtu = CANFD_MTU;
|
dev->max_mtu = MAX_MTU;
|
||||||
|
#endif
|
||||||
dev->mtu = CANFD_MTU; /* TODO: Check CAN-FD support from usermode daemon */
|
dev->mtu = CANFD_MTU; /* TODO: Check CAN-FD support from usermode daemon */
|
||||||
dev->netdev_ops = &intrepid_netdevice_ops;
|
dev->netdev_ops = &intrepid_netdevice_ops;
|
||||||
|
#if KERNEL_SUPPORTS_ALIASES
|
||||||
if (requestedName && ((aliasLen = strlen(requestedName)) > 0) && aliasLen < IFALIASZ) {
|
if (requestedName && ((aliasLen = strlen(requestedName)) > 0) && aliasLen < IFALIASZ) {
|
||||||
dev->ifalias = kzalloc(sizeof(struct dev_ifalias) + aliasLen + 1, GFP_KERNEL);
|
dev->ifalias = kzalloc(sizeof(struct dev_ifalias) + aliasLen + 1, GFP_KERNEL);
|
||||||
if (dev->ifalias == NULL) {
|
if (dev->ifalias == NULL) {
|
||||||
pr_alert("intrepid: Could not allocate space for ifalias %lu\n", sizeof(struct dev_ifalias));
|
pr_alert("intrepid: Could not allocate space for ifalias %zu\n", sizeof(struct dev_ifalias));
|
||||||
} else {
|
} else {
|
||||||
strncpy(dev->ifalias->ifalias, requestedName, aliasLen + 1);
|
strncpy(dev->ifalias->ifalias, requestedName, aliasLen + 1);
|
||||||
pr_info("intrepid: %s alias set to %s\n", dev->name, requestedName);
|
pr_info("intrepid: %s alias set to %s\n", dev->name, requestedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
ics = netdev_priv(dev);
|
ics = netdev_priv(dev);
|
||||||
ics->dev = dev;
|
ics->dev = dev;
|
||||||
ics->is_stopped = 0;
|
ics->is_stopped = 0;
|
||||||
ics->from_user = GET_RX_BOX(i); /* incoming rx messages */
|
ics->from_user = GET_RX_BOX(i); /* incoming rx messages */
|
||||||
|
ics->tx_idx = 0;
|
||||||
|
|
||||||
spin_lock_init(&ics->lock);
|
spin_lock_init(&ics->lock);
|
||||||
|
|
||||||
@@ -453,7 +499,10 @@ static int intrepid_fill_can_frame_from_neomessage(
|
|||||||
if (msg->status.remoteFrame)
|
if (msg->status.remoteFrame)
|
||||||
cf->can_id |= CAN_RTR_FLAG;
|
cf->can_id |= CAN_RTR_FLAG;
|
||||||
|
|
||||||
cf->can_dlc = get_can_dlc(msg->length);
|
if (unlikely(msg->length > 8))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
cf->can_dlc = msg->length;
|
||||||
memcpy(cf->data, data, cf->can_dlc);
|
memcpy(cf->data, data, cf->can_dlc);
|
||||||
|
|
||||||
stats->rx_bytes += cf->can_dlc;
|
stats->rx_bytes += cf->can_dlc;
|
||||||
@@ -462,23 +511,74 @@ static int intrepid_fill_can_frame_from_neomessage(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns true if this message was handled as a transmit receipt.
|
||||||
|
* If false is returned, this message should be handled as a receive
|
||||||
|
* message, regardless of the transmit flag.
|
||||||
|
*/
|
||||||
|
static bool handle_transmit_receipt(
|
||||||
|
struct net_device *device,
|
||||||
|
const neomessage_can_t *msg,
|
||||||
|
const uint8_t *data,
|
||||||
|
struct net_device_stats *stats)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
int tx_idx;
|
||||||
|
|
||||||
|
if (!msg->status.transmitMessage)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tx_idx = intrepid_description_to_idx(msg->description);
|
||||||
|
|
||||||
|
/* not transmitted by us, maybe by CoreMini */
|
||||||
|
/* just handle it as a receive */
|
||||||
|
if (tx_idx < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* unsuccessful transmits */
|
||||||
|
/* stats are handled in intrepid_fill_canerr_frame_from_neomessage */
|
||||||
|
if (msg->status.globalError) {
|
||||||
|
can_free_echo_skb(device, tx_idx, NULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
length = can_get_echo_skb(device, tx_idx, NULL);
|
||||||
|
stats->tx_packets++;
|
||||||
|
stats->tx_bytes += length;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static struct sk_buff *intrepid_skb_from_neomessage(
|
static struct sk_buff *intrepid_skb_from_neomessage(
|
||||||
struct net_device *device,
|
struct net_device *device,
|
||||||
const neomessage_t *msg,
|
const neomessage_frame_t *msg_generic,
|
||||||
const uint8_t *data,
|
const uint8_t *data,
|
||||||
struct net_device_stats *stats)
|
struct net_device_stats *stats)
|
||||||
{
|
{
|
||||||
struct sk_buff *skb = NULL;
|
struct sk_buff *skb = NULL;
|
||||||
struct canfd_frame* cf = NULL;
|
struct canfd_frame* cf = NULL;
|
||||||
|
const neomessage_can_t* msg = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* input validation */
|
/* input validation */
|
||||||
if (unlikely(device == NULL || msg == NULL || data == NULL || stats == NULL)) {
|
if (unlikely(device == NULL || msg_generic == NULL || data == NULL || stats == NULL)) {
|
||||||
stats->rx_dropped++;
|
stats->rx_dropped++;
|
||||||
pr_warn("intrepid: Dropping message on %s, skb from neomessage input validation failed", device->name);
|
pr_warn("intrepid: Dropping message on %s, skb from neomessage input validation failed", device->name);
|
||||||
goto fail;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unlikely(msg_generic->type != ICSNEO_NETWORK_TYPE_CAN)) {
|
||||||
|
stats->rx_dropped++;
|
||||||
|
pr_warn("intrepid: Dropping message on %s, wrong type %d", device->name, (int)msg_generic->type);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = (const neomessage_can_t*)msg_generic;
|
||||||
|
|
||||||
|
/* if this message is handled as a transmit receipt,
|
||||||
|
* don't turn it into a receive skb here.
|
||||||
|
*/
|
||||||
|
if (handle_transmit_receipt(device, msg, data, stats))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (msg->status.globalError)
|
if (msg->status.globalError)
|
||||||
skb = alloc_can_err_skb(device, (struct can_frame**)&cf);
|
skb = alloc_can_err_skb(device, (struct can_frame**)&cf);
|
||||||
else if (msg->status.canfdFDF)
|
else if (msg->status.canfdFDF)
|
||||||
@@ -489,7 +589,7 @@ static struct sk_buff *intrepid_skb_from_neomessage(
|
|||||||
if (unlikely(skb == NULL)) {
|
if (unlikely(skb == NULL)) {
|
||||||
stats->rx_dropped++;
|
stats->rx_dropped++;
|
||||||
pr_warn("intrepid: Dropping message on %s, skb allocation failed", device->name);
|
pr_warn("intrepid: Dropping message on %s, skb allocation failed", device->name);
|
||||||
goto fail;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(msg->type) {
|
switch(msg->type) {
|
||||||
@@ -514,16 +614,16 @@ static struct sk_buff *intrepid_skb_from_neomessage(
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr_warn("intrepid: Dropping message on %s, invalid type %d", device->name, msg->type);
|
pr_warn("intrepid: Dropping message on %s, invalid type %d", device->name, msg->type);
|
||||||
goto fail;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (unlikely(ret != 0)) {
|
if (unlikely(ret != 0)) {
|
||||||
pr_warn("intrepid: Dropping message on %s, frame fill failed", device->name);
|
pr_warn("intrepid: Dropping message on %s, frame fill failed", device->name);
|
||||||
goto fail;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
out:
|
||||||
return skb;
|
return skb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,19 +648,19 @@ static int intrepid_read_messages(int device_index, unsigned int count)
|
|||||||
* converting neomessage_t to a CAN sk_buff */
|
* converting neomessage_t to a CAN sk_buff */
|
||||||
|
|
||||||
while (count--) {
|
while (count--) {
|
||||||
const neomessage_t *msg;
|
const neomessage_frame_t *msg;
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
msg = (const neomessage_t*)currentPosition;
|
msg = (const neomessage_frame_t*)currentPosition;
|
||||||
currentPosition += sizeof(neomessage_t);
|
currentPosition += sizeof(neomessage_frame_t);
|
||||||
data = currentPosition;
|
data = currentPosition;
|
||||||
currentPosition += msg->length;
|
currentPosition += msg->length;
|
||||||
|
|
||||||
/* pass along the converted message to the kernel for dispatch */
|
/* pass along the converted message to the kernel for dispatch */
|
||||||
skb = intrepid_skb_from_neomessage(device, msg, data, stats);
|
skb = intrepid_skb_from_neomessage(device, msg, data, stats);
|
||||||
if (likely(skb != NULL))
|
if (skb != NULL)
|
||||||
ret = netif_rx(skb);
|
ret = netif_rx(skb);
|
||||||
|
|
||||||
if (ret == NET_RX_DROP)
|
if (ret == NET_RX_DROP)
|
||||||
@@ -582,14 +682,20 @@ static long intrepid_dev_ioctl(struct file *fp, unsigned int cmd, unsigned long
|
|||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case SIOCSADDIF: {
|
case SIOCSADDIF: {
|
||||||
struct intrepid_netdevice *result = NULL;
|
struct intrepid_netdevice *result = NULL;
|
||||||
|
#if KERNEL_SUPPORTS_ALIASES
|
||||||
char requestedNameBuffer[IFALIASZ] = {0};
|
char requestedNameBuffer[IFALIASZ] = {0};
|
||||||
char* requestedName = NULL;
|
char* requestedName = NULL;
|
||||||
|
int bytesNotCopied = 0;
|
||||||
if ((void __user*)arg != NULL) {
|
if ((void __user*)arg != NULL) {
|
||||||
copy_from_user(requestedNameBuffer, (void __user*)arg, IFALIASZ);
|
bytesNotCopied = copy_from_user(requestedNameBuffer, (void __user*)arg, IFALIASZ);
|
||||||
|
if(bytesNotCopied != 0)
|
||||||
|
pr_warn("intrepid: %d bytes not copied for alias", bytesNotCopied);
|
||||||
requestedName = requestedNameBuffer;
|
requestedName = requestedNameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = intrepid_add_can_if(&result, requestedName);
|
ret = intrepid_add_can_if(&result, requestedName);
|
||||||
|
#else
|
||||||
|
ret = intrepid_add_can_if(&result, NULL);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SIOCSREMOVEIF:
|
case SIOCSREMOVEIF:
|
||||||
@@ -607,9 +713,11 @@ static long intrepid_dev_ioctl(struct file *fp, unsigned int cmd, unsigned long
|
|||||||
case SIOCGCLIENTVEROK:
|
case SIOCGCLIENTVEROK:
|
||||||
/* Here we can do checks to see if the usermode daemon is
|
/* Here we can do checks to see if the usermode daemon is
|
||||||
* a compatible version with us. We don't enforce anything
|
* a compatible version with us. We don't enforce anything
|
||||||
* on the kernel side. For now, being version 2.X.X is good.
|
* on the kernel side. icsscand v2.0.0 will not work with
|
||||||
|
* older kernels, and would display an obscure error, thus
|
||||||
|
* we want to ask the user to update to v2.0.1 or later
|
||||||
*/
|
*/
|
||||||
if (VER_MAJ_FROM_INT(arg) == 2)
|
if (VER_MAJ_FROM_INT(arg) == 2 && (VER_MIN_FROM_INT(arg) > 0 || VER_PATCH_FROM_INT(arg) >= 1))
|
||||||
ret = 0; /* ok to start */
|
ret = 0; /* ok to start */
|
||||||
else
|
else
|
||||||
ret = 1;
|
ret = 1;
|
||||||
@@ -632,8 +740,8 @@ static long intrepid_dev_ioctl(struct file *fp, unsigned int cmd, unsigned long
|
|||||||
*
|
*
|
||||||
* Starting in kernel version 4.11, (struct vm_operations_struct *)->fault() no
|
* Starting in kernel version 4.11, (struct vm_operations_struct *)->fault() no
|
||||||
* longer takes the vma parameter (since it resides in vmf) */
|
* longer takes the vma parameter (since it resides in vmf) */
|
||||||
static int intrepid_vm_fault(
|
static vm_fault_t intrepid_vm_fault(
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
|
#if KERNEL_FAULT_TAKES_VMA
|
||||||
struct vm_area_struct *vma,
|
struct vm_area_struct *vma,
|
||||||
#endif
|
#endif
|
||||||
struct vm_fault *vmf)
|
struct vm_fault *vmf)
|
||||||
@@ -809,7 +917,7 @@ exit:
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
free_net_devices:
|
free_net_devices:
|
||||||
kzfree(net_devices);
|
kfree(net_devices);
|
||||||
free_shared_mem:
|
free_shared_mem:
|
||||||
vfree(shared_mem);
|
vfree(shared_mem);
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
+54
-19
@@ -16,12 +16,12 @@ typedef union {
|
|||||||
uint32_t extendedFrame : 1;
|
uint32_t extendedFrame : 1;
|
||||||
uint32_t remoteFrame : 1;
|
uint32_t remoteFrame : 1;
|
||||||
uint32_t crcError : 1;
|
uint32_t crcError : 1;
|
||||||
uint32_t canErrorPassive : 1;
|
uint32_t canErrorPassive : 1; // Occupies the same space as headerCRCError
|
||||||
uint32_t incompleteFrame : 1;
|
uint32_t incompleteFrame : 1;
|
||||||
uint32_t lostArbitration : 1;
|
uint32_t lostArbitration : 1;
|
||||||
uint32_t undefinedError : 1;
|
uint32_t undefinedError : 1;
|
||||||
uint32_t canBusOff : 1;
|
uint32_t canBusOff : 1;
|
||||||
uint32_t canErrorWarning : 1;
|
uint32_t canBusRecovered : 1;
|
||||||
uint32_t canBusShortedPlus : 1;
|
uint32_t canBusShortedPlus : 1;
|
||||||
uint32_t canBusShortedGround : 1;
|
uint32_t canBusShortedGround : 1;
|
||||||
uint32_t checksumError : 1;
|
uint32_t checksumError : 1;
|
||||||
@@ -98,6 +98,10 @@ typedef union {
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef uint16_t neonetid_t;
|
||||||
|
typedef uint8_t neonettype_t;
|
||||||
|
typedef uint16_t neomessagetype_t;
|
||||||
|
|
||||||
#define ICSNEO_NETWORK_TYPE_INVALID ((uint8_t)0)
|
#define ICSNEO_NETWORK_TYPE_INVALID ((uint8_t)0)
|
||||||
#define ICSNEO_NETWORK_TYPE_INTERNAL ((uint8_t)1) // Used for statuses that don't actually need to be transferred to the client application
|
#define ICSNEO_NETWORK_TYPE_INTERNAL ((uint8_t)1) // Used for statuses that don't actually need to be transferred to the client application
|
||||||
#define ICSNEO_NETWORK_TYPE_CAN ((uint8_t)2)
|
#define ICSNEO_NETWORK_TYPE_CAN ((uint8_t)2)
|
||||||
@@ -109,42 +113,73 @@ typedef union {
|
|||||||
#define ICSNEO_NETWORK_TYPE_OTHER ((uint8_t)0xFF)
|
#define ICSNEO_NETWORK_TYPE_OTHER ((uint8_t)0xFF)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
neomessage_statusbitfield_t status;
|
uint8_t _reserved1[16];
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
uint64_t timestampReserved;
|
uint64_t _reservedTimestamp;
|
||||||
const uint8_t* data;
|
uint8_t _reserved2[sizeof(size_t) * 2 + 7 + sizeof(neonetid_t) + sizeof(neonettype_t)];
|
||||||
size_t length;
|
neomessagetype_t messageType;
|
||||||
uint8_t header[4];
|
uint8_t _reserved3[12];
|
||||||
uint16_t netid;
|
|
||||||
uint8_t type;
|
|
||||||
uint8_t reserved[17];
|
|
||||||
} neomessage_t; // 72 bytes total
|
} neomessage_t; // 72 bytes total
|
||||||
// Any time you add another neomessage_*_t type, make sure to add it to the static_asserts below!
|
// Any time you add another neomessage_*_t type, make sure to add it to the static_asserts below!
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
neomessage_statusbitfield_t status;
|
neomessage_statusbitfield_t status;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
uint64_t timestampReserved;
|
uint64_t _reservedTimestamp;
|
||||||
|
const uint8_t* data;
|
||||||
|
size_t length;
|
||||||
|
uint8_t header[4];
|
||||||
|
neonetid_t netid;
|
||||||
|
neonettype_t type;
|
||||||
|
uint8_t _reserved0;
|
||||||
|
uint16_t description;
|
||||||
|
neomessagetype_t messageType;
|
||||||
|
uint8_t _reserved1[12];
|
||||||
|
} neomessage_frame_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
neomessage_statusbitfield_t status;
|
||||||
|
uint64_t timestamp;
|
||||||
|
uint64_t _reservedTimestamp;
|
||||||
const uint8_t* data;
|
const uint8_t* data;
|
||||||
size_t length;
|
size_t length;
|
||||||
uint32_t arbid;
|
uint32_t arbid;
|
||||||
uint16_t netid;
|
neonetid_t netid;
|
||||||
uint8_t type;
|
neonettype_t type;
|
||||||
uint8_t dlcOnWire;
|
uint8_t dlcOnWire;
|
||||||
uint8_t reserved[16];
|
uint16_t description;
|
||||||
|
neomessagetype_t messageType;
|
||||||
|
uint8_t _reserved1[12];
|
||||||
} neomessage_can_t;
|
} neomessage_can_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
neomessage_statusbitfield_t status;
|
neomessage_statusbitfield_t status;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
uint64_t timestampReserved;
|
uint64_t _reservedTimestamp;
|
||||||
|
size_t _reserved2[2];
|
||||||
|
uint8_t transmitErrorCount;
|
||||||
|
uint8_t receiveErrorCount;
|
||||||
|
uint8_t _reserved3[5];
|
||||||
|
neonetid_t netid;
|
||||||
|
neonettype_t type;
|
||||||
|
neomessagetype_t messageType;
|
||||||
|
uint8_t _reserved4[12];
|
||||||
|
} neomessage_can_error_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
neomessage_statusbitfield_t status;
|
||||||
|
uint64_t timestamp;
|
||||||
|
uint64_t _reservedTimestamp;
|
||||||
const uint8_t* data;
|
const uint8_t* data;
|
||||||
size_t length;
|
size_t length;
|
||||||
uint8_t preemptionFlags;
|
uint8_t preemptionFlags;
|
||||||
uint8_t reservedHeader[3];
|
uint8_t _reservedHeader[3];
|
||||||
uint16_t netid;
|
neonetid_t netid;
|
||||||
uint8_t type;
|
neonettype_t type;
|
||||||
uint8_t reserved[17];
|
uint8_t _reserved0;
|
||||||
|
uint16_t description;
|
||||||
|
neomessagetype_t messageType;
|
||||||
|
uint8_t _reserved1[12];
|
||||||
} neomessage_eth_t;
|
} neomessage_eth_t;
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
Reference in New Issue
Block a user