mac802154.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #ifndef NET_MAC802154_H
  20. #define NET_MAC802154_H
  21. #include <net/af_ieee802154.h>
  22. #include <linux/skbuff.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 IEEE802515_AFILT_SADDR_CHANGED 0x00000001
  35. /* indicates that the IEEE Address changed */
  36. #define IEEE802515_AFILT_IEEEADDR_CHANGED 0x00000002
  37. /* indicates that the PAN ID changed */
  38. #define IEEE802515_AFILT_PANID_CHANGED 0x00000004
  39. /* indicates that PAN Coordinator status changed */
  40. #define IEEE802515_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_dev {
  53. /* filled by the driver */
  54. int extra_tx_headroom;
  55. u32 flags;
  56. struct device *parent;
  57. /* filled by mac802154 core */
  58. struct ieee802154_hw_addr_filt hw_filt;
  59. void *priv;
  60. struct wpan_phy *phy;
  61. };
  62. /* Checksum is in hardware and is omitted from a packet
  63. *
  64. * These following flags are used to indicate hardware capabilities to
  65. * the stack. Generally, flags here should have their meaning
  66. * done in a way that the simplest hardware doesn't need setting
  67. * any particular flags. There are some exceptions to this rule,
  68. * however, so you are advised to review these flags carefully.
  69. */
  70. /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
  71. #define IEEE802154_HW_OMIT_CKSUM 0x00000001
  72. /* Indicates that receiver will autorespond with ACK frames. */
  73. #define IEEE802154_HW_AACK 0x00000002
  74. /* struct ieee802154_ops - callbacks from mac802154 to the driver
  75. *
  76. * This structure contains various callbacks that the driver may
  77. * handle or, in some cases, must handle, for example to transmit
  78. * a frame.
  79. *
  80. * start: Handler that 802.15.4 module calls for device initialization.
  81. * This function is called before the first interface is attached.
  82. *
  83. * stop: Handler that 802.15.4 module calls for device cleanup.
  84. * This function is called after the last interface is removed.
  85. *
  86. * xmit: Handler that 802.15.4 module calls for each transmitted frame.
  87. * skb cntains the buffer starting from the IEEE 802.15.4 header.
  88. * The low-level driver should send the frame based on available
  89. * configuration.
  90. * This function should return zero or negative errno. Called with
  91. * pib_lock held.
  92. *
  93. * ed: Handler that 802.15.4 module calls for Energy Detection.
  94. * This function should place the value for detected energy
  95. * (usually device-dependant) in the level pointer and return
  96. * either zero or negative errno. Called with pib_lock held.
  97. *
  98. * set_channel:
  99. * Set radio for listening on specific channel.
  100. * Set the device for listening on specified channel.
  101. * Returns either zero, or negative errno. Called with pib_lock held.
  102. *
  103. * set_hw_addr_filt:
  104. * Set radio for listening on specific address.
  105. * Set the device for listening on specified address.
  106. * Returns either zero, or negative errno.
  107. *
  108. * set_txpower:
  109. * Set radio transmit power in dB. Called with pib_lock held.
  110. * Returns either zero, or negative errno.
  111. *
  112. * set_lbt
  113. * Enables or disables listen before talk on the device. Called with
  114. * pib_lock held.
  115. * Returns either zero, or negative errno.
  116. *
  117. * set_cca_mode
  118. * Sets the CCA mode used by the device. Called with pib_lock held.
  119. * Returns either zero, or negative errno.
  120. *
  121. * set_cca_ed_level
  122. * Sets the CCA energy detection threshold in dBm. Called with pib_lock
  123. * held.
  124. * Returns either zero, or negative errno.
  125. *
  126. * set_csma_params
  127. * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
  128. * Returns either zero, or negative errno.
  129. *
  130. * set_frame_retries
  131. * Sets the retransmission attempt limit. Called with pib_lock held.
  132. * Returns either zero, or negative errno.
  133. */
  134. struct ieee802154_ops {
  135. struct module *owner;
  136. int (*start)(struct ieee802154_dev *dev);
  137. void (*stop)(struct ieee802154_dev *dev);
  138. int (*xmit)(struct ieee802154_dev *dev,
  139. struct sk_buff *skb);
  140. int (*ed)(struct ieee802154_dev *dev, u8 *level);
  141. int (*set_channel)(struct ieee802154_dev *dev,
  142. int page,
  143. int channel);
  144. int (*set_hw_addr_filt)(struct ieee802154_dev *dev,
  145. struct ieee802154_hw_addr_filt *filt,
  146. unsigned long changed);
  147. int (*ieee_addr)(struct ieee802154_dev *dev, __le64 addr);
  148. int (*set_txpower)(struct ieee802154_dev *dev, int db);
  149. int (*set_lbt)(struct ieee802154_dev *dev, bool on);
  150. int (*set_cca_mode)(struct ieee802154_dev *dev, u8 mode);
  151. int (*set_cca_ed_level)(struct ieee802154_dev *dev,
  152. s32 level);
  153. int (*set_csma_params)(struct ieee802154_dev *dev,
  154. u8 min_be, u8 max_be, u8 retries);
  155. int (*set_frame_retries)(struct ieee802154_dev *dev,
  156. s8 retries);
  157. };
  158. /* Basic interface to register ieee802154 device */
  159. struct ieee802154_dev *
  160. ieee802154_alloc_device(size_t priv_data_len, struct ieee802154_ops *ops);
  161. void ieee802154_free_device(struct ieee802154_dev *dev);
  162. int ieee802154_register_device(struct ieee802154_dev *dev);
  163. void ieee802154_unregister_device(struct ieee802154_dev *dev);
  164. void ieee802154_rx_irqsafe(struct ieee802154_dev *dev, struct sk_buff *skb,
  165. u8 lqi);
  166. #endif /* NET_MAC802154_H */