p2p_invitation.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * Wi-Fi Direct - P2P Invitation procedure
  3. * Copyright (c) 2010, Atheros Communications
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "p2p_i.h"
  12. #include "p2p.h"
  13. static struct wpabuf * p2p_build_invitation_req(struct p2p_data *p2p,
  14. struct p2p_device *peer,
  15. const u8 *go_dev_addr)
  16. {
  17. struct wpabuf *buf;
  18. u8 *len;
  19. const u8 *dev_addr;
  20. size_t extra = 0;
  21. #ifdef CONFIG_WIFI_DISPLAY
  22. struct wpabuf *wfd_ie = p2p->wfd_ie_invitation;
  23. if (wfd_ie && p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO) {
  24. size_t i;
  25. for (i = 0; i < p2p->num_groups; i++) {
  26. struct p2p_group *g = p2p->groups[i];
  27. struct wpabuf *ie;
  28. if (os_memcmp(p2p_group_get_interface_addr(g),
  29. p2p->inv_bssid, ETH_ALEN) != 0)
  30. continue;
  31. ie = p2p_group_get_wfd_ie(g);
  32. if (ie) {
  33. wfd_ie = ie;
  34. break;
  35. }
  36. }
  37. }
  38. if (wfd_ie)
  39. extra = wpabuf_len(wfd_ie);
  40. #endif /* CONFIG_WIFI_DISPLAY */
  41. buf = wpabuf_alloc(1000 + extra);
  42. if (buf == NULL)
  43. return NULL;
  44. peer->dialog_token++;
  45. if (peer->dialog_token == 0)
  46. peer->dialog_token = 1;
  47. p2p_buf_add_public_action_hdr(buf, P2P_INVITATION_REQ,
  48. peer->dialog_token);
  49. len = p2p_buf_add_ie_hdr(buf);
  50. if (p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO || !p2p->inv_persistent)
  51. p2p_buf_add_config_timeout(buf, 0, 0);
  52. else
  53. p2p_buf_add_config_timeout(buf, p2p->go_timeout,
  54. p2p->client_timeout);
  55. p2p_buf_add_invitation_flags(buf, p2p->inv_persistent ?
  56. P2P_INVITATION_FLAGS_TYPE : 0);
  57. if (p2p->inv_role != P2P_INVITE_ROLE_CLIENT ||
  58. !(peer->flags & P2P_DEV_NO_PREF_CHAN))
  59. p2p_buf_add_operating_channel(buf, p2p->cfg->country,
  60. p2p->op_reg_class,
  61. p2p->op_channel);
  62. if (p2p->inv_bssid_set)
  63. p2p_buf_add_group_bssid(buf, p2p->inv_bssid);
  64. p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels);
  65. if (go_dev_addr)
  66. dev_addr = go_dev_addr;
  67. else if (p2p->inv_role == P2P_INVITE_ROLE_CLIENT)
  68. dev_addr = peer->info.p2p_device_addr;
  69. else
  70. dev_addr = p2p->cfg->dev_addr;
  71. p2p_buf_add_group_id(buf, dev_addr, p2p->inv_ssid, p2p->inv_ssid_len);
  72. p2p_buf_add_device_info(buf, p2p, peer);
  73. p2p_buf_update_ie_hdr(buf, len);
  74. #ifdef CONFIG_WIFI_DISPLAY
  75. if (wfd_ie)
  76. wpabuf_put_buf(buf, wfd_ie);
  77. #endif /* CONFIG_WIFI_DISPLAY */
  78. return buf;
  79. }
  80. static struct wpabuf * p2p_build_invitation_resp(struct p2p_data *p2p,
  81. struct p2p_device *peer,
  82. u8 dialog_token, u8 status,
  83. const u8 *group_bssid,
  84. u8 reg_class, u8 channel,
  85. struct p2p_channels *channels)
  86. {
  87. struct wpabuf *buf;
  88. u8 *len;
  89. size_t extra = 0;
  90. #ifdef CONFIG_WIFI_DISPLAY
  91. struct wpabuf *wfd_ie = p2p->wfd_ie_invitation;
  92. if (wfd_ie && group_bssid) {
  93. size_t i;
  94. for (i = 0; i < p2p->num_groups; i++) {
  95. struct p2p_group *g = p2p->groups[i];
  96. struct wpabuf *ie;
  97. if (os_memcmp(p2p_group_get_interface_addr(g),
  98. group_bssid, ETH_ALEN) != 0)
  99. continue;
  100. ie = p2p_group_get_wfd_ie(g);
  101. if (ie) {
  102. wfd_ie = ie;
  103. break;
  104. }
  105. }
  106. }
  107. if (wfd_ie)
  108. extra = wpabuf_len(wfd_ie);
  109. #endif /* CONFIG_WIFI_DISPLAY */
  110. buf = wpabuf_alloc(1000 + extra);
  111. if (buf == NULL)
  112. return NULL;
  113. p2p_buf_add_public_action_hdr(buf, P2P_INVITATION_RESP,
  114. dialog_token);
  115. len = p2p_buf_add_ie_hdr(buf);
  116. p2p_buf_add_status(buf, status);
  117. p2p_buf_add_config_timeout(buf, 0, 0); /* FIX */
  118. if (reg_class && channel)
  119. p2p_buf_add_operating_channel(buf, p2p->cfg->country,
  120. reg_class, channel);
  121. if (group_bssid)
  122. p2p_buf_add_group_bssid(buf, group_bssid);
  123. if (channels)
  124. p2p_buf_add_channel_list(buf, p2p->cfg->country, channels);
  125. p2p_buf_update_ie_hdr(buf, len);
  126. #ifdef CONFIG_WIFI_DISPLAY
  127. if (wfd_ie)
  128. wpabuf_put_buf(buf, wfd_ie);
  129. #endif /* CONFIG_WIFI_DISPLAY */
  130. return buf;
  131. }
  132. void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
  133. const u8 *data, size_t len, int rx_freq)
  134. {
  135. struct p2p_device *dev;
  136. struct p2p_message msg;
  137. struct wpabuf *resp = NULL;
  138. u8 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
  139. int freq;
  140. int go = 0;
  141. u8 group_bssid[ETH_ALEN], *bssid;
  142. int op_freq = 0;
  143. u8 reg_class = 0, channel = 0;
  144. struct p2p_channels intersection, *channels = NULL;
  145. int persistent;
  146. os_memset(group_bssid, 0, sizeof(group_bssid));
  147. p2p_dbg(p2p, "Received Invitation Request from " MACSTR " (freq=%d)",
  148. MAC2STR(sa), rx_freq);
  149. if (p2p_parse(data, len, &msg))
  150. return;
  151. dev = p2p_get_device(p2p, sa);
  152. if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
  153. p2p_dbg(p2p, "Invitation Request from unknown peer " MACSTR,
  154. MAC2STR(sa));
  155. if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1,
  156. 0)) {
  157. p2p_dbg(p2p, "Invitation Request add device failed "
  158. MACSTR, MAC2STR(sa));
  159. status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
  160. goto fail;
  161. }
  162. dev = p2p_get_device(p2p, sa);
  163. if (dev == NULL) {
  164. p2p_dbg(p2p, "Reject Invitation Request from unknown peer "
  165. MACSTR, MAC2STR(sa));
  166. status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
  167. goto fail;
  168. }
  169. }
  170. if (!msg.group_id || !msg.channel_list) {
  171. p2p_dbg(p2p, "Mandatory attribute missing in Invitation Request from "
  172. MACSTR, MAC2STR(sa));
  173. status = P2P_SC_FAIL_INVALID_PARAMS;
  174. goto fail;
  175. }
  176. if (msg.invitation_flags)
  177. persistent = *msg.invitation_flags & P2P_INVITATION_FLAGS_TYPE;
  178. else {
  179. /* Invitation Flags is a mandatory attribute starting from P2P
  180. * spec 1.06. As a backwards compatibility mechanism, assume
  181. * the request was for a persistent group if the attribute is
  182. * missing.
  183. */
  184. p2p_dbg(p2p, "Mandatory Invitation Flags attribute missing from Invitation Request");
  185. persistent = 1;
  186. }
  187. if (p2p_peer_channels_check(p2p, &p2p->cfg->channels, dev,
  188. msg.channel_list, msg.channel_list_len) <
  189. 0) {
  190. p2p_dbg(p2p, "No common channels found");
  191. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  192. goto fail;
  193. }
  194. p2p_channels_intersect(&p2p->cfg->channels, &dev->channels,
  195. &intersection);
  196. if (p2p->cfg->invitation_process) {
  197. status = p2p->cfg->invitation_process(
  198. p2p->cfg->cb_ctx, sa, msg.group_bssid, msg.group_id,
  199. msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN,
  200. &go, group_bssid, &op_freq, persistent, &intersection);
  201. }
  202. if (op_freq) {
  203. p2p_dbg(p2p, "Invitation processing forced frequency %d MHz",
  204. op_freq);
  205. if (p2p_freq_to_channel(op_freq, &reg_class, &channel) < 0) {
  206. p2p_dbg(p2p, "Unknown forced freq %d MHz from invitation_process()",
  207. op_freq);
  208. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  209. goto fail;
  210. }
  211. if (!p2p_channels_includes(&intersection, reg_class, channel))
  212. {
  213. p2p_dbg(p2p, "forced freq %d MHz not in the supported channels interaction",
  214. op_freq);
  215. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  216. goto fail;
  217. }
  218. if (status == P2P_SC_SUCCESS)
  219. channels = &intersection;
  220. } else {
  221. p2p_dbg(p2p, "No forced channel from invitation processing - figure out best one to use");
  222. /* Default to own configuration as a starting point */
  223. p2p->op_reg_class = p2p->cfg->op_reg_class;
  224. p2p->op_channel = p2p->cfg->op_channel;
  225. p2p_dbg(p2p, "Own default op_class %d channel %d",
  226. p2p->op_reg_class, p2p->op_channel);
  227. /* Use peer preference if specified and compatible */
  228. if (msg.operating_channel) {
  229. int req_freq;
  230. req_freq = p2p_channel_to_freq(
  231. msg.operating_channel[3],
  232. msg.operating_channel[4]);
  233. p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
  234. req_freq);
  235. if (req_freq > 0 &&
  236. p2p_channels_includes(&intersection,
  237. msg.operating_channel[3],
  238. msg.operating_channel[4])) {
  239. p2p->op_reg_class = msg.operating_channel[3];
  240. p2p->op_channel = msg.operating_channel[4];
  241. p2p_dbg(p2p, "Use peer preference op_class %d channel %d",
  242. p2p->op_reg_class, p2p->op_channel);
  243. } else {
  244. p2p_dbg(p2p, "Cannot use peer channel preference");
  245. }
  246. }
  247. if (!p2p_channels_includes(&intersection, p2p->op_reg_class,
  248. p2p->op_channel)) {
  249. p2p_dbg(p2p, "Initially selected channel (op_class %d channel %d) not in channel intersection - try to reselect",
  250. p2p->op_reg_class, p2p->op_channel);
  251. p2p_reselect_channel(p2p, &intersection);
  252. p2p_dbg(p2p, "Re-selection result: op_class %d channel %d",
  253. p2p->op_reg_class, p2p->op_channel);
  254. if (!p2p_channels_includes(&intersection,
  255. p2p->op_reg_class,
  256. p2p->op_channel)) {
  257. p2p_dbg(p2p, "Peer does not support selected operating channel (reg_class=%u channel=%u)",
  258. p2p->op_reg_class, p2p->op_channel);
  259. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  260. goto fail;
  261. }
  262. } else if (!(dev->flags & P2P_DEV_FORCE_FREQ) &&
  263. !p2p->cfg->cfg_op_channel) {
  264. p2p_dbg(p2p, "Try to reselect channel selection with peer information received; previously selected op_class %u channel %u",
  265. p2p->op_reg_class, p2p->op_channel);
  266. p2p_reselect_channel(p2p, &intersection);
  267. }
  268. op_freq = p2p_channel_to_freq(p2p->op_reg_class,
  269. p2p->op_channel);
  270. if (op_freq < 0) {
  271. p2p_dbg(p2p, "Unknown operational channel (country=%c%c reg_class=%u channel=%u)",
  272. p2p->cfg->country[0], p2p->cfg->country[1],
  273. p2p->op_reg_class, p2p->op_channel);
  274. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  275. goto fail;
  276. }
  277. p2p_dbg(p2p, "Selected operating channel - %d MHz", op_freq);
  278. if (status == P2P_SC_SUCCESS) {
  279. reg_class = p2p->op_reg_class;
  280. channel = p2p->op_channel;
  281. channels = &intersection;
  282. }
  283. }
  284. fail:
  285. if (go && status == P2P_SC_SUCCESS && !is_zero_ether_addr(group_bssid))
  286. bssid = group_bssid;
  287. else
  288. bssid = NULL;
  289. resp = p2p_build_invitation_resp(p2p, dev, msg.dialog_token, status,
  290. bssid, reg_class, channel, channels);
  291. if (resp == NULL)
  292. goto out;
  293. if (rx_freq > 0)
  294. freq = rx_freq;
  295. else
  296. freq = p2p_channel_to_freq(p2p->cfg->reg_class,
  297. p2p->cfg->channel);
  298. if (freq < 0) {
  299. p2p_dbg(p2p, "Unknown regulatory class/channel");
  300. goto out;
  301. }
  302. /*
  303. * Store copy of invitation data to be used when processing TX status
  304. * callback for the Acton frame.
  305. */
  306. os_memcpy(p2p->inv_sa, sa, ETH_ALEN);
  307. if (msg.group_bssid) {
  308. os_memcpy(p2p->inv_group_bssid, msg.group_bssid, ETH_ALEN);
  309. p2p->inv_group_bssid_ptr = p2p->inv_group_bssid;
  310. } else
  311. p2p->inv_group_bssid_ptr = NULL;
  312. if (msg.group_id_len - ETH_ALEN <= 32) {
  313. os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN,
  314. msg.group_id_len - ETH_ALEN);
  315. p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN;
  316. }
  317. os_memcpy(p2p->inv_go_dev_addr, msg.group_id, ETH_ALEN);
  318. p2p->inv_status = status;
  319. p2p->inv_op_freq = op_freq;
  320. p2p->pending_action_state = P2P_PENDING_INVITATION_RESPONSE;
  321. if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
  322. p2p->cfg->dev_addr,
  323. wpabuf_head(resp), wpabuf_len(resp), 200) < 0) {
  324. p2p_dbg(p2p, "Failed to send Action frame");
  325. }
  326. out:
  327. wpabuf_free(resp);
  328. p2p_parse_free(&msg);
  329. }
  330. void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa,
  331. const u8 *data, size_t len)
  332. {
  333. struct p2p_device *dev;
  334. struct p2p_message msg;
  335. struct p2p_channels intersection, *channels = NULL;
  336. p2p_dbg(p2p, "Received Invitation Response from " MACSTR,
  337. MAC2STR(sa));
  338. dev = p2p_get_device(p2p, sa);
  339. if (dev == NULL) {
  340. p2p_dbg(p2p, "Ignore Invitation Response from unknown peer "
  341. MACSTR, MAC2STR(sa));
  342. return;
  343. }
  344. if (dev != p2p->invite_peer) {
  345. p2p_dbg(p2p, "Ignore unexpected Invitation Response from peer "
  346. MACSTR, MAC2STR(sa));
  347. return;
  348. }
  349. if (p2p_parse(data, len, &msg))
  350. return;
  351. if (!msg.status) {
  352. p2p_dbg(p2p, "Mandatory Status attribute missing in Invitation Response from "
  353. MACSTR, MAC2STR(sa));
  354. p2p_parse_free(&msg);
  355. return;
  356. }
  357. if (!msg.channel_list && *msg.status == P2P_SC_SUCCESS) {
  358. p2p_dbg(p2p, "Mandatory Channel List attribute missing in Invitation Response from "
  359. MACSTR, MAC2STR(sa));
  360. #ifdef CONFIG_P2P_STRICT
  361. p2p_parse_free(&msg);
  362. return;
  363. #endif /* CONFIG_P2P_STRICT */
  364. /* Try to survive without peer channel list */
  365. channels = &p2p->channels;
  366. } else if (!msg.channel_list) {
  367. /* Non-success cases are not required to include Channel List */
  368. channels = &p2p->channels;
  369. } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev,
  370. msg.channel_list,
  371. msg.channel_list_len) < 0) {
  372. p2p_dbg(p2p, "No common channels found");
  373. p2p_parse_free(&msg);
  374. return;
  375. } else {
  376. p2p_channels_intersect(&p2p->channels, &dev->channels,
  377. &intersection);
  378. channels = &intersection;
  379. }
  380. if (p2p->cfg->invitation_result)
  381. p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status,
  382. msg.group_bssid, channels, sa);
  383. p2p_parse_free(&msg);
  384. p2p_clear_timeout(p2p);
  385. p2p_set_state(p2p, P2P_IDLE);
  386. p2p->invite_peer = NULL;
  387. }
  388. int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
  389. const u8 *go_dev_addr)
  390. {
  391. struct wpabuf *req;
  392. int freq;
  393. freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
  394. if (freq <= 0) {
  395. p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
  396. MACSTR " to send Invitation Request",
  397. MAC2STR(dev->info.p2p_device_addr));
  398. return -1;
  399. }
  400. req = p2p_build_invitation_req(p2p, dev, go_dev_addr);
  401. if (req == NULL)
  402. return -1;
  403. if (p2p->state != P2P_IDLE)
  404. p2p_stop_listen_for_freq(p2p, freq);
  405. p2p_dbg(p2p, "Sending Invitation Request");
  406. p2p_set_state(p2p, P2P_INVITE);
  407. p2p->pending_action_state = P2P_PENDING_INVITATION_REQUEST;
  408. p2p->invite_peer = dev;
  409. dev->invitation_reqs++;
  410. if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
  411. p2p->cfg->dev_addr, dev->info.p2p_device_addr,
  412. wpabuf_head(req), wpabuf_len(req), 500) < 0) {
  413. p2p_dbg(p2p, "Failed to send Action frame");
  414. /* Use P2P find to recover and retry */
  415. p2p_set_timeout(p2p, 0, 0);
  416. }
  417. wpabuf_free(req);
  418. return 0;
  419. }
  420. void p2p_invitation_req_cb(struct p2p_data *p2p, int success)
  421. {
  422. p2p_dbg(p2p, "Invitation Request TX callback: success=%d", success);
  423. if (p2p->invite_peer == NULL) {
  424. p2p_dbg(p2p, "No pending Invite");
  425. return;
  426. }
  427. /*
  428. * Use P2P find, if needed, to find the other device from its listen
  429. * channel.
  430. */
  431. p2p_set_state(p2p, P2P_INVITE);
  432. p2p_set_timeout(p2p, 0, success ? 500000 : 100000);
  433. }
  434. void p2p_invitation_resp_cb(struct p2p_data *p2p, int success)
  435. {
  436. p2p_dbg(p2p, "Invitation Response TX callback: success=%d", success);
  437. p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
  438. if (!success)
  439. p2p_dbg(p2p, "Assume Invitation Response was actually received by the peer even though Ack was not reported");
  440. if (p2p->cfg->invitation_received) {
  441. p2p->cfg->invitation_received(p2p->cfg->cb_ctx,
  442. p2p->inv_sa,
  443. p2p->inv_group_bssid_ptr,
  444. p2p->inv_ssid, p2p->inv_ssid_len,
  445. p2p->inv_go_dev_addr,
  446. p2p->inv_status,
  447. p2p->inv_op_freq);
  448. }
  449. }
  450. int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
  451. const u8 *bssid, const u8 *ssid, size_t ssid_len,
  452. unsigned int force_freq, const u8 *go_dev_addr,
  453. int persistent_group, unsigned int pref_freq)
  454. {
  455. struct p2p_device *dev;
  456. p2p_dbg(p2p, "Request to invite peer " MACSTR " role=%d persistent=%d "
  457. "force_freq=%u",
  458. MAC2STR(peer), role, persistent_group, force_freq);
  459. if (bssid)
  460. p2p_dbg(p2p, "Invitation for BSSID " MACSTR, MAC2STR(bssid));
  461. if (go_dev_addr) {
  462. p2p_dbg(p2p, "Invitation for GO Device Address " MACSTR,
  463. MAC2STR(go_dev_addr));
  464. os_memcpy(p2p->invite_go_dev_addr_buf, go_dev_addr, ETH_ALEN);
  465. p2p->invite_go_dev_addr = p2p->invite_go_dev_addr_buf;
  466. } else
  467. p2p->invite_go_dev_addr = NULL;
  468. wpa_hexdump_ascii(MSG_DEBUG, "Invitation for SSID",
  469. ssid, ssid_len);
  470. dev = p2p_get_device(p2p, peer);
  471. if (dev == NULL || (dev->listen_freq <= 0 && dev->oper_freq <= 0)) {
  472. p2p_dbg(p2p, "Cannot invite unknown P2P Device " MACSTR,
  473. MAC2STR(peer));
  474. return -1;
  475. }
  476. if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq,
  477. role != P2P_INVITE_ROLE_CLIENT) < 0)
  478. return -1;
  479. if (persistent_group && role == P2P_INVITE_ROLE_CLIENT && !force_freq &&
  480. !pref_freq)
  481. dev->flags |= P2P_DEV_NO_PREF_CHAN;
  482. else
  483. dev->flags &= ~P2P_DEV_NO_PREF_CHAN;
  484. if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
  485. if (!(dev->info.dev_capab &
  486. P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
  487. p2p_dbg(p2p, "Cannot invite a P2P Device " MACSTR
  488. " that is in a group and is not discoverable",
  489. MAC2STR(peer));
  490. }
  491. /* TODO: use device discoverability request through GO */
  492. }
  493. dev->invitation_reqs = 0;
  494. if (p2p->state != P2P_IDLE)
  495. p2p_stop_find(p2p);
  496. p2p->inv_role = role;
  497. p2p->inv_bssid_set = bssid != NULL;
  498. if (bssid)
  499. os_memcpy(p2p->inv_bssid, bssid, ETH_ALEN);
  500. os_memcpy(p2p->inv_ssid, ssid, ssid_len);
  501. p2p->inv_ssid_len = ssid_len;
  502. p2p->inv_persistent = persistent_group;
  503. return p2p_invite_send(p2p, dev, go_dev_addr);
  504. }