p2p_go_neg.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. /*
  2. * Wi-Fi Direct - P2P Group Owner Negotiation
  3. * Copyright (c) 2009-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 "wps/wps_defs.h"
  12. #include "p2p_i.h"
  13. #include "p2p.h"
  14. static int p2p_go_det(u8 own_intent, u8 peer_value)
  15. {
  16. u8 peer_intent = peer_value >> 1;
  17. if (own_intent == peer_intent) {
  18. if (own_intent == P2P_MAX_GO_INTENT)
  19. return -1; /* both devices want to become GO */
  20. /* Use tie breaker bit to determine GO */
  21. return (peer_value & 0x01) ? 0 : 1;
  22. }
  23. return own_intent > peer_intent;
  24. }
  25. int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own,
  26. struct p2p_device *dev,
  27. const u8 *channel_list, size_t channel_list_len)
  28. {
  29. const u8 *pos, *end;
  30. struct p2p_channels *ch;
  31. size_t channels;
  32. struct p2p_channels intersection;
  33. ch = &dev->channels;
  34. os_memset(ch, 0, sizeof(*ch));
  35. pos = channel_list;
  36. end = channel_list + channel_list_len;
  37. if (end - pos < 3)
  38. return -1;
  39. os_memcpy(dev->country, pos, 3);
  40. wpa_hexdump_ascii(MSG_DEBUG, "P2P: Peer country", pos, 3);
  41. if (pos[2] != 0x04 && os_memcmp(pos, p2p->cfg->country, 2) != 0) {
  42. wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
  43. "P2P: Mismatching country (ours=%c%c peer's=%c%c)",
  44. p2p->cfg->country[0], p2p->cfg->country[1],
  45. pos[0], pos[1]);
  46. return -1;
  47. }
  48. pos += 3;
  49. while (pos + 2 < end) {
  50. struct p2p_reg_class *cl = &ch->reg_class[ch->reg_classes];
  51. cl->reg_class = *pos++;
  52. if (pos + 1 + pos[0] > end) {
  53. wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
  54. "P2P: Invalid peer Channel List");
  55. return -1;
  56. }
  57. channels = *pos++;
  58. cl->channels = channels > P2P_MAX_REG_CLASS_CHANNELS ?
  59. P2P_MAX_REG_CLASS_CHANNELS : channels;
  60. os_memcpy(cl->channel, pos, cl->channels);
  61. pos += channels;
  62. ch->reg_classes++;
  63. if (ch->reg_classes == P2P_MAX_REG_CLASSES)
  64. break;
  65. }
  66. p2p_channels_intersect(own, &dev->channels, &intersection);
  67. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Own reg_classes %d "
  68. "peer reg_classes %d intersection reg_classes %d",
  69. (int) own->reg_classes,
  70. (int) dev->channels.reg_classes,
  71. (int) intersection.reg_classes);
  72. if (intersection.reg_classes == 0) {
  73. wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
  74. "P2P: No common channels found");
  75. return -1;
  76. }
  77. return 0;
  78. }
  79. static int p2p_peer_channels(struct p2p_data *p2p, struct p2p_device *dev,
  80. const u8 *channel_list, size_t channel_list_len)
  81. {
  82. return p2p_peer_channels_check(p2p, &p2p->channels, dev,
  83. channel_list, channel_list_len);
  84. }
  85. u16 p2p_wps_method_pw_id(enum p2p_wps_method wps_method)
  86. {
  87. switch (wps_method) {
  88. case WPS_PIN_DISPLAY:
  89. return DEV_PW_REGISTRAR_SPECIFIED;
  90. case WPS_PIN_KEYPAD:
  91. return DEV_PW_USER_SPECIFIED;
  92. case WPS_PBC:
  93. return DEV_PW_PUSHBUTTON;
  94. default:
  95. return DEV_PW_DEFAULT;
  96. }
  97. }
  98. static const char * p2p_wps_method_str(enum p2p_wps_method wps_method)
  99. {
  100. switch (wps_method) {
  101. case WPS_PIN_DISPLAY:
  102. return "Display";
  103. case WPS_PIN_KEYPAD:
  104. return "Keypad";
  105. case WPS_PBC:
  106. return "PBC";
  107. default:
  108. return "??";
  109. }
  110. }
  111. static struct wpabuf * p2p_build_go_neg_req(struct p2p_data *p2p,
  112. struct p2p_device *peer)
  113. {
  114. struct wpabuf *buf;
  115. u8 *len;
  116. u8 group_capab;
  117. buf = wpabuf_alloc(1000);
  118. if (buf == NULL)
  119. return NULL;
  120. peer->dialog_token++;
  121. if (peer->dialog_token == 0)
  122. peer->dialog_token = 1;
  123. p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_REQ, peer->dialog_token);
  124. len = p2p_buf_add_ie_hdr(buf);
  125. group_capab = 0;
  126. if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
  127. group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
  128. if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
  129. group_capab |= P2P_GROUP_CAPAB_PERSISTENT_RECONN;
  130. }
  131. if (p2p->cross_connect)
  132. group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
  133. if (p2p->cfg->p2p_intra_bss)
  134. group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
  135. p2p_buf_add_capability(buf, p2p->dev_capab &
  136. ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
  137. group_capab);
  138. p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) |
  139. p2p->next_tie_breaker);
  140. p2p->next_tie_breaker = !p2p->next_tie_breaker;
  141. p2p_buf_add_config_timeout(buf, 100, 20);
  142. p2p_buf_add_listen_channel(buf, p2p->cfg->country, p2p->cfg->reg_class,
  143. p2p->cfg->channel);
  144. if (p2p->ext_listen_interval)
  145. p2p_buf_add_ext_listen_timing(buf, p2p->ext_listen_period,
  146. p2p->ext_listen_interval);
  147. p2p_buf_add_intended_addr(buf, p2p->intended_addr);
  148. p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels);
  149. p2p_buf_add_device_info(buf, p2p, peer);
  150. p2p_buf_add_operating_channel(buf, p2p->cfg->country,
  151. p2p->op_reg_class, p2p->op_channel);
  152. p2p_buf_update_ie_hdr(buf, len);
  153. /* WPS IE with Device Password ID attribute */
  154. p2p_build_wps_ie(p2p, buf, p2p_wps_method_pw_id(peer->wps_method), 0);
  155. return buf;
  156. }
  157. int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
  158. {
  159. struct wpabuf *req;
  160. int freq;
  161. if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) {
  162. u16 config_method;
  163. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  164. "P2P: Use PD-before-GO-Neg workaround for " MACSTR,
  165. MAC2STR(dev->info.p2p_device_addr));
  166. if (dev->wps_method == WPS_PIN_DISPLAY)
  167. config_method = WPS_CONFIG_KEYPAD;
  168. else if (dev->wps_method == WPS_PIN_KEYPAD)
  169. config_method = WPS_CONFIG_DISPLAY;
  170. else if (dev->wps_method == WPS_PBC)
  171. config_method = WPS_CONFIG_PUSHBUTTON;
  172. else
  173. return -1;
  174. return p2p_prov_disc_req(p2p, dev->info.p2p_device_addr,
  175. config_method, 0, 0);
  176. }
  177. freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
  178. if (freq <= 0) {
  179. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  180. "P2P: No Listen/Operating frequency known for the "
  181. "peer " MACSTR " to send GO Negotiation Request",
  182. MAC2STR(dev->info.p2p_device_addr));
  183. return -1;
  184. }
  185. req = p2p_build_go_neg_req(p2p, dev);
  186. if (req == NULL)
  187. return -1;
  188. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  189. "P2P: Sending GO Negotiation Request");
  190. p2p_set_state(p2p, P2P_CONNECT);
  191. p2p->pending_action_state = P2P_PENDING_GO_NEG_REQUEST;
  192. p2p->go_neg_peer = dev;
  193. dev->flags |= P2P_DEV_WAIT_GO_NEG_RESPONSE;
  194. dev->connect_reqs++;
  195. if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
  196. p2p->cfg->dev_addr, dev->info.p2p_device_addr,
  197. wpabuf_head(req), wpabuf_len(req), 200) < 0) {
  198. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  199. "P2P: Failed to send Action frame");
  200. /* Use P2P find to recover and retry */
  201. p2p_set_timeout(p2p, 0, 0);
  202. } else
  203. dev->go_neg_req_sent++;
  204. wpabuf_free(req);
  205. return 0;
  206. }
  207. static struct wpabuf * p2p_build_go_neg_resp(struct p2p_data *p2p,
  208. struct p2p_device *peer,
  209. u8 dialog_token, u8 status,
  210. u8 tie_breaker)
  211. {
  212. struct wpabuf *buf;
  213. u8 *len;
  214. u8 group_capab;
  215. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  216. "P2P: Building GO Negotiation Response");
  217. buf = wpabuf_alloc(1000);
  218. if (buf == NULL)
  219. return NULL;
  220. p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_RESP, dialog_token);
  221. len = p2p_buf_add_ie_hdr(buf);
  222. p2p_buf_add_status(buf, status);
  223. group_capab = 0;
  224. if (peer && peer->go_state == LOCAL_GO) {
  225. if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
  226. group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
  227. if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
  228. group_capab |=
  229. P2P_GROUP_CAPAB_PERSISTENT_RECONN;
  230. }
  231. if (p2p->cross_connect)
  232. group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
  233. if (p2p->cfg->p2p_intra_bss)
  234. group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
  235. }
  236. p2p_buf_add_capability(buf, p2p->dev_capab &
  237. ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
  238. group_capab);
  239. p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) | tie_breaker);
  240. p2p_buf_add_config_timeout(buf, 100, 20);
  241. if (peer && peer->go_state == REMOTE_GO) {
  242. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Omit Operating "
  243. "Channel attribute");
  244. } else {
  245. p2p_buf_add_operating_channel(buf, p2p->cfg->country,
  246. p2p->op_reg_class,
  247. p2p->op_channel);
  248. }
  249. p2p_buf_add_intended_addr(buf, p2p->intended_addr);
  250. if (status || peer == NULL) {
  251. p2p_buf_add_channel_list(buf, p2p->cfg->country,
  252. &p2p->channels);
  253. } else if (peer->go_state == REMOTE_GO) {
  254. p2p_buf_add_channel_list(buf, p2p->cfg->country,
  255. &p2p->channels);
  256. } else {
  257. struct p2p_channels res;
  258. p2p_channels_intersect(&p2p->channels, &peer->channels,
  259. &res);
  260. p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
  261. }
  262. p2p_buf_add_device_info(buf, p2p, peer);
  263. if (peer && peer->go_state == LOCAL_GO) {
  264. p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
  265. p2p->ssid_len);
  266. }
  267. p2p_buf_update_ie_hdr(buf, len);
  268. /* WPS IE with Device Password ID attribute */
  269. p2p_build_wps_ie(p2p, buf,
  270. p2p_wps_method_pw_id(peer ? peer->wps_method :
  271. WPS_NOT_READY), 0);
  272. return buf;
  273. }
  274. static void p2p_reselect_channel(struct p2p_data *p2p,
  275. struct p2p_channels *intersection)
  276. {
  277. struct p2p_reg_class *cl;
  278. int freq;
  279. u8 op_reg_class, op_channel;
  280. unsigned int i;
  281. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Selected operating "
  282. "channel (reg_class %u channel %u) not acceptable to the "
  283. "peer", p2p->op_reg_class, p2p->op_channel);
  284. /* First, try to pick the best channel from another band */
  285. freq = p2p_channel_to_freq(p2p->cfg->country, p2p->op_reg_class,
  286. p2p->op_channel);
  287. if (freq >= 2400 && freq < 2500 && p2p->best_freq_5 > 0 &&
  288. p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_5,
  289. &op_reg_class, &op_channel) == 0 &&
  290. p2p_channels_includes(intersection, op_reg_class, op_channel)) {
  291. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best 5 GHz "
  292. "channel (reg_class %u channel %u) from intersection",
  293. op_reg_class, op_channel);
  294. p2p->op_reg_class = op_reg_class;
  295. p2p->op_channel = op_channel;
  296. return;
  297. }
  298. if (freq >= 4900 && freq < 6000 && p2p->best_freq_24 > 0 &&
  299. p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_24,
  300. &op_reg_class, &op_channel) == 0 &&
  301. p2p_channels_includes(intersection, op_reg_class, op_channel)) {
  302. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best 2.4 GHz "
  303. "channel (reg_class %u channel %u) from intersection",
  304. op_reg_class, op_channel);
  305. p2p->op_reg_class = op_reg_class;
  306. p2p->op_channel = op_channel;
  307. return;
  308. }
  309. /* Select channel with highest preference if the peer supports it */
  310. for (i = 0; p2p->cfg->pref_chan && i < p2p->cfg->num_pref_chan; i++) {
  311. if (p2p_channels_includes(intersection,
  312. p2p->cfg->pref_chan[i].op_class,
  313. p2p->cfg->pref_chan[i].chan)) {
  314. p2p->op_reg_class = p2p->cfg->pref_chan[i].op_class;
  315. p2p->op_channel = p2p->cfg->pref_chan[i].chan;
  316. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick "
  317. "highest preferred chnnel (op_class %u "
  318. "channel %u) from intersection",
  319. p2p->op_reg_class, p2p->op_channel);
  320. return;
  321. }
  322. }
  323. /*
  324. * Fall back to whatever is included in the channel intersection since
  325. * no better options seems to be available.
  326. */
  327. cl = &intersection->reg_class[0];
  328. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick another channel "
  329. "(reg_class %u channel %u) from intersection",
  330. cl->reg_class, cl->channel[0]);
  331. p2p->op_reg_class = cl->reg_class;
  332. p2p->op_channel = cl->channel[0];
  333. }
  334. void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
  335. const u8 *data, size_t len, int rx_freq)
  336. {
  337. struct p2p_device *dev = NULL;
  338. struct wpabuf *resp;
  339. struct p2p_message msg;
  340. u8 status = P2P_SC_FAIL_INVALID_PARAMS;
  341. int tie_breaker = 0;
  342. int freq;
  343. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  344. "P2P: Received GO Negotiation Request from " MACSTR
  345. "(freq=%d)", MAC2STR(sa), rx_freq);
  346. if (p2p_parse(data, len, &msg))
  347. return;
  348. if (!msg.capability) {
  349. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  350. "P2P: Mandatory Capability attribute missing from GO "
  351. "Negotiation Request");
  352. #ifdef CONFIG_P2P_STRICT
  353. goto fail;
  354. #endif /* CONFIG_P2P_STRICT */
  355. }
  356. if (msg.go_intent)
  357. tie_breaker = *msg.go_intent & 0x01;
  358. else {
  359. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  360. "P2P: Mandatory GO Intent attribute missing from GO "
  361. "Negotiation Request");
  362. #ifdef CONFIG_P2P_STRICT
  363. goto fail;
  364. #endif /* CONFIG_P2P_STRICT */
  365. }
  366. if (!msg.config_timeout) {
  367. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  368. "P2P: Mandatory Configuration Timeout attribute "
  369. "missing from GO Negotiation Request");
  370. #ifdef CONFIG_P2P_STRICT
  371. goto fail;
  372. #endif /* CONFIG_P2P_STRICT */
  373. }
  374. if (!msg.listen_channel) {
  375. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  376. "P2P: No Listen Channel attribute received");
  377. goto fail;
  378. }
  379. if (!msg.operating_channel) {
  380. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  381. "P2P: No Operating Channel attribute received");
  382. goto fail;
  383. }
  384. if (!msg.channel_list) {
  385. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  386. "P2P: No Channel List attribute received");
  387. goto fail;
  388. }
  389. if (!msg.intended_addr) {
  390. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  391. "P2P: No Intended P2P Interface Address attribute "
  392. "received");
  393. goto fail;
  394. }
  395. if (!msg.p2p_device_info) {
  396. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  397. "P2P: No P2P Device Info attribute received");
  398. goto fail;
  399. }
  400. if (os_memcmp(msg.p2p_device_addr, sa, ETH_ALEN) != 0) {
  401. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  402. "P2P: Unexpected GO Negotiation Request SA=" MACSTR
  403. " != dev_addr=" MACSTR,
  404. MAC2STR(sa), MAC2STR(msg.p2p_device_addr));
  405. goto fail;
  406. }
  407. dev = p2p_get_device(p2p, sa);
  408. if (msg.status && *msg.status) {
  409. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  410. "P2P: Unexpected Status attribute (%d) in GO "
  411. "Negotiation Request", *msg.status);
  412. goto fail;
  413. }
  414. if (dev == NULL)
  415. dev = p2p_add_dev_from_go_neg_req(p2p, sa, &msg);
  416. else if (dev->flags & P2P_DEV_PROBE_REQ_ONLY)
  417. p2p_add_dev_info(p2p, sa, dev, &msg);
  418. if (dev && dev->flags & P2P_DEV_USER_REJECTED) {
  419. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  420. "P2P: User has rejected this peer");
  421. status = P2P_SC_FAIL_REJECTED_BY_USER;
  422. } else if (dev == NULL || dev->wps_method == WPS_NOT_READY) {
  423. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  424. "P2P: Not ready for GO negotiation with " MACSTR,
  425. MAC2STR(sa));
  426. status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
  427. if (dev)
  428. dev->flags |= P2P_DEV_PEER_WAITING_RESPONSE;
  429. p2p->cfg->go_neg_req_rx(p2p->cfg->cb_ctx, sa,
  430. msg.dev_password_id);
  431. } else if (p2p->go_neg_peer && p2p->go_neg_peer != dev) {
  432. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  433. "P2P: Already in Group Formation with another peer");
  434. status = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
  435. } else {
  436. int go;
  437. if (!p2p->go_neg_peer) {
  438. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting "
  439. "GO Negotiation with previously authorized "
  440. "peer");
  441. if (!(dev->flags & P2P_DEV_FORCE_FREQ)) {
  442. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  443. "P2P: Use default channel settings");
  444. p2p->op_reg_class = p2p->cfg->op_reg_class;
  445. p2p->op_channel = p2p->cfg->op_channel;
  446. os_memcpy(&p2p->channels, &p2p->cfg->channels,
  447. sizeof(struct p2p_channels));
  448. } else {
  449. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  450. "P2P: Use previously configured "
  451. "forced channel settings");
  452. }
  453. }
  454. dev->flags &= ~P2P_DEV_NOT_YET_READY;
  455. if (!msg.go_intent) {
  456. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  457. "P2P: No GO Intent attribute received");
  458. goto fail;
  459. }
  460. if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
  461. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  462. "P2P: Invalid GO Intent value (%u) received",
  463. *msg.go_intent >> 1);
  464. goto fail;
  465. }
  466. if (dev->go_neg_req_sent &&
  467. os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) > 0) {
  468. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  469. "P2P: Do not reply since peer has higher "
  470. "address and GO Neg Request already sent");
  471. p2p_parse_free(&msg);
  472. return;
  473. }
  474. go = p2p_go_det(p2p->go_intent, *msg.go_intent);
  475. if (go < 0) {
  476. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  477. "P2P: Incompatible GO Intent");
  478. status = P2P_SC_FAIL_BOTH_GO_INTENT_15;
  479. goto fail;
  480. }
  481. if (p2p_peer_channels(p2p, dev, msg.channel_list,
  482. msg.channel_list_len) < 0) {
  483. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  484. "P2P: No common channels found");
  485. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  486. goto fail;
  487. }
  488. switch (msg.dev_password_id) {
  489. case DEV_PW_REGISTRAR_SPECIFIED:
  490. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  491. "P2P: PIN from peer Display");
  492. if (dev->wps_method != WPS_PIN_KEYPAD) {
  493. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  494. "P2P: We have wps_method=%s -> "
  495. "incompatible",
  496. p2p_wps_method_str(dev->wps_method));
  497. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  498. goto fail;
  499. }
  500. break;
  501. case DEV_PW_USER_SPECIFIED:
  502. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  503. "P2P: Peer entered PIN on Keypad");
  504. if (dev->wps_method != WPS_PIN_DISPLAY) {
  505. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  506. "P2P: We have wps_method=%s -> "
  507. "incompatible",
  508. p2p_wps_method_str(dev->wps_method));
  509. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  510. goto fail;
  511. }
  512. break;
  513. case DEV_PW_PUSHBUTTON:
  514. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  515. "P2P: Peer using pushbutton");
  516. if (dev->wps_method != WPS_PBC) {
  517. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  518. "P2P: We have wps_method=%s -> "
  519. "incompatible",
  520. p2p_wps_method_str(dev->wps_method));
  521. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  522. goto fail;
  523. }
  524. break;
  525. default:
  526. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  527. "P2P: Unsupported Device Password ID %d",
  528. msg.dev_password_id);
  529. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  530. goto fail;
  531. }
  532. if (go) {
  533. struct p2p_channels intersection;
  534. size_t i;
  535. p2p_channels_intersect(&p2p->channels, &dev->channels,
  536. &intersection);
  537. if (intersection.reg_classes == 0 ||
  538. intersection.reg_class[0].channels == 0) {
  539. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  540. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  541. "P2P: No common channels found");
  542. goto fail;
  543. }
  544. for (i = 0; i < intersection.reg_classes; i++) {
  545. struct p2p_reg_class *c;
  546. c = &intersection.reg_class[i];
  547. wpa_printf(MSG_DEBUG, "P2P: reg_class %u",
  548. c->reg_class);
  549. wpa_hexdump(MSG_DEBUG, "P2P: channels",
  550. c->channel, c->channels);
  551. }
  552. if (!p2p_channels_includes(&intersection,
  553. p2p->op_reg_class,
  554. p2p->op_channel))
  555. p2p_reselect_channel(p2p, &intersection);
  556. if (!p2p->ssid_set) {
  557. p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
  558. p2p->ssid_set = 1;
  559. }
  560. }
  561. dev->go_state = go ? LOCAL_GO : REMOTE_GO;
  562. dev->oper_freq = p2p_channel_to_freq((const char *)
  563. msg.operating_channel,
  564. msg.operating_channel[3],
  565. msg.operating_channel[4]);
  566. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
  567. "channel preference: %d MHz", dev->oper_freq);
  568. if (msg.config_timeout) {
  569. dev->go_timeout = msg.config_timeout[0];
  570. dev->client_timeout = msg.config_timeout[1];
  571. }
  572. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  573. "P2P: GO Negotiation with " MACSTR, MAC2STR(sa));
  574. if (p2p->state != P2P_IDLE)
  575. p2p_stop_find_for_freq(p2p, rx_freq);
  576. p2p_set_state(p2p, P2P_GO_NEG);
  577. p2p_clear_timeout(p2p);
  578. dev->dialog_token = msg.dialog_token;
  579. os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
  580. p2p->go_neg_peer = dev;
  581. status = P2P_SC_SUCCESS;
  582. }
  583. fail:
  584. if (dev)
  585. dev->status = status;
  586. resp = p2p_build_go_neg_resp(p2p, dev, msg.dialog_token, status,
  587. !tie_breaker);
  588. p2p_parse_free(&msg);
  589. if (resp == NULL)
  590. return;
  591. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  592. "P2P: Sending GO Negotiation Response");
  593. if (rx_freq > 0)
  594. freq = rx_freq;
  595. else
  596. freq = p2p_channel_to_freq(p2p->cfg->country,
  597. p2p->cfg->reg_class,
  598. p2p->cfg->channel);
  599. if (freq < 0) {
  600. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  601. "P2P: Unknown regulatory class/channel");
  602. wpabuf_free(resp);
  603. return;
  604. }
  605. if (status == P2P_SC_SUCCESS) {
  606. p2p->pending_action_state = P2P_PENDING_GO_NEG_RESPONSE;
  607. dev->flags |= P2P_DEV_WAIT_GO_NEG_CONFIRM;
  608. if (os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) < 0) {
  609. /*
  610. * Peer has smaller address, so the GO Negotiation
  611. * Response from us is expected to complete
  612. * negotiation. Ignore a GO Negotiation Response from
  613. * the peer if it happens to be received after this
  614. * point due to a race condition in GO Negotiation
  615. * Request transmission and processing.
  616. */
  617. dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
  618. }
  619. } else
  620. p2p->pending_action_state =
  621. P2P_PENDING_GO_NEG_RESPONSE_FAILURE;
  622. if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
  623. p2p->cfg->dev_addr,
  624. wpabuf_head(resp), wpabuf_len(resp), 250) < 0) {
  625. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  626. "P2P: Failed to send Action frame");
  627. }
  628. wpabuf_free(resp);
  629. }
  630. static struct wpabuf * p2p_build_go_neg_conf(struct p2p_data *p2p,
  631. struct p2p_device *peer,
  632. u8 dialog_token, u8 status,
  633. const u8 *resp_chan, int go)
  634. {
  635. struct wpabuf *buf;
  636. u8 *len;
  637. struct p2p_channels res;
  638. u8 group_capab;
  639. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  640. "P2P: Building GO Negotiation Confirm");
  641. buf = wpabuf_alloc(1000);
  642. if (buf == NULL)
  643. return NULL;
  644. p2p_buf_add_public_action_hdr(buf, P2P_GO_NEG_CONF, dialog_token);
  645. len = p2p_buf_add_ie_hdr(buf);
  646. p2p_buf_add_status(buf, status);
  647. group_capab = 0;
  648. if (peer->go_state == LOCAL_GO) {
  649. if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) {
  650. group_capab |= P2P_GROUP_CAPAB_PERSISTENT_GROUP;
  651. if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN)
  652. group_capab |=
  653. P2P_GROUP_CAPAB_PERSISTENT_RECONN;
  654. }
  655. if (p2p->cross_connect)
  656. group_capab |= P2P_GROUP_CAPAB_CROSS_CONN;
  657. if (p2p->cfg->p2p_intra_bss)
  658. group_capab |= P2P_GROUP_CAPAB_INTRA_BSS_DIST;
  659. }
  660. p2p_buf_add_capability(buf, p2p->dev_capab &
  661. ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY,
  662. group_capab);
  663. if (go || resp_chan == NULL)
  664. p2p_buf_add_operating_channel(buf, p2p->cfg->country,
  665. p2p->op_reg_class,
  666. p2p->op_channel);
  667. else
  668. p2p_buf_add_operating_channel(buf, (const char *) resp_chan,
  669. resp_chan[3], resp_chan[4]);
  670. p2p_channels_intersect(&p2p->channels, &peer->channels, &res);
  671. p2p_buf_add_channel_list(buf, p2p->cfg->country, &res);
  672. if (go) {
  673. p2p_buf_add_group_id(buf, p2p->cfg->dev_addr, p2p->ssid,
  674. p2p->ssid_len);
  675. }
  676. p2p_buf_update_ie_hdr(buf, len);
  677. return buf;
  678. }
  679. void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
  680. const u8 *data, size_t len, int rx_freq)
  681. {
  682. struct p2p_device *dev;
  683. struct wpabuf *conf;
  684. int go = -1;
  685. struct p2p_message msg;
  686. u8 status = P2P_SC_SUCCESS;
  687. int freq;
  688. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  689. "P2P: Received GO Negotiation Response from " MACSTR
  690. " (freq=%d)", MAC2STR(sa), rx_freq);
  691. dev = p2p_get_device(p2p, sa);
  692. if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
  693. dev != p2p->go_neg_peer) {
  694. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  695. "P2P: Not ready for GO negotiation with " MACSTR,
  696. MAC2STR(sa));
  697. return;
  698. }
  699. if (p2p_parse(data, len, &msg))
  700. return;
  701. if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE)) {
  702. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  703. "P2P: Was not expecting GO Negotiation Response - "
  704. "ignore");
  705. p2p_parse_free(&msg);
  706. return;
  707. }
  708. dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
  709. if (msg.dialog_token != dev->dialog_token) {
  710. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  711. "P2P: Unexpected Dialog Token %u (expected %u)",
  712. msg.dialog_token, dev->dialog_token);
  713. p2p_parse_free(&msg);
  714. return;
  715. }
  716. if (!msg.status) {
  717. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  718. "P2P: No Status attribute received");
  719. status = P2P_SC_FAIL_INVALID_PARAMS;
  720. goto fail;
  721. }
  722. if (*msg.status) {
  723. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  724. "P2P: GO Negotiation rejected: status %d",
  725. *msg.status);
  726. dev->go_neg_req_sent = 0;
  727. if (*msg.status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
  728. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  729. "P2P: Wait for the peer to become ready for "
  730. "GO Negotiation");
  731. dev->flags |= P2P_DEV_NOT_YET_READY;
  732. dev->wait_count = 0;
  733. p2p_set_state(p2p, P2P_WAIT_PEER_IDLE);
  734. p2p_set_timeout(p2p, 0, 0);
  735. } else {
  736. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  737. "P2P: Stop GO Negotiation attempt");
  738. p2p_go_neg_failed(p2p, dev, *msg.status);
  739. }
  740. p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
  741. p2p_parse_free(&msg);
  742. return;
  743. }
  744. if (!msg.capability) {
  745. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  746. "P2P: Mandatory Capability attribute missing from GO "
  747. "Negotiation Response");
  748. #ifdef CONFIG_P2P_STRICT
  749. status = P2P_SC_FAIL_INVALID_PARAMS;
  750. goto fail;
  751. #endif /* CONFIG_P2P_STRICT */
  752. }
  753. if (!msg.p2p_device_info) {
  754. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  755. "P2P: Mandatory P2P Device Info attribute missing "
  756. "from GO Negotiation Response");
  757. #ifdef CONFIG_P2P_STRICT
  758. status = P2P_SC_FAIL_INVALID_PARAMS;
  759. goto fail;
  760. #endif /* CONFIG_P2P_STRICT */
  761. }
  762. if (!msg.intended_addr) {
  763. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  764. "P2P: No Intended P2P Interface Address attribute "
  765. "received");
  766. status = P2P_SC_FAIL_INVALID_PARAMS;
  767. goto fail;
  768. }
  769. if (!msg.go_intent) {
  770. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  771. "P2P: No GO Intent attribute received");
  772. status = P2P_SC_FAIL_INVALID_PARAMS;
  773. goto fail;
  774. }
  775. if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
  776. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  777. "P2P: Invalid GO Intent value (%u) received",
  778. *msg.go_intent >> 1);
  779. status = P2P_SC_FAIL_INVALID_PARAMS;
  780. goto fail;
  781. }
  782. go = p2p_go_det(p2p->go_intent, *msg.go_intent);
  783. if (go < 0) {
  784. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  785. "P2P: Incompatible GO Intent");
  786. status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
  787. goto fail;
  788. }
  789. if (!go && msg.group_id) {
  790. /* Store SSID for Provisioning step */
  791. p2p->ssid_len = msg.group_id_len - ETH_ALEN;
  792. os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
  793. } else if (!go) {
  794. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  795. "P2P: Mandatory P2P Group ID attribute missing from "
  796. "GO Negotiation Response");
  797. p2p->ssid_len = 0;
  798. #ifdef CONFIG_P2P_STRICT
  799. status = P2P_SC_FAIL_INVALID_PARAMS;
  800. goto fail;
  801. #endif /* CONFIG_P2P_STRICT */
  802. }
  803. if (!msg.config_timeout) {
  804. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  805. "P2P: Mandatory Configuration Timeout attribute "
  806. "missing from GO Negotiation Response");
  807. #ifdef CONFIG_P2P_STRICT
  808. status = P2P_SC_FAIL_INVALID_PARAMS;
  809. goto fail;
  810. #endif /* CONFIG_P2P_STRICT */
  811. } else {
  812. dev->go_timeout = msg.config_timeout[0];
  813. dev->client_timeout = msg.config_timeout[1];
  814. }
  815. if (!msg.operating_channel && !go) {
  816. /*
  817. * Note: P2P Client may omit Operating Channel attribute to
  818. * indicate it does not have a preference.
  819. */
  820. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  821. "P2P: No Operating Channel attribute received");
  822. status = P2P_SC_FAIL_INVALID_PARAMS;
  823. goto fail;
  824. }
  825. if (!msg.channel_list) {
  826. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  827. "P2P: No Channel List attribute received");
  828. status = P2P_SC_FAIL_INVALID_PARAMS;
  829. goto fail;
  830. }
  831. if (p2p_peer_channels(p2p, dev, msg.channel_list,
  832. msg.channel_list_len) < 0) {
  833. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  834. "P2P: No common channels found");
  835. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  836. goto fail;
  837. }
  838. if (msg.operating_channel) {
  839. dev->oper_freq = p2p_channel_to_freq((const char *)
  840. msg.operating_channel,
  841. msg.operating_channel[3],
  842. msg.operating_channel[4]);
  843. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
  844. "channel preference: %d MHz", dev->oper_freq);
  845. } else
  846. dev->oper_freq = 0;
  847. switch (msg.dev_password_id) {
  848. case DEV_PW_REGISTRAR_SPECIFIED:
  849. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  850. "P2P: PIN from peer Display");
  851. if (dev->wps_method != WPS_PIN_KEYPAD) {
  852. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  853. "P2P: We have wps_method=%s -> "
  854. "incompatible",
  855. p2p_wps_method_str(dev->wps_method));
  856. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  857. goto fail;
  858. }
  859. break;
  860. case DEV_PW_USER_SPECIFIED:
  861. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  862. "P2P: Peer entered PIN on Keypad");
  863. if (dev->wps_method != WPS_PIN_DISPLAY) {
  864. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  865. "P2P: We have wps_method=%s -> "
  866. "incompatible",
  867. p2p_wps_method_str(dev->wps_method));
  868. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  869. goto fail;
  870. }
  871. break;
  872. case DEV_PW_PUSHBUTTON:
  873. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  874. "P2P: Peer using pushbutton");
  875. if (dev->wps_method != WPS_PBC) {
  876. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  877. "P2P: We have wps_method=%s -> "
  878. "incompatible",
  879. p2p_wps_method_str(dev->wps_method));
  880. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  881. goto fail;
  882. }
  883. break;
  884. default:
  885. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  886. "P2P: Unsupported Device Password ID %d",
  887. msg.dev_password_id);
  888. status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
  889. goto fail;
  890. }
  891. if (go) {
  892. struct p2p_channels intersection;
  893. size_t i;
  894. p2p_channels_intersect(&p2p->channels, &dev->channels,
  895. &intersection);
  896. if (intersection.reg_classes == 0 ||
  897. intersection.reg_class[0].channels == 0) {
  898. status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
  899. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  900. "P2P: No common channels found");
  901. goto fail;
  902. }
  903. for (i = 0; i < intersection.reg_classes; i++) {
  904. struct p2p_reg_class *c;
  905. c = &intersection.reg_class[i];
  906. wpa_printf(MSG_DEBUG, "P2P: reg_class %u",
  907. c->reg_class);
  908. wpa_hexdump(MSG_DEBUG, "P2P: channels",
  909. c->channel, c->channels);
  910. }
  911. if (!p2p_channels_includes(&intersection, p2p->op_reg_class,
  912. p2p->op_channel))
  913. p2p_reselect_channel(p2p, &intersection);
  914. if (!p2p->ssid_set) {
  915. p2p_build_ssid(p2p, p2p->ssid, &p2p->ssid_len);
  916. p2p->ssid_set = 1;
  917. }
  918. }
  919. p2p_set_state(p2p, P2P_GO_NEG);
  920. p2p_clear_timeout(p2p);
  921. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  922. "P2P: GO Negotiation with " MACSTR, MAC2STR(sa));
  923. os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
  924. fail:
  925. conf = p2p_build_go_neg_conf(p2p, dev, msg.dialog_token, status,
  926. msg.operating_channel, go);
  927. p2p_parse_free(&msg);
  928. if (conf == NULL)
  929. return;
  930. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  931. "P2P: Sending GO Negotiation Confirm");
  932. if (status == P2P_SC_SUCCESS) {
  933. p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM;
  934. dev->go_state = go ? LOCAL_GO : REMOTE_GO;
  935. } else
  936. p2p->pending_action_state = P2P_NO_PENDING_ACTION;
  937. if (rx_freq > 0)
  938. freq = rx_freq;
  939. else
  940. freq = dev->listen_freq;
  941. if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, sa,
  942. wpabuf_head(conf), wpabuf_len(conf), 0) < 0) {
  943. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  944. "P2P: Failed to send Action frame");
  945. p2p_go_neg_failed(p2p, dev, -1);
  946. }
  947. wpabuf_free(conf);
  948. }
  949. void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
  950. const u8 *data, size_t len)
  951. {
  952. struct p2p_device *dev;
  953. struct p2p_message msg;
  954. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  955. "P2P: Received GO Negotiation Confirm from " MACSTR,
  956. MAC2STR(sa));
  957. dev = p2p_get_device(p2p, sa);
  958. if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
  959. dev != p2p->go_neg_peer) {
  960. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  961. "P2P: Not ready for GO negotiation with " MACSTR,
  962. MAC2STR(sa));
  963. return;
  964. }
  965. if (p2p->pending_action_state == P2P_PENDING_GO_NEG_RESPONSE) {
  966. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Stopped waiting "
  967. "for TX status on GO Negotiation Response since we "
  968. "already received Confirmation");
  969. p2p->pending_action_state = P2P_NO_PENDING_ACTION;
  970. }
  971. if (p2p_parse(data, len, &msg))
  972. return;
  973. if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
  974. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  975. "P2P: Was not expecting GO Negotiation Confirm - "
  976. "ignore");
  977. return;
  978. }
  979. dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM;
  980. if (msg.dialog_token != dev->dialog_token) {
  981. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  982. "P2P: Unexpected Dialog Token %u (expected %u)",
  983. msg.dialog_token, dev->dialog_token);
  984. p2p_parse_free(&msg);
  985. return;
  986. }
  987. if (!msg.status) {
  988. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  989. "P2P: No Status attribute received");
  990. p2p_parse_free(&msg);
  991. return;
  992. }
  993. if (*msg.status) {
  994. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  995. "P2P: GO Negotiation rejected: status %d",
  996. *msg.status);
  997. p2p_parse_free(&msg);
  998. return;
  999. }
  1000. if (dev->go_state == REMOTE_GO && msg.group_id) {
  1001. /* Store SSID for Provisioning step */
  1002. p2p->ssid_len = msg.group_id_len - ETH_ALEN;
  1003. os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
  1004. } else if (dev->go_state == REMOTE_GO) {
  1005. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  1006. "P2P: Mandatory P2P Group ID attribute missing from "
  1007. "GO Negotiation Confirmation");
  1008. p2p->ssid_len = 0;
  1009. #ifdef CONFIG_P2P_STRICT
  1010. p2p_parse_free(&msg);
  1011. return;
  1012. #endif /* CONFIG_P2P_STRICT */
  1013. }
  1014. if (!msg.operating_channel) {
  1015. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  1016. "P2P: Mandatory Operating Channel attribute missing "
  1017. "from GO Negotiation Confirmation");
  1018. #ifdef CONFIG_P2P_STRICT
  1019. p2p_parse_free(&msg);
  1020. return;
  1021. #endif /* CONFIG_P2P_STRICT */
  1022. }
  1023. if (!msg.channel_list) {
  1024. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  1025. "P2P: Mandatory Operating Channel attribute missing "
  1026. "from GO Negotiation Confirmation");
  1027. #ifdef CONFIG_P2P_STRICT
  1028. p2p_parse_free(&msg);
  1029. return;
  1030. #endif /* CONFIG_P2P_STRICT */
  1031. }
  1032. p2p_parse_free(&msg);
  1033. if (dev->go_state == UNKNOWN_GO) {
  1034. /*
  1035. * This should not happen since GO negotiation has already
  1036. * been completed.
  1037. */
  1038. wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
  1039. "P2P: Unexpected GO Neg state - do not know which end "
  1040. "becomes GO");
  1041. return;
  1042. }
  1043. p2p_go_complete(p2p, dev);
  1044. }