/*---------------------------------------------------------------------------*/ void uip_ds6_defrt_periodic(void) { uip_ds6_defrt_t *d; d = list_head(defaultrouterlist); while(d != NULL) { if(!d->isinfinite && stimer_expired(&d->lifetime)) { PRINTF("uip_ds6_defrt_periodic: defrt lifetime expired\n"); uip_ds6_defrt_rm(d); d = list_head(defaultrouterlist); } else { d = list_item_next(d); } } }
/* Decrement backoff window for all queues directed at dest_addr */ void tsch_queue_update_all_backoff_windows(const linkaddr_t *dest_addr) { if(!tsch_is_locked()) { int is_broadcast = linkaddr_cmp(dest_addr, &tsch_broadcast_address); struct tsch_neighbor *n = list_head(neighbor_list); while(n != NULL) { if(n->backoff_window != 0 /* Is the queue in backoff state? */ && ((n->tx_links_count == 0 && is_broadcast) || (n->tx_links_count > 0 && linkaddr_cmp(dest_addr, &n->addr)))) { n->backoff_window--; } n = list_item_next(n); } } }
/* Flush all neighbor queues */ void tsch_queue_reset(void) { /* Deallocate unneeded neighbors */ if(!tsch_is_locked()) { struct tsch_neighbor *n = list_head(neighbor_list); while(n != NULL) { struct tsch_neighbor *next_n = list_item_next(n); /* Flush queue */ tsch_queue_flush_nbr_queue(n); /* Reset backoff exponent */ tsch_queue_backoff_reset(n); n = next_n; } } }
/*---------------------------------------------------------------------------*/ static void qsend_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list) { struct rdc_buf_list *curr = buf_list; struct rdc_buf_list *next; int ret; if(curr == NULL) { return; } /* Do not send during reception of a burst */ if(we_are_receiving_burst) { /* Prepare the packetbuf for callback */ queuebuf_to_packetbuf(curr->buf); /* Return COLLISION so the MAC may try again later */ mac_call_sent_callback(sent, ptr, MAC_TX_COLLISION, 1); return; } /* The receiver needs to be awoken before we send */ is_receiver_awake = 0; do { /* A loop sending a burst of packets from buf_list */ next = list_item_next(curr); /* Prepare the packetbuf */ queuebuf_to_packetbuf(curr->buf); if(next != NULL) { packetbuf_set_attr(PACKETBUF_ATTR_PENDING, 1); } /* Send the current packet */ ret = send_packet(sent, ptr, curr); if(ret != MAC_TX_DEFERRED) { mac_call_sent_callback(sent, ptr, ret, 1); } if(ret == MAC_TX_OK) { if(next != NULL) { /* We're in a burst, no need to wake the receiver up again */ is_receiver_awake = 1; curr = next; } } else { /* The transmission failed, we stop the burst */ next = NULL; } } while(next != NULL); is_receiver_awake = 0; }
/*---------------------------------------------------------------------------*/ static int native_config_handler(void* user, const char* section, const char* name, const char* value) { native_config_callback_t *cb; for(cb = list_head(callbacks); cb != NULL; cb = list_item_next(cb)) { if(strcmp(section, cb->section) == 0) { break; } } if(cb) { return cb->callback(*(config_level_t *)user, cb->user, cb->section, name, value); } else { LOG6LBR_WARN("Invalid section : %s\n", section); } return 1; }
/*---------------------------------------------------------------------------*/ struct ip64_addrmap_entry * ip64_addrmap_lookup_port(uint16_t mapped_port, uint8_t protocol) { struct ip64_addrmap_entry *m; check_age(); for(m = list_head(entrylist); m != NULL; m = list_item_next(m)) { printf("mapped port %d %d, protocol %d %d\n", m->mapped_port, mapped_port, m->protocol, protocol); if(m->mapped_port == mapped_port && m->protocol == protocol) { return m; } } return NULL; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(at_test_process, ev, data) { PROCESS_BEGIN(); struct at_cmd *a; /* Initialize the driver, default is UART0 */ at_init(0); /* Register a list of commands, is mandatory to start with "AT" */ at_register(&at_cmd_test, &at_test_process, "AT", 2, 2, at_cmd_test_callback); at_register(&at_cmd_board, &at_test_process, "AT&V", 4, 4, at_cmd_board_callback); at_register(&at_cmd_led, &at_test_process, "AT&LED", 6, 10, at_cmd_leds_callback); at_register(&at_cmd_addr, &at_test_process, "AT&A", 4, 4, at_cmd_address_callback); at_register(&at_cmd_gpio, &at_test_process, "AT&GPIO=", 8, 12, at_cmd_gpio_callback); at_register(&at_cmd_read, &at_test_process, "AT&READ=", 8, 10, at_cmd_read_callback); at_register(&at_cmd_adc, &at_test_process, "AT&ADC=", 7, 8, at_cmd_adc_callback); at_register(&at_cmd_flop, &at_test_process, "AT&FLOP=", 8, 10, at_cmd_flop_callback); at_register(&at_cmd_reset, &at_test_process, "AT&RESET=", 9, 10, at_cmd_reset_callback); at_register(&at_cmd_sha256, &at_test_process, "AT&SHA256=", 10, 64, at_cmd_sha256_callback); /* Print the command list */ PRINTF("AT command list:\n"); for(a = at_list(); a != NULL; a = list_item_next(a)) { PRINTF("* HDR %s LEN %u MAX %u\n", a->cmd_header, a->cmd_hdr_len, a->cmd_max_len); } /* * When an AT command is received over the serial line, the registered * callbacks will be invoked, let the process spin until then */ while(1) { PROCESS_YIELD(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static uip_icmp6_input_handler_t * input_handler_lookup(uint8_t type, uint8_t icode) { uip_icmp6_input_handler_t *handler = NULL; for(handler = list_head(input_handler_list); handler != NULL; handler = list_item_next(handler)) { if(handler->type == type && (handler->icode == icode || handler->icode == UIP_ICMP6_HANDLER_CODE_ANY)) { return handler; } } return NULL; }
/*---------------------------------------------------------------------------*/ enum cmd_broker_result cmd_broker_publish(void) { enum cmd_broker_result result; struct cmd_broker_subscription *subscription; uint8_t *payload; payload = (uint8_t *)packetbuf_dataptr(); subscription = list_head(subscriptions_list); while(subscription) { if(((result = subscription->on_command(payload[0], payload + 1)))) { return result; } subscription = list_item_next(subscription); } return CMD_BROKER_UNCONSUMED; }
static void call_route_callback(int event, uip_ipaddr_t *route, uip_ipaddr_t *nexthop) { int num; struct uip_ds6_notification *n; for(n = list_head(notificationlist); n != NULL; n = list_item_next(n)) { if(event == UIP_DS6_NOTIFICATION_DEFRT_ADD || event == UIP_DS6_NOTIFICATION_DEFRT_RM) { num = list_length(defaultrouterlist); } else { num = num_routes; } n->callback(event, route, nexthop, num); } }
/*---------------------------------------------------------------------------*/ static void check_age(void) { struct ip64_addrmap_entry *m; /* Walk through the list of address mappings, throw away the ones that are too old. */ m = list_head(entrylist); while(m != NULL) { if(timer_expired(&m->timer)) { list_remove(entrylist, m); memb_free(&entrymemb, m); m = list_head(entrylist); } else { m = list_item_next(m); } } }
/*---------------------------------------------------------------------------*/ void print_routingtable(struct routingtable *t) { struct routingtable_item *i; uint8_t numItems = 0; uint8_t count = 1; numItems = routingtable_length(t); PRINTF("Routing Table Contents: %d entries found\n", numItems); PRINTF("------------------------------------------------------------\n"); for(i = list_head(*t->list); i != NULL; i = list_item_next(i)) { PRINTF("Routing table item: %d\n", count); PRINTF("neighbor: %d.%d\n", i->neighbor.u8[0], i->neighbor.u8[1]); PRINTF("backpressure: %d\n", i->backpressure); weight_estimator_print_item(t->bcp_connection, i); PRINTF("------------------------------------------------------------\n"); count++; } }
/* Looks within a slotframe for a link with a given timeslot */ struct tsch_link * tsch_schedule_get_link_by_timeslot(struct tsch_slotframe *slotframe, uint16_t timeslot) { if(!tsch_is_locked()) { if(slotframe != NULL) { struct tsch_link *l = list_head(slotframe->links_list); /* Loop over all items. Assume there is max one link per timeslot */ while(l != NULL) { if(l->timeslot == timeslot) { return l; } l = list_item_next(l); } return l; } } return NULL; }
/* Get the index of a neighbor from its link-layer address */ static int index_from_lladdr(const linkaddr_t *lladdr) { nbr_table_key_t *key; /* Allow lladdr-free insertion, useful e.g. for IPv6 ND. * Only one such entry is possible at a time, indexed by linkaddr_null. */ if(lladdr == NULL) { lladdr = &linkaddr_null; } key = list_head(nbr_table_keys); while(key != NULL) { if(lladdr && linkaddr_cmp(lladdr, &key->lladdr)) { return index_from_key(key); } key = list_item_next(key); } return -1; }
int netq_insert_node(netq_t **queue, netq_t *node) { netq_t *p; assert(queue); assert(node); p = (netq_t *)list_head((list_t)queue); while(p && p->t <= node->t) p = list_item_next(p); if (p) list_insert((list_t)queue, p, node); else list_push((list_t)queue, node); return 1; }
/* Deallocate neighbors with empty queue */ void tsch_queue_free_unused_neighbors(void) { /* Deallocate unneeded neighbors */ if(!tsch_is_locked()) { struct tsch_neighbor *n = list_head(neighbor_list); while(n != NULL) { struct tsch_neighbor *next_n = list_item_next(n); /* Queue is empty, no tx link to this neighbor: deallocate. * Always keep time source and virtual broadcast neighbors. */ if(!n->is_broadcast && !n->is_time_source && !n->tx_links_count && tsch_queue_is_empty(n)) { tsch_queue_remove_nbr(n); } n = next_n; } } }
/*---------------------------------------------------------------------------*/ static int num_packets_to_send(void) { #if WITH_PENDING_BROADCAST struct queue_list_item *i; int num = 0; for(i = list_head(queued_packets_list); i != NULL; i = list_item_next(i)) { if(i->broadcast_flag == BROADCAST_FLAG_SEND || i->broadcast_flag == BROADCAST_FLAG_NONE) { ++num; } } return num; #else /* WITH_PENDING_BROADCAST */ return list_length(queued_packets_list); #endif /* WITH_PENDING_BROADCAST */ }
static struct discovery_ipnd_neighbour_list_entry* discovery_ipnd_find_neighbour(const uint32_t eid) { if( discovery_status == 0 ) { // Not initialized yet return NULL; } const linkaddr_t addr = convert_eid_to_rime(eid); for(struct discovery_ipnd_neighbour_list_entry* entry = list_head(neighbour_list); entry != NULL; entry = list_item_next(entry)) { if( linkaddr_cmp(&entry->neighbour, &addr) ) { return entry; } } return NULL; }
/*---------------------------------------------------------------------------*/ static void input(void) { struct rime_sniffer *s; struct channel *c; RIMESTATS_ADD(rx); c = chameleon_parse(); for(s = list_head(sniffers); s != NULL; s = list_item_next(s)) { if(s->input_callback != NULL) { s->input_callback(); } } if(c != NULL) { abc_input(c); } }
/** * \brief Checks if ''neighbours'' is already known * Yes: refresh timestamp * No: Create entry * * \param neighbour Address of the neighbour that should be refreshed * \return <0 error * 0 neighbour not existing * 1 neighbour was updated */ static int discovery_ipnd_refresh_neighbour(const cl_addr_t* const neighbour) { if (neighbour == NULL) { LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_WRN, "called with NULL pointer address."); return -1; } #if DISCOVERY_IPND_WHITELIST > 0 int i; int found = 0; for(i=0; i<DISCOVERY_IPND_WHITELIST; i++) { if( linkaddr_cmp(&discovery_whitelist[i], neighbour) ) { found = 1; break; } } if( !found ) { LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_WRN, "Ignoring peer %u.%u, not on whitelist", neighbour->u8[0], neighbour->u8[1]); return; } #endif if( discovery_status == 0 ) { // Not initialized yet return - 2; } for(struct discovery_ipnd_neighbour_list_entry* entry = list_head(neighbour_list); entry != NULL; entry = list_item_next(entry)) { if( discovery_neighbour_cmp( (struct discovery_neighbour_list_entry*)entry, neighbour ) ) { if (neighbour->isIP) { entry->timestamp_last_ip = clock_seconds(); } else { entry->timestamp_last_lowpan = clock_seconds(); } return 1; } } return 0; }
// ["config_cnf", config_section_0, ...] int convert_cnf_to_py(PyObject** cnf_py, config_cnf_t* cnf) { //Py_ssize_t len = 0; *cnf_py = PyList_New(0); if ( PyList_Append(*cnf_py, PyString_FromString("config_cnf")) ) { return 1; } PyObject* new_section = NULL; config_section_t* curr = list_head(cnf->sections); while(curr != NULL) { if ( convert_section_to_py(&new_section, curr) ) return 1; if ( PyList_Append(*cnf_py, new_section) ) return 2; curr = list_item_next(curr); } return 0; }
/*---------------------------------------------------------------------------*/ static void save_config() { /* Dump current running config to flash */ #if BOARD_SENSORTAG int rv; cc26xx_web_demo_sensor_reading_t *reading = NULL; rv = ext_flash_open(); if(!rv) { printf("Could not open flash to save config\n"); ext_flash_close(); return; } rv = ext_flash_erase(CONFIG_FLASH_OFFSET, sizeof(cc26xx_web_demo_config_t)); if(!rv) { printf("Error erasing flash\n"); } else { cc26xx_web_demo_config.magic = CONFIG_MAGIC; cc26xx_web_demo_config.len = sizeof(cc26xx_web_demo_config_t); cc26xx_web_demo_config.sensors_bitmap = 0; for(reading = list_head(sensor_list); reading != NULL; reading = list_item_next(reading)) { if(reading->publish) { cc26xx_web_demo_config.sensors_bitmap |= (1 << reading->type); } } rv = ext_flash_write(CONFIG_FLASH_OFFSET, sizeof(cc26xx_web_demo_config_t), (uint8_t *)&cc26xx_web_demo_config); if(!rv) { printf("Error saving config\n"); } } ext_flash_close(); #endif }
/*---------------------------------------------------------------------------*/ uip_ipaddr_t * uip_ds6_defrt_choose(void) { uip_ds6_defrt_t *d; uip_ds6_nbr_t *bestnbr; uip_ipaddr_t *addr; addr = NULL; for(d = list_head(defaultrouterlist); d != NULL; d = list_item_next(d)) { PRINTF("Defrt, IP address "); PRINT6ADDR(&d->ipaddr); PRINTF("\n"); bestnbr = uip_ds6_nbr_lookup(&d->ipaddr); if(bestnbr != NULL && bestnbr->state != NBR_INCOMPLETE) { PRINTF("Defrt found, IP address "); PRINT6ADDR(&d->ipaddr); //ADILA EDIT 03/11/14 /*printf("Defrt found "); uip_debug_ipaddr_print(&d->ipaddr); printf(" %d\n", uip_ds6_defrt_ch());*/ //@ //cc2420_set_channel(uip_ds6_defrt_ch()); /* printf("Defrt found, IP address "); uip_debug_ipaddr_print(&d->ipaddr); printf(" OWNCH %d PREVCH %d", uip_ds6_if.addr_list[1].currentCh, uip_ds6_if.addr_list[1].prevCh); printf(" PARENTCH %d\n", d->parentCh); */ //------------------- PRINTF("\n"); return &d->ipaddr; } else { addr = &d->ipaddr; PRINTF("Defrt INCOMPLETE found, IP address "); PRINT6ADDR(&d->ipaddr); PRINTF("\n"); } } return addr; }
/*---------------------------------------------------------------------------*/ uip_ds6_route_t * uip_ds6_route_next(uip_ds6_route_t *r) { if(r != NULL) { uip_ds6_route_t *n = list_item_next(r); if(n != NULL) { return n; } else { struct uip_ds6_route_neighbor_routes *routes; routes = (struct uip_ds6_route_neighbor_routes *) nbr_table_next(nbr_routes, r->routes); if(routes != NULL) { return list_head(routes->route_list); } } } return NULL; }
/*---------------------------------------------------------------------------*/ static void periodic(void *ptr) { struct route_entry *e; for(e = list_head(route_table); e != NULL; e = list_item_next(e)) { e->time++; if(e->time >= max_time) { PRINTF("route periodic: removing entry to %d.%d with nexthop %d.%d and cost %d\n", e->dest.u8[0], e->dest.u8[1], e->nexthop.u8[0], e->nexthop.u8[1], e->cost); list_remove(route_table, e); memb_free(&route_mem, e); } } ctimer_set(&t, CLOCK_SECOND, periodic, NULL); }
/** * \brief Forward a bundle to its destination * \param entry Pointer to the routing entry of the bundle * \return FLOOD_ROUTE_RETURN_OK if queued, FLOOD_ROUTE_RETURN_CONTINUE if not queued and FLOOD_ROUTE_RETURN_FAIL of queue is full */ int routing_chain_forward_directly(struct routing_entry_t * entry) { struct discovery_neighbour_list_entry *nei_l = NULL; linkaddr_t dest_node; int h = 0; /* Who is the destination for this bundle? */ dest_node = convert_eid_to_rime(entry->destination_node); /* First step: check, if the destination is one of our neighbours */ for( nei_l = DISCOVERY.neighbours(); nei_l != NULL; nei_l = list_item_next(nei_l) ) { if( linkaddr_cmp(&nei_l->neighbour, &dest_node) ) { break; } } if( nei_l == NULL ) { return CHAIN_ROUTE_RETURN_CONTINUE; } /* We know the neighbour, send it directly */ LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF, "send bundle %lu to %u.%u directly", entry->bundle_number, nei_l->neighbour.u8[0], nei_l->neighbour.u8[1]); /* Mark bundle as busy */ entry->flags |= ROUTING_FLAG_IN_TRANSIT; /* And queue it for sending */ h = routing_chain_send_bundle(entry->bundle_number, &nei_l->neighbour); if( h < 0 ) { /* Enqueuing bundle failed - unblock it */ entry->flags &= ~ROUTING_FLAG_IN_TRANSIT; /* If sending the bundle fails, all other will likely also fail */ return CHAIN_ROUTE_RETURN_FAIL; } /* We do not want the bundle to be sent to anybody else at the moment, so: */ return CHAIN_ROUTE_RETURN_OK; }
/*---------------------------------------------------------------------------*/ static void load_config() { #if BOARD_SENSORTAG /* Read from flash into a temp buffer */ cc26xx_web_demo_config_t tmp_cfg; cc26xx_web_demo_sensor_reading_t *reading = NULL; int rv = ext_flash_open(); if(!rv) { printf("Could not open flash to load config\n"); ext_flash_close(); return; } rv = ext_flash_read(CONFIG_FLASH_OFFSET, sizeof(tmp_cfg), (uint8_t *)&tmp_cfg); ext_flash_close(); if(!rv) { printf("Error loading config\n"); return; } if(tmp_cfg.magic == CONFIG_MAGIC && tmp_cfg.len == sizeof(tmp_cfg)) { memcpy(&cc26xx_web_demo_config, &tmp_cfg, sizeof(cc26xx_web_demo_config)); } for(reading = list_head(sensor_list); reading != NULL; reading = list_item_next(reading)) { if(cc26xx_web_demo_config.sensors_bitmap & (1 << reading->type)) { reading->publish = 1; } else { reading->publish = 0; snprintf(reading->converted, CC26XX_WEB_DEMO_CONVERTED_LEN, "\"N/A\""); } } #endif }
/** * \brief Marks a neighbour as 'dead' after multiple transmission attempts have failed * \param neighbour Address of the neighbour */ static void discovery_ipnd_delete_neighbour(const cl_addr_t* const neighbour) { struct discovery_ipnd_neighbour_list_entry * entry; if( discovery_status == 0 ) { // Not initialized yet return; } char addr_str[CL_ADDR_STRING_LENGTH]; cl_addr_string(neighbour, addr_str, sizeof(addr_str)); LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_INF, "Neighbour %s disappeared", addr_str); // Tell the CL that this neighbour has disappeared convergence_layer_dgram_neighbour_down(neighbour); for(entry = list_head(neighbour_list); entry != NULL; entry = list_item_next(entry)) { if( discovery_neighbour_cmp((struct discovery_neighbour_list_entry*)entry, neighbour) ) { /* firstly remove the corresponding address type * and check, if there are other adresses */ const uint8_t addr_type = neighbour->isIP ? CL_TYPE_FLAG_DGRAM_UDP : CL_TYPE_FLAG_DGRAM_LOWPAN; entry->addr_type &= ~addr_type; if (entry->addr_type != 0) { /* there are other addresses for this neighbour available. * So do not delete this discovery entry */ return; } // Notify the statistics module statistics_contacts_down(&entry->neighbour, entry->timestamp_last_lowpan - entry->timestamp_discovered); // TODO statistics_contacts_down(&entry->neighbour, entry->timestamp_last_ip - entry->timestamp_discovered); discovery_ipnd_destroy_neighbour(entry); return; } } }
/*---------------------------------------------------------------------------*/ static void remove_worst_parent(rpl_dag_t *dag, rpl_rank_t min_worst_rank) { rpl_parent_t *p, *worst; PRINTF("RPL: Removing the worst parent\n"); /* Find the parent with the highest rank. */ worst = NULL; for(p = list_head(dag->parents); p != NULL; p = list_item_next(p)) { if(p != dag->preferred_parent && (worst == NULL || p->rank > worst->rank)) { worst = p; } } /* Remove the neighbor if its rank is worse than the minimum worst rank. */ if(worst != NULL && worst->rank > min_worst_rank) { rpl_remove_parent(dag, worst); } }
/** * @brief neighs_h2_indirect * @return */ uint8_t neighs_h2_indirect(){ uint8_t frac_neigh = 0; uint16_t t1, t2; struct nodelist_item *lpf = NULL; lpf = list_head(neighs_list); for( ; lpf != NULL ; lpf = list_item_next(lpf)){ /*t1 = lpf->tknown; t2 = lpf->tconfirmed;*/ if ((lpf->hopcount == 2) /*&& ((t2-t1) > 0)*/){ frac_neigh = frac_neigh + 1; } } return frac_neigh; }