Lines Matching refs:p2p

25 static void p2p_device_free(struct p2p_data *p2p, struct p2p_device *dev);
26 static void p2p_process_presence_req(struct p2p_data *p2p, const u8 *da,
29 static void p2p_process_presence_resp(struct p2p_data *p2p, const u8 *da,
53 void p2p_expire_peers(struct p2p_data *p2p) in p2p_expire_peers() argument
60 dl_list_for_each_safe(dev, n, &p2p->devices, struct p2p_device, list) { in p2p_expire_peers()
64 if (dev == p2p->go_neg_peer) { in p2p_expire_peers()
73 if (p2p->cfg->go_connected && in p2p_expire_peers()
74 p2p->cfg->go_connected(p2p->cfg->cb_ctx, in p2p_expire_peers()
84 for (i = 0; i < p2p->num_groups; i++) { in p2p_expire_peers()
86 p2p->groups[i], dev->info.p2p_device_addr)) in p2p_expire_peers()
89 if (i < p2p->num_groups) { in p2p_expire_peers()
98 p2p_dbg(p2p, "Expiring old peer entry " MACSTR, in p2p_expire_peers()
101 p2p_device_free(p2p, dev); in p2p_expire_peers()
141 const char * p2p_get_state_txt(struct p2p_data *p2p) in p2p_get_state_txt() argument
143 return p2p_state_txt(p2p->state); in p2p_get_state_txt()
147 struct p2ps_advertisement * p2p_get_p2ps_adv_list(struct p2p_data *p2p) in p2p_get_p2ps_adv_list() argument
149 return p2p ? p2p->p2ps_adv_list : NULL; in p2p_get_p2ps_adv_list()
153 void p2p_set_intended_addr(struct p2p_data *p2p, const u8 *intended_addr) in p2p_set_intended_addr() argument
155 if (p2p && intended_addr) in p2p_set_intended_addr()
156 os_memcpy(p2p->intended_addr, intended_addr, ETH_ALEN); in p2p_set_intended_addr()
160 u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr) in p2p_get_provisioning_info() argument
164 if (!addr || !p2p) in p2p_get_provisioning_info()
167 dev = p2p_get_device(p2p, addr); in p2p_get_provisioning_info()
175 void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr) in p2p_clear_provisioning_info() argument
179 if (!addr || !p2p) in p2p_clear_provisioning_info()
182 dev = p2p_get_device(p2p, addr); in p2p_clear_provisioning_info()
188 void p2p_set_state(struct p2p_data *p2p, int new_state) in p2p_set_state() argument
190 p2p_dbg(p2p, "State %s -> %s", in p2p_set_state()
191 p2p_state_txt(p2p->state), p2p_state_txt(new_state)); in p2p_set_state()
192 p2p->state = new_state; in p2p_set_state()
194 if (new_state == P2P_IDLE && p2p->pending_channel) { in p2p_set_state()
195 p2p_dbg(p2p, "Apply change in listen channel"); in p2p_set_state()
196 p2p->cfg->reg_class = p2p->pending_reg_class; in p2p_set_state()
197 p2p->cfg->channel = p2p->pending_channel; in p2p_set_state()
198 p2p->pending_reg_class = 0; in p2p_set_state()
199 p2p->pending_channel = 0; in p2p_set_state()
204 void p2p_set_timeout(struct p2p_data *p2p, unsigned int sec, unsigned int usec) in p2p_set_timeout() argument
206 p2p_dbg(p2p, "Set timeout (state=%s): %u.%06u sec", in p2p_set_timeout()
207 p2p_state_txt(p2p->state), sec, usec); in p2p_set_timeout()
208 eloop_cancel_timeout(p2p_state_timeout, p2p, NULL); in p2p_set_timeout()
209 eloop_register_timeout(sec, usec, p2p_state_timeout, p2p, NULL); in p2p_set_timeout()
213 void p2p_clear_timeout(struct p2p_data *p2p) in p2p_clear_timeout() argument
215 p2p_dbg(p2p, "Clear timeout (state=%s)", p2p_state_txt(p2p->state)); in p2p_clear_timeout()
216 eloop_cancel_timeout(p2p_state_timeout, p2p, NULL); in p2p_clear_timeout()
220 void p2p_go_neg_failed(struct p2p_data *p2p, int status) in p2p_go_neg_failed() argument
223 struct p2p_device *peer = p2p->go_neg_peer; in p2p_go_neg_failed()
228 eloop_cancel_timeout(p2p_go_neg_wait_timeout, p2p, NULL); in p2p_go_neg_failed()
229 if (p2p->state != P2P_SEARCH) { in p2p_go_neg_failed()
234 p2p_clear_timeout(p2p); in p2p_go_neg_failed()
235 p2p_set_state(p2p, P2P_IDLE); in p2p_go_neg_failed()
243 p2p->go_neg_peer = NULL; in p2p_go_neg_failed()
249 p2p->cfg->go_neg_completed(p2p->cfg->cb_ctx, &res); in p2p_go_neg_failed()
253 static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc) in p2p_listen_in_find() argument
259 p2p_dbg(p2p, "Starting short listen state (state=%s)", in p2p_listen_in_find()
260 p2p_state_txt(p2p->state)); in p2p_listen_in_find()
262 if (p2p->pending_listen_freq) { in p2p_listen_in_find()
264 p2p_dbg(p2p, "p2p_listen command pending already"); in p2p_listen_in_find()
268 freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); in p2p_listen_in_find()
270 p2p_dbg(p2p, "Unknown regulatory class/channel"); in p2p_listen_in_find()
276 tu = (r % ((p2p->max_disc_int - p2p->min_disc_int) + 1) + in p2p_listen_in_find()
277 p2p->min_disc_int) * 100; in p2p_listen_in_find()
278 if (p2p->max_disc_tu >= 0 && tu > (unsigned int) p2p->max_disc_tu) in p2p_listen_in_find()
279 tu = p2p->max_disc_tu; in p2p_listen_in_find()
282 if (p2p->cfg->max_listen && 1024 * tu / 1000 > p2p->cfg->max_listen) in p2p_listen_in_find()
283 tu = p2p->cfg->max_listen * 1000 / 1024; in p2p_listen_in_find()
286 p2p_dbg(p2p, "Skip listen state since duration was 0 TU"); in p2p_listen_in_find()
287 p2p_set_timeout(p2p, 0, 0); in p2p_listen_in_find()
291 ies = p2p_build_probe_resp_ies(p2p, NULL, 0); in p2p_listen_in_find()
295 p2p->pending_listen_freq = freq; in p2p_listen_in_find()
296 p2p->pending_listen_sec = 0; in p2p_listen_in_find()
297 p2p->pending_listen_usec = 1024 * tu; in p2p_listen_in_find()
299 if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, freq, 1024 * tu / 1000, in p2p_listen_in_find()
301 p2p_dbg(p2p, "Failed to start listen mode"); in p2p_listen_in_find()
302 p2p->pending_listen_freq = 0; in p2p_listen_in_find()
308 int p2p_listen(struct p2p_data *p2p, unsigned int timeout) in p2p_listen() argument
313 p2p_dbg(p2p, "Going to listen(only) state"); in p2p_listen()
315 if (p2p->pending_listen_freq) { in p2p_listen()
317 p2p_dbg(p2p, "p2p_listen command pending already"); in p2p_listen()
321 freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); in p2p_listen()
323 p2p_dbg(p2p, "Unknown regulatory class/channel"); in p2p_listen()
327 p2p->pending_listen_sec = timeout / 1000; in p2p_listen()
328 p2p->pending_listen_usec = (timeout % 1000) * 1000; in p2p_listen()
330 if (p2p->p2p_scan_running) { in p2p_listen()
331 if (p2p->start_after_scan == P2P_AFTER_SCAN_CONNECT) { in p2p_listen()
332 p2p_dbg(p2p, "p2p_scan running - connect is already pending - skip listen"); in p2p_listen()
335 p2p_dbg(p2p, "p2p_scan running - delay start of listen state"); in p2p_listen()
336 p2p->start_after_scan = P2P_AFTER_SCAN_LISTEN; in p2p_listen()
340 ies = p2p_build_probe_resp_ies(p2p, NULL, 0); in p2p_listen()
344 p2p->pending_listen_freq = freq; in p2p_listen()
346 if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, freq, timeout, ies) < 0) { in p2p_listen()
347 p2p_dbg(p2p, "Failed to start listen mode"); in p2p_listen()
348 p2p->pending_listen_freq = 0; in p2p_listen()
354 p2p_set_state(p2p, P2P_LISTEN_ONLY); in p2p_listen()
360 static void p2p_device_clear_reported(struct p2p_data *p2p) in p2p_device_clear_reported() argument
363 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_device_clear_reported()
376 struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr) in p2p_get_device() argument
379 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_get_device()
393 struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p, in p2p_get_device_interface() argument
397 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_get_device_interface()
414 static struct p2p_device * p2p_create_device(struct p2p_data *p2p, in p2p_create_device() argument
420 dev = p2p_get_device(p2p, addr); in p2p_create_device()
424 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_create_device()
430 if (count + 1 > p2p->cfg->max_peers && oldest) { in p2p_create_device()
431 p2p_dbg(p2p, "Remove oldest peer entry to make room for a new peer"); in p2p_create_device()
433 p2p_device_free(p2p, oldest); in p2p_create_device()
439 dl_list_add(&p2p->devices, &dev->list); in p2p_create_device()
461 static int p2p_add_group_clients(struct p2p_data *p2p, const u8 *go_dev_addr, in p2p_add_group_clients() argument
480 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_add_group_clients()
490 if (os_memcmp(cli->p2p_device_addr, p2p->cfg->dev_addr, in p2p_add_group_clients()
493 dev = p2p_get_device(p2p, cli->p2p_device_addr); in p2p_add_group_clients()
518 dev = p2p_create_device(p2p, cli->p2p_device_addr); in p2p_add_group_clients()
524 p2p->cfg->dev_found(p2p->cfg->cb_ctx, in p2p_add_group_clients()
543 static void p2p_copy_wps_info(struct p2p_data *p2p, struct p2p_device *dev, in p2p_copy_wps_info() argument
619 p2p_dbg(p2p, "Update peer " MACSTR in p2p_copy_wps_info()
706 int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, in p2p_add_device() argument
720 p2p_dbg(p2p, "Failed to parse P2P IE for a device entry"); in p2p_add_device()
730 p2p_dbg(p2p, "Ignore scan data without P2P Device Info or P2P Device Id"); in p2p_add_device()
735 if (!is_zero_ether_addr(p2p->peer_filter) && in p2p_add_device()
736 os_memcmp(p2p_dev_addr, p2p->peer_filter, ETH_ALEN) != 0) { in p2p_add_device()
737 p2p_dbg(p2p, "Do not add peer filter for " MACSTR in p2p_add_device()
743 dev = p2p_create_device(p2p, p2p_dev_addr); in p2p_add_device()
765 p2p_dbg(p2p, in p2p_add_device()
806 p2p_dbg(p2p, "Update Listen frequency based on DS Parameter Set IE: %d -> %d MHz", in p2p_add_device()
813 p2p_dbg(p2p, "Update Listen frequency based on scan results (" in p2p_add_device()
828 p2p_copy_wps_info(p2p, dev, 0, &msg); in p2p_add_device()
855 p2p_add_group_clients(p2p, p2p_dev_addr, addr, freq, in p2p_add_device()
870 p2p_dbg(p2p, "Peer found with Listen frequency %d MHz (rx_time=%u.%06u)", in p2p_add_device()
874 p2p_dbg(p2p, "Do not report rejected device"); in p2p_add_device()
894 p2p_dbg(p2p, "Do not report peer " MACSTR in p2p_add_device()
899 p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info, in p2p_add_device()
910 static void p2p_device_free(struct p2p_data *p2p, struct p2p_device *dev) in p2p_device_free() argument
914 if (p2p->go_neg_peer == dev) { in p2p_device_free()
918 p2p_go_neg_failed(p2p, -1); in p2p_device_free()
920 if (p2p->invite_peer == dev) in p2p_device_free()
921 p2p->invite_peer = NULL; in p2p_device_free()
922 if (p2p->sd_peer == dev) in p2p_device_free()
923 p2p->sd_peer = NULL; in p2p_device_free()
924 if (p2p->pending_client_disc_go == dev) in p2p_device_free()
925 p2p->pending_client_disc_go = NULL; in p2p_device_free()
929 p2p->cfg->dev_lost(p2p->cfg->cb_ctx, in p2p_device_free()
946 static int p2p_get_next_prog_freq(struct p2p_data *p2p) in p2p_get_next_prog_freq() argument
956 c = &p2p->cfg->channels; in p2p_get_next_prog_freq()
959 if (cla->reg_class != p2p->last_prog_scan_class) in p2p_get_next_prog_freq()
962 if (cla->channel[ch] == p2p->last_prog_scan_chan) { in p2p_get_next_prog_freq()
989 p2p_dbg(p2p, "Next progressive search channel: reg_class %u channel %u -> %d MHz", in p2p_get_next_prog_freq()
991 p2p->last_prog_scan_class = reg_class; in p2p_get_next_prog_freq()
992 p2p->last_prog_scan_chan = channel; in p2p_get_next_prog_freq()
1000 static void p2p_search(struct p2p_data *p2p) in p2p_search() argument
1007 if (p2p->drv_in_listen) { in p2p_search()
1008 p2p_dbg(p2p, "Driver is still in Listen state - wait for it to end before continuing"); in p2p_search()
1011 p2p->cfg->stop_listen(p2p->cfg->cb_ctx); in p2p_search()
1013 if (p2p->find_type == P2P_FIND_PROGRESSIVE && in p2p_search()
1014 (freq = p2p_get_next_prog_freq(p2p)) > 0) { in p2p_search()
1016 p2p_dbg(p2p, "Starting search (+ freq %u)", freq); in p2p_search()
1019 p2p_dbg(p2p, "Starting search"); in p2p_search()
1022 res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, type, freq, in p2p_search()
1023 p2p->num_req_dev_types, p2p->req_dev_types, in p2p_search()
1024 p2p->find_dev_id, pw_id); in p2p_search()
1026 p2p_dbg(p2p, "Scan request schedule failed"); in p2p_search()
1027 p2p_continue_find(p2p); in p2p_search()
1034 struct p2p_data *p2p = eloop_ctx; in p2p_find_timeout() local
1035 p2p_dbg(p2p, "Find timeout -> stop"); in p2p_find_timeout()
1036 p2p_stop_find(p2p); in p2p_find_timeout()
1040 void p2p_notify_scan_trigger_status(struct p2p_data *p2p, int status) in p2p_notify_scan_trigger_status() argument
1043 p2p_dbg(p2p, "Scan request failed"); in p2p_notify_scan_trigger_status()
1045 p2p_continue_find(p2p); in p2p_notify_scan_trigger_status()
1047 p2p_dbg(p2p, "Running p2p_scan"); in p2p_notify_scan_trigger_status()
1048 p2p->p2p_scan_running = 1; in p2p_notify_scan_trigger_status()
1049 eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); in p2p_notify_scan_trigger_status()
1051 p2p, NULL); in p2p_notify_scan_trigger_status()
1056 static int p2p_run_after_scan(struct p2p_data *p2p) in p2p_run_after_scan() argument
1061 if (p2p->after_scan_tx) { in p2p_run_after_scan()
1062 p2p->after_scan_tx_in_progress = 1; in p2p_run_after_scan()
1063 p2p_dbg(p2p, "Send pending Action frame at p2p_scan completion"); in p2p_run_after_scan()
1064 p2p->cfg->send_action(p2p->cfg->cb_ctx, in p2p_run_after_scan()
1065 p2p->after_scan_tx->freq, in p2p_run_after_scan()
1066 p2p->after_scan_tx->dst, in p2p_run_after_scan()
1067 p2p->after_scan_tx->src, in p2p_run_after_scan()
1068 p2p->after_scan_tx->bssid, in p2p_run_after_scan()
1069 (u8 *) (p2p->after_scan_tx + 1), in p2p_run_after_scan()
1070 p2p->after_scan_tx->len, in p2p_run_after_scan()
1071 p2p->after_scan_tx->wait_time); in p2p_run_after_scan()
1072 os_free(p2p->after_scan_tx); in p2p_run_after_scan()
1073 p2p->after_scan_tx = NULL; in p2p_run_after_scan()
1077 op = p2p->start_after_scan; in p2p_run_after_scan()
1078 p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; in p2p_run_after_scan()
1083 p2p_dbg(p2p, "Start previously requested Listen state"); in p2p_run_after_scan()
1084 p2p_listen(p2p, p2p->pending_listen_sec * 1000 + in p2p_run_after_scan()
1085 p2p->pending_listen_usec / 1000); in p2p_run_after_scan()
1088 p2p_dbg(p2p, "Start previously requested connect with " MACSTR, in p2p_run_after_scan()
1089 MAC2STR(p2p->after_scan_peer)); in p2p_run_after_scan()
1090 dev = p2p_get_device(p2p, p2p->after_scan_peer); in p2p_run_after_scan()
1092 p2p_dbg(p2p, "Peer not known anymore"); in p2p_run_after_scan()
1095 p2p_connect_send(p2p, dev); in p2p_run_after_scan()
1105 struct p2p_data *p2p = eloop_ctx; in p2p_scan_timeout() local
1107 p2p_dbg(p2p, "p2p_scan timeout (running=%d)", p2p->p2p_scan_running); in p2p_scan_timeout()
1108 running = p2p->p2p_scan_running; in p2p_scan_timeout()
1110 p2p->p2p_scan_running = 0; in p2p_scan_timeout()
1113 p2p_run_after_scan(p2p); in p2p_scan_timeout()
1117 static void p2p_free_req_dev_types(struct p2p_data *p2p) in p2p_free_req_dev_types() argument
1119 p2p->num_req_dev_types = 0; in p2p_free_req_dev_types()
1120 os_free(p2p->req_dev_types); in p2p_free_req_dev_types()
1121 p2p->req_dev_types = NULL; in p2p_free_req_dev_types()
1125 static int p2ps_gen_hash(struct p2p_data *p2p, const char *str, u8 *hash) in p2ps_gen_hash() argument
1136 os_memcpy(hash, p2p->wild_card_hash, P2PS_HASH_LEN); in p2ps_gen_hash()
1160 int p2p_find(struct p2p_data *p2p, unsigned int timeout, in p2p_find() argument
1168 p2p_dbg(p2p, "Starting find (type=%d)", type); in p2p_find()
1169 os_get_reltime(&p2p->find_start); in p2p_find()
1170 if (p2p->p2p_scan_running) { in p2p_find()
1171 p2p_dbg(p2p, "p2p_scan is already running"); in p2p_find()
1174 p2p_free_req_dev_types(p2p); in p2p_find()
1176 p2p->req_dev_types = os_malloc(num_req_dev_types * in p2p_find()
1178 if (p2p->req_dev_types == NULL) in p2p_find()
1180 os_memcpy(p2p->req_dev_types, req_dev_types, in p2p_find()
1182 p2p->num_req_dev_types = num_req_dev_types; in p2p_find()
1186 os_memcpy(p2p->find_dev_id_buf, dev_id, ETH_ALEN); in p2p_find()
1187 p2p->find_dev_id = p2p->find_dev_id_buf; in p2p_find()
1189 p2p->find_dev_id = NULL; in p2p_find()
1193 p2p->p2ps_seek = 0; in p2p_find()
1199 p2p_dbg(p2p, "ASP search"); in p2p_find()
1200 p2p->p2ps_seek_count = 0; in p2p_find()
1201 p2p->p2ps_seek = 1; in p2p_find()
1207 if (!p2ps_gen_hash(p2p, seek[i], buf)) in p2p_find()
1210 p2p_dbg(p2p, "Seek service %s hash " MACSTR, in p2p_find()
1212 os_memcpy(&p2p->p2ps_seek_hash[count * P2PS_HASH_LEN], in p2p_find()
1217 p2p->p2ps_seek_count = count; in p2p_find()
1218 p2p->p2ps_seek = 1; in p2p_find()
1220 p2p->p2ps_seek_count = 0; in p2p_find()
1221 p2p->p2ps_seek = 1; in p2p_find()
1225 if (p2p->p2ps_seek_count == 0 && p2p->p2ps_seek) { in p2p_find()
1226 p2p->p2ps_seek_count = 1; in p2p_find()
1227 os_memcpy(&p2p->p2ps_seek_hash, p2p->wild_card_hash, in p2p_find()
1231 p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; in p2p_find()
1232 p2p_clear_timeout(p2p); in p2p_find()
1233 if (p2p->pending_listen_freq) { in p2p_find()
1234 p2p_dbg(p2p, "Clear pending_listen_freq for p2p_find"); in p2p_find()
1235 p2p->pending_listen_freq = 0; in p2p_find()
1237 p2p->cfg->stop_listen(p2p->cfg->cb_ctx); in p2p_find()
1238 p2p->find_type = type; in p2p_find()
1239 p2p_device_clear_reported(p2p); in p2p_find()
1240 os_memset(p2p->sd_query_no_ack, 0, ETH_ALEN); in p2p_find()
1241 p2p_set_state(p2p, P2P_SEARCH); in p2p_find()
1242 p2p->search_delay = search_delay; in p2p_find()
1243 p2p->in_search_delay = 0; in p2p_find()
1244 eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); in p2p_find()
1245 p2p->last_p2p_find_timeout = timeout; in p2p_find()
1248 p2p, NULL); in p2p_find()
1256 res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, in p2p_find()
1258 p2p->num_req_dev_types, in p2p_find()
1259 p2p->req_dev_types, dev_id, in p2p_find()
1265 res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_FULL, 0, in p2p_find()
1266 p2p->num_req_dev_types, in p2p_find()
1267 p2p->req_dev_types, dev_id, in p2p_find()
1271 res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_SOCIAL, 0, in p2p_find()
1272 p2p->num_req_dev_types, in p2p_find()
1273 p2p->req_dev_types, dev_id, in p2p_find()
1280 if (res != 0 && p2p->p2p_scan_running) { in p2p_find()
1281 p2p_dbg(p2p, "Failed to start p2p_scan - another p2p_scan was already running"); in p2p_find()
1285 p2p_dbg(p2p, "Failed to start p2p_scan"); in p2p_find()
1286 p2p_set_state(p2p, P2P_IDLE); in p2p_find()
1287 eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); in p2p_find()
1294 void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq) in p2p_stop_find_for_freq() argument
1296 p2p_dbg(p2p, "Stopping find"); in p2p_stop_find_for_freq()
1297 eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); in p2p_stop_find_for_freq()
1298 p2p_clear_timeout(p2p); in p2p_stop_find_for_freq()
1299 if (p2p->state == P2P_SEARCH || p2p->state == P2P_SD_DURING_FIND) in p2p_stop_find_for_freq()
1300 p2p->cfg->find_stopped(p2p->cfg->cb_ctx); in p2p_stop_find_for_freq()
1302 p2p->p2ps_seek_count = 0; in p2p_stop_find_for_freq()
1304 p2p_set_state(p2p, P2P_IDLE); in p2p_stop_find_for_freq()
1305 p2p_free_req_dev_types(p2p); in p2p_stop_find_for_freq()
1306 p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; in p2p_stop_find_for_freq()
1307 if (p2p->go_neg_peer) in p2p_stop_find_for_freq()
1308 p2p->go_neg_peer->flags &= ~P2P_DEV_PEER_WAITING_RESPONSE; in p2p_stop_find_for_freq()
1309 p2p->go_neg_peer = NULL; in p2p_stop_find_for_freq()
1310 p2p->sd_peer = NULL; in p2p_stop_find_for_freq()
1311 p2p->invite_peer = NULL; in p2p_stop_find_for_freq()
1312 p2p_stop_listen_for_freq(p2p, freq); in p2p_stop_find_for_freq()
1313 p2p->send_action_in_progress = 0; in p2p_stop_find_for_freq()
1317 void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq) in p2p_stop_listen_for_freq() argument
1319 if (freq > 0 && p2p->drv_in_listen == freq && p2p->in_listen) { in p2p_stop_listen_for_freq()
1320 p2p_dbg(p2p, "Skip stop_listen since we are on correct channel for response"); in p2p_stop_listen_for_freq()
1323 if (p2p->in_listen) { in p2p_stop_listen_for_freq()
1324 p2p->in_listen = 0; in p2p_stop_listen_for_freq()
1325 p2p_clear_timeout(p2p); in p2p_stop_listen_for_freq()
1327 if (p2p->drv_in_listen) { in p2p_stop_listen_for_freq()
1333 p2p_dbg(p2p, "Clear drv_in_listen (%d)", p2p->drv_in_listen); in p2p_stop_listen_for_freq()
1334 p2p->drv_in_listen = 0; in p2p_stop_listen_for_freq()
1336 p2p->cfg->stop_listen(p2p->cfg->cb_ctx); in p2p_stop_listen_for_freq()
1340 void p2p_stop_listen(struct p2p_data *p2p) in p2p_stop_listen() argument
1342 if (p2p->state != P2P_LISTEN_ONLY) { in p2p_stop_listen()
1343 p2p_dbg(p2p, "Skip stop_listen since not in listen_only state."); in p2p_stop_listen()
1347 p2p_stop_listen_for_freq(p2p, 0); in p2p_stop_listen()
1348 p2p_set_state(p2p, P2P_IDLE); in p2p_stop_listen()
1352 void p2p_stop_find(struct p2p_data *p2p) in p2p_stop_find() argument
1354 p2p->pending_listen_freq = 0; in p2p_stop_find()
1355 p2p_stop_find_for_freq(p2p, 0); in p2p_stop_find()
1359 static int p2p_prepare_channel_pref(struct p2p_data *p2p, in p2p_prepare_channel_pref() argument
1366 p2p_dbg(p2p, "Prepare channel pref - force_freq=%u pref_freq=%u go=%d", in p2p_prepare_channel_pref()
1369 p2p_dbg(p2p, "Unsupported frequency %u MHz", freq); in p2p_prepare_channel_pref()
1373 if (!p2p_channels_includes(&p2p->cfg->channels, op_class, op_channel) && in p2p_prepare_channel_pref()
1374 (go || !p2p_channels_includes(&p2p->cfg->cli_channels, op_class, in p2p_prepare_channel_pref()
1376 p2p_dbg(p2p, "Frequency %u MHz (oper_class %u channel %u) not allowed for P2P", in p2p_prepare_channel_pref()
1381 p2p->op_reg_class = op_class; in p2p_prepare_channel_pref()
1382 p2p->op_channel = op_channel; in p2p_prepare_channel_pref()
1385 p2p->channels.reg_classes = 1; in p2p_prepare_channel_pref()
1386 p2p->channels.reg_class[0].channels = 1; in p2p_prepare_channel_pref()
1387 p2p->channels.reg_class[0].reg_class = p2p->op_reg_class; in p2p_prepare_channel_pref()
1388 p2p->channels.reg_class[0].channel[0] = p2p->op_channel; in p2p_prepare_channel_pref()
1390 os_memcpy(&p2p->channels, &p2p->cfg->channels, in p2p_prepare_channel_pref()
1398 static void p2p_prepare_channel_best(struct p2p_data *p2p) in p2p_prepare_channel_best() argument
1405 p2p_dbg(p2p, "Prepare channel best"); in p2p_prepare_channel_best()
1407 if (!p2p->cfg->cfg_op_channel && p2p->best_freq_overall > 0 && in p2p_prepare_channel_best()
1408 p2p_supported_freq(p2p, p2p->best_freq_overall) && in p2p_prepare_channel_best()
1409 p2p_freq_to_channel(p2p->best_freq_overall, &op_class, &op_channel) in p2p_prepare_channel_best()
1411 p2p_dbg(p2p, "Select best overall channel as operating channel preference"); in p2p_prepare_channel_best()
1412 p2p->op_reg_class = op_class; in p2p_prepare_channel_best()
1413 p2p->op_channel = op_channel; in p2p_prepare_channel_best()
1414 } else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_5 > 0 && in p2p_prepare_channel_best()
1415 p2p_supported_freq(p2p, p2p->best_freq_5) && in p2p_prepare_channel_best()
1416 p2p_freq_to_channel(p2p->best_freq_5, &op_class, &op_channel) in p2p_prepare_channel_best()
1418 p2p_dbg(p2p, "Select best 5 GHz channel as operating channel preference"); in p2p_prepare_channel_best()
1419 p2p->op_reg_class = op_class; in p2p_prepare_channel_best()
1420 p2p->op_channel = op_channel; in p2p_prepare_channel_best()
1421 } else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_24 > 0 && in p2p_prepare_channel_best()
1422 p2p_supported_freq(p2p, p2p->best_freq_24) && in p2p_prepare_channel_best()
1423 p2p_freq_to_channel(p2p->best_freq_24, &op_class, in p2p_prepare_channel_best()
1425 p2p_dbg(p2p, "Select best 2.4 GHz channel as operating channel preference"); in p2p_prepare_channel_best()
1426 p2p->op_reg_class = op_class; in p2p_prepare_channel_best()
1427 p2p->op_channel = op_channel; in p2p_prepare_channel_best()
1428 } else if (p2p->cfg->num_pref_chan > 0 && in p2p_prepare_channel_best()
1429 p2p_channels_includes(&p2p->cfg->channels, in p2p_prepare_channel_best()
1430 p2p->cfg->pref_chan[0].op_class, in p2p_prepare_channel_best()
1431 p2p->cfg->pref_chan[0].chan)) { in p2p_prepare_channel_best()
1432 p2p_dbg(p2p, "Select first pref_chan entry as operating channel preference"); in p2p_prepare_channel_best()
1433 p2p->op_reg_class = p2p->cfg->pref_chan[0].op_class; in p2p_prepare_channel_best()
1434 p2p->op_channel = p2p->cfg->pref_chan[0].chan; in p2p_prepare_channel_best()
1435 } else if (p2p_channel_select(&p2p->cfg->channels, op_classes_vht, in p2p_prepare_channel_best()
1436 &p2p->op_reg_class, &p2p->op_channel) == in p2p_prepare_channel_best()
1438 …p2p_dbg(p2p, "Select possible VHT channel (op_class %u channel %u) as operating channel preference… in p2p_prepare_channel_best()
1439 p2p->op_reg_class, p2p->op_channel); in p2p_prepare_channel_best()
1440 } else if (p2p_channel_select(&p2p->cfg->channels, op_classes_ht40, in p2p_prepare_channel_best()
1441 &p2p->op_reg_class, &p2p->op_channel) == in p2p_prepare_channel_best()
1443 …p2p_dbg(p2p, "Select possible HT40 channel (op_class %u channel %u) as operating channel preferenc… in p2p_prepare_channel_best()
1444 p2p->op_reg_class, p2p->op_channel); in p2p_prepare_channel_best()
1445 } else if (p2p_channel_select(&p2p->cfg->channels, op_classes_5ghz, in p2p_prepare_channel_best()
1446 &p2p->op_reg_class, &p2p->op_channel) == in p2p_prepare_channel_best()
1448 …p2p_dbg(p2p, "Select possible 5 GHz channel (op_class %u channel %u) as operating channel preferen… in p2p_prepare_channel_best()
1449 p2p->op_reg_class, p2p->op_channel); in p2p_prepare_channel_best()
1450 } else if (p2p_channels_includes(&p2p->cfg->channels, in p2p_prepare_channel_best()
1451 p2p->cfg->op_reg_class, in p2p_prepare_channel_best()
1452 p2p->cfg->op_channel)) { in p2p_prepare_channel_best()
1453 p2p_dbg(p2p, "Select pre-configured channel as operating channel preference"); in p2p_prepare_channel_best()
1454 p2p->op_reg_class = p2p->cfg->op_reg_class; in p2p_prepare_channel_best()
1455 p2p->op_channel = p2p->cfg->op_channel; in p2p_prepare_channel_best()
1456 } else if (p2p_channel_random_social(&p2p->cfg->channels, in p2p_prepare_channel_best()
1457 &p2p->op_reg_class, in p2p_prepare_channel_best()
1458 &p2p->op_channel) == 0) { in p2p_prepare_channel_best()
1459 …p2p_dbg(p2p, "Select random available social channel (op_class %u channel %u) as operating channel… in p2p_prepare_channel_best()
1460 p2p->op_reg_class, p2p->op_channel); in p2p_prepare_channel_best()
1464 p2p_channel_select(&p2p->cfg->channels, NULL, in p2p_prepare_channel_best()
1465 &p2p->op_reg_class, in p2p_prepare_channel_best()
1466 &p2p->op_channel); in p2p_prepare_channel_best()
1467 …p2p_dbg(p2p, "Select random available channel %d from operating class %d as operating channel pref… in p2p_prepare_channel_best()
1468 p2p->op_channel, p2p->op_reg_class); in p2p_prepare_channel_best()
1471 os_memcpy(&p2p->channels, &p2p->cfg->channels, in p2p_prepare_channel_best()
1490 int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev, in p2p_prepare_channel() argument
1493 p2p_dbg(p2p, "Prepare channel - force_freq=%u pref_freq=%u go=%d", in p2p_prepare_channel()
1496 if (p2p_prepare_channel_pref(p2p, force_freq, pref_freq, go) < in p2p_prepare_channel()
1500 p2p_prepare_channel_best(p2p); in p2p_prepare_channel()
1502 p2p_channels_dump(p2p, "prepared channels", &p2p->channels); in p2p_prepare_channel()
1504 p2p_channels_remove_freqs(&p2p->channels, &p2p->no_go_freq); in p2p_prepare_channel()
1506 p2p_channels_union_inplace(&p2p->channels, in p2p_prepare_channel()
1507 &p2p->cfg->cli_channels); in p2p_prepare_channel()
1508 p2p_channels_dump(p2p, "after go/cli filter/add", &p2p->channels); in p2p_prepare_channel()
1510 p2p_dbg(p2p, "Own preference for operation channel: Operating Class %u Channel %u%s", in p2p_prepare_channel()
1511 p2p->op_reg_class, p2p->op_channel, in p2p_prepare_channel()
1543 int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr, in p2p_connect() argument
1552 p2p_dbg(p2p, "Request to start group negotiation - peer=" MACSTR in p2p_connect()
1559 dev = p2p_get_device(p2p, peer_addr); in p2p_connect()
1561 p2p_dbg(p2p, "Cannot connect to unknown P2P Device " MACSTR, in p2p_connect()
1566 if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq, in p2p_connect()
1573 p2p_dbg(p2p, "Cannot connect to P2P Device " MACSTR in p2p_connect()
1579 p2p_dbg(p2p, "Cannot connect to P2P Device " MACSTR in p2p_connect()
1592 p2p->ssid_set = 0; in p2p_connect()
1596 os_memcpy(p2p->ssid, force_ssid, force_ssid_len); in p2p_connect()
1597 p2p->ssid_len = force_ssid_len; in p2p_connect()
1598 p2p->ssid_set = 1; in p2p_connect()
1616 dev->tie_breaker = p2p->next_tie_breaker; in p2p_connect()
1617 p2p->next_tie_breaker = !p2p->next_tie_breaker; in p2p_connect()
1623 p2p->go_intent = go_intent; in p2p_connect()
1624 os_memcpy(p2p->intended_addr, own_interface_addr, ETH_ALEN); in p2p_connect()
1626 if (p2p->state != P2P_IDLE) in p2p_connect()
1627 p2p_stop_find(p2p); in p2p_connect()
1629 if (p2p->after_scan_tx) { in p2p_connect()
1635 p2p_dbg(p2p, "Dropped previous pending Action frame TX that was waiting for p2p_scan completion"); in p2p_connect()
1636 os_free(p2p->after_scan_tx); in p2p_connect()
1637 p2p->after_scan_tx = NULL; in p2p_connect()
1644 if (p2p->p2p_scan_running) { in p2p_connect()
1645 p2p_dbg(p2p, "p2p_scan running - delay connect send"); in p2p_connect()
1646 p2p->start_after_scan = P2P_AFTER_SCAN_CONNECT; in p2p_connect()
1647 os_memcpy(p2p->after_scan_peer, peer_addr, ETH_ALEN); in p2p_connect()
1650 p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; in p2p_connect()
1652 return p2p_connect_send(p2p, dev); in p2p_connect()
1656 int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr, in p2p_authorize() argument
1665 p2p_dbg(p2p, "Request to authorize group negotiation - peer=" MACSTR in p2p_authorize()
1671 dev = p2p_get_device(p2p, peer_addr); in p2p_authorize()
1673 p2p_dbg(p2p, "Cannot authorize unknown P2P Device " MACSTR, in p2p_authorize()
1678 if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq, go_intent == in p2p_authorize()
1682 p2p->ssid_set = 0; in p2p_authorize()
1686 os_memcpy(p2p->ssid, force_ssid, force_ssid_len); in p2p_authorize()
1687 p2p->ssid_len = force_ssid_len; in p2p_authorize()
1688 p2p->ssid_set = 1; in p2p_authorize()
1696 p2p->go_intent = go_intent; in p2p_authorize()
1697 os_memcpy(p2p->intended_addr, own_interface_addr, ETH_ALEN); in p2p_authorize()
1707 void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr, in p2p_add_dev_info() argument
1712 p2p_copy_wps_info(p2p, dev, 0, msg); in p2p_add_dev_info()
1719 p2p_dbg(p2p, "Unknown peer Listen channel: " in p2p_add_dev_info()
1727 p2p_dbg(p2p, "Update peer " MACSTR in p2p_add_dev_info()
1742 p2p_dbg(p2p, "Completed device entry based on data from GO Negotiation Request"); in p2p_add_dev_info()
1744 p2p_dbg(p2p, "Created device entry based on GO Neg Req: " in p2p_add_dev_info()
1755 p2p_dbg(p2p, "Do not report rejected device"); in p2p_add_dev_info()
1759 p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info, in p2p_add_dev_info()
1765 void p2p_build_ssid(struct p2p_data *p2p, u8 *ssid, size_t *ssid_len) in p2p_build_ssid() argument
1770 p2p->cfg->ssid_postfix, p2p->cfg->ssid_postfix_len); in p2p_build_ssid()
1771 *ssid_len = P2P_WILDCARD_SSID_LEN + 2 + p2p->cfg->ssid_postfix_len; in p2p_build_ssid()
1775 int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params) in p2p_go_params() argument
1777 if (p2p->ssid_set) { in p2p_go_params()
1778 os_memcpy(params->ssid, p2p->ssid, p2p->ssid_len); in p2p_go_params()
1779 params->ssid_len = p2p->ssid_len; in p2p_go_params()
1781 p2p_build_ssid(p2p, params->ssid, &params->ssid_len); in p2p_go_params()
1783 p2p->ssid_set = 0; in p2p_go_params()
1785 p2p_random(params->passphrase, p2p->cfg->passphrase_len); in p2p_go_params()
1790 void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer) in p2p_go_complete() argument
1796 p2p_dbg(p2p, "GO Negotiation with " MACSTR " completed (%s will be GO)", in p2p_go_complete()
1813 res.freq = p2p_channel_to_freq(p2p->op_reg_class, in p2p_go_complete()
1814 p2p->op_channel); in p2p_go_complete()
1815 os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len); in p2p_go_complete()
1816 res.ssid_len = p2p->ssid_len; in p2p_go_complete()
1817 p2p_random(res.passphrase, p2p->cfg->passphrase_len); in p2p_go_complete()
1820 if (p2p->ssid_len) { in p2p_go_complete()
1821 os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len); in p2p_go_complete()
1822 res.ssid_len = p2p->ssid_len; in p2p_go_complete()
1826 p2p_channels_dump(p2p, "own channels", &p2p->channels); in p2p_go_complete()
1827 p2p_channels_dump(p2p, "peer channels", &peer->channels); in p2p_go_complete()
1828 p2p_channels_intersect(&p2p->channels, &peer->channels, in p2p_go_complete()
1831 p2p_channels_remove_freqs(&intersection, &p2p->no_go_freq); in p2p_go_complete()
1832 p2p_channels_dump(p2p, "intersection after no-GO removal", in p2p_go_complete()
1841 p2p_clear_timeout(p2p); in p2p_go_complete()
1842 p2p->ssid_set = 0; in p2p_go_complete()
1850 p2p_set_state(p2p, P2P_PROVISIONING); in p2p_go_complete()
1851 p2p->cfg->go_neg_completed(p2p->cfg->cb_ctx, &res); in p2p_go_complete()
1855 static void p2p_rx_p2p_action(struct p2p_data *p2p, const u8 *sa, in p2p_rx_p2p_action() argument
1858 p2p_dbg(p2p, "RX P2P Public Action from " MACSTR, MAC2STR(sa)); in p2p_rx_p2p_action()
1866 p2p_process_go_neg_req(p2p, sa, data + 1, len - 1, rx_freq); in p2p_rx_p2p_action()
1869 p2p_process_go_neg_resp(p2p, sa, data + 1, len - 1, rx_freq); in p2p_rx_p2p_action()
1872 p2p_process_go_neg_conf(p2p, sa, data + 1, len - 1); in p2p_rx_p2p_action()
1875 p2p_process_invitation_req(p2p, sa, data + 1, len - 1, in p2p_rx_p2p_action()
1879 p2p_process_invitation_resp(p2p, sa, data + 1, len - 1); in p2p_rx_p2p_action()
1882 p2p_process_prov_disc_req(p2p, sa, data + 1, len - 1, rx_freq); in p2p_rx_p2p_action()
1885 p2p_process_prov_disc_resp(p2p, sa, data + 1, len - 1); in p2p_rx_p2p_action()
1888 p2p_process_dev_disc_req(p2p, sa, data + 1, len - 1, rx_freq); in p2p_rx_p2p_action()
1891 p2p_process_dev_disc_resp(p2p, sa, data + 1, len - 1); in p2p_rx_p2p_action()
1894 p2p_dbg(p2p, "Unsupported P2P Public Action frame type %d", in p2p_rx_p2p_action()
1901 static void p2p_rx_action_public(struct p2p_data *p2p, const u8 *da, in p2p_rx_action_public() argument
1920 p2p_rx_p2p_action(p2p, sa, data, len, freq); in p2p_rx_action_public()
1923 p2p_rx_gas_initial_req(p2p, sa, data + 1, len - 1, freq); in p2p_rx_action_public()
1926 p2p_rx_gas_initial_resp(p2p, sa, data + 1, len - 1, freq); in p2p_rx_action_public()
1929 p2p_rx_gas_comeback_req(p2p, sa, data + 1, len - 1, freq); in p2p_rx_action_public()
1932 p2p_rx_gas_comeback_resp(p2p, sa, data + 1, len - 1, freq); in p2p_rx_action_public()
1938 void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa, in p2p_rx_action() argument
1943 p2p_rx_action_public(p2p, da, sa, bssid, data, len, freq); in p2p_rx_action()
1959 p2p_dbg(p2p, "RX P2P Action from " MACSTR, MAC2STR(sa)); in p2p_rx_action()
1966 p2p_dbg(p2p, "Received P2P Action - Notice of Absence"); in p2p_rx_action()
1970 p2p_process_presence_req(p2p, da, sa, data + 1, len - 1, freq); in p2p_rx_action()
1973 p2p_process_presence_resp(p2p, da, sa, data + 1, len - 1); in p2p_rx_action()
1976 p2p_process_go_disc_req(p2p, da, sa, data + 1, len - 1, freq); in p2p_rx_action()
1979 p2p_dbg(p2p, "Received P2P Action - unknown type %u", data[0]); in p2p_rx_action()
1987 struct p2p_data *p2p = eloop_ctx; in p2p_go_neg_start() local
1988 if (p2p->go_neg_peer == NULL) in p2p_go_neg_start()
1990 if (p2p->pending_listen_freq) { in p2p_go_neg_start()
1991 p2p_dbg(p2p, "Clear pending_listen_freq for p2p_go_neg_start"); in p2p_go_neg_start()
1992 p2p->pending_listen_freq = 0; in p2p_go_neg_start()
1994 p2p->cfg->stop_listen(p2p->cfg->cb_ctx); in p2p_go_neg_start()
1995 p2p->go_neg_peer->status = P2P_SC_SUCCESS; in p2p_go_neg_start()
2000 p2p_set_timeout(p2p, 0, 500000); in p2p_go_neg_start()
2001 p2p_connect_send(p2p, p2p->go_neg_peer); in p2p_go_neg_start()
2007 struct p2p_data *p2p = eloop_ctx; in p2p_invite_start() local
2008 if (p2p->invite_peer == NULL) in p2p_invite_start()
2010 if (p2p->pending_listen_freq) { in p2p_invite_start()
2011 p2p_dbg(p2p, "Clear pending_listen_freq for p2p_invite_start"); in p2p_invite_start()
2012 p2p->pending_listen_freq = 0; in p2p_invite_start()
2014 p2p->cfg->stop_listen(p2p->cfg->cb_ctx); in p2p_invite_start()
2015 p2p_invite_send(p2p, p2p->invite_peer, p2p->invite_go_dev_addr, in p2p_invite_start()
2016 p2p->invite_dev_pw_id); in p2p_invite_start()
2020 static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr, in p2p_add_dev_from_probe_req() argument
2045 dev = p2p_get_device(p2p, addr); in p2p_add_dev_from_probe_req()
2057 p2p_dbg(p2p, in p2p_add_dev_from_probe_req()
2069 dev = p2p_create_device(p2p, addr); in p2p_add_dev_from_probe_req()
2084 p2p_copy_wps_info(p2p, dev, 1, &msg); in p2p_add_dev_from_probe_req()
2093 p2p_dbg(p2p, "Created device entry based on Probe Req: " MACSTR in p2p_add_dev_from_probe_req()
2101 struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p, in p2p_add_dev_from_go_neg_req() argument
2107 dev = p2p_get_device(p2p, addr); in p2p_add_dev_from_go_neg_req()
2113 dev = p2p_create_device(p2p, addr); in p2p_add_dev_from_go_neg_req()
2117 p2p_add_dev_info(p2p, addr, dev, msg); in p2p_add_dev_from_go_neg_req()
2157 int p2p_match_dev_type(struct p2p_data *p2p, struct wpabuf *wps) in p2p_match_dev_type() argument
2168 if (dev_type_list_match(p2p->cfg->pri_dev_type, attr.req_dev_type, in p2p_match_dev_type()
2172 for (i = 0; i < p2p->cfg->num_sec_dev_types; i++) { in p2p_match_dev_type()
2173 if (dev_type_list_match(p2p->cfg->sec_dev_type[i], in p2p_match_dev_type()
2184 struct wpabuf * p2p_build_probe_resp_ies(struct p2p_data *p2p, in p2p_build_probe_resp_ies() argument
2194 if (p2p->wfd_ie_probe_resp) in p2p_build_probe_resp_ies()
2195 extra = wpabuf_len(p2p->wfd_ie_probe_resp); in p2p_build_probe_resp_ies()
2198 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_PROBE_RESP_P2P]) in p2p_build_probe_resp_ies()
2199 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_PROBE_RESP_P2P]); in p2p_build_probe_resp_ies()
2208 if (p2p->go_neg_peer) { in p2p_build_probe_resp_ies()
2210 pw_id = p2p_wps_method_pw_id(p2p->go_neg_peer->wps_method); in p2p_build_probe_resp_ies()
2213 if (p2p_build_wps_ie(p2p, buf, pw_id, 1) < 0) { in p2p_build_probe_resp_ies()
2214 p2p_dbg(p2p, "Failed to build WPS IE for Probe Response"); in p2p_build_probe_resp_ies()
2220 if (p2p->wfd_ie_probe_resp) in p2p_build_probe_resp_ies()
2221 wpabuf_put_buf(buf, p2p->wfd_ie_probe_resp); in p2p_build_probe_resp_ies()
2224 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_PROBE_RESP_P2P]) in p2p_build_probe_resp_ies()
2226 p2p->vendor_elem[VENDOR_ELEM_PROBE_RESP_P2P]); in p2p_build_probe_resp_ies()
2230 p2p_buf_add_capability(buf, p2p->dev_capab & in p2p_build_probe_resp_ies()
2232 if (p2p->ext_listen_interval) in p2p_build_probe_resp_ies()
2233 p2p_buf_add_ext_listen_timing(buf, p2p->ext_listen_period, in p2p_build_probe_resp_ies()
2234 p2p->ext_listen_interval); in p2p_build_probe_resp_ies()
2235 p2p_buf_add_device_info(buf, p2p, NULL); in p2p_build_probe_resp_ies()
2239 p2p_buf_add_service_instance(buf, p2p, query_count, query_hash, in p2p_build_probe_resp_ies()
2240 p2p->p2ps_adv_list); in p2p_build_probe_resp_ies()
2246 static int p2p_build_probe_resp_buf(struct p2p_data *p2p, struct wpabuf *buf, in p2p_build_probe_resp_buf() argument
2259 os_memcpy(resp->sa, p2p->cfg->dev_addr, ETH_ALEN); in p2p_build_probe_resp_buf()
2260 os_memcpy(resp->bssid, p2p->cfg->dev_addr, ETH_ALEN); in p2p_build_probe_resp_buf()
2284 channel = p2p->cfg->channel; in p2p_build_probe_resp_buf()
2286 p2p_err(p2p, "Failed to convert freq to channel"); in p2p_build_probe_resp_buf()
2299 static int p2p_service_find_asp(struct p2p_data *p2p, const u8 *hash) in p2p_service_find_asp() argument
2304 p2p_dbg(p2p, "ASP find - ASP list: %p", p2p->p2ps_adv_list); in p2p_service_find_asp()
2307 any_wfa = os_memcmp(hash, p2p->wild_card_hash, P2PS_HASH_LEN) == 0; in p2p_service_find_asp()
2309 adv_data = p2p->p2ps_adv_list; in p2p_service_find_asp()
2325 p2p_reply_probe(struct p2p_data *p2p, const u8 *addr, const u8 *dst, in p2p_reply_probe() argument
2337 p2p_dbg(p2p, "Could not parse Probe Request frame - ignore it"); in p2p_reply_probe()
2341 if (elems.p2p == NULL) { in p2p_reply_probe()
2343 p2p_dbg(p2p, "Not a P2P probe - ignore it"); in p2p_reply_probe()
2348 os_memcmp(dst, p2p->cfg->dev_addr, ETH_ALEN) != 0) { in p2p_reply_probe()
2351 p2p_dbg(p2p, "Probe Req DA " MACSTR " not ours - ignore it", in p2p_reply_probe()
2358 p2p_dbg(p2p, "Probe Req BSSID " MACSTR " not wildcard - ignore it", in p2p_reply_probe()
2367 p2p_dbg(p2p, "Probe Req not using P2P Wildcard SSID - ignore it"); in p2p_reply_probe()
2373 p2p_dbg(p2p, "Probe Req with 11b rates only supported - ignore it"); in p2p_reply_probe()
2380 p2p_dbg(p2p, "Could not parse P2P attributes in Probe Req - ignore it"); in p2p_reply_probe()
2389 …p2p_dbg(p2p, "in_listen=%d drv_in_listen=%d when received P2PS Probe Request at %u MHz; own Listen… in p2p_reply_probe()
2390 p2p->in_listen, p2p->drv_in_listen, rx_freq, in p2p_reply_probe()
2391 p2p->cfg->channel, p2p->pending_listen_freq); in p2p_reply_probe()
2393 if (!p2p->in_listen && !p2p->drv_in_listen && in p2p_reply_probe()
2394 p2p->pending_listen_freq && rx_freq && in p2p_reply_probe()
2395 rx_freq != p2p->pending_listen_freq) { in p2p_reply_probe()
2396 …p2p_dbg(p2p, "Do not reply to Probe Request frame that was received on %u MHz while waiting to sta… in p2p_reply_probe()
2397 rx_freq, p2p->pending_listen_freq); in p2p_reply_probe()
2403 if (p2p_service_find_asp(p2p, hash)) { in p2p_reply_probe()
2404 p2p_dbg(p2p, "Service Hash match found: " in p2p_reply_probe()
2414 p2p_dbg(p2p, "No Service Hash match found"); in p2p_reply_probe()
2420 p2p_dbg(p2p, "No P2PS Hash in Probe Request"); in p2p_reply_probe()
2422 if (!p2p->in_listen || !p2p->drv_in_listen) { in p2p_reply_probe()
2424 p2p_dbg(p2p, "Not in Listen state (in_listen=%d drv_in_listen=%d) - ignore Probe Request", in p2p_reply_probe()
2425 p2p->in_listen, p2p->drv_in_listen); in p2p_reply_probe()
2432 os_memcmp(msg.device_id, p2p->cfg->dev_addr, ETH_ALEN) != 0) { in p2p_reply_probe()
2434 p2p_dbg(p2p, "Probe Req requested Device ID " MACSTR " did not match - ignore it", in p2p_reply_probe()
2442 !p2p_match_dev_type(p2p, msg.wps_attributes)) { in p2p_reply_probe()
2444 p2p_dbg(p2p, "Probe Req requestred Device Type did not match - ignore it"); in p2p_reply_probe()
2449 if (!p2p->cfg->send_probe_resp) { in p2p_reply_probe()
2451 p2p_dbg(p2p, "Probe Resp generated elsewhere - do not generate additional response"); in p2p_reply_probe()
2456 p2p_dbg(p2p, "Reply to P2P Probe Request in Listen state"); in p2p_reply_probe()
2464 ies = p2p_build_probe_resp_ies(p2p, msg.service_hash, in p2p_reply_probe()
2476 if (p2p_build_probe_resp_buf(p2p, buf, ies, addr, rx_freq)) { in p2p_reply_probe()
2484 p2p->cfg->send_probe_resp(p2p->cfg->cb_ctx, buf, rx_freq); in p2p_reply_probe()
2493 p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst, in p2p_probe_req_rx() argument
2499 p2p_add_dev_from_probe_req(p2p, addr, ie, ie_len); in p2p_probe_req_rx()
2502 p2p_dbg(p2p, in p2p_probe_req_rx()
2507 res = p2p_reply_probe(p2p, addr, dst, bssid, ie, ie_len, rx_freq); in p2p_probe_req_rx()
2519 if ((p2p->state == P2P_CONNECT || p2p->state == P2P_CONNECT_LISTEN) && in p2p_probe_req_rx()
2520 p2p->go_neg_peer && in p2p_probe_req_rx()
2521 os_memcmp(addr, p2p->go_neg_peer->info.p2p_device_addr, ETH_ALEN) in p2p_probe_req_rx()
2523 !(p2p->go_neg_peer->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) { in p2p_probe_req_rx()
2525 p2p_dbg(p2p, "Found GO Negotiation peer - try to start GO negotiation from timeout"); in p2p_probe_req_rx()
2526 eloop_cancel_timeout(p2p_go_neg_start, p2p, NULL); in p2p_probe_req_rx()
2527 eloop_register_timeout(0, 0, p2p_go_neg_start, p2p, NULL); in p2p_probe_req_rx()
2531 if ((p2p->state == P2P_INVITE || p2p->state == P2P_INVITE_LISTEN) && in p2p_probe_req_rx()
2532 p2p->invite_peer && in p2p_probe_req_rx()
2533 (p2p->invite_peer->flags & P2P_DEV_WAIT_INV_REQ_ACK) && in p2p_probe_req_rx()
2534 os_memcmp(addr, p2p->invite_peer->info.p2p_device_addr, ETH_ALEN) in p2p_probe_req_rx()
2537 p2p_dbg(p2p, "Found Invite peer - try to start Invite from timeout"); in p2p_probe_req_rx()
2538 eloop_cancel_timeout(p2p_invite_start, p2p, NULL); in p2p_probe_req_rx()
2539 eloop_register_timeout(0, 0, p2p_invite_start, p2p, NULL); in p2p_probe_req_rx()
2547 static int p2p_assoc_req_ie_wlan_ap(struct p2p_data *p2p, const u8 *bssid, in p2p_assoc_req_ie_wlan_ap() argument
2564 p2p_dbg(p2p, "BSS P2P manageability %s", in p2p_assoc_req_ie_wlan_ap()
2582 if (p2p->num_groups > 0) { in p2p_assoc_req_ie_wlan_ap()
2584 if ((p2p->dev_capab & P2P_DEV_CAPAB_CONCURRENT_OPER) && in p2p_assoc_req_ie_wlan_ap()
2585 (p2p->dev_capab & P2P_DEV_CAPAB_INFRA_MANAGED) && in p2p_assoc_req_ie_wlan_ap()
2586 p2p->cross_connect) in p2p_assoc_req_ie_wlan_ap()
2589 p2p_buf_add_capability(tmp, p2p->dev_capab, group_capab); in p2p_assoc_req_ie_wlan_ap()
2590 if ((p2p->dev_capab & P2P_DEV_CAPAB_CONCURRENT_OPER) && in p2p_assoc_req_ie_wlan_ap()
2591 (p2p->dev_capab & P2P_DEV_CAPAB_INFRA_MANAGED)) in p2p_assoc_req_ie_wlan_ap()
2592 p2p_buf_add_p2p_interface(tmp, p2p); in p2p_assoc_req_ie_wlan_ap()
2608 int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf, in p2p_assoc_req_ie() argument
2619 return p2p_assoc_req_ie_wlan_ap(p2p, bssid, buf, len, p2p_ie); in p2p_assoc_req_ie()
2622 if (p2p->wfd_ie_assoc_req) in p2p_assoc_req_ie()
2623 extra = wpabuf_len(p2p->wfd_ie_assoc_req); in p2p_assoc_req_ie()
2626 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_ASSOC_REQ]) in p2p_assoc_req_ie()
2627 extra += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_P2P_ASSOC_REQ]); in p2p_assoc_req_ie()
2640 if (p2p->wfd_ie_assoc_req) in p2p_assoc_req_ie()
2641 wpabuf_put_buf(tmp, p2p->wfd_ie_assoc_req); in p2p_assoc_req_ie()
2644 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_P2P_ASSOC_REQ]) in p2p_assoc_req_ie()
2646 p2p->vendor_elem[VENDOR_ELEM_P2P_ASSOC_REQ]); in p2p_assoc_req_ie()
2648 peer = bssid ? p2p_get_device(p2p, bssid) : NULL; in p2p_assoc_req_ie()
2651 p2p_buf_add_capability(tmp, p2p->dev_capab, 0); in p2p_assoc_req_ie()
2652 if (p2p->ext_listen_interval) in p2p_assoc_req_ie()
2653 p2p_buf_add_ext_listen_timing(tmp, p2p->ext_listen_period, in p2p_assoc_req_ie()
2654 p2p->ext_listen_interval); in p2p_assoc_req_ie()
2655 p2p_buf_add_device_info(tmp, p2p, peer); in p2p_assoc_req_ie()
2687 p2p_service_p2ps_id(struct p2p_data *p2p, u32 adv_id) in p2p_service_p2ps_id() argument
2691 if (!p2p) in p2p_service_p2ps_id()
2694 adv_data = p2p->p2ps_adv_list; in p2p_service_p2ps_id()
2705 int p2p_service_del_asp(struct p2p_data *p2p, u32 adv_id) in p2p_service_del_asp() argument
2710 if (!p2p) in p2p_service_del_asp()
2713 adv_data = p2p->p2ps_adv_list; in p2p_service_del_asp()
2714 prior = &p2p->p2ps_adv_list; in p2p_service_del_asp()
2717 p2p_dbg(p2p, "Delete ASP adv_id=0x%x", adv_id); in p2p_service_del_asp()
2730 int p2p_service_add_asp(struct p2p_data *p2p, int auto_accept, u32 adv_id, in p2p_service_add_asp() argument
2739 if (!p2p || !adv_str || !adv_str[0] || !cpt_priority) in p2p_service_add_asp()
2742 if (!(config_methods & p2p->cfg->config_methods)) { in p2p_service_add_asp()
2743 p2p_dbg(p2p, "Config methods not supported svc: 0x%x dev: 0x%x", in p2p_service_add_asp()
2744 config_methods, p2p->cfg->config_methods); in p2p_service_add_asp()
2748 if (!p2ps_gen_hash(p2p, adv_str, buf)) in p2p_service_add_asp()
2764 adv_data->config_methods = config_methods & p2p->cfg->config_methods; in p2p_service_add_asp()
2782 tmp = p2p->p2ps_adv_list; in p2p_service_add_asp()
2783 prev = &p2p->p2ps_adv_list; in p2p_service_add_asp()
2806 adv_data->next = p2p->p2ps_adv_list; in p2p_service_add_asp()
2807 p2p->p2ps_adv_list = adv_data; in p2p_service_add_asp()
2810 p2p_dbg(p2p, in p2p_service_add_asp()
2819 void p2p_service_flush_asp(struct p2p_data *p2p) in p2p_service_flush_asp() argument
2823 if (!p2p) in p2p_service_flush_asp()
2826 adv = p2p->p2ps_adv_list; in p2p_service_flush_asp()
2833 p2p->p2ps_adv_list = NULL; in p2p_service_flush_asp()
2834 p2ps_prov_free(p2p); in p2p_service_flush_asp()
2835 p2p_dbg(p2p, "All ASP advertisements flushed"); in p2p_service_flush_asp()
2873 static void p2p_clear_go_neg(struct p2p_data *p2p) in p2p_clear_go_neg() argument
2875 p2p->go_neg_peer = NULL; in p2p_clear_go_neg()
2876 p2p_clear_timeout(p2p); in p2p_clear_go_neg()
2877 p2p_set_state(p2p, P2P_IDLE); in p2p_clear_go_neg()
2881 void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr) in p2p_wps_success_cb() argument
2883 if (p2p->go_neg_peer == NULL) { in p2p_wps_success_cb()
2884 p2p_dbg(p2p, "No pending Group Formation - ignore WPS registration success notification"); in p2p_wps_success_cb()
2888 if (os_memcmp(mac_addr, p2p->go_neg_peer->intended_addr, ETH_ALEN) != in p2p_wps_success_cb()
2890 p2p_dbg(p2p, "Ignore WPS registration success notification for " in p2p_wps_success_cb()
2893 MAC2STR(p2p->go_neg_peer->intended_addr)); in p2p_wps_success_cb()
2897 p2p_dbg(p2p, "Group Formation completed successfully with " MACSTR, in p2p_wps_success_cb()
2900 p2p_clear_go_neg(p2p); in p2p_wps_success_cb()
2904 void p2p_group_formation_failed(struct p2p_data *p2p) in p2p_group_formation_failed() argument
2906 if (p2p->go_neg_peer == NULL) { in p2p_group_formation_failed()
2907 p2p_dbg(p2p, "No pending Group Formation - ignore group formation failure notification"); in p2p_group_formation_failed()
2911 p2p_dbg(p2p, "Group Formation failed with " MACSTR, in p2p_group_formation_failed()
2912 MAC2STR(p2p->go_neg_peer->intended_addr)); in p2p_group_formation_failed()
2914 p2p_clear_go_neg(p2p); in p2p_group_formation_failed()
2920 struct p2p_data *p2p; in p2p_init() local
2926 p2p = os_zalloc(sizeof(*p2p) + sizeof(*cfg)); in p2p_init()
2927 if (p2p == NULL) in p2p_init()
2929 p2p->cfg = (struct p2p_config *) (p2p + 1); in p2p_init()
2930 os_memcpy(p2p->cfg, cfg, sizeof(*cfg)); in p2p_init()
2932 p2p->cfg->dev_name = os_strdup(cfg->dev_name); in p2p_init()
2934 p2p->cfg->manufacturer = os_strdup(cfg->manufacturer); in p2p_init()
2936 p2p->cfg->model_name = os_strdup(cfg->model_name); in p2p_init()
2938 p2p->cfg->model_number = os_strdup(cfg->model_number); in p2p_init()
2940 p2p->cfg->serial_number = os_strdup(cfg->serial_number); in p2p_init()
2942 p2p->cfg->pref_chan = os_malloc(cfg->num_pref_chan * in p2p_init()
2944 if (p2p->cfg->pref_chan) { in p2p_init()
2945 os_memcpy(p2p->cfg->pref_chan, cfg->pref_chan, in p2p_init()
2949 p2p->cfg->num_pref_chan = 0; in p2p_init()
2952 p2ps_gen_hash(p2p, P2PS_WILD_HASH_STR, p2p->wild_card_hash); in p2p_init()
2954 p2p->min_disc_int = 1; in p2p_init()
2955 p2p->max_disc_int = 3; in p2p_init()
2956 p2p->max_disc_tu = -1; in p2p_init()
2958 if (os_get_random(&p2p->next_tie_breaker, 1) < 0) in p2p_init()
2959 p2p->next_tie_breaker = 0; in p2p_init()
2960 p2p->next_tie_breaker &= 0x01; in p2p_init()
2962 p2p->dev_capab |= P2P_DEV_CAPAB_SERVICE_DISCOVERY; in p2p_init()
2963 p2p->dev_capab |= P2P_DEV_CAPAB_INVITATION_PROCEDURE; in p2p_init()
2965 p2p->dev_capab |= P2P_DEV_CAPAB_CONCURRENT_OPER; in p2p_init()
2966 p2p->dev_capab |= P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; in p2p_init()
2968 dl_list_init(&p2p->devices); in p2p_init()
2970 p2p->go_timeout = 100; in p2p_init()
2971 p2p->client_timeout = 20; in p2p_init()
2972 p2p->num_p2p_sd_queries = 0; in p2p_init()
2974 p2p_dbg(p2p, "initialized"); in p2p_init()
2975 p2p_channels_dump(p2p, "channels", &p2p->cfg->channels); in p2p_init()
2976 p2p_channels_dump(p2p, "cli_channels", &p2p->cfg->cli_channels); in p2p_init()
2978 return p2p; in p2p_init()
2982 void p2p_deinit(struct p2p_data *p2p) in p2p_deinit() argument
2985 wpabuf_free(p2p->wfd_ie_beacon); in p2p_deinit()
2986 wpabuf_free(p2p->wfd_ie_probe_req); in p2p_deinit()
2987 wpabuf_free(p2p->wfd_ie_probe_resp); in p2p_deinit()
2988 wpabuf_free(p2p->wfd_ie_assoc_req); in p2p_deinit()
2989 wpabuf_free(p2p->wfd_ie_invitation); in p2p_deinit()
2990 wpabuf_free(p2p->wfd_ie_prov_disc_req); in p2p_deinit()
2991 wpabuf_free(p2p->wfd_ie_prov_disc_resp); in p2p_deinit()
2992 wpabuf_free(p2p->wfd_ie_go_neg); in p2p_deinit()
2993 wpabuf_free(p2p->wfd_dev_info); in p2p_deinit()
2994 wpabuf_free(p2p->wfd_assoc_bssid); in p2p_deinit()
2995 wpabuf_free(p2p->wfd_coupled_sink_info); in p2p_deinit()
2998 eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); in p2p_deinit()
2999 eloop_cancel_timeout(p2p_go_neg_start, p2p, NULL); in p2p_deinit()
3000 eloop_cancel_timeout(p2p_go_neg_wait_timeout, p2p, NULL); in p2p_deinit()
3001 p2p_flush(p2p); in p2p_deinit()
3002 p2p_free_req_dev_types(p2p); in p2p_deinit()
3003 os_free(p2p->cfg->dev_name); in p2p_deinit()
3004 os_free(p2p->cfg->manufacturer); in p2p_deinit()
3005 os_free(p2p->cfg->model_name); in p2p_deinit()
3006 os_free(p2p->cfg->model_number); in p2p_deinit()
3007 os_free(p2p->cfg->serial_number); in p2p_deinit()
3008 os_free(p2p->cfg->pref_chan); in p2p_deinit()
3009 os_free(p2p->groups); in p2p_deinit()
3010 p2ps_prov_free(p2p); in p2p_deinit()
3011 wpabuf_free(p2p->sd_resp); in p2p_deinit()
3012 p2p_remove_wps_vendor_extensions(p2p); in p2p_deinit()
3013 os_free(p2p->no_go_freq.range); in p2p_deinit()
3014 p2p_service_flush_asp(p2p); in p2p_deinit()
3016 os_free(p2p); in p2p_deinit()
3020 void p2p_flush(struct p2p_data *p2p) in p2p_flush() argument
3024 p2p_ext_listen(p2p, 0, 0); in p2p_flush()
3025 p2p_stop_find(p2p); in p2p_flush()
3026 dl_list_for_each_safe(dev, prev, &p2p->devices, struct p2p_device, in p2p_flush()
3029 p2p_device_free(p2p, dev); in p2p_flush()
3031 p2p_free_sd_queries(p2p); in p2p_flush()
3032 os_free(p2p->after_scan_tx); in p2p_flush()
3033 p2p->after_scan_tx = NULL; in p2p_flush()
3034 p2p->ssid_set = 0; in p2p_flush()
3035 p2ps_prov_free(p2p); in p2p_flush()
3036 p2p_reset_pending_pd(p2p); in p2p_flush()
3037 p2p->override_pref_op_class = 0; in p2p_flush()
3038 p2p->override_pref_channel = 0; in p2p_flush()
3042 int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr) in p2p_unauthorize() argument
3046 dev = p2p_get_device(p2p, addr); in p2p_unauthorize()
3050 p2p_dbg(p2p, "Unauthorizing " MACSTR, MAC2STR(addr)); in p2p_unauthorize()
3052 if (p2p->go_neg_peer == dev) { in p2p_unauthorize()
3053 eloop_cancel_timeout(p2p_go_neg_wait_timeout, p2p, NULL); in p2p_unauthorize()
3054 p2p->go_neg_peer = NULL; in p2p_unauthorize()
3063 if (p2p->after_scan_tx && in p2p_unauthorize()
3064 os_memcmp(addr, p2p->after_scan_tx->dst, ETH_ALEN) == 0) { in p2p_unauthorize()
3065 os_free(p2p->after_scan_tx); in p2p_unauthorize()
3066 p2p->after_scan_tx = NULL; in p2p_unauthorize()
3073 int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name) in p2p_set_dev_name() argument
3075 os_free(p2p->cfg->dev_name); in p2p_set_dev_name()
3077 p2p->cfg->dev_name = os_strdup(dev_name); in p2p_set_dev_name()
3078 if (p2p->cfg->dev_name == NULL) in p2p_set_dev_name()
3081 p2p->cfg->dev_name = NULL; in p2p_set_dev_name()
3086 int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer) in p2p_set_manufacturer() argument
3088 os_free(p2p->cfg->manufacturer); in p2p_set_manufacturer()
3089 p2p->cfg->manufacturer = NULL; in p2p_set_manufacturer()
3091 p2p->cfg->manufacturer = os_strdup(manufacturer); in p2p_set_manufacturer()
3092 if (p2p->cfg->manufacturer == NULL) in p2p_set_manufacturer()
3100 int p2p_set_model_name(struct p2p_data *p2p, const char *model_name) in p2p_set_model_name() argument
3102 os_free(p2p->cfg->model_name); in p2p_set_model_name()
3103 p2p->cfg->model_name = NULL; in p2p_set_model_name()
3105 p2p->cfg->model_name = os_strdup(model_name); in p2p_set_model_name()
3106 if (p2p->cfg->model_name == NULL) in p2p_set_model_name()
3114 int p2p_set_model_number(struct p2p_data *p2p, const char *model_number) in p2p_set_model_number() argument
3116 os_free(p2p->cfg->model_number); in p2p_set_model_number()
3117 p2p->cfg->model_number = NULL; in p2p_set_model_number()
3119 p2p->cfg->model_number = os_strdup(model_number); in p2p_set_model_number()
3120 if (p2p->cfg->model_number == NULL) in p2p_set_model_number()
3128 int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number) in p2p_set_serial_number() argument
3130 os_free(p2p->cfg->serial_number); in p2p_set_serial_number()
3131 p2p->cfg->serial_number = NULL; in p2p_set_serial_number()
3133 p2p->cfg->serial_number = os_strdup(serial_number); in p2p_set_serial_number()
3134 if (p2p->cfg->serial_number == NULL) in p2p_set_serial_number()
3142 void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods) in p2p_set_config_methods() argument
3144 p2p->cfg->config_methods = config_methods; in p2p_set_config_methods()
3148 void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid) in p2p_set_uuid() argument
3150 os_memcpy(p2p->cfg->uuid, uuid, 16); in p2p_set_uuid()
3154 int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type) in p2p_set_pri_dev_type() argument
3156 os_memcpy(p2p->cfg->pri_dev_type, pri_dev_type, 8); in p2p_set_pri_dev_type()
3161 int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8], in p2p_set_sec_dev_types() argument
3166 p2p->cfg->num_sec_dev_types = num_dev_types; in p2p_set_sec_dev_types()
3167 os_memcpy(p2p->cfg->sec_dev_type, dev_types, num_dev_types * 8); in p2p_set_sec_dev_types()
3172 void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p) in p2p_remove_wps_vendor_extensions() argument
3177 wpabuf_free(p2p->wps_vendor_ext[i]); in p2p_remove_wps_vendor_extensions()
3178 p2p->wps_vendor_ext[i] = NULL; in p2p_remove_wps_vendor_extensions()
3183 int p2p_add_wps_vendor_extension(struct p2p_data *p2p, in p2p_add_wps_vendor_extension() argument
3192 if (p2p->wps_vendor_ext[i] == NULL) in p2p_add_wps_vendor_extension()
3198 p2p->wps_vendor_ext[i] = wpabuf_dup(vendor_ext); in p2p_add_wps_vendor_extension()
3199 if (p2p->wps_vendor_ext[i] == NULL) in p2p_add_wps_vendor_extension()
3206 int p2p_set_country(struct p2p_data *p2p, const char *country) in p2p_set_country() argument
3208 os_memcpy(p2p->cfg->country, country, 3); in p2p_set_country()
3213 static int p2p_pre_find_operation(struct p2p_data *p2p, struct p2p_device *dev) in p2p_pre_find_operation() argument
3220 dev->sd_pending_bcast_queries = p2p->num_p2p_sd_queries; in p2p_pre_find_operation()
3223 res = p2p_start_sd(p2p, dev); in p2p_pre_find_operation()
3231 p2p_dbg(p2p, "Send pending Provision Discovery Request to " in p2p_pre_find_operation()
3235 if (p2p_send_prov_disc_req(p2p, dev, 0, 0) == 0) in p2p_pre_find_operation()
3243 void p2p_continue_find(struct p2p_data *p2p) in p2p_continue_find() argument
3248 p2p_set_state(p2p, P2P_SEARCH); in p2p_continue_find()
3252 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_continue_find()
3253 if (dev == p2p->last_p2p_find_oper) { in p2p_continue_find()
3259 res = p2p_pre_find_operation(p2p, dev); in p2p_continue_find()
3261 p2p->last_p2p_find_oper = dev; in p2p_continue_find()
3272 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_continue_find()
3273 res = p2p_pre_find_operation(p2p, dev); in p2p_continue_find()
3275 p2p->last_p2p_find_oper = dev; in p2p_continue_find()
3280 if (dev == p2p->last_p2p_find_oper) in p2p_continue_find()
3285 os_memset(p2p->sd_query_no_ack, 0, ETH_ALEN); in p2p_continue_find()
3286 p2p_listen_in_find(p2p, 1); in p2p_continue_find()
3290 static void p2p_sd_cb(struct p2p_data *p2p, int success) in p2p_sd_cb() argument
3292 p2p_dbg(p2p, "Service Discovery Query TX callback: success=%d", in p2p_sd_cb()
3294 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_sd_cb()
3297 if (p2p->sd_peer) { in p2p_sd_cb()
3298 if (is_zero_ether_addr(p2p->sd_query_no_ack)) { in p2p_sd_cb()
3299 os_memcpy(p2p->sd_query_no_ack, in p2p_sd_cb()
3300 p2p->sd_peer->info.p2p_device_addr, in p2p_sd_cb()
3302 p2p_dbg(p2p, in p2p_sd_cb()
3304 MACSTR, MAC2STR(p2p->sd_query_no_ack)); in p2p_sd_cb()
3306 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_sd_cb()
3308 p2p->sd_peer = NULL; in p2p_sd_cb()
3309 if (p2p->state != P2P_IDLE) in p2p_sd_cb()
3310 p2p_continue_find(p2p); in p2p_sd_cb()
3314 if (p2p->sd_peer == NULL) { in p2p_sd_cb()
3315 p2p_dbg(p2p, "No SD peer entry known"); in p2p_sd_cb()
3316 if (p2p->state != P2P_IDLE) in p2p_sd_cb()
3317 p2p_continue_find(p2p); in p2p_sd_cb()
3321 if (p2p->sd_query && p2p->sd_query->for_all_peers) { in p2p_sd_cb()
3324 p2p->sd_peer->sd_pending_bcast_queries--; in p2p_sd_cb()
3330 if (p2p->sd_peer->sd_pending_bcast_queries == 0) in p2p_sd_cb()
3331 p2p->sd_peer->sd_pending_bcast_queries = -1; in p2p_sd_cb()
3335 p2p_set_state(p2p, P2P_SD_DURING_FIND); in p2p_sd_cb()
3336 p2p_set_timeout(p2p, 0, 200000); in p2p_sd_cb()
3344 static void p2p_retry_pd(struct p2p_data *p2p) in p2p_retry_pd() argument
3353 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_retry_pd()
3354 if (os_memcmp(p2p->pending_pd_devaddr, in p2p_retry_pd()
3360 p2p_dbg(p2p, "Send pending Provision Discovery Request to " in p2p_retry_pd()
3364 p2p_send_prov_disc_req(p2p, dev, in p2p_retry_pd()
3366 p2p->pd_force_freq); in p2p_retry_pd()
3372 static void p2p_prov_disc_cb(struct p2p_data *p2p, int success) in p2p_prov_disc_cb() argument
3374 p2p_dbg(p2p, "Provision Discovery Request TX callback: success=%d", in p2p_prov_disc_cb()
3388 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_prov_disc_cb()
3390 if (p2p->user_initiated_pd && in p2p_prov_disc_cb()
3391 (p2p->state == P2P_SEARCH || p2p->state == P2P_LISTEN_ONLY)) in p2p_prov_disc_cb()
3394 p2p->pending_action_state = P2P_PENDING_PD; in p2p_prov_disc_cb()
3395 p2p_set_timeout(p2p, 0, 50000); in p2p_prov_disc_cb()
3396 } else if (p2p->state != P2P_IDLE) in p2p_prov_disc_cb()
3397 p2p_continue_find(p2p); in p2p_prov_disc_cb()
3398 else if (p2p->user_initiated_pd) { in p2p_prov_disc_cb()
3399 p2p->pending_action_state = P2P_PENDING_PD; in p2p_prov_disc_cb()
3400 p2p_set_timeout(p2p, 0, 300000); in p2p_prov_disc_cb()
3411 if (p2p->p2ps_prov && !p2p->p2ps_prov->pd_seeker && in p2p_prov_disc_cb()
3412 p2p->p2ps_prov->status != P2P_SC_SUCCESS_DEFERRED) { in p2p_prov_disc_cb()
3413 p2p_dbg(p2p, "P2PS PD completion on Follow-on PD Request ACK"); in p2p_prov_disc_cb()
3415 if (p2p->send_action_in_progress) { in p2p_prov_disc_cb()
3416 p2p->send_action_in_progress = 0; in p2p_prov_disc_cb()
3417 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_prov_disc_cb()
3420 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_prov_disc_cb()
3422 if (p2p->cfg->p2ps_prov_complete) { in p2p_prov_disc_cb()
3423 p2p->cfg->p2ps_prov_complete( in p2p_prov_disc_cb()
3424 p2p->cfg->cb_ctx, in p2p_prov_disc_cb()
3425 p2p->p2ps_prov->status, in p2p_prov_disc_cb()
3426 p2p->p2ps_prov->adv_mac, in p2p_prov_disc_cb()
3427 p2p->p2ps_prov->adv_mac, in p2p_prov_disc_cb()
3428 p2p->p2ps_prov->session_mac, in p2p_prov_disc_cb()
3429 NULL, p2p->p2ps_prov->adv_id, in p2p_prov_disc_cb()
3430 p2p->p2ps_prov->session_id, in p2p_prov_disc_cb()
3435 if (p2p->user_initiated_pd) in p2p_prov_disc_cb()
3436 p2p_reset_pending_pd(p2p); in p2p_prov_disc_cb()
3438 p2ps_prov_free(p2p); in p2p_prov_disc_cb()
3446 if (p2p->user_initiated_pd) in p2p_prov_disc_cb()
3447 p2p->pending_action_state = P2P_PENDING_PD; in p2p_prov_disc_cb()
3449 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_prov_disc_cb()
3452 if (p2p->state == P2P_SEARCH) in p2p_prov_disc_cb()
3453 p2p_set_state(p2p, P2P_PD_DURING_FIND); in p2p_prov_disc_cb()
3454 p2p_set_timeout(p2p, 0, 200000); in p2p_prov_disc_cb()
3458 static int p2p_check_after_scan_tx_continuation(struct p2p_data *p2p) in p2p_check_after_scan_tx_continuation() argument
3460 if (p2p->after_scan_tx_in_progress) { in p2p_check_after_scan_tx_continuation()
3461 p2p->after_scan_tx_in_progress = 0; in p2p_check_after_scan_tx_continuation()
3462 if (p2p->start_after_scan != P2P_AFTER_SCAN_NOTHING && in p2p_check_after_scan_tx_continuation()
3463 p2p_run_after_scan(p2p)) in p2p_check_after_scan_tx_continuation()
3465 if (p2p->state == P2P_SEARCH) { in p2p_check_after_scan_tx_continuation()
3466 p2p_dbg(p2p, "Continue find after after_scan_tx completion"); in p2p_check_after_scan_tx_continuation()
3467 p2p_continue_find(p2p); in p2p_check_after_scan_tx_continuation()
3475 static void p2p_prov_disc_resp_cb(struct p2p_data *p2p, int success) in p2p_prov_disc_resp_cb() argument
3477 p2p_dbg(p2p, "Provision Discovery Response TX callback: success=%d", in p2p_prov_disc_resp_cb()
3480 if (p2p->send_action_in_progress) { in p2p_prov_disc_resp_cb()
3481 p2p->send_action_in_progress = 0; in p2p_prov_disc_resp_cb()
3482 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_prov_disc_resp_cb()
3485 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_prov_disc_resp_cb()
3490 if (!p2p->cfg->prov_disc_resp_cb || in p2p_prov_disc_resp_cb()
3491 p2p->cfg->prov_disc_resp_cb(p2p->cfg->cb_ctx) < 1) in p2p_prov_disc_resp_cb()
3494 p2p_dbg(p2p, in p2p_prov_disc_resp_cb()
3499 p2p_check_after_scan_tx_continuation(p2p); in p2p_prov_disc_resp_cb()
3503 int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, in p2p_scan_res_handler() argument
3507 if (os_reltime_before(rx_time, &p2p->find_start)) { in p2p_scan_res_handler()
3515 p2p_dbg(p2p, "Ignore old scan result for " MACSTR in p2p_scan_res_handler()
3519 (unsigned int) p2p->find_start.sec, in p2p_scan_res_handler()
3520 (unsigned int) p2p->find_start.usec); in p2p_scan_res_handler()
3524 p2p_add_device(p2p, bssid, freq, rx_time, level, ies, ies_len, 1); in p2p_scan_res_handler()
3530 void p2p_scan_res_handled(struct p2p_data *p2p) in p2p_scan_res_handled() argument
3532 if (!p2p->p2p_scan_running) { in p2p_scan_res_handled()
3533 p2p_dbg(p2p, "p2p_scan was not running, but scan results received"); in p2p_scan_res_handled()
3535 p2p->p2p_scan_running = 0; in p2p_scan_res_handled()
3536 eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); in p2p_scan_res_handled()
3538 if (p2p_run_after_scan(p2p)) in p2p_scan_res_handled()
3540 if (p2p->state == P2P_SEARCH) in p2p_scan_res_handled()
3541 p2p_continue_find(p2p); in p2p_scan_res_handled()
3545 void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id, in p2p_scan_ie() argument
3552 if (p2p->wfd_ie_probe_req) in p2p_scan_ie()
3553 wpabuf_put_buf(ies, p2p->wfd_ie_probe_req); in p2p_scan_ie()
3556 if (p2p->vendor_elem && p2p->vendor_elem[VENDOR_ELEM_PROBE_REQ_P2P]) in p2p_scan_ie()
3558 p2p->vendor_elem[VENDOR_ELEM_PROBE_REQ_P2P]); in p2p_scan_ie()
3562 dev_capab = p2p->dev_capab & ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; in p2p_scan_ie()
3565 if (p2p->p2ps_seek && p2p->p2ps_seek_count) in p2p_scan_ie()
3572 if (p2p->cfg->reg_class && p2p->cfg->channel) in p2p_scan_ie()
3573 p2p_buf_add_listen_channel(ies, p2p->cfg->country, in p2p_scan_ie()
3574 p2p->cfg->reg_class, in p2p_scan_ie()
3575 p2p->cfg->channel); in p2p_scan_ie()
3576 if (p2p->ext_listen_interval) in p2p_scan_ie()
3577 p2p_buf_add_ext_listen_timing(ies, p2p->ext_listen_period, in p2p_scan_ie()
3578 p2p->ext_listen_interval); in p2p_scan_ie()
3581 p2p_buf_add_device_info(ies, p2p, NULL); in p2p_scan_ie()
3583 if (p2p->p2ps_seek && p2p->p2ps_seek_count) in p2p_scan_ie()
3584 p2p_buf_add_service_hash(ies, p2p); in p2p_scan_ie()
3591 size_t p2p_scan_ie_buf_len(struct p2p_data *p2p) in p2p_scan_ie_buf_len() argument
3596 if (p2p && p2p->wfd_ie_probe_req) in p2p_scan_ie_buf_len()
3597 len += wpabuf_len(p2p->wfd_ie_probe_req); in p2p_scan_ie_buf_len()
3600 if (p2p && p2p->vendor_elem && in p2p_scan_ie_buf_len()
3601 p2p->vendor_elem[VENDOR_ELEM_PROBE_REQ_P2P]) in p2p_scan_ie_buf_len()
3602 len += wpabuf_len(p2p->vendor_elem[VENDOR_ELEM_PROBE_REQ_P2P]); in p2p_scan_ie_buf_len()
3614 static void p2p_go_neg_req_cb(struct p2p_data *p2p, int success) in p2p_go_neg_req_cb() argument
3616 struct p2p_device *dev = p2p->go_neg_peer; in p2p_go_neg_req_cb()
3619 p2p_dbg(p2p, "GO Negotiation Request TX callback: success=%d", success); in p2p_go_neg_req_cb()
3622 p2p_dbg(p2p, "No pending GO Negotiation"); in p2p_go_neg_req_cb()
3628 p2p_set_state(p2p, P2P_IDLE); in p2p_go_neg_req_cb()
3639 …p2p_dbg(p2p, "Peer " MACSTR " did not acknowledge request - try to use device discoverability thro… in p2p_go_neg_req_cb()
3641 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_go_neg_req_cb()
3642 p2p_send_dev_disc_req(p2p, dev); in p2p_go_neg_req_cb()
3650 p2p_set_state(p2p, P2P_CONNECT); in p2p_go_neg_req_cb()
3652 if (!success && p2p->go_neg_peer && in p2p_go_neg_req_cb()
3653 (p2p->go_neg_peer->flags & P2P_DEV_PEER_WAITING_RESPONSE)) { in p2p_go_neg_req_cb()
3665 p2p_set_timeout(p2p, 0, timeout); in p2p_go_neg_req_cb()
3669 static void p2p_go_neg_resp_cb(struct p2p_data *p2p, int success) in p2p_go_neg_resp_cb() argument
3671 p2p_dbg(p2p, "GO Negotiation Response TX callback: success=%d", in p2p_go_neg_resp_cb()
3673 if (!p2p->go_neg_peer && p2p->state == P2P_PROVISIONING) { in p2p_go_neg_resp_cb()
3674 p2p_dbg(p2p, "Ignore TX callback event - GO Negotiation is not running anymore"); in p2p_go_neg_resp_cb()
3677 p2p_set_state(p2p, P2P_CONNECT); in p2p_go_neg_resp_cb()
3678 p2p_set_timeout(p2p, 0, 500000); in p2p_go_neg_resp_cb()
3682 static void p2p_go_neg_resp_failure_cb(struct p2p_data *p2p, int success, in p2p_go_neg_resp_failure_cb() argument
3685 p2p_dbg(p2p, "GO Negotiation Response (failure) TX callback: success=%d", success); in p2p_go_neg_resp_failure_cb()
3686 if (p2p->go_neg_peer && p2p->go_neg_peer->status != P2P_SC_SUCCESS) { in p2p_go_neg_resp_failure_cb()
3687 p2p_go_neg_failed(p2p, p2p->go_neg_peer->status); in p2p_go_neg_resp_failure_cb()
3693 dev = p2p_get_device(p2p, addr); in p2p_go_neg_resp_failure_cb()
3699 if (p2p->state == P2P_SEARCH || p2p->state == P2P_SD_DURING_FIND) in p2p_go_neg_resp_failure_cb()
3700 p2p_continue_find(p2p); in p2p_go_neg_resp_failure_cb()
3704 static void p2p_go_neg_conf_cb(struct p2p_data *p2p, in p2p_go_neg_conf_cb() argument
3709 p2p_dbg(p2p, "GO Negotiation Confirm TX callback: result=%d", result); in p2p_go_neg_conf_cb()
3711 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_go_neg_conf_cb()
3712 p2p_go_neg_failed(p2p, -1); in p2p_go_neg_conf_cb()
3716 dev = p2p->go_neg_peer; in p2p_go_neg_conf_cb()
3726 p2p_dbg(p2p, "GO Negotiation Confirm retry %d", in p2p_go_neg_conf_cb()
3728 p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM; in p2p_go_neg_conf_cb()
3729 if (p2p_send_action(p2p, dev->go_neg_conf_freq, in p2p_go_neg_conf_cb()
3731 p2p->cfg->dev_addr, in p2p_go_neg_conf_cb()
3739 p2p_dbg(p2p, "Failed to re-send Action frame"); in p2p_go_neg_conf_cb()
3757 …p2p_dbg(p2p, "Assume GO Negotiation Confirm TX was actually received by the peer even though Ack w… in p2p_go_neg_conf_cb()
3760 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_go_neg_conf_cb()
3765 p2p_go_complete(p2p, dev); in p2p_go_neg_conf_cb()
3769 void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst, in p2p_send_action_cb() argument
3776 p2p_dbg(p2p, "Action frame TX callback (state=%d freq=%u dst=" MACSTR in p2p_send_action_cb()
3778 p2p->pending_action_state, freq, MAC2STR(dst), MAC2STR(src), in p2p_send_action_cb()
3779 MAC2STR(bssid), result, p2p_state_txt(p2p->state)); in p2p_send_action_cb()
3781 state = p2p->pending_action_state; in p2p_send_action_cb()
3782 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_send_action_cb()
3785 if (p2p->send_action_in_progress) { in p2p_send_action_cb()
3786 p2p->send_action_in_progress = 0; in p2p_send_action_cb()
3787 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_send_action_cb()
3789 p2p_check_after_scan_tx_continuation(p2p); in p2p_send_action_cb()
3792 p2p_go_neg_req_cb(p2p, success); in p2p_send_action_cb()
3795 p2p_go_neg_resp_cb(p2p, success); in p2p_send_action_cb()
3798 p2p_go_neg_resp_failure_cb(p2p, success, dst); in p2p_send_action_cb()
3801 p2p_go_neg_conf_cb(p2p, result); in p2p_send_action_cb()
3804 p2p_sd_cb(p2p, success); in p2p_send_action_cb()
3807 p2p_prov_disc_cb(p2p, success); in p2p_send_action_cb()
3810 p2p_prov_disc_resp_cb(p2p, success); in p2p_send_action_cb()
3813 p2p_invitation_req_cb(p2p, success); in p2p_send_action_cb()
3816 p2p_invitation_resp_cb(p2p, success); in p2p_send_action_cb()
3817 if (p2p->inv_status != P2P_SC_SUCCESS) in p2p_send_action_cb()
3818 p2p_check_after_scan_tx_continuation(p2p); in p2p_send_action_cb()
3821 p2p_dev_disc_req_cb(p2p, success); in p2p_send_action_cb()
3824 p2p_dev_disc_resp_cb(p2p, success); in p2p_send_action_cb()
3827 p2p_go_disc_req_cb(p2p, success); in p2p_send_action_cb()
3831 p2p->after_scan_tx_in_progress = 0; in p2p_send_action_cb()
3835 void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq, in p2p_listen_cb() argument
3838 if (freq == p2p->pending_client_disc_freq) { in p2p_listen_cb()
3839 p2p_dbg(p2p, "Client discoverability remain-awake completed"); in p2p_listen_cb()
3840 p2p->pending_client_disc_freq = 0; in p2p_listen_cb()
3844 if (freq != p2p->pending_listen_freq) { in p2p_listen_cb()
3845 p2p_dbg(p2p, "Unexpected listen callback for freq=%u duration=%u (pending_listen_freq=%u)", in p2p_listen_cb()
3846 freq, duration, p2p->pending_listen_freq); in p2p_listen_cb()
3850 p2p_dbg(p2p, "Starting Listen timeout(%u,%u) on freq=%u based on callback", in p2p_listen_cb()
3851 p2p->pending_listen_sec, p2p->pending_listen_usec, in p2p_listen_cb()
3852 p2p->pending_listen_freq); in p2p_listen_cb()
3853 p2p->in_listen = 1; in p2p_listen_cb()
3854 p2p->drv_in_listen = freq; in p2p_listen_cb()
3855 if (p2p->pending_listen_sec || p2p->pending_listen_usec) { in p2p_listen_cb()
3861 p2p_set_timeout(p2p, p2p->pending_listen_sec, in p2p_listen_cb()
3862 p2p->pending_listen_usec + 20000); in p2p_listen_cb()
3865 p2p->pending_listen_freq = 0; in p2p_listen_cb()
3869 int p2p_listen_end(struct p2p_data *p2p, unsigned int freq) in p2p_listen_end() argument
3871 p2p_dbg(p2p, "Driver ended Listen state (freq=%u)", freq); in p2p_listen_end()
3872 p2p->drv_in_listen = 0; in p2p_listen_end()
3873 if (p2p->in_listen) in p2p_listen_end()
3876 if (p2p->state == P2P_CONNECT_LISTEN && p2p->go_neg_peer) { in p2p_listen_end()
3877 if (p2p->go_neg_peer->connect_reqs >= 120) { in p2p_listen_end()
3878 p2p_dbg(p2p, "Timeout on sending GO Negotiation Request without getting response"); in p2p_listen_end()
3879 p2p_go_neg_failed(p2p, -1); in p2p_listen_end()
3883 p2p_set_state(p2p, P2P_CONNECT); in p2p_listen_end()
3884 p2p_connect_send(p2p, p2p->go_neg_peer); in p2p_listen_end()
3886 } else if (p2p->state == P2P_SEARCH) { in p2p_listen_end()
3887 if (p2p->p2p_scan_running) { in p2p_listen_end()
3896 p2p_dbg(p2p, "p2p_scan already in progress - do not try to start a new one"); in p2p_listen_end()
3899 if (p2p->pending_listen_freq) { in p2p_listen_end()
3905 p2p_dbg(p2p, "Listen operation did not seem to start - delay search phase to avoid busy loop"); in p2p_listen_end()
3906 p2p_set_timeout(p2p, 0, 100000); in p2p_listen_end()
3909 if (p2p->search_delay) { in p2p_listen_end()
3910 p2p_dbg(p2p, "Delay search operation by %u ms", in p2p_listen_end()
3911 p2p->search_delay); in p2p_listen_end()
3912 p2p_set_timeout(p2p, p2p->search_delay / 1000, in p2p_listen_end()
3913 (p2p->search_delay % 1000) * 1000); in p2p_listen_end()
3916 p2p_search(p2p); in p2p_listen_end()
3924 static void p2p_timeout_connect(struct p2p_data *p2p) in p2p_timeout_connect() argument
3926 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_timeout_connect()
3927 if (p2p->go_neg_peer && in p2p_timeout_connect()
3928 (p2p->go_neg_peer->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) { in p2p_timeout_connect()
3929 p2p_dbg(p2p, "Wait for GO Negotiation Confirm timed out - assume GO Negotiation failed"); in p2p_timeout_connect()
3930 p2p_go_neg_failed(p2p, -1); in p2p_timeout_connect()
3933 if (p2p->go_neg_peer && in p2p_timeout_connect()
3934 (p2p->go_neg_peer->flags & P2P_DEV_PEER_WAITING_RESPONSE) && in p2p_timeout_connect()
3935 p2p->go_neg_peer->connect_reqs < 120) { in p2p_timeout_connect()
3936 p2p_dbg(p2p, "Peer expected to wait our response - skip listen"); in p2p_timeout_connect()
3937 p2p_connect_send(p2p, p2p->go_neg_peer); in p2p_timeout_connect()
3940 if (p2p->go_neg_peer && p2p->go_neg_peer->oob_go_neg_freq > 0) { in p2p_timeout_connect()
3941 p2p_dbg(p2p, "Skip connect-listen since GO Neg channel known (OOB)"); in p2p_timeout_connect()
3942 p2p_set_state(p2p, P2P_CONNECT_LISTEN); in p2p_timeout_connect()
3943 p2p_set_timeout(p2p, 0, 30000); in p2p_timeout_connect()
3946 p2p_set_state(p2p, P2P_CONNECT_LISTEN); in p2p_timeout_connect()
3947 p2p_listen_in_find(p2p, 0); in p2p_timeout_connect()
3951 static void p2p_timeout_connect_listen(struct p2p_data *p2p) in p2p_timeout_connect_listen() argument
3953 if (p2p->go_neg_peer) { in p2p_timeout_connect_listen()
3954 if (p2p->drv_in_listen) { in p2p_timeout_connect_listen()
3955 p2p_dbg(p2p, "Driver is still in Listen state; wait for it to complete"); in p2p_timeout_connect_listen()
3959 if (p2p->go_neg_peer->connect_reqs >= 120) { in p2p_timeout_connect_listen()
3960 p2p_dbg(p2p, "Timeout on sending GO Negotiation Request without getting response"); in p2p_timeout_connect_listen()
3961 p2p_go_neg_failed(p2p, -1); in p2p_timeout_connect_listen()
3965 p2p_set_state(p2p, P2P_CONNECT); in p2p_timeout_connect_listen()
3966 p2p_connect_send(p2p, p2p->go_neg_peer); in p2p_timeout_connect_listen()
3968 p2p_set_state(p2p, P2P_IDLE); in p2p_timeout_connect_listen()
3972 static void p2p_timeout_wait_peer_connect(struct p2p_data *p2p) in p2p_timeout_wait_peer_connect() argument
3974 p2p_set_state(p2p, P2P_WAIT_PEER_IDLE); in p2p_timeout_wait_peer_connect()
3976 if (p2p->cfg->is_concurrent_session_active && in p2p_timeout_wait_peer_connect()
3977 p2p->cfg->is_concurrent_session_active(p2p->cfg->cb_ctx)) in p2p_timeout_wait_peer_connect()
3978 p2p_set_timeout(p2p, 0, 500000); in p2p_timeout_wait_peer_connect()
3980 p2p_set_timeout(p2p, 0, 200000); in p2p_timeout_wait_peer_connect()
3984 static void p2p_timeout_wait_peer_idle(struct p2p_data *p2p) in p2p_timeout_wait_peer_idle() argument
3986 struct p2p_device *dev = p2p->go_neg_peer; in p2p_timeout_wait_peer_idle()
3989 p2p_dbg(p2p, "Unknown GO Neg peer - stop GO Neg wait"); in p2p_timeout_wait_peer_idle()
3993 p2p_dbg(p2p, "Go to Listen state while waiting for the peer to become ready for GO Negotiation"); in p2p_timeout_wait_peer_idle()
3994 p2p_set_state(p2p, P2P_WAIT_PEER_CONNECT); in p2p_timeout_wait_peer_idle()
3995 p2p_listen_in_find(p2p, 0); in p2p_timeout_wait_peer_idle()
3999 static void p2p_timeout_sd_during_find(struct p2p_data *p2p) in p2p_timeout_sd_during_find() argument
4001 p2p_dbg(p2p, "Service Discovery Query timeout"); in p2p_timeout_sd_during_find()
4002 if (p2p->sd_peer) { in p2p_timeout_sd_during_find()
4003 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_timeout_sd_during_find()
4004 p2p->sd_peer = NULL; in p2p_timeout_sd_during_find()
4006 p2p_continue_find(p2p); in p2p_timeout_sd_during_find()
4010 static void p2p_timeout_prov_disc_during_find(struct p2p_data *p2p) in p2p_timeout_prov_disc_during_find() argument
4012 p2p_dbg(p2p, "Provision Discovery Request timeout"); in p2p_timeout_prov_disc_during_find()
4013 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_timeout_prov_disc_during_find()
4014 p2p_continue_find(p2p); in p2p_timeout_prov_disc_during_find()
4018 static void p2p_timeout_prov_disc_req(struct p2p_data *p2p) in p2p_timeout_prov_disc_req() argument
4023 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_timeout_prov_disc_req()
4030 if (!p2p->user_initiated_pd) in p2p_timeout_prov_disc_req()
4033 p2p_dbg(p2p, "User initiated Provision Discovery Request timeout"); in p2p_timeout_prov_disc_req()
4035 if (p2p->pd_retries) { in p2p_timeout_prov_disc_req()
4036 p2p->pd_retries--; in p2p_timeout_prov_disc_req()
4037 p2p_retry_pd(p2p); in p2p_timeout_prov_disc_req()
4042 dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { in p2p_timeout_prov_disc_req()
4043 if (os_memcmp(p2p->pending_pd_devaddr, in p2p_timeout_prov_disc_req()
4051 if (p2p->p2ps_prov) { in p2p_timeout_prov_disc_req()
4052 adv_id = p2p->p2ps_prov->adv_id; in p2p_timeout_prov_disc_req()
4053 adv_mac = p2p->p2ps_prov->adv_mac; in p2p_timeout_prov_disc_req()
4056 if (p2p->cfg->prov_disc_fail) in p2p_timeout_prov_disc_req()
4057 p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, in p2p_timeout_prov_disc_req()
4058 p2p->pending_pd_devaddr, in p2p_timeout_prov_disc_req()
4063 p2p_reset_pending_pd(p2p); in p2p_timeout_prov_disc_req()
4068 static void p2p_timeout_invite(struct p2p_data *p2p) in p2p_timeout_invite() argument
4070 p2p->cfg->send_action_done(p2p->cfg->cb_ctx); in p2p_timeout_invite()
4071 p2p_set_state(p2p, P2P_INVITE_LISTEN); in p2p_timeout_invite()
4072 if (p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO) { in p2p_timeout_invite()
4077 p2p_dbg(p2p, "Inviting in active GO role - wait on operating channel"); in p2p_timeout_invite()
4078 p2p_set_timeout(p2p, 0, 100000); in p2p_timeout_invite()
4081 p2p_listen_in_find(p2p, 0); in p2p_timeout_invite()
4085 static void p2p_timeout_invite_listen(struct p2p_data *p2p) in p2p_timeout_invite_listen() argument
4087 if (p2p->invite_peer && p2p->invite_peer->invitation_reqs < 100) { in p2p_timeout_invite_listen()
4088 p2p_set_state(p2p, P2P_INVITE); in p2p_timeout_invite_listen()
4089 p2p_invite_send(p2p, p2p->invite_peer, in p2p_timeout_invite_listen()
4090 p2p->invite_go_dev_addr, p2p->invite_dev_pw_id); in p2p_timeout_invite_listen()
4092 if (p2p->invite_peer) { in p2p_timeout_invite_listen()
4093 p2p_dbg(p2p, "Invitation Request retry limit reached"); in p2p_timeout_invite_listen()
4094 if (p2p->cfg->invitation_result) in p2p_timeout_invite_listen()
4095 p2p->cfg->invitation_result( in p2p_timeout_invite_listen()
4096 p2p->cfg->cb_ctx, -1, NULL, NULL, in p2p_timeout_invite_listen()
4097 p2p->invite_peer->info.p2p_device_addr, in p2p_timeout_invite_listen()
4100 p2p_set_state(p2p, P2P_IDLE); in p2p_timeout_invite_listen()
4107 struct p2p_data *p2p = eloop_ctx; in p2p_state_timeout() local
4109 p2p_dbg(p2p, "Timeout (state=%s)", p2p_state_txt(p2p->state)); in p2p_state_timeout()
4111 p2p->in_listen = 0; in p2p_state_timeout()
4112 if (p2p->drv_in_listen) { in p2p_state_timeout()
4113 p2p_dbg(p2p, "Driver is still in listen state - stop it"); in p2p_state_timeout()
4114 p2p->cfg->stop_listen(p2p->cfg->cb_ctx); in p2p_state_timeout()
4117 switch (p2p->state) { in p2p_state_timeout()
4120 if (p2p->pending_action_state == P2P_PENDING_PD) in p2p_state_timeout()
4121 p2p_timeout_prov_disc_req(p2p); in p2p_state_timeout()
4125 if (p2p->pending_action_state == P2P_PENDING_PD) in p2p_state_timeout()
4126 p2p_timeout_prov_disc_req(p2p); in p2p_state_timeout()
4127 if (p2p->search_delay && !p2p->in_search_delay) { in p2p_state_timeout()
4128 p2p_dbg(p2p, "Delay search operation by %u ms", in p2p_state_timeout()
4129 p2p->search_delay); in p2p_state_timeout()
4130 p2p->in_search_delay = 1; in p2p_state_timeout()
4131 p2p_set_timeout(p2p, p2p->search_delay / 1000, in p2p_state_timeout()
4132 (p2p->search_delay % 1000) * 1000); in p2p_state_timeout()
4135 p2p->in_search_delay = 0; in p2p_state_timeout()
4136 p2p_search(p2p); in p2p_state_timeout()
4139 p2p_timeout_connect(p2p); in p2p_state_timeout()
4142 p2p_timeout_connect_listen(p2p); in p2p_state_timeout()
4148 if (p2p->pending_action_state == P2P_PENDING_PD) in p2p_state_timeout()
4149 p2p_timeout_prov_disc_req(p2p); in p2p_state_timeout()
4151 if (p2p->ext_listen_only) { in p2p_state_timeout()
4152 p2p_dbg(p2p, "Extended Listen Timing - Listen State completed"); in p2p_state_timeout()
4153 p2p->ext_listen_only = 0; in p2p_state_timeout()
4154 p2p_set_state(p2p, P2P_IDLE); in p2p_state_timeout()
4158 p2p_timeout_wait_peer_connect(p2p); in p2p_state_timeout()
4161 p2p_timeout_wait_peer_idle(p2p); in p2p_state_timeout()
4164 p2p_timeout_sd_during_find(p2p); in p2p_state_timeout()
4169 p2p_timeout_prov_disc_during_find(p2p); in p2p_state_timeout()
4172 p2p_timeout_invite(p2p); in p2p_state_timeout()
4175 p2p_timeout_invite_listen(p2p); in p2p_state_timeout()
4181 int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr) in p2p_reject() argument
4185 dev = p2p_get_device(p2p, peer_addr); in p2p_reject()
4186 p2p_dbg(p2p, "Local request to reject connection attempts by peer " in p2p_reject()
4189 p2p_dbg(p2p, "Peer " MACSTR " unknown", MAC2STR(peer_addr)); in p2p_reject()
4234 const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p, in p2p_get_peer_info() argument
4240 dev = p2p_get_device(p2p, addr); in p2p_get_peer_info()
4242 dev = dl_list_first(&p2p->devices, struct p2p_device, list); in p2p_get_peer_info()
4246 if (&dev->list == &p2p->devices) in p2p_get_peer_info()
4384 int p2p_peer_known(struct p2p_data *p2p, const u8 *addr) in p2p_peer_known() argument
4386 return p2p_get_device(p2p, addr) != NULL; in p2p_peer_known()
4390 void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled) in p2p_set_client_discoverability() argument
4393 p2p_dbg(p2p, "Client discoverability enabled"); in p2p_set_client_discoverability()
4394 p2p->dev_capab |= P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; in p2p_set_client_discoverability()
4396 p2p_dbg(p2p, "Client discoverability disabled"); in p2p_set_client_discoverability()
4397 p2p->dev_capab &= ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; in p2p_set_client_discoverability()
4438 int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr, in p2p_presence_req() argument
4445 p2p_dbg(p2p, "Send Presence Request to GO " MACSTR in p2p_presence_req()
4456 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_presence_req()
4457 if (p2p_send_action(p2p, freq, go_interface_addr, own_interface_addr, in p2p_presence_req()
4460 p2p_dbg(p2p, "Failed to send Action frame"); in p2p_presence_req()
4493 static void p2p_process_presence_req(struct p2p_data *p2p, const u8 *da, in p2p_process_presence_req() argument
4506 p2p_dbg(p2p, "Received P2P Action - P2P Presence Request"); in p2p_process_presence_req()
4508 for (g = 0; g < p2p->num_groups; g++) { in p2p_process_presence_req()
4509 if (os_memcmp(da, p2p_group_get_interface_addr(p2p->groups[g]), in p2p_process_presence_req()
4511 group = p2p->groups[g]; in p2p_process_presence_req()
4516 p2p_dbg(p2p, "Ignore P2P Presence Request for unknown group " in p2p_process_presence_req()
4522 p2p_dbg(p2p, "Failed to parse P2P Presence Request"); in p2p_process_presence_req()
4529 p2p_dbg(p2p, "No NoA attribute in P2P Presence Request"); in p2p_process_presence_req()
4537 if (p2p->cfg->get_noa) in p2p_process_presence_req()
4538 noa_len = p2p->cfg->get_noa(p2p->cfg->cb_ctx, da, noa, in p2p_process_presence_req()
4550 p2p->pending_action_state = P2P_NO_PENDING_ACTION; in p2p_process_presence_req()
4551 if (p2p_send_action(p2p, rx_freq, sa, da, da, in p2p_process_presence_req()
4553 p2p_dbg(p2p, "Failed to send Action frame"); in p2p_process_presence_req()
4559 static void p2p_process_presence_resp(struct p2p_data *p2p, const u8 *da, in p2p_process_presence_resp() argument
4564 p2p_dbg(p2p, "Received P2P Action - P2P Presence Response"); in p2p_process_presence_resp()
4567 p2p_dbg(p2p, "Failed to parse P2P Presence Response"); in p2p_process_presence_resp()
4572 p2p_dbg(p2p, "No Status or NoA attribute in P2P Presence Response"); in p2p_process_presence_resp()
4577 if (p2p->cfg->presence_resp) { in p2p_process_presence_resp()
4578 p2p->cfg->presence_resp(p2p->cfg->cb_ctx, sa, *msg.status, in p2p_process_presence_resp()
4583 p2p_dbg(p2p, "P2P Presence Request was rejected: status %u", in p2p_process_presence_resp()
4589 p2p_dbg(p2p, "P2P Presence Request was accepted"); in p2p_process_presence_resp()
4599 struct p2p_data *p2p = eloop_ctx; in p2p_ext_listen_timeout() local
4601 if (p2p->ext_listen_interval) { in p2p_ext_listen_timeout()
4603 eloop_register_timeout(p2p->ext_listen_interval_sec, in p2p_ext_listen_timeout()
4604 p2p->ext_listen_interval_usec, in p2p_ext_listen_timeout()
4605 p2p_ext_listen_timeout, p2p, NULL); in p2p_ext_listen_timeout()
4608 if ((p2p->cfg->is_p2p_in_progress && in p2p_ext_listen_timeout()
4609 p2p->cfg->is_p2p_in_progress(p2p->cfg->cb_ctx)) || in p2p_ext_listen_timeout()
4610 (p2p->pending_action_state == P2P_PENDING_PD && in p2p_ext_listen_timeout()
4611 p2p->pd_retries > 0)) { in p2p_ext_listen_timeout()
4612 p2p_dbg(p2p, "Operation in progress - skip Extended Listen timeout (%s)", in p2p_ext_listen_timeout()
4613 p2p_state_txt(p2p->state)); in p2p_ext_listen_timeout()
4617 if (p2p->state == P2P_LISTEN_ONLY && p2p->ext_listen_only) { in p2p_ext_listen_timeout()
4624 p2p_dbg(p2p, "Previous Extended Listen operation had not been completed - try again"); in p2p_ext_listen_timeout()
4625 p2p->ext_listen_only = 0; in p2p_ext_listen_timeout()
4626 p2p_set_state(p2p, P2P_IDLE); in p2p_ext_listen_timeout()
4629 if (p2p->state != P2P_IDLE) { in p2p_ext_listen_timeout()
4630 p2p_dbg(p2p, "Skip Extended Listen timeout in active state (%s)", p2p_state_txt(p2p->state)); in p2p_ext_listen_timeout()
4634 p2p_dbg(p2p, "Extended Listen timeout"); in p2p_ext_listen_timeout()
4635 p2p->ext_listen_only = 1; in p2p_ext_listen_timeout()
4636 if (p2p_listen(p2p, p2p->ext_listen_period) < 0) { in p2p_ext_listen_timeout()
4637 p2p_dbg(p2p, "Failed to start Listen state for Extended Listen Timing"); in p2p_ext_listen_timeout()
4638 p2p->ext_listen_only = 0; in p2p_ext_listen_timeout()
4643 int p2p_ext_listen(struct p2p_data *p2p, unsigned int period, in p2p_ext_listen() argument
4648 p2p_dbg(p2p, "Invalid Extended Listen Timing request: period=%u interval=%u", in p2p_ext_listen()
4653 eloop_cancel_timeout(p2p_ext_listen_timeout, p2p, NULL); in p2p_ext_listen()
4656 p2p_dbg(p2p, "Disabling Extended Listen Timing"); in p2p_ext_listen()
4657 p2p->ext_listen_period = 0; in p2p_ext_listen()
4658 p2p->ext_listen_interval = 0; in p2p_ext_listen()
4662 p2p_dbg(p2p, "Enabling Extended Listen Timing: period %u msec, interval %u msec", in p2p_ext_listen()
4664 p2p->ext_listen_period = period; in p2p_ext_listen()
4665 p2p->ext_listen_interval = interval; in p2p_ext_listen()
4666 p2p->ext_listen_interval_sec = interval / 1000; in p2p_ext_listen()
4667 p2p->ext_listen_interval_usec = (interval % 1000) * 1000; in p2p_ext_listen()
4669 eloop_register_timeout(p2p->ext_listen_interval_sec, in p2p_ext_listen()
4670 p2p->ext_listen_interval_usec, in p2p_ext_listen()
4671 p2p_ext_listen_timeout, p2p, NULL); in p2p_ext_listen()
4677 void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, in p2p_deauth_notif() argument
4693 p2p_dbg(p2p, "Deauthentication notification BSSID " MACSTR in p2p_deauth_notif()
4701 void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, in p2p_disassoc_notif() argument
4717 p2p_dbg(p2p, "Disassociation notification BSSID " MACSTR in p2p_disassoc_notif()
4725 void p2p_set_managed_oper(struct p2p_data *p2p, int enabled) in p2p_set_managed_oper() argument
4728 p2p_dbg(p2p, "Managed P2P Device operations enabled"); in p2p_set_managed_oper()
4729 p2p->dev_capab |= P2P_DEV_CAPAB_INFRA_MANAGED; in p2p_set_managed_oper()
4731 p2p_dbg(p2p, "Managed P2P Device operations disabled"); in p2p_set_managed_oper()
4732 p2p->dev_capab &= ~P2P_DEV_CAPAB_INFRA_MANAGED; in p2p_set_managed_oper()
4737 int p2p_config_get_random_social(struct p2p_config *p2p, u8 *op_class, in p2p_config_get_random_social() argument
4740 return p2p_channel_random_social(&p2p->channels, op_class, op_channel); in p2p_config_get_random_social()
4744 int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel, in p2p_set_listen_channel() argument
4754 if (p2p->cfg->channel_forced && forced == 0) { in p2p_set_listen_channel()
4755 p2p_dbg(p2p, in p2p_set_listen_channel()
4760 p2p_dbg(p2p, "Set Listen channel: reg_class %u channel %u", in p2p_set_listen_channel()
4763 if (p2p->state == P2P_IDLE) { in p2p_set_listen_channel()
4764 p2p->cfg->reg_class = reg_class; in p2p_set_listen_channel()
4765 p2p->cfg->channel = channel; in p2p_set_listen_channel()
4766 p2p->cfg->channel_forced = forced; in p2p_set_listen_channel()
4768 p2p_dbg(p2p, "Defer setting listen channel"); in p2p_set_listen_channel()
4769 p2p->pending_reg_class = reg_class; in p2p_set_listen_channel()
4770 p2p->pending_channel = channel; in p2p_set_listen_channel()
4771 p2p->pending_channel_forced = forced; in p2p_set_listen_channel()
4778 u8 p2p_get_listen_channel(struct p2p_data *p2p) in p2p_get_listen_channel() argument
4780 return p2p->cfg->channel; in p2p_get_listen_channel()
4784 int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len) in p2p_set_ssid_postfix() argument
4786 p2p_dbg(p2p, "New SSID postfix: %s", wpa_ssid_txt(postfix, len)); in p2p_set_ssid_postfix()
4788 p2p->cfg->ssid_postfix_len = 0; in p2p_set_ssid_postfix()
4791 if (len > sizeof(p2p->cfg->ssid_postfix)) in p2p_set_ssid_postfix()
4793 os_memcpy(p2p->cfg->ssid_postfix, postfix, len); in p2p_set_ssid_postfix()
4794 p2p->cfg->ssid_postfix_len = len; in p2p_set_ssid_postfix()
4799 int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, in p2p_set_oper_channel() argument
4805 p2p_dbg(p2p, "Set Operating channel: reg_class %u channel %u", in p2p_set_oper_channel()
4807 p2p->cfg->op_reg_class = op_reg_class; in p2p_set_oper_channel()
4808 p2p->cfg->op_channel = op_channel; in p2p_set_oper_channel()
4809 p2p->cfg->cfg_op_channel = cfg_op_channel; in p2p_set_oper_channel()
4814 int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan, in p2p_set_pref_chan() argument
4828 os_free(p2p->cfg->pref_chan); in p2p_set_pref_chan()
4829 p2p->cfg->pref_chan = n; in p2p_set_pref_chan()
4830 p2p->cfg->num_pref_chan = num_pref_chan; in p2p_set_pref_chan()
4836 int p2p_set_no_go_freq(struct p2p_data *p2p, in p2p_set_no_go_freq() argument
4842 os_free(p2p->no_go_freq.range); in p2p_set_no_go_freq()
4843 p2p->no_go_freq.range = NULL; in p2p_set_no_go_freq()
4844 p2p->no_go_freq.num = 0; in p2p_set_no_go_freq()
4852 os_free(p2p->no_go_freq.range); in p2p_set_no_go_freq()
4853 p2p->no_go_freq.range = tmp; in p2p_set_no_go_freq()
4854 p2p->no_go_freq.num = list->num; in p2p_set_no_go_freq()
4855 p2p_dbg(p2p, "Updated no GO chan list"); in p2p_set_no_go_freq()
4861 int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, in p2p_get_interface_addr() argument
4864 struct p2p_device *dev = p2p_get_device(p2p, dev_addr); in p2p_get_interface_addr()
4872 int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr, in p2p_get_dev_addr() argument
4875 struct p2p_device *dev = p2p_get_device_interface(p2p, iface_addr); in p2p_get_dev_addr()
4883 void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr) in p2p_set_peer_filter() argument
4885 os_memcpy(p2p->peer_filter, addr, ETH_ALEN); in p2p_set_peer_filter()
4886 if (is_zero_ether_addr(p2p->peer_filter)) in p2p_set_peer_filter()
4887 p2p_dbg(p2p, "Disable peer filter"); in p2p_set_peer_filter()
4889 p2p_dbg(p2p, "Enable peer filter for " MACSTR, in p2p_set_peer_filter()
4890 MAC2STR(p2p->peer_filter)); in p2p_set_peer_filter()
4894 void p2p_set_cross_connect(struct p2p_data *p2p, int enabled) in p2p_set_cross_connect() argument
4896 p2p_dbg(p2p, "Cross connection %s", enabled ? "enabled" : "disabled"); in p2p_set_cross_connect()
4897 if (p2p->cross_connect == enabled) in p2p_set_cross_connect()
4899 p2p->cross_connect = enabled; in p2p_set_cross_connect()
4904 int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr) in p2p_get_oper_freq() argument
4906 struct p2p_device *dev = p2p_get_device_interface(p2p, iface_addr); in p2p_get_oper_freq()
4915 void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled) in p2p_set_intra_bss_dist() argument
4917 p2p_dbg(p2p, "Intra BSS distribution %s", in p2p_set_intra_bss_dist()
4919 p2p->cfg->p2p_intra_bss = enabled; in p2p_set_intra_bss_dist()
4923 void p2p_update_channel_list(struct p2p_data *p2p, in p2p_update_channel_list() argument
4927 p2p_dbg(p2p, "Update channel list"); in p2p_update_channel_list()
4928 os_memcpy(&p2p->cfg->channels, chan, sizeof(struct p2p_channels)); in p2p_update_channel_list()
4929 p2p_channels_dump(p2p, "channels", &p2p->cfg->channels); in p2p_update_channel_list()
4930 os_memcpy(&p2p->cfg->cli_channels, cli_chan, in p2p_update_channel_list()
4932 p2p_channels_dump(p2p, "cli_channels", &p2p->cfg->cli_channels); in p2p_update_channel_list()
4936 int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst, in p2p_send_action() argument
4940 if (p2p->p2p_scan_running) { in p2p_send_action()
4941 p2p_dbg(p2p, "Delay Action frame TX until p2p_scan completes"); in p2p_send_action()
4942 if (p2p->after_scan_tx) { in p2p_send_action()
4943 p2p_dbg(p2p, "Dropped previous pending Action frame TX"); in p2p_send_action()
4944 os_free(p2p->after_scan_tx); in p2p_send_action()
4946 p2p->after_scan_tx = os_malloc(sizeof(*p2p->after_scan_tx) + in p2p_send_action()
4948 if (p2p->after_scan_tx == NULL) in p2p_send_action()
4950 p2p->after_scan_tx->freq = freq; in p2p_send_action()
4951 os_memcpy(p2p->after_scan_tx->dst, dst, ETH_ALEN); in p2p_send_action()
4952 os_memcpy(p2p->after_scan_tx->src, src, ETH_ALEN); in p2p_send_action()
4953 os_memcpy(p2p->after_scan_tx->bssid, bssid, ETH_ALEN); in p2p_send_action()
4954 p2p->after_scan_tx->len = len; in p2p_send_action()
4955 p2p->after_scan_tx->wait_time = wait_time; in p2p_send_action()
4956 os_memcpy(p2p->after_scan_tx + 1, buf, len); in p2p_send_action()
4960 return p2p->cfg->send_action(p2p->cfg->cb_ctx, freq, dst, src, bssid, in p2p_send_action()
4965 void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5, in p2p_set_best_channels() argument
4968 p2p_dbg(p2p, "Best channel: 2.4 GHz: %d, 5 GHz: %d, overall: %d", in p2p_set_best_channels()
4970 p2p->best_freq_24 = freq_24; in p2p_set_best_channels()
4971 p2p->best_freq_5 = freq_5; in p2p_set_best_channels()
4972 p2p->best_freq_overall = freq_overall; in p2p_set_best_channels()
4976 void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq) in p2p_set_own_freq_preference() argument
4978 p2p_dbg(p2p, "Own frequency preference: %d MHz", freq); in p2p_set_own_freq_preference()
4979 p2p->own_freq_preference = freq; in p2p_set_own_freq_preference()
4983 const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p) in p2p_get_go_neg_peer() argument
4985 if (p2p == NULL || p2p->go_neg_peer == NULL) in p2p_get_go_neg_peer()
4987 return p2p->go_neg_peer->info.p2p_device_addr; in p2p_get_go_neg_peer()
4992 p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next) in p2p_get_peer_found() argument
4997 dev = p2p_get_device(p2p, addr); in p2p_get_peer_found()
5011 if (!dev || &dev->list == &p2p->devices) in p2p_get_peer_found()
5016 dev = dl_list_first(&p2p->devices, struct p2p_device, list); in p2p_get_peer_found()
5023 if (!dev || &dev->list == &p2p->devices) in p2p_get_peer_found()
5032 int p2p_in_progress(struct p2p_data *p2p) in p2p_in_progress() argument
5034 if (p2p == NULL) in p2p_in_progress()
5036 if (p2p->state == P2P_SEARCH) in p2p_in_progress()
5038 return p2p->state != P2P_IDLE && p2p->state != P2P_PROVISIONING; in p2p_in_progress()
5042 void p2p_set_config_timeout(struct p2p_data *p2p, u8 go_timeout, in p2p_set_config_timeout() argument
5045 if (p2p) { in p2p_set_config_timeout()
5046 p2p->go_timeout = go_timeout; in p2p_set_config_timeout()
5047 p2p->client_timeout = client_timeout; in p2p_set_config_timeout()
5054 static void p2p_update_wfd_ie_groups(struct p2p_data *p2p) in p2p_update_wfd_ie_groups() argument
5059 for (g = 0; g < p2p->num_groups; g++) { in p2p_update_wfd_ie_groups()
5060 group = p2p->groups[g]; in p2p_update_wfd_ie_groups()
5066 int p2p_set_wfd_ie_beacon(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_beacon() argument
5068 wpabuf_free(p2p->wfd_ie_beacon); in p2p_set_wfd_ie_beacon()
5069 p2p->wfd_ie_beacon = ie; in p2p_set_wfd_ie_beacon()
5070 p2p_update_wfd_ie_groups(p2p); in p2p_set_wfd_ie_beacon()
5075 int p2p_set_wfd_ie_probe_req(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_probe_req() argument
5077 wpabuf_free(p2p->wfd_ie_probe_req); in p2p_set_wfd_ie_probe_req()
5078 p2p->wfd_ie_probe_req = ie; in p2p_set_wfd_ie_probe_req()
5083 int p2p_set_wfd_ie_probe_resp(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_probe_resp() argument
5085 wpabuf_free(p2p->wfd_ie_probe_resp); in p2p_set_wfd_ie_probe_resp()
5086 p2p->wfd_ie_probe_resp = ie; in p2p_set_wfd_ie_probe_resp()
5087 p2p_update_wfd_ie_groups(p2p); in p2p_set_wfd_ie_probe_resp()
5092 int p2p_set_wfd_ie_assoc_req(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_assoc_req() argument
5094 wpabuf_free(p2p->wfd_ie_assoc_req); in p2p_set_wfd_ie_assoc_req()
5095 p2p->wfd_ie_assoc_req = ie; in p2p_set_wfd_ie_assoc_req()
5100 int p2p_set_wfd_ie_invitation(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_invitation() argument
5102 wpabuf_free(p2p->wfd_ie_invitation); in p2p_set_wfd_ie_invitation()
5103 p2p->wfd_ie_invitation = ie; in p2p_set_wfd_ie_invitation()
5108 int p2p_set_wfd_ie_prov_disc_req(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_prov_disc_req() argument
5110 wpabuf_free(p2p->wfd_ie_prov_disc_req); in p2p_set_wfd_ie_prov_disc_req()
5111 p2p->wfd_ie_prov_disc_req = ie; in p2p_set_wfd_ie_prov_disc_req()
5116 int p2p_set_wfd_ie_prov_disc_resp(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_prov_disc_resp() argument
5118 wpabuf_free(p2p->wfd_ie_prov_disc_resp); in p2p_set_wfd_ie_prov_disc_resp()
5119 p2p->wfd_ie_prov_disc_resp = ie; in p2p_set_wfd_ie_prov_disc_resp()
5124 int p2p_set_wfd_ie_go_neg(struct p2p_data *p2p, struct wpabuf *ie) in p2p_set_wfd_ie_go_neg() argument
5126 wpabuf_free(p2p->wfd_ie_go_neg); in p2p_set_wfd_ie_go_neg()
5127 p2p->wfd_ie_go_neg = ie; in p2p_set_wfd_ie_go_neg()
5132 int p2p_set_wfd_dev_info(struct p2p_data *p2p, const struct wpabuf *elem) in p2p_set_wfd_dev_info() argument
5134 wpabuf_free(p2p->wfd_dev_info); in p2p_set_wfd_dev_info()
5136 p2p->wfd_dev_info = wpabuf_dup(elem); in p2p_set_wfd_dev_info()
5137 if (p2p->wfd_dev_info == NULL) in p2p_set_wfd_dev_info()
5140 p2p->wfd_dev_info = NULL; in p2p_set_wfd_dev_info()
5146 int p2p_set_wfd_assoc_bssid(struct p2p_data *p2p, const struct wpabuf *elem) in p2p_set_wfd_assoc_bssid() argument
5148 wpabuf_free(p2p->wfd_assoc_bssid); in p2p_set_wfd_assoc_bssid()
5150 p2p->wfd_assoc_bssid = wpabuf_dup(elem); in p2p_set_wfd_assoc_bssid()
5151 if (p2p->wfd_assoc_bssid == NULL) in p2p_set_wfd_assoc_bssid()
5154 p2p->wfd_assoc_bssid = NULL; in p2p_set_wfd_assoc_bssid()
5160 int p2p_set_wfd_coupled_sink_info(struct p2p_data *p2p, in p2p_set_wfd_coupled_sink_info() argument
5163 wpabuf_free(p2p->wfd_coupled_sink_info); in p2p_set_wfd_coupled_sink_info()
5165 p2p->wfd_coupled_sink_info = wpabuf_dup(elem); in p2p_set_wfd_coupled_sink_info()
5166 if (p2p->wfd_coupled_sink_info == NULL) in p2p_set_wfd_coupled_sink_info()
5169 p2p->wfd_coupled_sink_info = NULL; in p2p_set_wfd_coupled_sink_info()
5177 int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int, in p2p_set_disc_int() argument
5183 p2p->min_disc_int = min_disc_int; in p2p_set_disc_int()
5184 p2p->max_disc_int = max_disc_int; in p2p_set_disc_int()
5185 p2p->max_disc_tu = max_disc_tu; in p2p_set_disc_int()
5186 p2p_dbg(p2p, "Set discoverable interval: min=%d max=%d max_tu=%d", in p2p_set_disc_int()
5193 void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...) in p2p_dbg() argument
5198 if (!p2p->cfg->debug_print) in p2p_dbg()
5205 p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_DEBUG, buf); in p2p_dbg()
5209 void p2p_info(struct p2p_data *p2p, const char *fmt, ...) in p2p_info() argument
5214 if (!p2p->cfg->debug_print) in p2p_info()
5221 p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_INFO, buf); in p2p_info()
5225 void p2p_err(struct p2p_data *p2p, const char *fmt, ...) in p2p_err() argument
5230 if (!p2p->cfg->debug_print) in p2p_err()
5237 p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_ERROR, buf); in p2p_err()
5241 void p2p_loop_on_known_peers(struct p2p_data *p2p, in p2p_loop_on_known_peers() argument
5248 dl_list_for_each_safe(dev, n, &p2p->devices, struct p2p_device, list) { in p2p_loop_on_known_peers()
5256 static struct wpabuf * p2p_build_nfc_handover(struct p2p_data *p2p, in p2p_build_nfc_handover() argument
5269 op_class = p2p->cfg->reg_class; in p2p_build_nfc_handover()
5270 channel = p2p->cfg->channel; in p2p_build_nfc_handover()
5272 p2p_buf_add_capability(buf, p2p->dev_capab & in p2p_build_nfc_handover()
5274 p2p_buf_add_device_info(buf, p2p, NULL); in p2p_build_nfc_handover()
5276 if (p2p->num_groups > 0) { in p2p_build_nfc_handover()
5277 int freq = p2p_group_get_freq(p2p->groups[0]); in p2p_build_nfc_handover()
5280 p2p_dbg(p2p, in p2p_build_nfc_handover()
5289 p2p_dbg(p2p, in p2p_build_nfc_handover()
5297 p2p_buf_add_oob_go_neg_channel(buf, p2p->cfg->country, op_class, in p2p_build_nfc_handover()
5300 if (p2p->num_groups > 0) { in p2p_build_nfc_handover()
5302 p2p_buf_add_group_info(p2p->groups[0], buf, 5); in p2p_build_nfc_handover()
5303 p2p_group_buf_add_id(p2p->groups[0], buf); in p2p_build_nfc_handover()
5318 struct wpabuf * p2p_build_nfc_handover_req(struct p2p_data *p2p, in p2p_build_nfc_handover_req() argument
5323 return p2p_build_nfc_handover(p2p, client_freq, go_dev_addr, ssid, in p2p_build_nfc_handover_req()
5328 struct wpabuf * p2p_build_nfc_handover_sel(struct p2p_data *p2p, in p2p_build_nfc_handover_sel() argument
5333 return p2p_build_nfc_handover(p2p, client_freq, go_dev_addr, ssid, in p2p_build_nfc_handover_sel()
5338 int p2p_process_nfc_connection_handover(struct p2p_data *p2p, in p2p_process_nfc_connection_handover() argument
5351 p2p_dbg(p2p, "Failed to parse WSC/P2P attributes from NFC"); in p2p_process_nfc_connection_handover()
5361 p2p_dbg(p2p, "Ignore scan data without P2P Device Info or P2P Device Id"); in p2p_process_nfc_connection_handover()
5372 dev = p2p_create_device(p2p, p2p_dev_addr); in p2p_process_nfc_connection_handover()
5382 p2p_copy_wps_info(p2p, dev, 0, &msg); in p2p_process_nfc_connection_handover()
5385 p2p_dbg(p2p, "OOB GO Negotiation Channel attribute not included"); in p2p_process_nfc_connection_handover()
5397 p2p_dbg(p2p, "Unknown peer OOB GO Neg channel"); in p2p_process_nfc_connection_handover()
5404 p2p_dbg(p2p, "Peer OOB GO operating channel: %u MHz", freq); in p2p_process_nfc_connection_handover()
5407 p2p_dbg(p2p, "Peer (client) OOB GO operating channel: %u MHz", in p2p_process_nfc_connection_handover()
5411 p2p_dbg(p2p, "Peer OOB GO Neg channel: %u MHz", freq); in p2p_process_nfc_connection_handover()
5415 freq = p2p_channel_to_freq(p2p->cfg->reg_class, in p2p_process_nfc_connection_handover()
5416 p2p->cfg->channel); in p2p_process_nfc_connection_handover()
5418 p2p_dbg(p2p, "Own listen channel not known"); in p2p_process_nfc_connection_handover()
5422 p2p_dbg(p2p, "Use own Listen channel as OOB GO Neg channel: %u MHz", freq); in p2p_process_nfc_connection_handover()
5434 p2p_dbg(p2p, "Do not report rejected device"); in p2p_process_nfc_connection_handover()
5440 p2p->cfg->dev_found(p2p->cfg->cb_ctx, p2p_dev_addr, &dev->info, in p2p_process_nfc_connection_handover()
5446 if (role == P2P_GO_IN_A_GROUP && p2p->num_groups > 0) in p2p_process_nfc_connection_handover()
5453 } else if (p2p->num_groups > 0) in p2p_process_nfc_connection_handover()
5464 void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id, in p2p_set_authorized_oob_dev_pw_id() argument
5469 p2p->authorized_oob_dev_pw_id = dev_pw_id; in p2p_set_authorized_oob_dev_pw_id()
5471 p2p_dbg(p2p, "NFC OOB Password unauthorized for static handover"); in p2p_set_authorized_oob_dev_pw_id()
5475 p2p_dbg(p2p, "NFC OOB Password (id=%u) authorized for static handover", in p2p_set_authorized_oob_dev_pw_id()
5478 p2p->go_intent = go_intent; in p2p_set_authorized_oob_dev_pw_id()
5479 os_memcpy(p2p->intended_addr, own_interface_addr, ETH_ALEN); in p2p_set_authorized_oob_dev_pw_id()
5485 int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len) in p2p_set_passphrase_len() argument
5489 p2p->cfg->passphrase_len = len; in p2p_set_passphrase_len()
5494 void p2p_set_vendor_elems(struct p2p_data *p2p, struct wpabuf **vendor_elem) in p2p_set_vendor_elems() argument
5496 p2p->vendor_elem = vendor_elem; in p2p_set_vendor_elems()
5502 struct p2p_data *p2p = eloop_ctx; in p2p_go_neg_wait_timeout() local
5504 p2p_dbg(p2p, in p2p_go_neg_wait_timeout()
5506 p2p_go_neg_failed(p2p, -1); in p2p_go_neg_wait_timeout()
5510 void p2p_set_own_pref_freq_list(struct p2p_data *p2p, in p2p_set_own_pref_freq_list() argument
5518 p2p->num_pref_freq = size; in p2p_set_own_pref_freq_list()
5520 p2p->pref_freq_list[i] = pref_freq_list[i]; in p2p_set_own_pref_freq_list()
5521 p2p_dbg(p2p, "Own preferred frequency list[%u]=%u MHz", in p2p_set_own_pref_freq_list()
5522 i, p2p->pref_freq_list[i]); in p2p_set_own_pref_freq_list()
5527 void p2p_set_override_pref_op_chan(struct p2p_data *p2p, u8 op_class, in p2p_set_override_pref_op_chan() argument
5530 p2p->override_pref_op_class = op_class; in p2p_set_override_pref_op_chan()
5531 p2p->override_pref_channel = chan; in p2p_set_override_pref_op_chan()
5535 struct wpabuf * p2p_build_probe_resp_template(struct p2p_data *p2p, in p2p_build_probe_resp_template() argument
5542 ies = p2p_build_probe_resp_ies(p2p, NULL, 0); in p2p_build_probe_resp_template()
5555 ret = p2p_build_probe_resp_buf(p2p, buf, ies, addr, freq); in p2p_build_probe_resp_template()