net: ieee802154: Use proper network interface in shell
If the device has multiple network interface, then we must not blindly use the default one but get the IEEE 802.15.4 network interface when setting radio parameters in the shell. Jira: ZEP-2432 Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
f4673fa8b6
commit
b57edf042e
1 changed files with 84 additions and 14 deletions
|
@ -27,7 +27,12 @@ static struct net_mgmt_event_callback scan_cb;
|
|||
|
||||
static int shell_cmd_ack(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "set") || !strcmp(argv[1], "1")) {
|
||||
net_mgmt(NET_REQUEST_IEEE802154_SET_ACK, iface, NULL, 0);
|
||||
|
@ -66,7 +71,12 @@ static inline void parse_extended_address(char *addr, u8_t *ext_addr)
|
|||
|
||||
static int shell_cmd_associate(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
params.pan_id = atoi(argv[1]);
|
||||
|
||||
|
@ -91,9 +101,14 @@ static int shell_cmd_associate(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_disassociate(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
int ret;
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = net_mgmt(NET_REQUEST_IEEE802154_DISASSOCIATE, iface, NULL, 0);
|
||||
if (ret == -EALREADY) {
|
||||
printk("Interface is not associated\n");
|
||||
|
@ -162,10 +177,15 @@ static void scan_result_cb(struct net_mgmt_event_callback *cb,
|
|||
|
||||
static int shell_cmd_scan(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u32_t scan_type;
|
||||
int ret;
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(¶ms, 0, sizeof(struct ieee802154_req_params));
|
||||
|
||||
net_mgmt_init_event_callback(&scan_cb, scan_result_cb,
|
||||
|
@ -214,9 +234,14 @@ static int shell_cmd_scan(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_set_chan(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u16_t channel = (u16_t) atoi(argv[1]);
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_SET_CHANNEL, iface,
|
||||
&channel, sizeof(u16_t))) {
|
||||
printk("Could not set channel %u\n", channel);
|
||||
|
@ -229,9 +254,14 @@ static int shell_cmd_set_chan(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_get_chan(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u16_t channel;
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_GET_CHANNEL, iface,
|
||||
&channel, sizeof(u16_t))) {
|
||||
printk("Could not get channel\n");
|
||||
|
@ -244,9 +274,14 @@ static int shell_cmd_get_chan(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_set_pan_id(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u16_t pan_id = (u16_t) atoi(argv[1]);
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_SET_PAN_ID, iface,
|
||||
&pan_id, sizeof(u16_t))) {
|
||||
printk("Could not set PAN ID %u\n", pan_id);
|
||||
|
@ -259,9 +294,14 @@ static int shell_cmd_set_pan_id(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_get_pan_id(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u16_t pan_id;
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_GET_PAN_ID, iface,
|
||||
&pan_id, sizeof(u16_t))) {
|
||||
printk("Could not get PAN ID\n");
|
||||
|
@ -274,9 +314,14 @@ static int shell_cmd_get_pan_id(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_set_ext_addr(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u8_t addr[IEEE802154_EXT_ADDR_LENGTH];
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (strlen(argv[2]) != 23) {
|
||||
printk("23 characters needed\n");
|
||||
return 0;
|
||||
|
@ -296,9 +341,14 @@ static int shell_cmd_set_ext_addr(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_get_ext_addr(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u8_t addr[IEEE802154_EXT_ADDR_LENGTH];
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_GET_EXT_ADDR, iface,
|
||||
addr, IEEE802154_EXT_ADDR_LENGTH)) {
|
||||
printk("Could not get extended address\n");
|
||||
|
@ -322,9 +372,14 @@ static int shell_cmd_get_ext_addr(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_set_short_addr(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u16_t short_addr = (u16_t) atoi(argv[1]);
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_SET_SHORT_ADDR, iface,
|
||||
&short_addr, sizeof(u16_t))) {
|
||||
printk("Could not set short address %u\n", short_addr);
|
||||
|
@ -337,9 +392,14 @@ static int shell_cmd_set_short_addr(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_get_short_addr(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
u16_t short_addr;
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_GET_SHORT_ADDR, iface,
|
||||
&short_addr, sizeof(u16_t))) {
|
||||
printk("Could not get short address\n");
|
||||
|
@ -352,9 +412,14 @@ static int shell_cmd_get_short_addr(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_set_tx_power(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
s16_t tx_power = (s16_t) atoi(argv[1]);
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_SET_TX_POWER, iface,
|
||||
&tx_power, sizeof(s16_t))) {
|
||||
printk("Could not set TX power %d\n", tx_power);
|
||||
|
@ -367,9 +432,14 @@ static int shell_cmd_set_tx_power(int argc, char *argv[])
|
|||
|
||||
static int shell_cmd_get_tx_power(int argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
struct net_if *iface = net_if_get_ieee802154();
|
||||
s16_t tx_power;
|
||||
|
||||
if (!iface) {
|
||||
printk("No IEEE 802.15.4 interface found.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_IEEE802154_GET_SHORT_ADDR, iface,
|
||||
&tx_power, sizeof(s16_t))) {
|
||||
printk("Could not get TX power\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue