Skip to content

Commit

Permalink
fix: Ember: remove zigbeed stack detection (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored and Koenkk committed Mar 20, 2024
1 parent 029903d commit 126e926
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 38 deletions.
5 changes: 3 additions & 2 deletions src/adapter/ember/adapter/emberAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,9 @@ export class EmberAdapter extends Adapter {
adapterOptions: TsType.AdapterOptions, logger?: LoggerStub) {
super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);

// TODO config, should be fine like this for now?
this.stackConfig = SocketPortUtils.isTcpPath(serialPortOptions.path) ? 'zigbeed' : 'default';
// TODO config
// XXX: 'zigbeed': 4.4.x/7.4.x not supported by multiprotocol at the moment, will need refactoring when/if support is added
this.stackConfig = 'default';
// TODO config
this.concentratorType = EMBER_HIGH_RAM_CONCENTRATOR;

Expand Down
97 changes: 63 additions & 34 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ import {
} from "../types";
import {
EmberZdoStatus,
ZDOLQITableEntry,
ACTIVE_ENDPOINTS_RESPONSE,
BINDING_TABLE_RESPONSE,
BIND_RESPONSE,
Expand All @@ -102,11 +101,13 @@ import {
ROUTING_TABLE_RESPONSE,
SIMPLE_DESCRIPTOR_RESPONSE,
UNBIND_RESPONSE,
ZDORoutingTableEntry,
ZDO_MESSAGE_OVERHEAD,
ZDO_PROFILE_ID,
ZDOBindingTableEntry,
END_DEVICE_ANNOUNCE,
PARENT_ANNOUNCE_RESPONSE,
ZDOLQITableEntry,
ZDORoutingTableEntry,
ZDOBindingTableEntry,
IEEEAddressResponsePayload,
NetworkAddressResponsePayload,
MatchDescriptorsResponsePayload,
Expand All @@ -117,7 +118,8 @@ import {
LQITableResponsePayload,
RoutingTableResponsePayload,
BindingTableResponsePayload,
EndDeviceAnnouncePayload
EndDeviceAnnouncePayload,
ParentAnnounceResponsePayload
} from "../zdo";
import {
EZSP_FRAME_CONTROL_ASYNCH_CB,
Expand Down Expand Up @@ -4102,7 +4104,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO IEEE_ADDRESS_RESPONSE status=${status}]`);
debug(`<=== [ZDO IEEE_ADDRESS_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
// 64-bit address for the remote device
Expand Down Expand Up @@ -4130,7 +4132,7 @@ export class Ezsp extends EventEmitter {
assocDevList = zdoBuffalo.readListUInt16({length: assocDevCount});
}

debug(`<=== [ZDO IEEE_ADDRESS_RESPONSE status=${status} eui64=${eui64} nodeId=${nodeId} startIndex=${startIndex} `
debug(`<=== [ZDO IEEE_ADDRESS_RESPONSE status=${EmberZdoStatus[status]} eui64=${eui64} nodeId=${nodeId} startIndex=${startIndex} `
+ `assocDevList=${assocDevList}]`);
debug(`<=== [ZDO IEEE_ADDRESS_RESPONSE] Support not implemented upstream`);

Expand All @@ -4144,7 +4146,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO NETWORK_ADDRESS_RESPONSE status=${status}]`);
debug(`<=== [ZDO NETWORK_ADDRESS_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
// 64-bit address for the remote device
Expand Down Expand Up @@ -4172,8 +4174,8 @@ export class Ezsp extends EventEmitter {
assocDevList = zdoBuffalo.readListUInt16({length: assocDevCount});
}

debug(`<=== [ZDO NETWORK_ADDRESS_RESPONSE status=${status} eui64=${eui64} nodeId=${nodeId} startIndex=${startIndex} `
+ `assocDevList=${assocDevList}]`);
debug(`<=== [ZDO NETWORK_ADDRESS_RESPONSE status=${EmberZdoStatus[status]} eui64=${eui64} nodeId=${nodeId} `
+ `startIndex=${startIndex} assocDevList=${assocDevList}]`);

const payload: NetworkAddressResponsePayload = {eui64, nodeId, assocDevList};

Expand All @@ -4185,14 +4187,14 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO MATCH_DESCRIPTORS_RESPONSE status=${status}]`);
debug(`<=== [ZDO MATCH_DESCRIPTORS_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const nodeId = zdoBuffalo.readUInt16();
const endpointCount = zdoBuffalo.readUInt8();
const endpointList = zdoBuffalo.readListUInt8({length: endpointCount});

debug(`<=== [ZDO MATCH_DESCRIPTORS_RESPONSE status=${status} nodeId=${nodeId} endpointList=${endpointList}]`);
debug(`<=== [ZDO MATCH_DESCRIPTORS_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} endpointList=${endpointList}]`);
debug(`<=== [ZDO MATCH_DESCRIPTORS_RESPONSE] Support not implemented upstream`);

const payload: MatchDescriptorsResponsePayload = {nodeId, endpointList};
Expand All @@ -4205,7 +4207,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO SIMPLE_DESCRIPTOR_RESPONSE status=${status}]`);
debug(`<=== [ZDO SIMPLE_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const nodeId = zdoBuffalo.readUInt16();
Expand All @@ -4221,8 +4223,9 @@ export class Ezsp extends EventEmitter {
const outClusterCount = zdoBuffalo.readUInt8();
const outClusterList = zdoBuffalo.readListUInt16({length: outClusterCount});

debug(`<=== [ZDO SIMPLE_DESCRIPTOR_RESPONSE status=${status} nodeId=${nodeId} endpoint=${endpoint} profileId=${profileId} `
+ `deviceId=${deviceId} deviceVersion=${deviceVersion} inClusterList=${inClusterList} outClusterList=${outClusterList}]`);
debug(`<=== [ZDO SIMPLE_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} endpoint=${endpoint} `
+ `profileId=${profileId} deviceId=${deviceId} deviceVersion=${deviceVersion} inClusterList=${inClusterList} `
+ `outClusterList=${outClusterList}]`);

const payload: SimpleDescriptorResponsePayload = {
nodeId,
Expand All @@ -4241,7 +4244,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO NODE_DESCRIPTOR_RESPONSE status=${status}]`);
debug(`<=== [ZDO NODE_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const nodeId = zdoBuffalo.readUInt16();
Expand Down Expand Up @@ -4296,7 +4299,7 @@ export class Ezsp extends EventEmitter {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const descCapFlags = zdoBuffalo.readUInt8();

debug(`<=== [ZDO NODE_DESCRIPTOR_RESPONSE status=${status} nodeId=${nodeId} logicalType=${logicalType} `
debug(`<=== [ZDO NODE_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} logicalType=${logicalType} `
+ `freqBand=${freqBand} macCapFlags=${byteToBits(macCapFlags)} manufacturerCode=${manufacturerCode} maxBufSize=${maxBufSize} `
+ `maxIncTxSize=${maxIncTxSize} stackRevision=${stackRevision} maxOutTxSize=${maxOutTxSize}]`);

Expand All @@ -4316,7 +4319,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO POWER_DESCRIPTOR_RESPONSE status=${status}]`);
debug(`<=== [ZDO POWER_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const nodeId = zdoBuffalo.readUInt16();
Expand All @@ -4340,8 +4343,8 @@ export class Ezsp extends EventEmitter {
// All other values reserved
const [currentPowerSource, currentPowerSourceLevel] = lowHighBits(zdoBuffalo.readUInt8());

debug(`<=== [ZDO POWER_DESCRIPTOR_RESPONSE status=${status} nodeId=${nodeId} currentPowerMode=${currentPowerMode} `
+ `availPowerSources=${availPowerSources} currentPowerSource=${currentPowerSource} `
debug(`<=== [ZDO POWER_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} `
+ `currentPowerMode=${currentPowerMode} availPowerSources=${availPowerSources} currentPowerSource=${currentPowerSource} `
+ `currentPowerSourceLevel=${currentPowerSourceLevel}]`);
debug(`<=== [ZDO POWER_DESCRIPTOR_RESPONSE] Support not implemented upstream`);

Expand All @@ -4361,14 +4364,14 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO ACTIVE_ENDPOINTS_RESPONSE status=${status}]`);
debug(`<=== [ZDO ACTIVE_ENDPOINTS_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const nodeId = zdoBuffalo.readUInt16();
const endpointCount = zdoBuffalo.readUInt8();
const endpointList = zdoBuffalo.readListUInt8({length: endpointCount});

debug(`<=== [ZDO ACTIVE_ENDPOINTS_RESPONSE status=${status} nodeId=${nodeId} endpointList=${endpointList}]`);
debug(`<=== [ZDO ACTIVE_ENDPOINTS_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} endpointList=${endpointList}]`);

const payload: ActiveEndpointsResponsePayload = {nodeId, endpointList};

Expand All @@ -4380,7 +4383,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO LQI_TABLE_RESPONSE status=${status}]`);
debug(`<=== [ZDO LQI_TABLE_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
// 0x00-0xFF, total number of neighbor table entries within the remote device
Expand Down Expand Up @@ -4417,8 +4420,8 @@ export class Ezsp extends EventEmitter {
});
}

debug(`<=== [ZDO LQI_TABLE_RESPONSE status=${status} neighborTableEntries=${neighborTableEntries} startIndex=${startIndex} `
+ `entryCount=${entryCount} entryList=${JSON.stringify(entryList)}]`);
debug(`<=== [ZDO LQI_TABLE_RESPONSE status=${EmberZdoStatus[status]} neighborTableEntries=${neighborTableEntries} `
+ `startIndex=${startIndex} entryCount=${entryCount} entryList=${JSON.stringify(entryList)}]`);

const payload: LQITableResponsePayload = {neighborTableEntries, entryList};

Expand All @@ -4430,7 +4433,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO ROUTING_TABLE_RESPONSE status=${status}]`);
debug(`<=== [ZDO ROUTING_TABLE_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
// 0x00-0xFF, total number of routing table entries within the remote device
Expand Down Expand Up @@ -4459,8 +4462,8 @@ export class Ezsp extends EventEmitter {
});
}

debug(`<=== [ZDO ROUTING_TABLE_RESPONSE status=${status} routingTableEntries=${routingTableEntries} startIndex=${startIndex} `
+ `entryCount=${entryCount} entryList=${JSON.stringify(entryList)}]`);
debug(`<=== [ZDO ROUTING_TABLE_RESPONSE status=${EmberZdoStatus[status]} routingTableEntries=${routingTableEntries} `
+ `startIndex=${startIndex} entryCount=${entryCount} entryList=${JSON.stringify(entryList)}]`);

const payload: RoutingTableResponsePayload = {routingTableEntries, entryList};

Expand All @@ -4472,7 +4475,7 @@ export class Ezsp extends EventEmitter {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
debug(`<=== [ZDO BINDING_TABLE_RESPONSE status=${status}]`);
debug(`<=== [ZDO BINDING_TABLE_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const bindingTableEntries = zdoBuffalo.readUInt8();
Expand All @@ -4498,8 +4501,8 @@ export class Ezsp extends EventEmitter {
});
}

debug(`<=== [ZDO BINDING_TABLE_RESPONSE status=${status} bindingTableEntries=${bindingTableEntries} startIndex=${startIndex} `
+ `entryCount=${entryCount} entryList=${JSON.stringify(entryList)}]`);
debug(`<=== [ZDO BINDING_TABLE_RESPONSE status=${EmberZdoStatus[status]} bindingTableEntries=${bindingTableEntries} `
+ `startIndex=${startIndex} entryCount=${entryCount} entryList=${JSON.stringify(entryList)}]`);
debug(`<=== [ZDO BINDING_TABLE_RESPONSE] Support not implemented upstream`);

const payload: BindingTableResponsePayload = {bindingTableEntries, entryList};
Expand All @@ -4511,28 +4514,28 @@ export class Ezsp extends EventEmitter {
case BIND_RESPONSE: {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

debug(`<=== [ZDO BIND_RESPONSE status=${status}]`);
debug(`<=== [ZDO BIND_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame);
break;
}
case UNBIND_RESPONSE:{
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

debug(`<=== [ZDO UNBIND_RESPONSE status=${status}]`);
debug(`<=== [ZDO UNBIND_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame);
break;
}
case LEAVE_RESPONSE: {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

debug(`<=== [ZDO LEAVE_RESPONSE status=${status}]`);
debug(`<=== [ZDO LEAVE_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame);
break;
}
case PERMIT_JOINING_RESPONSE: {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

debug(`<=== [ZDO PERMIT_JOINING_RESPONSE status=${status}]`);
debug(`<=== [ZDO PERMIT_JOINING_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame);
break;
}
Expand All @@ -4550,6 +4553,32 @@ export class Ezsp extends EventEmitter {
this.emit(EzspEvents.END_DEVICE_ANNOUNCE, sender, apsFrame, payload);
break;
}
case PARENT_ANNOUNCE_RESPONSE: {
const status: EmberZdoStatus = zdoBuffalo.readUInt8();

if (status !== EmberZdoStatus.ZDP_SUCCESS) {
// status should always be NOT_SUPPORTED here
debug(`<=== [ZDO PARENT_ANNOUNCE_RESPONSE status=${EmberZdoStatus[status]}]`);
this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, null);
} else {
const numberOfChildren = zdoBuffalo.readUInt8();
const children: EmberEUI64[] = [];

for (let i = 0; i < numberOfChildren; i++) {
const childEui64 = zdoBuffalo.readIeeeAddr();

children.push(childEui64);
}

debug(`<=== [ZDO PARENT_ANNOUNCE_RESPONSE status=${EmberZdoStatus[status]} numberOfChildren=${numberOfChildren} `
+ `children=${children}]`);
debug(`<=== [ZDO PARENT_ANNOUNCE_RESPONSE] Support not implemented upstream`);

const payload: ParentAnnounceResponsePayload = {children};

this.emit(EzspEvents.ZDO_RESPONSE, status, sender, apsFrame, payload);
}
}
default: {
console.log(`<=== [ZDO clusterId=${apsFrame.clusterId} sender=${sender}] Support not implemented upstream.`);
break;
Expand Down
9 changes: 7 additions & 2 deletions src/adapter/ember/zdo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ export type EndDeviceAnnouncePayload = {
capabilities: MACCapabilityFlags,
};

/** @see PARENT_ANNOUNCE_RESPONSE */
export type ParentAnnounceResponsePayload = {
children: EmberEUI64[],
};

/**
* Defines for ZigBee device profile cluster IDs follow. These
* include descriptions of the formats of the messages.
Expand Down Expand Up @@ -473,12 +478,12 @@ export const SYSTEM_SERVER_DISCOVERY_RESPONSE = 0x8015;
// The response contains the list of children that the recipient now holds.
/**
* Request: [transaction sequence number: 1]
* [number of children:1] [child EUI64:8] [child Age:4]*
* [number of children:1] [child EUI64:8]*
*/
export const PARENT_ANNOUNCE = 0x001F;
/**
* Response: [transaction sequence number: 1]
* [number of children:1] [child EUI64:8] [child Age:4]*
* [status: 1] [number of children:1] [child EUI64:8]*
*/
export const PARENT_ANNOUNCE_RESPONSE = 0x801F;

Expand Down

0 comments on commit 126e926

Please sign in to comment.