int main(void) { puts("RIOT 6LoWPAN example v"APP_VERSION); sixlowpan_lowpan_init_interface(IF_ID); /* start thread for monitor mode */ kernel_pid_t monitor_pid = thread_create(monitor_stack_buffer, sizeof(monitor_stack_buffer), PRIORITY_MAIN - 2, CREATE_STACKTEST, sixlowapp_monitor, NULL, "monitor"); ipv6_register_packet_handler(monitor_pid); /* Start the UDP server thread */ sixlowapp_udp_server_pid = thread_create(udp_server_stack_buffer, sizeof(udp_server_stack_buffer), PRIORITY_MAIN, CREATE_STACKTEST, sixlowapp_udp_server_loop, NULL, "UDP receiver"); /* Open the UART0 for the shell */ posix_open(uart0_handler_pid, 0); /* initialize the shell */ shell_t shell; shell_init(&shell, shell_commands, UART0_BUFSIZE, uart0_readc, uart0_putc); /* start the shell loop */ shell_run(&shell); return 0; }
void init(char *str) { transceiver_command_t tcmd; msg_t m; uint8_t chan = RADIO_CHANNEL; char command; int res = sscanf(str, "init %c", &command); if (res < 1) { printf("Usage: init (r|n)\n"); printf("\tr\tinitialize as root\n"); printf("\tn\tinitialize as node router\n"); } uint8_t state; if ((command == 'n') || (command == 'r')) { printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id); if (!id || (id > 255)) { printf("ERROR: address not a valid 8 bit integer\n"); return; } state = rpl_init(TRANSCEIVER, id); if (state != SIXLOWERROR_SUCCESS) { printf("Error initializing RPL\n"); } else { puts("6LoWPAN and RPL initialized."); } if (command == 'r') { rpl_init_root(); is_root = 1; } else { ipv6_iface_set_routing_provider(rpl_get_next_hop); } int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, monitor, "monitor"); transceiver_register(TRANSCEIVER, monitor_pid); ipv6_register_packet_handler(monitor_pid); //sixlowpan_lowpan_register(monitor_pid); } else { printf("ERROR: Unknown command '%c'\n", command); return; } /* TODO: check if this works as intended */ ipv6_addr_t prefix, tmp; ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id); ipv6_addr_init_prefix(&prefix, &std_addr, 64); plist_add(&prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE, 0, 1, ICMPV6_NDP_OPT_PI_FLAG_AUTONOM); ipv6_init_iface_as_router(); /* add global address */ ipv6_addr_set_by_eui64(&tmp, &std_addr); ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_GLOBAL, NDP_ADDR_STATE_PREFERRED, 0, 0); /* set channel to 10 */ tcmd.transceivers = TRANSCEIVER; tcmd.data = &chan; m.type = SET_CHANNEL; m.content.ptr = (void *) &tcmd; msg_send_receive(&m, &m, transceiver_pid); printf("Channel set to %u\n", RADIO_CHANNEL); destiny_init_transport_layer(); puts("Destiny initialized"); /* start transceiver watchdog */ }
void rpl_udp_init(int argc, char **argv) { transceiver_command_t tcmd; msg_t m; uint8_t chan = RADIO_CHANNEL; if (argc != 2) { printf("Usage: %s (r|n)\n", argv[0]); printf("\tr\tinitialize as root\n"); printf("\tn\tinitialize as node router\n"); return; } uint8_t state; char command = argv[1][0]; if ((command == 'n') || (command == 'r')) { printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id); if (!id || (id > 255)) { printf("ERROR: address not a valid 8 bit integer\n"); return; } DEBUGF("Setting HW address to %u\n", id); net_if_set_hardware_address(0, id); DEBUGF("Initializing RPL for interface 0\n"); state = rpl_init(0); if (state != SIXLOWERROR_SUCCESS) { printf("Error initializing RPL\n"); } else { puts("6LoWPAN and RPL initialized."); } if (command == 'r') { rpl_init_root(); is_root = 1; } else { ipv6_iface_set_routing_provider(rpl_get_next_hop); } DEBUGF("Start monitor\n"); int monitor_pid = thread_create( monitor_stack_buffer, sizeof(monitor_stack_buffer), PRIORITY_MAIN - 2, CREATE_STACKTEST, rpl_udp_monitor, NULL, "monitor"); DEBUGF("Register at transceiver %02X\n", TRANSCEIVER); transceiver_register(TRANSCEIVER, monitor_pid); ipv6_register_packet_handler(monitor_pid); //sixlowpan_lowpan_register(monitor_pid); } else { printf("ERROR: Unknown command '%c'\n", command); return; } /* TODO: check if this works as intended */ ipv6_addr_t prefix, tmp; ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id); ipv6_addr_init_prefix(&prefix, &std_addr, 64); ndp_add_prefix_info(0, &prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE, NDP_OPT_PI_PLIFETIME_INFINITE, 1, ICMPV6_NDP_OPT_PI_FLAG_AUTONOM); ipv6_init_as_router(); /* add global address */ ipv6_addr_set_by_eui64(&tmp, 0, &std_addr); ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0); /* set channel to 10 */ tcmd.transceivers = TRANSCEIVER; tcmd.data = &chan; m.type = SET_CHANNEL; m.content.ptr = (void *) &tcmd; msg_send_receive(&m, &m, transceiver_pid); printf("Channel set to %u\n", RADIO_CHANNEL); puts("Destiny initialized"); /* start transceiver watchdog */ }