ieee802154_netdev.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * An interface between IEEE802.15.4 device and rest of the kernel.
  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. * Written by:
  20. * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
  21. * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
  22. * Maxim Osipov <maxim.osipov@siemens.com>
  23. * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
  24. * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
  25. */
  26. #ifndef IEEE802154_NETDEVICE_H
  27. #define IEEE802154_NETDEVICE_H
  28. #include <net/af_ieee802154.h>
  29. /*
  30. * A control block of skb passed between the ARPHRD_IEEE802154 device
  31. * and other stack parts.
  32. */
  33. struct ieee802154_mac_cb {
  34. u8 lqi;
  35. struct ieee802154_addr sa;
  36. struct ieee802154_addr da;
  37. u8 flags;
  38. u8 seq;
  39. };
  40. static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
  41. {
  42. return (struct ieee802154_mac_cb *)skb->cb;
  43. }
  44. #define MAC_CB_FLAG_TYPEMASK ((1 << 3) - 1)
  45. #define MAC_CB_FLAG_ACKREQ (1 << 3)
  46. #define MAC_CB_FLAG_SECEN (1 << 4)
  47. #define MAC_CB_FLAG_INTRAPAN (1 << 5)
  48. static inline int mac_cb_is_ackreq(struct sk_buff *skb)
  49. {
  50. return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ;
  51. }
  52. static inline int mac_cb_is_secen(struct sk_buff *skb)
  53. {
  54. return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN;
  55. }
  56. static inline int mac_cb_is_intrapan(struct sk_buff *skb)
  57. {
  58. return mac_cb(skb)->flags & MAC_CB_FLAG_INTRAPAN;
  59. }
  60. static inline int mac_cb_type(struct sk_buff *skb)
  61. {
  62. return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK;
  63. }
  64. #define IEEE802154_MAC_SCAN_ED 0
  65. #define IEEE802154_MAC_SCAN_ACTIVE 1
  66. #define IEEE802154_MAC_SCAN_PASSIVE 2
  67. #define IEEE802154_MAC_SCAN_ORPHAN 3
  68. struct wpan_phy;
  69. /*
  70. * This should be located at net_device->ml_priv
  71. *
  72. * get_phy should increment the reference counting on returned phy.
  73. * Use wpan_wpy_put to put that reference.
  74. */
  75. struct ieee802154_mlme_ops {
  76. /* The following fields are optional (can be NULL). */
  77. int (*assoc_req)(struct net_device *dev,
  78. struct ieee802154_addr *addr,
  79. u8 channel, u8 page, u8 cap);
  80. int (*assoc_resp)(struct net_device *dev,
  81. struct ieee802154_addr *addr,
  82. u16 short_addr, u8 status);
  83. int (*disassoc_req)(struct net_device *dev,
  84. struct ieee802154_addr *addr,
  85. u8 reason);
  86. int (*start_req)(struct net_device *dev,
  87. struct ieee802154_addr *addr,
  88. u8 channel, u8 page, u8 bcn_ord, u8 sf_ord,
  89. u8 pan_coord, u8 blx, u8 coord_realign);
  90. int (*scan_req)(struct net_device *dev,
  91. u8 type, u32 channels, u8 page, u8 duration);
  92. /* The fields below are required. */
  93. struct wpan_phy *(*get_phy)(const struct net_device *dev);
  94. /*
  95. * FIXME: these should become the part of PIB/MIB interface.
  96. * However we still don't have IB interface of any kind
  97. */
  98. u16 (*get_pan_id)(const struct net_device *dev);
  99. u16 (*get_short_addr)(const struct net_device *dev);
  100. u8 (*get_dsn)(const struct net_device *dev);
  101. };
  102. /* The IEEE 802.15.4 standard defines 2 type of the devices:
  103. * - FFD - full functionality device
  104. * - RFD - reduce functionality device
  105. *
  106. * So 2 sets of mlme operations are needed
  107. */
  108. struct ieee802154_reduced_mlme_ops {
  109. struct wpan_phy *(*get_phy)(const struct net_device *dev);
  110. };
  111. static inline struct ieee802154_mlme_ops *
  112. ieee802154_mlme_ops(const struct net_device *dev)
  113. {
  114. return dev->ml_priv;
  115. }
  116. static inline struct ieee802154_reduced_mlme_ops *
  117. ieee802154_reduced_mlme_ops(const struct net_device *dev)
  118. {
  119. return dev->ml_priv;
  120. }
  121. #endif