Saturday, April 16, 2016

Wifibroadcast - measuring latency on a laptop

My method of measuring the absolute latency scene-to-screen involves the camera looking at the receiver screen which is partially obstructed by a smartphone running a stopwatch, all being recorded by a Casio EX-F1 at 600fps.











The darker one is the smartphone screen, the lighter, grainy one is the laptop. I picked shots where both numbers are not blurred as they are changing.
Phone has an LCD, not AMMOLED display, so it tends to blur fast changing stuff. Both displays (phone and laptop) should be TFT, so about as fast as a consumer-grade LCD can be.

The mathematical average of these 10 shots is 197ms. Not too bad...

Sunday, April 10, 2016

Wifibroadcast receiving on a PC

Yup, you definitely can watch on a PC. (And there's no limit on how many! :D)
Tested on a Lenovo x230 running Ubuntu 14.01 LTS x64 with a TP-Link TP-WN722N.

Installing wifibroadcast:
open Terminal or some other commanline and input:

  • sudo apt-get install mercurial libpcap-dev iw
  • hg clone https://bitbucket.org/befi/wifibroadcast
  • cd wifibroadcast
  • make
If there's no screaming or error, you may proceed with connecting the wifi card and waiting until it lights up. Then proceed with setting it up:
  • cd $HOME/wifibroadcast
  • sudo ifconfig wlan1 down
  • sudo iw dev wlan1 set monitor otherbss fcsfail
  • sudo ifconfig wlan1 up
  • sudo iwconfig wlan1 channel 13
Run the program with:
  • sudo ./rx -b 8 -r 4 -f 1024 wlan1 | gst-launch-1.0 -v fdsrc ! h264parse ! avdec_h264 !  xvimagesink sync=false
Once there is a valid signal from the transmitter, the wifi LED will start flashing and shortly after you should see a window with the stream pop up. 
To infinity and beyond!

You can close it with ALT+F4 and stop the wifi with 

  • sudo ifconfig wlan1 down

To start it up again, repeat the setup (no need to install anything again) and run the program. Here I'm using wlan1, because I'm assuming that like me, you'll be using a laptop, so wlan0 will likely be taken by the internal wifi card. This may however not be the case, unless you are sure, check with ifconfig

Scripting it because typing everything is for noobs

1) create a new file (with no extension) and open with a text editor of your choice (I used gedit)
2) paste the following into it:
  • cd $HOME/wifibroadcast
  • ifconfig wlan1 down
  • iw dev wlan1 set monitor otherbss fcsfail
  • ifconfig wlan1 up
  • iwconfig wlan1 channel 13
  • ./rx -b 8 -r 4 -f 1024 wlan1 | gst-launch-1.0 -v fdsrc ! h264parse ! avdec_h264 !  xvimagesink sync=false
3) save to a convenient place, like /home
4) type the following into terminal, replacing "script_name" with the actual one you saved:
  • chmod 755 "script_name"
This gives the script read and write permissions.
5) to run the script, you only have to type:
  • sudo ./script_name
Again, replacing "script_name" with the actual one. You have to use sudo, because it needs permissions to tweak the wifi dongle. Without it, it'll never run.

Saturday, April 9, 2016

Dual boot for Windows 8 with Bitlocker and Ubuntu 14.01 LTS, UEFI version

  • Make sure you are booting in UEFI, not legacy mode. Seriously, check that shit.
  • Turn off secure boot.
  • Windows 8 goes first. For good measure, make sure the drive is GPT, not MBR. This can be done even in the install by clicking the "repair" and clicking your way to a commandline (tons of how-to's on teh interwebs)
  • If you need to make a UEFI-capable install USB flash, simply use diskpart to: 1) clean the drive 2) convert to GPT 3) create a primary partition DO NOT mark it active!!! 4) format it to FAT32 5) assign a letter. Close Diskpart, if you have a ISO somehow extract it (W8 and later can mount ISOs as a virtual drive; winzip can open it like an archive), dump the contents straight to the flash.
  • Create a patition for windows, make sure you leave enough space for Ubuntu, 10GB seems to be the recomended minimum. Windows installer should tell you that it's going to create additional pratitions, there should be a total of 4 including the one you made.
  • After the install and initial config, set up Bitlocker, save the keyfile outside the encryped drive, encrypt drive. Take ownership of the TPM. Reboot and make sure it works.
  • Disable fast boot, otherwise stuff WILL BREAK. There's little difference having it on for SSDs, magnetic drives are a different story though. The checkbox can be found in power management ->buttons setup ->the top "change what you can't now..." checkbox -> allow fast boot (uncheck).
  • Install Ubuntu. Bootable USB the same way as for windows. I chose 14.01 LTS, but I see no reason the newer versions would not work. Run the setup in "install alongside windows" mode. Partitions can be shrunk later. Make sure you note down all the passwords and pass phrases you set up. Test Ubuntu boot.
  • Test Windows boot. Most likely it will require you to input the key that you should have saved outside the encrypted drive. If you didn't, you're a dumbass and now have locked yourself out. Best start over.
  • boot Ubuntu, Change UEFI boot order via efibootmgr - in terminal type sudo efibootmgr -v  to see whats going on (you'll see quite a few  things with 4-digit numbers, and the boot order), then type sudo efibootmgr -o with the altered boot order. You'll most likely be switching the 2nd for the first. This is not fuck-up-resistant! You screw up - no worky worky!
  • If windows boot works, reboot again. If it keeps requesting you input the key every time you boot, you have to take ownership of the TPM again. If the greedy bastard keeps insisting you input the key over and over again despite you taking ownership of the TPM, something's fucked up and you have a long Google session ahead of you.
  • You will most likely not see any mention of Ubuntu during boot anymore, but fret not, try mashing whatever key brings up the boot menu before it starts booting, you should see "windows...something" and "ubuntu". This will be the way for choosing. Should also work for additional UEFI installs, the names seem to match the directories in the \EFI  
  • Turn secure boot back on
  • Install drivers and crucial software for both systems, make a disk image. Seriously, do that, the time you save when reinstalling is makes this worth it. Save the keys, passwords and passphrases with the image, as it's useless without them.
  • Enjoy your dual-boot.

This was done on a Lenovo x230 running an aftermarket SSD, Windows 8.1 and Ubuntu 14.01 LTS, all from UEFI-capable bootable USB flash drives. Both OSs run in secure mode with no bitching.
The boot menu is slow to load (10s for me), but that seems to be feature, not a bug.
Your results may vary, as i uderstand UEFI implementation is not perfectly the same for all PCs.

Thursday, April 7, 2016

Dual boot for Windows 8.1 and Ubuntu with encryption galore, MBR version

word of warning - this is for patient people only. If you are known to chimp out after 4 hours of something refusing to work as it's supposed to - I'd suggest something different...

On to the magic, why would you do this?
I have a Lenovo x230 laptop to which I cheaply bought windows 8.1. Once you get Classic Shell installed, it even mostly feels like W7 which boots insanely fast. I'll gladly admit that I'm a windows guy, it's what I feel at least slightly comfortable working with since I practically grew up with it. Venturing into Linux territory usually means Google is working overtime and it takes a fuckton of time to get anything done, because everything is different. Don't even get me started on OS X.
That being said, Linux allows for certain unicorns that are not possible (or horribly difficult) on Windows because of the way the drivers work. Monitor mode for WiFi adapters is one of those things, extremely useful if you wish to do any type of poking with WiFi, good or bad. It's what allows Wifibroadcast to shove packets into the WiFi adapter without caring where or if even at all the end up at. It also allows receiving mangled packets (only some chipsets though, Atheros has long history of that).

Why would you do it like I did?
These days, a healthy dose of computer paranoia tends to be quite reasonable, given how much sensitive info can be extracted out of your daily use PC. Just the windows password is the equivalent of a 1 meter high decorative fence around your house. Enough to make normies understand that you don't want them rummaging through your stuff, but obviously very easy to defeat by multiple methods. So, if you want something a little more resilient, there's encryption.
Now common 256bit AES is enough to make even American 3-letter agencies pissed (btw it's approved for use on top-secret information), your average tech-sawwy criminal has no hope in hell of defeating the encryption itself, (it's much easier to literally beat the password out of the owner) at least not in his lifetime.
Naturally, the one thing I was satisfied with on previous OS versions doesn't really work for W8, so I have to use Bitlocker. Because of how this thing works, IT needs to be the first thing to boot, otherwise it's a no-go. Yes, having to boot most of windows only to tell it that you want linux and letting it reboot is kinda silly now that I think about it, but until M$ acknowledges that they could do a better job on the bootloader, it's the only way of running it like this.
If it weren't for the Bitlocker part, you can happily use the automated install and let linux configure everything for you. But if you need your tinfoil hat, it's hacking time!

Loosely following this guide, (loosely meaning not everything was exactly acording to this guide, there were others as well...), I created 2 partitions for Linux, one for root, the other for swap. The root one needs some space to be usable, exact figure depends on what you want install, but mine is roughly 20GB. Swap should be more then happy with 4GB, although I used 8GB. Don't know why (the machine has 8GB RAM), but I saw this once the win was set up and I didn't feel like doing it again (can't move the boot partition without breaking booting).
Then I let windows create it's boot partition and gave it some reasonable space for C:, roughly 50GB and let it install. Once that's done and you have most of the stuff installed, turn Bitlocker on, configure the TMP, then turn it off again. (where have I heard that before...oh right, I have the misfortune to do IT support for a living...).
Once that's done, I'd suggest making an image of the machine, because if you fuck up the following steps, it's really hard to fix. Much easier to just restore. I personally like Clonezilla. I tend carry in on a multiboot flash along with other goodies.
Install your Linux of choice, but you can't use the "auto" install, you have to do it manually. Tell it to use the bigger linux partition as /root and format it to EXT4 and to use the swap as...swap. Install everyhing. Once that's done, DO NOT let it place the bootloader into the MBR (if you do, windows will not boot), instead plop it into the /root partition.
If you've customised the crap out of the thing during install and windows STILL boots, make another image, saves time if you fuck up the bootloader.

Now comes the "fun" part. (link to source)
Boot some kind of linux from a flashdrive, somehow determine what is your partition of interest (gparted has a nice GUI; or just fdisk -l) and make note of it, it has to be the /root (or whatever you stashed the bootlader into). Do dd if=/dev/sda1 of=/tmp/linux.bin bs=512 count=1 , replacing sda1 with the patition with the bootloader.
This will make and copy linux.bin into the tmp folder (it's in /root). From there, copy it either to a flash drive or if you feel like it, plonk it straight into the root of C:. Boot into windows.
Launch cmd with admin rights and do bcdedit , it should dump the current state.
Now, do bcdedit /create /d “GRUB” /application BOOTSECTOR , you can replace the "GRUB" with whatever you want to name the entry (it will show up as the selection of what to boot). You will get a long GUID in curly brackets, copy that shit.
Now, do bcdedit /set {GUID} device boot , {GUID} is what you should have copied from the previous step.
Next do bcdedit /set {GUID} PATH \linux.bin
then bcdedit /displayorder {GUID} /addlast to put it below the win8 selection,
then bcdedit /timeout 10 , the number is timeout in seconds. I recommend less, 5s is plenty enough.
The final step is bcdedit /set {LinuxID} device partition=C: , this tells it which actual partition it can find the linux.bin.
Once you feel you did all that you should, do bcdedit again and check that the second entry looks something like this:
Real-mode Boot Sector
---------------------
identifier              {a33bafb4-fc1d-11e5-8259-3c970e62ae2e}
device                  partition=C:
path                    \linux.bin
description             Ubuntu
Obviously, the identifier will be diefferent and the description will be whatever you made it.
The device part is what took me almost 8 hours of trying various things, including different distros and what have you, only to realize that there is no way the system can know where to look for the bootloader. After extensively searching how to use the bcdedit /set , I found this, did it, tested it, found it working exactly as it should, did the "yatta!" and went on to post a comment to the M$ blog article, only to find THAT EXACT THING THAT TOOK SO LONG TO FIND was there all the time... read the comments...
If both systems boot, turn on bitlocker, make sure TPM is running (otherwise you'll have to manually input the long key every time) and let it encrypt.

Last but not least, make a partition on the remaing unused diskspace and format it to NTFS. Then install Truecrypt (or other encryption SW of your choice) on both systems and encrypt the partition, it will serve as a safe datastore that both systems can access.

Now make the final image of the machine and store it safe, unless you want to ever go through this again. Enjoy your reasonably secure dual boot system.

Saturday, April 2, 2016

polishing the turd some more

To address the light performance and increase the view angle, you need a different lens.
To hold the lens, you need a lens holder. Like this one. (not optimal*, but can be made to work)
Before you buy said lens holder, note that the hole spacing on the camera module is 21mm, not 20. Holders with 21mm spacing seem magically more expensive, even though they are made from the same material using the same technology. Before you put on the new lens, the old one obviously has to go. This needs needle-nose pliers and a bit of persuasion, but it's not terrible hard.
Because of the hole spacing, I had to secure the holder with wire and then glue it to the PCB. Then I could screw in the lens and focus it.

So, without further ado, I present:

Totally not a bomb mk. II

Not a bomb even in the slightest

On the back is a different switchmode converter, not sure about the topology, but it goes both up and down. Uses 2 inductors and doesn't invert the output voltage. buy here
Efficiency is not all that awesome, still draws 2,68W, so pretty much n=80%. Also, it makes audible noise, (discontinuous mode), so it's not matched well for the current draw...

voltage is inverted, so it's rising in the graph
New toy btw. Would be perfect if they added some math functions to the app.

trash TV in action
Viewing it on the trash TV, the latency is barely perceptible, probably close to what the project author measured.



Latency seems to be betweeen 140-170ms, so unless you need to go crazy fast, quite usable.