All right, it's 1.30. Thanks for coming to my talk about Mesh-tastic. We're going to go really low level. 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. So I'll explain how I got to this state, how we got this working, or how I got this working. Let's stop this for a moment. All right, so just real quickly first, what is Mesh-tastic? Probably most of you who are here probably know this, so I'm going to go a bit faster these first few slides. But if you don't know, it's an off-grid, multi-mile, low-power Mesh network. Low power and it's very resilient to noise. You can send messages below the noise floor. It doesn't rely on any infrastructure. Basically, you would install an app on your phone, relay over to a little device, like such a device. 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. It's able to transmit fairly far at very low power. 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. It's open source and has a lot of community momentum. That's what I like about it, and I think a lot of people like about it. Just to give a taste, this is the Android app. It's what it looks like. Just a chat app. It has a bunch of other features I'm not that interested in, but it can do a lot of stuff. The next slide will be about what you probably need to know for this to make sense. Then I'll go deep in this technology LoRa, this technology underlying Mesh-tastic. How it's modulated, how it's encoded, how to decode it. And then I'm going to go deep in how Mesh-tastic, the layer on top, is encoded and decoded. I'm going to be using, I'm going to be demoing a lot. Different software, GQRX and Spectrum to zoom in really far, GQRX to capture. GNU Radio to do some more actual decoding. Wireshark because it's useful to look at individual bytes and see what byte means what in what packet. And Python to glue it all together. So Prereqs, this is not like an intro talk to RF and software-defined radio. I'm not really going to go over the basics of GNU Radio. You probably need to know a little bit of GNU Radio for it to make sense. That said, you'll still get the gist of most of it, I'd say, even if you don't. Packet formats, it should probably not be your first time seeing Wireshark. That wouldn't make much sense either. Protobufs, Google's very efficient format for serializing structured data into bytes in a binary format. So that's pretty much all we need to know about that. It's a serialization format. 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. I like this one because it fits in your pocket. 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. He has all of them, I think. I'm going to be using the HackRF, Software Defined Radio Receiver or Transceiver. You could probably use a really cheap RTL-SDR as well. I didn't get time to try, actually, but I think you could. What I'm doing here doesn't really require such a fancy SDR, actually. 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. It is probably possible, but it would take a lot more effort. So I'm just transmitting through a really simple Arduino with a LoRa chip built in. I'll show you that at the end, but you can get these on Amazon for real cheap as well. So what is LoRa? So LoRa is a radio modulation and encoding system. It's a closed source technology by this company called Semtech. And the primary use is for LoRaWAN. 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. You'd have base stations that are connected to the internet then. So your LoRa devices reach base stations, and then that relays the thing onto the internet. 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. 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. So it's just kind of a hop to the internet. That's what LoRaWAN is. That's not what Meshtastic does, though. 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. So real quick recap of common modulations. 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. You might make it stronger, weaker, stronger, weaker in some wave, a 400 Hz wave, for example, if you're modulating an audible tone. So that would be amplitude modulation. 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. So amplitude shift keying. You might make the frequency higher, lower, like 400 times per second if you were modulating a tone. 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. So that's a quick recap. So LoRa uses a really different modulation, which is very clever. I've seen different names for it. Chirp Spread Spectrum is one name. Frequency Shift Chirp Modulation is another name. I thought that was a pretty well-descriptive name. 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. So it's these chirps, like up, up, up. We'll see it in a different format later. The illustration here is in what we call a time domain, right? This is what the wave would look like. Wave gets shorter and shorter and shorter, higher and higher frequency. We can also look at it in the FFT plot style. We'll do that later. But chirps, so tones rising, rising, rising, and then I'll show you how you can encode data in that. And why is this good? Because with frequency shift keying, you're sending on one frequency for a bit and then another on a bit. But while you're on this one frequency, you might get a lot of noise. You might get buried in the noise. The signal would easily drown out in other types of modulation. This type of modulation is very resilient to drowning out. 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. I'll leave it at that. All right, so let's do some demoing. Let's capture a chirp. So I'm using the HackRF. 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. And that's what I'm going to be doing. I'm going to be recording. So what we already see here is 917 megahertz, a bunch of stuff going on. Now, that's the DEF CON configuration that most people here are probably running, like LORAC or Meshtastic configuration. It's called... there's some different modem settings you can have in Meshtastic. You can have different frequencies and so on. Meshtastic has some presets, and the preset that the DEF CON Meshtastic configuration recommends is running around 917 megahertz. So that's why we're seeing a bunch of stuff going on up there. The preset is called short turbo. Because it's turbo, it's really hard to view. So I'm going to transmit on the medium slow preset, which is what we use in the Bay Area mostly. It's just popular there. So that... well, you know, different presets are more resilient to different things. Some have longer range, but take more time so you don't have as high bandwidth. 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. We want there to be enough room for all messages to not step on each other. All right, so I'm on my phone getting up now in the Meshtastic app. I'm just going to send one message here. Okay, we saw my message here. I'm sending on medium slow, so that's a different frequency, like around 915 megahertz. And it got retransmitted because nobody acted. Let me move them a little bit away. These are the transmitters. I'll just move them away from the antenna so it doesn't blast so loud. And this time I'm going to record. So I'm going to try to time it because the recordings are really big. It's like we're looking at 8 megahertz of bandwidth here, and it's like 100 megabytes a second or something. So I'm just going to record for just a second when I press send. Okay, I got it. So I'm stopping the program. I got this down here. I pressed record. I got this file. We're going to look at that now in a tool called InSpectrum. I'm going to launch that. So the reason I like this tool is you can zoom in really well. Here we go. So I had offset. I didn't center it around the tuned frequency. There's some limitations of the HackerRF, so I offset it by 1 megahertz. That's why we're seeing it centered around 1 megahertz here. 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. That's what the modulation looks like when you visualize it. So let's see what next I want to show here. Yeah, I think what I'll show now is this tool, InSpectrum, you can choose, you can enable a grid. Let's do that. 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. Okay, that's pretty well aligned almost. There we go. Align that at these up chirps. So each up chirp, each chirp here is a symbol. And let's move a little around. At the beginning, there's some, I'll come back to actually how the structure is. There's some up chirps, there's some down chirps. But now we got, like, from the up chirps in the beginning, we could see the width of each symbol. So now I have my grid, like, set up right for that width. And then there's two and a quarter down chirps. I'll tell more about that later. And then there's a bunch of up chirps. Let's actually, let's go here. It's more interesting. Yeah, okay. So the intuition here is when you've aligned this right, you can see where these up chirps start and then wrap around. This is a good one. It starts kind of in the middle, goes to the top, and then wraps around, goes up there, goes up to where it started. So this starting position, the intuition here is the starting position is the symbol. So we're trying to send numbers here, right, at the end of the day. 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. This is maybe, I don't know, 79. And this might be the number 40 or 30. And this might be number 20, and so forth. So that's how the encoding works intuitively, like at a high level. All right, so we had these, we saw many just up chirps in the beginning. 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. And then after that, it knows kind of how to align its grid like I was doing manually. 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. So like Meshtastic uses symbol, like one byte symbol, 2B, to indicate that this transmission was a Meshtastic transmission. Then there are these two and a quarter down chirps to show that the preamble has ended and now the actual payload is coming. So everything after that are symbols that are the actual Meshtastic data. So let me go back here and look. 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. 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, and then two and a quarter down chirps, and then from here, after the quarter down chirp, our actual payload begins. All right, so let's see, how are we on time? 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, so it becomes like, if you have this symbol, an up chirp, this down chirp, you get a flat line. 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. 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, like which was the dominant frequency in this time span, in this chirp. 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, somewhat, there's more to it. 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? So how does it do that? 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? 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, then I know I need to move it this much back. That's how it synchronizes, right? 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. 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. Visual Electric, it's on YouTube. You can, oh, I should mention my slides here are on my GitHub, so you can go and click the links from there. Okay, encoding, so I think I've got to move a bit faster now. So we've talked about modulation so far, right? We're getting from radio signals into some kind of numbers. So what happens with these numbers? Well, let's talk first about what would happen when we're sending, right? So first, it adds a cyclic redundancy check, it adds some error detection, right? A hash, just a couple of bytes at the end, just to see, like, did the end result turn out right? 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, because then we wouldn't be able to, you know, then the preamble isn't that unique, right? So the payload could never contain this repeated sequence of zeros. 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. 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. So, like, maybe the forward error correction will help us recover if just, like, one of the symbols were a bit off. And then gray coding, so that reduces the impact of errors. 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. This is because, like, you might misread the signal slightly. If it was with binary, there'd be a big difference between the number 63 and 64. Like, there's a lot of bits that are different, right? So if you misread it slightly, you'd be completely off, like, your bits would be completely off. With gray coding, you might still be able to recover with the other techniques with the forward error correction it's on. All right, so let's move to GNU Radio to see this. 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. 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, then it starts flowing out this flow graph. And this and all these blocks were a guy called Joachim Taperl, he made the open source, these blocks that are pretty decent. I tried myself, it was a lot of work, so I ended up using his blocks for the decoding and demodulation. 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. This is some code I made, just some pretty basic Python code I'll show you in a minute that does the mishtastic decoding. So it gets bytes. At this point, we're at bytes. Actually, we're at messages. So chunks of bytes come into the Python code, and then we can decode that. I'll show you that in a minute. Um, yeah, I'll just, let me just run this real quick. Oh, the device is busy because I still have GQRX open. Let's close that. So that was what I was showing in the beginning before I started. I'll just open the console window I launched this from. So right now I've set it, let me stop it again. I've set it to print out the symbols, that's what we see up here. The demodulation got the symbols, in this case, the mishtastic configuration for Defcon uses a spread factor of seven. So that means, like, that's, like, how many numbers could there possibly be between the bottom and the top of the chirp, right? So two to the power of seven in this case. 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. So we'll get symbols between zero and 128. So that block that's printing out the symbols gives us that. It gives us numbers between zero and 128. 127, rather. Zero and 127. All right. So that's some basic walkthrough of the GNU Radio flow graph. 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. That stuff, you can't really read it anywhere. You have to do a lot of experimentation. 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. So highly recommend that talk. So there are different modem settings, like I mentioned. So this is like in the Mystastic source code. You can go there and you can look up modem setting different presets for what modem settings you want your LoRa radio configured at. This is one example. Like I said, this is popular in the Bay Area Mystastic network. So we've talked all about demodulation, all about LoRa, and we have some bytes now. Now we're at the application layer, Mystastic. So the bytes of a Mystastic packet consist of first a 16-byte header, where it is like a destination, sender. There's like, channel does this belong to? That's kind of a funky way to do that. I won't go deeper there. And then there's a payload, which is encrypted. And yeah, you can click here to see the protobuf definition for this top-level encrypted chunk of payload. But I think it's more interesting to let's look in Wireshark. So I'll start this again. And what I've done is I've rewritten, I've written a small, oops, let's close this. Open Wireshark. My new radio flow graph ended up, oh I should say that, it ended up with just dumping the bytes out on UDP. So then I've written a small, I've set up here Wireshark to listen on UDP, and written a small Lua disector. In Wireshark it's really easy to make your own extensions for how to decode a packet, how to dissect a packet. So I've made one for Meshtastic. So we can click on it. Here's an interesting, here's a text message that was the most interesting, I think. We can look at here. This is what Wireshark really shines at. You can click on different bytes of your package and it'll tell you, it'll highlight what was that. You can click the other way as well in the tree here. This is the destination. There's the sender, there's a packet ID, there's some flags about how many hops can we take. We don't want it to circle around forever so it decreases the hops every time it relays a packet on. Channel hash and so on. These first are the 16 bytes of header that are plain text. And then comes the payload which is encrypted. 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. So it's already decrypted by the time it reaches my setup here, my Wireshark setup. So payload says that the message type, what they call a port number, is a text message. Actual payload is a text message, someone sent Weep. 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. So yeah, that's the basics of the packet. Okay, so we're getting close to time so I'm going to go a bit quick now. The last bit, I'll skip past this. Encryption, yeah, it's a normal AES-256 encryption, the keys are pre-shared. Transmission you might be interested in. 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. Like I showed you before how the bytes are not that complicated and the keys are already pre-shared, so why not? Why not transmit like not using their firmware, just writing your own. So that's what I did here. Actually, real quick, just show the code. Here's my little sender. 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. Here's the real interesting part, build a packet. 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. 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. Then you get your packet. 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. 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. 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. You should normally have carrier sense, multiple access, collision avoidance, like you shouldn't be transmitting on top of somebody else. 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. Did any of you get the message? Not? Oh, okay, let me see. Did I comment that out? Oh, I put it on the wrong channel. Let's set it on the DefConnet channel. You got it? Okay, great. Almost done, yeah, almost done. So you could do things like this. I haven't done this before because it's kind of nasty to do. You see what I'm doing? I put a loop around the send, a little sleep. This is nothing really preventing us from doing that. This is our airwaves. This is unlicensed spectrum. So are you getting a bunch of messages? This one so far? Okay, maybe the receiver app filters out of it. I hadn't tried this kind of spamming before. I'll stop it again. You get the idea. Yeah. That's it. We're past time, so there has to be one question, I think, at most. Thank you.