Add CI support to az6007 driver
PATCH 1/1 Add CI support to az6007 driver
This patch add CI support to az6007 driver.
drivers/media/dvb/dvb-usb/az6007.c +376 -1
@@ -54,6 +54,7 @@struct az6007_device_state {struct mutex mutex; +struct mutex ca_mutex;struct dvb_ca_en50221 ca;unsigned warm:1 ;int (*gate_ctrl) (struct dvb_frontend *,int );
@@ -218,6 +219,371 @@return 0 ; } +static int az6007_ci_read_attribute_mem (struct dvb_ca_en50221 *ca, +int slot, +int address) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; + +int ret; +u8 req; +u16 value; +u16 index; +int blen; +u8 *b; + +if (slot !=0 ) +return -EINVAL ; + + b =kmalloc (12 ,GFP_KERNEL ); +if (!b) +return -ENOMEM ; + +mutex_lock (&state->ca_mutex); + + req =0xC1 ; + value = address; + index =0 ; + blen =1 ; + + ret =az6007_read (d, req, value, index, b, blen); +if (ret <0 ) { +warn ("usb in operation failed. (%d)" , ret); + ret = -EINVAL ; + }else { + ret = b[0 ]; + } + +mutex_unlock (&state->ca_mutex); +kfree (b); +return ret; +} + +static int az6007_ci_write_attribute_mem (struct dvb_ca_en50221 *ca, +int slot, +int address, +u8 value) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; + +int ret; +u8 req; +u16 value1; +u16 index; +int blen; + +deb_info ("%s %d" , __func__, slot); +if (slot !=0 ) +return -EINVAL ; + +mutex_lock (&state->ca_mutex); + req =0xC2 ; + value1 = address; + index = value; + blen =0 ; + + ret =az6007_write (d, req, value1, index,NULL , blen); +if (ret !=0 ) +warn ("usb out operation failed. (%d)" , ret); + +mutex_unlock (&state->ca_mutex); +return ret; +} + +static int az6007_ci_read_cam_control (struct dvb_ca_en50221 *ca, +int slot, +u8 address) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; + +int ret; +u8 req; +u16 value; +u16 index; +int blen; +u8 *b; + +if (slot !=0 ) +return -EINVAL ; + + b =kmalloc (12 ,GFP_KERNEL ); +if (!b) +return -ENOMEM ; + +mutex_lock (&state->ca_mutex); + + req =0xC3 ; + value = address; + index =0 ; + blen =2 ; + + ret =az6007_read (d, req, value, index, b, blen); +if (ret <0 ) { +warn ("usb in operation failed. (%d)" , ret); + ret = -EINVAL ; + }else { +if (b[0 ] ==0 ) +warn ("Read CI IO error" ); + + ret = b[1 ]; +deb_info ("read cam data = %x from 0x%x" , b[1 ], value); + } + +mutex_unlock (&state->ca_mutex); +kfree (b); +return ret; +} + +static int az6007_ci_write_cam_control (struct dvb_ca_en50221 *ca, +int slot, +u8 address, +u8 value) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; + +int ret; +u8 req; +u16 value1; +u16 index; +int blen; + +if (slot !=0 ) +return -EINVAL ; + +mutex_lock (&state->ca_mutex); + req =0xC4 ; + value1 = address; + index = value; + blen =0 ; + + ret =az6007_write (d, req, value1, index,NULL , blen); +if (ret !=0 ) { +warn ("usb out operation failed. (%d)" , ret); + goto failed; + } + +failed: +mutex_unlock (&state->ca_mutex); +return ret; +} + +static int CI_CamReady (struct dvb_ca_en50221 *ca,int slot) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; + +int ret; +u8 req; +u16 value; +u16 index; +int blen; +u8 *b; + + b =kmalloc (12 ,GFP_KERNEL ); +if (!b) +return -ENOMEM ; + + req =0xC8 ; + value =0 ; + index =0 ; + blen =1 ; + + ret =az6007_read (d, req, value, index, b, blen); +if (ret <0 ) { +warn ("usb in operation failed. (%d)" , ret); + ret = -EIO ; + }else { + ret = b[0 ]; + } +kfree (b); +return ret; +} + +static int az6007_ci_slot_reset (struct dvb_ca_en50221 *ca,int slot) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; + +int ret, i; +u8 req; +u16 value; +u16 index; +int blen; + +mutex_lock (&state->ca_mutex); + + req =0xC6 ; + value =1 ; + index =0 ; + blen =0 ; + + ret =az6007_write (d, req, value, index,NULL , blen); +if (ret !=0 ) { +warn ("usb out operation failed. (%d)" , ret); + goto failed; + } + +msleep (500 ); + req =0xC6 ; + value =0 ; + index =0 ; + blen =0 ; + + ret =az6007_write (d, req, value, index,NULL , blen); +if (ret !=0 ) { +warn ("usb out operation failed. (%d)" , ret); + goto failed; + } + +for (i =0 ; i <15 ; i++) { +msleep (100 ); + +if (CI_CamReady (ca, slot)) { +deb_info ("CAM Ready" ); +break ; + } + } +msleep (5000 ); + +failed: +mutex_unlock (&state->ca_mutex); +return ret; +} + +static int az6007_ci_slot_shutdown (struct dvb_ca_en50221 *ca,int slot) +{ +return 0 ; +} + +static int az6007_ci_slot_ts_enable (struct dvb_ca_en50221 *ca,int slot) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; + +int ret; +u8 req; +u16 value; +u16 index; +int blen; + +deb_info ("%s" , __func__); +mutex_lock (&state->ca_mutex); + req =0xC7 ; + value =1 ; + index =0 ; + blen =0 ; + + ret =az6007_write (d, req, value, index,NULL , blen); +if (ret !=0 ) { +warn ("usb out operation failed. (%d)" , ret); + goto failed; + } + +failed: +mutex_unlock (&state->ca_mutex); +return ret; +} + +static int az6007_ci_poll_slot_status (struct dvb_ca_en50221 *ca,int slot,int open) +{ +struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; +int ret; +u8 req; +u16 value; +u16 index; +int blen; +u8 *b; + + b =kmalloc (12 ,GFP_KERNEL ); +if (!b) +return -ENOMEM ; +mutex_lock (&state->ca_mutex); + + req =0xC5 ; + value =0 ; + index =0 ; + blen =1 ; + + ret =az6007_read (d, req, value, index, b, blen); +if (ret <0 ) { +warn ("usb in operation failed. (%d)" , ret); + ret = -EIO ; + }else + ret =0 ; + +if (!ret && b[0 ] ==1 ) { + ret =DVB_CA_EN50221_POLL_CAM_PRESENT | +DVB_CA_EN50221_POLL_CAM_READY ; + } + +mutex_unlock (&state->ca_mutex); +kfree (b); +return ret; +} + + +static void az6007_ci_uninit (struct dvb_usb_device *d) +{ +struct az6007_device_state *state; + +deb_info ("%s" , __func__); + +if (NULL == d) +return ; + + state = (struct az6007_device_state *)d->priv; +if (NULL == state) +return ; + +if (NULL == state->ca.data) +return ; + +dvb_ca_en50221_release (&state->ca); + +memset (&state->ca,0 ,sizeof (state->ca)); +} + + +static int az6007_ci_init (struct dvb_usb_adapter *a) +{ +struct dvb_usb_device *d = a->dev; +struct az6007_device_state *state = (struct az6007_device_state *)d->priv; +int ret; + +deb_info ("%s" , __func__); + +mutex_init (&state->ca_mutex); + + state->ca.owner =THIS_MODULE ; + state->ca.read_attribute_mem = az6007_ci_read_attribute_mem; + state->ca.write_attribute_mem = az6007_ci_write_attribute_mem; + state->ca.read_cam_control = az6007_ci_read_cam_control; + state->ca.write_cam_control = az6007_ci_write_cam_control; + state->ca.slot_reset = az6007_ci_slot_reset; + state->ca.slot_shutdown = az6007_ci_slot_shutdown; + state->ca.slot_ts_enable = az6007_ci_slot_ts_enable; + state->ca.poll_slot_status = az6007_ci_poll_slot_status; + state->ca.data = d; + + ret =dvb_ca_en50221_init (&a->dvb_adap, + &state->ca, +0 ,/* flags */ +1 );/* n_slots */ +if (ret !=0 ) { +err ("Cannot initialize CI: Error %d." , ret); +memset (&state->ca,0 ,sizeof (state->ca)); +return ret; + } + +deb_info ("CI initialized." ); + +return 0 ; +} +static int az6007_read_mac_addr (struct dvb_usb_device *d,u8 mac[6 ]) {struct az6007_device_state *st = d->priv;
@@ -249,6 +615,8 @@ st->gate_ctrl = adap->fe_adap[0 ].fe->ops.i2c_gate_ctrl; adap->fe_adap[0 ].fe->ops.i2c_gate_ctrl = drxk_gate_ctrl; +az6007_ci_init (adap); +return 0 ; }
@@ -471,6 +839,13 @@static struct dvb_usb_device_properties az6007_properties; +static void az6007_usb_disconnect (struct usb_interface *intf) +{ +struct dvb_usb_device *d =usb_get_intfdata (intf); +az6007_ci_uninit (d); +dvb_usb_device_exit (intf); +} +static int az6007_usb_probe (struct usb_interface *intf,const struct usb_device_id *id) {
@@ -545,7 +922,7 @@static struct usb_driver az6007_usb_driver = { .name ="dvb_usb_az6007" , .probe = az6007_usb_probe, - .disconnect = dvb_usb_device_exit, + .disconnect = az6007_usb_disconnect, .id_table = az6007_usb_table, };
Jose Alberto Reguero skrev 2012-03-05 00:22:
Quoted 3 lines
This patch add CI support to az6007 driver.
Signed-off-by Jose Alberto Reguero<[email protected]>
Since I have this device and have access to a CAM-card and program card to access the encrypted channels(DVB-C) I thought I should try this patch and report my findings. First I have to say that I'm just a user and no developer.
After managing to include the patch in media_build I do get this in dmesg when inserting the CAM.
[ 395.561886] dvb_ca adapter 2: DVB CAM detected and initialised successfully
When scanning I can find my channels.
I can watch unencrypted channels without problem even with the CAM inserted.
When trying a encrypted channel with gnutv I get this:
$ gnutv -adapter 2 -channels my-channels-v4.conf -out file t.mpg -timeout 30 TV3 Using frontend "DRXK DVB-C DVB-T", type DVB-C status SCVYL | signal 02c7 | snr 00be | ber 00000000 | unc 00000704 | FE_HAS_LOCK en50221_tl_handle_sb: Received T_SB for connection not in T_STATE_ACTIVE from module on slot 00
en50221_stdcam_llci_poll: Error reported by stack:-7
CAM Application type: 01
CAM Application manufacturer: cafe
CAM Manufacturer code: babe
CAM Menu string: Conax Conditional Access
CAM supports the following ca system ids:
0x0b00
Received new PMT - sending to CAM...
And the resulting mpeg file is not watchable with mplayer.
Do you want me to test anything?
Quoted 36 lines · On Lunes, 5 de marzo de 2012 21:42:48 Roger Mårtensson escribió:
Jose Alberto Reguero skrev 2012-03-05 00:22:
Quoted 3 lines
This patch add CI support to az6007 driver.
Signed-off-by Jose Alberto Reguero<[email protected]>Since I have this device and have access to a CAM-card and program card to access the encrypted channels(DVB-C) I thought I should try this patch and report my findings. First I have to say that I'm just a user and no developer.
After managing to include the patch in
media_buildI do get this in dmesg when inserting the CAM.[ 395.561886] dvb_ca adapter 2: DVB CAM detected and initialisedsuccessfully
When scanning I can find my channels.
I can watch unencrypted channels without problem even with the CAM inserted.When trying a encrypted channel with gnutv I get this:
$ gnutv -adapter 2 -channels my-channels-v4.conf -out file t.mpg -timeout 30 TV3 Using frontend "DRXK DVB-C DVB-T", type DVB-C status SCVYL | signal 02c7 | snr 00be | ber 00000000 | unc 00000704 | FE_HAS_LOCK en50221_tl_handle_sb: Received T_SB for connection not in T_STATE_ACTIVE from module on slot 00
en50221_stdcam_llci_poll: Error reported by stack:-7CAM Application type: 01
CAM Application manufacturer: cafe
CAM Manufacturer code: babe
CAM Menu string: Conax Conditional Access
CAM supports the following ca system ids:
Quoted 7 lines
0x0b00Received new PMT - sending to CAM...
And the resulting mpeg file is not watchable with mplayer.
Do you want me to test anything?
--
No. I tested the patch with DVB-T an watch encrypted channels with vdr without problems. I don't know why you can't. I don't know gnutv. Try with other software if you want.
Jose Alberto
Jose Alberto Reguero skrev 2012-03-06 00:23:
Quoted 5 lines · On Lunes, 5 de marzo de 2012 21:42:48 Roger Mårtensson escribió:
No. I tested the patch with DVB-T an watch encrypted channels with vdr without problems. I don't know why you can't. I don't know gnutv. Try with other software if you want.
I have done some more testing and it works.. Sort of. :-)
First let me walk through the dmesg.
First I reinsert the CAM-card:
Mar 7 20:12:36 tvpc kernel: [ 959.717666] dvb_ca adapter 2: DVB CAM detected and initialised successfully
The next lines are when I start Kaffeine. Kaffeine gets a lock on the encrypted channel and starts viewing it.
Mar 7 20:13:02 tvpc kernel: [ 986.359195] mt2063: detected a mt2063 B3 Mar 7 20:13:03 tvpc kernel: [ 987.368964] drxk: SCU_RESULT_INVPAR while sending cmd 0x0203 with params: Mar 7 20:13:03 tvpc kernel: [ 987.368974] drxk: 02 00 00 00 10 00 05 00 03 02 .......... Mar 7 20:13:06 tvpc kernel: [ 990.286628] dvb_ca adapter 2: DVB CAM detected and initialised successfully
And now my "sort of"-comment. When I change the to another encrypted channel in kaffeine I get nothing. To be able to view this channel I need to restart kaffeine.
The only thing that seems different in the logs are that when restarting kaffeine I get the "CAM detected and initialised" but when changing channels I do not get that line.
Maybe there should be another reinit of the CAM somewhere? (just a guess)
Hello!
Sorry for the top post but this is just to check with you if you have experienced the same problem that I have. See below with some additional comments.
Roger Mårtensson skrev 2012-03-07 20:21:
Quoted 22 lines
Jose Alberto Reguero skrev 2012-03-06 00:23:
Quoted 5 lines · On Lunes, 5 de marzo de 2012 21:42:48 Roger Mårtensson escribió:
No. I tested the patch with DVB-T an watch encrypted channels with vdr without problems. I don't know why you can't. I don't know gnutv. Try with other software if you want.
I have done some more testing and it works.. Sort of. :-)
First let me walk through the dmesg.
First I reinsert the CAM-card:
Mar 7 20:12:36 tvpc kernel: [ 959.717666] dvb_ca adapter 2: DVB CAM detected and initialised successfullyThe next lines are when I start Kaffeine. Kaffeine gets a lock on the encrypted channel and starts viewing it.
Mar 7 20:13:02 tvpc kernel: [ 986.359195] mt2063: detected a mt2063 B3 Mar 7 20:13:03 tvpc kernel: [ 987.368964] drxk: SCU_RESULT_INVPAR while sending cmd 0x0203 with params: Mar 7 20:13:03 tvpc kernel: [ 987.368974] drxk: 02 00 00 00 10 00 05 00 03 02 .......... Mar 7 20:13:06 tvpc kernel: [ 990.286628] dvb_ca adapter 2: DVB CAM detected and initialised successfully
Quoted 5 lines
And now my "sort of"-comment. When I change the to another encrypted channel in kaffeine I get nothing. To be able to view this channel I need to restart kaffeine.
The only thing that seems different in the logs are that when restarting kaffeine I get the "CAM detected and initialised" but when changing channels I do not get that line.
Maybe there should be another reinit of the CAM somewhere? (just a guess)
I turned on debugging and I see when changing channels from one encrypted to another I get lots of:
"40 from 0x1read cam data = 0 from 0x1read cam data = 80 from 0x1read cam data = "
So the drivers is doing something except I don't get anything in kaffeine until I restart the application. Now and then I even have to restart kaffeine twice. Same as above.. I see it reading but nothing happens.
I seem to find some EPG data since it can tell me what programs should be shown.
Quoted 52 lines · On Miércoles, 14 de marzo de 2012 18:45:24 Roger Mårtensson escribió:
Hello!
Sorry for the top post but this is just to check with you if you have experienced the same problem that I have. See below with some additional comments.
Roger Mårtensson skrev 2012-03-07 20:21:
Quoted 33 lines
Jose Alberto Reguero skrev 2012-03-06 00:23:
Quoted 7 lines · On Lunes, 5 de marzo de 2012 21:42:48 Roger Mårtensson escribió:
No. I tested the patch with DVB-T an watch encrypted channels with vdr without
problems. I don't know why you can't. I don't know gnutv. Try with other
software if you want.I have done some more testing and it works.. Sort of. :-)
First let me walk through the dmesg.
First I reinsert the CAM-card:
Mar 7 20:12:36 tvpc kernel: [ 959.717666] dvb_ca adapter 2: DVB CAMdetected and initialised successfully
The next lines are when I start Kaffeine. Kaffeine gets a lock on the encrypted channel and starts viewing it.
Mar 7 20:13:02 tvpc kernel: [ 986.359195] mt2063: detected a mt2063 B3 Mar 7 20:13:03 tvpc kernel: [ 987.368964] drxk: SCU_RESULT_INVPAR while sending cmd 0x0203 with params: Mar 7 20:13:03 tvpc kernel: [ 987.368974] drxk: 02 00 00 00 10 00 05 00 03 02 .......... Mar 7 20:13:06 tvpc kernel: [ 990.286628] dvb_ca adapter 2: DVB CAMdetected and initialised successfully
And now my "sort of"-comment. When I change the to another encrypted channel in kaffeine I get nothing. To be able to view this channel I need to restart kaffeine.
Quoted 6 lines
The only thing that seems different in the logs are that when restarting kaffeine I get the "CAM detected and initialised" but when changing channels I do not get that line.
Maybe there should be another reinit of the CAM somewhere? (just a guess)
I turned on debugging and I see when changing channels from one encrypted to another I get lots of:
"40 from 0x1read cam data = 0 from 0x1read cam data = 80 from 0x1read cam data = "
Quoted 7 lines
So the drivers is doing something except I don't get anything in kaffeine until I restart the application.
Now and then I even have to restart kaffeine twice. Same as above.. I see it reading but nothing happens.I seem to find some EPG data since it can tell me what programs should be shown.
No, I don't have this problem. The only problem I have is when the reception is not very good, the cam don't work.
Perhaps is a kaffeine problem, or a cam specific problem.
Jose Alberto
Jose Alberto Reguero skrev 2012-03-15 13:29:
Quoted 6 lines · On Miércoles, 14 de marzo de 2012 18:45:24 Roger Mårtensson escribió:
Quoted 5 lines
So the drivers is doing something except I don't get anything in kaffeine until I restart the application.
Now and then I even have to restart kaffeine twice. Same as above.. I see it reading but nothing happens.
Quoted 6 lines
Quoted 2 lines
I seem to find some EPG data since it can tell me what programs should be shown.
No, I don't have this problem. The only problem I have is when the reception is not very good, the cam don't work.
Perhaps is a kaffeine problem, or a cam specific problem.
Bummer... :)
I'll see if I can find another DVB-application to test. My CAM is a SMIT CONAX cam and it is proven to work and many have had success. I have another CAM I could test but earlier test in another DVB-C card didn't work.
Thanks for your work. Hopefully your patch will be included soon. :)
Other than my "problem" everything works as expected.