* [RFC v4 3/6] Bluetooth: Initial skeleton code for BT 6LoWPAN
From: Jukka Rissanen @ 2013-11-13 10:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384337495-9043-1-git-send-email-jukka.rissanen@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
---
include/net/bluetooth/l2cap.h | 1 +
net/bluetooth/6lowpan.c | 544 ++++++++++++++++++++++++++++++++++++++++++
net/bluetooth/6lowpan.h | 26 ++
net/bluetooth/Makefile | 2 +-
net/bluetooth/l2cap_core.c | 22 +-
5 files changed, 593 insertions(+), 2 deletions(-)
create mode 100644 net/bluetooth/6lowpan.c
create mode 100644 net/bluetooth/6lowpan.h
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 5132990..c28ac0d 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -133,6 +133,7 @@ struct l2cap_conninfo {
#define L2CAP_FC_L2CAP 0x02
#define L2CAP_FC_CONNLESS 0x04
#define L2CAP_FC_A2MP 0x08
+#define L2CAP_FC_6LOWPAN 0x3e
/* L2CAP Control Field bit masks */
#define L2CAP_CTRL_SAR 0xC000
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
new file mode 100644
index 0000000..85754e2
--- /dev/null
+++ b/net/bluetooth/6lowpan.c
@@ -0,0 +1,544 @@
+/*
+ Copyright (c) 2013 Intel Corp.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 and
+ only version 2 as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+*/
+
+#include <linux/version.h>
+#include <linux/bitops.h>
+#include <linux/if_arp.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+
+#include <net/ipv6.h>
+#include <net/ip6_route.h>
+#include <net/addrconf.h>
+
+#include <net/af_ieee802154.h>
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/l2cap.h>
+
+#include "../ieee802154/6lowpan.h" /* for the compression defines */
+
+#define IFACE_NAME_TEMPLATE "bt%d"
+#define EUI64_ADDR_LEN 8
+
+struct skb_cb {
+ struct in6_addr addr;
+ struct l2cap_conn *conn;
+};
+#define lowpan_cb(skb) ((struct skb_cb *)((skb)->cb))
+
+/*
+ * The devices list contains those devices that we are acting
+ * as a proxy. The BT 6LoWPAN device is a virtual device that
+ * connects to the Bluetooth LE device. The real connection to
+ * BT device is done via l2cap layer. There exists one
+ * virtual device / one BT 6LoWPAN network (=hciX device).
+ * The list contains struct lowpan_dev elements.
+ */
+static LIST_HEAD(bt_6lowpan_devices);
+static DEFINE_RWLOCK(devices_lock);
+
+struct lowpan_dev {
+ struct net_device *dev;
+ struct work_struct delete_netdev;
+ struct list_head list;
+};
+
+struct peer {
+ struct list_head list;
+ struct l2cap_conn *conn;
+
+ /* peer addresses in various formats */
+ unsigned char eui64_addr[EUI64_ADDR_LEN];
+ struct in6_addr peer_addr;
+};
+
+struct lowpan_info {
+ struct net_device *net;
+ struct list_head peers;
+ int peer_count;
+};
+
+static inline struct lowpan_info *lowpan_info(const struct net_device *dev)
+{
+ return netdev_priv(dev);
+}
+
+static inline void peer_add(struct lowpan_info *info, struct peer *peer)
+{
+ list_add(&peer->list, &info->peers);
+ info->peer_count++;
+}
+
+static inline void peer_del(struct lowpan_info *info, struct peer *peer)
+{
+ list_del(&peer->list);
+ info->peer_count--;
+ if (info->peer_count < 0) {
+ BT_ERR("peer count underflow");
+ info->peer_count = 0;
+ }
+}
+
+static inline struct peer *peer_lookup_ba(struct lowpan_info *info,
+ __u8 type, bdaddr_t *ba)
+{
+ struct peer *peer, *tmp;
+
+ BT_DBG("peers %d addr %pMR type %d", info->peer_count, ba, type);
+
+ list_for_each_entry_safe(peer, tmp, &info->peers, list) {
+ BT_DBG("addr %pMR type %d",
+ &peer->conn->hcon->dst, peer->conn->hcon->dst_type);
+
+ if (!bacmp(&peer->conn->hcon->dst, ba))
+ return peer;
+ }
+
+ return NULL;
+}
+
+static inline struct peer *peer_lookup_conn(struct lowpan_info *info,
+ struct l2cap_conn *conn)
+{
+ struct peer *peer, *tmp;
+
+ list_for_each_entry_safe(peer, tmp, &info->peers, list) {
+ if (peer->conn == conn)
+ return peer;
+ }
+
+ return NULL;
+}
+
+static struct peer *lookup_peer(struct l2cap_conn *conn,
+ struct lowpan_info **dev)
+{
+ struct lowpan_dev *entry, *tmp;
+ struct peer *peer = NULL;
+
+ write_lock(&devices_lock);
+
+ list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
+ struct lowpan_info *info = lowpan_info(entry->dev);
+
+ if (dev)
+ *dev = info;
+
+ peer = peer_lookup_conn(info, conn);
+ if (peer)
+ break;
+ }
+
+ write_unlock(&devices_lock);
+
+ return peer;
+}
+
+/* print data in line */
+static inline void raw_dump_inline(const char *caller, char *msg,
+ unsigned char *buf, int len)
+{
+ if (msg)
+ pr_debug("%s():%s: ", caller, msg);
+ print_hex_dump_debug("", DUMP_PREFIX_NONE,
+ 16, 1, buf, len, false);
+}
+
+/*
+ * print data in a table format:
+ *
+ * addr: xx xx xx xx xx xx
+ * addr: xx xx xx xx xx xx
+ * ...
+ */
+static inline void raw_dump_table(const char *caller, char *msg,
+ unsigned char *buf, int len)
+{
+ if (msg)
+ pr_debug("%s():%s:\n", caller, msg);
+ print_hex_dump_debug("\t", DUMP_PREFIX_OFFSET,
+ 16, 1, buf, len, false);
+}
+
+static int recv_pkt(struct sk_buff *skb, struct net_device *dev)
+{
+ kfree_skb(skb);
+ return NET_RX_DROP;
+}
+
+/* Packet from BT LE device */
+int bt_6lowpan_recv(struct l2cap_conn *conn, struct sk_buff *skb)
+{
+ struct lowpan_info *info = NULL;
+ struct peer *peer;
+ int err = -ENOENT;
+
+ peer = lookup_peer(conn, &info);
+ if (!peer)
+ return -ENOENT;
+
+ if (info && info->net) {
+ err = recv_pkt(skb, info->net, conn);
+ BT_DBG("recv pkt %d", err);
+ }
+
+ return err;
+}
+
+static void do_send(struct l2cap_conn *conn, struct sk_buff *skb)
+{
+ BT_DBG("conn %p, skb %p len %d priority %u", conn, skb, skb->len,
+ skb->priority);
+
+ return;
+}
+
+static int conn_send(struct l2cap_conn *conn,
+ void *msg, size_t len, u32 priority,
+ struct net_device *dev)
+{
+ struct sk_buff *skb = {0};
+
+ do_send(conn, skb);
+ return 0;
+}
+
+/* Packet to BT LE device */
+static int send_pkt(struct l2cap_conn *conn, const void *saddr,
+ const void *daddr, struct sk_buff *skb,
+ struct net_device *dev)
+{
+ raw_dump_table(__func__, "raw skb data dump before fragmentation",
+ skb->data, skb->len);
+
+ return conn_send(conn, skb->data, skb->len, 0, dev);
+}
+
+static int send_mcast_pkt(struct sk_buff *skb, struct net_device *dev)
+{
+ struct sk_buff *local_skb;
+ struct lowpan_dev *entry, *tmp;
+ int err = 0;
+
+ write_lock(&devices_lock);
+
+ list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
+ struct peer *pentry, *ptmp;
+ struct lowpan_info *info;
+
+ if (entry->dev != dev)
+ continue;
+
+ info = lowpan_info(entry->dev);
+
+ list_for_each_entry_safe(pentry, ptmp, &info->peers, list) {
+ local_skb = skb_clone(skb, GFP_ATOMIC);
+
+ err = send_pkt(pentry->conn, dev->dev_addr,
+ pentry->eui64_addr,
+ local_skb, dev);
+
+ kfree_skb(local_skb);
+ }
+ }
+
+ write_unlock(&devices_lock);
+
+ return err;
+}
+
+static netdev_tx_t xmit(struct sk_buff *skb, struct net_device *dev)
+{
+ int err = -ENOENT;
+ unsigned char *eui64_addr;
+ struct lowpan_info *info;
+ struct peer *peer;
+ bdaddr_t addr;
+ u8 addr_type;
+
+ if (ipv6_addr_is_multicast(&lowpan_cb(skb)->addr)) {
+ /*
+ * We need to send the packet to every device
+ * behind this interface.
+ */
+ err = send_mcast_pkt(skb, dev);
+ } else {
+ get_dest_bdaddr(&lowpan_cb(skb)->addr, &addr, &addr_type);
+ eui64_addr = lowpan_cb(skb)->addr.s6_addr + 8;
+ info = lowpan_info(dev);
+
+ write_lock(&devices_lock);
+ peer = peer_lookup_ba(info, addr_type, &addr);
+ write_unlock(&devices_lock);
+
+ BT_DBG("xmit from %s to %pMR (%pI6c), peer %p", dev->name,
+ &addr, &lowpan_cb(skb)->addr, peer);
+
+ if (peer && peer->conn)
+ err = send_pkt(peer->conn,
+ dev->dev_addr,
+ eui64_addr,
+ skb,
+ dev);
+ }
+ dev_kfree_skb(skb);
+
+ if (err)
+ BT_DBG("ERROR: xmit failed (%d)", err);
+
+ return (err < 0) ? NET_XMIT_DROP : err;
+}
+
+static const struct net_device_ops netdev_ops = {
+ .ndo_start_xmit = xmit,
+};
+
+static void netdev_setup(struct net_device *dev)
+{
+ dev->addr_len = EUI64_ADDR_LEN;
+ dev->type = ARPHRD_RAWIP;
+
+ dev->hard_header_len = 0;
+ dev->needed_tailroom = 0;
+ dev->mtu = IPV6_MIN_MTU;
+ dev->tx_queue_len = 0;
+ dev->flags = IFF_RUNNING | IFF_POINTOPOINT;
+ dev->watchdog_timeo = 0;
+
+ dev->netdev_ops = &netdev_ops;
+ dev->destructor = free_netdev;
+}
+
+static struct device_type bt_type = {
+ .name = "bluetooth",
+};
+
+static void set_addr(u8 *eui, u8 *addr, u8 addr_type)
+{
+ /* addr is the BT address in little-endian format */
+ eui[0] = addr[5];
+ eui[1] = addr[4];
+ eui[2] = addr[3];
+ eui[3] = 0xFF;
+ eui[4] = 0xFE;
+ eui[5] = addr[2];
+ eui[6] = addr[1];
+ eui[7] = addr[0];
+
+ eui[0] ^= 2;
+
+ /*
+ * Universal/local bit set, RFC 4291
+ */
+ if (addr_type == BDADDR_LE_PUBLIC)
+ eui[0] |= 1;
+ else
+ eui[0] &= ~1;
+}
+
+static void set_dev_addr(struct net_device *net, bdaddr_t *addr,
+ u8 addr_type)
+{
+ net->addr_assign_type = NET_ADDR_PERM;
+ set_addr(net->dev_addr, addr->b, addr_type);
+ net->dev_addr[0] ^= 2;
+}
+
+static void ifup(struct net_device *net)
+{
+ int err;
+
+ rtnl_lock();
+ err = dev_open(net);
+ if (err < 0)
+ BT_INFO("iface %s cannot be opened (%d)", net->name, err);
+ rtnl_unlock();
+}
+
+/*
+ * This gets called when BT LE 6LoWPAN device is connected. We then
+ * create network device that acts as a proxy between BT LE device
+ * and kernel network stack.
+ */
+int bt_6lowpan_add_conn(struct l2cap_conn *conn)
+{
+ struct lowpan_info *dev = NULL;
+ struct peer *peer = NULL;
+ struct net_device *net;
+ struct lowpan_dev *entry;
+ int err = 0;
+
+ peer = lookup_peer(conn, &dev);
+ if (peer)
+ return -EEXIST;
+
+ /*
+ * If net device exists already, just add route.
+ */
+ if (dev && !peer)
+ goto add_peer;
+
+ net = alloc_netdev(sizeof(struct lowpan_info), IFACE_NAME_TEMPLATE,
+ netdev_setup);
+ if (!net)
+ return -ENOMEM;
+
+ dev = netdev_priv(net);
+ dev->net = net;
+ INIT_LIST_HEAD(&dev->peers);
+
+ set_dev_addr(net, &conn->hcon->src, conn->hcon->src_type);
+
+ net->netdev_ops = &netdev_ops;
+ SET_NETDEV_DEV(net, &conn->hcon->dev);
+ SET_NETDEV_DEVTYPE(net, &bt_type);
+
+ err = register_netdev(net);
+ if (err < 0) {
+ BT_INFO("register_netdev failed %d", err);
+ free_netdev(net);
+ goto out;
+ }
+
+ BT_DBG("ifindex %d peer bdaddr %pMR my addr %pMR",
+ net->ifindex, &conn->hcon->dst, &conn->hcon->src);
+ set_bit(__LINK_STATE_PRESENT, &net->state);
+
+ entry = kzalloc(sizeof(struct lowpan_dev), GFP_KERNEL);
+ if (!entry) {
+ unregister_netdev(net);
+ return -ENOMEM;
+ }
+
+ entry->dev = net;
+
+ write_lock(&devices_lock);
+ INIT_LIST_HEAD(&entry->list);
+ list_add(&entry->list, &bt_6lowpan_devices);
+ write_unlock(&devices_lock);
+
+ ifup(net);
+
+add_peer:
+ peer = kzalloc(sizeof(struct peer), GFP_KERNEL);
+ if (!peer)
+ return -ENOMEM;
+
+ peer->conn = conn;
+ memset(&peer->peer_addr, 0, sizeof(struct in6_addr));
+
+ /* RFC 2464 ch. 5 */
+ peer->peer_addr.s6_addr[0] = 0xFE;
+ peer->peer_addr.s6_addr[1] = 0x80;
+ set_addr((u8 *)&peer->peer_addr.s6_addr + 8, conn->hcon->dst.b,
+ conn->hcon->dst_type);
+
+ memcpy(&peer->eui64_addr, (u8 *)&peer->peer_addr.s6_addr + 8,
+ EUI64_ADDR_LEN);
+
+ write_lock(&devices_lock);
+ INIT_LIST_HEAD(&peer->list);
+ peer_add(dev, peer);
+ write_unlock(&devices_lock);
+
+ netdev_notify_peers(dev->net); /* send neighbour adv at startup */
+
+out:
+ return err;
+}
+
+static void delete_netdev(struct work_struct *work)
+{
+ struct lowpan_dev *entry = container_of(work, struct lowpan_dev,
+ delete_netdev);
+
+ unregister_netdev(entry->dev);
+
+ /* The entry pointer is deleted in device_event() */
+}
+
+int bt_6lowpan_del_conn(struct l2cap_conn *conn)
+{
+ struct lowpan_dev *entry, *tmp;
+ struct lowpan_info *info = NULL;
+ struct peer *peer;
+ int err = -ENOENT;
+
+ write_lock(&devices_lock);
+
+ list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) {
+ info = lowpan_info(entry->dev);
+ peer = peer_lookup_conn(info, conn);
+ if (peer) {
+ peer_del(info, peer);
+ err = 0;
+ break;
+ }
+ }
+
+ write_unlock(&devices_lock);
+
+ if (!err && info && info->peer_count == 0) {
+ /*
+ * This function is called with hci dev lock held which means
+ * that we must delete the netdevice in worker thread.
+ */
+ INIT_WORK(&entry->delete_netdev, delete_netdev);
+ schedule_work(&entry->delete_netdev);
+ }
+
+ return err;
+}
+
+static int device_event(struct notifier_block *unused,
+ unsigned long event, void *ptr)
+{
+ struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+ struct lowpan_dev *entry, *tmp;
+
+ if (dev->type != ARPHRD_RAWIP)
+ return NOTIFY_DONE;
+
+ switch (event) {
+ case NETDEV_UNREGISTER:
+ write_lock(&devices_lock);
+ list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices,
+ list) {
+ if (entry->dev == dev) {
+ list_del(&entry->list);
+ kfree(entry);
+ break;
+ }
+ }
+ write_unlock(&devices_lock);
+ break;
+ }
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block bt_6lowpan_dev_notifier = {
+ .notifier_call = device_event,
+};
+
+int bt_6lowpan_init(void)
+{
+ return register_netdevice_notifier(&bt_6lowpan_dev_notifier);
+}
+
+void bt_6lowpan_cleanup(void)
+{
+ unregister_netdevice_notifier(&bt_6lowpan_dev_notifier);
+}
diff --git a/net/bluetooth/6lowpan.h b/net/bluetooth/6lowpan.h
new file mode 100644
index 0000000..680eac8
--- /dev/null
+++ b/net/bluetooth/6lowpan.h
@@ -0,0 +1,26 @@
+/*
+ Copyright (c) 2013 Intel Corp.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 and
+ only version 2 as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+*/
+
+#ifndef __6LOWPAN_H
+#define __6LOWPAN_H
+
+#include <linux/skbuff.h>
+#include <net/bluetooth/l2cap.h>
+
+int bt_6lowpan_recv(struct l2cap_conn *conn, struct sk_buff *skb);
+int bt_6lowpan_add_conn(struct l2cap_conn *conn);
+int bt_6lowpan_del_conn(struct l2cap_conn *conn);
+int bt_6lowpan_init(void);
+void bt_6lowpan_cleanup(void);
+
+#endif /* __6LOWPAN_H */
diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile
index 6a791e7..80cb215 100644
--- a/net/bluetooth/Makefile
+++ b/net/bluetooth/Makefile
@@ -10,6 +10,6 @@ obj-$(CONFIG_BT_HIDP) += hidp/
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 sco.o lib.o \
- a2mp.o amp.o
+ a2mp.o amp.o 6lowpan.o
subdir-ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 4af3821..155485f 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -40,6 +40,7 @@
#include "smp.h"
#include "a2mp.h"
#include "amp.h"
+#include "6lowpan.h"
bool disable_ertm;
@@ -6473,6 +6474,10 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
l2cap_conn_del(conn->hcon, EACCES);
break;
+ case L2CAP_FC_6LOWPAN:
+ bt_6lowpan_recv(conn, skb);
+ break;
+
default:
l2cap_data_channel(conn, cid, skb);
break;
@@ -6510,6 +6515,11 @@ int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr)
return exact ? lm1 : lm2;
}
+static bool is_bt_6lowpan(struct hci_conn *hcon)
+{
+ return false;
+}
+
void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
{
struct l2cap_conn *conn;
@@ -6518,8 +6528,12 @@ void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
if (!status) {
conn = l2cap_conn_add(hcon);
- if (conn)
+ if (conn) {
l2cap_conn_ready(conn);
+
+ if (is_bt_6lowpan(hcon))
+ bt_6lowpan_add_conn(conn);
+ }
} else {
l2cap_conn_del(hcon, bt_to_errno(status));
}
@@ -6540,6 +6554,9 @@ void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
{
BT_DBG("hcon %p reason %d", hcon, reason);
+ if (is_bt_6lowpan(hcon))
+ bt_6lowpan_del_conn(hcon->l2cap_data);
+
l2cap_conn_del(hcon, bt_to_errno(reason));
}
@@ -6817,11 +6834,14 @@ int __init l2cap_init(void)
l2cap_debugfs = debugfs_create_file("l2cap", 0444, bt_debugfs,
NULL, &l2cap_debugfs_fops);
+ bt_6lowpan_init();
+
return 0;
}
void l2cap_exit(void)
{
+ bt_6lowpan_cleanup();
debugfs_remove(l2cap_debugfs);
l2cap_cleanup_sockets();
}
--
1.8.3.1
^ permalink raw reply related
* [RFC v4 2/6] ipv6: Add checks for RAWIP ARP type
From: Jukka Rissanen @ 2013-11-13 10:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384337495-9043-1-git-send-email-jukka.rissanen@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
---
net/ipv6/addrconf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d6ff126..cde1061 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1797,6 +1797,7 @@ static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
return addrconf_ifid_sit(eui, dev);
case ARPHRD_IPGRE:
return addrconf_ifid_gre(eui, dev);
+ case ARPHRD_RAWIP:
case ARPHRD_IEEE802154:
return addrconf_ifid_eui64(eui, dev);
case ARPHRD_IEEE1394:
@@ -2681,7 +2682,8 @@ static void addrconf_dev_config(struct net_device *dev)
(dev->type != ARPHRD_INFINIBAND) &&
(dev->type != ARPHRD_IEEE802154) &&
(dev->type != ARPHRD_IEEE1394) &&
- (dev->type != ARPHRD_TUNNEL6)) {
+ (dev->type != ARPHRD_TUNNEL6) &&
+ (dev->type != ARPHRD_RAWIP)) {
/* Alas, we support only Ethernet autoconfiguration. */
return;
}
--
1.8.3.1
^ permalink raw reply related
* [RFC v4 1/6] net: if_arp: add ARPHRD_RAWIP type
From: Jukka Rissanen @ 2013-11-13 10:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384337495-9043-1-git-send-email-jukka.rissanen@linux.intel.com>
This is used when there is no L2 header before IP header.
Example of this is Bluetooth 6LoWPAN network.
The RAWIP header type value is already used in some Android kernels
so same value is used here in order not to break userspace.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
---
include/uapi/linux/if_arp.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/uapi/linux/if_arp.h b/include/uapi/linux/if_arp.h
index d7fea34..06fc69f 100644
--- a/include/uapi/linux/if_arp.h
+++ b/include/uapi/linux/if_arp.h
@@ -59,6 +59,7 @@
#define ARPHRD_LAPB 516 /* LAPB */
#define ARPHRD_DDCMP 517 /* Digital's DDCMP protocol */
#define ARPHRD_RAWHDLC 518 /* Raw HDLC */
+#define ARPHRD_RAWIP 530 /* Raw IP */
#define ARPHRD_TUNNEL 768 /* IPIP tunnel */
#define ARPHRD_TUNNEL6 769 /* IP6IP6 tunnel */
--
1.8.3.1
^ permalink raw reply related
* [RFC v4 0/6] Bluetooth LE 6LoWPAN
From: Jukka Rissanen @ 2013-11-13 10:11 UTC (permalink / raw)
To: linux-bluetooth
Hi,
this is 6LoWPAN code for BT LE as described in
http://tools.ietf.org/html/draft-ietf-6lowpan-btle-12
v4:
- removed the route setting code, neighbour discovery
should allow the devices to discover each other
- fix the uncompression of Traffic Class in IPv6 header,
this makes ssh to work between devices over a BT 6lowpan link
- removed setting of /proc conf options, they were useless
and not to be done in kernel module anyway
v3:
- misc changes according to Marcel's comments
- supports multiple connections / interface
- removed unused fragmentation code
- setup 6lowpan connection automatically if enabled via debugfs
The automatic 6lowpan enabling is done by setting
echo 1 > /sys/kernel/debug/bluetooth/hci0/6lowpan
before devices are connected.
v2:
- Change ARPHRD_IEEE802154 to ARPHRD_RAWIP. The generic code
in patches 1 and 2 is also sent to netdev mailing list.
- Sending route exporting patch 5 to netdev ml
- Check private/public BT address and toggle universal/local bit
accordingly in patch 3.
- The virtual interface template name is now shorter (bt%d)
- Various function name renames
- devtype of the interface set to "bluetooth"
v1:
- initial release
TODO:
- Discovery of 6LoWPAN service needs be automatic (UUID support)
- Refactor compression and uncompression code after these are fixed
in net/ieee802154/6lowpan.c. Bluetooth 6LoWPAN should be able to share
that part of the code.
Known issues:
- no UUID handling yet
Cheers,
Jukka
Jukka Rissanen (6):
net: if_arp: add ARPHRD_RAWIP type
ipv6: Add checks for RAWIP ARP type
Bluetooth: Initial skeleton code for BT 6LoWPAN
Bluetooth: Enable 6LoWPAN support for BT LE devices
Bluetooth: Enable 6LoWPAN if device supports it
Bluetooth: Manually enable or disable 6LoWPAN between devices
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 1 +
include/net/bluetooth/l2cap.h | 1 +
include/uapi/linux/if_arp.h | 1 +
net/bluetooth/6lowpan.c | 1687 ++++++++++++++++++++++++++++++++++++++
net/bluetooth/6lowpan.h | 27 +
net/bluetooth/Makefile | 2 +-
net/bluetooth/hci_core.c | 4 +
net/bluetooth/hci_event.c | 3 +
net/bluetooth/l2cap_core.c | 25 +-
net/ipv6/addrconf.c | 4 +-
11 files changed, 1753 insertions(+), 3 deletions(-)
create mode 100644 net/bluetooth/6lowpan.c
create mode 100644 net/bluetooth/6lowpan.h
--
1.8.3.1
^ permalink raw reply
* Re: [PATCH_v3 3/3] android/pan: Handle connection and control state notifications
From: Szymon Janc @ 2013-11-13 9:59 UTC (permalink / raw)
To: Ravi Kumar Veeramally; +Cc: linux-bluetooth, Johan Hedberg
In-Reply-To: <52834A76.4050600@linux.intel.com>
Hi,
> >> +
> >> + switch (opcode) {
> >> + case HAL_EV_PAN_CONN_STATE:
> >> + handle_conn_state(buf);
> >> + break;
> >> + case HAL_EV_PAN_CTRL_STATE:
> >> + handle_ctrl_state(buf);
> >> + break;
> >> + default:
> >> + DBG("Unhandled callback opcode=0x%x", opcode);
> >> + break;
> >> + }
> >> }
> > What I don't like about this is that you're not pushing the data length
> > to the handler functions. If you did that the handler functions could:
> >
> > if (len < sizeof(*ev))
> > return;
> >
> > Instead of return we could also just abort - what's the general policy
> > on the HAL side regarding invalid data from the daemon? How does this
> > relate to the work Szymon is doing to add proper checks for the IPC
> > data? Is that only for the daemon side?
> >
> > Are we missing similar checks in other HALs too?
>
> Yes, we are not doing similar checks in other HALs
> (hal-bluetooth/a2dp/hid/) too.
> Very few places in hal-bluetooth length is passing but validation is
> not done.
> I will fix them all and send you the patch.
As mentioned in my RFC, messages have very similar format and can be checked
in single place using some common macros. I'm now working on addressing Johan
comments in that RFC. As suggested I'm going to use tables of handlers instead
switch-case and this should also allow to refactor current code to avoid
switch-cases we currently have. Services will simply register own tables of
handlers for service they implement. Idea is that check will be done in common
place and then handlers will have form of void handle_foo(struct foo *ev) with
guarantee that passed command/event is memory size valid.
Plan is to make this generic code use both by hal and daemon.
So, I'm not sure if it makes much sense to fix passing buf+len to all handlers
we have now.
If you have other ideas for this please comment.
--
BR
Szymon Janc
^ permalink raw reply
* Re: [PATCH_v3 3/3] android/pan: Handle connection and control state notifications
From: Ravi Kumar Veeramally @ 2013-11-13 9:46 UTC (permalink / raw)
To: linux-bluetooth, Johan Hedberg
In-Reply-To: <20131113093301.GB1749@x220.p-661hnu-f1>
Hi Johan,
On 11/13/2013 11:33 AM, Johan Hedberg wrote:
> Hi Ravi,
>
> On Wed, Nov 13, 2013, Ravi kumar Veeramally wrote:
>> ---
>> android/hal-pan.c | 31 +++++++++++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
> I've applied the first two patches, but for this one I've got a few
> questions:
>
>> diff --git a/android/hal-pan.c b/android/hal-pan.c
>> index 851c5d2..2bc560e 100644
>> --- a/android/hal-pan.c
>> +++ b/android/hal-pan.c
>> @@ -31,10 +31,41 @@ static bool interface_ready(void)
>> return cbs != NULL;
>> }
>>
>> +static void handle_conn_state(void *buf)
>> +{
>> + struct hal_ev_pan_conn_state *ev = buf;
>> +
>> + if (cbs->connection_state_cb)
>> + cbs->connection_state_cb(ev->state, ev->status,
>> + (bt_bdaddr_t *) ev->bdaddr,
>> + ev->local_role, ev->remote_role);
>> +}
>> +
>> +static void handle_ctrl_state(void *buf)
>> +{
>> + struct hal_ev_pan_ctrl_state *ev = buf;
>> +
>> + if (cbs->control_state_cb)
>> + cbs->control_state_cb(ev->state, ev->status,
>> + ev->local_role, (char *)ev->name);
>> +}
>> +
>> void bt_notify_pan(uint8_t opcode, void *buf, uint16_t len)
>> {
>> if (!interface_ready())
>> return;
>> +
>> + switch (opcode) {
>> + case HAL_EV_PAN_CONN_STATE:
>> + handle_conn_state(buf);
>> + break;
>> + case HAL_EV_PAN_CTRL_STATE:
>> + handle_ctrl_state(buf);
>> + break;
>> + default:
>> + DBG("Unhandled callback opcode=0x%x", opcode);
>> + break;
>> + }
>> }
> What I don't like about this is that you're not pushing the data length
> to the handler functions. If you did that the handler functions could:
>
> if (len < sizeof(*ev))
> return;
>
> Instead of return we could also just abort - what's the general policy
> on the HAL side regarding invalid data from the daemon? How does this
> relate to the work Szymon is doing to add proper checks for the IPC
> data? Is that only for the daemon side?
>
> Are we missing similar checks in other HALs too?
Yes, we are not doing similar checks in other HALs
(hal-bluetooth/a2dp/hid/) too.
Very few places in hal-bluetooth length is passing but validation is
not done.
I will fix them all and send you the patch.
Thanks,
Ravi.
^ permalink raw reply
* Re: [PATCH_v3 3/3] android/pan: Handle connection and control state notifications
From: Johan Hedberg @ 2013-11-13 9:33 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1384334727-25940-3-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Wed, Nov 13, 2013, Ravi kumar Veeramally wrote:
> ---
> android/hal-pan.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
I've applied the first two patches, but for this one I've got a few
questions:
> diff --git a/android/hal-pan.c b/android/hal-pan.c
> index 851c5d2..2bc560e 100644
> --- a/android/hal-pan.c
> +++ b/android/hal-pan.c
> @@ -31,10 +31,41 @@ static bool interface_ready(void)
> return cbs != NULL;
> }
>
> +static void handle_conn_state(void *buf)
> +{
> + struct hal_ev_pan_conn_state *ev = buf;
> +
> + if (cbs->connection_state_cb)
> + cbs->connection_state_cb(ev->state, ev->status,
> + (bt_bdaddr_t *) ev->bdaddr,
> + ev->local_role, ev->remote_role);
> +}
> +
> +static void handle_ctrl_state(void *buf)
> +{
> + struct hal_ev_pan_ctrl_state *ev = buf;
> +
> + if (cbs->control_state_cb)
> + cbs->control_state_cb(ev->state, ev->status,
> + ev->local_role, (char *)ev->name);
> +}
> +
> void bt_notify_pan(uint8_t opcode, void *buf, uint16_t len)
> {
> if (!interface_ready())
> return;
> +
> + switch (opcode) {
> + case HAL_EV_PAN_CONN_STATE:
> + handle_conn_state(buf);
> + break;
> + case HAL_EV_PAN_CTRL_STATE:
> + handle_ctrl_state(buf);
> + break;
> + default:
> + DBG("Unhandled callback opcode=0x%x", opcode);
> + break;
> + }
> }
What I don't like about this is that you're not pushing the data length
to the handler functions. If you did that the handler functions could:
if (len < sizeof(*ev))
return;
Instead of return we could also just abort - what's the general policy
on the HAL side regarding invalid data from the daemon? How does this
relate to the work Szymon is doing to add proper checks for the IPC
data? Is that only for the daemon side?
Are we missing similar checks in other HALs too?
Johan
^ permalink raw reply
* Re: [PATCH_v2 1/3] android/hidhost: Handle uhid output and feature events
From: Johan Hedberg @ 2013-11-13 9:27 UTC (permalink / raw)
To: Ravi Kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <528343B1.5020306@linux.intel.com>
Hi Ravi,
On Wed, Nov 13, 2013, Ravi Kumar Veeramally wrote:
> Hi Johan,
>
> >>+ sscanf((char *) &(ev->u.output.data)[i * 2],
> >>+ "%hhx", &(req + 1)[i]);
> >The last parameter is a bit of a brain twister. How about simply &req[1 + i]?
> >
> Yeap, simple :).
I fixed this up myself, so all three patches have now been applied.
Johan
^ permalink raw reply
* [PATCH_v3 3/3] android/pan: Handle connection and control state notifications
From: Ravi kumar Veeramally @ 2013-11-13 9:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1384334727-25940-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-pan.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/android/hal-pan.c b/android/hal-pan.c
index 851c5d2..2bc560e 100644
--- a/android/hal-pan.c
+++ b/android/hal-pan.c
@@ -31,10 +31,41 @@ static bool interface_ready(void)
return cbs != NULL;
}
+static void handle_conn_state(void *buf)
+{
+ struct hal_ev_pan_conn_state *ev = buf;
+
+ if (cbs->connection_state_cb)
+ cbs->connection_state_cb(ev->state, ev->status,
+ (bt_bdaddr_t *) ev->bdaddr,
+ ev->local_role, ev->remote_role);
+}
+
+static void handle_ctrl_state(void *buf)
+{
+ struct hal_ev_pan_ctrl_state *ev = buf;
+
+ if (cbs->control_state_cb)
+ cbs->control_state_cb(ev->state, ev->status,
+ ev->local_role, (char *)ev->name);
+}
+
void bt_notify_pan(uint8_t opcode, void *buf, uint16_t len)
{
if (!interface_ready())
return;
+
+ switch (opcode) {
+ case HAL_EV_PAN_CONN_STATE:
+ handle_conn_state(buf);
+ break;
+ case HAL_EV_PAN_CTRL_STATE:
+ handle_ctrl_state(buf);
+ break;
+ default:
+ DBG("Unhandled callback opcode=0x%x", opcode);
+ break;
+ }
}
static bt_status_t pan_enable(int local_role)
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v3 2/3] android/pan: Add notify method to PAN notifications
From: Ravi kumar Veeramally @ 2013-11-13 9:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1384334727-25940-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-pan.c | 6 ++++++
android/hal.h | 1 +
2 files changed, 7 insertions(+)
diff --git a/android/hal-pan.c b/android/hal-pan.c
index bec179f..851c5d2 100644
--- a/android/hal-pan.c
+++ b/android/hal-pan.c
@@ -31,6 +31,12 @@ static bool interface_ready(void)
return cbs != NULL;
}
+void bt_notify_pan(uint8_t opcode, void *buf, uint16_t len)
+{
+ if (!interface_ready())
+ return;
+}
+
static bt_status_t pan_enable(int local_role)
{
struct hal_cmd_pan_enable cmd;
diff --git a/android/hal.h b/android/hal.h
index baa4754..72090fe 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -31,3 +31,4 @@ void bt_thread_associate(void);
void bt_thread_disassociate(void);
void bt_notify_hidhost(uint8_t opcode, void *buf, uint16_t len);
void bt_notify_a2dp(uint8_t opcode, void *buf, uint16_t len);
+void bt_notify_pan(uint8_t opcode, void *buf, uint16_t len);
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v3 1/3] android: Fix opcode parameter type from uint16_t to uint8_t
From: Ravi kumar Veeramally @ 2013-11-13 9:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
---
android/hal-a2dp.c | 2 +-
android/hal-bluetooth.c | 2 +-
android/hal-hidhost.c | 2 +-
android/hal.h | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/android/hal-a2dp.c b/android/hal-a2dp.c
index f0c301e..4fe7c20 100644
--- a/android/hal-a2dp.c
+++ b/android/hal-a2dp.c
@@ -49,7 +49,7 @@ static void handle_audio_state(void *buf)
}
/* will be called from notification thread context */
-void bt_notify_a2dp(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_a2dp(uint8_t opcode, void *buf, uint16_t len)
{
if (!interface_ready())
return;
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 3e5d41f..1cfd994 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -281,7 +281,7 @@ static void handle_acl_state_changed(void *buf)
}
/* will be called from notification thread context */
-void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_adapter(uint8_t opcode, void *buf, uint16_t len)
{
if (!interface_ready())
return;
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 97a1aa0..2ce17a3 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -88,7 +88,7 @@ static void handle_virtual_unplug(void *buf)
}
/* will be called from notification thread context */
-void bt_notify_hidhost(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_hidhost(uint8_t opcode, void *buf, uint16_t len)
{
if (!interface_ready())
return;
diff --git a/android/hal.h b/android/hal.h
index 2ce7932..baa4754 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -26,8 +26,8 @@ bthh_interface_t *bt_get_hidhost_interface(void);
btpan_interface_t *bt_get_pan_interface(void);
btav_interface_t *bt_get_a2dp_interface(void);
-void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len);
+void bt_notify_adapter(uint8_t opcode, void *buf, uint16_t len);
void bt_thread_associate(void);
void bt_thread_disassociate(void);
-void bt_notify_hidhost(uint16_t opcode, void *buf, uint16_t len);
-void bt_notify_a2dp(uint16_t opcode, void *buf, uint16_t len);
+void bt_notify_hidhost(uint8_t opcode, void *buf, uint16_t len);
+void bt_notify_a2dp(uint8_t opcode, void *buf, uint16_t len);
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH_v2 1/3] android/hidhost: Handle uhid output and feature events
From: Ravi Kumar Veeramally @ 2013-11-13 9:17 UTC (permalink / raw)
To: linux-bluetooth, Johan Hedberg
In-Reply-To: <20131113090159.GA32659@x220.p-661hnu-f1>
Hi Johan,
>> + sscanf((char *) &(ev->u.output.data)[i * 2],
>> + "%hhx", &(req + 1)[i]);
> The last parameter is a bit of a brain twister. How about simply &req[1 + i]?
>
Yeap, simple :).
Thanks,
Ravi.
^ permalink raw reply
* Re: [PATCH_v2 1/3] android/hidhost: Handle uhid output and feature events
From: Johan Hedberg @ 2013-11-13 9:01 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1384268835-7570-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Tue, Nov 12, 2013, Ravi kumar Veeramally wrote:
> + sscanf((char *) &(ev->u.output.data)[i * 2],
> + "%hhx", &(req + 1)[i]);
The last parameter is a bit of a brain twister. How about simply &req[1 + i]?
Johan
^ permalink raw reply
* [RFC BlueZ 3/3] input: Fix setting .local_uuid
From: Luiz Augusto von Dentz @ 2013-11-13 8:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384332813-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
By setting .local_uuid it makes the core do a scrict check on uuids
enabled for the adapter but HID host does not have a record so it
does not require a .local_uuid to be set.
---
profiles/input/manager.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/profiles/input/manager.c b/profiles/input/manager.c
index 689ccdd..b12b43e 100644
--- a/profiles/input/manager.c
+++ b/profiles/input/manager.c
@@ -57,7 +57,6 @@ static void hid_server_remove(struct btd_profile *p,
static struct btd_profile input_profile = {
.name = "input-hid",
- .local_uuid = HID_UUID,
.remote_uuid = HID_UUID,
.auto_connect = true,
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ 2/3] audio/A2DP: Set profile .local_uuid properly
From: Luiz Augusto von Dentz @ 2013-11-13 8:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384332813-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
With the changes to the core now it does a strict match of adapter
profiles with .local_uuid to prevent connecting to profiles not
enabled in SDP.
---
profiles/audio/a2dp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 6b3d6b2..0a347e5 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -2008,6 +2008,7 @@ static struct btd_profile a2dp_source_profile = {
.name = "a2dp-source",
.priority = BTD_PROFILE_PRIORITY_MEDIUM,
+ .local_uuid = A2DP_SINK_UUID,
.remote_uuid = A2DP_SOURCE_UUID,
.device_probe = a2dp_source_probe,
.device_remove = a2dp_source_remove,
@@ -2024,6 +2025,7 @@ static struct btd_profile a2dp_sink_profile = {
.name = "a2dp-sink",
.priority = BTD_PROFILE_PRIORITY_MEDIUM,
+ .local_uuid = A2DP_SOURCE_UUID,
.remote_uuid = A2DP_SINK_UUID,
.device_probe = a2dp_sink_probe,
.device_remove = a2dp_sink_remove,
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ 1/3] core/device: Only connect profiles which are enabled
From: Luiz Augusto von Dentz @ 2013-11-13 8:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384332813-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Some profile may register their records dynamically e.g. A2DP so the code
has to check if the profile is really available before attempting to
connect.
---
src/device.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/src/device.c b/src/device.c
index 9ca457e..60efd62 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1224,11 +1224,25 @@ void device_add_eir_uuids(struct btd_device *dev, GSList *uuids)
DEVICE_INTERFACE, "UUIDs");
}
+static int uuid_cmp(const void *a, const void *b)
+{
+ const sdp_record_t *rec = a;
+ const char *string = b;
+ uuid_t uuid;
+
+ if (bt_string2uuid(&uuid, string) < 0)
+ return -1;
+
+ return sdp_uuid_cmp(&rec->svclass, &uuid);
+}
+
static struct btd_service *find_connectable_service(struct btd_device *dev,
const char *uuid)
{
GSList *l;
+ sdp_list_t *uuids;
+ uuids = btd_adapter_get_services(dev->adapter);
for (l = dev->services; l != NULL; l = g_slist_next(l)) {
struct btd_service *service = l->data;
struct btd_profile *p = btd_service_get_profile(service);
@@ -1236,7 +1250,12 @@ static struct btd_service *find_connectable_service(struct btd_device *dev,
if (!p->connect || !p->remote_uuid)
continue;
- if (strcasecmp(uuid, p->remote_uuid) == 0)
+ if (strcasecmp(uuid, p->remote_uuid))
+ continue;
+
+ /* Check if adapter has the local_uuid enabled */
+ if (!p->local_uuid || sdp_list_find(uuids,
+ (void *) p->local_uuid, uuid_cmp))
return service;
}
@@ -1256,6 +1275,7 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
struct btd_service *service;
struct btd_profile *p;
GSList *l;
+ sdp_list_t *uuids;
if (uuid) {
service = find_connectable_service(dev, uuid);
@@ -1265,6 +1285,7 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
return dev->pending;
}
+ uuids = btd_adapter_get_services(dev->adapter);
for (l = dev->services; l != NULL; l = g_slist_next(l)) {
service = l->data;
p = btd_service_get_profile(service);
@@ -1272,14 +1293,18 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
if (!p->auto_connect)
continue;
- if (g_slist_find(dev->pending, service))
- continue;
-
if (btd_service_get_state(service) !=
BTD_SERVICE_STATE_DISCONNECTED)
continue;
- dev->pending = g_slist_insert_sorted(dev->pending, service,
+ if (g_slist_find(dev->pending, service))
+ continue;
+
+ /* Check if adapter has the local_uuid enabled */
+ if (!p->local_uuid || sdp_list_find(uuids,
+ (void *) p->local_uuid, uuid_cmp))
+ dev->pending = g_slist_insert_sorted(dev->pending,
+ service,
service_prio_cmp);
}
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ 0/3] Check if profile local_uuid is enabled
From: Luiz Augusto von Dentz @ 2013-11-13 8:53 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This attempts to solve a problem with certain APIs that are adapter bond
such as Media interface and adapter_service_add as opposed to btd_profile
that is valid for every adapter.
Making Media API to be available on /org/bluez and perhaps tight btd_profile
and adapter_service_add should solve the problem in the long term but since
we cannot just break the API this is probably still necessary.
Luiz Augusto von Dentz (3):
core/device: Only connect profiles which are enabled
audio/A2DP: Set profile .local_uuid properly
input: Fix setting .local_uuid
profiles/audio/a2dp.c | 2 ++
profiles/input/manager.c | 1 -
src/device.c | 35 ++++++++++++++++++++++++++++++-----
3 files changed, 32 insertions(+), 6 deletions(-)
--
1.8.3.1
^ permalink raw reply
* [PATCH RFC] tty_ldisc: add more limits to the @write_wakeup
From: Huang Shijie @ 2013-11-13 7:30 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, marcel, linux-bluetooth, Huang Shijie
In the uart_handle_cts_change(), uart_write_wakeup() is called after
we call @uart_port->ops->start_tx().
The Documentation/serial/driver tells us:
-----------------------------------------------
start_tx(port)
Start transmitting characters.
Locking: port->lock taken.
Interrupts: locally disabled.
-----------------------------------------------
So when the uart_write_wakeup() is called, the port->lock is taken by
the upper. See the following callstack:
|_ uart_write_wakeup
|_ tty_wakeup
|_ ld->ops->write_wakeup
With the port->lock held, we call the @write_wakeup. Some implemetation of
the @write_wakeup does not notice that the port->lock is held, and it still
tries to send data with uart_write() which will try to grab the prot->lock.
A dead lock occurs, see the following log caught in the Bluetooth by uart:
--------------------------------------------------------------------
BUG: spinlock lockup suspected on CPU#0, swapper/0/0
lock: 0xdc3f4410, .magic: dead4ead, .owner: swapper/0/0, .owner_cpu: 0
CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W 3.10.17-16839-ge4a1bef #1320
[<80014cbc>] (unwind_backtrace+0x0/0x138) from [<8001251c>] (show_stack+0x10/0x14)
[<8001251c>] (show_stack+0x10/0x14) from [<802816ac>] (do_raw_spin_lock+0x108/0x184)
[<802816ac>] (do_raw_spin_lock+0x108/0x184) from [<806a22b0>] (_raw_spin_lock_irqsave+0x54/0x60)
[<806a22b0>] (_raw_spin_lock_irqsave+0x54/0x60) from [<802f5754>] (uart_write+0x38/0xe0)
[<802f5754>] (uart_write+0x38/0xe0) from [<80455270>] (hci_uart_tx_wakeup+0xa4/0x168)
[<80455270>] (hci_uart_tx_wakeup+0xa4/0x168) from [<802dab18>] (tty_wakeup+0x50/0x5c)
[<802dab18>] (tty_wakeup+0x50/0x5c) from [<802f81a4>] (imx_rtsint+0x50/0x80)
[<802f81a4>] (imx_rtsint+0x50/0x80) from [<802f88f4>] (imx_int+0x158/0x17c)
[<802f88f4>] (imx_int+0x158/0x17c) from [<8007abe0>] (handle_irq_event_percpu+0x50/0x194)
[<8007abe0>] (handle_irq_event_percpu+0x50/0x194) from [<8007ad60>] (handle_irq_event+0x3c/0x5c)
--------------------------------------------------------------------
This patch adds more limits to the @write_wakeup, the one who wants to
implemet the @write_wakeup should follow the limits which avoid the deadlock.
Signed-off-by: Huang Shijie <b32955@freescale.com>
---
include/linux/tty_ldisc.h | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index f15c898..539ccc5 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -91,7 +91,10 @@
* This function is called by the low-level tty driver to signal
* that line discpline should try to send more characters to the
* low-level driver for transmission. If the line discpline does
- * not have any more data to send, it can just return.
+ * not have any more data to send, it can just return. If the line
+ * discipline does have some data to send, please arise a tasklet
+ * or workqueue to do the real data transfer. Do not send data in
+ * this hook, it may leads to a deadlock.
*
* int (*hangup)(struct tty_struct *)
*
--
1.7.2.rc3
^ permalink raw reply related
* Re: shutdown(3) and bluetooth.
From: Marcel Holtmann @ 2013-11-13 1:58 UTC (permalink / raw)
To: Dave Jones; +Cc: netdev, linux-bluetooth@vger.kernel.org development
In-Reply-To: <20131113002819.GB12615@redhat.com>
Hi Dave,
>>> So it seems it affects both SCO and RFCOMM.
>>>
>>>> What kernel did you run this against? It is a shot in the dark, but can you try linux-next quickly.
>>>> There was a socket related fix for the socket options where we confused RFCOMM vs L2CAP struct sock.
>>>
>>> first noticed it on Linus' latest HEAD, and then reproduced it on 3.11.6
>>> I'll look at linux-next tomorrow.
>>
>> I looked through the code and only call bt_sock_wait_state when SOCK_LINGER and sk_lingertime is set. In that case we actually block until the socket state changes to BT_CLOSED.
>>
>> The only way I see this could happen is if you have a huge linger timeout and confused the socket state before. What is actually the list of system calls that you are throwing at this socket.
>
> Ah. I recently changed some code that's now doing this on every socket at shutdown..
> (simplified cut-n-paste)
>
> struct linger ling = { .l_onoff = FALSE, };
>
> for (i = 0; i < nr_sockets; i++) {
> fd = shm->sockets[i].fd;
> shm->sockets[i].fd = 0;
>
> setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger));
> shutdown(fd, SHUT_RDWR);
> close(fd);
> }
>
> I could just rip out that linger code completely and just hope that sockets staying in
> TIME_WAIT is good enough. iirc, I added it when after multiple runs, some of the
> weirder protocols would fail to open a socket once a certain number of existing
> sockets had opened, even if they were in SOCK_WAIT
>
> two remaining questions though. That code is setting linger to false. Why would
> that cause the sk_lingertime to be taken into consideration ? And why is this
> only a problem for bluetooth (apparently) ?
we are not touching that part of setsockopt. That is handled by net/core/sock.c and we just check if SOCK_LINGER flag is set and if we have a positive sk_lingertime. So this is a bit suspicious on why this is happening, but I don’t think it is our mistake.
Regards
Marcel
^ permalink raw reply
* Re: shutdown(3) and bluetooth.
From: Dave Jones @ 2013-11-13 0:28 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: netdev, linux-bluetooth@vger.kernel.org development
In-Reply-To: <D8BE686E-E81D-48CD-8D67-2B138191E0CC@holtmann.org>
On Wed, Nov 13, 2013 at 08:37:15AM +0900, Marcel Holtmann wrote:
> > So it seems it affects both SCO and RFCOMM.
> >
> >> What kernel did you run this against? It is a shot in the dark, but can you try linux-next quickly.
> >> There was a socket related fix for the socket options where we confused RFCOMM vs L2CAP struct sock.
> >
> > first noticed it on Linus' latest HEAD, and then reproduced it on 3.11.6
> > I'll look at linux-next tomorrow.
>
> I looked through the code and only call bt_sock_wait_state when SOCK_LINGER and sk_lingertime is set. In that case we actually block until the socket state changes to BT_CLOSED.
>
> The only way I see this could happen is if you have a huge linger timeout and confused the socket state before. What is actually the list of system calls that you are throwing at this socket.
Ah. I recently changed some code that's now doing this on every socket at shutdown..
(simplified cut-n-paste)
struct linger ling = { .l_onoff = FALSE, };
for (i = 0; i < nr_sockets; i++) {
fd = shm->sockets[i].fd;
shm->sockets[i].fd = 0;
setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger));
shutdown(fd, SHUT_RDWR);
close(fd);
}
I could just rip out that linger code completely and just hope that sockets staying in
TIME_WAIT is good enough. iirc, I added it when after multiple runs, some of the
weirder protocols would fail to open a socket once a certain number of existing
sockets had opened, even if they were in SOCK_WAIT
two remaining questions though. That code is setting linger to false. Why would
that cause the sk_lingertime to be taken into consideration ? And why is this
only a problem for bluetooth (apparently) ?
Dave
^ permalink raw reply
* [PATCH v2 8/8] android: Rename bluetooth service functions to match service name
From: Szymon Janc @ 2013-11-12 23:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384300100-8941-1-git-send-email-szymon.janc@tieto.com>
Make public functions match service name.
---
android/bluetooth.c | 26 +++++++++++++-------------
android/bluetooth.h | 16 ++++++++--------
android/main.c | 13 +++++++------
3 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 7a33d4f..39589fa 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -938,7 +938,7 @@ static void register_mgmt_handlers(void)
static void load_link_keys_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
- bt_adapter_ready cb = user_data;
+ bt_bluetooth_ready cb = user_data;
int err;
if (status) {
@@ -957,7 +957,7 @@ failed:
cb(err, NULL);
}
-static void load_link_keys(GSList *keys, bt_adapter_ready cb)
+static void load_link_keys(GSList *keys, bt_bluetooth_ready cb)
{
struct mgmt_cp_load_link_keys *cp;
struct mgmt_link_key_info *key;
@@ -1279,7 +1279,7 @@ static void read_info_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_rp_read_info *rp = param;
- bt_adapter_ready cb = user_data;
+ bt_bluetooth_ready cb = user_data;
uint32_t missing_settings, supported_settings;
int err;
@@ -1342,7 +1342,7 @@ failed:
static void mgmt_index_added_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
- bt_adapter_ready cb = user_data;
+ bt_bluetooth_ready cb = user_data;
DBG("index %u", index);
@@ -1379,7 +1379,7 @@ static void read_index_list_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_rp_read_index_list *rp = param;
- bt_adapter_ready cb = user_data;
+ bt_bluetooth_ready cb = user_data;
uint16_t num;
int i;
@@ -1433,7 +1433,7 @@ static void read_version_complete(uint8_t status, uint16_t length,
{
const struct mgmt_rp_read_version *rp = param;
uint8_t mgmt_version, mgmt_revision;
- bt_adapter_ready cb = user_data;
+ bt_bluetooth_ready cb = user_data;
DBG("");
@@ -1474,7 +1474,7 @@ failed:
cb(-EIO, NULL);
}
-bool bt_adapter_start(int index, bt_adapter_ready cb)
+bool bt_bluetooth_start(int index, bt_bluetooth_ready cb)
{
DBG("index %d", index);
@@ -1503,7 +1503,7 @@ bool bt_adapter_start(int index, bt_adapter_ready cb)
static void shutdown_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
- bt_adapter_stopped cb = user_data;
+ bt_bluetooth_stopped cb = user_data;
if (status != MGMT_STATUS_SUCCESS)
error("Clean controller shutdown failed");
@@ -1511,7 +1511,7 @@ static void shutdown_complete(uint8_t status, uint16_t length,
cb();
}
-bool bt_adapter_stop(bt_adapter_stopped cb)
+bool bt_bluetooth_stop(bt_bluetooth_stopped cb)
{
struct mgmt_mode cp;
@@ -1527,7 +1527,7 @@ bool bt_adapter_stop(bt_adapter_stopped cb)
NULL) > 0;
}
-void bt_adapter_cleanup(void)
+void bt_bluetooth_cleanup(void)
{
g_free(adapter.name);
adapter.name = NULL;
@@ -2041,7 +2041,7 @@ static uint8_t get_remote_services(void *buf, uint16_t len)
return browse_remote_sdp(&addr);
}
-void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
+void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
{
uint8_t status = HAL_STATUS_FAILED;
@@ -2160,7 +2160,7 @@ error:
ipc_send_rsp(sk, HAL_SERVICE_ID_BLUETOOTH, status);
}
-bool bt_adapter_register(int sk)
+bool bt_bluetooth_register(int sk)
{
DBG("");
@@ -2169,7 +2169,7 @@ bool bt_adapter_register(int sk)
return true;
}
-void bt_adapter_unregister(void)
+void bt_bluetooth_unregister(void)
{
DBG("");
diff --git a/android/bluetooth.h b/android/bluetooth.h
index 99bd85f..44b8e9e 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
@@ -21,18 +21,18 @@
*
*/
-typedef void (*bt_adapter_ready)(int err, const bdaddr_t *addr);
-bool bt_adapter_start(int index, bt_adapter_ready cb);
+typedef void (*bt_bluetooth_ready)(int err, const bdaddr_t *addr);
+bool bt_bluetooth_start(int index, bt_bluetooth_ready cb);
-typedef void (*bt_adapter_stopped)(void);
-bool bt_adapter_stop(bt_adapter_stopped cb);
+typedef void (*bt_bluetooth_stopped)(void);
+bool bt_bluetooth_stop(bt_bluetooth_stopped cb);
-void bt_adapter_cleanup(void);
+void bt_bluetooth_cleanup(void);
-void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
+void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-bool bt_adapter_register(int sk);
-void bt_adapter_unregister(void);
+bool bt_bluetooth_register(int sk);
+void bt_bluetooth_unregister(void);
int bt_adapter_add_record(sdp_record_t *rec, uint8_t svc_hint);
void bt_adapter_remove_record(uint32_t handle);
diff --git a/android/main.c b/android/main.c
index e4c93ec..cbbfc06 100644
--- a/android/main.c
+++ b/android/main.c
@@ -84,7 +84,7 @@ static void service_register(void *buf, uint16_t len)
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
- if (!bt_adapter_register(sk))
+ if (!bt_bluetooth_register(sk))
goto failed;
break;
@@ -134,7 +134,7 @@ static void service_unregister(void *buf, uint16_t len)
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
- bt_adapter_unregister();
+ bt_bluetooth_unregister();
break;
case HAL_SERVICE_ID_SOCK:
bt_socket_unregister();
@@ -203,7 +203,7 @@ static void stop_bluetooth(void)
__stop = true;
- if (!bt_adapter_stop(bluetooth_stopped)) {
+ if (!bt_bluetooth_stop(bluetooth_stopped)) {
g_main_loop_quit(event_loop);
return;
}
@@ -251,7 +251,8 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
handle_service_core(msg->opcode, msg->payload, msg->len);
break;
case HAL_SERVICE_ID_BLUETOOTH:
- bt_adapter_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
+ bt_bluetooth_handle_cmd(fd, msg->opcode, msg->payload,
+ msg->len);
break;
case HAL_SERVICE_ID_HIDHOST:
bt_hid_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
@@ -560,7 +561,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (!bt_adapter_start(option_index, adapter_ready))
+ if (!bt_bluetooth_start(option_index, adapter_ready))
return EXIT_FAILURE;
/* Use params: mtu = 0, flags = 0 */
@@ -574,7 +575,7 @@ int main(int argc, char *argv[])
cleanup_hal_connection();
stop_sdp_server();
- bt_adapter_cleanup();
+ bt_bluetooth_cleanup();
g_main_loop_unref(event_loop);
info("Exit");
--
1.8.4.3
^ permalink raw reply related
* [PATCH v2 6/8] android: Remove not needed bt_adapter_get_address function
From: Szymon Janc @ 2013-11-12 23:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384300100-8941-1-git-send-email-szymon.janc@tieto.com>
All services receive adapter address on init so there is no need for
this function. Removing it will also help keeping services not depend
on adapter service.
---
android/adapter.c | 5 -----
android/adapter.h | 2 --
2 files changed, 7 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index dcb823b..3f135be 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -2160,11 +2160,6 @@ error:
ipc_send_rsp(sk, HAL_SERVICE_ID_BLUETOOTH, status);
}
-const bdaddr_t *bt_adapter_get_address(void)
-{
- return &adapter.bdaddr;
-}
-
bool bt_adapter_register(int sk)
{
DBG("");
diff --git a/android/adapter.h b/android/adapter.h
index 68f2046..99bd85f 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -31,8 +31,6 @@ void bt_adapter_cleanup(void);
void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-const bdaddr_t *bt_adapter_get_address(void);
-
bool bt_adapter_register(int sk);
void bt_adapter_unregister(void);
--
1.8.4.3
^ permalink raw reply related
* [PATCH v2 5/8] android: Report adapter address in adapter_ready callback
From: Szymon Janc @ 2013-11-12 23:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384300100-8941-1-git-send-email-szymon.janc@tieto.com>
Adapter is not going to change while daemon is running so its address
can be stored after init is complete.
---
android/adapter.c | 14 +++++++-------
android/adapter.h | 2 +-
android/main.c | 7 +++++--
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 001059a..dcb823b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -950,11 +950,11 @@ static void load_link_keys_complete(uint8_t status, uint16_t length,
DBG("status %u", status);
- cb(0);
+ cb(0, &adapter.bdaddr);
return;
failed:
- cb(err);
+ cb(err, NULL);
}
static void load_link_keys(GSList *keys, bt_adapter_ready cb)
@@ -989,7 +989,7 @@ static void load_link_keys(GSList *keys, bt_adapter_ready cb)
if (id == 0) {
error("Failed to load link keys");
- cb(-EIO);
+ cb(-EIO, NULL);
}
}
@@ -1336,7 +1336,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
return;
failed:
- cb(err);
+ cb(err, NULL);
}
static void mgmt_index_added_event(uint16_t index, uint16_t length,
@@ -1358,7 +1358,7 @@ static void mgmt_index_added_event(uint16_t index, uint16_t length,
if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
read_info_complete, cb, NULL) == 0) {
- cb(-EIO);
+ cb(-EIO, NULL);
return;
}
}
@@ -1425,7 +1425,7 @@ static void read_index_list_complete(uint8_t status, uint16_t length,
return;
failed:
- cb(-EIO);
+ cb(-EIO, NULL);
}
static void read_version_complete(uint8_t status, uint16_t length,
@@ -1471,7 +1471,7 @@ static void read_version_complete(uint8_t status, uint16_t length,
error("Failed to read controller index list");
failed:
- cb(-EIO);
+ cb(-EIO, NULL);
}
bool bt_adapter_start(int index, bt_adapter_ready cb)
diff --git a/android/adapter.h b/android/adapter.h
index e8993f2..68f2046 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -21,7 +21,7 @@
*
*/
-typedef void (*bt_adapter_ready)(int err);
+typedef void (*bt_adapter_ready)(int err, const bdaddr_t *addr);
bool bt_adapter_start(int index, bt_adapter_ready cb);
typedef void (*bt_adapter_stopped)(void);
diff --git a/android/main.c b/android/main.c
index f82e6d8..27513f8 100644
--- a/android/main.c
+++ b/android/main.c
@@ -65,6 +65,8 @@
static guint bluetooth_start_timeout = 0;
+static const bdaddr_t *adapter_bdaddr = NULL;
+
static GMainLoop *event_loop;
static GIOChannel *hal_cmd_io = NULL;
@@ -75,7 +77,6 @@ static bool services[HAL_SERVICE_ID_MAX + 1] = { false };
static void service_register(void *buf, uint16_t len)
{
struct hal_cmd_register_module *m = buf;
- const bdaddr_t *adapter_bdaddr = bt_adapter_get_address();
int sk = g_io_channel_unix_get_fd(hal_notif_io);
if (m->service_id > HAL_SERVICE_ID_MAX || services[m->service_id])
@@ -365,13 +366,15 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
return FALSE;
}
-static void adapter_ready(int err)
+static void adapter_ready(int err, const bdaddr_t *addr)
{
if (err < 0) {
error("Adapter initialization failed: %s", strerror(-err));
exit(EXIT_FAILURE);
}
+ adapter_bdaddr = addr;
+
if (bluetooth_start_timeout > 0) {
g_source_remove(bluetooth_start_timeout);
bluetooth_start_timeout = 0;
--
1.8.4.3
^ permalink raw reply related
* [PATCH v2 4/8] android/hidhost: Use adapter address provided on register
From: Szymon Janc @ 2013-11-12 23:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384300100-8941-1-git-send-email-szymon.janc@tieto.com>
There is no need to use bt_adapter_get_address every time local address
is needed.
---
android/hidhost.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index cba80a6..cf670d6 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -47,7 +47,6 @@
#include "hal-msg.h"
#include "ipc.h"
#include "hidhost.h"
-#include "adapter.h"
#include "utils.h"
#define L2CAP_PSM_HIDP_CTRL 0x11
@@ -77,6 +76,8 @@
/* HID Virtual Cable Unplug */
#define HID_VIRTUAL_CABLE_UNPLUG 0x05
+static const bdaddr_t *adapter_addr = NULL;
+
static int notification_sk = -1;
static GIOChannel *ctrl_io = NULL;
static GIOChannel *intr_io = NULL;
@@ -563,7 +564,6 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
{
struct hid_device *dev = user_data;
GError *err = NULL;
- const bdaddr_t *src = bt_adapter_get_address();
DBG("");
@@ -575,7 +575,7 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
/* Connect to the HID interrupt channel */
dev->intr_io = bt_io_connect(interrupt_connect_cb, dev, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR, src,
+ BT_IO_OPT_SOURCE_BDADDR, adapter_addr,
BT_IO_OPT_DEST_BDADDR, &dev->dst,
BT_IO_OPT_PSM, L2CAP_PSM_HIDP_INTR,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
@@ -601,7 +601,6 @@ static void hid_sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
struct hid_device *dev = data;
sdp_list_t *list;
GError *gerr = NULL;
- const bdaddr_t *src = bt_adapter_get_address();
DBG("");
@@ -675,7 +674,7 @@ static void hid_sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
}
dev->ctrl_io = bt_io_connect(control_connect_cb, dev, NULL, &gerr,
- BT_IO_OPT_SOURCE_BDADDR, src,
+ BT_IO_OPT_SOURCE_BDADDR, adapter_addr,
BT_IO_OPT_DEST_BDADDR, &dev->dst,
BT_IO_OPT_PSM, L2CAP_PSM_HIDP_CTRL,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
@@ -700,7 +699,6 @@ static uint8_t bt_hid_connect(struct hal_cmd_hidhost_connect *cmd,
char addr[18];
bdaddr_t dst;
GSList *l;
- const bdaddr_t *src = bt_adapter_get_address();
uuid_t uuid;
DBG("");
@@ -722,8 +720,8 @@ static uint8_t bt_hid_connect(struct hal_cmd_hidhost_connect *cmd,
DBG("connecting to %s", addr);
bt_string2uuid(&uuid, HID_UUID);
- if (bt_search_service(src, &dev->dst, &uuid, hid_sdp_search_cb, dev,
- NULL) < 0) {
+ if (bt_search_service(adapter_addr, &dev->dst, &uuid,
+ hid_sdp_search_cb, dev, NULL) < 0) {
error("Failed to search sdp details");
hid_device_free(dev);
return HAL_STATUS_FAILED;
@@ -1161,12 +1159,13 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
bool bt_hid_register(int sk, const bdaddr_t *addr)
{
GError *err = NULL;
- const bdaddr_t *src = bt_adapter_get_address();
DBG("");
+ adapter_addr = addr;
+
ctrl_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR, src,
+ BT_IO_OPT_SOURCE_BDADDR, adapter_addr,
BT_IO_OPT_PSM, L2CAP_PSM_HIDP_CTRL,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
@@ -1177,7 +1176,7 @@ bool bt_hid_register(int sk, const bdaddr_t *addr)
}
intr_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR, src,
+ BT_IO_OPT_SOURCE_BDADDR, adapter_addr,
BT_IO_OPT_PSM, L2CAP_PSM_HIDP_INTR,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
--
1.8.4.3
^ permalink raw reply related
* [PATCH v2 3/8] android: Don't use static pointer for storing adapter_ready callback
From: Szymon Janc @ 2013-11-12 23:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384300100-8941-1-git-send-email-szymon.janc@tieto.com>
There is no need to keep ready callback for daemon lifetime as it is
not used after reporting adapter being ready. Use mgmt library feature
for passing user data so that static pointer is not needed.
---
android/adapter.c | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 1d628c8..001059a 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -65,8 +65,6 @@ static int notification_sk = -1;
/* This list contains addresses which are asked for records */
static GSList *browse_reqs;
-static bt_adapter_ready adapter_ready = NULL;
-
static struct mgmt *mgmt_if = NULL;
static struct {
@@ -940,6 +938,7 @@ static void register_mgmt_handlers(void)
static void load_link_keys_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
+ bt_adapter_ready cb = user_data;
int err;
if (status) {
@@ -951,14 +950,14 @@ static void load_link_keys_complete(uint8_t status, uint16_t length,
DBG("status %u", status);
- adapter_ready(0);
+ cb(0);
return;
failed:
- adapter_ready(err);
+ cb(err);
}
-static void load_link_keys(GSList *keys)
+static void load_link_keys(GSList *keys, bt_adapter_ready cb)
{
struct mgmt_cp_load_link_keys *cp;
struct mgmt_link_key_info *key;
@@ -984,13 +983,13 @@ static void load_link_keys(GSList *keys)
memcpy(key, keys->data, sizeof(*key));
id = mgmt_send(mgmt_if, MGMT_OP_LOAD_LINK_KEYS, adapter.index,
- cp_size, cp, load_link_keys_complete, NULL, NULL);
+ cp_size, cp, load_link_keys_complete, cb, NULL);
g_free(cp);
if (id == 0) {
error("Failed to load link keys");
- adapter_ready(-EIO);
+ cb(-EIO);
}
}
@@ -1280,6 +1279,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
void *user_data)
{
const struct mgmt_rp_read_info *rp = param;
+ bt_adapter_ready cb = user_data;
uint32_t missing_settings, supported_settings;
int err;
@@ -1320,7 +1320,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
clear_uuids();
- load_link_keys(NULL);
+ load_link_keys(NULL, cb);
set_io_capability();
set_device_id();
@@ -1336,12 +1336,14 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
return;
failed:
- adapter_ready(err);
+ cb(err);
}
static void mgmt_index_added_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
+ bt_adapter_ready cb = user_data;
+
DBG("index %u", index);
if (adapter.index != MGMT_INDEX_NONE) {
@@ -1355,8 +1357,8 @@ static void mgmt_index_added_event(uint16_t index, uint16_t length,
}
if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
- read_info_complete, NULL, NULL) == 0) {
- adapter_ready(-EIO);
+ read_info_complete, cb, NULL) == 0) {
+ cb(-EIO);
return;
}
}
@@ -1377,6 +1379,7 @@ static void read_index_list_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_rp_read_index_list *rp = param;
+ bt_adapter_ready cb = user_data;
uint16_t num;
int i;
@@ -1412,7 +1415,7 @@ static void read_index_list_complete(uint8_t status, uint16_t length,
continue;
if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
- read_info_complete, NULL, NULL) == 0)
+ read_info_complete, cb, NULL) == 0)
goto failed;
adapter.index = index;
@@ -1422,7 +1425,7 @@ static void read_index_list_complete(uint8_t status, uint16_t length,
return;
failed:
- adapter_ready(-EIO);
+ cb(-EIO);
}
static void read_version_complete(uint8_t status, uint16_t length,
@@ -1430,6 +1433,7 @@ static void read_version_complete(uint8_t status, uint16_t length,
{
const struct mgmt_rp_read_version *rp = param;
uint8_t mgmt_version, mgmt_revision;
+ bt_adapter_ready cb = user_data;
DBG("");
@@ -1456,18 +1460,18 @@ static void read_version_complete(uint8_t status, uint16_t length,
}
mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
- mgmt_index_added_event, NULL, NULL);
+ mgmt_index_added_event, cb, NULL);
mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
mgmt_index_removed_event, NULL, NULL);
if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
- NULL, read_index_list_complete, NULL, NULL) > 0)
+ NULL, read_index_list_complete, cb, NULL) > 0)
return;
error("Failed to read controller index list");
failed:
- adapter_ready(-EIO);
+ cb(-EIO);
}
bool bt_adapter_start(int index, bt_adapter_ready cb)
@@ -1481,7 +1485,7 @@ bool bt_adapter_start(int index, bt_adapter_ready cb)
}
if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
- read_version_complete, NULL, NULL) == 0) {
+ read_version_complete, cb, NULL) == 0) {
error("Error sending READ_VERSION mgmt command");
mgmt_unref(mgmt_if);
@@ -1493,8 +1497,6 @@ bool bt_adapter_start(int index, bt_adapter_ready cb)
if (index >= 0)
option_index = index;
- adapter_ready = cb;
-
return true;
}
--
1.8.4.3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox