1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
#include <fcntl.h>
#include <sys/ioctl.h>
#include <lib/base/init.h>
#include <lib/base/init_num.h>
#include <lib/base/ebase.h>
#include <lib/base/eerror.h>
#include <lib/dvb_ci/dvbci.h>
#include <lib/dvb_ci/dvbci_session.h>
#include <lib/dvb_ci/dvbci_ui.h>
#include <lib/dvb_ci/dvbci_appmgr.h>
#include <lib/dvb_ci/dvbci_mmi.h>
eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;
eDVBCIInterfaces::eDVBCIInterfaces()
{
int num_ci = 0;
instance = this;
eDebug("scanning for common interfaces..");
while (1)
{
struct stat s;
char filename[128];
sprintf(filename, "/dev/ci%d", num_ci);
if (stat(filename, &s))
break;
ePtr<eDVBCISlot> cislot;
cislot = new eDVBCISlot(eApp, num_ci);
m_slots.push_back(cislot);
++num_ci;
}
eDebug("done, found %d common interface slots", num_ci);
}
eDVBCIInterfaces::~eDVBCIInterfaces()
{
}
eDVBCIInterfaces *eDVBCIInterfaces::getInstance()
{
return instance;
}
eDVBCISlot *eDVBCIInterfaces::getSlot(int slotid)
{
for(eSmartPtrList<eDVBCISlot>::iterator i(m_slots.begin()); i != m_slots.end(); ++i)
if(i->getSlotID() == slotid)
return i;
printf("FIXME: request for unknown slot\n");
return 0;
}
int eDVBCIInterfaces::reset(int slotid)
{
eDVBCISlot *slot;
if( (slot = getSlot(slotid)) == 0 )
return -1;
return slot->reset();
}
int eDVBCIInterfaces::initialize(int slotid)
{
eDVBCISlot *slot;
if( (slot = getSlot(slotid)) == 0 )
return -1;
return slot->initialize();
}
int eDVBCIInterfaces::startMMI(int slotid)
{
eDVBCISlot *slot;
if( (slot = getSlot(slotid)) == 0 )
return -1;
return slot->startMMI();
}
int eDVBCIInterfaces::stopMMI(int slotid)
{
eDVBCISlot *slot;
if( (slot = getSlot(slotid)) == 0 )
return -1;
return slot->stopMMI();
}
int eDVBCIInterfaces::answerText(int slotid, int answer)
{
eDVBCISlot *slot;
if( (slot = getSlot(slotid)) == 0 )
return -1;
return slot->answerText(answer);
}
int eDVBCIInterfaces::answerEnq(int slotid, int answer, char *value)
{
eDVBCISlot *slot;
if( (slot = getSlot(slotid)) == 0 )
return -1;
return slot->answerEnq(answer, value);
}
int eDVBCISlot::send(const unsigned char *data, size_t len)
{
int res;
//int i;
//printf("< ");
//for(i=0;i<len;i++)
// printf("%02x ",data[i]);
//printf("\n");
res = ::write(fd, data, len);
//printf("write() %d\n",res);
notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
return res;
}
void eDVBCISlot::data(int what)
{
if(what == eSocketNotifier::Priority) {
if(state != stateRemoved) {
state = stateRemoved;
printf("ci removed\n");
notifier->setRequested(eSocketNotifier::Read);
//HACK
eDVBCI_UI::getInstance()->setState(0,0);
}
return;
}
__u8 data[4096];
int r;
r = ::read(fd, data, 4096);
if(state != stateInserted) {
state = stateInserted;
eDebug("ci inserted");
//HACK
eDVBCI_UI::getInstance()->setState(0,1);
/* enable PRI to detect removal or errors */
notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
}
if(r > 0) {
//int i;
//printf("> ");
//for(i=0;i<r;i++)
// printf("%02x ",data[i]);
//printf("\n");
eDVBCISession::receiveData(this, data, r);
notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
return;
}
if(what == eSocketNotifier::Write) {
if(eDVBCISession::pollAll() == 0) {
notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
}
}
}
DEFINE_REF(eDVBCISlot);
eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
{
char filename[128];
application_manager = 0;
mmi_session = 0;
slotid = nr;
sprintf(filename, "/dev/ci%d", nr);
fd = ::open(filename, O_RDWR | O_NONBLOCK);
eDebug("eDVBCISlot has fd %d", fd);
state = stateInserted;
if (fd >= 0)
{
notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
CONNECT(notifier->activated, eDVBCISlot::data);
} else
{
perror(filename);
}
}
eDVBCISlot::~eDVBCISlot()
{
}
int eDVBCISlot::getSlotID()
{
return slotid;
}
int eDVBCISlot::reset()
{
printf("edvbcislot: reset requested\n");
ioctl(fd, 0);
return 0;
}
int eDVBCISlot::initialize()
{
printf("edvbcislot: initialize()\n");
return 0;
}
int eDVBCISlot::startMMI()
{
printf("edvbcislot: startMMI()\n");
if(application_manager)
application_manager->startMMI();
return 0;
}
int eDVBCISlot::stopMMI()
{
printf("edvbcislot: stopMMI()\n");
if(mmi_session)
mmi_session->stopMMI();
return 0;
}
int eDVBCISlot::answerText(int answer)
{
printf("edvbcislot: answerText(%d)\n", answer);
if(mmi_session)
mmi_session->answerText(answer);
return 0;
}
int eDVBCISlot::answerEnq(int answer, char *value)
{
printf("edvbcislot: answerMMI(%d,%s)\n", answer, value);
return 0;
}
eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");
|