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

Merge pull request #5227 from authmillenon/at86rf2xx/fix/set

at86rf2xx: fix option setting
This commit is contained in:
Martine Lenders 2016-04-20 17:33:44 +02:00
commit cedf7d8455
2 changed files with 24 additions and 13 deletions

View File

@ -383,7 +383,7 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
{
at86rf2xx_t *dev = (at86rf2xx_t *) netdev;
uint8_t old_state = at86rf2xx_get_status(dev);
int res = 0;
int res = -ENOTSUP;
if (dev == NULL) {
return -ENODEV;
@ -433,7 +433,7 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
uint8_t chan = ((uint8_t *)val)[0];
if (chan < AT86RF2XX_MIN_CHANNEL ||
chan > AT86RF2XX_MAX_CHANNEL) {
res = -ENOTSUP;
res = -EINVAL;
break;
}
at86rf2xx_set_chan(dev, chan);
@ -449,7 +449,7 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
uint8_t page = ((uint8_t *)val)[0];
#ifdef MODULE_AT86RF212B
if ((page != 0) && (page != 2)) {
res = -ENOTSUP;
res = -EINVAL;
}
else {
at86rf2xx_set_page(dev, page);
@ -458,7 +458,7 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
#else
/* rf23x only supports page 0, no need to configure anything in the driver. */
if (page != 0) {
res = -ENOTSUP;
res = -EINVAL;
}
else {
res = sizeof(uint16_t);
@ -549,11 +549,8 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
(*((uint8_t *)val) > 5)) {
res = -EOVERFLOW;
}
else if (!(dev->netdev.flags & AT86RF2XX_OPT_CSMA)) {
/* If CSMA is disabled, don't allow setting retries */
res = -ENOTSUP;
}
else {
else if (dev->netdev.flags & AT86RF2XX_OPT_CSMA) {
/* only set if CSMA is enabled */
at86rf2xx_set_csma_max_retries(dev, *((uint8_t *)val));
res = sizeof(uint8_t);
}
@ -570,7 +567,7 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
break;
default:
res = -ENOTSUP;
break;
}
/* go back to sleep if were sleeping and state hasn't been changed */

View File

@ -154,7 +154,7 @@ int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
res = -EOVERFLOW;
break;
}
*((netstats_t**)value) = &dev->netdev.stats;
*((netstats_t **)value) = &dev->netdev.stats;
res = sizeof(uintptr_t);
break;
#endif
@ -170,6 +170,21 @@ int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
int res = -ENOTSUP;
switch (opt) {
case NETOPT_CHANNEL:
{
if (len > sizeof(uint16_t)) {
res = -EOVERFLOW;
break;
}
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
* check that it fits in an 8-bit variabl*/
assert(chan <= UINT8_MAX);
dev->chan = chan;
res = sizeof(uint16_t);
break;
}
case NETOPT_ADDRESS:
if (len > sizeof(dev->short_addr)) {
res = -EOVERFLOW;
@ -208,14 +223,13 @@ int netdev2_ieee802154_set(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
res = sizeof(uint16_t);
break;
case NETOPT_NID:
if (len > sizeof(dev->pan)) {
if (len > sizeof(uint16_t)) {
res = -EOVERFLOW;
break;
}
dev->pan = *((uint16_t *)value);
res = sizeof(dev->pan);
break;
/* channel can be very device specific */
case NETOPT_AUTOACK:
if ((*(bool *)value)) {
dev->flags |= NETDEV2_IEEE802154_ACK_REQ;