1 | //FIXME Not checked on threadsafety yet; after checking please remove this line
|
---|
2 | #include <sys/time.h>
|
---|
3 | #include "globals.h"
|
---|
4 | #include "module-cccam.h"
|
---|
5 |
|
---|
6 | void aes_set_key(char *key)
|
---|
7 | {
|
---|
8 | AES_set_decrypt_key((const unsigned char *)key, 128, &cur_client()->aeskey_decrypt);
|
---|
9 | AES_set_encrypt_key((const unsigned char *)key, 128, &cur_client()->aeskey);
|
---|
10 | }
|
---|
11 |
|
---|
12 | void aes_decrypt(uchar *buf, int n)
|
---|
13 | {
|
---|
14 | int i;
|
---|
15 | for(i=0; i<n; i+=16)
|
---|
16 | AES_decrypt(buf+i, buf+i, &cur_client()->aeskey_decrypt);
|
---|
17 | }
|
---|
18 |
|
---|
19 | void aes_encrypt_idx(struct s_client *cl, uchar *buf, int n)
|
---|
20 | {
|
---|
21 | int i;
|
---|
22 | for(i=0; i<n; i+=16)
|
---|
23 | AES_encrypt(buf+i, buf+i, &cl->aeskey);
|
---|
24 | }
|
---|
25 |
|
---|
26 | void add_aes_entry(struct s_reader *rdr, ushort caid, uint32 ident, int keyid, uchar *aesKey)
|
---|
27 | {
|
---|
28 | AES_ENTRY *new_entry;
|
---|
29 | AES_ENTRY *next,*current;
|
---|
30 |
|
---|
31 | // create de AES key entry for the linked list
|
---|
32 | if(!cs_malloc(&new_entry, sizeof(AES_ENTRY), -1)) return;
|
---|
33 |
|
---|
34 | memcpy(new_entry->plainkey, aesKey, 16);
|
---|
35 | new_entry->caid=caid;
|
---|
36 | new_entry->ident=ident;
|
---|
37 | new_entry->keyid=keyid;
|
---|
38 | if(memcmp(aesKey,"\xFF\xFF",2)) {
|
---|
39 | AES_set_decrypt_key((const unsigned char *)aesKey, 128, &(new_entry->key));
|
---|
40 | // cs_log("adding key : %s",cs_hexdump(1,aesKey,16));
|
---|
41 | }
|
---|
42 | else {
|
---|
43 | memset(&new_entry->key,0,sizeof(AES_KEY));
|
---|
44 | // cs_log("adding fake key");
|
---|
45 | }
|
---|
46 | new_entry->next=NULL;
|
---|
47 |
|
---|
48 | //if list is empty, new_entry is the new head
|
---|
49 | if(!rdr->aes_list) {
|
---|
50 | rdr->aes_list=new_entry;
|
---|
51 | return;
|
---|
52 | }
|
---|
53 |
|
---|
54 | //happend it to the list
|
---|
55 | current=rdr->aes_list;
|
---|
56 | next=current->next;
|
---|
57 | while(next) {
|
---|
58 | current=next;
|
---|
59 | next=current->next;
|
---|
60 | }
|
---|
61 |
|
---|
62 | current->next=new_entry;
|
---|
63 |
|
---|
64 | }
|
---|
65 |
|
---|
66 | void parse_aes_entry(struct s_reader *rdr,char *value) {
|
---|
67 | ushort caid;
|
---|
68 | ushort dummy;
|
---|
69 | uint32 ident;
|
---|
70 | int len;
|
---|
71 | char *tmp;
|
---|
72 | int nb_keys,key_id;
|
---|
73 | uchar aes_key[16];
|
---|
74 | char *save=NULL;
|
---|
75 |
|
---|
76 | tmp=strtok_r(value,"@",&save);
|
---|
77 | caid=a2i(tmp,2);
|
---|
78 | tmp=strtok_r(NULL,":",&save);
|
---|
79 | ident=a2i(tmp,3);
|
---|
80 |
|
---|
81 | // now we need to split the key ane add the entry to the reader.
|
---|
82 | nb_keys=0;
|
---|
83 | key_id=0;
|
---|
84 | while((tmp=strtok_r(NULL,",",&save))) {
|
---|
85 | dummy=0;
|
---|
86 | len=strlen(tmp);
|
---|
87 | if(len!=32) {
|
---|
88 | dummy=a2i(tmp,1);
|
---|
89 | // FF means the card will do the AES decrypt
|
---|
90 | // 00 means we don't have the aes.
|
---|
91 | if((dummy!=0xFF && dummy!=0x00) || len>2) {
|
---|
92 | key_id++;
|
---|
93 | cs_log("AES key length error .. not adding");
|
---|
94 | continue;
|
---|
95 | }
|
---|
96 | if(dummy==0x00) {
|
---|
97 | key_id++;
|
---|
98 | continue;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | nb_keys++;
|
---|
102 | if(dummy)
|
---|
103 | memset(aes_key,0xFF,16);
|
---|
104 | else
|
---|
105 | key_atob_l(tmp,aes_key,32);
|
---|
106 | // now add the key to the reader... TBD
|
---|
107 | add_aes_entry(rdr,caid,ident,key_id,aes_key);
|
---|
108 | key_id++;
|
---|
109 | }
|
---|
110 |
|
---|
111 | cs_log("%d AES key(s) added on reader %s for %04x:%06x", nb_keys, rdr->label, caid, ident);
|
---|
112 | }
|
---|
113 |
|
---|
114 | void parse_aes_keys(struct s_reader *rdr,char *value)
|
---|
115 | {
|
---|
116 | // value format is caid1@ident1:key0,key1;caid2@indent2:key0,key1
|
---|
117 | char *entry;
|
---|
118 | char *save=NULL;
|
---|
119 |
|
---|
120 | rdr->aes_list=NULL;
|
---|
121 | for (entry=strtok_r(value, ";",&save); entry; entry=strtok_r(NULL, ";",&save)) {
|
---|
122 | parse_aes_entry(rdr,entry);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /*
|
---|
126 | AES_ENTRY *current;
|
---|
127 | current=rdr->aes_list;
|
---|
128 | while(current) {
|
---|
129 | cs_log("**************************");
|
---|
130 | cs_log("current = %p",current);
|
---|
131 | cs_log("CAID = %04x",current->caid);
|
---|
132 | cs_log("IDENT = %06x",current->ident);
|
---|
133 | cs_log("keyID = %d",current->keyid);
|
---|
134 | cs_log("next = %p",current->next);
|
---|
135 | cs_log("**************************");
|
---|
136 | current=current->next;
|
---|
137 | }
|
---|
138 | */
|
---|
139 | }
|
---|
140 |
|
---|
141 | int aes_decrypt_from_list(AES_ENTRY *list, ushort caid, uint32 provid,int keyid, uchar *buf, int n)
|
---|
142 | {
|
---|
143 | AES_ENTRY *current;
|
---|
144 | AES_KEY dummy;
|
---|
145 | int i;
|
---|
146 | int ok=1;
|
---|
147 | int error=0;
|
---|
148 |
|
---|
149 | current=list;
|
---|
150 | while(current) {
|
---|
151 | if(current->caid==caid && current->ident==provid && current->keyid==keyid)
|
---|
152 | break;
|
---|
153 | current=current->next;
|
---|
154 | }
|
---|
155 |
|
---|
156 | if(!current) {
|
---|
157 | cs_log("AES Decrypt : key id %d not found for CAID %04X , provider %06x",keyid,caid,provid);
|
---|
158 | return error; // we don't have the key to decode this buffer.
|
---|
159 | }
|
---|
160 | else {
|
---|
161 | // hack for card that do the AES decrypt themsleves
|
---|
162 | memset(&dummy,0,sizeof(AES_KEY));
|
---|
163 | if(!memcmp(¤t->key,&dummy,sizeof(AES_KEY))) {
|
---|
164 | return ok;
|
---|
165 | }
|
---|
166 | // decode the key
|
---|
167 | for(i=0; i<n; i+=16)
|
---|
168 | AES_decrypt(buf+i, buf+i, &(current->key));
|
---|
169 | }
|
---|
170 | return ok; // all ok, key decoded.
|
---|
171 | }
|
---|
172 |
|
---|
173 | int aes_present(AES_ENTRY *list, ushort caid, uint32 provid,int keyid)
|
---|
174 | {
|
---|
175 | AES_ENTRY *current;
|
---|
176 | int ok=1;
|
---|
177 | int error=0;
|
---|
178 |
|
---|
179 | current=list;
|
---|
180 | while(current) {
|
---|
181 | if(current->caid==caid && current->ident==provid && current->keyid==keyid)
|
---|
182 | break;
|
---|
183 | current=current->next;
|
---|
184 | }
|
---|
185 |
|
---|
186 | if(!current) {
|
---|
187 | cs_log("AES Decrypt : key id %d not found for CAID %04X , provider %06x",keyid,caid,provid);
|
---|
188 | return error; // we don't have the key to decode this buffer.
|
---|
189 | }
|
---|
190 |
|
---|
191 | return ok;
|
---|
192 | }
|
---|
193 |
|
---|
194 | void aes_clear_entries(struct s_reader *rdr)
|
---|
195 | {
|
---|
196 |
|
---|
197 | AES_ENTRY *current;
|
---|
198 | AES_ENTRY *next;
|
---|
199 |
|
---|
200 | current=NULL;
|
---|
201 | next=rdr->aes_list;
|
---|
202 | while(next) {
|
---|
203 | current=next;
|
---|
204 | next=current->next;
|
---|
205 | free(current);
|
---|
206 | }
|
---|
207 | rdr->aes_list=NULL;
|
---|
208 | }
|
---|
209 |
|
---|
210 | char *remote_txt(void)
|
---|
211 | {
|
---|
212 | if (cur_client()->typ == 'c')
|
---|
213 | return("client");
|
---|
214 | else
|
---|
215 | return("remote server");
|
---|
216 | }
|
---|
217 |
|
---|
218 | char *trim(txt)
|
---|
219 | char *txt;
|
---|
220 | {
|
---|
221 | register int l;
|
---|
222 | register char *p1, *p2;
|
---|
223 |
|
---|
224 | if (*txt==' ')
|
---|
225 | {
|
---|
226 | for (p1=p2=txt;
|
---|
227 | (*p1==' ') || (*p1=='\t') || (*p1=='\n') || (*p1=='\r');
|
---|
228 | p1++);
|
---|
229 | while (*p1)
|
---|
230 | *p2++=*p1++;
|
---|
231 | *p2='\0';
|
---|
232 | }
|
---|
233 | if ((l=strlen(txt))>0)
|
---|
234 | for (p1=txt+l-1;
|
---|
235 | (*p1==' ') || (*p1=='\t') || (*p1=='\n') || (*p1=='\r');
|
---|
236 | *p1--='\0');
|
---|
237 |
|
---|
238 | return(txt);
|
---|
239 | }
|
---|
240 |
|
---|
241 | char *strtolower(char *txt)
|
---|
242 | {
|
---|
243 | char *p;
|
---|
244 | for (p=txt; *p; p++)
|
---|
245 | if (isupper((uchar)*p)) *p=tolower((uchar)*p);
|
---|
246 | return(txt);
|
---|
247 | }
|
---|
248 |
|
---|
249 | int gethexval(char c)
|
---|
250 | {
|
---|
251 | if ((c>='0') && (c<='9')) return(c-'0');
|
---|
252 | if ((c>='A') && (c<='F')) return(c-'A'+10);
|
---|
253 | if ((c>='a') && (c<='f')) return(c-'a'+10);
|
---|
254 | return(-1);
|
---|
255 | }
|
---|
256 |
|
---|
257 | int cs_atob(uchar *buf, char *asc, int n)
|
---|
258 | {
|
---|
259 | int i, rc;
|
---|
260 | for (i=0; i<n; i++)
|
---|
261 | {
|
---|
262 | if ((rc=(gethexval(asc[i<<1])<<4)|gethexval(asc[(i<<1)+1]))&0x100)
|
---|
263 | return(-1);
|
---|
264 | buf[i]=rc;
|
---|
265 | }
|
---|
266 | return(n);
|
---|
267 | }
|
---|
268 |
|
---|
269 | ulong cs_atoi(char *asc, int l, int val_on_err)
|
---|
270 | {
|
---|
271 | int i, n=0;
|
---|
272 | ulong rc=0;
|
---|
273 | for (i=((l-1)<<1), errno=0; (i>=0) && (n<4); i-=2)
|
---|
274 | {
|
---|
275 | int b;
|
---|
276 | b=(gethexval(asc[i])<<4) | gethexval(asc[i+1]);
|
---|
277 | if (b<0)
|
---|
278 | {
|
---|
279 | errno=EINVAL;
|
---|
280 | rc=(val_on_err) ? 0xFFFFFFFF : 0;
|
---|
281 | break;
|
---|
282 | }
|
---|
283 | rc|=b<<(n<<3);
|
---|
284 | n++;
|
---|
285 | }
|
---|
286 | return(rc);
|
---|
287 | }
|
---|
288 |
|
---|
289 | int byte_atob(char *asc)
|
---|
290 | {
|
---|
291 | int rc;
|
---|
292 |
|
---|
293 | if (strlen(trim(asc))!=2)
|
---|
294 | rc=(-1);
|
---|
295 | else
|
---|
296 | if ((rc=(gethexval(asc[0])<<4)|gethexval(asc[1]))&0x100)
|
---|
297 | rc=(-1);
|
---|
298 | return(rc);
|
---|
299 | }
|
---|
300 |
|
---|
301 | long word_atob(char *asc)
|
---|
302 | {
|
---|
303 | long rc;
|
---|
304 |
|
---|
305 | if (strlen(trim(asc))!=4)
|
---|
306 | rc=(-1);
|
---|
307 | else
|
---|
308 | {
|
---|
309 | rc=gethexval(asc[0])<<12 | gethexval(asc[1])<<8 |
|
---|
310 | gethexval(asc[2])<<4 | gethexval(asc[3]);
|
---|
311 | if (rc&0x10000)
|
---|
312 | rc=(-1);
|
---|
313 | }
|
---|
314 | return(rc);
|
---|
315 | }
|
---|
316 |
|
---|
317 | /*
|
---|
318 | * dynamic word_atob
|
---|
319 | * converts an 1-4 digit asc hexstring
|
---|
320 | */
|
---|
321 | long dyn_word_atob(char *asc)
|
---|
322 | {
|
---|
323 | long rc = (-1);
|
---|
324 | int i, len = strlen(trim(asc));
|
---|
325 |
|
---|
326 | if (len <= 4 && len > 0) {
|
---|
327 | for(i = 0, rc = 0; i < len; i++)
|
---|
328 | rc = rc << 4 | gethexval(asc[i]);
|
---|
329 |
|
---|
330 | if (rc & 0x10000)
|
---|
331 | rc = (-1);
|
---|
332 | }
|
---|
333 | return(rc);
|
---|
334 | }
|
---|
335 |
|
---|
336 | int key_atob_l(char *asc, uchar *bin, int l)
|
---|
337 | {
|
---|
338 | int i, n1, n2, rc;
|
---|
339 | for (i=rc=0; i<l; i+=2)
|
---|
340 | {
|
---|
341 | if ((n1=gethexval(asc[i ]))<0) rc=(-1);
|
---|
342 | if ((n2=gethexval(asc[i+1]))<0) rc=(-1);
|
---|
343 | bin[i>>1]=(n1<<4)+(n2&0xff);
|
---|
344 | }
|
---|
345 | return(rc);
|
---|
346 | }
|
---|
347 |
|
---|
348 | char *cs_hexdump(int m, const uchar *buf, int n)
|
---|
349 | {
|
---|
350 | //TODO: not threadsafe
|
---|
351 | int i;
|
---|
352 | char *dump = (char *)cur_client()->dump;
|
---|
353 |
|
---|
354 | dump[i=0]='\0';
|
---|
355 | m=(m)?3:2;
|
---|
356 | if (m*n>=(int)sizeof(cur_client()->dump)) n=(sizeof(cur_client()->dump)/m)-1;
|
---|
357 | while (i<n){
|
---|
358 | snprintf(dump+(m*i), sizeof(cur_client()->dump)-(m*i), "%02X%s", *buf++, (m>2)?" ":"");
|
---|
359 | ++i;
|
---|
360 | }
|
---|
361 | return(dump);
|
---|
362 | }
|
---|
363 |
|
---|
364 | static int inet_byteorder=0;
|
---|
365 | in_addr_t cs_inet_order(in_addr_t n)
|
---|
366 | {
|
---|
367 | if (!inet_byteorder)
|
---|
368 | inet_byteorder=((inet_addr("1.2.3.4")+1)==inet_addr("1.2.3.5")) ? 1 : 2;
|
---|
369 | switch (inet_byteorder)
|
---|
370 | {
|
---|
371 | case 1:
|
---|
372 | break;
|
---|
373 | case 2:
|
---|
374 | n=((n&0xff000000) >> 24 ) |
|
---|
375 | ((n&0x00ff0000) >> 8 ) |
|
---|
376 | ((n&0x0000ff00) << 8 ) |
|
---|
377 | ((n&0x000000ff) << 24 );
|
---|
378 | break;
|
---|
379 | }
|
---|
380 | return(n);
|
---|
381 | }
|
---|
382 |
|
---|
383 | char *cs_inet_ntoa(in_addr_t n)
|
---|
384 | {
|
---|
385 | struct in_addr in;
|
---|
386 | in.s_addr=n;
|
---|
387 | return((char *)inet_ntoa(in));
|
---|
388 | }
|
---|
389 |
|
---|
390 | in_addr_t cs_inet_addr(char *txt)
|
---|
391 | {
|
---|
392 | return(inet_addr(txt));
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 | int check_ip(struct s_ip *ip, in_addr_t n)
|
---|
397 | {
|
---|
398 | struct s_ip *p_ip;
|
---|
399 | int ok = 0;
|
---|
400 | for (p_ip=ip; (p_ip) && (!ok); p_ip=p_ip->next)
|
---|
401 | ok=((cs_inet_order(n)>=cs_inet_order(p_ip->ip[0])) && (cs_inet_order(n)<=cs_inet_order(p_ip->ip[1])));
|
---|
402 |
|
---|
403 | return ok;
|
---|
404 | }
|
---|
405 |
|
---|
406 | ulong b2i(int n, uchar *b)
|
---|
407 | {
|
---|
408 | switch(n)
|
---|
409 | {
|
---|
410 | case 2:
|
---|
411 | return ((b[0]<<8) | b[1]);
|
---|
412 | case 3:
|
---|
413 | return ((b[0]<<16) | (b[1]<<8) | b[2]);
|
---|
414 | case 4:
|
---|
415 | return (((b[0]<<24) | (b[1]<<16) | (b[2]<<8) | b[3]) & 0xffffffffL);
|
---|
416 | default:
|
---|
417 | cs_log("Error in b2i, n=%i",n);
|
---|
418 | }
|
---|
419 | return 0;
|
---|
420 | }
|
---|
421 |
|
---|
422 | ullong b2ll(int n, uchar *b)
|
---|
423 | {
|
---|
424 | int i;
|
---|
425 | ullong k=0;
|
---|
426 | for(i=0; i<n; k+=b[i++])
|
---|
427 | k<<=8;
|
---|
428 | return(k);
|
---|
429 | }
|
---|
430 |
|
---|
431 | uchar *i2b(int n, ulong i)
|
---|
432 | {
|
---|
433 | return i2b_buf(n, i, cur_client()->dump);
|
---|
434 | }
|
---|
435 |
|
---|
436 | uchar *i2b_cl(int n, ulong i, struct s_client *cl)
|
---|
437 | {
|
---|
438 | return i2b_buf(n, i, cl->dump);
|
---|
439 | }
|
---|
440 |
|
---|
441 | uchar *i2b_buf(int n, ulong i, uchar *b)
|
---|
442 | {
|
---|
443 | switch(n)
|
---|
444 | {
|
---|
445 | case 2:
|
---|
446 | b[0]=(i>> 8) & 0xff;
|
---|
447 | b[1]=(i ) & 0xff;
|
---|
448 | break;
|
---|
449 | case 3:
|
---|
450 | b[0]=(i>>16) & 0xff;
|
---|
451 | b[1]=(i>> 8) & 0xff;
|
---|
452 | b[2]=(i ) & 0xff;
|
---|
453 | case 4:
|
---|
454 | b[0]=(i>>24) & 0xff;
|
---|
455 | b[1]=(i>>16) & 0xff;
|
---|
456 | b[2]=(i>> 8) & 0xff;
|
---|
457 | b[3]=(i ) & 0xff;
|
---|
458 | break;
|
---|
459 | }
|
---|
460 | return(b);
|
---|
461 | }
|
---|
462 |
|
---|
463 | ulong a2i(char *asc, int bytes)
|
---|
464 | {
|
---|
465 | int i, n;
|
---|
466 | ulong rc;
|
---|
467 | for (rc=i=0, n=strlen(trim(asc))-1; i<(abs(bytes)<<1); n--, i++)
|
---|
468 | if (n>=0)
|
---|
469 | {
|
---|
470 | int rcl;
|
---|
471 | if ((rcl=gethexval(asc[n]))<0)
|
---|
472 | {
|
---|
473 | errno=EINVAL;
|
---|
474 | return(0x1F1F1F);
|
---|
475 | }
|
---|
476 | rc|=(rcl<<(i<<2));
|
---|
477 | }
|
---|
478 | else
|
---|
479 | if (bytes<0)
|
---|
480 | rc|=(0xf<<(i<<2));
|
---|
481 | errno=0;
|
---|
482 | return(rc);
|
---|
483 | }
|
---|
484 |
|
---|
485 | int boundary(int exp, int n)
|
---|
486 | {
|
---|
487 | return((((n-1)>>exp)+1)<<exp);
|
---|
488 | }
|
---|
489 |
|
---|
490 | void cs_ftime(struct timeb *tp)
|
---|
491 | {
|
---|
492 | #ifdef NO_FTIME
|
---|
493 | struct timeval tv;
|
---|
494 | gettimeofday(&tv, (struct timezone *)0);
|
---|
495 | tp->time=tv.tv_sec;
|
---|
496 | tp->millitm=tv.tv_usec/1000;
|
---|
497 | #else
|
---|
498 | ftime(tp);
|
---|
499 | #endif
|
---|
500 | }
|
---|
501 |
|
---|
502 | void cs_sleepms(unsigned int msec)
|
---|
503 | {
|
---|
504 | //does not interfere with signals like sleep and usleep do
|
---|
505 | struct timespec req_ts;
|
---|
506 | req_ts.tv_sec = msec/1000;
|
---|
507 | req_ts.tv_nsec = (msec % 1000) * 1000000L;
|
---|
508 | nanosleep (&req_ts, NULL);
|
---|
509 | }
|
---|
510 |
|
---|
511 | void cs_sleepus(unsigned int usec)
|
---|
512 | {
|
---|
513 | //does not interfere with signals like sleep and usleep do
|
---|
514 | struct timespec req_ts;
|
---|
515 | req_ts.tv_sec = usec/1000000;
|
---|
516 | req_ts.tv_nsec = (usec % 1000000) * 1000L;
|
---|
517 | nanosleep (&req_ts, NULL);
|
---|
518 | }
|
---|
519 |
|
---|
520 | int bytes_available(int fd)
|
---|
521 | {
|
---|
522 | fd_set rfds;
|
---|
523 | fd_set erfds;
|
---|
524 | int select_ret;
|
---|
525 | int in_fd;
|
---|
526 |
|
---|
527 | in_fd=fd;
|
---|
528 |
|
---|
529 | FD_ZERO(&rfds);
|
---|
530 | FD_SET(in_fd, &rfds);
|
---|
531 |
|
---|
532 | FD_ZERO(&erfds);
|
---|
533 | FD_SET(in_fd, &erfds);
|
---|
534 |
|
---|
535 | select_ret = select(in_fd+1, &rfds, NULL, &erfds, NULL);
|
---|
536 | if (select_ret==-1)
|
---|
537 | {
|
---|
538 | cs_log("ERROR reading from fd %d select_ret=%i, errno=%d",in_fd, select_ret, errno);
|
---|
539 | return 0;
|
---|
540 | }
|
---|
541 |
|
---|
542 | if (FD_ISSET(in_fd, &erfds))
|
---|
543 | {
|
---|
544 | cs_log("ERROR reading from fd %d select_ret=%i, errno=%d",in_fd, select_ret, errno);
|
---|
545 | return 0;
|
---|
546 | }
|
---|
547 | if (FD_ISSET(in_fd,&rfds))
|
---|
548 | return 1;
|
---|
549 | else
|
---|
550 | return 0;
|
---|
551 | }
|
---|
552 |
|
---|
553 |
|
---|
554 | #ifdef OS_CYGWIN32
|
---|
555 | #include <windows.h>
|
---|
556 | void cs_setpriority(int prio)
|
---|
557 | {
|
---|
558 | HANDLE WinId;
|
---|
559 | ulong wprio;
|
---|
560 | switch((prio+20)/10)
|
---|
561 | {
|
---|
562 | case 0: wprio=REALTIME_PRIORITY_CLASS; break;
|
---|
563 | case 1: wprio=HIGH_PRIORITY_CLASS; break;
|
---|
564 | case 2: wprio=NORMAL_PRIORITY_CLASS; break;
|
---|
565 | default: wprio=IDLE_PRIORITY_CLASS; break;
|
---|
566 | }
|
---|
567 | WinId=GetCurrentProcess();
|
---|
568 | SetPriorityClass(WinId, wprio);
|
---|
569 | }
|
---|
570 | #else
|
---|
571 | void cs_setpriority(int prio)
|
---|
572 | {
|
---|
573 | #ifdef PRIO_PROCESS
|
---|
574 | setpriority(PRIO_PROCESS, 0, prio); // ignore errors
|
---|
575 | #endif
|
---|
576 | }
|
---|
577 | #endif
|
---|
578 |
|
---|
579 | /* Checks an array if it is filled (a value > 0) and returns the last position (1...length) where something was found.
|
---|
580 | length specifies the maximum length to check for. */
|
---|
581 | int check_filled(uchar *value, int length){
|
---|
582 | if(value == NULL) return 0;
|
---|
583 | int i, j = 0;
|
---|
584 | for (i = 0; i < length; ++i){
|
---|
585 | if(value[i] > 0) j = i + 1;
|
---|
586 | }
|
---|
587 | return j;
|
---|
588 | }
|
---|
589 |
|
---|
590 | /* This function encapsulates malloc. It automatically adds an error message to the log if it failed and calls cs_exit(quiterror) if quiterror > -1.
|
---|
591 | result will be automatically filled with the new memory position or NULL on failure. */
|
---|
592 | void *cs_malloc(void *result, size_t size, int quiterror){
|
---|
593 | void **tmp = (void *)result;
|
---|
594 | *tmp = malloc (size);
|
---|
595 | if(*tmp == NULL){
|
---|
596 | cs_log("Couldn't allocate memory (errno=%d)!", errno);
|
---|
597 | if(quiterror > -1) cs_exit(quiterror);
|
---|
598 | } else {
|
---|
599 | memset(*tmp, 0, size);
|
---|
600 | }
|
---|
601 | return *tmp;
|
---|
602 | }
|
---|
603 |
|
---|
604 | /* This function encapsulates realloc. It automatically adds an error message to the log if it failed and calls cs_exit(quiterror) if quiterror > -1.
|
---|
605 | result will be automatically filled with the new memory position or NULL on failure. If a failure occured, the existing memory in result will be freed. */
|
---|
606 | void *cs_realloc(void *result, size_t size, int quiterror){
|
---|
607 | void **tmp = (void *)result, **tmp2 = (void *)result;
|
---|
608 | *tmp = realloc (*tmp, size);
|
---|
609 | if(*tmp == NULL){
|
---|
610 | cs_log("Couldn't allocate memory (errno=%d)!", errno);
|
---|
611 | free(*tmp2);
|
---|
612 | if(quiterror > -1) cs_exit(quiterror);
|
---|
613 | }
|
---|
614 | return *tmp;
|
---|
615 | }
|
---|
616 |
|
---|
617 | #ifdef WEBIF
|
---|
618 | /* Converts a char to it's hex representation. See urlencode and char_to_hex on how to use it.*/
|
---|
619 | char to_hex(char code){
|
---|
620 | static const char hex[] = "0123456789abcdef";
|
---|
621 | return hex[(int)code & 15];
|
---|
622 | }
|
---|
623 |
|
---|
624 | /* Converts a char array to a char array with hex values (needed for example for md5).
|
---|
625 | Note that result needs to be at least (p_array_len * 2) + 1 large. */
|
---|
626 | void char_to_hex(const unsigned char* p_array, unsigned int p_array_len, unsigned char *result) {
|
---|
627 | result[p_array_len*2] = '\0';
|
---|
628 | const unsigned char* p_end = p_array + p_array_len;
|
---|
629 | size_t pos=0;
|
---|
630 | const unsigned char* p;
|
---|
631 | for( p = p_array; p != p_end; p++, pos+=2 ) {
|
---|
632 | result[pos] = to_hex(*p >> 4);
|
---|
633 | result[pos+1] = to_hex(*p & 15);
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 | /* Creates a random string with specified length. Note that dst must be one larger than size to hold the trailing \0*/
|
---|
638 | void create_rand_str(char *dst, int size){
|
---|
639 | int i;
|
---|
640 | for (i = 0; i < size; ++i){
|
---|
641 | dst[i] = (rand() % 94) + 32;
|
---|
642 | }
|
---|
643 | dst[i] = '\0';
|
---|
644 | }
|
---|
645 | #endif
|
---|
646 |
|
---|
647 | /* Converts a uint64 value (you may also cast smaller types) to a char array in bitwise representation.
|
---|
648 | Note that the result array MUST be at least size+1 bit large and that this function assumes values
|
---|
649 | to be only positive! The result of e.g. uint64 7 is
|
---|
650 | 11100000000000000000000000000000000000000000000000000000000000000 this means the array is reversed */
|
---|
651 | void uint64ToBitchar(uint64 value, int size, char *result){
|
---|
652 | int pos;
|
---|
653 | for (pos=0;pos<size;pos++) result[pos]='0';
|
---|
654 | result[pos] = '\0';
|
---|
655 |
|
---|
656 | pos=0;
|
---|
657 | while (value > 0 && pos < size){
|
---|
658 | if(value % 2 == 1) result[pos]='1';
|
---|
659 | else result[pos]='0';
|
---|
660 | value=value / (uint64)2;
|
---|
661 | pos++;
|
---|
662 | }
|
---|
663 | }
|
---|
664 |
|
---|
665 | /* Return 1 if the file exists, else 0 */
|
---|
666 | int file_exists(const char * filename){
|
---|
667 | FILE *file;
|
---|
668 | if ((file = fopen(filename, "r"))){
|
---|
669 | fclose(file);
|
---|
670 | return 1;
|
---|
671 | }
|
---|
672 | return 0;
|
---|
673 | }
|
---|
674 |
|
---|
675 | /* Clears the s_ip structure provided. The pointer will be set to NULL so everything is cleared.*/
|
---|
676 | void clear_sip(struct s_ip **sip){
|
---|
677 | struct s_ip *cip = *sip, *lip;
|
---|
678 | for (*sip = NULL; cip != NULL; cip = lip){
|
---|
679 | lip = cip->next;
|
---|
680 | free(cip);
|
---|
681 | }
|
---|
682 | }
|
---|
683 |
|
---|
684 | /* Clears the s_ftab struct provided by setting nfilts and nprids to zero. */
|
---|
685 | void clear_ftab(struct s_ftab *ftab){
|
---|
686 | int i, j;
|
---|
687 | for (i = 0; i < CS_MAXFILTERS; i++) {
|
---|
688 | ftab->filts[i].caid = 0;
|
---|
689 | for (j = 0; j < CS_MAXPROV; j++)
|
---|
690 | ftab->filts[i].prids[j] = 0;
|
---|
691 | ftab->filts[i].nprids = 0;
|
---|
692 | }
|
---|
693 | ftab->nfilts = 0;
|
---|
694 | }
|
---|
695 |
|
---|
696 | /* Clears the s_ptab struct provided by setting nfilts and nprids to zero. */
|
---|
697 | void clear_ptab(struct s_ptab *ptab){
|
---|
698 | int i;
|
---|
699 | for (i = 0; i < ptab->nports; i++) {
|
---|
700 | ptab->ports[i].ftab.nfilts = 0;
|
---|
701 | ptab->ports[i].ftab.filts[0].nprids = 0;
|
---|
702 | }
|
---|
703 | ptab->nports = 0;
|
---|
704 | }
|
---|
705 |
|
---|
706 | /* Clears given caidtab */
|
---|
707 | void clear_caidtab(struct s_caidtab *ctab){
|
---|
708 | int i;
|
---|
709 | for (i = 0; i < CS_MAXCAIDTAB; i++) {
|
---|
710 | ctab->caid[i] = 0;
|
---|
711 | ctab->mask[i] = 0;
|
---|
712 | ctab->cmap[i] = 0;
|
---|
713 | }
|
---|
714 | }
|
---|
715 |
|
---|
716 | /* Clears given tuntab */
|
---|
717 | void clear_tuntab(struct s_tuntab *ttab){
|
---|
718 | int i;
|
---|
719 | for (i = 0; i < CS_MAXTUNTAB; i++) {
|
---|
720 | ttab->bt_caidfrom[i] = 0;
|
---|
721 | ttab->bt_caidto[i] = 0;
|
---|
722 | ttab->bt_srvid[i] = 0;
|
---|
723 | }
|
---|
724 | }
|
---|
725 |
|
---|
726 | /* Copies a file from srcfile to destfile. If an error occured before writing, -1 is returned, else -2. On success, 0 is returned.*/
|
---|
727 | int file_copy(char *srcfile, char *destfile){
|
---|
728 | FILE *src, *dest;
|
---|
729 | int ch;
|
---|
730 | if((src = fopen(srcfile, "r"))==NULL) {
|
---|
731 | cs_log("Error opening file %s for reading (errno=%d)!", srcfile, errno);
|
---|
732 | return(-1);
|
---|
733 | }
|
---|
734 | if((dest = fopen(destfile, "w"))==NULL) {
|
---|
735 | cs_log("Error opening file %s for writing (errno=%d)!", destfile, errno);
|
---|
736 | fclose(src);
|
---|
737 | return(-1);
|
---|
738 | }
|
---|
739 |
|
---|
740 | while(1){
|
---|
741 | ch = fgetc(src);
|
---|
742 | if(ch==EOF){
|
---|
743 | break;
|
---|
744 | } else {
|
---|
745 | fputc(ch, dest);
|
---|
746 | if(ferror(dest)) {
|
---|
747 | cs_log("Error while writing to file %s (errno=%d)!", destfile, errno);
|
---|
748 | fclose(src);
|
---|
749 | fclose(dest);
|
---|
750 | return(-2);
|
---|
751 | }
|
---|
752 | }
|
---|
753 | }
|
---|
754 | fclose(src);
|
---|
755 | fclose(dest);
|
---|
756 | return(0);
|
---|
757 | }
|
---|
758 |
|
---|
759 | /* Overwrites destfile with tmpfile. If forceBakOverWrite = 0, the bakfile will not be overwritten if it exists, else it will be.*/
|
---|
760 | int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite){
|
---|
761 | int rc;
|
---|
762 | if (file_exists(destfile)) {
|
---|
763 | if(forceBakOverWrite != 0 || !file_exists(bakfile)){
|
---|
764 | if(file_copy(destfile, bakfile) < 0){
|
---|
765 | cs_log("Error copying original config file %s to %s. The original config will be left untouched!", destfile, bakfile);
|
---|
766 | if(remove(tmpfile) < 0) cs_log("Error removing temp config file %s (errno=%d)!", tmpfile, errno);
|
---|
767 | return(1);
|
---|
768 | }
|
---|
769 | }
|
---|
770 | }
|
---|
771 | if((rc = file_copy(tmpfile, destfile)) < 0){
|
---|
772 | cs_log("An error occured while writing the new config file %s.", destfile);
|
---|
773 | if(rc == -2) cs_log("The config will be missing or only partly filled upon next startup as this is a non-recoverable error! Please restore from backup or try again.", destfile);
|
---|
774 | if(remove(tmpfile) < 0) cs_log("Error removing temp config file %s (errno=%d)!", tmpfile, errno);
|
---|
775 | return(1);
|
---|
776 | }
|
---|
777 | if(remove(tmpfile) < 0) cs_log("Error removing temp config file %s (errno=%d)!", tmpfile, errno);
|
---|
778 | return(0);
|
---|
779 | }
|
---|
780 |
|
---|
781 | /* Replacement of fprintf which adds necessary whitespace to fill up the varname to a fixed width.
|
---|
782 | If varname is longer than varnameWidth, no whitespace is added*/
|
---|
783 | void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...){
|
---|
784 | int varlen = strlen(varname);
|
---|
785 | int max = (varlen > varnameWidth) ? varlen : varnameWidth;
|
---|
786 | char varnamebuf[max + 3];
|
---|
787 | char *ptr = varnamebuf + varlen;
|
---|
788 | va_list argptr;
|
---|
789 |
|
---|
790 | cs_strncpy(varnamebuf, varname, sizeof(varnamebuf));
|
---|
791 | while(varlen < varnameWidth){
|
---|
792 | ptr[0] = ' ';
|
---|
793 | ++ptr;
|
---|
794 | ++varlen;
|
---|
795 | }
|
---|
796 | cs_strncpy(ptr, "= ", sizeof(varnamebuf)-(ptr-varnamebuf));
|
---|
797 | if (fwrite(varnamebuf, sizeof(char), strlen(varnamebuf), f)){
|
---|
798 | if(strlen(fmtstring) > 0){
|
---|
799 | va_start(argptr, fmtstring);
|
---|
800 | vfprintf(f, fmtstring, argptr);
|
---|
801 | va_end(argptr);
|
---|
802 | }
|
---|
803 | }
|
---|
804 | }
|
---|
805 |
|
---|
806 | /* Ordinary strncpy does not terminate the string if the source is exactly as long or longer as the specified size. This can raise security issues.
|
---|
807 | This function is a replacement which makes sure that a \0 is always added. num should be the real size of char array (do not subtract -1). */
|
---|
808 | void cs_strncpy(char * destination, const char * source, size_t num){
|
---|
809 | uint32 l, size = strlen(source);
|
---|
810 | if(size > num - 1) l = num - 1;
|
---|
811 | else l = size;
|
---|
812 | memcpy(destination, source, l);
|
---|
813 | destination[l] = '\0';
|
---|
814 | }
|
---|
815 |
|
---|
816 | char *get_servicename(int srvid, int caid){
|
---|
817 | int i;
|
---|
818 | struct s_srvid *this = cfg.srvid;
|
---|
819 | static char name[83];
|
---|
820 |
|
---|
821 | for (name[0] = 0; this && (!name[0]); this = this->next)
|
---|
822 | if (this->srvid == srvid)
|
---|
823 | for (i=0; i<this->ncaid; i++)
|
---|
824 | if (this->caid[i] == caid)
|
---|
825 | cs_strncpy(name, this->name, 32);
|
---|
826 |
|
---|
827 | if (!name[0]) snprintf(name, sizeof(name), "%04X:%04X unknown", caid, srvid);
|
---|
828 | if (!srvid) name[0] = '\0';
|
---|
829 | return(name);
|
---|
830 | }
|
---|
831 |
|
---|
832 | char *get_tiername(int tierid, int caid){
|
---|
833 | int i;
|
---|
834 | struct s_tierid *this = cfg.tierid;
|
---|
835 | static char name[83];
|
---|
836 |
|
---|
837 | for (name[0] = 0; this && (!name[0]); this = this->next)
|
---|
838 | if (this->tierid == tierid)
|
---|
839 | for (i=0; i<this->ncaid; i++)
|
---|
840 | if (this->caid[i] == caid)
|
---|
841 | cs_strncpy(name, this->name, 32);
|
---|
842 |
|
---|
843 | //if (!name[0]) sprintf(name, "%04X:%04X unknown", caid, tierid);
|
---|
844 | if (!tierid) name[0] = '\0';
|
---|
845 | return(name);
|
---|
846 | }
|
---|
847 |
|
---|
848 | char *get_provider(int caid, ulong provid){
|
---|
849 | struct s_provid *this = cfg.provid;
|
---|
850 | static char name[83];
|
---|
851 |
|
---|
852 | for (name[0] = 0; this && (!name[0]); this = this->next) {
|
---|
853 | if (this->caid == caid && this->provid == provid) {
|
---|
854 | snprintf(name, 83, "%s", this->prov);
|
---|
855 | if (this->sat[0]) {
|
---|
856 | strcat(name, " / ");
|
---|
857 | strcat(name, this->sat);
|
---|
858 | }
|
---|
859 | if (this->lang[0]) {
|
---|
860 | strcat(name, " / ");
|
---|
861 | strcat(name, this->lang);
|
---|
862 | }
|
---|
863 | }
|
---|
864 | }
|
---|
865 |
|
---|
866 | if (!name[0]) snprintf(name, 83, "%04X:%06lX unknown", caid, provid);
|
---|
867 | if (!caid) name[0] = '\0';
|
---|
868 | return(name);
|
---|
869 | }
|
---|
870 |
|
---|
871 | void make_non_blocking(int fd) {
|
---|
872 | int fl;
|
---|
873 | fl=fcntl(fd, F_GETFL);
|
---|
874 | fcntl(fd, F_SETFL, fl | O_NONBLOCK | O_NDELAY);
|
---|
875 | }
|
---|
876 |
|
---|
877 | unsigned int seed;
|
---|
878 |
|
---|
879 | uchar fast_rnd() {
|
---|
880 | unsigned int offset = 12923;
|
---|
881 | unsigned int multiplier = 4079;
|
---|
882 |
|
---|
883 | seed = seed * multiplier + offset;
|
---|
884 | return (uchar) (seed % 0xFF);
|
---|
885 | }
|
---|
886 |
|
---|
887 | void init_rnd() {
|
---|
888 | seed = (unsigned int) time((time_t*)0);
|
---|
889 | }
|
---|
890 |
|
---|
891 | int hexserialset(struct s_reader *rdr)
|
---|
892 | {
|
---|
893 | int i;
|
---|
894 |
|
---|
895 | if (!rdr) return 0;
|
---|
896 |
|
---|
897 | for (i = 0; i < 8; i++)
|
---|
898 | if (rdr->hexserial[i])
|
---|
899 | return 1;
|
---|
900 | return 0;
|
---|
901 | }
|
---|
902 |
|
---|
903 | static char *netw_ext_prot[] = { "cccam", "cccam ext", "newcamd524" };
|
---|
904 |
|
---|
905 | char *reader_get_type_desc(struct s_reader * rdr, int extended)
|
---|
906 | {
|
---|
907 | static char *typtxt[] = { "unknown", "mouse", "mouse", "sc8in1", "mp35", "mouse", "internal", "smartreader", "pcsc" };
|
---|
908 | char *desc = typtxt[0];
|
---|
909 |
|
---|
910 | if (rdr->crdr.active==1)
|
---|
911 | return rdr->crdr.desc;
|
---|
912 |
|
---|
913 | if (rdr->typ & R_IS_NETWORK) {
|
---|
914 | if (rdr->ph.desc)
|
---|
915 | desc = rdr->ph.desc;
|
---|
916 | } else {
|
---|
917 | desc = typtxt[rdr->typ];
|
---|
918 | }
|
---|
919 |
|
---|
920 | if ((rdr->typ == R_NEWCAMD) && (rdr->ncd_proto == NCD_524))
|
---|
921 | desc = netw_ext_prot[2];
|
---|
922 |
|
---|
923 | else if (rdr->typ == R_CCCAM) {
|
---|
924 | if (rdr->client) {
|
---|
925 | if (rdr->client && rdr->client->cc && ((struct cc_data *)rdr->client->cc)->extended_mode)
|
---|
926 | desc = netw_ext_prot[extended];
|
---|
927 | else
|
---|
928 | desc = netw_ext_prot[0];
|
---|
929 | } else {
|
---|
930 | desc = netw_ext_prot[0];
|
---|
931 | }
|
---|
932 | }
|
---|
933 |
|
---|
934 | return (desc);
|
---|
935 | }
|
---|
936 |
|
---|
937 | char *monitor_get_proto(struct s_client *cl)
|
---|
938 | {
|
---|
939 | char *ctyp;
|
---|
940 | switch(cl->typ) {
|
---|
941 | case 's' : ctyp = "server"; break;
|
---|
942 | case 'p' :
|
---|
943 | case 'r' : ctyp = reader_get_type_desc(cl->reader, 1); break;
|
---|
944 | case 'c' :
|
---|
945 | if (cl->cc && ((struct cc_data *)cl->cc)->extended_mode) {
|
---|
946 | ctyp = netw_ext_prot[1];
|
---|
947 | break;
|
---|
948 | }
|
---|
949 | default : ctyp = ph[cl->ctyp].desc;
|
---|
950 | }
|
---|
951 | return(ctyp);
|
---|
952 | }
|
---|
953 |
|
---|
954 | /*
|
---|
955 | * resolve clienttype for newcamdprotocol
|
---|
956 | */
|
---|
957 | char *get_ncd_client_name(char *client_id)
|
---|
958 | {
|
---|
959 | static const int max_id_idx = 31;
|
---|
960 | static const char const *ncd_service_ids[] = { "0000", "5644", "4C43", "4333", "7264", "6762", "6D67", "7763", "6E73", "6378", "6B61",
|
---|
961 | "6576", "4343", "5456", "414C", "0666", "0667", "9911", "434C", "4765", "5342",
|
---|
962 | "6E65", "4E58", "4453", "8888", "7363", "0669", "0665", "0769", "4543", "6D63",
|
---|
963 | "6B63" };
|
---|
964 |
|
---|
965 | static char *ncd_service_names[] = { "generic", "vdr-sc", "LCE", "camd3", "radegast", "gbox2CS", "mgcamd", //actually a const so threadsafe
|
---|
966 | "WinCSC", "NewCS", "cx", "Kaffeine", "evocamd", "CCcam", "Tecview",
|
---|
967 | "AlexCS", "rqcamd", "rq-echo-client", "ACamd", "Cardlink", "Octagon", "SBCL",
|
---|
968 | "NextYE2k", "NextYE2k", "DiabloCam/UW", "OSCam", "Scam", "rq-sssp-client/CW",
|
---|
969 | "rq-sssp-client/CS", "JlsRq", "eyetvCamd", "mpcs", "kpcs", "unknown - please report" };
|
---|
970 |
|
---|
971 | int idx = 0;
|
---|
972 | for (idx = 0; idx <= max_id_idx; idx++) {
|
---|
973 | if(!memcmp(ncd_service_ids[idx], client_id, 4))
|
---|
974 | return ncd_service_names[idx];
|
---|
975 |
|
---|
976 | }
|
---|
977 |
|
---|
978 | return ncd_service_names[max_id_idx+1];
|
---|
979 | }
|
---|
980 |
|
---|
981 | char *strnew(char *str)
|
---|
982 | {
|
---|
983 | if (!str)
|
---|
984 | return NULL;
|
---|
985 |
|
---|
986 | char *newstr = cs_malloc(&newstr, strlen(str)+1, 1);
|
---|
987 | cs_strncpy(newstr, str, strlen(str)+1);
|
---|
988 |
|
---|
989 | return newstr;
|
---|
990 | }
|
---|
991 |
|
---|
992 | void hexserial_to_newcamd(uchar *source, uchar *dest, ushort caid)
|
---|
993 | {
|
---|
994 | caid = caid >> 8;
|
---|
995 | if ((caid == 0x17) || (caid == 0x06)) // Betacrypt or Irdeto
|
---|
996 | {
|
---|
997 | // only 4 Bytes Hexserial for newcamd clients (Hex Base + Hex Serial)
|
---|
998 | // first 2 Byte always 00
|
---|
999 | dest[0]=0x00; //serial only 4 bytes
|
---|
1000 | dest[1]=0x00; //serial only 4 bytes
|
---|
1001 | // 1 Byte Hex Base (see reader-irdeto.c how this is stored in "source")
|
---|
1002 | dest[2]=source[3];
|
---|
1003 | // 3 Bytes Hex Serial (see reader-irdeto.c how this is stored in "source")
|
---|
1004 | dest[3]=source[0];
|
---|
1005 | dest[4]=source[1];
|
---|
1006 | dest[5]=source[2];
|
---|
1007 | }
|
---|
1008 | else if ((caid == 0x05) || (caid == 0x0D))
|
---|
1009 | {
|
---|
1010 | dest[0] = 0x00;
|
---|
1011 | memcpy(dest+1, source, 5);
|
---|
1012 | }
|
---|
1013 | else
|
---|
1014 | memcpy(dest, source, 6);
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | void newcamd_to_hexserial(uchar *source, uchar *dest, ushort caid)
|
---|
1018 | {
|
---|
1019 | caid = caid >> 8;
|
---|
1020 | if ((caid == 0x17) || (caid == 0x06)) {
|
---|
1021 | memcpy(dest, source+3, 3);
|
---|
1022 | dest[3] = source[2];
|
---|
1023 | dest[4] = 0;
|
---|
1024 | dest[5] = 0;
|
---|
1025 | }
|
---|
1026 | else if ((caid == 0x05) || (caid == 0x0D)) {
|
---|
1027 | memcpy(dest, source+1, 5);
|
---|
1028 | dest[5] = 0;
|
---|
1029 | }
|
---|
1030 | else
|
---|
1031 | memcpy(dest, source, 6);
|
---|
1032 | }
|
---|