-
Notifications
You must be signed in to change notification settings - Fork 38
/
en50221.h
206 lines (175 loc) · 6.82 KB
/
en50221.h
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
/*****************************************************************************
* en50221.h
*****************************************************************************
* Copyright (C) 2008 VideoLAN
*
* Authors: Christophe Massiot <[email protected]>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*****************************************************************************/
#include <stddef.h>
typedef void * access_t;
#define STRINGIFY( z ) UGLY_KLUDGE( z )
#define UGLY_KLUDGE( z ) #z
#define EN50221_MMI_NONE 0
#define EN50221_MMI_ENQ 1
#define EN50221_MMI_ANSW 2
#define EN50221_MMI_MENU 3
#define EN50221_MMI_MENU_ANSW 4
#define EN50221_MMI_LIST 5
typedef struct en50221_mmi_object_t
{
int i_object_type;
union
{
struct
{
int b_blind;
char *psz_text;
} enq;
struct
{
int b_ok;
char *psz_answ;
} answ;
struct
{
char *psz_title, *psz_subtitle, *psz_bottom;
char **ppsz_choices;
int i_choices;
} menu; /* menu and list are the same */
struct
{
int i_choice;
} menu_answ;
} u;
} en50221_mmi_object_t;
#define MAX_CI_SLOTS 16
#define MAX_SESSIONS 32
extern int i_ca_handle;
extern int i_ca_type;
/*****************************************************************************
* Prototypes
*****************************************************************************/
void en50221_Init( void );
void en50221_Reset( void );
void en50221_AddPMT( uint8_t *p_pmt );
void en50221_UpdatePMT( uint8_t *p_pmt );
void en50221_DeletePMT( uint8_t *p_pmt );
uint8_t en50221_StatusMMI( uint8_t *p_answer, ssize_t *pi_size );
uint8_t en50221_StatusMMISlot( uint8_t *p_buffer, ssize_t i_size,
uint8_t *p_answer, ssize_t *pi_size );
uint8_t en50221_OpenMMI( uint8_t *p_buffer, ssize_t i_size );
uint8_t en50221_CloseMMI( uint8_t *p_buffer, ssize_t i_size );
uint8_t en50221_GetMMIObject( uint8_t *p_buffer, ssize_t i_size,
uint8_t *p_answer, ssize_t *pi_size );
uint8_t en50221_SendMMIObject( uint8_t *p_buffer, ssize_t i_size );
/*
* This is where it gets scary: do not show to < 18 yrs old
*/
/*****************************************************************************
* en50221_SerializeMMIObject :
*****************************************************************************/
static inline int en50221_SerializeMMIObject( uint8_t *p_answer,
ssize_t *pi_size,
en50221_mmi_object_t *p_object )
{
ssize_t i_max_size = *pi_size;
en50221_mmi_object_t *p_serialized = (en50221_mmi_object_t *)p_answer;
char **pp_tmp;
int i;
#define STORE_MEMBER(pp_pointer, i_size) \
if ( i_size + *pi_size > i_max_size ) \
return -1; \
memcpy( p_answer, *pp_pointer, i_size ); \
*pp_pointer = (void *)*pi_size; \
*pi_size += i_size; \
p_answer += i_size;
if ( sizeof(en50221_mmi_object_t) > i_max_size )
return -1;
memcpy( p_answer, p_object, sizeof(en50221_mmi_object_t) );
*pi_size = sizeof(en50221_mmi_object_t);
p_answer += sizeof(en50221_mmi_object_t);
switch ( p_object->i_object_type )
{
case EN50221_MMI_ENQ:
STORE_MEMBER( &p_serialized->u.enq.psz_text,
strlen(p_object->u.enq.psz_text) + 1 );
break;
case EN50221_MMI_ANSW:
STORE_MEMBER( &p_serialized->u.answ.psz_answ,
strlen(p_object->u.answ.psz_answ) + 1 );
break;
case EN50221_MMI_MENU:
case EN50221_MMI_LIST:
STORE_MEMBER( &p_serialized->u.menu.psz_title,
strlen(p_object->u.menu.psz_title) + 1 );
STORE_MEMBER( &p_serialized->u.menu.psz_subtitle,
strlen(p_object->u.menu.psz_subtitle) + 1 );
STORE_MEMBER( &p_serialized->u.menu.psz_bottom,
strlen(p_object->u.menu.psz_bottom) + 1 );
/* pointer alignment */
i = ((*pi_size + 7) / 8) * 8 - *pi_size;
*pi_size += i;
p_answer += i;
pp_tmp = (char **)p_answer;
STORE_MEMBER( &p_serialized->u.menu.ppsz_choices,
p_object->u.menu.i_choices * sizeof(char *) );
for ( i = 0; i < p_object->u.menu.i_choices; i++ )
{
STORE_MEMBER( &pp_tmp[i],
strlen(p_object->u.menu.ppsz_choices[i]) + 1 );
}
break;
default:
break;
}
return 0;
}
/*****************************************************************************
* en50221_UnserializeMMIObject :
*****************************************************************************/
static inline int en50221_UnserializeMMIObject( en50221_mmi_object_t *p_object,
ssize_t i_size )
{
int i, j;
#define CHECK_MEMBER(pp_member) \
if ( (ptrdiff_t)*pp_member >= i_size ) \
return -1; \
for ( i = 0; ((char *)p_object + (ptrdiff_t)*pp_member)[i] != '\0'; \
i++ ) \
if ( (ptrdiff_t)*pp_member + i >= i_size ) \
return -1; \
*pp_member += (ptrdiff_t)p_object;
switch ( p_object->i_object_type )
{
case EN50221_MMI_ENQ:
CHECK_MEMBER(&p_object->u.enq.psz_text);
break;
case EN50221_MMI_ANSW:
CHECK_MEMBER(&p_object->u.answ.psz_answ);
break;
case EN50221_MMI_MENU:
case EN50221_MMI_LIST:
CHECK_MEMBER(&p_object->u.menu.psz_title);
CHECK_MEMBER(&p_object->u.menu.psz_subtitle);
CHECK_MEMBER(&p_object->u.menu.psz_bottom);
if ( (ptrdiff_t)p_object->u.menu.ppsz_choices
+ p_object->u.menu.i_choices * sizeof(char *) >= i_size )
return -1;
p_object->u.menu.ppsz_choices = (char **)((char *)p_object
+ (ptrdiff_t)p_object->u.menu.ppsz_choices);
for ( j = 0; j < p_object->u.menu.i_choices; j++ )
{
CHECK_MEMBER(&p_object->u.menu.ppsz_choices[j]);
}
break;
default:
break;
}
return 0;
}