Skip to content

Commit

Permalink
fix(ignore): Ember: Add tests for adapter layer (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored Jul 21, 2024
1 parent db2d9a5 commit 6318333
Show file tree
Hide file tree
Showing 7 changed files with 4,447 additions and 561 deletions.
727 changes: 245 additions & 482 deletions src/adapter/ember/adapter/emberAdapter.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/adapter/ember/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
export const INVALID_CONFIG_VALUE = 0xffff;
/** Serves to initialize cache */
export const INVALID_RADIO_CHANNEL = 0xff;
export const UNKNOWN_NETWORK_STATE = 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
70 changes: 27 additions & 43 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2782,8 +2782,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspNetworkFoundHandler(networkFound: EmberZigbeeNetwork, lastHopLqi: number, lastHopRssi: number): void {
logger.debug(
`ezspNetworkFoundHandler(): callback called with: [networkFound=${JSON.stringify(networkFound)}], ` +
`[lastHopLqi=${lastHopLqi}], [lastHopRssi=${lastHopRssi}]`,
`ezspNetworkFoundHandler(): callback called with: [networkFound=${JSON.stringify(networkFound)}], [lastHopLqi=${lastHopLqi}], [lastHopRssi=${lastHopRssi}]`,
NS,
);
}
Expand Down Expand Up @@ -3042,8 +3041,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspChildJoinHandler(index: number, joining: boolean, childId: NodeId, childEui64: EUI64, childType: EmberNodeType): void {
logger.debug(
`ezspChildJoinHandler(): callback called with: [index=${index}], [joining=${joining}], ` +
`[childId=${childId}], [childEui64=${childEui64}], [childType=${childType}]`,
`ezspChildJoinHandler(): callback called with: [index=${index}], [joining=${joining}], [childId=${childId}], [childEui64=${childEui64}], [childType=${childType}]`,
NS,
);
}
Expand Down Expand Up @@ -4221,8 +4219,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
arrayOfDeviceDutyCycles: EmberPerDeviceDutyCycle[],
): void {
logger.debug(
`ezspDutyCycleHandler(): callback called with: [channelPage=${channelPage}], [channel=${channel}], ` +
`[state=${state}], [totalDevices=${totalDevices}], [arrayOfDeviceDutyCycles=${arrayOfDeviceDutyCycles}]`,
`ezspDutyCycleHandler(): callback called with: [channelPage=${channelPage}], [channel=${channel}], [state=${state}], [totalDevices=${totalDevices}], [arrayOfDeviceDutyCycles=${arrayOfDeviceDutyCycles}]`,
NS,
);
}
Expand Down Expand Up @@ -4712,8 +4709,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspRemoteSetBindingHandler(entry: EmberBindingTableEntry, index: number, policyDecision: SLStatus): void {
logger.debug(
`ezspRemoteSetBindingHandler(): callback called with: [entry=${JSON.stringify(entry)}], [index=${index}], ` +
`[policyDecision=${SLStatus[policyDecision]}]`,
`ezspRemoteSetBindingHandler(): callback called with: [entry=${JSON.stringify(entry)}], [index=${index}], [policyDecision=${SLStatus[policyDecision]}]`,
NS,
);
}
Expand Down Expand Up @@ -5392,8 +5388,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
relayList: number[],
): void {
logger.debug(
`ezspIncomingRouteRecordHandler(): callback called with: [source=${source}], [sourceEui=${sourceEui}], ` +
`[lastHopLqi=${lastHopLqi}], [lastHopRssi=${lastHopRssi}], [relayCount=${relayCount}], [relayList=${relayList}]`,
`ezspIncomingRouteRecordHandler(): callback called with: [source=${source}], [sourceEui=${sourceEui}], [lastHopLqi=${lastHopLqi}], [lastHopRssi=${lastHopRssi}], [relayCount=${relayCount}], [relayList=${relayList}]`,
NS,
);
// XXX: could at least trigger a `Events.lastSeenChanged` but this is not currently being listened to at the adapter level
Expand Down Expand Up @@ -5731,7 +5726,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspIdConflictHandler(id: NodeId): void {
logger.debug(`ezspIdConflictHandler(): callback called with: [id=${id}]`, NS);
logger.warning(`An ID conflict was detected for network address "${id}". Corresponding devices kicked from the network.`, NS);
logger.warning(`An ID conflict was detected for network address '${id}'. Corresponding devices kicked from the network.`, NS);

// XXX: this is currently causing more problems than not doing it, so disabled for now.
// devices should rejoin on ID conflict anyway, so the database isn't out of sync for very long.
Expand Down Expand Up @@ -5794,8 +5789,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspMacPassthroughMessageHandler(messageType: EmberMacPassthroughType, packetInfo: EmberRxPacketInfo, messageContents: Buffer): void {
logger.debug(
`ezspMacPassthroughMessageHandler(): callback called with: [messageType=${messageType}], ` +
`[packetInfo=${JSON.stringify(packetInfo)}], [messageContents=${messageContents.toString('hex')}]`,
`ezspMacPassthroughMessageHandler(): callback called with: [messageType=${messageType}], [packetInfo=${JSON.stringify(packetInfo)}], [messageContents=${messageContents.toString('hex')}]`,
NS,
);
}
Expand All @@ -5816,9 +5810,8 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
messageContents: Buffer,
): void {
logger.debug(
`ezspMacFilterMatchMessageHandler(): callback called with: [filterIndexMatch=${filterIndexMatch}], ` +
`[legacyPassthroughType=${legacyPassthroughType}], [packetInfo=${JSON.stringify(packetInfo)}], ` +
`[messageContents=${messageContents.toString('hex')}]`,
`ezspMacFilterMatchMessageHandler(): callback called with: [filterIndexMatch=${filterIndexMatch}], [legacyPassthroughType=${legacyPassthroughType}], ` +
`[packetInfo=${JSON.stringify(packetInfo)}], [messageContents=${messageContents.toString('hex')}]`,
NS,
);

Expand All @@ -5838,7 +5831,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
destAddress = msgBuffalo.readUInt16();
} else {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN macFrameControl "${macFrameControl}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN macFrameControl '${macFrameControl}'.`, NS);
return;
}

Expand All @@ -5849,15 +5842,15 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
let remainingLength = msgBuffalo.getBufferLength() - msgBuffalo.getPosition();

if (remainingLength < STUB_NWK_SIZE + MIN_STUB_APS_SIZE) {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN length "${remainingLength}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN length '${remainingLength}'.`, NS);
return;
}

const nwkFrameControl = msgBuffalo.readUInt16();
remainingLength -= 2; // read 2 more bytes before APS stuff

if (nwkFrameControl !== STUB_NWK_FRAME_CONTROL) {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN nwkFrameControl "${nwkFrameControl}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN nwkFrameControl '${nwkFrameControl}'.`, NS);
return;
}

Expand All @@ -5867,7 +5860,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
(apsFrameControl & ~INTERPAN_APS_FRAME_DELIVERY_MODE_MASK & ~INTERPAN_APS_FRAME_SECURITY) !==
INTERPAN_APS_FRAME_CONTROL_NO_DELIVERY_MODE
) {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN apsFrameControl "${apsFrameControl}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN apsFrameControl '${apsFrameControl}'.`, NS);
return;
}

Expand All @@ -5878,22 +5871,22 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
case EmberInterpanMessageType.UNICAST:
case EmberInterpanMessageType.BROADCAST: {
if (remainingLength < INTERPAN_APS_UNICAST_BROADCAST_SIZE) {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN length "${remainingLength}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN length '${remainingLength}'.`, NS);
return;
}
break;
}
case EmberInterpanMessageType.MULTICAST: {
if (remainingLength < INTERPAN_APS_MULTICAST_SIZE) {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN length "${remainingLength}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN length '${remainingLength}'.`, NS);
return;
}

groupId = msgBuffalo.readUInt16();
break;
}
default: {
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN messageType "${messageType}".`, NS);
logger.debug(`ezspMacFilterMatchMessageHandler INVALID InterPAN messageType '${messageType}'.`, NS);
return;
}
}
Expand All @@ -5918,8 +5911,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspRawTransmitCompleteHandler(messageContents: Buffer, status: SLStatus): void {
logger.debug(
`ezspRawTransmitCompleteHandler(): callback called with: [messageContents=${messageContents.toString('hex')}], ` +
`[status=${SLStatus[status]}]`,
`ezspRawTransmitCompleteHandler(): callback called with: [messageContents=${messageContents.toString('hex')}], [status=${SLStatus[status]}]`,
NS,
);
}
Expand Down Expand Up @@ -6904,8 +6896,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
): void {
logger.debug(
`ezspTrustCenterJoinHandler(): callback called with: [newNodeId=${newNodeId}], [newNodeEui64=${newNodeEui64}], ` +
`[status=${EmberDeviceUpdate[status]}], [policyDecision=${EmberJoinDecision[policyDecision]}], ` +
`[parentOfNewNodeId=${parentOfNewNodeId}]`,
`[status=${EmberDeviceUpdate[status]}], [policyDecision=${EmberJoinDecision[policyDecision]}], [parentOfNewNodeId=${parentOfNewNodeId}]`,
NS,
);
// NOTE: this is mostly just passing stuff up to Z2M, so use only one emit for all, let adapter do the rest, no parsing needed
Expand Down Expand Up @@ -7124,8 +7115,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspCalculateSmacsHandler(status: SLStatus, initiatorSmac: EmberSmacData, responderSmac: EmberSmacData): void {
logger.debug(
`ezspCalculateSmacsHandler(): callback called with: [status=${SLStatus[status]}], [initiatorSmac=${initiatorSmac}], ` +
`[responderSmac=${responderSmac}]`,
`ezspCalculateSmacsHandler(): callback called with: [status=${SLStatus[status]}], [initiatorSmac=${initiatorSmac}], [responderSmac=${responderSmac}]`,
NS,
);
}
Expand Down Expand Up @@ -7160,7 +7150,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspGenerateCbkeKeysHandler283k1(status: SLStatus, ephemeralPublicKey: EmberPublicKey283k1Data): void {
logger.debug(
`ezspGenerateCbkeKeysHandler283k1(): callback called with: [status=${SLStatus[status]}], ` + `[ephemeralPublicKey=${ephemeralPublicKey}]`,
`ezspGenerateCbkeKeysHandler283k1(): callback called with: [status=${SLStatus[status]}], [ephemeralPublicKey=${ephemeralPublicKey}]`,
NS,
);
}
Expand Down Expand Up @@ -7209,8 +7199,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspCalculateSmacsHandler283k1(status: SLStatus, initiatorSmac: EmberSmacData, responderSmac: EmberSmacData): void {
logger.debug(
`ezspCalculateSmacsHandler283k1(): callback called with: [status=${SLStatus[status]}], [initiatorSmac=${initiatorSmac}], ` +
`[responderSmac=${responderSmac}]`,
`ezspCalculateSmacsHandler283k1(): callback called with: [status=${SLStatus[status]}], [initiatorSmac=${initiatorSmac}], [responderSmac=${responderSmac}]`,
NS,
);
}
Expand Down Expand Up @@ -7672,8 +7661,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspMfglibRxHandler(linkQuality: number, rssi: number, packetContents: Buffer): void {
logger.debug(
`ezspMfglibRxHandler(): callback called with: [linkQuality=${linkQuality}], [rssi=${rssi}], ` +
`[packetContents=${packetContents.toString('hex')}]`,
`ezspMfglibRxHandler(): callback called with: [linkQuality=${linkQuality}], [rssi=${rssi}], [packetContents=${packetContents.toString('hex')}]`,
NS,
);
}
Expand Down Expand Up @@ -7771,8 +7759,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspIncomingBootloadMessageHandler(longId: EUI64, packetInfo: EmberRxPacketInfo, messageContents: Buffer): void {
logger.debug(
`ezspIncomingBootloadMessageHandler(): callback called with: [longId=${longId}], [packetInfo=${JSON.stringify(packetInfo)}], ` +
`[messageContents=${messageContents.toString('hex')}]`,
`ezspIncomingBootloadMessageHandler(): callback called with: [longId=${longId}], [packetInfo=${JSON.stringify(packetInfo)}], [messageContents=${messageContents.toString('hex')}]`,
NS,
);
}
Expand All @@ -7788,8 +7775,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspBootloadTransmitCompleteHandler(status: SLStatus, messageContents: Buffer): void {
logger.debug(
`ezspBootloadTransmitCompleteHandler(): callback called with: [status=${SLStatus[status]}], ` +
`[messageContents=${messageContents.toString('hex')}]`,
`ezspBootloadTransmitCompleteHandler(): callback called with: [status=${SLStatus[status]}], [messageContents=${messageContents.toString('hex')}]`,
NS,
);
}
Expand Down Expand Up @@ -7826,8 +7812,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspIncomingMfgTestMessageHandler(messageType: number, messageContents: Buffer): void {
logger.debug(
`ezspIncomingMfgTestMessageHandler(): callback called with: [messageType=${messageType}], ` +
`[messageContents=${messageContents.toString('hex')}]`,
`ezspIncomingMfgTestMessageHandler(): callback called with: [messageType=${messageType}], [messageContents=${messageContents.toString('hex')}]`,
NS,
);
}
Expand Down Expand Up @@ -8127,8 +8112,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
packetInfo: EmberRxPacketInfo,
): void {
logger.debug(
`ezspZllNetworkFoundHandler(): callback called with: [networkInfo=${networkInfo}], [isDeviceInfoNull=${isDeviceInfoNull}], ` +
`[deviceInfo=${deviceInfo}], [packetInfo=${JSON.stringify(packetInfo)}]`,
`ezspZllNetworkFoundHandler(): callback called with: [networkInfo=${networkInfo}], [isDeviceInfoNull=${isDeviceInfoNull}], [deviceInfo=${deviceInfo}], [packetInfo=${JSON.stringify(packetInfo)}]`,
NS,
);
}
Expand All @@ -8151,7 +8135,7 @@ export class Ezsp extends EventEmitter<EzspEventMap> {
*/
ezspZllAddressAssignmentHandler(addressInfo: EmberZllAddressAssignment, packetInfo: EmberRxPacketInfo): void {
logger.debug(
`ezspZllAddressAssignmentHandler(): callback called with: [addressInfo=${addressInfo}], ` + `[packetInfo=${JSON.stringify(packetInfo)}]`,
`ezspZllAddressAssignmentHandler(): callback called with: [addressInfo=${addressInfo}], [packetInfo=${JSON.stringify(packetInfo)}]`,
NS,
);
}
Expand Down
10 changes: 3 additions & 7 deletions src/adapter/ember/uart/ash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import {
ASH_MAX_TIMEOUTS,
ASH_MIN_DATA_FIELD_LEN,
ASH_MIN_FRAME_WITH_CRC_LEN,
ASH_NFLAG_BIT,
ASH_NFLAG_MASK,
ASH_RFLAG_BIT,
ASH_RFLAG_MASK,
ASH_SHFRAME_MASK,
ASH_VERSION,
Expand All @@ -49,11 +47,9 @@ import {AshWriter} from './writer';
const NS = 'zh:ember:uart:ash';

/** ASH get rflag in control byte */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ashGetRFlag = (ctrl: number): number => (ctrl & ASH_RFLAG_MASK) >> ASH_RFLAG_BIT;
// const ashGetRFlag = (ctrl: number): number => (ctrl & ASH_RFLAG_MASK) >> ASH_RFLAG_BIT;
/** ASH get nflag in control byte */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ashGetNFlag = (ctrl: number): number => (ctrl & ASH_NFLAG_MASK) >> ASH_NFLAG_BIT;
// const ashGetNFlag = (ctrl: number): number => (ctrl & ASH_NFLAG_MASK) >> ASH_NFLAG_BIT;
/** ASH get frmnum in control byte */
const ashGetFrmNum = (ctrl: number): number => (ctrl & ASH_FRMNUM_MASK) >> ASH_FRMNUM_BIT;
/** ASH get acknum in control byte */
Expand Down Expand Up @@ -152,7 +148,7 @@ enum Flag {
}

/** max frames sent without being ACKed (1-7) */
const CONFIG_TX_K = 3;
export const CONFIG_TX_K = 3;
/** enables randomizing DATA frame payloads */
const CONFIG_RANDOMIZE = true;
/** adaptive rec'd ACK timeout initial value */
Expand Down
5 changes: 2 additions & 3 deletions src/adapter/ember/utils/initters.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* istanbul ignore file */
import * as ZSpec from '../../../zspec';
import {NetworkCache} from '../adapter/emberAdapter';
import {UNKNOWN_NETWORK_STATE, ZB_PSA_ALG, INVALID_RADIO_CHANNEL, EMBER_ALL_802_15_4_CHANNELS_MASK} from '../consts';
import {EmberJoinMethod, EmberNetworkStatus, SecManDerivedKeyType, SecManFlag, SecManKeyType} from '../enums';
import {ZB_PSA_ALG, INVALID_RADIO_CHANNEL, EMBER_ALL_802_15_4_CHANNELS_MASK} from '../consts';
import {EmberJoinMethod, SecManDerivedKeyType, SecManFlag, SecManKeyType} from '../enums';
import {EMBER_AES_HASH_BLOCK_SIZE} from '../ezsp/consts';
import {EmberAesMmoHashContext, SecManContext} from '../types';

Expand All @@ -23,7 +23,6 @@ export const initNetworkCache = (): NetworkCache => {
nwkUpdateId: 0,
channels: EMBER_ALL_802_15_4_CHANNELS_MASK,
},
status: UNKNOWN_NETWORK_STATE as EmberNetworkStatus,
};
};

Expand Down
Loading

0 comments on commit 6318333

Please sign in to comment.