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_mmi(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *mmi_msg)
314 static u8 get_mmi[] = { 0x07, 0x40, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x0f };
316 put_checksum(&get_mmi[0], 7);
317 if ((dst_put_ci(state, get_mmi, sizeof (get_mmi), hw_msg->msg, GET_REPLY)) < 0) {
318 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
321 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
322 memcpy(mmi_msg->msg, hw_msg->msg, hw_msg->msg[4]);
328 * Get Menu should be the first MMI function (like open !)
330 static int ca_get_menu(struct dst_state *state)
332 static u8 get_menu[] = { 0x07, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00, 0xff };
334 put_checksum(&get_menu[0], 7);
335 if ((dst_put_ci(state, get_menu, sizeof (get_menu), get_menu, NO_REPLY)) < 0) {
336 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
339 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
345 * MMI Enq (Enquire the application to allow user input)
347 static int ca_answer_menu(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *menu_answ)
351 static u8 answer_menu[] = { 0x08, 0x40, 0x00, 0x00, 0x0b, 0x01, 0x00, 0x01, 0xff };
353 /* derive answer from menu (This comes from the user) */
354 answer_menu[7] = choice;
355 put_checksum(&answer_menu[0], 7);
356 if ((dst_put_ci(state, answer_menu, sizeof (answer_menu), hw_msg->msg, NO_REPLY)) < 0) {
357 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
360 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
365 static int ca_answer_mmi(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *answ_msg)
367 u8 answer =0, length = 0;
369 static u8 answer_mmi[] = { 0x08, 0x40, 0x00, 0x00, 0x08, 0x01, 0x00, 0x01, 0xff };
371 /* derive answer from answ_msg (This comes from the user) */
372 if (answer == 0) /* 0x00 == Cancel */
373 answer_mmi[7] = 0x00;
374 else { /* 0x01 == Answer */
375 length = strlen(answ_msg->msg);
376 memcpy(&answer_mmi[8], answ_msg->msg, length);
377 answer_mmi[0] += length;
378 answer_mmi[5] += length;
380 put_checksum(&answer_mmi[0], (8 + length));
381 if ((dst_put_ci(state, answer_mmi, sizeof (answer_mmi), hw_msg->msg, GET_REPLY)) < 0) {
382 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci FAILED !");
386 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
391 static int ca_close_mmi(struct dst_state *state, struct ca_msg *hw_msg)
393 static u8 close_mmi[] = { 0x07, 0x40, 0x00, 0x00, 0x0e, 0x00, 0x00, 0xff };
395 put_checksum(&close_mmi[0], 7);
396 if ((dst_put_ci(state, close_mmi, sizeof (close_mmi), hw_msg->msg, NO_REPLY)) < 0) {
397 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
401 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
406 static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
411 if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg)))
414 if (p_ca_message->msg) {
415 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]);
417 for (i = 0; i < 3; i++) {
418 command = command | p_ca_message->msg[i];
420 command = command << 8;
422 dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);
426 memcpy(p_ca_message->msg, state->messages, 128);
427 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
431 memcpy(p_ca_message->msg, state->messages, 128);
432 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
441 static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
443 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
444 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
445 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
448 dprintk(verbose, DST_CA_ERROR, 1, " Message too long ! *** Bailing Out *** !");
451 hw_buffer->msg[0] = (length & 0xff) + 7;
452 hw_buffer->msg[1] = 0x40;
453 hw_buffer->msg[2] = 0x03;
454 hw_buffer->msg[3] = 0x00;
455 hw_buffer->msg[4] = 0x03;
456 hw_buffer->msg[5] = length & 0xff;
457 hw_buffer->msg[6] = 0x00;
460 * Need to compute length for EN50221 section 8.3.2, for the time being
461 * assuming 8.3.2 is not applicable
463 memcpy(&hw_buffer->msg[7], &p_ca_message->msg[4], length);
469 static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
471 if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
472 dprintk(verbose, DST_CA_ERROR, 1, " DST-CI Command failed.");
473 dprintk(verbose, DST_CA_NOTICE, 1, " Resetting DST.");
474 rdc_reset_state(state);
477 dprintk(verbose, DST_CA_NOTICE, 1, " DST-CI Command success.");
482 static u32 asn_1_decode(u8 *asn_1_array)
484 u8 length_field = 0, word_count = 0, count = 0;
487 length_field = asn_1_array[0];
488 dprintk(verbose, DST_CA_DEBUG, 1, " Length field=[%02x]", length_field);
489 if (length_field < 0x80) {
490 length = length_field & 0x7f;
491 dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%02x]\n", length);
493 word_count = length_field & 0x7f;
494 for (count = 0; count < word_count; count++) {
495 length = length << 8;
496 length += asn_1_array[count + 1];
497 dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length);
503 static int debug_string(u8 *msg, u32 length, u32 offset)
507 dprintk(verbose, DST_CA_DEBUG, 0, " String=[ ");
508 for (i = offset; i < length; i++)
509 dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]);
510 dprintk(verbose, DST_CA_DEBUG, 0, "]\n");
516 static int ca_get_mmi(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *mmi_msg)
518 static u8 get_mmi[] = { 0x07, 0x40, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x0f };
520 put_checksum(&get_mmi[0], 7);
521 if ((dst_put_ci(state, get_mmi, sizeof (get_mmi), hw_msg->msg, GET_REPLY)) < 0) {
522 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
525 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
526 memcpy(mmi_msg->msg, hw_msg->msg, hw_msg->msg[4]);
532 * Get Menu should be the first MMI function (like open !)
534 static int ca_get_menu(struct dst_state *state)
536 static u8 get_menu[] = { 0x07, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00, 0xff };
538 put_checksum(&get_menu[0], 7);
539 if ((dst_put_ci(state, get_menu, sizeof (get_menu), get_menu, NO_REPLY)) < 0) {
540 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
543 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
549 * MMI Enq (Enquire the application to allow user input)
551 static int ca_answer_menu(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *menu_answ)
555 static u8 answer_menu[] = { 0x08, 0x40, 0x00, 0x00, 0x0b, 0x01, 0x00, 0x01, 0xff };
557 /* derive answer from menu (This comes from the user) */
558 answer_menu[7] = choice;
559 put_checksum(&answer_menu[0], 7);
560 if ((dst_put_ci(state, answer_menu, sizeof (answer_menu), hw_msg->msg, NO_REPLY)) < 0) {
561 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
564 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
569 static int ca_answer_mmi(struct dst_state *state, struct ca_msg *hw_msg, struct ca_msg *answ_msg)
571 u8 answer =0, length = 0;
573 static u8 answer_mmi[] = { 0x08, 0x40, 0x00, 0x00, 0x08, 0x01, 0x00, 0x01, 0xff };
575 /* derive answer from answ_msg (This comes from the user) */
576 if (answer == 0) /* 0x00 == Cancel */
577 answer_mmi[7] = 0x00;
578 else { /* 0x01 == Answer */
579 length = strlen(answ_msg->msg);
580 memcpy(&answer_mmi[8], answ_msg->msg, length);
581 answer_mmi[0] += length;
582 answer_mmi[5] += length;
584 put_checksum(&answer_mmi[0], (8 + length));
585 if ((dst_put_ci(state, answer_mmi, sizeof (answer_mmi), hw_msg->msg, GET_REPLY)) < 0) {
586 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci FAILED !");
590 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
595 static int ca_close_mmi(struct dst_state *state, struct ca_msg *hw_msg)
597 static u8 close_mmi[] = { 0x07, 0x40, 0x00, 0x00, 0x0e, 0x00, 0x00, 0xff };
599 put_checksum(&close_mmi[0], 7);
600 if ((dst_put_ci(state, close_mmi, sizeof (close_mmi), hw_msg->msg, NO_REPLY)) < 0) {
601 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
605 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
610 static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
615 length = asn_1_decode(&p_ca_message->msg[3]);
616 dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length);
617 debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */
619 memset(hw_buffer->msg, '\0', length);
620 handle_dst_tag(state, p_ca_message, hw_buffer, length);
621 put_checksum(hw_buffer->msg, hw_buffer->msg[0]);
623 debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */
624 write_to_8820(state, hw_buffer, (length + tag_length), reply);
630 /* Board supports CA PMT reply ? */
631 static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
633 int ca_pmt_reply_test = 0;
636 /* Not there yet but soon */
638 /* CA PMT Reply capable */
639 if (ca_pmt_reply_test) {
640 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
641 dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
645 /* Process CA PMT Reply */
646 /* will implement soon */
647 dprintk(verbose, DST_CA_ERROR, 1, " Not there yet");
649 /* CA PMT Reply not capable */
650 if (!ca_pmt_reply_test) {
651 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
652 dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
655 dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !");
656 /* put a dummy message */
662 static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
665 unsigned int ca_message_header_len;
668 struct ca_msg *hw_buffer;
671 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
672 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
675 dprintk(verbose, DST_CA_DEBUG, 1, " ");
677 if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) {
679 goto free_mem_and_exit;
683 if (p_ca_message->msg) {
684 ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
688 for (i = 0; i < 3; i++) {
689 command = command | p_ca_message->msg[i];
691 command = command << 8;
693 dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);
697 dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");
698 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
699 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");
701 goto free_mem_and_exit;
703 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");
706 dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");
707 /* Have to handle the 2 basic types of cards here */
708 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
709 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");
711 goto free_mem_and_exit;
713 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
715 case CA_APP_INFO_ENQUIRY: // only for debugging
716 dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
718 if ((ca_get_app_info(state)) < 0) {
719 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
721 goto free_mem_and_exit;
723 dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
725 case CA_INFO_ENQUIRY:
726 dprintk(verbose, DST_CA_INFO, 1, " Getting CA Information");
728 if ((ca_get_ca_info(state)) < 0) {
729 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_INFO_ENQUIRY Failed !");
731 goto free_mem_and_exit;
733 dprintk(verbose, DST_CA_INFO, 1, " -->CA_INFO_ENQUIRY Success !");
743 static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg)
745 struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
746 struct dst_state* state = (struct dst_state*) dvbdev->priv;
747 struct ca_slot_info *p_ca_slot_info;
748 struct ca_caps *p_ca_caps;
749 struct ca_msg *p_ca_message;
750 void __user *arg = (void __user *)ioctl_arg;
753 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
754 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
757 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
758 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
761 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
762 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
765 /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
768 dprintk(verbose, DST_CA_INFO, 1, " Sending message");
769 if ((ca_send_message(state, p_ca_message, arg)) < 0) {
770 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");
772 goto free_mem_and_exit;
776 dprintk(verbose, DST_CA_INFO, 1, " Getting message");
777 if ((ca_get_message(state, p_ca_message, arg)) < 0) {
778 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");
780 goto free_mem_and_exit;
782 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");
785 dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");
786 dst_error_bailout(state);
789 case CA_GET_SLOT_INFO:
790 dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");
791 if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
792 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");
794 goto free_mem_and_exit;
796 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");
799 dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");
800 if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
801 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");
803 goto free_mem_and_exit;
805 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");
807 case CA_GET_DESCR_INFO:
808 dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");
809 if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
810 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");
812 goto free_mem_and_exit;
814 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");
817 dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");
818 if ((ca_set_slot_descr()) < 0) {
819 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");
821 goto free_mem_and_exit;
823 dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");
826 dprintk(verbose, DST_CA_INFO, 1, " Setting PID");
827 if ((ca_set_pid()) < 0) {
828 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");
830 goto free_mem_and_exit;
832 dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");
834 result = -EOPNOTSUPP;
837 kfree (p_ca_message);
838 kfree (p_ca_slot_info);
844 static int dst_ca_open(struct inode *inode, struct file *file)
846 dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file);
847 try_module_get(THIS_MODULE);
852 static int dst_ca_release(struct inode *inode, struct file *file)
854 dprintk(verbose, DST_CA_DEBUG, 1, " Device closed.");
855 module_put(THIS_MODULE);
860 static ssize_t dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
862 ssize_t bytes_read = 0;
864 dprintk(verbose, DST_CA_DEBUG, 1, " Device read.");
869 static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)
871 dprintk(verbose, DST_CA_DEBUG, 1, " Device write.");
876 static struct file_operations dst_ca_fops = {
877 .owner = THIS_MODULE,
878 .ioctl = dst_ca_ioctl,
880 .release = dst_ca_release,
882 .write = dst_ca_write
885 static struct dvb_device dvbdev_ca = {
893 int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
895 struct dvb_device *dvbdev;
896 dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
897 dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
901 EXPORT_SYMBOL(dst_ca_attach);
903 MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
904 MODULE_AUTHOR("Manu Abraham");
905 MODULE_LICENSE("GPL");