Example #1
0
void* DefaultWifiThread(void *pThreadArg)
{
    int iExit = 0;
	int iRecv = 0;
	OTDRMSGQUEUE *pWifiMsg = NULL;
	pWifiMsg = GetWifiMsgQueue();
	printf("enter thd\n");
	if(pWifiMsg == NULL)
	{
		printf("error, pWifiMsg is NULL\n");
		return NULL;
	}
	else
	{
		ClearOTDRMsgQueue(pWifiMsg);
	}
	
    while (!iExit)
    {		
        iExit = GetExitFlag();
		
        if (iExit == 1)
        {
            break;
        }

		iRecv = 0;
		ReadWifiMsgQueue(&iRecv);
		if(iRecv)
		{
			printf("wifiTHD Recv = %d\n", iRecv);
			switch(iRecv)
			{
				case ENUM_OPEN:
					WifiOpen();
					break;
				case ENUM_SCAN:
					WifiScan();
					break;
				case ENUM_SCAN_R:
					WifiScan_r();
					break;
				case ENUM_CONNECT://victor
					WifiConnect();
					break;
				default:
					break;
			}
		}
		else
		{
			MsecSleep(30);
		}
		
    }	
	printf("exit thd\n");
	return NULL;
}
Example #2
0
bool ProcessUserInput(void)
{
    char	tmp[100];

		if(DbgScan("%s", tmp)==1)
		switch(tmp[0]) {
		case 'q':
        return false;
    
		case '0':
        GetStatus(seqNo++);
        break;

    case '1':
        WifiScan(seqNo++);
        break;

    case '2':
        WifiDisconn(seqNo++);
        WifiJoin(seqNo++);
        SnicInit(seqNo++);
        SnicIPConfig(seqNo++);
        break;

    case '3':
        SnicInit(seqNo++);
        SnicGetDhcp(seqNo++);
        break;

    case '4':
        mysock = -1;
        tcpCreateSocket(0, 0xFF, 0xFF, seqNo++, SNIC_TCP_CREATE_SOCKET_REQ);
        if (mysock != -1) {
            if (getTCPinfo() == CMD_ERROR) {
                DbgPrint("Invalid Server\r\n");
                break;
            }
            // This connection can receive data upto 0x0400=1K bytes at a time.
            tcpConnectToServer(mysock, destIP, (unsigned short)destPort, 0x0400, 0x5, seqNo++);
        }
        break;

    case '5':
        if (setTCPinfo() == CMD_ERROR) {
            DbgPrint("Invalid Server to create\r\n");
            break;
        }
        mysock = -1;
        tcpCreateSocket(1, srcIP, (unsigned short)srcPort, seqNo++, SNIC_TCP_CREATE_SOCKET_REQ);
        if (mysock != -1) {
            // This connection can receive data upto TEST_BUFFERSIZE at a time.
            tcpCreateConnection(mysock, TEST_BUFFERSIZE, 0x5, seqNo++);
        }
        break;

    case '6': {
        char tempstr[2] = {0};
        int8u datamode;
        char sockstr[8];
        int32u sock;
        char teststr[128];
        int len;

        DbgPrint("Enter socket number to send from: \r\n");
        DbgScan("%s", sockstr);
        sock = strtol(sockstr, NULL, 0);

        DbgPrint("Content Option? (0: Default  1: User specific) \r\n");
        DbgScan("%s", tempstr);
        datamode = atoi(tempstr);

        if (datamode) {
            DbgPrint("Enter payload to send (up to 128 bytes): \r\n");
            DbgScan("%s", teststr);
            len = (int)strlen(teststr);
            sendFromSock(sock, (int8u*)teststr, len, 2, seqNo++);
        } else {
            sendFromSock(sock, TxBuf, TEST_BUFFERSIZE, 2, seqNo++);
            pktcnt = 0;
        }
        break;
    }

    case '7':
        SnicCleanup(seqNo++);
        WifiDisconn(seqNo++);
        break;

    case '8':
        ApOnOff(seqNo++);
        break;

    case '9': {//udp send
        int i;
        udpCreateSocket(0, 0, 0, seqNo++);
        if (mysock != -1) {
            if (getUDPinfo() == CMD_ERROR) {
                DbgPrint("Invalid Server\r\n");
                break;
            }
            DbgPrint("Send %d\r\n", UDP_NUM_PKT);
            for (i=0; i<UDP_NUM_PKT; i++) {
                int si = i % TEST_BUFFERSIZE + 1;
                SendSNIC(TxBuf, si);
                DbgPrint("%d %d\r\n", i, si);
            }

            closeSocket(mysock,seqNo++);
        }
        break;
    }

    case 'a': {//udp recv
        int16u port = 43211;
        int32u ip = 0xAC1F0001; // 172.31.0.1
        udpCreateSocket(1, ip, port, seqNo++);
        udpStartRecv(mysock, 2048, seqNo++);
        break;
    }

    case 'b':
        SnicCleanup(seqNo++);
        WifiOff(seqNo++);
        break;
    case 'c':
        WifiOn(seqNo++);
        break;

    case 'd':
        DbgPrint("Enter server name:  %s\r\n", domain);
        DbgScan("%s", tmp);
        DbgPrint("\r\n");
        if (strlen(tmp)) 
            strcpy(domain, tmp);
        sendHttpReqTest(domain, 0);
        break;

    case'e':
        DbgPrint("Enter server name: ([CR] to accept %s)\r\n", domain);
        DbgScan("%s", tmp);
        DbgPrint("\r\n");
        if (strlen(tmp)) 
        strcpy(domain, tmp);
        sendHttpPostDemo(domain);
        break;

    case 'f':
        DbgPrint("Make sure STA is connected to SN8200 soft AP.\r\n");
        strcpy(domain, "sn8200.com");
        DbgPrint("Enter server name: ([CR] to accept %s)\r\n", domain);
        DbgScan("%s", tmp);
        DbgPrint("\r\n");
        if (strlen(tmp)) 
            strcpy(domain, tmp);
        sendHttpJsonPostDemo(domain);
        break;
#if 1

    case 'g':
        strcpy(domain, "192.168.10.100");
        DbgPrint("Enter server name (or the peer testclient IP, peer testclient should start TCP server on port 80): ([CR] to accept %s)\r\n", domain);
        DbgScan("%s", tmp);
        DbgPrint("\r\n");
        if (strlen(tmp)) 
            strcpy(domain, tmp);
        sendHttpChunkReqTest(domain);
        break;
#endif

    case 'h':
        DbgPrint("Enter server name: ([CR] to accept %s)\r\n", domain);
        DbgScan("%s", tmp);
        DbgPrint("\r\n");
        if (strlen(tmp)) 
            strcpy(domain, tmp);
        sendHttpReqTest(domain, 1);
        break;

    case 'i':
        timeout1 = 5;
        mysock = -1;
        tcpCreateSocket(0, 0xFF, 0xFF, seqNo++, SNIC_TCP_CREATE_SIMPLE_TLS_SOCKET_REQ);  // use less memory in SN8200
        mdelay(500);
        if (mysock != -1) {
            strcpy(Portstr, "443");
 
					if (getTCPinfo() == CMD_ERROR) {
                DbgPrint("Invalid Server\r\n");
                break;
            }
					
            tcpConnectToServer(mysock, destIP, (unsigned short)destPort,0x0000,timeout1,seqNo++);
            while ((sockConnected == -1) && timeout1) {
                mdelay(500);
                timeout1--;
                if (sockClosed == mysock) {
                    sockClosed = -1;
                    break;
                }
            }

            if (sockConnected == mysock) {
                sendFromSock(mysock, (int8u*)GET_REQUEST, sizeof(GET_REQUEST)-1, 2, seqNo++);
                sockConnected = -1;
            }
            else DbgPrint("Connect failed.\r\n");
        }
        break;

    case 'j': //ssl server
        strcpy(Portstr, "443");
        if (setTCPinfo() == CMD_ERROR) {
            DbgPrint("Invalid Server to create\r\n");
            break;
        }
        mysock = -1;
        tcpCreateSocket(1, srcIP, (unsigned short)srcPort, seqNo++, SNIC_TCP_CREATE_ADV_TLS_SOCKET_REQ);
        if (mysock != -1) {
            // This connection can receive data upto TEST_BUFFERSIZE at a time. 
            tcpCreateConnection(mysock, TEST_BUFFERSIZE, 0x5, seqNo++);
        }
        break;

    case 'm':
        ShowMenu();
        break;

    default:
        break;
    }
		return true;

}