From 19ee95491af87afac9ea33d30cc3003db7ec288d Mon Sep 17 00:00:00 2001 From: Kurt Van Dijck Date: Wed, 13 Mar 2013 21:05:55 +0100 Subject: [PATCH] can-j1939: update headers with j1939 Signed-off-by: Kurt Van Dijck Signed-off-by: Marc Kleine-Budde --- GNUmakefile.am | 1 + include/linux/can.h | 20 +++++++++- include/linux/can/j1939.h | 81 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 include/linux/can/j1939.h diff --git a/GNUmakefile.am b/GNUmakefile.am index c824f55..db81487 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -18,6 +18,7 @@ noinst_HEADERS = \ include/linux/can/gw.h \ include/linux/can.h \ include/linux/can/isotp.h \ + include/linux/can/j1939.h \ include/linux/can/netlink.h \ include/linux/can/raw.h \ include/linux/can/vxcan.h diff --git a/include/linux/can.h b/include/linux/can.h index 984915c..3ed2f17 100644 --- a/include/linux/can.h +++ b/include/linux/can.h @@ -157,7 +157,8 @@ struct canfd_frame { #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */ #define CAN_MCNET 5 /* Bosch MCNet */ #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */ -#define CAN_NPROTO 7 +#define CAN_J1939 7 /* SAE J1939 */ +#define CAN_NPROTO 8 #define SOL_CAN_BASE 100 @@ -185,6 +186,23 @@ struct sockaddr_can { canid_t tx_id; } tp; + /* J1939 address information */ + struct { + /* 8 byte name when using dynamic addressing */ + __u64 name; + /* + * pgn: + * 8bit: PS in PDU2 case, else 0 + * 8bit: PF + * 1bit: DP + * 1bit: reserved + */ + __u32 pgn; + + /* 1byte address */ + __u8 addr; + } j1939; + /* reserved for future CAN protocols address information */ } can_addr; }; diff --git a/include/linux/can/j1939.h b/include/linux/can/j1939.h new file mode 100644 index 0000000..cd4661a --- /dev/null +++ b/include/linux/can/j1939.h @@ -0,0 +1,81 @@ +/* + * j1939.h + * + * Copyright (c) 2010-2011 EIA Electronics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _UAPI_CAN_J1939_H_ +#define _UAPI_CAN_J1939_H_ + +#include +#include +#include + +#define J1939_IDLE_ADDR 0xfe +#define J1939_NO_ADDR 0xff +#define J1939_NO_NAME 0 +#define J1939_NO_PGN 0x40000 + +/* J1939 Parameter Group Number + * + * bit 0-7 : PDU Specific (PS) + * bit 8-15 : PDU Format (PF) + * bit 16 : Data Page (DP) + * bit 17 : Reserved (R) + * bit 19-31 : set to zero + */ +typedef __u32 pgn_t; + +/* J1939 Priority + * + * bit 0-2 : Priority (P) + * bit 3-7 : set to zero + */ +typedef __u8 priority_t; + +/* J1939 NAME + * + * bit 0-20 : Identity Number + * bit 21-31 : Manufacturer Code + * bit 32-34 : ECU Instance + * bit 35-39 : Function Instance + * bit 40-47 : Function + * bit 48 : Reserved + * bit 49-55 : Vehicle System + * bit 56-59 : Vehicle System Instance + * bit 60-62 : Industry Group + * bit 63 : Arbitrary Address Capable + */ +typedef __u64 name_t; + +/* J1939 socket options */ +#define SOL_CAN_J1939 (SOL_CAN_BASE + CAN_J1939) +enum { + SO_J1939_FILTER = 1, /* set filters */ + SO_J1939_PROMISC = 2, /* set/clr promiscuous mode */ + SO_J1939_RECV_OWN = 3, + SO_J1939_SEND_PRIO = 4, +}; + +enum { + SCM_J1939_DEST_ADDR = 1, + SCM_J1939_DEST_NAME = 2, + SCM_J1939_PRIO = 3, +}; + +struct j1939_filter { + name_t name; + name_t name_mask; + __u8 addr; + __u8 addr_mask; + pgn_t pgn; + pgn_t pgn_mask; +}; + +#define J1939_FILTER_MAX 512 /* maximum number of j1939_filter set via setsockopt() */ + +#endif /* !_UAPI_CAN_J1939_H_ */