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 static int (*input_handler)(
unsigned char c);
166 void native_uart_set_input(
int (*
input)(
unsigned char c)) {
167 input_handler =
input;
172 stdin_handle_fd(fd_set *rset, fd_set *wset)
175 if(FD_ISSET(STDIN_FILENO, rset)) {
176 if(read(STDIN_FILENO, &c, 1) > 0) {
181 const static struct select_callback stdin_fd = {
182 stdin_set_fd, stdin_handle_fd
191 memset(&addr, 0,
sizeof(linkaddr_t));
192 #if NETSTACK_CONF_WITH_IPV6 193 memcpy(addr.u8, mac_addr,
sizeof(addr.u8));
196 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
197 addr.u8[i] = mac_addr[7 - i];
203 #if NETSTACK_CONF_WITH_IPV6 205 set_global_address(
void)
212 uip_ip6addr_copy(&ipaddr, default_prefix);
218 LOG_INFO(
"Added global IPv6 address ");
219 LOG_INFO_6ADDR(&ipaddr);
223 uip_ip6addr_copy(&ipaddr, default_prefix);
225 uip_ds6_defrt_add(&ipaddr, 0);
229 int contiki_argc = 0;
245 #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);
306 tv.tv_usec = retval ? 1 : SELECT_TIMEOUT;
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);
338 log_message(
char *m1,
char *m2)
340 fprintf(stderr,
"%s%s\n", m1, m2);
346 fprintf(stderr,
"%s\n", m);
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
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.
const uip_ip6addr_t * uip_ds6_default_prefix()
Retrieve the Default IPv6 prefix.
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
static void input(void)
Process a received 6lowpan packet.
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.