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
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
114static const struct select_callback *select_callback[SELECT_MAX];
115static int select_max = 0;
117#ifdef PLATFORM_CONF_MAC_ADDR
118static uint8_t mac_addr[] = PLATFORM_CONF_MAC_ADDR;
120static uint8_t mac_addr[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
125select_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) {
158stdin_set_fd(fd_set *rset, fd_set *wset)
160 FD_SET(STDIN_FILENO, rset);
163static int (*input_handler)(
unsigned char c);
166native_uart_set_input(
int (*
input)(
unsigned char c))
168 input_handler =
input;
171stdin_handle_fd(fd_set *rset, fd_set *wset)
174 if(FD_ISSET(STDIN_FILENO, rset)) {
175 if(read(STDIN_FILENO, &c, 1) > 0) {
180const static struct select_callback stdin_fd = {
181 stdin_set_fd, stdin_handle_fd
190 memset(&
addr, 0,
sizeof(linkaddr_t));
191#if NETSTACK_CONF_WITH_IPV6
192 memcpy(
addr.u8, mac_addr,
sizeof(
addr.u8));
195 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
196 addr.u8[i] = mac_addr[7 - i];
202#if NETSTACK_CONF_WITH_IPV6
204set_global_address(
void)
211 uip_ip6addr_copy(&
ipaddr, default_prefix);
217 LOG_INFO(
"Added global IPv6 address ");
222 uip_ip6addr_copy(&
ipaddr, default_prefix);
224 uip_ds6_defrt_add(&
ipaddr, 0);
244#ifdef UIP_FALLBACK_INTERFACE
267 if(NULL == input_handler) {
276#if NETSTACK_CONF_WITH_IPV6
281 set_global_address();
286 setvbuf(stdout, (
char *)NULL, _IONBF, 0);
293 select_set_callback(STDIN_FILENO, &stdin_fd);
305 tv.tv_sec = retval ? 0 : SELECT_TIMEOUT / 1000;
306 tv.tv_usec = retval ? 1 : (SELECT_TIMEOUT * 1000) % 1000000;
311 for(i = 0; i <= select_max; i++) {
312 if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
317 retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv);
322 }
else if(retval > 0) {
324 for(i = 0; i <= maxfd; i++) {
325 if(select_callback[i] != NULL) {
326 select_callback[i]->handle_fd(&fdr, &fdw);
336log_message(
char *m1,
char *m2)
338 fprintf(stderr,
"%s%s\n", m1, m2);
344 fprintf(stderr,
"%s\n", m);
Header file for the GPIO HAL.
void platform_init_stage_three()
Final stage of platform driver initialisation.
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
void leds_init(void)
Initialise the LED HAL.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void gpio_hal_init()
Initialise the GPIO HAL.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
void platform_main_loop()
The platform's main loop, if provided.
int process_run(void)
Run the system once - call poll handlers and process one event.
void process_start(struct process *p, process_data_t data)
Start a process.
static void input(void)
Process a received 6lowpan packet.
const uip_ip6addr_t * uip_ds6_default_prefix()
Retrieve the Default IPv6 prefix.
uip_lladdr_t uip_lladdr
Host L2 address.
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 uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
Header file for the LED HAL.
Header file for the logging system.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Packet queue buffer management.
Generic serial I/O process header filer.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
A set of debugging macros for the IP stack.
Header file for IPv6-related data structures.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Header file for the uIP TCP/IP stack.