I am implementing software on many arduino and I wanted to know if there is a way to automatically assign the MAC Addresses, rather than hard coding them in. I looked online and it seemed as if you can do it with hardware, but I wanted to know if it is programmed into a chip somewhere. I have the Arduino brand Ethernet shield.
By definition it is not possible to assign the MAC address. AFAIK it is hard coded with an Ethernet port.
That said there exists something called - MAC spoofing - in which one Ethernet device behaves as if it was another one.
Furthermore there are many devices in which you have to assign a MAC address 0xFEEDDEADBEEF is a well known one
problem with spoofing a MAC address is that you can get a MAC address conflict when routing Ethernet packages
This is similar to IP-address conflicts but on the lowest layer of the OSI stack.
That said as long as you keep the traffic in your local network, you won't get serious trouble.
robtillaart:
By definition it is not possible to assign the MAC address. AFAIK it is hard coded with an Ethernet port.
Yes, hard coded. But not at the Ethernet controller level (the MAC isn't burned into the silicon of the controller's die). Something in the circuit tells the Ethernet controller what it's MAC should be (usually some sort of firmware somewhere). With Arduino, we are creating the firmware. Our Ethernet shields are basically bare controllers.
I think a better question (set) should be:
- Is there EEPROM space in the Ethernet controllers that either already has a MAC encoded in it or can be used to store MAC (and/or other configuration)?
- If so, how do we access that EEPROM space?
The answer to the first question should be in the datasheet for the specific Ethernet controller of the shield you are using. In theory, the answer to the second question (if applicable) should also be in the datasheet... (Probably direct SPI queries and responses, I don't think the Ethernet library supports this. I could be wrong though...)
[... MAC spoofing and collision talk snipped ...]
I just looked through a datasheet for the WIZnet w5100 chip (I think that's the one on the Ethernet shield from arduino.cc, and what the Ethernet library expects to talk to through SPI), and I didn't see any indication of nonvolatile memory. Makes me wish the reference design from arduino.cc included an EEPROM somewhere (so the MAC stored in the EEPROM follows the shield). There is an SD slot... So I suppose if you want the MAC to follow the shield, dedicate a (micro)SD card to your shield and store the MAC for the shield in a file on the SD card. Then before you do your Ethernet.begin(), read the MAC from the SD card and feed the result into Ethernet.begin().
I think that is about as automatic as it can get... (Unless I misread the datasheet and the registers aren't volatile memory...)
Okay so it sounds like it is going to be difficult to do the MAC Address thing. The solution might be to store it in a standard format on the SD Card and pull it from that location in the sketch. Would that work?
Regardless, I am sharing information with an online server, and it needs a unique way to identify each arduino. Does such a unique identifier exist inside an arduino that a programmer is able to access?