aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorOliver Hartkopp <oliver.hartkopp@volkswagen.de>2007-11-16 18:52:17 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:54:10 -0500
commit0d66548a10cbbe0ef256852d63d30603f0f73f9b (patch)
tree58c91033f88014c6a25b4d105a721bc58ec35f2c /include/linux
parentcd05acfe65ed2cf2db683fa9a6adb8d35635263b (diff)
[CAN]: Add PF_CAN core module
This patch adds the CAN core functionality but no protocols or drivers. No protocol implementations are included here. They come as separate patches. Protocol numbers are already in include/linux/can.h. Signed-off-by: Oliver Hartkopp <oliver.hartkopp@volkswagen.de> Signed-off-by: Urs Thuermann <urs.thuermann@volkswagen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/can.h111
-rw-r--r--include/linux/can/core.h64
-rw-r--r--include/linux/can/error.h93
3 files changed, 268 insertions, 0 deletions
diff --git a/include/linux/can.h b/include/linux/can.h
new file mode 100644
index 000000000000..d18333302cbd
--- /dev/null
+++ b/include/linux/can.h
@@ -0,0 +1,111 @@
1/*
2 * linux/can.h
3 *
4 * Definitions for CAN network layer (socket addr / CAN frame / CAN filter)
5 *
6 * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
7 * Urs Thuermann <urs.thuermann@volkswagen.de>
8 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
9 * All rights reserved.
10 *
11 * Send feedback to <socketcan-users@lists.berlios.de>
12 *
13 */
14
15#ifndef CAN_H
16#define CAN_H
17
18#include <linux/types.h>
19#include <linux/socket.h>
20
21/* controller area network (CAN) kernel definitions */
22
23/* special address description flags for the CAN_ID */
24#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
25#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
26#define CAN_ERR_FLAG 0x20000000U /* error frame */
27
28/* valid bits in CAN ID for frame formats */
29#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
30#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
31#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
32
33/*
34 * Controller Area Network Identifier structure
35 *
36 * bit 0-28 : CAN identifier (11/29 bit)
37 * bit 29 : error frame flag (0 = data frame, 1 = error frame)
38 * bit 30 : remote transmission request flag (1 = rtr frame)
39 * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
40 */
41typedef __u32 canid_t;
42
43/*
44 * Controller Area Network Error Frame Mask structure
45 *
46 * bit 0-28 : error class mask (see include/linux/can/error.h)
47 * bit 29-31 : set to zero
48 */
49typedef __u32 can_err_mask_t;
50
51/**
52 * struct can_frame - basic CAN frame structure
53 * @can_id: the CAN ID of the frame and CAN_*_FLAG flags, see above.
54 * @can_dlc: the data length field of the CAN frame
55 * @data: the CAN frame payload.
56 */
57struct can_frame {
58 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
59 __u8 can_dlc; /* data length code: 0 .. 8 */
60 __u8 data[8] __attribute__((aligned(8)));
61};
62
63/* particular protocols of the protocol family PF_CAN */
64#define CAN_RAW 1 /* RAW sockets */
65#define CAN_BCM 2 /* Broadcast Manager */
66#define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
67#define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
68#define CAN_MCNET 5 /* Bosch MCNet */
69#define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
70#define CAN_NPROTO 7
71
72#define SOL_CAN_BASE 100
73
74/**
75 * struct sockaddr_can - the sockaddr structure for CAN sockets
76 * @can_family: address family number AF_CAN.
77 * @can_ifindex: CAN network interface index.
78 * @can_addr: protocol specific address information
79 */
80struct sockaddr_can {
81 sa_family_t can_family;
82 int can_ifindex;
83 union {
84 /* transport protocol class address information (e.g. ISOTP) */
85 struct { canid_t rx_id, tx_id; } tp;
86
87 /* reserved for future CAN protocols address information */
88 } can_addr;
89};
90
91/**
92 * struct can_filter - CAN ID based filter in can_register().
93 * @can_id: relevant bits of CAN ID which are not masked out.
94 * @can_mask: CAN mask (see description)
95 *
96 * Description:
97 * A filter matches, when
98 *
99 * <received_can_id> & mask == can_id & mask
100 *
101 * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
102 * filter for error frames (CAN_ERR_FLAG bit set in mask).
103 */
104struct can_filter {
105 canid_t can_id;
106 canid_t can_mask;
107};
108
109#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
110
111#endif /* CAN_H */
diff --git a/include/linux/can/core.h b/include/linux/can/core.h
new file mode 100644
index 000000000000..e9ca210ffa5b
--- /dev/null
+++ b/include/linux/can/core.h
@@ -0,0 +1,64 @@
1/*
2 * linux/can/core.h
3 *
4 * Protoypes and definitions for CAN protocol modules using the PF_CAN core
5 *
6 * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
7 * Urs Thuermann <urs.thuermann@volkswagen.de>
8 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
9 * All rights reserved.
10 *
11 * Send feedback to <socketcan-users@lists.berlios.de>
12 *
13 */
14
15#ifndef CAN_CORE_H
16#define CAN_CORE_H
17
18#include <linux/can.h>
19#include <linux/skbuff.h>
20#include <linux/netdevice.h>
21
22#define CAN_VERSION "20071116"
23
24/* increment this number each time you change some user-space interface */
25#define CAN_ABI_VERSION "8"
26
27#define CAN_VERSION_STRING "rev " CAN_VERSION " abi " CAN_ABI_VERSION
28
29#define DNAME(dev) ((dev) ? (dev)->name : "any")
30
31/**
32 * struct can_proto - CAN protocol structure
33 * @type: type argument in socket() syscall, e.g. SOCK_DGRAM.
34 * @protocol: protocol number in socket() syscall.
35 * @capability: capability needed to open the socket, or -1 for no restriction.
36 * @ops: pointer to struct proto_ops for sock->ops.
37 * @prot: pointer to struct proto structure.
38 */
39struct can_proto {
40 int type;
41 int protocol;
42 int capability;
43 struct proto_ops *ops;
44 struct proto *prot;
45};
46
47/* function prototypes for the CAN networklayer core (af_can.c) */
48
49extern int can_proto_register(struct can_proto *cp);
50extern void can_proto_unregister(struct can_proto *cp);
51
52extern int can_rx_register(struct net_device *dev, canid_t can_id,
53 canid_t mask,
54 void (*func)(struct sk_buff *, void *),
55 void *data, char *ident);
56
57extern void can_rx_unregister(struct net_device *dev, canid_t can_id,
58 canid_t mask,
59 void (*func)(struct sk_buff *, void *),
60 void *data);
61
62extern int can_send(struct sk_buff *skb, int loop);
63
64#endif /* CAN_CORE_H */
diff --git a/include/linux/can/error.h b/include/linux/can/error.h
new file mode 100644
index 000000000000..d4127fd9e681
--- /dev/null
+++ b/include/linux/can/error.h
@@ -0,0 +1,93 @@
1/*
2 * linux/can/error.h
3 *
4 * Definitions of the CAN error frame to be filtered and passed to the user.
5 *
6 * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
7 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
8 * All rights reserved.
9 *
10 * Send feedback to <socketcan-users@lists.berlios.de>
11 *
12 */
13
14#ifndef CAN_ERROR_H
15#define CAN_ERROR_H
16
17#define CAN_ERR_DLC 8 /* dlc for error frames */
18
19/* error class (mask) in can_id */
20#define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */
21#define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */
22#define CAN_ERR_CRTL 0x00000004U /* controller problems / data[1] */
23#define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */
24#define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */
25#define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */
26#define CAN_ERR_BUSOFF 0x00000040U /* bus off */
27#define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
28#define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
29
30/* arbitration lost in bit ... / data[0] */
31#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
32 /* else bit number in bitstream */
33
34/* error status of CAN-controller / data[1] */
35#define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */
36#define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */
37#define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */
38#define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */
39#define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */
40#define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */
41#define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */
42 /* (at least one error counter exceeds */
43 /* the protocol-defined level of 127) */
44
45/* error in CAN protocol (type) / data[2] */
46#define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */
47#define CAN_ERR_PROT_BIT 0x01 /* single bit error */
48#define CAN_ERR_PROT_FORM 0x02 /* frame format error */
49#define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */
50#define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */
51#define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */
52#define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */
53#define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */
54#define CAN_ERR_PROT_TX 0x80 /* error occured on transmission */
55
56/* error in CAN protocol (location) / data[3] */
57#define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */
58#define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */
59#define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */
60#define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/
61#define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */
62#define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */
63#define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */
64#define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */
65#define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */
66#define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */
67#define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */
68#define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */
69#define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */
70#define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */
71#define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */
72#define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */
73#define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */
74#define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */
75#define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */
76#define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */
77
78/* error status of CAN-transceiver / data[4] */
79/* CANH CANL */
80#define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */
81#define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */
82#define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 /* 0000 0101 */
83#define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 /* 0000 0110 */
84#define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 /* 0000 0111 */
85#define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */
86#define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 /* 0101 0000 */
87#define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 /* 0110 0000 */
88#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */
89#define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */
90
91/* controller specific additional information / data[5..7] */
92
93#endif /* CAN_ERROR_H */