Skip to content
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

pkg/lwip: fix code style #18357

Merged
merged 1 commit into from
Jul 22, 2022
Merged
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
34 changes: 17 additions & 17 deletions pkg/lwip/contrib/_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ int netif_get_opt(netif_t *iface, netopt_t opt, uint16_t context,
int res = -ENOTSUP;
switch (opt) {
#ifdef MODULE_LWIP_IPV6
case NETOPT_IPV6_ADDR: {
assert(max_len >= sizeof(ipv6_addr_t));
ipv6_addr_t *tgt = value;
case NETOPT_IPV6_ADDR: {
assert(max_len >= sizeof(ipv6_addr_t));
ipv6_addr_t *tgt = value;

res = 0;
for (unsigned i = 0;
((res + sizeof(ipv6_addr_t)) <= max_len) &&
(i < LWIP_IPV6_NUM_ADDRESSES);
i++) {
if (netif_ip6_addr_state(netif, i) != IP6_ADDR_INVALID) {
memcpy(tgt, &(netif_ip6_addr(netif, i)->addr), sizeof(ipv6_addr_t));
res += sizeof(ipv6_addr_t);
tgt++;
}
res = 0;
for (unsigned i = 0;
((res + sizeof(ipv6_addr_t)) <= max_len) &&
(i < LWIP_IPV6_NUM_ADDRESSES);
i++) {
if (netif_ip6_addr_state(netif, i) != IP6_ADDR_INVALID) {
memcpy(tgt, &(netif_ip6_addr(netif, i)->addr), sizeof(ipv6_addr_t));
res += sizeof(ipv6_addr_t);
tgt++;
}
}
break;
}
break;
#endif
default:
break;
default:
break;
}
if (res == -ENOTSUP) {
// Ask underlying netdev
/* Ask underlying netdev */
res = dev->driver->get(dev, opt, value, max_len);
}
return res;
Expand Down
171 changes: 85 additions & 86 deletions pkg/lwip/contrib/netdev/lwip_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,83 +96,82 @@ err_t lwip_netdev_init(struct netif *netif)
netif->hostname = "riot";
#endif /* LWIP_NETIF_HOSTNAME */

/* XXX: for now assume its Ethernet, since netdev is implemented only by ethernet drivers */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This comment is obsolete, below both Ethernet and IEEE 802.15.4 devices are handled differently. There is no "this must be Ethernet" assumption baked in anywhere.

switch (dev_type) {
#ifdef MODULE_NETDEV_ETH
case NETDEV_TYPE_ETHERNET:
netif->name[0] = ETHERNET_IFNAME1;
netif->name[1] = ETHERNET_IFNAME2;
netif->hwaddr_len = (u8_t)netdev->driver->get(netdev, NETOPT_ADDRESS, netif->hwaddr,
sizeof(netif->hwaddr));
if (netif->hwaddr_len > sizeof(netif->hwaddr)) {
return ERR_IF;
}
/* TODO: get from driver (currently not in netdev_eth) */
netif->mtu = ETHERNET_DATA_LEN;
netif->linkoutput = _eth_link_output;
case NETDEV_TYPE_ETHERNET:
netif->name[0] = ETHERNET_IFNAME1;
netif->name[1] = ETHERNET_IFNAME2;
netif->hwaddr_len = (u8_t)netdev->driver->get(netdev, NETOPT_ADDRESS, netif->hwaddr,
sizeof(netif->hwaddr));
if (netif->hwaddr_len > sizeof(netif->hwaddr)) {
return ERR_IF;
}
/* TODO: get from driver (currently not in netdev_eth) */
netif->mtu = ETHERNET_DATA_LEN;
netif->linkoutput = _eth_link_output;
#if LWIP_IPV4
netif->output = etharp_output;
netif->output = etharp_output;
#endif
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
netif_create_ip6_linklocal_address(netif, 1); /* 1: hwaddr is 48-bit MAC addr */
netif->output_ip6 = ethip6_output;
netif_create_ip6_linklocal_address(netif, 1); /* 1: hwaddr is 48-bit MAC addr */
#endif
netif->flags |= NETIF_FLAG_BROADCAST;
netif->flags |= NETIF_FLAG_ETHARP;
netif->flags |= NETIF_FLAG_ETHERNET;
break;
netif->flags |= NETIF_FLAG_BROADCAST;
netif->flags |= NETIF_FLAG_ETHARP;
netif->flags |= NETIF_FLAG_ETHERNET;
break;
#endif
#ifdef MODULE_LWIP_SIXLOWPAN
case NETDEV_TYPE_IEEE802154:
{
u16_t val;
ip6_addr_t *addr;
netif->name[0] = WPAN_IFNAME1;
netif->name[1] = WPAN_IFNAME2;
if (netdev->driver->get(netdev, NETOPT_NID, &val,
sizeof(val)) < 0) {
return ERR_IF;
}
lowpan6_set_pan_id(val);
netif->hwaddr_len = (u8_t)netdev->driver->get(netdev, NETOPT_ADDRESS_LONG,
netif->hwaddr, sizeof(netif->hwaddr));
if (netif->hwaddr_len > sizeof(netif->hwaddr)) {
return ERR_IF;
}
netif->linkoutput = _ieee802154_link_output;
res = lowpan6_if_init(netif);
if (res != ERR_OK) {
return res;
}
/* assure usage of long address as source address */
val = netif->hwaddr_len;
if (netdev->driver->set(netdev, NETOPT_SRC_LEN, &val, sizeof(val)) < 0) {
return ERR_IF;
}
/* netif_create_ip6_linklocal_address() does weird byte-swapping
* with full IIDs, so let's do it ourselves */
addr = ip_2_ip6(&(netif->ip6_addr[0]));
/* addr->addr is a uint32_t array */
if (l2util_ipv6_iid_from_addr(dev_type,
netif->hwaddr, netif->hwaddr_len,
(eui64_t *)&addr->addr[2]) < 0) {
return ERR_IF;
}
ipv6_addr_set_link_local_prefix((ipv6_addr_t *)&addr->addr[0]);
ip6_addr_assign_zone(addr, IP6_UNICAST, netif);
/* Set address state. */
case NETDEV_TYPE_IEEE802154:
{
u16_t val;
ip6_addr_t *addr;
netif->name[0] = WPAN_IFNAME1;
netif->name[1] = WPAN_IFNAME2;
if (netdev->driver->get(netdev, NETOPT_NID, &val,
sizeof(val)) < 0) {
return ERR_IF;
}
lowpan6_set_pan_id(val);
netif->hwaddr_len = (u8_t)netdev->driver->get(netdev, NETOPT_ADDRESS_LONG,
netif->hwaddr, sizeof(netif->hwaddr));
if (netif->hwaddr_len > sizeof(netif->hwaddr)) {
return ERR_IF;
}
netif->linkoutput = _ieee802154_link_output;
res = lowpan6_if_init(netif);
if (res != ERR_OK) {
return res;
}
/* assure usage of long address as source address */
val = netif->hwaddr_len;
if (netdev->driver->set(netdev, NETOPT_SRC_LEN, &val, sizeof(val)) < 0) {
return ERR_IF;
}
/* netif_create_ip6_linklocal_address() does weird byte-swapping
* with full IIDs, so let's do it ourselves */
addr = ip_2_ip6(&(netif->ip6_addr[0]));
/* addr->addr is a uint32_t array */
if (l2util_ipv6_iid_from_addr(dev_type,
netif->hwaddr, netif->hwaddr_len,
(eui64_t *)&addr->addr[2]) < 0) {
return ERR_IF;
}
ipv6_addr_set_link_local_prefix((ipv6_addr_t *)&addr->addr[0]);
ip6_addr_assign_zone(addr, IP6_UNICAST, netif);
/* Set address state. */
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS
/* Will perform duplicate address detection (DAD). */
netif->ip6_addr_state[0] = IP6_ADDR_TENTATIVE;
/* Will perform duplicate address detection (DAD). */
netif->ip6_addr_state[0] = IP6_ADDR_TENTATIVE;
#else
/* Consider address valid. */
netif->ip6_addr_state[0] = IP6_ADDR_PREFERRED;
/* Consider address valid. */
netif->ip6_addr_state[0] = IP6_ADDR_PREFERRED;
#endif /* LWIP_IPV6_AUTOCONFIG */
break;
}
break;
}
#endif
default:
return ERR_IF; /* device type not supported yet */
default:
return ERR_IF; /* device type not supported yet */
}
netif->flags |= NETIF_FLAG_UP;
/* Set link state up if link state is unsupported, or if it is up */
Expand Down Expand Up @@ -271,29 +270,29 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
lwip_netif_t *compat_netif = dev->context;
struct netif *netif = &compat_netif->lwip_netif;
switch (event) {
case NETDEV_EVENT_RX_COMPLETE: {
struct pbuf *p = _get_recv_pkt(dev);
if (p == NULL) {
DEBUG("lwip_netdev: error receiving packet\n");
return;
}
if (netif->input(p, netif) != ERR_OK) {
DEBUG("lwip_netdev: error inputing packet\n");
return;
}
break;
case NETDEV_EVENT_RX_COMPLETE: {
struct pbuf *p = _get_recv_pkt(dev);
if (p == NULL) {
DEBUG("lwip_netdev: error receiving packet\n");
return;
}
case NETDEV_EVENT_LINK_UP: {
/* Will wake up DHCP state machine */
netifapi_netif_set_link_up(netif);
break;
if (netif->input(p, netif) != ERR_OK) {
DEBUG("lwip_netdev: error inputing packet\n");
return;
}
case NETDEV_EVENT_LINK_DOWN: {
netifapi_netif_set_link_down(netif);
break;
}
default:
break;
break;
}
case NETDEV_EVENT_LINK_UP: {
/* Will wake up DHCP state machine */
netifapi_netif_set_link_up(netif);
break;
}
case NETDEV_EVENT_LINK_DOWN: {
netifapi_netif_set_link_down(netif);
break;
}
default:
break;
}
}
}
Expand Down
74 changes: 37 additions & 37 deletions pkg/lwip/contrib/sock/ip/lwip_sock_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,50 +123,50 @@ static int _parse_iphdr(struct netbuf *buf, void **data, void **ctx,

switch (data_ptr[0] >> 4) {
#if LWIP_IPV4
case 4:
if (remote != NULL) {
struct ip_hdr *iphdr = (struct ip_hdr *)data_ptr;
case 4:
if (remote != NULL) {
struct ip_hdr *iphdr = (struct ip_hdr *)data_ptr;

assert(buf->p->len > sizeof(struct ip_hdr));
remote->family = AF_INET;
memcpy(&remote->addr, &iphdr->src, sizeof(ip4_addr_t));
remote->netif = _ip4_addr_to_netif(&iphdr->dest);
}
if (local != NULL) {
struct ip_hdr *iphdr = (struct ip_hdr *)data_ptr;
assert(buf->p->len > sizeof(struct ip_hdr));
remote->family = AF_INET;
memcpy(&remote->addr, &iphdr->src, sizeof(ip4_addr_t));
remote->netif = _ip4_addr_to_netif(&iphdr->dest);
}
if (local != NULL) {
struct ip_hdr *iphdr = (struct ip_hdr *)data_ptr;

assert(buf->p->len > sizeof(struct ip_hdr));
local->family = AF_INET;
memcpy(&local->addr, &iphdr->dest, sizeof(ip4_addr_t));
}
data_ptr += sizeof(struct ip_hdr);
data_len -= sizeof(struct ip_hdr);
break;
assert(buf->p->len > sizeof(struct ip_hdr));
local->family = AF_INET;
memcpy(&local->addr, &iphdr->dest, sizeof(ip4_addr_t));
}
data_ptr += sizeof(struct ip_hdr);
data_len -= sizeof(struct ip_hdr);
break;
#endif
#if LWIP_IPV6
case 6:
if (remote != NULL) {
struct ip6_hdr *iphdr = (struct ip6_hdr *)data_ptr;
case 6:
if (remote != NULL) {
struct ip6_hdr *iphdr = (struct ip6_hdr *)data_ptr;

assert(buf->p->len > sizeof(struct ip6_hdr));
remote->family = AF_INET6;
memcpy(&remote->addr, &iphdr->src, sizeof(ip6_addr_t));
remote->netif = _ip6_addr_to_netif(&iphdr->dest);
}
if (local != NULL) {
struct ip6_hdr *iphdr = (struct ip6_hdr *)data_ptr;
assert(buf->p->len > sizeof(struct ip6_hdr));
remote->family = AF_INET6;
memcpy(&remote->addr, &iphdr->src, sizeof(ip6_addr_t));
remote->netif = _ip6_addr_to_netif(&iphdr->dest);
}
if (local != NULL) {
struct ip6_hdr *iphdr = (struct ip6_hdr *)data_ptr;

assert(buf->p->len > sizeof(struct ip6_hdr));
local->family = AF_INET6;
memcpy(&local->addr, &iphdr->dest, sizeof(ip6_addr_t));
}
data_ptr += sizeof(struct ip6_hdr);
data_len -= sizeof(struct ip6_hdr);
break;
assert(buf->p->len > sizeof(struct ip6_hdr));
local->family = AF_INET6;
memcpy(&local->addr, &iphdr->dest, sizeof(ip6_addr_t));
}
data_ptr += sizeof(struct ip6_hdr);
data_len -= sizeof(struct ip6_hdr);
break;
#endif
default:
netbuf_delete(buf);
return -EPROTO;
default:
netbuf_delete(buf);
return -EPROTO;
}
*data = data_ptr;
*ctx = buf;
Expand Down
Loading