u32 hw_offset, buf_offset, i, k; u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0; u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0; 
u32 length = 0, count = 0; u8 asn_1_words, program_header_length; u16 program_info_length = 0, es_info_length = 0; u32 hw_offset = 0, buf_offset = 0, i; u8 dst_tag_length; 
static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query){	u32 hw_offset, buf_offset, i, k;	u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0;	u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0;	if (verbose > 3)		dprintk("%s, p_ca_message length %d (0x%x)\n", __FUNCTION__,p_ca_message->length,p_ca_message->length );	handle_en50221_tag(state, p_ca_message, hw_buffer);			/*	EN50221 tag		*/	/*	Handle the length field (variable)	*/	if (!(p_ca_message->msg[3] & 0x80)) {				/*	Length = 1		*/		length = p_ca_message->msg[3] & 0x7f;		words = 0;						/*	domi's suggestion	*/	}	else {								/*	Length = words		*/		words = p_ca_message->msg[3] & 0x7f;		for (i = 0; i < words; i++) {			length = length << 8;			length = length | p_ca_message->msg[4 + i];		}	}	if (verbose > 4) {		dprintk("%s:Length=[%d (0x%x)], Words=[%d]\n", __FUNCTION__, length,length, words);		/*	Debug Input string		*/		for (i = 0; i < length; i++)			dprintk(" %02x", p_ca_message->msg[i]);		dprintk("]\n");	}	hw_offset = 7;	buf_offset = words + 4;	/*		Program Header			*/	if (verbose > 4)		dprintk("\n%s:Program Header=[", __FUNCTION__);	for (i = 0; i < 6; i++) {		hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];		if (verbose > 4)			dprintk(" %02x", p_ca_message->msg[buf_offset]);		hw_offset++, buf_offset++, hw_buffer_length++;	}	if (verbose > 4)		dprintk("]\n");	program_info_length = 0;	program_info_length = (((program_info_length | p_ca_message->msg[words + 8]) & 0x0f) << 8) | p_ca_message->msg[words + 9];	if (verbose > 4)		dprintk("%s:Program info Length=[%d][%02x], hw_offset=[%d], buf_offset=[%d] \n",			__FUNCTION__, program_info_length, program_info_length, hw_offset, buf_offset);	if (program_info_length && (program_info_length < 256)) {	/*	If program_info_length		*/		hw_buffer->msg[11] = hw_buffer->msg[11] & 0x0f;		/*	req only 4 bits			*/		hw_buffer->msg[12] = hw_buffer->msg[12] + 1;		/*	increment! ASIC bug!		*/		if (p_ca_message->msg[buf_offset + 1] == 0x09) {	/*	Check CA descriptor		*/			found_prog_ca_desc = 1;			if (verbose > 4)				dprintk("%s: Found CA descriptor @ Program level\n", __FUNCTION__);		}		if (found_prog_ca_desc) {				/*	Command only if CA descriptor	*/			hw_buffer->msg[13] = p_ca_message->msg[buf_offset];	/*	CA PMT command ID	*/			hw_offset++, buf_offset++, hw_buffer_length++;		}		/*			Program descriptors				*/		if (verbose > 4) {			dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);			dprintk("%s:Program descriptors=[", __FUNCTION__);		}		while (program_info_length && !error_condition) {		/*	Copy prog descriptors	*/			if (program_info_length > p_ca_message->length) {	/*	Error situation		*/				dprintk ("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d]\n",								__FUNCTION__, __LINE__, program_info_length);				dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);				error_condition = 1;				break;			}			hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];			dprintk(" %02x", p_ca_message->msg[buf_offset]);			hw_offset++, buf_offset++, hw_buffer_length++, program_info_length--;		}		if (verbose > 4) {			dprintk("]\n");			dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);		}		if (found_prog_ca_desc) {			if (!reply) {				hw_buffer->msg[13] = 0x01;		/*	OK descrambling			*/				if (verbose > 1)					dprintk("CA PMT Command = OK Descrambling\n");			}			else {				hw_buffer->msg[13] = 0x02;		/*	Ok MMI				*/				if (verbose > 1)					dprintk("CA PMT Command = Ok MMI\n");			}			if (query) {				hw_buffer->msg[13] = 0x03;		/*	Query				*/				if (verbose > 1)					dprintk("CA PMT Command = CA PMT query\n");			}		}	}	else {		hw_buffer->msg[11] = hw_buffer->msg[11] & 0xf0;		/*	Don't write to ASIC		*/		hw_buffer->msg[12] = hw_buffer->msg[12] = 0x00;	}	if (verbose > 4)		dprintk("%s:**********>p_ca_message->length=[%d], buf_offset=[%d], hw_offset=[%d]\n",					__FUNCTION__, p_ca_message->length, buf_offset, hw_offset);	while ((buf_offset  < p_ca_message->length)  && !error_condition) {		/*	Bail out in case of an indefinite loop		*/		if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {			dprintk("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d], buf_offset=[%d]\n",							__FUNCTION__, __LINE__, program_info_length, buf_offset);			dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);			error_condition = 1;			break;		}		/*		Stream Header				*/		for (k = 0; k < 5; k++) {			hw_buffer->msg[hw_offset + k] = p_ca_message->msg[buf_offset + k];		}		es_info_length = 0;		es_info_length = (es_info_length | (p_ca_message->msg[buf_offset + 3] & 0x0f)) << 8 | p_ca_message->msg[buf_offset + 4];		if (verbose > 4) {			dprintk("\n%s:----->Stream header=[%02x %02x %02x %02x %02x]\n", __FUNCTION__,				p_ca_message->msg[buf_offset + 0], p_ca_message->msg[buf_offset + 1],				p_ca_message->msg[buf_offset + 2], p_ca_message->msg[buf_offset + 3],				p_ca_message->msg[buf_offset + 4]);			dprintk("%s:----->Stream type=[%02x], es length=[%d (0x%x)], Chars=[%02x] [%02x], buf_offset=[%d]\n", __FUNCTION__,				p_ca_message->msg[buf_offset + 0], es_info_length, es_info_length,				p_ca_message->msg[buf_offset + 3], p_ca_message->msg[buf_offset + 4], buf_offset);		}		hw_buffer->msg[hw_offset + 3] &= 0x0f;			/*	req only 4 bits			*/		if (found_prog_ca_desc) {			hw_buffer->msg[hw_offset + 3] = 0x00;			hw_buffer->msg[hw_offset + 4] = 0x00;		}		hw_offset += 5, buf_offset += 5, hw_buffer_length += 5;		/*		Check for CA descriptor			*/		if (p_ca_message->msg[buf_offset + 1] == 0x09) {			if (verbose > 4)				dprintk("%s:Found CA descriptor @ Stream level\n", __FUNCTION__);			found_stream_ca_desc = 1;		}		/*		ES descriptors				*/		if (es_info_length && !error_condition && !found_prog_ca_desc && found_stream_ca_desc) {//			if (!ca_pmt_done) {				hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];	/*	CA PMT cmd(es)	*/				if (verbose > 4)					printk("%s:----->CA PMT Command ID=[%02x]\n", __FUNCTION__, p_ca_message->msg[buf_offset]);//				hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--, ca_pmt_done = 1;				hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;//			}			if (verbose > 4)				dprintk("%s:----->ES descriptors=[", __FUNCTION__);			while (es_info_length && !error_condition) {	/*	ES descriptors			*/				if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {					if (verbose > 4) {						dprintk("%s:\"WARNING\" ES Length error, line=[%d], es_info_length=[%d], buf_offset=[%d]\n",										__FUNCTION__, __LINE__, es_info_length, buf_offset);						dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);					}					error_condition = 1;					break;				}				hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];				if (verbose > 3)					dprintk("%02x ", hw_buffer->msg[hw_offset]);				hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;			}			found_stream_ca_desc = 0;			/*	unset for new streams		*/			dprintk("]\n");		}	}	/*		MCU Magic words					*/	hw_buffer_length += 7;	hw_buffer->msg[0] = hw_buffer_length;	hw_buffer->msg[1] = 64;	hw_buffer->msg[4] = 3;	hw_buffer->msg[5] = hw_buffer->msg[0] - 7;	hw_buffer->msg[6] = 0;	/*      Fix length      */	hw_buffer->length = hw_buffer->msg[0];	put_checksum(&hw_buffer->msg[0], hw_buffer->msg[0]);	/*      Do the actual write     */	if (verbose > 4) {		dprintk("%s:======================DEBUGGING================================\n", __FUNCTION__);		dprintk("%s: Actual Length=[%d]\n", __FUNCTION__, hw_buffer_length);	}	/*      Only for debugging!     */	if (verbose > 2)		debug_8820_buffer(hw_buffer);	if (verbose > 3)		dprintk("%s: Reply = [%d]\n", __FUNCTION__, reply);	write_to_8820(state, hw_buffer, reply);	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/7d53421c6adce47d067b834c605daeafe1ff9356/dst_ca.c/clean/drivers/media/dvb/bt8xx/dst_ca.c