├── .gitignore ├── CONTRIBUTING.md ├── COPYING ├── Doxyfile ├── INSTALL.md ├── Kconfig ├── Makefile ├── README.md ├── doc ├── developer_doc.md ├── images │ ├── CAN Frame.png │ ├── CAN to eth 01.bmp │ ├── CAN to eth 01.graphml │ ├── CAN to eth 02.bmp │ ├── CAN to eth 02.graphml │ ├── CAN to eth 03.bmp │ ├── CAN to eth 03.graphml │ ├── CAN-signal.txt │ ├── CAN-struct.txt │ ├── CAN-to-Ethernet.txt │ ├── CANFD-struct.txt │ ├── CANFD-to-Ethernet.txt │ ├── Diagramm mit Dateinamen.graphml │ ├── Diagramm ohne Dateinamen 02.bmp │ ├── Diagramm ohne Dateinamen CAN - Ethernet Gateway.bmp │ ├── Diagramm ohne Dateinamen CAN - Ethernet Gateway.graphml │ ├── Diagramm ohne Dateinamen Netlink.bmp │ ├── Diagramm ohne Dateinamen Netlink.graphml │ ├── Diagramm ohne Dateinamen virtual Ethernet.bmp │ ├── Diagramm ohne Dateinamen virtual Ethernet.graphml │ ├── Diagramm ohne Dateinamen.bmp │ ├── Diagramm ohne Dateinamen.graphml │ ├── Ethernet-header1.txt │ ├── Ethernet-header2.txt │ ├── Ethernet-header3.txt │ ├── Ethernet-including-CAN-to-CAN.txt │ ├── Ethernet-to-CAN.txt │ ├── Ethernet-to-CANFD.txt │ ├── Relation-Graph.txt │ ├── UML.bmp │ ├── UML.graphml │ ├── can_to_eth │ ├── eth_to_can │ ├── ethernet-frame.gif │ ├── uml.txt │ └── uml_example.txt └── rough_tutorial.md ├── include ├── ce_gw_dev.h ├── ce_gw_main.h └── ce_gw_netlink.h ├── man ├── README.md ├── ce_gw.7 ├── ce_gw.7.jekyii.md ├── ce_gw.7.md ├── ce_gw.7.strict.md ├── ce_gw.markdown ├── html.template ├── jekyii.template ├── markdown.template └── pandoc-convert.sh └── src ├── ce_gw_dev.c ├── ce_gw_main.c └── ce_gw_netlink.c /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #ignore thumbnails created by windows 3 | Thumbs.db 4 | #Ignore files build by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.user 9 | *.aps 10 | *.pch 11 | *.vspscc 12 | *_i.c 13 | *_p.c 14 | *.ncb 15 | *.suo 16 | *.tlb 17 | *.tlh 18 | *.bak 19 | *.cache 20 | *.ilk 21 | *.log 22 | [Bb]in 23 | [Dd]ebug*/ 24 | *.lib 25 | *.sbr 26 | obj/ 27 | [Rr]elease*/ 28 | _ReSharper*/ 29 | [Tt]est[Rr]esult* 30 | 31 | #Ignore Editor Related 32 | *~ 33 | *.orig 34 | 35 | #Ignore General C Binaries 36 | *.ko 37 | *.o 38 | *.mod.c 39 | *.mod.o 40 | *.mod 41 | *.cmd 42 | modules.order 43 | Module.symvers 44 | *.tmp_versions 45 | 46 | #Ignore Special C Binaries 47 | cegwctl 48 | cegwctl_test 49 | cegwsend 50 | 51 | #doxygen 52 | doxygen/ 53 | 54 | #html 55 | *.html 56 | *.htm 57 | 58 | *.tmp 59 | /.project 60 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | We are happy for any contribution, but you have to notice some rules: 5 | 6 | Coding 7 | ------ 8 | 9 | We are strictly following the [Linux Kernel Code Style guide](https://www.kernel.org/doc/Documentation/CodingStyle) `[LINUX-KERNEL-SRC]/Documentation/CodingStyle`. 10 | In general we use [astyle with `--style=linux`](http://astyle.sourceforge.net/astyle.html#_style=linux) option to check and automatically format the source code files accoring to the guide. 11 | 12 | The code must be well commented and according documentation have to be updated. We use [doxygen](https://www.stack.nl/~dimitri/doxygen/manual/docblocks.html#cppblock) for function documentation and as general format. 13 | 14 | Your Contribution 15 | ----------------- 16 | 17 | Every contribution is welcome. And we always searching for keen developers. 18 | 19 | If you show us some improvements to the code you can get write access to the repository so that you can work on yourself. 20 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | Install 2 | ======= 3 | 4 | Requirements: 5 | ------------- 6 | + gcc (>=4.7) 7 | + Kernel (>=3.6) for the necessary LinuxCan code. 8 | + Kernel == 3.8. Due to tree function changes this version of can-eth-gw will only compile at this Kernel version. But it should be modifiable for other verions. 9 | 10 | Installation: 11 | ------------- 12 | Change working dir into the Sources. 13 | 14 | 15 | make 16 | make modules_install 17 | depmod -a 18 | modprobe ce_gw 19 | 20 | 21 | References 22 | ========== 23 | 24 | __Sources:__ 25 | [https://github.com/can-eth-gw/can_eth_gw/](https://github.com/can-eth-gw/can_eth_gw/ "Sources") 26 | __Homepage:__ 27 | [http://can-eth-gw.github.io/](http://can-eth-gw.github.io/ "Homepage") 28 | 29 | __Authors:__ 30 | 31 | + Fabian Raab __ 32 | + Stefan Smarzly __ 33 | -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | menu "CAN - Ethernet Gateway" 2 | 3 | config CE_GW 4 | tristate "Bidirectional CAN - Ethernet Gateway" 5 | depends on CAN && CAN_DEV 6 | default n 7 | ---help--- 8 | A bidirectional CAN to Ethernet Gateway. You can translate the 9 | packages in several ways, like CAN Haeder to Ethernet Header or 10 | CAN Frame to Ethernet Payload or CAN Header to IP/UDP or IP/UDP 11 | Header. The Routes are between an existing linux-can (formerly 12 | SocketCAN) device and an virtual ethernet device, witch creates then 13 | Gateway. 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Makefile - Control Area Network - Ethernet - Gateway (Kernel Module) 3 | ############################################################################# 4 | 5 | ############################################################################# 6 | # (C) Copyright 2013 Fabian Raab, Stefan Smarzly 7 | # 8 | # This file is part of CAN-Eth-GW. 9 | # 10 | # CAN-Eth-GW is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 3 of the License, or 13 | # (at your option) any later version. 14 | #6 15 | # CAN-Eth-GW is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with CAN-Eth-GW. If not, see . 22 | ############################################################################# 23 | 24 | # TODO remove Debugging mode 25 | ccflags-y := -DDEBUG -std=gnu99 -Wno-declaration-after-statement 26 | ccflags-y += -Wno-unused-label -Wno-unused-function 27 | ccflags-y += -I$(PWD)/src -I$(PWD)/include 28 | 29 | SRC := src/ce_gw_main.o 30 | SRC += src/ce_gw_dev.o 31 | SRC += src/ce_gw_netlink.o 32 | OUTPUT := out 33 | 34 | # If KERNELRELEASE is defined, we've been invoked from the 35 | # kernel build system and can use its language. 36 | ifneq ($(KERNELRELEASE),) 37 | obj-${CONFIG_CE_GW} += ${OUTPUT}/ce_gw.o 38 | ${OUTPUT}/ce_gw-objs = $(SRC:.c=.o) 39 | 40 | # Otherwise we were called directly from the command 41 | # line; invoke the kernel build system. 42 | else 43 | #Keep export CONFIG* until the sources moved into the kernel source tree 44 | export CONFIG_CE_GW=m 45 | 46 | KERNELDIR := /lib/modules/$(shell uname -r)/build 47 | # Path to target Linux Kernel 48 | PWD := $(shell pwd) 49 | 50 | modules modules_install clean: 51 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ 52 | 53 | endif 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Readme 2 | ====== 3 | 4 | Use `cegwctl` from the utilities package to control the gateway: 5 | 6 | See a [small tutorial](doc/rough_tutorial.md) in the docs, if you want to try it out. 7 | 8 | References 9 | ========== 10 | 11 | __Sources:__ 12 | [https://github.com/can-eth-gw/can_eth_gw/](https://github.com/can-eth-gw/can_eth_gw/ "Sources") 13 | __Homepage:__ 14 | [http://can-eth-gw.github.io/](http://can-eth-gw.github.io/ "Homepage") 15 | 16 | __Authors:__ 17 | 18 | + Fabian Raab __ 19 | + Stefan Smarzly __ 20 | -------------------------------------------------------------------------------- /doc/images/CAN Frame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/CAN Frame.png -------------------------------------------------------------------------------- /doc/images/CAN to eth 01.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/CAN to eth 01.bmp -------------------------------------------------------------------------------- /doc/images/CAN to eth 01.graphml: -------------------------------------------------------------------------------- 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 | Group 1 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Folder 1 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | payload 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | CAN header 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | Ethernet header 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | payload 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | CAN header 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /doc/images/CAN to eth 02.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/CAN to eth 02.bmp -------------------------------------------------------------------------------- /doc/images/CAN to eth 02.graphml: -------------------------------------------------------------------------------- 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 | Group 2 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Folder 2 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | IP header 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | UDP/TCP header 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | payload 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | Group 1 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | Folder 1 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | IP header 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | UDP/TCP header 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | payload 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | Ethernet header 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | CAN header 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | -------------------------------------------------------------------------------- /doc/images/CAN to eth 03.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/CAN to eth 03.bmp -------------------------------------------------------------------------------- /doc/images/CAN to eth 03.graphml: -------------------------------------------------------------------------------- 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 | Group 6 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Folder 6 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | CAN header 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | payload 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | IP header 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | UDP/TCP header 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Ethernet header 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | CAN header 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | payload 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /doc/images/CAN-signal.txt: -------------------------------------------------------------------------------- 1 | SFF header: 2 | ----------- 3 | 1 1 1 4 | 11 bit bit bit bit 4 bit 5 | +___________+___+___+___+______+___... 6 | | | | | | | Raw 7 | |identifier |RTR|EFF|res| DLC | Data 8 | +___________+___+___+___+______+___... 9 | | | | 10 | |<------------->|<------------>| 11 | Arbitration Control 12 | Field Field 13 | 14 | EFF header: 15 | ----------- 16 | 1 1 1 1 1 17 | 11 bit bit bit 18 bit bit bit bit 4 bit 18 | +___________+___+___+__________________+___+___+___+______+___... 19 | | |sub| | extended | | | | | Raw 20 | |identifier |RTR|EFF| identifier |RTR|res|res| DLC | Data 21 | +___________+___+___+__________________+___+___+___+______+___... 22 | | | | 23 | |<---------------------------------------->|<------------>| 24 | Arbitration Field Control Field 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/images/CAN-struct.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 4 4 2 | 11 bit 18 bit bit bit bit bit bit 3 byte 3 | +___________+__________________+___+___+___+_____+_____+________________+___... 4 | | | extended | | | | DLC | | | Raw 5 | |identifier | identifier |ERR|RTR|EFF| pad | DLC | padding | Data 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 | -------------------------------------------------------------------------------- /doc/images/CAN-to-Ethernet.txt: -------------------------------------------------------------------------------- 1 | mac header 2 | data pointer-->+----------------------+ +----------------------+<--data pointer 3 | | | | | 4 | | CAN header [5 bit] | | MAC (Ethernet) [14 B]| 5 | +----------------------+ +----------------------+<--network 6 | | +----------------+ | | +----------------+ | header 7 | | | | | | | | | 8 | | | payload [8 B] |--+--+->| payload [8 B] | | 9 | | +----------------+ | | +----------------+ | 10 | +----------------------+ +----------------------+<--transport 11 | header 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /doc/images/CANFD-struct.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 2 | 11 bit 18 bit bit bit bit 4 bit 4 bit 8 bit 8 bit 8 bit 3 | +___________+__________________+___+___+___+_____+_____+______+______+______+ 4 | | | Extended | | | | len | | | res0 | res1 | 5 | |identifier | identifier |ERR|RTR|EFF| pad | len |flags | pad | pad | 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 | -------------------------------------------------------------------------------- /doc/images/CANFD-to-Ethernet.txt: -------------------------------------------------------------------------------- 1 | mac header 2 | data pointer-->+______________________+ +______________________+<--data pointer 3 | | | | | 4 | | CAN FD header [8 B] | | MAC (Ethernet) [14 B]| 5 | __+______________________+ +______________________+__ 6 | / | +________________+ | | +________________+<-+--\--network 7 | | | | | | | | | | | header 8 | | | | IP header | | | | IP header | | | 9 | | | +________________+ | | +________________+<-+--+--transport 10 | / | | | | | | | | \ header 11 | [64 B] < | | UDP/TCP header |--+-+->| UDP/TCP header | + > [64 B] 12 | \ | +________________+ | | +________________+ | / 13 | | | | | | | | | | | 14 | | | | payload | | | | payload | | | 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 | -------------------------------------------------------------------------------- /doc/images/Diagramm mit Dateinamen.graphml: -------------------------------------------------------------------------------- 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 | CAN Ethernet Gateway (ce_gw) 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Folder 1 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | OS 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Netlink Client 74 | netlink.c 75 | (can-eth-gw-utils) 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | CAN - Ethernet Gateway 94 | ce_gw_main.c 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | virtual Ethernet dev 113 | ('cegw#' Interface) 114 | ce_gw_dev.c 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | Netlink Server 133 | ce_gw_netlink.c 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | Userspace 160 | 161 | Kernelspace 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | CAN Device 180 | can.c 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | CAN Driver 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | CAN NIC 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | Ethernet Frame 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | CAN Frame 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen 02.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/Diagramm ohne Dateinamen 02.bmp -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen CAN - Ethernet Gateway.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/Diagramm ohne Dateinamen CAN - Ethernet Gateway.bmp -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen CAN - Ethernet Gateway.graphml: -------------------------------------------------------------------------------- 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 | CAN Ethernet Gateway 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Folder 1 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | OS 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Netlink Client 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | CAN - Ethernet Gateway 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | virtual Ethernet dev 111 | ('cegw#' Interface) 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Netlink Server 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | Userspace 156 | 157 | Kernelspace 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | CAN Device 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | CAN Driver 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | CAN NIC 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | Ethernet Frame 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | CAN Frame 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen Netlink.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/Diagramm ohne Dateinamen Netlink.bmp -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen Netlink.graphml: -------------------------------------------------------------------------------- 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 | CAN Ethernet Gateway 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Folder 1 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | OS 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Netlink Client 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | CAN - Ethernet Gateway 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | virtual Ethernet dev 111 | ('cegw#' Interface) 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Netlink Server 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | Userspace 156 | 157 | Kernelspace 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | CAN Device 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | CAN Driver 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | CAN NIC 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | Ethernet Frame 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | CAN Frame 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen virtual Ethernet.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/Diagramm ohne Dateinamen virtual Ethernet.bmp -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen virtual Ethernet.graphml: -------------------------------------------------------------------------------- 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 | CAN Ethernet Gateway 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Folder 1 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | OS 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Netlink Client 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | CAN - Ethernet Gateway 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | virtual Ethernet dev 111 | ('cegw#' Interface) 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Netlink Server 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | Userspace 156 | 157 | Kernelspace 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | CAN Device 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | CAN Driver 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | CAN NIC 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | Ethernet Frame 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | CAN Frame 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/Diagramm ohne Dateinamen.bmp -------------------------------------------------------------------------------- /doc/images/Diagramm ohne Dateinamen.graphml: -------------------------------------------------------------------------------- 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 | CAN Ethernet Gateway 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Folder 1 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | OS 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Netlink Client 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | CAN - Ethernet Gateway 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | virtual Ethernet dev 111 | ('cegw#' Interface) 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Netlink Server 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | Userspace 156 | 157 | Kernelspace 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | CAN Device 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | CAN Driver 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | CAN NIC 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | Ethernet Frame 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | CAN Frame 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | -------------------------------------------------------------------------------- /doc/images/Ethernet-header1.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +____________________+ 9 | | | 10 | | MAC (Ethernet) | 11 | +____________________+ 12 | | +______________+ | +______________+ 13 | | | | | | | 14 | | | CAN header | | | CAN header | 15 | | +______________+<-+------>+______________+ 16 | | | | | | | 17 | | | payload | | | payload | 18 | | +______________+ | +______________+ 19 | +____________________+ 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /doc/images/Ethernet-header2.txt: -------------------------------------------------------------------------------- 1 | 2 | +______________________+ +______________________+ 3 | | | | | 4 | | MAC (Ethernet) | | CAN header | 5 | +______________________+ +______________________+ 6 | | +________________+ | | +________________+ | 7 | | | | | | | | | 8 | | | IP header | | | | IP header | | 9 | | +________________+ | | +________________+ | 10 | | | | | | | | | 11 | | | UDP/TCP header |<-+------+->| UDP/TCP header | | 12 | | +________________+ | | +________________+ | 13 | | | | | | | | | 14 | | | payload | | | | payload | | 15 | | +________________+ | | +________________+ | 16 | +______________________+ +______________________+ 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/images/Ethernet-header3.txt: -------------------------------------------------------------------------------- 1 | +______________________+ 2 | | | 3 | | MAC (Ethernet) | 4 | +______________________+ 5 | | | 6 | | IP header | 7 | +______________________+ 8 | | | 9 | | UDP/TCP header | 10 | +______________________+ 11 | | +________________+ | +________________+ 12 | | | | | | | 13 | | | CAN header | | | CAN header | 14 | | |________________|<-+------>+________________+ 15 | | | | | | | 16 | | | payload | | | payload | 17 | | +________________+ | +________________+ 18 | +______________________+ 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /doc/images/Ethernet-including-CAN-to-CAN.txt: -------------------------------------------------------------------------------- 1 | mac header 2 | data pointer-->+_______________________+ 3 | | | 4 | | MAC (Ethernet) [14 B] | 5 | network-->+_______________________+ 6 | header | +__________________+ | +_________________+<--data pointer 7 | | | CAN/CAN FD header| | |CAN/CAN FD header| 8 | | | [5 B/8 B] | | | [5 B/8 B] | 9 | | +__________________+<-+-->+_________________+ 10 | | | payload | | | payload | 11 | | | [8 B/64 B] | | | [8 B/64 B] | 12 | | +__________________+ | +_________________+ 13 | transport-->+_______________________+ 14 | header 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/images/Ethernet-to-CAN.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | mac header mac header 7 | data pointer-->+----------------------+ +----------------------+<--data pointer 8 | | | | | 9 | | MAC (Ethernet) [14 B]| | CAN header [5 bit] | 10 | network-->+----------------------+ +----------------------+<--network 11 | header | +----------------+ | | +----------------+ | header 12 | | | | | | | | | 13 | | | payload [8 B] |--+--+->| payload [8 B] | | 14 | | +----------------+ | | +----------------+ | 15 | transport-->+----------------------+ +----------------------+<--transport 16 | header header 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 | -------------------------------------------------------------------------------- /doc/images/Ethernet-to-CANFD.txt: -------------------------------------------------------------------------------- 1 | 2 | mac header mac header 3 | data pointer-->+______________________+ +______________________+<--data pointer 4 | | | | | 5 | | MAC (Ethernet) [14 B]| | CAN FD header [8 B] | 6 | __+______________________+ +______________________+__ 7 | network--/--+->+________________+ | | +________________+<-+--\--network 8 | header | | | | | | | | | | header 9 | | | | IP header | | | | IP header | | | 10 | transport--+--+->+________________+ | | +________________+<-+--+--transport 11 | header / | | | | | | | | \ header 12 | [64 B] < | | UDP/TCP header |--+-+->| UDP/TCP header | | > [64 B] 13 | \ | +________________+ | | +________________+ | / 14 | | | | | | | | | | | 15 | | | | payload | | | | payload | | | 16 | | | +________________+ | | +________________+ | | 17 | \__+______________________+ +______________________+__/ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/images/Relation-Graph.txt: -------------------------------------------------------------------------------- 1 | _______________________________________________________ 2 | | | 3 | | CAN Ethernet Gateway Kernel Module (ce_gw) | 4 | |_______________________________________________________| 5 | | | 6 | | Ethernet Frame +----------------------+ | CAN Frame 7 | | +-----o---------->|CAN - Ethernet Gateway|<-+-------o----+ 8 | | | | ce_gw_main.c | | | 9 | | | +----------------------+ | v 10 | | v | +----------+ 11 | | +--------------------+ | |CAN Device| 12 | | |virtual Ethernet dev| | | can.c | 13 | | |('cegw#' Interface) | +---------------+ | +----------+ 14 | | | ce_gw_dev.c | |Netlink Server | | ^ 15 | | +--------------------+ |ce_gw_netlink.c| | | 16 | | ^ +---------------+ | v 17 | | | ^ | +----------+ 18 | |___________|____________________________|______________| |CAN Driver| 19 | | o Netlink Frame +----------+ 20 | v Kernelspace | ^ 21 | +----+ __________________|_____________ | 22 | | OS | Userspace | v 23 | +----+ v +-------+ 24 | +------------------+ |CAN NIC| 25 | | Netlink Client | +-------+ 26 | | netlink.c | 27 | |(can-eth-gw-utils)| 28 | +------------------+ 29 | 30 | Diagramm which shows the relation and packet transmission between 31 | the components of this kernel module (ce_gw) and others of the OS. 32 | -------------------------------------------------------------------------------- /doc/images/UML.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/UML.bmp -------------------------------------------------------------------------------- /doc/images/can_to_eth: -------------------------------------------------------------------------------- 1 | /* 2 | * @fn struct sk_buff *ce_gw_can_to_eth(unsigned char dest, unsigned char 3 | * source, __be16 type, struct sk_buff *can_buffer) 4 | * @brief converts sk_buffer including can_frame into sk_buffer including 5 | * ethernet_frame 6 | * @param dest MAC address of destination 7 | * @param source MAC address of source 8 | * @param type type of layer3 message (example: ipv4 or ipv6 ...) 9 | * @param can_buffer sk_buffer including a can_frame 10 | */ 11 | struct sk_buff *ce_gw_can_to_eth(unsigned char dest, unsigned char source, 12 | __be16 type, struct sk_buff *can_buffer) 13 | { 14 | struct sk_buff *eth_skb = 0; 15 | struct ethhdr *ethhdr; 16 | u32 *crc_ethhdr; 17 | struct can_frame *can_frame_skb = (struct can_frame *) can_buffer-> 18 | mac_header; 19 | const unsigned char *data_skb = (const unsigned char *) eth_skb-> 20 | mac_header; 21 | 22 | eth_skb = dev_alloc_skb(130); /*64 byte data from CAN + 14 byte 23 | ethernet header +4 byte CRC = 82 */ 24 | 25 | /*fills new_eth_hdr with data */ 26 | ethhdr = eth_hdr(eth_skb); 27 | memcpy(ethhdr->h_dest, &dest, ETH_ALEN); 28 | memcpy(ethhdr->h_source, &source, ETH_ALEN); 29 | ethhdr->h_proto = type; 30 | 31 | memcpy(eth_skb->data, can_buffer->network_header, can_frame_skb-> 32 | can_dlc); /* don't know if nh points to beginning of data field 33 | after can header*/ 34 | crc_ethhdr = (u32 *) crc32_le (~0, data_skb, eth_skb->tail - eth_skb-> 35 | mac_header); /* don't know if eth_sk_buff_mac is the right 36 | pointer */ 37 | memcpy(eth_skb->data, crc_ethhdr, 4); 38 | 39 | return eth_skb; 40 | } 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /doc/images/eth_to_can: -------------------------------------------------------------------------------- 1 | /* TODO: implement CRC for CAN ! */ 2 | 3 | /** 4 | * @fn struct sk_buff *ce_gw_eth_to_can(canid_t, id, struct sk_buff *eth_buff) 5 | * @brief converst sk_buffer including an ethernet frame to sk_buffer 6 | * including a can_frame 7 | * @param id identifier of can_frame (see ce_gw_get_header for more information 8 | * @param eth_buffer sk_buffer including an ethernet frame 9 | * @return sk_buffer including a can frame 10 | */ 11 | struct sk_buff *ce_gw_eth_to_can(canid_t id, struct sk_buff *eth_buff) 12 | { 13 | struct sk_buff *can_buff; 14 | struct can_frame *can = 0; 15 | 16 | can->can_id = id; 17 | can->can_dlc = (__u8) eth_buff->data_len - 18; 18 | 19 | can_buff = dev_alloc_skb(130); 20 | 21 | memcpy(can_buff->mac_header, &can->can_id, 40); 22 | can_buff->network_header = can_buff->data; 23 | memcpy(can_buff->data, eth_buff->network_header, can->can_dlc); 24 | can_buff->transport_header = (__u8 *) can_buff->network_header + 25 | ip_hdrlen(can_buff); 26 | /*crc irgendwie berechnen??? */ 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /doc/images/ethernet-frame.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/can-eth-gw/can_eth_gw/6a5fbd59cf83b3f5998070a0247e93099f6c55c3/doc/images/ethernet-frame.gif -------------------------------------------------------------------------------- /doc/images/uml.txt: -------------------------------------------------------------------------------- 1 | +------------------+ /--------------------------------------\ 2 | | <> | |ce_gw_job has ethernet as dst and CAN | 3 | |struct net_device | |as source OR has ethernet as src and | 4 | +------------------+ |CAN as dst. hlist_node annotations are| 5 | +-->| .... | |members of the structs where the arrow| 6 | | +------------------+ |points to. The hlist structs are not | 7 | | | |directly represented here and have | 8 | | |void *priv |been simplyfied. | 9 | | | \--------------------------------------/ 10 | | v 11 | | +---------------------+ struct hlist_head ce_gw_job_list 12 | | |struct ce_gw_job_info| | 13 | | +---------------------+ | 14 | | | | struct hlist_node | 15 | | +---------------------+ list \ | 16 | | | | struct \| 17 | | struct | |hlist_head | +------------------+ 18 | | hlist_head| | job_src | | <> | 19 | | job_dst | | | |struct net_device | 20 | | | |\ | +------------------+ 21 | | | | struct hlist_node | | .... | 22 | | | |/ list_dev | +------------------+ 23 | | | / | ^ 24 | | |/| |0...* | 25 | | struct | | 0...* v | struct 26 | |net_device | +--------->+----------------------+ |net_device 27 | | *dev +----------->| struct ce_gw_job | | *dev 28 | | 0...* +----------------------+ | 29 | | +-------------+ |struct rcu_head rcu | +-------------+ 30 | | | union | |u32 id | | union | 31 | +--------+-------------+ |enum ce_gw_type type | +-------------+ 32 | | |<>-----|u32 flags |----<>| | 33 | +-------------+ dst/ |u32 handled_frames | src/ +-------------+ 34 | src |u32 dropped_frames | dst 35 | |union { struct can_ | 36 | |filter can_rcv_filter}| 37 | +----------------------+ 38 | 39 | This is an UML class diagramm which shows the main routing management lists. 40 | -------------------------------------------------------------------------------- /doc/images/uml_example.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | +------------------- -+ /----------------------------------------\ 4 | | <> | |Example for exactly one instance of a | 5 | |__struct net_device__| |can net_device, one ethernet can_device | 6 | +---------------------+ |and one gateway route job with ethernet | 7 | +-->| .... | |as destination and can as source device.| 8 | | +---------------------+ \----------------------------------------/ 9 | | | 10 | | |void *priv 11 | | | 12 | | v 13 | | +-------------------------+ __struct hlist_head ce_gw_job_list__ 14 | | |__struct ce_gw_job_info__| | 15 | | +-------------------------+ | 16 | | | | struct hlist_node | 17 | | +-------------------------+ list \ | 18 | | | | struct \| 19 | | struct | |hlist_head | +---------------------+ 20 | | hlist_head| | job_src | | <> | 21 | | job_dst | | | |__struct net_device__| 22 | | | |\ | +---------------------+ 23 | | | | struct hlist_node | | .... | 24 | | | |/ list_dev | +---------------------+ 25 | | | / | ^ 26 | | |/| |1 | 27 | | struct | | 0 v |struct 28 | | net_device | +--------->+----------------------+ |net_device 29 | | *dev +----------->|__struct ce_gw_job__ | |*dev 30 | | 1 +----------------------+ | 31 | | +-------------+ |struct rcu_head rcu | +-------------+ 32 | | | __union__ | |u32 id | | __union__ | 33 | +--------+-------------+ |enum ce_gw_type type | +-------------+ 34 | | |<>-----|u32 flags |----<>| | 35 | +-------------+ dst |u32 handled_frames | src +-------------+ 36 | |u32 dropped_frames | 37 | |union { struct can_ | 38 | |filter can_rcv_filter}| 39 | +----------------------+ 40 | -------------------------------------------------------------------------------- /doc/rough_tutorial.md: -------------------------------------------------------------------------------- 1 | Rough Tutorial 2 | ============== 3 | 4 | This document is just a rough tutorial if you just want to try ca-eth-gw out and see it working. Only virtual devices are used, so there is no need for a real CAN device. 5 | 6 | This tutorial was done on Linux Kernel 3.8.0 . It is not sure if it works on other kernels too. See `INSTALL.md` for more general details. 7 | 8 | You need the kernel module itself `can_eth_gw` and the two userspace tools `cegwctl` and `cegwsend`. Look at the according `INSTALL.md` for how to set up them. 9 | 10 | Lets start with loading the required kernel modules: 11 | 12 | modprobe -vv can 13 | modprobe -vv can-bcm 14 | modprobe -vv can-dev 15 | modprobe -vv can-gw 16 | modprobe -vv can-raw 17 | modprobe -vv vcan 18 | 19 | ad of course also our own module: 20 | 21 | modprobe -vv ce_gw 22 | 23 | Then set up a virtual can device and an appropiate etehrnet gateway: 24 | 25 | ip link add dev vcan0 type vcan 26 | ip link set up vcan0 27 | 28 | cegwctl add dev 29 | ip addr add 192.168.145.2/24 brd 192.168.145.255 dev cegw0 30 | ip link set up dev cegw0 31 | 32 | Now you should see a virtual can device `vcan0` and a gatewayed ethernet device `cegw0`, both with state `UNKNOWN` with the command `ip addr`: 33 | 34 | $ ip addr 35 | 6: vcan0: mtu 16 qdisc noqueue state UNKNOWN 36 | link/can 37 | 7: cegw0: mtu 16 qdisc pfifo_fast state UNKNOWN qlen 1000 38 | link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 39 | inet 192.168.145.2/24 brd 192.168.145.255 scope global cegw0 40 | 41 | Now add a bidirectional route between `vcan0` and `cegw0`: 42 | 43 | cegwctl add route --type=net vcan0 cegw0 44 | cegwctl add route --type=net cegw0 vcan0 45 | 46 | The command `cegwctl route` should now show you the routes_ 47 | 48 | $ cegwctl route 49 | ID SRC DST TYPE HANDLED DROPPED FLAGS 50 | 2 cegw0 vcan0 NET 0 0 <> 51 | 1 vcan0 cegw0 NET 0 0 <> 52 | 53 | Now you need two terminals; one for sending data and one for capturing. 54 | 55 | Start capturing on the `cegw0` device. `tshark` ist the command line version of *wireshark*, but of course you can also use wireshark directly: 56 | *terminal1:* 57 | 58 | tshark -i cegw0 -S -x 59 | 60 | Now send some random data on the virtial can device: 61 | *terminal2:* 62 | 63 | cangen vcan0 64 | 65 | You should now see on the capturing terminal the translated ethernet packages: 66 | *terminal1:* 67 | 68 | Capturing on cegw0 69 | 0.000000 00:00:00_00:00:00 -> Broadcast LLC 30 I, N(R)=0, N(S)=0; DSAP 0xce Group, SSAP NULL LSAP Response 70 | 71 | 0000 ff ff ff ff ff ff 00 00 00 00 00 00 00 0c cf 01 ................ 72 | 0010 00 00 08 00 00 00 f3 1c df 72 06 ca 88 34 .........r...4 73 | 74 | Lets try vice-versa: Stop the other commans with `^c` and start capturing the virtual can device: 75 | 76 | *terminal1:* 77 | 78 | candump vcan0 79 | 80 | Now send a raw ethernet package with an can header as payload on the `cegw0` device: 81 | 82 | *terminal2:* 83 | 84 | cegwsend -d ff-ff-ff-ff-ff-ff -t can -r 435f -i cegw0 85 | 86 | On the capturing terminal you should see that some data is arriving: 87 | *terminal1:* 88 | 89 | vcan0 000 [1] 5F 90 | 91 | Congratulations, you have now successfully translated a can packet to a ethernet packet in both directions. 92 | -------------------------------------------------------------------------------- /include/ce_gw_dev.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ce_gw_dev.h 3 | * @brief Control Area Network - Ethernet - Gateway - Device Header 4 | * @author Fabian Raab (fabian.raab@tum.de) 5 | * @date May, 2013 6 | * @copyright GNU Public License v3 or higher 7 | * @ingroup files 8 | * @{ 9 | */ 10 | 11 | /***************************************************************************** 12 | * (C) Copyright 2013 Fabian Raab, Stefan Smarzly 13 | * 14 | * This file is part of CAN-Eth-GW. 15 | * 16 | * CAN-Eth-GW is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * CAN-Eth-GW is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with CAN-Eth-GW. If not, see . 28 | *****************************************************************************/ 29 | 30 | #ifndef __CE_GW_DEV_H__ 31 | #define __CE_GW_DEV_H__ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) 40 | # include 41 | # else 42 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) 43 | # include 44 | # else 45 | # error Only Linux Kernel 3.6 and above are supported 46 | # endif 47 | #endif 48 | #include "ce_gw_main.h" 49 | 50 | enum ce_gw_type; 51 | struct ce_gw_job; 52 | 53 | /** 54 | * @struct ce_gw_job_info 55 | * @brief The private Field of ether struct net_device with pointer to its job. 56 | * @details The private Field of ethernet net_device. struct hlist_head job_src; 57 | * and struct hlist_head job_dst; are Lists with struct ce_gw_job as 58 | * as its elements. They Point to to the struct ce_gw_job where the 59 | * dev is part of it. So there exist a Pointer from the 60 | * struct ce_gw_job to the net_device and from struct ce_gw_job_info 61 | * back to the same struct ce_gw_job. 62 | */ 63 | struct ce_gw_job_info { 64 | struct hlist_head job_src; /**< List where the dev is the src in job */ 65 | struct hlist_head job_dst; /**< List where the dev is the dst in job */ 66 | }; 67 | 68 | /** 69 | * @fn int ce_gw_is_allocated_dev(struct net_device *eth_dev) 70 | * @brief check if the param eth_dev is allocated by this module 71 | * @param eth_dev the device wich should be checked 72 | * @retval 0 param eth_dev was allocated by this module 73 | * @retval -ENODEV param eth_dev was NOT allocated by this module 74 | * @retval others error occured 75 | * @see ce_gw_is_registered_dev() should you normally use 76 | * @ingroup dev 77 | */ 78 | extern int ce_gw_is_allocated_dev(struct net_device *eth_dev); 79 | 80 | /** 81 | * @fn int ce_gw_is_registered_dev(struct net_device *eth_dev) 82 | * @brief check if the param eth_dev is registered by this module 83 | * @param eth_dev the device wich should be checked 84 | * @retval 0 param eth_dev was registered by this module 85 | * @retval -ENODEV param eth_dev was NOT registered by this module 86 | * @retval others error occured 87 | * @ingroup dev 88 | */ 89 | extern int ce_gw_is_registered_dev(struct net_device *eth_dev); 90 | 91 | /** 92 | * @fn int ce_gw_has_min_mtu(struct net_device *dev, enum ce_gw_type type, 93 | * u32 flags) 94 | * @brief checks if the given device has enough mtu to use the type and flags 95 | * @param dev The net_device which schould be checked 96 | * @param type The type which sould be compared to 97 | * @param flags needed dor the #CE_GW_F_CAN_FD flag, to check if the type is 98 | * CANfd capable 99 | * @retval true The mtu of dev is bigger then the nedded mtu by the type 100 | * @retval false if not 101 | */ 102 | int ce_gw_has_min_mtu(struct net_device *dev, enum ce_gw_type type, u32 flags); 103 | 104 | /** 105 | * @fn void ce_gw_dev_job_src_add(struct ce_gw_job *job) 106 | * @brief Adds an pointer to the net_device internal list where it is the src. 107 | * @details The Function will add a Pointer to the list in the net_device 108 | * private field back to the param job. The pointer in union src.dev in 109 | * the param job be set to the param eth_dev. 110 | * @pre union src.dev in param job must already point to the ethernet device. 111 | * @param job The struct ce_gw_job where union src will points to the param 112 | * eth_dev. A Pointer to this param will be added. 113 | * @ingroup dev 114 | */ 115 | void ce_gw_dev_job_src_add(struct ce_gw_job *job); 116 | 117 | /** 118 | * @fn void ce_gw_dev_job_dst_add(struct ce_gw_job *job) 119 | * @brief Adds an pointer to the net_device internal list where it is the dst. 120 | * @details The Function will add a Pointer to the list in the net_device 121 | * private field back to the param job. The pointer in union dst.dev in 122 | * the param job be set to the param eth_dev. 123 | * @pre union dst.dev in param job must already point to the ethernet device. 124 | * @param job The struct ce_gw_job where union dst will points to the param 125 | * eth_dev. A Pointer to this param will be added. 126 | * @ingroup dev 127 | */ 128 | extern void ce_gw_dev_job_dst_add(struct ce_gw_job *job); 129 | 130 | /** 131 | * @fn void ce_gw_dev_job_add(struct net_device *eth_dev, 132 | * struct ce_gw_job *job) 133 | * @brief Adds an pointer to the net_device internal list where it is part of. 134 | * @details The Function will add a Pointer to the list in the net_device 135 | * private field back to the param job. There must be a pointer 136 | * in union src or union dst in the param job to the 137 | * struct net_device *eth_dev. 138 | * @pre union src.dev or union dst.dev in param job must already point to 139 | * the param eth_dev. 140 | * @param eth_dev The ethernet struct net_device witch is pointed from 141 | * union src or union dst in param job. 142 | * @param job The struct ce_gw_job where union src or union dst points to the 143 | * param eth_dev. A Pointer to this param will be added. 144 | * @retval 0 success 145 | * @retval <0 failure 146 | * @ingroup dev 147 | */ 148 | extern int ce_gw_dev_job_add(struct net_device *eth_dev, struct ce_gw_job *job); 149 | 150 | /** 151 | * @fn void ce_gw_dev_job_remove(struct ce_gw_job *job) 152 | * @brief Removes the pointer to param job from the list in ethernet net_device. 153 | * @details The private field of the ethernet struct net_device contains a 154 | * a pointer to the param job. The Function will remove this Pointer 155 | * from the list. 156 | * @param job The struct ce_gw_job where union src or union dst points to the 157 | * param eth_dev. A Pointer to this param will be removed. 158 | * @warning You must remove the pointer from union src and accordingly union dst 159 | * in param job to the ethernet struct net_device yourself. Until you 160 | * do this our pointer architecture is inconsistent. 161 | * @ingroup dev 162 | */ 163 | 164 | extern void ce_gw_dev_job_remove(struct ce_gw_job *job); 165 | 166 | /** 167 | * @fn struct net_device *ce_gw_dev_alloc(void) 168 | * @brief Allocates a Ethernet Device for the Gateway. 169 | * @param dev_name the name of the new allocated device 170 | * @details Allocates a Ethernet Device with struct ce_gw_job_info as private 171 | * data. ce_gw_dev_setup() should be called after this function. 172 | * ce_gw_dev_free() musst be called for freeing the memory. 173 | * @retval NULL If an error has occured. 174 | * @return A pointer to the allocated device. 175 | * @ingroup dev 176 | */ 177 | extern struct net_device *ce_gw_dev_alloc(char *dev_name); 178 | 179 | /** 180 | * @fn void ce_gw_dev_free(struct net_device *eth_dev) 181 | * @brief Free virtual ethernet device and remove from internal lists 182 | * @pre ce_gw_dev_unregister() was already called 183 | * @param eth_dev the virtual ethernet device allocated by ce_gw_dev_alloc() 184 | * @ingroup dev 185 | */ 186 | extern void ce_gw_dev_free(struct net_device *eth_dev); 187 | 188 | /** 189 | * @fn void ce_gw_dev_setup(struct net_device *dev, enum ce_gw_type type, 190 | * __u32 flags) 191 | * @brief Sets the default attributes for the Gateway Ethernet device. 192 | * @param type Type of the Gateway wich will be linked to the device. A 193 | * sensible MTU will be set. Use CE_GW_TYPE_NONE for default ethernet MTU. 194 | * @param flags If CE_GW_F_CAN_FD Flag is set the MTU will be set to the 195 | * CAN-FD size else to the normal CAN size. 196 | * @param dev the ethernet device which should be set up 197 | * @details Sets the default attributes for the Gateway Ethernet device. Also 198 | * links the net_device operations to the net_dev structure. 199 | * ce_gw_dev_register() should be called afterwards for registering, 200 | * ce_gw_dev_unregister() for unregistering at the end. 201 | * @ingroup dev 202 | */ 203 | extern void ce_gw_dev_setup(struct net_device *dev, enum ce_gw_type type, 204 | __u32 flags); 205 | 206 | /** 207 | * @fn struct net_device *ce_gw_dev_create(enum ce_gw_type type, __u32 flags) 208 | * @brief Allocate the device and set standart Attributes with ce_gw_dev_setup() 209 | * @param type Type of the Gateway wich will be linked to the device. A 210 | * sensible MTU will be set. Use CE_GW_TYPE_NONE for default ethernet MTU. 211 | * @param flags If CE_GW_F_CAN_FD Flag is set the MTU will be set to the 212 | * CAN-FD size else to the normal CAN size. 213 | * @param dev_name the name of the new allocated device 214 | * @return A pointer to the allocated and configured device. 215 | * @ingroup dev 216 | */ 217 | extern struct net_device *ce_gw_dev_create(enum ce_gw_type type, __u32 flags, 218 | char *dev_name); 219 | 220 | /** 221 | * @fn int ce_gw_dev_register(struct net_device *eth_dev) 222 | * @brief Register a virtual ethernet device on the OS 223 | * @param eth_dev the virtual ethernet device 224 | * @pre param eth_dev was previously allocated by ce_gw_dev_alloc() 225 | * @retval 0 on success 226 | * @retval <0 on failure 227 | * @ingroup dev 228 | */ 229 | extern int ce_gw_dev_register(struct net_device *eth_dev); 230 | 231 | /** 232 | * @fn void ce_gw_dev_unregister(struct net_device *eth_dev) 233 | * @brief Unregister virtual ethernet device and remove from internal lists 234 | * @param eth_dev the virtual ethernet device 235 | * @pre param eth_dev was previously registered by ce_gw_dev_register() 236 | * @ingroup dev 237 | */ 238 | extern void ce_gw_dev_unregister(struct net_device *eth_dev); 239 | 240 | /** 241 | * @fn int ce_gw_dev_init_module(void) 242 | * @brief Initialise all objects, wich are needed by the other functions 243 | * @post the other functions of the file could only be used after this 244 | * function was called 245 | * @retval 0 on success 246 | * @retval <0 on failure 247 | * @ingroup dev 248 | */ 249 | int ce_gw_dev_init_module(void); 250 | 251 | /** 252 | * @fn void ce_gw_dev_cleanup(void) 253 | * @brief Deleting all objects created by ce_gw_dev_init_module() and all 254 | * devices 255 | * @post after this function is called the other functions could not be used 256 | * any more 257 | * @ingroup dev 258 | */ 259 | extern void ce_gw_dev_cleanup(void); 260 | 261 | #endif 262 | 263 | /**@}*/ 264 | -------------------------------------------------------------------------------- /include/ce_gw_main.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ce_gw_main.h 3 | * @brief Control Area Network - Ethernet - Gateway - Haeder 4 | * @author Stefan Smarzly (stefan.smarzly@in.tum.de) 5 | * @date May, 2013 6 | * @copyright GNU Public License v3 or higher 7 | * @ingroup files 8 | * @{ 9 | */ 10 | 11 | /***************************************************************************** 12 | * (C) Copyright 2013 Fabian Raab, Stefan Smarzly 13 | * 14 | * This file is part of CAN-Eth-GW. 15 | * 16 | * CAN-Eth-GW is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * CAN-Eth-GW is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with CAN-Eth-GW. If not, see . 28 | *****************************************************************************/ 29 | 30 | #ifndef __CE_GW_MAIN_H__ 31 | #define __CE_GW_MAIN_H__ 32 | 33 | #include 34 | #include 35 | #include 36 | #include /* ce_gw_job */ 37 | #include /* sk_buff for receive */ 38 | #include "ce_gw_dev.h" 39 | #include "ce_gw_netlink.h" 40 | #include /* since kernel 3.7 in uapi/linux/ */ 41 | #include /* Net_device types */ 42 | #include /* for can_rx_register and can_send */ 43 | #include 44 | #include /* for using kmalloc/kfree */ 45 | #include 46 | #include 47 | 48 | /** ce_gw_job.flags: is Gateway CANfd compatible */ 49 | #define CE_GW_F_CAN_FD 0x00000001 50 | 51 | /** 52 | * @enum ce_gw_type 53 | * @brief Type of the Gateway 54 | */ 55 | enum ce_gw_type { 56 | CE_GW_TYPE_NONE,/**< No Type. Should normally not be used. */ 57 | CE_GW_TYPE_ETH, /**< Convert CAN header to Ethernet header 58 | * Payload of CAN header must contain an IP header */ 59 | CE_GW_TYPE_NET, /**< Copy complete CAN Frame into Ethernet payload 60 | * e.g use CAN as Network Layer (Layer 3) protocol. */ 61 | CE_GW_TYPE_TCP, /**< Convert CAN header into an IP/TCP package */ 62 | CE_GW_TYPE_UDP, /**< Convert CAN header into an IP/UDP package */ 63 | __CE_GW_TYPE_MAX, /**< Maximum Type Number + 1 */ 64 | }; 65 | #define CE_GW_TYPE_MAX (__CE_GW_TYPE_MAX - 1) /**< Maximum Type Number */ 66 | 67 | /** 68 | * @struct ce_jw_job 69 | * @brief Mapping and statistics for CAN <-> ETH gateway jobs 70 | * (Based on can/gw.c, rev 20101209) 71 | */ 72 | struct ce_gw_job { 73 | struct hlist_node list; /**< List entry for ce_gw_job_list main list */ 74 | struct rcu_head rcu; /**< Lock monitor */ 75 | struct hlist_node list_dev; /**< List entry from the ETH device */ 76 | u32 id; /**< Unique Identifier of Gateway */ 77 | enum ce_gw_type type; /**< Translation type of the Gateway */ 78 | u32 flags; /**< Flags with settings of the Gateway */ 79 | u32 handled_frames; /**< counter for handles frames */ 80 | u32 dropped_frames; /**< counter for dropped_frames */ 81 | 82 | union { 83 | struct net_device *dev; 84 | } src; /**< CAN / ETH frame data source */ 85 | union { 86 | struct net_device *dev; 87 | } dst; /**< CAN / ETH frame data destination */ 88 | union { 89 | struct can_filter can_rcv_filter; 90 | /* TODO: Add ethernet receive filter (eth_rcv_filter) */ 91 | }; /**< Filter incoming packet */ 92 | }; 93 | 94 | /** 95 | * @fn struct hlist_head *ce_gw_get_job_list(void); 96 | * @brief getter for HLIST_HEAD(ce_gw_job_list) 97 | * @returns Pointer to ce_gw_job_list. 98 | */ 99 | struct hlist_head *ce_gw_get_job_list(void); 100 | 101 | /** 102 | * @fn struct can_frame *ce_gw_alloc_can_frame(void) 103 | * @brief allocates memory for the can frame 104 | * @return pointer to the memory allocated 105 | * @ingroup alloc 106 | * @todo not tested yet 107 | */ 108 | extern struct can_frame *ce_gw_alloc_can_frame(void); 109 | 110 | /** 111 | * @fn void ce_gw_free_can_frame(struct can_frame *memory) 112 | * @brief frees memory allocated for can_frame 113 | * @param memory can frame that should be freed 114 | * @ingroup alloc 115 | * @todo not tested yet 116 | */ 117 | extern void ce_gw_free_can_frame(struct can_frame *memory); 118 | 119 | /** 120 | * @fn struct canfd_frame *ce_gw_alloc_canfd_frame(void) 121 | * @brief allocates memory for a canfd frame 122 | * @return pointer to the memory allocated 123 | * @ingroup alloc 124 | * @todo not tested yet 125 | */ 126 | extern struct canfd_frame *ce_gw_alloc_canfd_frame(void); 127 | 128 | /** 129 | * @fn void ce_gw_free_canfd_frame(struct canfd_frame *memory) 130 | * @brief frees memory allocated for can_frame 131 | * @param memory canfd_frame that should be freed 132 | * @ingroup alloc 133 | * @todo not tested yet 134 | */ 135 | extern void ce_gw_free_canfd_frame(struct canfd_frame *memory); 136 | 137 | /** 138 | * @fn struct can_frame *ce_gw_get_header_can(canid_t can_id, __u8 can_dlc, 139 | * __u8 *payload) 140 | * @brief builds a can header in SFF (standart frame format) or EFF 141 | * (extended frame formate) with the given information 142 | * @param can_id_t identifier (11/29 bits) + error flag (0=data, 1= error) + 143 | * remote transmission flag (1=rtr frame) + frame format flag (0=SFF, 1=EFF) 144 | * @param can_dlc data length code 145 | * @param payload data (maximum 64 bit in an 8*8 array) 146 | * @see include/linux/can.h 147 | * @retval can frame if successful 148 | * @retval NULL if unsuccessful 149 | * @todo not tested yet 150 | * @ingroup get 151 | */ 152 | extern struct can_frame *ce_gw_get_header_can(canid_t can_id, __u8 can_dlc, 153 | __u8 *payload); 154 | 155 | /** 156 | * @fn struct canfd_frame *ce_gw_get_header_canfd(canid_t id, __u8 len, __u8 157 | * flags, __u8 res0, __u8 res1, __u8 *data) 158 | * @brief builds canfd_frame with the given information 159 | * @param id identifier: 32 bit (CAN_ID + EFF + RTR + ERR flag) 160 | * @param len frame payload length in byte 161 | * @param flags additional flags for CAN FD 162 | * @param res0 reserved / padding 163 | * @param res1 reserved / padding 164 | * @param data payload 165 | * @retval canfd frame if successful 166 | * @retval NULL if unsuccessful 167 | * @todo not tested yet 168 | * @ingroup get 169 | */ 170 | extern struct canfd_frame *ce_gw_get_header_canfd(canid_t id, __u8 len, 171 | __u8 flags, __u8 res0, __u8 res1, __u8 *data); 172 | 173 | /** 174 | * @fn struct sk_buff *ce_gw_can_to_eth(unsigned char *dest, unsigned char 175 | * *source, __be16 type, struct sk_buff *can_buffer, struct net_device *dev) 176 | * @brief converts sk buffer including can frame into sk buffer including 177 | * ethernet_frame 178 | * @param dest MAC address of destination 179 | * @param source MAC address of source 180 | * @param type type of layer3 message (example: ipv4 or ipv6 ...) 181 | * @param can_buffer sk buffer including a can frame 182 | * @param dev device of destination 183 | * @retval sk_buffer on success including ethernet frame 184 | * @retval NULL if unsuccessful 185 | * @ingroup trans 186 | * @todo not tested yet 187 | */ 188 | extern struct sk_buff *ce_gw_can_to_eth(unsigned char *dest, 189 | unsigned char *source, __be16 type, struct sk_buff *can_buffer, 190 | struct net_device *net); 191 | 192 | /** 193 | * @fn struct sk_buff *ce_gw_canfd_to_eth(unsigned char *dest, unsigned char 194 | * *scource, __be16 type, struct sk_buff *canfd_skb, struct net_device *dev) 195 | * @brief converts sk buffer including canfd frame into sk buffer including 196 | * ethernet frame 197 | * @param dest MAC address of destination 198 | * @param source MAC address of source 199 | * @param type type of layer3 message (example: ipv4 or ipv6 ...) 200 | * @param canfd_skb sk buffer including a canfd_frame 201 | * @param dev device of the destination 202 | * @retval sk_buff including ethernet frame if successful 203 | * @retval NULL if unsuccessful 204 | * @ingroup trans 205 | * @todo not tested yet 206 | */ 207 | extern struct sk_buff *ce_gw_canfd_to_eth(unsigned char *dest, unsigned char *source, 208 | __be16 type, struct sk_buff *canfd_skb, 209 | struct net_device *net); 210 | 211 | /** 212 | * @fn struct sk_buff *ce_gw_eth_to_can(canid_t id, struct sk_buff *eth_buff, 213 | * struct net_device *dev) 214 | * @brief converst sk_buffer including an ethernet frame to sk_buffer 215 | * including a can_frame 216 | * @param id identifier of can_frame (see ce_gw_get_header for more information 217 | * @param eth_buff sk_buffer including an ethernet frame 218 | * @param dev device of the destination 219 | * @return sk_buffer including a can frame 220 | * @ingroup trans 221 | * @todo not tested yet 222 | */ 223 | extern struct sk_buff *ce_gw_eth_to_can(canid_t id, struct sk_buff *eth_buff, struct 224 | net_device *net); 225 | 226 | /** 227 | * @fn struct sk_buff *ce_gw_eth_to_canfd(canid_t id, __u8 flags, __u8 res0, 228 | * __u8 res1, struct sk_buff *eth_skb, struct net_device *dev) 229 | * @brief converst sk buffer including an ethernet frame to sk buffer 230 | * including a canfd frame 231 | * @param id identifier of canfd (see ce_gw_get_canfd_header for more 232 | * information) 233 | * @param flags additional flags for CAN FD 234 | * @param res0 reserved / padding 235 | * @param res1 reserved / padding 236 | * @param eth_skb sk buffer including ethernet frame 237 | * @param dev device of the destination 238 | * @return sk buffer including canfd frame 239 | * @ingroup trans 240 | * @todo not tested yet 241 | */ 242 | extern struct sk_buff *ce_gw_eth_to_canfd(canid_t id, __u8 flags, __u8 res0, 243 | __u8 res1, struct sk_buff *eth_skb, 244 | struct net_device *net); 245 | 246 | /** 247 | * @fn void ce_gw_can_rcv(struct sk_buff *can_skb, void *data) 248 | * @brief The gateway function for incoming CAN frames 249 | * Receive CAN frame --> process --> send to ETH dev 250 | * (skbuffer, struct receiver->data) 251 | * @param can_skb CAN sk buffer which should be translated to an ETH packet 252 | * @param data gwjob which is responsible for triggering this function 253 | * @ingroup proc 254 | * @todo check also for canfd flag not only Type and call function. You must 255 | * also check then if the message then is really a canfd-frame or not. 256 | * @todo call other translation functions. check for canfd-frame or only use 257 | * canfd-frame casts. 258 | */ 259 | extern void ce_gw_can_rcv(struct sk_buff *can_skb, void *data); 260 | 261 | /** 262 | * @fn static void ce_gw_eth_rcv(struct sk_buff *eth_skb, void *data) 263 | * @brief The gateway function for incoming ETH frames 264 | * Receive skb from ETH dev --> process --> send to CAN bus 265 | * @param eth_skb ETH sk buffer with CAN frame as payload. Exact location of CAN 266 | * frame depends on translation type (see enum ce_gw_type) 267 | * @param data gwjob which is responsible for triggering this function 268 | * @ingroup proc 269 | * @todo check for canfd-frame or only use canfd-frame casts. 270 | */ 271 | extern void ce_gw_eth_rcv(struct sk_buff *eth_skb, void *data); 272 | 273 | /** 274 | * @fn static int ce_gw_create_route(void) 275 | * @brief ce_gw_create_route - adds new route from CAN <-> ETH 276 | * @ingroup alloc 277 | * @retval TODO 278 | * @todo: add some more params: @param ce_gw_type 279 | */ 280 | extern int ce_gw_create_route(int src_ifindex, int dst_ifindex, 281 | enum ce_gw_type rt_type, u32 flags); 282 | 283 | /** 284 | * @fn static int ce_gw_remove_route(int id) 285 | * @brief ce_gw_remove_route - unregisters and removes CAN <-> ETH route by id 286 | * if id = 0: all routes will be removed 287 | * @ingroup alloc 288 | * @retval 0 on success 289 | */ 290 | extern int ce_gw_remove_route(u32 id); 291 | 292 | #endif 293 | 294 | /**@}*/ 295 | -------------------------------------------------------------------------------- /include/ce_gw_netlink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ce_gw_netlink.h 3 | * @brief Control Area Network - Ethernet - Gateway - Device Header 4 | * @author Fabian Raab (fabian.raab@tum.de) 5 | * @date May, 2013 6 | * @copyright GNU Public License v3 or higher 7 | * @ingroup files 8 | * @{ 9 | */ 10 | 11 | /***************************************************************************** 12 | * (C) Copyright 2013 Fabian Raab, Stefan Smarzly 13 | * 14 | * This file is part of CAN-Eth-GW. 15 | * 16 | * CAN-Eth-GW is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * CAN-Eth-GW is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with CAN-Eth-GW. If not, see . 28 | *****************************************************************************/ 29 | 30 | #ifndef __CE_GW_NETLINK_H__ 31 | #define __CE_GW_NETLINK_H__ 32 | 33 | /** 34 | * @fn int ce_gw_netlink_init(void) 35 | * @brief Must called once at module init. 36 | * @details During init of module this function must called. It registers 37 | * the family and its operations. 38 | * @retval 0 when init successful 39 | * @retval <0 if an error occurred. 40 | * @ingroup net 41 | */ 42 | int ce_gw_netlink_init(void); 43 | 44 | /** 45 | * @fn static void ce_gw_netlink_exit(void) 46 | * @brief Must called once at module exit. 47 | * @ingroup net 48 | * @details During exit of module this function must called. It unregisters 49 | * the family and its operations. 50 | */ 51 | void ce_gw_netlink_exit(void); 52 | 53 | #endif 54 | 55 | /**@}*/ 56 | -------------------------------------------------------------------------------- /man/README.md: -------------------------------------------------------------------------------- 1 | GNU Man Page 2 | =========== 3 | 4 | (!) Only edit the *.markdown files! 5 | 6 | The script `pandoc-convert.sh` will convert to other formats including *man*, so do not touch the other files, since they will be overwritten. The script will parse all files which match `*.markdown`, so name all other markdown files `.md`. 7 | 8 | (!) Make sure that you run the script bevore committing! 9 | 10 | Format of `*.markdown` files 11 | ------------------------- 12 | 13 | All *man pages* should be created here. Create a *pandoc markdown* file with the name `COMMAND.markdown` with a man page header. 14 | 15 | The script assumes that the first line of the `*.markdown` files begin with the book name: 16 | 17 | % CAN-ETH-GW(SECTION-NUMBER) TITLE | VERSION 18 | % AUTHOR1 19 | AUTHOR2 20 | % DATE 21 | 22 | + The file must have UNIX Line Endings 23 | + Use `:` for a definition 24 | + Tables must be in Github Flavored Markdow format and indented to a code block -------------------------------------------------------------------------------- /man/ce_gw.7: -------------------------------------------------------------------------------- 1 | .TH "CAN\-ETH\-GW" "7" "July 31, 2014" "CAN \- Ethernet Gateway Kernel Module" "master\-preview" 2 | .SH NAME 3 | .PP 4 | ce_gw \- CAN \- Ethernet Gateway Kernel Module 5 | .SH DESCRIPTION 6 | .PP 7 | Module for creating virtual ethernet devices. 8 | These virtual ethernet can transform the message for sending it to a CAN 9 | device and vice\-versa. 10 | See Control Uitlity (cegwctl) for configuring it. 11 | .SH BUGS 12 | .PP 13 | This is an early preview version. 14 | They are maybe some bugs. 15 | Please report bugs at GitHub can_eth_gw 16 | Issues (https://github.com/can-eth-gw/can_eth_gw/issues) 17 | .SH COPYRIGHT 18 | .PP 19 | © Copyright 2013 Fabian Raab, Stefan Smarzly 20 | .PP 21 | This file is part of CAN\-Eth\-GW. 22 | .PP 23 | CAN\-Eth\-GW is free software: you can redistribute it and/or modify it 24 | under the terms of the GNU General Public License as published by the 25 | Free Software Foundation, either version 3 of the License, or (at your 26 | option) any later version. 27 | .PP 28 | CAN\-Eth\-GW is distributed in the hope that it will be useful, but 29 | WITHOUT ANY WARRANTY; without even the implied warranty of 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 31 | See the GNU General Public License for more details. 32 | You should have received a copy of the GNU General Public License along 33 | with CAN\-Eth\-GW. 34 | If not, see . 35 | .SH SEE ALSO 36 | .PP 37 | \f[B]HOMEPAGE:\f[] can\-eth\-gw.github.io (http://can-eth-gw.github.io/) 38 | .PP 39 | cegwctl(8) 40 | .SH AUTHORS 41 | Fabian Raab ; Stefan Smarzly . 42 | -------------------------------------------------------------------------------- /man/ce_gw.7.jekyii.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: index 3 | title: man page 4 | subtitle: CAN-ETH-GW(7) CAN - Ethernet Gateway Kernel Module | master-preview 5 | --- 6 | 7 | NAME 8 | ==== 9 | 10 | ce\_gw - CAN - Ethernet Gateway Kernel Module 11 | 12 | DESCRIPTION 13 | =========== 14 | 15 | Module for creating virtual ethernet devices. These virtual ethernet can 16 | transform the message for sending it to a CAN device and vice-versa. See 17 | Control Uitlity (cegwctl) for configuring it. 18 | 19 | BUGS 20 | ==== 21 | 22 | This is an early preview version. They are maybe some bugs. Please 23 | report bugs at [GitHub can\_eth\_gw 24 | Issues](https://github.com/can-eth-gw/can_eth_gw/issues) 25 | 26 | COPYRIGHT 27 | ========= 28 | 29 | © Copyright 2013 Fabian Raab, Stefan Smarzly 30 | 31 | This file is part of CAN-Eth-GW. 32 | 33 | CAN-Eth-GW is free software: you can redistribute it and/or modify it 34 | under the terms of the GNU General Public License as published by the 35 | Free Software Foundation, either version 3 of the License, or (at your 36 | option) any later version. 37 | 38 | CAN-Eth-GW is distributed in the hope that it will be useful, but 39 | WITHOUT ANY WARRANTY; without even the implied warranty of 40 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 41 | Public License for more details. You should have received a copy of the 42 | GNU General Public License along with CAN-Eth-GW. If not, see 43 | . 44 | 45 | SEE ALSO 46 | ======== 47 | 48 | **HOMEPAGE:** [can-eth-gw.github.io](http://can-eth-gw.github.io/) 49 | 50 | cegwctl(8) 51 | 52 | AUTHORS 53 | ======= 54 | Fabian Raab ; Stefan Smarzly . 55 | -------------------------------------------------------------------------------- /man/ce_gw.7.md: -------------------------------------------------------------------------------- 1 | NAME 2 | ==== 3 | 4 | ce\_gw - CAN - Ethernet Gateway Kernel Module 5 | 6 | DESCRIPTION 7 | =========== 8 | 9 | Module for creating virtual ethernet devices. These virtual ethernet can transform the message for sending it to a CAN device and vice-versa. See Control Uitlity (cegwctl) for configuring it. 10 | 11 | BUGS 12 | ==== 13 | 14 | This is an early preview version. They are maybe some bugs. Please report bugs at [GitHub can\_eth\_gw Issues](https://github.com/can-eth-gw/can_eth_gw/issues) 15 | 16 | COPYRIGHT 17 | ========= 18 | 19 | © Copyright 2013 Fabian Raab, Stefan Smarzly 20 | 21 | This file is part of CAN-Eth-GW. 22 | 23 | CAN-Eth-GW is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 24 | 25 | CAN-Eth-GW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with CAN-Eth-GW. If not, see . 26 | 27 | SEE ALSO 28 | ======== 29 | 30 | **HOMEPAGE:** [can-eth-gw.github.io](http://can-eth-gw.github.io/) 31 | 32 | cegwctl(8) 33 | 34 | AUTHORS 35 | ======= 36 | Fabian Raab ; Stefan Smarzly . 37 | -------------------------------------------------------------------------------- /man/ce_gw.7.strict.md: -------------------------------------------------------------------------------- 1 | NAME 2 | ==== 3 | 4 | ce\_gw - CAN - Ethernet Gateway Kernel Module 5 | 6 | DESCRIPTION 7 | =========== 8 | 9 | Module for creating virtual ethernet devices. These virtual ethernet can 10 | transform the message for sending it to a CAN device and vice-versa. See 11 | Control Uitlity (cegwctl) for configuring it. 12 | 13 | BUGS 14 | ==== 15 | 16 | This is an early preview version. They are maybe some bugs. Please 17 | report bugs at [GitHub can\_eth\_gw 18 | Issues](https://github.com/can-eth-gw/can_eth_gw/issues) 19 | 20 | COPYRIGHT 21 | ========= 22 | 23 | © Copyright 2013 Fabian Raab, Stefan Smarzly 24 | 25 | This file is part of CAN-Eth-GW. 26 | 27 | CAN-Eth-GW is free software: you can redistribute it and/or modify it 28 | under the terms of the GNU General Public License as published by the 29 | Free Software Foundation, either version 3 of the License, or (at your 30 | option) any later version. 31 | 32 | CAN-Eth-GW is distributed in the hope that it will be useful, but 33 | WITHOUT ANY WARRANTY; without even the implied warranty of 34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 35 | Public License for more details. You should have received a copy of the 36 | GNU General Public License along with CAN-Eth-GW. If not, see 37 | . 38 | 39 | SEE ALSO 40 | ======== 41 | 42 | **HOMEPAGE:** [can-eth-gw.github.io](http://can-eth-gw.github.io/) 43 | 44 | cegwctl(8) 45 | 46 | AUTHORS 47 | ======= 48 | Fabian Raab ; Stefan Smarzly . 49 | -------------------------------------------------------------------------------- /man/ce_gw.markdown: -------------------------------------------------------------------------------- 1 | % CAN-ETH-GW(7) CAN - Ethernet Gateway Kernel Module | master-preview 2 | % Fabian Raab 3 | Stefan Smarzly 4 | % July 31, 2014 5 | 6 | 7 | 8 | # NAME 9 | 10 | ce_gw - CAN - Ethernet Gateway Kernel Module 11 | 12 | 13 | # DESCRIPTION 14 | 15 | Module for creating virtual ethernet devices. These virtual ethernet can transform the message for sending it to a CAN device and vice-versa. See Control Uitlity (cegwctl) for configuring it. 16 | 17 | 18 | # BUGS 19 | 20 | This is an early preview version. They are maybe some bugs. 21 | Please report bugs at [GitHub can_eth_gw Issues](https://github.com/can-eth-gw/can_eth_gw/issues) 22 | 23 | 24 | # COPYRIGHT 25 | 26 | © Copyright 2013 Fabian Raab, Stefan Smarzly 27 | 28 | This file is part of CAN-Eth-GW. 29 | 30 | CAN-Eth-GW is free software: you can redistribute it and/or modify 31 | it under the terms of the GNU General Public License as published by 32 | the Free Software Foundation, either version 3 of the License, or 33 | (at your option) any later version. 34 | 35 | CAN-Eth-GW is distributed in the hope that it will be useful, 36 | but WITHOUT ANY WARRANTY; without even the implied warranty of 37 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 38 | GNU General Public License for more details. 39 | You should have received a copy of the GNU General Public License 40 | along with CAN-Eth-GW. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/). 41 | 42 | 43 | # SEE ALSO 44 | 45 | **HOMEPAGE:** [can-eth-gw.github.io](http://can-eth-gw.github.io/) 46 | 47 | cegwctl(8) 48 | 49 | -------------------------------------------------------------------------------- /man/html.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | $for(author-meta)$ 8 | 9 | $endfor$ 10 | $if(date-meta)$ 11 | 12 | $endif$ 13 | $if(title-prefix)$$title-prefix$ - $endif$$pagetitle$ 14 | 15 | $if(quotes)$ 16 | 17 | $endif$ 18 | $if(highlighting-css)$ 19 | 22 | $endif$ 23 | $for(css)$ 24 | 25 | $endfor$ 26 | $if(math)$ 27 | $math$ 28 | $endif$ 29 | $for(header-includes)$ 30 | $header-includes$ 31 | $endfor$ 32 | 33 | 34 | $for(include-before)$ 35 | $include-before$ 36 | $endfor$ 37 | $if(title)$ 38 |
39 |

$title$

40 | $if(subtitle)$ 41 |

$subtitle$

42 | $endif$ 43 | $for(author)$ 44 |

$author$

45 | $endfor$ 46 | $if(date)$ 47 |

$date$

48 | $endif$ 49 |
50 | $endif$ 51 | $if(toc)$ 52 |
53 | $toc$ 54 |
55 | $endif$ 56 | $body$ 57 | $for(include-after)$ 58 | $include-after$ 59 | $endfor$ 60 |

AUTHORS

61 |

$for(author)$$author$$sep$; $endfor$.

62 | 63 | 64 | -------------------------------------------------------------------------------- /man/jekyii.template: -------------------------------------------------------------------------------- 1 | --- 2 | layout: index 3 | title: man page 4 | subtitle: $title$ 5 | --- 6 | 7 | $for(header-includes)$ 8 | $header-includes$ 9 | 10 | $endfor$ 11 | $for(include-before)$ 12 | $include-before$ 13 | 14 | $endfor$ 15 | $if(toc)$ 16 | $toc$ 17 | 18 | $endif$ 19 | $body$ 20 | $for(include-after)$ 21 | 22 | $include-after$ 23 | $endfor$ 24 | 25 | $if(author)$ 26 | AUTHORS 27 | ======= 28 | $for(author)$$author$$sep$; $endfor$. 29 | $endif$ 30 | -------------------------------------------------------------------------------- /man/markdown.template: -------------------------------------------------------------------------------- 1 | $for(header-includes)$ 2 | $header-includes$ 3 | 4 | $endfor$ 5 | $for(include-before)$ 6 | $include-before$ 7 | 8 | $endfor$ 9 | $if(toc)$ 10 | $toc$ 11 | 12 | $endif$ 13 | $body$ 14 | $for(include-after)$ 15 | 16 | $include-after$ 17 | $endfor$ 18 | 19 | $if(author)$ 20 | AUTHORS 21 | ======= 22 | $for(author)$$author$$sep$; $endfor$. 23 | $endif$ 24 | -------------------------------------------------------------------------------- /man/pandoc-convert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################################## 3 | ## Title: pandoc-convert 4 | ## Abstact: Converts from pandoc markdown to various formats 5 | ## Author: Fabian Raab 6 | ## Dependencies: bash, pandoc, sed, mktemp 7 | ## Files in the same dir as script: markdown.template 8 | ############################################################## 9 | 10 | SCRIPTNAME=$(basename $0) 11 | SCRIPTPATH="$0" 12 | EXIT_SUCCESS=0 13 | EXIT_FAILURE=1 14 | EXIT_ERROR=2 15 | EXIT_BUG=10 16 | 17 | SRC_DIR=$(dirname $0) 18 | DST_DIR=$(dirname $0) 19 | 20 | # count return codes 21 | rc=$EXIT_SUCCESS 22 | 23 | cd $SRC_DIR 24 | 25 | for file in "$SRC_DIR"/*.markdown; do 26 | 27 | echo "Converting $file" 28 | 29 | filetitle=$(basename --suffix=".markdown" "$file"; rc=$(($rc + $?))) 30 | 31 | # extract NUM of the first occurrence of '(NUM)'. The script assumes that in 32 | # the first line of $file the name and section of the man page is defined: 33 | # % CAN-ETH-GW(1) .... 34 | section=$(grep --max-count=1 -Po '^.*?\K(?<=\().*?(?=\))' "$file"; \ 35 | rc=$(($rc + $?))) 36 | 37 | temp_with_table=$(mktemp --suffix=".markdown") 38 | # removes spaces/tabs before '|' at beginning of line. Converts a table as code 39 | # block to a markdown table 40 | sed 's%^[\t ]*|\(.*\)$%|\1%g' ${file} > $temp_with_table 41 | rc=$(($rc + $?)) 42 | 43 | temp_with_table_greater=$(mktemp --suffix=".markdown") 44 | # replace ':' with '>' at beginning of lines 45 | sed 's%^[ ]*\:\(.*\)$%> \1%g' $temp_with_table > $temp_with_table_greater 46 | rc=$(($rc + $?)) 47 | 48 | ## Man Page 49 | pandoc -s -t man -i $temp_with_table -o ${DST_DIR}/${filetitle}.${section} 50 | rc=$(($rc + $?)) 51 | 52 | ## Standart Github Flavoured Markdown 53 | pandoc -t markdown_github --template=${SRC_DIR}/markdown.template \ 54 | -i $temp_with_table_greater \ 55 | -o ${DST_DIR}/${filetitle}.${section}.md 56 | rc=$(($rc + $?)) 57 | 58 | # pandoc removes \n before a '>' and add a escape. This command withdraw it. 59 | sed -i 's%\\>%\n>%g' ${DST_DIR}/${filetitle}.${section}.md 60 | rc=$(($rc + $?)) 61 | 62 | ## Strict Markdown 63 | pandoc -t markdown_strict --template=${SRC_DIR}/markdown.template \ 64 | -i $temp_with_table_greater \ 65 | -o ${DST_DIR}/${filetitle}.${section}.strict.md 66 | rc=$(($rc + $?)) 67 | 68 | # pandoc removes \n before a '>' and add a escape. This command withdraw it. 69 | sed -i 's%\\>%\n>%g' ${DST_DIR}/${filetitle}.${section}.strict.md 70 | rc=$(($rc + $?)) 71 | 72 | ## Strict Markdown with Jeky II header 73 | pandoc -t markdown_strict --template=${SRC_DIR}/jekyii.template \ 74 | -i $temp_with_table_greater \ 75 | -o ${DST_DIR}/${filetitle}.${section}.jekyii.md 76 | rc=$(($rc + $?)) 77 | 78 | # pandoc removes \n before a '>' and add a escape. This command withdraw it. 79 | sed -i 's%\\>%\n>%g' ${DST_DIR}/${filetitle}.${section}.jekyii.md 80 | rc=$(($rc + $?)) 81 | 82 | ## HTML 83 | pandoc -s -t html --template=${SRC_DIR}/html.template \ 84 | -i $temp_with_table \ 85 | -o ${DST_DIR}/${filetitle}.${section}.html 86 | rc=$(($rc + $?)) 87 | 88 | done 89 | 90 | exit $rc -------------------------------------------------------------------------------- /src/ce_gw_dev.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ce_gw_dev.c 3 | * @brief Control Area Network - Ethernet - Gateway - Device 4 | * @author Fabian Raab (fabian.raab@tum.de) 5 | * @date May, 2013 6 | * @copyright GNU Public License v3 or higher 7 | * @ingroup files 8 | * @{ 9 | */ 10 | 11 | /***************************************************************************** 12 | * (C) Copyright 2013 Fabian Raab, Stefan Smarzly 13 | * 14 | * This file is part of CAN-Eth-GW. 15 | * 16 | * CAN-Eth-GW is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * CAN-Eth-GW is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with CAN-Eth-GW. If not, see . 28 | *****************************************************************************/ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) 38 | # include 39 | # else 40 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) 41 | # include 42 | # else 43 | # error Only Linux Kernel 3.6 and above are supported 44 | # endif 45 | #endif 46 | #include "ce_gw_dev.h" 47 | #include "ce_gw_main.h" 48 | 49 | #include 50 | #include 51 | 52 | HLIST_HEAD(ce_gw_dev_allocated); /**< list of all allocated ethernet devices */ 53 | HLIST_HEAD(ce_gw_dev_registered);/**< list of all registered ethernet devices */ 54 | static struct kmem_cache *ce_gw_dev_cache __read_mostly; /**< cache for lists */ 55 | 56 | /** 57 | * @struct ce_gw_dev_list 58 | * @brief internal list of all registered and allocated devices. 59 | * @details This list is used on module exit for unregistering and freeing all 60 | * devices. 61 | */ 62 | struct ce_gw_dev_list { 63 | struct hlist_node list_alloc; 64 | struct hlist_node list_reg; 65 | struct rcu_head rcu; 66 | struct net_device *dev; 67 | }; 68 | 69 | /** 70 | * @fn int ce_gw_dev_open(struct net_device *dev) 71 | * @brief called by the OS on device up 72 | * @param dev correspondening eth device 73 | * @retval 0 on success 74 | * @retval <0 on failure 75 | * @ingroup dev 76 | */ 77 | int ce_gw_dev_open(struct net_device *dev) 78 | { 79 | printk("ce_gw: ce_gw_open called\n"); 80 | 81 | if (!netif_device_present(dev)) { 82 | pr_err("ce_gw_dev_open: Device not registered"); 83 | return -1; 84 | } 85 | 86 | netif_start_queue(dev); 87 | return 0; 88 | } 89 | 90 | /** 91 | * @fn int ce_gw_dev_stop(struct net_device *dev) 92 | * @brief called by the OS on device down 93 | * @param dev correspondening eth device 94 | * @retval 0 on success 95 | * @retval <0 on failure 96 | * @ingroup dev 97 | */ 98 | int ce_gw_dev_stop(struct net_device *dev) 99 | { 100 | printk ("ce_gw_dev: ce_gw_release called\n"); 101 | netif_stop_queue(dev); 102 | return 0; 103 | } 104 | 105 | /** 106 | * @fn static int ce_gw_dev_start_xmit(struct sk_buff *skb, 107 | * struct net_device *dev) 108 | * @brief called by the OS if a package is sent to the device 109 | * @param dev correspondening eth device 110 | * @param skb sk buffer from OS 111 | * @retval 0 on success 112 | * @retval <0 on failure 113 | * @ingroup dev 114 | */ 115 | static int ce_gw_dev_start_xmit(struct sk_buff *skb, 116 | struct net_device *dev) 117 | { 118 | printk ("ce_gw_dev: dummy xmit function called....\n"); 119 | /* TODO: Get right gw_job and push it to eth_skb (instead of NULL) */ 120 | struct ce_gw_job_info *priv = netdev_priv(dev); 121 | 122 | struct ce_gw_job *job = NULL; 123 | struct hlist_node *node; 124 | 125 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 126 | hlist_for_each_entry_safe(job, node, &priv->job_src, list_dev) { 127 | 128 | # else 129 | struct hlist_node *pos; 130 | hlist_for_each_entry_safe(job, pos, node, &priv->job_src, 131 | list_dev) { 132 | # endif 133 | ce_gw_eth_rcv(skb, job); 134 | } 135 | 136 | dev_kfree_skb(skb); 137 | 138 | /*here is my test for ce_gw_eth_to_canfd*/ 139 | /* struct sk_buff *can_skb;*/ 140 | /* __u32 id = 0xF65C034B;*/ 141 | /* __u8 flags = 0x04;*/ 142 | /* __u8 res0 = 0xF3;*/ 143 | /* __u8 res1 = 0x00;*/ 144 | /* can_skb = ce_gw_eth_to_canfd(id, flags, res0, res1, skb, dev);*/ 145 | return 0; 146 | } 147 | 148 | /** 149 | * @fn static int ce_gw_dev_init(struct net_device *dev) 150 | * @brief called by the OS on device registered 151 | * @param dev correspondening eth device 152 | * @retval 0 on success 153 | * @retval <0 on failure 154 | * @ingroup dev 155 | */ 156 | int ce_gw_dev_init(struct net_device *dev) { 157 | printk ("ce_gw_dev: device init called\n"); 158 | return 0; 159 | } 160 | 161 | /** 162 | * @brief Defined Functions of Ethernet device 163 | */ 164 | static struct net_device_ops ce_gw_ops = { 165 | .ndo_init = ce_gw_dev_init, 166 | .ndo_open = ce_gw_dev_open, 167 | .ndo_stop = ce_gw_dev_stop, 168 | .ndo_start_xmit = ce_gw_dev_start_xmit, 169 | 0 170 | }; 171 | 172 | int ce_gw_is_allocated_dev(struct net_device *eth_dev) { 173 | 174 | struct ce_gw_dev_list *dl = NULL; 175 | struct hlist_node *node; 176 | 177 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 178 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_allocated, list_alloc) { 179 | 180 | # else 181 | struct hlist_node *pos; 182 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_allocated, 183 | list_alloc) { 184 | # endif 185 | if (dl->dev == eth_dev) 186 | return 0; 187 | } 188 | 189 | return -ENODEV; 190 | } 191 | 192 | int ce_gw_is_registered_dev(struct net_device *eth_dev) { 193 | 194 | struct ce_gw_dev_list *dl = NULL; 195 | struct hlist_node *node; 196 | 197 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 198 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_registered, list_reg) { 199 | 200 | # else 201 | struct hlist_node *pos; 202 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_registered, 203 | list_reg) { 204 | # endif 205 | if (dl->dev == eth_dev) 206 | return 0; 207 | } 208 | 209 | pr_debug("ce_gw_is_registered_dev: Device not registered\n"); 210 | return -ENODEV; 211 | } 212 | 213 | int ce_gw_has_min_mtu(struct net_device *dev, enum ce_gw_type type, u32 flags) { 214 | 215 | int mtu = ETH_DATA_LEN; /* Standart Ethernet Value */ 216 | 217 | switch (type) { 218 | case CE_GW_TYPE_NONE: 219 | /* Do Nothing (default Ethernet MTU will be set) */ 220 | break; 221 | case CE_GW_TYPE_ETH: 222 | if ((flags & CE_GW_F_CAN_FD) == CE_GW_F_CAN_FD) { 223 | mtu = CANFD_MAX_DLEN; 224 | } else { 225 | mtu = CAN_MAX_DLEN; 226 | } 227 | break; 228 | case CE_GW_TYPE_NET: 229 | if ((flags & CE_GW_F_CAN_FD) == CE_GW_F_CAN_FD) { 230 | mtu = sizeof(struct canfd_frame); 231 | } else { 232 | mtu = sizeof(struct can_frame); 233 | } 234 | break; 235 | case CE_GW_TYPE_TCP: 236 | /* TODO nothing yet */ 237 | break; 238 | case CE_GW_TYPE_UDP: 239 | /* TODO nothing yet */ 240 | break; 241 | default: 242 | pr_err("ce_gw_dev: Type not defined."); 243 | } 244 | 245 | if (dev->mtu >= mtu) { 246 | return true; 247 | } 248 | 249 | return false; 250 | } 251 | 252 | void ce_gw_dev_job_src_add(struct ce_gw_job *job) { 253 | struct ce_gw_job_info *priv = netdev_priv(job->src.dev); 254 | hlist_add_head_rcu(&job->list_dev, &priv->job_src); 255 | } 256 | 257 | void ce_gw_dev_job_dst_add(struct ce_gw_job *job) { 258 | struct ce_gw_job_info *priv = netdev_priv(job->dst.dev); 259 | hlist_add_head_rcu(&job->list_dev, &priv->job_dst); 260 | } 261 | 262 | 263 | int ce_gw_dev_job_add(struct net_device *eth_dev, struct ce_gw_job *job) { 264 | if (job->src.dev == eth_dev) { 265 | ce_gw_dev_job_src_add(job); 266 | } else if (job->dst.dev == eth_dev) { 267 | ce_gw_dev_job_dst_add(job); 268 | } else { 269 | pr_err("ce_gw_dev_job_add: Invalid Arguments"); 270 | return -1; 271 | } 272 | return 0; 273 | } 274 | 275 | void ce_gw_dev_job_remove(struct ce_gw_job *job) { 276 | hlist_del_rcu(&job->list_dev); 277 | } 278 | 279 | struct net_device *ce_gw_dev_alloc(char *dev_name) { 280 | pr_debug("ce_gw_dev: Alloc Device\n"); 281 | struct net_device *dev; 282 | 283 | dev = alloc_netdev(sizeof(struct ce_gw_job_info), 284 | dev_name, ether_setup); 285 | if (dev == NULL) { 286 | pr_err("ce_gw_dev: Error allocation etherdev."); 287 | goto ce_gw_dev_create_error; 288 | } 289 | 290 | /* initialize private field */ 291 | struct ce_gw_job_info *priv = netdev_priv(dev); 292 | memset(priv, 0, sizeof(struct ce_gw_job_info)); 293 | priv->job_src.first = NULL; 294 | priv->job_dst.first = NULL; 295 | 296 | /* create list entry and add */ 297 | struct ce_gw_dev_list *dl; 298 | dl = kmem_cache_alloc(ce_gw_dev_cache, GFP_KERNEL); 299 | if (dl == NULL) { 300 | pr_err("ce_gw_dev: cache alloc failed"); 301 | goto ce_gw_dev_create_error_cache; 302 | } 303 | 304 | dl->dev = dev; 305 | 306 | hlist_add_head_rcu(&dl->list_alloc, &ce_gw_dev_allocated); 307 | 308 | return dev; 309 | 310 | ce_gw_dev_create_error_cache: 311 | kmem_cache_free(ce_gw_dev_cache, dl); 312 | 313 | ce_gw_dev_create_error: 314 | free_netdev(dev); 315 | return NULL; 316 | } 317 | 318 | void ce_gw_dev_free(struct net_device *eth_dev) { 319 | pr_debug("ce_gw_dev: Free Device %s\n", eth_dev->name); 320 | 321 | struct ce_gw_dev_list *dl = NULL; 322 | struct hlist_node *node; 323 | 324 | /* search for the List Element of eth_dev */ 325 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 326 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_allocated, list_alloc) { 327 | 328 | # else 329 | struct hlist_node *pos; 330 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_allocated, 331 | list_alloc) { 332 | # endif 333 | if (dl->dev == eth_dev) 334 | break; 335 | } 336 | 337 | if (dl == NULL || dl->dev != eth_dev) { 338 | pr_err("ce_gw_dev: Device not found in list\n"); 339 | } else { 340 | hlist_del_rcu(&dl->list_alloc); 341 | } 342 | 343 | free_netdev(eth_dev); 344 | kmem_cache_free(ce_gw_dev_cache, dl); 345 | } 346 | 347 | void ce_gw_dev_setup(struct net_device *dev, enum ce_gw_type type, 348 | __u32 flags) { 349 | dev->netdev_ops = &ce_gw_ops; 350 | 351 | /* Set sensible MTU */ 352 | switch (type) { 353 | case CE_GW_TYPE_NONE: 354 | /* Do Nothing (default Ethernet MTU will be set) */ 355 | break; 356 | case CE_GW_TYPE_ETH: 357 | if ((flags & CE_GW_F_CAN_FD) == CE_GW_F_CAN_FD) { 358 | dev->mtu = CANFD_MAX_DLEN; 359 | } else { 360 | dev->mtu = CAN_MAX_DLEN; 361 | } 362 | break; 363 | case CE_GW_TYPE_NET: 364 | if ((flags & CE_GW_F_CAN_FD) == CE_GW_F_CAN_FD) { 365 | dev->mtu = sizeof(struct canfd_frame); 366 | } else { 367 | dev->mtu = sizeof(struct can_frame); 368 | } 369 | break; 370 | case CE_GW_TYPE_TCP: 371 | /* TODO nothing yet */ 372 | break; 373 | case CE_GW_TYPE_UDP: 374 | /* TODO nothing yet */ 375 | break; 376 | default: 377 | pr_err("ce_gw_dev: Type not defined."); 378 | } 379 | } 380 | 381 | struct net_device *ce_gw_dev_create(enum ce_gw_type type, __u32 flags, 382 | char *dev_name) { 383 | struct net_device *dev; 384 | 385 | dev = ce_gw_dev_alloc(dev_name); 386 | 387 | ce_gw_dev_setup(dev, type, flags); 388 | 389 | return dev; 390 | } 391 | 392 | int ce_gw_dev_register(struct net_device *eth_dev) { 393 | pr_debug("ce_gw_dev: Register Device\n"); 394 | int err = 0; 395 | err = register_netdev(eth_dev); 396 | 397 | struct ce_gw_dev_list *dl = NULL; 398 | struct hlist_node *node; 399 | 400 | /* search for the List Element of eth_dev */ 401 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 402 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_allocated, list_alloc) { 403 | 404 | # else 405 | struct hlist_node *pos; 406 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_allocated, 407 | list_alloc) { 408 | # endif 409 | if (dl->dev == eth_dev) 410 | break; 411 | } 412 | 413 | if (dl == NULL || dl->dev != eth_dev) { 414 | pr_err("ce_gw_dev: Device not found in list\n"); 415 | goto ce_gw_dev_register_error; 416 | } 417 | 418 | hlist_add_head_rcu(&dl->list_reg, &ce_gw_dev_registered); 419 | if (&dl->list_reg == NULL) { 420 | pr_err("ce_gw_dev: Device not add to list correct\n"); 421 | } 422 | 423 | return err; 424 | 425 | ce_gw_dev_register_error: 426 | unregister_netdev(eth_dev); 427 | return err; 428 | } 429 | 430 | void ce_gw_dev_unregister(struct net_device *eth_dev) { 431 | pr_debug("ce_gw_dev: Unregister Device %s\n", eth_dev->name); 432 | int err = 0; 433 | 434 | struct ce_gw_job_info *priv = netdev_priv(eth_dev); 435 | pr_debug("ce_gw_dev: Deleting all Routes of %s\n", eth_dev->name); 436 | 437 | /* Delete all routes witch are linked to the soon unregistered device 438 | * where the device is the source */ 439 | struct ce_gw_job *job = NULL; 440 | struct hlist_node *node; 441 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 442 | hlist_for_each_entry_safe(job, node, &priv->job_src, list_dev) { 443 | 444 | # else 445 | struct hlist_node *pos; 446 | hlist_for_each_entry_safe(job, pos, node, &priv->job_src, list_dev) { 447 | # endif 448 | 449 | err = ce_gw_remove_route(job->id); 450 | if (err != 0) { 451 | pr_err("ce_gw_dev: route with id %u " 452 | "deleting failed: %d", job->id, err); 453 | } 454 | } 455 | 456 | /* Delete all routes witch are linked to the soon unregistered device 457 | * where the device is the dest */ 458 | job = NULL; 459 | node = NULL; 460 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 461 | hlist_for_each_entry_safe(job, node, &priv->job_dst, list_dev) { 462 | 463 | # else 464 | pos = NULL; 465 | hlist_for_each_entry_safe(job, pos, node, &priv->job_dst, list_dev) { 466 | # endif 467 | 468 | err = ce_gw_remove_route(job->id); 469 | { 470 | pr_err("ce_gw_dev: route with id %u " 471 | "deleting failed: %d", job->id, err); 472 | } 473 | } 474 | 475 | /* unregister */ 476 | pr_debug("ce_gw_dev: Call unregister_netdev() of %s\n", eth_dev->name); 477 | unregister_netdev(eth_dev); 478 | 479 | struct ce_gw_dev_list *dl = NULL; 480 | node = NULL; 481 | 482 | /* search for the List Element of eth_dev */ 483 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 484 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_registered, list_reg) { 485 | 486 | # else 487 | pos = NULL; 488 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_registered, 489 | list_reg) { 490 | # endif 491 | if (dl->dev == eth_dev) 492 | break; 493 | } 494 | 495 | if (dl == NULL || &dl->list_reg == NULL) { 496 | pr_err("ce_gw_dev: Device not correct in internal list\n"); 497 | } else { 498 | hlist_del_rcu(&dl->list_reg); 499 | } 500 | } 501 | 502 | 503 | int ce_gw_dev_init_module(void) { 504 | ce_gw_dev_cache = kmem_cache_create("can_eth_gw_dev", 505 | sizeof(struct ce_gw_dev_list), 506 | 0, 0, NULL); 507 | if (!ce_gw_dev_cache) 508 | return -ENOMEM; 509 | 510 | return 0; 511 | } 512 | 513 | void ce_gw_dev_cleanup(void) { 514 | struct ce_gw_dev_list *dl = NULL; 515 | struct hlist_node *node; 516 | 517 | /* iterate over list and unregister */ 518 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 519 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_registered, list_reg) { 520 | 521 | # else 522 | struct hlist_node *pos; 523 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_registered, 524 | list_reg) { 525 | # endif 526 | ce_gw_dev_unregister(dl->dev); 527 | } 528 | 529 | dl = NULL; 530 | node = NULL; 531 | 532 | /* iterate over list and free */ 533 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0) 534 | hlist_for_each_entry_safe(dl, node, &ce_gw_dev_allocated, list_alloc) { 535 | 536 | # else 537 | pos = NULL; 538 | hlist_for_each_entry_safe(dl, pos, node, &ce_gw_dev_allocated, 539 | list_alloc) { 540 | # endif 541 | ce_gw_dev_free(dl->dev); 542 | } 543 | 544 | kmem_cache_destroy(ce_gw_dev_cache); 545 | } 546 | 547 | /**@}*/ 548 | --------------------------------------------------------------------------------