| 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_stt.c |
|---|
| 12 | ** Description: function that parses the STT |
|---|
| 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_stt.h" |
|---|
| 29 | #include "si_descriptors.h" |
|---|
| 30 | |
|---|
| 31 | #ifdef INTEGRATE_WITH_BCM_SETTOP_API |
|---|
| 32 | extern void POD_Update_Systime(unsigned long t); |
|---|
| 33 | #endif |
|---|
| 34 | unsigned long SI_UTC_Time; |
|---|
| 35 | unsigned long SI_GPS_UTC_OFFSET; |
|---|
| 36 | unsigned char SI_DS_status; |
|---|
| 37 | unsigned char SI_DS_day_of_month; |
|---|
| 38 | unsigned char SI_DS_hour; |
|---|
| 39 | |
|---|
| 40 | void SI_STT_Init (void) |
|---|
| 41 | { |
|---|
| 42 | SI_UTC_Time = 0; |
|---|
| 43 | SI_GPS_UTC_OFFSET = 0; |
|---|
| 44 | SI_DS_status = 0; |
|---|
| 45 | SI_DS_day_of_month = 0; |
|---|
| 46 | SI_DS_hour = 0; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /********************************************************************* |
|---|
| 50 | Function : SI_STT_Get_Sys_Time |
|---|
| 51 | Description : Function get the current the system |
|---|
| 52 | UTC time. |
|---|
| 53 | Input : None. |
|---|
| 54 | Output : current system time. |
|---|
| 55 | **********************************************************************/ |
|---|
| 56 | unsigned long SI_STT_Get_Sys_Time (void) |
|---|
| 57 | { |
|---|
| 58 | return SI_UTC_Time; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /********************************************************************* |
|---|
| 62 | Function : SI_STT_Get_GPS_UTC_Offset |
|---|
| 63 | Description : Function get the current the system |
|---|
| 64 | GPS UTC offset. |
|---|
| 65 | Input : None. |
|---|
| 66 | Output : current system time. |
|---|
| 67 | **********************************************************************/ |
|---|
| 68 | unsigned long SI_STT_Get_GPS_UTC_Offset (void) |
|---|
| 69 | { |
|---|
| 70 | return SI_GPS_UTC_OFFSET; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /********************************************************************* |
|---|
| 74 | Function : SI_STT_Conv_To_UTC_Time |
|---|
| 75 | Description : Function get convert the GPS time to the system |
|---|
| 76 | UTC time. |
|---|
| 77 | Input : unsigned long time: GPS_time. |
|---|
| 78 | Output : converted to UTC time. |
|---|
| 79 | **********************************************************************/ |
|---|
| 80 | unsigned long SI_STT_Conv_To_UTC_Time (unsigned long time) |
|---|
| 81 | { |
|---|
| 82 | return (time - SI_GPS_UTC_OFFSET); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | /********************************************************************* |
|---|
| 87 | Function : SI_STT_parse |
|---|
| 88 | Description : Function to parse the STT table and set the system |
|---|
| 89 | UTC time. |
|---|
| 90 | Input : stt_table, point to the STT table data. |
|---|
| 91 | Output : Success code. |
|---|
| 92 | **********************************************************************/ |
|---|
| 93 | SI_RET_CODE SI_STT_parse (unsigned char * stt_table) |
|---|
| 94 | { |
|---|
| 95 | unsigned char temp; |
|---|
| 96 | unsigned long section_length; |
|---|
| 97 | unsigned long CRC_start; |
|---|
| 98 | unsigned long desc_start = STT_GPS_UTC_OFFSET_BYTE_INDX+STT_GPS_UTC_OFFSET_BYTE_NUM; |
|---|
| 99 | unsigned long desc_tag, desc_len; |
|---|
| 100 | unsigned char *desc; |
|---|
| 101 | |
|---|
| 102 | SI_DBG_PRINT(E_SI_DBG_MSG,("STT Table received.\n")); |
|---|
| 103 | |
|---|
| 104 | temp = *stt_table; |
|---|
| 105 | if (temp != SI_STT_TABLE_ID) |
|---|
| 106 | { |
|---|
| 107 | SI_DBG_PRINT(E_SI_ERR_MSG,("STT Table ID error!!! %x\n", temp)); |
|---|
| 108 | return SI_TABLE_ID_ERROR; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | section_length = SI_Construct_Data(stt_table, |
|---|
| 112 | STT_SECTION_LENGTH_BYTE_INDX, |
|---|
| 113 | STT_SECTION_LENGTH_BYTE_NUM, |
|---|
| 114 | STT_SECTION_LENGTH_SHIFT, |
|---|
| 115 | STT_SECTION_LENGTH_MASK); |
|---|
| 116 | section_length += STT_SECTION_LENGTH_BYTE_INDX+STT_SECTION_LENGTH_BYTE_NUM; |
|---|
| 117 | if (section_length > SI_NORMAL_SECTION_LENGTH) |
|---|
| 118 | { |
|---|
| 119 | SI_DBG_PRINT(E_SI_ERR_MSG,("STT Table section length error!!! %x\n", section_length)); |
|---|
| 120 | return SI_SECTION_LENGTH_ERROR; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /* We do the CRC check here to verify the contents of this section. */ |
|---|
| 124 | if (SI_CRC32_Check(stt_table, section_length) != SI_SUCCESS) |
|---|
| 125 | { |
|---|
| 126 | SI_DBG_PRINT(E_SI_ERR_MSG,("STT Table section CRC error!!!\n")); |
|---|
| 127 | return SI_CRC_ERROR; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | /* check to make sure protocol version is zero. */ |
|---|
| 131 | temp = SI_Construct_Data(stt_table, |
|---|
| 132 | STT_PROTOCOL_VERSION_BYTE_INDX, |
|---|
| 133 | STT_PROTOCOL_VERSION_BYTE_NUM, |
|---|
| 134 | STT_PROTOCOL_VERSION_SHIFT, |
|---|
| 135 | STT_PROTOCOL_VERSION_MASK); |
|---|
| 136 | if (temp != SI_CURRENT_PROTOCOL_VERSION) |
|---|
| 137 | { |
|---|
| 138 | SI_DBG_PRINT(E_SI_ERR_MSG,("STT Table PROTOCOL version error!!! %x\n", temp)); |
|---|
| 139 | return SI_PROTOCOL_VER_ERROR; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | CRC_start = section_length-SI_CRC_LENGTH; |
|---|
| 143 | |
|---|
| 144 | SI_UTC_Time = SI_Construct_Data(stt_table, |
|---|
| 145 | STT_SYSTEM_TIME_BYTE_INDX, |
|---|
| 146 | STT_SYSTEM_TIME_BYTE_NUM, |
|---|
| 147 | STT_SYSTEM_TIME_SHIFT, |
|---|
| 148 | STT_SYSTEM_TIME_MASK); |
|---|
| 149 | SI_GPS_UTC_OFFSET = SI_Construct_Data(stt_table, |
|---|
| 150 | STT_GPS_UTC_OFFSET_BYTE_INDX, |
|---|
| 151 | STT_GPS_UTC_OFFSET_BYTE_NUM, |
|---|
| 152 | STT_GPS_UTC_OFFSET_SHIFT, |
|---|
| 153 | STT_GPS_UTC_OFFSET_MASK); |
|---|
| 154 | SI_UTC_Time -= SI_GPS_UTC_OFFSET; |
|---|
| 155 | |
|---|
| 156 | SI_DBG_PRINT(E_SI_DBG_MSG,("STT UTC time %x, GPS UTC offset %x.\n", SI_UTC_Time, SI_GPS_UTC_OFFSET)); |
|---|
| 157 | |
|---|
| 158 | #ifdef INTEGRATE_WITH_BCM_SETTOP_API |
|---|
| 159 | POD_Update_Systime(SI_UTC_Time); |
|---|
| 160 | #endif |
|---|
| 161 | |
|---|
| 162 | /* Now let's worry about descriptors. */ |
|---|
| 163 | while (desc_start < CRC_start) |
|---|
| 164 | { |
|---|
| 165 | desc = (stt_table + desc_start); |
|---|
| 166 | desc_tag = desc[0]; |
|---|
| 167 | desc_len = desc[1]; |
|---|
| 168 | switch (desc_tag) |
|---|
| 169 | { |
|---|
| 170 | case SI_DESC_DAYLIGHT_SAVINGS_TIME: |
|---|
| 171 | SI_DS_status = SI_Construct_Data(desc, |
|---|
| 172 | DESC_DST_DS_STATUS_BYTE_INDEX, |
|---|
| 173 | DESC_DST_DS_STATUS_BYTE_NUM, |
|---|
| 174 | DESC_DST_DS_STATUS_SHIFT, |
|---|
| 175 | DESC_DST_DS_STATUS_MASK); |
|---|
| 176 | SI_DS_day_of_month = SI_Construct_Data(desc, |
|---|
| 177 | DESC_DST_DS_DAY_BYTE_INDEX, |
|---|
| 178 | DESC_DST_DS_DAY_BYTE_NUM, |
|---|
| 179 | DESC_DST_DS_DAY_SHIFT, |
|---|
| 180 | DESC_DST_DS_DAY_MASK); |
|---|
| 181 | SI_DS_hour = SI_Construct_Data(desc, |
|---|
| 182 | DESC_DST_DS_HOUR_BYTE_INDEX, |
|---|
| 183 | DESC_DST_DS_HOUR_BYTE_NUM, |
|---|
| 184 | DESC_DST_DS_HOUR_SHIFT, |
|---|
| 185 | DESC_DST_DS_HOUR_MASK); |
|---|
| 186 | |
|---|
| 187 | SI_DBG_PRINT(E_SI_DBG_MSG,("STT Table have DS descriptor: Status %d, day %d, hr %d.\n", SI_DS_status, SI_DS_day_of_month, SI_DS_hour)); |
|---|
| 188 | break; |
|---|
| 189 | |
|---|
| 190 | case SI_DESC_STUFFING: |
|---|
| 191 | SI_DBG_PRINT(E_SI_DBG_MSG,("STT Table have stuffing descriptor.\n")); |
|---|
| 192 | break; |
|---|
| 193 | |
|---|
| 194 | default: |
|---|
| 195 | if (desc_tag >= SI_DESC_USER_PRIVATE) |
|---|
| 196 | { |
|---|
| 197 | SI_DBG_PRINT(E_SI_WRN_MSG,("STT Table have user private descriptor. And we don't know what to do with it.\n")); |
|---|
| 198 | } |
|---|
| 199 | else |
|---|
| 200 | { |
|---|
| 201 | SI_DBG_PRINT(E_SI_ERR_MSG,("STT Table have bad descriptor %x!\n", desc_tag)); |
|---|
| 202 | return SI_DESCRIPTOR_ERROR; |
|---|
| 203 | } |
|---|
| 204 | break; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | desc_start += desc_len+2; /* plus the tag and length. */ |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | if (desc_start != CRC_start) |
|---|
| 211 | { |
|---|
| 212 | SI_DBG_PRINT(E_SI_ERR_MSG,("STT Table descriptor length error!\n")); |
|---|
| 213 | return SI_DESCRIPTOR_ERROR; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | return SI_SUCCESS; |
|---|
| 217 | } |
|---|
| 218 | |
|---|