dst_ca.c 18 KB

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