| [2] | 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 2003-2008 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** File: si_util.c |
|---|
| 12 | ** Description: general utility functions that can be used in SI |
|---|
| 13 | ** processing. |
|---|
| 14 | ** |
|---|
| 15 | ** Created: 03/08/2001 |
|---|
| 16 | ** |
|---|
| 17 | ** REVISION: |
|---|
| 18 | ** |
|---|
| 19 | ** $Log: $ |
|---|
| 20 | ** |
|---|
| 21 | ** |
|---|
| 22 | ****************************************************************/ |
|---|
| 23 | #include "si.h" |
|---|
| 24 | #include "si_os.h" |
|---|
| 25 | #include "si_dbg.h" |
|---|
| 26 | #include "si_util.h" |
|---|
| 27 | |
|---|
| 28 | unsigned long SI_Construct_Data( unsigned char * rawdat, unsigned long idx, unsigned long num, unsigned long shift, unsigned long mask) |
|---|
| 29 | { |
|---|
| 30 | unsigned long data = 0; |
|---|
| 31 | long i; |
|---|
| 32 | |
|---|
| 33 | if (num > 4) |
|---|
| 34 | { |
|---|
| 35 | SI_DBG_PRINT(E_SI_ERR_MSG, ("Error in SI_Construct_Data, the number of bytes has to be <= 4!!!\n")); |
|---|
| 36 | return 0; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | for (i=0; i<num; i++) |
|---|
| 40 | data |= ( ((unsigned long)rawdat[i+idx])<<((num-1-i)*8) ); |
|---|
| 41 | data >>= shift; |
|---|
| 42 | |
|---|
| 43 | return (data&mask); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | SI_RET_CODE SI_CRC32_Check ( unsigned char * data, unsigned short length) |
|---|
| 47 | { |
|---|
| 48 | #ifdef CONFIG_TABLE_WITH_CRC |
|---|
| 49 | unsigned long reg = 0xffffffff; /* Annex B of ISO/IEC 13818-1, init state all 1's */ |
|---|
| 50 | unsigned long add_mask = 0x04c11db6; /* generation poly coefficient except for bit0. */ |
|---|
| 51 | unsigned short i; |
|---|
| 52 | short bit; |
|---|
| 53 | unsigned char input, z31; |
|---|
| 54 | |
|---|
| 55 | for (i=0; i<length; i++) |
|---|
| 56 | { |
|---|
| 57 | for (bit=7; bit>=0; bit--) |
|---|
| 58 | { |
|---|
| 59 | z31 = (reg&0x80000000)?0x1:0x0; |
|---|
| 60 | reg <<= 1; |
|---|
| 61 | input = (data[i] & (0x0001<<bit))?0x01:0x00; |
|---|
| 62 | //printf("data %x, input %d\n", data[i], input); |
|---|
| 63 | if (z31 ^ input) |
|---|
| 64 | { |
|---|
| 65 | reg ^= add_mask; |
|---|
| 66 | reg |= 1; |
|---|
| 67 | } |
|---|
| 68 | //printf("reg = %x\n", reg); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | if (reg) |
|---|
| 73 | return SI_CRC_ERROR; |
|---|
| 74 | #endif /* CONFIG_TABLE_WITH_CRC */ |
|---|
| 75 | return SI_SUCCESS; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void SI_Init_Section_Mask(unsigned long *mask, unsigned char last_section_number) |
|---|
| 79 | { |
|---|
| 80 | unsigned char i; |
|---|
| 81 | for (i=0; i<8; i++) |
|---|
| 82 | { |
|---|
| 83 | mask[i] = 0; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | unsigned long SI_Chk_Section_mask(unsigned long *mask, unsigned char section_number) |
|---|
| 88 | { |
|---|
| 89 | unsigned char index, bit; |
|---|
| 90 | |
|---|
| 91 | index = section_number/32; |
|---|
| 92 | bit = section_number % 32; |
|---|
| 93 | |
|---|
| 94 | return (mask[index]&(1<<bit)); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | SI_RET_CODE SI_Chk_Section_complete(unsigned long *mask, unsigned char last_section_number) |
|---|
| 98 | { |
|---|
| 99 | unsigned char i; |
|---|
| 100 | |
|---|
| 101 | for (i = 0; i <= last_section_number; ++i) |
|---|
| 102 | { |
|---|
| 103 | if (SI_Chk_Section_mask(mask,i) == 0) |
|---|
| 104 | { |
|---|
| 105 | return SI_OTHER_ERROR; /* not all sections received */ |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | return SI_SUCCESS; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void SI_Set_Section_mask(unsigned long *mask, unsigned char section_number) |
|---|
| 113 | { |
|---|
| 114 | unsigned char index, bit; |
|---|
| 115 | |
|---|
| 116 | index = section_number/32; |
|---|
| 117 | bit = section_number % 32; |
|---|
| 118 | |
|---|
| 119 | mask[index] |= (1<<bit); |
|---|
| 120 | } |
|---|
| 121 | |
|---|