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