Skip to contentSkip to conversation

firedtv: correct version number and current/next in CA_PMT

PATCH New Stefan Richter 2 participants 9 messages Mar 1, 2010 – Mar 6, 2010 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firedtv: correct version number and current/next in CA_PMT

Date: Tue, 21 Jul 2009 18:45:50 +0200
From: Henrik Kurelid <[email protected]>

The version number in the CA_PMT message sent to the hardware was alwaysed set to zero. This could cause problems if the PMT would change during decryption of a channel since the new CA_PMT would have the same version number as the old. The version number is now copied from the original PMT.

---

This patch got stuck somehow on the long way upstream. :-) Would be good to get into one of the next .34-rc releases.

 drivers/media/dvb/firewire/firedtv-avc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb/firewire/firedtv-avc.c +1 -1
Index: b/drivers/media/dvb/firewire/firedtv-avc.c
===================================================================
@@ -1096,7 +1096,7 @@ int avc_ca_pmt(struct firedtv *fdtv, cha
 
 	c->operand[15] = msg[1]; /* Program number */
 	c->operand[16] = msg[2];
-	c->operand[17] = 0x01; /* Version number=0 + current/next=1 */
+	c->operand[17] = msg[3]; /* Version number and current/next */
 	c->operand[18] = 0x00; /* Section number=0 */
 	c->operand[19] = 0x00; /* Last section number=0 */
 	c->operand[20] = 0x1f; /* PCR_PID=1FFF */
Signature · 3 lines
Stefan Richter
-=====-==-=- --== ----=
http://arcgraph.de/sr/
#1 lore raw

PATCH 1/1 firedtv: add parameter to fake ca_system_ids in CA_INFO

Date: Sun, 4 Oct 2009 15:00:36 +0200
From: Henrik Kurelid <[email protected]>

The Digital Everywhere firmware have the shortcoming that ca_info_enq and ca_info are not supported. This means that we can never retrieve the correct ca_system_id to present in the CI message CA_INFO. Currently the driver uses the application id retrieved using app_info_req and app_info, but this id only match the correct ca_system_id as given in ca_info in some cases. This patch adds a parameter to the driver in order for the user to override what will be returned in the CA_INFO CI message. Up to four ca_system_ids can be specified.
This is needed for users with CAMs that have different manufacturer id and ca_system_id and that uses applications that take this into account, like MythTV.

---

Would be good to get into an .34-rc too.

 drivers/media/dvb/firewire/firedtv-avc.c |   31 ++++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/media/dvb/firewire/firedtv-avc.c +27 -4
Index: b/drivers/media/dvb/firewire/firedtv-avc.c
===================================================================
@@ -130,6 +130,20 @@ MODULE_PARM_DESC(debug, "Verbose logging
 	", FCP payloads = "		__stringify(AVC_DEBUG_FCP_PAYLOADS)
 	", or a combination, or all = -1)");
 
+/*
+ * This is a workaround since there is no vendor specific command to retrieve
+ * ca_info using AVC. If this parameter is not used, ca_system_id will be
+ * filled with application_manufacturer from ca_app_info.
+ * Digital Everywhere have said that adding ca_info is on their TODO list.
+ */
+static int num_fake_ca_system_ids;
+static int fake_ca_system_ids[4] = { -1, -1, -1, -1 };
+module_param_array(fake_ca_system_ids, int, &num_fake_ca_system_ids, 0644);
+MODULE_PARM_DESC(fake_ca_system_ids, "If your CAM application manufacturer "
+		 "does not have the same ca_system_id as your CAS, you can "
+		 "override what ca_system_ids are presented to the "
+		 "application by setting this field to an array of ids.");
+
 static const char *debug_fcp_ctype(unsigned int ctype)
 {
 	static const char *ctypes[] = {
@@ -977,7 +991,7 @@ int avc_ca_info(struct firedtv *fdtv, ch
 {
 	struct avc_command_frame *c = (void *)fdtv->avc_data;
 	struct avc_response_frame *r = (void *)fdtv->avc_data;
-	int pos, ret;
+	int i, pos, ret;
 
 	mutex_lock(&fdtv->avc_mutex);
 
@@ -1004,9 +1018,18 @@ int avc_ca_info(struct firedtv *fdtv, ch
 	app_info[0] = (EN50221_TAG_CA_INFO >> 16) & 0xff;
 	app_info[1] = (EN50221_TAG_CA_INFO >>  8) & 0xff;
 	app_info[2] = (EN50221_TAG_CA_INFO >>  0) & 0xff;
-	app_info[3] = 2;
-	app_info[4] = r->operand[pos + 0];
-	app_info[5] = r->operand[pos + 1];
+	if (num_fake_ca_system_ids == 0) {
+		app_info[3] = 2;
+		app_info[4] = r->operand[pos + 0];
+		app_info[5] = r->operand[pos + 1];
+	} else {
+		app_info[3] = num_fake_ca_system_ids * 2;
+		for (i = 0; i < num_fake_ca_system_ids; i++) {
+			app_info[4 + i * 2] =
+				(fake_ca_system_ids[i] >> 8) & 0xff;
+			app_info[5 + i * 2] = fake_ca_system_ids[i] & 0xff;
+		}
+	}
 	*len = app_info[3] + 4;
 out:
 	mutex_unlock(&fdtv->avc_mutex);
Signature · 3 lines
Stefan Richter
-=====-==-=- --== ----=
http://arcgraph.de/sr/
#2 lore raw

Re: [PATCH] firedtv: add parameter to fake ca_system_ids in CA_INFO

Quoted 11 lines

The Digital Everywhere firmware have the shortcoming that ca_info_enq and ca_info are not supported. This means that we can never retrieve the correct ca_system_id to present in the CI message CA_INFO. Currently the driver uses the application id retrieved using app_info_req and app_info, but this id only match the correct ca_system_id as given in ca_info in some cases. This patch adds a parameter to the driver in order for the user to override what will be returned in the CA_INFO CI message. Up to four ca_system_ids can be specified.
This is needed for users with CAMs that have different manufacturer id and ca_system_id and that uses applications that take this into account, like MythTV.

This workaround is of course rather awkward. Users who need this will have a hard time to work out that this parameter needs to be set and how. Furthermore, the web site of Digital Everywhere says that hey stopped manufacturing and ramped down support, hence it looks like this issue will stay with us forever.

Isn't there a CA command that could be (mis)used for some kind of probing of the CAM for correct system IDs? E.g. a loop which retries a kind of dummy operation with different system IDs until success, initially during fdtv_dvb_register/ fdtv_ca_register?

(I don't know how CI works, and alas I don't have a CAM myself for testing and am not very keen on getting one...)

Signature · 3 lines
Stefan Richter
-=====-==-=- --== ----=
http://arcgraph.de/sr/
#3 lore raw

PATCH 1/1 firedtv: add parameter to fake ca_system_ids in CA_INFO

In reply to Stefan Richter

From: Henrik Kurelid <[email protected]>
Subject: firedtv: add parameter to fake ca_system_ids in CA_INFO

The Digital Everywhere firmware have the shortcoming that ca_info_enq and ca_info are not supported. This means that we can never retrieve the correct ca_system_id to present in the CI message CA_INFO. Currently the driver uses the application id retrieved using app_info_req and app_info, but this id only match the correct ca_system_id as given in ca_info in some cases. This patch adds a parameter to the driver in order for the user to override what will be returned in the CA_INFO CI message. Up to four ca_system_ids can be specified.
This is needed for users with CAMs that have different manufacturer id and ca_system_id and that uses applications that take this into account, like MythTV.

---

Update: I found a sparse warning after the fact. num_fake_ca_system_ids is meant to be unsigned, not signed. Sorry that I missed it in my first posting; it was hidden by an unrelated sparse error in include/linux/skbuff.h which was introduced by commit 14d18a81. I need to have a word (again) with the author of this commit.

 drivers/media/dvb/firewire/firedtv-avc.c |   31 ++++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/media/dvb/firewire/firedtv-avc.c +27 -4
Index: b/drivers/media/dvb/firewire/firedtv-avc.c
===================================================================
@@ -130,6 +130,20 @@ MODULE_PARM_DESC(debug, "Verbose logging
 	", FCP payloads = "		__stringify(AVC_DEBUG_FCP_PAYLOADS)
 	", or a combination, or all = -1)");
 
+/*
+ * This is a workaround since there is no vendor specific command to retrieve
+ * ca_info using AVC. If this parameter is not used, ca_system_id will be
+ * filled with application_manufacturer from ca_app_info.
+ * Digital Everywhere have said that adding ca_info is on their TODO list.
+ */
+static unsigned int num_fake_ca_system_ids;
+static int fake_ca_system_ids[4] = { -1, -1, -1, -1 };
+module_param_array(fake_ca_system_ids, int, &num_fake_ca_system_ids, 0644);
+MODULE_PARM_DESC(fake_ca_system_ids, "If your CAM application manufacturer "
+		 "does not have the same ca_system_id as your CAS, you can "
+		 "override what ca_system_ids are presented to the "
+		 "application by setting this field to an array of ids.");
+
 static const char *debug_fcp_ctype(unsigned int ctype)
 {
 	static const char *ctypes[] = {
@@ -977,7 +991,7 @@ int avc_ca_info(struct firedtv *fdtv, ch
 {
 	struct avc_command_frame *c = (void *)fdtv->avc_data;
 	struct avc_response_frame *r = (void *)fdtv->avc_data;
-	int pos, ret;
+	int i, pos, ret;
 
 	mutex_lock(&fdtv->avc_mutex);
 
@@ -1004,9 +1018,18 @@ int avc_ca_info(struct firedtv *fdtv, ch
 	app_info[0] = (EN50221_TAG_CA_INFO >> 16) & 0xff;
 	app_info[1] = (EN50221_TAG_CA_INFO >>  8) & 0xff;
 	app_info[2] = (EN50221_TAG_CA_INFO >>  0) & 0xff;
-	app_info[3] = 2;
-	app_info[4] = r->operand[pos + 0];
-	app_info[5] = r->operand[pos + 1];
+	if (num_fake_ca_system_ids == 0) {
+		app_info[3] = 2;
+		app_info[4] = r->operand[pos + 0];
+		app_info[5] = r->operand[pos + 1];
+	} else {
+		app_info[3] = num_fake_ca_system_ids * 2;
+		for (i = 0; i < num_fake_ca_system_ids; i++) {
+			app_info[4 + i * 2] =
+				(fake_ca_system_ids[i] >> 8) & 0xff;
+			app_info[5 + i * 2] = fake_ca_system_ids[i] & 0xff;
+		}
+	}
 	*len = app_info[3] + 4;
 out:
 	mutex_unlock(&fdtv->avc_mutex);
Signature · 3 lines
Stefan Richter
-=====-==-=- --== ----=
http://arcgraph.de/sr/
#4 lore raw

Re: [PATCH] firedtv: add parameter to fake ca_system_ids in CA_INFO

In reply to Stefan Richter
Quoted 11 lines · Stefan Richter

The Digital Everywhere firmware have the shortcoming that ca_info_enq and ca_info are not supported. This means that we can never retrieve the correct ca_system_id to present in the CI message CA_INFO. Currently the driver uses the application id retrieved using app_info_req and app_info, but this id only match the correct ca_system_id as given in ca_info in some cases. This patch adds a parameter to the driver in order for the user to override what will be returned in the CA_INFO CI message. Up to four ca_system_ids can be specified.
This is needed for users with CAMs that have different manufacturer id and ca_system_id and that uses applications that take this into account, like MythTV.

This seems an ugly workaround. The better seems to patch MythTV to accept a different CAM.

Quoted 1 line

+static int num_fake_ca_system_ids;

...

drivers/media/dvb/firewire/firedtv-avc.c int avc_ca_info(struct firedtv *fdtv, ch · line 1029

Quoted 3 lines
drivers/media/dvb/firewire/firedtv-avc.c +3 -0
+		for (i = 0; i < num_fake_ca_system_ids; i++) {
+			app_info[4 + i * 2] =
+				(fake_ca_system_ids[i] >> 8) & 0xff;

...

NAK. If someone put an arbitrary high value for num_fake_ca_system_id's, it will write outside the app_info array space, as the num_fake_ca_system_ids is not validated against the size of app_info. Also, it makes no sense a negative value for this parameter.

Signature · 2 lines
Cheers,
Mauro
#5 lore raw

Re: [PATCH] firedtv: add parameter to fake ca_system_ids in CA_INFO

Quoted 14 lines · Mauro Carvalho Chehab
Quoted 11 lines · Stefan Richter

The Digital Everywhere firmware have the shortcoming that ca_info_enq and ca_info are not supported. This means that we can never retrieve the correct ca_system_id to present in the CI message CA_INFO. Currently the driver uses the application id retrieved using app_info_req and app_info, but this id only match the correct ca_system_id as given in ca_info in some cases. This patch adds a parameter to the driver in order for the user to override what will be returned in the CA_INFO CI message. Up to four ca_system_ids can be specified.
This is needed for users with CAMs that have different manufacturer id and ca_system_id and that uses applications that take this into account, like MythTV.

Quoted 2 lines

This seems an ugly workaround. The better seems to patch MythTV to accept a different CAM.

Ugly it is, for sure. Can't comment on application-level solutions; if thats the proper layer at which to address this, then that would be preferable of course.

Quoted 10 lines
Quoted 1 line

+static int num_fake_ca_system_ids;

...

drivers/media/dvb/firewire/firedtv-avc.c int avc_ca_info(struct firedtv *fdtv, ch · line 1029

Quoted 3 lines
drivers/media/dvb/firewire/firedtv-avc.c +3 -0
+		for (i = 0; i < num_fake_ca_system_ids; i++) {
+			app_info[4 + i * 2] =
+				(fake_ca_system_ids[i] >> 8) & 0xff;

...

NAK. If someone put an arbitrary high value for num_fake_ca_system_id's, it will write outside the app_info array space, as the num_fake_ca_system_ids is not validated against the size of app_info.

That's what I thought at first look at the patch too, but then I noticed that inlcude/linux/moduleparam.h and kernel/params.c properly track kparam_arry.max = ARRAY_SIZE(array).
http://lxr.linux.no/#linux+v2.6.33/include/linux/moduleparam.h#L62
http://lxr.linux.no/#linux+v2.6.33/include/linux/moduleparam.h#L213
http://lxr.linux.no/#linux+v2.6.33/kernel/params.c#L351
http://lxr.linux.no/#linux+v2.6.33/kernel/params.c#L296

So no danger here.

Quoted 1 line

Also, it makes no sense a negative value for this parameter.

I already posted an updated version of the patch which correctly defines num_fake_ca_system_ids as an unsigned long.

Signature · 3 lines
Stefan Richter
-=====-==-=- --== --==-
http://arcgraph.de/sr/
#6 lore raw

Re: [PATCH] firedtv: add parameter to fake ca_system_ids in CA_INFO

Quoted 2 lines · Stefan Richter

I already posted an updated version of the patch which correctly defines num_fake_ca_system_ids as an unsigned long.

err, unsigned int of course, as http://patchwork.kernel.org/patch/82912/.

Signature · 3 lines
Stefan Richter
-=====-==-=- --== --==-
http://arcgraph.de/sr/
#7 lore raw

Re: [PATCH] firedtv: add parameter to fake ca_system_ids in CA_INFO

Quoted 5 lines · Stefan Richter
Quoted 2 lines · Stefan Richter

I already posted an updated version of the patch which correctly defines num_fake_ca_system_ids as an unsigned long.

err, unsigned int of course, as http://patchwork.kernel.org/patch/82912/.

Ah, ok. This is one of the things that Patchwork doesn't handle nice: it doesn't show any hint that a patch might be superseded by a newer one.

Signature · 2 lines
Cheers,
Mauro
#8 lore raw

Re: [PATCH] firedtv: add parameter to fake ca_system_ids in CA_INFO

In reply to Stefan Richter
Quoted 14 lines · Stefan Richter
Quoted 13 lines · Mauro Carvalho Chehab
Quoted 11 lines · Stefan Richter

The Digital Everywhere firmware have the shortcoming that ca_info_enq and ca_info are not supported. This means that we can never retrieve the correct ca_system_id to present in the CI message CA_INFO. Currently the driver uses the application id retrieved using app_info_req and app_info, but this id only match the correct ca_system_id as given in ca_info in some cases. This patch adds a parameter to the driver in order for the user to override what will be returned in the CA_INFO CI message. Up to four ca_system_ids can be specified.
This is needed for users with CAMs that have different manufacturer id and ca_system_id and that uses applications that take this into account, like MythTV.

Quoted 8 lines
Quoted 2 lines

This seems an ugly workaround. The better seems to patch MythTV to accept a different CAM.

Ugly it is, for sure. Can't comment on application-level solutions; if thats the proper layer at which to address this, then that would be preferable of course.

From the report, this seems to be a requirement at application level. So, the fix should

be there.

Henrik, is there any reason why not patching MythTV?

Quoted 20 lines
Quoted 11 lines
Quoted 2 lines

+static int num_fake_ca_system_ids;

...

drivers/media/dvb/firewire/firedtv-avc.c int avc_ca_info(struct firedtv *fdtv, ch · line 1029

Quoted 3 lines
drivers/media/dvb/firewire/firedtv-avc.c +3 -0
+		for (i = 0; i < num_fake_ca_system_ids; i++) {
+			app_info[4 + i * 2] =
+				(fake_ca_system_ids[i] >> 8) & 0xff;

...

NAK. If someone put an arbitrary high value for num_fake_ca_system_id's, it will write outside the app_info array space, as the num_fake_ca_system_ids is not validated against the size of app_info.

That's what I thought at first look at the patch too, but then I noticed that inlcude/linux/moduleparam.h and kernel/params.c properly track kparam_arry.max = ARRAY_SIZE(array).
http://lxr.linux.no/#linux+v2.6.33/include/linux/moduleparam.h#L62
http://lxr.linux.no/#linux+v2.6.33/include/linux/moduleparam.h#L213
http://lxr.linux.no/#linux+v2.6.33/kernel/params.c#L351
http://lxr.linux.no/#linux+v2.6.33/kernel/params.c#L296

Quoted 6 lines

So no danger here.

Quoted 1 line

Also, it makes no sense a negative value for this parameter.

I already posted an updated version of the patch which correctly defines num_fake_ca_system_ids as an unsigned long.

Ok. As app_info is char [256] (from ca_info::msg field), and kernel module avoids the size of the array to be bigger than 4 (the sizeof the array), that's should be ok.

Signature · 2 lines
Cheers,
Mauro