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 Jan 26 16:55:23 2017 -0600
Revision:
29:590a7561318b
Child:
30:0784010d6975
Rollback to mbed 2 for stability until online compiler issues with mbed 5 can be resolved.

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 29:590a7561318b 31 *******************************************************************************
IanBenzMaxim 29:590a7561318b 32 */
IanBenzMaxim 29:590a7561318b 33
IanBenzMaxim 29:590a7561318b 34 #ifndef ESP8266_HPP
IanBenzMaxim 29:590a7561318b 35 #define ESP8266_HPP
IanBenzMaxim 29:590a7561318b 36
IanBenzMaxim 29:590a7561318b 37 #include <string>
IanBenzMaxim 29:590a7561318b 38 #include <sstream>
IanBenzMaxim 29:590a7561318b 39
IanBenzMaxim 29:590a7561318b 40 #include "PinNames.h"
IanBenzMaxim 29:590a7561318b 41 #include "Serial.h"
IanBenzMaxim 29:590a7561318b 42 #include "DigitalOut.h"
IanBenzMaxim 29:590a7561318b 43 #include "CircularBuffer.h"
IanBenzMaxim 29:590a7561318b 44
IanBenzMaxim 29:590a7561318b 45 namespace mbed { class Serial; }
IanBenzMaxim 29:590a7561318b 46
IanBenzMaxim 29:590a7561318b 47 /// Interface to the ESP8266 Wi-Fi module.
IanBenzMaxim 29:590a7561318b 48 class ESP8266
IanBenzMaxim 29:590a7561318b 49 {
IanBenzMaxim 29:590a7561318b 50 public:
IanBenzMaxim 29:590a7561318b 51 /// Result of sending an AT command.
IanBenzMaxim 29:590a7561318b 52 enum CmdResult
IanBenzMaxim 29:590a7561318b 53 {
IanBenzMaxim 29:590a7561318b 54 AT_OK = 1,
IanBenzMaxim 29:590a7561318b 55 AT_FAIL = 0,
IanBenzMaxim 29:590a7561318b 56 AT_ERROR = -1,
IanBenzMaxim 29:590a7561318b 57 HardwareError = -2,
IanBenzMaxim 29:590a7561318b 58 TimeoutError = -3
IanBenzMaxim 29:590a7561318b 59 };
IanBenzMaxim 29:590a7561318b 60
IanBenzMaxim 29:590a7561318b 61 /// ESP8266 Wi-Fi mode.
IanBenzMaxim 29:590a7561318b 62 enum WifiMode
IanBenzMaxim 29:590a7561318b 63 {
IanBenzMaxim 29:590a7561318b 64 station_mode = 1,
IanBenzMaxim 29:590a7561318b 65 softAP_mode = 2,
IanBenzMaxim 29:590a7561318b 66 softAP_station_mode = 3
IanBenzMaxim 29:590a7561318b 67 };
IanBenzMaxim 29:590a7561318b 68
IanBenzMaxim 29:590a7561318b 69 /// Connection type.
IanBenzMaxim 29:590a7561318b 70 enum ConnType
IanBenzMaxim 29:590a7561318b 71 {
IanBenzMaxim 29:590a7561318b 72 TCP,
IanBenzMaxim 29:590a7561318b 73 UDP
IanBenzMaxim 29:590a7561318b 74 };
IanBenzMaxim 29:590a7561318b 75
IanBenzMaxim 29:590a7561318b 76 /// Recovery time between Send Data operation as specified by datasheet.
IanBenzMaxim 29:590a7561318b 77 static const unsigned int sendDataRecoveryTimeMs = 1000;
IanBenzMaxim 29:590a7561318b 78
IanBenzMaxim 29:590a7561318b 79 /// Builds command strings for the ESP8266 with proper formatting.
IanBenzMaxim 29:590a7561318b 80 class CmdBuilder
IanBenzMaxim 29:590a7561318b 81 {
IanBenzMaxim 29:590a7561318b 82 public:
IanBenzMaxim 29:590a7561318b 83 /// @param cmd Command of the format "AT+[cmd]".
IanBenzMaxim 29:590a7561318b 84 CmdBuilder(const std::string & cmd = "");
IanBenzMaxim 29:590a7561318b 85
IanBenzMaxim 29:590a7561318b 86 /// Clear all arguments.
IanBenzMaxim 29:590a7561318b 87 /// @param cmd Command of the format "AT+[cmd]".
IanBenzMaxim 29:590a7561318b 88 void clear(const std::string & cmd);
IanBenzMaxim 29:590a7561318b 89
IanBenzMaxim 29:590a7561318b 90 /// Append an argument using the default string conversion for that type.
IanBenzMaxim 29:590a7561318b 91 /// @param arg Argument to append to the command.
IanBenzMaxim 29:590a7561318b 92 template <typename T> void addRawArgument(const T & arg)
IanBenzMaxim 29:590a7561318b 93 {
IanBenzMaxim 29:590a7561318b 94 cmdStream << ((numArgs == 0) ? "=" : ",") << arg;
IanBenzMaxim 29:590a7561318b 95 numArgs++;
IanBenzMaxim 29:590a7561318b 96 }
IanBenzMaxim 29:590a7561318b 97
IanBenzMaxim 29:590a7561318b 98 /// Append a string argument with proper quoting.
IanBenzMaxim 29:590a7561318b 99 /// @param arg Argument to append to the command.
IanBenzMaxim 29:590a7561318b 100 void addStringArgument(const std::string & arg);
IanBenzMaxim 29:590a7561318b 101
IanBenzMaxim 29:590a7561318b 102 /// Create a string suitable for use with sendCommand().
IanBenzMaxim 29:590a7561318b 103 /// @returns The formatted command string.
IanBenzMaxim 29:590a7561318b 104 std::string str() const;
IanBenzMaxim 29:590a7561318b 105
IanBenzMaxim 29:590a7561318b 106 private:
IanBenzMaxim 29:590a7561318b 107 int numArgs;
IanBenzMaxim 29:590a7561318b 108 std::ostringstream cmdStream;
IanBenzMaxim 29:590a7561318b 109 };
IanBenzMaxim 29:590a7561318b 110
IanBenzMaxim 29:590a7561318b 111 /// @{
IanBenzMaxim 29:590a7561318b 112 /// Default instance support for use with mbed Sockets.
IanBenzMaxim 29:590a7561318b 113 static void setDefaultInstance(ESP8266 * const instance);
IanBenzMaxim 29:590a7561318b 114 static ESP8266** getDefaultInstance();
IanBenzMaxim 29:590a7561318b 115 /// @}
IanBenzMaxim 29:590a7561318b 116
IanBenzMaxim 29:590a7561318b 117 /// @param tx Transmit pin from mbed to ESP8266.
IanBenzMaxim 29:590a7561318b 118 /// @param rx Receive pin from ESP8266 to mbed.
IanBenzMaxim 29:590a7561318b 119 /// @param rst Reset pin on ESP8266.
IanBenzMaxim 29:590a7561318b 120 /// @param CH_PD Power-down pin on ESP8266.
IanBenzMaxim 29:590a7561318b 121 /// @param baud Baud rate that the ESP8266 is using.
IanBenzMaxim 29:590a7561318b 122 /// @param debugMsgIntf Optional serial interface for debugging messages.
IanBenzMaxim 29:590a7561318b 123 ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, mbed::Serial * debugMsgIntf = NULL);
IanBenzMaxim 29:590a7561318b 124 ~ESP8266();
IanBenzMaxim 29:590a7561318b 125
IanBenzMaxim 29:590a7561318b 126 /// Reset the ESP8266 via the hardware reset pin.
IanBenzMaxim 29:590a7561318b 127 void reset();
IanBenzMaxim 29:590a7561318b 128
IanBenzMaxim 29:590a7561318b 129 // Update the baud rate for the ESP8266.
IanBenzMaxim 29:590a7561318b 130 void setBaud(int baud) { AT_intf.baud(baud); }
IanBenzMaxim 29:590a7561318b 131
IanBenzMaxim 29:590a7561318b 132 /// @{
IanBenzMaxim 29:590a7561318b 133 /// Control if the ESP8266 is powered via the hardware power-down pin.
IanBenzMaxim 29:590a7561318b 134 bool powered() const;
IanBenzMaxim 29:590a7561318b 135 void setPowered(bool powered);
IanBenzMaxim 29:590a7561318b 136 /// @}
IanBenzMaxim 29:590a7561318b 137
IanBenzMaxim 29:590a7561318b 138 /// Perform a self-test on the ESP8266.
IanBenzMaxim 29:590a7561318b 139 CmdResult performSelfTest();
IanBenzMaxim 29:590a7561318b 140
IanBenzMaxim 29:590a7561318b 141 /// Set the current Wi-Fi mode.
IanBenzMaxim 29:590a7561318b 142 CmdResult setCurrentWifiMode(const WifiMode mode);
IanBenzMaxim 29:590a7561318b 143
IanBenzMaxim 29:590a7561318b 144 /// Join a Wi-Fi access point.
IanBenzMaxim 29:590a7561318b 145 /// @param ssid Network SSID to connect to.
IanBenzMaxim 29:590a7561318b 146 /// @param pwd Network password.
IanBenzMaxim 29:590a7561318b 147 /// @param bssid Optional network BSSID.
IanBenzMaxim 29:590a7561318b 148 CmdResult joinCurrentAccessPoint(const std::string & ssid, const std::string & pwd, const std::string & bssid = "");
IanBenzMaxim 29:590a7561318b 149
IanBenzMaxim 29:590a7561318b 150 /// Quit the current access point.
IanBenzMaxim 29:590a7561318b 151 CmdResult quitAccessPoint();
IanBenzMaxim 29:590a7561318b 152
IanBenzMaxim 29:590a7561318b 153 /// Set the maximum WiFi tranmission power.
IanBenzMaxim 29:590a7561318b 154 /// @param power_dBm Power in dBm valid from 0 to 20.5 in 0.25 dBm increments.
IanBenzMaxim 29:590a7561318b 155 CmdResult setMaxRFTXPower(const float power_dBm);
IanBenzMaxim 29:590a7561318b 156
IanBenzMaxim 29:590a7561318b 157 /// Ping a host via the current access point.
IanBenzMaxim 29:590a7561318b 158 /// @param IP IP address or resolvable hostname.
IanBenzMaxim 29:590a7561318b 159 CmdResult ping(const std::string & IP);
IanBenzMaxim 29:590a7561318b 160
IanBenzMaxim 29:590a7561318b 161 /// Open a connection to a host via the current access point.
IanBenzMaxim 29:590a7561318b 162 /// @param type TCP or UPD connection.
IanBenzMaxim 29:590a7561318b 163 /// @param remoteIP IP address or resolvable hostname to connect to.
IanBenzMaxim 29:590a7561318b 164 /// @param remotePort Port on the host to connect to.
IanBenzMaxim 29:590a7561318b 165 CmdResult openConnection(const ConnType type, const std::string & remoteIP, const unsigned int remotePort);
IanBenzMaxim 29:590a7561318b 166
IanBenzMaxim 29:590a7561318b 167 /// Close the connection to the current host.
IanBenzMaxim 29:590a7561318b 168 CmdResult closeConnection();
IanBenzMaxim 29:590a7561318b 169
IanBenzMaxim 29:590a7561318b 170 /// Send data to the currently connected host.
IanBenzMaxim 29:590a7561318b 171 /// @param data May be in text or binary form.
IanBenzMaxim 29:590a7561318b 172 CmdResult sendData(const std::string & data);
IanBenzMaxim 29:590a7561318b 173
IanBenzMaxim 29:590a7561318b 174 /// Send an AT command to the ESP8266.
IanBenzMaxim 29:590a7561318b 175 /// @param cmd Formatted command to send.
IanBenzMaxim 29:590a7561318b 176 CmdResult sendCommand(const CmdBuilder & cmd);
IanBenzMaxim 29:590a7561318b 177
IanBenzMaxim 29:590a7561318b 178 /// Check if received IP data is available in the buffer.
IanBenzMaxim 29:590a7561318b 179 /// @note Allow some processing delay to happen between calls to this function.
IanBenzMaxim 29:590a7561318b 180 /// @returns True if data is available.
IanBenzMaxim 29:590a7561318b 181 bool recvIpDataReadable();
IanBenzMaxim 29:590a7561318b 182 /// Get the next character of received IP data from the buffer.
IanBenzMaxim 29:590a7561318b 183 char getcRecvIpData();
IanBenzMaxim 29:590a7561318b 184 /// Clear all received data from the buffer.
IanBenzMaxim 29:590a7561318b 185 void clearRecvData();
IanBenzMaxim 29:590a7561318b 186
IanBenzMaxim 29:590a7561318b 187 private:
IanBenzMaxim 29:590a7561318b 188 static ESP8266 * defaultInstance; ///< Default instance support for use with mbed Sockets.
IanBenzMaxim 29:590a7561318b 189
IanBenzMaxim 29:590a7561318b 190 mbed::Serial AT_intf;
IanBenzMaxim 29:590a7561318b 191 mbed::DigitalOut resetPin;
IanBenzMaxim 29:590a7561318b 192 mutable mbed::DigitalOut powerDownPin; ///< @note Mark as mutable for use in powered().
IanBenzMaxim 29:590a7561318b 193 mbed::CircularBuffer<char, 1024> recvIpDataBuffer; ///< Received IP data buffer.
IanBenzMaxim 29:590a7561318b 194 mbed::Serial * debugMsg;
IanBenzMaxim 29:590a7561318b 195 volatile bool parseRecvReset; ///< Indicates when AT interface received data parsers should be reset.
IanBenzMaxim 29:590a7561318b 196
IanBenzMaxim 29:590a7561318b 197 /// Send raw AT data to the ESP8266.
IanBenzMaxim 29:590a7561318b 198 /// @param cmdString Data to send.
IanBenzMaxim 29:590a7561318b 199 /// @param expectEcho True if the ESP8266 will echo sent data back.
IanBenzMaxim 29:590a7561318b 200 CmdResult send_AT_data(const std::string & cmdString, const bool expectEcho);
IanBenzMaxim 29:590a7561318b 201
IanBenzMaxim 29:590a7561318b 202 /// Attempts to read an entire line terminated with \r\n from the AT interface.
IanBenzMaxim 29:590a7561318b 203 /// \r will be preserved in the final string and \n will be stripped.
IanBenzMaxim 29:590a7561318b 204 /// @param line Buffer to store received characters in.
IanBenzMaxim 29:590a7561318b 205 /// @returns True if an entire line was read.
IanBenzMaxim 29:590a7561318b 206 bool read_line(std::string & line);
IanBenzMaxim 29:590a7561318b 207
IanBenzMaxim 29:590a7561318b 208 /// Callback for when data is received on the AT interface.
IanBenzMaxim 29:590a7561318b 209 void recv_AT_data_cb();
IanBenzMaxim 29:590a7561318b 210 /// Parse the next character received on the AT interface checking for valid IP data.
IanBenzMaxim 29:590a7561318b 211 void parseRecvIpData(const char received);
IanBenzMaxim 29:590a7561318b 212 /// Parse the next character receive on the AT interface for the connection closed message.
IanBenzMaxim 29:590a7561318b 213 void parseRecvConnClosedMsg(const char received);
IanBenzMaxim 29:590a7561318b 214
IanBenzMaxim 29:590a7561318b 215 /// Print a message on the debugging interface if setup.
IanBenzMaxim 29:590a7561318b 216 /// @param message Null terminated string.
IanBenzMaxim 29:590a7561318b 217 void printDbgMsg(const char * message);
IanBenzMaxim 29:590a7561318b 218 };
IanBenzMaxim 29:590a7561318b 219
IanBenzMaxim 29:590a7561318b 220 #endif