ewilken / hap-rs

Rust implementation of the Apple HomeKit Accessory Protocol (HAP)
Apache License 2.0
196 stars 33 forks source link

Examples are no longer working #90

Open bobrik opened 1 year ago

bobrik commented 1 year ago

I have two accessories that stopped working either after I switched the hub from Homepod mini to Apple TV or "upgraded home" with a prompt from Home app:

image

If I run the lightbulb example:

$ cargo run --example lightbulb

It can successfully pair, but then it fails with "No Response":

image

Here's what I see in the logs (from macOS):

[2023-06-10T05:35:13Z DEBUG hap::transport::http::server] incoming TCP stream from 192.168.1.177:51883
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] received 168 Bytes on incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::http::handler::pair_verify] received body: [6, 1, 1, 3, 32, 59, 103, 217, 133, 127, 61, 243, 35, 119, 77, 124, 139, 1, 29, 98, 96, 87, 149, 189, 76, 219, 217, 200, 56, 79, 217, 123, 42, 210, 255, 178, 4]
[2023-06-10T05:35:13Z INFO  hap::transport::http::handler::pair_verify] pair verify M1: received verify start request from [59, 103, 217, 133, 127, 61, 243, 35, 119, 77, 124, 139, 1, 29, 98, 96, 87, 149, 189, 76, 219, 217, 200, 56, 79, 217, 123, 42, 210, 255, 178, 4]
[2023-06-10T05:35:13Z INFO  hap::transport::http::handler::pair_verify] pair verify M2: sending verify start response
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] writing 257 Bytes to outgoing TCP stream sender
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] wrote 257 Bytes to outgoing TCP stream sender
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] writing 257 Bytes to outgoing TCP stream
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] wrote 257 Bytes to outgoing TCP stream
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] received 257 Bytes on incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::http::handler::pair_verify] received body: [5, 120, 234, 115, 84, 132, 182, 31, 103, 205, 150, 141, 113, 243, 165, 239, 190, 243, 218, 196, 74, 91, 227, 85, 60, 106, 12, 154, 9, 197, 152, 103, 34, 55, 55, 133, 114, 60, 7, 25, 189, 166, 87, 221, 250, 176, 224, 78, 104, 182, 151, 158, 162, 66, 63, 210, 187, 228, 55, 253, 18, 136, 253, 122, 107, 224, 149, 1, 65, 67, 87, 250, 200, 23, 186, 99, 250, 184, 106, 27, 3, 83, 56, 190, 200, 151, 51, 196, 208, 80, 239, 207, 236, 213, 146, 251, 194, 168, 234, 243, 133, 237, 101, 33, 61, 173, 171, 34, 184, 157, 24, 0, 148, 240, 75, 243, 129, 130, 237, 16, 208, 220, 6, 1, 3]
[2023-06-10T05:35:13Z INFO  hap::transport::http::handler::pair_verify] pair verify M3: received verify finish request
[2023-06-10T05:35:13Z DEBUG hap::transport::http::handler::pair_verify] received sub-TLV: {10: [246, 145, 32, 51, 62, 83, 31, 141, 126, 54, 209, 225, 243, 211, 97, 246, 164, 81, 128, 39, 220, 136, 108, 200, 222, 179, 125, 11, 146, 132, 208, 47, 178, 180, 231, 247, 135, 144, 114, 208, 90, 78, 63, 37, 86, 181, 128, 195, 23, 195, 73, 63, 191, 220, 215, 94, 39, 29, 81, 51, 141, 48, 253, 14], 1: [56, 65, 70, 50, 54, 65, 52, 57, 45, 51, 49, 57, 69, 45, 52, 53, 48, 65, 45, 56, 69, 52, 52, 45, 51, 52, 69, 68, 52, 53, 50, 70, 65, 67, 69, 69]}
[2023-06-10T05:35:13Z DEBUG hap::transport::http::handler::pair_verify] raw device pairing ID: [56, 65, 70, 50, 54, 65, 52, 57, 45, 51, 49, 57, 69, 45, 52, 53, 48, 65, 45, 56, 69, 52, 52, 45, 51, 52, 69, 68, 52, 53, 50, 70, 65, 67, 69, 69]
[2023-06-10T05:35:13Z DEBUG hap::transport::http::handler::pair_verify] device signature: ed25519::Signature(F69120333E531F8D7E36D1E1F3D361F6A4518027DC886CC8DEB37D0B9284D02FB2B4E7F7879072D05A4E3F2556B580C317C3493FBFDCD75E271D51338D30FD0E)
[2023-06-10T05:35:13Z DEBUG hap::transport::http::handler::pair_verify] device pairing UUID: 8af26a49-319e-450a-8e44-34ed452facee
[2023-06-10T05:35:13Z ERROR hap::tlv] Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] writing 121 Bytes to outgoing TCP stream sender
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] wrote 121 Bytes to outgoing TCP stream sender
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] writing 121 Bytes to outgoing TCP stream
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] wrote 121 Bytes to outgoing TCP stream
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] polling incoming TCP stream receiver
[2023-06-10T05:35:13Z DEBUG hap::transport::tcp] received 0 Bytes on incoming TCP stream receiver

I wiped the data directory and the result is the same. I'm not seeing No such file or directory on Linux, but it doesn't work there either.

thinkier commented 1 year ago

I had the same issue with the updated HomeKit Architecture. Above steps to reproduce were representative of the issue I had.

Development Device: MacBook Pro 2020 (Intel) running CLion 2023.1.3

Testing Devices:

I had undertaken the following steps to debug:

  1. Enable debug logging for HAP (install env logger etc.)
  2. Go into tlv.rs and breakpoint all invokations of the error! macro.
  3. Boot up the home app on my device.
  4. Trace the call stack of the emitter of error, keeping in mind that I'm using the FileStorage Storage engine. However, this appears to be a generic bug that likely came from the pairing process, so it should affect all storage engines.

Temporary Resolution

Find the data/pairings/UUID_HERE.json and create a copy where the UUID is the one emitted in console with the error. It should begin with: [TIMESTAMP DEBUG hap::transport::http::handler::pair_verify] device pairing UUID:

Location for your debugger: ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hap-0.1.0-pre.15/src/transport/http/handler/pair_verify.rs:226

The HAP accessory is now communicating with my HomeKit setup.

Note (unverified observation): Subsequently the new file I created disappeared and it reverted back to the original UUID.