espressif / esp-zigbee-sdk

Espressif Zigbee SDK
Apache License 2.0
162 stars 26 forks source link

Please expose functionality to set Standard Distributed Key (TZ-119) #25

Closed spark404 closed 1 year ago

spark404 commented 1 year ago

The current API doesn't expose a function to set the Standard Distributed Key. This would be nice to have in order to join networks that don't use the standard Zigbee Alliance Key Transport Key. Recognisable by having the Key Id set to 2 in the Security Control Field of the ZigBee Security Header.

This functionality is available in the boss library with the function call 'zb_zdo_set_tc_standard_distributed_key'. I was able to get my ZigBee device connected to the network by using a workaround. I reconfigured the on/off light example with 'CONFIG_ZB_ZCZR=y' to link against the zczr libraries that expose that function. And defined the function as external

extern void zb_zdo_set_tc_standard_distributed_key(unsigned char *key_ptr);

Calling this function with the correct key after invoking esp_zb_init allowed the module to extract the Standard Network Key from the Transport Key message. The module is correctly sending a Device Announcement with the network key.

Details:

ESP32-C6-DevKitC-1

I (275) cpu_start: Application information:
I (277) cpu_start: Project name:     light_bulb
I (283) cpu_start: App version:      v5.2-dev-503-g17451f1fb3-dirty
I (290) cpu_start: Compile time:     May 18 2023 19:34:07
I (296) cpu_start: ELF file SHA256:  d2e13cbd956f6be1...
I (302) cpu_start: ESP-IDF:          v5.2-dev-503-g17451f1fb3-dirty
I (309) cpu_start: Min chip rev:     v0.0
I (313) cpu_start: Max chip rev:     v0.99
I (318) cpu_start: Chip rev:         v0.0

dependencies:
  espressif/esp-zboss-lib:
    component_hash: 963540d31dd481b96caf1f9d61b213504faeb18b72b33a4617fd327a47bd013f
    source:
      service_url: https://api.components.espressif.com/
      type: service
    version: 0.3.6
  espressif/esp-zigbee-lib:
    component_hash: 37ec54b0e32e017f99b850afe0fd3e3ff493fc1c033591c57d5227eb5c683165
    source:
      service_url: https://api.components.espressif.com/
      type: service
    version: 0.5.5
  espressif/led_strip:
    component_hash: 7e92a0c8a2e35b40904f88e88ce3c0dffff504a2763f70fba7ef4787cf2eec83
    source:
      service_url: https://api.components.espressif.com/
      type: service
    version: 2.0.0
  idf:
    component_hash: null
    source:
      type: idf
    version: 5.2.0
manifest_hash: 1eb30226f3e4c780c0bf127d7afbf2f8f69c666bd5d51ca78990da67017e7e05
target: esp32c6
version: 1.0.0
likunqiao097304 commented 1 year ago

We will provide API for this, thanks for pointing out

chshu commented 1 year ago

@spark404 The API is added here: https://github.com/espressif/esp-zigbee-sdk/blob/main/components/esp-zigbee-lib/include/esp_zigbee_secur.h#L117

spark404 commented 1 year ago

Hi @chshu, thank you for doing this work.

It works like a charm in my test project. However I tried using this with the Zigbee device type set to "Zigbee End Device" and received the following error. If I set the device type to Zigbee Coordinator or Router device it works without problems.

/Users/hugo/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/12.2.0/../../../../riscv32-esp-elf/bin/ld: /Users/hugo/Projects/HackerHotelBadge/zll-light/managed_components/espressif__esp-zigbee-lib/lib/esp32c6/libesp_zb_api_ed.a(esp_zigbee_secur.c.obj): in function `.L0 ':
(.text.esp_zb_secur_TC_standard_distributed_key_set+0x4): undefined reference to `zb_zdo_set_tc_standard_distributed_key'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
xieqinan commented 1 year ago

Thank you for your test. Currently, the end device of Zigbee does not support temporarily setting the distributed key. However, this feature will be fixed in the next week.