- Timestamp:
- 07/24/19 21:36:09 (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/README.dvbapi_protocol
r11511 r11533 109 109 the EN 50221 PDF (european standard). 110 110 111 Please note that OSCam is expecting the own descriptor injected in the data. Look into get_demux_options() function 112 for details. 111 ------------------------------------------------------------------------------- 112 113 Please note that OSCam is expecting a number of private descriptors injected 114 into the CA PMT data. They shall be located inside the program info loop. All 115 supported descriptors follow the structure defined in 2.6 of Rec. ITU H.222.0 116 and they are the following: 117 118 --------------------------------------------------------------------- 119 | descriptor_tag | Identification | Usage | 120 --------------------------------------------------------------------- 121 | 0x81 | enigma_namespace_descriptor | optional | 122 | 0x82 | demux_ca_mask_device_descriptor | deprecated | 123 | 0x83 | adapter_device_descriptor | mandatory | 124 | 0x84 | pmt_pid_descriptor | mandatory | 125 | 0x85 | service_type_mask_descriptor | optional | 126 | 0x86 | demux_device_descriptor | mandatory | 127 | 0x87 | ca_device_descriptor | mandatory | 128 --------------------------------------------------------------------- 129 130 Descriptors marked as "mandatory" shall be present in the CA PMT message, in 131 order OSCam to get all necessary information for the specified program. Below 132 is a detailed description for each of the supported descriptors with its 133 structure and usage. 134 135 ------------------------------------------------------------------------------- 136 137 1. Enigma namespace descriptor 138 139 Provides additional information for the program specified, such as enigma 140 namespace (orbital position, frequency and polarization), transport stream id 141 and original network id. Although its presense in the CA PMT is optional, it 142 is advised to be included as OSCam utilizes these information in many aspects. 143 144 --------------------------------------------------------------------- 145 | Syntax | No. of bits | Mnemonic | 146 --------------------------------------------------------------------- 147 | enigma_namespace_descriptor(){ | | | 148 | descriptor_tag | 8 | uimsbf | 149 | descriptor_length | 8 | uimsbf | 150 | enigma_namespace | 32 | uimsbf | 151 | transport_stream_id | 16 | uimsbf | 152 | original_network_id | 16 | uimsbf | 153 | } | | | 154 --------------------------------------------------------------------- 155 156 decriptor_tag - The tag of the descriptor is equal to 0x81. 157 158 descriptor_length - The length of the descriptor is equal to 0x08. 159 160 ens - This is the enigma namespace as defined in OpenPLi, openATV and other 161 open enigma2 images. An example implementation can be found at: 162 https://github.com/OpenPLi/enigma2/blob/develop/lib/dvb/frontend.cpp#L476 163 164 transport_stream_id – The transport stream id as defined in various DVB SI 165 tables. 166 167 original_network_id - The original network id as defined in various DVB SI 168 tables. 169 170 ------------------------------------------------------------------------------- 171 172 2. Demux and ca mask device descriptor 173 174 It was used to provide information about the demux device as well as the ca 175 device(s) carrying the specified program. It was created for the DM7025 set top 176 box and it is now considered deprecated. Many hosts use this descriptor in a 177 different way (carrying different information) than it was originaly designed 178 leading to confusion. OSCam will continue to support this descriptor as some 179 legacy hosts still use it. For newer hosts, the adapter_device_descriptor (tag 180 0x83), the demux_device_descriptor (tag 0x86) and the ca_device_descriptor (tag 181 0x87) shall be used for sending the necessary data to OSCam. 182 183 --------------------------------------------------------------------- 184 | Syntax | No. of bits | Mnemonic | 185 --------------------------------------------------------------------- 186 | demux_ca_mask_device_descriptor(){ | | | 187 | descriptor_tag | 8 | uimsbf | 188 | descriptor_length | 8 | uimsbf | 189 | ca_mask | 8 | uimsbf | 190 | demux_device | 8 | uimsbf | 191 | } | | | 192 --------------------------------------------------------------------- 193 194 decriptor_tag - The tag of the descriptor is equal to 0x82. 195 196 descriptor_length - The length of the descriptor is equal to 0x02. 197 198 ca_mask - It is a bit mask of the ca device(s) carrying the specified program. 199 Bit 0 corresonds to ca0, bit 1 corresponds to ca1 and so on. 200 201 demux_device - The demux device that carries the specified program. It is 202 limited to values between 0x00 and 0x08 in older enigma2 images. 203 204 ------------------------------------------------------------------------------- 205 206 3. Adapter device descriptor 207 208 Provides information about the adapter device carrying the specified program. 209 210 --------------------------------------------------------------------- 211 | Syntax | No. of bits | Mnemonic | 212 --------------------------------------------------------------------- 213 | adapter_device_descriptor(){ | | | 214 | descriptor_tag | 8 | uimsbf | 215 | descriptor_length | 8 | uimsbf | 216 | adapter_device | 8 | uimsbf | 217 | } | | | 218 --------------------------------------------------------------------- 219 220 decriptor_tag - The tag of the descriptor is equal to 0x83. 221 222 descriptor_length - The length of the descriptor is equal to 0x01. 223 224 adapter_device - The adapter device that carries the specified program. It can 225 take values from 0x00 to 0xFF, thus a maximum number of different 256 adapters 226 are supported. 227 228 ------------------------------------------------------------------------------- 229 230 4. PMT pid descriptor 231 232 Provides information about the PMT pid of the specified program. 233 234 --------------------------------------------------------------------- 235 | Syntax | No. of bits | Mnemonic | 236 --------------------------------------------------------------------- 237 | pmt_pid_descriptor(){ | | | 238 | descriptor_tag | 8 | uimsbf | 239 | descriptor_length | 8 | uimsbf | 240 | pmt_pid | 16 | uimsbf | 241 | } | | | 242 --------------------------------------------------------------------- 243 244 decriptor_tag - The tag of the descriptor is equal to 0x84. 245 246 descriptor_length - The length of the descriptor is equal to 0x02. 247 248 pmt_pid - The pid that carries the PMT table of the specified program. 249 250 ------------------------------------------------------------------------------- 251 252 5. Service type mask descriptor 253 254 It provides information about the type (live tv, recording, streaming service, 255 or any combination) of the program specified. It's currently not unitilized in 256 OSCam and its usage in considered optional. 257 258 --------------------------------------------------------------------- 259 | Syntax | No. of bits | Mnemonic | 260 --------------------------------------------------------------------- 261 | service_type_mask_descriptor(){ | | | 262 | descriptor_tag | 8 | uimsbf | 263 | descriptor_length | 8 | uimsbf | 264 | service_type_mask | 32 | uimsbf | 265 | } | | | 266 --------------------------------------------------------------------- 267 268 decriptor_tag - The tag of the descriptor is equal to 0x85. 269 270 descriptor_length - The length of the descriptor is equal to 0x04. 271 272 service_type_mask - This is a bit mask of the different service types enabled 273 for the specified program. Service type values are defined in enigma2 and can 274 be found at https://github.com/OpenPLi/enigma2/blob/develop/lib/dvb/pmt.h#L135 275 276 ------------------------------------------------------------------------------- 277 278 6. Demux device descriptor 279 280 It is used to provide information about the demux device carrying the specified 281 program. It is a replacement to the deprecated demux_ca_mask_device_descriptor 282 (tag 0x82), as it supports up to 256 different demux devices. 283 284 --------------------------------------------------------------------- 285 | Syntax | No. of bits | Mnemonic | 286 --------------------------------------------------------------------- 287 | demux_device_descriptor(){ | | | 288 | descriptor_tag | 8 | uimsbf | 289 | descriptor_length | 8 | uimsbf | 290 | demux_device | 8 | uimsbf | 291 | } | | | 292 --------------------------------------------------------------------- 293 294 decriptor_tag - The tag of the descriptor is equal to 0x86. 295 296 descriptor_length - The length of the descriptor is equal to 0x01. 297 298 demux_device - The demux device that carries the specified program. Its value 299 can be between 0x00 and 0xFF. 300 301 ------------------------------------------------------------------------------- 302 303 7. Ca device descriptor 304 305 This descriptor provides OSCam with information about the ca device carrying 306 the specified program. It is created as a replacement to the deprecated 307 demux_ca_mask_device_descriptor (tag 0x82). It has the following syntax: 308 309 --------------------------------------------------------------------- 310 | Syntax | No. of bits | Mnemonic | 311 --------------------------------------------------------------------- 312 | ca_device_descriptor(){ | | | 313 | descriptor_tag | 8 | uimsbf | 314 | descriptor_length | 8 | uimsbf | 315 | ca_device | 8 | uimsbf | 316 | } | | | 317 --------------------------------------------------------------------- 318 319 decriptor_tag - The tag of the descriptor is equal to 0x87. 320 321 descriptor_length - The length of the descriptor is equal to 0x01. 322 323 ca_device - The ca device that carries the specified program. Its value can be 324 between 0x00 and 0xFF (256 different ca devices supported). 325 326 ------------------------------------------------------------------------------- 113 327 114 328 After OSCam parses the PMT data, it starts filtering ECM PIDs. It sends the following request to the client: -
trunk/module-dvbapi-azbox.c
r11509 r11533 173 173 memcpy(dest + 7, msg.buf + 12, msg.buf_len - 12 - 4); 174 174 175 dvbapi_parse_capmt(dest, 7 + msg.buf_len - 12 - 4, -1, NULL, 0, 0 , 0, 0);175 dvbapi_parse_capmt(dest, 7 + msg.buf_len - 12 - 4, -1, NULL, 0, 0); 176 176 NULLFREE(dest); 177 177 -
trunk/module-dvbapi-mca.c
r11509 r11533 454 454 if(new_len < msg.buf_len - 2) 455 455 { cs_log_dump_dbg(D_DVBAPI, msg.buf + 2, new_len, "capmt (duplicates removed):"); } 456 int demux_id = dvbapi_parse_capmt(msg.buf + 2, new_len, -1, NULL, 0, 0 , 0, 0);456 int demux_id = dvbapi_parse_capmt(msg.buf + 2, new_len, -1, NULL, 0, 0); 457 457 458 458 uint8_t mask[12]; -
trunk/module-dvbapi.c
r11532 r11533 343 343 #define TO_FROM 1 344 344 345 #if defined(CARDREADER_STAPI) || defined(CARDREADER_STAPI5) 346 //fix from stapi5 patch 347 int32_t pausecam = 0, disable_pmt_files = 0, pmt_stopmarking = 1; 348 #else 349 int32_t pausecam = 0, disable_pmt_files = 0, pmt_stopmarking = 0; 350 #endif 345 int32_t pausecam = 0, disable_pmt_files = 0; 351 346 352 347 DEMUXTYPE demux[MAX_DEMUX]; … … 3705 3700 demux[extra_demux_id].ca_mask = demux[demux_id].ca_mask; 3706 3701 demux[extra_demux_id].socket_fd = demux[demux_id].socket_fd; 3707 demux[extra_demux_id].stop descramble = 0;3702 demux[extra_demux_id].stop_descrambling = false; 3708 3703 demux[extra_demux_id].rdr = NULL; 3709 3704 demux[extra_demux_id].curindex = -1; … … 3761 3756 3762 3757 demux[extra_demux_id].program_number = 0; 3763 demux[extra_demux_id].stop descramble = 1;3758 demux[extra_demux_id].stop_descrambling = true; 3764 3759 } 3765 3760 … … 3772 3767 } 3773 3768 3774 static void dvbapi_parse_ca_descriptor(int32_t demux_id, uint8_t *buffer, uint8_t descriptor_length)3769 static void dvbapi_parse_ca_descriptor(int32_t demux_id, const uint8_t *buffer, uint8_t descriptor_length) 3775 3770 { 3776 3771 uint16_t i, ca_system_id, ca_pid; … … 3830 3825 } 3831 3826 3832 static void dvbapi_parse_pmt_descriptors(int32_t demux_id, uint8_t *buffer, uint16_t length, uint8_t *type) 3833 { 3834 // int32_t ca_pmt_cmd_id = buffer[i + 5]; 3835 uint8_t descriptor_tag = buffer[0], descriptor_length = 0; 3836 uint8_t skip_border = cfg.dvbapi_boxtype == BOXTYPE_SAMYGO ? 0x05 : 0x02; // skip input values <0x05 on samygo 3827 static void dvbapi_parse_pmt_descriptors(int32_t demux_id, const uint8_t *buffer, uint16_t length, uint8_t *type) 3828 { 3837 3829 uint16_t i, j; 3838 3839 if(length < 1) 3840 { 3841 return; 3842 } 3843 3844 // skip descriptors with tag 0x00 and 0x01, 3845 // or even greater for samygo (not sure why we do this...) 3846 if((descriptor_tag < skip_border) && length > 0) 3847 { 3848 buffer++; 3849 length--; 3850 } 3830 uint8_t descriptor_tag, descriptor_length; 3851 3831 3852 3832 for(i = 0; i + 1 < length; i += 2 + descriptor_length) … … 3924 3904 } 3925 3905 3926 case 0x81: 3927 { 3928 if(descriptor_length == 8) // private descriptor of length 8, assume enigma/tvh 3929 { 3930 demux[demux_id].ens = b2i(4, buffer + i + 2); 3931 demux[demux_id].tsid = b2i(2, buffer + i + 6); 3932 demux[demux_id].onid = b2i(2, buffer + i + 8); 3933 cs_log_dbg(D_DVBAPI, "Demuxer %d assuming enigma private descriptor (namespace: %08X tsid: %04X onid: %04X)", 3934 demux_id, demux[demux_id].ens, demux[demux_id].tsid, demux[demux_id].onid); 3935 } 3936 else if(descriptor_length != 0) // AC-3 descriptor (ATSC) 3937 { 3938 *type = STREAM_AUDIO; 3939 cs_log_dbg(D_DVBAPI, "Demuxer %d assuming AC-3 descriptor (ATSC)", demux_id); 3940 } 3906 case 0x81: // AC-3 descriptor (ATSC) 3907 { 3908 *type = STREAM_AUDIO; 3909 cs_log_dbg(D_DVBAPI, "Demuxer %d assuming AC-3 descriptor (ATSC)", demux_id); 3941 3910 break; 3942 3911 } … … 3945 3914 break; 3946 3915 } 3947 }3948 3949 // Apply mapping:3950 if(dvbapi_priority)3951 {3952 dvbapi_priority_read_entry_map(demux_id);3953 3916 } 3954 3917 } … … 4061 4024 } 4062 4025 4063 static void get_demux_options(int32_t demux_id, uint8_t *buffer, uint32_t *ca_mask, 4064 uint16_t *demux_index, uint16_t *adapter_index, uint16_t *pmtpid) 4065 { 4066 *ca_mask = 0x01; 4067 *demux_index = 0x00; 4068 *adapter_index = 0x00; 4069 *pmtpid = 0x00; 4026 static void dvbapi_parse_pmt_program_info(int32_t demux_id, const uint8_t *buffer, uint16_t length, uint8_t *ca_pmt_cmd_id) 4027 { 4028 uint16_t i, offset = 0; 4029 uint8_t descriptor_tag, descriptor_length; 4030 4031 if(ca_pmt_cmd_id != NULL) // We are on CA PMT parsing 4032 { 4033 *ca_pmt_cmd_id = buffer[0]; 4034 offset = 1; 4035 } 4036 4037 for(i = offset; i + 1 < length; i += 2 + descriptor_length) 4038 { 4039 descriptor_tag = buffer[i]; 4040 descriptor_length = buffer[i + 1]; 4041 4042 if(descriptor_tag == 0x09) // We only care about CA descriptors at program level 4043 { 4044 dvbapi_parse_ca_descriptor(demux_id, buffer + i + 2, descriptor_length); 4045 } 4046 } 4047 } 4048 4049 static void dvbapi_parse_pmt_es_info(int32_t demux_id, const uint8_t *buffer, uint16_t length, uint8_t *ca_pmt_cmd_id, uint16_t *video_pid) 4050 { 4051 uint16_t i, elementary_pid, es_info_length, offset = 0; 4052 uint8_t stream_type, type; 4053 4054 for(i = 0; i + 4 < length; i += 5 + es_info_length) 4055 { 4056 if(demux[demux_id].STREAMpidcount >= MAX_STREAM_PIDS) 4057 { 4058 cs_log("Demuxer %d reached maximum number of elementary streams", demux_id); 4059 break; 4060 } 4061 4062 type = STREAM_UNDEFINED; 4063 stream_type = buffer[i]; 4064 elementary_pid = b2i(2, buffer + i + 1) & 0x1FFF; 4065 es_info_length = b2i(2, buffer + i + 3) & 0x0FFF; 4066 4067 cs_log_dbg(D_DVBAPI,"Demuxer %d found %s stream (type: %02X pid: %04X)", 4068 demux_id, get_stream_type_txt(stream_type), stream_type, elementary_pid); 4069 4070 if(es_info_length != 0 && es_info_length < length) 4071 { 4072 // We are on CA PMT parsing 4073 // Only enigma2 and Spark follow the CA PMT specification ("ca_pmt_cmd_id" 4074 // shall be present in the ES info loop), so we need to check for the box type. 4075 if(ca_pmt_cmd_id != NULL && cfg.dvbapi_boxtype == BOXTYPE_DREAMBOX) 4076 { 4077 *ca_pmt_cmd_id = buffer[i + 5]; // It should be identical for all ES and the same as in program info 4078 offset = 1; 4079 } 4080 4081 // Parse descriptors at ES level 4082 dvbapi_parse_pmt_descriptors(demux_id, buffer + i + 5 + offset, es_info_length, &type); 4083 } 4084 4085 // Get basic stream type (video, audio, subtitle) for each ES pid 4086 switch(stream_type) 4087 { 4088 case 0x01: 4089 case 0x02: 4090 case 0x10: 4091 case 0x1B: 4092 case 0x20: 4093 case 0x24: 4094 case 0x25: 4095 case 0x42: 4096 case 0xD1: 4097 case 0xEA: 4098 if(*video_pid == 0) 4099 { 4100 *video_pid = elementary_pid; 4101 } 4102 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = STREAM_VIDEO; 4103 break; 4104 4105 case 0x03: 4106 case 0x04: 4107 case 0x0F: 4108 case 0x11: 4109 case 0x1C: 4110 case 0x2D: 4111 case 0x2E: 4112 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = STREAM_AUDIO; 4113 break; 4114 4115 case 0x06: 4116 case 0x81: 4117 case 0x87: 4118 // Set the type based on the descriptors for these stream types 4119 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = type; 4120 break; 4121 4122 default: 4123 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = STREAM_UNDEFINED; 4124 break; 4125 } 4126 4127 demux[demux_id].STREAMpids[demux[demux_id].STREAMpidcount] = elementary_pid; 4128 demux[demux_id].STREAMpidcount++; 4129 } 4130 } 4131 4132 static void dvbapi_parse_pmt_info(int32_t demux_id, const uint8_t *buffer, uint16_t length, uint8_t *ca_pmt_cmd_id) 4133 { 4134 uint16_t i, program_info_length, video_pid = 0; 4135 4136 // Cleanout demuxer from possible stale info 4137 // (reset ECM pids and streams) 4138 if(demux[demux_id].running == false) 4139 { 4140 demux[demux_id].ECMpidcount = 0; 4141 } 4142 4143 for(i = 0; i < demux[demux_id].ECMpidcount; i++) 4144 { 4145 demux[demux_id].ECMpids[i].streams = 0; 4146 } 4147 4148 demux[demux_id].STREAMpidcount = 0; 4149 4150 // Parse program info 4151 // In case of CA PMT, read the ca_pmt_cmd_id as well 4152 program_info_length = b2i(2, buffer) & 0x0FFF; 4153 if(program_info_length != 0 && program_info_length < length) 4154 { 4155 dvbapi_parse_pmt_program_info(demux_id, buffer + 2, program_info_length, ca_pmt_cmd_id); 4156 } 4157 4158 // Parse elementary stream info 4159 // In case of CA PMT, read the ca_pmt_cmd_id for each stream as well 4160 dvbapi_parse_pmt_es_info(demux_id, buffer + 2 + program_info_length, length - 2 - program_info_length, ca_pmt_cmd_id, &video_pid); 4161 4162 cs_log("Demuxer %d found %d ECM pids and %d STREAM pids in %sPMT", demux_id, 4163 demux[demux_id].ECMpidcount, demux[demux_id].STREAMpidcount, ca_pmt_cmd_id != NULL ? "CA " : ""); 4164 4165 // Various retarded boxes misuse the "ca_pmt_cmd_id" value. 4166 // Make sure we pass a value we can work with later on... 4167 if(cfg.dvbapi_boxtype == BOXTYPE_DUCKBOX) 4168 { 4169 *ca_pmt_cmd_id = CA_PMT_CMD_OK_DESCRAMBLING; 4170 } 4171 4172 // If no elementary streams are available, set the PMT pid as the 4173 // first stream (PMT cannot be encrypted, like it was mentioned 4174 // in the old comment, so not sure why this is needed...) 4175 if(demux[demux_id].STREAMpidcount == 0) 4176 { 4177 demux[demux_id].STREAMpids[0] = demux[demux_id].pmtpid; 4178 demux[demux_id].STREAMpidsType[0] = STREAM_VIDEO; 4179 demux[demux_id].STREAMpidcount++; 4180 video_pid = demux[demux_id].pmtpid; 4181 } 4182 4183 // Register found video pid on all ECM pids of this demuxer 4184 for(i = 0; i < demux[demux_id].ECMpidcount; i++) 4185 { 4186 demux[demux_id].ECMpids[i].VPID = video_pid; 4187 } 4188 4189 // Search for dvbapi priority entries for this program 4190 if(dvbapi_priority != NULL) 4191 { 4192 dvbapi_priority_read_entry_add(demux_id, video_pid); 4193 dvbapi_priority_read_entry_map(demux_id); 4194 dvbapi_priority_read_entry_extra(demux_id); 4195 } 4196 } 4197 4198 typedef struct demux_parameters 4199 { 4200 uint8_t demux_index; 4201 uint8_t adapter_index; 4202 uint32_t ca_mask; 4203 uint16_t program_number; 4204 uint16_t pmtpid; 4205 uint16_t onid; 4206 uint16_t tsid; 4207 uint32_t ens; 4208 } demux_parameters_t; 4209 4210 static void get_demux_parameters(const uint8_t *buffer, demux_parameters_t *parameters) 4211 { 4212 parameters->ca_mask = 1; 4213 parameters->demux_index = 0; 4214 parameters->adapter_index = 0; 4215 parameters->pmtpid = 0; 4216 parameters->program_number = b2i(2, buffer + 1); 4070 4217 4071 4218 uint16_t program_info_length = b2i(2, buffer + 4) & 0x0FFF; … … 4079 4226 switch(descriptor_tag) 4080 4227 { 4081 case 0x09: // CA 4082 // We parse this descriptor elsewhere 4228 case 0x09: // We parse ca_descriptor() later 4083 4229 break; 4084 4230 4085 case 0x81: // enigma namespace 4086 // We parse this in another function... 4087 // Maybe this is changed in the future 4231 case 0x81: // enigma_namespace_descriptor() 4232 { 4233 if(descriptor_length == 0x08) 4234 { 4235 parameters->ens = b2i(4, buffer + pos + 2); 4236 parameters->tsid = b2i(2, buffer + pos + 6); 4237 parameters->onid = b2i(2, buffer + pos + 8); 4238 } 4088 4239 break; 4089 4090 case 0x82: // demux, ca_mask, adapter (everyone is using this descriptor differently - what a mess) 4240 } 4241 4242 case 0x82: // demux, ca_mask, adapter (deprecated - applications should use descriptors 0x83, 0x86 and 0x87 instead) 4091 4243 { 4092 4244 if(descriptor_length == 0x02 && (cfg.dvbapi_boxtype == BOXTYPE_PC || 4093 4245 cfg.dvbapi_boxtype == BOXTYPE_PC_NODMX || cfg.dvbapi_boxtype == BOXTYPE_SAMYGO)) 4094 4246 { 4095 *demux_index = buffer[pos + 2]; // it is always 0 but you never know4096 *adapter_index = buffer[pos + 3]; // adapter index can be 0, 1, 24097 *ca_mask = (1 << *adapter_index); // use adapter_index as ca_mask4247 parameters->demux_index = buffer[pos + 2]; // Usually 0, but not always 4248 parameters->adapter_index = buffer[pos + 3]; // Can be 0, 1, 2, ... 4249 parameters->ca_mask = (1 << parameters->adapter_index); // use adapter_index as ca_mask 4098 4250 } 4099 4251 else if(descriptor_length == 0x03 && cfg.dvbapi_boxtype == BOXTYPE_QBOXHD) 4100 4252 { 4101 4253 // ca_mask = buffer[pos + 2]; // with STONE 1.0.4 always 0x01 4102 *demux_index = buffer[pos + 3]; // with STONE 1.0.4 always 0x004103 *adapter_index = buffer[pos + 4]; // with STONE 1.0.4 adapter index can be 0, 1, 24104 *ca_mask = (1 << *adapter_index); // use adapter_index as ca_mask4254 parameters->demux_index = buffer[pos + 3]; // with STONE 1.0.4 always 0x00 4255 parameters->adapter_index = buffer[pos + 4]; // with STONE 1.0.4 adapter index can be 0, 1, 2 4256 parameters->ca_mask = (1 << parameters->adapter_index); // use adapter_index as ca_mask 4105 4257 } 4106 4258 else if(descriptor_length == 0x02) // enigma2 4107 4259 { 4108 *ca_mask = buffer[pos + 2];4260 parameters->ca_mask = buffer[pos + 2]; 4109 4261 uint8_t demux_tmp = buffer[pos + 3]; 4110 4262 4111 if(demux_tmp >= 8 && *ca_mask == 0) // openpli based images4112 { 4113 *ca_mask = 1 << demux_tmp;4263 if(demux_tmp >= 8 && parameters->ca_mask == 0) // openpli based images 4264 { 4265 parameters->ca_mask = 1 << demux_tmp; 4114 4266 } 4115 4267 … … 4118 4270 demux_tmp = 0; 4119 4271 } 4120 *demux_index = demux_tmp;4272 parameters->demux_index = demux_tmp; 4121 4273 } 4122 4274 break; 4123 4275 } 4124 4276 4125 case 0x83: // adapter 4277 case 0x83: // adapter_device_descriptor() 4126 4278 { 4127 4279 if(descriptor_length == 0x01) 4128 4280 { 4129 *adapter_index = buffer[pos + 2];4281 parameters->adapter_index = buffer[pos + 2]; 4130 4282 } 4131 4283 break; 4132 4284 } 4133 4285 4134 case 0x84: // pmt pid4286 case 0x84: // pmt_pid_descriptor() 4135 4287 { 4136 4288 if(descriptor_length == 0x02) 4137 4289 { 4138 *pmtpid = b2i(2, buffer + pos + 2);4290 parameters->pmtpid = b2i(2, buffer + pos + 2); 4139 4291 } 4140 4292 break; 4141 4293 } 4142 4294 4143 case 0x85: // service type mask(not used by OSCam)4295 case 0x85: // service_type_mask_descriptor() (not used by OSCam) 4144 4296 break; 4145 4297 4146 case 0x86: // demux only (new - added in 2019)4298 case 0x86: // demux_device_descriptor() 4147 4299 { 4148 4300 if(descriptor_length == 0x01) 4149 4301 { 4150 *demux_index = buffer[pos + 2];4151 *ca_mask = 1 << *demux_index;4302 parameters->demux_index = buffer[pos + 2]; 4303 parameters->ca_mask = 1 << parameters->demux_index; 4152 4304 } 4153 4305 break; 4154 4306 } 4155 4307 4308 case 0x87: // ca_device_descriptor() 4309 { 4310 if(descriptor_length == 0x01) 4311 { 4312 parameters->ca_mask = 1 << buffer[pos + 2]; 4313 } 4314 break; 4315 } 4316 4156 4317 default: 4157 4318 { 4158 4319 cs_log_dbg(D_DVBAPI, "Received unknown CA PMT descriptor (tag: %02X length: %02X)", 4159 4320 descriptor_tag, descriptor_length); 4160 4321 break; 4161 4322 } … … 4163 4324 4164 4325 pos += 2 + descriptor_length; 4165 }4166 4167 // Probably this box doesn't send any private4168 // descriptor in the CA PMT, so we have to improvise4169 if(cfg.dvbapi_boxtype == BOXTYPE_IPBOX_PMT)4170 {4171 *ca_mask = demux_id + 1;4172 *demux_index = demux_id;4173 4326 } 4174 4327 } … … 4191 4344 } 4192 4345 4193 int32_t dvbapi_parse_capmt(uint8_t *buffer, uint32_t length, int32_t connfd, char *pmtfile, int8_t is_real_pmt, 4194 uint16_t existing_demux_id, uint16_t client_proto_version, uint32_t msgid) 4195 { 4196 uint32_t i = 0, start_descrambling = 0; 4197 int32_t j = 0; 4198 int32_t demux_id = -1; 4199 uint16_t demux_index, adapter_index, pmtpid; 4200 uint32_t ca_mask; 4201 uint32_t program_number, program_info_length; 4202 uint8_t program_info_start = is_real_pmt ? 12 : 6; 4203 4204 if(!is_real_pmt) 4205 { 4206 #if defined WITH_COOLAPI || defined WITH_COOLAPI2 4207 int32_t ca_pmt_list_management = CA_PMT_LIST_ONLY; 4208 #else 4209 int32_t ca_pmt_list_management = buffer[0]; 4346 static void dvbapi_prepare_descrambling(int32_t demux_id, uint32_t msgid) 4347 { 4348 bool is_powervu = false, start_emm = true; 4349 4350 // The CA PMT should have given us enough info to determine if descrambling 4351 // is possible. Parsing the (real) PMT is not necessary, unless we have a 4352 // PowerVu encrypted channel or (for some weird reason) no stream pids at all. 4353 // Actually, when no streams are available, we set the PMT pid as the 1st 4354 // stream pid, so we have to check against that. Finally, if the PMT pid is 4355 // not included in the CA PMT, we start the PAT filter instead. 4356 4357 #ifdef WITH_EXTENDED_CW 4358 for(i = 0; i < demux[demux_id].ECMpidcount; i++) 4359 { 4360 if(caid_is_powervu(demux[demux_id].ECMpids[i].CAID)) 4361 { 4362 is_powervu = true; 4363 break; 4364 } 4365 } 4210 4366 #endif 4211 program_number = b2i(2, buffer + 1); 4212 program_info_length = b2i(2, buffer + 4) &0xFFF; 4213 cs_log_dump_dbg(D_DVBAPI, buffer, length, "capmt:"); 4214 cs_log_dbg(D_DVBAPI, "Receiver sends PMT command %d for channel %04X", ca_pmt_list_management, program_number); 4215 4216 if(!pmt_stopmarking && (ca_pmt_list_management == CA_PMT_LIST_FIRST || ca_pmt_list_management == CA_PMT_LIST_ONLY)) 4217 { 4218 for(i = 0; i < MAX_DEMUX; i++) 4219 { 4220 // skip empty demuxers, skip demuxers belonging to other ca pmt connection, skip demuxers handled by other pmt files 4221 if((demux[i].program_number == 0) || (demux[i].socket_fd != connfd) || ((demux[i].socket_fd == -1) 4222 && (pmtfile && strcmp(demux[i].pmt_file, pmtfile) != 0))) 4223 { 4224 continue; 4225 } 4226 4227 demux[i].stopdescramble = 1; // Mark for deletion if not used again by following pmt objects. 4228 cs_log_dbg(D_DVBAPI, "Marked demuxer %d/%d (srvid = %04X fd = %d) to stop decoding", 4229 i, MAX_DEMUX, demux[i].program_number, connfd); 4230 } 4231 pmt_stopmarking = 1; // only stop demuxing for first pmt record 4232 } 4233 4234 get_demux_options(i, buffer, &ca_mask, &demux_index, &adapter_index, &pmtpid); 4235 cs_log_dbg(D_DVBAPI,"Receiver wants to demux srvid %04X on adapter %04X camask %04X index %04X pmtpid %04X", 4236 program_number, adapter_index, ca_mask, demux_index, pmtpid); 4237 4238 for(i = 0; i < MAX_DEMUX; i++) // search current demuxers for running the same program as the one we received in this PMT object 4239 { 4240 if(demux[i].program_number == 0) 4241 { 4242 continue; 4243 } 4244 4245 if(cfg.dvbapi_boxtype == BOXTYPE_IPBOX_PMT) 4246 { 4247 demux_index = i; // fixup for ipbox 4248 } 4249 4250 bool full_check = 1, matched = 0; 4251 if(config_enabled(WITH_COOLAPI) || config_enabled(WITH_COOLAPI2) || cfg.dvbapi_boxtype == BOXTYPE_SAMYGO) 4252 { 4253 full_check = 0; 4254 } 4255 4256 if(full_check) 4257 { 4258 matched = (connfd > 0 && demux[i].socket_fd == connfd) && demux[i].program_number == program_number; 4259 } 4260 else 4261 { 4262 matched = connfd > 0 && demux[i].program_number == program_number; 4263 } 4264 4265 if(matched) 4266 { 4267 if(full_check) 4268 { 4269 // perhaps next demuxer matches? 4270 if((demux[i].adapter_index != adapter_index) || (demux[i].ca_mask != ca_mask) || (demux[i].demux_index != demux_index)) 4271 { 4272 continue; 4273 } 4274 } 4275 4276 if(ca_pmt_list_management == CA_PMT_LIST_UPDATE) 4277 { 4278 cs_log("Demuxer %d PMT update for decoding of SRVID %04X! ", i, program_number); 4279 } 4280 4281 demux_id = i; 4282 cs_log("Demuxer %d continue decoding of SRVID %04X", i, demux[i].program_number); 4283 openxcas_set_sid(program_number); 4284 demux[i].stopdescramble = 0; // dont stop current demuxer! 4285 break; // no need to explore other demuxers since we have a found! 4286 } 4287 } 4288 4289 // start using the new list 4290 if(ca_pmt_list_management != CA_PMT_LIST_FIRST && ca_pmt_list_management != CA_PMT_LIST_MORE) 4291 { 4292 for(j = 0; j < MAX_DEMUX; j++) 4293 { 4294 if(demux[j].program_number == 0) 4295 { 4296 continue; 4297 } 4298 4299 if(demux[j].stopdescramble == 1) 4300 { 4301 dvbapi_stop_descrambling(j, msgid); // Stop descrambling and remove all demuxer entries not in new PMT. 4302 } 4303 } 4304 start_descrambling = 1; // flag that demuxer descrambling is to be executed! 4305 pmt_stopmarking = 0; // flag that demuxers may be marked for stop decoding again 4306 } 4307 4308 if(demux_id == -1) 4309 { 4310 for(demux_id = 0; demux_id < MAX_DEMUX; demux_id++) 4311 { 4312 if(demux[demux_id].program_number == 0) 4313 { 4314 demux[demux_id].program_number = program_number; // do this early since some prio items use them! 4315 demux[demux_id].ens = 0; 4316 demux[demux_id].tsid = 0; 4317 demux[demux_id].onid = 0; 4318 demux[demux_id].pmtpid = pmtpid; 4319 demux[demux_id].socket_fd = connfd; 4320 demux[demux_id].adapter_index = adapter_index; 4321 demux[demux_id].client_proto_version = client_proto_version; 4322 demux[demux_id].sdt_filter = -1; 4323 4324 if(demux_id < 1) 4325 { 4326 demux[demux_id].demux_index = demux_id; // set demuxer stop point if PMT demux_index == 0 4327 } 4328 4329 if(pmtfile) 4330 { 4331 cs_strncpy(demux[demux_id].pmt_file, pmtfile, sizeof(demux[demux_id].pmt_file)); 4332 } 4333 4334 // free demuxer found, start pat/pmt filter for this new demuxer 4335 if(demux[demux_id].pmtpid) 4336 { 4337 dvbapi_start_pmt_filter(demux_id); 4338 } 4339 else 4340 { 4341 dvbapi_start_pat_filter(demux_id); 4342 } 4343 break; 4344 } 4345 } 4346 } 4347 4348 if(demux_id >= MAX_DEMUX) 4349 { 4350 cs_log("ERROR: No free id (MAX_DEMUX)"); 4351 return -1; 4352 } 4353 4354 if(demux[demux_id].running == 0) 4355 { 4356 demux[demux_id].ECMpidcount = 0; // reset number of ecmpids only if it was not running! 4357 } 4358 } 4359 else // is_real_pmt 4360 { 4361 demux_id = existing_demux_id; 4362 dvbapi_stop_filter(demux_id, TYPE_PMT, msgid); 4363 program_number = b2i(2, buffer + 3); 4364 program_info_length = b2i(2, buffer + 10) & 0xFFF; 4365 cs_log_dump_dbg(D_DVBAPI, buffer, length, "pmt:"); 4366 pmtpid = demux[demux_id].pmtpid; 4367 } 4368 4369 for(j = 0; j < demux[demux_id].ECMpidcount; j++) // cleanout demuxer from possible stale info 4370 { 4371 demux[demux_id].ECMpids[j].streams = 0; // reset streams of each ecmpid! 4372 } 4373 demux[demux_id].STREAMpidcount = 0; // reset number of streams 4374 4375 if(program_info_length > 1 && program_info_length < length) // parse program descriptors 4376 { 4377 dvbapi_parse_pmt_descriptors(demux_id, buffer + program_info_start, program_info_length, NULL); 4378 } 4379 uint32_t es_info_length = 0, vpid = 0; 4380 4381 for(i = program_info_length + program_info_start; i + 4 < length; i += es_info_length + 5) 4382 { 4383 uint8_t stream_type = buffer[i], type = STREAM_AUDIO; // default to audio - quick fix for missing audio when recording 4384 uint16_t elementary_pid = b2i(2, buffer + i + 1) & 0x1FFF; 4385 es_info_length = b2i(2, buffer + i + 3) & 0x0FFF; 4386 4387 if(demux[demux_id].STREAMpidcount < MAX_STREAM_PIDS) 4388 { 4389 cs_log_dbg(D_DVBAPI,"Demuxer %d found %s stream (type: %02X pid: %04X)", 4390 demux_id, get_stream_type_txt(stream_type), stream_type, elementary_pid); 4391 4392 if(es_info_length != 0 && es_info_length < length) // parse program element descriptors 4393 { 4394 dvbapi_parse_pmt_descriptors(demux_id, buffer + i + 5, es_info_length, &type); 4395 } 4396 else 4397 { 4398 dvbapi_priority_read_entry_add(demux_id, vpid); 4399 } 4400 4401 switch(stream_type) 4402 { 4403 case 0x01: 4404 case 0x02: 4405 case 0x10: 4406 case 0x1B: 4407 case 0x20: 4408 case 0x24: 4409 case 0x25: 4410 case 0x42: 4411 case 0xD1: 4412 case 0xEA: 4413 if(!vpid) 4414 { 4415 vpid = elementary_pid; // register videopid 4416 } 4417 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = STREAM_VIDEO; 4418 break; 4419 4420 case 0x03: 4421 case 0x04: 4422 case 0x0F: 4423 case 0x11: 4424 case 0x1C: 4425 case 0x2D: 4426 case 0x2E: 4427 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = STREAM_AUDIO; 4428 break; 4429 4430 case 0x06: 4431 case 0x81: 4432 case 0x87: 4433 // Set the type based on the descriptors for these streams 4434 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = type; 4435 break; 4436 4437 default: 4438 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = STREAM_UNDEFINED; 4439 break; 4440 } 4441 demux[demux_id].STREAMpids[demux[demux_id].STREAMpidcount] = elementary_pid; 4442 demux[demux_id].STREAMpidcount++; 4443 } 4444 } 4445 4446 if(!is_real_pmt) 4447 { 4448 cs_log("Demuxer %d found %d ECMpids and %d STREAMpids in caPMT", 4449 demux_id, demux[demux_id].ECMpidcount, demux[demux_id].STREAMpidcount); 4450 4451 get_demux_options(demux_id, buffer, &ca_mask, &demux_index, &adapter_index, &pmtpid); 4452 4453 demux[demux_id].adapter_index = adapter_index; 4454 demux[demux_id].ca_mask = ca_mask; 4455 demux[demux_id].rdr = NULL; 4456 demux[demux_id].demux_index = demux_index; 4457 demux[demux_id].socket_fd = connfd; 4458 demux[demux_id].client_proto_version = client_proto_version; 4459 4460 if(demux[demux_id].STREAMpidcount == 0) // encrypted PMT 4461 { 4462 demux[demux_id].STREAMpids[demux[demux_id].STREAMpidcount] = pmtpid; 4463 demux[demux_id].STREAMpidsType[demux[demux_id].STREAMpidcount] = 0x01; 4464 demux[demux_id].STREAMpidcount++; 4465 vpid = pmtpid; 4466 } 4467 } 4468 else 4469 { 4470 cs_log("Demuxer %d found %d ECMpids and %d STREAMpids in PMT", 4471 demux_id, demux[demux_id].ECMpidcount, demux[demux_id].STREAMpidcount); 4472 4473 ca_mask = demux[demux_id].ca_mask; 4474 demux_index = demux[demux_id].demux_index; 4475 adapter_index = demux[demux_id].adapter_index; 4476 connfd = demux[demux_id].socket_fd; 4477 } 4478 4479 for(j = 0; j < demux[demux_id].ECMpidcount; j++) 4480 { 4481 demux[demux_id].ECMpids[j].VPID = vpid; // register found vpid on all ecmpids of this demuxer 4482 } 4483 4484 char channame[CS_SERVICENAME_SIZE]; 4485 get_servicename(dvbapi_client, 4486 demux[demux_id].program_number, 4487 demux[demux_id].ECMpidcount > 0 ? demux[demux_id].ECMpids[0].PROVID : NO_PROVID_VALUE, 4488 demux[demux_id].ECMpidcount > 0 ? demux[demux_id].ECMpids[0].CAID : NO_CAID_VALUE, 4489 channame, 4490 sizeof(channame)); 4491 4492 cs_log_dbg(D_DVBAPI,"Demuxer %d serving srvid %04X (%s) on adapter %04X camask %04X index %04X pmtpid %04X", 4493 demux_id, 4494 demux[demux_id].program_number, 4495 channame, 4496 adapter_index, 4497 ca_mask, 4498 demux_index, 4499 pmtpid); 4500 4501 demux[demux_id].stopdescramble = 0; // remove deletion mark! 4502 4503 // remove from unassoc_fd when necessary 4504 for(j = 0; j < MAX_DEMUX; j++) 4505 { 4506 if(unassoc_fd[j] == connfd) 4507 { 4508 unassoc_fd[j] = 0; 4509 } 4510 } 4511 4512 dvbapi_capmt_notify(&demux[demux_id]); 4513 dvbapi_priority_read_entry_extra(demux_id); 4514 4515 if(start_descrambling) 4516 { 4517 for(j = 0; j < MAX_DEMUX; j++) 4518 { 4519 // skip demuxers belonging to other caPMT connection 4520 // skip demuxers handled by other PMT files 4521 if((demux[j].program_number == 0) || (demux[j].socket_fd != connfd) || ((demux[j].socket_fd == -1) 4522 && (pmtfile && strcmp(demux[j].pmt_file, pmtfile) != 0))) 4523 { 4524 continue; 4525 } 4526 4527 if(demux[j].running && demux_id == j) 4528 { 4529 disable_unused_streampids(j); // disable all streampids not in use anymore 4530 } 4531 4532 if(demux[j].running == 0 && demux[j].ECMpidcount != 0) // only start demuxer if it wasn't running 4533 { 4534 // remove all non important filtering 4535 // (there are images with limited amount of filters available!) 4536 dvbapi_stop_all_emm_sdt_filtering(msgid); 4537 4538 cs_log_dbg(D_DVBAPI, "Demuxer %d/%d lets start descrambling (srvid = %04X fd = %d ecmpids = %d)", 4539 j, MAX_DEMUX, demux[j].program_number, connfd, demux[j].ECMpidcount); 4540 4541 demux[j].running = 1; // mark channel as running 4542 openxcas_set_sid(demux[j].program_number); 4543 demux[j].decodingtries = -1; 4544 dvbapi_resort_ecmpids(j); 4545 dvbapi_try_next_caid(j, 0, msgid); 4546 cs_sleepms(1); 4547 } 4548 else if(demux[j].ECMpidcount == 0) // fta do logging and part of ecmhandler since there will be no ecms asked! 4549 { 4550 cs_log_dbg(D_DVBAPI, "Demuxer %d/%d no descrambling needed (srvid = %04X fd = %d ecmpids = %d)", 4551 j, MAX_DEMUX, demux[j].program_number, connfd, demux[j].ECMpidcount); 4552 4553 demux[j].running = 0; // reset running flag 4554 demux[demux_id].pidindex = -1; // reset ecmpid used for descrambling 4555 dvbapi_stop_filter(j, TYPE_ECM, msgid); 4556 4557 if(cfg.usrfileflag) // add to user log previous channel + time on channel 4558 { 4559 cs_statistics(dvbapi_client); 4560 } 4561 4562 dvbapi_client->last_srvid = demux[demux_id].program_number; // set new channel srvid 4563 dvbapi_client->last_caid = NO_CAID_VALUE; // FTA channels have no caid! 4564 dvbapi_client->last_provid = NO_PROVID_VALUE; // FTA channels have no provid! 4565 dvbapi_client->lastswitch = dvbapi_client->last = time((time_t *)0); // reset idle-Time & last switch 4566 } 4567 } 4568 } 4569 4570 int32_t DoNotStartEMM = 0; 4367 4368 if(demux[demux_id].pmtpid == 0) 4369 { 4370 dvbapi_start_pat_filter(demux_id); 4371 } 4372 else if(demux[demux_id].STREAMpids[0] == demux[demux_id].pmtpid || is_powervu) 4373 { 4374 dvbapi_start_pmt_filter(demux_id); 4375 } 4376 4377 if(demux[demux_id].running) 4378 { 4379 disable_unused_streampids(demux_id); // disable all streampids not in use anymore 4380 } 4381 4382 if(!demux[demux_id].running && demux[demux_id].ECMpidcount != 0) // only start demuxer if it wasn't running 4383 { 4384 // remove all non important filtering 4385 // (there are images with limited amount of filters available!) 4386 dvbapi_stop_all_emm_sdt_filtering(msgid); 4387 4388 cs_log_dbg(D_DVBAPI, "Demuxer %d started descrambling for program %04X (fd: %d)", 4389 demux_id, demux[demux_id].program_number, demux[demux_id].socket_fd); 4390 4391 demux[demux_id].running = true; // mark channel as running 4392 openxcas_set_sid(demux[demux_id].program_number); 4393 demux[demux_id].decodingtries = -1; 4394 dvbapi_resort_ecmpids(demux_id); 4395 dvbapi_try_next_caid(demux_id, 0, msgid); 4396 cs_sleepms(1); 4397 } 4398 else if(demux[demux_id].ECMpidcount == 0) // FTA: do logging and part of ecm handler 4399 { 4400 cs_log_dbg(D_DVBAPI, "Demuxer %d no descrambling needed for FTA program %04X (fd: %d)", 4401 demux_id, demux[demux_id].program_number, demux[demux_id].socket_fd); 4402 4403 demux[demux_id].running = false; // reset running flag 4404 demux[demux_id].pidindex = -1; // reset ecmpid used for descrambling 4405 dvbapi_stop_filter(demux_id, TYPE_ECM, msgid); 4406 4407 if(cfg.usrfileflag) // add to user log previous channel + time on channel 4408 { 4409 cs_statistics(dvbapi_client); 4410 } 4411 4412 dvbapi_client->last_srvid = demux[demux_id].program_number; // set new channel srvid 4413 dvbapi_client->last_caid = NO_CAID_VALUE; // FTA channels have no caid! 4414 dvbapi_client->last_provid = NO_PROVID_VALUE; // FTA channels have no provid! 4415 dvbapi_client->lastswitch = dvbapi_client->last = time((time_t *)0); // reset idle-Time & last switch 4416 } 4571 4417 4572 4418 #if defined(WITH_COOLAPI) || defined(WITH_COOLAPI2) … … 4574 4420 if(dvbapi_client->last_caid == NO_CAID_VALUE) 4575 4421 { 4576 DoNotStartEMM = 1;4422 start_emm = false; 4577 4423 } 4578 4424 #endif 4579 4425 4580 4426 // only do emm setup if au enabled and not running! 4581 if(cfg.dvbapi_au > 0 && demux[demux_id].EMMpidcount == 0 && !DoNotStartEMM)4427 if(cfg.dvbapi_au > 0 && demux[demux_id].EMMpidcount == 0 && start_emm == true) 4582 4428 { 4583 4429 demux[demux_id].emm_filter = -1; // to register first run emmfilter start … … 4595 4441 } 4596 4442 } 4597 4598 return demux_id; 4443 } 4444 4445 int32_t dvbapi_parse_capmt(const uint8_t *buffer, uint32_t length, int32_t connfd, char *pmtfile, uint16_t client_proto_version, uint32_t msgid) 4446 { 4447 int32_t i, demux_id = -1; 4448 uint8_t ca_pmt_list_management, ca_pmt_cmd_id; 4449 bool is_update = false; 4450 demux_parameters_t parameters; 4451 memset(¶meters, 0, sizeof(parameters)); 4452 4453 #if defined WITH_COOLAPI || defined WITH_COOLAPI2 4454 ca_pmt_list_management = CA_PMT_LIST_ONLY; 4455 #else 4456 ca_pmt_list_management = buffer[0]; 4457 #endif 4458 4459 // We received a new list of CA PMT objects. 4460 // Mark all demuxers to stop descrambling, but do not actually stop any of them, 4461 // until we verify the new list does not contain any previously selected program. 4462 if(ca_pmt_list_management == CA_PMT_LIST_FIRST || ca_pmt_list_management == CA_PMT_LIST_ONLY) 4463 { 4464 for(i = 0; i < MAX_DEMUX; i++) 4465 { 4466 // Skip empty demuxers, demuxers belonging to different 4467 // CA PMT connections or handled by different PMT files. 4468 if(demux[i].program_number == 0 || demux[i].socket_fd != connfd || 4469 (demux[i].socket_fd == -1 && pmtfile && strcmp(demux[i].pmt_file, pmtfile) != 0)) 4470 { 4471 continue; 4472 } 4473 4474 demux[i].stop_descrambling = true; // Mark for deletion if not used again by following CA PMT objects 4475 4476 cs_log_dbg(D_DVBAPI, "Demuxer %d marked to stop descrambling for program %04X (fd: %d)", 4477 i, demux[i].program_number, connfd); 4478 } 4479 } 4480 4481 // Read private descriptors inside the CA PMT message 4482 // in order to get adapter, demux, ca, pmt pid and more. 4483 get_demux_parameters(buffer, ¶meters); 4484 4485 cs_log_dbg(D_DVBAPI, "Received CA PMT list management %d for program %04X (pmt pid: %04X adapter: %d demux: %d camask: %d)", 4486 ca_pmt_list_management, parameters.program_number, parameters.pmtpid, parameters.adapter_index, 4487 parameters.demux_index, parameters.ca_mask); 4488 4489 // Search current demuxers for having the same program 4490 // as the one we received in this CA PMT object. 4491 for(i = 0; i < MAX_DEMUX; i++) 4492 { 4493 if(demux[i].program_number == 0) 4494 { 4495 continue; 4496 } 4497 4498 if(cfg.dvbapi_boxtype == BOXTYPE_IPBOX_PMT) 4499 { 4500 parameters.demux_index = i; // fixup for ipbox 4501 } 4502 4503 bool full_check = true, matched = false; 4504 4505 if(config_enabled(WITH_COOLAPI) || config_enabled(WITH_COOLAPI2) || cfg.dvbapi_boxtype == BOXTYPE_SAMYGO) 4506 { 4507 full_check = false; 4508 } 4509 4510 if(full_check) 4511 { 4512 matched = (connfd > 0 && demux[i].socket_fd == connfd) && demux[i].program_number == parameters.program_number; 4513 } 4514 else 4515 { 4516 matched = connfd > 0 && demux[i].program_number == parameters.program_number; 4517 } 4518 4519 if(matched) 4520 { 4521 if(full_check) 4522 { 4523 // In PMT mode 6, when zapping between channels with the same program number and PMT pid 4524 // (sometimes the case with satellite feeds), as all hardware parameters being the same 4525 // (adapter, demux, ca_mask, connfd), the new program is considered an existing one (matched). 4526 // The only reliable way to determine whether we actually have a new program is to compare 4527 // the enigma namespace, tsid and onid as well. 4528 if(demux[i].demux_index != parameters.demux_index || demux[i].ca_mask != parameters.ca_mask || 4529 demux[i].adapter_index != parameters.adapter_index || demux[i].pmtpid != parameters.pmtpid || 4530 demux[i].ens != parameters.ens || demux[i].tsid != parameters.tsid || demux[i].onid != parameters.onid) 4531 { 4532 continue; 4533 } 4534 } 4535 4536 // A program update is normally signaled by either a list management: 4537 // 1. UPDATE for an existing program 4538 // 2. ADD for an existing program (which according to the specifications should be treated as an UPDATE) 4539 // 3. ONLY for an existing program (with broken clients, in pmt modes other than 6) 4540 if(ca_pmt_list_management == CA_PMT_LIST_UPDATE || ca_pmt_list_management == CA_PMT_LIST_ADD 4541 || (cfg.dvbapi_pmtmode != 6 && ca_pmt_list_management == CA_PMT_LIST_ONLY)) 4542 { 4543 is_update = true; 4544 cs_log("Demuxer %d received updated CA PMT for program %04X", i, parameters.program_number); 4545 } 4546 4547 cs_log("Demuxer %d continues descrambling for program %04X", i, demux[i].program_number); 4548 openxcas_set_sid(parameters.program_number); 4549 demux[i].stop_descrambling = false; // don't stop current demuxer! 4550 demux_id = i; 4551 break; // no need to explore other demuxers since we have a match! 4552 } 4553 } 4554 4555 // We are currently processing the last object of the CA PMT list. 4556 // We should now stop descrambling all programs not included in this list. 4557 if(ca_pmt_list_management != CA_PMT_LIST_FIRST && ca_pmt_list_management != CA_PMT_LIST_MORE) 4558 { 4559 for(i = 0; i < MAX_DEMUX; i++) 4560 { 4561 if(demux[i].program_number == 0) 4562 { 4563 continue; 4564 } 4565 4566 if(demux[i].stop_descrambling) 4567 { 4568 dvbapi_stop_descrambling(i, msgid); 4569 } 4570 } 4571 } 4572 4573 // We continue reading the CA PMT object only when we get 4574 // a new program (demux_id == -1) or an updated program. 4575 if(!(demux_id == -1 || is_update)) 4576 { 4577 return demux_id; 4578 } 4579 4580 // We received a CA PMT object for a new program. 4581 // Let's find an empty demuxer for it. 4582 if(demux_id == -1) 4583 { 4584 if(ca_pmt_list_management == CA_PMT_LIST_UPDATE) 4585 { 4586 cs_log("ERROR: Received CA PMT list update for unknown program"); 4587 return -1; 4588 } 4589 4590 for(demux_id = 0; demux_id < MAX_DEMUX; demux_id++) 4591 { 4592 if(demux[demux_id].program_number != 0) 4593 { 4594 continue; // Skip occupied demuxers 4595 } 4596 4597 // Probably this box doesn't send any private descriptor in the 4598 // CA PMT, so we have to improvise before saving to the demuxer. 4599 if(cfg.dvbapi_boxtype == BOXTYPE_IPBOX_PMT) 4600 { 4601 parameters.ca_mask = demux_id + 1; 4602 parameters.demux_index = demux_id; 4603 } 4604 4605 demux[demux_id].demux_index = parameters.demux_index; 4606 demux[demux_id].adapter_index = parameters.adapter_index; 4607 demux[demux_id].ca_mask = parameters.ca_mask; 4608 demux[demux_id].socket_fd = connfd; 4609 demux[demux_id].client_proto_version = client_proto_version; 4610 demux[demux_id].program_number = parameters.program_number; 4611 demux[demux_id].pmtpid = parameters.pmtpid; 4612 demux[demux_id].ens = parameters.ens; 4613 demux[demux_id].tsid = parameters.tsid; 4614 demux[demux_id].onid = parameters.onid; 4615 demux[demux_id].stop_descrambling = false; 4616 demux[demux_id].running = false; 4617 demux[demux_id].sdt_filter = -1; 4618 demux[demux_id].rdr = NULL; 4619 4620 if(pmtfile) 4621 { 4622 cs_strncpy(demux[demux_id].pmt_file, pmtfile, sizeof(demux[demux_id].pmt_file)); 4623 } 4624 4625 break; 4626 } 4627 4628 if(demux_id >= MAX_DEMUX) 4629 { 4630 cs_log("There is no free demuxer for the new program! Aborting..."); 4631 return -1; 4632 } 4633 } 4634 4635 // We continue parsing the CA PMT info for new or updated programs. 4636 // For updated programs, we just delete all previous stream pids and 4637 // ECM pids and start parsing the fresh data. 4638 dvbapi_parse_pmt_info(demux_id, buffer + 4, length - 4, &ca_pmt_cmd_id); 4639 4640 // Finally, evaluate what response the host requires from OSCam. 4641 // This allows multiple CA applications to run at the host simultaneously. 4642 // "OK query" will be implemented at a later stage, when support is first 4643 // added in enigma2. 4644 switch(ca_pmt_cmd_id) 4645 { 4646 case CA_PMT_CMD_OK_DESCRAMBLING: 4647 { 4648 // remove from unassoc_fd when necessary 4649 for(i = 0; i < MAX_DEMUX; i++) 4650 { 4651 if(unassoc_fd[i] == connfd) 4652 { 4653 unassoc_fd[i] = 0; 4654 } 4655 } 4656 4657 dvbapi_capmt_notify(&demux[demux_id]); 4658 dvbapi_prepare_descrambling(demux_id, msgid); 4659 return demux_id; 4660 } 4661 4662 case CA_PMT_CMD_QUERY: 4663 { 4664 cs_log("Received unsupported CA PMT command ID 'query' for program %04X", demux[demux_id].program_number); 4665 dvbapi_stop_descrambling(demux_id, msgid); // Clear all data from this demuxer 4666 return -1; 4667 } 4668 4669 case CA_PMT_CMD_NOT_SELETED: 4670 { 4671 cs_log("Program %04X is not selected for descrambling", demux[demux_id].program_number); 4672 dvbapi_stop_descrambling(demux_id, msgid); // Clear all data from this demuxer 4673 return -1; 4674 } 4675 4676 default: 4677 { 4678 cs_log("Received unknown or unsupported CA PMT command ID %02X from host", ca_pmt_cmd_id); 4679 dvbapi_stop_descrambling(demux_id, msgid); 4680 return -1; 4681 } 4682 } 4683 } 4684 4685 static void dvbapi_parse_pmt(int32_t demux_id, const uint8_t *buffer, uint32_t length, uint32_t msgid) 4686 { 4687 uint16_t program_number = b2i(2, buffer + 3); 4688 if(program_number != demux[demux_id].program_number) 4689 { 4690 cs_log("Demuxer %d received PMT for undefined program %04X", demux_id, program_number); 4691 return; 4692 } 4693 4694 dvbapi_stop_filter(demux_id, TYPE_PMT, msgid); 4695 dvbapi_parse_pmt_info(demux_id, buffer + 10, length - 10 - 4, NULL); // last 4 bytes are the CRC-32 4599 4696 } 4600 4697 … … 5305 5402 } 5306 5403 cs_log_dump_dbg(D_DVBAPI, (uint8_t *)dest, len / 2, "QboxHD pmt.tmp:"); 5307 demux_id = dvbapi_parse_capmt((uint8_t *)dest + 4, (len / 2) - 4, -1, dp->d_name, 0, 0 , 0, 0);5404 demux_id = dvbapi_parse_capmt((uint8_t *)dest + 4, (len / 2) - 4, -1, dp->d_name, 0, 0); 5308 5405 #else 5309 5406 if(len > sizeof(dest)) … … 5329 5426 memcpy(dest + 7, mbuf + 12, len - 12 - 4); 5330 5427 5331 demux_id = dvbapi_parse_capmt((uint8_t *)dest, 7 + len - 12 - 4, -1, dp->d_name, 0, 0 , 0, 0);5428 demux_id = dvbapi_parse_capmt((uint8_t *)dest, 7 + len - 12 - 4, -1, dp->d_name, 0, 0); 5332 5429 #endif 5333 5430 if(demux_id >= 0) … … 5896 5993 demux_id, filter_num + 1, sctlen); 5897 5994 5898 dvbapi_parse_ capmt(buffer, sctlen, demux[demux_id].socket_fd, demux[demux_id].pmt_file, 1, demux_id, demux[demux_id].client_proto_version, msgid);5995 dvbapi_parse_pmt(demux_id, buffer, sctlen, msgid); 5899 5996 } 5900 5997 } … … 6114 6211 } 6115 6212 6116 dvbapi_parse_capmt(mbuf + (chunksize - data_len), data_len, connfd, NULL, 0, 0,*client_proto_version, msgid);6213 dvbapi_parse_capmt(mbuf + (chunksize - data_len), data_len, connfd, NULL, *client_proto_version, msgid); 6117 6214 break; 6118 6215 } -
trunk/module-dvbapi.h
r11529 r11533 117 117 #define CA_PMT_LIST_UPDATE 0x05 // The CA PMT of a program already in the list is sent again because the version_number or 118 118 // the current_next_indicator has changed. 119 120 // ca_pmt_cmd_id: This parameter indicates what response is required from the application to a CA PMT object. It can 121 // take the following values: 122 123 #define CA_PMT_CMD_OK_DESCRAMBLING 0x01 // The host does not expect answer to the CA PMT and the application can start 124 // descrambling the program or start an MMI dialogue immediately. 125 126 #define CA_PMT_CMD_OK_MMI 0x02 // The application can start an MMI dialogue, but shall not start descrambling 127 // before reception of a new CA PMT object with "ca_pmt_cmd_id" set to 128 // "ok_descrambling". In this case the host shall quarantee that an MMI session 129 // can be opened by the CA application. 130 131 #define CA_PMT_CMD_QUERY 0x03 // The host expects to receive a CA PMT reply. In this case, the applicaiton is 132 // not allowed to start descrambling or MMI dialogue before reception of a new 133 // CA PMT object with "ca_pmt_cmd_id" set to "ok_descrambling or "ok_mmi". 134 135 #define CA_PMT_CMD_NOT_SELETED 0x04 // It indicates to the CA application that the host no longer requires that CA 136 // application to attempt to descramble the service. The CA application shall 137 // close any MMI dialogue it has opened. 119 138 120 139 //----------------------------------------------------------------------------- … … 403 422 char pmt_file[30]; 404 423 time_t pmt_time; 405 uint8_t stopdescramble;406 uint8_t running;424 bool stop_descrambling; // Program is marked to stop descrambling (not selected in the new CA PMT list) 425 bool running; // Descrambling is currently running for this program 407 426 uint8_t old_ecmfiltercount; // previous ecm filter count 408 427 uint8_t old_emmfiltercount; // previous emm filter count … … 466 485 void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er); 467 486 void dvbapi_write_cw(int32_t demux_id, int32_t pid, int32_t stream_id, uint8_t *cw, uint8_t cw_length, uint8_t *iv, uint8_t iv_length, enum ca_descr_algo algo, enum ca_descr_cipher_mode cipher_mode, uint32_t msgid); 468 int32_t dvbapi_parse_capmt( uint8_t *buffer, uint32_t length, int32_t connfd, char *pmtfile, int8_t is_real_pmt, uint16_t existing_demux_id, uint16_t client_proto_version, uint32_t msgid);487 int32_t dvbapi_parse_capmt(const uint8_t *buffer, uint32_t length, int32_t connfd, char *pmtfile, uint16_t client_proto_version, uint32_t msgid); 469 488 void request_cw(struct s_client *client, ECM_REQUEST *er, int32_t demux_id, uint8_t delayed_ecm_check); 470 489 void dvbapi_try_next_caid(int32_t demux_id, int8_t checked, uint32_t msgid);
Note:
See TracChangeset
for help on using the changeset viewer.