mongoose-os-libs / homekit-adk

Port of Apple's HomeKit ADK to Mongoose OS
Apache License 2.0
23 stars 5 forks source link

Preparation for library based QR-Code generation - setup identifier #2

Open cduvenhorst opened 3 years ago

cduvenhorst commented 3 years ago
rojer commented 3 years ago

looks good! make sure RPC handler is updated to handle this. i.e., HAP.Setup should be modified to set code, HAP.Reset should clear it.

rojer commented 3 years ago

actually, can you describe the flow of the setup with QR code? starting with a blank device, what will happen?

cduvenhorst commented 3 years ago

Ok! Meanwhile I ran into a problem which seems to be caused by the dynamic buffer allocation or the helper functions in the HAP lib. Have to dig a little deeper to nail it. Pairing fails based on dynamic setup info.

rojer commented 3 years ago

sounds good. when chasing a memory leak or corruption issue, using "grown up" tools such as address sanitizer is invaluable. mongoose os has a minimal "ubuntu" platform, that makes it possible - it doesn't support peripherals, but is ideal if you can separate the code you're debugging into something that doesn't require hardware access. and for shelly-homekit, we have a "ShellyU" target that is exactly that - it's a "switch" with no physical connections required but web interface and HAP functionality is fully working. it will catch memory corruption and pointer misus, such as double-free or use-after-free. really invaluable. long story short, here's how to build and use it:

on a Ubuntu machine with clang installed (apt install clang), run

make ShellyU

in the main source directory, then run the binary:

ASAN_SYMBOLIZER_PATH=$(realpath /usr/bin/llvm-symbolizer-*) build_ShellyU/objs/shelly-homekit.elf --insecure --chroot build_ShellyU/fs

go to http://localhost:8080/ to access the web interface, pair, etc. if your firmware does something nasty with a pointer, it will crash and you'll get a full trace. leak check is only performed on graceful exit, so to check if it leaks memory press ctrl-c in the terminal and if it does, you'll get a report.

cduvenhorst commented 3 years ago

I will update example-homekit for a POC.

cduvenhorst commented 3 years ago

Ok! Meanwhile I ran into a problem which seems to be caused by the dynamic buffer allocation or the helper functions in the HAP lib. Have to dig a little deeper to nail it. Pairing fails based on dynamic setup info.

Ok. This is caused by memory limitations if building for esp8266. The esp32 platform just runs fine with dynamic setup codes.

rojer commented 3 years ago

i can take a look, just tell me how to test

cduvenhorst commented 3 years ago

i can take a look, just tell me how to test

Strange. If you activate the accessory setup info server (set setupDisplay in happlatform) everything works with esp32, but esp8266 will not pair. I suspect memory limitations.

I have updated my example-homekit fork on branch "qrcode" for you to test.

Simply provision wifi and head over to "http://\<ip>/homekit/pairing" and try to pair while having a look at the console.