devif_poll.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /****************************************************************************
  2. * net/devif/devif_poll.c
  3. *
  4. * Copyright (C) 2007-2010, 2012, 2014, 2016-2019 Gregory Nutt. All rights
  5. * reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Included Files
  38. ****************************************************************************/
  39. #include <nuttx/config.h>
  40. #ifdef CONFIG_NET
  41. #include <debug.h>
  42. #include <nuttx/clock.h>
  43. #include <nuttx/net/netconfig.h>
  44. #include <nuttx/net/netdev.h>
  45. #include <nuttx/net/net.h>
  46. #include "devif/devif.h"
  47. #include "arp/arp.h"
  48. #include "can/can.h"
  49. #include "tcp/tcp.h"
  50. #include "udp/udp.h"
  51. #include "pkt/pkt.h"
  52. #include "bluetooth/bluetooth.h"
  53. #include "ieee802154/ieee802154.h"
  54. #include "icmp/icmp.h"
  55. #include "igmp/igmp.h"
  56. #include "icmpv6/icmpv6.h"
  57. #include "mld/mld.h"
  58. #include "ipforward/ipforward.h"
  59. #include "sixlowpan/sixlowpan.h"
  60. /****************************************************************************
  61. * Private Types
  62. ****************************************************************************/
  63. enum devif_packet_type
  64. {
  65. DEVIF_PKT = 0,
  66. DEVIF_ICMP,
  67. DEVIF_IGMP,
  68. DEVIF_TCP,
  69. DEVIF_UDP,
  70. DEVIF_ICMP6
  71. };
  72. /****************************************************************************
  73. * Private Functions
  74. ****************************************************************************/
  75. /****************************************************************************
  76. * Name: devif_packet_conversion
  77. *
  78. * Description:
  79. * Generic output conversion hook. Only needed for IEEE802.15.4 (and
  80. * other non-standard packet radios) for now but this is a point where
  81. * support for other conversions may be provided.
  82. *
  83. * TCP output comes through three different mechansims. Either from:
  84. *
  85. * 1. TCP socket output. For the case of TCP output to a radio,
  86. * the TCP output is caught in the socket send()/sendto() logic and
  87. * redirected to 6LoWPAN logic.
  88. * 2. TCP output from the TCP state machine. That will occur
  89. * during TCP packet processing by the TCP state meachine.
  90. * 3. TCP output resulting from TX or timer polling
  91. *
  92. * Cases 2 is handled here. Logic here detected if (1) an attempt
  93. * to return with d_len > 0 and (2) that the device is a radio
  94. * network driver. Under those conditions, 6LoWPAN logic will be called
  95. * to create the radio frames.
  96. *
  97. * All outgoing ICMPv6 messages come through one of two mechanisms:
  98. *
  99. * 1. The output from internal ICMPv6 message passing. These outgoing
  100. * messages will use device polling and will be handled here.
  101. * 2. ICMPv6 output resulting from TX or timer polling.
  102. *
  103. * Assumptions:
  104. * The network is locked.
  105. *
  106. ****************************************************************************/
  107. #ifdef CONFIG_NET_6LOWPAN
  108. static void devif_packet_conversion(FAR struct net_driver_s *dev,
  109. enum devif_packet_type pkttype)
  110. {
  111. if (dev->d_len > 0)
  112. {
  113. /* Check if this is a device served by 6LoWPAN */
  114. if (dev->d_lltype == NET_LL_IEEE802154 ||
  115. dev->d_lltype == NET_LL_PKTRADIO)
  116. {
  117. FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)dev->d_buf;
  118. #ifdef CONFIG_NET_IPv4
  119. if ((ipv6->vtc & IP_VERSION_MASK) != IPv6_VERSION)
  120. {
  121. nerr("ERROR: IPv6 version error: %02x... Packet dropped\n",
  122. ipv6->vtc);
  123. }
  124. else
  125. #endif
  126. #ifdef CONFIG_NET_TCP
  127. if (pkttype == DEVIF_TCP)
  128. {
  129. /* This packet came from a response to TCP polling and is
  130. * directed to an radio driver using 6LoWPAN. Verify that the
  131. * outgoing packet is IPv6 with TCP protocol.
  132. */
  133. if (ipv6->proto == IP_PROTO_TCP)
  134. {
  135. /* Let 6LoWPAN convert IPv6 TCP output into radio frames. */
  136. sixlowpan_tcp_send(dev, dev, ipv6);
  137. }
  138. else
  139. {
  140. nerr("ERROR: TCP protocol error: %u... Packet dropped\n",
  141. ipv6->proto);
  142. }
  143. }
  144. else
  145. #endif
  146. #ifdef CONFIG_NET_ICMPv6
  147. if (pkttype == DEVIF_ICMP6)
  148. {
  149. /* This packet came from a response to ICMPv6 polling and is
  150. * directed to a radio using 6LoWPAN. Verify that the outgoing
  151. * packet is IPv6 with TCP protocol.
  152. */
  153. if (ipv6->proto == IP_PROTO_ICMP6)
  154. {
  155. /* Let 6LoWPAN convert IPv6 ICMPv6 output into radio frames. */
  156. sixlowpan_icmpv6_send(dev, dev, ipv6);
  157. }
  158. else
  159. {
  160. nerr("ERROR: ICMPv6 protocol error: %u... Packet dropped\n",
  161. ipv6->proto);
  162. }
  163. }
  164. else
  165. #endif
  166. {
  167. nerr("ERROR: Unhandled packet dropped. pkttype=%u protocol=%u\n",
  168. pkttype, ipv6->proto);
  169. }
  170. UNUSED(ipv6);
  171. dev->d_len = 0;
  172. }
  173. }
  174. }
  175. #else
  176. # define devif_packet_conversion(dev,pkttype)
  177. #endif /* CONFIG_NET_6LOWPAN */
  178. /****************************************************************************
  179. * Name: devif_poll_pkt_connections
  180. *
  181. * Description:
  182. * Poll all packet connections for available packets to send.
  183. *
  184. * Assumptions:
  185. * This function is called from the MAC device driver with the network
  186. * locked.
  187. *
  188. ****************************************************************************/
  189. #ifdef CONFIG_NET_PKT
  190. static int devif_poll_pkt_connections(FAR struct net_driver_s *dev,
  191. devif_poll_callback_t callback)
  192. {
  193. FAR struct pkt_conn_s *pkt_conn = NULL;
  194. int bstop = 0;
  195. /* Traverse all of the allocated packet connections and perform the poll action */
  196. while (!bstop && (pkt_conn = pkt_nextconn(pkt_conn)))
  197. {
  198. /* Perform the packet TX poll */
  199. pkt_poll(dev, pkt_conn);
  200. /* Perform any necessary conversions on outgoing packets */
  201. devif_packet_conversion(dev, DEVIF_PKT);
  202. /* Call back into the driver */
  203. bstop = callback(dev);
  204. }
  205. return bstop;
  206. }
  207. #endif /* CONFIG_NET_PKT */
  208. /****************************************************************************
  209. * Name: devif_poll_pkt_connections
  210. *
  211. * Description:
  212. * Poll all packet connections for available packets to send.
  213. *
  214. * Assumptions:
  215. * This function is called from the MAC device driver with the network
  216. * locked.
  217. *
  218. ****************************************************************************/
  219. #ifdef CONFIG_NET_CAN
  220. static int devif_poll_can_connections(FAR struct net_driver_s *dev,
  221. devif_poll_callback_t callback)
  222. {
  223. FAR struct can_conn_s *can_conn = NULL;
  224. int bstop = 0;
  225. /* Traverse all of the allocated packet connections and
  226. * perform the poll action
  227. */
  228. while (!bstop && (can_conn = can_nextconn(can_conn)))
  229. {
  230. /* Perform the packet TX poll */
  231. can_poll(dev, can_conn);
  232. /* Call back into the driver */
  233. bstop = callback(dev);
  234. }
  235. return bstop;
  236. }
  237. #endif /* CONFIG_NET_PKT */
  238. /****************************************************************************
  239. * Name: devif_poll_bluetooth_connections
  240. *
  241. * Description:
  242. * Poll all packet connections for available packets to send.
  243. *
  244. * Assumptions:
  245. * This function is called from the MAC device driver with the network
  246. * locked.
  247. *
  248. ****************************************************************************/
  249. #ifdef CONFIG_NET_BLUETOOTH
  250. static int devif_poll_bluetooth_connections(FAR struct net_driver_s *dev,
  251. devif_poll_callback_t callback)
  252. {
  253. FAR struct bluetooth_conn_s *bluetooth_conn = NULL;
  254. int bstop = 0;
  255. /* Traverse all of the allocated packet connections and perform the poll action */
  256. while (!bstop && (bluetooth_conn = bluetooth_conn_next(bluetooth_conn)))
  257. {
  258. /* Perform the packet TX poll */
  259. bluetooth_poll(dev, bluetooth_conn);
  260. /* Call back into the driver */
  261. bstop = callback(dev);
  262. }
  263. return bstop;
  264. }
  265. #endif /* CONFIG_NET_BLUETOOTH */
  266. /****************************************************************************
  267. * Name: devif_poll_ieee802154_connections
  268. *
  269. * Description:
  270. * Poll all packet connections for available packets to send.
  271. *
  272. * Assumptions:
  273. * This function is called from the MAC device driver with the network
  274. * locked.
  275. *
  276. ****************************************************************************/
  277. #ifdef CONFIG_NET_IEEE802154
  278. static int devif_poll_ieee802154_connections(FAR struct net_driver_s *dev,
  279. devif_poll_callback_t callback)
  280. {
  281. FAR struct ieee802154_conn_s *ieee802154_conn = NULL;
  282. int bstop = 0;
  283. /* Traverse all of the allocated packet connections and perform the poll action */
  284. while (!bstop && (ieee802154_conn = ieee802154_conn_next(ieee802154_conn)))
  285. {
  286. /* Perform the packet TX poll */
  287. ieee802154_poll(dev, ieee802154_conn);
  288. /* Call back into the driver */
  289. bstop = callback(dev);
  290. }
  291. return bstop;
  292. }
  293. #endif /* CONFIG_NET_IEEE802154 */
  294. /****************************************************************************
  295. * Name: devif_poll_icmp
  296. *
  297. * Description:
  298. * Poll all of the connections waiting to send an ICMP ECHO request
  299. *
  300. ****************************************************************************/
  301. #if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_SOCKET)
  302. static inline int devif_poll_icmp(FAR struct net_driver_s *dev,
  303. devif_poll_callback_t callback)
  304. {
  305. FAR struct icmp_conn_s *conn = NULL;
  306. int bstop = 0;
  307. /* Traverse all of the allocated ICMP connections and perform the poll action */
  308. while (!bstop && (conn = icmp_nextconn(conn)) != NULL)
  309. {
  310. /* Perform the ICMP poll */
  311. icmp_poll(dev, conn);
  312. /* Perform any necessary conversions on outgoing packets */
  313. devif_packet_conversion(dev, DEVIF_ICMP);
  314. /* Call back into the driver */
  315. bstop = callback(dev);
  316. }
  317. return bstop;
  318. }
  319. #endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_SOCKET */
  320. /****************************************************************************
  321. * Name: devif_poll_icmpv6
  322. *
  323. * Description:
  324. * Poll all of the connections waiting to send an ICMPv6 ECHO request
  325. *
  326. ****************************************************************************/
  327. #if defined(CONFIG_NET_ICMPv6_SOCKET) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
  328. static inline int devif_poll_icmpv6(FAR struct net_driver_s *dev,
  329. devif_poll_callback_t callback)
  330. {
  331. FAR struct icmpv6_conn_s *conn = NULL;
  332. int bstop = 0;
  333. /* Traverse all of the allocated ICMPV6 connections and perform the poll action */
  334. do
  335. {
  336. /* Perform the ICMPV6 poll
  337. * Note: conn equal NULL in the first iteration means poll dev's callback list
  338. * since icmpv6_autoconfig and icmpv6_neighbor still append it's callback into
  339. * this list.
  340. */
  341. icmpv6_poll(dev, conn);
  342. /* Perform any necessary conversions on outgoing packets */
  343. devif_packet_conversion(dev, DEVIF_ICMP6);
  344. /* Call back into the driver */
  345. bstop = callback(dev);
  346. }
  347. while (!bstop && (conn = icmpv6_nextconn(conn)) != NULL);
  348. return bstop;
  349. }
  350. #endif /* CONFIG_NET_ICMPv6_SOCKET || CONFIG_NET_ICMPv6_NEIGHBOR*/
  351. /****************************************************************************
  352. * Name: devif_poll_forward
  353. *
  354. * Description:
  355. * Poll the device event to see if any task is waiting to forward a packet.
  356. *
  357. ****************************************************************************/
  358. #ifdef CONFIG_NET_IPFORWARD
  359. static inline int devif_poll_forward(FAR struct net_driver_s *dev,
  360. devif_poll_callback_t callback)
  361. {
  362. /* Perform the forwarding poll */
  363. ipfwd_poll(dev);
  364. /* NOTE: that 6LoWPAN packet conversions are handled differently for
  365. * forwarded packets. That is because we don't know what the packet
  366. * type is at this point; not within peeking into the device's d_buf.
  367. */
  368. /* Call back into the driver */
  369. return callback(dev);
  370. }
  371. #endif /* CONFIG_NET_ICMPv6_SOCKET || CONFIG_NET_ICMPv6_NEIGHBOR*/
  372. /****************************************************************************
  373. * Name: devif_poll_igmp
  374. *
  375. * Description:
  376. * Poll all IGMP connections for available packets to send.
  377. *
  378. * Assumptions:
  379. * This function is called from the MAC device driver with the network
  380. * locked.
  381. *
  382. ****************************************************************************/
  383. #ifdef CONFIG_NET_IGMP
  384. static inline int devif_poll_igmp(FAR struct net_driver_s *dev,
  385. devif_poll_callback_t callback)
  386. {
  387. /* Perform the IGMP TX poll */
  388. igmp_poll(dev);
  389. /* Perform any necessary conversions on outgoing packets */
  390. devif_packet_conversion(dev, DEVIF_IGMP);
  391. /* Call back into the driver */
  392. return callback(dev);
  393. }
  394. #endif /* CONFIG_NET_IGMP */
  395. /****************************************************************************
  396. * Name: devif_poll_mld
  397. *
  398. * Description:
  399. * Poll all MLD connections for available packets to send.
  400. *
  401. * Assumptions:
  402. * This function is called from the MAC device driver with the network
  403. * locked.
  404. *
  405. ****************************************************************************/
  406. #ifdef CONFIG_NET_MLD
  407. static inline int devif_poll_mld(FAR struct net_driver_s *dev,
  408. devif_poll_callback_t callback)
  409. {
  410. /* Perform the MLD TX poll */
  411. mld_poll(dev);
  412. /* Perform any necessary conversions on outgoing ICMPv6 packets */
  413. devif_packet_conversion(dev, DEVIF_ICMP6);
  414. /* Call back into the driver */
  415. return callback(dev);
  416. }
  417. #endif /* CONFIG_NET_MLD */
  418. /****************************************************************************
  419. * Name: devif_poll_udp_connections
  420. *
  421. * Description:
  422. * Poll all UDP connections for available packets to send.
  423. *
  424. * Assumptions:
  425. * This function is called from the MAC device driver with the network
  426. * locked.
  427. *
  428. ****************************************************************************/
  429. #ifdef NET_UDP_HAVE_STACK
  430. static int devif_poll_udp_connections(FAR struct net_driver_s *dev,
  431. devif_poll_callback_t callback)
  432. {
  433. FAR struct udp_conn_s *conn = NULL;
  434. int bstop = 0;
  435. /* Traverse all of the allocated UDP connections and perform the poll action */
  436. while (!bstop && (conn = udp_nextconn(conn)))
  437. {
  438. /* Perform the UDP TX poll */
  439. udp_poll(dev, conn);
  440. /* Perform any necessary conversions on outgoing packets */
  441. devif_packet_conversion(dev, DEVIF_UDP);
  442. /* Call back into the driver */
  443. bstop = callback(dev);
  444. }
  445. return bstop;
  446. }
  447. #endif /* NET_UDP_HAVE_STACK */
  448. /****************************************************************************
  449. * Name: devif_poll_tcp_connections
  450. *
  451. * Description:
  452. * Poll all UDP connections for available packets to send.
  453. *
  454. * Assumptions:
  455. * This function is called from the MAC device driver with the network
  456. * locked.
  457. *
  458. ****************************************************************************/
  459. #ifdef NET_TCP_HAVE_STACK
  460. static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev,
  461. devif_poll_callback_t callback)
  462. {
  463. FAR struct tcp_conn_s *conn = NULL;
  464. int bstop = 0;
  465. /* Traverse all of the active TCP connections and perform the poll action */
  466. while (!bstop && (conn = tcp_nextconn(conn)))
  467. {
  468. /* Perform the TCP TX poll */
  469. tcp_poll(dev, conn);
  470. /* Perform any necessary conversions on outgoing packets */
  471. devif_packet_conversion(dev, DEVIF_TCP);
  472. /* Call back into the driver */
  473. bstop = callback(dev);
  474. }
  475. return bstop;
  476. }
  477. #else
  478. # define devif_poll_tcp_connections(dev, callback) (0)
  479. #endif
  480. /****************************************************************************
  481. * Name: devif_poll_tcp_timer
  482. *
  483. * Description:
  484. * The TCP timer has expired. Update TCP timing state in each active,
  485. * TCP connection.
  486. *
  487. * Assumptions:
  488. * This function is called from the MAC device driver with the network
  489. * locked.
  490. *
  491. ****************************************************************************/
  492. #ifdef NET_TCP_HAVE_STACK
  493. static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev,
  494. devif_poll_callback_t callback,
  495. int hsec)
  496. {
  497. FAR struct tcp_conn_s *conn = NULL;
  498. int bstop = 0;
  499. /* Traverse all of the active TCP connections and perform the poll action. */
  500. while (!bstop && (conn = tcp_nextconn(conn)))
  501. {
  502. /* Perform the TCP timer poll */
  503. tcp_timer(dev, conn, hsec);
  504. /* Perform any necessary conversions on outgoing packets */
  505. devif_packet_conversion(dev, DEVIF_TCP);
  506. /* Call back into the driver */
  507. bstop = callback(dev);
  508. }
  509. return bstop;
  510. }
  511. #else
  512. # define devif_poll_tcp_timer(dev, callback, hsec) (0)
  513. #endif
  514. /****************************************************************************
  515. * Public Functions
  516. ****************************************************************************/
  517. /****************************************************************************
  518. * Name: devif_poll
  519. *
  520. * Description:
  521. * This function will traverse each active network connection structure and
  522. * will perform network polling operations. devif_poll() may be called
  523. * asynchronously with the network driver can accept another outgoing
  524. * packet.
  525. *
  526. * This function will call the provided callback function for every active
  527. * connection. Polling will continue until all connections have been polled
  528. * or until the user-supplied function returns a non-zero value (which it
  529. * should do only if it cannot accept further write data).
  530. *
  531. * When the callback function is called, there may be an outbound packet
  532. * waiting for service in the device packet buffer, and if so the d_len field
  533. * is set to a value larger than zero. The device driver should then send
  534. * out the packet.
  535. *
  536. * Assumptions:
  537. * This function is called from the MAC device driver with the network
  538. * locked.
  539. *
  540. ****************************************************************************/
  541. int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
  542. {
  543. int bstop = false;
  544. /* Traverse all of the active packet connections and perform the poll
  545. * action.
  546. */
  547. #ifdef CONFIG_NET_ARP_SEND
  548. /* Check for pending ARP requests */
  549. bstop = arp_poll(dev, callback);
  550. if (!bstop)
  551. #endif
  552. #ifdef CONFIG_NET_PKT
  553. {
  554. /* Check for pending packet socket transfer */
  555. bstop = devif_poll_pkt_connections(dev, callback);
  556. }
  557. if (!bstop)
  558. #endif
  559. #ifdef CONFIG_NET_CAN
  560. {
  561. /* Check for pending packet socket transfer */
  562. bstop = devif_poll_can_connections(dev, callback);
  563. }
  564. if (!bstop)
  565. #endif
  566. #ifdef CONFIG_NET_BLUETOOTH
  567. {
  568. /* Check for pending PF_BLUETOOTH socket transfer */
  569. bstop = devif_poll_bluetooth_connections(dev, callback);
  570. }
  571. if (!bstop)
  572. #endif
  573. #ifdef CONFIG_NET_IEEE802154
  574. {
  575. /* Check for pending PF_IEEE802154 socket transfer */
  576. bstop = devif_poll_ieee802154_connections(dev, callback);
  577. }
  578. if (!bstop)
  579. #endif
  580. #ifdef CONFIG_NET_IGMP
  581. {
  582. /* Check for pending IGMP messages */
  583. bstop = devif_poll_igmp(dev, callback);
  584. }
  585. if (!bstop)
  586. #endif
  587. #ifdef CONFIG_NET_MLD
  588. {
  589. /* Check for pending MLD messages */
  590. bstop = devif_poll_mld(dev, callback);
  591. }
  592. if (!bstop)
  593. #endif
  594. #ifdef NET_TCP_HAVE_STACK
  595. {
  596. /* Traverse all of the active TCP connections and perform the poll
  597. * action.
  598. */
  599. bstop = devif_poll_tcp_connections(dev, callback);
  600. }
  601. if (!bstop)
  602. #endif
  603. #ifdef NET_UDP_HAVE_STACK
  604. {
  605. /* Traverse all of the allocated UDP connections and perform
  606. * the poll action
  607. */
  608. bstop = devif_poll_udp_connections(dev, callback);
  609. }
  610. if (!bstop)
  611. #endif
  612. #if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_SOCKET)
  613. {
  614. /* Traverse all of the tasks waiting to send an ICMP ECHO request. */
  615. bstop = devif_poll_icmp(dev, callback);
  616. }
  617. if (!bstop)
  618. #endif
  619. #if defined(CONFIG_NET_ICMPv6_SOCKET) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
  620. {
  621. /* Traverse all of the tasks waiting to send an ICMPv6 ECHO request. */
  622. bstop = devif_poll_icmpv6(dev, callback);
  623. }
  624. if (!bstop)
  625. #endif
  626. #ifdef CONFIG_NET_IPFORWARD
  627. {
  628. /* Traverse all of the tasks waiting to forward a packet to this device. */
  629. bstop = devif_poll_forward(dev, callback);
  630. }
  631. if (!bstop)
  632. #endif
  633. {
  634. /* Nothing more to do */
  635. }
  636. return bstop;
  637. }
  638. /****************************************************************************
  639. * Name: devif_timer
  640. *
  641. * Description:
  642. * These function will traverse each active network connection structure and
  643. * perform network timer operations. The Ethernet driver MUST implement
  644. * logic to periodically call devif_timer().
  645. *
  646. * This function will call the provided callback function for every active
  647. * connection. Polling will continue until all connections have been polled
  648. * or until the user-supplied function returns a non-zero value (which it
  649. * should do only if it cannot accept further write data).
  650. *
  651. * When the callback function is called, there may be an outbound packet
  652. * waiting for service in the device packet buffer, and if so the d_len field
  653. * is set to a value larger than zero. The device driver should then send
  654. * out the packet.
  655. *
  656. * Assumptions:
  657. * This function is called from the MAC device driver with the network
  658. * locked.
  659. *
  660. ****************************************************************************/
  661. int devif_timer(FAR struct net_driver_s *dev, int delay,
  662. devif_poll_callback_t callback)
  663. {
  664. #if defined(CONFIG_NET_IPv4_REASSEMBLY) || defined(NET_TCP_HAVE_STACK)
  665. int hsec = TICK2HSEC(delay);
  666. #endif
  667. int bstop = false;
  668. #ifdef NET_TCP_HAVE_STACK
  669. /* Traverse all of the active TCP connections and perform the
  670. * timer action.
  671. */
  672. bstop = devif_poll_tcp_timer(dev, callback, hsec);
  673. #endif
  674. /* If possible, continue with a normal poll checking for pending
  675. * network driver actions.
  676. */
  677. if (!bstop)
  678. {
  679. bstop = devif_poll(dev, callback);
  680. }
  681. return bstop;
  682. }
  683. #endif /* CONFIG_NET */