source: tools/oebuild/data/pti_np/pti_descrambler.c @ 45168

Last change on this file since 45168 was 45168, checked in by obi, 19 months ago

add oebuild building files

  • Property svn:executable set to *
File size: 13.4 KB
Line 
1#include <linux/init.h>
2#include <linux/slab.h>
3#include <linux/wait.h>
4#include <linux/module.h>
5#include <linux/usb.h>
6#include <linux/delay.h>
7#include <linux/time.h>
8#include <linux/errno.h>
9
10#include <linux/version.h>
11
12#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
13#include <linux/semaphore.h>
14#else
15#include <asm/semaphore.h>
16#endif
17#include <linux/platform_device.h>
18#include <linux/mutex.h>
19
20#include "pti.h"
21#include "pti_main.h"
22
23void pti_descrambler_allocate(u32 tc_descrambler_index)
24{
25        STPTI_TCParameters_t *TC_Params_p = &tc_params;
26        TCKey_t *Key_p;
27        if (tc_descrambler_index < 0)
28        {
29                printk("%s: Invalid descrambler index passed %d\n", __func__, tc_descrambler_index);
30                return;
31        }
32        Key_p =
33                (TCKey_t *)((u32)(&(TC_Params_p->TC_DescramblerKeysStart)[0])
34                            + ((u16) tc_descrambler_index * TC_Params_p->TC_SizeOfDescramblerKeys));
35        /* mark as not valid */
36        STSYS_SetTCMask16LE((void *)&Key_p->KeyValidity, 0);
37}
38
39/* fixme: logisch gesehen auch eher link slot with descrambler ;) */
40void pti_descrambler_associate_with_slot(u32 tc_descrambler_index, u32 tc_slot_index)
41{
42        STPTI_TCParameters_t *TC_Params_p = &tc_params;
43        TCKey_t *Key_p;
44        TCMainInfo_t *MainInfo_p;
45        if (tc_descrambler_index < 0)
46        {
47                printk("%s: Invalid descrambler index passed %d\n", __func__, tc_descrambler_index);
48                return;
49        }
50        if (tc_slot_index < 0)
51        {
52                printk("%s: Invalid slot index passed %d\n", __func__, tc_slot_index);
53                return;
54        }
55        Key_p =
56                (TCKey_t *)((u32)(&(TC_Params_p->TC_DescramblerKeysStart)[0])
57                            + ((u16) tc_descrambler_index * TC_Params_p->TC_SizeOfDescramblerKeys));
58        printk("(da %d, %d)", tc_descrambler_index, tc_slot_index);
59        MainInfo_p = &((TCMainInfo_t *)TC_Params_p->TC_MainInfoStart)[tc_slot_index];
60        /* convert ST20.40 address in TCKey_p to one that the TC understands */
61        STSYS_WriteTCReg16LE((void *)&MainInfo_p->DescramblerKeys_p, (u32)((u8 *)Key_p - (u8 *)TC_Params_p->TC_DataStart + (u8 *)TC_DSRAM_BASE));
62        /* slot now does not ignore the descrambler */
63        STSYS_ClearTCMask16LE((void *)&MainInfo_p->SlotMode, (TC_MAIN_INFO_SLOT_MODE_IGNORE_SCRAMBLING));
64}
65
66/* auch eher eine reine slot aktion */
67void pti_descrambler_disassociate_from_slot(u32 tc_descrambler_index, u32 tc_slot_index)
68{
69        STPTI_TCParameters_t *TC_Params_p = &tc_params;
70        TCMainInfo_t *MainInfo_p;
71        if (tc_slot_index < 0)
72        {
73                printk("%s: Invalid slot index passed %d\n", __func__, tc_slot_index);
74                return;
75        }
76        MainInfo_p = &((TCMainInfo_t *)TC_Params_p->TC_MainInfoStart)[tc_slot_index];
77        STSYS_WriteTCReg16LE((u32)&MainInfo_p->DescramblerKeys_p, TC_INVALID_LINK);
78}
79
80/* wenn werte richtig dann, assignment pid - slot in beiden versionen dumpen */
81void dumpDescrambler(TCKey_t *Key_p)
82{
83        int vLoop = 1;
84        printk("%d. Validity = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->KeyValidity));
85        printk("%d. Mode = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->KeyMode));
86        printk("%d. Even0 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey0));
87        printk("%d. Even1 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey1));
88        printk("%d. Even2 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey2));
89        printk("%d. Even3 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey3));
90        printk("%d. Even4 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey4));
91        printk("%d. Even5 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey5));
92        printk("%d. Even6 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey6));
93        printk("%d. Even7 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenKey7));
94        printk("%d. Odd0 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey0));
95        printk("%d. Odd1 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey1));
96        printk("%d. Odd2 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey2));
97        printk("%d. Odd3 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey3));
98        printk("%d. Odd4 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey4));
99        printk("%d. Odd5 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey5));
100        printk("%d. Odd6 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey6));
101        printk("%d. Odd7 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddKey7));
102        printk("%d. EvenIV0 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV0));
103        printk("%d. EvenIV1 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV1));
104        printk("%d. EvenIV2 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV2));
105        printk("%d. EvenIV3 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV3));
106        printk("%d. EvenIV4 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV4));
107        printk("%d. EvenIV5 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV5));
108        printk("%d. EvenIV6 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV6));
109        printk("%d. EvenIV7 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->EvenIV7));
110        printk("%d. OddIV0 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV0));
111        printk("%d. OddIV1 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV1));
112        printk("%d. OddIV2 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV2));
113        printk("%d. OddIV3 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV3));
114        printk("%d. OddIV4 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV4));
115        printk("%d. OddIV5 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV5));
116        printk("%d. OddIV6 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV6));
117        printk("%d. OddIV7 = 0x%.4x\n", vLoop, (unsigned int) readw(&Key_p ->OddIV7));
118}
119
120void pti_descrambler_set(u32 tc_descrambler_index, int Parity, u8 *Data)
121{
122        STPTI_TCParameters_t *TC_Params_p = &tc_params;
123        TCKey_t *Key_p;
124        u16 /*KeyCheck, */KeyValidity = 0, KeyMode = 0;
125        if (tc_descrambler_index < 0)
126        {
127                printk("%s: Invalid descrambler index passed %d\n", __func__, tc_descrambler_index);
128                return;
129        }
130        Key_p = (TCKey_t *)((u32)(&(TC_Params_p->TC_DescramblerKeysStart)[0])
131                            + ((u16) tc_descrambler_index * TC_Params_p->TC_SizeOfDescramblerKeys));
132        dprintk("%s > (%d)\n", __func__, tc_descrambler_index);
133        /* As the key could be in use we update KeyValidity in a single write */
134        KeyValidity = readw((void *)&Key_p->KeyValidity);
135        /* Mask off the Algorithm, Chaining Mode, and Residue Mode (LeftResidue or RightResidue) */
136        KeyValidity &= ~(TCKEY_ALGORITHM_MASK | TCKEY_CHAIN_ALG_MASK | TCKEY_CHAIN_MODE_LR);
137        KeyValidity |= TCKEY_ALGORITHM_DVB;
138#if defined(SECURE_LITE2)
139        KeyMode = readw((void *)&Key_p->KeyMode);
140        KeyMode &= ~(TCKEY_MODE_EAVS | TCKEY_MODE_PERM0 | TCKEY_MODE_PERM1);
141        STSYS_WriteTCReg16LE((void *)&Key_p->KeyMode, KeyMode);
142#endif
143        /* fixme: das hab ich geaendert im gegensatz zum orig */
144        /* das habe ich auskommentiert warum diese umständliche Prüfung ?
145        wenn das cw alles 0 hat soll es doch in die Register schreiben
146        KeyValidity wird doch sowieso überschrieben */
147#if 0
148        if ((Data[0] == 0) && (Data[1] == 0) && (Data[2] == 0) && (Data[3] == 0) &&
149                        (Data[4] == 0) && (Data[5] == 0) && (Data[6] == 0) && (Data[7] == 0))
150        {
151                if (Parity == 0 /* even */)
152                {
153                        STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey0, 0);
154                        STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey1, 0);
155                        STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey2, 0);
156                        STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey3, 0);
157                }
158                else /* STPTI_KEY_PARITY_ODD_PARITY */
159                {
160                        STSYS_WriteTCReg16LE((void *)&Key_p->OddKey0, 0);
161                        STSYS_WriteTCReg16LE((void *)&Key_p->OddKey1, 0);
162                        STSYS_WriteTCReg16LE((void *)&Key_p->OddKey2, 0);
163                        STSYS_WriteTCReg16LE((void *)&Key_p->OddKey3, 0);
164                }
165                KeyCheck = readw((void *)&Key_p->EvenKey0) |
166                           readw((void *)&Key_p->EvenKey1) |
167                           readw((void *)&Key_p->EvenKey2) |
168                           readw((void *)&Key_p->EvenKey3);
169                KeyCheck |= readw((void *)&Key_p->OddKey0) |
170                            readw((void *)&Key_p->OddKey1) |
171                            readw((void *)&Key_p->OddKey2) |
172                            readw((void *)&Key_p->OddKey3);
173                if (0 == KeyCheck)
174                {
175                        /* if all keys zero then mark as not valid */
176                        /* this makes no sense because we leave in next statement
177                         * but that's what stapi is doing here ;)
178                         */
179                        KeyValidity = 0;
180                }
181                return;
182        }
183#endif
184        /* --- valid key of some type to process --- */
185        if (Parity == 0 /* even */)
186        {
187                //dprintk("%s seeting even key\n", __func__);
188                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey0, (Data[0] << 8) | Data[1]);
189                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey1, (Data[2] << 8) | Data[3]);
190                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey2, (Data[4] << 8) | Data[5]);
191                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey3, (Data[6] << 8) | Data[7]);
192                KeyValidity |= TCKEY_VALIDITY_TS_EVEN;
193                /* KeyValidity |= TCKEY_VALIDITY_PES_EVEN; */
194        }
195        else /* STPTI_KEY_PARITY_ODD_PARITY */
196        {
197                //dprintk("%s seeting odd key\n", __func__);
198                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey0, (Data[0] << 8) | Data[1]);
199                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey1, (Data[2] << 8) | Data[3]);
200                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey2, (Data[4] << 8) | Data[5]);
201                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey3, (Data[6] << 8) | Data[7]);
202                KeyValidity |= TCKEY_VALIDITY_TS_ODD;
203                /* KeyValidity |= TCKEY_VALIDITY_PES_ODD; */
204        }
205        STSYS_WriteTCReg16LE((void *)&Key_p->KeyValidity, KeyValidity);
206#ifdef CONFIG_PRINTK
207        printk("Validity = 0x%.4x Mode = 0x%.4x\n", (unsigned int) readw(&Key_p ->KeyValidity), (unsigned int) readw(&Key_p ->KeyMode));
208#endif
209        //dumpDescrambler(Key_p);
210        dprintk("%s <\n", __func__);
211        return;
212}
213
214void pti_descrambler_set_aes(u32 tc_descrambler_index, int Parity, u8 *Data, int data_type)
215{
216        STPTI_TCParameters_t *TC_Params_p = &tc_params;
217        TCKey_t *Key_p;
218        u16 KeyValidity = 0, KeyMode = 0;
219        if (tc_descrambler_index < 0)
220        {
221                printk("%s: Invalid descrambler index passed %d\n", __func__, tc_descrambler_index);
222                return;
223        }
224        Key_p =
225                (TCKey_t *)((u32)(&(TC_Params_p->TC_DescramblerKeysStart)[0])
226                            + ((u16) tc_descrambler_index * TC_Params_p->TC_SizeOfDescramblerKeys));
227        dprintk("%s > (%d)\n", __func__, tc_descrambler_index);
228        /* As the key could be in use we update KeyValidity in a single write */
229        /* maintain previous keys validity */
230        KeyValidity = readw((void *)&Key_p->KeyValidity);
231        /* Mask off the Algorithm, Chaining Mode, and Residue Mode (LeftResidue or RightResidue) */
232        KeyValidity &= ~(TCKEY_ALGORITHM_MASK | TCKEY_CHAIN_ALG_MASK | TCKEY_CHAIN_MODE_LR);
233        /*STPTI_DESCRAMBLER_TYPE_AES_CBC_DESCRAMBLER*/
234        KeyValidity |= TCKEY_ALGORITHM_AES | TCKEY_CHAIN_ALG_CBC;
235        /*STPTI_DESCRAMBLER_TYPE_AES_CBC_DVS042_DESCRAMBLER*/
236        //KeyValidity |= TCKEY_ALGORITHM_AES | TCKEY_CHAIN_ALG_CBC_IV;
237#if defined(SECURE_LITE2)
238        KeyMode = readw((void *)&Key_p->KeyMode);
239        KeyMode &= ~(TCKEY_MODE_EAVS | TCKEY_MODE_PERM0 | TCKEY_MODE_PERM1);
240        STSYS_WriteTCReg16LE((void *)&Key_p->KeyMode, KeyMode);
241#endif
242        /* --- valid key of some type to process --- */
243        if (Parity == 0 /* STPTI_KEY_PARITY_EVEN_PARITY */)
244        {
245                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey4, (Data[0] << 8) | Data[1]);
246                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey5, (Data[2] << 8) | Data[3]);
247                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey6, (Data[4] << 8) | Data[5]);
248                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey7, (Data[6] << 8) | Data[7]);
249                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey0, (Data[8] << 8) | Data[9]);
250                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey1, (Data[10] << 8) | Data[11]);
251                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey2, (Data[12] << 8) | Data[13]);
252                STSYS_WriteTCReg16LE((void *)&Key_p->EvenKey3, (Data[14] << 8) | Data[15]);
253                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV0, (Data[16] << 8) | Data[17]);
254                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV1, (Data[18] << 8) | Data[19]);
255                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV2, (Data[20] << 8) | Data[21]);
256                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV3, (Data[22] << 8) | Data[23]);
257                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV4, (Data[24] << 8) | Data[25]);
258                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV5, (Data[26] << 8) | Data[27]);
259                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV6, (Data[28] << 8) | Data[29]);
260                STSYS_WriteTCReg16LE((void *)&Key_p->EvenIV7, (Data[30] << 8) | Data[31]);
261                KeyValidity |= TCKEY_VALIDITY_TS_EVEN;
262        }
263        else /* STPTI_KEY_PARITY_ODD_PARITY */
264        {
265                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey4, (Data[0] << 8) | Data[1]);
266                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey5, (Data[2] << 8) | Data[3]);
267                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey6, (Data[4] << 8) | Data[5]);
268                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey7, (Data[6] << 8) | Data[7]);
269                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey0, (Data[8] << 8) | Data[9]);
270                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey1, (Data[10] << 8) | Data[11]);
271                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey2, (Data[12] << 8) | Data[13]);
272                STSYS_WriteTCReg16LE((void *)&Key_p->OddKey3, (Data[14] << 8) | Data[15]);
273                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV0, (Data[16] << 8) | Data[17]);
274                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV1, (Data[18] << 8) | Data[19]);
275                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV2, (Data[20] << 8) | Data[21]);
276                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV3, (Data[22] << 8) | Data[23]);
277                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV4, (Data[24] << 8) | Data[25]);
278                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV5, (Data[26] << 8) | Data[27]);
279                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV6, (Data[28] << 8) | Data[29]);
280                STSYS_WriteTCReg16LE((void *)&Key_p->OddIV7, (Data[30] << 8) | Data[31]);
281                KeyValidity |= TCKEY_VALIDITY_TS_ODD;
282        }
283        /* As the key could be in use we update KeyValidity in a single write */
284        STSYS_WriteTCReg16LE((void *)&Key_p->KeyValidity, KeyValidity);
285        //STSYS_WriteTCReg16LE((void *)&Key_p->KeyMode, KeyMode);
286#ifdef CONFIG_PRINTK
287        printk("Validity = 0x%.4x Mode = 0x%.4x\n", (unsigned int) readw(&Key_p ->KeyValidity), (unsigned int) readw(&Key_p ->KeyMode));
288#endif
289        //dumpDescrambler(Key_p);
290        dprintk("%s <\n", __func__);
291        return;
292}
293
Note: See TracBrowser for help on using the repository browser.