static int shell_cmd_scan(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); u32_t scan_type; int ret; memset(¶ms, 0, sizeof(struct ieee802154_req_params)); net_mgmt_init_event_callback(&scan_cb, scan_result_cb, NET_EVENT_IEEE802154_SCAN_RESULT); if (!strcmp(argv[1], "active")) { scan_type = NET_REQUEST_IEEE802154_ACTIVE_SCAN; } else if (!strcmp(argv[1], "passive")) { scan_type = NET_REQUEST_IEEE802154_PASSIVE_SCAN; } else { return -EINVAL; } if (!strcmp(argv[2], "all")) { params.channel_set = IEEE802154_ALL_CHANNELS; } else { params.channel_set = parse_channel_set(argv[2]); } if (!params.channel_set) { return -EINVAL; } params.duration = atoi(argv[3]); printk("%s Scanning (channel set: 0x%08x, duration %u ms)...", scan_type == NET_REQUEST_IEEE802154_ACTIVE_SCAN ? "Active" : "Passive", params.channel_set, params.duration); if (scan_type == NET_REQUEST_IEEE802154_ACTIVE_SCAN) { ret = net_mgmt(NET_REQUEST_IEEE802154_ACTIVE_SCAN, iface, ¶ms, sizeof(struct ieee802154_req_params)); } else { ret = net_mgmt(NET_REQUEST_IEEE802154_PASSIVE_SCAN, iface, ¶ms, sizeof(struct ieee802154_req_params)); } if (ret) { printk("Could not raise a scan (status: %i)\n", ret); } else { printk("Done\n"); } return 0; }
static int shell_cmd_get_ext_addr(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); u8_t addr[IEEE802154_EXT_ADDR_LENGTH]; if (net_mgmt(NET_REQUEST_IEEE802154_GET_EXT_ADDR, iface, addr, IEEE802154_EXT_ADDR_LENGTH)) { printk("Could not get extended address\n"); } else { int i; printk("Extended address: "); for (i = 0; i < IEEE802154_EXT_ADDR_LENGTH; i++) { printk("%02X", addr[i]); if (i < (IEEE802154_EXT_ADDR_LENGTH - 1)) { printk(":"); } } printk("\n"); } return 0; }
static int shell_cmd_ack(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); if (!strcmp(argv[1], "set") || !strcmp(argv[1], "1")) { net_mgmt(NET_REQUEST_IEEE802154_SET_ACK, iface, NULL, 0); printk("ACK flag set on outgoing packets\n"); return 0; } if (!strcmp(argv[1], "unset") || !strcmp(argv[1], "0")) { net_mgmt(NET_REQUEST_IEEE802154_SET_ACK, iface, NULL, 0); printk("ACK flag unset on outgoing packets\n"); return 0; } return -EINVAL; }
static int shell_cmd_get_tx_power(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); s16_t tx_power; if (net_mgmt(NET_REQUEST_IEEE802154_GET_SHORT_ADDR, iface, &tx_power, sizeof(s16_t))) { printk("Could not get TX power\n"); } else { printk("TX power (in dbm) %d\n", tx_power); } return 0; }
static int shell_cmd_set_tx_power(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); s16_t tx_power = (s16_t) atoi(argv[1]); 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); } else { printk("TX power %d set\n", tx_power); } return 0; }
static int shell_cmd_get_short_addr(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); u16_t short_addr; if (net_mgmt(NET_REQUEST_IEEE802154_GET_SHORT_ADDR, iface, &short_addr, sizeof(u16_t))) { printk("Could not get short address\n"); } else { printk("Short address %u\n", short_addr); } return 0; }
static int shell_cmd_get_pan_id(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); u16_t pan_id; if (net_mgmt(NET_REQUEST_IEEE802154_GET_PAN_ID, iface, &pan_id, sizeof(u16_t))) { printk("Could not get PAN ID\n"); } else { printk("PAN ID %u\n", pan_id); } return 0; }
static int shell_cmd_get_chan(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); u16_t channel; if (net_mgmt(NET_REQUEST_IEEE802154_GET_CHANNEL, iface, &channel, sizeof(u16_t))) { printk("Could not get channel\n"); } else { printk("Channel %u\n", channel); } return 0; }
static int shell_cmd_set_chan(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); uint16_t channel = (uint16_t) atoi(argv[1]); if (net_mgmt(NET_REQUEST_IEEE802154_SET_CHAN, iface, &channel, sizeof(uint16_t))) { printk("Could not set channel %u\n", channel); } else { printk("Channel %u set\n", channel); } return 0; }
static int shell_cmd_disassociate(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); int ret; ret = net_mgmt(NET_REQUEST_IEEE802154_DISASSOCIATE, iface, NULL, 0); if (ret == -EALREADY) { printk("Interface is not associated\n"); } else if (ret) { printk("Could not disassociate? (status: %i)\n", ret); } else { printk("Interface is now disassociated\n"); } return 0; }
static int shell_cmd_set_ext_addr(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); u8_t addr[IEEE802154_EXT_ADDR_LENGTH]; if (strlen(argv[2]) != 23) { printk("23 characters needed\n"); return 0; } parse_extended_address(argv[2], addr); if (net_mgmt(NET_REQUEST_IEEE802154_SET_EXT_ADDR, iface, addr, IEEE802154_EXT_ADDR_LENGTH)) { printk("Could not set extended address\n"); } else { printk("Extended address %s set\n", argv[2]); } return 0; }
static int shell_cmd_associate(int argc, char *argv[]) { struct net_if *iface = net_if_get_default(); params.pan_id = atoi(argv[1]); if (strlen(argv[2]) == 23) { parse_extended_address(argv[2], params.addr); params.len = IEEE802154_EXT_ADDR_LENGTH; } else { params.short_addr = (u16_t) atoi(argv[2]); params.len = IEEE802154_SHORT_ADDR_LENGTH; } if (net_mgmt(NET_REQUEST_IEEE802154_ASSOCIATE, iface, ¶ms, sizeof(struct ieee802154_req_params))) { printk("Could not associate to %s on PAN ID %u\n", argv[2], params.pan_id); } else { printk("Associated to PAN ID %u\n", params.pan_id); } return 0; }