Skip to content

Commit

Permalink
netdev: Make set() value parameter const void *
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Nohlgård committed Aug 25, 2017
1 parent 238b5d6 commit 065bc62
Show file tree
Hide file tree
Showing 23 changed files with 129 additions and 129 deletions.
22 changes: 11 additions & 11 deletions cpu/cc2538/radio/cc2538_rf_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define _MAX_MHR_OVERHEAD (25)

static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len);
static int _set(netdev_t *dev, netopt_t opt, void *value, size_t value_len);
static int _set(netdev_t *dev, netopt_t opt, const void *value, size_t value_len);
static int _send(netdev_t *netdev, const struct iovec *vector, unsigned count);
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info);
static void _isr(netdev_t *netdev);
Expand Down Expand Up @@ -148,7 +148,7 @@ static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
return -ENOTSUP;
}

static int _set(netdev_t *netdev, netopt_t opt, void *value, size_t value_len)
static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t value_len)
{
cc2538_rf_t *dev = (cc2538_rf_t *)netdev;
int res = -ENOTSUP;
Expand All @@ -163,7 +163,7 @@ static int _set(netdev_t *netdev, netopt_t opt, void *value, size_t value_len)
res = -EOVERFLOW;
}
else {
cc2538_set_addr_short(*((uint16_t*)value));
cc2538_set_addr_short(*((const uint16_t*)value));
}
break;

Expand All @@ -172,12 +172,12 @@ static int _set(netdev_t *netdev, netopt_t opt, void *value, size_t value_len)
res = -EOVERFLOW;
}
else {
cc2538_set_addr_long(*((uint64_t*)value));
cc2538_set_addr_long(*((const uint64_t*)value));
}
break;

case NETOPT_AUTOACK:
RFCORE->XREG_FRMCTRL0bits.AUTOACK = ((bool *)value)[0];
RFCORE->XREG_FRMCTRL0bits.AUTOACK = ((const bool *)value)[0];
res = sizeof(netopt_enable_t);
break;

Expand All @@ -186,7 +186,7 @@ static int _set(netdev_t *netdev, netopt_t opt, void *value, size_t value_len)
res = -EINVAL;
}
else {
uint8_t chan = ((uint8_t *)value)[0];
uint8_t chan = ((const uint8_t *)value)[0];
if (chan < IEEE802154_CHANNEL_MIN ||
chan > IEEE802154_CHANNEL_MAX) {
res = -EINVAL;
Expand All @@ -200,7 +200,7 @@ static int _set(netdev_t *netdev, netopt_t opt, void *value, size_t value_len)
case NETOPT_CHANNEL_PAGE:
/* This tranceiver only supports page 0 */
if (value_len != sizeof(uint16_t) ||
*((uint16_t *)value) != 0 ) {
*((const uint16_t *)value) != 0 ) {
res = -EINVAL;
}
else {
Expand All @@ -216,28 +216,28 @@ static int _set(netdev_t *netdev, netopt_t opt, void *value, size_t value_len)
res = -EOVERFLOW;
}
else {
cc2538_set_pan(*((uint16_t *)value));
cc2538_set_pan(*((const uint16_t *)value));
}
break;

case NETOPT_PROMISCUOUSMODE:
cc2538_set_monitor(((bool *)value)[0]);
cc2538_set_monitor(((const bool *)value)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_STATE:
if (value_len > sizeof(netopt_state_t)) {
return -EOVERFLOW;
}
cc2538_set_state(dev, *((netopt_state_t *)value));
cc2538_set_state(dev, *((const netopt_state_t *)value));
res = sizeof(netopt_state_t);
break;

case NETOPT_TX_POWER:
if (value_len > sizeof(int16_t)) {
return -EOVERFLOW;
}
cc2538_set_tx_power(*((int16_t *)value));
cc2538_set_tx_power(*((const int16_t *)value));
res = sizeof(uint16_t);
break;

Expand Down
8 changes: 4 additions & 4 deletions cpu/native/netdev_tap/netdev_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static inline void _get_mac_addr(netdev_t *netdev, uint8_t *dst)
memcpy(dst, dev->addr, ETHERNET_ADDR_LEN);
}

static inline void _set_mac_addr(netdev_t *netdev, uint8_t *src)
static inline void _set_mac_addr(netdev_t *netdev, const uint8_t *src)
{
netdev_tap_t *dev = (netdev_tap_t*)netdev;
memcpy(dev->addr, src, ETHERNET_ADDR_LEN);
Expand Down Expand Up @@ -130,18 +130,18 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
return res;
}

static int _set(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
static int _set(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
{
(void)value_len;
int res = 0;

switch (opt) {
case NETOPT_ADDRESS:
assert(value_len >= ETHERNET_ADDR_LEN);
_set_mac_addr(dev, (uint8_t*)value);
_set_mac_addr(dev, (const uint8_t*)value);
break;
case NETOPT_PROMISCUOUSMODE:
_set_promiscous(dev, ((bool *)value)[0]);
_set_promiscous(dev, ((const bool *)value)[0]);
break;
default:
res = netdev_eth_set(dev, opt, value, value_len);
Expand Down
12 changes: 6 additions & 6 deletions cpu/nrf5x_common/radio/nrfmin/nrfmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,31 +509,31 @@ static int nrfmin_get(netdev_t *dev, netopt_t opt, void *val, size_t max_len)
}
}

static int nrfmin_set(netdev_t *dev, netopt_t opt, void *val, size_t len)
static int nrfmin_set(netdev_t *dev, netopt_t opt, const void *val, size_t len)
{
(void)dev;

switch (opt) {
case NETOPT_CHANNEL:
assert(len == sizeof(uint16_t));
return nrfmin_set_channel(*((uint16_t *)val));
return nrfmin_set_channel(*((const uint16_t *)val));
case NETOPT_ADDRESS:
assert(len == sizeof(uint16_t));
nrfmin_set_addr(*((uint16_t *)val));
nrfmin_set_addr(*((const uint16_t *)val));
return sizeof(uint16_t);
case NETOPT_ADDR_LEN:
case NETOPT_SRC_LEN:
assert(len == sizeof(uint16_t));
if (*((uint16_t *)val) != 2) {
if (*((const uint16_t *)val) != 2) {
return -EAFNOSUPPORT;
}
return sizeof(uint16_t);
case NETOPT_STATE:
assert(len == sizeof(netopt_state_t));
return nrfmin_set_state(*((netopt_state_t *)val));
return nrfmin_set_state(*((const netopt_state_t *)val));
case NETOPT_TX_POWER:
assert(len == sizeof(int16_t));
nrfmin_set_txpower(*((int16_t *)val));
nrfmin_set_txpower(*((const int16_t *)val));
return sizeof(int16_t);
default:
return -ENOTSUP;
Expand Down
40 changes: 20 additions & 20 deletions drivers/at86rf2xx/at86rf2xx_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info);
static int _init(netdev_t *netdev);
static void _isr(netdev_t *netdev);
static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len);
static int _set(netdev_t *netdev, netopt_t opt, void *val, size_t len);
static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len);

const netdev_driver_t at86rf2xx_driver = {
.send = _send,
Expand Down Expand Up @@ -347,7 +347,7 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
return res;
}

static int _set(netdev_t *netdev, netopt_t opt, void *val, size_t len)
static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
{
at86rf2xx_t *dev = (at86rf2xx_t *) netdev;
uint8_t old_state = at86rf2xx_get_status(dev);
Expand All @@ -368,22 +368,22 @@ static int _set(netdev_t *netdev, netopt_t opt, void *val, size_t len)
switch (opt) {
case NETOPT_ADDRESS:
assert(len <= sizeof(uint16_t));
at86rf2xx_set_addr_short(dev, *((uint16_t *)val));
at86rf2xx_set_addr_short(dev, *((const uint16_t *)val));
/* don't set res to set netdev_ieee802154_t::short_addr */
break;
case NETOPT_ADDRESS_LONG:
assert(len <= sizeof(uint64_t));
at86rf2xx_set_addr_long(dev, *((uint64_t *)val));
at86rf2xx_set_addr_long(dev, *((const uint64_t *)val));
/* don't set res to set netdev_ieee802154_t::long_addr */
break;
case NETOPT_NID:
assert(len <= sizeof(uint16_t));
at86rf2xx_set_pan(dev, *((uint16_t *)val));
at86rf2xx_set_pan(dev, *((const uint16_t *)val));
/* don't set res to set netdev_ieee802154_t::pan */
break;
case NETOPT_CHANNEL:
assert(len != sizeof(uint8_t));
uint8_t chan = ((uint8_t *)val)[0];
uint8_t chan = ((const uint8_t *)val)[0];
if (chan < AT86RF2XX_MIN_CHANNEL ||
chan > AT86RF2XX_MAX_CHANNEL) {
res = -EINVAL;
Expand All @@ -395,7 +395,7 @@ static int _set(netdev_t *netdev, netopt_t opt, void *val, size_t len)

case NETOPT_CHANNEL_PAGE:
assert(len != sizeof(uint8_t));
uint8_t page = ((uint8_t *)val)[0];
uint8_t page = ((const uint8_t *)val)[0];
#ifdef MODULE_AT86RF212B
if ((page != 0) && (page != 2)) {
res = -EINVAL;
Expand All @@ -417,66 +417,66 @@ static int _set(netdev_t *netdev, netopt_t opt, void *val, size_t len)

case NETOPT_TX_POWER:
assert(len <= sizeof(int16_t));
at86rf2xx_set_txpower(dev, *((int16_t *)val));
at86rf2xx_set_txpower(dev, *((const int16_t *)val));
res = sizeof(uint16_t);
break;

case NETOPT_STATE:
assert(len <= sizeof(netopt_state_t));
res = _set_state(dev, *((netopt_state_t *)val));
res = _set_state(dev, *((const netopt_state_t *)val));
break;

case NETOPT_AUTOACK:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_AUTOACK,
((bool *)val)[0]);
((const bool *)val)[0]);
/* don't set res to set netdev_ieee802154_t::flags */
break;

case NETOPT_RETRANS:
assert(len <= sizeof(uint8_t));
at86rf2xx_set_max_retries(dev, *((uint8_t *)val));
at86rf2xx_set_max_retries(dev, *((const uint8_t *)val));
res = sizeof(uint8_t);
break;

case NETOPT_PRELOADING:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_PRELOADING,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_PROMISCUOUSMODE:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_PROMISCUOUS,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_RX_START_IRQ:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_TELL_RX_START,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_RX_END_IRQ:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_TELL_RX_END,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_TX_START_IRQ:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_TELL_TX_START,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_TX_END_IRQ:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_TELL_TX_END,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

case NETOPT_CSMA:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_CSMA,
((bool *)val)[0]);
((const bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;

Expand All @@ -488,14 +488,14 @@ static int _set(netdev_t *netdev, netopt_t opt, void *val, size_t len)
res = -EINVAL;
}
else {
at86rf2xx_set_csma_max_retries(dev, *((uint8_t *)val));
at86rf2xx_set_csma_max_retries(dev, *((const uint8_t *)val));
res = sizeof(uint8_t);
}
break;

case NETOPT_CCA_THRESHOLD:
assert(len <= sizeof(int8_t));
at86rf2xx_set_cca_threshold(dev, *((int8_t *)val));
at86rf2xx_set_cca_threshold(dev, *((const int8_t *)val));
res = sizeof(int8_t);
break;

Expand Down
6 changes: 3 additions & 3 deletions drivers/cc110x/cc110x-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
return -ENOTSUP;
}

static int _set(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
static int _set(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
{
cc110x_t *cc110x = &((netdev_cc110x_t*) dev)->cc110x;

switch (opt) {
case NETOPT_CHANNEL:
{
uint8_t *arg = (uint8_t*)value;
const uint8_t *arg = value;
uint8_t channel = arg[value_len-1];
if ((channel < CC110X_MIN_CHANNR) || (channel > CC110X_MAX_CHANNR)) {
return -EINVAL;
Expand All @@ -142,7 +142,7 @@ static int _set(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
if (value_len < 1) {
return -EINVAL;
}
if (!cc110x_set_address(cc110x, *(uint8_t*)value)) {
if (!cc110x_set_address(cc110x, *(const uint8_t*)value)) {
return -EINVAL;
}
return 1;
Expand Down
4 changes: 2 additions & 2 deletions drivers/cc2420/cc2420_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr)
addr[1] = tmp[0];
}

void cc2420_set_addr_short(cc2420_t *dev, uint8_t *addr)
void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr)
{
uint8_t tmp[2];
tmp[0] = addr[1];
Expand All @@ -91,7 +91,7 @@ void cc2420_get_addr_long(cc2420_t *dev, uint8_t *addr)
}
}

void cc2420_set_addr_long(cc2420_t *dev, uint8_t *addr)
void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr)
{
int i, j;
uint8_t tmp[8];
Expand Down
Loading

0 comments on commit 065bc62

Please sign in to comment.