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