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 mbed-rtos mbed-src
Fork of mDot_AT_firmware by
CmdDataSessionKey.cpp
00001 #include "CmdDataSessionKey.h" 00002 00003 CmdDataSessionKey::CmdDataSessionKey(mDot* dot, mts::MTSSerial& serial) : 00004 Command(dot, "Data Session Key", "AT+DSK", "Data session encryption key (16 bytes)"), _serial(serial) 00005 { 00006 _help = std::string(text()) + ": " + std::string(desc()); 00007 _usage = "(hex:16)"; 00008 _queryable = true; 00009 } 00010 00011 uint32_t CmdDataSessionKey::action(std::vector<std::string> args) 00012 { 00013 if (args.size() == 1) 00014 { 00015 if (_dot->getVerbose()) 00016 _serial.writef("Data Session Key: "); 00017 _serial.writef("%s\r\n", mts::Text::bin2hexString(_dot->getDataSessionKey(), ".").c_str()); 00018 } 00019 else if (args.size() == 2) 00020 { 00021 int32_t code; 00022 std::vector<uint8_t> NewKey; 00023 00024 // Read in the key components... 00025 readByteArray(args[1], NewKey, KEY_LENGTH); 00026 00027 if ((code = _dot->setDataSessionKey(NewKey)) == mDot::MDOT_OK) { 00028 _serial.writef("Set Data Session Key: "); 00029 _serial.writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str()); 00030 } else { 00031 std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); 00032 setErrorMessage(error); 00033 return 1; 00034 } 00035 } 00036 00037 return 0; 00038 } 00039 00040 bool CmdDataSessionKey::verify(std::vector<std::string> args) 00041 { 00042 if (args.size() == 1) 00043 return true; 00044 00045 if (args.size() == 2) { 00046 if (!isHexString(args[1], 16)) { 00047 setErrorMessage("Invalid key, expects (hex:16)"); 00048 return false; 00049 } 00050 00051 return true; 00052 } 00053 00054 setErrorMessage("Invalid arguments"); 00055 return false; 00056 }
Generated on Tue Jul 12 2022 21:40:57 by
1.7.2
