Example #1
0
void nic_connect(void)
{
/*	This part of code is required only if using the interrupt while accessing the SPI
	attachInterrupt(0, zg_isr, LOW);
*/	
	zg_setpolling();

	// Include debug functionalities, if required
	#if(VNET_DEBUG)
	// Print address  
    VNET_LOG("(vNet)WiFi Connecting");
	VNET_LOG("\r\n");
	#endif
	
	// Connect to a Wifi network or in AdHoc mode	
	while(zg_get_conn_state() != 1) {
		zg_drv_process();
	}	
	
	// Include debug functionalities, if required
	#if(VNET_DEBUG)
	// Print address  
    VNET_LOG("(vNet)WiFi Connected");
	VNET_LOG("\r\n");
	#endif	
}
Example #2
0
uint8_t UserMode_Get(U16 addr, U8* ip_addr, U8* p_port)
{
	U8 i=0;

	// Verify that the entry was not yet saved
	for(i=0;i<UMODE_USERS;i++)
		if(in_vNet_Addresses[i]==addr)
			break;

	// If the vNet address wasn't found, return
	if(i==UMODE_USERS)
		return 0;			
	
	// Return the IP address pointer
	memmove(ip_addr, in_IP_Addresses + i*(IPADDRESS_BYTES), IPADDRESS_BYTES);
	memmove(p_port, in_P_Port + i*(PPORT_BYTES), PPORT_BYTES);	

	// If the IP address is in black list skip
	#if(VNET_USERLOCKDOWN)
	for(i=0;i<UMODE_USERS;i++)
	{
		if((*(ip_addr) == *(blacklist_IP_Addresses+i)) && (*(ip_addr+1) == *(blacklist_IP_Addresses+i+1)) &&
			(*(ip_addr+2) == *(blacklist_IP_Addresses+i+2)) && (*(ip_addr+3) == *(blacklist_IP_Addresses+i+3)))
		{
			#if(VNET_DEBUG)
			VNET_LOG(F("(vNet)<Blacklist>\r\n"));
			#endif			

			return 0;
		}
	}
	#endif

	return 1;
}
Example #3
0
void vNet_SetAddress_M1(uint16_t addr)
{
	uint8_t ip_addr[4], mac_addr[6];
	
	// Translate and set the address
	eth_vNettoIP(addr, &ip_addr[0]);
	eth_SetIPAddress(&ip_addr[0]);
	
	// Set the MAC Address	
	#if(AUTO_MAC)
		eth_vNettoMAC(addr, mac_addr);
		W5x00.setMACAddress(mac_addr);
	#else
		W5x00.setMACAddress((uint8_t*)MAC_ADDRESS);
	#endif
	
	// Set the IP
	W5x00.setIPAddress(stack.ip);
	W5x00.setGatewayIp(stack.gateway);
	W5x00.setSubnetMask(stack.subnetmask);
	
	vNet_Begin_M1(UDP_SOCK);								// Start listen on socket

	// Include debug functionalities, if required
	#if(VNET_DEBUG)
	uint8_t addrval[6];
	
	// Print MAC address 
	W5x00.getMACAddress(addrval);
    VNET_LOG("(MAC)<");
	for(U8 i=0; i<6; i++)
	{
		VNET_LOG(addrval[i],HEX);
		VNET_LOG(",");
	}
	VNET_LOG(">\r\n");

	// Print IP address 
	W5x00.getIPAddress(addrval);
    VNET_LOG("(IP)<");
	for(U8 i=0; i<4; i++)
	{
		VNET_LOG(addrval[i],HEX);
		VNET_LOG(",");
	}
	
	VNET_LOG(">\r\n");
	#endif	
	
}
Example #4
0
u8_t nic_poll(void)
{
	u16_t packetLength;
	
	// Connection lost, retry	
	if(zg_get_conn_state() != 1) {
	
		// Include debug functionalities, if required
		#if(VNET_DEBUG)
		// Print address  
		VNET_LOG("(vNet)WiFi Connection lost, retry");
		VNET_LOG("\r\n");
		#endif	
	
		while(zg_get_conn_state() != 1){
			zg_drv_process();
		}
	}
	
	// This method place the incoming data directly into the uIP buffer
	packetLength = zg_get_rx_status();	

	// Process the in/out data from the Wifi controller
	zg_drv_process();
	
	// If there are no incoming data
	if(!packetLength)
	  return packetLength = 0;

	// If the lenght exceed the buffer size
	if(packetLength > UIP_BUFSIZE)
		return packetLength = 0; 
	
	// Return the lenght		
	return packetLength;	
}
Example #5
0
void UserMode_Init()
{
	for(U8 i=0;i<(UMODE_USERS*IPADDRESS_BYTES);i++)
	{
		in_IP_Addresses[i]=0;
		blacklist_IP_Addresses[i]=0;
	}

	// If there were previous saved vNet address from User Interfaces
	#if(USEEEPROM)
	if(Return_ID()==STORE__DEFAULTID)
		Return_UserModeAddresses(in_vNet_Addresses, UMODE_USERS);
	#endif

	#if(VNET_DEBUG)
	VNET_LOG(F("(vNet)<USERMODE><0x"));
	for(U8 i=0;i<(UMODE_USERS);i++)
	{
		VNET_LOG(in_vNet_Addresses[i],HEX);
		VNET_LOG(F("|0x"));
	}
	VNET_LOG(F(">\r\n"));
	#endif	
}
Example #6
0
void UserMode_Record(U16 addr, U8* ip_addr, U8* p_port)
{
	U8 i=0;

	// Verify that the entry was not yet saved or find the first available index
	for(i=0;i<UMODE_USERS;i++)
		if((in_vNet_Addresses[i]==addr) || (in_vNet_Addresses[i]==0x0000))
			break;


	// Accept new incoming connection only just after the boot
	#if(VNET_USERLOCKDOWN)
	if(!JustBooted())
	{
		// Update the IP address for existing entries
		if(in_vNet_Addresses[i]==addr)
		{
			// Refresh the IP address
			memmove(in_IP_Addresses + i*(IPADDRESS_BYTES), ip_addr, IPADDRESS_BYTES);	// Store the IP address
			memmove(in_P_Port + i*(PPORT_BYTES), p_port, PPORT_BYTES);					// Store the IP port
		}
		else
		{
			//Record the IP address in the black list
			for(i=0;i<(UMODE_USERS);i++)
				if((blacklist_IP_Addresses[i*4] == 0) || 
					((*(ip_addr) == *(blacklist_IP_Addresses+i)) && (*(ip_addr+1) == *(blacklist_IP_Addresses+i+1)) &&
					(*(ip_addr+2) == *(blacklist_IP_Addresses+i+2)) && (*(ip_addr+3) == *(blacklist_IP_Addresses+i+3))))

					break;
			
			// If the table is full start from the first entry
			if(i==UMODE_USERS)
				i=(last_entry_blacklist+1)%UMODE_USERS;
			
			last_entry_blacklist=i;

			// Store the IP address in the blacklist
			blacklist_IP_Addresses[i]	= ip_addr[0];
			blacklist_IP_Addresses[i+1] = ip_addr[1];
			blacklist_IP_Addresses[i+2] = ip_addr[2];
			blacklist_IP_Addresses[i+3] = ip_addr[3];
		}

		#if(VNET_DEBUG)
		VNET_LOG(F("(vNet)<Lockdwn>"));
		#endif			

		return;
	}
	#endif

	// If the table is full, use the oldest entry
	if(i==UMODE_USERS)
		i=(last_entry+1)%UMODE_USERS;
	
	// Record the last entry index
	last_entry = i;
	
	// If is a new vNet address, record it
	if((in_vNet_Addresses[i]!=addr))
	{
		in_vNet_Addresses[i] = addr;
		
		#if(USEEEPROM)
		Store_UserModeAddresses(in_vNet_Addresses, UMODE_USERS);
		Store_Commit();
		#endif	

		#if(VNET_DEBUG)
		VNET_LOG(F("(vNet)<USERMODE><0x"));
		for(U8 i=0;i<(UMODE_USERS);i++)
		{
			VNET_LOG(in_vNet_Addresses[i],HEX);
			VNET_LOG(F("|0x"));
		}
		VNET_LOG(F(">\r\n"));
		#endif		
	}

	// Refresh the IP address
	memmove(in_IP_Addresses + i*(IPADDRESS_BYTES), ip_addr, IPADDRESS_BYTES);	// Store the IP address
	memmove(in_P_Port + i*(PPORT_BYTES), p_port, PPORT_BYTES);					// Store the IP port
}