source: trunk/module-csp.c@ 8455

Last change on this file since 8455 was 8455, checked in by gf, 9 years ago

Make ptab in struct s_module embedded not a pointer.

This blows up bss (static) memory nearly twice but we'll get that
back and lots more once we slim down struct s_port in the next
commit.

  • Property svn:eol-style set to LF
File size: 4.1 KB
Line 
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
22static void * csp_server(struct s_client *client __attribute__((unused)), uchar *mbuf __attribute__((unused)), int32_t n __attribute__((unused)))
23{
24 return NULL;
25}
26
27static 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//
148void module_csp(struct s_module *ph)
149{
150 ph->ptab.nports = 1;
151 ph->ptab.ports[0].s_port = cfg.csp_port;
152
153 ph->desc="csp";
154 ph->type=MOD_CONN_UDP;
155 ph->large_ecm_support = 1;
156 ph->listenertype = LIS_CSPUDP;
157 IP_ASSIGN(ph->s_ip, cfg.csp_srvip);
158 ph->s_handler=csp_server;
159 ph->recv=csp_recv;
160// ph->send_dcw=csp_send_dcw;
161// ph->c_init=csp_client_init;
162// ph->c_recv_chk=csp_recv_chk;
163// ph->c_send_ecm=csp_send_ecm;
164// ph->c_send_emm=csp_send_emm;
165// ph->c_init_log=csp_client_init_log;
166// ph->c_recv_log=csp_recv_log;
167// ph->c_cache_push=csp_cache_push_out;
168 ph->num=R_CSP;
169}
170
171#endif
Note: See TracBrowser for help on using the repository browser.