I need to send a CAN-bus J1939 message with no data using socketcan. The reason why the message needs to be sent with no data is to follow the spec J1939-73 DM11 (PGN=0x00FED3).
The C code below works fine when sending data that is at least 1 byte in length. When sizeof(dat) == 0, the sendto() function does not send the message at all. We can verify this with candump vcan0
.
Is there any way to send a message with 0 byte of data using socket(PF_CAN, SOCK_DGRAM, CAN_J1939) ? It can confirm that it can be done in raw CAN using socket(AF_CAN, SOCK_RAW, CAN_RAW) but I need it to work with the J1939 protocol socket.
How can we contact the kernel developers to submit a bug/enhancement request?
The J1939 linux kernel documentation can be found here: https://www.kernel.org/doc/html/v5.8/networking/j1939.html
Thank you.
#include <inttypes.h>
#include <linux/can/j1939.h>
#include <sys/socket.h>
#include <net/if.h>
int main() {
int sock;
const char device[] = "vcan0";
uint8_t dat[2];
dat[0] = 0;
dat[1] = 1;
struct sockaddr_can baddr = {
.can_family = AF_CAN,
.can_addr.j1939 = {
.name = J1939_NO_NAME,
.addr = 0x20,
.pgn = J1939_NO_PGN,
},
.can_ifindex = if_nametoindex(device),
};
sock = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
bind(sock, (void *)&baddr, sizeof(baddr));
struct sockaddr_can saddr = {
.can_family = AF_CAN,
.can_addr.j1939 = {
.name = J1939_NO_NAME,
.addr = 0x30,
.pgn = 0xFED3,
},
};
// sendto(sock, dat, sizeof(dat), 0, (const struct sockaddr *)&saddr, sizeof(saddr));
sendto(sock, dat, 0, 0, (const struct sockaddr *)&saddr, sizeof(saddr));
return 0;
}
question from:
https://stackoverflow.com/questions/66049756/sending-can-bus-j1939-messages-with-no-data-in-linux 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…