start	end	text
0	660	Hey, everyone.
660	3780	Welcome to our talk about Behind the Badge.
3780	16080	And it's kind of a story on how we worked on improving our Aerospace Village badge from last year, as well as the design process and some of the challenges we've encountered while developing our SAO Charlie for this year.
16080	17860	So I'm Robert Pafford.
18620	20060	And I'm Adam Vettori.
21020	23780	And yeah, this is a Behind the Badge.
23820	28500	So a little kind of refresher on the badge we developed last year.
28500	32740	So this is a Linux badge running with a nice circular screen.
32740	38900	And its whole idea is it's designed to receive ADS-B packets that are sent out from airplanes.
39040	44600	So it picks it up on an internal antenna or external antenna and displays it on the nice screen.
44600	45940	It runs Linux.
45940	52720	It's got a dual core ARM core, as well as a DSP which we use to receive all these ADS-B packets.
52900	60120	So this past year, we've been kind of working on improving these algorithms to get better performance and be able to see more planes around you.
60140	62200	And so we actually pushed a software update this DEF CON.
62200	69680	So if you have a badge from last year and haven't gotten it, make sure to either stop by the village or check out our GitHub to get the links to update your badge to get these new improvements.
70000	75360	But part of this process was kind of actually optimizing the assembly.
75380	80580	So the HiFi 4 DSP has a lot of SIMD capabilities, but they weren't being used last year.
80720	89420	So we did some work to kind of optimize all this assembly and really leverage the full capabilities of this core to get all the performance out of it.
89620	92120	Additionally, we realized we had the cache turned off.
92120	96920	So when we turned on the cache, we actually were able to hit real-time decode and actually faster than real-time.
96920	101560	So we were able to receive all the packets and process all the data we have coming into the badge.
101800	109480	So this was a big performance boost, and we kind of pushed it out as a soft update for some of our testers over winter.
109480	117380	But we started to see some intermittent crashes every few minutes to actually every several hours on this new DSP firmware.
117900	123960	And this made it really difficult to debug of when you have a crash every few hours and you try and see, oh, did this fix it?
123960	127580	You have to wait six plus hours to see if it actually solved it.
128040	134420	So the crash was a kernel panic would occur, but it wasn't really consistent on what the message was.
134420	137180	You typically have a very corrupted stack message.
137180	139220	You wouldn't get a lot of registers or dumps.
139220	141720	Sometime it'd just be one or two lines of a panic message.
141900	145860	And it didn't even seem to have to do with anything related to the DSP.
145860	153120	And it appeared to be a memory corruption of some kind, some sort of issue on the TV decoder, some race condition.
153120	156480	We weren't really sure, and it was really difficult trying to debug it.
157780	167120	But after kind of working on this issue for several days, like a couple weeks, we were able to finally narrow down the bug.
167120	174860	And the solution to solve it ended up just be the big hammer of dump 128 megabytes of DRAM over JTAG.
174860	178280	It took around 45 minutes to get this whole dump out.
178280	185360	But from there, we were able to actually start to figure out where is this kernel panic coming from, of all it would be is some random memory pointer.
185360	196300	But when you searched for what that memory pointer was, you'd see that there's actually a large number of matches inside of the buffer that we get the raw ADC samples out.
196400	202000	And you'd actually be able to see in the buffer region we assigned for the TV decoder, it was there.
202000	206280	We'd also see a large number of matches at the start of DRAM, which was very interesting .
206620	214880	At the start of DRAM, it's reserved for the Linux kernel to keep all of its important structures and needs to actually boot up and actually run the operating system.
214880	224280	But if you inspected it on the crashed system, it actually looked like the start of DRAM was instead just a lot of signed 12-bit numbers , which looked a lot like the buffer from the TV decoder.
224400	238440	And it seemed that there was some sort of one in a million chance of a hardware bug that the TV decoder DMA would just instead of writing to where it's supposed to go, just dump it to the start of DRAM, and then destroy all of the kernel memory, and you would actually crash the device.
239100	245160	So this was a very difficult problem to actually like solve of like, well , it's a hardware bug, we can't really fix that.
245160	249160	How do you go about preventing it from randomly writing to the start of DRAM ?
249940	254940	The solution was to just move the DMA buffer to the start of DRAM , tell the Linux kernel to get out of the way.
254940	257640	So if it glitches, it'll just go where it's supposed to anyways.
257700	261600	And if you look at the memory map, it's kernels been moved out of the way.
261600	264760	And that's what you're running, that we're running on these badges now.
264760	266640	So we can now receive it.
266640	269620	And we have solved the hardware bug with software.
275430	283930	So a another hardware feature we want to revisit from last year and kind of add some extra polish on for this year was the our dual role USB C port.
284370	290050	So we put when we put the C port on the badge, we have the intention of it being both a device and a host.
290310	300370	So the intent is you get this badge, you plug it into your computer, and your computer is the host, this will act as a USB to Ethernet emulation gadget and lets you just SSH in kind of automagically.
300630	304230	But you know, it's DEF CON, we're all hackers, we want to have some fun with this portable Linux device.
304230	312230	If I have a flash drive or like a keyboard or some other smaller USB C device, I want to be able to plug it into this USB C port, have the badge act as the host.
312510	316730	And our power management chip will give you the five volts boosted from the battery.
316950	321230	And it should let you not use like, you know, any other normal USB device on Linux.
321510	332710	But when we were doing hardware bring up, we started seeing these, like very, again, interesting transient flaws where, you know, maybe about, like 70% of the time, we'd have these USB enumeration errors, but only in host mode.
332890	343450	And that tells us that it's likely not an issue in the actual hardware, like the signal integrity, since we can run high speed USB, like USB device 100% non like non stop, no problem.
343850	347430	But it's only in this host mode that this issue actually occurs.
347690	355270	So like, I was going into this thinking that there, okay, there might be some bug in the kernel driver, like, that would make sense, like, let's do some kernel debugging.
355990	364870	And another like data point we thought we saw is that the original all winner vendor like PSP kernel, the USB host mode also work fine on the same board.
364870	369930	So again, very likely not a PCB bug, just something in the mainline kernel might be bugged.
371150	388870	And as we're looking into the implementation of how all winner specifically does the dual role USB device switching, they actually like with some of these other IP cores have a pretty interesting way of solving the problem, where they have two effectively host controllers,
388870	399230	the main device controllers, the mentor graphics like the MUSB HDRC, it's a dual role controller, so it can do host and device mode in the same like a little like IP block.
399230	401590	And this has been used in a lot of devices.
401590	404310	So there's tons of info on it, like available online.
404450	408330	And for some reason, all winner actually only uses this in device mode.
408710	418410	They like on top of that, we'll glue on an EHCI OHCI, like second pair of host controllers, and add this like interesting UTMI mux.
418410	428850	Well, they claim it's UTMI mux, we have some, like things we found in the kernel code and like the, the like other data sheets that make it sound like it's actually not exactly that simple.
428850	432250	So how exactly they're doing the muxing and switching is not super clear.
432250	434450	But, you know, it doesn't really matter for right now.
438230	448730	And we, like, we see that, okay, the host mode itself works, sometimes when it enumerates, and the device works basically all the time.
448730	464050	And so we were looking at the actual USB PHY, like the, the, like, basically undocumented IP core that talks to the physical differential pairs on the USB port, and then takes that information passes it to the host control like EHCI OHCI controllers.
464230	481850	This interface is not your standard mem mapped like MMIO, it's a pretty cursed bitbang interface, where you can see that to actually read and write these, we call them like sub registers, like these very low level registers embedded deep in the the analog blocks of the PHY,
481850	488950	you basically are bitbanging some sort of serial shift register interface through these otherwise MMIO registers.
490190	495030	And, like, look, you're trying to debug the mainline kernel code, it seems to be using in a sane way.
495110	500190	There's only two times that ever actually really talks to this PHY, it's when the board turns on and does the setup.
500190	504930	And then when you do the actual roll switch, so sounds like we're on the right track.
504970	507270	And, you know, we were looking at bugs in the driver .
507770	511850	And it turns out that actually the entire mainline driver was the bug.
513310	516330	Allwinner has a whole, like, plethora of chips.
516330	521310	And they have these like code names, that's could be a whole other like our talk to explain that mess.
521650	528590	But they have the they have a quirks table that let you like try and handle different quirks between different versions of the silicon .
528590	531210	But overall, it's the same code for all the Allwinner SoCs .
531330	537690	Well, what we found in looking through a specific version of the Allwinner BSP kernel is that they had these interesting comments .
537690	539870	They're saying, Oh, yeah, we have this new PHY .
539990	541030	It's for the new PHY.
541030	543870	And it's for self developed by self.
544190	548410	So we suppose that Allwinner actually made what we call a v3 PHY.
548410	551870	They made their own in house, analog IP core.
552010	559970	And as a result, you'd have you need new ways of controlling that, especially with a really, really silicon specific analog low level control blocks.
560110	563470	And it seems that no one from like the mainline kernel actually noticed that.
563470	566550	Or if they did, they thought that the old driver would just work.
566790	569370	And it doesn't work at all, actually.
569990	575010	Like the registers it sets in this analog interface sub block are completely wrong.
575010	577250	Like they don't exist on the new v3 PHY.
577490	583290	The trim algorithms that the mainline kernel uses from the v2 PHYs don't apply at all to the v3.
583290	586390	Those actually done in factory now and loaded from fuse.
586390	589650	And we saw that, of course, mainline doesn't touch the fuses at all.
589650	593630	So we know that is completely not driving it correctly.
594190	604110	So this actually seems like it could be a good like explanation that the analog trims were not loaded from fuse and were just running untrimmed.
604110	608050	But actually no, that it somehow still actually just works fully untrimmed.
608050	614790	The real for real issue was that the kernel drive was not switching the PHY power bit correctly.
615250	624900	So regardless, we implemented both the like correct bring up initialization trimming functionality and the correct power switching.
624900	636280	And now with an actual proper v3 PHY driver, we finally just have it just works both USB device and host dual role switch over in the in the kernel.
636280	641740	So that's also packaged in a new new kernel update that we have shipped with our v2 firmware.
643640	654180	All right, and with those winglet updates, or updates our main ADS-B badge brings us to Charlie, which is the new SAO hardware we designed and brought to DEF CON this year.
655320	662840	So Charlie, as we call him, is designed to add some extra radio and like now audio capabilities to the Linux badge.
663120	669880	And in the vein of aerospace, we want to come up with some cool things around, you know, around air space and radio.
669900	678000	And we settled on trying to receive airband voice as a as an expansion of receiving the ADS-B messages from the planes with the base badge.
678440	682700	We have a headphone jack to listen to it, which also doubles as our antenna , the headphone wire.
682900	689500	And we figured like, hey, if we already are shipping headphones and audio processing, like, can we receive broadcast FM, that would be kind of cool.
689500	694800	It's something that's kind of around you no matter where you go, even if you're not near an airport or you're not line of sight to a plane .
695760	702040	And if we're going to do broadcast FM, we might as well do a nice stereo because we want only the best user experience.
703240	706700	We also have a pretty neat menu system and animations on this.
706700	711740	We are running full four color grayscale on the OLED, which we will absolutely get to in a little bit.
711880	718360	And as I like to say , to make all this run on our little microcontroller, we are programming five out of the two cores on it.
718560	721800	Because I mean, we need we need that much performance.
724770	728470	Yeah, so this a very powerful five core microcontroller.
728470	729570	Which one is that?
729850	735570	This is the TI SimpleLink CC1312R RF microcontroller.
735570	745310	It's a like sub gigahertz wireless microcontroller you might find in like, like wireless remotes or any sort of device that needs to communicate like long range over sub gigahertz.
745550	750770	The actual core of the microcontroller is a pretty standard like ARM Cortex M4F.
750770	753810	It's downclocked pretty low at 48 megahertz.
754070	758710	And it's got a your standard basic set of peripherals of UART, SPI, things like that.
758770	762370	So from the like a microcontroller point of view, it's pretty standard.
762410	767870	One interesting part is it has a thing called the sensor interface in the bottom right.
767890	770730	And that actually has a second core which you can program.
770730	772590	They give you all the tool chain to develop.
772590	775790	It's a sensor controller, they call it.
775830	784450	And it's a 16 bit DSP that's 16 bit CPU core, which is just ultra low power, super basic, basic edition.
784910	787870	But it's designed for like background sensor pulling tasks.
787870	793490	And it's a very low power core that can run while the entire main rest of the system is like power gated and turned off.
793650	799710	So that was very interesting, because you can actually use that for more features and adding more stuff into it.
799910	803970	From the RF side, it's great because it can receive sub gigahertz.
803970	808590	But there are a few short, few small issues when you're trying to develop with this .
808590	813250	One, the TI SimpleLink actually can't tune to the frequencies required for it.
813250	817690	So we wouldn't actually be able to tune to FM or airband if we chose this microcontroller.
817970	821410	And the microcontroller is only designed to receive digital signals .
821870	824450	But airband is an analog signal.
824510	829310	So a few small challenges we had to overcome to actually make this possible for this SAO.
829850	840090	So to actually do that, we have to kind of unlock more features of the RF core to convince it to receive analog and kind of go outside of what it's intended for by the manufacturer.
840390	844670	So we needed to convince the RF chain to kind of go and receive analog.
844670	848210	And the thing is that all the signals coming into the chip have to be analog.
848210	855090	And looking at the block diagram that they show here on the right, you can see that it's actually pulling two ADCs for IQ sampling.
855090	860890	So at some point in the signal processing chain, there should be raw IQ samples flowing through this chip.
860910	869930	So if we could figure out how to actually pull the samples out early enough in the processing chain, we could get the raw analog samples and we could actually receive these analog signals.
870050	875210	The problem is that there is absolutely no documentation on how any of this RF core works.
875370	878230	Pretty much any RF microcontroller you'll work with is like this.
878230	880750	They don't give you any of the register maps or documentation.
880750	884490	They just say, use our APIs, use this pre-compiled blob.
884490	886810	They don't even really give you source code to use it.
887070	889070	This chip takes it an extra step further.
889070	900190	And actually, the APIs, they give you the source code for, but all they do is talk to a mailbox to a third processor inside of this chip, which you can't, you're not supposed to run code on.
900190	901950	They say, oh, just use our APIs.
901950	904130	It's got a ROM with all the code it needs.
904330	911290	And it actually makes it more difficult to reverse engineer because you don't actually have a reference for even like a pre-compiled binary to look at.
911290	914030	It's just all in this walled off box.
914370	924670	But being able to directly drive the peripherals would give us full control and being able to do it on a second core would even take load off of the main CPU and we could do more cool stuff with the main core.
924670	927650	So that was kind of the objective for this.
928190	934590	The nice part is that what allowed this to be possible is TI creates a thing called RF patches.
934590	941290	So the whole idea behind this is they released this microcontroller when Bluetooth 5 was the latest and greatest.
941290	947490	But Bluetooth 6 comes out and they don't want to respin the silicon and change a bunch of ROMs out just to support Bluetooth 6.
947510	960190	So instead they created this concept of patches where in an SDK update they will give you some opaque binary blobs that you load in and it will put it in magic locations in the chip and it will actually be able to change the behavior of the RF subsystem.
960370	967830	So this seemed to be the best way to actually change the behavior and actually implement our own custom RF control on the chip.
968310	972950	So these are just after kind of looking through and reverse engineering these a bit.
973010	981750	These patches are just executable code that gets loaded into various parts of RAM and hooked into the various parts of the RF core.
982850	996290	Now the other interesting thing is that when you look through the RF patches, they talk about CPE patches, which stands for the Command Packet Engine, is that Cortex M0 in the previous slide that kind of all the RF libraries interact with.
996290	1003890	This has like the mailbox system and does all of that and does like the high level management and power up and power down of the RF subsystem.
1003890	1012110	But there's two other types of patches, MCE and RFE, which are designed to do more real-time processing tasks on the chip.
1012110	1022870	And these are a completely undocumented ISA, which required some reverse engineering to figure out how to actually create and develop code for these processing cores.
1022910	1034050	But they are two additional CPU cores, which also run at a rather fast speed, and they're able to do a bunch of real-time decoding and management of the RF subsystem.
1034050	1041010	So being able to leverage these cores, unlock even more capabilities and give you even lower level access into the RF subsystem.
1041930	1044990	And so all these CPUs can be patched.
1044990	1054750	And we had to create custom patches for all of these cores to be able to modify their behavior and actually start to pull out these analog samples and actually make all of these things possible.
1056130	1060110	So how do we get it to work on Charlie?
1060110	1062190	And how do we actually receive airband audio?
1062190	1068510	So the actual chip itself has a hardware IP block called the magnitude estimator.
1068510	1072590	So this converts the raw IQ RF samples into a magnitude.
1072590	1079490	So this is effectively an AMD modulator, where you can just get the absolute magnitude of the incoming waveform.
1079610	1088730	And if you were to take that audio out and play it, you would get roughly some sort of AM tape signal, and it would be very low quality, you could use that.
1088790	1109670	So we take that magnitude block out and we use the MCE firmware, we made a custom patch to kind of periodically pull this magnitude estimator and use debug registers to pull the samples directly out of the chain at an early point, and actually get it before it goes to the digitizer and then just forward that out into the FIFO that's typically used for digital packets that are received.
1110570	1116270	Then we create a custom CPE patch, which will be able to do all of the filtering of this data.
1116270	1122670	So this will take the samples coming in from the MCE, and it will be able to do like basic filtering.
1122670	1130570	So this hard audio doesn't sound as harsh, and you can kind of hear the airband voice and a little bit clearer, as well as it does the squelch algorithm.
1130570	1136750	So you don't hear static in the background, as you're kind of listening to dead air, it'll actually kind of mute that.
1137070	1142830	So part of that process, we were able to kind of talk to the RFE, which does all the power estimation.
1142890	1148110	So having all of these systems work together, we were able to create the airband receiver.
1148410	1153190	So when it's not, when you just have a transmission, you're able to pick it up, hear it rather clearly.
1153190	1156050	And then when there's nothing going on, it just silently mutes itself.
1156430	1163330	And this is all, once all this processing is done, you have audio samples written to a buffer , and it's sent to I2S.
1163330	1169570	And so the main CPU allocates the buffer, but after it does the handoff to the CPE, it pretty much steps completely away.
1169570	1173370	And so all the receiving is done with zero overhead to the main CPU.
1173370	1176070	So we're able to do a bunch of other interesting stuff in the meantime.
1176970	1179650	So that's the airband audio receiver.
1180390	1182910	And that was, we got working.
1182990	1195750	But we also wanted to make sure that we could receive FM, because you might not be directly near an airport, but it'd be nice to be able to still use Charlie and actually be able to pick up some sort of audio and kind of mess around with the SAO.
1195750	1198890	So part of this was, we wanted to get stereo FM.
1199510	1202410	Basic, like mono FM is pretty simple.
1202950	1213590	At the, this is the spectrum view of your RF spectrum, or the post frequency demodulation, what your spectrum will look like when you, for an FM station.
1213630	1219530	So everything below 15 kilohertz, you can kind of see is marked as L plus R.
1219530	1221150	And so that is your mono audio.
1221150	1232610	So your basic FM receiver will just put a filter, everything below 15 kilohertz, just put out over the speaker, everything above discard, and you can get a basic FM audio stream like that.
1232610	1237690	And so the first implementations we had of FM on the development boards were just basic mono audio.
1237970	1252230	But stereo actually sounds, even though you might not have the full high quality CD level audio you'd expect from modern digital electronics, stereo adds an extra sort of feeling to the audio that it makes it sound better.
1252230	1257310	And so I was determined that, okay, we are going to get stereo FM on this thing.
1257330	1261670	And we're going to figure out some way to get the signal processing chain to do this.
1262070	1269930	So the way you actually receive stereo is a little bit more complicated, because again, the everything below 15 kilohertz is mono audio.
1270090	1276370	So rather than to be able to separate the left and right channels, they don't have the left and right transmitted separately.
1276430	1285970	Instead, they have up at the 39 kilohertz point, this left minus right signal, which allows you to do addition and subtraction operations.
1285970	1288530	So if you add the two signals together, you'll get the left channel.
1288530	1290970	And if you subtract the two signals, you get the right channel.
1291290	1299190	So we would have to go in and kind of narrow out this sort of center left minus our region, and then add the two signals together.
1299190	1311030	And you do this with this 19 kilohertz pilot tone, where you will be able to see this tone, if you filter it, that will give you a pure tone, which you can multiply by two to get the dead center of your left minus right audio.
1311070	1314230	And then you're able to kind of go from there to actually receive it.
1315050	1321550	So the actual algorithm to do this is we take in the raw FM demodulation from the MCE.
1321830	1328430	And we first go through in the middle path to go through and I think I can do this.
1328430	1336210	So you go through the middle path, which is the 19 kilohertz pilot band pass to kind of isolate this center carrier frequency.
1336230	1338690	And then you run it through a phase lock loop.
1338690	1344630	So this turns it from a very noisy 19 kilohertz tone, depending on how close you are to the transmitter or how much noise is present.
1344630	1353890	This cleans it all up and does best effort to try and recreate this 19 kilohertz pilot carrier to then be used later in the chain.
1353890	1367610	We then multiply it by two and then are able to get a 39 kilohertz, which is our reference for what we need to shift our like the L minus R band down to, to actually get the L minus R signal.
1367610	1371450	So we shift the 39 kilohertz back down to zero and then filter it.
1371450	1373570	So we just get the L minus R signal.
1373710	1375970	So at this point right here, we have L minus R.
1376050	1380030	For the L plus R, aka the mono audio, you just have to filter it.
1380110	1381910	And then you get an L plus R.
1381910	1387010	Then you do the addition and subtraction operations, and you will get your FM, left channel and right channel.
1387010	1395030	And then after a little bit of the emphasis to correct the frequency response, you're able to get your left and right channels out of FM.
1395270	1400790	So there's a lot of filtering steps and a lot of various math that needs to be done to do this.
1400950	1406210	And there's a lot of demos online, and you can do this on your radio or on your computer with an SDR.
1406270	1411610	But we have a 48 megahertz Cortex M0, which is not a DSP.
1411610	1413570	We were lucky to get a multiplier.
1413630	1422090	So we had to kind of create a whole custom patch system to do this DSP in a very small amount of time.
1422610	1431070	So at this, we have a 200... at the audio rates we get, you need 200 kilo samples per second to get your 100 kilohertz of bandwidth required for FM.
1431110	1432690	So this is the absolute minimum.
1432690	1436510	You should really do 250, but we couldn't afford the cycles for that.
1436510	1437770	So we got 200.
1437870	1450330	And so this gives us around 240 cycles per sample to run an algorithm of two six-order IAR low-pass filters, a PLL , DDS, a bandpass filter, and two FM de-emphasis filters.
1450610	1462010	So this was done with a very custom Cortex M0 assembly routine, where to actually save CPU cycles, a load and store on the Cortex M0 actually used two cycles per.
1462010	1472370	We actually ended up moving the stack pointer and reusing it as a general purpose register to actually save CPU cycles while loading and storing to try and inch every piece of performance out of this chip.
1472510	1480450	But we were able to squeeze it just under with 235 out of 240 CPU cycles are in use to receive this FM.
1480450	1482670	And that leaves a few spare for bus arbitration.
1482670	1489550	But with all of this, you are now able to enjoy stereo FM, which is something your car can do, but now so can your SAO.
1499880	1500920	All right.
1501360	1502980	So this is great.
1503060	1508680	But to be able to like leverage any of this, we actually need to get the FM or airband signal into the chip.
1508680	1513840	And as we mentioned before, that that's not really possible on the SimpleLink, even though it's a sub -G chip.
1514460	1519440	FM requires you to tune to 88 megahertz, that's the lowest end that like we need to pick up.
1519720	1527140	And even though it's a sub-G chip around TI officially says around 169 megahertz, and there's gaps, it's not a full continuous spectrum.
1527140	1532460	But this chip will do 169 megahertz to about 1000 megahertz with some gaps in between.
1532740	1536040	And that's not enough to 88.
1536600	1541440	And we tried a few things to get this chip to tune down that low.
1541440	1548540	And I assure you we tried everything we could, including actually throwing away the existing PLL driver.
1548540	1552960	TI uses an interesting architecture called the ADPLL or all digital PLL.
1553220	1557280	So there's a few papers and like IEEE talks, they did on this.
1557280	1575080	And there's some cool stuff in there, like, this is interesting to you, where, for example, like they don't run the feedback loop in analog, in an analog mode, they actually run it as you can imagine, like a digital clock with just very, very fast, like up to 2.4 gigahertz fast counters as your phase comparators and all their PLL stuff .
1575460	1585580	But we were thinking, okay, well, if the existing PLL driver code does not let you tune this low, what if we write our own PLL driver code and see how low we can push the silicon?
1585740	1590660	And the answer is around 140 megahertz, which is still not even close enough to 88.
1591060	1609160	And for some other reasons in the hardware, like we have pretty good reason to believe that silicon physically cannot support this, this low frequency, like we're missing a few extra gates, we're missing a few extra divider chains, we're missing enough hardware in the actual RF core where there's realistically no way that this can happen in silicon.
1609420	1611680	So begrudgingly, we had to add some parts.
1611740	1613980	And one of those is external mixer.
1614580	1622500	Usually when you start buying discrete RF parts, they get expensive because the companies that make them know that you're probably pretty smart if you're buying RF parts, and you can afford it.
1622720	1628160	But we found a nice old, decently old part, it's called a max 2671.
1628160	1635900	It's a up converter mixer for I believe, like decked cordless phones, but they operate in about the right frequency range.
1635900	1646040	Because they have multiple part numbers that's effectively the same silicon, and we're jellybean parts in like the late 90s, there's still enough stock floating around where you can get these quite cheap for like what they are.
1646780	1653640	And because these are dedicated mixer ICs, we do get the benefit of it being a proper like Gilbert cell double balanced mixer.
1653660	1656560	So the silicon quality of the mixer is very nice.
1656640	1661960	And like, you know, we'll take every bit of dynamic range and noise, like low noise figure that we can.
1662540	1673700	The downside to using a mixer though, like a discrete mixer is that we need to generate our own LO or like our own local oscillator frequency reference for how much we want to shift the incoming radio signals by.
1674360	1680720	And to generate an LO, again, the off the shelf solution would be to buy a dedicated RF synthesizer chip.
1680720	1683500	But once again, these are expensive and also quite power hungry.
1683660	1689840	So we're thinking, well, if we don't want to buy a dedicated RF synthesizer, like what other options could we have?
1690120	1703880	And as I was like looking through just any chip I could find that kind of does anything related to RF, I came across these series of chips, like really, really tiny SAW 23 guys used in like these ultra low cost AliExpress garage door openers.
1703880	1712440	And it gives you these like random, like throwaway little, you know, you press a button and it receives it on the other end, like as like a GPI open basically, but it's over RF.
1712460	1719880	And what these are, are either OK, like on off keying or like GFSK, little single transmitter receiver pairs.
1720240	1730180	And the specific part we chose a CMT2119A, it's transmit only, but it has a like SPI retunable range of 240 to 960 megahertz.
1730380	1739700	Now this is designed to where you have a data pin that you clock in your digital data on and it, you know, translates that to like, it modulates that into RF, then you receive it on the other end.
1739700	1746600	But I mean, if you think about it, like on off keying, where you just hold the data pin high forever, I mean, that's basically continuous wave, right?
1747500	1751280	It's only on off keying if you turn it off and we don't turn it off.
1751280	1754000	And you're like, there's no way this works, right?
1754000	1756020	Like will the chip work?
1756040	1770000	And so we like threw together a quick test board and like to our surprise, not only did like the chip work, like really, really well, like it, you know, handled it running indefinitely long, we found that our actual like phase noise and like our spur performance is really,
1770000	1770640	really good .
1770960	1779900	And would actually like quite handily beat my USRP, like SDR for both frequency stability, power stability and like spurs.
1780160	1792160	So not only like what we like, we went into this thing that we might have a comp, like, we might have to make a compromise with this, like chip as our LO, but actually turned out to be a really, really good RF synthesizer.
1792400	1810520	So with this RF synth chip, our mixer, and then the SimpleLynx front end and the demodulation and RF core, like that finally gets like lets us complete the entire signal chain and do antenna to up conversion to down conversion in the SimpleLynx demodulation,
1810520	1821680	like the signal chain processing, audio DSP, all that, like all that good audio processing stuff that Robert was just talking about, and then DMA that out to our I2S stack and then finally get in your earbuds.
1824340	1830020	So with that, there's one more feature that we want to talk about and that's our OLED.
1830780	1841980	So pretty early in the design phase, we came up with the aesthetic choice to use this like commodity 1.3 inch I2C OLED, but commonly I2C, they support other standards, and we're using SPI.
1842320	1845440	And they will be listed as SSD 1306.
1845440	1847960	Although as we're about to find out that might not be true.
1848660	1852160	But we like these because I mean, they look they look good, you have really good contrast.
1852160	1855100	And they're also pretty common parts, they're fairly low cost.
1855100	1863920	And we were thinking that, hey, this is, you know, tons of people use these in projects, like you can find 1000s of projects out there with this, like this little SSD 1306 screen.
1864040	1870520	So sure, like this will be great, because we can save a bunch of time, we don't have to reinvent the drivers from the ground up, and it'll just work, right.
1872640	1879140	So we wanted to do SPI and DMA as the highest possible FPS interface to the screen to get a nice fluid UI.
1879340	1883600	And right away, we noticed a problem that, well, yeah, you have really bad screen tearing.
1883760	1889520	And this is to be expected, like we're throwing pixels at it as fast as our SPI, like in DMA can do.
1889600	1891160	And there's no sync.
1891340	1895820	So we like until we are synchronized, the displays frequency, of course, we'll get screen tearing.
1896060	1899760	So sure, this works, just how do we turn on screen tearing.
1899880	1905320	So we started looking into this, maybe we should have looked at this before we committed to it.
1905380	1906780	But we started looking at this.
1906780	1908260	And what do I see?
1909140	1914780	Oh, apparently, this is unsolvable.
1917200	1920460	So what are we up against?
1920840	1931340	Well, in theory, the SSD 1306 controller outputs a sync signal on this pin they call FR, like frame, I don't know what it is, they don't think they actually ever tell you what it stands for.
1931600	1948860	But this is really actually interesting and kind of an inversion of the normal paradigm with like screens, because this screen, not the host is what control sync, the pixel clock for the screen is not is not something you feed to the screen, it's actually generated internal to the screen with a little like RC oscillator.
1949160	1965140	And like any other like any RC oscillator, that's like the actual exact frequency of that is subject to trims, like, you know, the exact temperature, time, like humidity, a bunch of environmental factors, process factors, just manufacturing variability,
1965140	1970360	it's basically, it's a complete unknown and you would need like closed loop.
1971000	1979900	Without a closed loop feedback system, such as this, like FR signal, you cannot know, like 100%, what the actual pixel clock is.
1980980	1985920	And while this sounds great, and we saw this on the data sheet, like, oh, yeah, there's a signal, like, it'll be it'll be fine.
1985980	1993180	It turns out that actually none of the panels that are manufactured have this signal broken out from the chip to the ribbon cable.
1993600	1997800	And as we found, actually, a lot of them don't even have it broken out from the ASIC at all.
1998620	2004260	So I went in search of this FR pin, and see, can we probe it at all, like even just for debugging.
2004740	2012980	And my first thought was to probe the traces on the glass directly, like this metallization layer that's deposited on the glass, and then the chip is like kind of pasted on top.
2014020	2024140	And something I found that we weren't expecting is that what all these little displays that they call like the SSD 1306, most vendors actually have no idea what they're selling.
2024160	2031360	See, the SSD 1306 is not the only OLED controller, it's one of the OLED controllers.
2031700	2039820	And a lot of people have been making clones, and then clones of the clones and clones of the clones of the clones, and then clones of those.
2039860	2048680	So as we were trying to like back solve the device, the family tree of this controller, we found that there's multiple companies, some which are seemingly related and not.
2048680	2053300	And there's this whole huge mess of like, what controllers could actually be on your panel.
2053300	2055340	And the problem is the vendors generally don't know.
2055520	2063840	And even things like the exact like the silk screening on the actual ribbon cable that's bonded to the screen, I found examples where even that is wrong.
2064040	2075080	So because they, the manufacturers view this as compatible, like either 100% binary compatible, or like, you know, oh, you change one register and your code still works.
2075080	2076840	Well, it's not the same chip.
2076840	2085560	And as we're like finding out that there are like notable differences between them, that makes some things work on certain controllers, and some things work on only other controllers.
2085560	2090380	And actually being able to know what controller you have is a very, very difficult problem.
2090580	2093680	And I'm not sure there is a guaranteed way to know.
2094580	2097340	But, like, why does this even matter?
2097340	2102440	Well, it turns out the SSD 1306 is one of the earlier controllers and one of the more well featured ones.
2102760	2110060	And while that has an FR pin, the clones do not, or the derivatives of that do not, the cheaper, lower cost controllers.
2110140	2111920	And it's kind of like a cache 22.
2111920	2119000	Because no one was bonding out that pin from the SSD 1306s, the clone guys like, well, we're gonna save the pin, we don't need it.
2119000	2126480	So they actually just got like they get rid of the sink pad on the actual silicon, like the circuitry in the silicon just doesn't exist.
2126700	2133880	So then the manufacturers like buying these cheaper chips will be like, well, there's no sink pin on the silicon, so we're not going to bond it out.
2133880	2140020	And then that's like the feedback cycle of you end up with no OLEDs with this sink pin in existence.
2140740	2162100	So as I took some microscope shots on the lower right picture, you can see this kind of like, little frowny face, that darks that the darker rectangle is the actual pad on the silicon where this FR pin on an SSD on an actual authentic SSD 1306 is, and it's not connected.
2162100	2164520	So I can't probe that.
2164880	2168240	Well, that led us to look for other ideas.
2168240	2172280	If we can't extract timing information from the display, can we inject it?
2173540	2183780	You actually can supply your own clock to these panels, which would actually solve all of our problems, because if I can give it the clock, I will always know like deterministically what that clock is.
2184200	2188420	And it's called, you know, they give you a nice clock multiplexer so you can feed it in.
2188420	2190420	And of course, no one bonds that out either.
2190460	2193480	So that pin also exists and you can't get it.
2194460	2201920	We've asked the manufacturers this is the kind of problem where they're like, okay, if you're not ordering 5 million of these OLEDs right now, we're not going to like entertain this idea.
2202600	2209780	The SPI or I2C interface is read only because that saves like, you know, four more AND gates of not having to support register readback.
2209780	2217920	So you can really only just throw data at the screen, you can set up a couple configuration registers, and really, they just wanted to throw data at it and you can't read anything back.
2218220	2229340	So the any thoughts of like trying to find a register or like, maybe there's a register that has like a current scan line or anything of that sort is completely off the table because the digital interface to it is basically write only.
2229720	2232920	And the only other pins that we have on the ribbon cable are for power.
2233060	2239720	So we don't want to modify the OLED like and try to do something custom because that's unsolvably expensive.
2239880	2242520	So we are effectively out of options.
2242520	2245060	Now there's the sync pin doesn't exist on the ribbon cable.
2245080	2249760	The like digital interface is write only and all we have left is power.
2250140	2253260	So is there anything we can do with the power pins?
2254240	2266680	Well, aside from 3v3 logic, like the actual digital interface to your microcontroller, the OLED needs like higher voltages to actually drive the pixels and make them glow, nominally like call it around six and eight and a half volts, like something in that neighborhood.
2267680	2276720	And as a like little convenience feature, these controllers have charge pumps that will do a doubling and tripling of your 3v3 rail to generate these higher voltages.
2277040	2282140	And so just so you don't have to do it, all you do is throw on two capacitors and like you're you're done.
2282500	2285400	And charge pumps are a form of switching regulator.
2285440	2289760	And the way that they do this is by switching the voltage on and off the capacitors.
2290280	2305680	And well, as I was doing some testing, since there's a register you can actually set that margins the oscillator frequency higher or lower, I found that hey, the like, as I make the pixel clock go faster and slower, the charge pump clock happens to go a little bit faster and slower.
2305920	2308800	deterministically with how I set the pixel clock.
2311300	2320020	And it turns out like probing the actual charge pump capacitors that yes, the charge pump switching frequency is actually an exact integer ratio.
2320020	2322620	It's like half the speed of the pixel clock oscillator.
2322620	2325660	And this makes a side channel possible, right?
2325700	2334660	That we can recover the clock we can do if we do clock recovery on this charge pump signal, we can actually recover the exact closed loop frequency that the pixel clock is running at.
2334940	2344960	And there's only one other problem with this is that the density of the pulses since it's not on on the on all the time has to do with the contents of the pixels on the screen.
2345060	2353800	So for example, if you're showing 100% all white pixels on the display, then you need the most current from the charge pumps to drive all of those pixels on.
2353800	2367740	So the charge pumps will be running basically as a square wave of you know, constant, constant on time and duty cycle with 100% density, it's a square like it is trying to drive as much current as it can to the pixels.
2367820	2372900	But if you make that display then all black, you're effectively requesting no current from the charge pumps.
2373120	2380220	And because it's a power regulation loop, they will go to a very low pulse density and I mean, they don't need to drive current.
2380940	2385620	And that's solvable with a PLL or like other clock recovery techniques.
2385620	2404020	But as we already talked about, this is a 48 megahertz little microcontroller like doing this kind of like dynamic side channel and correlating that to the pixel contents of the screen and then doing that fast enough to know where we are in sync and then making sure we don't lose the sync like this is a this gets pretty pretty like yucky pretty fast.
2404200	2410980	And then also a little bit like a side tangent that this technique also seems to only work on some of the controllers.
2410980	2419220	So like the aforementioned SSD 1306 works, the very low cost CH1116 is also like has this effect.
2419220	2425280	And we found that the maybe now more common SH1106 controller actually does not work like this.
2425280	2428940	The charge pump frequency does not depend on the pixel clock.
2428940	2435060	And we said, like we think that either it has its own, like completely separate way of clocking or there's just no clock and it's just done in analog.
2437000	2450140	Well, going back to this, though, if we could get 100% pulse density, like not related to what's on the screen, instead of doing all this like complicated PLL side channel recovery timing shenanigans, like all you'd have to do is count edges, right?
2450140	2453460	The number of pixels on your screen doesn't change per frame.
2453880	2455660	And all you'd have to do is count edges.
2456520	2462060	And as we like talked just like mentioned that the density of these pulses relates to panel current.
2463280	2471560	And as we started looking into this, we went, maybe I went a little bit too far, because we started decapping these chips, found a way to pull them off the glass.
2471560	2479280	And then we're just looking, just kind of like hunting around for anything we could find that might help us get more information on this and get closer to this achieving this sync.
2479840	2484960	And the opcode space for this controller is like you send an 8-bit opcode.
2485100	2491380	But of all the documented commands in the data sheet, if you kind of like, you know, graph them out, you'll see that there's a lot of holes in there.
2491580	2495700	And a lot of undocumented or reserved space.
2496100	2503880	And well, what do you do when you have a bunch of undocumented opcodes, we do automated fuzzing in hardware on an OLED controller.
2504060	2518460	And after running this for a couple hours and a couple days, I was basically listening to the charge pump as an audio signal, trying to see, you know, can we get any change in these in the behavior of the silicon actually started yielding some very interesting findings.
2518940	2523680	There's actually multiple undocumented charge pump modes, like in the register that sets voltage.
2524280	2535640	For example, what that lets us do is instead of doing the pixel clock divided by two frequency, you can actually overclock your charge pump and run it at the pixel clock frequency doesn't really get us anything right now.
2535640	2542320	But it is something interesting that to see results basically right away, that there are a lot of secrets buried in here.
2542320	2548960	And then when we see that there's maybe one secret buried in here, then we're going to go all in and try to find all the secrets buried in here.
2549460	2555240	I found another undocumented command that lets you well, I suppose lets you adjust the internal references.
2555260	2558060	So kind of like your current and voltage references.
2558060	2565860	And as you start tampering with that knob, if you make the chip believe that it's actually pushing less current than it really is, then it will run the charge pumps harder.
2566200	2570100	And running the charge pumps harder, of course means increasing your pulse density.
2570280	2580680	And that's when I found for the first time that on at least the screen I was testing with on a fully black screen, we could get 100% charge pump density, aka we win perfect sync of just edge counting.
2581220	2596540	And while that is amazing, was really exciting at the time, certain screens then as like, again, depending on manufacturing tolerances, will then not do 100% density at that cranked up mode, like maybe we'll work on some but then on some other ones, it doesn't.
2596620	2599520	So more fuzzing, more searching through opcodes.
2599680	2608980	But then finally, we landed on the our final solution here, which is the burn in mode register or what we believe is the burn in mode register.
2609380	2615180	And if you are interested in playing around this at home is command D zero and you set it to 01.
2615860	2623200	But what this does is basically just tell the charge pumps to run at 100% all the time, like it does exactly what we need to do somehow.
2623580	2635200	And regardless of the pixel contents, regardless of any other setting, this command mode will tell the charge pumps to just run 100% on all the time, max voltage, doesn't matter what's on the screen doesn't matter what else you do.
2635320	2645960	And this lets us get our perfect sync, we have 100% guaranteed deterministic closed loop control, all we have to do is count edges, and which we know by just how many pixels we're clocking out.
2646020	2652340	And then you take that through and a few other undocumented commands for good measure like that margining and some things to make it nice.
2652380	2662280	And then that lets us finally for real achieve the effect we want to go for, which is our four color perfectly stable gray scale, regardless of pixel contents.
2666760	2674520	So now that we've got this great display synchronization, we wanted to create a graphics engine to actually drive the OLED.
2674600	2682880	We wanted to have a cool UI and some really nice graphics but didn't particularly want to write a full animation rendering engine in C.
2682980	2692740	So instead, we wrote a virtual machine to run a full animation system to actually render all the animations, which we call ANSM or animation state machine.
2692920	2697920	So the idea behind this was just create a sequence of multiple frames with the delay in between.
2697920	2701400	But as all things do, it slowly started to gain more features.
2702060	2706620	But the whole, we wanted to be able to allow graphics to be developed independently of firmware.
2706620	2716120	So while we were doing all the development with the sort of, like OLED and the DSP, the frames and stuff and all the graphics can be generated.
2717100	2730360	So some of the features we wanted to kind of ended up going in here was you could have multiple frames kind of be chained together of either grayscale or monochrome, but it's got your standard jumps, loops or randomness.
2730360	2732020	It can also support input events.
2732060	2735760	So allows like any sort of button presses to actually cause reaction.
2735760	2741580	So every time in your main menu, when you hit the up button, that's not C code actually seeing the up button and doing the action.
2741580	2749020	That is a virtual machine which forwards it into the ANSM script, which will then have a vector handler to then react to the button press.
2749180	2756320	Then to actually allow multiple events to kind of exist and have different menu modes, you can actually chain multiple of these ANSM scripts together.
2756380	2766200	So after you finish the button press animation, you can then go into another ANSM program for like the next menu item or the sub menu for like the airband player and things like that.
2766400	2775660	There's also support for preemption to kind of every time you see a sleep animation, it's actually preempting and launching another ANSM script while another one is kind of in sleep mode.
2775880	2779920	And it allows, it'll yield back controls to the previous script when it's done.
2779920	2781860	And you can also send signals out.
2781860	2790060	So on the actual, when you hit like the volume up button on the volume menu, that's the ANSM script actually saying, hey, to the firmware, please turn up the volume.
2790180	2796780	So all of this, like the UI was actually not really developed in C, but it was developed in this ANSM scripting language.
2797040	2805680	And so this just allows a lot of the UI to be offloaded and live in ANSM scripts rather than inside of the actual C code.
2805680	2807740	And of course, there's also a host emulator.
2807740	2811480	So you can run the VM and develop all this without even having an SAO.
2811480	2818420	So this was one of those small creature comfort things that ended up spiraling into a full virtual machine.
2818420	2822420	But that's what's running your, your UI on here, this ANSM script.
2822420	2844120	So and one final small thing is the ITC support for this, we wanted to have the ability for winglet to control it, like the main badge, as well as so you have your basic tuning, but all the settings and presets we loaded in with presets for Vegas, but you're going to go home and you're probably going to want presets from your local region.
2844120	2849100	So if you have a badge, you can program it with the UI, it'll give you settings to modify it.
2849100	2850860	But it's also available over ITC.
2850860	2855760	So we'll be looking at trying to release all the commands to do the reprogramming.
2855760	2859800	So you can just have an Arduino or an ESP 32 and change all the presets yourself.
2859800	2863180	So all this control is available over ITC.
2863540	2866820	But the only issue with that is there's only one ITC interface.
2866820	2870300	And we also need ITC to control the DAC.
2870540	2883560	Now, the same thing would be to do the ITC device inside of the actual hardware peripheral, which is designed to be asynchronous clock and derive the clock from like the ITC controller with like bit banging it.
2883560	2889220	But we wanted to use ARP to allow easy hotplug detection and make it kind of just work when you plug it in.
2889640	2901720	So the we're using this fifth sensor controller core inside of the chip just to run an ITC controller, do all the clock recovery and clock synchronization to fully implement like an ARP compliant ITC device.
2901720	2903760	So you can listen to two addresses at the same time.
2903760	2913480	So it has auto hotplug detection, removal detection, you don't have to worry about colliding IDs, you can plug three of them on the same ITC bus and they will all just work and figure each other out.
2914360	2920260	And it also we're also trying to work with other badge makers to kind of standardize this SAO identification and hotplug.
2920260	2926140	So all the SAOs that have like microcontrollers on them can have this kind of just works experience and auto detection.
2926140	2929140	So that's the thing for that.
2929140	2933320	But yeah, that's our the work we've been doing this past year.
2933560	2934680	Thank you.
2944120	2946960	Yeah, I think we have at least around five ish minutes for Q&A.
2946960	2949760	So if you have a yeah, if there's any questions.
2955100	2958020	I don't believe we have any more right now.
2958020	2963180	And I don't I have no, I don't know if we'll have any more.
2963260	2966260	That's a ask their their space village leads question.
2966260	2969220	But unfortunately, no, I think we are out of stock.
2972370	2973330	Question.
2977790	2981730	It can transmit I have removed all the transmit capabilities.
2981730	2984490	So we aren't transmitting out on airband and things like that.
2984510	2984830	So
2988290	3002690	yeah , there is a some some things have been removed to make sure it's receive only but yes, it's a transmit capable and it would be interesting to do other projects with this to kind of create things because it's a very powerful chip and having this low level access would be really nice.
3002690	3012210	One thing like maybe worth mentioning as a side note on like transmit is that while we can do arbitrary IQ receive these chips do not support arbitrary IQ transmit.
3012310	3013630	They are quite flexible.
3013630	3018290	And you know, the more like crazy you get with the low level firmware, you can make them do crazier things.
3018290	3023970	But just like we also had that initial idea of like, hey, can we do IQ transmit?
3023970	3024570	No.
3024770	3028190	But it is quite flexible in the transmit modes regardless.
3030250	3031130	Question.
3032210	3034150	We will open source.
3034150	3041470	I think the ANSM and then we'll like the all the ITC stuff but some of the we've been very busy.
3041730	3044590	As you can imagine getting everything ready for this DEF CON.
3044590	3046650	So we don't have things ready like right now right now.
3046730	3057010	But we're hoping to trickle some stuff out in the coming, you know, coming weeks, as we as we recover on sleep, like like the ANSM toolkit, like I think that's pretty cool having like that animation framework.
3057470	3066250	And you know, since we already made a virtual machine, if you can put it on anything else, like all the tooling, all the scripting is there and like, we'll go through what we can.
3070260	3071140	All right.
3071300	3072300	Thank you.
