| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2008, 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: cvt processing module |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include "bstd.h" |
|---|
| 25 | #include "bdbg.h" |
|---|
| 26 | |
|---|
| 27 | #include "dsmcc.h" |
|---|
| 28 | |
|---|
| 29 | #include "bapp_util.h" |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | BDBG_MODULE(dsmcc); |
|---|
| 33 | |
|---|
| 34 | #define CODE_VERSION_TABLE2_TAG 0x9f9c05 |
|---|
| 35 | #define CODE_VERSION_TABLE1_TAG 0x9f9c02 |
|---|
| 36 | |
|---|
| 37 | #define D_VENDOR_ID 0x345678 |
|---|
| 38 | #define D_HARDWARE_VERSION_ID 0x00550055 |
|---|
| 39 | |
|---|
| 40 | int cvt_parse(void * c, size_t msg_size, struct cvt_info_t * cvt) |
|---|
| 41 | { |
|---|
| 42 | int res; |
|---|
| 43 | int i, j; |
|---|
| 44 | size_t cvt_lenght; |
|---|
| 45 | size_t cvt_tag; |
|---|
| 46 | int cvt_type; |
|---|
| 47 | size_t num_descr; |
|---|
| 48 | size_t descr_tag; |
|---|
| 49 | size_t descr_len; |
|---|
| 50 | size_t download_type_command; |
|---|
| 51 | uint8_t number_of_cv_certificates; |
|---|
| 52 | struct bit_state_t bs; |
|---|
| 53 | |
|---|
| 54 | bs.data = (unsigned char*)c; |
|---|
| 55 | bs.bindex = 0; |
|---|
| 56 | |
|---|
| 57 | if(0xD9 != get_bits(8, &bs)){ |
|---|
| 58 | res = 1; |
|---|
| 59 | goto ExitFunc; |
|---|
| 60 | } |
|---|
| 61 | get_bits(4, &bs); |
|---|
| 62 | cvt_lenght = get_bits(12, &bs); |
|---|
| 63 | |
|---|
| 64 | cvt_tag = get_bits_aligned(24, &bs); |
|---|
| 65 | switch(cvt_tag){ |
|---|
| 66 | case CODE_VERSION_TABLE1_TAG: |
|---|
| 67 | cvt_type = 1; |
|---|
| 68 | break; |
|---|
| 69 | case CODE_VERSION_TABLE2_TAG: |
|---|
| 70 | cvt_type = 2; |
|---|
| 71 | break; |
|---|
| 72 | default: |
|---|
| 73 | res = 2; |
|---|
| 74 | goto ExitFunc; |
|---|
| 75 | } |
|---|
| 76 | /* skip length_field */ |
|---|
| 77 | if(0 == get_bits(1, &bs)){ |
|---|
| 78 | get_bits(7, &bs); |
|---|
| 79 | }else{ |
|---|
| 80 | i = get_bits(7, &bs); |
|---|
| 81 | while(0 != i--){ |
|---|
| 82 | get_bits(8, &bs); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | if(2 == cvt_type){ |
|---|
| 87 | cvt->protocol_version = get_bits(8, &bs); |
|---|
| 88 | cvt->configuration_count_change = get_bits(8, &bs); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | num_descr = get_bits(8, &bs); |
|---|
| 92 | |
|---|
| 93 | for(i = 0; i < num_descr; i++){ |
|---|
| 94 | descr_tag = get_bits(8, &bs); |
|---|
| 95 | switch(descr_tag){ |
|---|
| 96 | case 0x0: /* vendor id */ |
|---|
| 97 | descr_len = get_bits(8, &bs); |
|---|
| 98 | if(3 != descr_len){ |
|---|
| 99 | res = 4; |
|---|
| 100 | goto ExitFunc; |
|---|
| 101 | } |
|---|
| 102 | cvt->vendor_id = get_bits_aligned(24, &bs); |
|---|
| 103 | break; |
|---|
| 104 | case 0x1: /* hardware version id */ |
|---|
| 105 | descr_len = get_bits(8, &bs); |
|---|
| 106 | if(4 != descr_len){ |
|---|
| 107 | res = 4; |
|---|
| 108 | goto ExitFunc; |
|---|
| 109 | } |
|---|
| 110 | cvt->hardware_version_id = get_bits_aligned(32, &bs); |
|---|
| 111 | break; |
|---|
| 112 | default: /* consume unknown descriptor */ |
|---|
| 113 | descr_len = get_bits(8, &bs); |
|---|
| 114 | for(j = descr_len; j > 0; j--){ |
|---|
| 115 | get_bits(8, &bs); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | download_type_command = get_bits(8, &bs); |
|---|
| 120 | if(download_type_command > 1){ /* 0 = immediate, 1 = deferred */ |
|---|
| 121 | res = 6; |
|---|
| 122 | goto ExitFunc; |
|---|
| 123 | } |
|---|
| 124 | if(2 == cvt_type){ |
|---|
| 125 | cvt->location_type = get_bits(8, &bs); |
|---|
| 126 | switch(cvt->location_type){ |
|---|
| 127 | case 0: |
|---|
| 128 | cvt->source_ID = get_bits(16, &bs); |
|---|
| 129 | break; |
|---|
| 130 | case 1: |
|---|
| 131 | cvt->frequency_vector = get_bits(16, &bs); |
|---|
| 132 | cvt->modulation_type = get_bits(8, &bs); |
|---|
| 133 | get_bits(3, &bs); |
|---|
| 134 | cvt->pid = get_bits(13, &bs); |
|---|
| 135 | break; |
|---|
| 136 | case 2: |
|---|
| 137 | cvt->frequency_vector = get_bits(16, &bs); |
|---|
| 138 | cvt->modulation_type = get_bits(8, &bs); |
|---|
| 139 | cvt->program_number = get_bits(16, &bs); |
|---|
| 140 | break; |
|---|
| 141 | default: |
|---|
| 142 | res = 7; |
|---|
| 143 | goto ExitFunc; |
|---|
| 144 | } |
|---|
| 145 | }else{ |
|---|
| 146 | cvt->location_type = 1; |
|---|
| 147 | cvt->frequency_vector = get_bits(16, &bs); |
|---|
| 148 | cvt->modulation_type = get_bits(8, &bs); |
|---|
| 149 | get_bits(3, &bs); |
|---|
| 150 | cvt->pid = get_bits(13, &bs); |
|---|
| 151 | } |
|---|
| 152 | cvt->code_file_name_length = get_bits(8, &bs); |
|---|
| 153 | for(i = 0 ; i < cvt->code_file_name_length; i++){ |
|---|
| 154 | cvt->code_file_name[i] = get_bits(8, &bs); |
|---|
| 155 | } |
|---|
| 156 | if(2 == cvt_type){ |
|---|
| 157 | number_of_cv_certificates = get_bits(8, &bs); |
|---|
| 158 | if(0 != number_of_cv_certificates){ |
|---|
| 159 | res = 8; |
|---|
| 160 | goto ExitFunc; |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | res = 0; |
|---|
| 164 | ExitFunc: |
|---|
| 165 | return res; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | int dsmcc_dii_parse(void * data, size_t msg_size, struct dii_info_t * dii) |
|---|
| 169 | { |
|---|
| 170 | struct bit_state_t bs; |
|---|
| 171 | uint8_t table_id; |
|---|
| 172 | uint16_t section_length; |
|---|
| 173 | uint16_t compatibility_descriptor_length; |
|---|
| 174 | int res; |
|---|
| 175 | |
|---|
| 176 | bs.data = (unsigned char *)data; |
|---|
| 177 | bs.bindex = 0; |
|---|
| 178 | table_id = get_bits(8, &bs); |
|---|
| 179 | get_bits(4, &bs); |
|---|
| 180 | section_length = get_bits(12, &bs); |
|---|
| 181 | get_bits(16, &bs); /* table_id_extension */ |
|---|
| 182 | get_bits(2, &bs); |
|---|
| 183 | if(0 != get_bits(5, &bs)){ |
|---|
| 184 | res = 1; |
|---|
| 185 | goto ExitFunc; |
|---|
| 186 | } |
|---|
| 187 | get_bits(1, &bs); /* current_next_indicator */ |
|---|
| 188 | if(0 != get_bits(8, &bs)){ /* section_number */ |
|---|
| 189 | res = 2; |
|---|
| 190 | goto ExitFunc; |
|---|
| 191 | } |
|---|
| 192 | if(0 != get_bits(8, &bs)){ /* last_section_number */ |
|---|
| 193 | res = 2; |
|---|
| 194 | goto ExitFunc; |
|---|
| 195 | } |
|---|
| 196 | if(0x11 != get_bits(8, &bs)){ /* protocolDiscriminator */ |
|---|
| 197 | res = 3; |
|---|
| 198 | goto ExitFunc; |
|---|
| 199 | } |
|---|
| 200 | if(0x03 != get_bits(8, &bs)){ /* DsmccType */ |
|---|
| 201 | res = 4; |
|---|
| 202 | goto ExitFunc; |
|---|
| 203 | } |
|---|
| 204 | if(0x1002 != get_bits(16, &bs)){ /* MessageId */ |
|---|
| 205 | res = 5; |
|---|
| 206 | goto ExitFunc; |
|---|
| 207 | } |
|---|
| 208 | dii->transaction_id = get_bits_aligned(32, &bs); |
|---|
| 209 | get_bits(8, &bs); |
|---|
| 210 | if(0 != get_bits(8, &bs)){ /* adaptationLength */ |
|---|
| 211 | res = 8; |
|---|
| 212 | goto ExitFunc; |
|---|
| 213 | } |
|---|
| 214 | dii->message_length = get_bits(16, &bs); |
|---|
| 215 | dii->download_id = get_bits_aligned(32, &bs); |
|---|
| 216 | dii->block_size = get_bits(16, &bs); |
|---|
| 217 | get_bits(8, &bs); /* windowSize */ |
|---|
| 218 | get_bits(8, &bs); /* ackPeriod */ |
|---|
| 219 | get_bits_aligned(32, &bs); /* tCDownloadWindow */ |
|---|
| 220 | dii->download_scenario = get_bits_aligned(32, &bs); |
|---|
| 221 | /* skip compatibilityDescriptor */ |
|---|
| 222 | compatibility_descriptor_length = get_bits(16, &bs); |
|---|
| 223 | bs.bindex = bs.bindex + (compatibility_descriptor_length * 8); |
|---|
| 224 | |
|---|
| 225 | dii->number_of_modules = get_bits(16, &bs); |
|---|
| 226 | dii->bs.bindex = bs.bindex; |
|---|
| 227 | dii->bs.data = bs.data; |
|---|
| 228 | res = 0; |
|---|
| 229 | ExitFunc: |
|---|
| 230 | return res; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | int dsmcc_dii_next_module(struct dii_info_t * dii, struct dii_module_t * diim) |
|---|
| 234 | { |
|---|
| 235 | struct bit_state_t bs; |
|---|
| 236 | int i; |
|---|
| 237 | int res; |
|---|
| 238 | |
|---|
| 239 | bs.data = dii->bs.data; |
|---|
| 240 | bs.bindex = dii->bs.bindex; |
|---|
| 241 | diim->module_id = get_bits(16, &bs); |
|---|
| 242 | diim->module_size = get_bits_aligned(32, &bs); |
|---|
| 243 | diim->module_version = get_bits(8, &bs); |
|---|
| 244 | diim->module_info_length = get_bits(8, &bs); |
|---|
| 245 | for(i = 0; i < diim->module_info_length; i++){ |
|---|
| 246 | diim->module_info_byte[i] = get_bits(8, &bs); |
|---|
| 247 | } |
|---|
| 248 | dii->bs.bindex = bs.bindex; |
|---|
| 249 | dii->bs.data = bs.data; |
|---|
| 250 | |
|---|
| 251 | res = 0; |
|---|
| 252 | return res; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | int dsmcc_ddb_parse(void * data, size_t msg_length, struct ddb_info_t * ddb) |
|---|
| 256 | { |
|---|
| 257 | struct bit_state_t bs; |
|---|
| 258 | uint8_t table_id; |
|---|
| 259 | uint16_t section_length; |
|---|
| 260 | uint8_t version_number; |
|---|
| 261 | uint8_t section_number; |
|---|
| 262 | uint8_t last_section_number; |
|---|
| 263 | int res; |
|---|
| 264 | |
|---|
| 265 | bs.data = (unsigned char *)data; |
|---|
| 266 | bs.bindex = 0; |
|---|
| 267 | table_id = get_bits(8, &bs); |
|---|
| 268 | get_bits(4, &bs); |
|---|
| 269 | section_length = get_bits(12, &bs); |
|---|
| 270 | get_bits(16, &bs); /* table_id_extension */ |
|---|
| 271 | get_bits(2, &bs); |
|---|
| 272 | |
|---|
| 273 | version_number = get_bits(5, &bs); |
|---|
| 274 | |
|---|
| 275 | get_bits(1, &bs); /* current_next_indicator */ |
|---|
| 276 | |
|---|
| 277 | section_number = get_bits(8, &bs); |
|---|
| 278 | |
|---|
| 279 | last_section_number = get_bits(8, &bs); |
|---|
| 280 | |
|---|
| 281 | if(0x11 != get_bits(8, &bs)){ /* ProtocolDiscriminator */ |
|---|
| 282 | res = 4; |
|---|
| 283 | goto ExitFunc; |
|---|
| 284 | } |
|---|
| 285 | if(0x03 != get_bits(8, &bs)){ /* DsmccType */ |
|---|
| 286 | res = 5; |
|---|
| 287 | goto ExitFunc; |
|---|
| 288 | } |
|---|
| 289 | if(0x1003 != get_bits(16, &bs)){ /* MessageId */ |
|---|
| 290 | res = 6; |
|---|
| 291 | goto ExitFunc; |
|---|
| 292 | } |
|---|
| 293 | ddb->download_id = get_bits_aligned(32, &bs); |
|---|
| 294 | get_bits(8, &bs); /* reserved */ |
|---|
| 295 | if(0 != get_bits(8, &bs)){ /* AdaptationLength */ |
|---|
| 296 | res = 7; |
|---|
| 297 | goto ExitFunc; |
|---|
| 298 | } |
|---|
| 299 | ddb->message_length = get_bits(16, &bs); |
|---|
| 300 | /* DownloadDataBlock starts here */ |
|---|
| 301 | ddb->module_id = get_bits(16, &bs); |
|---|
| 302 | ddb->module_version = get_bits(8, &bs); |
|---|
| 303 | get_bits(8, &bs); /* reserved */ |
|---|
| 304 | ddb->block_number = get_bits(16, &bs); |
|---|
| 305 | if(section_number != (ddb->block_number & 0xFF)){ |
|---|
| 306 | res = 8; |
|---|
| 307 | goto ExitFunc; |
|---|
| 308 | } |
|---|
| 309 | ddb->data_length = ddb->message_length - 6; |
|---|
| 310 | ddb->data_bytes = data + (bs.bindex >> 3); |
|---|
| 311 | res = 0; |
|---|
| 312 | ExitFunc: |
|---|
| 313 | return res; |
|---|
| 314 | } |
|---|
| 315 | |
|---|