2
en50221 encoder An implementation for libdvb
3
an implementation for the en50221 transport layer
5
Copyright (C) 2004, 2005 Manu Abraham <abraham.manu@gmail.com>
6
Copyright (C) 2005 Julian Scheel (julian at jusst dot de)
7
Copyright (C) 2006 Andrew de Quincey (adq_dvb@lidskialf.net)
9
This library is free software; you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as
11
published by the Free Software Foundation; either version 2.1 of
12
the License, or (at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#ifndef __EN50221_APPLICATION_ca_H__
25
#define __EN50221_APPLICATION_ca_H__
33
#include <libdvben50221/en50221_app_utils.h>
34
#include <libucsi/mpeg/pmt_section.h>
35
#include <libucsi/dvb/descriptor.h>
37
#define CA_LIST_MANAGEMENT_MORE 0x00
38
#define CA_LIST_MANAGEMENT_FIRST 0x01
39
#define CA_LIST_MANAGEMENT_LAST 0x02
40
#define CA_LIST_MANAGEMENT_ONLY 0x03
41
#define CA_LIST_MANAGEMENT_ADD 0x04
42
#define CA_LIST_MANAGEMENT_UPDATE 0x05
44
#define CA_PMT_CMD_ID_OK_DESCRAMBLING 0x01
45
#define CA_PMT_CMD_ID_OK_MMI 0x02
46
#define CA_PMT_CMD_ID_QUERY 0x03
47
#define CA_PMT_CMD_ID_NOT_SELECTED 0x04
49
#define CA_ENABLE_DESCRAMBLING_POSSIBLE 0x01
50
#define CA_ENABLE_DESCRAMBLING_POSSIBLE_PURCHASE 0x02
51
#define CA_ENABLE_DESCRAMBLING_POSSIBLE_TECHNICAL 0x03
52
#define CA_ENABLE_DESCRAMBLING_NOT_POSSIBLE_NO_ENTITLEMENT 0x71
53
#define CA_ENABLE_DESCRAMBLING_NOT_POSSIBLE_TECHNICAL 0x73
56
#define EN50221_APP_CA_RESOURCEID MKRID(3,1,1)
59
* PMT reply structure.
61
struct en50221_app_pmt_reply {
62
uint16_t program_number;
63
EBIT3(uint8_t reserved_1 : 2;,
64
uint8_t version_number : 5;,
65
uint8_t current_next_indicator : 1;);
66
EBIT2(uint8_t CA_enable_flag : 1;,
67
uint8_t CA_enable : 7;);
68
/* struct en50221_app_pmt_stream streams[] */
69
} __attribute__ ((packed));
72
* A stream within a pmt reply structure.
74
struct en50221_app_pmt_stream {
75
EBIT2(uint16_t reserved_1 : 3;,
76
uint16_t es_pid :13;);
77
EBIT2(uint8_t CA_enable_flag : 1;,
78
uint8_t CA_enable : 7;);
79
} __attribute__ ((packed));
82
* Convenience iterator for the streams field of the en50221_app_pmt_reply structure.
84
* @param pmt Pointer to the en50221_app_pmt_reply structure.
85
* @param pos Variable holding a pointer to the current en50221_app_pmt_stream.
86
* @param size Total size of the PMT reply.
88
#define en50221_app_pmt_reply_streams_for_each(pmt, pos, size) \
89
for ((pos) = en50221_app_pmt_reply_streams_first(pmt, size); \
91
(pos) = en50221_app_pmt_reply_streams_next(pmt, pos, size))
95
* Type definition for command - called when we receive a ca info response.
97
* @param arg Private argument.
98
* @param slot_id Slot id concerned.
99
* @param session_number Session number concerned.
100
* @param ca_id_count Number of ca_system_ids.
101
* @param ca_ids Pointer to list of ca_system_ids.
102
* @return 0 on success, -1 on failure.
104
typedef int (*en50221_app_ca_info_callback) (void *arg,
106
uint16_t session_number,
107
uint32_t ca_id_count,
111
* Type definition for pmt_reply - called when we receive a pmt_reply.
113
* @param arg Private argument.
114
* @param slot_id Slot id concerned.
115
* @param session_number Session number concerned.
116
* @param reply Pointer to a struct en50221_app_pmt_reply.
117
* @param reply_size Total size of the struct en50221_app_pmt_reply in bytes.
118
* @return 0 on success, -1 on failure.
120
typedef int (*en50221_app_ca_pmt_reply_callback) (void *arg,
122
uint16_t session_number,
123
struct en50221_app_pmt_reply *reply,
124
uint32_t reply_size);
127
* Opaque type representing a ca resource.
129
struct en50221_app_ca;
132
* Create an instance of the ca resource.
134
* @param funcs Send functions to use.
135
* @return Instance, or NULL on failure.
137
extern struct en50221_app_ca *en50221_app_ca_create(struct en50221_app_send_functions *funcs);
140
* Destroy an instance of the ca resource.
142
* @param ca Instance to destroy.
144
extern void en50221_app_ca_destroy(struct en50221_app_ca *ca);
147
* Register the callback for when we receive a ca info.
149
* @param ca ca resource instance.
150
* @param callback The callback. Set to NULL to remove the callback completely.
151
* @param arg Private data passed as arg0 of the callback.
153
extern void en50221_app_ca_register_info_callback(struct en50221_app_ca *ca,
154
en50221_app_ca_info_callback callback,
158
* Register the callback for when we receive a pmt_reply.
160
* @param ca ca resource instance.
161
* @param callback The callback. Set to NULL to remove the callback completely.
162
* @param arg Private data passed as arg0 of the callback.
164
extern void en50221_app_ca_register_pmt_reply_callback(struct en50221_app_ca *ca,
165
en50221_app_ca_pmt_reply_callback callback,
169
* Send a ca_info_req to the CAM.
171
* @param ca ca resource instance.
172
* @param session_number Session number to send it on.
173
* @return 0 on success, -1 on failure.
175
extern int en50221_app_ca_info_enq(struct en50221_app_ca *ca,
176
uint16_t session_number);
179
* Send a ca_pmt structure to the CAM.
181
* @param ca ca resource instance.
182
* @param session_number Session number to send it on.
183
* @param ca_pmt A ca_pmt structure formatted with the en50221_ca_format_pmt() function.
184
* @param ca_pmt_length Length of ca_pmt structure in bytes.
185
* @return 0 on success, -1 on failure.
187
extern int en50221_app_ca_pmt(struct en50221_app_ca *ca,
188
uint16_t session_number,
190
uint32_t ca_pmt_length);
193
* Transform a libucsi PMT into a binary structure for sending to a CAM.
195
* @param pmt The source PMT structure.
196
* @param data Pointer to data buffer to write it to.
197
* @param data_length Number of bytes available in data buffer.
198
* @param move_ca_descriptors If non-zero, will attempt to move CA descriptors
199
* in order to reduce the size of the formatted CAPMT.
200
* @param ca_pmt_list_management One of the CA_LIST_MANAGEMENT_*.
201
* @param ca_pmt_cmd_id One of the CA_PMT_CMD_ID_*.
202
* @return Number of bytes used, or -1 on error.
204
extern int en50221_ca_format_pmt(struct mpeg_pmt_section *pmt,
206
uint32_t data_length,
207
int move_ca_descriptors,
208
uint8_t ca_pmt_list_management,
209
uint8_t ca_pmt_cmd_id);
212
* Pass data received for this resource into it for parsing.
214
* @param ca CA instance.
215
* @param slot_id Slot ID concerned.
216
* @param session_number Session number concerned.
217
* @param resource_id Resource ID concerned.
218
* @param data The data.
219
* @param data_length Length of data in bytes.
220
* @return 0 on success, -1 on failure.
222
extern int en50221_app_ca_message(struct en50221_app_ca *ca,
224
uint16_t session_number,
225
uint32_t resource_id,
227
uint32_t data_length);
232
static inline struct en50221_app_pmt_stream *
233
en50221_app_pmt_reply_streams_first(struct en50221_app_pmt_reply *reply,
236
uint32_t pos = sizeof(struct en50221_app_pmt_reply);
238
if (pos >= reply_size)
241
return (struct en50221_app_pmt_stream *) ((uint8_t *) reply + pos);
244
static inline struct en50221_app_pmt_stream *
245
en50221_app_pmt_reply_streams_next(struct en50221_app_pmt_reply *reply,
246
struct en50221_app_pmt_stream *pos,
249
uint8_t *end = (uint8_t *) reply + reply_size;
252
sizeof(struct en50221_app_pmt_stream);
257
return (struct en50221_app_pmt_stream *) next;