xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/dvb/ca_high_level.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593SmuzhiyunThe High level CI API
4*4882a593Smuzhiyun=====================
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun.. note::
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun   This documentation is outdated.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunThis document describes the high level CI API as in accordance to the
11*4882a593SmuzhiyunLinux DVB API.
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunWith the High Level CI approach any new card with almost any random
15*4882a593Smuzhiyunarchitecture can be implemented with this style, the definitions
16*4882a593Smuzhiyuninside the switch statement can be easily adapted for any card, thereby
17*4882a593Smuzhiyuneliminating the need for any additional ioctls.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunThe disadvantage is that the driver/hardware has to manage the rest. For
20*4882a593Smuzhiyunthe application programmer it would be as simple as sending/receiving an
21*4882a593Smuzhiyunarray to/from the CI ioctls as defined in the Linux DVB API. No changes
22*4882a593Smuzhiyunhave been made in the API to accommodate this feature.
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunWhy the need for another CI interface?
26*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunThis is one of the most commonly asked question. Well a nice question.
29*4882a593SmuzhiyunStrictly speaking this is not a new interface.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunThe CI interface is defined in the DVB API in ca.h as:
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun.. code-block:: c
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun	typedef struct ca_slot_info {
36*4882a593Smuzhiyun		int num;               /* slot number */
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun		int type;              /* CA interface this slot supports */
39*4882a593Smuzhiyun	#define CA_CI            1     /* CI high level interface */
40*4882a593Smuzhiyun	#define CA_CI_LINK       2     /* CI link layer level interface */
41*4882a593Smuzhiyun	#define CA_CI_PHYS       4     /* CI physical layer level interface */
42*4882a593Smuzhiyun	#define CA_DESCR         8     /* built-in descrambler */
43*4882a593Smuzhiyun	#define CA_SC          128     /* simple smart card interface */
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun		unsigned int flags;
46*4882a593Smuzhiyun	#define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */
47*4882a593Smuzhiyun	#define CA_CI_MODULE_READY   2
48*4882a593Smuzhiyun	} ca_slot_info_t;
49*4882a593Smuzhiyun
50*4882a593SmuzhiyunThis CI interface follows the CI high level interface, which is not
51*4882a593Smuzhiyunimplemented by most applications. Hence this area is revisited.
52*4882a593Smuzhiyun
53*4882a593SmuzhiyunThis CI interface is quite different in the case that it tries to
54*4882a593Smuzhiyunaccommodate all other CI based devices, that fall into the other categories.
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunThis means that this CI interface handles the EN50221 style tags in the
57*4882a593SmuzhiyunApplication layer only and no session management is taken care of by the
58*4882a593Smuzhiyunapplication. The driver/hardware will take care of all that.
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunThis interface is purely an EN50221 interface exchanging APDU's. This
61*4882a593Smuzhiyunmeans that no session management, link layer or a transport layer do
62*4882a593Smuzhiyunexist in this case in the application to driver communication. It is
63*4882a593Smuzhiyunas simple as that. The driver/hardware has to take care of that.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunWith this High Level CI interface, the interface can be defined with the
66*4882a593Smuzhiyunregular ioctls.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunAll these ioctls are also valid for the High level CI interface
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun#define CA_RESET          _IO('o', 128)
71*4882a593Smuzhiyun#define CA_GET_CAP        _IOR('o', 129, ca_caps_t)
72*4882a593Smuzhiyun#define CA_GET_SLOT_INFO  _IOR('o', 130, ca_slot_info_t)
73*4882a593Smuzhiyun#define CA_GET_DESCR_INFO _IOR('o', 131, ca_descr_info_t)
74*4882a593Smuzhiyun#define CA_GET_MSG        _IOR('o', 132, ca_msg_t)
75*4882a593Smuzhiyun#define CA_SEND_MSG       _IOW('o', 133, ca_msg_t)
76*4882a593Smuzhiyun#define CA_SET_DESCR      _IOW('o', 134, ca_descr_t)
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunOn querying the device, the device yields information thus:
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun.. code-block:: none
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun	CA_GET_SLOT_INFO
84*4882a593Smuzhiyun	----------------------------
85*4882a593Smuzhiyun	Command = [info]
86*4882a593Smuzhiyun	APP: Number=[1]
87*4882a593Smuzhiyun	APP: Type=[1]
88*4882a593Smuzhiyun	APP: flags=[1]
89*4882a593Smuzhiyun	APP: CI High level interface
90*4882a593Smuzhiyun	APP: CA/CI Module Present
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun	CA_GET_CAP
93*4882a593Smuzhiyun	----------------------------
94*4882a593Smuzhiyun	Command = [caps]
95*4882a593Smuzhiyun	APP: Slots=[1]
96*4882a593Smuzhiyun	APP: Type=[1]
97*4882a593Smuzhiyun	APP: Descrambler keys=[16]
98*4882a593Smuzhiyun	APP: Type=[1]
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun	CA_SEND_MSG
101*4882a593Smuzhiyun	----------------------------
102*4882a593Smuzhiyun	Descriptors(Program Level)=[ 09 06 06 04 05 50 ff f1]
103*4882a593Smuzhiyun	Found CA descriptor @ program level
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun	(20) ES type=[2] ES pid=[201]  ES length =[0 (0x0)]
106*4882a593Smuzhiyun	(25) ES type=[4] ES pid=[301]  ES length =[0 (0x0)]
107*4882a593Smuzhiyun	ca_message length is 25 (0x19) bytes
108*4882a593Smuzhiyun	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]
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun
111*4882a593SmuzhiyunNot all ioctl's are implemented in the driver from the API, the other
112*4882a593Smuzhiyunfeatures of the hardware that cannot be implemented by the API are achieved
113*4882a593Smuzhiyunusing the CA_GET_MSG and CA_SEND_MSG ioctls. An EN50221 style wrapper is
114*4882a593Smuzhiyunused to exchange the data to maintain compatibility with other hardware.
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun.. code-block:: c
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun	/* a message to/from a CI-CAM */
119*4882a593Smuzhiyun	typedef struct ca_msg {
120*4882a593Smuzhiyun		unsigned int index;
121*4882a593Smuzhiyun		unsigned int type;
122*4882a593Smuzhiyun		unsigned int length;
123*4882a593Smuzhiyun		unsigned char msg[256];
124*4882a593Smuzhiyun	} ca_msg_t;
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunThe flow of data can be described thus,
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun.. code-block:: none
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun	App (User)
132*4882a593Smuzhiyun	-----
133*4882a593Smuzhiyun	parse
134*4882a593Smuzhiyun	  |
135*4882a593Smuzhiyun	  |
136*4882a593Smuzhiyun	  v
137*4882a593Smuzhiyun	en50221 APDU (package)
138*4882a593Smuzhiyun   --------------------------------------
139*4882a593Smuzhiyun   |	  |				| High Level CI driver
140*4882a593Smuzhiyun   |	  |				|
141*4882a593Smuzhiyun   |	  v				|
142*4882a593Smuzhiyun   |	en50221 APDU (unpackage)	|
143*4882a593Smuzhiyun   |	  |				|
144*4882a593Smuzhiyun   |	  |				|
145*4882a593Smuzhiyun   |	  v				|
146*4882a593Smuzhiyun   |	sanity checks			|
147*4882a593Smuzhiyun   |	  |				|
148*4882a593Smuzhiyun   |	  |				|
149*4882a593Smuzhiyun   |	  v				|
150*4882a593Smuzhiyun   |	do (H/W dep)			|
151*4882a593Smuzhiyun   --------------------------------------
152*4882a593Smuzhiyun	  |    Hardware
153*4882a593Smuzhiyun	  |
154*4882a593Smuzhiyun	  v
155*4882a593Smuzhiyun
156*4882a593SmuzhiyunThe High Level CI interface uses the EN50221 DVB standard, following a
157*4882a593Smuzhiyunstandard ensures futureproofness.
158