dchristl / macless-haystack

Create your own AirTag with OpenHaystack, but without the need to own an Apple device
GNU General Public License v3.0
356 stars 58 forks source link

nrf51 - works but keys are not rotating #69

Closed smierd closed 5 months ago

smierd commented 6 months ago

I succesfully flashed and receive reports from my tag but only one of the 20 keys is beaconing because all my reports from apple are using the same hashed advertisement.

I messed around with the ADVERTISING_INTERVAL, would that effect the key rotation? I can't see anything obvious in the code that would explain that.

The build

NRF_MODEL=nrf51 BOARD=BOARD_SIMPLE make build
cd path_to_built_firmware/
export LC_CTYPE=C
xxd -p -c 100000 nrf001_keyfile | xxd -r -p | dd of=nrf51_firmware.bin skip=1 bs=1 seek=$(grep -oba OFFLINEFINDINGPUBLICKEYHERE! nrf51_firmware.bin | cut -d ':' -f 1) conv=notrunc
560+0 records in
560+0 records out
560 bytes copied, 0.000876 s, 639 kB/s
dchristl commented 6 months ago

Normally, this shouldn't be a problem. Does it work without changing it? You can also switch to the dev-Branch, there is a slightly improved version, that should fix some key rotating issues.

smierd commented 6 months ago

Normally, this shouldn't be a problem. Does it work without changing it? You can also switch to the dev-Branch, there is a slightly improved version, that should fix some key rotating issues.

Yes I do get reports for one of the advertisements. Querying all the IDs only returns results for this one key so that leads me to beleive it's not rotating. There aren't any huge gaps in the history as well that would indicate any sort of problem.

smierd commented 6 months ago

Tried building a new firmware using the dev branch and I also tried another board type. Device continues to beacon and report but I am only seeing one key in all the reports over the course of a few hours.

I am using the following board, but it does not contain an crystal. https://www.aliexpress.com/item/32827699610.html

Have any further suggestions? Appreciate any advice you may have.

smierd commented 5 months ago

Bit of an update. Got it to work by using the nrf51_firmware.bin in the releases. I then patched it using xxd -p -c 100000 PREFIX_keyfile | xxd -r -p | dd of=nrf51_firmware.bin skip=1 bs=1 seek=$(grep -oba OFFLINEFINDINGPUBLICKEYHERE! nrf51_firmware.bin | cut -d ':' -f 1) conv=notrunc and flashed it onto my tags.

So something is wrong with how I am building the Firmware it seems and I will look into it a bit more.

smierd commented 5 months ago

The tags stopped beaconing using the firmware in the releases page. I suspect this is what @jrperson mentioned in PR #65.

I've now tried building new firmware using main/dev branches and BOARD_SIMPLE, BOARD_ALIEXPRESS and BOARD_ALIEXPRESS_NO_XTAL.

Except for BOARD_ALIEXPRESS, they all seem to beacon but do not rotate keys.

ju5t3nc4s3 commented 5 months ago

Could this be the reason i am only getting a location once a week form multipal devices?

CappyT commented 5 months ago

Funnily enough I flashed the firmware from the release following the instructions, it rotates the keys but I got zero reports. I went into densely populated bars but no luck. I get zero reports even tho I can see the keys rotating in nrfconnect

CappyT commented 5 months ago

Okay, I fixed the no location reports by resetting app data and reimporting the devices.json

Referring to #65, if I switch to the main branch and try to compile for BOARD_ALIEXPRESS_NO_XTAL target, I get this:

NRF_MODEL=nrf51 BOARD=BOARD_ALIEXPRESS_NO_XTAL make build
BUILD OPTIONS:
 SoftDevice  s130
 SDK         11
 nRF         nrf51822
 RAM         16 kB
 FLASH       256 kB
 Board       BOARD_ALIEXPRESS_NO_XTAL

rm -rf nrf5x-base/make/../dfu/_build
rm -rf _build/
rm -f *.jlink
rm -f JLink.log
rm -f .gdbinit
  CC        nrf5x-base/make/../sdk/nrf51_sdk_11.0.0/components/toolchain/system_nrf51.c
  CC        ble_stack.c
In file included from ble_stack.h:2,
                 from ble_stack.c:4:
boards.h:54:2: error: #error "Board is not defined"
   54 | #error "Board is not defined"
      |  ^~~~~
ble_stack.c: In function 'init_ble':
ble_stack.c:17:39: error: 'NRF_CLOCK_LFCLKSRC' undeclared (first use in this function); did you mean 'NRF_CLOCK_LF_SRC_RC'?
   17 |     nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
      |                                       ^~~~~~~~~~~~~~~~~~
      |                                       NRF_CLOCK_LF_SRC_RC
ble_stack.c:17:39: note: each undeclared identifier is reported only once for each function it appears in
make: *** [nrf5x-base/make/Makefile:901: _build/ble_stack.o] Error 1

Not sure what is wrong. I checked also the submodule for the SDK and it seems all correct.

jrperson commented 5 months ago

I'll take a finer look through what I submitted and what I have locally to see if I missed something. My super quick look just now didn't look any different.

I am getting rotating keys using the BOARD_ALIEXPRESS_NO_XTAL

jrperson commented 5 months ago

I just confirmed that they keys are not rotating. It is likely due to app_timer not being started correctly. The Nordic docs say that if you use the softdevice you don't need to start a clock...so I didn't. The init_blu() function that starts bluetooth starts the softdevice, so I figured I was good to go. I intentionally ran the init_blu() function before setting up the timer because of this.

I am currently testing starting the clock before running init_blu() to see if that fixes and allows app_timer to function correctly. Once I get a solution I will do a PR.

I'll post progress in this thread.

smierd commented 5 months ago

Thanks for the update!

jrperson commented 5 months ago

I am out of the country so I don't have my dev boards to debug so I have had to resort to using the led to check app_timer.

I had it flashing the led "current_key" times in the setAndAdvertiseNextKey function which is triggered by app_timer. The app_timer is working to trigger to rotate keys and it is iterating the current_key variable just fine.

I will have to debug when I get home at the end of the week to dig further.

dchristl commented 5 months ago

Thank you for testing and trying out the nrf51 firmware. Unfortunately, I currently don't have the time to support it. However, I'm happily open to accepting pull requests.

dchristl commented 5 months ago

Fixed in v.2.20

smierd commented 5 months ago

Pretty sure this is still not working. Pulled the latest main and dev updates and applied multiple Firmware with no success. NRF51's will advertise the same one key without rotation.

dchristl commented 5 months ago

Could you possibly check an older version (1.5 or earlier) again? As mentioned before, I lack the time to support the firmwares. At the beginning of the project, the key rotating worked, so it's possible that a bug has crept in in the meantime (although there has only been one change in 2.2.0).

dschense commented 5 months ago

@dchristl @jrperson @smierd Referring to: #85

this fixed the build error for me.

NRF_MODEL=nrf51 BOARD=BOARD_ALIEXPRESS_NO_XTAL make build
BUILD OPTIONS:
 SoftDevice  s130
 SDK         11
 nRF         nrf51822
 RAM         16 kB
 FLASH       256 kB
 Board       BOARD_ALIEXPRESS_NO_XTAL

rm -rf nrf5x-base/make/../dfu/_build
rm -rf _build/
rm -f *.jlink
rm -f JLink.log
rm -f .gdbinit
  CC        nrf5x-base/make/../sdk/nrf51_sdk_11.0.0/components/toolchain/system_nrf51.c
  CC        ble_stack.c
In file included from ble_stack.h:2,
                 from ble_stack.c:4:
boards.h:54:2: error: #error "Board is not defined"
   54 | #error "Board is not defined"
      |  ^~~~~
ble_stack.c: In function 'init_ble':
ble_stack.c:17:39: error: 'NRF_CLOCK_LFCLKSRC' undeclared (first use in this function); did you mean 'NRF_CLOCK_LF_SRC_RC'?
   17 |     nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
      |                                       ^~~~~~~~~~~~~~~~~~
      |                                       NRF_CLOCK_LF_SRC_RC
ble_stack.c:17:39: note: each undeclared identifier is reported only once for each function it appears in
make: *** [nrf5x-base/make/Makefile:901: _build/ble_stack.o] Error 1