-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ng_sixlowpan: initial import #2614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ extern "C" { | |
| #endif | ||
|
|
||
| /** | ||
| * @brief Default name for the IPv6 thread | ||
| * @brief Default priority for the IPv6 thread | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated, but I will let this one slide. 😉
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooops this seems to be slipped through. |
||
| */ | ||
| #ifndef NG_IPV6_PRIO | ||
| #define NG_IPV6_PRIO (PRIORITY_MAIN - 3) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,15 @@ extern "C" { | |
| * @} | ||
| */ | ||
|
|
||
| /** | ||
| * @{ | ||
| * @name Flags for the interfaces | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Any reason against an enum?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enums for flags are ugly (yes I know I had used them in that context myself, but I changed my opinion on that).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because flags have a width in memory that is in most cases smaller than Making the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. Maybe another point for the RIOT best programming practice page. |
||
| */ | ||
| #define NG_IPV6_NETIF_FLAGS_SIXLOWPAN (0x01) /**< interface is 6LoWPAN interface */ | ||
| /** | ||
| * @} | ||
| */ | ||
|
|
||
| /** | ||
| * @brief Type to represent an IPv6 address registered to an interface. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright (C) 2015 Martine Lenders <[email protected]> | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_ng_sixlowpan 6LoWPAN | ||
| * @ingroup net | ||
| * @brief 6LoWPAN implementation | ||
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Definitions for 6LoWPAN | ||
| * | ||
| * @author Martine Lenders <[email protected]> | ||
| */ | ||
| #ifndef NG_SIXLOWPAN_H_ | ||
| #define NG_SIXLOWPAN_H_ | ||
|
|
||
| #include <stdbool.h> | ||
|
|
||
| #include "kernel_types.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Default stack size to use for the 6LoWPAN thread | ||
| */ | ||
| #ifndef NG_SIXLOWPAN_STACK_SIZE | ||
| #define NG_SIXLOWPAN_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT) | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Default priority for the 6LoWPAN thread | ||
| */ | ||
| #ifndef NG_SIXLOWPAN_PRIO | ||
| #define NG_SIXLOWPAN_PRIO (PRIORITY_MAIN - 4) | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Default message queue size to use for the 6LoWPAN thread. | ||
| */ | ||
| #ifndef NG_SIXLOWPAN_MSG_QUEUE_SIZE | ||
| #define NG_SIXLOWPAN_MSG_QUEUE_SIZE (8U) | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Dispatch for uncompressed 6LoWPAN frame. | ||
| */ | ||
| #define NG_SIXLOWPAN_UNCOMPRESSED (0x41) | ||
|
|
||
| /** | ||
| * @brief Checks if dispatch indicats that fram is not a 6LoWPAN (NALP) frame. | ||
| * | ||
| * @param[in] disp The first byte of a frame. | ||
| * | ||
| * @return true, if frame is a NALP. | ||
| * @return false, if frame is not a NALP. | ||
| */ | ||
| static inline bool ng_sixlowpan_nalp(uint8_t disp) | ||
| { | ||
| return (disp & 0x3f); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Initialization of the 6LoWPAN thread. | ||
| * | ||
| * @return The PID to the 6LoWPAN thread, on success. | ||
| * @return -EOVERFLOW, if there are too many threads running already | ||
| */ | ||
| kernel_pid_t ng_sixlowpan_init(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* NG_SIXLOWPAN_H_ */ | ||
| /** @} */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright (C) 2015 Martine Lenders <[email protected]> | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_ng_sixlowpan_netif 6LoWPAN network interfaces | ||
| * @ingroup net_ng_sixlowpan | ||
| * @brief 6LoWPAN specific information on @ref net_ng_netif | ||
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Definitions for 6LoWPAN specific information of network interfaces. | ||
| * | ||
| * @author Martine Lenders <[email protected]> | ||
| */ | ||
| #ifndef NG_SIXLOWPAN_NETIF_H_ | ||
| #define NG_SIXLOWPAN_NETIF_H_ | ||
|
|
||
| #include "kernel_types.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Definition of 6LoWPAN interface type. | ||
| */ | ||
| typedef struct { | ||
| kernel_pid_t pid; /**< PID of the interface */ | ||
| uint16_t max_frag_size; /**< Maximum fragment size for this interface */ | ||
| } ng_sixlowpan_netif_t; | ||
|
|
||
| /** | ||
| * @brief Initializes the module | ||
| */ | ||
| void ng_sixlowpan_netif_init(void); | ||
|
|
||
| /** | ||
| * @brief Add interface to 6LoWPAN. | ||
| * | ||
| * @param[in] pid The PID to the interface. | ||
| * @param[in] max_frag_size The maximum fragment size for this interface. | ||
| */ | ||
| void ng_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size); | ||
|
|
||
| /** | ||
| * @brief REmove interface from 6LoWPAN. | ||
| * | ||
| * @param[in] pid The PID to the interface. | ||
| */ | ||
| void ng_sixlowpan_netif_remove(kernel_pid_t pid); | ||
|
|
||
| /** | ||
| * @brief Get interface. | ||
| * | ||
| * @param[in] pid The PID to the interface | ||
| * | ||
| * @return The interface describing structure, on success. | ||
| * @return NULL, if there is no interface with PID @p pid. | ||
| */ | ||
| ng_sixlowpan_netif_t *ng_sixlowpan_netif_get(kernel_pid_t pid); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* NG_SIXLOWPAN_NETIF_H_ */ | ||
| /** @} */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,43 @@ static void *_event_loop(void *args) | |
| return NULL; | ||
| } | ||
|
|
||
| #ifdef MODULE_NG_SIXLOWPAN | ||
| static void _send_to_iface(kernel_pid_t iface, ng_pktsnip_t *pkt) | ||
| { | ||
| ng_ipv6_netif_t *if_entry = ng_ipv6_netif_get(iface); | ||
|
|
||
| ((ng_netif_hdr_t *)pkt->data)->if_pid = iface; | ||
|
|
||
| if ((if_entry != NULL) && (if_entry->flags & NG_IPV6_NETIF_FLAGS_SIXLOWPAN)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not exit early if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no exit on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought NULL indicates that the PID is probably not valid.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you still explain this? What does NULL as a return value for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That there is no IPv6 interface. This is not a case that should happen here so maybe we can even remove the NULL test |
||
| DEBUG("ipv6: send to 6LoWPAN instead\n"); | ||
| ng_netreg_entry_t *reg = ng_netreg_lookup(NG_NETTYPE_SIXLOWPAN, | ||
| NG_NETREG_DEMUX_CTX_ALL); | ||
|
|
||
| if (reg != NULL) { | ||
| ng_pktbuf_hold(pkt, ng_netreg_num(NG_NETTYPE_SIXLOWPAN, | ||
| NG_NETREG_DEMUX_CTX_ALL) - 1); | ||
| } | ||
| else { | ||
| DEBUG("ipv6: no 6LoWPAN thread found"); | ||
| } | ||
|
|
||
| while (reg) { | ||
| ng_netapi_send(reg->pid, pkt); | ||
| reg = ng_netreg_getnext(reg); | ||
| } | ||
| } | ||
| else { | ||
| ng_netapi_send(iface, pkt); | ||
| } | ||
| } | ||
| #else | ||
| static inline void _send_to_iface(kernel_pid_t iface, ng_pktsnip_t *pkt) | ||
| { | ||
| ((ng_netif_hdr_t *)pkt->data)->if_pid = iface; | ||
| ng_netapi_send(iface, pkt); | ||
| } | ||
| #endif | ||
|
|
||
| /* functions for sending */ | ||
| static void _send_unicast(kernel_pid_t iface, uint8_t *dst_l2addr, | ||
| uint16_t dst_l2addr_len, ng_pktsnip_t *pkt) | ||
|
|
@@ -165,7 +202,7 @@ static void _send_unicast(kernel_pid_t iface, uint8_t *dst_l2addr, | |
|
|
||
| DEBUG("ipv6: send unicast over interface %" PRIkernel_pid "\n", iface); | ||
| /* and send to interface */ | ||
| ng_netapi_send(iface, pkt); | ||
| _send_to_iface(iface, pkt); | ||
| } | ||
|
|
||
| static int _fill_ipv6_hdr(kernel_pid_t iface, ng_pktsnip_t *ipv6, | ||
|
|
@@ -243,7 +280,7 @@ static inline void _send_multicast_over_iface(kernel_pid_t iface, ng_pktsnip_t * | |
| /* mark as multicast */ | ||
| ((ng_netif_hdr_t *)netif->data)->flags |= NG_NETIF_HDR_FLAGS_MULTICAST; | ||
| /* and send to interface */ | ||
| ng_netapi_send(iface, pkt); | ||
| _send_to_iface(iface, pkt); | ||
| } | ||
|
|
||
| static void _send_multicast(kernel_pid_t iface, ng_pktsnip_t *pkt, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include $(RIOTBASE)/Makefile.base |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| MODULE = ng_sixlowpan_netif | ||
|
|
||
| include $(RIOTBASE)/Makefile.base |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright (C) 2015 Martine Lenders <[email protected]> | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * @{ | ||
| * | ||
| * @file | ||
| */ | ||
|
|
||
| #include "kernel_types.h" | ||
|
|
||
| #include "net/ng_netif.h" | ||
| #include "net/ng_sixlowpan/netif.h" | ||
|
|
||
| static ng_sixlowpan_netif_t sixlow_ifs[NG_NETIF_NUMOF]; | ||
|
|
||
| void ng_sixlowpan_netif_init(void) | ||
| { | ||
| for (int i = 0; i < NG_NETIF_NUMOF; i++) { | ||
| sixlow_ifs[i].pid = KERNEL_PID_UNDEF; | ||
| sixlow_ifs[i].max_frag_size = 0; | ||
| } | ||
| } | ||
|
|
||
| void ng_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size) | ||
| { | ||
| for (int i = 0; i < NG_NETIF_NUMOF; i++) { | ||
| if (sixlow_ifs[i].pid == pid) { | ||
| return; | ||
| } | ||
|
|
||
| if (sixlow_ifs[i].pid == KERNEL_PID_UNDEF) { | ||
| sixlow_ifs[i].pid = pid; | ||
| sixlow_ifs[i].max_frag_size = max_frag_size; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void ng_sixlowpan_netif_remove(kernel_pid_t pid) | ||
| { | ||
| ng_sixlowpan_netif_t *entry = ng_sixlowpan_netif_get(pid); | ||
|
|
||
| entry->pid = KERNEL_PID_UNDEF; | ||
| } | ||
|
|
||
| ng_sixlowpan_netif_t *ng_sixlowpan_netif_get(kernel_pid_t pid) | ||
| { | ||
| for (int i = 0; i < NG_NETIF_NUMOF; i++) { | ||
| if (sixlow_ifs[i].pid == pid) { | ||
| return sixlow_ifs + i; | ||
| } | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| /** @} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptional: Shouldn't be IPv6 also a dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptionally, yes. To work: no. If we ever want to introduce stand-alone tests for every layer we would not need IPv6 here.