EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Generate a unique (local) MAC address

Started by karelvergauwe December 13, 2007
Hello,

I have LPC2378 and use Ethernet. I would like to generate random MAC
address to use in my local network.

I tried this by generating randomly 8 bytes and assigning them to my
RTOS. This by using the function rand(). Problem is this always gives
the same numbers (in the same sequence). Then I found I should seed
them with the srand(seed) function. But this isn't any better because I
don't have a unique seed number. Normally the current time is used as
seed number. But When I start I don't have any time...

Is there an other function I could use. Or a unique number (for example
on the cpu or PHY IC of Ethernet)?

thx

An Engineer's Guide to the LPC2100 Series

On Thu, 13 Dec 2007 13:05:08 +0100, you wrote:

>karelvergauwe schrieb:
>
>> Is there an other function I could use. Or a unique number (for example
>> on the cpu or PHY IC of Ethernet)?
>
>Why not grab the first MAC you receive and take it as seed or just
>modify it.

and/or measure the time interval between the first couple of packets - with a 60MHz timer you will
get a good few useful random bits.
If your product has any user-interface, timing of things like button-presses are a good way to shake
up a random seed.
On Thu, 13 Dec 2007 22:15:33 +1100, you wrote:

>Hi,
>
>Could you use an A/D input that is floating.

Floating would be bad as it could easily float to a rail
If it's resistively tied somewhere, maybe with a diode to add a little noise & temperature
dependence, the bottom bit of the ADC should give a fairly noisy signal ( although clock-related
noise may mean you get some fixed patterns.

If you have an RTC crystal, measuring it's startup time would probably be good.

>Just a thought.
>
>Cheers,
>
>Peter.
>karelvergauwe wrote:
>> Hello,
>>
>> I have LPC2378 and use Ethernet. I would like to generate random MAC
>> address to use in my local network.
>>
>> I tried this by generating randomly 8 bytes and assigning them to my
>> RTOS. This by using the function rand(). Problem is this always gives
>> the same numbers (in the same sequence). Then I found I should seed
>> them with the srand(seed) function. But this isn't any better because I
>> don't have a unique seed number. Normally the current time is used as
>> seed number. But When I start I don't have any time...
>>
>> Is there an other function I could use. Or a unique number (for example
>> on the cpu or PHY IC of Ethernet)?
>>
>> thx
>>
>>
>>
karelvergauwe schrieb:

> Is there an other function I could use. Or a unique number (for example
> on the cpu or PHY IC of Ethernet)?

Why not grab the first MAC you receive and take it as seed or just
modify it.

--
42Bastian

Note: SPAM-only account, direct mail to bs42@...
> Is there an other function I could use. Or a unique number (for example
> on the cpu or PHY IC of Ethernet)?
>
> thx
>

I would grab an old ISA or PCI ethernet card out of my junk pile and
steal the MAC from that. I could, if I wish, guarantee the number is
unique in all the world by simply destroying the card.

Richard
>>> I have LPC2378 and use Ethernet. I would like to generate random MAC
>>> address to use in my local network.
>>>
I modified my flash-writing application to write a few random bytes to
the end of flash. I can then read these at run time. This approach is
nice because the same device will always boot up with the same MAC
address, so DHCP and other things will work properly.

-Ed
On Dec 13, 2007 10:08 PM, rtstofer wrote:
>
> > Is there an other function I could use. Or a unique number (for example
> > on the cpu or PHY IC of Ethernet)?
>
> I would grab an old ISA or PCI ethernet card out of my junk pile and
> steal the MAC from that. I could, if I wish, guarantee the number is
> unique in all the world by simply destroying the card.
>

The problem might be that some vendors (say your ISA card
or PCI Ethernet card vendor) are already reusing the MAC
address...
My project is not one time, it's for production. So taking the mac of
an existing PCI card won't work for me.

Taking the first MAC address that comes in won't work neither, because
I have to set my MAC address before I can init my TCP stack (wich is
TCPNet from Keil)

Is there not an unique number in the cpu of lpc? Can I perhaps just
make a pointer, and not initialize it, then just take the value of it.
Would this data be random or will it be '0' if I don't use this space
yet.

Are there no other really random making functions in C???

thx
karelvergauwe wrote:
> My project is not one time, it's for production. So taking the mac of
> an existing PCI card won't work for me.
>
> Taking the first MAC address that comes in won't work neither, because
> I have to set my MAC address before I can init my TCP stack (wich is
> TCPNet from Keil)
>
> Is there not an unique number in the cpu of lpc? Can I perhaps just
> make a pointer, and not initialize it, then just take the value of it.
> Would this data be random or will it be '0' if I don't use this space
> yet.
>
> Are there no other really random making functions in C???
>
> thx

For production purposes you should formally acquire a block of
addresses. A block of 4096 is only $550. See
http://standards.ieee.org/regauth/oui/pilot-ind.html

Regards
-Bill Knight
R O SoftWare
Mike Harrison wrote:
> On Thu, 13 Dec 2007 16:12:50 -0000, you wrote:

>> My project is not one time, it's for production. So taking the mac of
>> an existing PCI card won't work for me.

> If it's for production, shouldn't you really be buying a proper
> allocation of addresses ?
Exactly.

Memfault Beyond the Launch