mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
c06335b71b
Previously `shell_commands` was a "catch-all" module that included shell commands for each and every used module that has a shell companion. Instead, the new `shell_cmds` module is now used to provide shell commands as individually selectable submodules, e.g. `cmd_gnrc_icmpv6_echo` now provides the ICMPv6 echo command (a.k.a. ping). To still have a "catch all" module to pull in shell commands of modules already used, `shell_cmds_default` was introduced. `shell_commands` depends now on `shell_cmds_default` for backward compatibility, but has been deprecated. New apps should use `shell_cmds_default` instead. For a handful of shell commands individual selection was already possible. Those modules now depend on the corresponding `cmd_%` module and they have been deprecated.
109 lines
2.6 KiB
C
109 lines
2.6 KiB
C
/*
|
|
* Copyright (C) 2020 Freie Universität Berlin
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup sys_shell_commands
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief Shell commands to control the NimBLE netif statconn connection
|
|
* manager
|
|
*
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "net/bluetil/addr.h"
|
|
#include "nimble_statconn.h"
|
|
#include "shell.h"
|
|
|
|
static uint8_t _parsephy(const char *phy_str)
|
|
{
|
|
if (memcmp(phy_str, "1M", 2) == 0) {
|
|
return NIMBLE_PHY_1M;
|
|
}
|
|
#if IS_ACTIVE(MODULE_NIMBLE_PHY_2MBIT)
|
|
else if (memcmp(phy_str, "2M", 2) == 0) {
|
|
return NIMBLE_PHY_2M;
|
|
}
|
|
#endif
|
|
#if IS_ACTIVE(MODULE_NIMBLE_PHY_CODED)
|
|
else if (memcmp(phy_str, "CODED", 5) == 0) {
|
|
return NIMBLE_PHY_CODED;
|
|
}
|
|
#endif
|
|
else {
|
|
return NIMBLE_PHY_INVALID;
|
|
}
|
|
}
|
|
|
|
static int _nimble_statconn_handler(int argc, char **argv)
|
|
{
|
|
nimble_statconn_cfg_t cfg;
|
|
|
|
if ((argc < 3)) {
|
|
printf("usage: %s <addm|adds|rm> <BLE addr> [phy mode]\n"
|
|
" phy_mode := [1M, 2M, CODED]\n", argv[0]);
|
|
return 0;
|
|
}
|
|
|
|
if (argc >= 4) {
|
|
cfg.phy_mode = _parsephy(argv[3]);
|
|
if (cfg.phy_mode == NIMBLE_PHY_INVALID) {
|
|
puts("err: PHY mode not supported");
|
|
return 1;
|
|
}
|
|
}
|
|
else {
|
|
cfg.phy_mode = NIMBLE_STATCONN_PHY_MODE;
|
|
}
|
|
|
|
/* parse address */
|
|
uint8_t addr[BLE_ADDR_LEN];
|
|
if (bluetil_addr_from_str(addr, argv[2]) == NULL) {
|
|
puts("err: unable to parse BLE address");
|
|
return 1;
|
|
}
|
|
|
|
if (strncmp(argv[1], "addm", 4) == 0) {
|
|
if (nimble_statconn_add_master(addr, &cfg) == 0) {
|
|
puts("success: connecting to peer as slave");
|
|
}
|
|
else {
|
|
puts("err: unable to add peer");
|
|
}
|
|
}
|
|
else if (strncmp(argv[1], "adds", 4) == 0) {
|
|
if (nimble_statconn_add_slave(addr, &cfg) == 0) {
|
|
puts("success: connecting to peer as master");
|
|
}
|
|
else {
|
|
puts("err: unable to add peer");
|
|
}
|
|
}
|
|
else if (strncmp(argv[1], "rm", 2) == 0) {
|
|
if (nimble_statconn_rm(addr) == 0) {
|
|
puts("success: closed connection to peer");
|
|
}
|
|
else {
|
|
puts("err: unable to remove peer");
|
|
}
|
|
}
|
|
else {
|
|
puts("err: unable to parse command");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
SHELL_COMMAND(statconn, "NimBLE netif statconn", _nimble_statconn_handler);
|