DeepPass / mDot_AT_firmware

Dependencies:   MTS-Serial libmDot mbed-rtos mbed-src

Fork of mDot_AT_firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdEncryption.cpp Source File

CmdEncryption.cpp

00001 #include "CmdEncryption.h"
00002 
00003 CmdEncryption::CmdEncryption(mDot* dot, mts::MTSSerial& serial) :
00004         Command(dot, "AES Encryption", "AT+ENC", "Enable/disable AES encryption (0: off, 1: on)"), _serial(serial)
00005 {
00006     _help = std::string(text()) + ": " + std::string(desc());
00007     _usage = "(0,1)";
00008     _queryable = true;
00009 }
00010 
00011 uint32_t CmdEncryption::action(std::vector<std::string> args)
00012 {
00013     if (args.size() == 1)
00014     {
00015         if (_dot->getVerbose())
00016             _serial.writef("Encryption: ");
00017 
00018         _serial.writef("%d\r\n", _dot->getAesEncryption());
00019     }
00020     else if (args.size() == 2)
00021     {
00022         int32_t code;
00023         bool enable = (args[1] == "1");
00024 
00025         if ((code = _dot->setAesEncryption(enable)) != mDot::MDOT_OK)
00026         {
00027             std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError();
00028             setErrorMessage(error);
00029             return 1;
00030         }
00031     }
00032 
00033     return 0;
00034 }
00035 
00036 bool CmdEncryption::verify(std::vector<std::string> args)
00037 {
00038     if (args.size() == 1)
00039         return true;
00040 
00041     if (args.size() == 2)
00042     {
00043         if (args[1] != "1" && args[1] != "0") {
00044             setErrorMessage("Invalid parameter, expects (0: off, 1: on)");
00045             return false;
00046         }
00047 
00048         return true;
00049     }
00050 
00051     setErrorMessage("Invalid arguments");
00052     return false;
00053 }