4.3. 高级CI API

注意

本文档已过时。

本文档描述了符合Linux DVB API的高级CI API。

通过高级CI方法,可以使用这种风格实现具有几乎任何随机架构的任何新卡,可以轻松地为任何卡调整switch语句中的定义,从而消除了对任何其他ioctl的需求。

缺点是驱动程序/硬件必须管理其余部分。对于应用程序员来说,就像按照Linux DVB API中的定义,将数组发送/接收到CI ioctl一样简单。API中没有进行任何更改来适应此功能。

4.3.1. 为什么需要另一个CI接口?

这是最常被问到的问题之一。好吧,一个很好的问题。严格来说,这不是一个新的接口。

CI接口在DVB API的ca.h中定义为

typedef struct ca_slot_info {
        int num;               /* slot number */

        int type;              /* CA interface this slot supports */
#define CA_CI            1     /* CI high level interface */
#define CA_CI_LINK       2     /* CI link layer level interface */
#define CA_CI_PHYS       4     /* CI physical layer level interface */
#define CA_DESCR         8     /* built-in descrambler */
#define CA_SC          128     /* simple smart card interface */

        unsigned int flags;
#define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */
#define CA_CI_MODULE_READY   2
} ca_slot_info_t;

此CI接口遵循CI高级接口,该接口未被大多数应用程序实现。因此,重新审视了该领域。

此CI接口的不同之处在于,它试图容纳属于其他类别的所有其他基于CI的设备。

这意味着此CI接口仅在应用程序层中处理EN50221样式标签,并且应用程序不处理会话管理。驱动程序/硬件将负责所有这些。

该接口纯粹是交换APDU的EN50221接口。这意味着在这种情况下,应用程序到驱动程序的通信中不存在会话管理、链路层或传输层。就这么简单。驱动程序/硬件必须负责处理。

使用此高级CI接口,可以使用常规ioctl定义接口。

所有这些ioctl对于高级CI接口也有效

#define CA_RESET _IO('o', 128) #define CA_GET_CAP _IOR('o', 129, ca_caps_t) #define CA_GET_SLOT_INFO _IOR('o', 130, ca_slot_info_t) #define CA_GET_DESCR_INFO _IOR('o', 131, ca_descr_info_t) #define CA_GET_MSG _IOR('o', 132, ca_msg_t) #define CA_SEND_MSG _IOW('o', 133, ca_msg_t) #define CA_SET_DESCR _IOW('o', 134, ca_descr_t)

在查询设备时,设备会产生以下信息

CA_GET_SLOT_INFO
----------------------------
Command = [info]
APP: Number=[1]
APP: Type=[1]
APP: flags=[1]
APP: CI High level interface
APP: CA/CI Module Present

CA_GET_CAP
----------------------------
Command = [caps]
APP: Slots=[1]
APP: Type=[1]
APP: Descrambler keys=[16]
APP: Type=[1]

CA_SEND_MSG
----------------------------
Descriptors(Program Level)=[ 09 06 06 04 05 50 ff f1]
Found CA descriptor @ program level

(20) ES type=[2] ES pid=[201]  ES length =[0 (0x0)]
(25) ES type=[4] ES pid=[301]  ES length =[0 (0x0)]
ca_message length is 25 (0x19) bytes
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]

并非API中的所有ioctl都在驱动程序中实现,无法通过API实现的硬件的其他功能通过CA_GET_MSG和CA_SEND_MSG ioctl实现。 使用EN50221样式包装器交换数据以保持与其他硬件的兼容性。

/* a message to/from a CI-CAM */
typedef struct ca_msg {
        unsigned int index;
        unsigned int type;
        unsigned int length;
        unsigned char msg[256];
} ca_msg_t;

数据流可以这样描述,

     App (User)
     -----
     parse
       |
       |
       v
     en50221 APDU (package)
--------------------------------------
|      |                             | High Level CI driver
|      |                             |
|      v                             |
|    en50221 APDU (unpackage)        |
|      |                             |
|      |                             |
|      v                             |
|    sanity checks                   |
|      |                             |
|      |                             |
|      v                             |
|    do (H/W dep)                    |
--------------------------------------
       |    Hardware
       |
       v

高级CI接口使用EN50221 DVB标准,遵循标准可确保未来性。