Ignore:
Timestamp:
2011-04-17T19:17:55Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63517c2, cfbbe1d3
Parents:
ef354b6 (diff), 8595577b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

new report structure fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/generic/net_checksum.c

    ref354b6 re50cd7f  
    5252uint16_t compact_checksum(uint32_t sum)
    5353{
    54         // shorten to the 16 bits
     54        /* Shorten to the 16 bits */
    5555        while (sum >> 16)
    5656                sum = (sum & 0xffff) + (sum >> 16);
     
    7272        size_t index;
    7373
    74         // sum all the 16 bit fields
     74        /* Sum all the 16 bit fields */
    7575        for (index = 0; index + 1 < length; index += 2)
    7676                seed += (data[index] << 8) + data[index + 1];
    7777
    78         // last odd byte with zero padding
     78        /* Last odd byte with zero padding */
    7979        if (index + 1 == length)
    8080                seed += data[index] << 8;
     
    9494        size_t index;
    9595
    96         // process full bytes
     96        /* Process full bytes */
    9797        while (length >= 8) {
    98                 // add the data
     98                /* Add the data */
    9999                seed ^= (*data) << 24;
    100100               
    101                 // for each added bit
     101                /* For each added bit */
    102102                for (index = 0; index < 8; ++index) {
    103                         // if the first bit is set
     103                        /* If the first bit is set */
    104104                        if (seed & 0x80000000) {
    105                                 // shift and divide the checksum
     105                                /* Shift and divide the checksum */
    106106                                seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
    107107                        } else {
    108                                 // shift otherwise
     108                                /* Shift otherwise */
    109109                                seed <<= 1;
    110110                        }
    111111                }
    112112               
    113                 // move to the next byte
     113                /* Move to the next byte */
    114114                ++data;
    115115                length -= 8;
    116116        }
    117117
    118         // process the odd bits
     118        /* Process the odd bits */
    119119        if (length > 0) {
    120                 // add the data with zero padding
     120                /* Add the data with zero padding */
    121121                seed ^= ((*data) & (0xff << (8 - length))) << 24;
    122122               
    123                 // for each added bit
     123                /* For each added bit */
    124124                for (index = 0; index < length; ++index) {
    125                         // if the first bit is set
     125                        /* If the first bit is set */
    126126                        if (seed & 0x80000000) {
    127                                 // shift and divide the checksum
     127                                /* Shift and divide the checksum */
    128128                                seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
    129129                        } else {
    130                                 // shift otherwise
     130                                /* Shift otherwise */
    131131                                seed <<= 1;
    132132                        }
     
    148148        size_t index;
    149149
    150         // process full bytes
     150        /* Process full bytes */
    151151        while (length >= 8) {
    152                 // add the data
     152                /* Add the data */
    153153                seed ^= (*data);
    154154               
    155                 // for each added bit
     155                /* For each added bit */
    156156                for (index = 0; index < 8; ++index) {
    157                         // if the last bit is set
     157                        /* If the last bit is set */
    158158                        if (seed & 1) {
    159                                 // shift and divide the checksum
     159                                /* Shift and divide the checksum */
    160160                                seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
    161161                        } else {
    162                                 // shift otherwise
     162                                /* Shift otherwise */
    163163                                seed >>= 1;
    164164                        }
    165165                }
    166166               
    167                 // move to the next byte
     167                /* Move to the next byte */
    168168                ++data;
    169169                length -= 8;
    170170        }
    171171
    172         // process the odd bits
     172        /* Process the odd bits */
    173173        if (length > 0) {
    174                 // add the data with zero padding
     174                /* Add the data with zero padding */
    175175                seed ^= (*data) >> (8 - length);
    176176               
    177177                for (index = 0; index < length; ++index) {
    178                         // if the last bit is set
     178                        /* If the last bit is set */
    179179                        if (seed & 1) {
    180                                 // shift and divide the checksum
     180                                /* Shift and divide the checksum */
    181181                                seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
    182182                        } else {
    183                                 // shift otherwise
     183                                /* Shift otherwise */
    184184                                seed >>= 1;
    185185                        }
     
    198198uint16_t flip_checksum(uint16_t checksum)
    199199{
    200         // flip, zero is returned as 0xFFFF (not flipped)
     200        /* Flip, zero is returned as 0xFFFF (not flipped) */
    201201        checksum = ~checksum;
    202202        return checksum ? checksum : IP_CHECKSUM_ZERO;
     
    216216uint16_t ip_checksum(uint8_t *data, size_t length)
    217217{
    218         // compute, compact and flip the data checksum
     218        /* Compute, compact and flip the data checksum */
    219219        return flip_checksum(compact_checksum(compute_checksum(0, data,
    220220            length)));
Note: See TracChangeset for help on using the changeset viewer.