@ -68,62 +68,83 @@ void DHCPServerApp_Callback(void)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						DHCP_Header_t *  const  AppData      =  ( DHCP_Header_t * ) uip_appdata ; 
 
					 
					 
					 
						DHCP_Header_t *  const  AppData      =  ( DHCP_Header_t * ) uip_appdata ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint16_t              AppDataSize  =  0 ; 
 
					 
					 
					 
						uint16_t              AppDataSize  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  DHCPMessageType ; 
 
					 
					 
					 
						/* Only process when new data arrives - don't retransmit lost packets */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						if  ( ! ( DHCPCommon_GetOption ( AppData - > Options ,  DHCP_OPTION_MSG_TYPE ,  & DHCPMessageType ) ) ) 
 
					 
					 
					 
						if  ( uip_newdata ( ) ) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							return ;  
 
					 
					 
					 
						{ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
 
					 
					 
					 
							/* Get the DHCP message type (if present), otherwise early-abort */  
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						uip_ipaddr_t  Netmask ,  GatewayIPAddress ; 
 
					 
					 
					 
							uint8_t  DHCPMessageType  ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						struct  uip_eth_addr  RemoteMACAddress ; 
 
					 
					 
					 
							if  ( ! ( DHCPCommon_GetOption ( AppData - > Options ,  DHCP_OPTION_MSG_TYPE ,  & DHCPMessageType ) ) )  
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						uint32_t             TransactionID ; 
 
					 
					 
					 
								return  ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						memcpy ( & RemoteMACAddress ,  & AppData - > ClientHardwareAddress ,  sizeof ( struct  uip_eth_addr ) ) ; 
 
					 
					 
					 
							uip_ipaddr_t         Netmask ,  GatewayIPAddress ,  PreferredClientIP ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						uip_getnetmask ( & Netmask ) ; 
 
					 
					 
					 
							struct  uip_eth_addr  RemoteMACAddress ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						uip_getdraddr ( & GatewayIPAddress ) ; 	
 
					 
					 
					 
							uint32_t             TransactionID ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						TransactionID  =  AppData - > TransactionID ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						switch  ( DHCPMessageType ) 
 
					 
					 
					 
							/* Get configured network mask, gateway IP and extract out DHCP transaction ID and remote IP */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						{ 
 
					 
					 
					 
							uip_getnetmask ( & Netmask ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							case  DHCP_DISCOVER : 
 
					 
					 
					 
							uip_getdraddr ( & GatewayIPAddress ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								AppDataSize  + =  DHCPServerApp_FillDHCPHeader ( AppData ,  DHCP_OFFER ,  & RemoteMACAddress ,  TransactionID ) ; 
 
					 
					 
					 
							memcpy ( & RemoteMACAddress ,  & AppData - > ClientHardwareAddress ,  sizeof ( struct  uip_eth_addr ) ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							TransactionID  =  AppData - > TransactionID ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_SUBNET_MASK , 
 
					 
					 
					 
							/* Try to extract out the client's preferred IP address if it is indicated in the packet */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								                                    sizeof ( uip_ipaddr_t ) ,  & Netmask ) ; 
 
					 
					 
					 
							if  ( ! ( DHCPCommon_GetOption ( AppData - > Options ,  DHCP_OPTION_REQ_IPADDR ,  & PreferredClientIP ) ) ) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_ROUTER , 
 
					 
					 
					 
							  memcpy ( & PreferredClientIP ,  & uip_all_zeroes_addr ,  sizeof ( uip_ipaddr_t ) ) ; 	
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								                                    sizeof ( uip_ipaddr_t ) ,  & GatewayIPAddress ) ; 
 
					 
					 
					 
							
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								
 
					 
					 
					 
							switch  ( DHCPMessageType ) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								/* Send the DHCP OFFER packet */ 
 
					 
					 
					 
							{ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								uip_poll_conn ( BroadcastConnection ) ; 
 
					 
					 
					 
								case  DHCP_DISCOVER : 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								memcpy ( & uip_udp_conn - > ripaddr ,  & uip_broadcast_addr ,  sizeof ( uip_ipaddr_t ) ) ; 
 
					 
					 
					 
									/* If no preference was made or the preferred IP is already taken, find a new address */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								uip_udp_send ( AppDataSize ) ; 
 
					 
					 
					 
									if  ( DHCPServerApp_CheckIfIPLeased ( & PreferredClientIP ) ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									  DHCPServerApp_GetUnleasedIP ( & PreferredClientIP ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								break ; 
 
					 
					 
					 
									/* Create a new DHCP OFFER packet with the offered IP address */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							case  DHCP_REQUEST : 
 
					 
					 
					 
									AppDataSize  + =  DHCPServerApp_FillDHCPHeader ( AppData ,  DHCP_OFFER ,  & RemoteMACAddress ,  & PreferredClientIP ,  TransactionID ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								if  ( ! ( DHCPServerApp_CheckIfIPLeased ( & AppData - > YourIP ) ) ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								{ 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									AppDataSize  + =  DHCPServerApp_FillDHCPHeader ( AppData ,  DHCP_ACK ,  & RemoteMACAddress ,  TransactionID ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									/* Add network mask and router information to the list of DHCP OFFER packet options */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_SUBNET_MASK , 
 
					 
					 
					 
									AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_SUBNET_MASK , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
																		sizeof ( uip_ipaddr_t ) ,  & Netmask ) ; 
 
					 
					 
					 
																		sizeof ( uip_ipaddr_t ) ,  & Netmask ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_ROUTER , 
 
					 
					 
					 
									AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_ROUTER , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
																		sizeof ( uip_ipaddr_t ) ,  & GatewayIPAddress ) ; 
 
					 
					 
					 
										                                sizeof ( uip_ipaddr_t ) ,  & GatewayIPAddress ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
									DHCPServerApp_LeaseIP ( & AppData - > YourIP ) ; 
 
					 
					 
					 
									/* Send the DHCP OFFER packet */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								} 
 
					 
					 
					 
									uip_poll_conn ( BroadcastConnection ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								else 
 
					 
					 
					 
									memcpy ( & uip_udp_conn - > ripaddr ,  & uip_broadcast_addr ,  sizeof ( uip_ipaddr_t ) ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								{ 
 
					 
					 
					 
									uip_udp_send ( AppDataSize ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
									AppDataSize  + =  DHCPServerApp_FillDHCPHeader ( AppData ,  DHCP_NAK ,  & RemoteMACAddress ,  TransactionID ) ; 			
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								} 
 
					 
					 
					 
									break ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
								case  DHCP_REQUEST : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									/* Check to see if the requested IP address has already been leased to a client */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									if  ( ! ( DHCPServerApp_CheckIfIPLeased ( & PreferredClientIP ) ) ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										/* Create a new DHCP ACK packet to accept the IP address lease */ 					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										AppDataSize  + =  DHCPServerApp_FillDHCPHeader ( AppData ,  DHCP_ACK ,  & RemoteMACAddress ,  & PreferredClientIP ,  TransactionID ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										/* Add network mask and router information to the list of DHCP ACK packet options */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_SUBNET_MASK , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
																			sizeof ( uip_ipaddr_t ) ,  & Netmask ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										AppDataSize  + =  DHCPCommon_SetOption ( AppData - > Options ,  DHCP_OPTION_ROUTER , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										                                    sizeof ( uip_ipaddr_t ) ,  & GatewayIPAddress ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										/* Mark the requested IP as leased to a client */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										DHCPServerApp_LeaseIP ( & PreferredClientIP ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										/* Create a new DHCP NAK packet to reject the requested allocation */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
										AppDataSize  + =  DHCPServerApp_FillDHCPHeader ( AppData ,  DHCP_NAK ,  & RemoteMACAddress ,  & uip_all_zeroes_addr ,  TransactionID ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									/* Send the DHCP ACK or NAK packet */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									uip_poll_conn ( BroadcastConnection ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									memcpy ( & uip_udp_conn - > ripaddr ,  & uip_broadcast_addr ,  sizeof ( uip_ipaddr_t ) ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									uip_udp_send ( AppDataSize ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								
 
					 
					 
					 
								
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								/* Send the DHCP ACK or NAK packet */ 
 
					 
					 
					 
									break ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								uip_poll_conn ( BroadcastConnection ) ; 
 
					 
					 
					 
								case  DHCP_RELEASE : 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								memcpy ( & uip_udp_conn - > ripaddr ,  & uip_broadcast_addr ,  sizeof ( uip_ipaddr_t ) ) ; 
 
					 
					 
					 
									/* Mark the IP address as released in the allocation table */ 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								uip_udp_send ( AppDataSize ) ; 
 
					 
					 
					 
									DHCPServerApp_UnleaseIP ( & uip_udp_conn - > ripaddr ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							
 
					 
					 
					 
									break ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								break ; 
 
					 
					 
					 
							} 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							case  DHCP_RELEASE : 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								/* Mark the IP address as released in the allocation table */ 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								DHCPServerApp_UnleaseIP ( & uip_udp_conn - > ripaddr ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								break ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						} 
 
					 
					 
					 
						} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -139,8 +160,9 @@ void DHCPServerApp_Callback(void)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */ 
 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  uint16_t  DHCPServerApp_FillDHCPHeader ( DHCP_Header_t *  const  DHCPHeader , 
 
					 
					 
					 
					static  uint16_t  DHCPServerApp_FillDHCPHeader ( DHCP_Header_t *  const  DHCPHeader , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                                             const  uint8_t  DHCPMessageType , 
 
					 
					 
					 
					                                             const  uint8_t  DHCPMessageType , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                                             struct  uip_eth_addr *  ClientHardwareAddress , 
 
					 
					 
					 
					                                             const  struct  uip_eth_addr *  const  ClientHardwareAddress , 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					                                             uint32_t  TransactionID ) 
 
					 
					 
					 
																 const  uip_ipaddr_t *  const  PreferredClientIP , 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                                             const  uint32_t  TransactionID ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						/* Erase existing packet data so that we start will all 0x00 DHCP header data */ 
 
					 
					 
					 
						/* Erase existing packet data so that we start will all 0x00 DHCP header data */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 	memset ( DHCPHeader ,  0 ,  sizeof ( DHCP_Header_t ) ) ; 
 
					 
					 
					 
					 	memset ( DHCPHeader ,  0 ,  sizeof ( DHCP_Header_t ) ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -153,8 +175,7 @@ static uint16_t DHCPServerApp_FillDHCPHeader(DHCP_Header_t* const DHCPHeader,
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						DHCPHeader - > ElapsedSeconds         =  0 ; 
 
					 
					 
					 
						DHCPHeader - > ElapsedSeconds         =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						DHCPHeader - > Flags                  =  0 ; 
 
					 
					 
					 
						DHCPHeader - > Flags                  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						memcpy ( & DHCPHeader - > NextServerIP ,  & uip_hostaddr ,  sizeof ( uip_ipaddr_t ) ) ; 
 
					 
					 
					 
						memcpy ( & DHCPHeader - > NextServerIP ,  & uip_hostaddr ,  sizeof ( uip_ipaddr_t ) ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						if  ( uip_ipaddr_cmp ( & DHCPHeader - > YourIP ,  & uip_all_zeroes_addr ) ) 
 
					 
					 
					 
						memcpy ( & DHCPHeader - > YourIP ,  PreferredClientIP ,  sizeof ( uip_ipaddr_t ) ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						  DHCPServerApp_GetUnleasedIP ( & DHCPHeader - > YourIP ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						memcpy ( & DHCPHeader - > ClientHardwareAddress ,  ClientHardwareAddress ,  sizeof ( struct  uip_eth_addr ) ) ; 
 
					 
					 
					 
						memcpy ( & DHCPHeader - > ClientHardwareAddress ,  ClientHardwareAddress ,  sizeof ( struct  uip_eth_addr ) ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						DHCPHeader - > Cookie                 =  DHCP_MAGIC_COOKIE ; 
 
					 
					 
					 
						DHCPHeader - > Cookie                 =  DHCP_MAGIC_COOKIE ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						  
 
					 
					 
					 
						  
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -176,12 +197,13 @@ static uint16_t DHCPServerApp_FillDHCPHeader(DHCP_Header_t* const DHCPHeader,
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * 
 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *   \ return  Boolean  true  if  the  IP  has  already  been  leased  to  a  client ,  false  otherwise . 
 
					 
					 
					 
					 *   \ return  Boolean  true  if  the  IP  has  already  been  leased  to  a  client ,  false  otherwise . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */ 
 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  bool  DHCPServerApp_CheckIfIPLeased ( uip_ipaddr_t *  IPAddress ) 
 
					 
					 
					 
					static  bool  DHCPServerApp_CheckIfIPLeased ( const  uip_ipaddr_t *  const   IPAddress ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  Byte  =  ( IPAddress - > u8 [ 3 ]  /  8 ) ; 
 
					 
					 
					 
						uint8_t  Byte  =  ( IPAddress - > u8 [ 3 ]  /  8 ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  Mask  =  ( 1  < <  ( IPAddress - > u8 [ 3 ]  %  8 ) ) ; 
 
					 
					 
					 
						uint8_t  Mask  =  ( 1  < <  ( IPAddress - > u8 [ 3 ]  %  8 ) ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						
 
					 
					 
					 
						
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						if  ( ! ( IPAddress - > u8 [ 3 ]  = =  uip_hostaddr . u8 [ 3 ] )  & &  ! ( LeasedIPs [ Byte ]  &  Mask ) ) 
 
					 
					 
					 
						/* Make sure that the requested IP address isn't already leased to the virtual server or another client */ 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						if  ( IPAddress - > u8 [ 3 ]  & &  ! ( IPAddress - > u8 [ 3 ]  = =  uip_hostaddr . u8 [ 3 ] )  & &  ! ( LeasedIPs [ Byte ]  &  Mask ) ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						  return  false ; 
 
					 
					 
					 
						  return  false ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						else 
 
					 
					 
					 
						else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						  return  true ; 
 
					 
					 
					 
						  return  true ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -191,14 +213,17 @@ static bool DHCPServerApp_CheckIfIPLeased(uip_ipaddr_t* IPAddress)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * 
 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *   \ param [ out ]  NewIPAddress   Location  where  the  generated  IP  Address  should  be  stored 
 
					 
					 
					 
					 *   \ param [ out ]  NewIPAddress   Location  where  the  generated  IP  Address  should  be  stored 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */ 
 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  DHCPServerApp_GetUnleasedIP ( uip_ipaddr_t *  NewIPAddress ) 
 
					 
					 
					 
					static  void  DHCPServerApp_GetUnleasedIP ( uip_ipaddr_t *  const  NewIPAddress ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uip_ipaddr_copy ( NewIPAddress ,  & uip_hostaddr ) ; 
 
					 
					 
					 
						uip_ipaddr_copy ( NewIPAddress ,  & uip_hostaddr ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						
 
					 
					 
					 
						
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						/** Look through the current subnet, skipping the broadcast and zero IP addresses */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						for  ( uint8_t  IP  =  1 ;  IP  <  254 ;  IP + + ) 
 
					 
					 
					 
						for  ( uint8_t  IP  =  1 ;  IP  <  254 ;  IP + + ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						{ 
 
					 
					 
					 
						{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							/* Update new IP address to lease with the current IP address to test */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							NewIPAddress - > u8 [ 3 ]  =  IP ; 
 
					 
					 
					 
							NewIPAddress - > u8 [ 3 ]  =  IP ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							
 
					 
					 
					 
							
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							/* If we've found an unleased IP, abort with the updated IP stored for the called */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  ( ! ( DHCPServerApp_CheckIfIPLeased ( NewIPAddress ) ) ) 
 
					 
					 
					 
							if  ( ! ( DHCPServerApp_CheckIfIPLeased ( NewIPAddress ) ) ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							  return ; 
 
					 
					 
					 
							  return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						} 
 
					 
					 
					 
						} 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -211,11 +236,12 @@ static void DHCPServerApp_GetUnleasedIP(uip_ipaddr_t* NewIPAddress)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * 
 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *   \ pre  The  IP  address  must  be  within  the  same  / 24  subnet  as  the  virtual  webserver . 
 
					 
					 
					 
					 *   \ pre  The  IP  address  must  be  within  the  same  / 24  subnet  as  the  virtual  webserver . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */ 
 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  DHCPServerApp_LeaseIP ( uip_ipaddr_t *  IPAddress ) 
 
					 
					 
					 
					static  void  DHCPServerApp_LeaseIP ( const  uip_ipaddr_t *  const   IPAddress ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  Byte  =  ( IPAddress - > u8 [ 3 ]  /  8 ) ; 
 
					 
					 
					 
						uint8_t  Byte  =  ( IPAddress - > u8 [ 3 ]  /  8 ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  Mask  =  ( 1  < <  ( IPAddress - > u8 [ 3 ]  %  8 ) ) ; 
 
					 
					 
					 
						uint8_t  Mask  =  ( 1  < <  ( IPAddress - > u8 [ 3 ]  %  8 ) ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						
 
					 
					 
					 
						
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						/* Mark the IP address as leased in the allocation table */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						LeasedIPs [ Byte ]  | =  Mask ; 
 
					 
					 
					 
						LeasedIPs [ Byte ]  | =  Mask ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -226,11 +252,12 @@ static void DHCPServerApp_LeaseIP(uip_ipaddr_t* IPAddress)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * 
 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *   \ pre  The  IP  address  must  be  within  the  same  / 24  subnet  as  the  virtual  webserver . 
 
					 
					 
					 
					 *   \ pre  The  IP  address  must  be  within  the  same  / 24  subnet  as  the  virtual  webserver . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */ 
 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  DHCPServerApp_UnleaseIP ( uip_ipaddr_t *  IPAddress ) 
 
					 
					 
					 
					static  void  DHCPServerApp_UnleaseIP ( const  uip_ipaddr_t *  const   IPAddress ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					{ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  Byte  =  ( IPAddress - > u8 [ 3 ]  /  8 ) ; 
 
					 
					 
					 
						uint8_t  Byte  =  ( IPAddress - > u8 [ 3 ]  /  8 ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						uint8_t  Mask  =  ( 1  < <  ( IPAddress - > u8 [ 3 ]  %  8 ) ) ; 
 
					 
					 
					 
						uint8_t  Mask  =  ( 1  < <  ( IPAddress - > u8 [ 3 ]  %  8 ) ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						
 
					 
					 
					 
						
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						/* Mark the IP address as unleased in the allocation table */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						LeasedIPs [ Byte ]  & =  ~ Mask ; 
 
					 
					 
					 
						LeasedIPs [ Byte ]  & =  ~ Mask ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif