Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Remove Entropy Dependency
Browse files Browse the repository at this point in the history
Use strict default MAC without random assignment
Adjust EEPROM storage and allow full edit of MAC address
  • Loading branch information
Steven Dillingham authored and Steven Dillingham committed Jul 7, 2014
1 parent 5733f69 commit 4598a08
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
20 changes: 7 additions & 13 deletions Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <StandardCplusplus.h>
#include <serstream>
#include <EEPROM.h>
#include <Entropy.h>
#include <SD.h>

const char* configFilename = "config/network.cfg";
const char* Network::configFilename = "config/network.cfg";
uint8_t Network::mac_oui[3] = { 0x90, 0xA2, 0xDA };

Network::Network() {

// The first three octets of the MAC address are the "Organizationally Unique Identifier" or
// OUI. The UID from GHEO Sa, which is the correct one for Arduino Ethernet is 90:A2:DA
// This is the signature that is used to store the settings in EEPROM if there is no
// network.cfg file.
uint8_t mac_oui[3] = { 0x90, 0xA2, 0xDA };

// Default settings
use_dhcp = true;
memcpy(mac, mac_oui, 3);
memset(&mac[3], 0, 3);
memset(&mac[3], 0x81, 3);

ip = IPAddress(192, 168, 1, 2);
subnet = IPAddress(255, 255, 255, 0);
Expand Down Expand Up @@ -75,21 +74,15 @@ void Network::Initialize()
}
else
{
if (EEPROM.read(1) == mac[0] && EEPROM.read(2) == mac[1] && EEPROM.read(3) == mac[2])
if (EEPROM.read(1) == mac_oui[0] && EEPROM.read(2) == mac_oui[1] && EEPROM.read(3) == mac_oui[2])
{
// The settings have been written in EEPROM
cout << F("read from EEPROM") << endl;;
readSettings();
}
else
{
// Randomize the last three bytes of the MAC address
Entropy.Initialize();
for (int i = 3; i < 6; i++) {
mac[i] = Entropy.random(255);
}

// Save the settings to EEPROM
// Save the default settings to EEPROM
writeSettings();

cout << F("stored to EEPROM") << endl;
Expand Down Expand Up @@ -249,7 +242,7 @@ void Network::saveNetworkConfiguration(Stream& stream) {
*/
void Network::readSettings() {
int j = 4;
j+= readEEPROM(&mac[3], j, 3 * sizeof(uint8_t));
j+= readEEPROM(&mac[0], j, sizeof(mac) * sizeof(uint8_t));
j+= readEEPROM(&use_dhcp, j, sizeof(bool));
j+= readEEPROM(&ip, j);
j+= readEEPROM(&subnet, j);
Expand All @@ -264,6 +257,7 @@ void Network::readSettings() {
*/
void Network::writeSettings() {
int j = 1;
j+= writeEEPROM(mac_oui, j, sizeof(mac_oui) * sizeof(uint8_t));
j+= writeEEPROM(mac, j, sizeof(mac) * sizeof(uint8_t));
j+= writeEEPROM(&use_dhcp, j, sizeof(bool));
j+= writeEEPROM(&ip, j);
Expand Down
2 changes: 2 additions & 0 deletions Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Network {
void objectToArray(aJsonObject* object, IPAddress* ip);

public:
static const char* configFilename;
static uint8_t mac_oui[3];
bool use_dhcp;
uint8_t dhcp_refresh_minutes;
uint8_t mac[6];
Expand Down
1 change: 0 additions & 1 deletion dctt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "WebServer.h"

#include <EEPROM.h>
#include <Entropy.h>

#include <SD.h>

Expand Down
12 changes: 6 additions & 6 deletions sd_card/web/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,12 @@
</div>
<div class="col-md-6">
<table style="border-collapse:separate;border-spacing:10px"><tr>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[0]" ng-disabled="network.EEPROM"></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[1]" ng-disabled="network.EEPROM"></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[2]" ng-disabled="network.EEPROM"></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[3]" </td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[4]" </td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[5]" </td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[0]" ></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[1]" ></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[2]" ></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[3]" ></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[4]" ></td>
<td><input type="input" class="form-control hexNumber" maxlength="2" placeholder="00" ng-model="MAC[5]" ></td>
</tr></table>
</div>
</div>
Expand Down

0 comments on commit 4598a08

Please sign in to comment.