4 * Copyright (C) 2001 Convergence integrated media GmbH
5 * Ralph Metzler <ralph@convergence.de>
6 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
8 * ULE Decapsulation code:
9 * Copyright (C) 2003, 2004 gcs - Global Communication & Services GmbH.
10 * and Department of Scientific Computing
11 * Paris Lodron University of Salzburg.
12 * Hilmar Linder <hlinder@cosy.sbg.ac.at>
13 * and Wolfram Stering <wstering@cosy.sbg.ac.at>
15 * ULE Decaps according to RFC 4326.
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 * To obtain the license, point your browser to
27 * http://www.gnu.org/copyleft/gpl.html
32 * Feb 2004: hl/ws v1: Implementing draft-fair-ipdvb-ule-01.txt
34 * Dec 2004: hl/ws v2: Implementing draft-ietf-ipdvb-ule-03.txt:
35 * ULE Extension header handling.
36 * Bugreports by Moritz Vieth and Hanno Tersteegen,
37 * Fraunhofer Institute for Open Communication Systems
38 * Competence Center for Advanced Satellite Communications.
39 * Bugfixes and robustness improvements.
40 * Filtering on dest MAC addresses, if present (D-Bit = 0)
41 * ULE_DEBUG compile-time option.
42 * Apr 2006: cp v3: Bugfixes and compliency with RFC 4326 (ULE) by
43 * Christian Praehauser <cpraehaus@cosy.sbg.ac.at>,
44 * Paris Lodron University of Salzburg.
48 * FIXME / TODO (dvb_net.c):
50 * Unloading does not work for 2.6.9 kernels: a refcount doesn't go to zero.
54 #define pr_fmt(fmt) "dvb_net: " fmt
56 #include <linux/module.h>
57 #include <linux/kernel.h>
58 #include <linux/netdevice.h>
59 #include <linux/etherdevice.h>
60 #include <linux/dvb/net.h>
61 #include <linux/uio.h>
62 #include <linux/uaccess.h>
63 #include <linux/crc32.h>
64 #include <linux/mutex.h>
65 #include <linux/sched.h>
67 #include "dvb_demux.h"
70 static inline __u32
iov_crc32( __u32 c
, struct kvec
*iov
, unsigned int cnt
)
73 for (j
= 0; j
< cnt
; j
++)
74 c
= crc32_be( c
, iov
[j
].iov_base
, iov
[j
].iov_len
);
79 #define DVB_NET_MULTICAST_MAX 10
85 static void hexdump(const unsigned char *buf
, unsigned short len
)
87 print_hex_dump_debug("", DUMP_PREFIX_OFFSET
, 16, 1, buf
, len
, true);
95 struct net_device
*net
;
97 struct dmx_demux
*demux
;
98 struct dmx_section_feed
*secfeed
;
99 struct dmx_section_filter
*secfilter
;
100 struct dmx_ts_feed
*tsfeed
;
102 struct dmx_section_filter
*multi_secfilter
[DVB_NET_MULTICAST_MAX
];
103 unsigned char multi_macs
[DVB_NET_MULTICAST_MAX
][6];
105 #define RX_MODE_UNI 0
106 #define RX_MODE_MULTI 1
107 #define RX_MODE_ALL_MULTI 2
108 #define RX_MODE_PROMISC 3
109 struct work_struct set_multicast_list_wq
;
110 struct work_struct restart_net_feed_wq
;
111 unsigned char feedtype
; /* Either FEED_TYPE_ or FEED_TYPE_ULE */
112 int need_pusi
; /* Set to 1, if synchronization on PUSI required. */
113 unsigned char tscc
; /* TS continuity counter after sync on PUSI. */
114 struct sk_buff
*ule_skb
; /* ULE SNDU decodes into this buffer. */
115 unsigned char *ule_next_hdr
; /* Pointer into skb to next ULE extension header. */
116 unsigned short ule_sndu_len
; /* ULE SNDU length in bytes, w/o D-Bit. */
117 unsigned short ule_sndu_type
; /* ULE SNDU type field, complete. */
118 unsigned char ule_sndu_type_1
; /* ULE SNDU type field, if split across 2 TS cells. */
119 unsigned char ule_dbit
; /* Whether the DestMAC address present
120 * or not (bit is set). */
121 unsigned char ule_bridged
; /* Whether the ULE_BRIDGED extension header was found. */
122 int ule_sndu_remain
; /* Nr. of bytes still required for current ULE SNDU. */
123 unsigned long ts_count
; /* Current ts cell counter. */
129 * Determine the packet's protocol ID. The rule here is that we
130 * assume 802.3 if the type field is short enough to be a length.
131 * This is normal practice and works for any 'now in use' protocol.
133 * stolen from eth.c out of the linux kernel, hacked for dvb-device
134 * by Michael Holzt <kju@debian.org>
136 static __be16
dvb_net_eth_type_trans(struct sk_buff
*skb
,
137 struct net_device
*dev
)
142 skb_reset_mac_header(skb
);
143 skb_pull(skb
,dev
->hard_header_len
);
146 if (*eth
->h_dest
& 1) {
147 if(ether_addr_equal(eth
->h_dest
,dev
->broadcast
))
148 skb
->pkt_type
=PACKET_BROADCAST
;
150 skb
->pkt_type
=PACKET_MULTICAST
;
153 if (ntohs(eth
->h_proto
) >= ETH_P_802_3_MIN
)
159 * This is a magic hack to spot IPX packets. Older Novell breaks
160 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
161 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
162 * won't work for fault tolerant netware but does for the rest.
164 if (*(unsigned short *)rawp
== 0xFFFF)
165 return htons(ETH_P_802_3
);
170 return htons(ETH_P_802_2
);
181 /* ULE Extension Header handlers. */
184 #define ULE_BRIDGED 1
186 #define ULE_OPTEXTHDR_PADDING 0
188 static int ule_test_sndu( struct dvb_net_priv
*p
)
193 static int ule_bridged_sndu( struct dvb_net_priv
*p
)
195 struct ethhdr
*hdr
= (struct ethhdr
*) p
->ule_next_hdr
;
196 if(ntohs(hdr
->h_proto
) < ETH_P_802_3_MIN
) {
197 int framelen
= p
->ule_sndu_len
- ((p
->ule_next_hdr
+sizeof(struct ethhdr
)) - p
->ule_skb
->data
);
198 /* A frame Type < ETH_P_802_3_MIN for a bridged frame, introduces a LLC Length field. */
199 if(framelen
!= ntohs(hdr
->h_proto
)) {
205 * "A bridged SNDU is a Mandatory Extension Header of Type 1.
206 * It must be the final (or only) extension header specified in the header chain of a SNDU."
207 * The 'ule_bridged' flag will cause the extension header processing loop to terminate.
213 static int ule_exthdr_padding(struct dvb_net_priv
*p
)
218 /** Handle ULE extension headers.
219 * Function is called after a successful CRC32 verification of an ULE SNDU to complete its decoding.
220 * Returns: >= 0: nr. of bytes consumed by next extension header
221 * -1: Mandatory extension header that is not recognized or TEST SNDU; discard.
223 static int handle_one_ule_extension( struct dvb_net_priv
*p
)
225 /* Table of mandatory extension header handlers. The header type is the index. */
226 static int (*ule_mandatory_ext_handlers
[255])( struct dvb_net_priv
*p
) =
227 { [0] = ule_test_sndu
, [1] = ule_bridged_sndu
, [2] = NULL
, };
229 /* Table of optional extension header handlers. The header type is the index. */
230 static int (*ule_optional_ext_handlers
[255])( struct dvb_net_priv
*p
) =
231 { [0] = ule_exthdr_padding
, [1] = NULL
, };
234 unsigned char hlen
= (p
->ule_sndu_type
& 0x0700) >> 8;
235 unsigned char htype
= p
->ule_sndu_type
& 0x00FF;
237 /* Discriminate mandatory and optional extension headers. */
239 /* Mandatory extension header */
240 if (ule_mandatory_ext_handlers
[htype
]) {
241 ext_len
= ule_mandatory_ext_handlers
[htype
]( p
);
243 p
->ule_next_hdr
+= ext_len
;
244 if (!p
->ule_bridged
) {
245 p
->ule_sndu_type
= ntohs(*(__be16
*)p
->ule_next_hdr
);
246 p
->ule_next_hdr
+= 2;
248 p
->ule_sndu_type
= ntohs(*(__be16
*)(p
->ule_next_hdr
+ ((p
->ule_dbit
? 2 : 3) * ETH_ALEN
)));
249 /* This assures the extension handling loop will terminate. */
252 // else: extension handler failed or SNDU should be discarded
254 ext_len
= -1; /* SNDU has to be discarded. */
256 /* Optional extension header. Calculate the length. */
258 /* Process the optional extension header according to its type. */
259 if (ule_optional_ext_handlers
[htype
])
260 (void)ule_optional_ext_handlers
[htype
]( p
);
261 p
->ule_next_hdr
+= ext_len
;
262 p
->ule_sndu_type
= ntohs( *(__be16
*)(p
->ule_next_hdr
-2) );
264 * note: the length of the next header type is included in the
265 * length of THIS optional extension header
272 static int handle_ule_extensions( struct dvb_net_priv
*p
)
274 int total_ext_len
= 0, l
;
276 p
->ule_next_hdr
= p
->ule_skb
->data
;
278 l
= handle_one_ule_extension( p
);
280 return l
; /* Stop extension header processing and discard SNDU. */
283 pr_debug("ule_next_hdr=%p, ule_sndu_type=%i, l=%i, total_ext_len=%i\n",
284 p
->ule_next_hdr
, (int)p
->ule_sndu_type
,
288 } while (p
->ule_sndu_type
< ETH_P_802_3_MIN
);
290 return total_ext_len
;
294 /** Prepare for a new ULE SNDU: reset the decoder state. */
295 static inline void reset_ule( struct dvb_net_priv
*p
)
298 p
->ule_next_hdr
= NULL
;
300 p
->ule_sndu_type
= 0;
301 p
->ule_sndu_type_1
= 0;
302 p
->ule_sndu_remain
= 0;
308 * Decode ULE SNDUs according to draft-ietf-ipdvb-ule-03.txt from a sequence of
309 * TS cells of a single PID.
312 struct dvb_net_ule_handle
{
313 struct net_device
*dev
;
314 struct dvb_net_priv
*priv
;
318 unsigned long skipped
;
319 const u8
*ts
, *ts_end
, *from_where
;
320 u8 ts_remain
, how_much
, new_ts
;
324 * The code inside ULE_DEBUG keeps a history of the
325 * last 100 TS cells processed.
327 static unsigned char ule_hist
[100*TS_SZ
];
328 static unsigned char *ule_where
= ule_hist
, ule_dump
;
332 static int dvb_net_ule_new_ts_cell(struct dvb_net_ule_handle
*h
)
334 /* We are about to process a new TS cell. */
337 if (h
->ule_where
>= &h
->ule_hist
[100*TS_SZ
])
338 h
->ule_where
= h
->ule_hist
;
339 memcpy(h
->ule_where
, h
->ts
, TS_SZ
);
341 hexdump(h
->ule_where
, TS_SZ
);
344 h
->ule_where
+= TS_SZ
;
348 * Check TS h->error conditions: sync_byte, transport_error_indicator,
349 * scrambling_control .
351 if ((h
->ts
[0] != TS_SYNC
) || (h
->ts
[1] & TS_TEI
) ||
352 ((h
->ts
[3] & TS_SC
) != 0)) {
353 pr_warn("%lu: Invalid TS cell: SYNC %#x, TEI %u, SC %#x.\n",
354 h
->priv
->ts_count
, h
->ts
[0],
355 (h
->ts
[1] & TS_TEI
) >> 7,
356 (h
->ts
[3] & TS_SC
) >> 6);
358 /* Drop partly decoded SNDU, reset state, resync on PUSI. */
359 if (h
->priv
->ule_skb
) {
360 dev_kfree_skb(h
->priv
->ule_skb
);
361 /* Prepare for next SNDU. */
362 h
->dev
->stats
.rx_errors
++;
363 h
->dev
->stats
.rx_frame_errors
++;
366 h
->priv
->need_pusi
= 1;
368 /* Continue with next TS cell. */
375 h
->from_where
= h
->ts
+ 4;
380 static int dvb_net_ule_ts_pusi(struct dvb_net_ule_handle
*h
)
382 if (h
->ts
[1] & TS_PUSI
) {
383 /* Find beginning of first ULE SNDU in current TS cell. */
384 /* Synchronize continuity counter. */
385 h
->priv
->tscc
= h
->ts
[3] & 0x0F;
386 /* There is a pointer field here. */
387 if (h
->ts
[4] > h
->ts_remain
) {
388 pr_err("%lu: Invalid ULE packet (pointer field %d)\n",
389 h
->priv
->ts_count
, h
->ts
[4]);
394 /* Skip to destination of pointer field. */
395 h
->from_where
= &h
->ts
[5] + h
->ts
[4];
396 h
->ts_remain
-= 1 + h
->ts
[4];
408 static int dvb_net_ule_new_ts(struct dvb_net_ule_handle
*h
)
410 /* Check continuity counter. */
411 if ((h
->ts
[3] & 0x0F) == h
->priv
->tscc
)
412 h
->priv
->tscc
= (h
->priv
->tscc
+ 1) & 0x0F;
414 /* TS discontinuity handling: */
415 pr_warn("%lu: TS discontinuity: got %#x, expected %#x.\n",
416 h
->priv
->ts_count
, h
->ts
[3] & 0x0F,
418 /* Drop partly decoded SNDU, reset state, resync on PUSI. */
419 if (h
->priv
->ule_skb
) {
420 dev_kfree_skb(h
->priv
->ule_skb
);
421 /* Prepare for next SNDU. */
422 // reset_ule(h->priv); moved to below.
423 h
->dev
->stats
.rx_errors
++;
424 h
->dev
->stats
.rx_frame_errors
++;
427 /* skip to next PUSI. */
428 h
->priv
->need_pusi
= 1;
432 * If we still have an incomplete payload, but PUSI is
433 * set; some TS cells are missing.
434 * This is only possible here, if we missed exactly 16 TS
435 * cells (continuity counter wrap).
437 if (h
->ts
[1] & TS_PUSI
) {
438 if (!h
->priv
->need_pusi
) {
439 if (!(*h
->from_where
< (h
->ts_remain
-1)) ||
440 *h
->from_where
!= h
->priv
->ule_sndu_remain
) {
442 * Pointer field is invalid.
443 * Drop this TS cell and any started ULE SNDU.
445 pr_warn("%lu: Invalid pointer field: %u.\n",
450 * Drop partly decoded SNDU, reset state,
453 if (h
->priv
->ule_skb
) {
455 dev_kfree_skb(h
->priv
->ule_skb
);
458 if (h
->error
|| h
->priv
->ule_sndu_remain
) {
459 h
->dev
->stats
.rx_errors
++;
460 h
->dev
->stats
.rx_frame_errors
++;
465 h
->priv
->need_pusi
= 1;
469 * Skip pointer field (we're processing a
475 h
->priv
->need_pusi
= 0;
477 if (h
->priv
->ule_sndu_remain
> 183) {
479 * Current SNDU lacks more data than there
480 * could be available in the current TS cell.
482 h
->dev
->stats
.rx_errors
++;
483 h
->dev
->stats
.rx_length_errors
++;
484 pr_warn("%lu: Expected %d more SNDU bytes, but got PUSI (pf %d, h->ts_remain %d). Flushing incomplete payload.\n",
486 h
->priv
->ule_sndu_remain
,
487 h
->ts
[4], h
->ts_remain
);
488 dev_kfree_skb(h
->priv
->ule_skb
);
489 /* Prepare for next SNDU. */
492 * Resync: go to where pointer field points to:
493 * start of next ULE SNDU.
495 h
->from_where
+= h
->ts
[4];
496 h
->ts_remain
-= h
->ts
[4];
504 * Start a new payload with skb.
505 * Find ULE header. It is only guaranteed that the
506 * length field (2 bytes) is contained in the current
508 * Check h.ts_remain has to be >= 2 here.
510 static int dvb_net_ule_new_payload(struct dvb_net_ule_handle
*h
)
512 if (h
->ts_remain
< 2) {
513 pr_warn("Invalid payload packing: only %d bytes left in TS. Resyncing.\n",
515 h
->priv
->ule_sndu_len
= 0;
516 h
->priv
->need_pusi
= 1;
521 if (!h
->priv
->ule_sndu_len
) {
522 /* Got at least two bytes, thus extrace the SNDU length. */
523 h
->priv
->ule_sndu_len
= h
->from_where
[0] << 8 |
525 if (h
->priv
->ule_sndu_len
& 0x8000) {
526 /* D-Bit is set: no dest mac present. */
527 h
->priv
->ule_sndu_len
&= 0x7FFF;
528 h
->priv
->ule_dbit
= 1;
530 h
->priv
->ule_dbit
= 0;
532 if (h
->priv
->ule_sndu_len
< 5) {
533 pr_warn("%lu: Invalid ULE SNDU length %u. Resyncing.\n",
535 h
->priv
->ule_sndu_len
);
536 h
->dev
->stats
.rx_errors
++;
537 h
->dev
->stats
.rx_length_errors
++;
538 h
->priv
->ule_sndu_len
= 0;
539 h
->priv
->need_pusi
= 1;
545 h
->ts_remain
-= 2; /* consume the 2 bytes SNDU length. */
549 h
->priv
->ule_sndu_remain
= h
->priv
->ule_sndu_len
+ 2;
551 * State of current TS:
552 * h->ts_remain (remaining bytes in the current TS cell)
553 * 0 ule_type is not available now, we need the next TS cell
554 * 1 the first byte of the ule_type is present
555 * >=2 full ULE header present, maybe some payload data as well.
557 switch (h
->ts_remain
) {
559 h
->priv
->ule_sndu_remain
--;
560 h
->priv
->ule_sndu_type
= h
->from_where
[0] << 8;
562 /* first byte of ule_type is set. */
563 h
->priv
->ule_sndu_type_1
= 1;
573 default: /* complete ULE header is present in current TS. */
574 /* Extract ULE type field. */
575 if (h
->priv
->ule_sndu_type_1
) {
576 h
->priv
->ule_sndu_type_1
= 0;
577 h
->priv
->ule_sndu_type
|= h
->from_where
[0];
578 h
->from_where
+= 1; /* points to payload start. */
581 /* Complete type is present in new TS. */
582 h
->priv
->ule_sndu_type
= h
->from_where
[0] << 8 |
584 h
->from_where
+= 2; /* points to payload start. */
591 * Allocate the skb (decoder target buffer) with the correct size,
594 * prepare for the largest case: bridged SNDU with MAC address
597 h
->priv
->ule_skb
= dev_alloc_skb(h
->priv
->ule_sndu_len
+
598 ETH_HLEN
+ ETH_ALEN
);
599 if (!h
->priv
->ule_skb
) {
600 pr_notice("%s: Memory squeeze, dropping packet.\n",
602 h
->dev
->stats
.rx_dropped
++;
606 /* This includes the CRC32 _and_ dest mac, if !dbit. */
607 h
->priv
->ule_sndu_remain
= h
->priv
->ule_sndu_len
;
608 h
->priv
->ule_skb
->dev
= h
->dev
;
610 * Leave space for Ethernet or bridged SNDU header
611 * (eth hdr plus one MAC addr).
613 skb_reserve(h
->priv
->ule_skb
, ETH_HLEN
+ ETH_ALEN
);
619 static int dvb_net_ule_should_drop(struct dvb_net_ule_handle
*h
)
621 static const u8 bc_addr
[ETH_ALEN
] = { [0 ... ETH_ALEN
- 1] = 0xff };
624 * The destination MAC address is the next data in the skb. It comes
625 * before any extension headers.
627 * Check if the payload of this SNDU should be passed up the stack.
629 if (h
->priv
->rx_mode
== RX_MODE_PROMISC
)
632 if (h
->priv
->ule_skb
->data
[0] & 0x01) {
633 /* multicast or broadcast */
634 if (!ether_addr_equal(h
->priv
->ule_skb
->data
, bc_addr
)) {
636 if (h
->priv
->rx_mode
== RX_MODE_MULTI
) {
639 for (i
= 0; i
< h
->priv
->multi_num
&&
640 !ether_addr_equal(h
->priv
->ule_skb
->data
,
641 h
->priv
->multi_macs
[i
]);
644 if (i
== h
->priv
->multi_num
)
646 } else if (h
->priv
->rx_mode
!= RX_MODE_ALL_MULTI
)
647 return 1; /* no broadcast; */
650 * all multicast mode: accept all multicast packets
653 /* else: broadcast */
654 } else if (!ether_addr_equal(h
->priv
->ule_skb
->data
, h
->dev
->dev_addr
))
661 static void dvb_net_ule_check_crc(struct dvb_net_ule_handle
*h
,
662 u32 ule_crc
, u32 expected_crc
)
664 u8 dest_addr
[ETH_ALEN
];
666 if (ule_crc
!= expected_crc
) {
667 pr_warn("%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
668 h
->priv
->ts_count
, ule_crc
, expected_crc
,
669 h
->priv
->ule_sndu_len
, h
->priv
->ule_sndu_type
,
672 *(unsigned short *)h
->from_where
: 0);
675 hexdump(iov
[0].iov_base
, iov
[0].iov_len
);
676 hexdump(iov
[1].iov_base
, iov
[1].iov_len
);
677 hexdump(iov
[2].iov_base
, iov
[2].iov_len
);
679 if (h
->ule_where
== h
->ule_hist
) {
680 hexdump(&h
->ule_hist
[98*TS_SZ
], TS_SZ
);
681 hexdump(&h
->ule_hist
[99*TS_SZ
], TS_SZ
);
682 } else if (h
->ule_where
== &h
->ule_hist
[TS_SZ
]) {
683 hexdump(&h
->ule_hist
[99*TS_SZ
], TS_SZ
);
684 hexdump(h
->ule_hist
, TS_SZ
);
686 hexdump(h
->ule_where
- TS_SZ
- TS_SZ
, TS_SZ
);
687 hexdump(h
->ule_where
- TS_SZ
, TS_SZ
);
692 h
->dev
->stats
.rx_errors
++;
693 h
->dev
->stats
.rx_crc_errors
++;
694 dev_kfree_skb(h
->priv
->ule_skb
);
699 /* CRC32 verified OK. */
701 /* CRC32 was OK, so remove it from skb. */
702 h
->priv
->ule_skb
->tail
-= 4;
703 h
->priv
->ule_skb
->len
-= 4;
705 if (!h
->priv
->ule_dbit
) {
706 if (dvb_net_ule_should_drop(h
)) {
709 "Dropping SNDU: MAC destination address does not match: dest addr: %pM, h->dev addr: %pM\n",
710 h
->priv
->ule_skb
->data
, h
->dev
->dev_addr
);
712 dev_kfree_skb(h
->priv
->ule_skb
);
716 skb_copy_from_linear_data(h
->priv
->ule_skb
, dest_addr
,
718 skb_pull(h
->priv
->ule_skb
, ETH_ALEN
);
720 /* dest_addr buffer is only valid if h->priv->ule_dbit == 0 */
721 eth_zero_addr(dest_addr
);
724 /* Handle ULE Extension Headers. */
725 if (h
->priv
->ule_sndu_type
< ETH_P_802_3_MIN
) {
726 /* There is an extension header. Handle it accordingly. */
727 int l
= handle_ule_extensions(h
->priv
);
731 * Mandatory extension header unknown or TEST SNDU.
735 // pr_warn("Dropping SNDU, extension headers.\n" );
736 dev_kfree_skb(h
->priv
->ule_skb
);
739 skb_pull(h
->priv
->ule_skb
, l
);
743 * Construct/assure correct ethernet header.
744 * Note: in bridged mode (h->priv->ule_bridged != 0)
745 * we already have the (original) ethernet
746 * header at the start of the payload (after
747 * optional dest. address and any extension
750 if (!h
->priv
->ule_bridged
) {
751 skb_push(h
->priv
->ule_skb
, ETH_HLEN
);
752 h
->ethh
= (struct ethhdr
*)h
->priv
->ule_skb
->data
;
753 memcpy(h
->ethh
->h_dest
, dest_addr
, ETH_ALEN
);
754 eth_zero_addr(h
->ethh
->h_source
);
755 h
->ethh
->h_proto
= htons(h
->priv
->ule_sndu_type
);
757 /* else: skb is in correct state; nothing to do. */
758 h
->priv
->ule_bridged
= 0;
760 /* Stuff into kernel's protocol stack. */
761 h
->priv
->ule_skb
->protocol
= dvb_net_eth_type_trans(h
->priv
->ule_skb
,
764 * If D-bit is set (i.e. destination MAC address not present),
765 * receive the packet anyhow.
768 if (h
->priv
->ule_dbit
&& skb
->pkt_type
== PACKET_OTHERHOST
)
769 h
->priv
->ule_skb
->pkt_type
= PACKET_HOST
;
771 h
->dev
->stats
.rx_packets
++;
772 h
->dev
->stats
.rx_bytes
+= h
->priv
->ule_skb
->len
;
773 netif_rx(h
->priv
->ule_skb
);
776 static void dvb_net_ule(struct net_device
*dev
, const u8
*buf
, size_t buf_len
)
779 struct dvb_net_ule_handle h
= {
793 .ule_where
= ule_hist
,
798 * For all TS cells in current buffer.
799 * Appearently, we are called for every single TS cell.
801 for (h
.ts
= h
.buf
, h
.ts_end
= h
.buf
+ h
.buf_len
;
802 h
.ts
< h
.ts_end
; /* no incr. */) {
804 /* We are about to process a new TS cell. */
805 if (dvb_net_ule_new_ts_cell(&h
))
809 /* Synchronize on PUSI, if required. */
810 if (h
.priv
->need_pusi
) {
811 if (dvb_net_ule_ts_pusi(&h
))
816 if (dvb_net_ule_new_ts(&h
))
820 /* Check if new payload needs to be started. */
821 if (h
.priv
->ule_skb
== NULL
) {
822 ret
= dvb_net_ule_new_payload(&h
);
829 /* Copy data into our current skb. */
830 h
.how_much
= min(h
.priv
->ule_sndu_remain
, (int)h
.ts_remain
);
831 memcpy(skb_put(h
.priv
->ule_skb
, h
.how_much
),
832 h
.from_where
, h
.how_much
);
833 h
.priv
->ule_sndu_remain
-= h
.how_much
;
834 h
.ts_remain
-= h
.how_much
;
835 h
.from_where
+= h
.how_much
;
837 /* Check for complete payload. */
838 if (h
.priv
->ule_sndu_remain
<= 0) {
839 /* Check CRC32, we've got it in our skb already. */
840 __be16 ulen
= htons(h
.priv
->ule_sndu_len
);
841 __be16 utype
= htons(h
.priv
->ule_sndu_type
);
843 struct kvec iov
[3] = {
844 { &ulen
, sizeof ulen
},
845 { &utype
, sizeof utype
},
846 { h
.priv
->ule_skb
->data
,
847 h
.priv
->ule_skb
->len
- 4 }
849 u32 ule_crc
= ~0L, expected_crc
;
850 if (h
.priv
->ule_dbit
) {
851 /* Set D-bit for CRC32 verification,
852 * if it was set originally. */
853 ulen
|= htons(0x8000);
856 ule_crc
= iov_crc32(ule_crc
, iov
, 3);
857 tail
= skb_tail_pointer(h
.priv
->ule_skb
);
858 expected_crc
= *(tail
- 4) << 24 |
863 dvb_net_ule_check_crc(&h
, ule_crc
, expected_crc
);
865 /* Prepare for next SNDU. */
869 /* More data in current TS (look at the bytes following the CRC32)? */
870 if (h
.ts_remain
>= 2 && *((unsigned short *)h
.from_where
) != 0xFFFF) {
871 /* Next ULE SNDU starts right there. */
873 h
.priv
->ule_skb
= NULL
;
874 h
.priv
->ule_sndu_type_1
= 0;
875 h
.priv
->ule_sndu_len
= 0;
876 // pr_warn("More data in current TS: [%#x %#x %#x %#x]\n",
877 // *(h.from_where + 0), *(h.from_where + 1),
878 // *(h.from_where + 2), *(h.from_where + 3));
879 // pr_warn("h.ts @ %p, stopped @ %p:\n", h.ts, h.from_where + 0);
880 // hexdump(h.ts, 188);
885 if (h
.priv
->ule_skb
== NULL
) {
886 h
.priv
->need_pusi
= 1;
887 h
.priv
->ule_sndu_type_1
= 0;
888 h
.priv
->ule_sndu_len
= 0;
891 } /* for all available TS cells */
894 static int dvb_net_ts_callback(const u8
*buffer1
, size_t buffer1_len
,
895 const u8
*buffer2
, size_t buffer2_len
,
896 struct dmx_ts_feed
*feed
)
898 struct net_device
*dev
= feed
->priv
;
901 pr_warn("buffer2 not NULL: %p.\n", buffer2
);
902 if (buffer1_len
> 32768)
903 pr_warn("length > 32k: %zu.\n", buffer1_len
);
904 /* pr_info("TS callback: %u bytes, %u TS cells @ %p.\n",
905 buffer1_len, buffer1_len / TS_SZ, buffer1); */
906 dvb_net_ule(dev
, buffer1
, buffer1_len
);
911 static void dvb_net_sec(struct net_device
*dev
,
912 const u8
*pkt
, int pkt_len
)
916 struct net_device_stats
*stats
= &dev
->stats
;
919 /* note: pkt_len includes a 32bit checksum */
921 pr_warn("%s: IP/MPE packet length = %d too small.\n",
924 stats
->rx_length_errors
++;
927 /* it seems some ISPs manage to screw up here, so we have to
928 * relax the error checks... */
930 if ((pkt
[5] & 0xfd) != 0xc1) {
931 /* drop scrambled or broken packets */
933 if ((pkt
[5] & 0x3c) != 0x00) {
937 stats
->rx_crc_errors
++;
941 /* handle LLC/SNAP, see rfc-1042 */
942 if (pkt_len
< 24 || memcmp(&pkt
[12], "\xaa\xaa\x03\0\0\0", 6)) {
949 /* FIXME: assemble datagram from multiple sections */
951 stats
->rx_frame_errors
++;
955 /* we have 14 byte ethernet header (ip header follows);
956 * 12 byte MPE header; 4 byte checksum; + 2 byte alignment, 8 byte LLC/SNAP
958 if (!(skb
= dev_alloc_skb(pkt_len
- 4 - 12 + 14 + 2 - snap
))) {
959 //pr_notice("%s: Memory squeeze, dropping packet.\n", dev->name);
963 skb_reserve(skb
, 2); /* longword align L3 header */
966 /* copy L3 payload */
967 eth
= (u8
*) skb_put(skb
, pkt_len
- 12 - 4 + 14 - snap
);
968 memcpy(eth
+ 14, pkt
+ 12 + snap
, pkt_len
- 12 - 4 - snap
);
970 /* create ethernet header: */
978 eth
[6]=eth
[7]=eth
[8]=eth
[9]=eth
[10]=eth
[11]=0;
984 /* protocol numbers are from rfc-1700 or
985 * http://www.iana.org/assignments/ethernet-numbers
987 if (pkt
[12] >> 4 == 6) { /* version field from IP header */
988 eth
[12] = 0x86; /* IPv6 */
991 eth
[12] = 0x08; /* IPv4 */
996 skb
->protocol
= dvb_net_eth_type_trans(skb
, dev
);
999 stats
->rx_bytes
+=skb
->len
;
1003 static int dvb_net_sec_callback(const u8
*buffer1
, size_t buffer1_len
,
1004 const u8
*buffer2
, size_t buffer2_len
,
1005 struct dmx_section_filter
*filter
)
1007 struct net_device
*dev
= filter
->priv
;
1010 * we rely on the DVB API definition where exactly one complete
1011 * section is delivered in buffer1
1013 dvb_net_sec (dev
, buffer1
, buffer1_len
);
1017 static int dvb_net_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1020 return NETDEV_TX_OK
;
1023 static u8 mask_normal
[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1024 static u8 mask_allmulti
[6]={0xff, 0xff, 0xff, 0x00, 0x00, 0x00};
1025 static u8 mac_allmulti
[6]={0x01, 0x00, 0x5e, 0x00, 0x00, 0x00};
1026 static u8 mask_promisc
[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1028 static int dvb_net_filter_sec_set(struct net_device
*dev
,
1029 struct dmx_section_filter
**secfilter
,
1030 u8
*mac
, u8
*mac_mask
)
1032 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1036 ret
= priv
->secfeed
->allocate_filter(priv
->secfeed
, secfilter
);
1038 pr_err("%s: could not get filter\n", dev
->name
);
1042 (*secfilter
)->priv
=(void *) dev
;
1044 memset((*secfilter
)->filter_value
, 0x00, DMX_MAX_FILTER_SIZE
);
1045 memset((*secfilter
)->filter_mask
, 0x00, DMX_MAX_FILTER_SIZE
);
1046 memset((*secfilter
)->filter_mode
, 0xff, DMX_MAX_FILTER_SIZE
);
1048 (*secfilter
)->filter_value
[0]=0x3e;
1049 (*secfilter
)->filter_value
[3]=mac
[5];
1050 (*secfilter
)->filter_value
[4]=mac
[4];
1051 (*secfilter
)->filter_value
[8]=mac
[3];
1052 (*secfilter
)->filter_value
[9]=mac
[2];
1053 (*secfilter
)->filter_value
[10]=mac
[1];
1054 (*secfilter
)->filter_value
[11]=mac
[0];
1056 (*secfilter
)->filter_mask
[0] = 0xff;
1057 (*secfilter
)->filter_mask
[3] = mac_mask
[5];
1058 (*secfilter
)->filter_mask
[4] = mac_mask
[4];
1059 (*secfilter
)->filter_mask
[8] = mac_mask
[3];
1060 (*secfilter
)->filter_mask
[9] = mac_mask
[2];
1061 (*secfilter
)->filter_mask
[10] = mac_mask
[1];
1062 (*secfilter
)->filter_mask
[11]=mac_mask
[0];
1064 netdev_dbg(dev
, "filter mac=%pM mask=%pM\n", mac
, mac_mask
);
1069 static int dvb_net_feed_start(struct net_device
*dev
)
1072 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1073 struct dmx_demux
*demux
= priv
->demux
;
1074 unsigned char *mac
= (unsigned char *) dev
->dev_addr
;
1076 netdev_dbg(dev
, "rx_mode %i\n", priv
->rx_mode
);
1077 mutex_lock(&priv
->mutex
);
1078 if (priv
->tsfeed
|| priv
->secfeed
|| priv
->secfilter
|| priv
->multi_secfilter
[0])
1079 pr_err("%s: BUG %d\n", __func__
, __LINE__
);
1082 priv
->secfilter
=NULL
;
1083 priv
->tsfeed
= NULL
;
1085 if (priv
->feedtype
== DVB_NET_FEEDTYPE_MPE
) {
1086 netdev_dbg(dev
, "alloc secfeed\n");
1087 ret
=demux
->allocate_section_feed(demux
, &priv
->secfeed
,
1088 dvb_net_sec_callback
);
1090 pr_err("%s: could not allocate section feed\n",
1095 ret
= priv
->secfeed
->set(priv
->secfeed
, priv
->pid
, 1);
1098 pr_err("%s: could not set section feed\n", dev
->name
);
1099 priv
->demux
->release_section_feed(priv
->demux
, priv
->secfeed
);
1104 if (priv
->rx_mode
!= RX_MODE_PROMISC
) {
1105 netdev_dbg(dev
, "set secfilter\n");
1106 dvb_net_filter_sec_set(dev
, &priv
->secfilter
, mac
, mask_normal
);
1109 switch (priv
->rx_mode
) {
1111 for (i
= 0; i
< priv
->multi_num
; i
++) {
1112 netdev_dbg(dev
, "set multi_secfilter[%d]\n", i
);
1113 dvb_net_filter_sec_set(dev
, &priv
->multi_secfilter
[i
],
1114 priv
->multi_macs
[i
], mask_normal
);
1117 case RX_MODE_ALL_MULTI
:
1119 netdev_dbg(dev
, "set multi_secfilter[0]\n");
1120 dvb_net_filter_sec_set(dev
, &priv
->multi_secfilter
[0],
1121 mac_allmulti
, mask_allmulti
);
1123 case RX_MODE_PROMISC
:
1125 netdev_dbg(dev
, "set secfilter\n");
1126 dvb_net_filter_sec_set(dev
, &priv
->secfilter
, mac
, mask_promisc
);
1130 netdev_dbg(dev
, "start filtering\n");
1131 priv
->secfeed
->start_filtering(priv
->secfeed
);
1132 } else if (priv
->feedtype
== DVB_NET_FEEDTYPE_ULE
) {
1133 ktime_t timeout
= ns_to_ktime(10 * NSEC_PER_MSEC
);
1135 /* we have payloads encapsulated in TS */
1136 netdev_dbg(dev
, "alloc tsfeed\n");
1137 ret
= demux
->allocate_ts_feed(demux
, &priv
->tsfeed
, dvb_net_ts_callback
);
1139 pr_err("%s: could not allocate ts feed\n", dev
->name
);
1143 /* Set netdevice pointer for ts decaps callback. */
1144 priv
->tsfeed
->priv
= (void *)dev
;
1145 ret
= priv
->tsfeed
->set(priv
->tsfeed
,
1146 priv
->pid
, /* pid */
1147 TS_PACKET
, /* type */
1148 DMX_PES_OTHER
, /* pes type */
1149 timeout
/* timeout */
1153 pr_err("%s: could not set ts feed\n", dev
->name
);
1154 priv
->demux
->release_ts_feed(priv
->demux
, priv
->tsfeed
);
1155 priv
->tsfeed
= NULL
;
1159 netdev_dbg(dev
, "start filtering\n");
1160 priv
->tsfeed
->start_filtering(priv
->tsfeed
);
1165 mutex_unlock(&priv
->mutex
);
1169 static int dvb_net_feed_stop(struct net_device
*dev
)
1171 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1174 mutex_lock(&priv
->mutex
);
1175 if (priv
->feedtype
== DVB_NET_FEEDTYPE_MPE
) {
1176 if (priv
->secfeed
) {
1177 if (priv
->secfeed
->is_filtering
) {
1178 netdev_dbg(dev
, "stop secfeed\n");
1179 priv
->secfeed
->stop_filtering(priv
->secfeed
);
1182 if (priv
->secfilter
) {
1183 netdev_dbg(dev
, "release secfilter\n");
1184 priv
->secfeed
->release_filter(priv
->secfeed
,
1186 priv
->secfilter
=NULL
;
1189 for (i
=0; i
<priv
->multi_num
; i
++) {
1190 if (priv
->multi_secfilter
[i
]) {
1191 netdev_dbg(dev
, "release multi_filter[%d]\n",
1193 priv
->secfeed
->release_filter(priv
->secfeed
,
1194 priv
->multi_secfilter
[i
]);
1195 priv
->multi_secfilter
[i
] = NULL
;
1199 priv
->demux
->release_section_feed(priv
->demux
, priv
->secfeed
);
1200 priv
->secfeed
= NULL
;
1202 pr_err("%s: no feed to stop\n", dev
->name
);
1203 } else if (priv
->feedtype
== DVB_NET_FEEDTYPE_ULE
) {
1205 if (priv
->tsfeed
->is_filtering
) {
1206 netdev_dbg(dev
, "stop tsfeed\n");
1207 priv
->tsfeed
->stop_filtering(priv
->tsfeed
);
1209 priv
->demux
->release_ts_feed(priv
->demux
, priv
->tsfeed
);
1210 priv
->tsfeed
= NULL
;
1213 pr_err("%s: no ts feed to stop\n", dev
->name
);
1216 mutex_unlock(&priv
->mutex
);
1221 static int dvb_set_mc_filter(struct net_device
*dev
, unsigned char *addr
)
1223 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1225 if (priv
->multi_num
== DVB_NET_MULTICAST_MAX
)
1228 memcpy(priv
->multi_macs
[priv
->multi_num
], addr
, ETH_ALEN
);
1235 static void wq_set_multicast_list (struct work_struct
*work
)
1237 struct dvb_net_priv
*priv
=
1238 container_of(work
, struct dvb_net_priv
, set_multicast_list_wq
);
1239 struct net_device
*dev
= priv
->net
;
1241 dvb_net_feed_stop(dev
);
1242 priv
->rx_mode
= RX_MODE_UNI
;
1243 netif_addr_lock_bh(dev
);
1245 if (dev
->flags
& IFF_PROMISC
) {
1246 netdev_dbg(dev
, "promiscuous mode\n");
1247 priv
->rx_mode
= RX_MODE_PROMISC
;
1248 } else if ((dev
->flags
& IFF_ALLMULTI
)) {
1249 netdev_dbg(dev
, "allmulti mode\n");
1250 priv
->rx_mode
= RX_MODE_ALL_MULTI
;
1251 } else if (!netdev_mc_empty(dev
)) {
1252 struct netdev_hw_addr
*ha
;
1254 netdev_dbg(dev
, "set_mc_list, %d entries\n",
1255 netdev_mc_count(dev
));
1257 priv
->rx_mode
= RX_MODE_MULTI
;
1258 priv
->multi_num
= 0;
1260 netdev_for_each_mc_addr(ha
, dev
)
1261 dvb_set_mc_filter(dev
, ha
->addr
);
1264 netif_addr_unlock_bh(dev
);
1265 dvb_net_feed_start(dev
);
1269 static void dvb_net_set_multicast_list (struct net_device
*dev
)
1271 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1272 schedule_work(&priv
->set_multicast_list_wq
);
1276 static void wq_restart_net_feed (struct work_struct
*work
)
1278 struct dvb_net_priv
*priv
=
1279 container_of(work
, struct dvb_net_priv
, restart_net_feed_wq
);
1280 struct net_device
*dev
= priv
->net
;
1282 if (netif_running(dev
)) {
1283 dvb_net_feed_stop(dev
);
1284 dvb_net_feed_start(dev
);
1289 static int dvb_net_set_mac (struct net_device
*dev
, void *p
)
1291 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1292 struct sockaddr
*addr
=p
;
1294 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1296 if (netif_running(dev
))
1297 schedule_work(&priv
->restart_net_feed_wq
);
1303 static int dvb_net_open(struct net_device
*dev
)
1305 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1308 dvb_net_feed_start(dev
);
1313 static int dvb_net_stop(struct net_device
*dev
)
1315 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1318 return dvb_net_feed_stop(dev
);
1321 static const struct header_ops dvb_header_ops
= {
1322 .create
= eth_header
,
1323 .parse
= eth_header_parse
,
1327 static const struct net_device_ops dvb_netdev_ops
= {
1328 .ndo_open
= dvb_net_open
,
1329 .ndo_stop
= dvb_net_stop
,
1330 .ndo_start_xmit
= dvb_net_tx
,
1331 .ndo_set_rx_mode
= dvb_net_set_multicast_list
,
1332 .ndo_set_mac_address
= dvb_net_set_mac
,
1333 .ndo_validate_addr
= eth_validate_addr
,
1336 static void dvb_net_setup(struct net_device
*dev
)
1340 dev
->header_ops
= &dvb_header_ops
;
1341 dev
->netdev_ops
= &dvb_netdev_ops
;
1343 dev
->max_mtu
= 4096;
1345 dev
->flags
|= IFF_NOARP
;
1348 static int get_if(struct dvb_net
*dvbnet
)
1352 for (i
=0; i
<DVB_NET_DEVICES_MAX
; i
++)
1353 if (!dvbnet
->state
[i
])
1356 if (i
== DVB_NET_DEVICES_MAX
)
1363 static int dvb_net_add_if(struct dvb_net
*dvbnet
, u16 pid
, u8 feedtype
)
1365 struct net_device
*net
;
1366 struct dvb_net_priv
*priv
;
1370 if (feedtype
!= DVB_NET_FEEDTYPE_MPE
&& feedtype
!= DVB_NET_FEEDTYPE_ULE
)
1372 if ((if_num
= get_if(dvbnet
)) < 0)
1375 net
= alloc_netdev(sizeof(struct dvb_net_priv
), "dvb",
1376 NET_NAME_UNKNOWN
, dvb_net_setup
);
1380 if (dvbnet
->dvbdev
->id
)
1381 snprintf(net
->name
, IFNAMSIZ
, "dvb%d%u%d",
1382 dvbnet
->dvbdev
->adapter
->num
, dvbnet
->dvbdev
->id
, if_num
);
1384 /* compatibility fix to keep dvb0_0 format */
1385 snprintf(net
->name
, IFNAMSIZ
, "dvb%d_%d",
1386 dvbnet
->dvbdev
->adapter
->num
, if_num
);
1389 memcpy(net
->dev_addr
, dvbnet
->dvbdev
->adapter
->proposed_mac
, 6);
1391 dvbnet
->device
[if_num
] = net
;
1393 priv
= netdev_priv(net
);
1395 priv
->demux
= dvbnet
->demux
;
1397 priv
->rx_mode
= RX_MODE_UNI
;
1398 priv
->need_pusi
= 1;
1400 priv
->feedtype
= feedtype
;
1403 INIT_WORK(&priv
->set_multicast_list_wq
, wq_set_multicast_list
);
1404 INIT_WORK(&priv
->restart_net_feed_wq
, wq_restart_net_feed
);
1405 mutex_init(&priv
->mutex
);
1407 net
->base_addr
= pid
;
1409 if ((result
= register_netdev(net
)) < 0) {
1410 dvbnet
->device
[if_num
] = NULL
;
1414 pr_info("created network interface %s\n", net
->name
);
1419 static int dvb_net_remove_if(struct dvb_net
*dvbnet
, unsigned long num
)
1421 struct net_device
*net
= dvbnet
->device
[num
];
1422 struct dvb_net_priv
*priv
;
1424 if (!dvbnet
->state
[num
])
1426 priv
= netdev_priv(net
);
1431 flush_work(&priv
->set_multicast_list_wq
);
1432 flush_work(&priv
->restart_net_feed_wq
);
1433 pr_info("removed network interface %s\n", net
->name
);
1434 unregister_netdev(net
);
1435 dvbnet
->state
[num
]=0;
1436 dvbnet
->device
[num
] = NULL
;
1442 static int dvb_net_do_ioctl(struct file
*file
,
1443 unsigned int cmd
, void *parg
)
1445 struct dvb_device
*dvbdev
= file
->private_data
;
1446 struct dvb_net
*dvbnet
= dvbdev
->priv
;
1449 if (((file
->f_flags
&O_ACCMODE
)==O_RDONLY
))
1452 if (mutex_lock_interruptible(&dvbnet
->ioctl_mutex
))
1453 return -ERESTARTSYS
;
1458 struct dvb_net_if
*dvbnetif
= parg
;
1461 if (!capable(CAP_SYS_ADMIN
)) {
1466 if (!try_module_get(dvbdev
->adapter
->module
)) {
1471 result
=dvb_net_add_if(dvbnet
, dvbnetif
->pid
, dvbnetif
->feedtype
);
1473 module_put(dvbdev
->adapter
->module
);
1477 dvbnetif
->if_num
=result
;
1482 struct net_device
*netdev
;
1483 struct dvb_net_priv
*priv_data
;
1484 struct dvb_net_if
*dvbnetif
= parg
;
1486 if (dvbnetif
->if_num
>= DVB_NET_DEVICES_MAX
||
1487 !dvbnet
->state
[dvbnetif
->if_num
]) {
1492 netdev
= dvbnet
->device
[dvbnetif
->if_num
];
1494 priv_data
= netdev_priv(netdev
);
1495 dvbnetif
->pid
=priv_data
->pid
;
1496 dvbnetif
->feedtype
=priv_data
->feedtype
;
1501 if (!capable(CAP_SYS_ADMIN
)) {
1505 if ((unsigned long) parg
>= DVB_NET_DEVICES_MAX
) {
1509 ret
= dvb_net_remove_if(dvbnet
, (unsigned long) parg
);
1511 module_put(dvbdev
->adapter
->module
);
1515 /* binary compatibility cruft */
1516 case __NET_ADD_IF_OLD
:
1518 struct __dvb_net_if_old
*dvbnetif
= parg
;
1521 if (!capable(CAP_SYS_ADMIN
)) {
1526 if (!try_module_get(dvbdev
->adapter
->module
)) {
1531 result
=dvb_net_add_if(dvbnet
, dvbnetif
->pid
, DVB_NET_FEEDTYPE_MPE
);
1533 module_put(dvbdev
->adapter
->module
);
1537 dvbnetif
->if_num
=result
;
1540 case __NET_GET_IF_OLD
:
1542 struct net_device
*netdev
;
1543 struct dvb_net_priv
*priv_data
;
1544 struct __dvb_net_if_old
*dvbnetif
= parg
;
1546 if (dvbnetif
->if_num
>= DVB_NET_DEVICES_MAX
||
1547 !dvbnet
->state
[dvbnetif
->if_num
]) {
1552 netdev
= dvbnet
->device
[dvbnetif
->if_num
];
1554 priv_data
= netdev_priv(netdev
);
1555 dvbnetif
->pid
=priv_data
->pid
;
1564 mutex_unlock(&dvbnet
->ioctl_mutex
);
1568 static long dvb_net_ioctl(struct file
*file
,
1569 unsigned int cmd
, unsigned long arg
)
1571 return dvb_usercopy(file
, cmd
, arg
, dvb_net_do_ioctl
);
1574 static int dvb_net_close(struct inode
*inode
, struct file
*file
)
1576 struct dvb_device
*dvbdev
= file
->private_data
;
1577 struct dvb_net
*dvbnet
= dvbdev
->priv
;
1579 dvb_generic_release(inode
, file
);
1581 if(dvbdev
->users
== 1 && dvbnet
->exit
== 1)
1582 wake_up(&dvbdev
->wait_queue
);
1587 static const struct file_operations dvb_net_fops
= {
1588 .owner
= THIS_MODULE
,
1589 .unlocked_ioctl
= dvb_net_ioctl
,
1590 .open
= dvb_generic_open
,
1591 .release
= dvb_net_close
,
1592 .llseek
= noop_llseek
,
1595 static const struct dvb_device dvbdev_net
= {
1599 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
1602 .fops
= &dvb_net_fops
,
1605 void dvb_net_release (struct dvb_net
*dvbnet
)
1610 if (dvbnet
->dvbdev
->users
< 1)
1611 wait_event(dvbnet
->dvbdev
->wait_queue
,
1612 dvbnet
->dvbdev
->users
==1);
1614 dvb_unregister_device(dvbnet
->dvbdev
);
1616 for (i
=0; i
<DVB_NET_DEVICES_MAX
; i
++) {
1617 if (!dvbnet
->state
[i
])
1619 dvb_net_remove_if(dvbnet
, i
);
1622 EXPORT_SYMBOL(dvb_net_release
);
1625 int dvb_net_init (struct dvb_adapter
*adap
, struct dvb_net
*dvbnet
,
1626 struct dmx_demux
*dmx
)
1630 mutex_init(&dvbnet
->ioctl_mutex
);
1631 dvbnet
->demux
= dmx
;
1633 for (i
=0; i
<DVB_NET_DEVICES_MAX
; i
++)
1634 dvbnet
->state
[i
] = 0;
1636 return dvb_register_device(adap
, &dvbnet
->dvbdev
, &dvbdev_net
,
1637 dvbnet
, DVB_DEVICE_NET
, 0);
1639 EXPORT_SYMBOL(dvb_net_init
);