This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser.h
200 lines (167 loc) · 8.08 KB
/
parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "irdeto_core.h"
uint8_t frame[188];
uint8_t chid[2];
uint8_t keyid;
uint8_t provider;
uint8_t casid[2];
uint8_t streamid[2];// 0f,20
uint8_t ecmid[2]; //15,16
uint8_t cpdura[2];//1b, 1c
uint8_t cw0[8];
uint8_t cw1[8];
uint8_t acc[20];
uint8_t cwnum[2];
uint8_t cpnum[2];
const uint8_t ans0003[0x57] = {
//00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f
0x02 , 0x00 , 0x03 , 0x00 , 0x51 , 0x00 , 0x0e , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x01 , 0x01,
0x00 , 0x16 , 0x00 , 0x02 , 0x00 , 0xc8 , 0x00 , 0x17 , 0x00 , 0x02 , 0x00 , 0xc8 , 0x00 , 0x03 , 0x00 , 0x02,
0x00 , 0xc8 , 0x00 , 0x04 , 0x00 , 0x02 , 0x00 , 0xc8 , 0x00 , 0x05 , 0x00 , 0x02 , 0xfe , 0x0c , 0x00 , 0x06,
0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x07 , 0x00 , 0x02 , 0x00 , 0x64 , 0x00 , 0x08 , 0x00 , 0x02 , 0x00 , 0x00,
0x00 , 0x09 , 0x00 , 0x02 , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x01 , 0x01 , 0x00 , 0x0b , 0x00 , 0x01 , 0x02,
0x00 , 0x0c , 0x00 , 0x02 , 0x00 , 0x64 , 0x00
};
const uint8_t ans0103[0x1d] = {
//00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f
0x02 , 0x01 , 0x03 , 0x00 , 0x17 , 0x00 , 0x0e , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x0f , 0x00 , 0x02 , 0x00,
0x00 , 0x00 , 0x19 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x11 , 0x00 , 0x01 , 0x00 , 0x00
};
/*
const unsigned char ans0202[0x46] = {
0x02 , 0x02 , 0x02 , 0x00 , 0x3f , 0x00 , 0x0e , 0x00 , 0x02 , 0xb1 , 0x01 , 0x00 , 0x0f , 0x00 , 0x02 , 0x00,
0x01 , 0x00 , 0x12 , 0x00 , 0x02 , 0x00 , 0x01 , 0x00 , 0x15 , 0x00 , 0x29 , 0x00 , 0x00 , 0x26 , 0x00 , 0x00,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
};
*/
const uint8_t ans0202[0xd8] = {
0x02, 0x02, 0x02, 0x00, 0xd2, 0x00, 0x0e, 0x00, 0x02, 0xff, 0xff, 0x00, 0x0f, 0x00, 0x02, 0xff,
0xff, 0x00, 0x12, 0x00, 0x02, 0xff, 0xff, 0x00, 0x15, 0x00, 0xbc, 0x47, 0x5f, 0xff, 0x10, 0x00,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
};
const uint8_t ans0105[0x12] = {
0x02 , 0x01 , 0x05 , 0x00 , 0x0c , 0x00 , 0x0e , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x0f , 0x00 , 0x02 , 0x00,
0x00 , 0x00
};
/*
*/
void parse(char *daten,uint8_t menge,char *zurueck,int& senden){
//printf("\nins00 ");
if (daten[1]==0x0 && daten[2]==0x01){
//printf("cla01 \n");
chid[0]=daten[0x9];chid[1]=daten[0xa];
casid[0]=daten[0xf];casid[1]=daten[0x10];
for(int i = 0;i <= ans0003[4]+5;i++){ zurueck[i] = ans0003[i];}
zurueck[0x09]=chid[0];zurueck[0x0a]=chid[1];
senden = 1;
}
//printf("\nins01 ");
else if (daten[1] == 0x00 && daten[2] == 0x04){
senden = 0;
}
else if(daten[1]==0x1 && daten[2]==0x01){
//printf("cla01 \n");
streamid[0]=daten[0x0f];streamid[1]=daten[0x10];
ecmid[0]=daten[0x15];ecmid[1]= daten[0x16];
cpdura[0]=daten[0x1b];cpdura[1]=daten[0x1c];
for(int i = 0;i <= ans0103[4]+5;i++){ zurueck[i] = ans0103[i];}
zurueck[0x09]=chid[0];zurueck[0x0a]=chid[1];
zurueck[0x0f]=streamid[0];zurueck[0x10]=streamid[1];
zurueck[0x15]=ecmid[0];zurueck[0x16]=ecmid[1];
senden = 1;
}
else if (daten[1]==0x1 && daten[2]==0x04){
for(int i = 0;i <= ans0105[4]+5;i++){ zurueck[i] = ans0105[i];}
zurueck[0x09]=daten[0x09];zurueck[0x0a]=daten[0x0a];
zurueck[0x0f]=daten[0x0f];zurueck[0x10]=daten[0x10];
senden = 1;
}
else if(daten[1]==0x2 &&daten[2]==0x01){
for (int i = 5; i <= daten[4]+5;i++){
if(daten[i] == 0x00 && daten[i+1] == 0x14 && daten[i+3]== 0x0a) { //CW0 CW1
//printf("Found CW! \n");
cwnum[0] = daten[i+4]; cwnum[1] = daten[i+5];
if ((cwnum[1] & 1) == 1){
for(int j=0;j<=7;j++){cw1[j] = daten[i+6+j]&0xff;}
}
else {
for(int j=0;j<=7;j++){cw0[j] = daten[i+6+j]&0xff;}
}
i += daten[i+3]+3;
}
else if(daten[i] == 0x00 && daten[i+1] == 0x0e && daten[i+3]== 0x02){ //CHID
//printf("\nchid found \n");
chid[0] = daten[i+4]&0xff;chid[1] = daten[i+5]&0xff;
i += daten[i+3]+3;
}
else if(daten[i] == 0x00 && daten[i+1] == 0x0f && daten[i+3]== 0x02) { //streamid
//printf("stream id found \n");
streamid[0]=daten[i+4];streamid[1]=daten[i+5];
i += daten[i+3]+3;
}
else if(daten[i] == 0x00 && daten[i+1] == 0x13 && daten[i+3]== 0x02) { //cp duration
//printf("cp duration found \n");
cpdura[0] = daten[i+4];cpdura[1] = daten[i+5];
i += daten[i+3]+3;
}
else if(daten[i] == 0x00 && daten[i+1] == 0x12 && daten[i+3]== 0x02) {
//printf("cp number found \n");
cpnum[0] = daten[i+4];cpnum[1] = daten[i+5];
i += daten[i+3]+3;
}
else if(daten[i] == 0x00 && daten[i+1] == 0x0d && daten[i+3] > 0x0) {
//printf("access criteria found: \n");
for(int j= 0;j <= daten[i+3]+3;j++){acc[j] = daten[i+3+j];}
i += daten[i+3]+3;
}
}
printf("\nCW0: ");
for(int j=0;j<=7;j++){printf("%02X ",cw0[j]);}
printf("\nCW1: ");
for(int j=0;j<=7;j++){printf("%02X ",cw1[j]);}
printf("\nAccess-Criteria: ");
for(int j=1;j<=acc[0];j++){printf("%02X ",acc[j]&0xff);}
printf("\nCHID: %02X %02X \n",chid[0]&0xff,chid[1]&0xff);
printf("STREAM ID: %02X %02X \n",streamid[0]&0xff,streamid[1]&0xff);
printf("CP Number: %02X %02X \n",cpnum[0],cpnum[1]);
printf("CP DURATION: %02X %02X (%d sec.) \n",cpdura[0]&0xff,cpdura[1]&0xff,(cpdura[1]&0xff)/10);
printf("\n");
if ((cpnum[1]&0x1) == 1){frame[0] = 0x1;}
else {frame[0] = 0x00;}
frame[1] = 0x00;
generate_ecm(frame,chid,acc[1],acc[2],cw0,cw1);
frame[0]=0;
printf("ECM to SEND: \n");
//for (int i=0;i <= 0x25 ;i++){printf("%02X ",frame[i]);}
//printf("\n\n\n");
for(int i = 0;i <= ans0202[4]+5;i++){ zurueck[i] = (ans0202[i] & 0xff);}
if ((cpnum[1]&0x1) == 1){zurueck[0x20] = 0x81;}
else {zurueck[0x20] = 0x80;}
zurueck[0x21]=0x70;
//02 02 02 00 3F 00 0E 00 02 75 30 00 0F 00 02 33 33 00 12 00 02 00 06 00 15 00 29 80 70 26 00 00 23 75 30 10 0A 00 1D 00 02 08 23 78 12 0A 01 F4 A0 E4 69 A0 D0 8E 0E 2C 7A 2C 04 FC 4E 8B D7 88 AE F8 F1 A6
//zurueck[0x2d] = zurueck[0x30] + 3;
//zurueck[0x2a] = zurueck[0x2d] + 3;
//zurueck[0x04] = zurueck[0x2a] + 0x16;
for (int i=0;i <= 0x25 ;i++){printf("%02X ",frame[i]);zurueck[0x23 + i]=frame[i];}
printf("\n");
zurueck[0x09]=chid[0];zurueck[0x0a]=chid[1];
zurueck[0x0f]=streamid[0];zurueck[0x10]=streamid[1];
zurueck[0x15]=cpnum[0];zurueck[0x16]=cpnum[1];
zurueck[0x22] = zurueck[0x25] + 3;
//for(int i = 0;i <= (zurueck[4]+5 &0xff );i++){ printf("%02X ",zurueck[i]&0xff);}
senden = 1;
}
printf("\n");
}