~ubuntu-branches/debian/jessie/tsdecrypt/jessie

« back to all changes in this revision

Viewing changes to data.c

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-04-04 09:42:43 UTC
  • Revision ID: package-import@ubuntu.com-20120404094243-qsc40h18oolnxw5r
Tags: upstream-7.0
ImportĀ upstreamĀ versionĀ 7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Data functions
 
3
 * Copyright (C) 2011 Unix Solutions Ltd.
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License version 2
 
7
 * as published by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 
17
 */
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
#include <string.h>
 
21
 
 
22
#include "data.h"
 
23
#include "camd.h"
 
24
 
 
25
void data_init(struct ts *ts) {
 
26
        memset(ts, 0, sizeof(struct ts));
 
27
        // Stream
 
28
        ts->pat      = ts_pat_alloc();
 
29
        ts->curpat   = ts_pat_alloc();
 
30
        ts->genpat   = ts_pat_alloc();
 
31
 
 
32
        ts->cat      = ts_cat_alloc();
 
33
        ts->curcat   = ts_cat_alloc();
 
34
 
 
35
        ts->pmt      = ts_pmt_alloc();
 
36
        ts->curpmt   = ts_pmt_alloc();
 
37
 
 
38
        ts->sdt      = ts_sdt_alloc();
 
39
        ts->cursdt   = ts_sdt_alloc();
 
40
 
 
41
        ts->emm      = ts_privsec_alloc();
 
42
        ts->last_emm = ts_privsec_alloc();
 
43
        ts->tmp_emm  = ts_privsec_alloc();
 
44
 
 
45
        ts->ecm      = ts_privsec_alloc();
 
46
        ts->last_ecm = ts_privsec_alloc();
 
47
        ts->tmp_ecm  = ts_privsec_alloc();
 
48
 
 
49
        pidmap_clear(&ts->pidmap);
 
50
        pidmap_clear(&ts->cc);
 
51
        pidmap_clear(&ts->pid_seen);
 
52
 
 
53
        // Key
 
54
        memset(&ts->key, 0, sizeof(ts->key));
 
55
        ts->key.csakey[0] = dvbcsa_key_alloc();
 
56
        ts->key.csakey[1] = dvbcsa_key_alloc();
 
57
 
 
58
        ts->key.bs_csakey[0] = dvbcsa_bs_key_alloc();
 
59
        ts->key.bs_csakey[1] = dvbcsa_bs_key_alloc();
 
60
 
 
61
        gettimeofday(&ts->key.ts_keyset, NULL);
 
62
 
 
63
        // CAMD
 
64
        memset(&ts->camd, 0, sizeof(ts->camd));
 
65
        ts->camd.server_fd    = -1;
 
66
        ts->camd.server_port  = 2233;
 
67
        ts->camd.key          = &ts->key;
 
68
        ts->camd.user         = "user";
 
69
        ts->camd.pass         = "pass";
 
70
        strcpy(ts->camd.newcamd.hex_des_key, "0102030405060708091011121314");
 
71
 
 
72
        camd_proto_cs378x(&ts->camd.ops);
 
73
 
 
74
        // Config
 
75
        ts->syslog_port = 514;
 
76
 
 
77
        ts->ts_discont  = 1;
 
78
        ts->ecm_cw_log  = 1;
 
79
 
 
80
        ts->debug_level = 0;
 
81
        ts->req_CA_sys  = CA_CONAX;
 
82
        ts->emm_send    = 0;
 
83
        ts->pid_filter  = 1;
 
84
 
 
85
        ts->emm_report_interval = 60;
 
86
        ts->emm_last_report     = time(NULL);
 
87
 
 
88
        ts->ecm_report_interval = 60;
 
89
        ts->ecm_last_report     = time(NULL);
 
90
 
 
91
        ts->cw_warn_sec = 60;
 
92
        ts->cw_last_warn= time(NULL);
 
93
        ts->cw_last_warn= ts->cw_last_warn + ts->cw_warn_sec;
 
94
        ts->key.ts      = time(NULL);
 
95
 
 
96
        ts->input.fd    = 0; // STDIN
 
97
        ts->input.type  = FILE_IO;
 
98
 
 
99
        ts->output.fd   = 1; // STDOUT
 
100
        ts->output.type = FILE_IO;
 
101
        ts->output.ttl  = 1;
 
102
        ts->output.tos  = -1;
 
103
 
 
104
        ts->decode_buf  = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) * 16, "decode"); // ~658Kb
 
105
        ts->write_buf   = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) *  8, "write");  // ~324Kb
 
106
 
 
107
        ts->input_buffer= list_new("input");
 
108
}
 
109
 
 
110
void data_free(struct ts *ts) {
 
111
        ts_pat_free(&ts->pat);
 
112
        ts_pat_free(&ts->curpat);
 
113
        ts_pat_free(&ts->genpat);
 
114
        ts_cat_free(&ts->cat);
 
115
        ts_cat_free(&ts->curcat);
 
116
        ts_pmt_free(&ts->pmt);
 
117
        ts_pmt_free(&ts->curpmt);
 
118
        ts_sdt_free(&ts->sdt);
 
119
        ts_sdt_free(&ts->cursdt);
 
120
        ts_privsec_free(&ts->emm);
 
121
        ts_privsec_free(&ts->last_emm);
 
122
        ts_privsec_free(&ts->tmp_emm);
 
123
        ts_privsec_free(&ts->ecm);
 
124
        ts_privsec_free(&ts->last_ecm);
 
125
        ts_privsec_free(&ts->tmp_ecm);
 
126
 
 
127
        dvbcsa_key_free(ts->key.csakey[0]);
 
128
        dvbcsa_key_free(ts->key.csakey[1]);
 
129
 
 
130
        dvbcsa_bs_key_free(ts->key.bs_csakey[0]);
 
131
        dvbcsa_bs_key_free(ts->key.bs_csakey[1]);
 
132
 
 
133
        cbuf_free(&ts->decode_buf);
 
134
        cbuf_free(&ts->write_buf);
 
135
 
 
136
        FREE(ts->input.fname);
 
137
        FREE(ts->output.fname);
 
138
 
 
139
        list_free(&ts->input_buffer, free, NULL);
 
140
 
 
141
        // glibc's crypt function allocates static buffer on first crypt() call.
 
142
        // Since newcamd uses crypt(), the result is saved in c->newcamd.crypt_passwd
 
143
        // and in order to avoid leaking 43 bytes of memory on exit which makes valgrind
 
144
        // unhappy it is a good idea to free the memory (ONCE!).
 
145
        FREE(ts->camd.newcamd.crypt_passwd);
 
146
}