Re: How to send a CAN message while in a kernel module?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21/03/2020 20.15, Robert Barrows wrote:
You don't use sockets from INSIDE the kernel.
If you want to send CAN frames from inside the kernel you should use the
can_send() function from af_can.c
Great to know! I Will look at that right away, any example(s) you could point
me towards?


You mainly need to look at raw_sendmsg() from linux/net/can/raw.c

Create a skb and set can_skb_reserve() and the other stuff and finally put your CAN frame content into the skb->data and invoke can_send().

You will at least need

#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/can.h>
#include <linux/can/core.h>
#include <linux/can/skb.h>

Of course you don't have a sk reference as you don't have a socket in place.

So you maybe should check the content of alloc_can_skb() from linux/drivers/net/can/dev.c and use netdev_alloc_skb() or alloc_skb() instead of sock_alloc_send_skb() which needs sk to take care of socket specific memory quotas.

If you are unsure just post the code for a review.

Best,
Oliver




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux