MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification

Dependencies:   MaximInterface mbed

The MAXREFDES143# is an Internet of Things (IoT) embedded security reference design, built to protect an industrial sensing node by means of authentication and notification to a web server. The hardware includes a peripheral module representing a protected sensor node monitoring operating temperature and remaining life of a filter (simulated through ambient light sensing) and an mbed shield representing a controller node responsible for monitoring one or more sensor nodes. The design is hierarchical with each controller node communicating data from connected sensor nodes to a web server that maintains a centralized log and dispatches notifications as necessary. The mbed shield contains a Wi-Fi module, a DS2465 coprocessor with 1-Wire® master function, an LCD, LEDs, and pushbuttons. The protected sensor node contains a DS28E15 authenticator, a DS7505 temperature sensor, and a MAX44009 light sensor. The mbed shield communicates to a web server by the onboard Wi-Fi module and to the protected sensor node with I2C and 1-Wire. The MAXREFDES143# is equipped with a standard shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The simplicity of this design enables rapid integration into any star-topology IoT network requiring the heightened security with low overhead provided by the SHA-256 symmetric-key algorithm.

More information about the MAXREFDES143# is available on the Maxim Integrated website.

Committer:
IanBenzMaxim
Date:
Fri Jan 19 10:33:16 2018 -0600
Revision:
35:3d414ba9ab6c
Parent:
32:0a09505a656d
Updated MaximInterface revision.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 29:590a7561318b 1 /*******************************************************************************
IanBenzMaxim 29:590a7561318b 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 29:590a7561318b 3 *
IanBenzMaxim 29:590a7561318b 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 29:590a7561318b 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 29:590a7561318b 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 29:590a7561318b 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 29:590a7561318b 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 29:590a7561318b 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 29:590a7561318b 10 *
IanBenzMaxim 29:590a7561318b 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 29:590a7561318b 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 29:590a7561318b 13 *
IanBenzMaxim 29:590a7561318b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 29:590a7561318b 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 29:590a7561318b 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 29:590a7561318b 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 29:590a7561318b 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 29:590a7561318b 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 29:590a7561318b 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 29:590a7561318b 21 *
IanBenzMaxim 29:590a7561318b 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 29:590a7561318b 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 29:590a7561318b 24 * Products, Inc. Branding Policy.
IanBenzMaxim 29:590a7561318b 25 *
IanBenzMaxim 29:590a7561318b 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 29:590a7561318b 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 29:590a7561318b 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 29:590a7561318b 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 29:590a7561318b 30 * ownership rights.
IanBenzMaxim 32:0a09505a656d 31 *******************************************************************************/
IanBenzMaxim 29:590a7561318b 32
IanBenzMaxim 29:590a7561318b 33 #ifndef ESP8266_HPP
IanBenzMaxim 29:590a7561318b 34 #define ESP8266_HPP
IanBenzMaxim 29:590a7561318b 35
IanBenzMaxim 29:590a7561318b 36 #include <string>
IanBenzMaxim 29:590a7561318b 37 #include <sstream>
IanBenzMaxim 32:0a09505a656d 38 #include <PinNames.h>
IanBenzMaxim 32:0a09505a656d 39 #include <Serial.h>
IanBenzMaxim 32:0a09505a656d 40 #include <DigitalOut.h>
IanBenzMaxim 32:0a09505a656d 41 #include <CircularBuffer.h>
IanBenzMaxim 29:590a7561318b 42
IanBenzMaxim 29:590a7561318b 43 /// Interface to the ESP8266 Wi-Fi module.
IanBenzMaxim 32:0a09505a656d 44 class ESP8266 {
IanBenzMaxim 29:590a7561318b 45 public:
IanBenzMaxim 29:590a7561318b 46 /// Result of sending an AT command.
IanBenzMaxim 32:0a09505a656d 47 enum CmdResult {
IanBenzMaxim 29:590a7561318b 48 AT_OK = 1,
IanBenzMaxim 29:590a7561318b 49 AT_FAIL = 0,
IanBenzMaxim 29:590a7561318b 50 AT_ERROR = -1,
IanBenzMaxim 29:590a7561318b 51 HardwareError = -2,
IanBenzMaxim 29:590a7561318b 52 TimeoutError = -3
IanBenzMaxim 29:590a7561318b 53 };
IanBenzMaxim 32:0a09505a656d 54
IanBenzMaxim 29:590a7561318b 55 /// ESP8266 Wi-Fi mode.
IanBenzMaxim 32:0a09505a656d 56 enum WifiMode { station_mode = 1, softAP_mode = 2, softAP_station_mode = 3 };
IanBenzMaxim 32:0a09505a656d 57
IanBenzMaxim 29:590a7561318b 58 /// Connection type.
IanBenzMaxim 32:0a09505a656d 59 enum ConnType { TCP, UDP };
IanBenzMaxim 32:0a09505a656d 60
IanBenzMaxim 29:590a7561318b 61 /// Recovery time between Send Data operation as specified by datasheet.
IanBenzMaxim 32:0a09505a656d 62 static const int sendDataRecoveryTimeMs = 1000;
IanBenzMaxim 32:0a09505a656d 63
IanBenzMaxim 29:590a7561318b 64 /// Builds command strings for the ESP8266 with proper formatting.
IanBenzMaxim 32:0a09505a656d 65 class CmdBuilder {
IanBenzMaxim 29:590a7561318b 66 public:
IanBenzMaxim 29:590a7561318b 67 /// @param cmd Command of the format "AT+[cmd]".
IanBenzMaxim 29:590a7561318b 68 CmdBuilder(const std::string & cmd = "");
IanBenzMaxim 32:0a09505a656d 69
IanBenzMaxim 29:590a7561318b 70 /// Clear all arguments.
IanBenzMaxim 29:590a7561318b 71 /// @param cmd Command of the format "AT+[cmd]".
IanBenzMaxim 29:590a7561318b 72 void clear(const std::string & cmd);
IanBenzMaxim 32:0a09505a656d 73
IanBenzMaxim 29:590a7561318b 74 /// Append an argument using the default string conversion for that type.
IanBenzMaxim 29:590a7561318b 75 /// @param arg Argument to append to the command.
IanBenzMaxim 32:0a09505a656d 76 template <typename T> void addRawArgument(const T & arg) {
IanBenzMaxim 29:590a7561318b 77 cmdStream << ((numArgs == 0) ? "=" : ",") << arg;
IanBenzMaxim 29:590a7561318b 78 numArgs++;
IanBenzMaxim 29:590a7561318b 79 }
IanBenzMaxim 32:0a09505a656d 80
IanBenzMaxim 29:590a7561318b 81 /// Append a string argument with proper quoting.
IanBenzMaxim 29:590a7561318b 82 /// @param arg Argument to append to the command.
IanBenzMaxim 29:590a7561318b 83 void addStringArgument(const std::string & arg);
IanBenzMaxim 32:0a09505a656d 84
IanBenzMaxim 29:590a7561318b 85 /// Create a string suitable for use with sendCommand().
IanBenzMaxim 29:590a7561318b 86 /// @returns The formatted command string.
IanBenzMaxim 29:590a7561318b 87 std::string str() const;
IanBenzMaxim 32:0a09505a656d 88
IanBenzMaxim 29:590a7561318b 89 private:
IanBenzMaxim 29:590a7561318b 90 int numArgs;
IanBenzMaxim 29:590a7561318b 91 std::ostringstream cmdStream;
IanBenzMaxim 29:590a7561318b 92 };
IanBenzMaxim 32:0a09505a656d 93
IanBenzMaxim 29:590a7561318b 94 /// @param tx Transmit pin from mbed to ESP8266.
IanBenzMaxim 29:590a7561318b 95 /// @param rx Receive pin from ESP8266 to mbed.
IanBenzMaxim 29:590a7561318b 96 /// @param rst Reset pin on ESP8266.
IanBenzMaxim 29:590a7561318b 97 /// @param CH_PD Power-down pin on ESP8266.
IanBenzMaxim 29:590a7561318b 98 /// @param baud Baud rate that the ESP8266 is using.
IanBenzMaxim 29:590a7561318b 99 /// @param debugMsgIntf Optional serial interface for debugging messages.
IanBenzMaxim 32:0a09505a656d 100 ESP8266(const PinName tx, const PinName rx, const PinName rst,
IanBenzMaxim 32:0a09505a656d 101 const PinName CH_PD, const int baud,
IanBenzMaxim 32:0a09505a656d 102 mbed::Serial * debugMsgIntf = NULL);
IanBenzMaxim 32:0a09505a656d 103
IanBenzMaxim 29:590a7561318b 104 /// Reset the ESP8266 via the hardware reset pin.
IanBenzMaxim 29:590a7561318b 105 void reset();
IanBenzMaxim 32:0a09505a656d 106
IanBenzMaxim 29:590a7561318b 107 // Update the baud rate for the ESP8266.
IanBenzMaxim 29:590a7561318b 108 void setBaud(int baud) { AT_intf.baud(baud); }
IanBenzMaxim 32:0a09505a656d 109
IanBenzMaxim 29:590a7561318b 110 /// @{
IanBenzMaxim 29:590a7561318b 111 /// Control if the ESP8266 is powered via the hardware power-down pin.
IanBenzMaxim 29:590a7561318b 112 bool powered() const;
IanBenzMaxim 29:590a7561318b 113 void setPowered(bool powered);
IanBenzMaxim 29:590a7561318b 114 /// @}
IanBenzMaxim 32:0a09505a656d 115
IanBenzMaxim 29:590a7561318b 116 /// Perform a self-test on the ESP8266.
IanBenzMaxim 29:590a7561318b 117 CmdResult performSelfTest();
IanBenzMaxim 32:0a09505a656d 118
IanBenzMaxim 29:590a7561318b 119 /// Set the current Wi-Fi mode.
IanBenzMaxim 29:590a7561318b 120 CmdResult setCurrentWifiMode(const WifiMode mode);
IanBenzMaxim 32:0a09505a656d 121
IanBenzMaxim 29:590a7561318b 122 /// Join a Wi-Fi access point.
IanBenzMaxim 29:590a7561318b 123 /// @param ssid Network SSID to connect to.
IanBenzMaxim 29:590a7561318b 124 /// @param pwd Network password.
IanBenzMaxim 29:590a7561318b 125 /// @param bssid Optional network BSSID.
IanBenzMaxim 32:0a09505a656d 126 CmdResult joinCurrentAccessPoint(const std::string & ssid,
IanBenzMaxim 32:0a09505a656d 127 const std::string & pwd,
IanBenzMaxim 32:0a09505a656d 128 const std::string & bssid = "");
IanBenzMaxim 32:0a09505a656d 129
IanBenzMaxim 29:590a7561318b 130 /// Quit the current access point.
IanBenzMaxim 29:590a7561318b 131 CmdResult quitAccessPoint();
IanBenzMaxim 32:0a09505a656d 132
IanBenzMaxim 29:590a7561318b 133 /// Set the maximum WiFi tranmission power.
IanBenzMaxim 29:590a7561318b 134 /// @param power_dBm Power in dBm valid from 0 to 20.5 in 0.25 dBm increments.
IanBenzMaxim 29:590a7561318b 135 CmdResult setMaxRFTXPower(const float power_dBm);
IanBenzMaxim 32:0a09505a656d 136
IanBenzMaxim 29:590a7561318b 137 /// Ping a host via the current access point.
IanBenzMaxim 29:590a7561318b 138 /// @param IP IP address or resolvable hostname.
IanBenzMaxim 29:590a7561318b 139 CmdResult ping(const std::string & IP);
IanBenzMaxim 32:0a09505a656d 140
IanBenzMaxim 29:590a7561318b 141 /// Open a connection to a host via the current access point.
IanBenzMaxim 29:590a7561318b 142 /// @param type TCP or UPD connection.
IanBenzMaxim 29:590a7561318b 143 /// @param remoteIP IP address or resolvable hostname to connect to.
IanBenzMaxim 29:590a7561318b 144 /// @param remotePort Port on the host to connect to.
IanBenzMaxim 32:0a09505a656d 145 CmdResult openConnection(const ConnType type, const std::string & remoteIP,
IanBenzMaxim 32:0a09505a656d 146 const unsigned int remotePort);
IanBenzMaxim 32:0a09505a656d 147
IanBenzMaxim 29:590a7561318b 148 /// Close the connection to the current host.
IanBenzMaxim 29:590a7561318b 149 CmdResult closeConnection();
IanBenzMaxim 32:0a09505a656d 150
IanBenzMaxim 29:590a7561318b 151 /// Send data to the currently connected host.
IanBenzMaxim 29:590a7561318b 152 /// @param data May be in text or binary form.
IanBenzMaxim 29:590a7561318b 153 CmdResult sendData(const std::string & data);
IanBenzMaxim 32:0a09505a656d 154
IanBenzMaxim 29:590a7561318b 155 /// Send an AT command to the ESP8266.
IanBenzMaxim 29:590a7561318b 156 /// @param cmd Formatted command to send.
IanBenzMaxim 29:590a7561318b 157 CmdResult sendCommand(const CmdBuilder & cmd);
IanBenzMaxim 32:0a09505a656d 158
IanBenzMaxim 29:590a7561318b 159 /// Check if received IP data is available in the buffer.
IanBenzMaxim 29:590a7561318b 160 /// @note Allow some processing delay to happen between calls to this function.
IanBenzMaxim 29:590a7561318b 161 /// @returns True if data is available.
IanBenzMaxim 29:590a7561318b 162 bool recvIpDataReadable();
IanBenzMaxim 29:590a7561318b 163 /// Get the next character of received IP data from the buffer.
IanBenzMaxim 29:590a7561318b 164 char getcRecvIpData();
IanBenzMaxim 29:590a7561318b 165 /// Clear all received data from the buffer.
IanBenzMaxim 29:590a7561318b 166 void clearRecvData();
IanBenzMaxim 32:0a09505a656d 167
IanBenzMaxim 32:0a09505a656d 168 private:
IanBenzMaxim 29:590a7561318b 169 mbed::Serial AT_intf;
IanBenzMaxim 29:590a7561318b 170 mbed::DigitalOut resetPin;
IanBenzMaxim 32:0a09505a656d 171 /// @note Mark as mutable for use in powered().
IanBenzMaxim 32:0a09505a656d 172 mutable mbed::DigitalOut powerDownPin;
IanBenzMaxim 32:0a09505a656d 173 /// Received IP data buffer.
IanBenzMaxim 32:0a09505a656d 174 mbed::CircularBuffer<char, 1024> recvIpDataBuffer;
IanBenzMaxim 29:590a7561318b 175 mbed::Serial * debugMsg;
IanBenzMaxim 32:0a09505a656d 176 /// Indicates when AT interface received data parsers should be reset.
IanBenzMaxim 32:0a09505a656d 177 volatile bool parseRecvReset;
IanBenzMaxim 32:0a09505a656d 178
IanBenzMaxim 29:590a7561318b 179 /// Send raw AT data to the ESP8266.
IanBenzMaxim 29:590a7561318b 180 /// @param cmdString Data to send.
IanBenzMaxim 29:590a7561318b 181 /// @param expectEcho True if the ESP8266 will echo sent data back.
IanBenzMaxim 29:590a7561318b 182 CmdResult send_AT_data(const std::string & cmdString, const bool expectEcho);
IanBenzMaxim 32:0a09505a656d 183
IanBenzMaxim 29:590a7561318b 184 /// Attempts to read an entire line terminated with \r\n from the AT interface.
IanBenzMaxim 29:590a7561318b 185 /// \r will be preserved in the final string and \n will be stripped.
IanBenzMaxim 29:590a7561318b 186 /// @param line Buffer to store received characters in.
IanBenzMaxim 29:590a7561318b 187 /// @returns True if an entire line was read.
IanBenzMaxim 29:590a7561318b 188 bool read_line(std::string & line);
IanBenzMaxim 32:0a09505a656d 189
IanBenzMaxim 29:590a7561318b 190 /// Callback for when data is received on the AT interface.
IanBenzMaxim 29:590a7561318b 191 void recv_AT_data_cb();
IanBenzMaxim 29:590a7561318b 192 /// Parse the next character received on the AT interface checking for valid IP data.
IanBenzMaxim 29:590a7561318b 193 void parseRecvIpData(const char received);
IanBenzMaxim 32:0a09505a656d 194 /// Parse the next character receive on the AT interface for the connection
IanBenzMaxim 32:0a09505a656d 195 /// closed message.
IanBenzMaxim 29:590a7561318b 196 void parseRecvConnClosedMsg(const char received);
IanBenzMaxim 32:0a09505a656d 197
IanBenzMaxim 29:590a7561318b 198 /// Print a message on the debugging interface if setup.
IanBenzMaxim 29:590a7561318b 199 /// @param message Null terminated string.
IanBenzMaxim 29:590a7561318b 200 void printDbgMsg(const char * message);
IanBenzMaxim 29:590a7561318b 201 };
IanBenzMaxim 29:590a7561318b 202
IanBenzMaxim 29:590a7561318b 203 #endif