ca_high_level.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. .. SPDX-License-Identifier: GPL-2.0
  2. The High level CI API
  3. =====================
  4. .. note::
  5. This documentation is outdated.
  6. This document describes the high level CI API as in accordance to the
  7. Linux DVB API.
  8. With the High Level CI approach any new card with almost any random
  9. architecture can be implemented with this style, the definitions
  10. inside the switch statement can be easily adapted for any card, thereby
  11. eliminating the need for any additional ioctls.
  12. The disadvantage is that the driver/hardware has to manage the rest. For
  13. the application programmer it would be as simple as sending/receiving an
  14. array to/from the CI ioctls as defined in the Linux DVB API. No changes
  15. have been made in the API to accommodate this feature.
  16. Why the need for another CI interface?
  17. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. This is one of the most commonly asked question. Well a nice question.
  19. Strictly speaking this is not a new interface.
  20. The CI interface is defined in the DVB API in ca.h as:
  21. .. code-block:: c
  22. typedef struct ca_slot_info {
  23. int num; /* slot number */
  24. int type; /* CA interface this slot supports */
  25. #define CA_CI 1 /* CI high level interface */
  26. #define CA_CI_LINK 2 /* CI link layer level interface */
  27. #define CA_CI_PHYS 4 /* CI physical layer level interface */
  28. #define CA_DESCR 8 /* built-in descrambler */
  29. #define CA_SC 128 /* simple smart card interface */
  30. unsigned int flags;
  31. #define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */
  32. #define CA_CI_MODULE_READY 2
  33. } ca_slot_info_t;
  34. This CI interface follows the CI high level interface, which is not
  35. implemented by most applications. Hence this area is revisited.
  36. This CI interface is quite different in the case that it tries to
  37. accommodate all other CI based devices, that fall into the other categories.
  38. This means that this CI interface handles the EN50221 style tags in the
  39. Application layer only and no session management is taken care of by the
  40. application. The driver/hardware will take care of all that.
  41. This interface is purely an EN50221 interface exchanging APDU's. This
  42. means that no session management, link layer or a transport layer do
  43. exist in this case in the application to driver communication. It is
  44. as simple as that. The driver/hardware has to take care of that.
  45. With this High Level CI interface, the interface can be defined with the
  46. regular ioctls.
  47. All these ioctls are also valid for the High level CI interface
  48. #define CA_RESET _IO('o', 128)
  49. #define CA_GET_CAP _IOR('o', 129, ca_caps_t)
  50. #define CA_GET_SLOT_INFO _IOR('o', 130, ca_slot_info_t)
  51. #define CA_GET_DESCR_INFO _IOR('o', 131, ca_descr_info_t)
  52. #define CA_GET_MSG _IOR('o', 132, ca_msg_t)
  53. #define CA_SEND_MSG _IOW('o', 133, ca_msg_t)
  54. #define CA_SET_DESCR _IOW('o', 134, ca_descr_t)
  55. On querying the device, the device yields information thus:
  56. .. code-block:: none
  57. CA_GET_SLOT_INFO
  58. ----------------------------
  59. Command = [info]
  60. APP: Number=[1]
  61. APP: Type=[1]
  62. APP: flags=[1]
  63. APP: CI High level interface
  64. APP: CA/CI Module Present
  65. CA_GET_CAP
  66. ----------------------------
  67. Command = [caps]
  68. APP: Slots=[1]
  69. APP: Type=[1]
  70. APP: Descrambler keys=[16]
  71. APP: Type=[1]
  72. CA_SEND_MSG
  73. ----------------------------
  74. Descriptors(Program Level)=[ 09 06 06 04 05 50 ff f1]
  75. Found CA descriptor @ program level
  76. (20) ES type=[2] ES pid=[201] ES length =[0 (0x0)]
  77. (25) ES type=[4] ES pid=[301] ES length =[0 (0x0)]
  78. ca_message length is 25 (0x19) bytes
  79. EN50221 CA MSG=[ 9f 80 32 19 03 01 2d d1 f0 08 01 09 06 06 04 05 50 ff f1 02 e0 c9 00 00 04 e1 2d 00 00]
  80. Not all ioctl's are implemented in the driver from the API, the other
  81. features of the hardware that cannot be implemented by the API are achieved
  82. using the CA_GET_MSG and CA_SEND_MSG ioctls. An EN50221 style wrapper is
  83. used to exchange the data to maintain compatibility with other hardware.
  84. .. code-block:: c
  85. /* a message to/from a CI-CAM */
  86. typedef struct ca_msg {
  87. unsigned int index;
  88. unsigned int type;
  89. unsigned int length;
  90. unsigned char msg[256];
  91. } ca_msg_t;
  92. The flow of data can be described thus,
  93. .. code-block:: none
  94. App (User)
  95. -----
  96. parse
  97. |
  98. |
  99. v
  100. en50221 APDU (package)
  101. --------------------------------------
  102. | | | High Level CI driver
  103. | | |
  104. | v |
  105. | en50221 APDU (unpackage) |
  106. | | |
  107. | | |
  108. | v |
  109. | sanity checks |
  110. | | |
  111. | | |
  112. | v |
  113. | do (H/W dep) |
  114. --------------------------------------
  115. | Hardware
  116. |
  117. v
  118. The High Level CI interface uses the EN50221 DVB standard, following a
  119. standard ensures futureproofness.