]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * dvb_net.c | |
3 | * | |
4 | * Copyright (C) 2001 Convergence integrated media GmbH | |
5 | * Ralph Metzler <ralph@convergence.de> | |
6 | * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de> | |
7 | * | |
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> | |
14 | * | |
18232ca6 | 15 | * ULE Decaps according to RFC 4326. |
1da177e4 LT |
16 | * |
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. | |
21 | * | |
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 | * | |
27 | * You should have received a copy of the GNU General Public License | |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
30 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html | |
31 | */ | |
32 | ||
33 | /* | |
34 | * ULE ChangeLog: | |
35 | * Feb 2004: hl/ws v1: Implementing draft-fair-ipdvb-ule-01.txt | |
36 | * | |
37 | * Dec 2004: hl/ws v2: Implementing draft-ietf-ipdvb-ule-03.txt: | |
38 | * ULE Extension header handling. | |
39 | * Bugreports by Moritz Vieth and Hanno Tersteegen, | |
40 | * Fraunhofer Institute for Open Communication Systems | |
41 | * Competence Center for Advanced Satellite Communications. | |
42 | * Bugfixes and robustness improvements. | |
43 | * Filtering on dest MAC addresses, if present (D-Bit = 0) | |
44 | * ULE_DEBUG compile-time option. | |
18232ca6 CP |
45 | * Apr 2006: cp v3: Bugfixes and compliency with RFC 4326 (ULE) by |
46 | * Christian Praehauser <cpraehaus@cosy.sbg.ac.at>, | |
47 | * Paris Lodron University of Salzburg. | |
1da177e4 LT |
48 | */ |
49 | ||
50 | /* | |
51 | * FIXME / TODO (dvb_net.c): | |
52 | * | |
53 | * Unloading does not work for 2.6.9 kernels: a refcount doesn't go to zero. | |
54 | * | |
1da177e4 LT |
55 | */ |
56 | ||
b3ad24d2 MCC |
57 | #define pr_fmt(fmt) "dvb_net: " fmt |
58 | ||
1da177e4 LT |
59 | #include <linux/module.h> |
60 | #include <linux/kernel.h> | |
61 | #include <linux/netdevice.h> | |
62 | #include <linux/etherdevice.h> | |
63 | #include <linux/dvb/net.h> | |
64 | #include <linux/uio.h> | |
65 | #include <asm/uaccess.h> | |
66 | #include <linux/crc32.h> | |
3593cab5 | 67 | #include <linux/mutex.h> |
d43c36dc | 68 | #include <linux/sched.h> |
1da177e4 LT |
69 | |
70 | #include "dvb_demux.h" | |
71 | #include "dvb_net.h" | |
72 | ||
1da177e4 LT |
73 | static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt ) |
74 | { | |
75 | unsigned int j; | |
76 | for (j = 0; j < cnt; j++) | |
77 | c = crc32_be( c, iov[j].iov_base, iov[j].iov_len ); | |
78 | return c; | |
79 | } | |
80 | ||
81 | ||
82 | #define DVB_NET_MULTICAST_MAX 10 | |
83 | ||
84 | #undef ULE_DEBUG | |
85 | ||
86 | #ifdef ULE_DEBUG | |
87 | ||
4bad5d2d | 88 | static void hexdump(const unsigned char *buf, unsigned short len) |
1da177e4 | 89 | { |
4bad5d2d | 90 | print_hex_dump_debug("", DUMP_PREFIX_OFFSET, 16, 1, buf, len, true); |
1da177e4 LT |
91 | } |
92 | ||
93 | #endif | |
94 | ||
95 | struct dvb_net_priv { | |
96 | int in_use; | |
1da177e4 | 97 | u16 pid; |
c4028958 | 98 | struct net_device *net; |
1da177e4 LT |
99 | struct dvb_net *host; |
100 | struct dmx_demux *demux; | |
101 | struct dmx_section_feed *secfeed; | |
102 | struct dmx_section_filter *secfilter; | |
103 | struct dmx_ts_feed *tsfeed; | |
104 | int multi_num; | |
105 | struct dmx_section_filter *multi_secfilter[DVB_NET_MULTICAST_MAX]; | |
106 | unsigned char multi_macs[DVB_NET_MULTICAST_MAX][6]; | |
107 | int rx_mode; | |
108 | #define RX_MODE_UNI 0 | |
109 | #define RX_MODE_MULTI 1 | |
110 | #define RX_MODE_ALL_MULTI 2 | |
111 | #define RX_MODE_PROMISC 3 | |
112 | struct work_struct set_multicast_list_wq; | |
113 | struct work_struct restart_net_feed_wq; | |
114 | unsigned char feedtype; /* Either FEED_TYPE_ or FEED_TYPE_ULE */ | |
115 | int need_pusi; /* Set to 1, if synchronization on PUSI required. */ | |
116 | unsigned char tscc; /* TS continuity counter after sync on PUSI. */ | |
117 | struct sk_buff *ule_skb; /* ULE SNDU decodes into this buffer. */ | |
118 | unsigned char *ule_next_hdr; /* Pointer into skb to next ULE extension header. */ | |
119 | unsigned short ule_sndu_len; /* ULE SNDU length in bytes, w/o D-Bit. */ | |
120 | unsigned short ule_sndu_type; /* ULE SNDU type field, complete. */ | |
121 | unsigned char ule_sndu_type_1; /* ULE SNDU type field, if split across 2 TS cells. */ | |
122 | unsigned char ule_dbit; /* Whether the DestMAC address present | |
123 | * or not (bit is set). */ | |
124 | unsigned char ule_bridged; /* Whether the ULE_BRIDGED extension header was found. */ | |
125 | int ule_sndu_remain; /* Nr. of bytes still required for current ULE SNDU. */ | |
126 | unsigned long ts_count; /* Current ts cell counter. */ | |
3593cab5 | 127 | struct mutex mutex; |
1da177e4 LT |
128 | }; |
129 | ||
130 | ||
131 | /** | |
132 | * Determine the packet's protocol ID. The rule here is that we | |
133 | * assume 802.3 if the type field is short enough to be a length. | |
134 | * This is normal practice and works for any 'now in use' protocol. | |
135 | * | |
136 | * stolen from eth.c out of the linux kernel, hacked for dvb-device | |
137 | * by Michael Holzt <kju@debian.org> | |
138 | */ | |
12fbcef1 | 139 | static __be16 dvb_net_eth_type_trans(struct sk_buff *skb, |
1da177e4 LT |
140 | struct net_device *dev) |
141 | { | |
142 | struct ethhdr *eth; | |
143 | unsigned char *rawp; | |
144 | ||
98e399f8 | 145 | skb_reset_mac_header(skb); |
1da177e4 | 146 | skb_pull(skb,dev->hard_header_len); |
1da177e4 | 147 | eth = eth_hdr(skb); |
1da177e4 LT |
148 | |
149 | if (*eth->h_dest & 1) { | |
5e231c2c | 150 | if(ether_addr_equal(eth->h_dest,dev->broadcast)) |
1da177e4 LT |
151 | skb->pkt_type=PACKET_BROADCAST; |
152 | else | |
153 | skb->pkt_type=PACKET_MULTICAST; | |
154 | } | |
155 | ||
e5c5d22e | 156 | if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN) |
1da177e4 LT |
157 | return eth->h_proto; |
158 | ||
159 | rawp = skb->data; | |
160 | ||
161 | /** | |
162 | * This is a magic hack to spot IPX packets. Older Novell breaks | |
163 | * the protocol design and runs IPX over 802.3 without an 802.2 LLC | |
164 | * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This | |
165 | * won't work for fault tolerant netware but does for the rest. | |
166 | */ | |
167 | if (*(unsigned short *)rawp == 0xFFFF) | |
168 | return htons(ETH_P_802_3); | |
169 | ||
170 | /** | |
171 | * Real 802.2 LLC | |
172 | */ | |
173 | return htons(ETH_P_802_2); | |
174 | } | |
175 | ||
176 | #define TS_SZ 188 | |
177 | #define TS_SYNC 0x47 | |
178 | #define TS_TEI 0x80 | |
179 | #define TS_SC 0xC0 | |
180 | #define TS_PUSI 0x40 | |
181 | #define TS_AF_A 0x20 | |
182 | #define TS_AF_D 0x10 | |
183 | ||
184 | /* ULE Extension Header handlers. */ | |
185 | ||
186 | #define ULE_TEST 0 | |
187 | #define ULE_BRIDGED 1 | |
188 | ||
18232ca6 CP |
189 | #define ULE_OPTEXTHDR_PADDING 0 |
190 | ||
1da177e4 LT |
191 | static int ule_test_sndu( struct dvb_net_priv *p ) |
192 | { | |
193 | return -1; | |
194 | } | |
195 | ||
196 | static int ule_bridged_sndu( struct dvb_net_priv *p ) | |
197 | { | |
18232ca6 | 198 | struct ethhdr *hdr = (struct ethhdr*) p->ule_next_hdr; |
e5c5d22e | 199 | if(ntohs(hdr->h_proto) < ETH_P_802_3_MIN) { |
18232ca6 | 200 | int framelen = p->ule_sndu_len - ((p->ule_next_hdr+sizeof(struct ethhdr)) - p->ule_skb->data); |
e5c5d22e | 201 | /* A frame Type < ETH_P_802_3_MIN for a bridged frame, introduces a LLC Length field. */ |
18232ca6 CP |
202 | if(framelen != ntohs(hdr->h_proto)) { |
203 | return -1; | |
204 | } | |
205 | } | |
206 | /* Note: | |
207 | * From RFC4326: | |
208 | * "A bridged SNDU is a Mandatory Extension Header of Type 1. | |
209 | * It must be the final (or only) extension header specified in the header chain of a SNDU." | |
210 | * The 'ule_bridged' flag will cause the extension header processing loop to terminate. | |
1da177e4 LT |
211 | */ |
212 | p->ule_bridged = 1; | |
213 | return 0; | |
214 | } | |
215 | ||
18232ca6 CP |
216 | static int ule_exthdr_padding(struct dvb_net_priv *p) |
217 | { | |
218 | return 0; | |
219 | } | |
1da177e4 LT |
220 | |
221 | /** Handle ULE extension headers. | |
222 | * Function is called after a successful CRC32 verification of an ULE SNDU to complete its decoding. | |
223 | * Returns: >= 0: nr. of bytes consumed by next extension header | |
224 | * -1: Mandatory extension header that is not recognized or TEST SNDU; discard. | |
225 | */ | |
226 | static int handle_one_ule_extension( struct dvb_net_priv *p ) | |
227 | { | |
228 | /* Table of mandatory extension header handlers. The header type is the index. */ | |
229 | static int (*ule_mandatory_ext_handlers[255])( struct dvb_net_priv *p ) = | |
230 | { [0] = ule_test_sndu, [1] = ule_bridged_sndu, [2] = NULL, }; | |
231 | ||
232 | /* Table of optional extension header handlers. The header type is the index. */ | |
18232ca6 CP |
233 | static int (*ule_optional_ext_handlers[255])( struct dvb_net_priv *p ) = |
234 | { [0] = ule_exthdr_padding, [1] = NULL, }; | |
1da177e4 LT |
235 | |
236 | int ext_len = 0; | |
237 | unsigned char hlen = (p->ule_sndu_type & 0x0700) >> 8; | |
238 | unsigned char htype = p->ule_sndu_type & 0x00FF; | |
239 | ||
240 | /* Discriminate mandatory and optional extension headers. */ | |
241 | if (hlen == 0) { | |
242 | /* Mandatory extension header */ | |
243 | if (ule_mandatory_ext_handlers[htype]) { | |
244 | ext_len = ule_mandatory_ext_handlers[htype]( p ); | |
18232ca6 CP |
245 | if(ext_len >= 0) { |
246 | p->ule_next_hdr += ext_len; | |
247 | if (!p->ule_bridged) { | |
12fbcef1 | 248 | p->ule_sndu_type = ntohs(*(__be16 *)p->ule_next_hdr); |
18232ca6 CP |
249 | p->ule_next_hdr += 2; |
250 | } else { | |
12fbcef1 | 251 | p->ule_sndu_type = ntohs(*(__be16 *)(p->ule_next_hdr + ((p->ule_dbit ? 2 : 3) * ETH_ALEN))); |
18232ca6 CP |
252 | /* This assures the extension handling loop will terminate. */ |
253 | } | |
1da177e4 | 254 | } |
18232ca6 | 255 | // else: extension handler failed or SNDU should be discarded |
1da177e4 LT |
256 | } else |
257 | ext_len = -1; /* SNDU has to be discarded. */ | |
258 | } else { | |
259 | /* Optional extension header. Calculate the length. */ | |
18232ca6 | 260 | ext_len = hlen << 1; |
1da177e4 LT |
261 | /* Process the optional extension header according to its type. */ |
262 | if (ule_optional_ext_handlers[htype]) | |
263 | (void)ule_optional_ext_handlers[htype]( p ); | |
264 | p->ule_next_hdr += ext_len; | |
12fbcef1 | 265 | p->ule_sndu_type = ntohs( *(__be16 *)(p->ule_next_hdr-2) ); |
18232ca6 CP |
266 | /* |
267 | * note: the length of the next header type is included in the | |
268 | * length of THIS optional extension header | |
269 | */ | |
1da177e4 LT |
270 | } |
271 | ||
272 | return ext_len; | |
273 | } | |
274 | ||
275 | static int handle_ule_extensions( struct dvb_net_priv *p ) | |
276 | { | |
277 | int total_ext_len = 0, l; | |
278 | ||
279 | p->ule_next_hdr = p->ule_skb->data; | |
280 | do { | |
281 | l = handle_one_ule_extension( p ); | |
18232ca6 CP |
282 | if (l < 0) |
283 | return l; /* Stop extension header processing and discard SNDU. */ | |
1da177e4 | 284 | total_ext_len += l; |
18232ca6 | 285 | #ifdef ULE_DEBUG |
5c7c0ca0 JP |
286 | pr_debug("ule_next_hdr=%p, ule_sndu_type=%i, l=%i, total_ext_len=%i\n", |
287 | p->ule_next_hdr, (int)p->ule_sndu_type, | |
288 | l, total_ext_len); | |
18232ca6 | 289 | #endif |
1da177e4 | 290 | |
e5c5d22e | 291 | } while (p->ule_sndu_type < ETH_P_802_3_MIN); |
1da177e4 LT |
292 | |
293 | return total_ext_len; | |
294 | } | |
295 | ||
296 | ||
297 | /** Prepare for a new ULE SNDU: reset the decoder state. */ | |
298 | static inline void reset_ule( struct dvb_net_priv *p ) | |
299 | { | |
300 | p->ule_skb = NULL; | |
301 | p->ule_next_hdr = NULL; | |
302 | p->ule_sndu_len = 0; | |
303 | p->ule_sndu_type = 0; | |
304 | p->ule_sndu_type_1 = 0; | |
305 | p->ule_sndu_remain = 0; | |
306 | p->ule_dbit = 0xFF; | |
307 | p->ule_bridged = 0; | |
308 | } | |
309 | ||
310 | /** | |
311 | * Decode ULE SNDUs according to draft-ietf-ipdvb-ule-03.txt from a sequence of | |
312 | * TS cells of a single PID. | |
313 | */ | |
314 | static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len ) | |
315 | { | |
0eade1f9 | 316 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 | 317 | unsigned long skipped = 0L; |
372280d2 TP |
318 | const u8 *ts, *ts_end, *from_where = NULL; |
319 | u8 ts_remain = 0, how_much = 0, new_ts = 1; | |
1da177e4 | 320 | struct ethhdr *ethh = NULL; |
5c331fc8 | 321 | bool error = false; |
1da177e4 LT |
322 | |
323 | #ifdef ULE_DEBUG | |
324 | /* The code inside ULE_DEBUG keeps a history of the last 100 TS cells processed. */ | |
325 | static unsigned char ule_hist[100*TS_SZ]; | |
ff699e6b | 326 | static unsigned char *ule_where = ule_hist, ule_dump; |
1da177e4 LT |
327 | #endif |
328 | ||
1da177e4 LT |
329 | /* For all TS cells in current buffer. |
330 | * Appearently, we are called for every single TS cell. | |
331 | */ | |
372280d2 | 332 | for (ts = buf, ts_end = buf + buf_len; ts < ts_end; /* no default incr. */ ) { |
1da177e4 LT |
333 | |
334 | if (new_ts) { | |
335 | /* We are about to process a new TS cell. */ | |
336 | ||
337 | #ifdef ULE_DEBUG | |
338 | if (ule_where >= &ule_hist[100*TS_SZ]) ule_where = ule_hist; | |
339 | memcpy( ule_where, ts, TS_SZ ); | |
340 | if (ule_dump) { | |
341 | hexdump( ule_where, TS_SZ ); | |
342 | ule_dump = 0; | |
343 | } | |
344 | ule_where += TS_SZ; | |
345 | #endif | |
346 | ||
347 | /* Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control . */ | |
348 | if ((ts[0] != TS_SYNC) || (ts[1] & TS_TEI) || ((ts[3] & TS_SC) != 0)) { | |
b3ad24d2 | 349 | pr_warn("%lu: Invalid TS cell: SYNC %#x, TEI %u, SC %#x.\n", |
f491dbe0 JP |
350 | priv->ts_count, ts[0], |
351 | (ts[1] & TS_TEI) >> 7, | |
37314528 | 352 | (ts[3] & TS_SC) >> 6); |
1da177e4 LT |
353 | |
354 | /* Drop partly decoded SNDU, reset state, resync on PUSI. */ | |
355 | if (priv->ule_skb) { | |
356 | dev_kfree_skb( priv->ule_skb ); | |
357 | /* Prepare for next SNDU. */ | |
fb875333 SH |
358 | dev->stats.rx_errors++; |
359 | dev->stats.rx_frame_errors++; | |
1da177e4 LT |
360 | } |
361 | reset_ule(priv); | |
362 | priv->need_pusi = 1; | |
363 | ||
364 | /* Continue with next TS cell. */ | |
365 | ts += TS_SZ; | |
366 | priv->ts_count++; | |
367 | continue; | |
368 | } | |
369 | ||
370 | ts_remain = 184; | |
371 | from_where = ts + 4; | |
372 | } | |
373 | /* Synchronize on PUSI, if required. */ | |
374 | if (priv->need_pusi) { | |
375 | if (ts[1] & TS_PUSI) { | |
376 | /* Find beginning of first ULE SNDU in current TS cell. */ | |
377 | /* Synchronize continuity counter. */ | |
378 | priv->tscc = ts[3] & 0x0F; | |
379 | /* There is a pointer field here. */ | |
380 | if (ts[4] > ts_remain) { | |
b3ad24d2 MCC |
381 | pr_err("%lu: Invalid ULE packet (pointer field %d)\n", |
382 | priv->ts_count, ts[4]); | |
1da177e4 LT |
383 | ts += TS_SZ; |
384 | priv->ts_count++; | |
385 | continue; | |
386 | } | |
387 | /* Skip to destination of pointer field. */ | |
388 | from_where = &ts[5] + ts[4]; | |
389 | ts_remain -= 1 + ts[4]; | |
390 | skipped = 0; | |
391 | } else { | |
392 | skipped++; | |
393 | ts += TS_SZ; | |
394 | priv->ts_count++; | |
395 | continue; | |
396 | } | |
397 | } | |
398 | ||
1da177e4 | 399 | if (new_ts) { |
18232ca6 | 400 | /* Check continuity counter. */ |
1da177e4 LT |
401 | if ((ts[3] & 0x0F) == priv->tscc) |
402 | priv->tscc = (priv->tscc + 1) & 0x0F; | |
403 | else { | |
404 | /* TS discontinuity handling: */ | |
b3ad24d2 MCC |
405 | pr_warn("%lu: TS discontinuity: got %#x, expected %#x.\n", |
406 | priv->ts_count, ts[3] & 0x0F, | |
407 | priv->tscc); | |
1da177e4 LT |
408 | /* Drop partly decoded SNDU, reset state, resync on PUSI. */ |
409 | if (priv->ule_skb) { | |
410 | dev_kfree_skb( priv->ule_skb ); | |
411 | /* Prepare for next SNDU. */ | |
412 | // reset_ule(priv); moved to below. | |
fb875333 SH |
413 | dev->stats.rx_errors++; |
414 | dev->stats.rx_frame_errors++; | |
1da177e4 LT |
415 | } |
416 | reset_ule(priv); | |
417 | /* skip to next PUSI. */ | |
418 | priv->need_pusi = 1; | |
1da177e4 LT |
419 | continue; |
420 | } | |
421 | /* If we still have an incomplete payload, but PUSI is | |
422 | * set; some TS cells are missing. | |
423 | * This is only possible here, if we missed exactly 16 TS | |
424 | * cells (continuity counter wrap). */ | |
425 | if (ts[1] & TS_PUSI) { | |
426 | if (! priv->need_pusi) { | |
18232ca6 | 427 | if (!(*from_where < (ts_remain-1)) || *from_where != priv->ule_sndu_remain) { |
1da177e4 | 428 | /* Pointer field is invalid. Drop this TS cell and any started ULE SNDU. */ |
b3ad24d2 MCC |
429 | pr_warn("%lu: Invalid pointer field: %u.\n", |
430 | priv->ts_count, | |
431 | *from_where); | |
1da177e4 LT |
432 | |
433 | /* Drop partly decoded SNDU, reset state, resync on PUSI. */ | |
434 | if (priv->ule_skb) { | |
5c331fc8 AWC |
435 | error = true; |
436 | dev_kfree_skb(priv->ule_skb); | |
437 | } | |
438 | ||
439 | if (error || priv->ule_sndu_remain) { | |
fb875333 SH |
440 | dev->stats.rx_errors++; |
441 | dev->stats.rx_frame_errors++; | |
5c331fc8 | 442 | error = false; |
1da177e4 | 443 | } |
5c331fc8 | 444 | |
1da177e4 LT |
445 | reset_ule(priv); |
446 | priv->need_pusi = 1; | |
1da177e4 LT |
447 | continue; |
448 | } | |
449 | /* Skip pointer field (we're processing a | |
450 | * packed payload). */ | |
451 | from_where += 1; | |
452 | ts_remain -= 1; | |
453 | } else | |
454 | priv->need_pusi = 0; | |
455 | ||
456 | if (priv->ule_sndu_remain > 183) { | |
457 | /* Current SNDU lacks more data than there could be available in the | |
458 | * current TS cell. */ | |
fb875333 SH |
459 | dev->stats.rx_errors++; |
460 | dev->stats.rx_length_errors++; | |
b3ad24d2 MCC |
461 | pr_warn("%lu: Expected %d more SNDU bytes, but got PUSI (pf %d, ts_remain %d). Flushing incomplete payload.\n", |
462 | priv->ts_count, | |
463 | priv->ule_sndu_remain, | |
464 | ts[4], ts_remain); | |
1da177e4 LT |
465 | dev_kfree_skb(priv->ule_skb); |
466 | /* Prepare for next SNDU. */ | |
467 | reset_ule(priv); | |
468 | /* Resync: go to where pointer field points to: start of next ULE SNDU. */ | |
469 | from_where += ts[4]; | |
470 | ts_remain -= ts[4]; | |
471 | } | |
472 | } | |
473 | } | |
474 | ||
475 | /* Check if new payload needs to be started. */ | |
476 | if (priv->ule_skb == NULL) { | |
477 | /* Start a new payload with skb. | |
478 | * Find ULE header. It is only guaranteed that the | |
479 | * length field (2 bytes) is contained in the current | |
480 | * TS. | |
481 | * Check ts_remain has to be >= 2 here. */ | |
482 | if (ts_remain < 2) { | |
b3ad24d2 MCC |
483 | pr_warn("Invalid payload packing: only %d bytes left in TS. Resyncing.\n", |
484 | ts_remain); | |
1da177e4 LT |
485 | priv->ule_sndu_len = 0; |
486 | priv->need_pusi = 1; | |
29e1fa35 | 487 | ts += TS_SZ; |
1da177e4 LT |
488 | continue; |
489 | } | |
490 | ||
491 | if (! priv->ule_sndu_len) { | |
492 | /* Got at least two bytes, thus extrace the SNDU length. */ | |
493 | priv->ule_sndu_len = from_where[0] << 8 | from_where[1]; | |
494 | if (priv->ule_sndu_len & 0x8000) { | |
495 | /* D-Bit is set: no dest mac present. */ | |
496 | priv->ule_sndu_len &= 0x7FFF; | |
497 | priv->ule_dbit = 1; | |
498 | } else | |
499 | priv->ule_dbit = 0; | |
500 | ||
18232ca6 | 501 | if (priv->ule_sndu_len < 5) { |
b3ad24d2 MCC |
502 | pr_warn("%lu: Invalid ULE SNDU length %u. Resyncing.\n", |
503 | priv->ts_count, | |
504 | priv->ule_sndu_len); | |
fb875333 SH |
505 | dev->stats.rx_errors++; |
506 | dev->stats.rx_length_errors++; | |
1da177e4 LT |
507 | priv->ule_sndu_len = 0; |
508 | priv->need_pusi = 1; | |
509 | new_ts = 1; | |
510 | ts += TS_SZ; | |
511 | priv->ts_count++; | |
512 | continue; | |
513 | } | |
514 | ts_remain -= 2; /* consume the 2 bytes SNDU length. */ | |
515 | from_where += 2; | |
516 | } | |
517 | ||
5c331fc8 | 518 | priv->ule_sndu_remain = priv->ule_sndu_len + 2; |
1da177e4 LT |
519 | /* |
520 | * State of current TS: | |
521 | * ts_remain (remaining bytes in the current TS cell) | |
522 | * 0 ule_type is not available now, we need the next TS cell | |
523 | * 1 the first byte of the ule_type is present | |
524 | * >=2 full ULE header present, maybe some payload data as well. | |
525 | */ | |
526 | switch (ts_remain) { | |
527 | case 1: | |
5c331fc8 | 528 | priv->ule_sndu_remain--; |
1da177e4 LT |
529 | priv->ule_sndu_type = from_where[0] << 8; |
530 | priv->ule_sndu_type_1 = 1; /* first byte of ule_type is set. */ | |
531 | ts_remain -= 1; from_where += 1; | |
532 | /* Continue w/ next TS. */ | |
533 | case 0: | |
534 | new_ts = 1; | |
535 | ts += TS_SZ; | |
536 | priv->ts_count++; | |
537 | continue; | |
538 | ||
539 | default: /* complete ULE header is present in current TS. */ | |
540 | /* Extract ULE type field. */ | |
541 | if (priv->ule_sndu_type_1) { | |
5c331fc8 | 542 | priv->ule_sndu_type_1 = 0; |
1da177e4 LT |
543 | priv->ule_sndu_type |= from_where[0]; |
544 | from_where += 1; /* points to payload start. */ | |
545 | ts_remain -= 1; | |
546 | } else { | |
547 | /* Complete type is present in new TS. */ | |
548 | priv->ule_sndu_type = from_where[0] << 8 | from_where[1]; | |
549 | from_where += 2; /* points to payload start. */ | |
550 | ts_remain -= 2; | |
551 | } | |
552 | break; | |
553 | } | |
554 | ||
555 | /* Allocate the skb (decoder target buffer) with the correct size, as follows: | |
556 | * prepare for the largest case: bridged SNDU with MAC address (dbit = 0). */ | |
557 | priv->ule_skb = dev_alloc_skb( priv->ule_sndu_len + ETH_HLEN + ETH_ALEN ); | |
558 | if (priv->ule_skb == NULL) { | |
b3ad24d2 MCC |
559 | pr_notice("%s: Memory squeeze, dropping packet.\n", |
560 | dev->name); | |
fb875333 | 561 | dev->stats.rx_dropped++; |
1da177e4 LT |
562 | return; |
563 | } | |
564 | ||
565 | /* This includes the CRC32 _and_ dest mac, if !dbit. */ | |
566 | priv->ule_sndu_remain = priv->ule_sndu_len; | |
567 | priv->ule_skb->dev = dev; | |
568 | /* Leave space for Ethernet or bridged SNDU header (eth hdr plus one MAC addr). */ | |
569 | skb_reserve( priv->ule_skb, ETH_HLEN + ETH_ALEN ); | |
570 | } | |
571 | ||
572 | /* Copy data into our current skb. */ | |
573 | how_much = min(priv->ule_sndu_remain, (int)ts_remain); | |
574 | memcpy(skb_put(priv->ule_skb, how_much), from_where, how_much); | |
575 | priv->ule_sndu_remain -= how_much; | |
576 | ts_remain -= how_much; | |
577 | from_where += how_much; | |
578 | ||
579 | /* Check for complete payload. */ | |
580 | if (priv->ule_sndu_remain <= 0) { | |
581 | /* Check CRC32, we've got it in our skb already. */ | |
12fbcef1 AV |
582 | __be16 ulen = htons(priv->ule_sndu_len); |
583 | __be16 utype = htons(priv->ule_sndu_type); | |
27a884dc | 584 | const u8 *tail; |
1da177e4 LT |
585 | struct kvec iov[3] = { |
586 | { &ulen, sizeof ulen }, | |
587 | { &utype, sizeof utype }, | |
588 | { priv->ule_skb->data, priv->ule_skb->len - 4 } | |
589 | }; | |
dedcefb0 | 590 | u32 ule_crc = ~0L, expected_crc; |
1da177e4 LT |
591 | if (priv->ule_dbit) { |
592 | /* Set D-bit for CRC32 verification, | |
593 | * if it was set originally. */ | |
f51b10ef | 594 | ulen |= htons(0x8000); |
1da177e4 LT |
595 | } |
596 | ||
597 | ule_crc = iov_crc32(ule_crc, iov, 3); | |
27a884dc ACM |
598 | tail = skb_tail_pointer(priv->ule_skb); |
599 | expected_crc = *(tail - 4) << 24 | | |
600 | *(tail - 3) << 16 | | |
601 | *(tail - 2) << 8 | | |
602 | *(tail - 1); | |
1da177e4 | 603 | if (ule_crc != expected_crc) { |
b3ad24d2 MCC |
604 | pr_warn("%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n", |
605 | priv->ts_count, ule_crc, expected_crc, | |
606 | priv->ule_sndu_len, priv->ule_sndu_type, | |
607 | ts_remain, | |
608 | ts_remain > 2 ? *(unsigned short *)from_where : 0); | |
1da177e4 LT |
609 | |
610 | #ifdef ULE_DEBUG | |
611 | hexdump( iov[0].iov_base, iov[0].iov_len ); | |
612 | hexdump( iov[1].iov_base, iov[1].iov_len ); | |
613 | hexdump( iov[2].iov_base, iov[2].iov_len ); | |
614 | ||
615 | if (ule_where == ule_hist) { | |
616 | hexdump( &ule_hist[98*TS_SZ], TS_SZ ); | |
617 | hexdump( &ule_hist[99*TS_SZ], TS_SZ ); | |
618 | } else if (ule_where == &ule_hist[TS_SZ]) { | |
619 | hexdump( &ule_hist[99*TS_SZ], TS_SZ ); | |
620 | hexdump( ule_hist, TS_SZ ); | |
621 | } else { | |
622 | hexdump( ule_where - TS_SZ - TS_SZ, TS_SZ ); | |
623 | hexdump( ule_where - TS_SZ, TS_SZ ); | |
624 | } | |
625 | ule_dump = 1; | |
626 | #endif | |
627 | ||
fb875333 SH |
628 | dev->stats.rx_errors++; |
629 | dev->stats.rx_crc_errors++; | |
1da177e4 LT |
630 | dev_kfree_skb(priv->ule_skb); |
631 | } else { | |
632 | /* CRC32 verified OK. */ | |
18232ca6 CP |
633 | u8 dest_addr[ETH_ALEN]; |
634 | static const u8 bc_addr[ETH_ALEN] = | |
635 | { [ 0 ... ETH_ALEN-1] = 0xff }; | |
636 | ||
637 | /* CRC32 was OK. Remove it from skb. */ | |
638 | priv->ule_skb->tail -= 4; | |
639 | priv->ule_skb->len -= 4; | |
640 | ||
641 | if (!priv->ule_dbit) { | |
642 | /* | |
643 | * The destination MAC address is the | |
644 | * next data in the skb. It comes | |
645 | * before any extension headers. | |
646 | * | |
647 | * Check if the payload of this SNDU | |
648 | * should be passed up the stack. | |
649 | */ | |
650 | register int drop = 0; | |
651 | if (priv->rx_mode != RX_MODE_PROMISC) { | |
652 | if (priv->ule_skb->data[0] & 0x01) { | |
653 | /* multicast or broadcast */ | |
5e231c2c | 654 | if (!ether_addr_equal(priv->ule_skb->data, bc_addr)) { |
18232ca6 CP |
655 | /* multicast */ |
656 | if (priv->rx_mode == RX_MODE_MULTI) { | |
657 | int i; | |
5e231c2c | 658 | for(i = 0; i < priv->multi_num && |
659 | !ether_addr_equal(priv->ule_skb->data, | |
660 | priv->multi_macs[i]); i++) | |
18232ca6 CP |
661 | ; |
662 | if (i == priv->multi_num) | |
663 | drop = 1; | |
664 | } else if (priv->rx_mode != RX_MODE_ALL_MULTI) | |
665 | drop = 1; /* no broadcast; */ | |
666 | /* else: all multicast mode: accept all multicast packets */ | |
667 | } | |
668 | /* else: broadcast */ | |
669 | } | |
5e231c2c | 670 | else if (!ether_addr_equal(priv->ule_skb->data, dev->dev_addr)) |
18232ca6 CP |
671 | drop = 1; |
672 | /* else: destination address matches the MAC address of our receiver device */ | |
673 | } | |
c84e6036 | 674 | /* else: promiscuous mode; pass everything up the stack */ |
18232ca6 CP |
675 | |
676 | if (drop) { | |
677 | #ifdef ULE_DEBUG | |
5c7c0ca0 JP |
678 | netdev_dbg(dev, "Dropping SNDU: MAC destination address does not match: dest addr: %pM, dev addr: %pM\n", |
679 | priv->ule_skb->data, dev->dev_addr); | |
18232ca6 CP |
680 | #endif |
681 | dev_kfree_skb(priv->ule_skb); | |
682 | goto sndu_done; | |
683 | } | |
684 | else | |
685 | { | |
d626f62b ACM |
686 | skb_copy_from_linear_data(priv->ule_skb, |
687 | dest_addr, | |
688 | ETH_ALEN); | |
18232ca6 CP |
689 | skb_pull(priv->ule_skb, ETH_ALEN); |
690 | } | |
691 | } | |
692 | ||
1da177e4 | 693 | /* Handle ULE Extension Headers. */ |
e5c5d22e | 694 | if (priv->ule_sndu_type < ETH_P_802_3_MIN) { |
1da177e4 | 695 | /* There is an extension header. Handle it accordingly. */ |
18232ca6 | 696 | int l = handle_ule_extensions(priv); |
1da177e4 LT |
697 | if (l < 0) { |
698 | /* Mandatory extension header unknown or TEST SNDU. Drop it. */ | |
b3ad24d2 | 699 | // pr_warn("Dropping SNDU, extension headers.\n" ); |
18232ca6 | 700 | dev_kfree_skb(priv->ule_skb); |
1da177e4 LT |
701 | goto sndu_done; |
702 | } | |
18232ca6 | 703 | skb_pull(priv->ule_skb, l); |
1da177e4 LT |
704 | } |
705 | ||
18232ca6 CP |
706 | /* |
707 | * Construct/assure correct ethernet header. | |
708 | * Note: in bridged mode (priv->ule_bridged != | |
709 | * 0) we already have the (original) ethernet | |
710 | * header at the start of the payload (after | |
711 | * optional dest. address and any extension | |
712 | * headers). | |
713 | */ | |
714 | ||
715 | if (!priv->ule_bridged) { | |
716 | skb_push(priv->ule_skb, ETH_HLEN); | |
717 | ethh = (struct ethhdr *)priv->ule_skb->data; | |
718 | if (!priv->ule_dbit) { | |
719 | /* dest_addr buffer is only valid if priv->ule_dbit == 0 */ | |
720 | memcpy(ethh->h_dest, dest_addr, ETH_ALEN); | |
4dc102b2 | 721 | eth_zero_addr(ethh->h_source); |
1da177e4 | 722 | } |
18232ca6 CP |
723 | else /* zeroize source and dest */ |
724 | memset( ethh, 0, ETH_ALEN*2 ); | |
725 | ||
726 | ethh->h_proto = htons(priv->ule_sndu_type); | |
1da177e4 | 727 | } |
18232ca6 | 728 | /* else: skb is in correct state; nothing to do. */ |
1da177e4 LT |
729 | priv->ule_bridged = 0; |
730 | ||
731 | /* Stuff into kernel's protocol stack. */ | |
732 | priv->ule_skb->protocol = dvb_net_eth_type_trans(priv->ule_skb, dev); | |
733 | /* If D-bit is set (i.e. destination MAC address not present), | |
734 | * receive the packet anyhow. */ | |
735 | /* if (priv->ule_dbit && skb->pkt_type == PACKET_OTHERHOST) | |
736 | priv->ule_skb->pkt_type = PACKET_HOST; */ | |
fb875333 SH |
737 | dev->stats.rx_packets++; |
738 | dev->stats.rx_bytes += priv->ule_skb->len; | |
1da177e4 LT |
739 | netif_rx(priv->ule_skb); |
740 | } | |
741 | sndu_done: | |
742 | /* Prepare for next SNDU. */ | |
743 | reset_ule(priv); | |
744 | } | |
745 | ||
746 | /* More data in current TS (look at the bytes following the CRC32)? */ | |
747 | if (ts_remain >= 2 && *((unsigned short *)from_where) != 0xFFFF) { | |
748 | /* Next ULE SNDU starts right there. */ | |
749 | new_ts = 0; | |
750 | priv->ule_skb = NULL; | |
751 | priv->ule_sndu_type_1 = 0; | |
752 | priv->ule_sndu_len = 0; | |
b3ad24d2 | 753 | // pr_warn("More data in current TS: [%#x %#x %#x %#x]\n", |
1da177e4 LT |
754 | // *(from_where + 0), *(from_where + 1), |
755 | // *(from_where + 2), *(from_where + 3)); | |
b3ad24d2 | 756 | // pr_warn("ts @ %p, stopped @ %p:\n", ts, from_where + 0); |
1da177e4 LT |
757 | // hexdump(ts, 188); |
758 | } else { | |
759 | new_ts = 1; | |
760 | ts += TS_SZ; | |
761 | priv->ts_count++; | |
762 | if (priv->ule_skb == NULL) { | |
763 | priv->need_pusi = 1; | |
764 | priv->ule_sndu_type_1 = 0; | |
765 | priv->ule_sndu_len = 0; | |
766 | } | |
767 | } | |
768 | } /* for all available TS cells */ | |
769 | } | |
770 | ||
771 | static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len, | |
772 | const u8 *buffer2, size_t buffer2_len, | |
2f684b23 | 773 | struct dmx_ts_feed *feed) |
1da177e4 | 774 | { |
0c53c70f | 775 | struct net_device *dev = feed->priv; |
1da177e4 | 776 | |
5fa1247a | 777 | if (buffer2) |
b3ad24d2 | 778 | pr_warn("buffer2 not NULL: %p.\n", buffer2); |
1da177e4 | 779 | if (buffer1_len > 32768) |
b3ad24d2 MCC |
780 | pr_warn("length > 32k: %zu.\n", buffer1_len); |
781 | /* pr_info("TS callback: %u bytes, %u TS cells @ %p.\n", | |
afd1a0c9 | 782 | buffer1_len, buffer1_len / TS_SZ, buffer1); */ |
1da177e4 LT |
783 | dvb_net_ule(dev, buffer1, buffer1_len); |
784 | return 0; | |
785 | } | |
786 | ||
787 | ||
71be258b MK |
788 | static void dvb_net_sec(struct net_device *dev, |
789 | const u8 *pkt, int pkt_len) | |
1da177e4 | 790 | { |
afd1a0c9 MCC |
791 | u8 *eth; |
792 | struct sk_buff *skb; | |
fb875333 | 793 | struct net_device_stats *stats = &dev->stats; |
59142330 | 794 | int snap = 0; |
1da177e4 LT |
795 | |
796 | /* note: pkt_len includes a 32bit checksum */ | |
797 | if (pkt_len < 16) { | |
b3ad24d2 | 798 | pr_warn("%s: IP/MPE packet length = %d too small.\n", |
1da177e4 LT |
799 | dev->name, pkt_len); |
800 | stats->rx_errors++; | |
801 | stats->rx_length_errors++; | |
802 | return; | |
803 | } | |
804 | /* it seems some ISPs manage to screw up here, so we have to | |
805 | * relax the error checks... */ | |
806 | #if 0 | |
807 | if ((pkt[5] & 0xfd) != 0xc1) { | |
808 | /* drop scrambled or broken packets */ | |
809 | #else | |
810 | if ((pkt[5] & 0x3c) != 0x00) { | |
811 | /* drop scrambled */ | |
812 | #endif | |
813 | stats->rx_errors++; | |
814 | stats->rx_crc_errors++; | |
815 | return; | |
816 | } | |
817 | if (pkt[5] & 0x02) { | |
59142330 JS |
818 | /* handle LLC/SNAP, see rfc-1042 */ |
819 | if (pkt_len < 24 || memcmp(&pkt[12], "\xaa\xaa\x03\0\0\0", 6)) { | |
820 | stats->rx_dropped++; | |
821 | return; | |
822 | } | |
823 | snap = 8; | |
afd1a0c9 | 824 | } |
1da177e4 LT |
825 | if (pkt[7]) { |
826 | /* FIXME: assemble datagram from multiple sections */ | |
827 | stats->rx_errors++; | |
828 | stats->rx_frame_errors++; | |
829 | return; | |
830 | } | |
831 | ||
832 | /* we have 14 byte ethernet header (ip header follows); | |
59142330 | 833 | * 12 byte MPE header; 4 byte checksum; + 2 byte alignment, 8 byte LLC/SNAP |
1da177e4 | 834 | */ |
59142330 | 835 | if (!(skb = dev_alloc_skb(pkt_len - 4 - 12 + 14 + 2 - snap))) { |
b3ad24d2 | 836 | //pr_notice("%s: Memory squeeze, dropping packet.\n", dev->name); |
1da177e4 LT |
837 | stats->rx_dropped++; |
838 | return; | |
839 | } | |
840 | skb_reserve(skb, 2); /* longword align L3 header */ | |
841 | skb->dev = dev; | |
842 | ||
843 | /* copy L3 payload */ | |
59142330 JS |
844 | eth = (u8 *) skb_put(skb, pkt_len - 12 - 4 + 14 - snap); |
845 | memcpy(eth + 14, pkt + 12 + snap, pkt_len - 12 - 4 - snap); | |
1da177e4 LT |
846 | |
847 | /* create ethernet header: */ | |
afd1a0c9 MCC |
848 | eth[0]=pkt[0x0b]; |
849 | eth[1]=pkt[0x0a]; | |
850 | eth[2]=pkt[0x09]; | |
851 | eth[3]=pkt[0x08]; | |
852 | eth[4]=pkt[0x04]; | |
853 | eth[5]=pkt[0x03]; | |
1da177e4 | 854 | |
afd1a0c9 | 855 | eth[6]=eth[7]=eth[8]=eth[9]=eth[10]=eth[11]=0; |
1da177e4 | 856 | |
59142330 JS |
857 | if (snap) { |
858 | eth[12] = pkt[18]; | |
859 | eth[13] = pkt[19]; | |
860 | } else { | |
861 | /* protocol numbers are from rfc-1700 or | |
862 | * http://www.iana.org/assignments/ethernet-numbers | |
863 | */ | |
864 | if (pkt[12] >> 4 == 6) { /* version field from IP header */ | |
865 | eth[12] = 0x86; /* IPv6 */ | |
866 | eth[13] = 0xdd; | |
867 | } else { | |
868 | eth[12] = 0x08; /* IPv4 */ | |
869 | eth[13] = 0x00; | |
870 | } | |
871 | } | |
1da177e4 LT |
872 | |
873 | skb->protocol = dvb_net_eth_type_trans(skb, dev); | |
874 | ||
875 | stats->rx_packets++; | |
876 | stats->rx_bytes+=skb->len; | |
afd1a0c9 | 877 | netif_rx(skb); |
1da177e4 LT |
878 | } |
879 | ||
880 | static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len, | |
881 | const u8 *buffer2, size_t buffer2_len, | |
2f684b23 | 882 | struct dmx_section_filter *filter) |
1da177e4 | 883 | { |
afd1a0c9 | 884 | struct net_device *dev = filter->priv; |
1da177e4 LT |
885 | |
886 | /** | |
887 | * we rely on the DVB API definition where exactly one complete | |
888 | * section is delivered in buffer1 | |
889 | */ | |
04b35abe | 890 | dvb_net_sec (dev, buffer1, buffer1_len); |
1da177e4 LT |
891 | return 0; |
892 | } | |
893 | ||
894 | static int dvb_net_tx(struct sk_buff *skb, struct net_device *dev) | |
895 | { | |
896 | dev_kfree_skb(skb); | |
6ed10654 | 897 | return NETDEV_TX_OK; |
1da177e4 LT |
898 | } |
899 | ||
900 | static u8 mask_normal[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
901 | static u8 mask_allmulti[6]={0xff, 0xff, 0xff, 0x00, 0x00, 0x00}; | |
902 | static u8 mac_allmulti[6]={0x01, 0x00, 0x5e, 0x00, 0x00, 0x00}; | |
903 | static u8 mask_promisc[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; | |
904 | ||
905 | static int dvb_net_filter_sec_set(struct net_device *dev, | |
906 | struct dmx_section_filter **secfilter, | |
907 | u8 *mac, u8 *mac_mask) | |
908 | { | |
0eade1f9 | 909 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 LT |
910 | int ret; |
911 | ||
912 | *secfilter=NULL; | |
913 | ret = priv->secfeed->allocate_filter(priv->secfeed, secfilter); | |
914 | if (ret<0) { | |
b3ad24d2 | 915 | pr_err("%s: could not get filter\n", dev->name); |
1da177e4 LT |
916 | return ret; |
917 | } | |
918 | ||
919 | (*secfilter)->priv=(void *) dev; | |
920 | ||
921 | memset((*secfilter)->filter_value, 0x00, DMX_MAX_FILTER_SIZE); | |
922 | memset((*secfilter)->filter_mask, 0x00, DMX_MAX_FILTER_SIZE); | |
923 | memset((*secfilter)->filter_mode, 0xff, DMX_MAX_FILTER_SIZE); | |
924 | ||
925 | (*secfilter)->filter_value[0]=0x3e; | |
926 | (*secfilter)->filter_value[3]=mac[5]; | |
927 | (*secfilter)->filter_value[4]=mac[4]; | |
928 | (*secfilter)->filter_value[8]=mac[3]; | |
929 | (*secfilter)->filter_value[9]=mac[2]; | |
930 | (*secfilter)->filter_value[10]=mac[1]; | |
931 | (*secfilter)->filter_value[11]=mac[0]; | |
932 | ||
933 | (*secfilter)->filter_mask[0] = 0xff; | |
934 | (*secfilter)->filter_mask[3] = mac_mask[5]; | |
935 | (*secfilter)->filter_mask[4] = mac_mask[4]; | |
936 | (*secfilter)->filter_mask[8] = mac_mask[3]; | |
937 | (*secfilter)->filter_mask[9] = mac_mask[2]; | |
938 | (*secfilter)->filter_mask[10] = mac_mask[1]; | |
939 | (*secfilter)->filter_mask[11]=mac_mask[0]; | |
940 | ||
5c7c0ca0 | 941 | netdev_dbg(dev, "filter mac=%pM mask=%pM\n", mac, mac_mask); |
1da177e4 LT |
942 | |
943 | return 0; | |
944 | } | |
945 | ||
946 | static int dvb_net_feed_start(struct net_device *dev) | |
947 | { | |
1130ca45 | 948 | int ret = 0, i; |
0eade1f9 | 949 | struct dvb_net_priv *priv = netdev_priv(dev); |
afd1a0c9 MCC |
950 | struct dmx_demux *demux = priv->demux; |
951 | unsigned char *mac = (unsigned char *) dev->dev_addr; | |
1da177e4 | 952 | |
5c7c0ca0 | 953 | netdev_dbg(dev, "rx_mode %i\n", priv->rx_mode); |
3593cab5 | 954 | mutex_lock(&priv->mutex); |
1da177e4 | 955 | if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0]) |
b3ad24d2 | 956 | pr_err("%s: BUG %d\n", __func__, __LINE__); |
1da177e4 LT |
957 | |
958 | priv->secfeed=NULL; | |
959 | priv->secfilter=NULL; | |
960 | priv->tsfeed = NULL; | |
961 | ||
962 | if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { | |
5c7c0ca0 | 963 | netdev_dbg(dev, "alloc secfeed\n"); |
1da177e4 LT |
964 | ret=demux->allocate_section_feed(demux, &priv->secfeed, |
965 | dvb_net_sec_callback); | |
966 | if (ret<0) { | |
b3ad24d2 MCC |
967 | pr_err("%s: could not allocate section feed\n", |
968 | dev->name); | |
1130ca45 | 969 | goto error; |
1da177e4 LT |
970 | } |
971 | ||
5d2cd163 | 972 | ret = priv->secfeed->set(priv->secfeed, priv->pid, 32768, 1); |
1da177e4 LT |
973 | |
974 | if (ret<0) { | |
b3ad24d2 | 975 | pr_err("%s: could not set section feed\n", dev->name); |
1da177e4 LT |
976 | priv->demux->release_section_feed(priv->demux, priv->secfeed); |
977 | priv->secfeed=NULL; | |
1130ca45 | 978 | goto error; |
1da177e4 LT |
979 | } |
980 | ||
981 | if (priv->rx_mode != RX_MODE_PROMISC) { | |
5c7c0ca0 | 982 | netdev_dbg(dev, "set secfilter\n"); |
1da177e4 LT |
983 | dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_normal); |
984 | } | |
985 | ||
986 | switch (priv->rx_mode) { | |
987 | case RX_MODE_MULTI: | |
988 | for (i = 0; i < priv->multi_num; i++) { | |
5c7c0ca0 | 989 | netdev_dbg(dev, "set multi_secfilter[%d]\n", i); |
1da177e4 LT |
990 | dvb_net_filter_sec_set(dev, &priv->multi_secfilter[i], |
991 | priv->multi_macs[i], mask_normal); | |
992 | } | |
993 | break; | |
994 | case RX_MODE_ALL_MULTI: | |
995 | priv->multi_num=1; | |
5c7c0ca0 | 996 | netdev_dbg(dev, "set multi_secfilter[0]\n"); |
1da177e4 LT |
997 | dvb_net_filter_sec_set(dev, &priv->multi_secfilter[0], |
998 | mac_allmulti, mask_allmulti); | |
999 | break; | |
1000 | case RX_MODE_PROMISC: | |
1001 | priv->multi_num=0; | |
5c7c0ca0 | 1002 | netdev_dbg(dev, "set secfilter\n"); |
1da177e4 LT |
1003 | dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_promisc); |
1004 | break; | |
1005 | } | |
1006 | ||
5c7c0ca0 | 1007 | netdev_dbg(dev, "start filtering\n"); |
1da177e4 LT |
1008 | priv->secfeed->start_filtering(priv->secfeed); |
1009 | } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { | |
e95be158 | 1010 | ktime_t timeout = ns_to_ktime(10 * NSEC_PER_MSEC); |
1da177e4 LT |
1011 | |
1012 | /* we have payloads encapsulated in TS */ | |
5c7c0ca0 | 1013 | netdev_dbg(dev, "alloc tsfeed\n"); |
1da177e4 LT |
1014 | ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback); |
1015 | if (ret < 0) { | |
b3ad24d2 | 1016 | pr_err("%s: could not allocate ts feed\n", dev->name); |
1130ca45 | 1017 | goto error; |
1da177e4 LT |
1018 | } |
1019 | ||
1020 | /* Set netdevice pointer for ts decaps callback. */ | |
1021 | priv->tsfeed->priv = (void *)dev; | |
18232ca6 CP |
1022 | ret = priv->tsfeed->set(priv->tsfeed, |
1023 | priv->pid, /* pid */ | |
1024 | TS_PACKET, /* type */ | |
fde04ab9 | 1025 | DMX_PES_OTHER, /* pes type */ |
1da177e4 | 1026 | 32768, /* circular buffer size */ |
18232ca6 CP |
1027 | timeout /* timeout */ |
1028 | ); | |
1da177e4 LT |
1029 | |
1030 | if (ret < 0) { | |
b3ad24d2 | 1031 | pr_err("%s: could not set ts feed\n", dev->name); |
1da177e4 LT |
1032 | priv->demux->release_ts_feed(priv->demux, priv->tsfeed); |
1033 | priv->tsfeed = NULL; | |
1130ca45 | 1034 | goto error; |
1da177e4 LT |
1035 | } |
1036 | ||
5c7c0ca0 | 1037 | netdev_dbg(dev, "start filtering\n"); |
1da177e4 LT |
1038 | priv->tsfeed->start_filtering(priv->tsfeed); |
1039 | } else | |
1130ca45 | 1040 | ret = -EINVAL; |
1da177e4 | 1041 | |
1130ca45 | 1042 | error: |
3593cab5 | 1043 | mutex_unlock(&priv->mutex); |
1130ca45 | 1044 | return ret; |
1da177e4 LT |
1045 | } |
1046 | ||
1047 | static int dvb_net_feed_stop(struct net_device *dev) | |
1048 | { | |
0eade1f9 | 1049 | struct dvb_net_priv *priv = netdev_priv(dev); |
1130ca45 | 1050 | int i, ret = 0; |
1da177e4 | 1051 | |
3593cab5 | 1052 | mutex_lock(&priv->mutex); |
1da177e4 LT |
1053 | if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { |
1054 | if (priv->secfeed) { | |
1055 | if (priv->secfeed->is_filtering) { | |
5c7c0ca0 | 1056 | netdev_dbg(dev, "stop secfeed\n"); |
1da177e4 LT |
1057 | priv->secfeed->stop_filtering(priv->secfeed); |
1058 | } | |
1059 | ||
1060 | if (priv->secfilter) { | |
5c7c0ca0 | 1061 | netdev_dbg(dev, "release secfilter\n"); |
1da177e4 LT |
1062 | priv->secfeed->release_filter(priv->secfeed, |
1063 | priv->secfilter); | |
1064 | priv->secfilter=NULL; | |
1065 | } | |
1066 | ||
1067 | for (i=0; i<priv->multi_num; i++) { | |
1068 | if (priv->multi_secfilter[i]) { | |
5c7c0ca0 JP |
1069 | netdev_dbg(dev, "release multi_filter[%d]\n", |
1070 | i); | |
1da177e4 LT |
1071 | priv->secfeed->release_filter(priv->secfeed, |
1072 | priv->multi_secfilter[i]); | |
1073 | priv->multi_secfilter[i] = NULL; | |
1074 | } | |
1075 | } | |
1076 | ||
1077 | priv->demux->release_section_feed(priv->demux, priv->secfeed); | |
1078 | priv->secfeed = NULL; | |
1079 | } else | |
b3ad24d2 | 1080 | pr_err("%s: no feed to stop\n", dev->name); |
1da177e4 LT |
1081 | } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { |
1082 | if (priv->tsfeed) { | |
1083 | if (priv->tsfeed->is_filtering) { | |
5c7c0ca0 | 1084 | netdev_dbg(dev, "stop tsfeed\n"); |
1da177e4 LT |
1085 | priv->tsfeed->stop_filtering(priv->tsfeed); |
1086 | } | |
1087 | priv->demux->release_ts_feed(priv->demux, priv->tsfeed); | |
1088 | priv->tsfeed = NULL; | |
1089 | } | |
1090 | else | |
b3ad24d2 | 1091 | pr_err("%s: no ts feed to stop\n", dev->name); |
1da177e4 | 1092 | } else |
1130ca45 | 1093 | ret = -EINVAL; |
3593cab5 | 1094 | mutex_unlock(&priv->mutex); |
1130ca45 | 1095 | return ret; |
1da177e4 LT |
1096 | } |
1097 | ||
1098 | ||
22bedad3 | 1099 | static int dvb_set_mc_filter(struct net_device *dev, unsigned char *addr) |
1da177e4 | 1100 | { |
0eade1f9 | 1101 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 LT |
1102 | |
1103 | if (priv->multi_num == DVB_NET_MULTICAST_MAX) | |
1104 | return -ENOMEM; | |
1105 | ||
22bedad3 | 1106 | memcpy(priv->multi_macs[priv->multi_num], addr, ETH_ALEN); |
1da177e4 LT |
1107 | |
1108 | priv->multi_num++; | |
1109 | return 0; | |
1110 | } | |
1111 | ||
1112 | ||
c4028958 | 1113 | static void wq_set_multicast_list (struct work_struct *work) |
1da177e4 | 1114 | { |
c4028958 DH |
1115 | struct dvb_net_priv *priv = |
1116 | container_of(work, struct dvb_net_priv, set_multicast_list_wq); | |
1117 | struct net_device *dev = priv->net; | |
1da177e4 LT |
1118 | |
1119 | dvb_net_feed_stop(dev); | |
1da177e4 | 1120 | priv->rx_mode = RX_MODE_UNI; |
b9e40857 | 1121 | netif_addr_lock_bh(dev); |
1da177e4 LT |
1122 | |
1123 | if (dev->flags & IFF_PROMISC) { | |
5c7c0ca0 | 1124 | netdev_dbg(dev, "promiscuous mode\n"); |
1da177e4 LT |
1125 | priv->rx_mode = RX_MODE_PROMISC; |
1126 | } else if ((dev->flags & IFF_ALLMULTI)) { | |
5c7c0ca0 | 1127 | netdev_dbg(dev, "allmulti mode\n"); |
1da177e4 | 1128 | priv->rx_mode = RX_MODE_ALL_MULTI; |
4cd24eaf | 1129 | } else if (!netdev_mc_empty(dev)) { |
22bedad3 | 1130 | struct netdev_hw_addr *ha; |
1da177e4 | 1131 | |
5c7c0ca0 JP |
1132 | netdev_dbg(dev, "set_mc_list, %d entries\n", |
1133 | netdev_mc_count(dev)); | |
1da177e4 LT |
1134 | |
1135 | priv->rx_mode = RX_MODE_MULTI; | |
1136 | priv->multi_num = 0; | |
1137 | ||
22bedad3 JP |
1138 | netdev_for_each_mc_addr(ha, dev) |
1139 | dvb_set_mc_filter(dev, ha->addr); | |
1da177e4 LT |
1140 | } |
1141 | ||
b9e40857 | 1142 | netif_addr_unlock_bh(dev); |
1da177e4 LT |
1143 | dvb_net_feed_start(dev); |
1144 | } | |
1145 | ||
1146 | ||
1147 | static void dvb_net_set_multicast_list (struct net_device *dev) | |
1148 | { | |
0eade1f9 | 1149 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 LT |
1150 | schedule_work(&priv->set_multicast_list_wq); |
1151 | } | |
1152 | ||
1153 | ||
c4028958 | 1154 | static void wq_restart_net_feed (struct work_struct *work) |
1da177e4 | 1155 | { |
c4028958 DH |
1156 | struct dvb_net_priv *priv = |
1157 | container_of(work, struct dvb_net_priv, restart_net_feed_wq); | |
1158 | struct net_device *dev = priv->net; | |
1da177e4 LT |
1159 | |
1160 | if (netif_running(dev)) { | |
1161 | dvb_net_feed_stop(dev); | |
1162 | dvb_net_feed_start(dev); | |
1163 | } | |
1164 | } | |
1165 | ||
1166 | ||
1167 | static int dvb_net_set_mac (struct net_device *dev, void *p) | |
1168 | { | |
0eade1f9 | 1169 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 LT |
1170 | struct sockaddr *addr=p; |
1171 | ||
1172 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); | |
1173 | ||
1174 | if (netif_running(dev)) | |
1175 | schedule_work(&priv->restart_net_feed_wq); | |
1176 | ||
1177 | return 0; | |
1178 | } | |
1179 | ||
1180 | ||
1181 | static int dvb_net_open(struct net_device *dev) | |
1182 | { | |
0eade1f9 | 1183 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 LT |
1184 | |
1185 | priv->in_use++; | |
1186 | dvb_net_feed_start(dev); | |
1187 | return 0; | |
1188 | } | |
1189 | ||
1190 | ||
1191 | static int dvb_net_stop(struct net_device *dev) | |
1192 | { | |
0eade1f9 | 1193 | struct dvb_net_priv *priv = netdev_priv(dev); |
1da177e4 LT |
1194 | |
1195 | priv->in_use--; | |
afd1a0c9 | 1196 | return dvb_net_feed_stop(dev); |
1da177e4 LT |
1197 | } |
1198 | ||
3b04ddde SH |
1199 | static const struct header_ops dvb_header_ops = { |
1200 | .create = eth_header, | |
1201 | .parse = eth_header_parse, | |
3b04ddde SH |
1202 | }; |
1203 | ||
fb875333 SH |
1204 | |
1205 | static const struct net_device_ops dvb_netdev_ops = { | |
1206 | .ndo_open = dvb_net_open, | |
1207 | .ndo_stop = dvb_net_stop, | |
1208 | .ndo_start_xmit = dvb_net_tx, | |
afc4b13d | 1209 | .ndo_set_rx_mode = dvb_net_set_multicast_list, |
fb875333 SH |
1210 | .ndo_set_mac_address = dvb_net_set_mac, |
1211 | .ndo_change_mtu = eth_change_mtu, | |
1212 | .ndo_validate_addr = eth_validate_addr, | |
1213 | }; | |
1214 | ||
1da177e4 LT |
1215 | static void dvb_net_setup(struct net_device *dev) |
1216 | { | |
1217 | ether_setup(dev); | |
1218 | ||
3b04ddde | 1219 | dev->header_ops = &dvb_header_ops; |
fb875333 | 1220 | dev->netdev_ops = &dvb_netdev_ops; |
1da177e4 | 1221 | dev->mtu = 4096; |
3b04ddde | 1222 | |
1da177e4 LT |
1223 | dev->flags |= IFF_NOARP; |
1224 | } | |
1225 | ||
1226 | static int get_if(struct dvb_net *dvbnet) | |
1227 | { | |
1228 | int i; | |
1229 | ||
1230 | for (i=0; i<DVB_NET_DEVICES_MAX; i++) | |
1231 | if (!dvbnet->state[i]) | |
1232 | break; | |
1233 | ||
1234 | if (i == DVB_NET_DEVICES_MAX) | |
1235 | return -1; | |
1236 | ||
1237 | dvbnet->state[i]=1; | |
1238 | return i; | |
1239 | } | |
1240 | ||
1241 | static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype) | |
1242 | { | |
1243 | struct net_device *net; | |
1244 | struct dvb_net_priv *priv; | |
1245 | int result; | |
1246 | int if_num; | |
1247 | ||
1248 | if (feedtype != DVB_NET_FEEDTYPE_MPE && feedtype != DVB_NET_FEEDTYPE_ULE) | |
1249 | return -EINVAL; | |
1250 | if ((if_num = get_if(dvbnet)) < 0) | |
1251 | return -EINVAL; | |
1252 | ||
c835a677 TG |
1253 | net = alloc_netdev(sizeof(struct dvb_net_priv), "dvb", |
1254 | NET_NAME_UNKNOWN, dvb_net_setup); | |
1da177e4 LT |
1255 | if (!net) |
1256 | return -ENOMEM; | |
1257 | ||
1258 | if (dvbnet->dvbdev->id) | |
1259 | snprintf(net->name, IFNAMSIZ, "dvb%d%u%d", | |
1260 | dvbnet->dvbdev->adapter->num, dvbnet->dvbdev->id, if_num); | |
1261 | else | |
1262 | /* compatibility fix to keep dvb0_0 format */ | |
1263 | snprintf(net->name, IFNAMSIZ, "dvb%d_%d", | |
1264 | dvbnet->dvbdev->adapter->num, if_num); | |
1265 | ||
1266 | net->addr_len = 6; | |
1267 | memcpy(net->dev_addr, dvbnet->dvbdev->adapter->proposed_mac, 6); | |
1268 | ||
1269 | dvbnet->device[if_num] = net; | |
1270 | ||
0eade1f9 | 1271 | priv = netdev_priv(net); |
c4028958 | 1272 | priv->net = net; |
1da177e4 LT |
1273 | priv->demux = dvbnet->demux; |
1274 | priv->pid = pid; | |
1275 | priv->rx_mode = RX_MODE_UNI; | |
1276 | priv->need_pusi = 1; | |
1277 | priv->tscc = 0; | |
1278 | priv->feedtype = feedtype; | |
1279 | reset_ule(priv); | |
1280 | ||
c4028958 DH |
1281 | INIT_WORK(&priv->set_multicast_list_wq, wq_set_multicast_list); |
1282 | INIT_WORK(&priv->restart_net_feed_wq, wq_restart_net_feed); | |
3593cab5 | 1283 | mutex_init(&priv->mutex); |
1da177e4 LT |
1284 | |
1285 | net->base_addr = pid; | |
1286 | ||
1287 | if ((result = register_netdev(net)) < 0) { | |
1288 | dvbnet->device[if_num] = NULL; | |
1289 | free_netdev(net); | |
1290 | return result; | |
1291 | } | |
b3ad24d2 | 1292 | pr_info("created network interface %s\n", net->name); |
1da177e4 LT |
1293 | |
1294 | return if_num; | |
1295 | } | |
1296 | ||
400b7083 | 1297 | static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned long num) |
1da177e4 LT |
1298 | { |
1299 | struct net_device *net = dvbnet->device[num]; | |
1300 | struct dvb_net_priv *priv; | |
1301 | ||
1302 | if (!dvbnet->state[num]) | |
1303 | return -EINVAL; | |
0eade1f9 | 1304 | priv = netdev_priv(net); |
1da177e4 LT |
1305 | if (priv->in_use) |
1306 | return -EBUSY; | |
1307 | ||
1308 | dvb_net_stop(net); | |
43829731 TH |
1309 | flush_work(&priv->set_multicast_list_wq); |
1310 | flush_work(&priv->restart_net_feed_wq); | |
b3ad24d2 | 1311 | pr_info("removed network interface %s\n", net->name); |
1da177e4 LT |
1312 | unregister_netdev(net); |
1313 | dvbnet->state[num]=0; | |
1314 | dvbnet->device[num] = NULL; | |
1315 | free_netdev(net); | |
1316 | ||
1317 | return 0; | |
1318 | } | |
1319 | ||
16ef8def | 1320 | static int dvb_net_do_ioctl(struct file *file, |
1da177e4 LT |
1321 | unsigned int cmd, void *parg) |
1322 | { | |
0c53c70f JS |
1323 | struct dvb_device *dvbdev = file->private_data; |
1324 | struct dvb_net *dvbnet = dvbdev->priv; | |
30ad64b8 | 1325 | int ret = 0; |
1da177e4 LT |
1326 | |
1327 | if (((file->f_flags&O_ACCMODE)==O_RDONLY)) | |
1328 | return -EPERM; | |
1329 | ||
30ad64b8 NS |
1330 | if (mutex_lock_interruptible(&dvbnet->ioctl_mutex)) |
1331 | return -ERESTARTSYS; | |
1332 | ||
1da177e4 LT |
1333 | switch (cmd) { |
1334 | case NET_ADD_IF: | |
1335 | { | |
0c53c70f | 1336 | struct dvb_net_if *dvbnetif = parg; |
1da177e4 LT |
1337 | int result; |
1338 | ||
30ad64b8 NS |
1339 | if (!capable(CAP_SYS_ADMIN)) { |
1340 | ret = -EPERM; | |
1341 | goto ioctl_error; | |
1342 | } | |
1da177e4 | 1343 | |
30ad64b8 NS |
1344 | if (!try_module_get(dvbdev->adapter->module)) { |
1345 | ret = -EPERM; | |
1346 | goto ioctl_error; | |
1347 | } | |
1da177e4 LT |
1348 | |
1349 | result=dvb_net_add_if(dvbnet, dvbnetif->pid, dvbnetif->feedtype); | |
1350 | if (result<0) { | |
1351 | module_put(dvbdev->adapter->module); | |
30ad64b8 NS |
1352 | ret = result; |
1353 | goto ioctl_error; | |
1da177e4 LT |
1354 | } |
1355 | dvbnetif->if_num=result; | |
1356 | break; | |
1357 | } | |
1358 | case NET_GET_IF: | |
1359 | { | |
1360 | struct net_device *netdev; | |
1361 | struct dvb_net_priv *priv_data; | |
0c53c70f | 1362 | struct dvb_net_if *dvbnetif = parg; |
1da177e4 LT |
1363 | |
1364 | if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || | |
30ad64b8 NS |
1365 | !dvbnet->state[dvbnetif->if_num]) { |
1366 | ret = -EINVAL; | |
1367 | goto ioctl_error; | |
1368 | } | |
1da177e4 LT |
1369 | |
1370 | netdev = dvbnet->device[dvbnetif->if_num]; | |
1371 | ||
0eade1f9 | 1372 | priv_data = netdev_priv(netdev); |
1da177e4 LT |
1373 | dvbnetif->pid=priv_data->pid; |
1374 | dvbnetif->feedtype=priv_data->feedtype; | |
1375 | break; | |
1376 | } | |
1377 | case NET_REMOVE_IF: | |
1378 | { | |
30ad64b8 NS |
1379 | if (!capable(CAP_SYS_ADMIN)) { |
1380 | ret = -EPERM; | |
1381 | goto ioctl_error; | |
1382 | } | |
1383 | if ((unsigned long) parg >= DVB_NET_DEVICES_MAX) { | |
1384 | ret = -EINVAL; | |
1385 | goto ioctl_error; | |
1386 | } | |
e18828e4 | 1387 | ret = dvb_net_remove_if(dvbnet, (unsigned long) parg); |
1da177e4 LT |
1388 | if (!ret) |
1389 | module_put(dvbdev->adapter->module); | |
30ad64b8 | 1390 | break; |
1da177e4 LT |
1391 | } |
1392 | ||
06fe9fb4 | 1393 | /* binary compatibility cruft */ |
1da177e4 LT |
1394 | case __NET_ADD_IF_OLD: |
1395 | { | |
0c53c70f | 1396 | struct __dvb_net_if_old *dvbnetif = parg; |
1da177e4 LT |
1397 | int result; |
1398 | ||
30ad64b8 NS |
1399 | if (!capable(CAP_SYS_ADMIN)) { |
1400 | ret = -EPERM; | |
1401 | goto ioctl_error; | |
1402 | } | |
1da177e4 | 1403 | |
30ad64b8 NS |
1404 | if (!try_module_get(dvbdev->adapter->module)) { |
1405 | ret = -EPERM; | |
1406 | goto ioctl_error; | |
1407 | } | |
1da177e4 LT |
1408 | |
1409 | result=dvb_net_add_if(dvbnet, dvbnetif->pid, DVB_NET_FEEDTYPE_MPE); | |
1410 | if (result<0) { | |
1411 | module_put(dvbdev->adapter->module); | |
30ad64b8 NS |
1412 | ret = result; |
1413 | goto ioctl_error; | |
1da177e4 LT |
1414 | } |
1415 | dvbnetif->if_num=result; | |
1416 | break; | |
1417 | } | |
1418 | case __NET_GET_IF_OLD: | |
1419 | { | |
1420 | struct net_device *netdev; | |
1421 | struct dvb_net_priv *priv_data; | |
0c53c70f | 1422 | struct __dvb_net_if_old *dvbnetif = parg; |
1da177e4 LT |
1423 | |
1424 | if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || | |
30ad64b8 NS |
1425 | !dvbnet->state[dvbnetif->if_num]) { |
1426 | ret = -EINVAL; | |
1427 | goto ioctl_error; | |
1428 | } | |
1da177e4 LT |
1429 | |
1430 | netdev = dvbnet->device[dvbnetif->if_num]; | |
1431 | ||
0eade1f9 | 1432 | priv_data = netdev_priv(netdev); |
1da177e4 LT |
1433 | dvbnetif->pid=priv_data->pid; |
1434 | break; | |
1435 | } | |
1436 | default: | |
30ad64b8 NS |
1437 | ret = -ENOTTY; |
1438 | break; | |
1da177e4 | 1439 | } |
30ad64b8 NS |
1440 | |
1441 | ioctl_error: | |
1442 | mutex_unlock(&dvbnet->ioctl_mutex); | |
1443 | return ret; | |
1da177e4 LT |
1444 | } |
1445 | ||
16ef8def | 1446 | static long dvb_net_ioctl(struct file *file, |
1da177e4 LT |
1447 | unsigned int cmd, unsigned long arg) |
1448 | { | |
72024f1e | 1449 | return dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl); |
1da177e4 LT |
1450 | } |
1451 | ||
2c4d3364 MR |
1452 | static int dvb_net_close(struct inode *inode, struct file *file) |
1453 | { | |
1454 | struct dvb_device *dvbdev = file->private_data; | |
1455 | struct dvb_net *dvbnet = dvbdev->priv; | |
1456 | ||
82e67246 | 1457 | dvb_generic_release(inode, file); |
2c4d3364 | 1458 | |
7caf2184 | 1459 | if(dvbdev->users == 1 && dvbnet->exit == 1) |
2c4d3364 | 1460 | wake_up(&dvbdev->wait_queue); |
2c4d3364 MR |
1461 | return 0; |
1462 | } | |
1463 | ||
1464 | ||
784e29d2 | 1465 | static const struct file_operations dvb_net_fops = { |
1da177e4 | 1466 | .owner = THIS_MODULE, |
16ef8def | 1467 | .unlocked_ioctl = dvb_net_ioctl, |
1da177e4 | 1468 | .open = dvb_generic_open, |
2c4d3364 | 1469 | .release = dvb_net_close, |
6038f373 | 1470 | .llseek = noop_llseek, |
1da177e4 LT |
1471 | }; |
1472 | ||
e3d65c33 | 1473 | static const struct dvb_device dvbdev_net = { |
afd1a0c9 MCC |
1474 | .priv = NULL, |
1475 | .users = 1, | |
1476 | .writers = 1, | |
e3d65c33 | 1477 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
e4fd3bc5 | 1478 | .name = "dvb-net", |
e3d65c33 | 1479 | #endif |
afd1a0c9 | 1480 | .fops = &dvb_net_fops, |
1da177e4 LT |
1481 | }; |
1482 | ||
1da177e4 LT |
1483 | void dvb_net_release (struct dvb_net *dvbnet) |
1484 | { | |
1485 | int i; | |
1486 | ||
2c4d3364 MR |
1487 | dvbnet->exit = 1; |
1488 | if (dvbnet->dvbdev->users < 1) | |
1489 | wait_event(dvbnet->dvbdev->wait_queue, | |
1490 | dvbnet->dvbdev->users==1); | |
1491 | ||
1da177e4 LT |
1492 | dvb_unregister_device(dvbnet->dvbdev); |
1493 | ||
1494 | for (i=0; i<DVB_NET_DEVICES_MAX; i++) { | |
1495 | if (!dvbnet->state[i]) | |
1496 | continue; | |
1497 | dvb_net_remove_if(dvbnet, i); | |
1498 | } | |
1499 | } | |
1500 | EXPORT_SYMBOL(dvb_net_release); | |
1501 | ||
1502 | ||
1503 | int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet, | |
1504 | struct dmx_demux *dmx) | |
1505 | { | |
1506 | int i; | |
1507 | ||
30ad64b8 | 1508 | mutex_init(&dvbnet->ioctl_mutex); |
1da177e4 LT |
1509 | dvbnet->demux = dmx; |
1510 | ||
1511 | for (i=0; i<DVB_NET_DEVICES_MAX; i++) | |
1512 | dvbnet->state[i] = 0; | |
1513 | ||
58fae673 | 1514 | return dvb_register_device(adap, &dvbnet->dvbdev, &dvbdev_net, |
df2f94e5 | 1515 | dvbnet, DVB_DEVICE_NET, 0); |
1da177e4 LT |
1516 | } |
1517 | EXPORT_SYMBOL(dvb_net_init); |