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

Dependencies:   MaximInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SensorNode.hpp Source File

SensorNode.hpp

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************/
00032 
00033 #ifndef SENSORNODE_HPP
00034 #define SENSORNODE_HPP
00035 
00036 #include <stdint.h>
00037 #include <MaximInterface/Devices/DS28E15_22_25.hpp>
00038 #include <MaximInterface/Utilities/RomId.hpp>
00039 #include <MaximInterface/Utilities/ManId.hpp>
00040 #include "DS7505.hpp"
00041 #include "MAX44009.hpp"
00042 
00043 class SensorData;
00044 namespace MaximInterface { class DS2465; }
00045 namespace mbed { class I2C; }
00046 
00047 /// Interface to the Authenticated Sensor Node peripheral board.
00048 class SensorNode {
00049 public:
00050   enum State  {
00051     UnableToCommunicate, ///< I2C or 1-Wire communication failure.
00052     NotProvisioned,      ///< DS28E15 has not been provisioned.
00053     NotAuthentic,        ///< DS28E15 is not authentic.
00054     Authentic            ///< DS218E15 is authentic.
00055   };
00056 
00057   /// @param i2c Configured I2C communication interface.
00058   /// @param ds7505_i2c_addr I2C bus address of the DS7505 in mbed format.
00059   /// @param max44009_i2c_addr I2C bus address of the MAX44009 in mbed format.
00060   /// @param ds2465 Interface to DS2465 on the Controller.
00061   SensorNode (mbed::I2C & i2c, uint8_t ds7505_i2c_addr,
00062              uint8_t max44009_i2c_addr, MaximInterface::DS2465 & ds2465);
00063 
00064   /// Detect if an authentic Sensor Node is connected.
00065   /// @param userEntropy Additional entropy to supply to the RNG.
00066   /// @returns Authentic on success.
00067   State  detect(unsigned int userEntropy);
00068 
00069   /// Read the current temperature and filter life measurements with authentication.
00070   /// @param userEntropy Additional entropy to supply to the RNG.
00071   /// @param sensorData Measurements output location.
00072   /// @returns Authentic on success.
00073   State  authenticatedReadSensorData(unsigned int userEntropy,
00074                                     SensorData & sensorData);
00075 
00076   /// Reads the current temperature and filter life measurements.
00077   /// @param sensorData Measurements output location.
00078   /// @returns True on success or false if unable to communicate with a sensor.
00079   bool readSensorData(SensorData & sensorData);
00080 
00081   /// Get the ROM ID for this sensor node.
00082   const MaximInterface::RomId romId() const { return romId_; }
00083 
00084   /// Get the initial lux measurement for this sensor node.
00085   double initialLux() const { return initialLux_; }
00086 
00087   // Grant access to hardware interfaces for provisioning.
00088   friend bool provisionCoprocessor(MaximInterface::DS2465 & ds2465);
00089   friend bool provisionSensorNode(SensorNode & sensorNode, bool validSecret);
00090 
00091 private:
00092   /// Authenticated data stored in DS28E15.
00093   struct AuthData {
00094     static const uint8_t initialFilterLife = 100;
00095     MaximInterface::DS28E15::Segment segment;
00096     int pageNum, segmentNum;
00097 
00098     uint8_t & filterLife() { return segment[0]; }
00099     const uint8_t & filterLife() const { return segment[0]; }
00100 
00101     AuthData() : pageNum(0), segmentNum(0) { reset(); }
00102 
00103     void reset() {
00104       segment.fill(0);
00105       filterLife() = initialFilterLife;
00106     }
00107   };
00108 
00109   /// Padding value used in creation of the Slave Secret.
00110   static const uint8_t defaultPaddingByte = 0x00;
00111 
00112   static const MaximInterface::ManId manId;
00113 
00114   /// Indicates hardware RNG is initialized.
00115   static bool rngInitialized;
00116   // Initialize the hardware RNG.
00117   static void initializeRng();
00118 
00119   /// Initial lux measurement taken on initialization.
00120   /// Assumed to be the maximum intensity that will be observed.
00121   double initialLux_;
00122 
00123   /// Authenticated data stored on the DS28E15.
00124   AuthData authData;
00125 
00126   // Hardware interfaces
00127   MaximInterface::DS2465 & ds2465; ///< Interface to DS2465 on Controller.
00128   MaximInterface::DS28E15 ds28e15; ///< DS28E15 for authentication.
00129   MaximInterface::RomId romId_;
00130   DS7505 ds7505;     ///< DS7505 temperature sensor.
00131   MAX44009 max44009; ///< MAX44009 optical light sensor.
00132 
00133   /// Initialize sensors for measurement.
00134   /// @returns True on success.
00135   bool initializeSensors();
00136 
00137   /// Select the Slave Secret for this Sensor Node in the Controller.
00138   /// @returns True on success.
00139   bool setSecret();
00140 
00141   /// Check if the Sensor Board is provisioned.
00142   /// @param provisioned True if the sensor board is provisioned.
00143   /// @returns True if provisioning check was successful.
00144   bool checkProvisioned(bool & provisioned);
00145 
00146   /// Check if the Sensor Board is authentic.
00147   /// @param userEntropy Additional entropy to supply to the RNG.
00148   /// @returns True if the Sensor Board passed the authentication check.
00149   bool checkAuthentic(unsigned int userEntropy);
00150 
00151   /// Checks if the authenticated data stored in the DS28E15 needs to be updated.
00152   /// Updates the authenticated data if necessary.
00153   /// @param sensorData Current sensor data to check.
00154   /// @returns True on success.
00155   bool checkAndWriteAuthData(SensorData & sensorData);
00156 };
00157 
00158 #endif