dst_ca.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. }
  238. else {
  239. hw_buffer->msg[0] = (length & 0xff) + 7;
  240. hw_buffer->msg[1] = 0x40;
  241. hw_buffer->msg[2] = 0x03;
  242. hw_buffer->msg[3] = 0x00;
  243. hw_buffer->msg[4] = 0x03;
  244. hw_buffer->msg[5] = length & 0xff;
  245. hw_buffer->msg[6] = 0x00;
  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("%s: DST-CI Command failed.\n", __FUNCTION__);
  253. dprintk("%s: Resetting DST.\n", __FUNCTION__);
  254. rdc_reset_state(state);
  255. return -1;
  256. }
  257. if (verbose > 2)
  258. dprintk("%s: DST-CI Command succes.\n", __FUNCTION__);
  259. return 0;
  260. }
  261. u32 asn_1_decode(u8 *asn_1_array)
  262. {
  263. u8 length_field = 0, word_count = 0, count = 0;
  264. u32 length = 0;
  265. length_field = asn_1_array[0];
  266. dprintk("%s: Length field=[%02x]\n", __FUNCTION__, length_field);
  267. if (length_field < 0x80) {
  268. length = length_field & 0x7f;
  269. dprintk("%s: Length=[%02x]\n", __FUNCTION__, length);
  270. } else {
  271. word_count = length_field & 0x7f;
  272. for (count = 0; count < word_count; count++) {
  273. length = (length | asn_1_array[count + 1]) << 8;
  274. dprintk("%s: Length=[%04x]\n", __FUNCTION__, length);
  275. }
  276. }
  277. return length;
  278. }
  279. static int init_buffer(u8 *buffer, u32 length)
  280. {
  281. u32 i;
  282. for (i = 0; i < length; i++)
  283. buffer[i] = 0;
  284. return 0;
  285. }
  286. static int debug_string(u8 *msg, u32 length, u32 offset)
  287. {
  288. u32 i;
  289. dprintk(" String=[ ");
  290. for (i = offset; i < length; i++)
  291. dprintk("%02x ", msg[i]);
  292. dprintk("]\n");
  293. return 0;
  294. }
  295. static int copy_string(u8 *destination, u8 *source, u32 dest_offset, u32 source_offset, u32 length)
  296. {
  297. u32 i;
  298. dprintk("%s: Copying [", __FUNCTION__);
  299. for (i = 0; i < length; i++) {
  300. destination[i + dest_offset] = source[i + source_offset];
  301. dprintk(" %02x", source[i + source_offset]);
  302. }
  303. dprintk("]\n");
  304. return i;
  305. }
  306. static int modify_4_bits(u8 *message, u32 pos)
  307. {
  308. message[pos] &= 0x0f;
  309. return 0;
  310. }
  311. static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
  312. {
  313. u32 length = 0, count = 0;
  314. u8 asn_1_words, program_header_length;
  315. u16 program_info_length = 0, es_info_length = 0;
  316. u32 hw_offset = 0, buf_offset = 0, i;
  317. u8 dst_tag_length;
  318. length = asn_1_decode(&p_ca_message->msg[3]);
  319. dprintk("%s: CA Message length=[%d]\n", __FUNCTION__, length);
  320. dprintk("%s: ASN.1 ", __FUNCTION__);
  321. debug_string(&p_ca_message->msg[4], length, 0); // length does not include tag and length
  322. init_buffer(hw_buffer->msg, length);
  323. handle_dst_tag(state, p_ca_message, hw_buffer, length);
  324. hw_offset = 7;
  325. asn_1_words = 1; // just a hack to test, should compute this one
  326. buf_offset = 3;
  327. program_header_length = 6;
  328. dst_tag_length = 7;
  329. // debug_twinhan_ca_params(state, p_ca_message, hw_buffer, reply, query, length, hw_offset, buf_offset);
  330. // dprintk("%s: Program Header(BUF)", __FUNCTION__);
  331. // debug_string(&p_ca_message->msg[4], program_header_length, 0);
  332. // dprintk("%s: Copying Program header\n", __FUNCTION__);
  333. copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + asn_1_words), program_header_length);
  334. buf_offset += program_header_length, hw_offset += program_header_length;
  335. modify_4_bits(hw_buffer->msg, (hw_offset - 2));
  336. if (state->type_flags & DST_TYPE_HAS_INC_COUNT) { // workaround
  337. dprintk("%s: Probably an ASIC bug !!!\n", __FUNCTION__);
  338. debug_string(hw_buffer->msg, (hw_offset + program_header_length), 0);
  339. hw_buffer->msg[hw_offset - 1] += 1;
  340. }
  341. // dprintk("%s: Program Header(HW), Count=[%d]", __FUNCTION__, count);
  342. // debug_string(hw_buffer->msg, hw_offset, 0);
  343. program_info_length = ((program_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
  344. dprintk("%s: Program info length=[%02x]\n", __FUNCTION__, program_info_length);
  345. if (program_info_length) {
  346. count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + 1), (program_info_length + 1) ); // copy next elem, not current
  347. buf_offset += count, hw_offset += count;
  348. // dprintk("%s: Program level ", __FUNCTION__);
  349. // debug_string(hw_buffer->msg, hw_offset, 0);
  350. }
  351. buf_offset += 1;// hw_offset += 1;
  352. for (i = buf_offset; i < length; i++) {
  353. // dprintk("%s: Stream Header ", __FUNCTION__);
  354. count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, buf_offset, 5);
  355. modify_4_bits(hw_buffer->msg, (hw_offset + 3));
  356. hw_offset += 5, buf_offset += 5, i += 4;
  357. // debug_string(hw_buffer->msg, hw_offset, (hw_offset - 5));
  358. es_info_length = ((es_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
  359. dprintk("%s: ES info length=[%02x]\n", __FUNCTION__, es_info_length);
  360. if (es_info_length) {
  361. // copy descriptors @ STREAM level
  362. dprintk("%s: Descriptors @ STREAM level...!!! \n", __FUNCTION__);
  363. }
  364. }
  365. hw_buffer->msg[length + dst_tag_length] = dst_check_sum(hw_buffer->msg, (length + dst_tag_length));
  366. // dprintk("%s: Total length=[%d], Checksum=[%02x]\n", __FUNCTION__, (length + dst_tag_length), hw_buffer->msg[length + dst_tag_length]);
  367. debug_string(hw_buffer->msg, (length + dst_tag_length + 1), 0); // dst tags also
  368. write_to_8820(state, hw_buffer, (length + dst_tag_length + 1), reply); // checksum
  369. return 0;
  370. }
  371. /* Board supports CA PMT reply ? */
  372. static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
  373. {
  374. int ca_pmt_reply_test = 0;
  375. /* Do test board */
  376. /* Not there yet but soon */
  377. /* CA PMT Reply capable */
  378. if (ca_pmt_reply_test) {
  379. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
  380. dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__);
  381. return -1;
  382. }
  383. /* Process CA PMT Reply */
  384. /* will implement soon */
  385. dprintk("%s: Not there yet\n", __FUNCTION__);
  386. }
  387. /* CA PMT Reply not capable */
  388. if (!ca_pmt_reply_test) {
  389. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
  390. dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__);
  391. return -1;
  392. }
  393. if (verbose > 3)
  394. dprintk("%s: ca_set_pmt.. success !\n", __FUNCTION__);
  395. /* put a dummy message */
  396. }
  397. return 0;
  398. }
  399. static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void *arg)
  400. {
  401. int i = 0;
  402. unsigned int ca_message_header_len;
  403. u32 command = 0;
  404. struct ca_msg *hw_buffer;
  405. if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  406. dprintk("%s: Memory allocation failure\n", __FUNCTION__);
  407. return -ENOMEM;
  408. }
  409. if (verbose > 3)
  410. dprintk("%s\n", __FUNCTION__);
  411. if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg)))
  412. return -EFAULT;
  413. if (p_ca_message->msg) {
  414. ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
  415. /* EN50221 tag */
  416. command = 0;
  417. for (i = 0; i < 3; i++) {
  418. command = command | p_ca_message->msg[i];
  419. if (i < 2)
  420. command = command << 8;
  421. }
  422. if (verbose > 3)
  423. dprintk("%s:Command=[0x%x]\n", __FUNCTION__, command);
  424. switch (command) {
  425. case CA_PMT:
  426. if (verbose > 3)
  427. // dprintk("Command = SEND_CA_PMT\n");
  428. dprintk("Command = SEND_CA_PMT\n");
  429. // if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) {
  430. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
  431. dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__);
  432. return -1;
  433. }
  434. if (verbose > 3)
  435. dprintk("%s: -->CA_PMT Success !\n", __FUNCTION__);
  436. // retval = dummy_set_pmt(state, p_ca_message, hw_buffer, 0, 0);
  437. break;
  438. case CA_PMT_REPLY:
  439. if (verbose > 3)
  440. dprintk("Command = CA_PMT_REPLY\n");
  441. /* Have to handle the 2 basic types of cards here */
  442. if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
  443. dprintk("%s: -->CA_PMT_REPLY Failed !\n", __FUNCTION__);
  444. return -1;
  445. }
  446. if (verbose > 3)
  447. dprintk("%s: -->CA_PMT_REPLY Success !\n", __FUNCTION__);
  448. /* Certain boards do behave different ? */
  449. // retval = ca_set_pmt(state, p_ca_message, hw_buffer, 1, 1);
  450. case CA_APP_INFO_ENQUIRY: // only for debugging
  451. if (verbose > 3)
  452. dprintk("%s: Getting Cam Application information\n", __FUNCTION__);
  453. if ((ca_get_app_info(state)) < 0) {
  454. dprintk("%s: -->CA_APP_INFO_ENQUIRY Failed !\n", __FUNCTION__);
  455. return -1;
  456. }
  457. if (verbose > 3)
  458. dprintk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
  459. break;
  460. }
  461. }
  462. return 0;
  463. }
  464. static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg)
  465. {
  466. struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
  467. struct dst_state* state = (struct dst_state*) dvbdev->priv;
  468. struct ca_slot_info *p_ca_slot_info;
  469. struct ca_caps *p_ca_caps;
  470. struct ca_msg *p_ca_message;
  471. if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  472. dprintk("%s: Memory allocation failure\n", __FUNCTION__);
  473. return -ENOMEM;
  474. }
  475. if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
  476. dprintk("%s: Memory allocation failure\n", __FUNCTION__);
  477. return -ENOMEM;
  478. }
  479. if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
  480. dprintk("%s: Memory allocation failure\n", __FUNCTION__);
  481. return -ENOMEM;
  482. }
  483. /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
  484. switch (cmd) {
  485. case CA_SEND_MSG:
  486. if (verbose > 1)
  487. dprintk("%s: Sending message\n", __FUNCTION__);
  488. if ((ca_send_message(state, p_ca_message, arg)) < 0) {
  489. dprintk("%s: -->CA_SEND_MSG Failed !\n", __FUNCTION__);
  490. return -1;
  491. }
  492. break;
  493. case CA_GET_MSG:
  494. if (verbose > 1)
  495. dprintk("%s: Getting message\n", __FUNCTION__);
  496. if ((ca_get_message(state, p_ca_message, arg)) < 0) {
  497. dprintk("%s: -->CA_GET_MSG Failed !\n", __FUNCTION__);
  498. return -1;
  499. }
  500. if (verbose > 1)
  501. dprintk("%s: -->CA_GET_MSG Success !\n", __FUNCTION__);
  502. break;
  503. case CA_RESET:
  504. if (verbose > 1)
  505. dprintk("%s: Resetting DST\n", __FUNCTION__);
  506. dst_error_bailout(state);
  507. msleep(4000);
  508. break;
  509. case CA_GET_SLOT_INFO:
  510. if (verbose > 1)
  511. dprintk("%s: Getting Slot info\n", __FUNCTION__);
  512. if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
  513. dprintk("%s: -->CA_GET_SLOT_INFO Failed !\n", __FUNCTION__);
  514. return -1;
  515. }
  516. if (verbose > 1)
  517. dprintk("%s: -->CA_GET_SLOT_INFO Success !\n", __FUNCTION__);
  518. break;
  519. case CA_GET_CAP:
  520. if (verbose > 1)
  521. dprintk("%s: Getting Slot capabilities\n", __FUNCTION__);
  522. if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
  523. dprintk("%s: -->CA_GET_CAP Failed !\n", __FUNCTION__);
  524. return -1;
  525. }
  526. if (verbose > 1)
  527. dprintk("%s: -->CA_GET_CAP Success !\n", __FUNCTION__);
  528. break;
  529. case CA_GET_DESCR_INFO:
  530. if (verbose > 1)
  531. dprintk("%s: Getting descrambler description\n", __FUNCTION__);
  532. if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
  533. dprintk("%s: -->CA_GET_DESCR_INFO Failed !\n", __FUNCTION__);
  534. return -1;
  535. }
  536. if (verbose > 1)
  537. dprintk("%s: -->CA_GET_DESCR_INFO Success !\n", __FUNCTION__);
  538. break;
  539. case CA_SET_DESCR:
  540. if (verbose > 1)
  541. dprintk("%s: Setting descrambler\n", __FUNCTION__);
  542. if ((ca_set_slot_descr()) < 0) {
  543. dprintk("%s: -->CA_SET_DESCR Failed !\n", __FUNCTION__);
  544. return -1;
  545. }
  546. if (verbose > 1)
  547. dprintk("%s: -->CA_SET_DESCR Success !\n", __FUNCTION__);
  548. break;
  549. case CA_SET_PID:
  550. if (verbose > 1)
  551. dprintk("%s: Setting PID\n", __FUNCTION__);
  552. if ((ca_set_pid()) < 0) {
  553. dprintk("%s: -->CA_SET_PID Failed !\n", __FUNCTION__);
  554. return -1;
  555. }
  556. if (verbose > 1)
  557. dprintk("%s: -->CA_SET_PID Success !\n", __FUNCTION__);
  558. default:
  559. return -EOPNOTSUPP;
  560. };
  561. return 0;
  562. }
  563. static int dst_ca_open(struct inode *inode, struct file *file)
  564. {
  565. if (verbose > 4)
  566. dprintk("%s:Device opened [%p]\n", __FUNCTION__, file);
  567. try_module_get(THIS_MODULE);
  568. return 0;
  569. }
  570. static int dst_ca_release(struct inode *inode, struct file *file)
  571. {
  572. if (verbose > 4)
  573. dprintk("%s:Device closed.\n", __FUNCTION__);
  574. module_put(THIS_MODULE);
  575. return 0;
  576. }
  577. static int dst_ca_read(struct file *file, char __user * buffer, size_t length, loff_t * offset)
  578. {
  579. int bytes_read = 0;
  580. if (verbose > 4)
  581. dprintk("%s:Device read.\n", __FUNCTION__);
  582. return bytes_read;
  583. }
  584. static int dst_ca_write(struct file *file, const char __user * buffer, size_t length, loff_t * offset)
  585. {
  586. if (verbose > 4)
  587. dprintk("%s:Device write.\n", __FUNCTION__);
  588. return 0;
  589. }
  590. static struct file_operations dst_ca_fops = {
  591. .owner = THIS_MODULE,
  592. .ioctl = (void *)dst_ca_ioctl,
  593. .open = dst_ca_open,
  594. .release = dst_ca_release,
  595. .read = dst_ca_read,
  596. .write = dst_ca_write
  597. };
  598. static struct dvb_device dvbdev_ca = {
  599. .priv = NULL,
  600. .users = 1,
  601. .readers = 1,
  602. .writers = 1,
  603. .fops = &dst_ca_fops
  604. };
  605. int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
  606. {
  607. struct dvb_device *dvbdev;
  608. if (verbose > 4)
  609. dprintk("%s:registering DST-CA device\n", __FUNCTION__);
  610. dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
  611. return 0;
  612. }
  613. EXPORT_SYMBOL(dst_ca_attach);
  614. MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
  615. MODULE_AUTHOR("Manu Abraham");
  616. MODULE_LICENSE("GPL");