[Solved] Tvheadend fails initialize HW CAM correctly, unless hotplugged

Added by Jon Murdock 4 months ago

Hi all,

I have a TBS5980 USB DVB-S tuner with a single CI slot, and I'm using Tvheadend to stream FTA channels - works lovely.

However, my issue is that Tvheadend (4.2.1) doesn't initiate my SmarCAM NagraVision card correctly.

The CAM can only be recognised by Tvheadend when the CAM is physically reinserted - which isn't practical. Also DVBlast can initialise the card with no need for this reinsertion procedure, so it must be software-related.

I normally see the following on a cold Tvheadend start:

May 14 14:36:26 tvheadend tvheadend[1474]: linuxdvb: adapter added /dev/dvb/adapter0
May 14 14:36:26 tvheadend kernel: [ 6967.187619] tbsqbox2ci: tbsqbox2ci_led_ctrl 16
May 14 14:36:26 tvheadend kernel: [ 6967.188032] tbsqbox2ci: tbsqbox2ci_led_ctrl 0
May 14 14:36:26 tvheadend kernel: [ 6967.225342] tbsqbox2ci: CI disabled.
May 14 14:36:26 tvheadend tvheadend[1474]: csa: Using 32bit parallel descrambling
May 14 14:36:26 tvheadend tvheadend[1474]: descrambler: adding CAID 2600 as constant crypto-word (BISS)
May 14 14:36:28 tvheadend kernel: [ 6968.685622] dvb_ca adapter 0: Invalid PC card inserted :(
May 14 14:36:29 tvheadend kernel: [ 6970.286938] tbsqbox2ci: tbsqbox2ci_led_ctrl 16

This results in "ca0: slot empty". Disabling and reenabling via the UI gives a "ca0: (module ready)".

When the CAM is hotplugged:

May 14 13:51:47 tvheadend tvheadend[1058]: linuxdvb: CAM slot 0 status changed to slot empty
May 14 13:52:03 tvheadend tvheadend[1058]: linuxdvb: CAM slot 0 status changed to module present
May 14 13:52:04 tvheadend tvheadend[1058]: linuxdvb: CAM slot 0 status changed to module ready
May 14 13:52:06 tvheadend tvheadend[1058]: en50221: CAM slot 0: Application type: 01, manufacturer: 0000, Manufacturer code: 0000
May 14 13:52:06 tvheadend tvheadend[1058]: en50221: CAM slot 0: Menu string: Tiv▒Sat
May 14 13:52:07 tvheadend tvheadend[1058]: en50221: CAM slot 0 supported CAIDs:  183D (NagraVision) 183E (NagraVision) 183F (NagraVision)

And this gives "ca0: TivuSat (module ready)".

I've tried playing with the Send CAPMT query, timeouts, etc to get this working without the need to do the reinsertion procedure, but with no success.

Any idea on how I can initialise this card correctly without resorting to a physically removing the CAM would be greatly appreciated.

Jon


Replies (5)

RE: Tvheadend fails initialize HW CAM correctly, unless hotplugged - Added by Jon Murdock 4 months ago

I've had the time to run some traces to help (I'm using the latest GIT version).

Here's what I see when I power up:

2017-05-31 18:39:52.134 [ NOTICE]:linuxdvb: CAM slot 0 status changed to module ready
2017-05-31 18:39:52.145 [  TRACE]:thread: created thread -1499467488 [tvh:lnxdvb-ca / 0x7f7f56a8(0x80fac858)]
2017-05-31 18:39:52.258 [  TRACE]:en50221: 0x00000000 session 1 tc connect

When I remove and reinsert the CAM, it gets a lot further...

2017-05-31 19:03:04.807 [ NOTICE]:linuxdvb: CAM slot 0 status changed to module ready
2017-05-31 19:03:04.809 [  TRACE]:thread: created thread -1499467488 [tvh:lnxdvb-ca / 0x7f7c46a8(0x811a5a78)]
2017-05-31 19:03:04.858 [  TRACE]:en50221: 0x00000000 session 1 tc connect
2017-05-31 19:03:05.080 [  TRACE]:en50221: 0x00010041 session 1 connecting
2017-05-31 19:03:05.081 [  TRACE]:en50221: 0x00010041 session 1 connected
2017-05-31 19:03:05.537 [  TRACE]:en50221: rm reply cb received for slot 0, count 0
2017-05-31 19:03:05.881 [  TRACE]:en50221: rm enq callback received for slot 0
2017-05-31 19:03:06.219 [  TRACE]:en50221: 0x00240041 session 2 connecting
2017-05-31 19:03:06.220 [  TRACE]:en50221: 0x00240041 session 2 connected
2017-05-31 19:03:06.440 [  TRACE]:en50221: 0x00020041 session 3 connecting
2017-05-31 19:03:06.441 [  TRACE]:en50221: 0x00020041 session 3 connected
2017-05-31 19:03:06.573 [  TRACE]:en50221: 0x00030041 session 4 connecting
2017-05-31 19:03:06.573 [  TRACE]:en50221: 0x00030041 session 4 connected
2017-05-31 19:03:07.007 [   INFO]:en50221: CAM slot 0: Application type: 01, manufacturer: 0000, Manufacturer code: 0000
2017-05-31 19:03:07.015 [   INFO]:en50221: CAM slot 0: Menu string: Tiv<F9>Sat
2017-05-31 19:03:07.356 [  TRACE]:dvbcam: unregister cam lca 0x811a5a78 slot 0
2017-05-31 19:03:07.357 [  TRACE]:dvbcam: register cam ca 0x811a5a78 slot 0 num_caids 3
2017-05-31 19:03:07.358 [   INFO]:en50221: CAM slot 0 supported CAIDs:  183D (NagraVision) 183E (NagraVision) 183F (NagraVision)

RE: Tvheadend fails initialize HW CAM correctly, unless hotplugged - Added by Jon Murdock 4 months ago

I now have this working, after hacking linuxdvb_ca.c on tvheadend 4.2.2.

In summary I did the following changes:
  • Inserted a CA_RESET and CA_GET_SLOT_INFO into linuxdvb_ca_en50221_thread(), between en50221_tl_create() and en50221_tl_register_slot(). This is what dvb-apps does - not sure if the order has any effect.
  • Inserted a usleep() until CA_GET_SLOT_INFO returns a CA_CI_MODULE_READY status. I allocated 30 seconds in 1000us increments, as per dvb-apps. My CAM takes about 5-6 seconds to initialise with other tools.
  • Modified linuxdvb_ca_monitor() to do nothing if there's a state change to CA_SLOT_STATE_MODULE_PRESENT. This gives the CAM time to move to READY.

I need to tidy up my code, as it's a bit of a kludge, but I'd thought I'd share the detail for now.

Jon

RE: [Solved] Tvheadend fails initialize HW CAM correctly, unless hotplugged - Added by jiaxi xu 2 months ago

Hi Jon,

Sometimes, tvheadend will lose the ca, and I need to re-enable it to make it works.

Can you provide the patch for me?

Thanks.

RE: [Solved] Tvheadend fails initialize HW CAM correctly, unless hotplugged - Added by Jon Murdock 2 months ago

Hey,

FYI, my tvheadend CA patch seems only to work for the initialization of the CAM, especially if the re-enable does not work.

I have seen this same "losing the CA" issue with the 4.4-4.8 kernel series on my Raspberry Pi, so please upgrade your kernel or driver sources to at least 4.11. I use the CrazyCat69 sources.

However, I will still try to upload my tvheadend patch when I get home late this evening.

Jon

RE: [Solved] Tvheadend fails initialize HW CAM correctly, unless hotplugged - Added by Jon Murdock 2 months ago

I have attached the patch that can initialize my setup correctly with tvheadend 4.2.2.

This implements the same workflow that dvb-apps uses for CAM initalization.

However it could be a issue isolated to the Raspberry Pi 1B (slow kernel timer and CPU), the TBS5980, or the SmarCAM Nagravision CAM, but either way, the patch gets it working.

Jon

tvheadend-4.2.2-tbs5980-cam-init-fix.patch Magnifier - Tvheadend CAM Initialization Workaround for TBS5980 (3.51 KB)

(1-5/5)