driver_nl80211.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Driver interaction with Linux nl80211/cfg80211 - definitions
  3. * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2003-2004, Instant802 Networks, Inc.
  5. * Copyright (c) 2005-2006, Devicescape Software, Inc.
  6. * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright (c) 2009-2010, Atheros Communications
  8. *
  9. * This software may be distributed under the terms of the BSD license.
  10. * See README for more details.
  11. */
  12. #ifndef DRIVER_NL80211_H
  13. #define DRIVER_NL80211_H
  14. #include "nl80211_copy.h"
  15. #include "utils/list.h"
  16. #include "driver.h"
  17. #ifdef CONFIG_LIBNL20
  18. /* libnl 2.0 compatibility code */
  19. #define nl_handle nl_sock
  20. #define nl80211_handle_alloc nl_socket_alloc_cb
  21. #define nl80211_handle_destroy nl_socket_free
  22. #endif /* CONFIG_LIBNL20 */
  23. struct nl80211_global {
  24. void *ctx;
  25. struct dl_list interfaces;
  26. int if_add_ifindex;
  27. u64 if_add_wdevid;
  28. int if_add_wdevid_set;
  29. struct netlink_data *netlink;
  30. struct nl_cb *nl_cb;
  31. struct nl_handle *nl;
  32. int nl80211_id;
  33. int ioctl_sock; /* socket for ioctl() use */
  34. struct nl_handle *nl_event;
  35. };
  36. struct nl80211_wiphy_data {
  37. struct dl_list list;
  38. struct dl_list bsss;
  39. struct dl_list drvs;
  40. struct nl_handle *nl_beacons;
  41. struct nl_cb *nl_cb;
  42. int wiphy_idx;
  43. };
  44. struct i802_bss {
  45. struct wpa_driver_nl80211_data *drv;
  46. struct i802_bss *next;
  47. int ifindex;
  48. int br_ifindex;
  49. u64 wdev_id;
  50. char ifname[IFNAMSIZ + 1];
  51. char brname[IFNAMSIZ];
  52. unsigned int beacon_set:1;
  53. unsigned int added_if_into_bridge:1;
  54. unsigned int added_bridge:1;
  55. unsigned int in_deinit:1;
  56. unsigned int wdev_id_set:1;
  57. unsigned int added_if:1;
  58. unsigned int static_ap:1;
  59. u8 addr[ETH_ALEN];
  60. int freq;
  61. int bandwidth;
  62. int if_dynamic;
  63. void *ctx;
  64. struct nl_handle *nl_preq, *nl_mgmt;
  65. struct nl_cb *nl_cb;
  66. struct nl80211_wiphy_data *wiphy_data;
  67. struct dl_list wiphy_list;
  68. };
  69. struct wpa_driver_nl80211_data {
  70. struct nl80211_global *global;
  71. struct dl_list list;
  72. struct dl_list wiphy_list;
  73. char phyname[32];
  74. unsigned int wiphy_idx;
  75. u8 perm_addr[ETH_ALEN];
  76. void *ctx;
  77. int ifindex;
  78. int if_removed;
  79. int if_disabled;
  80. int ignore_if_down_event;
  81. struct rfkill_data *rfkill;
  82. struct wpa_driver_capa capa;
  83. u8 *extended_capa, *extended_capa_mask;
  84. unsigned int extended_capa_len;
  85. struct drv_nl80211_ext_capa {
  86. enum nl80211_iftype iftype;
  87. u8 *ext_capa, *ext_capa_mask;
  88. unsigned int ext_capa_len;
  89. } iface_ext_capa[NL80211_IFTYPE_MAX];
  90. unsigned int num_iface_ext_capa;
  91. int has_capability;
  92. int operstate;
  93. int scan_complete_events;
  94. enum scan_states {
  95. NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
  96. SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
  97. SCHED_SCAN_RESULTS
  98. } scan_state;
  99. u8 auth_bssid[ETH_ALEN];
  100. u8 auth_attempt_bssid[ETH_ALEN];
  101. u8 bssid[ETH_ALEN];
  102. u8 prev_bssid[ETH_ALEN];
  103. int associated;
  104. u8 ssid[SSID_MAX_LEN];
  105. size_t ssid_len;
  106. enum nl80211_iftype nlmode;
  107. enum nl80211_iftype ap_scan_as_station;
  108. unsigned int assoc_freq;
  109. int monitor_sock;
  110. int monitor_ifidx;
  111. int monitor_refcount;
  112. unsigned int disabled_11b_rates:1;
  113. unsigned int pending_remain_on_chan:1;
  114. unsigned int in_interface_list:1;
  115. unsigned int device_ap_sme:1;
  116. unsigned int poll_command_supported:1;
  117. unsigned int data_tx_status:1;
  118. unsigned int scan_for_auth:1;
  119. unsigned int retry_auth:1;
  120. unsigned int use_monitor:1;
  121. unsigned int ignore_next_local_disconnect:1;
  122. unsigned int ignore_next_local_deauth:1;
  123. unsigned int hostapd:1;
  124. unsigned int start_mode_ap:1;
  125. unsigned int start_iface_up:1;
  126. unsigned int test_use_roc_tx:1;
  127. unsigned int ignore_deauth_event:1;
  128. unsigned int vendor_cmd_test_avail:1;
  129. unsigned int roaming_vendor_cmd_avail:1;
  130. unsigned int dfs_vendor_cmd_avail:1;
  131. unsigned int have_low_prio_scan:1;
  132. unsigned int force_connect_cmd:1;
  133. unsigned int addr_changed:1;
  134. unsigned int get_features_vendor_cmd_avail:1;
  135. unsigned int set_rekey_offload:1;
  136. unsigned int p2p_go_ctwindow_supported:1;
  137. unsigned int setband_vendor_cmd_avail:1;
  138. unsigned int get_pref_freq_list:1;
  139. unsigned int set_prob_oper_freq:1;
  140. unsigned int scan_vendor_cmd_avail:1;
  141. unsigned int connect_reassoc:1;
  142. unsigned int set_wifi_conf_vendor_cmd_avail:1;
  143. u64 vendor_scan_cookie;
  144. u64 remain_on_chan_cookie;
  145. u64 send_action_cookie;
  146. #define MAX_SEND_ACTION_COOKIES 20
  147. u64 send_action_cookies[MAX_SEND_ACTION_COOKIES];
  148. unsigned int num_send_action_cookies;
  149. unsigned int last_mgmt_freq;
  150. struct wpa_driver_scan_filter *filter_ssids;
  151. size_t num_filter_ssids;
  152. struct i802_bss *first_bss;
  153. int eapol_tx_sock;
  154. int eapol_sock; /* socket for EAPOL frames */
  155. struct nl_handle *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
  156. int default_if_indices[16];
  157. /* the AP/AP_VLAN iface that is in this bridge */
  158. int default_if_indices_reason[16];
  159. int *if_indices;
  160. int *if_indices_reason;
  161. int num_if_indices;
  162. /* From failed authentication command */
  163. int auth_freq;
  164. u8 auth_bssid_[ETH_ALEN];
  165. u8 auth_ssid[SSID_MAX_LEN];
  166. size_t auth_ssid_len;
  167. int auth_alg;
  168. u8 *auth_ie;
  169. size_t auth_ie_len;
  170. u8 auth_wep_key[4][16];
  171. size_t auth_wep_key_len[4];
  172. int auth_wep_tx_keyidx;
  173. int auth_local_state_change;
  174. int auth_p2p;
  175. /*
  176. * Tells whether the last scan issued from wpa_supplicant was a normal
  177. * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
  178. * (NL80211_CMD_VENDOR). 0 if no pending scan request.
  179. */
  180. int last_scan_cmd;
  181. };
  182. struct nl_msg;
  183. void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
  184. struct nl_msg *msg, int flags, uint8_t cmd);
  185. struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
  186. struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
  187. uint8_t cmd);
  188. struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
  189. int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
  190. int (*valid_handler)(struct nl_msg *, void *),
  191. void *valid_data);
  192. int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
  193. const char *ifname, enum nl80211_iftype iftype,
  194. const u8 *addr, int wds,
  195. int (*handler)(struct nl_msg *, void *),
  196. void *arg, int use_existing);
  197. void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
  198. unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
  199. enum chan_width convert2width(int width);
  200. void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
  201. struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
  202. int ifindex);
  203. int is_ap_interface(enum nl80211_iftype nlmode);
  204. int is_sta_interface(enum nl80211_iftype nlmode);
  205. int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
  206. int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
  207. struct wpa_signal_info *sig);
  208. int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
  209. struct wpa_signal_info *sig_change);
  210. int nl80211_get_wiphy_index(struct i802_bss *bss);
  211. int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
  212. enum nl80211_iftype nlmode);
  213. int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
  214. const u8 *addr, int cmd, u16 reason_code,
  215. int local_state_change);
  216. int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
  217. void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
  218. int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
  219. const void *data, size_t len,
  220. int encrypt, int noack);
  221. int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
  222. struct hostapd_hw_modes *
  223. nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags);
  224. int process_global_event(struct nl_msg *msg, void *arg);
  225. int process_bss_event(struct nl_msg *msg, void *arg);
  226. const char * nl80211_iftype_str(enum nl80211_iftype mode);
  227. #ifdef ANDROID
  228. int android_nl_socket_set_nonblocking(struct nl_handle *handle);
  229. int android_pno_start(struct i802_bss *bss,
  230. struct wpa_driver_scan_params *params);
  231. int android_pno_stop(struct i802_bss *bss);
  232. extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
  233. size_t buf_len);
  234. #ifdef ANDROID_P2P
  235. int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
  236. int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
  237. int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
  238. int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
  239. const struct wpabuf *proberesp,
  240. const struct wpabuf *assocresp);
  241. #endif /* ANDROID_P2P */
  242. #endif /* ANDROID */
  243. /* driver_nl80211_scan.c */
  244. struct nl80211_bss_info_arg {
  245. struct wpa_driver_nl80211_data *drv;
  246. struct wpa_scan_results *res;
  247. unsigned int assoc_freq;
  248. unsigned int ibss_freq;
  249. u8 assoc_bssid[ETH_ALEN];
  250. };
  251. int bss_info_handler(struct nl_msg *msg, void *arg);
  252. void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
  253. int wpa_driver_nl80211_scan(struct i802_bss *bss,
  254. struct wpa_driver_scan_params *params);
  255. int wpa_driver_nl80211_sched_scan(void *priv,
  256. struct wpa_driver_scan_params *params);
  257. int wpa_driver_nl80211_stop_sched_scan(void *priv);
  258. struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
  259. void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
  260. int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
  261. int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
  262. struct wpa_driver_scan_params *params);
  263. int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
  264. #endif /* DRIVER_NL80211_H */