-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathmmi_ui.cpp
336 lines (285 loc) · 7.27 KB
/
mmi_ui.cpp
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <lib/mmi/mmi_ui.h>
#include <lib/dvb_ci/dvbci_session.h> // for parseLengthField
#include <regex>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <lib/base/init.h>
#include <lib/base/init_num.h>
#include <lib/base/eerror.h>
#include <lib/base/estring.h>
eMMI_UI::eMMI_UI(int max_slots)
:m_max_slots(max_slots)
{
slotdata = new slot_ui_data[m_max_slots];
for(int i=0;i<m_max_slots;++i)
{
slotdata[i].mmiScreenReady=0;
slotdata[i].mmiTuplePos=0;
slotdata[i].state=-1;
}
}
eMMI_UI::~eMMI_UI()
{
for(int i=0;i<m_max_slots;++i)
{
if (slotdata[i].mmiScreen)
Py_DECREF(slotdata[i].mmiScreen);
}
delete [] slotdata;
}
int eMMI_UI::processMMIData(int slot_id, const unsigned char *tag, const void *data, int len)
{
switch (tag[2])
{
case 0x00: //Tmmi_close
{
unsigned char *d=(unsigned char*)data;
int timeout=0;
if (d[0] == 1)
{
if (len > 1)
timeout = d[1];
else
{
eDebug("[eMMI_UI] close tag incorrect.. no timeout given.. assume 5 seconds");
timeout = 5;
}
}
else if (d[0] > 1)
eDebug("[eMMI_UI] close tag incorrect.. byte 4 should be 0 or 1");
mmiScreenClose(slot_id, timeout);
break;
}
case 0x01:
eDebug("[eMMI_UI] display control");
if (((unsigned char*)data)[0] != 1)
eDebug("[eMMI_UI] displeay control failes: expected 1 as first byte, got %d", ((unsigned char*)data)[0]);
return 1;
case 0x07: //Tmenu_enq
{
unsigned char *d=(unsigned char*)data;
unsigned char *max=((unsigned char*)d) + len;
int textlen = len - 2;
eDebug("[eMMI_UI] in enq");
if ((d+2) > max)
break;
int blind = *d++ & 1;
int alen = *d++;
eDebug("[eMMI_UI] %d bytes text", textlen);
if ((d+textlen) > max)
break;
unsigned char str[textlen + 1];
memcpy(str, ((unsigned char*)d), textlen);
str[textlen] = '\0';
std::string converted_str = convertDVBUTF8(str, textlen, -1, 1, 0);
eDebug("[eMMI_UI] enq-text: %s", converted_str.c_str());
mmiScreenEnq(slot_id, blind, alen, (char*)converted_str.c_str());
break;
}
case 0x09: //Tmenu_last
case 0x0c: //Tlist_last
{
unsigned char *d=(unsigned char*)data;
unsigned char *max=((unsigned char*)d) + len;
int pos = 0;
eDebug("[eMMI_UI] Tmenu_last");
if (d > max)
break;
int n=*d++;
if(tag[2] == 0x09) //menu
mmiScreenBegin(slot_id, 0);
else //list
mmiScreenBegin(slot_id, 1);
if (n == 0xFF)
n=0;
else
n++;
eDebug("[eMMI_UI] %d texts", n);
for (int i=0; i < (n+3); ++i)
{
int textlen;
if ((d+3) > max)
break;
eDebug("[eMMI_UI] text tag: %02x %02x %02x", d[0], d[1], d[2]);
d+=3;
d+=eDVBCISession::parseLengthField(d, textlen);
eDebug("[eMMI_UI] %d bytes text", textlen);
if ((d+textlen) > max)
break;
unsigned char str[textlen + 1];
memcpy(str, ((unsigned char*)d), textlen);
str[textlen] = '\0';
std::string converted_str = convertDVBUTF8(str, textlen, -1, 1, 0);
mmiScreenAddText(slot_id, pos++, (char*)converted_str.c_str());
eDebug("[eMMI_UI] %s", converted_str.c_str());
d += textlen;
}
mmiScreenFinish(slot_id);
break;
}
default:
eDebug("[eMMI_UI] unknown APDU tag 9F 88 %02x", tag[2]);
break;
}
return 0;
}
int eMMI_UI::getState(int slot)
{
if (slot < m_max_slots)
return slotdata[slot].state;
return 0;
}
int eMMI_UI::getDecodingState(int slot)
{
if (slot < m_max_slots)
return slotdata[slot].decoding_state;
return 0;
}
void eMMI_UI::setState(int slot, int newState)
{
if (slot < m_max_slots)
{
slotdata[slot].state = newState;
stateChanged(slot);
}
}
void eMMI_UI::setDecodingState(int slot, int newState)
{
if (slot < m_max_slots)
{
if (slotdata[slot].decoding_state == 1 && newState == 2)
slotdata[slot].decoding_state = 2;
else if (newState != 2)
slotdata[slot].decoding_state = newState;
stateChanged(slot);
}
}
std::string eMMI_UI::getAppName(int slot)
{
if (slot < m_max_slots)
return slotdata[slot].appName;
return "";
}
void eMMI_UI::setAppName(int slot, const char *name)
{
if (slot < m_max_slots)
slotdata[slot].appName = name;
}
int eMMI_UI::availableMMI(int slot)
{
if (slot < m_max_slots)
return slotdata[slot].mmiScreenReady;
return false;
}
int eMMI_UI::mmiScreenClose(int slot, int timeout)
{
if (slot >= m_max_slots)
return 0;
slot_ui_data &data = slotdata[slot];
data.mmiScreenReady = 0;
if (data.mmiScreen)
Py_DECREF(data.mmiScreen);
data.mmiScreen = PyList_New(1);
ePyObject tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("CLOSE"));
PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(timeout));
PyList_SET_ITEM(data.mmiScreen, 0, tuple);
data.mmiScreenReady = 1;
stateChanged(slot);
return 0;
}
int eMMI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
{
if (slot >= m_max_slots)
return 0;
slot_ui_data &data = slotdata[slot];
data.mmiScreenReady = 0;
if (data.mmiScreen)
Py_DECREF(data.mmiScreen);
data.mmiScreen = PyList_New(2);
ePyObject tuple = PyTuple_New(1);
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("ENQ"));
PyList_SET_ITEM(data.mmiScreen, 0, tuple);
tuple = PyTuple_New(4);
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("PIN"));
PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(answerLen));
PyTuple_SET_ITEM(tuple, 2, PyUnicode_FromString(text));
PyTuple_SET_ITEM(tuple, 3, PyLong_FromLong(blind));
PyList_SET_ITEM(data.mmiScreen, 1, tuple);
data.mmiScreenReady = 1;
stateChanged(slot);
return 0;
}
int eMMI_UI::mmiScreenBegin(int slot, int listmenu)
{
if (slot >= m_max_slots)
return 0;
eDebug("[eMMI_UI] mmiScreenBegin");
slot_ui_data &data = slotdata[slot];
data.mmiScreenReady = 0;
if (data.mmiScreen)
Py_DECREF(data.mmiScreen);
data.mmiScreen = PyList_New(1);
ePyObject tuple = PyTuple_New(1);
if (listmenu == 0) //menu
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("MENU"));
else //list
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("LIST"));
PyList_SET_ITEM(data.mmiScreen, 0, tuple);
data.mmiTuplePos = 1;
return 0;
}
int eMMI_UI::mmiScreenAddText(int slot, int type, char *value)
{
if (slot >= m_max_slots)
return 0;
eDebug("[eMMI_UI] mmiScreenAddText(%s)",value ? value : "");
slot_ui_data &data = slotdata[slot];
ePyObject tuple = PyTuple_New(3);
if (type == 0) //title
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("TITLE"));
else if (type == 1) //subtitle
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("SUBTITLE"));
else if (type == 2) //bottom
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("BOTTOM"));
else
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString("TEXT"));
eDebug("[eMMI_UI] addText %s with id %d", value, type);
PyTuple_SET_ITEM(tuple, 1, PyUnicode_FromString(value));
if (type > 2)
PyTuple_SET_ITEM(tuple, 2, PyLong_FromLong(type-2));
else
PyTuple_SET_ITEM(tuple, 2, PyLong_FromLong(-1));
PyList_Append(data.mmiScreen, tuple);
Py_DECREF(tuple);
return 0;
}
int eMMI_UI::mmiScreenFinish(int slot)
{
if (slot < m_max_slots)
{
eDebug("[eMMI_UI] mmiScreenFinish");
slotdata[slot].mmiScreenReady = 1;
stateChanged(slot);
}
return 0;
}
void eMMI_UI::mmiSessionDestroyed(int slot)
{
mmiScreenClose(slot, 0);
}
PyObject *eMMI_UI::getMMIScreen(int slot)
{
if (slot < m_max_slots)
{
slot_ui_data &data = slotdata[slot];
if (data.mmiScreenReady)
{
data.mmiScreenReady = 0;
Py_INCREF(data.mmiScreen);
return data.mmiScreen;
}
}
Py_RETURN_NONE;
}