dst_ca.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. CA-driver for TwinHan DST Frontend/Card
  3. Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/string.h>
  20. #include <linux/dvb/ca.h>
  21. #include "dvbdev.h"
  22. #include "dvb_frontend.h"
  23. #include "dst_ca.h"
  24. #include "dst_common.h"
  25. #define DST_CA_ERROR 0
  26. #define DST_CA_NOTICE 1
  27. #define DST_CA_INFO 2
  28. #define DST_CA_DEBUG 3
  29. #define dprintk(x, y, z, format, arg...) do { \
  30. if (z) { \
  31. if ((x > DST_CA_ERROR) && (x > y)) \
  32. printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \
  33. else if ((x > DST_CA_NOTICE) && (x > y)) \
  34. printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \
  35. else if ((x > DST_CA_INFO) && (x > y)) \
  36. printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \
  37. else if ((x > DST_CA_DEBUG) && (x > y)) \
  38. printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \
  39. } else { \
  40. if (x > y) \
  41. printk(format, ## arg); \
  42. } \
  43. } while(0)
  44. static unsigned int verbose = 5;
  45. module_param(verbose, int, 0644);
  46. MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
  47. /* Need some more work */
  48. static int ca_set_slot_descr(void)
  49. {
  50. /* We could make this more graceful ? */
  51. return -EOPNOTSUPP;
  52. }
  53. /* Need some more work */
  54. static int ca_set_pid(void)
  55. {
  56. /* We could make this more graceful ? */
  57. return -EOPNOTSUPP;
  58. }
  59. static void put_checksum(u8 *check_string, int length)
  60. {
  61. dprintk(verbose, DST_CA_DEBUG, 1, " Computing string checksum.");
  62. dprintk(verbose, DST_CA_DEBUG, 1, " -> string length : 0x%02x", length);
  63. check_string[length] = dst_check_sum (check_string, length);
  64. dprintk(verbose, DST_CA_DEBUG, 1, " -> checksum : 0x%02x", check_string[length]);
  65. }
  66. static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8 len, int read)
  67. {
  68. u8 reply;
  69. mutex_lock(&state->dst_mutex);
  70. dst_comm_init(state);
  71. msleep(65);
  72. if (write_dst(state, data, len)) {
  73. dprintk(verbose, DST_CA_INFO, 1, " Write not successful, trying to recover");
  74. dst_error_recovery(state);
  75. goto error;
  76. }
  77. if ((dst_pio_disable(state)) < 0) {
  78. dprintk(verbose, DST_CA_ERROR, 1, " DST PIO disable failed.");
  79. goto error;
  80. }
  81. if (read_dst(state, &reply, GET_ACK) < 0) {
  82. dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
  83. dst_error_recovery(state);
  84. goto error;
  85. }
  86. if (read) {
  87. if (! dst_wait_dst_ready(state, LONG_DELAY)) {
  88. dprintk(verbose, DST_CA_NOTICE, 1, " 8820 not ready");
  89. goto error;
  90. }
  91. if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */
  92. dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
  93. dst_error_recovery(state);
  94. goto error;
  95. }
  96. }
  97. mutex_unlock(&state->dst_mutex);
  98. return 0;
  99. error:
  100. mutex_unlock(&state->dst_mutex);
  101. return -EIO;
  102. }
  103. static int dst_put_ci(struct dst_state *state, u8 *data, int len, u8 *ca_string, int read)
  104. {
  105. u8 dst_ca_comm_err = 0;
  106. while (dst_ca_comm_err < RETRIES) {
  107. dst_comm_init(state);
  108. dprintk(verbose, DST_CA_NOTICE, 1, " Put Command");
  109. if (dst_ci_command(state, data, ca_string, len, read)) { // If error
  110. dst_error_recovery(state);
  111. dst_ca_comm_err++; // work required here.
  112. }
  113. break;
  114. }
  115. return 0;
  116. }
  117. static int ca_get_app_info(struct dst_state *state)
  118. {
  119. static u8 command[8] = {0x07, 0x40, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff};
  120. put_checksum(&command[0], command[0]);
  121. if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) {
  122. dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
  123. return -1;
  124. }
  125. dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
  126. dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================");
  127. dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]",
  128. state->messages[7], (state->messages[8] << 8) | state->messages[9],
  129. (state->messages[10] << 8) | state->messages[11], __FUNCTION__, (char *)(&state->messages[12]));
  130. dprintk(verbose, DST_CA_INFO, 1, " ==================================================================================================");
  131. return 0;
  132. }
  133. static int ca_get_slot_caps(struct dst_state *state, struct ca_caps *p_ca_caps, void __user *arg)
  134. {
  135. int i;
  136. u8 slot_cap[256];
  137. static u8 slot_command[8] = {0x07, 0x40, 0x02, 0x00, 0x02, 0x00, 0x00, 0xff};
  138. put_checksum(&slot_command[0], slot_command[0]);
  139. if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) {
  140. dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
  141. return -1;
  142. }
  143. dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
  144. /* Will implement the rest soon */
  145. dprintk(verbose, DST_CA_INFO, 1, " Slot cap = [%d]", slot_cap[7]);
  146. dprintk(verbose, DST_CA_INFO, 0, "===================================\n");
  147. for (i = 0; i < 8; i++)
  148. dprintk(verbose, DST_CA_INFO, 0, " %d", slot_cap[i]);
  149. dprintk(verbose, DST_CA_INFO, 0, "\n");
  150. p_ca_caps->slot_num = 1;
  151. p_ca_caps->slot_type = 1;
  152. p_ca_caps->descr_num = slot_cap[7];
  153. p_ca_caps->descr_type = 1;
  154. if (copy_to_user(arg, p_ca_caps, sizeof (struct ca_caps)))
  155. return -EFAULT;
  156. return 0;
  157. }
  158. /* Need some more work */
  159. static int ca_get_slot_descr(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
  160. {
  161. return -EOPNOTSUPP;
  162. }
  163. static int ca_get_slot_info(struct dst_state *state, struct ca_slot_info *p_ca_slot_info, void __user *arg)
  164. {
  165. int i;
  166. static u8 slot_command[8] = {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
  167. u8 *slot_info = state->messages;
  168. put_checksum(&slot_command[0], 7);
  169. if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) {
  170. dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
  171. return -1;
  172. }
  173. dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
  174. /* Will implement the rest soon */
  175. dprintk(verbose, DST_CA_INFO, 1, " Slot info = [%d]", slot_info[3]);
  176. dprintk(verbose, DST_CA_INFO, 0, "===================================\n");
  177. for (i = 0; i < 8; i++)
  178. dprintk(verbose, DST_CA_INFO, 0, " %d", slot_info[i]);
  179. dprintk(verbose, DST_CA_INFO, 0, "\n");
  180. if (slot_info[4] & 0x80) {
  181. p_ca_slot_info->flags = CA_CI_MODULE_PRESENT;
  182. p_ca_slot_info->num = 1;
  183. p_ca_slot_info->type = CA_CI;
  184. } else if (slot_info[4] & 0x40) {
  185. p_ca_slot_info->flags = CA_CI_MODULE_READY;
  186. p_ca_slot_info->num = 1;
  187. p_ca_slot_info->type = CA_CI;
  188. } else
  189. p_ca_slot_info->flags = 0;
  190. if (copy_to_user(arg, p_ca_slot_info, sizeof (struct ca_slot_info)))
  191. return -EFAULT;
  192. return 0;
  193. }
  194. static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
  195. {
  196. u8 i = 0;
  197. u32 command = 0;
  198. if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg)))
  199. return -EFAULT;
  200. if (p_ca_message->msg) {
  201. 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]);
  202. for (i = 0; i < 3; i++) {
  203. command = command | p_ca_message->msg[i];
  204. if (i < 2)
  205. command = command << 8;
  206. }
  207. dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);
  208. switch (command) {
  209. case CA_APP_INFO:
  210. memcpy(p_ca_message->msg, state->messages, 128);
  211. if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
  212. return -EFAULT;
  213. break;
  214. }
  215. }
  216. return 0;
  217. }
  218. static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
  219. {
  220. if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
  221. hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
  222. hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
  223. } else {
  224. if (length > 247) {
  225. dprintk(verbose, DST_CA_ERROR, 1, " Message too long ! *** Bailing Out *** !");
  226. return -1;
  227. }
  228. hw_buffer->msg[0] = (length & 0xff) + 7;
  229. hw_buffer->msg[1] = 0x40;
  230. hw_buffer->msg[2] = 0x03;
  231. hw_buffer->msg[3] = 0x00;
  232. hw_buffer->msg[4] = 0x03;
  233. hw_buffer->msg[5] = length & 0xff;
  234. hw_buffer->msg[6] = 0x00;
  235. /*
  236. * Need to compute length for EN50221 section 8.3.2, for the time being
  237. * assuming 8.3.2 is not applicable
  238. */
  239. memcpy(&hw_buffer->msg[7], &p_ca_message->msg[4], length);
  240. }
  241. return 0;
  242. }
  243. static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
  244. {
  245. if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
  246. dprintk(verbose, DST_CA_ERROR, 1, " DST-CI Command failed.");
  247. dprintk(verbose, DST_CA_NOTICE, 1, " Resetting DST.");
  248. rdc_reset_state(state);
  249. return -1;
  250. }
  251. dprintk(verbose, DST_CA_NOTICE, 1, " DST-CI Command succes.");
  252. return 0;
  253. }
  254. static u32 asn_1_decode(u8 *asn_1_array)
  255. {
  256. u8 length_field = 0, word_count = 0, count = 0;
  257. u32 length = 0;
  258. length_field = asn_1_array[0];
  259. dprintk(verbose, DST_CA_DEBUG, 1, " Length field=[%02x]", length_field);
  260. if (length_field < 0x80) {
  261. length = length_field & 0x7f;
  262. dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%02x]\n", length);
  263. } else {
  264. word_count = length_field & 0x7f;
  265. for (count = 0; count < word_count; count++) {
  266. length = length << 8;
  267. length += asn_1_array[count + 1];
  268. dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length);
  269. }
  270. }
  271. return length;
  272. }
  273. static int debug_string(u8 *msg, u32 length, u32 offset)
  274. {
  275. u32 i;
  276. dprintk(verbose, DST_CA_DEBUG, 0, " String=[ ");
  277. for (i = offset; i < length; i++)
  278. dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]);
  279. dprintk(verbose, DST_CA_DEBUG, 0, "]\n");
  280. return 0;
  281. }
  282. static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
  283. {
  284. u32 length = 0;
  285. u8 tag_length = 8;
  286. length = asn_1_decode(&p_ca_message->msg[3]);
  287. dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length);
  288. debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */
  289. memset(hw_buffer->msg, '\0', length);
  290. handle_dst_tag(state, p_ca_message, hw_buffer, length);
  291. put_checksum(hw_buffer->msg, hw_buffer->msg[0]);
  292. debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */
  293. write_to_8820(state, hw_buffer, (length + tag_length), reply);
  294. return 0;
  295. }
  296. /* Board supports CA PMT reply ? */
  297. static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
  298. {
  299. int ca_pmt_reply_test = 0;
  300. /* Do test board */
  301. /* Not there yet but soon */
  302. /* CA PMT Reply capable */
  303. if (ca_pmt_reply_test) {
  304. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
  305. dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
  306. return -1;
  307. }
  308. /* Process CA PMT Reply */
  309. /* will implement soon */
  310. dprintk(verbose, DST_CA_ERROR, 1, " Not there yet");
  311. }
  312. /* CA PMT Reply not capable */
  313. if (!ca_pmt_reply_test) {
  314. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
  315. dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
  316. return -1;
  317. }
  318. dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !");
  319. /* put a dummy message */
  320. }
  321. return 0;
  322. }
  323. static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
  324. {
  325. int i = 0;
  326. unsigned int ca_message_header_len;
  327. u32 command = 0;
  328. struct ca_msg *hw_buffer;
  329. int result = 0;
  330. if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  331. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  332. return -ENOMEM;
  333. }
  334. dprintk(verbose, DST_CA_DEBUG, 1, " ");
  335. if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) {
  336. result = -EFAULT;
  337. goto free_mem_and_exit;
  338. }
  339. if (p_ca_message->msg) {
  340. ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
  341. /* EN50221 tag */
  342. command = 0;
  343. for (i = 0; i < 3; i++) {
  344. command = command | p_ca_message->msg[i];
  345. if (i < 2)
  346. command = command << 8;
  347. }
  348. dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);
  349. switch (command) {
  350. case CA_PMT:
  351. dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");
  352. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
  353. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");
  354. result = -1;
  355. goto free_mem_and_exit;
  356. }
  357. dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");
  358. break;
  359. case CA_PMT_REPLY:
  360. dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");
  361. /* Have to handle the 2 basic types of cards here */
  362. if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
  363. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");
  364. result = -1;
  365. goto free_mem_and_exit;
  366. }
  367. dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
  368. break;
  369. case CA_APP_INFO_ENQUIRY: // only for debugging
  370. dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
  371. if ((ca_get_app_info(state)) < 0) {
  372. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
  373. result = -1;
  374. goto free_mem_and_exit;
  375. }
  376. dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
  377. break;
  378. }
  379. }
  380. free_mem_and_exit:
  381. kfree (hw_buffer);
  382. return result;
  383. }
  384. static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg)
  385. {
  386. struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
  387. struct dst_state* state = (struct dst_state*) dvbdev->priv;
  388. struct ca_slot_info *p_ca_slot_info;
  389. struct ca_caps *p_ca_caps;
  390. struct ca_msg *p_ca_message;
  391. void __user *arg = (void __user *)ioctl_arg;
  392. int result = 0;
  393. if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  394. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  395. return -ENOMEM;
  396. }
  397. if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
  398. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  399. return -ENOMEM;
  400. }
  401. if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
  402. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  403. return -ENOMEM;
  404. }
  405. /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
  406. switch (cmd) {
  407. case CA_SEND_MSG:
  408. dprintk(verbose, DST_CA_INFO, 1, " Sending message");
  409. if ((ca_send_message(state, p_ca_message, arg)) < 0) {
  410. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");
  411. result = -1;
  412. goto free_mem_and_exit;
  413. }
  414. break;
  415. case CA_GET_MSG:
  416. dprintk(verbose, DST_CA_INFO, 1, " Getting message");
  417. if ((ca_get_message(state, p_ca_message, arg)) < 0) {
  418. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");
  419. result = -1;
  420. goto free_mem_and_exit;
  421. }
  422. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");
  423. break;
  424. case CA_RESET:
  425. dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");
  426. dst_error_bailout(state);
  427. msleep(4000);
  428. break;
  429. case CA_GET_SLOT_INFO:
  430. dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");
  431. if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
  432. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");
  433. result = -1;
  434. goto free_mem_and_exit;
  435. }
  436. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");
  437. break;
  438. case CA_GET_CAP:
  439. dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");
  440. if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
  441. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");
  442. result = -1;
  443. goto free_mem_and_exit;
  444. }
  445. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");
  446. break;
  447. case CA_GET_DESCR_INFO:
  448. dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");
  449. if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
  450. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");
  451. result = -1;
  452. goto free_mem_and_exit;
  453. }
  454. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");
  455. break;
  456. case CA_SET_DESCR:
  457. dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");
  458. if ((ca_set_slot_descr()) < 0) {
  459. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");
  460. result = -1;
  461. goto free_mem_and_exit;
  462. }
  463. dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");
  464. break;
  465. case CA_SET_PID:
  466. dprintk(verbose, DST_CA_INFO, 1, " Setting PID");
  467. if ((ca_set_pid()) < 0) {
  468. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");
  469. result = -1;
  470. goto free_mem_and_exit;
  471. }
  472. dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");
  473. default:
  474. result = -EOPNOTSUPP;
  475. };
  476. free_mem_and_exit:
  477. kfree (p_ca_message);
  478. kfree (p_ca_slot_info);
  479. kfree (p_ca_caps);
  480. return result;
  481. }
  482. static int dst_ca_open(struct inode *inode, struct file *file)
  483. {
  484. dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file);
  485. try_module_get(THIS_MODULE);
  486. return 0;
  487. }
  488. static int dst_ca_release(struct inode *inode, struct file *file)
  489. {
  490. dprintk(verbose, DST_CA_DEBUG, 1, " Device closed.");
  491. module_put(THIS_MODULE);
  492. return 0;
  493. }
  494. static ssize_t dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
  495. {
  496. int bytes_read = 0;
  497. dprintk(verbose, DST_CA_DEBUG, 1, " Device read.");
  498. return bytes_read;
  499. }
  500. static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)
  501. {
  502. dprintk(verbose, DST_CA_DEBUG, 1, " Device write.");
  503. return 0;
  504. }
  505. static struct file_operations dst_ca_fops = {
  506. .owner = THIS_MODULE,
  507. .ioctl = dst_ca_ioctl,
  508. .open = dst_ca_open,
  509. .release = dst_ca_release,
  510. .read = dst_ca_read,
  511. .write = dst_ca_write
  512. };
  513. static struct dvb_device dvbdev_ca = {
  514. .priv = NULL,
  515. .users = 1,
  516. .readers = 1,
  517. .writers = 1,
  518. .fops = &dst_ca_fops
  519. };
  520. int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
  521. {
  522. struct dvb_device *dvbdev;
  523. dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
  524. dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
  525. return 0;
  526. }
  527. EXPORT_SYMBOL(dst_ca_attach);
  528. MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
  529. MODULE_AUTHOR("Manu Abraham");
  530. MODULE_LICENSE("GPL");