p2p.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. /*
  2. * Copyright (c) 2012 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/slab.h>
  17. #include <linux/netdevice.h>
  18. #include <net/cfg80211.h>
  19. #include <brcmu_wifi.h>
  20. #include <brcmu_utils.h>
  21. #include <defs.h>
  22. #include <dhd.h>
  23. #include <dhd_dbg.h>
  24. #include "fwil.h"
  25. #include "fwil_types.h"
  26. #include "p2p.h"
  27. #include "wl_cfg80211.h"
  28. /* parameters used for p2p escan */
  29. #define P2PAPI_SCAN_NPROBES 1
  30. #define P2PAPI_SCAN_DWELL_TIME_MS 80
  31. #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
  32. #define P2PAPI_SCAN_HOME_TIME_MS 60
  33. #define P2PAPI_SCAN_NPROBS_TIME_MS 30
  34. #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
  35. #define WL_SCAN_CONNECT_DWELL_TIME_MS 200
  36. #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
  37. #define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
  38. #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
  39. #define SOCIAL_CHAN_1 1
  40. #define SOCIAL_CHAN_2 6
  41. #define SOCIAL_CHAN_3 11
  42. #define SOCIAL_CHAN_CNT 3
  43. #define AF_PEER_SEARCH_CNT 2
  44. #define BRCMF_SCB_TIMEOUT_VALUE 20
  45. #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
  46. #define P2P_PUB_AF_CATEGORY 0x04
  47. #define P2P_PUB_AF_ACTION 0x09
  48. #define P2P_AF_CATEGORY 0x7f
  49. #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
  50. #define P2P_OUI_LEN 3 /* P2P OUI length */
  51. /* Action Frame Constants */
  52. #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
  53. #define DOT11_ACTION_CAT_OFF 0 /* category offset */
  54. #define DOT11_ACTION_ACT_OFF 1 /* action offset */
  55. #define P2P_AF_DWELL_TIME 200
  56. #define P2P_AF_MIN_DWELL_TIME 100
  57. #define P2P_AF_MED_DWELL_TIME 400
  58. #define P2P_AF_LONG_DWELL_TIME 1000
  59. #define P2P_AF_TX_MAX_RETRY 5
  60. #define P2P_AF_MAX_WAIT_TIME 2000
  61. #define P2P_INVALID_CHANNEL -1
  62. #define P2P_CHANNEL_SYNC_RETRY 5
  63. #define P2P_AF_FRM_SCAN_MAX_WAIT 1500
  64. /* WiFi P2P Public Action Frame OUI Subtypes */
  65. #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
  66. #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
  67. #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
  68. #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
  69. #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
  70. #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
  71. #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
  72. #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
  73. #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
  74. #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
  75. /* WiFi P2P Action Frame OUI Subtypes */
  76. #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
  77. #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
  78. #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
  79. #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
  80. /* P2P Service Discovery related */
  81. #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
  82. #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
  83. #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
  84. #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
  85. #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
  86. /**
  87. * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
  88. *
  89. * @state: requested discovery state (see enum brcmf_p2p_disc_state).
  90. * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
  91. * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
  92. */
  93. struct brcmf_p2p_disc_st_le {
  94. u8 state;
  95. __le16 chspec;
  96. __le16 dwell;
  97. };
  98. /**
  99. * enum brcmf_p2p_disc_state - P2P discovery state values
  100. *
  101. * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
  102. * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
  103. * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
  104. */
  105. enum brcmf_p2p_disc_state {
  106. WL_P2P_DISC_ST_SCAN,
  107. WL_P2P_DISC_ST_LISTEN,
  108. WL_P2P_DISC_ST_SEARCH
  109. };
  110. /**
  111. * struct brcmf_p2p_scan_le - P2P specific scan request.
  112. *
  113. * @type: type of scan method requested (values: 'E' or 'S').
  114. * @reserved: reserved (ignored).
  115. * @eparams: parameters used for type 'E'.
  116. * @sparams: parameters used for type 'S'.
  117. */
  118. struct brcmf_p2p_scan_le {
  119. u8 type;
  120. u8 reserved[3];
  121. union {
  122. struct brcmf_escan_params_le eparams;
  123. struct brcmf_scan_params_le sparams;
  124. };
  125. };
  126. /**
  127. * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
  128. *
  129. * @category: P2P_PUB_AF_CATEGORY
  130. * @action: P2P_PUB_AF_ACTION
  131. * @oui[3]: P2P_OUI
  132. * @oui_type: OUI type - P2P_VER
  133. * @subtype: OUI subtype - P2P_TYPE_*
  134. * @dialog_token: nonzero, identifies req/rsp transaction
  135. * @elts[1]: Variable length information elements.
  136. */
  137. struct brcmf_p2p_pub_act_frame {
  138. u8 category;
  139. u8 action;
  140. u8 oui[3];
  141. u8 oui_type;
  142. u8 subtype;
  143. u8 dialog_token;
  144. u8 elts[1];
  145. };
  146. /**
  147. * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
  148. *
  149. * @category: P2P_AF_CATEGORY
  150. * @OUI[3]: OUI - P2P_OUI
  151. * @type: OUI Type - P2P_VER
  152. * @subtype: OUI Subtype - P2P_AF_*
  153. * @dialog_token: nonzero, identifies req/resp tranaction
  154. * @elts[1]: Variable length information elements.
  155. */
  156. struct brcmf_p2p_action_frame {
  157. u8 category;
  158. u8 oui[3];
  159. u8 type;
  160. u8 subtype;
  161. u8 dialog_token;
  162. u8 elts[1];
  163. };
  164. /**
  165. * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
  166. *
  167. * @category: 0x04 Public Action Frame
  168. * @action: 0x6c Advertisement Protocol
  169. * @dialog_token: nonzero, identifies req/rsp transaction
  170. * @query_data[1]: Query Data. SD gas ireq SD gas iresp
  171. */
  172. struct brcmf_p2psd_gas_pub_act_frame {
  173. u8 category;
  174. u8 action;
  175. u8 dialog_token;
  176. u8 query_data[1];
  177. };
  178. /**
  179. * struct brcmf_config_af_params - Action Frame Parameters for tx.
  180. *
  181. * @max_tx_retry: max tx retry count if tx no ack.
  182. * @mpc_onoff: To make sure to send successfully action frame, we have to
  183. * turn off mpc 0: off, 1: on, (-1): do nothing
  184. */
  185. struct brcmf_config_af_params {
  186. s32 max_tx_retry;
  187. s32 mpc_onoff;
  188. };
  189. /**
  190. * brcmf_p2p_is_pub_action() - true if p2p public type frame.
  191. *
  192. * @frame: action frame data.
  193. * @frame_len: length of action frame data.
  194. *
  195. * Determine if action frame is p2p public action type
  196. */
  197. static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
  198. {
  199. struct brcmf_p2p_pub_act_frame *pact_frm;
  200. if (frame == NULL)
  201. return false;
  202. pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
  203. if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
  204. return false;
  205. if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
  206. pact_frm->action == P2P_PUB_AF_ACTION &&
  207. pact_frm->oui_type == P2P_VER &&
  208. memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
  209. return true;
  210. return false;
  211. }
  212. /**
  213. * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
  214. *
  215. * @frame: action frame data.
  216. * @frame_len: length of action frame data.
  217. *
  218. * Determine if action frame is p2p action type
  219. */
  220. static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
  221. {
  222. struct brcmf_p2p_action_frame *act_frm;
  223. if (frame == NULL)
  224. return false;
  225. act_frm = (struct brcmf_p2p_action_frame *)frame;
  226. if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
  227. return false;
  228. if (act_frm->category == P2P_AF_CATEGORY &&
  229. act_frm->type == P2P_VER &&
  230. memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
  231. return true;
  232. return false;
  233. }
  234. /**
  235. * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
  236. *
  237. * @frame: action frame data.
  238. * @frame_len: length of action frame data.
  239. *
  240. * Determine if action frame is p2p gas action type
  241. */
  242. static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
  243. {
  244. struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
  245. if (frame == NULL)
  246. return false;
  247. sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
  248. if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
  249. return false;
  250. if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
  251. return false;
  252. if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
  253. sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
  254. sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
  255. sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
  256. return true;
  257. return false;
  258. }
  259. /**
  260. * brcmf_p2p_print_actframe() - debug print routine.
  261. *
  262. * @tx: Received or to be transmitted
  263. * @frame: action frame data.
  264. * @frame_len: length of action frame data.
  265. *
  266. * Print information about the p2p action frame
  267. */
  268. static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
  269. {
  270. struct brcmf_p2p_pub_act_frame *pact_frm;
  271. struct brcmf_p2p_action_frame *act_frm;
  272. struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
  273. if (!frame || frame_len <= 2)
  274. return;
  275. if (brcmf_p2p_is_pub_action(frame, frame_len)) {
  276. pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
  277. switch (pact_frm->subtype) {
  278. case P2P_PAF_GON_REQ:
  279. brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
  280. (tx) ? "TX" : "RX");
  281. break;
  282. case P2P_PAF_GON_RSP:
  283. brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
  284. (tx) ? "TX" : "RX");
  285. break;
  286. case P2P_PAF_GON_CONF:
  287. brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
  288. (tx) ? "TX" : "RX");
  289. break;
  290. case P2P_PAF_INVITE_REQ:
  291. brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
  292. (tx) ? "TX" : "RX");
  293. break;
  294. case P2P_PAF_INVITE_RSP:
  295. brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
  296. (tx) ? "TX" : "RX");
  297. break;
  298. case P2P_PAF_DEVDIS_REQ:
  299. brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
  300. (tx) ? "TX" : "RX");
  301. break;
  302. case P2P_PAF_DEVDIS_RSP:
  303. brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
  304. (tx) ? "TX" : "RX");
  305. break;
  306. case P2P_PAF_PROVDIS_REQ:
  307. brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
  308. (tx) ? "TX" : "RX");
  309. break;
  310. case P2P_PAF_PROVDIS_RSP:
  311. brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
  312. (tx) ? "TX" : "RX");
  313. break;
  314. default:
  315. brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
  316. (tx) ? "TX" : "RX");
  317. break;
  318. }
  319. } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
  320. act_frm = (struct brcmf_p2p_action_frame *)frame;
  321. switch (act_frm->subtype) {
  322. case P2P_AF_NOTICE_OF_ABSENCE:
  323. brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
  324. (tx) ? "TX" : "RX");
  325. break;
  326. case P2P_AF_PRESENCE_REQ:
  327. brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
  328. (tx) ? "TX" : "RX");
  329. break;
  330. case P2P_AF_PRESENCE_RSP:
  331. brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
  332. (tx) ? "TX" : "RX");
  333. break;
  334. case P2P_AF_GO_DISC_REQ:
  335. brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
  336. (tx) ? "TX" : "RX");
  337. break;
  338. default:
  339. brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
  340. (tx) ? "TX" : "RX");
  341. }
  342. } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
  343. sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
  344. switch (sd_act_frm->action) {
  345. case P2PSD_ACTION_ID_GAS_IREQ:
  346. brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
  347. (tx) ? "TX" : "RX");
  348. break;
  349. case P2PSD_ACTION_ID_GAS_IRESP:
  350. brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
  351. (tx) ? "TX" : "RX");
  352. break;
  353. case P2PSD_ACTION_ID_GAS_CREQ:
  354. brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
  355. (tx) ? "TX" : "RX");
  356. break;
  357. case P2PSD_ACTION_ID_GAS_CRESP:
  358. brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
  359. (tx) ? "TX" : "RX");
  360. break;
  361. default:
  362. brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
  363. (tx) ? "TX" : "RX");
  364. break;
  365. }
  366. }
  367. }
  368. /**
  369. * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
  370. *
  371. * @p2p: P2P specific data.
  372. */
  373. static int brcmf_p2p_set_firmware(struct brcmf_p2p_info *p2p)
  374. {
  375. struct net_device *ndev = cfg_to_ndev(p2p->cfg);
  376. u8 null_eth_addr[] = { 0, 0, 0, 0, 0, 0 };
  377. s32 ret = 0;
  378. brcmf_fil_iovar_int_set(netdev_priv(ndev), "apsta", 1);
  379. /* In case of COB type, firmware has default mac address
  380. * After Initializing firmware, we have to set current mac address to
  381. * firmware for P2P device address
  382. */
  383. ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "p2p_da_override",
  384. null_eth_addr, sizeof(null_eth_addr));
  385. if (ret)
  386. brcmf_err("failed to update device address ret %d\n", ret);
  387. return ret;
  388. }
  389. /**
  390. * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
  391. *
  392. * @p2p: P2P specific data.
  393. *
  394. * P2P needs mac addresses for P2P device and interface. These are
  395. * derived from the primary net device, ie. the permanent ethernet
  396. * address of the device.
  397. */
  398. static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
  399. {
  400. /* Generate the P2P Device Address. This consists of the device's
  401. * primary MAC address with the locally administered bit set.
  402. */
  403. memcpy(p2p->dev_addr, p2p->cfg->pub->mac, ETH_ALEN);
  404. p2p->dev_addr[0] |= 0x02;
  405. /* Generate the P2P Interface Address. If the discovery and connection
  406. * BSSCFGs need to simultaneously co-exist, then this address must be
  407. * different from the P2P Device Address, but also locally administered.
  408. */
  409. memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
  410. p2p->int_addr[4] ^= 0x80;
  411. }
  412. /**
  413. * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
  414. *
  415. * @request: the scan request as received from cfg80211.
  416. *
  417. * returns true if one of the ssids in the request matches the
  418. * P2P wildcard ssid; otherwise returns false.
  419. */
  420. static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
  421. {
  422. struct cfg80211_ssid *ssids = request->ssids;
  423. int i;
  424. for (i = 0; i < request->n_ssids; i++) {
  425. if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
  426. continue;
  427. brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
  428. if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
  429. BRCMF_P2P_WILDCARD_SSID_LEN))
  430. return true;
  431. }
  432. return false;
  433. }
  434. /**
  435. * brcmf_p2p_set_discover_state - set discover state in firmware.
  436. *
  437. * @ifp: low-level interface object.
  438. * @state: discover state to set.
  439. * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
  440. * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
  441. */
  442. static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
  443. u16 chanspec, u16 listen_ms)
  444. {
  445. struct brcmf_p2p_disc_st_le discover_state;
  446. s32 ret = 0;
  447. brcmf_dbg(TRACE, "enter\n");
  448. discover_state.state = state;
  449. discover_state.chspec = cpu_to_le16(chanspec);
  450. discover_state.dwell = cpu_to_le16(listen_ms);
  451. ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
  452. sizeof(discover_state));
  453. return ret;
  454. }
  455. /**
  456. * brcmf_p2p_init_discovery() - enable discovery in the firmware.
  457. *
  458. * @p2p: P2P specific data.
  459. *
  460. * Configures the firmware to allow P2P peer discovery. Creates the
  461. * virtual interface and consequently the P2P device for it.
  462. */
  463. static s32 brcmf_p2p_init_discovery(struct brcmf_p2p_info *p2p)
  464. {
  465. struct net_device *ndev = cfg_to_ndev(p2p->cfg);
  466. struct brcmf_cfg80211_vif *vif;
  467. struct brcmf_if *ifp;
  468. struct p2p_bss *bss_dev;
  469. s32 index;
  470. s32 ret;
  471. brcmf_dbg(TRACE, "enter\n");
  472. bss_dev = &p2p->bss_idx[P2PAPI_BSSCFG_DEVICE];
  473. if (bss_dev->vif != NULL) {
  474. brcmf_dbg(INFO, "do nothing, already initialized\n");
  475. return 0;
  476. }
  477. /* Enable P2P Discovery in the firmware */
  478. ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 1);
  479. if (ret < 0) {
  480. brcmf_err("set discover error\n");
  481. return ret;
  482. }
  483. /* obtain bsscfg index for P2P discovery */
  484. ret = brcmf_fil_iovar_int_get(netdev_priv(ndev), "p2p_dev", &index);
  485. if (ret < 0) {
  486. brcmf_err("retrieving discover bsscfg index failed\n");
  487. return ret;
  488. }
  489. /*
  490. * need brcmf_if for setting the discovery state.
  491. */
  492. ifp = kzalloc(sizeof(*vif->ifp), GFP_KERNEL);
  493. if (!ifp) {
  494. brcmf_err("could not create discovery if\n");
  495. return -ENOMEM;
  496. }
  497. /* set required fields */
  498. ifp->drvr = p2p->cfg->pub;
  499. ifp->ifidx = 0;
  500. ifp->bssidx = index;
  501. /* Set the initial discovery state to SCAN */
  502. ret = brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
  503. if (ret != 0) {
  504. brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
  505. (void)brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 0);
  506. kfree(ifp);
  507. return ret;
  508. }
  509. /* create a vif for it */
  510. vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE, false);
  511. if (IS_ERR(vif)) {
  512. brcmf_err("could not create discovery vif\n");
  513. kfree(ifp);
  514. return PTR_ERR(vif);
  515. }
  516. vif->ifp = ifp;
  517. ifp->vif = vif;
  518. bss_dev->vif = vif;
  519. return 0;
  520. }
  521. /**
  522. * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
  523. *
  524. * @p2p: P2P specific data.
  525. *
  526. * Resets the discovery state and disables it in firmware. The virtual
  527. * interface and P2P device are freed.
  528. */
  529. static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
  530. {
  531. struct net_device *ndev = cfg_to_ndev(p2p->cfg);
  532. struct brcmf_if *ifp;
  533. struct p2p_bss *bss_dev;
  534. brcmf_dbg(TRACE, "enter\n");
  535. bss_dev = &p2p->bss_idx[P2PAPI_BSSCFG_DEVICE];
  536. ifp = bss_dev->vif->ifp;
  537. /* Set the discovery state to SCAN */
  538. (void)brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
  539. /* Disable P2P discovery in the firmware */
  540. (void)brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 0);
  541. /* remove discovery interface */
  542. brcmf_free_vif(bss_dev->vif);
  543. bss_dev->vif = NULL;
  544. kfree(ifp);
  545. return 0;
  546. }
  547. /**
  548. * brcmf_p2p_enable_discovery() - initialize and configure discovery.
  549. *
  550. * @p2p: P2P specific data.
  551. *
  552. * Initializes the discovery device and configure the virtual interface.
  553. */
  554. static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
  555. {
  556. struct brcmf_cfg80211_vif *vif;
  557. s32 ret = 0;
  558. brcmf_dbg(TRACE, "enter\n");
  559. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  560. if (vif) {
  561. brcmf_dbg(INFO, "DISCOVERY init already done\n");
  562. goto exit;
  563. }
  564. ret = brcmf_p2p_init_discovery(p2p);
  565. if (ret < 0) {
  566. brcmf_err("init discovery error %d\n", ret);
  567. goto exit;
  568. }
  569. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  570. /*
  571. * Set wsec to any non-zero value in the discovery bsscfg
  572. * to ensure our P2P probe responses have the privacy bit
  573. * set in the 802.11 WPA IE. Some peer devices may not
  574. * initiate WPS with us if this bit is not set.
  575. */
  576. ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
  577. if (ret < 0)
  578. brcmf_err("wsec error %d\n", ret);
  579. exit:
  580. return ret;
  581. }
  582. /**
  583. * brcmf_p2p_escan() - initiate a P2P scan.
  584. *
  585. * @p2p: P2P specific data.
  586. * @num_chans: number of channels to scan.
  587. * @chanspecs: channel parameters for @num_chans channels.
  588. * @search_state: P2P discover state to use.
  589. * @action: scan action to pass to firmware.
  590. * @bss_type: type of P2P bss.
  591. */
  592. static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
  593. u16 chanspecs[], s32 search_state, u16 action,
  594. enum p2p_bss_type bss_type)
  595. {
  596. s32 ret = 0;
  597. s32 memsize = offsetof(struct brcmf_p2p_scan_le,
  598. eparams.params_le.channel_list);
  599. s32 nprobes;
  600. s32 active;
  601. u32 i;
  602. u8 *memblk;
  603. struct brcmf_cfg80211_vif *vif;
  604. struct brcmf_p2p_scan_le *p2p_params;
  605. struct brcmf_scan_params_le *sparams;
  606. struct brcmf_ssid ssid;
  607. memsize += num_chans * sizeof(__le16);
  608. memblk = kzalloc(memsize, GFP_KERNEL);
  609. if (!memblk)
  610. return -ENOMEM;
  611. vif = p2p->bss_idx[bss_type].vif;
  612. if (vif == NULL) {
  613. brcmf_err("no vif for bss type %d\n", bss_type);
  614. ret = -EINVAL;
  615. goto exit;
  616. }
  617. switch (search_state) {
  618. case WL_P2P_DISC_ST_SEARCH:
  619. /*
  620. * If we in SEARCH STATE, we don't need to set SSID explictly
  621. * because dongle use P2P WILDCARD internally by default
  622. */
  623. /* use null ssid */
  624. ssid.SSID_len = 0;
  625. memset(ssid.SSID, 0, sizeof(ssid.SSID));
  626. break;
  627. case WL_P2P_DISC_ST_SCAN:
  628. /*
  629. * wpa_supplicant has p2p_find command with type social or
  630. * progressive. For progressive, we need to set the ssid to
  631. * P2P WILDCARD because we just do broadcast scan unless
  632. * setting SSID.
  633. */
  634. ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
  635. memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
  636. break;
  637. default:
  638. brcmf_err(" invalid search state %d\n", search_state);
  639. ret = -EINVAL;
  640. goto exit;
  641. }
  642. brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
  643. /*
  644. * set p2p scan parameters.
  645. */
  646. p2p_params = (struct brcmf_p2p_scan_le *)memblk;
  647. p2p_params->type = 'E';
  648. /* determine the scan engine parameters */
  649. sparams = &p2p_params->eparams.params_le;
  650. sparams->bss_type = DOT11_BSSTYPE_ANY;
  651. if (p2p->cfg->active_scan)
  652. sparams->scan_type = 0;
  653. else
  654. sparams->scan_type = 1;
  655. memset(&sparams->bssid, 0xFF, ETH_ALEN);
  656. if (ssid.SSID_len)
  657. memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
  658. sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
  659. sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
  660. /*
  661. * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
  662. * supported by the supplicant.
  663. */
  664. if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
  665. active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
  666. else if (num_chans == AF_PEER_SEARCH_CNT)
  667. active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
  668. else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
  669. active = -1;
  670. else
  671. active = P2PAPI_SCAN_DWELL_TIME_MS;
  672. /* Override scan params to find a peer for a connection */
  673. if (num_chans == 1) {
  674. active = WL_SCAN_CONNECT_DWELL_TIME_MS;
  675. /* WAR to sync with presence period of VSDB GO.
  676. * send probe request more frequently
  677. */
  678. nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
  679. } else {
  680. nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
  681. }
  682. if (nprobes <= 0)
  683. nprobes = 1;
  684. brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
  685. sparams->active_time = cpu_to_le32(active);
  686. sparams->nprobes = cpu_to_le32(nprobes);
  687. sparams->passive_time = cpu_to_le32(-1);
  688. sparams->channel_num = cpu_to_le32(num_chans &
  689. BRCMF_SCAN_PARAMS_COUNT_MASK);
  690. for (i = 0; i < num_chans; i++)
  691. sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
  692. /* set the escan specific parameters */
  693. p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
  694. p2p_params->eparams.action = cpu_to_le16(action);
  695. p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
  696. /* perform p2p scan on primary device */
  697. ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
  698. if (!ret)
  699. set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
  700. exit:
  701. kfree(memblk);
  702. return ret;
  703. }
  704. /**
  705. * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
  706. *
  707. * @cfg: driver private data for cfg80211 interface.
  708. * @ndev: net device for which scan is requested.
  709. * @request: scan request from cfg80211.
  710. * @action: scan action.
  711. *
  712. * Determines the P2P discovery state based to scan request parameters and
  713. * validates the channels in the request.
  714. */
  715. static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
  716. struct net_device *ndev,
  717. struct cfg80211_scan_request *request,
  718. u16 action)
  719. {
  720. struct brcmf_p2p_info *p2p = &cfg->p2p;
  721. s32 err = 0;
  722. s32 search_state = WL_P2P_DISC_ST_SCAN;
  723. struct brcmf_cfg80211_vif *vif;
  724. struct net_device *dev = NULL;
  725. int i, num_nodfs = 0;
  726. u16 *chanspecs;
  727. brcmf_dbg(TRACE, "enter\n");
  728. if (!request) {
  729. err = -EINVAL;
  730. goto exit;
  731. }
  732. if (request->n_channels) {
  733. chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
  734. GFP_KERNEL);
  735. if (!chanspecs) {
  736. err = -ENOMEM;
  737. goto exit;
  738. }
  739. vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
  740. if (vif)
  741. dev = vif->wdev.netdev;
  742. if (request->n_channels == 3 &&
  743. request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
  744. request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
  745. request->channels[2]->hw_value == SOCIAL_CHAN_3) {
  746. /* SOCIAL CHANNELS 1, 6, 11 */
  747. search_state = WL_P2P_DISC_ST_SEARCH;
  748. brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
  749. } else if (dev != NULL && vif->mode == WL_MODE_AP) {
  750. /* If you are already a GO, then do SEARCH only */
  751. brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
  752. search_state = WL_P2P_DISC_ST_SEARCH;
  753. } else {
  754. brcmf_dbg(INFO, "P2P SCAN STATE START\n");
  755. }
  756. /*
  757. * no P2P scanning on passive or DFS channels.
  758. */
  759. for (i = 0; i < request->n_channels; i++) {
  760. struct ieee80211_channel *chan = request->channels[i];
  761. if (chan->flags & (IEEE80211_CHAN_RADAR |
  762. IEEE80211_CHAN_PASSIVE_SCAN))
  763. continue;
  764. chanspecs[i] = channel_to_chanspec(chan);
  765. brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
  766. num_nodfs, chan->hw_value, chanspecs[i]);
  767. num_nodfs++;
  768. }
  769. err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
  770. action, P2PAPI_BSSCFG_DEVICE);
  771. }
  772. exit:
  773. if (err)
  774. brcmf_err("error (%d)\n", err);
  775. return err;
  776. }
  777. /**
  778. * brcmf_p2p_scan_prep() - prepare scan based on request.
  779. *
  780. * @wiphy: wiphy device.
  781. * @request: scan request from cfg80211.
  782. * @vif: vif on which scan request is to be executed.
  783. *
  784. * Prepare the scan appropriately for type of scan requested. Overrides the
  785. * escan .run() callback for peer-to-peer scanning.
  786. */
  787. int brcmf_p2p_scan_prep(struct wiphy *wiphy,
  788. struct cfg80211_scan_request *request,
  789. struct brcmf_cfg80211_vif *vif)
  790. {
  791. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  792. struct brcmf_p2p_info *p2p = &cfg->p2p;
  793. int err = 0;
  794. if (brcmf_p2p_scan_is_p2p_request(request)) {
  795. /* find my listen channel */
  796. err = cfg80211_get_p2p_attr(request->ie, request->ie_len,
  797. IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
  798. &p2p->listen_channel, 1);
  799. if (err < 0)
  800. return err;
  801. clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
  802. brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
  803. err = brcmf_p2p_enable_discovery(p2p);
  804. if (err)
  805. return err;
  806. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  807. /* override .run_escan() callback. */
  808. cfg->escan_info.run = brcmf_p2p_run_escan;
  809. }
  810. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
  811. request->ie, request->ie_len);
  812. return err;
  813. }
  814. /**
  815. * brcmf_p2p_discover_listen() - set firmware to discover listen state.
  816. *
  817. * @p2p: p2p device.
  818. * @freq: center frequency for discover listen.
  819. * #@duration: time in ms to stay on channel.
  820. *
  821. */
  822. static s32
  823. brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p,
  824. struct ieee80211_channel *channel, u32 duration)
  825. {
  826. struct brcmf_cfg80211_vif *vif;
  827. s32 err = 0;
  828. u16 chanspec;
  829. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  830. if (!vif) {
  831. brcmf_err("Discovery is not set, so we have nothing to do\n");
  832. err = -EPERM;
  833. goto exit;
  834. }
  835. if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
  836. brcmf_err("Previous LISTEN is not completed yet\n");
  837. /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
  838. goto exit;
  839. }
  840. chanspec = channel_to_chanspec(channel);
  841. err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
  842. chanspec, (u16)duration);
  843. if (!err) {
  844. set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
  845. p2p->remain_on_channel_cookie++;
  846. }
  847. exit:
  848. return err;
  849. }
  850. /**
  851. * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
  852. *
  853. * @wiphy: wiphy device.
  854. * @channel: channel to stay on.
  855. * @duration: time in ms to remain on channel.
  856. *
  857. */
  858. int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
  859. struct ieee80211_channel *channel,
  860. unsigned int duration, u64 *cookie)
  861. {
  862. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  863. struct brcmf_p2p_info *p2p = &cfg->p2p;
  864. s32 err;
  865. brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n",
  866. ieee80211_frequency_to_channel(channel->center_freq),
  867. duration);
  868. err = brcmf_p2p_enable_discovery(p2p);
  869. if (err)
  870. goto exit;
  871. err = brcmf_p2p_discover_listen(p2p, channel, duration);
  872. if (err)
  873. goto exit;
  874. memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
  875. *cookie = p2p->remain_on_channel_cookie;
  876. cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
  877. exit:
  878. return err;
  879. }
  880. /**
  881. * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
  882. *
  883. * @ifp: interfac control.
  884. * @e: event message. Not used, to make it usable for fweh event dispatcher.
  885. * @data: payload of message. Not used.
  886. *
  887. */
  888. int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
  889. const struct brcmf_event_msg *e,
  890. void *data)
  891. {
  892. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  893. struct brcmf_p2p_info *p2p = &cfg->p2p;
  894. brcmf_dbg(TRACE, "Enter\n");
  895. if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
  896. &p2p->status))
  897. cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
  898. p2p->remain_on_channel_cookie,
  899. &p2p->remain_on_channel,
  900. GFP_KERNEL);
  901. return 0;
  902. }
  903. /**
  904. * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
  905. *
  906. * @ifp: interfac control.
  907. *
  908. */
  909. void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
  910. {
  911. if (!ifp)
  912. return;
  913. brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
  914. brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
  915. }
  916. /**
  917. * brcmf_p2p_notify_action_frame_rx() - received action frame.
  918. *
  919. * @ifp: interfac control.
  920. * @e: event message. Not used, to make it usable for fweh event dispatcher.
  921. * @data: payload of message, containing action frame data.
  922. *
  923. */
  924. int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
  925. const struct brcmf_event_msg *e,
  926. void *data)
  927. {
  928. struct wireless_dev *wdev;
  929. u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
  930. struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
  931. u16 chanspec = be16_to_cpu(rxframe->chanspec);
  932. struct ieee80211_mgmt *mgmt_frame;
  933. s32 err;
  934. s32 freq;
  935. u16 mgmt_type;
  936. /* Check if wpa_supplicant has registered for this frame */
  937. brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
  938. mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
  939. if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
  940. return 0;
  941. brcmf_p2p_print_actframe(false, (u8 *)(rxframe + 1), mgmt_frame_len);
  942. mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
  943. mgmt_frame_len, GFP_KERNEL);
  944. if (!mgmt_frame) {
  945. brcmf_err("No memory available for action frame\n");
  946. return -ENOMEM;
  947. }
  948. memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
  949. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
  950. ETH_ALEN);
  951. if (err < 0)
  952. brcmf_err("BRCMF_C_GET_BSSID error %d\n", err);
  953. memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
  954. mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
  955. memcpy(&mgmt_frame->u, (u8 *)(rxframe + 1), mgmt_frame_len);
  956. mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
  957. freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
  958. CHSPEC_IS2G(chanspec) ?
  959. IEEE80211_BAND_2GHZ :
  960. IEEE80211_BAND_5GHZ);
  961. wdev = ifp->ndev->ieee80211_ptr;
  962. cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
  963. GFP_ATOMIC);
  964. kfree(mgmt_frame);
  965. return 0;
  966. }
  967. /**
  968. * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
  969. *
  970. * @ifp: interfac control.
  971. * @e: event message. Not used, to make it usable for fweh event dispatcher.
  972. * @data: not used.
  973. *
  974. */
  975. int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
  976. const struct brcmf_event_msg *e,
  977. void *data)
  978. {
  979. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  980. struct brcmf_p2p_info *p2p = &cfg->p2p;
  981. brcmf_dbg(INFO, "Enter: status %d\n", e->status);
  982. if (e->status == BRCMF_E_STATUS_SUCCESS)
  983. set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  984. else
  985. set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
  986. /* for now complete the receiver process here !! */
  987. complete(&p2p->send_af_done);
  988. return 0;
  989. }
  990. /**
  991. * brcmf_p2p_tx_action_frame() - send action frame over fil.
  992. *
  993. * @p2p: p2p info struct for vif.
  994. * @af_params: action frame data/info.
  995. *
  996. * Send an action frame immediately without doing channel synchronization.
  997. *
  998. * This function waits for a completion event before returning.
  999. * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
  1000. * frame is transmitted.
  1001. */
  1002. static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
  1003. struct brcmf_fil_af_params_le *af_params)
  1004. {
  1005. struct brcmf_cfg80211_vif *vif;
  1006. s32 err = 0;
  1007. s32 timeout = 0;
  1008. brcmf_dbg(TRACE, "Enter\n");
  1009. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  1010. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
  1011. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  1012. err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
  1013. sizeof(*af_params));
  1014. if (err) {
  1015. brcmf_err(" sending action frame has failed\n");
  1016. goto exit;
  1017. }
  1018. timeout = wait_for_completion_timeout(&p2p->send_af_done,
  1019. msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
  1020. if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
  1021. brcmf_dbg(TRACE, "TX action frame operation is success\n");
  1022. } else {
  1023. err = -EIO;
  1024. brcmf_dbg(TRACE, "TX action frame operation has failed\n");
  1025. }
  1026. /* clear status bit for action tx */
  1027. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  1028. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
  1029. exit:
  1030. return err;
  1031. }
  1032. /**
  1033. * brcmf_p2p_pub_af_tx() - public action frame tx routine.
  1034. *
  1035. * @cfg: driver private data for cfg80211 interface.
  1036. * @af_params: action frame data/info.
  1037. * @config_af_params: configuration data for action frame.
  1038. *
  1039. * routine which transmits ation frame public type.
  1040. */
  1041. static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
  1042. struct brcmf_fil_af_params_le *af_params,
  1043. struct brcmf_config_af_params *config_af_params)
  1044. {
  1045. struct brcmf_p2p_info *p2p = &cfg->p2p;
  1046. struct brcmf_fil_action_frame_le *action_frame;
  1047. struct brcmf_p2p_pub_act_frame *act_frm;
  1048. s32 err = 0;
  1049. action_frame = &af_params->action_frame;
  1050. act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
  1051. switch (act_frm->subtype) {
  1052. case P2P_PAF_GON_REQ:
  1053. brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
  1054. set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
  1055. config_af_params->mpc_onoff = 0;
  1056. p2p->next_af_subtype = act_frm->subtype + 1;
  1057. /* increase dwell time to wait for RESP frame */
  1058. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1059. break;
  1060. case P2P_PAF_GON_RSP:
  1061. p2p->next_af_subtype = act_frm->subtype + 1;
  1062. /* increase dwell time to wait for CONF frame */
  1063. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1064. break;
  1065. case P2P_PAF_GON_CONF:
  1066. /* If we reached till GO Neg confirmation reset the filter */
  1067. brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
  1068. clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
  1069. /* turn on mpc again if go nego is done */
  1070. config_af_params->mpc_onoff = 1;
  1071. /* minimize dwell time */
  1072. af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1073. break;
  1074. case P2P_PAF_INVITE_REQ:
  1075. p2p->next_af_subtype = act_frm->subtype + 1;
  1076. /* increase dwell time */
  1077. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1078. break;
  1079. case P2P_PAF_INVITE_RSP:
  1080. /* minimize dwell time */
  1081. af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1082. break;
  1083. case P2P_PAF_DEVDIS_REQ:
  1084. p2p->next_af_subtype = act_frm->subtype + 1;
  1085. /* maximize dwell time to wait for RESP frame */
  1086. af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
  1087. break;
  1088. case P2P_PAF_DEVDIS_RSP:
  1089. /* minimize dwell time */
  1090. af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1091. break;
  1092. case P2P_PAF_PROVDIS_REQ:
  1093. config_af_params->mpc_onoff = 0;
  1094. p2p->next_af_subtype = act_frm->subtype + 1;
  1095. /* increase dwell time to wait for RESP frame */
  1096. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1097. break;
  1098. case P2P_PAF_PROVDIS_RSP:
  1099. /* wpa_supplicant send go nego req right after prov disc */
  1100. p2p->next_af_subtype = P2P_PAF_GON_REQ;
  1101. /* increase dwell time to MED level */
  1102. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1103. break;
  1104. default:
  1105. brcmf_err("Unknown p2p pub act frame subtype: %d\n",
  1106. act_frm->subtype);
  1107. err = -EINVAL;
  1108. }
  1109. return err;
  1110. }
  1111. /**
  1112. * brcmf_p2p_send_action_frame() - send action frame .
  1113. *
  1114. * @cfg: driver private data for cfg80211 interface.
  1115. * @ndev: net device to transmit on.
  1116. * @af_params: configuration data for action frame.
  1117. */
  1118. bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
  1119. struct net_device *ndev,
  1120. struct brcmf_fil_af_params_le *af_params)
  1121. {
  1122. struct brcmf_p2p_info *p2p = &cfg->p2p;
  1123. struct brcmf_fil_action_frame_le *action_frame;
  1124. struct brcmf_config_af_params config_af_params;
  1125. u16 action_frame_len;
  1126. bool ack = false;
  1127. u8 category;
  1128. u8 action;
  1129. s32 tx_retry;
  1130. action_frame = &af_params->action_frame;
  1131. action_frame_len = le16_to_cpu(action_frame->len);
  1132. brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
  1133. /* Add the default dwell time. Dwell time to stay off-channel */
  1134. /* to wait for a response action frame after transmitting an */
  1135. /* GO Negotiation action frame */
  1136. af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
  1137. category = action_frame->data[DOT11_ACTION_CAT_OFF];
  1138. action = action_frame->data[DOT11_ACTION_ACT_OFF];
  1139. /* initialize variables */
  1140. p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
  1141. /* config parameters */
  1142. config_af_params.max_tx_retry = P2P_AF_TX_MAX_RETRY;
  1143. config_af_params.mpc_onoff = -1;
  1144. if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
  1145. /* p2p public action frame process */
  1146. if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
  1147. /* Just send unknown subtype frame with */
  1148. /* default parameters. */
  1149. brcmf_err("P2P Public action frame, unknown subtype.\n");
  1150. }
  1151. } else if (brcmf_p2p_is_gas_action(action_frame->data,
  1152. action_frame_len)) {
  1153. /* service discovery process */
  1154. if (action == P2PSD_ACTION_ID_GAS_IREQ ||
  1155. action == P2PSD_ACTION_ID_GAS_CREQ) {
  1156. /* save next af suptype to cancel */
  1157. /* remaining dwell time */
  1158. p2p->next_af_subtype = action + 1;
  1159. af_params->dwell_time =
  1160. cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1161. } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
  1162. action == P2PSD_ACTION_ID_GAS_CRESP) {
  1163. /* configure service discovery response frame */
  1164. af_params->dwell_time =
  1165. cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1166. } else {
  1167. brcmf_err("Unknown action type: %d\n", action);
  1168. goto exit;
  1169. }
  1170. } else if (brcmf_p2p_is_p2p_action(action_frame->data,
  1171. action_frame_len)) {
  1172. /* do not configure anything. it will be */
  1173. /* sent with a default configuration */
  1174. } else {
  1175. brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
  1176. category, action);
  1177. return false;
  1178. }
  1179. /* if scan is ongoing, abort current scan. */
  1180. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
  1181. brcmf_abort_scanning(cfg);
  1182. /* To make sure to send successfully action frame, turn off mpc */
  1183. if (config_af_params.mpc_onoff == 0)
  1184. brcmf_set_mpc(ndev, 0);
  1185. /* if failed, retry it. tx_retry_max value is configure by .... */
  1186. tx_retry = 0;
  1187. while ((ack == false) && (tx_retry < config_af_params.max_tx_retry)) {
  1188. ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
  1189. tx_retry++;
  1190. }
  1191. if (ack == false)
  1192. brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
  1193. exit:
  1194. /* if all done, turn mpc on again */
  1195. if (config_af_params.mpc_onoff == 1)
  1196. brcmf_set_mpc(ndev, 1);
  1197. return ack;
  1198. }
  1199. /**
  1200. * brcmf_p2p_attach() - attach for P2P.
  1201. *
  1202. * @cfg: driver private data for cfg80211 interface.
  1203. */
  1204. void brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg,
  1205. struct brcmf_cfg80211_vif *vif)
  1206. {
  1207. struct brcmf_p2p_info *p2p;
  1208. p2p = &cfg->p2p;
  1209. p2p->cfg = cfg;
  1210. p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = vif;
  1211. brcmf_p2p_generate_bss_mac(p2p);
  1212. brcmf_p2p_set_firmware(p2p);
  1213. init_completion(&p2p->send_af_done);
  1214. }
  1215. /**
  1216. * brcmf_p2p_detach() - detach P2P.
  1217. *
  1218. * @p2p: P2P specific data.
  1219. */
  1220. void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
  1221. {
  1222. if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif != NULL) {
  1223. brcmf_p2p_cancel_remain_on_channel(
  1224. p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp);
  1225. brcmf_p2p_deinit_discovery(p2p);
  1226. }
  1227. /* just set it all to zero */
  1228. memset(p2p, 0, sizeof(*p2p));
  1229. }
  1230. /**
  1231. * brcmf_p2p_get_current_chanspec() - Get current operation channel.
  1232. *
  1233. * @p2p: P2P specific data.
  1234. * @chanspec: chanspec to be returned.
  1235. */
  1236. static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
  1237. u16 *chanspec)
  1238. {
  1239. struct brcmf_if *ifp;
  1240. struct brcmf_fil_chan_info_le ci;
  1241. s32 err;
  1242. ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
  1243. *chanspec = 11 & WL_CHANSPEC_CHAN_MASK;
  1244. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_CHANNEL, &ci, sizeof(ci));
  1245. if (!err) {
  1246. *chanspec = le32_to_cpu(ci.hw_channel) & WL_CHANSPEC_CHAN_MASK;
  1247. if (*chanspec < CH_MAX_2G_CHANNEL)
  1248. *chanspec |= WL_CHANSPEC_BAND_2G;
  1249. else
  1250. *chanspec |= WL_CHANSPEC_BAND_5G;
  1251. }
  1252. *chanspec |= WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
  1253. }
  1254. /**
  1255. * Change a P2P Role.
  1256. * Parameters:
  1257. * @mac: MAC address of the BSS to change a role
  1258. * Returns 0 if success.
  1259. */
  1260. int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
  1261. enum brcmf_fil_p2p_if_types if_type)
  1262. {
  1263. struct brcmf_p2p_info *p2p = &cfg->p2p;
  1264. struct brcmf_cfg80211_vif *vif;
  1265. struct brcmf_fil_p2p_if_le if_request;
  1266. s32 err;
  1267. u16 chanspec;
  1268. brcmf_dbg(TRACE, "Enter\n");
  1269. vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
  1270. if (!vif) {
  1271. brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
  1272. return -EPERM;
  1273. }
  1274. brcmf_notify_escan_complete(cfg, vif->ifp->ndev, true, true);
  1275. vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
  1276. if (!vif) {
  1277. brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
  1278. return -EPERM;
  1279. }
  1280. brcmf_set_mpc(vif->ifp->ndev, 0);
  1281. /* In concurrency case, STA may be already associated in a particular */
  1282. /* channel. so retrieve the current channel of primary interface and */
  1283. /* then start the virtual interface on that. */
  1284. brcmf_p2p_get_current_chanspec(p2p, &chanspec);
  1285. if_request.type = cpu_to_le16((u16)if_type);
  1286. if_request.chspec = cpu_to_le16(chanspec);
  1287. memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
  1288. brcmf_cfg80211_arm_vif_event(cfg, vif);
  1289. err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
  1290. sizeof(if_request));
  1291. if (err) {
  1292. brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
  1293. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  1294. return err;
  1295. }
  1296. err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
  1297. msecs_to_jiffies(1500));
  1298. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  1299. if (!err) {
  1300. brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
  1301. return -EIO;
  1302. }
  1303. err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
  1304. BRCMF_SCB_TIMEOUT_VALUE);
  1305. return err;
  1306. }
  1307. static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
  1308. struct brcmf_if *ifp, u8 ea[ETH_ALEN],
  1309. enum brcmf_fil_p2p_if_types iftype)
  1310. {
  1311. struct brcmf_fil_p2p_if_le if_request;
  1312. int err;
  1313. u16 chanspec;
  1314. /* we need a default channel */
  1315. brcmf_p2p_get_current_chanspec(p2p, &chanspec);
  1316. /* fill the firmware request */
  1317. memcpy(if_request.addr, ea, ETH_ALEN);
  1318. if_request.type = cpu_to_le16((u16)iftype);
  1319. if_request.chspec = cpu_to_le16(chanspec);
  1320. err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
  1321. sizeof(if_request));
  1322. if (err)
  1323. return err;
  1324. return err;
  1325. }
  1326. static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
  1327. {
  1328. struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
  1329. struct net_device *pri_ndev = cfg_to_ndev(cfg);
  1330. struct brcmf_if *ifp = netdev_priv(pri_ndev);
  1331. u8 *addr = vif->wdev.netdev->dev_addr;
  1332. return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
  1333. }
  1334. static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
  1335. {
  1336. struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
  1337. struct net_device *pri_ndev = cfg_to_ndev(cfg);
  1338. struct brcmf_if *ifp = netdev_priv(pri_ndev);
  1339. u8 *addr = vif->wdev.netdev->dev_addr;
  1340. return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
  1341. }
  1342. /**
  1343. * brcmf_p2p_add_vif() - create a new P2P virtual interface.
  1344. *
  1345. * @wiphy: wiphy device of new interface.
  1346. * @name: name of the new interface.
  1347. * @type: nl80211 interface type.
  1348. * @flags: TBD
  1349. * @params: TBD
  1350. */
  1351. struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
  1352. enum nl80211_iftype type, u32 *flags,
  1353. struct vif_params *params)
  1354. {
  1355. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1356. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  1357. struct brcmf_cfg80211_vif *vif;
  1358. enum brcmf_fil_p2p_if_types iftype;
  1359. enum wl_mode mode;
  1360. int err;
  1361. if (brcmf_cfg80211_vif_event_armed(cfg))
  1362. return ERR_PTR(-EBUSY);
  1363. brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
  1364. switch (type) {
  1365. case NL80211_IFTYPE_P2P_CLIENT:
  1366. iftype = BRCMF_FIL_P2P_IF_CLIENT;
  1367. mode = WL_MODE_BSS;
  1368. break;
  1369. case NL80211_IFTYPE_P2P_GO:
  1370. iftype = BRCMF_FIL_P2P_IF_GO;
  1371. mode = WL_MODE_AP;
  1372. break;
  1373. default:
  1374. return ERR_PTR(-EOPNOTSUPP);
  1375. }
  1376. vif = brcmf_alloc_vif(cfg, type, false);
  1377. if (IS_ERR(vif))
  1378. return (struct wireless_dev *)vif;
  1379. brcmf_cfg80211_arm_vif_event(cfg, vif);
  1380. err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
  1381. iftype);
  1382. if (err) {
  1383. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  1384. goto fail;
  1385. }
  1386. /* wait for firmware event */
  1387. err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
  1388. msecs_to_jiffies(1500));
  1389. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  1390. if (!err) {
  1391. brcmf_err("timeout occurred\n");
  1392. err = -EIO;
  1393. goto fail;
  1394. }
  1395. /* interface created in firmware */
  1396. ifp = vif->ifp;
  1397. if (!ifp) {
  1398. brcmf_err("no if pointer provided\n");
  1399. err = -ENOENT;
  1400. goto fail;
  1401. }
  1402. strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
  1403. brcmf_cfg80211_vif_complete(cfg);
  1404. cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
  1405. /* Disable firmware roaming for P2P interface */
  1406. brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
  1407. if (iftype == BRCMF_FIL_P2P_IF_GO) {
  1408. /* set station timeout for p2p */
  1409. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
  1410. BRCMF_SCB_TIMEOUT_VALUE);
  1411. }
  1412. return &ifp->vif->wdev;
  1413. fail:
  1414. brcmf_free_vif(vif);
  1415. return ERR_PTR(err);
  1416. }
  1417. /**
  1418. * brcmf_p2p_del_vif() - delete a P2P virtual interface.
  1419. *
  1420. * @wiphy: wiphy device of interface.
  1421. * @wdev: wireless device of interface.
  1422. *
  1423. * TODO: not yet supported.
  1424. */
  1425. int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
  1426. {
  1427. struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
  1428. struct brcmf_cfg80211_vif *vif;
  1429. unsigned long jiffie_timeout = msecs_to_jiffies(1500);
  1430. bool wait_for_disable = false;
  1431. int err;
  1432. brcmf_dbg(TRACE, "delete P2P vif\n");
  1433. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  1434. switch (vif->wdev.iftype) {
  1435. case NL80211_IFTYPE_P2P_CLIENT:
  1436. if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
  1437. wait_for_disable = true;
  1438. break;
  1439. case NL80211_IFTYPE_P2P_GO:
  1440. if (!brcmf_p2p_disable_p2p_if(vif))
  1441. wait_for_disable = true;
  1442. break;
  1443. case NL80211_IFTYPE_P2P_DEVICE:
  1444. default:
  1445. return -ENOTSUPP;
  1446. break;
  1447. }
  1448. if (wait_for_disable)
  1449. wait_for_completion_timeout(&cfg->vif_disabled,
  1450. msecs_to_jiffies(500));
  1451. brcmf_vif_clear_mgmt_ies(vif);
  1452. brcmf_cfg80211_arm_vif_event(cfg, vif);
  1453. err = brcmf_p2p_release_p2p_if(vif);
  1454. if (!err) {
  1455. /* wait for firmware event */
  1456. err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
  1457. jiffie_timeout);
  1458. if (!err)
  1459. err = -EIO;
  1460. else
  1461. err = 0;
  1462. }
  1463. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  1464. brcmf_free_vif(vif);
  1465. cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;
  1466. return err;
  1467. }