示例#1
0
文件: rpl.c 项目: OlegHahm/SAFEST
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 */
}
示例#2
0
文件: rpl.c 项目: nandojve/RIOT
void rpl_udp_init(int argc, char **argv)
{
    transceiver_command_t tcmd;
    msg_t m;
    int32_t chan = UNASSIGNED_CHANNEL;

    if (argc != 2) {
        printf("Usage: %s (r|n|h)\n", argv[0]);
        printf("\tr\tinitialize as root\n");
        printf("\tn\tinitialize as node router\n");
        printf("\th\tinitialize as non-routing node (host-mode)\n");
        return;
    }

    char command = argv[1][0];
    if ((command == 'n') || (command == 'r') || (command == 'h')) {
        printf("INFO: Initialize as %srouting %s on address %d\n",
               ((command == 'h') ? "non-" : ""),
               (((command == 'n') || (command == 'h')) ? "node" : "root"), id);

#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA))
        if (!id || (id > 255)) {
            printf("ERROR: address not a valid 8 bit integer\n");
            return;
        }
#endif

        DEBUGF("Setting HW address to %u\n", id);
        net_if_set_hardware_address(0, id);

        tcmd.transceivers = TRANSCEIVER;
        tcmd.data = &chan;
        m.type = GET_CHANNEL;
        m.content.ptr = (void *) &tcmd;

        msg_send_receive(&m, &m, transceiver_pid);
        if( chan == UNASSIGNED_CHANNEL ) {
            DEBUGF("The channel has not been set yet.");

            /* try to set the channel to 10 (RADIO_CHANNEL) */
            chan = RADIO_CHANNEL;
        }

        m.type = SET_CHANNEL;
        msg_send_receive(&m, &m, transceiver_pid);
        if( chan == UNASSIGNED_CHANNEL ) {
            puts("ERROR: channel NOT set! Aborting initialization.");
            return;
        }

        printf("Channel set to %" PRIi32 "\n", chan);

        /* global address */
        ipv6_addr_t global_addr, global_prefix;
        ipv6_addr_init(&global_prefix, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
        ipv6_addr_set_by_eui64(&global_addr, 0, &global_prefix);

        if (command != 'h') {
            DEBUGF("Initializing RPL for interface 0\n");

            uint8_t state = SIXLOWERROR_VALUE;
            if (command == 'n') {
                /*
                 * no global address specified, we'll use auto address config
                 * initiated by the root node
                 */
                state = rpl_init(0, NULL);
            }
            else if (command == 'r') {
                rpl_options_t rpl_opts = {
                    .instance_id = 0,
                    .prefix = global_prefix,
                    .prefix_len = 64,
                    .prefix_flags = RPL_PREFIX_INFO_AUTO_ADDR_CONF,
                    /* autonomous address-configuration */
                };

                /* use specific global address */
                state = rpl_init(0, &global_addr);
                rpl_init_root(&rpl_opts);
                is_root = 1;
            }

            if (state != SIXLOWERROR_SUCCESS) {
                puts("Error initializing RPL");
            }
            else {
                puts("6LoWPAN and RPL initialized.");
            }

            ipv6_iface_set_routing_provider(rpl_get_next_hop);

        }
示例#3
0
文件: rpl.c 项目: Embedded-linux/RIOT
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 */
}