zigbee-herdsman 0.49.2 → 0.50.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.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +28 -0
- package/dist/adapter/ember/adapter/emberAdapter.d.ts +4 -2
- package/dist/adapter/ember/adapter/emberAdapter.d.ts.map +1 -1
- package/dist/adapter/ember/adapter/emberAdapter.js +361 -321
- package/dist/adapter/ember/adapter/emberAdapter.js.map +1 -1
- package/dist/adapter/ember/adapter/endpoints.d.ts.map +1 -1
- package/dist/adapter/ember/adapter/endpoints.js +2 -3
- package/dist/adapter/ember/adapter/endpoints.js.map +1 -1
- package/dist/adapter/ember/adapter/oneWaitress.d.ts +3 -3
- package/dist/adapter/ember/adapter/oneWaitress.js +1 -1
- package/dist/adapter/ember/adapter/oneWaitress.js.map +1 -1
- package/dist/adapter/ember/adapter/tokensManager.js +16 -16
- package/dist/adapter/ember/adapter/tokensManager.js.map +1 -1
- package/dist/adapter/ember/consts.d.ts +0 -50
- package/dist/adapter/ember/consts.d.ts.map +1 -1
- package/dist/adapter/ember/consts.js +1 -53
- package/dist/adapter/ember/consts.js.map +1 -1
- package/dist/adapter/ember/ezsp/ezsp.d.ts +4 -5
- package/dist/adapter/ember/ezsp/ezsp.d.ts.map +1 -1
- package/dist/adapter/ember/ezsp/ezsp.js +34 -16
- package/dist/adapter/ember/ezsp/ezsp.js.map +1 -1
- package/dist/adapter/ember/uart/ash.d.ts.map +1 -1
- package/dist/adapter/ember/uart/ash.js +9 -3
- package/dist/adapter/ember/uart/ash.js.map +1 -1
- package/dist/adapter/ember/utils/initters.d.ts.map +1 -1
- package/dist/adapter/ember/utils/initters.js +28 -4
- package/dist/adapter/ember/utils/initters.js.map +1 -1
- package/dist/adapter/ezsp/driver/driver.d.ts.map +1 -1
- package/dist/adapter/ezsp/driver/driver.js +1 -0
- package/dist/adapter/ezsp/driver/driver.js.map +1 -1
- package/dist/controller/controller.d.ts.map +1 -1
- package/dist/controller/controller.js +5 -9
- package/dist/controller/controller.js.map +1 -1
- package/dist/controller/events.d.ts +2 -5
- package/dist/controller/events.d.ts.map +1 -1
- package/dist/controller/events.js +1 -98
- package/dist/controller/events.js.map +1 -1
- package/dist/controller/model/device.js +7 -7
- package/dist/zspec/zcl/definition/cluster.d.ts.map +1 -1
- package/dist/zspec/zcl/definition/cluster.js +6 -168
- package/dist/zspec/zcl/definition/cluster.js.map +1 -1
- package/dist/zspec/zcl/definition/tstype.d.ts +1 -1
- package/dist/zspec/zcl/definition/tstype.d.ts.map +1 -1
- package/package.json +13 -7
|
@@ -36,13 +36,15 @@ const socketPortUtils_1 = __importDefault(require("../../socketPortUtils"));
|
|
|
36
36
|
const utils_1 = require("../../../utils");
|
|
37
37
|
const __1 = require("../..");
|
|
38
38
|
const Zcl = __importStar(require("../../../zspec/zcl"));
|
|
39
|
+
const enums_1 = require("../../../zspec/enums");
|
|
40
|
+
const ZSpec = __importStar(require("../../../zspec/consts"));
|
|
39
41
|
const events_1 = require("../../events");
|
|
40
42
|
const math_1 = require("../utils/math");
|
|
41
43
|
const ezsp_1 = require("../ezsp/ezsp");
|
|
42
44
|
const consts_1 = require("../ezsp/consts");
|
|
43
|
-
const
|
|
45
|
+
const enums_2 = require("../ezsp/enums");
|
|
44
46
|
const buffalo_1 = require("../ezsp/buffalo");
|
|
45
|
-
const
|
|
47
|
+
const enums_3 = require("../enums");
|
|
46
48
|
const zdo_1 = require("../zdo");
|
|
47
49
|
const consts_2 = require("../consts");
|
|
48
50
|
const requestQueue_1 = require("./requestQueue");
|
|
@@ -143,7 +145,7 @@ const DEFAULT_STACK_CONFIG = {
|
|
|
143
145
|
*
|
|
144
146
|
* Removing `ENABLE_ROUTE_DISCOVERY` leads to devices that won't reconnect/go offline, and various other issues. Keeping it for now.
|
|
145
147
|
*/
|
|
146
|
-
const DEFAULT_APS_OPTIONS = (
|
|
148
|
+
const DEFAULT_APS_OPTIONS = (enums_3.EmberApsOption.RETRY | enums_3.EmberApsOption.ENABLE_ROUTE_DISCOVERY | enums_3.EmberApsOption.ENABLE_ADDRESS_DISCOVERY);
|
|
147
149
|
/**
|
|
148
150
|
* Enabling this allows to immediately reject requests that won't be able to get to their destination.
|
|
149
151
|
* However, it causes more NCP calls, notably to get the source route overhead.
|
|
@@ -196,6 +198,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
196
198
|
* NOTE: Do not use directly, use getter functions for it that check if valid or need retrieval from NCP.
|
|
197
199
|
*/
|
|
198
200
|
networkCache;
|
|
201
|
+
multicastTable;
|
|
199
202
|
constructor(networkOptions, serialPortOptions, backupPath, adapterOptions) {
|
|
200
203
|
super(networkOptions, serialPortOptions, backupPath, adapterOptions);
|
|
201
204
|
this.stackConfig = this.loadStackConfig();
|
|
@@ -206,7 +209,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
206
209
|
this.zdoRequestBuffalo = new buffalo_1.EzspBuffalo(Buffer.alloc(consts_1.EZSP_MAX_FRAME_LENGTH));
|
|
207
210
|
this.ezsp = new ezsp_1.Ezsp(delay, serialPortOptions);
|
|
208
211
|
this.ezsp.on(ezsp_1.EzspEvents.STACK_STATUS, this.onStackStatus.bind(this));
|
|
209
|
-
this.ezsp.on(ezsp_1.EzspEvents.
|
|
212
|
+
this.ezsp.on(ezsp_1.EzspEvents.MESSAGE_SENT, this.onMessageSent.bind(this));
|
|
210
213
|
this.ezsp.on(ezsp_1.EzspEvents.ZDO_RESPONSE, this.onZDOResponse.bind(this));
|
|
211
214
|
this.ezsp.on(ezsp_1.EzspEvents.END_DEVICE_ANNOUNCE, this.onEndDeviceAnnounce.bind(this));
|
|
212
215
|
this.ezsp.on(ezsp_1.EzspEvents.INCOMING_MESSAGE, this.onIncomingMessage.bind(this));
|
|
@@ -318,27 +321,27 @@ class EmberAdapter extends __1.Adapter {
|
|
|
318
321
|
// to be extra careful, should clear network cache upon receiving this.
|
|
319
322
|
this.clearNetworkCache();
|
|
320
323
|
switch (status) {
|
|
321
|
-
case
|
|
324
|
+
case enums_3.EmberStatus.NETWORK_UP: {
|
|
322
325
|
this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_UP);
|
|
323
326
|
logger_1.logger.info(`[STACK STATUS] Network up.`, NS);
|
|
324
327
|
break;
|
|
325
328
|
}
|
|
326
|
-
case
|
|
329
|
+
case enums_3.EmberStatus.NETWORK_DOWN: {
|
|
327
330
|
this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_DOWN);
|
|
328
331
|
logger_1.logger.info(`[STACK STATUS] Network down.`, NS);
|
|
329
332
|
break;
|
|
330
333
|
}
|
|
331
|
-
case
|
|
334
|
+
case enums_3.EmberStatus.NETWORK_OPENED: {
|
|
332
335
|
this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_OPENED);
|
|
333
336
|
logger_1.logger.info(`[STACK STATUS] Network opened.`, NS);
|
|
334
337
|
break;
|
|
335
338
|
}
|
|
336
|
-
case
|
|
339
|
+
case enums_3.EmberStatus.NETWORK_CLOSED: {
|
|
337
340
|
this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_CLOSED);
|
|
338
341
|
logger_1.logger.info(`[STACK STATUS] Network closed.`, NS);
|
|
339
342
|
break;
|
|
340
343
|
}
|
|
341
|
-
case
|
|
344
|
+
case enums_3.EmberStatus.CHANNEL_CHANGED: {
|
|
342
345
|
this.oneWaitress.resolveEvent(oneWaitress_1.OneWaitressEvents.STACK_STATUS_CHANNEL_CHANGED);
|
|
343
346
|
// invalidate cache
|
|
344
347
|
this.networkCache.parameters.radioChannel = consts_2.INVALID_RADIO_CHANNEL;
|
|
@@ -346,7 +349,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
346
349
|
break;
|
|
347
350
|
}
|
|
348
351
|
default: {
|
|
349
|
-
logger_1.logger.debug(`[STACK STATUS] ${
|
|
352
|
+
logger_1.logger.debug(`[STACK STATUS] ${enums_3.EmberStatus[status]}.`, NS);
|
|
350
353
|
break;
|
|
351
354
|
}
|
|
352
355
|
}
|
|
@@ -359,24 +362,59 @@ class EmberAdapter extends __1.Adapter {
|
|
|
359
362
|
* @param indexOrDestination
|
|
360
363
|
* @param apsFrame
|
|
361
364
|
* @param messageTag
|
|
365
|
+
* @param status
|
|
362
366
|
*/
|
|
363
|
-
async
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
367
|
+
async onMessageSent(type, indexOrDestination, apsFrame, messageTag, status) {
|
|
368
|
+
if (status === enums_3.EmberStatus.DELIVERY_FAILED) {
|
|
369
|
+
// no ACK was received from the destination
|
|
370
|
+
switch (type) {
|
|
371
|
+
case enums_3.EmberOutgoingMessageType.BROADCAST:
|
|
372
|
+
case enums_3.EmberOutgoingMessageType.BROADCAST_WITH_ALIAS:
|
|
373
|
+
case enums_3.EmberOutgoingMessageType.MULTICAST:
|
|
374
|
+
case enums_3.EmberOutgoingMessageType.MULTICAST_WITH_ALIAS: {
|
|
375
|
+
// BC/MC not checking for message sent, avoid unnecessary waitress lookups
|
|
376
|
+
logger_1.logger.error(`Delivery of ${enums_3.EmberOutgoingMessageType[type]} failed for "${indexOrDestination}" `
|
|
377
|
+
+ `[apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
default: {
|
|
381
|
+
// reject any waitress early (don't wait for timeout if we know we're gonna get there eventually)
|
|
382
|
+
this.oneWaitress.deliveryFailedFor(indexOrDestination, apsFrame);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
373
385
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
386
|
+
}
|
|
387
|
+
else if (status === enums_3.EmberStatus.SUCCESS) {
|
|
388
|
+
if (type === enums_3.EmberOutgoingMessageType.MULTICAST && apsFrame.destinationEndpoint === 0xFF &&
|
|
389
|
+
apsFrame.groupId < consts_2.EMBER_MIN_BROADCAST_ADDRESS && !this.multicastTable.includes(apsFrame.groupId)) {
|
|
390
|
+
// workaround for devices using multicast for state update (coordinator passthrough)
|
|
391
|
+
const tableIdx = this.multicastTable.length;
|
|
392
|
+
const multicastEntry = {
|
|
393
|
+
multicastId: apsFrame.groupId,
|
|
394
|
+
endpoint: endpoints_1.FIXED_ENDPOINTS[0].endpoint,
|
|
395
|
+
networkIndex: endpoints_1.FIXED_ENDPOINTS[0].networkIndex,
|
|
396
|
+
};
|
|
397
|
+
// set immediately to avoid potential race
|
|
398
|
+
this.multicastTable.push(multicastEntry.multicastId);
|
|
399
|
+
await new Promise((resolve, reject) => {
|
|
400
|
+
this.requestQueue.enqueue(async () => {
|
|
401
|
+
const status = (await this.ezsp.ezspSetMulticastTableEntry(tableIdx, multicastEntry));
|
|
402
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
403
|
+
logger_1.logger.error(`Failed to register group "${multicastEntry.multicastId}" in multicast table with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
404
|
+
return status;
|
|
405
|
+
}
|
|
406
|
+
logger_1.logger.debug(`Registered multicast table entry (${tableIdx}): ${JSON.stringify(multicastEntry)}.`, NS);
|
|
407
|
+
resolve();
|
|
408
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
409
|
+
}, (reason) => {
|
|
410
|
+
// remove to allow retry on next occurrence
|
|
411
|
+
this.multicastTable.splice(tableIdx, 1);
|
|
412
|
+
reject(reason);
|
|
413
|
+
}, true);
|
|
414
|
+
});
|
|
378
415
|
}
|
|
379
416
|
}
|
|
417
|
+
// shouldn't be any other status
|
|
380
418
|
}
|
|
381
419
|
/**
|
|
382
420
|
* Emitted from @see Ezsp.ezspIncomingMessageHandler
|
|
@@ -420,7 +458,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
420
458
|
endpoint: apsFrame.sourceEndpoint,
|
|
421
459
|
linkquality: lastHopLqi,
|
|
422
460
|
groupID: apsFrame.groupId,
|
|
423
|
-
wasBroadcast: ((type ===
|
|
461
|
+
wasBroadcast: ((type === enums_3.EmberIncomingMessageType.BROADCAST) || (type === enums_3.EmberIncomingMessageType.BROADCAST_LOOPBACK)),
|
|
424
462
|
destinationEndpoint: apsFrame.destinationEndpoint,
|
|
425
463
|
};
|
|
426
464
|
this.oneWaitress.resolveZCL(payload);
|
|
@@ -480,11 +518,11 @@ class EmberAdapter extends __1.Adapter {
|
|
|
480
518
|
data,
|
|
481
519
|
clusterID: Zcl.Clusters.greenPower.ID,
|
|
482
520
|
address: sourceId,
|
|
483
|
-
endpoint:
|
|
521
|
+
endpoint: ZSpec.GP_ENDPOINT,
|
|
484
522
|
linkquality: gpdLink,
|
|
485
523
|
groupID: this.greenPowerGroup,
|
|
486
524
|
wasBroadcast: true,
|
|
487
|
-
destinationEndpoint:
|
|
525
|
+
destinationEndpoint: ZSpec.GP_ENDPOINT,
|
|
488
526
|
};
|
|
489
527
|
this.oneWaitress.resolveZCL(payload);
|
|
490
528
|
this.emit(events_1.Events.zclPayload, payload);
|
|
@@ -505,7 +543,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
505
543
|
* @param parentOfNewNodeId
|
|
506
544
|
*/
|
|
507
545
|
async onTrustCenterJoin(newNodeId, newNodeEui64, status, policyDecision, parentOfNewNodeId) {
|
|
508
|
-
if (status ===
|
|
546
|
+
if (status === enums_3.EmberDeviceUpdate.DEVICE_LEFT) {
|
|
509
547
|
const payload = {
|
|
510
548
|
networkAddress: newNodeId,
|
|
511
549
|
ieeeAddr: newNodeEui64,
|
|
@@ -513,7 +551,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
513
551
|
this.emit(events_1.Events.deviceLeave, payload);
|
|
514
552
|
}
|
|
515
553
|
else {
|
|
516
|
-
if (policyDecision !==
|
|
554
|
+
if (policyDecision !== enums_3.EmberJoinDecision.DENY_JOIN) {
|
|
517
555
|
const payload = {
|
|
518
556
|
networkAddress: newNodeId,
|
|
519
557
|
ieeeAddr: newNodeEui64,
|
|
@@ -528,7 +566,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
528
566
|
this.manufacturerCode = joinManufCode;
|
|
529
567
|
this.emit(events_1.Events.deviceJoined, payload);
|
|
530
568
|
resolve();
|
|
531
|
-
return
|
|
569
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
532
570
|
}, reject, true);
|
|
533
571
|
});
|
|
534
572
|
}
|
|
@@ -550,12 +588,12 @@ class EmberAdapter extends __1.Adapter {
|
|
|
550
588
|
const ashCounters = this.ezsp.ash.readAndClearCounters();
|
|
551
589
|
logger_1.logger.info(`[ASH COUNTERS] ${ashCounters.join(',')}`, NS);
|
|
552
590
|
resolve();
|
|
553
|
-
return
|
|
591
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
554
592
|
}, reject);
|
|
555
593
|
});
|
|
556
594
|
}
|
|
557
595
|
initVariables() {
|
|
558
|
-
this.ezsp.removeAllListeners(ezsp_1.EzspEvents.
|
|
596
|
+
this.ezsp.removeAllListeners(ezsp_1.EzspEvents.NCP_NEEDS_RESET_AND_INIT);
|
|
559
597
|
clearInterval(this.watchdogCountersHandle);
|
|
560
598
|
this.zdoRequestBuffalo.setPosition(0);
|
|
561
599
|
this.zdoRequestSequence = 0; // start at 1
|
|
@@ -563,7 +601,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
563
601
|
this.interpanLock = false;
|
|
564
602
|
this.networkCache = (0, initters_1.initNetworkCache)();
|
|
565
603
|
this.manufacturerCode = DEFAULT_MANUFACTURER_CODE; // will be set in NCP in initEzsp
|
|
566
|
-
this.
|
|
604
|
+
this.multicastTable = [];
|
|
605
|
+
this.ezsp.once(ezsp_1.EzspEvents.NCP_NEEDS_RESET_AND_INIT, this.onNcpNeedsResetAndInit.bind(this));
|
|
567
606
|
}
|
|
568
607
|
/**
|
|
569
608
|
* Proceed to execute the long list of commands required to setup comms between Host<>NCP.
|
|
@@ -573,8 +612,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
573
612
|
let result = "resumed";
|
|
574
613
|
// NOTE: something deep in this call can throw too
|
|
575
614
|
const startResult = (await this.ezsp.start());
|
|
576
|
-
if (startResult !==
|
|
577
|
-
throw new Error(`Failed to start EZSP layer with status=${
|
|
615
|
+
if (startResult !== enums_3.EzspStatus.SUCCESS) {
|
|
616
|
+
throw new Error(`Failed to start EZSP layer with status=${enums_3.EzspStatus[startResult]}.`);
|
|
578
617
|
}
|
|
579
618
|
// call before any other command, else fails
|
|
580
619
|
await this.emberVersion();
|
|
@@ -590,8 +629,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
590
629
|
// await (this.emberStartEnergyScan());// TODO: via config of some kind, better off waiting for UI supports though
|
|
591
630
|
// populate network cache info
|
|
592
631
|
const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
|
|
593
|
-
if (status !==
|
|
594
|
-
throw new Error(`Failed to get network parameters with status=${
|
|
632
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
633
|
+
throw new Error(`Failed to get network parameters with status=${enums_3.EmberStatus[status]}.`);
|
|
595
634
|
}
|
|
596
635
|
this.networkCache.parameters = parameters;
|
|
597
636
|
this.networkCache.status = (await this.ezsp.ezspNetworkState());
|
|
@@ -607,28 +646,28 @@ class EmberAdapter extends __1.Adapter {
|
|
|
607
646
|
*/
|
|
608
647
|
async initNCPPreConfiguration() {
|
|
609
648
|
// this can only decrease, not increase, NCP-side value
|
|
610
|
-
await this.emberSetEzspConfigValue(
|
|
611
|
-
await this.emberSetEzspConfigValue(
|
|
649
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.ADDRESS_TABLE_SIZE, this.stackConfig.ADDRESS_TABLE_SIZE);
|
|
650
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.TRUST_CENTER_ADDRESS_CACHE_SIZE, this.stackConfig.TRUST_CENTER_ADDRESS_CACHE_SIZE);
|
|
612
651
|
// BUG 14222: If stack profile is 2 (ZigBee Pro), we need to enforce
|
|
613
652
|
// the standard stack configuration values for that feature set.
|
|
614
653
|
/** MAC indirect timeout should be 7.68 secs */
|
|
615
|
-
await this.emberSetEzspConfigValue(
|
|
654
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.INDIRECT_TRANSMISSION_TIMEOUT, 7680);
|
|
616
655
|
/** Max hops should be 2 * nwkMaxDepth, where nwkMaxDepth is 15 */
|
|
617
|
-
await this.emberSetEzspConfigValue(
|
|
618
|
-
await this.emberSetEzspConfigValue(
|
|
619
|
-
await this.emberSetEzspConfigValue(
|
|
620
|
-
await this.emberSetEzspValue(
|
|
656
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.MAX_HOPS, 30);
|
|
657
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.TX_POWER_MODE, enums_3.EmberTXPowerMode.USE_TOKEN);
|
|
658
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.SUPPORTED_NETWORKS, 1);
|
|
659
|
+
await this.emberSetEzspValue(enums_2.EzspValueId.END_DEVICE_KEEP_ALIVE_SUPPORT_MODE, 1, [enums_3.EmberKeepAliveMode.KEEP_ALIVE_SUPPORT_ALL]);
|
|
621
660
|
// allow other devices to modify the binding table
|
|
622
|
-
await this.emberSetEzspPolicy(
|
|
661
|
+
await this.emberSetEzspPolicy(enums_2.EzspPolicyId.BINDING_MODIFICATION_POLICY, enums_2.EzspDecisionId.CHECK_BINDING_MODIFICATIONS_ARE_VALID_ENDPOINT_CLUSTERS);
|
|
623
662
|
// return message tag and message contents in ezspMessageSentHandler()
|
|
624
|
-
await this.emberSetEzspPolicy(
|
|
625
|
-
await this.emberSetEzspValue(
|
|
626
|
-
await this.emberSetEzspValue(
|
|
627
|
-
await this.emberSetEzspValue(
|
|
663
|
+
await this.emberSetEzspPolicy(enums_2.EzspPolicyId.MESSAGE_CONTENTS_IN_CALLBACK_POLICY, enums_2.EzspDecisionId.MESSAGE_TAG_AND_CONTENTS_IN_CALLBACK);
|
|
664
|
+
await this.emberSetEzspValue(enums_2.EzspValueId.MAXIMUM_INCOMING_TRANSFER_SIZE, 2, (0, math_1.lowHighBytes)(consts_2.MAXIMUM_APS_PAYLOAD_LENGTH));
|
|
665
|
+
await this.emberSetEzspValue(enums_2.EzspValueId.MAXIMUM_OUTGOING_TRANSFER_SIZE, 2, (0, math_1.lowHighBytes)(consts_2.MAXIMUM_APS_PAYLOAD_LENGTH));
|
|
666
|
+
await this.emberSetEzspValue(enums_2.EzspValueId.TRANSIENT_DEVICE_TIMEOUT, 2, (0, math_1.lowHighBytes)(this.stackConfig.TRANSIENT_DEVICE_TIMEOUT));
|
|
628
667
|
await this.ezsp.ezspSetManufacturerCode(this.manufacturerCode);
|
|
629
668
|
// network security init
|
|
630
|
-
await this.emberSetEzspConfigValue(
|
|
631
|
-
await this.emberSetEzspConfigValue(
|
|
669
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.STACK_PROFILE, consts_2.STACK_PROFILE_ZIGBEE_PRO);
|
|
670
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.SECURITY_LEVEL, consts_2.SECURITY_LEVEL_Z3);
|
|
632
671
|
}
|
|
633
672
|
/**
|
|
634
673
|
* NCP Address table init.
|
|
@@ -637,29 +676,29 @@ class EmberAdapter extends __1.Adapter {
|
|
|
637
676
|
async initNCPAddressTable() {
|
|
638
677
|
const desiredTableSize = this.stackConfig.ADDRESS_TABLE_SIZE;
|
|
639
678
|
// If the host and the ncp disagree on the address table size, explode.
|
|
640
|
-
const [status, addressTableSize] = (await this.ezsp.ezspGetConfigurationValue(
|
|
679
|
+
const [status, addressTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_2.EzspConfigId.ADDRESS_TABLE_SIZE));
|
|
641
680
|
// After the change of ncp memory model in UC, we can not increase the default NCP table sizes anymore.
|
|
642
681
|
// Therefore, checking for desiredTableSize == (ncp)addressTableSize might not be always true anymore
|
|
643
682
|
// assert(desiredTableSize <= addressTableSize);
|
|
644
|
-
if ((status !==
|
|
645
|
-
throw new Error(`[INIT] NCP (${addressTableSize}) disagrees with Host (min ${desiredTableSize}) on table size. status=${
|
|
683
|
+
if ((status !== enums_3.EzspStatus.SUCCESS) || (addressTableSize > desiredTableSize)) {
|
|
684
|
+
throw new Error(`[INIT] NCP (${addressTableSize}) disagrees with Host (min ${desiredTableSize}) on table size. status=${enums_3.EzspStatus[status]}`);
|
|
646
685
|
}
|
|
647
686
|
}
|
|
648
687
|
/**
|
|
649
688
|
* NCP configuration init
|
|
650
689
|
*/
|
|
651
690
|
async initNCPConfiguration() {
|
|
652
|
-
await this.emberSetEzspConfigValue(
|
|
653
|
-
await this.emberSetEzspConfigValue(
|
|
654
|
-
await this.emberSetEzspConfigValue(
|
|
655
|
-
await this.emberSetEzspConfigValue(
|
|
656
|
-
await this.emberSetEzspConfigValue(
|
|
657
|
-
await this.emberSetEzspConfigValue(
|
|
658
|
-
await this.emberSetEzspConfigValue(
|
|
659
|
-
await this.emberSetEzspConfigValue(
|
|
660
|
-
await this.emberSetEzspConfigValue(
|
|
661
|
-
await this.emberSetEzspConfigValue(
|
|
662
|
-
await this.emberSetEzspConfigValue(
|
|
691
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.BINDING_TABLE_SIZE, this.stackConfig.BINDING_TABLE_SIZE);
|
|
692
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.KEY_TABLE_SIZE, this.stackConfig.KEY_TABLE_SIZE);
|
|
693
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.MAX_END_DEVICE_CHILDREN, this.stackConfig.MAX_END_DEVICE_CHILDREN);
|
|
694
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.APS_UNICAST_MESSAGE_COUNT, this.stackConfig.APS_UNICAST_MESSAGE_COUNT);
|
|
695
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.BROADCAST_TABLE_SIZE, this.stackConfig.BROADCAST_TABLE_SIZE);
|
|
696
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.NEIGHBOR_TABLE_SIZE, this.stackConfig.NEIGHBOR_TABLE_SIZE);
|
|
697
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.END_DEVICE_POLL_TIMEOUT, this.stackConfig.END_DEVICE_POLL_TIMEOUT);
|
|
698
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.TRANSIENT_KEY_TIMEOUT_S, this.stackConfig.TRANSIENT_KEY_TIMEOUT_S);
|
|
699
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.RETRY_QUEUE_SIZE, this.stackConfig.RETRY_QUEUE_SIZE);
|
|
700
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.SOURCE_ROUTE_TABLE_SIZE, this.stackConfig.SOURCE_ROUTE_TABLE_SIZE);
|
|
701
|
+
await this.emberSetEzspConfigValue(enums_2.EzspConfigId.MULTICAST_TABLE_SIZE, this.stackConfig.MULTICAST_TABLE_SIZE);
|
|
663
702
|
}
|
|
664
703
|
/**
|
|
665
704
|
* NCP concentrator init. Also enables source route discovery mode with RESCHEDULE.
|
|
@@ -677,17 +716,16 @@ class EmberAdapter extends __1.Adapter {
|
|
|
677
716
|
*/
|
|
678
717
|
async initNCPConcentrator() {
|
|
679
718
|
const status = (await this.ezsp.ezspSetConcentrator(true, (this.stackConfig.CONCENTRATOR_RAM_TYPE === 'low') ? consts_2.EMBER_LOW_RAM_CONCENTRATOR : consts_2.EMBER_HIGH_RAM_CONCENTRATOR, this.stackConfig.CONCENTRATOR_MIN_TIME, this.stackConfig.CONCENTRATOR_MAX_TIME, this.stackConfig.CONCENTRATOR_ROUTE_ERROR_THRESHOLD, this.stackConfig.CONCENTRATOR_DELIVERY_FAILURE_THRESHOLD, this.stackConfig.CONCENTRATOR_MAX_HOPS));
|
|
680
|
-
if (status !==
|
|
719
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
681
720
|
throw new Error(`[CONCENTRATOR] Failed to set concentrator with status=${status}.`);
|
|
682
721
|
}
|
|
683
|
-
const remainTilMTORR = (await this.ezsp.ezspSetSourceRouteDiscoveryMode(
|
|
722
|
+
const remainTilMTORR = (await this.ezsp.ezspSetSourceRouteDiscoveryMode(enums_3.EmberSourceRouteDiscoveryMode.RESCHEDULE));
|
|
684
723
|
logger_1.logger.info(`[CONCENTRATOR] Started source route discovery. ${remainTilMTORR}ms until next broadcast.`, NS);
|
|
685
724
|
}
|
|
686
725
|
/**
|
|
687
726
|
* Register fixed endpoints and set any related multicast entries that need to be.
|
|
688
727
|
*/
|
|
689
728
|
async registerFixedEndpoints() {
|
|
690
|
-
let mcTableIdx = 0;
|
|
691
729
|
for (const ep of endpoints_1.FIXED_ENDPOINTS) {
|
|
692
730
|
if (ep.networkIndex !== 0x00) {
|
|
693
731
|
logger_1.logger.debug(`Multi-network not currently supported. Skipping endpoint ${JSON.stringify(ep)}.`, NS);
|
|
@@ -695,16 +733,16 @@ class EmberAdapter extends __1.Adapter {
|
|
|
695
733
|
}
|
|
696
734
|
const [epStatus,] = (await this.ezsp.ezspGetEndpointFlags(ep.endpoint));
|
|
697
735
|
// endpoint not already registered
|
|
698
|
-
if (epStatus !==
|
|
736
|
+
if (epStatus !== enums_3.EzspStatus.SUCCESS) {
|
|
699
737
|
// check to see if ezspAddEndpoint needs to be called
|
|
700
738
|
// if ezspInit is called without NCP reset, ezspAddEndpoint is not necessary and will return an error
|
|
701
739
|
const status = (await this.ezsp.ezspAddEndpoint(ep.endpoint, ep.profileId, ep.deviceId, ep.deviceVersion, ep.inClusterList.slice(), // copy
|
|
702
740
|
ep.outClusterList.slice()));
|
|
703
|
-
if (status ===
|
|
704
|
-
logger_1.logger.debug(`Registered endpoint "${ep.endpoint}" with status=${
|
|
741
|
+
if (status === enums_3.EzspStatus.SUCCESS) {
|
|
742
|
+
logger_1.logger.debug(`Registered endpoint "${ep.endpoint}" with status=${enums_3.EzspStatus[status]}.`, NS);
|
|
705
743
|
}
|
|
706
744
|
else {
|
|
707
|
-
throw new Error(`Failed to register endpoint "${ep.endpoint}" with status=${
|
|
745
|
+
throw new Error(`Failed to register endpoint "${ep.endpoint}" with status=${enums_3.EzspStatus[status]}.`);
|
|
708
746
|
}
|
|
709
747
|
}
|
|
710
748
|
else {
|
|
@@ -716,11 +754,12 @@ class EmberAdapter extends __1.Adapter {
|
|
|
716
754
|
endpoint: ep.endpoint,
|
|
717
755
|
networkIndex: ep.networkIndex,
|
|
718
756
|
};
|
|
719
|
-
const status = (await this.ezsp.ezspSetMulticastTableEntry(
|
|
720
|
-
if (status !==
|
|
721
|
-
throw new Error(`Failed to register group "${multicastId}" in multicast table with status=${
|
|
757
|
+
const status = (await this.ezsp.ezspSetMulticastTableEntry(this.multicastTable.length, multicastEntry));
|
|
758
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
759
|
+
throw new Error(`Failed to register group "${multicastId}" in multicast table with status=${enums_3.EmberStatus[status]}.`);
|
|
722
760
|
}
|
|
723
|
-
logger_1.logger.debug(`Registered multicast table entry: ${JSON.stringify(multicastEntry)}.`, NS);
|
|
761
|
+
logger_1.logger.debug(`Registered multicast table entry (${this.multicastTable.length}): ${JSON.stringify(multicastEntry)}.`, NS);
|
|
762
|
+
this.multicastTable.push(multicastEntry.multicastId);
|
|
724
763
|
}
|
|
725
764
|
}
|
|
726
765
|
}
|
|
@@ -731,47 +770,47 @@ class EmberAdapter extends __1.Adapter {
|
|
|
731
770
|
async initTrustCenter() {
|
|
732
771
|
// init TC policies
|
|
733
772
|
{
|
|
734
|
-
let status = (await this.emberSetEzspPolicy(
|
|
735
|
-
if (status !==
|
|
773
|
+
let status = (await this.emberSetEzspPolicy(enums_2.EzspPolicyId.TC_KEY_REQUEST_POLICY, enums_2.EzspDecisionId.ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY));
|
|
774
|
+
if (status !== enums_3.EzspStatus.SUCCESS) {
|
|
736
775
|
throw new Error(`[INIT TC] Failed to set EzspPolicyId TC_KEY_REQUEST_POLICY to ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY `
|
|
737
|
-
+ `with status=${
|
|
776
|
+
+ `with status=${enums_3.EzspStatus[status]}.`);
|
|
738
777
|
}
|
|
739
|
-
const appKeyPolicy = this.stackConfig.KEY_TABLE_SIZE ?
|
|
740
|
-
status = (await this.emberSetEzspPolicy(
|
|
741
|
-
if (status !==
|
|
742
|
-
throw new Error(`[INIT TC] Failed to set EzspPolicyId APP_KEY_REQUEST_POLICY to ${
|
|
743
|
-
+ `with status=${
|
|
778
|
+
const appKeyPolicy = this.stackConfig.KEY_TABLE_SIZE ? enums_2.EzspDecisionId.ALLOW_APP_KEY_REQUESTS : enums_2.EzspDecisionId.DENY_APP_KEY_REQUESTS;
|
|
779
|
+
status = (await this.emberSetEzspPolicy(enums_2.EzspPolicyId.APP_KEY_REQUEST_POLICY, appKeyPolicy));
|
|
780
|
+
if (status !== enums_3.EzspStatus.SUCCESS) {
|
|
781
|
+
throw new Error(`[INIT TC] Failed to set EzspPolicyId APP_KEY_REQUEST_POLICY to ${enums_2.EzspDecisionId[appKeyPolicy]} `
|
|
782
|
+
+ `with status=${enums_3.EzspStatus[status]}.`);
|
|
744
783
|
}
|
|
745
|
-
status = (await this.emberSetJoinPolicy(
|
|
746
|
-
if (status !==
|
|
747
|
-
throw new Error(`[INIT TC] Failed to set join policy to USE_PRECONFIGURED_KEY with status=${
|
|
784
|
+
status = (await this.emberSetJoinPolicy(enums_3.EmberJoinDecision.USE_PRECONFIGURED_KEY));
|
|
785
|
+
if (status !== enums_3.EzspStatus.SUCCESS) {
|
|
786
|
+
throw new Error(`[INIT TC] Failed to set join policy to USE_PRECONFIGURED_KEY with status=${enums_3.EzspStatus[status]}.`);
|
|
748
787
|
}
|
|
749
788
|
}
|
|
750
789
|
const configNetworkKey = Buffer.from(this.networkOptions.networkKey);
|
|
751
790
|
const networkInitStruct = {
|
|
752
|
-
bitmask: (
|
|
791
|
+
bitmask: (enums_3.EmberNetworkInitBitmask.PARENT_INFO_IN_TOKEN | enums_3.EmberNetworkInitBitmask.END_DEVICE_REJOIN_ON_REBOOT)
|
|
753
792
|
};
|
|
754
793
|
const initStatus = (await this.ezsp.ezspNetworkInit(networkInitStruct));
|
|
755
|
-
logger_1.logger.debug(`[INIT TC] Network init status=${
|
|
756
|
-
if ((initStatus !==
|
|
757
|
-
throw new Error(`[INIT TC] Failed network init request with status=${
|
|
794
|
+
logger_1.logger.debug(`[INIT TC] Network init status=${enums_3.EmberStatus[initStatus]}.`, NS);
|
|
795
|
+
if ((initStatus !== enums_3.EmberStatus.SUCCESS) && (initStatus !== enums_3.EmberStatus.NOT_JOINED)) {
|
|
796
|
+
throw new Error(`[INIT TC] Failed network init request with status=${enums_3.EmberStatus[initStatus]}.`);
|
|
758
797
|
}
|
|
759
798
|
let action = NetworkInitAction.DONE;
|
|
760
|
-
if (initStatus ===
|
|
799
|
+
if (initStatus === enums_3.EmberStatus.SUCCESS) {
|
|
761
800
|
// network
|
|
762
801
|
await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_UP }, DEFAULT_NETWORK_REQUEST_TIMEOUT, '[INIT TC] Network init');
|
|
763
802
|
const [npStatus, nodeType, netParams] = (await this.ezsp.ezspGetNetworkParameters());
|
|
764
803
|
logger_1.logger.debug(`[INIT TC] Current network config=${JSON.stringify(this.networkOptions)}`, NS);
|
|
765
|
-
logger_1.logger.debug(`[INIT TC] Current NCP network: nodeType=${
|
|
766
|
-
if ((npStatus ===
|
|
804
|
+
logger_1.logger.debug(`[INIT TC] Current NCP network: nodeType=${enums_3.EmberNodeType[nodeType]} params=${JSON.stringify(netParams)}`, NS);
|
|
805
|
+
if ((npStatus === enums_3.EmberStatus.SUCCESS) && (nodeType === enums_3.EmberNodeType.COORDINATOR) && (this.networkOptions.panID === netParams.panId)
|
|
767
806
|
&& ((0, es6_1.default)(this.networkOptions.extendedPanID, netParams.extendedPanId))) {
|
|
768
807
|
// config matches adapter so far, no error, we can check the network key
|
|
769
808
|
const context = (0, initters_1.initSecurityManagerContext)();
|
|
770
|
-
context.coreKeyType =
|
|
809
|
+
context.coreKeyType = enums_3.SecManKeyType.NETWORK;
|
|
771
810
|
context.keyIndex = 0;
|
|
772
811
|
const [networkKey, nkStatus] = (await this.ezsp.ezspExportKey(context));
|
|
773
|
-
if (nkStatus !==
|
|
774
|
-
throw new Error(`[BACKUP] Failed to export Network Key with status=${
|
|
812
|
+
if (nkStatus !== enums_3.SLStatus.OK) {
|
|
813
|
+
throw new Error(`[BACKUP] Failed to export Network Key with status=${enums_3.SLStatus[nkStatus]}.`);
|
|
775
814
|
}
|
|
776
815
|
logger_1.logger.debug(`[INIT TC] Current NCP network: networkKey=${networkKey.contents.toString('hex')}`, NS);
|
|
777
816
|
// config doesn't match adapter anymore
|
|
@@ -786,8 +825,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
786
825
|
if (action === NetworkInitAction.LEAVE) {
|
|
787
826
|
logger_1.logger.info(`[INIT TC] NCP network does not match config. Leaving network...`, NS);
|
|
788
827
|
const leaveStatus = (await this.ezsp.ezspLeaveNetwork());
|
|
789
|
-
if (leaveStatus !==
|
|
790
|
-
throw new Error(`[INIT TC] Failed leave network request with status=${
|
|
828
|
+
if (leaveStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
829
|
+
throw new Error(`[INIT TC] Failed leave network request with status=${enums_3.EmberStatus[leaveStatus]}.`);
|
|
791
830
|
}
|
|
792
831
|
await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_DOWN }, DEFAULT_NETWORK_REQUEST_TIMEOUT, '[INIT TC] Leave network');
|
|
793
832
|
await (0, utils_1.Wait)(200); // settle down
|
|
@@ -795,7 +834,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
795
834
|
}
|
|
796
835
|
}
|
|
797
836
|
const backup = this.getStoredBackup();
|
|
798
|
-
if ((initStatus ===
|
|
837
|
+
if ((initStatus === enums_3.EmberStatus.NOT_JOINED) || (action === NetworkInitAction.LEFT)) {
|
|
799
838
|
// no network
|
|
800
839
|
if (backup != null) {
|
|
801
840
|
if ((this.networkOptions.panID === backup.networkOptions.panId)
|
|
@@ -877,30 +916,30 @@ class EmberAdapter extends __1.Adapter {
|
|
|
877
916
|
*/
|
|
878
917
|
async formNetwork(fromBackup, networkKey, networkKeySequenceNumber, panId, extendedPanId, radioChannel, tcLinkKey) {
|
|
879
918
|
const state = {
|
|
880
|
-
bitmask: (
|
|
881
|
-
|
|
|
882
|
-
|
|
|
919
|
+
bitmask: (enums_3.EmberInitialSecurityBitmask.TRUST_CENTER_GLOBAL_LINK_KEY | enums_3.EmberInitialSecurityBitmask.HAVE_PRECONFIGURED_KEY
|
|
920
|
+
| enums_3.EmberInitialSecurityBitmask.HAVE_NETWORK_KEY | enums_3.EmberInitialSecurityBitmask.TRUST_CENTER_USES_HASHED_LINK_KEY
|
|
921
|
+
| enums_3.EmberInitialSecurityBitmask.REQUIRE_ENCRYPTED_KEY),
|
|
883
922
|
preconfiguredKey: { contents: tcLinkKey },
|
|
884
923
|
networkKey: { contents: networkKey },
|
|
885
924
|
networkKeySequenceNumber: networkKeySequenceNumber,
|
|
886
|
-
preconfiguredTrustCenterEui64:
|
|
925
|
+
preconfiguredTrustCenterEui64: ZSpec.BLANK_EUI64,
|
|
887
926
|
};
|
|
888
927
|
if (fromBackup) {
|
|
889
|
-
state.bitmask |=
|
|
928
|
+
state.bitmask |= enums_3.EmberInitialSecurityBitmask.NO_FRAME_COUNTER_RESET;
|
|
890
929
|
}
|
|
891
930
|
let emberStatus = (await this.ezsp.ezspSetInitialSecurityState(state));
|
|
892
|
-
if (emberStatus !==
|
|
893
|
-
throw new Error(`[INIT FORM] Failed to set initial security state with status=${
|
|
931
|
+
if (emberStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
932
|
+
throw new Error(`[INIT FORM] Failed to set initial security state with status=${enums_3.EmberStatus[emberStatus]}.`);
|
|
894
933
|
}
|
|
895
|
-
const extended = (
|
|
934
|
+
const extended = (enums_3.EmberExtendedSecurityBitmask.JOINER_GLOBAL_LINK_KEY | enums_3.EmberExtendedSecurityBitmask.NWK_LEAVE_REQUEST_NOT_ALLOWED);
|
|
896
935
|
const extSecStatus = (await this.ezsp.ezspSetExtendedSecurityBitmask(extended));
|
|
897
|
-
if (extSecStatus !==
|
|
898
|
-
throw new Error(`[INIT FORM] Failed to set extended security bitmask to ${extended} with status=${
|
|
936
|
+
if (extSecStatus !== enums_3.EzspStatus.SUCCESS) {
|
|
937
|
+
throw new Error(`[INIT FORM] Failed to set extended security bitmask to ${extended} with status=${enums_3.EzspStatus[extSecStatus]}.`);
|
|
899
938
|
}
|
|
900
939
|
if (!fromBackup && this.stackConfig.KEY_TABLE_SIZE > 0) {
|
|
901
940
|
emberStatus = await this.ezsp.ezspClearKeyTable();
|
|
902
|
-
if (emberStatus !==
|
|
903
|
-
throw new Error(`[INIT FORM] Failed to clear key table with status=${
|
|
941
|
+
if (emberStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
942
|
+
throw new Error(`[INIT FORM] Failed to clear key table with status=${enums_3.EmberStatus[emberStatus]}.`);
|
|
904
943
|
}
|
|
905
944
|
}
|
|
906
945
|
const netParams = {
|
|
@@ -908,19 +947,19 @@ class EmberAdapter extends __1.Adapter {
|
|
|
908
947
|
extendedPanId,
|
|
909
948
|
radioTxPower: 5,
|
|
910
949
|
radioChannel,
|
|
911
|
-
joinMethod:
|
|
912
|
-
nwkManagerId:
|
|
950
|
+
joinMethod: enums_3.EmberJoinMethod.MAC_ASSOCIATION,
|
|
951
|
+
nwkManagerId: ZSpec.COORDINATOR_ADDRESS,
|
|
913
952
|
nwkUpdateId: 0,
|
|
914
953
|
channels: consts_2.EMBER_ALL_802_15_4_CHANNELS_MASK,
|
|
915
954
|
};
|
|
916
955
|
logger_1.logger.info(`[INIT FORM] Forming new network with: ${JSON.stringify(netParams)}`, NS);
|
|
917
956
|
emberStatus = (await this.ezsp.ezspFormNetwork(netParams));
|
|
918
|
-
if (emberStatus !==
|
|
919
|
-
throw new Error(`[INIT FORM] Failed form network request with status=${
|
|
957
|
+
if (emberStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
958
|
+
throw new Error(`[INIT FORM] Failed form network request with status=${enums_3.EmberStatus[emberStatus]}.`);
|
|
920
959
|
}
|
|
921
960
|
await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_NETWORK_UP }, DEFAULT_NETWORK_REQUEST_TIMEOUT, '[INIT FORM] Form network');
|
|
922
961
|
const stStatus = await this.ezsp.ezspStartWritingStackTokens();
|
|
923
|
-
logger_1.logger.debug(`[INIT FORM] Start writing stack tokens status=${
|
|
962
|
+
logger_1.logger.debug(`[INIT FORM] Start writing stack tokens status=${enums_3.EzspStatus[stStatus]}.`, NS);
|
|
924
963
|
logger_1.logger.info(`[INIT FORM] New network formed!`, NS);
|
|
925
964
|
}
|
|
926
965
|
/**
|
|
@@ -945,7 +984,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
945
984
|
throw new Error(`[BACKUP] Current backup file is not for EmberZNet stack.`);
|
|
946
985
|
}
|
|
947
986
|
if (data.metadata.internal.ezspVersion < BACKUP_OLDEST_SUPPORTED_EZSP_VERSION) {
|
|
948
|
-
|
|
987
|
+
(0, fs_1.renameSync)(this.backupPath, `${this.backupPath}.old`);
|
|
988
|
+
logger_1.logger.warning(`[BACKUP] Current backup file is from an unsupported EZSP version. Renaming and ignoring.`, NS);
|
|
989
|
+
return null;
|
|
949
990
|
}
|
|
950
991
|
return utils_1.BackupUtils.fromUnifiedBackup(data);
|
|
951
992
|
}
|
|
@@ -959,9 +1000,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
959
1000
|
* @return List of keys data with AES hashed keys
|
|
960
1001
|
*/
|
|
961
1002
|
async exportLinkKeys() {
|
|
962
|
-
const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(
|
|
963
|
-
if (confStatus !==
|
|
964
|
-
throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${
|
|
1003
|
+
const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_2.EzspConfigId.KEY_TABLE_SIZE));
|
|
1004
|
+
if (confStatus !== enums_3.EzspStatus.SUCCESS) {
|
|
1005
|
+
throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${enums_3.EzspStatus[confStatus]}.`);
|
|
965
1006
|
}
|
|
966
1007
|
let deviceEui64;
|
|
967
1008
|
let plaintextKey;
|
|
@@ -970,14 +1011,14 @@ class EmberAdapter extends __1.Adapter {
|
|
|
970
1011
|
const keyList = [];
|
|
971
1012
|
for (let i = 0; i < keyTableSize; i++) {
|
|
972
1013
|
[deviceEui64, plaintextKey, apsKeyMeta, status] = (await this.ezsp.ezspExportLinkKeyByIndex(i));
|
|
973
|
-
logger_1.logger.debug(`[BACKUP] Export link key at index ${i}, status=${
|
|
1014
|
+
logger_1.logger.debug(`[BACKUP] Export link key at index ${i}, status=${enums_3.SLStatus[status]}.`, NS);
|
|
974
1015
|
// only include key if we could retrieve one at index and hash it properly
|
|
975
|
-
if (status ===
|
|
1016
|
+
if (status === enums_3.SLStatus.OK) {
|
|
976
1017
|
// Rather than give the real link key, the backup contains a hashed version of the key.
|
|
977
1018
|
// This is done to prevent a compromise of the backup data from compromising the current link keys.
|
|
978
1019
|
// This is per the Smart Energy spec.
|
|
979
1020
|
const [hashStatus, hashedKey] = (await this.emberAesHashSimple(plaintextKey.contents));
|
|
980
|
-
if (hashStatus ===
|
|
1021
|
+
if (hashStatus === enums_3.EmberStatus.SUCCESS) {
|
|
981
1022
|
keyList.push({
|
|
982
1023
|
deviceEui64,
|
|
983
1024
|
key: { contents: hashedKey },
|
|
@@ -987,7 +1028,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
987
1028
|
}
|
|
988
1029
|
else {
|
|
989
1030
|
// this should never happen?
|
|
990
|
-
logger_1.logger.error(`[BACKUP] Failed to hash link key at index ${i} with status=${
|
|
1031
|
+
logger_1.logger.error(`[BACKUP] Failed to hash link key at index ${i} with status=${enums_3.EmberStatus[hashStatus]}. Omitting from backup.`, NS);
|
|
991
1032
|
}
|
|
992
1033
|
}
|
|
993
1034
|
}
|
|
@@ -1003,16 +1044,16 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1003
1044
|
if (!backupData?.length) {
|
|
1004
1045
|
return;
|
|
1005
1046
|
}
|
|
1006
|
-
const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(
|
|
1007
|
-
if (confStatus !==
|
|
1008
|
-
throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${
|
|
1047
|
+
const [confStatus, keyTableSize] = (await this.ezsp.ezspGetConfigurationValue(enums_2.EzspConfigId.KEY_TABLE_SIZE));
|
|
1048
|
+
if (confStatus !== enums_3.EzspStatus.SUCCESS) {
|
|
1049
|
+
throw new Error(`[BACKUP] Failed to retrieve key table size from NCP with status=${enums_3.EzspStatus[confStatus]}.`);
|
|
1009
1050
|
}
|
|
1010
1051
|
if (backupData.length > keyTableSize) {
|
|
1011
1052
|
throw new Error(`[BACKUP] Current key table of ${keyTableSize} is too small to import backup of ${backupData.length}!`);
|
|
1012
1053
|
}
|
|
1013
1054
|
const networkStatus = (await this.emberNetworkState());
|
|
1014
|
-
if (networkStatus !==
|
|
1015
|
-
throw new Error(`[BACKUP] Cannot import TC data while network is up, networkStatus=${
|
|
1055
|
+
if (networkStatus !== enums_3.EmberNetworkStatus.NO_NETWORK) {
|
|
1056
|
+
throw new Error(`[BACKUP] Cannot import TC data while network is up, networkStatus=${enums_3.EmberNetworkStatus[networkStatus]}.`);
|
|
1016
1057
|
}
|
|
1017
1058
|
let status;
|
|
1018
1059
|
for (let i = 0; i < keyTableSize; i++) {
|
|
@@ -1022,11 +1063,11 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1022
1063
|
}
|
|
1023
1064
|
else {
|
|
1024
1065
|
const importStatus = (await this.ezsp.ezspImportLinkKey(i, backupData[i].deviceEui64, backupData[i].key));
|
|
1025
|
-
status = ((importStatus ===
|
|
1066
|
+
status = ((importStatus === enums_3.SLStatus.OK) ? enums_3.EmberStatus.SUCCESS : enums_3.EmberStatus.KEY_TABLE_INVALID_ADDRESS);
|
|
1026
1067
|
}
|
|
1027
|
-
if (status !==
|
|
1068
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
1028
1069
|
throw new Error(`[BACKUP] Failed to ${((i >= backupData.length) ? "erase" : "set")} key table entry at index ${i} `
|
|
1029
|
-
+ `with status=${
|
|
1070
|
+
+ `with status=${enums_3.EmberStatus[status]}`);
|
|
1030
1071
|
}
|
|
1031
1072
|
}
|
|
1032
1073
|
logger_1.logger.info(`[BACKUP] Imported ${backupData.length} keys.`, NS);
|
|
@@ -1043,17 +1084,17 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1043
1084
|
logger_1.logger.warning(`[TRUST CENTER] Performing a network key update. This might take a while and disrupt normal operation.`, NS);
|
|
1044
1085
|
// zero-filled = let stack generate new random network key
|
|
1045
1086
|
let status = await this.ezsp.ezspBroadcastNextNetworkKey({ contents: Buffer.alloc(consts_1.EMBER_ENCRYPTION_KEY_SIZE) });
|
|
1046
|
-
if (status !==
|
|
1047
|
-
logger_1.logger.error(`[TRUST CENTER] Failed to broadcast next network key with status=${
|
|
1087
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
1088
|
+
logger_1.logger.error(`[TRUST CENTER] Failed to broadcast next network key with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
1048
1089
|
return status;
|
|
1049
1090
|
}
|
|
1050
1091
|
// XXX: this will block other requests for a while, but should ensure the key propagates without interference?
|
|
1051
1092
|
// could also stop dispatching entirely and do this outside the queue if necessary/better
|
|
1052
1093
|
await (0, utils_1.Wait)(BROADCAST_NETWORK_KEY_SWITCH_WAIT_TIME);
|
|
1053
1094
|
status = (await this.ezsp.ezspBroadcastNetworkKeySwitch());
|
|
1054
|
-
if (status !==
|
|
1095
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
1055
1096
|
// XXX: Not sure how likely this is, but this is bad, probably should hard fail?
|
|
1056
|
-
logger_1.logger.error(`[TRUST CENTER] Failed to broadcast network key switch with status=${
|
|
1097
|
+
logger_1.logger.error(`[TRUST CENTER] Failed to broadcast network key switch with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
1057
1098
|
return status;
|
|
1058
1099
|
}
|
|
1059
1100
|
resolve();
|
|
@@ -1066,7 +1107,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1066
1107
|
* @param status
|
|
1067
1108
|
*/
|
|
1068
1109
|
async onNcpNeedsResetAndInit(status) {
|
|
1069
|
-
logger_1.logger.error(`!!! NCP FATAL ERROR reason=${
|
|
1110
|
+
logger_1.logger.error(`!!! NCP FATAL ERROR reason=${enums_3.EzspStatus[status]}. ATTEMPTING RESET... !!!`, NS);
|
|
1070
1111
|
try {
|
|
1071
1112
|
await this.stop();
|
|
1072
1113
|
await (0, utils_1.Wait)(500); // just because
|
|
@@ -1104,7 +1145,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1104
1145
|
* Check against BLANK_EUI64 for validity.
|
|
1105
1146
|
*/
|
|
1106
1147
|
async emberGetEui64() {
|
|
1107
|
-
if (this.networkCache.eui64 ===
|
|
1148
|
+
if (this.networkCache.eui64 === ZSpec.BLANK_EUI64) {
|
|
1108
1149
|
this.networkCache.eui64 = (await this.ezsp.ezspGetEui64());
|
|
1109
1150
|
}
|
|
1110
1151
|
return this.networkCache.eui64;
|
|
@@ -1115,13 +1156,13 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1115
1156
|
* Check against INVALID_PAN_ID for validity.
|
|
1116
1157
|
*/
|
|
1117
1158
|
async emberGetPanId() {
|
|
1118
|
-
if (this.networkCache.parameters.panId ===
|
|
1159
|
+
if (this.networkCache.parameters.panId === ZSpec.INVALID_PAN_ID) {
|
|
1119
1160
|
const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
|
|
1120
|
-
if (status ===
|
|
1161
|
+
if (status === enums_3.EmberStatus.SUCCESS) {
|
|
1121
1162
|
this.networkCache.parameters = parameters;
|
|
1122
1163
|
}
|
|
1123
1164
|
else {
|
|
1124
|
-
logger_1.logger.error(`Failed to get PAN ID (via network parameters) with status=${
|
|
1165
|
+
logger_1.logger.error(`Failed to get PAN ID (via network parameters) with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
1125
1166
|
}
|
|
1126
1167
|
}
|
|
1127
1168
|
return this.networkCache.parameters.panId;
|
|
@@ -1132,13 +1173,13 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1132
1173
|
* Check against BLANK_EXTENDED_PAN_ID for validity.
|
|
1133
1174
|
*/
|
|
1134
1175
|
async emberGetExtendedPanId() {
|
|
1135
|
-
if ((0, es6_1.default)(this.networkCache.parameters.extendedPanId,
|
|
1176
|
+
if ((0, es6_1.default)(this.networkCache.parameters.extendedPanId, ZSpec.BLANK_EXTENDED_PAN_ID)) {
|
|
1136
1177
|
const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
|
|
1137
|
-
if (status ===
|
|
1178
|
+
if (status === enums_3.EmberStatus.SUCCESS) {
|
|
1138
1179
|
this.networkCache.parameters = parameters;
|
|
1139
1180
|
}
|
|
1140
1181
|
else {
|
|
1141
|
-
logger_1.logger.error(`Failed to get Extended PAN ID (via network parameters) with status=${
|
|
1182
|
+
logger_1.logger.error(`Failed to get Extended PAN ID (via network parameters) with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
1142
1183
|
}
|
|
1143
1184
|
}
|
|
1144
1185
|
return this.networkCache.parameters.extendedPanId;
|
|
@@ -1151,11 +1192,11 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1151
1192
|
async emberGetRadioChannel() {
|
|
1152
1193
|
if (this.networkCache.parameters.radioChannel === consts_2.INVALID_RADIO_CHANNEL) {
|
|
1153
1194
|
const [status, , parameters] = (await this.ezsp.ezspGetNetworkParameters());
|
|
1154
|
-
if (status ===
|
|
1195
|
+
if (status === enums_3.EmberStatus.SUCCESS) {
|
|
1155
1196
|
this.networkCache.parameters = parameters;
|
|
1156
1197
|
}
|
|
1157
1198
|
else {
|
|
1158
|
-
logger_1.logger.error(`Failed to get radio channel (via network parameters) with status=${
|
|
1199
|
+
logger_1.logger.error(`Failed to get radio channel (via network parameters) with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
1159
1200
|
}
|
|
1160
1201
|
}
|
|
1161
1202
|
return this.networkCache.parameters.radioChannel;
|
|
@@ -1164,14 +1205,14 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1164
1205
|
async emberStartEnergyScan() {
|
|
1165
1206
|
return new Promise((resolve, reject) => {
|
|
1166
1207
|
this.requestQueue.enqueue(async () => {
|
|
1167
|
-
const status = (await this.ezsp.ezspStartScan(
|
|
1168
|
-
if (status !==
|
|
1169
|
-
logger_1.logger.error(`Failed energy scan request with status=${
|
|
1170
|
-
return
|
|
1208
|
+
const status = (await this.ezsp.ezspStartScan(enums_3.EzspNetworkScanType.ENERGY_SCAN, consts_2.EMBER_ALL_802_15_4_CHANNELS_MASK, ENERGY_SCAN_DURATION));
|
|
1209
|
+
if (status !== enums_3.SLStatus.OK) {
|
|
1210
|
+
logger_1.logger.error(`Failed energy scan request with status=${enums_3.SLStatus[status]}.`, NS);
|
|
1211
|
+
return enums_3.EmberStatus.ERR_FATAL;
|
|
1171
1212
|
}
|
|
1172
1213
|
// TODO: result in logs only atm, since UI doesn't support it
|
|
1173
1214
|
resolve();
|
|
1174
|
-
return
|
|
1215
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
1175
1216
|
}, reject);
|
|
1176
1217
|
});
|
|
1177
1218
|
}
|
|
@@ -1202,17 +1243,17 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1202
1243
|
}
|
|
1203
1244
|
logger_1.logger.debug(`NCP info: EZSPVersion=${ncpEzspProtocolVer} StackType=${ncpStackType} StackVersion=${ncpStackVer}`, NS);
|
|
1204
1245
|
const [status, versionStruct] = (await this.ezsp.ezspGetVersionStruct());
|
|
1205
|
-
if (status !==
|
|
1246
|
+
if (status !== enums_3.EzspStatus.SUCCESS) {
|
|
1206
1247
|
// Should never happen with support of only EZSP v13+
|
|
1207
1248
|
throw new Error(`NCP has old-style version number. Not supported.`);
|
|
1208
1249
|
}
|
|
1209
1250
|
this.version = {
|
|
1210
1251
|
ezsp: ncpEzspProtocolVer,
|
|
1211
|
-
revision: `${versionStruct.major}.${versionStruct.minor}.${versionStruct.patch} [${
|
|
1252
|
+
revision: `${versionStruct.major}.${versionStruct.minor}.${versionStruct.patch} [${enums_3.EmberVersionType[versionStruct.type]}]`,
|
|
1212
1253
|
...versionStruct,
|
|
1213
1254
|
};
|
|
1214
|
-
if (versionStruct.type !==
|
|
1215
|
-
logger_1.logger.warning(`NCP is running a non-GA version (${
|
|
1255
|
+
if (versionStruct.type !== enums_3.EmberVersionType.GA) {
|
|
1256
|
+
logger_1.logger.warning(`NCP is running a non-GA version (${enums_3.EmberVersionType[versionStruct.type]}).`, NS);
|
|
1216
1257
|
}
|
|
1217
1258
|
logger_1.logger.debug(`NCP version info: ${JSON.stringify(this.version)}`, NS);
|
|
1218
1259
|
}
|
|
@@ -1226,13 +1267,13 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1226
1267
|
*/
|
|
1227
1268
|
async emberSetEzspConfigValue(configId, value) {
|
|
1228
1269
|
const status = (await this.ezsp.ezspSetConfigurationValue(configId, value));
|
|
1229
|
-
logger_1.logger.debug(`[EzspConfigId] SET "${
|
|
1230
|
-
if (status ===
|
|
1270
|
+
logger_1.logger.debug(`[EzspConfigId] SET "${enums_2.EzspConfigId[configId]}" TO "${value}" with status=${enums_3.EzspStatus[status]}.`, NS);
|
|
1271
|
+
if (status === enums_3.EzspStatus.ERROR_INVALID_ID) {
|
|
1231
1272
|
// can be ZLL where not all NCPs need or support it.
|
|
1232
|
-
logger_1.logger.warning(`[EzspConfigId] Unsupported configuration ID ${
|
|
1273
|
+
logger_1.logger.warning(`[EzspConfigId] Unsupported configuration ID ${enums_2.EzspConfigId[configId]} by NCP.`, NS);
|
|
1233
1274
|
}
|
|
1234
|
-
else if (status !==
|
|
1235
|
-
logger_1.logger.warning(`[EzspConfigId] Failed to SET "${
|
|
1275
|
+
else if (status !== enums_3.EzspStatus.SUCCESS) {
|
|
1276
|
+
logger_1.logger.warning(`[EzspConfigId] Failed to SET "${enums_2.EzspConfigId[configId]}" TO "${value}" with status=${enums_3.EzspStatus[status]}. `
|
|
1236
1277
|
+ `Firmware value will be used instead.`, NS);
|
|
1237
1278
|
}
|
|
1238
1279
|
return status;
|
|
@@ -1246,7 +1287,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1246
1287
|
*/
|
|
1247
1288
|
async emberSetEzspValue(valueId, valueLength, value) {
|
|
1248
1289
|
const status = (await this.ezsp.ezspSetValue(valueId, valueLength, value));
|
|
1249
|
-
logger_1.logger.debug(`[EzspValueId] SET "${
|
|
1290
|
+
logger_1.logger.debug(`[EzspValueId] SET "${enums_2.EzspValueId[valueId]}" TO "${value}" with status=${enums_3.EzspStatus[status]}.`, NS);
|
|
1250
1291
|
return status;
|
|
1251
1292
|
}
|
|
1252
1293
|
/**
|
|
@@ -1257,7 +1298,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1257
1298
|
*/
|
|
1258
1299
|
async emberSetEzspPolicy(policyId, decisionId) {
|
|
1259
1300
|
const status = (await this.ezsp.ezspSetPolicy(policyId, decisionId));
|
|
1260
|
-
logger_1.logger.debug(`[EzspPolicyId] SET "${
|
|
1301
|
+
logger_1.logger.debug(`[EzspPolicyId] SET "${enums_2.EzspPolicyId[policyId]}" TO "${decisionId}" with status=${enums_3.EzspStatus[status]}.`, NS);
|
|
1261
1302
|
return status;
|
|
1262
1303
|
}
|
|
1263
1304
|
/**
|
|
@@ -1273,7 +1314,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1273
1314
|
*/
|
|
1274
1315
|
async aesMmoHash(context, finalize, data) {
|
|
1275
1316
|
if (data.length > 255) {
|
|
1276
|
-
throw new Error(
|
|
1317
|
+
throw new Error(enums_3.EzspStatus[enums_3.EzspStatus.ERROR_INVALID_CALL]);
|
|
1277
1318
|
}
|
|
1278
1319
|
const [status, reContext] = (await this.ezsp.ezspAesMmoHash(context, finalize, data));
|
|
1279
1320
|
return [status, reContext];
|
|
@@ -1352,7 +1393,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1352
1393
|
logger_1.logger.debug(`Permit joining for ${duration} sec. status=${[status]}`, NS);
|
|
1353
1394
|
if (broadcastMgmtPermitJoin) {
|
|
1354
1395
|
// `authentication`: TC significance always 1 (zb specs)
|
|
1355
|
-
[status, apsFrame, messageTag] = (await this.emberPermitJoiningRequest(
|
|
1396
|
+
[status, apsFrame, messageTag] = (await this.emberPermitJoiningRequest(enums_1.BroadcastAddress.DEFAULT, duration, 1, DEFAULT_APS_OPTIONS));
|
|
1356
1397
|
}
|
|
1357
1398
|
return [status, apsFrame, messageTag];
|
|
1358
1399
|
}
|
|
@@ -1362,17 +1403,17 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1362
1403
|
* @returns
|
|
1363
1404
|
*/
|
|
1364
1405
|
async emberSetJoinPolicy(decision) {
|
|
1365
|
-
let policy =
|
|
1366
|
-
if (decision ==
|
|
1367
|
-
policy = (
|
|
1406
|
+
let policy = enums_2.EzspDecisionBitmask.DEFAULT_CONFIGURATION;
|
|
1407
|
+
if (decision == enums_3.EmberJoinDecision.USE_PRECONFIGURED_KEY) {
|
|
1408
|
+
policy = (enums_2.EzspDecisionBitmask.ALLOW_JOINS | enums_2.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS);
|
|
1368
1409
|
}
|
|
1369
|
-
else if (decision ==
|
|
1370
|
-
policy = (
|
|
1410
|
+
else if (decision == enums_3.EmberJoinDecision.SEND_KEY_IN_THE_CLEAR) {
|
|
1411
|
+
policy = (enums_2.EzspDecisionBitmask.ALLOW_JOINS | enums_2.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS | enums_2.EzspDecisionBitmask.SEND_KEY_IN_CLEAR);
|
|
1371
1412
|
}
|
|
1372
|
-
else if (decision ==
|
|
1373
|
-
policy =
|
|
1413
|
+
else if (decision == enums_3.EmberJoinDecision.ALLOW_REJOINS_ONLY) {
|
|
1414
|
+
policy = enums_2.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS;
|
|
1374
1415
|
}
|
|
1375
|
-
return this.emberSetEzspPolicy(
|
|
1416
|
+
return this.emberSetEzspPolicy(enums_2.EzspPolicyId.TRUST_CENTER_POLICY, policy);
|
|
1376
1417
|
}
|
|
1377
1418
|
/**
|
|
1378
1419
|
* Get Source Route Overhead
|
|
@@ -1389,11 +1430,11 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1389
1430
|
*/
|
|
1390
1431
|
async emberGetSourceRouteOverhead(destination) {
|
|
1391
1432
|
const [status, value] = (await this.ezsp.ezspGetSourceRouteOverhead(destination));
|
|
1392
|
-
if (status ===
|
|
1433
|
+
if (status === enums_3.EzspStatus.SUCCESS) {
|
|
1393
1434
|
return value;
|
|
1394
1435
|
}
|
|
1395
1436
|
else {
|
|
1396
|
-
logger_1.logger.debug(`Failed to get source route overhead (via extended value), status=${
|
|
1437
|
+
logger_1.logger.debug(`Failed to get source route overhead (via extended value), status=${enums_3.EzspStatus[status]}.`, NS);
|
|
1397
1438
|
}
|
|
1398
1439
|
return 0;
|
|
1399
1440
|
}
|
|
@@ -1414,34 +1455,34 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1414
1455
|
async maximumApsPayloadLength(type, indexOrDestination, apsFrame) {
|
|
1415
1456
|
let destination = consts_2.EMBER_UNKNOWN_NODE_ID;
|
|
1416
1457
|
let max = consts_2.MAXIMUM_APS_PAYLOAD_LENGTH; // uint8_t
|
|
1417
|
-
if ((apsFrame.options &
|
|
1458
|
+
if ((apsFrame.options & enums_3.EmberApsOption.ENCRYPTION) !== 0) {
|
|
1418
1459
|
max -= consts_2.APS_ENCRYPTION_OVERHEAD;
|
|
1419
1460
|
}
|
|
1420
|
-
if ((apsFrame.options &
|
|
1461
|
+
if ((apsFrame.options & enums_3.EmberApsOption.SOURCE_EUI64) !== 0) {
|
|
1421
1462
|
max -= consts_1.EUI64_SIZE;
|
|
1422
1463
|
}
|
|
1423
|
-
if ((apsFrame.options &
|
|
1464
|
+
if ((apsFrame.options & enums_3.EmberApsOption.DESTINATION_EUI64) !== 0) {
|
|
1424
1465
|
max -= consts_1.EUI64_SIZE;
|
|
1425
1466
|
}
|
|
1426
|
-
if ((apsFrame.options &
|
|
1467
|
+
if ((apsFrame.options & enums_3.EmberApsOption.FRAGMENT) !== 0) {
|
|
1427
1468
|
max -= consts_2.APS_FRAGMENTATION_OVERHEAD;
|
|
1428
1469
|
}
|
|
1429
1470
|
switch (type) {
|
|
1430
|
-
case
|
|
1471
|
+
case enums_3.EmberOutgoingMessageType.DIRECT:
|
|
1431
1472
|
destination = indexOrDestination;
|
|
1432
1473
|
break;
|
|
1433
|
-
case
|
|
1474
|
+
case enums_3.EmberOutgoingMessageType.VIA_ADDRESS_TABLE:
|
|
1434
1475
|
destination = (await this.ezsp.ezspGetAddressTableRemoteNodeId(indexOrDestination));
|
|
1435
1476
|
break;
|
|
1436
|
-
case
|
|
1477
|
+
case enums_3.EmberOutgoingMessageType.VIA_BINDING:
|
|
1437
1478
|
destination = (await this.ezsp.ezspGetBindingRemoteNodeId(indexOrDestination));
|
|
1438
1479
|
break;
|
|
1439
|
-
case
|
|
1480
|
+
case enums_3.EmberOutgoingMessageType.MULTICAST:
|
|
1440
1481
|
// APS multicast messages include the two-byte group id and exclude the one-byte destination endpoint,
|
|
1441
1482
|
// for a net loss of an extra byte.
|
|
1442
1483
|
max--;
|
|
1443
1484
|
break;
|
|
1444
|
-
case
|
|
1485
|
+
case enums_3.EmberOutgoingMessageType.BROADCAST:
|
|
1445
1486
|
break;
|
|
1446
1487
|
default:
|
|
1447
1488
|
break;
|
|
@@ -1495,7 +1536,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1495
1536
|
*/
|
|
1496
1537
|
async sendZDORequestBuffer(destination, clusterId, options) {
|
|
1497
1538
|
if (this.zdoRequestBuffalo.getPosition() > consts_1.EZSP_MAX_FRAME_LENGTH) {
|
|
1498
|
-
return [
|
|
1539
|
+
return [enums_3.EmberStatus.MESSAGE_TOO_LONG, null, null];
|
|
1499
1540
|
}
|
|
1500
1541
|
const messageTag = this.nextZDORequestSequence();
|
|
1501
1542
|
this.zdoRequestBuffalo.setCommandByte(0, messageTag);
|
|
@@ -1509,19 +1550,19 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1509
1550
|
sequence: 0, // set by stack
|
|
1510
1551
|
};
|
|
1511
1552
|
const messageContents = this.zdoRequestBuffalo.getWritten();
|
|
1512
|
-
if (destination ===
|
|
1513
|
-
|| destination ===
|
|
1553
|
+
if (destination === enums_1.BroadcastAddress.DEFAULT || destination === enums_1.BroadcastAddress.RX_ON_WHEN_IDLE
|
|
1554
|
+
|| destination === enums_1.BroadcastAddress.SLEEPY) {
|
|
1514
1555
|
logger_1.logger.debug(`~~~> [ZDO BROADCAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
|
|
1515
1556
|
const [status, apsSequence] = (await this.ezsp.ezspSendBroadcast(destination, apsFrame, this.getZDORequestRadius(), messageTag, messageContents));
|
|
1516
1557
|
apsFrame.sequence = apsSequence;
|
|
1517
|
-
logger_1.logger.debug(`~~~> [SENT ZDO type=BROADCAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${
|
|
1558
|
+
logger_1.logger.debug(`~~~> [SENT ZDO type=BROADCAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${enums_3.EmberStatus[status]}]`, NS);
|
|
1518
1559
|
return [status, apsFrame, messageTag];
|
|
1519
1560
|
}
|
|
1520
1561
|
else {
|
|
1521
1562
|
logger_1.logger.debug(`~~~> [ZDO UNICAST apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag}]`, NS);
|
|
1522
|
-
const [status, apsSequence] = (await this.ezsp.ezspSendUnicast(
|
|
1563
|
+
const [status, apsSequence] = (await this.ezsp.ezspSendUnicast(enums_3.EmberOutgoingMessageType.DIRECT, destination, apsFrame, messageTag, messageContents));
|
|
1523
1564
|
apsFrame.sequence = apsSequence;
|
|
1524
|
-
logger_1.logger.debug(`~~~> [SENT ZDO type=DIRECT apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${
|
|
1565
|
+
logger_1.logger.debug(`~~~> [SENT ZDO type=DIRECT apsFrame=${JSON.stringify(apsFrame)} messageTag=${messageTag} status=${enums_3.EmberStatus[status]}]`, NS);
|
|
1525
1566
|
return [status, apsFrame, messageTag];
|
|
1526
1567
|
}
|
|
1527
1568
|
}
|
|
@@ -1554,7 +1595,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1554
1595
|
const length = (zdo_1.ZDO_MESSAGE_OVERHEAD + 2 + 2 + 1 + (inClusters.length * 2) + 1 + (outClusters.length * 2));
|
|
1555
1596
|
// sanity check
|
|
1556
1597
|
if (length > consts_1.EZSP_MAX_FRAME_LENGTH) {
|
|
1557
|
-
return [
|
|
1598
|
+
return [enums_3.EmberStatus.MESSAGE_TOO_LONG, null, null];
|
|
1558
1599
|
}
|
|
1559
1600
|
this.zdoRequestBuffalo.setPosition(zdo_1.ZDO_MESSAGE_OVERHEAD);
|
|
1560
1601
|
this.zdoRequestBuffalo.writeUInt16(target);
|
|
@@ -1589,7 +1630,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1589
1630
|
this.zdoRequestBuffalo.writeUInt8(reportKids ? 1 : 0);
|
|
1590
1631
|
this.zdoRequestBuffalo.writeUInt8(childStartIndex);
|
|
1591
1632
|
logger_1.logger.debug(`~~~> [ZDO NETWORK_ADDRESS_REQUEST target=${target} reportKids=${reportKids} childStartIndex=${childStartIndex}]`, NS);
|
|
1592
|
-
return this.sendZDORequestBuffer(
|
|
1633
|
+
return this.sendZDORequestBuffer(enums_1.BroadcastAddress.RX_ON_WHEN_IDLE, zdo_1.NETWORK_ADDRESS_REQUEST, enums_3.EmberApsOption.SOURCE_EUI64);
|
|
1593
1634
|
}
|
|
1594
1635
|
/**
|
|
1595
1636
|
* ZDO
|
|
@@ -1711,7 +1752,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
1711
1752
|
this.zdoRequestBuffalo.writeUInt16(groupAddress);
|
|
1712
1753
|
break;
|
|
1713
1754
|
default:
|
|
1714
|
-
return [
|
|
1755
|
+
return [enums_3.EmberStatus.ERR_FATAL, null, null];
|
|
1715
1756
|
}
|
|
1716
1757
|
return this.sendZDORequestBuffer(target, bindClusterId, options);
|
|
1717
1758
|
}
|
|
@@ -2022,7 +2063,6 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2022
2063
|
async start() {
|
|
2023
2064
|
logger_1.logger.info(`======== Ember Adapter Starting ========`, NS);
|
|
2024
2065
|
this.initVariables();
|
|
2025
|
-
logger_1.logger.debug(`Starting EZSP with stack configuration: "${this.stackConfig}".`, NS);
|
|
2026
2066
|
const result = await this.initEzsp();
|
|
2027
2067
|
return result;
|
|
2028
2068
|
}
|
|
@@ -2041,7 +2081,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2041
2081
|
const ieeeAddr = (await this.emberGetEui64());
|
|
2042
2082
|
resolve({
|
|
2043
2083
|
ieeeAddr,
|
|
2044
|
-
networkAddress:
|
|
2084
|
+
networkAddress: ZSpec.COORDINATOR_ADDRESS,
|
|
2045
2085
|
manufacturerID: DEFAULT_MANUFACTURER_CODE,
|
|
2046
2086
|
endpoints: endpoints_1.FIXED_ENDPOINTS.map((ep) => {
|
|
2047
2087
|
return {
|
|
@@ -2053,7 +2093,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2053
2093
|
};
|
|
2054
2094
|
}),
|
|
2055
2095
|
});
|
|
2056
|
-
return
|
|
2096
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2057
2097
|
}, reject);
|
|
2058
2098
|
});
|
|
2059
2099
|
}
|
|
@@ -2078,7 +2118,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2078
2118
|
this.requestQueue.enqueue(async () => {
|
|
2079
2119
|
// grab fresh version here, bypass cache
|
|
2080
2120
|
const [netStatus, , netParams] = (await this.ezsp.ezspGetNetworkParameters());
|
|
2081
|
-
if (netStatus !==
|
|
2121
|
+
if (netStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
2082
2122
|
logger_1.logger.error(`[BACKUP] Failed to get network parameters.`, NS);
|
|
2083
2123
|
return netStatus;
|
|
2084
2124
|
}
|
|
@@ -2086,10 +2126,10 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2086
2126
|
this.networkCache.parameters = netParams;
|
|
2087
2127
|
this.networkCache.eui64 = (await this.ezsp.ezspGetEui64());
|
|
2088
2128
|
const [netKeyStatus, netKeyInfo] = (await this.ezsp.ezspGetNetworkKeyInfo());
|
|
2089
|
-
if (netKeyStatus !==
|
|
2129
|
+
if (netKeyStatus !== enums_3.SLStatus.OK) {
|
|
2090
2130
|
logger_1.logger.error(`[BACKUP] Failed to get network keys info.`, NS);
|
|
2091
|
-
return ((netKeyStatus ===
|
|
2092
|
-
?
|
|
2131
|
+
return ((netKeyStatus === enums_3.SLStatus.BUSY) || (netKeyStatus === enums_3.SLStatus.NOT_READY))
|
|
2132
|
+
? enums_3.EmberStatus.NETWORK_BUSY : enums_3.EmberStatus.ERR_FATAL; // allow retry on statuses that should be temporary
|
|
2093
2133
|
}
|
|
2094
2134
|
if (!netKeyInfo.networkKeySet) {
|
|
2095
2135
|
throw new Error(`[BACKUP] No network key set.`);
|
|
@@ -2104,17 +2144,17 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2104
2144
|
// Buffer.from(this.networkCache.eui64.substring(2/*0x*/), 'hex').reverse()
|
|
2105
2145
|
// ));
|
|
2106
2146
|
let context = (0, initters_1.initSecurityManagerContext)();
|
|
2107
|
-
context.coreKeyType =
|
|
2147
|
+
context.coreKeyType = enums_3.SecManKeyType.TC_LINK;
|
|
2108
2148
|
const [tcLinkKey, tclkStatus] = (await this.ezsp.ezspExportKey(context));
|
|
2109
|
-
if (tclkStatus !==
|
|
2110
|
-
throw new Error(`[BACKUP] Failed to export TC Link Key with status=${
|
|
2149
|
+
if (tclkStatus !== enums_3.SLStatus.OK) {
|
|
2150
|
+
throw new Error(`[BACKUP] Failed to export TC Link Key with status=${enums_3.SLStatus[tclkStatus]}.`);
|
|
2111
2151
|
}
|
|
2112
2152
|
context = (0, initters_1.initSecurityManagerContext)(); // make sure it's back to zeroes
|
|
2113
|
-
context.coreKeyType =
|
|
2153
|
+
context.coreKeyType = enums_3.SecManKeyType.NETWORK;
|
|
2114
2154
|
context.keyIndex = 0;
|
|
2115
2155
|
const [networkKey, nkStatus] = (await this.ezsp.ezspExportKey(context));
|
|
2116
|
-
if (nkStatus !==
|
|
2117
|
-
throw new Error(`[BACKUP] Failed to export Network Key with status=${
|
|
2156
|
+
if (nkStatus !== enums_3.SLStatus.OK) {
|
|
2157
|
+
throw new Error(`[BACKUP] Failed to export Network Key with status=${enums_3.SLStatus[nkStatus]}.`);
|
|
2118
2158
|
}
|
|
2119
2159
|
const zbChannels = Array.from(Array(consts_2.EMBER_NUM_802_15_4_CHANNELS), (e, i) => i + consts_2.EMBER_MIN_802_15_4_CHANNEL_NUMBER);
|
|
2120
2160
|
resolve({
|
|
@@ -2150,7 +2190,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2150
2190
|
// altNetworkKey: altNetworkKey.contents,
|
|
2151
2191
|
}
|
|
2152
2192
|
});
|
|
2153
|
-
return
|
|
2193
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2154
2194
|
}, reject, true);
|
|
2155
2195
|
});
|
|
2156
2196
|
}
|
|
@@ -2169,7 +2209,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2169
2209
|
extendedPanID: parseInt(Buffer.from(extendedPanID).toString('hex'), 16),
|
|
2170
2210
|
channel,
|
|
2171
2211
|
});
|
|
2172
|
-
return
|
|
2212
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2173
2213
|
}, reject);
|
|
2174
2214
|
});
|
|
2175
2215
|
}
|
|
@@ -2182,15 +2222,15 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2182
2222
|
this.requestQueue.enqueue(async () => {
|
|
2183
2223
|
this.checkInterpanLock();
|
|
2184
2224
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2185
|
-
const [status, apsFrame, messageTag] = (await this.emberChannelChangeRequest(
|
|
2186
|
-
if (status !==
|
|
2187
|
-
logger_1.logger.error(`[ZDO] Failed broadcast channel change to "${newChannel}" with status=${
|
|
2225
|
+
const [status, apsFrame, messageTag] = (await this.emberChannelChangeRequest(enums_1.BroadcastAddress.SLEEPY, newChannel, DEFAULT_APS_OPTIONS));
|
|
2226
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2227
|
+
logger_1.logger.error(`[ZDO] Failed broadcast channel change to "${newChannel}" with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2188
2228
|
return status;
|
|
2189
2229
|
}
|
|
2190
2230
|
await this.oneWaitress.startWaitingForEvent({ eventName: oneWaitress_1.OneWaitressEvents.STACK_STATUS_CHANNEL_CHANGED }, DEFAULT_NETWORK_REQUEST_TIMEOUT * 2, // observed to ~9sec
|
|
2191
2231
|
'[ZDO] Change Channel');
|
|
2192
2232
|
resolve();
|
|
2193
|
-
return
|
|
2233
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2194
2234
|
}, reject);
|
|
2195
2235
|
});
|
|
2196
2236
|
}
|
|
@@ -2203,12 +2243,12 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2203
2243
|
return new Promise((resolve, reject) => {
|
|
2204
2244
|
this.requestQueue.enqueue(async () => {
|
|
2205
2245
|
const status = await this.ezsp.ezspSetRadioPower(value);
|
|
2206
|
-
if (status !==
|
|
2207
|
-
logger_1.logger.error(`Failed to set transmit power to ${value} status=${
|
|
2246
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2247
|
+
logger_1.logger.error(`Failed to set transmit power to ${value} status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2208
2248
|
return status;
|
|
2209
2249
|
}
|
|
2210
2250
|
resolve();
|
|
2211
|
-
return
|
|
2251
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2212
2252
|
}, reject);
|
|
2213
2253
|
});
|
|
2214
2254
|
}
|
|
@@ -2242,22 +2282,22 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2242
2282
|
this.requestQueue.enqueue(async () => {
|
|
2243
2283
|
// Compute the key from the install code and CRC.
|
|
2244
2284
|
const [aesStatus, keyContents] = (await this.emberAesHashSimple(key));
|
|
2245
|
-
if (aesStatus !==
|
|
2246
|
-
logger_1.logger.error(`[ADD INSTALL CODE] Failed AES hash for '${ieeeAddress}' with status=${
|
|
2285
|
+
if (aesStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
2286
|
+
logger_1.logger.error(`[ADD INSTALL CODE] Failed AES hash for '${ieeeAddress}' with status=${enums_3.EmberStatus[aesStatus]}.`, NS);
|
|
2247
2287
|
return aesStatus;
|
|
2248
2288
|
}
|
|
2249
2289
|
// Add the key to the transient key table.
|
|
2250
2290
|
// This will be used while the DUT joins.
|
|
2251
|
-
const impStatus = (await this.ezsp.ezspImportTransientKey(ieeeAddress, { contents: keyContents },
|
|
2252
|
-
if (impStatus ==
|
|
2291
|
+
const impStatus = (await this.ezsp.ezspImportTransientKey(ieeeAddress, { contents: keyContents }, enums_3.SecManFlag.NONE));
|
|
2292
|
+
if (impStatus == enums_3.SLStatus.OK) {
|
|
2253
2293
|
logger_1.logger.debug(`[ADD INSTALL CODE] Success for '${ieeeAddress}'.`, NS);
|
|
2254
2294
|
}
|
|
2255
2295
|
else {
|
|
2256
|
-
logger_1.logger.error(`[ADD INSTALL CODE] Failed for '${ieeeAddress}' with status=${
|
|
2257
|
-
return
|
|
2296
|
+
logger_1.logger.error(`[ADD INSTALL CODE] Failed for '${ieeeAddress}' with status=${enums_3.SLStatus[impStatus]}.`, NS);
|
|
2297
|
+
return enums_3.EmberStatus.ERR_FATAL;
|
|
2258
2298
|
}
|
|
2259
2299
|
resolve();
|
|
2260
|
-
return
|
|
2300
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2261
2301
|
}, reject);
|
|
2262
2302
|
});
|
|
2263
2303
|
}
|
|
@@ -2273,7 +2313,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2273
2313
|
sourceEndpoint: sourceEndpointInfo.endpoint,
|
|
2274
2314
|
destinationEndpoint: endpoint,
|
|
2275
2315
|
groupId: 0,
|
|
2276
|
-
options:
|
|
2316
|
+
options: enums_3.EmberApsOption.NONE,
|
|
2277
2317
|
},
|
|
2278
2318
|
zclSequence: transactionSequenceNumber,
|
|
2279
2319
|
commandIdentifier,
|
|
@@ -2289,17 +2329,17 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2289
2329
|
const preJoining = async () => {
|
|
2290
2330
|
if (seconds) {
|
|
2291
2331
|
const plaintextKey = { contents: Buffer.from(consts_2.ZIGBEE_PROFILE_INTEROPERABILITY_LINK_KEY) };
|
|
2292
|
-
const impKeyStatus = (await this.ezsp.ezspImportTransientKey(
|
|
2293
|
-
if (impKeyStatus !==
|
|
2294
|
-
logger_1.logger.error(`[ZDO] Failed import transient key with status=${
|
|
2295
|
-
return
|
|
2332
|
+
const impKeyStatus = (await this.ezsp.ezspImportTransientKey(ZSpec.BLANK_EUI64, plaintextKey, enums_3.SecManFlag.NONE));
|
|
2333
|
+
if (impKeyStatus !== enums_3.SLStatus.OK) {
|
|
2334
|
+
logger_1.logger.error(`[ZDO] Failed import transient key with status=${enums_3.SLStatus[impKeyStatus]}.`, NS);
|
|
2335
|
+
return enums_3.EmberStatus.ERR_FATAL;
|
|
2296
2336
|
}
|
|
2297
|
-
const setJPstatus = (await this.emberSetJoinPolicy(
|
|
2298
|
-
if (setJPstatus !==
|
|
2299
|
-
logger_1.logger.error(`[ZDO] Failed set join policy with status=${
|
|
2300
|
-
return
|
|
2337
|
+
const setJPstatus = (await this.emberSetJoinPolicy(enums_3.EmberJoinDecision.USE_PRECONFIGURED_KEY));
|
|
2338
|
+
if (setJPstatus !== enums_3.EzspStatus.SUCCESS) {
|
|
2339
|
+
logger_1.logger.error(`[ZDO] Failed set join policy with status=${enums_3.EzspStatus[setJPstatus]}.`, NS);
|
|
2340
|
+
return enums_3.EmberStatus.ERR_FATAL;
|
|
2301
2341
|
}
|
|
2302
|
-
return
|
|
2342
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2303
2343
|
}
|
|
2304
2344
|
else {
|
|
2305
2345
|
if (this.manufacturerCode !== DEFAULT_MANUFACTURER_CODE) {
|
|
@@ -2308,12 +2348,12 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2308
2348
|
this.manufacturerCode = DEFAULT_MANUFACTURER_CODE;
|
|
2309
2349
|
}
|
|
2310
2350
|
await this.ezsp.ezspClearTransientLinkKeys();
|
|
2311
|
-
const setJPstatus = (await this.emberSetJoinPolicy(
|
|
2312
|
-
if (setJPstatus !==
|
|
2313
|
-
logger_1.logger.error(`[ZDO] Failed set join policy for with status=${
|
|
2314
|
-
return
|
|
2351
|
+
const setJPstatus = (await this.emberSetJoinPolicy(enums_3.EmberJoinDecision.ALLOW_REJOINS_ONLY));
|
|
2352
|
+
if (setJPstatus !== enums_3.EzspStatus.SUCCESS) {
|
|
2353
|
+
logger_1.logger.error(`[ZDO] Failed set join policy for with status=${enums_3.EzspStatus[setJPstatus]}.`, NS);
|
|
2354
|
+
return enums_3.EmberStatus.ERR_FATAL;
|
|
2315
2355
|
}
|
|
2316
|
-
return
|
|
2356
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2317
2357
|
}
|
|
2318
2358
|
};
|
|
2319
2359
|
if (networkAddress) {
|
|
@@ -2322,15 +2362,15 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2322
2362
|
this.requestQueue.enqueue(async () => {
|
|
2323
2363
|
this.checkInterpanLock();
|
|
2324
2364
|
const pjStatus = (await preJoining());
|
|
2325
|
-
if (pjStatus !==
|
|
2326
|
-
logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${
|
|
2365
|
+
if (pjStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
2366
|
+
logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${enums_3.EmberStatus[pjStatus]}.`, NS);
|
|
2327
2367
|
return pjStatus;
|
|
2328
2368
|
}
|
|
2329
2369
|
// `authentication`: TC significance always 1 (zb specs)
|
|
2330
2370
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2331
2371
|
const [status, apsFrame, messageTag] = (await this.emberPermitJoiningRequest(networkAddress, seconds, 1, 0));
|
|
2332
|
-
if (status !==
|
|
2333
|
-
logger_1.logger.error(`[ZDO] Failed permit joining request for "${networkAddress}" with status=${
|
|
2372
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2373
|
+
logger_1.logger.error(`[ZDO] Failed permit joining request for "${networkAddress}" with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2334
2374
|
return status;
|
|
2335
2375
|
}
|
|
2336
2376
|
(await this.oneWaitress.startWaitingFor({
|
|
@@ -2339,7 +2379,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2339
2379
|
responseClusterId: zdo_1.PERMIT_JOINING_RESPONSE,
|
|
2340
2380
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT));
|
|
2341
2381
|
resolve();
|
|
2342
|
-
return
|
|
2382
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2343
2383
|
}, reject);
|
|
2344
2384
|
});
|
|
2345
2385
|
}
|
|
@@ -2349,15 +2389,15 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2349
2389
|
this.requestQueue.enqueue(async () => {
|
|
2350
2390
|
this.checkInterpanLock();
|
|
2351
2391
|
const pjStatus = (await preJoining());
|
|
2352
|
-
if (pjStatus !==
|
|
2353
|
-
logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${
|
|
2392
|
+
if (pjStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
2393
|
+
logger_1.logger.error(`[ZDO] Failed pre joining request for "${networkAddress}" with status=${enums_3.EmberStatus[pjStatus]}.`, NS);
|
|
2354
2394
|
return pjStatus;
|
|
2355
2395
|
}
|
|
2356
2396
|
// local permit join if `Coordinator`-only requested, else local + broadcast
|
|
2357
2397
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2358
|
-
const [status, apsFrame, messageTag] = (await this.emberPermitJoining(seconds, (networkAddress ===
|
|
2359
|
-
if (status !==
|
|
2360
|
-
logger_1.logger.error(`[ZDO] Failed permit joining request with status=${
|
|
2398
|
+
const [status, apsFrame, messageTag] = (await this.emberPermitJoining(seconds, (networkAddress === ZSpec.COORDINATOR_ADDRESS) ? false : true));
|
|
2399
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2400
|
+
logger_1.logger.error(`[ZDO] Failed permit joining request with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2361
2401
|
return status;
|
|
2362
2402
|
}
|
|
2363
2403
|
// NOTE: because Z2M is refreshing the permit join duration early to prevent it from closing
|
|
@@ -2378,7 +2418,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2378
2418
|
// // same kind of problem as described above (upstream always tries to close after start, but EZSP already is)
|
|
2379
2419
|
// }
|
|
2380
2420
|
resolve();
|
|
2381
|
-
return
|
|
2421
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2382
2422
|
}, reject);
|
|
2383
2423
|
});
|
|
2384
2424
|
}
|
|
@@ -2389,8 +2429,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2389
2429
|
const request = async (startIndex) => {
|
|
2390
2430
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2391
2431
|
const [reqStatus, apsFrame, messageTag] = (await this.emberLqiTableRequest(networkAddress, startIndex, DEFAULT_APS_OPTIONS));
|
|
2392
|
-
if (reqStatus !==
|
|
2393
|
-
logger_1.logger.error(`[ZDO] Failed LQI request for "${networkAddress}" (index "${startIndex}") with status=${
|
|
2432
|
+
if (reqStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
2433
|
+
logger_1.logger.error(`[ZDO] Failed LQI request for "${networkAddress}" (index "${startIndex}") with status=${enums_3.EmberStatus[reqStatus]}.`, NS);
|
|
2394
2434
|
return [reqStatus, null, null];
|
|
2395
2435
|
}
|
|
2396
2436
|
const result = (await this.oneWaitress.startWaitingFor({
|
|
@@ -2407,20 +2447,20 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2407
2447
|
depth: entry.depth,
|
|
2408
2448
|
});
|
|
2409
2449
|
}
|
|
2410
|
-
return [
|
|
2450
|
+
return [enums_3.EmberStatus.SUCCESS, result.neighborTableEntries, result.entryList.length];
|
|
2411
2451
|
};
|
|
2412
2452
|
return new Promise((resolve, reject) => {
|
|
2413
2453
|
this.requestQueue.enqueue(async () => {
|
|
2414
2454
|
this.checkInterpanLock();
|
|
2415
2455
|
let [status, tableEntries, entryCount] = (await request(0));
|
|
2416
|
-
if (status !==
|
|
2456
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2417
2457
|
return status;
|
|
2418
2458
|
}
|
|
2419
2459
|
const size = tableEntries;
|
|
2420
2460
|
let nextStartIndex = entryCount;
|
|
2421
2461
|
while (neighbors.length < size) {
|
|
2422
2462
|
[status, tableEntries, entryCount] = (await request(nextStartIndex));
|
|
2423
|
-
if (status !==
|
|
2463
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2424
2464
|
return status;
|
|
2425
2465
|
}
|
|
2426
2466
|
nextStartIndex += entryCount;
|
|
@@ -2436,8 +2476,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2436
2476
|
const request = async (startIndex) => {
|
|
2437
2477
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2438
2478
|
const [reqStatus, apsFrame, messageTag] = (await this.emberRoutingTableRequest(networkAddress, startIndex, DEFAULT_APS_OPTIONS));
|
|
2439
|
-
if (reqStatus !==
|
|
2440
|
-
logger_1.logger.error(`[ZDO] Failed routing table request for "${networkAddress}" (index "${startIndex}") with status=${
|
|
2479
|
+
if (reqStatus !== enums_3.EmberStatus.SUCCESS) {
|
|
2480
|
+
logger_1.logger.error(`[ZDO] Failed routing table request for "${networkAddress}" (index "${startIndex}") with status=${enums_3.EmberStatus[reqStatus]}.`, NS);
|
|
2441
2481
|
return [reqStatus, null, null];
|
|
2442
2482
|
}
|
|
2443
2483
|
const result = (await this.oneWaitress.startWaitingFor({
|
|
@@ -2452,26 +2492,26 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2452
2492
|
nextHop: entry.nextHopAddress,
|
|
2453
2493
|
});
|
|
2454
2494
|
}
|
|
2455
|
-
return [
|
|
2495
|
+
return [enums_3.EmberStatus.SUCCESS, result.routingTableEntries, result.entryList.length];
|
|
2456
2496
|
};
|
|
2457
2497
|
return new Promise((resolve, reject) => {
|
|
2458
2498
|
this.requestQueue.enqueue(async () => {
|
|
2459
2499
|
this.checkInterpanLock();
|
|
2460
2500
|
let [status, tableEntries, entryCount] = (await request(0));
|
|
2461
|
-
if (status !==
|
|
2501
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2462
2502
|
return status;
|
|
2463
2503
|
}
|
|
2464
2504
|
const size = tableEntries;
|
|
2465
2505
|
let nextStartIndex = entryCount;
|
|
2466
2506
|
while (table.length < size) {
|
|
2467
2507
|
[status, tableEntries, entryCount] = (await request(nextStartIndex));
|
|
2468
|
-
if (status !==
|
|
2508
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2469
2509
|
return status;
|
|
2470
2510
|
}
|
|
2471
2511
|
nextStartIndex += entryCount;
|
|
2472
2512
|
}
|
|
2473
2513
|
resolve({ table });
|
|
2474
|
-
return
|
|
2514
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2475
2515
|
}, reject);
|
|
2476
2516
|
});
|
|
2477
2517
|
}
|
|
@@ -2482,8 +2522,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2482
2522
|
this.checkInterpanLock();
|
|
2483
2523
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2484
2524
|
const [status, apsFrame, messageTag] = (await this.emberNodeDescriptorRequest(networkAddress, DEFAULT_APS_OPTIONS));
|
|
2485
|
-
if (status !==
|
|
2486
|
-
logger_1.logger.error(`[ZDO] Failed node descriptor for "${networkAddress}" with status=${
|
|
2525
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2526
|
+
logger_1.logger.error(`[ZDO] Failed node descriptor for "${networkAddress}" with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2487
2527
|
return status;
|
|
2488
2528
|
}
|
|
2489
2529
|
const result = (await this.oneWaitress.startWaitingFor({
|
|
@@ -2510,7 +2550,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2510
2550
|
+ `(current revision: ${CURRENT_ZIGBEE_SPEC_REVISION}).`, NS);
|
|
2511
2551
|
}
|
|
2512
2552
|
resolve({ type, manufacturerCode: result.manufacturerCode });
|
|
2513
|
-
return
|
|
2553
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2514
2554
|
}, reject);
|
|
2515
2555
|
});
|
|
2516
2556
|
}
|
|
@@ -2521,8 +2561,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2521
2561
|
this.checkInterpanLock();
|
|
2522
2562
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2523
2563
|
const [status, apsFrame, messageTag] = (await this.emberActiveEndpointsRequest(networkAddress, DEFAULT_APS_OPTIONS));
|
|
2524
|
-
if (status !==
|
|
2525
|
-
logger_1.logger.error(`[ZDO] Failed active endpoints request for "${networkAddress}" with status=${
|
|
2564
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2565
|
+
logger_1.logger.error(`[ZDO] Failed active endpoints request for "${networkAddress}" with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2526
2566
|
return status;
|
|
2527
2567
|
}
|
|
2528
2568
|
const result = (await this.oneWaitress.startWaitingFor({
|
|
@@ -2531,7 +2571,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2531
2571
|
responseClusterId: zdo_1.ACTIVE_ENDPOINTS_RESPONSE,
|
|
2532
2572
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT));
|
|
2533
2573
|
resolve({ endpoints: result.endpointList });
|
|
2534
|
-
return
|
|
2574
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2535
2575
|
}, reject);
|
|
2536
2576
|
});
|
|
2537
2577
|
}
|
|
@@ -2542,9 +2582,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2542
2582
|
this.checkInterpanLock();
|
|
2543
2583
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2544
2584
|
const [status, apsFrame, messageTag] = (await this.emberSimpleDescriptorRequest(networkAddress, endpointID, DEFAULT_APS_OPTIONS));
|
|
2545
|
-
if (status !==
|
|
2585
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2546
2586
|
logger_1.logger.error(`[ZDO] Failed simple descriptor request for "${networkAddress}" endpoint "${endpointID}" `
|
|
2547
|
-
+ `with status=${
|
|
2587
|
+
+ `with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2548
2588
|
return status;
|
|
2549
2589
|
}
|
|
2550
2590
|
const result = (await this.oneWaitress.startWaitingFor({
|
|
@@ -2559,7 +2599,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2559
2599
|
inputClusters: result.inClusterList,
|
|
2560
2600
|
outputClusters: result.outClusterList,
|
|
2561
2601
|
});
|
|
2562
|
-
return
|
|
2602
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2563
2603
|
}, reject);
|
|
2564
2604
|
});
|
|
2565
2605
|
}
|
|
@@ -2573,9 +2613,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2573
2613
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2574
2614
|
const [status, apsFrame, messageTag] = (await this.emberBindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.UNICAST_BINDING, destinationAddressOrGroup, null, // doesn't matter
|
|
2575
2615
|
destinationEndpoint, DEFAULT_APS_OPTIONS));
|
|
2576
|
-
if (status !==
|
|
2616
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2577
2617
|
logger_1.logger.error(`[ZDO] Failed bind request for "${destinationNetworkAddress}" destination "${destinationAddressOrGroup}" `
|
|
2578
|
-
+ `endpoint "${destinationEndpoint}" with status=${
|
|
2618
|
+
+ `endpoint "${destinationEndpoint}" with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2579
2619
|
return status;
|
|
2580
2620
|
}
|
|
2581
2621
|
await this.oneWaitress.startWaitingFor({
|
|
@@ -2584,7 +2624,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2584
2624
|
responseClusterId: zdo_1.BIND_RESPONSE,
|
|
2585
2625
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT);
|
|
2586
2626
|
resolve();
|
|
2587
|
-
return
|
|
2627
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2588
2628
|
}, reject);
|
|
2589
2629
|
});
|
|
2590
2630
|
}
|
|
@@ -2597,9 +2637,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2597
2637
|
const [status, apsFrame, messageTag] = (await this.emberBindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.MULTICAST_BINDING, null, // doesn't matter
|
|
2598
2638
|
destinationAddressOrGroup, destinationEndpoint, // doesn't matter
|
|
2599
2639
|
DEFAULT_APS_OPTIONS));
|
|
2600
|
-
if (status !==
|
|
2640
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2601
2641
|
logger_1.logger.error(`[ZDO] Failed bind request for "${destinationNetworkAddress}" group "${destinationAddressOrGroup}" `
|
|
2602
|
-
+ `with status=${
|
|
2642
|
+
+ `with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2603
2643
|
return status;
|
|
2604
2644
|
}
|
|
2605
2645
|
await this.oneWaitress.startWaitingFor({
|
|
@@ -2608,7 +2648,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2608
2648
|
responseClusterId: zdo_1.BIND_RESPONSE,
|
|
2609
2649
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT);
|
|
2610
2650
|
resolve();
|
|
2611
|
-
return
|
|
2651
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2612
2652
|
}, reject);
|
|
2613
2653
|
});
|
|
2614
2654
|
}
|
|
@@ -2623,9 +2663,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2623
2663
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2624
2664
|
const [status, apsFrame, messageTag] = (await this.emberUnbindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.UNICAST_BINDING, destinationAddressOrGroup, null, // doesn't matter
|
|
2625
2665
|
destinationEndpoint, DEFAULT_APS_OPTIONS));
|
|
2626
|
-
if (status !==
|
|
2666
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2627
2667
|
logger_1.logger.error(`[ZDO] Failed unbind request for "${destinationNetworkAddress}" destination "${destinationAddressOrGroup}" `
|
|
2628
|
-
+ `endpoint "${destinationEndpoint}" with status=${
|
|
2668
|
+
+ `endpoint "${destinationEndpoint}" with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2629
2669
|
return status;
|
|
2630
2670
|
}
|
|
2631
2671
|
await this.oneWaitress.startWaitingFor({
|
|
@@ -2634,7 +2674,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2634
2674
|
responseClusterId: zdo_1.UNBIND_RESPONSE,
|
|
2635
2675
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT);
|
|
2636
2676
|
resolve();
|
|
2637
|
-
return
|
|
2677
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2638
2678
|
}, reject);
|
|
2639
2679
|
});
|
|
2640
2680
|
}
|
|
@@ -2647,9 +2687,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2647
2687
|
const [status, apsFrame, messageTag] = (await this.emberUnbindRequest(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, zdo_1.MULTICAST_BINDING, null, // doesn't matter
|
|
2648
2688
|
destinationAddressOrGroup, destinationEndpoint, // doesn't matter
|
|
2649
2689
|
DEFAULT_APS_OPTIONS));
|
|
2650
|
-
if (status !==
|
|
2690
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2651
2691
|
logger_1.logger.error(`[ZDO] Failed unbind request for "${destinationNetworkAddress}" group "${destinationAddressOrGroup}" `
|
|
2652
|
-
+ `with status=${
|
|
2692
|
+
+ `with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2653
2693
|
return status;
|
|
2654
2694
|
}
|
|
2655
2695
|
await this.oneWaitress.startWaitingFor({
|
|
@@ -2658,7 +2698,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2658
2698
|
responseClusterId: zdo_1.UNBIND_RESPONSE,
|
|
2659
2699
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT);
|
|
2660
2700
|
resolve();
|
|
2661
|
-
return
|
|
2701
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2662
2702
|
}, reject);
|
|
2663
2703
|
});
|
|
2664
2704
|
}
|
|
@@ -2669,10 +2709,10 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2669
2709
|
this.requestQueue.enqueue(async () => {
|
|
2670
2710
|
this.checkInterpanLock();
|
|
2671
2711
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2672
|
-
const [status, apsFrame, messageTag] = (await this.emberLeaveRequest(networkAddress, ieeeAddr,
|
|
2673
|
-
if (status !==
|
|
2712
|
+
const [status, apsFrame, messageTag] = (await this.emberLeaveRequest(networkAddress, ieeeAddr, enums_3.EmberLeaveRequestFlags.WITHOUT_REJOIN, DEFAULT_APS_OPTIONS));
|
|
2713
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2674
2714
|
logger_1.logger.error(`[ZDO] Failed remove device request for "${networkAddress}" target "${ieeeAddr}" `
|
|
2675
|
-
+ `with status=${
|
|
2715
|
+
+ `with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2676
2716
|
return status;
|
|
2677
2717
|
}
|
|
2678
2718
|
await this.oneWaitress.startWaitingFor({
|
|
@@ -2681,7 +2721,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2681
2721
|
responseClusterId: zdo_1.LEAVE_RESPONSE,
|
|
2682
2722
|
}, DEFAULT_ZDO_REQUEST_TIMEOUT);
|
|
2683
2723
|
resolve();
|
|
2684
|
-
return
|
|
2724
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2685
2725
|
}, reject);
|
|
2686
2726
|
});
|
|
2687
2727
|
}
|
|
@@ -2709,24 +2749,24 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2709
2749
|
};
|
|
2710
2750
|
// don't RETRY if no response expected
|
|
2711
2751
|
if (commandResponseId == null) {
|
|
2712
|
-
apsFrame.options &= ~
|
|
2752
|
+
apsFrame.options &= ~enums_3.EmberApsOption.RETRY;
|
|
2713
2753
|
}
|
|
2714
2754
|
const data = zclFrame.toBuffer();
|
|
2715
2755
|
return new Promise((resolve, reject) => {
|
|
2716
2756
|
this.requestQueue.enqueue(async () => {
|
|
2717
2757
|
this.checkInterpanLock();
|
|
2718
2758
|
if (CHECK_APS_PAYLOAD_LENGTH) {
|
|
2719
|
-
const maxPayloadLength = (await this.maximumApsPayloadLength(
|
|
2759
|
+
const maxPayloadLength = (await this.maximumApsPayloadLength(enums_3.EmberOutgoingMessageType.DIRECT, networkAddress, apsFrame));
|
|
2720
2760
|
if (data.length > maxPayloadLength) {
|
|
2721
|
-
return
|
|
2761
|
+
return enums_3.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
|
|
2722
2762
|
}
|
|
2723
2763
|
}
|
|
2724
2764
|
logger_1.logger.debug(`~~~> [ZCL to=${networkAddress} apsFrame=${JSON.stringify(apsFrame)} header=${JSON.stringify(zclFrame.header)}]`, NS);
|
|
2725
2765
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2726
|
-
const [status, messageTag] = (await this.ezsp.send(
|
|
2766
|
+
const [status, messageTag] = (await this.ezsp.send(enums_3.EmberOutgoingMessageType.DIRECT, networkAddress, apsFrame, data, 0, // alias
|
|
2727
2767
|
0));
|
|
2728
|
-
if (status !==
|
|
2729
|
-
logger_1.logger.error(`~x~> [ZCL to=${networkAddress}] Failed to send request with status=${
|
|
2768
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2769
|
+
logger_1.logger.error(`~x~> [ZCL to=${networkAddress}] Failed to send request with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2730
2770
|
return status; // let queue handle retry based on status
|
|
2731
2771
|
}
|
|
2732
2772
|
if (commandResponseId != null) {
|
|
@@ -2741,7 +2781,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2741
2781
|
}
|
|
2742
2782
|
else {
|
|
2743
2783
|
resolve(null); // don't expect a response
|
|
2744
|
-
return
|
|
2784
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2745
2785
|
}
|
|
2746
2786
|
}, reject);
|
|
2747
2787
|
});
|
|
@@ -2764,23 +2804,23 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2764
2804
|
this.requestQueue.enqueue(async () => {
|
|
2765
2805
|
this.checkInterpanLock();
|
|
2766
2806
|
if (CHECK_APS_PAYLOAD_LENGTH) {
|
|
2767
|
-
const maxPayloadLength = (await this.maximumApsPayloadLength(
|
|
2807
|
+
const maxPayloadLength = (await this.maximumApsPayloadLength(enums_3.EmberOutgoingMessageType.MULTICAST, groupID, apsFrame));
|
|
2768
2808
|
if (data.length > maxPayloadLength) {
|
|
2769
|
-
return
|
|
2809
|
+
return enums_3.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
|
|
2770
2810
|
}
|
|
2771
2811
|
}
|
|
2772
2812
|
logger_1.logger.debug(`~~~> [ZCL GROUP apsFrame=${JSON.stringify(apsFrame)} header=${JSON.stringify(zclFrame.header)}]`, NS);
|
|
2773
2813
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2774
|
-
const [status, messageTag] = (await this.ezsp.send(
|
|
2814
|
+
const [status, messageTag] = (await this.ezsp.send(enums_3.EmberOutgoingMessageType.MULTICAST, apsFrame.groupId, // not used for MC
|
|
2775
2815
|
apsFrame, data, 0, // alias
|
|
2776
2816
|
0));
|
|
2777
|
-
if (status !==
|
|
2778
|
-
logger_1.logger.error(`~x~> [ZCL GROUP] Failed to send with status=${
|
|
2817
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2818
|
+
logger_1.logger.error(`~x~> [ZCL GROUP] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2779
2819
|
return status; // let queue handle retry based on status
|
|
2780
2820
|
}
|
|
2781
2821
|
// NOTE: since ezspMessageSentHandler could take a while here, we don't block, it'll just be logged if the delivery failed
|
|
2782
2822
|
resolve();
|
|
2783
|
-
return
|
|
2823
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2784
2824
|
}, reject);
|
|
2785
2825
|
});
|
|
2786
2826
|
}
|
|
@@ -2802,22 +2842,22 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2802
2842
|
this.requestQueue.enqueue(async () => {
|
|
2803
2843
|
this.checkInterpanLock();
|
|
2804
2844
|
if (CHECK_APS_PAYLOAD_LENGTH) {
|
|
2805
|
-
const maxPayloadLength = (await this.maximumApsPayloadLength(
|
|
2845
|
+
const maxPayloadLength = (await this.maximumApsPayloadLength(enums_3.EmberOutgoingMessageType.BROADCAST, destination, apsFrame));
|
|
2806
2846
|
if (data.length > maxPayloadLength) {
|
|
2807
|
-
return
|
|
2847
|
+
return enums_3.EmberStatus.MESSAGE_TOO_LONG; // queue will reject
|
|
2808
2848
|
}
|
|
2809
2849
|
}
|
|
2810
2850
|
logger_1.logger.debug(`~~~> [ZCL BROADCAST apsFrame=${JSON.stringify(apsFrame)} header=${JSON.stringify(zclFrame.header)}]`, NS);
|
|
2811
2851
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2812
|
-
const [status, messageTag] = (await this.ezsp.send(
|
|
2852
|
+
const [status, messageTag] = (await this.ezsp.send(enums_3.EmberOutgoingMessageType.BROADCAST, destination, apsFrame, data, 0, // alias
|
|
2813
2853
|
0));
|
|
2814
|
-
if (status !==
|
|
2815
|
-
logger_1.logger.error(`~x~> [ZCL BROADCAST] Failed to send with status=${
|
|
2854
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2855
|
+
logger_1.logger.error(`~x~> [ZCL BROADCAST] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2816
2856
|
return status; // let queue handle retry based on status
|
|
2817
2857
|
}
|
|
2818
2858
|
// NOTE: since ezspMessageSentHandler could take a while here, we don't block, it'll just be logged if the delivery failed
|
|
2819
2859
|
resolve();
|
|
2820
|
-
return
|
|
2860
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2821
2861
|
}, reject);
|
|
2822
2862
|
});
|
|
2823
2863
|
}
|
|
@@ -2834,9 +2874,9 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2834
2874
|
this.requestQueue.enqueue(async () => {
|
|
2835
2875
|
this.interpanLock = true;
|
|
2836
2876
|
const status = (await this.ezsp.ezspSetLogicalAndRadioChannel(channel));
|
|
2837
|
-
if (status !==
|
|
2877
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2838
2878
|
this.interpanLock = false; // XXX: ok?
|
|
2839
|
-
logger_1.logger.error(`Failed to set InterPAN channel to ${channel} with status=${
|
|
2879
|
+
logger_1.logger.error(`Failed to set InterPAN channel to ${channel} with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2840
2880
|
return status;
|
|
2841
2881
|
}
|
|
2842
2882
|
resolve();
|
|
@@ -2854,18 +2894,18 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2854
2894
|
const sourceEui64 = (await this.emberGetEui64());
|
|
2855
2895
|
msgBuffalo.writeUInt16((consts_2.LONG_DEST_FRAME_CONTROL | consts_2.MAC_ACK_REQUIRED)); // macFrameControl
|
|
2856
2896
|
msgBuffalo.writeUInt8(0); // sequence Skip Sequence number, stack sets the sequence number.
|
|
2857
|
-
msgBuffalo.writeUInt16(
|
|
2897
|
+
msgBuffalo.writeUInt16(ZSpec.INVALID_PAN_ID); // destPanId
|
|
2858
2898
|
msgBuffalo.writeIeeeAddr(ieeeAddress); // destAddress (longAddress)
|
|
2859
2899
|
msgBuffalo.writeUInt16(sourcePanId); // sourcePanId
|
|
2860
2900
|
msgBuffalo.writeIeeeAddr(sourceEui64); // sourceAddress
|
|
2861
2901
|
msgBuffalo.writeUInt16(consts_2.STUB_NWK_FRAME_CONTROL); // nwkFrameControl
|
|
2862
|
-
msgBuffalo.writeUInt8((
|
|
2902
|
+
msgBuffalo.writeUInt8((enums_3.EmberInterpanMessageType.UNICAST | consts_2.INTERPAN_APS_FRAME_TYPE)); // apsFrameControl
|
|
2863
2903
|
msgBuffalo.writeUInt16(zclFrame.cluster.ID);
|
|
2864
|
-
msgBuffalo.writeUInt16(
|
|
2904
|
+
msgBuffalo.writeUInt16(ZSpec.TOUCHLINK_PROFILE_ID);
|
|
2865
2905
|
logger_1.logger.debug(`~~~> [ZCL TOUCHLINK to=${ieeeAddress} header=${JSON.stringify(zclFrame.header)}]`, NS);
|
|
2866
2906
|
const status = (await this.ezsp.ezspSendRawMessage(Buffer.concat([msgBuffalo.getWritten(), zclFrame.toBuffer()])));
|
|
2867
|
-
if (status !==
|
|
2868
|
-
logger_1.logger.error(`~x~> [ZCL TOUCHLINK to=${ieeeAddress}] Failed to send with status=${
|
|
2907
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2908
|
+
logger_1.logger.error(`~x~> [ZCL TOUCHLINK to=${ieeeAddress}] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2869
2909
|
return status;
|
|
2870
2910
|
}
|
|
2871
2911
|
// NOTE: can use ezspRawTransmitCompleteHandler if needed here
|
|
@@ -2882,12 +2922,12 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2882
2922
|
}
|
|
2883
2923
|
// just for waitress
|
|
2884
2924
|
const apsFrame = {
|
|
2885
|
-
profileId:
|
|
2925
|
+
profileId: ZSpec.TOUCHLINK_PROFILE_ID,
|
|
2886
2926
|
clusterId: zclFrame.cluster.ID,
|
|
2887
2927
|
sourceEndpoint: 0,
|
|
2888
2928
|
destinationEndpoint: 0,
|
|
2889
|
-
options:
|
|
2890
|
-
groupId:
|
|
2929
|
+
options: enums_3.EmberApsOption.NONE,
|
|
2930
|
+
groupId: enums_1.BroadcastAddress.SLEEPY,
|
|
2891
2931
|
sequence: 0, // set by stack
|
|
2892
2932
|
};
|
|
2893
2933
|
return new Promise((resolve, reject) => {
|
|
@@ -2898,19 +2938,19 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2898
2938
|
const sourceEui64 = (await this.emberGetEui64());
|
|
2899
2939
|
msgBuffalo.writeUInt16(consts_2.SHORT_DEST_FRAME_CONTROL); // macFrameControl
|
|
2900
2940
|
msgBuffalo.writeUInt8(0); // sequence Skip Sequence number, stack sets the sequence number.
|
|
2901
|
-
msgBuffalo.writeUInt16(
|
|
2941
|
+
msgBuffalo.writeUInt16(ZSpec.INVALID_PAN_ID); // destPanId
|
|
2902
2942
|
msgBuffalo.writeUInt16(apsFrame.groupId); // destAddress (longAddress)
|
|
2903
2943
|
msgBuffalo.writeUInt16(sourcePanId); // sourcePanId
|
|
2904
2944
|
msgBuffalo.writeIeeeAddr(sourceEui64); // sourceAddress
|
|
2905
2945
|
msgBuffalo.writeUInt16(consts_2.STUB_NWK_FRAME_CONTROL); // nwkFrameControl
|
|
2906
|
-
msgBuffalo.writeUInt8((
|
|
2946
|
+
msgBuffalo.writeUInt8((enums_3.EmberInterpanMessageType.BROADCAST | consts_2.INTERPAN_APS_FRAME_TYPE)); // apsFrameControl
|
|
2907
2947
|
msgBuffalo.writeUInt16(apsFrame.clusterId);
|
|
2908
2948
|
msgBuffalo.writeUInt16(apsFrame.profileId);
|
|
2909
2949
|
const data = Buffer.concat([msgBuffalo.getWritten(), zclFrame.toBuffer()]);
|
|
2910
2950
|
logger_1.logger.debug(`~~~> [ZCL TOUCHLINK BROADCAST header=${JSON.stringify(zclFrame.header)}]`, NS);
|
|
2911
2951
|
const status = (await this.ezsp.ezspSendRawMessage(data));
|
|
2912
|
-
if (status !==
|
|
2913
|
-
logger_1.logger.error(`~x~> [ZCL TOUCHLINK BROADCAST] Failed to send with status=${
|
|
2952
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2953
|
+
logger_1.logger.error(`~x~> [ZCL TOUCHLINK BROADCAST] Failed to send with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2914
2954
|
return status;
|
|
2915
2955
|
}
|
|
2916
2956
|
// NOTE: can use ezspRawTransmitCompleteHandler if needed here
|
|
@@ -2921,7 +2961,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2921
2961
|
commandIdentifier: command.response,
|
|
2922
2962
|
}, timeout || DEFAULT_ZCL_REQUEST_TIMEOUT * 2)); // XXX: touchlink timeout?
|
|
2923
2963
|
resolve(result);
|
|
2924
|
-
return
|
|
2964
|
+
return enums_3.EmberStatus.SUCCESS;
|
|
2925
2965
|
}, reject);
|
|
2926
2966
|
});
|
|
2927
2967
|
}
|
|
@@ -2930,8 +2970,8 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2930
2970
|
return new Promise((resolve, reject) => {
|
|
2931
2971
|
this.requestQueue.enqueue(async () => {
|
|
2932
2972
|
const status = (await this.ezsp.ezspSetLogicalAndRadioChannel(this.networkOptions.channelList[0]));
|
|
2933
|
-
if (status !==
|
|
2934
|
-
logger_1.logger.error(`Failed to restore InterPAN channel to ${this.networkOptions.channelList[0]} with status=${
|
|
2973
|
+
if (status !== enums_3.EmberStatus.SUCCESS) {
|
|
2974
|
+
logger_1.logger.error(`Failed to restore InterPAN channel to ${this.networkOptions.channelList[0]} with status=${enums_3.EmberStatus[status]}.`, NS);
|
|
2935
2975
|
return status;
|
|
2936
2976
|
}
|
|
2937
2977
|
// let adapter settle down
|
|
@@ -2947,7 +2987,7 @@ class EmberAdapter extends __1.Adapter {
|
|
|
2947
2987
|
if (this.interpanLock) {
|
|
2948
2988
|
logger_1.logger.error(`[INTERPAN MODE] Cannot execute non-InterPAN commands.`, NS);
|
|
2949
2989
|
// will be caught by request queue and rejected internally.
|
|
2950
|
-
throw new Error(
|
|
2990
|
+
throw new Error(enums_3.EzspStatus[enums_3.EzspStatus.ERROR_INVALID_CALL]);
|
|
2951
2991
|
}
|
|
2952
2992
|
}
|
|
2953
2993
|
}
|