~ubuntu-branches/ubuntu/precise/me-tv/precise-proposed

« back to all changes in this revision

Viewing changes to src/libdvben50221/en50221_app_ca.h

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Kern
  • Date: 2008-07-23 14:03:56 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080723140356-m6ze7fbkydes42c7
Tags: 0.5.33-3
Fix xine-lib ffmpeg dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    en50221 encoder An implementation for libdvb
3
 
    an implementation for the en50221 transport layer
4
 
 
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)
8
 
 
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.
13
 
 
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.
18
 
 
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
22
 
*/
23
 
 
24
 
#ifndef __EN50221_APPLICATION_ca_H__
25
 
#define __EN50221_APPLICATION_ca_H__
26
 
 
27
 
#ifdef __cplusplus
28
 
extern "C" {
29
 
#endif
30
 
 
31
 
#include <stdlib.h>
32
 
#include <stdint.h>
33
 
#include <libdvben50221/en50221_app_utils.h>
34
 
#include <libucsi/mpeg/pmt_section.h>
35
 
#include <libucsi/dvb/descriptor.h>
36
 
 
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
43
 
 
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
48
 
 
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
54
 
 
55
 
 
56
 
#define EN50221_APP_CA_RESOURCEID MKRID(3,1,1)
57
 
 
58
 
/**
59
 
 * PMT reply structure.
60
 
 */
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));
70
 
 
71
 
/**
72
 
 * A stream within a pmt reply structure.
73
 
 */
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));
80
 
 
81
 
/**
82
 
 * Convenience iterator for the streams field of the en50221_app_pmt_reply structure.
83
 
 *
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.
87
 
 */
88
 
#define en50221_app_pmt_reply_streams_for_each(pmt, pos, size) \
89
 
    for ((pos) = en50221_app_pmt_reply_streams_first(pmt, size); \
90
 
         (pos); \
91
 
         (pos) = en50221_app_pmt_reply_streams_next(pmt, pos, size))
92
 
 
93
 
 
94
 
/**
95
 
 * Type definition for command - called when we receive a ca info response.
96
 
 *
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.
103
 
 */
104
 
typedef int (*en50221_app_ca_info_callback) (void *arg,
105
 
                                             uint8_t slot_id,
106
 
                                             uint16_t session_number,
107
 
                                             uint32_t ca_id_count,
108
 
                                             uint16_t * ca_ids);
109
 
 
110
 
/**
111
 
 * Type definition for pmt_reply - called when we receive a pmt_reply.
112
 
 *
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.
119
 
 */
120
 
typedef int (*en50221_app_ca_pmt_reply_callback) (void *arg,
121
 
                                                  uint8_t slot_id,
122
 
                                                  uint16_t session_number,
123
 
                                                  struct en50221_app_pmt_reply *reply,
124
 
                                                  uint32_t reply_size);
125
 
 
126
 
/**
127
 
 * Opaque type representing a ca resource.
128
 
 */
129
 
struct en50221_app_ca;
130
 
 
131
 
/**
132
 
 * Create an instance of the ca resource.
133
 
 *
134
 
 * @param funcs Send functions to use.
135
 
 * @return Instance, or NULL on failure.
136
 
 */
137
 
extern struct en50221_app_ca *en50221_app_ca_create(struct en50221_app_send_functions *funcs);
138
 
 
139
 
/**
140
 
 * Destroy an instance of the ca resource.
141
 
 *
142
 
 * @param ca Instance to destroy.
143
 
 */
144
 
extern void en50221_app_ca_destroy(struct en50221_app_ca *ca);
145
 
 
146
 
/**
147
 
 * Register the callback for when we receive a ca info.
148
 
 *
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.
152
 
 */
153
 
extern void en50221_app_ca_register_info_callback(struct en50221_app_ca *ca,
154
 
                                                  en50221_app_ca_info_callback callback,
155
 
                                                  void *arg);
156
 
 
157
 
/**
158
 
 * Register the callback for when we receive a pmt_reply.
159
 
 *
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.
163
 
 */
164
 
extern void en50221_app_ca_register_pmt_reply_callback(struct en50221_app_ca *ca,
165
 
                                                       en50221_app_ca_pmt_reply_callback callback,
166
 
                                                       void *arg);
167
 
 
168
 
/**
169
 
 * Send a ca_info_req to the CAM.
170
 
 *
171
 
 * @param ca ca resource instance.
172
 
 * @param session_number Session number to send it on.
173
 
 * @return 0 on success, -1 on failure.
174
 
 */
175
 
extern int en50221_app_ca_info_enq(struct en50221_app_ca *ca,
176
 
                                   uint16_t session_number);
177
 
 
178
 
/**
179
 
 * Send a ca_pmt structure to the CAM.
180
 
 *
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.
186
 
 */
187
 
extern int en50221_app_ca_pmt(struct en50221_app_ca *ca,
188
 
                              uint16_t session_number,
189
 
                              uint8_t * ca_pmt,
190
 
                              uint32_t ca_pmt_length);
191
 
 
192
 
/**
193
 
 * Transform a libucsi PMT into a binary structure for sending to a CAM.
194
 
 *
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.
203
 
 */
204
 
extern int en50221_ca_format_pmt(struct mpeg_pmt_section *pmt,
205
 
                                 uint8_t * data,
206
 
                                 uint32_t data_length,
207
 
                                 int move_ca_descriptors,
208
 
                                 uint8_t ca_pmt_list_management,
209
 
                                 uint8_t ca_pmt_cmd_id);
210
 
 
211
 
/**
212
 
 * Pass data received for this resource into it for parsing.
213
 
 *
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.
221
 
 */
222
 
extern int en50221_app_ca_message(struct en50221_app_ca *ca,
223
 
                                  uint8_t slot_id,
224
 
                                  uint16_t session_number,
225
 
                                  uint32_t resource_id,
226
 
                                  uint8_t *data,
227
 
                                  uint32_t data_length);
228
 
 
229
 
 
230
 
 
231
 
 
232
 
static inline struct en50221_app_pmt_stream *
233
 
        en50221_app_pmt_reply_streams_first(struct en50221_app_pmt_reply *reply,
234
 
                                            uint32_t reply_size)
235
 
{
236
 
        uint32_t pos = sizeof(struct en50221_app_pmt_reply);
237
 
 
238
 
        if (pos >= reply_size)
239
 
                return NULL;
240
 
 
241
 
        return (struct en50221_app_pmt_stream *) ((uint8_t *) reply + pos);
242
 
}
243
 
 
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,
247
 
                                           uint32_t reply_size)
248
 
{
249
 
        uint8_t *end = (uint8_t *) reply + reply_size;
250
 
        uint8_t *next =
251
 
                (uint8_t *) pos +
252
 
                sizeof(struct en50221_app_pmt_stream);
253
 
 
254
 
        if (next >= end)
255
 
                return NULL;
256
 
 
257
 
        return (struct en50221_app_pmt_stream *) next;
258
 
}
259
 
 
260
 
#ifdef __cplusplus
261
 
}
262
 
#endif
263
 
 
264
 
#endif