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.
Revision 6:b6bafd0a7013, committed 2016-05-12
- Comitter:
- IanBenzMaxim
- Date:
- Thu May 12 14:40:14 2016 -0500
- Parent:
- 5:63232ef22abe
- Child:
- 7:e24f0b29f1f7
- Commit message:
- Updated following downstream restructuring in OneWire library.
Changed in this revision
--- a/DS7505.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/DS7505.cpp Thu May 12 14:40:14 2016 -0500
@@ -32,7 +32,8 @@
*/
#include "DS7505.hpp"
-#include "mbed.h"
+#include "I2C.h"
+#include "wait_api.h"
#define I2C_WRITE 0
#define I2C_READ 1
@@ -40,7 +41,7 @@
static const int I2C_WRITE_OK = 0;
static const uint8_t DS7505_Config_SD_Bit = 0x01; // Enable shutdown mode
-DS7505::DS7505(I2C & I2C_interface, uint8_t I2C_address)
+DS7505::DS7505(mbed::I2C & I2C_interface, uint8_t I2C_address)
: m_current_config(Config_9b_Res, true), m_I2C_interface(I2C_interface), m_I2C_address(I2C_address)
{
@@ -83,8 +84,8 @@
sub_res = m_I2C_interface.write(m_I2C_address | I2C_READ);
if (sub_res == I2C_WRITE_OK)
{
- upperByte = m_I2C_interface.read(I2C::ACK);
- lowerByte = m_I2C_interface.read(I2C::NoACK);
+ upperByte = m_I2C_interface.read(mbed::I2C::ACK);
+ lowerByte = m_I2C_interface.read(mbed::I2C::NoACK);
}
m_I2C_interface.stop();
if (sub_res == I2C_WRITE_OK)
--- a/DS7505.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/DS7505.hpp Thu May 12 14:40:14 2016 -0500
@@ -34,7 +34,7 @@
#ifndef _DS7505_HPP
#define _DS7505_HPP
-#include <cstdint>
+#include <stdint.h>
namespace mbed
{
@@ -54,11 +54,11 @@
/// @param I2C_interface A configured I2C interface to use for communication.
/// @param I2C_address Device bus address in mbed format.
- DS7505(mbed::I2C & I2C_interface, std::uint8_t I2C_address);
+ DS7505(mbed::I2C & I2C_interface, uint8_t I2C_address);
/// Set the resolution for temperature conversions.
/// @param resolution Number of decimal bit from 1 to 4.
- Result set_resolution(std::uint8_t resolution);
+ Result set_resolution(uint8_t resolution);
/// Reads the current temperature with an exponent of 10^-2.
/// @note Compatible with Bluetooth characteristic: org.bluetooth.characteristic.temperature.
@@ -103,21 +103,21 @@
mutable Config m_current_config;
mbed::I2C & m_I2C_interface;
- std::uint8_t m_I2C_address;
+ uint8_t m_I2C_address;
/// Returns the maximum time needed in ms for a sample at the specified resolution.
- static std::uint8_t get_measure_delay_ms(Config_Resolution resolution);
+ static uint8_t get_measure_delay_ms(Config_Resolution resolution);
/// Reads the current temperature via I2C.
/// Assumes that the I2C register pointer is already set to the temperature register.
/// @param sensor_data Output for raw data from DS7505 with upper and lower bytes combined.
/// @returns True on success.
- bool read_temp_sensor_data(std::uint16_t & sensor_data) const;
+ bool read_temp_sensor_data(uint16_t & sensor_data) const;
/// Reads the current temperature with support for shutdown mode.
/// @param sensor_data Output for raw data from DS7505 with upper and lower bytes combined.
/// @returns Success or Hardware_Failure.
- Result read_temp_sensor(std::uint16_t & sensor_data) const;
+ Result read_temp_sensor(uint16_t & sensor_data) const;
/// Sets the I2C register pointer for the next operation.
/// @param pointer_reg Desired register to set.
@@ -130,7 +130,7 @@
/// @param write_val Value to write to the register.
/// @returns True on success.
/// @note Allow marking const since not public
- bool write_register(Register write_reg, std::uint8_t write_val) const;
+ bool write_register(Register write_reg, uint8_t write_val) const;
/// Writes the current configuration via I2C.
/// @returns True on success.
--- a/Display.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/Display.cpp Thu May 12 14:40:14 2016 -0500
@@ -33,7 +33,7 @@
#include <sstream>
#include "Display.hpp"
-#include "mbed.h"
+#include "I2C.h"
//LCD Commands
//If the RS bit is set to logic 1, these display bytes are stored in the display RAM at the address specified by the data pointer. The data pointer is
@@ -68,13 +68,13 @@
};
// Convert a byte color value into the representation used by the MAX7306 PWM registers
-static std::uint8_t convertColorToPwmRegVal(std::uint8_t color)
+static uint8_t convertColorToPwmRegVal(uint8_t color)
{
- const std::uint8_t staticOffRegVal = 0x80; // LED is static off by setting to input
- const std::uint8_t staticOnRegVal = 0x00; // LED is static on
- const std::uint8_t minOnRegVal = 0x01; // LED on for minimum duty cycle
+ const uint8_t staticOffRegVal = 0x80; // LED is static off by setting to input
+ const uint8_t staticOnRegVal = 0x00; // LED is static on
+ const uint8_t minOnRegVal = 0x01; // LED on for minimum duty cycle
- std::uint8_t regVal;
+ uint8_t regVal;
if (color == 0x00) // Use static off for no color
{
regVal = staticOffRegVal;
@@ -93,7 +93,7 @@
return regVal;
}
-Display::Display(I2C & I2C_intf, uint8_t LCD_I2C_addr, uint8_t LED_driver_I2C_addr)
+Display::Display(mbed::I2C & I2C_intf, uint8_t LCD_I2C_addr, uint8_t LED_driver_I2C_addr)
: m_I2C_intf(I2C_intf), m_LCD_I2C_addr(LCD_I2C_addr), m_LED_driver_I2C_addr(LED_driver_I2C_addr)
{
@@ -107,8 +107,8 @@
void Display::initializeLED_Driver(void)
{
- const std::uint8_t Configuration26 = 0x26; //intial port state 0xEC
- const std::uint8_t Configuration27 = 0x27; //intial port state 0x8F
+ const uint8_t Configuration26 = 0x26; //intial port state 0xEC
+ const uint8_t Configuration27 = 0x27; //intial port state 0x8F
//Intial mode
//write to Configuration Register 0x26
@@ -189,7 +189,7 @@
m_I2C_intf.stop();
}
-void Display::writeCharacter(std::uint8_t character)
+void Display::writeCharacter(uint8_t character)
{
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
@@ -202,7 +202,7 @@
{
const char RETURN_CHAR = 0x16;
- std::size_t length = text.length();
+ size_t length = text.length();
if (length > lineLength)
length = lineLength;
@@ -211,7 +211,7 @@
m_I2C_intf.write(m_LCD_I2C_addr);
m_I2C_intf.write(ControlByte_RS_Set);
- for(std::size_t i = 0; i < length; i++)
+ for(size_t i = 0; i < length; i++)
{
if(text[i] != RETURN_CHAR)
m_I2C_intf.write(text[i]);
@@ -220,7 +220,7 @@
m_I2C_intf.stop();
}
-void Display::setCursorPosition(Line line, std::size_t position)
+void Display::setCursorPosition(Line line, size_t position)
{
if (position > (lineLength - 1)) // Set to last line character for values outside the upper bound
position = (lineLength - 1);
@@ -257,7 +257,7 @@
// Find split point
std::istringstream messageStream(message);
std::string word;
- std::size_t splitIndex = 0;
+ size_t splitIndex = 0;
do
{
if (word.length() > 0)
--- a/Display.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/Display.hpp Thu May 12 14:40:14 2016 -0500
@@ -34,7 +34,8 @@
#ifndef _DISPLAY_HPP
#define _DISPLAY_HPP
-#include <cstdint>
+#include <stdint.h>
+#include <stddef.h>
#include <string>
namespace mbed { class I2C; }
@@ -54,18 +55,18 @@
/// 24-bit RGB color for the backlight.
struct Color
{
- std::uint8_t R, G, B;
- Color(std::uint8_t R, std::uint8_t G, std::uint8_t B)
+ uint8_t R, G, B;
+ Color(uint8_t R, uint8_t G, uint8_t B)
: R(R), G(G), B(B) { }
};
/// Length in character os a display line.
- static const std::size_t lineLength = 20;
+ static const size_t lineLength = 20;
/// @param I2C_interface A configured I2C interface to use for communication.
/// @param LCD_I2C_address LCD module bus address in mbed format.
/// @param LED_driver_I2C_addr PWM LED driver (MAX7306) bus address in mbed format.
- Display(mbed::I2C & I2C_intf, std::uint8_t LCD_I2C_addr, std::uint8_t LED_driver_I2C_addr);
+ Display(mbed::I2C & I2C_intf, uint8_t LCD_I2C_addr, uint8_t LED_driver_I2C_addr);
/// Initialize display components.
void initialize(void);
@@ -77,13 +78,13 @@
void clearLine(Line line);
/// Write a single character to the display at the current cursor position.
- void writeCharacter(std::uint8_t character);
+ void writeCharacter(uint8_t character);
/// Write text to the display at the current cursor position.
void writeText(const std::string & text);
/// Set cursor to a certain line and zero-index position within the line.
- void setCursorPosition(Line line, std::size_t position = 0);
+ void setCursorPosition(Line line, size_t position = 0);
/// Writes text to the display starting at the beginning of the line.
void writeLine(const std::string & text, Line line);
@@ -99,7 +100,7 @@
private:
mbed::I2C & m_I2C_intf;
- std::uint8_t m_LCD_I2C_addr, m_LED_driver_I2C_addr;
+ uint8_t m_LCD_I2C_addr, m_LED_driver_I2C_addr;
void initializeLCD(void);
void initializeLED_Driver(void);
--- a/ESP8266.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/ESP8266.cpp Thu May 12 14:40:14 2016 -0500
@@ -31,7 +31,10 @@
*******************************************************************************
*/
+#include <cstdlib>
#include "ESP8266.hpp"
+#include "Timer.h"
+#include "wait_api.h"
ESP8266* ESP8266::defaultInstance = NULL;
@@ -56,7 +59,7 @@
return &defaultInstance;
}
-ESP8266::ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, Serial * debugMsgIntf)
+ESP8266::ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, mbed::Serial * debugMsgIntf)
: AT_intf(tx, rx), resetPin(rst), powerDownPin(CH_PD), debugMsg(debugMsgIntf), parseRecvReset(false)
{
AT_intf.baud(baud);
@@ -227,7 +230,7 @@
{
const int timeout_ms = 10000;
- Timer timer;
+ mbed::Timer timer;
ESP8266::CmdResult result = ESP8266::HardwareError;
std::string response;
@@ -392,7 +395,7 @@
}
else if (received == ':')
{
- dataFinishedSize = atoi(sizeDigits);
+ dataFinishedSize = std::atoi(sizeDigits);
if (dataFinishedSize == 0)
{
state = Reset;
--- a/ESP8266.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/ESP8266.hpp Thu May 12 14:40:14 2016 -0500
@@ -37,9 +37,13 @@
#include <string>
#include <sstream>
-#include "mbed.h"
+#include "PinNames.h"
+#include "Serial.h"
+#include "DigitalOut.h"
#include "CircularBuffer.h"
+namespace mbed { class Serial; }
+
/// Interface to the ESP8266 Wi-Fi module.
class ESP8266
{
@@ -116,7 +120,7 @@
/// @param CH_PD Power-down pin on ESP8266.
/// @param baud Baud rate that the ESP8266 is using.
/// @param debugMsgIntf Optional serial interface for debugging messages.
- ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, Serial * debugMsgIntf = NULL);
+ ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, mbed::Serial * debugMsgIntf = NULL);
~ESP8266();
/// Reset the ESP8266 via the hardware reset pin.
@@ -183,11 +187,11 @@
private:
static ESP8266 * defaultInstance; ///< Default instance support for use with mbed Sockets.
- Serial AT_intf;
- DigitalOut resetPin;
- mutable DigitalOut powerDownPin; ///< @note Mark as mutable for use in powered().
- CircularBuffer<char, 1024> recvIpDataBuffer; ///< Received IP data buffer.
- Serial * debugMsg;
+ mbed::Serial AT_intf;
+ mbed::DigitalOut resetPin;
+ mutable mbed::DigitalOut powerDownPin; ///< @note Mark as mutable for use in powered().
+ mbed::CircularBuffer<char, 1024> recvIpDataBuffer; ///< Received IP data buffer.
+ mbed::Serial * debugMsg;
volatile bool parseRecvReset; ///< Indicates when AT interface received data parsers should be reset.
/// Send raw AT data to the ESP8266.
--- a/Factory.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/Factory.cpp Thu May 12 14:40:14 2016 -0500
@@ -34,18 +34,24 @@
#include "Factory.hpp"
#include "SensorNode.hpp"
#include "common.hpp"
-#include "OneWire_Masters/DS2465/DS2465.hpp"
-#include "OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp"
-#include "mbed.h"
+#include "Masters/DS2465/DS2465.h"
+#include "Authenticators/DS28E15_22_25/DS28E15_22_25.h"
+#include "wait_api.h"
-const std::uint8_t Factory::masterSecret[] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x21,
+using OneWire::Masters::OneWireMaster;
+using OneWire::Masters::DS2465;
+using OneWire::OneWireSlave;
+using OneWire::Authenticators::DS28E15_22_25;
+using OneWire::Authenticators::ISha256MacCoproc;
+
+const uint8_t Factory::masterSecret[] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x21,
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x31, 0x32 };
-const std::uint8_t Factory::invalidMasterSecret[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+const uint8_t Factory::invalidMasterSecret[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
bool Factory::provision(DS2465 & ds2465)
{
- bool result = (ds2465.setMasterSecret(masterSecret) == ISha256MacCoprocessor::Success);
+ bool result = (ds2465.setMasterSecret(masterSecret) == ISha256MacCoproc::Success);
if (result)
{
SensorNode::AuthData authData;
@@ -124,7 +130,7 @@
result = (sensorNode.ds28e15_22_25.computeSecret(sensorNode.authData.pageNum, false) == OneWireSlave::Success);
// Configure slave secret on DS2465
if (result)
- result = (DS28E15_22_25::computeNextSecret(sensorNode.ds2465, pageData, sensorNode.authData.pageNum, partialSecret, sensorNode.ds28e15_22_25.romId, sensorNode.ds28e15_22_25.manId) == ISha256MacCoprocessor::Success);
+ result = (DS28E15_22_25::computeNextSecret(sensorNode.ds2465, pageData, sensorNode.authData.pageNum, partialSecret, sensorNode.ds28e15_22_25.romId, sensorNode.ds28e15_22_25.manId) == ISha256MacCoproc::Success);
// Select device through Skip ROM
if (result)
result = (sensorNode.ds2465.OWSkipROM() == OneWireMaster::Success);
@@ -139,7 +145,7 @@
{
DS28E15_22_25::Segment blankSegment;
std::memset(blankSegment, SensorNode::defaultPaddingByte, blankSegment.length);
- for (std::size_t i = 0; i < DS28E15_22_25::segmentsPerPage; i++)
+ for (size_t i = 0; i < DS28E15_22_25::segmentsPerPage; i++)
{
result = (sensorNode.ds2465.OWSkipROM() == OneWireMaster::Success);
if (result)
@@ -185,7 +191,7 @@
result = (sensorNode.ds28e15_22_25.computeSecret(sensorNode.authData.pageNum, false) == OneWireSlave::Success);
// Configure slave secret on DS2465
if (result)
- result = (DS28E15_22_25::computeNextSecret(sensorNode.ds2465, pageData, sensorNode.authData.pageNum, partialSecret, sensorNode.ds28e15_22_25.romId, sensorNode.ds28e15_22_25.manId) == ISha256MacCoprocessor::Success);
+ result = (DS28E15_22_25::computeNextSecret(sensorNode.ds2465, pageData, sensorNode.authData.pageNum, partialSecret, sensorNode.ds28e15_22_25.romId, sensorNode.ds28e15_22_25.manId) == ISha256MacCoproc::Success);
return result;
}
\ No newline at end of file
--- a/Factory.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/Factory.hpp Thu May 12 14:40:14 2016 -0500
@@ -34,9 +34,9 @@
#ifndef _FACTORY_HPP
#define _FACTORY_HPP
-#include <cstdint>
+#include <stdint.h>
-class DS2465;
+namespace OneWire { namespace Masters { class DS2465; } }
class SensorNode;
/// Represents the secure factory that will perform the initial provisioning of
@@ -46,7 +46,7 @@
public:
/// Provision the DS2465 on a Controller.
/// @returns True on success.
- bool provision(DS2465 & ds2465);
+ bool provision(OneWire::Masters::DS2465 & ds2465);
/// Provision the DS28E15 on a Sensor Node.
/// @param validSecret True to provision using the valid system secret or false to imitate an invalid Controller.
@@ -54,8 +54,8 @@
bool provision(SensorNode & sensorNode, bool validSecret);
private:
- static const std::uint8_t masterSecret[]; ///< The valid master secret for the system.
- static const std::uint8_t invalidMasterSecret[]; ///< An invalid master secret for example purposes.
+ static const uint8_t masterSecret[]; ///< The valid master secret for the system.
+ static const uint8_t invalidMasterSecret[]; ///< An invalid master secret for example purposes.
};
#endif
\ No newline at end of file
--- a/MAX44009.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/MAX44009.cpp Thu May 12 14:40:14 2016 -0500
@@ -32,11 +32,11 @@
*/
#include "MAX44009.hpp"
-#include "mbed.h"
+#include "I2C.h"
static const int I2C_OK = 0;
-MAX44009::MAX44009(I2C & I2C_interface, uint8_t I2C_address)
+MAX44009::MAX44009(mbed::I2C & I2C_interface, uint8_t I2C_address)
: m_I2C_interface(I2C_interface), m_I2C_address(I2C_address)
{
--- a/MAX44009.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/MAX44009.hpp Thu May 12 14:40:14 2016 -0500
@@ -34,7 +34,7 @@
#ifndef _MAX44009_HPP
#define _MAX44009_HPP
-#include <cstdint>
+#include <stdint.h>
namespace mbed { class I2C; }
@@ -50,7 +50,7 @@
/// @param I2C_interface A configured I2C interface to use for communication.
/// @param I2C_address Device bus address in mbed format.
- MAX44009(mbed::I2C & I2C_interface, std::uint8_t I2C_address);
+ MAX44009(mbed::I2C & I2C_interface, uint8_t I2C_address);
/// Read the current lux from the MAX44009.
/// @returns Success or Hardware_Failure.
@@ -65,7 +65,7 @@
};
mbed::I2C & m_I2C_interface;
- std::uint8_t m_I2C_address;
+ uint8_t m_I2C_address;
};
#endif
--- a/SensorNode.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/SensorNode.cpp Thu May 12 14:40:14 2016 -0500
@@ -33,8 +33,8 @@
#include "SensorNode.hpp"
#include "common.hpp"
-#include "OneWire_Masters/DS2465/DS2465.hpp"
-#include "mbed.h"
+#include "Masters/DS2465/DS2465.h"
+#include "I2C.h"
#ifdef TARGET_MAX32600
#include "max32600.h"
@@ -44,6 +44,12 @@
#include <cstdlib>
#endif
+using OneWire::Masters::OneWireMaster;
+using OneWire::Masters::DS2465;
+using OneWire::OneWireSlave;
+using OneWire::Authenticators::DS28E15_22_25;
+using OneWire::Authenticators::ISha256MacCoproc;
+
bool SensorNode::rngInitialized = false;
void SensorNode::initializeRng()
@@ -57,7 +63,7 @@
#endif
}
-SensorNode::SensorNode(I2C & i2c, std::uint8_t ds7505_i2c_addr, std::uint8_t max44009_i2c_addr, DS2465 & ds2465)
+SensorNode::SensorNode(mbed::I2C & i2c, uint8_t ds7505_i2c_addr, uint8_t max44009_i2c_addr, DS2465 & ds2465)
: m_initialLux(1), ds28e15_22_25(ds2465), ds7505(i2c, ds7505_i2c_addr), max44009(i2c, max44009_i2c_addr), ds2465(ds2465)
{
if (!rngInitialized)
@@ -84,7 +90,7 @@
// Calculate secret
if (result)
{
- result = (DS28E15_22_25::computeNextSecret(ds2465, pageData, authData.pageNum, scratchpad, ds28e15_22_25.romId, ds28e15_22_25.manId) == ISha256MacCoprocessor::Success);
+ result = (DS28E15_22_25::computeNextSecret(ds2465, pageData, authData.pageNum, scratchpad, ds28e15_22_25.romId, ds28e15_22_25.manId) == ISha256MacCoproc::Success);
}
return result;
}
@@ -136,7 +142,7 @@
#else
std::srand(userEntropy);
#endif
- for (std::size_t i = 0; i < challenge.length; i++)
+ for (size_t i = 0; i < challenge.length; i++)
{
#ifdef TARGET_MAX32600
challenge[i] = MXC_TPU->prng_rnd_num;
@@ -160,7 +166,7 @@
return false;
// Compute expected MAC
DS28E15_22_25::Mac controllerMac;
- if (DS28E15_22_25::computeAuthMac(ds2465, pageData, authData.pageNum, challenge, ds28e15_22_25.romId, ds28e15_22_25.manId, controllerMac) != ISha256MacCoprocessor::Success)
+ if (DS28E15_22_25::computeAuthMac(ds2465, pageData, authData.pageNum, challenge, ds28e15_22_25.romId, ds28e15_22_25.manId, controllerMac) != ISha256MacCoproc::Success)
return false;
// Check if authentic
return (nodeMac == controllerMac);
--- a/SensorNode.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/SensorNode.hpp Thu May 12 14:40:14 2016 -0500
@@ -34,16 +34,19 @@
#ifndef _SENSORNODE_HPP
#define _SENSORNODE_HPP
-#include <cstdint>
+#include <stdint.h>
#include <cstring>
#include "DS7505.hpp"
#include "MAX44009.hpp"
-#include "OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp"
+#include "Authenticators/DS28E15_22_25/DS28E15_22_25.h"
-class DS2465;
-class RomId;
class SensorData;
+namespace OneWire
+{
+ class RomId;
+ namespace Masters { class DS2465; }
+}
namespace mbed { class I2C; }
/// Interface to the Authenticated Sensor Node peripheral board.
@@ -62,7 +65,7 @@
/// @param ds7505_i2c_addr I2C bus address of the DS7505 in mbed format.
/// @param max44009_i2c_addr I2C bus address of the MAX44009 in mbed format.
/// @param ds2465 Interface to DS2465 on the Controller.
- SensorNode(mbed::I2C & i2c, std::uint8_t ds7505_i2c_addr, std::uint8_t max44009_i2c_addr, DS2465 & ds2465);
+ SensorNode(mbed::I2C & i2c, uint8_t ds7505_i2c_addr, uint8_t max44009_i2c_addr, OneWire::Masters::DS2465 & ds2465);
/// Detect if an authentic Sensor Node is connected.
/// @param userEntropy Additional entropy to supply to the RNG.
@@ -81,7 +84,7 @@
bool readSensorData(SensorData & sensorData);
/// Get the ROM ID for this sensor node.
- const RomId & romId() const { return ds28e15_22_25.romId; }
+ const OneWire::RomId & romId() const { return ds28e15_22_25.romId; }
/// Get the initial lux measurement for this sensor node.
double initialLux() const { return m_initialLux; }
@@ -93,9 +96,9 @@
/// Authenticated data stored in DS28E15.
struct AuthData
{
- static const std::uint8_t initialFilterLife = 100;
- DS28E15_22_25::Segment segment;
- std::uint8_t & filterLife;
+ static const uint8_t initialFilterLife = 100;
+ OneWire::Authenticators::DS28E15_22_25::Segment segment;
+ uint8_t & filterLife;
unsigned int pageNum, segmentNum;
AuthData() : filterLife(segment[0]), pageNum(0), segmentNum(0) { reset(); }
@@ -108,7 +111,7 @@
};
/// Padding value used in creation of the Slave Secret.
- static const std::uint8_t defaultPaddingByte = 0x00;
+ static const uint8_t defaultPaddingByte = 0x00;
/// Indicates hardware RNG is initialized.
static bool rngInitialized;
@@ -123,10 +126,10 @@
AuthData authData;
// Hardware interfaces
- DS28E15_22_25 ds28e15_22_25; ///< DS28E15 for authentication.
+ OneWire::Authenticators::DS28E15_22_25 ds28e15_22_25; ///< DS28E15 for authentication.
DS7505 ds7505; ///< DS7505 temperature sensor.
MAX44009 max44009; ///< MAX44009 optical light sensor.
- DS2465 & ds2465; ///< Interface to DS2465 on Controller.
+ OneWire::Masters::DS2465 & ds2465; ///< Interface to DS2465 on Controller.
/// Initialize sensors for measurement.
/// @returns True on success.
--- a/WebServerInterface.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/WebServerInterface.cpp Thu May 12 14:40:14 2016 -0500
@@ -35,9 +35,12 @@
#include "WebServerInterface.hpp"
#include "ESP8266.hpp"
-#include "OneWire_Masters/ISha256MacCoprocessor.hpp"
+#include "Authenticators/ISha256MacCoproc.h"
#include "common.hpp"
-#include "mbed.h"
+#include "Serial.h"
+#include "wait_api.h"
+
+using OneWire::Authenticators::ISha256MacCoproc;
const char WebServerInterface::wifiSsid[] = "WifiSsid";
const char WebServerInterface::wifiPassword[] = "WifiPassword";
@@ -53,17 +56,17 @@
static const char sessionIdKey[] = "SessionId";
// Authentication MAC constants
-static const std::size_t challengeLen = 32;
-static const std::uint8_t defaultPaddingByte = 0x00;
+static const size_t challengeLen = 32;
+static const uint8_t defaultPaddingByte = 0x00;
/// Select the Transport Secret for the web server in the Controller.
/// @returns True on success.
-static bool setHttpPostSecret(ISha256MacCoprocessor & MacCoproc)
+static bool setHttpPostSecret(ISha256MacCoproc & MacCoproc)
{
- ISha256MacCoprocessor::DevicePage::Buffer fillData;
- std::memset(fillData, defaultPaddingByte, ISha256MacCoprocessor::DevicePage::length);
- // static_assert(ISha256MacCoprocessor::DevicePage::length > ISha256MacCoprocessor::SlaveSecretData::length);
- return (MacCoproc.computeSlaveSecret(fillData, fillData, reinterpret_cast<const ISha256MacCoprocessor::SlaveSecretData::Buffer &>(fillData)) == ISha256MacCoprocessor::Success);
+ ISha256MacCoproc::DevicePage::Buffer fillData;
+ std::memset(fillData, defaultPaddingByte, ISha256MacCoproc::DevicePage::length);
+ // static_assert(ISha256MacCoproc::DevicePage::length > ISha256MacCoproc::SlaveSecretData::length);
+ return (MacCoproc.computeSlaveSecret(fillData, fillData, reinterpret_cast<const ISha256MacCoproc::SlaveSecretData::Buffer &>(fillData)) == ISha256MacCoproc::Success);
}
WebServerInterface::WebServerInterface(ESP8266 & esp8266, mbed::Serial * pc)
@@ -121,11 +124,11 @@
/// @param input Message array used for MAC calculation.
/// @param ilen Length of array input.
/// @param output Calculated MAC output.
-static void calculateHttpPostMac(const ISha256MacCoprocessor & macCoproc, const std::uint8_t * input, std::size_t ilen, ISha256MacCoprocessor::Mac & output)
+static void calculateHttpPostMac(const ISha256MacCoproc & macCoproc, const uint8_t * input, size_t ilen, ISha256MacCoproc::Mac & output)
{
- ISha256MacCoprocessor::DeviceScratchpad block;
- std::size_t index = 0;
- ISha256MacCoprocessor::AuthMacData padding;
+ ISha256MacCoproc::DeviceScratchpad block;
+ size_t index = 0;
+ ISha256MacCoproc::AuthMacData padding;
std::memset(padding, defaultPaddingByte, padding.length);
std::memset(output, defaultPaddingByte, output.length); // Set initial hash value
while (index < ilen)
@@ -156,10 +159,10 @@
/// @param challenge Challenge previously received from web server for use in authentication MAC.
/// @returns POST request string.
static std::string formatHttpPost(const std::string & host, const std::string & path, const std::string & sessionId,
- const ISha256MacCoprocessor & macCoproc, PostEvent event, const std::string & initialPostBody,
- const std::uint8_t (&challenge)[challengeLen])
+ const ISha256MacCoproc & macCoproc, PostEvent event, const std::string & initialPostBody,
+ const uint8_t (&challenge)[challengeLen])
{
- const std::size_t headerReserve = 115, bodyReserve = 200;
+ const size_t headerReserve = 115, bodyReserve = 200;
std::string httpPost;
httpPost.reserve(initialPostBody.length() + headerReserve + bodyReserve);
@@ -202,11 +205,11 @@
}
// Combine initial post body with initial secret and hash
- std::vector<std::uint8_t> hashInput;
+ std::vector<uint8_t> hashInput;
hashInput.reserve(challengeLen + httpPost.length());
hashInput.insert(hashInput.end(), challenge, challenge + challengeLen);
hashInput.insert(hashInput.end(), httpPost.begin(), httpPost.end());
- ISha256MacCoprocessor::Mac mac;
+ ISha256MacCoproc::Mac mac;
calculateHttpPostMac(macCoproc, &hashInput[0], hashInput.size(), mac);
char contentLen[5];
@@ -241,11 +244,11 @@
return httpPost;
}
-bool WebServerInterface::authPostHttpEvent(ISha256MacCoprocessor & macCoproc, PostEvent event, const std::string & postData, bool setSecret)
+bool WebServerInterface::authPostHttpEvent(ISha256MacCoproc & macCoproc, PostEvent event, const std::string & postData, bool setSecret)
{
const std::string challengeSearch(newline + newline);
bool result;
- std::uint8_t challenge[challengeLen];
+ uint8_t challenge[challengeLen];
std::string response;
std::memset(challenge, defaultPaddingByte, challengeLen);
@@ -292,11 +295,11 @@
esp8266.closeConnection();
// Parse challenge from response
- std::size_t challengePos = response.find(challengeSearch);
+ size_t challengePos = response.find(challengeSearch);
if ((challengePos != std::string::npos) && ((challengePos + challengeSearch.length() + (challengeLen * charsPerByte)) <= response.length()))
{
challengePos += challengeSearch.length();
- for (std::size_t i = 0; i < challengeLen; i++)
+ for (size_t i = 0; i < challengeLen; i++)
{
std::sscanf(response.substr(challengePos + (i * charsPerByte), charsPerByte).c_str(), "%2hhx", &challenge[i]);
}
--- a/WebServerInterface.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/WebServerInterface.hpp Thu May 12 14:40:14 2016 -0500
@@ -44,8 +44,8 @@
};
namespace mbed { class Serial; }
+namespace OneWire { namespace Authenticators { class ISha256MacCoproc; } }
class ESP8266;
-class ISha256MacCoprocessor;
struct SensorData;
/// Network interface to the web server supporting authenticated posting of event
@@ -70,7 +70,7 @@
/// @postData Message body as determined by the event message type.
/// @setSecret True if the Transport Secret needs to be selected in the coprocessor.
/// @returns True on success.
- bool authPostHttpEvent(ISha256MacCoprocessor & macCoproc, PostEvent event, const std::string & postData, bool setSecret);
+ bool authPostHttpEvent(OneWire::Authenticators::ISha256MacCoproc & macCoproc, PostEvent event, const std::string & postData, bool setSecret);
/// Format sensor data as text suitable for use in a POST body.
/// @param sensorData Sensor data to format.
--- a/common.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/common.cpp Thu May 12 14:40:14 2016 -0500
@@ -33,9 +33,9 @@
#include "common.hpp"
-const std::size_t charsPerByte = 2;
+const size_t charsPerByte = 2;
-std::string byteArrayToHexString(const std::uint8_t * byteArray, std::size_t byteArraySize)
+std::string byteArrayToHexString(const uint8_t * byteArray, size_t byteArraySize)
{
std::string hexString;
hexString.reserve(byteArraySize * charsPerByte);
@@ -43,10 +43,10 @@
return hexString;
}
-void byteArrayToHexString(const std::uint8_t * byteArray, std::size_t byteArraySize, std::string & hexString)
+void byteArrayToHexString(const uint8_t * byteArray, size_t byteArraySize, std::string & hexString)
{
char hexBuf[charsPerByte + 1];
- for (std::size_t i = 0; i < byteArraySize; i++)
+ for (size_t i = 0; i < byteArraySize; i++)
{
std::snprintf(hexBuf, (sizeof(hexBuf) / sizeof(hexBuf[0])), "%2.2X", byteArray[i]);
hexString.append(hexBuf, charsPerByte);
--- a/common.hpp Wed Apr 20 20:13:33 2016 +0000
+++ b/common.hpp Thu May 12 14:40:14 2016 -0500
@@ -35,28 +35,29 @@
#define _COMMON_HPP
#include <string>
-#include <cstdint>
+#include <stdint.h>
+#include <stddef.h>
/// Contains a set of sensor measurements.
struct SensorData
{
static const std::int8_t tempAlarmLevel = 26;
- static const std::uint8_t filterLifeAlarmLevel = 20;
+ static const uint8_t filterLifeAlarmLevel = 20;
std::int8_t temp;
- std::uint8_t filterLife;
+ uint8_t filterLife;
bool tempAlarm() const { return (temp >= tempAlarmLevel); }
bool filterLifeAlarm() const { return (filterLife <= filterLifeAlarmLevel); }
};
/// Characters per byte for hex data.
-extern const std::size_t charsPerByte;
+extern const size_t charsPerByte;
/// Creates a new hex string from a byte array.
-std::string byteArrayToHexString(const std::uint8_t * byteArray, std::size_t byteArraySize);
+std::string byteArrayToHexString(const uint8_t * byteArray, size_t byteArraySize);
/// Appends a hex string created from a byte array to an existing string.
-void byteArrayToHexString(const std::uint8_t * byteArray, std::size_t byteArraySize, std::string & hexString);
+void byteArrayToHexString(const uint8_t * byteArray, size_t byteArraySize, std::string & hexString);
#endif
\ No newline at end of file
--- a/main.cpp Wed Apr 20 20:13:33 2016 +0000
+++ b/main.cpp Thu May 12 14:40:14 2016 -0500
@@ -37,12 +37,15 @@
#include "WebServerInterface.hpp"
#include "Factory.hpp"
#include "SensorNode.hpp"
-#include "OneWire_Masters/DS2465/DS2465.hpp"
+#include "Masters/DS2465/DS2465.h"
#include "Display.hpp"
-#include "RomId.hpp"
+#include "RomId.h"
#include "ESP8266.hpp"
#include "mbed.h"
+using OneWire::RomId;
+using OneWire::Masters::DS2465;
+
/// Main status for the program.
enum Status
{
@@ -63,7 +66,7 @@
/// Configuration options.
static const unsigned int webPostIntervalMs = 10000;
static const unsigned int webPostRetryIntervalMs = 1000;
-static const std::uint8_t maxConsecutiveWebPostErrors = 3;
+static const uint8_t maxConsecutiveWebPostErrors = 3;
/// @}
/// @{
@@ -93,7 +96,7 @@
static unsigned int randomSeed = 0; ///< Create extra entropy for challenge.
static Status currentStatus = InitializingController;
static bool result = false;
-static std::uint8_t consecutiveWebPostErrors = 0; ///< Account for a few network errors in case of flaky connection.
+static uint8_t consecutiveWebPostErrors = 0; ///< Account for a few network errors in case of flaky connection.
static Timer webPostTimer; ///< Software timer to track web posting interval.
static Timer retryTimer; ///< Software timer to track authentication retries.
MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification