/*---------------------------------------------------------------------------*/ void print_addresses(void) { uip_ds6_addr_t *lladdr; printf("link-local IPv6 address: "); lladdr = uip_ds6_get_link_local(-1); if(lladdr != NULL){ print_address(lladdr); printf("\r\n"); } else printf("None\r\n"); printf("global IPv6 address: "); lladdr = uip_ds6_get_global(-1); if(lladdr != NULL){ print_address(lladdr); printf("\r\n"); } else printf("None\r\n"); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(sensortag_process, ev, data) { static struct etimer et; uip_ipaddr_t ipaddr; etimer_set(&et, CLOCK_CONF_SECOND*20); PROCESS_BEGIN(); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) { printf("NO IP \n\r"); } else{ printf("Good \n\r"); } print_local_addresses(); if(uiplib_ipaddrconv("2001:0db8:0002:0000:0000:0000:0000:0002", &ipaddr)){ printf("Get server IP! \n\r"); } /* new connection with remote host */ client_conn = udp_new(&ipaddr, UIP_HTONS(10001), NULL); udp_bind(client_conn, UIP_HTONS(10002)); printf("Connect! \n\r"); init_hdc_reading(NULL); while(1) { PROCESS_YIELD(); if(ev == sensors_event && data == &hdc_1000_sensor) { get_hdc_reading(); } } PROCESS_END(); }
ule6lo_status_t ule6loGI_getIp6addr(ule6lo_ipType_t ipType, ule6lo_ip6addr_t* ipAddr, ule6lo_ipMode_t mode) { ule6lo_status_t status = STATUS_NO_DATA; uip_ds6_addr_t *uip_addr = NULL; uint8_t index=0; switch(ipType) { case IP_ADDRESS_LINK_LOCAL: uip_addr = uip_ds6_get_link_local((int8_t)mode); break; case IP_ADDRESS_GLOBAL: uip_addr = uip_ds6_get_global((int8_t)mode); break; default: break; } if(uip_addr !=NULL) { for(index=0;index<16;index++) { ipAddr->u8[index]=uip_addr->ipaddr.u8[index]; } status = STATUS_SUCCESS; } return status; }
/*---------------------------------------------------------------------------*/ static void timeout_handler(void) { static int seq_id; struct uip_udp_conn *this_conn; leds_on(LEDS_RED); memset(buf, 0, MAX_PAYLOAD_LEN); seq_id++; /* evens / odds */ if(seq_id & 0x01) { this_conn = l_conn; } else { this_conn = g_conn; if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) { return; } } PRINTF("Client to: "); PRINT6ADDR(&this_conn->ripaddr); memcpy(buf, &seq_id, sizeof(seq_id)); PRINTF(" Remote Port %u,", UIP_HTONS(this_conn->rport)); PRINTF(" (msg=0x%04x), %u bytes\n", *(uint16_t *) buf, sizeof(seq_id)); uip_udp_packet_send(this_conn, buf, sizeof(seq_id)); leds_off(LEDS_RED); }
/*---------------------------------------------------------------------------*/ static void ping_parent(void) { if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) { return; } uip_icmp6_send(uip_ds6_defrt_choose(), ICMP6_ECHO_REQUEST, 0, CC26XX_WEB_DEMO_ECHO_REQ_PAYLOAD_LEN); }
static bool get_local_address(struct sol_network_link_addr *addr) { uip_ds6_addr_t *dsaddr; dsaddr = uip_ds6_get_global(-1); if (!dsaddr) dsaddr = uip_ds6_get_link_local(-1); SOL_NULL_CHECK(dsaddr, false); addr->family = SOL_NETWORK_FAMILY_INET6; addr->port = 0; memcpy(&addr->addr.in6, &dsaddr->ipaddr, sizeof(addr->addr.in6)); return true; }
/* --------------------------------------------------------------- */ static void input_handler(char* input) { // If we haven't be able to reach the DAG RPL Router give error if (uip_ds6_get_global(ADDR_PREFERRED) == NULL) { printf("E02\n"); return; } // Send the data with magic uip_udp_packet_send(conn, input, strlen(input)); // Debug messages PRINTF("# %s\n", input); PRINTF("# Sent %u bytes to [", strlen(input)); PRINT6ADDR(&conn->ripaddr); PRINTF("]:%u\n", UIP_HTONS(conn->rport)); }
void xtcpd_get_ipconfig(xtcp_ipconfig_t *ipconfig) { #if UIP_CONF_IPV4 ipconfig->v = 4; memcpy(&ipconfig->ipaddr, &uip_hostaddr, sizeof(xtcp_ipconfig_t)); memcpy(&ipconfig->netmask, &uip_netmask, sizeof(xtcp_ipconfig_t)); memcpy(&ipconfig->gateway, &uip_draddr, sizeof(xtcp_ipconfig_t)); #elif UIP_CONF_IPV6 //TODO CHSC: Implement IPv6 get memset(ipconfig, 0, sizeof(xtcp_ipconfig_t)); ipconfig->v = 6; uip_ds6_addr_t *temp_uip_ds6_addr; temp_uip_ds6_addr = uip_ds6_get_global(-1); if(temp_uip_ds6_addr != NULL) memcpy(&ipconfig->ipaddr, &temp_uip_ds6_addr->ipaddr, sizeof(uip_ipaddr_t)); /* dump uip_ds6_if */ PRINTF("Dump uip_ds6_if:\n"); PRINTF(" link_mtu: %i\n", uip_ds6_if.link_mtu); PRINTF(" cur_hop_limit: %i\n", uip_ds6_if.cur_hop_limit); PRINTF(" base_reachable_time: %i\n", uip_ds6_if.base_reachable_time); PRINTF(" reachable_time: %i\n", uip_ds6_if.reachable_time); PRINTF(" retrans_timer: %i\n", uip_ds6_if.retrans_timer); PRINTF(" maxdadns: %i\n", uip_ds6_if.maxdadns); PRINTF("--ADDR LIST\n"); for(int i=0; i<UIP_DS6_ADDR_NB; i++){ PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); PRINTF(" is used: %s\n", uip_ds6_if.addr_list[i].isused ? "yes" : "no"); } PRINTF("--AADDR LIST\n"); for(int i=0; i<UIP_DS6_AADDR_NB; i++){ PRINT6ADDR(&uip_ds6_if.aaddr_list[i].ipaddr); PRINTF(" is used: %s\n", uip_ds6_if.aaddr_list[i].isused ? "yes" : "no"); } PRINTF("--MADDR LIST\n"); for(int i=0; i<UIP_DS6_MADDR_NB; i++){ PRINT6ADDR(&uip_ds6_if.maddr_list[i].ipaddr); PRINTF(" is used: %s\n", uip_ds6_if.maddr_list[i].isused ? "yes" : "no"); } #endif }
void create_dag() { rpl_dag_t *dag; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); print_local_addresses(); dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &uip_ds6_get_global(ADDR_PREFERRED)->ipaddr); if(dag != NULL) { uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); rpl_set_prefix(dag, &ipaddr, 64); PRINTF("Created a new RPL dag with ID: "); PRINT6ADDR(&dag->dag_id); PRINTF("\n"); } }
void create_dag() { uip_ipaddr_t ipaddr; rpl_dag_t* dag; // Create dag dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &uip_ds6_get_global(ADDR_PREFERRED)->ipaddr); if(dag == NULL) { printf("E03\n"); return; } // Set the network prefix uip_ip6addr(&ipaddr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0); rpl_set_prefix(dag, &ipaddr, 64); PRINTF("# Created a new RPL dag with ID: "); PRINT6ADDR(&dag->dag_id); PRINTF("\n"); }
void uip_ds6_br_config() { /* default value of 10,000 (~one week) */ locbr = uip_ds6_br_add(0, 0x0, &uip_ds6_get_global(ADDR_PREFERRED)->ipaddr); /* link all context to border router */ for(loccontext = uip_ds6_context_pref_list; loccontext < uip_ds6_context_pref_list + UIP_DS6_CONTEXT_PREF_NB; loccontext++) { if(loccontext->state != CONTEXT_PREF_ST_FREE) { loccontext->br = locbr; } } /* link all prefixes to border router */ for(locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if(locprefix->isused) { locprefix->br = locbr; } } }
/*---------------------------------------------------------------------------*/ void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst) { uint8_t best = 0; /* number of bit in common with best match */ uint8_t n = 0; uip_ds6_addr_t *matchaddr = NULL; if(!uip_is_addr_link_local(dst) && !uip_is_addr_mcast(dst)) { /* find longest match */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { /* Only preferred global (not link-local) addresses */ if(locaddr->isused && locaddr->state == ADDR_PREFERRED && !uip_is_addr_link_local(&locaddr->ipaddr)) { n = get_match_length(dst, &locaddr->ipaddr); if(n >= best) { best = n; matchaddr = locaddr; } } } #if UIP_IPV6_MULTICAST } else if(uip_is_addr_mcast_routable(dst)) { matchaddr = uip_ds6_get_global(ADDR_PREFERRED); #endif } else { matchaddr = uip_ds6_get_link_local(ADDR_PREFERRED); } /* use the :: (unspecified address) as source if no match found */ if(matchaddr == NULL) { uip_create_unspecified(src); } else { uip_ipaddr_copy(src, &matchaddr->ipaddr); } }
/*---------------------------------------------------------------------------*/ static void state_machine(void) { switch(state) { case MQTT_CLIENT_STATE_INIT: /* If we have just been configured register MQTT connection */ mqtt_register(&conn, &mqtt_client_process, client_id, mqtt_event, MQTT_CLIENT_MAX_SEGMENT_SIZE); /* * Authentication: provide user name and password */ if(strlen(conf->auth_token) > 0) { mqtt_set_username_password(&conn, "use-token-auth", conf->auth_token); } /* _register() will set auto_reconnect. We don't want that. */ conn.auto_reconnect = 0; connect_attempt = 1; /* * Wipe out the default route so we'll republish it every time we switch to * a new broker */ memset(&def_route, 0, sizeof(def_route)); state = MQTT_CLIENT_STATE_REGISTERED; DBG("Init\n"); /* Continue */ case MQTT_CLIENT_STATE_REGISTERED: if(uip_ds6_get_global(ADDR_PREFERRED) != NULL) { /* Registered and with a public IP. Connect */ DBG("Registered. Connect attempt %u\n", connect_attempt); ping_parent(); connect_to_broker(); } etimer_set(&publish_periodic_timer, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC); return; break; case MQTT_CLIENT_STATE_CONNECTING: leds_on(CC26XX_WEB_DEMO_STATUS_LED); ctimer_set(&ct, CONNECTING_LED_DURATION, publish_led_off, NULL); /* Not connected yet. Wait */ DBG("Connecting (%u)\n", connect_attempt); break; case MQTT_CLIENT_STATE_CONNECTED: /* Don't subscribe unless we are a registered device if(strncasecmp(conf->org_id, QUICKSTART, strlen(conf->org_id)) == 0) { DBG("Using 'quickstart': Skipping subscribe\n"); state = MQTT_CLIENT_STATE_PUBLISHING; }*/ /* Continue */ case MQTT_CLIENT_STATE_PUBLISHING: /* If the timer expired, the connection is stable. */ if(timer_expired(&connection_life)) { /* * Intentionally using 0 here instead of 1: We want RECONNECT_ATTEMPTS * attempts if we disconnect after a successful connect */ connect_attempt = 0; } if(mqtt_ready(&conn) && conn.out_buffer_sent) { /* Connected. Publish */ if(state == MQTT_CLIENT_STATE_CONNECTED) { subscribe(); state = MQTT_CLIENT_STATE_PUBLISHING; } else { leds_on(CC26XX_WEB_DEMO_STATUS_LED); ctimer_set(&ct, PUBLISH_LED_ON_DURATION, publish_led_off, NULL); publish(); } etimer_set(&publish_periodic_timer, conf->pub_interval); DBG("Publishing\n"); /* Return here so we don't end up rescheduling the timer */ return; } else { /* * Our publish timer fired, but some MQTT packet is already in flight * (either not sent at all, or sent but not fully ACKd). * * This can mean that we have lost connectivity to our broker or that * simply there is some network delay. In both cases, we refuse to * trigger a new message and we wait for TCP to either ACK the entire * packet after retries, or to timeout and notify us. */ DBG("Publishing... (MQTT state=%d, q=%u)\n", conn.state, conn.out_queue_full); } break; case MQTT_CLIENT_STATE_DISCONNECTED: DBG("Disconnected\n"); if(connect_attempt < RECONNECT_ATTEMPTS || RECONNECT_ATTEMPTS == RETRY_FOREVER) { /* Disconnect and backoff */ clock_time_t interval; mqtt_disconnect(&conn); connect_attempt++; interval = connect_attempt < 3 ? RECONNECT_INTERVAL << connect_attempt : RECONNECT_INTERVAL << 3; DBG("Disconnected. Attempt %u in %lu ticks\n", connect_attempt, interval); etimer_set(&publish_periodic_timer, interval); state = MQTT_CLIENT_STATE_REGISTERED; return; } else { /* Max reconnect attempts reached. Enter error state */ state = MQTT_CLIENT_STATE_ERROR; DBG("Aborting connection after %u attempts\n", connect_attempt - 1); } break; case MQTT_CLIENT_STATE_NEWCONFIG: /* Only update config after we have disconnected */ if(conn.state == MQTT_CONN_STATE_NOT_CONNECTED) { update_config(); DBG("New config\n"); /* update_config() scheduled next pass. Return */ return; } break; case MQTT_CLIENT_STATE_CONFIG_ERROR: /* Idle away. The only way out is a new config */ printf("Bad configuration.\n"); return; case MQTT_CLIENT_STATE_ERROR: default: leds_on(CC26XX_WEB_DEMO_STATUS_LED); /* * 'default' should never happen. * * If we enter here it's because of some error. Stop timers. The only thing * that can bring us out is a new config event */ printf("Default case: State=0x%02x\n", state); return; } /* If we didn't return so far, reschedule ourselves */ etimer_set(&publish_periodic_timer, STATE_MACHINE_PERIODIC); }
/*---------------------------------------------------------------------------*/ static void timeout_handler(void) { static int seq_id; char buf[MAX_PAYLOAD_LEN]; int i; uip_ip6addr_t *globaladdr = NULL; uint16_t dest_port = CETIC_6LBR_NODE_INFO_PORT; int has_dest = 0; rpl_dag_t *dag; uip_ds6_addr_t *addr_desc = uip_ds6_get_global(ADDR_PREFERRED); if(addr_desc != NULL) { globaladdr = &addr_desc->ipaddr; dag = rpl_get_any_dag(); if(dag) { uip_ipaddr_copy(&dest_addr, globaladdr); memcpy(&dest_addr.u8[8], &dag->dag_id.u8[8], sizeof(uip_ipaddr_t) / 2); has_dest = 1; } } if(has_dest) { if(client_conn == NULL) { PRINTF("UDP-CLIENT: address destination: "); PRINT6ADDR(&dest_addr); PRINTF("\n"); client_conn = udp_new(&dest_addr, UIP_HTONS(dest_port), NULL); if(client_conn != NULL) { PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); } else { PRINTF("Could not open connection\n"); } } else { if(memcmp(&client_conn->ripaddr, &dest_addr, sizeof(uip_ipaddr_t)) != 0) { PRINTF("UDP-CLIENT: new address destination: "); PRINT6ADDR(&dest_addr); PRINTF("\n"); uip_udp_remove(client_conn); client_conn = udp_new(&dest_addr, UIP_HTONS(dest_port), NULL); if(client_conn != NULL) { PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); } else { PRINTF("Could not open connection\n"); } } } if(client_conn != NULL) { PRINTF("Client sending to: "); PRINT6ADDR(&client_conn->ripaddr); i = sprintf(buf, "%d | ", ++seq_id); dag = rpl_get_any_dag(); if(dag && dag->instance->def_route) { add_ipaddr(buf + i, &dag->instance->def_route->ipaddr); } else { sprintf(buf + i, "(null)"); } PRINTF(" (msg: %s)\n", buf); uip_udp_packet_send(client_conn, buf, strlen(buf)); } else { PRINTF("No connection created\n"); } } else { PRINTF("No address configured\n"); } }
static void timeout_handler(void) { static int seq_id; char buf[MAX_PAYLOAD_LEN]; int i; uip_ipaddr_t *globaladdr = NULL; uip_ipaddr_t newdest_addr; uint16_t dest_port = use_user_dest_addr ? user_dest_port : 3000; int has_dest=0; if ( use_user_dest_addr ) { uip_ipaddr_copy(&newdest_addr, &user_dest_addr); has_dest=1; } else if((globaladdr = &uip_ds6_get_global(-1)->ipaddr) != NULL) { #if UIP_CONF_IPV6_RPL rpl_dag_t *dag = rpl_get_any_dag(); uip_ipaddr_copy(&newdest_addr, globaladdr); memcpy(&newdest_addr.u8[8], &dag->dag_id.u8[8], sizeof(uip_ipaddr_t) / 2); has_dest = dag == NULL ? 0 : 1; #else uip_ipaddr_t * defrt = uip_ds6_defrt_choose(); if ( defrt != NULL ) { uip_ipaddr_copy(&newdest_addr, defrt); has_dest=1; } #endif } if (client_conn == NULL) { if (has_dest) { /* At least one prefix announced : building of the global address to reach using prefixes */ memcpy(dest_addr, &newdest_addr, sizeof(uip_ipaddr_t)); PRINTF("UDP-CLIENT: address destination: "); PRINT6ADDR(dest_addr); PRINTF("\n"); client_conn = udp_new(dest_addr, UIP_HTONS(dest_port), NULL); udp_bind(client_conn, UIP_HTONS(3001)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); print_local_addresses(); } else { PRINTF("No address configured yet\n"); } } if (client_conn != NULL) { if(memcmp(&client_conn->ripaddr, &newdest_addr, sizeof(uip_ipaddr_t)) != 0) { PRINTF("UPD-CLIENT : new address, connection changed\n"); memcpy(dest_addr, &newdest_addr, sizeof(uip_ipaddr_t)); client_conn = udp_new(dest_addr, UIP_HTONS(3000), NULL); udp_bind(client_conn, UIP_HTONS(3001)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); print_local_addresses(); } if ( udp_client_run ) { PRINTF("Client sending to: "); PRINT6ADDR(&client_conn->ripaddr); i = sprintf(buf, "%d | ", ++seq_id); #if UIP_CONF_IPV6_RPL rpl_dag_t *dag = rpl_get_any_dag(); add_ipaddr(buf + i, &dag->instance->def_route->ipaddr); #endif PRINTF(" (msg: %s)\n", buf); #if SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION uip_udp_packet_send(client_conn, buf, UIP_APPDATA_SIZE); #else /* SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION */ uip_udp_packet_send(client_conn, buf, strlen(buf)); #endif /* SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION */ } } }
struct net_context *net_context_get(enum ip_protocol ip_proto, const struct net_addr *remote_addr, uint16_t remote_port, struct net_addr *local_addr, uint16_t local_port) { #ifdef CONFIG_NETWORKING_WITH_IPV6 const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; const uip_ds6_addr_t *uip_addr; uip_ipaddr_t ipaddr; #endif int i; struct net_context *context = NULL; /* User must provide storage for the local address. */ if (!local_addr) { return NULL; } #ifdef CONFIG_NETWORKING_WITH_IPV6 if (memcmp(&local_addr->in6_addr, &in6addr_any, sizeof(in6addr_any)) == 0) { uip_addr = uip_ds6_get_global(-1); if (!uip_addr) { uip_addr = uip_ds6_get_link_local(-1); } if (!uip_addr) { return NULL; } memcpy(&local_addr->in6_addr, &uip_addr->ipaddr, sizeof(struct in6_addr)); } #else if (local_addr->in_addr.s_addr == INADDR_ANY) { uip_gethostaddr((uip_ipaddr_t *)&local_addr->in_addr); } #endif nano_sem_take(&contexts_lock, TICKS_UNLIMITED); if (local_port) { if (context_port_used(ip_proto, local_port, local_addr) < 0) { return NULL; } } else { do { local_port = random_rand() | 0x8000; } while (context_port_used(ip_proto, local_port, local_addr) == -EEXIST); } for (i = 0; i < NET_MAX_CONTEXT; i++) { if (!contexts[i].tuple.ip_proto) { contexts[i].tuple.ip_proto = ip_proto; contexts[i].tuple.remote_addr = (struct net_addr *)remote_addr; contexts[i].tuple.remote_port = remote_port; contexts[i].tuple.local_addr = (struct net_addr *)local_addr; contexts[i].tuple.local_port = local_port; context = &contexts[i]; break; } } context_sem_give(&contexts_lock); /* Set our local address */ #ifdef CONFIG_NETWORKING_WITH_IPV6 memcpy(&ipaddr.u8, local_addr->in6_addr.s6_addr, sizeof(ipaddr.u8)); if (uip_is_addr_mcast(&ipaddr)) { uip_ds6_maddr_add(&ipaddr); } else { uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL); } #endif return context; }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(void) { #if CONF_6LOWPAN_ND_OPTI_START && UIP_CONF_6L_ROUTER /* Start RPL only when the device has global IPv6 */ if(!rpl_started && uip_ds6_get_global(ADDR_PREFERRED)) { rpl_init(); rpl_started = 1; } #endif /* CONF_6LOWPAN_ND_OPTI_START && UIP_CONF_6L_ROUTER */ /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); #if UIP_ND6_DEF_MAXDADNS > 0 } else if((locaddr->state == ADDR_TENTATIVE) && (locaddr->dadnscount <= uip_ds6_if.maxdadns) && (timer_expired(&locaddr->dadtimer)) && (uip_len == 0)) { uip_ds6_dad(locaddr); #endif /* UIP_ND6_DEF_MAXDADNS > 0 */ } } } /* Periodic processing on default routers */ uip_ds6_defrt_periodic(); /* for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite) && (stimer_expired(&(locdefrt->lifetime)))) { uip_ds6_defrt_rm(locdefrt); } }*/ #if CONF_6LOWPAN_ND /* Periodic processing on context prefixes */ for(loccontext = uip_ds6_context_pref_list; loccontext < uip_ds6_context_pref_list + UIP_DS6_CONTEXT_PREF_NB; loccontext++) { if(loccontext->state != CONTEXT_PREF_ST_FREE) { #if UIP_CONF_6LBR if(stimer_expired(&loccontext->lifetime) && loccontext->br->state != BR_ST_NEW_VERSION) { switch(loccontext->state) { case CONTEXT_PREF_ST_RM: /* Valid lifetime expired, so remove */ loccontext->state = CONTEXT_PREF_ST_FREE; break; case CONTEXT_PREF_ST_ADD: /* before c=0, now c=1 */ loccontext->state = CONTEXT_PREF_ST_COMPRESS; stimer_set(&loccontext->lifetime, loccontext->vlifetime * 60); break; } } #else /* UIP_CONF_6LBR */ if(stimer_expired(&loccontext->lifetime)) { switch(loccontext->state) { case CONTEXT_PREF_ST_UNCOMPRESSONLY: case CONTEXT_PREF_ST_RM: /* Valid lifetime expired, so remove */ loccontext->state = CONTEXT_PREF_ST_FREE; break; case CONTEXT_PREF_ST_SENDING: /* receive-only mode for a period of twice the default Router Lifetime */ loccontext->state = CONTEXT_PREF_ST_UNCOMPRESSONLY; stimer_set(&loccontext->lifetime, loccontext->router_lifetime * 2); break; case CONTEXT_PREF_ST_ADD: /* before c=0, now c=1 */ loccontext->state = CONTEXT_PREF_ST_COMPRESS; stimer_set(&loccontext->lifetime, loccontext->vlifetime * 60); break; } } else if(is_timeout_percent(&loccontext->lifetime, UIP_DS6_RS_PERCENT_LIFETIME_RETRAN, UIP_DS6_RS_MINLIFETIME_RETRAN) && loccontext->state == CONTEXT_PREF_ST_COMPRESS) { if(loccontext->br->state != BR_ST_SENDING_RS) { loccontext->br->state = BR_ST_MUST_SEND_RS; } loccontext->state = CONTEXT_PREF_ST_SENDING; } #endif /* UIP_CONF_6LBR */ } } #endif /* CONF_6LOWPAN_ND */ #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for(locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if(locprefix->isused && !locprefix->isinfinite) { if(stimer_expired(&(locprefix->vlifetime))) { uip_ds6_prefix_rm(locprefix); #if UIP_CONF_6LR || UIP_CONF_6LN } else if(is_timeout_percent(&locprefix->vlifetime, UIP_DS6_RS_PERCENT_LIFETIME_RETRAN, UIP_DS6_RS_MINLIFETIME_RETRAN)) { if(locprefix->br->state != BR_ST_SENDING_RS) { locprefix->br->state = BR_ST_MUST_SEND_RS; } #endif /* UIP_CONF_6LR || UIP_CONF_6LN */ } } } #endif /* !UIP_CONF_ROUTER */ /* Periodic processing on border router */ #if CONF_6LOWPAN_ND uip_ds6_br_periodic(); #endif /* CONF_6LOWPAN_ND */ /* Periodic processing on Duplication Address*/ #if UIP_CONF_6LBR for(locdad = uip_ds6_dup_addr_list; locdad < uip_ds6_dup_addr_list + UIP_DS6_DUPADDR_NB; locdad++) { if(locdad->isused && stimer_expired(&locdad->lifetime)) { uip_ds6_dup_addr_rm(locdad); } } #endif /* UIP_CONF_6LBR */ uip_ds6_neighbor_periodic(); #if UIP_CONF_ROUTER & UIP_ND6_SEND_RA #if !CONF_6LOWPAN_ND || UIP_ND6_RA_PERIODIC /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) { uip_ds6_send_ra_periodic(); } #endif /* !CONF_6LOWPAN_ND || UIP_ND6_RA_PERIODIC */ #endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }