aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libucsi/dvb/int_section.h
blob: 932c0e8d7e32f684c611d137a17610989de2e35f (plain)
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
/*
 * section and descriptor parser
 *
 * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
 * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
 * Copyright (C) 2005 Patrick Boettcher (pb@linuxtv.org)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
#ifndef _UCSI_DVB_INT_SECTION_H
#define _UCSI_DVB_INT_SECTION_H

#ifdef __cplusplus
extern "C"
{
#endif

#include <libucsi/section.h>

/**
 * dvb_int_section structure - IP/MAC notification section.
 */
struct dvb_int_section {
	struct section_ext head;

  EBIT2(uint32_t platform_id				:24;  ,
	uint32_t processing_order			: 8;  );
  EBIT2(uint16_t reserved2				: 4;  ,
	uint16_t platform_descriptors_length		:12;  );
	/* struct descriptor platform_descriptors[] */
	/* struct dvb_int_target target_loop[] */
} __ucsi_packed;

/**
 * An entry in the target_loop field of a dvb_int_section.
 */
struct dvb_int_target {
  EBIT2(uint16_t reserved3			: 4;  ,
	uint16_t target_descriptors_length	:12;  );
	/* struct descriptor target_descriptors[] */
	/* struct dvb_int_operational_loop operational_loop */
} __ucsi_packed;

/**
 * The operational_loop field in a dvb_int_target.
 */
struct dvb_int_operational_loop {
  EBIT2(uint16_t reserved4				: 4;  ,
	uint16_t operational_descriptors_length		:12;  );
	/* struct descriptor operational_descriptors[] */
} __ucsi_packed;

/**
 * Process a dvb_int_section.
 *
 * @param section Generic section_ext pointer.
 * @return dvb_int_section pointer, or NULL on error.
 */
extern struct dvb_int_section * dvb_int_section_codec(struct section_ext *section);

/**
 * Accessor for the action_type field of an INT.
 *
 * @param intp INT pointer.
 * @return The action_type.
 */
static inline uint8_t dvb_int_section_action_type(struct dvb_int_section *intp)
{
	return intp->head.table_id_ext >> 8;
}

/**
 * Accessor for the platform_id_hash field of an INT.
 *
 * @param intp INT pointer.
 * @return The platform_id_hash.
 */
static inline uint8_t dvb_int_section_platform_id_hash(struct dvb_int_section *intp)
{
	return intp->head.table_id_ext & 0xff;
}

/**
 * Iterator for platform_descriptors field in a dvb_int_section.
 *
 * @param intp dvb_int_section pointer.
 * @param pos Variable holding a pointer to the current descriptor.
 */
#define dvb_int_section_platform_descriptors_for_each(intp, pos) \
	for ((pos) = dvb_int_section_platform_descriptors_first(intp); \
	     (pos); \
	     (pos) = dvb_int_section_platform_descriptors_next(intp, pos))

/**
 * Iterator for the target_loop field in a dvb_int_section.
 *
 * @param intp dvb_int_section pointer.
 * @param pos Variable holding a pointer to the current dvb_int_target.
 */
#define dvb_int_section_target_loop_for_each(intp,pos) \
	for ((pos) = dvb_int_section_target_loop_first(intp); \
	     (pos); \
	     (pos) = dvb_int_section_target_loop_next(intp, pos))

/**
 * Iterator for the target_descriptors field in a dvb_int_target.
 *
 * @param target dvb_int_target pointer.
 * @param pos Variable holding a pointer to the current descriptor.
 */
#define dvb_int_target_target_descriptors_for_each(target, pos) \
	for ((pos) = dvb_int_target_target_descriptors_first(target); \
	     (pos); \
	     (pos) = dvb_int_target_target_descriptors_next(target, pos))

/**
 * Accessor for the operational_loop field of a dvb_int_target.
 *
 * @param target dvb_int_target pointer.
 * @return Pointer to a dvb_int_operational_loop.
 */
static inline struct dvb_int_operational_loop *
	dvb_int_target_operational_loop(struct dvb_int_target *target)
{
	return (struct dvb_int_operational_loop *)
		((uint8_t *) target + sizeof(struct dvb_int_target) + target->target_descriptors_length);
}

/**
 * Iterator for the operational_descriptors field in a dvb_int_operational_loop.
 *
 * @param oploop dvb_int_operational_loop pointer.
 * @param pos Variable holding a pointer to the current descriptor.
 */
#define dvb_int_operational_loop_operational_descriptors_for_each(oploop, pos) \
	for ((pos) = dvb_int_operational_loop_operational_descriptors_first(oploop); \
	     (pos); \
	     (pos) = dvb_int_operational_loop_operational_descriptors_next(oploop, pos))





/******************************** PRIVATE CODE ********************************/
static inline struct descriptor *
	dvb_int_section_platform_descriptors_first(struct dvb_int_section *in)
{
	if (in->platform_descriptors_length == 0)
		return NULL;

	return (struct descriptor *)
		((uint8_t *) in + sizeof(struct dvb_int_section));
}

static inline struct descriptor *
	dvb_int_section_platform_descriptors_next(struct dvb_int_section *in,
		struct descriptor* pos)
{
	return next_descriptor((uint8_t*) in + sizeof(struct dvb_int_section),
		in->platform_descriptors_length,
		pos);
}

static inline struct dvb_int_target *
	dvb_int_section_target_loop_first(struct dvb_int_section *in)
{
	if (sizeof(struct dvb_int_section) + in->platform_descriptors_length >= (uint32_t) section_ext_length((struct section_ext *) in))
		return NULL;

	return (struct dvb_int_target *)
		((uint8_t *) in + sizeof(struct dvb_int_section) + in->platform_descriptors_length);
}

static inline struct dvb_int_target *
	dvb_int_section_target_loop_next(struct dvb_int_section *in,
			struct dvb_int_target *pos)
{
	struct dvb_int_operational_loop *ol = dvb_int_target_operational_loop(pos);
	struct dvb_int_target *next =
		(struct dvb_int_target *) ( (uint8_t *) pos +
			sizeof(struct dvb_int_target) + pos->target_descriptors_length +
			sizeof(struct dvb_int_operational_loop) + ol->operational_descriptors_length);
	struct dvb_int_target *end =
		(struct dvb_int_target *) ((uint8_t *) in + section_ext_length((struct section_ext *) in) );

	if (next >= end)
		return 0;
	return next;
}

static inline struct descriptor *
	dvb_int_target_target_descriptors_first(struct dvb_int_target *tl)
{
	if (tl->target_descriptors_length == 0)
		return NULL;

	return (struct descriptor *)
		((uint8_t *) tl + sizeof(struct dvb_int_target));
}

static inline struct descriptor *
	dvb_int_target_target_descriptors_next(struct dvb_int_target *tl,
		struct descriptor* pos)
{
	return next_descriptor((uint8_t*) tl + sizeof(struct dvb_int_target),
		tl->target_descriptors_length,
		pos);
}

static inline struct descriptor *
	dvb_int_operational_loop_operational_descriptors_first(struct dvb_int_operational_loop *ol)
{
	if (ol->operational_descriptors_length == 0)
		return NULL;

	return (struct descriptor *)
		((uint8_t *) ol + sizeof(struct dvb_int_operational_loop));
}

static inline struct descriptor *
	dvb_int_operational_loop_operational_descriptors_next(struct dvb_int_operational_loop *ol,
		struct descriptor* pos)
{
	return next_descriptor((uint8_t*) ol + sizeof(struct dvb_int_operational_loop),
		ol->operational_descriptors_length,
		pos);
}

#ifdef __cplusplus
}
#endif

#endif