driver_atheros.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  1. /*
  2. * hostapd / Driver interaction with Atheros driver
  3. * Copyright (c) 2004, Sam Leffler <sam@errno.com>
  4. * Copyright (c) 2004, Video54 Technologies
  5. * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
  6. * Copyright (c) 2009, Atheros Communications
  7. *
  8. * This software may be distributed under the terms of the BSD license.
  9. * See README for more details.
  10. */
  11. #include "includes.h"
  12. #include <net/if.h>
  13. #include <sys/ioctl.h>
  14. #include "common.h"
  15. #include "eloop.h"
  16. #include "common/ieee802_11_defs.h"
  17. #include "l2_packet/l2_packet.h"
  18. #include "p2p/p2p.h"
  19. #include "common.h"
  20. #ifndef _BYTE_ORDER
  21. #ifdef WORDS_BIGENDIAN
  22. #define _BYTE_ORDER _BIG_ENDIAN
  23. #else
  24. #define _BYTE_ORDER _LITTLE_ENDIAN
  25. #endif
  26. #endif /* _BYTE_ORDER */
  27. /*
  28. * Note, the ATH_WPS_IE setting must match with the driver build.. If the
  29. * driver does not include this, the IEEE80211_IOCTL_GETWPAIE ioctl will fail.
  30. */
  31. #define ATH_WPS_IE
  32. #include "ieee80211_external.h"
  33. #ifdef CONFIG_WPS
  34. #include <netpacket/packet.h>
  35. #endif /* CONFIG_WPS */
  36. #ifndef ETH_P_80211_RAW
  37. #define ETH_P_80211_RAW 0x0019
  38. #endif
  39. #include "linux_wext.h"
  40. #include "driver.h"
  41. #include "eloop.h"
  42. #include "priv_netlink.h"
  43. #include "l2_packet/l2_packet.h"
  44. #include "common/ieee802_11_defs.h"
  45. #include "netlink.h"
  46. #include "linux_ioctl.h"
  47. struct atheros_driver_data {
  48. struct hostapd_data *hapd; /* back pointer */
  49. char iface[IFNAMSIZ + 1];
  50. int ifindex;
  51. struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
  52. struct l2_packet_data *sock_recv; /* raw packet recv socket */
  53. int ioctl_sock; /* socket for ioctl() use */
  54. struct netlink_data *netlink;
  55. int we_version;
  56. u8 acct_mac[ETH_ALEN];
  57. struct hostap_sta_driver_data acct_data;
  58. struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
  59. struct wpabuf *wpa_ie;
  60. struct wpabuf *wps_beacon_ie;
  61. struct wpabuf *wps_probe_resp_ie;
  62. u8 own_addr[ETH_ALEN];
  63. };
  64. static int atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
  65. int reason_code);
  66. static int atheros_set_privacy(void *priv, int enabled);
  67. static const char * athr_get_ioctl_name(int op)
  68. {
  69. switch (op) {
  70. case IEEE80211_IOCTL_SETPARAM:
  71. return "SETPARAM";
  72. case IEEE80211_IOCTL_GETPARAM:
  73. return "GETPARAM";
  74. case IEEE80211_IOCTL_SETKEY:
  75. return "SETKEY";
  76. case IEEE80211_IOCTL_SETWMMPARAMS:
  77. return "SETWMMPARAMS";
  78. case IEEE80211_IOCTL_DELKEY:
  79. return "DELKEY";
  80. case IEEE80211_IOCTL_GETWMMPARAMS:
  81. return "GETWMMPARAMS";
  82. case IEEE80211_IOCTL_SETMLME:
  83. return "SETMLME";
  84. case IEEE80211_IOCTL_GETCHANINFO:
  85. return "GETCHANINFO";
  86. case IEEE80211_IOCTL_SETOPTIE:
  87. return "SETOPTIE";
  88. case IEEE80211_IOCTL_GETOPTIE:
  89. return "GETOPTIE";
  90. case IEEE80211_IOCTL_ADDMAC:
  91. return "ADDMAC";
  92. case IEEE80211_IOCTL_DELMAC:
  93. return "DELMAC";
  94. case IEEE80211_IOCTL_GETCHANLIST:
  95. return "GETCHANLIST";
  96. case IEEE80211_IOCTL_SETCHANLIST:
  97. return "SETCHANLIST";
  98. case IEEE80211_IOCTL_KICKMAC:
  99. return "KICKMAC";
  100. case IEEE80211_IOCTL_CHANSWITCH:
  101. return "CHANSWITCH";
  102. case IEEE80211_IOCTL_GETMODE:
  103. return "GETMODE";
  104. case IEEE80211_IOCTL_SETMODE:
  105. return "SETMODE";
  106. case IEEE80211_IOCTL_GET_APPIEBUF:
  107. return "GET_APPIEBUF";
  108. case IEEE80211_IOCTL_SET_APPIEBUF:
  109. return "SET_APPIEBUF";
  110. case IEEE80211_IOCTL_SET_ACPARAMS:
  111. return "SET_ACPARAMS";
  112. case IEEE80211_IOCTL_FILTERFRAME:
  113. return "FILTERFRAME";
  114. case IEEE80211_IOCTL_SET_RTPARAMS:
  115. return "SET_RTPARAMS";
  116. case IEEE80211_IOCTL_SET_MEDENYENTRY:
  117. return "SET_MEDENYENTRY";
  118. case IEEE80211_IOCTL_GET_MACADDR:
  119. return "GET_MACADDR";
  120. case IEEE80211_IOCTL_SET_HBRPARAMS:
  121. return "SET_HBRPARAMS";
  122. case IEEE80211_IOCTL_SET_RXTIMEOUT:
  123. return "SET_RXTIMEOUT";
  124. case IEEE80211_IOCTL_STA_STATS:
  125. return "STA_STATS";
  126. case IEEE80211_IOCTL_GETWPAIE:
  127. return "GETWPAIE";
  128. default:
  129. return "??";
  130. }
  131. }
  132. static const char * athr_get_param_name(int op)
  133. {
  134. switch (op) {
  135. case IEEE80211_IOC_MCASTCIPHER:
  136. return "MCASTCIPHER";
  137. case IEEE80211_PARAM_MCASTKEYLEN:
  138. return "MCASTKEYLEN";
  139. case IEEE80211_PARAM_UCASTCIPHERS:
  140. return "UCASTCIPHERS";
  141. case IEEE80211_PARAM_KEYMGTALGS:
  142. return "KEYMGTALGS";
  143. case IEEE80211_PARAM_RSNCAPS:
  144. return "RSNCAPS";
  145. case IEEE80211_PARAM_WPA:
  146. return "WPA";
  147. case IEEE80211_PARAM_AUTHMODE:
  148. return "AUTHMODE";
  149. case IEEE80211_PARAM_PRIVACY:
  150. return "PRIVACY";
  151. case IEEE80211_PARAM_COUNTERMEASURES:
  152. return "COUNTERMEASURES";
  153. default:
  154. return "??";
  155. }
  156. }
  157. static int
  158. set80211priv(struct atheros_driver_data *drv, int op, void *data, int len)
  159. {
  160. struct iwreq iwr;
  161. int do_inline = len < IFNAMSIZ;
  162. /* Certain ioctls must use the non-inlined method */
  163. if (op == IEEE80211_IOCTL_SET_APPIEBUF ||
  164. op == IEEE80211_IOCTL_FILTERFRAME)
  165. do_inline = 0;
  166. memset(&iwr, 0, sizeof(iwr));
  167. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  168. if (do_inline) {
  169. /*
  170. * Argument data fits inline; put it there.
  171. */
  172. memcpy(iwr.u.name, data, len);
  173. } else {
  174. /*
  175. * Argument data too big for inline transfer; setup a
  176. * parameter block instead; the kernel will transfer
  177. * the data for the driver.
  178. */
  179. iwr.u.data.pointer = data;
  180. iwr.u.data.length = len;
  181. }
  182. if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {
  183. wpa_printf(MSG_DEBUG, "atheros: %s: %s: ioctl op=0x%x "
  184. "(%s) len=%d failed: %d (%s)",
  185. __func__, drv->iface, op,
  186. athr_get_ioctl_name(op),
  187. len, errno, strerror(errno));
  188. return -1;
  189. }
  190. return 0;
  191. }
  192. static int
  193. set80211param(struct atheros_driver_data *drv, int op, int arg)
  194. {
  195. struct iwreq iwr;
  196. memset(&iwr, 0, sizeof(iwr));
  197. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  198. iwr.u.mode = op;
  199. memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
  200. if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
  201. wpa_printf(MSG_INFO,
  202. "%s: %s: Failed to set parameter (op %d (%s) arg %d): ioctl[IEEE80211_IOCTL_SETPARAM]: %s",
  203. __func__, drv->iface, op, athr_get_param_name(op),
  204. arg, strerror(errno));
  205. return -1;
  206. }
  207. return 0;
  208. }
  209. #ifndef CONFIG_NO_STDOUT_DEBUG
  210. static const char *
  211. ether_sprintf(const u8 *addr)
  212. {
  213. static char buf[sizeof(MACSTR)];
  214. if (addr != NULL)
  215. snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
  216. else
  217. snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
  218. return buf;
  219. }
  220. #endif /* CONFIG_NO_STDOUT_DEBUG */
  221. /*
  222. * Configure WPA parameters.
  223. */
  224. static int
  225. atheros_configure_wpa(struct atheros_driver_data *drv,
  226. struct wpa_bss_params *params)
  227. {
  228. int v;
  229. switch (params->wpa_group) {
  230. case WPA_CIPHER_CCMP:
  231. v = IEEE80211_CIPHER_AES_CCM;
  232. break;
  233. #ifdef ATH_GCM_SUPPORT
  234. case WPA_CIPHER_CCMP_256:
  235. v = IEEE80211_CIPHER_AES_CCM_256;
  236. break;
  237. case WPA_CIPHER_GCMP:
  238. v = IEEE80211_CIPHER_AES_GCM;
  239. break;
  240. case WPA_CIPHER_GCMP_256:
  241. v = IEEE80211_CIPHER_AES_GCM_256;
  242. break;
  243. #endif /* ATH_GCM_SUPPORT */
  244. case WPA_CIPHER_TKIP:
  245. v = IEEE80211_CIPHER_TKIP;
  246. break;
  247. case WPA_CIPHER_WEP104:
  248. v = IEEE80211_CIPHER_WEP;
  249. break;
  250. case WPA_CIPHER_WEP40:
  251. v = IEEE80211_CIPHER_WEP;
  252. break;
  253. case WPA_CIPHER_NONE:
  254. v = IEEE80211_CIPHER_NONE;
  255. break;
  256. default:
  257. wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
  258. params->wpa_group);
  259. return -1;
  260. }
  261. wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);
  262. if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {
  263. wpa_printf(MSG_INFO, "Unable to set group key cipher to %u", v);
  264. return -1;
  265. }
  266. if (v == IEEE80211_CIPHER_WEP) {
  267. /* key length is done only for specific ciphers */
  268. v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
  269. if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {
  270. wpa_printf(MSG_INFO,
  271. "Unable to set group key length to %u", v);
  272. return -1;
  273. }
  274. }
  275. v = 0;
  276. if (params->wpa_pairwise & WPA_CIPHER_CCMP)
  277. v |= 1<<IEEE80211_CIPHER_AES_CCM;
  278. #ifdef ATH_GCM_SUPPORT
  279. if (params->wpa_pairwise & WPA_CIPHER_CCMP_256)
  280. v |= 1<<IEEE80211_CIPHER_AES_CCM_256;
  281. if (params->wpa_pairwise & WPA_CIPHER_GCMP)
  282. v |= 1<<IEEE80211_CIPHER_AES_GCM;
  283. if (params->wpa_pairwise & WPA_CIPHER_GCMP_256)
  284. v |= 1<<IEEE80211_CIPHER_AES_GCM_256;
  285. #endif /* ATH_GCM_SUPPORT */
  286. if (params->wpa_pairwise & WPA_CIPHER_TKIP)
  287. v |= 1<<IEEE80211_CIPHER_TKIP;
  288. if (params->wpa_pairwise & WPA_CIPHER_NONE)
  289. v |= 1<<IEEE80211_CIPHER_NONE;
  290. wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
  291. if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {
  292. wpa_printf(MSG_INFO,
  293. "Unable to set pairwise key ciphers to 0x%x", v);
  294. return -1;
  295. }
  296. wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
  297. __func__, params->wpa_key_mgmt);
  298. if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS,
  299. params->wpa_key_mgmt)) {
  300. wpa_printf(MSG_INFO,
  301. "Unable to set key management algorithms to 0x%x",
  302. params->wpa_key_mgmt);
  303. return -1;
  304. }
  305. v = 0;
  306. if (params->rsn_preauth)
  307. v |= BIT(0);
  308. #ifdef CONFIG_IEEE80211W
  309. if (params->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  310. v |= BIT(7);
  311. if (params->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
  312. v |= BIT(6);
  313. }
  314. #endif /* CONFIG_IEEE80211W */
  315. wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", __func__, v);
  316. if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
  317. wpa_printf(MSG_INFO, "Unable to set RSN capabilities to 0x%x",
  318. v);
  319. return -1;
  320. }
  321. wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, params->wpa);
  322. if (set80211param(drv, IEEE80211_PARAM_WPA, params->wpa)) {
  323. wpa_printf(MSG_INFO, "Unable to set WPA to %u", params->wpa);
  324. return -1;
  325. }
  326. return 0;
  327. }
  328. static int
  329. atheros_set_ieee8021x(void *priv, struct wpa_bss_params *params)
  330. {
  331. struct atheros_driver_data *drv = priv;
  332. wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
  333. if (!params->enabled) {
  334. /* XXX restore state */
  335. if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
  336. IEEE80211_AUTH_AUTO) < 0)
  337. return -1;
  338. /* IEEE80211_AUTH_AUTO ends up enabling Privacy; clear that */
  339. return atheros_set_privacy(drv, 0);
  340. }
  341. if (!params->wpa && !params->ieee802_1x) {
  342. wpa_printf(MSG_WARNING, "No 802.1X or WPA enabled!");
  343. return -1;
  344. }
  345. if (params->wpa && atheros_configure_wpa(drv, params) != 0) {
  346. wpa_printf(MSG_WARNING, "Error configuring WPA state!");
  347. return -1;
  348. }
  349. if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
  350. (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
  351. wpa_printf(MSG_WARNING, "Error enabling WPA/802.1X!");
  352. return -1;
  353. }
  354. return 0;
  355. }
  356. static int
  357. atheros_set_privacy(void *priv, int enabled)
  358. {
  359. struct atheros_driver_data *drv = priv;
  360. wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
  361. return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
  362. }
  363. static int
  364. atheros_set_sta_authorized(void *priv, const u8 *addr, int authorized)
  365. {
  366. struct atheros_driver_data *drv = priv;
  367. struct ieee80211req_mlme mlme;
  368. int ret;
  369. wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
  370. __func__, ether_sprintf(addr), authorized);
  371. if (authorized)
  372. mlme.im_op = IEEE80211_MLME_AUTHORIZE;
  373. else
  374. mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
  375. mlme.im_reason = 0;
  376. memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
  377. ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
  378. if (ret < 0) {
  379. wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
  380. __func__, authorized ? "" : "un", MAC2STR(addr));
  381. }
  382. return ret;
  383. }
  384. static int
  385. atheros_sta_set_flags(void *priv, const u8 *addr,
  386. unsigned int total_flags, unsigned int flags_or,
  387. unsigned int flags_and)
  388. {
  389. /* For now, only support setting Authorized flag */
  390. if (flags_or & WPA_STA_AUTHORIZED)
  391. return atheros_set_sta_authorized(priv, addr, 1);
  392. if (!(flags_and & WPA_STA_AUTHORIZED))
  393. return atheros_set_sta_authorized(priv, addr, 0);
  394. return 0;
  395. }
  396. static int
  397. atheros_del_key(void *priv, const u8 *addr, int key_idx)
  398. {
  399. struct atheros_driver_data *drv = priv;
  400. struct ieee80211req_del_key wk;
  401. int ret;
  402. wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
  403. __func__, ether_sprintf(addr), key_idx);
  404. memset(&wk, 0, sizeof(wk));
  405. if (addr != NULL) {
  406. memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
  407. wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
  408. } else {
  409. wk.idk_keyix = key_idx;
  410. }
  411. ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
  412. if (ret < 0) {
  413. wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
  414. " key_idx %d)", __func__, ether_sprintf(addr),
  415. key_idx);
  416. }
  417. return ret;
  418. }
  419. static int
  420. atheros_set_key(const char *ifname, void *priv, enum wpa_alg alg,
  421. const u8 *addr, int key_idx, int set_tx, const u8 *seq,
  422. size_t seq_len, const u8 *key, size_t key_len)
  423. {
  424. struct atheros_driver_data *drv = priv;
  425. struct ieee80211req_key wk;
  426. u_int8_t cipher;
  427. int ret;
  428. if (alg == WPA_ALG_NONE)
  429. return atheros_del_key(drv, addr, key_idx);
  430. wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
  431. __func__, alg, ether_sprintf(addr), key_idx);
  432. switch (alg) {
  433. case WPA_ALG_WEP:
  434. cipher = IEEE80211_CIPHER_WEP;
  435. break;
  436. case WPA_ALG_TKIP:
  437. cipher = IEEE80211_CIPHER_TKIP;
  438. break;
  439. case WPA_ALG_CCMP:
  440. cipher = IEEE80211_CIPHER_AES_CCM;
  441. break;
  442. #ifdef ATH_GCM_SUPPORT
  443. case WPA_ALG_CCMP_256:
  444. cipher = IEEE80211_CIPHER_AES_CCM_256;
  445. break;
  446. case WPA_ALG_GCMP:
  447. cipher = IEEE80211_CIPHER_AES_GCM;
  448. break;
  449. case WPA_ALG_GCMP_256:
  450. cipher = IEEE80211_CIPHER_AES_GCM_256;
  451. break;
  452. #endif /* ATH_GCM_SUPPORT */
  453. #ifdef CONFIG_IEEE80211W
  454. case WPA_ALG_IGTK:
  455. cipher = IEEE80211_CIPHER_AES_CMAC;
  456. break;
  457. #ifdef ATH_GCM_SUPPORT
  458. case WPA_ALG_BIP_CMAC_256:
  459. cipher = IEEE80211_CIPHER_AES_CMAC_256;
  460. break;
  461. case WPA_ALG_BIP_GMAC_128:
  462. cipher = IEEE80211_CIPHER_AES_GMAC;
  463. break;
  464. case WPA_ALG_BIP_GMAC_256:
  465. cipher = IEEE80211_CIPHER_AES_GMAC_256;
  466. break;
  467. #endif /* ATH_GCM_SUPPORT */
  468. #endif /* CONFIG_IEEE80211W */
  469. default:
  470. wpa_printf(MSG_INFO, "%s: unknown/unsupported algorithm %d",
  471. __func__, alg);
  472. return -1;
  473. }
  474. if (key_len > sizeof(wk.ik_keydata)) {
  475. wpa_printf(MSG_INFO, "%s: key length %lu too big", __func__,
  476. (unsigned long) key_len);
  477. return -3;
  478. }
  479. memset(&wk, 0, sizeof(wk));
  480. wk.ik_type = cipher;
  481. wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
  482. if (addr == NULL || is_broadcast_ether_addr(addr)) {
  483. memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
  484. wk.ik_keyix = key_idx;
  485. if (set_tx)
  486. wk.ik_flags |= IEEE80211_KEY_DEFAULT;
  487. } else {
  488. memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
  489. wk.ik_keyix = IEEE80211_KEYIX_NONE;
  490. }
  491. wk.ik_keylen = key_len;
  492. memcpy(wk.ik_keydata, key, key_len);
  493. ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
  494. if (ret < 0) {
  495. wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
  496. " key_idx %d alg %d key_len %lu set_tx %d)",
  497. __func__, ether_sprintf(wk.ik_macaddr), key_idx,
  498. alg, (unsigned long) key_len, set_tx);
  499. }
  500. return ret;
  501. }
  502. static int
  503. atheros_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
  504. u8 *seq)
  505. {
  506. struct atheros_driver_data *drv = priv;
  507. struct ieee80211req_key wk;
  508. wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
  509. __func__, ether_sprintf(addr), idx);
  510. memset(&wk, 0, sizeof(wk));
  511. if (addr == NULL)
  512. memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
  513. else
  514. memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
  515. wk.ik_keyix = idx;
  516. if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
  517. wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
  518. "(addr " MACSTR " key_idx %d)",
  519. __func__, MAC2STR(wk.ik_macaddr), idx);
  520. return -1;
  521. }
  522. #ifdef WORDS_BIGENDIAN
  523. {
  524. /*
  525. * wk.ik_keytsc is in host byte order (big endian), need to
  526. * swap it to match with the byte order used in WPA.
  527. */
  528. int i;
  529. #ifndef WPA_KEY_RSC_LEN
  530. #define WPA_KEY_RSC_LEN 8
  531. #endif
  532. u8 tmp[WPA_KEY_RSC_LEN];
  533. memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
  534. for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
  535. seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
  536. }
  537. }
  538. #else /* WORDS_BIGENDIAN */
  539. memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
  540. #endif /* WORDS_BIGENDIAN */
  541. return 0;
  542. }
  543. static int
  544. atheros_flush(void *priv)
  545. {
  546. u8 allsta[IEEE80211_ADDR_LEN];
  547. memset(allsta, 0xff, IEEE80211_ADDR_LEN);
  548. return atheros_sta_deauth(priv, NULL, allsta,
  549. IEEE80211_REASON_AUTH_LEAVE);
  550. }
  551. static int
  552. atheros_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
  553. const u8 *addr)
  554. {
  555. struct atheros_driver_data *drv = priv;
  556. struct ieee80211req_sta_stats stats;
  557. memset(data, 0, sizeof(*data));
  558. /*
  559. * Fetch statistics for station from the system.
  560. */
  561. memset(&stats, 0, sizeof(stats));
  562. memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
  563. if (set80211priv(drv, IEEE80211_IOCTL_STA_STATS,
  564. &stats, sizeof(stats))) {
  565. wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
  566. MACSTR ")", __func__, MAC2STR(addr));
  567. if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
  568. memcpy(data, &drv->acct_data, sizeof(*data));
  569. return 0;
  570. }
  571. wpa_printf(MSG_INFO,
  572. "Failed to get station stats information element");
  573. return -1;
  574. }
  575. data->rx_packets = stats.is_stats.ns_rx_data;
  576. data->rx_bytes = stats.is_stats.ns_rx_bytes;
  577. data->tx_packets = stats.is_stats.ns_tx_data;
  578. data->tx_bytes = stats.is_stats.ns_tx_bytes;
  579. return 0;
  580. }
  581. static int
  582. atheros_sta_clear_stats(void *priv, const u8 *addr)
  583. {
  584. struct atheros_driver_data *drv = priv;
  585. struct ieee80211req_mlme mlme;
  586. int ret;
  587. wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
  588. mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
  589. memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
  590. ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
  591. sizeof(mlme));
  592. if (ret < 0) {
  593. wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
  594. MACSTR ")", __func__, MAC2STR(addr));
  595. }
  596. return ret;
  597. }
  598. static int
  599. atheros_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
  600. {
  601. struct atheros_driver_data *drv = priv;
  602. u8 buf[512];
  603. struct ieee80211req_getset_appiebuf *app_ie;
  604. wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
  605. (unsigned long) ie_len);
  606. wpa_hexdump(MSG_DEBUG, "atheros: set_generic_elem", ie, ie_len);
  607. wpabuf_free(drv->wpa_ie);
  608. drv->wpa_ie = wpabuf_alloc_copy(ie, ie_len);
  609. app_ie = (struct ieee80211req_getset_appiebuf *) buf;
  610. os_memcpy(&(app_ie->app_buf[0]), ie, ie_len);
  611. app_ie->app_buflen = ie_len;
  612. app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;
  613. /* append WPS IE for Beacon */
  614. if (drv->wps_beacon_ie != NULL) {
  615. os_memcpy(&(app_ie->app_buf[ie_len]),
  616. wpabuf_head(drv->wps_beacon_ie),
  617. wpabuf_len(drv->wps_beacon_ie));
  618. app_ie->app_buflen = ie_len + wpabuf_len(drv->wps_beacon_ie);
  619. }
  620. wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(Beacon)",
  621. app_ie->app_buf, app_ie->app_buflen);
  622. set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
  623. sizeof(struct ieee80211req_getset_appiebuf) +
  624. app_ie->app_buflen);
  625. /* append WPS IE for Probe Response */
  626. app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;
  627. if (drv->wps_probe_resp_ie != NULL) {
  628. os_memcpy(&(app_ie->app_buf[ie_len]),
  629. wpabuf_head(drv->wps_probe_resp_ie),
  630. wpabuf_len(drv->wps_probe_resp_ie));
  631. app_ie->app_buflen = ie_len +
  632. wpabuf_len(drv->wps_probe_resp_ie);
  633. } else
  634. app_ie->app_buflen = ie_len;
  635. wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(ProbeResp)",
  636. app_ie->app_buf, app_ie->app_buflen);
  637. set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
  638. sizeof(struct ieee80211req_getset_appiebuf) +
  639. app_ie->app_buflen);
  640. return 0;
  641. }
  642. static int
  643. atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
  644. int reason_code)
  645. {
  646. struct atheros_driver_data *drv = priv;
  647. struct ieee80211req_mlme mlme;
  648. int ret;
  649. wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
  650. __func__, ether_sprintf(addr), reason_code);
  651. mlme.im_op = IEEE80211_MLME_DEAUTH;
  652. mlme.im_reason = reason_code;
  653. memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
  654. ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
  655. if (ret < 0) {
  656. wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
  657. " reason %d)",
  658. __func__, MAC2STR(addr), reason_code);
  659. }
  660. return ret;
  661. }
  662. static int
  663. atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
  664. int reason_code)
  665. {
  666. struct atheros_driver_data *drv = priv;
  667. struct ieee80211req_mlme mlme;
  668. int ret;
  669. wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
  670. __func__, ether_sprintf(addr), reason_code);
  671. mlme.im_op = IEEE80211_MLME_DISASSOC;
  672. mlme.im_reason = reason_code;
  673. memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
  674. ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
  675. if (ret < 0) {
  676. wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
  677. MACSTR " reason %d)",
  678. __func__, MAC2STR(addr), reason_code);
  679. }
  680. return ret;
  681. }
  682. static int atheros_set_qos_map(void *ctx, const u8 *qos_map_set,
  683. u8 qos_map_set_len)
  684. {
  685. #ifdef CONFIG_ATHEROS_QOS_MAP
  686. struct atheros_driver_data *drv = ctx;
  687. struct ieee80211req_athdbg req;
  688. struct ieee80211_qos_map *qos_map = &req.data.qos_map;
  689. struct iwreq iwr;
  690. int i, up_start;
  691. if (qos_map_set_len < 16 || qos_map_set_len > 58 ||
  692. qos_map_set_len & 1) {
  693. wpa_printf(MSG_ERROR, "Invalid QoS Map");
  694. return -1;
  695. } else {
  696. memset(&req, 0, sizeof(struct ieee80211req_athdbg));
  697. req.cmd = IEEE80211_DBGREQ_SETQOSMAPCONF;
  698. os_memset(&iwr, 0, sizeof(iwr));
  699. os_strlcpy(iwr.ifr_name, drv->iface, sizeof(iwr.ifr_name));
  700. iwr.u.data.pointer = (void *) &req;
  701. iwr.u.data.length = sizeof(struct ieee80211req_athdbg);
  702. }
  703. qos_map->valid = 1;
  704. qos_map->num_dscp_except = (qos_map_set_len - 16) / 2;
  705. if (qos_map->num_dscp_except) {
  706. for (i = 0; i < qos_map->num_dscp_except; i++) {
  707. qos_map->dscp_exception[i].dscp = qos_map_set[i * 2];
  708. qos_map->dscp_exception[i].up = qos_map_set[i * 2 + 1];
  709. }
  710. }
  711. up_start = qos_map_set_len - 16;
  712. for (i = 0; i < IEEE80211_MAX_QOS_UP_RANGE; i++) {
  713. qos_map->up[i].low = qos_map_set[up_start + (i * 2)];
  714. qos_map->up[i].high = qos_map_set[up_start + (i * 2) + 1];
  715. }
  716. if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_DBGREQ, &iwr) < 0) {
  717. wpa_printf(MSG_ERROR,
  718. "%s: %s: Failed to set QoS Map: ioctl[IEEE80211_IOCTL_DBGREQ]: %s",
  719. __func__, drv->iface, strerror(errno));
  720. return -1;
  721. }
  722. #endif /* CONFIG_ATHEROS_QOS_MAP */
  723. return 0;
  724. }
  725. #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_WNM) || defined(CONFIG_HS20)
  726. static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
  727. size_t len)
  728. {
  729. struct atheros_driver_data *drv = ctx;
  730. const struct ieee80211_mgmt *mgmt;
  731. union wpa_event_data event;
  732. u16 fc, stype;
  733. int ielen;
  734. const u8 *iebuf;
  735. if (len < IEEE80211_HDRLEN)
  736. return;
  737. mgmt = (const struct ieee80211_mgmt *) buf;
  738. fc = le_to_host16(mgmt->frame_control);
  739. if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
  740. return;
  741. stype = WLAN_FC_GET_STYPE(fc);
  742. wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
  743. (int) len);
  744. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  745. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
  746. return;
  747. os_memset(&event, 0, sizeof(event));
  748. event.rx_probe_req.sa = mgmt->sa;
  749. event.rx_probe_req.da = mgmt->da;
  750. event.rx_probe_req.bssid = mgmt->bssid;
  751. event.rx_probe_req.ie = mgmt->u.probe_req.variable;
  752. event.rx_probe_req.ie_len =
  753. len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
  754. wpa_supplicant_event(drv->hapd, EVENT_RX_PROBE_REQ, &event);
  755. return;
  756. }
  757. if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
  758. wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
  759. __func__);
  760. return;
  761. }
  762. switch (stype) {
  763. case WLAN_FC_STYPE_ASSOC_REQ:
  764. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req))
  765. break;
  766. ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
  767. iebuf = mgmt->u.assoc_req.variable;
  768. drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 0);
  769. break;
  770. case WLAN_FC_STYPE_REASSOC_REQ:
  771. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req))
  772. break;
  773. ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
  774. iebuf = mgmt->u.reassoc_req.variable;
  775. drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 1);
  776. break;
  777. case WLAN_FC_STYPE_ACTION:
  778. os_memset(&event, 0, sizeof(event));
  779. event.rx_mgmt.frame = buf;
  780. event.rx_mgmt.frame_len = len;
  781. wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
  782. break;
  783. case WLAN_FC_STYPE_AUTH:
  784. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth))
  785. break;
  786. os_memset(&event, 0, sizeof(event));
  787. os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
  788. os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
  789. event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
  790. event.auth.status_code =
  791. le_to_host16(mgmt->u.auth.status_code);
  792. event.auth.auth_transaction =
  793. le_to_host16(mgmt->u.auth.auth_transaction);
  794. event.auth.ies = mgmt->u.auth.variable;
  795. event.auth.ies_len = len - IEEE80211_HDRLEN -
  796. sizeof(mgmt->u.auth);
  797. wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
  798. break;
  799. default:
  800. break;
  801. }
  802. }
  803. #endif
  804. static int atheros_receive_pkt(struct atheros_driver_data *drv)
  805. {
  806. int ret = 0;
  807. struct ieee80211req_set_filter filt;
  808. wpa_printf(MSG_DEBUG, "%s Enter", __func__);
  809. filt.app_filterype = 0;
  810. #ifdef CONFIG_WPS
  811. filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
  812. #endif /* CONFIG_WPS */
  813. #ifdef CONFIG_IEEE80211R
  814. filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
  815. IEEE80211_FILTER_TYPE_AUTH |
  816. IEEE80211_FILTER_TYPE_ACTION);
  817. #endif
  818. #ifdef CONFIG_WNM
  819. filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
  820. #endif /* CONFIG_WNM */
  821. #ifdef CONFIG_HS20
  822. filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
  823. #endif /* CONFIG_HS20 */
  824. if (filt.app_filterype) {
  825. ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
  826. sizeof(struct ieee80211req_set_filter));
  827. if (ret)
  828. return ret;
  829. }
  830. #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R)
  831. drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
  832. atheros_raw_receive, drv, 1);
  833. if (drv->sock_raw == NULL)
  834. return -1;
  835. #endif /* CONFIG_WPS || CONFIG_IEEE80211R */
  836. return ret;
  837. }
  838. static int atheros_reset_appfilter(struct atheros_driver_data *drv)
  839. {
  840. struct ieee80211req_set_filter filt;
  841. filt.app_filterype = 0;
  842. return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
  843. sizeof(struct ieee80211req_set_filter));
  844. }
  845. #ifdef CONFIG_WPS
  846. static int
  847. atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
  848. {
  849. struct atheros_driver_data *drv = priv;
  850. u8 buf[512];
  851. struct ieee80211req_getset_appiebuf *beac_ie;
  852. wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
  853. (unsigned long) len, frametype);
  854. wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
  855. beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
  856. beac_ie->app_frmtype = frametype;
  857. beac_ie->app_buflen = len;
  858. os_memcpy(&(beac_ie->app_buf[0]), ie, len);
  859. /* append the WPA/RSN IE if it is set already */
  860. if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
  861. (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
  862. (drv->wpa_ie != NULL)) {
  863. wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
  864. drv->wpa_ie);
  865. os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
  866. wpabuf_len(drv->wpa_ie));
  867. beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
  868. }
  869. wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
  870. beac_ie->app_buf, beac_ie->app_buflen);
  871. return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
  872. sizeof(struct ieee80211req_getset_appiebuf) +
  873. beac_ie->app_buflen);
  874. }
  875. static int
  876. atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
  877. const struct wpabuf *proberesp,
  878. const struct wpabuf *assocresp)
  879. {
  880. struct atheros_driver_data *drv = priv;
  881. wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
  882. wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
  883. proberesp);
  884. wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
  885. assocresp);
  886. wpabuf_free(drv->wps_beacon_ie);
  887. drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
  888. wpabuf_free(drv->wps_probe_resp_ie);
  889. drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
  890. atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
  891. assocresp ? wpabuf_len(assocresp) : 0,
  892. IEEE80211_APPIE_FRAME_ASSOC_RESP);
  893. if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
  894. beacon ? wpabuf_len(beacon) : 0,
  895. IEEE80211_APPIE_FRAME_BEACON))
  896. return -1;
  897. return atheros_set_wps_ie(priv,
  898. proberesp ? wpabuf_head(proberesp) : NULL,
  899. proberesp ? wpabuf_len(proberesp): 0,
  900. IEEE80211_APPIE_FRAME_PROBE_RESP);
  901. }
  902. #else /* CONFIG_WPS */
  903. #define atheros_set_ap_wps_ie NULL
  904. #endif /* CONFIG_WPS */
  905. #ifdef CONFIG_IEEE80211R
  906. static int
  907. atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
  908. u16 status_code, const u8 *ie, size_t len)
  909. {
  910. struct atheros_driver_data *drv = priv;
  911. struct ieee80211req_mlme mlme;
  912. int ret;
  913. wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
  914. __func__, ether_sprintf(addr), status_code);
  915. mlme.im_op = IEEE80211_MLME_AUTH;
  916. mlme.im_reason = status_code;
  917. mlme.im_seq = seq;
  918. os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
  919. mlme.im_optie_len = len;
  920. if (len) {
  921. if (len < IEEE80211_MAX_OPT_IE) {
  922. os_memcpy(mlme.im_optie, ie, len);
  923. } else {
  924. wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
  925. "opt_ie STA (addr " MACSTR " reason %d, "
  926. "ie_len %d)",
  927. __func__, MAC2STR(addr), status_code,
  928. (int) len);
  929. return -1;
  930. }
  931. }
  932. ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
  933. if (ret < 0) {
  934. wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
  935. " reason %d)",
  936. __func__, MAC2STR(addr), status_code);
  937. }
  938. return ret;
  939. }
  940. static int
  941. atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
  942. int reassoc, u16 status_code, const u8 *ie, size_t len)
  943. {
  944. struct atheros_driver_data *drv = priv;
  945. struct ieee80211req_mlme mlme;
  946. int ret;
  947. wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
  948. __func__, ether_sprintf(addr), status_code, reassoc);
  949. if (reassoc)
  950. mlme.im_op = IEEE80211_MLME_REASSOC;
  951. else
  952. mlme.im_op = IEEE80211_MLME_ASSOC;
  953. mlme.im_reason = status_code;
  954. os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
  955. mlme.im_optie_len = len;
  956. if (len) {
  957. if (len < IEEE80211_MAX_OPT_IE) {
  958. os_memcpy(mlme.im_optie, ie, len);
  959. } else {
  960. wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
  961. "opt_ie STA (addr " MACSTR " reason %d, "
  962. "ie_len %d)",
  963. __func__, MAC2STR(addr), status_code,
  964. (int) len);
  965. return -1;
  966. }
  967. }
  968. ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
  969. if (ret < 0) {
  970. wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
  971. " reason %d)",
  972. __func__, MAC2STR(addr), status_code);
  973. }
  974. return ret;
  975. }
  976. #endif /* CONFIG_IEEE80211R */
  977. static void
  978. atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
  979. {
  980. struct hostapd_data *hapd = drv->hapd;
  981. struct ieee80211req_wpaie ie;
  982. int ielen = 0;
  983. u8 *iebuf = NULL;
  984. /*
  985. * Fetch negotiated WPA/RSN parameters from the system.
  986. */
  987. memset(&ie, 0, sizeof(ie));
  988. memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
  989. if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
  990. /*
  991. * See ATH_WPS_IE comment in the beginning of the file for a
  992. * possible cause for the failure..
  993. */
  994. wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
  995. __func__, strerror(errno));
  996. goto no_ie;
  997. }
  998. wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
  999. ie.wpa_ie, IEEE80211_MAX_OPT_IE);
  1000. wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
  1001. ie.rsn_ie, IEEE80211_MAX_OPT_IE);
  1002. #ifdef ATH_WPS_IE
  1003. wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
  1004. ie.wps_ie, IEEE80211_MAX_OPT_IE);
  1005. #endif /* ATH_WPS_IE */
  1006. iebuf = ie.wpa_ie;
  1007. /* atheros seems to return some random data if WPA/RSN IE is not set.
  1008. * Assume the IE was not included if the IE type is unknown. */
  1009. if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
  1010. iebuf[1] = 0;
  1011. if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
  1012. /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
  1013. * set. This is needed for WPA2. */
  1014. iebuf = ie.rsn_ie;
  1015. if (iebuf[0] != WLAN_EID_RSN)
  1016. iebuf[1] = 0;
  1017. }
  1018. ielen = iebuf[1];
  1019. #ifdef ATH_WPS_IE
  1020. /* if WPS IE is present, preference is given to WPS */
  1021. if (ie.wps_ie &&
  1022. (ie.wps_ie[1] > 0 && (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC))) {
  1023. iebuf = ie.wps_ie;
  1024. ielen = ie.wps_ie[1];
  1025. }
  1026. #endif /* ATH_WPS_IE */
  1027. if (ielen == 0)
  1028. iebuf = NULL;
  1029. else
  1030. ielen += 2;
  1031. no_ie:
  1032. drv_event_assoc(hapd, addr, iebuf, ielen, 0);
  1033. if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
  1034. /* Cached accounting data is not valid anymore. */
  1035. memset(drv->acct_mac, 0, ETH_ALEN);
  1036. memset(&drv->acct_data, 0, sizeof(drv->acct_data));
  1037. }
  1038. }
  1039. static void
  1040. atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
  1041. char *custom, char *end)
  1042. {
  1043. wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
  1044. if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
  1045. char *pos;
  1046. u8 addr[ETH_ALEN];
  1047. pos = strstr(custom, "addr=");
  1048. if (pos == NULL) {
  1049. wpa_printf(MSG_DEBUG,
  1050. "MLME-MICHAELMICFAILURE.indication "
  1051. "without sender address ignored");
  1052. return;
  1053. }
  1054. pos += 5;
  1055. if (hwaddr_aton(pos, addr) == 0) {
  1056. union wpa_event_data data;
  1057. os_memset(&data, 0, sizeof(data));
  1058. data.michael_mic_failure.unicast = 1;
  1059. data.michael_mic_failure.src = addr;
  1060. wpa_supplicant_event(drv->hapd,
  1061. EVENT_MICHAEL_MIC_FAILURE, &data);
  1062. } else {
  1063. wpa_printf(MSG_DEBUG,
  1064. "MLME-MICHAELMICFAILURE.indication "
  1065. "with invalid MAC address");
  1066. }
  1067. } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
  1068. char *key, *value;
  1069. u32 val;
  1070. key = custom;
  1071. while ((key = strchr(key, '\n')) != NULL) {
  1072. key++;
  1073. value = strchr(key, '=');
  1074. if (value == NULL)
  1075. continue;
  1076. *value++ = '\0';
  1077. val = strtoul(value, NULL, 10);
  1078. if (strcmp(key, "mac") == 0)
  1079. hwaddr_aton(value, drv->acct_mac);
  1080. else if (strcmp(key, "rx_packets") == 0)
  1081. drv->acct_data.rx_packets = val;
  1082. else if (strcmp(key, "tx_packets") == 0)
  1083. drv->acct_data.tx_packets = val;
  1084. else if (strcmp(key, "rx_bytes") == 0)
  1085. drv->acct_data.rx_bytes = val;
  1086. else if (strcmp(key, "tx_bytes") == 0)
  1087. drv->acct_data.tx_bytes = val;
  1088. key = value;
  1089. }
  1090. #ifdef CONFIG_WPS
  1091. } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
  1092. /* Some atheros kernels send push button as a wireless event */
  1093. /* PROBLEM! this event is received for ALL BSSs ...
  1094. * so all are enabled for WPS... ugh.
  1095. */
  1096. wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
  1097. #endif /* CONFIG_WPS */
  1098. #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20)
  1099. #define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
  1100. } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
  1101. /*
  1102. * Atheros driver uses a hack to pass Probe Request frames as a
  1103. * binary data in the custom wireless event. The old way (using
  1104. * packet sniffing) didn't work when bridging.
  1105. * Format: "Manage.prob_req <frame len>" | zero padding | frame
  1106. */
  1107. int len = atoi(custom + 16);
  1108. if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
  1109. wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
  1110. "length %d", len);
  1111. return;
  1112. }
  1113. atheros_raw_receive(drv, NULL,
  1114. (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
  1115. } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
  1116. /* Format: "Manage.assoc_req <frame len>" | zero padding |
  1117. * frame */
  1118. int len = atoi(custom + 17);
  1119. if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
  1120. wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
  1121. "assoc_req/auth event length %d", len);
  1122. return;
  1123. }
  1124. atheros_raw_receive(drv, NULL,
  1125. (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
  1126. } else if (strncmp(custom, "Manage.action ", 14) == 0) {
  1127. /* Format: "Manage.assoc_req <frame len>" | zero padding |
  1128. * frame */
  1129. int len = atoi(custom + 14);
  1130. if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
  1131. wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
  1132. "assoc_req/auth event length %d", len);
  1133. return;
  1134. }
  1135. atheros_raw_receive(drv, NULL,
  1136. (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
  1137. } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
  1138. /* Format: "Manage.auth <frame len>" | zero padding | frame
  1139. */
  1140. int len = atoi(custom + 12);
  1141. if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
  1142. wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
  1143. "assoc_req/auth event length %d", len);
  1144. return;
  1145. }
  1146. atheros_raw_receive(drv, NULL,
  1147. (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
  1148. #endif /* CONFIG_WPS or CONFIG_IEEE80211R */
  1149. }
  1150. }
  1151. /*
  1152. * Handle size of data problem. WEXT only allows data of 256 bytes for custom
  1153. * events, and p2p data can be much bigger. So the athr driver sends a small
  1154. * event telling me to collect the big data with an ioctl.
  1155. * On the first event, send all pending events to supplicant.
  1156. */
  1157. static void fetch_pending_big_events(struct atheros_driver_data *drv)
  1158. {
  1159. union wpa_event_data event;
  1160. const struct ieee80211_mgmt *mgmt;
  1161. u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
  1162. u16 fc, stype;
  1163. struct iwreq iwr;
  1164. size_t data_len;
  1165. u32 freq, frame_type;
  1166. while (1) {
  1167. os_memset(&iwr, 0, sizeof(iwr));
  1168. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1169. iwr.u.data.pointer = (void *) tbuf;
  1170. iwr.u.data.length = sizeof(tbuf);
  1171. iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
  1172. if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
  1173. < 0) {
  1174. if (errno == ENOSPC) {
  1175. wpa_printf(MSG_DEBUG, "%s:%d exit",
  1176. __func__, __LINE__);
  1177. return;
  1178. }
  1179. wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
  1180. "P2P_FETCH_FRAME] failed: %s",
  1181. __func__, strerror(errno));
  1182. return;
  1183. }
  1184. data_len = iwr.u.data.length;
  1185. wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
  1186. (u8 *) tbuf, data_len);
  1187. if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
  1188. wpa_printf(MSG_DEBUG, "athr: frame too short");
  1189. continue;
  1190. }
  1191. os_memcpy(&freq, tbuf, sizeof(freq));
  1192. os_memcpy(&frame_type, &tbuf[sizeof(freq)],
  1193. sizeof(frame_type));
  1194. mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
  1195. data_len -= sizeof(freq) + sizeof(frame_type);
  1196. if (frame_type == IEEE80211_EV_RX_MGMT) {
  1197. fc = le_to_host16(mgmt->frame_control);
  1198. stype = WLAN_FC_GET_STYPE(fc);
  1199. wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
  1200. "freq=%u len=%u", stype, freq, (int) data_len);
  1201. if (stype == WLAN_FC_STYPE_ACTION) {
  1202. os_memset(&event, 0, sizeof(event));
  1203. event.rx_mgmt.frame = (const u8 *) mgmt;
  1204. event.rx_mgmt.frame_len = data_len;
  1205. wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
  1206. &event);
  1207. continue;
  1208. }
  1209. } else {
  1210. wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
  1211. __func__, frame_type);
  1212. continue;
  1213. }
  1214. }
  1215. }
  1216. static void
  1217. atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
  1218. int opcode, char *buf, int len)
  1219. {
  1220. switch (opcode) {
  1221. case IEEE80211_EV_RX_MGMT:
  1222. wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
  1223. fetch_pending_big_events(drv);
  1224. break;
  1225. default:
  1226. break;
  1227. }
  1228. }
  1229. static void
  1230. atheros_wireless_event_wireless(struct atheros_driver_data *drv,
  1231. char *data, int len)
  1232. {
  1233. struct iw_event iwe_buf, *iwe = &iwe_buf;
  1234. char *pos, *end, *custom, *buf;
  1235. pos = data;
  1236. end = data + len;
  1237. while (pos + IW_EV_LCP_LEN <= end) {
  1238. /* Event data may be unaligned, so make a local, aligned copy
  1239. * before processing. */
  1240. memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
  1241. wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
  1242. iwe->cmd, iwe->len);
  1243. if (iwe->len <= IW_EV_LCP_LEN)
  1244. return;
  1245. custom = pos + IW_EV_POINT_LEN;
  1246. if (drv->we_version > 18 &&
  1247. (iwe->cmd == IWEVMICHAELMICFAILURE ||
  1248. iwe->cmd == IWEVASSOCREQIE ||
  1249. iwe->cmd == IWEVCUSTOM)) {
  1250. /* WE-19 removed the pointer from struct iw_point */
  1251. char *dpos = (char *) &iwe_buf.u.data.length;
  1252. int dlen = dpos - (char *) &iwe_buf;
  1253. memcpy(dpos, pos + IW_EV_LCP_LEN,
  1254. sizeof(struct iw_event) - dlen);
  1255. } else {
  1256. memcpy(&iwe_buf, pos, sizeof(struct iw_event));
  1257. custom += IW_EV_POINT_OFF;
  1258. }
  1259. switch (iwe->cmd) {
  1260. case IWEVEXPIRED:
  1261. drv_event_disassoc(drv->hapd,
  1262. (u8 *) iwe->u.addr.sa_data);
  1263. break;
  1264. case IWEVREGISTERED:
  1265. atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
  1266. break;
  1267. case IWEVASSOCREQIE:
  1268. /* Driver hack.. Use IWEVASSOCREQIE to bypass
  1269. * IWEVCUSTOM size limitations. Need to handle this
  1270. * just like IWEVCUSTOM.
  1271. */
  1272. case IWEVCUSTOM:
  1273. if (custom + iwe->u.data.length > end)
  1274. return;
  1275. buf = malloc(iwe->u.data.length + 1);
  1276. if (buf == NULL)
  1277. return; /* XXX */
  1278. memcpy(buf, custom, iwe->u.data.length);
  1279. buf[iwe->u.data.length] = '\0';
  1280. if (iwe->u.data.flags != 0) {
  1281. atheros_wireless_event_atheros_custom(
  1282. drv, (int) iwe->u.data.flags,
  1283. buf, len);
  1284. } else {
  1285. atheros_wireless_event_wireless_custom(
  1286. drv, buf, buf + iwe->u.data.length);
  1287. }
  1288. free(buf);
  1289. break;
  1290. }
  1291. pos += iwe->len;
  1292. }
  1293. }
  1294. static void
  1295. atheros_wireless_event_rtm_newlink(void *ctx,
  1296. struct ifinfomsg *ifi, u8 *buf, size_t len)
  1297. {
  1298. struct atheros_driver_data *drv = ctx;
  1299. int attrlen, rta_len;
  1300. struct rtattr *attr;
  1301. if (ifi->ifi_index != drv->ifindex)
  1302. return;
  1303. attrlen = len;
  1304. attr = (struct rtattr *) buf;
  1305. rta_len = RTA_ALIGN(sizeof(struct rtattr));
  1306. while (RTA_OK(attr, attrlen)) {
  1307. if (attr->rta_type == IFLA_WIRELESS) {
  1308. atheros_wireless_event_wireless(
  1309. drv, ((char *) attr) + rta_len,
  1310. attr->rta_len - rta_len);
  1311. }
  1312. attr = RTA_NEXT(attr, attrlen);
  1313. }
  1314. }
  1315. static int
  1316. atheros_get_we_version(struct atheros_driver_data *drv)
  1317. {
  1318. struct iw_range *range;
  1319. struct iwreq iwr;
  1320. int minlen;
  1321. size_t buflen;
  1322. drv->we_version = 0;
  1323. /*
  1324. * Use larger buffer than struct iw_range in order to allow the
  1325. * structure to grow in the future.
  1326. */
  1327. buflen = sizeof(struct iw_range) + 500;
  1328. range = os_zalloc(buflen);
  1329. if (range == NULL)
  1330. return -1;
  1331. memset(&iwr, 0, sizeof(iwr));
  1332. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1333. iwr.u.data.pointer = (caddr_t) range;
  1334. iwr.u.data.length = buflen;
  1335. minlen = ((char *) &range->enc_capa) - (char *) range +
  1336. sizeof(range->enc_capa);
  1337. if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
  1338. wpa_printf(MSG_ERROR, "ioctl[SIOCGIWRANGE]: %s",
  1339. strerror(errno));
  1340. os_free(range);
  1341. return -1;
  1342. } else if (iwr.u.data.length >= minlen &&
  1343. range->we_version_compiled >= 18) {
  1344. wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
  1345. "WE(source)=%d enc_capa=0x%x",
  1346. range->we_version_compiled,
  1347. range->we_version_source,
  1348. range->enc_capa);
  1349. drv->we_version = range->we_version_compiled;
  1350. }
  1351. os_free(range);
  1352. return 0;
  1353. }
  1354. static int
  1355. atheros_wireless_event_init(struct atheros_driver_data *drv)
  1356. {
  1357. struct netlink_config *cfg;
  1358. atheros_get_we_version(drv);
  1359. cfg = os_zalloc(sizeof(*cfg));
  1360. if (cfg == NULL)
  1361. return -1;
  1362. cfg->ctx = drv;
  1363. cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
  1364. drv->netlink = netlink_init(cfg);
  1365. if (drv->netlink == NULL) {
  1366. os_free(cfg);
  1367. return -1;
  1368. }
  1369. return 0;
  1370. }
  1371. static int
  1372. atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
  1373. int encrypt, const u8 *own_addr, u32 flags)
  1374. {
  1375. struct atheros_driver_data *drv = priv;
  1376. unsigned char buf[3000];
  1377. unsigned char *bp = buf;
  1378. struct l2_ethhdr *eth;
  1379. size_t len;
  1380. int status;
  1381. /*
  1382. * Prepend the Ethernet header. If the caller left us
  1383. * space at the front we could just insert it but since
  1384. * we don't know we copy to a local buffer. Given the frequency
  1385. * and size of frames this probably doesn't matter.
  1386. */
  1387. len = data_len + sizeof(struct l2_ethhdr);
  1388. if (len > sizeof(buf)) {
  1389. bp = malloc(len);
  1390. if (bp == NULL) {
  1391. wpa_printf(MSG_INFO,
  1392. "EAPOL frame discarded, cannot malloc temp buffer of size %lu!",
  1393. (unsigned long) len);
  1394. return -1;
  1395. }
  1396. }
  1397. eth = (struct l2_ethhdr *) bp;
  1398. memcpy(eth->h_dest, addr, ETH_ALEN);
  1399. memcpy(eth->h_source, own_addr, ETH_ALEN);
  1400. eth->h_proto = host_to_be16(ETH_P_EAPOL);
  1401. memcpy(eth+1, data, data_len);
  1402. wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
  1403. status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
  1404. if (bp != buf)
  1405. free(bp);
  1406. return status;
  1407. }
  1408. static void
  1409. handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
  1410. {
  1411. struct atheros_driver_data *drv = ctx;
  1412. drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
  1413. len - sizeof(struct l2_ethhdr));
  1414. }
  1415. static void *
  1416. atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
  1417. {
  1418. struct atheros_driver_data *drv;
  1419. struct ifreq ifr;
  1420. struct iwreq iwr;
  1421. char brname[IFNAMSIZ];
  1422. drv = os_zalloc(sizeof(struct atheros_driver_data));
  1423. if (drv == NULL) {
  1424. wpa_printf(MSG_INFO,
  1425. "Could not allocate memory for atheros driver data");
  1426. return NULL;
  1427. }
  1428. drv->hapd = hapd;
  1429. drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
  1430. if (drv->ioctl_sock < 0) {
  1431. wpa_printf(MSG_ERROR, "socket[PF_INET,SOCK_DGRAM]: %s",
  1432. strerror(errno));
  1433. goto bad;
  1434. }
  1435. memcpy(drv->iface, params->ifname, sizeof(drv->iface));
  1436. memset(&ifr, 0, sizeof(ifr));
  1437. os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
  1438. if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
  1439. wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
  1440. strerror(errno));
  1441. goto bad;
  1442. }
  1443. drv->ifindex = ifr.ifr_ifindex;
  1444. drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
  1445. handle_read, drv, 1);
  1446. if (drv->sock_xmit == NULL)
  1447. goto bad;
  1448. if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
  1449. goto bad;
  1450. os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
  1451. if (params->bridge[0]) {
  1452. wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
  1453. params->bridge[0]);
  1454. drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
  1455. ETH_P_EAPOL, handle_read, drv,
  1456. 1);
  1457. if (drv->sock_recv == NULL)
  1458. goto bad;
  1459. } else if (linux_br_get(brname, drv->iface) == 0) {
  1460. wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
  1461. "EAPOL receive", brname);
  1462. drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
  1463. handle_read, drv, 1);
  1464. if (drv->sock_recv == NULL)
  1465. goto bad;
  1466. } else
  1467. drv->sock_recv = drv->sock_xmit;
  1468. memset(&iwr, 0, sizeof(iwr));
  1469. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1470. iwr.u.mode = IW_MODE_MASTER;
  1471. if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
  1472. wpa_printf(MSG_ERROR,
  1473. "Could not set interface to master mode! ioctl[SIOCSIWMODE]: %s",
  1474. strerror(errno));
  1475. goto bad;
  1476. }
  1477. /* mark down during setup */
  1478. linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
  1479. atheros_set_privacy(drv, 0); /* default to no privacy */
  1480. if (atheros_receive_pkt(drv))
  1481. goto bad;
  1482. if (atheros_wireless_event_init(drv))
  1483. goto bad;
  1484. return drv;
  1485. bad:
  1486. atheros_reset_appfilter(drv);
  1487. if (drv->sock_raw)
  1488. l2_packet_deinit(drv->sock_raw);
  1489. if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
  1490. l2_packet_deinit(drv->sock_recv);
  1491. if (drv->sock_xmit != NULL)
  1492. l2_packet_deinit(drv->sock_xmit);
  1493. if (drv->ioctl_sock >= 0)
  1494. close(drv->ioctl_sock);
  1495. os_free(drv);
  1496. return NULL;
  1497. }
  1498. static void
  1499. atheros_deinit(void *priv)
  1500. {
  1501. struct atheros_driver_data *drv = priv;
  1502. atheros_reset_appfilter(drv);
  1503. if (drv->wpa_ie || drv->wps_beacon_ie || drv->wps_probe_resp_ie) {
  1504. wpabuf_free(drv->wpa_ie);
  1505. wpabuf_free(drv->wps_beacon_ie);
  1506. wpabuf_free(drv->wps_probe_resp_ie);
  1507. atheros_set_opt_ie(priv, NULL, 0);
  1508. }
  1509. netlink_deinit(drv->netlink);
  1510. (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
  1511. if (drv->ioctl_sock >= 0)
  1512. close(drv->ioctl_sock);
  1513. if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
  1514. l2_packet_deinit(drv->sock_recv);
  1515. if (drv->sock_xmit != NULL)
  1516. l2_packet_deinit(drv->sock_xmit);
  1517. if (drv->sock_raw)
  1518. l2_packet_deinit(drv->sock_raw);
  1519. os_free(drv);
  1520. }
  1521. static int
  1522. atheros_set_ssid(void *priv, const u8 *buf, int len)
  1523. {
  1524. struct atheros_driver_data *drv = priv;
  1525. struct iwreq iwr;
  1526. memset(&iwr, 0, sizeof(iwr));
  1527. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1528. iwr.u.essid.flags = 1; /* SSID active */
  1529. iwr.u.essid.pointer = (caddr_t) buf;
  1530. iwr.u.essid.length = len + 1;
  1531. if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
  1532. wpa_printf(MSG_ERROR, "ioctl[SIOCSIWESSID,len=%d]: %s",
  1533. len, strerror(errno));
  1534. return -1;
  1535. }
  1536. return 0;
  1537. }
  1538. static int
  1539. atheros_get_ssid(void *priv, u8 *buf, int len)
  1540. {
  1541. struct atheros_driver_data *drv = priv;
  1542. struct iwreq iwr;
  1543. int ret = 0;
  1544. memset(&iwr, 0, sizeof(iwr));
  1545. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1546. iwr.u.essid.pointer = (caddr_t) buf;
  1547. iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
  1548. IW_ESSID_MAX_SIZE : len;
  1549. if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
  1550. wpa_printf(MSG_ERROR, "ioctl[SIOCGIWESSID]: %s",
  1551. strerror(errno));
  1552. ret = -1;
  1553. } else
  1554. ret = iwr.u.essid.length;
  1555. return ret;
  1556. }
  1557. static int
  1558. atheros_set_countermeasures(void *priv, int enabled)
  1559. {
  1560. struct atheros_driver_data *drv = priv;
  1561. wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
  1562. return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
  1563. }
  1564. static int
  1565. atheros_commit(void *priv)
  1566. {
  1567. struct atheros_driver_data *drv = priv;
  1568. return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
  1569. }
  1570. static int atheros_set_authmode(void *priv, int auth_algs)
  1571. {
  1572. int authmode;
  1573. if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
  1574. (auth_algs & WPA_AUTH_ALG_SHARED))
  1575. authmode = IEEE80211_AUTH_AUTO;
  1576. else if (auth_algs & WPA_AUTH_ALG_OPEN)
  1577. authmode = IEEE80211_AUTH_OPEN;
  1578. else if (auth_algs & WPA_AUTH_ALG_SHARED)
  1579. authmode = IEEE80211_AUTH_SHARED;
  1580. else
  1581. return -1;
  1582. return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
  1583. }
  1584. static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
  1585. {
  1586. /*
  1587. * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
  1588. * set_generic_elem, and hapd_set_ssid.
  1589. */
  1590. wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
  1591. "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
  1592. "wpa_version=0x%x privacy=%d interworking=%d",
  1593. params->pairwise_ciphers, params->group_cipher,
  1594. params->key_mgmt_suites, params->auth_algs,
  1595. params->wpa_version, params->privacy, params->interworking);
  1596. wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
  1597. params->ssid, params->ssid_len);
  1598. if (params->hessid)
  1599. wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
  1600. MAC2STR(params->hessid));
  1601. wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
  1602. params->beacon_ies);
  1603. wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
  1604. params->proberesp_ies);
  1605. wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
  1606. params->assocresp_ies);
  1607. #if defined(CONFIG_HS20) && (defined(IEEE80211_PARAM_OSEN) || defined(CONFIG_ATHEROS_OSEN))
  1608. if (params->osen) {
  1609. struct wpa_bss_params bss_params;
  1610. os_memset(&bss_params, 0, sizeof(struct wpa_bss_params));
  1611. bss_params.enabled = 1;
  1612. bss_params.wpa = 2;
  1613. bss_params.wpa_pairwise = WPA_CIPHER_CCMP;
  1614. bss_params.wpa_group = WPA_CIPHER_CCMP;
  1615. bss_params.ieee802_1x = 1;
  1616. if (atheros_set_privacy(priv, 1) ||
  1617. set80211param(priv, IEEE80211_PARAM_OSEN, 1))
  1618. return -1;
  1619. return atheros_set_ieee8021x(priv, &bss_params);
  1620. }
  1621. #endif /* CONFIG_HS20 && IEEE80211_PARAM_OSEN */
  1622. return 0;
  1623. }
  1624. #ifdef CONFIG_IEEE80211R
  1625. static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
  1626. int noack, unsigned int freq)
  1627. {
  1628. struct atheros_driver_data *drv = priv;
  1629. u8 buf[1510];
  1630. const struct ieee80211_mgmt *mgmt;
  1631. struct ieee80211req_mgmtbuf *mgmt_frm;
  1632. mgmt = (const struct ieee80211_mgmt *) frm;
  1633. wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
  1634. (unsigned long) data_len, MAC2STR(mgmt->da));
  1635. mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
  1636. memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
  1637. mgmt_frm->buflen = data_len;
  1638. if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
  1639. wpa_printf(MSG_INFO, "atheros: Too long frame for "
  1640. "atheros_send_mgmt (%u)", (unsigned int) data_len);
  1641. return -1;
  1642. }
  1643. os_memcpy(&mgmt_frm->buf[0], frm, data_len);
  1644. return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
  1645. sizeof(struct ieee80211req_mgmtbuf) + data_len);
  1646. }
  1647. static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
  1648. size_t tspec_ielen)
  1649. {
  1650. struct atheros_driver_data *drv = priv;
  1651. int retv;
  1652. struct ieee80211req_res req;
  1653. struct ieee80211req_res_addts *addts = &req.u.addts;
  1654. wpa_printf(MSG_DEBUG, "%s", __func__);
  1655. req.type = IEEE80211_RESREQ_ADDTS;
  1656. os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
  1657. os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
  1658. retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
  1659. sizeof(struct ieee80211req_res));
  1660. if (retv < 0) {
  1661. wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
  1662. "retv = %d", __func__, retv);
  1663. return -1;
  1664. }
  1665. os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
  1666. return addts->status;
  1667. }
  1668. static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
  1669. {
  1670. struct atheros_driver_data *drv = priv;
  1671. struct ieee80211req_res req;
  1672. struct ieee80211req_res_addnode *addnode = &req.u.addnode;
  1673. wpa_printf(MSG_DEBUG, "%s", __func__);
  1674. req.type = IEEE80211_RESREQ_ADDNODE;
  1675. os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
  1676. addnode->auth_alg = auth_alg;
  1677. return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
  1678. sizeof(struct ieee80211req_res));
  1679. }
  1680. #endif /* CONFIG_IEEE80211R */
  1681. /* Use only to set a big param, get will not work. */
  1682. static int
  1683. set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
  1684. {
  1685. struct iwreq iwr;
  1686. os_memset(&iwr, 0, sizeof(iwr));
  1687. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1688. iwr.u.data.pointer = (void *) data;
  1689. iwr.u.data.length = len;
  1690. iwr.u.data.flags = op;
  1691. wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
  1692. __func__, op, op, athr_get_param_name(op), len);
  1693. if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
  1694. wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
  1695. "value=0x%x,0x%x failed: %d (%s)",
  1696. __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
  1697. iwr.u.mode, iwr.u.data.length,
  1698. iwr.u.data.flags, errno, strerror(errno));
  1699. return -1;
  1700. }
  1701. return 0;
  1702. }
  1703. static int atheros_send_action(void *priv, unsigned int freq,
  1704. unsigned int wait,
  1705. const u8 *dst, const u8 *src,
  1706. const u8 *bssid,
  1707. const u8 *data, size_t data_len, int no_cck)
  1708. {
  1709. struct atheros_driver_data *drv = priv;
  1710. struct ieee80211_p2p_send_action *act;
  1711. int res;
  1712. act = os_zalloc(sizeof(*act) + data_len);
  1713. if (act == NULL)
  1714. return -1;
  1715. act->freq = freq;
  1716. os_memcpy(act->dst_addr, dst, ETH_ALEN);
  1717. os_memcpy(act->src_addr, src, ETH_ALEN);
  1718. os_memcpy(act->bssid, bssid, ETH_ALEN);
  1719. os_memcpy(act + 1, data, data_len);
  1720. wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
  1721. MACSTR ", bssid=" MACSTR,
  1722. __func__, act->freq, wait, MAC2STR(act->dst_addr),
  1723. MAC2STR(act->src_addr), MAC2STR(act->bssid));
  1724. wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
  1725. wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
  1726. res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
  1727. act, sizeof(*act) + data_len);
  1728. os_free(act);
  1729. return res;
  1730. }
  1731. #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
  1732. static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
  1733. u8 *ie, u16 *len, enum wnm_oper oper)
  1734. {
  1735. #define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
  1736. u8 buf[IEEE80211_APPIE_MAX];
  1737. struct ieee80211req_getset_appiebuf *tfs_ie;
  1738. u16 val;
  1739. wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
  1740. drv->iface, oper, MAC2STR(peer));
  1741. switch (oper) {
  1742. case WNM_SLEEP_TFS_REQ_IE_SET:
  1743. if (*len > IEEE80211_APPIE_MAX -
  1744. sizeof(struct ieee80211req_getset_appiebuf)) {
  1745. wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
  1746. return -1;
  1747. }
  1748. tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
  1749. tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
  1750. tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
  1751. /* Command header for driver */
  1752. os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
  1753. val = oper;
  1754. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
  1755. val = *len;
  1756. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
  1757. /* copy the ie */
  1758. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
  1759. if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
  1760. IEEE80211_APPIE_MAX)) {
  1761. wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
  1762. "%s", __func__, strerror(errno));
  1763. return -1;
  1764. }
  1765. break;
  1766. case WNM_SLEEP_TFS_RESP_IE_ADD:
  1767. tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
  1768. tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
  1769. tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
  1770. sizeof(struct ieee80211req_getset_appiebuf);
  1771. /* Command header for driver */
  1772. os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
  1773. val = oper;
  1774. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
  1775. val = 0;
  1776. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
  1777. if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
  1778. IEEE80211_APPIE_MAX)) {
  1779. wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
  1780. "%s", __func__, strerror(errno));
  1781. return -1;
  1782. }
  1783. *len = tfs_ie->app_buflen;
  1784. os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
  1785. wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
  1786. *len);
  1787. break;
  1788. case WNM_SLEEP_TFS_RESP_IE_NONE:
  1789. *len = 0;
  1790. break;
  1791. case WNM_SLEEP_TFS_IE_DEL:
  1792. tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
  1793. tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
  1794. tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
  1795. sizeof(struct ieee80211req_getset_appiebuf);
  1796. /* Command header for driver */
  1797. os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
  1798. val = oper;
  1799. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
  1800. val = 0;
  1801. os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
  1802. if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
  1803. IEEE80211_APPIE_MAX)) {
  1804. wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
  1805. "%s", __func__, strerror(errno));
  1806. return -1;
  1807. }
  1808. break;
  1809. default:
  1810. wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
  1811. break;
  1812. }
  1813. return 0;
  1814. }
  1815. static int atheros_wnm_sleep(struct atheros_driver_data *drv,
  1816. const u8 *peer, enum wnm_oper oper)
  1817. {
  1818. u8 *data, *pos;
  1819. size_t dlen;
  1820. int ret;
  1821. u16 val;
  1822. wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
  1823. oper, MAC2STR(peer));
  1824. dlen = ETH_ALEN + 2 + 2;
  1825. data = os_malloc(dlen);
  1826. if (data == NULL)
  1827. return -1;
  1828. /* Command header for driver */
  1829. pos = data;
  1830. os_memcpy(pos, peer, ETH_ALEN);
  1831. pos += ETH_ALEN;
  1832. val = oper;
  1833. os_memcpy(pos, &val, 2);
  1834. pos += 2;
  1835. val = 0;
  1836. os_memcpy(pos, &val, 2);
  1837. ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
  1838. os_free(data);
  1839. return ret;
  1840. }
  1841. static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
  1842. u8 *buf, u16 *buf_len)
  1843. {
  1844. struct atheros_driver_data *drv = priv;
  1845. switch (oper) {
  1846. case WNM_SLEEP_ENTER_CONFIRM:
  1847. case WNM_SLEEP_ENTER_FAIL:
  1848. case WNM_SLEEP_EXIT_CONFIRM:
  1849. case WNM_SLEEP_EXIT_FAIL:
  1850. return atheros_wnm_sleep(drv, peer, oper);
  1851. case WNM_SLEEP_TFS_REQ_IE_SET:
  1852. case WNM_SLEEP_TFS_RESP_IE_ADD:
  1853. case WNM_SLEEP_TFS_RESP_IE_NONE:
  1854. case WNM_SLEEP_TFS_IE_DEL:
  1855. return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
  1856. default:
  1857. wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
  1858. oper);
  1859. return -1;
  1860. }
  1861. }
  1862. #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
  1863. const struct wpa_driver_ops wpa_driver_atheros_ops = {
  1864. .name = "atheros",
  1865. .hapd_init = atheros_init,
  1866. .hapd_deinit = atheros_deinit,
  1867. .set_ieee8021x = atheros_set_ieee8021x,
  1868. .set_privacy = atheros_set_privacy,
  1869. .set_key = atheros_set_key,
  1870. .get_seqnum = atheros_get_seqnum,
  1871. .flush = atheros_flush,
  1872. .set_generic_elem = atheros_set_opt_ie,
  1873. .sta_set_flags = atheros_sta_set_flags,
  1874. .read_sta_data = atheros_read_sta_driver_data,
  1875. .hapd_send_eapol = atheros_send_eapol,
  1876. .sta_disassoc = atheros_sta_disassoc,
  1877. .sta_deauth = atheros_sta_deauth,
  1878. .hapd_set_ssid = atheros_set_ssid,
  1879. .hapd_get_ssid = atheros_get_ssid,
  1880. .set_countermeasures = atheros_set_countermeasures,
  1881. .sta_clear_stats = atheros_sta_clear_stats,
  1882. .commit = atheros_commit,
  1883. .set_ap_wps_ie = atheros_set_ap_wps_ie,
  1884. .set_authmode = atheros_set_authmode,
  1885. .set_ap = atheros_set_ap,
  1886. #ifdef CONFIG_IEEE80211R
  1887. .sta_assoc = atheros_sta_assoc,
  1888. .sta_auth = atheros_sta_auth,
  1889. .send_mlme = atheros_send_mgmt,
  1890. .add_tspec = atheros_add_tspec,
  1891. .add_sta_node = atheros_add_sta_node,
  1892. #endif /* CONFIG_IEEE80211R */
  1893. .send_action = atheros_send_action,
  1894. #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
  1895. .wnm_oper = atheros_wnm_oper,
  1896. #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
  1897. .set_qos_map = atheros_set_qos_map,
  1898. };