fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / media / dvb / dvb-core / dvb_net.c
index 6a968c3..76e9c36 100644 (file)
@@ -12,7 +12,7 @@
  *                          Hilmar Linder <hlinder@cosy.sbg.ac.at>
  *                      and Wolfram Stering <wstering@cosy.sbg.ac.at>
  *
- * ULE Decaps according to draft-ietf-ipdvb-ule-03.txt.
+ * ULE Decaps according to RFC 4326.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -42,6 +42,9 @@
  *                     Bugfixes and robustness improvements.
  *                     Filtering on dest MAC addresses, if present (D-Bit = 0)
  *                     ULE_DEBUG compile-time option.
+ * Apr 2006: cp v3:    Bugfixes and compliency with RFC 4326 (ULE) by
+ *                       Christian Praehauser <cpraehaus@cosy.sbg.ac.at>,
+ *                       Paris Lodron University of Salzburg.
  */
 
 /*
@@ -49,9 +52,6 @@
  *
  * Unloading does not work for 2.6.9 kernels: a refcount doesn't go to zero.
  *
- * TS_FEED callback is called once for every single TS cell although it is
- * registered (in dvb_net_feed_start()) for 100 TS cells (used for dvb_net_ule()).
- *
  */
 
 #include <linux/module.h>
@@ -62,7 +62,7 @@
 #include <linux/uio.h>
 #include <asm/uaccess.h>
 #include <linux/crc32.h>
-#include <linux/version.h>
+#include <linux/mutex.h>
 
 #include "dvb_demux.h"
 #include "dvb_net.h"
@@ -89,6 +89,9 @@ static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt )
 
 #ifdef ULE_DEBUG
 
+#define MAC_ADDR_PRINTFMT "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x"
+#define MAX_ADDR_PRINTFMT_ARGS(macap) (macap)[0],(macap)[1],(macap)[2],(macap)[3],(macap)[4],(macap)[5]
+
 #define isprint(c)     ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))
 
 static void hexdump( const unsigned char *buf, unsigned short len )
@@ -124,6 +127,7 @@ struct dvb_net_priv {
        int in_use;
        struct net_device_stats stats;
        u16 pid;
+       struct net_device *net;
        struct dvb_net *host;
        struct dmx_demux *demux;
        struct dmx_section_feed *secfeed;
@@ -152,6 +156,7 @@ struct dvb_net_priv {
        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. */
+       struct mutex mutex;
 };
 
 
@@ -171,11 +176,7 @@ static unsigned short dvb_net_eth_type_trans(struct sk_buff *skb,
 
        skb->mac.raw=skb->data;
        skb_pull(skb,dev->hard_header_len);
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,8)
-       eth = skb->mac.ethernet;
-#else
        eth = eth_hdr(skb);
-#endif
 
        if (*eth->h_dest & 1) {
                if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
@@ -217,6 +218,8 @@ static unsigned short dvb_net_eth_type_trans(struct sk_buff *skb,
 #define ULE_TEST       0
 #define ULE_BRIDGED    1
 
+#define ULE_OPTEXTHDR_PADDING 0
+
 static int ule_test_sndu( struct dvb_net_priv *p )
 {
        return -1;
@@ -224,14 +227,28 @@ static int ule_test_sndu( struct dvb_net_priv *p )
 
 static int ule_bridged_sndu( struct dvb_net_priv *p )
 {
-       /* BRIDGE SNDU handling sucks in draft-ietf-ipdvb-ule-03.txt.
-        * This has to be the last extension header, otherwise it won't work.
-        * Blame the authors!
+       struct ethhdr *hdr = (struct ethhdr*) p->ule_next_hdr;
+       if(ntohs(hdr->h_proto) < 1536) {
+               int framelen = p->ule_sndu_len - ((p->ule_next_hdr+sizeof(struct ethhdr)) - p->ule_skb->data);
+               /* A frame Type < 1536 for a bridged frame, introduces a LLC Length field. */
+               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.
         */
        p->ule_bridged = 1;
        return 0;
 }
 
+static int ule_exthdr_padding(struct dvb_net_priv *p)
+{
+       return 0;
+}
 
 /** Handle ULE extension headers.
  *  Function is called after a successful CRC32 verification of an ULE SNDU to complete its decoding.
@@ -245,7 +262,8 @@ static int handle_one_ule_extension( 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. */
-       static int (*ule_optional_ext_handlers[255])( struct dvb_net_priv *p ) = { NULL, };
+       static int (*ule_optional_ext_handlers[255])( struct dvb_net_priv *p ) =
+               { [0] = ule_exthdr_padding, [1] = NULL, };
 
        int ext_len = 0;
        unsigned char hlen = (p->ule_sndu_type & 0x0700) >> 8;
@@ -256,25 +274,31 @@ static int handle_one_ule_extension( struct dvb_net_priv *p )
                /* Mandatory extension header */
                if (ule_mandatory_ext_handlers[htype]) {
                        ext_len = ule_mandatory_ext_handlers[htype]( p );
-                       p->ule_next_hdr += ext_len;
-                       if (! p->ule_bridged) {
-                               p->ule_sndu_type = ntohs( *(unsigned short *)p->ule_next_hdr );
-                               p->ule_next_hdr += 2;
-                       } else {
-                               p->ule_sndu_type = ntohs( *(unsigned short *)(p->ule_next_hdr + ((p->ule_dbit ? 2 : 3) * ETH_ALEN)) );
-                               /* This assures the extension handling loop will terminate. */
+                       if(ext_len >= 0) {
+                               p->ule_next_hdr += ext_len;
+                               if (!p->ule_bridged) {
+                                       p->ule_sndu_type = ntohs(*(unsigned short *)p->ule_next_hdr);
+                                       p->ule_next_hdr += 2;
+                               } else {
+                                       p->ule_sndu_type = ntohs(*(unsigned short *)(p->ule_next_hdr + ((p->ule_dbit ? 2 : 3) * ETH_ALEN)));
+                                       /* This assures the extension handling loop will terminate. */
+                               }
                        }
+                       // else: extension handler failed or SNDU should be discarded
                } else
                        ext_len = -1;   /* SNDU has to be discarded. */
        } else {
                /* Optional extension header.  Calculate the length. */
-               ext_len = hlen << 2;
+               ext_len = hlen << 1;
                /* 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;
-               p->ule_sndu_type = ntohs( *(unsigned short *)p->ule_next_hdr );
-               p->ule_next_hdr += 2;
+               p->ule_sndu_type = ntohs( *(unsigned short *)(p->ule_next_hdr-2) );
+               /*
+                * note: the length of the next header type is included in the
+                * length of THIS optional extension header
+                */
        }
 
        return ext_len;
@@ -287,8 +311,14 @@ static int handle_ule_extensions( struct dvb_net_priv *p )
        p->ule_next_hdr = p->ule_skb->data;
        do {
                l = handle_one_ule_extension( p );
-               if (l == -1) return -1; /* Stop extension header processing and discard SNDU. */
+               if (l < 0)
+                       return l;       /* Stop extension header processing and discard SNDU. */
                total_ext_len += l;
+#ifdef ULE_DEBUG
+               dprintk("handle_ule_extensions: 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);
+#endif
 
        } while (p->ule_sndu_type < 1536);
 
@@ -358,8 +388,8 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                if (priv->ule_skb) {
                                        dev_kfree_skb( priv->ule_skb );
                                        /* Prepare for next SNDU. */
-                                       ((struct dvb_net_priv *) dev->priv)->stats.rx_errors++;
-                                       ((struct dvb_net_priv *) dev->priv)->stats.rx_frame_errors++;
+                                       priv->stats.rx_errors++;
+                                       priv->stats.rx_frame_errors++;
                                }
                                reset_ule(priv);
                                priv->need_pusi = 1;
@@ -399,27 +429,25 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                        }
                }
 
-               /* Check continuity counter. */
                if (new_ts) {
+                       /* Check continuity counter. */
                        if ((ts[3] & 0x0F) == priv->tscc)
                                priv->tscc = (priv->tscc + 1) & 0x0F;
                        else {
                                /* TS discontinuity handling: */
                                printk(KERN_WARNING "%lu: TS discontinuity: got %#x, "
-                                      "exptected %#x.\n", priv->ts_count, ts[3] & 0x0F, priv->tscc);
+                                      "expected %#x.\n", priv->ts_count, ts[3] & 0x0F, priv->tscc);
                                /* Drop partly decoded SNDU, reset state, resync on PUSI. */
                                if (priv->ule_skb) {
                                        dev_kfree_skb( priv->ule_skb );
                                        /* Prepare for next SNDU. */
                                        // reset_ule(priv);  moved to below.
-                                       ((struct dvb_net_priv *) dev->priv)->stats.rx_errors++;
-                                       ((struct dvb_net_priv *) dev->priv)->stats.rx_frame_errors++;
+                                       priv->stats.rx_errors++;
+                                       priv->stats.rx_frame_errors++;
                                }
                                reset_ule(priv);
                                /* skip to next PUSI. */
                                priv->need_pusi = 1;
-                               ts += TS_SZ;
-                               priv->ts_count++;
                                continue;
                        }
                        /* If we still have an incomplete payload, but PUSI is
@@ -428,7 +456,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                         * cells (continuity counter wrap). */
                        if (ts[1] & TS_PUSI) {
                                if (! priv->need_pusi) {
-                                       if (*from_where > 181) {
+                                       if (!(*from_where < (ts_remain-1)) || *from_where != priv->ule_sndu_remain) {
                                                /* Pointer field is invalid.  Drop this TS cell and any started ULE SNDU. */
                                                printk(KERN_WARNING "%lu: Invalid pointer "
                                                       "field: %u.\n", priv->ts_count, *from_where);
@@ -441,8 +469,6 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                                }
                                                reset_ule(priv);
                                                priv->need_pusi = 1;
-                                               ts += TS_SZ;
-                                               priv->ts_count++;
                                                continue;
                                        }
                                        /* Skip pointer field (we're processing a
@@ -455,8 +481,8 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                if (priv->ule_sndu_remain > 183) {
                                        /* Current SNDU lacks more data than there could be available in the
                                         * current TS cell. */
-                                       ((struct dvb_net_priv *) dev->priv)->stats.rx_errors++;
-                                       ((struct dvb_net_priv *) dev->priv)->stats.rx_length_errors++;
+                                       priv->stats.rx_errors++;
+                                       priv->stats.rx_length_errors++;
                                        printk(KERN_WARNING "%lu: Expected %d more SNDU bytes, but "
                                               "got PUSI (pf %d, ts_remain %d).  Flushing incomplete payload.\n",
                                               priv->ts_count, priv->ule_sndu_remain, ts[4], ts_remain);
@@ -495,9 +521,11 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                } else
                                        priv->ule_dbit = 0;
 
-                               if (priv->ule_sndu_len > 32763) {
+                               if (priv->ule_sndu_len < 5) {
                                        printk(KERN_WARNING "%lu: Invalid ULE SNDU length %u. "
                                               "Resyncing.\n", priv->ts_count, priv->ule_sndu_len);
+                                       priv->stats.rx_errors++;
+                                       priv->stats.rx_length_errors++;
                                        priv->ule_sndu_len = 0;
                                        priv->need_pusi = 1;
                                        new_ts = 1;
@@ -577,7 +605,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                { &utype, sizeof utype },
                                { priv->ule_skb->data, priv->ule_skb->len - 4 }
                        };
-                       unsigned long ule_crc = ~0L, expected_crc;
+                       u32 ule_crc = ~0L, expected_crc;
                        if (priv->ule_dbit) {
                                /* Set D-bit for CRC32 verification,
                                 * if it was set originally. */
@@ -590,7 +618,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                       *((u8 *)priv->ule_skb->tail - 2) << 8 |
                                       *((u8 *)priv->ule_skb->tail - 1);
                        if (ule_crc != expected_crc) {
-                               printk(KERN_WARNING "%lu: CRC32 check FAILED: %#lx / %#lx, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
+                               printk(KERN_WARNING "%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
                                       priv->ts_count, ule_crc, expected_crc, priv->ule_sndu_len, priv->ule_sndu_type, ts_remain, ts_remain > 2 ? *(unsigned short *)from_where : 0);
 
 #ifdef ULE_DEBUG
@@ -611,58 +639,103 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                ule_dump = 1;
 #endif
 
-                               ((struct dvb_net_priv *) dev->priv)->stats.rx_errors++;
-                               ((struct dvb_net_priv *) dev->priv)->stats.rx_crc_errors++;
+                               priv->stats.rx_errors++;
+                               priv->stats.rx_crc_errors++;
                                dev_kfree_skb(priv->ule_skb);
                        } else {
                                /* CRC32 verified OK. */
+                               u8 dest_addr[ETH_ALEN];
+                               static const u8 bc_addr[ETH_ALEN] =
+                                       { [ 0 ... ETH_ALEN-1] = 0xff };
+
+                               /* CRC32 was OK. Remove it from skb. */
+                               priv->ule_skb->tail -= 4;
+                               priv->ule_skb->len -= 4;
+
+                               if (!priv->ule_dbit) {
+                                       /*
+                                        * 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.
+                                        */
+                                       register int drop = 0;
+                                       if (priv->rx_mode != RX_MODE_PROMISC) {
+                                               if (priv->ule_skb->data[0] & 0x01) {
+                                                       /* multicast or broadcast */
+                                                       if (memcmp(priv->ule_skb->data, bc_addr, ETH_ALEN)) {
+                                                               /* multicast */
+                                                               if (priv->rx_mode == RX_MODE_MULTI) {
+                                                                       int i;
+                                                                       for(i = 0; i < priv->multi_num && memcmp(priv->ule_skb->data, priv->multi_macs[i], ETH_ALEN); i++)
+                                                                               ;
+                                                                       if (i == priv->multi_num)
+                                                                               drop = 1;
+                                                               } else if (priv->rx_mode != RX_MODE_ALL_MULTI)
+                                                                       drop = 1; /* no broadcast; */
+                                                               /* else: all multicast mode: accept all multicast packets */
+                                                       }
+                                                       /* else: broadcast */
+                                               }
+                                               else if (memcmp(priv->ule_skb->data, dev->dev_addr, ETH_ALEN))
+                                                       drop = 1;
+                                               /* else: destination address matches the MAC address of our receiver device */
+                                       }
+                                       /* else: promiscious mode; pass everything up the stack */
+
+                                       if (drop) {
+#ifdef ULE_DEBUG
+                                               dprintk("Dropping SNDU: MAC destination address does not match: dest addr: "MAC_ADDR_PRINTFMT", dev addr: "MAC_ADDR_PRINTFMT"\n",
+                                                       MAX_ADDR_PRINTFMT_ARGS(priv->ule_skb->data), MAX_ADDR_PRINTFMT_ARGS(dev->dev_addr));
+#endif
+                                               dev_kfree_skb(priv->ule_skb);
+                                               goto sndu_done;
+                                       }
+                                       else
+                                       {
+                                               memcpy(dest_addr,  priv->ule_skb->data, ETH_ALEN);
+                                               skb_pull(priv->ule_skb, ETH_ALEN);
+                                       }
+                               }
+
                                /* Handle ULE Extension Headers. */
                                if (priv->ule_sndu_type < 1536) {
                                        /* There is an extension header.  Handle it accordingly. */
-                                       int l = handle_ule_extensions( priv );
+                                       int l = handle_ule_extensions(priv);
                                        if (l < 0) {
                                                /* Mandatory extension header unknown or TEST SNDU.  Drop it. */
                                                // printk( KERN_WARNING "Dropping SNDU, extension headers.\n" );
-                                               dev_kfree_skb( priv->ule_skb );
+                                               dev_kfree_skb(priv->ule_skb);
                                                goto sndu_done;
                                        }
-                                       skb_pull( priv->ule_skb, l );
+                                       skb_pull(priv->ule_skb, l);
                                }
 
-                               /* CRC32 was OK. Remove it from skb. */
-                               priv->ule_skb->tail -= 4;
-                               priv->ule_skb->len -= 4;
-
-                               /* Filter on receiver's destination MAC address, if present. */
-                               if (!priv->ule_dbit) {
-                                       /* The destination MAC address is the next data in the skb. */
-                                       if (memcmp( priv->ule_skb->data, dev->dev_addr, ETH_ALEN )) {
-                                               /* MAC addresses don't match.  Drop SNDU. */
-                                               // printk( KERN_WARNING "Dropping SNDU, MAC address.\n" );
-                                               dev_kfree_skb( priv->ule_skb );
-                                               goto sndu_done;
-                                       }
-                                       if (! priv->ule_bridged) {
-                                               skb_push( priv->ule_skb, ETH_ALEN + 2 );
-                                               ethh = (struct ethhdr *)priv->ule_skb->data;
-                                               memcpy( ethh->h_dest, ethh->h_source, ETH_ALEN );
-                                               memset( ethh->h_source, 0, ETH_ALEN );
-                                               ethh->h_proto = htons( priv->ule_sndu_type );
-                                       } else {
-                                               /* Skip the Receiver destination MAC address. */
-                                               skb_pull( priv->ule_skb, ETH_ALEN );
-                                       }
-                               } else {
-                                       if (! priv->ule_bridged) {
-                                               skb_push( priv->ule_skb, ETH_HLEN );
-                                               ethh = (struct ethhdr *)priv->ule_skb->data;
-                                               memcpy( ethh->h_dest, dev->dev_addr, ETH_ALEN );
-                                               memset( ethh->h_source, 0, ETH_ALEN );
-                                               ethh->h_proto = htons( priv->ule_sndu_type );
-                                       } else {
-                                               /* skb is in correct state; nothing to do. */
+                               /*
+                                * Construct/assure correct ethernet header.
+                                * Note: in bridged mode (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 (!priv->ule_bridged) {
+                                       skb_push(priv->ule_skb, ETH_HLEN);
+                                       ethh = (struct ethhdr *)priv->ule_skb->data;
+                                       if (!priv->ule_dbit) {
+                                                /* dest_addr buffer is only valid if priv->ule_dbit == 0 */
+                                               memcpy(ethh->h_dest, dest_addr, ETH_ALEN);
+                                               memset(ethh->h_source, 0, ETH_ALEN);
                                        }
+                                       else /* zeroize source and dest */
+                                               memset( ethh, 0, ETH_ALEN*2 );
+
+                                       ethh->h_proto = htons(priv->ule_sndu_type);
                                }
+                               /* else:  skb is in correct state; nothing to do. */
                                priv->ule_bridged = 0;
 
                                /* Stuff into kernel's protocol stack. */
@@ -671,8 +744,8 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
                                 * receive the packet anyhow. */
                                /* if (priv->ule_dbit && skb->pkt_type == PACKET_OTHERHOST)
                                        priv->ule_skb->pkt_type = PACKET_HOST; */
-                               ((struct dvb_net_priv *) dev->priv)->stats.rx_packets++;
-                               ((struct dvb_net_priv *) dev->priv)->stats.rx_bytes += priv->ule_skb->len;
+                               priv->stats.rx_packets++;
+                               priv->stats.rx_bytes += priv->ule_skb->len;
                                netif_rx(priv->ule_skb);
                        }
                        sndu_done:
@@ -716,7 +789,7 @@ static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len,
        if (buffer1_len > 32768)
                printk(KERN_WARNING "length > 32k: %zu.\n", buffer1_len);
        /* printk("TS callback: %u bytes, %u TS cells @ %p.\n",
-                 buffer1_len, buffer1_len / TS_SZ, buffer1); */
+                 buffer1_len, buffer1_len / TS_SZ, buffer1); */
        dvb_net_ule(dev, buffer1, buffer1_len);
        return 0;
 }
@@ -724,8 +797,8 @@ static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len,
 
 static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
 {
-        u8 *eth;
-        struct sk_buff *skb;
+       u8 *eth;
+       struct sk_buff *skb;
        struct net_device_stats *stats = &(((struct dvb_net_priv *) dev->priv)->stats);
        int snap = 0;
 
@@ -757,7 +830,7 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
                        return;
                }
                snap = 8;
-        }
+       }
        if (pkt[7]) {
                /* FIXME: assemble datagram from multiple sections */
                stats->rx_errors++;
@@ -781,14 +854,14 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
        memcpy(eth + 14, pkt + 12 + snap, pkt_len - 12 - 4 - snap);
 
        /* create ethernet header: */
-        eth[0]=pkt[0x0b];
-        eth[1]=pkt[0x0a];
-        eth[2]=pkt[0x09];
-        eth[3]=pkt[0x08];
-        eth[4]=pkt[0x04];
-        eth[5]=pkt[0x03];
+       eth[0]=pkt[0x0b];
+       eth[1]=pkt[0x0a];
+       eth[2]=pkt[0x09];
+       eth[3]=pkt[0x08];
+       eth[4]=pkt[0x04];
+       eth[5]=pkt[0x03];
 
-        eth[6]=eth[7]=eth[8]=eth[9]=eth[10]=eth[11]=0;
+       eth[6]=eth[7]=eth[8]=eth[9]=eth[10]=eth[11]=0;
 
        if (snap) {
                eth[12] = pkt[18];
@@ -810,7 +883,7 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
 
        stats->rx_packets++;
        stats->rx_bytes+=skb->len;
-        netif_rx(skb);
+       netif_rx(skb);
 }
 
 static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len,
@@ -818,7 +891,7 @@ static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len,
                 struct dmx_section_filter *filter,
                 enum dmx_success success)
 {
-        struct net_device *dev = filter->priv;
+       struct net_device *dev = filter->priv;
 
        /**
         * we rely on the DVB API definition where exactly one complete
@@ -886,12 +959,13 @@ static int dvb_net_filter_sec_set(struct net_device *dev,
 
 static int dvb_net_feed_start(struct net_device *dev)
 {
-       int ret, i;
+       int ret = 0, i;
        struct dvb_net_priv *priv = dev->priv;
-        struct dmx_demux *demux = priv->demux;
-        unsigned char *mac = (unsigned char *) dev->dev_addr;
+       struct dmx_demux *demux = priv->demux;
+       unsigned char *mac = (unsigned char *) dev->dev_addr;
 
        dprintk("%s: rx_mode %i\n", __FUNCTION__, priv->rx_mode);
+       mutex_lock(&priv->mutex);
        if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0])
                printk("%s: BUG %d\n", __FUNCTION__, __LINE__);
 
@@ -905,16 +979,16 @@ static int dvb_net_feed_start(struct net_device *dev)
                                         dvb_net_sec_callback);
                if (ret<0) {
                        printk("%s: could not allocate section feed\n", dev->name);
-                       return ret;
+                       goto error;
                }
 
-               ret = priv->secfeed->set(priv->secfeed, priv->pid, 32768, 0, 1);
+               ret = priv->secfeed->set(priv->secfeed, priv->pid, 32768, 1);
 
                if (ret<0) {
                        printk("%s: could not set section feed\n", dev->name);
                        priv->demux->release_section_feed(priv->demux, priv->secfeed);
                        priv->secfeed=NULL;
-                       return ret;
+                       goto error;
                }
 
                if (priv->rx_mode != RX_MODE_PROMISC) {
@@ -946,46 +1020,50 @@ static int dvb_net_feed_start(struct net_device *dev)
                dprintk("%s: start filtering\n", __FUNCTION__);
                priv->secfeed->start_filtering(priv->secfeed);
        } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
-               struct timespec timeout = { 0, 30000000 }; // 30 msec
+               struct timespec timeout = { 0, 10000000 }; // 10 msec
 
                /* we have payloads encapsulated in TS */
                dprintk("%s: alloc tsfeed\n", __FUNCTION__);
                ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback);
                if (ret < 0) {
                        printk("%s: could not allocate ts feed\n", dev->name);
-                       return ret;
+                       goto error;
                }
 
                /* Set netdevice pointer for ts decaps callback. */
                priv->tsfeed->priv = (void *)dev;
-               ret = priv->tsfeed->set(priv->tsfeed, priv->pid,
-                                       TS_PACKET, DMX_TS_PES_OTHER,
-                                       188 * 100, /* nr. of bytes delivered per callback */
+               ret = priv->tsfeed->set(priv->tsfeed,
+                                       priv->pid, /* pid */
+                                       TS_PACKET, /* type */
+                                       DMX_TS_PES_OTHER, /* pes type */
                                        32768,     /* circular buffer size */
-                                       0,         /* descramble */
-                                       timeout);
+                                       timeout    /* timeout */
+                                       );
 
                if (ret < 0) {
                        printk("%s: could not set ts feed\n", dev->name);
                        priv->demux->release_ts_feed(priv->demux, priv->tsfeed);
                        priv->tsfeed = NULL;
-                       return ret;
+                       goto error;
                }
 
                dprintk("%s: start filtering\n", __FUNCTION__);
                priv->tsfeed->start_filtering(priv->tsfeed);
        } else
-               return -EINVAL;
+               ret = -EINVAL;
 
-       return 0;
+error:
+       mutex_unlock(&priv->mutex);
+       return ret;
 }
 
 static int dvb_net_feed_stop(struct net_device *dev)
 {
        struct dvb_net_priv *priv = dev->priv;
-       int i;
+       int i, ret = 0;
 
        dprintk("%s\n", __FUNCTION__);
+       mutex_lock(&priv->mutex);
        if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
                if (priv->secfeed) {
                        if (priv->secfeed->is_filtering) {
@@ -1026,8 +1104,9 @@ static int dvb_net_feed_stop(struct net_device *dev)
                else
                        printk("%s: no ts feed to stop\n", dev->name);
        } else
-               return -EINVAL;
-       return 0;
+               ret = -EINVAL;
+       mutex_unlock(&priv->mutex);
+       return ret;
 }
 
 
@@ -1045,14 +1124,15 @@ static int dvb_set_mc_filter (struct net_device *dev, struct dev_mc_list *mc)
 }
 
 
-static void wq_set_multicast_list (void *data)
+static void wq_set_multicast_list (struct work_struct *work)
 {
-       struct net_device *dev = data;
-       struct dvb_net_priv *priv = dev->priv;
+       struct dvb_net_priv *priv =
+               container_of(work, struct dvb_net_priv, set_multicast_list_wq);
+       struct net_device *dev = priv->net;
 
        dvb_net_feed_stop(dev);
-
        priv->rx_mode = RX_MODE_UNI;
+       netif_tx_lock_bh(dev);
 
        if (dev->flags & IFF_PROMISC) {
                dprintk("%s: promiscuous mode\n", dev->name);
@@ -1077,6 +1157,7 @@ static void wq_set_multicast_list (void *data)
                }
        }
 
+       netif_tx_unlock_bh(dev);
        dvb_net_feed_start(dev);
 }
 
@@ -1088,9 +1169,11 @@ static void dvb_net_set_multicast_list (struct net_device *dev)
 }
 
 
-static void wq_restart_net_feed (void *data)
+static void wq_restart_net_feed (struct work_struct *work)
 {
-       struct net_device *dev = data;
+       struct dvb_net_priv *priv =
+               container_of(work, struct dvb_net_priv, restart_net_feed_wq);
+       struct net_device *dev = priv->net;
 
        if (netif_running(dev)) {
                dvb_net_feed_stop(dev);
@@ -1128,12 +1211,12 @@ static int dvb_net_stop(struct net_device *dev)
        struct dvb_net_priv *priv = dev->priv;
 
        priv->in_use--;
-        return dvb_net_feed_stop(dev);
+       return dvb_net_feed_stop(dev);
 }
 
 static struct net_device_stats * dvb_net_get_stats(struct net_device *dev)
 {
-        return &((struct dvb_net_priv*) dev->priv)->stats;
+       return &((struct dvb_net_priv*) dev->priv)->stats;
 }
 
 static void dvb_net_setup(struct net_device *dev)
@@ -1197,6 +1280,7 @@ static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype)
        dvbnet->device[if_num] = net;
 
        priv = net->priv;
+       priv->net = net;
        priv->demux = dvbnet->demux;
        priv->pid = pid;
        priv->rx_mode = RX_MODE_UNI;
@@ -1205,8 +1289,9 @@ static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype)
        priv->feedtype = feedtype;
        reset_ule(priv);
 
-       INIT_WORK(&priv->set_multicast_list_wq, wq_set_multicast_list, net);
-       INIT_WORK(&priv->restart_net_feed_wq, wq_restart_net_feed, net);
+       INIT_WORK(&priv->set_multicast_list_wq, wq_set_multicast_list);
+       INIT_WORK(&priv->restart_net_feed_wq, wq_restart_net_feed);
+       mutex_init(&priv->mutex);
 
        net->base_addr = pid;
 
@@ -1220,7 +1305,7 @@ static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype)
        return if_num;
 }
 
-static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned int num)
+static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned long num)
 {
        struct net_device *net = dvbnet->device[num];
        struct dvb_net_priv *priv;
@@ -1294,9 +1379,9 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
 
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
-               if ((unsigned int) parg >= DVB_NET_DEVICES_MAX)
+               if ((unsigned long) parg >= DVB_NET_DEVICES_MAX)
                        return -EINVAL;
-               ret = dvb_net_remove_if(dvbnet, (unsigned int) parg);
+               ret = dvb_net_remove_if(dvbnet, (unsigned long) parg);
                if (!ret)
                        module_put(dvbdev->adapter->module);
                return ret;
@@ -1358,10 +1443,10 @@ static struct file_operations dvb_net_fops = {
 };
 
 static struct dvb_device dvbdev_net = {
-        .priv = NULL,
-        .users = 1,
-        .writers = 1,
-        .fops = &dvb_net_fops,
+       .priv = NULL,
+       .users = 1,
+       .writers = 1,
+       .fops = &dvb_net_fops,
 };