bss.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 wpabuf *fils_realm_info;
  39. struct dl_list anqp_elems; /* list of struct wpa_bss_anqp_elem */
  40. #endif /* CONFIG_INTERWORKING */
  41. #ifdef CONFIG_HS20
  42. struct wpabuf *hs20_capability_list;
  43. struct wpabuf *hs20_operator_friendly_name;
  44. struct wpabuf *hs20_wan_metrics;
  45. struct wpabuf *hs20_connection_capability;
  46. struct wpabuf *hs20_operating_class;
  47. struct wpabuf *hs20_osu_providers_list;
  48. #endif /* CONFIG_HS20 */
  49. };
  50. /**
  51. * struct wpa_bss - BSS table
  52. *
  53. * This structure is used to store information about neighboring BSSes in
  54. * generic format. It is mainly updated based on scan results from the driver.
  55. */
  56. struct wpa_bss {
  57. /** List entry for struct wpa_supplicant::bss */
  58. struct dl_list list;
  59. /** List entry for struct wpa_supplicant::bss_id */
  60. struct dl_list list_id;
  61. /** Unique identifier for this BSS entry */
  62. unsigned int id;
  63. /** Number of counts without seeing this BSS */
  64. unsigned int scan_miss_count;
  65. /** Index of the last scan update */
  66. unsigned int last_update_idx;
  67. /** Information flags about the BSS/IBSS (WPA_BSS_*) */
  68. unsigned int flags;
  69. /** BSSID */
  70. u8 bssid[ETH_ALEN];
  71. /** HESSID */
  72. u8 hessid[ETH_ALEN];
  73. /** SSID */
  74. u8 ssid[SSID_MAX_LEN];
  75. /** Length of SSID */
  76. size_t ssid_len;
  77. /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
  78. int freq;
  79. /** Beacon interval in TUs (host byte order) */
  80. u16 beacon_int;
  81. /** Capability information field in host byte order */
  82. u16 caps;
  83. /** Signal quality */
  84. int qual;
  85. /** Noise level */
  86. int noise;
  87. /** Signal level */
  88. int level;
  89. /** Timestamp of last Beacon/Probe Response frame */
  90. u64 tsf;
  91. /** Time of the last update (i.e., Beacon or Probe Response RX) */
  92. struct os_reltime last_update;
  93. /** Estimated throughput in kbps */
  94. unsigned int est_throughput;
  95. /** Signal-to-noise ratio in dB */
  96. int snr;
  97. /** ANQP data */
  98. struct wpa_bss_anqp *anqp;
  99. /** Length of the following IE field in octets (from Probe Response) */
  100. size_t ie_len;
  101. /** Length of the following Beacon IE field in octets */
  102. size_t beacon_ie_len;
  103. /* followed by ie_len octets of IEs */
  104. /* followed by beacon_ie_len octets of IEs */
  105. };
  106. void wpa_bss_update_start(struct wpa_supplicant *wpa_s);
  107. void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
  108. struct wpa_scan_res *res,
  109. struct os_reltime *fetch_time);
  110. void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  111. const char *reason);
  112. void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
  113. int new_scan);
  114. int wpa_bss_init(struct wpa_supplicant *wpa_s);
  115. void wpa_bss_deinit(struct wpa_supplicant *wpa_s);
  116. void wpa_bss_flush(struct wpa_supplicant *wpa_s);
  117. void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age);
  118. struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
  119. const u8 *ssid, size_t ssid_len);
  120. struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
  121. const u8 *bssid);
  122. struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s,
  123. const u8 *bssid);
  124. struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s,
  125. const u8 *dev_addr);
  126. struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id);
  127. struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s,
  128. unsigned int idf, unsigned int idl);
  129. const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie);
  130. const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type);
  131. const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss,
  132. u32 vendor_type);
  133. struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
  134. u32 vendor_type);
  135. struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
  136. u32 vendor_type);
  137. int wpa_bss_get_max_rate(const struct wpa_bss *bss);
  138. int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates);
  139. struct wpa_bss_anqp * wpa_bss_anqp_alloc(void);
  140. int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss);
  141. const u8 * wpa_bss_get_fils_cache_id(struct wpa_bss *bss);
  142. static inline int bss_is_dmg(const struct wpa_bss *bss)
  143. {
  144. return bss->freq > 45000;
  145. }
  146. /**
  147. * Test whether a BSS is a PBSS.
  148. * This checks whether a BSS is a DMG-band PBSS. PBSS is used for P2P DMG
  149. * network.
  150. */
  151. static inline int bss_is_pbss(struct wpa_bss *bss)
  152. {
  153. return bss_is_dmg(bss) &&
  154. (bss->caps & IEEE80211_CAP_DMG_MASK) == IEEE80211_CAP_DMG_PBSS;
  155. }
  156. static inline void wpa_bss_update_level(struct wpa_bss *bss, int new_level)
  157. {
  158. if (bss != NULL && new_level < 0)
  159. bss->level = new_level;
  160. }
  161. void calculate_update_time(const struct os_reltime *fetch_time,
  162. unsigned int age_ms,
  163. struct os_reltime *update_time);
  164. #endif /* BSS_H */