pktradio.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /****************************************************************************
  2. * include/nuttx/wireless/pktradio.h
  3. *
  4. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Includes some definitions that a compatible with the LGPL GNU C Library
  8. * header file of the same name.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. * 3. Neither the name NuttX nor the names of its contributors may be
  21. * used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  32. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ****************************************************************************/
  38. #ifndef __INCLUDE_NUTTX_WIRELESS_PKTRADIO_H
  39. #define __INCLUDE_NUTTX_WIRELESS_PKTRADIO_H
  40. /****************************************************************************
  41. * Included Files
  42. ****************************************************************************/
  43. #include <nuttx/config.h>
  44. #include <nuttx/net/netdev.h>
  45. #include <nuttx/wireless/wireless.h>
  46. #ifdef CONFIG_WIRELESS_PKTRADIO
  47. /****************************************************************************
  48. * Pre-processor Definitions
  49. ****************************************************************************/
  50. /* Packet radio network device IOCTL commands. */
  51. #ifndef WL_NPKTRADIOCMDS != 3
  52. # error Incorrect setting for number of PktRadio IOCTL commands
  53. #endif
  54. /* SIOCPKTRADIOGGPROPS
  55. * Description: Get the radio properties
  56. * Input: Pointer to read-write instance of struct pktradio_ifreq_s
  57. * Output: Properties returned in struct pktradio_ifreq_s instance
  58. */
  59. #define SIOCPKTRADIOGGPROPS _WLIOC(WL_PKTRADIOFIRST)
  60. /* SIOCPKTRADIOGSNODE
  61. * Description: Set the radio node address
  62. * Input: Pointer to read-only instance of struct pktradio_ifreq_s
  63. * Output: None
  64. */
  65. #define SIOCPKTRADIOSNODE _WLIOC(WL_PKTRADIOFIRST + 1)
  66. /* SIOCPKTRADIOGGNODE
  67. * Description: Get the radio node address
  68. * Input: Pointer to read-write instance of struct pktradio_ifreq_s
  69. * Output: Node address return in struct pktradio_ifreq_s instance
  70. */
  71. #define SIOCPKTRADIOGNODE _WLIOC(WL_PKTRADIOFIRST + 2)
  72. /* Memory Pools */
  73. #define PKTRADIO_POOL_PREALLOCATED 0
  74. #define PKTRADIO_POOL_DYNAMIC 1
  75. /****************************************************************************
  76. * Public Types
  77. ****************************************************************************/
  78. /* This describes an address used by the packet radio. There is no standard
  79. * size for such an address. Hence, it is represented simply as a array of
  80. * bytes.
  81. *
  82. * NOTE: This MUST be the same as the struct netdev_varaddr_s as defined in
  83. * netdev.h. It is duplicated here for no particularly good reason other
  84. * than to maintain a clean PktRadio namespace.
  85. */
  86. struct pktradio_addr_s
  87. {
  88. uint8_t pa_addr[RADIO_MAX_ADDRLEN];
  89. uint8_t pa_addrlen; /* Length of the following address */
  90. };
  91. /* Different packet radios may have different properties. If there are
  92. * multiple packet radios, then those properties have to be queried at
  93. * run time. This information is provided to the 6LoWPAN network via the
  94. * following structure.
  95. *
  96. * NOTE: This MUST be the same as the struct radiodev_properties_s as
  97. * defined in radiodev.h. It is duplicated here with a different name in
  98. * order to avoid circular header file inclusion.
  99. */
  100. struct pktradio_properties_s
  101. {
  102. uint8_t pp_addrlen; /* Length of an address */
  103. uint8_t pp_pktlen; /* Fixed packet/frame size (up to 255) */
  104. struct pktradio_addr_s pp_mcast; /* Multicast address */
  105. struct pktradio_addr_s pp_bcast; /* Broadcast address */
  106. #ifdef CONFIG_NET_STARPOINT
  107. struct pktradio_addr_s pp_hubnode; /* Address of the hub node in a star */
  108. #endif
  109. };
  110. /* This is the structure passed with all packet radio IOCTL commands.
  111. * NOTE: This is merely a placeholder for now.
  112. */
  113. struct pktradio_ifreq_s
  114. {
  115. char pifr_name[IFNAMSIZ]; /* Network device name (e.g. "wpan0") */
  116. union
  117. {
  118. struct pktradio_addr_s pifru_hwaddr; /* Radio node address */
  119. struct pktradio_properties_s pifru_props; /* Radio properties */
  120. } pifr_u;
  121. };
  122. #define pifr_hwaddr pifr_u.pifru_hwaddr /* Radio node address */
  123. #define pifr_props pifr_u.pifru_props /* Radio properties */
  124. /* This is the form of the meta data that provides the radio-specific
  125. * information necessary to send and receive packets to and from the radio.
  126. */
  127. struct iob_s; /* Forward reference */
  128. struct pktradio_metadata_s
  129. {
  130. struct pktradio_metadata_s *pm_flink; /* Supports a singly linked list */
  131. struct pktradio_addr_s pm_src; /* Source of the packet */
  132. struct pktradio_addr_s pm_dest; /* Destination of the packet */
  133. FAR struct iob_s *pm_iob; /* Contained IOB */
  134. uint8_t pm_pool; /* See PKTRADIO_POOL_* definitions */
  135. };
  136. /****************************************************************************
  137. * Public Data
  138. ****************************************************************************/
  139. /****************************************************************************
  140. * Public Function Prototypes
  141. ****************************************************************************/
  142. /****************************************************************************
  143. * Name: pktradio_metadata_initialize
  144. *
  145. * Description:
  146. * This function initializes the meta-data allocator. This function must
  147. * be called early in the initialization sequence before any radios
  148. * begin operation.
  149. *
  150. * This function is idempotent: It may be called numerous times. The
  151. * initialization will be performed only on the first time that it is
  152. * called. Therefore, it may be called during packet radio driver
  153. * initialization, even if there are multiple packet radio drivers.
  154. *
  155. * Input Parameters:
  156. * None
  157. *
  158. * Returned Value:
  159. * None
  160. *
  161. ****************************************************************************/
  162. void pktradio_metadata_initialize(void);
  163. /****************************************************************************
  164. * Name: pktradio_metadata_allocate
  165. *
  166. * Description:
  167. * The pktradio_metadata_allocate function will get a free meta-data
  168. * structure for use by the packet radio.
  169. *
  170. * This function will first attempt to allocate from the g_free_metadata
  171. * list. If that the list is empty, then the meta-data structure will be
  172. * allocated from the dynamic memory pool.
  173. *
  174. * Input Parameters:
  175. * None
  176. *
  177. * Returned Value:
  178. * A reference to the allocated metadata structure. All user fields in this
  179. * structure have been zeroed. On a failure to allocate, NULL is
  180. * returned.
  181. *
  182. ****************************************************************************/
  183. FAR struct pktradio_metadata_s *pktradio_metadata_allocate(void);
  184. /****************************************************************************
  185. * Name: pktradio_metadata_free
  186. *
  187. * Description:
  188. * The pktradio_metadata_free function will return a metadata structure
  189. * to the free list of messages if it was a pre-allocated metadata
  190. * structure. If the metadata structure was allocated dynamically it will
  191. * be deallocated.
  192. *
  193. * Input Parameters:
  194. * metadata - metadata structure to free
  195. *
  196. * Returned Value:
  197. * None
  198. *
  199. ****************************************************************************/
  200. void pktradio_metadata_free(FAR struct pktradio_metadata_s *metadata);
  201. /****************************************************************************
  202. * Name: pktradio_loopback
  203. *
  204. * Description:
  205. * Initialize and register the Ieee802.15.4 MAC loopback network driver.
  206. *
  207. * Input Parameters:
  208. * None
  209. *
  210. * Returned Value:
  211. * OK on success; Negated errno on failure.
  212. *
  213. * Assumptions:
  214. *
  215. ****************************************************************************/
  216. #ifdef CONFIG_PKTRADIO_LOOPBACK
  217. int pktradio_loopback(void);
  218. #endif
  219. #endif /* CONFIG_WIRELESS_PKTRADIO */
  220. #endif /* __INCLUDE_NUTTX_WIRELESS_PKTRADIO_H */