static int _set(netdev2_t *dev, netopt_t opt, void *value, size_t value_len) { cc110x_t *cc110x = &((netdev2_cc110x_t*) dev)->cc110x; switch (opt) { case NETOPT_CHANNEL: { uint8_t *arg = (uint8_t*)value; uint8_t channel = arg[value_len-1]; if ((channel < CC110X_MIN_CHANNR) || (channel > CC110X_MAX_CHANNR)) { return -EINVAL; } if (cc110x_set_channel(cc110x, channel) == -1) { return -EINVAL; } return 1; } case NETOPT_ADDRESS: if (value_len < 1) { return -EINVAL; } if (!cc110x_set_address(cc110x, *(uint8_t*)value)) { return -EINVAL; } return 1; default: return -ENOTSUP; } return 0; }
radio_address_t cc110x_set_config_address(radio_address_t address) { radio_address_t a = cc110x_set_address(address); if(a) { sysconfig.radio_address = a; } config_save(); return a; }
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: { const uint8_t *arg = value; uint8_t channel = arg[value_len-1]; #if CC110X_MIN_CHANNR if (channel < CC110X_MIN_CHANNR) { return -EINVAL; } #endif /* CC110X_MIN_CHANNR */ if (channel > CC110X_MAX_CHANNR) { return -EINVAL; } if (cc110x_set_channel(cc110x, channel) == -1) { return -EINVAL; } return 1; } case NETOPT_ADDRESS: if (value_len < 1) { return -EINVAL; } if (!cc110x_set_address(cc110x, *(const uint8_t*)value)) { return -EINVAL; } return 1; #ifdef MODULE_GNRC_NETIF case NETOPT_PROTO: if (value_len != sizeof(gnrc_nettype_t)) { return -EINVAL; } else { cc110x->proto = (gnrc_nettype_t) value; return sizeof(gnrc_nettype_t); } break; #endif default: return -ENOTSUP; } return 0; }
/* * @brief Set the address of the transceiver device * * @param t The transceiver device * @param address Generic pointer to the address to set * * @return The new radio address of the device * * TODO: define error behavior */ static radio_address_t set_address(transceiver_type_t t, void *address) { /* cppcheck: addr is read depending on enabled modules */ /* cppcheck-suppress unreadVariable */ radio_address_t addr = *((radio_address_t *)address); switch (t) { case TRANSCEIVER_CC1100: #if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY)) return cc110x_set_address(addr); #elif MODULE_CC110X_LEGACY_CSMA return cc1100_set_address(addr); #else return 0; /* XXX see TODO above */ #endif #ifdef MODULE_CC2420 case TRANSCEIVER_CC2420: return cc2420_set_address(addr); #endif #ifdef MODULE_MC1322X case TRANSCEIVER_MC1322X: return maca_set_address(addr); #endif #ifdef MODULE_NATIVENET case TRANSCEIVER_NATIVE: return nativenet_set_address(addr); #endif #ifdef MODULE_AT86RF231 case TRANSCEIVER_AT86RF231: return at86rf231_set_address(addr); #endif default: return 0; /* XXX see TODO above */ } }
int _cc110x_set_option(netdev_t *dev, netdev_opt_t opt, void *value, size_t value_len) { if (dev != &cc110x_dev) { return -ENODEV; } switch (opt) { case NETDEV_OPT_CHANNEL: if (value_len != sizeof(uint8_t)) { return -EOVERFLOW; } if (cc110x_set_channel(*((uint8_t *)value)) == -1) { return -EINVAL; } break; case NETDEV_OPT_ADDRESS: /* leaves room for optimization */ if (value_len > sizeof(radio_address_t)) { return -EOVERFLOW; } radio_address_t temp_address; if (value_len == sizeof(uint8_t)) { temp_address = ((radio_address_t)(*((uint8_t *)value))); } else { temp_address = *((radio_address_t *)value); } if (!cc110x_set_address(temp_address)) { return -EINVAL; } break; default: return -ENOTSUP; } return 0; }