mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
netdev2_ieee802154: replace overflow checks with asserts
This commit is contained in:
parent
8a85725cf9
commit
315dea3e7c
@ -32,9 +32,7 @@ static int _get_iid(netdev2_ieee802154_t *dev, eui64_t *value, size_t max_len)
|
||||
uint8_t *addr;
|
||||
uint16_t addr_len;
|
||||
|
||||
if (max_len < sizeof(eui64_t)) {
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
assert(max_len >= sizeof(eui64_t));
|
||||
|
||||
if (dev->flags & NETDEV2_IEEE802154_SRC_MODE_LONG) {
|
||||
addr_len = IEEE802154_LONG_ADDRESS_LEN;
|
||||
@ -56,27 +54,18 @@ int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
|
||||
switch (opt) {
|
||||
case NETOPT_ADDRESS:
|
||||
if (max_len < sizeof(dev->short_addr)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len >= sizeof(dev->short_addr));
|
||||
memcpy(value, dev->short_addr, sizeof(dev->short_addr));
|
||||
res = sizeof(dev->short_addr);
|
||||
break;
|
||||
case NETOPT_ADDRESS_LONG:
|
||||
if (max_len < sizeof(dev->long_addr)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len >= sizeof(dev->long_addr));
|
||||
memcpy(value, dev->long_addr, sizeof(dev->long_addr));
|
||||
res = sizeof(dev->long_addr);
|
||||
break;
|
||||
case NETOPT_ADDR_LEN:
|
||||
case NETOPT_SRC_LEN:
|
||||
if (max_len < sizeof(uint16_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
if (dev->flags & NETDEV2_IEEE802154_SRC_MODE_LONG) {
|
||||
*((uint16_t *)value) = IEEE802154_LONG_ADDRESS_LEN;
|
||||
}
|
||||
@ -86,26 +75,17 @@ int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
res = sizeof(uint16_t);
|
||||
break;
|
||||
case NETOPT_NID:
|
||||
if (max_len < sizeof(dev->pan)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(dev->pan));
|
||||
*((uint16_t *)value) = dev->pan;
|
||||
res = sizeof(dev->pan);
|
||||
break;
|
||||
case NETOPT_CHANNEL:
|
||||
if (max_len < sizeof(uint16_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = (uint16_t)dev->chan;
|
||||
res = sizeof(dev->chan);
|
||||
break;
|
||||
case NETOPT_AUTOACK:
|
||||
if (max_len < sizeof(netopt_enable_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(netopt_enable_t));
|
||||
if (dev->flags & NETDEV2_IEEE802154_ACK_REQ) {
|
||||
*((netopt_enable_t *)value) = NETOPT_ENABLE;
|
||||
}
|
||||
@ -115,10 +95,7 @@ int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
res = sizeof(netopt_enable_t);
|
||||
break;
|
||||
case NETOPT_RAWMODE:
|
||||
if (max_len < sizeof(netopt_enable_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(netopt_enable_t));
|
||||
if (dev->flags & NETDEV2_IEEE802154_RAW) {
|
||||
*((netopt_enable_t *)value) = NETOPT_ENABLE;
|
||||
}
|
||||
@ -129,19 +106,13 @@ int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
break;
|
||||
#ifdef MODULE_GNRC
|
||||
case NETOPT_PROTO:
|
||||
if (max_len < sizeof(gnrc_nettype_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(gnrc_nettype_t));
|
||||
*((gnrc_nettype_t *)value) = dev->proto;
|
||||
res = sizeof(gnrc_nettype_t);
|
||||
break;
|
||||
#endif
|
||||
case NETOPT_DEVICE_TYPE:
|
||||
if (max_len < sizeof(uint16_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(uint16_t));
|
||||
*((uint16_t *)value) = NETDEV2_TYPE_IEEE802154;
|
||||
res = sizeof(uint16_t);
|
||||
break;
|
||||
@ -150,10 +121,7 @@ int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
break;
|
||||
#ifdef MODULE_NETSTATS_L2
|
||||
case NETOPT_STATS:
|
||||
if (max_len < sizeof(uintptr_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(max_len == sizeof(uintptr_t));
|
||||
*((netstats_t **)value) = &dev->netdev.stats;
|
||||
res = sizeof(uintptr_t);
|
||||
break;
|
||||
@ -172,10 +140,7 @@ int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
switch (opt) {
|
||||
case NETOPT_CHANNEL:
|
||||
{
|
||||
if (len > sizeof(uint16_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(len == sizeof(uint16_t));
|
||||
uint16_t chan = *((uint16_t *)value);
|
||||
/* real validity needs to be checked by device, since sub-GHz and
|
||||
* 2.4 GHz band radios have different legal values. Here we only
|
||||
@ -186,29 +151,20 @@ int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
break;
|
||||
}
|
||||
case NETOPT_ADDRESS:
|
||||
if (len > sizeof(dev->short_addr)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(len <= sizeof(dev->short_addr));
|
||||
memset(dev->short_addr, 0, sizeof(dev->short_addr));
|
||||
memcpy(dev->short_addr, value, len);
|
||||
res = sizeof(dev->short_addr);
|
||||
break;
|
||||
case NETOPT_ADDRESS_LONG:
|
||||
if (len > sizeof(dev->long_addr)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(len <= sizeof(dev->long_addr));
|
||||
memset(dev->long_addr, 0, sizeof(dev->long_addr));
|
||||
memcpy(dev->long_addr, value, len);
|
||||
res = sizeof(dev->long_addr);
|
||||
break;
|
||||
case NETOPT_ADDR_LEN:
|
||||
case NETOPT_SRC_LEN:
|
||||
if (len > sizeof(uint16_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(len == sizeof(uint16_t));
|
||||
switch ((*(uint16_t *)value)) {
|
||||
case IEEE802154_SHORT_ADDRESS_LEN:
|
||||
dev->flags &= ~NETDEV2_IEEE802154_SRC_MODE_LONG;
|
||||
@ -223,10 +179,7 @@ int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
res = sizeof(uint16_t);
|
||||
break;
|
||||
case NETOPT_NID:
|
||||
if (len > sizeof(uint16_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(len == sizeof(dev->pan));
|
||||
dev->pan = *((uint16_t *)value);
|
||||
res = sizeof(dev->pan);
|
||||
break;
|
||||
@ -250,10 +203,7 @@ int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
|
||||
break;
|
||||
#ifdef MODULE_GNRC
|
||||
case NETOPT_PROTO:
|
||||
if (len > sizeof(gnrc_nettype_t)) {
|
||||
res = -EOVERFLOW;
|
||||
break;
|
||||
}
|
||||
assert(len == sizeof(gnrc_nettype_t));
|
||||
dev->proto = *((gnrc_nettype_t *)value);
|
||||
res = sizeof(gnrc_nettype_t);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user