blueluna / psila

Work in progress Zigbee stack in Rust
MIT License
42 stars 5 forks source link

Unknown cluster codes #5

Closed lattice0 closed 9 months ago

lattice0 commented 9 months ago

I just got a esp32 and when interpreting the mac frame with psila, I get packets with strange cluster and profile numbers:

################
nwk: NetworkHeader { control: FrameControl { frame_type: InterPan, protocol_version: 14, discover_route: EnableDiscovery, multicast: true, security: false, contains_source_route_frame: false, contains_destination_ieee_address: false, contains_source_ieee_address: false }, destination_address: ShortAddress(0), source_address: ShortAddress(0), radius: 0, sequence_number: 0, destination_ieee_address: None, source_ieee_address: None, multicast_control: None, source_route_frame: None }, used: 2

security header: SecurityHeader { control: SecurityControl { level: Integrity64, identifier: Network, has_source_address: false }, counter: 785921159, source: None, sequence: Some(4) }
APS: ApplicationServiceHeader { control: FrameControl { frame_type: InterPan, delivery_mode: Unicast, acknowledge_format: true, security: true, acknowledge_request: false, extended_header: true }, destination: None, group: None, cluster: Some(13323), profile: Some(0), source: None, counter: 0 }
SEC SecurityHeader { control: SecurityControl { level: EncryptedIntegrity64, identifier: KeyLoad, has_source_address: false }, counter: 72418744, source: None, sequence: None }
payload loaded, size: 96

which when converted to hexadecimal have nothing to do with the cluster and profiles listed on zigbee's documentation. Is it possible that this library is just interpreting random stuff as an APS header? I'm still waiting for my sniffer to arrive so I can look better on wireshark.

lattice0 commented 9 months ago

By the way, would it make sense to create an Enum with cluster codes and another with profile codes, with Into and TryFrom implementations?

blueluna commented 9 months ago

Yes, those messages seems strange. Maybe the data has an offset. I believe that a protocol_version of 14 is invalid, it should be 0x02. Profile 0x0000 and Cluster 0x340b?

It makes sense to have some kind of register for the cluster library (ZCL). For a while I tried to generate code from XML. Like, https://github.com/dresden-elektronik/deconz-rest-plugin/blob/master/general.xml

blueluna commented 9 months ago

I hacked together a listener for ESP32C6 which can parse network headers. See esp32-psila.

lattice0 commented 9 months ago

Thanks, I didn't know this:

            let size = usize::from(received.data[0]);
            let _rssi = usize::from(received.data[size]);
            let part = &received.data[1..(size - 1)];

so I war trying to parse the entire thing. Didn't read specs yet, neither my sniffer arrived for wireshark debugging.

off topic: are you getting rust-analyzer to work, in case you use vscode?

off topic: what is missing so I can use this to create a zigbee device for my tuya network?

blueluna commented 9 months ago

If my example resolves your problem, can we close the issue?