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