cfg802154.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/netdevice.h>
  19. #include <linux/mutex.h>
  20. #include <linux/bug.h>
  21. /* According to the IEEE 802.15.4 stadard the upper most significant bits of
  22. * the 32-bit channel bitmaps shall be used as an integer value to specify 32
  23. * possible channel pages. The lower 27 bits of the channel bit map shall be
  24. * used as a bit mask to specify channel numbers within a channel page.
  25. */
  26. #define WPAN_NUM_CHANNELS 27
  27. #define WPAN_NUM_PAGES 32
  28. struct wpan_phy;
  29. struct cfg802154_ops {
  30. struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
  31. const char *name,
  32. int type);
  33. void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
  34. struct net_device *dev);
  35. int (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
  36. int (*set_pan_id)(struct wpan_phy *wpan_phy,
  37. struct wpan_dev *wpan_dev, u16 pan_id);
  38. int (*set_short_addr)(struct wpan_phy *wpan_phy,
  39. struct wpan_dev *wpan_dev, u16 short_addr);
  40. int (*set_backoff_exponent)(struct wpan_phy *wpan_phy,
  41. struct wpan_dev *wpan_dev, u8 min_be,
  42. u8 max_be);
  43. int (*set_max_csma_backoffs)(struct wpan_phy *wpan_phy,
  44. struct wpan_dev *wpan_dev,
  45. u8 max_csma_backoffs);
  46. };
  47. struct wpan_phy {
  48. struct mutex pib_lock;
  49. /* If multiple wpan_phys are registered and you're handed e.g.
  50. * a regular netdev with assigned ieee802154_ptr, you won't
  51. * know whether it points to a wpan_phy your driver has registered
  52. * or not. Assign this to something global to your driver to
  53. * help determine whether you own this wpan_phy or not.
  54. */
  55. const void *privid;
  56. /*
  57. * This is a PIB according to 802.15.4-2011.
  58. * We do not provide timing-related variables, as they
  59. * aren't used outside of driver
  60. */
  61. u8 current_channel;
  62. u8 current_page;
  63. u32 channels_supported[32];
  64. s8 transmit_power;
  65. u8 cca_mode;
  66. __le64 perm_extended_addr;
  67. s32 cca_ed_level;
  68. struct device dev;
  69. char priv[0] __aligned(NETDEV_ALIGN);
  70. };
  71. struct wpan_dev {
  72. struct wpan_phy *wpan_phy;
  73. int iftype;
  74. /* the remainder of this struct should be private to cfg802154 */
  75. struct list_head list;
  76. struct net_device *netdev;
  77. u32 identifier;
  78. /* MAC PIB */
  79. __le16 pan_id;
  80. __le16 short_addr;
  81. __le64 extended_addr;
  82. /* MAC BSN field */
  83. u8 bsn;
  84. /* MAC DSN field */
  85. u8 dsn;
  86. u8 min_be;
  87. u8 max_be;
  88. u8 csma_retries;
  89. s8 frame_retries;
  90. bool lbt;
  91. bool promiscuous_mode;
  92. };
  93. #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
  94. struct wpan_phy *
  95. wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
  96. static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
  97. {
  98. phy->dev.parent = dev;
  99. }
  100. int wpan_phy_register(struct wpan_phy *phy);
  101. void wpan_phy_unregister(struct wpan_phy *phy);
  102. void wpan_phy_free(struct wpan_phy *phy);
  103. /* Same semantics as for class_for_each_device */
  104. int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
  105. static inline void *wpan_phy_priv(struct wpan_phy *phy)
  106. {
  107. BUG_ON(!phy);
  108. return &phy->priv;
  109. }
  110. struct wpan_phy *wpan_phy_find(const char *str);
  111. static inline void wpan_phy_put(struct wpan_phy *phy)
  112. {
  113. put_device(&phy->dev);
  114. }
  115. static inline const char *wpan_phy_name(struct wpan_phy *phy)
  116. {
  117. return dev_name(&phy->dev);
  118. }
  119. #endif /* __NET_CFG802154_H */