/*****************************************************************************
  Function:
	void UDPPerformanceTask(void)

  Summary:
	Tests the transmit performance of the UDP module.

  Description:
	This function tests the transmit performance of the UDP module.  At boot,
	this module will transmit 1024 large UDP broadcast packets of 1024 bytes
	each.  Using a packet sniffer, one can determine how long this process 
	takes and calculate the transmit rate of the stack.  This function tests 
	true UDP performance in that it will open a socket, transmit one packet, 
	and close the socket for each loop.  After this initial transmission, the
	module can be re-enabled by holding button 3.
	
	This function is particularly useful after development to determine the
	impact of your application code on the stack's performance.  A before and
	after comparison will indicate if your application is unacceptably
	blocking the processor or taking too long to execute.

  Precondition:
	UDP is initialized.

  Parameters:
	None

  Returns:
	None
  ***************************************************************************/
void UDPPerformanceTask(void)
{
	UDP_SOCKET	MySocket;
	NODE_INFO	Remote;
	WORD		wTemp;
	static DWORD dwCounter = 1;

	if((BUTTON3_IO) && (dwCounter > 1024))
		return;

	// Suppress transmissions if we don't have an Ethernet link so our counter starts correctly at 0x00000001
	if(!MACIsLinked())
		return;
	
	// Set the socket's destination to be a broadcast over our IP 
	// subnet
	// Set the MAC destination to be a broadcast
	memset(&Remote, 0xFF, sizeof(Remote));
	
	// Open a UDP socket for outbound transmission
	MySocket = UDPOpen(0, &Remote, PERFORMANCE_PORT);
	
	// Abort operation if no UDP sockets are available
	// If this ever happens, incrementing MAX_UDP_SOCKETS in 
	// StackTsk.h may help (at the expense of more global memory 
	// resources).
	if(MySocket == INVALID_UDP_SOCKET)
		return;
	
	// Make certain the socket can be written to
	if(!UDPIsPutReady(MySocket))
	{
		UDPClose(MySocket);
		return;
	}
	
	// Put counter value into first 4 bytes of the packet
	UDPPutArray((BYTE*)&dwCounter, sizeof(dwCounter));
	dwCounter++;
	
	wTemp = UDPPutROMArray((ROM BYTE*)
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 256 bytes.\r\n"
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 256 bytes.\r\n"
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 256 bytes.\r\n"
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 252b. \r\n", 1020);

	// Send the packet
	UDPFlush();
	
	// Close the socket so it can be used by other modules
	UDPClose(MySocket);
}
Example #2
0
/*****************************************************************************
  Function:
	void DHCPInit(BYTE vInterface)

  Summary:
	Resets the DHCP client module for the specified interface.

  Description:
	Resets the DHCP client module, giving up any current lease, knowledge of 
	DHCP servers, etc. for the specified interface.

  Precondition:
	None

  Parameters:
	vInterface - Interface number to initialize DHCP client state variables 
		for.   If you only have one interface, specify 0x00.

  Returns:
	None

  Remarks:
	This function may be called multiple times throughout the life of the 
	application, if desired.  
***************************************************************************/
void DHCPInit(BYTE vInterface)
{
	BYTE i;
	
    // initialize global module statics
    // DHCPClientInitializedOnce = FALSE;

	// Upon the first call after POR, we must reset all handles to invalid so 
	// that we don't inadvertently close someone else's handle.
	if(!DHCPClientInitializedOnce)
	{
		DHCPClientInitializedOnce = TRUE;
		for(i = 0; i < NETWORK_INTERFACES; i++)
		{
			LoadState(i);
			DHCPClient.hDHCPSocket = INVALID_UDP_SOCKET;
		}		
	}
	
	
	LoadState(vInterface);
	
	if(DHCPClient.hDHCPSocket != INVALID_UDP_SOCKET)
	{
		UDPClose(DHCPClient.hDHCPSocket);
		DHCPClient.hDHCPSocket = INVALID_UDP_SOCKET;
	}

	// Reset state machine and flags to default values
	DHCPClient.smState = SM_DHCP_GET_SOCKET;
	DHCPClient.flags.val = 0;
	DHCPClient.flags.bits.bUseUnicastMode = TRUE;	// This flag toggles before use, so this statement actually means to start out using broadcast mode.
	DHCPClient.flags.bits.bEvent = TRUE;
}
Example #3
0
void loopback_udp(uint8 ch, uint16 port)
{
    int ret;
    uint32 destip = 0;
    uint16 destport;

    ret = UDPRecv(ch, data_buf, TX_RX_MAX_BUF_SIZE, (uint8*)&destip, &destport);

    if(ret > 0) {				// Received
        ret = UDPSend(ch, data_buf, ret, (uint8*)&destip ,destport);

        if(ret == ERROR_TIME_OUT) {
            ERR("Timeout");
            UDPClose(ch);
            DBG("UDP Socket Close");
        }

    } else if(ret == ERROR_NOT_UDP_SOCKET) {	// Not UDP Socket, It's TCP Socket
        DBG("TCP Socket Close");
        TCPClose(ch);
    } else if(ret == ERROR_CLOSED) {		// Socket Closed
        LOGA("UDP Loop-Back Started - ch(%d)",(uint16)ch);
        UDPOpen(ch, port);
    }
}
Example #4
0
//	Callback function
int cUDPGenericClose()
{
	UDPClose(udpSocket[callbackUdpSocket-1]);
	udpSocket[callbackUdpSocket-1] = INVALID_UDP_SOCKET;
	numUdpSocket--;
	return 0;
}
Example #5
0
int8_t vscp_udpinit( void )
{
    NODE_INFO remote_node;

    remote_node.IPAddr.v[ 0 ] = 0xff;	// Broadcast
    remote_node.IPAddr.v[ 1 ] = 0xff;
    remote_node.IPAddr.v[ 2 ] = 0xff;
    remote_node.IPAddr.v[ 3 ] = 0xff;
    remote_node.MACAddr.v[ 0 ] = 0xff;
    remote_node.MACAddr.v[ 1 ] = 0xff;
    remote_node.MACAddr.v[ 2 ] = 0xff;
    remote_node.MACAddr.v[ 3 ] = 0xff;
    remote_node.MACAddr.v[ 4 ] = 0xff;
    remote_node.MACAddr.v[ 5 ] = 0xff;

    // setup receive socket
    vscp_udp_receivesocket = UDPOpen( VSCP_LEVEL2_UDP_PORT, &remote_node, NULL );
    if ( INVALID_SOCKET == vscp_udp_receivesocket ) return FALSE;

    // Setup transmit socket
    vscp_udp_transmitsocket = UDPOpen( 30200, &remote_node, VSCP_LEVEL2_UDP_PORT );
    if ( INVALID_SOCKET == vscp_udp_transmitsocket ) {
        UDPClose( vscp_udp_receivesocket );
        return FALSE;
    }
}
/*****************************************************************************
  Function:
	int closesocket( SOCKET s )
	
  Summary:
	The closesocket function closes an existing socket.

  Description:
	The closesocket function closes an existing socket.  
    This function releases the socket descriptor s.  
    Further references to s fails with SOCKET_ERROR code.  
    Any data buffered at the socket is discarded.  If the 
    socket s is no longer needed, closesocket() must be 
    called in order to release all resources associated with s.

  Precondition:
	None.

  Parameters:
	s - Socket descriptor returned from a previous call to socket

  Returns:
	If closesocket is successful, a value of 0 is returned. 
    A return value of SOCKET_ERROR (-1) indicates an error.

  Remarks:
	None.
  ***************************************************************************/
int closesocket( SOCKET s )
{
    struct BSDSocket *socket;
    
    if( s >= BSD_SOCKET_COUNT )
        return SOCKET_ERROR;

    socket = &BSDSocketArray[s];

    if( socket->SocketType == SOCK_STREAM)
    {
        TCPDisconnect(socket->SocketID);
    }
    else //udp sockets
    {
        UDPClose(socket->SocketID);
    }

    if(socket->isServer == TRUE)
    {
        socket->bsdState = SKT_LISTEN;
    }
    else
    {
        socket->SocketType = SOCK_DGRAM;
        socket->bsdState   = SKT_CLOSED;
        socket->SocketID   = INVALID_SOCKET;
    }
    return 0; //success
}
Example #7
0
/*********************************************************************
 * Function:        void NBNSDeInit(const TCPIP_STACK_MODULE_CTRL* const stackCtrl)
 *
 * PreCondition:    None
 *
 * Input:           stackCtrl - Interface and stack module data.
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        DeInitializes state machine
 *
 * Note:            None
 ********************************************************************/
void NBNSDeInit(const TCPIP_STACK_MODULE_CTRL* const stackCtrl)
{
    // if(stackCtrl->stackAction == TCPIP_STACK_ACTION_DEINIT) // stack shut down
    // if(stackCtrl->stackAction == TCPIP_STACK_ACTION_IF_DOWN) // interface down

    // one way or another this interface is going down

    if(stackCtrl->stackAction == TCPIP_STACK_ACTION_DEINIT)
    {   // whole stack is going down
        if(nbnsInitCount > 0)
        {   // we're up and running
            if(--nbnsInitCount == 0)
            {   // all closed
                // release resources
                if(nbnsDcpt.uSkt != INVALID_UDP_SOCKET)
                {
                   UDPClose(nbnsDcpt.uSkt);
                   nbnsDcpt.uSkt = INVALID_UDP_SOCKET;
                }
                nbnsDcpt.sm = NBNS_HOME;
            }
        }
    }

}
Example #8
0
/****************************************************************************
  Function:
   UDP_SOCKET ChipKITUDPBegin(UDP_PORT localPort)

  Description:
    Implementes the Arduino UDP begin function.
 
  Parameters:
    localPort   - The port to start listening on.

  Returns:
    The socket that was opened, or INVALID_UDP_SOCKET if it couldn't get one

  Remarks:
    Creates a socket and starts listening on the specifed port.
    Note that Arduino never specifies an IP address with this, that
    is done on the individual send packetes.
    If there is not enough space for the socket cache, this API will fail
   
  ***************************************************************************/
UDP_SOCKET ChipKITUDPBegin(UDP_PORT localPort)
{
	UDP_SOCKET hUDP = INVALID_UDP_SOCKET;
    hUDP = UDPOpen(localPort, NULL, 0);

	if(hUDP < MAX_UDP_SOCKETS && rgUDPSocketBuffers[hUDP] == NULL)
	{
		rgUDPSocketBuffers[hUDP] = (UDPSB *) malloc(sizeof(UDPSB));	
		if(rgUDPSocketBuffers[hUDP] != NULL)
		{
			memset(rgUDPSocketBuffers[hUDP], 0, sizeof(sizeof(UDPSB)));
		}

		// no space for the buffer, no socket!
		else
		{
			UDPClose(hUDP);
			hUDP = INVALID_UDP_SOCKET;
		}
	}

    ChipKITPeriodicTasks();

    return(hUDP);
}
Example #9
0
/*****************************************************************************
  Function:
	int closesocket( SOCKET s )

  Summary:
	The closesocket function closes an existing socket.

  Description:
	The closesocket function closes an existing socket.
	This function releases the socket descriptor s.
	Any data buffered at the socket is discarded.  If the
	socket s is no longer needed, closesocket() must be
	called in order to release all resources associated with s.

  Precondition:
	None.

  Parameters:
	s - Socket descriptor returned from a previous call to socket

  Returns:
	If closesocket is successful, a value of 0 is returned.
	A return value of SOCKET_ERROR (-1) indicates an error.

  Remarks:
	None.
  ***************************************************************************/
int closesocket( SOCKET s )
{
    struct BSDSocket *socket;

    if( s >= BSD_SOCKET_COUNT )
        return SOCKET_ERROR;

    socket = &BSDSocketArray[s];

    if(socket->bsdState == SKT_CLOSED)
        return 0;	// Nothing to do, so return success

    if( socket->SocketType == SOCK_STREAM)
    {
        if(socket->bsdState >= SKT_LISTEN)
        {
            HandlePossibleTCPDisconnection(s);

            if(socket->bsdState == SKT_LISTEN)
                return 0;
        }
    }
    else //udp sockets
    {
        if(socket->SocketID != INVALID_UDP_SOCKET)
            UDPClose(socket->SocketID);
    }

    socket->bsdState = SKT_CLOSED;
    return 0; //success
}
Example #10
0
/*static __inline__*/static  void /*__attribute__((always_inline))*/ _DNSReleaseSocket(void)
{
	if(DNSSocket != INVALID_UDP_SOCKET)
	{
		UDPClose(DNSSocket);
		DNSSocket = INVALID_UDP_SOCKET;
	}
}
Example #11
0
/*********************************************************************
 * Function:        void UDPInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Initializes internal variables.
 *
 * Note:
 ********************************************************************/
void        UDPInit(void)
{
    UDP_SOCKET s;

    for ( s = 0; s < MAX_UDP_SOCKETS; s++ )
    {
      UDPClose(s);
    }
}
Example #12
0
/*****************************************************************************
 Function:
 void DHCPDisable(BYTE vInterface)

 Summary:
 Disables the DHCP Client for the specified interface.

 Description:
 Disables the DHCP client for the specified interface by sending the state
 machine to "SM_DHCP_DISABLED".  If the interface was previously configured
 by DHCP, the configuration will continue to be used but the module will no
 longer preform any renewals.

 Precondition:
 None

 Parameters:
 vInterface - Interface number to disable the DHCP client on.   If you only
 have one interface, specify 0x00.

 Returns:
 None

 Remarks:
 Since the interface continues using its old configuration, it is possible
 that the lease may expire and the DHCP server provide the IP to another
 client.  The application should replace the current IP address and other
 configuration with static information following a call to this function.
 ***************************************************************************/
void DHCPDisable(BYTE vInterface) {
	LoadState(vInterface);

	if (DHCPClient.hDHCPSocket != INVALID_UDP_SOCKET) {
		UDPClose(DHCPClient.hDHCPSocket);
		DHCPClient.hDHCPSocket = INVALID_UDP_SOCKET;
	}

	DHCPClient.smState = SM_DHCP_DISABLED;
}
Example #13
0
/*****************************************************************************
  Function:
	void UDPInit(void)

  Summary:
	Initializes the UDP module.

  Description:
	Initializes the UDP module.  This function initializes all the UDP 
	sockets to the closed state.

  Precondition:
	None

  Parameters:
	None

  Returns:
  	None
  	
  Remarks:
	This function is called only one during lifetime of the application.
  ***************************************************************************/
void UDPInit(void)
{
    UDP_SOCKET s;

    for ( s = 0; s < MAX_UDP_SOCKETS; s++ )
    {
		UDPClose(s);
    }
	Flags.bWasDiscarded = 1;
}
Example #14
0
void DHCPServer_Disable(void)
{
	smDHCPServer = DHCPS_DISABLE;

	if(MySocket != INVALID_UDP_SOCKET)
	{
		UDPClose(MySocket);
		MySocket = INVALID_UDP_SOCKET;
	}
}
Example #15
0
void UDPCloseAllSockets(void)
{
    UDPSOCKET * pSocket = NULL;

    // go until you empty the list.
    while((pSocket = FFNext(&g_ffptListeningUDPSockets, NULL)) != NULL)
    {
        UDPClose(pSocket);
    }
}
Example #16
0
/****************************************************************************************************
  Function:
            void AnnounceIP(void)
    
  Summary:
    Transmits an Announce packet.
  Conditions:
    Stack is initialized()
  Return:
    None
  Side Effects:
    None
  Description:
    AnnounceIP opens a UDP socket and transmits a broadcast packet to port
    \30303. If a computer is on the same subnet and a utility is looking
    for packets on the UDP port, it will receive the broadcast. For this
    application, it is used to announce the change of this board's IP
    address. The messages can be viewed with the TCP/IP Discoverer
    software tool.
  Remarks:
    A UDP socket must be available before this function is called. It is
    freed at the end of the function. MAX_UDP_SOCKETS may need to be
    increased if other modules use UDP sockets.                                                      
  ****************************************************************************************************/
void AnnounceIP(void)
{
	UDP_SOCKET	MySocket;
	BYTE 		i;

	if(!MACIsLinked())  // Check for link before blindly opening and transmitting (similar to DHCP case)
		return;

	// Open a UDP socket for outbound broadcast transmission
	//MySocket = UDPOpen(2860, NULL, ANNOUNCE_PORT);
	MySocket = UDPOpenEx(0,UDP_OPEN_SERVER,2860, ANNOUNCE_PORT);
            LED1_IO = 0;

	// Abort operation if no UDP sockets are available
	// If this ever happens, incrementing MAX_UDP_SOCKETS in 
	// StackTsk.h may help (at the expense of more global memory 
	// resources).
	if(MySocket == INVALID_UDP_SOCKET)
		return;
	
	// Make certain the socket can be written to
	while(!UDPIsPutReady(MySocket));
	
	// Begin sending our MAC address in human readable form.
	// The MAC address theoretically could be obtained from the 
	// packet header when the computer receives our UDP packet, 
	// however, in practice, the OS will abstract away the useful
	// information and it would be difficult to obtain.  It also 
	// would be lost if this broadcast packet were forwarded by a
	// router to a different portion of the network (note that 
	// broadcasts are normally not forwarded by routers).
	UDPPutArray((BYTE*)AppConfig.NetBIOSName, sizeof(AppConfig.NetBIOSName)-1);
	UDPPut('\r');
	UDPPut('\n');

	// Convert the MAC address bytes to hex (text) and then send it
	i = 0;
	while(1)
	{
		UDPPut(btohexa_high(AppConfig.MyMACAddr.v[i]));
	    UDPPut(btohexa_low(AppConfig.MyMACAddr.v[i]));
	    if(++i == 6u)
	    	break;
	    UDPPut('-');
	}

	// Send some other human readable information.
	UDPPutROMString((ROM BYTE*)"\r\nDHCP/Power event occurred");

	// Send the packet
	UDPFlush();
	
	// Close the socket so it can be used by other modules
	UDPClose(MySocket);
}
Example #17
0
bool DNSTerminate(const LLADP * pLLAdp)
{
    if(pLLAdp != NULL && pLLAdp->pDNSMem != NULL)
    {
        pLLAdp->pDNSMem->dnsState = dnsUninit;
        UDPClose(&pLLAdp->pDNSMem->socket);
        ((LLADP *) pLLAdp)->pDNSMem = NULL;
    }

    return(true);
}
Example #18
0
/*****************************************************************************
  Function:
	void DHCPDisable(void)

  Summary:
	Disables the DHCP Client.

  Description:
	Disables the DHCP client by sending the state machine to 
	"SM_DHCP_DISABLED".  If the board was previously configured by DHCP, the
	configuration will continue to be used but the module will no longer
	preform any renewals.

  Precondition:
	None

  Parameters:
	None

  Returns:
  	None
  	
  Remarks:
	Since the board continues using its old configuration, it is possible 
	that the lease may expire and the DHCP server provide the IP to another
	client.  The application should replace the current IP address and other
	configuration with static information following a call to this function.
  ***************************************************************************/
void DHCPDisable(void)
{
	if(DHCPSocket != INVALID_UDP_SOCKET)
	{
        UDPClose(DHCPSocket);
    	DHCPSocket = INVALID_UDP_SOCKET;
	}
	
	smDHCPState = SM_DHCP_DISABLED;
	AppConfig.Flags.bIsDHCPEnabled = 0;
}
Example #19
0
void registerListener() {
	memcpy(&remote, &UDPSocketInfo[localSocket].remote, sizeof(remote));
	localPort = UDPSocketInfo[localSocket].remotePort;

	listenerActive = 1;
	
	if(s != INVALID_UDP_SOCKET) {
		UDPClose(s);
		s = INVALID_UDP_SOCKET;
		return;
	}
}
Example #20
0
File: DNS.c Project: CEIT-UQ/RGB
/*****************************************************************************
  Function:
	BOOL DNSEndUsage(void)

  Summary:
	Releases control of the DNS module.
	
  Description:
	This function acts as a semaphore to obtain usage of the DNS module.
	Call this function when this application no longer needs the DNS 
	module so that other applications may make use of it.

  Precondition:
	DNSBeginUsage returned TRUE on a previous call.

  Parameters:
	None

  Return Values:
  	TRUE - The address to the host name was successfully resolved.
  	FALSE - The DNS failed or the address does not exist.
  	
  Remarks:
	Ensure that DNSEndUsage is always called once your application has
	obtained control of the DNS module.  If this is not done, the stack
	will hang for all future applications requiring DNS access.
  ***************************************************************************/
BOOL DNSEndUsage(void)
{
	if(MySocket != INVALID_UDP_SOCKET)
	{
		UDPClose(MySocket);
		MySocket = INVALID_UDP_SOCKET;
	}
	smDNS = DNS_DONE;
	Flags.bits.DNSInUse = FALSE;

	return Flags.bits.AddressValid;
}
Example #21
0
void DHCPReset(void)
{
    // Do not reset DHCP if it was previously disabled.
    if ( smDHCPState == SM_DHCP_DISABLED )
        return;

    if ( DHCPSocket != INVALID_UDP_SOCKET )
        UDPClose(DHCPSocket);
    DHCPSocket = INVALID_UDP_SOCKET;

    smDHCPState = SM_DHCP_INIT;
    DHCPBindCount = 0;
}
Example #22
0
/***	void UdpClient::close(void)
**
**	Synopsis:   
**      Closes the socket and clears the UdpClient instance;
**      Returns the instance to a just constructed state releasing
**      all resources except the user supplied datagram cache buffer
**      which will be reused if SetEndPoint is called again.
**
**	Parameters:
**      None
**
**	Return Values:
**      None
**
**	Errors:
**      None
**
**  Notes:
**
**      Returns the UdpClient instance to 
**      a state just as if the instance had just been
**      constructed. The user supplied datagram cache
**      should still be kept valid.
**
*/
void UdpClient::close(void)
{
    if(_hUDP < INVALID_UDP_SOCKET)
    {
        // remove from the UDP Cache
        ExchangeCacheBuffer(_hUDP, NULL, 0);

        // release MAL socket
        UDPClose(_hUDP);
        _hUDP = INVALID_UDP_SOCKET;
    }

    // initialize this instance of the class
    initUdpClient();
}
Example #23
0
void DHCPReset(void)
{
    // Do not reset DHCP if it was previously disabled.
    if ( smDHCPState == SM_DHCP_DISABLED )
        return;

    if ( DHCPSocket != INVALID_UDP_SOCKET )
        UDPClose(DHCPSocket);
    DHCPSocket = INVALID_UDP_SOCKET;

    smDHCPState = SM_DHCP_INIT_FIRST_TIME;
    DHCPBindCount = 0;

    DHCPState.bits.bIsBound = FALSE;
    DHCPState.bits.bStaticIP = FALSE;
}
Example #24
0
/****************************************************************************
  Function:
   void ChipKITUDPClose(UDP_SOCKET hUDP)

  Description:
    reads the available bytes out of the UDP cache
 
  Parameters:
    hUDP        - the UDP socket to clsoe

 
  Returns:
    None
  Remarks:
    The socket is closed and the resources returned to the UDP stack. Also the cache buffers are released and freed.

  ***************************************************************************/
void ChipKITUDPClose(UDP_SOCKET hUDP)
{
    if(UDPIsGetReady(hUDP) > 0)
    {
        UDPDiscard();
    }

    UDPClose(hUDP);

	// delete our cache buffer
	if(rgUDPSocketBuffers[hUDP] != NULL)
	{
		free(rgUDPSocketBuffers[hUDP]);
		rgUDPSocketBuffers[hUDP] = NULL;
	}
}
Example #25
0
/**
 * Disables the DHCP Client.
 * Disables the DHCP client by sending the state machine to 
 * "SM_DHCP_DISABLED".  If the board was previously configured by DHCP, the
 * configuration will continue to be used but the module will no longer
 * preform any renewals.
 */
void DHCPDisable(void)
{
	if(DHCPSocket != INVALID_UDP_SOCKET)
	{
        UDPClose(DHCPSocket);
    	DHCPSocket = INVALID_UDP_SOCKET;
	}
	
	smDHCPState = SM_DHCP_DISABLED;

    //Clear DHCP flag
    appcfgPutc(APPCFG_NETFLAGS, appcfgGetc(APPCFG_NETFLAGS) & ~APPCFG_NETFLAGS_DHCP);
    
    #if (DEBUG_DHCP >= LOG_INFO)
    debugPutMsg(14); //@mxd:14:Disabled
    #endif
}
Example #26
0
//processing http protocol , and excuting the followed fuction.
void WebServer(uint8 s)
{
	int ret;
	uint32 header_len=0, content_len=0, received_len=0;
	char sub[10];

	/* http service start */
	ret = TCPRecv(s, (int8*)rx_buf, MAX_URI_SIZE);

	if(ret > 0){					// If Received..
		*(((uint8*)rx_buf)+ret) = '\0';

		if(strstr(rx_buf, "Content-Length: ")){
			mid((char*)rx_buf, "Content-Length: ", "\r\n", sub);
			content_len=atoi(sub);
			header_len = (uint32)(strstr(rx_buf, "\r\n\r\n") - rx_buf + 4);

			received_len = ret;
			while(received_len!=(content_len+header_len))
			{
				ret = TCPRecv(s, (int8*)rx_buf+received_len, MAX_URI_SIZE);
				received_len+=ret;
			}

			*(((uint8*)rx_buf)+received_len) = '\0';
		}

		HTTPProcessor(s, (char*)rx_buf);	// request is processed
		memset(rx_buf,0x00,MAX_URI_SIZE);

		TCPDisconnect(s);

	} else if(ret == SOCKERR_NOT_TCP){		// Not TCP Socket, It's UDP Socket
		DBG("UDP Socket Close");
		UDPClose(s);

	} else if(ret == SOCKERR_CLOSED){			// Socket Closed
		LOGA("HTTP Server Started - ch(%d)",(uint16)s);
		TCPServerOpen(s, DEFAULT_HTTP_PORT);
	}

	if(GetTCPSocketStatus(s) == SOCKERR_CLOSE_WAIT){// Close waiting
		TCPClose(s);
	}
}
Example #27
0
void act_ncls(uint8 sock)
{
	int8 ret;

	if(sockbusy[sock] == VAL_TRUE) CMD_RESP_RET(RET_BUSY, VAL_NONE);
	if(sockstat[sock] == SOCK_STAT_IDLE) CMD_RESP_RET(RET_SOCK_CLS, VAL_NONE);
	if(sockstat[sock] & SOCK_STAT_TCP_MASK) {
		ret = TCPCloseNB(sock);
		if(ret != RET_OK) CMD_RESP_RET(RET_OK, VAL_NONE);
		sockwatch_set(sock, WATCH_SOCK_CLS_TRY);
		sockbusy[sock] = VAL_TRUE;
		CMD_RESP_RET(RET_ASYNC, sock);
	} else {
		UDPClose(sock);
		sock_put(sock);
		CMD_RESP_RET(RET_OK, VAL_NONE);
	}
}
Example #28
0
/***	void UdpServer::close(void)
**
**	Synopsis:   
**      Stops Listening and closes all unaccepted sockets
**      and clears everything back to it's originally constructed state.
**      The datagram cache buffers remain in use as this is specified on the constuctor
**
**	Parameters:
**      None
**
**	Return Values:
**      None
**
**	Errors:
**      None
**
**  Notes:
**
**      Returns the UdpServer instance to 
**      a state just as if the instance had just been
**      constructed. It also, Close all connections
**      and releases all resources (sockets).
**
*/
void UdpServer::close(void)
{
    stopListening();

    for(int i = 0; i < _cMaxPendingAllowed; i++)
    {
        if(_rghUDP[i] < INVALID_UDP_SOCKET)
        {
            // clean out the buffer
            UDPIsGetReady(_rghUDP[i]);
            UDPDiscard();
            UDPClose(_rghUDP[i]);
            ExchangeCacheBuffer(_rghUDP[i], NULL, 0);
            _rghUDP[i] = INVALID_UDP_SOCKET;
        }
    }

    clear();
}
Example #29
0
/***	void UdpServer::stopListening(void)
**
**	Synopsis:   
**      This stops listening on the server port, but does not shutdown UdpServer
**
**	Parameters:
**     None
**
**	Return Values:
**      None
**
**	Errors:
**      None
**
**  Notes:
**      To resume listening, just call ResumeListening
**      This is a soft stop listening in that only the server stops listening on the port
**      however the instance is still valid and you can continue to accept pending client.
**      and you can resume the listening.
**
*/
void UdpServer::stopListening(void)
{
   // DO NOT blow away pending clients.
   // that will be done on a close()
   // update the pending count so we have them all.
    availableClients();

   // blow away any listening socket
   if(_cPending < _cPendingMax && _rghUDP[_cPending] < INVALID_UDP_SOCKET)
    {
        UDPIsGetReady(_rghUDP[_cPending]);
        UDPDiscard();
        UDPClose(_rghUDP[_cPending]);
        ExchangeCacheBuffer(_rghUDP[_cPending], NULL, 0);
        _rghUDP[_cPending] = INVALID_UDP_SOCKET;
    }

    // no longer listening
    _fListening = false;
}
Example #30
0
void loopback_tcps(uint8 ch, uint16 port)
{
    int ret;
    int SendLen, ReSendLen;

    ret = TCPRecv(ch, data_buf, TX_RX_MAX_BUF_SIZE);

    if(ret > 0) {				// Received
        SendLen = TCPSend(ch, data_buf, ret);

        if(SendLen < ret) {
            while(SendLen != ret) {
                ReSendLen = TCPReSend(ch);

                if(ReSendLen > 0) {
                    SendLen += ReSendLen;

                } else if(ReSendLen == ERROR_WINDOW_FULL) {
                    LOG("Window Full");
                    TCPClose(ch);
                    DBG("TCP Socket Close");
                    while(1);

                } else {
                    break;
                }
            }
        }

    } else if(ret == ERROR_NOT_TCP_SOCKET) {	// Not TCP Socket, It's UDP Socket
        DBG("UDP Socket Close");
        UDPClose(ch);
    } else if(ret == ERROR_CLOSED) {		// Socket Closed
        LOGA("TCP Loop-Back Started - ch(%d)",(uint16)ch);
        TCPServerOpen(ch, port);
    }

    if(GetTCPSocketStatus(ch) == STATUS_CLOSE_WAIT) {	// Close waiting
        TCPClose(ch);
    }
}