source: trunk/module-constcw.c @ 5375

Last change on this file since 5375 was 4994, checked in by Admin, 8 years ago

I noticed that monitor encryption is not working on 64bit plattforms due to other sizes of long on this plattform. This patch converts all numeric types like long to portable types like uint32_t. This is not complete yet (only base folder up to r4987, changes thereafter might be incompletely converted). If you encounter problems through this patch please report in forum.

File size: 4.2 KB
Line 
1//FIXME Not checked on threadsafety yet; after checking please remove this line
2#include "globals.h"
3
4int32_t pserver = 0;
5
6int32_t constcw_file_available(void)
7{
8    FILE *fp;
9   
10    fp=fopen(cur_client()->reader->device, "r");
11    if (!fp) return (0);
12    fclose(fp);
13    return (1);
14}
15
16int32_t constcw_analyse_file(uint16_t c_caid, uint32_t c_prid, uint16_t c_sid, uchar *dcw)
17{
18    //CAID:PROVIDER:SID:PMT:PID:: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
19   
20    FILE *fp;
21    char token[4096];
22    uint32_t caid, provid, sid, pmt, pid;
23    uchar cw[16];
24
25    // FIXME
26    c_prid = c_prid;
27
28    fp=fopen(cur_client()->reader->device, "r");
29    if (!fp) return (0);
30   
31    while (fgets(token, sizeof(token), fp))
32    {
33    if (token[0]=='#') continue;
34   
35    sscanf(token, "%x:%x:%x:%x:%x::%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", &caid, &provid, &sid, &pmt, &pid, 
36        (uint*) &cw[0], (uint*) &cw[1], (uint*) &cw[2], (uint*) &cw[3], 
37        (uint*) &cw[4], (uint*) &cw[5], (uint*) &cw[6], (uint*) &cw[7], 
38        (uint*) &cw[8], (uint*) &cw[9], (uint*) &cw[10], (uint*) &cw[11], 
39        (uint*) &cw[12], (uint*) &cw[13], (uint*) &cw[14], (uint*) &cw[15]);
40
41    //cs_log("Line found: %s", token);
42    if (c_caid == caid && c_sid == sid)
43    {
44        cs_log("Entry found: %04X:%06X:%04X %s", caid, provid, sid, cs_hexdump(1, cw, 16));
45        memcpy(dcw, cw, 16);
46        fclose(fp);
47        return 1;
48    }
49    }
50   
51    fclose(fp);
52    return 0;
53}
54//************************************************************************************************************************
55//* client/server common functions
56//************************************************************************************************************************
57static int32_t constcw_recv(struct s_client *client, uchar *buf, int32_t l)
58{
59    int32_t ret;
60
61    if (!client->udp_fd) return(-9);
62    ret = read(client->udp_fd, buf, l);
63    if (ret < 1) return(-1);
64    client->last = time(NULL);
65    return(ret);
66}
67
68//************************************************************************************************************************
69//*       client functions
70//************************************************************************************************************************
71int32_t constcw_client_init(struct s_client *client)
72{
73    int32_t fdp[2];
74   
75    client->pfd = 0;
76    if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fdp))
77    {
78    cs_log("Socket creation failed (%s)", strerror(errno));
79    cs_exit(1);
80    }
81    client->udp_fd =fdp[0];
82    pserver = fdp[1];
83
84    memset((char *) &client->udp_sa, 0, sizeof(client->udp_sa));
85    client->udp_sa.sin_family = AF_INET;
86
87    // Oscam has no reader.au in s_reader like ki's mpcs ;)
88    // reader[ridx].au = 0;
89    // cs_log("local reader: %s (file: %s) constant cw au=0", reader[ridx].label, reader[ridx].device);
90    cs_log("local reader: %s (file: %s) constant cw", client->reader->label, client->reader->device);
91
92    client->pfd = client->udp_fd;
93   
94    if (constcw_file_available())
95    {
96    client->reader->tcp_connected = 2;
97        client->reader->card_status = CARD_INSERTED;
98    }
99
100    return(0);
101}
102
103static int32_t constcw_send_ecm(struct s_client *client, ECM_REQUEST *er, uchar *msgbuf)
104{
105    time_t t;
106    struct s_reader *rdr = client->reader;
107
108    // FIXME
109    msgbuf = msgbuf;
110
111    t = time(NULL);
112    // Check if DCW exist in the files
113    //cs_log("Searching ConstCW for ECM: %04X:%06X:%04X (%d)", er->caid, er->prid, er->srvid, er->l);
114   
115    if (constcw_analyse_file(er->caid, er->prid, er->srvid, er->cw)==0)
116    {
117        er->rc = E_RDR_NOTFOUND;
118        er->rcEx = E1_READER<<4 | E2_SID;
119    //cs_sleepms(100);
120    }
121
122    //cs_sleepms(50);
123    write_ecm_answer(rdr, er);
124   
125    client->last = t;
126    rdr->last_g = t;
127    return(0);
128}
129
130static int32_t constcw_recv_chk(struct s_client *client, uchar *dcw, int32_t *rc, uchar *buf, int32_t n)
131{
132    // FIXME
133    *client = *client;
134    dcw = dcw;
135    n = n;
136    buf = buf;
137
138    *rc = 0;
139    return(-1);
140}
141
142void module_constcw(struct s_module *ph)
143{
144  cs_strncpy(ph->desc, "constcw", sizeof(ph->desc));
145  ph->type = MOD_NO_CONN;
146  ph->multi = 0;
147  ph->watchdog = 1;
148  ph->recv = constcw_recv;
149 
150  ph->c_multi = 1;
151  ph->c_init = constcw_client_init;
152  ph->c_recv_chk = constcw_recv_chk;
153  ph->c_send_ecm = constcw_send_ecm;
154  ph->num=R_CONSTCW;
155}
Note: See TracBrowser for help on using the repository browser.