cfg802154.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2007, 2008, 2009 Siemens AG
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * Written by:
  14. * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
  15. */
  16. #ifndef __NET_CFG802154_H
  17. #define __NET_CFG802154_H
  18. #include <linux/ieee802154.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/mutex.h>
  21. #include <linux/bug.h>
  22. #include <net/nl802154.h>
  23. struct wpan_phy;
  24. struct wpan_phy_cca;
  25. struct cfg802154_ops {
  26. struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
  27. const char *name,
  28. int type);
  29. void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
  30. struct net_device *dev);
  31. int (*add_virtual_intf)(struct wpan_phy *wpan_phy,
  32. const char *name,
  33. enum nl802154_iftype type,
  34. __le64 extended_addr);
  35. int (*del_virtual_intf)(struct wpan_phy *wpan_phy,
  36. struct wpan_dev *wpan_dev);
  37. int (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
  38. int (*set_cca_mode)(struct wpan_phy *wpan_phy,
  39. const struct wpan_phy_cca *cca);
  40. int (*set_pan_id)(struct wpan_phy *wpan_phy,
  41. struct wpan_dev *wpan_dev, __le16 pan_id);
  42. int (*set_short_addr)(struct wpan_phy *wpan_phy,
  43. struct wpan_dev *wpan_dev, __le16 short_addr);
  44. int (*set_backoff_exponent)(struct wpan_phy *wpan_phy,
  45. struct wpan_dev *wpan_dev, u8 min_be,
  46. u8 max_be);
  47. int (*set_max_csma_backoffs)(struct wpan_phy *wpan_phy,
  48. struct wpan_dev *wpan_dev,
  49. u8 max_csma_backoffs);
  50. int (*set_max_frame_retries)(struct wpan_phy *wpan_phy,
  51. struct wpan_dev *wpan_dev,
  52. s8 max_frame_retries);
  53. int (*set_lbt_mode)(struct wpan_phy *wpan_phy,
  54. struct wpan_dev *wpan_dev, bool mode);
  55. };
  56. struct wpan_phy_cca {
  57. enum nl802154_cca_modes mode;
  58. enum nl802154_cca_opts opt;
  59. };
  60. struct wpan_phy {
  61. struct mutex pib_lock;
  62. /* If multiple wpan_phys are registered and you're handed e.g.
  63. * a regular netdev with assigned ieee802154_ptr, you won't
  64. * know whether it points to a wpan_phy your driver has registered
  65. * or not. Assign this to something global to your driver to
  66. * help determine whether you own this wpan_phy or not.
  67. */
  68. const void *privid;
  69. /*
  70. * This is a PIB according to 802.15.4-2011.
  71. * We do not provide timing-related variables, as they
  72. * aren't used outside of driver
  73. */
  74. u8 current_channel;
  75. u8 current_page;
  76. u32 channels_supported[IEEE802154_MAX_PAGE + 1];
  77. s8 transmit_power;
  78. struct wpan_phy_cca cca;
  79. __le64 perm_extended_addr;
  80. s32 cca_ed_level;
  81. /* PHY depended MAC PIB values */
  82. /* 802.15.4 acronym: Tdsym in usec */
  83. u8 symbol_duration;
  84. /* lifs and sifs periods timing */
  85. u16 lifs_period;
  86. u16 sifs_period;
  87. struct device dev;
  88. char priv[0] __aligned(NETDEV_ALIGN);
  89. };
  90. struct wpan_dev {
  91. struct wpan_phy *wpan_phy;
  92. int iftype;
  93. /* the remainder of this struct should be private to cfg802154 */
  94. struct list_head list;
  95. struct net_device *netdev;
  96. u32 identifier;
  97. /* MAC PIB */
  98. __le16 pan_id;
  99. __le16 short_addr;
  100. __le64 extended_addr;
  101. /* MAC BSN field */
  102. u8 bsn;
  103. /* MAC DSN field */
  104. u8 dsn;
  105. u8 min_be;
  106. u8 max_be;
  107. u8 csma_retries;
  108. s8 frame_retries;
  109. bool lbt;
  110. bool promiscuous_mode;
  111. };
  112. #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
  113. struct wpan_phy *
  114. wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
  115. static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
  116. {
  117. phy->dev.parent = dev;
  118. }
  119. int wpan_phy_register(struct wpan_phy *phy);
  120. void wpan_phy_unregister(struct wpan_phy *phy);
  121. void wpan_phy_free(struct wpan_phy *phy);
  122. /* Same semantics as for class_for_each_device */
  123. int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
  124. static inline void *wpan_phy_priv(struct wpan_phy *phy)
  125. {
  126. BUG_ON(!phy);
  127. return &phy->priv;
  128. }
  129. struct wpan_phy *wpan_phy_find(const char *str);
  130. static inline void wpan_phy_put(struct wpan_phy *phy)
  131. {
  132. put_device(&phy->dev);
  133. }
  134. static inline const char *wpan_phy_name(struct wpan_phy *phy)
  135. {
  136. return dev_name(&phy->dev);
  137. }
  138. #endif /* __NET_CFG802154_H */