#include <stdio.h>
#include <string.h>
#include "contiki.h"
#include "contiki-net.h"
#include "net/ip/dhcpc.h"
Data Structures | |
struct | dhcp_msg |
Macros | |
#define | BOOTP_BROADCAST 0x8000 |
#define | DHCP_HLEN_ETHERNET 6 |
#define | DHCP_HTYPE_ETHERNET 1 |
#define | DHCP_MSG_LEN 236 |
#define | DHCP_OPTION_DNS_SERVER 6 |
#define | DHCP_OPTION_END 255 |
#define | DHCP_OPTION_LEASE_TIME 51 |
#define | DHCP_OPTION_MSG_TYPE 53 |
#define | DHCP_OPTION_REQ_IPADDR 50 |
#define | DHCP_OPTION_REQ_LIST 55 |
#define | DHCP_OPTION_ROUTER 3 |
#define | DHCP_OPTION_SERVER_ID 54 |
#define | DHCP_OPTION_SUBNET_MASK 1 |
#define | DHCP_REPLY 2 |
#define | DHCP_REQUEST 1 |
#define | DHCPACK 5 |
#define | DHCPC_CLIENT_PORT 68 |
#define | DHCPC_SERVER_PORT 67 |
#define | DHCPDECLINE 4 |
#define | DHCPDISCOVER 1 |
#define | DHCPNAK 6 |
#define | DHCPOFFER 2 |
#define | DHCPRELEASE 7 |
#define | DHCPREQUEST 3 |
#define | IMIN(a, b) ((a) < (b) ? (a) : (b)) |
#define | MAX_TICKS (~((clock_time_t)0) / 2) |
#define | MAX_TICKS32 (~((uint32_t)0)) |
#define | STATE_CONFIG_RECEIVED 3 |
#define | STATE_INITIAL 0 |
#define | STATE_OFFER_RECEIVED 2 |
#define | STATE_SENDING 1 |
Functions | |
static uint8_t * | add_end (uint8_t *optptr) |
static uint8_t * | add_msg_type (uint8_t *optptr, uint8_t type) |
static uint8_t * | add_req_ipaddr (uint8_t *optptr) |
static uint8_t * | add_req_options (uint8_t *optptr) |
static uint8_t * | add_server_id (uint8_t *optptr) |
static void | create_msg (CC_REGISTER_ARG struct dhcp_msg *m) |
void | dhcpc_appcall (process_event_t ev, void *data) |
void | dhcpc_init (const void *mac_addr, int mac_len) |
void | dhcpc_request (void) |
if (ev==tcpip_event &&uip_newdata()&&msg_for_me()==DHCPACK) | |
if (s.ticks<=CLOCK_SECOND *10) | |
if ((uip_ntohs(s.lease_time[0])*65536ul+uip_ntohs(s.lease_time[1]))*CLOCK_SECOND/2<=MAX_TICKS32) | |
static int | msg_for_me (void) |
static uint8_t | parse_msg (void) |
static uint8_t | parse_options (uint8_t *optptr, int len) |
static void | send_discover (void) |
static void | send_request (void) |
while (1) | |
while (!etimer_expired(&s.etimer)) | |
while (s.state!=STATE_CONFIG_RECEIVED) | |
while (s.ticks > 0) | |
while (s.ticks >=CLOCK_SECOND *3) | |
Variables | |
init | __pad0__ |
selecting | __pad1__ |
bound | __pad2__ |
do | |
else | |
goto | init |
static const uint8_t | magic_cookie [4] = {99, 130, 83, 99} |
static struct dhcpc_state | s |
s | state = STATE_SENDING |
s | ticks = CLOCK_SECOND |
static uint32_t | xid |
#define BOOTP_BROADCAST 0x8000 |
Referenced by create_msg().
#define DHCP_HLEN_ETHERNET 6 |
#define DHCP_HTYPE_ETHERNET 1 |
Referenced by create_msg().
#define DHCP_MSG_LEN 236 |
#define DHCP_OPTION_DNS_SERVER 6 |
Referenced by add_req_options(), and parse_options().
#define DHCP_OPTION_END 255 |
Referenced by add_end(), msg_for_me(), and parse_options().
#define DHCP_OPTION_LEASE_TIME 51 |
Referenced by parse_options().
#define DHCP_OPTION_MSG_TYPE 53 |
Referenced by add_msg_type(), msg_for_me(), and parse_options().
#define DHCP_OPTION_REQ_IPADDR 50 |
Referenced by add_req_ipaddr().
#define DHCP_OPTION_REQ_LIST 55 |
Referenced by add_req_options().
#define DHCP_OPTION_ROUTER 3 |
Referenced by add_req_options(), and parse_options().
#define DHCP_OPTION_SERVER_ID 54 |
Referenced by add_server_id(), and parse_options().
#define DHCP_OPTION_SUBNET_MASK 1 |
Referenced by add_req_options(), and parse_options().
#define DHCP_REPLY 2 |
Referenced by msg_for_me(), and parse_msg().
#define DHCP_REQUEST 1 |
Referenced by create_msg().
#define DHCPACK 5 |
#define DHCPC_CLIENT_PORT 68 |
Referenced by dhcpc_init().
#define DHCPC_SERVER_PORT 67 |
Referenced by dhcpc_init().
#define DHCPDECLINE 4 |
#define DHCPDISCOVER 1 |
Referenced by send_discover().
#define DHCPNAK 6 |
#define DHCPOFFER 2 |
Referenced by while().
#define DHCPRELEASE 7 |
#define DHCPREQUEST 3 |
Referenced by send_request().
#define IMIN | ( | a, | |
b | |||
) | ((a) < (b) ? (a) : (b)) |
Referenced by while().
#define MAX_TICKS (~((clock_time_t)0) / 2) |
Referenced by while().
#define MAX_TICKS32 (~((uint32_t)0)) |
#define STATE_CONFIG_RECEIVED 3 |
Referenced by if().
#define STATE_INITIAL 0 |
Referenced by dhcpc_init(), and dhcpc_request().
#define STATE_OFFER_RECEIVED 2 |
Referenced by while().
#define STATE_SENDING 1 |
|
static |
References DHCP_OPTION_END.
Referenced by send_discover(), and send_request().
|
static |
References DHCP_OPTION_MSG_TYPE.
Referenced by send_discover(), and send_request().
|
static |
References DHCP_OPTION_REQ_IPADDR, and s.
Referenced by send_request().
|
static |
References DHCP_OPTION_DNS_SERVER, DHCP_OPTION_REQ_LIST, DHCP_OPTION_ROUTER, and DHCP_OPTION_SUBNET_MASK.
Referenced by send_discover().
|
static |
References DHCP_OPTION_SERVER_ID, and s.
Referenced by send_request().
|
static |
References BOOTP_BROADCAST, DHCP_HTYPE_ETHERNET, DHCP_REQUEST, magic_cookie, s, uip_ip6addr_t::u16, uip_hostaddr, UIP_HTONS, and xid.
Referenced by send_discover(), and send_request().
void dhcpc_appcall | ( | process_event_t | ev, |
void * | data | ||
) |
References PROCESS_EVENT_TIMER, and tcpip_event.
void dhcpc_init | ( | const void * | mac_addr, |
int | mac_len | ||
) |
References addr, DHCPC_CLIENT_PORT, DHCPC_SERVER_PORT, mac_addr, NULL, PT_INIT, s, STATE_INITIAL, udp_bind, udp_new(), UIP_HTONS, and uip_ipaddr.
void dhcpc_request | ( | void | ) |
References ipaddr, NULL, PROCESS_EVENT_NONE, s, STATE_INITIAL, uip_ipaddr, and uip_sethostaddr.
if | ( | ev | = = tcpip_event && uip_newdata() && msg_for_me() == DHCPACK | ) |
References parse_msg(), s, and STATE_CONFIG_RECEIVED.
if | ( | s.ticks<=CLOCK_SECOND * | 10 | ) |
References CLOCK_SECOND, and s.
if | ( | (uip_ntohs(s.lease_time[0])*65536ul+uip_ntohs(s.lease_time[1]))*CLOCK_SECOND/2<= | MAX_TICKS32 | ) |
References CLOCK_SECOND, s, and uip_ntohs.
|
static |
References dhcp_msg::chaddr, DHCP_OPTION_END, DHCP_OPTION_MSG_TYPE, DHCP_REPLY, end, dhcp_msg::op, dhcp_msg::options, s, uip_appdata, uip_datalen, dhcp_msg::xid, and xid.
Referenced by while().
|
static |
References dhcp_msg::chaddr, DHCP_REPLY, dhcp_msg::op, dhcp_msg::options, parse_options(), s, uip_appdata, uip_datalen, dhcp_msg::xid, xid, and dhcp_msg::yiaddr.
|
static |
References DHCP_OPTION_DNS_SERVER, DHCP_OPTION_END, DHCP_OPTION_LEASE_TIME, DHCP_OPTION_MSG_TYPE, DHCP_OPTION_ROUTER, DHCP_OPTION_SERVER_ID, DHCP_OPTION_SUBNET_MASK, end, len, and s.
Referenced by parse_msg().
|
static |
References add_end(), add_msg_type(), add_req_options(), create_msg(), DHCPDISCOVER, end, dhcp_msg::options, uip_appdata, and uip_send().
Referenced by while().
|
static |
References add_end(), add_msg_type(), add_req_ipaddr(), add_server_id(), create_msg(), DHCPREQUEST, end, dhcp_msg::options, uip_appdata, and uip_send().
while | ( | 1 | ) |
References CLOCK_SECOND, DHCPOFFER, etimer_expired(), etimer_set(), msg_for_me(), parse_msg(), PT_YIELD, s, send_discover(), STATE_OFFER_RECEIVED, tcpip_event, tcpip_poll_udp(), and uip_newdata.
while | ( | !etimer_expired &. | etimer | ) |
while | ( | s.state! | = STATE_CONFIG_RECEIVED | ) |
while | ( | s. | ticks, |
0 | |||
) |
References etimer_expired(), etimer_set(), IMIN, MAX_TICKS, PT_YIELD_UNTIL, s, and ticks.
while | ( | s.ticks >=CLOCK_SECOND * | 3 | ) |
init __pad0__ |
selecting __pad1__ |
bound __pad2__ |
do |
goto init |
Referenced by http_socket_get(), http_socket_post(), netif_add(), tcp_socket_register(), and udp_socket_register().
|
static |
Referenced by create_msg().
|
static |
s state = STATE_SENDING |
s ticks = CLOCK_SECOND |
|
static |
Referenced by create_msg(), msg_for_me(), and parse_msg().