Skip to contentSkip to conversation

DVB : add option to dump PDU exchanged with CAM in dvb_core

PATCH In review Sébastien RAILLARD (COEXSI) 1 participant 2 messages Feb 28, 2011 – Mar 3, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DVB : add option to dump PDU exchanged with CAM in dvb_core

Dear all,

Here is a patch for the dvb_core module, you'll find it attached to this message.

It's adding a new module integer parameter called "cam_dump_pdu" that can have the following values:
- 0 (by default): don't dump PDU (do nothing)
- 1: Dump all PDU written and read on device through the syscall functions. The PDU are dumped in segments of 16 bytes maximum written in hexadecimal.
- 2: like value 1 but remove the commonly used PDU for polling (generating a lot of "noise" in the logs)

The goal of dumping PDU exchanged with CAM is to help debugging userland applications and libraries.

This is my first patch submission, so I may have made some errors regarding the submission rules.

Best regards,
Sebastien.

linux/drivers/media/dvb/dvb-core/dvb_ca_en50221.c +56 -0
@@ -43,10 +43,14 @@
 #include "dvb_ringbuffer.h"
 
 static int dvb_ca_en50221_debug;
+static int dvb_ca_en50221_dump_pdu;
 
 module_param_named(cam_debug, dvb_ca_en50221_debug, int, 0644);
 MODULE_PARM_DESC(cam_debug, "enable verbose debug messages");
 
+module_param_named(cam_dump_pdu, dvb_ca_en50221_dump_pdu, int, 0644);
+MODULE_PARM_DESC(cam_dump_pdu, "1 = enable dumping of all PDU; 2 = filter out commonly used PDU for polling");
+
 #define dprintk if (dvb_ca_en50221_debug) printk
 
 #define INIT_TIMEOUT_SECS 10
@@ -1346,6 +1350,32 @@ static ssize_t dvb_ca_en50221_io_write(s
 	status = count + 2;
 
 exit:
+
+	// Check if the dump PDU option is enabled
+	if (dvb_ca_en50221_dump_pdu>0) {
+		 if (status<2) {
+			printk(KERN_INFO "dvb%d.ca%d PDU_write: ERROR, status=%d\n", ca->dvbdev->adapter->num, ca->dvbdev->id, status);
+		} else {
+			// Check if we need to filter the [A00101] PDU used for polling (empty T_data_last transport tag for for t_c_id=1)
+			if (!(dvb_ca_en50221_dump_pdu==2 && (status-2)==3 && (unsigned char)(buf[0])==0xa0 && (unsigned char)(buf[1])==0x01 && (unsigned char)(buf[2])==0x01)) {
+				char dumped_string[33];
+				int total_bytes, segment, dumped_bytes, to_be_written, i;
+				total_bytes=status-2;
+				segment=0;
+				dumped_bytes=0;
+				while (dumped_bytes<total_bytes) {
+					to_be_written=((total_bytes-dumped_bytes)<16)?(total_bytes-dumped_bytes):16;
+					for (i=0;i<to_be_written;i++) 
+						sprintf(dumped_string+i*2,"%02X",(unsigned char)(buf[dumped_bytes+i]));
+					dumped_string[to_be_written*2]=0;
+					printk(KERN_INFO "dvb%d.ca%d PDU_write: length=%03d, segment=%02d, dump=[%s]\n", ca->dvbdev->adapter->num, ca->dvbdev->id, total_bytes, segment, dumped_string);
+					segment++;
+					dumped_bytes+=to_be_written;
+				}
+			}
+		}
+	}
+
 	return status;
 }
 
@@ -1493,6 +1523,32 @@ static ssize_t dvb_ca_en50221_io_read(st
 	status = pktlen;
 
 exit:
+
+	// Check if the dump PDU option is enabled
+	if (dvb_ca_en50221_dump_pdu>0) {
+		 if (status<2) {
+			printk(KERN_INFO "dvb%d.ca%d PDU_read:  ERROR, status=%d\n", ca->dvbdev->adapter->num, ca->dvbdev->id, status);
+		} else {
+			// Check if we need to filter the [80020100] PDU used for polling (T_SB transport tag for t_c_id=1 saying no data avaliable)
+			if (!(dvb_ca_en50221_dump_pdu==2 && (status-2)==4 && (unsigned char)(buf[0+2])==0x80 && (unsigned char)(buf[1+2])==0x02 && (unsigned char)(buf[2+2])==0x01 && (unsigned char)(buf[3+2])==0x00)) {
+				char dumped_string[33];
+				int total_bytes, segment, dumped_bytes, to_be_written, i;
+				total_bytes=status-2;
+				segment=0;
+				dumped_bytes=0;
+				while (dumped_bytes<total_bytes) {
+					to_be_written=((total_bytes-dumped_bytes)<16)?(total_bytes-dumped_bytes):16;
+					for (i=0;i<to_be_written;i++) 
+						sprintf(dumped_string+i*2,"%02X",(unsigned char)(buf[dumped_bytes+i+2]));
+					dumped_string[to_be_written*2]=0;
+					printk(KERN_INFO "dvb%d.ca%d PDU_read:  length=%03d, segment=%02d, dump=[%s]\n", ca->dvbdev->adapter->num, ca->dvbdev->id, total_bytes, segment, dumped_string);
+					segment++;
+					dumped_bytes+=to_be_written;
+				}
+			}
+		}
+	}
+
 	return status;
 }
 
#1 lore raw
Quoted 24 lines

-----Original Message-----
From: [email protected] [mailto:linux-media- [email protected]] On Behalf Of Sébastien RAILLARD (COEXSI)
Sent: lundi 28 février 2011 18:53
To: Linux Media Mailing List
Subject: [PATCH] DVB : add option to dump PDU exchanged with CAM in dvb_core

Dear all,

Here is a patch for the dvb_core module, you'll find it attached to this message.

It's adding a new module integer parameter called "cam_dump_pdu" that can have the following values:
- 0 (by default): don't dump PDU (do nothing)
- 1: Dump all PDU written and read on device through the syscall functions.
The PDU are dumped in segments of 16 bytes maximum written in hexadecimal.
- 2: like value 1 but remove the commonly used PDU for polling (generating a lot of "noise" in the logs)

Quoted 2 lines

The goal of dumping PDU exchanged with CAM is to help debugging userland applications and libraries.

I have to add that the PDU dumped are the "TPDU" (Transport Protocol Data Units), the 2nd level of the stack.
The first level of PDU, the "LPDU" (Link Protocol Data Unit) fragments, are reassembled by the dvb_core module and are not exposed to the applications.

Anyone interested by this option?

Quoted 6 lines

This is my first patch submission, so I may have made some errors regarding the submission rules.

Best regards,
Sebastien.