1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Use net_if in 6LoWPAN layer

This commit is contained in:
Martin Lenders 2014-02-13 15:54:42 +01:00
parent 108989b65d
commit c9e8adc414
6 changed files with 489 additions and 354 deletions

View File

@ -25,6 +25,8 @@
#include <stdint.h>
#include "transceiver.h"
#include "net_help.h"
#include "net_if.h"
#include "sixlowpan/types.h"
/**
@ -178,26 +180,44 @@ typedef struct __attribute__((packed)) {
/**
* @brief Initializes 6LoWPAN.
* @brief Initializes all addresses on an interface needed for 6LoWPAN.
*
* @param[in] trans Transceiver to use with 6LoWPAN.
* @param[in] r_addr PHY layer address.
* @param[in] as_border 1 if node should act as border router,
* 0 otherwise.
* @param[in] if_id The interface to use with 6LoWPAN.
*
* @return 1 on success, 0 on failure.
*/
void sixlowpan_lowpan_init(transceiver_type_t trans, uint8_t r_addr,
int as_border);
int sixlowpan_lowpan_init_interface(int if_id);
/**
* @brief Initializes a 6LoWPAN router with address prefix
* @brief Checks if an EUI-64 was set from a short address. If so
* it returns this address, else 0
*
* @param[in] trans transceiver to use with 6LoWPAN.
* @param[in] prefix the address prefix to advertise.
* @param[in] r_addr PHY layer address.
* @param[in] iid An EUI-64.
*
* @return The short address on success, 0 on failure.
*/
void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
const ipv6_addr_t *prefix,
uint8_t r_addr);
static inline uint16_t sixlowpan_lowpan_eui64_to_short_addr(const net_if_eui64_t *iid)
{
if (iid->uint32[0] == HTONL(0x000000ff) &&
iid->uint16[2] == HTONS(0xfe00)) {
return NTOHS(iid->uint16[3]);
}
return 0;
}
/**
* @brief Initializes all addresses and prefixes on an interface needed
* for 6LoWPAN. Calling this function together with
* sixlowpan_lowpan_init_interface() is not necessary.
*
* @param[in] if_id The interface to use with 6LoWPAN.
* @param[in] prefix the address prefix to advertise.
*
* @return 1 on success, 0 on failure.
*/
int sixlowpan_lowpan_init_adhoc_interface(int if_id,
const ipv6_addr_t *prefix);
/**
* @brief Initializes a 6LoWPAN border router with an address
@ -205,26 +225,26 @@ void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
* @note Currently only working with addresses generated from
* IEEE 802.15.4 16-bit short addresses.
*
* @param[in] trans transceiver to use with 6LoWPAN.
* @param[in] border_router_addr Address of this border router.
* @param[in] if_id The interface to use with 6LoWPAN.
*
* @return SIXLOWERROR_SUCCESS on success, otherwise SIXLOWERROR_ADDRESS if
* address was not generated from IEEE 802.15.4 16-bit short
* address.
* @return 1 on success, 0 on failure.
*/
uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans,
const ipv6_addr_t *border_router_addr);
int sixlowpan_lowpan_border_init(int if_id);
/**
* @brief Send data via 6LoWPAN to destination node dest.
* @brief Send data via 6LoWPAN to destination node or next hop dest.
*
* @param[in] dest EUI-64 of destination node.
* @param[in] if_id The interface to send the data over.
* @param[in] dest Hardware address of the next hop or destination node.
* @param[in] dest_len Length of the destination address in byte.
* @param[in] data Data to send to destination node (may be
* manipulated).
* @param[in] data_len Length of data.
*
* @return length of transmitted data on success, -1 on failure.
*/
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
uint8_t *data, uint16_t data_len);
int sixlowpan_lowpan_sendto(int if_id, const void *dest, int dest_len,
uint8_t *data, uint16_t data_len);
/**
* @brief Set header compression status for 6LoWPAN.
@ -272,5 +292,12 @@ void sixlowpan_lowpan_print_fifo_buffers(void);
void sixlowpan_lowpan_print_reassembly_buffers(void);
#endif
/**
* @brief Initializes 6LoWPAN module.
*
* @return 1 on success, 0 on failure.
*/
int sixlowpan_lowpan_init(void);
/** @} */
#endif /* SIXLOWPAN_LOWPAN_H */

View File

@ -16,6 +16,7 @@
* @}
*/
/* TODO: Put this in its own module */
#include <stdint.h>
#include <string.h>
#include <stdio.h>
@ -37,9 +38,10 @@
#include "net_help.h"
#define READER_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
#define ENABLE_DEBUG (0)
#include "debug.h"
ipv6_addr_t abr_addr;
#define READER_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
char serial_reader_stack[READER_STACK_SIZE];
uint16_t serial_reader_pid;
@ -47,6 +49,8 @@ uint16_t serial_reader_pid;
uint8_t serial_out_buf[BORDER_BUFFER_SIZE];
uint8_t serial_in_buf[BORDER_BUFFER_SIZE];
ipv6_addr_t *abr_addr;
uint8_t *get_serial_out_buffer(int offset)
{
if (offset > BUFFER_SIZE) {
@ -120,45 +124,52 @@ void serial_reader_f(void)
}
}
uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans,
const ipv6_addr_t *border_router_addr)
int sixlowpan_lowpan_border_init(int if_id)
{
ipv6_addr_t addr;
ipv6_net_if_addr_t *addr = NULL;
uint8_t abr_addr_initialized = 0;
serial_reader_pid = thread_create(
serial_reader_stack, READER_STACK_SIZE,
PRIORITY_MAIN - 1, CREATE_STACKTEST,
serial_reader_f, "serial_reader");
ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE,
PRIORITY_MAIN - 1, CREATE_STACKTEST,
border_process_lowpan,
"border_process_lowpan");
if (border_router_addr == NULL) {
border_router_addr = &addr;
addr = flowcontrol_init();
if (ip_process_pid < 0) {
return 0;
}
/* only allow addresses generated accoding to
* RFC 4944 (Section 6) & RFC 2464 (Section 4) from short address
* -- for now
*/
if (border_router_addr->uint16[4] != HTONS(IEEE_802154_PAN_ID ^ 0x0200) ||
border_router_addr->uint16[5] != HTONS(0x00FF) ||
border_router_addr->uint16[6] != HTONS(0xFE00)
) {
return SIXLOWERROR_ADDRESS;
if (!sixlowpan_lowpan_init()) {
return 0;
}
/* radio-address is 8-bit so this must be tested extra */
if (border_router_addr->uint8[14] != 0) {
return SIXLOWERROR_ADDRESS;
if (!sixlowpan_lowpan_init_interface(if_id)) {
return 0;
}
memcpy(&(abr_addr.uint8[0]), &(border_router_addr->uint8[0]), 16);
while (net_if_iter_addresses(if_id, (net_if_addr_t **) &addr)) {
if (!ipv6_addr_is_multicast(addr->addr_data) &&
!ipv6_addr_is_link_local(addr->addr_data) &&
!ipv6_addr_is_loopback(addr->addr_data) &&
!ipv6_addr_is_unique_local_unicast(addr->addr_data)) {
abr_addr_initialized = 1;
abr_addr = addr->addr_data;
break;
}
}
sixlowpan_lowpan_init(trans, border_router_addr->uint8[15], 1);
if (!abr_addr_initialized) {
DEBUG("sixlowpan_lowpan_border_init(): A prefix must be initialized to"
"interface %d first", if_id);
return 0;
}
ipv6_init_iface_as_router();
ipv6_init_as_router();
return SIXLOWERROR_SUCCESS;
return 1;
}
void border_process_lowpan(void)

View File

@ -64,6 +64,7 @@ int sixlowip_reg[SIXLOWIP_MAX_REGISTERED];
int ipv6_send_packet(ipv6_hdr_t *bytes)
{
int if_id = 0;
uint16_t offset = IPV6_HDR_LEN + HTONS(bytes->length);
bytes->flowlabel = HTONS(bytes->flowlabel);
@ -72,9 +73,12 @@ int ipv6_send_packet(ipv6_hdr_t *bytes)
memset(bytes, 0, BUFFER_SIZE);
memcpy(bytes + LL_HDR_LEN, bytes, offset);
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &bytes->destaddr.uint16[4],
(uint8_t *)bytes,
offset);
if (sixlowpan_lowpan_sendto(nce->if_id, &nce->lladdr, nce->lladdr_len,
(uint8_t *)packet, length) < 0) {
return -1;
}
return length;
}
ipv6_hdr_t *ipv6_get_buf_send(void)
@ -143,7 +147,7 @@ int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
return -1;
}
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &dest->uint16[4],
sixlowpan_lowpan_sendto(0, &dest->uint16[4], 8,
(uint8_t *)ipv6_buf, packet_length);
return payload_length;

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,8 @@
#include "sixlowpan/lowpan.h"
#define IEEE802154_TRANSCEIVER (TRANSCEIVER_AT86RF231 | TRANSCEIVER_CC2420 | TRANSCEIVER_MC1322X)
typedef struct {
uint8_t num;
ipv6_addr_t prefix;

View File

@ -47,7 +47,6 @@
#define RADIO_SENDING_DELAY (1000)
#define DEFAULT_IEEE_802154_PAN_ID (0x1234)
#define IEEE802154_TRANSCEIVER (TRANSCEIVER_AT86RF231 | TRANSCEIVER_CC2420 | TRANSCEIVER_MC1322X)
char radio_stack_buffer[RADIO_STACK_SIZE];
msg_t msg_q[RADIO_RCV_BUF_SIZE];