Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear the Ember NCP key table when reforming the network #700

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspAddTransientLinkKeyResponse;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspAesMmoHashRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspAesMmoHashResponse;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspClearKeyTableRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspClearKeyTableResponse;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspEnergyScanResultHandler;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetCertificate283k1Request;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetCertificate283k1Response;
Expand Down Expand Up @@ -332,6 +334,21 @@ public int[] getCounters() {
return response.getValues();
}

/**
* Clears the key table on the NCP
*
* @return the {@link EmberStatus} or null on error
*/
public EmberStatus clearKeyTable() {
EzspClearKeyTableRequest request = new EzspClearKeyTableRequest();
EzspTransaction transaction = protocolHandler
.sendEzspTransaction(new EzspSingleResponseTransaction(request, EzspClearKeyTableResponse.class));
EzspClearKeyTableResponse response = (EzspClearKeyTableResponse) transaction.getResponse();
logger.debug(response.toString());
lastStatus = response.getStatus();
return lastStatus;
}

/**
* Gets a Security Key based on the passed key type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public void formNetwork(EmberNetworkParameters networkParameters, ZigBeeKey link
ncp.leaveNetwork();
}

ncp.clearKeyTable();

// Perform an energy scan to find a clear channel
int quietestChannel = doEnergyScan(ncp, scanDuration);
logger.debug("Energy scan reports quietest channel is {}", quietestChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.zsmartsystems.zigbee.ZigBeeChannelMask;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.EzspFrameRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.EzspFrameResponse;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspClearKeyTableRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspClearKeyTableResponse;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetEui64Request;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetEui64Response;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetNetworkParametersRequest;
Expand Down Expand Up @@ -211,4 +213,16 @@ public void doEnergyScan() {
assertEquals(ZigBeeChannelMask.CHANNEL_MASK_2GHZ, ((EzspStartScanRequest) request).getChannelMask());
}

@Test
public void clearKeyTable() {
EmberNcp ncp = getEmberNcp(Mockito.mock(EzspClearKeyTableResponse.class));

ncp.clearKeyTable();

Mockito.verify(handler, Mockito.times(1)).sendEzspTransaction(ezspTransactionCapture.capture());

EzspFrameRequest request = ezspTransactionCapture.getValue().getRequest();
assertTrue(request instanceof EzspClearKeyTableRequest);
}

}