CRC-32 Calculation, Test Cases and HEC TutorialCourtesy of Charles Michael Heard - Single error correction/double error detection explained, w/sample code. CRC-32 Code NotesIn < my00-220994104419@myuen.gte.com> Michael Yuen wrote: Michael> Hi All, I want to implement functions to encode and Michael> decode CRC for AAL5. Are there any written code available Michael> from FTP sites? I am aware of Vince. Are there any Michael> others? Thanks. In response Berry Kercheval stated: Berry> The AAL5 CRC is the same as the Ethernet CRC. You can find example Berry> code in many PD or freeware packages such as XModem or Kermit; or Berry> by asking archie about CRC. You should be aware that while these Berry> examples all use the "look up 1 byte at a time" mode to speed things Berry> up, the programs to build the lookup tables seem to feed the bits in Berry> in the opposite order from that which the Ethernet and AAL5 CRC expects. The accompanying code in crc32h.c takes care of the bit-ordering problem. It will definitely do the right thing if correctly used, but it is very easy to get tripped unless you pay attention to the following things: 1.) The intial value of crc_accum which you pass to update_crc is 0xFFFFFFFFL, not zero. This is true whether the code is used for CRC generation or checking. 2.) In order to generate the AAL5 CRC you must first run update_crc over the whole CPCS-PDU, including PADS, CPCS-UU, and all other trailer fields except the CRC field itself. You must then append the ones complement of the output from update_crc as the CRC field of the CPCS-PDU. 3.) In order to check the AAL5 CRC you must run update_crc over the whole CPCS-PDU including the CRC field and check that the remainder is 0xC704DD7BL, as specified in recommendation I.363. 4.) You must run gen_crc_table before using update_crc. Note that update_crc has been designed to allow for incremental calculation one cell at a time should you wish to do so. All that you need to do is to save the return value from one invocation of update_crc and pass it as the crc_accum argument to the next invocation of update_crc. -- C. M. Heard |
|