48 #include <sys/select.h> 52 #include "net/wpcap-drv.h" 67 #if NETSTACK_CONF_WITH_IPV6 73 #define LOG_MODULE "Native" 74 #define LOG_LEVEL LOG_LEVEL_MAIN 87 #ifdef SELECT_CONF_MAX 88 #define SELECT_MAX SELECT_CONF_MAX 97 #ifdef SELECT_CONF_TIMEOUT 98 #define SELECT_TIMEOUT SELECT_CONF_TIMEOUT 100 #define SELECT_TIMEOUT 1000 106 #ifdef SELECT_CONF_STDIN 107 #define SELECT_STDIN SELECT_CONF_STDIN 109 #define SELECT_STDIN 1 114 static const struct select_callback *select_callback[SELECT_MAX];
115 static int select_max = 0;
117 #ifdef PLATFORM_CONF_MAC_ADDR 118 static uint8_t mac_addr[] = PLATFORM_CONF_MAC_ADDR;
120 static uint8_t mac_addr[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
125 select_set_callback(
int fd,
const struct select_callback *callback)
128 if(fd >= 0 && fd < SELECT_MAX) {
130 if(callback != NULL &&
131 (callback->set_fd == NULL || callback->handle_fd == NULL)) {
135 select_callback[fd] = callback;
138 if(callback != NULL) {
139 if(fd > select_max) {
144 for(i = SELECT_MAX - 1; i > 0; i--) {
145 if(select_callback[i] != NULL) {
158 stdin_set_fd(fd_set *rset, fd_set *wset)
160 FD_SET(STDIN_FILENO, rset);
164 stdin_handle_fd(fd_set *rset, fd_set *wset)
167 if(FD_ISSET(STDIN_FILENO, rset)) {
168 if(read(STDIN_FILENO, &c, 1) > 0) {
173 const static struct select_callback stdin_fd = {
174 stdin_set_fd, stdin_handle_fd
183 memset(&addr, 0,
sizeof(linkaddr_t));
184 #if NETSTACK_CONF_WITH_IPV6 185 memcpy(addr.u8, mac_addr,
sizeof(addr.u8));
188 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
189 addr.u8[i] = mac_addr[7 - i];
195 #if NETSTACK_CONF_WITH_IPV6 197 set_global_address(
void)
199 static uip_ipaddr_t
ipaddr;
200 static uip_ipaddr_t *prefix = NULL;
205 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
207 memcpy(&ipaddr, prefix, 8);
213 LOG_INFO(
"Added global IPv6 address ");
214 LOG_INFO_6ADDR(&ipaddr);
218 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 1);
219 uip_ds6_defrt_add(&ipaddr, 0);
223 int contiki_argc = 0;
239 #ifdef UIP_FALLBACK_INTERFACE 265 #if NETSTACK_CONF_WITH_IPV6 270 set_global_address();
275 setvbuf(stdout, (
char *)NULL, _IONBF, 0);
282 select_set_callback(STDIN_FILENO, &stdin_fd);
295 tv.tv_usec = retval ? 1 : SELECT_TIMEOUT;
300 for(i = 0; i <= select_max; i++) {
301 if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
306 retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv);
311 }
else if(retval > 0) {
313 for(i = 0; i <= maxfd; i++) {
314 if(select_callback[i] != NULL) {
315 select_callback[i]->handle_fd(&fdr, &fdw);
327 log_message(
char *m1,
char *m2)
329 fprintf(stderr,
"%s%s\n", m1, m2);
335 fprintf(stderr,
"%s\n", m);
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
uip_lladdr_t uip_lladdr
Host L2 address.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
void platform_main_loop()
The platform's main loop, if provided.
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void leds_init(void)
Initialise the LED HAL.
A set of debugging macros for the IP stack
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
void gpio_hal_init()
Initialise the GPIO HAL.
Header file for IPv6-related data structures.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Header file for the Packet queue buffer management
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
void platform_init_stage_three()
Final stage of platform driver initialisation.
Header file for the uIP TCP/IP stack.
Generic serial I/O process header filer.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the GPIO HAL.
Header file for the logging system
Header file for the LED HAL.
int process_run(void)
Run the system once - call poll handlers and process one event.
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
void process_start(struct process *p, process_data_t data)
Start a process.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.