Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CmdNetworkSessionKey.cpp
00001 #include "CmdNetworkSessionKey.h" 00002 00003 CmdNetworkSessionKey::CmdNetworkSessionKey() : 00004 Command("Network Session Key", "AT+NSK", "Network session encryption key (16 bytes)", "(hex:16)") 00005 { 00006 _queryable = true; 00007 } 00008 00009 uint32_t CmdNetworkSessionKey::action(std::vector<std::string> args) 00010 { 00011 if (args.size() == 1) 00012 { 00013 CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(CommandTerminal::Dot()->getNetworkSessionKey(), ".").c_str()); 00014 } 00015 else if (args.size() == 2) 00016 { 00017 std::vector<uint8_t> NewKey; 00018 00019 // Read in the key components... 00020 readByteArray(args[1], NewKey, KEY_LENGTH); 00021 00022 if (CommandTerminal::Dot()->setNetworkSessionKey(NewKey) == mDot::MDOT_OK) { 00023 CommandTerminal::Serial()->writef("Set Network Session Key: "); 00024 CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str()); 00025 } else { 00026 00027 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; 00028 return 1; 00029 } 00030 } 00031 00032 return 0; 00033 } 00034 00035 bool CmdNetworkSessionKey::verify(std::vector<std::string> args) 00036 { 00037 if (args.size() == 1) 00038 return true; 00039 00040 if (args.size() == 2) { 00041 if (!isHexString(args[1], 16)) { 00042 CommandTerminal::setErrorMessage("Invalid key, expects (hex:16)"); 00043 return false; 00044 } 00045 00046 return true; 00047 } 00048 00049 CommandTerminal::setErrorMessage("Invalid arguments"); 00050 return false; 00051 }
Generated on Tue Jul 12 2022 20:40:04 by
