Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletions sys/net/network_layer/sixlowpan/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,82 +240,52 @@ static icmpv6_ndp_opt_aro_t *get_opt_aro_buf(uint8_t ext_len, uint8_t opt_len)

void icmpv6_send_echo_request(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data, size_t data_len)
{
uint16_t packet_length;

ipv6_buf = ipv6_get_buf();
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
icmpv6_echo_request_hdr_t *echo_buf = get_echo_req_buf(ipv6_ext_hdr_len);
char *echo_data_buf = ((char *)echo_buf) + sizeof(icmpv6_echo_request_hdr_t);

icmp_buf->type = ICMPV6_TYPE_ECHO_REQUEST;
icmp_buf->code = 0;
ipv6_buf->version_trafficclass = IPV6_VER;
ipv6_buf->trafficclass_flowlabel = 0;
ipv6_buf->flowlabel = 0;
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
ipv6_buf->hoplimit = 0xff;

memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t));
ipv6_iface_get_best_src_addr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr);
echo_buf->id = id;
echo_buf->seq = seq;

memcpy(echo_data_buf, data, data_len);
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len +
ECHO_REQ_LEN + data_len;

ipv6_buf->length = packet_length - IPV6_HDR_LEN;
ipv6_buf->length = ICMPV6_HDR_LEN + ipv6_ext_hdr_len + ECHO_REQ_LEN + data_len;

icmp_buf->checksum = 0;
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);

#ifdef ENABLE_DEBUG
char addr_str[IPV6_MAX_ADDR_STR_LEN];
printf("INFO: send echo request to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
printf("INFO: send echo request to: %s\n", ipv6_addr_to_str(addr_str, destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4], (uint8_t *)ipv6_buf, packet_length);

ipv6_sendto(destaddr, IPV6_PROTO_NUM_ICMPV6, (uint8_t*) icmp_buf, ipv6_buf->length);
}

void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data, size_t data_len)
{
uint16_t packet_length;

ipv6_buf = ipv6_get_buf();
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
icmpv6_echo_reply_hdr_t *echo_buf = get_echo_repl_buf(ipv6_ext_hdr_len);
char *echo_data_buf = ((char *)echo_buf) + sizeof(icmpv6_echo_reply_hdr_t);

icmp_buf->type = ICMPV6_TYPE_ECHO_REPLY;
icmp_buf->code = 0;
ipv6_buf->version_trafficclass = IPV6_VER;
ipv6_buf->trafficclass_flowlabel = 0;
ipv6_buf->flowlabel = 0;
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
ipv6_buf->hoplimit = 0xff;

memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t));
ipv6_iface_get_best_src_addr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr);
echo_buf->id = id;
echo_buf->seq = seq;

memcpy(echo_data_buf, data, data_len);
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len +
ECHO_REPL_LEN + data_len;

ipv6_buf->length = packet_length - IPV6_HDR_LEN;
ipv6_buf->length = ICMPV6_HDR_LEN + ipv6_ext_hdr_len + ECHO_REPL_LEN + data_len;

icmp_buf->checksum = 0;
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);

#ifdef ENABLE_DEBUG
char addr_str[IPV6_MAX_ADDR_STR_LEN];
printf("INFO: send echo request to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
printf("INFO: send echo reply to: %s\n", ipv6_addr_to_str(addr_str, destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4],
(uint8_t *)ipv6_buf,
packet_length);

ipv6_sendto(destaddr, IPV6_PROTO_NUM_ICMPV6, (uint8_t*) icmp_buf, ipv6_buf->length);
}

/* send router solicitation message - RFC4861 section 4.1 */
Expand Down Expand Up @@ -372,7 +342,7 @@ void recv_echo_req(void)
ipv6_buf = ipv6_get_buf();
icmpv6_echo_request_hdr_t *echo_buf = get_echo_req_buf(ipv6_ext_hdr_len);
char *echo_data_buf = ((char *)echo_buf) + sizeof(icmpv6_echo_reply_hdr_t);
size_t data_len = ipv6_buf->length - (IPV6_HDR_LEN + ICMPV6_HDR_LEN +
size_t data_len = ipv6_buf->length - (ICMPV6_HDR_LEN +
ipv6_ext_hdr_len + ECHO_REQ_LEN);
#ifdef ENABLE_DEBUG
char addr_str[IPV6_MAX_ADDR_STR_LEN];
Expand All @@ -399,7 +369,7 @@ void recv_echo_repl(void)
ipv6_buf = ipv6_get_buf();
icmpv6_echo_reply_hdr_t *echo_buf = get_echo_repl_buf(ipv6_ext_hdr_len);
char *echo_data_buf = ((char *)echo_buf) + sizeof(icmpv6_echo_reply_hdr_t);
size_t data_len = ipv6_buf->length - (IPV6_HDR_LEN + ICMPV6_HDR_LEN +
size_t data_len = ipv6_buf->length - (ICMPV6_HDR_LEN +
ipv6_ext_hdr_len + ECHO_REPL_LEN);
#ifdef ENABLE_DEBUG
char addr_str[IPV6_MAX_ADDR_STR_LEN];
Expand Down
5 changes: 3 additions & 2 deletions sys/net/network_layer/sixlowpan/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ int icmpv6_demultiplex(const icmpv6_hdr_t *hdr)
}

default:
DEBUG("INFO: packet type: Unknown\n");
return -1;
}

Expand Down Expand Up @@ -269,8 +270,8 @@ void ipv6_process(void)
uint8_t i;
uint16_t packet_length;

ipv6_addr_init(&myaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00,
sixlowpan_mac_get_radio_address());
ipv6_addr_set_all_nodes_addr(&myaddr);
ipv6_iface_get_best_src_addr(&myaddr, &myaddr);

while (1) {
msg_receive(&m_recv_lowpan);
Expand Down