forked from nx111/oscam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module-cccam-cacheex.c
1538 lines (1357 loc) · 38.2 KB
/
module-cccam-cacheex.c
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define MODULE_LOG_PREFIX "cccam"
#include "globals.h"
#include "oscam-array.h"
#if defined(CS_CACHEEX) && defined(MODULE_CCCAM)
#include "module-cacheex.h"
#include "module-cccam-data.h"
#include "module-cccam-cacheex.h"
#include "oscam-cache.h"
#include "oscam-client.h"
#include "oscam-ecm.h"
#include "oscam-string.h"
#include "oscam-chk.h"
#include "oscam-reader.h"
#ifdef CS_CACHEEX_AIO
#include "oscam-chk.h"
#include "oscam-config.h"
#endif
#define CSP_HASH_SWAP(n) (((((uint32_t)(n) & 0xFF)) << 24) | \
((((uint32_t)(n) & 0xFF00)) << 8) | \
((((uint32_t)(n) & 0xFF0000)) >> 8) | \
((((uint32_t)(n) & 0xFF000000)) >> 24))
extern int32_t cc_cli_connect(struct s_client *cl);
extern int32_t cc_cmd_send(struct s_client *cl, uint8_t *buf, int32_t len, cc_msg_type_t cmd);
#ifdef CS_CACHEEX_AIO
void cc_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf)
{
int32_t feature = 0;
int i = 0;
uint8_t filter_count;
uint8_t j, k, l, rc;
feature = buf[1] | (buf[0] << 8);
FTAB *lgonly_tab;
// check client & cacheex-mode
if(
!check_client(cl) ||
!(
(cl->typ == 'c' && cl->account->cacheex.mode > 0) ||
(cl->typ == 'p' && cl->reader->cacheex.mode > 0)
)
)
{
return;
}
switch(feature)
{
// set localgenerated only
case 1:
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1))
{
if(cfg.cacheex_lg_only_remote_settings || cl->account->cacheex.lg_only_remote_settings)
cl->account->cacheex.localgenerated_only = buf[4];
else if(buf[4])
cl->account->cacheex.localgenerated_only = buf[4];
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3)
{
if(cfg.cacheex_lg_only_remote_settings || cl->reader->cacheex.lg_only_remote_settings)
cl->reader->cacheex.localgenerated_only = buf[4];
else if(buf[4])
cl->reader->cacheex.localgenerated_only = buf[4];
}
break;
// set localgenerated only caidtab
case 2:
filter_count = buf[i+4];
i += 5;
memset(&lgonly_tab, 0, sizeof(lgonly_tab));
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1))
{
lgonly_tab = &cl->account->cacheex.lg_only_tab;
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3)
{
lgonly_tab = &cl->reader->cacheex.lg_only_tab;
}
else
{
return;
}
// remotesettings enabled - replace local settings
if(cfg.cacheex_lg_only_remote_settings ||
(
(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.lg_only_remote_settings)
|| (cl->typ == 'p' && cl->reader->cacheex.mode == 3 && cl->reader->cacheex.lg_only_remote_settings)
)
)
{
ftab_clear(lgonly_tab);
for(j = 0; j < filter_count; j++)
{
FILTER d;
memset(&d, 0, sizeof(d));
d.caid = b2i(2, buf + i);
i += 2;
d.nprids = 1;
d.prids[0] = NO_PROVID_VALUE;
ftab_add(lgonly_tab, &d);
}
}
// remotesettings disabled - write additional remote-caids received
else
{
for(j = 0; j < filter_count; j++)
{
FILTER d;
memset(&d, 0, sizeof(d));
d.caid = b2i(2, buf + i);
i += 2;
d.nprids = 1;
d.prids[0] = NO_PROVID_VALUE;
if(!chk_lg_only_cp(d.caid, d.prids[0], lgonly_tab))
{
cs_log_dbg(D_CACHEEX, "%04X:%06X not found in local settings - adding them", d.caid, d.prids[0]);
for(l = rc = 0; (!rc) && (l < lgonly_tab->nfilts); l++)
{
if(lgonly_tab->filts[l].caid == d.caid)
{
rc = 1;
if(lgonly_tab->filts[l].nprids+1 <= CS_MAXPROV)
{
lgonly_tab->filts[l].prids[lgonly_tab->filts[l].nprids] = d.prids[0];
lgonly_tab->filts[l].nprids++;
}
else
{
cs_log_dbg(D_CACHEEX, "error: cacheex_lg_only_tab -> max. number(%i) of providers reached", CS_MAXPROV);
}
}
}
if(!rc)
{
ftab_add(lgonly_tab, &d);
}
}
}
}
break;
// set cacheex_ecm_filter - extended
case 4:
filter_count = buf[i+4];
i += 5;
CECSPVALUETAB *filter;
memset(&filter, 0, sizeof(filter));
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.allow_filter)
{
filter = &cl->account->cacheex.filter_caidtab;
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3 && cl->reader->cacheex.allow_filter)
{
filter = &cl->reader->cacheex.filter_caidtab;
}
else
{
return;
}
cecspvaluetab_clear(filter);
for(j = 0; j < filter_count; j++)
{
int32_t caid = -1, cmask = -1, provid = -1, srvid = -1;
CECSPVALUETAB_DATA d;
memset(&d, 0, sizeof(d));
caid = b2i(2, buf + i);
if(caid == 0xFFFF) caid = -1;
i += 2;
cmask = b2i(2, buf + i);
if(cmask == 0xFFFF) cmask = -1;
i += 2;
provid = b2i(3, buf + i);
if(provid == 0xFFFFFF) provid = -1;
i += 3;
srvid = b2i(2, buf + i);
if(srvid == 0xFFFF) srvid = -1;
i += 2;
if(caid > 0)
{
d.caid = caid;
d.cmask = cmask;
d.prid = provid;
d.srvid = srvid;
cecspvaluetab_add(filter, &d);
}
}
break;
// no push after
case 8: ;
CAIDVALUETAB *ctab;
memset(&ctab, 0, sizeof(ctab));
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1))
{
ctab = &cl->account->cacheex.cacheex_nopushafter_tab;
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3)
{
ctab = &cl->reader->cacheex.cacheex_nopushafter_tab;
}
else
{
return;
}
filter_count = buf[i+4];
i += 5;
caidvaluetab_clear(ctab);
for(j = 0; j < filter_count; j++)
{
uint16_t caid = 0, value = 0;
CAIDVALUETAB_DATA d;
memset(&d, 0, sizeof(d));
caid = b2i(2, buf + i);
if(caid == 0xFFFF) caid = -1;
i += 2;
value = b2i(2, buf + i);
if(value == 0xFFFF) value = -1;
i += 2;
if(caid > 0)
{
d.caid = caid;
d.value = value;
caidvaluetab_add(ctab, &d);
}
}
break;
// max_hop
case 16:
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.allow_maxhop)
{
cl->account->cacheex.maxhop = buf[4];
cl->account->cacheex.maxhop_lg = buf[5];
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3 && cl->reader->cacheex.allow_maxhop)
{
cl->reader->cacheex.maxhop = buf[4];
cl->reader->cacheex.maxhop_lg = buf[5];
}
break;
// aio-version
case 32:
if(cl->typ == 'c' && cl->account->cacheex.mode > 0)
{
char *ofs = (char *)buf + i + 4;
cs_strncpy(cl->account->cacheex.aio_version, ofs, sizeof(cl->account->cacheex.aio_version));
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode > 0)
{
char *ofs = (char *)buf + i + 4;
cs_strncpy(cl->reader->cacheex.aio_version, ofs, sizeof(cl->reader->cacheex.aio_version));
}
break;
// lg_only_tab caid:prov1[,provN][;caid:prov]
case 64: ;
memset(&lgonly_tab, 0, sizeof(lgonly_tab));
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1))
{
lgonly_tab = &cl->account->cacheex.lg_only_tab;
}
else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3)
{
lgonly_tab = &cl->reader->cacheex.lg_only_tab;
}
else
{
return;
}
filter_count = buf[i+4];
i += 5;
// remotesettings enabled - replace local settings
if(cfg.cacheex_lg_only_remote_settings ||
(
(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.lg_only_remote_settings)
|| (cl->typ == 'p' && cl->reader->cacheex.mode == 3 && cl->reader->cacheex.lg_only_remote_settings)
|| !lgonly_tab->nfilts
)
)
{
ftab_clear(lgonly_tab);
for(j = 0; j < filter_count; j++)
{
FILTER d;
memset(&d, 0, sizeof(d));
d.caid = b2i(2, buf + i);
i += 2;
d.nprids = b2i(1, buf + i);
i += 1;
for(k=0; k < d.nprids; k++)
{
d.prids[k] = b2i(3, buf + i);
i += 3;
}
ftab_add(lgonly_tab, &d);
}
}
// remotesettings disabled - write additional remote-caid/provids received
else
{
for(j = 0; j < filter_count; j++)
{
FILTER d;
memset(&d, 0, sizeof(d));
d.caid = b2i(2, buf + i);
i += 2;
d.nprids = b2i(1, buf + i);
i += 1;
for(k=0; k < d.nprids; k++)
{
d.prids[k] = b2i(3, buf + i);
i += 3;
if(!chk_ident_filter(d.caid, d.prids[k], lgonly_tab))
{
cs_log_dbg(D_CACHEEX, "%04X:%06X not found in local settings - adding them", d.caid, d.prids[k]);
for(l = rc = 0; (!rc) && (l < lgonly_tab->nfilts); l++)
{
if(lgonly_tab->filts[l].caid == d.caid)
{
rc = 1;
if(lgonly_tab->filts[l].nprids+1 <= CS_MAXPROV)
{
lgonly_tab->filts[l].prids[lgonly_tab->filts[l].nprids] = d.prids[k];
lgonly_tab->filts[l].nprids++;
}
else
{
cs_log_dbg(D_CACHEEX, "error: cacheex_lg_only_tab -> max. number of providers reached");
}
}
}
if(!rc)
{
ftab_add(lgonly_tab, &d);
}
}
}
}
}
break;
default:
return;
}
}
void cc_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_t mode)
{
// size: (feature-bitfield & mask: 2) + payload-size: 2 + feature-payload :x
uint16_t size = 2 + 2;
int i = 0;
uint8_t j;
uint8_t payload[MAX_ECM_SIZE-size];
memset(payload, 0, sizeof(payload));
// check client & cacheex-mode
if(!check_client(cl))
{
return;
}
switch(feature)
{
FTAB *lgonly_tab;
// set localgenerated only
case 1:
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
// payload-size
i2b_buf(2, 1, payload + i);
i += 2;
size += 1;
// set payload
if(mode == 2)
{
if(cl->reader->cacheex.localgenerated_only_in)
payload[i] = cl->reader->cacheex.localgenerated_only_in;
else
payload[i] = cfg.cacheex_localgenerated_only_in;
}
else if(mode == 3)
{
if(cl->account->cacheex.localgenerated_only_in)
payload[i] = cl->account->cacheex.localgenerated_only_in;
else
payload[i] = cfg.cacheex_localgenerated_only_in;
}
break;
// set localgenerated only caidtab; cx-aio < 9.2.6-04
case 2: ;
if(mode == 2)
{
lgonly_tab = &cl->reader->cacheex.lg_only_in_tab;
if(!lgonly_tab->nfilts)
lgonly_tab = &cfg.cacheex_lg_only_in_tab;
}
else if(mode == 3)
{
lgonly_tab = &cl->account->cacheex.lg_only_in_tab;
if(!lgonly_tab->nfilts)
lgonly_tab = &cfg.cacheex_lg_only_in_tab;
}
else
{
return;
}
size += (lgonly_tab->nfilts * 2 + 1);
if(size < 32)
size = 32;
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
// payload-size
if((lgonly_tab->nfilts * 2 + 1) > (int)sizeof(payload))
{
cs_log_dbg(D_CACHEEX, "ERROR: too much localgenerated only caidtab-entries (max. 255)");
return;
}
i2b_buf(2, (lgonly_tab->nfilts * 2 + 1), payload + i); // n * caid + ctnum
i += 2;
// set payload
if(lgonly_tab->nfilts > 255)
{
cs_log_dbg(D_CACHEEX, "ERROR: too much localgenerated only caidtab-entries (max. 255)");
return;
}
payload[i] = lgonly_tab->nfilts;
i += 1;
for(j = 0; j < lgonly_tab->nfilts; j++)
{
FILTER *d = &lgonly_tab->filts[j];
if(d->caid)
{
i2b_buf(2, d->caid, payload + i);
i += 2;
}
else
{
continue;
}
}
break;
// cacchex_ecm_filter extendend
case 4: ;
CECSPVALUETAB *filter;
if(mode == 2)
{
filter = &cl->reader->cacheex.filter_caidtab;
// if not set, use global settings
if(cl->reader->cacheex.filter_caidtab.cevnum == 0 && cfg.cacheex_filter_caidtab.cevnum > 0)
filter = &cfg.cacheex_filter_caidtab;
// if aio, use global aio settings
if(cl->reader->cacheex.filter_caidtab.cevnum == 0 && cfg.cacheex_filter_caidtab_aio.cevnum > 0 && cl->cacheex_aio_checked && (cl->reader->cacheex.feature_bitfield & 4))
filter = &cfg.cacheex_filter_caidtab_aio;
}
else if(mode == 3)
{
filter = &cl->account->cacheex.filter_caidtab;
// if not set, use global settings
if(cl->account->cacheex.filter_caidtab.cevnum == 0 && cfg.cacheex_filter_caidtab.cevnum > 0)
filter = &cfg.cacheex_filter_caidtab;
// if aio, use global aio settings
if(cl->account->cacheex.filter_caidtab.cevnum == 0 && cfg.cacheex_filter_caidtab_aio.cevnum > 0 && cl->cacheex_aio_checked && (cl->account->cacheex.feature_bitfield & 4))
filter = &cfg.cacheex_filter_caidtab_aio;
}
else
{
return;
}
size += (filter->cevnum * 9 + 1);
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
// payload-size
if((filter->cevnum * 9 + 1) > (int)sizeof(payload))
{
cs_log_dbg(D_CACHEEX, "ERROR: to much cacheex_ecm_filter-entries (max. 63), only 30 default cccam-filters sent");
return;
}
i2b_buf(2, (filter->cevnum * 9 + 1), payload + i); // n * (caid2,mask2,provid3,srvid2) + ctnum1
i += 2;
// set payload
payload[i] = filter->cevnum;
i += 1;
for(j = 0; j < filter->cevnum; j++)
{
CECSPVALUETAB_DATA *d = &filter->cevdata[j];
if(d->caid)
{
i2b_buf(2, d->caid, payload + i);
i += 2;
}
if(d->cmask)
{
i2b_buf(2, d->cmask, payload + i);
}
i += 2;
if(d->prid)
{
i2b_buf(3, d->prid, payload + i);
}
i += 3;
if(d->srvid)
{
i2b_buf(2, d->srvid, payload + i);
}
i += 2;
}
break;
// no push after
case 8: ;
CAIDVALUETAB *ctab;
if(mode == 2)
{
ctab = &cl->reader->cacheex.cacheex_nopushafter_tab;
if(!ctab->cvnum)
ctab = &cfg.cacheex_nopushafter_tab;
}
else if(mode == 3)
{
ctab = &cl->account->cacheex.cacheex_nopushafter_tab;
if(!ctab->cvnum)
ctab = &cfg.cacheex_nopushafter_tab;
}
else
{
return;
}
size += (ctab->cvnum * 4 + 1);
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
// payload-size
if((ctab->cvnum * 4 + 1) > (int)sizeof(payload))
{
cs_log_dbg(D_CACHEEX, "ERROR: to much no push after caidtvalueab-entries (max. 255)");
return;
}
i2b_buf(2, (ctab->cvnum * 4 + 1), payload + i); // n * (caid2+value2) + cvnum
i += 2;
// set payload
if(ctab->cvnum > 255)
{
cs_log_dbg(D_CACHEEX, "ERROR: to much no push after caidtvalueab-entries (max. 255)");
return;
}
payload[i] = ctab->cvnum;
i += 1;
for(j = 0; j < ctab->cvnum; j++)
{
CAIDVALUETAB_DATA *d = &ctab->cvdata[j];
if(d->caid)
{
i2b_buf(2, d->caid, payload + i);
i += 2;
i2b_buf(2, d->value, payload + i);
i += 2;
}
else
{
continue;
}
}
break;
// max hop
case 16:
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
// payload-size
i2b_buf(2, 2, payload + i);
i += 2;
size += 2;
// set payload
if(mode == 2)
{
if(cl->reader->cacheex.maxhop)
payload[i] = cl->reader->cacheex.maxhop;
else
payload[i] = 0;
i += 1;
if(cl->reader->cacheex.maxhop_lg)
payload[i] = cl->reader->cacheex.maxhop_lg;
else
payload[i] = 0;
}
else if(mode == 3)
{
if(cl->account->cacheex.maxhop)
payload[i] = cl->account->cacheex.maxhop;
else
payload[i] = 0;
i += 1;
if(cl->account->cacheex.maxhop_lg)
payload[i] = cl->account->cacheex.maxhop_lg;
else
payload[i] = 0;
}
break;
// aio-version
case 32: ;
uint8_t token[12];
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
// payload-size
i2b_buf(2, sizeof(token), payload + i);
i += 2;
size +=sizeof(token);
// set payload
snprintf((char *)token, sizeof(token), "%s", CS_AIO_VERSION);
uint8_t *ofs = payload + i;
memcpy(ofs, token, sizeof(token));
break;
// lg_only_tab
case 64: ;
// bitfield
i2b_buf(2, feature, payload + i);
i += 2;
if(mode == 2)
{
lgonly_tab = &cl->reader->cacheex.lg_only_in_tab;
if(!lgonly_tab->nfilts)
lgonly_tab = &cfg.cacheex_lg_only_in_tab;
}
else if(mode == 3)
{
lgonly_tab = &cl->account->cacheex.lg_only_in_tab;
if(!lgonly_tab->nfilts)
lgonly_tab = &cfg.cacheex_lg_only_in_tab;
}
else
{
return;
}
char *cx_aio_ftab;
cx_aio_ftab = cxaio_ftab_to_buf(lgonly_tab);
if(cs_strlen(cx_aio_ftab) > 0 && cx_aio_ftab[0] != '\0')
{
size += cs_strlen(cx_aio_ftab) * sizeof(char);
// payload-size
i2b_buf(2, cs_strlen(cx_aio_ftab), payload + i);
i += 2;
// filter counter
payload[i] = lgonly_tab->nfilts;
i += 1;
for(j=0; j<cs_strlen(cx_aio_ftab); j+=2)
{
payload[i] = (gethexval(cx_aio_ftab[j]) << 4) | gethexval(cx_aio_ftab[j + 1]);
i++;
}
}
if(size < 32)
size = 32;
NULLFREE(cx_aio_ftab);
break;
default:
return;
}
uint8_t buf[size];
memset(buf, 0, sizeof(buf));
memcpy(buf, payload, size);
cc_cmd_send(cl, payload, size, MSG_CACHE_FEATURE_TRIGGER);
}
void cc_cacheex_feature_request_save(struct s_client *cl, uint8_t *buf)
{
int32_t field = b2i(2, buf);
if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1))
{
cl->account->cacheex.feature_bitfield = field;
// flag 32 => aio-version
if(cl->account->cacheex.feature_bitfield & 32)
{
cc_cacheex_feature_trigger(cl, 32, 2);
}
}
if(cl->typ == 'p' && cl->reader->cacheex.mode == 3)
{
cl->reader->cacheex.feature_bitfield = field;
// flag 32 => aio-version
if(cl->reader->cacheex.feature_bitfield & 32)
{
cc_cacheex_feature_trigger(cl, 32, 3);
}
}
if(cl->typ == 'c' && cl->account->cacheex.mode == 3)
{
struct s_auth *acc = cl->account;
if(acc)
{
acc->cacheex.feature_bitfield = field;
// process feature-specific actions based on feature_bitfield received
// flag 1 => set localgenerated only flag
if(acc->cacheex.feature_bitfield & 1)
{
cc_cacheex_feature_trigger(cl, 1, 3);
}
// flag 2 => set localgenerated only caids flag
if(acc->cacheex.feature_bitfield & 2 && !(acc->cacheex.feature_bitfield & 64))
{
cc_cacheex_feature_trigger(cl, 2, 3);
}
// flag 4 => set cacheex_ecm_filter (extended)
if(acc->cacheex.feature_bitfield & 4)
{
cc_cacheex_feature_trigger(cl, 4, 3);
}
// flag 8 => np push after caids
if(acc->cacheex.feature_bitfield & 8)
{
cc_cacheex_feature_trigger(cl, 8, 3);
}
// flag 16 => maxhop
if(acc->cacheex.feature_bitfield & 16)
{
cc_cacheex_feature_trigger(cl, 16, 3);
}
// flag 32 => aio-version
if(acc->cacheex.feature_bitfield & 32)
{
cc_cacheex_feature_trigger(cl, 32, 3);
}
// flag 64 => lg_only_tab
if(acc->cacheex.feature_bitfield & 64)
{
cc_cacheex_feature_trigger(cl, 64, 3);
}
}
else
{
cs_log_dbg(D_CACHEEX, "feature_bitfield save failed - cl, %s", username(cl));
}
}
else if(cl->typ == 'p' && (cl->reader->cacheex.mode == 2 || cl->reader->cacheex.mode == 1))
{
struct s_reader *rdr = cl->reader;
if(rdr)
{
rdr->cacheex.feature_bitfield = field;
// process feature-specific actions
// flag 1 => set localgenerated_only; cause of rdr->cacheex.localgenerated_only_in is set
if(rdr->cacheex.feature_bitfield & 1)
{
cc_cacheex_feature_trigger(cl, 1, 2);
}
// flag 2 => set localgenerated_only_caidtab; cause of rdr->cacheex.localgenerated_only_in_caidtab is set
if(rdr->cacheex.feature_bitfield & 2 && !(rdr->cacheex.feature_bitfield & 64))
{
cc_cacheex_feature_trigger(cl, 2, 2);
}
// flag 4 => set cacchex_ecm_filter extendend
if(rdr->cacheex.feature_bitfield & 4)
{
cc_cacheex_feature_trigger(cl, 4, 2);
}
// flag 8 => np push after caids
if(rdr->cacheex.feature_bitfield & 8)
{
cc_cacheex_feature_trigger(cl, 8, 2);
}
// flag 16 => maxhop
if(rdr->cacheex.feature_bitfield & 16)
{
cc_cacheex_feature_trigger(cl, 16, 2);
}
// flag 32 => aio-version
if(rdr->cacheex.feature_bitfield & 32)
{
cc_cacheex_feature_trigger(cl, 32, 2);
}
// flag 64 => lg_only_tab
if(rdr->cacheex.feature_bitfield & 64)
{
cc_cacheex_feature_trigger(cl, 64, 2);
}
}
else
{
cs_log_dbg(D_CACHEEX, "feature_bitfield save failed - rdr, %s", username(cl));
}
}
}
void cc_cacheex_feature_request_reply(struct s_client *cl)
{
int32_t size = 2;
uint8_t rbuf[size];
i2b_buf(2, CACHEEX_FEATURES, rbuf);
cc_cmd_send(cl, rbuf, size, MSG_CACHE_FEATURE_EXCHANGE_REPLY);
}
void cc_cacheex_feature_request(struct s_client *cl)
{
int32_t size = 2;
uint8_t rbuf[2];
i2b_buf(2, CACHEEX_FEATURES, rbuf);
cc_cmd_send(cl, rbuf, size, MSG_CACHE_FEATURE_EXCHANGE);
}
#endif
void cc_cacheex_filter_out(struct s_client *cl)
{
struct s_reader *rdr = (cl->typ == 'c') ? NULL : cl->reader;
int i = 0, j;
CECSPVALUETAB *filter;
int32_t size = 482; // minimal size, keep it <= 512 for max UDP packet size without fragmentation
uint8_t buf[482];
memset(buf, 0, sizeof(buf));
if(rdr && (rdr->cacheex.mode == 2
#ifdef CS_CACHEEX_AIO
|| rdr->cacheex.mode == 1
#endif
)) // mode == 2 send filters from rdr
{
filter = &rdr->cacheex.filter_caidtab;
#ifdef CS_CACHEEX_AIO
// if not set, use global settings
if(rdr->cacheex.filter_caidtab.cevnum == 0 && cfg.cacheex_filter_caidtab.cevnum > 0)
filter = &cfg.cacheex_filter_caidtab;
#endif
}
else if(cl->typ == 'c' && cl->account && cl->account->cacheex.mode == 3) // mode == 3 send filters from acc
{
filter = &cl->account->cacheex.filter_caidtab;
#ifdef CS_CACHEEX_AIO
// if not set, use global settings
if(cl->account->cacheex.filter_caidtab.cevnum == 0 && cfg.cacheex_filter_caidtab.cevnum > 0)
filter = &cfg.cacheex_filter_caidtab;
#endif
}
else
{
return;
}
i2b_buf(2, filter->cevnum, buf + i);
i += 2;
int32_t max_filters = 30;
for(j = 0; j < max_filters; j++)
{
if(filter->cevnum > j)
{
CECSPVALUETAB_DATA *d = &filter->cevdata[j];
i2b_buf(4, d->caid, buf + i);
}
i += 4;
}
for(j = 0; j < max_filters; j++)
{
if(filter->cevnum > j)
{
CECSPVALUETAB_DATA *d = &filter->cevdata[j];
i2b_buf(4, d->cmask, buf + i);
}
i += 4;
}
for(j = 0; j < max_filters; j++)
{
if(filter->cevnum > j)
{
CECSPVALUETAB_DATA *d = &filter->cevdata[j];
i2b_buf(4, d->prid, buf + i);
}
i += 4;
}
for(j = 0; j < max_filters; j++)
{
if(filter->cevnum > j)
{
CECSPVALUETAB_DATA *d = &filter->cevdata[j];
i2b_buf(4, d->srvid, buf + i);
}
i += 4;
}
cs_log_dbg(D_CACHEEX, "cacheex: sending push filter request to %s", username(cl));
cc_cmd_send(cl, buf, size, MSG_CACHE_FILTER);
}
void cc_cacheex_filter_in(struct s_client *cl, uint8_t *buf)
{
struct s_reader *rdr = (cl->typ == 'c') ? NULL : cl->reader;
int i = 0, j;
int32_t caid, cmask, provid, srvid;
CECSPVALUETAB *filter;
// mode == 2 write filters to acc
if(cl->typ == 'c' && cl->account && (cl->account->cacheex.mode == 2
#ifdef CS_CACHEEX_AIO
|| cl->account->cacheex.mode == 1
#endif
) && cl->account->cacheex.allow_filter == 1)
{
filter = &cl->account->cacheex.filter_caidtab;
}
else if(rdr && rdr->cacheex.mode == 3 && rdr->cacheex.allow_filter == 1) // mode == 3 write filters to rdr
{
filter = &rdr->cacheex.filter_caidtab;
}
else
{
return;
}
cecspvaluetab_clear(filter);
i += 2;
int32_t max_filters = 30;
for(j = 0; j < max_filters; j++)
{
caid = b2i(4, buf + i);
if(caid > 0)
{