Esempio n. 1
0
File: main.c Progetto: Rossano/RIOT
int test_net_if_get_set_hardware_address(int iface, uint16_t addr)
{
    uint16_t tmp;

    if (net_if_set_hardware_address(iface + 1, addr)) {
        printf("FAILED: expected net_if_set_hardware_address(%d, %d) to fail.\n",
               iface + 1, addr);
        return 0;
    }

    if (net_if_set_hardware_address(iface, 0)) {
        printf("FAILED: expected net_if_set_hardware_address(%d, 0) to fail.\n",
               iface);
        return 0;
    }

    tmp = net_if_set_hardware_address(iface, addr);

    if (addr != tmp) {
        printf("FAILED: Expected '%d' as result of net_if_set_hardware_addr() "
               "(was '%d')\n", addr, tmp);
        return 0;
    }

    tmp = net_if_get_hardware_address(iface);

    if (addr != tmp) {
        printf("FAILED: Expected '%d' as result of net_if_get_hardware_addr() "
               "(was '%d')\n", addr, tmp);
        return 0;
    }

    return 1;
}
Esempio n. 2
0
File: main.c Progetto: 4120976/RIOT
int init_local_address(uint16_t r_addr)
{
    ipv6_addr_t std_addr;
    ipv6_addr_init(&std_addr, 0xabcd, 0xef12, 0, 0, 0x1034, 0x00ff, 0xfe00,
                   0);
    net_if_set_src_address_mode(0, NET_IF_TRANS_ADDR_M_SHORT);
    return net_if_set_hardware_address(0, r_addr) &&
           sixlowpan_lowpan_init_adhoc_interface(0, &std_addr);
}
Esempio n. 3
0
File: rpl.c Progetto: 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);

        }
Esempio n. 4
0
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 */
}