driver_atheros.c 62 KB

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