mac802154.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * IEEE802.15.4-2003 specification
  3. *
  4. * Copyright (C) 2007-2012 Siemens AG
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef NET_MAC802154_H
  17. #define NET_MAC802154_H
  18. #include <net/af_ieee802154.h>
  19. #include <linux/ieee802154.h>
  20. #include <linux/skbuff.h>
  21. #include <net/cfg802154.h>
  22. /* General MAC frame format:
  23. * 2 bytes: Frame Control
  24. * 1 byte: Sequence Number
  25. * 20 bytes: Addressing fields
  26. * 14 bytes: Auxiliary Security Header
  27. */
  28. #define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14)
  29. /* The following flags are used to indicate changed address settings from
  30. * the stack to the hardware.
  31. */
  32. /* indicates that the Short Address changed */
  33. #define IEEE802154_AFILT_SADDR_CHANGED 0x00000001
  34. /* indicates that the IEEE Address changed */
  35. #define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002
  36. /* indicates that the PAN ID changed */
  37. #define IEEE802154_AFILT_PANID_CHANGED 0x00000004
  38. /* indicates that PAN Coordinator status changed */
  39. #define IEEE802154_AFILT_PANC_CHANGED 0x00000008
  40. struct ieee802154_hw_addr_filt {
  41. __le16 pan_id; /* Each independent PAN selects a unique
  42. * identifier. This PAN id allows communication
  43. * between devices within a network using short
  44. * addresses and enables transmissions between
  45. * devices across independent networks.
  46. */
  47. __le16 short_addr;
  48. __le64 ieee_addr;
  49. u8 pan_coord;
  50. };
  51. struct ieee802154_vif {
  52. int type;
  53. /* must be last */
  54. u8 drv_priv[0] __aligned(sizeof(void *));
  55. };
  56. struct ieee802154_hw {
  57. /* filled by the driver */
  58. int extra_tx_headroom;
  59. u32 flags;
  60. struct device *parent;
  61. /* filled by mac802154 core */
  62. struct ieee802154_hw_addr_filt hw_filt;
  63. void *priv;
  64. struct wpan_phy *phy;
  65. size_t vif_data_size;
  66. };
  67. /* Checksum is in hardware and is omitted from a packet
  68. *
  69. * These following flags are used to indicate hardware capabilities to
  70. * the stack. Generally, flags here should have their meaning
  71. * done in a way that the simplest hardware doesn't need setting
  72. * any particular flags. There are some exceptions to this rule,
  73. * however, so you are advised to review these flags carefully.
  74. */
  75. /* Indicates that xmitter will add FCS on it's own. */
  76. #define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001
  77. /* Indicates that receiver will autorespond with ACK frames. */
  78. #define IEEE802154_HW_AACK 0x00000002
  79. /* Indicates that transceiver will support transmit power setting. */
  80. #define IEEE802154_HW_TXPOWER 0x00000004
  81. /* Indicates that transceiver will support listen before transmit. */
  82. #define IEEE802154_HW_LBT 0x00000008
  83. /* Indicates that transceiver will support cca mode setting. */
  84. #define IEEE802154_HW_CCA_MODE 0x00000010
  85. /* Indicates that transceiver will support cca ed level setting. */
  86. #define IEEE802154_HW_CCA_ED_LEVEL 0x00000020
  87. /* Indicates that transceiver will support csma (max_be, min_be, csma retries)
  88. * settings. */
  89. #define IEEE802154_HW_CSMA_PARAMS 0x00000040
  90. /* Indicates that transceiver will support ARET frame retries setting. */
  91. #define IEEE802154_HW_FRAME_RETRIES 0x00000080
  92. /* Indicates that transceiver will support hardware address filter setting. */
  93. #define IEEE802154_HW_AFILT 0x00000100
  94. /* Indicates that transceiver will support promiscuous mode setting. */
  95. #define IEEE802154_HW_PROMISCUOUS 0x00000200
  96. /* Indicates that receiver omits FCS. */
  97. #define IEEE802154_HW_RX_OMIT_CKSUM 0x00000400
  98. /* Indicates that receiver will not filter frames with bad checksum. */
  99. #define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000800
  100. /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
  101. #define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \
  102. IEEE802154_HW_RX_OMIT_CKSUM)
  103. /* This groups the most common CSMA support fields into one. */
  104. #define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \
  105. IEEE802154_HW_CCA_ED_LEVEL | \
  106. IEEE802154_HW_CSMA_PARAMS)
  107. /* This groups the most common ARET support fields into one. */
  108. #define IEEE802154_HW_ARET (IEEE802154_HW_CSMA | \
  109. IEEE802154_HW_FRAME_RETRIES)
  110. /* struct ieee802154_ops - callbacks from mac802154 to the driver
  111. *
  112. * This structure contains various callbacks that the driver may
  113. * handle or, in some cases, must handle, for example to transmit
  114. * a frame.
  115. *
  116. * start: Handler that 802.15.4 module calls for device initialization.
  117. * This function is called before the first interface is attached.
  118. *
  119. * stop: Handler that 802.15.4 module calls for device cleanup.
  120. * This function is called after the last interface is removed.
  121. *
  122. * xmit_sync:
  123. * Handler that 802.15.4 module calls for each transmitted frame.
  124. * skb cntains the buffer starting from the IEEE 802.15.4 header.
  125. * The low-level driver should send the frame based on available
  126. * configuration. This is called by a workqueue and useful for
  127. * synchronous 802.15.4 drivers.
  128. * This function should return zero or negative errno.
  129. *
  130. * WARNING:
  131. * This will be deprecated soon. We don't accept synced xmit callbacks
  132. * drivers anymore.
  133. *
  134. * xmit_async:
  135. * Handler that 802.15.4 module calls for each transmitted frame.
  136. * skb cntains the buffer starting from the IEEE 802.15.4 header.
  137. * The low-level driver should send the frame based on available
  138. * configuration.
  139. * This function should return zero or negative errno.
  140. *
  141. * ed: Handler that 802.15.4 module calls for Energy Detection.
  142. * This function should place the value for detected energy
  143. * (usually device-dependant) in the level pointer and return
  144. * either zero or negative errno. Called with pib_lock held.
  145. *
  146. * set_channel:
  147. * Set radio for listening on specific channel.
  148. * Set the device for listening on specified channel.
  149. * Returns either zero, or negative errno. Called with pib_lock held.
  150. *
  151. * set_hw_addr_filt:
  152. * Set radio for listening on specific address.
  153. * Set the device for listening on specified address.
  154. * Returns either zero, or negative errno.
  155. *
  156. * set_txpower:
  157. * Set radio transmit power in dB. Called with pib_lock held.
  158. * Returns either zero, or negative errno.
  159. *
  160. * set_lbt
  161. * Enables or disables listen before talk on the device. Called with
  162. * pib_lock held.
  163. * Returns either zero, or negative errno.
  164. *
  165. * set_cca_mode
  166. * Sets the CCA mode used by the device. Called with pib_lock held.
  167. * Returns either zero, or negative errno.
  168. *
  169. * set_cca_ed_level
  170. * Sets the CCA energy detection threshold in dBm. Called with pib_lock
  171. * held.
  172. * Returns either zero, or negative errno.
  173. *
  174. * set_csma_params
  175. * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
  176. * Returns either zero, or negative errno.
  177. *
  178. * set_frame_retries
  179. * Sets the retransmission attempt limit. Called with pib_lock held.
  180. * Returns either zero, or negative errno.
  181. *
  182. * set_promiscuous_mode
  183. * Enables or disable promiscuous mode.
  184. */
  185. struct ieee802154_ops {
  186. struct module *owner;
  187. int (*start)(struct ieee802154_hw *hw);
  188. void (*stop)(struct ieee802154_hw *hw);
  189. int (*xmit_sync)(struct ieee802154_hw *hw,
  190. struct sk_buff *skb);
  191. int (*xmit_async)(struct ieee802154_hw *hw,
  192. struct sk_buff *skb);
  193. int (*ed)(struct ieee802154_hw *hw, u8 *level);
  194. int (*set_channel)(struct ieee802154_hw *hw, u8 page,
  195. u8 channel);
  196. int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
  197. struct ieee802154_hw_addr_filt *filt,
  198. unsigned long changed);
  199. int (*set_txpower)(struct ieee802154_hw *hw, int db);
  200. int (*set_lbt)(struct ieee802154_hw *hw, bool on);
  201. int (*set_cca_mode)(struct ieee802154_hw *hw,
  202. const struct wpan_phy_cca *cca);
  203. int (*set_cca_ed_level)(struct ieee802154_hw *hw,
  204. s32 level);
  205. int (*set_csma_params)(struct ieee802154_hw *hw,
  206. u8 min_be, u8 max_be, u8 retries);
  207. int (*set_frame_retries)(struct ieee802154_hw *hw,
  208. s8 retries);
  209. int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
  210. const bool on);
  211. };
  212. /**
  213. * ieee802154_be64_to_le64 - copies and convert be64 to le64
  214. * @le64_dst: le64 destination pointer
  215. * @be64_src: be64 source pointer
  216. */
  217. static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
  218. {
  219. __le64 tmp = (__force __le64)swab64p(be64_src);
  220. memcpy(le64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
  221. }
  222. /**
  223. * ieee802154_le64_to_be64 - copies and convert le64 to be64
  224. * @be64_dst: be64 destination pointer
  225. * @le64_src: le64 source pointer
  226. */
  227. static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
  228. {
  229. __be64 tmp = (__force __be64)swab64p(le64_src);
  230. memcpy(be64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
  231. }
  232. /* Basic interface to register ieee802154 hwice */
  233. struct ieee802154_hw *
  234. ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
  235. void ieee802154_free_hw(struct ieee802154_hw *hw);
  236. int ieee802154_register_hw(struct ieee802154_hw *hw);
  237. void ieee802154_unregister_hw(struct ieee802154_hw *hw);
  238. void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
  239. void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
  240. u8 lqi);
  241. void ieee802154_wake_queue(struct ieee802154_hw *hw);
  242. void ieee802154_stop_queue(struct ieee802154_hw *hw);
  243. void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
  244. bool ifs_handling);
  245. #endif /* NET_MAC802154_H */