dst_ca.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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 __user *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(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 __user *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 __user *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(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 __user *arg)
  201. {
  202. u8 i = 0;
  203. u32 command = 0;
  204. if (copy_from_user(p_ca_message, 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(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. static 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 << 8;
  273. length += asn_1_array[count + 1];
  274. dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length);
  275. }
  276. }
  277. return length;
  278. }
  279. static int debug_string(u8 *msg, u32 length, u32 offset)
  280. {
  281. u32 i;
  282. dprintk(verbose, DST_CA_DEBUG, 0, " String=[ ");
  283. for (i = offset; i < length; i++)
  284. dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]);
  285. dprintk(verbose, DST_CA_DEBUG, 0, "]\n");
  286. return 0;
  287. }
  288. static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
  289. {
  290. u32 length = 0;
  291. u8 tag_length = 8;
  292. length = asn_1_decode(&p_ca_message->msg[3]);
  293. dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length);
  294. debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */
  295. memset(hw_buffer->msg, '\0', length);
  296. handle_dst_tag(state, p_ca_message, hw_buffer, length);
  297. put_checksum(hw_buffer->msg, hw_buffer->msg[0]);
  298. debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */
  299. write_to_8820(state, hw_buffer, (length + tag_length), reply);
  300. return 0;
  301. }
  302. /* Board supports CA PMT reply ? */
  303. static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
  304. {
  305. int ca_pmt_reply_test = 0;
  306. /* Do test board */
  307. /* Not there yet but soon */
  308. /* CA PMT Reply capable */
  309. if (ca_pmt_reply_test) {
  310. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
  311. dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
  312. return -1;
  313. }
  314. /* Process CA PMT Reply */
  315. /* will implement soon */
  316. dprintk(verbose, DST_CA_ERROR, 1, " Not there yet");
  317. }
  318. /* CA PMT Reply not capable */
  319. if (!ca_pmt_reply_test) {
  320. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
  321. dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
  322. return -1;
  323. }
  324. dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !");
  325. /* put a dummy message */
  326. }
  327. return 0;
  328. }
  329. static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void __user *arg)
  330. {
  331. int i = 0;
  332. unsigned int ca_message_header_len;
  333. u32 command = 0;
  334. struct ca_msg *hw_buffer;
  335. int result = 0;
  336. if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  337. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  338. return -ENOMEM;
  339. }
  340. dprintk(verbose, DST_CA_DEBUG, 1, " ");
  341. if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg))) {
  342. result = -EFAULT;
  343. goto free_mem_and_exit;
  344. }
  345. if (p_ca_message->msg) {
  346. ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
  347. /* EN50221 tag */
  348. command = 0;
  349. for (i = 0; i < 3; i++) {
  350. command = command | p_ca_message->msg[i];
  351. if (i < 2)
  352. command = command << 8;
  353. }
  354. dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);
  355. switch (command) {
  356. case CA_PMT:
  357. dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");
  358. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
  359. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");
  360. result = -1;
  361. goto free_mem_and_exit;
  362. }
  363. dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");
  364. break;
  365. case CA_PMT_REPLY:
  366. dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");
  367. /* Have to handle the 2 basic types of cards here */
  368. if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
  369. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");
  370. result = -1;
  371. goto free_mem_and_exit;
  372. }
  373. dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
  374. break;
  375. case CA_APP_INFO_ENQUIRY: // only for debugging
  376. dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
  377. if ((ca_get_app_info(state)) < 0) {
  378. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
  379. result = -1;
  380. goto free_mem_and_exit;
  381. }
  382. dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
  383. break;
  384. }
  385. }
  386. free_mem_and_exit:
  387. kfree (hw_buffer);
  388. return result;
  389. }
  390. static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg)
  391. {
  392. struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
  393. struct dst_state* state = (struct dst_state*) dvbdev->priv;
  394. struct ca_slot_info *p_ca_slot_info;
  395. struct ca_caps *p_ca_caps;
  396. struct ca_msg *p_ca_message;
  397. void __user *arg = (void __user *)ioctl_arg;
  398. int result = 0;
  399. if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  400. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  401. return -ENOMEM;
  402. }
  403. if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
  404. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  405. return -ENOMEM;
  406. }
  407. if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
  408. dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
  409. return -ENOMEM;
  410. }
  411. /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
  412. switch (cmd) {
  413. case CA_SEND_MSG:
  414. dprintk(verbose, DST_CA_INFO, 1, " Sending message");
  415. if ((ca_send_message(state, p_ca_message, arg)) < 0) {
  416. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");
  417. result = -1;
  418. goto free_mem_and_exit;
  419. }
  420. break;
  421. case CA_GET_MSG:
  422. dprintk(verbose, DST_CA_INFO, 1, " Getting message");
  423. if ((ca_get_message(state, p_ca_message, arg)) < 0) {
  424. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");
  425. result = -1;
  426. goto free_mem_and_exit;
  427. }
  428. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");
  429. break;
  430. case CA_RESET:
  431. dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");
  432. dst_error_bailout(state);
  433. msleep(4000);
  434. break;
  435. case CA_GET_SLOT_INFO:
  436. dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");
  437. if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
  438. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");
  439. result = -1;
  440. goto free_mem_and_exit;
  441. }
  442. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");
  443. break;
  444. case CA_GET_CAP:
  445. dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");
  446. if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
  447. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");
  448. result = -1;
  449. goto free_mem_and_exit;
  450. }
  451. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");
  452. break;
  453. case CA_GET_DESCR_INFO:
  454. dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");
  455. if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
  456. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");
  457. result = -1;
  458. goto free_mem_and_exit;
  459. }
  460. dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");
  461. break;
  462. case CA_SET_DESCR:
  463. dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");
  464. if ((ca_set_slot_descr()) < 0) {
  465. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");
  466. result = -1;
  467. goto free_mem_and_exit;
  468. }
  469. dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");
  470. break;
  471. case CA_SET_PID:
  472. dprintk(verbose, DST_CA_INFO, 1, " Setting PID");
  473. if ((ca_set_pid()) < 0) {
  474. dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");
  475. result = -1;
  476. goto free_mem_and_exit;
  477. }
  478. dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");
  479. default:
  480. result = -EOPNOTSUPP;
  481. };
  482. free_mem_and_exit:
  483. kfree (p_ca_message);
  484. kfree (p_ca_slot_info);
  485. kfree (p_ca_caps);
  486. return result;
  487. }
  488. static int dst_ca_open(struct inode *inode, struct file *file)
  489. {
  490. dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file);
  491. try_module_get(THIS_MODULE);
  492. return 0;
  493. }
  494. static int dst_ca_release(struct inode *inode, struct file *file)
  495. {
  496. dprintk(verbose, DST_CA_DEBUG, 1, " Device closed.");
  497. module_put(THIS_MODULE);
  498. return 0;
  499. }
  500. static int dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
  501. {
  502. int bytes_read = 0;
  503. dprintk(verbose, DST_CA_DEBUG, 1, " Device read.");
  504. return bytes_read;
  505. }
  506. static int dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)
  507. {
  508. dprintk(verbose, DST_CA_DEBUG, 1, " Device write.");
  509. return 0;
  510. }
  511. static struct file_operations dst_ca_fops = {
  512. .owner = THIS_MODULE,
  513. .ioctl = dst_ca_ioctl,
  514. .open = dst_ca_open,
  515. .release = dst_ca_release,
  516. .read = dst_ca_read,
  517. .write = dst_ca_write
  518. };
  519. static struct dvb_device dvbdev_ca = {
  520. .priv = NULL,
  521. .users = 1,
  522. .readers = 1,
  523. .writers = 1,
  524. .fops = &dst_ca_fops
  525. };
  526. int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
  527. {
  528. struct dvb_device *dvbdev;
  529. dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
  530. dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
  531. return 0;
  532. }
  533. EXPORT_SYMBOL(dst_ca_attach);
  534. MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
  535. MODULE_AUTHOR("Manu Abraham");
  536. MODULE_LICENSE("GPL");