dst_ca.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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 = 1;
  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_en50221_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
  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[2] = 0x03;
  240. hw_buffer->msg[3] = 0x00;
  241. }
  242. return 0;
  243. }
  244. static int debug_8820_buffer(struct ca_msg *hw_buffer)
  245. {
  246. unsigned int i;
  247. dprintk("%s:Debug=[", __FUNCTION__);
  248. for (i = 0; i < (hw_buffer->msg[0] + 1); i++)
  249. dprintk(" %02x", hw_buffer->msg[i]);
  250. dprintk("]\n");
  251. return 0;
  252. }
  253. static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 reply)
  254. {
  255. if ((dst_put_ci(state, hw_buffer->msg, (hw_buffer->length + 1), hw_buffer->msg, reply)) < 0) {
  256. dprintk("%s: DST-CI Command failed.\n", __FUNCTION__);
  257. dprintk("%s: Resetting DST.\n", __FUNCTION__);
  258. rdc_reset_state(state);
  259. return -1;
  260. }
  261. if (verbose > 2)
  262. dprintk("%s: DST-CI Command succes.\n", __FUNCTION__);
  263. return 0;
  264. }
  265. static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
  266. {
  267. u32 hw_offset, buf_offset, i, k;
  268. u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0;
  269. u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0;
  270. if (verbose > 3)
  271. dprintk("%s, p_ca_message length %d (0x%x)\n", __FUNCTION__,p_ca_message->length,p_ca_message->length );
  272. handle_en50221_tag(state, p_ca_message, hw_buffer); /* EN50221 tag */
  273. /* Handle the length field (variable) */
  274. if (!(p_ca_message->msg[3] & 0x80)) { /* Length = 1 */
  275. length = p_ca_message->msg[3] & 0x7f;
  276. words = 0; /* domi's suggestion */
  277. }
  278. else { /* Length = words */
  279. words = p_ca_message->msg[3] & 0x7f;
  280. for (i = 0; i < words; i++) {
  281. length = length << 8;
  282. length = length | p_ca_message->msg[4 + i];
  283. }
  284. }
  285. if (verbose > 4) {
  286. dprintk("%s:Length=[%d (0x%x)], Words=[%d]\n", __FUNCTION__, length,length, words);
  287. /* Debug Input string */
  288. for (i = 0; i < length; i++)
  289. dprintk(" %02x", p_ca_message->msg[i]);
  290. dprintk("]\n");
  291. }
  292. hw_offset = 7;
  293. buf_offset = words + 4;
  294. /* Program Header */
  295. if (verbose > 4)
  296. dprintk("\n%s:Program Header=[", __FUNCTION__);
  297. for (i = 0; i < 6; i++) {
  298. hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
  299. if (verbose > 4)
  300. dprintk(" %02x", p_ca_message->msg[buf_offset]);
  301. hw_offset++, buf_offset++, hw_buffer_length++;
  302. }
  303. if (verbose > 4)
  304. dprintk("]\n");
  305. program_info_length = 0;
  306. program_info_length = (((program_info_length | p_ca_message->msg[words + 8]) & 0x0f) << 8) | p_ca_message->msg[words + 9];
  307. if (verbose > 4)
  308. dprintk("%s:Program info Length=[%d][%02x], hw_offset=[%d], buf_offset=[%d] \n",
  309. __FUNCTION__, program_info_length, program_info_length, hw_offset, buf_offset);
  310. if (program_info_length && (program_info_length < 256)) { /* If program_info_length */
  311. hw_buffer->msg[11] = hw_buffer->msg[11] & 0x0f; /* req only 4 bits */
  312. hw_buffer->msg[12] = hw_buffer->msg[12] + 1; /* increment! ASIC bug! */
  313. if (p_ca_message->msg[buf_offset + 1] == 0x09) { /* Check CA descriptor */
  314. found_prog_ca_desc = 1;
  315. if (verbose > 4)
  316. dprintk("%s: Found CA descriptor @ Program level\n", __FUNCTION__);
  317. }
  318. if (found_prog_ca_desc) { /* Command only if CA descriptor */
  319. hw_buffer->msg[13] = p_ca_message->msg[buf_offset]; /* CA PMT command ID */
  320. hw_offset++, buf_offset++, hw_buffer_length++;
  321. }
  322. /* Program descriptors */
  323. if (verbose > 4) {
  324. dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
  325. dprintk("%s:Program descriptors=[", __FUNCTION__);
  326. }
  327. while (program_info_length && !error_condition) { /* Copy prog descriptors */
  328. if (program_info_length > p_ca_message->length) { /* Error situation */
  329. dprintk ("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d]\n",
  330. __FUNCTION__, __LINE__, program_info_length);
  331. dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
  332. error_condition = 1;
  333. break;
  334. }
  335. hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
  336. dprintk(" %02x", p_ca_message->msg[buf_offset]);
  337. hw_offset++, buf_offset++, hw_buffer_length++, program_info_length--;
  338. }
  339. if (verbose > 4) {
  340. dprintk("]\n");
  341. dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
  342. }
  343. if (found_prog_ca_desc) {
  344. if (!reply) {
  345. hw_buffer->msg[13] = 0x01; /* OK descrambling */
  346. if (verbose > 1)
  347. dprintk("CA PMT Command = OK Descrambling\n");
  348. }
  349. else {
  350. hw_buffer->msg[13] = 0x02; /* Ok MMI */
  351. if (verbose > 1)
  352. dprintk("CA PMT Command = Ok MMI\n");
  353. }
  354. if (query) {
  355. hw_buffer->msg[13] = 0x03; /* Query */
  356. if (verbose > 1)
  357. dprintk("CA PMT Command = CA PMT query\n");
  358. }
  359. }
  360. }
  361. else {
  362. hw_buffer->msg[11] = hw_buffer->msg[11] & 0xf0; /* Don't write to ASIC */
  363. hw_buffer->msg[12] = hw_buffer->msg[12] = 0x00;
  364. }
  365. if (verbose > 4)
  366. dprintk("%s:**********>p_ca_message->length=[%d], buf_offset=[%d], hw_offset=[%d]\n",
  367. __FUNCTION__, p_ca_message->length, buf_offset, hw_offset);
  368. while ((buf_offset < p_ca_message->length) && !error_condition) {
  369. /* Bail out in case of an indefinite loop */
  370. if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
  371. dprintk("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d], buf_offset=[%d]\n",
  372. __FUNCTION__, __LINE__, program_info_length, buf_offset);
  373. dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
  374. error_condition = 1;
  375. break;
  376. }
  377. /* Stream Header */
  378. for (k = 0; k < 5; k++) {
  379. hw_buffer->msg[hw_offset + k] = p_ca_message->msg[buf_offset + k];
  380. }
  381. es_info_length = 0;
  382. es_info_length = (es_info_length | (p_ca_message->msg[buf_offset + 3] & 0x0f)) << 8 | p_ca_message->msg[buf_offset + 4];
  383. if (verbose > 4) {
  384. dprintk("\n%s:----->Stream header=[%02x %02x %02x %02x %02x]\n", __FUNCTION__,
  385. p_ca_message->msg[buf_offset + 0], p_ca_message->msg[buf_offset + 1],
  386. p_ca_message->msg[buf_offset + 2], p_ca_message->msg[buf_offset + 3],
  387. p_ca_message->msg[buf_offset + 4]);
  388. dprintk("%s:----->Stream type=[%02x], es length=[%d (0x%x)], Chars=[%02x] [%02x], buf_offset=[%d]\n", __FUNCTION__,
  389. p_ca_message->msg[buf_offset + 0], es_info_length, es_info_length,
  390. p_ca_message->msg[buf_offset + 3], p_ca_message->msg[buf_offset + 4], buf_offset);
  391. }
  392. hw_buffer->msg[hw_offset + 3] &= 0x0f; /* req only 4 bits */
  393. if (found_prog_ca_desc) {
  394. hw_buffer->msg[hw_offset + 3] = 0x00;
  395. hw_buffer->msg[hw_offset + 4] = 0x00;
  396. }
  397. hw_offset += 5, buf_offset += 5, hw_buffer_length += 5;
  398. /* Check for CA descriptor */
  399. if (p_ca_message->msg[buf_offset + 1] == 0x09) {
  400. if (verbose > 4)
  401. dprintk("%s:Found CA descriptor @ Stream level\n", __FUNCTION__);
  402. found_stream_ca_desc = 1;
  403. }
  404. /* ES descriptors */
  405. if (es_info_length && !error_condition && !found_prog_ca_desc && found_stream_ca_desc) {
  406. // if (!ca_pmt_done) {
  407. hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; /* CA PMT cmd(es) */
  408. if (verbose > 4)
  409. printk("%s:----->CA PMT Command ID=[%02x]\n", __FUNCTION__, p_ca_message->msg[buf_offset]);
  410. // hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--, ca_pmt_done = 1;
  411. hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
  412. // }
  413. if (verbose > 4)
  414. dprintk("%s:----->ES descriptors=[", __FUNCTION__);
  415. while (es_info_length && !error_condition) { /* ES descriptors */
  416. if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
  417. if (verbose > 4) {
  418. dprintk("%s:\"WARNING\" ES Length error, line=[%d], es_info_length=[%d], buf_offset=[%d]\n",
  419. __FUNCTION__, __LINE__, es_info_length, buf_offset);
  420. dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
  421. }
  422. error_condition = 1;
  423. break;
  424. }
  425. hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
  426. if (verbose > 3)
  427. dprintk("%02x ", hw_buffer->msg[hw_offset]);
  428. hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
  429. }
  430. found_stream_ca_desc = 0; /* unset for new streams */
  431. dprintk("]\n");
  432. }
  433. }
  434. /* MCU Magic words */
  435. hw_buffer_length += 7;
  436. hw_buffer->msg[0] = hw_buffer_length;
  437. hw_buffer->msg[1] = 64;
  438. hw_buffer->msg[4] = 3;
  439. hw_buffer->msg[5] = hw_buffer->msg[0] - 7;
  440. hw_buffer->msg[6] = 0;
  441. /* Fix length */
  442. hw_buffer->length = hw_buffer->msg[0];
  443. put_checksum(&hw_buffer->msg[0], hw_buffer->msg[0]);
  444. /* Do the actual write */
  445. if (verbose > 4) {
  446. dprintk("%s:======================DEBUGGING================================\n", __FUNCTION__);
  447. dprintk("%s: Actual Length=[%d]\n", __FUNCTION__, hw_buffer_length);
  448. }
  449. /* Only for debugging! */
  450. if (verbose > 2)
  451. debug_8820_buffer(hw_buffer);
  452. if (verbose > 3)
  453. dprintk("%s: Reply = [%d]\n", __FUNCTION__, reply);
  454. write_to_8820(state, hw_buffer, reply);
  455. return 0;
  456. }
  457. /* Board supports CA PMT reply ? */
  458. static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
  459. {
  460. int ca_pmt_reply_test = 0;
  461. /* Do test board */
  462. /* Not there yet but soon */
  463. /* CA PMT Reply capable */
  464. if (ca_pmt_reply_test) {
  465. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
  466. dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__);
  467. return -1;
  468. }
  469. /* Process CA PMT Reply */
  470. /* will implement soon */
  471. dprintk("%s: Not there yet\n", __FUNCTION__);
  472. }
  473. /* CA PMT Reply not capable */
  474. if (!ca_pmt_reply_test) {
  475. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
  476. dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__);
  477. return -1;
  478. }
  479. if (verbose > 3)
  480. dprintk("%s: ca_set_pmt.. success !\n", __FUNCTION__);
  481. /* put a dummy message */
  482. }
  483. return 0;
  484. }
  485. static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void *arg)
  486. {
  487. int i = 0;
  488. unsigned int ca_message_header_len;
  489. u32 command = 0;
  490. struct ca_msg *hw_buffer;
  491. if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  492. printk("%s: Memory allocation failure\n", __FUNCTION__);
  493. return -ENOMEM;
  494. }
  495. if (verbose > 3)
  496. dprintk("%s\n", __FUNCTION__);
  497. if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg)))
  498. return -EFAULT;
  499. if (p_ca_message->msg) {
  500. ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
  501. /* EN50221 tag */
  502. command = 0;
  503. for (i = 0; i < 3; i++) {
  504. command = command | p_ca_message->msg[i];
  505. if (i < 2)
  506. command = command << 8;
  507. }
  508. if (verbose > 3)
  509. dprintk("%s:Command=[0x%x]\n", __FUNCTION__, command);
  510. switch (command) {
  511. case CA_PMT:
  512. if (verbose > 3)
  513. dprintk("Command = SEND_CA_PMT\n");
  514. if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) {
  515. dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__);
  516. return -1;
  517. }
  518. if (verbose > 3)
  519. dprintk("%s: -->CA_PMT Success !\n", __FUNCTION__);
  520. // retval = dummy_set_pmt(state, p_ca_message, hw_buffer, 0, 0);
  521. break;
  522. case CA_PMT_REPLY:
  523. if (verbose > 3)
  524. dprintk("Command = CA_PMT_REPLY\n");
  525. /* Have to handle the 2 basic types of cards here */
  526. if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
  527. dprintk("%s: -->CA_PMT_REPLY Failed !\n", __FUNCTION__);
  528. return -1;
  529. }
  530. if (verbose > 3)
  531. dprintk("%s: -->CA_PMT_REPLY Success !\n", __FUNCTION__);
  532. /* Certain boards do behave different ? */
  533. // retval = ca_set_pmt(state, p_ca_message, hw_buffer, 1, 1);
  534. case CA_APP_INFO_ENQUIRY: // only for debugging
  535. if (verbose > 3)
  536. dprintk("%s: Getting Cam Application information\n", __FUNCTION__);
  537. if ((ca_get_app_info(state)) < 0) {
  538. dprintk("%s: -->CA_APP_INFO_ENQUIRY Failed !\n", __FUNCTION__);
  539. return -1;
  540. }
  541. if (verbose > 3)
  542. printk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
  543. break;
  544. }
  545. }
  546. return 0;
  547. }
  548. static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg)
  549. {
  550. struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
  551. struct dst_state* state = (struct dst_state*) dvbdev->priv;
  552. struct ca_slot_info *p_ca_slot_info;
  553. struct ca_caps *p_ca_caps;
  554. struct ca_msg *p_ca_message;
  555. if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
  556. printk("%s: Memory allocation failure\n", __FUNCTION__);
  557. return -ENOMEM;
  558. }
  559. if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
  560. printk("%s: Memory allocation failure\n", __FUNCTION__);
  561. return -ENOMEM;
  562. }
  563. if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
  564. printk("%s: Memory allocation failure\n", __FUNCTION__);
  565. return -ENOMEM;
  566. }
  567. /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
  568. switch (cmd) {
  569. case CA_SEND_MSG:
  570. if (verbose > 1)
  571. dprintk("%s: Sending message\n", __FUNCTION__);
  572. if ((ca_send_message(state, p_ca_message, arg)) < 0) {
  573. dprintk("%s: -->CA_SEND_MSG Failed !\n", __FUNCTION__);
  574. return -1;
  575. }
  576. break;
  577. case CA_GET_MSG:
  578. if (verbose > 1)
  579. dprintk("%s: Getting message\n", __FUNCTION__);
  580. if ((ca_get_message(state, p_ca_message, arg)) < 0) {
  581. dprintk("%s: -->CA_GET_MSG Failed !\n", __FUNCTION__);
  582. return -1;
  583. }
  584. if (verbose > 1)
  585. dprintk("%s: -->CA_GET_MSG Success !\n", __FUNCTION__);
  586. break;
  587. case CA_RESET:
  588. if (verbose > 1)
  589. dprintk("%s: Resetting DST\n", __FUNCTION__);
  590. dst_error_bailout(state);
  591. msleep(4000);
  592. break;
  593. case CA_GET_SLOT_INFO:
  594. if (verbose > 1)
  595. dprintk("%s: Getting Slot info\n", __FUNCTION__);
  596. if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
  597. dprintk("%s: -->CA_GET_SLOT_INFO Failed !\n", __FUNCTION__);
  598. return -1;
  599. }
  600. if (verbose > 1)
  601. dprintk("%s: -->CA_GET_SLOT_INFO Success !\n", __FUNCTION__);
  602. break;
  603. case CA_GET_CAP:
  604. if (verbose > 1)
  605. dprintk("%s: Getting Slot capabilities\n", __FUNCTION__);
  606. if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
  607. dprintk("%s: -->CA_GET_CAP Failed !\n", __FUNCTION__);
  608. return -1;
  609. }
  610. if (verbose > 1)
  611. dprintk("%s: -->CA_GET_CAP Success !\n", __FUNCTION__);
  612. break;
  613. case CA_GET_DESCR_INFO:
  614. if (verbose > 1)
  615. dprintk("%s: Getting descrambler description\n", __FUNCTION__);
  616. if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
  617. dprintk("%s: -->CA_GET_DESCR_INFO Failed !\n", __FUNCTION__);
  618. return -1;
  619. }
  620. if (verbose > 1)
  621. dprintk("%s: -->CA_GET_DESCR_INFO Success !\n", __FUNCTION__);
  622. break;
  623. case CA_SET_DESCR:
  624. if (verbose > 1)
  625. dprintk("%s: Setting descrambler\n", __FUNCTION__);
  626. if ((ca_set_slot_descr()) < 0) {
  627. dprintk("%s: -->CA_SET_DESCR Failed !\n", __FUNCTION__);
  628. return -1;
  629. }
  630. if (verbose > 1)
  631. dprintk("%s: -->CA_SET_DESCR Success !\n", __FUNCTION__);
  632. break;
  633. case CA_SET_PID:
  634. if (verbose > 1)
  635. dprintk("%s: Setting PID\n", __FUNCTION__);
  636. if ((ca_set_pid()) < 0) {
  637. dprintk("%s: -->CA_SET_PID Failed !\n", __FUNCTION__);
  638. return -1;
  639. }
  640. if (verbose > 1)
  641. dprintk("%s: -->CA_SET_PID Success !\n", __FUNCTION__);
  642. default:
  643. return -EOPNOTSUPP;
  644. };
  645. return 0;
  646. }
  647. static int dst_ca_open(struct inode *inode, struct file *file)
  648. {
  649. if (verbose > 4)
  650. dprintk("%s:Device opened [%p]\n", __FUNCTION__, file);
  651. try_module_get(THIS_MODULE);
  652. return 0;
  653. }
  654. static int dst_ca_release(struct inode *inode, struct file *file)
  655. {
  656. if (verbose > 4)
  657. dprintk("%s:Device closed.\n", __FUNCTION__);
  658. module_put(THIS_MODULE);
  659. return 0;
  660. }
  661. static int dst_ca_read(struct file *file, char __user * buffer, size_t length, loff_t * offset)
  662. {
  663. int bytes_read = 0;
  664. if (verbose > 4)
  665. dprintk("%s:Device read.\n", __FUNCTION__);
  666. return bytes_read;
  667. }
  668. static int dst_ca_write(struct file *file, const char __user * buffer, size_t length, loff_t * offset)
  669. {
  670. if (verbose > 4)
  671. dprintk("%s:Device write.\n", __FUNCTION__);
  672. return 0;
  673. }
  674. static struct file_operations dst_ca_fops = {
  675. .owner = THIS_MODULE,
  676. .ioctl = (void *)dst_ca_ioctl,
  677. .open = dst_ca_open,
  678. .release = dst_ca_release,
  679. .read = dst_ca_read,
  680. .write = dst_ca_write
  681. };
  682. static struct dvb_device dvbdev_ca = {
  683. .priv = NULL,
  684. .users = 1,
  685. .readers = 1,
  686. .writers = 1,
  687. .fops = &dst_ca_fops
  688. };
  689. int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
  690. {
  691. struct dvb_device *dvbdev;
  692. if (verbose > 4)
  693. dprintk("%s:registering DST-CA device\n", __FUNCTION__);
  694. dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
  695. return 0;
  696. }
  697. EXPORT_SYMBOL(dst_ca_attach);
  698. MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
  699. MODULE_AUTHOR("Manu Abraham");
  700. MODULE_LICENSE("GPL");