Implement BTLE Network Management interface API
Subsystems (2)
cover Implement BTLE Network Management interface API
Hi,
This patch set implements kernel support for RFC v3 of the Management Interface Network API. The current implementation reuses existing Bluetooth 6LowPAN functionality except for the debugfs interface parts that are replace by the Management API.
The debugfs implementation for enabling and disabling incoming connection support is still used, here it is anticipated that it will be replaced by device whitelisting using the Add Device command in the future.
Please review,
Patrik
Patrik Flykt (5):
bluetooth: Merge Bluetooth 6lowpan functionality to bluetooth module
bluetooth: Implement Get Networks Management API command
l2cap: Pass hci_dev to l2cap_chan_connect()
bluetooth: Implement Add Network Management API command
bluetooth: Implement Remove Network Management API command
include/net/bluetooth/l2cap.h | 4 +- include/net/bluetooth/mgmt.h | 40 ++++ net/bluetooth/6lowpan.c | 495 ++++++++++++++++++++++++++++-------------- net/bluetooth/Kconfig | 2 +- net/bluetooth/Makefile | 4 +- net/bluetooth/af_bluetooth.c | 11 + net/bluetooth/l2cap_core.c | 6 +- net/bluetooth/l2cap_sock.c | 5 +- net/bluetooth/mgmt.c | 9 + 9 files changed, 397 insertions(+), 179 deletions(-)
Signature · 1 line
2.1.4
RFC 1/5 bluetooth: Merge Bluetooth 6lowpan functionality to bluetooth module
The bluetooth_6lowpan.ko module functionality is compiled into the bluetooth module and a new header file 6lowpan.h is created. Kconfig and Makefile are updated accordingly. 6lowpan init and exit functions are called from the bluetooth module.
--- net/bluetooth/6lowpan.c | 12 ++---------- net/bluetooth/Kconfig | 2 +- net/bluetooth/Makefile | 4 +--- net/bluetooth/af_bluetooth.c | 11 +++++++++++ 4 files changed, 15 insertions(+), 14 deletions(-)
net/bluetooth/6lowpan.c +2 -10
@@ -1387,7 +1387,7 @@ static struct notifier_block bt_6lowpan_dev_notifier = { .notifier_call = device_event, }; -static int __init bt_6lowpan_init (void ) +int bt_6lowpan_init (void ) { lowpan_enable_debugfs = debugfs_create_file("6lowpan_enable", 0644, bt_debugfs, NULL,
@@ -1399,7 +1399,7 @@ static int __init bt_6lowpan_init(void)return register_netdevice_notifier (&bt_6lowpan_dev_notifier); } -static void __exit bt_6lowpan_exit(void) +void bt_6lowpan_exit (void ) {debugfs_remove (lowpan_enable_debugfs);debugfs_remove (lowpan_control_debugfs);
@@ -1413,11 +1413,3 @@ static void __exit bt_6lowpan_exit(void)unregister_netdevice_notifier (&bt_6lowpan_dev_notifier); } - -module_init (bt_6lowpan_init); -module_exit (bt_6lowpan_exit); - -MODULE_AUTHOR ("Jukka Rissanen <[email protected]>" ); -MODULE_DESCRIPTION ("Bluetooth 6LoWPAN" ); -MODULE_VERSION (VERSION ); -MODULE_LICENSE ("GPL" );
net/bluetooth/Kconfig +1 -1
@@ -64,7 +64,7 @@ config BT_LE default y config BT_6LOWPAN - tristate "Bluetooth 6LoWPAN support" + bool "Bluetooth 6LoWPAN support" depends on BT_LE && 6LOWPAN help IPv6 compression over Bluetooth Low Energy.
net/bluetooth/Makefile +1 -3
@@ -7,9 +7,6 @@ obj-$(CONFIG_BT_RFCOMM) += rfcomm/ obj-$(CONFIG_BT_BNEP) += bnep/ obj-$(CONFIG_BT_CMTP) += cmtp/ obj-$(CONFIG_BT_HIDP) += hidp/ -obj-$(CONFIG_BT_6LOWPAN) += bluetooth_6lowpan.o - -bluetooth_6lowpan-y := 6lowpan.o bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o lib.o \
@@ -18,6 +15,7 @@ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ bluetooth-$(CONFIG_BT_BREDR) += sco.o bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o bluetooth-$(CONFIG_BT_LEDS) += leds.o +bluetooth-$(CONFIG_BT_6LOWPAN) += 6lowpan.o bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o
net/bluetooth/af_bluetooth.c +11 -0
@@ -29,6 +29,7 @@#include <asm/ioctls.h> #include <net/bluetooth/bluetooth.h> +#include <net/bluetooth/6lowpan.h> #include <linux/proc_fs.h> #include "selftest.h"
@@ -747,8 +748,16 @@ static int __init bt_init(void) goto sock_err; } + err =bt_6lowpan_init (); +if (err <0 ) { +sco_exit (); +l2cap_exit (); + goto sock_err; + } + err =mgmt_init ();if (err <0 ) { +bt_6lowpan_exit ();sco_exit ();l2cap_exit (); goto sock_err;
@@ -770,6 +779,8 @@ static void __exit bt_exit(void) {mgmt_exit (); +bt_6lowpan_exit (); +sco_exit ();l2cap_exit ();
Signature · 1 line
2.1.4
Re: [RFC 1/5] bluetooth: Merge Bluetooth 6lowpan functionality to bluetooth module
Hi,
tried that patch out and it fails:
net/bluetooth/af_bluetooth.c:32:35: fatal error:net/bluetooth/6lowpan.h: No such file or directory #include <net/bluetooth/6lowpan.h>
There is some missing file. :-)
Actually while review I tried to find the prototypes for init/exit functionality. So this file is missing somehow but I think it should include:
#ifdef CONFIG_BT_6LOWPAN
... prototypes ...
#else
static inline empty files of prototypes
#endif
- Alex
Re: [RFC 1/5] bluetooth: Merge Bluetooth 6lowpan functionality to bluetooth module
Quoted 9 lines · Alexander Aring
Hi,
tried that patch out and it fails:
net/bluetooth/af_bluetooth.c:32:35: fatal error:net/bluetooth/6lowpan.h: No such file or directory #include <net/bluetooth/6lowpan.h>There is some missing file. :-)
Quoted 7 lines
Actually while review I tried to find the prototypes for init/exit functionality. So this file is missing somehow but I think it should include:
#ifdef
CONFIG_BT_6LOWPAN
... prototypes ...
#else
static inline empty files of prototypes
s/files/functions/
Also if the above is true to put the prototypes there, why putting it into a "global" header file. Use some local header #include "6lowpan.h" or something else. :-)
Maybe I oversight something here and there are good arguments to put it into a global header.
- Alex
RFC 2/5 bluetooth: Implement Get Networks Management API command
In reply to Patrik FlyktImplement MGMT_OP_GET_NETWORKS command by replying with the addresses and address types of all 6LowPAN peers. If none are found, return peer count and interface as zero.
Remove the debugfs implementation for achieving the same thing.
The MGMT_OP_GET_NETWORKS command is defined as:
Command Code: 0x0042
Controller Index: <controller id>
Command Parameters:
Return Parameters: Connection_Count (2 Octets)
Network1 {
Address (6 Octets) Address_Type (1 Octet) Interface Index (4 Octets)
}
Network2 { }
...
This command is used to retrieve a list of BTLE network connections. A pre-requisite is that LE is already enabled, otherwise this command will return a "rejected" response.
Possible values for the Address_Type parameter:
0 Reserved
1 LE Public
2 LE Random
For devices using resolvable random addresses with a known identity resolving key, the Address and Address_Type will contain the identity information.
This command can only be used when the controller is powered.
This command generates a Command Complete event on success or a Command Status event on failure.
Possible errors: Invalid Parameters
Not Powered
Invalid Index
--- include/net/bluetooth/mgmt.h | 10 ++++ net/bluetooth/6lowpan.c | 110 +++++++++++++++++++++++++++++++++---------- net/bluetooth/mgmt.c | 3 ++ 3 files changed, 98 insertions(+), 25 deletions(-)
include/net/bluetooth/mgmt.h +10 -0
@@ -586,6 +586,16 @@ struct mgmt_rp_get_adv_size_info {#define MGMT_OP_START_LIMITED_DISCOVERY 0x0041 +#define MGMT_OP_GET_NETWORKS 0x0042 +#define MGMT_GET_NETWORKS_SIZE 0 +struct mgmt_rp_get_networks { +__u16 count; +} __packed;/* followed by zero or more struct mgmt_rp_network */ +struct mgmt_rp_network { +struct mgmt_addr_info dst; +int ifindex; +} __packed; +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;
net/bluetooth/6lowpan.c +85 -25
129 lines not on this page · raw message
net/bluetooth/mgmt.c +3 -0
@@ -31,6 +31,7 @@#include <net/bluetooth/hci_core.h> #include <net/bluetooth/hci_sock.h> #include <net/bluetooth/l2cap.h> +#include <net/bluetooth/6lowpan.h> #include <net/bluetooth/mgmt.h> #include "hci_request.h"
@@ -104,6 +105,7 @@ static const u16 mgmt_commands[] = {MGMT_OP_REMOVE_ADVERTISING ,MGMT_OP_GET_ADV_SIZE_INFO ,MGMT_OP_START_LIMITED_DISCOVERY , + MGMT_OP_GET_NETWORKS, }; static const u16 mgmt_events[] = {
@@ -6336,6 +6338,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { remove_advertising, MGMT_REMOVE_ADVERTISING_SIZE }, { get_adv_size_info, MGMT_GET_ADV_SIZE_INFO_SIZE }, { start_limited_discovery, MGMT_START_DISCOVERY_SIZE }, + { bt_6lowpan_get_networks, MGMT_GET_NETWORKS_SIZE }, };void mgmt_index_added (struct hci_dev *hdev)
Signature · 1 line
2.1.4
Re: [RFC 2/5] bluetooth: Implement Get Networks Management API command
net/bluetooth/mgmt.c line 34
Quoted 7 lines · Patrik Flykt
net/bluetooth/mgmt.c +1
-0@@ -31,6 +31,7 @@#include <net/bluetooth/hci_core.h> #include <net/bluetooth/hci_sock.h> #include <net/bluetooth/l2cap.h> +#include <net/bluetooth/6lowpan.h>
And of course the header file gets left behind. I'll fix...
Cheers,
Patrik
RFC 3/5 l2cap: Pass hci_dev to l2cap_chan_connect()
In reply to Patrik FlyktSince the Bluetooth Management Interface already associates commands with a hci_dev, pass the hci_dev when calling l2cap_chan_connect(). This indicates which specific hci_dev to use for the l2cap connection and will be useful when connecting or disconnecting Bluetooth IPSP.
Modify the existing code to do a hci_dev lookup before calling connect.
--- include/net/bluetooth/l2cap.h | 4 ++-- net/bluetooth/6lowpan.c | 4 +++- net/bluetooth/l2cap_core.c | 6 ++---- net/bluetooth/l2cap_sock.c | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-)
include/net/bluetooth/l2cap.h +2 -2
@@ -926,8 +926,8 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid);struct l2cap_chan *l2cap_chan_create (void );void l2cap_chan_close (struct l2cap_chan *chan,int reason); -int l2cap_chan_connect (struct l2cap_chan *chan,__le16 psm,u16 cid, -bdaddr_t *dst,u8 dst_type); +int l2cap_chan_connect (struct l2cap_chan *chan,struct hci_dev *hdev, +__le16 psm,u16 cid,bdaddr_t *dst,u8 dst_type);int l2cap_chan_send (struct l2cap_chan *chan,struct msghdr *msg,size_t len);void l2cap_chan_busy (struct l2cap_chan *chan,int busy);int l2cap_chan_check_security (struct l2cap_chan *chan,bool initiator);
net/bluetooth/6lowpan.c +3 -1
@@ -1113,6 +1113,7 @@ static inline __u8 bdaddr_type(__u8 type)static int bt_6lowpan_connect (bdaddr_t *addr,u8 dst_type) { +struct hci_dev *hdev;struct l2cap_chan *chan;int err;
@@ -1122,7 +1123,8 @@ static int bt_6lowpan_connect(bdaddr_t *addr, u8 dst_type) chan->ops = &bt_6lowpan_chan_ops; - err =l2cap_chan_connect (chan,cpu_to_le16 (L2CAP_PSM_IPSP ),0 , + hdev =hci_get_route (addr,NULL ); + err =l2cap_chan_connect (chan, hdev,cpu_to_le16 (L2CAP_PSM_IPSP ),0 , addr, dst_type);BT_DBG ("chan %p err %d" , chan, err);
net/bluetooth/l2cap_core.c +2 -4
@@ -7041,18 +7041,16 @@ static bool is_valid_psm(u16 psm, u8 dst_type) {return ((psm &0x0101 ) ==0x0001 ); } -int l2cap_chan_connect (struct l2cap_chan *chan,__le16 psm,u16 cid, -bdaddr_t *dst,u8 dst_type) +int l2cap_chan_connect (struct l2cap_chan *chan,struct hci_dev *hdev, +__le16 psm,u16 cid,bdaddr_t *dst,u8 dst_type) {struct l2cap_conn *conn;struct hci_conn *hcon; -struct hci_dev *hdev;int err;BT_DBG ("%pMR -> %pMR (type %u) psm 0x%2.2x" , &chan->src, dst, dst_type,__le16_to_cpu (psm)); - hdev =hci_get_route (dst, &chan->src);if (!hdev)return -EHOSTUNREACH ;
net/bluetooth/l2cap_sock.c +4 -1
@@ -176,6 +176,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan;struct sockaddr_l2 la; +struct hci_dev *hdev;int len, err =0 ;BT_DBG ("sk %p" , sk);
@@ -233,7 +234,9 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,if (chan->psm &&bdaddr_type_is_le (chan->src_type)) chan->mode =L2CAP_MODE_LE_FLOWCTL ; - err =l2cap_chan_connect (chan, la.l2_psm,__le16_to_cpu (la.l2_cid), + hdev =hci_get_route (&la.l2_bdaddr, &chan->src); + err =l2cap_chan_connect (chan, hdev, la.l2_psm, +__le16_to_cpu (la.l2_cid), &la.l2_bdaddr, la.l2_bdaddr_type);if (err)return err;
Signature · 1 line
2.1.4
Marcel Holtmann
maintainerRe: [RFC 3/5] l2cap: Pass hci_dev to l2cap_chan_connect()
Hi Patrik,
Quoted 22 lines
Since the Bluetooth Management Interface already associates commands with a
hci_dev, pass thehci_devwhen callingl2cap_chan_connect(). This indicates which specifichci_devto use for the l2cap connection and will be useful when connecting or disconnecting Bluetooth IPSP.Modify the existing code to do a
hci_devlookup before calling connect.Signed-off-by Patrik Flykt <[email protected]>---
include/net/bluetooth/l2cap.h | 4 ++-- net/bluetooth/6lowpan.c | 4 +++- net/bluetooth/l2cap_core.c | 6 ++---- net/bluetooth/l2cap_sock.c | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-)include/net/bluetooth/l2cap.h +0
-0
include/net/bluetooth/l2cap.h int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); · line 930
Quoted 7 lines
include/net/bluetooth/l2cap.h +2
-2@@ -926,8 +926,8 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid);struct l2cap_chan *l2cap_chan_create (void );void l2cap_chan_close (struct l2cap_chan *chan,int reason); -int l2cap_chan_connect (struct l2cap_chan *chan,__le16 psm,u16 cid, -bdaddr_t *dst,u8 dst_type); +int l2cap_chan_connect (struct l2cap_chan *chan,struct hci_dev *hdev, +__le16 psm,u16 cid,bdaddr_t *dst,u8 dst_type);
actually lets not do that. I am pretty much against hacking just more parameters into this function. Do that in the l2cap_chan abstraction. It already knows which hci_dev it needs to pick.
Regards
Marcel
RFC 4/5 bluetooth: Implement Add Network Management API command
In reply to Patrik FlyktQueue Add Network Management API command and initiate a L2CAP connect to the destination. Reply to the command in the l2cap_ops ready callback when the channel is successfully created and inidcate failure in both l2cap_ops close and state callbacks when an error is indicated.
On success add the remote peer to the internal data structures and create the network interface as before. Remove the debugfs implementation doing the same thing.
The MGMT_OP_ADD_NETWORK command is defined as:
Command Code: 0x0043
Controller Index: <controller id>
Command Parameters: Address (6 Octets) Address_Type (1 Octet)
Return Parameters: Address (6 Octets)
Address_Type (1 Octet) Interface Index (4 Octets)
This command is used to connect to establish a network connection to a remote BTLE node. A pre-requisite is that LE is already enabled, otherwise this command will return a "rejected" response.
Possible values for the Address_Type parameter:
0 Reserved
1 LE Public
2 LE Random
This command generates a Command Complete event on success or failure.
Possible errors: Busy
Refused
Invalid Parameters
Not Powered
Invalid Index
Already Connected
The MGMT_EV_NETWORK_ADDED event is defined as:
Event Code: 0x0025
Controller Index: <controller id>
Event Parameters: Address (6 Octets) Address_Type (1 Octet) Interface Index (4 Octets)
This event indicates that a network connection to a remote BTLE node has been established successfully.
Possible values for the Address_Type parameter:
1 LE Public
2 LE Random
For devices using resolvable random addresses with a known identity resolving key, the Address and Address_Type will contain the identity information.
--- include/net/bluetooth/mgmt.h | 16 ++++ net/bluetooth/6lowpan.c | 205 ++++++++++++++++++++++++++++++++----------- net/bluetooth/mgmt.c | 3 + 3 files changed, 172 insertions(+), 52 deletions(-)
include/net/bluetooth/mgmt.h +16 -0
@@ -596,6 +596,16 @@ struct mgmt_rp_network {int ifindex; } __packed; +#define MGMT_OP_ADD_NETWORK 0x0043 +#define MGMT_ADD_NETWORK_SIZE 7 +struct mgmt_cp_add_network { +struct mgmt_addr_info dst; +} __packed; +struct mgmt_rp_add_network { +struct mgmt_addr_info dst; +int ifindex; +} __packed; +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;
@@ -809,3 +819,9 @@ struct mgmt_ev_advertising_added {struct mgmt_ev_advertising_removed {__u8 instance; } __packed; + +#define MGMT_EV_NETWORK_ADDED 0x0025 +struct mgmt_ev_network_added { +struct mgmt_addr_info dst; +int ifindex; +} __packed;
net/bluetooth/6lowpan.c +153 -52
258 lines not on this page · raw message
net/bluetooth/mgmt.c +3 -0
@@ -106,6 +106,7 @@ static const u16 mgmt_commands[] = {MGMT_OP_GET_ADV_SIZE_INFO ,MGMT_OP_START_LIMITED_DISCOVERY ,MGMT_OP_GET_NETWORKS , + MGMT_OP_ADD_NETWORK, }; static const u16 mgmt_events[] = {
@@ -143,6 +144,7 @@ static const u16 mgmt_events[] = {MGMT_EV_LOCAL_OOB_DATA_UPDATED ,MGMT_EV_ADVERTISING_ADDED ,MGMT_EV_ADVERTISING_REMOVED , + MGMT_EV_NETWORK_ADDED, }; static const u16 mgmt_untrusted_commands[] = {
@@ -6339,6 +6341,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { get_adv_size_info, MGMT_GET_ADV_SIZE_INFO_SIZE }, { start_limited_discovery, MGMT_START_DISCOVERY_SIZE }, { bt_6lowpan_get_networks, MGMT_GET_NETWORKS_SIZE }, + { bt_6lowpan_add_network, MGMT_ADD_NETWORK_SIZE }, };void mgmt_index_added (struct hci_dev *hdev)
Signature · 1 line
2.1.4
RFC 5/5 bluetooth: Implement Remove Network Management API command
In reply to Patrik FlyktQueue Remove Network Management API command and disconnect the L2CAP channel. Once the channel has been removed, reply to the command in l2cap_ops close callback. On error reply with a failure in the l2cap_ops status callback.
Remove the remaining part of the debugfs code handling the control file.
The MGMT_OP_REMOVE_NETWORK command is defined as:
Command Code: 0x0044
Controller Index: <controller id>
Command Parameters: Address (6 Octets) Address_Type (1 Octet)
Return Parameters: Address (6 Octets)
Address_Type (1 Octet)
This command is used to disconnect a network connection from a remote BTLE node. A pre-requisite is that LE is already enabled, otherwise this command will return a "rejected" response.
Possible values for the Address_Type parameter:
0 Reserved
1 LE Public
2 LE Random
This command generates a Command Complete event on success or failure.
Possible errors: Busy
Not Connected
Invalid Parameters
Not Powered
Invalid Index
The MGMT_EV_NETWORK_REMOVED event is defined as:
Event Code: 0x0026
Controller Index: <controller id>
Event Parameters: Address (6 Octets) Address_Type (1 Octet)
This event indicates that the BTLE network connection to a remote node has been lost.
Possible values for the Address_Type parameter:
1 LE Public
2 LE Random
For devices using resolvable random addresses with a known identity resolving key, the Address and Address_Type will contain the identity information.
--- include/net/bluetooth/mgmt.h | 14 ++++ net/bluetooth/6lowpan.c | 174 ++++++++++++++++++++++--------------------- net/bluetooth/mgmt.c | 3 + 3 files changed, 106 insertions(+), 85 deletions(-)
include/net/bluetooth/mgmt.h +14 -0
@@ -606,6 +606,15 @@ struct mgmt_rp_add_network {int ifindex; } __packed; +#define MGMT_OP_REMOVE_NETWORK 0x0044 +#define MGMT_REMOVE_NETWORK_SIZE 7 +struct mgmt_cp_remove_network { +struct mgmt_addr_info dst; +} __packed; +struct mgmt_rp_remove_network { +struct mgmt_addr_info dst; +} __packed; +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;
@@ -825,3 +834,8 @@ struct mgmt_ev_network_added {struct mgmt_addr_info dst;int ifindex; } __packed; + +#define MGMT_EV_NETWORK_REMOVED 0x0026 +struct mgmt_ev_network_removed { +struct mgmt_addr_info dst; +} __packed;
net/bluetooth/6lowpan.c +89 -85
235 lines not on this page · raw message
net/bluetooth/mgmt.c +3 -0
@@ -107,6 +107,7 @@ static const u16 mgmt_commands[] = {MGMT_OP_START_LIMITED_DISCOVERY ,MGMT_OP_GET_NETWORKS ,MGMT_OP_ADD_NETWORK , + MGMT_OP_REMOVE_NETWORK, }; static const u16 mgmt_events[] = {
@@ -145,6 +146,7 @@ static const u16 mgmt_events[] = {MGMT_EV_ADVERTISING_ADDED ,MGMT_EV_ADVERTISING_REMOVED ,MGMT_EV_NETWORK_ADDED , + MGMT_EV_NETWORK_REMOVED, }; static const u16 mgmt_untrusted_commands[] = {
@@ -6342,6 +6344,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { start_limited_discovery, MGMT_START_DISCOVERY_SIZE }, { bt_6lowpan_get_networks, MGMT_GET_NETWORKS_SIZE }, { bt_6lowpan_add_network, MGMT_ADD_NETWORK_SIZE }, + { bt_6lowpan_remove_network, MGMT_REMOVE_NETWORK_SIZE }, };void mgmt_index_added (struct hci_dev *hdev)
Signature · 1 line
2.1.4
Marcel Holtmann
maintainerRe: [RFC 5/5] bluetooth: Implement Remove Network Management API command
Hi Patrik,
Quoted 304 lines
Queue Remove Network Management API command and disconnect the L2CAP channel. Once the channel has been removed, reply to the command in
l2cap_opsclose callback. On error reply with a failure in thel2cap_opsstatus callback.Remove the remaining part of the debugfs code handling the control file.
The
MGMT_OP_REMOVE_NETWORKcommand is defined as:Command Code: 0x0044 Controller Index: <controller id> Command Parameters: Address (6 Octets)
Address_Type(1 Octet)
Return Parameters: Address (6 Octets)
Address_Type(1 Octet)This command is used to disconnect a network connection from a remote BTLE node. A pre-requisite is that LE is already enabled, otherwise this command will return a "rejected" response.
Possible values for the
Address_Typeparameter:
0 Reserved
1 LE Public
2 LE RandomThis command generates a Command Complete event on success or failure.
Possible errors: Busy
Not Connected
Invalid Parameters
Not Powered
Invalid IndexThe
MGMT_EV_NETWORK_REMOVEDevent is defined as:Event Code: 0x0026 Controller Index: <controller id> Event Parameters: Address (6 Octets)
Address_Type(1 Octet)This event indicates that the BTLE network connection to a remote node has been lost.
Possible values for the
Address_Typeparameter:
1 LE Public
2 LE RandomFor devices using resolvable random addresses with a known identity resolving key, the Address and
Address_Typewill contain the identity information.
---include/net/bluetooth/mgmt.h | 14 ++++ net/bluetooth/6lowpan.c | 174 ++++++++++++++++++++++--------------------- net/bluetooth/mgmt.c | 3 + 3 files changed, 106 insertions(+), 85 deletions(-)include/net/bluetooth/mgmt.h +14
-0@@ -606,6 +606,15 @@ struct mgmt_rp_add_network {int ifindex; } __packed; +#define MGMT_OP_REMOVE_NETWORK 0x0044 +#define MGMT_REMOVE_NETWORK_SIZE 7 +struct mgmt_cp_remove_network { +struct mgmt_addr_info dst; +} __packed; +struct mgmt_rp_remove_network { +struct mgmt_addr_info dst; +} __packed; +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;@@ -825,3 +834,8 @@ struct mgmt_ev_network_added {struct mgmt_addr_info dst;int ifindex; } __packed; + +#define MGMT_EV_NETWORK_REMOVED 0x0026 +struct mgmt_ev_network_removed { +struct mgmt_addr_info dst; +} __packed;net/bluetooth/6lowpan.c +89
-70@@ -33,7 +33,6 @@#define VERSION "0.1"static struct dentry *lowpan_enable_debugfs; -static struct dentry *lowpan_control_debugfs;#define IFACE_NAME_TEMPLATE "bt%d"@@ -929,6 +928,46 @@ static void cmd_add_network_complete(struct l2cap_chan *chan, int status,mgmt_pending_remove (cmd); } +static void cmd_remove_network_complete (struct l2cap_chan *chan,int status) +{ +struct hci_dev *hdev; +struct mgmt_pending_cmd *cmd; + + hdev =hci_get_route (NULL , &chan->src); + +if (!hdev) { +BT_DBG ("No matching hci_dev for l2cap_chan %p" , chan); +return ; + } + + cmd =mgmt_pending_find (HCI_CHANNEL_CONTROL ,MGMT_OP_REMOVE_NETWORK , + hdev); +if (cmd) { +struct mgmt_cp_remove_network *cp = cmd->param; +struct mgmt_rp_remove_network rp; + +bacpy (&rp.dst.bdaddr, &cp->dst.bdaddr); + rp.dst.type = cp->dst.type; + +mgmt_cmd_complete (cmd->sk, cmd->index, cmd->opcode, + status, &rp,sizeof (rp)); + } + +if (status ==MGMT_STATUS_SUCCESS && chan->state ==BT_DISCONN ) { +struct mgmt_ev_network_removed ep; + +bacpy (&ep.dst.bdaddr, &chan->dst); + ep.dst.type = chan->dst_type; + +mgmt_send_event (MGMT_EV_NETWORK_REMOVED , hdev, +HCI_CHANNEL_CONTROL , &ep,sizeof (ep), +HCI_SOCK_TRUSTED , cmd? cmd->sk:NULL ); + } + +if (cmd) +mgmt_pending_remove (cmd); +} +static inline void chan_ready_cb (struct l2cap_chan *chan) {struct lowpan_dev *dev;@@ -1000,6 +1039,7 @@ static void chan_close_cb(struct l2cap_chan *chan) }cmd_add_network_complete (chan,MGMT_STATUS_CONNECT_FAILED ,0 ); +cmd_remove_network_complete (chan,MGMT_STATUS_SUCCESS );spin_lock (&devices_lock);@@ -1045,6 +1085,7 @@ static void chan_state_change_cb(struct l2cap_chan *chan, int state, int err)if (err <0 ) {cmd_add_network_complete (chan,MGMT_STATUS_CONNECT_FAILED ,0 ); +cmd_remove_network_complete (chan,MGMT_STATUS_CONNECT_FAILED ); } }@@ -1270,21 +1311,60 @@ unlock:return err; } -static int bt_6lowpan_disconnect (struct l2cap_conn *conn,u8 dst_type) +int bt_6lowpan_remove_network (struct sock *sk,struct hci_dev *hdev, +void *data,u16 data_len) { +struct mgmt_cp_remove_network *cp = data; +int err =0 ;struct lowpan_peer *peer; +struct mgmt_pending_cmd *cmd; -BT_DBG ("conn %p dst type %d" , conn, dst_type); +BT_DBG ("remove network hdev %p data %p data len %d" , + hdev, data, data_len); - peer =lookup_peer (conn); -if (!peer) -return -ENOENT ; +if (!lmp_le_capable (hdev)) { + err =mgmt_cmd_complete (sk, hdev->id,MGMT_OP_REMOVE_NETWORK , +MGMT_STATUS_NOT_SUPPORTED , cp, +sizeof (*cp)); + goto failed; + } -BT_DBG ("peer %p chan %p" , peer, peer->chan); +if (!bdaddr_type_is_le (cp->dst.type)) { + err =mgmt_cmd_complete (sk, hdev->id,MGMT_OP_REMOVE_NETWORK , +MGMT_STATUS_INVALID_PARAMS , cp, +sizeof (*cp)); + goto failed; + } -l2cap_chan_close (peer->chan,ENOENT ); +hci_dev_lock (hdev); -return 0 ; +if (mgmt_pending_find (HCI_CHANNEL_CONTROL ,MGMT_OP_REMOVE_NETWORK , + hdev)) { + err =mgmt_cmd_status (sk, hdev->id,MGMT_OP_REMOVE_NETWORK , +MGMT_STATUS_BUSY ); + goto unlock; + } + + peer =lookup_bdaddr (hdev, &cp->dst.bdaddr, cp->dst.type); +if (!peer) { + err =mgmt_cmd_complete (sk, hdev->id,MGMT_OP_REMOVE_NETWORK , +MGMT_STATUS_FAILED , + cp,sizeof (*cp)); + goto unlock; + } + + cmd =mgmt_pending_add (sk,MGMT_OP_REMOVE_NETWORK , hdev, + data, data_len); +if (!cmd) + err = -ENOMEM ; + +l2cap_chan_close (peer->chan,0 ); + +unlock: +hci_dev_unlock (hdev); + +failed: +return err; }static struct l2cap_chan *bt_6lowpan_listen (void )@@ -1318,40 +1398,6 @@ static struct l2cap_chan *bt_6lowpan_listen(void)return chan; } -static int get_l2cap_conn (char *buf,bdaddr_t *addr,u8 *addr_type, -struct l2cap_conn **conn) -{ -struct hci_conn *hcon; -struct hci_dev *hdev; -bdaddr_t *src =BDADDR_ANY ; -int n; - - n =sscanf (buf,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu" , - &addr->b[5 ], &addr->b[4 ], &addr->b[3 ], - &addr->b[2 ], &addr->b[1 ], &addr->b[0 ], - addr_type); - -if (n <7 ) -return -EINVAL ; - - hdev =hci_get_route (addr, src); -if (!hdev) -return -ENOENT ; - -hci_dev_lock (hdev); - hcon =hci_conn_hash_lookup_le (hdev, addr, *addr_type); -hci_dev_unlock (hdev); - -if (!hcon) -return -ENOENT ; - - *conn = (struct l2cap_conn *)hcon->l2cap_data; - -BT_DBG ("conn %p dst %pMR type %d" , *conn, &hcon->dst, hcon->dst_type); - -return 0 ; -} -static void disconnect_all_peers (void ) {struct lowpan_dev *entry;@@ -1445,44 +1491,6 @@ static int lowpan_enable_get(void *data, u64 *val)DEFINE_SIMPLE_ATTRIBUTE (lowpan_enable_fops, lowpan_enable_get, lowpan_enable_set,"%llu\n" ); -static ssize_t lowpan_control_write (struct file *fp, -const char __user *user_buffer, -size_t count, -loff_t *position) -{ -char buf[32 ]; -size_t buf_size =min (count,sizeof (buf) -1 ); -int ret; -bdaddr_t addr; -u8 addr_type; -struct l2cap_conn *conn =NULL ; - -if (copy_from_user (buf, user_buffer, buf_size)) -return -EFAULT ; - - buf[buf_size] ='\0' ; - -if (memcmp (buf,"disconnect " ,11 ) ==0 ) { - ret =get_l2cap_conn (&buf[11 ], &addr, &addr_type, &conn); -if (ret <0 ) -return ret; - - ret =bt_6lowpan_disconnect (conn, addr_type); -if (ret <0 ) -return ret; - -return count;
net/bluetooth/6lowpan.c static int lowpan_enable_get(void *data, u64 *val) · line 1484
Quoted 10 lines
net/bluetooth/6lowpan.c +0
-10- } - -return count; -} - -static const struct file_operations lowpan_control_fops = { - .write = lowpan_control_write, - .llseek = seq_lseek, - .release = single_release, -};
removing the debugfs stuff should be a separate cleanup at the end of the series. I prefer we do not intermix this.
Regards
Marcel