Microchip® Advanced Software Framework

dhcpc.c File Reference
#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
#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,
 
)    ((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 uint8_t* add_end ( uint8_t *  optptr)
static

References DHCP_OPTION_END.

Referenced by send_discover(), and send_request().

static uint8_t* add_msg_type ( uint8_t *  optptr,
uint8_t  type 
)
static

References DHCP_OPTION_MSG_TYPE.

Referenced by send_discover(), and send_request().

static uint8_t* add_req_ipaddr ( uint8_t *  optptr)
static

References DHCP_OPTION_REQ_IPADDR, and s.

Referenced by send_request().

static uint8_t* add_req_options ( uint8_t *  optptr)
static
static uint8_t* add_server_id ( uint8_t *  optptr)
static

References DHCP_OPTION_SERVER_ID, and s.

Referenced by send_request().

static void create_msg ( CC_REGISTER_ARG struct dhcp_msg m)
static
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 
)
void dhcpc_request ( void  )
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 int msg_for_me ( void  )
static
static uint8_t parse_msg ( void  )
static
static uint8_t parse_options ( uint8_t *  optptr,
int  len 
)
static
static void send_discover ( void  )
static
static void send_request ( void  )
static
while ( !etimer_expired &.  etimer)
while ( s.state!  = STATE_CONFIG_RECEIVED)
while ( s.  ticks,
 
)
while ( s.ticks >=CLOCK_SECOND 3)

init __pad0__
selecting __pad1__
bound __pad2__
do
Initial value:
{
while(ev != tcpip_event) {
PT_YIELD(&s.pt);
}
static void send_request(void)
Definition: dhcpc.c:181
process_event_t tcpip_event
The uIP event.
Definition: wireless/SmartConnect_6LoWPAN/core/net/ip/tcpip.c:77
#define PT_YIELD(pt)
Yield from the current protothread.
Definition: pt.h:289
CCIF void tcpip_poll_udp(struct uip_udp_conn *conn)
Cause a specified UDP connection to be polled.
PSOCK_END & s
Definition: wireless/SmartConnect_6LoWPAN/apps/ip64-webserver/httpd.c:132
else
Initial value:
{
goto init
goto init
Definition: dhcpc.c:392
const uint8_t magic_cookie[4] = {99, 130, 83, 99}
static

Referenced by create_msg().

PT_END& s
static
Initial value:
{
clock_time_t ticks
static volatile uint32_t ticks
Copyright (c) 2015 Microchip Technology Inc and 2012 – 2013, Thingsquare, http://www.thingsquare.com/.
Definition: tc-clock.c:40
s state = STATE_SENDING
s ticks = CLOCK_SECOND
xid
static

Referenced by create_msg(), msg_for_me(), and parse_msg().