So my name is Eric Evanczyk. I work on cars. I work for a company now called Faraday Future. We're making a new electric vehicle. I get to say that we're hiring, which is something I've never got to say in my life before. So if you're someone who's into cars, wants to do like firmware kind of stuff on cars, reach out after. We can chat about that. The other thing that I've done is build this little open source can tool called Cantact. Basically, the way that this came along is I was giving a talk on CAN bus just sort of in general at TourCon, which is a great conference that happens in San Diego every year. And I was like, yeah, there's a bunch of tools available. Most of them are kind of a couple hundred bucks or whatever. There's some open source ones, but no one really makes them anymore. And someone was like, oh, well, you should build one. And so I did. This talk isn't really about this tool. It kind of is. But it's more about something called SanDisk. It's called Socket CAN. And we'll talk about Socket CAN, which applies to a lot of different tools, both commercial and open source. What it is, how it works, and how you can use it to develop CAN bus applications for, you know, whatever you want to do with cars. So what is Socket CAN? Basically, if you've ever dealt with... Is anyone here like a Linux user in general? Or are you mostly Windows? Okay, so like we got, you know, a good amount of Linux users. OSX, anybody? Couple, okay. You guys might know what's going on a little bit. And then Windows, you have no idea what's going on. But, well, I'm sorry. You can run a VM. You can run a VM. So what happens with this is, if you've ever used Linux network devices before, you know, you have the network driver, which is sitting real low in the kernel, deals with the actual hardware. In this case, that's replaced with the CAN controller. Then on the left, we have the Socket CAN version. On the right, we have the traditional version. We'll start with the traditional way of doing it. So CAN controller, you stick a driver on top of that, such as a character device driver for the SL CAN devices we'll talk about. Then on top of that, you can stick a protocol interface. And then the application that you actually write goes in the very, very end. You can take a picture of this or literally go to Wikipedia, which I ripped it off of. Yeah, sorry. But on the left-hand side, you have the Socket CAN version. The way this works is your Ethernet hardware or whatever Wi-Fi card, whatever it is, replaced with a CAN controller. And then Socket CAN kind of jumps in and takes over from the network device driver level up. And it actually merges back with how you'd normally deal with sockets in Linux at the socket layer, which means that we can write code that looks a lot like network socket code, but it's actually going to talk CAN. And then in your application, you make those calls just like you would with any other socket. And, you know, you're probably familiar with something like this if you've ever dealt with sockets ever or devices on Linux at all. This is kind of washed out, I'm sorry, but this is me running ifconfig for a vCAN device, which is a virtual CAN bus device we'll talk about. And it shows up just like any other network device you'd see. It has the one weird thing with it is the hardware address comes up as like just a whole bunch of zeros for some weird reason. And it has everything you'd expect. Some of those numbers don't work, but a lot of them do. Receipt packets, transmitted packets, all that kind of stuff. So once you have this device and, you know, you've set it up, and it's actually a network device, in C you literally do everything you'd expect to do with sockets. Has anyone done socket code in C before? Got a couple hands. So, like, you know, you call the function, you get a file descriptor back. The difference being where normally you would specify, like, I want an INET socket, and I want it to be, or UDP datagram, and I want these flags. This will get you a CAN socket that is a raw CAN socket, which means you get direct access. There's also a mode called BCM, which is meant to deal with queuing, and it's meant to take the work off of the user space application and do more of it in the kernel space. I haven't worked with it too much. It supports kind of odd, it seems, but it's getting there. So once you have that socket, you can do everything you'd expect. You can call IOControl to set up, you know, in some cases bit rates, but at the very least set the address of it. You can bind to it, and then you can do reads and writes, and you can set socket options to block or not block or time out, all those things. You can also do all of this from Python, but specifically Python 3. For whatever reason, socket.pfcan and sock.raw, or socket.sockraw, are not defined in Python 2. I'm not quite sure why. But in Python 3, it works great. You can create a new socket and call all the same functions. It's just an interface. So this is, you know, that's how you go from CAN to sockets, is you're just working with them. You fill up a buffer. Rather than sending a normal IP, like a TCP IP or UDP buffer, you populate a CAN frame struct, and you say, hey, send this CAN frame struct, or read me in a CAN frame struct, just like you would with TCP or UDP. Now, if you don't have any CAN devices, though a lot of you will have one of these sweet things now, but it doesn't plug into your computer. So let's say you want to play around with CAN on your computer and, you know, create a device that's not a real device, but it'll let you send and receive messages and play around with all the tools with no hardware. So it's free. That's the biggest benefit. It's also useful for, like, simulating stuff and just testing out tools. You can actually do this sudo ip link add vcan 0 of type vcan. That will create you a new virtual CAN device. Once you have the device, you can just do ifconfig vcan up, and sure enough, you get a CAN device. Again, it's not going to send any frames out on the wire. It's just virtual. But you can use all the tools. You can send stuff around. You can write. It's quite useful for developing tools because let's say you have a client and a server. You can develop both of them to use socket CAN, use this to test it without actually having to deal with hardware, and then write whatever you need to deal with the hardware later. I may have done that once or twice, so it's kind of handy. Now, if you want a real device, there's a few things you can do. One is this SL CAN. So this stands for serial line CAN. And it supports this pretty old protocol that some company came up with a while ago that basically takes CAN frames and encodes them over serial data like UART or RS-232. You can actually buy something that does this from, for example, Peak or GridConnect. They sell a tool that is CAN to RS-232, and it spits out ASCII. So it's really not that efficient because, for example, the byte FF becomes the two bytes, the character F and the character F again. But it's well supported, and it works out of the box. So that's why this CANTAC thing ended up using this protocol rather than something more efficient. It's just, it works. The bad news is that serial is very slow. You know, typical baud rates you're going to get off of a RS-232 or UART, it's going to be 115, 200 bits per second. CAN can go up to 1 megabit per second, though we usually see it used at 500, or KBPS. CAN FD is another thing that I'm not going to talk about, but there actually is starting to be Linux support for it. So yeah, that's a problem, right? We have one order of magnitude of a jump. The good news is that it turns out that the bit rate doesn't actually matter when you're dealing with a USB to serial device. That bit rate that you set is only to tell the device, okay, please talk serial at whatever rate. So in the case of the CANTAC, if I do this thing, I want to do 9600 baud, it will ignore you and instead just continue talking as fast as it possibly can over USB. It's kind of a common misconception. People figure, oh, well, USB serial devices must be limited to whatever, 115, 200, but no, they can go a lot faster. Specifically, if you're interested in it, it's a 64-byte endpoint for USB, so you can basically do really fast transfers as long as they're 64 bytes or less. So you can use this. There's a typo on this slide, but you can use this command to bring up a serial line device. So anything that speaks this standard protocol will interface by running this command. So it's SLCAND, which is the serial line CAN daemon. Dash O tells it that when you start it up, you want to send the open command, which is just capital O and a carriage. It actually all uses a carriage return rather than a new line. Yeah, carriage return rather than new line for whatever reason. Dash C tells it whenever you close SLCAND, you want to send the close command. You give it the path to your device, dev, TTY, ACM, whatever, then the name of the device that you want to actually create. So in this case, it would connect to something like this and create a CAN0 device. Here's the typo. You would then call ifconfig can, not vcan, 0 up, and that would bring the device up, and now you have access to it over a socket interface. Now, if you're a developer who deals with Unix sockets, that might be of interest to you. You might be like, great, I can do CAN now. That's cool. If you're not, you're probably thinking, well, okay, what's the point? Like, I don't write code for that anyway. And the main reason you'd want to do this is there's a whole bunch of tools you get for free. This is a list of some of them, and we'll show them now because I don't have that many slides. I figured it would be better to actually show you this working and, you know, how it works. So if I switch to VM mode, and if it actually works, oh, that is interesting. That is not what I want at all. I have no idea what that is. That's pretty much the same thing. Displays. The thermostat was an example of an RTU. RTUs are obviously designed to be remote, so they are in remote locations. This is why you test out the projector before you start your talk, just for future reference. Really harsh conditions sometimes. I mean, imagine how many PLCs we had on top. Nope, that's me changing my screensaver now. And then compare that with the ones I took that picture. It's a good one. Thank you. Here we are. Arrangement. Let's see. Where is mirror? It's not going to let me mirror. Awesome. What we're going to do then is we're just going to take my VM because you guys are probably bored of me playing around with display settings. And where is that? Oh, there it is. Apparently it's off to the left of my screen. Hey. Please don't be terrible resolution. All right. Now I have to look this way. So, first thing we're going to talk about, and I'm going to do this all on VCAN devices, just because this is all stuff you can try at home with no hardware, which is kind of fun. First thing we'll do is actually, let's do TMUX. Let's do equals. Cool. So I have two terminals here. Hopefully it comes out later. I don't know if this is legible. Projectors and VMs are always trying. So, first thing you're probably going to want to do if you're ever on a CAN system is dump a whole bunch of stuff. So let's do that. So CAN DUMP VCAN 0. What this is going to do is start dumping messages. And there actually are active messages right now flying around. We'll look at them more later. But, you know, it's going to give you a trace of the CAN bus. It's just going to give you every message printed out with a few different options. There are a lot of options that are quite useful. So if you want time stamps, you can do TA for absolute time stamps. That's the number of seconds since the Unix epoch that your CAN message arrived, which is probably not the most useful number. But TD is a very useful one. It will tell you the delta time, so time in between messages. And that would be CAN DUMP. Pretty simple. But let's keep CAN DUMP running. We'll kill off that stuff running in the background. Cool. So it stopped. We'll start it again so you can see. You want to send some arbitrary CAN frames. That's another useful thing to do. We can use CAN SEND. Format for this is CAN SEND, CAN ID, number sign, and some bytes. 11AABBCC, whatever. And that, oh, no, it's not. VCAN 0 for the device. And that will let us send CAN frames. So if we're connected to a real car right now, we're literally sending CAN frames on the bus. It's pretty simple. If you want to just fuzz out some frames and see what happens. Another pretty useful thing you can do is logging. So I actually took a log by using CAN DUMP with the dash L flag, which will log to a file. And the nice thing about this is I can now play it back. So this might be a little hard to read. What I'm doing here is using CAN Player, which is a playback tool. And I'm saying send the messages that were on CAN. Can 1, whenever you received them. To the device CAN 0. And repeat this infinitely using this log file. And so that's what lets us, you know, just generate a whole boatload of frames that are kind of useful. There's another tool if you want to generate useless frames called CAN GEN. And that will literally just spit out random data. There's a whole bunch of different flags you can set for different types of data. But VCAN 0. You can use this. Very useful if you want to load up a bus to like 90% and see what happens. You can say I want message 0 to be going on at really, really fast speed so that I can test to see if my diagnostic stuff that's on really high IDs still work. One example of using it. But here it's just spitting out crap. So these are all like, you know, simple CAN interfacing tools. Now we'll talk about some actually pretty useful ones. The first one is CAN sniffer. And CAN sniffer is sort of unlike any other tool that I've really seen for CAN. It basically lets you. VCAN 0. Basically lets you just take a look at what's going on. I've killed off all of my messages. One sec. We'll start that log up again. And we will do over here. CAN sniffer VCAN 0. Okay. This is going to show you everything going on in the bus. You see a bunch of messages at the top. After a couple seconds, a lot of them go away. And we only have one left. And the reason being this is the only frame where anything is changing. Everything else, it's just we're getting the same frame, the same data over and over and over again. And that's not exciting because who cares. When you're reverse engineering CAN buses, though, it's quite useful to be able to see what's changing. For example, you want to know where the pedal position signal is on the bus. So you plug in. And you start pushing the pedal. And you want to see that value change. This gets even better if you do use the what's the flag? It's definitely not dash dash help for it. There is a flag for color. It's dash C. Great. So now we can actually see what's changing. And it shows you exactly what byte is changing. It shows you it in ASCII as well. And increments like that. If you plug this into real systems, it's quite useful because all the cruft that just repeats itself over and over and over again goes away. And you actually get to see the live data. So that's CAN sniffer. It has a whole bunch of other options. This is a quick demo. Depending on what you're trying to do, CAN sniffer might have something useful. The last thing I really want to demo, and then, you know, this is basically just about showing you tools and having you ask questions about them. But the last tool I'll show off is Wireshark, which some of you have probably used for not CAN purposes. It's a really good tool. It's a pretty popular tool. You may have heard of it. Wireshark supports CAN. And most people don't know this. It supports it out of the box. It does a pretty good job of it, too. If you just want to record CAN frames, everything that I've been doing is now recorded in this Wireshark trace. I can scroll through. I can pause it. I can save a PCAP file. You can write filters like CAN. ID is greater than OX100. It will filter them. If you're working with CAN open, which is a protocol mostly used in ICS systems, not so much cars, so industrial stuff, SCADA. You can actually do CAN open dot and filter by a lot of different things that CAN open uses. I'm not sure if anyone is interested in that part of CAN, but those options are there. And it's a useful tool for looking at buses. It can deal with very large amounts of data. It's used to dealing with network packets. And, yeah, it's kind of a nice thing to run in the background and just be able to save a trace of what you're doing. So, yeah. So, yeah. So, yeah. So, yeah. So, all this stuff, it's pretty low-level tools. It's more meant for the development end. But it makes it pretty easy to then write your own software using CAN. And, you know, if you do C right now and you do network devices or any kind of socket stuff, extending that to CAN has just become, okay, I'll call it with the right flags and that's about it. So, that's pretty much my really quick tour of socket CAN. At this point, questions or tool demos that you want to specifically see, I'll put them in the chat. I think the ones that you see probably make the most sense because we should tailor this to what you want and not just keep talking about random tools. So, is there any questions from anyone about socket CAN or devices or really anything CAN related? I'll try to answer. Oh. What is CAN? I figured people in here, like, knew a bit about cars and CAN bus. I may have just, like, gone way the hell over everybody's head. I hope I didn't. Has anyone gone to none of the car hacking stuff yet? Everyone's gone to something, right? Good. You scared me. I didn't realize that. Okay. Good. Are there any other questions about socket CAN or CAN in general? Yeah. So, it's this device that I built. It's basically I was like, hey, I should build an open source hardware thing. So, I did. This is using the open source hardware. This is the STM32F0, which is remarkably similar to the microcontroller on this guy. Slightly different package. Cool thing about it is it can do USB and CAN at the same time. So, this is essentially a USB connector, microcontroller, CAN transceiver, and some jumpers. Reason being, if you've ever dealt with DB9 cables, they come in two different formats. The really expensive ones come with the right pinout. The cheap ones from China come with the wrong pinout. So, this lets you select between both those pinouts. So, this lets you select between both those pinouts. I say the right pinout because it was actually set by CAN and automation like 20 years back. And for some reason, they don't conform to it. It also has a little termination resistor. So, if you're just testing like two of these or this and one other device, you can terminate the bus. Otherwise, nothing works. So, it's useful to be able to jumper select that. And yeah, DB9 connector on the end. Yeah, it was just mostly to say, hey, I want to put together something, make it open source. GitHub.com slash link layer. Has all the firmware, hardware design, everything you would need to put one of these together yourself. If you want, you can print your own board and build it. Cantact.io C-A-N-T-A-C-T is the actual website. I'm not allowed to get so I'm just going to stop right there. You can go learn more on that website. But yeah, the main goal was let's build an open source one. And the information's out there now for anybody here to go out and build a USB to CAN tool that speaks socket language. Can. Any other thoughts, questions, ramblings? I'll take anything, really. This was meant to be kind of quick and introductory. Not after market. I've worked with some OEMs, but not with this. It's a really divided world, the automotive one. OEMs, for example, work with the most expensive tools out there that cost more than everyone's You can get this for registration here combined times 10. Stuff like that. You were talking like five figures before you can get even a single CAN channel plus the software, plus the support, plus, plus, plus. The tuning guys, I'm guessing, are more into cheaper things and they need to get that out there. That could be interesting. But it's a pretty closed community from what I've seen. They don't want to talk about much. I don't know if you work in that. Yeah, okay. It would be interesting. We should talk, yeah. Because some people figure out secrets about how to make your car go faster and they want to not tell you that because they can make money off of selling that option. That's a business model, I guess. The automotive companies, of course, they're most interested in making your car as emissions friendly as possible nowadays. So that's why. The aftermarket guys can have some fun. We don't care about emissions now, let's just go for performance. And then suddenly your car behaves very differently. Any other stuff? Yeah. So, Oh, okay. So if you want to figure out what ECUs are talking to each other, the question was how do you figure out interactions between them. Oh, if you want to simulate an ECU. Okay. So it's hard. CAN is a totally multi-master bus and everything is sent to everybody. It's broadcast. So every message that's sent out could be received by every controller for all you know. You have no idea really how they act. The way you would find out is you get the DBC file, which is a CAN database from the manufacturer, which actually will say here are all of the nodes in the network, here is all the messages that every single one of them receives. The only problem is the manufacturer is not going to give that to you. Yeah. They're not going to give it to you. They'll make it available if you care to go down that road. So yeah, they just don't want you to know or they figure they can make money off keeping that information secret and selling it. So really the best way to figure out interactions between controllers is by trial and error nowadays. It's sort of, it sounds unfortunate but it's true. If you disconnect a controller from a CAN bus, a whole bunch of messages disappear so you know where those were coming from at least. You can also do things like fuzzing the CAN bus while it's running. Fuzzing in a real car can be kind of dangerous. I have a little story. I was talking about this at another conference. There was somebody from Continental in the audience and he was like, don't tell people to fuzz CAN. I said, okay, why not? He said, well, I'm not going to give you any details but you can actually destroy an engine by fuzzing the CAN bus while it's running. I was like, oh, I've seen it happen. I was like, oh, that sounds really bad. So you can do fuzzing but that gets to be somewhat problematic. You can actually potentially mess things up. In simulating, if you're doing V-CAN simulations, the easiest way to do it is you treat the V-CAN interface like a CAN bus and you just make everybody connect to it. You can also use it for piping messages around. I've seen at least one script that took messages from a real CAN interface, moved them to V-CAN doing some filtering and some reassignment of IDs and then moved them back to a different CAN interface. So that way, what often happens is you buy something from an OEM it only supports CAN ID 100 and 101 and they want to charge you like 10 grand to change it to 102 and 104 or whatever. So you put a device in the middle and you make it do that translation for you because it's cheaper. For stuff like that, V-CAN can be pretty useful. But in terms of actually knowing who's talking to who, unfortunately, CAN is pretty good at hiding that from you. Makes a lot of other stuff available though. Yep? Sure. So this is raw CAN. This is just the messages. This will do anything except CAN FD. For those higher level protocols, 1939, OBD2, Unified Diagnostic Services, which is ISO 14229, I think. Somebody? Yeah, I got it. For those, you're going to need some higher level software. There is support for all right, I have to back up. CAN supports 8 bytes per message. That's a little limiting if you're trying to send, let's say, a firmware update 8 bytes at a time. 15765-2. 15765-2. I'm bad with numbers. So that is the protocol that's used to basically say, I want to send 10 kilobytes over CAN. How do I string it all together? It'll do that. Then on top of that are the actual services for UDS. That middle part, which is called ISO TP, if you don't want to remember that number that Rob yelled out, that is actually implemented in the kernel space, but it's not included with the kernel and it's really hard to build. It's a lot of buts, I'm afraid. It would be really nice if it worked, but it doesn't. One thing I'm working on are some new open source software tools for doing the higher level protocols, but socket CAN itself is very raw. Give it 8 bytes, a data length code, and a message ID, and it will send a frame. That's about it. That's the silence. Are we good? You can find me after and ask me about anything, really. I'll be around here for a little while. Thanks a lot for listening about socket CAN. Hopefully it was of some interest and you can play around with it.