| 1 | /** |
|---|
| 2 | @file |
|---|
| 3 | DLIB_SDDS_Parser.c |
|---|
| 4 | |
|---|
| 5 | @brief |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | ////#include <string.h> |
|---|
| 9 | |
|---|
| 10 | #include "DHL_DBG.h" |
|---|
| 11 | |
|---|
| 12 | #include "DLIB_BitOp.h" |
|---|
| 13 | |
|---|
| 14 | #include "DLIB_SDDS.h" |
|---|
| 15 | #include "DLIB_SDDS_Parser.h" |
|---|
| 16 | #include "DLIB_PSI_Parser.h" |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #if COMMENT |
|---|
| 22 | ____Config____(){} |
|---|
| 23 | #endif |
|---|
| 24 | |
|---|
| 25 | #if SUPPORT_DST_PLATFORM |
|---|
| 26 | #define MEM_LIMIT 0x00008000 /* BK: 0x00004000 16k => 0x00008000 32k*/ |
|---|
| 27 | #else |
|---|
| 28 | #define MEM_LIMIT 0x00004000 /* 16k */ |
|---|
| 29 | #endif |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | #define DEBUG_MODE 0 |
|---|
| 33 | // °³¹ß Áß¿¡ µµ¿òÀÌ µÉ ¸¸ÇÑ Á¤º¸ Ç¥½Ã.. |
|---|
| 34 | // ¾ç»ê SW¿¡¼´Â 0À¸·Î ÇÏ´Â °ÍÀÌ ¾ÈÀüÇÔ. |
|---|
| 35 | |
|---|
| 36 | #define DEBUG_CRC_RECHECK 1 |
|---|
| 37 | // ÀÌ SDDS ¸ðµâ ³»¿¡¼ SWÀûÀ¸·Î ´Ù½Ã crc Àç°è»ê.. |
|---|
| 38 | // ¸¸¾à DHL ·¹º§¿¡¼ SW recalc ·çƾÀÌ ÀÖ´Ù¸é ¿©±â¼ ÇÒ ÇÊ¿ä ¾øÀ½. |
|---|
| 39 | // HW filter µ¿ÀÛÀÌ ¿Ïº®ÇÏ´Ù¸é üũ ºÒÇÊ¿ä. |
|---|
| 40 | // EMMA3 °³¹ß Áß¿¡¸¸ »ç¿ëÇϱâ·Î ÇÔ. |
|---|
| 41 | // ¾ç»ê SW¿¡¼´Â ºÒÇÊ¿äÇÑ ÄÚµåÀÓ. |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | #define SHOW_LOCAL_TIME 1 |
|---|
| 45 | // 1À̸é GPS ½Ã°£ Ç¥½Ã ºÎºÐÀ» local time Çü½ÄÀ¸·Î º¸¿©ÁØ´Ù. |
|---|
| 46 | // º°µµÀÇ ¿ÜºÎ library°¡ ÇÊ¿äÇÔ. |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | #if COMMENT |
|---|
| 51 | ____Types____(){} |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | #if COMMENT |
|---|
| 57 | ____Macro____(){} |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | #ifndef min |
|---|
| 62 | #define min(a,b) ((a)<(b)?(a):(b)) |
|---|
| 63 | #endif |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | #define get_table_id(p) (p[0]) |
|---|
| 67 | #define get_section_syntax_indicator(p) (p[1] >> 7) |
|---|
| 68 | #define get_private_indicator(p) ((p[1] >> 6) & 0x1) |
|---|
| 69 | #define get_section_length(p) (((p[1] & 0x0F) << 8) | p[2]) |
|---|
| 70 | |
|---|
| 71 | #define get_16(p) (((p)[0]<<8U) | (p)[1]) |
|---|
| 72 | #define get_32(p) (((p)[0]<<24UL) | ((p)[1]<<16UL) | ((p)[2]<<8UL) | (p)[3]) |
|---|
| 73 | |
|---|
| 74 | #define checkMemoryError(p) if (p == NULL) {err = DHL_FAIL_OUT_OF_MEMORY; goto ParseExit;} |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | #define READ4(p) ( \ |
|---|
| 78 | (((UINT8 *)(p))[0]<<24UL) | \ |
|---|
| 79 | (((UINT8 *)(p))[1]<<16UL) | \ |
|---|
| 80 | (((UINT8 *)(p))[2]<<8UL) | \ |
|---|
| 81 | (((UINT8 *)(p))[3]) ) |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | #if COMMENT |
|---|
| 85 | ____Variables____(){} |
|---|
| 86 | #endif |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | #if COMMENT |
|---|
| 92 | ____Util____(){} |
|---|
| 93 | #endif |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | /* µð½ºÅ©¸³ÅÍ ¸®½ºÆ® Áß¿¡¼ ƯÁ¤ µð½ºÅ©¸³Å͸¦ ã¾Æ Æ÷ÀÎÅ͸¦ ¸®ÅÏÇÑ´Ù. |
|---|
| 97 | ¾øÀ¸¸é NULLÀ» ¸®ÅÏ. |
|---|
| 98 | ÃÖÃÊ·Î ¹ß°ßµÇ´Â ÇÑ °³¸¸ ¸®ÅÏ. |
|---|
| 99 | */ |
|---|
| 100 | UINT8 *find_desc (UINT8 *descriptors, UINT16 len, UINT8 tag) |
|---|
| 101 | { |
|---|
| 102 | UINT8 *p; // running pointer |
|---|
| 103 | UINT8 descriptor_length; |
|---|
| 104 | |
|---|
| 105 | p = descriptors; |
|---|
| 106 | while (p < descriptors + len) { |
|---|
| 107 | if (*p == tag) { |
|---|
| 108 | /* check for length error */ |
|---|
| 109 | descriptor_length = p[1]; |
|---|
| 110 | if ((p + descriptor_length + 2) <= (descriptors + len)) { |
|---|
| 111 | return p; |
|---|
| 112 | } |
|---|
| 113 | return NULL; // ¹ß°ßÀº µÇ¾úÀ¸³ª Çã¿ë ¿µ¿ªÀ» ³Ñ¾î¼¹À¸¹Ç·Î ½ÇÆÐ. |
|---|
| 114 | } |
|---|
| 115 | p++; /* skip tag */ |
|---|
| 116 | descriptor_length = *p++; |
|---|
| 117 | p += descriptor_length; |
|---|
| 118 | } |
|---|
| 119 | return NULL; // ¹ß°ßµÇÁö ¾Ê¾ÒÀ½. |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | #if DEBUG_CRC_RECHECK |
|---|
| 125 | // todo |
|---|
| 126 | // CRC ·çƾÀ» º°µµÀÇ ´Ù¸¥ DLIB ¶óÀ̺귯¸®·Î °ü¸®Çϸé ÁÁ°ÚÀ½. |
|---|
| 127 | |
|---|
| 128 | static UINT32 crc_tbl[256]; |
|---|
| 129 | #define DEMUX_CRC_ADDER_MASK 0x04C11DB7 /* As defined in MPEG-2 CRC */ |
|---|
| 130 | |
|---|
| 131 | static void init_crc32(void) |
|---|
| 132 | { |
|---|
| 133 | UINT32 crc; |
|---|
| 134 | INT32 i, j; |
|---|
| 135 | |
|---|
| 136 | if (crc_tbl[0] || crc_tbl[1]) return; |
|---|
| 137 | |
|---|
| 138 | DHL_OS_Printf("init crc32..\n"); |
|---|
| 139 | // Initialize CRC table |
|---|
| 140 | for (i=0; i<256; i++) { |
|---|
| 141 | crc = 0; |
|---|
| 142 | for (j=7; j>=0; j--) { |
|---|
| 143 | if (((i >> j) ^ (crc >> 31)) & 1) |
|---|
| 144 | crc=(crc<<1)^DEMUX_CRC_ADDER_MASK; |
|---|
| 145 | else |
|---|
| 146 | crc<<=1; |
|---|
| 147 | } |
|---|
| 148 | crc_tbl[i] = crc; |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | static UINT32 calc_crc32(UINT32 crc_start, const UINT8 *data, UINT32 len) |
|---|
| 153 | { |
|---|
| 154 | UINT32 crc = crc_start; |
|---|
| 155 | UINT32 i; |
|---|
| 156 | |
|---|
| 157 | if (crc_tbl[1] == 0) |
|---|
| 158 | init_crc32(); |
|---|
| 159 | |
|---|
| 160 | for (i = 0; i < len; ++i) |
|---|
| 161 | crc = (crc << 8) ^ crc_tbl[(crc >> 24) ^ (*data++)]; |
|---|
| 162 | |
|---|
| 163 | return (crc); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | /* |
|---|
| 167 | c¾ð¾î¿¡¼´Â 32-bit addÀÇ carry¸¦ ¾Ë ¼ö ¾øÀ¸¹Ç·Î ³ª´²¼ °è»ê.. |
|---|
| 168 | |
|---|
| 169 | uuuuuuuu dddddddd n1 |
|---|
| 170 | uuuuuuuu dddddddd n2 |
|---|
| 171 | |
|---|
| 172 | 1´Ü°è: Lower 16-bit addition |
|---|
| 173 | dddddddd n1 low |
|---|
| 174 | dddddddd (+ n2 low |
|---|
| 175 | ------------------- |
|---|
| 176 | u dddddddd a1 |
|---|
| 177 | 2´Ü°è: Upper 16-bit addition |
|---|
| 178 | uuuuuuuu n1 high |
|---|
| 179 | uuuuuuuu n2 high |
|---|
| 180 | u (+ a1 high |
|---|
| 181 | ---------- |
|---|
| 182 | u dddddddd a2 |
|---|
| 183 | 3´Ü°è: compose with carry add back |
|---|
| 184 | dddddddd a1 low |
|---|
| 185 | dddddddd a2 low->high shift |
|---|
| 186 | u (+ a2 carry |
|---|
| 187 | ------------------- |
|---|
| 188 | ******** ******** a3 |
|---|
| 189 | */ |
|---|
| 190 | |
|---|
| 191 | static UINT32 ones_complement_add(UINT32 d1, UINT32 d2) |
|---|
| 192 | { |
|---|
| 193 | UINT32 a1, a2, a3; |
|---|
| 194 | |
|---|
| 195 | a1 = (d1 & 0xffff) + (d2 & 0xffff); |
|---|
| 196 | a2 = ((d1>>16)) + ((d2>>16)) + (a1>>16); |
|---|
| 197 | a3 = (a1 & 0xffff) + ((a2<<16)) + (a2>>16); |
|---|
| 198 | |
|---|
| 199 | return a3; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | /* |
|---|
| 203 | byte streamÀ» uint32 Á¤¼öÀÇ ¿¬¼ÓÀ¸·Î °£ÁÖÇÑ´Ù. |
|---|
| 204 | lenÀÌ 4 alignÀÌ ¾ÈµÇ¾î ÀÖ´Â °æ¿ì´Â 0x00 padding ÇÑ´Ù. (°è»ê½Ã¿¡¸¸ padding) |
|---|
| 205 | */ |
|---|
| 206 | static UINT32 calc_ckecksum(const UINT8 *buf, UINT32 len) |
|---|
| 207 | { |
|---|
| 208 | int i; |
|---|
| 209 | UINT32 checksum;//, data; |
|---|
| 210 | |
|---|
| 211 | checksum = 0; |
|---|
| 212 | for (i=0; i<len; i+=4) { |
|---|
| 213 | checksum = ones_complement_add(checksum, READ4(&buf[i])); |
|---|
| 214 | } |
|---|
| 215 | if (len & 3) { // ¸Ç ¸¶Áö¸· Â¥Åõ¸®°¡ ´õÇØÁöÁö ¾Ê¾ÒÀ½ |
|---|
| 216 | UINT8 pad[4] = {0, }; |
|---|
| 217 | memcpy(pad, buf+(len & ~3), len & 3); |
|---|
| 218 | checksum = ones_complement_add(checksum, READ4(pad)); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | // take one's complement of result |
|---|
| 222 | checksum = 0xffffffff ^ checksum; |
|---|
| 223 | |
|---|
| 224 | // this can be done in caller's side, but we also do.. |
|---|
| 225 | return checksum ? checksum : 0xffffffff; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | #endif // DEBUG_CRC_RECHECK |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | #if COMMENT |
|---|
| 233 | ____Parse____(){} |
|---|
| 234 | #endif |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | DHL_RESULT ParseCompatDesc(bitBufferPtr_t bitsOrg, memId_t memId, sddsCompatDesc_t *compat) |
|---|
| 239 | { |
|---|
| 240 | int i, k, n; |
|---|
| 241 | UINT32 data; |
|---|
| 242 | bitBuffer_t tBits, *bits = &tBits; |
|---|
| 243 | DHL_RESULT err = DHL_OK; |
|---|
| 244 | |
|---|
| 245 | data = bitBufferGetBits(bitsOrg,16); // compatibilityDescriptorLength |
|---|
| 246 | if (data == 0) return DHL_OK; |
|---|
| 247 | // length°¡ 0À̸é ÀÌÈÄÀÇ parsingÀº ºÒÇÊ¿äÇÏ´Ù. |
|---|
| 248 | |
|---|
| 249 | // »õ·Î¿î bitbuffer¸¦ ¸¸µé¾î¼ »ç¿ëÇϵµ·Ï ÇÏÀÚ. |
|---|
| 250 | // ±× ÀÌÀ¯´Â ¿ì¸®´Â compat descriptor¸¦ ÃÖ´ë 2°³ ¸¸ parsing ÇÒ °ÍÀ̱⠶§¹®.. |
|---|
| 251 | bitBufferInitialize(bits,bitBufferGetBytePointer(bitsOrg),data); |
|---|
| 252 | |
|---|
| 253 | // ¿øº» bitbuffer advance.. |
|---|
| 254 | for (i=0; i<data; i++) |
|---|
| 255 | bitBufferSkipBits(bitsOrg, 8); |
|---|
| 256 | |
|---|
| 257 | // »çº» bitbuffer·Î parsing.. |
|---|
| 258 | compat->descriptorCount = bitBufferGetBits(bits,16); // descriptorCount |
|---|
| 259 | |
|---|
| 260 | // 2°³ ¸¸ parsing Çϵµ·Ï ÇÑ´Ù. |
|---|
| 261 | for (i=0; i<min(2, compat->descriptorCount); i++) |
|---|
| 262 | { |
|---|
| 263 | sddsCompatDescEntry_t *d = &compat->desc[i]; |
|---|
| 264 | d->descriptorType = bitBufferGetBits(bits,8); // descriptorType |
|---|
| 265 | #if DEBUG_MODE |
|---|
| 266 | // todo.. |
|---|
| 267 | // ÀÌ descriptor length °ª°ú, ½ÇÁ¦·Î ¾Æ·¡¿¡¼ parsing ÇÏ¸é¼ »ç¿ëµÈ byte Å©±â°¡ |
|---|
| 268 | // ÀÏÄ¡ÇÏ´ÂÁö üũ ÈÄ µð¹ö±× Ãâ·Â. |
|---|
| 269 | #endif |
|---|
| 270 | bitBufferSkipBits(bits,8); // descriptorLength |
|---|
| 271 | |
|---|
| 272 | d->specifierType = bitBufferGetBits(bits,8); // specifierType |
|---|
| 273 | d->specifierData = bitBufferGetBits(bits,24); // specifierData |
|---|
| 274 | |
|---|
| 275 | d->model = bitBufferGetBits(bits,16); // model |
|---|
| 276 | d->version = bitBufferGetBits(bits,16); // version |
|---|
| 277 | |
|---|
| 278 | d->subDescriptorCount = bitBufferGetBits(bits,8); // subDescriptorCount |
|---|
| 279 | if (d->subDescriptorCount > 0) { |
|---|
| 280 | d->subDescriptors = (sddsCompatSubDesc_t *)memChainAlloc(memId,d->subDescriptorCount*sizeof(sddsCompatSubDesc_t)); |
|---|
| 281 | checkMemoryError(d->subDescriptors); |
|---|
| 282 | } |
|---|
| 283 | for (k=0; k<d->subDescriptorCount; k++) { |
|---|
| 284 | sddsCompatSubDesc_t *sd = &d->subDescriptors[k]; |
|---|
| 285 | sd->subDescriptorType = bitBufferGetBits(bits,8); |
|---|
| 286 | sd->subDescriptorLength = bitBufferGetBits(bits,8); |
|---|
| 287 | if (sd->subDescriptorLength > 0) { |
|---|
| 288 | sd->additionalInformation = (UINT8 *)memChainAlloc(memId,sd->subDescriptorLength); |
|---|
| 289 | checkMemoryError(sd->additionalInformation); |
|---|
| 290 | } |
|---|
| 291 | for (n=0; n<sd->subDescriptorLength; n++) |
|---|
| 292 | sd->additionalInformation[n] = bitBufferGetBits(bits,8); |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | ParseExit: |
|---|
| 297 | return err; |
|---|
| 298 | |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | /* |
|---|
| 302 | dii ModuleInfo descriptorÀÇ private data bytes ¿µ¿ªÀÇ Á¤º¸¿¡ Æ÷ÇԵǴ |
|---|
| 303 | descriptorÀÌ´Ù. |
|---|
| 304 | */ |
|---|
| 305 | DHL_RESULT ParseDstModuleInfoDesc(UINT8 *p, int len, sddsDstModuleInfoDesc_t *di) |
|---|
| 306 | { |
|---|
| 307 | int err = 0; |
|---|
| 308 | int len1=0, len2=0, len3=0; |
|---|
| 309 | |
|---|
| 310 | memset(di, 0, sizeof(sddsDstModuleInfoDesc_t)); |
|---|
| 311 | |
|---|
| 312 | if (len >= 1) |
|---|
| 313 | di->moduleType = p[0]; |
|---|
| 314 | |
|---|
| 315 | if (len >= 2) |
|---|
| 316 | //di->moduleNameLen = |
|---|
| 317 | len1 = p[1]; |
|---|
| 318 | |
|---|
| 319 | if (len >= 2+len1) |
|---|
| 320 | //di->moduleName = &p[2]; |
|---|
| 321 | memcpy(di->moduleName, &p[2], min(len1, sizeof(di->moduleName)-1)); |
|---|
| 322 | else { |
|---|
| 323 | //di->moduleNameLen = 0; |
|---|
| 324 | err = -1; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | if (len >= 2+len1+1) |
|---|
| 328 | //di->moduleVerLen = |
|---|
| 329 | len2 = p[2+len1]; |
|---|
| 330 | |
|---|
| 331 | if (len >= 2+len1+1+len2) |
|---|
| 332 | //di->moduleVer = &p[2+len1+1]; |
|---|
| 333 | memcpy(di->moduleVer, &p[2+len1+1], min(len2, sizeof(di->moduleVer)-1)); |
|---|
| 334 | else { |
|---|
| 335 | //di->moduleVerLen = 0; |
|---|
| 336 | err = -1; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | if (len >= 2+len1+1+len2+1) |
|---|
| 340 | di->numSupportedHwVersions = len3 = p[2+len1+1+len2]; |
|---|
| 341 | |
|---|
| 342 | if (len >= 2+len1+1+len2+1+len3) |
|---|
| 343 | di->supportedHwVersions = &p[2+len1+1+len2+1]; |
|---|
| 344 | else { |
|---|
| 345 | di->numSupportedHwVersions = 0; |
|---|
| 346 | err = -1; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | if (len >= 2+len1+1+len2+1+len3+4) |
|---|
| 350 | di->fileCRC32 = READ4(&p[2+len1+1+len2+1+len3]); |
|---|
| 351 | else { |
|---|
| 352 | err = -1; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | return err ? DHL_FAIL : DHL_OK; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | DHL_RESULT ParseModuleInfoDesc(memId_t memId, UINT8 *p, sddsModuleInfoDesc_t **descripPtr) |
|---|
| 359 | { |
|---|
| 360 | bitBuffer_t tBits; |
|---|
| 361 | bitBufferPtr_t bits = &tBits; |
|---|
| 362 | //memId_t memId; |
|---|
| 363 | //memChainSetup_t memSetup = {MEM_LIMIT,NULL,NULL}; |
|---|
| 364 | UINT8 length; |
|---|
| 365 | // INT32 count; |
|---|
| 366 | INT32 i; |
|---|
| 367 | DHL_RESULT err; |
|---|
| 368 | |
|---|
| 369 | sddsModuleInfoDesc_t *mi; |
|---|
| 370 | |
|---|
| 371 | DHL_ASSERT((p != NULL), "ParseModuleInfoDesc():bad parameter"); |
|---|
| 372 | DHL_ASSERT((*p == SDDS_module_info_tag), "Bad descriptor tag.\n"); |
|---|
| 373 | |
|---|
| 374 | length = p[1]; |
|---|
| 375 | |
|---|
| 376 | /* initialize the bitBuffer */ |
|---|
| 377 | bitBufferInitialize(bits,p+2,length); |
|---|
| 378 | |
|---|
| 379 | /* alloc the descriptor memory */ |
|---|
| 380 | mi = (sddsModuleInfoDesc_t *)memChainAlloc(memId,sizeof(sddsModuleInfoDesc_t)); |
|---|
| 381 | checkMemoryError(mi); |
|---|
| 382 | |
|---|
| 383 | /* parse the descriptor */ |
|---|
| 384 | mi->encoding = bitBufferGetBits(bits, 8); /* encoding */ |
|---|
| 385 | mi->nameLength = bitBufferGetBits(bits, 8); /* nameLength */ |
|---|
| 386 | if (mi->nameLength > 0) { |
|---|
| 387 | // alloc extra null-term. 0 character space. |
|---|
| 388 | mi->nameBytes = (UINT8 *)memChainAlloc(memId,(mi->nameLength+1)*sizeof(UINT8)); |
|---|
| 389 | checkMemoryError(mi->nameBytes); |
|---|
| 390 | |
|---|
| 391 | for (i=0; i<mi->nameLength; i++) |
|---|
| 392 | mi->nameBytes[i] = bitBufferGetBits(bits,8); |
|---|
| 393 | mi->nameBytes[mi->nameLength] = 0; // null terminate |
|---|
| 394 | } |
|---|
| 395 | mi->signatureType = bitBufferGetBits(bits, 8); |
|---|
| 396 | mi->signatureLength = bitBufferGetBits(bits, 8); |
|---|
| 397 | if (mi->signatureLength > 0) { |
|---|
| 398 | mi->signatureBytes = (UINT8 *)memChainAlloc(memId,(mi->signatureLength)*sizeof(UINT8)); |
|---|
| 399 | checkMemoryError(mi->signatureBytes); |
|---|
| 400 | |
|---|
| 401 | for (i=0; i<mi->signatureLength; i++) |
|---|
| 402 | mi->signatureBytes[i] = bitBufferGetBits(bits,8); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | mi->privateModuleLength = bitBufferGetBits(bits, 8); |
|---|
| 406 | if (mi->privateModuleLength > 0) { |
|---|
| 407 | mi->privateModuleBytes = (UINT8 *)memChainAlloc(memId,(mi->privateModuleLength)*sizeof(UINT8)); |
|---|
| 408 | checkMemoryError(mi->privateModuleBytes); |
|---|
| 409 | |
|---|
| 410 | for (i=0; i<mi->privateModuleLength; i++) |
|---|
| 411 | mi->privateModuleBytes[i] = bitBufferGetBits(bits,8); |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | #if SUPPORT_SDDS_DST_EXTENSION |
|---|
| 415 | if (1) { |
|---|
| 416 | int len = mi->privateModuleLength; |
|---|
| 417 | UINT8 *p = mi->privateModuleBytes; |
|---|
| 418 | UINT8 *p_end = p + len; |
|---|
| 419 | |
|---|
| 420 | while (p && p+2 <= p_end) { |
|---|
| 421 | //p[0] // descriptor_tag |
|---|
| 422 | //p[1] // descriptor_len |
|---|
| 423 | |
|---|
| 424 | if (p[0] == SDDS_DST_module_info_tag) { |
|---|
| 425 | err = ParseDstModuleInfoDesc(&p[2], p[1], &mi->dstinfo); |
|---|
| 426 | if (err) { |
|---|
| 427 | DHL_OS_Printf("!! parse dst module info desc err, len %u\n", p[1]); |
|---|
| 428 | //if (dprintable(2)) |
|---|
| 429 | memdump(&p[0], p[1]+2, "dst mi desc"); |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | else { // unknown descriptor |
|---|
| 433 | DHL_OS_Printf("!! unknown module info private desc, tag %02x, len %u\n", p[0], p[1]); |
|---|
| 434 | //if (dprintable(2)) |
|---|
| 435 | memdump(&p[0], p[1]+2, "unknown desc"); |
|---|
| 436 | } |
|---|
| 437 | p += 2 + p[1]; // go to next descriptor |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | #endif |
|---|
| 441 | |
|---|
| 442 | *descripPtr = mi; |
|---|
| 443 | err = DHL_OK; |
|---|
| 444 | |
|---|
| 445 | ParseExit: |
|---|
| 446 | |
|---|
| 447 | return (err); |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | void DLIB_SDDS_FreeSection (void *sectionPtr) |
|---|
| 453 | { |
|---|
| 454 | if (sectionPtr == NULL) { |
|---|
| 455 | return; |
|---|
| 456 | } |
|---|
| 457 | memChainDestroy(*(((memId_t *)sectionPtr)-1)); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | DHL_RESULT DLIB_SDDS_ParseDsiSection (UINT8 *section, sddsDsiPtr_t *ppDsi) |
|---|
| 461 | { |
|---|
| 462 | sddsDsiPtr_t dsi = NULL; |
|---|
| 463 | memChainSetup_t memSetup = {MEM_LIMIT,NULL,NULL}; |
|---|
| 464 | memId_t memId = NULL; |
|---|
| 465 | bitBuffer_t tBits, *bits = &tBits; |
|---|
| 466 | DHL_RESULT err = DHL_OK; |
|---|
| 467 | |
|---|
| 468 | char *name = "dsi"; |
|---|
| 469 | int i, iGroup; |
|---|
| 470 | UINT32 tmp; |
|---|
| 471 | UINT16 section_length; |
|---|
| 472 | UINT8 adaptationLength; |
|---|
| 473 | UINT8 *p; |
|---|
| 474 | |
|---|
| 475 | #if DEBUG_MODE |
|---|
| 476 | UINT16 table_id_extension, messageLength, privateDataLength; |
|---|
| 477 | UINT8 *ptr0, *ptr1; |
|---|
| 478 | #endif |
|---|
| 479 | |
|---|
| 480 | if (section == NULL) { |
|---|
| 481 | DHL_OS_Printf("%s: null ptr\n", name); |
|---|
| 482 | #if DEBUG_MODE |
|---|
| 483 | DHL_ASSERT(FALSE, ""); |
|---|
| 484 | #endif |
|---|
| 485 | err = DHL_FAIL_INVALID_PARAM; |
|---|
| 486 | goto ParseExit; |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | if (get_table_id(section) != SDDS_Table_ID_Msg) { |
|---|
| 490 | DHL_OS_Printf("%s: invalid table_id\n", name); |
|---|
| 491 | #if DEBUG_MODE |
|---|
| 492 | DHL_ASSERT(FALSE, ""); |
|---|
| 493 | #endif |
|---|
| 494 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 495 | goto ParseExit; |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | #if DEBUG_MODE |
|---|
| 499 | tmp = get_section_syntax_indicator(section); |
|---|
| 500 | if (get_private_indicator(section) == tmp) |
|---|
| 501 | DHL_OS_Printf("%s: private_indicator not complement of ssi\n", name); |
|---|
| 502 | #endif |
|---|
| 503 | |
|---|
| 504 | section_length = get_section_length(section); |
|---|
| 505 | if (section_length > 4093) { |
|---|
| 506 | DHL_OS_Printf("%s: section_length %d\n", name, section_length); |
|---|
| 507 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 508 | goto ParseExit; |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | bitBufferInitialize(bits,section+3,section_length); |
|---|
| 512 | |
|---|
| 513 | /* create the memChain */ |
|---|
| 514 | err = memChainCreate(&memId,&memSetup); |
|---|
| 515 | if (err) { |
|---|
| 516 | goto ParseExit; |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | /* allocate memory for dsiSection + memId */ |
|---|
| 520 | dsi = (sddsDsiPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(sddsDsi_t)+sizeof(memId_t))) + 1); |
|---|
| 521 | checkMemoryError(dsi); |
|---|
| 522 | |
|---|
| 523 | dsi->section_syntax_indicator = get_section_syntax_indicator(section); |
|---|
| 524 | |
|---|
| 525 | #if DEBUG_MODE |
|---|
| 526 | table_id_extension = bitBufferGetBits(bits,16); |
|---|
| 527 | #else |
|---|
| 528 | bitBufferSkipBits(bits,16); |
|---|
| 529 | #endif |
|---|
| 530 | |
|---|
| 531 | #if DEBUG_MODE |
|---|
| 532 | bitBufferSkipBits(bits,2); // reserved |
|---|
| 533 | tmp = bitBufferGetBits(bits,5); // version_number |
|---|
| 534 | if (tmp != 0) |
|---|
| 535 | DHL_OS_Printf("%s: version_number %d != 0\n", name, tmp); |
|---|
| 536 | |
|---|
| 537 | tmp = bitBufferGetBits(bits,1); // current_next_indicator |
|---|
| 538 | if (tmp != 1) |
|---|
| 539 | DHL_OS_Printf("%s: current_next_indicator != 1\n", name); |
|---|
| 540 | |
|---|
| 541 | tmp = bitBufferGetBits(bits,8); // section_number |
|---|
| 542 | if (tmp != 0x00) |
|---|
| 543 | DHL_OS_Printf("%s: section_number %x != 0x00\n", name, tmp); |
|---|
| 544 | |
|---|
| 545 | tmp = bitBufferGetBits(bits,8); // last_section_number |
|---|
| 546 | if (tmp != 0x00) |
|---|
| 547 | DHL_OS_Printf("%s: last_section_number %x != 0x00\n", name, tmp); |
|---|
| 548 | |
|---|
| 549 | tmp = bitBufferGetBits(bits,8); // protocolDiscriminator |
|---|
| 550 | if (tmp != 0x11) |
|---|
| 551 | DHL_OS_Printf("%s: protocolDiscriminator %x != 0x11\n", name, tmp); |
|---|
| 552 | |
|---|
| 553 | tmp = bitBufferGetBits(bits,8); // dsmccType |
|---|
| 554 | if (tmp != 0x03) |
|---|
| 555 | DHL_OS_Printf("%s: dsmccType %x != 0x03\n", name, tmp); |
|---|
| 556 | #else |
|---|
| 557 | bitBufferSkipBits(bits, 32); |
|---|
| 558 | bitBufferSkipBits(bits, 8); |
|---|
| 559 | #endif |
|---|
| 560 | |
|---|
| 561 | tmp = bitBufferGetBits(bits,16); // messageId |
|---|
| 562 | if (tmp != SDDS_Message_ID_DSI) { // 0x1006 |
|---|
| 563 | DHL_OS_Printf("%s: messageId %x != 0x1006\n", name, tmp); |
|---|
| 564 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 565 | goto ParseExit; |
|---|
| 566 | } |
|---|
| 567 | dsi->transactionId = bitBufferGetBits(bits,32); // transactionId |
|---|
| 568 | #if DEBUG_MODE |
|---|
| 569 | if (table_id_extension != (dsi->transactionId & 0xffff)) { |
|---|
| 570 | DHL_OS_Printf("%s: tidex %x != trid %x\n", name, table_id_extension, dsi->transactionId); |
|---|
| 571 | } |
|---|
| 572 | #endif |
|---|
| 573 | |
|---|
| 574 | bitBufferSkipBits(bits,8); // reserved |
|---|
| 575 | |
|---|
| 576 | adaptationLength = bitBufferGetBits(bits,8); // adaptationLength |
|---|
| 577 | #if DEBUG_MODE |
|---|
| 578 | if (adaptationLength > 0) |
|---|
| 579 | DHL_OS_Printf("%s: warning! adaptationLength %d\n", name, adaptationLength); |
|---|
| 580 | #endif |
|---|
| 581 | |
|---|
| 582 | #if DEBUG_MODE |
|---|
| 583 | messageLength = bitBufferGetBits(bits,16); // messageLength |
|---|
| 584 | ptr0 = bitBufferGetBytePointer(bits); |
|---|
| 585 | #else |
|---|
| 586 | bitBufferSkipBits(bits,16); // messageLength |
|---|
| 587 | #endif |
|---|
| 588 | |
|---|
| 589 | for (i=0; i<adaptationLength; i++) |
|---|
| 590 | bitBufferSkipBits(bits,8); // adaptionHeader |
|---|
| 591 | |
|---|
| 592 | //--------- message body ------------- |
|---|
| 593 | |
|---|
| 594 | for (i=0; i<20; i++) { |
|---|
| 595 | tmp = bitBufferGetBits(bits,8); // serverId |
|---|
| 596 | #if DEBUG_MODE |
|---|
| 597 | if (tmp != 0xff) DHL_OS_Printf("%s: server id[%d] not 0xff\n", name, i); |
|---|
| 598 | #endif |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | err = ParseCompatDesc(bits, memId, &dsi->compat); |
|---|
| 602 | if (err) goto ParseExit; |
|---|
| 603 | |
|---|
| 604 | #if DEBUG_MODE |
|---|
| 605 | privateDataLength = bitBufferGetBits(bits,16); // privateDataLength |
|---|
| 606 | // ¿©±âºÎÅÍ checksum Á÷Àü±îÁöÀÇ ÃÑ ±æÀ̸¦ ÀǹÌÇÑ´Ù. |
|---|
| 607 | ptr1 = bitBufferGetBytePointer(bits); |
|---|
| 608 | #else |
|---|
| 609 | bitBufferSkipBits(bits,16); // privateDataLength |
|---|
| 610 | #endif |
|---|
| 611 | |
|---|
| 612 | dsi->numberOfGroups = bitBufferGetBits(bits,16); // numberOfGroups |
|---|
| 613 | if (dsi->numberOfGroups > 0) { |
|---|
| 614 | dsi->groups = (sddsDsiGroup_t *)memChainAlloc(memId,dsi->numberOfGroups*sizeof(sddsDsiGroup_t)); |
|---|
| 615 | checkMemoryError(dsi->groups); |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | for (iGroup=0; iGroup<dsi->numberOfGroups; iGroup++) |
|---|
| 619 | { |
|---|
| 620 | sddsDsiGroup_t *g = &dsi->groups[iGroup]; |
|---|
| 621 | |
|---|
| 622 | g->groupId = bitBufferGetBits(bits,32); |
|---|
| 623 | g->groupSize = bitBufferGetBits(bits,32); |
|---|
| 624 | |
|---|
| 625 | err = ParseCompatDesc(bits, memId, &g->compat); |
|---|
| 626 | if (err) goto ParseExit; |
|---|
| 627 | |
|---|
| 628 | g->groupInfoLength = bitBufferGetBits(bits,16); |
|---|
| 629 | if (g->groupInfoLength > 0) { |
|---|
| 630 | g->groupDescriptors = (UINT8 *)memChainAlloc(memId,g->groupInfoLength); |
|---|
| 631 | checkMemoryError(g->groupDescriptors); |
|---|
| 632 | } |
|---|
| 633 | for (i=0; i<g->groupInfoLength; i++) |
|---|
| 634 | g->groupDescriptors[i] = bitBufferGetBits(bits,8); |
|---|
| 635 | |
|---|
| 636 | // schedule descriptor parsing |
|---|
| 637 | p = find_desc(g->groupDescriptors, g->groupInfoLength, SDDS_schedule_tag); |
|---|
| 638 | if (p && p[1] >= 8) |
|---|
| 639 | { |
|---|
| 640 | // length´Â 8ÀÇ ¹è¼öÀ̾î¾ß ÇÏÁö¸¸, ²À ±×·¸Áö ¾Ê´õ¶óµµ ÇÊ¿äÇÑ µ¥ÀÌÅ͸¸ ÃßÃâÇØ¼ »ç¿ëÇϵµ·Ï ÇÏÀÚ. |
|---|
| 641 | int numSchedules = p[1]/8; |
|---|
| 642 | |
|---|
| 643 | g->scheduleDescriptor.numSchedules = numSchedules; |
|---|
| 644 | g->scheduleDescriptor.schedules = (sddsScheduleEntry_t *) |
|---|
| 645 | memChainAlloc(memId,numSchedules*sizeof(sddsScheduleEntry_t)); |
|---|
| 646 | checkMemoryError(g->scheduleDescriptor.schedules); |
|---|
| 647 | |
|---|
| 648 | for (i=0; i<numSchedules; i++) { |
|---|
| 649 | g->scheduleDescriptor.schedules[i].startTime = get_32(p+2+i*8); |
|---|
| 650 | g->scheduleDescriptor.schedules[i].lengthInSeconds = get_32(p+2+i*8+4) & 0xFFFFF; |
|---|
| 651 | } |
|---|
| 652 | } |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | dsi->groupInfoPrivateDataLength = bitBufferGetBits(bits,16); |
|---|
| 656 | if (dsi->groupInfoPrivateDataLength > 0) { |
|---|
| 657 | dsi->groupInfoPrivateDataBytes = (UINT8 *)memChainAlloc(memId,dsi->groupInfoPrivateDataLength); |
|---|
| 658 | checkMemoryError(dsi->groupInfoPrivateDataBytes); |
|---|
| 659 | } |
|---|
| 660 | for (i=0; i<dsi->groupInfoPrivateDataLength; i++) |
|---|
| 661 | dsi->groupInfoPrivateDataBytes[i] = bitBufferGetBits(bits,8); |
|---|
| 662 | |
|---|
| 663 | #if DEBUG_MODE |
|---|
| 664 | if (messageLength != (bitBufferGetBytePointer(bits)-ptr0)) |
|---|
| 665 | DHL_OS_Printf("!! %s: messageLength %d mismatch\n", name, messageLength); |
|---|
| 666 | if (privateDataLength != (bitBufferGetBytePointer(bits)-ptr1)) |
|---|
| 667 | DHL_OS_Printf("!! %s: privateDataLength %d mismatch\n", name, privateDataLength); |
|---|
| 668 | #endif |
|---|
| 669 | |
|---|
| 670 | dsi->checksum_CRC32 = bitBufferGetBits(bits,32); |
|---|
| 671 | |
|---|
| 672 | #if DEBUG_MODE |
|---|
| 673 | if (bitBufferCheckError(bits)) |
|---|
| 674 | DHL_OS_Printf("%s: bitbuf err\n", name); |
|---|
| 675 | |
|---|
| 676 | tmp = bitBufferGetBytePointer(bits) - section; // ¿ì¸®°¡ bitbuffer¿¡¼ ¼Ò¸ðÇÑ ¾ç. |
|---|
| 677 | if (tmp != section_length+3) |
|---|
| 678 | DHL_OS_Printf("%s: section len mismatch! consumed %u != hdr %u\n", name, tmp, section_length+3); |
|---|
| 679 | #endif |
|---|
| 680 | |
|---|
| 681 | #if DEBUG_CRC_RECHECK |
|---|
| 682 | if (dsi->section_syntax_indicator) { |
|---|
| 683 | if (calc_crc32(0xffffffff, section, section_length+3) != 0) |
|---|
| 684 | DHL_OS_Printf("%s: section crc err\n", name); |
|---|
| 685 | } |
|---|
| 686 | else { |
|---|
| 687 | UINT32 checksum = calc_ckecksum(section, section_length+3); |
|---|
| 688 | if (checksum != 0x0 && checksum != 0xffffffff) |
|---|
| 689 | DHL_OS_Printf("%s: section checksum err\n", name); |
|---|
| 690 | } |
|---|
| 691 | #endif |
|---|
| 692 | |
|---|
| 693 | /* parsing complete */ |
|---|
| 694 | *(((memId_t *)dsi)-1) = memId; |
|---|
| 695 | memId = NULL; /* so memChain not deleted */ |
|---|
| 696 | *ppDsi = dsi; |
|---|
| 697 | |
|---|
| 698 | ParseExit: |
|---|
| 699 | if (memId) { |
|---|
| 700 | /* delete the memory */ |
|---|
| 701 | memChainDestroy(memId); |
|---|
| 702 | } |
|---|
| 703 | return (err); |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | DHL_RESULT DLIB_SDDS_ParseDiiSection (UINT8 *section, sddsDiiPtr_t *ppDii) |
|---|
| 709 | { |
|---|
| 710 | sddsDiiPtr_t dii = NULL; |
|---|
| 711 | memChainSetup_t memSetup = {MEM_LIMIT,NULL,NULL}; |
|---|
| 712 | memId_t memId = NULL; |
|---|
| 713 | bitBuffer_t tBits, *bits = &tBits; |
|---|
| 714 | DHL_RESULT err = DHL_OK; |
|---|
| 715 | |
|---|
| 716 | char *name = "dii"; |
|---|
| 717 | int i, iModule; |
|---|
| 718 | UINT32 tmp; |
|---|
| 719 | UINT16 section_length; |
|---|
| 720 | UINT8 adaptationLength; |
|---|
| 721 | |
|---|
| 722 | #if DEBUG_MODE |
|---|
| 723 | UINT16 table_id_extension, messageLength;//, privateDataLength; |
|---|
| 724 | UINT8 *ptr0;//, *ptr1; |
|---|
| 725 | #endif |
|---|
| 726 | |
|---|
| 727 | if (section == NULL) { |
|---|
| 728 | DHL_OS_Printf("%s: null ptr\n", name); |
|---|
| 729 | #if DEBUG_MODE |
|---|
| 730 | DHL_ASSERT(FALSE, ""); |
|---|
| 731 | #endif |
|---|
| 732 | err = DHL_FAIL_INVALID_PARAM; |
|---|
| 733 | goto ParseExit; |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | if (get_table_id(section) != SDDS_Table_ID_Msg) { |
|---|
| 737 | DHL_OS_Printf("%s: invalid table_id\n", name); |
|---|
| 738 | #if DEBUG_MODE |
|---|
| 739 | DHL_ASSERT(FALSE, ""); |
|---|
| 740 | #endif |
|---|
| 741 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 742 | goto ParseExit; |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | #if DEBUG_MODE |
|---|
| 746 | tmp = get_section_syntax_indicator(section); |
|---|
| 747 | if (get_private_indicator(section) == tmp) |
|---|
| 748 | DHL_OS_Printf("%s: private_indicator not complement of ssi\n", name); |
|---|
| 749 | #endif |
|---|
| 750 | |
|---|
| 751 | section_length = get_section_length(section); |
|---|
| 752 | if (section_length > 4093) { |
|---|
| 753 | DHL_OS_Printf("%s: section_length %d\n", name, section_length); |
|---|
| 754 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 755 | goto ParseExit; |
|---|
| 756 | } |
|---|
| 757 | |
|---|
| 758 | bitBufferInitialize(bits,section+3,section_length); |
|---|
| 759 | |
|---|
| 760 | /* create the memChain */ |
|---|
| 761 | err = memChainCreate(&memId,&memSetup); |
|---|
| 762 | if (err) { |
|---|
| 763 | goto ParseExit; |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | /* allocate memory for diiSection + memId */ |
|---|
| 767 | dii = (sddsDiiPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(sddsDii_t)+sizeof(memId_t))) + 1); |
|---|
| 768 | checkMemoryError(dii); |
|---|
| 769 | |
|---|
| 770 | dii->section_syntax_indicator = get_section_syntax_indicator(section); |
|---|
| 771 | |
|---|
| 772 | #if DEBUG_MODE |
|---|
| 773 | table_id_extension = bitBufferGetBits(bits,16); |
|---|
| 774 | #else |
|---|
| 775 | bitBufferSkipBits(bits,16); |
|---|
| 776 | #endif |
|---|
| 777 | |
|---|
| 778 | #if DEBUG_MODE |
|---|
| 779 | bitBufferSkipBits(bits,2); // reserved |
|---|
| 780 | tmp = bitBufferGetBits(bits,5); // version_number |
|---|
| 781 | if (tmp != 0) |
|---|
| 782 | DHL_OS_Printf("%s: version_number %d != 0\n", name, tmp); |
|---|
| 783 | |
|---|
| 784 | tmp = bitBufferGetBits(bits,1); // current_next_indicator |
|---|
| 785 | if (tmp != 1) |
|---|
| 786 | DHL_OS_Printf("%s: current_next_indicator != 1\n", name); |
|---|
| 787 | |
|---|
| 788 | tmp = bitBufferGetBits(bits,8); // section_number |
|---|
| 789 | if (tmp != 0x00) |
|---|
| 790 | DHL_OS_Printf("%s: section_number %x != 0x00\n", name, tmp); |
|---|
| 791 | |
|---|
| 792 | tmp = bitBufferGetBits(bits,8); // last_section_number |
|---|
| 793 | if (tmp != 0x00) |
|---|
| 794 | DHL_OS_Printf("%s: last_section_number %x != 0x00\n", name, tmp); |
|---|
| 795 | |
|---|
| 796 | tmp = bitBufferGetBits(bits,8); // protocolDiscriminator |
|---|
| 797 | if (tmp != 0x11) |
|---|
| 798 | DHL_OS_Printf("%s: protocolDiscriminator %x != 0x11\n", name, tmp); |
|---|
| 799 | |
|---|
| 800 | tmp = bitBufferGetBits(bits,8); // dsmccType |
|---|
| 801 | if (tmp != 0x03) |
|---|
| 802 | DHL_OS_Printf("%s: dsmccType %x != 0x03\n", name, tmp); |
|---|
| 803 | #else |
|---|
| 804 | bitBufferSkipBits(bits, 32); |
|---|
| 805 | bitBufferSkipBits(bits, 8); |
|---|
| 806 | #endif |
|---|
| 807 | |
|---|
| 808 | tmp = bitBufferGetBits(bits,16); // messageId |
|---|
| 809 | if (tmp != SDDS_Message_ID_DII) { // 0x1002 |
|---|
| 810 | DHL_OS_Printf("%s: messageId %x != 0x1006\n", name, tmp); |
|---|
| 811 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 812 | goto ParseExit; |
|---|
| 813 | } |
|---|
| 814 | dii->transactionId = bitBufferGetBits(bits,32); // transactionId |
|---|
| 815 | #if DEBUG_MODE |
|---|
| 816 | if (table_id_extension != (dii->transactionId & 0xffff)) { |
|---|
| 817 | DHL_OS_Printf("%s: tidex %x != trid %x\n", name, table_id_extension, dii->transactionId); |
|---|
| 818 | } |
|---|
| 819 | #endif |
|---|
| 820 | |
|---|
| 821 | bitBufferSkipBits(bits,8); // reserved |
|---|
| 822 | |
|---|
| 823 | adaptationLength = bitBufferGetBits(bits,8); // adaptationLength |
|---|
| 824 | #if DEBUG_MODE |
|---|
| 825 | if (adaptationLength > 0) |
|---|
| 826 | DHL_OS_Printf("%s: warning! adaptationLength %d\n", name, adaptationLength); |
|---|
| 827 | #endif |
|---|
| 828 | |
|---|
| 829 | #if DEBUG_MODE |
|---|
| 830 | messageLength = bitBufferGetBits(bits,16); // messageLength |
|---|
| 831 | ptr0 = bitBufferGetBytePointer(bits); |
|---|
| 832 | #else |
|---|
| 833 | bitBufferSkipBits(bits,16); // messageLength |
|---|
| 834 | #endif |
|---|
| 835 | |
|---|
| 836 | for (i=0; i<adaptationLength; i++) { |
|---|
| 837 | bitBufferSkipBits(bits,8); // adaptionHeader |
|---|
| 838 | } |
|---|
| 839 | //--------- message body ------------- |
|---|
| 840 | |
|---|
| 841 | dii->downloadId = bitBufferGetBits(bits,32); // downloadId |
|---|
| 842 | dii->blockSize = bitBufferGetBits(bits,16); // blockSize |
|---|
| 843 | |
|---|
| 844 | bitBufferSkipBits(bits,8); // windowSize |
|---|
| 845 | bitBufferSkipBits(bits,8); // ackPeriod |
|---|
| 846 | bitBufferSkipBits(bits,32); // tcDownloadWindow |
|---|
| 847 | bitBufferSkipBits(bits,32); // tcDownloadScenario |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | err = ParseCompatDesc(bits, memId, &dii->compat); |
|---|
| 851 | if (err) goto ParseExit; |
|---|
| 852 | |
|---|
| 853 | dii->numberOfModules = bitBufferGetBits(bits,16); // numberOfModules |
|---|
| 854 | if (dii->numberOfModules > 0) { |
|---|
| 855 | dii->modules = (sddsDiiModule_t *)memChainAlloc(memId,dii->numberOfModules*sizeof(sddsDiiModule_t)); |
|---|
| 856 | checkMemoryError(dii->modules); |
|---|
| 857 | } |
|---|
| 858 | for (iModule=0; iModule<dii->numberOfModules; iModule++) |
|---|
| 859 | { |
|---|
| 860 | UINT8 *p; |
|---|
| 861 | DHL_RESULT err2; |
|---|
| 862 | |
|---|
| 863 | sddsDiiModule_t *m = &dii->modules[iModule]; |
|---|
| 864 | m->moduleId = bitBufferGetBits(bits,16); |
|---|
| 865 | m->moduleSize = bitBufferGetBits(bits,32); |
|---|
| 866 | m->moduleVersion = bitBufferGetBits(bits,8); |
|---|
| 867 | m->moduleInfoLength = bitBufferGetBits(bits,8); |
|---|
| 868 | if (m->moduleInfoLength > 0) { |
|---|
| 869 | m->moduleDescriptors = (UINT8 *)memChainAlloc(memId,m->moduleInfoLength); |
|---|
| 870 | checkMemoryError(m->moduleDescriptors); |
|---|
| 871 | } |
|---|
| 872 | for (i=0; i<m->moduleInfoLength; i++) |
|---|
| 873 | m->moduleDescriptors[i] = bitBufferGetBits(bits,8); |
|---|
| 874 | |
|---|
| 875 | // moduleInfoDescriptor Ãß°¡. |
|---|
| 876 | err2 = GetMpegDescriptor(m->moduleDescriptors, m->moduleInfoLength, |
|---|
| 877 | SDDS_module_info_tag, 0, &p); |
|---|
| 878 | if (!err2) { |
|---|
| 879 | err2 = ParseModuleInfoDesc(memId, p, &m->moduleInfoDesc); |
|---|
| 880 | checkMemoryError(m->moduleInfoDesc); |
|---|
| 881 | // ÀÌ dii ¿¡¼ »ç¿ëÇÏ´Â memId¸¦ ±×´ë·Î »ç¿ëÇϰí ÀÖÀ¸¹Ç·Î |
|---|
| 882 | // moduleInfoDesc´Â dii ¿¡ ¿¬°áµÇ¾î ÀÖ´Ù. ³ªÁß¿¡ ÇѲ¨¹ø¿¡ free µÈ´Ù. |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | dii->privateDataLength = bitBufferGetBits(bits,16); |
|---|
| 888 | if (dii->privateDataLength > 0) { |
|---|
| 889 | dii->privateDataBytes = (UINT8 *)memChainAlloc(memId,dii->privateDataLength); |
|---|
| 890 | checkMemoryError(dii->privateDataBytes); |
|---|
| 891 | } |
|---|
| 892 | for (i=0; i<dii->privateDataLength; i++) |
|---|
| 893 | dii->privateDataBytes[i] = bitBufferGetBits(bits,8); |
|---|
| 894 | |
|---|
| 895 | #if DEBUG_MODE |
|---|
| 896 | if (messageLength != (tmp = bitBufferGetBytePointer(bits)-ptr0)) |
|---|
| 897 | DHL_OS_Printf("!! %s: messageLength mismatch %u %u\n", name, messageLength, tmp); |
|---|
| 898 | #endif |
|---|
| 899 | |
|---|
| 900 | dii->checksum_CRC32 = bitBufferGetBits(bits,32); |
|---|
| 901 | |
|---|
| 902 | #if DEBUG_MODE |
|---|
| 903 | if (bitBufferCheckError(bits)) |
|---|
| 904 | DHL_OS_Printf("%s: bitbuf err\n", name); |
|---|
| 905 | |
|---|
| 906 | tmp = bitBufferGetBytePointer(bits) - section; // ¿ì¸®°¡ bitbuffer¿¡¼ ¼Ò¸ðÇÑ ¾ç. |
|---|
| 907 | if (tmp != section_length+3) |
|---|
| 908 | DHL_OS_Printf("%s: section len mismatch! consumed %u != hdr %u\n", name, tmp, section_length+3); |
|---|
| 909 | #endif |
|---|
| 910 | |
|---|
| 911 | #if DEBUG_CRC_RECHECK |
|---|
| 912 | if (dii->section_syntax_indicator) { |
|---|
| 913 | if (calc_crc32(0xffffffff, section, section_length+3) != 0) |
|---|
| 914 | DHL_OS_Printf("%s: section crc err\n", name); |
|---|
| 915 | } |
|---|
| 916 | #endif |
|---|
| 917 | |
|---|
| 918 | /* parsing complete */ |
|---|
| 919 | *(((memId_t *)dii)-1) = memId; |
|---|
| 920 | memId = NULL; /* so memChain not deleted */ |
|---|
| 921 | *ppDii = dii; |
|---|
| 922 | |
|---|
| 923 | ParseExit: |
|---|
| 924 | if (memId) { |
|---|
| 925 | /* delete the memory */ |
|---|
| 926 | memChainDestroy(memId); |
|---|
| 927 | } |
|---|
| 928 | return (err); |
|---|
| 929 | } |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | DHL_RESULT DLIB_SDDS_ParseDdbSection (UINT8 *section, sddsDdbPtr_t *ppDdb) |
|---|
| 933 | { |
|---|
| 934 | sddsDdbPtr_t ddb = NULL; |
|---|
| 935 | memChainSetup_t memSetup = {MEM_LIMIT,NULL,NULL}; |
|---|
| 936 | memId_t memId = NULL; |
|---|
| 937 | bitBuffer_t tBits, *bits = &tBits; |
|---|
| 938 | DHL_RESULT err = DHL_OK; |
|---|
| 939 | |
|---|
| 940 | char *name = "ddb"; |
|---|
| 941 | int i; |
|---|
| 942 | UINT16 section_length;//, table_id_extension; |
|---|
| 943 | UINT32 tmp; |
|---|
| 944 | UINT8 adaptationLength; |
|---|
| 945 | UINT16 messageLength; |
|---|
| 946 | UINT8 *ptr0; |
|---|
| 947 | |
|---|
| 948 | #if DEBUG_MODE |
|---|
| 949 | UINT8 version_number, section_number; |
|---|
| 950 | #endif |
|---|
| 951 | |
|---|
| 952 | if (section == NULL) { |
|---|
| 953 | DHL_OS_Printf("%s: null ptr\n", name); |
|---|
| 954 | #if DEBUG_MODE |
|---|
| 955 | DHL_ASSERT(FALSE, ""); |
|---|
| 956 | #endif |
|---|
| 957 | err = DHL_FAIL_INVALID_PARAM; |
|---|
| 958 | goto ParseExit; |
|---|
| 959 | } |
|---|
| 960 | |
|---|
| 961 | if (get_table_id(section) != SDDS_Table_ID_Data) { |
|---|
| 962 | DHL_OS_Printf("%s: invalid table_id\n", name); |
|---|
| 963 | #if DEBUG_MODE |
|---|
| 964 | DHL_ASSERT(FALSE, ""); |
|---|
| 965 | #endif |
|---|
| 966 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 967 | goto ParseExit; |
|---|
| 968 | } |
|---|
| 969 | |
|---|
| 970 | #if DEBUG_MODE |
|---|
| 971 | tmp = get_section_syntax_indicator(section); |
|---|
| 972 | if (get_private_indicator(section) == tmp) |
|---|
| 973 | DHL_OS_Printf("%s: private_indicator not complement of ssi\n", name); |
|---|
| 974 | #endif |
|---|
| 975 | |
|---|
| 976 | section_length = get_section_length(section); |
|---|
| 977 | if (section_length > 4093) { |
|---|
| 978 | DHL_OS_Printf("%s: section_length %d\n", name, section_length); |
|---|
| 979 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 980 | goto ParseExit; |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | bitBufferInitialize(bits,section+3,section_length); |
|---|
| 984 | |
|---|
| 985 | /* create the memChain */ |
|---|
| 986 | err = memChainCreate(&memId,&memSetup); |
|---|
| 987 | if (err) { |
|---|
| 988 | goto ParseExit; |
|---|
| 989 | } |
|---|
| 990 | |
|---|
| 991 | /* allocate memory for ddbSection + memId */ |
|---|
| 992 | ddb = (sddsDdbPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(sddsDdb_t)+sizeof(memId_t))) + 1); |
|---|
| 993 | checkMemoryError(ddb); |
|---|
| 994 | |
|---|
| 995 | ddb->section_syntax_indicator = get_section_syntax_indicator(section); |
|---|
| 996 | |
|---|
| 997 | #if DEBUG_MODE |
|---|
| 998 | table_id_extension = bitBufferGetBits(bits,16); |
|---|
| 999 | // ÀÌ °ªÀº moduleid¿Í µ¿ÀÏÇØ¾ß ÇÑ´Ù. |
|---|
| 1000 | #else |
|---|
| 1001 | bitBufferSkipBits(bits,16); |
|---|
| 1002 | #endif |
|---|
| 1003 | |
|---|
| 1004 | #if DEBUG_MODE |
|---|
| 1005 | bitBufferSkipBits(bits,2); // reserved |
|---|
| 1006 | version_number = bitBufferGetBits(bits,5); // version_number |
|---|
| 1007 | |
|---|
| 1008 | tmp = bitBufferGetBits(bits,1); // current_next_indicator |
|---|
| 1009 | if (tmp != 1) |
|---|
| 1010 | DHL_OS_Printf("%s: current_next_indicator != 1\n", name); |
|---|
| 1011 | |
|---|
| 1012 | section_number = bitBufferGetBits(bits,8); // section_number |
|---|
| 1013 | bitBufferSkipBits(bits,8); // last_section_number |
|---|
| 1014 | |
|---|
| 1015 | tmp = bitBufferGetBits(bits,8); // protocolDiscriminator |
|---|
| 1016 | if (tmp != 0x11) |
|---|
| 1017 | DHL_OS_Printf("%s: protocolDiscriminator %x != 0x11\n", name, tmp); |
|---|
| 1018 | |
|---|
| 1019 | tmp = bitBufferGetBits(bits,8); // dsmccType |
|---|
| 1020 | if (tmp != 0x03) |
|---|
| 1021 | DHL_OS_Printf("%s: dsmccType %x != 0x03\n", name, tmp); |
|---|
| 1022 | #else |
|---|
| 1023 | bitBufferSkipBits(bits,32); |
|---|
| 1024 | bitBufferSkipBits(bits,8); |
|---|
| 1025 | #endif |
|---|
| 1026 | |
|---|
| 1027 | tmp = bitBufferGetBits(bits,16); // messageId |
|---|
| 1028 | if (tmp != SDDS_Message_ID_DDB) { // 0x1003 |
|---|
| 1029 | DHL_OS_Printf("%s: messageId %x != 0x1003\n", name, tmp); |
|---|
| 1030 | err = DHL_FAIL_BAD_FORMAT; |
|---|
| 1031 | goto ParseExit; |
|---|
| 1032 | } |
|---|
| 1033 | ddb->downloadId= bitBufferGetBits(bits,32); // downloadId |
|---|
| 1034 | |
|---|
| 1035 | bitBufferSkipBits(bits,8); // reserved |
|---|
| 1036 | |
|---|
| 1037 | adaptationLength = bitBufferGetBits(bits,8); // adaptationLength |
|---|
| 1038 | messageLength = bitBufferGetBits(bits,16); // messageLength |
|---|
| 1039 | // ÀÌ ÁöÁ¡ºÎÅÍ crc ¹Ù·Î ¾Õ ±îÁöÀÇ ±æÀÌ. |
|---|
| 1040 | // payload ±æÀ̸¦ ¾Ë·ÁÁÖ´Â ´Ù¸¥ indicator°¡ ¾øÀ¸¹Ç·Î |
|---|
| 1041 | // ÀÌ °ªÀº »ó´çÈ÷ Áß¿äÇÏ´Ù. |
|---|
| 1042 | ptr0 = bitBufferGetBytePointer(bits); |
|---|
| 1043 | |
|---|
| 1044 | for (i=0; i<adaptationLength; i++) |
|---|
| 1045 | bitBufferSkipBits(bits,8); // adaptionHeader |
|---|
| 1046 | |
|---|
| 1047 | ddb->moduleId = bitBufferGetBits(bits,16); // moduleId |
|---|
| 1048 | #if DEBUG_MODE |
|---|
| 1049 | if (table_id_extension != (ddb->moduleId)) { |
|---|
| 1050 | DHL_OS_Printf("%s: tidex %x != moduleId %x\n", name, table_id_extension, ddb->moduleId); |
|---|
| 1051 | } |
|---|
| 1052 | #endif |
|---|
| 1053 | ddb->moduleVersion = bitBufferGetBits(bits,8); // moduleVersion |
|---|
| 1054 | #if DEBUG_MODE |
|---|
| 1055 | if (version_number != ddb->moduleVersion & 0x1f) |
|---|
| 1056 | DHL_OS_Printf("%s: ver 0x%x != modulever 0x%x\n", name, version_number, ddb->moduleVersion); |
|---|
| 1057 | #endif |
|---|
| 1058 | |
|---|
| 1059 | bitBufferSkipBits(bits,8); // reserved |
|---|
| 1060 | |
|---|
| 1061 | ddb->blockNumber = bitBufferGetBits(bits,16); // blockNumber |
|---|
| 1062 | #if DEBUG_MODE |
|---|
| 1063 | if (section_number != (ddb->blockNumber & 0xff)) |
|---|
| 1064 | DHL_OS_Printf("%s: secnum 0x%x != blknum 0x%x\n", name, section_number, ddb->blockNumber); |
|---|
| 1065 | #endif |
|---|
| 1066 | |
|---|
| 1067 | ddb->blockDataBytePtr = bitBufferGetBytePointer(bits); |
|---|
| 1068 | // ÁÖÀÇ!! |
|---|
| 1069 | // ½ÇÁ¦·Î memcpy¸¦ ¼öÇàÇÏÁö´Â ¾Ê´Â´Ù. ±×³É Æ÷ÀÎÅ͸¸ ¾Ë¾Æ³½´Ù. |
|---|
| 1070 | |
|---|
| 1071 | // ddb message ±æÀÌ¿¡¼ payload ¾Õ ºÎºÐÀÇ overhead¸¦ »©¸é data block Å©±â °è»ê. |
|---|
| 1072 | ddb->blockDataLength = messageLength - (ddb->blockDataBytePtr - ptr0); |
|---|
| 1073 | for (i=0; i<ddb->blockDataLength; i++) |
|---|
| 1074 | bitBufferSkipBits(bits,8); // blockDataByte |
|---|
| 1075 | |
|---|
| 1076 | ddb->checksum_CRC32 = bitBufferGetBits(bits,32); |
|---|
| 1077 | |
|---|
| 1078 | #if DEBUG_MODE |
|---|
| 1079 | if (bitBufferCheckError(bits)) |
|---|
| 1080 | DHL_OS_Printf("%s: bitbuf err\n", name); |
|---|
| 1081 | |
|---|
| 1082 | tmp = bitBufferGetBytePointer(bits) - section; // ¿ì¸®°¡ bitbuffer¿¡¼ ¼Ò¸ðÇÑ ¾ç. |
|---|
| 1083 | if (tmp != section_length+3) |
|---|
| 1084 | DHL_OS_Printf("%s: section len mismatch! consumed %u != hdr %u\n", name, tmp, section_length+3); |
|---|
| 1085 | #endif |
|---|
| 1086 | |
|---|
| 1087 | #if DEBUG_CRC_RECHECK |
|---|
| 1088 | if (ddb->section_syntax_indicator) { |
|---|
| 1089 | if (calc_crc32(0xffffffff, section, section_length+3) != 0) |
|---|
| 1090 | DHL_OS_Printf("%s: section crc err\n", name); |
|---|
| 1091 | } |
|---|
| 1092 | #endif |
|---|
| 1093 | |
|---|
| 1094 | /* parsing complete */ |
|---|
| 1095 | *(((memId_t *)ddb)-1) = memId; |
|---|
| 1096 | memId = NULL; /* so memChain not deleted */ |
|---|
| 1097 | *ppDdb = ddb; |
|---|
| 1098 | |
|---|
| 1099 | ParseExit: |
|---|
| 1100 | if (memId) { |
|---|
| 1101 | /* delete the memory */ |
|---|
| 1102 | memChainDestroy(memId); |
|---|
| 1103 | } |
|---|
| 1104 | return (err); |
|---|
| 1105 | } |
|---|
| 1106 | |
|---|
| 1107 | #if COMMENT |
|---|
| 1108 | ____DbgPrint____(){} |
|---|
| 1109 | #endif |
|---|
| 1110 | |
|---|
| 1111 | #if SHOW_LOCAL_TIME |
|---|
| 1112 | |
|---|
| 1113 | #include "DMW_SysTime.h" |
|---|
| 1114 | |
|---|
| 1115 | /* |
|---|
| 1116 | API¸¦ »ç¿ëÇϱâ À§ÇØ ÇÊ¿äÇÑ time context. |
|---|
| 1117 | ¿ì¸®´Â ½ÇÁ¦ ½Ã°£ÀÌ ÇÊ¿äÇÑ °Ô ¾Æ´Ï°í, º¯È¯¸¸ ÇÒ °ÍÀ̹ǷΠ, |
|---|
| 1118 | ¿©±â¼ »ç¿ëµÇ´Â °ÍÀº timezone, daylight Á¤º¸, offset Á¤º¸ »ÓÀÌ´Ù. |
|---|
| 1119 | */ |
|---|
| 1120 | SysTimeContext s_stc = |
|---|
| 1121 | { |
|---|
| 1122 | 0, /* BOOL bTimebaseAdjusted */ |
|---|
| 1123 | 630687600, /* 2000³â 1¿ù1ÀÏ Çѱ¹¿¡¼ÀÇ UTC.. this will be updated by DMW_SetUTCTime */ |
|---|
| 1124 | 9, /* int nTimeZone; */ /* this will be updated to g_EpgDebugTimeZone */ |
|---|
| 1125 | 0, /* BOOL bDaylightSavingOn; */ /* 1:day light saving , 0: no day light saving */ |
|---|
| 1126 | 13, /* int GPS_UTC_offset; */ |
|---|
| 1127 | }; |
|---|
| 1128 | |
|---|
| 1129 | /* |
|---|
| 1130 | port from DMW_EpgDebug.c: GpsTimeString2() function. |
|---|
| 1131 | recommended to move DLIB library.. |
|---|
| 1132 | */ |
|---|
| 1133 | static char *local_time(UINT32 gps, char *buf, int level) |
|---|
| 1134 | { |
|---|
| 1135 | /* 0: (3:20), 1: (3:20:15) 2: (4/19 3:20:15) 3: (2004/4/19 ¿ù 3:20:15) */ |
|---|
| 1136 | //char *WdayString_k[7]={"ÀÏ", "¿ù", "È", "¼ö", "¸ñ", "±Ý", "Åä"}; |
|---|
| 1137 | //char *WdayString_e[7]={"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
|---|
| 1138 | |
|---|
| 1139 | static char _buf[100]; |
|---|
| 1140 | STime_t s; |
|---|
| 1141 | UINT32 utc; |
|---|
| 1142 | |
|---|
| 1143 | utc = DMW_ConvertGPS2UTC(&s_stc, gps); |
|---|
| 1144 | DMW_ConvertUTC2LocalTime(&s_stc, utc, &s); |
|---|
| 1145 | |
|---|
| 1146 | if (buf == NULL) buf = _buf; |
|---|
| 1147 | |
|---|
| 1148 | #if 1 |
|---|
| 1149 | sprintf(buf, "%d/%d/%d %02d:%02d:%02d", |
|---|
| 1150 | s.year, s.month, s.day, s.hour, s.min, s.sec); |
|---|
| 1151 | #else |
|---|
| 1152 | if (level >= 4) |
|---|
| 1153 | sprintf(buf, "%d/%d/%d %s %2d:%02d:%02d [tz%+d]", |
|---|
| 1154 | s.year, s.month, s.day, s.wday<7?WdayString_e[s.wday]:"", s.hour, s.min, s.sec, |
|---|
| 1155 | s_stc.nTimeZone); |
|---|
| 1156 | else if (level >= 3) |
|---|
| 1157 | sprintf(buf, "%d/%d/%d %s %2d:%02d:%02d", |
|---|
| 1158 | s.year, s.month, s.day, s.wday<7?WdayString_k[s.wday]:"", s.hour, s.min, s.sec); |
|---|
| 1159 | else if (level >= 2) |
|---|
| 1160 | sprintf(buf, "%d/%d %2d:%02d:%02d", |
|---|
| 1161 | s.month, s.day, s.hour, s.min, s.sec); |
|---|
| 1162 | else if (level >= 1) |
|---|
| 1163 | sprintf(buf, "%2d:%02d:%02d", s.hour, s.min, s.sec); |
|---|
| 1164 | else |
|---|
| 1165 | sprintf(buf, "%2d:%02d", s.hour, s.min); |
|---|
| 1166 | #endif |
|---|
| 1167 | return buf; |
|---|
| 1168 | } |
|---|
| 1169 | |
|---|
| 1170 | #endif // SHOW_LOCAL_TIME |
|---|
| 1171 | |
|---|
| 1172 | |
|---|
| 1173 | #define print DHL_OS_Printf |
|---|
| 1174 | |
|---|
| 1175 | #define DLIB_MAX_PRINT_INDENT 16 |
|---|
| 1176 | // µé¿©¾²±â ÃÖ´ë Æø. |
|---|
| 1177 | |
|---|
| 1178 | void dump_bytes(UINT8 *p, int len, UINT32 indent) |
|---|
| 1179 | { |
|---|
| 1180 | int i, k; |
|---|
| 1181 | char ib[DLIB_MAX_PRINT_INDENT+1]; // µé¿©¾²±â¿ë ¹öÆÛ. |
|---|
| 1182 | char buf[16*3 + 20]; // ÇÑ ÁÙ¿¡ 16 ±ÛÀÚ¸¸ Ãâ·Â ÇÒ °ÍÀÓ. |
|---|
| 1183 | |
|---|
| 1184 | indent = min(indent, DLIB_MAX_PRINT_INDENT); |
|---|
| 1185 | memset(ib, ' ', sizeof(ib)); |
|---|
| 1186 | ib[indent] = 0; |
|---|
| 1187 | |
|---|
| 1188 | for (i=0; i<len; i+=16) { |
|---|
| 1189 | buf[0] = 0; |
|---|
| 1190 | for (k=0; k<min(16, len-i); k++) |
|---|
| 1191 | sprintf(buf+strlen(buf), "%02x ", p[i+k]); |
|---|
| 1192 | print("%s %s\n", ib, buf); |
|---|
| 1193 | } |
|---|
| 1194 | } |
|---|
| 1195 | |
|---|
| 1196 | void print_compat(sddsCompatDesc_t *compat, UINT32 indent) |
|---|
| 1197 | { |
|---|
| 1198 | int i, k; |
|---|
| 1199 | char ib[DLIB_MAX_PRINT_INDENT+1]; // µé¿©¾²±â¿ë ¹öÆÛ. |
|---|
| 1200 | |
|---|
| 1201 | indent = min(indent, DLIB_MAX_PRINT_INDENT); |
|---|
| 1202 | memset(ib, ' ', sizeof(ib)); |
|---|
| 1203 | ib[indent] = 0; |
|---|
| 1204 | |
|---|
| 1205 | print("%s compat desc count: %d\n", ib, compat->descriptorCount); |
|---|
| 1206 | for (i=0; i<compat->descriptorCount; i++) { |
|---|
| 1207 | sddsCompatDescEntry_t *e = &compat->desc[i]; |
|---|
| 1208 | |
|---|
| 1209 | print("%s [%d] type 0x%02x, spec %02x:%08x, m %04x v %04x\n", |
|---|
| 1210 | ib, i, e->descriptorType, e->specifierType, e->specifierData, |
|---|
| 1211 | e->model, e->version); |
|---|
| 1212 | if (e->subDescriptorCount == 0) continue; |
|---|
| 1213 | for (k=0; k<e->subDescriptorCount; k++) { |
|---|
| 1214 | sddsCompatSubDesc_t *s = &e->subDescriptors[k]; |
|---|
| 1215 | print("%s (%d) sub type 0x%2x, len %d (0x%x)\n", |
|---|
| 1216 | ib, k, s->subDescriptorType, s->subDescriptorLength, s->subDescriptorLength); |
|---|
| 1217 | if (s->subDescriptorLength > 0) |
|---|
| 1218 | dump_bytes(s->additionalInformation, s->subDescriptorLength, indent+2); |
|---|
| 1219 | } |
|---|
| 1220 | } |
|---|
| 1221 | } |
|---|
| 1222 | |
|---|
| 1223 | void print_midesc(sddsModuleInfoDesc_t *mid, int indent) |
|---|
| 1224 | { |
|---|
| 1225 | int i, k; |
|---|
| 1226 | char ib[DLIB_MAX_PRINT_INDENT+1]; // µé¿©¾²±â¿ë ¹öÆÛ. |
|---|
| 1227 | sddsDstModuleInfoDesc_t *di; |
|---|
| 1228 | char buf[10*3 + 8]; // 8 is safe margin.. |
|---|
| 1229 | |
|---|
| 1230 | indent = min(indent, DLIB_MAX_PRINT_INDENT); |
|---|
| 1231 | memset(ib, ' ', sizeof(ib)); |
|---|
| 1232 | ib[indent] = 0; |
|---|
| 1233 | |
|---|
| 1234 | di = &mid->dstinfo; |
|---|
| 1235 | |
|---|
| 1236 | // prepare bdver list string |
|---|
| 1237 | sprintf(buf, "num bdver %u: ", di->numSupportedHwVersions); |
|---|
| 1238 | for (k=0; di->supportedHwVersions && k<min(di->numSupportedHwVersions, 10); k++) |
|---|
| 1239 | sprintf(buf+strlen(buf), "%02x ", di->supportedHwVersions[k]); |
|---|
| 1240 | if (di->numSupportedHwVersions > 10) |
|---|
| 1241 | sprintf(buf+strlen(buf), ".."); |
|---|
| 1242 | |
|---|
| 1243 | print("%s ---- module info descriptor ----\n", ib); |
|---|
| 1244 | print("%s encoding %x, name '%s', sigtype %x, sig %d bytes\n", |
|---|
| 1245 | ib, mid->encoding, mid->nameBytes, mid->signatureType, mid->signatureLength); |
|---|
| 1246 | print("%s type 0x%x, name '%s', ver '%s' crc 0x%08x\n", |
|---|
| 1247 | ib, di->moduleType, di->moduleName, di->moduleVer, di->fileCRC32); |
|---|
| 1248 | print("%s %s\n", ib, buf); |
|---|
| 1249 | |
|---|
| 1250 | } |
|---|
| 1251 | |
|---|
| 1252 | |
|---|
| 1253 | void DLIB_SDDS_PrintDsiSection (sddsDsiPtr_t dsi, UINT32 indent) |
|---|
| 1254 | { |
|---|
| 1255 | int i, k; |
|---|
| 1256 | char ib[DLIB_MAX_PRINT_INDENT+1]; |
|---|
| 1257 | |
|---|
| 1258 | if (!dsi) return; |
|---|
| 1259 | |
|---|
| 1260 | indent = min(indent, DLIB_MAX_PRINT_INDENT); |
|---|
| 1261 | memset(ib, ' ', sizeof(ib)); |
|---|
| 1262 | ib[indent] = 0; |
|---|
| 1263 | |
|---|
| 1264 | print("%s------------- dsi section ------------\n", ib); |
|---|
| 1265 | print("%s trid 0x%08x, %d groups\n", ib, dsi->transactionId, dsi->numberOfGroups); |
|---|
| 1266 | if (dsi->compat.descriptorCount > 0) |
|---|
| 1267 | print_compat(&dsi->compat, indent); |
|---|
| 1268 | |
|---|
| 1269 | for (i=0; i<dsi->numberOfGroups; i++) { |
|---|
| 1270 | sddsDsiGroup_t *gi = &dsi->groups[i]; |
|---|
| 1271 | print("%s (%u) groupId 0x%08x, groupSize %d bytes\n", ib, i, gi->groupId, gi->groupSize); |
|---|
| 1272 | |
|---|
| 1273 | if (gi->compat.descriptorCount > 0) |
|---|
| 1274 | print_compat(&gi->compat, indent+2); |
|---|
| 1275 | |
|---|
| 1276 | if (gi->groupInfoLength > 0) { |
|---|
| 1277 | print("%s priv data: %d bytes\n", ib, gi->groupInfoLength); |
|---|
| 1278 | dump_bytes(gi->groupDescriptors, gi->groupInfoLength, indent+4); |
|---|
| 1279 | } |
|---|
| 1280 | if (gi->scheduleDescriptor.numSchedules > 0) { |
|---|
| 1281 | sddsScheduleDesc_t *sc = &gi->scheduleDescriptor; |
|---|
| 1282 | for (k=0; k<sc->numSchedules; k++) |
|---|
| 1283 | #if SHOW_LOCAL_TIME |
|---|
| 1284 | print("%s sched[%d]: 0x%x (%s) %u sec\n", ib, k, |
|---|
| 1285 | sc->schedules[k].startTime, local_time(sc->schedules[k].startTime, 0, 3), |
|---|
| 1286 | sc->schedules[k].lengthInSeconds); |
|---|
| 1287 | #else |
|---|
| 1288 | print("%s sched[%d]: 0x%x, %u seconds\n", ib, k, |
|---|
| 1289 | sc->schedules[k].startTime, sc->schedules[k].lengthInSeconds); |
|---|
| 1290 | #endif |
|---|
| 1291 | } |
|---|
| 1292 | } |
|---|
| 1293 | if (dsi->groupInfoPrivateDataLength > 0) { |
|---|
| 1294 | print("%s group priv data: %d bytes\n", ib, dsi->groupInfoPrivateDataLength); |
|---|
| 1295 | dump_bytes(dsi->groupInfoPrivateDataBytes, dsi->groupInfoPrivateDataLength, indent); |
|---|
| 1296 | } |
|---|
| 1297 | print("%s %s 0x%08x\n", ib, dsi->section_syntax_indicator ? "crc" : "chksum", dsi->checksum_CRC32); |
|---|
| 1298 | |
|---|
| 1299 | } |
|---|
| 1300 | |
|---|
| 1301 | |
|---|
| 1302 | |
|---|
| 1303 | void DLIB_SDDS_PrintDiiSection (sddsDiiPtr_t dii, UINT32 indent) |
|---|
| 1304 | { |
|---|
| 1305 | int i, k; |
|---|
| 1306 | char ib[DLIB_MAX_PRINT_INDENT+1]; |
|---|
| 1307 | |
|---|
| 1308 | if (!dii) return; |
|---|
| 1309 | |
|---|
| 1310 | indent = min(indent, DLIB_MAX_PRINT_INDENT); |
|---|
| 1311 | memset(ib, ' ', sizeof(ib)); |
|---|
| 1312 | ib[indent] = 0; |
|---|
| 1313 | |
|---|
| 1314 | print("%s------------- dii section ------------\n", ib); |
|---|
| 1315 | print("%s trid 0x%08x, downloadid %d, blocksz %d, %d modules\n", |
|---|
| 1316 | ib, dii->transactionId, dii->downloadId, dii->blockSize, dii->numberOfModules); |
|---|
| 1317 | |
|---|
| 1318 | if (dii->compat.descriptorCount > 0) |
|---|
| 1319 | print_compat(&dii->compat, indent); |
|---|
| 1320 | |
|---|
| 1321 | for (i=0; i<dii->numberOfModules; i++) { |
|---|
| 1322 | sddsDiiModule_t *m = &dii->modules[i]; |
|---|
| 1323 | print("%s %2d) moduleid 0x%04x, size %u, v 0x%x, %d blocks\n", |
|---|
| 1324 | ib, i, m->moduleId, m->moduleSize, m->moduleVersion, |
|---|
| 1325 | (m->moduleSize+dii->blockSize-1)/dii->blockSize); |
|---|
| 1326 | if (m->moduleInfoLength > 0) { |
|---|
| 1327 | print("%s descriptors: %d bytes\n", ib, m->moduleInfoLength); |
|---|
| 1328 | dump_bytes(m->moduleDescriptors, m->moduleInfoLength, indent+4); |
|---|
| 1329 | print_midesc(m->moduleInfoDesc, indent+4); |
|---|
| 1330 | } |
|---|
| 1331 | } |
|---|
| 1332 | if (dii->privateDataLength > 0) { |
|---|
| 1333 | print("%s priv data: %d bytes\n", ib, dii->privateDataLength); |
|---|
| 1334 | dump_bytes(dii->privateDataBytes, dii->privateDataLength, indent); |
|---|
| 1335 | } |
|---|
| 1336 | print("%s %s 0x%08x\n", ib, dii->section_syntax_indicator ? "crc" : "chksum", dii->checksum_CRC32); |
|---|
| 1337 | |
|---|
| 1338 | } |
|---|
| 1339 | |
|---|
| 1340 | |
|---|
| 1341 | void DLIB_SDDS_PrintDdbSection (sddsDdbPtr_t ddb, UINT32 indent) |
|---|
| 1342 | { |
|---|
| 1343 | int i, k; |
|---|
| 1344 | char ib[DLIB_MAX_PRINT_INDENT+1]; |
|---|
| 1345 | |
|---|
| 1346 | if (!ddb) return; |
|---|
| 1347 | |
|---|
| 1348 | indent = min(indent, DLIB_MAX_PRINT_INDENT); |
|---|
| 1349 | memset(ib, ' ', sizeof(ib)); |
|---|
| 1350 | ib[indent] = 0; |
|---|
| 1351 | |
|---|
| 1352 | print("%s------------- ddb section ------------\n", ib); |
|---|
| 1353 | print("%s downloadid 0x%x, moduleId 0x%x, ver 0x%x, blk# %u\n", |
|---|
| 1354 | ib, ddb->downloadId, ddb->moduleId, ddb->moduleVersion, ddb->blockNumber); |
|---|
| 1355 | print("%s %s 0x%08x ptr 0x%x, len %d\n", |
|---|
| 1356 | ib, ddb->section_syntax_indicator ? "crc" : "chksum", |
|---|
| 1357 | ddb->checksum_CRC32, ddb->blockDataBytePtr, ddb->blockDataLength); |
|---|
| 1358 | } |
|---|
| 1359 | |
|---|
| 1360 | |
|---|
| 1361 | |
|---|
| 1362 | #if COMMENT |
|---|
| 1363 | ____Test____(){} |
|---|
| 1364 | #endif |
|---|
| 1365 | |
|---|
| 1366 | #if INCLUDE_SDDS_PARSER_TEST |
|---|
| 1367 | |
|---|
| 1368 | int hexconvert(char *string, UINT8 *dest) |
|---|
| 1369 | { |
|---|
| 1370 | #define H2D(a) ((a)>='0' && (a)<='9' ? (a)-'0' : (a)>='a' && (a)<='f' ? (a)-'a'+10 : 0) |
|---|
| 1371 | UINT8 data; |
|---|
| 1372 | UINT8 *t = dest; |
|---|
| 1373 | char *s = string; |
|---|
| 1374 | while (*s) { |
|---|
| 1375 | if (*s == ' ' || *s == '\r' || *s == '\n') { |
|---|
| 1376 | s++; continue; |
|---|
| 1377 | } |
|---|
| 1378 | data = (H2D(s[0]) << 4) | H2D(s[1]); |
|---|
| 1379 | *t++ = data; |
|---|
| 1380 | s += 2; |
|---|
| 1381 | } |
|---|
| 1382 | return (t - dest); // output data len |
|---|
| 1383 | } |
|---|
| 1384 | |
|---|
| 1385 | |
|---|
| 1386 | |
|---|
| 1387 | char *ddb_sample_string = "\ |
|---|
| 1388 | 3c 71 88 00 02 c1 f2 ff 11 03 10 03 00 00 00 01 \ |
|---|
| 1389 | ff 00 01 73 00 02 00 ff 02 f2 4c 69 31 08 82 f4 \ |
|---|
| 1390 | ee 04 80 1b 86 43 e8 01 b8 68 18 80 1b 87 4b ec \ |
|---|
| 1391 | a7 f0 0d ff 05 0c 52 ab 00 00 00 00 aa 89 e2 70 \ |
|---|
| 1392 | 84 04 72 70 82 02 1c 01 aa a8 35 61 6b 00 81 00 \ |
|---|
| 1393 | 00 00 1b a0 00 00 00 03 f2 c6 77 71 02 45 98 32 \ |
|---|
| 1394 | 40 48 00 20 06 e6 ae 00 20 10 00 b4 00 2c 92 06 \ |
|---|
| 1395 | 7c 13 80 00 00 73 60 00 00 00 64 00 00 01 73 84 \ |
|---|
| 1396 | 04 54 00 dd 10 12 f5 83 00 45 00 37 48 5c 43 1b \ |
|---|
| 1397 | a4 1a 1d a4 75 31 80 00 71 00 d5 1d 40 c6 eb 10 \ |
|---|
| 1398 | f8 00 05 02 05 6e e0 90 88 18 40 0d db 02 8b c8 \ |
|---|
| 1399 | c3 76 da a3 fe 24 88 47 6b 1f 80 50 dd f6 2c 9d \ |
|---|
| 1400 | f5 bf 04 6e fd 5c 73 2f d8 cc ff d0 9e 00 07 c2 \ |
|---|
| 1401 | f9 40 0e 03 62 89 18 90 04 40 88 01 c0 81 f1 1c \ |
|---|
| 1402 | 18 70 2f 7f 20 07 03 f7 14 28 32 2b 6d 00 38 23 \ |
|---|
| 1403 | 87 9f ef f7 26 38 24 00 e0 ac a5 9f 03 00 46 08 \ |
|---|
| 1404 | 19 5c f5 06 0c b4 df 86 06 5d 9c 83 26 86 4f 0c \ |
|---|
| 1405 | a2 1c 10 21 e0 00 00 00 4b a3 09 47 08 00 00 00 \ |
|---|
| 1406 | 0c b1 04 00 6b b8 90 5e 00 00 01 08 09 11 04 c8 \ |
|---|
| 1407 | f8 40 15 97 6d 44 00 e0 cc 68 40 0e 0c ea 00 00 \ |
|---|
| 1408 | 00 04 bc de cd 0d 46 1b 18 05 00 38 39 14 2c 21 \ |
|---|
| 1409 | 0e 0e cf c4 00 e0 f2 c5 40 0e 0f cb 44 00 e1 06 \ |
|---|
| 1410 | 2c 40 0e 10 6f cf 03 f1 60 51 2c 39 48 68 a4 b8 \ |
|---|
| 1411 | 00 03 e2 1e 0e 1a 3c 6d 07 0d 1e eb 84 86 94 4a \ |
|---|
| 1412 | 20 07 09 53 2c 69 20 00 00 00 00 \ |
|---|
| 1413 | \0\0\0"; |
|---|
| 1414 | |
|---|
| 1415 | char *dii_sample_string = "\ |
|---|
| 1416 | 3b 70 64 80 00 c1 00 00 11 03 10 02 80 00 80 00\ |
|---|
| 1417 | ff 00 00 4f 00 00 00 01 0f e2 00 00 00 00 00 00\ |
|---|
| 1418 | 00 00 00 00 00 00 00 02 00 01 00 00 34 4f 00 17\ |
|---|
| 1419 | b7 15 00 0a 42 6f 6f 74 4c 6f 61 64 65 72 00 00\ |
|---|
| 1420 | 06 00 02 00 10 00 20 00 02 00 2e c9 11 00 12 b7\ |
|---|
| 1421 | 10 00 05 4e 45 57 42 59 00 00 06 08 02 00 10 00\ |
|---|
| 1422 | 20 00 00 00 00 00 00\ |
|---|
| 1423 | \0\0\0"; |
|---|
| 1424 | |
|---|
| 1425 | char *dsi_sample_string = "\ |
|---|
| 1426 | 3b 70 65 00 00 c1 00 00 11 03 10 06 80 00 00 00 \ |
|---|
| 1427 | ff 00 00 50 ff ff ff ff ff ff ff ff ff ff ff ff \ |
|---|
| 1428 | ff ff ff ff ff ff ff ff 00 00 00 38 00 01 80 00 \ |
|---|
| 1429 | 10 00 00 00 00 00 00 1e 00 02 01 0b 01 00 1e 1b \ |
|---|
| 1430 | 00 00 00 00 01 f7 01 3e 02 0b 01 00 1e 1b 00 00 \ |
|---|
| 1431 | 00 00 01 f7 01 3e 00 0a ba 08 39 33 04 80 00 09 \ |
|---|
| 1432 | 3a 80 00 00 00 00 00 00\0\0\0"; |
|---|
| 1433 | |
|---|
| 1434 | UINT8 sample_buf[1096]; |
|---|
| 1435 | |
|---|
| 1436 | void test_parse_dsi(void) |
|---|
| 1437 | { |
|---|
| 1438 | int len; |
|---|
| 1439 | sddsDsiPtr_t dsi; |
|---|
| 1440 | |
|---|
| 1441 | len = hexconvert(dsi_sample_string, sample_buf); |
|---|
| 1442 | memdump(sample_buf, len, "dsi"); |
|---|
| 1443 | DLIB_SDDS_ParseDsiSection(sample_buf, &dsi); |
|---|
| 1444 | DLIB_SDDS_PrintDsiSection(dsi, 0); |
|---|
| 1445 | DLIB_SDDS_FreeSection(dsi); |
|---|
| 1446 | } |
|---|
| 1447 | |
|---|
| 1448 | void test_parse_dii(void) |
|---|
| 1449 | { |
|---|
| 1450 | int len; |
|---|
| 1451 | sddsDiiPtr_t dii; |
|---|
| 1452 | |
|---|
| 1453 | len = hexconvert(dii_sample_string, sample_buf); |
|---|
| 1454 | memdump(sample_buf, len, "dii"); |
|---|
| 1455 | DLIB_SDDS_ParseDiiSection(sample_buf, &dii); |
|---|
| 1456 | DLIB_SDDS_PrintDiiSection(dii, 0); |
|---|
| 1457 | DLIB_SDDS_FreeSection(dii); |
|---|
| 1458 | } |
|---|
| 1459 | |
|---|
| 1460 | void test_parse_ddb(void) |
|---|
| 1461 | { |
|---|
| 1462 | int len; |
|---|
| 1463 | sddsDdbPtr_t ddb; |
|---|
| 1464 | |
|---|
| 1465 | len = hexconvert(ddb_sample_string, sample_buf); |
|---|
| 1466 | memdump(sample_buf, len, "ddb"); |
|---|
| 1467 | DLIB_SDDS_ParseDdbSection(sample_buf, &ddb); |
|---|
| 1468 | DLIB_SDDS_PrintDdbSection(ddb, 0); |
|---|
| 1469 | DLIB_SDDS_FreeSection(ddb); |
|---|
| 1470 | } |
|---|
| 1471 | |
|---|
| 1472 | #endif // INCLUDE_SDDS_PARSER_TEST |
|---|
| 1473 | |
|---|
| 1474 | |
|---|
| 1475 | #if COMMENT |
|---|
| 1476 | ____Symbol____(){} |
|---|
| 1477 | #endif |
|---|
| 1478 | |
|---|
| 1479 | |
|---|
| 1480 | |
|---|
| 1481 | |
|---|
| 1482 | #if COMMENT |
|---|
| 1483 | ____Init____(){} |
|---|
| 1484 | #endif |
|---|
| 1485 | |
|---|
| 1486 | |
|---|
| 1487 | |
|---|
| 1488 | /* end of file */ |
|---|
| 1489 | |
|---|