Search in sources :

Example 1 with EmberKeyData

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData in project com.zsmartsystems.zigbee by zsmartsystems.

the class EzspSetInitialSecurityStateRequestTest method testSecurityStateRequest.

@Test
public void testSecurityStateRequest() {
    EzspFrame.setEzspVersion(4);
    EmberKeyData keyData;
    EzspSetInitialSecurityStateRequest request = new EzspSetInitialSecurityStateRequest();
    EmberInitialSecurityState state = new EmberInitialSecurityState();
    keyData = new EmberKeyData();
    keyData.setContents(new int[] { 0xAA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA });
    state.setNetworkKey(keyData);
    keyData = new EmberKeyData();
    keyData.setContents(new int[] { 0xBB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xBB });
    state.setPreconfiguredKey(keyData);
    state.setPreconfiguredTrustCenterEui64(new IeeeAddress("1234567890ABCDEF"));
    state.setNetworkKeySequenceNumber(0);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_STANDARD_SECURITY_MODE);
    request.setState(state);
    request.setSequenceNumber(7);
    System.out.println(request);
    assertTrue(Arrays.equals(getPacketData("07 00 68 00 00 BB 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BB AA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 AA 00 EF CD AB 90 78 56 34 12"), request.serialize()));
}
Also used : EmberKeyData(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData) EmberInitialSecurityState(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberInitialSecurityState) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Example 2 with EmberKeyData

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData in project com.zsmartsystems.zigbee by zsmartsystems.

the class EmberNetworkInitialisation method setSecurityState.

/**
 * Sets the initial security state
 *
 * @param networkKey the initial {@link EmberKeyData}
 * @return true if the security state was set successfully
 */
private boolean setSecurityState(EmberKeyData networkKey) {
    // Define the ZigBeeAliance09 key for HA link-key
    // This is used to encrypt the network key when it is transferred to a newly joining device.
    EmberKeyData linkKey = new EmberKeyData();
    linkKey.setContents(new int[] { 0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 });
    // linkKey.setContents(new int[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    // 0xFF, 0xFF, 0xFF });
    EzspSetInitialSecurityStateRequest securityState = new EzspSetInitialSecurityStateRequest();
    EmberInitialSecurityState state = new EmberInitialSecurityState();
    // state.addBitmask(EmberInitialSecurityBitmask.EMBER_STANDARD_SECURITY_MODE);
    // state.addBitmask(EmberInitialSecurityBitmask.EMBER_DISTRIBUTED_TRUST_CENTER_MODE);//
    // EMBER_TRUST_CENTER_GLOBAL_LINK_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_TRUST_CENTER_GLOBAL_LINK_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_HAVE_PRECONFIGURED_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_HAVE_NETWORK_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_NO_FRAME_COUNTER_RESET);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_REQUIRE_ENCRYPTED_KEY);
    state.setNetworkKey(networkKey);
    state.setPreconfiguredKey(linkKey);
    state.setPreconfiguredTrustCenterEui64(new IeeeAddress());
    securityState.setState(state);
    EzspSingleResponseTransaction transaction = new EzspSingleResponseTransaction(securityState, EzspSetInitialSecurityStateResponse.class);
    ashHandler.sendEzspTransaction(transaction);
    EzspSetInitialSecurityStateResponse securityStateResponse = (EzspSetInitialSecurityStateResponse) transaction.getResponse();
    logger.debug(securityStateResponse.toString());
    if (securityStateResponse.getStatus() != EmberStatus.EMBER_SUCCESS) {
        logger.debug("Error during retrieval of network parameters: {}", securityStateResponse);
        return false;
    }
    return true;
}
Also used : EzspSetInitialSecurityStateRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSetInitialSecurityStateRequest) EmberKeyData(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData) EzspSetInitialSecurityStateResponse(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSetInitialSecurityStateResponse) EzspSingleResponseTransaction(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspSingleResponseTransaction) EmberInitialSecurityState(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberInitialSecurityState) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress)

Aggregations

IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)2 EmberInitialSecurityState (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberInitialSecurityState)2 EmberKeyData (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData)2 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)1 EzspSetInitialSecurityStateRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSetInitialSecurityStateRequest)1 EzspSetInitialSecurityStateResponse (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSetInitialSecurityStateResponse)1 EzspSingleResponseTransaction (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspSingleResponseTransaction)1 Test (org.junit.Test)1