FTLab Wireless Smart Geiger — Part 5

Previous posts:

So with a bit of help from the decompiled Android application and more poking around, here are some of the quirks found in the FTLab’s BSG-001.

Nordic nRF51822

As said in an earlier post, the device runs on a Nordic nRF51822 and its firmware was clearly started from Nordic’s ble_app_blinky SDK example. We can still find references to the LED Button Service UUIDs from the example.

The protocol

The length byte is always 11

The Bluetooth frames sent from the device start with the opcode it answers, then a byte that looks like a payload length. But it’s always 0b (so 11 bytes) and that happens to be right for two of the three types of replies:

So when implementing a client, it’s safer to know how long each reply is and ignore that byte.

Garbage in padding

Replies are 20 bytes long, whatever the real payload size, but the padding bytes are not always zero (as you would expect…).

I have seen a reply to the “read the name” (31) command holding the end of the last logging-state reply (21). It looks like the firmware uses the same buffer between the different replies and only overwrites the first bytes with the answer, leaving the extra bytes with their previous values. Hope the people who wrote that code will never work with sensitive data…

Write commands don’t reply

The device does not send any reply when setting the name, setting the clock and starting or stopping a run. The only way to know those write commands worked is to query the state again afterwards.

No synchronization

When sending multiple commands, a reply (notification) to an earlier command can arrive after a newer command is sent. So when implementing a client, you have to ensure the response opcode matches the query’s.

Dangerous opcodes

Opcode 30 sets the name. When sent as a single byte, so without length or payload, the firmware reads a length from whatever happens to follow in its buffer and writes a garbage name to flash. At some point my device came back advertising as BLE_Gamma: followed by a newline. Thankfully, properly setting the name with that 30 opcode repairs it.

Opcode 40 is not in the vendor app at all. When sent, the device jumps into its Nordic legacy DFU bootloader and the command fails with ATT error 0x0E (“Unlikely Error”). The device then advertises as DfuTarg and is stuck there until power is cycled.

Dose rates

The “last minute” dose rate is ten times too low

The live reading contains two dose rates: a 10-minute average and the last minute.

They are calculated the same way: the firmware holds 10 counters, 1 per minute, and each pulse is added to the latest 1-minute counter. Then the firmware considers a pulse to be 0.05 µSv/h. So 2 pulses in 10 minutes will report 0.10 µSv/h (which is correct), but 2 pulses in 1 minute will also report 0.10 µSv/h (which is wrong, 1 µSv/h would be correct).

Anyway, with this device, the last-minute counter is not precise enough to be useful. But maybe it can help to quickly detect a spike in case of a nuclear incident?

Both windows move on the minute

The 10-minute average and the last-minute rate only change once every minute, so no need to poll the device faster than that. I guess the firmware has in fact 11 1-minute buckets: the current one and those of the 10 previous minutes. Once the clock ticks the end of the minute, the oldest bucket is discarded and a new one is added. That new one (the current minute’s bucket) is never sent to the client. The previous minute’s bucket is the “last-minute” counter, and the sum of the previous 10 minutes is the “average” counter.

An off-by-one on large values

For the 10-minute window, every dose value should be a multiple of 0.05 µSv/h, since it is a counter of pulses at 0.05 µSv/h each.

But when parsing the multiple history exports I did with the iOS app, recording every 10 minutes, 17 out of about 220 000 values were not. All of them are a multiple of 0.05 minus 0.01.

They appeared on very large values, so there seems to be a bad conversion somewhere. I also got one during a live reading when simulating a spike (flashing a bright light at the device): the device reported 8.14 µSv/h, which is 163 pulses × 0.05 µSv/h − 0.01 µSv/h.

This one is still a mystery.

Max value

Dose rates are stored as 16-bit integers, so the maximum value is 655.35 µSv/h, which is above the announced range (0.05 to 200 µSv/h). But the announced range can probably be exceeded by the following bug (not tested that high though). I haven’t tried to max-out the 16-bit integer to see if the device crashes, stays at the max value or restart from zero.

Recording runs

The pulse counter is not cleared on start

The first record of every logging run is garbage. While the device is stopped, it keeps counting pulses and never clears that counter. So when a new run starts, all of those pulses end up in the first record.

In all my recording exports, 46 % of first records are at or above 1.00 µSv/h, against 0.06 % of all other records.

The day counter is not cleared either

The live reading includes a measuring time in days, hours, minutes and seconds. Starting a run resets the hours, minutes and seconds, but not the days… So a new run may say it started many days ago while in fact it just started a few minutes before.

What about setting the recording session settings when pressing “Stop”?

Start and stop are the same command, 10, with a run byte and a logging duration in days. And of course, when sending a stop command, the device doesn’t ignore the run byte and logging duration… hence changing the settings. So the start command should not first read the settings to reuse the same ones, since the previous stop command may have changed them.

Logging off still looks like logging on

When starting a run with a duration of 00, it actually means: start measuring live but record nothing. In that state the device still reports a logging start time and a 10- or 60-minute record interval.

You can’t set the record interval

There is no command to choose the record interval. The firmware derives it from the duration: every 10 minutes for 1 to 10 days, every 60 minutes for 11 to 31 days.

The clock

Setting the clock does nothing visible until the next start

The set-clock command (20) sets the device’s real-time clock. But that clock is only used to stamp the start of a run.

The clock has no time zone

As expected in an embedded device, the clock does not carry a time zone. But it’s in fact way worse than that. The clock stores six bytes, one for each of those fields: year since 2000, month, day, hour, minute and second.

So the device has to do the calendar math when calculating the duration of the run. And of course the range is limited: it works from 2000 to 2255.

For this kind of device, they could have done without having the date at all. Just a counter since the beginning of the run. On 4 bytes (so 2 bytes less than the device implementation), it could count up to about 136 years, whatever the start date is (now, 400 years ago, in 400 years…). While the current device logic will stop working in 2256.

Also, the date is in the device’s RAM, so a loss of power or a battery change resets the date to zero… becoming an invalid date (month 00 and day 00).

The records

No timestamps, and padding that looks like data

Records are 16-bit dose values with nothing else: no timestamp, no opcode, no length. So the timestamps have to be calculated from the run start and the record interval.

The data are padded with zeros to a multiple of 20 bytes but 00 is also a valid record value (for 0.00 µSv/h). The only way to know where the records end is with the record count retrieved from a different command. Which leads to the next issue.

A count and a dump from different moments

The record count and the checksum come from query 21 but the records come from query a1. If a record is appended between the two queries, the checksum will fail, while in fact both queries were right… when they were issued. In that case, the client must re-read the count to get the updated values.

The name

Semantic error

This device’s name is “Wireless Smart Geiger” but there is no Geiger tube inside. Radiation pulses are counted by what are probably two PIN photodiodes.

The stored name and the advertised name disagree

After setting the name, the device still advertises the old name until the device is rebooted, but the name query already returns the new name. The standard GAP Device Name characteristic is writable too, but whatever is written there is lost on reboot.

Renaming may restart the clock

It happened only once (so that was probably a one-time issue), sending 30 restarted the measuring clock: the uptime was reset but the measurements kept going.

Just in case, refrain from renaming the device in the middle of a run.

Power

The battery

The battery field seems to be a raw ADC value, not a percentage like the apps are showing. Both vendor apps convert that to a scale (in steps of 20 %) but the iOS app has a bug… just off by a factor of 10, so the battery never shows more than a few percent.

Power loss

In case of a power loss, only the name (written in the device’s flash memory) is kept. Everything else is lost (stored in RAM): the records, the clock, the logging duration and the run state.


Given the goal now is to implement a client, those quirks need to be taken into account.

Comments Add one by emailing me.