Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | CA-driver for TwinHan DST Frontend/Card |
| 3 | |
| 4 | Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com) |
| 5 | |
| 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. |
| 10 | |
| 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. |
| 15 | |
| 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. |
| 19 | */ |
| 20 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
Arnd Bergmann | adfedd2 | 2010-09-11 19:53:25 +0200 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 26 | #include <linux/string.h> |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 27 | #include <linux/dvb/ca.h> |
Mauro Carvalho Chehab | fada193 | 2017-12-28 13:03:51 -0500 | [diff] [blame^] | 28 | #include <media/dvbdev.h> |
| 29 | #include <media/dvb_frontend.h> |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 30 | #include "dst_ca.h" |
| 31 | #include "dst_common.h" |
| 32 | |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 33 | #define DST_CA_ERROR 0 |
| 34 | #define DST_CA_NOTICE 1 |
| 35 | #define DST_CA_INFO 2 |
| 36 | #define DST_CA_DEBUG 3 |
| 37 | |
| 38 | #define dprintk(x, y, z, format, arg...) do { \ |
| 39 | if (z) { \ |
| 40 | if ((x > DST_CA_ERROR) && (x > y)) \ |
Harvey Harrison | b2e62e7 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 41 | printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \ |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 42 | else if ((x > DST_CA_NOTICE) && (x > y)) \ |
Harvey Harrison | b2e62e7 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 43 | printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \ |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 44 | else if ((x > DST_CA_INFO) && (x > y)) \ |
Harvey Harrison | b2e62e7 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 45 | printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \ |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 46 | else if ((x > DST_CA_DEBUG) && (x > y)) \ |
Harvey Harrison | b2e62e7 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 47 | printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \ |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 48 | } else { \ |
| 49 | if (x > y) \ |
| 50 | printk(format, ## arg); \ |
| 51 | } \ |
| 52 | } while(0) |
| 53 | |
| 54 | |
Arnd Bergmann | adfedd2 | 2010-09-11 19:53:25 +0200 | [diff] [blame] | 55 | static DEFINE_MUTEX(dst_ca_mutex); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 56 | static unsigned int verbose = 5; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 57 | module_param(verbose, int, 0644); |
| 58 | MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); |
| 59 | |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 60 | static void put_command_and_length(u8 *data, int command, int length) |
| 61 | { |
| 62 | data[0] = (command >> 16) & 0xff; |
| 63 | data[1] = (command >> 8) & 0xff; |
| 64 | data[2] = command & 0xff; |
| 65 | data[3] = length; |
| 66 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 67 | |
Perceval Anichini | 4fbbc7e | 2005-11-08 21:35:23 -0800 | [diff] [blame] | 68 | static void put_checksum(u8 *check_string, int length) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 69 | { |
Perceval Anichini | 4fbbc7e | 2005-11-08 21:35:23 -0800 | [diff] [blame] | 70 | dprintk(verbose, DST_CA_DEBUG, 1, " Computing string checksum."); |
| 71 | dprintk(verbose, DST_CA_DEBUG, 1, " -> string length : 0x%02x", length); |
| 72 | check_string[length] = dst_check_sum (check_string, length); |
| 73 | dprintk(verbose, DST_CA_DEBUG, 1, " -> checksum : 0x%02x", check_string[length]); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8 len, int read) |
| 77 | { |
| 78 | u8 reply; |
| 79 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 80 | mutex_lock(&state->dst_mutex); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 81 | dst_comm_init(state); |
| 82 | msleep(65); |
| 83 | |
| 84 | if (write_dst(state, data, len)) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 85 | dprintk(verbose, DST_CA_INFO, 1, " Write not successful, trying to recover"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 86 | dst_error_recovery(state); |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 87 | goto error; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 88 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 89 | if ((dst_pio_disable(state)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 90 | dprintk(verbose, DST_CA_ERROR, 1, " DST PIO disable failed."); |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 91 | goto error; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 92 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 93 | if (read_dst(state, &reply, GET_ACK) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 94 | dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 95 | dst_error_recovery(state); |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 96 | goto error; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 97 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 98 | if (read) { |
| 99 | if (! dst_wait_dst_ready(state, LONG_DELAY)) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 100 | dprintk(verbose, DST_CA_NOTICE, 1, " 8820 not ready"); |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 101 | goto error; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 102 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 103 | if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */ |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 104 | dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 105 | dst_error_recovery(state); |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 106 | goto error; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 109 | mutex_unlock(&state->dst_mutex); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 110 | return 0; |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 111 | |
| 112 | error: |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 113 | mutex_unlock(&state->dst_mutex); |
Manu Abraham | d28d576 | 2005-11-08 21:35:36 -0800 | [diff] [blame] | 114 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
| 118 | static int dst_put_ci(struct dst_state *state, u8 *data, int len, u8 *ca_string, int read) |
| 119 | { |
| 120 | u8 dst_ca_comm_err = 0; |
| 121 | |
| 122 | while (dst_ca_comm_err < RETRIES) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 123 | dprintk(verbose, DST_CA_NOTICE, 1, " Put Command"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 124 | if (dst_ci_command(state, data, ca_string, len, read)) { // If error |
| 125 | dst_error_recovery(state); |
| 126 | dst_ca_comm_err++; // work required here. |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 127 | } else { |
| 128 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 129 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 132 | if(dst_ca_comm_err == RETRIES) |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 133 | return -EIO; |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 134 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | |
| 140 | static int ca_get_app_info(struct dst_state *state) |
| 141 | { |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 142 | int length, str_length; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 143 | static u8 command[8] = {0x07, 0x40, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff}; |
| 144 | |
| 145 | put_checksum(&command[0], command[0]); |
| 146 | if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 147 | dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 148 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 149 | } |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 150 | dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !"); |
| 151 | dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================"); |
| 152 | dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]", |
| 153 | state->messages[7], (state->messages[8] << 8) | state->messages[9], |
Harvey Harrison | b2e62e7 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 154 | (state->messages[10] << 8) | state->messages[11], __func__, (char *)(&state->messages[12])); |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 155 | dprintk(verbose, DST_CA_INFO, 1, " =================================================================================================="); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 156 | |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 157 | // Transform dst message to correct application_info message |
| 158 | length = state->messages[5]; |
| 159 | str_length = length - 6; |
| 160 | if (str_length < 0) { |
| 161 | str_length = 0; |
| 162 | dprintk(verbose, DST_CA_ERROR, 1, "Invalid string length returned in ca_get_app_info(). Recovering."); |
| 163 | } |
| 164 | |
| 165 | // First, the command and length fields |
| 166 | put_command_and_length(&state->messages[0], CA_APP_INFO, length); |
| 167 | |
| 168 | // Copy application_type, application_manufacturer and manufacturer_code |
Nickolai Zeldovich | bb71b14 | 2013-01-07 22:28:05 -0300 | [diff] [blame] | 169 | memmove(&state->messages[4], &state->messages[7], 5); |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 170 | |
| 171 | // Set string length and copy string |
| 172 | state->messages[9] = str_length; |
Nickolai Zeldovich | bb71b14 | 2013-01-07 22:28:05 -0300 | [diff] [blame] | 173 | memmove(&state->messages[10], &state->messages[12], str_length); |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int ca_get_ca_info(struct dst_state *state) |
| 179 | { |
| 180 | int srcPtr, dstPtr, i, num_ids; |
| 181 | static u8 slot_command[8] = {0x07, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0xff}; |
| 182 | const int in_system_id_pos = 8, out_system_id_pos = 4, in_num_ids_pos = 7; |
| 183 | |
| 184 | put_checksum(&slot_command[0], slot_command[0]); |
| 185 | if ((dst_put_ci(state, slot_command, sizeof (slot_command), state->messages, GET_REPLY)) < 0) { |
| 186 | dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 187 | return -EIO; |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 188 | } |
| 189 | dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !"); |
| 190 | |
| 191 | // Print raw data |
| 192 | dprintk(verbose, DST_CA_INFO, 0, " DST data = ["); |
| 193 | for (i = 0; i < state->messages[0] + 1; i++) { |
| 194 | dprintk(verbose, DST_CA_INFO, 0, " 0x%02x", state->messages[i]); |
| 195 | } |
| 196 | dprintk(verbose, DST_CA_INFO, 0, "]\n"); |
| 197 | |
| 198 | // Set the command and length of the output |
| 199 | num_ids = state->messages[in_num_ids_pos]; |
| 200 | if (num_ids >= 100) { |
| 201 | num_ids = 100; |
| 202 | dprintk(verbose, DST_CA_ERROR, 1, "Invalid number of ids (>100). Recovering."); |
| 203 | } |
| 204 | put_command_and_length(&state->messages[0], CA_INFO, num_ids * 2); |
| 205 | |
| 206 | dprintk(verbose, DST_CA_INFO, 0, " CA_INFO = ["); |
| 207 | srcPtr = in_system_id_pos; |
| 208 | dstPtr = out_system_id_pos; |
| 209 | for(i = 0; i < num_ids; i++) { |
| 210 | dprintk(verbose, DST_CA_INFO, 0, " 0x%02x%02x", state->messages[srcPtr + 0], state->messages[srcPtr + 1]); |
| 211 | // Append to output |
| 212 | state->messages[dstPtr + 0] = state->messages[srcPtr + 0]; |
| 213 | state->messages[dstPtr + 1] = state->messages[srcPtr + 1]; |
| 214 | srcPtr += 2; |
| 215 | dstPtr += 2; |
| 216 | } |
| 217 | dprintk(verbose, DST_CA_INFO, 0, "]\n"); |
| 218 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 222 | static int ca_get_slot_caps(struct dst_state *state, struct ca_caps *p_ca_caps, void __user *arg) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 223 | { |
| 224 | int i; |
| 225 | u8 slot_cap[256]; |
| 226 | static u8 slot_command[8] = {0x07, 0x40, 0x02, 0x00, 0x02, 0x00, 0x00, 0xff}; |
| 227 | |
| 228 | put_checksum(&slot_command[0], slot_command[0]); |
| 229 | if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 230 | dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 231 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 232 | } |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 233 | dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 234 | |
| 235 | /* Will implement the rest soon */ |
| 236 | |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 237 | dprintk(verbose, DST_CA_INFO, 1, " Slot cap = [%d]", slot_cap[7]); |
| 238 | dprintk(verbose, DST_CA_INFO, 0, "===================================\n"); |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 239 | for (i = 0; i < slot_cap[0] + 1; i++) |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 240 | dprintk(verbose, DST_CA_INFO, 0, " %d", slot_cap[i]); |
| 241 | dprintk(verbose, DST_CA_INFO, 0, "\n"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 242 | |
| 243 | p_ca_caps->slot_num = 1; |
| 244 | p_ca_caps->slot_type = 1; |
| 245 | p_ca_caps->descr_num = slot_cap[7]; |
| 246 | p_ca_caps->descr_type = 1; |
| 247 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 248 | if (copy_to_user(arg, p_ca_caps, sizeof (struct ca_caps))) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 249 | return -EFAULT; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Johannes Stezenbach | 4a2cc12 | 2005-05-16 21:54:45 -0700 | [diff] [blame] | 254 | /* Need some more work */ |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 255 | static int ca_get_slot_descr(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 256 | { |
| 257 | return -EOPNOTSUPP; |
| 258 | } |
| 259 | |
| 260 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 261 | static int ca_get_slot_info(struct dst_state *state, struct ca_slot_info *p_ca_slot_info, void __user *arg) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 262 | { |
| 263 | int i; |
| 264 | static u8 slot_command[8] = {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}; |
| 265 | |
Manu Abraham | 5c15c0b | 2005-11-08 21:35:24 -0800 | [diff] [blame] | 266 | u8 *slot_info = state->messages; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 267 | |
| 268 | put_checksum(&slot_command[0], 7); |
| 269 | if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 270 | dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 271 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 272 | } |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 273 | dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 274 | |
| 275 | /* Will implement the rest soon */ |
| 276 | |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 277 | dprintk(verbose, DST_CA_INFO, 1, " Slot info = [%d]", slot_info[3]); |
| 278 | dprintk(verbose, DST_CA_INFO, 0, "===================================\n"); |
| 279 | for (i = 0; i < 8; i++) |
| 280 | dprintk(verbose, DST_CA_INFO, 0, " %d", slot_info[i]); |
| 281 | dprintk(verbose, DST_CA_INFO, 0, "\n"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 282 | |
| 283 | if (slot_info[4] & 0x80) { |
| 284 | p_ca_slot_info->flags = CA_CI_MODULE_PRESENT; |
| 285 | p_ca_slot_info->num = 1; |
| 286 | p_ca_slot_info->type = CA_CI; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 287 | } else if (slot_info[4] & 0x40) { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 288 | p_ca_slot_info->flags = CA_CI_MODULE_READY; |
| 289 | p_ca_slot_info->num = 1; |
| 290 | p_ca_slot_info->type = CA_CI; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 291 | } else |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 292 | p_ca_slot_info->flags = 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 293 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 294 | if (copy_to_user(arg, p_ca_slot_info, sizeof (struct ca_slot_info))) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 295 | return -EFAULT; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 301 | static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 302 | { |
| 303 | u8 i = 0; |
| 304 | u32 command = 0; |
| 305 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 306 | if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 307 | return -EFAULT; |
| 308 | |
Mauro Carvalho Chehab | c65171c | 2015-06-05 08:35:09 -0300 | [diff] [blame] | 309 | dprintk(verbose, DST_CA_NOTICE, 1, " Message = [%*ph]", |
| 310 | 3, p_ca_message->msg); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 311 | |
Mauro Carvalho Chehab | c65171c | 2015-06-05 08:35:09 -0300 | [diff] [blame] | 312 | for (i = 0; i < 3; i++) { |
| 313 | command = command | p_ca_message->msg[i]; |
| 314 | if (i < 2) |
| 315 | command = command << 8; |
| 316 | } |
| 317 | dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 318 | |
Mauro Carvalho Chehab | c65171c | 2015-06-05 08:35:09 -0300 | [diff] [blame] | 319 | switch (command) { |
| 320 | case CA_APP_INFO: |
| 321 | memcpy(p_ca_message->msg, state->messages, 128); |
| 322 | if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) ) |
| 323 | return -EFAULT; |
| 324 | break; |
| 325 | case CA_INFO: |
| 326 | memcpy(p_ca_message->msg, state->messages, 128); |
| 327 | if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) ) |
| 328 | return -EFAULT; |
| 329 | break; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 335 | static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 336 | { |
Johannes Stezenbach | 4a2cc12 | 2005-05-16 21:54:45 -0700 | [diff] [blame] | 337 | if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) { |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 338 | hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */ |
| 339 | hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */ |
| 340 | } else { |
| 341 | if (length > 247) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 342 | dprintk(verbose, DST_CA_ERROR, 1, " Message too long ! *** Bailing Out *** !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 343 | return -EIO; |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 344 | } |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 345 | hw_buffer->msg[0] = (length & 0xff) + 7; |
| 346 | hw_buffer->msg[1] = 0x40; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 347 | hw_buffer->msg[2] = 0x03; |
| 348 | hw_buffer->msg[3] = 0x00; |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 349 | hw_buffer->msg[4] = 0x03; |
| 350 | hw_buffer->msg[5] = length & 0xff; |
| 351 | hw_buffer->msg[6] = 0x00; |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 352 | |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 353 | /* |
| 354 | * Need to compute length for EN50221 section 8.3.2, for the time being |
| 355 | * assuming 8.3.2 is not applicable |
| 356 | */ |
| 357 | memcpy(&hw_buffer->msg[7], &p_ca_message->msg[4], length); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 358 | } |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 359 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 363 | static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 364 | { |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 365 | if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 366 | dprintk(verbose, DST_CA_ERROR, 1, " DST-CI Command failed."); |
| 367 | dprintk(verbose, DST_CA_NOTICE, 1, " Resetting DST."); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 368 | rdc_reset_state(state); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 369 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 370 | } |
Henrik Sjoberg | 1f19456 | 2006-06-21 16:33:21 -0300 | [diff] [blame] | 371 | dprintk(verbose, DST_CA_NOTICE, 1, " DST-CI Command success."); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 376 | static u32 asn_1_decode(u8 *asn_1_array) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 377 | { |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 378 | u8 length_field = 0, word_count = 0, count = 0; |
| 379 | u32 length = 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 380 | |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 381 | length_field = asn_1_array[0]; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 382 | dprintk(verbose, DST_CA_DEBUG, 1, " Length field=[%02x]", length_field); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 383 | if (length_field < 0x80) { |
| 384 | length = length_field & 0x7f; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 385 | dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%02x]\n", length); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 386 | } else { |
| 387 | word_count = length_field & 0x7f; |
| 388 | for (count = 0; count < word_count; count++) { |
Raymond Mantchala | 93a14f1 | 2005-11-08 21:35:17 -0800 | [diff] [blame] | 389 | length = length << 8; |
| 390 | length += asn_1_array[count + 1]; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 391 | dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 394 | return length; |
| 395 | } |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 396 | |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 397 | static int debug_string(u8 *msg, u32 length, u32 offset) |
| 398 | { |
| 399 | u32 i; |
| 400 | |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 401 | dprintk(verbose, DST_CA_DEBUG, 0, " String=[ "); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 402 | for (i = offset; i < length; i++) |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 403 | dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]); |
| 404 | dprintk(verbose, DST_CA_DEBUG, 0, "]\n"); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Manu Abraham | 3e357fd | 2006-06-21 15:06:49 -0300 | [diff] [blame] | 409 | |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 410 | static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query) |
| 411 | { |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 412 | u32 length = 0; |
| 413 | u8 tag_length = 8; |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 414 | |
| 415 | length = asn_1_decode(&p_ca_message->msg[3]); |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 416 | dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length); |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 417 | debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */ |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 418 | |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 419 | memset(hw_buffer->msg, '\0', length); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 420 | handle_dst_tag(state, p_ca_message, hw_buffer, length); |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 421 | put_checksum(hw_buffer->msg, hw_buffer->msg[0]); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 422 | |
Manu Abraham | 94b7410 | 2005-09-09 13:02:59 -0700 | [diff] [blame] | 423 | debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */ |
| 424 | write_to_8820(state, hw_buffer, (length + tag_length), reply); |
Manu Abraham | 7d53421 | 2005-07-07 17:57:50 -0700 | [diff] [blame] | 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 430 | /* Board supports CA PMT reply ? */ |
| 431 | static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) |
| 432 | { |
| 433 | int ca_pmt_reply_test = 0; |
| 434 | |
| 435 | /* Do test board */ |
| 436 | /* Not there yet but soon */ |
| 437 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 438 | /* CA PMT Reply capable */ |
| 439 | if (ca_pmt_reply_test) { |
| 440 | if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 441 | dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 442 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /* Process CA PMT Reply */ |
| 446 | /* will implement soon */ |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 447 | dprintk(verbose, DST_CA_ERROR, 1, " Not there yet"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 448 | } |
| 449 | /* CA PMT Reply not capable */ |
| 450 | if (!ca_pmt_reply_test) { |
| 451 | if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 452 | dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 453 | return -EIO; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 454 | } |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 455 | dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !"); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 456 | /* put a dummy message */ |
| 457 | |
| 458 | } |
| 459 | return 0; |
| 460 | } |
| 461 | |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 462 | static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 463 | { |
Markus Elfring | 8726650 | 2016-12-10 17:56:04 -0200 | [diff] [blame] | 464 | int i; |
| 465 | u32 command; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 466 | struct ca_msg *hw_buffer; |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 467 | int result = 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 468 | |
Markus Elfring | 6e531f1 | 2016-12-10 17:50:58 -0200 | [diff] [blame] | 469 | hw_buffer = kmalloc(sizeof(*hw_buffer), GFP_KERNEL); |
| 470 | if (!hw_buffer) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 471 | return -ENOMEM; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 472 | dprintk(verbose, DST_CA_DEBUG, 1, " "); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 473 | |
Al Viro | 9429917 | 2005-12-15 09:18:45 +0000 | [diff] [blame] | 474 | if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) { |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 475 | result = -EFAULT; |
| 476 | goto free_mem_and_exit; |
| 477 | } |
| 478 | |
Mauro Carvalho Chehab | c65171c | 2015-06-05 08:35:09 -0300 | [diff] [blame] | 479 | /* EN50221 tag */ |
| 480 | command = 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 481 | |
Mauro Carvalho Chehab | c65171c | 2015-06-05 08:35:09 -0300 | [diff] [blame] | 482 | for (i = 0; i < 3; i++) { |
| 483 | command = command | p_ca_message->msg[i]; |
| 484 | if (i < 2) |
| 485 | command = command << 8; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 486 | } |
Mauro Carvalho Chehab | c65171c | 2015-06-05 08:35:09 -0300 | [diff] [blame] | 487 | dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command); |
| 488 | |
| 489 | switch (command) { |
| 490 | case CA_PMT: |
| 491 | dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT"); |
| 492 | if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started |
| 493 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !"); |
| 494 | result = -1; |
| 495 | goto free_mem_and_exit; |
| 496 | } |
| 497 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !"); |
| 498 | break; |
| 499 | case CA_PMT_REPLY: |
| 500 | dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY"); |
| 501 | /* Have to handle the 2 basic types of cards here */ |
| 502 | if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) { |
| 503 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !"); |
| 504 | result = -1; |
| 505 | goto free_mem_and_exit; |
| 506 | } |
| 507 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !"); |
| 508 | break; |
| 509 | case CA_APP_INFO_ENQUIRY: // only for debugging |
| 510 | dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information"); |
| 511 | |
| 512 | if ((ca_get_app_info(state)) < 0) { |
| 513 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !"); |
| 514 | result = -1; |
| 515 | goto free_mem_and_exit; |
| 516 | } |
| 517 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !"); |
| 518 | break; |
| 519 | case CA_INFO_ENQUIRY: |
| 520 | dprintk(verbose, DST_CA_INFO, 1, " Getting CA Information"); |
| 521 | |
| 522 | if ((ca_get_ca_info(state)) < 0) { |
| 523 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_INFO_ENQUIRY Failed !"); |
| 524 | result = -1; |
| 525 | goto free_mem_and_exit; |
| 526 | } |
| 527 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_INFO_ENQUIRY Success !"); |
| 528 | break; |
| 529 | } |
| 530 | |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 531 | free_mem_and_exit: |
| 532 | kfree (hw_buffer); |
| 533 | |
| 534 | return result; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Stoyan Gaydarov | 5ed2b64 | 2009-03-24 18:12:47 -0300 | [diff] [blame] | 537 | static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioctl_arg) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 538 | { |
Hans Verkuil | ce18c48 | 2009-03-28 09:35:40 -0300 | [diff] [blame] | 539 | struct dvb_device *dvbdev; |
| 540 | struct dst_state *state; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 541 | struct ca_slot_info *p_ca_slot_info; |
| 542 | struct ca_caps *p_ca_caps; |
| 543 | struct ca_msg *p_ca_message; |
Peter Hagervall | 174f80d | 2005-11-08 21:35:18 -0800 | [diff] [blame] | 544 | void __user *arg = (void __user *)ioctl_arg; |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 545 | int result = 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 546 | |
Arnd Bergmann | adfedd2 | 2010-09-11 19:53:25 +0200 | [diff] [blame] | 547 | mutex_lock(&dst_ca_mutex); |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 548 | dvbdev = file->private_data; |
Hans Verkuil | ce18c48 | 2009-03-28 09:35:40 -0300 | [diff] [blame] | 549 | state = (struct dst_state *)dvbdev->priv; |
Mauro Carvalho Chehab | b57e557 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 550 | p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL); |
| 551 | p_ca_slot_info = kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL); |
| 552 | p_ca_caps = kmalloc(sizeof (struct ca_caps), GFP_KERNEL); |
| 553 | if (!p_ca_message || !p_ca_slot_info || !p_ca_caps) { |
Mauro Carvalho Chehab | b57e557 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 554 | result = -ENOMEM; |
| 555 | goto free_mem_and_exit; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 556 | } |
Mauro Carvalho Chehab | b57e557 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 557 | |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 558 | /* We have now only the standard ioctl's, the driver is upposed to handle internals. */ |
| 559 | switch (cmd) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 560 | case CA_SEND_MSG: |
| 561 | dprintk(verbose, DST_CA_INFO, 1, " Sending message"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 562 | result = ca_send_message(state, p_ca_message, arg); |
| 563 | |
| 564 | if (result < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 565 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !"); |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 566 | goto free_mem_and_exit; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 567 | } |
| 568 | break; |
| 569 | case CA_GET_MSG: |
| 570 | dprintk(verbose, DST_CA_INFO, 1, " Getting message"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 571 | result = ca_get_message(state, p_ca_message, arg); |
| 572 | if (result < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 573 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !"); |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 574 | goto free_mem_and_exit; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 575 | } |
| 576 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !"); |
| 577 | break; |
| 578 | case CA_RESET: |
| 579 | dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST"); |
| 580 | dst_error_bailout(state); |
| 581 | msleep(4000); |
| 582 | break; |
| 583 | case CA_GET_SLOT_INFO: |
| 584 | dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 585 | result = ca_get_slot_info(state, p_ca_slot_info, arg); |
| 586 | if (result < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 587 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !"); |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 588 | result = -1; |
| 589 | goto free_mem_and_exit; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 590 | } |
| 591 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !"); |
| 592 | break; |
| 593 | case CA_GET_CAP: |
| 594 | dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 595 | result = ca_get_slot_caps(state, p_ca_caps, arg); |
| 596 | if (result < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 597 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !"); |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 598 | goto free_mem_and_exit; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 599 | } |
| 600 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !"); |
| 601 | break; |
| 602 | case CA_GET_DESCR_INFO: |
| 603 | dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description"); |
Mauro Carvalho Chehab | 39a7c8a | 2017-09-01 08:21:04 -0400 | [diff] [blame] | 604 | result = ca_get_slot_descr(state, p_ca_message, arg); |
| 605 | if (result < 0) { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 606 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !"); |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 607 | goto free_mem_and_exit; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 608 | } |
| 609 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !"); |
| 610 | break; |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 611 | default: |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 612 | result = -EOPNOTSUPP; |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 613 | } |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 614 | free_mem_and_exit: |
| 615 | kfree (p_ca_message); |
| 616 | kfree (p_ca_slot_info); |
| 617 | kfree (p_ca_caps); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 618 | |
Arnd Bergmann | adfedd2 | 2010-09-11 19:53:25 +0200 | [diff] [blame] | 619 | mutex_unlock(&dst_ca_mutex); |
Perceval Anichini | f630558 | 2005-11-08 21:35:19 -0800 | [diff] [blame] | 620 | return result; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static int dst_ca_open(struct inode *inode, struct file *file) |
| 624 | { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 625 | dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | static int dst_ca_release(struct inode *inode, struct file *file) |
| 631 | { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 632 | dprintk(verbose, DST_CA_DEBUG, 1, " Device closed."); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
Al Viro | 9429917 | 2005-12-15 09:18:45 +0000 | [diff] [blame] | 637 | static ssize_t dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 638 | { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 639 | dprintk(verbose, DST_CA_DEBUG, 1, " Device read."); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 640 | |
Mauro Carvalho Chehab | a896dc7 | 2014-09-03 15:30:41 -0300 | [diff] [blame] | 641 | return 0; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Al Viro | 9429917 | 2005-12-15 09:18:45 +0000 | [diff] [blame] | 644 | static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 645 | { |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 646 | dprintk(verbose, DST_CA_DEBUG, 1, " Device write."); |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
Jan Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 651 | static const struct file_operations dst_ca_fops = { |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 652 | .owner = THIS_MODULE, |
Stoyan Gaydarov | 5ed2b64 | 2009-03-24 18:12:47 -0300 | [diff] [blame] | 653 | .unlocked_ioctl = dst_ca_ioctl, |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 654 | .open = dst_ca_open, |
| 655 | .release = dst_ca_release, |
| 656 | .read = dst_ca_read, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 657 | .write = dst_ca_write, |
| 658 | .llseek = noop_llseek, |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | static struct dvb_device dvbdev_ca = { |
| 662 | .priv = NULL, |
| 663 | .users = 1, |
| 664 | .readers = 1, |
| 665 | .writers = 1, |
| 666 | .fops = &dst_ca_fops |
| 667 | }; |
| 668 | |
Manu Abraham | bbdd11f | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 669 | struct dvb_device *dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter) |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 670 | { |
| 671 | struct dvb_device *dvbdev; |
Manu Abraham | bbdd11f | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 672 | |
Manu Abraham | a427de6 | 2005-09-09 13:03:00 -0700 | [diff] [blame] | 673 | dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device"); |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 674 | if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, |
| 675 | DVB_DEVICE_CA, 0) == 0) { |
Manu Abraham | bbdd11f | 2006-08-08 15:48:08 -0300 | [diff] [blame] | 676 | dst->dst_ca = dvbdev; |
| 677 | return dst->dst_ca; |
| 678 | } |
| 679 | |
| 680 | return NULL; |
Johannes Stezenbach | 50b215a | 2005-05-16 21:54:41 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | EXPORT_SYMBOL(dst_ca_attach); |
| 684 | |
| 685 | MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver"); |
| 686 | MODULE_AUTHOR("Manu Abraham"); |
| 687 | MODULE_LICENSE("GPL"); |