2007-02-09 22:24:33 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
BNEP implementation for Linux Bluetooth stack (BlueZ).
|
|
|
|
Copyright (C) 2001-2002 Inventel Systemes
|
|
|
|
Written 2001-2002 by
|
2007-10-20 05:21:04 +08:00
|
|
|
Clément Moreau <clement.moreau@inventel.fr>
|
2005-04-17 06:20:36 +08:00
|
|
|
David Libault <david.libault@inventel.fr>
|
|
|
|
|
|
|
|
Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License version 2 as
|
|
|
|
published by the Free Software Foundation;
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
|
|
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
|
2007-02-09 22:24:33 +08:00
|
|
|
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
2005-04-17 06:20:36 +08:00
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2007-02-09 22:24:33 +08:00
|
|
|
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
|
|
|
|
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
|
2005-04-17 06:20:36 +08:00
|
|
|
SOFTWARE IS DISCLAIMED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
|
|
|
#include <net/bluetooth/bluetooth.h>
|
|
|
|
#include <net/bluetooth/hci_core.h>
|
|
|
|
#include <net/bluetooth/l2cap.h>
|
|
|
|
|
|
|
|
#include "bnep.h"
|
|
|
|
|
|
|
|
#define BNEP_TX_QUEUE_LEN 20
|
|
|
|
|
|
|
|
static int bnep_net_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_start_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bnep_net_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bnep_net_set_mc_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BT_BNEP_MC_FILTER
|
2008-11-13 15:39:10 +08:00
|
|
|
struct bnep_session *s = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sock *sk = s->sock->sk;
|
|
|
|
struct bnep_set_filter_req *r;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int size;
|
|
|
|
|
2010-02-08 12:30:35 +08:00
|
|
|
BT_DBG("%s mc_count %d", dev->name, netdev_mc_count(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
size = sizeof(*r) + (BNEP_MAX_MULTICAST_FILTERS + 1) * ETH_ALEN * 2;
|
|
|
|
skb = alloc_skb(size, GFP_ATOMIC);
|
|
|
|
if (!skb) {
|
|
|
|
BT_ERR("%s Multicast list allocation failed", dev->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = (void *) skb->data;
|
|
|
|
__skb_put(skb, sizeof(*r));
|
|
|
|
|
|
|
|
r->type = BNEP_CONTROL;
|
|
|
|
r->ctrl = BNEP_FILTER_MULTI_ADDR_SET;
|
|
|
|
|
2007-02-09 22:24:33 +08:00
|
|
|
if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 start[ETH_ALEN] = { 0x01 };
|
|
|
|
|
|
|
|
/* Request all addresses */
|
|
|
|
memcpy(__skb_put(skb, ETH_ALEN), start, ETH_ALEN);
|
|
|
|
memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN);
|
|
|
|
r->len = htons(ETH_ALEN * 2);
|
|
|
|
} else {
|
2010-04-02 05:22:57 +08:00
|
|
|
struct netdev_hw_addr *ha;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, len = skb->len;
|
|
|
|
|
|
|
|
if (dev->flags & IFF_BROADCAST) {
|
|
|
|
memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN);
|
|
|
|
memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN);
|
2007-02-09 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* FIXME: We should group addresses here. */
|
|
|
|
|
2010-03-01 13:09:14 +08:00
|
|
|
i = 0;
|
2010-04-02 05:22:57 +08:00
|
|
|
netdev_for_each_mc_addr(ha, dev) {
|
2010-03-01 13:09:14 +08:00
|
|
|
if (i == BNEP_MAX_MULTICAST_FILTERS)
|
|
|
|
break;
|
2010-04-02 05:22:57 +08:00
|
|
|
memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN);
|
|
|
|
memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
r->len = htons(skb->len - len);
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_queue_tail(&sk->sk_write_queue, skb);
|
2010-04-20 21:03:51 +08:00
|
|
|
wake_up_interruptible(sk_sleep(sk));
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bnep_net_set_mac_addr(struct net_device *dev, void *arg)
|
|
|
|
{
|
|
|
|
BT_DBG("%s", dev->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bnep_net_timeout(struct net_device *dev)
|
|
|
|
{
|
|
|
|
BT_DBG("net_timeout");
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_BT_BNEP_MC_FILTER
|
|
|
|
static inline int bnep_net_mc_filter(struct sk_buff *skb, struct bnep_session *s)
|
|
|
|
{
|
|
|
|
struct ethhdr *eh = (void *) skb->data;
|
|
|
|
|
|
|
|
if ((eh->h_dest[0] & 1) && !test_bit(bnep_mc_hash(eh->h_dest), (ulong *) &s->mc_filter))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BT_BNEP_PROTO_FILTER
|
|
|
|
/* Determine ether protocol. Based on eth_type_trans. */
|
|
|
|
static inline u16 bnep_net_eth_proto(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ethhdr *eh = (void *) skb->data;
|
2006-11-08 16:27:36 +08:00
|
|
|
u16 proto = ntohs(eh->h_proto);
|
2007-02-09 22:24:33 +08:00
|
|
|
|
2006-11-08 16:27:36 +08:00
|
|
|
if (proto >= 1536)
|
|
|
|
return proto;
|
2007-02-09 22:24:33 +08:00
|
|
|
|
2006-11-08 16:27:36 +08:00
|
|
|
if (get_unaligned((__be16 *) skb->data) == htons(0xFFFF))
|
|
|
|
return ETH_P_802_3;
|
2007-02-09 22:24:33 +08:00
|
|
|
|
2006-11-08 16:27:36 +08:00
|
|
|
return ETH_P_802_2;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bnep_net_proto_filter(struct sk_buff *skb, struct bnep_session *s)
|
|
|
|
{
|
|
|
|
u16 proto = bnep_net_eth_proto(skb);
|
|
|
|
struct bnep_proto_filter *f = s->proto_filter;
|
|
|
|
int i;
|
2007-02-09 22:24:33 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < BNEP_MAX_PROTO_FILTERS && f[i].end; i++) {
|
|
|
|
if (proto >= f[i].start && proto <= f[i].end)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_DBG("BNEP: filtered skb %p, proto 0x%.4x", skb, proto);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-01 03:50:41 +08:00
|
|
|
static netdev_tx_t bnep_net_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:39:10 +08:00
|
|
|
struct bnep_session *s = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sock *sk = s->sock->sk;
|
|
|
|
|
|
|
|
BT_DBG("skb %p, dev %p", skb, dev);
|
|
|
|
|
|
|
|
#ifdef CONFIG_BT_BNEP_MC_FILTER
|
|
|
|
if (bnep_net_mc_filter(skb, s)) {
|
|
|
|
kfree_skb(skb);
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
2007-02-09 22:24:33 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_BT_BNEP_PROTO_FILTER
|
|
|
|
if (bnep_net_proto_filter(skb, s)) {
|
|
|
|
kfree_skb(skb);
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
2007-02-09 22:24:33 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We cannot send L2CAP packets from here as we are potentially in a bh.
|
|
|
|
* So we have to queue them and wake up session thread which is sleeping
|
2010-04-20 21:03:51 +08:00
|
|
|
* on the sk_sleep(sk).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
dev->trans_start = jiffies;
|
|
|
|
skb_queue_tail(&sk->sk_write_queue, skb);
|
2010-04-20 21:03:51 +08:00
|
|
|
wake_up_interruptible(sk_sleep(sk));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (skb_queue_len(&sk->sk_write_queue) >= BNEP_TX_QUEUE_LEN) {
|
|
|
|
BT_DBG("tx queue is full");
|
|
|
|
|
|
|
|
/* Stop queuing.
|
|
|
|
* Session thread will do netif_wake_queue() */
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
}
|
|
|
|
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-01-08 09:23:17 +08:00
|
|
|
static const struct net_device_ops bnep_netdev_ops = {
|
|
|
|
.ndo_open = bnep_net_open,
|
|
|
|
.ndo_stop = bnep_net_close,
|
|
|
|
.ndo_start_xmit = bnep_net_xmit,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_set_multicast_list = bnep_net_set_mc_list,
|
|
|
|
.ndo_set_mac_address = bnep_net_set_mac_addr,
|
|
|
|
.ndo_tx_timeout = bnep_net_timeout,
|
|
|
|
.ndo_change_mtu = eth_change_mtu,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void bnep_net_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
memset(dev->broadcast, 0xff, ETH_ALEN);
|
|
|
|
dev->addr_len = ETH_ALEN;
|
|
|
|
|
|
|
|
ether_setup(dev);
|
2009-01-08 09:23:17 +08:00
|
|
|
dev->netdev_ops = &bnep_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dev->watchdog_timeo = HZ * 2;
|
|
|
|
}
|