mac802154_getset.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /****************************************************************************
  2. * wireless/ieee802154/mac802154_getset.c
  3. *
  4. * Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
  5. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
  6. * Copyright (C) 2017 Verge Inc. All rights reserved.
  7. *
  8. * Author: Sebastien Lorquet <sebastien@lorquet.fr>
  9. * Author: Gregory Nutt <gnutt@nuttx.org>
  10. * Author: Anthony Merlino <anthony@vergeaero.com>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in
  20. * the documentation and/or other materials provided with the
  21. * distribution.
  22. * 3. Neither the name NuttX nor the names of its contributors may be
  23. * used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  33. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  34. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. ****************************************************************************/
  40. /****************************************************************************
  41. * Included Files
  42. ****************************************************************************/
  43. #include <nuttx/config.h>
  44. #include <stdlib.h>
  45. #include <assert.h>
  46. #include <errno.h>
  47. #include <debug.h>
  48. #include <string.h>
  49. #include "mac802154.h"
  50. #include "mac802154_internal.h"
  51. #include <nuttx/wireless/ieee802154/ieee802154_mac.h>
  52. /****************************************************************************
  53. * Public MAC Functions
  54. ****************************************************************************/
  55. /****************************************************************************
  56. * Name: mac802154_req_get
  57. *
  58. * Description:
  59. * The MLME-GET.request primitive requests information about a given PIB
  60. * attribute.
  61. *
  62. * NOTE: The standard specifies that the attribute value should be returned
  63. * via the asynchronous MLME-GET.confirm primitve. However, in our
  64. * implementation, we synchronously return the value immediately.Therefore, we
  65. * merge the functionality of the MLME-GET.request and MLME-GET.confirm
  66. * primitives together.
  67. *
  68. ****************************************************************************/
  69. int mac802154_req_get(MACHANDLE mac, enum ieee802154_attr_e attr,
  70. FAR union ieee802154_attr_u *attrval)
  71. {
  72. FAR struct ieee802154_privmac_s *priv =
  73. (FAR struct ieee802154_privmac_s *)mac;
  74. int ret = IEEE802154_STATUS_SUCCESS;
  75. switch (attr)
  76. {
  77. case IEEE802154_ATTR_MAC_PANID:
  78. {
  79. IEEE802154_PANIDCOPY(attrval->mac.panid, priv->addr.panid);
  80. }
  81. break;
  82. case IEEE802154_ATTR_MAC_SADDR:
  83. {
  84. IEEE802154_SADDRCOPY(attrval->mac.saddr, priv->addr.saddr);
  85. }
  86. break;
  87. case IEEE802154_ATTR_MAC_EADDR:
  88. {
  89. IEEE802154_EADDRCOPY(attrval->mac.eaddr, priv->addr.eaddr);
  90. }
  91. break;
  92. case IEEE802154_ATTR_MAC_COORD_SADDR:
  93. {
  94. IEEE802154_SADDRCOPY(attrval->mac.coordsaddr, priv->pandesc.coordaddr.saddr);
  95. }
  96. break;
  97. case IEEE802154_ATTR_MAC_COORD_EADDR:
  98. {
  99. IEEE802154_EADDRCOPY(attrval->mac.coordeaddr, priv->pandesc.coordaddr.eaddr);
  100. }
  101. break;
  102. case IEEE802154_ATTR_MAC_DEVMODE:
  103. {
  104. attrval->mac.devmode = priv->devmode;
  105. }
  106. break;
  107. case IEEE802154_ATTR_MAC_RESPONSE_WAIT_TIME:
  108. {
  109. attrval->mac.resp_waittime = priv->resp_waittime;
  110. }
  111. break;
  112. case IEEE802154_ATTR_MAC_PROMISCUOUS_MODE:
  113. {
  114. attrval->mac.promisc_mode = priv->promisc;
  115. }
  116. break;
  117. case IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES:
  118. {
  119. attrval->mac.max_retries = priv->maxretries;
  120. }
  121. break;
  122. case IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE:
  123. {
  124. attrval->mac.rxonidle = priv->rxonidle;
  125. }
  126. break;
  127. default:
  128. {
  129. /* The attribute may be handled soley in the radio driver, so pass
  130. * it along.
  131. */
  132. ret = priv->radio->getattr(priv->radio, attr, attrval);
  133. }
  134. break;
  135. }
  136. return ret;
  137. }
  138. /****************************************************************************
  139. * Name: mac802154_req_set
  140. *
  141. * Description:
  142. * The MLME-SET.request primitive attempts to write the given value to the
  143. * indicated MAC PIB attribute.
  144. *
  145. * NOTE: The standard specifies that confirmation should be indicated via
  146. * the asynchronous MLME-SET.confirm primitve. However, in our implementation
  147. * we synchronously return the status from the request. Therefore, we do merge
  148. * the functionality of the MLME-SET.request and MLME-SET.confirm primitives
  149. * together.
  150. *
  151. ****************************************************************************/
  152. int mac802154_req_set(MACHANDLE mac, enum ieee802154_attr_e attr,
  153. FAR const union ieee802154_attr_u *attrval)
  154. {
  155. FAR struct ieee802154_privmac_s *priv =
  156. (FAR struct ieee802154_privmac_s *)mac;
  157. int ret = IEEE802154_STATUS_SUCCESS;
  158. switch (attr)
  159. {
  160. case IEEE802154_ATTR_MAC_PANID:
  161. {
  162. mac802154_setpanid(priv, attrval->mac.panid);
  163. }
  164. break;
  165. case IEEE802154_ATTR_MAC_SADDR:
  166. {
  167. mac802154_setsaddr(priv, attrval->mac.saddr);
  168. }
  169. break;
  170. case IEEE802154_ATTR_MAC_EADDR:
  171. {
  172. /* macExtendedAddress is a read-only attribute */
  173. ret = IEEE802154_STATUS_DENIED;
  174. }
  175. break;
  176. case IEEE802154_ATTR_MAC_COORD_SADDR:
  177. {
  178. mac802154_setcoordsaddr(priv, attrval->mac.coordsaddr);
  179. }
  180. break;
  181. case IEEE802154_ATTR_MAC_COORD_EADDR:
  182. {
  183. mac802154_setcoordeaddr(priv, attrval->mac.coordeaddr);
  184. }
  185. break;
  186. case IEEE802154_ATTR_MAC_ASSOCIATION_PERMIT:
  187. {
  188. priv->sfspec.assocpermit = attrval->mac.assocpermit;
  189. priv->beaconupdate = true;
  190. }
  191. break;
  192. case IEEE802154_ATTR_MAC_RESPONSE_WAIT_TIME:
  193. {
  194. priv->resp_waittime = attrval->mac.resp_waittime;
  195. }
  196. break;
  197. case IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE:
  198. {
  199. mac802154_setrxonidle(priv, attrval->mac.rxonidle);
  200. }
  201. break;
  202. case IEEE802154_ATTR_MAC_PROMISCUOUS_MODE:
  203. {
  204. ret = priv->radio->setattr(priv->radio, attr, attrval);
  205. if (ret == 0)
  206. {
  207. priv->promisc = attrval->mac.promisc_mode;
  208. }
  209. }
  210. break;
  211. case IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES:
  212. {
  213. priv->maxretries = attrval->mac.max_retries;
  214. }
  215. break;
  216. default:
  217. {
  218. /* The attribute may be handled soley in the radio driver, so pass
  219. * it along.
  220. */
  221. ret = priv->radio->setattr(priv->radio, attr, attrval);
  222. }
  223. break;
  224. }
  225. return ret;
  226. }