Skip to content

Commit

Permalink
fix: Ember: workaround: auto-register unknown multicasts in coordinat…
Browse files Browse the repository at this point in the history
…or (#1089)
  • Loading branch information
Nerivec authored Jun 14, 2024
1 parent 690408f commit f5e82bf
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 139 deletions.
142 changes: 90 additions & 52 deletions src/adapter/ember/adapter/emberAdapter.ts

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/adapter/ember/adapter/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Clusters} from '../../../zspec/zcl/definition/cluster';
import {GP_ENDPOINT, GP_PROFILE_ID, HA_PROFILE_ID} from '../consts';
import {GP_ENDPOINT, GP_PROFILE_ID, HA_PROFILE_ID} from '../../../zspec/consts';
import {ClusterId, EmberMulticastId, ProfileId} from '../types';


Expand Down Expand Up @@ -65,8 +65,7 @@ export const FIXED_ENDPOINTS: readonly FixedEndpointInfo[] = [
Clusters.touchlink.ID,// 0x1000, // touchlink
],
networkIndex: 0x00,
// Cluster spec 3.7.2.4.1: group identifier 0x0000 is reserved for the global scene used by the OnOff cluster.
// - IKEA sending state updates via MULTICAST(0x0000) https://github.com/Koenkk/zigbee-herdsman/issues/954
// - Cluster spec 3.7.2.4.1: group identifier 0x0000 is reserved for the global scene used by the OnOff cluster.
// - 901: defaultBindGroup
multicastIds: [0, 901],
},
Expand Down
8 changes: 4 additions & 4 deletions src/adapter/ember/adapter/oneWaitress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* istanbul ignore file */
import equals from 'fast-deep-equal/es6';
import {ZclPayload} from "../../events";
import {TOUCHLINK_PROFILE_ID} from "../consts";
import {EmberApsFrame, EmberNodeId} from "../types";
import {EmberZdoStatus} from "../zdo";
import {ZclPayload} from '../../events';
import {TOUCHLINK_PROFILE_ID} from '../../../zspec/consts';
import {EmberApsFrame, EmberNodeId} from '../types';
import {EmberZdoStatus} from '../zdo';
import {logger} from '../../../utils/logger';

const NS = 'zh:ember:waitress';
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/ember/adapter/tokensManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* istanbul ignore file */
import {initSecurityManagerContext} from "../utils/initters";
import {BLANK_EUI64} from "../consts";
import {BLANK_EUI64} from "../../../zspec";
import {EMBER_ENCRYPTION_KEY_SIZE, EUI64_SIZE} from "../ezsp/consts";
import {EmberStatus, EzspStatus, SLStatus, SecManFlag, SecManKeyType} from "../enums";
import {EzspValueId} from "../ezsp/enums";
Expand Down
55 changes: 0 additions & 55 deletions src/adapter/ember/consts.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
//-------------------------------------------------------------------------------------------------
// General

/** Endpoint profile ID */
export const CBA_PROFILE_ID = 0x0105;
/** Endpoint profile ID for Zigbee 3.0. "Home Automation" */
export const HA_PROFILE_ID = 0x0104;
/** Endpoint profile ID for Smart Energy */
export const SE_PROFILE_ID = 0x0109;
/** Endpoint profile ID for Green Power */
export const GP_PROFILE_ID = 0xA1E0;
/** The touchlink (ZigBee Light Link/ZLL) Profile ID. */
export const TOUCHLINK_PROFILE_ID = 0xC05E;
/** The profile ID used to address all the public profiles. */
export const WILDCARD_PROFILE_ID = 0xFFFF;

/** The network ID of the coordinator in a ZigBee network is 0x0000. */
export const ZIGBEE_COORDINATOR_ADDRESS = 0x0000;

/** A blank (also used as "wildcard") EUI64 hex string prefixed with 0x */
export const BLANK_EUI64 = "0xFFFFFFFFFFFFFFFF";
/** A blank extended PAN ID. (null/not present) */
export const BLANK_EXTENDED_PAN_ID: readonly number[] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
/** An invalid profile ID. This is a reserved profileId. */
export const INVALID_PROFILE_ID = 0xFFFF;
/** An invalid cluster ID. */
export const INVALID_CLUSTER_ID = 0xFFFF;
/** An invalid PAN ID. */
export const INVALID_PAN_ID = 0xFFFF;
/** Serves to initialize cache */
export const INVALID_NODE_TYPE = 0xFF;
/** Serves to initialize cache for config IDs */
export const INVALID_CONFIG_VALUE = 0xFFFF;
/** Serves to initialize cache */
export const INVALID_RADIO_CHANNEL = 0xFF;
/** A distinguished network ID that will never be assigned to any node. It is used to indicate the absence of a node ID. */
export const NULL_NODE_ID = 0xFFFF;
export const UNKNOWN_NETWORK_STATE = 0xFF;
/** A distinguished binding index used to indicate the absence of a binding. */
export const NULL_BINDING = 0xFF;
/**
* A distinguished network ID that will never be assigned to any node.
* This value is returned when getting the remote node ID from the binding table and the given binding table index refers
Expand Down Expand Up @@ -65,29 +33,9 @@ export const EMBER_NULL_ADDRESS_TABLE_INDEX = 0xFF;
/** Invalidates cached information */
export const SOURCE_ROUTE_OVERHEAD_UNKNOWN = 0xFF;

// Permit join times.
export const PERMIT_JOIN_FOREVER = 0xFF;
export const PERMIT_JOIN_MAX_TIMEOUT = 0xFE;

//-------------------------------------------------------------------------------------------------
// Network

/**
* ZigBee Broadcast Addresses
*
* ZigBee specifies three different broadcast addresses that
* reach different collections of nodes. Broadcasts are normally sent only
* to routers. Broadcasts can also be forwarded to end devices, either
* all of them or only those that do not sleep. Broadcasting to end
* devices is both significantly more resource-intensive and significantly
* less reliable than broadcasting to routers.
*/
/** Broadcast to all routers. */
export const EMBER_BROADCAST_ADDRESS = 0xFFFC;
/** Broadcast to all non-sleepy devices. */
export const EMBER_RX_ON_WHEN_IDLE_BROADCAST_ADDRESS = 0xFFFD;
/** Broadcast to all devices, including sleepy end devices. */
export const EMBER_SLEEPY_BROADCAST_ADDRESS = 0xFFFF;
// From table 3.51 of 053474r14
// When sending many-to-one route requests, the following
// addresses are used
Expand Down Expand Up @@ -198,9 +146,6 @@ export const ZIGBEE_PROFILE_INTEROPERABILITY_LINK_KEY: readonly number[] = [
//-------------------------------------------------------------------------------------------------
// Zigbee Green Power types and defines.

/** The GP endpoint, as defined in the ZigBee spec. */
export const GP_ENDPOINT = 0xF2;

/** Number of GP sink list entries. Minimum is 2 sink list entries. */
export const GP_SINK_LIST_ENTRIES = 2;
/** The size of the SinkList entries in sink table in format of octet string that has a format of {<1 byte length>, <n bytes for sink groups>} */
Expand Down
23 changes: 7 additions & 16 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import EventEmitter from "events";
import {SerialPortOptions} from "../../tstype";
import {Clusters} from "../../../zspec/zcl/definition/cluster";
import * as ZSpec from "../../../zspec";
import {byteToBits, getMacCapFlags, highByte, highLowToInt, lowByte, lowHighBits} from "../utils/math";
import {
EmberOutgoingMessageType,
Expand Down Expand Up @@ -164,8 +165,6 @@ import {AshEvents, UartAsh} from "../uart/ash";
import {EzspBuffer} from "../uart/queues";
import {EzspBuffalo} from "./buffalo";
import {
GP_PROFILE_ID,
HA_PROFILE_ID,
INTERPAN_APS_FRAME_CONTROL_NO_DELIVERY_MODE,
INTERPAN_APS_FRAME_DELIVERY_MODE_MASK,
INTERPAN_APS_FRAME_SECURITY,
Expand All @@ -177,8 +176,6 @@ import {
SHORT_DEST_FRAME_CONTROL,
STUB_NWK_FRAME_CONTROL,
STUB_NWK_SIZE,
TOUCHLINK_PROFILE_ID,
WILDCARD_PROFILE_ID
} from "../consts";
import {FIXED_ENDPOINTS} from "../adapter/endpoints";
import {logger} from "../../../utils/logger";
Expand Down Expand Up @@ -239,10 +236,8 @@ export enum EzspEvents {
TRUST_CENTER_JOIN = 'TRUST_CENTER_JOIN',

//-- ezspMessageSentHandler
/** params => type: EmberOutgoingMessageType, indexOrDestination: number, apsFrame: EmberApsFrame, messageTag: number */
// MESSAGE_SENT_SUCCESS = 'MESSAGE_SENT_SUCCESS',
/** params => type: EmberOutgoingMessageType, indexOrDestination: number, apsFrame: EmberApsFrame, messageTag: number */
MESSAGE_SENT_DELIVERY_FAILED = 'MESSAGE_SENT_DELIVERY_FAILED',
/** params => type: EmberOutgoingMessageType, indexOrDestination: number, apsFrame: EmberApsFrame, messageTag: number, status: EmberStatus */
MESSAGE_SENT = 'MESSAGE_SENT',

//-- ezspGpepIncomingMessageHandler
/** params => sequenceNumber: number, commandIdentifier: number, sourceId: number, frameCounter: number, gpdCommandId: number, gpdCommandPayload: Buffer, gpdLink: number */
Expand Down Expand Up @@ -3955,11 +3950,7 @@ export class Ezsp extends EventEmitter {
NS,
);

if (status === EmberStatus.DELIVERY_FAILED) {
// no ACK was received from the destination
this.emit(EzspEvents.MESSAGE_SENT_DELIVERY_FAILED, type, indexOrDestination, apsFrame, messageTag);
}
// shouldn't be any other status except SUCCESS... no use for it atm
this.emit(EzspEvents.MESSAGE_SENT, type, indexOrDestination, apsFrame, messageTag, status);
}

/**
Expand Down Expand Up @@ -4592,9 +4583,9 @@ export class Ezsp extends EventEmitter {
break;
}
}
} else if (apsFrame.profileId === HA_PROFILE_ID || apsFrame.profileId === WILDCARD_PROFILE_ID) {
} else if (apsFrame.profileId === ZSpec.HA_PROFILE_ID || apsFrame.profileId === ZSpec.WILDCARD_PROFILE_ID) {
this.emit(EzspEvents.INCOMING_MESSAGE, type, apsFrame, lastHopLqi, sender, messageContents);
} else if (apsFrame.profileId === GP_PROFILE_ID) {
} else if (apsFrame.profileId === ZSpec.GP_PROFILE_ID) {
// only broadcast loopback in here
}
}
Expand Down Expand Up @@ -5236,7 +5227,7 @@ export class Ezsp extends EventEmitter {
const profileId = msgBuffalo.readUInt16();
const payload = msgBuffalo.readRest();

if (profileId === TOUCHLINK_PROFILE_ID && clusterId === Clusters.touchlink.ID) {
if (profileId === ZSpec.TOUCHLINK_PROFILE_ID && clusterId === Clusters.touchlink.ID) {
this.emit(EzspEvents.TOUCHLINK_MESSAGE, sourcePanId, sourceAddress, groupId, lastHopLqi, payload);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/adapter/ember/utils/initters.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/* istanbul ignore file */
import {NetworkCache} from "../adapter/emberAdapter";
import * as ZSpec from "../../../zspec";
import {
BLANK_EUI64,
UNKNOWN_NETWORK_STATE,
ZB_PSA_ALG,
INVALID_PAN_ID,
INVALID_RADIO_CHANNEL,
NULL_NODE_ID,
EMBER_ALL_802_15_4_CHANNELS_MASK,
BLANK_EXTENDED_PAN_ID
} from "../consts";
import {
EmberJoinMethod,
Expand All @@ -27,14 +24,14 @@ import {EmberAesMmoHashContext, SecManContext} from "../types";
*/
export const initNetworkCache = (): NetworkCache => {
return {
eui64: BLANK_EUI64,
eui64: ZSpec.BLANK_EUI64,
parameters: {
extendedPanId: BLANK_EXTENDED_PAN_ID.slice(),// copy
panId: INVALID_PAN_ID,
extendedPanId: ZSpec.BLANK_EXTENDED_PAN_ID.slice(),// copy
panId: ZSpec.INVALID_PAN_ID,
radioTxPower: 0,
radioChannel: INVALID_RADIO_CHANNEL,
joinMethod: EmberJoinMethod.MAC_ASSOCIATION,
nwkManagerId: NULL_NODE_ID,
nwkManagerId: ZSpec.NULL_NODE_ID,
nwkUpdateId: 0,
channels: EMBER_ALL_802_15_4_CHANNELS_MASK,
},
Expand Down

0 comments on commit f5e82bf

Please sign in to comment.