ficdecoder.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. /*****************************************************************************
  2. Copyright(c) 2009 FCI Inc. All Rights Reserved
  3. File name : ficdecoder.c
  4. Description : fic parser
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. History :
  17. ----------------------------------------------------------------------
  18. *******************************************************************************/
  19. #include <linux/string.h>
  20. #include <linux/delay.h>
  21. #include "ficdecoder.h"
  22. #include "fci_oal.h"
  23. #define MSB(X) (((X) >> 8) & 0Xff)
  24. #define LSB(X) ((X) & 0Xff)
  25. #define BYTESWAP(X) ((LSB(X)<<8) | MSB(X))
  26. struct esbinfo_t ensemble_info[MAX_ESB_NUM];
  27. struct service_info_t service_info[MAX_SVC_NUM];
  28. struct scInfo_t sc_info[MAX_SC_NUM];
  29. struct subch_info_t subchannel_info[MAX_SUBCH_NUM];
  30. struct didp_info_t didpInfo[MAX_DIDP_NUM];
  31. static int fig0_decoder(struct fig *pFig);
  32. static int fig1_decoder(struct fig *pFig);
  33. static int fig0_ext1_decoder(u8 cn, u8 *fibBuffer, int figLength);
  34. static int fig0_ext2_decoder(u8 *fibBuffer, int figLength, int pd);
  35. static int fig0_ext3_decoder(u8 *fibBuffer, int figLength);
  36. /* static int fig0_ext4_decoder(u8 *fibBuffer, int figLength); */
  37. static int fig0_ext9_decoder(u8 *fibBuffer, int figLength);
  38. static int fig0_ext10_decoder(u8 *fibBuffer, int figLength);
  39. static int fig0_ext13_decoder(u8 *fibBuffer, int figLength, int pd);
  40. static int fig0_ext14_decoder(u8 *fibBuffer, int figLength);
  41. static int fig0_ext15_decoder(u8 *fibBuffer, int figLength, int pd);
  42. static int fig0_ext18_decoder(u8 *fibBuffer, int figLength);
  43. static int fig1_ext0_decoder(u8 *fibBuffer, int figLength);
  44. static int fig1_ext5_decoder(u8 *fibBuffer, int figLength);
  45. static int fig1_ext1_decoder(u8 *fibBuffer, int figLength);
  46. static int fig1_ext4_decoder(u8 *fibBuffer, int figLength);
  47. const u16 bitrate_profile[64][3] = { /* CU PL Bit Rates */
  48. { 16, 5, 32}, { 21, 4, 32}, { 24, 3, 32},
  49. { 29, 2, 32}, { 35, 1, 32}, { 24, 5, 48},
  50. { 29, 4, 48}, { 35, 3, 48}, { 42, 2, 48},
  51. { 52, 1, 48}, { 29, 5, 56}, { 35, 4, 56},
  52. { 42, 3, 56}, { 52, 2, 56}, { 32, 5, 64},
  53. { 42, 4, 64}, { 48, 3, 64}, { 58, 2, 64},
  54. { 70, 1, 64}, { 40, 5, 80}, { 52, 4, 80},
  55. { 58, 3, 80}, { 70, 2, 80}, { 84, 1, 80},
  56. { 48, 5, 96}, { 58, 4, 96}, { 70, 3, 96},
  57. { 84, 2, 96}, {104, 1, 96}, { 58, 5, 112},
  58. { 70, 4, 112}, { 84, 3, 112}, {104, 2, 112},
  59. { 64, 5, 128}, { 84, 4, 128}, { 96, 3, 128},
  60. {116, 2, 128}, {140, 1, 128}, { 80, 5, 160},
  61. {104, 4, 160}, {116, 3, 160}, {140, 2, 160},
  62. {168, 1, 160}, { 96, 5, 192}, {116, 4, 192},
  63. {140, 3, 192}, {168, 2, 192}, {208, 1, 192},
  64. {116, 5, 224}, {140, 4, 224}, {168, 3, 224},
  65. {208, 2, 224}, {232, 1, 224}, {128, 5, 256},
  66. {168, 4, 256}, {192, 3, 256}, {232, 2, 256},
  67. {280, 1, 256}, {160, 5, 320}, {208, 4, 320},
  68. {280, 2, 320}, {192, 5, 384}, {280, 3, 384},
  69. {416, 1, 384}
  70. };
  71. const u16 uep_profile[14][5][9] = { /* L1 L2 L3 L4 PI1 PI2 PI3 PI4 pad */
  72. /* 32kbps */
  73. {
  74. { 3, 5, 13, 3, 24, 17, 12, 17, 4},
  75. { 3, 4, 14, 3, 22, 13, 8, 13, 0},
  76. { 3, 4, 14, 3, 15, 9, 6, 8, 0},
  77. { 3, 3, 18, 0, 11, 6, 5, 0, 0},
  78. { 3, 4, 17, 0, 5, 3, 2, 0, 0}
  79. },
  80. /* 48kbps */
  81. {
  82. { 3, 5, 25, 3, 24, 18, 13, 18, 0},
  83. { 3, 4, 26, 3, 24, 14, 8, 15, 0},
  84. { 3, 4, 26, 3, 15, 10, 6, 9, 4},
  85. { 3, 4, 26, 3, 9, 6, 4, 6, 0},
  86. { 4, 3, 26, 3, 5, 4, 2, 3, 0}
  87. },
  88. /* 56kbps */
  89. {
  90. { 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* not use */
  91. { 6, 10, 23, 3, 23, 13, 8, 13, 8},
  92. { 6, 12, 21, 3, 16, 7, 6, 9, 0},
  93. { 6, 10, 23, 3, 9, 6, 4, 5, 0},
  94. { 6, 10, 23, 3, 5, 4, 2, 3, 0}
  95. },
  96. /* 64kbps */
  97. {
  98. { 6, 11, 28, 3, 24, 18, 12, 18, 4},
  99. { 6, 10, 29, 3, 23, 13, 8, 13, 8},
  100. { 6, 12, 27, 3, 16, 8, 6, 9, 0},
  101. { 6, 9, 33, 0, 11, 6, 5, 0, 0},
  102. { 6, 9, 31, 2, 5, 3, 2, 3, 0}
  103. },
  104. /* 80kbps */
  105. {
  106. { 6, 10, 41, 3, 24, 17, 12, 18, 4},
  107. { 6, 10, 41, 3, 23, 13, 8, 13, 8},
  108. { 6, 11, 40, 3, 16, 8, 6, 7, 0},
  109. { 6, 10, 41, 3, 11, 6, 5, 6, 0},
  110. { 6, 10, 41, 3, 6, 3, 2, 3, 0}
  111. },
  112. /* 96kbps */
  113. {
  114. { 6, 13, 50, 3, 24, 18, 13, 19, 0},
  115. { 6, 10, 53, 3, 22, 12, 9, 12, 0},
  116. { 6, 12, 51, 3, 16, 9, 6, 10, 4},
  117. { 7, 10, 52, 3, 9, 6, 4, 6, 0},
  118. { 7, 9, 53, 3, 5, 4, 2, 4, 0}
  119. },
  120. /* 112kbps */
  121. {
  122. { 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* not use */
  123. { 11, 21, 49, 3, 23, 12, 9, 14, 4},
  124. { 11, 23, 47, 3, 16, 8, 6, 9, 0},
  125. { 11, 21, 49, 3, 9, 6, 4, 8, 0},
  126. { 14, 17, 50, 3, 5, 4, 2, 5, 0}
  127. },
  128. /* 128kbps */
  129. {
  130. { 11, 20, 62, 3, 24, 17, 13, 19, 8},
  131. { 11, 21, 61, 3, 22, 12, 9, 14, 0},
  132. { 11, 22, 60, 3, 16, 9, 6, 10, 4},
  133. { 11, 21, 61, 3, 11, 6, 5, 7, 0},
  134. { 12, 19, 62, 3, 5, 3, 2, 4, 0}
  135. },
  136. /* 160kbps */
  137. {
  138. { 11, 22, 84, 3, 24, 18, 12, 19, 0},
  139. { 11, 21, 85, 3, 22, 11, 9, 13, 0},
  140. { 11, 24, 82, 3, 16, 8, 6, 11, 0},
  141. { 11, 23, 83, 3, 11, 6, 5, 9, 0},
  142. { 11, 19, 87, 3, 5, 4, 2, 4, 0}
  143. },
  144. /* 192kbps */
  145. {
  146. { 11, 21, 109, 3, 24, 20, 13, 24, 0},
  147. { 11, 20, 110, 3, 22, 13, 9, 13, 8},
  148. { 11, 24, 106, 3, 16, 10, 6, 11, 0},
  149. { 11, 22, 108, 3, 10, 6, 4, 9, 0},
  150. { 11, 20, 110, 3, 6, 4, 2, 5, 0}
  151. },
  152. /* 224kbps */
  153. {
  154. { 11, 24, 130, 3, 24, 20, 12, 20, 4},
  155. { 11, 22, 132, 3, 24, 16, 10, 15, 0},
  156. { 11, 20, 134, 3, 16, 10, 7, 9, 0},
  157. { 12, 26, 127, 3, 12, 8, 4, 11, 0},
  158. { 12, 22, 131, 3, 8, 6, 2, 6, 4}
  159. },
  160. /* 256kbps */
  161. {
  162. { 11, 26, 152, 3, 24, 19, 14, 18, 4},
  163. { 11, 22, 156, 3, 24, 14, 10, 13, 8},
  164. { 11, 27, 151, 3, 16, 10, 7, 10, 0},
  165. { 11, 24, 154, 3, 12, 9, 5, 10, 4},
  166. { 11, 24, 154, 3, 6, 5, 2, 5, 0}
  167. },
  168. /* 320kbps */
  169. {
  170. { 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* not use */
  171. { 11, 26, 200, 3, 24, 17, 9, 17, 0},
  172. { 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* not use */
  173. { 11, 25, 201, 3, 13, 9, 5, 10, 8},
  174. { 11, 26, 200, 3, 8, 5, 2, 6, 4}
  175. },
  176. /* 384kbps */
  177. {
  178. { 12, 28, 245, 3, 24, 20, 14, 23, 8},
  179. { 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* not use */
  180. { 11, 24, 250, 3, 16, 9, 7, 10, 4},
  181. { 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* not use */
  182. { 11, 27, 247, 3, 8, 6, 2, 7, 0}
  183. }
  184. };
  185. int crc_good_cnt;
  186. int crc_bad_cnt;
  187. int fic_nice_cnt;
  188. int announcement;
  189. int bbm_recfg_flag;
  190. struct esbinfo_t *get_emsemble_info(void)
  191. {
  192. return &ensemble_info[0];
  193. }
  194. struct subch_info_t *get_subchannel_info(u8 subchannel_id)
  195. {
  196. struct subch_info_t *sub_ch_info;
  197. int i;
  198. for (i = 0; i < MAX_SUBCH_NUM; i++) {
  199. sub_ch_info = &subchannel_info[i];
  200. if ((sub_ch_info->flag != 0)
  201. && (sub_ch_info->subchannel_id == subchannel_id))
  202. break;
  203. }
  204. if (i == MAX_SUBCH_NUM) {
  205. for (i = 0; i < MAX_SUBCH_NUM; i++) {
  206. sub_ch_info = &subchannel_info[i];
  207. if (sub_ch_info->flag == 0)
  208. break;
  209. }
  210. if (i == MAX_SUBCH_NUM)
  211. return NULL;
  212. }
  213. return sub_ch_info;
  214. }
  215. struct service_info_t *get_service_info_list(u8 service_index)
  216. {
  217. return &service_info[service_index];
  218. }
  219. struct service_info_t *get_service_info(u32 sid)
  220. {
  221. struct service_info_t *svc_info;
  222. int i;
  223. for (i = 0; i < MAX_SVC_NUM; i++) {
  224. svc_info = &service_info[i];
  225. if ((svc_info->flag != 0) && (sid == svc_info->sid))
  226. break;
  227. }
  228. if (i == MAX_SVC_NUM) {
  229. for (i = 0; i < MAX_SVC_NUM; i++) {
  230. svc_info = &service_info[i];
  231. if (svc_info->flag == 0) {
  232. svc_info->sid = sid;
  233. break;
  234. }
  235. }
  236. if (i == MAX_SVC_NUM)
  237. return NULL;
  238. }
  239. return svc_info;
  240. }
  241. struct scInfo_t *get_sc_info(u16 scid)
  242. {
  243. struct scInfo_t *pScInfo;
  244. int i;
  245. for (i = 0; i < MAX_SC_NUM; i++) {
  246. pScInfo = &sc_info[i];
  247. if ((pScInfo->flag == 99) && (pScInfo->scid == scid)) {
  248. /* pScInfo->scid = 0xffff; */
  249. break;
  250. }
  251. }
  252. if (i == MAX_SVC_NUM) {
  253. for (i = 0; i < MAX_SVC_NUM; i++) {
  254. pScInfo = &sc_info[i];
  255. if (pScInfo->flag == 0)
  256. break;
  257. }
  258. if (i == MAX_SC_NUM)
  259. return NULL;
  260. }
  261. return pScInfo;
  262. }
  263. static unsigned short crc16(unsigned char *fibBuffer, int len)
  264. {
  265. int i, j, k;
  266. unsigned int sta, din;
  267. unsigned int crc_tmp = 0x0;
  268. int crc_buf[16];
  269. int crc_coff[16] = { /* CRC16 CCITT REVERSED */
  270. 0, 0, 0, 0, /* 0x0 */
  271. 1, 0, 0, 0, /* 0x8 */
  272. 0, 0, 0, 1, /* 0x1 */
  273. 0, 0, 0, 1 /* 0x1 */
  274. };
  275. for (j = 0; j < 16; j++)
  276. crc_buf[j] = 0x1;
  277. for (i = 0; i < len; i++) {
  278. sta = fibBuffer[i] & 0xff;
  279. for (k = 7; k >= 0; k--) {
  280. din = ((sta >> k) & 0x1) ^ (crc_buf[15] & 0x1);
  281. for (j = 15; j > 0; j--)
  282. crc_buf[j] =
  283. (crc_buf[j-1] & 0x1)
  284. ^ ((crc_coff[j-1] * din) & 0x1);
  285. crc_buf[0] = din;
  286. }
  287. }
  288. crc_tmp = 0;
  289. for (j = 15; j >= 0; j--)
  290. crc_tmp = (crc_tmp << 1) | (crc_buf[j] & 0x1);
  291. return ~crc_tmp & 0xffff;
  292. }
  293. int fic_crc_ctrl = 1; /* fic crc check enable */
  294. int fic_decoder(struct fic *pfic, u16 length)
  295. {
  296. struct fib *pfib;
  297. int result = 0;
  298. int i;
  299. u16 bufferCnt;
  300. bufferCnt = length;
  301. if (bufferCnt % 32) {
  302. /* print_log(NULL
  303. , "FIC BUFFER LENGTH ERROR %d\n", bufferCnt); */
  304. return 1;
  305. }
  306. for (i = 0; i < bufferCnt/32; i++) {
  307. pfib = &pfic->fib[i];
  308. if (fic_crc_ctrl) {
  309. if (crc16(pfib->data, 30) == BYTESWAP(pfib->crc)) {
  310. crc_good_cnt++;
  311. result = fib_decoder(pfib);
  312. } else {
  313. crc_bad_cnt++;
  314. /* print_log(NULL, "CRC ERROR: FIB %d\n", i); */
  315. }
  316. } else {
  317. result = fib_decoder(pfib);
  318. crc_good_cnt++;
  319. }
  320. }
  321. return result;
  322. }
  323. int fib_decoder(struct fib *pfib)
  324. {
  325. struct fig *pFig;
  326. int type, length;
  327. int fib_ptr = 0;
  328. int result = 0;
  329. while (fib_ptr < 30) {
  330. pFig = (struct fig *)&pfib->data[fib_ptr];
  331. type = (pFig->head >> 5) & 0x7;
  332. length = pFig->head & 0x1f;
  333. if (pFig->head == 0xff || !length) { /* end mark */
  334. break;
  335. }
  336. fic_nice_cnt++;
  337. switch (type) {
  338. case 0:
  339. result = fig0_decoder(pFig); /* MCI & SI */
  340. break;
  341. case 1:
  342. result = fig1_decoder(pFig); /* SI */
  343. /*
  344. if (result)
  345. print_log(NULL, "SI Error [%x]\n", result);
  346. */
  347. break;
  348. default:
  349. /*
  350. print_log(NULL, "FIG 0x%X Length : 0x%X 0x%X\n"
  351. , type, length, fib_ptr);
  352. */
  353. result = 1;
  354. break;
  355. }
  356. fib_ptr += length + 1;
  357. }
  358. return result;
  359. }
  360. /*
  361. * MCI & SI
  362. */
  363. static int fig0_decoder(struct fig *pFig)
  364. {
  365. int result = 0;
  366. int extension, length, pd;
  367. u8 cn;
  368. length = pFig->head & 0x1f;
  369. cn = (pFig->data[0] & 0x80) >> 7;
  370. if ((bbm_recfg_flag == 1) && (cn == 0))
  371. return 0;
  372. /* if (cn)
  373. print_log(NULL, "N");
  374. */
  375. extension = pFig->data[0] & 0x1F;
  376. pd = (pFig->data[0] & 0x20) >> 5;
  377. switch (extension) {
  378. case 1:
  379. result = fig0_ext1_decoder(cn, &pFig->data[1], length);
  380. break;
  381. case 2:
  382. result = fig0_ext2_decoder(&pFig->data[1], length, pd);
  383. break;
  384. case 3: /* Service component in packet mode or without CA */
  385. result = fig0_ext3_decoder(&pFig->data[1], length);
  386. break;
  387. case 4: /* Service component with CA */
  388. /*
  389. result = fig0_ext4_decoder(&pFig->data[1], length);
  390. */
  391. break;
  392. case 9: /* Country LTO and International table */
  393. result = fig0_ext9_decoder(&pFig->data[1], length);
  394. break;
  395. case 10: /* Date & Time */
  396. result = fig0_ext10_decoder(&pFig->data[1], length-1);
  397. break;
  398. case 13:
  399. result = fig0_ext13_decoder(&pFig->data[1], length, pd);
  400. break;
  401. case 14: /* FEC */
  402. result = fig0_ext14_decoder(&pFig->data[1], length);
  403. break;
  404. case 15:
  405. result = fig0_ext15_decoder(&pFig->data[1], length, pd);
  406. break;
  407. case 0: /* Ensembel Information */
  408. case 5: /* Language */
  409. case 8: /* Service component global definition */
  410. case 17: /* Programme Type */
  411. result = dummy_decoder(&pFig->data[1], length);
  412. break;
  413. case 18: /* Announcements */
  414. if (announcement)
  415. result =
  416. fig0_ext18_decoder(&pFig->data[1], length);
  417. break;
  418. case 19: /* Announcements switching */
  419. /*
  420. print_log(NULL, "FIG 0x%X/0x%X Length : 0x%X\n"
  421. , 0, extension, length);
  422. */
  423. break;
  424. default:
  425. /*
  426. print_log(NULL, "FIG 0x%X/0x%X Length : 0x%X\n"
  427. , 0, extension, length);
  428. */
  429. result = 1;
  430. break;
  431. }
  432. return result;
  433. }
  434. static int fig1_decoder(struct fig *pFig)
  435. {
  436. int result = 0;
  437. int length;
  438. int /*charset, oe,*/ extension;
  439. length = pFig->head & 0x1f;
  440. /* charset = (pFig->data[0] >> 4) & 0xF; */
  441. /* oe = (pFig->data[0]) >> 3 & 0x1; */
  442. extension = pFig->data[0] & 0x7;
  443. switch (extension) {
  444. case 0: /* Ensembel Label */
  445. result = fig1_ext0_decoder(&pFig->data[1], length);
  446. break;
  447. case 1: /* Programme service Label */
  448. result = fig1_ext1_decoder(&pFig->data[1], length);
  449. break;
  450. case 5: /* Data service Label */
  451. result = fig1_ext5_decoder(&pFig->data[1], length);
  452. break;
  453. case 4: /* Service component Label */
  454. result = fig1_ext4_decoder(&pFig->data[1], length);
  455. break;
  456. default:
  457. /*
  458. print_log(NULL, "FIG 0x%X/0x%X Length : 0x%X\n"
  459. , 1, extension, length);
  460. */
  461. result = 1;
  462. break;
  463. }
  464. return result;
  465. }
  466. int dummy_decoder(u8 *fibBuffer, int figLength)
  467. {
  468. return 0;
  469. }
  470. /*
  471. * FIG 0/1 MCI, Sub Channel Organization
  472. */
  473. int fig0_ext1_decoder(u8 cn, u8 *fibBuffer, int figLength)
  474. {
  475. u8 sta;
  476. int result = 0;
  477. int readcnt = 0;
  478. u8 subchannel_id;
  479. struct subch_info_t *sub_ch_info;
  480. while (figLength-1 > readcnt) {
  481. sta = fibBuffer[readcnt++];
  482. if (sta == 0xFF)
  483. break;
  484. subchannel_id = (sta >> 2) & 0x3F;
  485. sub_ch_info = get_subchannel_info(subchannel_id);
  486. if (sub_ch_info == NULL) {
  487. /*print_log(NULL, "subchannel_info error ..\n"); */
  488. return 1;
  489. }
  490. sub_ch_info->flag = 99;
  491. sub_ch_info->mode = 0; /* T-DMB */
  492. sub_ch_info->subchannel_id = subchannel_id;
  493. sub_ch_info->start_address = (sta & 0x3) << 8;
  494. sta = fibBuffer[readcnt++];
  495. sub_ch_info->start_address |= sta;
  496. sta = fibBuffer[readcnt++];
  497. sub_ch_info->form_type = (sta & 0x80) >> 7;
  498. switch (sub_ch_info->form_type) {
  499. case 0: /* short form */
  500. sub_ch_info->table_switch = (sta & 0x40) >> 6;
  501. sub_ch_info->table_index = sta & 0x3f;
  502. break;
  503. case 1: /* long form */
  504. sub_ch_info->option = (sta & 0x70) >> 4;
  505. sub_ch_info->protect_level = (sta & 0x0c) >> 2;
  506. sub_ch_info->subch_size = (sta & 0x03) << 8;
  507. sta = fibBuffer[readcnt++];
  508. sub_ch_info->subch_size |= sta;
  509. break;
  510. default:
  511. /*
  512. print_log(NULL, "Unknown Form Type %d\n"
  513. , sub_ch_info->form_type);
  514. */
  515. result = 1;
  516. break;
  517. }
  518. if (cn) {
  519. if (sub_ch_info->re_config == 0)
  520. sub_ch_info->re_config = 1;
  521. /* ReConfig Info Updated */
  522. }
  523. }
  524. return result;
  525. }
  526. /*
  527. * FIG 0/2 MCI, Sub Channel Organization
  528. */
  529. static int fig0_ext2_decoder(u8 *fibBuffer, int figLength, int pd)
  530. {
  531. struct service_info_t *svc_info;
  532. struct subch_info_t *sub_ch_info;
  533. u8 sta;
  534. int result = 0;
  535. int readcnt = 0;
  536. u32 sid = 0xffffffff;
  537. int nscps;
  538. u32 temp;
  539. int tmid;
  540. int i;
  541. while (figLength-1 > readcnt) {
  542. temp = 0;
  543. temp = fibBuffer[readcnt++];
  544. temp = (temp << 8) | fibBuffer[readcnt++];
  545. switch (pd) {
  546. case 0: /* 16-bit sid, used for programme services */
  547. {
  548. temp = temp;
  549. /*sid = temp & 0xFFF; */
  550. sid = temp;
  551. }
  552. break;
  553. case 1: /*32bit sid, used for data service */
  554. {
  555. temp = (temp << 8) | fibBuffer[readcnt++];
  556. temp = (temp << 8) | fibBuffer[readcnt++];
  557. /*sid = temp & 0xFFFFF; */
  558. sid = temp;
  559. }
  560. break;
  561. default:
  562. break;
  563. }
  564. svc_info = get_service_info(sid);
  565. if (svc_info == NULL) {
  566. /*print_log(NULL, "get_service_info Error ...\n"); */
  567. break;
  568. }
  569. svc_info->addrType = pd;
  570. svc_info->sid = sid;
  571. svc_info->flag |= 0x02;
  572. sta = fibBuffer[readcnt++]; /* flag, CAId, nscps */
  573. nscps = sta & 0xF;
  574. svc_info->nscps = nscps;
  575. for (i = 0; i < nscps; i++) {
  576. sta = fibBuffer[readcnt++];
  577. tmid = (sta >> 6) & 0x3;
  578. /* svc_info->tmid = tmid; */
  579. switch (tmid) {
  580. case 0: /* MSC stream audio */
  581. svc_info->ascty = sta & 0x3f;
  582. sta = fibBuffer[readcnt++];
  583. if ((sta & 0x02) == 0x02) { /* Primary */
  584. svc_info->sub_channel_id
  585. = (sta >> 2) & 0x3F;
  586. svc_info->tmid = tmid;
  587. }
  588. sub_ch_info =
  589. get_subchannel_info(svc_info->sub_channel_id);
  590. if (sub_ch_info == NULL) {
  591. /*
  592. print_log(NULL
  593. , "get_subchannel_info Error ...\n");
  594. */
  595. return 1;
  596. }
  597. sub_ch_info->sid = svc_info->sid;
  598. svc_info->flag |= 0x04;
  599. break;
  600. case 1: /* MSC stream data */
  601. svc_info->dscty = sta & 0x3f;
  602. sta = fibBuffer[readcnt++];
  603. if ((sta & 0x02) == 0x02) { /* Primary */
  604. svc_info->sub_channel_id
  605. = (sta >> 2) & 0x3F;
  606. svc_info->tmid = tmid;
  607. }
  608. sub_ch_info =
  609. get_subchannel_info(svc_info->sub_channel_id);
  610. if (sub_ch_info == NULL) {
  611. /*
  612. print_log(NULL
  613. , "get_subchannel_info Error ...\n");
  614. */
  615. return 1;
  616. }
  617. sub_ch_info->sid = svc_info->sid;
  618. svc_info->flag |= 0x04;
  619. break;
  620. case 2: /* FIDC */
  621. svc_info->dscty = sta & 0x3f;
  622. sta = fibBuffer[readcnt++];
  623. if ((sta & 0x02) == 0x02) { /* Primary */
  624. svc_info->fidc_id = (sta & 0xFC) >> 2;
  625. svc_info->tmid = tmid;
  626. }
  627. svc_info->flag |= 0x04;
  628. break;
  629. case 3: /* MSC packet data */
  630. svc_info->scid = (sta & 0x3F) << 6;
  631. sta = fibBuffer[readcnt++];
  632. if ((sta & 0x02) == 0x02) { /* Primary */
  633. svc_info->scid |= (sta & 0xFC) >> 2;
  634. svc_info->tmid = tmid;
  635. }
  636. /* by iproda */
  637. svc_info->flag |= 0x04;
  638. break;
  639. default:
  640. /* print_log(NULL
  641. , "Unkown tmid [%X]\n", tmid); */
  642. result = 1;
  643. break;
  644. }
  645. }
  646. }
  647. return result;
  648. }
  649. int fig0_ext3_decoder(u8 *fibBuffer, int figLength)
  650. {
  651. u8 sta;
  652. int result = 0;
  653. int readcnt = 0;
  654. u16 scid;
  655. int i;
  656. struct scInfo_t *pScInfo;
  657. struct service_info_t *svc_info;
  658. struct subch_info_t *sub_ch_info;
  659. while (figLength-1 > readcnt) {
  660. scid = 0;
  661. sta = fibBuffer[readcnt++];
  662. scid = sta;
  663. scid = scid << 4;
  664. sta = fibBuffer[readcnt++];
  665. scid |= (sta & 0xf0) >> 4;
  666. pScInfo = get_sc_info(scid);
  667. if (pScInfo == NULL) {
  668. /* print_log(NULL, "get_sc_info Error ...\n"); */
  669. return 1;
  670. }
  671. pScInfo->flag = 99;
  672. pScInfo->scid = scid;
  673. pScInfo->scca_flag = sta & 0x1;
  674. sta = fibBuffer[readcnt++];
  675. pScInfo->dg_flag = (sta & 0x80) >> 7;
  676. pScInfo->dscty = (sta & 0x3f);
  677. sta = fibBuffer[readcnt++];
  678. pScInfo->sub_channel_id = (sta & 0xfc) >> 2;
  679. pScInfo->packet_address = sta & 0x3;
  680. pScInfo->packet_address = pScInfo->packet_address << 8;
  681. sta = fibBuffer[readcnt++];
  682. pScInfo->packet_address |= sta;
  683. if (pScInfo->scca_flag) {
  684. sta = fibBuffer[readcnt++];
  685. pScInfo->scca = sta;
  686. pScInfo->scca = pScInfo->scca << 8;
  687. sta = fibBuffer[readcnt++];
  688. pScInfo->scca |= sta;
  689. }
  690. for (i = 0; i < MAX_SVC_NUM; i++) {
  691. svc_info = &service_info[i];
  692. if (svc_info->scid == pScInfo->scid
  693. && svc_info->tmid == 3) {
  694. sub_ch_info =
  695. get_subchannel_info(pScInfo->sub_channel_id);
  696. if (sub_ch_info == NULL) {
  697. /*
  698. print_log(NULL
  699. , "get_subchannel_info Error ...\n");
  700. */
  701. return 1;
  702. }
  703. sub_ch_info->sid = svc_info->sid;
  704. svc_info->sub_channel_id
  705. = sub_ch_info->subchannel_id;
  706. }
  707. }
  708. }
  709. return result;
  710. }
  711. /*int fig0_ext4_decoder(u8 *fibBuffer, int figLength) {
  712. int result = 0;
  713. int readcnt = 0;
  714. int Mf, sub_channel_id, CAOrg;
  715. while (figLength - 1 > readcnt) {
  716. Mf = (fibBuffer[readcnt] & 0x40) >> 6;
  717. sub_channel_id = (fibBuffer[readcnt] & 0x3f);
  718. CAOrg =
  719. (fibBuffer[readcnt + 1] << 8) + fibBuffer[readcnt + 2];
  720. readcnt += 3;
  721. //print_log(NULL, "CA MF: %d, SubChiD: %d, CAOrg: %d\n"
  722. , Mf, sub_channel_id, CAOrg);
  723. }
  724. return result;
  725. }*/
  726. /*
  727. * FIG 0/9 Country, LTO and international table
  728. */
  729. int fig0_ext9_decoder(u8 *fibBuffer, int figLength)
  730. {
  731. struct esbinfo_t *esb;
  732. u8 ensemble_ecc;
  733. esb = get_emsemble_info();
  734. ensemble_ecc = fibBuffer[1];
  735. esb->ecc = ensemble_ecc;
  736. /*PRINTF("Ensemble ECC: 0x%02x\n", ensemble_ecc);*/
  737. return 0;
  738. }
  739. /*
  740. * FIG 0/10 Date & Time
  741. */
  742. int fig0_ext10_decoder(u8 *fibBuffer, int figLength)
  743. {
  744. int result = 0;
  745. u8 MJD, /*ConfInd,*/ UTCflag;
  746. /* u16 LSI; */
  747. u8 hour = 0; /*minutes = 0, seconds = 0*/
  748. u16 milliseconds = 0;
  749. MJD = (fibBuffer[0] & 0x7f) << 10;
  750. MJD |= (fibBuffer[1] << 2);
  751. MJD |= (fibBuffer[2] & 0xc0) >> 6;
  752. /*LSI = (fibBuffer[2] & 0x20) >> 5; */
  753. /*ConfInd = (fibBuffer[2] & 0x10) >> 4; */
  754. UTCflag = (fibBuffer[2] & 0x08) >> 3;
  755. hour = (fibBuffer[2] & 0x07) << 2;
  756. hour |= (fibBuffer[3] & 0xc0) >> 6;
  757. /* minutes = fibBuffer[3] & 0x3f; */
  758. if (UTCflag) {
  759. /* seconds = (fibBuffer[4] & 0xfc) >> 2; */
  760. milliseconds = (fibBuffer[4] & 0x03) << 8;
  761. milliseconds |= fibBuffer[5];
  762. }
  763. /*
  764. print_log(NULL, " %d:%d:%d.%d\n"
  765. , hour+9, minutes, seconds, milliseconds);
  766. */
  767. return result;
  768. }
  769. /*
  770. * FIG 0/13 User Application Type
  771. */
  772. int fig0_ext13_decoder(u8 *fibBuffer, int figLength, int pd)
  773. {
  774. u8 sta;
  775. int result = 0;
  776. int readcnt = 0;
  777. u32 sid = 0xffffffff;
  778. u8 SCIdS;
  779. u8 NumOfUAs;
  780. u16 UAtype;
  781. u8 UAlen;
  782. int i, j;
  783. struct service_info_t *svc_info;
  784. while (figLength-1 > readcnt) {
  785. switch (pd) {
  786. case 0: /* 16-bit sid, used for programme services */
  787. {
  788. u32 temp;
  789. temp = 0;
  790. temp = fibBuffer[readcnt++];
  791. temp = (temp << 8) | fibBuffer[readcnt++];
  792. sid = temp;
  793. }
  794. break;
  795. case 1: /* 32bit sid, used for data service */
  796. {
  797. u32 temp;
  798. temp = 0;
  799. temp = fibBuffer[readcnt++];
  800. temp = (temp << 8) | fibBuffer[readcnt++];
  801. temp = (temp << 8) | fibBuffer[readcnt++];
  802. temp = (temp << 8) | fibBuffer[readcnt++];
  803. sid = temp;
  804. }
  805. break;
  806. default:
  807. break;
  808. }
  809. svc_info = get_service_info(sid);
  810. if (svc_info == NULL) {
  811. /* print_log(NULL, "get_service_info Error ...\n"); */
  812. break;
  813. }
  814. svc_info->sid = sid;
  815. svc_info->flag |= 0x04;
  816. sta = fibBuffer[readcnt++];
  817. SCIdS = (sta & 0xf0) >> 4;
  818. svc_info->scids = SCIdS;
  819. NumOfUAs = sta & 0x0f;
  820. /* Because of Visual Radio */
  821. svc_info->num_of_user_appl = NumOfUAs;
  822. for (i = 0; i < NumOfUAs; i++) {
  823. UAtype = 0;
  824. sta = fibBuffer[readcnt++];
  825. UAtype = sta;
  826. sta = fibBuffer[readcnt++];
  827. UAtype = (UAtype << 3) | ((sta >> 5) & 0x07);
  828. /* Because of Visual Radio */
  829. UAlen = sta & 0x1f;
  830. if (UAlen > 24) {
  831. /* print_log(NULL, "UAlen Err= %d, ", UAlen); */
  832. UAlen = 24;
  833. }
  834. svc_info->user_appl_type[i] = UAtype;
  835. svc_info->user_appl_length[i] = UAlen;
  836. for (j = 0; j < UAlen; j++) {
  837. sta = fibBuffer[readcnt++];
  838. svc_info->user_appl_data[i][j] = sta;
  839. }
  840. }
  841. }
  842. return result;
  843. }
  844. int fig0_ext14_decoder(u8 *fibBuffer, int figLength)
  845. {
  846. int result = 0;
  847. int readcnt = 0;
  848. unsigned char subch, fec_scheme;
  849. struct subch_info_t *sub_ch_info;
  850. while (figLength-1 > readcnt) {
  851. subch = (fibBuffer[readcnt] & 0xfc) >> 2;
  852. fec_scheme = (fibBuffer[readcnt] & 0x03);
  853. readcnt++;
  854. /*
  855. print_log(NULL, "SubChID: %d, FEC Scheme: %d\n"
  856. , subch, fec_scheme);
  857. */
  858. sub_ch_info = get_subchannel_info(subch);
  859. if (sub_ch_info)
  860. sub_ch_info->fec_schem = fec_scheme;
  861. }
  862. return result;
  863. }
  864. /*
  865. * TMMB kjju TODO
  866. */
  867. int fig0_ext15_decoder(u8 *fibBuffer, int figLength, int pd)
  868. {
  869. u8 sta;
  870. int result = 0;
  871. int readcnt = 0;
  872. u8 subchannel_id;
  873. struct subch_info_t *sub_ch_info;
  874. while (figLength-1 > readcnt) {
  875. sta = fibBuffer[readcnt++];
  876. if (sta == 0xFF)
  877. break;
  878. subchannel_id = (sta & 0xfc) >> 2;
  879. sub_ch_info = get_subchannel_info(subchannel_id);
  880. if (sub_ch_info == NULL) {
  881. /* print_log(NULL, "subchannel_info error ..\n"); */
  882. return 1;
  883. }
  884. sub_ch_info->flag = 99;
  885. sub_ch_info->mode = 1; /* T-MMB */
  886. sub_ch_info->subchannel_id = subchannel_id;
  887. sub_ch_info->start_address = (sta & 0x3) << 8;
  888. sta = fibBuffer[readcnt++];
  889. sub_ch_info->start_address |= sta;
  890. sub_ch_info = get_subchannel_info(sub_ch_info->subchannel_id);
  891. if (sub_ch_info == NULL) {
  892. /* print_log(NULL, "subchannel_info error ..\n"); */
  893. return 1;
  894. }
  895. sta = fibBuffer[readcnt++];
  896. sub_ch_info->mod_type = (sta & 0xc0) >> 6;
  897. sub_ch_info->enc_type = (sta & 0x20) >> 5;
  898. sub_ch_info->intv_depth = (sta & 0x18) >> 3;
  899. sub_ch_info->pl = (sta & 0x04) >> 2;
  900. sub_ch_info->subch_size = (sta & 0x03) << 8;
  901. sta = fibBuffer[readcnt++];
  902. sub_ch_info->subch_size |= sta;
  903. }
  904. return result;
  905. }
  906. /*
  907. * FIG 0/18 Announcement
  908. */
  909. int fig0_ext18_decoder(u8 *fibBuffer, int figLength)
  910. {
  911. u8 sta;
  912. int result = 0;
  913. int readcnt = 0;
  914. u16 sid;
  915. /* u8 CId; */
  916. u16 AsuFlag;
  917. int nocs;
  918. int i;
  919. while (figLength-1 > readcnt) {
  920. sta = fibBuffer[readcnt++];
  921. sid = sta << 8;
  922. sta = fibBuffer[readcnt++];
  923. sid |= sta;
  924. /* print_log(NULL, "sid = 0x%X, ", sid); */
  925. sta = fibBuffer[readcnt++];
  926. AsuFlag = sta << 8;
  927. sta = fibBuffer[readcnt++];
  928. AsuFlag |= sta;
  929. /* print_log(NULL, "AsuFlag = 0x%X, ", AsuFlag); */
  930. sta = fibBuffer[readcnt++];
  931. nocs = sta & 0x1F;
  932. /* print_log(NULL, "nocs = 0x%X, ", nocs); */
  933. for (i = 0; i < nocs; i++) {
  934. sta = fibBuffer[readcnt++];
  935. /* CId = sta; */
  936. /* print_log(NULL, "CId = %d, ", CId); */
  937. }
  938. /* print_log(NULL, "\n"); */
  939. }
  940. return result;
  941. }
  942. static int fig1_ext0_decoder(u8 *fibBuffer, int figLength)
  943. {
  944. int result = 0;
  945. int readcnt = 0;
  946. int i;
  947. u16 eid;
  948. u16 flag;
  949. eid = 0;
  950. eid = fibBuffer[readcnt++];
  951. eid = eid << 8 | fibBuffer[readcnt++];
  952. for (i = 0; i < 16; i++)
  953. ensemble_info[0].label[i] = fibBuffer[readcnt++];
  954. flag = 0;
  955. flag = fibBuffer[readcnt++];
  956. flag = flag << 8 | fibBuffer[readcnt++];
  957. ensemble_info[0].label[16] = '\0';
  958. ensemble_info[0].flag = 99;
  959. ensemble_info[0].eid = eid;
  960. /*
  961. print_log(DMB_FIC_INFO"FIG 1/0 label [%x][%s]\n"
  962. , eid, ensemble_info[0].label);
  963. */
  964. for (i = 16-1; i >= 0; i--) {
  965. if (ensemble_info[0].label[i] == 0x20)
  966. ensemble_info[0].label[i] = 0;
  967. else {
  968. #ifdef FEATURE_END_CHAR
  969. if (i == 16-1)
  970. ensemble_info[0].label[i] = 0;
  971. #endif
  972. break;
  973. }
  974. }
  975. return result;
  976. }
  977. static int fig1_ext1_decoder(u8 *fibBuffer, int figLength)
  978. {
  979. struct service_info_t *svc_info;
  980. u32 temp;
  981. int result = 0;
  982. int readcnt = 0;
  983. int i;
  984. u16 sid;
  985. temp = 0;
  986. temp = fibBuffer[readcnt++];
  987. temp = temp << 8 | fibBuffer[readcnt++];
  988. sid = temp;
  989. svc_info = get_service_info(sid);
  990. if (svc_info == NULL) {
  991. /* print_log(NULL, "get_service_info Error ...\n"); */
  992. return 1;
  993. }
  994. svc_info->sid = sid;
  995. svc_info->flag |= 0x01;
  996. for (i = 0; i < 16; i++)
  997. svc_info->label[i] = fibBuffer[readcnt++];
  998. svc_info->label[16] = '\0';
  999. /* print_log(NULL, "FIG 1/1 label [%x][%s]\n", sid, svc_info->label); */
  1000. for (i = 16-1; i >= 0; i--) {
  1001. if (svc_info->label[i] == 0x20)
  1002. svc_info->label[i] = 0;
  1003. else {
  1004. #ifdef FEATURE_END_CHAR
  1005. if (i == 16-1)
  1006. svc_info->label[i] = 0;
  1007. #endif
  1008. break;
  1009. }
  1010. }
  1011. /* print_log(NULL, "FIG 1/5 label [%x][%s]\n", sid, svc_info->label); */
  1012. return result;
  1013. }
  1014. static int fig1_ext4_decoder(u8 *fibBuffer, int figLength)
  1015. {
  1016. struct scInfo_t *pScInfo;
  1017. u8 sta;
  1018. u8 pd;
  1019. u32 temp;
  1020. int result = 0;
  1021. int readcnt = 0;
  1022. int i;
  1023. u16 scid;
  1024. /* u32 sid; */
  1025. u16 flag;
  1026. sta = fibBuffer[readcnt++];
  1027. pd = (sta & 0x80) >> 7;
  1028. scid = (sta & 0x0f);
  1029. temp = 0;
  1030. temp = fibBuffer[readcnt++];
  1031. temp = temp << 8 | fibBuffer[readcnt++];
  1032. if (pd) {
  1033. temp = temp << 8 | fibBuffer[readcnt++];
  1034. temp = temp << 8 | fibBuffer[readcnt++];
  1035. /* sid = temp; */
  1036. } else {
  1037. /* sid = temp; */
  1038. }
  1039. pScInfo = get_sc_info(scid);
  1040. if (pScInfo == NULL) {
  1041. /* print_log(NULL, "get_service_info Error ...\n"); */
  1042. return 1;
  1043. }
  1044. pScInfo->flag = 99;
  1045. pScInfo->scid = scid;
  1046. for (i = 0; i < 16; i++)
  1047. pScInfo->label[i] = fibBuffer[readcnt++];
  1048. flag = 0;
  1049. flag = fibBuffer[readcnt++];
  1050. flag = flag << 8 | fibBuffer[readcnt++];
  1051. pScInfo->label[16] = '\0';
  1052. /* print_log(NULL, "FIG 1/4 label [%x][%s]\n", sid, pScInfo->label); */
  1053. for (i = 16-1; i >= 0; i--) {
  1054. if (pScInfo->label[i] == 0x20)
  1055. pScInfo->label[i] = 0;
  1056. else {
  1057. #ifdef FEATURE_END_CHAR
  1058. if (i == 16-1)
  1059. pScInfo->label[i] = 0;
  1060. #endif
  1061. break;
  1062. }
  1063. }
  1064. /*print_log(NULL, "FIG 1/5 label [%x][%s]\n", sid, svc_info->label); */
  1065. return result;
  1066. }
  1067. static int fig1_ext5_decoder(u8 *fibBuffer, int figLength)
  1068. {
  1069. struct service_info_t *svc_info;
  1070. u32 temp;
  1071. int result = 0;
  1072. int readcnt = 0;
  1073. int i;
  1074. u32 sid;
  1075. u16 flag;
  1076. temp = 0;
  1077. temp = fibBuffer[readcnt++];
  1078. temp = temp << 8 | fibBuffer[readcnt++];
  1079. temp = temp << 8 | fibBuffer[readcnt++];
  1080. temp = temp << 8 | fibBuffer[readcnt++];
  1081. sid = temp;
  1082. svc_info = get_service_info(sid);
  1083. if (svc_info == NULL) {
  1084. /* print_log(NULL, "get_service_info Error ...\n"); */
  1085. return 1;
  1086. }
  1087. svc_info->sid = sid;
  1088. svc_info->flag |= 0x01;
  1089. for (i = 0; i < 16; i++)
  1090. svc_info->label[i] = fibBuffer[readcnt++];
  1091. flag = 0;
  1092. flag = fibBuffer[readcnt++];
  1093. flag = flag << 8 | fibBuffer[readcnt++];
  1094. svc_info->label[16] = '\0';
  1095. for (i = 16-1; i >= 0; i--) {
  1096. if (svc_info->label[i] == 0x20)
  1097. svc_info->label[i] = 0;
  1098. else {
  1099. #ifdef FEATURE_END_CHAR
  1100. if (i == 16-1)
  1101. svc_info->label[i] = 0;
  1102. #endif
  1103. break;
  1104. }
  1105. }
  1106. /* print_log(NULL, "FIG 1/5 label [%x][%s]\n", sid, svc_info->label); */
  1107. return result;
  1108. }
  1109. void subchannel_org_prn(int subchannel_id)
  1110. {
  1111. struct didp_info_t didp;
  1112. struct subch_info_t *sub_ch_info;
  1113. memset(&didp, 0, sizeof(didp));
  1114. sub_ch_info = get_subchannel_info(subchannel_id);
  1115. if (sub_ch_info == NULL)
  1116. return;
  1117. if (sub_ch_info->flag == 99) {
  1118. subchannel_org_to_didp(sub_ch_info, &didp);
  1119. /*
  1120. if (sub_ch_info->service_channel_id & 0x40)
  1121. print_log(NULL, "service_channel_id = 0x%X, "
  1122. , sub_ch_info->service_channel_id & 0x3F);
  1123. else
  1124. print_log(NULL, "service_channel_id = NOTUSE, ");
  1125. */
  1126. switch (sub_ch_info->re_config) {
  1127. case 0:
  1128. /* print_log(NULL, "re_config = INIT\n"); */
  1129. break;
  1130. case 1:
  1131. /* print_log(NULL, "re_config = UPDATED\n"); */
  1132. break;
  1133. case 2:
  1134. /* print_log(NULL, "re_config = DONE\n"); */
  1135. break;
  1136. }
  1137. /* print_log(NULL, "sid = 0x%X\n", sub_ch_info->sid); */
  1138. /* didp_prn(&didp); */
  1139. }
  1140. }
  1141. void subchannel_org_clean(void)
  1142. {
  1143. int i;
  1144. memset(ensemble_info, 0, sizeof(struct esbinfo_t) * MAX_ESB_NUM);
  1145. memset(service_info, 0, sizeof(struct service_info_t) * MAX_SVC_NUM);
  1146. memset(sc_info, 0, sizeof(struct scInfo_t) * MAX_SC_NUM);
  1147. memset(subchannel_info, 0, sizeof(struct subch_info_t) * MAX_SUBCH_NUM);
  1148. for (i = 0; i < MAX_SUBCH_NUM; i++)
  1149. subchannel_info[i].flag = 0;
  1150. for (i = 0; i < MAX_SVC_NUM; i++) {
  1151. service_info[i].flag = 0;
  1152. service_info[i].scid = 0xffff;
  1153. }
  1154. for (i = 0; i < MAX_SC_NUM; i++)
  1155. sc_info[i].scid = 0xffff;
  1156. return;
  1157. }
  1158. int bitrate_to_index(u16 bitrate)
  1159. {
  1160. int index;
  1161. switch (bitrate) {
  1162. case 32:
  1163. index = 0; break;
  1164. case 48:
  1165. index = 1; break;
  1166. case 56:
  1167. index = 2; break;
  1168. case 64:
  1169. index = 3; break;
  1170. case 80:
  1171. index = 4; break;
  1172. case 96:
  1173. index = 5; break;
  1174. case 112:
  1175. index = 6; break;
  1176. case 128:
  1177. index = 7; break;
  1178. case 160:
  1179. index = 8; break;
  1180. case 192:
  1181. index = 9; break;
  1182. case 224:
  1183. index = 10; break;
  1184. case 256:
  1185. index = 11; break;
  1186. case 320:
  1187. index = 12; break;
  1188. case 384:
  1189. index = 13; break;
  1190. default:
  1191. index = -1; break;
  1192. }
  1193. return index;
  1194. }
  1195. int GetN(struct subch_info_t *sub_ch_info, int *n)
  1196. {
  1197. int result = 0;
  1198. switch (sub_ch_info->option) {
  1199. case 0:
  1200. switch (sub_ch_info->protect_level) {
  1201. case 0:
  1202. *n = sub_ch_info->subch_size / 12;
  1203. break;
  1204. case 1:
  1205. *n = sub_ch_info->subch_size / 8;
  1206. break;
  1207. case 2:
  1208. *n = sub_ch_info->subch_size / 6;
  1209. break;
  1210. case 3:
  1211. *n = sub_ch_info->subch_size / 4;
  1212. break;
  1213. default:
  1214. /*
  1215. print_log(NULL, "Unknown Protection Level %d\n"
  1216. , sub_ch_info->protect_level);
  1217. */
  1218. result = 1;
  1219. break;
  1220. }
  1221. break;
  1222. case 1:
  1223. switch (sub_ch_info->protect_level) {
  1224. case 0:
  1225. *n = sub_ch_info->subch_size / 27;
  1226. break;
  1227. case 1:
  1228. *n = sub_ch_info->subch_size / 21;
  1229. break;
  1230. case 2:
  1231. *n = sub_ch_info->subch_size / 18;
  1232. break;
  1233. case 3:
  1234. *n = sub_ch_info->subch_size / 15;
  1235. break;
  1236. default:
  1237. /*
  1238. print_log(NULL, "Unknown Protection Level %d\n"
  1239. , sub_ch_info->protect_level);
  1240. */
  1241. result = 1;
  1242. break;
  1243. }
  1244. break;
  1245. default:
  1246. /* print_log(NULL, "Unknown Option %d\n"
  1247. , sub_ch_info->option); */
  1248. result = 1;
  1249. break;
  1250. }
  1251. return result;
  1252. }
  1253. int subchannel_org_to_didp(
  1254. struct subch_info_t *sub_ch_info, struct didp_info_t *pdidp)
  1255. {
  1256. int index, bitrate, level;
  1257. int result = 0, n = 0;
  1258. u16 subch_size = 0;
  1259. u16 dataRate;
  1260. u8 intv_depth = 0;
  1261. if (sub_ch_info->flag != 99)
  1262. return 1;
  1263. switch (sub_ch_info->mode) {
  1264. case 0: /* T-DMB */
  1265. pdidp->mode = sub_ch_info->mode;
  1266. switch (sub_ch_info->form_type) {
  1267. case 0: /* short form UEP */
  1268. pdidp->subchannel_id = sub_ch_info->subchannel_id;
  1269. pdidp->start_address = sub_ch_info->start_address;
  1270. pdidp->form_type = sub_ch_info->form_type;
  1271. subch_size =
  1272. bitrate_profile[sub_ch_info->table_index][0];
  1273. pdidp->speed =
  1274. bitrate_profile[sub_ch_info->table_index][2];
  1275. level = bitrate_profile[sub_ch_info->table_index][1];
  1276. bitrate = bitrate_profile[sub_ch_info->table_index][2];
  1277. index = bitrate_to_index(bitrate);
  1278. if (index < 0) {
  1279. result = 1;
  1280. break;
  1281. }
  1282. pdidp->l1 = uep_profile[index][level-1][0];
  1283. pdidp->l2 = uep_profile[index][level-1][1];
  1284. pdidp->l3 = uep_profile[index][level-1][2];
  1285. pdidp->l4 = uep_profile[index][level-1][3];
  1286. pdidp->p1 = (u8)uep_profile[index][level-1][4];
  1287. pdidp->p2 = (u8)uep_profile[index][level-1][5];
  1288. pdidp->p3 = (u8)uep_profile[index][level-1][6];
  1289. pdidp->p4 = (u8)uep_profile[index][level-1][7];
  1290. pdidp->pad = (u8)uep_profile[index][level-1][8];
  1291. break;
  1292. case 1: /* long form EEP */
  1293. pdidp->subchannel_id = sub_ch_info->subchannel_id;
  1294. pdidp->start_address = sub_ch_info->start_address;
  1295. pdidp->form_type = sub_ch_info->form_type;
  1296. subch_size = sub_ch_info->subch_size;
  1297. pdidp->l3 = 0;
  1298. pdidp->p3 = 0;
  1299. pdidp->l4 = 0;
  1300. pdidp->p4 = 0;
  1301. pdidp->pad = 0;
  1302. if (GetN(sub_ch_info, &n)) {
  1303. result = 1;
  1304. break;
  1305. }
  1306. switch (sub_ch_info->option) {
  1307. case 0:
  1308. switch (sub_ch_info->protect_level) {
  1309. case 0:
  1310. pdidp->l1 = 6*n - 3;
  1311. pdidp->l2 = 3;
  1312. pdidp->p1 = 24;
  1313. pdidp->p2 = 23;
  1314. break;
  1315. case 1:
  1316. if (n > 1) {
  1317. pdidp->l1 = 2*n - 3;
  1318. pdidp->l2 = 4*n + 3;
  1319. pdidp->p1 = 14;
  1320. pdidp->p2 = 13;
  1321. } else {
  1322. pdidp->l1 = 5;
  1323. pdidp->l2 = 1;
  1324. pdidp->p1 = 13;
  1325. pdidp->p2 = 12;
  1326. }
  1327. break;
  1328. case 2:
  1329. pdidp->l1 = 6*n - 3;
  1330. pdidp->l2 = 3;
  1331. pdidp->p1 = 8;
  1332. pdidp->p2 = 7;
  1333. break;
  1334. case 3:
  1335. pdidp->l1 = 4*n - 3;
  1336. pdidp->l2 = 2*n + 3;
  1337. pdidp->p1 = 3;
  1338. pdidp->p2 = 2;
  1339. break;
  1340. default:
  1341. result = 1;
  1342. break;
  1343. }
  1344. pdidp->speed = 8*n;
  1345. break;
  1346. case 1:
  1347. switch (sub_ch_info->protect_level) {
  1348. case 0:
  1349. pdidp->l1 = 24*n - 3;
  1350. pdidp->l2 = 3;
  1351. pdidp->p1 = 10;
  1352. pdidp->p2 = 9;
  1353. break;
  1354. case 1:
  1355. pdidp->l1 = 24*n - 3;
  1356. pdidp->l2 = 3;
  1357. pdidp->p1 = 6;
  1358. pdidp->p2 = 5;
  1359. break;
  1360. case 2:
  1361. pdidp->l1 = 24*n - 3;
  1362. pdidp->l2 = 3;
  1363. pdidp->p1 = 4;
  1364. pdidp->p2 = 3;
  1365. break;
  1366. case 3:
  1367. pdidp->l1 = 24*n - 3;
  1368. pdidp->l2 = 3;
  1369. pdidp->p1 = 2;
  1370. pdidp->p2 = 1;
  1371. break;
  1372. default:
  1373. break;
  1374. }
  1375. pdidp->speed = 32*n;
  1376. break;
  1377. default:
  1378. result = 1;
  1379. break;
  1380. }
  1381. break;
  1382. default:
  1383. result = 1;
  1384. break;
  1385. }
  1386. if (subch_size <= pdidp->subch_size)
  1387. pdidp->reconfig_offset = 0;
  1388. else
  1389. pdidp->reconfig_offset = 1;
  1390. pdidp->subch_size = subch_size;
  1391. break;
  1392. case 1: /* T-MMB */
  1393. pdidp->mode = sub_ch_info->mode;
  1394. pdidp->start_address = sub_ch_info->start_address;
  1395. pdidp->subchannel_id = sub_ch_info->subchannel_id;
  1396. pdidp->subch_size = sub_ch_info->subch_size;
  1397. pdidp->mod_type = sub_ch_info->mod_type;
  1398. pdidp->enc_type = sub_ch_info->enc_type;
  1399. pdidp->intv_depth = sub_ch_info->intv_depth;
  1400. pdidp->pl = sub_ch_info->pl;
  1401. switch (pdidp->mod_type) {
  1402. case 0:
  1403. n = pdidp->subch_size / 18;
  1404. break;
  1405. case 1:
  1406. n = pdidp->subch_size / 12;
  1407. break;
  1408. case 2:
  1409. n = pdidp->subch_size / 9;
  1410. break;
  1411. default:
  1412. result = 1;
  1413. break;
  1414. }
  1415. switch (pdidp->intv_depth) {
  1416. case 0:
  1417. intv_depth = 16;
  1418. break;
  1419. case 1:
  1420. intv_depth = 32;
  1421. break;
  1422. case 2:
  1423. intv_depth = 64;
  1424. break;
  1425. default:
  1426. result = 1;
  1427. break;
  1428. }
  1429. if (result == 1)
  1430. break;
  1431. if (pdidp->pl) {
  1432. dataRate = n * 32;
  1433. pdidp->mi =
  1434. (((((dataRate * 3) / 2) * 24) / intv_depth) * 3)
  1435. / 4;
  1436. } else {
  1437. dataRate = n * 24;
  1438. pdidp->mi =
  1439. ((((dataRate * 2) * 24) / intv_depth) * 3) / 4;
  1440. }
  1441. break;
  1442. default:
  1443. break;
  1444. }
  1445. return result;
  1446. }
  1447. int found_all_labels(void)
  1448. {
  1449. ms_wait(1200);
  1450. return 1;
  1451. }