| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ****************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #include "bstd.h" |
|---|
| 23 | #include "bkni.h" |
|---|
| 24 | #include "ts_priv.h" |
|---|
| 25 | #include "ts_psi.h" |
|---|
| 26 | #include "ministd.h" |
|---|
| 27 | #include "dvb_parser.h" |
|---|
| 28 | |
|---|
| 29 | #include "si.h" |
|---|
| 30 | #include "si_util.h" |
|---|
| 31 | static nit_map_t nit_map; |
|---|
| 32 | static dvb_nit_cb_t *nit_cb = NULL; |
|---|
| 33 | |
|---|
| 34 | static uint8_t nit_version_num; |
|---|
| 35 | static uint8_t nit_last_section; |
|---|
| 36 | static uint32_t nit_section_mask[8]; |
|---|
| 37 | |
|---|
| 38 | BDBG_MODULE(dvb_nit); |
|---|
| 39 | |
|---|
| 40 | void dvb_nit_init(dvb_nit_cb_t *cb) |
|---|
| 41 | { |
|---|
| 42 | int i; |
|---|
| 43 | |
|---|
| 44 | nit_cb = cb; |
|---|
| 45 | BKNI_Memset(&nit_map, 0, sizeof(nit_map)); |
|---|
| 46 | nit_version_num = 32; |
|---|
| 47 | nit_last_section = 0; |
|---|
| 48 | for (i=0; i<8; i++) { |
|---|
| 49 | nit_section_mask[i] = 0; |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | uint32_t dvb_find_frequency_for_stream_id(uint16_t stream_id) |
|---|
| 54 | { |
|---|
| 55 | int i; |
|---|
| 56 | for (i=0; i<nit_map.num_nit; i++) { |
|---|
| 57 | if (nit_map.nit[i].stream_id == stream_id) |
|---|
| 58 | return nit_map.nit[i].frequency; |
|---|
| 59 | } |
|---|
| 60 | return 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | int dvb_nit_parse(const uint8_t *nit_buf, size_t *psize) |
|---|
| 64 | { |
|---|
| 65 | uint8_t version_num, section_num, last_section; |
|---|
| 66 | uint16_t section_len, desc_len, stream_loop_len; |
|---|
| 67 | uint16_t network_id, stream_id, orig_network_id, parsed; |
|---|
| 68 | nit_t *p_nit; |
|---|
| 69 | struct bit_state_t bs; |
|---|
| 70 | |
|---|
| 71 | BDBG_ASSERT(nit_buf && psize); |
|---|
| 72 | BDBG_MSG(("%s: enter", __FUNCTION__)); |
|---|
| 73 | |
|---|
| 74 | if ((*nit_buf != DVB_TID_NIT_ACT) && (*nit_buf != DVB_TID_NIT_OTH)) { |
|---|
| 75 | BDBG_WRN(("%s: invalid table id (0x%x)", __FUNCTION__, *nit_buf)); |
|---|
| 76 | return 0; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | bs.data = (unsigned char *)nit_buf; |
|---|
| 80 | bs.bindex = 0; |
|---|
| 81 | |
|---|
| 82 | get_bits(8, &bs); |
|---|
| 83 | |
|---|
| 84 | get_bits(4, &bs); |
|---|
| 85 | section_len = get_bits(12, &bs); |
|---|
| 86 | network_id = get_bits(16, &bs); |
|---|
| 87 | get_bits(2, &bs); |
|---|
| 88 | version_num = get_bits(5, &bs); |
|---|
| 89 | get_bits(1, &bs); |
|---|
| 90 | |
|---|
| 91 | section_num = get_bits(8, &bs); |
|---|
| 92 | last_section = get_bits(8, &bs); |
|---|
| 93 | |
|---|
| 94 | if (version_num != nit_version_num) { |
|---|
| 95 | SI_Init_Section_Mask((unsigned long *)nit_section_mask, last_section); |
|---|
| 96 | nit_last_section = last_section; |
|---|
| 97 | } |
|---|
| 98 | else if (SI_Chk_Section_mask((unsigned long *)nit_section_mask, section_num)) { |
|---|
| 99 | return 0; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | SI_Set_Section_mask((unsigned long *)nit_section_mask, section_num); |
|---|
| 103 | |
|---|
| 104 | BDBG_WRN(("NIT updated to %d->%d", nit_version_num, version_num)); |
|---|
| 105 | |
|---|
| 106 | nit_map.num_nit = 0; /* new version arrived, refresh nit_map */ |
|---|
| 107 | nit_version_num = version_num; |
|---|
| 108 | |
|---|
| 109 | get_bits(4, &bs); |
|---|
| 110 | desc_len = get_bits(12, &bs); |
|---|
| 111 | dvb_parse_descriptors((uint8_t *)&nit_buf[bs.bindex/8], desc_len, DVB_TID_NIT_ACT, NULL); |
|---|
| 112 | |
|---|
| 113 | bs.bindex = bs.bindex + desc_len*8; |
|---|
| 114 | |
|---|
| 115 | get_bits(4, &bs); |
|---|
| 116 | stream_loop_len = get_bits(12, &bs); |
|---|
| 117 | parsed = 0; |
|---|
| 118 | while (parsed<stream_loop_len) { |
|---|
| 119 | stream_id = get_bits(16, &bs); parsed += 2; |
|---|
| 120 | orig_network_id = get_bits(16, &bs); parsed+=2; |
|---|
| 121 | |
|---|
| 122 | p_nit = &nit_map.nit[nit_map.num_nit]; |
|---|
| 123 | BKNI_Memset(p_nit, 0, sizeof(nit_t)); |
|---|
| 124 | get_bits(4, &bs); |
|---|
| 125 | desc_len = get_bits(12, &bs); parsed+=2; |
|---|
| 126 | BDBG_WRN(("stream_id in NIT : %x", stream_id)); |
|---|
| 127 | |
|---|
| 128 | dvb_parse_descriptors((uint8_t *)&nit_buf[bs.bindex/8], desc_len, DVB_TID_NIT_ACT, p_nit); |
|---|
| 129 | |
|---|
| 130 | bs.bindex = bs.bindex + desc_len*8; |
|---|
| 131 | |
|---|
| 132 | p_nit->stream_id = stream_id; |
|---|
| 133 | |
|---|
| 134 | if (p_nit->frequency) { |
|---|
| 135 | nit_map.num_nit++; |
|---|
| 136 | if (nit_cb && nit_cb->cb) { |
|---|
| 137 | nit_cb->cb(p_nit, nit_cb->data); |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | else { |
|---|
| 141 | BDBG_WRN(("nit entry doesn't contain frequency")); |
|---|
| 142 | } |
|---|
| 143 | parsed += desc_len; |
|---|
| 144 | } |
|---|
| 145 | return 1; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | bool dvb_nit_complete(void) |
|---|
| 149 | { |
|---|
| 150 | return (SI_Chk_Section_complete((unsigned long *)nit_section_mask, nit_last_section) == SI_SUCCESS); |
|---|
| 151 | } |
|---|