2013-06-18 17:21:38 +02:00
|
|
|
/**
|
2013-06-22 05:11:53 +02:00
|
|
|
* Auto initialization for used modules
|
2013-06-18 17:21:38 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 INRIA.
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-06-18 17:21:38 +02:00
|
|
|
*
|
|
|
|
* @ingroup auto_init
|
|
|
|
* @{
|
|
|
|
* @file auto_init_c
|
|
|
|
* @brief initializes any used module that has a trivial init function
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
2015-04-29 21:17:07 +02:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2013-06-18 17:21:38 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2013-10-27 17:23:25 +01:00
|
|
|
|
|
|
|
#include "auto_init.h"
|
|
|
|
|
2014-10-30 17:48:58 +01:00
|
|
|
#ifdef MODULE_CONFIG
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-12-21 15:23:17 +01:00
|
|
|
#ifdef MODULE_SHT11
|
|
|
|
#include "sht11.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_GPIOINT
|
|
|
|
#include "gpioint.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-26 22:02:18 +01:00
|
|
|
#ifdef MODULE_CC110X_LEGACY_CSMA
|
|
|
|
#include "cc110x_legacy_csma.h"
|
2013-12-21 15:23:17 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_LTC4150
|
|
|
|
#include "ltc4150.h"
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 17:23:25 +01:00
|
|
|
#ifdef MODULE_UART0
|
2011-12-12 17:50:22 +01:00
|
|
|
#include "board_uart0.h"
|
2013-10-27 17:23:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_MCI
|
2011-12-12 17:50:22 +01:00
|
|
|
#include "diskio.h"
|
2013-10-27 17:23:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_VTIMER
|
2012-05-22 15:59:36 +02:00
|
|
|
#include "vtimer.h"
|
2013-10-27 17:23:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_RTC
|
2014-11-20 17:55:28 +01:00
|
|
|
#include "periph/rtc.h"
|
2013-10-27 17:23:25 +01:00
|
|
|
#endif
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-02-08 04:22:42 +01:00
|
|
|
#ifdef MODULE_SIXLOWPAN
|
|
|
|
#include "sixlowpan.h"
|
|
|
|
#endif
|
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
#ifdef MODULE_UDP
|
|
|
|
#include "udp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_TCP
|
|
|
|
#include "tcp.h"
|
2014-01-16 16:41:07 +01:00
|
|
|
#endif
|
|
|
|
|
2014-07-19 18:00:21 +02:00
|
|
|
#ifdef MODULE_NOMAC
|
|
|
|
#include "nomac.h"
|
|
|
|
#endif
|
|
|
|
|
2013-12-20 15:23:09 +01:00
|
|
|
#ifdef MODULE_NET_IF
|
2014-03-03 11:04:14 +01:00
|
|
|
#include "cpu-conf.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "kernel.h"
|
2013-12-20 15:23:09 +01:00
|
|
|
#include "net_if.h"
|
|
|
|
#include "transceiver.h"
|
2014-03-03 11:04:14 +01:00
|
|
|
#include "net_help.h"
|
|
|
|
#include "hashes.h"
|
|
|
|
#include "periph/cpuid.h"
|
2013-12-20 15:23:09 +01:00
|
|
|
#endif
|
|
|
|
|
2015-03-16 17:52:19 +01:00
|
|
|
#ifdef MODULE_NG_SIXLOWPAN
|
|
|
|
#include "net/ng_sixlowpan.h"
|
|
|
|
#endif
|
|
|
|
|
2015-03-03 22:20:21 +01:00
|
|
|
#ifdef MODULE_NG_IPV6
|
|
|
|
#include "net/ng_ipv6.h"
|
|
|
|
#endif
|
|
|
|
|
2014-11-21 23:10:06 +01:00
|
|
|
#ifdef MODULE_L2_PING
|
|
|
|
#include "l2_ping.h"
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 23:51:35 +01:00
|
|
|
#ifdef MODULE_NG_PKTDUMP
|
|
|
|
#include "net/ng_pktdump.h"
|
|
|
|
#endif
|
|
|
|
|
2015-04-24 15:08:36 +02:00
|
|
|
#ifdef MODULE_NG_UDP
|
|
|
|
#include "net/ng_udp.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-25 21:55:49 +02:00
|
|
|
#define ENABLE_DEBUG (0)
|
2013-10-27 17:23:25 +01:00
|
|
|
#include "debug.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-02-08 04:22:42 +01:00
|
|
|
#ifndef CONF_RADIO_ADDR
|
|
|
|
#define CONF_RADIO_ADDR (1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONF_PAN_ID
|
|
|
|
#define CONF_PAN_ID (0xabcd)
|
|
|
|
#endif
|
|
|
|
|
2013-12-20 15:23:09 +01:00
|
|
|
#ifdef MODULE_NET_IF
|
2014-08-08 23:53:38 +02:00
|
|
|
void auto_init_net_if(void)
|
|
|
|
{
|
2013-12-20 15:23:09 +01:00
|
|
|
transceiver_type_t transceivers = 0;
|
|
|
|
#ifdef MODULE_AT86RF231
|
|
|
|
transceivers |= TRANSCEIVER_AT86RF231;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_CC1020
|
|
|
|
transceivers |= TRANSCEIVER_CC1020;
|
|
|
|
#endif
|
2014-09-23 01:30:37 +02:00
|
|
|
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA))
|
2013-12-20 15:23:09 +01:00
|
|
|
transceivers |= TRANSCEIVER_CC1100;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_CC2420
|
|
|
|
transceivers |= TRANSCEIVER_CC2420;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_MC1322X
|
|
|
|
transceivers |= TRANSCEIVER_MC1322X;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_NATIVENET
|
|
|
|
transceivers |= TRANSCEIVER_NATIVE;
|
|
|
|
#endif
|
|
|
|
net_if_init();
|
|
|
|
|
|
|
|
if (transceivers != 0) {
|
2014-03-03 11:04:14 +01:00
|
|
|
#if CPUID_ID_LEN && defined(MODULE_HASHES)
|
|
|
|
uint8_t cpuid[CPUID_ID_LEN];
|
|
|
|
|
|
|
|
cpuid_get(cpuid);
|
|
|
|
#endif
|
2013-12-20 15:23:09 +01:00
|
|
|
transceiver_init(transceivers);
|
|
|
|
transceiver_start();
|
2014-10-16 16:24:16 +02:00
|
|
|
int iface = net_if_init_interface(0, transceivers);
|
2014-02-08 04:22:42 +01:00
|
|
|
|
2014-03-03 11:04:14 +01:00
|
|
|
#if CPUID_ID_LEN && defined(MODULE_HASHES)
|
|
|
|
net_if_eui64_t eui64;
|
2014-08-08 23:53:38 +02:00
|
|
|
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 */
|
|
|
|
|
2015-05-13 09:52:36 +02:00
|
|
|
eui64.uint32[1] = hash_l;
|
|
|
|
eui64.uint32[0] = hash_h;
|
|
|
|
|
2015-03-12 07:45:40 +01:00
|
|
|
/* Set Local/Universal bit to Local since this EUI64 is made up. */
|
|
|
|
eui64.uint8[0] |= 0x02;
|
2014-03-03 11:04:14 +01:00
|
|
|
net_if_set_eui64(iface, &eui64);
|
|
|
|
|
2014-12-03 22:59:14 +01:00
|
|
|
#if ENABLE_DEBUG
|
2014-03-03 11:04:14 +01:00
|
|
|
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");
|
2014-12-03 22:59:14 +01:00
|
|
|
#endif /* ENABLE_DEBUG */
|
2014-03-03 11:04:14 +01:00
|
|
|
|
|
|
|
#undef CONF_RADIO_ADDR
|
2014-09-23 01:30:37 +02:00
|
|
|
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA))
|
2014-10-25 18:32:25 +02:00
|
|
|
uint8_t hwaddr = (uint8_t)((hash_l ^ hash_h) ^ ((hash_l ^ hash_h) >> 24));
|
|
|
|
/* do not combine more parts to keep the propability low that it just
|
|
|
|
* becomes 0xff */
|
|
|
|
#else
|
2014-10-14 14:32:09 +02:00
|
|
|
uint16_t hwaddr = HTONS((uint16_t)((hash_l ^ hash_h) ^ ((hash_l ^ hash_h) >> 16)));
|
2014-10-25 18:32:25 +02:00
|
|
|
#endif
|
2014-03-03 11:04:14 +01:00
|
|
|
net_if_set_hardware_address(iface, hwaddr);
|
|
|
|
DEBUG("Auto init radio address on interface %d to 0x%04x\n", iface, hwaddr);
|
2014-08-08 23:53:38 +02:00
|
|
|
#else /* CPUID_ID_LEN && defined(MODULE_HASHES) */
|
2014-03-03 11:04:14 +01:00
|
|
|
|
2014-11-06 21:52:08 +01:00
|
|
|
if (!net_if_get_hardware_address(iface)) {
|
|
|
|
DEBUG("Auto init radio address on interface %d to 0x%04x\n", iface, CONF_RADIO_ADDR);
|
|
|
|
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) */
|
|
|
|
|
2014-03-04 10:56:52 +01:00
|
|
|
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 {
|
2014-03-03 11:04:14 +01:00
|
|
|
net_if_set_src_address_mode(iface, NET_IF_TRANS_ADDR_M_LONG);
|
2014-03-04 10:56:52 +01:00
|
|
|
DEBUG("Auto init source address mode to long on interface %d\n",
|
|
|
|
iface);
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:04:14 +01:00
|
|
|
|
2014-02-08 04:22:42 +01:00
|
|
|
if (net_if_get_pan_id(iface) <= 0) {
|
|
|
|
DEBUG("Auto init PAN ID on interface %d to 0x%04x\n", iface, CONF_PAN_ID);
|
|
|
|
DEBUG("Change this value at compile time with macro CONF_PAN_ID\n");
|
|
|
|
net_if_set_pan_id(iface, CONF_PAN_ID);
|
|
|
|
}
|
2013-12-20 15:23:09 +01:00
|
|
|
|
|
|
|
if (iface >= 0) {
|
2014-02-08 04:22:42 +01:00
|
|
|
DEBUG("Auto init interface %d\n", iface);
|
2013-12-20 15:23:09 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-08 23:53:38 +02:00
|
|
|
}
|
|
|
|
#endif /* MODULE_NET_IF */
|
2013-12-20 15:23:09 +01:00
|
|
|
|
2014-08-08 23:53:38 +02:00
|
|
|
void auto_init(void)
|
|
|
|
{
|
2014-10-30 17:48:58 +01:00
|
|
|
#ifdef MODULE_CONFIG
|
|
|
|
DEBUG("Auto init loading config\n");
|
|
|
|
config_load();
|
|
|
|
#endif
|
|
|
|
|
2014-08-08 23:53:38 +02:00
|
|
|
#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();
|
|
|
|
#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
|
2014-10-26 22:02:18 +01:00
|
|
|
#ifdef MODULE_CC110X_LEGACY_CSMA
|
2014-08-08 23:53:38 +02:00
|
|
|
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
|
2014-11-21 23:10:06 +01:00
|
|
|
#ifdef MODULE_L2_PING
|
|
|
|
DEBUG("Auto init net_if module.\n");
|
|
|
|
l2_ping_init();
|
|
|
|
#endif
|
2014-07-19 18:00:21 +02:00
|
|
|
#ifdef MODULE_NOMAC
|
|
|
|
DEBUG("Auto init nomac module.\n");
|
|
|
|
nomac_init_module();
|
|
|
|
#endif
|
2014-08-08 23:53:38 +02:00
|
|
|
#ifdef MODULE_NET_IF
|
|
|
|
DEBUG("Auto init net_if module.\n");
|
|
|
|
auto_init_net_if();
|
|
|
|
#endif
|
2014-02-08 04:22:42 +01:00
|
|
|
#ifdef MODULE_SIXLOWPAN
|
|
|
|
DEBUG("Auto init 6LoWPAN module.\n");
|
|
|
|
sixlowpan_lowpan_init();
|
|
|
|
#endif
|
2011-01-31 18:25:20 +01:00
|
|
|
#ifdef MODULE_PROFILING
|
|
|
|
extern void profiling_init(void);
|
|
|
|
profiling_init();
|
2010-09-22 15:10:42 +02:00
|
|
|
#endif
|
2014-07-31 17:53:46 +02:00
|
|
|
#ifdef MODULE_UDP
|
|
|
|
DEBUG("Auto init transport layer module: [udp].\n");
|
|
|
|
udp_init_transport_layer();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_TCP
|
|
|
|
DEBUG("Auto init transport layer module: [tcp].\n");
|
|
|
|
tcp_init_transport_layer();
|
2014-01-16 16:41:07 +01:00
|
|
|
#endif
|
2015-03-25 23:51:35 +01:00
|
|
|
#ifdef MODULE_NG_PKTDUMP
|
|
|
|
DEBUG("Auto init ng_pktdump module.\n");
|
|
|
|
ng_pktdump_init();
|
|
|
|
#endif
|
2015-03-16 17:52:19 +01:00
|
|
|
#ifdef MODULE_NG_SIXLOWPAN
|
|
|
|
DEBUG("Auto init ng_sixlowpan module.\n");
|
|
|
|
ng_sixlowpan_init();
|
|
|
|
#endif
|
2015-03-03 22:20:21 +01:00
|
|
|
#ifdef MODULE_NG_IPV6
|
|
|
|
DEBUG("Auto init ng_ipv6 module.\n");
|
|
|
|
ng_ipv6_init();
|
|
|
|
#endif
|
2015-04-24 15:08:36 +02:00
|
|
|
#ifdef MODULE_NG_UDP
|
|
|
|
DEBUG("Auto init UDP module.\n");
|
|
|
|
ng_udp_init();
|
|
|
|
#endif
|
2015-05-08 15:50:35 +02:00
|
|
|
|
|
|
|
|
2015-05-17 21:01:07 +02:00
|
|
|
/* initialize network devices */
|
|
|
|
#ifdef MODULE_AUTO_INIT_NG_NETIF
|
2015-05-08 15:50:35 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_NG_AT86RF2XX
|
|
|
|
extern void auto_init_ng_at86rf2xx(void);
|
|
|
|
auto_init_ng_at86rf2xx();
|
|
|
|
#endif
|
2015-05-08 15:51:26 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_XBEE
|
|
|
|
extern void auto_init_xbee(void);
|
|
|
|
auto_init_xbee();
|
|
|
|
#endif
|
2015-05-17 21:01:07 +02:00
|
|
|
|
2015-05-17 15:21:49 +02:00
|
|
|
#ifdef MODULE_KW2XRF
|
|
|
|
extern void auto_init_kw2xrf(void);
|
|
|
|
auto_init_kw2xrf();
|
|
|
|
#endif
|
|
|
|
|
2015-05-17 21:01:07 +02:00
|
|
|
#endif /* MODULE_AUTO_INIT_NG_NETIF */
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|