Path: blob/master/drivers/media/dvb/bt8xx/dst_ca.c
15112 views
/*1CA-driver for TwinHan DST Frontend/Card23Copyright (C) 2004, 2005 Manu Abraham ([email protected])45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*/1920#include <linux/kernel.h>21#include <linux/module.h>22#include <linux/slab.h>23#include <linux/init.h>24#include <linux/mutex.h>25#include <linux/string.h>26#include <linux/dvb/ca.h>27#include "dvbdev.h"28#include "dvb_frontend.h"29#include "dst_ca.h"30#include "dst_common.h"3132#define DST_CA_ERROR 033#define DST_CA_NOTICE 134#define DST_CA_INFO 235#define DST_CA_DEBUG 33637#define dprintk(x, y, z, format, arg...) do { \38if (z) { \39if ((x > DST_CA_ERROR) && (x > y)) \40printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \41else if ((x > DST_CA_NOTICE) && (x > y)) \42printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \43else if ((x > DST_CA_INFO) && (x > y)) \44printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \45else if ((x > DST_CA_DEBUG) && (x > y)) \46printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \47} else { \48if (x > y) \49printk(format, ## arg); \50} \51} while(0)525354static DEFINE_MUTEX(dst_ca_mutex);55static unsigned int verbose = 5;56module_param(verbose, int, 0644);57MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");5859/* Need some more work */60static int ca_set_slot_descr(void)61{62/* We could make this more graceful ? */63return -EOPNOTSUPP;64}6566/* Need some more work */67static int ca_set_pid(void)68{69/* We could make this more graceful ? */70return -EOPNOTSUPP;71}7273static void put_command_and_length(u8 *data, int command, int length)74{75data[0] = (command >> 16) & 0xff;76data[1] = (command >> 8) & 0xff;77data[2] = command & 0xff;78data[3] = length;79}8081static void put_checksum(u8 *check_string, int length)82{83dprintk(verbose, DST_CA_DEBUG, 1, " Computing string checksum.");84dprintk(verbose, DST_CA_DEBUG, 1, " -> string length : 0x%02x", length);85check_string[length] = dst_check_sum (check_string, length);86dprintk(verbose, DST_CA_DEBUG, 1, " -> checksum : 0x%02x", check_string[length]);87}8889static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8 len, int read)90{91u8 reply;9293mutex_lock(&state->dst_mutex);94dst_comm_init(state);95msleep(65);9697if (write_dst(state, data, len)) {98dprintk(verbose, DST_CA_INFO, 1, " Write not successful, trying to recover");99dst_error_recovery(state);100goto error;101}102if ((dst_pio_disable(state)) < 0) {103dprintk(verbose, DST_CA_ERROR, 1, " DST PIO disable failed.");104goto error;105}106if (read_dst(state, &reply, GET_ACK) < 0) {107dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");108dst_error_recovery(state);109goto error;110}111if (read) {112if (! dst_wait_dst_ready(state, LONG_DELAY)) {113dprintk(verbose, DST_CA_NOTICE, 1, " 8820 not ready");114goto error;115}116if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */117dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");118dst_error_recovery(state);119goto error;120}121}122mutex_unlock(&state->dst_mutex);123return 0;124125error:126mutex_unlock(&state->dst_mutex);127return -EIO;128}129130131static int dst_put_ci(struct dst_state *state, u8 *data, int len, u8 *ca_string, int read)132{133u8 dst_ca_comm_err = 0;134135while (dst_ca_comm_err < RETRIES) {136dprintk(verbose, DST_CA_NOTICE, 1, " Put Command");137if (dst_ci_command(state, data, ca_string, len, read)) { // If error138dst_error_recovery(state);139dst_ca_comm_err++; // work required here.140} else {141break;142}143}144145if(dst_ca_comm_err == RETRIES)146return -1;147148return 0;149}150151152153static int ca_get_app_info(struct dst_state *state)154{155int length, str_length;156static u8 command[8] = {0x07, 0x40, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff};157158put_checksum(&command[0], command[0]);159if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) {160dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");161return -1;162}163dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");164dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================");165dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]",166state->messages[7], (state->messages[8] << 8) | state->messages[9],167(state->messages[10] << 8) | state->messages[11], __func__, (char *)(&state->messages[12]));168dprintk(verbose, DST_CA_INFO, 1, " ==================================================================================================");169170// Transform dst message to correct application_info message171length = state->messages[5];172str_length = length - 6;173if (str_length < 0) {174str_length = 0;175dprintk(verbose, DST_CA_ERROR, 1, "Invalid string length returned in ca_get_app_info(). Recovering.");176}177178// First, the command and length fields179put_command_and_length(&state->messages[0], CA_APP_INFO, length);180181// Copy application_type, application_manufacturer and manufacturer_code182memcpy(&state->messages[4], &state->messages[7], 5);183184// Set string length and copy string185state->messages[9] = str_length;186memcpy(&state->messages[10], &state->messages[12], str_length);187188return 0;189}190191static int ca_get_ca_info(struct dst_state *state)192{193int srcPtr, dstPtr, i, num_ids;194static u8 slot_command[8] = {0x07, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0xff};195const int in_system_id_pos = 8, out_system_id_pos = 4, in_num_ids_pos = 7;196197put_checksum(&slot_command[0], slot_command[0]);198if ((dst_put_ci(state, slot_command, sizeof (slot_command), state->messages, GET_REPLY)) < 0) {199dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");200return -1;201}202dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");203204// Print raw data205dprintk(verbose, DST_CA_INFO, 0, " DST data = [");206for (i = 0; i < state->messages[0] + 1; i++) {207dprintk(verbose, DST_CA_INFO, 0, " 0x%02x", state->messages[i]);208}209dprintk(verbose, DST_CA_INFO, 0, "]\n");210211// Set the command and length of the output212num_ids = state->messages[in_num_ids_pos];213if (num_ids >= 100) {214num_ids = 100;215dprintk(verbose, DST_CA_ERROR, 1, "Invalid number of ids (>100). Recovering.");216}217put_command_and_length(&state->messages[0], CA_INFO, num_ids * 2);218219dprintk(verbose, DST_CA_INFO, 0, " CA_INFO = [");220srcPtr = in_system_id_pos;221dstPtr = out_system_id_pos;222for(i = 0; i < num_ids; i++) {223dprintk(verbose, DST_CA_INFO, 0, " 0x%02x%02x", state->messages[srcPtr + 0], state->messages[srcPtr + 1]);224// Append to output225state->messages[dstPtr + 0] = state->messages[srcPtr + 0];226state->messages[dstPtr + 1] = state->messages[srcPtr + 1];227srcPtr += 2;228dstPtr += 2;229}230dprintk(verbose, DST_CA_INFO, 0, "]\n");231232return 0;233}234235static int ca_get_slot_caps(struct dst_state *state, struct ca_caps *p_ca_caps, void __user *arg)236{237int i;238u8 slot_cap[256];239static u8 slot_command[8] = {0x07, 0x40, 0x02, 0x00, 0x02, 0x00, 0x00, 0xff};240241put_checksum(&slot_command[0], slot_command[0]);242if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) {243dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");244return -1;245}246dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");247248/* Will implement the rest soon */249250dprintk(verbose, DST_CA_INFO, 1, " Slot cap = [%d]", slot_cap[7]);251dprintk(verbose, DST_CA_INFO, 0, "===================================\n");252for (i = 0; i < slot_cap[0] + 1; i++)253dprintk(verbose, DST_CA_INFO, 0, " %d", slot_cap[i]);254dprintk(verbose, DST_CA_INFO, 0, "\n");255256p_ca_caps->slot_num = 1;257p_ca_caps->slot_type = 1;258p_ca_caps->descr_num = slot_cap[7];259p_ca_caps->descr_type = 1;260261if (copy_to_user(arg, p_ca_caps, sizeof (struct ca_caps)))262return -EFAULT;263264return 0;265}266267/* Need some more work */268static int ca_get_slot_descr(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)269{270return -EOPNOTSUPP;271}272273274static int ca_get_slot_info(struct dst_state *state, struct ca_slot_info *p_ca_slot_info, void __user *arg)275{276int i;277static u8 slot_command[8] = {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};278279u8 *slot_info = state->messages;280281put_checksum(&slot_command[0], 7);282if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) {283dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");284return -1;285}286dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");287288/* Will implement the rest soon */289290dprintk(verbose, DST_CA_INFO, 1, " Slot info = [%d]", slot_info[3]);291dprintk(verbose, DST_CA_INFO, 0, "===================================\n");292for (i = 0; i < 8; i++)293dprintk(verbose, DST_CA_INFO, 0, " %d", slot_info[i]);294dprintk(verbose, DST_CA_INFO, 0, "\n");295296if (slot_info[4] & 0x80) {297p_ca_slot_info->flags = CA_CI_MODULE_PRESENT;298p_ca_slot_info->num = 1;299p_ca_slot_info->type = CA_CI;300} else if (slot_info[4] & 0x40) {301p_ca_slot_info->flags = CA_CI_MODULE_READY;302p_ca_slot_info->num = 1;303p_ca_slot_info->type = CA_CI;304} else305p_ca_slot_info->flags = 0;306307if (copy_to_user(arg, p_ca_slot_info, sizeof (struct ca_slot_info)))308return -EFAULT;309310return 0;311}312313314static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)315{316u8 i = 0;317u32 command = 0;318319if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg)))320return -EFAULT;321322if (p_ca_message->msg) {323dprintk(verbose, DST_CA_NOTICE, 1, " Message = [%02x %02x %02x]", p_ca_message->msg[0], p_ca_message->msg[1], p_ca_message->msg[2]);324325for (i = 0; i < 3; i++) {326command = command | p_ca_message->msg[i];327if (i < 2)328command = command << 8;329}330dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);331332switch (command) {333case CA_APP_INFO:334memcpy(p_ca_message->msg, state->messages, 128);335if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )336return -EFAULT;337break;338case CA_INFO:339memcpy(p_ca_message->msg, state->messages, 128);340if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )341return -EFAULT;342break;343}344}345346return 0;347}348349static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)350{351if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {352hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */353hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */354} else {355if (length > 247) {356dprintk(verbose, DST_CA_ERROR, 1, " Message too long ! *** Bailing Out *** !");357return -1;358}359hw_buffer->msg[0] = (length & 0xff) + 7;360hw_buffer->msg[1] = 0x40;361hw_buffer->msg[2] = 0x03;362hw_buffer->msg[3] = 0x00;363hw_buffer->msg[4] = 0x03;364hw_buffer->msg[5] = length & 0xff;365hw_buffer->msg[6] = 0x00;366367/*368* Need to compute length for EN50221 section 8.3.2, for the time being369* assuming 8.3.2 is not applicable370*/371memcpy(&hw_buffer->msg[7], &p_ca_message->msg[4], length);372}373374return 0;375}376377static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)378{379if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {380dprintk(verbose, DST_CA_ERROR, 1, " DST-CI Command failed.");381dprintk(verbose, DST_CA_NOTICE, 1, " Resetting DST.");382rdc_reset_state(state);383return -1;384}385dprintk(verbose, DST_CA_NOTICE, 1, " DST-CI Command success.");386387return 0;388}389390static u32 asn_1_decode(u8 *asn_1_array)391{392u8 length_field = 0, word_count = 0, count = 0;393u32 length = 0;394395length_field = asn_1_array[0];396dprintk(verbose, DST_CA_DEBUG, 1, " Length field=[%02x]", length_field);397if (length_field < 0x80) {398length = length_field & 0x7f;399dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%02x]\n", length);400} else {401word_count = length_field & 0x7f;402for (count = 0; count < word_count; count++) {403length = length << 8;404length += asn_1_array[count + 1];405dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length);406}407}408return length;409}410411static int debug_string(u8 *msg, u32 length, u32 offset)412{413u32 i;414415dprintk(verbose, DST_CA_DEBUG, 0, " String=[ ");416for (i = offset; i < length; i++)417dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]);418dprintk(verbose, DST_CA_DEBUG, 0, "]\n");419420return 0;421}422423424static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)425{426u32 length = 0;427u8 tag_length = 8;428429length = asn_1_decode(&p_ca_message->msg[3]);430dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length);431debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */432433memset(hw_buffer->msg, '\0', length);434handle_dst_tag(state, p_ca_message, hw_buffer, length);435put_checksum(hw_buffer->msg, hw_buffer->msg[0]);436437debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */438write_to_8820(state, hw_buffer, (length + tag_length), reply);439440return 0;441}442443444/* Board supports CA PMT reply ? */445static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)446{447int ca_pmt_reply_test = 0;448449/* Do test board */450/* Not there yet but soon */451452/* CA PMT Reply capable */453if (ca_pmt_reply_test) {454if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {455dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");456return -1;457}458459/* Process CA PMT Reply */460/* will implement soon */461dprintk(verbose, DST_CA_ERROR, 1, " Not there yet");462}463/* CA PMT Reply not capable */464if (!ca_pmt_reply_test) {465if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {466dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");467return -1;468}469dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !");470/* put a dummy message */471472}473return 0;474}475476static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)477{478int i = 0;479unsigned int ca_message_header_len;480481u32 command = 0;482struct ca_msg *hw_buffer;483int result = 0;484485if ((hw_buffer = kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {486dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");487return -ENOMEM;488}489dprintk(verbose, DST_CA_DEBUG, 1, " ");490491if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) {492result = -EFAULT;493goto free_mem_and_exit;494}495496497if (p_ca_message->msg) {498ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */499/* EN50221 tag */500command = 0;501502for (i = 0; i < 3; i++) {503command = command | p_ca_message->msg[i];504if (i < 2)505command = command << 8;506}507dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);508509switch (command) {510case CA_PMT:511dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");512if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started513dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");514result = -1;515goto free_mem_and_exit;516}517dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");518break;519case CA_PMT_REPLY:520dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");521/* Have to handle the 2 basic types of cards here */522if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {523dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");524result = -1;525goto free_mem_and_exit;526}527dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");528break;529case CA_APP_INFO_ENQUIRY: // only for debugging530dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");531532if ((ca_get_app_info(state)) < 0) {533dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");534result = -1;535goto free_mem_and_exit;536}537dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");538break;539case CA_INFO_ENQUIRY:540dprintk(verbose, DST_CA_INFO, 1, " Getting CA Information");541542if ((ca_get_ca_info(state)) < 0) {543dprintk(verbose, DST_CA_ERROR, 1, " -->CA_INFO_ENQUIRY Failed !");544result = -1;545goto free_mem_and_exit;546}547dprintk(verbose, DST_CA_INFO, 1, " -->CA_INFO_ENQUIRY Success !");548break;549}550}551free_mem_and_exit:552kfree (hw_buffer);553554return result;555}556557static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioctl_arg)558{559struct dvb_device *dvbdev;560struct dst_state *state;561struct ca_slot_info *p_ca_slot_info;562struct ca_caps *p_ca_caps;563struct ca_msg *p_ca_message;564void __user *arg = (void __user *)ioctl_arg;565int result = 0;566567mutex_lock(&dst_ca_mutex);568dvbdev = file->private_data;569state = (struct dst_state *)dvbdev->priv;570p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL);571p_ca_slot_info = kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL);572p_ca_caps = kmalloc(sizeof (struct ca_caps), GFP_KERNEL);573if (!p_ca_message || !p_ca_slot_info || !p_ca_caps) {574dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");575result = -ENOMEM;576goto free_mem_and_exit;577}578579/* We have now only the standard ioctl's, the driver is upposed to handle internals. */580switch (cmd) {581case CA_SEND_MSG:582dprintk(verbose, DST_CA_INFO, 1, " Sending message");583if ((ca_send_message(state, p_ca_message, arg)) < 0) {584dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");585result = -1;586goto free_mem_and_exit;587}588break;589case CA_GET_MSG:590dprintk(verbose, DST_CA_INFO, 1, " Getting message");591if ((ca_get_message(state, p_ca_message, arg)) < 0) {592dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");593result = -1;594goto free_mem_and_exit;595}596dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");597break;598case CA_RESET:599dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");600dst_error_bailout(state);601msleep(4000);602break;603case CA_GET_SLOT_INFO:604dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");605if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {606dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");607result = -1;608goto free_mem_and_exit;609}610dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");611break;612case CA_GET_CAP:613dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");614if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {615dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");616result = -1;617goto free_mem_and_exit;618}619dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");620break;621case CA_GET_DESCR_INFO:622dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");623if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {624dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");625result = -1;626goto free_mem_and_exit;627}628dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");629break;630case CA_SET_DESCR:631dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");632if ((ca_set_slot_descr()) < 0) {633dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");634result = -1;635goto free_mem_and_exit;636}637dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");638break;639case CA_SET_PID:640dprintk(verbose, DST_CA_INFO, 1, " Setting PID");641if ((ca_set_pid()) < 0) {642dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");643result = -1;644goto free_mem_and_exit;645}646dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");647default:648result = -EOPNOTSUPP;649};650free_mem_and_exit:651kfree (p_ca_message);652kfree (p_ca_slot_info);653kfree (p_ca_caps);654655mutex_unlock(&dst_ca_mutex);656return result;657}658659static int dst_ca_open(struct inode *inode, struct file *file)660{661dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file);662try_module_get(THIS_MODULE);663664return 0;665}666667static int dst_ca_release(struct inode *inode, struct file *file)668{669dprintk(verbose, DST_CA_DEBUG, 1, " Device closed.");670module_put(THIS_MODULE);671672return 0;673}674675static ssize_t dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)676{677ssize_t bytes_read = 0;678679dprintk(verbose, DST_CA_DEBUG, 1, " Device read.");680681return bytes_read;682}683684static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)685{686dprintk(verbose, DST_CA_DEBUG, 1, " Device write.");687688return 0;689}690691static const struct file_operations dst_ca_fops = {692.owner = THIS_MODULE,693.unlocked_ioctl = dst_ca_ioctl,694.open = dst_ca_open,695.release = dst_ca_release,696.read = dst_ca_read,697.write = dst_ca_write,698.llseek = noop_llseek,699};700701static struct dvb_device dvbdev_ca = {702.priv = NULL,703.users = 1,704.readers = 1,705.writers = 1,706.fops = &dst_ca_fops707};708709struct dvb_device *dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)710{711struct dvb_device *dvbdev;712713dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");714if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA) == 0) {715dst->dst_ca = dvbdev;716return dst->dst_ca;717}718719return NULL;720}721722EXPORT_SYMBOL(dst_ca_attach);723724MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");725MODULE_AUTHOR("Manu Abraham");726MODULE_LICENSE("GPL");727728729