18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciThe High level CI API 48c2ecf20Sopenharmony_ci===================== 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci.. note:: 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci This documentation is outdated. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciThis document describes the high level CI API as in accordance to the 118c2ecf20Sopenharmony_ciLinux DVB API. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciWith the High Level CI approach any new card with almost any random 158c2ecf20Sopenharmony_ciarchitecture can be implemented with this style, the definitions 168c2ecf20Sopenharmony_ciinside the switch statement can be easily adapted for any card, thereby 178c2ecf20Sopenharmony_cieliminating the need for any additional ioctls. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciThe disadvantage is that the driver/hardware has to manage the rest. For 208c2ecf20Sopenharmony_cithe application programmer it would be as simple as sending/receiving an 218c2ecf20Sopenharmony_ciarray to/from the CI ioctls as defined in the Linux DVB API. No changes 228c2ecf20Sopenharmony_cihave been made in the API to accommodate this feature. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ciWhy the need for another CI interface? 268c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciThis is one of the most commonly asked question. Well a nice question. 298c2ecf20Sopenharmony_ciStrictly speaking this is not a new interface. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciThe CI interface is defined in the DVB API in ca.h as: 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci.. code-block:: c 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci typedef struct ca_slot_info { 368c2ecf20Sopenharmony_ci int num; /* slot number */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci int type; /* CA interface this slot supports */ 398c2ecf20Sopenharmony_ci #define CA_CI 1 /* CI high level interface */ 408c2ecf20Sopenharmony_ci #define CA_CI_LINK 2 /* CI link layer level interface */ 418c2ecf20Sopenharmony_ci #define CA_CI_PHYS 4 /* CI physical layer level interface */ 428c2ecf20Sopenharmony_ci #define CA_DESCR 8 /* built-in descrambler */ 438c2ecf20Sopenharmony_ci #define CA_SC 128 /* simple smart card interface */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci unsigned int flags; 468c2ecf20Sopenharmony_ci #define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */ 478c2ecf20Sopenharmony_ci #define CA_CI_MODULE_READY 2 488c2ecf20Sopenharmony_ci } ca_slot_info_t; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciThis CI interface follows the CI high level interface, which is not 518c2ecf20Sopenharmony_ciimplemented by most applications. Hence this area is revisited. 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciThis CI interface is quite different in the case that it tries to 548c2ecf20Sopenharmony_ciaccommodate all other CI based devices, that fall into the other categories. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciThis means that this CI interface handles the EN50221 style tags in the 578c2ecf20Sopenharmony_ciApplication layer only and no session management is taken care of by the 588c2ecf20Sopenharmony_ciapplication. The driver/hardware will take care of all that. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciThis interface is purely an EN50221 interface exchanging APDU's. This 618c2ecf20Sopenharmony_cimeans that no session management, link layer or a transport layer do 628c2ecf20Sopenharmony_ciexist in this case in the application to driver communication. It is 638c2ecf20Sopenharmony_cias simple as that. The driver/hardware has to take care of that. 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciWith this High Level CI interface, the interface can be defined with the 668c2ecf20Sopenharmony_ciregular ioctls. 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciAll these ioctls are also valid for the High level CI interface 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define CA_RESET _IO('o', 128) 718c2ecf20Sopenharmony_ci#define CA_GET_CAP _IOR('o', 129, ca_caps_t) 728c2ecf20Sopenharmony_ci#define CA_GET_SLOT_INFO _IOR('o', 130, ca_slot_info_t) 738c2ecf20Sopenharmony_ci#define CA_GET_DESCR_INFO _IOR('o', 131, ca_descr_info_t) 748c2ecf20Sopenharmony_ci#define CA_GET_MSG _IOR('o', 132, ca_msg_t) 758c2ecf20Sopenharmony_ci#define CA_SEND_MSG _IOW('o', 133, ca_msg_t) 768c2ecf20Sopenharmony_ci#define CA_SET_DESCR _IOW('o', 134, ca_descr_t) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciOn querying the device, the device yields information thus: 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci.. code-block:: none 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci CA_GET_SLOT_INFO 848c2ecf20Sopenharmony_ci ---------------------------- 858c2ecf20Sopenharmony_ci Command = [info] 868c2ecf20Sopenharmony_ci APP: Number=[1] 878c2ecf20Sopenharmony_ci APP: Type=[1] 888c2ecf20Sopenharmony_ci APP: flags=[1] 898c2ecf20Sopenharmony_ci APP: CI High level interface 908c2ecf20Sopenharmony_ci APP: CA/CI Module Present 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci CA_GET_CAP 938c2ecf20Sopenharmony_ci ---------------------------- 948c2ecf20Sopenharmony_ci Command = [caps] 958c2ecf20Sopenharmony_ci APP: Slots=[1] 968c2ecf20Sopenharmony_ci APP: Type=[1] 978c2ecf20Sopenharmony_ci APP: Descrambler keys=[16] 988c2ecf20Sopenharmony_ci APP: Type=[1] 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci CA_SEND_MSG 1018c2ecf20Sopenharmony_ci ---------------------------- 1028c2ecf20Sopenharmony_ci Descriptors(Program Level)=[ 09 06 06 04 05 50 ff f1] 1038c2ecf20Sopenharmony_ci Found CA descriptor @ program level 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci (20) ES type=[2] ES pid=[201] ES length =[0 (0x0)] 1068c2ecf20Sopenharmony_ci (25) ES type=[4] ES pid=[301] ES length =[0 (0x0)] 1078c2ecf20Sopenharmony_ci ca_message length is 25 (0x19) bytes 1088c2ecf20Sopenharmony_ci 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] 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ciNot all ioctl's are implemented in the driver from the API, the other 1128c2ecf20Sopenharmony_cifeatures of the hardware that cannot be implemented by the API are achieved 1138c2ecf20Sopenharmony_ciusing the CA_GET_MSG and CA_SEND_MSG ioctls. An EN50221 style wrapper is 1148c2ecf20Sopenharmony_ciused to exchange the data to maintain compatibility with other hardware. 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci.. code-block:: c 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci /* a message to/from a CI-CAM */ 1198c2ecf20Sopenharmony_ci typedef struct ca_msg { 1208c2ecf20Sopenharmony_ci unsigned int index; 1218c2ecf20Sopenharmony_ci unsigned int type; 1228c2ecf20Sopenharmony_ci unsigned int length; 1238c2ecf20Sopenharmony_ci unsigned char msg[256]; 1248c2ecf20Sopenharmony_ci } ca_msg_t; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciThe flow of data can be described thus, 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci.. code-block:: none 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci App (User) 1328c2ecf20Sopenharmony_ci ----- 1338c2ecf20Sopenharmony_ci parse 1348c2ecf20Sopenharmony_ci | 1358c2ecf20Sopenharmony_ci | 1368c2ecf20Sopenharmony_ci v 1378c2ecf20Sopenharmony_ci en50221 APDU (package) 1388c2ecf20Sopenharmony_ci -------------------------------------- 1398c2ecf20Sopenharmony_ci | | | High Level CI driver 1408c2ecf20Sopenharmony_ci | | | 1418c2ecf20Sopenharmony_ci | v | 1428c2ecf20Sopenharmony_ci | en50221 APDU (unpackage) | 1438c2ecf20Sopenharmony_ci | | | 1448c2ecf20Sopenharmony_ci | | | 1458c2ecf20Sopenharmony_ci | v | 1468c2ecf20Sopenharmony_ci | sanity checks | 1478c2ecf20Sopenharmony_ci | | | 1488c2ecf20Sopenharmony_ci | | | 1498c2ecf20Sopenharmony_ci | v | 1508c2ecf20Sopenharmony_ci | do (H/W dep) | 1518c2ecf20Sopenharmony_ci -------------------------------------- 1528c2ecf20Sopenharmony_ci | Hardware 1538c2ecf20Sopenharmony_ci | 1548c2ecf20Sopenharmony_ci v 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciThe High Level CI interface uses the EN50221 DVB standard, following a 1578c2ecf20Sopenharmony_cistandard ensures futureproofness. 158