1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2001 Convergence integrated media GmbH
6 * Ralph Metzler <ralph@convergence.de>
7 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
9 * ULE Decapsulation code:
10 * Copyright (C) 2003, 2004 gcs - Global Communication & Services GmbH.
11 * and Department of Scientific Computing
12 * Paris Lodron University of Salzburg.
13 * Hilmar Linder <hlinder@cosy.sbg.ac.at>
14 * and Wolfram Stering <wstering@cosy.sbg.ac.at>
16 * ULE Decaps according to RFC 4326.
21 * Feb 2004: hl/ws v1: Implementing draft-fair-ipdvb-ule-01.txt
23 * Dec 2004: hl/ws v2: Implementing draft-ietf-ipdvb-ule-03.txt:
24 * ULE Extension header handling.
25 * Bugreports by Moritz Vieth and Hanno Tersteegen,
26 * Fraunhofer Institute for Open Communication Systems
27 * Competence Center for Advanced Satellite Communications.
28 * Bugfixes and robustness improvements.
29 * Filtering on dest MAC addresses, if present (D-Bit = 0)
30 * DVB_ULE_DEBUG compile-time option.
31 * Apr 2006: cp v3: Bugfixes and compliency with RFC 4326 (ULE) by
32 * Christian Praehauser <cpraehaus@cosy.sbg.ac.at>,
33 * Paris Lodron University of Salzburg.
37 * FIXME / TODO (dvb_net.c):
39 * Unloading does not work for 2.6.9 kernels: a refcount doesn't go to zero.
43 #define pr_fmt(fmt) "dvb_net: " fmt
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/netdevice.h>
48 #include <linux/etherdevice.h>
49 #include <linux/dvb/net.h>
50 #include <linux/uio.h>
51 #include <linux/uaccess.h>
52 #include <linux/crc32.h>
53 #include <linux/mutex.h>
54 #include <linux/sched.h>
56 #include <media/dvb_demux.h>
57 #include <media/dvb_net.h>
59 static inline __u32
iov_crc32( __u32 c
, struct kvec
*iov
, unsigned int cnt
)
62 for (j
= 0; j
< cnt
; j
++)
63 c
= crc32_be( c
, iov
[j
].iov_base
, iov
[j
].iov_len
);
68 #define DVB_NET_MULTICAST_MAX 10
72 * The code inside DVB_ULE_DEBUG keeps a history of the
73 * last 100 TS cells processed.
75 static unsigned char ule_hist
[100*TS_SZ
] = { 0 };
76 static unsigned char *ule_where
= ule_hist
, ule_dump
;
78 static void hexdump(const unsigned char *buf
, unsigned short len
)
80 print_hex_dump_debug("", DUMP_PREFIX_OFFSET
, 16, 1, buf
, len
, true);
87 struct net_device
*net
;
89 struct dmx_demux
*demux
;
90 struct dmx_section_feed
*secfeed
;
91 struct dmx_section_filter
*secfilter
;
92 struct dmx_ts_feed
*tsfeed
;
94 struct dmx_section_filter
*multi_secfilter
[DVB_NET_MULTICAST_MAX
];
95 unsigned char multi_macs
[DVB_NET_MULTICAST_MAX
][6];
98 #define RX_MODE_MULTI 1
99 #define RX_MODE_ALL_MULTI 2
100 #define RX_MODE_PROMISC 3
101 struct work_struct set_multicast_list_wq
;
102 struct work_struct restart_net_feed_wq
;
103 unsigned char feedtype
; /* Either FEED_TYPE_ or FEED_TYPE_ULE */
104 int need_pusi
; /* Set to 1, if synchronization on PUSI required. */
105 unsigned char tscc
; /* TS continuity counter after sync on PUSI. */
106 struct sk_buff
*ule_skb
; /* ULE SNDU decodes into this buffer. */
107 unsigned char *ule_next_hdr
; /* Pointer into skb to next ULE extension header. */
108 unsigned short ule_sndu_len
; /* ULE SNDU length in bytes, w/o D-Bit. */
109 unsigned short ule_sndu_type
; /* ULE SNDU type field, complete. */
110 unsigned char ule_sndu_type_1
; /* ULE SNDU type field, if split across 2 TS cells. */
111 unsigned char ule_dbit
; /* Whether the DestMAC address present
112 * or not (bit is set). */
113 unsigned char ule_bridged
; /* Whether the ULE_BRIDGED extension header was found. */
114 int ule_sndu_remain
; /* Nr. of bytes still required for current ULE SNDU. */
115 unsigned long ts_count
; /* Current ts cell counter. */
121 * Determine the packet's protocol ID. The rule here is that we
122 * assume 802.3 if the type field is short enough to be a length.
123 * This is normal practice and works for any 'now in use' protocol.
125 * stolen from eth.c out of the linux kernel, hacked for dvb-device
126 * by Michael Holzt <kju@debian.org>
128 static __be16
dvb_net_eth_type_trans(struct sk_buff
*skb
,
129 struct net_device
*dev
)
134 skb_reset_mac_header(skb
);
135 skb_pull(skb
,dev
->hard_header_len
);
138 if (*eth
->h_dest
& 1) {
139 if(ether_addr_equal(eth
->h_dest
,dev
->broadcast
))
140 skb
->pkt_type
=PACKET_BROADCAST
;
142 skb
->pkt_type
=PACKET_MULTICAST
;
145 if (ntohs(eth
->h_proto
) >= ETH_P_802_3_MIN
)
151 * This is a magic hack to spot IPX packets. Older Novell breaks
152 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
153 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
154 * won't work for fault tolerant netware but does for the rest.
156 if (*(unsigned short *)rawp
== 0xFFFF)
157 return htons(ETH_P_802_3
);
162 return htons(ETH_P_802_2
);
173 /* ULE Extension Header handlers. */
176 #define ULE_BRIDGED 1
178 #define ULE_OPTEXTHDR_PADDING 0
180 static int ule_test_sndu( struct dvb_net_priv
*p
)
185 static int ule_bridged_sndu( struct dvb_net_priv
*p
)
187 struct ethhdr
*hdr
= (struct ethhdr
*) p
->ule_next_hdr
;
188 if(ntohs(hdr
->h_proto
) < ETH_P_802_3_MIN
) {
189 int framelen
= p
->ule_sndu_len
- ((p
->ule_next_hdr
+sizeof(struct ethhdr
)) - p
->ule_skb
->data
);
190 /* A frame Type < ETH_P_802_3_MIN for a bridged frame, introduces a LLC Length field. */
191 if(framelen
!= ntohs(hdr
->h_proto
)) {
197 * "A bridged SNDU is a Mandatory Extension Header of Type 1.
198 * It must be the final (or only) extension header specified in the header chain of a SNDU."
199 * The 'ule_bridged' flag will cause the extension header processing loop to terminate.
205 static int ule_exthdr_padding(struct dvb_net_priv
*p
)
211 * Handle ULE extension headers.
212 * Function is called after a successful CRC32 verification of an ULE SNDU to complete its decoding.
213 * Returns: >= 0: nr. of bytes consumed by next extension header
214 * -1: Mandatory extension header that is not recognized or TEST SNDU; discard.
216 static int handle_one_ule_extension( struct dvb_net_priv
*p
)
218 /* Table of mandatory extension header handlers. The header type is the index. */
219 static int (*ule_mandatory_ext_handlers
[255])( struct dvb_net_priv
*p
) =
220 { [0] = ule_test_sndu
, [1] = ule_bridged_sndu
, [2] = NULL
, };
222 /* Table of optional extension header handlers. The header type is the index. */
223 static int (*ule_optional_ext_handlers
[255])( struct dvb_net_priv
*p
) =
224 { [0] = ule_exthdr_padding
, [1] = NULL
, };
227 unsigned char hlen
= (p
->ule_sndu_type
& 0x0700) >> 8;
228 unsigned char htype
= p
->ule_sndu_type
& 0x00FF;
230 /* Discriminate mandatory and optional extension headers. */
232 /* Mandatory extension header */
233 if (ule_mandatory_ext_handlers
[htype
]) {
234 ext_len
= ule_mandatory_ext_handlers
[htype
]( p
);
236 p
->ule_next_hdr
+= ext_len
;
237 if (!p
->ule_bridged
) {
238 p
->ule_sndu_type
= ntohs(*(__be16
*)p
->ule_next_hdr
);
239 p
->ule_next_hdr
+= 2;
241 p
->ule_sndu_type
= ntohs(*(__be16
*)(p
->ule_next_hdr
+ ((p
->ule_dbit
? 2 : 3) * ETH_ALEN
)));
242 /* This assures the extension handling loop will terminate. */
245 // else: extension handler failed or SNDU should be discarded
247 ext_len
= -1; /* SNDU has to be discarded. */
249 /* Optional extension header. Calculate the length. */
251 /* Process the optional extension header according to its type. */
252 if (ule_optional_ext_handlers
[htype
])
253 (void)ule_optional_ext_handlers
[htype
]( p
);
254 p
->ule_next_hdr
+= ext_len
;
255 p
->ule_sndu_type
= ntohs( *(__be16
*)(p
->ule_next_hdr
-2) );
257 * note: the length of the next header type is included in the
258 * length of THIS optional extension header
265 static int handle_ule_extensions( struct dvb_net_priv
*p
)
267 int total_ext_len
= 0, l
;
269 p
->ule_next_hdr
= p
->ule_skb
->data
;
271 l
= handle_one_ule_extension( p
);
273 return l
; /* Stop extension header processing and discard SNDU. */
275 pr_debug("ule_next_hdr=%p, ule_sndu_type=%i, l=%i, total_ext_len=%i\n",
276 p
->ule_next_hdr
, (int)p
->ule_sndu_type
,
279 } while (p
->ule_sndu_type
< ETH_P_802_3_MIN
);
281 return total_ext_len
;
285 /* Prepare for a new ULE SNDU: reset the decoder state. */
286 static inline void reset_ule( struct dvb_net_priv
*p
)
289 p
->ule_next_hdr
= NULL
;
291 p
->ule_sndu_type
= 0;
292 p
->ule_sndu_type_1
= 0;
293 p
->ule_sndu_remain
= 0;
299 * Decode ULE SNDUs according to draft-ietf-ipdvb-ule-03.txt from a sequence of
300 * TS cells of a single PID.
303 struct dvb_net_ule_handle
{
304 struct net_device
*dev
;
305 struct dvb_net_priv
*priv
;
309 unsigned long skipped
;
310 const u8
*ts
, *ts_end
, *from_where
;
311 u8 ts_remain
, how_much
, new_ts
;
315 static int dvb_net_ule_new_ts_cell(struct dvb_net_ule_handle
*h
)
317 /* We are about to process a new TS cell. */
320 if (ule_where
>= &ule_hist
[100*TS_SZ
])
321 ule_where
= ule_hist
;
322 memcpy(ule_where
, h
->ts
, TS_SZ
);
324 hexdump(ule_where
, TS_SZ
);
331 * Check TS h->error conditions: sync_byte, transport_error_indicator,
332 * scrambling_control .
334 if ((h
->ts
[0] != TS_SYNC
) || (h
->ts
[1] & TS_TEI
) ||
335 ((h
->ts
[3] & TS_SC
) != 0)) {
336 pr_warn("%lu: Invalid TS cell: SYNC %#x, TEI %u, SC %#x.\n",
337 h
->priv
->ts_count
, h
->ts
[0],
338 (h
->ts
[1] & TS_TEI
) >> 7,
339 (h
->ts
[3] & TS_SC
) >> 6);
341 /* Drop partly decoded SNDU, reset state, resync on PUSI. */
342 if (h
->priv
->ule_skb
) {
343 dev_kfree_skb(h
->priv
->ule_skb
);
344 /* Prepare for next SNDU. */
345 h
->dev
->stats
.rx_errors
++;
346 h
->dev
->stats
.rx_frame_errors
++;
349 h
->priv
->need_pusi
= 1;
351 /* Continue with next TS cell. */
358 h
->from_where
= h
->ts
+ 4;
363 static int dvb_net_ule_ts_pusi(struct dvb_net_ule_handle
*h
)
365 if (h
->ts
[1] & TS_PUSI
) {
366 /* Find beginning of first ULE SNDU in current TS cell. */
367 /* Synchronize continuity counter. */
368 h
->priv
->tscc
= h
->ts
[3] & 0x0F;
369 /* There is a pointer field here. */
370 if (h
->ts
[4] > h
->ts_remain
) {
371 pr_err("%lu: Invalid ULE packet (pointer field %d)\n",
372 h
->priv
->ts_count
, h
->ts
[4]);
377 /* Skip to destination of pointer field. */
378 h
->from_where
= &h
->ts
[5] + h
->ts
[4];
379 h
->ts_remain
-= 1 + h
->ts
[4];
391 static int dvb_net_ule_new_ts(struct dvb_net_ule_handle
*h
)
393 /* Check continuity counter. */
394 if ((h
->ts
[3] & 0x0F) == h
->priv
->tscc
)
395 h
->priv
->tscc
= (h
->priv
->tscc
+ 1) & 0x0F;
397 /* TS discontinuity handling: */
398 pr_warn("%lu: TS discontinuity: got %#x, expected %#x.\n",
399 h
->priv
->ts_count
, h
->ts
[3] & 0x0F,
401 /* Drop partly decoded SNDU, reset state, resync on PUSI. */
402 if (h
->priv
->ule_skb
) {
403 dev_kfree_skb(h
->priv
->ule_skb
);
404 /* Prepare for next SNDU. */
405 // reset_ule(h->priv); moved to below.
406 h
->dev
->stats
.rx_errors
++;
407 h
->dev
->stats
.rx_frame_errors
++;
410 /* skip to next PUSI. */
411 h
->priv
->need_pusi
= 1;
415 * If we still have an incomplete payload, but PUSI is
416 * set; some TS cells are missing.
417 * This is only possible here, if we missed exactly 16 TS
418 * cells (continuity counter wrap).
420 if (h
->ts
[1] & TS_PUSI
) {
421 if (!h
->priv
->need_pusi
) {
422 if (!(*h
->from_where
< (h
->ts_remain
-1)) ||
423 *h
->from_where
!= h
->priv
->ule_sndu_remain
) {
425 * Pointer field is invalid.
426 * Drop this TS cell and any started ULE SNDU.
428 pr_warn("%lu: Invalid pointer field: %u.\n",
433 * Drop partly decoded SNDU, reset state,
436 if (h
->priv
->ule_skb
) {
438 dev_kfree_skb(h
->priv
->ule_skb
);
441 if (h
->error
|| h
->priv
->ule_sndu_remain
) {
442 h
->dev
->stats
.rx_errors
++;
443 h
->dev
->stats
.rx_frame_errors
++;
448 h
->priv
->need_pusi
= 1;
452 * Skip pointer field (we're processing a
458 h
->priv
->need_pusi
= 0;
460 if (h
->priv
->ule_sndu_remain
> 183) {
462 * Current SNDU lacks more data than there
463 * could be available in the current TS cell.
465 h
->dev
->stats
.rx_errors
++;
466 h
->dev
->stats
.rx_length_errors
++;
467 pr_warn("%lu: Expected %d more SNDU bytes, but got PUSI (pf %d, h->ts_remain %d). Flushing incomplete payload.\n",
469 h
->priv
->ule_sndu_remain
,
470 h
->ts
[4], h
->ts_remain
);
471 dev_kfree_skb(h
->priv
->ule_skb
);
472 /* Prepare for next SNDU. */
475 * Resync: go to where pointer field points to:
476 * start of next ULE SNDU.
478 h
->from_where
+= h
->ts
[4];
479 h
->ts_remain
-= h
->ts
[4];
487 * Start a new payload with skb.
488 * Find ULE header. It is only guaranteed that the
489 * length field (2 bytes) is contained in the current
491 * Check h.ts_remain has to be >= 2 here.
493 static int dvb_net_ule_new_payload(struct dvb_net_ule_handle
*h
)
495 if (h
->ts_remain
< 2) {
496 pr_warn("Invalid payload packing: only %d bytes left in TS. Resyncing.\n",
498 h
->priv
->ule_sndu_len
= 0;
499 h
->priv
->need_pusi
= 1;
504 if (!h
->priv
->ule_sndu_len
) {
505 /* Got at least two bytes, thus extrace the SNDU length. */
506 h
->priv
->ule_sndu_len
= h
->from_where
[0] << 8 |
508 if (h
->priv
->ule_sndu_len
& 0x8000) {
509 /* D-Bit is set: no dest mac present. */
510 h
->priv
->ule_sndu_len
&= 0x7FFF;
511 h
->priv
->ule_dbit
= 1;
513 h
->priv
->ule_dbit
= 0;
515 if (h
->priv
->ule_sndu_len
< 5) {
516 pr_warn("%lu: Invalid ULE SNDU length %u. Resyncing.\n",
518 h
->priv
->ule_sndu_len
);
519 h
->dev
->stats
.rx_errors
++;
520 h
->dev
->stats
.rx_length_errors
++;
521 h
->priv
->ule_sndu_len
= 0;
522 h
->priv
->need_pusi
= 1;
528 h
->ts_remain
-= 2; /* consume the 2 bytes SNDU length. */
532 h
->priv
->ule_sndu_remain
= h
->priv
->ule_sndu_len
+ 2;
534 * State of current TS:
535 * h->ts_remain (remaining bytes in the current TS cell)
536 * 0 ule_type is not available now, we need the next TS cell
537 * 1 the first byte of the ule_type is present
538 * >=2 full ULE header present, maybe some payload data as well.
540 switch (h
->ts_remain
) {
542 h
->priv
->ule_sndu_remain
--;
543 h
->priv
->ule_sndu_type
= h
->from_where
[0] << 8;
545 /* first byte of ule_type is set. */
546 h
->priv
->ule_sndu_type_1
= 1;
556 default: /* complete ULE header is present in current TS. */
557 /* Extract ULE type field. */
558 if (h
->priv
->ule_sndu_type_1
) {
559 h
->priv
->ule_sndu_type_1
= 0;
560 h
->priv
->ule_sndu_type
|= h
->from_where
[0];
561 h
->from_where
+= 1; /* points to payload start. */
564 /* Complete type is present in new TS. */
565 h
->priv
->ule_sndu_type
= h
->from_where
[0] << 8 |
567 h
->from_where
+= 2; /* points to payload start. */
574 * Allocate the skb (decoder target buffer) with the correct size,
577 * prepare for the largest case: bridged SNDU with MAC address
580 h
->priv
->ule_skb
= dev_alloc_skb(h
->priv
->ule_sndu_len
+
581 ETH_HLEN
+ ETH_ALEN
);
582 if (!h
->priv
->ule_skb
) {
583 pr_notice("%s: Memory squeeze, dropping packet.\n",
585 h
->dev
->stats
.rx_dropped
++;
589 /* This includes the CRC32 _and_ dest mac, if !dbit. */
590 h
->priv
->ule_sndu_remain
= h
->priv
->ule_sndu_len
;
591 h
->priv
->ule_skb
->dev
= h
->dev
;
593 * Leave space for Ethernet or bridged SNDU header
594 * (eth hdr plus one MAC addr).
596 skb_reserve(h
->priv
->ule_skb
, ETH_HLEN
+ ETH_ALEN
);
602 static int dvb_net_ule_should_drop(struct dvb_net_ule_handle
*h
)
604 static const u8 bc_addr
[ETH_ALEN
] = { [0 ... ETH_ALEN
- 1] = 0xff };
607 * The destination MAC address is the next data in the skb. It comes
608 * before any extension headers.
610 * Check if the payload of this SNDU should be passed up the stack.
612 if (h
->priv
->rx_mode
== RX_MODE_PROMISC
)
615 if (h
->priv
->ule_skb
->data
[0] & 0x01) {
616 /* multicast or broadcast */
617 if (!ether_addr_equal(h
->priv
->ule_skb
->data
, bc_addr
)) {
619 if (h
->priv
->rx_mode
== RX_MODE_MULTI
) {
622 for (i
= 0; i
< h
->priv
->multi_num
&&
623 !ether_addr_equal(h
->priv
->ule_skb
->data
,
624 h
->priv
->multi_macs
[i
]);
627 if (i
== h
->priv
->multi_num
)
629 } else if (h
->priv
->rx_mode
!= RX_MODE_ALL_MULTI
)
630 return 1; /* no broadcast; */
633 * all multicast mode: accept all multicast packets
636 /* else: broadcast */
637 } else if (!ether_addr_equal(h
->priv
->ule_skb
->data
, h
->dev
->dev_addr
))
644 static void dvb_net_ule_check_crc(struct dvb_net_ule_handle
*h
,
646 u32 ule_crc
, u32 expected_crc
)
648 u8 dest_addr
[ETH_ALEN
];
650 if (ule_crc
!= expected_crc
) {
651 pr_warn("%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
652 h
->priv
->ts_count
, ule_crc
, expected_crc
,
653 h
->priv
->ule_sndu_len
, h
->priv
->ule_sndu_type
,
656 *(unsigned short *)h
->from_where
: 0);
659 hexdump(iov
[0].iov_base
, iov
[0].iov_len
);
660 hexdump(iov
[1].iov_base
, iov
[1].iov_len
);
661 hexdump(iov
[2].iov_base
, iov
[2].iov_len
);
663 if (ule_where
== ule_hist
) {
664 hexdump(&ule_hist
[98*TS_SZ
], TS_SZ
);
665 hexdump(&ule_hist
[99*TS_SZ
], TS_SZ
);
666 } else if (ule_where
== &ule_hist
[TS_SZ
]) {
667 hexdump(&ule_hist
[99*TS_SZ
], TS_SZ
);
668 hexdump(ule_hist
, TS_SZ
);
670 hexdump(ule_where
- TS_SZ
- TS_SZ
, TS_SZ
);
671 hexdump(ule_where
- TS_SZ
, TS_SZ
);
676 h
->dev
->stats
.rx_errors
++;
677 h
->dev
->stats
.rx_crc_errors
++;
678 dev_kfree_skb(h
->priv
->ule_skb
);
683 /* CRC32 verified OK. */
685 /* CRC32 was OK, so remove it from skb. */
686 h
->priv
->ule_skb
->tail
-= 4;
687 h
->priv
->ule_skb
->len
-= 4;
689 if (!h
->priv
->ule_dbit
) {
690 if (dvb_net_ule_should_drop(h
)) {
692 "Dropping SNDU: MAC destination address does not match: dest addr: %pM, h->dev addr: %pM\n",
693 h
->priv
->ule_skb
->data
, h
->dev
->dev_addr
);
694 dev_kfree_skb(h
->priv
->ule_skb
);
698 skb_copy_from_linear_data(h
->priv
->ule_skb
, dest_addr
,
700 skb_pull(h
->priv
->ule_skb
, ETH_ALEN
);
702 /* dest_addr buffer is only valid if h->priv->ule_dbit == 0 */
703 eth_zero_addr(dest_addr
);
706 /* Handle ULE Extension Headers. */
707 if (h
->priv
->ule_sndu_type
< ETH_P_802_3_MIN
) {
708 /* There is an extension header. Handle it accordingly. */
709 int l
= handle_ule_extensions(h
->priv
);
713 * Mandatory extension header unknown or TEST SNDU.
717 // pr_warn("Dropping SNDU, extension headers.\n" );
718 dev_kfree_skb(h
->priv
->ule_skb
);
721 skb_pull(h
->priv
->ule_skb
, l
);
725 * Construct/assure correct ethernet header.
726 * Note: in bridged mode (h->priv->ule_bridged != 0)
727 * we already have the (original) ethernet
728 * header at the start of the payload (after
729 * optional dest. address and any extension
732 if (!h
->priv
->ule_bridged
) {
733 skb_push(h
->priv
->ule_skb
, ETH_HLEN
);
734 h
->ethh
= (struct ethhdr
*)h
->priv
->ule_skb
->data
;
735 memcpy(h
->ethh
->h_dest
, dest_addr
, ETH_ALEN
);
736 eth_zero_addr(h
->ethh
->h_source
);
737 h
->ethh
->h_proto
= htons(h
->priv
->ule_sndu_type
);
739 /* else: skb is in correct state; nothing to do. */
740 h
->priv
->ule_bridged
= 0;
742 /* Stuff into kernel's protocol stack. */
743 h
->priv
->ule_skb
->protocol
= dvb_net_eth_type_trans(h
->priv
->ule_skb
,
746 * If D-bit is set (i.e. destination MAC address not present),
747 * receive the packet anyhow.
750 if (h
->priv
->ule_dbit
&& skb
->pkt_type
== PACKET_OTHERHOST
)
751 h
->priv
->ule_skb
->pkt_type
= PACKET_HOST
;
753 h
->dev
->stats
.rx_packets
++;
754 h
->dev
->stats
.rx_bytes
+= h
->priv
->ule_skb
->len
;
755 netif_rx(h
->priv
->ule_skb
);
758 static void dvb_net_ule(struct net_device
*dev
, const u8
*buf
, size_t buf_len
)
761 struct dvb_net_ule_handle h
= {
763 .priv
= netdev_priv(dev
),
778 * For all TS cells in current buffer.
779 * Appearently, we are called for every single TS cell.
781 for (h
.ts
= h
.buf
, h
.ts_end
= h
.buf
+ h
.buf_len
;
782 h
.ts
< h
.ts_end
; /* no incr. */) {
784 /* We are about to process a new TS cell. */
785 if (dvb_net_ule_new_ts_cell(&h
))
789 /* Synchronize on PUSI, if required. */
790 if (h
.priv
->need_pusi
) {
791 if (dvb_net_ule_ts_pusi(&h
))
796 if (dvb_net_ule_new_ts(&h
))
800 /* Check if new payload needs to be started. */
801 if (h
.priv
->ule_skb
== NULL
) {
802 ret
= dvb_net_ule_new_payload(&h
);
809 /* Copy data into our current skb. */
810 h
.how_much
= min(h
.priv
->ule_sndu_remain
, (int)h
.ts_remain
);
811 skb_put_data(h
.priv
->ule_skb
, h
.from_where
, h
.how_much
);
812 h
.priv
->ule_sndu_remain
-= h
.how_much
;
813 h
.ts_remain
-= h
.how_much
;
814 h
.from_where
+= h
.how_much
;
816 /* Check for complete payload. */
817 if (h
.priv
->ule_sndu_remain
<= 0) {
818 /* Check CRC32, we've got it in our skb already. */
819 __be16 ulen
= htons(h
.priv
->ule_sndu_len
);
820 __be16 utype
= htons(h
.priv
->ule_sndu_type
);
822 struct kvec iov
[3] = {
823 { &ulen
, sizeof ulen
},
824 { &utype
, sizeof utype
},
825 { h
.priv
->ule_skb
->data
,
826 h
.priv
->ule_skb
->len
- 4 }
828 u32 ule_crc
= ~0L, expected_crc
;
829 if (h
.priv
->ule_dbit
) {
830 /* Set D-bit for CRC32 verification,
831 * if it was set originally. */
832 ulen
|= htons(0x8000);
835 ule_crc
= iov_crc32(ule_crc
, iov
, 3);
836 tail
= skb_tail_pointer(h
.priv
->ule_skb
);
837 expected_crc
= *(tail
- 4) << 24 |
842 dvb_net_ule_check_crc(&h
, iov
, ule_crc
, expected_crc
);
844 /* Prepare for next SNDU. */
848 /* More data in current TS (look at the bytes following the CRC32)? */
849 if (h
.ts_remain
>= 2 && *((unsigned short *)h
.from_where
) != 0xFFFF) {
850 /* Next ULE SNDU starts right there. */
852 h
.priv
->ule_skb
= NULL
;
853 h
.priv
->ule_sndu_type_1
= 0;
854 h
.priv
->ule_sndu_len
= 0;
855 // pr_warn("More data in current TS: [%#x %#x %#x %#x]\n",
856 // *(h.from_where + 0), *(h.from_where + 1),
857 // *(h.from_where + 2), *(h.from_where + 3));
858 // pr_warn("h.ts @ %p, stopped @ %p:\n", h.ts, h.from_where + 0);
859 // hexdump(h.ts, 188);
864 if (h
.priv
->ule_skb
== NULL
) {
865 h
.priv
->need_pusi
= 1;
866 h
.priv
->ule_sndu_type_1
= 0;
867 h
.priv
->ule_sndu_len
= 0;
870 } /* for all available TS cells */
873 static int dvb_net_ts_callback(const u8
*buffer1
, size_t buffer1_len
,
874 const u8
*buffer2
, size_t buffer2_len
,
875 struct dmx_ts_feed
*feed
,
878 struct net_device
*dev
= feed
->priv
;
881 pr_warn("buffer2 not NULL: %p.\n", buffer2
);
882 if (buffer1_len
> 32768)
883 pr_warn("length > 32k: %zu.\n", buffer1_len
);
884 /* pr_info("TS callback: %u bytes, %u TS cells @ %p.\n",
885 buffer1_len, buffer1_len / TS_SZ, buffer1); */
886 dvb_net_ule(dev
, buffer1
, buffer1_len
);
891 static void dvb_net_sec(struct net_device
*dev
,
892 const u8
*pkt
, int pkt_len
)
896 struct net_device_stats
*stats
= &dev
->stats
;
899 /* note: pkt_len includes a 32bit checksum */
901 pr_warn("%s: IP/MPE packet length = %d too small.\n",
904 stats
->rx_length_errors
++;
907 /* it seems some ISPs manage to screw up here, so we have to
908 * relax the error checks... */
910 if ((pkt
[5] & 0xfd) != 0xc1) {
911 /* drop scrambled or broken packets */
913 if ((pkt
[5] & 0x3c) != 0x00) {
917 stats
->rx_crc_errors
++;
921 /* handle LLC/SNAP, see rfc-1042 */
922 if (pkt_len
< 24 || memcmp(&pkt
[12], "\xaa\xaa\x03\0\0\0", 6)) {
929 /* FIXME: assemble datagram from multiple sections */
931 stats
->rx_frame_errors
++;
935 /* we have 14 byte ethernet header (ip header follows);
936 * 12 byte MPE header; 4 byte checksum; + 2 byte alignment, 8 byte LLC/SNAP
938 if (!(skb
= dev_alloc_skb(pkt_len
- 4 - 12 + 14 + 2 - snap
))) {
939 //pr_notice("%s: Memory squeeze, dropping packet.\n", dev->name);
943 skb_reserve(skb
, 2); /* longword align L3 header */
946 /* copy L3 payload */
947 eth
= skb_put(skb
, pkt_len
- 12 - 4 + 14 - snap
);
948 memcpy(eth
+ 14, pkt
+ 12 + snap
, pkt_len
- 12 - 4 - snap
);
950 /* create ethernet header: */
958 eth
[6]=eth
[7]=eth
[8]=eth
[9]=eth
[10]=eth
[11]=0;
964 /* protocol numbers are from rfc-1700 or
965 * http://www.iana.org/assignments/ethernet-numbers
967 if (pkt
[12] >> 4 == 6) { /* version field from IP header */
968 eth
[12] = 0x86; /* IPv6 */
971 eth
[12] = 0x08; /* IPv4 */
976 skb
->protocol
= dvb_net_eth_type_trans(skb
, dev
);
979 stats
->rx_bytes
+=skb
->len
;
983 static int dvb_net_sec_callback(const u8
*buffer1
, size_t buffer1_len
,
984 const u8
*buffer2
, size_t buffer2_len
,
985 struct dmx_section_filter
*filter
, u32
*buffer_flags
)
987 struct net_device
*dev
= filter
->priv
;
990 * we rely on the DVB API definition where exactly one complete
991 * section is delivered in buffer1
993 dvb_net_sec (dev
, buffer1
, buffer1_len
);
997 static netdev_tx_t
dvb_net_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1000 return NETDEV_TX_OK
;
1003 static u8 mask_normal
[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1004 static u8 mask_allmulti
[6]={0xff, 0xff, 0xff, 0x00, 0x00, 0x00};
1005 static u8 mac_allmulti
[6]={0x01, 0x00, 0x5e, 0x00, 0x00, 0x00};
1006 static u8 mask_promisc
[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1008 static int dvb_net_filter_sec_set(struct net_device
*dev
,
1009 struct dmx_section_filter
**secfilter
,
1010 u8
*mac
, u8
*mac_mask
)
1012 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1016 ret
= priv
->secfeed
->allocate_filter(priv
->secfeed
, secfilter
);
1018 pr_err("%s: could not get filter\n", dev
->name
);
1022 (*secfilter
)->priv
=(void *) dev
;
1024 memset((*secfilter
)->filter_value
, 0x00, DMX_MAX_FILTER_SIZE
);
1025 memset((*secfilter
)->filter_mask
, 0x00, DMX_MAX_FILTER_SIZE
);
1026 memset((*secfilter
)->filter_mode
, 0xff, DMX_MAX_FILTER_SIZE
);
1028 (*secfilter
)->filter_value
[0]=0x3e;
1029 (*secfilter
)->filter_value
[3]=mac
[5];
1030 (*secfilter
)->filter_value
[4]=mac
[4];
1031 (*secfilter
)->filter_value
[8]=mac
[3];
1032 (*secfilter
)->filter_value
[9]=mac
[2];
1033 (*secfilter
)->filter_value
[10]=mac
[1];
1034 (*secfilter
)->filter_value
[11]=mac
[0];
1036 (*secfilter
)->filter_mask
[0] = 0xff;
1037 (*secfilter
)->filter_mask
[3] = mac_mask
[5];
1038 (*secfilter
)->filter_mask
[4] = mac_mask
[4];
1039 (*secfilter
)->filter_mask
[8] = mac_mask
[3];
1040 (*secfilter
)->filter_mask
[9] = mac_mask
[2];
1041 (*secfilter
)->filter_mask
[10] = mac_mask
[1];
1042 (*secfilter
)->filter_mask
[11]=mac_mask
[0];
1044 netdev_dbg(dev
, "filter mac=%pM mask=%pM\n", mac
, mac_mask
);
1049 static int dvb_net_feed_start(struct net_device
*dev
)
1052 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1053 struct dmx_demux
*demux
= priv
->demux
;
1054 unsigned char *mac
= (unsigned char *) dev
->dev_addr
;
1056 netdev_dbg(dev
, "rx_mode %i\n", priv
->rx_mode
);
1057 mutex_lock(&priv
->mutex
);
1058 if (priv
->tsfeed
|| priv
->secfeed
|| priv
->secfilter
|| priv
->multi_secfilter
[0])
1059 pr_err("%s: BUG %d\n", __func__
, __LINE__
);
1062 priv
->secfilter
=NULL
;
1063 priv
->tsfeed
= NULL
;
1065 if (priv
->feedtype
== DVB_NET_FEEDTYPE_MPE
) {
1066 netdev_dbg(dev
, "alloc secfeed\n");
1067 ret
=demux
->allocate_section_feed(demux
, &priv
->secfeed
,
1068 dvb_net_sec_callback
);
1070 pr_err("%s: could not allocate section feed\n",
1075 ret
= priv
->secfeed
->set(priv
->secfeed
, priv
->pid
, 1);
1078 pr_err("%s: could not set section feed\n", dev
->name
);
1079 priv
->demux
->release_section_feed(priv
->demux
, priv
->secfeed
);
1084 if (priv
->rx_mode
!= RX_MODE_PROMISC
) {
1085 netdev_dbg(dev
, "set secfilter\n");
1086 dvb_net_filter_sec_set(dev
, &priv
->secfilter
, mac
, mask_normal
);
1089 switch (priv
->rx_mode
) {
1091 for (i
= 0; i
< priv
->multi_num
; i
++) {
1092 netdev_dbg(dev
, "set multi_secfilter[%d]\n", i
);
1093 dvb_net_filter_sec_set(dev
, &priv
->multi_secfilter
[i
],
1094 priv
->multi_macs
[i
], mask_normal
);
1097 case RX_MODE_ALL_MULTI
:
1099 netdev_dbg(dev
, "set multi_secfilter[0]\n");
1100 dvb_net_filter_sec_set(dev
, &priv
->multi_secfilter
[0],
1101 mac_allmulti
, mask_allmulti
);
1103 case RX_MODE_PROMISC
:
1105 netdev_dbg(dev
, "set secfilter\n");
1106 dvb_net_filter_sec_set(dev
, &priv
->secfilter
, mac
, mask_promisc
);
1110 netdev_dbg(dev
, "start filtering\n");
1111 priv
->secfeed
->start_filtering(priv
->secfeed
);
1112 } else if (priv
->feedtype
== DVB_NET_FEEDTYPE_ULE
) {
1113 ktime_t timeout
= ns_to_ktime(10 * NSEC_PER_MSEC
);
1115 /* we have payloads encapsulated in TS */
1116 netdev_dbg(dev
, "alloc tsfeed\n");
1117 ret
= demux
->allocate_ts_feed(demux
, &priv
->tsfeed
, dvb_net_ts_callback
);
1119 pr_err("%s: could not allocate ts feed\n", dev
->name
);
1123 /* Set netdevice pointer for ts decaps callback. */
1124 priv
->tsfeed
->priv
= (void *)dev
;
1125 ret
= priv
->tsfeed
->set(priv
->tsfeed
,
1126 priv
->pid
, /* pid */
1127 TS_PACKET
, /* type */
1128 DMX_PES_OTHER
, /* pes type */
1129 timeout
/* timeout */
1133 pr_err("%s: could not set ts feed\n", dev
->name
);
1134 priv
->demux
->release_ts_feed(priv
->demux
, priv
->tsfeed
);
1135 priv
->tsfeed
= NULL
;
1139 netdev_dbg(dev
, "start filtering\n");
1140 priv
->tsfeed
->start_filtering(priv
->tsfeed
);
1145 mutex_unlock(&priv
->mutex
);
1149 static int dvb_net_feed_stop(struct net_device
*dev
)
1151 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1154 mutex_lock(&priv
->mutex
);
1155 if (priv
->feedtype
== DVB_NET_FEEDTYPE_MPE
) {
1156 if (priv
->secfeed
) {
1157 if (priv
->secfeed
->is_filtering
) {
1158 netdev_dbg(dev
, "stop secfeed\n");
1159 priv
->secfeed
->stop_filtering(priv
->secfeed
);
1162 if (priv
->secfilter
) {
1163 netdev_dbg(dev
, "release secfilter\n");
1164 priv
->secfeed
->release_filter(priv
->secfeed
,
1166 priv
->secfilter
=NULL
;
1169 for (i
=0; i
<priv
->multi_num
; i
++) {
1170 if (priv
->multi_secfilter
[i
]) {
1171 netdev_dbg(dev
, "release multi_filter[%d]\n",
1173 priv
->secfeed
->release_filter(priv
->secfeed
,
1174 priv
->multi_secfilter
[i
]);
1175 priv
->multi_secfilter
[i
] = NULL
;
1179 priv
->demux
->release_section_feed(priv
->demux
, priv
->secfeed
);
1180 priv
->secfeed
= NULL
;
1182 pr_err("%s: no feed to stop\n", dev
->name
);
1183 } else if (priv
->feedtype
== DVB_NET_FEEDTYPE_ULE
) {
1185 if (priv
->tsfeed
->is_filtering
) {
1186 netdev_dbg(dev
, "stop tsfeed\n");
1187 priv
->tsfeed
->stop_filtering(priv
->tsfeed
);
1189 priv
->demux
->release_ts_feed(priv
->demux
, priv
->tsfeed
);
1190 priv
->tsfeed
= NULL
;
1193 pr_err("%s: no ts feed to stop\n", dev
->name
);
1196 mutex_unlock(&priv
->mutex
);
1201 static int dvb_set_mc_filter(struct net_device
*dev
, unsigned char *addr
)
1203 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1205 if (priv
->multi_num
== DVB_NET_MULTICAST_MAX
)
1208 memcpy(priv
->multi_macs
[priv
->multi_num
], addr
, ETH_ALEN
);
1215 static void wq_set_multicast_list (struct work_struct
*work
)
1217 struct dvb_net_priv
*priv
=
1218 container_of(work
, struct dvb_net_priv
, set_multicast_list_wq
);
1219 struct net_device
*dev
= priv
->net
;
1221 dvb_net_feed_stop(dev
);
1222 priv
->rx_mode
= RX_MODE_UNI
;
1223 netif_addr_lock_bh(dev
);
1225 if (dev
->flags
& IFF_PROMISC
) {
1226 netdev_dbg(dev
, "promiscuous mode\n");
1227 priv
->rx_mode
= RX_MODE_PROMISC
;
1228 } else if ((dev
->flags
& IFF_ALLMULTI
)) {
1229 netdev_dbg(dev
, "allmulti mode\n");
1230 priv
->rx_mode
= RX_MODE_ALL_MULTI
;
1231 } else if (!netdev_mc_empty(dev
)) {
1232 struct netdev_hw_addr
*ha
;
1234 netdev_dbg(dev
, "set_mc_list, %d entries\n",
1235 netdev_mc_count(dev
));
1237 priv
->rx_mode
= RX_MODE_MULTI
;
1238 priv
->multi_num
= 0;
1240 netdev_for_each_mc_addr(ha
, dev
)
1241 dvb_set_mc_filter(dev
, ha
->addr
);
1244 netif_addr_unlock_bh(dev
);
1245 dvb_net_feed_start(dev
);
1249 static void dvb_net_set_multicast_list (struct net_device
*dev
)
1251 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1252 schedule_work(&priv
->set_multicast_list_wq
);
1256 static void wq_restart_net_feed (struct work_struct
*work
)
1258 struct dvb_net_priv
*priv
=
1259 container_of(work
, struct dvb_net_priv
, restart_net_feed_wq
);
1260 struct net_device
*dev
= priv
->net
;
1262 if (netif_running(dev
)) {
1263 dvb_net_feed_stop(dev
);
1264 dvb_net_feed_start(dev
);
1269 static int dvb_net_set_mac (struct net_device
*dev
, void *p
)
1271 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1272 struct sockaddr
*addr
=p
;
1274 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1276 if (netif_running(dev
))
1277 schedule_work(&priv
->restart_net_feed_wq
);
1283 static int dvb_net_open(struct net_device
*dev
)
1285 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1288 dvb_net_feed_start(dev
);
1293 static int dvb_net_stop(struct net_device
*dev
)
1295 struct dvb_net_priv
*priv
= netdev_priv(dev
);
1298 return dvb_net_feed_stop(dev
);
1301 static const struct header_ops dvb_header_ops
= {
1302 .create
= eth_header
,
1303 .parse
= eth_header_parse
,
1307 static const struct net_device_ops dvb_netdev_ops
= {
1308 .ndo_open
= dvb_net_open
,
1309 .ndo_stop
= dvb_net_stop
,
1310 .ndo_start_xmit
= dvb_net_tx
,
1311 .ndo_set_rx_mode
= dvb_net_set_multicast_list
,
1312 .ndo_set_mac_address
= dvb_net_set_mac
,
1313 .ndo_validate_addr
= eth_validate_addr
,
1316 static void dvb_net_setup(struct net_device
*dev
)
1320 dev
->header_ops
= &dvb_header_ops
;
1321 dev
->netdev_ops
= &dvb_netdev_ops
;
1323 dev
->max_mtu
= 4096;
1325 dev
->flags
|= IFF_NOARP
;
1328 static int get_if(struct dvb_net
*dvbnet
)
1332 for (i
=0; i
<DVB_NET_DEVICES_MAX
; i
++)
1333 if (!dvbnet
->state
[i
])
1336 if (i
== DVB_NET_DEVICES_MAX
)
1343 static int dvb_net_add_if(struct dvb_net
*dvbnet
, u16 pid
, u8 feedtype
)
1345 struct net_device
*net
;
1346 struct dvb_net_priv
*priv
;
1350 if (feedtype
!= DVB_NET_FEEDTYPE_MPE
&& feedtype
!= DVB_NET_FEEDTYPE_ULE
)
1352 if ((if_num
= get_if(dvbnet
)) < 0)
1355 net
= alloc_netdev(sizeof(struct dvb_net_priv
), "dvb",
1356 NET_NAME_UNKNOWN
, dvb_net_setup
);
1360 if (dvbnet
->dvbdev
->id
)
1361 snprintf(net
->name
, IFNAMSIZ
, "dvb%d%u%d",
1362 dvbnet
->dvbdev
->adapter
->num
, dvbnet
->dvbdev
->id
, if_num
);
1364 /* compatibility fix to keep dvb0_0 format */
1365 snprintf(net
->name
, IFNAMSIZ
, "dvb%d_%d",
1366 dvbnet
->dvbdev
->adapter
->num
, if_num
);
1369 memcpy(net
->dev_addr
, dvbnet
->dvbdev
->adapter
->proposed_mac
, 6);
1371 dvbnet
->device
[if_num
] = net
;
1373 priv
= netdev_priv(net
);
1375 priv
->demux
= dvbnet
->demux
;
1377 priv
->rx_mode
= RX_MODE_UNI
;
1378 priv
->need_pusi
= 1;
1380 priv
->feedtype
= feedtype
;
1383 INIT_WORK(&priv
->set_multicast_list_wq
, wq_set_multicast_list
);
1384 INIT_WORK(&priv
->restart_net_feed_wq
, wq_restart_net_feed
);
1385 mutex_init(&priv
->mutex
);
1387 net
->base_addr
= pid
;
1389 if ((result
= register_netdev(net
)) < 0) {
1390 dvbnet
->device
[if_num
] = NULL
;
1394 pr_info("created network interface %s\n", net
->name
);
1399 static int dvb_net_remove_if(struct dvb_net
*dvbnet
, unsigned long num
)
1401 struct net_device
*net
= dvbnet
->device
[num
];
1402 struct dvb_net_priv
*priv
;
1404 if (!dvbnet
->state
[num
])
1406 priv
= netdev_priv(net
);
1411 flush_work(&priv
->set_multicast_list_wq
);
1412 flush_work(&priv
->restart_net_feed_wq
);
1413 pr_info("removed network interface %s\n", net
->name
);
1414 unregister_netdev(net
);
1415 dvbnet
->state
[num
]=0;
1416 dvbnet
->device
[num
] = NULL
;
1422 static int dvb_net_do_ioctl(struct file
*file
,
1423 unsigned int cmd
, void *parg
)
1425 struct dvb_device
*dvbdev
= file
->private_data
;
1426 struct dvb_net
*dvbnet
= dvbdev
->priv
;
1429 if (((file
->f_flags
&O_ACCMODE
)==O_RDONLY
))
1432 if (mutex_lock_interruptible(&dvbnet
->ioctl_mutex
))
1433 return -ERESTARTSYS
;
1438 struct dvb_net_if
*dvbnetif
= parg
;
1441 if (!capable(CAP_SYS_ADMIN
)) {
1446 if (!try_module_get(dvbdev
->adapter
->module
)) {
1451 result
=dvb_net_add_if(dvbnet
, dvbnetif
->pid
, dvbnetif
->feedtype
);
1453 module_put(dvbdev
->adapter
->module
);
1457 dvbnetif
->if_num
=result
;
1462 struct net_device
*netdev
;
1463 struct dvb_net_priv
*priv_data
;
1464 struct dvb_net_if
*dvbnetif
= parg
;
1466 if (dvbnetif
->if_num
>= DVB_NET_DEVICES_MAX
||
1467 !dvbnet
->state
[dvbnetif
->if_num
]) {
1472 netdev
= dvbnet
->device
[dvbnetif
->if_num
];
1474 priv_data
= netdev_priv(netdev
);
1475 dvbnetif
->pid
=priv_data
->pid
;
1476 dvbnetif
->feedtype
=priv_data
->feedtype
;
1481 if (!capable(CAP_SYS_ADMIN
)) {
1485 if ((unsigned long) parg
>= DVB_NET_DEVICES_MAX
) {
1489 ret
= dvb_net_remove_if(dvbnet
, (unsigned long) parg
);
1491 module_put(dvbdev
->adapter
->module
);
1495 /* binary compatibility cruft */
1496 case __NET_ADD_IF_OLD
:
1498 struct __dvb_net_if_old
*dvbnetif
= parg
;
1501 if (!capable(CAP_SYS_ADMIN
)) {
1506 if (!try_module_get(dvbdev
->adapter
->module
)) {
1511 result
=dvb_net_add_if(dvbnet
, dvbnetif
->pid
, DVB_NET_FEEDTYPE_MPE
);
1513 module_put(dvbdev
->adapter
->module
);
1517 dvbnetif
->if_num
=result
;
1520 case __NET_GET_IF_OLD
:
1522 struct net_device
*netdev
;
1523 struct dvb_net_priv
*priv_data
;
1524 struct __dvb_net_if_old
*dvbnetif
= parg
;
1526 if (dvbnetif
->if_num
>= DVB_NET_DEVICES_MAX
||
1527 !dvbnet
->state
[dvbnetif
->if_num
]) {
1532 netdev
= dvbnet
->device
[dvbnetif
->if_num
];
1534 priv_data
= netdev_priv(netdev
);
1535 dvbnetif
->pid
=priv_data
->pid
;
1544 mutex_unlock(&dvbnet
->ioctl_mutex
);
1548 static long dvb_net_ioctl(struct file
*file
,
1549 unsigned int cmd
, unsigned long arg
)
1551 return dvb_usercopy(file
, cmd
, arg
, dvb_net_do_ioctl
);
1554 static int dvb_net_close(struct inode
*inode
, struct file
*file
)
1556 struct dvb_device
*dvbdev
= file
->private_data
;
1557 struct dvb_net
*dvbnet
= dvbdev
->priv
;
1559 dvb_generic_release(inode
, file
);
1561 if(dvbdev
->users
== 1 && dvbnet
->exit
== 1)
1562 wake_up(&dvbdev
->wait_queue
);
1567 static const struct file_operations dvb_net_fops
= {
1568 .owner
= THIS_MODULE
,
1569 .unlocked_ioctl
= dvb_net_ioctl
,
1570 .open
= dvb_generic_open
,
1571 .release
= dvb_net_close
,
1572 .llseek
= noop_llseek
,
1575 static const struct dvb_device dvbdev_net
= {
1579 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
1582 .fops
= &dvb_net_fops
,
1585 void dvb_net_release (struct dvb_net
*dvbnet
)
1590 if (dvbnet
->dvbdev
->users
< 1)
1591 wait_event(dvbnet
->dvbdev
->wait_queue
,
1592 dvbnet
->dvbdev
->users
==1);
1594 dvb_unregister_device(dvbnet
->dvbdev
);
1596 for (i
=0; i
<DVB_NET_DEVICES_MAX
; i
++) {
1597 if (!dvbnet
->state
[i
])
1599 dvb_net_remove_if(dvbnet
, i
);
1602 EXPORT_SYMBOL(dvb_net_release
);
1605 int dvb_net_init (struct dvb_adapter
*adap
, struct dvb_net
*dvbnet
,
1606 struct dmx_demux
*dmx
)
1610 mutex_init(&dvbnet
->ioctl_mutex
);
1611 dvbnet
->demux
= dmx
;
1613 for (i
=0; i
<DVB_NET_DEVICES_MAX
; i
++)
1614 dvbnet
->state
[i
] = 0;
1616 return dvb_register_device(adap
, &dvbnet
->dvbdev
, &dvbdev_net
,
1617 dvbnet
, DVB_DEVICE_NET
, 0);
1619 EXPORT_SYMBOL(dvb_net_init
);