2 CA-driver for TwinHan DST Frontend/Card
4 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/string.h>
25 #include <linux/dvb/ca.h>
27 #include "dvb_frontend.h"
29 #include "dst_common.h"
31 #define DST_CA_ERROR 0
32 #define DST_CA_NOTICE 1
34 #define DST_CA_DEBUG 3
36 #define dprintk(x, y, z, format, arg...) do { \
38 if ((x > DST_CA_ERROR) && (x > y)) \
39 printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \
40 else if ((x > DST_CA_NOTICE) && (x > y)) \
41 printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \
42 else if ((x > DST_CA_INFO) && (x > y)) \
43 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \
44 else if ((x > DST_CA_DEBUG) && (x > y)) \
45 printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \
48 printk(format, ## arg); \
53 static unsigned int verbose = 5;
54 module_param(verbose, int, 0644);
55 MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
57 /* Need some more work */
58 static int ca_set_slot_descr(void)
60 /* We could make this more graceful ? */
64 /* Need some more work */
65 static int ca_set_pid(void)
67 /* We could make this more graceful ? */
71 static void put_command_and_length(u8 *data, int command, int length)
73 data[0] = (command >> 16) & 0xff;
74 data[1] = (command >> 8) & 0xff;
75 data[2] = command & 0xff;
79 static void put_checksum(u8 *check_string, int length)
81 dprintk(verbose, DST_CA_DEBUG, 1, " Computing string checksum.");
82 dprintk(verbose, DST_CA_DEBUG, 1, " -> string length : 0x%02x", length);
83 check_string[length] = dst_check_sum (check_string, length);
84 dprintk(verbose, DST_CA_DEBUG, 1, " -> checksum : 0x%02x", check_string[length]);
87 static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8 len, int read)
91 mutex_lock(&state->dst_mutex);
95 if (write_dst(state, data, len)) {
96 dprintk(verbose, DST_CA_INFO, 1, " Write not successful, trying to recover");
97 dst_error_recovery(state);
100 if ((dst_pio_disable(state)) < 0) {
101 dprintk(verbose, DST_CA_ERROR, 1, " DST PIO disable failed.");
104 if (read_dst(state, &reply, GET_ACK) < 0) {
105 dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
106 dst_error_recovery(state);
110 if (! dst_wait_dst_ready(state, LONG_DELAY)) {
111 dprintk(verbose, DST_CA_NOTICE, 1, " 8820 not ready");
114 if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */
115 dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
116 dst_error_recovery(state);
120 mutex_unlock(&state->dst_mutex);
124 mutex_unlock(&state->dst_mutex);
129 static int dst_put_ci(struct dst_state *state, u8 *data, int len, u8 *ca_string, int read)
131 u8 dst_ca_comm_err = 0;
133 while (dst_ca_comm_err < RETRIES) {
134 dprintk(verbose, DST_CA_NOTICE, 1, " Put Command");
135 if (dst_ci_command(state, data, ca_string, len, read)) { // If error
136 dst_error_recovery(state);
137 dst_ca_comm_err++; // work required here.
143 if(dst_ca_comm_err == RETRIES)
151 static int ca_get_app_info(struct dst_state *state)
153 int length, str_length;
154 static u8 command[8] = {0x07, 0x40, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff};
156 put_checksum(&command[0], command[0]);
157 if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) {
158 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
161 dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
162 dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================");
163 dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]",
164 state->messages[7], (state->messages[8] << 8) | state->messages[9],
165 (state->messages[10] << 8) | state->messages[11], __FUNCTION__, (char *)(&state->messages[12]));
166 dprintk(verbose, DST_CA_INFO, 1, " ==================================================================================================");
168 // Transform dst message to correct application_info message
169 length = state->messages[5];
170 str_length = length - 6;
171 if (str_length < 0) {
173 dprintk(verbose, DST_CA_ERROR, 1, "Invalid string length returned in ca_get_app_info(). Recovering.");
176 // First, the command and length fields
177 put_command_and_length(&state->messages[0], CA_APP_INFO, length);
179 // Copy application_type, application_manufacturer and manufacturer_code
180 memcpy(&state->messages[4], &state->messages[7], 5);
182 // Set string length and copy string
183 state->messages[9] = str_length;
184 memcpy(&state->messages[10], &state->messages[12], str_length);
189 static int ca_get_ca_info(struct dst_state *state)
191 int srcPtr, dstPtr, i, num_ids;
192 static u8 slot_command[8] = {0x07, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0xff};
193 const int in_system_id_pos = 8, out_system_id_pos = 4, in_num_ids_pos = 7;
195 put_checksum(&slot_command[0], slot_command[0]);
196 if ((dst_put_ci(state, slot_command, sizeof (slot_command), state->messages, GET_REPLY)) < 0) {
197 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
200 dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
203 dprintk(verbose, DST_CA_INFO, 0, " DST data = [");
204 for (i = 0; i < state->messages[0] + 1; i++) {
205 dprintk(verbose, DST_CA_INFO, 0, " 0x%02x", state->messages[i]);
207 dprintk(verbose, DST_CA_INFO, 0, "]\n");
209 // Set the command and length of the output
210 num_ids = state->messages[in_num_ids_pos];
211 if (num_ids >= 100) {
213 dprintk(verbose, DST_CA_ERROR, 1, "Invalid number of ids (>100). Recovering.");
215 put_command_and_length(&state->messages[0], CA_INFO, num_ids * 2);
217 dprintk(verbose, DST_CA_INFO, 0, " CA_INFO = [");
218 srcPtr = in_system_id_pos;
219 dstPtr = out_system_id_pos;
220 for(i = 0; i < num_ids; i++) {
221 dprintk(verbose, DST_CA_INFO, 0, " 0x%02x%02x", state->messages[srcPtr + 0], state->messages[srcPtr + 1]);
223 state->messages[dstPtr + 0] = state->messages[srcPtr + 0];
224 state->messages[dstPtr + 1] = state->messages[srcPtr + 1];
228 dprintk(verbose, DST_CA_INFO, 0, "]\n");
233 static int ca_get_slot_caps(struct dst_state *state, struct ca_caps *p_ca_caps, void __user *arg)
237 static u8 slot_command[8] = {0x07, 0x40, 0x02, 0x00, 0x02, 0x00, 0x00, 0xff};
239 put_checksum(&slot_command[0], slot_command[0]);
240 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) {
241 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
244 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
246 /* Will implement the rest soon */
248 dprintk(verbose, DST_CA_INFO, 1, " Slot cap = [%d]", slot_cap[7]);
249 dprintk(verbose, DST_CA_INFO, 0, "===================================\n");
250 for (i = 0; i < slot_cap[0] + 1; i++)
251 dprintk(verbose, DST_CA_INFO, 0, " %d", slot_cap[i]);
252 dprintk(verbose, DST_CA_INFO, 0, "\n");
254 p_ca_caps->slot_num = 1;
255 p_ca_caps->slot_type = 1;
256 p_ca_caps->descr_num = slot_cap[7];
257 p_ca_caps->descr_type = 1;
259 if (copy_to_user(arg, p_ca_caps, sizeof (struct ca_caps)))
265 /* Need some more work */
266 static int ca_get_slot_descr(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
272 static int ca_get_slot_info(struct dst_state *state, struct ca_slot_info *p_ca_slot_info, void __user *arg)
275 static u8 slot_command[8] = {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
277 u8 *slot_info = state->messages;
279 put_checksum(&slot_command[0], 7);
280 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) {
281 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
284 dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
286 /* Will implement the rest soon */
288 dprintk(verbose, DST_CA_INFO, 1, " Slot info = [%d]", slot_info[3]);
289 dprintk(verbose, DST_CA_INFO, 0, "===================================\n");
290 for (i = 0; i < 8; i++)
291 dprintk(verbose, DST_CA_INFO, 0, " %d", slot_info[i]);
292 dprintk(verbose, DST_CA_INFO, 0, "\n");
294 if (slot_info[4] & 0x80) {
295 p_ca_slot_info->flags = CA_CI_MODULE_PRESENT;
296 p_ca_slot_info->num = 1;
297 p_ca_slot_info->type = CA_CI;
298 } else if (slot_info[4] & 0x40) {
299 p_ca_slot_info->flags = CA_CI_MODULE_READY;
300 p_ca_slot_info->num = 1;
301 p_ca_slot_info->type = CA_CI;
303 p_ca_slot_info->flags = 0;
305 if (copy_to_user(arg, p_ca_slot_info, sizeof (struct ca_slot_info)))
312 static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
317 if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg)))
320 if (p_ca_message->msg) {
321 dprintk(verbose, DST_CA_NOTICE, 1, " Message = [%02x %02x %02x]", p_ca_message->msg[0], p_ca_message->msg[1], p_ca_message->msg[2]);
323 for (i = 0; i < 3; i++) {
324 command = command | p_ca_message->msg[i];
326 command = command << 8;
328 dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);
332 memcpy(p_ca_message->msg, state->messages, 128);
333 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
337 memcpy(p_ca_message->msg, state->messages, 128);
338 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
347 static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
349 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
350 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
351 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
354 dprintk(verbose, DST_CA_ERROR, 1, " Message too long ! *** Bailing Out *** !");
357 hw_buffer->msg[0] = (length & 0xff) + 7;
358 hw_buffer->msg[1] = 0x40;
359 hw_buffer->msg[2] = 0x03;
360 hw_buffer->msg[3] = 0x00;
361 hw_buffer->msg[4] = 0x03;
362 hw_buffer->msg[5] = length & 0xff;
363 hw_buffer->msg[6] = 0x00;
366 * Need to compute length for EN50221 section 8.3.2, for the time being
367 * assuming 8.3.2 is not applicable
369 memcpy(&hw_buffer->msg[7], &p_ca_message->msg[4], length);
375 static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
377 if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
378 dprintk(verbose, DST_CA_ERROR, 1, " DST-CI Command failed.");
379 dprintk(verbose, DST_CA_NOTICE, 1, " Resetting DST.");
380 rdc_reset_state(state);
383 dprintk(verbose, DST_CA_NOTICE, 1, " DST-CI Command success.");
388 static u32 asn_1_decode(u8 *asn_1_array)
390 u8 length_field = 0, word_count = 0, count = 0;
393 length_field = asn_1_array[0];
394 dprintk(verbose, DST_CA_DEBUG, 1, " Length field=[%02x]", length_field);
395 if (length_field < 0x80) {
396 length = length_field & 0x7f;
397 dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%02x]\n", length);
399 word_count = length_field & 0x7f;
400 for (count = 0; count < word_count; count++) {
401 length = length << 8;
402 length += asn_1_array[count + 1];
403 dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length);
409 static int debug_string(u8 *msg, u32 length, u32 offset)
413 dprintk(verbose, DST_CA_DEBUG, 0, " String=[ ");
414 for (i = offset; i < length; i++)
415 dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]);
416 dprintk(verbose, DST_CA_DEBUG, 0, "]\n");
422 static int ca_get_mmi(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *mmi_msg)
424 static u8 get_mmi[] = { 0x07, 0x40, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x0f };
426 put_checksum(&get_mmi[0], 7);
427 if ((dst_put_ci(state, get_mmi, sizeof (get_mmi), hw_msg->msg, GET_REPLY)) < 0) {
428 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
431 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
432 memcpy(mmi_msg->msg, hw_msg->msg, hw_msg->msg[4]);
438 * Get Menu should be the first MMI function (like open !)
440 static int ca_get_menu(struct dst_state *state)
442 static u8 get_menu[] = { 0x07, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00, 0xff };
444 put_checksum(&get_menu[0], 7);
445 if ((dst_put_ci(state, get_menu, sizeof (get_menu), get_menu, NO_REPLY)) < 0) {
446 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
449 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
455 * MMI Enq (Enquire the application to allow user input)
457 static int ca_answer_menu(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *menu_answ)
461 static u8 answer_menu[] = { 0x08, 0x40, 0x00, 0x00, 0x0b, 0x01, 0x00, 0x01, 0xff };
463 /* derive answer from menu (This comes from the user) */
464 answer_menu[7] = choice;
465 put_checksum(&answer_menu[0], 7);
466 if ((dst_put_ci(state, answer_menu, sizeof (answer_menu), hw_msg->msg, NO_REPLY)) < 0) {
467 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
470 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
475 static int ca_answer_mmi(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *answ_msg)
477 u8 answer =0, length = 0;
479 static u8 answer_mmi[] = { 0x08, 0x40, 0x00, 0x00, 0x08, 0x01, 0x00, 0x01, 0xff };
481 /* derive answer from answ_msg (This comes from the user) */
482 if (answer == 0) /* 0x00 == Cancel */
483 answer_mmi[7] = 0x00;
484 else { /* 0x01 == Answer */
485 length = strlen(answ_msg->msg);
486 memcpy(&answer_mmi[8], answ_msg->msg, length);
487 answer_mmi[0] += length;
488 answer_mmi[5] += length;
490 put_checksum(&answer_mmi[0], (8 + length));
491 if ((dst_put_ci(state, answer_mmi, sizeof (answer_mmi), hw_msg->msg, GET_REPLY)) < 0) {
492 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci FAILED !");
496 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
501 static int ca_close_mmi(struct dst_state *state, struct ca_msg *hw_msg)
503 static u8 close_mmi[] = { 0x07, 0x40, 0x00, 0x00, 0x0e, 0x00, 0x00, 0xff };
505 put_checksum(&close_mmi[0], 7);
506 if ((dst_put_ci(state, close_mmi, sizeof (close_mmi), hw_msg->msg, NO_REPLY)) < 0) {
507 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
511 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
516 static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
521 length = asn_1_decode(&p_ca_message->msg[3]);
522 dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length);
523 debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */
525 memset(hw_buffer->msg, '\0', length);
526 handle_dst_tag(state, p_ca_message, hw_buffer, length);
527 put_checksum(hw_buffer->msg, hw_buffer->msg[0]);
529 debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */
530 write_to_8820(state, hw_buffer, (length + tag_length), reply);
536 /* Board supports CA PMT reply ? */
537 static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
539 int ca_pmt_reply_test = 0;
542 /* Not there yet but soon */
544 /* CA PMT Reply capable */
545 if (ca_pmt_reply_test) {
546 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
547 dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
551 /* Process CA PMT Reply */
552 /* will implement soon */
553 dprintk(verbose, DST_CA_ERROR, 1, " Not there yet");
555 /* CA PMT Reply not capable */
556 if (!ca_pmt_reply_test) {
557 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
558 dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
561 dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !");
562 /* put a dummy message */
568 static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
571 unsigned int ca_message_header_len;
574 struct ca_msg *hw_buffer;
577 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
578 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
581 dprintk(verbose, DST_CA_DEBUG, 1, " ");
583 if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) {
585 goto free_mem_and_exit;
589 if (p_ca_message->msg) {
590 ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
594 for (i = 0; i < 3; i++) {
595 command = command | p_ca_message->msg[i];
597 command = command << 8;
599 dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);
603 dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");
604 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
605 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");
607 goto free_mem_and_exit;
609 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");
612 dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");
613 /* Have to handle the 2 basic types of cards here */
614 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
615 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");
617 goto free_mem_and_exit;
619 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
621 case CA_APP_INFO_ENQUIRY: // only for debugging
622 dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
624 if ((ca_get_app_info(state)) < 0) {
625 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
627 goto free_mem_and_exit;
629 dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
631 case CA_INFO_ENQUIRY:
632 dprintk(verbose, DST_CA_INFO, 1, " Getting CA Information");
634 if ((ca_get_ca_info(state)) < 0) {
635 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_INFO_ENQUIRY Failed !");
637 goto free_mem_and_exit;
639 dprintk(verbose, DST_CA_INFO, 1, " -->CA_INFO_ENQUIRY Success !");
649 static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg)
651 struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
652 struct dst_state* state = (struct dst_state*) dvbdev->priv;
653 struct ca_slot_info *p_ca_slot_info;
654 struct ca_caps *p_ca_caps;
655 struct ca_msg *p_ca_message;
656 void __user *arg = (void __user *)ioctl_arg;
659 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
660 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
663 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
664 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
667 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
668 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
671 /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
674 dprintk(verbose, DST_CA_INFO, 1, " Sending message");
675 if ((ca_send_message(state, p_ca_message, arg)) < 0) {
676 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");
678 goto free_mem_and_exit;
682 dprintk(verbose, DST_CA_INFO, 1, " Getting message");
683 if ((ca_get_message(state, p_ca_message, arg)) < 0) {
684 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");
686 goto free_mem_and_exit;
688 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");
691 dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");
692 dst_error_bailout(state);
695 case CA_GET_SLOT_INFO:
696 dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");
697 if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
698 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");
700 goto free_mem_and_exit;
702 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");
705 dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");
706 if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
707 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");
709 goto free_mem_and_exit;
711 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");
713 case CA_GET_DESCR_INFO:
714 dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");
715 if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
716 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");
718 goto free_mem_and_exit;
720 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");
723 dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");
724 if ((ca_set_slot_descr()) < 0) {
725 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");
727 goto free_mem_and_exit;
729 dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");
732 dprintk(verbose, DST_CA_INFO, 1, " Setting PID");
733 if ((ca_set_pid()) < 0) {
734 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");
736 goto free_mem_and_exit;
738 dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");
740 result = -EOPNOTSUPP;
743 kfree (p_ca_message);
744 kfree (p_ca_slot_info);
750 static int dst_ca_open(struct inode *inode, struct file *file)
752 dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file);
753 try_module_get(THIS_MODULE);
758 static int dst_ca_release(struct inode *inode, struct file *file)
760 dprintk(verbose, DST_CA_DEBUG, 1, " Device closed.");
761 module_put(THIS_MODULE);
766 static ssize_t dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
768 ssize_t bytes_read = 0;
770 dprintk(verbose, DST_CA_DEBUG, 1, " Device read.");
775 static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)
777 dprintk(verbose, DST_CA_DEBUG, 1, " Device write.");
782 static struct file_operations dst_ca_fops = {
783 .owner = THIS_MODULE,
784 .ioctl = dst_ca_ioctl,
786 .release = dst_ca_release,
788 .write = dst_ca_write
791 static struct dvb_device dvbdev_ca = {
799 int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
801 struct dvb_device *dvbdev;
802 dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
803 dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
807 EXPORT_SYMBOL(dst_ca_attach);
809 MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
810 MODULE_AUTHOR("Manu Abraham");
811 MODULE_LICENSE("GPL");