mld_poll.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /****************************************************************************
  2. * net/mld/mld_poll.c
  3. *
  4. * Copyright (C) 2018 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. ****************************************************************************/
  33. /****************************************************************************
  34. * Included Files
  35. ****************************************************************************/
  36. #include <nuttx/config.h>
  37. #include <assert.h>
  38. #include <debug.h>
  39. #include <nuttx/net/netconfig.h>
  40. #include <nuttx/net/netdev.h>
  41. #include <nuttx/net/netstats.h>
  42. #include <nuttx/net/ip.h>
  43. #include "devif/devif.h"
  44. #include "mld/mld.h"
  45. /****************************************************************************
  46. * Public Functions
  47. ****************************************************************************/
  48. /****************************************************************************
  49. * Name: mld_poll
  50. *
  51. * Description:
  52. * Poll the groups associated with the device to see if any MLD messages
  53. * are pending transfer.
  54. *
  55. * Returned Value:
  56. * Returns a non-zero value if a IGP message is sent.
  57. *
  58. * Assumptions:
  59. * This function must be called with the network locked.
  60. *
  61. ****************************************************************************/
  62. void mld_poll(FAR struct net_driver_s *dev)
  63. {
  64. FAR struct mld_group_s *group;
  65. /* Setup the poll operation */
  66. dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN];
  67. dev->d_len = 0;
  68. dev->d_sndlen = 0;
  69. /* Check if a general query is pending */
  70. if (IS_MLD_GENPEND(dev->d_mld.flags))
  71. {
  72. /* Clear the pending flag */
  73. CLR_MLD_GENPEND(dev->d_mld.flags);
  74. /* Are we still the querier? */
  75. if (IS_MLD_QUERIER(dev->d_mld.flags))
  76. {
  77. /* Yes, send the general query and return */
  78. mld_send(dev, NULL, MLD_SEND_GENQUERY);
  79. return;
  80. }
  81. }
  82. /* Check each member of the group */
  83. for (group = (FAR struct mld_group_s *)dev->d_mld.grplist.head;
  84. group;
  85. group = group->next)
  86. {
  87. /* Does this member have a pending outgoing message? */
  88. if (IS_MLD_SCHEDMSG(group->flags))
  89. {
  90. /* Yes.. create the MLD message in the driver buffer */
  91. mld_send(dev, group, group->msgtype);
  92. /* Indicate that the message has been sent */
  93. CLR_MLD_SCHEDMSG(group->flags);
  94. group->msgtype = MLD_SEND_NONE;
  95. /* If there is a thread waiting fore the message to be sent, wake
  96. * it up.
  97. */
  98. if (IS_MLD_WAITMSG(group->flags))
  99. {
  100. mldinfo("Awakening waiter\n");
  101. CLR_MLD_WAITMSG(group->flags);
  102. nxsem_post(&group->sem);
  103. }
  104. /* And break out of the loop */
  105. break;
  106. }
  107. /* No.. does this message have a pending report still to be sent? */
  108. else if (IS_MLD_RPTPEND(group->flags))
  109. {
  110. /* Yes.. create the MLD message in the driver buffer */
  111. mld_send(dev, group, mld_report_msgtype(dev));
  112. /* Indicate that the report is no longer pending */
  113. CLR_MLD_RPTPEND(group->flags);
  114. /* And break out of the loop */
  115. break;
  116. }
  117. }
  118. }