bss.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * BSS table
  3. * Copyright (c) 2009-2015, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef BSS_H
  9. #define BSS_H
  10. struct wpa_scan_res;
  11. #define WPA_BSS_QUAL_INVALID BIT(0)
  12. #define WPA_BSS_NOISE_INVALID BIT(1)
  13. #define WPA_BSS_LEVEL_INVALID BIT(2)
  14. #define WPA_BSS_LEVEL_DBM BIT(3)
  15. #define WPA_BSS_AUTHENTICATED BIT(4)
  16. #define WPA_BSS_ASSOCIATED BIT(5)
  17. #define WPA_BSS_ANQP_FETCH_TRIED BIT(6)
  18. struct wpa_bss_anqp_elem {
  19. struct dl_list list;
  20. u16 infoid;
  21. struct wpabuf *payload;
  22. };
  23. /**
  24. * struct wpa_bss_anqp - ANQP data for a BSS entry (struct wpa_bss)
  25. */
  26. struct wpa_bss_anqp {
  27. /** Number of BSS entries referring to this ANQP data instance */
  28. unsigned int users;
  29. #ifdef CONFIG_INTERWORKING
  30. struct wpabuf *capability_list;
  31. struct wpabuf *venue_name;
  32. struct wpabuf *network_auth_type;
  33. struct wpabuf *roaming_consortium;
  34. struct wpabuf *ip_addr_type_availability;
  35. struct wpabuf *nai_realm;
  36. struct wpabuf *anqp_3gpp;
  37. struct wpabuf *domain_name;
  38. struct dl_list anqp_elems; /* list of struct wpa_bss_anqp_elem */
  39. #endif /* CONFIG_INTERWORKING */
  40. #ifdef CONFIG_HS20
  41. struct wpabuf *hs20_capability_list;
  42. struct wpabuf *hs20_operator_friendly_name;
  43. struct wpabuf *hs20_wan_metrics;
  44. struct wpabuf *hs20_connection_capability;
  45. struct wpabuf *hs20_operating_class;
  46. struct wpabuf *hs20_osu_providers_list;
  47. #endif /* CONFIG_HS20 */
  48. };
  49. /**
  50. * struct wpa_bss - BSS table
  51. *
  52. * This structure is used to store information about neighboring BSSes in
  53. * generic format. It is mainly updated based on scan results from the driver.
  54. */
  55. struct wpa_bss {
  56. /** List entry for struct wpa_supplicant::bss */
  57. struct dl_list list;
  58. /** List entry for struct wpa_supplicant::bss_id */
  59. struct dl_list list_id;
  60. /** Unique identifier for this BSS entry */
  61. unsigned int id;
  62. /** Number of counts without seeing this BSS */
  63. unsigned int scan_miss_count;
  64. /** Index of the last scan update */
  65. unsigned int last_update_idx;
  66. /** Information flags about the BSS/IBSS (WPA_BSS_*) */
  67. unsigned int flags;
  68. /** BSSID */
  69. u8 bssid[ETH_ALEN];
  70. /** HESSID */
  71. u8 hessid[ETH_ALEN];
  72. /** SSID */
  73. u8 ssid[SSID_MAX_LEN];
  74. /** Length of SSID */
  75. size_t ssid_len;
  76. /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
  77. int freq;
  78. /** Beacon interval in TUs (host byte order) */
  79. u16 beacon_int;
  80. /** Capability information field in host byte order */
  81. u16 caps;
  82. /** Signal quality */
  83. int qual;
  84. /** Noise level */
  85. int noise;
  86. /** Signal level */
  87. int level;
  88. /** Timestamp of last Beacon/Probe Response frame */
  89. u64 tsf;
  90. /** Time of the last update (i.e., Beacon or Probe Response RX) */
  91. struct os_reltime last_update;
  92. /** Estimated throughput in kbps */
  93. unsigned int est_throughput;
  94. /** Signal-to-noise ratio in dB */
  95. int snr;
  96. /** ANQP data */
  97. struct wpa_bss_anqp *anqp;
  98. /** Length of the following IE field in octets (from Probe Response) */
  99. size_t ie_len;
  100. /** Length of the following Beacon IE field in octets */
  101. size_t beacon_ie_len;
  102. /* followed by ie_len octets of IEs */
  103. /* followed by beacon_ie_len octets of IEs */
  104. };
  105. void wpa_bss_update_start(struct wpa_supplicant *wpa_s);
  106. void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
  107. struct wpa_scan_res *res,
  108. struct os_reltime *fetch_time);
  109. void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
  110. int new_scan);
  111. int wpa_bss_init(struct wpa_supplicant *wpa_s);
  112. void wpa_bss_deinit(struct wpa_supplicant *wpa_s);
  113. void wpa_bss_flush(struct wpa_supplicant *wpa_s);
  114. void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age);
  115. struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
  116. const u8 *ssid, size_t ssid_len);
  117. struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
  118. const u8 *bssid);
  119. struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s,
  120. const u8 *bssid);
  121. struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s,
  122. const u8 *dev_addr);
  123. struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id);
  124. struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s,
  125. unsigned int idf, unsigned int idl);
  126. const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie);
  127. const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type);
  128. const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss,
  129. u32 vendor_type);
  130. struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
  131. u32 vendor_type);
  132. struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
  133. u32 vendor_type);
  134. int wpa_bss_get_max_rate(const struct wpa_bss *bss);
  135. int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates);
  136. struct wpa_bss_anqp * wpa_bss_anqp_alloc(void);
  137. int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss);
  138. static inline int bss_is_dmg(const struct wpa_bss *bss)
  139. {
  140. return bss->freq > 45000;
  141. }
  142. /**
  143. * Test whether a BSS is a PBSS.
  144. * This checks whether a BSS is a DMG-band PBSS. PBSS is used for P2P DMG
  145. * network.
  146. */
  147. static inline int bss_is_pbss(struct wpa_bss *bss)
  148. {
  149. return bss_is_dmg(bss) &&
  150. (bss->caps & IEEE80211_CAP_DMG_MASK) == IEEE80211_CAP_DMG_PBSS;
  151. }
  152. static inline void wpa_bss_update_level(struct wpa_bss *bss, int new_level)
  153. {
  154. if (bss != NULL && new_level < 0)
  155. bss->level = new_level;
  156. }
  157. #endif /* BSS_H */