[lib][minip] add utility routine to generate a random mac address

-Move both stm32f7xx targets to this mechanism
This commit is contained in:
Travis Geiselbrecht
2015-10-15 11:40:12 -07:00
parent af08e2c0ca
commit 95bae7b1e7
4 changed files with 21 additions and 25 deletions

View File

@@ -84,4 +84,7 @@ static inline status_t tcp_accept(tcp_socket_t *listen_socket, tcp_socket_t **ac
return tcp_accept_timeout(listen_socket, accept_socket, INFINITE_TIME);
}
/* utilities */
void gen_random_mac_address(uint8_t *mac_addr);
// vim: set ts=4 sw=4 expandtab:

View File

@@ -86,6 +86,16 @@ void minip_set_ipaddr(const uint32_t addr) {
compute_broadcast_address();
}
void gen_random_mac_address(uint8_t *mac_addr)
{
for (size_t i = 0; i < 6; i++) {
mac_addr[i] = rand() & 0xff;
}
/* unicast and locally administered */
mac_addr[0] &= ~(1<<0);
mac_addr[0] |= (1<<1);
}
/* This function is called by minip to send packets */
tx_func_t minip_tx_handler;
void *minip_tx_arg;

View File

@@ -75,16 +75,8 @@ void target_init(void)
stm32_debug_init();
#if WITH_LIB_MINIP
// make up a mac address
uint8_t mac_addr[6];
for (size_t i = 0; i < sizeof(mac_addr); i++) {
mac_addr[i] = rand() & 0xff;
}
/* unicast and locally administered */
mac_addr[0] &= ~(1<<0);
mac_addr[0] |= (1<<1);
gen_random_mac_address(mac_addr);
eth_init(mac_addr, PHY_DP83848);
/* start minip */

View File

@@ -65,33 +65,24 @@ void target_early_init(void)
BSP_LCD_Init(SDRAM_BASE);
}
static uint8_t* gen_mac_address(void)
{
static uint8_t mac_addr[6];
for (size_t i = 0; i < sizeof(mac_addr); i++) {
mac_addr[i] = rand() & 0xff;
}
mac_addr[5] += 1;
/* unicast and locally administered */
mac_addr[0] &= ~(1<<0);
mac_addr[0] |= (1<<1);
return mac_addr;
}
void target_init(void)
{
uint8_t* mac_addr = gen_mac_address();
stm32_debug_init();
eth_init(mac_addr, PHY_LAN8742A);
qspi_flash_init();
#if WITH_LIB_MINIP
uint8_t mac_addr[6];
gen_random_mac_address(mac_addr);
eth_init(mac_addr, PHY_LAN8742A);
/* start minip */
minip_set_macaddr(mac_addr);
uint32_t ip_addr = IPV4(192, 168, 0, 98);
uint32_t ip_mask = IPV4(255, 255, 255, 0);
uint32_t ip_gateway = IPV4_NONE;
minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
#endif
}