├── .gitignore
├── LICENSE
├── Protocol
├── CanInterfaceDefinition.md
├── FrameCalculations.xlsx
├── bootMenu.gif
├── flowchart_boot_menu.dot
├── flowchart_boot_menu.png
├── flowchart_boot_menu2.png
├── flowchart_flashing.dot
└── flowchart_flashing.png
├── README.md
├── RasPi
├── .cproject
├── .project
├── .settings
│ └── language.settings.xml
├── CanInterface.c
├── CanInterface.h
├── CanMessage.h
├── GNUmakefile.am
├── Makefile
├── asc2log.c
├── autogen.sh
├── bcmserver.c
├── can-calc-bit-timing.c
├── canbusload.c
├── candump.c
├── canfdtest.c
├── cangen.c
├── cangw.c
├── canlogserver.c
├── cannon.c
├── cannon.h
├── canplayer.c
├── cansend.c
├── cansniffer.c
├── cantest.c
├── clean.sh
├── config.c
├── config.h
├── configure.ac
├── file_input.c
├── file_input.h
├── include
│ ├── linux
│ │ ├── can.h
│ │ └── can
│ │ │ ├── bcm.h
│ │ │ ├── core.h
│ │ │ ├── dev.h
│ │ │ ├── error.h
│ │ │ ├── gw.h
│ │ │ ├── isotp.h
│ │ │ ├── netlink.h
│ │ │ └── raw.h
│ └── socketcan
│ │ ├── can.h
│ │ └── can
│ │ ├── bcm.h
│ │ ├── error.h
│ │ ├── gw.h
│ │ ├── ioctl.h
│ │ ├── isotp.h
│ │ ├── netlink.h
│ │ └── raw.h
├── isotpdump.c
├── isotprecv.c
├── isotpsend.c
├── isotpserver.c
├── isotpsniffer.c
├── isotptun.c
├── lib.c
├── lib.h
├── log2asc.c
├── log2long.c
├── makefile
├── sendToBBB.sh
├── sendToPi.sh
├── slcan_attach.c
├── slcand.c
├── slcanpty.c
├── startCanInterface.sh
├── stopCanInterface.sh
├── stp.sh.save
└── terminal.h
└── STM32
├── .mxproject
├── Drivers
├── CMSIS
│ ├── Device
│ │ └── ST
│ │ │ └── STM32F4xx
│ │ │ ├── Include
│ │ │ ├── stm32f405xx.h
│ │ │ ├── stm32f4xx.h
│ │ │ └── system_stm32f4xx.h
│ │ │ └── Source
│ │ │ └── Templates
│ │ │ └── gcc
│ │ │ └── startup_stm32f405xx.s
│ └── Include
│ │ ├── arm_common_tables.h
│ │ ├── arm_const_structs.h
│ │ ├── arm_math.h
│ │ ├── cmsis_armcc.h
│ │ ├── cmsis_armcc_V6.h
│ │ ├── cmsis_gcc.h
│ │ ├── core_cm0.h
│ │ ├── core_cm0plus.h
│ │ ├── core_cm3.h
│ │ ├── core_cm4.h
│ │ ├── core_cm7.h
│ │ ├── core_cmFunc.h
│ │ ├── core_cmInstr.h
│ │ ├── core_cmSimd.h
│ │ ├── core_sc000.h
│ │ └── core_sc300.h
└── STM32F4xx_HAL_Driver
│ ├── Inc
│ ├── Legacy
│ │ └── stm32_hal_legacy.h
│ ├── stm32f4xx_hal.h
│ ├── stm32f4xx_hal_can.h
│ ├── stm32f4xx_hal_cortex.h
│ ├── stm32f4xx_hal_def.h
│ ├── stm32f4xx_hal_dma.h
│ ├── stm32f4xx_hal_dma_ex.h
│ ├── stm32f4xx_hal_flash.h
│ ├── stm32f4xx_hal_flash_ex.h
│ ├── stm32f4xx_hal_flash_ramfunc.h
│ ├── stm32f4xx_hal_gpio.h
│ ├── stm32f4xx_hal_gpio_ex.h
│ ├── stm32f4xx_hal_pwr.h
│ ├── stm32f4xx_hal_pwr_ex.h
│ ├── stm32f4xx_hal_rcc.h
│ ├── stm32f4xx_hal_rcc_ex.h
│ ├── stm32f4xx_hal_tim.h
│ └── stm32f4xx_hal_tim_ex.h
│ └── Src
│ ├── stm32f4xx_hal.c
│ ├── stm32f4xx_hal_can.c
│ ├── stm32f4xx_hal_cortex.c
│ ├── stm32f4xx_hal_dma.c
│ ├── stm32f4xx_hal_dma_ex.c
│ ├── stm32f4xx_hal_flash.c
│ ├── stm32f4xx_hal_flash_ex.c
│ ├── stm32f4xx_hal_flash_ramfunc.c
│ ├── stm32f4xx_hal_gpio.c
│ ├── stm32f4xx_hal_pwr.c
│ ├── stm32f4xx_hal_pwr_ex.c
│ ├── stm32f4xx_hal_rcc.c
│ ├── stm32f4xx_hal_rcc_ex.c
│ ├── stm32f4xx_hal_tim.c
│ └── stm32f4xx_hal_tim_ex.c
├── Inc
├── can.h
├── gpio.h
├── main.h
├── stm32f4xx_hal_conf.h
└── stm32f4xx_it.h
├── STM32.ioc
├── STM32.pdf
├── STM32.txt
├── SW4STM32
├── STM32
│ ├── .cproject
│ ├── .custom.cfg
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ └── language.settings.xml
│ ├── Application
│ │ ├── Inc
│ │ │ ├── config.h
│ │ │ ├── eeprom.h
│ │ │ ├── link_layer.h
│ │ │ └── target_device.h
│ │ └── User
│ │ │ ├── can.c
│ │ │ ├── eeprom.c
│ │ │ ├── link_layer.c
│ │ │ └── target_device.c
│ ├── GT_9D_STM32.cfg
│ ├── STM32.xml
│ ├── STM32F405RGTx_FLASH.ld
│ ├── core
│ └── gt_9d_stm32.xml
└── startup_stm32f405xx.s
└── Src
├── can.c
├── gpio.c
├── main.c
├── stm32f4xx_hal_msp.c
├── stm32f4xx_it.c
└── system_stm32f4xx.c
/.gitignore:
--------------------------------------------------------------------------------
1 | Debug/
2 |
3 | # Object files
4 | *.o
5 | *.ko
6 | *.obj
7 | *.elf
8 |
9 | # Precompiled Headers
10 | *.gch
11 | *.pch
12 |
13 | # Libraries
14 | *.lib
15 | *.a
16 | *.la
17 | *.lo
18 |
19 | # Shared objects (inc. Windows DLLs)
20 | *.dll
21 | *.so
22 | *.so.*
23 | *.dylib
24 |
25 | # Executables
26 | *.exe
27 | *.out
28 | *.app
29 | *.i*86
30 | *.x86_64
31 | *.hex
32 |
33 | # Debug files
34 | *.dSYM/
35 | *.su
36 |
--------------------------------------------------------------------------------
/Protocol/FrameCalculations.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxcd/CANnon/948f92a580b735612361a133187608d53781b50b/Protocol/FrameCalculations.xlsx
--------------------------------------------------------------------------------
/Protocol/bootMenu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxcd/CANnon/948f92a580b735612361a133187608d53781b50b/Protocol/bootMenu.gif
--------------------------------------------------------------------------------
/Protocol/flowchart_boot_menu.dot:
--------------------------------------------------------------------------------
1 | digraph G
2 | {
3 | graph [ dpi = 400 ];
4 | start [label="START"];
5 | rankdir=LR;
6 | {rank = same; user_app; wait_interrupt}
7 | wait_interrupt [label="Waiting for interrupt"];
8 | user_app [label="User Application"];
9 | menu [label="Boot Menu"] [shape="box"] [width="1"] [height="6"];
10 | flash_mode [label="Flash Mode"][group=g1];
11 | send_ping[label="Send ping"][group=g1];
12 | get_version[label="Get programm version"][group=g1];
13 | get_name[label="Get programm name"][group=g1];
14 | get_crc[label="Get flash CRC"][group=g1];
15 | get_chip_id[label="Get chip id"][group=g1];
16 |
17 | start -> wait_interrupt
18 | wait_interrupt -> menu [label="Interrupt Message (0x03)"];
19 | wait_interrupt -> user_app[label="T>500ms"];
20 | menu -> flash_mode [label="Init Flash Mode (0x08)"];
21 | flash_mode -> menu [label="Exit Flash Mode (0x0C)"];
22 | menu -> send_ping [label="Ping request (0x00, 0x01)"];
23 | send_ping -> menu [label="Ping response (0x02)"];
24 | menu -> get_version[label="Version request (0x04)"];
25 | get_version -> menu[label="Version response (0x05)"];
26 | menu -> get_name[label="Name request (0x06)"];
27 | get_name -> menu[label="Name response (0x07)"];
28 | menu -> get_crc[label="CRC request (0x0D)"];
29 | get_crc -> menu [label="CRC response (0x0E)"];
30 | menu -> user_app[label="Start user app (0xFF)"]
31 | menu -> get_chip_id[label="ChipId request (0x12)"];
32 | get_chip_id -> menu[label="Send ChipId (0x13)"];
33 | }
34 |
--------------------------------------------------------------------------------
/Protocol/flowchart_boot_menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxcd/CANnon/948f92a580b735612361a133187608d53781b50b/Protocol/flowchart_boot_menu.png
--------------------------------------------------------------------------------
/Protocol/flowchart_boot_menu2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxcd/CANnon/948f92a580b735612361a133187608d53781b50b/Protocol/flowchart_boot_menu2.png
--------------------------------------------------------------------------------
/Protocol/flowchart_flashing.dot:
--------------------------------------------------------------------------------
1 | digraph G
2 | {
3 | graph [ dpi = 400 ];
4 | menu [label="Boot Menu"] [shape="box"] [width="3"] [height="1"];
5 | flash_mode [label="Flash Mode"];
6 | wait_flash_message [label = "Waiting for flash message"];
7 | flash_message_received [label = "Flash message received"];
8 | ack_request_received [label = "Ack request received"];
9 | sending_ack [label = "Sending ACK frame"];
10 | sending_nack [label= "Sending NACK frame"];
11 | write_to_flash [label = "Write Message to Flash"];
12 |
13 | menu -> flash_mode [label="Init Flash Mode (0x08)"];
14 | flash_mode -> wait_flash_message[label="Start Flash Process (0x0F)"];
15 | wait_flash_message -> flash_message_received;
16 | flash_message_received -> write_to_flash -> wait_flash_message;
17 | wait_flash_message -> ack_request_received [label="ACK request (0x09)"];
18 | ack_request_received -> sending_ack [label="All received"];
19 | sending_ack -> wait_flash_message[label="0x0A"];
20 | ack_request_received -> sending_nack[label="Packs missing"];
21 | sending_nack -> wait_flash_message[label="0x0B"];
22 | wait_flash_message -> flash_mode[label="End flash process (0x10)"];
23 | flash_mode -> menu [label="Exit Flash Mode (0x0C)"];
24 | }
25 |
--------------------------------------------------------------------------------
/Protocol/flowchart_flashing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxcd/CANnon/948f92a580b735612361a133187608d53781b50b/Protocol/flowchart_flashing.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CANnon
2 | #### A versatile CAN bootloader for the STM32 and friends
3 |
4 | ##### Why would anyone name a bootloader CANnon?
5 | Well, there are several reasons for that:
6 | * First off, there is the historical approach: a bootloader (or bootstrap loader) is named after the saying "to pull oneself up by one's bootstraps". Then there was this other guy named Baron Munchausen, who famously pulled himself out of the swamp by his pigtail. Munchausen was also good at riding cannon balls, so there you have it.
7 | * Secondly, it is supposed to load the program on the micro controller via CAN. CANnon... you get it
8 | * Thirdly, we are shooting some .bin files at the controller, so that seemed legit.
9 |
10 | ##### Modules
11 |
12 | The CANnon bootloader consists of two modules:
13 | * The CANnon that shoots the CANonball (.bin file) at the target
14 | * The target code that accepts what the CANon shoots at it
15 |
--------------------------------------------------------------------------------
/RasPi/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/RasPi/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | RasPiCANnon
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/RasPi/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/RasPi/CanInterface.c:
--------------------------------------------------------------------------------
1 | /*
2 | * CanInterface.cpp
3 | *
4 | * Created on: Mar 16, 2017
5 | * Author: max
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include "lib.h"
30 |
31 | #include "CanMessage.h"
32 | #include "CanInterface.h"
33 | #include "config.h"
34 |
35 |
36 |
37 | void initCanInterface(int deviceId)
38 | {
39 | /* open socket */
40 | if ((baseSocket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0)
41 | {
42 | perror("socket");
43 | }
44 |
45 | addr.can_family = AF_CAN;
46 |
47 | strcpy(ifr.ifr_name, "can0");
48 | if (ioctl(baseSocket, SIOCGIFINDEX, &ifr) < 0)
49 | {
50 | perror("SIOCGIFINDEX");
51 | }
52 | addr.can_ifindex = ifr.ifr_ifindex;
53 |
54 | //struct can_filter *rfilter;
55 | //rfilter = malloc(sizeof(struct can_filter));
56 | struct can_filter rfilter[4];
57 |
58 | if(deviceId != 0)
59 | {
60 | rfilter[0].can_id = CAN_EFF_FLAG | deviceId << 20;
61 | rfilter[0].can_mask = CAN_EFF_FLAG | 0xFF << 20;
62 | }
63 | else
64 | {
65 | rfilter[0].can_id = CAN_EFF_FLAG;
66 | rfilter[0].can_mask = CAN_EFF_FLAG;
67 | }
68 |
69 | rfilter[1].can_id = 0x421;
70 | rfilter[1].can_mask = 0x7FF;
71 |
72 | rfilter[2].can_id = 0x424;
73 | rfilter[2].can_mask = 0x7FF;
74 |
75 | rfilter[3].can_id = 0x427;
76 | rfilter[3].can_mask = 0x7FF;
77 |
78 | setsockopt(baseSocket, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, 4*sizeof(struct can_filter));
79 |
80 | //free(rfilter);
81 |
82 | if (bind(baseSocket, (struct sockaddr *)&addr, sizeof(addr)) < 0)
83 | {
84 | perror("bind");
85 | }
86 |
87 | iov.iov_base = &frame;
88 | msg.msg_name = &addr;
89 | msg.msg_iov = &iov;
90 | msg.msg_iovlen = 1;
91 | msg.msg_control = &ctrlmsg;
92 | }
93 |
94 | int receiveMessage(CanMessage* cMsg)
95 | {
96 | int i;
97 | int nbytes, count = 0;
98 | struct cmsghdr *cmsg;
99 |
100 | cMsg->dlc = 0;
101 | cMsg->id = 0;
102 | cMsg->ext = 0;
103 | for(i = 0; i < 8; ++i)
104 | cMsg->data[i] = 0;
105 |
106 | FD_ZERO(&rdfs);
107 | FD_SET(baseSocket, &rdfs);
108 | if(FD_ISSET(baseSocket, &rdfs))
109 | {
110 | int idx;
111 |
112 | /* these settings may be modified by recvmsg() */
113 | iov.iov_len = sizeof(frame);
114 | msg.msg_namelen = sizeof(addr);
115 | msg.msg_controllen = sizeof(ctrlmsg);
116 | msg.msg_flags = 0;
117 |
118 | nbytes = recvmsg(baseSocket, &msg, MSG_DONTWAIT);
119 | if(nbytes > 0)
120 | {
121 | for (cmsg = CMSG_FIRSTHDR(&msg);
122 | cmsg && (cmsg->cmsg_level == SOL_SOCKET);
123 | cmsg = CMSG_NXTHDR(&msg,cmsg)) {
124 | }
125 |
126 | //idx = idx2dindex(addr.can_ifindex, &addr);
127 | /*
128 | printf("%x:", frame.can_id);
129 | for(i = 0; i < frame.can_dlc; ++i)
130 | {
131 | cMsg->data[i] = frame.data[i];
132 | printf("[%x]", frame.data[i]);
133 | }
134 | printf("\n");*/
135 | cMsg->dlc = frame.can_dlc;
136 | cMsg->ext = true;
137 | cMsg->id = frame.can_id;
138 | }
139 | //printf("Received msg with id %lu\n", cMsg.id);
140 | }
141 |
142 | return nbytes;
143 | }
144 |
145 | int receiveGenericMessage(BlGenericMessage* msg)
146 | {
147 | if(__VERBOSE)
148 | printf("msg receive\n");
149 | fflush(stdout);
150 | CanMessage cMsg;
151 | int nbytes;
152 |
153 | nbytes = receiveMessage(&cMsg);
154 | msgToGeneric(&cMsg, msg);
155 |
156 | printErrorCodes(msg);
157 |
158 | return nbytes;
159 | }
160 |
161 | void printErrorCodes(BlGenericMessage* msg)
162 | {
163 | if(__VERBOSE)
164 | {
165 | if(msg->commandId == STATUS_ID)
166 | {
167 | switch(msg->data[0])
168 | {
169 | case ERRCODE_NO_FLASH_PROCESS:
170 | printf("Error: No flashing in process!\n");
171 | break;
172 | case ERRCODE_NOT_IN_FLASH_MODE:
173 | printf("Error: Not in flash mode\n");
174 | break;
175 | case ERRCODE_NOT_IN_BOOT_MENU:
176 | printf("Error: Not in boot menu\n");
177 | break;
178 | case ERRCODE_ALREADY_FLASHING:
179 | printf("Error: Already flashing\n");
180 | break;
181 | case STATUS_IN_BOOT_MENU:
182 | printf("Status: Entering boot menu\n");
183 | break;
184 | case STATUS_START_ERASE:
185 | printf("Status: Starting flash erase\n");
186 | break;
187 | case STATUS_ERASE_FINISHED:
188 | printf("Status: Flash erase finished\n");
189 | break;
190 | case STATUS_FLASH_START:
191 | printf("Status: Starting flashing\n");
192 | break;
193 | case STATUS_FLASH_DONE:
194 | printf("Status: Flashing done\n");
195 | break;
196 | case STATUS_STARTING_APP:
197 | printf("Status: Starting user app\n");
198 | break;
199 | }
200 | }
201 | }
202 | }
203 |
204 | void sendGenericMessage(BlGenericMessage* msg)
205 | {
206 | if(__VERBOSE)
207 | {
208 | printf("msg send");
209 | fflush(stdout);
210 | }
211 |
212 | CanMessage cMsg;
213 | genericToMsg(msg, &cMsg);
214 | sendMessage(&cMsg);
215 | }
216 |
217 | void sendMessage(CanMessage* msg)
218 | {
219 | if(__VERBOSE)
220 | {
221 | printf("cMsg send");
222 | fflush(stdout);
223 | }
224 |
225 | int nbytes;
226 | int i;
227 | struct can_frame frame;
228 | frame.can_dlc = msg->dlc;
229 | frame.can_id = msg->id;
230 |
231 | if(msg->ext)
232 | {
233 | frame.can_id |= CAN_EFF_FLAG;
234 | }
235 | for(i = 0; i < msg->dlc; ++i)
236 | {
237 | frame.data[i] = msg->data[i];
238 | }
239 |
240 | if ((nbytes = write(baseSocket, &frame, sizeof(frame))) != sizeof(frame))
241 | {
242 | perror("write");
243 | }
244 | }
245 |
246 | void clearInputBuffer()
247 | {
248 | int nbytes;
249 | do
250 | {
251 | CanMessage msg;
252 | nbytes = receiveMessage(&msg);
253 | }
254 | while(nbytes > 0);
255 | }
256 |
257 | static void msgToGeneric(CanMessage* cMsg, BlGenericMessage* msg)
258 | {
259 | msg->FOF = ((cMsg->id>>28)&0x1);
260 | msg->commandId = (cMsg->id>>12)&0xFF;
261 | msg->targetDeviceId = (cMsg->id>>20)&0xFF;
262 | msg->length = cMsg->dlc;
263 | int i;
264 | for(i = 0; i < msg->length; ++i)
265 | {
266 | msg->data[i] = cMsg->data[i];
267 | }
268 | }
269 |
270 | static void genericToMsg(BlGenericMessage* msg, CanMessage* cMsg)
271 | {
272 | int id = ((msg->FOF & 0x1) << 28);
273 | id |= (msg->targetDeviceId & 0xFF) << 20;
274 | if(msg->FOF)
275 | {
276 | id |= (msg->flashPackId & 0xFFFFF);
277 | }
278 | else
279 | {
280 | id |= (msg->commandId & 0xFF) << 12;
281 | }
282 |
283 | cMsg->dlc = msg->length;
284 | cMsg->id = id;
285 | cMsg->ext = 1;
286 | int i;
287 | for(i = 0; i < msg->length; ++i)
288 | {
289 | cMsg->data[i] = msg->data[i];
290 | }
291 | }
292 |
293 | /** Returns true on success, or false if there was an error */
294 | bool SetSocketBlockingEnabled(int fd, bool blocking)
295 | {
296 | if (fd < 0) return false;
297 |
298 | #ifdef WIN32
299 | unsigned long mode = blocking ? 0 : 1;
300 | return (ioctlsocket(fd, FIONBIO, &mode) == 0) ? true : false;
301 | #else
302 | int flags = fcntl(fd, F_GETFL, 0);
303 | if (flags < 0) return false;
304 | flags = blocking ? (flags&~O_NONBLOCK) : (flags|O_NONBLOCK);
305 | return (fcntl(fd, F_SETFL, flags) == 0) ? true : false;
306 | #endif
307 | }
308 |
309 |
--------------------------------------------------------------------------------
/RasPi/CanInterface.h:
--------------------------------------------------------------------------------
1 | /*
2 | * CanInterface.h
3 | *
4 | * Created on: Mar 16, 2017
5 | * Author: max
6 | */
7 |
8 | #ifndef CANINTERFACE_H_
9 | #define CANINTERFACE_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 |
24 | #include "lib.h"
25 |
26 | #include "CanMessage.h"
27 |
28 | #define MAXANI 4
29 | #define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */
30 | #define MAXIFNAMES 30 /* size of receive name index to omit ioctls */
31 | #define MAXCOL 6 /* number of different colors for colorized output */
32 | #define ANYDEV "any" /* name of interface to receive from any CAN interface */
33 | #define ANL "\r\n" /* newline in ASC mode */
34 |
35 |
36 | void initCanInterface(int deviceId);
37 |
38 | int receiveMessage(CanMessage* cMsg);
39 | int receiveGenericMessage(BlGenericMessage* msg);
40 |
41 | void sendMessage(CanMessage* msg);
42 | void sendGenericMessage(BlGenericMessage* msg);
43 |
44 | void printErrorCodes(BlGenericMessage* msg);
45 |
46 | static void msgToGeneric(CanMessage* cMsg, BlGenericMessage* msg);
47 | static void genericToMsg(BlGenericMessage* msg, CanMessage* cMsg);
48 |
49 | static bool SetSocketBlockingEnabled(int fd, bool blocking);
50 |
51 | void clearInputBuffer();
52 |
53 |
54 | int baseSocket; /* can raw socket */
55 | struct iovec iov;
56 | struct msghdr msg;
57 | struct can_frame frame;
58 | char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
59 | struct sockaddr_can addr;
60 | struct ifreq ifr;
61 | fd_set rdfs;
62 | static int dindex[MAXIFNAMES];
63 |
64 | #endif /* CANINTERFACE_H_ */
65 |
--------------------------------------------------------------------------------
/RasPi/CanMessage.h:
--------------------------------------------------------------------------------
1 | /*
2 | * CanMessage.h
3 | *
4 | * Created on: Mar 16, 2017
5 | * Author: max
6 | */
7 |
8 | #ifndef CANMESSAGE_H_
9 | #define CANMESSAGE_H_
10 | #include
11 |
12 | typedef struct
13 | {
14 | char dlc;
15 | long id;
16 | char data[8];
17 | bool ext;
18 |
19 | }CanMessage;
20 |
21 | typedef struct
22 | {
23 | bool FOF; // FlashOperationField, used when flash packs are being sent
24 |
25 | int targetDeviceId; // ID of the target device, always used
26 |
27 | int flashPackId; // ID of the flash pack, only used when FOF == 1
28 |
29 | int commandId; // Command ID of the message, used when FOF == 0
30 |
31 | int length; // Length of the data array
32 |
33 | char data[8]; // Data array of the message
34 | }BlGenericMessage;
35 |
36 | #endif /* CANMESSAGE_H_ */
37 |
--------------------------------------------------------------------------------
/RasPi/GNUmakefile.am:
--------------------------------------------------------------------------------
1 | AM_CPPFLAGS = \
2 | -I$(top_srcdir)/include \
3 | -I$(top_builddir)/include \
4 | $(linux_CFLAGS)
5 |
6 | # link every app against libcan, it's static so it wouldn't hurt
7 | LDADD = \
8 | libcan.la
9 |
10 | noinst_HEADERS = \
11 | lib.h \
12 | terminal.h \
13 | include/linux/can/bcm.h \
14 | include/linux/can/core.h \
15 | include/linux/can/dev.h \
16 | include/linux/can/error.h \
17 | include/linux/can/gw.h \
18 | include/linux/can.h \
19 | include/linux/can/isotp.h \
20 | include/linux/can/netlink.h \
21 | include/linux/can/raw.h \
22 | include/socketcan/can/bcm.h \
23 | include/socketcan/can/error.h \
24 | include/socketcan/can/gw.h \
25 | include/socketcan/can.h \
26 | include/socketcan/can/ioctl.h \
27 | include/socketcan/can/isotp.h \
28 | include/socketcan/can/netlink.h \
29 | include/socketcan/can/raw.h
30 |
31 |
32 | noinst_LTLIBRARIES = \
33 | libcan.la
34 |
35 | libcan_la_SOURCES = \
36 | lib.c
37 |
38 |
39 | bin_PROGRAMS = \
40 | asc2log \
41 | bcmserver \
42 | can-calc-bit-timing \
43 | canbusload \
44 | candump \
45 | canfdtest \
46 | cangen \
47 | cangw \
48 | canlogserver \
49 | canplayer \
50 | cansend \
51 | cansniffer \
52 | isotpdump \
53 | isotprecv \
54 | isotpsend \
55 | isotpserver \
56 | isotpsniffer \
57 | isotptun \
58 | log2asc \
59 | log2long \
60 | slcan_attach \
61 | slcand \
62 | slcanpty
63 |
64 | EXTRA_DIST = \
65 | autogen.sh
66 |
67 | MAINTAINERCLEANFILES = \
68 | configure \
69 | GNUmakefile.in \
70 | aclocal.m4 \
71 | config/autoconf/compile \
72 | config/autoconf/config.guess \
73 | config/autoconf/config.sub \
74 | config/autoconf/depcomp \
75 | config/autoconf/install-sh \
76 | config/autoconf/ltmain.sh \
77 | config/autoconf/mdate-sh \
78 | config/autoconf/missing \
79 | config/autoconf/texinfo.tex \
80 | config/m4/libtool.m4 \
81 | config/m4/ltoptions.m4 \
82 | config/m4/ltsugar.m4 \
83 | config/m4/ltversion.m4 \
84 | config/m4/lt~obsolete.m4 \
85 | $(DIST_ARCHIVES)
86 |
87 | maintainer-clean-local:
88 | -chmod -R a+rw $(distdir)
89 | -rm -fr $(distdir)
90 |
91 |
--------------------------------------------------------------------------------
/RasPi/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # $Id$
3 | #
4 | # Copyright (c) 2002-2005 Volkswagen Group Electronic Research
5 | # All rights reserved.
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions
9 | # are met:
10 | # 1. Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions, the following disclaimer and
12 | # the referenced file 'COPYING'.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of Volkswagen nor the names of its contributors
17 | # may be used to endorse or promote products derived from this software
18 | # without specific prior written permission.
19 | #
20 | # Alternatively, provided that this notice is retained in full, this
21 | # software may be distributed under the terms of the GNU General
22 | # Public License ("GPL") version 2 as distributed in the 'COPYING'
23 | # file from the main directory of the linux kernel source.
24 | #
25 | # The provided data structures and external interfaces from this code
26 | # are not restricted to be used by modules with a GPL compatible license.
27 | #
28 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
39 | # DAMAGE.
40 | #
41 | # Send feedback to
42 |
43 | DESTDIR =
44 | PREFIX = /usr/local
45 |
46 | MAKEFLAGS = -k
47 |
48 | CFLAGS = -O2 -Wall -Wno-parentheses -Iinclude \
49 | -fno-strict-aliasing \
50 | -DSO_RXQ_OVFL=40 \
51 | -DPF_CAN=29 \
52 | -DAF_CAN=PF_CAN
53 |
54 | PROGRAMS_ISOTP = isotpdump isotprecv isotpsend isotpsniffer isotptun isotpserver
55 | PROGRAMS_CANGW = cangw
56 | PROGRAMS_SLCAN = slcan_attach slcand
57 | PROGRAMS = can-calc-bit-timing candump cansniffer cansend canplayer cangen canbusload\
58 | log2long log2asc asc2log\
59 | canlogserver bcmserver\
60 | $(PROGRAMS_ISOTP)\
61 | $(PROGRAMS_CANGW)\
62 | $(PROGRAMS_SLCAN)\
63 | slcanpty canfdtest
64 |
65 | all: $(PROGRAMS)
66 |
67 | clean:
68 | rm -f $(PROGRAMS) *.o
69 |
70 | install:
71 | mkdir -p $(DESTDIR)$(PREFIX)/bin
72 | cp -f $(PROGRAMS) $(DESTDIR)$(PREFIX)/bin
73 |
74 | distclean:
75 | rm -f $(PROGRAMS) *.o *~
76 |
77 | cansend.o: lib.h
78 | cangen.o: lib.h
79 | candump.o: lib.h
80 | canplayer.o: lib.h
81 | canlogserver.o: lib.h
82 | canbusload.o: lib.h
83 | log2long.o: lib.h
84 | log2asc.o: lib.h
85 | asc2log.o: lib.h
86 |
87 | cansend: cansend.o lib.o
88 | cangen: cangen.o lib.o
89 | candump: candump.o lib.o
90 | canplayer: canplayer.o lib.o
91 | canlogserver: canlogserver.o lib.o
92 | log2long: log2long.o lib.o
93 | log2asc: log2asc.o lib.o
94 | asc2log: asc2log.o lib.o
95 |
--------------------------------------------------------------------------------
/RasPi/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # usage:
5 | #
6 | # banner
7 | #
8 | banner() {
9 | echo
10 | TG=`echo $1 | sed -e "s,/.*/,,g"`
11 | LINE=`echo $TG |sed -e "s/./-/g"`
12 | echo $LINE
13 | echo $TG
14 | echo $LINE
15 | echo
16 | }
17 |
18 | banner "autoreconf"
19 |
20 | autoreconf --force --install --symlink -Wall || exit $?
21 |
22 | banner "Finished"
23 |
--------------------------------------------------------------------------------
/RasPi/cannon.h:
--------------------------------------------------------------------------------
1 | /*
2 | * cannon.h
3 | *
4 | * Created on: Mar 17, 2017
5 | * Author: max
6 | */
7 |
8 | #ifndef CANNON_H_
9 | #define CANNON_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 |
23 | #include "lib.h"
24 |
25 | //int main(int argc, char **argv);
26 | void doBroadcastPing();
27 | void sendSignalMessage(int deviceId, char command);
28 | void doFlash(char* deviceName);
29 | char* readFile(char* file);
30 | int getFileSize(char* file);
31 | void resetDevice(DEVICE_CONFIG device);
32 | void restoreDevicePower();
33 | void waitFor (unsigned int secs);
34 | void startFlashing(int deviceId, int packsPerSprint, int size);
35 | void sendFlashPack(int deviceId, int packId, char* data, int len);
36 | void waitForSignal(int deviceId, int statusFlag, int triggerMessage, int triggerRate);
37 | DEVICE_CONFIG findDeviceByName(char* deviceName);
38 | char* concat(const char *s1, const char *s2);
39 |
40 | int lvs_f_on_states = 0;
41 | int lvs_r1_on_states = 0;
42 | int lvs_r2_on_states = 0;
43 |
44 | #endif /* CANNON_H_ */
45 |
--------------------------------------------------------------------------------
/RasPi/cansend.c:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id$
3 | */
4 |
5 | /*
6 | * cansend.c - simple command line tool to send CAN-frames via CAN_RAW sockets
7 | *
8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 3. Neither the name of Volkswagen nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * Alternatively, provided that this notice is retained in full, this
24 | * software may be distributed under the terms of the GNU General
25 | * Public License ("GPL") version 2, in which case the provisions of the
26 | * GPL apply INSTEAD OF those given above.
27 | *
28 | * The provided data structures and external interfaces from this code
29 | * are not restricted to be used by modules with a GPL compatible license.
30 | *
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42 | * DAMAGE.
43 | *
44 | * Send feedback to
45 | *
46 | */
47 |
48 | #include
49 | #include
50 | #include
51 | #include
52 |
53 | #include
54 | #include
55 |
56 | #include
57 | #include
58 |
59 | #include "lib.h"
60 |
61 | int main(int argc, char **argv)
62 | {
63 | int s; /* can raw socket */
64 | int nbytes;
65 | struct sockaddr_can addr;
66 | struct can_frame frame;
67 | struct ifreq ifr;
68 |
69 | /* check command line options */
70 | if (argc != 3) {
71 | fprintf(stderr, "Usage: %s .\n", argv[0]);
72 | return 1;
73 | }
74 |
75 | /* parse CAN frame */
76 | if (parse_canframe(argv[2], &frame)){
77 | fprintf(stderr, "\nWrong CAN-frame format!\n\n");
78 | fprintf(stderr, "Try: #{R|data}\n");
79 | fprintf(stderr, "can_id can have 3 (SFF) or 8 (EFF) hex chars\n");
80 | fprintf(stderr, "data has 0 to 8 hex-values that can (optionally)");
81 | fprintf(stderr, " be seperated by '.'\n\n");
82 | fprintf(stderr, "e.g. 5A1#11.2233.44556677.88 / 123#DEADBEEF / ");
83 | fprintf(stderr, "5AA# /\n 1F334455#1122334455667788 / 123#R ");
84 | fprintf(stderr, "for remote transmission request.\n\n");
85 | return 1;
86 | }
87 |
88 | /* open socket */
89 | if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
90 | perror("socket");
91 | return 1;
92 | }
93 |
94 | addr.can_family = AF_CAN;
95 |
96 | strcpy(ifr.ifr_name, argv[1]);
97 | if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
98 | perror("SIOCGIFINDEX");
99 | return 1;
100 | }
101 | addr.can_ifindex = ifr.ifr_ifindex;
102 |
103 | /* disable default receive filter on this RAW socket */
104 | /* This is obsolete as we do not read from the socket at all, but for */
105 | /* this reason we can remove the receive list in the Kernel to save a */
106 | /* little (really a very little!) CPU usage. */
107 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
108 |
109 | if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
110 | perror("bind");
111 | return 1;
112 | }
113 |
114 | /* send frame */
115 | if ((nbytes = write(s, &frame, sizeof(frame))) != sizeof(frame)) {
116 | perror("write");
117 | return 1;
118 | }
119 |
120 | //fprint_long_canframe(stdout, &frame, "\n", 0);
121 |
122 | close(s);
123 |
124 | return 0;
125 | }
126 |
--------------------------------------------------------------------------------
/RasPi/cantest.c:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id$
3 | */
4 |
5 | /*
6 | * cansend.c - simple command line tool to send CAN-frames via CAN_RAW sockets
7 | *
8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 3. Neither the name of Volkswagen nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * Alternatively, provided that this notice is retained in full, this
24 | * software may be distributed under the terms of the GNU General
25 | * Public License ("GPL") version 2, in which case the provisions of the
26 | * GPL apply INSTEAD OF those given above.
27 | *
28 | * The provided data structures and external interfaces from this code
29 | * are not restricted to be used by modules with a GPL compatible license.
30 | *
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42 | * DAMAGE.
43 | *
44 | * Send feedback to
45 | *
46 | */
47 |
48 | /* 20-05-15 Modified to sent a message out in code rather then from parameter.
49 |
50 | www.skpang.co.uk
51 | */
52 | #include
53 | #include
54 | #include
55 | #include
56 | #include
57 |
58 | #include
59 | #include
60 |
61 | #include
62 | #include
63 |
64 | #include "lib.h"
65 |
66 | int main(int argc, char **argv)
67 | {
68 | int s; /* can raw socket */
69 | int nbytes;
70 | struct sockaddr_can addr;
71 | struct can_frame frame;
72 | struct ifreq ifr;
73 |
74 | int i;
75 |
76 | /* CAN message to be sent out */
77 | unsigned char buff[] = "7DF#0201050000000000";
78 |
79 | fprintf(stderr,"CAN testing\n");
80 |
81 | /* parse CAN frame */
82 | if (parse_canframe(buff, &frame)){
83 | fprintf(stderr, "\nWrong CAN-frame format!\n\n");
84 | fprintf(stderr, "Try: #{R|data}\n");
85 | fprintf(stderr, "can_id can have 3 (SFF) or 8 (EFF) hex chars\n");
86 | fprintf(stderr, "data has 0 to 8 hex-values that can (optionally)");
87 | fprintf(stderr, " be seperated by '.'\n\n");
88 | fprintf(stderr, "e.g. 5A1#11.2233.44556677.88 / 123#DEADBEEF / ");
89 | fprintf(stderr, "5AA# /\n 1F334455#1122334455667788 / 123#R ");
90 | fprintf(stderr, "for remote transmission request.\n\n");
91 | return 1;
92 | }
93 |
94 | /* open socket */
95 | if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
96 | perror("socket");
97 | return 1;
98 | }
99 |
100 | addr.can_family = AF_CAN;
101 |
102 | strcpy(ifr.ifr_name, "can0");
103 | if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
104 | perror("SIOCGIFINDEX");
105 | return 1;
106 | }
107 | addr.can_ifindex = ifr.ifr_ifindex;
108 |
109 | /* disable default receive filter on this RAW socket */
110 | /* This is obsolete as we do not read from the socket at all, but for */
111 | /* this reason we can remove the receive list in the Kernel to save a */
112 | /* little (really a very little!) CPU usage. */
113 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
114 |
115 | if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
116 | perror("bind");
117 | return 1;
118 | }
119 |
120 | /* send frame */
121 | for(i=0;i<100;i++)
122 | {
123 | if ((nbytes = write(s, &frame, sizeof(frame))) != sizeof(frame)) {
124 | perror("write");
125 | return 1;
126 | }
127 |
128 | fprintf(stderr, "%d \n", i);
129 |
130 | usleep(10000); /* Delay before next loop */
131 | }
132 |
133 | close(s);
134 | return 0;
135 | }
136 |
--------------------------------------------------------------------------------
/RasPi/clean.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | rm *.o
3 | rm cannon
4 |
--------------------------------------------------------------------------------
/RasPi/config.c:
--------------------------------------------------------------------------------
1 | /*
2 | * config.c
3 | *
4 | * Created on: Apr 5, 2017
5 | * Author: max
6 | */
7 |
8 | #include "config.h"
9 |
10 | /**
11 | * Definition of Target Devices
12 | */
13 | void initTargetDeviceConfig()
14 | {
15 | blconf[0].id = 1;
16 | blconf[0].name = "COM_GW";
17 | blconf[0].LVS = LVS_R1;
18 | blconf[0].CH = 8;
19 |
20 | blconf[1].id = 2;
21 | blconf[1].name = "HMI_DB";
22 | blconf[1].LVS = LVS_F;
23 | blconf[1].CH = 7;
24 |
25 | blconf[2].id = 3;
26 | blconf[2].name = "HVM_BMS";
27 | blconf[2].LVS = LVS_R2;
28 | blconf[2].CH = 1;
29 |
30 | blconf[3].id = 4;
31 | blconf[3].name = "HVM_ECU";
32 | blconf[3].LVS = LVS_R1;
33 | blconf[3].CH = 2;
34 |
35 | blconf[4].id = 5;
36 | blconf[4].name = "HVM_PM";
37 | blconf[4].LVS = LVS_R1;
38 | blconf[4].CH = 4;
39 |
40 | blconf[5].id = 6;
41 | blconf[5].name = "LVS_BMS";
42 | blconf[5].LVS = LVS_NONE;
43 | blconf[5].CH = -1;
44 |
45 | blconf[6].id = 7;
46 | blconf[6].name = "LVS_ECU_F";
47 | blconf[6].LVS = LVS_BMS;
48 | blconf[6].CH = 0;
49 |
50 | blconf[7].id = 8;
51 | blconf[7].name = "LVS_ECU_R1";
52 | blconf[7].LVS = LVS_BMS;
53 | blconf[7].CH = 0;
54 |
55 | blconf[8].id = 9;
56 | blconf[8].name = "LVS_ECU_R2";
57 | blconf[8].LVS = LVS_BMS;
58 | blconf[8].CH = 0;
59 |
60 | blconf[9].id = 10;
61 | blconf[9].name = "MS_AD_F";
62 | blconf[9].LVS = LVS_F;
63 | blconf[9].CH = 5;
64 |
65 | blconf[10].id = 11;
66 | blconf[10].name = "MS_AD_PEDALS";
67 | blconf[10].LVS = LVS_F;
68 | blconf[10].CH = 1;
69 |
70 | blconf[11].id = 12;
71 | blconf[11].name = "MS_9D_F";
72 | blconf[11].LVS = LVS_F;
73 | blconf[11].CH = 4;
74 |
75 | blconf[12].id = 13;
76 | blconf[12].name = "MS_V2O";
77 | blconf[12].LVS = LVS_F;
78 | blconf[12].CH = 6;
79 |
80 | blconf[13].id = 14;
81 | blconf[13].name = "VD_ECU";
82 | blconf[13].LVS = LVS_R2;
83 | blconf[13].CH = 6;
84 |
85 | blconf[14].id = 15;
86 | blconf[14].name = "MS_AD_R";
87 | blconf[14].LVS = LVS_R2;
88 | blconf[14].CH = 8;
89 |
90 | blconf[15].id = 16;
91 | blconf[15].name = "MS_9D_R";
92 | blconf[15].LVS = LVS_R2;
93 | blconf[15].CH = 3;
94 |
95 | blconf[16].id = 17;
96 | blconf[16].name = "MS_TT_FL";
97 | blconf[16].LVS = LVS_F;
98 | blconf[16].CH = 0;
99 |
100 | blconf[17].id = 18;
101 | blconf[17].name = "MS_TT_FR";
102 | blconf[17].LVS = LVS_F;
103 | blconf[17].CH = 0;
104 |
105 | blconf[18].id = 19;
106 | blconf[18].name = "MS_TT_RL";
107 | blconf[18].LVS = LVS_R1;
108 | blconf[18].CH = 4;
109 |
110 | blconf[19].id = 20;
111 | blconf[19].name = "MS_TT_RR";
112 | blconf[19].LVS = LVS_R1;
113 | blconf[19].CH = 4;
114 |
115 | blconf[20].id = 21;
116 | blconf[20].name = "MS_AD_OCPD";
117 | blconf[20].LVS = LVS_R1;
118 | blconf[20].CH = 2;
119 |
120 | maxDeviceCount = 21;
121 |
122 | //#define CHIP_ID 1U // COM_GW // R1 8
123 | //#define CHIP_ID 2U // HMI_DB // F 2
124 | //#define CHIP_ID 3U // HVM_BMS // R2 1
125 | //#define CHIP_ID 4U // HVM_ECU // R1 2
126 | //#define CHIP_ID 5U // HVM_PM // R1 6
127 | //#define CHIP_ID 6U // LVS_BMS
128 | //#define CHIP_ID 7U // LVS_ECU_F
129 | //#define CHIP_ID 8U // LVS_ECU_R1
130 | //#define CHIP_ID 9U // LVS_ECU_R2
131 | //#define CHIP_ID 10U // MS_AD_F // F 5
132 | //#define CHIP_ID 11U // MS_AD_PEDAL // F 1
133 | //#define CHIP_ID 12U // MS_9D_F // F 4
134 | //#define CHIP_ID 13U // MS_V2O // F 6
135 | //#define CHIP_ID 14U // VD_ECU // R2 6
136 | /*------ CAN A2 ------*/
137 | //#define CHIP_ID 15U // MS_AD_R // R2 8
138 | //#define CHIP_ID 16U // MS_9D_R // R2 3
139 | //#define CHIP_ID 17U // MS_TT_FL // F 0
140 | //#define CHIP_ID 18U // MS_TT_FR // F 0
141 | //#define CHIP_ID 19U // MS_TT_RL // R1 4
142 | //#define CHIP_ID 20U // MS_TT_RR // R1 4
143 | }
144 | /**
145 | * End Definition of Target Devices
146 | */
147 |
148 |
149 |
--------------------------------------------------------------------------------
/RasPi/config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * config.h
3 | *
4 | * Created on: Mar 18, 2017
5 | * Author: max
6 | */
7 |
8 | #ifndef CONFIG_H_
9 | #define CONFIG_H_
10 |
11 |
12 | /**
13 | * Command ID defines start
14 | */
15 | #define SINGLE_PING_ID 0x00 // OUTGOING -->
16 | #define BROADCAST_PING_ID 0x01 // OUTGOING -->
17 | #define PING_RESPONSE_ID 0x02 // INCOMING <--
18 | #define INTERRUPT_ID 0x03 // OUTGOING -->
19 | #define GET_VERSION_ID 0x04 // OUTGOING -->
20 | #define SEND_VERSION_ID 0x05 // INCOMING <--
21 | #define GET_NAME_ID 0x06 // OUTGOING -->
22 | #define SEND_NAME_ID 0x07 // INCOMING <--
23 | #define INIT_FLASH_ID 0x08 // OUTGOING -->
24 | #define ACK_REQUEST_ID 0x09 // OUTGOING -->
25 | #define ACK_ID 0x0A // INCOMING <--
26 | #define NACK_ID 0x0B // INCOMING <--
27 | #define EXIT_FLASH_ID 0x0C // OUTGOING -->
28 | #define GET_CRC_ID 0x0D // OUTGOING -->
29 | #define SEND_CRC_ID 0x0E // INCOMING <--
30 | #define START_FLASH_ID 0x0F // OUTGOING -->
31 | #define END_FLASH_ID 0x10 // OUTGOING -->
32 | #define STATUS_ID 0x11 // INCOMING <--
33 | #define GET_CHIP_ID 0x12 // OUTGOING -->
34 | #define SEND_CHIP_ID 0x13 // INCOMING <--
35 | #define START_APP_ID 0xFF // OUTGOING -->
36 | /**
37 | * Command ID defines end
38 | */
39 |
40 | /**
41 | * Error Codes
42 | */
43 | #define ERRCODE_OK 0U
44 | #define ERRCODE_NO_FLASH_PROCESS 1U
45 | #define ERRCODE_NOT_IN_FLASH_MODE 2U
46 | #define ERRCODE_NOT_IN_BOOT_MENU 3U
47 | #define ERRCODE_ALREADY_FLASHING 4U
48 | #define STATUS_IN_BOOT_MENU 5U
49 | #define STATUS_START_ERASE 6U
50 | #define STATUS_ERASE_FINISHED 7U
51 | #define STATUS_FLASH_START 8U
52 | #define STATUS_FLASH_DONE 9U
53 | #define STATUS_STARTING_APP 10U
54 | /*
55 | * Error Codes end
56 | */
57 |
58 | #define CANNON_DEVICE_ID 42U
59 | #define __VERBOSE 0
60 |
61 | #define LVS_F 0
62 | #define LVS_R1 1
63 | #define LVS_R2 2
64 | #define LVS_NONE 3
65 | #define LVS_BMS 4
66 |
67 | #define LVS_F_CAN_ID 0x410
68 | #define LVS_R1_CAN_ID 0x412
69 | #define LVS_R2_CAN_ID 0x413
70 |
71 | typedef struct
72 | {
73 | int LVS;
74 | int CH;
75 | char* name;
76 | int id;
77 |
78 | }DEVICE_CONFIG;
79 |
80 | DEVICE_CONFIG blconf[30];
81 | int maxDeviceCount;
82 |
83 | void initTargetDeviceConfig();
84 |
85 |
86 | #endif /* CONFIG_H_ */
87 |
--------------------------------------------------------------------------------
/RasPi/configure.ac:
--------------------------------------------------------------------------------
1 | # -*- Autoconf -*-
2 | # Process this file with autoconf to produce a configure script.
3 | AC_PREREQ(2.59)
4 |
5 | AC_INIT([can-utils], [trunk], [socketcan-core@lists.berlios.de])
6 | AC_CONFIG_SRCDIR([lib.c])
7 | AC_CONFIG_MACRO_DIR([config/m4])
8 | AC_CONFIG_AUX_DIR([config/autoconf])
9 | AC_CANONICAL_BUILD
10 | AC_CANONICAL_HOST
11 |
12 | #AM_MAINTAINER_MODE
13 |
14 | CFLAGS="${CFLAGS} -Wall"
15 |
16 | #
17 | # Checks for programs.
18 | #
19 | AC_PROG_CC
20 | #AM_MISSING_PROG(PERL, perl, $missing_dir)
21 | # libtool, old:
22 | AC_LIBTOOL_WIN32_DLL
23 | #AC_LIBTOOL_TAGS([])
24 | AC_PROG_LIBTOOL
25 | # libtool, new:
26 | # LT_INIT(win32-dll)
27 |
28 | AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2])
29 |
30 |
31 | #
32 | # Checks for header files.
33 | #
34 | AC_CHECK_HEADERS([ \
35 | fcntl.h \
36 | limits.h \
37 | locale.h \
38 | stdint.h \
39 | stdlib.h \
40 | string.h \
41 | syslog.h \
42 | termios.h \
43 | unistd.h \
44 | \
45 | netinet/in.h \
46 | \
47 | sys/ioctl.h \
48 | sys/socket.h \
49 | sys/time.h \
50 | ])
51 |
52 |
53 | #
54 | # Checks for typedefs, structures, and compiler characteristics.
55 | #
56 | AC_C_INLINE
57 | AC_TYPE_PID_T
58 | AC_TYPE_UINT64_T
59 |
60 |
61 | #
62 | # Checks for library functions.
63 | #
64 | AC_FUNC_FORK
65 | AC_FUNC_MKTIME
66 | AC_CHECK_FUNCS([ \
67 | alarm \
68 | gettimeofday \
69 | localtime_r \
70 | memset \
71 | select \
72 | setlocale \
73 | socket \
74 | strchr \
75 | strerror \
76 | strstr \
77 | strtoul \
78 | ])
79 |
80 |
81 | AC_CHECK_DECL(SO_RXQ_OVFL,,
82 | [AC_DEFINE([SO_RXQ_OVFL], [40], [SO_RXQ_OVFL])]
83 | )
84 | AC_CHECK_DECL(PF_CAN,,
85 | [AC_DEFINE([PF_CAN], [29], [PF_CAN])]
86 | )
87 | AC_CHECK_DECL(AF_CAN,,
88 | [AC_DEFINE([AF_CAN], [PF_CAN], [AF_CAN])]
89 | )
90 |
91 |
92 | #
93 | # Debugging
94 | #
95 | AC_MSG_CHECKING([whether to enable debugging])
96 | AC_ARG_ENABLE(debug,
97 | AS_HELP_STRING([--enable-debug], [enable debugging [[default=no]]]),
98 | [case "$enableval" in
99 | (y | yes) CONFIG_DEBUG=yes ;;
100 | (*) CONFIG_DEBUG=no ;;
101 | esac],
102 | [CONFIG_DEBUG=no])
103 | AC_MSG_RESULT([${CONFIG_DEBUG}])
104 | if test "${CONFIG_DEBUG}" = "yes"; then
105 | CFLAGS="${CFLAGS} -Wsign-compare -Wfloat-equal -Wformat-security -g -O1"
106 | AC_DEFINE(DEBUG, 1, [debugging])
107 | else
108 | CFLAGS="${CFLAGS} -O2"
109 | fi
110 |
111 |
112 | AC_CONFIG_FILES([
113 | GNUmakefile
114 | ])
115 | AC_OUTPUT
116 |
--------------------------------------------------------------------------------
/RasPi/file_input.c:
--------------------------------------------------------------------------------
1 |
2 | #include "file_input.h"
3 |
4 |
5 | int main(int argc, char **argv)
6 | {
7 | initCanInterface();
8 | if(argc < 2)
9 | {
10 | fprintf(stderr, "got no arg\n");
11 | // print help
12 | fprintf(stderr, "Please use the help\n");
13 | }
14 | else if(argc == 2)
15 | {
16 | fprintf(stderr, "Got one args\n");
17 |
18 | char* fileArray;
19 | long len = readFile(argv[1], fileArray);
20 |
21 | int i;
22 | for(i = 0; i < len; ++i)
23 | {
24 | printf(fileArray[i]);
25 | }
26 | }
27 | }
28 |
29 | long readFile(char* filename, char* buffer)
30 | {
31 | FILE *fileptr;
32 | long filelen;
33 |
34 | fileptr = fopen(filename, "rb"); // Open the file in binary mode
35 | fseek(fileptr, 0, SEEK_END); // Jump to the end of the file
36 | filelen = ftell(fileptr); // Get the current byte offset in the file
37 | rewind(fileptr); // Jump back to the beginning of the file
38 |
39 | buffer = (char *)malloc((filelen+1)*sizeof(char)); // Enough memory for file + \0
40 | fread(buffer, filelen, 1, fileptr); // Read in the entire file
41 | fclose(fileptr); // Close the file
42 |
43 | return filelen;
44 | }
45 |
--------------------------------------------------------------------------------
/RasPi/file_input.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FILE_INPUT_H_
3 | #define FILE_INPUT_H_
4 |
5 | #include
6 | #include
7 |
8 | char* readFile(char* filename);
9 |
10 |
11 | #endif // FILE_INPUT_H
12 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/bcm.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/core.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/dev.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/error.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/gw.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/isotp.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/netlink.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/linux/can/raw.h:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can.h
3 | *
4 | * Definitions for CAN network layer (socket addr / CAN frame / CAN filter)
5 | *
6 | * $Id$
7 | *
8 | * Authors: Oliver Hartkopp
9 | * Urs Thuermann
10 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
11 | * All rights reserved.
12 | *
13 | * Send feedback to
14 | *
15 | */
16 |
17 | #ifndef CAN_H
18 | #define CAN_H
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | /* controller area network (CAN) kernel definitions */
25 |
26 | /* special address description flags for the CAN_ID */
27 | #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
28 | #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
29 | #define CAN_ERR_FLAG 0x20000000U /* error frame */
30 |
31 | /* valid bits in CAN ID for frame formats */
32 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
33 | #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
34 | #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
35 |
36 | /*
37 | * Controller Area Network Identifier structure
38 | *
39 | * bit 0-28 : CAN identifier (11/29 bit)
40 | * bit 29 : error frame flag (0 = data frame, 1 = error frame)
41 | * bit 30 : remote transmission request flag (1 = rtr frame)
42 | * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
43 | */
44 | typedef __u32 canid_t;
45 |
46 | /*
47 | * Controller Area Network Error Frame Mask structure
48 | *
49 | * bit 0-28 : error class mask (see include/socketcan/can/error.h)
50 | * bit 29-31 : set to zero
51 | */
52 | typedef __u32 can_err_mask_t;
53 |
54 | /**
55 | * struct can_frame - basic CAN frame structure
56 | * @can_id: the CAN ID of the frame and CAN_*_FLAG flags, see above.
57 | * @can_dlc: the data length field of the CAN frame
58 | * @data: the CAN frame payload.
59 | */
60 | struct can_frame {
61 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
62 | __u8 can_dlc; /* data length code: 0 .. 8 */
63 | __u8 data[8] __attribute__((aligned(8)));
64 | };
65 |
66 | /* particular protocols of the protocol family PF_CAN */
67 | #define CAN_RAW 1 /* RAW sockets */
68 | #define CAN_BCM 2 /* Broadcast Manager */
69 | #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
70 | #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
71 | #define CAN_MCNET 5 /* Bosch MCNet */
72 | #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
73 | #define CAN_NPROTO 7
74 |
75 | #define SOL_CAN_BASE 100
76 |
77 | /**
78 | * struct sockaddr_can - the sockaddr structure for CAN sockets
79 | * @can_family: address family number AF_CAN.
80 | * @can_ifindex: CAN network interface index.
81 | * @can_addr: protocol specific address information
82 | */
83 | struct sockaddr_can {
84 | sa_family_t can_family;
85 | int can_ifindex;
86 | union {
87 | /* transport protocol class address information (e.g. ISOTP) */
88 | struct { canid_t rx_id, tx_id; } tp;
89 |
90 | /* reserved for future CAN protocols address information */
91 | } can_addr;
92 | };
93 |
94 | /**
95 | * struct can_filter - CAN ID based filter in can_register().
96 | * @can_id: relevant bits of CAN ID which are not masked out.
97 | * @can_mask: CAN mask (see description)
98 | *
99 | * Description:
100 | * A filter matches, when
101 | *
102 | * & mask == can_id & mask
103 | *
104 | * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
105 | * filter for error frames (CAN_ERR_FLAG bit set in mask).
106 | */
107 | struct can_filter {
108 | canid_t can_id;
109 | canid_t can_mask;
110 | };
111 |
112 | #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
113 |
114 | #endif /* CAN_H */
115 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/bcm.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can/bcm.h
3 | *
4 | * Definitions for CAN Broadcast Manager (BCM)
5 | *
6 | * $Id$
7 | *
8 | * Author: Oliver Hartkopp
9 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
10 | * All rights reserved.
11 | *
12 | * Send feedback to
13 | *
14 | */
15 |
16 | #ifndef CAN_BCM_H
17 | #define CAN_BCM_H
18 |
19 | /**
20 | * struct bcm_msg_head - head of messages to/from the broadcast manager
21 | * @opcode: opcode, see enum below.
22 | * @flags: special flags, see below.
23 | * @count: number of frames to send before changing interval.
24 | * @ival1: interval for the first @count frames.
25 | * @ival2: interval for the following frames.
26 | * @can_id: CAN ID of frames to be sent or received.
27 | * @nframes: number of frames appended to the message head.
28 | * @frames: array of CAN frames.
29 | */
30 | struct bcm_msg_head {
31 | __u32 opcode;
32 | __u32 flags;
33 | __u32 count;
34 | struct timeval ival1, ival2;
35 | canid_t can_id;
36 | __u32 nframes;
37 | struct can_frame frames[0];
38 | };
39 |
40 | enum {
41 | TX_SETUP = 1, /* create (cyclic) transmission task */
42 | TX_DELETE, /* remove (cyclic) transmission task */
43 | TX_READ, /* read properties of (cyclic) transmission task */
44 | TX_SEND, /* send one CAN frame */
45 | RX_SETUP, /* create RX content filter subscription */
46 | RX_DELETE, /* remove RX content filter subscription */
47 | RX_READ, /* read properties of RX content filter subscription */
48 | TX_STATUS, /* reply to TX_READ request */
49 | TX_EXPIRED, /* notification on performed transmissions (count=0) */
50 | RX_STATUS, /* reply to RX_READ request */
51 | RX_TIMEOUT, /* cyclic message is absent */
52 | RX_CHANGED /* updated CAN frame (detected content change) */
53 | };
54 |
55 | #define SETTIMER 0x0001
56 | #define STARTTIMER 0x0002
57 | #define TX_COUNTEVT 0x0004
58 | #define TX_ANNOUNCE 0x0008
59 | #define TX_CP_CAN_ID 0x0010
60 | #define RX_FILTER_ID 0x0020
61 | #define RX_CHECK_DLC 0x0040
62 | #define RX_NO_AUTOTIMER 0x0080
63 | #define RX_ANNOUNCE_RESUME 0x0100
64 | #define TX_RESET_MULTI_IDX 0x0200
65 | #define RX_RTR_FRAME 0x0400
66 |
67 | #endif /* CAN_BCM_H */
68 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/error.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can/error.h
3 | *
4 | * Definitions of the CAN error frame to be filtered and passed to the user.
5 | *
6 | * $Id$
7 | *
8 | * Author: Oliver Hartkopp
9 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
10 | * All rights reserved.
11 | *
12 | * Send feedback to
13 | *
14 | */
15 |
16 | #ifndef CAN_ERROR_H
17 | #define CAN_ERROR_H
18 |
19 | #define CAN_ERR_DLC 8 /* dlc for error frames */
20 |
21 | /* error class (mask) in can_id */
22 | #define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */
23 | #define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */
24 | #define CAN_ERR_CRTL 0x00000004U /* controller problems / data[1] */
25 | #define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */
26 | #define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */
27 | #define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */
28 | #define CAN_ERR_BUSOFF 0x00000040U /* bus off */
29 | #define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
30 | #define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
31 |
32 | /* arbitration lost in bit ... / data[0] */
33 | #define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
34 | /* else bit number in bitstream */
35 |
36 | /* error status of CAN-controller / data[1] */
37 | #define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */
38 | #define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */
39 | #define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */
40 | #define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */
41 | #define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */
42 | #define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */
43 | #define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */
44 | /* (at least one error counter exceeds */
45 | /* the protocol-defined level of 127) */
46 |
47 | /* error in CAN protocol (type) / data[2] */
48 | #define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */
49 | #define CAN_ERR_PROT_BIT 0x01 /* single bit error */
50 | #define CAN_ERR_PROT_FORM 0x02 /* frame format error */
51 | #define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */
52 | #define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */
53 | #define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */
54 | #define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */
55 | #define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */
56 | #define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */
57 |
58 | /* error in CAN protocol (location) / data[3] */
59 | #define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */
60 | #define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */
61 | #define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */
62 | #define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/
63 | #define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */
64 | #define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */
65 | #define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */
66 | #define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */
67 | #define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */
68 | #define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */
69 | #define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */
70 | #define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */
71 | #define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */
72 | #define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */
73 | #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */
74 | #define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */
75 | #define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */
76 | #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */
77 | #define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */
78 | #define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */
79 |
80 | /* error status of CAN-transceiver / data[4] */
81 | /* CANH CANL */
82 | #define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */
83 | #define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */
84 | #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 /* 0000 0101 */
85 | #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 /* 0000 0110 */
86 | #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 /* 0000 0111 */
87 | #define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */
88 | #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 /* 0101 0000 */
89 | #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 /* 0110 0000 */
90 | #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */
91 | #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */
92 |
93 | /* controller specific additional information / data[5..7] */
94 |
95 | #endif /* CAN_ERROR_H */
96 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/gw.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can/gw.h
3 | *
4 | * Definitions for CAN frame Gateway/Router/Bridge
5 | *
6 | * $Id$
7 | *
8 | * Author: Oliver Hartkopp
9 | * Copyright (c) 2011 Volkswagen Group Electronic Research
10 | * All rights reserved.
11 | *
12 | * Send feedback to
13 | *
14 | */
15 |
16 | #ifndef CAN_GW_H
17 | #define CAN_GW_H
18 |
19 | #include
20 | #include
21 |
22 | struct rtcanmsg {
23 | __u8 can_family;
24 | __u8 gwtype;
25 | __u16 flags;
26 | };
27 |
28 | /* CAN gateway types */
29 | enum {
30 | CGW_TYPE_UNSPEC,
31 | CGW_TYPE_CAN_CAN, /* CAN->CAN routing */
32 | __CGW_TYPE_MAX
33 | };
34 |
35 | #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1)
36 |
37 | /* CAN rtnetlink attribute definitions */
38 | enum {
39 | CGW_UNSPEC,
40 | CGW_MOD_AND, /* CAN frame modification binary AND */
41 | CGW_MOD_OR, /* CAN frame modification binary OR */
42 | CGW_MOD_XOR, /* CAN frame modification binary XOR */
43 | CGW_MOD_SET, /* CAN frame modification set alternate values */
44 | CGW_CS_XOR, /* set data[] XOR checksum into data[index] */
45 | CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */
46 | CGW_HANDLED, /* number of handled CAN frames */
47 | CGW_DROPPED, /* number of dropped CAN frames */
48 | CGW_SRC_IF, /* ifindex of source network interface */
49 | CGW_DST_IF, /* ifindex of destination network interface */
50 | CGW_FILTER, /* specify struct can_filter on source CAN device */
51 | __CGW_MAX
52 | };
53 |
54 | #define CGW_MAX (__CGW_MAX - 1)
55 |
56 | #define CGW_FLAGS_CAN_ECHO 0x01
57 | #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02
58 |
59 | #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */
60 |
61 | /* CAN frame elements that are affected by curr. 3 CAN frame modifications */
62 | #define CGW_MOD_ID 0x01
63 | #define CGW_MOD_DLC 0x02
64 | #define CGW_MOD_DATA 0x04
65 |
66 | #define CGW_FRAME_MODS 3 /* ID DLC DATA */
67 |
68 | #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS)
69 |
70 | struct cgw_frame_mod {
71 | struct can_frame cf;
72 | __u8 modtype;
73 | } __attribute__((packed));
74 |
75 | #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod)
76 |
77 | struct cgw_csum_xor {
78 | __s8 from_idx;
79 | __s8 to_idx;
80 | __s8 result_idx;
81 | __u8 init_xor_val;
82 | } __attribute__((packed));
83 |
84 | struct cgw_csum_crc8 {
85 | __s8 from_idx;
86 | __s8 to_idx;
87 | __s8 result_idx;
88 | __u8 init_crc_val;
89 | __u8 final_xor_val;
90 | __u8 crctab[256];
91 | __u8 profile;
92 | __u8 profile_data[20];
93 | } __attribute__((packed));
94 |
95 | /* length of checksum operation parameters. idx = index in CAN frame data[] */
96 | #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor)
97 | #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8)
98 |
99 | /* CRC8 profiles (compute CRC for additional data elements - see below) */
100 | enum {
101 | CGW_CRC8PRF_UNSPEC,
102 | CGW_CRC8PRF_1U8, /* compute one additional u8 value */
103 | CGW_CRC8PRF_16U8, /* u8 value table indexed by data[1] & 0xF */
104 | CGW_CRC8PRF_SFFID_XOR, /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */
105 | __CGW_CRC8PRF_MAX
106 | };
107 |
108 | #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1)
109 |
110 | /*
111 | * CAN rtnetlink attribute contents in detail
112 | *
113 | * CGW_XXX_IF (length 4 bytes):
114 | * Sets an interface index for source/destination network interfaces.
115 | * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory.
116 | *
117 | * CGW_FILTER (length 8 bytes):
118 | * Sets a CAN receive filter for the gateway job specified by the
119 | * struct can_filter described in include/linux/can.h
120 | *
121 | * CGW_MOD_XXX (length 17 bytes):
122 | * Specifies a modification that's done to a received CAN frame before it is
123 | * send out to the destination interface.
124 | *
125 | * data used as operator
126 | * affected CAN frame elements
127 | *
128 | * CGW_CS_XOR (length 4 bytes):
129 | * Set a simple XOR checksum starting with an initial value into
130 | * data[result-idx] using data[start-idx] .. data[end-idx]
131 | *
132 | * The XOR checksum is calculated like this:
133 | *
134 | * xor = init_xor_val
135 | *
136 | * for (i = from_idx .. to_idx)
137 | * xor ^= can_frame.data[i]
138 | *
139 | * can_frame.data[ result_idx ] = xor
140 | *
141 | * CGW_CS_CRC8 (length 282 bytes):
142 | * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table,
143 | * a given initial value and a defined input data[start-idx] .. data[end-idx].
144 | * Finally the result value is XOR'ed with the final_xor_val.
145 | *
146 | * The CRC8 checksum is calculated like this:
147 | *
148 | * crc = init_crc_val
149 | *
150 | * for (i = from_idx .. to_idx)
151 | * crc = crctab[ crc ^ can_frame.data[i] ]
152 | *
153 | * can_frame.data[ result_idx ] = crc ^ final_xor_val
154 | *
155 | * The calculated CRC may contain additional source data elements that can be
156 | * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs
157 | * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf
158 | * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs)
159 | * that are used depending on counter values inside the CAN frame data[].
160 | * So far only three profiles have been implemented for illustration.
161 | *
162 | * Remark: In general the attribute data is a linear buffer.
163 | * Beware of sending unpacked or aligned structs!
164 | */
165 |
166 | #endif
167 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/ioctl.h:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * socketcan/can/ioctl.h
4 | *
5 | * Definitions for CAN controller setup (work in progress)
6 | *
7 | * $Id$
8 | *
9 | * Send feedback to
10 | *
11 | */
12 |
13 | #ifndef CAN_IOCTL_H
14 | #define CAN_IOCTL_H
15 |
16 | #include
17 |
18 | /*
19 | * CAN bitrate
20 | */
21 | #define CAN_BITRATE_UNCONFIGURED ((__u32) 0xFFFFFFFFU)
22 | #define CAN_BITRATE_UNKNOWN 0
23 | #define CAN_BITRATE_DEFAULT 500000
24 |
25 | /*
26 | * CAN custom bit time
27 | */
28 | enum can_bittimes {
29 | CAN_BITTIME_STD,
30 | CAN_BITTIME_BTR
31 | };
32 |
33 | /* TSEG1 of controllers usually is a sum of synch_seg (always 1),
34 | * prop_seg and phase_seg1, TSEG2 = phase_seg2 */
35 |
36 | struct can_bittime_std {
37 | __u32 brp; /* baud rate prescaler */
38 | __u8 prop_seg; /* from 1 to 8 */
39 | __u8 phase_seg1; /* from 1 to 8 */
40 | __u8 phase_seg2; /* from 1 to 8 */
41 | __u8 sjw:7; /* from 1 to 4 */
42 | __u8 sam:1; /* 1 - enable triple sampling */
43 | };
44 |
45 | struct can_bittime_btr {
46 | __u8 btr0;
47 | __u8 btr1;
48 | };
49 |
50 | struct can_bittime {
51 | enum can_bittimes type;
52 | union {
53 | struct can_bittime_std std;
54 | struct can_bittime_btr btr;
55 | };
56 | };
57 |
58 | /*
59 | * CAN mode
60 | */
61 | enum can_mode {
62 | CAN_MODE_STOP = 0,
63 | CAN_MODE_START,
64 | CAN_MODE_SLEEP
65 | };
66 |
67 | /*
68 | * CAN controller mode
69 | */
70 | #define CAN_CTRLMODE_LOOPBACK 0x1
71 | #define CAN_CTRLMODE_LISTENONLY 0x2
72 |
73 | /*
74 | * CAN operational and error states
75 | */
76 | enum can_state {
77 | CAN_STATE_ACTIVE = 0,
78 | CAN_STATE_BUS_WARNING,
79 | CAN_STATE_BUS_PASSIVE,
80 | CAN_STATE_BUS_OFF,
81 | CAN_STATE_STOPPED,
82 | CAN_STATE_SLEEPING
83 | };
84 |
85 | /*
86 | * CAN device statistics
87 | */
88 | struct can_device_stats {
89 | int error_warning;
90 | int data_overrun;
91 | int wakeup;
92 | int bus_error;
93 | int error_passive;
94 | int arbitration_lost;
95 | int restarts;
96 | int bus_error_at_init;
97 | };
98 |
99 | #endif /* CAN_IOCTL_H */
100 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/isotp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can/isotp.h
3 | *
4 | * Definitions for isotp CAN sockets
5 | *
6 | * $Id$
7 | *
8 | * Author: Oliver Hartkopp
9 | * Copyright (c) 2008 Volkswagen Group Electronic Research
10 | * All rights reserved.
11 | *
12 | * Send feedback to
13 | *
14 | */
15 |
16 | #ifndef CAN_ISOTP_H
17 | #define CAN_ISOTP_H
18 |
19 | #include
20 |
21 | #define SOL_CAN_ISOTP (SOL_CAN_BASE + CAN_ISOTP)
22 |
23 | /* for socket options affecting the socket (not the global system) */
24 |
25 | #define CAN_ISOTP_OPTS 1 /* pass struct can_isotp_options */
26 |
27 | #define CAN_ISOTP_RECV_FC 2 /* pass struct can_isotp_fc_options */
28 |
29 | /* sockopts to force stmin timer values for protocol regression tests */
30 |
31 | #define CAN_ISOTP_TX_STMIN 3 /* pass __u32 value in nano secs */
32 | /* use this time instead of value */
33 | /* provided in FC from the receiver */
34 |
35 | #define CAN_ISOTP_RX_STMIN 4 /* pass __u32 value in nano secs */
36 | /* ignore received CF frames which */
37 | /* timestamps differ less than val */
38 |
39 | struct can_isotp_options {
40 |
41 | __u32 flags; /* set flags for isotp behaviour. */
42 | /* __u32 value : flags see below */
43 |
44 | __u32 frame_txtime; /* frame transmission time (N_As/N_Ar) */
45 | /* __u32 value : time in nano secs */
46 |
47 | __u8 ext_address; /* set address for extended addressing */
48 | /* __u8 value : extended address */
49 |
50 | __u8 txpad_content; /* set content of padding byte (tx) */
51 | /* __u8 value : content on tx path */
52 |
53 | __u8 rxpad_content; /* set content of padding byte (rx) */
54 | /* __u8 value : content on rx path */
55 | };
56 |
57 | struct can_isotp_fc_options {
58 |
59 | __u8 bs; /* blocksize provided in FC frame */
60 | /* __u8 value : blocksize. 0 = off */
61 |
62 | __u8 stmin; /* separation time provided in FC frame */
63 | /* __u8 value : */
64 | /* 0x00 - 0x7F : 0 - 127 ms */
65 | /* 0x80 - 0xF0 : reserved */
66 | /* 0xF1 - 0xF9 : 100 us - 900 us */
67 | /* 0xFA - 0xFF : reserved */
68 |
69 | __u8 wftmax; /* max. number of wait frame transmiss. */
70 | /* __u8 value : 0 = omit FC N_PDU WT */
71 | };
72 |
73 |
74 | /* flags for isotp behaviour */
75 |
76 | #define CAN_ISOTP_LISTEN_MODE 0x001 /* listen only (do not send FC) */
77 | #define CAN_ISOTP_EXTEND_ADDR 0x002 /* enable extended addressing */
78 | #define CAN_ISOTP_TX_PADDING 0x004 /* enable CAN frame padding tx path */
79 | #define CAN_ISOTP_RX_PADDING 0x008 /* enable CAN frame padding rx path */
80 | #define CAN_ISOTP_CHK_PAD_LEN 0x010 /* check received CAN frame padding */
81 | #define CAN_ISOTP_CHK_PAD_DATA 0x020 /* check received CAN frame padding */
82 | #define CAN_ISOTP_HALF_DUPLEX 0x040 /* half duplex error state handling */
83 | #define CAN_ISOTP_FORCE_TXSTMIN 0x080 /* ignore stmin from received FC */
84 | #define CAN_ISOTP_FORCE_RXSTMIN 0x100 /* ignore CFs depending on rx stmin */
85 |
86 |
87 | /* default values */
88 |
89 | #define CAN_ISOTP_DEFAULT_FLAGS 0
90 | #define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00
91 | #define CAN_ISOTP_DEFAULT_RXPAD_CONTENT 0x00
92 | #define CAN_ISOTP_DEFAULT_TXPAD_CONTENT 0x00
93 | #define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0
94 | #define CAN_ISOTP_DEFAULT_RECV_BS 0
95 | #define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00
96 | #define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0
97 |
98 | /*
99 | * Remark on CAN_ISOTP_DEFAULT_RECV_* values:
100 | *
101 | * We can strongly assume, that the Linux Kernel implementation of
102 | * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0.
103 | * But as we like to be able to behave as a commonly available ECU,
104 | * these default settings can be changed via sockopts.
105 | * For that reason the STmin value is intentionally _not_ checked for
106 | * consistency and copied directly into the flow control (FC) frame.
107 | *
108 | */
109 |
110 | #endif
111 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/netlink.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can/netlink.h
3 | *
4 | * Definitions for the CAN netlink interface
5 | *
6 | * $Id: dev.h 939 2009-02-14 14:30:19Z wolf $
7 | *
8 | * Copyright (c) 2009 Wolfgang Grandegger
9 | *
10 | * Send feedback to
11 | *
12 | */
13 |
14 | #ifndef CAN_NETLINK_H
15 | #define CAN_NETLINK_H
16 |
17 | #include
18 |
19 | /*
20 | * CAN bit-timing parameters
21 | *
22 | * For further information, please read chapter "8 BIT TIMING
23 | * REQUIREMENTS" of the "Bosch CAN Specification version 2.0"
24 | * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf.
25 | */
26 | struct can_bittiming {
27 | __u32 bitrate; /* Bit-rate in bits/second */
28 | __u32 sample_point; /* Sample point in one-tenth of a percent */
29 | __u32 tq; /* Time quanta (TQ) in nanoseconds */
30 | __u32 prop_seg; /* Propagation segment in TQs */
31 | __u32 phase_seg1; /* Phase buffer segment 1 in TQs */
32 | __u32 phase_seg2; /* Phase buffer segment 2 in TQs */
33 | __u32 sjw; /* Synchronisation jump width in TQs */
34 | __u32 brp; /* Bit-rate prescaler */
35 | };
36 |
37 | /*
38 | * CAN harware-dependent bit-timing constant
39 | *
40 | * Used for calculating and checking bit-timing parameters
41 | */
42 | struct can_bittiming_const {
43 | char name[16]; /* Name of the CAN controller hardware */
44 | __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */
45 | __u32 tseg1_max;
46 | __u32 tseg2_min; /* Time segement 2 = phase_seg2 */
47 | __u32 tseg2_max;
48 | __u32 sjw_max; /* Synchronisation jump width */
49 | __u32 brp_min; /* Bit-rate prescaler */
50 | __u32 brp_max;
51 | __u32 brp_inc;
52 | };
53 |
54 | /*
55 | * CAN clock parameters
56 | */
57 | struct can_clock {
58 | __u32 freq; /* CAN system clock frequency in Hz */
59 | };
60 |
61 | /*
62 | * CAN operational and error states
63 | */
64 | enum can_state {
65 | CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */
66 | CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */
67 | CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */
68 | CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */
69 | CAN_STATE_STOPPED, /* Device is stopped */
70 | CAN_STATE_SLEEPING, /* Device is sleeping */
71 | CAN_STATE_MAX
72 | };
73 |
74 | /*
75 | * CAN bus error counters
76 | */
77 | struct can_berr_counter {
78 | __u16 txerr;
79 | __u16 rxerr;
80 | };
81 |
82 | /*
83 | * CAN controller mode
84 | */
85 | struct can_ctrlmode {
86 | __u32 mask;
87 | __u32 flags;
88 | };
89 |
90 | #define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */
91 | #define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */
92 | #define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */
93 | #define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */
94 | #define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */
95 |
96 | /*
97 | * CAN device statistics
98 | */
99 | struct can_device_stats {
100 | __u32 bus_error; /* Bus errors */
101 | __u32 error_warning; /* Changes to error warning state */
102 | __u32 error_passive; /* Changes to error passive state */
103 | __u32 bus_off; /* Changes to bus off state */
104 | __u32 arbitration_lost; /* Arbitration lost errors */
105 | __u32 restarts; /* CAN controller re-starts */
106 | };
107 |
108 | /*
109 | * CAN netlink interface
110 | */
111 | enum {
112 | IFLA_CAN_UNSPEC,
113 | IFLA_CAN_BITTIMING,
114 | IFLA_CAN_BITTIMING_CONST,
115 | IFLA_CAN_CLOCK,
116 | IFLA_CAN_STATE,
117 | IFLA_CAN_CTRLMODE,
118 | IFLA_CAN_RESTART_MS,
119 | IFLA_CAN_RESTART,
120 | IFLA_CAN_BERR_COUNTER,
121 | __IFLA_CAN_MAX
122 | };
123 |
124 | #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1)
125 |
126 | #endif /* CAN_NETLINK_H */
127 |
--------------------------------------------------------------------------------
/RasPi/include/socketcan/can/raw.h:
--------------------------------------------------------------------------------
1 | /*
2 | * socketcan/can/raw.h
3 | *
4 | * Definitions for raw CAN sockets
5 | *
6 | * $Id$
7 | *
8 | * Authors: Oliver Hartkopp
9 | * Urs Thuermann
10 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
11 | * All rights reserved.
12 | *
13 | * Send feedback to
14 | *
15 | */
16 |
17 | #ifndef CAN_RAW_H
18 | #define CAN_RAW_H
19 |
20 | #include
21 |
22 | #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
23 |
24 | /* for socket options affecting the socket (not the global system) */
25 |
26 | enum {
27 | CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s) */
28 | CAN_RAW_ERR_FILTER, /* set filter for error frames */
29 | CAN_RAW_LOOPBACK, /* local loopback (default:on) */
30 | CAN_RAW_RECV_OWN_MSGS /* receive my own msgs (default:off) */
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/RasPi/isotprecv.c:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id$
3 | */
4 |
5 | /*
6 | * isotprecv.c
7 | *
8 | * Copyright (c) 2008 Volkswagen Group Electronic Research
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 3. Neither the name of Volkswagen nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * Alternatively, provided that this notice is retained in full, this
24 | * software may be distributed under the terms of the GNU General
25 | * Public License ("GPL") version 2, in which case the provisions of the
26 | * GPL apply INSTEAD OF those given above.
27 | *
28 | * The provided data structures and external interfaces from this code
29 | * are not restricted to be used by modules with a GPL compatible license.
30 | *
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42 | * DAMAGE.
43 | *
44 | * Send feedback to
45 | *
46 | */
47 |
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include
53 |
54 | #include
55 | #include
56 | #include
57 | #include
58 |
59 | #include
60 | #include
61 |
62 | #define NO_CAN_ID 0xFFFFFFFFU
63 |
64 | void print_usage(char *prg)
65 | {
66 | fprintf(stderr, "\nUsage: %s [options] \n", prg);
67 | fprintf(stderr, "Options: -s (source can_id. Use 8 digits for extended IDs)\n");
68 | fprintf(stderr, " -d (destination can_id. Use 8 digits for extended IDs)\n");
69 | fprintf(stderr, " -x (extended addressing mode.)\n");
70 | fprintf(stderr, " -p (set and enable padding byte)\n");
71 | fprintf(stderr, " -P (check padding in SF/CF. (l)ength (c)ontent (a)ll)\n");
72 | fprintf(stderr, " -b (blocksize. 0 = off)\n");
73 | fprintf(stderr, " -m (STmin in ms/ns. See spec.)\n");
74 | fprintf(stderr, " -f