Example #1
0
tZGVoidReturn
adHocConnStartComplete(tZGU8 type, tZGDataPtr fourByteHeader, tZGDataPtr pBuf,
                       tZGU16 len, tZGVoidInput *appOpaquePtr)
{

    tZGU8 result = fourByteHeader[0];
    APPCXT.FSM.stateStatus= kFAILURE;

    if(result == (tZGU8)kZGResultSuccess)
    {
        ZG_PUTRSUART("    succeeded\n\r");
        APPCXT.bConnected = kZGBoolTrue;
        APPCXT.FSM.stateStatus= kSUCCESS;

        /* Enable link up/down indicates */
        if ( !ZGLibEnableIndicate( ZG_INDICATE_HANDLE(genericIndicate), kZGBoolTrue) )
        {
            ZGSYS_MODULE_ASSERT(1, (ROM FAR char*) "Enable link up/down\n\r");
        }

#ifdef ZG_CONFIG_STATIC_IP
        printIPAddr();
#endif

    }
    else
    {
        ZG_PUTRSUART("    failed\n\r");
    }

}
Example #2
0
enum tFSMValidStates
adHocScanNextState( tZGVoidInput  )
{
    enum tFSMValidStates nextState = kSTIdle;

    if ( APPCXT.FSM.stateStatus == kSUCCESS )
    {

#if defined ( ZG_CONFIG_CONSOLE )
        sprintf( (char *) g_ConsoleContext.txBuf,
        "    IBSS selected = [%ld] \n\r", (tZGU32) APPCXT.selectedBSS );

        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
#endif

        nextState = kSTConnect;
    }
    else if ( APPCXT.FSM.stateStatus == kFAILURE )
    {

#if defined ( ZG_CONFIG_CONSOLE )
        ZG_PUTRSUART("    starting network ...\n\r");
#endif

        nextState = kSTStart;
    }
    else
    {
        if ( ++(APPCXT.nScanRetryState) < MAX_ADHOC_SCAN_RETRY )
        {

#if defined ( ZG_CONFIG_CONSOLE )
            sprintf( (char *) g_ConsoleContext.txBuf,
            "    retry ... (%d/%d)\n\r",
            APPCXT.nScanRetryState,
            MAX_ADHOC_SCAN_RETRY);

            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
#endif

            nextState = kSTScan;
        }
        else
        {
#if defined ( ZG_CONFIG_CONSOLE )
            ZG_PUTRSUART("    failed ... (*)\n\r");
#endif
            ZG_SETNEXT_MODE( kZGLMNetworkModeIdle );
        }

    }

    return nextState;

}
Example #3
0
static tZGVoidReturn OutputCommandPrompt(tZGVoidInput)
{
    if ( IS_ECHO_ON() )
    {
        ZG_PUTRSUART("\n\r");
        ZG_PUTRSUART((ROM FAR char*) gCmdLinePrompt);
    }
    SET_CURSOR(gCmdLinePromptLength);
    memset(g_ConsoleContext.rxBuf, 0x00, sizeof(g_ConsoleContext.rxBuf));

}
Example #4
0
/*= Output_Monitor_Hdr =======================================================
Purpose: After clearing screen, outputs to terminal the header block of text.

Inputs:  None

Returns: None
============================================================================*/
tZGVoidReturn Output_Monitor_Hdr(tZGVoidInput)
{
    // KS:
    // EraseEntireScreen();

    ZG_PUTRSUART("\n\r");
    OutputLine('=', 79);
    ZG_PUTRSUART("* ZeroG Host Interface Monitor\n\r");
    ZG_PUTRSUART("* (c) 2008 -- ZeroG, Inc.\n\r");
    ZG_PUTRSUART("*\n\r* Type 'help' to get a list of commands.\n\r");
    OutputLine('=', 79);
    OutputCommandPrompt();

}
static tZGVoidReturn do_help_msg(tZGVoidInput)
{
    tZGU8 i;

    ZG_PUTRSUART("\n\r");
    for (i = 0; i < g_numCmds; ++i)
    {
        ZG_PUTRSUART( (ROM FAR char *) g_consoleCmd[i].p_cmdName);
        ZG_PUTRSUART("\r\t\t");
        ZG_PUTRSUART( (ROM FAR char*) g_consoleCmd[i].p_cmdHelp);
        ZG_PUTRSUART("\n\r");
    }

}
Example #6
0
tZGVoidReturn ZGErrorHandler(ROM char *p_errorString)
{
#if defined STACK_USE_UART
    ZG_PUTRSUART("ERROR: ");
    ZG_PUTRSUART(p_errorString);
    ZG_PUTRSUART("\r\n");
#endif

#if defined(USE_LCD)
    strcpypgm2ram((char*)LCDText, p_errorString);
    LCDUpdate();
#endif
    
    while (1);
}    
Example #7
0
/*****************************************************************************
 * FUNCTION: IfconfigDisplayStatus
 *
 * RETURNS: None
 *
 * PARAMS:    None
 *
 * NOTES:   Responds to the user invoking ifconfig with no parameters
 *****************************************************************************/
static tZGVoidReturn IfconfigDisplayStatus(tZGVoidInput)
{
    tZGU8 *p_mac;

    sprintf( (char *) g_ConsoleContext.txBuf,
              "\tIP addr:  %d.%d.%d.%d\n\r", AppConfig.MyIPAddr.v[0],
                                           AppConfig.MyIPAddr.v[1],
                                           AppConfig.MyIPAddr.v[2],
                                           AppConfig.MyIPAddr.v[3] );

    ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );


    p_mac = ZG_GET_MAC_ADDR();
    sprintf( (char *) g_ConsoleContext.txBuf,
             "\tMAC addr: %02X:%02X:%02X:%02X:%02X:%02X\n\r", p_mac[0], p_mac[1],
                                                            p_mac[2], p_mac[3],
                                                            p_mac[4], p_mac[5]);
    ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );



    sprintf( (char *) g_ConsoleContext.txBuf,
              "\tNetmask:  %d.%d.%d.%d\n\r", AppConfig.MyMask.v[0],
                                           AppConfig.MyMask.v[1],
                                           AppConfig.MyMask.v[2],
                                           AppConfig.MyMask.v[3] );
    ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );


    sprintf( (char *) g_ConsoleContext.txBuf,
              "\tGateway:  %d.%d.%d.%d\n\r", AppConfig.MyGateway.v[0],
                                           AppConfig.MyGateway.v[1],
                                           AppConfig.MyGateway.v[2],
                                           AppConfig.MyGateway.v[3] );
    ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );




#ifdef ZG_CONFIG_DHCP
    if ( ZG_GET_DHCP_STATE() == DHCP_ENABLED)
       ZG_PUTRSUART("\tDHCP:     Started\n\r");
    else
       ZG_PUTRSUART("\tDHCP:     Stopped\n\r");
#endif

}
Example #8
0
static void EraseEntireLine()
{
    // int i;
    ZG_PUTRSUART( (ROM FAR char*) eraseEntireLineEscapeSequence);
    CursorLeft_N(GET_CURSOR());
    SET_CURSOR(0);
}
Example #9
0
/*= CursorRight =============================================================
Purpose: Moves the cursor right by one character

Inputs:  none

Returns: none
============================================================================*/
tZGVoidReturn CursorRight(tZGVoidInput)
{
    /* if cursor is not already at the right-most position */
    if (GET_CURSOR() < GET_LEN_RX_CMD_STRING() + gCmdLinePromptLength)
    {
        SET_CURSOR( GET_CURSOR() + 1);
        ZG_PUTRSUART( (ROM FAR char*) cursorRightEscapeSequence);
    }
}
Example #10
0
/*= CursorLeft ==============================================================
Purpose: Moves the cursor left by one character

Inputs:  none

Returns: none
============================================================================*/
tZGVoidReturn CursorLeft(tZGVoidInput)
{
    /* if cursor is not already at the left-most position */
    if (GET_CURSOR() > strlenpgm( (ROM FAR char *) gCmdLinePrompt))
    {
        SET_CURSOR( GET_CURSOR() - 1);
        ZG_PUTRSUART( (ROM FAR char *) cursorLeftEscapeSequence);
    }
}
static tZGVoidReturn do_get_zg2100_version_cmd(tZGVoidInput)
{


    if ( DISPATCH_ZGLIB( ZG_LIB_FUNC(ZGLibGetChipVersion),
                         kNULL,
                         ZG_COMP_FUNC(consoleGetVerComplete),
                         kNULL ) != kZGSuccess )
    {
        ZG_PUTRSUART("Device busy, try again...\n\r");
    }
}
Example #12
0
/*= OutputLine ===============================================================
Purpose: Outputs a line of the specified character

Inputs:  lineChar -- character the comprises the line
         count    -- number of characters in the line

Returns: None
============================================================================*/
static tZGVoidReturn OutputLine(tZGS8 lineChar, tZGU8 count)
{
#if defined( STACK_USE_UART )
    tZGU8 i;

    for (i = 0; i < count; ++i)
    {
        while(BusyUART());
        putcUART(lineChar);
    }
    ZG_PUTRSUART("\n\r");
#endif
}
Example #13
0
tZGVoidReturn
adHocDisconnComplete(tZGU8 type, tZGDataPtr fourByteHeader, tZGDataPtr pBuf,
                     tZGU16 len, tZGVoidInput *appOpaquePtr)
{
    APPCXT.FSM.stateStatus= kSUCCESS;

    /* Disable link up/down indicates */
    if ( !ZGLibEnableIndicate( ZG_INDICATE_HANDLE(genericIndicate), kZGBoolFalse) )
    {
        ZGSYS_MODULE_ASSERT(1, (ROM FAR char*) "Error Disable indicate\n\r");
    }

    ZG_PUTRSUART("    succeeded\n\r");

}
Example #14
0
tZGU8
adHocScanRequest(void * const ptrRequest, tZGVoidInput *appOpaquePtr)
{
    tZGScanReqPtr ptrScan = (tZGScanReqPtr)ptrRequest;

    buildScanRequest( ptrScan );

    ptrScan->bss =  kZGBssAdHoc;
    ptrScan->snType = kZGScanTypeActive;

#if defined ( ZG_CONFIG_CONSOLE )
    ZG_PUTRSUART("Scan ...\n\r");
#endif

    return ( sizeof(tZGScanReq) );
}
tZGBool
startDynamicScan()
{
   /* If scan already in progress bail out */
   if (IS_ANY_SCAN_INPROGRESS(APPCXT.scanStatus))
       return false;

#if !defined (ZG_CONFIG_NO_ADHOCMGRII)
   if (ZG_GET_MODE() == kZGLMNetworkModeAdhoc) {
       ZG_PUTRSUART( "Can not do scan in adhoc\n\r");
       return false;
   }
#endif

   SET_USER_SCAN_INPROGRESS(APPCXT.scanStatus);
   return true;
}
Example #16
0
tZGU8
adHocConnRequest( void * const ptrRequest, tZGVoidInput *appOpaquePtr)
{
    tZGAdhocConnectReqPtr ptrConn = (tZGAdhocConnectReqPtr)ptrRequest;

    ptrConn->timeout = HSTOZGS( (tZGU16) 50);            /* *10 msec */
    ptrConn->beaconPrd = HSTOZGS( (tZGU16) 100);
    ptrConn->channel = APPCXT.bssDesc.channel;           /* Use the channel found in scan */
    memcpy( (void *) ptrConn->bssid, (const void *) APPCXT.bssDesc.bssid, kZGMACAddrLen);

    ptrConn->ssidLen = ZG_SSID_LEN();
    memcpy( (void *) ptrConn->ssid, (const void *) ZG_GET_SSID(), ptrConn->ssidLen);

    ZG_PUTRSUART("Connect ...\n\r");

    return ( sizeof(tZGAdhocConnectReq) );
}
Example #17
0
tZGU8
adHocDisconnRequest( void * const ptrRequest, tZGVoidInput *appOpaquePtr)
{
    tZGDisconnectReqPtr ptrDisconn = (tZGDisconnectReqPtr)ptrRequest;

    ptrDisconn->reasonCode = HSTOZGS( (tZGU16) 1);   /* 1: "Unspecified", 3: "STA left BSS and is deauthenticated" */
    ptrDisconn->disconnect = 1;                      /* Upon completion, MAC shall enter (0) joined state (1) idle state */
    ptrDisconn->txFrame = 0;                         /* MAC shall (0) do nothing, or (1) tx a deauth frame */

    ZG_PUTRSUART("Disconnect...\n\r");

    APPCXT.bConnected = kZGBoolFalse;
    APPCXT.FSM.bSilent =  kZGBoolFalse;

    return ( sizeof(tZGDisconnectReq) );

}
extern
tZGVoidReturn  DisplayScanList()
{
    int i;
    tZGBssDesc* pBssDesc;

    for (i=0; i < APPCXT.scanListCount; i++) {

        pBssDesc = &APPCXT.scanList[i];

        sprintf( (char *) g_ConsoleContext.txBuf,
                  "    [%u] bssid = %02X:%02X:%02X:%02X:%02X:%02X\n\r",
                  i,
                  pBssDesc->bssid[0],
                  pBssDesc->bssid[1],
                  pBssDesc->bssid[2],
                  pBssDesc->bssid[3],
                  pBssDesc->bssid[4],
                  pBssDesc->bssid[5]);

        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        DisplaySignalStrength(pBssDesc->rssi);

        sprintf( (char *) g_ConsoleContext.txBuf,
                "    indicator = %d\n\r", pBssDesc->rssi);

        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        if ( pBssDesc->ssidLen < kZGMaxSsidLen )
        {
            pBssDesc->ssid[pBssDesc->ssidLen] = '\0';
            sprintf( (char *) g_ConsoleContext.txBuf,
                     "    ssid = %s \n\r", (char *) pBssDesc->ssid);
            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
        }

        sprintf( (char *) g_ConsoleContext.txBuf,
                 "    channel = %u\n\r", pBssDesc->channel);
        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
    }
    ZG_PUTRSUART( "\n\r");
    return;
}
Example #19
0
enum tFSMValidStates
adHocMainConnNextState( tZGVoidInput  )
{

    enum tFSMValidStates nextState = kSTMaintainConnect;

    if (  ZG_GETNEXT_MODE() != kZGLMNetworkModeAdhoc )
    {

#if defined ( ZG_CONFIG_CONSOLE )
        /* We have been asked to exit from the adhoc mode */
        ZG_PUTRSUART("\n\r");   /* right justify console msgs */
#endif

        nextState  = kSTDisconnect;
    }

    return nextState;

}
extern tZGVoidReturn

ZGUserScanMgr(tZGVoidInput)

{
    tZGU32   time = ZGSYS_MODULE_GET_MSEC_TICK_COUNT();

    if (IS_USER_SCAN_INPROGRESS(APPCXT.scanStatus))  {
        if ((time - APPCXT.scanTime) > TIME_BETWEEN_SCAN) {
            if ( DISPATCH_ZGLIB( ZG_LIB_FUNC(ZGLibScan),
                                 ZG_REQ_FUNC(ZG_SCAN),
                                 ZG_COMP_FUNC(genericScanComplete),
                                 APPCXT.scanList ) != kZGSuccess )
            {
                /* If we get here no sweat we will come back and try */
                ZG_PUTRSUART( "Device busy, try again...\n\r");
            }
        }     
    }

    return;
}
Example #21
0
enum tFSMValidStates
adHocDomNextState( tZGVoidInput  )
{
    enum tFSMValidStates nextState = kSTIdle;

    if ( APPCXT.FSM.stateStatus != kFAILURE )
    {

        switch ( ZG_GET_ENC_TYPE() )
        {

        case kKeyTypeWep:
            nextState = kSTInstallWEPKey;
            break;

        case kKeyTypeCalcPsk:
        case kKeyTypePsk:
            nextState = kSTIdle;
            ZG_SETNEXT_MODE( kZGLMNetworkModeIdle );
#if defined ( ZG_CONFIG_CONSOLE )
            ZG_PUTRSUART("PSK/WPA not supported in AdHoc mode.\n\r");
#endif
            break;

        case kKeyTypeNone:
            nextState = kSTScan;
            break;

        default:
            ZGSYS_MODULE_ASSERT(1, (ROM FAR char*) "Unknown security encryption type");
            break;
        }

    }

    return nextState;

}
Example #22
0
tZGU8
adHocStartRequest( void * const ptrRequest, tZGVoidInput *appOpaquePtr)
{
    tZGAdhocStartReqPtr ptrStart = (tZGAdhocStartReqPtr)ptrRequest;

    /* choose the first channel in ordered list for network start */
    if ( ZG_GET_ACTIVE_CHANNELS() == 0u )
    {
        ZGSYS_MODULE_ASSERT(1, (ROM FAR char *)"Adhoc StartReq: empty channel list\n\r");
    }
    else
        ptrStart->channel = ZG_CHANNEL(0);

    ptrStart->beaconPrd = HSTOZGS( (tZGU16) 100);
    ptrStart->capInfo[0] = kZGAdhocMgrCapBitIbss; /* was | kZGAdhocMgrCapBitShortPreamble;  0x22 */

    /* If in WEP mode, set the corresponding bit. */
    if ( ZG_GET_ENC_TYPE() == (tZGU8)kKeyTypeWep )
    {
        ptrStart->capInfo[0] = ptrStart->capInfo[0] | kZGAdhocMgrCapBitPrivacy;
    }

    ptrStart->capInfo[1] = 0;
    ptrStart->ssidLen = ZG_SSID_LEN();
    memcpy( (void *) ptrStart->ssid, (const void*) ZG_GET_SSID(), ptrStart->ssidLen);

    /* These values are part of the adhoc network beacon */
    /* and are part of the "basic rate" set, not to be */
    /* confused with supported rate set */
    ptrStart->dataRateLen = 2;
    ptrStart->dataRates[0] = 0x82; /* 1Mbps */
    ptrStart->dataRates[1] = 0x84; /* 2Mbps */

    ZG_PUTRSUART("Start ...\n\r");

    return ( sizeof(tZGAdhocStartReq) );
}
Example #23
0
static tZGVoidReturn Delete(tZGVoidInput)
{
    unsigned int num_chars;
    unsigned int orig_index = GET_CURSOR();

    /* if cursor is not at the end of the line */
    if (GET_CURSOR() != GET_LEN_RX_CMD_STRING() + gCmdLinePromptLength)
    {
        /* Null out tmp cmd line */
        memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine));

        /* get characters before the deleted key */
        num_chars = GET_CURSOR() - gCmdLinePromptLength;
        strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, num_chars);

        /* append characters after the deleted char (if there are any) */
        if (strlen( (char *) g_ConsoleContext.rxBuf) - 1 > 0u)
        {
            strcpy( (char *) &gTmpCmdLine[num_chars], (const char *) &g_ConsoleContext.rxBuf[num_chars + 1]);
        }

        EraseEntireLine();               /* leaves g_ConsoleContext.cursorIndex at 0 */
        ZG_PUTRSUART( (ROM FAR char *) gCmdLinePrompt);

        strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine);


        ZG_PUTSUART( (char *) g_ConsoleContext.rxBuf );
        SET_CURSOR(gCmdLinePromptLength + GET_LEN_RX_CMD_STRING());
        CursorHome(); /* to first character after prompt */


        /* move cursor to point of delete */
        CursorRight_N(orig_index - gCmdLinePromptLength);
    }
}
Example #24
0
/*= Backspace ================================================================
Purpose: Performs a backspace operation on the command line

Inputs:  none

Returns: none
============================================================================*/
static tZGVoidReturn Backspace(tZGVoidInput)
{
    tZGU8 num_chars;
    tZGU8 orig_index = GET_CURSOR();

    /* if cursor is not at the left-most position */
    if (GET_CURSOR() != gCmdLinePromptLength)
    {
        /* Null out tmp cmd line */
        memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine));

        /* get characters before the backspace */
        num_chars = GET_CURSOR() - gCmdLinePromptLength - 1;
        strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, num_chars);

        /* append characters after the deleted char (if there are any) */
        if ( (GET_LEN_RX_CMD_STRING() - 1) > 0u)
        {
            strcpy( (char *) &gTmpCmdLine[num_chars], (const char *) &g_ConsoleContext.rxBuf[num_chars + 1]);
        }

        EraseEntireLine();  /* leaves g_ConsoleContext.cursorIndex at 0 */

        strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine);

        ZG_PUTRSUART( (ROM FAR char *) gCmdLinePrompt);
        ZG_PUTSUART( (char *) g_ConsoleContext.rxBuf);
        SET_CURSOR(gCmdLinePromptLength + GET_LEN_RX_CMD_STRING());

        CursorHome(); /* to first character after prompt */


        /* move cursor to point of backspace */
        CursorRight_N(orig_index - 1 - gCmdLinePromptLength);
    }
}
/*****************************************************************************
 * FUNCTION: process_cmd
 *
 * RETURNS: None
 *
 * PARAMS:  None
 *
 * NOTES:   Determines which command has been received and processes it.
 *****************************************************************************/
tZGVoidReturn process_cmd(tZGVoidInput)
{
    tZGBool new_arg;
    tZGU8 i;


    g_ConsoleContext.argc = 0;
    new_arg = kZGBoolTrue;

    // Get pointers to each token in the command string
    TokenizeCmdLine(g_ConsoleContext.rxBuf);

    // if command line nothing but white kZGSpace or a linefeed
    if ( g_ConsoleContext.argc == 0u )
    {
        return;   // nothing to do
    }

    // change the command itself (token[0]) to lower case
    for (i = 0; i < strlen((char *)g_ConsoleContext.argv[0]); ++i)
    {
        g_ConsoleContext.argv[0][i] = tolower(g_ConsoleContext.argv[0][i]);
    }


    if ( IS_ECHO_ON() )
    {
        ZG_PUTRSUART("\n\r");
    }

    switch (GetCmdId())
    {

        case HELP_MSG:
            do_help_msg();
            break;

        case GET_ZG2100_VERSION_MSG:
            do_get_zg2100_version_cmd();
            break;

        case RESET_HOST:
            Reset();
            break;

        case CLEAR_SCREEN_MSG:
            do_cls_cmd();
            break;

        case IFCONFIG_MSG:
            do_ifconfig_cmd();
            break;

        case IWCONFIG_MSG:
            do_iwconfig_cmd();
            break;

        case IWPRIV_MSG:
            do_iwpriv_cmd();
            break;

        default:
            // if we don't match one of the built-in command strings, check to
            // see if we match one of the application-defined command strings
            if (CheckForAppSpecificCommand(g_ConsoleContext.argv[0]))
            {
                ; // nothing else to do
            }
            else
            {

               sprintf((char *) g_ConsoleContext.txBuf, "Unknown cmd: %s\n\r", ARGV[0]);
               ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

            }
            break;
    }
}
/*****************************************************************************
* FUNCTION: do_iwpriv_cmd
*
* RETURNS: None
*
* PARAMS:    None
*
* NOTES:   Responds to the user invoking ifconfig
*****************************************************************************/
tZGVoidReturn do_iwpriv_cmd(tZGVoidInput)
{
    tZGU8  i;
    tZGU8  temp;
    tZGBool cont_parse;
    tZGS8* ptrString;

    gLineParseState = kZGWaitingForParamKeyword;

    // if user only typed in iwpriv with no other parameters
    if (ARGC == 1u)
    {
        IwprivDisplayStatus();
    }
    // else loop through each parameter
    else
    {
        // parse each param and set state variables
        for (i = 1; i < ARGC; ++i)
        {
            switch (gLineParseState)
            {
            case kZGWaitingForParamKeyword:

                if ( !getParam(i) )
                {
                    return;
                }

                break;

            case kZGWaitingForWpaPsk:

                /* Can only set security in idle state */
                if ( ZG_IS_CONNECTED() == kZGBoolTrue )
                {
                    ZG_PUTRSUART("Security context may only be set in idle state\n\r");
                    return;
                }

                /* The ARGV buffer is modified in place  */
                if ( !ExtractandValidateWpaPSK( ARGV[i] ) )
                {
                    ZG_PUTRSUART("WPA PSK must be exactly 64 bytes\n\r");
                    return;
                }

                ZG_SET_WPAPSK( (tZGU8Ptr) ARGV[i] );
                gLineParseState = kZGWaitingForParamKeyword;

                break;

            case kZGWaitingForWpaStr:

                /* Can only set security in idle state */
                if ( ZG_IS_CONNECTED() == kZGBoolTrue )
                {
                    ZG_PUTRSUART("Security context may only be set in idle state\n\r");
                    return;
                }

                ptrString = ARGV[i++];

                /* if the start char is found, gobble that char */
                if ( (cont_parse = ExtractWpaStrStart(ptrString)) == kZGBoolTrue)
                {
                    ptrString++;
                }

                /* this code concats tokens together with whitespace */
                /* until no more tokens or the EOS " char is found */
                while ( cont_parse && (i++ < ARGC))
                {
                    cont_parse = ExtractWpaStrEnd( ptrString );
                }

                /* if the EOS char is not found then cont parse is true */
                if (cont_parse)
                {
                    ZG_PUTRSUART("Passphrase missing EOS '\"' \n\r");
                    return;
                }

                /* temp contains the string length after call */
                if ( !ValidateWpaStr(&ptrString, &temp) )
                {
                    ZG_PUTRSUART("Passphrase must be between 8 and 63 chars\n\r");
                    return;
                }

                ZG_SET_WPA_PASSPHRASE( ptrString, temp );

                gLineParseState = kZGWaitingForParamKeyword;

                break;

            case kZGWaitingForEnc:
                /* Can only set security in idle state */
                if ( ZG_IS_CONNECTED() == kZGBoolTrue )
                {
                    ZG_PUTRSUART("Security context may only be set in idle state\n\r");
                    return;
                }

                /* temp contains the encryption type enum */
                if ( !ExtractandValidateEncType(ARGV[i], &temp) )
                {
                    ZG_PUTRSUART("Invalid encyption type\n\r");
                    return;
                }

                ZG_SET_ENC_TYPE( temp );
                gLineParseState = kZGWaitingForParamKeyword;

                break;


            case kZGWaitingForWepAuth:

                /* Can only set security in idle state */
                if ( ZG_IS_CONNECTED() == kZGBoolTrue )
                {
                    ZG_PUTRSUART("Security context may only be set in idle state\n\r");
                    return;
                }

                /* temp contains the Wep Auth type enum */
                if ( !ExtractandValidateAuthType(ARGV[i], &temp) )
                {
                    ZG_PUTRSUART("Invalid WEP Auth type\n\r");
                    return;
                }

                ZG_SET_AUTH_TYPE( temp );
                gLineParseState = kZGWaitingForParamKeyword;

                break;

            case kZGWaitingForWepKey:

                /* Can only set security in idle state */
                if ( ZG_IS_CONNECTED() == kZGBoolTrue )
                {
                    ZG_PUTRSUART("Security context may only be set in idle state\n\r");
                    return;
                }

                /* temp contains the active WEP key index 1 of 4 */
                if ( !ExtractandValidateWepIndex(ARGV[i], &temp) )
                {
                    ZG_PUTRSUART("Invalid WEP key index\n\r");
                    return;
                }

                /* check for a 3rd optional parameter */
                if ( (i+1 < ARGC) &&
                    (getParamType(ARGV[i+1]) == kZGUnknownParam) )
                {

                    i++;  /* advance to the optional param */

                    /* The ARGV buffer is modified in place  */
                    if ( ExtractandValidateWepLong( ARGV[i] ) )
                    {
                        ZG_SET_WEP_KEY_LONG( (tZGU8Ptr) ARGV[i], temp );
                    }
                    else if ( ExtractandValidateWepShort( ARGV[i] ) )
                    {
                        ZG_SET_WEP_KEY_SHORT( (tZGU8Ptr) ARGV[i], temp );
                    }
                    else
                    {
                        ZG_PUTRSUART("\n\rWarning, 64/128bit WEP key format not valid \n\r\t");
                        return;
                    }
                }

                ZG_SET_WEP_ACTIVE_INDEX(temp);

                gLineParseState = kZGWaitingForParamKeyword;
                break;

            default:

                ZGSYS_MODULE_ASSERT(2, (ROM FAR char*)"iwpriv param");
                break;

            } // end switch

        } // end for
    }

    switch (gLineParseState)
    {
    case kZGWaitingForBeacon:

        // Send an untampered frame that looks like a Beacon.
        iwpriv_beacon();

        gLineParseState = kZGWaitingForParamKeyword;
        break;

    default:
        //do nothing
        break;
    }

    if (gLineParseState != (tZGU8)kZGWaitingForParamKeyword)
    {
        ZG_PUTRSUART("Missing value after last parameter\n\r");
    }

}
Example #27
0
/*= InsertCharacter =========================================================
Purpose: Inserts and echoes an printable character into the command line at the
         cursor location.

Inputs:  c  -- char to insert

Returns: none
============================================================================*/
static tZGVoidReturn InsertCharacter(tZGS8 c)
{
    tZGU8 len;

    tZGU8 i;
    tZGU8 orig_cursor_index = GET_CURSOR();
    tZGU8 count;

    /* throw away characters if exceeded cmd line length */
    if (GET_LEN_RX_CMD_STRING() >= sizeof(g_ConsoleContext.rxBuf)-1)
    {
        return;
    }

    len = GET_LEN_RX_CMD_STRING() + gCmdLinePromptLength;

    /* if inserting a character at end of cmd line */
    if (GET_CURSOR() == len)
    {
        g_ConsoleContext.rxBuf[GET_CURSOR() - gCmdLinePromptLength] = c;
        SET_CURSOR(GET_CURSOR() + 1);
        EchoCharacter(c);
    }
    /* inserting a character somewhere before the end of command line */
    else
    {
        /* Null out tmp cmd line */
        memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine));

        /* copy up to the point of insertion */
        strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, GET_CURSOR() - gCmdLinePromptLength);

        /* insert the new character */
        gTmpCmdLine[GET_CURSOR() - gCmdLinePromptLength] = c;

        /* copy the chars after the new character */
        strncpy( (char *) &gTmpCmdLine[GET_CURSOR() - gCmdLinePromptLength + 1],
                 (const char *) &g_ConsoleContext.rxBuf[GET_CURSOR() - gCmdLinePromptLength],
                 len - GET_CURSOR());

        /* put the first part of new string in the cmd line buffer */
        strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine);

        /* erase entire line, put the cursor at index 0 */
        EraseEntireLine();

        /* output the prompt */
        ZG_PUTRSUART( (ROM FAR char *) gCmdLinePrompt);

        /* Output the updated command line */
        ZG_PUTSUART( (char *) &g_ConsoleContext.rxBuf[0]);

        /* move the cursor to the next insert location */
        count = (len + 1) - orig_cursor_index - 1;
        for (i = 0; i < count; ++i)
        {
            ZG_PUTRSUART( (ROM FAR char *) cursorLeftEscapeSequence);
        }

        SET_CURSOR(orig_cursor_index + 1);
    }
}
/*****************************************************************************
* FUNCTION: IwconfigDisplayStatus
*
* RETURNS: None
*
* PARAMS:    None
*
* NOTES:   Responds to the user invoking ifconfig with no parameters
*****************************************************************************/
static tZGVoidReturn IwprivDisplayStatus(tZGVoidInput)
{

    tZGU8 i, j;
    tZGU8Ptr ptrTemp;

    sprintf( (char *) g_ConsoleContext.txBuf,

#if defined( __18CXX)
        "\nEncryption: %HS\n\r",
#else
        "\nEncryption: %s\n\r",
#endif
        (ROM FAR char*) ZG_GET_CUR_ENC_STR() );

    ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

    switch ( ZG_GET_ENC_TYPE() )
    {

    case kKeyTypeWep:

        sprintf( (char *) g_ConsoleContext.txBuf,
#if defined( __18CXX)
            "  Auth: %HS\n\r",
#else
            "  Auth: %s\n\r",
#endif
            (ROM FAR char*) ZG_GET_CUR_AUTH_STR());
        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        for( j=0; j < (tZGU8)kZGNumDefWepKeys; j++)
        {

            if ( j == ZG_GET_WEP_ACTIVE_INDEX() )
                ZG_PUTRSUART("* ");
            else
                ZG_PUTRSUART("  ");

            sprintf( (char *) g_ConsoleContext.txBuf,
                "Wep key[%d]:  0x",j+1);
            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

            ptrTemp = ZG_GET_WEPKEY(j);

            for ( i=0; i < ZG_GET_WEP_KEY_LEN(); i++ )
            {
                sprintf( (char *) g_ConsoleContext.txBuf,
                    "%.2x", ptrTemp[i]);
                ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
            }

            ZG_PUTRSUART("\n\r");

        }

        break;

    case kKeyTypePsk:

        ZG_PUTRSUART("  PSK:  0x");

        ptrTemp = ZG_GET_WPAPSK();

        for ( i=0; i <  (tZGU8)kZGMaxPmkLen; i++ )
        {
            sprintf( (char *) g_ConsoleContext.txBuf,
                "%.2x", ptrTemp[i]);
            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        }

        ZG_PUTRSUART("\n\r");
        break;

    case kKeyTypeCalcPsk:

        /* if no pass phrase show a user friendly string */
        if ( ZG_GET_PASSPHRASE_LEN() == 0u )
        {
            sprintf( (char *) g_ConsoleContext.txBuf,
#if defined( __18CXX)
                "  Phrase:  \"%HS\"\n\r",
#else
                "  Phrase:  \"%s\"\n\r",
#endif
                (ROM FAR char*)  kZGNone);
        }
        else
        {
            sprintf( (char *) g_ConsoleContext.txBuf,
                "  Phrase:  \"%s\"\n\r",
                ZG_GET_WPA_PASSPHRASE() );
        }
        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );


        sprintf( (char *) g_ConsoleContext.txBuf,
            "  SSID:    %s\n\r", ZG_GET_SSID());
        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        break;

    }


}
Example #29
0
/*****************************************************************************
 * FUNCTION: DisplayHistoryEntry
 *
 * RETURNS: None
 *
 * PARAMS:  action -- PREV_HISTORY or NEXT_HISTORY
 *
 * NOTES:   In response to the user pressing up or down arrow key, display
 *          corresponding entry in history buffer.
 *
 *****************************************************************************/
static tZGVoidReturn DisplayHistoryEntry(tZGU8 action)
{

    tZGBool foundEntry = kZGBoolFalse;

    // if nothing in history buffer
    if (history.seeded == kZGBoolFalse)
    {
        return;
    }

    if (action == (tZGU8)kZGPrevHistory)
    {
        --history.recallIndex;
        if (history.recallIndex < 0)
        {
            history.recallIndex = kZGNumHistoryEntries - 1;
        }

        /* search until found a history entry or searched all entries */
        while (foundEntry == kZGBoolFalse)
        {
            /* if found a history entry */
            if (history.buf[history.recallIndex][0] != 0)
            {
                foundEntry = kZGBoolTrue;
            }
            else
            {
                --history.recallIndex;
                if (history.recallIndex < 0)
                {
                    history.recallIndex = kZGNumHistoryEntries  - 1;
                }
            }
        }
    }
    else /* action == kZGNextHistory */
    {
        history.recallIndex = (history.recallIndex + 1) % kZGNumHistoryEntries;

        /* search until found a history entry or searched all entries */
        while (foundEntry == kZGBoolFalse)
        {
            /* if found a history entry */
            if (history.buf[history.recallIndex][0] != 0)
            {
                foundEntry = kZGBoolTrue;
            }
            else
            {
                history.recallIndex = (history.recallIndex + 1) % kZGNumHistoryEntries;
            }
        }
    }

    if (foundEntry)
    {
        // erase line on screen and output command from history
        EraseEntireLine();          /* leaves Cursor_Index at 0 */
        ZG_PUTRSUART( (ROM FAR char *) gCmdLinePrompt );
        ZG_PUTSUART( (char *) history.buf[history.recallIndex]);

        // copy history command to console buffer (so they match) and put cursor
        // at end of line
        memset(g_ConsoleContext.rxBuf, 0x00, GET_LEN_RX_CMD_STRING() );
        strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) history.buf[history.recallIndex]);
        SET_CURSOR(gCmdLinePromptLength + strlen( (char *) history.buf[history.recallIndex]));
    }

}