Example #1
0
static int32_t pico_ll_receive(struct pico_frame *f)
{
    struct pico_eth_hdr *hdr = (struct pico_eth_hdr *) f->datalink_hdr;
    f->net_hdr = f->datalink_hdr + sizeof(struct pico_eth_hdr);

#if (defined PICO_SUPPORT_IPV4) && (defined PICO_SUPPORT_ETH)
    if (hdr->proto == PICO_IDETH_ARP)
        return pico_arp_receive(f);

#endif

#if defined (PICO_SUPPORT_IPV4)
    if (hdr->proto == PICO_IDETH_IPV4)
        return pico_ipv4_ethernet_receive(f);

#endif

#if defined (PICO_SUPPORT_IPV6)
    if (hdr->proto == PICO_IDETH_IPV6)
        return pico_ipv6_ethernet_receive(f);

#endif

    pico_frame_discard(f);
    return -1;
}
END_TEST
START_TEST(tc_pico_ipv6_ethernet_receive)
{
   /* test this: static int32_t pico_ipv6_ethernet_receive(struct pico_frame *f) */
    struct pico_frame *f = NULL;
    struct pico_ipv6_hdr *h = NULL;

    int ret = 0, count = 0;

    STARTING();
    f = pico_frame_alloc(sizeof(struct pico_ipv6_hdr));
    h = (struct pico_ipv6_hdr *)f->buffer;
    f->net_hdr = (uint8_t*) h;
    f->buffer[0] = 0x40; /* Ipv6 */

    TRYING("With wrong network type\n");
    ret = pico_ipv6_ethernet_receive(f);
    CHECKING(count);
    fail_unless(ret == -1, "Wrong type should've returned an error\n");
    SUCCESS();

    f = pico_frame_alloc(sizeof(struct pico_ipv6_hdr));
    h = (struct pico_ipv6_hdr *)f->buffer;
    f->net_hdr = (uint8_t*) h;
    f->buffer[0] = 0x60;
    TRYING("With correct network type\n");
    ret = pico_ipv6_ethernet_receive(f);
    CHECKING(count);
    fail_unless(ret == (int32_t)f->buffer_len, "Was correct frame, should've returned success\n");
    SUCCESS();
    CHECKING(count);
    fail_unless(pico_proto_ipv6.q_in->size == f->buffer_len, "Frame not enqueued\n");
    SUCCESS();

    ENDING(count);
}