mac802154.h 9.4 KB

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