firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdDataSessionKey.cpp@1:c1c6549b9333, 2018-10-22 (annotated)
- Committer:
- nguyenhoang9x5555
- Date:
- Mon Oct 22 01:56:09 2018 +0000
- Revision:
- 1:c1c6549b9333
- Parent:
- 0:3c869a8cb8f8
hey
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 1 | #include "CmdDataSessionKey.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | CmdDataSessionKey::CmdDataSessionKey() : |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | Command("Data Session Key", "AT+DSK", "Data session encryption key (16 bytes)", "(hex:16)") |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | _queryable = true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | uint32_t CmdDataSessionKey::action(std::vector<std::string> args) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | {; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(CommandTerminal::Dot()->getDataSessionKey(), ".").c_str()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | else if (args.size() == 2) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | std::vector<uint8_t> NewKey; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | // Read in the key components... |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | readByteArray(args[1], NewKey, KEY_LENGTH); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | if (CommandTerminal::Dot()->setDataSessionKey(NewKey) == mDot::MDOT_OK) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | CommandTerminal::Serial()->writef("Set Data Session Key: "); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | CommandTerminal::Serial()->writef("%s\r\n", mts::Text::bin2hexString(NewKey, ".").c_str()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | } else { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | return 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | bool CmdDataSessionKey::verify(std::vector<std::string> args) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | if (args.size() == 2) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | if (!isHexString(args[1], 16)) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | CommandTerminal::setErrorMessage("Invalid key, expects (hex:16)"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | } |