private void processRx ( byte [ ] buff , int len ) { int i = 0 ; // start HDLC alg while ( i < len ) { while ( rxState . bits <= 24 && i < len ) { int b = buff [ i ++ ] & 0xff ; hdlc . fasthdlc_rx_load_nocheck ( rxState , b ) ; if ( rxState . state == 0 ) { // octet counting mode nCount = ( nCount + 1 ) % 16 ; if ( nCount == 0 ) { countError ( "on receive" ) ; } } } int res = hdlc . fasthdlc_rx_run ( rxState ) ; switch ( res ) { case FastHDLC . RETURN_COMPLETE_FLAG : // frame received and we count it countFrame ( ) ; // checking length and CRC of the received frame if ( rxFrame . len == 0 ) { } else if ( rxFrame . len < 5 ) { // frame must be at least 5 bytes in length countError ( "hdlc error, frame LI<5" ) ; } else if ( rxCRC == 0xF0B8 ) { // good frame received processFrame ( ) ; } else { countError ( "hdlc complete, wrong terms." ) ; } rxFrame . len = 0 ; rxCRC = 0xffff ; break ; case FastHDLC . RETURN_DISCARD_FLAG : // looking for next flag rxCRC = 0xffff ; rxFrame . len = 0 ; // eCount = 0; countFrame ( ) ; // "on receive, hdlc discard" countError ( "hdlc discard." ) ; break ; case FastHDLC . RETURN_EMPTY_FLAG : rxFrame . len = 0 ; break ; default : if ( rxFrame . len > 279 ) { rxState . state = 0 ; rxFrame . len = 0 ; rxCRC = 0xffff ; eCount = 0 ; countFrame ( ) ; countError ( "Overlong MTP frame, entering octet mode on link '" + name + "'" ) ; } else { rxFrame . frame [ rxFrame . len ++ ] = ( byte ) res ; rxCRC = PPP_FCS ( rxCRC , res & 0xff ) ; } } } }
Handles received data .