Skip to content

Commit

Permalink
Merge pull request RIOT-OS#254 from OlegHahm/network_debug
Browse files Browse the repository at this point in the history
added some debug output for the network stack
  • Loading branch information
OlegHahm authored and thomaseichinger committed Dec 9, 2013
2 parents 35ad891 + db9ecaf commit 087a126
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cpu/native/net/interface.c
Expand Up @@ -53,7 +53,7 @@ radio_address_t _native_net_addr;

void nativenet_init(int transceiver_pid)
{
DEBUG("nativenet_init(transceiver_pid=%d)", transceiver_pid);
DEBUG("nativenet_init(transceiver_pid=%d)\n", transceiver_pid);
rx_buffer_next = 0;
_native_net_pan = 0;
_native_net_chan = 0;
Expand Down Expand Up @@ -96,12 +96,14 @@ uint16_t nativenet_get_pan()

radio_address_t nativenet_set_address(radio_address_t address)
{
DEBUG("nativenet_set_address(address=%d)\n", address);
_native_net_addr = address;
return _native_net_addr;
}

radio_address_t nativenet_get_address()
{
DEBUG("nativenet_get_address -> address = %d\n", _native_net_addr);
return _native_net_addr;
}

Expand Down
19 changes: 19 additions & 0 deletions sys/net/include/sixlowpan/mac.h
Expand Up @@ -26,6 +26,11 @@

#include "sixlowpan/types.h"

/**
* @brief Maximum length of a IEEE 802.15.4 long address represented as string.
*/
#define IEEE_802154_MAX_ADDR_STR_LEN (12)

/**
* @brief Gets current radio transmitter address.
*
Expand Down Expand Up @@ -86,6 +91,20 @@ void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
*/
void sixlowpan_mac_init(transceiver_type_t type);

/**
* @brief Converts IEEE 802.15.4 long address into string.
* Note that addr_str must allocate at least
* IEEE_802154_MAX_ADDR_STR_LEN byte (12 byte).
*
* @param[out] addr_str The IEEE 802.15.4 long address as string. Must
* allocate at least IEEE_802154_ADDR_STR_LEN byte (12
* byte).
* @param[in] laddr IEEE 802.15.4 address to be converted.
*
* @return Pointer to addr_str.
*/
char *sixlowpan_mac_802154_long_addr_to_str(char *addr_str, const ieee_802154_long_t *laddr);

/**
* @}
*/
Expand Down
21 changes: 20 additions & 1 deletion sys/net/sixlowpan/mac.c
Expand Up @@ -40,6 +40,9 @@
#include "net_help.h"

#define ENABLE_DEBUG (0)
#if ENABLE_DEBUG
#define DEBUG_ENABLED
#endif
#include "debug.h"

#define RADIO_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
Expand All @@ -61,6 +64,7 @@ static transceiver_command_t tcmd;
uint8_t sixlowpan_mac_get_radio_address(void)
{
int16_t address;
DEBUG("sixlowpan_mac_get_radio_address()\n");

tcmd.transceivers = transceiver_type;
tcmd.data = &address;
Expand Down Expand Up @@ -103,6 +107,7 @@ void switch_to_rx(void)

void sixlowpan_mac_init_802154_short_addr(ieee_802154_short_t *saddr)
{
DEBUG("sixlowpan_mac_init_802154_short_addr(saddr=%02X)\n", *saddr);
saddr->uint8[0] = 0;
saddr->uint8[1] = sixlowpan_mac_get_radio_address();
}
Expand All @@ -114,6 +119,12 @@ ieee_802154_long_t *sixlowpan_mac_get_eui64(const ipv6_addr_t *ipaddr)

void sixlowpan_mac_init_802154_long_addr(ieee_802154_long_t *laddr)
{
#ifdef DEBUG_ENABLED
char addr_str[IEEE_802154_MAX_ADDR_STR_LEN];
sixlowpan_mac_802154_long_addr_to_str(addr_str, laddr);
DEBUG("sixlowpan_mac_init_802154_long_addr(laddr=%s)\n", addr_str);
#endif

// 16bit Pan-ID:16-zero-bits:16-bit-short-addr = 48bit
laddr->uint16[0] = IEEE_802154_PAN_ID;

Expand All @@ -127,6 +138,14 @@ void sixlowpan_mac_init_802154_long_addr(ieee_802154_long_t *laddr)
laddr->uint8[7] = sixlowpan_mac_get_radio_address();
}

char *sixlowpan_mac_802154_long_addr_to_str(char *addr_str, const ieee_802154_long_t *laddr) {
sprintf(addr_str,
"%02x:%02x:%02x:%02x",
laddr->uint16[0], laddr->uint16[1],
laddr->uint16[2], laddr->uint16[3]);
return addr_str;
}

void recv_ieee802154_frame(void)
{
msg_t m;
Expand Down Expand Up @@ -222,7 +241,7 @@ void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
buf[frame.payload_len+hdrlen] = 0;
/* FCS Valid = 1 / LQI Correlation Value = 0 */
buf[frame.payload_len+hdrlen+1] = 0x80;
DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", buf[0], buf[1], frame->dest_pan_id, frame->src_pan_id, frame->seq_nr);
DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", buf[0], buf[1], frame.dest_pan_id, frame.src_pan_id, frame.seq_nr);

p.length = hdrlen + frame.payload_len + IEEE_802154_FCS_LEN;

Expand Down
2 changes: 1 addition & 1 deletion sys/transceiver/transceiver.c
Expand Up @@ -246,7 +246,7 @@ void run(void)
msg_receive(&m);
/* only makes sense for messages for upper layers */
cmd = (transceiver_command_t *) m.content.ptr;
DEBUG("transceiver: Transceiver: Message received\n");
DEBUG("transceiver: Transceiver: Message received, type: %02X\n", m.type);

switch(m.type) {
case RCV_PKT_CC1020:
Expand Down

0 comments on commit 087a126

Please sign in to comment.