Skip to content

Commit

Permalink
Firmware: Resolutions of modules to a better comprension and more fle…
Browse files Browse the repository at this point in the history
…xibility to some modifications
  • Loading branch information
eduazocar committed Jun 2, 2022
1 parent 8a855db commit e29891e
Show file tree
Hide file tree
Showing 23 changed files with 275 additions and 284 deletions.
7 changes: 4 additions & 3 deletions firmware/network/Kconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
menu "Network"
rsource "udp_server/Kconfig"
rsource "udp_client/Kconfig"
rsource "chamos/Kconfig"
rsource "radio/Kconfig"
rsource "rpl_protocol/Kconfig"
rsource "chamos/Kconfig"
rsource "udp_client/Kconfig"
rsource "udp_server/Kconfig"

endmenu
4 changes: 4 additions & 0 deletions firmware/network/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ ifneq (,$(filter border_router,$(USEMODULE)))
DIRS += border_router
endif

ifneq (,$(filter net_tools,$(USEMODULE)))
DIRS += net_tools
endif

include $(RIOTBASE)/Makefile.base
8 changes: 6 additions & 2 deletions firmware/network/border_router/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ ifneq (,$(filter gnrc_netif_ieee802154,$(USEMODULE)))
USEMODULE += gnrc_netif_ieee802154
endif

ifeq (,$(filter rpl_protocol,$(USEMODULE)))
USEMODULE += rpl_protocol
ifeq (,$(filter radio,$(USEMODULE)))
USEMODULE += radio
endif

ifeq (,$(filter net_tools,$(USEMODULE)))
USEMODULE += net_tools
endif
110 changes: 33 additions & 77 deletions firmware/network/border_router/border_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
#include <stdio.h>
#include <string.h>
#include "border_router.h"
#include "rpl_protocol.h"

static uint8_t radio_devices[] = {NETDEV_AT86RF215, NETDEV_AT86RF2XX, NETDEV_CC2538};
#include "radio.h"
#include "net_tools.h"

int8_t get_wired_iface(void) {
int max_ifaces = gnrc_netif_numof();
Expand All @@ -39,94 +38,51 @@ int8_t get_wired_iface(void) {
return -1;
}

int8_t get_wireless_iface(void) {
int max_ifaces = gnrc_netif_numof();
if (max_ifaces > 0) {
gnrc_netif_t *iface;
for (uint8_t i = 0; i < ARRAY_SIZE(radio_devices); i++) {
iface = gnrc_netif_get_by_type(radio_devices[i], NETDEV_INDEX_ANY);
if (iface != NULL) {
break;
}
}
if (iface != NULL) {
return iface->pid;
} else {
return -1;
}
}
return -1;
}

int border_router_add_ipv6(int cast_type, ipv6_addr_t *addr) {
int border_router_add_ipv6(int cast_type, ipv6_addr_t *addr, uint8_t iface_type) {
uint16_t flags = GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID;
uint8_t prefix_len = _IPV6_DEFAULT_PREFIX_LEN;
netif_t *iface = NULL;
int index = get_wired_iface();
int16_t isWired;
iface = netif_get_by_id(index);
if (cast_type == _ANYCAST || cast_type == _UNICAST || cast_type == _MULTICAST) {
if (netif_get_opt(iface, NETOPT_IS_WIRED, 0, &isWired, sizeof(isWired)) > 0) {
if (cast_type == _MULTICAST) {
if (ipv6_addr_is_multicast(addr)) {
if (netif_set_opt(iface, NETOPT_IPV6_GROUP, 0, addr, sizeof(ipv6_addr_t)) < 0) {
printf("error: unable to join IPv6 multicast group\n");
return -1;
}
} else {
return -1;
}
} else {
if (cast_type == _ANYCAST) {
flags |= GNRC_NETIF_IPV6_ADDRS_FLAGS_ANYCAST;
}
flags |= (prefix_len << 8U);
if (netif_set_opt(iface, NETOPT_IPV6_ADDR, flags, addr, sizeof(ipv6_addr_t)) < 0) {
printf("error: unable to add IPv6 address\n");
return -1;
}
}
} else {
return -1;
}
ipv6_addr_t ip;
int8_t index;
if (iface_type == WIRED_INTERFACE) {
index = get_wired_iface();
} else if (iface_type == WIRELESS_INTERFACE) {
index = get_ieee802154_iface();
} else {
printf("Error: Type of Interface doesn't exists File: %s, line: %d\n", __FILE__, __LINE__);
return -1;
}
if (index == -1) {
printf("Error: Expected interface wasn't found. File: %s, line %d\n", __FILE__, __LINE__);
return -1;
}
if (get_ipv6_global(index, &ip) == 0) {
printf("Error: Already exists an ipv6 Address File: %s, line: %d\n", __FILE__, __LINE__);
return -1;
}
return 0;
}

int border_router_add_ipv6_node(int cast_type, ipv6_addr_t *addr) {
uint16_t flags = GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID;
uint8_t prefix_len = _IPV6_DEFAULT_PREFIX_LEN;
netif_t *iface = NULL;
int index = get_wireless_iface();
iface = netif_get_by_id(index);
if (cast_type == _ANYCAST || cast_type == _UNICAST || cast_type == _MULTICAST) {
if (cast_type == _MULTICAST) {
if (ipv6_addr_is_multicast(addr)) {
if (netif_set_opt(iface, NETOPT_IPV6_GROUP, 0, addr, sizeof(ipv6_addr_t)) < 0) {
printf("error: unable to join IPv6 multicast group\n");
return -1;
}
} else {
if (cast_type == _MULTICAST) {
if (ipv6_addr_is_multicast(addr)) {
if (netif_set_opt(iface, NETOPT_IPV6_GROUP, 0, addr, sizeof(ipv6_addr_t)) < 0) {
printf("error: unable to join IPv6 multicast group\n");
return -1;
}
} else {
if (cast_type == _ANYCAST) {
flags |= GNRC_NETIF_IPV6_ADDRS_FLAGS_ANYCAST;
}
flags |= (prefix_len << 8U);
if (netif_set_opt(iface, NETOPT_IPV6_ADDR, flags, addr, sizeof(ipv6_addr_t)) < 0) {
printf("error: unable to add IPv6 address\n");
return -1;
}
return -1;
}
} else {
if (cast_type == _ANYCAST) {
flags |= GNRC_NETIF_IPV6_ADDRS_FLAGS_ANYCAST;
}
flags |= (prefix_len << 8U);
if (netif_set_opt(iface, NETOPT_IPV6_ADDR, flags, addr, sizeof(ipv6_addr_t)) < 0) {
printf("error: unable to add IPv6 address\n");
return -1;
}
}
} else {
return -1;
}

rpl_init(index);

gnrc_rpl_dodag_root(CONFIG_DODAG_INSTANCE, addr);
return 0;
}
35 changes: 19 additions & 16 deletions firmware/network/border_router/include/border_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,34 @@ extern "C" {
*
*/
enum cast_t {
_UNICAST = 0, /*!< Sets a process by which a packet is sent
from one host to an individual host*/
_ANYCAST, /*!< Sets a method forwards messages to a single
device of a specific group of devices. */
_MULTICAST /*!< Sets multicasting addresses messages for a
specific group of devices in a network */
};
_UNICAST = 0, /*!< Sets a process by which a packet is sent
from one host to an individual host*/
_ANYCAST, /*!< Sets a method forwards messages to a single
device of a specific group of devices. */
_MULTICAST /*!< Sets multicasting addresses messages for a
specific group of devices in a network */
};

/**
* @brief This function it's set to border router to host.
* @enum type_iface_t List of all types of Interface
* @{
*
* @param [in] cast_type cast_type you want to set
* @param [in] addr ipv6 address
* @return int
*/
int border_router_add_ipv6(int cast_type, ipv6_addr_t *addr);
enum type_iface_t {
WIRED_INTERFACE = 0, /*!<Represents the type of interface is wired*/
WIRELESS_INTERFACE /*!<Represents the type of interface is wireless*/
};
/**@}*/

/**
* @brief This function it's set to border router to node.
* @brief This function it's set to border router to host.
*
* @param[in] cast_type cast_type you want to set
* @param[in] addr ipv6 address
* @param [in] cast_type cast_type you want to set
* @param [in] addr ipv6 address
* @param [in] iface_type refers to if is used a WIRED or WIRELESS interface.
* @return int
*/
int border_router_add_ipv6_node(int cast_type, ipv6_addr_t *addr);
int border_router_add_ipv6(int cast_type, ipv6_addr_t *addr, uint8_t iface_type);

#ifdef __cplusplus
}
Expand Down
22 changes: 0 additions & 22 deletions firmware/network/border_router_node/Makefile.dep

This file was deleted.

2 changes: 0 additions & 2 deletions firmware/network/border_router_node/Makefile.include

This file was deleted.

28 changes: 0 additions & 28 deletions firmware/network/border_router_node/border_router_node.c

This file was deleted.

10 changes: 0 additions & 10 deletions firmware/network/border_router_node/doc.txt

This file was deleted.

42 changes: 0 additions & 42 deletions firmware/network/border_router_node/include/border_router_node.h

This file was deleted.

File renamed without changes.
11 changes: 11 additions & 0 deletions firmware/network/net_tools/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ifneq (,$(filter netdev_default,$(USEMODULE)))
USEMODULE += netdev_default
endif

ifeq (,$(filter auto_init_gnrc_netif,$(USEMODULE)))
USEMODULE += auto_init_gnrc_netif
endif

ifeq (,$(filter gnrc_ipv6_default,$(USEMODULE)))
USEMODULE += gnrc_ipv6_default
endif
2 changes: 2 additions & 0 deletions firmware/network/net_tools/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USEMODULE_INCLUDES_net_tools := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_net_tools)
Loading

0 comments on commit e29891e

Please # to comment.