Merge pull request #13579 from jia200x/pr/gnrc_netif_send

gnrc_netif_send: add send function
This commit is contained in:
Martine Lenders 2020-03-06 20:07:45 +01:00 committed by GitHub
commit c30f83ac3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 18 deletions

View File

@ -73,7 +73,7 @@ int tx_cmd(int argc, char **argv)
} }
gnrc_netapi_set(interface, NETOPT_LORAWAN_TX_PORT, 0, &port, sizeof(port)); gnrc_netapi_set(interface, NETOPT_LORAWAN_TX_PORT, 0, &port, sizeof(port));
gnrc_netapi_send(interface, pkt); gnrc_netif_send(gnrc_netif_get_by_pid(interface), pkt);
msg_t msg; msg_t msg;
/* wait for packet status and check */ /* wait for packet status and check */

View File

@ -527,6 +527,20 @@ char *gnrc_netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
*/ */
size_t gnrc_netif_addr_from_str(const char *str, uint8_t *out); size_t gnrc_netif_addr_from_str(const char *str, uint8_t *out);
/**
* @brief Send a GNRC packet via a given @ref gnrc_netif_t interface.
*
* @param netif pointer to the interface
* @param pkt packet to be sent.
*
* @return 1 if packet was successfully delivered
* @return -1 on error
*/
static inline int gnrc_netif_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
{
return gnrc_netapi_send(netif->pid, pkt);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -285,7 +285,7 @@ static void _send_to_iface(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
return; return;
} }
#endif #endif
if (gnrc_netapi_send(netif->pid, pkt) < 1) { if (gnrc_netif_send(netif, pkt) < 1) {
DEBUG("ipv6: unable to send packet\n"); DEBUG("ipv6: unable to send packet\n");
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
} }

View File

@ -95,7 +95,7 @@ void gnrc_sixlowpan_dispatch_send(gnrc_pktsnip_t *pkt, void *context,
(void)page; (void)page;
assert(pkt->type == GNRC_NETTYPE_NETIF); assert(pkt->type == GNRC_NETTYPE_NETIF);
gnrc_netif_hdr_t *hdr = pkt->data; gnrc_netif_hdr_t *hdr = pkt->data;
if (gnrc_netapi_send(hdr->if_pid, pkt) < 1) { if (gnrc_netif_send(gnrc_netif_get_by_pid(hdr->if_pid), pkt) < 1) {
DEBUG("6lo: unable to send %p over interface %u\n", (void *)pkt, DEBUG("6lo: unable to send %p over interface %u\n", (void *)pkt,
hdr->if_pid); hdr->if_pid);
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);

View File

@ -1401,7 +1401,7 @@ int _gnrc_netif_send(int argc, char **argv)
nethdr = (gnrc_netif_hdr_t *)hdr->data; nethdr = (gnrc_netif_hdr_t *)hdr->data;
nethdr->flags = flags; nethdr->flags = flags;
/* and send it */ /* and send it */
if (gnrc_netapi_send(((gnrc_netif_t *)iface)->pid, pkt) < 1) { if (gnrc_netif_send((gnrc_netif_t *)iface, pkt) < 1) {
puts("error: unable to send"); puts("error: unable to send");
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
return 1; return 1;

View File

@ -1196,7 +1196,7 @@ static void test_netapi_send__raw_unicast_ethernet_packet(void)
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst)); gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ethernet_netif->pid, pkt); gnrc_netif_send(ethernet_netif, pkt);
} }
static void test_netapi_send__raw_broadcast_ethernet_packet(void) static void test_netapi_send__raw_broadcast_ethernet_packet(void)
@ -1211,7 +1211,7 @@ static void test_netapi_send__raw_broadcast_ethernet_packet(void)
hdr = netif->data; hdr = netif->data;
hdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST; hdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ethernet_netif->pid, pkt); gnrc_netif_send(ethernet_netif, pkt);
} }
static void test_netapi_send__raw_unicast_ieee802154_long_long_packet(void) static void test_netapi_send__raw_unicast_ieee802154_long_long_packet(void)
@ -1224,7 +1224,7 @@ static void test_netapi_send__raw_unicast_ieee802154_long_long_packet(void)
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst)); gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
} }
static void test_netapi_send__raw_unicast_ieee802154_long_short_packet(void) static void test_netapi_send__raw_unicast_ieee802154_long_short_packet(void)
@ -1237,7 +1237,7 @@ static void test_netapi_send__raw_unicast_ieee802154_long_short_packet(void)
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst)); gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
} }
static void test_netapi_send__raw_unicast_ieee802154_short_long_packet1(void) static void test_netapi_send__raw_unicast_ieee802154_short_long_packet1(void)
@ -1255,7 +1255,7 @@ static void test_netapi_send__raw_unicast_ieee802154_short_long_packet1(void)
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst)); gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
/* reset src_len */ /* reset src_len */
src_len = 8U; src_len = 8U;
TEST_ASSERT_EQUAL_INT(sizeof(src_len), TEST_ASSERT_EQUAL_INT(sizeof(src_len),
@ -1275,7 +1275,7 @@ static void test_netapi_send__raw_unicast_ieee802154_short_long_packet2(void)
dst, sizeof(dst)); dst, sizeof(dst));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
} }
static void test_netapi_send__raw_unicast_ieee802154_short_short_packet(void) static void test_netapi_send__raw_unicast_ieee802154_short_short_packet(void)
@ -1293,7 +1293,7 @@ static void test_netapi_send__raw_unicast_ieee802154_short_short_packet(void)
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst)); gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, dst, sizeof(dst));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
/* reset src_len */ /* reset src_len */
src_len = 8U; src_len = 8U;
TEST_ASSERT_EQUAL_INT(sizeof(src_len), TEST_ASSERT_EQUAL_INT(sizeof(src_len),
@ -1313,7 +1313,7 @@ static void test_netapi_send__raw_broadcast_ieee802154_long_packet(void)
hdr = netif->data; hdr = netif->data;
hdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST; hdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
} }
static void test_netapi_send__raw_broadcast_ieee802154_short_packet(void) static void test_netapi_send__raw_broadcast_ieee802154_short_packet(void)
@ -1333,7 +1333,7 @@ static void test_netapi_send__raw_broadcast_ieee802154_short_packet(void)
hdr = netif->data; hdr = netif->data;
hdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST; hdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
/* reset src_len */ /* reset src_len */
src_len = 8U; src_len = 8U;
TEST_ASSERT_EQUAL_INT(sizeof(src_len), TEST_ASSERT_EQUAL_INT(sizeof(src_len),
@ -1367,7 +1367,7 @@ static void test_netapi_send__ipv6_unicast_ethernet_packet(void)
sizeof(dst_netif)); sizeof(dst_netif));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ethernet_netif->pid, pkt); gnrc_netif_send(ethernet_netif, pkt);
} }
static void test_netapi_send__ipv6_multicast_ethernet_packet(void) static void test_netapi_send__ipv6_multicast_ethernet_packet(void)
@ -1394,7 +1394,7 @@ static void test_netapi_send__ipv6_multicast_ethernet_packet(void)
netif_hdr = netif->data; netif_hdr = netif->data;
netif_hdr->flags |= GNRC_NETIF_HDR_FLAGS_MULTICAST; netif_hdr->flags |= GNRC_NETIF_HDR_FLAGS_MULTICAST;
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ethernet_netif->pid, pkt); gnrc_netif_send(ethernet_netif, pkt);
} }
static void test_netapi_send__ipv6_unicast_ieee802154_packet(void) static void test_netapi_send__ipv6_unicast_ieee802154_packet(void)
@ -1423,7 +1423,7 @@ static void test_netapi_send__ipv6_unicast_ieee802154_packet(void)
sizeof(dst_netif)); sizeof(dst_netif));
TEST_ASSERT_NOT_NULL(netif); TEST_ASSERT_NOT_NULL(netif);
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
} }
static void test_netapi_send__ipv6_multicast_ieee802154_packet(void) static void test_netapi_send__ipv6_multicast_ieee802154_packet(void)
@ -1450,7 +1450,7 @@ static void test_netapi_send__ipv6_multicast_ieee802154_packet(void)
netif_hdr = netif->data; netif_hdr = netif->data;
netif_hdr->flags |= GNRC_NETIF_HDR_FLAGS_MULTICAST; netif_hdr->flags |= GNRC_NETIF_HDR_FLAGS_MULTICAST;
LL_PREPEND(pkt, netif); LL_PREPEND(pkt, netif);
gnrc_netapi_send(ieee802154_netif->pid, pkt); gnrc_netif_send(ieee802154_netif, pkt);
} }
static void test_netapi_recv__empty_ethernet_payload(void) static void test_netapi_recv__empty_ethernet_payload(void)

View File

@ -115,7 +115,7 @@ static int test_send(void)
return 0; return 0;
} }
/* send packet to MAC layer */ /* send packet to MAC layer */
gnrc_netapi_send(_mac_pid, pkt); gnrc_netif_send(gnrc_netif_get_by_pid(_mac_pid), pkt);
/* wait for packet status and check */ /* wait for packet status and check */
msg_receive(&msg); msg_receive(&msg);
if ((msg.type != GNRC_NETERR_MSG_TYPE) || if ((msg.type != GNRC_NETERR_MSG_TYPE) ||