1 00:00:04,920 --> 00:00:06,740 All right, it's 1.30. 2 00:00:08,580 --> 00:00:10,760 Thanks for coming to my talk about Mesh-tastic. 3 00:00:10,760 --> 00:00:12,240 We're going to go really low level. 4 00:00:12,480 --> 00:00:21,780 You can see on the screen right now we have chirps being captured on one side, on the right, and chat messages and node infos coming out on the left here. 5 00:00:21,780 --> 00:00:25,760 So I'll explain how I got to this state, how we got this working, or how I got this working. 6 00:00:26,420 --> 00:00:27,860 Let's stop this for a moment. 7 00:00:32,340 --> 00:00:35,360 All right, so just real quickly first, what is Mesh-tastic? 8 00:00:35,360 --> 00:00:39,380 Probably most of you who are here probably know this, so I'm going to go a bit faster these first few slides. 9 00:00:39,460 --> 00:00:43,460 But if you don't know, it's an off-grid, multi-mile, low-power Mesh network. 10 00:00:43,560 --> 00:00:47,140 Low power and it's very resilient to noise. 11 00:00:47,160 --> 00:00:49,900 You can send messages below the noise floor. 12 00:00:50,580 --> 00:00:52,480 It doesn't rely on any infrastructure. 13 00:00:52,600 --> 00:00:57,860 Basically, you would install an app on your phone, relay over to a little device, like such a device. 14 00:00:57,860 --> 00:01:06,140 I have a tiny one here, fits in your pocket or your backpack, and then that sends the message out a couple of miles using this technology called LoRa. 15 00:01:06,160 --> 00:01:10,240 It's able to transmit fairly far at very low power. 16 00:01:10,360 --> 00:01:18,880 And then with this Mesh-tastic app layer on top, that retransmits the message a couple of times, a couple of hops, to get your message pretty far. 17 00:01:20,080 --> 00:01:22,420 It's open source and has a lot of community momentum. 18 00:01:22,420 --> 00:01:25,160 That's what I like about it, and I think a lot of people like about it. 19 00:01:26,700 --> 00:01:29,880 Just to give a taste, this is the Android app. 20 00:01:29,880 --> 00:01:30,440 It's what it looks like. 21 00:01:30,440 --> 00:01:31,540 Just a chat app. 22 00:01:31,580 --> 00:01:35,800 It has a bunch of other features I'm not that interested in, but it can do a lot of stuff. 23 00:01:39,600 --> 00:01:43,460 The next slide will be about what you probably need to know for this to make sense. 24 00:01:43,980 --> 00:01:49,040 Then I'll go deep in this technology LoRa, this technology underlying Mesh-tastic. 25 00:01:50,120 --> 00:01:52,660 How it's modulated, how it's encoded, how to decode it. 26 00:01:52,660 --> 00:01:57,720 And then I'm going to go deep in how Mesh-tastic, the layer on top, is encoded and decoded. 27 00:01:57,860 --> 00:02:00,180 I'm going to be using, I'm going to be demoing a lot. 28 00:02:00,420 --> 00:02:05,520 Different software, GQRX and Spectrum to zoom in really far, GQRX to capture. 29 00:02:05,520 --> 00:02:08,260 GNU Radio to do some more actual decoding. 30 00:02:08,660 --> 00:02:13,980 Wireshark because it's useful to look at individual bytes and see what byte means what in what packet. 31 00:02:14,400 --> 00:02:16,820 And Python to glue it all together. 32 00:02:18,340 --> 00:02:23,420 So Prereqs, this is not like an intro talk to RF and software-defined radio. 33 00:02:24,200 --> 00:02:26,240 I'm not really going to go over the basics of GNU Radio. 34 00:02:26,240 --> 00:02:28,740 You probably need to know a little bit of GNU Radio for it to make sense. 35 00:02:29,680 --> 00:02:35,340 That said, you'll still get the gist of most of it, I'd say, even if you don't. 36 00:02:35,820 --> 00:02:38,700 Packet formats, it should probably not be your first time seeing Wireshark. 37 00:02:38,700 --> 00:02:40,500 That wouldn't make much sense either. 38 00:02:41,100 --> 00:02:48,760 Protobufs, Google's very efficient format for serializing structured data into bytes in a binary format. 39 00:02:49,260 --> 00:02:51,100 So that's pretty much all we need to know about that. 40 00:02:51,100 --> 00:02:53,080 It's a serialization format. 41 00:02:54,320 --> 00:03:05,860 Hardware I'm going to be using, I'm going to be using one of these T1000s, but there are a lot of other Meshtastic devices or LoRa devices that can run Meshtastic firmware. 42 00:03:06,380 --> 00:03:08,600 I like this one because it fits in your pocket. 43 00:03:10,880 --> 00:03:15,940 Eric yesterday was giving a really good talk about that, so you can see the recording for that if you want to see all the different types of devices that exist. 44 00:03:15,940 --> 00:03:17,100 He has all of them, I think. 45 00:03:18,660 --> 00:03:24,600 I'm going to be using the HackRF, Software Defined Radio Receiver or Transceiver. 46 00:03:25,200 --> 00:03:27,900 You could probably use a really cheap RTL-SDR as well. 47 00:03:27,900 --> 00:03:30,440 I didn't get time to try, actually, but I think you could. 48 00:03:30,440 --> 00:03:33,980 What I'm doing here doesn't really require such a fancy SDR, actually. 49 00:03:34,180 --> 00:03:38,740 And then I'm going to be, because I'm going to be transmitting a little bit at the end, I didn't get time to transmit through the HackRF. 50 00:03:38,740 --> 00:03:41,840 It is probably possible, but it would take a lot more effort. 51 00:03:41,840 --> 00:03:46,640 So I'm just transmitting through a really simple Arduino with a LoRa chip built in. 52 00:03:46,680 --> 00:03:51,680 I'll show you that at the end, but you can get these on Amazon for real cheap as well. 53 00:03:53,120 --> 00:03:54,480 So what is LoRa? 54 00:03:54,480 --> 00:03:58,780 So LoRa is a radio modulation and encoding system. 55 00:03:58,800 --> 00:04:03,320 It's a closed source technology by this company called Semtech. 56 00:04:03,320 --> 00:04:06,020 And the primary use is for LoRaWAN. 57 00:04:06,340 --> 00:04:16,980 So LoRaWAN is like a commercial, or rather, I guess you could call it a commercial system, where it's more like a traditional cell system. 58 00:04:16,980 --> 00:04:20,380 You'd have base stations that are connected to the internet then. 59 00:04:20,380 --> 00:04:27,500 So your LoRa devices reach base stations, and then that relays the thing onto the internet. 60 00:04:27,660 --> 00:04:46,300 So IoT device manufacturers, for example, that's I think the primary use case, can use this as an alternative to LTE or other cell technologies to have a low power, like low bandwidth, low power, really cheap way of connecting IoT devices through these base stations out to the internet. 61 00:04:46,300 --> 00:05:01,060 So manufacturers, all they have to do is use some LoRaWAN API on their server side, on the internet side, to receive packets or send packets, and then some SDK to put on their IoT devices to communicate to the internet through LoRa. 62 00:05:01,060 --> 00:05:03,080 So it's just kind of a hop to the internet. 63 00:05:03,700 --> 00:05:05,560 That's what LoRaWAN is. 64 00:05:06,000 --> 00:05:07,680 That's not what Meshtastic does, though. 65 00:05:07,680 --> 00:05:21,100 Meshtastic just uses the physical layer, not LoRaWAN, just LoRa, which is just the physical layer, and they use it to peer-to-peer messages between nodes and relay them on in this mesh fashion. 66 00:05:22,760 --> 00:05:25,520 So real quick recap of common modulations. 67 00:05:25,520 --> 00:05:34,160 Like I said, it's not like a beginner's R, but just to recap, AM modulation, so you might have some, let's say, 900 MHz signal. 68 00:05:34,540 --> 00:05:43,040 You might make it stronger, weaker, stronger, weaker in some wave, a 400 Hz wave, for example, if you're modulating an audible tone. 69 00:05:43,040 --> 00:05:44,640 So that would be amplitude modulation. 70 00:05:44,860 --> 00:05:50,260 You might turn it on and off, on and off, if you're modulating, if you're trying to encode a digital signal in this fashion. 71 00:05:50,360 --> 00:05:52,160 So amplitude shift keying. 72 00:05:52,960 --> 00:06:00,480 You might make the frequency higher, lower, like 400 times per second if you were modulating a tone. 73 00:06:00,680 --> 00:06:12,120 If you were modulating something digital with frequency shifting, you might make the frequency higher for some time, lower for some time, higher for some time, to encode ones and zeros. 74 00:06:12,280 --> 00:06:13,440 So that's a quick recap. 75 00:06:13,960 --> 00:06:18,320 So LoRa uses a really different modulation, which is very clever. 76 00:06:19,380 --> 00:06:20,740 I've seen different names for it. 77 00:06:20,740 --> 00:06:23,020 Chirp Spread Spectrum is one name. 78 00:06:23,520 --> 00:06:25,820 Frequency Shift Chirp Modulation is another name. 79 00:06:25,820 --> 00:06:28,020 I thought that was a pretty well-descriptive name. 80 00:06:28,260 --> 00:06:41,440 So the first way you can think of it is there's some frequencies, like in frequency shift modulation, but they're moving from some frequency and then gradually up, and then down to that frequency and up. 81 00:06:41,440 --> 00:06:42,840 So it's these chirps, like up, up, up. 82 00:06:42,840 --> 00:06:45,400 We'll see it in a different format later. 83 00:06:45,800 --> 00:06:51,220 The illustration here is in what we call a time domain, right? 84 00:06:51,220 --> 00:06:52,960 This is what the wave would look like. 85 00:06:52,960 --> 00:06:56,260 Wave gets shorter and shorter and shorter, higher and higher frequency. 86 00:06:56,340 --> 00:06:59,620 We can also look at it in the FFT plot style. 87 00:06:59,620 --> 00:07:00,600 We'll do that later. 88 00:07:01,080 --> 00:07:07,620 But chirps, so tones rising, rising, rising, and then I'll show you how you can encode data in that. 89 00:07:08,280 --> 00:07:09,380 And why is this good? 90 00:07:09,380 --> 00:07:15,460 Because with frequency shift keying, you're sending on one frequency for a bit and then another on a bit. 91 00:07:15,460 --> 00:07:17,980 But while you're on this one frequency, you might get a lot of noise. 92 00:07:17,980 --> 00:07:19,880 You might get buried in the noise. 93 00:07:20,160 --> 00:07:24,420 The signal would easily drown out in other types of modulation. 94 00:07:24,420 --> 00:07:28,000 This type of modulation is very resilient to drowning out. 95 00:07:28,140 --> 00:07:35,860 It can work below the noise floor, which is still hard for me to comprehend, but I'll tell you later of a video where the guy explains it really well. 96 00:07:36,400 --> 00:07:37,520 I'll leave it at that. 97 00:07:38,580 --> 00:07:40,480 All right, so let's do some demoing. 98 00:07:40,480 --> 00:07:41,600 Let's capture a chirp. 99 00:07:44,880 --> 00:07:46,560 So I'm using the HackRF. 100 00:07:48,900 --> 00:07:58,580 I'm going to use the software called GQRX, which is a software-defined radio, kind of just like an explorer, a viewer, and recorder. 101 00:07:58,580 --> 00:07:59,340 And that's what I'm going to be doing. 102 00:07:59,340 --> 00:08:00,340 I'm going to be recording. 103 00:08:00,580 --> 00:08:05,000 So what we already see here is 917 megahertz, a bunch of stuff going on. 104 00:08:05,000 --> 00:08:13,080 Now, that's the DEF CON configuration that most people here are probably running, like LORAC or Meshtastic configuration. 105 00:08:13,160 --> 00:08:14,140 It's called... 106 00:08:14,140 --> 00:08:17,000 there's some different modem settings you can have in Meshtastic. 107 00:08:17,000 --> 00:08:18,940 You can have different frequencies and so on. 108 00:08:19,520 --> 00:08:29,260 Meshtastic has some presets, and the preset that the DEF CON Meshtastic configuration recommends is running around 917 megahertz. 109 00:08:29,260 --> 00:08:31,840 So that's why we're seeing a bunch of stuff going on up there. 110 00:08:32,240 --> 00:08:34,380 The preset is called short turbo. 111 00:08:34,380 --> 00:08:37,260 Because it's turbo, it's really hard to view. 112 00:08:37,260 --> 00:08:45,280 So I'm going to transmit on the medium slow preset, which is what we use in the Bay Area mostly. 113 00:08:46,900 --> 00:08:48,580 It's just popular there. 114 00:08:48,760 --> 00:08:52,080 So that... well, you know, different presets are more resilient to different things. 115 00:08:52,080 --> 00:08:58,100 Some have longer range, but take more time so you don't have as high bandwidth. 116 00:08:58,160 --> 00:09:07,160 I guess the DEF CON, the folks who came up with the configuration for DEF CON decided we need the short ones because it doesn't take up much time on air, so there's so many messages going around. 117 00:09:07,160 --> 00:09:10,960 We want there to be enough room for all messages to not step on each other. 118 00:09:13,140 --> 00:09:15,980 All right, so I'm on my phone getting up now in the Meshtastic app. 119 00:09:15,980 --> 00:09:18,440 I'm just going to send one message here. 120 00:09:18,460 --> 00:09:20,120 Okay, we saw my message here. 121 00:09:20,120 --> 00:09:24,600 I'm sending on medium slow, so that's a different frequency, like around 915 megahertz. 122 00:09:24,600 --> 00:09:26,580 And it got retransmitted because nobody acted. 123 00:09:26,580 --> 00:09:28,040 Let me move them a little bit away. 124 00:09:28,320 --> 00:09:30,540 These are the transmitters. 125 00:09:30,540 --> 00:09:33,480 I'll just move them away from the antenna so it doesn't blast so loud. 126 00:09:35,660 --> 00:09:37,600 And this time I'm going to record. 127 00:09:40,180 --> 00:09:43,360 So I'm going to try to time it because the recordings are really big. 128 00:09:43,360 --> 00:09:48,760 It's like we're looking at 8 megahertz of bandwidth here, and it's like 100 megabytes a second or something. 129 00:09:48,760 --> 00:09:54,000 So I'm just going to record for just a second when I press send. 130 00:09:56,320 --> 00:09:57,740 Okay, I got it. 131 00:09:58,100 --> 00:10:01,660 So I'm stopping the program. 132 00:10:01,660 --> 00:10:02,540 I got this down here. 133 00:10:02,540 --> 00:10:03,260 I pressed record. 134 00:10:03,260 --> 00:10:04,280 I got this file. 135 00:10:04,420 --> 00:10:07,140 We're going to look at that now in a tool called InSpectrum. 136 00:10:07,140 --> 00:10:08,620 I'm going to launch that. 137 00:10:13,620 --> 00:10:17,380 So the reason I like this tool is you can zoom in really well. 138 00:10:27,160 --> 00:10:28,280 Here we go. 139 00:10:28,300 --> 00:10:30,880 So I had offset. 140 00:10:30,960 --> 00:10:34,120 I didn't center it around the tuned frequency. 141 00:10:34,120 --> 00:10:37,580 There's some limitations of the HackerRF, so I offset it by 1 megahertz. 142 00:10:37,580 --> 00:10:41,560 That's why we're seeing it centered around 1 megahertz here. 143 00:10:41,840 --> 00:10:48,500 And if you notice, this is, when I saw this, oh, now I understand why the Mishtastic logo is these kind of waves up and down. 144 00:10:48,700 --> 00:10:51,500 That's what the modulation looks like when you visualize it. 145 00:10:55,470 --> 00:10:58,550 So let's see what next I want to show here. 146 00:10:59,110 --> 00:11:04,550 Yeah, I think what I'll show now is this tool, InSpectrum, you can choose, you can enable a grid. 147 00:11:04,750 --> 00:11:05,810 Let's do that. 148 00:11:06,190 --> 00:11:15,570 Just to kind of help you analyze what's going on, let's set it at, I just want a grid with four lines, and I'll try to align that. 149 00:11:15,570 --> 00:11:17,450 Okay, that's pretty well aligned almost. 150 00:11:17,790 --> 00:11:18,170 There we go. 151 00:11:18,170 --> 00:11:19,930 Align that at these up chirps. 152 00:11:20,770 --> 00:11:23,450 So each up chirp, each chirp here is a symbol. 153 00:11:24,030 --> 00:11:27,010 And let's move a little around. 154 00:11:27,170 --> 00:11:29,750 At the beginning, there's some, I'll come back to actually how the structure is. 155 00:11:29,750 --> 00:11:31,650 There's some up chirps, there's some down chirps. 156 00:11:31,650 --> 00:11:36,470 But now we got, like, from the up chirps in the beginning, we could see the width of each symbol. 157 00:11:36,890 --> 00:11:39,890 So now I have my grid, like, set up right for that width. 158 00:11:40,750 --> 00:11:43,650 And then there's two and a quarter down chirps. 159 00:11:43,650 --> 00:11:45,090 I'll tell more about that later. 160 00:11:45,190 --> 00:11:46,830 And then there's a bunch of up chirps. 161 00:11:46,830 --> 00:11:49,250 Let's actually, let's go here. 162 00:11:49,250 --> 00:11:50,450 It's more interesting. 163 00:11:50,530 --> 00:11:51,210 Yeah, okay. 164 00:11:51,210 --> 00:11:58,630 So the intuition here is when you've aligned this right, you can see where these up chirps start and then wrap around. 165 00:11:59,030 --> 00:11:59,910 This is a good one. 166 00:11:59,910 --> 00:12:05,530 It starts kind of in the middle, goes to the top, and then wraps around, goes up there, goes up to where it started. 167 00:12:06,850 --> 00:12:11,230 So this starting position, the intuition here is the starting position is the symbol. 168 00:12:11,290 --> 00:12:14,230 So we're trying to send numbers here, right, at the end of the day. 169 00:12:14,430 --> 00:12:22,170 So maybe the number we were sending, if bottom is, let's say, 100, top is, sorry, bottom is zero, top is 100, then maybe this is the number 80. 170 00:12:22,270 --> 00:12:23,950 This is maybe, I don't know, 79. 171 00:12:23,970 --> 00:12:26,190 And this might be the number 40 or 30. 172 00:12:26,190 --> 00:12:29,690 And this might be number 20, and so forth. 173 00:12:29,690 --> 00:12:34,330 So that's how the encoding works intuitively, like at a high level. 174 00:12:38,180 --> 00:12:43,800 All right, so we had these, we saw many just up chirps in the beginning. 175 00:12:43,800 --> 00:12:54,140 Those are the preamble, and those are used by the radios to synchronize, to figure out what's this beginning, like how, not so much how wide they are, that's pre-configured, but more where does each one start. 176 00:12:54,140 --> 00:12:59,660 And then after that, it knows kind of how to align its grid like I was doing manually. 177 00:12:59,920 --> 00:13:11,200 There's a sync word, there's like a specific thing, a specific symbol that's encoded at the beginning of the transmission for radios to know was this part of the application they're using. 178 00:13:11,200 --> 00:13:20,020 So like Meshtastic uses symbol, like one byte symbol, 2B, to indicate that this transmission was a Meshtastic transmission. 179 00:13:20,160 --> 00:13:27,140 Then there are these two and a quarter down chirps to show that the preamble has ended and now the actual payload is coming. 180 00:13:27,260 --> 00:13:31,980 So everything after that are symbols that are the actual Meshtastic data. 181 00:13:33,260 --> 00:13:35,240 So let me go back here and look. 182 00:13:35,940 --> 00:13:46,500 So we saw all these up chirps, the preamble, and actually the last two of them are a little bit off, it's hard to see, but this is supposed to encode the symbol 2B, I believe. 183 00:13:46,500 --> 00:14:00,740 Though there is some open issue right now with some of these chips, some of the firmers are doing something slightly wrong about the sync word, so it could also be that they're all just zeros here, but it's like 000 and then supposed to be 2B in these last couple of chirps, 184 00:14:00,740 --> 00:14:07,820 and then two and a quarter down chirps, and then from here, after the quarter down chirp, our actual payload begins. 185 00:14:11,120 --> 00:14:13,400 All right, so let's see, how are we on time? 186 00:14:13,780 --> 00:14:33,280 Okay, so a useful property of chirps is that you can get them to almost be like frequency shift keying, if you have your up chirp and you multiply it, like complex multiply it by a down chirp, you kind of translate the up chirp down, that flattens it, 187 00:14:33,280 --> 00:14:38,480 so it becomes like, if you have this symbol, an up chirp, this down chirp, you get a flat line. 188 00:14:38,640 --> 00:14:52,520 So if you have this discontinued, like this broken one, up chirp here, then you know the first bit will get pulled down to here, and the second bit would get pulled up to here, so you would get a straight line, like frequency shift keying. 189 00:14:52,520 --> 00:15:12,480 So that makes it easy, in the end you just, like in your radio receiver, in your decoder, you just multiply all of these, all the up chirps, or the received chirps, with the opposite chirp, and that gives you just like a single frequency, so you can just do a Fourier transform on that to figure out where, 190 00:15:12,480 --> 00:15:16,780 like which was the dominant frequency in this time span, in this chirp. 191 00:15:16,780 --> 00:15:33,720 Here's a little animation then showing how we could be sweeping over different symbols we're sending, and then when you combine that with a down chirp, we would get this, we've de-chirped it and turned it into just a straight line, and it's basically then normal frequency shift keying encoding from there, 192 00:15:33,720 --> 00:15:35,900 somewhat, there's more to it. 193 00:15:37,680 --> 00:15:54,040 Oh, and a clever thing about the preamble, I thought this was really interesting at least, like how does the radio synchronize, how does it know, like, are we at the right place now, like have we positioned ourselves at the beginning of the chirp, or are we kind of offset? 194 00:15:54,200 --> 00:15:55,420 So how does it do that? 195 00:15:55,420 --> 00:16:04,920 Well, turns out, you can just put the grid anywhere, the radio can just assume some random synchronization, let's say it assumed here, right in the middle, right? 196 00:16:05,040 --> 00:16:19,020 So it would still be getting the same symbol, if this is 0, this is 100, then it would be getting 50, 50, 50, 50, so the radio just sees, when I got the same symbol many times in a row, 50, 50, 50, 50, then I know I'm in a preamble, and the symbol was 50, 197 00:16:19,020 --> 00:16:21,640 then I know I need to move it this much back. 198 00:16:22,900 --> 00:16:24,500 That's how it synchronizes, right? 199 00:16:24,500 --> 00:16:37,440 So it's actually, I can imagine how they've implemented the syncing in that fashion, by looking for repeated symbols, getting that symbol that was repeated, and then translating the synchronization window back to the right position. 200 00:16:40,200 --> 00:16:54,060 This talk is really good, it goes really deep, and he does experiments in MATLAB showing why and how LoRa works below the noise floor, and highly recommended for the demodulation part, he goes really deep. 201 00:16:54,120 --> 00:16:55,980 Visual Electric, it's on YouTube. 202 00:16:57,200 --> 00:17:04,900 You can, oh, I should mention my slides here are on my GitHub, so you can go and click the links from there. 203 00:17:05,840 --> 00:17:09,420 Okay, encoding, so I think I've got to move a bit faster now. 204 00:17:09,420 --> 00:17:13,680 So we've talked about modulation so far, right? 205 00:17:13,680 --> 00:17:16,600 We're getting from radio signals into some kind of numbers. 206 00:17:16,600 --> 00:17:18,320 So what happens with these numbers? 207 00:17:18,320 --> 00:17:21,080 Well, let's talk first about what would happen when we're sending, right? 208 00:17:21,080 --> 00:17:25,420 So first, it adds a cyclic redundancy check, it adds some error detection, right? 209 00:17:25,420 --> 00:17:31,340 A hash, just a couple of bytes at the end, just to see, like, did the end result turn out right? 210 00:17:31,440 --> 00:17:51,660 It does what's called whitening, so that's, like, it just combines with a known sequence of not random, but pseudo random numbers, so every radio would get the same sequence, but the sequence, like, doesn't have any repeated long run of zeros, so that ensures that there will be nothing like the preamble anywhere in the payload, 211 00:17:51,660 --> 00:17:55,400 because then we wouldn't be able to, you know, then the preamble isn't that unique, right? 212 00:17:55,400 --> 00:18:00,080 So the payload could never contain this repeated sequence of zeros. 213 00:18:00,300 --> 00:18:11,980 Then it does some forward error correction, it adds some extra bits that it could use to fix if there are errors, like, it can, yeah, do error correction, I'll leave it at that. 214 00:18:11,980 --> 00:18:28,520 It does interleaving, so it spreads bits from your individual bytes over different symbols, because then that way, if one symbol was slightly misread, then maybe we haven't lost a whole chunk of bytes at least, so that way we can better recover later. 215 00:18:28,920 --> 00:18:35,180 So, like, maybe the forward error correction will help us recover if just, like, one of the symbols were a bit off. 216 00:18:35,180 --> 00:18:37,840 And then gray coding, so that reduces the impact of errors. 217 00:18:37,840 --> 00:18:47,560 Gray coding is kind of like binary encoding, but numbers that are close to each other have fewer, have not very many bytes apart, sorry, bits apart. 218 00:18:47,660 --> 00:18:50,600 This is because, like, you might misread the signal slightly. 219 00:18:50,600 --> 00:18:56,000 If it was with binary, there'd be a big difference between the number 63 and 64. 220 00:18:56,000 --> 00:18:57,340 Like, there's a lot of bits that are different, right? 221 00:18:57,340 --> 00:19:01,240 So if you misread it slightly, you'd be completely off, like, your bits would be completely off. 222 00:19:01,240 --> 00:19:06,600 With gray coding, you might still be able to recover with the other techniques with the forward error correction it's on. 223 00:19:06,840 --> 00:19:09,420 All right, so let's move to GNU Radio to see this. 224 00:19:11,880 --> 00:19:26,920 So I'll do a real quick walkthrough of my GNU Radio flow graph here, receiving the signal from my hackerf, moving the signal down to baseband, down to zero, filter it, because the following blocks expect it to be around zero. 225 00:19:27,880 --> 00:19:41,860 And then frame synchronization, so that's what I was talking about, like, looking for the repeated sequence and then moving, and then it's like, what comes out of this flow graph is, like, only when it's found, when we're past the preamble and the down chirps, 226 00:19:41,860 --> 00:19:45,360 then it starts flowing out this flow graph. 227 00:19:45,540 --> 00:19:55,120 And this and all these blocks were a guy called Joachim Taperl, he made the open source, these blocks that are pretty decent. 228 00:19:55,120 --> 00:20:00,900 I tried myself, it was a lot of work, so I ended up using his blocks for the decoding and demodulation. 229 00:20:02,920 --> 00:20:16,660 So demodulation, gray mapping, interleaving, all those I just talked about, so the signal flows through all these blocks, de-whitening, that was the de-scrambling to avoid the long run of zeros, checks the CRC, then does some parsing. 230 00:20:16,660 --> 00:20:24,840 This is some code I made, just some pretty basic Python code I'll show you in a minute that does the mishtastic decoding. 231 00:20:24,840 --> 00:20:25,860 So it gets bytes. 232 00:20:25,860 --> 00:20:26,940 At this point, we're at bytes. 233 00:20:26,940 --> 00:20:28,080 Actually, we're at messages. 234 00:20:29,360 --> 00:20:34,500 So chunks of bytes come into the Python code, and then we can decode that. 235 00:20:34,500 --> 00:20:35,500 I'll show you that in a minute. 236 00:20:35,500 --> 00:20:40,320 Um, yeah, I'll just, let me just run this real quick. 237 00:20:42,560 --> 00:20:46,280 Oh, the device is busy because I still have GQRX open. 238 00:20:46,280 --> 00:20:47,380 Let's close that. 239 00:20:51,170 --> 00:20:53,810 So that was what I was showing in the beginning before I started. 240 00:20:53,810 --> 00:20:55,850 I'll just open the console window I launched this from. 241 00:20:55,850 --> 00:20:57,890 So right now I've set it, let me stop it again. 242 00:20:58,270 --> 00:21:00,950 I've set it to print out the symbols, that's what we see up here. 243 00:21:00,950 --> 00:21:10,270 The demodulation got the symbols, in this case, the mishtastic configuration for Defcon uses a spread factor of seven. 244 00:21:10,370 --> 00:21:19,230 So that means, like, that's, like, how many numbers could there possibly be between the bottom and the top of the chirp, right? 245 00:21:19,230 --> 00:21:21,310 So two to the power of seven in this case. 246 00:21:21,310 --> 00:21:29,050 So that's, oh, that should have been, instead of two to the power of seven, not two to the power of seven, it's just that two to the power of seven is 128. 247 00:21:29,050 --> 00:21:31,790 So we'll get symbols between zero and 128. 248 00:21:31,790 --> 00:21:35,250 So that block that's printing out the symbols gives us that. 249 00:21:35,250 --> 00:21:37,510 It gives us numbers between zero and 128. 250 00:21:38,290 --> 00:21:39,470 127, rather. 251 00:21:39,470 --> 00:21:40,670 Zero and 127. 252 00:21:41,170 --> 00:21:41,950 All right. 253 00:21:41,970 --> 00:21:46,490 So that's some basic walkthrough of the GNU Radio flow graph. 254 00:21:46,570 --> 00:22:00,030 And then I'd highly recommend this talk by a fellow called Matt Knight, who's here in the audience I know, who I think was the first person to reverse engineer the LoRa decoding, all of the gray coding and the scrambling stuff I was talking about earlier. 255 00:22:00,030 --> 00:22:02,210 That stuff, you can't really read it anywhere. 256 00:22:02,210 --> 00:22:03,810 You have to do a lot of experimentation. 257 00:22:04,010 --> 00:22:12,030 And this talk walks through very well how they arrived, and I think they were the first to reverse engineer, how they arrived at the perimeters that are actually used here. 258 00:22:12,030 --> 00:22:13,710 So highly recommend that talk. 259 00:22:15,130 --> 00:22:17,630 So there are different modem settings, like I mentioned. 260 00:22:18,290 --> 00:22:20,490 So this is like in the Mystastic source code. 261 00:22:20,490 --> 00:22:29,050 You can go there and you can look up modem setting different presets for what modem settings you want your LoRa radio configured at. 262 00:22:29,690 --> 00:22:30,770 This is one example. 263 00:22:30,770 --> 00:22:34,330 Like I said, this is popular in the Bay Area Mystastic network. 264 00:22:36,150 --> 00:22:41,170 So we've talked all about demodulation, all about LoRa, and we have some bytes now. 265 00:22:41,170 --> 00:22:43,910 Now we're at the application layer, Mystastic. 266 00:22:43,910 --> 00:22:55,330 So the bytes of a Mystastic packet consist of first a 16-byte header, where it is like a destination, sender. 267 00:22:55,330 --> 00:22:57,190 There's like, channel does this belong to? 268 00:22:57,190 --> 00:22:58,770 That's kind of a funky way to do that. 269 00:22:58,770 --> 00:22:59,990 I won't go deeper there. 270 00:22:59,990 --> 00:23:01,950 And then there's a payload, which is encrypted. 271 00:23:02,970 --> 00:23:11,210 And yeah, you can click here to see the protobuf definition for this top-level encrypted chunk of payload. 272 00:23:11,490 --> 00:23:14,990 But I think it's more interesting to let's look in Wireshark. 273 00:23:14,990 --> 00:23:16,550 So I'll start this again. 274 00:23:17,670 --> 00:23:23,430 And what I've done is I've rewritten, I've written a small, oops, let's close this. 275 00:23:25,550 --> 00:23:27,090 Open Wireshark. 276 00:23:27,630 --> 00:23:35,570 My new radio flow graph ended up, oh I should say that, it ended up with just dumping the bytes out on UDP. 277 00:23:35,650 --> 00:23:45,990 So then I've written a small, I've set up here Wireshark to listen on UDP, and written a small Lua disector. 278 00:23:45,990 --> 00:23:53,050 In Wireshark it's really easy to make your own extensions for how to decode a packet, how to dissect a packet. 279 00:23:53,230 --> 00:23:55,610 So I've made one for Meshtastic. 280 00:23:55,990 --> 00:23:56,970 So we can click on it. 281 00:23:57,350 --> 00:24:00,730 Here's an interesting, here's a text message that was the most interesting, I think. 282 00:24:01,770 --> 00:24:03,550 We can look at here. 283 00:24:03,710 --> 00:24:05,710 This is what Wireshark really shines at. 284 00:24:05,930 --> 00:24:12,730 You can click on different bytes of your package and it'll tell you, it'll highlight what was that. 285 00:24:13,730 --> 00:24:15,550 You can click the other way as well in the tree here. 286 00:24:15,550 --> 00:24:16,750 This is the destination. 287 00:24:16,750 --> 00:24:22,030 There's the sender, there's a packet ID, there's some flags about how many hops can we take. 288 00:24:22,350 --> 00:24:27,310 We don't want it to circle around forever so it decreases the hops every time it relays a packet on. 289 00:24:29,370 --> 00:24:30,710 Channel hash and so on. 290 00:24:30,810 --> 00:24:36,130 These first are the 16 bytes of header that are plain text. 291 00:24:36,130 --> 00:24:38,530 And then comes the payload which is encrypted. 292 00:24:38,730 --> 00:24:44,550 I've done the decryption over in my Python code that was in the new radio flow graph because that was too difficult to do in Lua. 293 00:24:44,550 --> 00:24:49,090 So it's already decrypted by the time it reaches my setup here, my Wireshark setup. 294 00:24:49,570 --> 00:24:54,410 So payload says that the message type, what they call a port number, is a text message. 295 00:24:54,470 --> 00:24:58,470 Actual payload is a text message, someone sent Weep. 296 00:24:59,550 --> 00:25:12,730 Node info, most of the things that go there aren't just node info, like nodes transmitting their name, short name, long name, which hardware model it is, the public key if you want to send them an encrypted direct message. 297 00:25:14,030 --> 00:25:18,770 So yeah, that's the basics of the packet. 298 00:25:18,770 --> 00:25:22,310 Okay, so we're getting close to time so I'm going to go a bit quick now. 299 00:25:22,530 --> 00:25:26,450 The last bit, I'll skip past this. 300 00:25:26,450 --> 00:25:30,450 Encryption, yeah, it's a normal AES-256 encryption, the keys are pre-shared. 301 00:25:31,430 --> 00:25:33,610 Transmission you might be interested in. 302 00:25:33,790 --> 00:25:41,910 So could be done by an SDR, much easier just to do with an Arduino that already has a LoRa radio built in, so that's what I did. 303 00:25:42,150 --> 00:25:49,810 Like I showed you before how the bytes are not that complicated and the keys are already pre-shared, so why not? 304 00:25:49,950 --> 00:25:53,490 Why not transmit like not using their firmware, just writing your own. 305 00:25:53,490 --> 00:25:54,810 So that's what I did here. 306 00:25:56,490 --> 00:25:59,570 Actually, real quick, just show the code. 307 00:26:00,150 --> 00:26:02,410 Here's my little sender. 308 00:26:03,750 --> 00:26:13,190 Set a few constants here, like what I want my address to be, what the destination should be, broadcast in this case, channel name, scroll down a bit. 309 00:26:13,190 --> 00:26:15,550 Here's the real interesting part, build a packet. 310 00:26:15,550 --> 00:26:31,930 So it's first using protobuf here to build a packet, get some bytes, data plane, packet ID is random in this case, encrypt the packet, get a packet, like append this header which consisted of these bytes here. 311 00:26:31,930 --> 00:26:43,010 There's like the three 32-bit integers, destination, sender, packet ID, followed by four one-byte fields, the flags, the channel number, and a few other fields. 312 00:26:43,010 --> 00:26:44,150 Then you get your packet. 313 00:26:45,070 --> 00:26:52,770 I wrote a little Arduino program that just receives these simple commands where you just write your data in hex and then it sends it out. 314 00:26:52,790 --> 00:27:02,150 So if any of you have your MISTASIC device open right now, I'm going to send a message, I'm going to send a few sweet potatoes. 315 00:27:02,150 --> 00:27:14,730 I'm writing sweet potatoes because that's kind of sweet, it's kind of nasty what I'm doing here because I'm skipping the whole protocol of MISTASIC, I'm not adhering to what you should normally be doing as a sender on this. 316 00:27:14,730 --> 00:27:21,070 You should normally have carrier sense, multiple access, collision avoidance, like you shouldn't be transmitting on top of somebody else. 317 00:27:21,070 --> 00:27:28,510 We're not doing any of that right here, we're just bypassing all of that, not following the protocol of, you know, relaying on messages that were supposed to be relayed on. 318 00:27:28,510 --> 00:27:30,130 Did any of you get the message? 319 00:27:33,250 --> 00:27:33,790 Not? 320 00:27:33,790 --> 00:27:35,010 Oh, okay, let me see. 321 00:27:35,190 --> 00:27:36,490 Did I comment that out? 322 00:27:36,510 --> 00:27:37,790 Oh, I put it on the wrong channel. 323 00:27:37,790 --> 00:27:38,770 Let's set it on the 324 00:27:43,210 --> 00:27:46,490 DefConnet channel. 325 00:27:50,020 --> 00:27:50,680 You got it? 326 00:27:50,680 --> 00:27:51,440 Okay, great. 327 00:27:56,880 --> 00:27:58,440 Almost done, yeah, almost done. 328 00:28:02,280 --> 00:28:03,780 So you could do things like this. 329 00:28:03,780 --> 00:28:06,440 I haven't done this before because it's kind of nasty to do. 330 00:28:06,440 --> 00:28:06,940 You see what I'm doing? 331 00:28:06,940 --> 00:28:09,780 I put a loop around the send, a little sleep. 332 00:28:10,520 --> 00:28:12,340 This is nothing really preventing us from doing that. 333 00:28:12,340 --> 00:28:13,700 This is our airwaves. 334 00:28:13,700 --> 00:28:16,500 This is unlicensed spectrum. 335 00:28:16,820 --> 00:28:18,960 So are you getting a bunch of messages? 336 00:28:21,300 --> 00:28:22,240 This one so far? 337 00:28:22,240 --> 00:28:24,600 Okay, maybe the receiver app filters out of it. 338 00:28:24,600 --> 00:28:26,460 I hadn't tried this kind of spamming before. 339 00:28:27,000 --> 00:28:27,820 I'll stop it again. 340 00:28:27,820 --> 00:28:28,740 You get the idea. 341 00:28:30,320 --> 00:28:31,000 Yeah. 342 00:28:31,860 --> 00:28:32,680 That's it. 343 00:28:32,880 --> 00:28:36,400 We're past time, so there has to be one question, I think, at most. 344 00:28:37,120 --> 00:28:37,920 Thank you.