blob: 8124bf5ce5ef826436057156d2b2ddd0359d841b [file] [log] [blame]
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -03001Digital TV Conditional Access Interface (CI API)
2================================================
3
4
5.. note::
6
7 This documentation is outdated.
8
9This document describes the usage of the high level CI API as
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070010in accordance to the Linux DVB API. This is a not a documentation for the,
11existing low level CI API.
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070012
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030013.. note::
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070014
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030015 For the Twinhan/Twinhan clones, the dst_ca module handles the CI
16 hardware handling.This module is loaded automatically if a CI
17 (Common Interface, that holds the CAM (Conditional Access Module)
18 is detected.
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070019
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030020ca_zap
21~~~~~~
22
23An userspace application, like ``ca_zap`` is required to handle encrypted
24MPEG-TS streams.
25
26The ``ca_zap`` userland application is in charge of sending the
27descrambling related information to the Conditional Access Module (CAM).
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070028
29This application requires the following to function properly as of now.
30
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030031a) Tune to a valid channel, with szap.
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070032
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030033 eg: $ szap -c channels.conf -r "TMC" -x
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070034
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030035b) a channels.conf containing a valid PMT PID
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070036
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030037 eg: TMC:11996:h:0:27500:278:512:650:321
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070038
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030039 here 278 is a valid PMT PID. the rest of the values are the
40 same ones that szap uses.
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070041
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030042c) after running a szap, you have to run ca_zap, for the
43 descrambler to function,
44
45 eg: $ ca_zap channels.conf "TMC"
46
47d) Hopefully enjoy your favourite subscribed channel as you do with
48 a FTA card.
49
50.. note::
51
52 Currently ca_zap, and dst_test, both are meant for demonstration
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070053 purposes only, they can become full fledged applications if necessary.
54
55
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030056Cards that fall in this category
57~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
Francis Galieguea33f3222010-04-23 00:08:02 +020059At present the cards that fall in this category are the Twinhan and its
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070060clones, these cards are available as VVMER, Tomato, Hercules, Orange and
61so on.
62
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030063CI modules that are supported
64~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65
Lucas De Marchi25985ed2011-03-30 22:57:33 -030066The CI module support is largely dependent upon the firmware on the cards
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070067Some cards do support almost all of the available CI modules. There is
68nothing much that can be done in order to make additional CI modules
69working with these cards.
70
71Modules that have been tested by this driver at present are
72
73(1) Irdeto 1 and 2 from SCM
74(2) Viaccess from SCM
75(3) Dragoncam
76
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030077The High level CI API
78~~~~~~~~~~~~~~~~~~~~~
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070079
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030080For the programmer
81^^^^^^^^^^^^^^^^^^
82
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070083With the High Level CI approach any new card with almost any random
84architecture can be implemented with this style, the definitions
Matt LaPlante2fe0ae72006-10-03 22:50:39 +020085inside the switch statement can be easily adapted for any card, thereby
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070086eliminating the need for any additional ioctls.
87
88The disadvantage is that the driver/hardware has to manage the rest. For
89the application programmer it would be as simple as sending/receiving an
90array to/from the CI ioctls as defined in the Linux DVB API. No changes
Matt LaPlante4ae0edc2006-11-30 04:58:40 +010091have been made in the API to accommodate this feature.
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070092
93
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -030094Why the need for another CI interface?
95~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96
Johannes Stezenbach50b215a2005-05-16 21:54:41 -070097This is one of the most commonly asked question. Well a nice question.
98Strictly speaking this is not a new interface.
99
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300100The CI interface is defined in the DVB API in ca.h as:
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700101
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300102.. code-block:: c
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700103
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300104 typedef struct ca_slot_info {
105 int num; /* slot number */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700106
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300107 int type; /* CA interface this slot supports */
108 #define CA_CI 1 /* CI high level interface */
109 #define CA_CI_LINK 2 /* CI link layer level interface */
110 #define CA_CI_PHYS 4 /* CI physical layer level interface */
111 #define CA_DESCR 8 /* built-in descrambler */
112 #define CA_SC 128 /* simple smart card interface */
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700113
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300114 unsigned int flags;
115 #define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */
116 #define CA_CI_MODULE_READY 2
117 } ca_slot_info_t;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700118
119This CI interface follows the CI high level interface, which is not
120implemented by most applications. Hence this area is revisited.
121
122This CI interface is quite different in the case that it tries to
Matt LaPlante4ae0edc2006-11-30 04:58:40 +0100123accommodate all other CI based devices, that fall into the other categories.
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700124
125This means that this CI interface handles the EN50221 style tags in the
126Application layer only and no session management is taken care of by the
127application. The driver/hardware will take care of all that.
128
129This interface is purely an EN50221 interface exchanging APDU's. This
130means that no session management, link layer or a transport layer do
131exist in this case in the application to driver communication. It is
132as simple as that. The driver/hardware has to take care of that.
133
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700134With this High Level CI interface, the interface can be defined with the
135regular ioctls.
136
137All these ioctls are also valid for the High level CI interface
138
139#define CA_RESET _IO('o', 128)
140#define CA_GET_CAP _IOR('o', 129, ca_caps_t)
141#define CA_GET_SLOT_INFO _IOR('o', 130, ca_slot_info_t)
142#define CA_GET_DESCR_INFO _IOR('o', 131, ca_descr_info_t)
143#define CA_GET_MSG _IOR('o', 132, ca_msg_t)
144#define CA_SEND_MSG _IOW('o', 133, ca_msg_t)
145#define CA_SET_DESCR _IOW('o', 134, ca_descr_t)
146#define CA_SET_PID _IOW('o', 135, ca_pid_t)
147
148
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300149On querying the device, the device yields information thus:
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700150
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300151.. code-block:: none
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700152
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300153 CA_GET_SLOT_INFO
154 ----------------------------
155 Command = [info]
156 APP: Number=[1]
157 APP: Type=[1]
158 APP: flags=[1]
159 APP: CI High level interface
160 APP: CA/CI Module Present
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700161
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300162 CA_GET_CAP
163 ----------------------------
164 Command = [caps]
165 APP: Slots=[1]
166 APP: Type=[1]
167 APP: Descrambler keys=[16]
168 APP: Type=[1]
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700169
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300170 CA_SEND_MSG
171 ----------------------------
172 Descriptors(Program Level)=[ 09 06 06 04 05 50 ff f1]
173 Found CA descriptor @ program level
174
175 (20) ES type=[2] ES pid=[201] ES length =[0 (0x0)]
176 (25) ES type=[4] ES pid=[301] ES length =[0 (0x0)]
177 ca_message length is 25 (0x19) bytes
178 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]
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700179
180
181Not all ioctl's are implemented in the driver from the API, the other
182features of the hardware that cannot be implemented by the API are achieved
183using the CA_GET_MSG and CA_SEND_MSG ioctls. An EN50221 style wrapper is
184used to exchange the data to maintain compatibility with other hardware.
185
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300186.. code-block:: c
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700187
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300188 /* a message to/from a CI-CAM */
189 typedef struct ca_msg {
190 unsigned int index;
191 unsigned int type;
192 unsigned int length;
193 unsigned char msg[256];
194 } ca_msg_t;
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700195
196
197The flow of data can be described thus,
198
Mauro Carvalho Chehabc1eaa6c2016-07-17 12:48:43 -0300199.. code-block:: none
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700200
201 App (User)
202 -----
203 parse
204 |
205 |
206 v
207 en50221 APDU (package)
208 --------------------------------------
209 | | | High Level CI driver
210 | | |
211 | v |
212 | en50221 APDU (unpackage) |
213 | | |
214 | | |
215 | v |
216 | sanity checks |
217 | | |
218 | | |
219 | v |
220 | do (H/W dep) |
221 --------------------------------------
222 | Hardware
223 |
224 v
225
226
227
228
229The High Level CI interface uses the EN50221 DVB standard, following a
230standard ensures futureproofness.