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:
Thu Apr 14 19:48:01 2016 +0000
Revision:
1:e1c7c1c636af
Child:
6:b6bafd0a7013
Add initial source files.

Who changed what in which revision?

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