cregit-Linux how code gets into the kernel

Release 4.11 net/bluetooth/bnep/netdev.c

/*
   BNEP implementation for Linux Bluetooth stack (BlueZ).
   Copyright (C) 2001-2002 Inventel Systemes
   Written 2001-2002 by
        Clément Moreau <clement.moreau@inventel.fr>
        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
   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
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

   ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
   COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
   SOFTWARE IS DISCLAIMED.
*/

#include <linux/etherdevice.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; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy19100.00%1100.00%
Total19100.00%1100.00%


static int bnep_net_close(struct net_device *dev) { netif_stop_queue(dev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy19100.00%1100.00%
Total19100.00%1100.00%


static void bnep_net_set_mc_list(struct net_device *dev) { #ifdef CONFIG_BT_BNEP_MC_FILTER struct bnep_session *s = netdev_priv(dev); struct sock *sk = s->sock->sk; struct bnep_set_filter_req *r; struct sk_buff *skb; int size; BT_DBG("%s mc_count %d", dev->name, netdev_mc_count(dev)); 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; if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { 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 { struct netdev_hw_addr *ha; 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); } /* FIXME: We should group addresses here. */ i = 0; netdev_for_each_mc_addr(ha, dev) { if (i == BNEP_MAX_MULTICAST_FILTERS) break; memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN); memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN); i++; } r->len = htons(skb->len - len); } skb_queue_tail(&sk->sk_write_queue, skb); wake_up_interruptible(sk_sleep(sk)); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy31990.62%222.22%
Jiri Pirko226.25%333.33%
Eric Dumazet30.85%111.11%
Gustavo Fernando Padovan30.85%111.11%
Wang Chen30.85%111.11%
Arnaldo Carvalho de Melo20.57%111.11%
Total352100.00%9100.00%


static int bnep_net_set_mac_addr(struct net_device *dev, void *arg) { BT_DBG("%s", dev->name); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy27100.00%1100.00%
Total27100.00%1100.00%


static void bnep_net_timeout(struct net_device *dev) { BT_DBG("net_timeout"); netif_wake_queue(dev); }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy21100.00%1100.00%
Total21100.00%1100.00%

#ifdef CONFIG_BT_BNEP_MC_FILTER
static 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; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy68100.00%1100.00%
Total68100.00%1100.00%

#endif #ifdef CONFIG_BT_BNEP_PROTO_FILTER /* Determine ether protocol. Based on eth_type_trans. */
static u16 bnep_net_eth_proto(struct sk_buff *skb) { struct ethhdr *eh = (void *) skb->data; u16 proto = ntohs(eh->h_proto); if (proto >= ETH_P_802_3_MIN) return proto; if (get_unaligned((__be16 *) skb->data) == htons(0xFFFF)) return ETH_P_802_3; return ETH_P_802_2; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy5480.60%133.33%
Al Viro1217.91%133.33%
Simon Horman11.49%133.33%
Total67100.00%3100.00%


static 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; 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; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy93100.00%1100.00%
Total93100.00%1100.00%

#endif
static netdev_tx_t bnep_net_xmit(struct sk_buff *skb, struct net_device *dev) { struct bnep_session *s = netdev_priv(dev); 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); return NETDEV_TX_OK; } #endif #ifdef CONFIG_BT_BNEP_PROTO_FILTER if (bnep_net_proto_filter(skb, s)) { kfree_skb(skb); return NETDEV_TX_OK; } #endif /* * 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 * on the sk_sleep(sk). */ netif_trans_update(dev); skb_queue_tail(&sk->sk_write_queue, skb); wake_up_interruptible(sk_sleep(sk)); 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); } return NETDEV_TX_OK; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy12988.36%225.00%
Eric Dumazet42.74%112.50%
Patrick McHardy32.05%112.50%
Arnaldo Carvalho de Melo32.05%112.50%
Florian Westphal32.05%112.50%
Wang Chen32.05%112.50%
Stephen Hemminger10.68%112.50%
Total146100.00%8100.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_rx_mode = bnep_net_set_mc_list, .ndo_set_mac_address = bnep_net_set_mac_addr, .ndo_tx_timeout = bnep_net_timeout, };
void bnep_net_setup(struct net_device *dev) { eth_broadcast_addr(dev->broadcast); dev->addr_len = ETH_ALEN; ether_setup(dev); dev->min_mtu = 0; dev->max_mtu = ETH_MAX_MTU; dev->priv_flags &= ~IFF_TX_SKB_SHARING; dev->netdev_ops = &bnep_netdev_ops; dev->watchdog_timeo = HZ * 2; }

Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy3962.90%233.33%
Jarod Wilson1219.35%116.67%
Neil Horman711.29%116.67%
Stephen Hemminger34.84%116.67%
Joe Perches11.61%116.67%
Total62100.00%6100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Maksim Krasnyanskiy81886.29%314.29%
Stephen Hemminger464.85%29.52%
Jiri Pirko232.43%419.05%
Jarod Wilson121.27%14.76%
Al Viro121.27%14.76%
Eric Dumazet70.74%14.76%
Neil Horman70.74%14.76%
Wang Chen60.63%14.76%
Arnaldo Carvalho de Melo50.53%14.76%
Patrick McHardy30.32%14.76%
Florian Westphal30.32%14.76%
Gustavo Fernando Padovan30.32%14.76%
Joe Perches10.11%14.76%
Simon Horman10.11%14.76%
Jan Engelhardt10.11%14.76%
Total948100.00%21100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.