/*****************************************************************************
 * FUNCTION: iwprivSetPsk
 *
 * RETURNS: true or false
 *
 * PARAMS: none
 *
 * NOTES: Set PSK key
 *         Valid key length:
 *          The PSK is 32 bytes (256 bits),
 * 			often displayed as 64 hexadecimal characters.
 *****************************************************************************/
static bool iwprivSetPsk(void)
{
    if ( iwprivCb.securityType != WF_SECURITY_WPA_AUTO_WITH_KEY )
    {
        WFConsolePrintRomStr("WPA-PSK encryption mode is not selected", true);
        return false;
    }

    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", true);
        return false;
    }

    if ( convertAsciiToHexInPlace(ARGV[2], WF_WPA_KEY_LENGTH) )
    {
        memcpy((void*)iwprivCb.securityKey, (const void *)ARGV[2], WF_WPA_KEY_LENGTH);
        iwprivCb.securityKeyLength = WF_WPA_KEY_LENGTH;
    }
    else
    {
        WFConsolePrintRomStr("WPA-PSK Key length must be exactly 32 bytes long. It is often displayed as 64 hex characters.", true);
        return false;
    }

    WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, 0, iwprivCb.securityKey, iwprivCb.securityKeyLength);

    return true;
}
Exemplo n.º 2
0
static BOOL iwprivSetPsk(void)
{
	if ( iwprivCb.securityType != WF_SECURITY_WPA_AUTO_WITH_KEY )
	{
		WFConsolePrintRomStr("WPA-PSK encryption mode is not selected", TRUE);
		return FALSE;
	}

	if (ARGC < 3u)
	{
		WFConsolePrintRomStr("Missing value for last parameter", TRUE);
		return FALSE;
	}

	if ( convertAsciiToHexInPlace(ARGV[2], WF_WPA_KEY_LENGTH) )
	{
		memcpy((void*)iwprivCb.securityKey, (const void*)ARGV[2], WF_WPA_KEY_LENGTH);
		iwprivCb.securityKeyLength = WF_WPA_KEY_LENGTH;
	}
	else
	{
		WFConsolePrintRomStr("WPA PSK must be exactly 32 bytes", TRUE);
		return FALSE;
	}

	WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, 0, iwprivCb.securityKey, iwprivCb.securityKeyLength);

	return TRUE;
}
Exemplo n.º 3
0
static BOOL iwconfigSetChannel(void)
{
    UINT8 *p1, *p2;
    UINT8 *p_channelList;
    UINT8 index = 0;
    UINT16 temp;

    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", TRUE);
        return FALSE;
    }

    if ( !iwconfigCb.isIdle )
    {
        WFConsolePrintRomStr("Channel can only be set in idle mode", TRUE);
        return FALSE;
    }

    p_channelList = (UINT8*) ARGV[2];
    p1 = p2 = p_channelList;

    if ( strlen( (char*) p_channelList) == 0u )
        return FALSE;

    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "all") == 0) )
    {
        WF_CASetChannelList(p_channelList, 0); // reset to domain default channel list
        return TRUE;
    }

    do
    {
        if ( (p2 = (UINT8*) strchr( (const char *) p1, (int) ',')) != NULL )
        {
            *p2='\0';
            p2++;
        }

        if( !ConvertASCIIUnsignedDecimalToBinary((INT8 *)p1, &temp) )
            return  FALSE;

        p1 = p2;
        p_channelList[index] = (UINT8) temp;
        index++;

    } while (  p2 != NULL );

    WF_CASetChannelList(p_channelList, index);

    return TRUE;
}
Exemplo n.º 4
0
static void do_get_wfver_cmd(void)
{
 	tWFDeviceInfo  deviceInfo;

	WF_GetDeviceInfo(&deviceInfo);
	WFConsolePrintRomStr("Firmware version   0x", FALSE);
	WFConsolePrintHex(deviceInfo.romVersion, 2);
	WFConsolePrintHex(deviceInfo.patchVersion, 2);
	WFConsolePrintRomStr("", TRUE);  

	WFConsolePrintRomStr("Host Driver version        ", FALSE);
	WFConsolePrintRomStr(WF_HOST_DRIVER_VERSION_NUMBER, TRUE);
}
/*****************************************************************************
 * FUNCTION: iwprivSetEnc
 *
 * RETURNS: true or false
 *
 * PARAMS: none
 *
 * NOTES: Set security mode
 *         Valid security mode:
 *          Open
 *          WEP40
 *          WEP104
 *          WPA-PSK/WPA2-PSK Auto with Key
 *          WPA-PSK/WPA2-PSK Auto with Passphrase
 *****************************************************************************/
static bool iwprivSetEnc(void)
{
    uint8_t securityType;

    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", true);
        return false;
    }

    if ( (3u <= ARGC) && (strcmppgm2ram((char *)ARGV[2], "OPEN") == 0) )
    {
        securityType = WF_SECURITY_OPEN;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char *)ARGV[2], "WEP40") == 0) )
    {
        securityType = WF_SECURITY_WEP_40;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char *)ARGV[2], "WEP104") == 0) )
    {
        securityType = WF_SECURITY_WEP_104;
    }    
    else if ( (3u <= ARGC) && (strcmppgm2ram((char *)ARGV[2], "WPA-PSK/WPA2-PSK AUTO with KEY") == 0) )
    {
        securityType = WF_SECURITY_WPA_AUTO_WITH_KEY;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char *)ARGV[2], "WPA-PSK/WPA2-PSK Auto with Passphrase") == 0) )
    {
        securityType = WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE;
    }
    else
    {
        WFConsolePrintRomStr("Unknown parameter", true);
        return false;
    }

    if ( iwprivCb.securityType != securityType ) // security type changed
    {   // reset the security context
        memset(iwprivCb.securityKey, 0, sizeof(iwprivCb.securityKey));
        iwprivCb.securityKeyLength = 0;
    }

    iwprivCb.securityType = securityType; // save the security type

    if (iwprivCb.securityType == WF_SECURITY_OPEN)
    {
        WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, 0, NULL, 0);
    }

    return true;
}
Exemplo n.º 6
0
/*****************************************************************************
* FUNCTION: do_iwpriv_cmd
*
* RETURNS: None
*
* PARAMS:    None
*
* NOTES:   Responds to the user invoking ifconfig
*****************************************************************************/
void do_iwpriv_cmd(void)
{
	if (g_hibernate_state)
	{
		WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", TRUE);
		return;
	}

	if ( !iwprivSetCb() )
			return;

    // if user only typed in iwpriv with no other parameters
    if (ARGC == 1u)
    {
		iwprivDisplayStatus();
		return;
    }

	if ( !iwconfigCb.isIdle )
	{
		WFConsolePrintRomStr("Security context modification can be only done in the idle state", TRUE);
		return;
	}

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "enc") == 0) )
    {
    	if ( !iwprivSetEnc() )
			return;
	}
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "key") == 0) )
    {
    	if ( !iwprivSetKey() )
			return;
	}
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "psk") == 0) )
    {
    	if ( !iwprivSetPsk() )
			return;
	}
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "phrase") == 0) )
    {
    	if ( !iwprivSetPhrase() )
			return;
	}
    else
    {
		WFConsolePrintRomStr("Unknown parameter", TRUE);
		return;
	}
}
Exemplo n.º 7
0
static BOOL iwprivSetEnc(void)
{
	UINT8 securityType;

	if (ARGC < 3u)
	{
		WFConsolePrintRomStr("Missing value for last parameter", TRUE);
		return FALSE;
	}

    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "none") == 0) )
    {
		securityType = WF_SECURITY_OPEN;
	}
	else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "wep") == 0) )
    {
		securityType = WF_SECURITY_WEP_40; // by default
	}
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "wpa-psk") == 0) )
    {
		securityType = WF_SECURITY_WPA_AUTO_WITH_KEY;

	}
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "wpa-phrase") == 0) )
    {
		securityType = WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE;
	}
	else
	{
		WFConsolePrintRomStr("Unknown parameter", TRUE);
		return FALSE;
	}

	if ( iwprivCb.securityType != securityType ) // security type changed
	{	// reset the security context
		memset(iwprivCb.securityKey, 0, sizeof(iwprivCb.securityKey));
		iwprivCb.securityKeyLength = 0;
	}
	
	iwprivCb.securityType = securityType; // save the security type
	
	if (iwprivCb.securityType == WF_SECURITY_OPEN)
	{
        WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, 0, NULL, 0);
    }   	

	return TRUE;
}
Exemplo n.º 8
0
static void do_wps_pin_cmd(void)
{
    UINT8 pinLength;
    UINT8 pin[8];   // presume pin won't be greater than 8 digits
#if 0
    UINT8 i;
    UINT8 pinChar;
#endif
      
    if (ARGC == 1)
    {
        WFConsolePrintRomStr("Missing PIN parameter", TRUE);
        return;
    }    
    
    if (ARGC > 2)
    {
        WFConsolePrintRomStr("Too many parameters", TRUE);
        return;
    }  
    
    pinLength = strlen((char *)ARGV[1]);   
    
#if 1
    strcpy((char *)pin, (char *)ARGV[1]);
#else
    memset(pin, 0x00, sizeof(pin));
    for (i = 0; i < pinLength; ++i)
    {
        pinChar = ARGV[1][i];
        
        if ((pinChar < '0') || (pinChar > '9'))
        {
            WFConsolePrintRomStr("PIN must be all digits", TRUE);
            return;
        }    

        pin[i] = pinChar - '0';  // convert pin digit from ASCII to binary
        
 
    }    
#endif
    
    WF_CPSetSecurity(1, WF_SECURITY_WPS_PIN, 0, pin, pinLength);
    
}    
Exemplo n.º 9
0
static BOOL iwconfigSetSsid(void)
{
    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", TRUE);
        return FALSE;
    }

    if (ARGC > 3u)
    {
        WFConsolePrintRomStr("SSID may not contain space for this demo", TRUE);
        return FALSE;
    }

    WF_CPSetSsid(iwconfigCb.cpId, (UINT8 *)ARGV[2], strlen((char*)ARGV[2]));

    return TRUE;
}
Exemplo n.º 10
0
/*****************************************************************************
 * FUNCTION: IfconfigDisplayStatus
 *
 * RETURNS: None
 *
 * PARAMS:    None
 *
 * NOTES:   Responds to the user invoking ifconfig with no parameters
 *****************************************************************************/
static void IfconfigDisplayStatus(void)
{
    UINT8 p_mac[6];

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


    WF_GetMacAddress(p_mac);
    sprintf( (char *) g_ConsoleContext.txBuf,
             "\tMAC addr: %02X:%02X:%02X:%02X:%02X:%02X",   p_mac[0], p_mac[1],
                                                            p_mac[2], p_mac[3],
                                                            p_mac[4], p_mac[5]);
    WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , TRUE);



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


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

    #if defined(STACK_USE_DHCP_CLIENT)
    if ( DHCPIsEnabled(0) )
       WFConsolePrintRomStr("\tDHCP:     Started", TRUE);
    else
       WFConsolePrintRomStr("\tDHCP:     Stopped", TRUE);
    #endif
}
Exemplo n.º 11
0
static void do_wps_push_button_cmd(void)
{
    if (ARGC > 1)
    {
        WFConsolePrintRomStr("Too many parameters", TRUE);
        return;
    }  
    
    WF_CPSetSecurity(1, WF_SECURITY_WPS_PUSH_BUTTON, 0, NULL, 0);

} 
Exemplo n.º 12
0
/*******************************************************************************
  Function:
	  BOOL iwconfigSetPower(void)

  Summary:
	 Enables or disables PS Poll mode.

  Description:
	 Enables or disables PS Poll mode.
	 reenable / all - Enables all power saving features (PS_POLL) of the MRF24W. MRF24W
	                        will wake up to check for all types of traffic (unicast, multicast, and broadcast)
        disable          - Disables any power savings features.
        unicast          - MRF24W will be in its deepest sleep state, only waking up at periodic intervals
                               to check for unicast data. MRF24W will not wake up on the DTIM period for
                               broadcast or multicast traffic.

  Parameters:
       reenable / disable / unicast /all

  Returns:
	TRUE or FALSE

  Remarks:
       WF_USE_POWER_SAVE_FUNCTIONS must be defined to use PS Poll mode.
 *****************************************************************************/
static BOOL iwconfigSetPower(void)
{
    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", TRUE);
        return FALSE;
    }

    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "reenable") == 0) )
    {   // reenable power saving
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
        WF_PsPollEnable(TRUE);
#endif
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "disable") == 0) )
    {   // disable power saving
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
        WF_PsPollDisable();
#endif
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "unicast") == 0) )
    {   // enable power saving but don't poll for DTIM
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
        WF_PsPollEnable(FALSE);
#endif
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "all") == 0) )
    {   // enable power saving and poll for DTIM
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
        WF_PsPollEnable(TRUE);
#endif
    }
    else
    {
        WFConsolePrintRomStr("Unknown parameter", TRUE);
        return FALSE;
    }

    return TRUE;
}
/*****************************************************************************
 * FUNCTION: WFConsoleProcessEpilogue
 *
 * RETURNS: None
 *
 * PARAMS:  None
 *
 * NOTES:   Check if there is a left console msg, and release it if found.
 *
 *****************************************************************************/
void WFConsoleProcessEpilogue(void)
{
    if (WFConsoleIsConsoleMsgReceived())
	{
		if ( memcmppgm2ram(ARGV[0], "help", 4) != 0 )
		{
			WFConsolePrintRomStr("Unknown cmd: ", FALSE);
			WFConsolePrintRamStr(ARGV[0], TRUE);
		}

	    WFConsoleReleaseConsoleMsg();
	}
}
Exemplo n.º 14
0
static BOOL iwconfigSetRTS(void)
{
    UINT16 rtsThreshold;

    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", TRUE);
        return FALSE;
    }

    if( !ConvertASCIIUnsignedDecimalToBinary(ARGV[2], &rtsThreshold) )
        return  FALSE;

    WF_SetRtsThreshold(rtsThreshold);

    return TRUE;
}
Exemplo n.º 15
0
/*****************************************************************************
 * FUNCTION: WFConsoleProcessEpilogue
 *
 * RETURNS: None
 *
 * PARAMS:  None
 *
 * NOTES:   Check if there is a left console msg, and release it if found.
 *
 *****************************************************************************/
void WFConsoleProcessEpilogue(void)
{
    if (WFConsoleIsConsoleMsgReceived())
    {
#if defined(WF_EASY_CONFIG_DEMO) && !defined(__C32__)
        putrsUART("Iperf supports only PIC32 for EasyConfig\n\r");
#else
        if (( memcmppgm2ram(ARGV[0], "iperf", 5) == 0 ) || ( memcmppgm2ram(ARGV[0], "kill", 4) == 0 ))
        {
            return;
        }
#endif
        if ( memcmppgm2ram(ARGV[0], "help", 4) != 0 )
        {
            WFConsolePrintRomStr("Unknown cmd: ", FALSE);
            WFConsolePrintRamStr(ARGV[0], TRUE);
        }
            
        WFConsoleReleaseConsoleMsg();
    }
}
Exemplo n.º 16
0
static void do_get_wfver_cmd(void)
{
 	tWFDeviceInfo  deviceInfo;
	if (WF_hibernate.state)
	{
		WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", TRUE);
		return;
	}
	WF_GetDeviceInfo(&deviceInfo);
	
	#if defined(MRF24WG)
	    WFConsolePrintRomStr("MRF24WG firmware version: 0x", FALSE);

	#else
	    WFConsolePrintRomStr("MRF24WB firmware version:     0x", FALSE);	
	#endif

	WFConsolePrintHex(deviceInfo.romVersion, 2);
	WFConsolePrintHex(deviceInfo.patchVersion, 2);
	WFConsolePrintRomStr("", TRUE);  

	WFConsolePrintRomStr("Host Driver version:      ", FALSE);
	WFConsolePrintRomStr(WF_HOST_DRIVER_VERSION_NUMBER, TRUE);
}
/*****************************************************************************
 * FUNCTION: iwprivDisplayStatus
 *
 * RETURNS: none
 *
 * PARAMS: none
 *
 * NOTES: Display security mode status
 *         Valid security mode:
 *          Open
 *          WEP40
 *          WEP104
 *          WPA-PSK/WPA2-PSK Auto with Key
 *          WPA-PSK/WPA2-PSK Auto with Passphrase
 *****************************************************************************/
static void iwprivDisplayStatus(void)
{
    uint8_t i, j;
    uint8_t * p;

    // security type
    {
        WFConsolePrintRomStr("Encryption: ", false);

        switch (iwprivCb.securityType)
        {
        case WF_SECURITY_OPEN:
            WFConsolePrintRomStr("Open", true);
            break;
        case WF_SECURITY_WEP_40:
            WFConsolePrintRomStr("WEP40", true);
            break;
        case WF_SECURITY_WEP_104:
            WFConsolePrintRomStr("WEP104", true);
            break;
        case WF_SECURITY_WPA_AUTO_WITH_KEY:
            WFConsolePrintRomStr("WPA-PSK/WPA2-PSK Auto with Key", true);
            break;
        case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE:
            WFConsolePrintRomStr("WPA-PSK/WPA2-PSK Auto with Passphrase", true);
            break;
        default:
            WFConsolePrintRomStr("Unknown", true);
            return;
        }
    }

    if ( iwprivCb.securityType == WF_SECURITY_WEP_40 || iwprivCb.securityType == WF_SECURITY_WEP_104 )
    {
        uint8_t webKeyLen;

        if ( iwprivCb.securityKeyLength == (IWPRIV_WEB_KEY_NUM * IWPRIV_WEB_LONG_KEY_LEN) )
        {
            webKeyLen = IWPRIV_WEB_LONG_KEY_LEN;
        }
        else if ( iwprivCb.securityKeyLength == (IWPRIV_WEB_KEY_NUM * IWPRIV_WEB_SHORT_KEY_LEN) )
        {
            webKeyLen = IWPRIV_WEB_SHORT_KEY_LEN;
        }
        else
        {
            WFConsolePrintRomStr("  WEP Key: not yet set or unknown", true);
            return;
        }

        p = iwprivCb.securityKey;
        for (j = 0; j < IWPRIV_WEB_KEY_NUM; j++)
        {
            if (j == iwprivCb.wepDefaultKeyId )
                WFConsolePrintRomStr(" *", false);
            else
                WFConsolePrintRomStr("  ", false);

            WFConsolePrintRomStr("WEP Key[", false);
            WFConsolePrintInteger(j + 1, false);
            WFConsolePrintRomStr("]:  0x", false);

            for (i = 0; i < webKeyLen ; i++)
            {
                sprintf( (char *) g_ConsoleContext.txBuf,
                    "%.2x", *p++);
                WFConsolePrintRamStr((char *) g_ConsoleContext.txBuf, false);
            }

            WFConsolePrintRomStr("", true);
        }
    }
    else if ( iwprivCb.securityType == WF_SECURITY_WPA_AUTO_WITH_KEY )
    {
        if ( iwprivCb.securityKeyLength != WF_WPA_KEY_LENGTH )
        {
            WFConsolePrintRomStr("  PSK: not yet set or unknown", true);
            return;
        }

        putrsUART("  PSK: \"");

        p = iwprivCb.securityKey;
        for (j = 0; j < WF_WPA_KEY_LENGTH; j++)
        {
            sprintf( (char *) g_ConsoleContext.txBuf, "%.2x", *p++);
            WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , false );
        }

        WFConsolePrintRomStr("", true);
    }
    else if ( iwprivCb.securityType == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE )
    {
        if ( iwprivCb.securityKeyLength == 0 )
        {
            WFConsolePrintRomStr("  Passphrase: not yet set or unknown", true);
            return;
        }

        WFConsolePrintRomStr("  Passphrase: \"", false);

        p = iwprivCb.securityKey;
        for (j = 0; j < iwprivCb.securityKeyLength; j++ )
        {
            sprintf( (char *) g_ConsoleContext.txBuf, "%c", *p++);
            WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf, false );
        }

        WFConsolePrintRomStr("\"", true);

        WFConsolePrintRomStr("  SSID: ", false);
        WFConsolePrintRamStr(iwprivCb.ssid, true);
    }
}
Exemplo n.º 18
0
static void iwprivDisplayStatus(void)
{
	UINT8 i, j;
	UINT8* p;

	// security type
	{
		WFConsolePrintRomStr("Encryption: ", FALSE);

		switch (iwprivCb.securityType)
		{
		case WF_SECURITY_OPEN:
			WFConsolePrintRomStr("none", TRUE);
			break;
		case WF_SECURITY_WEP_40:
		case WF_SECURITY_WEP_104:
			WFConsolePrintRomStr("wep", TRUE);
			break;
		case WF_SECURITY_WPA_WITH_KEY:
		case WF_SECURITY_WPA2_WITH_KEY:
		case WF_SECURITY_WPA_AUTO_WITH_KEY:
			WFConsolePrintRomStr("wpa-psk", TRUE);
			break;
		case WF_SECURITY_WPA_WITH_PASS_PHRASE:
		case WF_SECURITY_WPA2_WITH_PASS_PHRASE:
		case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE:
			WFConsolePrintRomStr("wpa-phrase", TRUE);
			break;
		default:
			WFConsolePrintRomStr("unknown", TRUE);
			return;
		}
	}

	if ( iwprivCb.securityType == WF_SECURITY_WEP_40 || iwprivCb.securityType == WF_SECURITY_WEP_104 )
	{
		UINT8 webKeyLen;

		if ( iwprivCb.securityKeyLength == (IWPRIV_WEB_KEY_NUM * IWPRIV_WEB_LONG_KEY_LEN) )
		{
			webKeyLen = IWPRIV_WEB_LONG_KEY_LEN;
		}
		else if ( iwprivCb.securityKeyLength == (IWPRIV_WEB_KEY_NUM * IWPRIV_WEB_SHORT_KEY_LEN) )
		{
			webKeyLen = IWPRIV_WEB_SHORT_KEY_LEN;
		}
		else
		{
			WFConsolePrintRomStr("  Wep key: not yet set or unknown", TRUE);
			return;
		}

		p = iwprivCb.securityKey;
        for( j=0; j < IWPRIV_WEB_KEY_NUM ; j++ )
        {
            if ( j == iwprivCb.wepDefaultKeyId )
                WFConsolePrintRomStr(" *", FALSE);
            else
                WFConsolePrintRomStr("  ", FALSE);

			WFConsolePrintRomStr("Wep key[", FALSE);
			WFConsolePrintInteger(j+1, FALSE);
			WFConsolePrintRomStr("]:  0x", FALSE);

            for ( i=0; i < webKeyLen ; i++ )
            {
                sprintf( (char *) g_ConsoleContext.txBuf,
                    "%.2x", *p++);
                WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf, FALSE);
            }

            WFConsolePrintRomStr("", TRUE);
        }
	}
	else if ( iwprivCb.securityType == WF_SECURITY_WPA_AUTO_WITH_KEY )
	{
		if ( iwprivCb.securityKeyLength != WF_WPA_KEY_LENGTH )
		{
			WFConsolePrintRomStr("  PSK: not yet set or unknown", TRUE);
			return;
		}

		putrsUART("  PSK: \"");

		p = iwprivCb.securityKey;
        for( j=0; j < WF_WPA_KEY_LENGTH ; j++ )
        {
			sprintf( (char *) g_ConsoleContext.txBuf,
				"%.2x", *p++);
			WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , FALSE );
		}

        WFConsolePrintRomStr("", TRUE);
	}
	else if ( iwprivCb.securityType == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE )
	{
		if ( iwprivCb.securityKeyLength == 0 )
		{
			WFConsolePrintRomStr("  Phrase: not yet set or unknown", TRUE);
			return;
		}

		WFConsolePrintRomStr("  Phrase: \"", FALSE);

		p = iwprivCb.securityKey;
        for( j=0; j < iwprivCb.securityKeyLength ; j++ )
        {
			sprintf( (char *) g_ConsoleContext.txBuf,
				"%c", *p++);
			WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf, FALSE );
		}

		WFConsolePrintRomStr("\"", TRUE);

		WFConsolePrintRomStr("  SSID: ", FALSE);
		WFConsolePrintRamStr(iwprivCb.ssid, TRUE);
	}
}
Exemplo n.º 19
0
static BOOL iwprivSetKey(void)
{
	UINT8 webKey;

	if (iwprivCb.securityType != WF_SECURITY_WEP_40 && iwprivCb.securityType != WF_SECURITY_WEP_104)
	{
		WFConsolePrintRomStr("WEP encryption mode is not selected", TRUE);
		return FALSE;
	}

	if (ARGC < 3u)
	{
		WFConsolePrintRomStr("Missing value for last parameter", TRUE);
		return FALSE;
	}

    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "[1]") == 0) )
    {
		webKey = 0u;
	}
	else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "[2]") == 0) )
    {
		webKey = 1u;
	}
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "[3]") == 0) )
    {
		webKey = 2u;

	}
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "[4]") == 0) )
    {
		webKey = 3u;
	}
	else
	{
		WFConsolePrintRomStr("Invalid WEP key index", TRUE);
		return FALSE;
	}

	if (4u <= ARGC)
	{
		if ( convertAsciiToHexInPlace(ARGV[3], IWPRIV_WEB_LONG_KEY_LEN) ) // for long web key
		{
    		iwprivCb.securityType = WF_SECURITY_WEP_104;
    		
			memcpy((void*)(iwprivCb.securityKey + webKey * IWPRIV_WEB_LONG_KEY_LEN), (const void*)ARGV[3], IWPRIV_WEB_LONG_KEY_LEN);
			iwprivCb.securityKeyLength = IWPRIV_WEB_KEY_NUM * IWPRIV_WEB_LONG_KEY_LEN;
			
			WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, webKey,
			    iwprivCb.securityKey + webKey * IWPRIV_WEB_LONG_KEY_LEN, IWPRIV_WEB_LONG_KEY_LEN);
		}
		else if ( convertAsciiToHexInPlace(ARGV[3], IWPRIV_WEB_SHORT_KEY_LEN) ) // for short web key
		{
    		iwprivCb.securityType = WF_SECURITY_WEP_40;
    		
			memcpy((void*)(iwprivCb.securityKey + webKey * IWPRIV_WEB_SHORT_KEY_LEN), (const void*)ARGV[3], IWPRIV_WEB_SHORT_KEY_LEN);
			iwprivCb.securityKeyLength = IWPRIV_WEB_KEY_NUM * IWPRIV_WEB_SHORT_KEY_LEN;
			
			WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, webKey,
			    iwprivCb.securityKey + webKey * IWPRIV_WEB_SHORT_KEY_LEN, IWPRIV_WEB_SHORT_KEY_LEN);
		}
		else
		{
			WFConsolePrintRomStr("64/128bit WEP key format not valid", TRUE);
			return FALSE;
		}
	}
	else // ARGC == 3u
	{
		WF_CPSetDefaultWepKeyIndex(iwprivCb.cpId, webKey);
	}

	return TRUE;
}
Exemplo n.º 20
0
/*******************************************************************************
  Function:
	  BOOL iwconfigSetMode(void)

  Summary:
	 Set the mode to idle, managed or adhoc.

  Description:
	 Idle mode        - Force MRF24W module to disconnect from any currently connected network
        Managed mode - MRF24W module will connect to SSID in infrastructure mode. Ensure all network
                                  parameters are correct before this command is invoked.
        Adhoc mode     - MRF24W module will connect to SSID in adhoc mode. Ensure all network
                                  parameters are correct before this command is invoked.

  Parameters:
      Mode - idle / managed /adhoc

  Returns:
	TRUE or FALSE

  Remarks:
       None.
 *****************************************************************************/
static BOOL iwconfigSetMode(void)
{
    UINT8 networkType;

    WF_CPGetNetworkType(iwconfigCb.cpId, &networkType);

    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "idle") == 0) )
    {
        if ( iwconfigCb.isIdle )
        {
            WFConsolePrintRomStr("Already in the idle mode", TRUE);
        }
        else
        {
            if (WF_CMDisconnect() != WF_SUCCESS)
            {
#if defined(STACK_USE_UART)
                putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n");
#endif
            }
            WF_PsPollDisable();
        }
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "managed") == 0) )
    {
        if ( iwconfigCb.isIdle )
        {
            WF_CPSetNetworkType(iwconfigCb.cpId, WF_INFRASTRUCTURE);
            WF_CMConnect(iwconfigCb.cpId);
        }
        else
        {
            WF_CPGetNetworkType(iwconfigCb.cpId, &networkType);
            if (networkType == WF_INFRASTRUCTURE)
            {
                WFConsolePrintRomStr("Already in the managed mode", TRUE);
            }
            else
            {
                if (WF_CMDisconnect() != WF_SUCCESS)
                {
#if defined(STACK_USE_UART)
                    putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n");
#endif
                }

                WF_CPSetNetworkType(iwconfigCb.cpId, WF_INFRASTRUCTURE);
                WF_CMConnect(iwconfigCb.cpId);
            }
        }
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "adhoc") == 0) )
    {
        if ( iwconfigCb.isIdle )
        {
            WF_CASetListRetryCount(ADHOC_RETRY_COUNT);
            WF_CPSetNetworkType(iwconfigCb.cpId, WF_ADHOC);
            WF_CPSetAdHocBehavior(iwconfigCb.cpId, WF_ADHOC_CONNECT_THEN_START);
            WF_CMConnect(iwconfigCb.cpId);
        }
        else
        {
            WF_CPGetNetworkType(iwconfigCb.cpId, &networkType);
            if (networkType == WF_ADHOC)
            {
                WFConsolePrintRomStr("Already in the adhoc mode", TRUE);
            }
            else
            {
                if (WF_CMDisconnect() != WF_SUCCESS)
                {
#if defined(STACK_USE_UART)
                    putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n");
#endif
                }

                WF_CPSetNetworkType(iwconfigCb.cpId, WF_ADHOC);
                WF_CMConnect(iwconfigCb.cpId);
            }
        }
    }
    else
    {
        WFConsolePrintRomStr("Unknown parameter", TRUE);
        return FALSE;
    }

    return TRUE;
}
Exemplo n.º 21
0
static BOOL iwprivSetPhrase(void)
{
	UINT8 j;
	UINT8 securityType;
	UINT8* phraseStart;
	UINT8* phraseEnd;
	UINT8 phraseLen;

	if ( iwprivCb.securityType == WF_SECURITY_WPA_AUTO_WITH_KEY || iwprivCb.securityType == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE )
	{
		securityType = WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE;
	}
	else
	{
		WFConsolePrintRomStr("WPA-PSK or WPA-PHRASE encryption mode is not selected", TRUE);
		return FALSE;
	}

	if (ARGC < 3u)
	{
		WFConsolePrintRomStr("Missing value for last parameter", TRUE);
		return FALSE;
	}

	phraseStart = (UINT8*) ARGV[2];
	if (*phraseStart == '\"') // cancatenate remaining args into one string
	{
		for (j = 2; j < (ARGC-1); j++)
		{
			UINT8 argLen = strlen((char*)ARGV[j]);
			ARGV[j][argLen] = ' '; // replace '\0' with ' '
		}

		// searching for an ending quote
		phraseEnd = phraseStart + strlen((char *)phraseStart) - 1;
		while (*phraseEnd != '\"')
			phraseEnd--;

		// remove the double quotes
		phraseStart++;
		phraseEnd--;
	}
	else // a single word
	{
		phraseEnd = phraseStart + strlen((char *)phraseStart) - 1;
	}

	phraseLen = phraseEnd - phraseStart + 1;
	if (phraseLen < WF_MIN_WPA_PASS_PHRASE_LENGTH || WF_MAX_WPA_PASS_PHRASE_LENGTH < phraseLen)
	{
		WFConsolePrintRomStr("Phrase string must be at least 8 chars and no greater than 64", TRUE);
		return FALSE;
	}
	
	iwprivCb.securityType = securityType;

	memcpy((void*)iwprivCb.securityKey, (const void*)phraseStart, phraseLen);
	iwprivCb.securityKey[phraseLen] = '\0'; // just for easy printing on the console
	iwprivCb.securityKeyLength = phraseLen;

	WF_CPSetSecurity(iwprivCb.cpId, iwprivCb.securityType, 0,
	    iwprivCb.securityKey, iwprivCb.securityKeyLength);

	return TRUE;
}
Exemplo n.º 22
0
/*******************************************************************************
  Function:
	  void iwconfigDisplayStatus(void)

  Summary:
	Responds to the user invoking iwconfig with no parameters

  Description:
	Responds to the user invoking iwconfig with no parameters

  Parameters:
      None.

  Returns:
	None

  Remarks:
       None.
 *****************************************************************************/
static void iwconfigDisplayStatus(void)
{
    UINT8 *p;
    UINT8 tmp;
    UINT8 connectionState;
    UINT8 cpId;
#if defined(MRF24WG)
    char buf[6];
#endif

    union
    {
        struct
        {
            UINT8 List[WF_CHANNEL_LIST_LENGTH];
            UINT8 Num;
        } Channel;

        UINT8 Domain;

        struct
        {
            UINT8 String[WF_MAX_SSID_LENGTH+1];
            UINT8 Len;
        } Ssid;

        struct
        {
            UINT8 NetworkType;
        } Mode;

        struct
        {
            UINT16 Threshold;
        } Rts;
    } ws; // workspace

    // cpId
    {
        WFConsolePrintRomStr("\tcpid:     ", FALSE);
        WFConsolePrintInteger(iwconfigCb.cpId, 'd');
        WFConsolePrintRomStr("", TRUE);
    }

    // channel
    {
        WF_CAGetChannelList(ws.Channel.List, &ws.Channel.Num);
        WFConsolePrintRomStr("\tchannel:  ", FALSE);

        p = ws.Channel.List;
        tmp = ws.Channel.Num;

        while ( --tmp > 0u )
        {
            WFConsolePrintInteger(*p, 'd');
            WFConsolePrintRomStr(",", FALSE);
            p++;
        }

        WFConsolePrintInteger(*p, 'd');
        WFConsolePrintRomStr("", TRUE);
    }

#if defined(MRF24WG)
    // domain
    {
        WF_GetRegionalDomain(&ws.Domain);

        WFConsolePrintRomStr("\tdomain:   ", FALSE);

        if ( ws.Domain == WF_DOMAIN_FCC )
        {
            WFConsolePrintRomStr("fcc", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_ETSI )
        {
            WFConsolePrintRomStr("etsi", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_JAPAN )
        {
            WFConsolePrintRomStr("japan", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_OTHER )
        {
            WFConsolePrintRomStr("other", TRUE);
        }
        else
        {
            WFConsolePrintRomStr("unknown", TRUE);
        }
    }
#else
    // domain
    {
        WF_GetRegionalDomain(&ws.Domain);

        WFConsolePrintRomStr("\tdomain:   ", FALSE);

        if ( ws.Domain == WF_DOMAIN_FCC )
        {
            WFConsolePrintRomStr("fcc", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_IC )
        {
            WFConsolePrintRomStr("ic", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_ETSI )
        {
            WFConsolePrintRomStr("etsi", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_SPAIN )
        {
            WFConsolePrintRomStr("spain", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_FRANCE )
        {
            WFConsolePrintRomStr("france", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_JAPAN_A )
        {
            WFConsolePrintRomStr("japana", TRUE);
        }
        else if ( ws.Domain == WF_DOMAIN_JAPAN_B )
        {
            WFConsolePrintRomStr("japanb", TRUE);
        }
        else
        {
            WFConsolePrintRomStr("unknown", TRUE);
        }
    }

#endif

    // rts
    {
        WF_GetRtsThreshold(&ws.Rts.Threshold);

        WFConsolePrintRomStr("\trts:      ", FALSE);
        WFConsolePrintInteger(ws.Rts.Threshold, 'd');
        WFConsolePrintRomStr("", TRUE);
    }

    // mode
    {

        WF_CMGetConnectionState(&connectionState, &cpId);
        WF_CPGetNetworkType(iwconfigCb.cpId, &ws.Mode.NetworkType);

        WFConsolePrintRomStr("\tmode:     ", FALSE);

        if (iwconfigCb.isIdle)
        {
            if (iwconfigCb.connState == WF_CSTATE_NOT_CONNECTED)
            {
                WFConsolePrintRomStr("idle", TRUE);
            }
            else if (iwconfigCb.connState == WF_CSTATE_CONNECTION_PERMANENTLY_LOST)
            {
                WFConsolePrintRomStr("idle (connection permanently lost)", TRUE);
            }
            else
            {
                WFConsolePrintRomStr("idle (?)", TRUE);
            }
        }
        else
        {
            WF_CPGetNetworkType(iwconfigCb.cpId, &ws.Mode.NetworkType);
            if (ws.Mode.NetworkType == WF_INFRASTRUCTURE)
            {
                if (iwconfigCb.connState == WF_CSTATE_CONNECTION_IN_PROGRESS)
                {
                    WFConsolePrintRomStr("managed (connection in progress)", TRUE);
                }
                else if (iwconfigCb.connState == WF_CSTATE_CONNECTED_INFRASTRUCTURE)
                {
                    WFConsolePrintRomStr("managed", TRUE);
                }
                else if (iwconfigCb.connState == WF_CSTATE_RECONNECTION_IN_PROGRESS)
                {
                    WFConsolePrintRomStr("managed (reconnection in progress)", TRUE);
                }
                else
                {
                    WFConsolePrintRomStr("managed (?)", TRUE);
                }
            }
            else if (ws.Mode.NetworkType == WF_ADHOC)
            {
                if (iwconfigCb.connState == WF_CSTATE_CONNECTION_IN_PROGRESS)
                {
                    WFConsolePrintRomStr("adhoc (connection in progress)", TRUE);
                }
                else if (iwconfigCb.connState == WF_CSTATE_CONNECTED_ADHOC)
                {
                    WFConsolePrintRomStr("adhoc", TRUE);
                }
                else if (iwconfigCb.connState == WF_CSTATE_RECONNECTION_IN_PROGRESS)
                {
                    WFConsolePrintRomStr("adhoc (reconnection in progress)", TRUE);
                }
                else
                {
                    WFConsolePrintRomStr("adhoc (?)", TRUE);
                }
            }
            else
            {
                WFConsolePrintRomStr("unknown", TRUE);
            }
        }
    }

    // ssid
    {
        WF_CPGetSsid(iwconfigCb.cpId, ws.Ssid.String, &ws.Ssid.Len);
        ws.Ssid.String[ws.Ssid.Len] = '\0';

        WFConsolePrintRomStr("\tssid:     ", FALSE);
        WFConsolePrintRamStr(ws.Ssid.String, TRUE);
    }

    // power
    {
        switch (iwconfigCb.powerSaveState)
        {
        case WF_PS_PS_POLL_DTIM_ENABLED:
            WFConsolePrintRomStr("\tpwrsave:  enabled", TRUE);
            WFConsolePrintRomStr("\tdtim rx:  enabled", TRUE);
            break;
        case WF_PS_PS_POLL_DTIM_DISABLED:
            WFConsolePrintRomStr("\tpwrsave:  enabled", TRUE);
            WFConsolePrintRomStr("\tdtim rx:  disabled", TRUE);
            break;
        case WF_PS_OFF:
            WFConsolePrintRomStr("\tpwrsave:  disabled", TRUE);
            break;
        default:
            WFConsolePrintRomStr("\tpwrsave:  unknown(", FALSE);
            WFConsolePrintInteger(iwconfigCb.powerSaveState, 'd');
            WFConsolePrintRomStr(")", TRUE);
            break;
        }
    }

#if defined(MRF24WG)
    // context
    WF_OutputConnectionContext();

    // Network Type
    putrsUART("\tNetwork:  ");
#if defined(EZ_CONFIG_STORE) && !defined(WF_CONSOLE_DEMO)   /* if EZConfig demo */

    if (AppConfig.networkType == WF_ADHOC)
    {
        putrsUART("AdHoc\r\n");
    }
    else
    {
        putrsUART("Infrastructure\r\n");
    }
#else
#if (MY_DEFAULT_NETWORK_TYPE == WF_ADHOC)
    putrsUART("AdHoc\r\n");
#elif (MY_DEFAULT_NETWORK_TYPE == WF_P2P)
    putrsUART("P2P\r\n");
#elif (MY_DEFAULT_NETWORK_TYPE == WF_INFRASTRUCTURE)
#if (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPS_PUSH_BUTTON)
    putrsUART("Infrastructure (using WPS Push Button)\r\n");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPS_PIN)
    putrsUART("Infrastructure (using WPS Pin)\r\n");
#else
    putrsUART("Infrastructure\r\n");
#endif
#endif
#endif /* EZ_CONFIG_STORE  */

    // Retry Count
    putrsUART("\tRetries   ");
#if (MY_DEFAULT_NETWORK_TYPE == WF_ADHOC)
    sprintf(buf, "%d\r\n", ADHOC_RETRY_COUNT);
    putsUART(buf);
#elif (MY_DEFAULT_NETWORK_TYPE == WF_INFRASTRUCTURE)
#if (INFRASTRUCTURE_RETRY_COUNT == WF_RETRY_FOREVER)
    sprintf(buf, "Retry Forever\r\n");
    putsUART(buf);
#else
    sprintf(buf, "%d\r\n", INFRASTRUCTURE_RETRY_COUNT);
    putsUART(buf);
#endif
#endif    /* (MY_DEFAULT_NETWORK_TYPE == WF_ADHOC) */

    // Security
    putrsUART("\tSecurity: ");
#if (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_OPEN)
    putrsUART("WF_SECURITY_OPEN");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WEP_40)
    putrsUART("WF_SECURITY_WEP_40");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WEP_104)
    putrsUART("WF_SECURITY_WEP_104");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPA_WITH_KEY)
    putrsUART("WF_SECURITY_WPA_WITH_KEY");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPA_WITH_PASS_PHRASE)
    putrsUART("WF_SECURITY_WPA_WITH_PASS_PHRASE");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPA2_WITH_KEY)
    putrsUART("WF_SECURITY_WPA2_WITH_KEY");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPA2_WITH_PASS_PHRASE)
    putrsUART("WF_SECURITY_WPA2_WITH_PASS_PHRASE");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPA_AUTO_WITH_KEY)
    putrsUART("WF_SECURITY_WPA_AUTO_WITH_KEY");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE)
    putrsUART("WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPS_PUSH_BUTTON)
    putrsUART("WF_SECURITY_WPS_PUSH_BUTTON");
#elif (MY_DEFAULT_WIFI_SECURITY_MODE == WF_SECURITY_WPS_PIN)
    putrsUART("WF_SECURITY_WPS_PIN");
#else
    putrsUART("Unknown");
#endif
    putrsUART("\r\n");

    // scan type
    putrsUART("\tScan:     ");
#if (MY_DEFAULT_SCAN_TYPE == WF_ACTIVE_SCAN)
    putrsUART("Active Scan\r\n");
#else
    putrsUART("Passive Scan\r\n");
#endif

    // MAC address
    putrsUART("\tMAC:      ");
    OutputMacAddress();

#endif  /* MRF24WG */
}
Exemplo n.º 23
0
static void notHandledParam(UINT8 index)
{
    WFConsolePrintRomStr("Param ", FALSE);
	WFConsolePrintInteger(index, 'd');
	WFConsolePrintRomStr(" not handled", TRUE);
}
Exemplo n.º 24
0
/*******************************************************************************
  Function:
    void do_iwconfig_cmd(void)

  Summary:
    Responds to the user invoking iwconfig command

  Description:
    Responds to the user invoking iwconfig command

  Precondition:
    MACInit must be called first.

  Parameters:
    None.

  Returns:
    None.

  Remarks:
    None.
 *****************************************************************************/
void do_iwconfig_cmd(void)
{
    if (!WF_hibernate.state && !iwconfigSetCb() )
        return;

    // if user only typed in iwconfig with no other parameters
    if (ARGC == 1u)
    {
        if (!WF_hibernate.state)
            iwconfigDisplayStatus();
        else
#if defined(STACK_USE_UART)
            WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", TRUE);
#endif
        return;
    }

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "wakeup") == 0) )
    {
        if (!WF_hibernate.wakeup_notice)
        {
            WF_hibernate.wakeup_notice = TRUE;
        }

#if defined(STACK_USE_UART)
        WFConsolePrintRomStr("The Wi-Fi module is awake.", TRUE);
#endif

        return;
    }

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "hibernate") == 0) )
    {
        if (!WF_hibernate.state)
        {
            WF_hibernate.state = WF_HB_ENTER_SLEEP;
            WF_hibernate.wakeup_notice = FALSE;
            WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode.", TRUE);
        }
        else
            WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode.", TRUE);
        return;
    }

    if (WF_hibernate.state)
    {
        WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", TRUE);
        return;
    }

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "ssid") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetSsid())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "mode") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetMode())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "channel") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetChannel())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "power") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetPower())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "domain") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetDomain())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "rts") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetRTS())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "txrate") == 0) )
    {
        // txrate is NOT available. Will always return FALSE
        if (!WF_hibernate.state && !iwconfigSetTxRate())
            return;
    }

#if defined ( EZ_CONFIG_SCAN ) && !defined(__18CXX)
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "scan") == 0))
    {
        if (!WF_hibernate.state)
        {
            // WFInitScan();
            WFConsolePrintRomStr("Scanning...", TRUE);
            if (WFStartScan() == WF_SUCCESS)
            {
                WFConsolePrintRomStr("Scan completed.", TRUE);
            }
            else
            {
                WFConsolePrintRomStr("Scan failed. Already in progress or not allowed", TRUE);
            }
        }
        else
        {
            WFConsolePrintRomStr("In hibernate mode - scan is not allowed.", TRUE);
        }
        return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "scanresults") == 0) )
    {
        if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
            WFConsolePrintRomStr("Scann in process...please wait or try again later", TRUE);
        else if (SCANCXT.numScanResults > 0)
        {
            SCAN_SET_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
            while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
            {
                WFDisplayScanMgr();
            }
        }
        else
            WFConsolePrintRomStr("No scan results to display.", TRUE);

        return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "starttest") == 0))
    {
        test_flag = TRUE;
        test_count = 0;
        return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "stoptest") == 0))
    {
        test_flag = FALSE;
        return;
    }

#endif /* EZ_CONFIG_SCAN */

    else if( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "connect") == 0))
    {
        iwconfigSetConnect();
        return;
    }
#ifdef	STACK_USE_CERTIFICATE_DEBUG
    else if( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "macstats") == 0))
    {
        iwconfigGetMacStats();
        return;
    }
#endif
    else
    {
        WFConsolePrintRomStr("Unknown parameter", TRUE);
        return;
    }
}
Exemplo n.º 25
0
/*******************************************************************************
  Function:
      BOOL iwconfigSetCb(void)

  Summary:
	Set the iwconfigCb structure

  Description:
	Set the iwconfigCb structure

  Parameters:
      None.

  Returns:
      TRUE or FALSE

  Remarks:
       None.
 *****************************************************************************/
BOOL iwconfigSetCb(void)
{
    UINT8 cpId;

    if ( !iwconfigCbInitialized ) // first time call of iwconfigSetCb
    {
        memset(&iwconfigCb, 0, sizeof(iwconfigCb));
        iwconfigCbInitialized = TRUE;
    }

#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
    WF_GetPowerSaveState(&iwconfigCb.powerSaveState);
#endif
    if (iwconfigCb.powerSaveState == WF_PS_HIBERNATE)
    {
        WFConsolePrintRomStr("WF device hibernated", TRUE);
        return FALSE;
    }

    WF_CMGetConnectionState(&iwconfigCb.connState, &cpId);

    if ( iwconfigCb.cpId == WF_CURRENT_CPID_NONE )
    {
        if ( cpId == WF_CURRENT_CPID_NONE )
        {
            iwconfigCb.cpId = 1;     // console demo only supports 1 CPID; don't create a new one here
        }
        else if ( cpId == WF_CURRENT_CPID_LIST )
        {
            WFConsolePrintRomStr("Connection profile list not supported", TRUE);
            return FALSE;
        }
        else
        {
            iwconfigCb.cpId = cpId; // use the application-created profile
        }
    }
    else // WF_MIN_NUM_CPID <= iwconfigCb.cpId && iwconfigCb.cpId <= WF_MAX_NUM_CPID
    {
        if ( cpId == WF_CURRENT_CPID_NONE )
        {
            // continue to use iwconfigCb.cpId
        }
        else if ( cpId == WF_CURRENT_CPID_LIST )
        {
            WFConsolePrintRomStr("Conection profile list not supported", TRUE);

            WF_CPDelete(iwconfigCb.cpId);
            iwconfigCb.cpId = WF_CURRENT_CPID_NONE;

            return FALSE;
        }
        else if ( cpId != iwconfigCb.cpId )
        {
            WF_CPDelete(iwconfigCb.cpId);
            iwconfigCb.cpId = cpId; // use the application-created profile
        }
        else // cpId == iwconfigCb.cpId
        {
            // contine to use iwconfigCb.cpId
        }
    }

    if ((iwconfigCb.connState == WF_CSTATE_NOT_CONNECTED) || (iwconfigCb.connState == WF_CSTATE_CONNECTION_PERMANENTLY_LOST))
    {
        iwconfigCb.isIdle = TRUE;
    }
    else
    {
        iwconfigCb.isIdle = FALSE;
    }

    return TRUE;
}
Exemplo n.º 26
0
static BOOL iwconfigSetConnect(void)
{   // IWCONFIG CONNECT [ssid] [channel] [power-mode]   //[security-mode] [WEP-key/passphrase] [retry-attempt]
    UINT8 networkType;
    if(ARGC < 3u)
    {
        putsUART("Wrong command, correct command is:IWCONFIG CONNECT [ssid] [bssid] [channel] [power-mode]\r\n");
        return FALSE;
    }
    networkType = SetMode_idle();
    if(ARGC >= 3u) // ssid
    {
        WF_CPSetSsid(iwconfigCb.cpId, (UINT8 *)ARGV[2], strlen((char*)ARGV[2]));
    }
    if(ARGC >= 4u) //channel
    {
        int int_channel;
        sscanf((const char *)ARGV[3], (const char *)"%d",&int_channel);
        if((int_channel>=1)&&(int_channel<=14))
        {
            WF_CASetChannelList((UINT8 *)&int_channel, 1);
        }
        else
        {
            WFConsolePrintRomStr("channel err (1~14): Unknown parameter", TRUE);
            return FALSE;
        }
    }
    if(ARGC >= 5u) //channel
    {
        int int_channel;
        UINT8 channel;
        sscanf((const char *)ARGV[4], (const char *)"%d",&int_channel);
        if((int_channel>=1)&&(int_channel<=14))
        {
            channel = int_channel;
            //{char buf_t[20];sprintf(buf_t,"channel=%d\r\n",int_channel);putsUART(buf_t);}
            WF_CASetChannelList(&channel, 1);
            DelayMs(100);
        }
        else
        {
            WFConsolePrintRomStr("channel err (1~14): Unknown parameter", TRUE);
            return FALSE;
        }
    }
    if(ARGC >= 6u) // power-mode
    {
        if (strcmppgm2ram((char*)ARGV[5], "reenable") == 0)
        {   // reenable power saving
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
            WF_PsPollEnable(TRUE);
#endif
        }
        else if  (strcmppgm2ram((char*)ARGV[5], "disable") == 0)
        {   // disable power saving
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
            WF_PsPollDisable();
#endif
        }
        else if  (strcmppgm2ram((char*)ARGV[5], "unicast") == 0)
        {   // enable power saving but don't poll for DTIM
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
            WF_PsPollEnable(FALSE);
#endif
        }
        else if  (strcmppgm2ram((char*)ARGV[5], "all") == 0)
        {   // enable power saving and poll for DTIM
#if defined(WF_USE_POWER_SAVE_FUNCTIONS)
            WF_PsPollEnable(TRUE);
#endif
        }
        else
        {
            WFConsolePrintRomStr("Unknown parameter", TRUE);
            return FALSE;
        }
    }
    if(ARGC >= 7u) // [security-mode]
    {

    }
    SetMode_NotIdle(networkType);
    return TRUE;
}
/*****************************************************************************
 * FUNCTION: do_ifconfig_cmd
 *
 * RETURNS: None
 *
 * PARAMS:  None
 *
 * NOTES:   Responds to the user invoking ifconfig
 *****************************************************************************/
void do_ifconfig_cmd(void)
{
     uint8_t   macAddress[6];
     uint8_t conState, cpId;
     IP_ADDR ipAddress;

    // if user only typed in ifconfig with no other parameters
    if (ARGC == 1u)
    {
        IfconfigDisplayStatus();
        return;
    }

    if (WF_hibernate.state)
    {
        WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", true);
        return;
    }

#if defined(WF_CM_DEBUG)
    else if ( (ARGC == 2u) && !strcmp((char *) ARGV[1], "info") )
    {
        uint8_t i;
        tWFCMInfoFSMStats cm_stats;

        WF_CMInfoGetFSMStats(&cm_stats);
        for (i = 0; i < 12; i++)
        {
            sprintf( (char *) g_ConsoleContext.txBuf,
                    "[%02X]: %02X%02X %02X%02X",
                    i,
                    cm_stats.byte[i*4 + 0],
                    cm_stats.byte[i*4 + 1],
                    cm_stats.byte[i*4 + 2],
                    cm_stats.byte[i*4 + 3]
                    );
            WFConsolePrintRamStr( (char *) g_ConsoleContext.txBuf , true);
        }
    }
    else if ( (ARGC == 2u) && !strcmp((char *) ARGV[1], "scan") )
    {
        if (WF_Scan(1) != WF_SUCCESS) // scan, using CP 1
            WFConsolePrintRomStr("Scan failed", true);
    }
    else if ( (ARGC == 2u) && !strcmp((char *) ARGV[1], "scanget") ) //"scangetresult"
    {
        tWFScanResult pScanResult[1];

        WF_ScanGetResult(0, pScanResult);
    }
    else if ( (ARGC == 2u) && !strcmp((char *) ARGV[1], "cpgete") ) //"cpgetelements"
    {
        tWFCPElements pCPElements[1];

        WF_CPGetElements(1, pCPElements);
    }
#endif
    // else if 2 arguments and the second arg is IP address
    else if ( (ARGC == 2u) && (StringToIPAddress((uint8_t*)ARGV[1], &ipAddress)) )
    {
        #if defined(STACK_USE_DHCP_CLIENT)
        if (DHCPIsEnabled(0))
        {
          WFConsolePrintRomStr("Static IP address should not be set with DHCP enabled", true);
          return;
        }
        #endif

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

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

        LCDDisplayIPValue(AppConfig.MyIPAddr);
    }
    // else if 2 args and second arg is MAC address
    else if ( (ARGC == 2u) && isMacAddress(ARGV[1], macAddress))
    {
        /* Can only set MAC address in idle state */
        WF_CMGetConnectionState(&conState, &cpId);
        if ( conState != WF_CSTATE_NOT_CONNECTED )
        {
            WFConsolePrintRomStr("HW MAC address can only be set in idle mode", true);
            return;
        }

        WF_SetMacAddress( macAddress );
        AppConfig.MyMACAddr.v[0] = macAddress[0];
        AppConfig.MyMACAddr.v[1] = macAddress[1];
        AppConfig.MyMACAddr.v[2] = macAddress[2];
        AppConfig.MyMACAddr.v[3] = macAddress[3];
        AppConfig.MyMACAddr.v[4] = macAddress[4];
        AppConfig.MyMACAddr.v[5] = macAddress[5];
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char *)ARGV[1], (ROM FAR char *)"netmask") == 0) )
    {
        if (ARGC != 3u)
        {
            missingValue();
            return;
        }

        #if defined(STACK_USE_DHCP_CLIENT)
        if ( DHCPIsEnabled(0) )
        {
            WFConsolePrintRomStr(
                "The Netmask should not be set with DHCP enabled", true);
            return;
        }
        #endif

        if ( !StringToIPAddress((uint8_t*)ARGV[2], &ipAddress) )
        {
            WFConsolePrintRomStr("Invalid netmask value", true);
            return;
        }

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

        /* Microchip DHCP client clobbers static netmask on every iteration of loop, even if dhcp is turned off*/
        AppConfig.DefaultMask.v[0] = ipAddress.v[0];
        AppConfig.DefaultMask.v[1] = ipAddress.v[1];
        AppConfig.DefaultMask.v[2] = ipAddress.v[2];
        AppConfig.DefaultMask.v[3] = ipAddress.v[3];
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char *)ARGV[1], (ROM FAR char *)"gateway") == 0) )
    {
        if (ARGC != 3u)
        {
            missingValue();
            return;
        }

        if ( !StringToIPAddress((uint8_t*)ARGV[2], &ipAddress) )
        {
            WFConsolePrintRomStr("Invalid gateway value", true);
            return;
        }

        AppConfig.MyGateway.v[0] = ipAddress.v[0];
        AppConfig.MyGateway.v[1] = ipAddress.v[1];
        AppConfig.MyGateway.v[2] = ipAddress.v[2];
        AppConfig.MyGateway.v[3] = ipAddress.v[3];
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "auto-dhcp") == 0) )
    {
        if (ARGC != 3u)
        {
            missingValue();
            return;
        }

        #if defined(STACK_USE_DHCP_CLIENT)
        if (strcmppgm2ram((char*)ARGV[2], "start") == 0)
        {
            setDHCPState(true);
        }
        else if (strcmppgm2ram((char*)ARGV[2], "stop") == 0)
        {
            setDHCPState(false);
        }
        else
        #endif
        {
            WFConsolePrintRomStr("   Invalid dhcp param", true);
            return;
        }
    }
    else
    {
        notHandledParam(1);
    }
}
Exemplo n.º 28
0
/*******************************************************************************
  Function:
	  BOOL iwconfigSetDomain(void)

  Summary:
	 Set the domain.

  Description:
	 Set the MRF24W Regional Domain.
	 For MRF24WG with RF module FW version 0x3107 and future releases, this function
	 is NOT supported due to changes in FCC requirements, which does not allow programming
	 of the regional domain.

  Parameters:
       Domain - fcc / etsi /japan / other

  Returns:
	TRUE or FALSE

  Remarks:
       None.
 *****************************************************************************/
static BOOL iwconfigSetDomain(void)
{
    UINT8 domain;

    if (ARGC < 3u)
    {
        WFConsolePrintRomStr("Missing value for last parameter", TRUE);
        return FALSE;
    }

    if ( !iwconfigCb.isIdle )
    {
        WFConsolePrintRomStr("Domain can only be set in idle mode", TRUE);
        return FALSE;
    }

#if defined(MRF24WG)
    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "fcc") == 0) )
    {
        domain = WF_DOMAIN_FCC;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "etsi") == 0) )
    {
        domain = WF_DOMAIN_ETSI;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "japan") == 0) )
    {
        domain = WF_DOMAIN_JAPAN;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "other") == 0) )
    {
        domain = WF_DOMAIN_OTHER;
    }
    else
    {
        WFConsolePrintRomStr("Unknown domain", TRUE);
        return FALSE;
    }
#else
    if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "fcc") == 0) )
    {
        domain = WF_DOMAIN_FCC;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "ic") == 0) )
    {
        domain = WF_DOMAIN_IC;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "etsi") == 0) )
    {
        domain = WF_DOMAIN_ETSI;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "spain") == 0) )
    {
        domain = WF_DOMAIN_SPAIN;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "france") == 0) )
    {
        domain = WF_DOMAIN_FRANCE;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "japana") == 0) )
    {
        domain = WF_DOMAIN_JAPAN_A;
    }
    else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "japanb") == 0) )
    {
        domain = WF_DOMAIN_JAPAN_B;
    }
    else
    {
        WFConsolePrintRomStr("Unknown domain", TRUE);
        return FALSE;
    }
#endif

    WF_SetRegionalDomain(domain);
    WF_CASetChannelList(NULL, 0); // reset to domain default channel list

    return TRUE;
}
static void missingValue(void)
{
    WFConsolePrintRomStr(
        "Missing value after last parameter", true);
}
static void notHandledParam(uint8_t index)
{
    WFConsolePrintRomStr("Param ", false);
    WFConsolePrintInteger(index, 'd');
    WFConsolePrintRomStr(" not handled", true);
}