----------------------------------------------------------------------------- Get the Network Key we will use for Security Command Class -----------------------------------------------------------------------------
| 7004 | // Get the Network Key we will use for Security Command Class |
| 7005 | //----------------------------------------------------------------------------- |
| 7006 | uint8 *Driver::GetNetworkKey() { |
| 7007 | std::string networkKey; |
| 7008 | std::vector<std::string> elems; |
| 7009 | unsigned int tempkey[16]; |
| 7010 | static uint8 keybytes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 7011 | static bool keySet = false; |
| 7012 | if (keySet == false) { |
| 7013 | Options::Get()->GetOptionAsString("NetworkKey", &networkKey ); |
| 7014 | OpenZWave::split(elems, networkKey, ",", true); |
| 7015 | if (elems.size() != 16) { |
| 7016 | Log::Write(LogLevel_Warning, "Invalid Network Key. Does not contain 16 Bytes - Contains %d", elems.size()); |
| 7017 | Log::Write(LogLevel_Warning, "Raw Key: %s", networkKey.c_str()); |
| 7018 | Log::Write(LogLevel_Warning, "Parsed Key:"); |
| 7019 | int i = 0; |
| 7020 | for (std::vector<std::string>::iterator it = elems.begin(); it != elems.end(); it++) |
| 7021 | Log::Write(LogLevel_Warning, "%d) - %s", ++i, (*it).c_str()); |
| 7022 | OZW_FATAL_ERROR(OZWException::OZWEXCEPTION_SECURITY_FAILED, "Failed to Read Network Key"); |
| 7023 | } |
| 7024 | int i = 0; |
| 7025 | for (std::vector<std::string>::iterator it = elems.begin(); it != elems.end(); it++) { |
| 7026 | if (0 == sscanf(OpenZWave::trim(*it).c_str(), "%x", &tempkey[i])) { |
| 7027 | Log::Write(LogLevel_Warning, "Cannot Convert Network Key Byte %s to Key", (*it).c_str()); |
| 7028 | OZW_FATAL_ERROR(OZWException::OZWEXCEPTION_SECURITY_FAILED, "Failed to Convert Network Key"); |
| 7029 | } else { |
| 7030 | keybytes[i] = (tempkey[i] & 0xFF); |
| 7031 | } |
| 7032 | i++; |
| 7033 | } |
| 7034 | keySet = true; |
| 7035 | } |
| 7036 | return keybytes; |
| 7037 | } |
| 7038 | |
| 7039 | //----------------------------------------------------------------------------- |
| 7040 | // <Driver::SendEncryptedMessage> |