net: bt: Convert network Bluetooth shell to use new shell
Use new shell instead of the legacy one. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
1f4bae79e2
commit
d8defbd08a
@ -14,11 +14,11 @@ CONFIG_NET_IPV6_MAX_NEIGHBORS=6
|
||||
CONFIG_NET_MAX_CONTEXTS=5
|
||||
CONFIG_NET_SHELL=y
|
||||
|
||||
CONFIG_NET_PKT_RX_COUNT=16
|
||||
CONFIG_NET_PKT_TX_COUNT=16
|
||||
CONFIG_NET_PKT_RX_COUNT=15
|
||||
CONFIG_NET_PKT_TX_COUNT=15
|
||||
CONFIG_NET_BUF_DATA_SIZE=256
|
||||
CONFIG_NET_BUF_RX_COUNT=15
|
||||
CONFIG_NET_BUF_TX_COUNT=15
|
||||
CONFIG_NET_BUF_RX_COUNT=11
|
||||
CONFIG_NET_BUF_TX_COUNT=11
|
||||
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
@ -60,7 +60,3 @@ CONFIG_BT_CONN=y
|
||||
CONFIG_BT_SIGNING=y
|
||||
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
|
||||
CONFIG_BT_DEBUG_LOG=y
|
||||
|
||||
CONFIG_CONSOLE_SHELL=y
|
||||
CONFIG_CONSOLE_SHELL_STACKSIZE=1504
|
||||
CONFIG_CONSOLE_SHELL_MAX_CMD_QUEUED=3
|
||||
|
||||
@ -64,7 +64,7 @@ config NET_L2_BT_MGMT
|
||||
|
||||
config NET_L2_BT_SHELL
|
||||
bool "Enable Bluetooth shell module"
|
||||
select CONSOLE_SHELL
|
||||
select SHELL
|
||||
select NET_L2_BT_MGMT
|
||||
help
|
||||
This can be used for testing Bluetooth management commands through the
|
||||
|
||||
@ -44,6 +44,12 @@
|
||||
static struct bt_conn *default_conn;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_L2_BT_SHELL)
|
||||
extern int net_bt_shell_init(void);
|
||||
#else
|
||||
#define net_bt_shell_init(...)
|
||||
#endif
|
||||
|
||||
struct bt_context {
|
||||
struct net_if *iface;
|
||||
struct bt_l2cap_le_chan ipsp_chan;
|
||||
@ -561,6 +567,8 @@ static int net_bt_init(struct device *dev)
|
||||
#endif
|
||||
bt_l2cap_server_register(&server);
|
||||
|
||||
net_bt_shell_init();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,8 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <shell/legacy_shell.h>
|
||||
#include <shell/shell.h>
|
||||
#include <shell/shell_uart.h>
|
||||
#include <misc/printk.h>
|
||||
|
||||
#include <net/net_core.h>
|
||||
@ -24,8 +25,6 @@
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
#define BT_SHELL_MODULE "net_bt"
|
||||
|
||||
static int char2hex(const char *c, u8_t *x)
|
||||
{
|
||||
if (*c >= '0' && *c <= '9') {
|
||||
@ -78,86 +77,119 @@ static int str2bt_addr_le(const char *str, const char *type, bt_addr_le_t *addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int shell_cmd_connect(int argc, char *argv[])
|
||||
static int shell_cmd_connect(const struct shell *shell,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
bt_addr_le_t addr;
|
||||
struct net_if *iface = net_if_get_default();
|
||||
|
||||
if (argc < 3) {
|
||||
return -EINVAL;
|
||||
if (argc < 3 || shell_help_requested(shell)) {
|
||||
shell_help_print(shell, NULL, 0);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||
if (err) {
|
||||
printk("Invalid peer address (err %d)\n", err);
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Invalid peer address (err %d)\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_BT_CONNECT, iface, &addr, sizeof(addr))) {
|
||||
printk("Connection failed\n");
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Connection failed\n");
|
||||
} else {
|
||||
printk("Connection pending\n");
|
||||
shell_fprintf(shell, SHELL_NORMAL,
|
||||
"Connection pending\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int shell_cmd_scan(int argc, char *argv[])
|
||||
static int shell_cmd_scan(const struct shell *shell,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
if (argc < 2 || shell_help_requested(shell)) {
|
||||
shell_help_print(shell, NULL, 0);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_BT_SCAN, iface, argv[1], strlen(argv[1]))) {
|
||||
printk("Scan failed\n");
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Scan failed\n");
|
||||
} else {
|
||||
printk("Scan in progress\n");
|
||||
shell_fprintf(shell, SHELL_NORMAL,
|
||||
"Scan in progress\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int shell_cmd_disconnect(int argc, char *argv[])
|
||||
static int shell_cmd_disconnect(const struct shell *shell,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
|
||||
if (shell_help_requested(shell)) {
|
||||
shell_help_print(shell, NULL, 0);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_BT_DISCONNECT, iface, NULL, 0)) {
|
||||
printk("Disconnect failed\n");
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Disconnect failed\n");
|
||||
} else {
|
||||
printk("Disconnected\n");
|
||||
shell_fprintf(shell, SHELL_NORMAL,
|
||||
"Disconnected\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int shell_cmd_advertise(int argc, char *argv[])
|
||||
static int shell_cmd_advertise(const struct shell *shell,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
struct net_if *iface = net_if_get_default();
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
if (argc < 2 || shell_help_requested(shell)) {
|
||||
shell_help_print(shell, NULL, 0);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (net_mgmt(NET_REQUEST_BT_ADVERTISE, iface, argv[1],
|
||||
strlen(argv[1]))) {
|
||||
printk("Advertise failed\n");
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Advertise failed\n");
|
||||
} else {
|
||||
printk("Advertise in progress\n");
|
||||
shell_fprintf(shell, SHELL_NORMAL,
|
||||
"Advertise in progress\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct shell_cmd bt_commands[] = {
|
||||
{ "advertise", shell_cmd_advertise, "on/off" },
|
||||
{ "connect", shell_cmd_connect,
|
||||
"<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>" },
|
||||
{ "scan", shell_cmd_scan, "<on/off/active/passive>" },
|
||||
{ "disconnect", shell_cmd_disconnect, "" },
|
||||
{ NULL, NULL, NULL },
|
||||
SHELL_CREATE_STATIC_SUBCMD_SET(bt_commands)
|
||||
{
|
||||
SHELL_CMD(advertise, NULL,
|
||||
"on/off",
|
||||
shell_cmd_advertise),
|
||||
SHELL_CMD(connect, NULL,
|
||||
"<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>",
|
||||
shell_cmd_connect),
|
||||
SHELL_CMD(scan, NULL,
|
||||
"<on/off/active/passive>",
|
||||
shell_cmd_scan),
|
||||
SHELL_CMD(disconnect, NULL,
|
||||
"",
|
||||
shell_cmd_disconnect),
|
||||
SHELL_SUBCMD_SET_END
|
||||
};
|
||||
|
||||
SHELL_REGISTER(BT_SHELL_MODULE, bt_commands);
|
||||
SHELL_CMD_REGISTER(net_bt, &bt_commands, "Net Bluetooth commands", NULL);
|
||||
|
||||
void net_bt_shell_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user