35 #include "contiki-net.h"
38 #include "net/ip/dhcpc.h"
42 static struct ctk_button requestbutton =
44 static struct ctk_label statuslabel =
46 static struct ctk_label ipaddrlabel =
48 static char ipaddr[16];
49 static struct ctk_textentry ipaddrtextentry =
51 static struct ctk_label netmasklabel =
53 static char netmask[16];
54 static struct ctk_textentry netmasktextentry =
56 static struct ctk_label gatewaylabel =
58 static char gateway[16];
59 static struct ctk_textentry gatewaytextentry =
62 static struct ctk_label dnsserverlabel =
64 static char dnsserver[16];
65 static struct ctk_textentry dnsservertextentry =
68 static struct ctk_button savebutton =
70 static struct ctk_button cancelbutton =
73 PROCESS(ipconfig_process,
"IP config");
75 AUTOSTART_PROCESSES(&ipconfig_process);
79 makebyte(uint8_t byte,
char *str)
82 *str++ = (byte / 100 ) % 10 +
'0';
85 *str++ = (byte / 10) % 10 +
'0';
87 *str++ = (byte % 10) +
'0';
93 makeaddr(uip_ipaddr_t *addr,
char *str)
95 str = makebyte(addr->u8[0], str);
97 str = makebyte(addr->u8[1], str);
99 str = makebyte(addr->u8[2], str);
101 str = makebyte(addr->u8[3], str);
108 uip_ipaddr_t addr, *addrptr;
111 makeaddr(&addr, ipaddr);
114 makeaddr(&addr, netmask);
117 makeaddr(&addr, gateway);
120 addrptr = resolv_getserver();
121 if(addrptr !=
NULL) {
122 makeaddr(addrptr, dnsserver);
128 nullterminate(
char *cptr)
132 for(; *cptr !=
' ' && *cptr != 0; ++cptr);
137 apply_tcpipconfig(
void)
140 int size = cfs_read(file, uip_buf, 100);
143 nullterminate(ipaddr);
146 nullterminate(netmask);
149 nullterminate(gateway);
153 nullterminate(dnsserver);
158 cfs_write(file, uip_buf, size);
163 set_statustext(
char *text)
212 if(ev == PROCESS_EVENT_MSG) {
216 dhcpc_appcall(ev, data);
218 if(data == (process_data_t)&requestbutton) {
220 set_statustext(
"Requesting...");
222 if(data == (process_data_t)&savebutton) {
226 if(data == (process_data_t)&cancelbutton) {
230 #
if CTK_CONF_WINDOWCLOSE
233 ev == PROCESS_EVENT_EXIT) {
242 dhcpc_configured(
const struct dhcpc_state *s)
248 resolv_conf(&s->dnsaddr);
251 set_statustext(
"Configured.");
256 dhcpc_unconfigured(
const struct dhcpc_state *s)
258 static uip_ipaddr_t nulladdr;
264 resolv_conf(&nulladdr);
267 set_statustext(
"Unconfigured.");
#define PROCESS_CURRENT()
Get a pointer to the currently running process.
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
process_event_t ctk_signal_window_close
Emitted when a window is closed.
process_event_t ctk_signal_button_activate
Same as ctk_signal_widget_activate.
#define uip_sethostaddr(addr)
Set the IP address of this host.
#define uip_gethostaddr(addr)
Get the IP address of this host.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
int cfs_open(const char *name, int flags)
Open a file.
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
#define CTK_TEXTENTRY(x, y, w, h, text, len)
Instantiating macro for the ctk_textentry widget.
#define ctk_label_set_text(l, t)
Set the text of a label.
#define NULL
The null pointer.
void ctk_window_redraw(struct ctk_window *w)
Redraw a window.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
#define uip_getdraddr(addr)
Get the default router's IP address.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
#define uip_setdraddr(addr)
Set the default router's IP address.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
#define LOADER_UNLOAD()
Unload a program from memory.
#define uip_getnetmask(addr)
Get the netmask.
#define PROCESS_PAUSE()
Yield the process for a short while.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
process_event_t tcpip_event
The uIP event.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Representation of a CTK window.
#define CTK_WIDGET_REDRAW(widg)
Add a widget to the redraw queue.
#define uip_setnetmask(addr)
Set the netmask.
void process_exit(struct process *p)
Cause a process to exit.
void cfs_close(int fd)
Close an open file.