source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/scte65/ea/si_ea.c

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

first commit

  • Property svn:executable set to *
File size: 12.0 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_ea.c
12** Description: function that parses the EA message
13**
14** Created: 03/08/2001
15**
16** REVISION:
17**
18** $Log: $
19**
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_ea.h"
28#include "si_api_ea.h"
29#include "si_descriptors.h"
30
31static unsigned char ea_sequence_number, ea_flags = 0;
32
33
34EA_MSG_INFO             ea_msg;
35
36#define EA_FLAGS_SEQ_NUM_VALID          0x01
37#define EA_FLAGS_EVENT_ID_VALID         0x02
38
39void SI_EA_Init (void)
40{
41}
42
43/*********************************************************************
44 Function : SI_EA_GetEventTime                                                                                   
45 Description : Function to get event start time and duration
46 Input : p_ea_start_time - pointer to store start time
47       : p_ea_duration   - pointer to store duration
48 Output : none.
49**********************************************************************/
50void SI_EA_GetEventTime (unsigned long *p_ea_start_time, unsigned short *p_ea_duration)
51{
52        *p_ea_start_time = ea_msg.ea_event_start_time;
53        *p_ea_duration = ea_msg.ea_event_duration;
54}
55
56/*********************************************************************
57 Function : SI_EA_GetEventTime                                                                                   
58 Description : Callback function when an event expires
59 Input : none.
60 Output : none.
61**********************************************************************/
62void SI_EA_EventExpirationCb (void)
63{
64        ea_flags &= ~EA_FLAGS_EVENT_ID_VALID;
65}
66
67/*********************************************************************
68 Function : SI_EA_parse                                                                                 
69 Description : Function to parse the EA message
70 Input : ea_table, point to the EA message data
71 Output : Success code.                                                                                 
72**********************************************************************/
73SI_RET_CODE SI_EA_Parse (unsigned char * ea_table)
74{
75        int                             i;
76        unsigned char   temp, eas_event_code_length, nature_of_act_text_length;
77        unsigned short  temp16;
78        unsigned short  ea_alert_text_length, ea_descriptors_length;
79        unsigned long   temp32, ea_byte_index;
80        unsigned long   section_length;
81
82        SI_DBG_PRINT(E_SI_DBG_MSG,("EA Message received.\n"));
83
84        ea_msg.process = 1;
85
86        temp = *ea_table;
87        if (temp != SI_EA_TABLE_ID)
88        {
89                ea_msg.process = 0;
90                SI_DBG_PRINT(E_SI_ERR_MSG,("EA Table ID error!!! %x\n", temp));
91                return SI_TABLE_ID_ERROR;
92        }
93
94        /*
95         * Get section length
96         */
97        section_length = SI_Construct_Data(ea_table, 
98                                EA_SECTION_LENGTH_BYTE_INDX,
99                                EA_SECTION_LENGTH_BYTE_NUM,
100                                EA_SECTION_LENGTH_SHIFT,
101                                EA_SECTION_LENGTH_MASK);
102        section_length += EA_SECTION_LENGTH_BYTE_INDX+EA_SECTION_LENGTH_BYTE_NUM;
103        if (section_length > SI_NORMAL_SECTION_LENGTH)
104        {
105                ea_msg.process = 0;
106                SI_DBG_PRINT(E_SI_ERR_MSG,("EA Table section length error!!! %x\n", section_length));
107                return SI_SECTION_LENGTH_ERROR;
108        }
109        SI_DBG_PRINT(E_SI_DBG_MSG,("EA Table section length = %d\n", section_length));
110
111#if 0
112printf("Data:");
113for (i=0; i < section_length; i++)
114{
115        if (!(i & 0x0f)) printf("\n");
116        printf("%02x ", ea_table[i]);
117}
118printf("\n");
119#endif
120       
121        /*
122         * Check table id extension
123         */
124        temp = SI_Construct_Data(ea_table, 
125                                EA_TABLE_ID_EXTENSION_BYTE_INDX,
126                                EA_TABLE_ID_EXTENSION_BYTE_NUM,
127                                EA_TABLE_ID_EXTENSION_SHIFT,
128                                EA_TABLE_ID_EXTENSION_MASK);
129        if (temp != 0)
130        {
131                ea_msg.process = 0;
132                SI_DBG_PRINT(E_SI_ERR_MSG,("EA Table ID extension error!!! %x\n", temp));
133                return SI_TABLE_ID_ERROR;
134        }
135
136        /*
137         * Check protocol version
138         */
139        temp = SI_Construct_Data(ea_table, 
140                                EA_PROTOCOL_VERSION_BYTE_INDX,
141                                EA_PROTOCOL_VERSION_BYTE_NUM,
142                                EA_PROTOCOL_VERSION_SHIFT,
143                                EA_PROTOCOL_VERSION_MASK);
144        if (temp != 0)                          /* only support protocol version 0 */
145        {
146                ea_msg.process = 0;
147                SI_DBG_PRINT(E_SI_ERR_MSG,("EA Table PROTOCOL version error!!! %x\n", temp));
148                return SI_PROTOCOL_VER_ERROR;
149        }
150
151        /*
152         * Get sequence number
153         */
154        temp32 = SI_Construct_Data(ea_table, 
155                                                EA_SEQUENCE_NUMBER_BYTE_INDX,
156                                                EA_SEQUENCE_NUMBER_BYTE_NUM,
157                                                EA_SEQUENCE_NUMBER_SHIFT,
158                                                EA_SEQUENCE_NUMBER_MASK);
159
160        if ((ea_flags & EA_FLAGS_SEQ_NUM_VALID) && (temp32 == ea_sequence_number))
161        {
162                ea_msg.process = 0;
163                SI_DBG_PRINT(E_SI_ERR_MSG,("Duplicate sequence number %x, discarding message\n", temp32));
164                return SI_SUCCESS;
165        }
166
167        ea_flags |= EA_FLAGS_SEQ_NUM_VALID;
168        ea_sequence_number = temp32;
169        SI_DBG_PRINT(E_SI_DBG_MSG,("EA Table sequence number = %x\n", ea_sequence_number));
170
171        /*
172         * Get Event ID
173         */
174        temp16 = SI_Construct_Data(ea_table, 
175                                                EA_EAS_EVENT_ID_BYTE_INDX,
176                                                EA_EAS_EVENT_ID_BYTE_NUM,
177                                                EA_EAS_EVENT_ID_SHIFT,
178                                                EA_EAS_EVENT_ID_MASK);
179        if ((ea_flags & EA_FLAGS_EVENT_ID_VALID) && (temp32 == ea_msg.eas_event_id))
180        {
181                ea_msg.process = 0;
182                SI_DBG_PRINT(E_SI_ERR_MSG,("Duplicate event id %x, discarding message\n", temp16));
183                return SI_SUCCESS;
184        }
185
186        ea_flags |= EA_FLAGS_EVENT_ID_VALID;
187        ea_msg.eas_event_id = temp16;
188        SI_DBG_PRINT(E_SI_DBG_MSG,("EA event id = %x\n", ea_msg.eas_event_id));
189
190        /*
191         * Get EAS originator code
192         */
193        ea_msg.eas_originator_code[0] = ea_table[EA_EAS_ORIGINATOR_CODE_BYTE_INDX];
194        ea_msg.eas_originator_code[1] = ea_table[EA_EAS_ORIGINATOR_CODE_BYTE_INDX + 1];
195        ea_msg.eas_originator_code[2] = ea_table[EA_EAS_ORIGINATOR_CODE_BYTE_INDX + 2];
196        ea_msg.eas_originator_code[3] = (char)NULL;
197        SI_DBG_PRINT(E_SI_DBG_MSG,("EAS originator code = %s\n", ea_msg.eas_originator_code));
198
199        /*
200         * Get EAS event code
201         */
202        eas_event_code_length = SI_Construct_Data(ea_table, 
203                                                EA_EAS_EVENT_CODE_LENGTH_BYTE_INDX,
204                                                EA_EAS_EVENT_CODE_LENGTH_BYTE_NUM,
205                                                EA_EAS_EVENT_CODE_LENGTH_SHIFT,
206                                                EA_EAS_EVENT_CODE_LENGTH_MASK);
207
208        /*
209         * Get EAS event code
210         */
211        for (i=0; i < eas_event_code_length; i++)
212                ea_msg.eas_event_code[i] = ea_table[EA_EAS_EVENT_CODE_BYTE_INDX + i];
213        ea_msg.eas_event_code[i] = (char)NULL;
214        SI_DBG_PRINT(E_SI_DBG_MSG,("EAS event code = %s\n", ea_msg.eas_event_code));
215
216        ea_byte_index = EA_EAS_EVENT_CODE_BYTE_INDX + eas_event_code_length;
217        SI_DBG_PRINT(E_SI_DBG_MSG,("EA byte index = %d\n", ea_byte_index));
218
219        /*
220         * Get nature of activation text fields
221         */
222        nature_of_act_text_length = ea_table[ea_byte_index++];
223        SI_DBG_PRINT(E_SI_DBG_MSG,("Nature of activation text length = %d\n", nature_of_act_text_length));
224        if (nature_of_act_text_length)
225        {       
226                SI_DBG_PRINT(E_SI_DBG_MSG,("Nature of activation text = "));
227                for (i=0; i < nature_of_act_text_length; i++)
228                {
229                        ea_msg.nature_of_act_text[i] = ea_table[ea_byte_index++];
230                        SI_DBG_PRINT(E_SI_DBG_MSG,("%c", ea_msg.nature_of_act_text[i]));
231                }
232                SI_DBG_PRINT(E_SI_DBG_MSG,("\n"));
233                ea_msg.nature_of_act_text[i] = (char)NULL;
234        }
235        else
236                ea_msg.nature_of_act_text[0] = (char)NULL;
237
238        /*
239         * Alert message time remaining
240         */
241        ea_msg.ea_alert_message_time_rem = ea_table[ea_byte_index++];
242        SI_DBG_PRINT(E_SI_DBG_MSG,("Alert message time remaining = %d\n", ea_msg.ea_alert_message_time_rem));
243
244        /*
245         * Event start time
246         */
247        ea_msg.ea_event_start_time = SI_Construct_Data(ea_table, ea_byte_index, 4, 0, 0xffffffff);
248        SI_DBG_PRINT(E_SI_DBG_MSG,("Event start time = %x\n", ea_msg.ea_event_start_time));
249        ea_byte_index += 4;
250
251        /*
252         * Event duration
253         */
254        ea_msg.ea_event_duration = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0xffff);
255        SI_DBG_PRINT(E_SI_DBG_MSG,("Event duration = %x\n", ea_msg.ea_event_duration));
256        ea_byte_index += 2;
257
258        /*
259         * Alert priority
260         */
261        ea_msg.ea_alert_priority = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x000f);
262        SI_DBG_PRINT(E_SI_DBG_MSG,("Alert priority = %x\n", ea_msg.ea_alert_priority));
263        ea_byte_index += 2;
264
265        /*
266         * Details OOB source ID
267         */
268        ea_msg.ea_details_oob_source_id = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0xffff);
269        SI_DBG_PRINT(E_SI_DBG_MSG,("Details OOB source id = %x\n", ea_msg.ea_details_oob_source_id));
270        ea_byte_index += 2;
271
272        /*
273         * Details major channel number
274         */
275        ea_msg.ea_details_major_chan_number = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x03ff);
276        SI_DBG_PRINT(E_SI_DBG_MSG,("Details major channel number = %x\n", ea_msg.ea_details_major_chan_number));
277        ea_byte_index += 2;
278
279        /*
280         * Details minor channel number
281         */
282        ea_msg.ea_details_minor_chan_number = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x03ff);
283        SI_DBG_PRINT(E_SI_DBG_MSG,("Details minor channel number = %x\n", ea_msg.ea_details_minor_chan_number));
284        ea_byte_index += 2;
285
286        /*
287         * Audio OOB source id
288         */
289        ea_msg.ea_audio_oob_source_id = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0xffff);
290        SI_DBG_PRINT(E_SI_DBG_MSG,("Audio OOB source id = %x\n", ea_msg.ea_audio_oob_source_id));
291        ea_byte_index += 2;
292
293        /*
294         * Alert text length, alert text
295         */
296        ea_alert_text_length = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0xffff);
297        SI_DBG_PRINT(E_SI_DBG_MSG,("Alert text length = %x\n", ea_alert_text_length));
298        ea_byte_index += 2;
299        if (ea_alert_text_length)
300        {       
301                SI_DBG_PRINT(E_SI_DBG_MSG,("EA alert text = "));
302                for (i=0; i < ea_alert_text_length; i++)
303                {
304                        ea_msg.ea_alert_text[i] = ea_table[ea_byte_index++];
305                        SI_DBG_PRINT(E_SI_DBG_MSG,("%c", ea_msg.ea_alert_text[i]));
306                }
307                SI_DBG_PRINT(E_SI_DBG_MSG,("\n"));
308                ea_msg.ea_alert_text[i] = (char)NULL;
309        }
310        else
311                ea_msg.ea_alert_text[0] = (char)NULL;
312
313        /*
314         * Location code
315         */
316        ea_msg.ea_location_code_count = SI_Construct_Data(ea_table, ea_byte_index, 1, 0, 0xff);
317        SI_DBG_PRINT(E_SI_DBG_MSG,("Location code count = %x\n", ea_msg.ea_location_code_count));
318        ea_byte_index++;
319
320        if (ea_msg.ea_location_code_count)
321        {
322                /* Get location codes */
323                for (i=0; i < ea_msg.ea_location_code_count; i++)
324                {
325                        ea_msg.ea_location_code[i].state_code = SI_Construct_Data(ea_table, ea_byte_index, 1, 0, 0xff);
326                        ea_byte_index++;
327                        ea_msg.ea_location_code[i].county_subdevision = SI_Construct_Data(ea_table, ea_byte_index, 1, 4, 0x0f);
328                        ea_msg.ea_location_code[i].county_code = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x03ff);
329                        ea_byte_index += 2;
330                        SI_DBG_PRINT(E_SI_DBG_MSG,("  Location code %d state_code = %x\n", i, ea_msg.ea_location_code[i].state_code));
331                        SI_DBG_PRINT(E_SI_DBG_MSG,("  Location code %d county_subdevision = %x\n", i, ea_msg.ea_location_code[i].county_subdevision));
332                        SI_DBG_PRINT(E_SI_DBG_MSG,("  Location code %d county_code = %x\n", i, ea_msg.ea_location_code[i].county_code));
333                }
334        }
335
336        /*
337         * Exceptions
338         */
339        ea_msg.ea_exception_count = SI_Construct_Data(ea_table, ea_byte_index, 1, 0, 0xff);
340        SI_DBG_PRINT(E_SI_DBG_MSG,("Exception count = %x\n", ea_msg.ea_exception_count));
341        ea_byte_index++;
342        if (ea_msg.ea_exception_count)
343        {
344                temp = SI_Construct_Data(ea_table, ea_byte_index, 1, 0, 0xff);
345                ea_byte_index++;
346                if (temp & 0x80)                        /* if inband reference */
347                {
348                        for (i=0; i < ea_msg.ea_exception_count; i++)
349                        {
350                                ea_msg.ea_exception_major_chan_no[i] = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x03ff);
351                                ea_byte_index += 2;
352                                ea_msg.ea_exception_minor_chan_no[i] = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x03ff);
353                                ea_byte_index += 2;
354                        }
355                }
356                else                                            /* out of band */
357                {
358                        for (i=0; i < ea_msg.ea_exception_count; i++)
359                        {
360                                ea_byte_index += 2;
361                                ea_msg.ea_exception_oob_source_id[i] = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0xffff);
362                                ea_byte_index += 2;
363                        }
364                }
365        }
366
367        /*
368         * Descriptors
369         */
370        ea_descriptors_length = SI_Construct_Data(ea_table, ea_byte_index, 2, 0, 0x03ff);
371        SI_DBG_PRINT(E_SI_DBG_MSG,("Descriptors length = %x\n", ea_descriptors_length));
372        ea_byte_index += 2;
373        if (ea_descriptors_length)
374        {
375                unsigned char   desc_tag, desc_length;
376                unsigned long   company_id;
377
378                desc_tag = ea_table[ea_byte_index++];
379                if (desc_tag >= 0xc0)
380                {
381                        /*
382                         * User private descriptor
383                         */
384                        desc_length = ea_table[ea_byte_index++];
385                        company_id = SI_Construct_Data(ea_table, ea_byte_index, 3, 0, 0xffffff);
386                        ea_byte_index += 3;
387                        for (i=0; i < desc_length; i++)
388                        {
389                                /* private data */
390                        }
391                }
392                else
393                {
394                        /*
395                         * Standard descriptor
396                         */
397                }
398        }
399
400        /*
401         * Call application callback to let them know an EA message has been received
402         */
403        EA_message_received_cb(&ea_msg);
404
405        return SI_SUCCESS;
406}
407
Note: See TracBrowser for help on using the repository browser.