source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/scte65/ntt/si_ntt_sns.c

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

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