1 00:00:00,000 --> 00:00:09,600 So, today I'm just going to go through real quickly about the Vehicle Hacking Villages badge that is for sale this year. 2 00:00:10,760 --> 00:00:16,520 Basically, here's a picture of the badge that shows some of the features that the badge has. 3 00:00:19,620 --> 00:00:25,700 Basically, the hardware highlights are, you know, there are four independently controllable RGB LEDs. 4 00:00:25,700 --> 00:00:29,920 LEDs? I'm just talking to the microphone. I don't know if it's coming out here. 5 00:00:31,060 --> 00:00:36,760 Okay, so the story is, there's no projector, so you aren't going to be able to see anything that I'm talking about. 6 00:00:37,220 --> 00:00:40,200 But we have to record this so that DEF CON can put it online. 7 00:00:41,440 --> 00:00:48,100 So, if you want something, my opinion is, if you want to get something valuable out of it, just come over to the Automotive Hacking Village. 8 00:00:48,520 --> 00:00:52,280 I'm going to be doing this talk again this afternoon. I believe it's at 3 o'clock over there. 9 00:00:52,600 --> 00:00:54,240 I'll also be doing it tomorrow morning. 10 00:00:54,880 --> 00:00:55,240 But. 11 00:00:55,700 --> 00:00:57,440 I'll be over there all day, all day tomorrow. 12 00:00:57,620 --> 00:00:58,600 Just come and grab me. 13 00:00:58,680 --> 00:01:00,200 We can go through it. We can do an ad hoc. 14 00:01:00,360 --> 00:01:02,840 If everybody in here wants me to just do it right after this, we can. 15 00:01:03,400 --> 00:01:05,520 Right? Assuming that there's a free spot, we can do it. 16 00:01:06,520 --> 00:01:08,560 So, this is kind of like a technicality here. 17 00:01:09,680 --> 00:01:11,240 If there was a projector, you'd be able to see. 18 00:01:11,560 --> 00:01:14,620 So, can you guys hear the audio okay through this? 19 00:01:14,800 --> 00:01:15,100 Okay. 20 00:01:17,220 --> 00:01:19,940 So, basically, there are four independently controllable LEDs. 21 00:01:20,960 --> 00:01:25,480 There's a 128 by 128 color LCD on the badge. 22 00:01:25,980 --> 00:01:27,860 Along with two more push buttons. 23 00:01:28,420 --> 00:01:34,340 And then, as far as I.O. goes, there's a USB port that can be talked. 24 00:01:34,560 --> 00:01:35,620 And I'll talk about that later. 25 00:01:36,120 --> 00:01:39,240 There are two independent CAN channels on the badge. 26 00:01:40,400 --> 00:01:44,760 I also break out the single wire debug Cortex header. 27 00:01:45,340 --> 00:01:50,060 So, if one wanted to blank this and use it as kind of an evaluation board, feel free. 28 00:01:50,860 --> 00:01:53,740 And then, also, I provide some pin headers for native I.O. 29 00:01:54,360 --> 00:01:55,160 Most important. 30 00:01:55,160 --> 00:01:58,600 Go to carhackingvillage.com and get the SDK. 31 00:01:58,900 --> 00:02:01,100 The SDK has lots of documentation. 32 00:02:01,900 --> 00:02:08,400 I wanted to provide enough documentation this year so that, you know, you aren't forced to use Windows, for example. 33 00:02:08,540 --> 00:02:14,800 Let's say you wanted to use Linux and try to use the USB port, et cetera. 34 00:02:15,140 --> 00:02:20,840 I give you all the information about the protocols, the Windows tools that we're going to talk about coming up here. 35 00:02:21,160 --> 00:02:22,600 Use to program the badge. 36 00:02:22,800 --> 00:02:25,080 I gave the full source code for those. 37 00:02:25,580 --> 00:02:33,500 So, I wanted to try to make it easy for Linux users and Mac users to use the badge this year. 38 00:02:36,080 --> 00:02:39,700 Basically, the badge, in a nutshell, is fully scriptable. 39 00:02:40,880 --> 00:02:52,240 Basically, you don't need to, you know, write raw C code, per se, to control everything that you see on the badge and to have the badge do what you need it to do. 40 00:02:52,400 --> 00:02:55,120 So, the scripting language that I use, just like Lash, 41 00:02:55,160 --> 00:02:55,980 is called Pawn. 42 00:02:57,400 --> 00:02:58,400 It's C-like. 43 00:02:58,640 --> 00:02:59,480 It's interpreted. 44 00:03:00,200 --> 00:03:03,260 And it's designed to run very quickly in embedded targets. 45 00:03:05,600 --> 00:03:10,500 It's my opinion that it's easier to write than using, you know, traditional embedded C, et cetera. 46 00:03:11,300 --> 00:03:16,240 And here's some information here as far as where Pawn came from and who created it, et cetera. 47 00:03:16,340 --> 00:03:18,400 The documentation is excellent for the language, by the way. 48 00:03:20,660 --> 00:03:21,960 Some more nuts and bolts. 49 00:03:22,100 --> 00:03:25,140 And you can read into this more as you explore Pawn on your computer. 50 00:03:25,140 --> 00:03:28,420 It looks like C, but there are some weird things. 51 00:03:28,600 --> 00:03:29,580 Semicolons are optional. 52 00:03:30,700 --> 00:03:33,580 There's only one real type, and that's a cell. 53 00:03:35,800 --> 00:03:40,040 The other one out of here is, you know, there's really no linking phase. 54 00:03:41,360 --> 00:03:45,520 So, basically, you just chain multiple scripts together using Pawn includes. 55 00:03:46,940 --> 00:03:50,760 There aren't any prototypes for functions, et cetera. 56 00:03:54,100 --> 00:04:00,460 So, when you look at Pawn on the badge, basically, Pawn, by itself, is the interpreter. 57 00:04:00,680 --> 00:04:07,440 But there are libraries that Pawn comes with, much like how there are standard libraries with C, to do core operations. 58 00:04:08,640 --> 00:04:13,260 These things are basically implemented through what Pawn calls native extensions. 59 00:04:14,380 --> 00:04:20,740 So, basically, what that means is in the Pawn land, a function is called in the Pawn world. 60 00:04:20,760 --> 00:04:26,380 And that maps down to something that's been implemented in C on the target. 61 00:04:27,500 --> 00:04:31,000 So, you know, some of these standard libraries, there's stuff in there for strings. 62 00:04:31,140 --> 00:04:34,080 There's stuff in there for floating point operations, et cetera. 63 00:04:34,760 --> 00:04:37,880 Again, the SDK has all the documentation in it, if you get it. 64 00:04:39,620 --> 00:04:44,320 But, more importantly, the badge has a lot of native extensions that have been created by myself 65 00:04:44,320 --> 00:04:50,160 to do things like control the LCD, control the LEDs, manipulate the CAN bus, et cetera. 66 00:04:50,220 --> 00:04:50,740 And that's where the... 67 00:04:50,760 --> 00:04:53,060 That's where the real power comes in. 68 00:04:53,780 --> 00:04:56,360 So, of course, you have to start with the hello world. 69 00:04:57,860 --> 00:04:59,360 So, here it is in Pawn. 70 00:04:59,860 --> 00:05:02,440 Looks a lot like C, as you can tell. 71 00:05:03,460 --> 00:05:08,380 Some of the more syntactic stuff, like, you know, main's not returning a type. 72 00:05:08,480 --> 00:05:10,200 It's not accepting any arguments. 73 00:05:10,440 --> 00:05:11,660 You don't have to put void in there. 74 00:05:11,800 --> 00:05:14,640 There's no semicolon after the printf, et cetera. 75 00:05:14,740 --> 00:05:17,900 But, you know, this script will run on the badge. 76 00:05:19,180 --> 00:05:20,740 And, you know, when using the badge, 77 00:05:20,740 --> 00:05:21,220 when you're using the right tools, 78 00:05:21,340 --> 00:05:23,860 you will see hello world come out of the console. 79 00:05:26,120 --> 00:05:28,040 So, as I mentioned before, the SDK. 80 00:05:29,280 --> 00:05:29,960 Download it. 81 00:05:30,120 --> 00:05:32,040 There's tons of great information in there. 82 00:05:32,240 --> 00:05:34,840 I think you'll find that it's incredibly easy to customize the badge. 83 00:05:34,960 --> 00:05:37,840 Even if you don't use the badge for doing CAN bus stuff, 84 00:05:39,460 --> 00:05:41,260 the tools that I provide, et cetera, 85 00:05:41,420 --> 00:05:44,980 let's say you just wanted the lights to change colors differently, 86 00:05:45,100 --> 00:05:47,140 or you wanted to put your own bitmaps on the LCD, 87 00:05:48,140 --> 00:05:50,480 should be incredibly easy for you to do that. 88 00:05:50,620 --> 00:05:57,300 So, I'm really excited to see how people customize this badge 89 00:05:57,300 --> 00:05:59,020 once they start getting into this SDK, 90 00:05:59,240 --> 00:06:04,060 because I think this year I tried to make the badge as accessible as possible. 91 00:06:04,620 --> 00:06:10,000 Last year it was accessible, but you needed an FTDI, you know, USB to UR converter. 92 00:06:10,260 --> 00:06:11,380 It was a little clunky. 93 00:06:11,740 --> 00:06:15,520 This year, in my opinion, it's very streamlined. 94 00:06:16,220 --> 00:06:17,120 There are lots of options. 95 00:06:17,120 --> 00:06:17,780 There are lots of examples. 96 00:06:17,900 --> 00:06:25,720 In fact, what the badge does right out of the box with the LEDs and the bitmaps being shown, 97 00:06:26,000 --> 00:06:29,620 that's a script that's in the include or in the example files as well. 98 00:06:29,740 --> 00:06:32,180 So, you could go in and just modify that if you wanted to change something. 99 00:06:34,800 --> 00:06:35,420 Compiling scripts. 100 00:06:35,680 --> 00:06:37,380 We'll talk about this a little bit more at the Village, 101 00:06:37,520 --> 00:06:41,900 and there are lots of readmes in the SDK on how to do this. 102 00:06:42,180 --> 00:06:46,680 But, basically, you invoke a binary called PawnCC. 103 00:06:47,120 --> 00:06:48,000 And you pass it your script. 104 00:06:48,340 --> 00:06:52,100 And out from that comes an AMX file. 105 00:06:52,220 --> 00:06:57,140 That's basically Pawn's intermediate compiled bytecode. 106 00:06:58,400 --> 00:07:01,980 Then, also in the SDK, there's a utility that I call qcm.exe 107 00:07:02,540 --> 00:07:06,480 that basically talks to the badge and loads the AMX file. 108 00:07:06,800 --> 00:07:10,160 So, this is a .NET application. 109 00:07:10,480 --> 00:07:11,200 It's a Windows application. 110 00:07:11,980 --> 00:07:15,020 It's very, I think, pretty intuitive to use. 111 00:07:15,160 --> 00:07:16,700 I mean, there are two buttons at the top of it. 112 00:07:16,700 --> 00:07:17,660 One says load script. 113 00:07:17,920 --> 00:07:18,800 So, you click on script. 114 00:07:19,200 --> 00:07:21,000 And you click on load script. 115 00:07:21,220 --> 00:07:22,580 You point it at the AMX file. 116 00:07:22,780 --> 00:07:23,140 Kaboom. 117 00:07:23,160 --> 00:07:24,100 Down to the badge it goes. 118 00:07:24,220 --> 00:07:24,980 And it instantly runs. 119 00:07:26,520 --> 00:07:30,700 Again, as I mentioned before, to help non-Windows users out, 120 00:07:30,840 --> 00:07:33,780 I've included the full source code for this application in the SDK 121 00:07:34,500 --> 00:07:38,900 with the intention of somebody being able to easily see how to talk to the badge 122 00:07:38,900 --> 00:07:41,980 by analyzing that source code and then creating something else, 123 00:07:42,000 --> 00:07:43,860 either a different script, 124 00:07:43,860 --> 00:07:49,920 potentially a Python script or a Perl script or something like that on Linux. 125 00:07:52,320 --> 00:07:55,460 So, with Pawn, one of the biggest powers, 126 00:07:55,520 --> 00:07:56,820 I'm just going to go through this really quickly, 127 00:07:56,960 --> 00:07:58,400 there's this concept of event handlers. 128 00:07:58,540 --> 00:08:01,280 And this is what makes Pawn so powerful in the badge 129 00:08:01,780 --> 00:08:09,140 because think of it as there are asynchronous callbacks that occur in the interpreter. 130 00:08:09,580 --> 00:08:12,100 So, they're kind of like interrupt service routines. 131 00:08:13,780 --> 00:08:18,480 Or something like that to where when events happen outside of the interpreter, 132 00:08:19,060 --> 00:08:20,740 these routines are instantly called. 133 00:08:20,880 --> 00:08:24,800 So, this lends itself very nicely to handling like timer expirations 134 00:08:24,800 --> 00:08:29,960 or a CAN message has arrived for a particular filter on a particular channel, 135 00:08:30,160 --> 00:08:31,400 et cetera, et cetera. 136 00:08:31,700 --> 00:08:32,860 Look at the examples. 137 00:08:33,000 --> 00:08:35,060 You'll see a lot of what I'm talking about. 138 00:08:36,060 --> 00:08:36,580 Timers. 139 00:08:37,420 --> 00:08:38,800 Again, look at the SDK. 140 00:08:38,940 --> 00:08:41,020 But I basically go through here 141 00:08:41,020 --> 00:08:43,900 and show a little bit about how timers are set up. 142 00:08:44,140 --> 00:08:45,700 You can see it's a very small script 143 00:08:45,700 --> 00:08:49,660 to kick a timer off that expires after 250 milliseconds. 144 00:08:50,040 --> 00:08:51,440 In main, we start the timer 145 00:08:51,440 --> 00:08:53,640 and we have this callback that starts with the at sign 146 00:08:53,640 --> 00:08:55,540 that where the timer expires, 147 00:08:55,640 --> 00:08:59,320 we're going to get something out of the console that says timer expired. 148 00:09:02,940 --> 00:09:03,980 Console routines. 149 00:09:04,120 --> 00:09:07,340 This example basically shows 150 00:09:07,920 --> 00:09:10,800 what happens when data is received over USB 151 00:09:11,380 --> 00:09:12,740 from the Windows PC. 152 00:09:13,160 --> 00:09:14,900 It basically calls a, say, 153 00:09:14,900 --> 00:09:16,420 circuitous callback called host RX. 154 00:09:16,660 --> 00:09:17,740 It passes the data. 155 00:09:17,840 --> 00:09:20,200 And all this example does is just print the data out 156 00:09:20,200 --> 00:09:21,600 in hexadecimal format. 157 00:09:23,380 --> 00:09:24,200 CAN interfaces. 158 00:09:24,560 --> 00:09:29,980 So, again, look at the SDK for this to really dig into it. 159 00:09:30,160 --> 00:09:31,220 I'll go to the example. 160 00:09:31,860 --> 00:09:34,560 If we look at the main routine at the bottom again, 161 00:09:34,760 --> 00:09:38,700 we initialize the CAN channel to 500 kilobits. 162 00:09:38,800 --> 00:09:40,800 We configure a filter. 163 00:09:41,420 --> 00:09:42,820 For that channel, 164 00:09:43,040 --> 00:09:47,860 let's say it's the filters at 7 E0 hex is the CAN ID. 165 00:09:48,340 --> 00:09:50,680 And in the same way as the previous example, 166 00:09:51,280 --> 00:09:56,240 whenever we receive a message for this CAN channel and this filter, 167 00:09:56,420 --> 00:09:59,540 we get this callback that starts with the at sign. 168 00:09:59,720 --> 00:10:01,060 And in this example, 169 00:10:01,140 --> 00:10:02,700 what we do is we print that data out, 170 00:10:02,780 --> 00:10:05,560 but we also transmit the same message out 171 00:10:05,560 --> 00:10:09,120 using QCM CAN TX on a different CAN channel. 172 00:10:09,200 --> 00:10:10,800 So this example kind of shows 173 00:10:10,800 --> 00:10:12,100 a real rudimentary gateway. 174 00:10:12,440 --> 00:10:13,900 We're receiving 7 E0, 175 00:10:14,400 --> 00:10:16,800 and we're forwarding on a different CAN channel, 176 00:10:16,900 --> 00:10:18,920 7 E8, for example. 177 00:10:21,020 --> 00:10:22,220 I'm not going to spend a lot of time 178 00:10:22,220 --> 00:10:24,120 on the state machine stuff. 179 00:10:24,360 --> 00:10:25,700 Lots of examples to look at. 180 00:10:27,060 --> 00:10:28,580 Again, the badge PON specifics. 181 00:10:28,880 --> 00:10:31,080 This is also in readmes in the SDK. 182 00:10:33,340 --> 00:10:35,640 Basically, this is talking about some of the limitations 183 00:10:35,640 --> 00:10:38,320 of the badge stuff and also some of the stuff 184 00:10:38,320 --> 00:10:39,460 that is in the badge. 185 00:10:41,040 --> 00:10:41,960 As I mentioned, 186 00:10:42,040 --> 00:10:43,120 look at the examples folder. 187 00:10:44,040 --> 00:10:46,020 I've included all of the PON documentation 188 00:10:46,020 --> 00:10:48,800 that's available on this PON website in there as well. 189 00:10:49,300 --> 00:10:52,380 But if you want to look at it more in depth, 190 00:10:52,480 --> 00:10:54,740 feel free to look at the website. 191 00:10:56,680 --> 00:10:58,180 And here's my email address 192 00:10:58,180 --> 00:10:59,780 if you want to contact me. 193 00:10:59,940 --> 00:11:01,880 Feel free to contact me any time about PON, 194 00:11:02,000 --> 00:11:02,380 the badge, 195 00:11:03,700 --> 00:11:05,440 other systems that I make 196 00:11:05,440 --> 00:11:07,920 that basically use this system 197 00:11:07,920 --> 00:11:09,460 that are more robust, etc. 198 00:11:10,800 --> 00:11:11,800 I welcome the comments 199 00:11:11,800 --> 00:11:15,300 and look forward to any questions. 200 00:11:15,660 --> 00:11:17,160 With that, thank you very much.