Friday, September 30, 2011

Perl code for Light Strike decoding

Making progress on my quest to write a 'capture the flag' module for the light strike laser tag guns. Some googling found me this code from Kenneth L. Root. <http://the-b.org>. I hacked it into this the other day and am able to get this output now:




root@rwhiffen-OptiPlex-GX280:/tmp# ./light-strike.pl
Opening port: /dev/ttyUSB0
Opened port /dev/ttyUSB0
Shoot the gun at the IR Sensor
IR Code: 0xe6 0xc2 0x87 0x0d 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x40 0x12 0x40 0x12 0x40 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x3f 0x12 0x0e 0x12 0x40 0x12 0x0f 0x11 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x3f 0x12 0x0e 0x12 0xff
root@rwhiffen-OptiPlex-GX280:/tmp# ./light-strike.pl
Opening port: /dev/ttyUSB0
Opened port /dev/ttyUSB0
Shoot the gun at the IR Sensor
IR Code: 0xb9 0xc2 0x86 0x0e 0x11 0x0f 0x11 0x0f 0x11 0x0e 0x12 0x0e 0x12 0x40 0x12 0x3f 0x12 0x40 0x12 0x0e 0x12 0x0f 0x11 0x0e 0x11 0x0f 0x11 0x0e 0x12 0x0e 0x11 0x0e 0x12 0x0e 0x11 0x0e 0x12 0x0e 0x12 0x0f 0x11 0x0e 0x12 0x0e 0x12 0x40 0x12 0x0e 0x12 0x3f 0x12 0x0e 0x12 0x0e 0x12 0x0f 0x11 0x0e 0x12 0x0e 0x12 0x0e 0x12 0x40 0x12 0x0e 0x12 0xff
root@rwhiffen-OptiPlex-GX280:/tmp#


So I'm getting closer. The results are more inconsistent with the perl code than with the 'mode2 command, which makes me think I might want to do some 'expect' style perl coding with the app rather than direct. maybe something like:




open(MODE,"|mode2 --driver=usb_uirt_raw --device=/dev/ttyUSB0 --mode");


And then do all my interacting with the output via the MODE file handle. That would allow me to get some basic functionality going.


Wednesday, September 28, 2011

Light Strike IR decoding part 2

The continuing saga of my efforts to hack a light strike laser tag system by reading the infrared signals it puts out…

Ok so I just went from being totally stuck and posting that blog post, to being unstuck in about 30 minutes. Ok, so in the last post, I was thinking I needed to figure out what the bit encoding was for the pulses coming in. WHen you look at the in a long row, it's hard to see the patterns. So I was reading the man page for mode2, and it says there's another command line switch called --mode, which is helpfully described as " enable alternative display mode". Ok, what could it hurt right? So I ran it. Instead of getting the two column pulse/space list, you get a more helpful:


6700     650      900      700      900      700
900      700      900      700      900     3150
900     3150      900     3150      900      750
850      750      850      700      900      700
900      700      850      700      900      700
850      750      850      700      900      700
900      700      900      700      850      750
900     3200      850      700      900     3150
900      700      850      700      900      700
850      700      900      700      900      700
900     3200      900      700      900  1382500


Which is a lot easier to read, and makes deltas between two different settings stand out. That one was a blue, this one is a red.


6700     650      900      700      900      700
900      700      900      700      900     3150
900      700      900      700      900      700
900      700      900      700      900      700
900      700      900      700      900      700
900      700      900      700      900      700
900      700      900      700      900      700
900     3150      900      700      900     3150
900      700      900      700      900      700
900      700      900      700      900      700
900     3150      900      700      900  2267300


Notice how C2 R3 and C4 R3 change from 3150 to 700? That pattern holds for yellow and green as well. You end up with a pretty simple table:






If you count the spaces as clock ticks and the pulses as 'bits' you can then start to map things out. The last huge number in C6 R11 is the time between the last event and the next event. The last event recorded does not have this value, it is blank and can be discarded. The first pulse is a 'double-high' value which marks the beginning of a frame. This gives you effectively 32 bits. Now I just have to get a perl or python script to read the device instead of the 'mode2' command and I'm off to the races. That will have to wait for another day however, because I need to get back to work.

Light Strike laser tag

After reading a review on Ars Technica: Lawn warfare: Light Strike brings laser tag back home I decided I had to have some of these at the office. They're pretty cool, mostly gimmicks but they do work. I bought myself a D.C.R.-012. Am probably going to pick up some of the accessories as well. I've talked some co-workers into buying them, so we're almost ready to have some office warfare.

dcr-icon

The trick is, you can only 'death match' each other for so long. And most of the that would be on the honor system, since you can self-respawn quickly. So I've set out to try and make my own 'targets' or flags to play capture the flag with. I have some USB-UIRT devices. I found some Linux drivers at LIRC.org and a CPAN perl module for the driver. So far, so good. I'm able to detect gun output by running:

mode2 --driver=uirt2_raw --device=/dev/ttyUSB0

From the command line. It gives me output like this:

pulse 6650
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 3200
pulse 850
space 3200
pulse 850
space 3200
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 700
pulse 850
space 700
pulse 850
space 700
pulse 850
space 750
pulse 850
space 3200
pulse 850
space 700
pulse 850
space 3200
pulse 850
space 750
pulse 850
space 750
pulse 850
space 750
pulse 850
space 700
pulse 850
space 750
pulse 850
space 700
pulse 850
space 3200
pulse 850
space 750
pulse 850

Unfortunately subsequent firings do not give me identical values. Some times the pulses are 50 higher, so 6700 rather than 850. Perhaps worse still, the other three colors (that was a 'blue team' laser) seem to have the same values. Next I'm going to plug it into a windows machine and run Girder on it and see what that gives me.

Google wasn't very helpful, perhaps because Light Strike isn't a unique term to the laser tag guns. It's used in other contexts as well. So I think I'll pads this post with light strike hacking and other google-able terms. Light Strike IR hacking is a good example of what I was hoping to find a post about. ANyway, hopefully someone who is searching for linux IR hacking light strike guns will find me and we can team up.

Tuesday, July 26, 2011

Canon printer errors from Mac OS X (10.6 and 10.7)

Occasionally when printing to our Canon iR C3080 from Mac OS X 10.6 (Snow Leopard) or 10.7 (Lion) we get the following error:

Cannot continue printing because an error occurred. To continue printing, select [Raster Mode] in [Quality]-[Quality Settings]-[Graphics Mode].: 15920

Google wasn't immediately helpful, so I pieced a few things together and wanted to write them down so I can remember how I fixed it if/when it happens again.

First, We're running the canon UFRII v2.21 drivers from the canon website, so start there if you're not running the specific drivers. Next, you must have admin privileges on your Mac to make the changes I'm about to describe.

Start by going to the CUPS home page: http://localhost:631/

From here you can find out all kinds of interesting things that the system preferences app hides from you. From there, we need to go to the Printers Page. Click the Printers tab on the top of the web page. (http://localhost:631/printers/). In this screen we click on the canon iR printer we need to fix.

Screen shot 2011 07 26 at 111649 am

In my case it's canon.streamsage.com. In the page that follows there is a drop down for "Administration". In that menu we need to select "Set Default Options". On that page we need to set the "General" options by clicking the General link.

Screen shot 2011 07 26 at 112550 am

We need to scroll down a bit on this page to find the "Graphics" option the original error complained about.

Screen shot 2011 07 26 at 112651 am

And set that to Raster Mode. You have to scroll to the bottom of the list of options and click the "Set Default Options" button. It should then prompt you for the admin password. Enter it and you're all set.

 

Thursday, May 12, 2011

I think I might need to wear a watch again

Watchmaker Fossil has a new digital watch they're planning to market under the Meta Watch brand. The website ThisIsMyNext has a good write-up about it. In short, it's a bluetooth connected external display that you can push information to. The idea isn't new. SonyEricsson makes one Casio announced one. Thinkgeek.com sells more than one (one and two). There's probably others along the same line. The SonyEricsson one is the most interesting, it's not only a remote display of callerID but it also has control for your music player on the phone. It's close to what I'd like to have.


Enter the Meta Watch. It's the same idea, but it's basically a blank slate. It's not designed for a specific purpose. It's make with customization in mind. So, you could, for example, push inbox counts, weather forecasts and other data like that. I'd like to use it with my ipod touch so it could summarize the nike+ or DigiFit data. Miles per hour, distance traveled, etc. It's a pain to look at that data on the actual iPod while you're exercising. It also is supposed to have an accelerometer, which gives other possibilities. You could count reps for exercise for example. You could flick your wrist to move from view to view. When you detect the bluetooth MAC address of someone you know, your watch could say "hey, John's near by" or "hide that window, your boss is coming".   


I don't wear a watch since I started carrying a cell phone but now I might have to again.


Sunday, December 19, 2010

Mystery 5.8Gb of app data on my iPad

So I go to sync my iPad for my short trip to Denver. I wanted to put a movie on it so I could watch something on the plane . Imagine my surprise when my iPad had these stats:

201012191312

5.8Gb of App data! Wow. Where did that come from? I go into the apps tab and sort my apps by size:

201012191314

The biggest app I have installed is 190Mb (big to be clear, but not 5.8Gb of big. If I add up all my Apps, I get somewhere in the 500Mb range. Where is all this space going? So I do some googling around and get no where fast. Turns out Apple has changed the way they do backups from version to version. Some say it should be under /private/Library. Some say /private/var, etc... Anyway, I found my backups under /Users/rwhiffen/Library/Application Support/MobileSync/Backup. Under there are some cryptic directory names, likely MD5 hashes. The one I'm interested in is from today when I'm syncing my iPad: 6bf83d2961ea2206b4c08edb555b2b0d89c7f218. Inside there are 4083 more hashed file names. One in particular is quite large:

 


rwhiffen:6bf83d2961ea2206b4c08edb555b2b0d89c7f218 rwhiffen$ ls -lh 5180d2cec771957569b3dc0a8eed20b536fa9185



-rw-r--r-- 1 rwhiffen rwhiffen 4.2G Dec 14 00:22 5180d2cec771957569b3dc0a8eed20b536fa9185



rwhiffen:6bf83d2961ea2206b4c08edb555b2b0d89c7f218 rwhiffen$


 

So that's probably my problem App. Now I just need to figure out how to get 5180d2cec771957569b3dc0a8eed20b536fa9185 translated into something meaningful. There are a few files:

 


-rw-r--r-- 1 rwhiffen rwhiffen 93500 Dec 19 13:01 Info.plist



-rw-r--r-- 1 rwhiffen rwhiffen 660554 Dec 19 13:01 Manifest.mbdb



-rw-r--r-- 1 rwhiffen rwhiffen 126656 Dec 19 13:01 Manifest.mbdx



-rw-r--r-- 1 rwhiffen rwhiffen 7025 Dec 19 13:01 Manifest.plist



-rw-r--r-- 1 rwhiffen rwhiffen 189 Dec 19 13:01 Status.plist


 

That probably have the data, just need to figure out how to read them. Info.plist just has some interesting xml data about my iPad. Manifest.plist looked promising. It was in binary so I had to convert it to xml first: plutil -convert xml1 Manifest.plist (be sure you copy it to a temp location first and don't convert the original...). Manifest.plist looked like a bust too. Status.plist is just the status of the last backup. So no useful stuff there. Ugh.

 

So that means I need to try and slog through the mbdm and mbdx files. Yikes. Fortunately someone else has been there first: http://stackoverflow.com/questions/3085153/how-to-parse-the-manifest-mbdb-file-in-an-ios-4-0-itunes-backup The user Galloglass' solution worked best for me. I cut and pasted his Python code into a file lsback.py and chmod'ed it 755.

 


rwhiffen:6bf83d2961ea2206b4c08edb555b2b0d89c7f218 rwhiffen$ ./lsback.py | grep 5180d2cec771957569b3dc0a8eed20b536fa9185



-rw-r--r-- 000001f5 000001f5 4479500672 1291642994 1291642994 1291592204 (5180d2cec771957569b3dc0a8eed20b536fa9185)AppDomain-com.polishedplay.puppetpals::Documents/ipad/recordings/new/audio



rwhiffen:6bf83d2961ea2206b4c08edb555b2b0d89c7f218 rwhiffen$


 

So it would seem that there is a stray audio recording for PupetPals , one of my kids games. So I deleted it, re-synced the iPad, then added the App back.

201012191341

Now a more reasonable number. Still higher than I would have thought, but not 5.8Gb.

 

Friday, November 19, 2010

More splunk fun...

I've started setting up summary indexes. I take results and put them in a second index for reporting. First you have to create the new index, mine's called "dashboard_summarize". It will require a restart of splunk, just so you know. Next up, the ugly query:


search = host="srchqenmana*" (source="/usr/local/tvs/apache-tomcat/logs/qlogger/*" NOT source="*.gz") "<A9_Request" AND NOT ("FFFFFFFFFFFF" OR "000013ED3AEB" OR "Agent.007") | lookup Market_by_Controller_ID Controller_ID as Controller_ID OUTPUT Market as Market | eval QueryFirstTwo=substr(TextQuery,1,2) | transaction MAC, QueryFirstTwo maxspan=5m maxpause=1m delim="," mvlist=TextQuery | eval LastQuery=mvindex(TextQuery, -1) | fillnull value=0 forward | eval MAC="costtimequalityscope".MAC | eval MAC=md5(MAC)|stats count(LastQuery) as QueryCount by LastQuery, Market, Controller_ID, StreamingServerID, forward | fields QueryCount LastQuery Controller_ID StreamingServerID Market forward |collect addtime=true index=dashboard_summarize


Yikes! Lets break that down a bit. First up we have the sifting portion of the query. Basically search terms that rule data pieces in our out:

host="srchqenmana*" (source="/usr/local/tvs/apache-tomcat/logs/qlogger/*" NOT source="*.gz") "<A9_Request" AND NOT ("FFFFFFFFFFFF" OR "000013ED3AEB" OR "Agent.007")

Next up we have some data lookups. We take the numerical ControllerID and map that to a human readable market name like 'Salt Lake' or 'Bucks County'.

lookup Market_by_Controller_ID Controller_ID as Controller_ID OUTPUT Market as Market
Next we start doing calculations, conversions and transformations of the data. We'll stanza by stanza this part:

eval QueryFirstTwo=substr(TextQuery,1,2)

Eval a field called 'QueryFirstTwo' to the first two letters of the string TextQuery using the substr function

transaction MAC, QueryFirstTwo maxspan=5m maxpause=1m delim="," mvlist=TextQuery

This little gem is a beauty. I wish I could take credit for what the Splunk consultant did there. Basically we define what a single user search is here by defining what a transaction is.. We do not count just the simple submission of a request, because we do live updating of search results after two letters. So if you were searching for the show HOUSE, with live updating you would make a request for HO, HOU, HOUS, HOUSE at every key press. That's great if your just measuring raw throughput, not not a valuable business data point. If everyone is searching for a really long search terms like SUPERNATURAL your usage stats would be skewed. So we roll those up into a single transaction by setting some parameters. First, we time box it at 5 minutes. Second we only allow for a 1 minute pause. Sure there are edge cases where you may exceed either of these time boundaries but it should be a wash over all. Further the MAC address and the first two letters of the search must also be the same. This lets us have typos later on. So if you did HOUU the HOUS because HO would match, it's still in the same transaction. And the last little bit, mvlist=TextQuery says to make a multi-value (or array) of TextQuery values used in this transaction. In my example the list would have ("HO", "HOU", "HOUS","HOUSE"). This comes up in our next stanza.
eval LastQuery=mvindex(TextQuery, -1)

If you look up mvindex and it's syntax, you see that we're setting the field LastQuery to the last entry in the list. In my example, LastQuery=HOUSE. Side note: the page linked for mvindex is titled 'Common Eval Functions' according to the URL. I'd hate to see the uncommon ones.
fillnull value=0 forward | eval MAC="salted".MAC | eval MAC=md5(MAC)

I'm grouping the next three stanza's together because they're doing similar things. If the field named "forward" is null, set it to zero. Next we add a salt to the MAC address to obscure/anonymize it. The MAC (much like an IP address), while not directly identifying an individual is sensitive just the same, and needs to be hidden, so first we add the string salted to the current value of MAC. Think of this like a password or key. Next we convert the string+MAC value to the MD5 HASH of that string. So 000013ED3AEB becomes salted000013ED3AEB which becomes ce431f1c1a634337ca1cdcde78a1d15f. Now if someone knows someone's MAC address and does echo -n "000013ED3AEB" | md5sum to try and figure out their new obscured value, they can't because they don't know the SALT. And because the salt can be of arbitrary length, brute force isn't effective. So it's reasonably protected if for some reason the data needs to be shared with non-trusted parties.

stats count(LastQuery) as QueryCount by LastQuery, Market, Controller_ID, StreamingServerID, forward, MAC
This one is fairly straight forward. Get the number of times the search term was searched, organized by Market (which we looked up in a table before) and Controller_ID, StreamingServerID, and the value of forward (which are app specific fields that only has meaning to us) The why of this is coming up.
fields QueryCount LastQuery Controller_ID StreamingServerID Market forward, MAC

Next we want to take the fields listed above and output them in the search results (why is next).
collect addtime=true index=dashboard_summary

Lastly, we collect this data and store it into an index called 'dashboard_summary'. What we're doing is making a roll-up of searches and weeding out all the cruft that isn't needed to make the reports or dashboards. Further because we've scrubbed sensitive data, we now can let a larger audience view the data by giving them only permissions to this new index. Because the index is lean and mean, dashboards and reports are several orders of magnitude faster than going against the raw data. Further we've pre-paid a lot of calculation expense with the eval's and transaction logic.  
Now I have an index to do my reporting out of that's much faster than the raw queries against all the data.