/**
 * Copyright (c) 2016-2018 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.console;

import java.io.PrintStream;

import com.zsmartsystems.zigbee.IeeeAddress;
import com.zsmartsystems.zigbee.ZigBeeKey;
import com.zsmartsystems.zigbee.ZigBeeNetworkManager;

/**
 * Handles management of install keys
 *
 * @author Chris Jackson
 *
 */
public class ZigBeeConsoleInstallKeyCommand extends ZigBeeConsoleAbstractCommand {
    @Override
    public String getCommand() {
        return "installkey";
    }

    @Override
    public String getDescription() {
        return "Adds an install key to the dongle";
    }

    @Override
    public String getSyntax() {
        return "IEEEADDRESS KEYDATA";
    }

    @Override
    public String getHelp() {
        return "";
    }

    @Override
    public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out)
            throws IllegalArgumentException {
        if (args.length < 2 || args.length > 3) {
            throw new IllegalArgumentException("Incorrect number of arguments.");
        }

        IeeeAddress partner;
        try {
            partner = new IeeeAddress(args[1]);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Partner address is incorrect format.");
        }

        ZigBeeKey installKey;
        try {
            installKey = new ZigBeeKey(args[2]);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Install key is incorrect format.");
        }

        boolean result = networkManager.setZigBeeInstallKey(partner, installKey);
        out.println("Ember transient key for address " + partner + " was " + (result ? "" : "not") + " set.");
    }

}

@@ -524,16 +524,66 @@
 Manager;
+%0Aimport com.zsmartsystems.zigbee.security.MmoHash;
 %0A%0A/**%0A *
@@ -919,16 +919,59 @@
 e dongle
+, computing the MMO Hash from the join code
 %22;%0A    %7D
@@ -1658,32 +1658,54 @@
 .%22);%0A        %7D%0A%0A
+        MmoHash hash;%0A
         ZigBeeKe
@@ -1724,32 +1724,73 @@
 ;%0A        try %7B%0A
+            hash = new MmoHash(args%5B2%5D);%0A
             inst
@@ -1812,23 +1812,30 @@
 gBeeKey(
-args%5B2%5D
+hash.getHash()
 );%0A     
@@ -2078,27 +2078,43 @@
 ln(%22
-Ember transient key
+Install key %22 + hash.toString() + %22
  for
@@ -2167,16 +2167,32 @@
 : %22not%22)
+%0A               
  + %22 set

Update install key CLI command to perform MMO hash (#314)