示例#1
0
static int _Command_MACAddressSet(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    TCPIP_MAC_ADDR macAddr;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc != 3) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: setmac <interface> <x:x:x:x:x:x> \r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: setmac PIC32INT aa:bb:cc:dd:ee:ff \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    (*pCmdIO->pCmdApi->print)(cmdIoParam, "argv[2]: %s\r\n", argv[2]);

    if (!TCPIP_Helper_StringToMACAddress(argv[2], macAddr.v)) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid MAC address string \r\n");
        return false;
    }

    if(!TCPIP_STACK_NetAddressMacSet(netH, &macAddr)) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Set MAC address failed\r\n");
        return false;
    }

    return true;
}
示例#2
0
static int _Command_PrimaryDNSAddressSet(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    IPV4_ADDR ipDNS;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc != 3) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: setdns <interface> <x.x.x.x> \r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: setdns PIC32INT 255.255.255.0 \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    if (!TCPIP_Helper_StringToIPAddress(argv[2], &ipDNS)) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid IP address string \r\n");
        return false;
    }

    if(!TCPIP_STACK_NetAddressDnsPrimarySet(netH, &ipDNS)) {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Set DNS address failed\r\n");
        return false;
    }

    return true;
}
示例#3
0
static int _Command_BIOSNameSet(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    const char* msg;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc != 3)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: setbios <interface> <x.x.x.x> \r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: setbios PIC32INT MCHPBOARD_29 \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    if(TCPIP_STACK_NetBiosNameSet(netH, argv[2]))
    {
        msg = "Set BIOS Name OK\r\n";
    }
    else
    {
        msg = "Set BIOS Name failed\r\n";
    }

    (*pCmdIO->pCmdApi->msg)(cmdIoParam, msg);
    return true;
}
示例#4
0
static int _Command_DefaultInterfaceSet (_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc != 2)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: defnet <interface>\r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: defnet PIC32INT\r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    if(TCPIP_STACK_NetDefaultSet(netH))
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Default interface set successful\r\n");
    }
    else
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Operation not accepted\r\n");
    }

    return true;
}
示例#5
0
static int _Command_DHCPLeaseInfo(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    DHCPS_LEASE_HANDLE  prevLease, nextLease;
    DHCPS_LEASE_ENTRY leaseEntry;
    char   addrBuff[20];
const void* cmdIoParam = pCmdIO->cmdIoParam;	

	if (argc != 2)
    {
		(*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: dhcpsinfo <interface> \r\n");
		(*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: dhcpsinfo PIC32INT \r\n");
		return false;
	}

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

	(*pCmdIO->pCmdApi->print)(cmdIoParam,"MAC Address		IPAddress		RemainingLeaseTime \r\n",0);

    prevLease = 0;
    do
    {
        nextLease = TCPIP_DHCPS_LeaseEntryGet(netH, &leaseEntry, prevLease);
		if(!nextLease)
		{
            (*pCmdIO->pCmdApi->print)(cmdIoParam, " \n\r No more entry present \r\n", 0);
		}
        if(nextLease)
        {   // valid info
            // display info
            TCPIP_Helper_MACAddressToString(&leaseEntry.hwAdd, addrBuff, sizeof(addrBuff));
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, addrBuff);
            TCPIP_Helper_IPAddressToString(&leaseEntry.ipAddress, addrBuff, sizeof(addrBuff));
            (*pCmdIO->pCmdApi->print)(cmdIoParam, "	%s ", addrBuff);
            (*pCmdIO->pCmdApi->print)(cmdIoParam, "	%d Secs\r\n", leaseEntry.leaseTime/SYS_TICK_TicksPerSecondGet());

            prevLease = nextLease;
        }
    }while(nextLease != 0);


	return true;

}
示例#6
0
文件: sntp.c 项目: ctapang/v0_70_01b
// sntp_manager.h
bool TCPIP_SNTP_Initialize(const TCPIP_STACK_MODULE_CTRL* const stackCtrl, const SNTP_MODULE_CONFIG* pSNTPConfig)
{

    if(stackCtrl->stackAction == TCPIP_STACK_ACTION_IF_UP)
    {   // interface restart
        return true;
    }

    // stack init
    _SntpInit(stackCtrl->pNetIf);

    pSntpDefIf = (TCPIP_NET_IF*)TCPIP_STACK_NetHandleGet(NTP_DEFAULT_IF);

    ntpLastError = SNTP_RES_NTP_SERVER_TMO; 
    sntpState = SM_HOME;
    return true;

}//TCPIP_SNTP_Initialize
static void WF_Initialize_IPV6_Multicast_Filter(void)
{
    TCPIP_NET_IF* pNetIf;
    TCPIP_NET_HANDLE netH = TCPIP_STACK_NetHandleGet("MRF24W");
    uint8_t solicitedNodeMulticastMACAddr[] = {0x33, 0x33, 0xff, 0x00, 0x00, 0x00};
    uint8_t allNodesMulticastMACAddr[] = {0x33, 0x33, 0x00, 0x00, 0x00, 0x01};
    uint8_t i;

    pNetIf =  (TCPIP_NET_IF*)netH;

    for (i =0; i < 3; i++)
    {
        solicitedNodeMulticastMACAddr[3 + i] = pNetIf->netMACAddr.v[3 + i];
    }

    #if (WF_SOFTWARE_MULTICAST_FILTER ==  DRV_WIFI_ENABLED)
        DRV_WIFI_SWMultiCastFilterEnable();
        do {
            DRV_WIFI_SWMULTICAST_CONFIG p_config;

            p_config.filterId = DRV_WIFI_MULTICAST_FILTER_1;
            p_config.action = DRV_WIFI_MULTICAST_USE_FILTERS;
            memcpy((void *)p_config.macBytes, (void *)solicitedNodeMulticastMACAddr, WF_MAC_ADDRESS_LENGTH);
            p_config.macBitMask = 0x3F;
            DRV_WIFI_SWMulticastFilterSet(&p_config);

            p_config.filterId = DRV_WIFI_MULTICAST_FILTER_2;
            p_config.action = DRV_WIFI_MULTICAST_USE_FILTERS;
            memcpy((void *)p_config.macBytes, (void *)allNodesMulticastMACAddr, WF_MAC_ADDRESS_LENGTH);
            p_config.macBitMask = 0x3F;
            DRV_WIFI_SWMulticastFilterSet(&p_config);
        } while (0);

    #else // using HW multicast flters
        DRV_WIFI_HWMulticastFilterSet(DRV_WIFI_MULTICAST_FILTER_1, solicitedNodeMulticastMACAddr);
        DRV_WIFI_HWMulticastFilterSet(DRV_WIFI_MULTICAST_FILTER_2, allNodesMulticastMACAddr);
    #endif 
}
void DhcpConfigTask(void)
{
    TCPIP_NET_HANDLE netH;
    uint8_t networkType;

    networkType = GetWiFiNetworkType();

    netH = TCPIP_STACK_NetHandleGet("MRF24W");
    if(networkType == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
    {
        TCPIP_DHCP_Disable(netH);          //Client  Off
        TCPIP_DHCPS_Enable(netH);     //Server On
    }
    else if(networkType == DRV_WIFI_NETWORK_TYPE_INFRASTRUCTURE)
    {
        TCPIP_DHCP_Enable(netH);           //Client On
        TCPIP_DHCPS_Disable(netH);    //Server Off
    }
    else if(networkType == DRV_WIFI_NETWORK_TYPE_ADHOC)
    {
        TCPIP_DHCP_Disable(netH);          //Client Off
        TCPIP_DHCPS_Enable(netH);     //Server On
    }
}
示例#9
0
static int _Command_NetworkOnOff(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    bool res = false;
    TCPIP_NET_HANDLE netH;
#if defined(TCPIP_STACK_COMMANDS_STORAGE_ENABLE)
    TCPIP_COMMAND_STG_DCPT*   pDcpt;
    TCPIP_NETWORK_CONFIG*     pNetConf;
#endif  // defined(TCPIP_STACK_COMMANDS_STORAGE_ENABLE)
    uint16_t net_ix = 0;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc != 3)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: if <interface> <down/up> \r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: if PIC32INT down \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);

    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    net_ix = TCPIP_STACK_NetIndexGet(netH);

    if (memcmp(argv[2], "up", 2) == 0)
    {
        if(TCPIP_STACK_NetIsUp(netH))
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "This interface already up\r\n");
            return true;
        }

#if defined(TCPIP_STACK_COMMANDS_STORAGE_ENABLE)
        pNetConf = 0;
        if(pCmdStgDcpt) 
        {
            // get the saved network configuration
            pDcpt = pCmdStgDcpt + net_ix;
            if(pDcpt->stgSize)
            {   // saved config is valid; restore
                pNetConf = TCPIP_STACK_NetConfigSet(&pDcpt->netDcptStg, pDcpt->restoreBuff, sizeof(pDcpt->restoreBuff), 0);
                (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Interface up: configuration " );
                (*pCmdIO->pCmdApi->msg)(cmdIoParam, pNetConf ? "restored\r\n" : "restore failed!\r\n");
            }
        }
        res = TCPIP_STACK_NetUp(netH, pNetConf);
#else
        res = TCPIP_STACK_NetUp(netH, 0);
#endif  // defined(TCPIP_STACK_COMMANDS_STORAGE_ENABLE)

    }
    else if (memcmp(argv[2], "down", 4) == 0)
    {
        if(TCPIP_STACK_NetIsUp(netH) == 0)
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "This interface already down\r\n");
            return true;
        }

#if defined(TCPIP_STACK_COMMANDS_STORAGE_ENABLE)
        if(pCmdStgDcpt) 
        {
            // get the last network configuration so we use it when
            // restart the stack/interface 
            pDcpt = pCmdStgDcpt + net_ix;
            pDcpt->stgSize = TCPIP_STACK_NetConfigGet(netH, &pDcpt->netDcptStg, sizeof(pDcpt->netDcptStg), 0);

            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Interface down: configuration saved\r\n");
        }
#endif  // defined(TCPIP_STACK_COMMANDS_STORAGE_ENABLE)

        res = TCPIP_STACK_NetDown(netH);
    } 
    else
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Wrong parameter specified \r\n");
        return false;
    }

    if (res == true)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Operation successful!\r\n");
    }
    else
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Operation failed!\r\n");
    }

    return true;
}
示例#10
0
static int _Command_GatewayAddressSet(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    IP_ADDRESS_TYPE addType;
#if defined(TCPIP_STACK_USE_IPV4)
    IPV4_ADDR ipGateway;
#endif  // defined(TCPIP_STACK_USE_IPV4)
#if defined(TCPIP_STACK_USE_IPV6)
    IPV6_ADDR  ipv6Gateway;
    unsigned long validTime;
#endif  // defined(TCPIP_STACK_USE_IPV6)
    const void* cmdIoParam = pCmdIO->cmdIoParam;
    bool     success = false;

    if (argc != 3)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: setgw <interface> <ipv4/6 address> <validTime> \r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: setgw PIC32INT 192.168.0.1 \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    addType = IP_ADDRESS_TYPE_ANY;

#if defined(TCPIP_STACK_USE_IPV4)
    if (TCPIP_Helper_StringToIPAddress(argv[2], &ipGateway))
    {
        addType = IP_ADDRESS_TYPE_IPV4;
    }
#endif  // defined(TCPIP_STACK_USE_IPV4)
#if defined(TCPIP_STACK_USE_IPV6)
    if(TCPIP_Helper_StringToIPv6Address (argv[2], &ipv6Gateway))
    {
        addType = IP_ADDRESS_TYPE_IPV6;
    }
#endif  // defined(TCPIP_STACK_USE_IPV6)

    if(addType == IP_ADDRESS_TYPE_ANY)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid IP address string \r\n");
        return false;
    }


#if defined(TCPIP_STACK_USE_IPV4)
    if(addType == IP_ADDRESS_TYPE_IPV4)
    {
        success = TCPIP_STACK_NetAddressGatewaySet(netH, &ipGateway);
    }
#endif  // defined(TCPIP_STACK_USE_IPV4)

#if defined(TCPIP_STACK_USE_IPV6)
    if(addType == IP_ADDRESS_TYPE_IPV6)
    {
        if(argc > 3)
        {   // we have validity time
            validTime = (unsigned long)atoi(argv[3]);
        }
        else
        {
            validTime = 0;
        }
        success = TCPIP_IPV6_RouterAddressAdd(netH, &ipv6Gateway, validTime, 0);
    }
#endif  // defined(TCPIP_STACK_USE_IPV6)


    (*pCmdIO->pCmdApi->msg)(cmdIoParam, success ? "Set gateway address OK\r\n" : "Set gateway address failed\r\n");
    return false;

}
示例#11
0
static int _Command_IPAddressSet(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    TCPIP_NET_IF*   pNetIf;
    IP_ADDRESS_TYPE addType;

#if defined(TCPIP_STACK_USE_IPV4)
    IPV4_ADDR ipAddr, ipMask;
    IPV4_ADDR*  pMask;
#endif  // defined(TCPIP_STACK_USE_IPV4)
#if defined(TCPIP_STACK_USE_IPV6)
    IPV6_ADDR  ipv6Addr;
    int     prefixLen;
#endif  // defined(TCPIP_STACK_USE_IPV6)
    const void* cmdIoParam = pCmdIO->cmdIoParam;
    bool     success = false;

    if (argc < 3)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: setip <interface> <ipv4/6 address> <ipv4mask/ipv6 prefix len>\r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: setip PIC32INT 192.168.0.8 255.255.255.0 \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface specified \r\n");
        return false;
    }

    pNetIf = _TCPIPStackHandleToNetUp(netH);
    if(pNetIf == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "No such interface is up\r\n");
        return false;
    }


    addType = IP_ADDRESS_TYPE_ANY;

#if defined(TCPIP_STACK_USE_IPV4)
    if (TCPIP_Helper_StringToIPAddress(argv[2], &ipAddr))
    {
        addType = IP_ADDRESS_TYPE_IPV4;
    }
#endif  // defined(TCPIP_STACK_USE_IPV4)
#if defined(TCPIP_STACK_USE_IPV6)
    if(TCPIP_Helper_StringToIPv6Address (argv[2], &ipv6Addr))
    {
        addType = IP_ADDRESS_TYPE_IPV6;
    }
#endif  // defined(TCPIP_STACK_USE_IPV6)

    if(addType == IP_ADDRESS_TYPE_ANY)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid IP address string \r\n");
        return false;
    }
    

#if defined(TCPIP_STACK_USE_IPV4)
    if(addType == IP_ADDRESS_TYPE_IPV4)
    {
        if(_TCPIPStackAddressServiceIsRunning(pNetIf) != TCPIP_STACK_ADDRESS_SERVICE_NONE)
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "An address service is already running. Stop DHCP, ZCLL, etc. first\r\n");
            return false;
        }

        if(argc > 3)
        {   // we have net mask too
            if (!TCPIP_Helper_StringToIPAddress(argv[3], &ipMask))
            {
                (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid IP mask string \r\n");
                return false;
            }
            pMask = &ipMask;
        }
        else
        {
            pMask = 0;
        }

        if(TCPIP_STACK_NetAddressSet(netH, &ipAddr, pMask, true))
        {
            success = true;
        }

    }
#endif  // defined(TCPIP_STACK_USE_IPV4)

#if defined(TCPIP_STACK_USE_IPV6)

    if(addType == IP_ADDRESS_TYPE_IPV6)
    {
        if(argc > 3)
        {   // we have prefix length
            prefixLen = atoi(argv[3]);
        }
        else
        {
            prefixLen = 0;
        }

        if(TCPIP_IPV6_UnicastAddressAdd (netH, &ipv6Addr, prefixLen, false) != 0)
        {
            success = true;
        }
    }

#endif  // defined(TCPIP_STACK_USE_IPV6)


    (*pCmdIO->pCmdApi->msg)(cmdIoParam, success ? "Set ip address OK\r\n" : "Set ip address failed\r\n");
    return false;
}
示例#12
0
static int _Command_AddressService(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv, TCPIP_STACK_ADDRESS_SERVICE_TYPE svcType)
{ 
    typedef bool(*addSvcFnc)(TCPIP_NET_HANDLE hNet);

    TCPIP_NET_HANDLE netH;
    addSvcFnc        addFnc;
    bool             addRes, svcEnable;
    const char       *msgOK, *msgFail;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc != 3)
    {
        (*pCmdIO->pCmdApi->print)(cmdIoParam, "Usage: %s <interface> <on/off> \r\n", argv[0]);
        (*pCmdIO->pCmdApi->print)(cmdIoParam, "Ex: %s PIC32INT on \r\n", argv[0]);
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface\r\n");
        return false;
    }

    if (memcmp(argv[2], "on", 2) == 0)
    {   // turning on a service
        svcEnable = true;
    }
    else if (memcmp(argv[2], "off", 2) == 0)
    {   // turning off a service
        svcEnable = false;
    }
    else
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown option\r\n");
        return false;
    }

    switch(svcType)
    {
        case TCPIP_STACK_ADDRESS_SERVICE_DHCPC:
            addFnc = svcEnable?TCPIP_DHCP_Enable:TCPIP_DHCP_Disable;
            break;

        case TCPIP_STACK_ADDRESS_SERVICE_DHCPS:
            addFnc = svcEnable?TCPIP_DHCPS_Enable:TCPIP_DHCPS_Disable;
            break;

        case TCPIP_STACK_ADDRESS_SERVICE_ZCLL:
            addFnc = svcEnable?TCPIP_ZCLL_Enable:TCPIP_ZCLL_Disable;
            break;

        default:
            addFnc = 0;     // unknown service; shouldn't happen
            break;
    }

    if(addFnc)
    {
        msgOK   = svcEnable?"enabled":"disabled";
        msgFail = svcEnable?"enable":"disable";

        addRes = (*addFnc)(netH);
        
        if(addRes)
        {
            (*pCmdIO->pCmdApi->print)(cmdIoParam, "%s %s\r\n", argv[0], msgOK);
        }
        else
        {
            (*pCmdIO->pCmdApi->print)(cmdIoParam, "Failed to %s %s\r\n", msgFail, argv[0]);
        }
    }

    return true;
}
示例#13
0
static int CommandDhcpOptions(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    IPV4_ADDR       reqIpAddr;
    bool            dhcpRes;
    int             opCode = 0;
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc < 3)
    {
        (*pCmdIO->pCmdApi->print)(cmdIoParam, "Usage: %s <interface> <on/off/renew/request> \r\n", argv[0]);
        (*pCmdIO->pCmdApi->print)(cmdIoParam, "Ex: %s PIC32INT on \r\n", argv[0]);
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface\r\n");
        return false;
    }

    if (strcmp(argv[2], "on") == 0)
    {   // turning on a service
        opCode = 1;
    }
    else if (strcmp(argv[2], "off") == 0)
    {   // turning off a service
        opCode = 2;
    }
    else if (strcmp(argv[2], "renew") == 0)
    {   // DHCP renew
        opCode = 3;
    }
    else if (strcmp(argv[2], "request") == 0)
    {   // DHCP request
        opCode = 4;
        if(argc < 4)
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Request needs an IP address\r\n");
            return false;
        }

        if (!TCPIP_Helper_StringToIPAddress(argv[3], &reqIpAddr))
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid IP address string \r\n");
            return false;
        }
    }
    else
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown option\r\n");
        return false;
    }


    switch(opCode)
    {
        case 1:
            dhcpRes = TCPIP_DHCP_Enable(netH);
            break;

        case 2:
            dhcpRes = TCPIP_DHCP_Disable(netH);
            break;

        case 3:
            dhcpRes = TCPIP_DHCP_Renew(netH);
            break;

        case 4:
            dhcpRes = TCPIP_DHCP_Request(netH, reqIpAddr);
            break;

        default:
            dhcpRes = false;
            break;
    }

    (*pCmdIO->pCmdApi->print)(cmdIoParam, "%s %s %s\r\n", argv[0], argv[2], dhcpRes ? "succes" : "fail");

    return true;
}
示例#14
0
static int CommandArp(_CMDIO_DEV_NODE* pCmdIO, int argc, char** argv)
{
    TCPIP_NET_HANDLE netH;
    IPV4_ADDR ipAddr;
    TCPIP_ARP_RESULT  arpRes;
    TCPIP_MAC_ADDR    macAddr;
    char*       message;
    char        addrBuff[20];
    size_t      arpEntries, ix;
    TCPIP_ARP_ENTRY_QUERY arpQuery;

    
    const void* cmdIoParam = pCmdIO->cmdIoParam;

    if (argc < 3)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Usage: arp <interface> <r/q/d/l> <ipAddr> \r\n");
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Ex: arp PIC32INT r 192.168.1.105 \r\n");
        return false;
    }

    netH = TCPIP_STACK_NetHandleGet(argv[1]);
    if (netH == 0)
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Unknown interface\r\n");
        return false;
    }


    if (strcmp(argv[2], "l") == 0)
    {   // list the cache contents
        arpEntries = TCPIP_ARP_CacheEntriesNoGet(netH, ARP_ENTRY_TYPE_TOTAL);
        (*pCmdIO->pCmdApi->print)(cmdIoParam, "arp: %d slots in the cache\r\n", arpEntries);
        for(ix = 0; ix < arpEntries; ix++)
        {
            TCPIP_ARP_EntryQuery(netH, ix, &arpQuery);
            if(arpQuery.entryType == ARP_ENTRY_TYPE_PERMANENT || arpQuery.entryType == ARP_ENTRY_TYPE_COMPLETE)
            {
                TCPIP_Helper_IPAddressToString(&arpQuery.entryIpAdd, addrBuff, sizeof(addrBuff));
                (*pCmdIO->pCmdApi->print)(cmdIoParam, "arp: IPv4 address: %s", addrBuff);
                TCPIP_Helper_MACAddressToString(&arpQuery.entryHwAdd, addrBuff, sizeof(addrBuff));
                (*pCmdIO->pCmdApi->print)(cmdIoParam, ", MAC Address: %s", addrBuff);
                if(arpQuery.entryType == ARP_ENTRY_TYPE_COMPLETE)
                {
                    (*pCmdIO->pCmdApi->msg)(cmdIoParam, ", complete\r\n");
                }
                else
                {
                    (*pCmdIO->pCmdApi->msg)(cmdIoParam, ", permanent\r\n");
                }
            }
            else if(arpQuery.entryType == ARP_ENTRY_TYPE_INCOMPLETE)
            {
                TCPIP_Helper_IPAddressToString(&arpQuery.entryIpAdd, addrBuff, sizeof(addrBuff));
                (*pCmdIO->pCmdApi->print)(cmdIoParam, "arp: IPv4 address: %s, queued\r\n", addrBuff);
            }
        }

        return false;
    }

    if (argc < 4 || !TCPIP_Helper_StringToIPAddress(argv[3], &ipAddr))
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "Invalid IP address string \r\n");
        return false;
    }

    if (strcmp(argv[2], "r") == 0)
    {   // request an address
        arpRes = TCPIP_ARP_EntryGet(netH, &ipAddr, &macAddr, true);
        switch(arpRes)
        {
            case ARP_RES_ENTRY_SOLVED:

                TCPIP_Helper_MACAddressToString(&macAddr, addrBuff, sizeof(addrBuff));
                (*pCmdIO->pCmdApi->print)(cmdIoParam, "arp: resolved - IPv4 address: %s, MAC Address: %s\r\n", argv[3], addrBuff);
                return false;

            case ARP_RES_ENTRY_QUEUED:
                message = "arp: address already queued\r\n";
                break;

            case ARP_RES_ENTRY_NEW:
                message = "arp: address newly queued\r\n";
                break;

            default:    // ARP_RES_CACHE_FULL  
                message = "arp: queue full/error\r\n";
                break;
        }
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, message);
    }
    else if (strcmp(argv[2], "q") == 0)
    {   // query for an address
        arpRes = TCPIP_ARP_EntryGet(netH, &ipAddr, &macAddr, false);
        if(arpRes == ARP_RES_OK)
        {
            TCPIP_Helper_MACAddressToString(&macAddr, addrBuff, sizeof(addrBuff));
            (*pCmdIO->pCmdApi->print)(cmdIoParam, "arp: IPv4 address: %s, MAC Address: %s\r\n", argv[3], addrBuff);
        }
        else
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "arp: no such entry\r\n");
        }
    }
    else if (strcmp(argv[2], "d") == 0)
    {   // delete an address
        arpRes = TCPIP_ARP_EntryRemove(netH, &ipAddr);
        if(arpRes == ARP_RES_OK)
        {
            (*pCmdIO->pCmdApi->print)(cmdIoParam, "arp: removed %s\r\n", argv[3]);
        }
        else
        {
            (*pCmdIO->pCmdApi->msg)(cmdIoParam, "arp: no such entry\r\n");
        }
    }
    else
    {
        (*pCmdIO->pCmdApi->msg)(cmdIoParam, "arp: Unknown option\r\n");
    }


    return false;
}
bool    WF_FirmwareUpdate_Uart_24G(void)
{
    enum SM_FIRMWARE_UPDATE
    {
        SM_FIRMWARE_UPDATE_SOH,
        SM_FIRMWARE_UPDATE_BLOCK,
        SM_FIRMWARE_UPDATE_BLOCK_CMP,
        SM_FIRMWARE_UPDATE_DATA,
        SM_FIRMWARE_UPDATE_CHECKSUM,
        SM_FIRMWARE_UPDATE_FINISH,
    } state;

    uint8_t c;
   // MPFS_HANDLE handle;
    bool lbDone;
    uint8_t blockLen=0;
    bool lResult = FALSE;
    uint8_t BlockNumber=0, preBlockNum=0;
    uint8_t checksum=0;
    
    SYS_TICK lastTick;
    SYS_TICK currentTick;
    state = SM_FIRMWARE_UPDATE_SOH;
    lbDone = FALSE;

    TCPIP_NET_HANDLE netH;


    netH = TCPIP_STACK_NetHandleGet("MRF24W");
    
    if( BUTTON3_IO == 1u) return FALSE;    
    printf("\n\rPress S2 (on Explorer16) to start the update.\n\r");
    while(BUTTON2_IO == 1u);


    // TBD: need a new way of doing this, as DRV_WIFI_Initialize no longer exists
    DRV_WIFI_Initialize((void *)netH);//MACInit();
    //printf("2\n");
    SYS_TICK_MsDelay(100);
    //printf("3\n");
    AutoUpdate_Initialize();
    printf("I am ready, Please transfer firmware patch by XMODEM.\r\n"); 
    printf("If you press S3(On Explorwe16), I will stop update, and restore back to previous firmware.\r\n"); 
    lastTick = SYS_TICK_Get();
    do
    {
        currentTick = SYS_TICK_Get();
        if ( currentTick - lastTick >= (SYS_TICK_TicksPerSecondGet()*2) )
        {
            lastTick = SYS_TICK_Get();
            //todo jw  //while(BusyUART());
            _SYS_CONSOLE_PUTC(XMODEM_NAK); //WriteUART(XMODEM_NAK);
        }

    } while(!_SYS_CONSOLE_DATA_RDY()); //(!DataRdyUART());

    
    while(!lbDone)
    {
        if (BUTTON3_IO == 0u)   // If you want to cancel AutoUpdate, please press S3
        {
            printf("You press S3 button, revert begin...\r\n");
            AutoUpdate_Restore();
            printf("revert done\r\n");
            return FALSE;
        }
        if(_SYS_CONSOLE_DATA_RDY()) //(DataRdyUART())
        {
            c = _SYS_CONSOLE_GETC();//ReadUART();
            lastTick = SYS_TICK_Get();
        }
        else
        {
            // put some timeout to make sure  that we do not wait forever.
             currentTick = SYS_TICK_Get();
            if ( currentTick - lastTick >= (SYS_TICK_TicksPerSecondGet()*10) )
            {
                //if time out, copy old patch image from bank2 to bank1
                printf("timeout, revert begin...\r\n");
                AutoUpdate_Restore();
                printf("revert done\r\n");
                return FALSE;
            }
            continue;
        }
        //dbgPrintf("(%02x) ",c); 
        switch(state)
        {
        case SM_FIRMWARE_UPDATE_SOH:
            if(c == XMODEM_SOH)
            {
                state = SM_FIRMWARE_UPDATE_BLOCK;
                dbgPrintf("\r\n! ");
                checksum = c;
                lResult = TRUE;
            }
            else if ( c == XMODEM_EOT )
            {
                state = SM_FIRMWARE_UPDATE_FINISH;
                
                // todo jw://while(BusyUART());
                _SYS_CONSOLE_PUTC(XMODEM_ACK); //WriteUART(XMODEM_ACK);
                lbDone = TRUE;
            }  
            else
            {
                dbgPrintf("\n!error\n");
                while(1);
            }
            break;
        case SM_FIRMWARE_UPDATE_BLOCK:
            BlockNumber = c;
            dbgPrintf("BLK=%d ",BlockNumber);         
            checksum += c;
            state = SM_FIRMWARE_UPDATE_BLOCK_CMP;
            break;

        case SM_FIRMWARE_UPDATE_BLOCK_CMP:
            dbgPrintf("%d ",c);
            dbgPrintf("@:");
            //Judge: Is it correct ?
            if(c != (BlockNumber ^ 0xFF))
            {
                lResult = FALSE;
                dbgPrintf("\nBLOCK_CMP err: %x,%x\n", c, BlockNumber ^ 0xFF );
            }
            else 
            {
                if((uint8_t)(preBlockNum+1) != BlockNumber)
                {
                    lResult = FALSE;
                    dbgPrintf("\nBLOCK  err %x %x\n",preBlockNum+1,BlockNumber);
                }
            }
            checksum += c;
            blockLen = 0;
            state = SM_FIRMWARE_UPDATE_DATA;
            break;
        case SM_FIRMWARE_UPDATE_DATA:
            // Buffer block data until it is over.
            tempData[blockLen++] = c;
            if ( blockLen == XMODEM_BLOCK_LEN )
            {
                state = SM_FIRMWARE_UPDATE_CHECKSUM;
            }
            checksum += c;
            
            break;
        case SM_FIRMWARE_UPDATE_CHECKSUM:
            dbgPrintf("Checksum=%x=%x ",checksum,c);
            if(checksum != c)
            {
                lResult = FALSE;
                dbgPrintf("\nchecksum  err\n");
            }
            XMODEM_SendToModule(tempData);
            // todo jw://while(BusyUART());
            if(lResult == TRUE)
            {
                _SYS_CONSOLE_PUTC(XMODEM_ACK);//WriteUART(XMODEM_ACK);
                preBlockNum++;
            }
            else
            {
                _SYS_CONSOLE_PUTC(XMODEM_NAK);//WriteUART(XMODEM_NAK);
            }
            state = SM_FIRMWARE_UPDATE_SOH;
            break;

        default:
            dbgPrintf("\n!error\n");
            while(1);
            break;
        }

    }
    
    AutoUpdate_Completed();

    return TRUE;
}
示例#16
0
/*****************************************************************************
 * FUNCTION: Demo_Wifi_Connect
 *
 * RETURNS:  TCPIP_MAC_RES
 *
 * PARAMS:   None
 *
 *  NOTES:   Connects to an 802.11 network.
 *****************************************************************************/
 TCPIP_MAC_RES Demo_Wifi_Connect(void)
{
    typedef enum {
        demo_Wifi_Connect_SM_1=0,
        demo_Wifi_Connect_SM_2,
        demo_Wifi_Connect_SM_3,
        demo_Wifi_Connect_SM_done
    }enum_demoWifiConnect_SM;
    static enum_demoWifiConnect_SM demoWifiConnect_SM = demo_Wifi_Connect_SM_1;
    TCPIP_MAC_RES RetCode = TCPIP_MAC_RES_PENDING;
	

    switch(demoWifiConnect_SM)
    {
        case demo_Wifi_Connect_SM_1:
        {
            uint8_t channelList[] = WF_DEFAULT_CHANNEL_LIST;
            DRV_WIFI_SCAN_CONTEXT scanContext;

#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            uint8_t channelList_postscan[] = WF_DEFAULT_CHANNEL_LIST_POSTSCAN;
#endif

            DRV_WIFI_SsidSet(p_wifi_ConfigData->netSSID, p_wifi_ConfigData->SsidLength);

#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_ADHOC) || (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            DRV_WIFI_NetworkTypeSet(p_wifi_ConfigData->networkType);
#else
            DRV_WIFI_NetworkTypeSet(WF_DEFAULT_NETWORK_TYPE);
#endif

#ifndef WF_DEFAULT_SCAN_TYPE
            scanContext.scanType = DRV_WIFI_ACTIVE_SCAN;    
#else
            scanContext.scanType = WF_DEFAULT_SCAN_TYPE;
#endif

            scanContext.minChannelTime = DRV_WIFI_DEFAULT_SCAN_MIN_CHANNEL_TIME;
            scanContext.maxChannelTime = DRV_WIFI_DEFAULT_SCAN_MAX_CHANNEL_TIME;
            scanContext.probeDelay     = DRV_WIFI_DEFAULT_SCAN_PROBE_DELAY;
            scanContext.scanCount      = DRV_WIFI_DEFAULT_SCAN_COUNT;
            DRV_WIFI_ScanContextSet(&scanContext);

#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            if (((CFGCXT.type != DRV_WIFI_NETWORK_TYPE_SOFT_AP) && (CFGCXT.prevWLAN == DRV_WIFI_NETWORK_TYPE_SOFT_AP)) ||
                (p_wifi_ConfigData->networkType != DRV_WIFI_NETWORK_TYPE_SOFT_AP))
            {
                DRV_WIFI_ChannelListSet(channelList_postscan, sizeof(channelList_postscan));
            }
            else
            {
                DRV_WIFI_ChannelListSet(channelList, sizeof(channelList));
            }
#else // not network type not DRV_WIFI_NETWORK_TYPE_SOFT_AP
            DRV_WIFI_ChannelListSet(channelList, sizeof(channelList));
#endif // (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)

            // The Retry Count parameter tells the WiFi Connection manager how many attempts to make when trying
            // to connect to an existing network.  In the Infrastructure case, the default is to retry forever so that
            // if the AP is turned off or out of range, the radio will continue to attempt a connection until the
            // AP is eventually back on or in range.  In the Adhoc case, the default is to retry 3 times since the
            // purpose of attempting to establish a network in the Adhoc case is only to verify that one does not
            // initially exist.  If the retry count was set to DRV_WIFI_RETRY_FOREVER in the AdHoc mode, an AdHoc network
            // would never be established.
#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_ADHOC) || (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            if(p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_INFRASTRUCTURE)
            {
                DRV_WIFI_ReconnectModeSet(DRV_WIFI_RETRY_FOREVER,   // retry forever to connect to WiFi network
                                    DRV_WIFI_ATTEMPT_TO_RECONNECT,  // reconnect on deauth from AP
                                    40,                             // beacon timeout is 40 beacon periods
                                    DRV_WIFI_ATTEMPT_TO_RECONNECT); // reconnect on beacon timeout
            }
            else if((p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_ADHOC) || (p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_SOFT_AP))
            {
                DRV_WIFI_ReconnectModeSet(WF_DEFAULT_LIST_RETRY_COUNT,    // retry N times to start or join AdHoc network
                                    DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT, // do not attempt to reconnect on deauth from station
                                    40,                                   // beacon timeout is 40 beacon periods
                                    DRV_WIFI_ATTEMPT_TO_RECONNECT);             // reconnect on beacon timeout
            }
            else
            {
                SYS_CONSOLE_MESSAGE("Please compile with correct XX_RETRY_COUNT\r\n");
                while(1);
            }
#else // network type not DRV_WIFI_NETWORK_TYPE_ADHOC or DRV_WIFI_NETWORK_TYPE_SOFT_AP
            DRV_WIFI_ReconnectModeSet(WF_DEFAULT_LIST_RETRY_COUNT, // retry N times to start or join AdHoc network
                                DRV_WIFI_ATTEMPT_TO_RECONNECT,     // reconnect on deauth from AP
                                40,                                // beacon timeout is 40 beacon periods
                                DRV_WIFI_ATTEMPT_TO_RECONNECT);    // reconnect on beacon timeout

#endif // (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_ADHOC) || (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)


            // Set Tx Mode
            DRV_WIFI_TxModeSet(WF_DEFAULT_TX_MODE); // WF_TXMODE_G_RATES, WF_TXMODE_B_RATES, WF_TXMODE_LEGACY_RATES

            // Error check items specific to WPS Push Button mode
#if (WF_DEFAULT_WIFI_SECURITY_MODE==DRV_WIFI_SECURITY_WPS_PUSH_BUTTON)
                //    SYS_ASSERT(strlen(p_wifi_ConfigData->netSSID) == 0, "");  // SSID must be empty when using WPS
                // To Do: fix this to work with different Domain and also empty channelList
                // SYS_ASSERT(sizeof(channelList)==11, "");      // must scan all channels for WPS
#endif
        
        }
        demoWifiConnect_SM++;
        break;

        case demo_Wifi_Connect_SM_2:
        {
            TCPIP_MAC_RES tmp = TCPIP_MAC_RES_OK;
            if (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_OPEN)
            {
                DRV_WIFI_SecurityOpenSet();
            }
            else if ((p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WEP_40) || (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WEP_104))
            {
                SetWepSecurity();
            }
            else if ((p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY)         ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_WITH_KEY)              ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE) ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_WITH_PASS_PHRASE)      ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA2_WITH_KEY)             ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA2_WITH_PASS_PHRASE))
            {
                tmp = SetWpaSecurity();
            }
            else if ((p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPS_PIN) ||
                    (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPS_PUSH_BUTTON))
            {
                SetWpsSecurity();
            }
            else if (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_EAP)
            {
                SetEapSecurity();
            }

            if(TCPIP_MAC_RES_OK == tmp ) demoWifiConnect_SM++;
        }
            
            break;
        
        case demo_Wifi_Connect_SM_3:
        {
#if WF_DEFAULT_PS_POLL == DRV_WIFI_ENABLED
            {
                DRV_WIFI_PS_POLL_CONTEXT psPollContext;
                psPollContext.dtimInterval   = DRV_WIFI_DEFAULT_PS_DTIM_INTERVAL;
                psPollContext.listenInterval = DRV_WIFI_DEFAULT_PS_LISTEN_INTERVAL;
                psPollContext.useDtim        = true;
                DRV_WIFI_PsPollEnable(&psPollContext);
            }
 #else    /* WF_DEFAULT_PS_POLL == DRV_WIFI_DISABLED */
            DRV_WIFI_PsPollDisable();
#endif    /* WF_DEFAULT_PS_POLL == DRV_WIFI_ENABLED */

#if defined(TCPIP_STACK_USE_GRATUITOUS_ARP)
            DRV_WIFI_GratuitousArpStart(5);  // output a gratuitous arp every 5 seconds (after connection)
#endif

 #if defined(SYS_CONSOLE_ENABLE)
             OutputDemoHeader();
#endif

        // override reconnect mode if connection manager disabled
#if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE)
            DRV_WIFI_ReconnectModeSet(0,                               // report-only when connection lost (no reconnect)
                                DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT,  // report-only when deauth received (no reconnect)
                                40,                                    // set beacon timeout to 40 beacon periods
                                DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT); // report only when beacon timeout occurs
#endif

            WF_EnableDebugPrint(ENABLE_WPS_PRINTS);
            SYS_CONSOLE_MESSAGE("\r\nStart WiFi Connect . . .\r\n");

#if defined(TCPIP_STACK_USE_DHCP_CLIENT)
            if( DhcpHandle_Mrf24w == NULL)
            {    DhcpHandle_Mrf24w =  TCPIP_DHCP_HandlerRegister(TCPIP_STACK_NetHandleGet("MRF24W"), DhcpEventHandler, NULL);
            }
#endif  // defined(TCPIP_STACK_USE_DHCP_CLIENT)

            // start the WiFi connection process
            DRV_WIFI_Connect();

            WifiAsyncSetEventPending(ASYNC_DHCP_CONFIG_PENDING);  // ken test
        }
            demoWifiConnect_SM++;
            RetCode = TCPIP_MAC_RES_OK;
            //break;   //not break, will continue to demo_Wifi_Connect_SM_done
            
        case demo_Wifi_Connect_SM_done:
            demoWifiConnect_SM = demo_Wifi_Connect_SM_1;
            break;
    }
 
	return RetCode;
}