p2p.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  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. #ifdef DEBUG
  269. static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
  270. {
  271. struct brcmf_p2p_pub_act_frame *pact_frm;
  272. struct brcmf_p2p_action_frame *act_frm;
  273. struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
  274. if (!frame || frame_len <= 2)
  275. return;
  276. if (brcmf_p2p_is_pub_action(frame, frame_len)) {
  277. pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
  278. switch (pact_frm->subtype) {
  279. case P2P_PAF_GON_REQ:
  280. brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
  281. (tx) ? "TX" : "RX");
  282. break;
  283. case P2P_PAF_GON_RSP:
  284. brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
  285. (tx) ? "TX" : "RX");
  286. break;
  287. case P2P_PAF_GON_CONF:
  288. brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
  289. (tx) ? "TX" : "RX");
  290. break;
  291. case P2P_PAF_INVITE_REQ:
  292. brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
  293. (tx) ? "TX" : "RX");
  294. break;
  295. case P2P_PAF_INVITE_RSP:
  296. brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
  297. (tx) ? "TX" : "RX");
  298. break;
  299. case P2P_PAF_DEVDIS_REQ:
  300. brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
  301. (tx) ? "TX" : "RX");
  302. break;
  303. case P2P_PAF_DEVDIS_RSP:
  304. brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
  305. (tx) ? "TX" : "RX");
  306. break;
  307. case P2P_PAF_PROVDIS_REQ:
  308. brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
  309. (tx) ? "TX" : "RX");
  310. break;
  311. case P2P_PAF_PROVDIS_RSP:
  312. brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
  313. (tx) ? "TX" : "RX");
  314. break;
  315. default:
  316. brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
  317. (tx) ? "TX" : "RX");
  318. break;
  319. }
  320. } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
  321. act_frm = (struct brcmf_p2p_action_frame *)frame;
  322. switch (act_frm->subtype) {
  323. case P2P_AF_NOTICE_OF_ABSENCE:
  324. brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
  325. (tx) ? "TX" : "RX");
  326. break;
  327. case P2P_AF_PRESENCE_REQ:
  328. brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
  329. (tx) ? "TX" : "RX");
  330. break;
  331. case P2P_AF_PRESENCE_RSP:
  332. brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
  333. (tx) ? "TX" : "RX");
  334. break;
  335. case P2P_AF_GO_DISC_REQ:
  336. brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
  337. (tx) ? "TX" : "RX");
  338. break;
  339. default:
  340. brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
  341. (tx) ? "TX" : "RX");
  342. }
  343. } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
  344. sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
  345. switch (sd_act_frm->action) {
  346. case P2PSD_ACTION_ID_GAS_IREQ:
  347. brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
  348. (tx) ? "TX" : "RX");
  349. break;
  350. case P2PSD_ACTION_ID_GAS_IRESP:
  351. brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
  352. (tx) ? "TX" : "RX");
  353. break;
  354. case P2PSD_ACTION_ID_GAS_CREQ:
  355. brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
  356. (tx) ? "TX" : "RX");
  357. break;
  358. case P2PSD_ACTION_ID_GAS_CRESP:
  359. brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
  360. (tx) ? "TX" : "RX");
  361. break;
  362. default:
  363. brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
  364. (tx) ? "TX" : "RX");
  365. break;
  366. }
  367. }
  368. }
  369. #else
  370. static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
  371. {
  372. }
  373. #endif
  374. /**
  375. * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
  376. *
  377. * @ifp: ifp to use for iovars (primary).
  378. * @p2p_mac: mac address to configure for p2p_da_override
  379. */
  380. static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
  381. {
  382. s32 ret = 0;
  383. brcmf_fil_iovar_int_set(ifp, "apsta", 1);
  384. /* In case of COB type, firmware has default mac address
  385. * After Initializing firmware, we have to set current mac address to
  386. * firmware for P2P device address
  387. */
  388. ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
  389. ETH_ALEN);
  390. if (ret)
  391. brcmf_err("failed to update device address ret %d\n", ret);
  392. return ret;
  393. }
  394. /**
  395. * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
  396. *
  397. * @p2p: P2P specific data.
  398. *
  399. * P2P needs mac addresses for P2P device and interface. These are
  400. * derived from the primary net device, ie. the permanent ethernet
  401. * address of the device.
  402. */
  403. static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
  404. {
  405. struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
  406. struct brcmf_if *p2p_ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
  407. /* Generate the P2P Device Address. This consists of the device's
  408. * primary MAC address with the locally administered bit set.
  409. */
  410. memcpy(p2p->dev_addr, pri_ifp->mac_addr, ETH_ALEN);
  411. p2p->dev_addr[0] |= 0x02;
  412. memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
  413. /* Generate the P2P Interface Address. If the discovery and connection
  414. * BSSCFGs need to simultaneously co-exist, then this address must be
  415. * different from the P2P Device Address, but also locally administered.
  416. */
  417. memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
  418. p2p->int_addr[4] ^= 0x80;
  419. }
  420. /**
  421. * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
  422. *
  423. * @request: the scan request as received from cfg80211.
  424. *
  425. * returns true if one of the ssids in the request matches the
  426. * P2P wildcard ssid; otherwise returns false.
  427. */
  428. static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
  429. {
  430. struct cfg80211_ssid *ssids = request->ssids;
  431. int i;
  432. for (i = 0; i < request->n_ssids; i++) {
  433. if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
  434. continue;
  435. brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
  436. if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
  437. BRCMF_P2P_WILDCARD_SSID_LEN))
  438. return true;
  439. }
  440. return false;
  441. }
  442. /**
  443. * brcmf_p2p_set_discover_state - set discover state in firmware.
  444. *
  445. * @ifp: low-level interface object.
  446. * @state: discover state to set.
  447. * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
  448. * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
  449. */
  450. static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
  451. u16 chanspec, u16 listen_ms)
  452. {
  453. struct brcmf_p2p_disc_st_le discover_state;
  454. s32 ret = 0;
  455. brcmf_dbg(TRACE, "enter\n");
  456. discover_state.state = state;
  457. discover_state.chspec = cpu_to_le16(chanspec);
  458. discover_state.dwell = cpu_to_le16(listen_ms);
  459. ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
  460. sizeof(discover_state));
  461. return ret;
  462. }
  463. /**
  464. * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
  465. *
  466. * @p2p: P2P specific data.
  467. *
  468. * Resets the discovery state and disables it in firmware.
  469. */
  470. static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
  471. {
  472. struct brcmf_cfg80211_vif *vif;
  473. brcmf_dbg(TRACE, "enter\n");
  474. /* Set the discovery state to SCAN */
  475. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  476. (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
  477. /* Disable P2P discovery in the firmware */
  478. vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
  479. (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
  480. return 0;
  481. }
  482. /**
  483. * brcmf_p2p_enable_discovery() - initialize and configure discovery.
  484. *
  485. * @p2p: P2P specific data.
  486. *
  487. * Initializes the discovery device and configure the virtual interface.
  488. */
  489. static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
  490. {
  491. struct brcmf_cfg80211_vif *vif;
  492. s32 ret = 0;
  493. brcmf_dbg(TRACE, "enter\n");
  494. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  495. if (!vif) {
  496. brcmf_err("P2P config device not available\n");
  497. ret = -EPERM;
  498. goto exit;
  499. }
  500. if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
  501. brcmf_dbg(INFO, "P2P config device already configured\n");
  502. goto exit;
  503. }
  504. /* Re-initialize P2P Discovery in the firmware */
  505. vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
  506. ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
  507. if (ret < 0) {
  508. brcmf_err("set p2p_disc error\n");
  509. goto exit;
  510. }
  511. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  512. ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
  513. if (ret < 0) {
  514. brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
  515. goto exit;
  516. }
  517. /*
  518. * Set wsec to any non-zero value in the discovery bsscfg
  519. * to ensure our P2P probe responses have the privacy bit
  520. * set in the 802.11 WPA IE. Some peer devices may not
  521. * initiate WPS with us if this bit is not set.
  522. */
  523. ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
  524. if (ret < 0) {
  525. brcmf_err("wsec error %d\n", ret);
  526. goto exit;
  527. }
  528. set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
  529. exit:
  530. return ret;
  531. }
  532. /**
  533. * brcmf_p2p_escan() - initiate a P2P scan.
  534. *
  535. * @p2p: P2P specific data.
  536. * @num_chans: number of channels to scan.
  537. * @chanspecs: channel parameters for @num_chans channels.
  538. * @search_state: P2P discover state to use.
  539. * @action: scan action to pass to firmware.
  540. * @bss_type: type of P2P bss.
  541. */
  542. static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
  543. u16 chanspecs[], s32 search_state, u16 action,
  544. enum p2p_bss_type bss_type)
  545. {
  546. s32 ret = 0;
  547. s32 memsize = offsetof(struct brcmf_p2p_scan_le,
  548. eparams.params_le.channel_list);
  549. s32 nprobes;
  550. s32 active;
  551. u32 i;
  552. u8 *memblk;
  553. struct brcmf_cfg80211_vif *vif;
  554. struct brcmf_p2p_scan_le *p2p_params;
  555. struct brcmf_scan_params_le *sparams;
  556. struct brcmf_ssid ssid;
  557. memsize += num_chans * sizeof(__le16);
  558. memblk = kzalloc(memsize, GFP_KERNEL);
  559. if (!memblk)
  560. return -ENOMEM;
  561. vif = p2p->bss_idx[bss_type].vif;
  562. if (vif == NULL) {
  563. brcmf_err("no vif for bss type %d\n", bss_type);
  564. ret = -EINVAL;
  565. goto exit;
  566. }
  567. switch (search_state) {
  568. case WL_P2P_DISC_ST_SEARCH:
  569. /*
  570. * If we in SEARCH STATE, we don't need to set SSID explictly
  571. * because dongle use P2P WILDCARD internally by default
  572. */
  573. /* use null ssid */
  574. ssid.SSID_len = 0;
  575. memset(ssid.SSID, 0, sizeof(ssid.SSID));
  576. break;
  577. case WL_P2P_DISC_ST_SCAN:
  578. /*
  579. * wpa_supplicant has p2p_find command with type social or
  580. * progressive. For progressive, we need to set the ssid to
  581. * P2P WILDCARD because we just do broadcast scan unless
  582. * setting SSID.
  583. */
  584. ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
  585. memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
  586. break;
  587. default:
  588. brcmf_err(" invalid search state %d\n", search_state);
  589. ret = -EINVAL;
  590. goto exit;
  591. }
  592. brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
  593. /*
  594. * set p2p scan parameters.
  595. */
  596. p2p_params = (struct brcmf_p2p_scan_le *)memblk;
  597. p2p_params->type = 'E';
  598. /* determine the scan engine parameters */
  599. sparams = &p2p_params->eparams.params_le;
  600. sparams->bss_type = DOT11_BSSTYPE_ANY;
  601. if (p2p->cfg->active_scan)
  602. sparams->scan_type = 0;
  603. else
  604. sparams->scan_type = 1;
  605. memset(&sparams->bssid, 0xFF, ETH_ALEN);
  606. if (ssid.SSID_len)
  607. memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
  608. sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
  609. sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
  610. /*
  611. * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
  612. * supported by the supplicant.
  613. */
  614. if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
  615. active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
  616. else if (num_chans == AF_PEER_SEARCH_CNT)
  617. active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
  618. else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
  619. active = -1;
  620. else
  621. active = P2PAPI_SCAN_DWELL_TIME_MS;
  622. /* Override scan params to find a peer for a connection */
  623. if (num_chans == 1) {
  624. active = WL_SCAN_CONNECT_DWELL_TIME_MS;
  625. /* WAR to sync with presence period of VSDB GO.
  626. * send probe request more frequently
  627. */
  628. nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
  629. } else {
  630. nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
  631. }
  632. if (nprobes <= 0)
  633. nprobes = 1;
  634. brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
  635. sparams->active_time = cpu_to_le32(active);
  636. sparams->nprobes = cpu_to_le32(nprobes);
  637. sparams->passive_time = cpu_to_le32(-1);
  638. sparams->channel_num = cpu_to_le32(num_chans &
  639. BRCMF_SCAN_PARAMS_COUNT_MASK);
  640. for (i = 0; i < num_chans; i++)
  641. sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
  642. /* set the escan specific parameters */
  643. p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
  644. p2p_params->eparams.action = cpu_to_le16(action);
  645. p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
  646. /* perform p2p scan on primary device */
  647. ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
  648. if (!ret)
  649. set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
  650. exit:
  651. kfree(memblk);
  652. return ret;
  653. }
  654. /**
  655. * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
  656. *
  657. * @cfg: driver private data for cfg80211 interface.
  658. * @ndev: net device for which scan is requested.
  659. * @request: scan request from cfg80211.
  660. * @action: scan action.
  661. *
  662. * Determines the P2P discovery state based to scan request parameters and
  663. * validates the channels in the request.
  664. */
  665. static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
  666. struct net_device *ndev,
  667. struct cfg80211_scan_request *request,
  668. u16 action)
  669. {
  670. struct brcmf_p2p_info *p2p = &cfg->p2p;
  671. s32 err = 0;
  672. s32 search_state = WL_P2P_DISC_ST_SCAN;
  673. struct brcmf_cfg80211_vif *vif;
  674. struct net_device *dev = NULL;
  675. int i, num_nodfs = 0;
  676. u16 *chanspecs;
  677. brcmf_dbg(TRACE, "enter\n");
  678. if (!request) {
  679. err = -EINVAL;
  680. goto exit;
  681. }
  682. if (request->n_channels) {
  683. chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
  684. GFP_KERNEL);
  685. if (!chanspecs) {
  686. err = -ENOMEM;
  687. goto exit;
  688. }
  689. vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
  690. if (vif)
  691. dev = vif->wdev.netdev;
  692. if (request->n_channels == 3 &&
  693. request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
  694. request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
  695. request->channels[2]->hw_value == SOCIAL_CHAN_3) {
  696. /* SOCIAL CHANNELS 1, 6, 11 */
  697. search_state = WL_P2P_DISC_ST_SEARCH;
  698. brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
  699. } else if (dev != NULL && vif->mode == WL_MODE_AP) {
  700. /* If you are already a GO, then do SEARCH only */
  701. brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
  702. search_state = WL_P2P_DISC_ST_SEARCH;
  703. } else {
  704. brcmf_dbg(INFO, "P2P SCAN STATE START\n");
  705. }
  706. /*
  707. * no P2P scanning on passive or DFS channels.
  708. */
  709. for (i = 0; i < request->n_channels; i++) {
  710. struct ieee80211_channel *chan = request->channels[i];
  711. if (chan->flags & (IEEE80211_CHAN_RADAR |
  712. IEEE80211_CHAN_PASSIVE_SCAN))
  713. continue;
  714. chanspecs[i] = channel_to_chanspec(chan);
  715. brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
  716. num_nodfs, chan->hw_value, chanspecs[i]);
  717. num_nodfs++;
  718. }
  719. err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
  720. action, P2PAPI_BSSCFG_DEVICE);
  721. }
  722. exit:
  723. if (err)
  724. brcmf_err("error (%d)\n", err);
  725. return err;
  726. }
  727. /**
  728. * brcmf_p2p_scan_prep() - prepare scan based on request.
  729. *
  730. * @wiphy: wiphy device.
  731. * @request: scan request from cfg80211.
  732. * @vif: vif on which scan request is to be executed.
  733. *
  734. * Prepare the scan appropriately for type of scan requested. Overrides the
  735. * escan .run() callback for peer-to-peer scanning.
  736. */
  737. int brcmf_p2p_scan_prep(struct wiphy *wiphy,
  738. struct cfg80211_scan_request *request,
  739. struct brcmf_cfg80211_vif *vif)
  740. {
  741. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  742. struct brcmf_p2p_info *p2p = &cfg->p2p;
  743. int err = 0;
  744. if (brcmf_p2p_scan_is_p2p_request(request)) {
  745. /* find my listen channel */
  746. err = cfg80211_get_p2p_attr(request->ie, request->ie_len,
  747. IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
  748. &p2p->listen_channel, 1);
  749. if (err < 0)
  750. return err;
  751. clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
  752. brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
  753. err = brcmf_p2p_enable_discovery(p2p);
  754. if (err)
  755. return err;
  756. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  757. /* override .run_escan() callback. */
  758. cfg->escan_info.run = brcmf_p2p_run_escan;
  759. }
  760. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
  761. request->ie, request->ie_len);
  762. return err;
  763. }
  764. /**
  765. * brcmf_p2p_discover_listen() - set firmware to discover listen state.
  766. *
  767. * @p2p: p2p device.
  768. * @freq: center frequency for discover listen.
  769. * #@duration: time in ms to stay on channel.
  770. *
  771. */
  772. static s32
  773. brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p,
  774. struct ieee80211_channel *channel, u32 duration)
  775. {
  776. struct brcmf_cfg80211_vif *vif;
  777. s32 err = 0;
  778. u16 chanspec;
  779. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  780. if (!vif) {
  781. brcmf_err("Discovery is not set, so we have nothing to do\n");
  782. err = -EPERM;
  783. goto exit;
  784. }
  785. if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
  786. brcmf_err("Previous LISTEN is not completed yet\n");
  787. /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
  788. goto exit;
  789. }
  790. chanspec = channel_to_chanspec(channel);
  791. err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
  792. chanspec, (u16)duration);
  793. if (!err) {
  794. set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
  795. p2p->remain_on_channel_cookie++;
  796. }
  797. exit:
  798. return err;
  799. }
  800. /**
  801. * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
  802. *
  803. * @wiphy: wiphy device.
  804. * @channel: channel to stay on.
  805. * @duration: time in ms to remain on channel.
  806. *
  807. */
  808. int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
  809. struct ieee80211_channel *channel,
  810. unsigned int duration, u64 *cookie)
  811. {
  812. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  813. struct brcmf_p2p_info *p2p = &cfg->p2p;
  814. s32 err;
  815. brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n",
  816. ieee80211_frequency_to_channel(channel->center_freq),
  817. duration);
  818. err = brcmf_p2p_enable_discovery(p2p);
  819. if (err)
  820. goto exit;
  821. err = brcmf_p2p_discover_listen(p2p, channel, duration);
  822. if (err)
  823. goto exit;
  824. memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
  825. *cookie = p2p->remain_on_channel_cookie;
  826. cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
  827. exit:
  828. return err;
  829. }
  830. /**
  831. * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
  832. *
  833. * @ifp: interfac control.
  834. * @e: event message. Not used, to make it usable for fweh event dispatcher.
  835. * @data: payload of message. Not used.
  836. *
  837. */
  838. int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
  839. const struct brcmf_event_msg *e,
  840. void *data)
  841. {
  842. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  843. struct brcmf_p2p_info *p2p = &cfg->p2p;
  844. brcmf_dbg(TRACE, "Enter\n");
  845. if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
  846. &p2p->status))
  847. cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
  848. p2p->remain_on_channel_cookie,
  849. &p2p->remain_on_channel,
  850. GFP_KERNEL);
  851. return 0;
  852. }
  853. /**
  854. * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
  855. *
  856. * @ifp: interfac control.
  857. *
  858. */
  859. void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
  860. {
  861. if (!ifp)
  862. return;
  863. brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
  864. brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
  865. }
  866. /**
  867. * brcmf_p2p_notify_action_frame_rx() - received action frame.
  868. *
  869. * @ifp: interfac control.
  870. * @e: event message. Not used, to make it usable for fweh event dispatcher.
  871. * @data: payload of message, containing action frame data.
  872. *
  873. */
  874. int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
  875. const struct brcmf_event_msg *e,
  876. void *data)
  877. {
  878. struct wireless_dev *wdev;
  879. u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
  880. struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
  881. u16 chanspec = be16_to_cpu(rxframe->chanspec);
  882. struct ieee80211_mgmt *mgmt_frame;
  883. s32 err;
  884. s32 freq;
  885. u16 mgmt_type;
  886. /* Check if wpa_supplicant has registered for this frame */
  887. brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
  888. mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
  889. if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
  890. return 0;
  891. brcmf_p2p_print_actframe(false, (u8 *)(rxframe + 1), mgmt_frame_len);
  892. mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
  893. mgmt_frame_len, GFP_KERNEL);
  894. if (!mgmt_frame) {
  895. brcmf_err("No memory available for action frame\n");
  896. return -ENOMEM;
  897. }
  898. memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
  899. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
  900. ETH_ALEN);
  901. if (err < 0)
  902. brcmf_err("BRCMF_C_GET_BSSID error %d\n", err);
  903. memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
  904. mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
  905. memcpy(&mgmt_frame->u, (u8 *)(rxframe + 1), mgmt_frame_len);
  906. mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
  907. freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
  908. CHSPEC_IS2G(chanspec) ?
  909. IEEE80211_BAND_2GHZ :
  910. IEEE80211_BAND_5GHZ);
  911. wdev = ifp->ndev->ieee80211_ptr;
  912. cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
  913. GFP_ATOMIC);
  914. kfree(mgmt_frame);
  915. return 0;
  916. }
  917. /**
  918. * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
  919. *
  920. * @ifp: interfac control.
  921. * @e: event message. Not used, to make it usable for fweh event dispatcher.
  922. * @data: not used.
  923. *
  924. */
  925. int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
  926. const struct brcmf_event_msg *e,
  927. void *data)
  928. {
  929. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  930. struct brcmf_p2p_info *p2p = &cfg->p2p;
  931. brcmf_dbg(INFO, "Enter: status %d\n", e->status);
  932. if (e->status == BRCMF_E_STATUS_SUCCESS)
  933. set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  934. else
  935. set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
  936. /* for now complete the receiver process here !! */
  937. complete(&p2p->send_af_done);
  938. return 0;
  939. }
  940. /**
  941. * brcmf_p2p_tx_action_frame() - send action frame over fil.
  942. *
  943. * @p2p: p2p info struct for vif.
  944. * @af_params: action frame data/info.
  945. *
  946. * Send an action frame immediately without doing channel synchronization.
  947. *
  948. * This function waits for a completion event before returning.
  949. * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
  950. * frame is transmitted.
  951. */
  952. static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
  953. struct brcmf_fil_af_params_le *af_params)
  954. {
  955. struct brcmf_cfg80211_vif *vif;
  956. s32 err = 0;
  957. s32 timeout = 0;
  958. brcmf_dbg(TRACE, "Enter\n");
  959. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  960. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
  961. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  962. err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
  963. sizeof(*af_params));
  964. if (err) {
  965. brcmf_err(" sending action frame has failed\n");
  966. goto exit;
  967. }
  968. timeout = wait_for_completion_timeout(&p2p->send_af_done,
  969. msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
  970. if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
  971. brcmf_dbg(TRACE, "TX action frame operation is success\n");
  972. } else {
  973. err = -EIO;
  974. brcmf_dbg(TRACE, "TX action frame operation has failed\n");
  975. }
  976. /* clear status bit for action tx */
  977. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  978. clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
  979. exit:
  980. return err;
  981. }
  982. /**
  983. * brcmf_p2p_pub_af_tx() - public action frame tx routine.
  984. *
  985. * @cfg: driver private data for cfg80211 interface.
  986. * @af_params: action frame data/info.
  987. * @config_af_params: configuration data for action frame.
  988. *
  989. * routine which transmits ation frame public type.
  990. */
  991. static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
  992. struct brcmf_fil_af_params_le *af_params,
  993. struct brcmf_config_af_params *config_af_params)
  994. {
  995. struct brcmf_p2p_info *p2p = &cfg->p2p;
  996. struct brcmf_fil_action_frame_le *action_frame;
  997. struct brcmf_p2p_pub_act_frame *act_frm;
  998. s32 err = 0;
  999. action_frame = &af_params->action_frame;
  1000. act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
  1001. switch (act_frm->subtype) {
  1002. case P2P_PAF_GON_REQ:
  1003. brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
  1004. set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
  1005. config_af_params->mpc_onoff = 0;
  1006. p2p->next_af_subtype = act_frm->subtype + 1;
  1007. /* increase dwell time to wait for RESP frame */
  1008. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1009. break;
  1010. case P2P_PAF_GON_RSP:
  1011. p2p->next_af_subtype = act_frm->subtype + 1;
  1012. /* increase dwell time to wait for CONF frame */
  1013. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1014. break;
  1015. case P2P_PAF_GON_CONF:
  1016. /* If we reached till GO Neg confirmation reset the filter */
  1017. brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
  1018. clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
  1019. /* turn on mpc again if go nego is done */
  1020. config_af_params->mpc_onoff = 1;
  1021. /* minimize dwell time */
  1022. af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1023. break;
  1024. case P2P_PAF_INVITE_REQ:
  1025. p2p->next_af_subtype = act_frm->subtype + 1;
  1026. /* increase dwell time */
  1027. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1028. break;
  1029. case P2P_PAF_INVITE_RSP:
  1030. /* minimize dwell time */
  1031. af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1032. break;
  1033. case P2P_PAF_DEVDIS_REQ:
  1034. p2p->next_af_subtype = act_frm->subtype + 1;
  1035. /* maximize dwell time to wait for RESP frame */
  1036. af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
  1037. break;
  1038. case P2P_PAF_DEVDIS_RSP:
  1039. /* minimize dwell time */
  1040. af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1041. break;
  1042. case P2P_PAF_PROVDIS_REQ:
  1043. config_af_params->mpc_onoff = 0;
  1044. p2p->next_af_subtype = act_frm->subtype + 1;
  1045. /* increase dwell time to wait for RESP frame */
  1046. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1047. break;
  1048. case P2P_PAF_PROVDIS_RSP:
  1049. /* wpa_supplicant send go nego req right after prov disc */
  1050. p2p->next_af_subtype = P2P_PAF_GON_REQ;
  1051. /* increase dwell time to MED level */
  1052. af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1053. break;
  1054. default:
  1055. brcmf_err("Unknown p2p pub act frame subtype: %d\n",
  1056. act_frm->subtype);
  1057. err = -EINVAL;
  1058. }
  1059. return err;
  1060. }
  1061. /**
  1062. * brcmf_p2p_send_action_frame() - send action frame .
  1063. *
  1064. * @cfg: driver private data for cfg80211 interface.
  1065. * @ndev: net device to transmit on.
  1066. * @af_params: configuration data for action frame.
  1067. */
  1068. bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
  1069. struct net_device *ndev,
  1070. struct brcmf_fil_af_params_le *af_params)
  1071. {
  1072. struct brcmf_p2p_info *p2p = &cfg->p2p;
  1073. struct brcmf_fil_action_frame_le *action_frame;
  1074. struct brcmf_config_af_params config_af_params;
  1075. u16 action_frame_len;
  1076. bool ack = false;
  1077. u8 category;
  1078. u8 action;
  1079. s32 tx_retry;
  1080. action_frame = &af_params->action_frame;
  1081. action_frame_len = le16_to_cpu(action_frame->len);
  1082. brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
  1083. /* Add the default dwell time. Dwell time to stay off-channel */
  1084. /* to wait for a response action frame after transmitting an */
  1085. /* GO Negotiation action frame */
  1086. af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
  1087. category = action_frame->data[DOT11_ACTION_CAT_OFF];
  1088. action = action_frame->data[DOT11_ACTION_ACT_OFF];
  1089. /* initialize variables */
  1090. p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
  1091. /* config parameters */
  1092. config_af_params.max_tx_retry = P2P_AF_TX_MAX_RETRY;
  1093. config_af_params.mpc_onoff = -1;
  1094. if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
  1095. /* p2p public action frame process */
  1096. if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
  1097. /* Just send unknown subtype frame with */
  1098. /* default parameters. */
  1099. brcmf_err("P2P Public action frame, unknown subtype.\n");
  1100. }
  1101. } else if (brcmf_p2p_is_gas_action(action_frame->data,
  1102. action_frame_len)) {
  1103. /* service discovery process */
  1104. if (action == P2PSD_ACTION_ID_GAS_IREQ ||
  1105. action == P2PSD_ACTION_ID_GAS_CREQ) {
  1106. /* save next af suptype to cancel */
  1107. /* remaining dwell time */
  1108. p2p->next_af_subtype = action + 1;
  1109. af_params->dwell_time =
  1110. cpu_to_le32(P2P_AF_MED_DWELL_TIME);
  1111. } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
  1112. action == P2PSD_ACTION_ID_GAS_CRESP) {
  1113. /* configure service discovery response frame */
  1114. af_params->dwell_time =
  1115. cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
  1116. } else {
  1117. brcmf_err("Unknown action type: %d\n", action);
  1118. goto exit;
  1119. }
  1120. } else if (brcmf_p2p_is_p2p_action(action_frame->data,
  1121. action_frame_len)) {
  1122. /* do not configure anything. it will be */
  1123. /* sent with a default configuration */
  1124. } else {
  1125. brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
  1126. category, action);
  1127. return false;
  1128. }
  1129. /* if scan is ongoing, abort current scan. */
  1130. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
  1131. brcmf_abort_scanning(cfg);
  1132. /* To make sure to send successfully action frame, turn off mpc */
  1133. if (config_af_params.mpc_onoff == 0)
  1134. brcmf_set_mpc(ndev, 0);
  1135. /* if failed, retry it. tx_retry_max value is configure by .... */
  1136. tx_retry = 0;
  1137. while ((ack == false) && (tx_retry < config_af_params.max_tx_retry)) {
  1138. ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
  1139. tx_retry++;
  1140. }
  1141. if (ack == false)
  1142. brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
  1143. exit:
  1144. /* if all done, turn mpc on again */
  1145. if (config_af_params.mpc_onoff == 1)
  1146. brcmf_set_mpc(ndev, 1);
  1147. return ack;
  1148. }
  1149. /**
  1150. * brcmf_p2p_attach() - attach for P2P.
  1151. *
  1152. * @cfg: driver private data for cfg80211 interface.
  1153. */
  1154. s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg)
  1155. {
  1156. struct brcmf_if *pri_ifp;
  1157. struct brcmf_if *p2p_ifp;
  1158. struct brcmf_cfg80211_vif *p2p_vif;
  1159. struct brcmf_p2p_info *p2p;
  1160. struct brcmf_pub *drvr;
  1161. s32 bssidx;
  1162. s32 err = 0;
  1163. p2p = &cfg->p2p;
  1164. p2p->cfg = cfg;
  1165. drvr = cfg->pub;
  1166. pri_ifp = drvr->iflist[0];
  1167. p2p_ifp = drvr->iflist[1];
  1168. p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
  1169. if (p2p_ifp) {
  1170. p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_P2P_DEVICE,
  1171. false);
  1172. if (IS_ERR(p2p_vif)) {
  1173. brcmf_err("could not create discovery vif\n");
  1174. err = -ENOMEM;
  1175. goto exit;
  1176. }
  1177. p2p_vif->ifp = p2p_ifp;
  1178. p2p_ifp->vif = p2p_vif;
  1179. p2p_vif->wdev.netdev = p2p_ifp->ndev;
  1180. p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev;
  1181. SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy));
  1182. p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
  1183. brcmf_p2p_generate_bss_mac(p2p);
  1184. brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
  1185. /* Initialize P2P Discovery in the firmware */
  1186. err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
  1187. if (err < 0) {
  1188. brcmf_err("set p2p_disc error\n");
  1189. brcmf_free_vif(p2p_vif);
  1190. goto exit;
  1191. }
  1192. /* obtain bsscfg index for P2P discovery */
  1193. err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx);
  1194. if (err < 0) {
  1195. brcmf_err("retrieving discover bsscfg index failed\n");
  1196. brcmf_free_vif(p2p_vif);
  1197. goto exit;
  1198. }
  1199. /* Verify that firmware uses same bssidx as driver !! */
  1200. if (p2p_ifp->bssidx != bssidx) {
  1201. brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n",
  1202. bssidx, p2p_ifp->bssidx);
  1203. brcmf_free_vif(p2p_vif);
  1204. goto exit;
  1205. }
  1206. init_completion(&p2p->send_af_done);
  1207. }
  1208. exit:
  1209. return err;
  1210. }
  1211. /**
  1212. * brcmf_p2p_detach() - detach P2P.
  1213. *
  1214. * @p2p: P2P specific data.
  1215. */
  1216. void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
  1217. {
  1218. struct brcmf_cfg80211_vif *vif;
  1219. vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  1220. if (vif != NULL) {
  1221. brcmf_p2p_cancel_remain_on_channel(vif->ifp);
  1222. brcmf_p2p_deinit_discovery(p2p);
  1223. /* remove discovery interface */
  1224. brcmf_free_vif(vif);
  1225. p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
  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. }