driver_nl80211_capa.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. /*
  2. * Driver interaction with Linux nl80211/cfg80211 - Capabilities
  3. * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright (c) 2009-2010, Atheros Communications
  6. *
  7. * This software may be distributed under the terms of the BSD license.
  8. * See README for more details.
  9. */
  10. #include "includes.h"
  11. #include <netlink/genl/genl.h>
  12. #include "utils/common.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "common/ieee802_11_common.h"
  15. #include "common/qca-vendor.h"
  16. #include "common/qca-vendor-attr.h"
  17. #include "driver_nl80211.h"
  18. static int protocol_feature_handler(struct nl_msg *msg, void *arg)
  19. {
  20. u32 *feat = arg;
  21. struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
  22. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  23. nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  24. genlmsg_attrlen(gnlh, 0), NULL);
  25. if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES])
  26. *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
  27. return NL_SKIP;
  28. }
  29. static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
  30. {
  31. u32 feat = 0;
  32. struct nl_msg *msg;
  33. msg = nlmsg_alloc();
  34. if (!msg)
  35. return 0;
  36. if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
  37. nlmsg_free(msg);
  38. return 0;
  39. }
  40. if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
  41. return feat;
  42. return 0;
  43. }
  44. struct wiphy_info_data {
  45. struct wpa_driver_nl80211_data *drv;
  46. struct wpa_driver_capa *capa;
  47. unsigned int num_multichan_concurrent;
  48. unsigned int error:1;
  49. unsigned int device_ap_sme:1;
  50. unsigned int poll_command_supported:1;
  51. unsigned int data_tx_status:1;
  52. unsigned int monitor_supported:1;
  53. unsigned int auth_supported:1;
  54. unsigned int connect_supported:1;
  55. unsigned int p2p_go_supported:1;
  56. unsigned int p2p_client_supported:1;
  57. unsigned int p2p_go_ctwindow_supported:1;
  58. unsigned int p2p_concurrent:1;
  59. unsigned int channel_switch_supported:1;
  60. unsigned int set_qos_map_supported:1;
  61. unsigned int have_low_prio_scan:1;
  62. unsigned int wmm_ac_supported:1;
  63. unsigned int mac_addr_rand_scan_supported:1;
  64. unsigned int mac_addr_rand_sched_scan_supported:1;
  65. };
  66. static unsigned int probe_resp_offload_support(int supp_protocols)
  67. {
  68. unsigned int prot = 0;
  69. if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS)
  70. prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS;
  71. if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2)
  72. prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2;
  73. if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P)
  74. prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P;
  75. if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U)
  76. prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING;
  77. return prot;
  78. }
  79. static void wiphy_info_supported_iftypes(struct wiphy_info_data *info,
  80. struct nlattr *tb)
  81. {
  82. struct nlattr *nl_mode;
  83. int i;
  84. if (tb == NULL)
  85. return;
  86. nla_for_each_nested(nl_mode, tb, i) {
  87. switch (nla_type(nl_mode)) {
  88. case NL80211_IFTYPE_AP:
  89. info->capa->flags |= WPA_DRIVER_FLAGS_AP;
  90. break;
  91. case NL80211_IFTYPE_MESH_POINT:
  92. info->capa->flags |= WPA_DRIVER_FLAGS_MESH;
  93. break;
  94. case NL80211_IFTYPE_ADHOC:
  95. info->capa->flags |= WPA_DRIVER_FLAGS_IBSS;
  96. break;
  97. case NL80211_IFTYPE_P2P_DEVICE:
  98. info->capa->flags |=
  99. WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
  100. break;
  101. case NL80211_IFTYPE_P2P_GO:
  102. info->p2p_go_supported = 1;
  103. break;
  104. case NL80211_IFTYPE_P2P_CLIENT:
  105. info->p2p_client_supported = 1;
  106. break;
  107. case NL80211_IFTYPE_MONITOR:
  108. info->monitor_supported = 1;
  109. break;
  110. }
  111. }
  112. }
  113. static int wiphy_info_iface_comb_process(struct wiphy_info_data *info,
  114. struct nlattr *nl_combi)
  115. {
  116. struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
  117. struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
  118. struct nlattr *nl_limit, *nl_mode;
  119. int err, rem_limit, rem_mode;
  120. int combination_has_p2p = 0, combination_has_mgd = 0;
  121. static struct nla_policy
  122. iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
  123. [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
  124. [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
  125. [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
  126. [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
  127. [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
  128. },
  129. iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
  130. [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
  131. [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
  132. };
  133. err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
  134. nl_combi, iface_combination_policy);
  135. if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
  136. !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
  137. !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS])
  138. return 0; /* broken combination */
  139. if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS])
  140. info->capa->flags |= WPA_DRIVER_FLAGS_RADAR;
  141. nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS],
  142. rem_limit) {
  143. err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
  144. nl_limit, iface_limit_policy);
  145. if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES])
  146. return 0; /* broken combination */
  147. nla_for_each_nested(nl_mode,
  148. tb_limit[NL80211_IFACE_LIMIT_TYPES],
  149. rem_mode) {
  150. int ift = nla_type(nl_mode);
  151. if (ift == NL80211_IFTYPE_P2P_GO ||
  152. ift == NL80211_IFTYPE_P2P_CLIENT)
  153. combination_has_p2p = 1;
  154. if (ift == NL80211_IFTYPE_STATION)
  155. combination_has_mgd = 1;
  156. }
  157. if (combination_has_p2p && combination_has_mgd)
  158. break;
  159. }
  160. if (combination_has_p2p && combination_has_mgd) {
  161. unsigned int num_channels =
  162. nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]);
  163. info->p2p_concurrent = 1;
  164. if (info->num_multichan_concurrent < num_channels)
  165. info->num_multichan_concurrent = num_channels;
  166. }
  167. return 0;
  168. }
  169. static void wiphy_info_iface_comb(struct wiphy_info_data *info,
  170. struct nlattr *tb)
  171. {
  172. struct nlattr *nl_combi;
  173. int rem_combi;
  174. if (tb == NULL)
  175. return;
  176. nla_for_each_nested(nl_combi, tb, rem_combi) {
  177. if (wiphy_info_iface_comb_process(info, nl_combi) > 0)
  178. break;
  179. }
  180. }
  181. static void wiphy_info_supp_cmds(struct wiphy_info_data *info,
  182. struct nlattr *tb)
  183. {
  184. struct nlattr *nl_cmd;
  185. int i;
  186. if (tb == NULL)
  187. return;
  188. nla_for_each_nested(nl_cmd, tb, i) {
  189. switch (nla_get_u32(nl_cmd)) {
  190. case NL80211_CMD_AUTHENTICATE:
  191. info->auth_supported = 1;
  192. break;
  193. case NL80211_CMD_CONNECT:
  194. info->connect_supported = 1;
  195. break;
  196. case NL80211_CMD_START_SCHED_SCAN:
  197. info->capa->sched_scan_supported = 1;
  198. break;
  199. case NL80211_CMD_PROBE_CLIENT:
  200. info->poll_command_supported = 1;
  201. break;
  202. case NL80211_CMD_CHANNEL_SWITCH:
  203. info->channel_switch_supported = 1;
  204. break;
  205. case NL80211_CMD_SET_QOS_MAP:
  206. info->set_qos_map_supported = 1;
  207. break;
  208. }
  209. }
  210. }
  211. static void wiphy_info_cipher_suites(struct wiphy_info_data *info,
  212. struct nlattr *tb)
  213. {
  214. int i, num;
  215. u32 *ciphers;
  216. if (tb == NULL)
  217. return;
  218. num = nla_len(tb) / sizeof(u32);
  219. ciphers = nla_data(tb);
  220. for (i = 0; i < num; i++) {
  221. u32 c = ciphers[i];
  222. wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d",
  223. c >> 24, (c >> 16) & 0xff,
  224. (c >> 8) & 0xff, c & 0xff);
  225. switch (c) {
  226. case WLAN_CIPHER_SUITE_CCMP_256:
  227. info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256;
  228. break;
  229. case WLAN_CIPHER_SUITE_GCMP_256:
  230. info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256;
  231. break;
  232. case WLAN_CIPHER_SUITE_CCMP:
  233. info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP;
  234. break;
  235. case WLAN_CIPHER_SUITE_GCMP:
  236. info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP;
  237. break;
  238. case WLAN_CIPHER_SUITE_TKIP:
  239. info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP;
  240. break;
  241. case WLAN_CIPHER_SUITE_WEP104:
  242. info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104;
  243. break;
  244. case WLAN_CIPHER_SUITE_WEP40:
  245. info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40;
  246. break;
  247. case WLAN_CIPHER_SUITE_AES_CMAC:
  248. info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP;
  249. break;
  250. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  251. info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128;
  252. break;
  253. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  254. info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256;
  255. break;
  256. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  257. info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256;
  258. break;
  259. case WLAN_CIPHER_SUITE_NO_GROUP_ADDR:
  260. info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED;
  261. break;
  262. }
  263. }
  264. }
  265. static void wiphy_info_max_roc(struct wpa_driver_capa *capa,
  266. struct nlattr *tb)
  267. {
  268. if (tb)
  269. capa->max_remain_on_chan = nla_get_u32(tb);
  270. }
  271. static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls,
  272. struct nlattr *ext_setup)
  273. {
  274. if (tdls == NULL)
  275. return;
  276. wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
  277. capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
  278. if (ext_setup) {
  279. wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
  280. capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
  281. }
  282. }
  283. static int ext_feature_isset(const u8 *ext_features, int ext_features_len,
  284. enum nl80211_ext_feature_index ftidx)
  285. {
  286. u8 ft_byte;
  287. if ((int) ftidx / 8 >= ext_features_len)
  288. return 0;
  289. ft_byte = ext_features[ftidx / 8];
  290. return (ft_byte & BIT(ftidx % 8)) != 0;
  291. }
  292. static void wiphy_info_ext_feature_flags(struct wiphy_info_data *info,
  293. struct nlattr *tb)
  294. {
  295. struct wpa_driver_capa *capa = info->capa;
  296. u8 *ext_features;
  297. int len;
  298. if (tb == NULL)
  299. return;
  300. ext_features = nla_data(tb);
  301. len = nla_len(tb);
  302. if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_VHT_IBSS))
  303. capa->flags |= WPA_DRIVER_FLAGS_VHT_IBSS;
  304. if (ext_feature_isset(ext_features, len, NL80211_EXT_FEATURE_RRM))
  305. capa->rrm_flags |= WPA_DRIVER_FLAGS_SUPPORT_RRM;
  306. }
  307. static void wiphy_info_feature_flags(struct wiphy_info_data *info,
  308. struct nlattr *tb)
  309. {
  310. u32 flags;
  311. struct wpa_driver_capa *capa = info->capa;
  312. if (tb == NULL)
  313. return;
  314. flags = nla_get_u32(tb);
  315. if (flags & NL80211_FEATURE_SK_TX_STATUS)
  316. info->data_tx_status = 1;
  317. if (flags & NL80211_FEATURE_INACTIVITY_TIMER)
  318. capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER;
  319. if (flags & NL80211_FEATURE_SAE)
  320. capa->flags |= WPA_DRIVER_FLAGS_SAE;
  321. if (flags & NL80211_FEATURE_NEED_OBSS_SCAN)
  322. capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN;
  323. if (flags & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
  324. capa->flags |= WPA_DRIVER_FLAGS_HT_2040_COEX;
  325. if (flags & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) {
  326. wpa_printf(MSG_DEBUG, "nl80211: TDLS channel switch");
  327. capa->flags |= WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH;
  328. }
  329. if (flags & NL80211_FEATURE_P2P_GO_CTWIN)
  330. info->p2p_go_ctwindow_supported = 1;
  331. if (flags & NL80211_FEATURE_LOW_PRIORITY_SCAN)
  332. info->have_low_prio_scan = 1;
  333. if (flags & NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)
  334. info->mac_addr_rand_scan_supported = 1;
  335. if (flags & NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR)
  336. info->mac_addr_rand_sched_scan_supported = 1;
  337. if (flags & NL80211_FEATURE_STATIC_SMPS)
  338. capa->smps_modes |= WPA_DRIVER_SMPS_MODE_STATIC;
  339. if (flags & NL80211_FEATURE_DYNAMIC_SMPS)
  340. capa->smps_modes |= WPA_DRIVER_SMPS_MODE_DYNAMIC;
  341. if (flags & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
  342. info->wmm_ac_supported = 1;
  343. if (flags & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
  344. capa->rrm_flags |= WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES;
  345. if (flags & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
  346. capa->rrm_flags |= WPA_DRIVER_FLAGS_WFA_TPC_IE_IN_PROBES;
  347. if (flags & NL80211_FEATURE_QUIET)
  348. capa->rrm_flags |= WPA_DRIVER_FLAGS_QUIET;
  349. if (flags & NL80211_FEATURE_TX_POWER_INSERTION)
  350. capa->rrm_flags |= WPA_DRIVER_FLAGS_TX_POWER_INSERTION;
  351. if (flags & NL80211_FEATURE_HT_IBSS)
  352. capa->flags |= WPA_DRIVER_FLAGS_HT_IBSS;
  353. if (flags & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
  354. capa->flags |= WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE;
  355. }
  356. static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa,
  357. struct nlattr *tb)
  358. {
  359. u32 protocols;
  360. if (tb == NULL)
  361. return;
  362. protocols = nla_get_u32(tb);
  363. wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP "
  364. "mode");
  365. capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD;
  366. capa->probe_resp_offloads = probe_resp_offload_support(protocols);
  367. }
  368. static void wiphy_info_wowlan_triggers(struct wpa_driver_capa *capa,
  369. struct nlattr *tb)
  370. {
  371. struct nlattr *triggers[MAX_NL80211_WOWLAN_TRIG + 1];
  372. if (tb == NULL)
  373. return;
  374. if (nla_parse_nested(triggers, MAX_NL80211_WOWLAN_TRIG,
  375. tb, NULL))
  376. return;
  377. if (triggers[NL80211_WOWLAN_TRIG_ANY])
  378. capa->wowlan_triggers.any = 1;
  379. if (triggers[NL80211_WOWLAN_TRIG_DISCONNECT])
  380. capa->wowlan_triggers.disconnect = 1;
  381. if (triggers[NL80211_WOWLAN_TRIG_MAGIC_PKT])
  382. capa->wowlan_triggers.magic_pkt = 1;
  383. if (triggers[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
  384. capa->wowlan_triggers.gtk_rekey_failure = 1;
  385. if (triggers[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
  386. capa->wowlan_triggers.eap_identity_req = 1;
  387. if (triggers[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
  388. capa->wowlan_triggers.four_way_handshake = 1;
  389. if (triggers[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
  390. capa->wowlan_triggers.rfkill_release = 1;
  391. }
  392. static void wiphy_info_extended_capab(struct wpa_driver_nl80211_data *drv,
  393. struct nlattr *tb)
  394. {
  395. int rem = 0, i;
  396. struct nlattr *tb1[NL80211_ATTR_MAX + 1], *attr;
  397. if (!tb || drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
  398. return;
  399. nla_for_each_nested(attr, tb, rem) {
  400. unsigned int len;
  401. struct drv_nl80211_ext_capa *capa;
  402. nla_parse(tb1, NL80211_ATTR_MAX, nla_data(attr),
  403. nla_len(attr), NULL);
  404. if (!tb1[NL80211_ATTR_IFTYPE] ||
  405. !tb1[NL80211_ATTR_EXT_CAPA] ||
  406. !tb1[NL80211_ATTR_EXT_CAPA_MASK])
  407. continue;
  408. capa = &drv->iface_ext_capa[drv->num_iface_ext_capa];
  409. capa->iftype = nla_get_u32(tb1[NL80211_ATTR_IFTYPE]);
  410. wpa_printf(MSG_DEBUG,
  411. "nl80211: Driver-advertised extended capabilities for interface type %s",
  412. nl80211_iftype_str(capa->iftype));
  413. len = nla_len(tb1[NL80211_ATTR_EXT_CAPA]);
  414. capa->ext_capa = os_malloc(len);
  415. if (!capa->ext_capa)
  416. goto err;
  417. os_memcpy(capa->ext_capa, nla_data(tb1[NL80211_ATTR_EXT_CAPA]),
  418. len);
  419. capa->ext_capa_len = len;
  420. wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities",
  421. capa->ext_capa, capa->ext_capa_len);
  422. len = nla_len(tb1[NL80211_ATTR_EXT_CAPA_MASK]);
  423. capa->ext_capa_mask = os_malloc(len);
  424. if (!capa->ext_capa_mask)
  425. goto err;
  426. os_memcpy(capa->ext_capa_mask,
  427. nla_data(tb1[NL80211_ATTR_EXT_CAPA_MASK]), len);
  428. wpa_hexdump(MSG_DEBUG, "nl80211: Extended capabilities mask",
  429. capa->ext_capa_mask, capa->ext_capa_len);
  430. drv->num_iface_ext_capa++;
  431. if (drv->num_iface_ext_capa == NL80211_IFTYPE_MAX)
  432. break;
  433. }
  434. return;
  435. err:
  436. /* Cleanup allocated memory on error */
  437. for (i = 0; i < NL80211_IFTYPE_MAX; i++) {
  438. os_free(drv->iface_ext_capa[i].ext_capa);
  439. drv->iface_ext_capa[i].ext_capa = NULL;
  440. os_free(drv->iface_ext_capa[i].ext_capa_mask);
  441. drv->iface_ext_capa[i].ext_capa_mask = NULL;
  442. drv->iface_ext_capa[i].ext_capa_len = 0;
  443. }
  444. drv->num_iface_ext_capa = 0;
  445. }
  446. static int wiphy_info_handler(struct nl_msg *msg, void *arg)
  447. {
  448. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  449. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  450. struct wiphy_info_data *info = arg;
  451. struct wpa_driver_capa *capa = info->capa;
  452. struct wpa_driver_nl80211_data *drv = info->drv;
  453. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  454. genlmsg_attrlen(gnlh, 0), NULL);
  455. if (tb[NL80211_ATTR_WIPHY])
  456. drv->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
  457. if (tb[NL80211_ATTR_WIPHY_NAME])
  458. os_strlcpy(drv->phyname,
  459. nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]),
  460. sizeof(drv->phyname));
  461. if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
  462. capa->max_scan_ssids =
  463. nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]);
  464. if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
  465. capa->max_sched_scan_ssids =
  466. nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]);
  467. if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS] &&
  468. tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL] &&
  469. tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]) {
  470. capa->max_sched_scan_plans =
  471. nla_get_u32(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS]);
  472. capa->max_sched_scan_plan_interval =
  473. nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL]);
  474. capa->max_sched_scan_plan_iterations =
  475. nla_get_u32(tb[NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS]);
  476. }
  477. if (tb[NL80211_ATTR_MAX_MATCH_SETS])
  478. capa->max_match_sets =
  479. nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]);
  480. if (tb[NL80211_ATTR_MAC_ACL_MAX])
  481. capa->max_acl_mac_addrs =
  482. nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]);
  483. wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]);
  484. wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]);
  485. wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]);
  486. wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]);
  487. if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) {
  488. wpa_printf(MSG_DEBUG, "nl80211: Using driver-based "
  489. "off-channel TX");
  490. capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
  491. }
  492. if (tb[NL80211_ATTR_ROAM_SUPPORT]) {
  493. wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming");
  494. capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
  495. }
  496. wiphy_info_max_roc(capa,
  497. tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
  498. if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD])
  499. capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD;
  500. wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT],
  501. tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]);
  502. if (tb[NL80211_ATTR_DEVICE_AP_SME])
  503. info->device_ap_sme = 1;
  504. wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]);
  505. wiphy_info_ext_feature_flags(info, tb[NL80211_ATTR_EXT_FEATURES]);
  506. wiphy_info_probe_resp_offload(capa,
  507. tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]);
  508. if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] &&
  509. drv->extended_capa == NULL) {
  510. drv->extended_capa =
  511. os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA]));
  512. if (drv->extended_capa) {
  513. os_memcpy(drv->extended_capa,
  514. nla_data(tb[NL80211_ATTR_EXT_CAPA]),
  515. nla_len(tb[NL80211_ATTR_EXT_CAPA]));
  516. drv->extended_capa_len =
  517. nla_len(tb[NL80211_ATTR_EXT_CAPA]);
  518. wpa_hexdump(MSG_DEBUG,
  519. "nl80211: Driver-advertised extended capabilities (default)",
  520. drv->extended_capa, drv->extended_capa_len);
  521. }
  522. drv->extended_capa_mask =
  523. os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
  524. if (drv->extended_capa_mask) {
  525. os_memcpy(drv->extended_capa_mask,
  526. nla_data(tb[NL80211_ATTR_EXT_CAPA_MASK]),
  527. nla_len(tb[NL80211_ATTR_EXT_CAPA_MASK]));
  528. wpa_hexdump(MSG_DEBUG,
  529. "nl80211: Driver-advertised extended capabilities mask (default)",
  530. drv->extended_capa_mask,
  531. drv->extended_capa_len);
  532. } else {
  533. os_free(drv->extended_capa);
  534. drv->extended_capa = NULL;
  535. drv->extended_capa_len = 0;
  536. }
  537. }
  538. wiphy_info_extended_capab(drv, tb[NL80211_ATTR_IFTYPE_EXT_CAPA]);
  539. if (tb[NL80211_ATTR_VENDOR_DATA]) {
  540. struct nlattr *nl;
  541. int rem;
  542. nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) {
  543. struct nl80211_vendor_cmd_info *vinfo;
  544. if (nla_len(nl) != sizeof(*vinfo)) {
  545. wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
  546. continue;
  547. }
  548. vinfo = nla_data(nl);
  549. if (vinfo->vendor_id == OUI_QCA) {
  550. switch (vinfo->subcmd) {
  551. case QCA_NL80211_VENDOR_SUBCMD_TEST:
  552. drv->vendor_cmd_test_avail = 1;
  553. break;
  554. #ifdef CONFIG_DRIVER_NL80211_QCA
  555. case QCA_NL80211_VENDOR_SUBCMD_ROAMING:
  556. drv->roaming_vendor_cmd_avail = 1;
  557. break;
  558. case QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY:
  559. drv->dfs_vendor_cmd_avail = 1;
  560. break;
  561. case QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES:
  562. drv->get_features_vendor_cmd_avail = 1;
  563. break;
  564. case QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST:
  565. drv->get_pref_freq_list = 1;
  566. break;
  567. case QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL:
  568. drv->set_prob_oper_freq = 1;
  569. break;
  570. case QCA_NL80211_VENDOR_SUBCMD_DO_ACS:
  571. drv->capa.flags |=
  572. WPA_DRIVER_FLAGS_ACS_OFFLOAD;
  573. break;
  574. case QCA_NL80211_VENDOR_SUBCMD_SETBAND:
  575. drv->setband_vendor_cmd_avail = 1;
  576. break;
  577. case QCA_NL80211_VENDOR_SUBCMD_TRIGGER_SCAN:
  578. drv->scan_vendor_cmd_avail = 1;
  579. break;
  580. #endif /* CONFIG_DRIVER_NL80211_QCA */
  581. }
  582. }
  583. wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
  584. vinfo->vendor_id, vinfo->subcmd);
  585. }
  586. }
  587. if (tb[NL80211_ATTR_VENDOR_EVENTS]) {
  588. struct nlattr *nl;
  589. int rem;
  590. nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) {
  591. struct nl80211_vendor_cmd_info *vinfo;
  592. if (nla_len(nl) != sizeof(*vinfo)) {
  593. wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info");
  594. continue;
  595. }
  596. vinfo = nla_data(nl);
  597. wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u",
  598. vinfo->vendor_id, vinfo->subcmd);
  599. }
  600. }
  601. wiphy_info_wowlan_triggers(capa,
  602. tb[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]);
  603. if (tb[NL80211_ATTR_MAX_AP_ASSOC_STA])
  604. capa->max_stations =
  605. nla_get_u32(tb[NL80211_ATTR_MAX_AP_ASSOC_STA]);
  606. if (tb[NL80211_ATTR_MAX_CSA_COUNTERS])
  607. capa->max_csa_counters =
  608. nla_get_u8(tb[NL80211_ATTR_MAX_CSA_COUNTERS]);
  609. return NL_SKIP;
  610. }
  611. static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv,
  612. struct wiphy_info_data *info)
  613. {
  614. u32 feat;
  615. struct nl_msg *msg;
  616. int flags = 0;
  617. os_memset(info, 0, sizeof(*info));
  618. info->capa = &drv->capa;
  619. info->drv = drv;
  620. feat = get_nl80211_protocol_features(drv);
  621. if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
  622. flags = NLM_F_DUMP;
  623. msg = nl80211_cmd_msg(drv->first_bss, flags, NL80211_CMD_GET_WIPHY);
  624. if (!msg || nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
  625. nlmsg_free(msg);
  626. return -1;
  627. }
  628. if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info))
  629. return -1;
  630. if (info->auth_supported)
  631. drv->capa.flags |= WPA_DRIVER_FLAGS_SME;
  632. else if (!info->connect_supported) {
  633. wpa_printf(MSG_INFO, "nl80211: Driver does not support "
  634. "authentication/association or connect commands");
  635. info->error = 1;
  636. }
  637. if (info->p2p_go_supported && info->p2p_client_supported)
  638. drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE;
  639. if (info->p2p_concurrent) {
  640. wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
  641. "interface (driver advertised support)");
  642. drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
  643. drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
  644. }
  645. if (info->num_multichan_concurrent > 1) {
  646. wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel "
  647. "concurrent (driver advertised support)");
  648. drv->capa.num_multichan_concurrent =
  649. info->num_multichan_concurrent;
  650. }
  651. if (drv->capa.flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
  652. wpa_printf(MSG_DEBUG, "nl80211: use P2P_DEVICE support");
  653. /* default to 5000 since early versions of mac80211 don't set it */
  654. if (!drv->capa.max_remain_on_chan)
  655. drv->capa.max_remain_on_chan = 5000;
  656. drv->capa.wmm_ac_supported = info->wmm_ac_supported;
  657. drv->capa.mac_addr_rand_sched_scan_supported =
  658. info->mac_addr_rand_sched_scan_supported;
  659. drv->capa.mac_addr_rand_scan_supported =
  660. info->mac_addr_rand_scan_supported;
  661. if (info->channel_switch_supported) {
  662. drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA;
  663. if (!drv->capa.max_csa_counters)
  664. drv->capa.max_csa_counters = 1;
  665. }
  666. if (!drv->capa.max_sched_scan_plans) {
  667. drv->capa.max_sched_scan_plans = 1;
  668. drv->capa.max_sched_scan_plan_interval = UINT32_MAX;
  669. drv->capa.max_sched_scan_plan_iterations = 0;
  670. }
  671. return 0;
  672. }
  673. #ifdef CONFIG_DRIVER_NL80211_QCA
  674. static int dfs_info_handler(struct nl_msg *msg, void *arg)
  675. {
  676. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  677. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  678. int *dfs_capability_ptr = arg;
  679. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  680. genlmsg_attrlen(gnlh, 0), NULL);
  681. if (tb[NL80211_ATTR_VENDOR_DATA]) {
  682. struct nlattr *nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
  683. struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
  684. nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
  685. nla_data(nl_vend), nla_len(nl_vend), NULL);
  686. if (tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]) {
  687. u32 val;
  688. val = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_DFS]);
  689. wpa_printf(MSG_DEBUG, "nl80211: DFS offload capability: %u",
  690. val);
  691. *dfs_capability_ptr = val;
  692. }
  693. }
  694. return NL_SKIP;
  695. }
  696. static void qca_nl80211_check_dfs_capa(struct wpa_driver_nl80211_data *drv)
  697. {
  698. struct nl_msg *msg;
  699. int dfs_capability = 0;
  700. int ret;
  701. if (!drv->dfs_vendor_cmd_avail)
  702. return;
  703. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  704. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  705. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  706. QCA_NL80211_VENDOR_SUBCMD_DFS_CAPABILITY)) {
  707. nlmsg_free(msg);
  708. return;
  709. }
  710. ret = send_and_recv_msgs(drv, msg, dfs_info_handler, &dfs_capability);
  711. if (!ret && dfs_capability)
  712. drv->capa.flags |= WPA_DRIVER_FLAGS_DFS_OFFLOAD;
  713. }
  714. struct features_info {
  715. u8 *flags;
  716. size_t flags_len;
  717. struct wpa_driver_capa *capa;
  718. };
  719. static int features_info_handler(struct nl_msg *msg, void *arg)
  720. {
  721. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  722. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  723. struct features_info *info = arg;
  724. struct nlattr *nl_vend, *attr;
  725. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  726. genlmsg_attrlen(gnlh, 0), NULL);
  727. nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
  728. if (nl_vend) {
  729. struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
  730. nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
  731. nla_data(nl_vend), nla_len(nl_vend), NULL);
  732. attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
  733. if (attr) {
  734. int len = nla_len(attr);
  735. info->flags = os_malloc(len);
  736. if (info->flags != NULL) {
  737. os_memcpy(info->flags, nla_data(attr), len);
  738. info->flags_len = len;
  739. }
  740. }
  741. attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_CONCURRENCY_CAPA];
  742. if (attr)
  743. info->capa->conc_capab = nla_get_u32(attr);
  744. attr = tb_vendor[
  745. QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_2_4_BAND];
  746. if (attr)
  747. info->capa->max_conc_chan_2_4 = nla_get_u32(attr);
  748. attr = tb_vendor[
  749. QCA_WLAN_VENDOR_ATTR_MAX_CONCURRENT_CHANNELS_5_0_BAND];
  750. if (attr)
  751. info->capa->max_conc_chan_5_0 = nla_get_u32(attr);
  752. }
  753. return NL_SKIP;
  754. }
  755. static int check_feature(enum qca_wlan_vendor_features feature,
  756. struct features_info *info)
  757. {
  758. size_t idx = feature / 8;
  759. return (idx < info->flags_len) &&
  760. (info->flags[idx] & BIT(feature % 8));
  761. }
  762. static void qca_nl80211_get_features(struct wpa_driver_nl80211_data *drv)
  763. {
  764. struct nl_msg *msg;
  765. struct features_info info;
  766. int ret;
  767. if (!drv->get_features_vendor_cmd_avail)
  768. return;
  769. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  770. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  771. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  772. QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
  773. nlmsg_free(msg);
  774. return;
  775. }
  776. os_memset(&info, 0, sizeof(info));
  777. info.capa = &drv->capa;
  778. ret = send_and_recv_msgs(drv, msg, features_info_handler, &info);
  779. if (ret || !info.flags)
  780. return;
  781. if (check_feature(QCA_WLAN_VENDOR_FEATURE_KEY_MGMT_OFFLOAD, &info))
  782. drv->capa.flags |= WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD;
  783. if (check_feature(QCA_WLAN_VENDOR_FEATURE_SUPPORT_HW_MODE_ANY, &info))
  784. drv->capa.flags |= WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY;
  785. if (check_feature(QCA_WLAN_VENDOR_FEATURE_OFFCHANNEL_SIMULTANEOUS,
  786. &info))
  787. drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
  788. if (check_feature(QCA_WLAN_VENDOR_FEATURE_P2P_LISTEN_OFFLOAD, &info))
  789. drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD;
  790. os_free(info.flags);
  791. }
  792. #endif /* CONFIG_DRIVER_NL80211_QCA */
  793. int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
  794. {
  795. struct wiphy_info_data info;
  796. if (wpa_driver_nl80211_get_info(drv, &info))
  797. return -1;
  798. if (info.error)
  799. return -1;
  800. drv->has_capability = 1;
  801. drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  802. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  803. WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  804. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK |
  805. WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B |
  806. WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192;
  807. drv->capa.auth = WPA_DRIVER_AUTH_OPEN |
  808. WPA_DRIVER_AUTH_SHARED |
  809. WPA_DRIVER_AUTH_LEAP;
  810. drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
  811. drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
  812. drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
  813. /*
  814. * As all cfg80211 drivers must support cases where the AP interface is
  815. * removed without the knowledge of wpa_supplicant/hostapd, e.g., in
  816. * case that the user space daemon has crashed, they must be able to
  817. * cleanup all stations and key entries in the AP tear down flow. Thus,
  818. * this flag can/should always be set for cfg80211 drivers.
  819. */
  820. drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT;
  821. if (!info.device_ap_sme) {
  822. drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS;
  823. /*
  824. * No AP SME is currently assumed to also indicate no AP MLME
  825. * in the driver/firmware.
  826. */
  827. drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME;
  828. }
  829. drv->device_ap_sme = info.device_ap_sme;
  830. drv->poll_command_supported = info.poll_command_supported;
  831. drv->data_tx_status = info.data_tx_status;
  832. drv->p2p_go_ctwindow_supported = info.p2p_go_ctwindow_supported;
  833. if (info.set_qos_map_supported)
  834. drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING;
  835. drv->have_low_prio_scan = info.have_low_prio_scan;
  836. /*
  837. * If poll command and tx status are supported, mac80211 is new enough
  838. * to have everything we need to not need monitor interfaces.
  839. */
  840. drv->use_monitor = !info.poll_command_supported || !info.data_tx_status;
  841. if (drv->device_ap_sme && drv->use_monitor) {
  842. /*
  843. * Non-mac80211 drivers may not support monitor interface.
  844. * Make sure we do not get stuck with incorrect capability here
  845. * by explicitly testing this.
  846. */
  847. if (!info.monitor_supported) {
  848. wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor "
  849. "with device_ap_sme since no monitor mode "
  850. "support detected");
  851. drv->use_monitor = 0;
  852. }
  853. }
  854. /*
  855. * If we aren't going to use monitor interfaces, but the
  856. * driver doesn't support data TX status, we won't get TX
  857. * status for EAPOL frames.
  858. */
  859. if (!drv->use_monitor && !info.data_tx_status)
  860. drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
  861. #ifdef CONFIG_DRIVER_NL80211_QCA
  862. qca_nl80211_check_dfs_capa(drv);
  863. qca_nl80211_get_features(drv);
  864. /*
  865. * To enable offchannel simultaneous support in wpa_supplicant, the
  866. * underlying driver needs to support the same along with offchannel TX.
  867. * Offchannel TX support is needed since remain_on_channel and
  868. * action_tx use some common data structures and hence cannot be
  869. * scheduled simultaneously.
  870. */
  871. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX))
  872. drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS;
  873. #endif /* CONFIG_DRIVER_NL80211_QCA */
  874. return 0;
  875. }
  876. struct phy_info_arg {
  877. u16 *num_modes;
  878. struct hostapd_hw_modes *modes;
  879. int last_mode, last_chan_idx;
  880. int failed;
  881. };
  882. static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa,
  883. struct nlattr *ampdu_factor,
  884. struct nlattr *ampdu_density,
  885. struct nlattr *mcs_set)
  886. {
  887. if (capa)
  888. mode->ht_capab = nla_get_u16(capa);
  889. if (ampdu_factor)
  890. mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03;
  891. if (ampdu_density)
  892. mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2;
  893. if (mcs_set && nla_len(mcs_set) >= 16) {
  894. u8 *mcs;
  895. mcs = nla_data(mcs_set);
  896. os_memcpy(mode->mcs_set, mcs, 16);
  897. }
  898. }
  899. static void phy_info_vht_capa(struct hostapd_hw_modes *mode,
  900. struct nlattr *capa,
  901. struct nlattr *mcs_set)
  902. {
  903. if (capa)
  904. mode->vht_capab = nla_get_u32(capa);
  905. if (mcs_set && nla_len(mcs_set) >= 8) {
  906. u8 *mcs;
  907. mcs = nla_data(mcs_set);
  908. os_memcpy(mode->vht_mcs_set, mcs, 8);
  909. }
  910. }
  911. static void phy_info_freq(struct hostapd_hw_modes *mode,
  912. struct hostapd_channel_data *chan,
  913. struct nlattr *tb_freq[])
  914. {
  915. u8 channel;
  916. chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
  917. chan->flag = 0;
  918. chan->dfs_cac_ms = 0;
  919. if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES)
  920. chan->chan = channel;
  921. if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
  922. chan->flag |= HOSTAPD_CHAN_DISABLED;
  923. if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR])
  924. chan->flag |= HOSTAPD_CHAN_NO_IR;
  925. if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
  926. chan->flag |= HOSTAPD_CHAN_RADAR;
  927. if (tb_freq[NL80211_FREQUENCY_ATTR_INDOOR_ONLY])
  928. chan->flag |= HOSTAPD_CHAN_INDOOR_ONLY;
  929. if (tb_freq[NL80211_FREQUENCY_ATTR_GO_CONCURRENT])
  930. chan->flag |= HOSTAPD_CHAN_GO_CONCURRENT;
  931. if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
  932. enum nl80211_dfs_state state =
  933. nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
  934. switch (state) {
  935. case NL80211_DFS_USABLE:
  936. chan->flag |= HOSTAPD_CHAN_DFS_USABLE;
  937. break;
  938. case NL80211_DFS_AVAILABLE:
  939. chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE;
  940. break;
  941. case NL80211_DFS_UNAVAILABLE:
  942. chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE;
  943. break;
  944. }
  945. }
  946. if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]) {
  947. chan->dfs_cac_ms = nla_get_u32(
  948. tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]);
  949. }
  950. }
  951. static int phy_info_freqs(struct phy_info_arg *phy_info,
  952. struct hostapd_hw_modes *mode, struct nlattr *tb)
  953. {
  954. static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
  955. [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
  956. [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
  957. [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
  958. [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
  959. [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
  960. [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 },
  961. };
  962. int new_channels = 0;
  963. struct hostapd_channel_data *channel;
  964. struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
  965. struct nlattr *nl_freq;
  966. int rem_freq, idx;
  967. if (tb == NULL)
  968. return NL_OK;
  969. nla_for_each_nested(nl_freq, tb, rem_freq) {
  970. nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
  971. nla_data(nl_freq), nla_len(nl_freq), freq_policy);
  972. if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
  973. continue;
  974. new_channels++;
  975. }
  976. channel = os_realloc_array(mode->channels,
  977. mode->num_channels + new_channels,
  978. sizeof(struct hostapd_channel_data));
  979. if (!channel)
  980. return NL_STOP;
  981. mode->channels = channel;
  982. mode->num_channels += new_channels;
  983. idx = phy_info->last_chan_idx;
  984. nla_for_each_nested(nl_freq, tb, rem_freq) {
  985. nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
  986. nla_data(nl_freq), nla_len(nl_freq), freq_policy);
  987. if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
  988. continue;
  989. phy_info_freq(mode, &mode->channels[idx], tb_freq);
  990. idx++;
  991. }
  992. phy_info->last_chan_idx = idx;
  993. return NL_OK;
  994. }
  995. static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb)
  996. {
  997. static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
  998. [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
  999. [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
  1000. { .type = NLA_FLAG },
  1001. };
  1002. struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
  1003. struct nlattr *nl_rate;
  1004. int rem_rate, idx;
  1005. if (tb == NULL)
  1006. return NL_OK;
  1007. nla_for_each_nested(nl_rate, tb, rem_rate) {
  1008. nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
  1009. nla_data(nl_rate), nla_len(nl_rate),
  1010. rate_policy);
  1011. if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
  1012. continue;
  1013. mode->num_rates++;
  1014. }
  1015. mode->rates = os_calloc(mode->num_rates, sizeof(int));
  1016. if (!mode->rates)
  1017. return NL_STOP;
  1018. idx = 0;
  1019. nla_for_each_nested(nl_rate, tb, rem_rate) {
  1020. nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
  1021. nla_data(nl_rate), nla_len(nl_rate),
  1022. rate_policy);
  1023. if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
  1024. continue;
  1025. mode->rates[idx] = nla_get_u32(
  1026. tb_rate[NL80211_BITRATE_ATTR_RATE]);
  1027. idx++;
  1028. }
  1029. return NL_OK;
  1030. }
  1031. static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
  1032. {
  1033. struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
  1034. struct hostapd_hw_modes *mode;
  1035. int ret;
  1036. if (phy_info->last_mode != nl_band->nla_type) {
  1037. mode = os_realloc_array(phy_info->modes,
  1038. *phy_info->num_modes + 1,
  1039. sizeof(*mode));
  1040. if (!mode) {
  1041. phy_info->failed = 1;
  1042. return NL_STOP;
  1043. }
  1044. phy_info->modes = mode;
  1045. mode = &phy_info->modes[*(phy_info->num_modes)];
  1046. os_memset(mode, 0, sizeof(*mode));
  1047. mode->mode = NUM_HOSTAPD_MODES;
  1048. mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN |
  1049. HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN;
  1050. /*
  1051. * Unsupported VHT MCS stream is defined as value 3, so the VHT
  1052. * MCS RX/TX map must be initialized with 0xffff to mark all 8
  1053. * possible streams as unsupported. This will be overridden if
  1054. * driver advertises VHT support.
  1055. */
  1056. mode->vht_mcs_set[0] = 0xff;
  1057. mode->vht_mcs_set[1] = 0xff;
  1058. mode->vht_mcs_set[4] = 0xff;
  1059. mode->vht_mcs_set[5] = 0xff;
  1060. *(phy_info->num_modes) += 1;
  1061. phy_info->last_mode = nl_band->nla_type;
  1062. phy_info->last_chan_idx = 0;
  1063. } else
  1064. mode = &phy_info->modes[*(phy_info->num_modes) - 1];
  1065. nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
  1066. nla_len(nl_band), NULL);
  1067. phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA],
  1068. tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR],
  1069. tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY],
  1070. tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
  1071. phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA],
  1072. tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]);
  1073. ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]);
  1074. if (ret == NL_OK)
  1075. ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]);
  1076. if (ret != NL_OK) {
  1077. phy_info->failed = 1;
  1078. return ret;
  1079. }
  1080. return NL_OK;
  1081. }
  1082. static int phy_info_handler(struct nl_msg *msg, void *arg)
  1083. {
  1084. struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
  1085. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  1086. struct phy_info_arg *phy_info = arg;
  1087. struct nlattr *nl_band;
  1088. int rem_band;
  1089. nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  1090. genlmsg_attrlen(gnlh, 0), NULL);
  1091. if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
  1092. return NL_SKIP;
  1093. nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
  1094. {
  1095. int res = phy_info_band(phy_info, nl_band);
  1096. if (res != NL_OK)
  1097. return res;
  1098. }
  1099. return NL_SKIP;
  1100. }
  1101. static struct hostapd_hw_modes *
  1102. wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes,
  1103. u16 *num_modes)
  1104. {
  1105. u16 m;
  1106. struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
  1107. int i, mode11g_idx = -1;
  1108. /* heuristic to set up modes */
  1109. for (m = 0; m < *num_modes; m++) {
  1110. if (!modes[m].num_channels)
  1111. continue;
  1112. if (modes[m].channels[0].freq < 4000) {
  1113. modes[m].mode = HOSTAPD_MODE_IEEE80211B;
  1114. for (i = 0; i < modes[m].num_rates; i++) {
  1115. if (modes[m].rates[i] > 200) {
  1116. modes[m].mode = HOSTAPD_MODE_IEEE80211G;
  1117. break;
  1118. }
  1119. }
  1120. } else if (modes[m].channels[0].freq > 50000)
  1121. modes[m].mode = HOSTAPD_MODE_IEEE80211AD;
  1122. else
  1123. modes[m].mode = HOSTAPD_MODE_IEEE80211A;
  1124. }
  1125. /* If only 802.11g mode is included, use it to construct matching
  1126. * 802.11b mode data. */
  1127. for (m = 0; m < *num_modes; m++) {
  1128. if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
  1129. return modes; /* 802.11b already included */
  1130. if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
  1131. mode11g_idx = m;
  1132. }
  1133. if (mode11g_idx < 0)
  1134. return modes; /* 2.4 GHz band not supported at all */
  1135. nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes));
  1136. if (nmodes == NULL)
  1137. return modes; /* Could not add 802.11b mode */
  1138. mode = &nmodes[*num_modes];
  1139. os_memset(mode, 0, sizeof(*mode));
  1140. (*num_modes)++;
  1141. modes = nmodes;
  1142. mode->mode = HOSTAPD_MODE_IEEE80211B;
  1143. mode11g = &modes[mode11g_idx];
  1144. mode->num_channels = mode11g->num_channels;
  1145. mode->channels = os_malloc(mode11g->num_channels *
  1146. sizeof(struct hostapd_channel_data));
  1147. if (mode->channels == NULL) {
  1148. (*num_modes)--;
  1149. return modes; /* Could not add 802.11b mode */
  1150. }
  1151. os_memcpy(mode->channels, mode11g->channels,
  1152. mode11g->num_channels * sizeof(struct hostapd_channel_data));
  1153. mode->num_rates = 0;
  1154. mode->rates = os_malloc(4 * sizeof(int));
  1155. if (mode->rates == NULL) {
  1156. os_free(mode->channels);
  1157. (*num_modes)--;
  1158. return modes; /* Could not add 802.11b mode */
  1159. }
  1160. for (i = 0; i < mode11g->num_rates; i++) {
  1161. if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
  1162. mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
  1163. continue;
  1164. mode->rates[mode->num_rates] = mode11g->rates[i];
  1165. mode->num_rates++;
  1166. if (mode->num_rates == 4)
  1167. break;
  1168. }
  1169. if (mode->num_rates == 0) {
  1170. os_free(mode->channels);
  1171. os_free(mode->rates);
  1172. (*num_modes)--;
  1173. return modes; /* No 802.11b rates */
  1174. }
  1175. wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
  1176. "information");
  1177. return modes;
  1178. }
  1179. static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start,
  1180. int end)
  1181. {
  1182. int c;
  1183. for (c = 0; c < mode->num_channels; c++) {
  1184. struct hostapd_channel_data *chan = &mode->channels[c];
  1185. if (chan->freq - 10 >= start && chan->freq + 10 <= end)
  1186. chan->flag |= HOSTAPD_CHAN_HT40;
  1187. }
  1188. }
  1189. static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start,
  1190. int end)
  1191. {
  1192. int c;
  1193. for (c = 0; c < mode->num_channels; c++) {
  1194. struct hostapd_channel_data *chan = &mode->channels[c];
  1195. if (!(chan->flag & HOSTAPD_CHAN_HT40))
  1196. continue;
  1197. if (chan->freq - 30 >= start && chan->freq - 10 <= end)
  1198. chan->flag |= HOSTAPD_CHAN_HT40MINUS;
  1199. if (chan->freq + 10 >= start && chan->freq + 30 <= end)
  1200. chan->flag |= HOSTAPD_CHAN_HT40PLUS;
  1201. }
  1202. }
  1203. static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp,
  1204. struct phy_info_arg *results)
  1205. {
  1206. u16 m;
  1207. for (m = 0; m < *results->num_modes; m++) {
  1208. int c;
  1209. struct hostapd_hw_modes *mode = &results->modes[m];
  1210. for (c = 0; c < mode->num_channels; c++) {
  1211. struct hostapd_channel_data *chan = &mode->channels[c];
  1212. if ((u32) chan->freq - 10 >= start &&
  1213. (u32) chan->freq + 10 <= end)
  1214. chan->max_tx_power = max_eirp;
  1215. }
  1216. }
  1217. }
  1218. static void nl80211_reg_rule_ht40(u32 start, u32 end,
  1219. struct phy_info_arg *results)
  1220. {
  1221. u16 m;
  1222. for (m = 0; m < *results->num_modes; m++) {
  1223. if (!(results->modes[m].ht_capab &
  1224. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
  1225. continue;
  1226. nl80211_set_ht40_mode(&results->modes[m], start, end);
  1227. }
  1228. }
  1229. static void nl80211_reg_rule_sec(struct nlattr *tb[],
  1230. struct phy_info_arg *results)
  1231. {
  1232. u32 start, end, max_bw;
  1233. u16 m;
  1234. if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
  1235. tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
  1236. tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
  1237. return;
  1238. start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
  1239. end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
  1240. max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
  1241. if (max_bw < 20)
  1242. return;
  1243. for (m = 0; m < *results->num_modes; m++) {
  1244. if (!(results->modes[m].ht_capab &
  1245. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
  1246. continue;
  1247. nl80211_set_ht40_mode_sec(&results->modes[m], start, end);
  1248. }
  1249. }
  1250. static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start,
  1251. int end, int max_bw)
  1252. {
  1253. int c;
  1254. for (c = 0; c < mode->num_channels; c++) {
  1255. struct hostapd_channel_data *chan = &mode->channels[c];
  1256. if (chan->freq - 10 >= start && chan->freq + 70 <= end)
  1257. chan->flag |= HOSTAPD_CHAN_VHT_10_70;
  1258. if (chan->freq - 30 >= start && chan->freq + 50 <= end)
  1259. chan->flag |= HOSTAPD_CHAN_VHT_30_50;
  1260. if (chan->freq - 50 >= start && chan->freq + 30 <= end)
  1261. chan->flag |= HOSTAPD_CHAN_VHT_50_30;
  1262. if (chan->freq - 70 >= start && chan->freq + 10 <= end)
  1263. chan->flag |= HOSTAPD_CHAN_VHT_70_10;
  1264. if (max_bw >= 160) {
  1265. if (chan->freq - 10 >= start && chan->freq + 150 <= end)
  1266. chan->flag |= HOSTAPD_CHAN_VHT_10_150;
  1267. if (chan->freq - 30 >= start && chan->freq + 130 <= end)
  1268. chan->flag |= HOSTAPD_CHAN_VHT_30_130;
  1269. if (chan->freq - 50 >= start && chan->freq + 110 <= end)
  1270. chan->flag |= HOSTAPD_CHAN_VHT_50_110;
  1271. if (chan->freq - 70 >= start && chan->freq + 90 <= end)
  1272. chan->flag |= HOSTAPD_CHAN_VHT_70_90;
  1273. if (chan->freq - 90 >= start && chan->freq + 70 <= end)
  1274. chan->flag |= HOSTAPD_CHAN_VHT_90_70;
  1275. if (chan->freq - 110 >= start && chan->freq + 50 <= end)
  1276. chan->flag |= HOSTAPD_CHAN_VHT_110_50;
  1277. if (chan->freq - 130 >= start && chan->freq + 30 <= end)
  1278. chan->flag |= HOSTAPD_CHAN_VHT_130_30;
  1279. if (chan->freq - 150 >= start && chan->freq + 10 <= end)
  1280. chan->flag |= HOSTAPD_CHAN_VHT_150_10;
  1281. }
  1282. }
  1283. }
  1284. static void nl80211_reg_rule_vht(struct nlattr *tb[],
  1285. struct phy_info_arg *results)
  1286. {
  1287. u32 start, end, max_bw;
  1288. u16 m;
  1289. if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
  1290. tb[NL80211_ATTR_FREQ_RANGE_END] == NULL ||
  1291. tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL)
  1292. return;
  1293. start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
  1294. end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
  1295. max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
  1296. if (max_bw < 80)
  1297. return;
  1298. for (m = 0; m < *results->num_modes; m++) {
  1299. if (!(results->modes[m].ht_capab &
  1300. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
  1301. continue;
  1302. /* TODO: use a real VHT support indication */
  1303. if (!results->modes[m].vht_capab)
  1304. continue;
  1305. nl80211_set_vht_mode(&results->modes[m], start, end, max_bw);
  1306. }
  1307. }
  1308. static const char * dfs_domain_name(enum nl80211_dfs_regions region)
  1309. {
  1310. switch (region) {
  1311. case NL80211_DFS_UNSET:
  1312. return "DFS-UNSET";
  1313. case NL80211_DFS_FCC:
  1314. return "DFS-FCC";
  1315. case NL80211_DFS_ETSI:
  1316. return "DFS-ETSI";
  1317. case NL80211_DFS_JP:
  1318. return "DFS-JP";
  1319. default:
  1320. return "DFS-invalid";
  1321. }
  1322. }
  1323. static int nl80211_get_reg(struct nl_msg *msg, void *arg)
  1324. {
  1325. struct phy_info_arg *results = arg;
  1326. struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
  1327. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  1328. struct nlattr *nl_rule;
  1329. struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
  1330. int rem_rule;
  1331. static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
  1332. [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
  1333. [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
  1334. [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
  1335. [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
  1336. [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
  1337. [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
  1338. };
  1339. nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  1340. genlmsg_attrlen(gnlh, 0), NULL);
  1341. if (!tb_msg[NL80211_ATTR_REG_ALPHA2] ||
  1342. !tb_msg[NL80211_ATTR_REG_RULES]) {
  1343. wpa_printf(MSG_DEBUG, "nl80211: No regulatory information "
  1344. "available");
  1345. return NL_SKIP;
  1346. }
  1347. if (tb_msg[NL80211_ATTR_DFS_REGION]) {
  1348. enum nl80211_dfs_regions dfs_domain;
  1349. dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
  1350. wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)",
  1351. (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]),
  1352. dfs_domain_name(dfs_domain));
  1353. } else {
  1354. wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s",
  1355. (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]));
  1356. }
  1357. nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
  1358. {
  1359. u32 start, end, max_eirp = 0, max_bw = 0, flags = 0;
  1360. nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
  1361. nla_data(nl_rule), nla_len(nl_rule), reg_policy);
  1362. if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL ||
  1363. tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL)
  1364. continue;
  1365. start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000;
  1366. end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000;
  1367. if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
  1368. max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100;
  1369. if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW])
  1370. max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000;
  1371. if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS])
  1372. flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
  1373. wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s",
  1374. start, end, max_bw, max_eirp,
  1375. flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "",
  1376. flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "",
  1377. flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "",
  1378. flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" :
  1379. "",
  1380. flags & NL80211_RRF_DFS ? " (DFS)" : "",
  1381. flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "",
  1382. flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "",
  1383. flags & NL80211_RRF_NO_IR ? " (no IR)" : "");
  1384. if (max_bw >= 40)
  1385. nl80211_reg_rule_ht40(start, end, results);
  1386. if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP])
  1387. nl80211_reg_rule_max_eirp(start, end, max_eirp,
  1388. results);
  1389. }
  1390. nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
  1391. {
  1392. nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
  1393. nla_data(nl_rule), nla_len(nl_rule), reg_policy);
  1394. nl80211_reg_rule_sec(tb_rule, results);
  1395. }
  1396. nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule)
  1397. {
  1398. nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX,
  1399. nla_data(nl_rule), nla_len(nl_rule), reg_policy);
  1400. nl80211_reg_rule_vht(tb_rule, results);
  1401. }
  1402. return NL_SKIP;
  1403. }
  1404. static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv,
  1405. struct phy_info_arg *results)
  1406. {
  1407. struct nl_msg *msg;
  1408. msg = nlmsg_alloc();
  1409. if (!msg)
  1410. return -ENOMEM;
  1411. nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
  1412. return send_and_recv_msgs(drv, msg, nl80211_get_reg, results);
  1413. }
  1414. struct hostapd_hw_modes *
  1415. nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
  1416. {
  1417. u32 feat;
  1418. struct i802_bss *bss = priv;
  1419. struct wpa_driver_nl80211_data *drv = bss->drv;
  1420. int nl_flags = 0;
  1421. struct nl_msg *msg;
  1422. struct phy_info_arg result = {
  1423. .num_modes = num_modes,
  1424. .modes = NULL,
  1425. .last_mode = -1,
  1426. .failed = 0,
  1427. };
  1428. *num_modes = 0;
  1429. *flags = 0;
  1430. feat = get_nl80211_protocol_features(drv);
  1431. if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
  1432. nl_flags = NLM_F_DUMP;
  1433. if (!(msg = nl80211_cmd_msg(bss, nl_flags, NL80211_CMD_GET_WIPHY)) ||
  1434. nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP)) {
  1435. nlmsg_free(msg);
  1436. return NULL;
  1437. }
  1438. if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) {
  1439. nl80211_set_regulatory_flags(drv, &result);
  1440. if (result.failed) {
  1441. int i;
  1442. for (i = 0; result.modes && i < *num_modes; i++) {
  1443. os_free(result.modes[i].channels);
  1444. os_free(result.modes[i].rates);
  1445. }
  1446. os_free(result.modes);
  1447. return NULL;
  1448. }
  1449. return wpa_driver_nl80211_postprocess_modes(result.modes,
  1450. num_modes);
  1451. }
  1452. return NULL;
  1453. }