Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/dhcp/dhcpc.c File Reference


Detailed Description

Author:
Version:
1.03
Date:
23.5.2003
Bug:
Warning:
Todo:
OpenTCP DHCP client protocol implementation. Features a complete DHCP state machine. Function declarations can be found in inet/dhcp/dhcpc.h

Definition in file dhcpc.c.

Go to the source code of this file.

Functions

INT32 dhcpc_eventlistener (INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen)
 DHCP event listener, parses all DHCP replies.

INT8 dhcpc_send_message (UINT8 msg_type)
 Sends DHCP messages.

INT8 dhcpc_init (void)
 Initializes DHCP client.

void dhcpc_run (void)
 DHCP client main state machine.

UINT32 dhcpc_read_n_bytes (UINT8 n)
 Processes received parameter from DHCP server.


Variables

UINT8 dhcpc_state
 Holds DHCP clients' state information.

UINT8 dhcpc_timer_handle
 DHCP client's timer handle.

INT8 dhcpc_soc_handle
 DHCP client's UDP socket handle.

UINT8 dhcpc_initialized = 0
 Holds information if DHCP client is initialized.

UINT32 dhcpc_t1
 DHCP renew timer.

UINT32 dhcpc_t2
 DHCP rebind timer.

UINT32 dhcpc_server_identifier
 DHCP server identifier as received from DHCP server.

UINT32 dhcpc_requested_ip
 Holds offered IP address or IP address that we're requesting.


Function Documentation

INT32 dhcpc_eventlistener INT8    cbhandle,
UINT8    event,
UINT32    ipaddr,
UINT16    port,
UINT16    buffindex,
UINT16    datalen
 

Author:
Date:
23.05.2003
This is internal function invoked by OpenTCP UDP module when DHCP reply on a given UDP port is received. This function parses the response, checks for correctnes and performs certain actions based on the current state of DHCP client.

Definition at line 568 of file dhcpc.c.

References dhcpc_read_n_bytes(), dhcpc_requested_ip, dhcpc_send_message(), dhcpc_server_identifier, dhcpc_soc_handle, dhcpc_state, dhcpc_t1, dhcpc_t2, RECEIVE_NETWORK_B, and UDP_EVENT_DATA.

Referenced by dhcpc_init().

INT8 dhcpc_send_message UINT8    msg_type
 

Author:
Date:
23.05.2003
Parameters:
msg_type  Type of DHCP message to be sent. This implementation can send only DHCP_DISCOVER, DHCP_REQUEST and DCHP_DECLINE messages.
Returns:
Returns result of udp_send() function.
This is internal function invoked to send appropriate DHCP message.

Definition at line 389 of file dhcpc.c.

References dhcpc_requested_ip, dhcpc_server_identifier, dhcpc_soc_handle, dhcpc_state, NETWORK_TX_BUFFER_SIZE, UDP_APP_OFFSET, and udp_send().

Referenced by dhcpc_eventlistener(), and dhcpc_run().

INT8 dhcpc_init void   
 

Author:
Date:
23.05.2003
This function should be called once when system starts to initialize and start DHCP client. Before this function is invoked, localmachine.localip MUST be se to either zero (in which case DHCP client will request any IP address) or a previously assigned IP address (which doesn't mean DHCP server will allow us to continue using this address) in which case DHCP client will first try to obtain that existing IP address.

Definition at line 158 of file dhcpc.c.

References dhcpc_eventlistener(), dhcpc_initialized, dhcpc_soc_handle, dhcpc_state, dhcpc_timer_handle, get_timer(), init_timer(), TIMERTIC, udp_getsocket(), udp_open(), UDP_OPT_CHECK_CS, and UDP_OPT_SEND_CS.

void dhcpc_run void   
 

Author:
Date:
23.05.2003
Call this function periodically from main loop to ensure proper operation. This function holds the main state machine of DHCP client that ensures proper operation.

Definition at line 201 of file dhcpc.c.

References check_timer(), dhcpc_initialized, dhcpc_requested_ip, dhcpc_send_message(), dhcpc_state, dhcpc_t1, dhcpc_t2, dhcpc_timer_handle, init_timer(), and TIMERTIC.

UINT32 dhcpc_read_n_bytes UINT8    n
 

Author:
Date:
23.05.2003
Parameters:
n  Number of bytes to read&process.
Returns:
Returns last for 4 bytes that were read as a 32-bit variable
This is internal function that get's invoked to read a received parameter in DHCP message. Introduced to optimize code a little as 4 byte parameters are often returned by DHCP server (netmask, gateway, server identifier, T1, T2, lease expiration time, DNS IP,..)

Definition at line 549 of file dhcpc.c.

References RECEIVE_NETWORK_B.

Referenced by dhcpc_eventlistener().


Variable Documentation

UINT8 dhcpc_state
 

This variable holds DHCP clients' current state information. Possible states are DHCP_STATE_INIT_REBOOT, DHCP_STATE_REBOOTING, DHCP_STATE_INIT, DHCP_STATE_SELECTING, DHCP_STATE_REQUESTING, DHCP_STATE_BOUND, DHCP_STATE_RENEWING, DHCP_STATE_REBINDING.

Definition at line 87 of file dhcpc.c.

Referenced by dhcpc_eventlistener(), dhcpc_init(), dhcpc_run(), and dhcpc_send_message().

UINT8 dhcpc_timer_handle
 

Hold DHCP clients' timer handle. We'll use only one timer from timer pool and take care of the rest by ourselves manually

Definition at line 94 of file dhcpc.c.

Referenced by dhcpc_init(), and dhcpc_run().

INT8 dhcpc_soc_handle
 

DHCP client's UDP socket handle

Definition at line 100 of file dhcpc.c.

Referenced by dhcpc_eventlistener(), dhcpc_init(), and dhcpc_send_message().

UINT8 dhcpc_initialized = 0
 

Holds information if DHCP client is initialized

Definition at line 106 of file dhcpc.c.

Referenced by dhcpc_init(), and dhcpc_run().

UINT32 dhcpc_t1
 

This variable holds renew time (in seconds) after which we'll start the renewing process. While obtaining the parameters from DHCP server (thus before we know of the renew time) this is used also to time retransmissions.

Definition at line 115 of file dhcpc.c.

Referenced by dhcpc_eventlistener(), and dhcpc_run().

UINT32 dhcpc_t2
 

This variable holds rebind time (in seconds) after which we'll start the rebinding process. While obtaining the paramters from DHCP server (thus before we know of the renew time) this is also used to time retransmissions as well as timeout detection

Definition at line 124 of file dhcpc.c.

Referenced by dhcpc_eventlistener(), and dhcpc_run().

UINT32 dhcpc_server_identifier
 

This variable will hold DHCP server identifier (which will actually be server's IP address).

Definition at line 131 of file dhcpc.c.

Referenced by dhcpc_eventlistener(), and dhcpc_send_message().

UINT32 dhcpc_requested_ip
 

This variable holds the IP address that DHCP server offered to us during address request procedure and this is the address that we will be requesting in all future requests untill DHCP server disallows us to use it any more.

Definition at line 140 of file dhcpc.c.

Referenced by dhcpc_eventlistener(), dhcpc_run(), and dhcpc_send_message().


Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by doxygen1.2.18