1 #if !defined(DISABLE_DVBCA) || !defined(DISABLE_DVBAPI)
2 
3 #ifndef TABLES_H
4 #define TABLES_H
5 
6 #include "adapter.h"
7 #include "pmt.h"
8 
9 #define MAX_CA 8
10 #define MAX_CAID_LEN 30
11 
12 #define TABLES_RESULT_OK 0
13 #define TABLES_RESULT_ERROR_RETRY 1
14 #define TABLES_RESULT_ERROR_NORETRY 2
15 
16 #define TABLES_CHANNEL_ENCRYPTED 1
17 #define TABLES_CHANNEL_DECRYPTED 2
18 
19 typedef int (*ca_pmt_action)(adapter *ad, SPMT *pmt);
20 typedef int (*ca_pid_action)(adapter *ad, SPMT *pmt, int pid);
21 typedef int (*ca_device_action)(adapter *ad);
22 typedef int (*ca_close_action)();
23 
24 typedef struct struct_CA_op {
25     ca_pid_action ca_add_pid, ca_del_pid;
26     ca_pmt_action ca_add_pmt, ca_del_pmt, ca_decrypted, ca_encrypted;
27     ca_device_action ca_init_dev, ca_close_dev, ca_ts;
28     ca_close_action ca_close_ca;
29 } SCA_op;
30 
31 typedef struct struct_CA_AD {
32     int caid[MAX_CAID_LEN], mask[MAX_CAID_LEN];
33     int caids;
34 
35 } SCA_AD;
36 
37 typedef struct struct_CA {
38     uint8_t enabled;
39     SCA_op *op;
40     uint64_t adapter_mask; // 1 << x, means enabled for adapter X
41     int id;
42     SCA_AD ad_info[MAX_ADAPTERS];
43 } SCA;
44 int add_ca(SCA_op *op, uint64_t adapter_mask);
45 void del_ca(SCA_op *op);
46 void add_caid_mask(int ica, int aid, int caid, int mask);
47 void init_ca_device(SCA *c); //  calls table_init_device for all the devices
48 int register_ca_for_adapter(
49     int i,
50     int aid); // register a CA just for a device, and run tables_init_device for
51               // the CA and Adapter, if succeds, send all the opened PMTs
52 int unregister_ca_for_adapter(int i,
53                               int aid); // unregister a CA just for a device
54 int tables_init_device(adapter *ad);
55 int tables_close_device(adapter *ad);
56 int tables_init();
57 int tables_destroy();
58 void tables_add_pid(adapter *ad, SPMT *pmt, int pid);
59 void tables_del_pid(adapter *ad, SPMT *pmt, int pid);
60 int send_pmt_to_cas(adapter *ad, SPMT *pmt);
61 void close_pmt_for_ca(int i, adapter *ad, SPMT *pmt);
62 int close_pmt_for_cas(adapter *ad, SPMT *pmt);
63 void tables_ca_ts(adapter *ad);
64 int match_caid(SPMT *pmt, int caid, int mask);
65 void tables_update_encrypted_status(adapter *ad, SPMT *pmt);
66 
67 #endif
68 
69 #endif
70