zigbee-herdsman 3.5.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (726) hide show
  1. package/.github/dependabot.yml +9 -3
  2. package/.github/workflows/ci.yml +2 -4
  3. package/.github/workflows/stale.yml +1 -1
  4. package/.release-please-manifest.json +1 -1
  5. package/.vscode/extensions.json +3 -0
  6. package/.vscode/settings.json +11 -0
  7. package/CHANGELOG.md +25 -0
  8. package/biome.json +89 -0
  9. package/dist/adapter/adapter.d.ts +11 -11
  10. package/dist/adapter/adapter.d.ts.map +1 -1
  11. package/dist/adapter/adapter.js +14 -14
  12. package/dist/adapter/adapterDiscovery.d.ts +6 -6
  13. package/dist/adapter/adapterDiscovery.d.ts.map +1 -1
  14. package/dist/adapter/adapterDiscovery.js +139 -141
  15. package/dist/adapter/adapterDiscovery.js.map +1 -1
  16. package/dist/adapter/const.d.ts +1 -1
  17. package/dist/adapter/const.js +2 -2
  18. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts +16 -16
  19. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts.map +1 -1
  20. package/dist/adapter/deconz/adapter/deconzAdapter.js +95 -100
  21. package/dist/adapter/deconz/adapter/deconzAdapter.js.map +1 -1
  22. package/dist/adapter/deconz/driver/constants.d.ts +5 -5
  23. package/dist/adapter/deconz/driver/constants.d.ts.map +1 -1
  24. package/dist/adapter/deconz/driver/driver.d.ts +9 -9
  25. package/dist/adapter/deconz/driver/driver.d.ts.map +1 -1
  26. package/dist/adapter/deconz/driver/driver.js +112 -106
  27. package/dist/adapter/deconz/driver/driver.js.map +1 -1
  28. package/dist/adapter/deconz/driver/frame.d.ts +1 -1
  29. package/dist/adapter/deconz/driver/frame.d.ts.map +1 -1
  30. package/dist/adapter/deconz/driver/frame.js +1 -2
  31. package/dist/adapter/deconz/driver/frame.js.map +1 -1
  32. package/dist/adapter/deconz/driver/frameParser.d.ts +1 -1
  33. package/dist/adapter/deconz/driver/frameParser.d.ts.map +1 -1
  34. package/dist/adapter/deconz/driver/frameParser.js +66 -70
  35. package/dist/adapter/deconz/driver/frameParser.js.map +1 -1
  36. package/dist/adapter/deconz/driver/parser.d.ts +1 -1
  37. package/dist/adapter/deconz/driver/parser.d.ts.map +1 -1
  38. package/dist/adapter/deconz/driver/parser.js +2 -2
  39. package/dist/adapter/deconz/driver/parser.js.map +1 -1
  40. package/dist/adapter/deconz/driver/writer.d.ts +2 -2
  41. package/dist/adapter/deconz/driver/writer.d.ts.map +1 -1
  42. package/dist/adapter/deconz/driver/writer.js +1 -1
  43. package/dist/adapter/ember/adapter/emberAdapter.d.ts +19 -19
  44. package/dist/adapter/ember/adapter/emberAdapter.d.ts.map +1 -1
  45. package/dist/adapter/ember/adapter/emberAdapter.js +117 -97
  46. package/dist/adapter/ember/adapter/emberAdapter.js.map +1 -1
  47. package/dist/adapter/ember/adapter/endpoints.d.ts +1 -1
  48. package/dist/adapter/ember/adapter/endpoints.d.ts.map +1 -1
  49. package/dist/adapter/ember/adapter/oneWaitress.d.ts +5 -5
  50. package/dist/adapter/ember/adapter/oneWaitress.d.ts.map +1 -1
  51. package/dist/adapter/ember/adapter/oneWaitress.js +2 -2
  52. package/dist/adapter/ember/adapter/oneWaitress.js.map +1 -1
  53. package/dist/adapter/ember/adapter/tokensManager.d.ts +3 -3
  54. package/dist/adapter/ember/adapter/tokensManager.d.ts.map +1 -1
  55. package/dist/adapter/ember/adapter/tokensManager.js +20 -23
  56. package/dist/adapter/ember/adapter/tokensManager.js.map +1 -1
  57. package/dist/adapter/ember/enums.d.ts +4 -4
  58. package/dist/adapter/ember/enums.d.ts.map +1 -1
  59. package/dist/adapter/ember/enums.js +4 -6
  60. package/dist/adapter/ember/enums.js.map +1 -1
  61. package/dist/adapter/ember/ezsp/buffalo.d.ts +4 -4
  62. package/dist/adapter/ember/ezsp/buffalo.d.ts.map +1 -1
  63. package/dist/adapter/ember/ezsp/buffalo.js +30 -32
  64. package/dist/adapter/ember/ezsp/buffalo.js.map +1 -1
  65. package/dist/adapter/ember/ezsp/ezsp.d.ts +46 -46
  66. package/dist/adapter/ember/ezsp/ezsp.d.ts.map +1 -1
  67. package/dist/adapter/ember/ezsp/ezsp.js +85 -111
  68. package/dist/adapter/ember/ezsp/ezsp.js.map +1 -1
  69. package/dist/adapter/ember/ezspError.d.ts +1 -1
  70. package/dist/adapter/ember/types.d.ts +14 -14
  71. package/dist/adapter/ember/types.d.ts.map +1 -1
  72. package/dist/adapter/ember/uart/ash.d.ts +5 -5
  73. package/dist/adapter/ember/uart/ash.d.ts.map +1 -1
  74. package/dist/adapter/ember/uart/ash.js +80 -71
  75. package/dist/adapter/ember/uart/ash.js.map +1 -1
  76. package/dist/adapter/ember/uart/parser.d.ts +2 -2
  77. package/dist/adapter/ember/uart/parser.d.ts.map +1 -1
  78. package/dist/adapter/ember/uart/parser.js +2 -1
  79. package/dist/adapter/ember/uart/parser.js.map +1 -1
  80. package/dist/adapter/ember/uart/queues.js +27 -29
  81. package/dist/adapter/ember/uart/queues.js.map +1 -1
  82. package/dist/adapter/ember/uart/writer.d.ts +1 -1
  83. package/dist/adapter/ember/uart/writer.d.ts.map +1 -1
  84. package/dist/adapter/ember/uart/writer.js +3 -5
  85. package/dist/adapter/ember/uart/writer.js.map +1 -1
  86. package/dist/adapter/ember/utils/initters.d.ts +2 -2
  87. package/dist/adapter/ember/utils/initters.d.ts.map +1 -1
  88. package/dist/adapter/ember/utils/initters.js +1 -1
  89. package/dist/adapter/ember/utils/math.js +1 -1
  90. package/dist/adapter/events.d.ts +1 -1
  91. package/dist/adapter/events.d.ts.map +1 -1
  92. package/dist/adapter/ezsp/adapter/backup.d.ts +3 -3
  93. package/dist/adapter/ezsp/adapter/backup.d.ts.map +1 -1
  94. package/dist/adapter/ezsp/adapter/backup.js +8 -10
  95. package/dist/adapter/ezsp/adapter/backup.js.map +1 -1
  96. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts +12 -12
  97. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts.map +1 -1
  98. package/dist/adapter/ezsp/adapter/ezspAdapter.js +45 -44
  99. package/dist/adapter/ezsp/adapter/ezspAdapter.js.map +1 -1
  100. package/dist/adapter/ezsp/driver/driver.d.ts +12 -12
  101. package/dist/adapter/ezsp/driver/driver.d.ts.map +1 -1
  102. package/dist/adapter/ezsp/driver/driver.js +148 -141
  103. package/dist/adapter/ezsp/driver/driver.js.map +1 -1
  104. package/dist/adapter/ezsp/driver/ezsp.d.ts +7 -7
  105. package/dist/adapter/ezsp/driver/ezsp.d.ts.map +1 -1
  106. package/dist/adapter/ezsp/driver/ezsp.js +61 -59
  107. package/dist/adapter/ezsp/driver/ezsp.js.map +1 -1
  108. package/dist/adapter/ezsp/driver/frame.js +2 -2
  109. package/dist/adapter/ezsp/driver/index.d.ts +2 -2
  110. package/dist/adapter/ezsp/driver/multicast.d.ts +8 -5
  111. package/dist/adapter/ezsp/driver/multicast.d.ts.map +1 -1
  112. package/dist/adapter/ezsp/driver/multicast.js +9 -9
  113. package/dist/adapter/ezsp/driver/multicast.js.map +1 -1
  114. package/dist/adapter/ezsp/driver/parser.d.ts +1 -1
  115. package/dist/adapter/ezsp/driver/parser.js +3 -3
  116. package/dist/adapter/ezsp/driver/types/basic.d.ts +5 -5
  117. package/dist/adapter/ezsp/driver/types/basic.d.ts.map +1 -1
  118. package/dist/adapter/ezsp/driver/types/basic.js +12 -33
  119. package/dist/adapter/ezsp/driver/types/basic.js.map +1 -1
  120. package/dist/adapter/ezsp/driver/types/index.d.ts +3 -3
  121. package/dist/adapter/ezsp/driver/types/index.d.ts.map +1 -1
  122. package/dist/adapter/ezsp/driver/types/index.js +8 -9
  123. package/dist/adapter/ezsp/driver/types/index.js.map +1 -1
  124. package/dist/adapter/ezsp/driver/types/named.d.ts +2 -2
  125. package/dist/adapter/ezsp/driver/types/named.d.ts.map +1 -1
  126. package/dist/adapter/ezsp/driver/types/named.js +8 -11
  127. package/dist/adapter/ezsp/driver/types/named.js.map +1 -1
  128. package/dist/adapter/ezsp/driver/types/struct.d.ts +2 -2
  129. package/dist/adapter/ezsp/driver/types/struct.d.ts.map +1 -1
  130. package/dist/adapter/ezsp/driver/types/struct.js +207 -214
  131. package/dist/adapter/ezsp/driver/types/struct.js.map +1 -1
  132. package/dist/adapter/ezsp/driver/uart.d.ts +2 -2
  133. package/dist/adapter/ezsp/driver/uart.d.ts.map +1 -1
  134. package/dist/adapter/ezsp/driver/uart.js +48 -37
  135. package/dist/adapter/ezsp/driver/uart.js.map +1 -1
  136. package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts +3 -3
  137. package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts.map +1 -1
  138. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js +16 -34
  139. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js.map +1 -1
  140. package/dist/adapter/ezsp/driver/utils/index.d.ts +4 -4
  141. package/dist/adapter/ezsp/driver/utils/index.d.ts.map +1 -1
  142. package/dist/adapter/ezsp/driver/utils/index.js +4 -4
  143. package/dist/adapter/ezsp/driver/utils/index.js.map +1 -1
  144. package/dist/adapter/ezsp/driver/writer.d.ts +1 -1
  145. package/dist/adapter/ezsp/driver/writer.js +2 -2
  146. package/dist/adapter/index.d.ts +3 -3
  147. package/dist/adapter/serialPort.d.ts +3 -3
  148. package/dist/adapter/serialPort.d.ts.map +1 -1
  149. package/dist/adapter/serialPort.js +1 -0
  150. package/dist/adapter/serialPort.js.map +1 -1
  151. package/dist/adapter/socketPortUtils.js +3 -3
  152. package/dist/adapter/tstype.d.ts +6 -6
  153. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts +4 -4
  154. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts.map +1 -1
  155. package/dist/adapter/z-stack/adapter/adapter-backup.js +106 -119
  156. package/dist/adapter/z-stack/adapter/adapter-backup.js.map +1 -1
  157. package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts +10 -10
  158. package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts.map +1 -1
  159. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js +23 -24
  160. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js.map +1 -1
  161. package/dist/adapter/z-stack/adapter/manager.d.ts +6 -6
  162. package/dist/adapter/z-stack/adapter/manager.d.ts.map +1 -1
  163. package/dist/adapter/z-stack/adapter/manager.js +115 -127
  164. package/dist/adapter/z-stack/adapter/manager.js.map +1 -1
  165. package/dist/adapter/z-stack/adapter/tstype.d.ts +3 -3
  166. package/dist/adapter/z-stack/adapter/tstype.js +3 -3
  167. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts +10 -10
  168. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts.map +1 -1
  169. package/dist/adapter/z-stack/adapter/zStackAdapter.js +125 -137
  170. package/dist/adapter/z-stack/adapter/zStackAdapter.js.map +1 -1
  171. package/dist/adapter/z-stack/constants/common.d.ts.map +1 -1
  172. package/dist/adapter/z-stack/constants/common.js +0 -3
  173. package/dist/adapter/z-stack/constants/common.js.map +1 -1
  174. package/dist/adapter/z-stack/constants/index.d.ts +10 -10
  175. package/dist/adapter/z-stack/constants/index.d.ts.map +1 -1
  176. package/dist/adapter/z-stack/constants/index.js +2 -2
  177. package/dist/adapter/z-stack/constants/index.js.map +1 -1
  178. package/dist/adapter/z-stack/constants/utils.d.ts +1 -1
  179. package/dist/adapter/z-stack/constants/utils.js +2 -2
  180. package/dist/adapter/z-stack/constants/utils.js.map +1 -1
  181. package/dist/adapter/z-stack/models/startup-options.d.ts +2 -2
  182. package/dist/adapter/z-stack/models/startup-options.d.ts.map +1 -1
  183. package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts +1 -1
  184. package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts.map +1 -1
  185. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js +4 -5
  186. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js.map +1 -1
  187. package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts +2 -2
  188. package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts.map +1 -1
  189. package/dist/adapter/z-stack/structs/entries/address-manager-table.js +3 -4
  190. package/dist/adapter/z-stack/structs/entries/address-manager-table.js.map +1 -1
  191. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts +1 -1
  192. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts.map +1 -1
  193. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js +1 -2
  194. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js.map +1 -1
  195. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts +2 -2
  196. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts.map +1 -1
  197. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js +3 -4
  198. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js.map +1 -1
  199. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts +1 -1
  200. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts.map +1 -1
  201. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js +6 -7
  202. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js.map +1 -1
  203. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts +2 -2
  204. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts.map +1 -1
  205. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js +3 -4
  206. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js.map +1 -1
  207. package/dist/adapter/z-stack/structs/entries/channel-list.d.ts +1 -1
  208. package/dist/adapter/z-stack/structs/entries/channel-list.d.ts.map +1 -1
  209. package/dist/adapter/z-stack/structs/entries/channel-list.js +1 -2
  210. package/dist/adapter/z-stack/structs/entries/channel-list.js.map +1 -1
  211. package/dist/adapter/z-stack/structs/entries/has-configured.d.ts +1 -1
  212. package/dist/adapter/z-stack/structs/entries/has-configured.d.ts.map +1 -1
  213. package/dist/adapter/z-stack/structs/entries/has-configured.js +2 -3
  214. package/dist/adapter/z-stack/structs/entries/has-configured.js.map +1 -1
  215. package/dist/adapter/z-stack/structs/entries/index.d.ts +16 -16
  216. package/dist/adapter/z-stack/structs/entries/nib.d.ts +1 -1
  217. package/dist/adapter/z-stack/structs/entries/nib.d.ts.map +1 -1
  218. package/dist/adapter/z-stack/structs/entries/nib.js +49 -50
  219. package/dist/adapter/z-stack/structs/entries/nib.js.map +1 -1
  220. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts +1 -1
  221. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts.map +1 -1
  222. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js +1 -2
  223. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js.map +1 -1
  224. package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts +1 -1
  225. package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts.map +1 -1
  226. package/dist/adapter/z-stack/structs/entries/nwk-key.js +1 -2
  227. package/dist/adapter/z-stack/structs/entries/nwk-key.js.map +1 -1
  228. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts +1 -1
  229. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts.map +1 -1
  230. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js +1 -2
  231. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js.map +1 -1
  232. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts +1 -1
  233. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts.map +1 -1
  234. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js +3 -4
  235. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js.map +1 -1
  236. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts +2 -2
  237. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts.map +1 -1
  238. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js +3 -4
  239. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js.map +1 -1
  240. package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts +1 -1
  241. package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts.map +1 -1
  242. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js +4 -5
  243. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js.map +1 -1
  244. package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts +2 -2
  245. package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts.map +1 -1
  246. package/dist/adapter/z-stack/structs/entries/security-manager-table.js +3 -4
  247. package/dist/adapter/z-stack/structs/entries/security-manager-table.js.map +1 -1
  248. package/dist/adapter/z-stack/structs/index.d.ts +4 -4
  249. package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts +2 -2
  250. package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts.map +1 -1
  251. package/dist/adapter/z-stack/structs/struct.d.ts +8 -8
  252. package/dist/adapter/z-stack/structs/struct.d.ts.map +1 -1
  253. package/dist/adapter/z-stack/structs/struct.js +42 -43
  254. package/dist/adapter/z-stack/structs/struct.js.map +1 -1
  255. package/dist/adapter/z-stack/structs/table.d.ts +3 -3
  256. package/dist/adapter/z-stack/structs/table.d.ts.map +1 -1
  257. package/dist/adapter/z-stack/structs/table.js +10 -10
  258. package/dist/adapter/z-stack/structs/table.js.map +1 -1
  259. package/dist/adapter/z-stack/unpi/frame.d.ts +1 -1
  260. package/dist/adapter/z-stack/unpi/frame.d.ts.map +1 -1
  261. package/dist/adapter/z-stack/unpi/frame.js +2 -4
  262. package/dist/adapter/z-stack/unpi/frame.js.map +1 -1
  263. package/dist/adapter/z-stack/unpi/index.d.ts +4 -4
  264. package/dist/adapter/z-stack/unpi/parser.d.ts +1 -1
  265. package/dist/adapter/z-stack/unpi/parser.js +3 -3
  266. package/dist/adapter/z-stack/unpi/parser.js.map +1 -1
  267. package/dist/adapter/z-stack/unpi/writer.d.ts +2 -2
  268. package/dist/adapter/z-stack/unpi/writer.d.ts.map +1 -1
  269. package/dist/adapter/z-stack/unpi/writer.js +1 -1
  270. package/dist/adapter/z-stack/utils/index.d.ts +2 -2
  271. package/dist/adapter/z-stack/utils/network-options.d.ts +1 -1
  272. package/dist/adapter/z-stack/utils/network-options.d.ts.map +1 -1
  273. package/dist/adapter/z-stack/znp/buffaloZnp.d.ts +3 -3
  274. package/dist/adapter/z-stack/znp/buffaloZnp.d.ts.map +1 -1
  275. package/dist/adapter/z-stack/znp/buffaloZnp.js +34 -20
  276. package/dist/adapter/z-stack/znp/buffaloZnp.js.map +1 -1
  277. package/dist/adapter/z-stack/znp/definition.d.ts +2 -2
  278. package/dist/adapter/z-stack/znp/definition.d.ts.map +1 -1
  279. package/dist/adapter/z-stack/znp/definition.js +1111 -1111
  280. package/dist/adapter/z-stack/znp/index.d.ts +2 -2
  281. package/dist/adapter/z-stack/znp/tstype.d.ts +7 -7
  282. package/dist/adapter/z-stack/znp/tstype.d.ts.map +1 -1
  283. package/dist/adapter/z-stack/znp/utils.d.ts +1 -1
  284. package/dist/adapter/z-stack/znp/utils.d.ts.map +1 -1
  285. package/dist/adapter/z-stack/znp/utils.js +2 -2
  286. package/dist/adapter/z-stack/znp/znp.d.ts +7 -7
  287. package/dist/adapter/z-stack/znp/znp.d.ts.map +1 -1
  288. package/dist/adapter/z-stack/znp/znp.js +46 -45
  289. package/dist/adapter/z-stack/znp/znp.js.map +1 -1
  290. package/dist/adapter/z-stack/znp/zpiObject.d.ts +8 -8
  291. package/dist/adapter/z-stack/znp/zpiObject.d.ts.map +1 -1
  292. package/dist/adapter/z-stack/znp/zpiObject.js +6 -6
  293. package/dist/adapter/z-stack/znp/zpiObject.js.map +1 -1
  294. package/dist/adapter/zboss/adapter/zbossAdapter.d.ts +11 -11
  295. package/dist/adapter/zboss/adapter/zbossAdapter.d.ts.map +1 -1
  296. package/dist/adapter/zboss/adapter/zbossAdapter.js +37 -36
  297. package/dist/adapter/zboss/adapter/zbossAdapter.js.map +1 -1
  298. package/dist/adapter/zboss/commands.d.ts +4 -6
  299. package/dist/adapter/zboss/commands.d.ts.map +1 -1
  300. package/dist/adapter/zboss/commands.js +321 -287
  301. package/dist/adapter/zboss/commands.js.map +1 -1
  302. package/dist/adapter/zboss/driver.d.ts +9 -9
  303. package/dist/adapter/zboss/driver.d.ts.map +1 -1
  304. package/dist/adapter/zboss/driver.js +25 -25
  305. package/dist/adapter/zboss/driver.js.map +1 -1
  306. package/dist/adapter/zboss/frame.d.ts +9 -9
  307. package/dist/adapter/zboss/frame.d.ts.map +1 -1
  308. package/dist/adapter/zboss/frame.js +15 -15
  309. package/dist/adapter/zboss/frame.js.map +1 -1
  310. package/dist/adapter/zboss/reader.d.ts +2 -2
  311. package/dist/adapter/zboss/reader.d.ts.map +1 -1
  312. package/dist/adapter/zboss/reader.js +6 -5
  313. package/dist/adapter/zboss/reader.js.map +1 -1
  314. package/dist/adapter/zboss/uart.d.ts +3 -3
  315. package/dist/adapter/zboss/uart.d.ts.map +1 -1
  316. package/dist/adapter/zboss/uart.js +36 -36
  317. package/dist/adapter/zboss/uart.js.map +1 -1
  318. package/dist/adapter/zboss/writer.d.ts +1 -1
  319. package/dist/adapter/zboss/writer.d.ts.map +1 -1
  320. package/dist/adapter/zboss/writer.js +3 -5
  321. package/dist/adapter/zboss/writer.js.map +1 -1
  322. package/dist/adapter/zigate/adapter/patchZdoBuffaloBE.js +2 -2
  323. package/dist/adapter/zigate/adapter/patchZdoBuffaloBE.js.map +1 -1
  324. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts +14 -14
  325. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts.map +1 -1
  326. package/dist/adapter/zigate/adapter/zigateAdapter.js +52 -53
  327. package/dist/adapter/zigate/adapter/zigateAdapter.js.map +1 -1
  328. package/dist/adapter/zigate/driver/buffaloZiGate.d.ts +6 -6
  329. package/dist/adapter/zigate/driver/buffaloZiGate.d.ts.map +1 -1
  330. package/dist/adapter/zigate/driver/buffaloZiGate.js +41 -23
  331. package/dist/adapter/zigate/driver/buffaloZiGate.js.map +1 -1
  332. package/dist/adapter/zigate/driver/commandType.d.ts +2 -2
  333. package/dist/adapter/zigate/driver/commandType.d.ts.map +1 -1
  334. package/dist/adapter/zigate/driver/commandType.js +37 -37
  335. package/dist/adapter/zigate/driver/commandType.js.map +1 -1
  336. package/dist/adapter/zigate/driver/constants.d.ts +27 -200
  337. package/dist/adapter/zigate/driver/constants.d.ts.map +1 -1
  338. package/dist/adapter/zigate/driver/constants.js +40 -236
  339. package/dist/adapter/zigate/driver/constants.js.map +1 -1
  340. package/dist/adapter/zigate/driver/frame.d.ts.map +1 -1
  341. package/dist/adapter/zigate/driver/frame.js +4 -3
  342. package/dist/adapter/zigate/driver/frame.js.map +1 -1
  343. package/dist/adapter/zigate/driver/messageType.d.ts +1 -1
  344. package/dist/adapter/zigate/driver/messageType.js +76 -76
  345. package/dist/adapter/zigate/driver/ziGateObject.d.ts +3 -3
  346. package/dist/adapter/zigate/driver/ziGateObject.d.ts.map +1 -1
  347. package/dist/adapter/zigate/driver/ziGateObject.js +7 -6
  348. package/dist/adapter/zigate/driver/ziGateObject.js.map +1 -1
  349. package/dist/adapter/zigate/driver/zigate.d.ts +8 -8
  350. package/dist/adapter/zigate/driver/zigate.d.ts.map +1 -1
  351. package/dist/adapter/zigate/driver/zigate.js +59 -54
  352. package/dist/adapter/zigate/driver/zigate.js.map +1 -1
  353. package/dist/adapter/zoh/adapter/utils.js +1 -1
  354. package/dist/adapter/zoh/adapter/zohAdapter.d.ts +13 -13
  355. package/dist/adapter/zoh/adapter/zohAdapter.d.ts.map +1 -1
  356. package/dist/adapter/zoh/adapter/zohAdapter.js +101 -67
  357. package/dist/adapter/zoh/adapter/zohAdapter.js.map +1 -1
  358. package/dist/buffalo/buffalo.d.ts +2 -2
  359. package/dist/buffalo/buffalo.js +4 -4
  360. package/dist/buffalo/buffalo.js.map +1 -1
  361. package/dist/buffalo/index.d.ts +1 -1
  362. package/dist/controller/controller.d.ts +7 -7
  363. package/dist/controller/controller.d.ts.map +1 -1
  364. package/dist/controller/controller.js +94 -98
  365. package/dist/controller/controller.js.map +1 -1
  366. package/dist/controller/database.d.ts +1 -1
  367. package/dist/controller/database.d.ts.map +1 -1
  368. package/dist/controller/database.js +9 -9
  369. package/dist/controller/database.js.map +1 -1
  370. package/dist/controller/events.d.ts +6 -6
  371. package/dist/controller/events.d.ts.map +1 -1
  372. package/dist/controller/greenPower.d.ts +21 -21
  373. package/dist/controller/greenPower.d.ts.map +1 -1
  374. package/dist/controller/greenPower.js +41 -41
  375. package/dist/controller/greenPower.js.map +1 -1
  376. package/dist/controller/helpers/index.d.ts +1 -1
  377. package/dist/controller/helpers/request.d.ts +2 -2
  378. package/dist/controller/helpers/request.d.ts.map +1 -1
  379. package/dist/controller/helpers/request.js +31 -27
  380. package/dist/controller/helpers/request.js.map +1 -1
  381. package/dist/controller/helpers/requestQueue.d.ts +3 -3
  382. package/dist/controller/helpers/requestQueue.d.ts.map +1 -1
  383. package/dist/controller/helpers/requestQueue.js +20 -20
  384. package/dist/controller/helpers/requestQueue.js.map +1 -1
  385. package/dist/controller/helpers/zclFrameConverter.d.ts +2 -2
  386. package/dist/controller/helpers/zclFrameConverter.d.ts.map +1 -1
  387. package/dist/controller/helpers/zclFrameConverter.js +1 -1
  388. package/dist/controller/helpers/zclFrameConverter.js.map +1 -1
  389. package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts +6 -4
  390. package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts.map +1 -1
  391. package/dist/controller/helpers/zclTransactionSequenceNumber.js +6 -5
  392. package/dist/controller/helpers/zclTransactionSequenceNumber.js.map +1 -1
  393. package/dist/controller/index.d.ts +1 -1
  394. package/dist/controller/model/device.d.ts +23 -19
  395. package/dist/controller/model/device.d.ts.map +1 -1
  396. package/dist/controller/model/device.js +153 -128
  397. package/dist/controller/model/device.js.map +1 -1
  398. package/dist/controller/model/endpoint.d.ts +11 -11
  399. package/dist/controller/model/endpoint.d.ts.map +1 -1
  400. package/dist/controller/model/endpoint.js +84 -67
  401. package/dist/controller/model/endpoint.js.map +1 -1
  402. package/dist/controller/model/entity.d.ts +3 -3
  403. package/dist/controller/model/entity.d.ts.map +1 -1
  404. package/dist/controller/model/group.d.ts +4 -4
  405. package/dist/controller/model/group.d.ts.map +1 -1
  406. package/dist/controller/model/group.js +21 -9
  407. package/dist/controller/model/group.js.map +1 -1
  408. package/dist/controller/model/index.d.ts +4 -4
  409. package/dist/controller/touchlink.d.ts +1 -1
  410. package/dist/controller/touchlink.d.ts.map +1 -1
  411. package/dist/controller/touchlink.js +11 -11
  412. package/dist/controller/tstype.d.ts +3 -3
  413. package/dist/index.d.ts +10 -10
  414. package/dist/models/backup-storage-legacy.d.ts +14 -16
  415. package/dist/models/backup-storage-legacy.d.ts.map +1 -1
  416. package/dist/models/backup-storage-unified.d.ts +1 -1
  417. package/dist/models/backup.d.ts +2 -2
  418. package/dist/models/backup.d.ts.map +1 -1
  419. package/dist/models/index.d.ts +4 -4
  420. package/dist/utils/backup.d.ts +1 -1
  421. package/dist/utils/backup.d.ts.map +1 -1
  422. package/dist/utils/backup.js +26 -26
  423. package/dist/utils/backup.js.map +1 -1
  424. package/dist/utils/index.d.ts +5 -5
  425. package/dist/utils/logger.js +3 -3
  426. package/dist/utils/patchBigIntSerialization.js +1 -1
  427. package/dist/utils/patchBigIntSerialization.js.map +1 -1
  428. package/dist/utils/queue.d.ts.map +1 -1
  429. package/dist/utils/queue.js +1 -0
  430. package/dist/utils/queue.js.map +1 -1
  431. package/dist/utils/utils.d.ts.map +1 -1
  432. package/dist/utils/utils.js +5 -4
  433. package/dist/utils/utils.js.map +1 -1
  434. package/dist/utils/waitress.d.ts +1 -1
  435. package/dist/utils/waitress.js +3 -3
  436. package/dist/zspec/consts.d.ts +1 -1
  437. package/dist/zspec/consts.d.ts.map +1 -1
  438. package/dist/zspec/consts.js +1 -1
  439. package/dist/zspec/index.d.ts +3 -3
  440. package/dist/zspec/tstypes.d.ts +1 -1
  441. package/dist/zspec/utils.d.ts +4 -4
  442. package/dist/zspec/utils.d.ts.map +1 -1
  443. package/dist/zspec/utils.js +9 -13
  444. package/dist/zspec/utils.js.map +1 -1
  445. package/dist/zspec/zcl/buffaloZcl.d.ts +3 -3
  446. package/dist/zspec/zcl/buffaloZcl.d.ts.map +1 -1
  447. package/dist/zspec/zcl/buffaloZcl.js +127 -84
  448. package/dist/zspec/zcl/buffaloZcl.js.map +1 -1
  449. package/dist/zspec/zcl/definition/cluster.d.ts +1 -1
  450. package/dist/zspec/zcl/definition/cluster.d.ts.map +1 -1
  451. package/dist/zspec/zcl/definition/cluster.js +894 -893
  452. package/dist/zspec/zcl/definition/cluster.js.map +1 -1
  453. package/dist/zspec/zcl/definition/consts.js +7 -7
  454. package/dist/zspec/zcl/definition/foundation.d.ts +3 -3
  455. package/dist/zspec/zcl/definition/foundation.d.ts.map +1 -1
  456. package/dist/zspec/zcl/definition/foundation.js +88 -89
  457. package/dist/zspec/zcl/definition/foundation.js.map +1 -1
  458. package/dist/zspec/zcl/definition/manufacturerCode.d.ts +1 -1
  459. package/dist/zspec/zcl/definition/manufacturerCode.js +1 -1
  460. package/dist/zspec/zcl/definition/manufacturerCode.js.map +1 -1
  461. package/dist/zspec/zcl/definition/status.d.ts +3 -3
  462. package/dist/zspec/zcl/definition/status.js +3 -3
  463. package/dist/zspec/zcl/definition/tstype.d.ts +3 -3
  464. package/dist/zspec/zcl/definition/tstype.d.ts.map +1 -1
  465. package/dist/zspec/zcl/index.d.ts +10 -10
  466. package/dist/zspec/zcl/utils.d.ts +3 -3
  467. package/dist/zspec/zcl/utils.d.ts.map +1 -1
  468. package/dist/zspec/zcl/utils.js +18 -21
  469. package/dist/zspec/zcl/utils.js.map +1 -1
  470. package/dist/zspec/zcl/zclFrame.d.ts +7 -7
  471. package/dist/zspec/zcl/zclFrame.d.ts.map +1 -1
  472. package/dist/zspec/zcl/zclFrame.js +38 -41
  473. package/dist/zspec/zcl/zclFrame.js.map +1 -1
  474. package/dist/zspec/zcl/zclHeader.d.ts +2 -2
  475. package/dist/zspec/zcl/zclHeader.d.ts.map +1 -1
  476. package/dist/zspec/zcl/zclHeader.js +3 -3
  477. package/dist/zspec/zcl/zclStatusError.d.ts +1 -1
  478. package/dist/zspec/zdo/buffaloZdo.d.ts +7 -7
  479. package/dist/zspec/zdo/buffaloZdo.d.ts.map +1 -1
  480. package/dist/zspec/zdo/buffaloZdo.js +4 -4
  481. package/dist/zspec/zdo/buffaloZdo.js.map +1 -1
  482. package/dist/zspec/zdo/definition/status.d.ts +1 -1
  483. package/dist/zspec/zdo/definition/status.js +1 -1
  484. package/dist/zspec/zdo/definition/tstypes.d.ts +48 -48
  485. package/dist/zspec/zdo/definition/tstypes.d.ts.map +1 -1
  486. package/dist/zspec/zdo/index.d.ts +7 -7
  487. package/dist/zspec/zdo/utils.d.ts +2 -2
  488. package/dist/zspec/zdo/utils.d.ts.map +1 -1
  489. package/dist/zspec/zdo/utils.js +1 -1
  490. package/dist/zspec/zdo/utils.js.map +1 -1
  491. package/dist/zspec/zdo/zdoStatusError.d.ts +1 -1
  492. package/examples/join-and-log.js +5 -5
  493. package/package.json +6 -13
  494. package/src/adapter/adapter.ts +189 -0
  495. package/src/adapter/adapterDiscovery.ts +653 -0
  496. package/src/adapter/const.ts +12 -0
  497. package/src/adapter/deconz/adapter/deconzAdapter.ts +768 -0
  498. package/src/adapter/deconz/driver/constants.ts +180 -0
  499. package/src/adapter/deconz/driver/driver.ts +900 -0
  500. package/src/adapter/deconz/driver/frame.ts +11 -0
  501. package/src/adapter/deconz/driver/frameParser.ts +557 -0
  502. package/src/adapter/deconz/driver/parser.ts +45 -0
  503. package/src/adapter/deconz/driver/writer.ts +22 -0
  504. package/src/adapter/deconz/types.d.ts +13 -0
  505. package/src/adapter/ember/adapter/emberAdapter.ts +2266 -0
  506. package/src/adapter/ember/adapter/endpoints.ts +86 -0
  507. package/src/adapter/ember/adapter/oneWaitress.ts +322 -0
  508. package/src/adapter/ember/adapter/tokensManager.ts +782 -0
  509. package/src/adapter/ember/consts.ts +178 -0
  510. package/src/adapter/ember/enums.ts +2123 -0
  511. package/src/adapter/ember/ezsp/buffalo.ts +1397 -0
  512. package/src/adapter/ember/ezsp/consts.ts +148 -0
  513. package/src/adapter/ember/ezsp/enums.ts +1087 -0
  514. package/src/adapter/ember/ezsp/ezsp.ts +8985 -0
  515. package/src/adapter/ember/ezspError.ts +10 -0
  516. package/src/adapter/ember/types.ts +866 -0
  517. package/src/adapter/ember/uart/ash.ts +1969 -0
  518. package/src/adapter/ember/uart/consts.ts +109 -0
  519. package/src/adapter/ember/uart/enums.ts +192 -0
  520. package/src/adapter/ember/uart/parser.ts +48 -0
  521. package/src/adapter/ember/uart/queues.ts +247 -0
  522. package/src/adapter/ember/uart/writer.ts +53 -0
  523. package/src/adapter/ember/utils/initters.ts +58 -0
  524. package/src/adapter/ember/utils/math.ts +73 -0
  525. package/src/adapter/events.ts +21 -0
  526. package/src/adapter/ezsp/adapter/backup.ts +109 -0
  527. package/src/adapter/ezsp/adapter/ezspAdapter.ts +614 -0
  528. package/src/adapter/ezsp/driver/commands.ts +2497 -0
  529. package/src/adapter/ezsp/driver/consts.ts +11 -0
  530. package/src/adapter/ezsp/driver/driver.ts +1002 -0
  531. package/src/adapter/ezsp/driver/ezsp.ts +802 -0
  532. package/src/adapter/ezsp/driver/frame.ts +101 -0
  533. package/src/adapter/ezsp/driver/index.ts +4 -0
  534. package/src/adapter/ezsp/driver/multicast.ts +78 -0
  535. package/src/adapter/ezsp/driver/parser.ts +81 -0
  536. package/src/adapter/ezsp/driver/types/basic.ts +201 -0
  537. package/src/adapter/ezsp/driver/types/index.ts +239 -0
  538. package/src/adapter/ezsp/driver/types/named.ts +2330 -0
  539. package/src/adapter/ezsp/driver/types/struct.ts +844 -0
  540. package/src/adapter/ezsp/driver/uart.ts +460 -0
  541. package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +44 -0
  542. package/src/adapter/ezsp/driver/utils/index.ts +32 -0
  543. package/src/adapter/ezsp/driver/writer.ts +64 -0
  544. package/src/adapter/index.ts +3 -0
  545. package/src/adapter/serialPort.ts +58 -0
  546. package/src/adapter/socketPortUtils.ts +16 -0
  547. package/src/adapter/tstype.ts +78 -0
  548. package/src/adapter/z-stack/adapter/adapter-backup.ts +519 -0
  549. package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +457 -0
  550. package/src/adapter/z-stack/adapter/endpoints.ts +57 -0
  551. package/src/adapter/z-stack/adapter/manager.ts +543 -0
  552. package/src/adapter/z-stack/adapter/tstype.ts +6 -0
  553. package/src/adapter/z-stack/adapter/zStackAdapter.ts +1190 -0
  554. package/src/adapter/z-stack/constants/af.ts +27 -0
  555. package/src/adapter/z-stack/constants/common.ts +285 -0
  556. package/src/adapter/z-stack/constants/dbg.ts +23 -0
  557. package/src/adapter/z-stack/constants/index.ts +11 -0
  558. package/src/adapter/z-stack/constants/mac.ts +128 -0
  559. package/src/adapter/z-stack/constants/sapi.ts +25 -0
  560. package/src/adapter/z-stack/constants/sys.ts +72 -0
  561. package/src/adapter/z-stack/constants/util.ts +82 -0
  562. package/src/adapter/z-stack/constants/utils.ts +14 -0
  563. package/src/adapter/z-stack/constants/zdo.ts +103 -0
  564. package/src/adapter/z-stack/models/startup-options.ts +13 -0
  565. package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +44 -0
  566. package/src/adapter/z-stack/structs/entries/address-manager-table.ts +19 -0
  567. package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +12 -0
  568. package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +21 -0
  569. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +19 -0
  570. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +21 -0
  571. package/src/adapter/z-stack/structs/entries/channel-list.ts +8 -0
  572. package/src/adapter/z-stack/structs/entries/has-configured.ts +16 -0
  573. package/src/adapter/z-stack/structs/entries/index.ts +16 -0
  574. package/src/adapter/z-stack/structs/entries/nib.ts +66 -0
  575. package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +15 -0
  576. package/src/adapter/z-stack/structs/entries/nwk-key.ts +13 -0
  577. package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +8 -0
  578. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +20 -0
  579. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +19 -0
  580. package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +33 -0
  581. package/src/adapter/z-stack/structs/entries/security-manager-table.ts +22 -0
  582. package/src/adapter/z-stack/structs/index.ts +4 -0
  583. package/src/adapter/z-stack/structs/serializable-memory-object.ts +14 -0
  584. package/src/adapter/z-stack/structs/struct.ts +367 -0
  585. package/src/adapter/z-stack/structs/table.ts +198 -0
  586. package/src/adapter/z-stack/unpi/constants.ts +33 -0
  587. package/src/adapter/z-stack/unpi/frame.ts +62 -0
  588. package/src/adapter/z-stack/unpi/index.ts +4 -0
  589. package/src/adapter/z-stack/unpi/parser.ts +56 -0
  590. package/src/adapter/z-stack/unpi/writer.ts +21 -0
  591. package/src/adapter/z-stack/utils/channel-list.ts +40 -0
  592. package/src/adapter/z-stack/utils/index.ts +2 -0
  593. package/src/adapter/z-stack/utils/network-options.ts +26 -0
  594. package/src/adapter/z-stack/znp/buffaloZnp.ts +175 -0
  595. package/src/adapter/z-stack/znp/definition.ts +2713 -0
  596. package/src/adapter/z-stack/znp/index.ts +2 -0
  597. package/src/adapter/z-stack/znp/parameterType.ts +22 -0
  598. package/src/adapter/z-stack/znp/tstype.ts +44 -0
  599. package/src/adapter/z-stack/znp/utils.ts +10 -0
  600. package/src/adapter/z-stack/znp/znp.ts +342 -0
  601. package/src/adapter/z-stack/znp/zpiObject.ts +148 -0
  602. package/src/adapter/zboss/adapter/zbossAdapter.ts +527 -0
  603. package/src/adapter/zboss/commands.ts +1184 -0
  604. package/src/adapter/zboss/consts.ts +9 -0
  605. package/src/adapter/zboss/driver.ts +423 -0
  606. package/src/adapter/zboss/enums.ts +360 -0
  607. package/src/adapter/zboss/frame.ts +227 -0
  608. package/src/adapter/zboss/reader.ts +65 -0
  609. package/src/adapter/zboss/types.ts +0 -0
  610. package/src/adapter/zboss/uart.ts +428 -0
  611. package/src/adapter/zboss/utils.ts +58 -0
  612. package/src/adapter/zboss/writer.ts +49 -0
  613. package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +27 -0
  614. package/src/adapter/zigate/adapter/zigateAdapter.ts +618 -0
  615. package/src/adapter/zigate/driver/LICENSE +17 -0
  616. package/src/adapter/zigate/driver/buffaloZiGate.ts +212 -0
  617. package/src/adapter/zigate/driver/commandType.ts +418 -0
  618. package/src/adapter/zigate/driver/constants.ts +150 -0
  619. package/src/adapter/zigate/driver/frame.ts +197 -0
  620. package/src/adapter/zigate/driver/messageType.ts +287 -0
  621. package/src/adapter/zigate/driver/parameterType.ts +32 -0
  622. package/src/adapter/zigate/driver/ziGateObject.ts +146 -0
  623. package/src/adapter/zigate/driver/zigate.ts +426 -0
  624. package/src/adapter/zoh/adapter/utils.ts +27 -0
  625. package/src/adapter/zoh/adapter/zohAdapter.ts +837 -0
  626. package/src/buffalo/buffalo.ts +335 -0
  627. package/src/buffalo/index.ts +1 -0
  628. package/src/controller/controller.ts +1048 -0
  629. package/src/controller/database.ts +124 -0
  630. package/src/controller/events.ts +51 -0
  631. package/src/controller/greenPower.ts +603 -0
  632. package/src/controller/helpers/index.ts +1 -0
  633. package/src/controller/helpers/request.ts +94 -0
  634. package/src/controller/helpers/requestQueue.ts +125 -0
  635. package/src/controller/helpers/zclFrameConverter.ts +51 -0
  636. package/src/controller/helpers/zclTransactionSequenceNumber.ts +19 -0
  637. package/src/controller/index.ts +6 -0
  638. package/src/controller/model/device.ts +1320 -0
  639. package/src/controller/model/endpoint.ts +1040 -0
  640. package/src/controller/model/entity.ts +23 -0
  641. package/src/controller/model/group.ts +333 -0
  642. package/src/controller/model/index.ts +4 -0
  643. package/src/controller/touchlink.ts +189 -0
  644. package/src/controller/tstype.ts +39 -0
  645. package/src/index.ts +12 -0
  646. package/src/models/backup-storage-legacy.ts +48 -0
  647. package/src/models/backup-storage-unified.ts +47 -0
  648. package/src/models/backup.ts +37 -0
  649. package/src/models/index.ts +5 -0
  650. package/src/models/network-options.ts +11 -0
  651. package/src/utils/backup.ts +152 -0
  652. package/src/utils/index.ts +5 -0
  653. package/src/utils/logger.ts +20 -0
  654. package/src/utils/patchBigIntSerialization.ts +8 -0
  655. package/src/utils/queue.ts +76 -0
  656. package/src/utils/types.d.ts +3 -0
  657. package/src/utils/utils.ts +20 -0
  658. package/src/utils/wait.ts +5 -0
  659. package/src/utils/waitress.ts +95 -0
  660. package/src/zspec/consts.ts +84 -0
  661. package/src/zspec/enums.ts +22 -0
  662. package/src/zspec/index.ts +3 -0
  663. package/src/zspec/tstypes.ts +18 -0
  664. package/src/zspec/utils.ts +308 -0
  665. package/src/zspec/zcl/buffaloZcl.ts +1133 -0
  666. package/src/zspec/zcl/definition/cluster.ts +5398 -0
  667. package/src/zspec/zcl/definition/consts.ts +24 -0
  668. package/src/zspec/zcl/definition/enums.ts +194 -0
  669. package/src/zspec/zcl/definition/foundation.ts +301 -0
  670. package/src/zspec/zcl/definition/manufacturerCode.ts +729 -0
  671. package/src/zspec/zcl/definition/status.ts +69 -0
  672. package/src/zspec/zcl/definition/tstype.ts +236 -0
  673. package/src/zspec/zcl/index.ts +10 -0
  674. package/src/zspec/zcl/utils.ts +342 -0
  675. package/src/zspec/zcl/zclFrame.ts +336 -0
  676. package/src/zspec/zcl/zclHeader.ts +102 -0
  677. package/src/zspec/zcl/zclStatusError.ts +10 -0
  678. package/src/zspec/zdo/buffaloZdo.ts +2345 -0
  679. package/src/zspec/zdo/definition/clusters.ts +722 -0
  680. package/src/zspec/zdo/definition/consts.ts +16 -0
  681. package/src/zspec/zdo/definition/enums.ts +99 -0
  682. package/src/zspec/zdo/definition/status.ts +105 -0
  683. package/src/zspec/zdo/definition/tstypes.ts +1062 -0
  684. package/src/zspec/zdo/index.ts +7 -0
  685. package/src/zspec/zdo/utils.ts +76 -0
  686. package/src/zspec/zdo/zdoStatusError.ts +10 -0
  687. package/test/adapter/adapter.test.ts +1062 -0
  688. package/test/adapter/ember/ash.test.ts +337 -0
  689. package/test/adapter/ember/consts.ts +131 -0
  690. package/test/adapter/ember/emberAdapter.test.ts +3449 -0
  691. package/test/adapter/ember/ezsp.test.ts +386 -0
  692. package/test/adapter/ember/ezspBuffalo.test.ts +92 -0
  693. package/test/adapter/ember/ezspError.test.ts +11 -0
  694. package/test/adapter/ember/math.test.ts +205 -0
  695. package/test/adapter/ezsp/frame.test.ts +29 -0
  696. package/test/adapter/ezsp/uart.test.ts +180 -0
  697. package/test/adapter/z-stack/adapter.test.ts +3985 -0
  698. package/test/adapter/z-stack/constants.test.ts +32 -0
  699. package/test/adapter/z-stack/structs.test.ts +114 -0
  700. package/test/adapter/z-stack/unpi.test.ts +212 -0
  701. package/test/adapter/z-stack/znp.test.ts +1284 -0
  702. package/test/adapter/zboss/fixZdoResponse.test.ts +178 -0
  703. package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +80 -0
  704. package/test/adapter/zigate/zdo.test.ts +187 -0
  705. package/test/adapter/zoh/utils.test.ts +35 -0
  706. package/test/adapter/zoh/zohAdapter.test.ts +1306 -0
  707. package/test/buffalo.test.ts +430 -0
  708. package/test/controller.test.ts +10005 -0
  709. package/test/greenpower.test.ts +1421 -0
  710. package/test/mockAdapters.ts +65 -0
  711. package/test/mockDevices.ts +472 -0
  712. package/test/testUtils.ts +20 -0
  713. package/test/tsconfig.json +10 -0
  714. package/test/utils/math.ts +19 -0
  715. package/test/utils.test.ts +227 -0
  716. package/test/vitest.config.mts +25 -0
  717. package/test/zcl.test.ts +2832 -0
  718. package/test/zspec/utils.test.ts +131 -0
  719. package/test/zspec/zcl/buffalo.test.ts +1231 -0
  720. package/test/zspec/zcl/frame.test.ts +925 -0
  721. package/test/zspec/zcl/utils.test.ts +280 -0
  722. package/test/zspec/zdo/buffalo.test.ts +1849 -0
  723. package/test/zspec/zdo/utils.test.ts +240 -0
  724. package/.prettierignore +0 -2
  725. package/.prettierrc +0 -26
  726. package/eslint.config.mjs +0 -32
@@ -0,0 +1,2345 @@
1
+ import Buffalo from "../../buffalo/buffalo";
2
+ import {logger} from "../../utils/logger";
3
+ import {DEFAULT_ENCRYPTION_KEY_SIZE, EUI64_SIZE, EXTENDED_PAN_ID_SIZE, PAN_ID_SIZE} from "../consts";
4
+ import type {ClusterId, Eui64, NodeId, ProfileId} from "../tstypes";
5
+ import * as ZSpecUtils from "../utils";
6
+ import {ClusterId as ZdoClusterId} from "./definition/clusters";
7
+ import {CHALLENGE_VALUE_SIZE, CURVE_PUBLIC_POINT_SIZE, MULTICAST_BINDING, UNICAST_BINDING, ZDO_MESSAGE_OVERHEAD} from "./definition/consts";
8
+ import {GlobalTLV, type LeaveRequestFlags, RoutingTableStatus} from "./definition/enums";
9
+ import {Status} from "./definition/status";
10
+ import type {
11
+ APSFrameCounterChallengeTLV,
12
+ APSFrameCounterResponseTLV,
13
+ ActiveEndpointsResponse,
14
+ AuthenticationTokenIdTLV,
15
+ BeaconAppendixEncapsulationGlobalTLV,
16
+ BeaconSurveyConfigurationTLV,
17
+ BeaconSurveyResultsTLV,
18
+ BindingTableEntry,
19
+ BindingTableResponse,
20
+ ChallengeResponse,
21
+ ClearAllBindingsReqEUI64TLV,
22
+ ConfigurationParametersGlobalTLV,
23
+ Curve25519PublicPointTLV,
24
+ DeviceAuthenticationLevelTLV,
25
+ DeviceCapabilityExtensionGlobalTLV,
26
+ DeviceEUI64ListTLV,
27
+ FragmentationParametersGlobalTLV,
28
+ GetAuthenticationLevelResponse,
29
+ GetConfigurationResponse,
30
+ IEEEAddressResponse,
31
+ JoinerEncapsulationGlobalTLV,
32
+ LQITableEntry,
33
+ LQITableResponse,
34
+ LocalTLVReader,
35
+ ManufacturerSpecificGlobalTLV,
36
+ MatchDescriptorsResponse,
37
+ NetworkAddressResponse,
38
+ NextChannelChangeGlobalTLV,
39
+ NextPanIdChangeGlobalTLV,
40
+ NodeDescriptorResponse,
41
+ NwkBeaconSurveyResponse,
42
+ NwkEnhancedUpdateResponse,
43
+ NwkIEEEJoiningListResponse,
44
+ NwkUnsolicitedEnhancedUpdateResponse,
45
+ NwkUpdateResponse,
46
+ PanIdConflictReportGlobalTLV,
47
+ ParentAnnounceResponse,
48
+ PotentialParentsTLV,
49
+ PowerDescriptorResponse,
50
+ ProcessingStatusTLV,
51
+ RequestMap,
52
+ ResponseMap,
53
+ RetrieveAuthenticationTokenResponse,
54
+ RouterInformationGlobalTLV,
55
+ RoutingTableEntry,
56
+ RoutingTableResponse,
57
+ SelectedKeyNegotiationMethodTLV,
58
+ ServerMask,
59
+ SetConfigurationResponse,
60
+ SimpleDescriptorResponse,
61
+ StartKeyNegotiationResponse,
62
+ SupportedKeyNegotiationMethodsGlobalTLV,
63
+ SymmetricPassphraseGlobalTLV,
64
+ SystemServerDiscoveryResponse,
65
+ TargetIEEEAddressTLV,
66
+ Tlv,
67
+ ValidResponseMap,
68
+ } from "./definition/tstypes";
69
+ import * as Utils from "./utils";
70
+ import {ZdoStatusError} from "./zdoStatusError";
71
+
72
+ const NS = "zh:zdo:buffalo";
73
+
74
+ const MAX_BUFFER_SIZE = 255;
75
+
76
+ export class BuffaloZdo extends Buffalo {
77
+ /**
78
+ * Set the position of the internal position tracker.
79
+ * TODO: move to base `Buffalo` class
80
+ * @param position
81
+ */
82
+ public setPosition(position: number): void {
83
+ this.position = position;
84
+ }
85
+
86
+ /**
87
+ * Set the byte at given position without affecting the internal position tracker.
88
+ * TODO: move to base `Buffalo` class
89
+ * @param position
90
+ * @param value
91
+ */
92
+ public setByte(position: number, value: number): void {
93
+ this.buffer.writeUInt8(value, position);
94
+ }
95
+
96
+ /**
97
+ * Get the byte at given position without affecting the internal position tracker.
98
+ * TODO: move to base `Buffalo` class
99
+ * @param position
100
+ * @returns
101
+ */
102
+ public getByte(position: number): number {
103
+ return this.buffer.readUInt8(position);
104
+ }
105
+
106
+ /**
107
+ * Check if internal buffer has enough bytes to satisfy: (current position + given count).
108
+ * TODO: move to base `Buffalo` class
109
+ * @param count
110
+ * @returns True if has given more bytes
111
+ */
112
+ public isMoreBy(count: number): boolean {
113
+ return this.position + count <= this.buffer.length;
114
+ }
115
+
116
+ //-- GLOBAL TLVS
117
+
118
+ private writeManufacturerSpecificGlobalTLV(tlv: ManufacturerSpecificGlobalTLV): void {
119
+ this.writeUInt16(tlv.zigbeeManufacturerId);
120
+ this.writeBuffer(tlv.additionalData, tlv.additionalData.length);
121
+ }
122
+
123
+ private readManufacturerSpecificGlobalTLV(length: number): ManufacturerSpecificGlobalTLV {
124
+ logger.debug(`readManufacturerSpecificGlobalTLV with length=${length}`, NS);
125
+ if (length < 2) {
126
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
127
+ }
128
+
129
+ const zigbeeManufacturerId = this.readUInt16();
130
+ const additionalData = this.readBuffer(length - 2);
131
+
132
+ return {
133
+ zigbeeManufacturerId,
134
+ additionalData,
135
+ };
136
+ }
137
+
138
+ private writeSupportedKeyNegotiationMethodsGlobalTLV(tlv: SupportedKeyNegotiationMethodsGlobalTLV): void {
139
+ this.writeUInt8(tlv.keyNegotiationProtocolsBitmask);
140
+ this.writeUInt8(tlv.preSharedSecretsBitmask);
141
+
142
+ if (tlv.sourceDeviceEui64) {
143
+ this.writeIeeeAddr(tlv.sourceDeviceEui64);
144
+ }
145
+ }
146
+
147
+ private readSupportedKeyNegotiationMethodsGlobalTLV(length: number): SupportedKeyNegotiationMethodsGlobalTLV {
148
+ logger.debug(`readSupportedKeyNegotiationMethodsGlobalTLV with length=${length}`, NS);
149
+ if (length < 2) {
150
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
151
+ }
152
+
153
+ const keyNegotiationProtocolsBitmask = this.readUInt8();
154
+ const preSharedSecretsBitmask = this.readUInt8();
155
+ let sourceDeviceEui64: SupportedKeyNegotiationMethodsGlobalTLV["sourceDeviceEui64"];
156
+
157
+ if (length >= 2 + EUI64_SIZE) {
158
+ sourceDeviceEui64 = this.readIeeeAddr();
159
+ }
160
+
161
+ return {
162
+ keyNegotiationProtocolsBitmask,
163
+ preSharedSecretsBitmask,
164
+ sourceDeviceEui64,
165
+ };
166
+ }
167
+
168
+ private writePanIdConflictReportGlobalTLV(tlv: PanIdConflictReportGlobalTLV): void {
169
+ this.writeUInt16(tlv.nwkPanIdConflictCount);
170
+ }
171
+
172
+ private readPanIdConflictReportGlobalTLV(length: number): PanIdConflictReportGlobalTLV {
173
+ logger.debug(`readPanIdConflictReportGlobalTLV with length=${length}`, NS);
174
+ if (length < 2) {
175
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
176
+ }
177
+
178
+ const nwkPanIdConflictCount = this.readUInt16();
179
+
180
+ return {
181
+ nwkPanIdConflictCount,
182
+ };
183
+ }
184
+
185
+ private writeNextPanIdChangeGlobalTLV(tlv: NextPanIdChangeGlobalTLV): void {
186
+ this.writeUInt16(tlv.panId);
187
+ }
188
+
189
+ private readNextPanIdChangeGlobalTLV(length: number): NextPanIdChangeGlobalTLV {
190
+ logger.debug(`readNextPanIdChangeGlobalTLV with length=${length}`, NS);
191
+ if (length < PAN_ID_SIZE) {
192
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least ${PAN_ID_SIZE}.`);
193
+ }
194
+
195
+ const panId = this.readUInt16();
196
+
197
+ return {
198
+ panId,
199
+ };
200
+ }
201
+
202
+ private writeNextChannelChangeGlobalTLV(tlv: NextChannelChangeGlobalTLV): void {
203
+ this.writeUInt32(tlv.channel);
204
+ }
205
+
206
+ private readNextChannelChangeGlobalTLV(length: number): NextChannelChangeGlobalTLV {
207
+ logger.debug(`readNextChannelChangeGlobalTLV with length=${length}`, NS);
208
+ if (length < 4) {
209
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 4.`);
210
+ }
211
+
212
+ const channel = this.readUInt32();
213
+
214
+ return {
215
+ channel,
216
+ };
217
+ }
218
+
219
+ private writeSymmetricPassphraseGlobalTLV(tlv: SymmetricPassphraseGlobalTLV): void {
220
+ this.writeBuffer(tlv.passphrase, DEFAULT_ENCRYPTION_KEY_SIZE);
221
+ }
222
+
223
+ private readSymmetricPassphraseGlobalTLV(length: number): SymmetricPassphraseGlobalTLV {
224
+ logger.debug(`readSymmetricPassphraseGlobalTLV with length=${length}`, NS);
225
+ if (length < DEFAULT_ENCRYPTION_KEY_SIZE) {
226
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least ${DEFAULT_ENCRYPTION_KEY_SIZE}.`);
227
+ }
228
+
229
+ const passphrase = this.readBuffer(DEFAULT_ENCRYPTION_KEY_SIZE);
230
+
231
+ return {
232
+ passphrase,
233
+ };
234
+ }
235
+
236
+ private writeRouterInformationGlobalTLV(tlv: RouterInformationGlobalTLV): void {
237
+ this.writeUInt16(tlv.bitmask);
238
+ }
239
+
240
+ private readRouterInformationGlobalTLV(length: number): RouterInformationGlobalTLV {
241
+ logger.debug(`readRouterInformationGlobalTLV with length=${length}`, NS);
242
+ if (length < 2) {
243
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
244
+ }
245
+
246
+ const bitmask = this.readUInt16();
247
+
248
+ return {
249
+ bitmask,
250
+ };
251
+ }
252
+
253
+ private writeFragmentationParametersGlobalTLV(tlv: FragmentationParametersGlobalTLV): void {
254
+ this.writeUInt16(tlv.nwkAddress);
255
+
256
+ if (tlv.fragmentationOptions !== undefined) {
257
+ this.writeUInt8(tlv.fragmentationOptions);
258
+ }
259
+
260
+ if (tlv.maxIncomingTransferUnit !== undefined) {
261
+ this.writeUInt16(tlv.maxIncomingTransferUnit);
262
+ }
263
+ }
264
+
265
+ private readFragmentationParametersGlobalTLV(length: number): FragmentationParametersGlobalTLV {
266
+ logger.debug(`readFragmentationParametersGlobalTLV with length=${length}`, NS);
267
+ if (length < 2) {
268
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
269
+ }
270
+
271
+ const nwkAddress = this.readUInt16();
272
+ let fragmentationOptions: FragmentationParametersGlobalTLV["fragmentationOptions"];
273
+ let maxIncomingTransferUnit: FragmentationParametersGlobalTLV["maxIncomingTransferUnit"];
274
+
275
+ if (length >= 3) {
276
+ fragmentationOptions = this.readUInt8();
277
+ }
278
+
279
+ if (length >= 5) {
280
+ maxIncomingTransferUnit = this.readUInt16();
281
+ }
282
+
283
+ return {
284
+ nwkAddress,
285
+ fragmentationOptions,
286
+ maxIncomingTransferUnit,
287
+ };
288
+ }
289
+
290
+ private writeJoinerEncapsulationGlobalTLV(encapsulationTLV: JoinerEncapsulationGlobalTLV): void {
291
+ this.writeGlobalTLVs(encapsulationTLV.additionalTLVs);
292
+ }
293
+
294
+ private readJoinerEncapsulationGlobalTLV(length: number): JoinerEncapsulationGlobalTLV {
295
+ logger.debug(`readJoinerEncapsulationGlobalTLV with length=${length}`, NS);
296
+ // at least the length of tagId+length for first encapsulated tlv, doesn't make sense otherwise
297
+ if (length < 2) {
298
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
299
+ }
300
+
301
+ const encapsulationBuffalo = new BuffaloZdo(this.readBuffer(length));
302
+ const additionalTLVs = encapsulationBuffalo.readTLVs(undefined, true);
303
+
304
+ return {
305
+ additionalTLVs,
306
+ };
307
+ }
308
+
309
+ private writeBeaconAppendixEncapsulationGlobalTLV(encapsulationTLV: BeaconAppendixEncapsulationGlobalTLV): void {
310
+ this.writeGlobalTLVs(encapsulationTLV.additionalTLVs);
311
+ }
312
+
313
+ private readBeaconAppendixEncapsulationGlobalTLV(length: number): BeaconAppendixEncapsulationGlobalTLV {
314
+ logger.debug(`readBeaconAppendixEncapsulationGlobalTLV with length=${length}`, NS);
315
+ // at least the length of tagId+length for first encapsulated tlv, doesn't make sense otherwise
316
+ if (length < 2) {
317
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
318
+ }
319
+
320
+ const encapsulationBuffalo = new BuffaloZdo(this.readBuffer(length));
321
+ // Global: SupportedKeyNegotiationMethodsGlobalTLV
322
+ // Global: FragmentationParametersGlobalTLV
323
+ const additionalTLVs = encapsulationBuffalo.readTLVs(undefined, true);
324
+
325
+ return {
326
+ additionalTLVs,
327
+ };
328
+ }
329
+
330
+ private writeConfigurationParametersGlobalTLV(configurationParameters: ConfigurationParametersGlobalTLV): void {
331
+ this.writeUInt16(configurationParameters.configurationParameters);
332
+ }
333
+
334
+ private readConfigurationParametersGlobalTLV(length: number): ConfigurationParametersGlobalTLV {
335
+ logger.debug(`readConfigurationParametersGlobalTLV with length=${length}`, NS);
336
+ if (length < 2) {
337
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 2.`);
338
+ }
339
+
340
+ const configurationParameters = this.readUInt16();
341
+
342
+ return {
343
+ configurationParameters,
344
+ };
345
+ }
346
+
347
+ private writeDeviceCapabilityExtensionGlobalTLV(tlv: DeviceCapabilityExtensionGlobalTLV): void {
348
+ this.writeBuffer(tlv.data, tlv.data.length);
349
+ }
350
+
351
+ private readDeviceCapabilityExtensionGlobalTLV(length: number): DeviceCapabilityExtensionGlobalTLV {
352
+ logger.debug(`readDeviceCapabilityExtensionGlobalTLV with length=${length}`, NS);
353
+ const data = this.readBuffer(length);
354
+
355
+ return {
356
+ data,
357
+ };
358
+ }
359
+
360
+ public writeGlobalTLV(tlv: Tlv): void {
361
+ this.writeUInt8(tlv.tagId);
362
+ this.writeUInt8(tlv.length - 1); // remove offset (spec quirk...)
363
+
364
+ switch (tlv.tagId) {
365
+ case GlobalTLV.MANUFACTURER_SPECIFIC: {
366
+ this.writeManufacturerSpecificGlobalTLV(tlv.tlv as ManufacturerSpecificGlobalTLV);
367
+ break;
368
+ }
369
+ case GlobalTLV.SUPPORTED_KEY_NEGOTIATION_METHODS: {
370
+ this.writeSupportedKeyNegotiationMethodsGlobalTLV(tlv.tlv as SupportedKeyNegotiationMethodsGlobalTLV);
371
+ break;
372
+ }
373
+ case GlobalTLV.PAN_ID_CONFLICT_REPORT: {
374
+ this.writePanIdConflictReportGlobalTLV(tlv.tlv as PanIdConflictReportGlobalTLV);
375
+ break;
376
+ }
377
+ case GlobalTLV.NEXT_PAN_ID_CHANGE: {
378
+ this.writeNextPanIdChangeGlobalTLV(tlv.tlv as NextPanIdChangeGlobalTLV);
379
+ break;
380
+ }
381
+ case GlobalTLV.NEXT_CHANNEL_CHANGE: {
382
+ this.writeNextChannelChangeGlobalTLV(tlv.tlv as NextChannelChangeGlobalTLV);
383
+ break;
384
+ }
385
+ case GlobalTLV.SYMMETRIC_PASSPHRASE: {
386
+ this.writeSymmetricPassphraseGlobalTLV(tlv.tlv as SymmetricPassphraseGlobalTLV);
387
+ break;
388
+ }
389
+ case GlobalTLV.ROUTER_INFORMATION: {
390
+ this.writeRouterInformationGlobalTLV(tlv.tlv as RouterInformationGlobalTLV);
391
+ break;
392
+ }
393
+ case GlobalTLV.FRAGMENTATION_PARAMETERS: {
394
+ this.writeFragmentationParametersGlobalTLV(tlv.tlv as FragmentationParametersGlobalTLV);
395
+ break;
396
+ }
397
+ case GlobalTLV.JOINER_ENCAPSULATION: {
398
+ this.writeJoinerEncapsulationGlobalTLV(tlv.tlv as JoinerEncapsulationGlobalTLV);
399
+ break;
400
+ }
401
+ case GlobalTLV.BEACON_APPENDIX_ENCAPSULATION: {
402
+ this.writeBeaconAppendixEncapsulationGlobalTLV(tlv.tlv as BeaconAppendixEncapsulationGlobalTLV);
403
+ break;
404
+ }
405
+ case GlobalTLV.CONFIGURATION_PARAMETERS: {
406
+ this.writeConfigurationParametersGlobalTLV(tlv.tlv as ConfigurationParametersGlobalTLV);
407
+ break;
408
+ }
409
+ case GlobalTLV.DEVICE_CAPABILITY_EXTENSION: {
410
+ this.writeDeviceCapabilityExtensionGlobalTLV(tlv.tlv as DeviceCapabilityExtensionGlobalTLV);
411
+ break;
412
+ }
413
+ default: {
414
+ throw new ZdoStatusError(Status.NOT_SUPPORTED);
415
+ }
416
+ }
417
+ }
418
+
419
+ public readGlobalTLV(tagId: number, length: number): Tlv["tlv"] | undefined {
420
+ switch (tagId) {
421
+ case GlobalTLV.MANUFACTURER_SPECIFIC: {
422
+ return this.readManufacturerSpecificGlobalTLV(length);
423
+ }
424
+ case GlobalTLV.SUPPORTED_KEY_NEGOTIATION_METHODS: {
425
+ return this.readSupportedKeyNegotiationMethodsGlobalTLV(length);
426
+ }
427
+ case GlobalTLV.PAN_ID_CONFLICT_REPORT: {
428
+ return this.readPanIdConflictReportGlobalTLV(length);
429
+ }
430
+ case GlobalTLV.NEXT_PAN_ID_CHANGE: {
431
+ return this.readNextPanIdChangeGlobalTLV(length);
432
+ }
433
+ case GlobalTLV.NEXT_CHANNEL_CHANGE: {
434
+ return this.readNextChannelChangeGlobalTLV(length);
435
+ }
436
+ case GlobalTLV.SYMMETRIC_PASSPHRASE: {
437
+ return this.readSymmetricPassphraseGlobalTLV(length);
438
+ }
439
+ case GlobalTLV.ROUTER_INFORMATION: {
440
+ return this.readRouterInformationGlobalTLV(length);
441
+ }
442
+ case GlobalTLV.FRAGMENTATION_PARAMETERS: {
443
+ return this.readFragmentationParametersGlobalTLV(length);
444
+ }
445
+ case GlobalTLV.JOINER_ENCAPSULATION: {
446
+ return this.readJoinerEncapsulationGlobalTLV(length);
447
+ }
448
+ case GlobalTLV.BEACON_APPENDIX_ENCAPSULATION: {
449
+ return this.readBeaconAppendixEncapsulationGlobalTLV(length);
450
+ }
451
+ case GlobalTLV.CONFIGURATION_PARAMETERS: {
452
+ return this.readConfigurationParametersGlobalTLV(length);
453
+ }
454
+ case GlobalTLV.DEVICE_CAPABILITY_EXTENSION: {
455
+ return this.readDeviceCapabilityExtensionGlobalTLV(length);
456
+ }
457
+ default: {
458
+ // validation: unknown tag shall be ignored
459
+ return undefined;
460
+ }
461
+ }
462
+ }
463
+
464
+ public writeGlobalTLVs(tlvs: Tlv[]): void {
465
+ for (const tlv of tlvs) {
466
+ this.writeGlobalTLV(tlv);
467
+ }
468
+ }
469
+
470
+ //-- LOCAL TLVS
471
+
472
+ // write only
473
+ // private readBeaconSurveyConfigurationTLV(length: number): BeaconSurveyConfigurationTLV {
474
+ // logger.debug(`readBeaconSurveyConfigurationTLV with length=${length}`, NS);
475
+ // const count = this.readUInt8();
476
+
477
+ // if (length !== (1 + (count * 4) + 1)) {
478
+ // throw new Error(`Malformed TLV. Invalid length '${length}', expected ${(1 + (count * 4) + 1)}.`);
479
+ // }
480
+
481
+ // const scanChannelList = this.readListUInt32(count);
482
+ // const configurationBitmask = this.readUInt8();
483
+
484
+ // return {
485
+ // scanChannelList,
486
+ // configurationBitmask,
487
+ // };
488
+ // }
489
+
490
+ private readCurve25519PublicPointTLV(length: number): Curve25519PublicPointTLV {
491
+ logger.debug(`readCurve25519PublicPointTLV with length=${length}`, NS);
492
+ if (length !== EUI64_SIZE + CURVE_PUBLIC_POINT_SIZE) {
493
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected ${EUI64_SIZE + CURVE_PUBLIC_POINT_SIZE}.`);
494
+ }
495
+
496
+ const eui64 = this.readIeeeAddr();
497
+ const publicPoint = this.readBuffer(CURVE_PUBLIC_POINT_SIZE);
498
+
499
+ return {
500
+ eui64,
501
+ publicPoint,
502
+ };
503
+ }
504
+
505
+ // write only
506
+ // private readTargetIEEEAddressTLV(length: number): TargetIEEEAddressTLV {
507
+ // logger.debug(`readTargetIEEEAddressTLV with length=${length}`, NS);
508
+ // if (length !== EUI64_SIZE) {
509
+ // throw new Error(`Malformed TLV. Invalid length '${length}', expected ${EUI64_SIZE}.`);
510
+ // }
511
+
512
+ // const ieee = this.readIeeeAddr();
513
+
514
+ // return {
515
+ // ieee,
516
+ // };
517
+ // }
518
+
519
+ // write only
520
+ // private readSelectedKeyNegotiationMethodTLV(length: number): SelectedKeyNegotiationMethodTLV {
521
+ // logger.debug(`readSelectedKeyNegotiationMethodTLV with length=${length}`, NS);
522
+ // if (length !== 10) {
523
+ // throw new Error(`Malformed TLV. Invalid length '${length}', expected 10.`);
524
+ // }
525
+
526
+ // const protocol = this.readUInt8();
527
+ // const presharedSecret = this.readUInt8();
528
+ // const sendingDeviceEui64 = this.readIeeeAddr();
529
+
530
+ // return {
531
+ // protocol,
532
+ // presharedSecret,
533
+ // sendingDeviceEui64,
534
+ // };
535
+ // }
536
+
537
+ // write only
538
+ // private readDeviceEUI64ListTLV(length: number): DeviceEUI64ListTLV {
539
+ // logger.debug(`readDeviceEUI64ListTLV with length=${length}`, NS);
540
+ // const count = this.readUInt8();
541
+
542
+ // if (length !== (1 + (count * EUI64_SIZE))) {
543
+ // throw new Error(`Malformed TLV. Invalid length '${length}', expected ${(1 + (count * EUI64_SIZE))}.`);
544
+ // }
545
+
546
+ // const eui64List: DeviceEUI64ListTLV['eui64List'] = [];
547
+
548
+ // for (let i = 0; i < count; i++) {
549
+ // const eui64 = this.readIeeeAddr();
550
+
551
+ // eui64List.push(eui64);
552
+ // }
553
+
554
+ // return {
555
+ // eui64List,
556
+ // };
557
+ // }
558
+
559
+ private readAPSFrameCounterResponseTLV(length: number): APSFrameCounterResponseTLV {
560
+ logger.debug(`readAPSFrameCounterResponseTLV with length=${length}`, NS);
561
+ if (length !== 32) {
562
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected 32.`);
563
+ }
564
+
565
+ const responderEui64 = this.readIeeeAddr();
566
+ const receivedChallengeValue = this.readBuffer(CHALLENGE_VALUE_SIZE);
567
+ const apsFrameCounter = this.readUInt32();
568
+ const challengeSecurityFrameCounter = this.readUInt32();
569
+ const mic = this.readBuffer(8);
570
+
571
+ return {
572
+ responderEui64,
573
+ receivedChallengeValue,
574
+ apsFrameCounter,
575
+ challengeSecurityFrameCounter,
576
+ mic,
577
+ };
578
+ }
579
+
580
+ private readBeaconSurveyResultsTLV(length: number): BeaconSurveyResultsTLV {
581
+ logger.debug(`readBeaconSurveyResultsTLV with length=${length}`, NS);
582
+ if (length !== 4) {
583
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected 4.`);
584
+ }
585
+
586
+ const totalBeaconsReceived = this.readUInt8();
587
+ const onNetworkBeacons = this.readUInt8();
588
+ const potentialParentBeacons = this.readUInt8();
589
+ const otherNetworkBeacons = this.readUInt8();
590
+
591
+ return {
592
+ totalBeaconsReceived,
593
+ onNetworkBeacons,
594
+ potentialParentBeacons,
595
+ otherNetworkBeacons,
596
+ };
597
+ }
598
+
599
+ private readPotentialParentsTLV(length: number): PotentialParentsTLV {
600
+ logger.debug(`readPotentialParentsTLV with length=${length}`, NS);
601
+ if (length < 4) {
602
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected at least 4.`);
603
+ }
604
+
605
+ const currentParentNwkAddress = this.readUInt16();
606
+ const currentParentLQA = this.readUInt8();
607
+ // [0x00 - 0x05]
608
+ const entryCount = this.readUInt8();
609
+
610
+ if (length !== 4 + entryCount * 3) {
611
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected ${4 + entryCount * 3}.`);
612
+ }
613
+
614
+ const potentialParents: PotentialParentsTLV["potentialParents"] = [];
615
+
616
+ for (let i = 0; i < entryCount; i++) {
617
+ const nwkAddress = this.readUInt16();
618
+ const lqa = this.readUInt8();
619
+
620
+ potentialParents.push({
621
+ nwkAddress,
622
+ lqa,
623
+ });
624
+ }
625
+
626
+ return {
627
+ currentParentNwkAddress,
628
+ currentParentLQA,
629
+ entryCount,
630
+ potentialParents,
631
+ };
632
+ }
633
+
634
+ private readDeviceAuthenticationLevelTLV(length: number): DeviceAuthenticationLevelTLV {
635
+ logger.debug(`readDeviceAuthenticationLevelTLV with length=${length}`, NS);
636
+ if (length !== 10) {
637
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected 10.`);
638
+ }
639
+
640
+ const remoteNodeIeee = this.readIeeeAddr();
641
+ const initialJoinMethod = this.readUInt8();
642
+ const activeLinkKeyType = this.readUInt8();
643
+
644
+ return {
645
+ remoteNodeIeee,
646
+ initialJoinMethod,
647
+ activeLinkKeyType,
648
+ };
649
+ }
650
+
651
+ private readProcessingStatusTLV(length: number): ProcessingStatusTLV {
652
+ logger.debug(`readProcessingStatusTLV with length=${length}`, NS);
653
+ const count = this.readUInt8();
654
+
655
+ if (length !== 1 + count * 2) {
656
+ throw new Error(`Malformed TLV. Invalid length '${length}', expected ${1 + count * 2}.`);
657
+ }
658
+
659
+ const tlvs: ProcessingStatusTLV["tlvs"] = [];
660
+
661
+ for (let i = 0; i < count; i++) {
662
+ const tagId = this.readUInt8();
663
+ const processingStatus = this.readUInt8();
664
+
665
+ tlvs.push({
666
+ tagId,
667
+ processingStatus,
668
+ });
669
+ }
670
+
671
+ return {
672
+ count,
673
+ tlvs,
674
+ };
675
+ }
676
+
677
+ /**
678
+ * ANNEX I ZIGBEE TLV DEFINITIONS AND FORMAT
679
+ *
680
+ * Unknown tags => TLV ignored
681
+ * Duplicate tags => reject message except for MANUFACTURER_SPECIFIC_GLOBAL_TLV
682
+ * Malformed TLVs => reject message
683
+ *
684
+ * @param localTLVReaders Mapping of tagID to local TLV reader function
685
+ * @param encapsulated Default false. If true, this is reading inside an encapsuled TLV (excludes further encapsulation)
686
+ * @returns
687
+ */
688
+ public readTLVs(localTLVReaders?: Map<number, LocalTLVReader>, encapsulated = false): Tlv[] {
689
+ const tlvs: Tlv[] = [];
690
+
691
+ while (this.isMore()) {
692
+ const tagId = this.readUInt8();
693
+
694
+ // validation: cannot have duplicate tagId, except MANUFACTURER_SPECIFIC_GLOBAL_TLV
695
+ if (tagId !== GlobalTLV.MANUFACTURER_SPECIFIC && tlvs.findIndex((tlv) => tlv.tagId === tagId) !== -1) {
696
+ throw new Error(`Duplicate tag. Cannot have more than one of tagId=${tagId}.`);
697
+ }
698
+
699
+ // validation: encapsulation TLV cannot contain another encapsulation TLV, outer considered malformed, reject message
700
+ if (encapsulated && (tagId === GlobalTLV.BEACON_APPENDIX_ENCAPSULATION || tagId === GlobalTLV.JOINER_ENCAPSULATION)) {
701
+ throw new Error(`Invalid nested encapsulation for tagId=${tagId}.`);
702
+ }
703
+
704
+ const length = this.readUInt8() + 1; // add offset (spec quirk...)
705
+
706
+ // validation: invalid if not at least ${length} bytes to read
707
+ if (!this.isMoreBy(length)) {
708
+ throw new Error(`Malformed TLV. Invalid data length for tagId=${tagId}, expected ${length}.`);
709
+ }
710
+
711
+ const nextTLVStart = this.getPosition() + length;
712
+ // undefined == unknown tag
713
+ let tlv: Tlv["tlv"] | undefined;
714
+
715
+ if (tagId < GlobalTLV.MANUFACTURER_SPECIFIC) {
716
+ if (localTLVReaders) {
717
+ const localTLVReader = localTLVReaders.get(tagId);
718
+
719
+ if (localTLVReader) {
720
+ tlv = localTLVReader.call(this, length);
721
+ /* v8 ignore start */
722
+ } else {
723
+ logger.debug(`Local TLV found tagId=${tagId} but no reader given for it. Ignoring it.`, NS);
724
+ }
725
+ /* v8 ignore stop */
726
+ /* v8 ignore start */
727
+ } else {
728
+ logger.debug(`Local TLV found tagId=${tagId} but no reader available. Ignoring it.`, NS);
729
+ }
730
+ /* v8 ignore stop */
731
+ } else {
732
+ tlv = this.readGlobalTLV(tagId, length);
733
+ }
734
+
735
+ // validation: unknown tag shall be ignored
736
+ if (tlv) {
737
+ tlvs.push({
738
+ tagId,
739
+ length,
740
+ tlv,
741
+ });
742
+ } else {
743
+ logger.debug(`Unknown TLV tagId=${tagId}. Ignoring it.`, NS);
744
+ }
745
+
746
+ // ensure we're at the right position as dictated by the tlv length field, and not the tlv reader (should be the same if proper)
747
+ this.setPosition(nextTLVStart);
748
+ }
749
+
750
+ return tlvs;
751
+ }
752
+
753
+ //-- REQUESTS
754
+
755
+ public static buildRequest<K extends keyof RequestMap>(hasZdoMessageOverhead: boolean, clusterId: K, ...args: RequestMap[K]): Buffer {
756
+ const buffalo = new BuffaloZdo(Buffer.alloc(MAX_BUFFER_SIZE), hasZdoMessageOverhead ? ZDO_MESSAGE_OVERHEAD : 0);
757
+
758
+ switch (clusterId) {
759
+ case ZdoClusterId.NETWORK_ADDRESS_REQUEST: {
760
+ return buffalo.buildNetworkAddressRequest(...(args as RequestMap[ZdoClusterId.NETWORK_ADDRESS_REQUEST]));
761
+ }
762
+
763
+ case ZdoClusterId.IEEE_ADDRESS_REQUEST: {
764
+ return buffalo.buildIeeeAddressRequest(...(args as RequestMap[ZdoClusterId.IEEE_ADDRESS_REQUEST]));
765
+ }
766
+
767
+ case ZdoClusterId.NODE_DESCRIPTOR_REQUEST: {
768
+ return buffalo.buildNodeDescriptorRequest(...(args as RequestMap[ZdoClusterId.NODE_DESCRIPTOR_REQUEST]));
769
+ }
770
+
771
+ case ZdoClusterId.POWER_DESCRIPTOR_REQUEST: {
772
+ return buffalo.buildPowerDescriptorRequest(...(args as RequestMap[ZdoClusterId.POWER_DESCRIPTOR_REQUEST]));
773
+ }
774
+
775
+ case ZdoClusterId.SIMPLE_DESCRIPTOR_REQUEST: {
776
+ return buffalo.buildSimpleDescriptorRequest(...(args as RequestMap[ZdoClusterId.SIMPLE_DESCRIPTOR_REQUEST]));
777
+ }
778
+
779
+ case ZdoClusterId.ACTIVE_ENDPOINTS_REQUEST: {
780
+ return buffalo.buildActiveEndpointsRequest(...(args as RequestMap[ZdoClusterId.ACTIVE_ENDPOINTS_REQUEST]));
781
+ }
782
+
783
+ case ZdoClusterId.MATCH_DESCRIPTORS_REQUEST: {
784
+ return buffalo.buildMatchDescriptorRequest(...(args as RequestMap[ZdoClusterId.MATCH_DESCRIPTORS_REQUEST]));
785
+ }
786
+
787
+ case ZdoClusterId.SYSTEM_SERVER_DISCOVERY_REQUEST: {
788
+ return buffalo.buildSystemServiceDiscoveryRequest(...(args as RequestMap[ZdoClusterId.SYSTEM_SERVER_DISCOVERY_REQUEST]));
789
+ }
790
+
791
+ case ZdoClusterId.PARENT_ANNOUNCE: {
792
+ return buffalo.buildParentAnnounce(...(args as RequestMap[ZdoClusterId.PARENT_ANNOUNCE]));
793
+ }
794
+
795
+ case ZdoClusterId.BIND_REQUEST: {
796
+ return buffalo.buildBindRequest(...(args as RequestMap[ZdoClusterId.BIND_REQUEST]));
797
+ }
798
+
799
+ case ZdoClusterId.UNBIND_REQUEST: {
800
+ return buffalo.buildUnbindRequest(...(args as RequestMap[ZdoClusterId.UNBIND_REQUEST]));
801
+ }
802
+
803
+ case ZdoClusterId.CLEAR_ALL_BINDINGS_REQUEST: {
804
+ return buffalo.buildClearAllBindingsRequest(...(args as RequestMap[ZdoClusterId.CLEAR_ALL_BINDINGS_REQUEST]));
805
+ }
806
+
807
+ case ZdoClusterId.LQI_TABLE_REQUEST: {
808
+ return buffalo.buildLqiTableRequest(...(args as RequestMap[ZdoClusterId.LQI_TABLE_REQUEST]));
809
+ }
810
+
811
+ case ZdoClusterId.ROUTING_TABLE_REQUEST: {
812
+ return buffalo.buildRoutingTableRequest(...(args as RequestMap[ZdoClusterId.ROUTING_TABLE_REQUEST]));
813
+ }
814
+
815
+ case ZdoClusterId.BINDING_TABLE_REQUEST: {
816
+ return buffalo.buildBindingTableRequest(...(args as RequestMap[ZdoClusterId.BINDING_TABLE_REQUEST]));
817
+ }
818
+
819
+ case ZdoClusterId.LEAVE_REQUEST: {
820
+ return buffalo.buildLeaveRequest(...(args as RequestMap[ZdoClusterId.LEAVE_REQUEST]));
821
+ }
822
+
823
+ case ZdoClusterId.PERMIT_JOINING_REQUEST: {
824
+ return buffalo.buildPermitJoining(...(args as RequestMap[ZdoClusterId.PERMIT_JOINING_REQUEST]));
825
+ }
826
+
827
+ case ZdoClusterId.NWK_UPDATE_REQUEST: {
828
+ return buffalo.buildNwkUpdateRequest(...(args as RequestMap[ZdoClusterId.NWK_UPDATE_REQUEST]));
829
+ }
830
+
831
+ case ZdoClusterId.NWK_ENHANCED_UPDATE_REQUEST: {
832
+ return buffalo.buildNwkEnhancedUpdateRequest(...(args as RequestMap[ZdoClusterId.NWK_ENHANCED_UPDATE_REQUEST]));
833
+ }
834
+
835
+ case ZdoClusterId.NWK_IEEE_JOINING_LIST_REQUEST: {
836
+ return buffalo.buildNwkIEEEJoiningListRequest(...(args as RequestMap[ZdoClusterId.NWK_IEEE_JOINING_LIST_REQUEST]));
837
+ }
838
+
839
+ case ZdoClusterId.NWK_BEACON_SURVEY_REQUEST: {
840
+ return buffalo.buildNwkBeaconSurveyRequest(...(args as RequestMap[ZdoClusterId.NWK_BEACON_SURVEY_REQUEST]));
841
+ }
842
+
843
+ case ZdoClusterId.START_KEY_NEGOTIATION_REQUEST: {
844
+ return buffalo.buildStartKeyNegotiationRequest(...(args as RequestMap[ZdoClusterId.START_KEY_NEGOTIATION_REQUEST]));
845
+ }
846
+
847
+ case ZdoClusterId.RETRIEVE_AUTHENTICATION_TOKEN_REQUEST: {
848
+ return buffalo.buildRetrieveAuthenticationTokenRequest(...(args as RequestMap[ZdoClusterId.RETRIEVE_AUTHENTICATION_TOKEN_REQUEST]));
849
+ }
850
+
851
+ case ZdoClusterId.GET_AUTHENTICATION_LEVEL_REQUEST: {
852
+ return buffalo.buildGetAuthenticationLevelRequest(...(args as RequestMap[ZdoClusterId.GET_AUTHENTICATION_LEVEL_REQUEST]));
853
+ }
854
+
855
+ case ZdoClusterId.SET_CONFIGURATION_REQUEST: {
856
+ return buffalo.buildSetConfigurationRequest(...(args as RequestMap[ZdoClusterId.SET_CONFIGURATION_REQUEST]));
857
+ }
858
+
859
+ case ZdoClusterId.GET_CONFIGURATION_REQUEST: {
860
+ return buffalo.buildGetConfigurationRequest(...(args as RequestMap[ZdoClusterId.GET_CONFIGURATION_REQUEST]));
861
+ }
862
+
863
+ case ZdoClusterId.START_KEY_UPDATE_REQUEST: {
864
+ return buffalo.buildStartKeyUpdateRequest(...(args as RequestMap[ZdoClusterId.START_KEY_UPDATE_REQUEST]));
865
+ }
866
+
867
+ case ZdoClusterId.DECOMMISSION_REQUEST: {
868
+ return buffalo.buildDecommissionRequest(...(args as RequestMap[ZdoClusterId.DECOMMISSION_REQUEST]));
869
+ }
870
+
871
+ case ZdoClusterId.CHALLENGE_REQUEST: {
872
+ return buffalo.buildChallengeRequest(...(args as RequestMap[ZdoClusterId.CHALLENGE_REQUEST]));
873
+ }
874
+
875
+ default: {
876
+ throw new Error(`Unsupported request building for cluster ID '${clusterId}'.`);
877
+ }
878
+ }
879
+ }
880
+
881
+ /**
882
+ * @see ClusterId.NETWORK_ADDRESS_REQUEST
883
+ * @param target IEEE address for the request
884
+ * @param reportKids True to request that the target list their children in the response. [request type = 0x01]
885
+ * @param childStartIndex The index of the first child to list in the response. Ignored if reportKids is false.
886
+ */
887
+ private buildNetworkAddressRequest(target: Eui64, reportKids: boolean, childStartIndex: number): Buffer {
888
+ this.writeIeeeAddr(target);
889
+ this.writeUInt8(reportKids ? 1 : 0);
890
+ this.writeUInt8(childStartIndex);
891
+
892
+ return this.getWritten();
893
+ }
894
+
895
+ /**
896
+ * @see ClusterId.IEEE_ADDRESS_REQUEST
897
+ * Can be sent to target, or to another node that will send to target.
898
+ * @param target NWK address for the request
899
+ * @param reportKids True to request that the target list their children in the response. [request type = 0x01]
900
+ * @param childStartIndex The index of the first child to list in the response. Ignored if reportKids is false.
901
+ */
902
+ private buildIeeeAddressRequest(target: NodeId, reportKids: boolean, childStartIndex: number): Buffer {
903
+ this.writeUInt16(target);
904
+ this.writeUInt8(reportKids ? 1 : 0);
905
+ this.writeUInt8(childStartIndex);
906
+
907
+ return this.getWritten();
908
+ }
909
+
910
+ /**
911
+ * @see ClusterId.NODE_DESCRIPTOR_REQUEST
912
+ * @param target NWK address for the request
913
+ */
914
+ private buildNodeDescriptorRequest(target: NodeId, fragmentationParameters?: FragmentationParametersGlobalTLV): Buffer {
915
+ this.writeUInt16(target);
916
+
917
+ if (fragmentationParameters) {
918
+ let length = 2;
919
+
920
+ if (fragmentationParameters.fragmentationOptions) {
921
+ length += 1;
922
+ }
923
+
924
+ if (fragmentationParameters.maxIncomingTransferUnit) {
925
+ length += 2;
926
+ }
927
+
928
+ this.writeGlobalTLV({tagId: GlobalTLV.FRAGMENTATION_PARAMETERS, length, tlv: fragmentationParameters});
929
+ }
930
+
931
+ return this.getWritten();
932
+ }
933
+
934
+ /**
935
+ * @see ClusterId.POWER_DESCRIPTOR_REQUEST
936
+ * @param target NWK address for the request
937
+ */
938
+ private buildPowerDescriptorRequest(target: NodeId): Buffer {
939
+ this.writeUInt16(target);
940
+
941
+ return this.getWritten();
942
+ }
943
+
944
+ /**
945
+ * @see ClusterId.SIMPLE_DESCRIPTOR_REQUEST
946
+ * @param target NWK address for the request
947
+ * @param targetEndpoint The endpoint on the destination
948
+ */
949
+ private buildSimpleDescriptorRequest(target: NodeId, targetEndpoint: number): Buffer {
950
+ this.writeUInt16(target);
951
+ this.writeUInt8(targetEndpoint);
952
+
953
+ return this.getWritten();
954
+ }
955
+
956
+ /**
957
+ * @see ClusterId.ACTIVE_ENDPOINTS_REQUEST
958
+ * @param target NWK address for the request
959
+ */
960
+ private buildActiveEndpointsRequest(target: NodeId): Buffer {
961
+ this.writeUInt16(target);
962
+
963
+ return this.getWritten();
964
+ }
965
+
966
+ /**
967
+ * @see ClusterId.MATCH_DESCRIPTORS_REQUEST
968
+ * @param target NWK address for the request
969
+ * @param profileId Profile ID to be matched at the destination
970
+ * @param inClusterList List of Input ClusterIDs to be used for matching
971
+ * @param outClusterList List of Output ClusterIDs to be used for matching
972
+ */
973
+ private buildMatchDescriptorRequest(target: NodeId, profileId: ProfileId, inClusterList: ClusterId[], outClusterList: ClusterId[]): Buffer {
974
+ this.writeUInt16(target);
975
+ this.writeUInt16(profileId);
976
+ this.writeUInt8(inClusterList.length);
977
+ this.writeListUInt16(inClusterList);
978
+ this.writeUInt8(outClusterList.length);
979
+ this.writeListUInt16(outClusterList);
980
+
981
+ return this.getWritten();
982
+ }
983
+
984
+ /**
985
+ * @see ClusterId.SYSTEM_SERVER_DISCOVERY_REQUEST
986
+ * @param serverMask See Table 2-34 for bit assignments.
987
+ */
988
+ private buildSystemServiceDiscoveryRequest(serverMask: ServerMask): Buffer {
989
+ this.writeUInt16(Utils.createServerMask(serverMask));
990
+
991
+ return this.getWritten();
992
+ }
993
+
994
+ /**
995
+ * @see ClusterId.PARENT_ANNOUNCE
996
+ * @param children The IEEE addresses of the children bound to the parent.
997
+ */
998
+ private buildParentAnnounce(children: Eui64[]): Buffer {
999
+ this.writeUInt8(children.length);
1000
+
1001
+ for (const child of children) {
1002
+ this.writeIeeeAddr(child);
1003
+ }
1004
+
1005
+ return this.getWritten();
1006
+ }
1007
+
1008
+ /**
1009
+ * @see ClusterId.BIND_REQUEST
1010
+ *
1011
+ * @param source The IEEE address for the source.
1012
+ * @param sourceEndpoint The source endpoint for the binding entry.
1013
+ * @param clusterId The identifier of the cluster on the source device that is bound to the destination.
1014
+ * @param type The addressing mode for the destination address used in this command, either ::UNICAST_BINDING, ::MULTICAST_BINDING.
1015
+ * @param destination The destination address for the binding entry. IEEE for ::UNICAST_BINDING.
1016
+ * @param groupAddress The destination address for the binding entry. Group ID for ::MULTICAST_BINDING.
1017
+ * @param destinationEndpoint The destination endpoint for the binding entry. Only if ::UNICAST_BINDING.
1018
+ */
1019
+ private buildBindRequest(
1020
+ source: Eui64,
1021
+ sourceEndpoint: number,
1022
+ clusterId: ClusterId,
1023
+ type: number,
1024
+ destination: Eui64,
1025
+ groupAddress: number,
1026
+ destinationEndpoint: number,
1027
+ ): Buffer {
1028
+ this.writeIeeeAddr(source);
1029
+ this.writeUInt8(sourceEndpoint);
1030
+ this.writeUInt16(clusterId);
1031
+ this.writeUInt8(type);
1032
+
1033
+ switch (type) {
1034
+ case UNICAST_BINDING: {
1035
+ this.writeIeeeAddr(destination);
1036
+ this.writeUInt8(destinationEndpoint);
1037
+ break;
1038
+ }
1039
+ case MULTICAST_BINDING: {
1040
+ this.writeUInt16(groupAddress);
1041
+ break;
1042
+ }
1043
+ default:
1044
+ throw new ZdoStatusError(Status.NOT_SUPPORTED);
1045
+ }
1046
+
1047
+ return this.getWritten();
1048
+ }
1049
+
1050
+ /**
1051
+ * @see ClusterId.UNBIND_REQUEST
1052
+ *
1053
+ * @param source The IEEE address for the source.
1054
+ * @param sourceEndpoint The source endpoint for the binding entry.
1055
+ * @param clusterId The identifier of the cluster on the source device that is bound to the destination.
1056
+ * @param type The addressing mode for the destination address used in this command, either ::UNICAST_BINDING, ::MULTICAST_BINDING.
1057
+ * @param destination The destination address for the binding entry. IEEE for ::UNICAST_BINDING.
1058
+ * @param groupAddress The destination address for the binding entry. Group ID for ::MULTICAST_BINDING.
1059
+ * @param destinationEndpoint The destination endpoint for the binding entry. Only if ::UNICAST_BINDING.
1060
+ */
1061
+ private buildUnbindRequest(
1062
+ source: Eui64,
1063
+ sourceEndpoint: number,
1064
+ clusterId: ClusterId,
1065
+ type: number,
1066
+ destination: Eui64,
1067
+ groupAddress: number,
1068
+ destinationEndpoint: number,
1069
+ ): Buffer {
1070
+ this.writeIeeeAddr(source);
1071
+ this.writeUInt8(sourceEndpoint);
1072
+ this.writeUInt16(clusterId);
1073
+ this.writeUInt8(type);
1074
+
1075
+ switch (type) {
1076
+ case UNICAST_BINDING: {
1077
+ this.writeIeeeAddr(destination);
1078
+ this.writeUInt8(destinationEndpoint);
1079
+ break;
1080
+ }
1081
+ case MULTICAST_BINDING: {
1082
+ this.writeUInt16(groupAddress);
1083
+ break;
1084
+ }
1085
+ default:
1086
+ throw new ZdoStatusError(Status.NOT_SUPPORTED);
1087
+ }
1088
+
1089
+ return this.getWritten();
1090
+ }
1091
+
1092
+ /**
1093
+ * @see ClusterId.CLEAR_ALL_BINDINGS_REQUEST
1094
+ */
1095
+ private buildClearAllBindingsRequest(tlv: ClearAllBindingsReqEUI64TLV): Buffer {
1096
+ // ClearAllBindingsReqEUI64TLV: Local: ID: 0x00
1097
+ this.writeUInt8(0x00);
1098
+ this.writeUInt8(tlv.eui64List.length * EUI64_SIZE + 1 - 1);
1099
+ this.writeUInt8(tlv.eui64List.length);
1100
+
1101
+ for (const entry of tlv.eui64List) {
1102
+ this.writeIeeeAddr(entry);
1103
+ }
1104
+
1105
+ return this.getWritten();
1106
+ }
1107
+
1108
+ /**
1109
+ * @see ClusterId.LQI_TABLE_REQUEST
1110
+ * @param startIndex Starting Index for the requested elements of the Neighbor Table.
1111
+ */
1112
+ private buildLqiTableRequest(startIndex: number): Buffer {
1113
+ this.writeUInt8(startIndex);
1114
+
1115
+ return this.getWritten();
1116
+ }
1117
+
1118
+ /**
1119
+ * @see ClusterId.ROUTING_TABLE_REQUEST
1120
+ * @param startIndex Starting Index for the requested elements of the Neighbor Table.
1121
+ */
1122
+ private buildRoutingTableRequest(startIndex: number): Buffer {
1123
+ this.writeUInt8(startIndex);
1124
+
1125
+ return this.getWritten();
1126
+ }
1127
+
1128
+ /**
1129
+ * @see ClusterId.BINDING_TABLE_REQUEST
1130
+ * @param startIndex Starting Index for the requested elements of the Neighbor Table.
1131
+ */
1132
+ private buildBindingTableRequest(startIndex: number): Buffer {
1133
+ this.writeUInt8(startIndex);
1134
+
1135
+ return this.getWritten();
1136
+ }
1137
+
1138
+ /**
1139
+ * @see ClusterId.LEAVE_REQUEST
1140
+ * @param deviceAddress All zeros if the target is to remove itself from the network or
1141
+ * the EUI64 of a child of the target device to remove that child.
1142
+ * @param leaveRequestFlags A bitmask of leave options. Include ::AND_REJOIN if the target is to rejoin the network immediately after leaving.
1143
+ */
1144
+ private buildLeaveRequest(deviceAddress: Eui64, leaveRequestFlags: LeaveRequestFlags): Buffer {
1145
+ this.writeIeeeAddr(deviceAddress);
1146
+ this.writeUInt8(leaveRequestFlags);
1147
+
1148
+ return this.getWritten();
1149
+ }
1150
+
1151
+ /**
1152
+ * @see ClusterId.PERMIT_JOINING_REQUEST
1153
+ * @param duration A value of 0x00 disables joining. A value of 0xFF enables joining. Any other value enables joining for that number of seconds.
1154
+ * @param authentication Controls Trust Center authentication behavior.
1155
+ * This field SHALL always have a value of 1, indicating a request to change the Trust Center policy.
1156
+ * If a frame is received with a value of 0, it shall be treated as having a value of 1.
1157
+ */
1158
+ private buildPermitJoining(duration: number, authentication: number, tlvs: Tlv[]): Buffer {
1159
+ this.writeUInt8(duration);
1160
+ this.writeUInt8(authentication);
1161
+ // BeaconAppendixEncapsulationGlobalTLV
1162
+ // - SupportedKeyNegotiationMethodsGlobalTLV
1163
+ // - FragmentationParametersGlobalTLV
1164
+ this.writeGlobalTLVs(tlvs);
1165
+
1166
+ return this.getWritten();
1167
+ }
1168
+
1169
+ /**
1170
+ * @see ClusterId.NWK_UPDATE_REQUEST
1171
+ * @param channels See Table 3-7 for details on the 32-bit field structure..
1172
+ * @param duration A value used to calculate the length of time to spend scanning each channel.
1173
+ * The time spent scanning each channel is (aBaseSuperframeDuration * (2n + 1)) symbols, where n is the value of the duration parameter.
1174
+ * If has a value of 0xfe this is a request for channel change.
1175
+ * If has a value of 0xff this is a request to change the apsChannelMaskList and nwkManagerAddr attributes.
1176
+ * @param count This field represents the number of energy scans to be conducted and reported.
1177
+ * This field SHALL be present only if the duration is within the range of 0x00 to 0x05.
1178
+ * @param nwkUpdateId The value of the nwkUpdateId contained in this request.
1179
+ * This value is set by the Network Channel Manager prior to sending the message.
1180
+ * This field SHALL only be present if the duration is 0xfe or 0xff.
1181
+ * If the ScanDuration is 0xff, then the value in the nwkUpdateID SHALL be ignored.
1182
+ * @param nwkManagerAddr This field SHALL be present only if the duration is set to 0xff, and, where present,
1183
+ * indicates the NWK address for the device with the Network Manager bit set in its Node Descriptor.
1184
+ */
1185
+ private buildNwkUpdateRequest(
1186
+ channels: number[],
1187
+ duration: number,
1188
+ count: number | undefined,
1189
+ nwkUpdateId: number | undefined,
1190
+ nwkManagerAddr: number | undefined,
1191
+ ): Buffer {
1192
+ this.writeUInt32(ZSpecUtils.channelsToUInt32Mask(channels));
1193
+ this.writeUInt8(duration);
1194
+
1195
+ if (count !== undefined && duration >= 0x00 && duration <= 0x05) {
1196
+ this.writeUInt8(count);
1197
+ }
1198
+
1199
+ // TODO: What does "This value is set by the Network Channel Manager prior to sending the message." mean exactly??
1200
+ // (isn't used/mentioned in EmberZNet, confirmed working if not set at all for channel change)
1201
+ // for now, allow to bypass with undefined, otherwise should throw if undefined and duration passes below conditions (see NwkEnhancedUpdateRequest)
1202
+ if (nwkUpdateId !== undefined && (duration === 0xfe || duration === 0xff)) {
1203
+ this.writeUInt8(nwkUpdateId);
1204
+ }
1205
+
1206
+ if (nwkManagerAddr !== undefined && duration === 0xff) {
1207
+ this.writeUInt16(nwkManagerAddr);
1208
+ }
1209
+
1210
+ return this.getWritten();
1211
+ }
1212
+
1213
+ // /**
1214
+ // * Shortcut for @see BuffaloZdo.buildNwkUpdateRequest
1215
+ // */
1216
+ // private buildScanChannelsRequest(scanChannels: number[], duration: number, count: number): Buffer {
1217
+ // return this.buildNwkUpdateRequest(scanChannels, duration, count, undefined, undefined);
1218
+ // }
1219
+
1220
+ // /**
1221
+ // * Shortcut for @see BuffaloZdo.buildNwkUpdateRequest
1222
+ // */
1223
+ // private buildChannelChangeRequest(channel: number, nwkUpdateId: number | undefined): Buffer {
1224
+ // return this.buildNwkUpdateRequest([channel], 0xfe, undefined, nwkUpdateId, undefined);
1225
+ // }
1226
+
1227
+ // /**
1228
+ // * Shortcut for @see BuffaloZdo.buildNwkUpdateRequest
1229
+ // */
1230
+ // private buildSetActiveChannelsAndNwkManagerIdRequest(channels: number[], nwkUpdateId: number | undefined, nwkManagerAddr: NodeId): Buffer {
1231
+ // return this.buildNwkUpdateRequest(channels, 0xff, undefined, nwkUpdateId, nwkManagerAddr);
1232
+ // }
1233
+
1234
+ /**
1235
+ * @see ClusterId.NWK_ENHANCED_UPDATE_REQUEST
1236
+ * @param channelPages The set of channels (32-bit bitmap) for each channel page.
1237
+ * The five most significant bits (b27,..., b31) represent the binary encoded Channel Page.
1238
+ * The 27 least significant bits (b0, b1,... b26) indicate which channels are to be scanned
1239
+ * (1 = scan, 0 = do not scan) for each of the 27 valid channels
1240
+ * If duration is in the range 0x00 to 0x05, SHALL be restricted to a single page.
1241
+ * @param duration A value used to calculate the length of time to spend scanning each channel.
1242
+ * The time spent scanning each channel is (aBaseSuperframeDuration * (2n + 1)) symbols, where n is the value of the duration parameter.
1243
+ * If has a value of 0xfe this is a request for channel change.
1244
+ * If has a value of 0xff this is a request to change the apsChannelMaskList and nwkManagerAddr attributes.
1245
+ * @param count This field represents the number of energy scans to be conducted and reported.
1246
+ * This field SHALL be present only if the duration is within the range of 0x00 to 0x05.
1247
+ * @param nwkUpdateId The value of the nwkUpdateId contained in this request.
1248
+ * This value is set by the Network Channel Manager prior to sending the message.
1249
+ * This field SHALL only be present if the duration is 0xfe or 0xff.
1250
+ * If the ScanDuration is 0xff, then the value in the nwkUpdateID SHALL be ignored.
1251
+ * @param nwkManagerAddr This field SHALL be present only if the duration is set to 0xff, and, where present,
1252
+ * indicates the NWK address for the device with the Network Manager bit set in its Node Descriptor.
1253
+ * @param configurationBitmask Defined in defined in section 2.4.3.3.12.
1254
+ * The configurationBitmask must be added to the end of the list of parameters.
1255
+ * This octet may or may not be present.
1256
+ * If not present then assumption should be that it is enhanced active scan.
1257
+ * Bit 0: This bit determines whether to do an Active Scan or Enhanced Active Scan.
1258
+ * When the bit is set to 1 it indicates an Enhanced Active Scan.
1259
+ * And in case of Enhanced Active scan EBR shall be sent with EPID filter instead of PJOIN filter.
1260
+ * Bit 1-7: Reserved
1261
+ */
1262
+ private buildNwkEnhancedUpdateRequest(
1263
+ channelPages: number[],
1264
+ duration: number,
1265
+ count: number | undefined,
1266
+ nwkUpdateId: number | undefined,
1267
+ nwkManagerAddr: NodeId | undefined,
1268
+ configurationBitmask: number | undefined,
1269
+ ): Buffer {
1270
+ this.writeUInt8(channelPages.length);
1271
+
1272
+ for (const channelPage of channelPages) {
1273
+ this.writeUInt32(channelPage);
1274
+ }
1275
+
1276
+ this.writeUInt8(duration);
1277
+
1278
+ if (count !== undefined && duration >= 0x00 && duration <= 0x05) {
1279
+ this.writeUInt8(count);
1280
+ }
1281
+
1282
+ if (nwkUpdateId !== undefined && (duration === 0xfe || duration === 0xff)) {
1283
+ this.writeUInt8(nwkUpdateId);
1284
+ }
1285
+
1286
+ if (nwkManagerAddr !== undefined && duration === 0xff) {
1287
+ this.writeUInt16(nwkManagerAddr);
1288
+ }
1289
+
1290
+ if (configurationBitmask !== undefined) {
1291
+ this.writeUInt8(configurationBitmask);
1292
+ }
1293
+
1294
+ return this.getWritten();
1295
+ }
1296
+
1297
+ // /**
1298
+ // * Shortcut for @see BuffaloZdo.buildNwkEnhancedUpdateRequest
1299
+ // */
1300
+ // private buildEnhancedScanChannelsRequest(channelPages: number[], duration: number, count: number, configurationBitmask: number | undefined): Buffer {
1301
+ // return this.buildNwkEnhancedUpdateRequest(channelPages, duration, count, undefined, undefined, configurationBitmask);
1302
+ // }
1303
+
1304
+ // /**
1305
+ // * Shortcut for @see BuffaloZdo.buildNwkEnhancedUpdateRequest
1306
+ // */
1307
+ // private buildEnhancedChannelChangeRequest(channelPage: number, nwkUpdateId: number | undefined, configurationBitmask: number | undefined): Buffer {
1308
+ // return this.buildNwkEnhancedUpdateRequest([channelPage], 0xfe, undefined, nwkUpdateId, undefined, configurationBitmask);
1309
+ // }
1310
+
1311
+ // /**
1312
+ // * Shortcut for @see BuffaloZdo.buildNwkEnhancedUpdateRequest
1313
+ // */
1314
+ // private buildEnhancedSetActiveChannelsAndNwkManagerIdRequest(
1315
+ // channelPages: number[],
1316
+ // nwkUpdateId: number | undefined,
1317
+ // nwkManagerAddr: NodeId,
1318
+ // configurationBitmask: number | undefined,
1319
+ // ): Buffer {
1320
+ // return this.buildNwkEnhancedUpdateRequest(channelPages, 0xff, undefined, nwkUpdateId, nwkManagerAddr, configurationBitmask);
1321
+ // }
1322
+
1323
+ /**
1324
+ * @see ClusterId.NWK_IEEE_JOINING_LIST_REQUEST
1325
+ * @param startIndex The starting index into the receiving device’s nwkIeeeJoiningList that SHALL be sent back.
1326
+ */
1327
+ private buildNwkIEEEJoiningListRequest(startIndex: number): Buffer {
1328
+ this.writeUInt8(startIndex);
1329
+
1330
+ return this.getWritten();
1331
+ }
1332
+
1333
+ /**
1334
+ * @see ClusterId.NWK_BEACON_SURVEY_REQUEST
1335
+ */
1336
+ private buildNwkBeaconSurveyRequest(tlv: BeaconSurveyConfigurationTLV): Buffer {
1337
+ // BeaconSurveyConfigurationTLV: Local: ID: 0x00
1338
+ this.writeUInt8(0x00);
1339
+ this.writeUInt8(2 + tlv.scanChannelList.length * 4 - 1);
1340
+ this.writeUInt8(tlv.scanChannelList.length);
1341
+ this.writeListUInt32(tlv.scanChannelList);
1342
+ this.writeUInt8(tlv.configurationBitmask);
1343
+
1344
+ return this.getWritten();
1345
+ }
1346
+
1347
+ /**
1348
+ * @see ClusterId.START_KEY_NEGOTIATION_REQUEST
1349
+ */
1350
+ private buildStartKeyNegotiationRequest(tlv: Curve25519PublicPointTLV): Buffer {
1351
+ // Curve25519PublicPointTLV: Local: ID: 0x00
1352
+ this.writeUInt8(0x00);
1353
+ this.writeUInt8(EUI64_SIZE + CURVE_PUBLIC_POINT_SIZE - 1);
1354
+ this.writeIeeeAddr(tlv.eui64);
1355
+ this.writeBuffer(tlv.publicPoint, CURVE_PUBLIC_POINT_SIZE);
1356
+
1357
+ return this.getWritten();
1358
+ }
1359
+
1360
+ /**
1361
+ * @see ClusterId.RETRIEVE_AUTHENTICATION_TOKEN_REQUEST
1362
+ */
1363
+ private buildRetrieveAuthenticationTokenRequest(tlv: AuthenticationTokenIdTLV): Buffer {
1364
+ // AuthenticationTokenIdTLV: Local: ID: 0x00
1365
+ this.writeUInt8(0x00);
1366
+ this.writeUInt8(1 - 1);
1367
+ this.writeUInt8(tlv.tlvTypeTagId);
1368
+
1369
+ return this.getWritten();
1370
+ }
1371
+
1372
+ /**
1373
+ * @see ClusterId.GET_AUTHENTICATION_LEVEL_REQUEST
1374
+ */
1375
+ private buildGetAuthenticationLevelRequest(tlv: TargetIEEEAddressTLV): Buffer {
1376
+ // TargetIEEEAddressTLV: Local: ID: 0x00
1377
+ this.writeUInt8(0x00);
1378
+ this.writeUInt8(EUI64_SIZE - 1);
1379
+ this.writeIeeeAddr(tlv.ieee);
1380
+
1381
+ return this.getWritten();
1382
+ }
1383
+
1384
+ /**
1385
+ * @see ClusterId.SET_CONFIGURATION_REQUEST
1386
+ */
1387
+ private buildSetConfigurationRequest(
1388
+ nextPanIdChange: NextPanIdChangeGlobalTLV,
1389
+ nextChannelChange: NextChannelChangeGlobalTLV,
1390
+ configurationParameters: ConfigurationParametersGlobalTLV,
1391
+ ): Buffer {
1392
+ this.writeGlobalTLV({tagId: GlobalTLV.NEXT_PAN_ID_CHANGE, length: PAN_ID_SIZE, tlv: nextPanIdChange});
1393
+ this.writeGlobalTLV({tagId: GlobalTLV.NEXT_CHANNEL_CHANGE, length: 4, tlv: nextChannelChange});
1394
+ this.writeGlobalTLV({tagId: GlobalTLV.CONFIGURATION_PARAMETERS, length: 2, tlv: configurationParameters});
1395
+
1396
+ return this.getWritten();
1397
+ }
1398
+
1399
+ /**
1400
+ * @see ClusterId.GET_CONFIGURATION_REQUEST
1401
+ * @param tlvIds The IDs of each TLV that are being requested.
1402
+ * Maximum number dependent on the underlying maximum size of the message as allowed by fragmentation.
1403
+ */
1404
+ private buildGetConfigurationRequest(tlvIds: number[]): Buffer {
1405
+ this.writeUInt8(tlvIds.length);
1406
+
1407
+ for (const tlvId of tlvIds) {
1408
+ this.writeUInt8(tlvId);
1409
+ }
1410
+
1411
+ return this.getWritten();
1412
+ }
1413
+
1414
+ /**
1415
+ * @see ClusterId.START_KEY_UPDATE_REQUEST
1416
+ */
1417
+ private buildStartKeyUpdateRequest(
1418
+ selectedKeyNegotiationMethod: SelectedKeyNegotiationMethodTLV,
1419
+ fragmentationParameters: FragmentationParametersGlobalTLV,
1420
+ ): Buffer {
1421
+ // SelectedKeyNegotiationMethodTLV: Local: ID: 0x00
1422
+ this.writeUInt8(0x00);
1423
+ this.writeUInt8(EUI64_SIZE + 2 - 1);
1424
+ this.writeUInt8(selectedKeyNegotiationMethod.protocol);
1425
+ this.writeUInt8(selectedKeyNegotiationMethod.presharedSecret);
1426
+ this.writeIeeeAddr(selectedKeyNegotiationMethod.sendingDeviceEui64);
1427
+
1428
+ {
1429
+ let length = 2;
1430
+
1431
+ if (fragmentationParameters.fragmentationOptions) {
1432
+ length += 1;
1433
+ }
1434
+
1435
+ if (fragmentationParameters.maxIncomingTransferUnit) {
1436
+ length += 2;
1437
+ }
1438
+
1439
+ this.writeGlobalTLV({tagId: GlobalTLV.FRAGMENTATION_PARAMETERS, length, tlv: fragmentationParameters});
1440
+ }
1441
+
1442
+ return this.getWritten();
1443
+ }
1444
+
1445
+ /**
1446
+ * @see ClusterId.DECOMMISSION_REQUEST
1447
+ */
1448
+ private buildDecommissionRequest(tlv: DeviceEUI64ListTLV): Buffer {
1449
+ // DeviceEUI64ListTLV: Local: ID: 0x00
1450
+ this.writeUInt8(0x00);
1451
+ this.writeUInt8(tlv.eui64List.length * EUI64_SIZE + 1 - 1);
1452
+ this.writeUInt8(tlv.eui64List.length);
1453
+
1454
+ for (const eui64 of tlv.eui64List) {
1455
+ this.writeIeeeAddr(eui64);
1456
+ }
1457
+
1458
+ return this.getWritten();
1459
+ }
1460
+
1461
+ /**
1462
+ * @see ClusterId.CHALLENGE_REQUEST
1463
+ */
1464
+ private buildChallengeRequest(tlv: APSFrameCounterChallengeTLV): Buffer {
1465
+ // APSFrameCounterChallengeTLV: Local: ID: 0x00
1466
+ this.writeUInt8(0x00);
1467
+ this.writeUInt8(EUI64_SIZE + CHALLENGE_VALUE_SIZE - 1);
1468
+ this.writeIeeeAddr(tlv.senderEui64);
1469
+ this.writeBuffer(tlv.challengeValue, CHALLENGE_VALUE_SIZE);
1470
+
1471
+ return this.getWritten();
1472
+ }
1473
+ //-- RESPONSES
1474
+
1475
+ public static checkStatus<K extends keyof ValidResponseMap>(result: ResponseMap[number]): result is ValidResponseMap[K] {
1476
+ return result[0] === Status.SUCCESS;
1477
+ }
1478
+
1479
+ public static readResponse<K extends number>(
1480
+ hasZdoMessageOverhead: boolean,
1481
+ clusterId: K extends keyof ResponseMap ? keyof ResponseMap : K,
1482
+ buffer: Buffer,
1483
+ ): ResponseMap[K] {
1484
+ const buffalo = new BuffaloZdo(buffer, hasZdoMessageOverhead ? ZDO_MESSAGE_OVERHEAD : 0); // set pos to skip `transaction sequence number`
1485
+
1486
+ switch (clusterId) {
1487
+ case ZdoClusterId.NETWORK_ADDRESS_RESPONSE: {
1488
+ return buffalo.readNetworkAddressResponse() as ResponseMap[K];
1489
+ }
1490
+ case ZdoClusterId.IEEE_ADDRESS_RESPONSE: {
1491
+ return buffalo.readIEEEAddressResponse() as ResponseMap[K];
1492
+ }
1493
+ case ZdoClusterId.NODE_DESCRIPTOR_RESPONSE: {
1494
+ return buffalo.readNodeDescriptorResponse() as ResponseMap[K];
1495
+ }
1496
+ case ZdoClusterId.POWER_DESCRIPTOR_RESPONSE: {
1497
+ return buffalo.readPowerDescriptorResponse() as ResponseMap[K];
1498
+ }
1499
+ case ZdoClusterId.SIMPLE_DESCRIPTOR_RESPONSE: {
1500
+ return buffalo.readSimpleDescriptorResponse() as ResponseMap[K];
1501
+ }
1502
+ case ZdoClusterId.ACTIVE_ENDPOINTS_RESPONSE: {
1503
+ return buffalo.readActiveEndpointsResponse() as ResponseMap[K];
1504
+ }
1505
+ case ZdoClusterId.MATCH_DESCRIPTORS_RESPONSE: {
1506
+ return buffalo.readMatchDescriptorsResponse() as ResponseMap[K];
1507
+ }
1508
+ case ZdoClusterId.END_DEVICE_ANNOUNCE: {
1509
+ return buffalo.readEndDeviceAnnounce() as ResponseMap[K];
1510
+ }
1511
+ case ZdoClusterId.SYSTEM_SERVER_DISCOVERY_RESPONSE: {
1512
+ return buffalo.readSystemServerDiscoveryResponse() as ResponseMap[K];
1513
+ }
1514
+ case ZdoClusterId.PARENT_ANNOUNCE_RESPONSE: {
1515
+ return buffalo.readParentAnnounceResponse() as ResponseMap[K];
1516
+ }
1517
+ case ZdoClusterId.BIND_RESPONSE: {
1518
+ return buffalo.readBindResponse() as ResponseMap[K];
1519
+ }
1520
+ case ZdoClusterId.UNBIND_RESPONSE: {
1521
+ return buffalo.readUnbindResponse() as ResponseMap[K];
1522
+ }
1523
+ case ZdoClusterId.CLEAR_ALL_BINDINGS_RESPONSE: {
1524
+ return buffalo.readClearAllBindingsResponse() as ResponseMap[K];
1525
+ }
1526
+ case ZdoClusterId.LQI_TABLE_RESPONSE: {
1527
+ return buffalo.readLQITableResponse() as ResponseMap[K];
1528
+ }
1529
+ case ZdoClusterId.ROUTING_TABLE_RESPONSE: {
1530
+ return buffalo.readRoutingTableResponse() as ResponseMap[K];
1531
+ }
1532
+ case ZdoClusterId.BINDING_TABLE_RESPONSE: {
1533
+ return buffalo.readBindingTableResponse() as ResponseMap[K];
1534
+ }
1535
+ case ZdoClusterId.LEAVE_RESPONSE: {
1536
+ return buffalo.readLeaveResponse() as ResponseMap[K];
1537
+ }
1538
+ case ZdoClusterId.PERMIT_JOINING_RESPONSE: {
1539
+ return buffalo.readPermitJoiningResponse() as ResponseMap[K];
1540
+ }
1541
+ case ZdoClusterId.NWK_UPDATE_RESPONSE: {
1542
+ return buffalo.readNwkUpdateResponse() as ResponseMap[K];
1543
+ }
1544
+ case ZdoClusterId.NWK_ENHANCED_UPDATE_RESPONSE: {
1545
+ return buffalo.readNwkEnhancedUpdateResponse() as ResponseMap[K];
1546
+ }
1547
+ case ZdoClusterId.NWK_IEEE_JOINING_LIST_RESPONSE: {
1548
+ return buffalo.readNwkIEEEJoiningListResponse() as ResponseMap[K];
1549
+ }
1550
+ case ZdoClusterId.NWK_UNSOLICITED_ENHANCED_UPDATE_RESPONSE: {
1551
+ return buffalo.readNwkUnsolicitedEnhancedUpdateResponse() as ResponseMap[K];
1552
+ }
1553
+ case ZdoClusterId.NWK_BEACON_SURVEY_RESPONSE: {
1554
+ return buffalo.readNwkBeaconSurveyResponse() as ResponseMap[K];
1555
+ }
1556
+ case ZdoClusterId.START_KEY_NEGOTIATION_RESPONSE: {
1557
+ return buffalo.readStartKeyNegotiationResponse() as ResponseMap[K];
1558
+ }
1559
+ case ZdoClusterId.RETRIEVE_AUTHENTICATION_TOKEN_RESPONSE: {
1560
+ return buffalo.readRetrieveAuthenticationTokenResponse() as ResponseMap[K];
1561
+ }
1562
+ case ZdoClusterId.GET_AUTHENTICATION_LEVEL_RESPONSE: {
1563
+ return buffalo.readGetAuthenticationLevelResponse() as ResponseMap[K];
1564
+ }
1565
+ case ZdoClusterId.SET_CONFIGURATION_RESPONSE: {
1566
+ return buffalo.readSetConfigurationResponse() as ResponseMap[K];
1567
+ }
1568
+ case ZdoClusterId.GET_CONFIGURATION_RESPONSE: {
1569
+ return buffalo.readGetConfigurationResponse() as ResponseMap[K];
1570
+ }
1571
+ case ZdoClusterId.START_KEY_UPDATE_RESPONSE: {
1572
+ return buffalo.readStartKeyUpdateResponse() as ResponseMap[K];
1573
+ }
1574
+ case ZdoClusterId.DECOMMISSION_RESPONSE: {
1575
+ return buffalo.readDecommissionResponse() as ResponseMap[K];
1576
+ }
1577
+ case ZdoClusterId.CHALLENGE_RESPONSE: {
1578
+ return buffalo.readChallengeResponse() as ResponseMap[K];
1579
+ }
1580
+ default: {
1581
+ throw new Error(`Unsupported response reading for cluster ID '${clusterId}'.`);
1582
+ }
1583
+ }
1584
+ }
1585
+
1586
+ /**
1587
+ * @see ClusterId.NETWORK_ADDRESS_RESPONSE
1588
+ */
1589
+ public readNetworkAddressResponse(): ResponseMap[ZdoClusterId.NETWORK_ADDRESS_RESPONSE] {
1590
+ // INV_REQUESTTYPE or DEVICE_NOT_FOUND
1591
+ const status: Status = this.readUInt8();
1592
+ let result: NetworkAddressResponse | undefined;
1593
+
1594
+ if (status === Status.SUCCESS) {
1595
+ const eui64 = this.readIeeeAddr();
1596
+ const nwkAddress = this.readUInt16();
1597
+ let assocDevCount = 0;
1598
+ let startIndex = 0;
1599
+ let assocDevList: number[] = [];
1600
+
1601
+ if (this.isMore()) {
1602
+ assocDevCount = this.readUInt8();
1603
+ startIndex = this.readUInt8();
1604
+
1605
+ assocDevList = this.readListUInt16(assocDevCount);
1606
+ }
1607
+
1608
+ result = {
1609
+ eui64,
1610
+ nwkAddress,
1611
+ startIndex,
1612
+ assocDevList,
1613
+ };
1614
+ }
1615
+
1616
+ return [status, result];
1617
+ }
1618
+
1619
+ /**
1620
+ * @see ClusterId.IEEE_ADDRESS_RESPONSE
1621
+ */
1622
+ public readIEEEAddressResponse(): ResponseMap[ZdoClusterId.IEEE_ADDRESS_RESPONSE] {
1623
+ // INV_REQUESTTYPE or DEVICE_NOT_FOUND
1624
+ const status: Status = this.readUInt8();
1625
+ let result: IEEEAddressResponse | undefined;
1626
+
1627
+ if (status === Status.SUCCESS) {
1628
+ const eui64 = this.readIeeeAddr();
1629
+ const nwkAddress = this.readUInt16();
1630
+ let assocDevCount = 0;
1631
+ let startIndex = 0;
1632
+ let assocDevList: number[] = [];
1633
+
1634
+ if (this.isMore()) {
1635
+ assocDevCount = this.readUInt8();
1636
+ startIndex = this.readUInt8();
1637
+ assocDevList = this.readListUInt16(assocDevCount);
1638
+ }
1639
+
1640
+ result = {
1641
+ eui64,
1642
+ nwkAddress,
1643
+ startIndex,
1644
+ assocDevList,
1645
+ };
1646
+ }
1647
+
1648
+ return [status, result];
1649
+ }
1650
+
1651
+ /**
1652
+ * @see ClusterId.NODE_DESCRIPTOR_RESPONSE
1653
+ */
1654
+ public readNodeDescriptorResponse(): ResponseMap[ZdoClusterId.NODE_DESCRIPTOR_RESPONSE] {
1655
+ // DEVICE_NOT_FOUND, INV_REQUESTTYPE, or NO_DESCRIPTOR
1656
+ const status: Status = this.readUInt8();
1657
+ let result: NodeDescriptorResponse | undefined;
1658
+
1659
+ if (status === Status.SUCCESS) {
1660
+ const nwkAddress = this.readUInt16();
1661
+ // in bits: [logical type: 3] [deprecated: 1] [deprecated: 1] [fragmentation supported (R23): 1] [reserved/unused: 2]
1662
+ const nodeDescByte1 = this.readUInt8();
1663
+ // in bits: [aps flags: 3] [frequency band: 5]
1664
+ const nodeDescByte2 = this.readUInt8();
1665
+ const macCapFlags = Utils.getMacCapFlags(this.readUInt8());
1666
+ const manufacturerCode = this.readUInt16();
1667
+ const maxBufSize = this.readUInt8();
1668
+ const maxIncTxSize = this.readUInt16();
1669
+ const serverMask = Utils.getServerMask(this.readUInt16());
1670
+ const maxOutTxSize = this.readUInt16();
1671
+ const deprecated1 = this.readUInt8();
1672
+ // Global: FragmentationParametersGlobalTLV
1673
+ const tlvs: Tlv[] = this.readTLVs();
1674
+
1675
+ result = {
1676
+ nwkAddress,
1677
+ logicalType: nodeDescByte1 & 0x07,
1678
+ fragmentationSupported: serverMask.stackComplianceRevision >= 23 ? (nodeDescByte1 & 0x20) >> 5 === 1 : undefined,
1679
+ apsFlags: nodeDescByte2 & 0x07,
1680
+ frequencyBand: (nodeDescByte2 & 0xf8) >> 3,
1681
+ capabilities: macCapFlags,
1682
+ manufacturerCode,
1683
+ maxBufSize,
1684
+ maxIncTxSize,
1685
+ serverMask,
1686
+ maxOutTxSize,
1687
+ deprecated1,
1688
+ tlvs,
1689
+ };
1690
+ }
1691
+
1692
+ return [status, result];
1693
+ }
1694
+
1695
+ /**
1696
+ * @see ClusterId.POWER_DESCRIPTOR_RESPONSE
1697
+ */
1698
+ public readPowerDescriptorResponse(): ResponseMap[ZdoClusterId.POWER_DESCRIPTOR_RESPONSE] {
1699
+ // DEVICE_NOT_FOUND, INV_REQUESTTYPE, or NO_DESCRIPTOR
1700
+ const status: Status = this.readUInt8();
1701
+ let result: PowerDescriptorResponse | undefined;
1702
+
1703
+ if (status === Status.SUCCESS) {
1704
+ const nwkAddress = this.readUInt16();
1705
+ const byte1 = this.readUInt8();
1706
+ const byte2 = this.readUInt8();
1707
+
1708
+ result = {
1709
+ nwkAddress,
1710
+ currentPowerMode: byte1 & 0xf,
1711
+ availPowerSources: (byte1 >> 4) & 0xf,
1712
+ currentPowerSource: byte2 & 0xf,
1713
+ currentPowerSourceLevel: (byte2 >> 4) & 0xf,
1714
+ };
1715
+ }
1716
+
1717
+ return [status, result];
1718
+ }
1719
+
1720
+ /**
1721
+ * @see ClusterId.SIMPLE_DESCRIPTOR_RESPONSE
1722
+ */
1723
+ public readSimpleDescriptorResponse(): ResponseMap[ZdoClusterId.SIMPLE_DESCRIPTOR_RESPONSE] {
1724
+ // INVALID_EP, NOT_ACTIVE, DEVICE_NOT_FOUND, INV_REQUESTTYPE or NO_DESCRIPTOR
1725
+ const status: Status = this.readUInt8();
1726
+ let result: SimpleDescriptorResponse | undefined;
1727
+
1728
+ if (status === Status.SUCCESS) {
1729
+ const nwkAddress = this.readUInt16();
1730
+ // Length in bytes of the Simple Descriptor to follow. [0x00-0xff]
1731
+ const length = this.readUInt8();
1732
+ const endpoint = this.readUInt8();
1733
+ const profileId = this.readUInt16();
1734
+ const deviceId = this.readUInt16();
1735
+ const deviceVersion = this.readUInt8();
1736
+ const inClusterCount = this.readUInt8();
1737
+ const inClusterList = this.readListUInt16(inClusterCount); // empty if inClusterCount==0
1738
+ const outClusterCount = this.readUInt8();
1739
+ const outClusterList = this.readListUInt16(outClusterCount); // empty if outClusterCount==0
1740
+
1741
+ result = {
1742
+ nwkAddress,
1743
+ length,
1744
+ endpoint,
1745
+ profileId,
1746
+ deviceId,
1747
+ deviceVersion,
1748
+ inClusterList,
1749
+ outClusterList,
1750
+ };
1751
+ }
1752
+
1753
+ return [status, result];
1754
+ }
1755
+
1756
+ /**
1757
+ * @see ClusterId.ACTIVE_ENDPOINTS_RESPONSE
1758
+ */
1759
+ public readActiveEndpointsResponse(): ResponseMap[ZdoClusterId.ACTIVE_ENDPOINTS_RESPONSE] {
1760
+ // DEVICE_NOT_FOUND, INV_REQUESTTYPE, or NO_DESCRIPTOR
1761
+ const status: Status = this.readUInt8();
1762
+ let result: ActiveEndpointsResponse | undefined;
1763
+
1764
+ if (status === Status.SUCCESS) {
1765
+ const nwkAddress = this.readUInt16();
1766
+ const endpointCount = this.readUInt8();
1767
+ const endpointList = this.readListUInt8(endpointCount);
1768
+
1769
+ result = {
1770
+ nwkAddress,
1771
+ endpointList,
1772
+ };
1773
+ }
1774
+
1775
+ return [status, result];
1776
+ }
1777
+
1778
+ /**
1779
+ * @see ClusterId.MATCH_DESCRIPTORS_RESPONSE
1780
+ */
1781
+ public readMatchDescriptorsResponse(): ResponseMap[ZdoClusterId.MATCH_DESCRIPTORS_RESPONSE] {
1782
+ // DEVICE_NOT_FOUND, INV_REQUESTTYPE, or NO_DESCRIPTOR
1783
+ const status: Status = this.readUInt8();
1784
+ let result: MatchDescriptorsResponse | undefined;
1785
+
1786
+ if (status === Status.SUCCESS) {
1787
+ const nwkAddress = this.readUInt16();
1788
+ const endpointCount = this.readUInt8();
1789
+ const endpointList = this.readListUInt8(endpointCount);
1790
+
1791
+ result = {
1792
+ nwkAddress,
1793
+ endpointList,
1794
+ };
1795
+ }
1796
+
1797
+ return [status, result];
1798
+ }
1799
+
1800
+ /**
1801
+ * @see ClusterId.END_DEVICE_ANNOUNCE
1802
+ */
1803
+ public readEndDeviceAnnounce(): ResponseMap[ZdoClusterId.END_DEVICE_ANNOUNCE] {
1804
+ const nwkAddress = this.readUInt16();
1805
+ const eui64 = this.readIeeeAddr();
1806
+ /** @see MACCapabilityFlags */
1807
+ const capabilities = this.readUInt8();
1808
+
1809
+ return [Status.SUCCESS, {nwkAddress, eui64, capabilities: Utils.getMacCapFlags(capabilities)}];
1810
+ }
1811
+
1812
+ /**
1813
+ * @see ClusterId.SYSTEM_SERVER_DISCOVERY_RESPONSE
1814
+ */
1815
+ public readSystemServerDiscoveryResponse(): ResponseMap[ZdoClusterId.SYSTEM_SERVER_DISCOVERY_RESPONSE] {
1816
+ // never expected !== SUCCESS
1817
+ const status: Status = this.readUInt8();
1818
+ let result: SystemServerDiscoveryResponse | undefined;
1819
+
1820
+ if (status === Status.SUCCESS) {
1821
+ const serverMask = Utils.getServerMask(this.readUInt16());
1822
+
1823
+ result = {
1824
+ serverMask,
1825
+ };
1826
+ }
1827
+
1828
+ return [status, result];
1829
+ }
1830
+
1831
+ /**
1832
+ * @see ClusterId.PARENT_ANNOUNCE_RESPONSE
1833
+ */
1834
+ public readParentAnnounceResponse(): ResponseMap[ZdoClusterId.PARENT_ANNOUNCE_RESPONSE] {
1835
+ // NOT_SUPPORTED
1836
+ const status: Status = this.readUInt8();
1837
+ let result: ParentAnnounceResponse | undefined;
1838
+
1839
+ if (status === Status.SUCCESS) {
1840
+ const numberOfChildren = this.readUInt8();
1841
+ const children: Eui64[] = [];
1842
+
1843
+ for (let i = 0; i < numberOfChildren; i++) {
1844
+ const childEui64 = this.readIeeeAddr();
1845
+
1846
+ children.push(childEui64);
1847
+ }
1848
+
1849
+ result = {children};
1850
+ }
1851
+
1852
+ return [status, result];
1853
+ }
1854
+
1855
+ /**
1856
+ * @see ClusterId.BIND_RESPONSE
1857
+ * @returns No response payload, throws if not success
1858
+ */
1859
+ public readBindResponse(): ResponseMap[ZdoClusterId.BIND_RESPONSE] {
1860
+ // NOT_SUPPORTED, INVALID_EP, TABLE_FULL, or NOT_AUTHORIZED
1861
+ const status: Status = this.readUInt8();
1862
+
1863
+ return [status, undefined];
1864
+ }
1865
+
1866
+ /**
1867
+ * @see ClusterId.UNBIND_RESPONSE
1868
+ * @returns No response payload, throws if not success
1869
+ */
1870
+ public readUnbindResponse(): ResponseMap[ZdoClusterId.UNBIND_RESPONSE] {
1871
+ // NOT_SUPPORTED, INVALID_EP, NO_ENTRY or NOT_AUTHORIZED
1872
+ const status: Status = this.readUInt8();
1873
+
1874
+ return [status, undefined];
1875
+ }
1876
+
1877
+ /**
1878
+ * @see ClusterId.CLEAR_ALL_BINDINGS_RESPONSE
1879
+ * @returns No response payload, throws if not success
1880
+ */
1881
+ public readClearAllBindingsResponse(): ResponseMap[ZdoClusterId.CLEAR_ALL_BINDINGS_RESPONSE] {
1882
+ // NOT_SUPPORTED, NOT_AUTHORIZED, INV_REQUESTTYPE, or NO_MATCH.
1883
+ const status: Status = this.readUInt8();
1884
+
1885
+ return [status, undefined];
1886
+ }
1887
+
1888
+ /**
1889
+ * @see ClusterId.LQI_TABLE_RESPONSE
1890
+ */
1891
+ public readLQITableResponse(): ResponseMap[ZdoClusterId.LQI_TABLE_RESPONSE] {
1892
+ // NOT_SUPPORTED or any status code returned from the NLME-GET.confirm primitive.
1893
+ const status: Status = this.readUInt8();
1894
+ let result: LQITableResponse | undefined;
1895
+
1896
+ if (status === Status.SUCCESS) {
1897
+ const neighborTableEntries = this.readUInt8();
1898
+ const startIndex = this.readUInt8();
1899
+ // [0x00-0x02]
1900
+ const entryCount = this.readUInt8();
1901
+ const entryList: LQITableEntry[] = [];
1902
+
1903
+ for (let i = 0; i < entryCount; i++) {
1904
+ const extendedPanId = this.readListUInt8(EXTENDED_PAN_ID_SIZE);
1905
+ const eui64 = this.readIeeeAddr();
1906
+ const nwkAddress = this.readUInt16();
1907
+ const deviceTypeByte = this.readUInt8();
1908
+ const permitJoiningByte = this.readUInt8();
1909
+ const depth = this.readUInt8();
1910
+ const lqi = this.readUInt8();
1911
+
1912
+ entryList.push({
1913
+ extendedPanId,
1914
+ eui64,
1915
+ nwkAddress,
1916
+ deviceType: deviceTypeByte & 0x03,
1917
+ rxOnWhenIdle: (deviceTypeByte & 0x0c) >> 2,
1918
+ relationship: (deviceTypeByte & 0x70) >> 4,
1919
+ reserved1: (deviceTypeByte & 0x10) >> 7,
1920
+ permitJoining: permitJoiningByte & 0x03,
1921
+ reserved2: (permitJoiningByte & 0xfc) >> 2,
1922
+ depth,
1923
+ lqi,
1924
+ });
1925
+ }
1926
+
1927
+ result = {
1928
+ neighborTableEntries,
1929
+ startIndex,
1930
+ entryList,
1931
+ };
1932
+ }
1933
+
1934
+ return [status, result];
1935
+ }
1936
+
1937
+ /**
1938
+ * @see ClusterId.ROUTING_TABLE_RESPONSE
1939
+ */
1940
+ public readRoutingTableResponse(): ResponseMap[ZdoClusterId.ROUTING_TABLE_RESPONSE] {
1941
+ // NOT_SUPPORTED or any status code returned from the NLMEGET.confirm primitive.
1942
+ const status: Status = this.readUInt8();
1943
+ let result: RoutingTableResponse | undefined;
1944
+
1945
+ if (status === Status.SUCCESS) {
1946
+ const routingTableEntries = this.readUInt8();
1947
+ const startIndex = this.readUInt8();
1948
+ // [0x00-0xFF]
1949
+ const entryCount = this.readUInt8();
1950
+ const entryList: RoutingTableEntry[] = [];
1951
+
1952
+ for (let i = 0; i < entryCount; i++) {
1953
+ const destinationAddress = this.readUInt16();
1954
+ const statusByte = this.readUInt8();
1955
+ const nextHopAddress = this.readUInt16();
1956
+
1957
+ entryList.push({
1958
+ destinationAddress,
1959
+ status: RoutingTableStatus[statusByte & 0x07] as keyof typeof RoutingTableStatus,
1960
+ memoryConstrained: (statusByte & 0x08) >> 3,
1961
+ manyToOne: (statusByte & 0x10) >> 4,
1962
+ routeRecordRequired: (statusByte & 0x20) >> 5,
1963
+ reserved1: (statusByte & 0xc0) >> 6,
1964
+ nextHopAddress,
1965
+ });
1966
+ }
1967
+
1968
+ result = {
1969
+ routingTableEntries,
1970
+ startIndex,
1971
+ entryList,
1972
+ };
1973
+ }
1974
+
1975
+ return [status, result];
1976
+ }
1977
+
1978
+ /**
1979
+ * @see ClusterId.BINDING_TABLE_RESPONSE
1980
+ */
1981
+ public readBindingTableResponse(): ResponseMap[ZdoClusterId.BINDING_TABLE_RESPONSE] {
1982
+ // NOT_SUPPORTED or any status code returned from the APSMEGET.confirm primitive.
1983
+ const status: Status = this.readUInt8();
1984
+ let result: BindingTableResponse | undefined;
1985
+
1986
+ if (status === Status.SUCCESS) {
1987
+ const bindingTableEntries = this.readUInt8();
1988
+ const startIndex = this.readUInt8();
1989
+ // [0x00-0xFF]
1990
+ const entryCount = this.readUInt8();
1991
+ const entryList: BindingTableEntry[] = [];
1992
+
1993
+ for (let i = 0; i < entryCount; i++) {
1994
+ const sourceEui64 = this.readIeeeAddr();
1995
+ const sourceEndpoint = this.readUInt8();
1996
+ const clusterId = this.readUInt16();
1997
+ const destAddrMode = this.readUInt8();
1998
+ const dest = destAddrMode === 0x01 ? this.readUInt16() : destAddrMode === 0x03 ? this.readIeeeAddr() : undefined;
1999
+ const destEndpoint = destAddrMode === 0x03 ? this.readUInt8() : undefined;
2000
+
2001
+ if (dest === undefined) {
2002
+ // not supported (using reserved value)
2003
+ continue;
2004
+ }
2005
+
2006
+ entryList.push({
2007
+ sourceEui64,
2008
+ sourceEndpoint,
2009
+ clusterId,
2010
+ destAddrMode,
2011
+ dest,
2012
+ destEndpoint,
2013
+ });
2014
+ }
2015
+
2016
+ result = {
2017
+ bindingTableEntries,
2018
+ startIndex,
2019
+ entryList,
2020
+ };
2021
+ }
2022
+
2023
+ return [status, result];
2024
+ }
2025
+
2026
+ /**
2027
+ * @see ClusterId.LEAVE_RESPONSE
2028
+ * @returns No response payload, throws if not success
2029
+ */
2030
+ public readLeaveResponse(): ResponseMap[ZdoClusterId.LEAVE_RESPONSE] {
2031
+ // NOT_SUPPORTED, NOT_AUTHORIZED or any status code returned from the NLMELEAVE.confirm primitive.
2032
+ const status: Status = this.readUInt8();
2033
+
2034
+ return [status, undefined];
2035
+ }
2036
+
2037
+ /**
2038
+ * @see ClusterId.PERMIT_JOINING_RESPONSE
2039
+ * @returns No response payload, throws if not success
2040
+ */
2041
+ public readPermitJoiningResponse(): ResponseMap[ZdoClusterId.PERMIT_JOINING_RESPONSE] {
2042
+ // INV_REQUESTTYPE, NOT_AUTHORIZED, or any status code returned from the NLME-PERMIT-JOINING.confirm primitive.
2043
+ const status: Status = this.readUInt8();
2044
+
2045
+ return [status, undefined];
2046
+ }
2047
+
2048
+ /**
2049
+ * @see ClusterId.NWK_UPDATE_RESPONSE
2050
+ */
2051
+ public readNwkUpdateResponse(): ResponseMap[ZdoClusterId.NWK_UPDATE_RESPONSE] {
2052
+ // INV_REQUESTTYPE, NOT_SUPPORTED, or any status values returned from the MLME-SCAN.confirm primitive
2053
+ const status: Status = this.readUInt8();
2054
+ let result: NwkUpdateResponse | undefined;
2055
+
2056
+ if (status === Status.SUCCESS) {
2057
+ const scannedChannels = this.readUInt32();
2058
+ const totalTransmissions = this.readUInt16();
2059
+ const totalFailures = this.readUInt16();
2060
+ // [0x00-0xFF]
2061
+ const entryCount = this.readUInt8();
2062
+ const entryList = this.readListUInt8(entryCount);
2063
+
2064
+ result = {
2065
+ scannedChannels,
2066
+ totalTransmissions,
2067
+ totalFailures,
2068
+ entryList,
2069
+ };
2070
+ }
2071
+
2072
+ return [status, result];
2073
+ }
2074
+
2075
+ /**
2076
+ * @see ClusterId.NWK_ENHANCED_UPDATE_RESPONSE
2077
+ */
2078
+ public readNwkEnhancedUpdateResponse(): ResponseMap[ZdoClusterId.NWK_ENHANCED_UPDATE_RESPONSE] {
2079
+ // INV_REQUESTTYPE, NOT_SUPPORTED, or any status values returned from the MLME-SCAN.confirm primitive.
2080
+ const status: Status = this.readUInt8();
2081
+ let result: NwkEnhancedUpdateResponse | undefined;
2082
+
2083
+ if (status === Status.SUCCESS) {
2084
+ const scannedChannels = this.readUInt32();
2085
+ const totalTransmissions = this.readUInt16();
2086
+ const totalFailures = this.readUInt16();
2087
+ // [0x00-0xFF]
2088
+ const entryCount = this.readUInt8();
2089
+ const entryList = this.readListUInt8(entryCount);
2090
+
2091
+ result = {
2092
+ scannedChannels,
2093
+ totalTransmissions,
2094
+ totalFailures,
2095
+ entryList,
2096
+ };
2097
+ }
2098
+
2099
+ return [status, result];
2100
+ }
2101
+
2102
+ /**
2103
+ * @see ClusterId.NWK_IEEE_JOINING_LIST_REPONSE
2104
+ */
2105
+ public readNwkIEEEJoiningListResponse(): ResponseMap[ZdoClusterId.NWK_IEEE_JOINING_LIST_RESPONSE] {
2106
+ // INV_REQUESTTYPE, or NOT_SUPPORTED
2107
+ const status: Status = this.readUInt8();
2108
+ let result: NwkIEEEJoiningListResponse | undefined;
2109
+
2110
+ if (status === Status.SUCCESS) {
2111
+ const updateId = this.readUInt8();
2112
+ const joiningPolicy = this.readUInt8();
2113
+ // [0x00-0xFF]
2114
+ const entryListTotal = this.readUInt8();
2115
+ let startIndex: number | undefined;
2116
+ let entryList: Eui64[] | undefined;
2117
+
2118
+ if (entryListTotal > 0) {
2119
+ startIndex = this.readUInt8();
2120
+ const entryCount = this.readUInt8();
2121
+ entryList = [];
2122
+
2123
+ for (let i = 0; i < entryCount; i++) {
2124
+ const ieee = this.readIeeeAddr();
2125
+
2126
+ entryList.push(ieee);
2127
+ }
2128
+ }
2129
+
2130
+ result = {
2131
+ updateId,
2132
+ joiningPolicy,
2133
+ entryListTotal,
2134
+ startIndex,
2135
+ entryList,
2136
+ };
2137
+ }
2138
+
2139
+ return [status, result];
2140
+ }
2141
+
2142
+ /**
2143
+ * @see ClusterId.NWK_UNSOLICITED_ENHANCED_UPDATE_RESPONSE
2144
+ */
2145
+ public readNwkUnsolicitedEnhancedUpdateResponse(): ResponseMap[ZdoClusterId.NWK_UNSOLICITED_ENHANCED_UPDATE_RESPONSE] {
2146
+ // ??
2147
+ const status: Status = this.readUInt8();
2148
+ let result: NwkUnsolicitedEnhancedUpdateResponse | undefined;
2149
+
2150
+ if (status === Status.SUCCESS) {
2151
+ const channelInUse = this.readUInt32();
2152
+ const macTxUCastTotal = this.readUInt16();
2153
+ const macTxUCastFailures = this.readUInt16();
2154
+ const macTxUCastRetries = this.readUInt16();
2155
+ const timePeriod = this.readUInt8();
2156
+
2157
+ result = {
2158
+ channelInUse,
2159
+ macTxUCastTotal,
2160
+ macTxUCastFailures,
2161
+ macTxUCastRetries,
2162
+ timePeriod,
2163
+ };
2164
+ }
2165
+
2166
+ return [status, result];
2167
+ }
2168
+
2169
+ /**
2170
+ * @see ClusterId.NWK_BEACON_SURVEY_RESPONSE
2171
+ */
2172
+ public readNwkBeaconSurveyResponse(): ResponseMap[ZdoClusterId.NWK_BEACON_SURVEY_RESPONSE] {
2173
+ // INV_REQUESTTYPE, or NOT_SUPPORTED
2174
+ const status: Status = this.readUInt8();
2175
+ let result: NwkBeaconSurveyResponse | undefined;
2176
+
2177
+ if (status === Status.SUCCESS) {
2178
+ const localTLVs = new Map<number, LocalTLVReader>([
2179
+ // Local: ID: 0x01: BeaconSurveyResultsTLV
2180
+ [0x01, this.readBeaconSurveyResultsTLV],
2181
+ // Local: ID: 0x02: PotentialParentsTLV
2182
+ [0x02, this.readPotentialParentsTLV],
2183
+ ]);
2184
+ const tlvs: Tlv[] = this.readTLVs(localTLVs);
2185
+
2186
+ result = {
2187
+ tlvs,
2188
+ };
2189
+ }
2190
+
2191
+ return [status, result];
2192
+ }
2193
+
2194
+ /**
2195
+ * @see ClusterId.START_KEY_NEGOTIATION_RESPONSE
2196
+ */
2197
+ public readStartKeyNegotiationResponse(): ResponseMap[ZdoClusterId.START_KEY_NEGOTIATION_RESPONSE] {
2198
+ // INVALID_TLV, MISSING_TLV, TEMPORARY_FAILURE, NOT_AUTHORIZED
2199
+ const status: Status = this.readUInt8();
2200
+ let result: StartKeyNegotiationResponse | undefined;
2201
+
2202
+ if (status === Status.SUCCESS) {
2203
+ const localTLVs = new Map<number, LocalTLVReader>([
2204
+ // Local: ID: 0x00: Curve25519PublicPointTLV
2205
+ [0x00, this.readCurve25519PublicPointTLV],
2206
+ ]);
2207
+ const tlvs: Tlv[] = this.readTLVs(localTLVs);
2208
+
2209
+ result = {
2210
+ tlvs,
2211
+ };
2212
+ }
2213
+
2214
+ return [status, result];
2215
+ }
2216
+
2217
+ /**
2218
+ * @see ClusterId.RETRIEVE_AUTHENTICATION_TOKEN_RESPONSE
2219
+ */
2220
+ public readRetrieveAuthenticationTokenResponse(): ResponseMap[ZdoClusterId.RETRIEVE_AUTHENTICATION_TOKEN_RESPONSE] {
2221
+ const status: Status = this.readUInt8();
2222
+ let result: RetrieveAuthenticationTokenResponse | undefined;
2223
+
2224
+ if (status === Status.SUCCESS) {
2225
+ // no local TLV
2226
+ const tlvs: Tlv[] = this.readTLVs();
2227
+
2228
+ result = {
2229
+ tlvs,
2230
+ };
2231
+ }
2232
+
2233
+ return [status, result];
2234
+ }
2235
+
2236
+ /**
2237
+ * @see ClusterId.GET_AUTHENTICATION_LEVEL_RESPONSE
2238
+ */
2239
+ public readGetAuthenticationLevelResponse(): ResponseMap[ZdoClusterId.GET_AUTHENTICATION_LEVEL_RESPONSE] {
2240
+ // NOT_SUPPORTED, INV_REQUESTTYPE, MISSING_TLV, and NOT_AUTHORIZED
2241
+ const status: Status = this.readUInt8();
2242
+ let result: GetAuthenticationLevelResponse | undefined;
2243
+
2244
+ if (status === Status.SUCCESS) {
2245
+ const localTLVs = new Map<number, LocalTLVReader>([
2246
+ // Local: ID: 0x00: DeviceAuthenticationLevelTLV
2247
+ [0x00, this.readDeviceAuthenticationLevelTLV],
2248
+ ]);
2249
+ const tlvs: Tlv[] = this.readTLVs(localTLVs);
2250
+
2251
+ result = {
2252
+ tlvs,
2253
+ };
2254
+ }
2255
+
2256
+ return [status, result];
2257
+ }
2258
+
2259
+ /**
2260
+ * @see ClusterId.SET_CONFIGURATION_RESPONSE
2261
+ */
2262
+ public readSetConfigurationResponse(): ResponseMap[ZdoClusterId.SET_CONFIGURATION_RESPONSE] {
2263
+ // INV_REQUESTTYPE, or NOT_SUPPORTED
2264
+ const status: Status = this.readUInt8();
2265
+ let result: SetConfigurationResponse | undefined;
2266
+
2267
+ if (status === Status.SUCCESS) {
2268
+ const localTLVs = new Map<number, LocalTLVReader>([
2269
+ // Local: ID: 0x00: ProcessingStatusTLV
2270
+ [0x00, this.readProcessingStatusTLV],
2271
+ ]);
2272
+ const tlvs: Tlv[] = this.readTLVs(localTLVs);
2273
+
2274
+ result = {
2275
+ tlvs,
2276
+ };
2277
+ }
2278
+
2279
+ return [status, result];
2280
+ }
2281
+
2282
+ /**
2283
+ * @see ClusterId.GET_CONFIGURATION_RESPONSE
2284
+ */
2285
+ public readGetConfigurationResponse(): ResponseMap[ZdoClusterId.GET_CONFIGURATION_RESPONSE] {
2286
+ // INV_REQUESTTYPE, or NOT_SUPPORTED
2287
+ const status: Status = this.readUInt8();
2288
+ let result: GetConfigurationResponse | undefined;
2289
+
2290
+ if (status === Status.SUCCESS) {
2291
+ // Global: IDs: x, y, z
2292
+ const tlvs: Tlv[] = this.readTLVs();
2293
+
2294
+ result = {
2295
+ tlvs,
2296
+ };
2297
+ }
2298
+
2299
+ return [status, result];
2300
+ }
2301
+
2302
+ /**
2303
+ * @see ClusterId.START_KEY_UPDATE_RESPONSE
2304
+ * @returns No response payload, throws if not success
2305
+ */
2306
+ public readStartKeyUpdateResponse(): ResponseMap[ZdoClusterId.START_KEY_UPDATE_RESPONSE] {
2307
+ // INV_REQUESTTYPE, NOT_AUTHORIZED or NOT_SUPPORTED
2308
+ const status: Status = this.readUInt8();
2309
+
2310
+ return [status, undefined];
2311
+ }
2312
+
2313
+ /**
2314
+ * @see ClusterId.DECOMMISSION_RESPONSE
2315
+ * @returns No response payload, throws if not success
2316
+ */
2317
+ public readDecommissionResponse(): ResponseMap[ZdoClusterId.DECOMMISSION_RESPONSE] {
2318
+ // INV_REQUESTTYPE, NOT_AUTHORIZED or NOT_SUPPORTED
2319
+ const status: Status = this.readUInt8();
2320
+
2321
+ return [status, undefined];
2322
+ }
2323
+
2324
+ /**
2325
+ * @see ClusterId.CHALLENGE_RESPONSE
2326
+ */
2327
+ public readChallengeResponse(): ResponseMap[ZdoClusterId.CHALLENGE_RESPONSE] {
2328
+ const status: Status = this.readUInt8();
2329
+ let result: ChallengeResponse | undefined;
2330
+
2331
+ if (status === Status.SUCCESS) {
2332
+ const localTLVs = new Map<number, LocalTLVReader>([
2333
+ // Local: ID: 0x00: APSFrameCounterResponseTLV
2334
+ [0x00, this.readAPSFrameCounterResponseTLV],
2335
+ ]);
2336
+ const tlvs: Tlv[] = this.readTLVs(localTLVs);
2337
+
2338
+ result = {
2339
+ tlvs,
2340
+ };
2341
+ }
2342
+
2343
+ return [status, result];
2344
+ }
2345
+ }