source: svn/newcon3bcm2_21bu/BSEAV/lib/scte65/mgt/si_mgt.c @ 46

Last change on this file since 46 was 46, checked in by megakiss, 11 years ago

459Mhz로 OTC 주파수 변경

  • Property svn:executable set to *
File size: 23.7 KB
Line 
1/***************************************************************
2**
3** Broadcom Corp. Confidential
4** Copyright 2003-2008 Broadcom Corp. All Rights Reserved.
5**
6** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED
7** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM.
8** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT
9** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
10**
11** File:                si_mgt.c
12** Description: function that parses the MGT
13**              table section.
14**
15** Created: 03/08/2001
16**
17** REVISION:
18**
19** $Log: $
20**
21**
22****************************************************************/
23
24#include "si.h"
25#include "si_os.h"
26#include "si_dbg.h"
27#include "si_util.h"
28#include "si_list.h"
29#include "si_aeit.h"
30#include "si_aett.h"
31#include "si_mgt.h"
32#include "si_descriptors.h"
33
34
35/* local function prototypes. */
36static SI_RET_CODE SI_MGT_Upadte_Total_AEIT_NUMBER(unsigned long aeit_n);
37static SI_RET_CODE SI_MGT_Upadte_Total_AETT_NUMBER(unsigned long aett_n);
38static SI_RET_CODE SI_MGT_AEIT_Del_All_Slot(void);
39static SI_RET_CODE SI_MGT_AETT_Del_All_Slot(void);
40static SI_RET_CODE SI_MGT_AEIT_Create_Slot (unsigned char *current, SI_AEIT_SLOT *prev_slot, 
41                        unsigned long table_type, unsigned long version_number, unsigned long table_pid);
42static SI_RET_CODE SI_MGT_AETT_Create_Slot (unsigned char *current, SI_AETT_SLOT *prev_slot, 
43                        unsigned long table_type, unsigned long version_number, unsigned long table_pid);
44static SI_RET_CODE SI_MGT_AEIT_Type_Receive(unsigned char *current, unsigned char aeit_n, unsigned long table_type);
45static SI_RET_CODE SI_MGT_AETT_Type_Receive(unsigned char *current, unsigned char aett_n, unsigned long table_type);
46
47
48struct aeit_slot_list head_aeit_slot, current_aeit0_slot;               /* always point to AEIT-0 */
49struct aett_slot_list head_aett_slot, current_aett0_slot;               /* always point to AETT-0 */
50
51unsigned char MGT_table_version;
52unsigned short past_aeit_n, past_aett_n;  /* total number of slots we keep for the past. */
53unsigned short mgt_aeit_n, mgt_aett_n;  /* total number of slots defined by MGT. */
54
55SI_mutex m_aeit, m_aett;
56
57
58void SI_MGT_Init (void)
59{
60        int i;
61       
62        SI_LST_D_INIT(&current_aeit0_slot);
63        SI_LST_D_INIT(&current_aett0_slot);
64        SI_LST_D_INIT(&head_aeit_slot);
65        SI_LST_D_INIT(&head_aett_slot);
66       
67        MGT_table_version = 0xff;
68
69        past_aeit_n = past_aett_n = 0;
70        mgt_aeit_n = mgt_aett_n = 0;
71        SI_mutex_init(m_aeit);
72        SI_mutex_init(m_aett);
73}
74
75static SI_RET_CODE SI_MGT_Upadte_Total_AEIT_NUMBER(unsigned long aeit_n)
76{
77        SI_AEIT_SLOT * aeit_slot, *temps;
78        int i;
79       
80        if (mgt_aeit_n > aeit_n)
81        {
82                /* if the new number of slots is smaller than current number. I don't know
83                        how possible it is?? */
84                aeit_slot = SI_LST_D_FIRST(&current_aeit0_slot);
85                for (i=0; ((i<aeit_n) && aeit_slot); i++)
86                        aeit_slot = SI_LST_D_NEXT(aeit_slot, slot_link);
87                if (i != aeit_n || aeit_slot == NULL)
88                        return SI_AEIT_LIST_ERROR;
89
90                /* free all the extra slots before. */
91                for (i=aeit_n; i<mgt_aeit_n; i++)
92                {
93                        if (aeit_slot)
94                        {
95                                temps = SI_LST_D_NEXT(aeit_slot, slot_link);
96                                SI_LST_D_REMOVE(&head_aeit_slot, aeit_slot, slot_link);
97                                SI_AEIT_Clear_Slot(aeit_slot);
98                                SI_free(aeit_slot);
99                                aeit_slot = temps;
100                        }
101                }
102               
103        }
104
105        mgt_aeit_n = aeit_n;
106
107        return SI_SUCCESS;
108}
109
110static SI_RET_CODE SI_MGT_Upadte_Total_AETT_NUMBER(unsigned long aett_n)
111{
112        SI_AETT_SLOT * aett_slot, *temps;
113        int i;
114       
115        if (mgt_aett_n > aett_n)
116        {
117                /* if the new number of slots is smaller than current number. I don't know
118                        how possible it is?? */
119                aett_slot = SI_LST_D_FIRST(&current_aett0_slot);
120                for (i=0; ((i<aett_n) && aett_slot); i++)
121                        aett_slot = SI_LST_D_NEXT(aett_slot, slot_link);
122                if (i != aett_n || aett_slot == NULL)
123                        return SI_AETT_LIST_ERROR;
124
125                /* free all the extra slots before. */
126                for (i=aett_n; i<mgt_aett_n; i++)
127                {
128                        if (aett_slot)
129                        {
130                                temps = SI_LST_D_NEXT(aett_slot, slot_link);
131                                SI_LST_D_REMOVE(&head_aett_slot, aett_slot, slot_link);
132                                SI_AETT_Clear_Slot(aett_slot);
133                                SI_free(aett_slot);
134                                aett_slot = temps;
135                        }
136                }
137               
138        }
139
140        mgt_aett_n = aett_n;
141
142        return SI_SUCCESS;
143}
144
145
146static SI_RET_CODE SI_MGT_AEIT_Del_All_Slot(void)
147{
148        SI_AEIT_SLOT * aeit_slot;
149
150        while ((aeit_slot = SI_LST_D_FIRST(&head_aeit_slot)))
151        {
152                SI_LST_D_REMOVE_HEAD(&head_aeit_slot, slot_link);
153                SI_AEIT_Clear_Slot(aeit_slot);
154                SI_free(aeit_slot);
155        }
156
157        SI_LST_D_INIT(&current_aeit0_slot);
158        SI_LST_D_INIT(&head_aeit_slot);
159        past_aeit_n = 0;
160        mgt_aeit_n = 0;
161       
162        return SI_SUCCESS;
163}
164
165static SI_RET_CODE SI_MGT_AETT_Del_All_Slot(void)
166{
167        SI_AETT_SLOT * aett_slot;
168
169        while ((aett_slot = SI_LST_D_FIRST(&head_aett_slot)))
170        {
171                SI_LST_D_REMOVE_HEAD(&head_aett_slot, slot_link);
172                SI_AETT_Clear_Slot(aett_slot);
173                SI_free(aett_slot);
174        }
175
176        SI_LST_D_INIT(&current_aett0_slot);
177        SI_LST_D_INIT(&head_aett_slot);
178        past_aett_n = 0;
179        mgt_aett_n = 0;
180       
181        return SI_SUCCESS;
182}
183
184static SI_RET_CODE SI_MGT_AEIT_Create_Slot (unsigned char *current, SI_AEIT_SLOT *prev_slot, 
185                        unsigned long table_type, unsigned long version_number, unsigned long table_pid)
186{
187        SI_AEIT_SLOT * aeit_slot;
188
189        if ((aeit_slot = SI_AEIT_Create_Slot()) == NULL)
190        {
191                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT failed to create AEIT slot!!!\n"));
192                return SI_NO_MEMORY;
193        }
194       
195        aeit_slot->MGT_tag = (table_type&0xff);
196        aeit_slot->MGT_version_number = version_number;
197        aeit_slot->pid = table_pid;
198
199        if (prev_slot)
200                SI_LST_D_INSERT_AFTER(prev_slot, aeit_slot, slot_link);
201        else
202        {
203                /* in this case the slot list MUST be EMPTY! */
204                /* create the first element in aeit slot list. init head and current aeit0 pointer. */ 
205                SI_LST_D_INSERT_HEAD(&current_aeit0_slot, aeit_slot, slot_link);
206                SI_LST_D_FIRST(&head_aeit_slot) = SI_LST_D_FIRST(&current_aeit0_slot);
207        }
208
209        return SI_SUCCESS;
210}
211
212static SI_RET_CODE SI_MGT_AETT_Create_Slot (unsigned char *current, SI_AETT_SLOT *prev_slot, 
213                        unsigned long table_type, unsigned long version_number, unsigned long table_pid)
214{
215        SI_AETT_SLOT * aett_slot;
216
217        if ((aett_slot = SI_AETT_Create_Slot()) == NULL)
218        {
219                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT failed to create AETT slot!!!\n"));
220                return SI_NO_MEMORY;
221        }
222       
223        aett_slot->MGT_tag = (table_type&0xff);
224        aett_slot->MGT_version_number = version_number;
225        aett_slot->pid = table_pid;
226
227        if (prev_slot)
228                SI_LST_D_INSERT_AFTER(prev_slot, aett_slot, slot_link);
229        else
230        {
231                /* in this case the slot list MUST be EMPTY! */
232                /* create the first element in aett slot list. init head and current aett0 pointer. */ 
233                SI_LST_D_INSERT_HEAD(&current_aett0_slot, aett_slot, slot_link);
234                SI_LST_D_FIRST(&head_aett_slot) = SI_LST_D_FIRST(&current_aett0_slot);
235        }
236
237        return SI_SUCCESS;
238}
239
240/********************************************************************
241 Function : SI_MGT_AEIT_Type_Receive                                                             
242 Description : Function to handle the receiving of AEIT table type
243                                 for MGT table. It will create and                                       
244                                 keep track of AEIT instances.                                           
245 Input : current, point to the current mgt table type data.             
246                   aeit_n: the instance of AEIT type received.                           
247                   tag : the table type of this aeit slot.                                       
248 Output : Success code.                                                                                 
249********************************************************************/
250static SI_RET_CODE SI_MGT_AEIT_Type_Receive(unsigned char *current, unsigned char aeit_n, unsigned long table_type)
251{
252        SI_AEIT_SLOT * aeit_slot, *prev_aeit_slot, *new_aeit_slot;
253        int i, j;
254        unsigned long version_number, table_pid;
255
256        version_number = SI_Construct_Data(current, 
257                        MGT_TABLE_TYPE_VERSION_NUMBER_BYTE_INDX,
258                        MGT_TABLE_TYPE_VERSION_NUMBER_BYTE_NUM,
259                        MGT_TABLE_TYPE_VERSION_NUMBER_SHIFT,
260                        MGT_TABLE_TYPE_VERSION_NUMBER_MASK);
261        table_pid =     SI_Construct_Data(current, 
262                                MGT_TABLE_TYPE_PID_BYTE_INDX,
263                                MGT_TABLE_TYPE_PID_BYTE_NUM,
264                                MGT_TABLE_TYPE_PID_SHIFT,
265                                MGT_TABLE_TYPE_PID_MASK);
266
267        /* find where aeit-n points to. */
268        aeit_slot = SI_LST_D_FIRST(&current_aeit0_slot);
269        if (aeit_slot)
270                prev_aeit_slot = SI_LST_D_PREV(aeit_slot, slot_link);
271        else
272                prev_aeit_slot = NULL;
273        for (i=0; ((i<aeit_n) && aeit_slot); i++)
274        {
275                prev_aeit_slot = aeit_slot;
276                aeit_slot = SI_LST_D_NEXT(aeit_slot, slot_link);
277        }
278
279        /* if the slot does not exist. */
280        if (aeit_slot == NULL)
281                return SI_MGT_AEIT_Create_Slot(current, prev_aeit_slot, table_type, version_number, table_pid);
282
283        /* the slot is already there. */
284        if (aeit_slot->MGT_tag != (table_type&0xff))
285        {
286                /* the slot may have moved. We SHOULD only be able to get here the first time!!! Since
287                        after we moved the first time, everything else should be aligned. */
288                if (aeit_n == 0)
289                {
290                        /* for AEIT-0. */
291                        /* find the MGT_tag down the line that matches the current received one.
292                                should be right after the current slot. */
293                        j=0;
294                        while (aeit_slot->MGT_tag != (table_type&0xff))
295                        {
296                                if (SI_LST_D_NEXT(aeit_slot, slot_link) == NULL)
297                                        break;
298                                j++;
299                                aeit_slot = SI_LST_D_NEXT(aeit_slot, slot_link);
300                        }
301
302                        if (aeit_slot->MGT_tag != (table_type&0xff))
303                        {
304                                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT failed to find AEIT-%d slot!!!\n", aeit_n));
305                                /* we should free everything and start over again. */
306                                SI_MGT_AEIT_Del_All_Slot();
307                                return SI_AEIT_LIST_ERROR;
308                        }
309
310                        if (j>1)
311                        {
312                                /* if the AEIT slot has shifted for more than 1 spot. We should give
313                                        a warning. */
314                                SI_DBG_PRINT(E_SI_WRN_MSG,("MGT AEIT-%d shifted %d slots\n", aeit_n, j));
315                        }
316
317                        /* modify the current_aeit_slot pointer. */
318                        SI_LST_D_FIRST(&current_aeit0_slot) = aeit_slot;
319
320                        /* Check the version and do as needed. */
321                        if (version_number != aeit_slot->MGT_version_number)
322                        {
323                                /* The version number changed. clear the old slot
324                                        and put new data in it. */
325                                SI_AEIT_Clear_Slot(aeit_slot);
326                                aeit_slot->MGT_tag = (table_type&0xff);
327                                aeit_slot->MGT_version_number = version_number;
328                        }
329                        /* always update the pid. */
330                        aeit_slot->pid = table_pid;
331
332                        /* check to see if we need to delete any past AEIT slots. */
333                        past_aeit_n += j;
334                        if (past_aeit_n > MAX_PAST_AEXT_N)
335                        {
336                                for (j=0; ((j<(past_aeit_n-MAX_PAST_AEXT_N)) && ((aeit_slot = SI_LST_D_FIRST(&head_aeit_slot)) != NULL)); j++)
337                                {
338                                        SI_LST_D_REMOVE_HEAD(&head_aeit_slot, slot_link);
339                                        SI_AEIT_Clear_Slot(aeit_slot);
340                                        SI_free(aeit_slot);
341                                }
342                        }
343                }
344                else
345                {
346                        /* for AEIT-n where n>0. should not happen. */
347                        SI_DBG_PRINT(E_SI_ERR_MSG,("MGT AEIT-%d slot does not match new one!!!\n", aeit_n));
348                        /* we should just replace it with the new one */
349                        SI_AEIT_Clear_Slot(aeit_slot);
350                        aeit_slot->MGT_tag = (table_type&0xff);
351                        aeit_slot->MGT_version_number = version_number;
352                        aeit_slot->pid = table_pid;
353                        /* we still want to keep going after this . */
354                }
355        }
356        else  /*if (aeit_slot->MGT_tag == (table_type&0xff))*/
357        {
358                /* the slot has not moved yet. Check the version and do as needed. */
359                if (version_number != aeit_slot->MGT_version_number)
360                {
361                        /* The version number changed. clear the old slot
362                                and put new data in it. */
363                        SI_AEIT_Clear_Slot(aeit_slot);
364                        aeit_slot->MGT_tag = (table_type&0xff);
365                        aeit_slot->MGT_version_number = version_number;
366                }
367                aeit_slot->pid = table_pid; /* always update the pid. */
368        }
369
370
371        return SI_SUCCESS;
372}
373
374/********************************************************************
375 Function : SI_MGT_AETT_Type_Receive                                                             
376 Description : Function to handle the receiving of AETT table type
377                                 for MGT table. It will create and                                       
378                                 keep track of AETT instances.                                           
379 Input : current, point to the current mgt table type data.             
380                   aett_n: the instance of AETT type received.                           
381                   tag : the table type of this aett slot.                                       
382 Output : Success code.                                                                                 
383********************************************************************/
384static SI_RET_CODE SI_MGT_AETT_Type_Receive(unsigned char *current, unsigned char aett_n, unsigned long table_type)
385{
386        SI_AETT_SLOT * aett_slot, *prev_aett_slot, *new_aett_slot;
387        int i, j;
388        unsigned long version_number, table_pid;
389
390        version_number = SI_Construct_Data(current, 
391                        MGT_TABLE_TYPE_VERSION_NUMBER_BYTE_INDX,
392                        MGT_TABLE_TYPE_VERSION_NUMBER_BYTE_NUM,
393                        MGT_TABLE_TYPE_VERSION_NUMBER_SHIFT,
394                        MGT_TABLE_TYPE_VERSION_NUMBER_MASK);
395        table_pid =     SI_Construct_Data(current, 
396                                MGT_TABLE_TYPE_PID_BYTE_INDX,
397                                MGT_TABLE_TYPE_PID_BYTE_NUM,
398                                MGT_TABLE_TYPE_PID_SHIFT,
399                                MGT_TABLE_TYPE_PID_MASK);
400
401        /* find where aett-n points to. */
402        aett_slot = SI_LST_D_FIRST(&current_aett0_slot);
403        if (aett_slot)
404                prev_aett_slot = SI_LST_D_PREV(aett_slot, slot_link);
405        else
406                prev_aett_slot = NULL;
407        for (i=0; ((i<aett_n) && aett_slot); i++)
408        {
409                prev_aett_slot = aett_slot;
410                aett_slot = SI_LST_D_NEXT(aett_slot, slot_link);
411        }
412
413        /* if the slot does not exist. */
414        if (aett_slot == NULL)
415                return SI_MGT_AETT_Create_Slot(current, prev_aett_slot, table_type, version_number, table_pid);
416
417        /* the slot is already there. */
418        if (aett_slot->MGT_tag != (table_type&0xff))
419        {
420                /* the slot may have moved. We SHOULD only be able to get here the first time!!! Since
421                        after we moved the first time, everything else should be aligned. */
422                if (aett_n == 0)
423                {
424                        /* for AETT-0. */
425                        /* find the MGT_tag down the line that matches the current received one.
426                                should be right after the current slot. */
427                        j=0;
428                        while (aett_slot->MGT_tag != (table_type&0xff))
429                        {
430                                if (SI_LST_D_NEXT(aett_slot, slot_link) == NULL)
431                                        break;
432                                j++;
433                                aett_slot = SI_LST_D_NEXT(aett_slot, slot_link);
434                        }
435
436                        if (aett_slot->MGT_tag != (table_type&0xff))
437                        {
438                                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT failed to find AETT-%d slot!!!\n", aett_n));
439                                /* we should free everything and start over again. */
440                                SI_MGT_AETT_Del_All_Slot();
441                                return SI_AETT_LIST_ERROR;
442                        }
443
444                        if (j>1)
445                        {
446                                /* if the AETT slot has shifted for more than 1 spot. We should give
447                                        a warning. */
448                                SI_DBG_PRINT(E_SI_WRN_MSG,("MGT AETT-%d shifted %d slots\n", aett_n, j));
449                        }
450
451                        /* modify the current_aett_slot pointer. */
452                        SI_LST_D_FIRST(&current_aett0_slot) = aett_slot;
453
454                        /* Check the version and do as needed. */
455                        if (version_number != aett_slot->MGT_version_number)
456                        {
457                                /* The version number changed. clear the old slot
458                                        and put new data in it. */
459                                SI_AETT_Clear_Slot(aett_slot);
460                                aett_slot->MGT_tag = (table_type&0xff);
461                                aett_slot->MGT_version_number = version_number;
462                        }
463                        /* always update the pid. */
464                        aett_slot->pid = table_pid;
465
466                        /* check to see if we need to delete any past AETT slots. */
467                        past_aett_n += j;
468                        if (past_aett_n > MAX_PAST_AEXT_N)
469                        {
470                                for (j=0; ((j<(past_aett_n-MAX_PAST_AEXT_N)) && ((aett_slot = SI_LST_D_FIRST(&head_aett_slot)) != NULL)); j++)
471                                {
472                                        SI_LST_D_REMOVE_HEAD(&head_aett_slot, slot_link);
473                                        SI_AETT_Clear_Slot(aett_slot);
474                                        SI_free(aett_slot);
475                                }
476                        }
477                }
478                else
479                {
480                        /* for AETT-n where n>0. It should not happen. */
481                        SI_DBG_PRINT(E_SI_ERR_MSG,("MGT AETT-%d slot does not match new one!!!\n", aett_n));
482                        /* we should just replace it with the new one */
483                        SI_AETT_Clear_Slot(aett_slot);
484                        aett_slot->MGT_tag = (table_type&0xff);
485                        aett_slot->MGT_version_number = version_number;
486                        aett_slot->pid = table_pid;
487                        /* we still want to keep going after this . */
488                }
489        }
490        else /*if (aett_slot->MGT_tag == (table_type&0xff))*/
491        {
492                /* the slot has not moved yet. Check the version and do as needed. */
493                if (version_number != aett_slot->MGT_version_number)
494                {
495                        /* The version number changed. clear the old slot
496                                and put new data in it. */
497                        SI_AETT_Clear_Slot(aett_slot);
498                        aett_slot->MGT_tag = (table_type&0xff);
499                        aett_slot->MGT_version_number = version_number;
500                }
501                aett_slot->pid = table_pid; /* always update the pid. */
502        }
503
504
505        return SI_SUCCESS;
506}
507
508/*********************************************************************/
509/* Function : SI_MGT_parse                                                                                       */
510/* Description : Function to parse the MGT table. It will create and */
511/*                               keep track of AEIT and AETT instances.                          */
512/* Input : mgt_table, point to the mgt table data.                               */
513/* Output : Success code.                                                                                */
514/*********************************************************************/
515SI_RET_CODE SI_MGT_parse (unsigned char * mgt_table)
516{
517        unsigned long temp, i;
518        unsigned long section_length;
519        unsigned long tables_defined, table_type, num_bytes;
520        unsigned long CRC_start;
521        unsigned long desc_start, len;
522        unsigned long desc_tag, desc_len;
523        unsigned char *desc, *current;
524        unsigned char curr_aeit_n, curr_aett_n;
525        SI_RET_CODE result;
526
527        SI_DBG_PRINT(E_SI_DBG_MSG,("MGT Table received.\n"));
528
529        temp = *mgt_table;
530        if (temp != SI_MGT_TABLE_ID)
531        {
532                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table ID error!!! %x\n", temp));
533                return SI_TABLE_ID_ERROR;
534        }
535
536        /* calculate and check section length. */
537        section_length = SI_Construct_Data(mgt_table, 
538                                MGT_SECTION_LENGTH_BYTE_INDX,
539                                MGT_SECTION_LENGTH_BYTE_NUM,
540                                MGT_SECTION_LENGTH_SHIFT,
541                                MGT_SECTION_LENGTH_MASK);
542        section_length += MGT_SECTION_LENGTH_BYTE_INDX+MGT_SECTION_LENGTH_BYTE_NUM;
543        if (section_length > SI_LONG_SECTION_LENGTH)
544        {
545                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table section length error!!! %x\n", section_length));
546                return SI_SECTION_LENGTH_ERROR;
547        }
548       
549        /* We do the CRC check here to verify the contents of this section. */
550        if (SI_CRC32_Check(mgt_table, section_length) != SI_SUCCESS)
551        {
552                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table section CRC error!!!\n"));
553                //return SI_CRC_ERROR;
554        }
555
556        /* check to make sure protocol version is zero. */
557        temp = SI_Construct_Data(mgt_table, 
558                                MGT_PROTOCOL_VERSION_BYTE_INDX,
559                                MGT_PROTOCOL_VERSION_BYTE_NUM,
560                                MGT_PROTOCOL_VERSION_SHIFT,
561                                MGT_PROTOCOL_VERSION_MASK);
562        if (temp != SI_CURRENT_PROTOCOL_VERSION)
563        {
564                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table PROTOCOL version error!!! %x\n", temp));
565                return SI_PROTOCOL_VER_ERROR;
566        }
567       
568        /* make sure that section_number and last_section_number are both 0. */
569        temp = SI_Construct_Data(mgt_table, 
570                                MGT_SECTION_NUMBER_BYTE_INDX,
571                                MGT_SECTION_NUMBER_BYTE_NUM,
572                                MGT_SECTION_NUMBER_SHIFT,
573                                MGT_SECTION_NUMBER_MASK);
574        if (temp != 0)
575        {
576                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table section_number not zero!!! %x\n", temp));
577                return SI_SECTION_NUMBER_ERROR;
578        }
579        temp = SI_Construct_Data(mgt_table, 
580                                MGT_LAST_SECTION_NUMBER_BYTE_INDX,
581                                MGT_LAST_SECTION_NUMBER_BYTE_NUM,
582                                MGT_LAST_SECTION_NUMBER_SHIFT,
583                                MGT_LAST_SECTION_NUMBER_MASK);
584        if (temp != 0)
585        {
586                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table last_section_number not zero!!! %x\n", temp));
587                return SI_SECTION_NUMBER_ERROR;
588        }
589
590        /* look at current_next_indicator. It should be 1 for MGT. */
591        temp = SI_Construct_Data(mgt_table, 
592                                MGT_CURRENT_NEXT_INDICATOR_BYTE_INDX,
593                                MGT_CURRENT_NEXT_INDICATOR_BYTE_NUM,
594                                MGT_CURRENT_NEXT_INDICATOR_SHIFT,
595                                MGT_CURRENT_NEXT_INDICATOR_MASK);
596        if (temp != 1)
597        {
598                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table current_next_indicator not one!!! %x\n", temp));
599                return SI_CURRENT_NEXT_INDICATOR_ERROR;
600        }
601
602        /* Now check the version number and decide whether we want to update or not */
603        temp = SI_Construct_Data(mgt_table, 
604                                MGT_VERSION_NUMBER_BYTE_INDX,
605                                MGT_VERSION_NUMBER_BYTE_NUM,
606                                MGT_VERSION_NUMBER_SHIFT,
607                                MGT_VERSION_NUMBER_MASK);
608        if (MGT_table_version == temp)
609                return SI_SUCCESS; /* do not need to do anything when it is the same version */
610
611        /* new MGT table received!!! */
612        MGT_table_version = temp;
613        SI_DBG_PRINT(E_SI_DBG_MSG,("New MGT Table received!\n"));
614
615        tables_defined = SI_Construct_Data(mgt_table, 
616                                MGT_TABLES_DEFINED_BYTE_INDX,
617                                MGT_TABLES_DEFINED_BYTE_NUM,
618                                MGT_TABLES_DEFINED_SHIFT,
619                                MGT_TABLES_DEFINED_MASK);
620printf("MGT tables define %x\n", tables_defined);
621
622        /* going through all the tables. */
623        current = mgt_table + MGT_TABLES_DEFINED_BYTE_INDX + MGT_TABLES_DEFINED_BYTE_NUM;
624        curr_aeit_n = curr_aett_n = 0;
625        for (i=0; i<tables_defined; i++)
626        {
627                table_type = SI_Construct_Data(current, 
628                                MGT_TABLE_TYPE_BYTE_INDX,
629                                MGT_TABLE_TYPE_BYTE_NUM,
630                                MGT_TABLE_TYPE_SHIFT,
631                                MGT_TABLE_TYPE_MASK);
632                num_bytes = SI_Construct_Data(current, 
633                                MGT_NUMBER_BYTES_BYTE_INDX,
634                                MGT_NUMBER_BYTES_BYTE_NUM,
635                                MGT_NUMBER_BYTES_SHIFT,
636                                MGT_NUMBER_BYTES_MASK);                                 
637                desc_len = SI_Construct_Data(current, 
638                                MGT_TABLE_TYPE_DESC_LENGTH_BYTE_INDX,
639                                MGT_TABLE_TYPE_DESC_LENGTH_BYTE_NUM,
640                                MGT_TABLE_TYPE_DESC_LENGTH_SHIFT,
641                                MGT_TABLE_TYPE_DESC_LENGTH_MASK);
642                               
643                /* check for  AEIT/AETT types. */
644                if (table_type>=MGT_TABLE_TYPE_AEIT_START && table_type<=MGT_TABLE_TYPE_AEIT_END)
645                {
646                        SI_DBG_PRINT(E_SI_DBG_MSG,("MGT: AEIT type received.\n"));
647
648                        /* lock mutex for AEIT table access. */
649                        SI_mutex_lock(m_aeit);
650                       
651                        /* handle the AEIT types. */
652                        result = SI_MGT_AEIT_Type_Receive(current, curr_aeit_n, table_type);
653                        if (result == SI_AEIT_LIST_ERROR)
654                        {
655                                /* error happened, */
656                                /* for AEIT_LIST_ERROR, we already cleared the slot list. Now reprocess it. */
657                                if ((result = SI_MGT_AEIT_Type_Receive(current, curr_aeit_n, table_type)) != SI_SUCCESS)
658                                {
659                                        SI_mutex_unlock(m_aeit);
660                                        return result;
661                                }
662                        }
663                        else if (result != SI_SUCCESS)
664                        {
665                                /*Other errors, we simply return. */
666                                SI_mutex_unlock(m_aeit);
667                                return result;
668                        }
669               
670                        curr_aeit_n++;          /* incrementing current number of AEIT's received. */
671
672                        /* unlock mutex for AEIT table access. */
673                        SI_mutex_unlock(m_aeit);
674                }
675                else if (table_type>=MGT_TABLE_TYPE_AETT_START && table_type<=MGT_TABLE_TYPE_AETT_END)
676                {
677                        SI_DBG_PRINT(E_SI_DBG_MSG,("MGT: AETT type received.\n"));
678
679                        /* lock mutex for AETT table access. */
680                        SI_mutex_lock(m_aett);
681
682                        /* handle the AETT types. */
683                        result = SI_MGT_AETT_Type_Receive(current, curr_aett_n, table_type);
684                        if (result == SI_AETT_LIST_ERROR)
685                        {
686                                /* error happened, */
687                                /* for AETT_LIST_ERROR, we already cleared the slot list. Now reprocess it. */
688                                if ((result = SI_MGT_AETT_Type_Receive(current, curr_aett_n, table_type)) != SI_SUCCESS)
689                                {
690                                        SI_mutex_unlock(m_aett);
691                                        return result;
692                                }
693                        }
694                        else if (result != SI_SUCCESS)
695                        {
696                                /*Other errors, we simply return. */
697                                SI_mutex_unlock(m_aett);
698                                return result;
699                        }
700
701                        curr_aett_n++;          /* incrementing current number of AETT's received. */
702
703                        /* unlock mutex for AETT table access. */
704                        SI_mutex_unlock(m_aett);
705                }
706               
707#if 0   /* I don't knopw what num_bytes are for? */
708                /* for now just handle the AEIT/AETT table type. */
709                if (num_bytes != desc_len + MGT_TABLE_TYPE_DESC_LENGTH_BYTE_NUM)
710                {
711                        SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table type %x, number_bytes = %d, table type descriptor length %d!!!\n", table_type, num_bytes, desc_len));
712                        return SI_SECTION_LENGTH_ERROR;
713                }
714#endif
715
716                /* only handle stuffing descriptors for now. */
717                current += MGT_TABLE_TYPE_DESC_LENGTH_BYTE_INDX+MGT_TABLE_TYPE_DESC_LENGTH_BYTE_NUM;
718                desc_start = 0;
719                while (desc_start < desc_len)
720                {
721                        if ( (desc_tag = *(current++)) != SI_DESC_STUFFING)
722                                SI_DBG_PRINT(E_SI_WRN_MSG,("MGT table type descriptor %x received! Ignoring!\n", desc_tag));
723
724                        len = *(current++); /* desc length. */
725                        current += len;
726                        desc_start += len+2;
727                }
728
729                if (desc_start != desc_len)
730                {
731                        SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table type descriptor length error!!!\n"));
732                        return SI_DESCRIPTOR_ERROR;
733                }
734                               
735        }               /* end of for (i=0; i<tables_defined; i++) */
736
737        /* check for total number of AEIT/AETT-n's received. */
738        SI_mutex_lock(m_aeit);         
739        SI_MGT_Upadte_Total_AEIT_NUMBER (curr_aeit_n);
740        SI_mutex_unlock(m_aeit);               
741
742        SI_mutex_lock(m_aett);         
743        SI_MGT_Upadte_Total_AETT_NUMBER (curr_aett_n);
744        SI_mutex_unlock(m_aett);               
745
746        /* just for fun, go through table desc and make sure the section length works out. */
747        desc_len = SI_Construct_Data(current, 
748                                MGT_DESC_LENGTH_BYTE_INDX,
749                                MGT_DESC_LENGTH_BYTE_NUM,
750                                MGT_DESC_LENGTH_SHIFT,
751                                MGT_DESC_LENGTH_MASK);
752        current += MGT_DESC_LENGTH_BYTE_INDX+MGT_DESC_LENGTH_BYTE_NUM;
753        desc_start = 0;
754        while (desc_start < desc_len)
755        {
756                if ( (desc_tag = *(current++)) != SI_DESC_STUFFING)
757                        SI_DBG_PRINT(E_SI_WRN_MSG,("MGT table descriptor %x received! Ignoring!\n", desc_tag));
758
759                len = *(current++); /* desc length. */
760                current += len;
761                desc_start += len+2;
762        }
763
764        if (desc_start != desc_len)
765        {
766                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table descriptor length error!!!\n"));
767                return SI_DESCRIPTOR_ERROR;
768        }
769
770        if (current+SI_CRC_LENGTH != (mgt_table + section_length))
771        {
772                SI_DBG_PRINT(E_SI_ERR_MSG,("MGT Table length error!!!\n"));
773                return SI_SECTION_LENGTH_ERROR;
774        }
775
776        return SI_SUCCESS;
777}
Note: See TracBrowser for help on using the repository browser.