source: trunk/module-constcw.c@ 4149

Last change on this file since 4149 was 3653, checked in by dingo35, 13 years ago

get rid of extern reader declararions

File size: 4.1 KB
Line 
1//FIXME Not checked on threadsafety yet; after checking please remove this line
2#include "globals.h"
3
4int pserver = 0;
5
6int 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
16int constcw_analyse_file(ushort c_caid, uint c_prid, ushort 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 uint 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 int constcw_recv(struct s_client *client, uchar *buf, int l)
58{
59 int 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//************************************************************************************************************************
71int constcw_client_init(struct s_client *client)
72{
73 int 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 int 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 = 0;
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 int constcw_recv_chk(struct s_client *client, uchar *dcw, int *rc, uchar *buf, int 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 strcpy(ph->desc, "constcw");
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.