blob: 30e66f619fe650fb8359c08a37e9c1bb449ed240 [file] [log] [blame]
chuangcheng pengfacd04c2023-08-21 14:02:24 +08001/* SPDX-License-Identifier: LGPL-2.1+ WITH Linux-syscall-note */
2/*
3 * ca.h
4 *
5 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
6 * & Marcus Metzler <marcus@convergence.de>
7 * for convergence integrated media GmbH
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Lesser Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 */
24
25#ifndef _DVBCA_H_
26#define _DVBCA_H_
27
28#define CONFIG_AMLOGIC_DVB_COMPAT
29/**
30 * struct ca_slot_info - CA slot interface types and info.
31 *
32 * @num: slot number.
33 * @type: slot type.
34 * @flags: flags applicable to the slot.
35 *
36 * This struct stores the CA slot information.
37 *
38 * @type can be:
39 *
40 * - %CA_CI - CI high level interface;
41 * - %CA_CI_LINK - CI link layer level interface;
42 * - %CA_CI_PHYS - CI physical layer level interface;
43 * - %CA_DESCR - built-in descrambler;
44 * - %CA_SC -simple smart card interface.
45 *
46 * @flags can be:
47 *
48 * - %CA_CI_MODULE_PRESENT - module (or card) inserted;
49 * - %CA_CI_MODULE_READY - module is ready for usage.
50 */
51
52struct ca_slot_info {
53 int num;
54 int type;
55#define CA_CI 1
56#define CA_CI_LINK 2
57#define CA_CI_PHYS 4
58#define CA_DESCR 8
59#define CA_SC 128
60
61 unsigned int flags;
62#define CA_CI_MODULE_PRESENT 1
63#define CA_CI_MODULE_READY 2
64};
65
66
67/**
68 * struct ca_descr_info - descrambler types and info.
69 *
70 * @num: number of available descramblers (keys).
71 * @type: type of supported scrambling system.
72 *
73 * Identifies the number of descramblers and their type.
74 *
75 * @type can be:
76 *
77 * - %CA_ECD - European Common Descrambler (ECD) hardware;
78 * - %CA_NDS - Videoguard (NDS) hardware;
79 * - %CA_DSS - Distributed Sample Scrambling (DSS) hardware.
80 */
81struct ca_descr_info {
82 unsigned int num;
83 unsigned int type;
84#define CA_ECD 1
85#define CA_NDS 2
86#define CA_DSS 4
87};
88
89/**
90 * struct ca_caps - CA slot interface capabilities.
91 *
92 * @slot_num: total number of CA card and module slots.
93 * @slot_type: bitmap with all supported types as defined at
94 * &struct ca_slot_info (e. g. %CA_CI, %CA_CI_LINK, etc).
95 * @descr_num: total number of descrambler slots (keys)
96 * @descr_type: bitmap with all supported types as defined at
97 * &struct ca_descr_info (e. g. %CA_ECD, %CA_NDS, etc).
98 */
99struct ca_caps {
100 unsigned int slot_num;
101 unsigned int slot_type;
102 unsigned int descr_num;
103 unsigned int descr_type;
104};
105
106/**
107 * struct ca_msg - a message to/from a CI-CAM
108 *
109 * @index: unused
110 * @type: unused
111 * @length: length of the message
112 * @msg: message
113 *
114 * This struct carries a message to be send/received from a CI CA module.
115 */
116struct ca_msg {
117 unsigned int index;
118 unsigned int type;
119 unsigned int length;
120 unsigned char msg[256];
121};
122
123/**
124 * struct ca_descr - CA descrambler control words info
125 *
126 * @index: CA Descrambler slot
127 * @parity: control words parity, where 0 means even and 1 means odd
128 * @cw: CA Descrambler control words
129 */
130struct ca_descr {
131 unsigned int index;
132 unsigned int parity;
133 unsigned char cw[8];
134};
135
136#ifdef CONFIG_AMLOGIC_DVB_COMPAT
137/* CW type. */
138enum ca_cw_type {
139 CA_CW_DVB_CSA_EVEN,
140 CA_CW_DVB_CSA_ODD,
141 CA_CW_AES_EVEN,
142 CA_CW_AES_ODD,
143 CA_CW_AES_EVEN_IV,
144 CA_CW_AES_ODD_IV,
145 CA_CW_DES_EVEN,
146 CA_CW_DES_ODD,
147 CA_CW_SM4_EVEN,
148 CA_CW_SM4_ODD,
149 CA_CW_SM4_EVEN_IV,
150 CA_CW_SM4_ODD_IV,
151 CA_CW_TYPE_MAX
152};
153
154enum ca_dsc_mode {
155 CA_DSC_CBC = 1,
156 CA_DSC_ECB,
157 CA_DSC_IDSA
158};
159
160struct ca_descr_ex {
161 unsigned int index;
162 enum ca_cw_type type;
163 enum ca_dsc_mode mode;
164 int flags;
165#define CA_CW_FROM_KL 1
166 unsigned char cw[16];
167};
168
169/* add for support sc2 ca*/
170enum ca_sc2_cmd_type {
171 CA_ALLOC,
172 CA_FREE,
173 CA_KEY,
174 CA_GET_STATUS,
175 CA_SET_SCB,
176 CA_SET_ALGO
177};
178
179enum ca_sc2_algo_type {
180 CA_ALGO_AES_ECB_CLR_END,
181 CA_ALGO_AES_ECB_CLR_FRONT,
182 CA_ALGO_AES_CBC_CLR_END,
183 CA_ALGO_AES_CBC_IDSA,
184 CA_ALGO_CSA2,
185 CA_ALGO_DES_SCTE41,
186 CA_ALGO_DES_SCTE52,
187 CA_ALGO_TDES_ECB_CLR_END,
188 CA_ALGO_CPCM_LSA_MDI_CBC,
189 CA_ALGO_CPCM_LSA_MDD_CBC,
190 CA_ALGO_CSA3,
191 CA_ALGO_ASA,
192 CA_ALGO_ASA_LIGHT,
193 CA_ALGO_S17_ECB_CLR_END,
194 CA_ALGO_S17_ECB_CTS,
195 CA_ALGO_UNKNOWN
196};
197
198enum ca_sc2_dsc_type {
199 CA_DSC_COMMON_TYPE,
200 CA_DSC_TSD_TYPE, /*just support AES descramble.*/
201 CA_DSC_TSE_TYPE /*just support AES enscramble.*/
202};
203
204/**
205 * struct ca_alloc - malloc ca slot index by params
206 *
207 * @pid: slot use pid.
208 * @algo: use the algorithm
209 * @dsc_type: CA_DSC_COMMON_TYPE:support all ca_algo_type
210 * CA_DSC_TSD_TYPE & CA_DSC_TSE_TYPE just support AES
211 * @ca_index: return slot index.
212 */
213struct ca_sc2_alloc {
214 unsigned int pid;
215 enum ca_sc2_algo_type algo;
216 enum ca_sc2_dsc_type dsc_type;
217 unsigned int ca_index;
218 unsigned char loop;
219};
220
221/**
222 * struct ca_sc2_free - free slot index
223 *
224 * @ca_index: need free slot index.
225 */
226struct ca_sc2_free {
227 unsigned int ca_index;
228};
229
230enum ca_sc2_key_type {
231 CA_KEY_EVEN_TYPE,
232 CA_KEY_EVEN_IV_TYPE,
233 CA_KEY_ODD_TYPE,
234 CA_KEY_ODD_IV_TYPE,
235 CA_KEY_00_TYPE,
236 CA_KEY_00_IV_TYPE
237};
238
239/**
240 * struct ca_sc2_key - set key slot index
241 *
242 * @ca_index: use slot index.
243 * @parity: key type (odd/even/key00)
244 * @key_index: key store index.
245 */
246struct ca_sc2_key {
247 unsigned int ca_index;
248 enum ca_sc2_key_type parity;
249 unsigned int key_index;
250};
251
252/**
253 * struct ca_sc2_scb - set scb
254 *
255 * @ca_index: use slot index.
256 * @ca_scb: ca_scb (2bit)
257 * @ca_scb_as_is:if 1, scb use original
258 * if 0, use ca_scb
259 */
260struct ca_sc2_scb {
261 unsigned int ca_index;
262 unsigned char ca_scb;
263 unsigned char ca_scb_as_is;
264};
265
266/**
267 * struct ca_sc2_algo - set algo
268 *
269 * @ca_index: use slot index.
270 * @algo: algo
271 */
272struct ca_sc2_algo {
273 unsigned int ca_index;
274 enum ca_sc2_algo_type algo;
275};
276
277/**
278 * struct ca_sc2_descr_ex - ca extend descriptor
279 *
280 * @params: command resource params
281 */
282struct ca_sc2_descr_ex {
283 enum ca_sc2_cmd_type cmd;
284 union {
285 struct ca_sc2_alloc alloc_params;
286 struct ca_sc2_free free_params;
287 struct ca_sc2_key key_params;
288 struct ca_sc2_scb scb_params;
289 struct ca_sc2_algo algo_params;
290 } params;
291};
292
293struct ca_pid {
294 unsigned int pid;
295 int index; /* -1 == disable*/
296};
297
298#endif /*CONFIG_AMLOGIC_DVB_COMPAT*/
299#define CA_RESET _IO('o', 128)
300#define CA_GET_CAP _IOR('o', 129, struct ca_caps)
301#define CA_GET_SLOT_INFO _IOR('o', 130, struct ca_slot_info)
302#define CA_GET_DESCR_INFO _IOR('o', 131, struct ca_descr_info)
303#define CA_GET_MSG _IOR('o', 132, struct ca_msg)
304#define CA_SEND_MSG _IOW('o', 133, struct ca_msg)
305#define CA_SET_DESCR _IOW('o', 134, struct ca_descr)
306#ifdef CONFIG_AMLOGIC_DVB_COMPAT
307#define CA_SET_PID _IOW('o', 135, struct ca_pid)
308#define CA_SET_DESCR_EX _IOW('o', 200, struct ca_descr_ex)
309#define CA_SC2_SET_DESCR_EX _IOWR('o', 201, struct ca_sc2_descr_ex)
310#endif
311#if !defined(__KERNEL__)
312
313/* This is needed for legacy userspace support */
314typedef struct ca_slot_info ca_slot_info_t;
315typedef struct ca_descr_info ca_descr_info_t;
316typedef struct ca_caps ca_caps_t;
317typedef struct ca_msg ca_msg_t;
318typedef struct ca_descr ca_descr_t;
319
320#endif
321
322
323#endif