mld_msg.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /****************************************************************************
  2. * net/mld/mld_msg.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <assert.h>
  25. #include <debug.h>
  26. #include <nuttx/net/netconfig.h>
  27. #include <nuttx/net/net.h>
  28. #include <nuttx/net/mld.h>
  29. #include "devif/devif.h"
  30. #include "netdev/netdev.h"
  31. #include "mld/mld.h"
  32. #ifdef CONFIG_NET_MLD
  33. /****************************************************************************
  34. * Public Functions
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Name: mld_schedmsg
  38. *
  39. * Description:
  40. * Schedule a message to be send at the next driver polling interval.
  41. *
  42. * Assumptions:
  43. * The network is locked
  44. *
  45. ****************************************************************************/
  46. int mld_schedmsg(FAR struct mld_group_s *group, uint8_t msgtype)
  47. {
  48. FAR struct net_driver_s *dev;
  49. DEBUGASSERT(group != NULL && !IS_MLD_SCHEDMSG(group->flags));
  50. DEBUGASSERT(group->ifindex > 0);
  51. /* Get the device instance associated with the interface index
  52. * of the group
  53. */
  54. dev = netdev_findbyindex(group->ifindex);
  55. if (dev == NULL)
  56. {
  57. mlderr("ERROR: No device for this interface index: %u\n",
  58. group->ifindex);
  59. return -ENODEV;
  60. }
  61. /* Schedule the message */
  62. group->msgtype = msgtype;
  63. SET_MLD_SCHEDMSG(group->flags);
  64. /* Notify the device that we have a packet to send */
  65. netdev_txnotify_dev(dev);
  66. return OK;
  67. }
  68. /****************************************************************************
  69. * Name: mld_waitmsg
  70. *
  71. * Description:
  72. * Schedule a message to be send at the next driver polling interval and
  73. * block, waiting for the message to be sent.
  74. *
  75. * Assumptions:
  76. * The network is locked
  77. *
  78. ****************************************************************************/
  79. int mld_waitmsg(FAR struct mld_group_s *group, uint8_t msgtype)
  80. {
  81. int ret;
  82. /* Schedule to send the message */
  83. DEBUGASSERT(!IS_MLD_WAITMSG(group->flags));
  84. SET_MLD_WAITMSG(group->flags);
  85. ret = mld_schedmsg(group, msgtype);
  86. if (ret < 0)
  87. {
  88. mlderr("ERROR: Failed to schedule the message: %d\n", ret);
  89. goto errout;
  90. }
  91. /* Then wait for the message to be sent */
  92. while (IS_MLD_SCHEDMSG(group->flags))
  93. {
  94. /* Wait for the semaphore to be posted */
  95. ret = net_lockedwait_uninterruptible(&group->sem);
  96. if (ret < 0)
  97. {
  98. break;
  99. }
  100. }
  101. /* The message has been sent and we are no longer waiting */
  102. errout:
  103. CLR_MLD_WAITMSG(group->flags);
  104. return ret;
  105. }
  106. #endif /* CONFIG_NET_MLD */