Exemplo n.º 1
0
int main(void)
{
    tlsf_create_with_pool(_tlsf_heap, sizeof(_tlsf_heap));
    msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);

    puts("Basic CCN-Lite example");

    ccnl_core_init();

    ccnl_start();

    /* get the default interface */
    gnrc_netif_t *netif = gnrc_netif_iter(NULL);

    /* set the relay's PID, configure the interface to interface to use CCN
     * nettype */
    if ((netif == NULL) || (ccnl_open_netif(netif->pid, GNRC_NETTYPE_CCN) < 0)) {
        puts("Error registering at network interface!");
        return -1;
    }

    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
    return 0;
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: A-Paul/RIOT
static int _list_all_inet6(int argc, char **argv)
{
    (void)argc;
    (void)argv;
    gnrc_netif_t *netif = NULL;
    unsigned addr_qty = 0;

    while ((netif = gnrc_netif_iter(netif))) {
        ipv6_addr_t ipv6_addrs[GNRC_NETIF_IPV6_ADDRS_NUMOF];

        int res = gnrc_netapi_get(netif->pid, NETOPT_IPV6_ADDR, 0, ipv6_addrs,
                                  sizeof(ipv6_addrs));
        if (res >= 0) {
            uint8_t ipv6_addrs_flags[GNRC_NETIF_IPV6_ADDRS_NUMOF];

            memset(ipv6_addrs_flags, 0, sizeof(ipv6_addrs_flags));
            /* assume it to succeed (otherwise array will stay 0) */
            gnrc_netapi_get(netif->pid, NETOPT_IPV6_ADDR_FLAGS, 0,
                            ipv6_addrs_flags, sizeof(ipv6_addrs_flags));
            /* yes, the res of NETOPT_IPV6_ADDR is meant to be here ;-) */
            for (unsigned i = 0; i < (res / sizeof(ipv6_addr_t)); i++) {
                _print_addr(&ipv6_addrs[i], ipv6_addrs_flags[i]);
                addr_qty++;
            }
        }
    }
    if (!addr_qty) {
        printf("no addresses found\n");
    }
    return 0;
}
Exemplo n.º 3
0
gnrc_netif_t *gnrc_netif_get_by_pid(kernel_pid_t pid)
{
    gnrc_netif_t *netif = NULL;

    while ((netif = gnrc_netif_iter(netif))) {
        if (netif->pid == pid) {
            return netif;
        }
    }
    return NULL;
}
Exemplo n.º 4
0
unsigned gnrc_netif_numof(void)
{
    gnrc_netif_t *netif = NULL;
    unsigned res = 0;

    while ((netif = gnrc_netif_iter(netif))) {
        if (netif->ops != NULL) {
            res++;
        }
    }
    return res;
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: kbumsik/RIOT
static void _send_packet(void)
{
    gnrc_netif_t *netif = gnrc_netif_iter(NULL);

    struct {
        gnrc_netif_hdr_t netif_hdr;
        uint8_t src[8];
        uint8_t dst[8];
    } netif_hdr = {
        .src = { 0x02, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0x02 },
        .dst = { 0x02, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0x01 },
    };
Exemplo n.º 6
0
gnrc_netif_t *gnrc_netif_get_by_ipv6_addr(const ipv6_addr_t *addr)
{
    gnrc_netif_t *netif = NULL;

    DEBUG("gnrc_netif: get interface by IPv6 address %s\n",
          ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)));
    while ((netif = gnrc_netif_iter(netif))) {
        if (_addr_idx(netif, addr) >= 0) {
            break;
        }
        if (_group_idx(netif, addr) >= 0) {
            break;
        }
    }
    return netif;
}
Exemplo n.º 7
0
gnrc_netif_t *gnrc_netif_get_by_prefix(const ipv6_addr_t *prefix)
{
    gnrc_netif_t *netif = NULL, *best_netif = NULL;
    unsigned best_match = 0;

    while ((netif = gnrc_netif_iter(netif))) {
        unsigned match;
        int idx;

        if (((match = _match(netif, prefix, NULL, &idx)) > 0) &&
            (match > best_match)) {
            best_match = match;
            best_netif = netif;
        }
    }
    return best_netif;
}
Exemplo n.º 8
0
void comm_init(void)
{
    uint8_t addr[2] = CONF_COMM_ADDR;
    uint16_t pan = CONF_COMM_PAN;
    uint16_t chan = CONF_COMM_CHAN;

    /* get the PID of the first radio */
    gnrc_netif_t *netif = gnrc_netif_iter(NULL);
    if (netif == NULL) {
        puts("comm: ERROR during init, not radio found\n");
        return;
    }

    /* initialize the radio */
    puts("comm: setting address and PAN");
    gnrc_netapi_set(netif->pid, NETOPT_ADDRESS, 0, &addr, 2);
    gnrc_netapi_set(netif->pid, NETOPT_NID, 0, &pan, 2);
    gnrc_netapi_set(netif->pid, NETOPT_CHANNEL, 0, &chan, 2);
}
Exemplo n.º 9
0
            }
            else {
                code = COAP_CODE_VALID;
                _increment_points(p);
            }
            puts("Sending response");
            return gcoap_response(pdu, buf, len, code);
        default:
            return 0;
    }
}

static void _init_iface(void)
{
    ipv6_addr_t prefix = { .u8 = LUKE_DISPLAY_PREFIX }, addr;
    gnrc_netif_t *netif = gnrc_netif_iter(NULL);
    netopt_enable_t enable = NETOPT_ENABLE;
    char addr_str[IPV6_ADDR_MAX_STR_LEN];

    gnrc_netif_ipv6_addrs_get(netif, &addr, sizeof(addr));
    ipv6_addr_init_prefix(&addr, &prefix, LUKE_DISPLAY_PREFIX_LEN);
    gnrc_netif_ipv6_addr_add(netif, &addr, LUKE_DISPLAY_PREFIX_LEN,
                             GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID);
    gnrc_netapi_set(netif->pid, NETOPT_IPV6_SND_RTR_ADV, 0, &enable,
                    sizeof(enable));
    gnrc_ipv6_nib_abr_add(&addr);
    printf("Set address to %s\n", ipv6_addr_to_str(addr_str, &addr,
                                                   sizeof(addr_str)));
}

static void _init_color_map(void)
Exemplo n.º 10
0
Arquivo: main.c Projeto: A-Paul/RIOT
static void _send_packet(void)
{
    gnrc_netif_t *netif = gnrc_netif_iter(NULL);

    struct {
        gnrc_netif_hdr_t netif_hdr;
        uint8_t src[8];
        uint8_t dst[8];
    } netif_hdr = {
        .src = IEEE802154_REMOTE_EUI64,
        .dst = IEEE802154_LOCAL_EUI64,
    };

    gnrc_netif_hdr_init(&(netif_hdr.netif_hdr), 8, 8);

    netif_hdr.netif_hdr.if_pid = netif->pid;

    uint8_t data1[] = {
        /* 6LoWPAN Header */
        /* Fragmentation Header (first) */
        0xc0, 0x94, /* 0b11000: frag1, 0b00010010100: datagram_size (148) */
        0x00, 0x01, /* datagram_tag */
        /* 0b011: LOWPAN_IPHC */
        /* 0b11: Traffic Class and Flow Label are elided */
        /* 0b1: Next Header is compressed */
        /* 0b11: The Hop Limit field is compressed and the hop limit is 255 */
        0x7f,
        /* 0b0: No additional 8-bit Context Identifier Extension is used */
        /* 0b0: Source address compression uses stateless compression */
        /* 0b11: source address mode is 0 bits */
        /* 0b0: Destination address is not a multicast address */
        /* 0x0: Destination address compression uses stateless compression */
        /* 0x00: destination address mode is 128 bits */
        0x30,

        /* destination address: fd01::1 */
        0xfd, 0x01, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x01,

        /* 0b11110: UDP LOWPAN_NHC */
        /* 0b0: Checksum is carried in-line */
        /* 0b11: First 12 bits of both Source Port and Destination Port are 0xf0b and elided */
        0xf3,
        0x00, /* Source Port and Destination Port (4 bits each) */
        0x23, 0x2f, /* Checksum */

        /* payload */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    };

    uint8_t data2[] = {
        /* 6LoWPAN Header */
        /* Fragmentation Header (rest) */
        0xe0, 0x94, /* 0b11100: frag1, 0b00010010100: datagram_size (148) */
        0x00, 0x01, /* datagram_tag */
        0x0c,       /* datagram_offset (12 * 8 = 96) */

        /* payload */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
    };

    gnrc_netreg_entry_t dump_6lowpan = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid);
    gnrc_netreg_entry_t dump_ipv6 = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid);
    gnrc_netreg_entry_t dump_udp = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid);
    gnrc_netreg_entry_t dump_udp_61616 = GNRC_NETREG_ENTRY_INIT_PID(61616, gnrc_pktdump_pid);

    gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &dump_6lowpan);
    gnrc_netreg_register(GNRC_NETTYPE_IPV6, &dump_ipv6);
    gnrc_netreg_register(GNRC_NETTYPE_UDP, &dump_udp);
    gnrc_netreg_register(GNRC_NETTYPE_UDP, &dump_udp_61616);

    gnrc_pktsnip_t *netif1 = gnrc_pktbuf_add(NULL,
                                            &netif_hdr,
                                            sizeof(netif_hdr),
                                            GNRC_NETTYPE_NETIF);
    gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(netif1,
                                           data1,
                                           sizeof(data1),
                                           GNRC_NETTYPE_SIXLOWPAN);

    gnrc_netapi_dispatch_receive(GNRC_NETTYPE_SIXLOWPAN, GNRC_NETREG_DEMUX_CTX_ALL, pkt1);

    gnrc_pktsnip_t *netif2 = gnrc_pktbuf_add(NULL,
                                             &netif_hdr,
                                             sizeof(netif_hdr),
                                             GNRC_NETTYPE_NETIF);
    gnrc_pktsnip_t *pkt2 = gnrc_pktbuf_add(netif2,
                                           data2,
                                           sizeof(data2),
                                           GNRC_NETTYPE_SIXLOWPAN);

    gnrc_netapi_dispatch_receive(GNRC_NETTYPE_SIXLOWPAN, GNRC_NETREG_DEMUX_CTX_ALL, pkt2);
}
Exemplo n.º 11
0
int _gnrc_netif_config(int argc, char **argv)
{
    if (argc < 2) {
        gnrc_netif_t *netif = NULL;

        while ((netif = gnrc_netif_iter(netif))) {
            _netif_list(netif->pid);
        }

        return 0;
    }
    else if (_is_number(argv[1])) {
        kernel_pid_t iface = atoi(argv[1]);

        if (_is_iface(iface)) {
            if (argc < 3) {
                _netif_list(iface);
                return 0;
            }
            else if (strcmp(argv[2], "set") == 0) {
                if (argc < 5) {
                    _set_usage(argv[0]);
                    return 1;
                }

                return _netif_set(argv[0], iface, argv[3], argv[4]);
            }
            else if (strcmp(argv[2], "add") == 0) {
                if (argc < 4) {
                    _add_usage(argv[0]);
                    return 1;
                }

                return _netif_add(argv[0], (kernel_pid_t)iface, argc - 3, argv + 3);
            }
            else if (strcmp(argv[2], "del") == 0) {
                if (argc < 4) {
                    _del_usage(argv[0]);
                    return 1;
                }

                return _netif_del((kernel_pid_t)iface, argv[3]);
            }
#ifdef MODULE_L2FILTER
            else if (strcmp(argv[2], "l2filter") == 0) {
                if (argc < 5) {
                    _l2filter_usage(argv[2]);
                }
                else if (strcmp(argv[3], "add") == 0) {
                    return _netif_addrm_l2filter(iface, argv[4], true);
                }
                else if (strcmp(argv[3], "del") == 0) {
                    return _netif_addrm_l2filter(iface, argv[4], false);
                }
                else {
                    _l2filter_usage(argv[2]);
                }
                return 1;
            }
#endif
#ifdef MODULE_NETSTATS
            else if (strcmp(argv[2], "stats") == 0) {
                uint8_t module;
                bool reset = false;

                /* check for requested module */
                if ((argc == 3) || (strcmp(argv[3], "all") == 0)) {
                    module = NETSTATS_ALL;
                }
                else if (strcmp(argv[3], "l2") == 0) {
                    module = NETSTATS_LAYER2;
                }
                else if (strcmp(argv[3], "ipv6") == 0) {
                    module = NETSTATS_IPV6;
                }
                else {
                    printf("Module %s doesn't exist or does not provide statistics.\n", argv[3]);

                    return 0;
                }

                /* check if reset flag was given */
                if ((argc > 4) && (strncmp(argv[4], "reset", 5) == 0)) {
                    reset = true;
                }
                if (module & NETSTATS_LAYER2) {
                    _netif_stats((kernel_pid_t) iface, NETSTATS_LAYER2, reset);
                }
                if (module & NETSTATS_IPV6) {
                    _netif_stats((kernel_pid_t) iface, NETSTATS_IPV6, reset);
                }

                return 1;
            }
#endif
            else if (strcmp(argv[2], "help") == 0) {
                _usage(argv[0]);
                return 0;
            }
            else {
                return _netif_flag(argv[0], iface, argv[2]);
            }
        }
        else {
            puts("error: invalid interface given");
            return 1;
        }
    }

    _usage(argv[0]);
    return 1;
}