blob: 4bf9bd817e5f6fa3df21ebfc14101cf1e30f66af [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{
Jimmy Dub044cc12017-06-06 11:58:54 -050019 unsigned char enetaddr[ARP_HLEN];
Michael Walle99e139d2012-06-05 11:33:15 +000020 unsigned int seed;
21
22 /* get our mac */
Jimmy Dub044cc12017-06-06 11:58:54 -050023 memcpy(enetaddr, eth_get_ethaddr(), ARP_HLEN);
Michael Walle99e139d2012-06-05 11:33:15 +000024
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__ */