Exemplo n.º 1
0
// 
// autotest helper function
//
void validate_crc(crc_scheme _check,
                  unsigned int _n)
{
    unsigned int i;

    // generate pseudo-random data
    unsigned char data[_n];
    msequence ms = msequence_create_default(9);
    for (i=0; i<_n; i++)
        data[i] = msequence_generate_symbol(ms,8);
    msequence_destroy(ms);

    // generate key
    unsigned int key = crc_generate_key(_check, data, _n);

    // contend data/key are valid
    CONTEND_EXPRESSION(crc_validate_message(_check, data, _n, key));

    //
    unsigned char data_corrupt[_n];
    unsigned int j;
    for (i=0; i<_n; i++) {
        for (j=0; j<8; j++) {
            // copy original data sequence
            memmove(data_corrupt, data, _n*sizeof(unsigned char));

            // flip bit j at byte i
            data[i] ^= (1 << j);

            // contend data/key are invalid
            CONTEND_EXPRESSION(crc_validate_message(_check, data, _n, key)==0);
        }
    }
}
Exemplo n.º 2
0
// Execute the packetizer to decode an input message, return validity
// check of resulting data
//
//  _p      :   packetizer object
//  _pkt    :   input message (coded soft bits)
//  _msg    :   decoded output message
int packetizer_decode_soft(packetizer _p,
                           unsigned char * _pkt,
                           unsigned char * _msg)
{
    // copy coded message to internal buffer[0]
    memmove(_p->buffer_0, _pkt, 8*_p->packet_len);

    // 
    // decode outer level using soft decoding
    //

    // run the de-interleaver: buffer[0] > buffer[1]
    interleaver_decode_soft(_p->plan[1].q,
                            _p->buffer_0,
                            _p->buffer_1);

    // run the decoder: buffer[1] > buffer[0]
    fec_decode_soft(_p->plan[1].f,
                    _p->plan[1].dec_msg_len,
                    _p->buffer_1,
                    _p->buffer_0);

    // 
    // decode inner level using hard decoding
    //

    // run the de-interleaver: buffer[0] > buffer[1]
    interleaver_decode(_p->plan[0].q,
                       _p->buffer_0,
                       _p->buffer_1);

    // run the decoder: buffer[1] > buffer[0]
    fec_decode(_p->plan[0].f,
               _p->plan[0].dec_msg_len,
               _p->buffer_1,
               _p->buffer_0);

    // strip crc, validate message
    unsigned int key = 0;
    unsigned int i;
    for (i=0; i<_p->crc_length; i++) {
        key <<= 8;

        key |= _p->buffer_0[_p->msg_len+i];
    }

    // copy result to output
    memmove(_msg, _p->buffer_0, _p->msg_len);

    // return crc validity
    return crc_validate_message(_p->check,
                                _p->buffer_0,
                                _p->msg_len,
                                key);
}
Exemplo n.º 3
0
// Execute the packetizer to decode an input message, return validity
// check of resulting data
//
//  _p      :   packetizer object
//  _pkt    :   input message (coded bytes)
//  _msg    :   decoded output message
int packetizer_decode(packetizer _p,
                      unsigned char * _pkt,
                      unsigned char * _msg)
{
    // copy coded message to internal buffer[0]
    memmove(_p->buffer_0, _pkt, _p->packet_len);

    // execute fec/interleaver plans
    unsigned int i;
    for (i=_p->plan_len; i>0; i--) {
        // run the de-interleaver: buffer[0] > buffer[1]
        interleaver_decode(_p->plan[i-1].q,
                           _p->buffer_0,
                           _p->buffer_1);

        // run the decoder: buffer[1] > buffer[0]
        fec_decode(_p->plan[i-1].f,
                   _p->plan[i-1].dec_msg_len,
                   _p->buffer_1,
                   _p->buffer_0);
    }

    // strip crc, validate message
    unsigned int key = 0;
    for (i=0; i<_p->crc_length; i++) {
        key <<= 8;

        key |= _p->buffer_0[_p->msg_len+i];
    }

    // copy result to output
    memmove(_msg, _p->buffer_0, _p->msg_len);

    // return crc validity
    return crc_validate_message(_p->check,
                                _p->buffer_0,
                                _p->msg_len,
                                key);
}