netdev.h (8626B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2013-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #include <stdbool.h> 24 25 struct netdev; 26 struct scan_bss; 27 struct handshake_state; 28 struct eapol_sm; 29 struct mmpdu_header; 30 struct diagnostic_station_info; 31 32 #define GENERAL "General" 33 #define NETDEV_ADDRESS_RANDOMIZATION GENERAL, "AddressRandomization" 34 #define NETDEV_ROAM_THRESHOLD GENERAL, "RoamThreshold" 35 #define NETDEV_ROAM_THRESHOLD_5G GENERAL, "RoamThreshold5G" 36 #define NETDEV_CRITICAL_ROAM_THRESHOLD GENERAL, "CriticalRoamThreshold" 37 #define NETDEV_CRITICAL_ROAM_THRESHOLD_5G GENERAL, "CriticalRoamThreshold5G" 38 39 enum netdev_result { 40 NETDEV_RESULT_OK, 41 NETDEV_RESULT_AUTHENTICATION_FAILED, 42 NETDEV_RESULT_ASSOCIATION_FAILED, 43 NETDEV_RESULT_HANDSHAKE_FAILED, 44 NETDEV_RESULT_KEY_SETTING_FAILED, 45 NETDEV_RESULT_ABORTED, 46 NETDEV_RESULT_DISCONNECTED, 47 }; 48 49 enum netdev_event { 50 NETDEV_EVENT_AUTHENTICATING, 51 NETDEV_EVENT_ASSOCIATING, 52 NETDEV_EVENT_ROAMING, 53 NETDEV_EVENT_ROAMED, 54 NETDEV_EVENT_CHANNEL_SWITCHED, 55 NETDEV_EVENT_DISCONNECT_BY_AP, 56 NETDEV_EVENT_DISCONNECT_BY_SME, 57 NETDEV_EVENT_RSSI_THRESHOLD_LOW, 58 NETDEV_EVENT_RSSI_THRESHOLD_HIGH, 59 NETDEV_EVENT_RSSI_LEVEL_NOTIFY, 60 NETDEV_EVENT_PACKET_LOSS_NOTIFY, 61 NETDEV_EVENT_BEACON_LOSS_NOTIFY, 62 NETDEV_EVENT_ECC_GROUP_RETRY, 63 }; 64 65 enum netdev_watch_event { 66 NETDEV_WATCH_EVENT_NEW, 67 NETDEV_WATCH_EVENT_DEL, 68 NETDEV_WATCH_EVENT_UP, 69 NETDEV_WATCH_EVENT_DOWN, 70 NETDEV_WATCH_EVENT_NAME_CHANGE, 71 NETDEV_WATCH_EVENT_ADDRESS_CHANGE, 72 NETDEV_WATCH_EVENT_IFTYPE_CHANGE, 73 }; 74 75 /* Mirror definitions from nl80211.h to make conversions simpler */ 76 enum netdev_iftype { 77 NETDEV_IFTYPE_ADHOC = 1, 78 NETDEV_IFTYPE_STATION = 2, 79 NETDEV_IFTYPE_AP = 3, 80 NETDEV_IFTYPE_P2P_CLIENT = 8, 81 NETDEV_IFTYPE_P2P_GO = 9, 82 }; 83 84 typedef void (*netdev_command_cb_t)(struct netdev *netdev, int result, 85 void *user_data); 86 /* 87 * Callback for a connection attempt. This callback is called on both success 88 * and failure. Depending on result, the event_data will have different 89 * meanings: 90 * 91 * NETDEV_RESULT_OK - unused 92 * NETDEV_RESULT_AUTHENTICATION_FAILED - MMPDU_STATUS_CODE 93 * NETDEV_RESULT_ASSOCIATION_FAILED - MMPDU_STATUS_CODE 94 * NETDEV_RESULT_HANDSHAKE_FAILED - MMPDU_REASON_CODE 95 * NETDEV_RESULT_KEY_SETTING_FAILED - unused 96 * NETDEV_RESULT_ABORTED - unused. 97 * NETDEV_RESULT_DISCONNECTED - MMPDU_REASON_CODE 98 */ 99 typedef void (*netdev_connect_cb_t)(struct netdev *netdev, 100 enum netdev_result result, 101 void *event_data, 102 void *user_data); 103 /* 104 * Notify function for netdev events. Depending on the event type, event_data 105 * will have different meanings: 106 * 107 * NETDEV_EVENT_AUTHENTICATING - unused 108 * NETDEV_EVENT_ASSOCIATING - unused 109 * NETDEV_EVENT_DISCONNECT_BY_AP - MMPDU_REASON_CODE 110 * NETDEV_EVENT_DISCONNECT_BY_SME - MMPDU_REASON_CODE 111 * NETDEV_EVENT_RSSI_THRESHOLD_LOW - unused 112 * NETDEV_EVENT_RSSI_THRESHOLD_HIGH - unused 113 * NETDEV_EVENT_RSSI_LEVEL_NOTIFY - rssi level index (uint8_t) 114 */ 115 typedef void (*netdev_event_func_t)(struct netdev *netdev, 116 enum netdev_event event, 117 void *event_data, 118 void *user_data); 119 typedef void (*netdev_disconnect_cb_t)(struct netdev *netdev, bool result, 120 void *user_data); 121 typedef void (*netdev_watch_func_t)(struct netdev *netdev, 122 enum netdev_watch_event event, 123 void *user_data); 124 typedef void (*netdev_destroy_func_t)(void *user_data); 125 typedef void (*netdev_neighbor_report_cb_t)(struct netdev *netdev, int err, 126 const uint8_t *reports, 127 size_t reports_len, void *user_data); 128 typedef void (*netdev_preauthenticate_cb_t)(struct netdev *netdev, 129 enum netdev_result result, 130 const uint8_t *pmk, void *user_data); 131 typedef void (*netdev_station_watch_func_t)(struct netdev *netdev, 132 const uint8_t *mac, bool added, 133 void *user_data); 134 135 typedef void (*netdev_get_station_cb_t)( 136 const struct diagnostic_station_info *info, 137 void *user_data); 138 139 const char *netdev_iftype_to_string(uint32_t iftype); 140 141 typedef void (*netdev_ft_over_ds_cb_t)(struct netdev *netdev, 142 uint16_t status, const uint8_t *bssid, 143 void *user_data); 144 145 struct wiphy *netdev_get_wiphy(struct netdev *netdev); 146 const uint8_t *netdev_get_address(struct netdev *netdev); 147 uint32_t netdev_get_ifindex(struct netdev *netdev); 148 uint64_t netdev_get_wdev_id(struct netdev *netdev); 149 enum netdev_iftype netdev_get_iftype(struct netdev *netdev); 150 int netdev_set_iftype(struct netdev *netdev, enum netdev_iftype type, 151 netdev_command_cb_t cb, void *user_data, 152 netdev_destroy_func_t destroy); 153 int netdev_set_4addr(struct netdev *netdev, bool use_4addr, 154 netdev_command_cb_t cb, void *user_data, 155 netdev_destroy_func_t destroy); 156 bool netdev_get_4addr(struct netdev *netdev); 157 const char *netdev_get_name(struct netdev *netdev); 158 bool netdev_foreach_name(bool (*visit)(const char *, void *), void *data); 159 bool netdev_get_is_up(struct netdev *netdev); 160 const char *netdev_get_path(struct netdev *netdev); 161 uint8_t netdev_get_rssi_level_idx(struct netdev *netdev); 162 int netdev_get_low_signal_threshold(uint32_t frequency); 163 164 struct handshake_state *netdev_handshake_state_new(struct netdev *netdev); 165 struct handshake_state *netdev_get_handshake(struct netdev *netdev); 166 167 int netdev_connect(struct netdev *netdev, const struct scan_bss *bss, 168 struct handshake_state *hs, 169 netdev_event_func_t event_filter, 170 netdev_connect_cb_t cb, void *user_data); 171 int netdev_disconnect(struct netdev *netdev, 172 netdev_disconnect_cb_t cb, void *user_data); 173 int netdev_reassociate(struct netdev *netdev, 174 const struct scan_bss *target_bss, 175 const struct scan_bss *orig_bss, 176 struct handshake_state *hs, 177 netdev_event_func_t event_filter, 178 netdev_connect_cb_t cb, void *user_data); 179 int netdev_ft_reassociate(struct netdev *netdev, 180 const struct scan_bss *target_bss, 181 const struct scan_bss *orig_bss, 182 netdev_event_func_t event_filter, 183 netdev_connect_cb_t cb, void *user_data); 184 185 int netdev_preauthenticate(struct netdev *netdev, 186 const struct scan_bss *target_bss, 187 netdev_preauthenticate_cb_t cb, 188 void *user_data); 189 190 int netdev_del_station(struct netdev *netdev, const uint8_t *sta, 191 uint16_t reason_code, bool disassociate); 192 193 int netdev_join_adhoc(struct netdev *netdev, const char *ssid, 194 struct iovec *extra_ie, size_t extra_ie_elems, 195 bool control_port, netdev_command_cb_t cb, 196 void *user_data); 197 int netdev_leave_adhoc(struct netdev *netdev, netdev_command_cb_t cb, 198 void *user_data); 199 200 int netdev_set_powered(struct netdev *netdev, bool powered, 201 netdev_command_cb_t cb, void *user_data, 202 netdev_destroy_func_t destroy); 203 204 int netdev_neighbor_report_req(struct netdev *netdev, 205 netdev_neighbor_report_cb_t cb); 206 207 int netdev_set_rssi_report_levels(struct netdev *netdev, const int8_t *levels, 208 size_t levels_num); 209 int netdev_lower_signal_threshold(struct netdev *netdev); 210 int netdev_raise_signal_threshold(struct netdev *netdev); 211 212 int netdev_get_station(struct netdev *netdev, const uint8_t *mac, 213 netdev_get_station_cb_t cb, void *user_data, 214 netdev_destroy_func_t destroy); 215 int netdev_get_current_station(struct netdev *netdev, 216 netdev_get_station_cb_t cb, void *user_data, 217 netdev_destroy_func_t destroy); 218 int netdev_get_all_stations(struct netdev *netdev, netdev_get_station_cb_t cb, 219 void *user_data, netdev_destroy_func_t destroy); 220 221 void netdev_handshake_failed(struct handshake_state *hs, uint16_t reason_code); 222 223 struct netdev *netdev_find(int ifindex); 224 225 uint32_t netdev_watch_add(netdev_watch_func_t func, 226 void *user_data, netdev_destroy_func_t destroy); 227 bool netdev_watch_remove(uint32_t id); 228 229 uint32_t netdev_station_watch_add(struct netdev *netdev, 230 netdev_station_watch_func_t func, void *user_data); 231 232 bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id); 233 234 struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, 235 const uint8_t *set_mac); 236 bool netdev_destroy(struct netdev *netdev);