2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* dvb_net.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Convergence integrated media GmbH
|
|
|
|
* Ralph Metzler <ralph@convergence.de>
|
|
|
|
* Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
|
|
|
|
*
|
|
|
|
* ULE Decapsulation code:
|
|
|
|
* Copyright (C) 2003, 2004 gcs - Global Communication & Services GmbH.
|
|
|
|
* and Department of Scientific Computing
|
|
|
|
* Paris Lodron University of Salzburg.
|
|
|
|
* Hilmar Linder <hlinder@cosy.sbg.ac.at>
|
|
|
|
* and Wolfram Stering <wstering@cosy.sbg.ac.at>
|
|
|
|
*
|
2006-05-22 21:31:47 +08:00
|
|
|
* ULE Decaps according to RFC 4326.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
2016-10-28 19:31:20 +08:00
|
|
|
* To obtain the license, point your browser to
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ULE ChangeLog:
|
|
|
|
* Feb 2004: hl/ws v1: Implementing draft-fair-ipdvb-ule-01.txt
|
|
|
|
*
|
|
|
|
* Dec 2004: hl/ws v2: Implementing draft-ietf-ipdvb-ule-03.txt:
|
|
|
|
* ULE Extension header handling.
|
|
|
|
* Bugreports by Moritz Vieth and Hanno Tersteegen,
|
|
|
|
* Fraunhofer Institute for Open Communication Systems
|
|
|
|
* Competence Center for Advanced Satellite Communications.
|
|
|
|
* Bugfixes and robustness improvements.
|
|
|
|
* Filtering on dest MAC addresses, if present (D-Bit = 0)
|
2017-12-12 00:37:26 +08:00
|
|
|
* DVB_ULE_DEBUG compile-time option.
|
2006-05-22 21:31:47 +08:00
|
|
|
* Apr 2006: cp v3: Bugfixes and compliency with RFC 4326 (ULE) by
|
|
|
|
* Christian Praehauser <cpraehaus@cosy.sbg.ac.at>,
|
|
|
|
* Paris Lodron University of Salzburg.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME / TODO (dvb_net.c):
|
|
|
|
*
|
|
|
|
* Unloading does not work for 2.6.9 kernels: a refcount doesn't go to zero.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-13 17:47:54 +08:00
|
|
|
#define pr_fmt(fmt) "dvb_net: " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/dvb/net.h>
|
|
|
|
#include <linux/uio.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/crc32.h>
|
2006-02-07 16:49:14 +08:00
|
|
|
#include <linux/mutex.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-12-29 02:03:51 +08:00
|
|
|
#include <media/dvb_demux.h>
|
|
|
|
#include <media/dvb_net.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt )
|
|
|
|
{
|
|
|
|
unsigned int j;
|
|
|
|
for (j = 0; j < cnt; j++)
|
|
|
|
c = crc32_be( c, iov[j].iov_base, iov[j].iov_len );
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define DVB_NET_MULTICAST_MAX 10
|
|
|
|
|
2017-12-12 00:37:26 +08:00
|
|
|
#ifdef DVB_ULE_DEBUG
|
2017-12-12 00:37:24 +08:00
|
|
|
/*
|
2017-12-12 00:37:26 +08:00
|
|
|
* The code inside DVB_ULE_DEBUG keeps a history of the
|
2017-12-12 00:37:24 +08:00
|
|
|
* last 100 TS cells processed.
|
|
|
|
*/
|
|
|
|
static unsigned char ule_hist[100*TS_SZ] = { 0 };
|
|
|
|
static unsigned char *ule_where = ule_hist, ule_dump;
|
|
|
|
|
2015-01-29 02:05:52 +08:00
|
|
|
static void hexdump(const unsigned char *buf, unsigned short len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-01-29 02:05:52 +08:00
|
|
|
print_hex_dump_debug("", DUMP_PREFIX_OFFSET, 16, 1, buf, len, true);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct dvb_net_priv {
|
|
|
|
int in_use;
|
|
|
|
u16 pid;
|
2006-11-22 22:57:56 +08:00
|
|
|
struct net_device *net;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dvb_net *host;
|
|
|
|
struct dmx_demux *demux;
|
|
|
|
struct dmx_section_feed *secfeed;
|
|
|
|
struct dmx_section_filter *secfilter;
|
|
|
|
struct dmx_ts_feed *tsfeed;
|
|
|
|
int multi_num;
|
|
|
|
struct dmx_section_filter *multi_secfilter[DVB_NET_MULTICAST_MAX];
|
|
|
|
unsigned char multi_macs[DVB_NET_MULTICAST_MAX][6];
|
|
|
|
int rx_mode;
|
|
|
|
#define RX_MODE_UNI 0
|
|
|
|
#define RX_MODE_MULTI 1
|
|
|
|
#define RX_MODE_ALL_MULTI 2
|
|
|
|
#define RX_MODE_PROMISC 3
|
|
|
|
struct work_struct set_multicast_list_wq;
|
|
|
|
struct work_struct restart_net_feed_wq;
|
|
|
|
unsigned char feedtype; /* Either FEED_TYPE_ or FEED_TYPE_ULE */
|
|
|
|
int need_pusi; /* Set to 1, if synchronization on PUSI required. */
|
|
|
|
unsigned char tscc; /* TS continuity counter after sync on PUSI. */
|
|
|
|
struct sk_buff *ule_skb; /* ULE SNDU decodes into this buffer. */
|
|
|
|
unsigned char *ule_next_hdr; /* Pointer into skb to next ULE extension header. */
|
|
|
|
unsigned short ule_sndu_len; /* ULE SNDU length in bytes, w/o D-Bit. */
|
|
|
|
unsigned short ule_sndu_type; /* ULE SNDU type field, complete. */
|
|
|
|
unsigned char ule_sndu_type_1; /* ULE SNDU type field, if split across 2 TS cells. */
|
|
|
|
unsigned char ule_dbit; /* Whether the DestMAC address present
|
|
|
|
* or not (bit is set). */
|
|
|
|
unsigned char ule_bridged; /* Whether the ULE_BRIDGED extension header was found. */
|
|
|
|
int ule_sndu_remain; /* Nr. of bytes still required for current ULE SNDU. */
|
|
|
|
unsigned long ts_count; /* Current ts cell counter. */
|
2006-02-07 16:49:14 +08:00
|
|
|
struct mutex mutex;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Determine the packet's protocol ID. The rule here is that we
|
|
|
|
* assume 802.3 if the type field is short enough to be a length.
|
|
|
|
* This is normal practice and works for any 'now in use' protocol.
|
|
|
|
*
|
|
|
|
* stolen from eth.c out of the linux kernel, hacked for dvb-device
|
|
|
|
* by Michael Holzt <kju@debian.org>
|
|
|
|
*/
|
2008-05-21 11:31:11 +08:00
|
|
|
static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ethhdr *eth;
|
|
|
|
unsigned char *rawp;
|
|
|
|
|
2007-03-20 06:33:04 +08:00
|
|
|
skb_reset_mac_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb_pull(skb,dev->hard_header_len);
|
|
|
|
eth = eth_hdr(skb);
|
|
|
|
|
|
|
|
if (*eth->h_dest & 1) {
|
2013-12-26 19:41:10 +08:00
|
|
|
if(ether_addr_equal(eth->h_dest,dev->broadcast))
|
2005-04-17 06:20:36 +08:00
|
|
|
skb->pkt_type=PACKET_BROADCAST;
|
|
|
|
else
|
|
|
|
skb->pkt_type=PACKET_MULTICAST;
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:38:25 +08:00
|
|
|
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
|
2005-04-17 06:20:36 +08:00
|
|
|
return eth->h_proto;
|
|
|
|
|
|
|
|
rawp = skb->data;
|
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This is a magic hack to spot IPX packets. Older Novell breaks
|
|
|
|
* the protocol design and runs IPX over 802.3 without an 802.2 LLC
|
|
|
|
* layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
|
|
|
|
* won't work for fault tolerant netware but does for the rest.
|
|
|
|
*/
|
|
|
|
if (*(unsigned short *)rawp == 0xFFFF)
|
|
|
|
return htons(ETH_P_802_3);
|
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Real 802.2 LLC
|
|
|
|
*/
|
|
|
|
return htons(ETH_P_802_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TS_SZ 188
|
|
|
|
#define TS_SYNC 0x47
|
|
|
|
#define TS_TEI 0x80
|
|
|
|
#define TS_SC 0xC0
|
|
|
|
#define TS_PUSI 0x40
|
|
|
|
#define TS_AF_A 0x20
|
|
|
|
#define TS_AF_D 0x10
|
|
|
|
|
|
|
|
/* ULE Extension Header handlers. */
|
|
|
|
|
|
|
|
#define ULE_TEST 0
|
|
|
|
#define ULE_BRIDGED 1
|
|
|
|
|
2006-05-22 21:31:47 +08:00
|
|
|
#define ULE_OPTEXTHDR_PADDING 0
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int ule_test_sndu( struct dvb_net_priv *p )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ule_bridged_sndu( struct dvb_net_priv *p )
|
|
|
|
{
|
2006-05-22 21:31:47 +08:00
|
|
|
struct ethhdr *hdr = (struct ethhdr*) p->ule_next_hdr;
|
2013-03-28 12:38:25 +08:00
|
|
|
if(ntohs(hdr->h_proto) < ETH_P_802_3_MIN) {
|
2006-05-22 21:31:47 +08:00
|
|
|
int framelen = p->ule_sndu_len - ((p->ule_next_hdr+sizeof(struct ethhdr)) - p->ule_skb->data);
|
2013-03-28 12:38:25 +08:00
|
|
|
/* A frame Type < ETH_P_802_3_MIN for a bridged frame, introduces a LLC Length field. */
|
2006-05-22 21:31:47 +08:00
|
|
|
if(framelen != ntohs(hdr->h_proto)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Note:
|
|
|
|
* From RFC4326:
|
|
|
|
* "A bridged SNDU is a Mandatory Extension Header of Type 1.
|
|
|
|
* It must be the final (or only) extension header specified in the header chain of a SNDU."
|
|
|
|
* The 'ule_bridged' flag will cause the extension header processing loop to terminate.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
p->ule_bridged = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-22 21:31:47 +08:00
|
|
|
static int ule_exthdr_padding(struct dvb_net_priv *p)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/*
|
|
|
|
* Handle ULE extension headers.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Function is called after a successful CRC32 verification of an ULE SNDU to complete its decoding.
|
|
|
|
* Returns: >= 0: nr. of bytes consumed by next extension header
|
|
|
|
* -1: Mandatory extension header that is not recognized or TEST SNDU; discard.
|
|
|
|
*/
|
|
|
|
static int handle_one_ule_extension( struct dvb_net_priv *p )
|
|
|
|
{
|
|
|
|
/* Table of mandatory extension header handlers. The header type is the index. */
|
|
|
|
static int (*ule_mandatory_ext_handlers[255])( struct dvb_net_priv *p ) =
|
|
|
|
{ [0] = ule_test_sndu, [1] = ule_bridged_sndu, [2] = NULL, };
|
|
|
|
|
|
|
|
/* Table of optional extension header handlers. The header type is the index. */
|
2006-05-22 21:31:47 +08:00
|
|
|
static int (*ule_optional_ext_handlers[255])( struct dvb_net_priv *p ) =
|
|
|
|
{ [0] = ule_exthdr_padding, [1] = NULL, };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int ext_len = 0;
|
|
|
|
unsigned char hlen = (p->ule_sndu_type & 0x0700) >> 8;
|
|
|
|
unsigned char htype = p->ule_sndu_type & 0x00FF;
|
|
|
|
|
|
|
|
/* Discriminate mandatory and optional extension headers. */
|
|
|
|
if (hlen == 0) {
|
|
|
|
/* Mandatory extension header */
|
|
|
|
if (ule_mandatory_ext_handlers[htype]) {
|
|
|
|
ext_len = ule_mandatory_ext_handlers[htype]( p );
|
2006-05-22 21:31:47 +08:00
|
|
|
if(ext_len >= 0) {
|
|
|
|
p->ule_next_hdr += ext_len;
|
|
|
|
if (!p->ule_bridged) {
|
2008-05-21 11:31:11 +08:00
|
|
|
p->ule_sndu_type = ntohs(*(__be16 *)p->ule_next_hdr);
|
2006-05-22 21:31:47 +08:00
|
|
|
p->ule_next_hdr += 2;
|
|
|
|
} else {
|
2008-05-21 11:31:11 +08:00
|
|
|
p->ule_sndu_type = ntohs(*(__be16 *)(p->ule_next_hdr + ((p->ule_dbit ? 2 : 3) * ETH_ALEN)));
|
2006-05-22 21:31:47 +08:00
|
|
|
/* This assures the extension handling loop will terminate. */
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-05-22 21:31:47 +08:00
|
|
|
// else: extension handler failed or SNDU should be discarded
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
|
|
|
ext_len = -1; /* SNDU has to be discarded. */
|
|
|
|
} else {
|
|
|
|
/* Optional extension header. Calculate the length. */
|
2006-05-22 21:31:47 +08:00
|
|
|
ext_len = hlen << 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Process the optional extension header according to its type. */
|
|
|
|
if (ule_optional_ext_handlers[htype])
|
|
|
|
(void)ule_optional_ext_handlers[htype]( p );
|
|
|
|
p->ule_next_hdr += ext_len;
|
2008-05-21 11:31:11 +08:00
|
|
|
p->ule_sndu_type = ntohs( *(__be16 *)(p->ule_next_hdr-2) );
|
2006-05-22 21:31:47 +08:00
|
|
|
/*
|
|
|
|
* note: the length of the next header type is included in the
|
|
|
|
* length of THIS optional extension header
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ext_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_ule_extensions( struct dvb_net_priv *p )
|
|
|
|
{
|
|
|
|
int total_ext_len = 0, l;
|
|
|
|
|
|
|
|
p->ule_next_hdr = p->ule_skb->data;
|
|
|
|
do {
|
|
|
|
l = handle_one_ule_extension( p );
|
2006-05-22 21:31:47 +08:00
|
|
|
if (l < 0)
|
|
|
|
return l; /* Stop extension header processing and discard SNDU. */
|
2005-04-17 06:20:36 +08:00
|
|
|
total_ext_len += l;
|
2015-01-29 02:05:51 +08:00
|
|
|
pr_debug("ule_next_hdr=%p, ule_sndu_type=%i, l=%i, total_ext_len=%i\n",
|
|
|
|
p->ule_next_hdr, (int)p->ule_sndu_type,
|
|
|
|
l, total_ext_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-03-28 12:38:25 +08:00
|
|
|
} while (p->ule_sndu_type < ETH_P_802_3_MIN);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return total_ext_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/* Prepare for a new ULE SNDU: reset the decoder state. */
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline void reset_ule( struct dvb_net_priv *p )
|
|
|
|
{
|
|
|
|
p->ule_skb = NULL;
|
|
|
|
p->ule_next_hdr = NULL;
|
|
|
|
p->ule_sndu_len = 0;
|
|
|
|
p->ule_sndu_type = 0;
|
|
|
|
p->ule_sndu_type_1 = 0;
|
|
|
|
p->ule_sndu_remain = 0;
|
|
|
|
p->ule_dbit = 0xFF;
|
|
|
|
p->ule_bridged = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Decode ULE SNDUs according to draft-ietf-ipdvb-ule-03.txt from a sequence of
|
|
|
|
* TS cells of a single PID.
|
|
|
|
*/
|
|
|
|
|
2016-11-19 22:56:58 +08:00
|
|
|
struct dvb_net_ule_handle {
|
|
|
|
struct net_device *dev;
|
|
|
|
struct dvb_net_priv *priv;
|
|
|
|
struct ethhdr *ethh;
|
|
|
|
const u8 *buf;
|
|
|
|
size_t buf_len;
|
|
|
|
unsigned long skipped;
|
|
|
|
const u8 *ts, *ts_end, *from_where;
|
|
|
|
u8 ts_remain, how_much, new_ts;
|
|
|
|
bool error;
|
|
|
|
};
|
|
|
|
|
2016-11-19 22:56:59 +08:00
|
|
|
static int dvb_net_ule_new_ts_cell(struct dvb_net_ule_handle *h)
|
|
|
|
{
|
|
|
|
/* We are about to process a new TS cell. */
|
|
|
|
|
2017-12-12 00:37:26 +08:00
|
|
|
#ifdef DVB_ULE_DEBUG
|
2017-12-12 00:37:24 +08:00
|
|
|
if (ule_where >= &ule_hist[100*TS_SZ])
|
|
|
|
ule_where = ule_hist;
|
|
|
|
memcpy(ule_where, h->ts, TS_SZ);
|
|
|
|
if (ule_dump) {
|
|
|
|
hexdump(ule_where, TS_SZ);
|
|
|
|
ule_dump = 0;
|
2016-11-19 22:56:59 +08:00
|
|
|
}
|
2017-12-12 00:37:24 +08:00
|
|
|
ule_where += TS_SZ;
|
2016-11-19 22:56:59 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check TS h->error conditions: sync_byte, transport_error_indicator,
|
|
|
|
* scrambling_control .
|
|
|
|
*/
|
|
|
|
if ((h->ts[0] != TS_SYNC) || (h->ts[1] & TS_TEI) ||
|
|
|
|
((h->ts[3] & TS_SC) != 0)) {
|
|
|
|
pr_warn("%lu: Invalid TS cell: SYNC %#x, TEI %u, SC %#x.\n",
|
|
|
|
h->priv->ts_count, h->ts[0],
|
|
|
|
(h->ts[1] & TS_TEI) >> 7,
|
|
|
|
(h->ts[3] & TS_SC) >> 6);
|
|
|
|
|
|
|
|
/* Drop partly decoded SNDU, reset state, resync on PUSI. */
|
|
|
|
if (h->priv->ule_skb) {
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
/* Prepare for next SNDU. */
|
|
|
|
h->dev->stats.rx_errors++;
|
|
|
|
h->dev->stats.rx_frame_errors++;
|
|
|
|
}
|
|
|
|
reset_ule(h->priv);
|
|
|
|
h->priv->need_pusi = 1;
|
|
|
|
|
|
|
|
/* Continue with next TS cell. */
|
|
|
|
h->ts += TS_SZ;
|
|
|
|
h->priv->ts_count++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
h->ts_remain = 184;
|
|
|
|
h->from_where = h->ts + 4;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_ule_ts_pusi(struct dvb_net_ule_handle *h)
|
|
|
|
{
|
|
|
|
if (h->ts[1] & TS_PUSI) {
|
|
|
|
/* Find beginning of first ULE SNDU in current TS cell. */
|
|
|
|
/* Synchronize continuity counter. */
|
|
|
|
h->priv->tscc = h->ts[3] & 0x0F;
|
|
|
|
/* There is a pointer field here. */
|
|
|
|
if (h->ts[4] > h->ts_remain) {
|
|
|
|
pr_err("%lu: Invalid ULE packet (pointer field %d)\n",
|
|
|
|
h->priv->ts_count, h->ts[4]);
|
|
|
|
h->ts += TS_SZ;
|
|
|
|
h->priv->ts_count++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Skip to destination of pointer field. */
|
|
|
|
h->from_where = &h->ts[5] + h->ts[4];
|
|
|
|
h->ts_remain -= 1 + h->ts[4];
|
|
|
|
h->skipped = 0;
|
|
|
|
} else {
|
|
|
|
h->skipped++;
|
|
|
|
h->ts += TS_SZ;
|
|
|
|
h->priv->ts_count++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_ule_new_ts(struct dvb_net_ule_handle *h)
|
|
|
|
{
|
|
|
|
/* Check continuity counter. */
|
|
|
|
if ((h->ts[3] & 0x0F) == h->priv->tscc)
|
|
|
|
h->priv->tscc = (h->priv->tscc + 1) & 0x0F;
|
|
|
|
else {
|
|
|
|
/* TS discontinuity handling: */
|
|
|
|
pr_warn("%lu: TS discontinuity: got %#x, expected %#x.\n",
|
|
|
|
h->priv->ts_count, h->ts[3] & 0x0F,
|
|
|
|
h->priv->tscc);
|
|
|
|
/* Drop partly decoded SNDU, reset state, resync on PUSI. */
|
|
|
|
if (h->priv->ule_skb) {
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
/* Prepare for next SNDU. */
|
|
|
|
// reset_ule(h->priv); moved to below.
|
|
|
|
h->dev->stats.rx_errors++;
|
|
|
|
h->dev->stats.rx_frame_errors++;
|
|
|
|
}
|
|
|
|
reset_ule(h->priv);
|
|
|
|
/* skip to next PUSI. */
|
|
|
|
h->priv->need_pusi = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we still have an incomplete payload, but PUSI is
|
|
|
|
* set; some TS cells are missing.
|
|
|
|
* This is only possible here, if we missed exactly 16 TS
|
|
|
|
* cells (continuity counter wrap).
|
|
|
|
*/
|
|
|
|
if (h->ts[1] & TS_PUSI) {
|
|
|
|
if (!h->priv->need_pusi) {
|
|
|
|
if (!(*h->from_where < (h->ts_remain-1)) ||
|
|
|
|
*h->from_where != h->priv->ule_sndu_remain) {
|
|
|
|
/*
|
|
|
|
* Pointer field is invalid.
|
|
|
|
* Drop this TS cell and any started ULE SNDU.
|
|
|
|
*/
|
|
|
|
pr_warn("%lu: Invalid pointer field: %u.\n",
|
|
|
|
h->priv->ts_count,
|
|
|
|
*h->from_where);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop partly decoded SNDU, reset state,
|
|
|
|
* resync on PUSI.
|
|
|
|
*/
|
|
|
|
if (h->priv->ule_skb) {
|
|
|
|
h->error = true;
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->error || h->priv->ule_sndu_remain) {
|
|
|
|
h->dev->stats.rx_errors++;
|
|
|
|
h->dev->stats.rx_frame_errors++;
|
|
|
|
h->error = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_ule(h->priv);
|
|
|
|
h->priv->need_pusi = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Skip pointer field (we're processing a
|
|
|
|
* packed payload).
|
|
|
|
*/
|
|
|
|
h->from_where += 1;
|
|
|
|
h->ts_remain -= 1;
|
|
|
|
} else
|
|
|
|
h->priv->need_pusi = 0;
|
|
|
|
|
|
|
|
if (h->priv->ule_sndu_remain > 183) {
|
|
|
|
/*
|
|
|
|
* Current SNDU lacks more data than there
|
|
|
|
* could be available in the current TS cell.
|
|
|
|
*/
|
|
|
|
h->dev->stats.rx_errors++;
|
|
|
|
h->dev->stats.rx_length_errors++;
|
|
|
|
pr_warn("%lu: Expected %d more SNDU bytes, but got PUSI (pf %d, h->ts_remain %d). Flushing incomplete payload.\n",
|
|
|
|
h->priv->ts_count,
|
|
|
|
h->priv->ule_sndu_remain,
|
|
|
|
h->ts[4], h->ts_remain);
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
/* Prepare for next SNDU. */
|
|
|
|
reset_ule(h->priv);
|
|
|
|
/*
|
|
|
|
* Resync: go to where pointer field points to:
|
|
|
|
* start of next ULE SNDU.
|
|
|
|
*/
|
|
|
|
h->from_where += h->ts[4];
|
|
|
|
h->ts_remain -= h->ts[4];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start a new payload with skb.
|
|
|
|
* Find ULE header. It is only guaranteed that the
|
|
|
|
* length field (2 bytes) is contained in the current
|
|
|
|
* TS.
|
|
|
|
* Check h.ts_remain has to be >= 2 here.
|
|
|
|
*/
|
|
|
|
static int dvb_net_ule_new_payload(struct dvb_net_ule_handle *h)
|
|
|
|
{
|
|
|
|
if (h->ts_remain < 2) {
|
|
|
|
pr_warn("Invalid payload packing: only %d bytes left in TS. Resyncing.\n",
|
|
|
|
h->ts_remain);
|
|
|
|
h->priv->ule_sndu_len = 0;
|
|
|
|
h->priv->need_pusi = 1;
|
|
|
|
h->ts += TS_SZ;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!h->priv->ule_sndu_len) {
|
|
|
|
/* Got at least two bytes, thus extrace the SNDU length. */
|
|
|
|
h->priv->ule_sndu_len = h->from_where[0] << 8 |
|
|
|
|
h->from_where[1];
|
|
|
|
if (h->priv->ule_sndu_len & 0x8000) {
|
|
|
|
/* D-Bit is set: no dest mac present. */
|
|
|
|
h->priv->ule_sndu_len &= 0x7FFF;
|
|
|
|
h->priv->ule_dbit = 1;
|
|
|
|
} else
|
|
|
|
h->priv->ule_dbit = 0;
|
|
|
|
|
|
|
|
if (h->priv->ule_sndu_len < 5) {
|
|
|
|
pr_warn("%lu: Invalid ULE SNDU length %u. Resyncing.\n",
|
|
|
|
h->priv->ts_count,
|
|
|
|
h->priv->ule_sndu_len);
|
|
|
|
h->dev->stats.rx_errors++;
|
|
|
|
h->dev->stats.rx_length_errors++;
|
|
|
|
h->priv->ule_sndu_len = 0;
|
|
|
|
h->priv->need_pusi = 1;
|
|
|
|
h->new_ts = 1;
|
|
|
|
h->ts += TS_SZ;
|
|
|
|
h->priv->ts_count++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
h->ts_remain -= 2; /* consume the 2 bytes SNDU length. */
|
|
|
|
h->from_where += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
h->priv->ule_sndu_remain = h->priv->ule_sndu_len + 2;
|
|
|
|
/*
|
|
|
|
* State of current TS:
|
|
|
|
* h->ts_remain (remaining bytes in the current TS cell)
|
|
|
|
* 0 ule_type is not available now, we need the next TS cell
|
|
|
|
* 1 the first byte of the ule_type is present
|
|
|
|
* >=2 full ULE header present, maybe some payload data as well.
|
|
|
|
*/
|
|
|
|
switch (h->ts_remain) {
|
|
|
|
case 1:
|
|
|
|
h->priv->ule_sndu_remain--;
|
|
|
|
h->priv->ule_sndu_type = h->from_where[0] << 8;
|
|
|
|
|
|
|
|
/* first byte of ule_type is set. */
|
|
|
|
h->priv->ule_sndu_type_1 = 1;
|
|
|
|
h->ts_remain -= 1;
|
|
|
|
h->from_where += 1;
|
|
|
|
/* fallthrough */
|
|
|
|
case 0:
|
|
|
|
h->new_ts = 1;
|
|
|
|
h->ts += TS_SZ;
|
|
|
|
h->priv->ts_count++;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default: /* complete ULE header is present in current TS. */
|
|
|
|
/* Extract ULE type field. */
|
|
|
|
if (h->priv->ule_sndu_type_1) {
|
|
|
|
h->priv->ule_sndu_type_1 = 0;
|
|
|
|
h->priv->ule_sndu_type |= h->from_where[0];
|
|
|
|
h->from_where += 1; /* points to payload start. */
|
|
|
|
h->ts_remain -= 1;
|
|
|
|
} else {
|
|
|
|
/* Complete type is present in new TS. */
|
|
|
|
h->priv->ule_sndu_type = h->from_where[0] << 8 |
|
|
|
|
h->from_where[1];
|
|
|
|
h->from_where += 2; /* points to payload start. */
|
|
|
|
h->ts_remain -= 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the skb (decoder target buffer) with the correct size,
|
|
|
|
* as follows:
|
|
|
|
*
|
|
|
|
* prepare for the largest case: bridged SNDU with MAC address
|
|
|
|
* (dbit = 0).
|
|
|
|
*/
|
|
|
|
h->priv->ule_skb = dev_alloc_skb(h->priv->ule_sndu_len +
|
|
|
|
ETH_HLEN + ETH_ALEN);
|
|
|
|
if (!h->priv->ule_skb) {
|
|
|
|
pr_notice("%s: Memory squeeze, dropping packet.\n",
|
|
|
|
h->dev->name);
|
|
|
|
h->dev->stats.rx_dropped++;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This includes the CRC32 _and_ dest mac, if !dbit. */
|
|
|
|
h->priv->ule_sndu_remain = h->priv->ule_sndu_len;
|
|
|
|
h->priv->ule_skb->dev = h->dev;
|
|
|
|
/*
|
|
|
|
* Leave space for Ethernet or bridged SNDU header
|
|
|
|
* (eth hdr plus one MAC addr).
|
|
|
|
*/
|
|
|
|
skb_reserve(h->priv->ule_skb, ETH_HLEN + ETH_ALEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dvb_net_ule_should_drop(struct dvb_net_ule_handle *h)
|
|
|
|
{
|
|
|
|
static const u8 bc_addr[ETH_ALEN] = { [0 ... ETH_ALEN - 1] = 0xff };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The destination MAC address is the next data in the skb. It comes
|
|
|
|
* before any extension headers.
|
|
|
|
*
|
|
|
|
* Check if the payload of this SNDU should be passed up the stack.
|
|
|
|
*/
|
|
|
|
if (h->priv->rx_mode == RX_MODE_PROMISC)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (h->priv->ule_skb->data[0] & 0x01) {
|
|
|
|
/* multicast or broadcast */
|
|
|
|
if (!ether_addr_equal(h->priv->ule_skb->data, bc_addr)) {
|
|
|
|
/* multicast */
|
|
|
|
if (h->priv->rx_mode == RX_MODE_MULTI) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < h->priv->multi_num &&
|
|
|
|
!ether_addr_equal(h->priv->ule_skb->data,
|
|
|
|
h->priv->multi_macs[i]);
|
|
|
|
i++)
|
|
|
|
;
|
|
|
|
if (i == h->priv->multi_num)
|
|
|
|
return 1;
|
|
|
|
} else if (h->priv->rx_mode != RX_MODE_ALL_MULTI)
|
|
|
|
return 1; /* no broadcast; */
|
|
|
|
/*
|
|
|
|
* else:
|
|
|
|
* all multicast mode: accept all multicast packets
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/* else: broadcast */
|
|
|
|
} else if (!ether_addr_equal(h->priv->ule_skb->data, h->dev->dev_addr))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void dvb_net_ule_check_crc(struct dvb_net_ule_handle *h,
|
2017-12-12 00:37:24 +08:00
|
|
|
struct kvec iov[3],
|
2016-11-19 22:56:59 +08:00
|
|
|
u32 ule_crc, u32 expected_crc)
|
|
|
|
{
|
|
|
|
u8 dest_addr[ETH_ALEN];
|
|
|
|
|
|
|
|
if (ule_crc != expected_crc) {
|
|
|
|
pr_warn("%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
|
|
|
|
h->priv->ts_count, ule_crc, expected_crc,
|
|
|
|
h->priv->ule_sndu_len, h->priv->ule_sndu_type,
|
|
|
|
h->ts_remain,
|
|
|
|
h->ts_remain > 2 ?
|
|
|
|
*(unsigned short *)h->from_where : 0);
|
|
|
|
|
2017-12-12 00:37:26 +08:00
|
|
|
#ifdef DVB_ULE_DEBUG
|
2016-11-19 22:56:59 +08:00
|
|
|
hexdump(iov[0].iov_base, iov[0].iov_len);
|
|
|
|
hexdump(iov[1].iov_base, iov[1].iov_len);
|
|
|
|
hexdump(iov[2].iov_base, iov[2].iov_len);
|
|
|
|
|
2017-12-12 00:37:24 +08:00
|
|
|
if (ule_where == ule_hist) {
|
|
|
|
hexdump(&ule_hist[98*TS_SZ], TS_SZ);
|
|
|
|
hexdump(&ule_hist[99*TS_SZ], TS_SZ);
|
|
|
|
} else if (ule_where == &ule_hist[TS_SZ]) {
|
|
|
|
hexdump(&ule_hist[99*TS_SZ], TS_SZ);
|
|
|
|
hexdump(ule_hist, TS_SZ);
|
2016-11-19 22:56:59 +08:00
|
|
|
} else {
|
2017-12-12 00:37:24 +08:00
|
|
|
hexdump(ule_where - TS_SZ - TS_SZ, TS_SZ);
|
|
|
|
hexdump(ule_where - TS_SZ, TS_SZ);
|
2016-11-19 22:56:59 +08:00
|
|
|
}
|
2017-12-12 00:37:24 +08:00
|
|
|
ule_dump = 1;
|
2016-11-19 22:56:59 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
h->dev->stats.rx_errors++;
|
|
|
|
h->dev->stats.rx_crc_errors++;
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CRC32 verified OK. */
|
|
|
|
|
|
|
|
/* CRC32 was OK, so remove it from skb. */
|
|
|
|
h->priv->ule_skb->tail -= 4;
|
|
|
|
h->priv->ule_skb->len -= 4;
|
|
|
|
|
|
|
|
if (!h->priv->ule_dbit) {
|
|
|
|
if (dvb_net_ule_should_drop(h)) {
|
|
|
|
netdev_dbg(h->dev,
|
|
|
|
"Dropping SNDU: MAC destination address does not match: dest addr: %pM, h->dev addr: %pM\n",
|
|
|
|
h->priv->ule_skb->data, h->dev->dev_addr);
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_copy_from_linear_data(h->priv->ule_skb, dest_addr,
|
|
|
|
ETH_ALEN);
|
|
|
|
skb_pull(h->priv->ule_skb, ETH_ALEN);
|
2016-12-09 19:36:29 +08:00
|
|
|
} else {
|
|
|
|
/* dest_addr buffer is only valid if h->priv->ule_dbit == 0 */
|
|
|
|
eth_zero_addr(dest_addr);
|
2016-11-19 22:56:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle ULE Extension Headers. */
|
|
|
|
if (h->priv->ule_sndu_type < ETH_P_802_3_MIN) {
|
|
|
|
/* There is an extension header. Handle it accordingly. */
|
|
|
|
int l = handle_ule_extensions(h->priv);
|
|
|
|
|
|
|
|
if (l < 0) {
|
|
|
|
/*
|
|
|
|
* Mandatory extension header unknown or TEST SNDU.
|
|
|
|
* Drop it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// pr_warn("Dropping SNDU, extension headers.\n" );
|
|
|
|
dev_kfree_skb(h->priv->ule_skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
skb_pull(h->priv->ule_skb, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct/assure correct ethernet header.
|
|
|
|
* Note: in bridged mode (h->priv->ule_bridged != 0)
|
|
|
|
* we already have the (original) ethernet
|
|
|
|
* header at the start of the payload (after
|
|
|
|
* optional dest. address and any extension
|
|
|
|
* headers).
|
|
|
|
*/
|
|
|
|
if (!h->priv->ule_bridged) {
|
|
|
|
skb_push(h->priv->ule_skb, ETH_HLEN);
|
|
|
|
h->ethh = (struct ethhdr *)h->priv->ule_skb->data;
|
2016-12-09 19:36:29 +08:00
|
|
|
memcpy(h->ethh->h_dest, dest_addr, ETH_ALEN);
|
|
|
|
eth_zero_addr(h->ethh->h_source);
|
2016-11-19 22:56:59 +08:00
|
|
|
h->ethh->h_proto = htons(h->priv->ule_sndu_type);
|
|
|
|
}
|
|
|
|
/* else: skb is in correct state; nothing to do. */
|
|
|
|
h->priv->ule_bridged = 0;
|
|
|
|
|
|
|
|
/* Stuff into kernel's protocol stack. */
|
|
|
|
h->priv->ule_skb->protocol = dvb_net_eth_type_trans(h->priv->ule_skb,
|
|
|
|
h->dev);
|
|
|
|
/*
|
|
|
|
* If D-bit is set (i.e. destination MAC address not present),
|
|
|
|
* receive the packet anyhow.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
if (h->priv->ule_dbit && skb->pkt_type == PACKET_OTHERHOST)
|
|
|
|
h->priv->ule_skb->pkt_type = PACKET_HOST;
|
|
|
|
#endif
|
|
|
|
h->dev->stats.rx_packets++;
|
|
|
|
h->dev->stats.rx_bytes += h->priv->ule_skb->len;
|
|
|
|
netif_rx(h->priv->ule_skb);
|
|
|
|
}
|
|
|
|
|
2016-11-19 22:56:58 +08:00
|
|
|
static void dvb_net_ule(struct net_device *dev, const u8 *buf, size_t buf_len)
|
|
|
|
{
|
2016-11-19 22:56:59 +08:00
|
|
|
int ret;
|
2016-11-19 22:56:58 +08:00
|
|
|
struct dvb_net_ule_handle h = {
|
|
|
|
.dev = dev,
|
2017-12-12 00:37:24 +08:00
|
|
|
.priv = netdev_priv(dev),
|
|
|
|
.ethh = NULL,
|
2016-11-19 22:56:58 +08:00
|
|
|
.buf = buf,
|
|
|
|
.buf_len = buf_len,
|
|
|
|
.skipped = 0L,
|
|
|
|
.ts = NULL,
|
|
|
|
.ts_end = NULL,
|
|
|
|
.from_where = NULL,
|
|
|
|
.ts_remain = 0,
|
|
|
|
.how_much = 0,
|
|
|
|
.new_ts = 1,
|
|
|
|
.error = false,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-11-19 22:56:59 +08:00
|
|
|
/*
|
|
|
|
* For all TS cells in current buffer.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Appearently, we are called for every single TS cell.
|
|
|
|
*/
|
2016-11-19 22:56:59 +08:00
|
|
|
for (h.ts = h.buf, h.ts_end = h.buf + h.buf_len;
|
|
|
|
h.ts < h.ts_end; /* no incr. */) {
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.new_ts) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* We are about to process a new TS cell. */
|
2016-11-19 22:56:59 +08:00
|
|
|
if (dvb_net_ule_new_ts_cell(&h))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2016-11-19 22:56:59 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Synchronize on PUSI, if required. */
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.priv->need_pusi) {
|
2016-11-19 22:56:59 +08:00
|
|
|
if (dvb_net_ule_ts_pusi(&h))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.new_ts) {
|
2016-11-19 22:56:59 +08:00
|
|
|
if (dvb_net_ule_new_ts(&h))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if new payload needs to be started. */
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.priv->ule_skb == NULL) {
|
2016-11-19 22:56:59 +08:00
|
|
|
ret = dvb_net_ule_new_payload(&h);
|
|
|
|
if (ret < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2016-11-19 22:56:59 +08:00
|
|
|
if (ret)
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy data into our current skb. */
|
2016-11-19 22:56:58 +08:00
|
|
|
h.how_much = min(h.priv->ule_sndu_remain, (int)h.ts_remain);
|
networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.
An spatch similar to the one for skb_put_zero() converts many
of the places using it:
@@
identifier p, p2;
expression len, skb, data;
type t, t2;
@@
(
-p = skb_put(skb, len);
+p = skb_put_data(skb, data, len);
|
-p = (t)skb_put(skb, len);
+p = skb_put_data(skb, data, len);
)
(
p2 = (t2)p;
-memcpy(p2, data, len);
|
-memcpy(p, data, len);
)
@@
type t, t2;
identifier p, p2;
expression skb, data;
@@
t *p;
...
(
-p = skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
|
-p = (t *)skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
)
(
p2 = (t2)p;
-memcpy(p2, data, sizeof(*p));
|
-memcpy(p, data, sizeof(*p));
)
@@
expression skb, len, data;
@@
-memcpy(skb_put(skb, len), data, len);
+skb_put_data(skb, data, len);
(again, manually post-processed to retain some comments)
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:20 +08:00
|
|
|
skb_put_data(h.priv->ule_skb, h.from_where, h.how_much);
|
2016-11-19 22:56:58 +08:00
|
|
|
h.priv->ule_sndu_remain -= h.how_much;
|
|
|
|
h.ts_remain -= h.how_much;
|
|
|
|
h.from_where += h.how_much;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Check for complete payload. */
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.priv->ule_sndu_remain <= 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Check CRC32, we've got it in our skb already. */
|
2016-11-19 22:56:58 +08:00
|
|
|
__be16 ulen = htons(h.priv->ule_sndu_len);
|
|
|
|
__be16 utype = htons(h.priv->ule_sndu_type);
|
2007-04-20 11:29:13 +08:00
|
|
|
const u8 *tail;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct kvec iov[3] = {
|
|
|
|
{ &ulen, sizeof ulen },
|
|
|
|
{ &utype, sizeof utype },
|
2016-11-19 22:56:59 +08:00
|
|
|
{ h.priv->ule_skb->data,
|
|
|
|
h.priv->ule_skb->len - 4 }
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2006-12-15 00:51:44 +08:00
|
|
|
u32 ule_crc = ~0L, expected_crc;
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.priv->ule_dbit) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Set D-bit for CRC32 verification,
|
|
|
|
* if it was set originally. */
|
2008-06-23 01:20:49 +08:00
|
|
|
ulen |= htons(0x8000);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ule_crc = iov_crc32(ule_crc, iov, 3);
|
2016-11-19 22:56:58 +08:00
|
|
|
tail = skb_tail_pointer(h.priv->ule_skb);
|
2007-04-20 11:29:13 +08:00
|
|
|
expected_crc = *(tail - 4) << 24 |
|
|
|
|
*(tail - 3) << 16 |
|
|
|
|
*(tail - 2) << 8 |
|
|
|
|
*(tail - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-12-12 00:37:24 +08:00
|
|
|
dvb_net_ule_check_crc(&h, iov, ule_crc, expected_crc);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Prepare for next SNDU. */
|
2016-11-19 22:56:58 +08:00
|
|
|
reset_ule(h.priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* More data in current TS (look at the bytes following the CRC32)? */
|
2016-11-19 22:56:58 +08:00
|
|
|
if (h.ts_remain >= 2 && *((unsigned short *)h.from_where) != 0xFFFF) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Next ULE SNDU starts right there. */
|
2016-11-19 22:56:58 +08:00
|
|
|
h.new_ts = 0;
|
|
|
|
h.priv->ule_skb = NULL;
|
|
|
|
h.priv->ule_sndu_type_1 = 0;
|
|
|
|
h.priv->ule_sndu_len = 0;
|
2016-10-13 17:47:54 +08:00
|
|
|
// pr_warn("More data in current TS: [%#x %#x %#x %#x]\n",
|
2016-11-19 22:56:58 +08:00
|
|
|
// *(h.from_where + 0), *(h.from_where + 1),
|
|
|
|
// *(h.from_where + 2), *(h.from_where + 3));
|
|
|
|
// pr_warn("h.ts @ %p, stopped @ %p:\n", h.ts, h.from_where + 0);
|
|
|
|
// hexdump(h.ts, 188);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2016-11-19 22:56:58 +08:00
|
|
|
h.new_ts = 1;
|
|
|
|
h.ts += TS_SZ;
|
|
|
|
h.priv->ts_count++;
|
|
|
|
if (h.priv->ule_skb == NULL) {
|
|
|
|
h.priv->need_pusi = 1;
|
|
|
|
h.priv->ule_sndu_type_1 = 0;
|
|
|
|
h.priv->ule_sndu_len = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* for all available TS cells */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len,
|
|
|
|
const u8 *buffer2, size_t buffer2_len,
|
2015-10-07 06:53:02 +08:00
|
|
|
struct dmx_ts_feed *feed)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-05-17 12:54:24 +08:00
|
|
|
struct net_device *dev = feed->priv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-29 11:07:38 +08:00
|
|
|
if (buffer2)
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_warn("buffer2 not NULL: %p.\n", buffer2);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (buffer1_len > 32768)
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_warn("length > 32k: %zu.\n", buffer1_len);
|
|
|
|
/* pr_info("TS callback: %u bytes, %u TS cells @ %p.\n",
|
2005-12-12 16:37:27 +08:00
|
|
|
buffer1_len, buffer1_len / TS_SZ, buffer1); */
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_net_ule(dev, buffer1, buffer1_len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 09:33:28 +08:00
|
|
|
static void dvb_net_sec(struct net_device *dev,
|
|
|
|
const u8 *pkt, int pkt_len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-12-12 16:37:27 +08:00
|
|
|
u8 *eth;
|
|
|
|
struct sk_buff *skb;
|
2009-01-08 10:02:53 +08:00
|
|
|
struct net_device_stats *stats = &dev->stats;
|
2005-05-17 12:54:25 +08:00
|
|
|
int snap = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* note: pkt_len includes a 32bit checksum */
|
|
|
|
if (pkt_len < 16) {
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_warn("%s: IP/MPE packet length = %d too small.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->name, pkt_len);
|
|
|
|
stats->rx_errors++;
|
|
|
|
stats->rx_length_errors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* it seems some ISPs manage to screw up here, so we have to
|
|
|
|
* relax the error checks... */
|
|
|
|
#if 0
|
|
|
|
if ((pkt[5] & 0xfd) != 0xc1) {
|
|
|
|
/* drop scrambled or broken packets */
|
|
|
|
#else
|
|
|
|
if ((pkt[5] & 0x3c) != 0x00) {
|
|
|
|
/* drop scrambled */
|
|
|
|
#endif
|
|
|
|
stats->rx_errors++;
|
|
|
|
stats->rx_crc_errors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pkt[5] & 0x02) {
|
2005-05-17 12:54:25 +08:00
|
|
|
/* handle LLC/SNAP, see rfc-1042 */
|
|
|
|
if (pkt_len < 24 || memcmp(&pkt[12], "\xaa\xaa\x03\0\0\0", 6)) {
|
|
|
|
stats->rx_dropped++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snap = 8;
|
2005-12-12 16:37:27 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (pkt[7]) {
|
|
|
|
/* FIXME: assemble datagram from multiple sections */
|
|
|
|
stats->rx_errors++;
|
|
|
|
stats->rx_frame_errors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have 14 byte ethernet header (ip header follows);
|
2005-05-17 12:54:25 +08:00
|
|
|
* 12 byte MPE header; 4 byte checksum; + 2 byte alignment, 8 byte LLC/SNAP
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-05-17 12:54:25 +08:00
|
|
|
if (!(skb = dev_alloc_skb(pkt_len - 4 - 12 + 14 + 2 - snap))) {
|
2016-10-13 17:47:54 +08:00
|
|
|
//pr_notice("%s: Memory squeeze, dropping packet.\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
stats->rx_dropped++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
skb_reserve(skb, 2); /* longword align L3 header */
|
|
|
|
skb->dev = dev;
|
|
|
|
|
|
|
|
/* copy L3 payload */
|
networking: make skb_put & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions (skb_put, __skb_put and pskb_put) return void *
and remove all the casts across the tree, adding a (u8 *) cast only
where the unsigned char pointer was used directly, all done with the
following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_put, __skb_put };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_put, __skb_put };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
which actually doesn't cover pskb_put since there are only three
users overall.
A handful of stragglers were converted manually, notably a macro in
drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
instances in net/bluetooth/hci_sock.c. In the former file, I also
had to fix one whitespace problem spatch introduced.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:21 +08:00
|
|
|
eth = skb_put(skb, pkt_len - 12 - 4 + 14 - snap);
|
2005-05-17 12:54:25 +08:00
|
|
|
memcpy(eth + 14, pkt + 12 + snap, pkt_len - 12 - 4 - snap);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* create ethernet header: */
|
2005-12-12 16:37:27 +08:00
|
|
|
eth[0]=pkt[0x0b];
|
|
|
|
eth[1]=pkt[0x0a];
|
|
|
|
eth[2]=pkt[0x09];
|
|
|
|
eth[3]=pkt[0x08];
|
|
|
|
eth[4]=pkt[0x04];
|
|
|
|
eth[5]=pkt[0x03];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-12-12 16:37:27 +08:00
|
|
|
eth[6]=eth[7]=eth[8]=eth[9]=eth[10]=eth[11]=0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-17 12:54:25 +08:00
|
|
|
if (snap) {
|
|
|
|
eth[12] = pkt[18];
|
|
|
|
eth[13] = pkt[19];
|
|
|
|
} else {
|
|
|
|
/* protocol numbers are from rfc-1700 or
|
|
|
|
* http://www.iana.org/assignments/ethernet-numbers
|
|
|
|
*/
|
|
|
|
if (pkt[12] >> 4 == 6) { /* version field from IP header */
|
|
|
|
eth[12] = 0x86; /* IPv6 */
|
|
|
|
eth[13] = 0xdd;
|
|
|
|
} else {
|
|
|
|
eth[12] = 0x08; /* IPv4 */
|
|
|
|
eth[13] = 0x00;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
skb->protocol = dvb_net_eth_type_trans(skb, dev);
|
|
|
|
|
|
|
|
stats->rx_packets++;
|
|
|
|
stats->rx_bytes+=skb->len;
|
2005-12-12 16:37:27 +08:00
|
|
|
netif_rx(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len,
|
|
|
|
const u8 *buffer2, size_t buffer2_len,
|
2015-10-07 06:53:02 +08:00
|
|
|
struct dmx_section_filter *filter)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-12-12 16:37:27 +08:00
|
|
|
struct net_device *dev = filter->priv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-11-27 23:21:28 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* we rely on the DVB API definition where exactly one complete
|
|
|
|
* section is delivered in buffer1
|
|
|
|
*/
|
2007-08-21 03:45:35 +08:00
|
|
|
dvb_net_sec (dev, buffer1, buffer1_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_tx(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
dev_kfree_skb(skb);
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u8 mask_normal[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
|
|
|
static u8 mask_allmulti[6]={0xff, 0xff, 0xff, 0x00, 0x00, 0x00};
|
|
|
|
static u8 mac_allmulti[6]={0x01, 0x00, 0x5e, 0x00, 0x00, 0x00};
|
|
|
|
static u8 mask_promisc[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
static int dvb_net_filter_sec_set(struct net_device *dev,
|
|
|
|
struct dmx_section_filter **secfilter,
|
|
|
|
u8 *mac, u8 *mac_mask)
|
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
*secfilter=NULL;
|
|
|
|
ret = priv->secfeed->allocate_filter(priv->secfeed, secfilter);
|
|
|
|
if (ret<0) {
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: could not get filter\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*secfilter)->priv=(void *) dev;
|
|
|
|
|
|
|
|
memset((*secfilter)->filter_value, 0x00, DMX_MAX_FILTER_SIZE);
|
|
|
|
memset((*secfilter)->filter_mask, 0x00, DMX_MAX_FILTER_SIZE);
|
|
|
|
memset((*secfilter)->filter_mode, 0xff, DMX_MAX_FILTER_SIZE);
|
|
|
|
|
|
|
|
(*secfilter)->filter_value[0]=0x3e;
|
|
|
|
(*secfilter)->filter_value[3]=mac[5];
|
|
|
|
(*secfilter)->filter_value[4]=mac[4];
|
|
|
|
(*secfilter)->filter_value[8]=mac[3];
|
|
|
|
(*secfilter)->filter_value[9]=mac[2];
|
|
|
|
(*secfilter)->filter_value[10]=mac[1];
|
|
|
|
(*secfilter)->filter_value[11]=mac[0];
|
|
|
|
|
|
|
|
(*secfilter)->filter_mask[0] = 0xff;
|
|
|
|
(*secfilter)->filter_mask[3] = mac_mask[5];
|
|
|
|
(*secfilter)->filter_mask[4] = mac_mask[4];
|
|
|
|
(*secfilter)->filter_mask[8] = mac_mask[3];
|
|
|
|
(*secfilter)->filter_mask[9] = mac_mask[2];
|
|
|
|
(*secfilter)->filter_mask[10] = mac_mask[1];
|
|
|
|
(*secfilter)->filter_mask[11]=mac_mask[0];
|
|
|
|
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "filter mac=%pM mask=%pM\n", mac, mac_mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_feed_start(struct net_device *dev)
|
|
|
|
{
|
2005-12-01 16:51:54 +08:00
|
|
|
int ret = 0, i;
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-12-12 16:37:27 +08:00
|
|
|
struct dmx_demux *demux = priv->demux;
|
|
|
|
unsigned char *mac = (unsigned char *) dev->dev_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "rx_mode %i\n", priv->rx_mode);
|
2006-02-07 16:49:14 +08:00
|
|
|
mutex_lock(&priv->mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0])
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: BUG %d\n", __func__, __LINE__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
priv->secfeed=NULL;
|
|
|
|
priv->secfilter=NULL;
|
|
|
|
priv->tsfeed = NULL;
|
|
|
|
|
|
|
|
if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "alloc secfeed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
ret=demux->allocate_section_feed(demux, &priv->secfeed,
|
|
|
|
dvb_net_sec_callback);
|
|
|
|
if (ret<0) {
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: could not allocate section feed\n",
|
|
|
|
dev->name);
|
2005-12-01 16:51:54 +08:00
|
|
|
goto error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-10-13 18:14:38 +08:00
|
|
|
ret = priv->secfeed->set(priv->secfeed, priv->pid, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ret<0) {
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: could not set section feed\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->demux->release_section_feed(priv->demux, priv->secfeed);
|
|
|
|
priv->secfeed=NULL;
|
2005-12-01 16:51:54 +08:00
|
|
|
goto error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->rx_mode != RX_MODE_PROMISC) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "set secfilter\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_normal);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (priv->rx_mode) {
|
|
|
|
case RX_MODE_MULTI:
|
|
|
|
for (i = 0; i < priv->multi_num; i++) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "set multi_secfilter[%d]\n", i);
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_net_filter_sec_set(dev, &priv->multi_secfilter[i],
|
|
|
|
priv->multi_macs[i], mask_normal);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RX_MODE_ALL_MULTI:
|
|
|
|
priv->multi_num=1;
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "set multi_secfilter[0]\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_net_filter_sec_set(dev, &priv->multi_secfilter[0],
|
|
|
|
mac_allmulti, mask_allmulti);
|
|
|
|
break;
|
|
|
|
case RX_MODE_PROMISC:
|
|
|
|
priv->multi_num=0;
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "set secfilter\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_promisc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "start filtering\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->secfeed->start_filtering(priv->secfeed);
|
|
|
|
} else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
|
2016-06-18 04:46:28 +08:00
|
|
|
ktime_t timeout = ns_to_ktime(10 * NSEC_PER_MSEC);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* we have payloads encapsulated in TS */
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "alloc tsfeed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback);
|
|
|
|
if (ret < 0) {
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: could not allocate ts feed\n", dev->name);
|
2005-12-01 16:51:54 +08:00
|
|
|
goto error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set netdevice pointer for ts decaps callback. */
|
|
|
|
priv->tsfeed->priv = (void *)dev;
|
2006-05-22 21:31:47 +08:00
|
|
|
ret = priv->tsfeed->set(priv->tsfeed,
|
|
|
|
priv->pid, /* pid */
|
|
|
|
TS_PACKET, /* type */
|
2013-04-05 00:25:30 +08:00
|
|
|
DMX_PES_OTHER, /* pes type */
|
2006-05-22 21:31:47 +08:00
|
|
|
timeout /* timeout */
|
|
|
|
);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ret < 0) {
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: could not set ts feed\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->demux->release_ts_feed(priv->demux, priv->tsfeed);
|
|
|
|
priv->tsfeed = NULL;
|
2005-12-01 16:51:54 +08:00
|
|
|
goto error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "start filtering\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->tsfeed->start_filtering(priv->tsfeed);
|
|
|
|
} else
|
2005-12-01 16:51:54 +08:00
|
|
|
ret = -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-12-01 16:51:54 +08:00
|
|
|
error:
|
2006-02-07 16:49:14 +08:00
|
|
|
mutex_unlock(&priv->mutex);
|
2005-12-01 16:51:54 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_feed_stop(struct net_device *dev)
|
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-12-01 16:51:54 +08:00
|
|
|
int i, ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-02-07 16:49:14 +08:00
|
|
|
mutex_lock(&priv->mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
|
|
|
|
if (priv->secfeed) {
|
|
|
|
if (priv->secfeed->is_filtering) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "stop secfeed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->secfeed->stop_filtering(priv->secfeed);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->secfilter) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "release secfilter\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->secfeed->release_filter(priv->secfeed,
|
|
|
|
priv->secfilter);
|
|
|
|
priv->secfilter=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<priv->multi_num; i++) {
|
|
|
|
if (priv->multi_secfilter[i]) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "release multi_filter[%d]\n",
|
|
|
|
i);
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->secfeed->release_filter(priv->secfeed,
|
|
|
|
priv->multi_secfilter[i]);
|
|
|
|
priv->multi_secfilter[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->demux->release_section_feed(priv->demux, priv->secfeed);
|
|
|
|
priv->secfeed = NULL;
|
|
|
|
} else
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: no feed to stop\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
|
|
|
|
if (priv->tsfeed) {
|
|
|
|
if (priv->tsfeed->is_filtering) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "stop tsfeed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->tsfeed->stop_filtering(priv->tsfeed);
|
|
|
|
}
|
|
|
|
priv->demux->release_ts_feed(priv->demux, priv->tsfeed);
|
|
|
|
priv->tsfeed = NULL;
|
|
|
|
}
|
|
|
|
else
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_err("%s: no ts feed to stop\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
2005-12-01 16:51:54 +08:00
|
|
|
ret = -EINVAL;
|
2006-02-07 16:49:14 +08:00
|
|
|
mutex_unlock(&priv->mutex);
|
2005-12-01 16:51:54 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-02 05:22:57 +08:00
|
|
|
static int dvb_set_mc_filter(struct net_device *dev, unsigned char *addr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (priv->multi_num == DVB_NET_MULTICAST_MAX)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-04-02 05:22:57 +08:00
|
|
|
memcpy(priv->multi_macs[priv->multi_num], addr, ETH_ALEN);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
priv->multi_num++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static void wq_set_multicast_list (struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-11-22 22:57:56 +08:00
|
|
|
struct dvb_net_priv *priv =
|
|
|
|
container_of(work, struct dvb_net_priv, set_multicast_list_wq);
|
|
|
|
struct net_device *dev = priv->net;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dvb_net_feed_stop(dev);
|
|
|
|
priv->rx_mode = RX_MODE_UNI;
|
2008-07-15 15:15:08 +08:00
|
|
|
netif_addr_lock_bh(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dev->flags & IFF_PROMISC) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "promiscuous mode\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->rx_mode = RX_MODE_PROMISC;
|
|
|
|
} else if ((dev->flags & IFF_ALLMULTI)) {
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "allmulti mode\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->rx_mode = RX_MODE_ALL_MULTI;
|
2010-02-08 12:30:35 +08:00
|
|
|
} else if (!netdev_mc_empty(dev)) {
|
2010-04-02 05:22:57 +08:00
|
|
|
struct netdev_hw_addr *ha;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-01-29 02:05:51 +08:00
|
|
|
netdev_dbg(dev, "set_mc_list, %d entries\n",
|
|
|
|
netdev_mc_count(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
priv->rx_mode = RX_MODE_MULTI;
|
|
|
|
priv->multi_num = 0;
|
|
|
|
|
2010-04-02 05:22:57 +08:00
|
|
|
netdev_for_each_mc_addr(ha, dev)
|
|
|
|
dvb_set_mc_filter(dev, ha->addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-07-15 15:15:08 +08:00
|
|
|
netif_addr_unlock_bh(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_net_feed_start(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void dvb_net_set_multicast_list (struct net_device *dev)
|
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule_work(&priv->set_multicast_list_wq);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static void wq_restart_net_feed (struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-11-22 22:57:56 +08:00
|
|
|
struct dvb_net_priv *priv =
|
|
|
|
container_of(work, struct dvb_net_priv, restart_net_feed_wq);
|
|
|
|
struct net_device *dev = priv->net;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (netif_running(dev)) {
|
|
|
|
dvb_net_feed_stop(dev);
|
|
|
|
dvb_net_feed_start(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dvb_net_set_mac (struct net_device *dev, void *p)
|
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sockaddr *addr=p;
|
|
|
|
|
|
|
|
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
|
|
|
|
|
|
|
|
if (netif_running(dev))
|
|
|
|
schedule_work(&priv->restart_net_feed_wq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dvb_net_open(struct net_device *dev)
|
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
priv->in_use++;
|
|
|
|
dvb_net_feed_start(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dvb_net_stop(struct net_device *dev)
|
|
|
|
{
|
2008-12-04 13:13:13 +08:00
|
|
|
struct dvb_net_priv *priv = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
priv->in_use--;
|
2005-12-12 16:37:27 +08:00
|
|
|
return dvb_net_feed_stop(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-10-09 16:40:57 +08:00
|
|
|
static const struct header_ops dvb_header_ops = {
|
|
|
|
.create = eth_header,
|
|
|
|
.parse = eth_header_parse,
|
|
|
|
};
|
|
|
|
|
2009-01-08 10:02:53 +08:00
|
|
|
|
|
|
|
static const struct net_device_ops dvb_netdev_ops = {
|
|
|
|
.ndo_open = dvb_net_open,
|
|
|
|
.ndo_stop = dvb_net_stop,
|
|
|
|
.ndo_start_xmit = dvb_net_tx,
|
2011-08-16 14:29:01 +08:00
|
|
|
.ndo_set_rx_mode = dvb_net_set_multicast_list,
|
2009-01-08 10:02:53 +08:00
|
|
|
.ndo_set_mac_address = dvb_net_set_mac,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void dvb_net_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ether_setup(dev);
|
|
|
|
|
2007-10-09 16:40:57 +08:00
|
|
|
dev->header_ops = &dvb_header_ops;
|
2009-01-08 10:02:53 +08:00
|
|
|
dev->netdev_ops = &dvb_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->mtu = 4096;
|
net: deprecate eth_change_mtu, remove usage
With centralized MTU checking, there's nothing productive done by
eth_change_mtu that isn't already done in dev_set_mtu, so mark it as
deprecated and remove all usage of it in the kernel. All callers have been
audited for calls to alloc_etherdev* or ether_setup directly, which means
they all have a valid dev->min_mtu and dev->max_mtu. Now eth_change_mtu
prints out a netdev_warn about being deprecated, for the benefit of
out-of-tree drivers that might be utilizing it.
Of note, dvb_net.c actually had dev->mtu = 4096, while using
eth_change_mtu, meaning that if you ever tried changing it's mtu, you
couldn't set it above 1500 anymore. It's now getting dev->max_mtu also set
to 4096 to remedy that.
v2: fix up lantiq_etop, missed breakage due to drive not compiling on x86
CC: netdev@vger.kernel.org
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-10-08 10:04:34 +08:00
|
|
|
dev->max_mtu = 4096;
|
2007-10-09 16:40:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->flags |= IFF_NOARP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_if(struct dvb_net *dvbnet)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<DVB_NET_DEVICES_MAX; i++)
|
|
|
|
if (!dvbnet->state[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == DVB_NET_DEVICES_MAX)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
dvbnet->state[i]=1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype)
|
|
|
|
{
|
|
|
|
struct net_device *net;
|
|
|
|
struct dvb_net_priv *priv;
|
|
|
|
int result;
|
|
|
|
int if_num;
|
|
|
|
|
|
|
|
if (feedtype != DVB_NET_FEEDTYPE_MPE && feedtype != DVB_NET_FEEDTYPE_ULE)
|
|
|
|
return -EINVAL;
|
|
|
|
if ((if_num = get_if(dvbnet)) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
net: set name_assign_type in alloc_netdev()
Extend alloc_netdev{,_mq{,s}}() to take name_assign_type as argument, and convert
all users to pass NET_NAME_UNKNOWN.
Coccinelle patch:
@@
expression sizeof_priv, name, setup, txqs, rxqs, count;
@@
(
-alloc_netdev_mqs(sizeof_priv, name, setup, txqs, rxqs)
+alloc_netdev_mqs(sizeof_priv, name, NET_NAME_UNKNOWN, setup, txqs, rxqs)
|
-alloc_netdev_mq(sizeof_priv, name, setup, count)
+alloc_netdev_mq(sizeof_priv, name, NET_NAME_UNKNOWN, setup, count)
|
-alloc_netdev(sizeof_priv, name, setup)
+alloc_netdev(sizeof_priv, name, NET_NAME_UNKNOWN, setup)
)
v9: move comments here from the wrong commit
Signed-off-by: Tom Gundersen <teg@jklm.no>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-07-14 22:37:24 +08:00
|
|
|
net = alloc_netdev(sizeof(struct dvb_net_priv), "dvb",
|
|
|
|
NET_NAME_UNKNOWN, dvb_net_setup);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!net)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (dvbnet->dvbdev->id)
|
|
|
|
snprintf(net->name, IFNAMSIZ, "dvb%d%u%d",
|
|
|
|
dvbnet->dvbdev->adapter->num, dvbnet->dvbdev->id, if_num);
|
|
|
|
else
|
|
|
|
/* compatibility fix to keep dvb0_0 format */
|
|
|
|
snprintf(net->name, IFNAMSIZ, "dvb%d_%d",
|
|
|
|
dvbnet->dvbdev->adapter->num, if_num);
|
|
|
|
|
|
|
|
net->addr_len = 6;
|
|
|
|
memcpy(net->dev_addr, dvbnet->dvbdev->adapter->proposed_mac, 6);
|
|
|
|
|
|
|
|
dvbnet->device[if_num] = net;
|
|
|
|
|
2008-12-04 13:13:13 +08:00
|
|
|
priv = netdev_priv(net);
|
2006-11-22 22:57:56 +08:00
|
|
|
priv->net = net;
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->demux = dvbnet->demux;
|
|
|
|
priv->pid = pid;
|
|
|
|
priv->rx_mode = RX_MODE_UNI;
|
|
|
|
priv->need_pusi = 1;
|
|
|
|
priv->tscc = 0;
|
|
|
|
priv->feedtype = feedtype;
|
|
|
|
reset_ule(priv);
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
INIT_WORK(&priv->set_multicast_list_wq, wq_set_multicast_list);
|
|
|
|
INIT_WORK(&priv->restart_net_feed_wq, wq_restart_net_feed);
|
2006-02-07 16:49:14 +08:00
|
|
|
mutex_init(&priv->mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
net->base_addr = pid;
|
|
|
|
|
|
|
|
if ((result = register_netdev(net)) < 0) {
|
|
|
|
dvbnet->device[if_num] = NULL;
|
|
|
|
free_netdev(net);
|
|
|
|
return result;
|
|
|
|
}
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_info("created network interface %s\n", net->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return if_num;
|
|
|
|
}
|
|
|
|
|
2006-01-10 01:32:43 +08:00
|
|
|
static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned long num)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *net = dvbnet->device[num];
|
|
|
|
struct dvb_net_priv *priv;
|
|
|
|
|
|
|
|
if (!dvbnet->state[num])
|
|
|
|
return -EINVAL;
|
2008-12-04 13:13:13 +08:00
|
|
|
priv = netdev_priv(net);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (priv->in_use)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
dvb_net_stop(net);
|
2012-08-21 05:51:24 +08:00
|
|
|
flush_work(&priv->set_multicast_list_wq);
|
|
|
|
flush_work(&priv->restart_net_feed_wq);
|
2016-10-13 17:47:54 +08:00
|
|
|
pr_info("removed network interface %s\n", net->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
unregister_netdev(net);
|
|
|
|
dvbnet->state[num]=0;
|
|
|
|
dvbnet->device[num] = NULL;
|
|
|
|
free_netdev(net);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-27 06:24:00 +08:00
|
|
|
static int dvb_net_do_ioctl(struct file *file,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int cmd, void *parg)
|
|
|
|
{
|
2005-05-17 12:54:24 +08:00
|
|
|
struct dvb_device *dvbdev = file->private_data;
|
|
|
|
struct dvb_net *dvbnet = dvbdev->priv;
|
2012-12-24 05:49:07 +08:00
|
|
|
int ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (((file->f_flags&O_ACCMODE)==O_RDONLY))
|
|
|
|
return -EPERM;
|
|
|
|
|
2012-12-24 05:49:07 +08:00
|
|
|
if (mutex_lock_interruptible(&dvbnet->ioctl_mutex))
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case NET_ADD_IF:
|
|
|
|
{
|
2005-05-17 12:54:24 +08:00
|
|
|
struct dvb_net_if *dvbnetif = parg;
|
2005-04-17 06:20:36 +08:00
|
|
|
int result;
|
|
|
|
|
2012-12-24 05:49:07 +08:00
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-12-24 05:49:07 +08:00
|
|
|
if (!try_module_get(dvbdev->adapter->module)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
result=dvb_net_add_if(dvbnet, dvbnetif->pid, dvbnetif->feedtype);
|
|
|
|
if (result<0) {
|
|
|
|
module_put(dvbdev->adapter->module);
|
2012-12-24 05:49:07 +08:00
|
|
|
ret = result;
|
|
|
|
goto ioctl_error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
dvbnetif->if_num=result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NET_GET_IF:
|
|
|
|
{
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct dvb_net_priv *priv_data;
|
2005-05-17 12:54:24 +08:00
|
|
|
struct dvb_net_if *dvbnetif = parg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX ||
|
2012-12-24 05:49:07 +08:00
|
|
|
!dvbnet->state[dvbnetif->if_num]) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
netdev = dvbnet->device[dvbnetif->if_num];
|
|
|
|
|
2008-12-04 13:13:13 +08:00
|
|
|
priv_data = netdev_priv(netdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
dvbnetif->pid=priv_data->pid;
|
|
|
|
dvbnetif->feedtype=priv_data->feedtype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NET_REMOVE_IF:
|
|
|
|
{
|
2012-12-24 05:49:07 +08:00
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
|
|
|
if ((unsigned long) parg >= DVB_NET_DEVICES_MAX) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2006-01-10 01:25:28 +08:00
|
|
|
ret = dvb_net_remove_if(dvbnet, (unsigned long) parg);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ret)
|
|
|
|
module_put(dvbdev->adapter->module);
|
2012-12-24 05:49:07 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-29 09:43:57 +08:00
|
|
|
/* binary compatibility cruft */
|
2005-04-17 06:20:36 +08:00
|
|
|
case __NET_ADD_IF_OLD:
|
|
|
|
{
|
2005-05-17 12:54:24 +08:00
|
|
|
struct __dvb_net_if_old *dvbnetif = parg;
|
2005-04-17 06:20:36 +08:00
|
|
|
int result;
|
|
|
|
|
2012-12-24 05:49:07 +08:00
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-12-24 05:49:07 +08:00
|
|
|
if (!try_module_get(dvbdev->adapter->module)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
result=dvb_net_add_if(dvbnet, dvbnetif->pid, DVB_NET_FEEDTYPE_MPE);
|
|
|
|
if (result<0) {
|
|
|
|
module_put(dvbdev->adapter->module);
|
2012-12-24 05:49:07 +08:00
|
|
|
ret = result;
|
|
|
|
goto ioctl_error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
dvbnetif->if_num=result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case __NET_GET_IF_OLD:
|
|
|
|
{
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct dvb_net_priv *priv_data;
|
2005-05-17 12:54:24 +08:00
|
|
|
struct __dvb_net_if_old *dvbnetif = parg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX ||
|
2012-12-24 05:49:07 +08:00
|
|
|
!dvbnet->state[dvbnetif->if_num]) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto ioctl_error;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
netdev = dvbnet->device[dvbnetif->if_num];
|
|
|
|
|
2008-12-04 13:13:13 +08:00
|
|
|
priv_data = netdev_priv(netdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
dvbnetif->pid=priv_data->pid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-12-24 05:49:07 +08:00
|
|
|
ret = -ENOTTY;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2012-12-24 05:49:07 +08:00
|
|
|
|
|
|
|
ioctl_error:
|
|
|
|
mutex_unlock(&dvbnet->ioctl_mutex);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-04-27 06:24:00 +08:00
|
|
|
static long dvb_net_ioctl(struct file *file,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2010-09-12 01:56:45 +08:00
|
|
|
return dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-04-14 21:19:36 +08:00
|
|
|
static int dvb_net_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct dvb_device *dvbdev = file->private_data;
|
|
|
|
struct dvb_net *dvbnet = dvbdev->priv;
|
|
|
|
|
2007-08-18 04:49:41 +08:00
|
|
|
dvb_generic_release(inode, file);
|
2007-04-14 21:19:36 +08:00
|
|
|
|
2013-04-16 01:56:11 +08:00
|
|
|
if(dvbdev->users == 1 && dvbnet->exit == 1)
|
2007-04-14 21:19:36 +08:00
|
|
|
wake_up(&dvbdev->wait_queue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-11 17:12:43 +08:00
|
|
|
static const struct file_operations dvb_net_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
2010-04-27 06:24:00 +08:00
|
|
|
.unlocked_ioctl = dvb_net_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = dvb_generic_open,
|
2007-04-14 21:19:36 +08:00
|
|
|
.release = dvb_net_close,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = noop_llseek,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2015-01-03 09:53:58 +08:00
|
|
|
static const struct dvb_device dvbdev_net = {
|
2005-12-12 16:37:27 +08:00
|
|
|
.priv = NULL,
|
|
|
|
.users = 1,
|
|
|
|
.writers = 1,
|
2015-01-03 09:53:58 +08:00
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
|
2015-02-18 23:09:27 +08:00
|
|
|
.name = "dvb-net",
|
2015-01-03 09:53:58 +08:00
|
|
|
#endif
|
2005-12-12 16:37:27 +08:00
|
|
|
.fops = &dvb_net_fops,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void dvb_net_release (struct dvb_net *dvbnet)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-04-14 21:19:36 +08:00
|
|
|
dvbnet->exit = 1;
|
|
|
|
if (dvbnet->dvbdev->users < 1)
|
|
|
|
wait_event(dvbnet->dvbdev->wait_queue,
|
|
|
|
dvbnet->dvbdev->users==1);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dvb_unregister_device(dvbnet->dvbdev);
|
|
|
|
|
|
|
|
for (i=0; i<DVB_NET_DEVICES_MAX; i++) {
|
|
|
|
if (!dvbnet->state[i])
|
|
|
|
continue;
|
|
|
|
dvb_net_remove_if(dvbnet, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_net_release);
|
|
|
|
|
|
|
|
|
|
|
|
int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet,
|
|
|
|
struct dmx_demux *dmx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-12-24 05:49:07 +08:00
|
|
|
mutex_init(&dvbnet->ioctl_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
dvbnet->demux = dmx;
|
|
|
|
|
|
|
|
for (i=0; i<DVB_NET_DEVICES_MAX; i++)
|
|
|
|
dvbnet->state[i] = 0;
|
|
|
|
|
2011-12-31 18:54:16 +08:00
|
|
|
return dvb_register_device(adap, &dvbnet->dvbdev, &dvbdev_net,
|
2015-08-22 03:18:18 +08:00
|
|
|
dvbnet, DVB_DEVICE_NET, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_net_init);
|