Custom Channel Plan version of MTDOT Box firmware
Dependencies: DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot-Custom mDot_Channel_Plans
Fork of MTDOT-BOX-EVB-Factory-Firmware by
CmdNetworkSessionKey.cpp
00001 /* Copyright (c) <2016> <MultiTech Systems>, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #include "CmdNetworkSessionKey.h" 00020 00021 CmdNetworkSessionKey::CmdNetworkSessionKey(mDot* dot, mts::MTSSerial& serial) : 00022 Command(dot, "Network Session Key", "AT+NSK", "Network session encryption key (16 bytes)"), _serial(serial) 00023 { 00024 _help = std::string(text()) + ": " + std::string(desc()); 00025 _usage = "(hex:16)"; 00026 _queryable = true; 00027 } 00028 00029 uint32_t CmdNetworkSessionKey::action(std::vector<std::string> args) 00030 { 00031 if (args.size() == 1) 00032 { 00033 if (_dot->getVerbose()) 00034 _serial.writef("Network Session Key: "); 00035 00036 _serial.writef("%s\r\n", mts::Text::bin2hexString(_dot->getNetworkSessionKey(), ".").c_str()); 00037 } 00038 else if (args.size() == 2) 00039 { 00040 int32_t code; 00041 std::vector<uint8_t> NewKey; 00042 00043 // Read in the key components... 00044 readByteArray(args[1], NewKey, KEY_LENGTH); 00045 00046 if ((code = _dot->setNetworkSessionKey(NewKey)) == mDot::MDOT_OK) { 00047 _serial.writef("Set Network Session Key: "); 00048 _serial.writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str()); 00049 } else { 00050 std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); 00051 setErrorMessage(error); 00052 return 1; 00053 } 00054 } 00055 00056 return 0; 00057 } 00058 00059 bool CmdNetworkSessionKey::verify(std::vector<std::string> args) 00060 { 00061 if (args.size() == 1) 00062 return true; 00063 00064 if (args.size() == 2) { 00065 if (!isHexString(args[1], 16)) { 00066 setErrorMessage("Invalid key, expects (hex:16)"); 00067 return false; 00068 } 00069 00070 return true; 00071 } 00072 00073 setErrorMessage("Invalid arguments"); 00074 return false; 00075 }
Generated on Tue Jul 12 2022 13:07:48 by 1.7.2