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