dst_ca.c 18 KB

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