28 #include <linux/module.h>
32 #include <asm/unaligned.h>
42 static bool compress_src =
true;
43 static bool compress_dst =
true;
63 list_add(&s->list, &bnep_session_list);
66 static void __bnep_unlink_session(
struct bnep_session *s)
85 return bnep_send(s, &
rsp,
sizeof(
rsp));
88 #ifdef CONFIG_BT_BNEP_PROTO_FILTER
89 static inline void bnep_set_default_proto_filter(
struct bnep_session *s)
110 n = get_unaligned_be16(data);
117 BT_DBG(
"filter len %d", n);
119 #ifdef CONFIG_BT_BNEP_PROTO_FILTER
125 for (i = 0; i <
n; i++) {
126 f[
i].
start = get_unaligned_be16(data++);
127 f[
i].
end = get_unaligned_be16(data++);
129 BT_DBG(
"proto filter start %d end %d",
134 memset(f + i, 0,
sizeof(*f));
137 bnep_set_default_proto_filter(s);
149 static int bnep_ctrl_set_mcfilter(
struct bnep_session *s,
u8 *data,
int len)
156 n = get_unaligned_be16(data);
163 BT_DBG(
"filter len %d", n);
165 #ifdef CONFIG_BT_BNEP_MC_FILTER
185 BT_DBG(
"mc filter %s -> %s",
193 while (i >= 0 && ++a1[i--] == 0)
210 static int bnep_rx_control(
struct bnep_session *s,
void *data,
int len)
227 err = bnep_ctrl_set_netfilter(s, data, len);
231 err = bnep_ctrl_set_mcfilter(s, data, len);
243 bnep_send(s, pkt,
sizeof(pkt));
257 h = (
void *) skb->
data;
267 bnep_rx_control(s, skb->
data, skb->
len);
284 static u8 __bnep_rx_hlen[] = {
307 bnep_rx_control(s, skb->
data, skb->
len);
312 skb_reset_mac_header(skb);
315 if (!
skb_pull(skb, __bnep_rx_hlen[type & BNEP_TYPE_MASK]))
321 if (bnep_rx_extension(s, skb) < 0)
336 dev->
stats.rx_dropped++;
340 skb_reserve(nskb, 2);
343 switch (type & BNEP_TYPE_MASK) {
368 skb_copy_from_linear_data(skb, __skb_put(nskb, skb->
len), skb->
len);
371 dev->
stats.rx_packets++;
378 dev->
stats.rx_errors++;
383 static u8 __bnep_tx_types[] = {
408 if (compress_src && ether_addr_equal(eh->
h_dest, s->
eh.h_source))
411 if (compress_dst && ether_addr_equal(eh->
h_source, s->
eh.h_dest))
417 type = __bnep_tx_types[
type];
441 s->
dev->stats.tx_bytes += len;
442 s->
dev->stats.tx_packets++;
461 init_waitqueue_entry(&wait,
current);
471 if (!skb_linearize(skb))
472 bnep_rx_frame(s, skb);
482 if (bnep_tx_frame(s, skb))
484 netif_wake_queue(dev);
505 __bnep_unlink_session(s);
516 bdaddr_t *dst = &
bt_sk(session->
sock->sk)->dst;
524 conn = hci_conn_hash_lookup_ba(hdev,
ACL_LINK, dst);
528 return conn ? &conn->
dev :
NULL;
556 ss = __bnep_get_session(dst);
562 s = netdev_priv(dev);
577 #ifdef CONFIG_BT_BNEP_MC_FILTER
582 #ifdef CONFIG_BT_BNEP_PROTO_FILTER
584 bnep_set_default_proto_filter(s);
594 __bnep_link_session(s);
598 if (IS_ERR(s->
task)) {
602 __bnep_unlink_session(s);
603 err = PTR_ERR(s->
task);
626 s = __bnep_get_session(req->
dst);
639 memset(ci, 0,
sizeof(*ci));
657 __bnep_copy_ci(&ci, s);
664 if (++n >= req->
cnum)
682 s = __bnep_get_session(ci->
dst);
684 __bnep_copy_ci(ci, s);
692 static int __init bnep_init(
void)
696 #ifdef CONFIG_BT_BNEP_PROTO_FILTER
700 #ifdef CONFIG_BT_BNEP_MC_FILTER
706 BT_INFO(
"BNEP filters: %s", flt);
712 static void __exit bnep_exit(
void)