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標準,遵循標準可確保未來性。