tZGVoidReturn
consoleGetVerComplete(tZGU8 type, tZGDataPtr fourByteHeader, tZGDataPtr pBuf,
                      tZGU16 len, tZGVoidInput *appOpaquePtr)

{
   tZGU8 result = fourByteHeader[0];
   tZGU8 chipVersion[2] = {0,0};

   if( result == (tZGU8)kZGResultSuccess )
   {
        ZGLibLoadConfirmBuffer(pBuf, sizeof(tZGU8)*2, 0);
        chipVersion[0] = pBuf[kZGGetMACParamCnfSZ];
        chipVersion[1] = pBuf[kZGGetMACParamCnfSZ+1];
   }

   sprintf( (char *) g_ConsoleContext.txBuf,
            "Firmware version   0x%02X%02X\n\r",
            chipVersion[0],
            chipVersion[1]);
   ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );


   sprintf( (char *) g_ConsoleContext.txBuf,
#if defined( __18CXX)
            "SDK version        %HS\n\r",
#else
            "SDK version        %s\n\r",
#endif
             (ROM FAR char*) ZG_GET_SDK_VERSION());

   ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

}
Пример #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;

}
Пример #3
0
static tZGBool getParam(tZGU8 index)
{
    tZGU8 paramType;

    paramType = getParamType(ARGV[index]);
    switch (paramType)
    {
        case kZGUnknownParam:
            sprintf( (char *) g_ConsoleContext.txBuf,
                      "Param %d invalid", index);

            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

            return kZGBoolFalse;

        case kZGNetmaskParam:
            gLineParseState = kZGWaitingForNetmaskValue;
            return kZGBoolTrue;

#ifdef ZG_CONFIG_DHCP
        case kZGDHCPParam:
            gLineParseState = kZGWaitingForDHCP;
            return kZGBoolTrue;
#endif

        case kZGGatewayParam:
            gLineParseState = kZGWaitingForGateway;
            return kZGBoolTrue;

        case kZGArpParam:
        case kZGMinusArpParam:
        case kZGDownParam:
        case kZGUpParam:
            sprintf( (char *) g_ConsoleContext.txBuf,
                     "Param %d not supported", index);

            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

            return kZGBoolFalse;

        default:
            sprintf( (char *) g_ConsoleContext.txBuf,
                     "Param %d not handled", index);

            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

            return kZGBoolFalse;
    }

    return kZGBoolTrue;
}
Пример #4
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

}
Пример #5
0
tZGReturnStatus
ZGLibScan(tDispatchRequest appPrepareCallback, tDispatchComplete  appDoneCallback, tZGVoidInput *appOpaquePtr)
{
   /* Check if just starting scan, then init some values */
   if (!IS_SCAN_INPROGRESS(APPCXT.scanStatus)) {
#if defined (ZG_CONFIG_CONSOLE)
#if defined (EZ_CONFIG_SCAN)
       if (!IS_USER_SCAN_INPROGRESS(APPCXT.scanStatus))
#endif
       {
           sprintf( (char *) g_ConsoleContext.txBuf,
               "Scan ... for ssid \"%s\"\n\r", ZG_GET_SSID() );

           ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
       }
#endif
#if defined (EZ_CONFIG_SCAN)
       APPCXT.scanListCount = 0; /* Clean scan list */
#endif /* EZ_CONFIG_SCAN */
       APPCXT.scanCurrentChanIdx = 0;
       SET_SCAN_INPROGRESS(APPCXT.scanStatus);     
   }
  
   return ZGLibQAdd( kZGScanReqSZ, kZGMSGScan, 0,
                     appPrepareCallback, appDoneCallback, appOpaquePtr );
}
Пример #6
0
/*= CursorLeft_N ==============================================================
Purpose: Moves the cursor left N characters to the left

Inputs:  n -- number of characters to move the cursor to the left

         Note: This sequence only takes a single digit of length, so may need to
               do the move in steps


Returns: none
============================================================================*/
tZGVoidReturn CursorLeft_N(tZGU8 n)
{
    tZGS8 sequence_string[sizeof(cursorLeftEscapeSequence) + 2];  /* null and extra digit */

    if (n > 0u)
    {
        SET_CURSOR( GET_CURSOR() - n );

        sequence_string[0] = cursorLeftEscapeSequence[0];  /* ESC */
        sequence_string[1] = cursorLeftEscapeSequence[1];  /* '[' */

        if (n < 10u)
        {
            sequence_string[2] = n + '0';  /* ascii digit */
            sequence_string[3] = cursorLeftEscapeSequence[3];    /* 'D' */
            sequence_string[4] = '\0';
        }
        else
        {
            sequence_string[2] = (n / 10) + '0';  /* first ascii digit  */
            sequence_string[3] = (n % 10) + '0';  /* second ascii digit */
            sequence_string[4] = cursorLeftEscapeSequence[3];    /* 'D' */
            sequence_string[5] = '\0';

        }

        ZG_PUTSUART( (char *) sequence_string);
    }
}
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;
}
tZGBool ExtractandValidateRts(tZGS8 *p_string, tZGU16 *p_rts)
{
    // extract RTS
    if (!ConvertASCIIUnsignedDecimalToBinary(p_string, p_rts))
    {
        sprintf( (char *) g_ConsoleContext.txBuf,
                  "   Unable to parse RTS");
        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
        return kZGBoolFalse;
    }

    if ((*p_rts < 256u) || (*p_rts > 2347u))
    {
        sprintf( (char *) g_ConsoleContext.txBuf,
                 "   RTS out of range");

        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        return kZGBoolFalse;
    }

    return kZGBoolTrue;
}
/*****************************************************************************
* FUNCTION: getParam

*
* RETURNS: None
*
* PARAMS:    tokenIndex -- index of token in the command line
*
* NOTES:
*****************************************************************************/
static tZGBool getParam(tZGU8 tokenIndex)
{
    tZGU8 paramType;

    // Parse the token and return it's corresponding paramType id
    paramType = getParamType(ARGV[tokenIndex]);

    // set the state of the line parsing state machine based on the parameter type.
    // Either need to wait for a value or go on to the next parameter
    switch (paramType)
    {
    case kZGUnknownParam:
        sprintf( (char *) g_ConsoleContext.txBuf,
            "Param %d invalid", tokenIndex);
        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
        return kZGBoolFalse;

    case kZGWpaPskParam:
        gLineParseState = kZGWaitingForWpaPsk;
        break;

    case kZGWpaStrParam:
        gLineParseState = kZGWaitingForWpaStr;
        break;

    case kZGEncTypeParam:
        gLineParseState = kZGWaitingForEnc;
        break;

    case kZGWepAuthParam:
        gLineParseState = kZGWaitingForWepAuth;
        break;

    case kZGWepKeyParam:
        gLineParseState = kZGWaitingForWepKey;
        break;

    case kZGBeaconParam:
        gLineParseState = kZGWaitingForBeacon;
        break;

    default:
        sprintf( (char *) g_ConsoleContext.txBuf,
            "Param %d not handled", tokenIndex);

        return kZGBoolFalse;
    }

    return kZGBoolTrue;
}
tZGBool ExtractandValidateDomain(tZGS8 *pDomainStr, tZGU8 *pDomain)
{
    tZGU8 i=0;

    // search list of domain name strings until we find a match

    while ( g_DomainStrings[i] != NULL )
    {
        if (strcmppgm2ram((char *)pDomainStr, (ROM FAR char *) g_DomainStrings[i]) == 0)
        {
            *pDomain = i;
            return kZGBoolTrue;
        }
        i++;
    }
    sprintf( (char *) g_ConsoleContext.txBuf,
            "   Invalid domain");
    ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

    return kZGBoolFalse;
}
tZGBool ExtractandValidateDHCP(tZGS8 *p_string, tZGU8 *p_dhcp)
{
    if (strcmppgm2ram((char *)p_string, (ROM FAR char *)kZGDHCPStart) == 0)
    {
        *p_dhcp = DHCP_ENABLED;
    }
    else if (strcmppgm2ram((char *)p_string, (ROM FAR char *)kZGDHCPDrop) == 0)
    {
        *p_dhcp = DHCP_DISABLED;
    }
    else
    {
        sprintf( (char *) g_ConsoleContext.txBuf,
                "   Invalid dhcp param");

        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

        return kZGBoolFalse;
    }

    return kZGBoolTrue;
}
Пример #12
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);
    }
}
Пример #13
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);
    }
}
Пример #14
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]));
    }

}
Пример #15
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;

    }


}
/*****************************************************************************
 * 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;
    }
}
Пример #18
0
/*****************************************************************************
 * FUNCTION: do_ifconfig_cmd
 *
 * RETURNS: None
 *
 * PARAMS:    None
 *
 * NOTES:   Responds to the user invoking ifconfig
 *****************************************************************************/
tZGVoidReturn do_ifconfig_cmd(tZGVoidInput)
{
    tZGU8 i;
    tZGU8 address[6];
#if defined(ZG_CONFIG_DHCP) && defined(STACK_USE_DHCP_CLIENT)
    tZGU16 tmp[4]; // uip requires these be 2-byte words.
#endif


   gLineParseState = kZGWaitingForParamKeyword;

    // if user only typed in ifconfig with no other parameters
    if (ARGC == 1u)
    {
        IfconfigDisplayStatus();
    }
    // else if 2 arguments and the second arg is IP address
    else if ( (ARGC == 2u) && (isIPAddress(ARGV[1], address)) )
    {
        if ( ZG_GET_DHCP_STATE() == DHCP_ENABLED )
        {

          sprintf( (char *) g_ConsoleContext.txBuf,
                     "Static IP address should not be set with DHCP enabled.\n\r");

          ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
          return;
        }

        AppConfig.MyIPAddr.v[0] = address[0];
        AppConfig.MyIPAddr.v[1] = address[1];
        AppConfig.MyIPAddr.v[2] = address[2];
        AppConfig.MyIPAddr.v[3] = address[3];

        /* Microchip DHCP client clobbers static ip on every iteration of loop, even if dhcp is turned off*/
        AppConfig.DefaultIPAddr.v[0] = address[0];
        AppConfig.DefaultIPAddr.v[1] = address[1];
        AppConfig.DefaultIPAddr.v[2] = address[2];
        AppConfig.DefaultIPAddr.v[3] = address[3];

#ifdef USE_LCD
        LCDDisplayIPValue(AppConfig.MyIPAddr);
#endif
    }
    // else if 2 args and second arg is MAC address
    else if ( (ARGC == 2u) && isMacAddress(ARGV[1], address))
    {
        /* Can only set MAC address in idle state */
        if ( ZG_IS_CONNECTED() == kZGBoolTrue )
        {
            sprintf( (char *) g_ConsoleContext.txBuf,
                     "HW MAC address can only be set in idle mode");

            ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );

            return;
        }

        /* update G2100 */
        ZG_SET_MAC_ADDR( address );

    }
    // 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 kZGWaitingForNetmaskValue:

                    if ( ZG_GET_DHCP_STATE() == DHCP_ENABLED )
                    {
                        sprintf( (char *) g_ConsoleContext.txBuf,
                                "The Netmask should not be set with DHCP enabled.\n\r");

                        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
                        return;
                    }

                    if ( !isIPAddress(ARGV[i], address) )
                    {
                        sprintf( (char *) g_ConsoleContext.txBuf,
                                 "Invalid netmask value");
                        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
                        return;
                    }

                    AppConfig.MyMask.v[0] = address[0];
                    AppConfig.MyMask.v[1] = address[1];
                    AppConfig.MyMask.v[2] = address[2];
                    AppConfig.MyMask.v[3] = address[3];

                    /* Microchip DHCP client clobbers static netmask on every iteration of loop, even if dhcp is turned off*/
                    AppConfig.DefaultMask.v[0] = address[0];
                    AppConfig.DefaultMask.v[1] = address[1];
                    AppConfig.DefaultMask.v[2] = address[2];
                    AppConfig.DefaultMask.v[3] = address[3];


                    gLineParseState = kZGWaitingForParamKeyword;
                    break;

#if defined(ZG_CONFIG_DHCP) && defined(STACK_USE_DHCP_CLIENT)
                case kZGWaitingForDHCP:
                    /* buf[4] contains DHCP enable/disable enum */
                    if ( !ExtractandValidateDHCP(ARGV[i], (tZGU8 *) &tmp[0]) )
                    {
                        return;
                    }

                    ZG_SET_DHCP_STATE( (tZGBool) tmp[0] );
                    gLineParseState = kZGWaitingForParamKeyword;
                    break;
#endif

                case kZGWaitingForGateway:
                    if ( !isIPAddress(ARGV[i], address) )
                    {
                        sprintf( (char *) g_ConsoleContext.txBuf,
                                 "Invalid gateway value");
                        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
                        return;
                    }

                    AppConfig.MyGateway.v[0] = address[0];
                    AppConfig.MyGateway.v[1] = address[1];
                    AppConfig.MyGateway.v[2] = address[2];
                    AppConfig.MyGateway.v[3] = address[3];

                    // There is no such thing as AppConfig.DefaultGateway

                    gLineParseState = kZGWaitingForParamKeyword;
                    break;

            } // end switch
//            ZGConsolePrintf("%s ", ARGV[i]);
        } // end for
    }

    if (gLineParseState != (tZGU8)kZGWaitingForParamKeyword)
    {
        sprintf( (char *) g_ConsoleContext.txBuf,
                  "Missing value after last parameter");

        ZG_PUTSUART( (char *) g_ConsoleContext.txBuf );
    }

}