Merge pull request #837 from authmillenon/auto-init-addresses

auto_init: Initialize link-layer addresses from CPU ID
dev/timer
Oleg Hahm 9 years ago
commit be1fde1557

@ -89,6 +89,7 @@ endif
ifneq (,$(filter net_if,$(USEMODULE)))
USEMODULE += transceiver
USEMODULE += net_help
USEMODULE += hashes
endif
ifneq (,$(filter ccn_lite,$(USEMODULE)))

@ -64,11 +64,20 @@
#endif
#ifdef MODULE_NET_IF
#include "cpu-conf.h"
#include "cpu.h"
#include "kernel.h"
#include "net_if.h"
#include "transceiver.h"
#include "net_help.h"
#include "hashes.h"
#include "periph/cpuid.h"
#endif
#define ENABLE_DEBUG (0)
#if ENABLE_DEBUG
#define DEBUG_ENABLED
#endif
#include "debug.h"
#ifndef CONF_RADIO_ADDR
@ -79,46 +88,10 @@
#define CONF_PAN_ID (0xabcd)
#endif
void auto_init(void)
{
#ifdef MODULE_VTIMER
DEBUG("Auto init vtimer module.\n");
vtimer_init();
#endif
#ifdef MODULE_UART0
DEBUG("Auto init uart0 module.\n");
board_uart0_init();
#endif
#ifdef MODULE_RTC
DEBUG("Auto init rtc module.\n");
rtc_init();
rtc_enable();
#endif
#ifdef MODULE_SHT11
DEBUG("Auto init SHT11 module.\n");
sht11_init();
#endif
#ifdef MODULE_GPIOINT
DEBUG("Auto init gpioint module.\n");
gpioint_init();
#endif
#ifdef MODULE_CC110X
DEBUG("Auto init CC1100 module.\n");
#ifndef MODULE_TRANSCEIVER
cc1100_init();
#endif
#endif
#ifdef MODULE_LTC4150
DEBUG("Auto init ltc4150 module.\n");
ltc4150_init();
#endif
#ifdef MODULE_MCI
DEBUG("Auto init mci module.\n");
MCI_initialize();
#endif
#ifdef MODULE_NET_IF
void auto_init_net_if(void)
{
int iface;
DEBUG("Auto init net_if module.\n");
transceiver_type_t transceivers = 0;
#ifdef MODULE_AT86RF231
transceivers |= TRANSCEIVER_AT86RF231;
@ -141,16 +114,52 @@ void auto_init(void)
net_if_init();
if (transceivers != 0) {
#if CPUID_ID_LEN && defined(MODULE_HASHES)
uint8_t cpuid[CPUID_ID_LEN];
cpuid_get(cpuid);
#endif
transceiver_init(transceivers);
transceiver_start();
iface = net_if_init_interface(0, transceivers);
#if CPUID_ID_LEN && defined(MODULE_HASHES)
net_if_eui64_t eui64;
uint32_t hash_h = djb2_hash(cpuid, CPUID_ID_LEN / 2);
#if CPUID_ID_LEN % 2 == 0
uint32_t hash_l = djb2_hash(&(cpuid[CPUID_ID_LEN / 2]),
CPUID_ID_LEN / 2);
#else /* CPUID_ID_LEN % 2 == 0 */
uint32_t hash_l = djb2_hash(&(cpuid[CPUID_ID_LEN / 2]),
CPUID_ID_LEN / 2 + 1);
#endif /* CPUID_ID_LEN % 2 == 0 */
memcpy(&(eui64.uint32[0]), &hash_h, sizeof(uint32_t));
memcpy(&(eui64.uint32[1]), &hash_l, sizeof(uint32_t));
net_if_set_eui64(iface, &eui64);
#ifdef DEBUG_ENABLED
DEBUG("Auto init radio long address on interface %d to ", iface);
for (size_t i = 0; i < 8; i++) {
printf("%02x ", eui64.uint8[i]);
}
DEBUG("\n");
#endif /* DEBUG_ENABLED */
#undef CONF_RADIO_ADDR
uint16_t hwaddr = HTONS((uint16_t)hash_l);
net_if_set_hardware_address(iface, hwaddr);
DEBUG("Auto init radio address on interface %d to 0x%04x\n", iface, hwaddr);
#else /* CPUID_ID_LEN && defined(MODULE_HASHES) */
if (net_if_set_src_address_mode(iface, NET_IF_TRANS_ADDR_M_SHORT)) {
DEBUG("Auto init source address mode to short on interface %d\n",
iface);
}
else {
net_if_set_hardware_address(iface, NET_IF_TRANS_ADDR_M_LONG);
net_if_set_src_address_mode(iface, NET_IF_TRANS_ADDR_M_LONG);
DEBUG("Auto init source address mode to long on interface %d\n",
iface);
}
@ -160,6 +169,7 @@ void auto_init(void)
DEBUG("Change this value at compile time with macro CONF_RADIO_ADDR\n");
net_if_set_hardware_address(iface, CONF_RADIO_ADDR);
}
#endif /* CPUID_ID_LEN && defined(MODULE_HASHES) */
if (net_if_get_pan_id(iface) <= 0) {
DEBUG("Auto init PAN ID on interface %d to 0x%04x\n", iface, CONF_PAN_ID);
@ -174,12 +184,54 @@ void auto_init(void)
else {
iface = -1;
}
}
#endif /* MODULE_NET_IF */
void auto_init(void)
{
#ifdef MODULE_VTIMER
DEBUG("Auto init vtimer module.\n");
vtimer_init();
#endif
#ifdef MODULE_UART0
DEBUG("Auto init uart0 module.\n");
board_uart0_init();
#endif
#ifdef MODULE_RTC
DEBUG("Auto init rtc module.\n");
rtc_init();
rtc_enable();
#endif
#ifdef MODULE_SHT11
DEBUG("Auto init SHT11 module.\n");
sht11_init();
#endif
#ifdef MODULE_GPIOINT
DEBUG("Auto init gpioint module.\n");
gpioint_init();
#endif
#ifdef MODULE_CC110X
DEBUG("Auto init CC1100 module.\n");
#ifndef MODULE_TRANSCEIVER
cc1100_init();
#endif
#endif
#ifdef MODULE_LTC4150
DEBUG("Auto init ltc4150 module.\n");
ltc4150_init();
#endif
#ifdef MODULE_MCI
DEBUG("Auto init mci module.\n");
MCI_initialize();
#endif
#ifdef MODULE_NET_IF
DEBUG("Auto init net_if module.\n");
auto_init_net_if();
#endif
#ifdef MODULE_SIXLOWPAN
DEBUG("Auto init 6LoWPAN module.\n");
sixlowpan_lowpan_init();
#endif
#endif
#ifdef MODULE_PROFILING
extern void profiling_init(void);
profiling_init();

Loading…
Cancel
Save