cfg802154.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. unsigned char name_assign_type,
  29. int type);
  30. void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
  31. struct net_device *dev);
  32. int (*add_virtual_intf)(struct wpan_phy *wpan_phy,
  33. const char *name,
  34. unsigned char name_assign_type,
  35. enum nl802154_iftype type,
  36. __le64 extended_addr);
  37. int (*del_virtual_intf)(struct wpan_phy *wpan_phy,
  38. struct wpan_dev *wpan_dev);
  39. int (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
  40. int (*set_cca_mode)(struct wpan_phy *wpan_phy,
  41. const struct wpan_phy_cca *cca);
  42. int (*set_pan_id)(struct wpan_phy *wpan_phy,
  43. struct wpan_dev *wpan_dev, __le16 pan_id);
  44. int (*set_short_addr)(struct wpan_phy *wpan_phy,
  45. struct wpan_dev *wpan_dev, __le16 short_addr);
  46. int (*set_backoff_exponent)(struct wpan_phy *wpan_phy,
  47. struct wpan_dev *wpan_dev, u8 min_be,
  48. u8 max_be);
  49. int (*set_max_csma_backoffs)(struct wpan_phy *wpan_phy,
  50. struct wpan_dev *wpan_dev,
  51. u8 max_csma_backoffs);
  52. int (*set_max_frame_retries)(struct wpan_phy *wpan_phy,
  53. struct wpan_dev *wpan_dev,
  54. s8 max_frame_retries);
  55. int (*set_lbt_mode)(struct wpan_phy *wpan_phy,
  56. struct wpan_dev *wpan_dev, bool mode);
  57. };
  58. struct wpan_phy_cca {
  59. enum nl802154_cca_modes mode;
  60. enum nl802154_cca_opts opt;
  61. };
  62. struct wpan_phy {
  63. struct mutex pib_lock;
  64. /* If multiple wpan_phys are registered and you're handed e.g.
  65. * a regular netdev with assigned ieee802154_ptr, you won't
  66. * know whether it points to a wpan_phy your driver has registered
  67. * or not. Assign this to something global to your driver to
  68. * help determine whether you own this wpan_phy or not.
  69. */
  70. const void *privid;
  71. /*
  72. * This is a PIB according to 802.15.4-2011.
  73. * We do not provide timing-related variables, as they
  74. * aren't used outside of driver
  75. */
  76. u8 current_channel;
  77. u8 current_page;
  78. u32 channels_supported[IEEE802154_MAX_PAGE + 1];
  79. s8 transmit_power;
  80. struct wpan_phy_cca cca;
  81. __le64 perm_extended_addr;
  82. s32 cca_ed_level;
  83. /* PHY depended MAC PIB values */
  84. /* 802.15.4 acronym: Tdsym in usec */
  85. u8 symbol_duration;
  86. /* lifs and sifs periods timing */
  87. u16 lifs_period;
  88. u16 sifs_period;
  89. struct device dev;
  90. char priv[0] __aligned(NETDEV_ALIGN);
  91. };
  92. struct wpan_dev {
  93. struct wpan_phy *wpan_phy;
  94. int iftype;
  95. /* the remainder of this struct should be private to cfg802154 */
  96. struct list_head list;
  97. struct net_device *netdev;
  98. u32 identifier;
  99. /* MAC PIB */
  100. __le16 pan_id;
  101. __le16 short_addr;
  102. __le64 extended_addr;
  103. /* MAC BSN field */
  104. u8 bsn;
  105. /* MAC DSN field */
  106. u8 dsn;
  107. u8 min_be;
  108. u8 max_be;
  109. u8 csma_retries;
  110. s8 frame_retries;
  111. bool lbt;
  112. bool promiscuous_mode;
  113. };
  114. #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
  115. struct wpan_phy *
  116. wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
  117. static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
  118. {
  119. phy->dev.parent = dev;
  120. }
  121. int wpan_phy_register(struct wpan_phy *phy);
  122. void wpan_phy_unregister(struct wpan_phy *phy);
  123. void wpan_phy_free(struct wpan_phy *phy);
  124. /* Same semantics as for class_for_each_device */
  125. int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
  126. static inline void *wpan_phy_priv(struct wpan_phy *phy)
  127. {
  128. BUG_ON(!phy);
  129. return &phy->priv;
  130. }
  131. struct wpan_phy *wpan_phy_find(const char *str);
  132. static inline void wpan_phy_put(struct wpan_phy *phy)
  133. {
  134. put_device(&phy->dev);
  135. }
  136. static inline const char *wpan_phy_name(struct wpan_phy *phy)
  137. {
  138. return dev_name(&phy->dev);
  139. }
  140. #endif /* __NET_CFG802154_H */