1 | /*
|
---|
2 | * module-csp.c
|
---|
3 | *
|
---|
4 | * Created on: 20.12.2011
|
---|
5 | * Author: Corsair
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "globals.h"
|
---|
9 |
|
---|
10 | #ifdef CS_CACHEEX
|
---|
11 |
|
---|
12 | #include "module-cacheex.h"
|
---|
13 | #include "oscam-ecm.h"
|
---|
14 | #include "oscam-net.h"
|
---|
15 |
|
---|
16 | #define TYPE_REQUEST 1
|
---|
17 | #define TYPE_REPLY 2
|
---|
18 | #define TYPE_PINGREQ 3
|
---|
19 | #define TYPE_PINGRPL 4
|
---|
20 | #define TYPE_RESENDREQ 5
|
---|
21 |
|
---|
22 | static void * csp_server(struct s_client *client __attribute__((unused)), uchar *mbuf __attribute__((unused)), int32_t n __attribute__((unused)))
|
---|
23 | {
|
---|
24 | return NULL;
|
---|
25 | }
|
---|
26 |
|
---|
27 | static int32_t csp_recv(struct s_client *client, uchar *buf, int32_t l)
|
---|
28 | {
|
---|
29 | int32_t rs = 0;
|
---|
30 | if (!client->udp_fd) return(-9);
|
---|
31 | if (client->is_udp && client->typ == 'c') {
|
---|
32 | rs=recv_from_udpipe(buf);
|
---|
33 | } else {
|
---|
34 | rs = recv(client->udp_fd, buf, client->is_udp ? l : 36, 0);
|
---|
35 | }
|
---|
36 | //cs_ddump_mask(D_TRACE, buf, rs, "received %d bytes from csp", rs);
|
---|
37 |
|
---|
38 | uint8_t type = buf[0]; //TYPE
|
---|
39 | //int8_t commandTag = buf[1]; //commandTag
|
---|
40 |
|
---|
41 | switch(type) {
|
---|
42 | case TYPE_REPLY: // We got a CW:
|
---|
43 | if (rs >= 29) {
|
---|
44 | uint16_t srvid = (buf[2] << 8) | buf[3];
|
---|
45 | //uint16_t nwid = (buf[4] << 8) | buf[5];
|
---|
46 | uint16_t caid = (buf[6] << 8) | buf[7];
|
---|
47 | int32_t hash = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
|
---|
48 | //int8_t commandTag2 = buf[12];
|
---|
49 |
|
---|
50 | ECM_REQUEST *er = get_ecmtask();
|
---|
51 | if (!er)
|
---|
52 | return -1;
|
---|
53 |
|
---|
54 | er->caid = caid;
|
---|
55 | er->srvid = srvid;
|
---|
56 | er->csp_hash = hash;
|
---|
57 | er->rc = E_FOUND;
|
---|
58 | if (chk_csp_ctab(er, &cfg.csp.filter_caidtab)) {
|
---|
59 | memcpy(er->cw, buf+13, sizeof(er->cw));
|
---|
60 |
|
---|
61 | cs_ddump_mask(D_TRACE, er->cw, sizeof(er->cw), "received cw from csp caid=%04X srvid=%04X hash=%08X", caid, srvid, hash);
|
---|
62 | cacheex_add_to_cache_from_csp(client, er);
|
---|
63 | } else free(er);
|
---|
64 | }
|
---|
65 | break;
|
---|
66 |
|
---|
67 | case TYPE_REQUEST: // We got an Request:
|
---|
68 | if (rs >= 12) {
|
---|
69 | uint16_t srvid = (buf[2] << 8) | buf[3];
|
---|
70 | //uint16_t nwid = (buf[4] << 8) | buf[5];
|
---|
71 | uint16_t caid = (buf[6] << 8) | buf[7];
|
---|
72 | int32_t hash = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
|
---|
73 | //int8_t commandTag2 = buf[12];
|
---|
74 |
|
---|
75 | ECM_REQUEST *er = get_ecmtask();
|
---|
76 | if (!er)
|
---|
77 | return -1;
|
---|
78 |
|
---|
79 | er->caid = caid;
|
---|
80 | er->srvid = srvid;
|
---|
81 | er->csp_hash = hash;
|
---|
82 | er->rc = E_UNHANDLED;
|
---|
83 | if (chk_csp_ctab(er, &cfg.csp.filter_caidtab) && cfg.csp.allow_request) {
|
---|
84 | cs_ddump_mask(D_TRACE, buf, l, "received ecm request from csp caid=%04X srvid=%04X hash=%08X", caid, srvid, hash);
|
---|
85 | cacheex_add_to_cache_from_csp(client, er);
|
---|
86 | } else free(er);
|
---|
87 | }
|
---|
88 | break;
|
---|
89 |
|
---|
90 | case TYPE_PINGREQ:
|
---|
91 | break;
|
---|
92 |
|
---|
93 | case TYPE_PINGRPL:
|
---|
94 | break;
|
---|
95 |
|
---|
96 | case TYPE_RESENDREQ:
|
---|
97 | break;
|
---|
98 |
|
---|
99 | default:
|
---|
100 | cs_debug_mask(D_TRACE, "Unknown cache message received");
|
---|
101 | }
|
---|
102 |
|
---|
103 | return rs;
|
---|
104 | }
|
---|
105 |
|
---|
106 | //int32_t csp_send(struct s_client *client, ECM_REQUEST *er, struct s_ecm_answer *ea)
|
---|
107 | //{
|
---|
108 | // int8_t rc = ea?ea->rc:er->rc;
|
---|
109 | // uint8_t *cw = ea?ea->cw:er->cw;
|
---|
110 | //
|
---|
111 | // uint8_t buf[512];
|
---|
112 | // memset(buf, 0, sizeof(buf));
|
---|
113 | // uint16_t srvid = (buf[2] << 8) | buf[3];
|
---|
114 | // //uint16_t nwid = (buf[4] << 8) | buf[5];
|
---|
115 | // uint16_t caid = (buf[6] << 8) | buf[7];
|
---|
116 | // int32_t hash = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
|
---|
117 | // //int8_t commandTag2 = buf[12];
|
---|
118 | //
|
---|
119 | // switch(rc) {
|
---|
120 | // case E_FOUND:
|
---|
121 | // buf[0] = TYPE_REPLY;
|
---|
122 | //
|
---|
123 | // break;
|
---|
124 | //
|
---|
125 | // }
|
---|
126 | //}
|
---|
127 |
|
---|
128 | //
|
---|
129 | //static void csp_send_dcw(struct s_client *client, ECM_REQUEST *er)
|
---|
130 | //{
|
---|
131 | //}
|
---|
132 | //
|
---|
133 | //int32_t csp_client_init(struct s_client *client)
|
---|
134 | //{
|
---|
135 | // return -1;
|
---|
136 | //}
|
---|
137 | //
|
---|
138 | //static int32_t csp_recv_chk(struct s_client *client, uchar *dcw, int32_t *rc, uchar *buf, int32_t rc2)
|
---|
139 | //{
|
---|
140 | // return -1;
|
---|
141 | //}
|
---|
142 | //
|
---|
143 | //static int32_t csp_send_ecm(struct s_client *client, ECM_REQUEST *er, uchar *buf)
|
---|
144 | //{
|
---|
145 | // return -1;
|
---|
146 | //}
|
---|
147 | //
|
---|
148 | void module_csp(struct s_module *ph)
|
---|
149 | {
|
---|
150 | static PTAB ptab; //since there is always only 1 csp server running, this is threadsafe
|
---|
151 | ptab.ports[0].s_port = cfg.csp_port;
|
---|
152 | ph->ptab = &ptab;
|
---|
153 | ph->ptab->nports = 1;
|
---|
154 |
|
---|
155 | ph->desc="csp";
|
---|
156 | ph->type=MOD_CONN_UDP;
|
---|
157 | ph->large_ecm_support = 1;
|
---|
158 | ph->listenertype = LIS_CSPUDP;
|
---|
159 | IP_ASSIGN(ph->s_ip, cfg.csp_srvip);
|
---|
160 | ph->s_handler=csp_server;
|
---|
161 | ph->recv=csp_recv;
|
---|
162 | // ph->send_dcw=csp_send_dcw;
|
---|
163 | // ph->c_init=csp_client_init;
|
---|
164 | // ph->c_recv_chk=csp_recv_chk;
|
---|
165 | // ph->c_send_ecm=csp_send_ecm;
|
---|
166 | // ph->c_send_emm=csp_send_emm;
|
---|
167 | // ph->c_init_log=csp_client_init_log;
|
---|
168 | // ph->c_recv_log=csp_recv_log;
|
---|
169 | // ph->c_cache_push=csp_cache_push_out;
|
---|
170 | ph->num=R_CSP;
|
---|
171 | }
|
---|
172 |
|
---|
173 | #endif
|
---|