static void net_rx_thread(void) { struct net_pkt *pkt; NET_DBG("Starting RX thread (stack %zu bytes)", sizeof(rx_stack)); /* Starting TX side. The ordering is important here and the TX * can only be started when RX side is ready to receive packets. * We synchronize the startup of the device so that both RX and TX * are only started fully when both are ready to receive or send * data. */ net_if_init(&startup_sync); k_sem_take(&startup_sync, K_FOREVER); /* This will take the interface up and start everything. */ net_if_post_init(); while (1) { #if defined(CONFIG_NET_STATISTICS) || defined(CONFIG_NET_DEBUG_CORE) size_t pkt_len; #endif pkt = k_fifo_get(&rx_queue, K_FOREVER); net_analyze_stack("RX thread", rx_stack, sizeof(rx_stack)); #if defined(CONFIG_NET_STATISTICS) || defined(CONFIG_NET_DEBUG_CORE) pkt_len = net_pkt_get_len(pkt); #endif NET_DBG("Received pkt %p len %zu", pkt, pkt_len); net_stats_update_bytes_recv(pkt_len); processing_data(pkt, false); net_print_statistics(); net_pkt_print(); k_yield(); } }
int main(void) { int iface; char *addr1_data = "abcdefgh", *addr2_data = "12345678"; net_if_addr_t addr1 = { .addr_next = NULL, .addr_prev = NULL, .addr_protocol = NET_IF_L3P_IPV6_MULTICAST, .addr_data = (void *)addr1_data, .addr_len = (strlen(addr1_data) + 1) * 8 }; net_if_addr_t addr2 = { .addr_next = NULL, .addr_prev = NULL, .addr_protocol = NET_IF_L3P_IPV6_PREFIX, .addr_data = (void *)addr2_data, .addr_len = (strlen(addr2_data) + 1) * 8 }; uint16_t own = 1, target = 2; net_if_eui64_t eui64; iface = initialize_tests(); if (!test_net_if_initialization(iface)) { printf("FAILED: test_net_if_initialization()\n"); return -1; } if (!test_net_if_get_add_l3p_types(iface)) { printf("FAILED: test_net_if_get_add_l3p_types()\n"); return -1; } if (!test_net_if_add_address(iface, &addr1, &addr2)) { printf("FAILED: test_net_if_add_address()\n"); return -1; } if (!test_net_if_del_address(iface, &addr1, &addr2)) { printf("FAILED: test_net_if_del_address()\n"); return -1; } if (!test_net_if_get_set_hardware_address(iface, own)) { printf("FAILED: test_net_if_get_set_hardware_address()\n"); return -1; } if (!test_net_if_get_set_pan_id(iface)) { printf("FAILED: test_net_if_get_set_pan_id()\n"); return -1; } if (!test_net_if_get_set_eui64(iface, &eui64, own)) { printf("FAILED: test_net_if_get_set_eui64()\n"); return -1; } int count = net_if_send_packet(iface, target, "Test", 4); printf("Count was %i after net_if_send_packet()\n", count); printf("All test ran successfully.\n"); return 0; } int initialize_tests(void) { int iface; #ifndef MODULE_AUTO_INIT transceiver_init(TRANSCEIVER); transceiver_start(); net_if_init(); iface = net_if_init_interface(0, TRANSCEIVER); return iface; #else iface = -1; while ((iface = net_if_iter_interfaces(iface)) >= 0) { return iface; } return iface; #endif } int test_net_if_initialization(int iface) { net_if_addr_t *addr_ptr = NULL; if (net_if_get_l3p_types(iface)) { printf("FAILED: No L3 type expected on interface %d.\n", iface); return 0; } if (net_if_iter_addresses(iface + 1, &addr_ptr)) { printf("FAILED: Expected error on interface '%d'\n", iface + 1); return 0; } if (net_if_iter_addresses(iface, &addr_ptr)) { printf("FAILED: Expected error on interface '%d'\n", iface); return 0; } return 1; }