AT Command Set mDot firmware with updated libmDot, to fix endian problem with joining LoRaWAN network
Dependencies: MTS-Serial libmDot mbed-rtos mbed-src
Fork of mDot_AT_firmware by
CmdNetworkSessionKey.cpp
00001 #include "CmdNetworkSessionKey.h" 00002 00003 CmdNetworkSessionKey::CmdNetworkSessionKey(mDot* dot, mts::MTSSerial& serial) : 00004 Command(dot, "Network Session Key", "AT+NSK", "Network 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 CmdNetworkSessionKey::action(std::vector<std::string> args) 00012 { 00013 if (args.size() == 1) 00014 { 00015 if (_dot->getVerbose()) 00016 _serial.writef("Network Session Key: "); 00017 00018 _serial.writef("%s\r\n", mts::Text::bin2hexString(_dot->getNetworkSessionKey(), ".").c_str()); 00019 } 00020 else if (args.size() == 2) 00021 { 00022 int32_t code; 00023 std::vector<uint8_t> NewKey; 00024 00025 // Read in the key components... 00026 readByteArray(args[1], NewKey, KEY_LENGTH); 00027 00028 if ((code = _dot->setNetworkSessionKey(NewKey)) == mDot::MDOT_OK) { 00029 _serial.writef("Set Network Session Key: "); 00030 _serial.writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str()); 00031 } else { 00032 std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); 00033 setErrorMessage(error); 00034 return 1; 00035 } 00036 } 00037 00038 return 0; 00039 } 00040 00041 bool CmdNetworkSessionKey::verify(std::vector<std::string> args) 00042 { 00043 if (args.size() == 1) 00044 return true; 00045 00046 if (args.size() == 2) { 00047 if (!isHexString(args[1], 16)) { 00048 setErrorMessage("Invalid key, expects (hex:16)"); 00049 return false; 00050 } 00051 00052 return true; 00053 } 00054 00055 setErrorMessage("Invalid arguments"); 00056 return false; 00057 }
Generated on Tue Jul 12 2022 21:40:57 by
1.7.2
