blob: ba9d0642cf231ab2ed14c162f2c7fb975f315574 [file] [log] [blame]
Joe Hershbergereafc8db2012-05-23 07:57:58 +00001/*
2 * Copied from LiMon - BOOTP.
3 *
4 * Copyright 1994, 1995, 2000 Neil Russell.
5 * (See License)
6 * Copyright 2000 Paolo Scaffardi
7 */
8
9#ifndef __NET_RAND_H__
10#define __NET_RAND_H__
11
Michael Walle99e139d2012-06-05 11:33:15 +000012#include <common.h>
Joe Hershbergereafc8db2012-05-23 07:57:58 +000013
14/*
Michael Walle99e139d2012-06-05 11:33:15 +000015 * Return a seed for the PRNG derived from the eth0 MAC address.
Joe Hershbergereafc8db2012-05-23 07:57:58 +000016 */
Michael Walle99e139d2012-06-05 11:33:15 +000017static inline unsigned int seed_mac(void)
18{
19 unsigned char enetaddr[6];
20 unsigned int seed;
21
22 /* get our mac */
23 eth_getenv_enetaddr("ethaddr", enetaddr);
24
25 seed = enetaddr[5];
26 seed ^= enetaddr[4] << 8;
27 seed ^= enetaddr[3] << 16;
28 seed ^= enetaddr[2] << 24;
29 seed ^= enetaddr[1];
30 seed ^= enetaddr[0] << 8;
31
32 return seed;
33}
Joe Hershbergereafc8db2012-05-23 07:57:58 +000034
35/*
Michael Walle99e139d2012-06-05 11:33:15 +000036 * Seed the random number generator using the eth0 MAC address.
Joe Hershbergereafc8db2012-05-23 07:57:58 +000037 */
Michael Walle99e139d2012-06-05 11:33:15 +000038static inline void srand_mac(void)
39{
40 srand(seed_mac());
41}
Joe Hershbergereafc8db2012-05-23 07:57:58 +000042
43#endif /* __NET_RAND_H__ */