Beispiel #1
0
static void test_ng_netif_add__memfull(void)
{
    for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
        TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i));
    }

    TEST_ASSERT_EQUAL_INT(-ENOMEM, gnrc_netif_add(TEST_UINT8 - 1));
}
Beispiel #2
0
static void test_gnrc_netif_exist(void)
{
    TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(0));
    TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(1));
    TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8));

    for (int i = 0; i < UINT8_MAX; i++) {
        if ((i == 0) || (i == 1) || (i == TEST_UINT8)) {
            TEST_ASSERT(gnrc_netif_exist(i));
        }
        else {
            TEST_ASSERT(!gnrc_netif_exist(i));
        }
    }
}
Beispiel #3
0
static void test_ng_netif_add__KERNEL_PID_UNDEF(void)
{
    kernel_pid_t ifs[GNRC_NETIF_NUMOF];
    size_t size;

    TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(KERNEL_PID_UNDEF));
    size = gnrc_netif_get(ifs);
    TEST_ASSERT_EQUAL_INT(0, size);
}
Beispiel #4
0
static void test_ng_netif_add__success(void)
{
    kernel_pid_t ifs[GNRC_NETIF_NUMOF];
    size_t size;

    TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8));

    size = gnrc_netif_get(ifs);
    TEST_ASSERT_EQUAL_INT(1, size);
    TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]);
}
Beispiel #5
0
static void test_ng_netif_get__full(void)
{
    kernel_pid_t ifs[GNRC_NETIF_NUMOF];
    size_t size;

    for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
        TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i));
    }

    size = gnrc_netif_get(ifs);
    TEST_ASSERT_EQUAL_INT(GNRC_NETIF_NUMOF, size);
}
Beispiel #6
0
static void test_ng_netif_add__duplicate_entry(void)
{
    kernel_pid_t ifs[GNRC_NETIF_NUMOF];
    size_t size;

    for (int i = 0; i < GNRC_NETIF_NUMOF + 4; i++) {
        TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8));
    }

    size = gnrc_netif_get(ifs);
    TEST_ASSERT_EQUAL_INT(1, size);
    TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]);
}
Beispiel #7
0
gnrc_nettest_res_t gnrc_nettest_send_iface(kernel_pid_t pid, gnrc_pktsnip_t *in,
        unsigned int exp_pkts,
        const kernel_pid_t *exp_senders,
        const gnrc_pktsnip_t **exp_out)
{
    gnrc_nettest_res_t res;

    gnrc_netif_add(thread_getpid());

    res = _pkt_test(GNRC_NETAPI_MSG_TYPE_SND, pid, in, exp_pkts, exp_senders,
                    exp_out);

    gnrc_netif_remove(thread_getpid());

    return res;
}
Beispiel #8
0
static void *_slip(void *args)
{
    gnrc_slip_dev_t *dev = _SLIP_DEV(args);
    msg_t msg, reply, msg_q[_SLIP_MSG_QUEUE_SIZE];

    msg_init_queue(msg_q, _SLIP_MSG_QUEUE_SIZE);
    dev->slip_pid = thread_getpid();
    gnrc_netif_add(dev->slip_pid);

    DEBUG("slip: SLIP runs on UART_%d\n", dev->uart);

    while (1) {
        DEBUG("slip: waiting for incoming messages\n");
        msg_receive(&msg);

        switch (msg.type) {
            case _SLIP_MSG_TYPE:
                DEBUG("slip: incoming message of size %" PRIu32 " from UART_%d in buffer\n",
                      msg.content.value, dev->uart);
                _slip_receive(dev, (size_t)msg.content.value);
                break;

            case GNRC_NETAPI_MSG_TYPE_SND:
                DEBUG("slip: GNRC_NETAPI_MSG_TYPE_SND received\n");
                _slip_send(dev, (gnrc_pktsnip_t *)msg.content.ptr);
                break;

            case GNRC_NETAPI_MSG_TYPE_GET:
                DEBUG("slip: GNRC_NETAPI_MSG_TYPE_GET received\n");
                reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
                reply.content.value = (uint32_t)_slip_get((gnrc_netapi_opt_t *)msg.content.ptr);
                msg_reply(&msg, &reply);
                break;

            case GNRC_NETAPI_MSG_TYPE_SET:
                DEBUG("slip: GNRC_NETAPI_MSG_TYPE_SET received\n");
                reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
                reply.content.value = (uint32_t)(-ENOTSUP);
                DEBUG("slip: I don't support this but have to reply.\n");
                msg_reply(&msg, &reply);
                break;
        }
    }

    /* should be never reached */
    return NULL;
}
Beispiel #9
0
/* takes one out of the middle of the netif list and checks if all interfaces
 * are gotten regardless */
static void test_ng_netif_get__success_3_minus_one(void)
{
    kernel_pid_t ifs[GNRC_NETIF_NUMOF];
    size_t size;
    int count = 0;

    for (int i = 0; i < 3; i++) {
        TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i));
    }

    gnrc_netif_remove(TEST_UINT8 + 1);

    size = gnrc_netif_get(ifs);
    TEST_ASSERT_EQUAL_INT(2, size);

    for (size_t i = 0; i < size; i++) {
        if ((ifs[i] == TEST_UINT8) || ifs[i] == (TEST_UINT8 + 2)) {
            count++;
        }
    }

    TEST_ASSERT_EQUAL_INT(size, count);
}
Beispiel #10
0
/**
 * @brief   Startup code and event loop of the gnrc_netdev2 layer
 *
 * @param[in] args  expects a pointer to the underlying netdev device
 *
 * @return          never returns
 */
static void *_gnrc_netdev2_thread(void *args)
{
    DEBUG("gnrc_netdev2: starting thread\n");

    gnrc_netdev2_t *gnrc_netdev2 = (gnrc_netdev2_t*) args;
    netdev2_t *dev = gnrc_netdev2->dev;

    gnrc_netdev2->pid = thread_getpid();

    gnrc_netapi_opt_t *opt;
    int res;
    msg_t msg, reply, msg_queue[NETDEV2_NETAPI_MSG_QUEUE_SIZE];

    /* setup the MAC layers message queue */
    msg_init_queue(msg_queue, NETDEV2_NETAPI_MSG_QUEUE_SIZE);

    /* register the event callback with the device driver */
    dev->event_callback = _event_cb;
    dev->context = (void*) gnrc_netdev2;

    /* register the device to the network stack*/
    gnrc_netif_add(thread_getpid());

    /* initialize low-level driver */
    dev->driver->init(dev);

    /* start the event loop */
    while (1) {
        DEBUG("gnrc_netdev2: waiting for incoming messages\n");
        msg_receive(&msg);
        /* dispatch NETDEV and NETAPI messages */
        switch (msg.type) {
            case NETDEV2_MSG_TYPE_EVENT:
                DEBUG("gnrc_netdev2: GNRC_NETDEV_MSG_TYPE_EVENT received\n");
                dev->driver->isr(dev);
                break;
            case GNRC_NETAPI_MSG_TYPE_SND:
                DEBUG("gnrc_netdev2: GNRC_NETAPI_MSG_TYPE_SND received\n");
                gnrc_pktsnip_t *pkt = (gnrc_pktsnip_t *)msg.content.ptr;
                gnrc_netdev2->send(gnrc_netdev2, pkt);
                break;
            case GNRC_NETAPI_MSG_TYPE_SET:
                /* read incoming options */
                opt = (gnrc_netapi_opt_t *)msg.content.ptr;
                DEBUG("gnrc_netdev2: GNRC_NETAPI_MSG_TYPE_SET received. opt=%s\n",
                        netopt2str(opt->opt));
                /* set option for device driver */
                res = dev->driver->set(dev, opt->opt, opt->data, opt->data_len);
                DEBUG("gnrc_netdev2: response of netdev->set: %i\n", res);
                /* send reply to calling thread */
                reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
                reply.content.value = (uint32_t)res;
                msg_reply(&msg, &reply);
                break;
            case GNRC_NETAPI_MSG_TYPE_GET:
                /* read incoming options */
                opt = (gnrc_netapi_opt_t *)msg.content.ptr;
                DEBUG("gnrc_netdev2: GNRC_NETAPI_MSG_TYPE_GET received. opt=%s\n",
                        netopt2str(opt->opt));
                /* get option from device driver */
                res = dev->driver->get(dev, opt->opt, opt->data, opt->data_len);
                DEBUG("gnrc_netdev2: response of netdev->get: %i\n", res);
                /* send reply to calling thread */
                reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
                reply.content.value = (uint32_t)res;
                msg_reply(&msg, &reply);
                break;
            default:
                DEBUG("gnrc_netdev2: Unknown command %" PRIu16 "\n", msg.type);
                break;
        }
    }
    /* never reached */
    return NULL;
}
Beispiel #11
0
/**
 * @brief   Startup code and event loop of the NOMAC layer
 *
 * @param[in] args          expects a pointer to the underlying netdev device
 *
 * @return                  never returns
 */
static void *_nomac_thread(void *args)
{
    gnrc_netdev_t *dev = (gnrc_netdev_t *)args;
    gnrc_netapi_opt_t *opt;
    int res;
    msg_t msg, reply, msg_queue[GNRC_NOMAC_MSG_QUEUE_SIZE];

    /* setup the MAC layers message queue */
    msg_init_queue(msg_queue, GNRC_NOMAC_MSG_QUEUE_SIZE);
    /* save the PID to the device descriptor and register the device */
    dev->mac_pid = thread_getpid();
    gnrc_netif_add(dev->mac_pid);
    /* register the event callback with the device driver */
    dev->driver->add_event_callback(dev, _event_cb);

    /* start the event loop */
    while (1) {
        DEBUG("nomac: waiting for incoming messages\n");
        msg_receive(&msg);
        /* dispatch NETDEV and NETAPI messages */
        switch (msg.type) {
            case GNRC_NETDEV_MSG_TYPE_EVENT:
                DEBUG("nomac: GNRC_NETDEV_MSG_TYPE_EVENT received\n");
                dev->driver->isr_event(dev, msg.content.value);
                break;
            case GNRC_NETAPI_MSG_TYPE_SND:
                DEBUG("nomac: GNRC_NETAPI_MSG_TYPE_SND received\n");
                dev->driver->send_data(dev, (gnrc_pktsnip_t *)msg.content.ptr);
                break;
            case GNRC_NETAPI_MSG_TYPE_SET:
                /* TODO: filter out MAC layer options -> for now forward
                         everything to the device driver */
                DEBUG("nomac: GNRC_NETAPI_MSG_TYPE_SET received\n");
                /* read incoming options */
                opt = (gnrc_netapi_opt_t *)msg.content.ptr;
                /* set option for device driver */
                res = dev->driver->set(dev, opt->opt, opt->data, opt->data_len);
                DEBUG("nomac: response of netdev->set: %i\n", res);
                /* send reply to calling thread */
                reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
                reply.content.value = (uint32_t)res;
                msg_reply(&msg, &reply);
                break;
            case GNRC_NETAPI_MSG_TYPE_GET:
                /* TODO: filter out MAC layer options -> for now forward
                         everything to the device driver */
                DEBUG("nomac: GNRC_NETAPI_MSG_TYPE_GET received\n");
                /* read incoming options */
                opt = (gnrc_netapi_opt_t *)msg.content.ptr;
                /* get option from device driver */
                res = dev->driver->get(dev, opt->opt, opt->data, opt->data_len);
                DEBUG("nomac: response of netdev->get: %i\n", res);
                /* send reply to calling thread */
                reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
                reply.content.value = (uint32_t)res;
                msg_reply(&msg, &reply);
                break;
            default:
                DEBUG("nomac: Unknown command %" PRIu16 "\n", msg.type);
                break;
        }
    }
    /* never reached */
    return NULL;
}