@@ -12,7 +12,6 @@ import * as ZSpec from '../../../zspec';
12
12
import { EUI64 , ExtendedPanId , NodeId , PanId } from '../../../zspec/tstypes' ;
13
13
import * as Zcl from '../../../zspec/zcl' ;
14
14
import * as Zdo from '../../../zspec/zdo' ;
15
- import { BuffaloZdo } from '../../../zspec/zdo/buffaloZdo' ;
16
15
import * as ZdoTypes from '../../../zspec/zdo/definition/tstypes' ;
17
16
import { DeviceAnnouncePayload , DeviceJoinedPayload , DeviceLeavePayload , NetworkAddressPayload , ZclPayload } from '../../events' ;
18
17
import SerialPortUtils from '../../serialPortUtils' ;
@@ -523,9 +522,9 @@ export class EmberAdapter extends Adapter {
523
522
* @param messageContents The content of the response.
524
523
*/
525
524
private async onZDOResponse ( apsFrame : EmberApsFrame , sender : NodeId , messageContents : Buffer ) : Promise < void > {
526
- try {
527
- const payload = BuffaloZdo . readResponse ( apsFrame . clusterId , messageContents , true ) ;
525
+ const [ status , payload ] = Zdo . Buffalo . readResponse ( this . hasZdoMessageOverhead , apsFrame . clusterId , messageContents ) ;
528
526
527
+ if ( status === Zdo . Status . SUCCESS ) {
529
528
logger . debug ( ( ) => `<~~~ [ZDO ${ Zdo . ClusterId [ apsFrame . clusterId ] } from=${ sender } ${ payload ? JSON . stringify ( payload ) : 'OK' } ]` , NS ) ;
530
529
this . oneWaitress . resolveZDO ( sender , apsFrame , payload ) ;
531
530
@@ -540,8 +539,8 @@ export class EmberAdapter extends Adapter {
540
539
ieeeAddr : ( payload as ZdoTypes . EndDeviceAnnounce ) . eui64 ,
541
540
} as DeviceAnnouncePayload ) ;
542
541
}
543
- } catch ( error ) {
544
- this . oneWaitress . resolveZDO ( sender , apsFrame , error ) ;
542
+ } else {
543
+ this . oneWaitress . resolveZDO ( sender , apsFrame , new Zdo . StatusError ( status ) ) ;
545
544
}
546
545
}
547
546
@@ -1513,43 +1512,6 @@ export class EmberAdapter extends Adapter {
1513
1512
return [ status , reContext ?. result ] ;
1514
1513
}
1515
1514
1516
- /**
1517
- * Enable local permit join and optionally broadcast the ZDO Mgmt_Permit_Join_req message.
1518
- * This API can be called from any device type and still return EMBER_SUCCESS.
1519
- * If the API is called from an end device, the permit association bit will just be left off.
1520
- *
1521
- * @param duration uint8_t The duration that the permit join bit will remain on
1522
- * and other devices will be able to join the current network.
1523
- * @param broadcastMgmtPermitJoin whether or not to broadcast the ZDO Mgmt_Permit_Join_req message.
1524
- *
1525
- * @returns status of whether or not permit join was enabled.
1526
- * @returns apsFrame Will be null if not broadcasting.
1527
- * @returns messageTag The tag passed to ezspSend${x} function.
1528
- */
1529
- private async emberPermitJoining (
1530
- duration : number ,
1531
- broadcastMgmtPermitJoin : boolean ,
1532
- ) : Promise < [ SLStatus , apsFrame : EmberApsFrame | undefined , messageTag : number | undefined ] > {
1533
- let status = await this . ezsp . ezspPermitJoining ( duration ) ;
1534
- let apsFrame : EmberApsFrame | undefined ;
1535
- let messageTag : number | undefined ;
1536
-
1537
- logger . debug ( `Permit joining for ${ duration } sec. status=${ [ status ] } ` , NS ) ;
1538
-
1539
- if ( broadcastMgmtPermitJoin ) {
1540
- // `authentication`: TC significance always 1 (zb specs)
1541
- const zdoPayload = BuffaloZdo . buildPermitJoining ( duration , 1 , [ ] ) ;
1542
- [ status , apsFrame , messageTag ] = await this . sendZDORequest (
1543
- ZSpec . BroadcastAddress . DEFAULT ,
1544
- Zdo . ClusterId . PERMIT_JOINING_REQUEST ,
1545
- zdoPayload ,
1546
- DEFAULT_APS_OPTIONS ,
1547
- ) ;
1548
- }
1549
-
1550
- return [ status , apsFrame , messageTag ] ;
1551
- }
1552
-
1553
1515
/**
1554
1516
* Set the trust center policy bitmask using decision.
1555
1517
* @param decision
@@ -1854,7 +1816,15 @@ export class EmberAdapter extends Adapter {
1854
1816
return await this . queue . execute < void > ( async ( ) => {
1855
1817
this . checkInterpanLock ( ) ;
1856
1818
1857
- const zdoPayload = BuffaloZdo . buildChannelChangeRequest ( newChannel , null ) ;
1819
+ const zdoPayload = Zdo . Buffalo . buildRequest (
1820
+ this . hasZdoMessageOverhead ,
1821
+ Zdo . ClusterId . NWK_UPDATE_REQUEST ,
1822
+ [ newChannel ] ,
1823
+ 0xfe ,
1824
+ undefined ,
1825
+ undefined ,
1826
+ undefined ,
1827
+ ) ;
1858
1828
const [ status ] = await this . sendZDORequest (
1859
1829
ZSpec . BroadcastAddress . SLEEPY ,
1860
1830
Zdo . ClusterId . NWK_UPDATE_REQUEST ,
@@ -2012,7 +1982,7 @@ export class EmberAdapter extends Adapter {
2012
1982
await preJoining ( ) ;
2013
1983
2014
1984
// `authentication`: TC significance always 1 (zb specs)
2015
- const zdoPayload = BuffaloZdo . buildPermitJoining ( seconds , 1 , [ ] ) ;
1985
+ const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , Zdo . ClusterId . PERMIT_JOINING_REQUEST , seconds , 1 , [ ] ) ;
2016
1986
const [ status , apsFrame ] = await this . sendZDORequest (
2017
1987
networkAddress ,
2018
1988
Zdo . ClusterId . PERMIT_JOINING_REQUEST ,
@@ -2034,35 +2004,36 @@ export class EmberAdapter extends Adapter {
2034
2004
) ;
2035
2005
} ) ;
2036
2006
} else {
2037
- // coordinator-only, or all
2007
+ // coordinator-only (0) , or all
2038
2008
return await this . queue . execute < void > ( async ( ) => {
2039
2009
this . checkInterpanLock ( ) ;
2040
2010
await preJoining ( ) ;
2041
2011
2042
- // local permit join if `Coordinator`-only requested, else local + broadcast
2043
- const [ status ] = await this . emberPermitJoining ( seconds , networkAddress === ZSpec . COORDINATOR_ADDRESS ? false : true ) ;
2012
+ const status = await this . ezsp . ezspPermitJoining ( seconds ) ;
2044
2013
2045
2014
if ( status !== SLStatus . OK ) {
2046
- throw new Error ( `[ZDO] Failed permit joining request with status=${ SLStatus [ status ] } .` ) ;
2015
+ throw new Error ( `[ZDO] Failed coordinator permit joining request with status=${ SLStatus [ status ] } .` ) ;
2047
2016
}
2048
2017
2049
- // NOTE: because Z2M is refreshing the permit join duration early to prevent it from closing
2050
- // (every 200sec, even if only opened for 254sec), we can't wait for the stack opened status,
2051
- // as it won't trigger again if already opened... so instead we assume it worked
2052
- // NOTE2: with EZSP, 255=forever, and 254=max, but since upstream logic uses fixed 254 with interval refresh,
2053
- // we can't simply bypass upstream calls if called for "forever" to prevent useless NCP calls (3-4 each time),
2054
- // until called with 0 (disable), since we don't know if it was requested for forever or not...
2055
- // TLDR: upstream logic change required to allow this
2056
- // if (seconds) {
2057
- // await this.oneWaitress.startWaitingForEvent(
2058
- // {eventName: OneWaitressEvents.STACK_STATUS_NETWORK_OPENED},
2059
- // DEFAULT_ZCL_REQUEST_TIMEOUT,
2060
- // '[ZDO] Permit Joining',
2061
- // );
2062
- // } else {
2063
- // // NOTE: CLOSED stack status is not triggered if the network was not OPENED in the first place, so don't wait for it
2064
- // // same kind of problem as described above (upstream always tries to close after start, but EZSP already is)
2065
- // }
2018
+ logger . debug ( `Permit joining on coordinator for ${ seconds } sec.` , NS ) ;
2019
+
2020
+ // broadcast permit joining ZDO
2021
+ if ( networkAddress === undefined ) {
2022
+ // `authentication`: TC significance always 1 (zb specs)
2023
+ const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , Zdo . ClusterId . PERMIT_JOINING_REQUEST , seconds , 1 , [ ] ) ;
2024
+
2025
+ const [ bcStatus ] = await this . sendZDORequest (
2026
+ ZSpec . BroadcastAddress . DEFAULT ,
2027
+ Zdo . ClusterId . PERMIT_JOINING_REQUEST ,
2028
+ zdoPayload ,
2029
+ DEFAULT_APS_OPTIONS ,
2030
+ ) ;
2031
+
2032
+ if ( bcStatus !== SLStatus . OK ) {
2033
+ // don't throw, coordinator succeeded at least
2034
+ logger . error ( `[ZDO] Failed broadcast permit joining request with status=${ SLStatus [ bcStatus ] } .` , NS ) ;
2035
+ }
2036
+ }
2066
2037
} ) ;
2067
2038
}
2068
2039
}
@@ -2074,7 +2045,7 @@ export class EmberAdapter extends Adapter {
2074
2045
2075
2046
const neighbors : TsType . LQINeighbor [ ] = [ ] ;
2076
2047
const request = async ( startIndex : number ) : Promise < [ tableEntries : number , entryCount : number ] > => {
2077
- const zdoPayload = BuffaloZdo . buildLqiTableRequest ( startIndex ) ;
2048
+ const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , Zdo . ClusterId . LQI_TABLE_REQUEST , startIndex ) ;
2078
2049
const [ status , apsFrame ] = await this . sendZDORequest (
2079
2050
networkAddress ,
2080
2051
Zdo . ClusterId . LQI_TABLE_REQUEST ,
@@ -2130,7 +2101,7 @@ export class EmberAdapter extends Adapter {
2130
2101
2131
2102
const table : TsType . RoutingTableEntry [ ] = [ ] ;
2132
2103
const request = async ( startIndex : number ) : Promise < [ tableEntries : number , entryCount : number ] > => {
2133
- const zdoPayload = BuffaloZdo . buildRoutingTableRequest ( startIndex ) ;
2104
+ const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , Zdo . ClusterId . ROUTING_TABLE_REQUEST , startIndex ) ;
2134
2105
const [ status , apsFrame ] = await this . sendZDORequest (
2135
2106
networkAddress ,
2136
2107
Zdo . ClusterId . ROUTING_TABLE_REQUEST ,
@@ -2156,7 +2127,7 @@ export class EmberAdapter extends Adapter {
2156
2127
for ( const entry of result . entryList ) {
2157
2128
table . push ( {
2158
2129
destinationAddress : entry . destinationAddress ,
2159
- status : TsType . RoutingTableStatus [ entry . status ] , // get str value from enum to satisfy upstream's needs
2130
+ status : entry . status ,
2160
2131
nextHop : entry . nextHopAddress ,
2161
2132
} ) ;
2162
2133
}
@@ -2184,7 +2155,7 @@ export class EmberAdapter extends Adapter {
2184
2155
return await this . queue . execute < TsType . NodeDescriptor > ( async ( ) => {
2185
2156
this . checkInterpanLock ( ) ;
2186
2157
2187
- const zdoPayload = BuffaloZdo . buildNodeDescriptorRequest ( networkAddress ) ;
2158
+ const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , Zdo . ClusterId . NODE_DESCRIPTOR_REQUEST , networkAddress ) ;
2188
2159
const [ status , apsFrame ] = await this . sendZDORequest (
2189
2160
networkAddress ,
2190
2161
Zdo . ClusterId . NODE_DESCRIPTOR_REQUEST ,
@@ -2220,9 +2191,9 @@ export class EmberAdapter extends Adapter {
2220
2191
}
2221
2192
2222
2193
/* istanbul ignore else */
2223
- if ( result . serverMask . stackComplianceResivion < CURRENT_ZIGBEE_SPEC_REVISION ) {
2194
+ if ( result . serverMask . stackComplianceRevision < CURRENT_ZIGBEE_SPEC_REVISION ) {
2224
2195
// always 0 before rev. 21 where field was added
2225
- const rev = result . serverMask . stackComplianceResivion < 21 ? 'pre-21' : result . serverMask . stackComplianceResivion ;
2196
+ const rev = result . serverMask . stackComplianceRevision < 21 ? 'pre-21' : result . serverMask . stackComplianceRevision ;
2226
2197
2227
2198
logger . warning (
2228
2199
`[ZDO] Device '${ networkAddress } ' is only compliant to revision '${ rev } ' of the ZigBee specification (current revision: ${ CURRENT_ZIGBEE_SPEC_REVISION } ).` ,
@@ -2239,7 +2210,7 @@ export class EmberAdapter extends Adapter {
2239
2210
return await this . queue . execute < TsType . ActiveEndpoints > ( async ( ) => {
2240
2211
this . checkInterpanLock ( ) ;
2241
2212
2242
- const zdoPayload = BuffaloZdo . buildActiveEndpointsRequest ( networkAddress ) ;
2213
+ const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , Zdo . ClusterId . ACTIVE_ENDPOINTS_REQUEST , networkAddress ) ;
2243
2214
const [ status , apsFrame ] = await this . sendZDORequest (
2244
2215
networkAddress ,
2245
2216
Zdo . ClusterId . ACTIVE_ENDPOINTS_REQUEST ,
@@ -2269,7 +2240,12 @@ export class EmberAdapter extends Adapter {
2269
2240
return await this . queue . execute < TsType . SimpleDescriptor > ( async ( ) => {
2270
2241
this . checkInterpanLock ( ) ;
2271
2242
2272
- const zdoPayload = BuffaloZdo . buildSimpleDescriptorRequest ( networkAddress , endpointID ) ;
2243
+ const zdoPayload = Zdo . Buffalo . buildRequest (
2244
+ this . hasZdoMessageOverhead ,
2245
+ Zdo . ClusterId . SIMPLE_DESCRIPTOR_REQUEST ,
2246
+ networkAddress ,
2247
+ endpointID ,
2248
+ ) ;
2273
2249
const [ status , apsFrame ] = await this . sendZDORequest (
2274
2250
networkAddress ,
2275
2251
Zdo . ClusterId . SIMPLE_DESCRIPTOR_REQUEST ,
@@ -2315,7 +2291,9 @@ export class EmberAdapter extends Adapter {
2315
2291
return await this . queue . execute < void > ( async ( ) => {
2316
2292
this . checkInterpanLock ( ) ;
2317
2293
2318
- const zdoPayload = BuffaloZdo . buildBindRequest (
2294
+ const zdoPayload = Zdo . Buffalo . buildRequest (
2295
+ this . hasZdoMessageOverhead ,
2296
+ Zdo . ClusterId . BIND_REQUEST ,
2319
2297
sourceIeeeAddress as EUI64 ,
2320
2298
sourceEndpoint ,
2321
2299
clusterID ,
@@ -2361,7 +2339,9 @@ export class EmberAdapter extends Adapter {
2361
2339
return await this . queue . execute < void > ( async ( ) => {
2362
2340
this . checkInterpanLock ( ) ;
2363
2341
2364
- const zdoPayload = BuffaloZdo . buildUnbindRequest (
2342
+ const zdoPayload = Zdo . Buffalo . buildRequest (
2343
+ this . hasZdoMessageOverhead ,
2344
+ Zdo . ClusterId . UNBIND_REQUEST ,
2365
2345
sourceIeeeAddress as EUI64 ,
2366
2346
sourceEndpoint ,
2367
2347
clusterID ,
@@ -2399,7 +2379,12 @@ export class EmberAdapter extends Adapter {
2399
2379
return await this . queue . execute < void > ( async ( ) => {
2400
2380
this . checkInterpanLock ( ) ;
2401
2381
2402
- const zdoPayload = BuffaloZdo . buildLeaveRequest ( ieeeAddr as EUI64 , Zdo . LeaveRequestFlags . WITHOUT_REJOIN ) ;
2382
+ const zdoPayload = Zdo . Buffalo . buildRequest (
2383
+ this . hasZdoMessageOverhead ,
2384
+ Zdo . ClusterId . LEAVE_REQUEST ,
2385
+ ieeeAddr as EUI64 ,
2386
+ Zdo . LeaveRequestFlags . WITHOUT_REJOIN ,
2387
+ ) ;
2403
2388
const [ status , apsFrame ] = await this . sendZDORequest ( networkAddress , Zdo . ClusterId . LEAVE_REQUEST , zdoPayload , DEFAULT_APS_OPTIONS ) ;
2404
2389
2405
2390
if ( status !== SLStatus . OK ) {
0 commit comments