Order Tray | Contact Us | Home | SIG Lists

[ax25-layer2] Comments on OpenAX.25 pseudo-code

Samuel A. Falvo II sam.falvo at gmail.com
Sat Aug 5 17:02:19 UTC 2006


On 8/4/06, Pete Loveall AE5PL <pete at ae5pl.net> wrote:
> My understanding of Samuel's intent of OpenAX.25 is to give us a generic,
> open basis on which to build layer 3 interfaces, etc.  That is definitely
> within the scope of this list.  Again, my intent for creating this list is

Thanks.  Here's what I have so far:

typedef struct AX25Connection AX25Connection;

struct AX25Connection
{
    char                 calledAddress[7];
    char                 calledMask[7];
    char                 callingAddress[7];
    char                 callingMask[7];
    int                  isConnected;
    int                  vR;
    int                  vS;
    int                  vA;
    AX25Queue            outboundPacketQueue;

    void (*I)            ( AX25Connection *, char *, int * );
    void (*DuplicateI)   ( AX25Connection *, char *, int * );
    void (*S)            ( AX25Connection *, char *, int * );
    void (*ConnectedU)   ( AX25Connection *, char *, int * );
    void (*DisconnectedU)( AX25Connection *, char *, int * );
};

int
ax25_address_mismatch( char *addr, char *andmask, char *xormask )
{
    int i;

    for( i = 0; i < 7; i++ )
    {
        if( ( addr[i] & andmask[i] ) ^ xormask[i] )
            return 1;
    }

    return 0;
}

void
ax25_swap_addresses( char *frame )
{
    char t;
    int i;

    for( i = 0; i < 7; i++ )
    {
        t = frame[i];
        frame[i] = frame[i+7];
        frame[i+7] = t;
    }
}

void
ax25_reply_u( AX25Connection *cxn, char *frame, int *length, char type )
{
    ax25_swap_addresses( frame );
    frame[FRM_CTRL] = type;
    *length = U_FRAME_SIZE;

    /* Calling application must still queue the frame though */
}

int
ax25_connection_process( AX25Connection *cxn, char *frame, int *length )
{
    char ctrl;
    char pollbit;

    /* No FCS check -- assume layer 1 took care of this */

    if( *length < MINIMUM_FRAME_LENGTH )
        return ERC_RUNT;

    if( ax25_address_mismatch( frame, cxn -> calledMask, cxn ->
calledAddress ) )
        return ERC_DST_ADDRESS_MISMATCH;

    if( cxn -> isConnected )
    {
        if( ax25_address_mismatch( &frame[FRM_SRCADDR], cxn ->
callingMask, cxn -> callingAddress )
            return ERC_SRC_ADDRESS_MISMATCH;

        ctrl = frame[FRM_CTRL];
        nS = ( ctrl >> 1 ) & 0x07;
        nR = ( ctrl >> 5 ) & 0x07;

        if( ( ctrl & 0x01 ) == 0 )
        {
            if( nS < cxn -> vR )
                cxn -> DuplicateI( cxn, frame, length );
            else
            {
                cxn -> I( cxn, frame, length );
                cxn -> vR = ( nS + 1 ) & 0x07;
                cxn -> vA = nR;
            }
        }
        else if( ( ctrl & 0x03 ) == 1 )
        {
            cxn -> S( cxn, frame, length );
            cxn -> vA = nR;
        }
        else  /* ctrl & 0x03 must equal 3 */
        {
            cxn -> ConnectedU( cxn, frame, length );
        }
    }
    else
    {
        if( ( ctrl & 0x01 ) == 0 )
            ax25_reply_u( cxn, frame, length, FRAME_DM );
            /* I-frames in an unconnected state are dealt with by
             * reminding the sending station that we're currently not in
             * a connected mode.
             */

        else if( ( ctrl & 0x03 ) == 1 )
            cxn -> S( cxn, frame, length );
            /* We don't bother updating the state variables since they're
             * meaningless in an unconnected state anyway.
             */

        else
            cxn -> DisconnectedU( cxn, frame, length );
    }

    return ERC_OK;
}

I was originally going to go for something a bit more object oriented
(yes, in C) in architecture, including using some design patterns to
implement various features (e.g., using the Strategy pattern instead
of maintaining a state variable and a deluge of if-statements to
monitor it).  But that would have been way too big to post here, and
too difficult to explain how it worked unless you already had some
familiarity with the patterns used.  :)

Also, out-bound packet handling is not yet addressed.  I'm still
trying to derive a basic algorithm for that.

-- 
Samuel A. Falvo II




More information about the ax25-layer2 mailing list