source: svn/newcon3bcm2_21bu/BSEAV/lib/si/a56/ntm/si_ntm_snt.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 11.5 KB
Line 
1/***************************************************************
2**
3** Broadcom Corp. Confidential
4** Copyright 2003-2012 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_ntm_snt.c
12** Description: function that parses the NTM table SNT table
13**                              sections.
14**
15** Created: 03/08/2001
16**                      02/01/2012 modified for A56 support
17**
18** REVISION:
19**
20** $Log: $
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_descriptors.h"
30
31#include "si_ntm_snt.h"
32
33#ifdef MANAGE_SNT
34static SI_NTM_SNT_LINK * SI_NTM_SNT_Create_Link (void);
35static SI_RET_CODE SI_NTM_SNT_Ins_Link(SI_NTM_SNT_LINK *new_snt);
36#endif
37static SI_RET_CODE SI_NTM_SNT_Free_Link(SI_NTM_SNT_LINK *snt);
38
39
40struct NTM_SNT_List_Struct NTM_SNT_List;
41SI_mutex m_ntt_snt;
42static SI_NTM_SNT_Callback_t *s_snt_cb = NULL;
43
44void SI_NTM_SNT_Init(SI_NTM_SNT_Callback_t *cb)
45{
46        SI_LST_D_INIT(&NTM_SNT_List);
47        SI_mutex_init(m_ntt_snt);
48        s_snt_cb = cb;
49}
50
51#ifdef MANAGE_SNT
52/*********************************************************************
53 Function : SI_NTM_SNT_Create_Link
54 Description : Function to allocate the space for an SNT link.
55 Input : none.
56 Output : pointer to the SNT link structure allocated. Will
57                        return NULL if out of memory.
58**********************************************************************/
59static SI_NTM_SNT_LINK * SI_NTM_SNT_Create_Link (void)
60{
61        SI_NTM_SNT_LINK * snt;
62
63        snt = (SI_NTM_SNT_LINK *)SI_alloc(sizeof(SI_NTM_SNT_LINK));
64        if (snt == NULL)
65        {
66                SI_DBG_PRINT(E_SI_ERR_MSG,("Failed to allocate an NTM SNT link!!!\n"));
67                return NULL;
68        }
69
70        SI_LST_D_INIT_ENTRY(&(snt->snt_link));
71        snt->source_name = (unsigned char *)0;
72
73        return snt;
74}
75#endif
76
77/*********************************************************************
78 Function : SI_NTM_SNT_Free_Link
79 Description : Function to free an NTM SNT link from the NTM SNT
80                                list. the link structure will be freed but
81                                not removed from the link list. WE ASSUME THAT WHEN
82                                CALLING THIS FUNCTION, THE LINK HAS NOT BEEN ADDED
83                                TO THE LIST YET!!!
84 Input : SI_NTM_SNT_LINK *snt.  pointer to  NTM SNT link
85                        structure to be freed.
86 Output : SI_RET_CODE.
87**********************************************************************/
88static SI_RET_CODE SI_NTM_SNT_Free_Link(SI_NTM_SNT_LINK *snt)
89{
90        if (snt)
91        {
92                if (snt->source_name)
93                        SI_free(snt->source_name);
94                SI_free(snt);
95        }
96
97        return SI_SUCCESS;
98}
99
100
101/*********************************************************************
102 Function : SI_NTM_SNT_Free_List
103 Description : Function to free the whole NTM SNT list.
104 Input : None.
105 Output : SI_RET_CODE.
106**********************************************************************/
107SI_RET_CODE SI_NTM_SNT_Free_List(void)
108{
109        SI_NTM_SNT_LINK *snt;
110
111        SI_mutex_lock(m_ntt_snt);
112
113        while ((snt = SI_LST_D_FIRST(&NTM_SNT_List)))
114        {
115                SI_LST_D_REMOVE_HEAD(&NTM_SNT_List, snt_link);
116                SI_NTM_SNT_Free_Link(snt);
117        }
118
119        SI_mutex_unlock(m_ntt_snt);
120
121        return SI_SUCCESS;
122}
123
124#ifdef MANAGE_SNT
125/*********************************************************************
126 Function : SI_NTM_SNT_Ins_Link
127 Description : Function to insert an NTM SNT link into the NTM SNT
128                                list. The order is source_ID in incrementing order.
129 Input : SI_NTM_SNT_LINK *new_snt.      pointer to new NTM SNT link
130                        structure to be inserted.
131 Output : SI_RET_CODE.
132**********************************************************************/
133static SI_RET_CODE SI_NTM_SNT_Ins_Link(SI_NTM_SNT_LINK *new_snt)
134{
135        SI_NTM_SNT_LINK * snt;
136        /* unsigned char comp;
137       int      i; */
138
139        SI_mutex_lock(m_ntt_snt);
140
141        snt = SI_LST_D_FIRST(&NTM_SNT_List);
142        /* if the list is empty, just put the new snt link in. */
143        if (snt == NULL)
144        {
145                SI_LST_D_INSERT_HEAD(&NTM_SNT_List, new_snt, snt_link);
146                SI_mutex_unlock(m_ntt_snt);
147                return SI_SUCCESS;
148        }
149
150        /* search for the the place to insert. */
151        while ( (snt->source_ID < new_snt->source_ID) && SI_LST_D_NEXT(snt, snt_link))
152                snt = SI_LST_D_NEXT(snt, snt_link);
153
154        if (snt->source_ID < new_snt->source_ID)
155        {
156                /* we got to the end of list. insert after current element. */
157                SI_LST_D_INSERT_AFTER(snt, new_snt, snt_link);
158        }
159        else if (snt->source_ID > new_snt->source_ID)
160        {
161                /* insert before the current element. */
162                SI_LST_D_INSERT_BEFORE(&NTM_SNT_List, snt, new_snt, snt_link);
163        }
164        else
165        {
166                /* equal! It should only happen when we do not have the revision descriptor,
167                        simply keep the old one and free the new one. */
168                SI_NTM_SNT_Free_Link(new_snt);
169        }
170
171        SI_mutex_unlock(m_ntt_snt);
172
173        return SI_SUCCESS;
174}
175#endif
176/*********************************************************************
177 Function : SI_NTM_SNT_Find_SrcId
178 Description : Function to return name based on Source ID
179 Input : unsigned short source_id: Source Id to match
180         unsigned char *name: channel name
181         int max_len: max channel length
182 Output : if matched return 0; else return -1;.
183**********************************************************************/
184int SI_NTM_SNT_Find_SrcId(unsigned short id, unsigned char *name, int max_len)
185{
186        SI_NTM_SNT_LINK * snt;
187
188        SI_mutex_lock(m_ntt_snt);
189
190        snt = SI_LST_D_FIRST(&NTM_SNT_List);
191        if (snt == NULL)
192        {
193                SI_mutex_unlock(m_ntt_snt);
194                return -1;
195        }
196
197        while ( snt ) {
198                if (snt->source_ID  == id) break;
199                snt = SI_LST_D_NEXT(snt, snt_link);
200        }
201
202        /* TODO::only handle ASCII MTS for the time being*/
203        if (snt == NULL || snt->source_ID != id || snt->source_name[0] != 0) {
204                SI_mutex_unlock(m_ntt_snt);
205                return -1;
206        }
207        if (max_len > snt->source_name[1]) max_len = snt->source_name[1];
208        memcpy(name, &snt->source_name[2], max_len);
209        name[max_len] = 0 ;
210        SI_mutex_unlock(m_ntt_snt);
211        return 0;
212}
213
214
215/*********************************************************************
216 Function : SI_NTM_SNT_Pointer
217 Description : Function to point past newly received NTM SNT table
218                                section inorder to get to table descriptors.
219 Input : unsigned char *table : point to the start of SNT table data.
220 Output : unsigned char * points to the end of SNT record plus 1 which is the
221                                        start of NTM table descriptors.
222**********************************************************************/
223unsigned char * SI_NTM_SNT_Pointer (unsigned char *table)
224{
225        unsigned char num_snt_rec, name_len;
226        unsigned long desc_tag, desc_cnt, len, i, j;
227        unsigned char *current;
228
229        /* get number of SNT records. */
230        num_snt_rec = SI_Construct_Data(table,
231                NTM_SNT_NUM_REC_BYTE_INDX,
232                NTM_SNT_NUM_REC_BYTE_NUM,
233                NTM_SNT_NUM_REC_SHIFT,
234                NTM_SNT_NUM_REC_MASK);
235        SI_DBG_PRINT(E_SI_DBG_MSG,("snt ptr : num of snt %x\n", num_snt_rec));
236
237        current = table + NTM_SNT_NUM_REC_BYTE_INDX + NTM_SNT_NUM_REC_BYTE_NUM;
238
239        /* go through all the SNT records. */
240        for (i=0; i<num_snt_rec; i++)
241        {
242                name_len = SI_Construct_Data(current,
243                        NTM_SNT_NAME_LEN_BYTE_INDX,
244                        NTM_SNT_NAME_LEN_BYTE_NUM,
245                        NTM_SNT_NAME_LEN_SHIFT,
246                        NTM_SNT_NAME_LEN_MASK);
247
248                current += NTM_SNT_NAME_LEN_BYTE_INDX+NTM_SNT_NAME_LEN_BYTE_NUM+name_len;
249
250                desc_cnt = SI_Construct_Data(current,
251                        NTM_SNT_DESC_CNT_BYTE_INDX,
252                        NTM_SNT_DESC_CNT_BYTE_NUM,
253                        NTM_SNT_DESC_CNT_SHIFT,
254                        NTM_SNT_DESC_CNT_MASK);
255
256                current += NTM_SNT_DESC_CNT_BYTE_INDX+NTM_SNT_DESC_CNT_BYTE_NUM;
257
258                /* go through all descriptors. */
259                for (j=0; j<desc_cnt; j++)
260                {
261                        desc_tag = *(current++);
262                        len = *(current++);
263                        /* update current pointer. */
264                        current += len;
265                }
266        }
267
268        return current;
269}
270
271/*********************************************************************
272Function : SI_NTM_SNT_Parse
273Description : Function to parse a newly received NTM SNT table section and
274put it into the NTM SNT link list
275Input : unsigned char *table : point to the start of SNT table data.
276Output : SI_RET_CODE.
277 **********************************************************************/
278SI_RET_CODE SI_NTM_SNT_Parse (unsigned char *table,unsigned int iso639)
279{
280        unsigned long i, j;
281        unsigned char num_snt_rec;
282        unsigned long desc_tag, desc_cnt, len;
283        unsigned char *current;
284#ifdef MANAGE_SNT
285        SI_NTM_SNT_LINK * snt;
286#endif
287        /*SI_RET_CODE result;*/
288
289        SI_DBG_PRINT(E_SI_DBG_MSG,("NTM SNT Table received.\n"));
290
291        /* get number of VC records. */
292        num_snt_rec = SI_Construct_Data(table,
293                NTM_SNT_NUM_REC_BYTE_INDX,
294                NTM_SNT_NUM_REC_BYTE_NUM,
295                NTM_SNT_NUM_REC_SHIFT,
296                NTM_SNT_NUM_REC_MASK);
297        SI_DBG_PRINT(E_SI_DBG_MSG,("NTM SNT num of rec's %x.\n", num_snt_rec));
298
299        current = table + NTM_SNT_NUM_REC_BYTE_INDX + NTM_SNT_NUM_REC_BYTE_NUM;
300
301        /* go through all the SNT records. */
302        for (i=0; i<num_snt_rec; i++)
303        {
304                /* create the snt link struct. */
305#ifdef MANAGE_SNT
306                if ((snt = SI_NTM_SNT_Create_Link()) == NULL)
307                {
308                        SI_DBG_PRINT(E_SI_ERR_MSG,("NTM SNT cannot create link structure!!!\n"));
309                        return SI_NO_MEMORY;
310                }
311
312                snt->appflag = SI_Construct_Data(current,
313                                NTM_SNT_APP_TYPE_BYTE_INDX,
314                                NTM_SNT_APP_TYPE_BYTE_NUM,
315                                NTM_SNT_APP_TYPE_SHIFT,
316                                NTM_SNT_APP_TYPE_MASK);
317                if (snt->appflag)
318                        SI_DBG_PRINT(E_SI_WRN_MSG,("NTM SNT received app entry point!!!\n"));
319
320                snt->source_ID = SI_Construct_Data(current,
321                                NTM_SNT_SOURCE_ID_BYTE_INDX,
322                                NTM_SNT_SOURCE_ID_BYTE_NUM,
323                                NTM_SNT_SOURCE_ID_SHIFT,
324                                NTM_SNT_SOURCE_ID_MASK);
325
326                snt->name_len = SI_Construct_Data(current,
327                                NTM_SNT_NAME_LEN_BYTE_INDX,
328                                NTM_SNT_NAME_LEN_BYTE_NUM,
329                                NTM_SNT_NAME_LEN_SHIFT,
330                                NTM_SNT_NAME_LEN_MASK);
331                snt->source_name = (unsigned char *)SI_alloc(snt->name_len);
332                if (snt->source_name == NULL)
333                {
334                        SI_DBG_PRINT(E_SI_ERR_MSG,("Failed to allocate mem for source name!!!\n"));
335                        return SI_NO_MEMORY;
336                }
337
338                current += NTM_SNT_NAME_LEN_BYTE_INDX+NTM_SNT_NAME_LEN_BYTE_NUM;
339                SI_memcpy(snt->source_name, current, snt->name_len);
340
341                SI_DBG_PRINT(E_SI_DBG_MSG,("NTM SNT appflag %x, source id %x :\n", snt->appflag, snt->source_ID));
342#if 0
343                for (j=0; j<snt->name_len; j++)
344                {
345                        if (j > 1)
346                                SI_DBG_PRINT(E_SI_DBG_MSG,("%c", (char)snt->source_name[j]));
347                }
348                SI_DBG_PRINT(E_SI_DBG_MSG,("\n"));
349#endif
350                current += snt->name_len;
351#else
352                static SI_NTM_SNT_t snt;
353                snt.iso639 = iso639;
354                snt.application_type = SI_Construct_Data(current,
355                                NTM_SNT_APP_TYPE_BYTE_INDX,
356                                NTM_SNT_APP_TYPE_BYTE_NUM,
357                                NTM_SNT_APP_TYPE_SHIFT,
358                                NTM_SNT_APP_TYPE_MASK);
359                if (snt.application_type)
360                        SI_DBG_PRINT(E_SI_WRN_MSG,("NTM SNT received app entry point!!!\n"));
361
362                snt.source_id = SI_Construct_Data(current,
363                                NTM_SNT_SOURCE_ID_BYTE_INDX,
364                                NTM_SNT_SOURCE_ID_BYTE_NUM,
365                                NTM_SNT_SOURCE_ID_SHIFT,
366                                NTM_SNT_SOURCE_ID_MASK);
367
368                snt.name_length = SI_Construct_Data(current,
369                                NTM_SNT_NAME_LEN_BYTE_INDX,
370                                NTM_SNT_NAME_LEN_BYTE_NUM,
371                                NTM_SNT_NAME_LEN_SHIFT,
372                                NTM_SNT_NAME_LEN_MASK);
373
374                current += NTM_SNT_NAME_LEN_BYTE_INDX+NTM_SNT_NAME_LEN_BYTE_NUM;
375                /*if (snt.name_length > SNT_MTT_MAX_LEN)
376                  {
377                  snt.name_length = (unsigned char)SNT_MTT_MAX_LEN;
378                  }*/
379                SI_memcpy(snt.mtt, current, snt.name_length);
380
381                if (s_snt_cb && s_snt_cb->cb)
382                        s_snt_cb->cb(&snt,s_snt_cb->data);
383                current += snt.name_length;
384#endif
385
386                /* get descriptors count. */
387                desc_cnt = SI_Construct_Data(current,
388                                NTM_SNT_DESC_CNT_BYTE_INDX,
389                                NTM_SNT_DESC_CNT_BYTE_NUM,
390                                NTM_SNT_DESC_CNT_SHIFT,
391                                NTM_SNT_DESC_CNT_MASK);
392                current += NTM_SNT_DESC_CNT_BYTE_INDX+NTM_SNT_DESC_CNT_BYTE_NUM;
393
394                /* go through all descriptors. */
395                for (j=0; j<desc_cnt; j++)
396                {
397                        desc_tag = *(current++);
398                        len = *(current++);
399                        switch(desc_tag)
400                        {
401                                default:
402                                        SI_DBG_PRINT(E_SI_WRN_MSG,("NTM SNT table descriptor %x received! Ignoring!\n", desc_tag));
403                                        break;
404                        }
405
406                        /* update current pointer. */
407                        current += len;
408                }
409#ifdef MANAGE_SNT
410
411                /* insert the snt link */
412                SI_NTM_SNT_Ins_Link(snt);
413#endif
414        }
415
416        return SI_SUCCESS;
417}
418
Note: See TracBrowser for help on using the repository browser.