driver_nl80211.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489
  1. /*
  2. * hostapd / Kernel driver communication via nl80211
  3. * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2003-2004, Instant802 Networks, Inc.
  5. * Copyright (c) 2005-2006, Devicescape Software, Inc.
  6. * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Alternatively, this software may be distributed under the terms of BSD
  13. * license.
  14. *
  15. * See README and COPYING for more details.
  16. */
  17. #include "includes.h"
  18. #include <sys/ioctl.h>
  19. #include <netlink/genl/genl.h>
  20. #include <netlink/genl/family.h>
  21. #include <netlink/genl/ctrl.h>
  22. #include <netlink/msg.h>
  23. #include <netlink/attr.h>
  24. #include <linux/nl80211.h>
  25. #include <net/if.h>
  26. #include <linux/if_packet.h>
  27. #include <linux/if_ether.h> /* The L2 protocols */
  28. #include "wireless_copy.h"
  29. #include <net/if_arp.h>
  30. #include "hostapd.h"
  31. #include "driver.h"
  32. #include "ieee802_1x.h"
  33. #include "eloop.h"
  34. #include "ieee802_11.h"
  35. #include "sta_info.h"
  36. #include "hw_features.h"
  37. #include "mlme.h"
  38. #include "radiotap.h"
  39. #include "radiotap_iter.h"
  40. enum ieee80211_msg_type {
  41. ieee80211_msg_normal = 0,
  42. ieee80211_msg_tx_callback_ack = 1,
  43. ieee80211_msg_tx_callback_fail = 2,
  44. };
  45. struct i802_driver_data {
  46. struct hostapd_data *hapd;
  47. char iface[IFNAMSIZ + 1];
  48. int bridge;
  49. int ioctl_sock; /* socket for ioctl() use */
  50. int wext_sock; /* socket for wireless events */
  51. int eapol_sock; /* socket for EAPOL frames */
  52. int monitor_sock; /* socket for monitor */
  53. int monitor_ifidx;
  54. int default_if_indices[16];
  55. int *if_indices;
  56. int num_if_indices;
  57. int we_version;
  58. struct nl_handle *nl_handle;
  59. struct nl_cache *nl_cache;
  60. struct nl_cb *nl_cb;
  61. struct genl_family *nl80211;
  62. int dtim_period, beacon_int;
  63. unsigned int beacon_set:1;
  64. unsigned int ieee802_1x_active:1;
  65. };
  66. static void add_ifidx(struct i802_driver_data *drv, int ifidx)
  67. {
  68. int i;
  69. int *old;
  70. for (i = 0; i < drv->num_if_indices; i++) {
  71. if (drv->if_indices[i] == 0) {
  72. drv->if_indices[i] = ifidx;
  73. return;
  74. }
  75. }
  76. if (drv->if_indices != drv->default_if_indices)
  77. old = drv->if_indices;
  78. else
  79. old = NULL;
  80. drv->if_indices = realloc(old,
  81. sizeof(int) * (drv->num_if_indices + 1));
  82. if (!drv->if_indices) {
  83. if (!old)
  84. drv->if_indices = drv->default_if_indices;
  85. else
  86. drv->if_indices = old;
  87. wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
  88. "interfaces");
  89. wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
  90. return;
  91. }
  92. drv->if_indices[drv->num_if_indices] = ifidx;
  93. drv->num_if_indices++;
  94. }
  95. static void del_ifidx(struct i802_driver_data *drv, int ifidx)
  96. {
  97. int i;
  98. for (i = 0; i < drv->num_if_indices; i++) {
  99. if (drv->if_indices[i] == ifidx) {
  100. drv->if_indices[i] = 0;
  101. break;
  102. }
  103. }
  104. }
  105. static int have_ifidx(struct i802_driver_data *drv, int ifidx)
  106. {
  107. int i;
  108. if (ifidx == drv->bridge)
  109. return 1;
  110. for (i = 0; i < drv->num_if_indices; i++)
  111. if (drv->if_indices[i] == ifidx)
  112. return 1;
  113. return 0;
  114. }
  115. /* helper for netlink get routines */
  116. static int ack_wait_handler(struct nl_msg *msg, void *arg)
  117. {
  118. int *finished = arg;
  119. *finished = 1;
  120. return NL_STOP;
  121. }
  122. static int hostapd_set_iface_flags(struct i802_driver_data *drv,
  123. const char *ifname, int dev_up)
  124. {
  125. struct ifreq ifr;
  126. if (drv->ioctl_sock < 0)
  127. return -1;
  128. memset(&ifr, 0, sizeof(ifr));
  129. os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
  130. if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
  131. perror("ioctl[SIOCGIFFLAGS]");
  132. wpa_printf(MSG_DEBUG, "Could not read interface flags (%s)",
  133. drv->iface);
  134. return -1;
  135. }
  136. if (dev_up)
  137. ifr.ifr_flags |= IFF_UP;
  138. else
  139. ifr.ifr_flags &= ~IFF_UP;
  140. if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
  141. perror("ioctl[SIOCSIFFLAGS]");
  142. return -1;
  143. }
  144. return 0;
  145. }
  146. static int nl_set_encr(int ifindex, struct i802_driver_data *drv,
  147. const char *alg, const u8 *addr, int idx, const u8 *key,
  148. size_t key_len, int txkey)
  149. {
  150. struct nl_msg *msg;
  151. int ret = -1;
  152. int err = 0;
  153. msg = nlmsg_alloc();
  154. if (!msg)
  155. goto out;
  156. if (strcmp(alg, "none") == 0) {
  157. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  158. 0, NL80211_CMD_DEL_KEY, 0);
  159. } else {
  160. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  161. 0, NL80211_CMD_NEW_KEY, 0);
  162. NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key);
  163. if (strcmp(alg, "WEP") == 0) {
  164. if (key_len == 5)
  165. NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
  166. 0x000FAC01);
  167. else
  168. NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
  169. 0x000FAC05);
  170. } else if (strcmp(alg, "TKIP") == 0)
  171. NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC02);
  172. else if (strcmp(alg, "CCMP") == 0)
  173. NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC04);
  174. else if (strcmp(alg, "IGTK") == 0)
  175. NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC06);
  176. else {
  177. wpa_printf(MSG_ERROR, "%s: Unsupported encryption "
  178. "algorithm '%s'", __func__, alg);
  179. goto out;
  180. }
  181. }
  182. if (addr)
  183. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  184. NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
  185. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
  186. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  187. (err = nl_wait_for_ack(drv->nl_handle)) < 0) {
  188. if (err != -ENOENT) {
  189. ret = 0;
  190. goto out;
  191. }
  192. }
  193. /*
  194. * If we need to set the default TX key we do that below,
  195. * otherwise we're done here.
  196. */
  197. if (!txkey || addr) {
  198. ret = 0;
  199. goto out;
  200. }
  201. nlmsg_free(msg);
  202. msg = nlmsg_alloc();
  203. if (!msg)
  204. goto out;
  205. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  206. 0, NL80211_CMD_SET_KEY, 0);
  207. NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
  208. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
  209. #ifdef NL80211_MFP_PENDING
  210. if (strcmp(alg, "IGTK") == 0)
  211. NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT);
  212. else
  213. NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
  214. #else /* NL80211_MFP_PENDING */
  215. NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
  216. #endif /* NL80211_MFP_PENDING */
  217. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  218. (err = nl_wait_for_ack(drv->nl_handle)) < 0) {
  219. if (err != -ENOENT) {
  220. ret = 0;
  221. goto out;
  222. }
  223. }
  224. ret = 0;
  225. out:
  226. nla_put_failure:
  227. nlmsg_free(msg);
  228. return ret;
  229. }
  230. static int i802_set_encryption(const char *iface, void *priv, const char *alg,
  231. const u8 *addr, int idx, const u8 *key,
  232. size_t key_len, int txkey)
  233. {
  234. struct i802_driver_data *drv = priv;
  235. int ret;
  236. ret = nl_set_encr(if_nametoindex(iface), drv, alg, addr, idx, key,
  237. key_len, txkey);
  238. if (ret < 0)
  239. return ret;
  240. if (strcmp(alg, "IGTK") == 0) {
  241. ret = nl_set_encr(drv->monitor_ifidx, drv, alg, addr, idx, key,
  242. key_len, txkey);
  243. }
  244. return ret;
  245. }
  246. static inline int min_int(int a, int b)
  247. {
  248. if (a < b)
  249. return a;
  250. return b;
  251. }
  252. static int get_key_handler(struct nl_msg *msg, void *arg)
  253. {
  254. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  255. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  256. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  257. genlmsg_attrlen(gnlh, 0), NULL);
  258. /*
  259. * TODO: validate the key index and mac address!
  260. * Otherwise, there's a race condition as soon as
  261. * the kernel starts sending key notifications.
  262. */
  263. if (tb[NL80211_ATTR_KEY_SEQ])
  264. memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
  265. min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
  266. return NL_SKIP;
  267. }
  268. static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
  269. int idx, u8 *seq)
  270. {
  271. struct i802_driver_data *drv = priv;
  272. struct nl_msg *msg;
  273. struct nl_cb *cb = NULL;
  274. int ret = -1;
  275. int err = 0;
  276. int finished = 0;
  277. msg = nlmsg_alloc();
  278. if (!msg)
  279. goto out;
  280. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  281. 0, NL80211_CMD_GET_KEY, 0);
  282. if (addr)
  283. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  284. NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
  285. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
  286. cb = nl_cb_clone(drv->nl_cb);
  287. if (!cb)
  288. goto out;
  289. memset(seq, 0, 6);
  290. if (nl_send_auto_complete(drv->nl_handle, msg) < 0)
  291. goto out;
  292. nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, get_key_handler, seq);
  293. nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, &finished);
  294. err = nl_recvmsgs(drv->nl_handle, cb);
  295. if (!finished)
  296. err = nl_wait_for_ack(drv->nl_handle);
  297. if (err < 0)
  298. goto out;
  299. ret = 0;
  300. out:
  301. nl_cb_put(cb);
  302. nla_put_failure:
  303. nlmsg_free(msg);
  304. return ret;
  305. }
  306. static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
  307. int mode)
  308. {
  309. return -1;
  310. }
  311. static int i802_set_ssid(const char *ifname, void *priv, const u8 *buf,
  312. int len)
  313. {
  314. struct i802_driver_data *drv = priv;
  315. struct iwreq iwr;
  316. memset(&iwr, 0, sizeof(iwr));
  317. os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
  318. iwr.u.essid.flags = 1; /* SSID active */
  319. iwr.u.essid.pointer = (caddr_t) buf;
  320. iwr.u.essid.length = len;
  321. if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
  322. perror("ioctl[SIOCSIWESSID]");
  323. printf("len=%d\n", len);
  324. return -1;
  325. }
  326. return 0;
  327. }
  328. static int i802_send_mgmt_frame(void *priv, const void *data, size_t len,
  329. int flags)
  330. {
  331. struct ieee80211_hdr *hdr = (void*) data;
  332. __u8 rtap_hdr[] = {
  333. 0x00, 0x00, /* radiotap version */
  334. 0x0e, 0x00, /* radiotap length */
  335. 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
  336. 0x0c, /* F_WEP | F_FRAG (encrypt/fragment if required) */
  337. 0x00, /* padding */
  338. 0x00, 0x00, /* RX and TX flags to indicate that */
  339. 0x00, 0x00, /* this is the injected frame directly */
  340. };
  341. struct i802_driver_data *drv = priv;
  342. struct iovec iov[2] = {
  343. {
  344. .iov_base = &rtap_hdr,
  345. .iov_len = sizeof(rtap_hdr),
  346. },
  347. {
  348. .iov_base = (void*)data,
  349. .iov_len = len,
  350. }
  351. };
  352. struct msghdr msg = {
  353. .msg_name = NULL,
  354. .msg_namelen = 0,
  355. .msg_iov = iov,
  356. .msg_iovlen = 2,
  357. .msg_control = NULL,
  358. .msg_controllen = 0,
  359. .msg_flags = 0,
  360. };
  361. /*
  362. * ugh, guess what, the generic code sets one of the version
  363. * bits to request tx callback
  364. */
  365. hdr->frame_control &= ~host_to_le16(BIT(1));
  366. return sendmsg(drv->monitor_sock, &msg, flags);
  367. }
  368. /* Set kernel driver on given frequency (MHz) */
  369. static int i802_set_freq(void *priv, int mode, int freq)
  370. {
  371. struct i802_driver_data *drv = priv;
  372. struct iwreq iwr;
  373. memset(&iwr, 0, sizeof(iwr));
  374. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  375. iwr.u.freq.m = freq;
  376. iwr.u.freq.e = 6;
  377. if (ioctl(drv->ioctl_sock, SIOCSIWFREQ, &iwr) < 0) {
  378. perror("ioctl[SIOCSIWFREQ]");
  379. return -1;
  380. }
  381. return 0;
  382. }
  383. static int i802_set_rts(void *priv, int rts)
  384. {
  385. struct i802_driver_data *drv = priv;
  386. struct iwreq iwr;
  387. memset(&iwr, 0, sizeof(iwr));
  388. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  389. iwr.u.rts.value = rts;
  390. iwr.u.rts.fixed = 1;
  391. if (ioctl(drv->ioctl_sock, SIOCSIWRTS, &iwr) < 0) {
  392. perror("ioctl[SIOCSIWRTS]");
  393. return -1;
  394. }
  395. return 0;
  396. }
  397. static int i802_get_rts(void *priv, int *rts)
  398. {
  399. struct i802_driver_data *drv = priv;
  400. struct iwreq iwr;
  401. memset(&iwr, 0, sizeof(iwr));
  402. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  403. if (ioctl(drv->ioctl_sock, SIOCGIWRTS, &iwr) < 0) {
  404. perror("ioctl[SIOCGIWRTS]");
  405. return -1;
  406. }
  407. *rts = iwr.u.rts.value;
  408. return 0;
  409. }
  410. static int i802_set_frag(void *priv, int frag)
  411. {
  412. struct i802_driver_data *drv = priv;
  413. struct iwreq iwr;
  414. memset(&iwr, 0, sizeof(iwr));
  415. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  416. iwr.u.frag.value = frag;
  417. iwr.u.frag.fixed = 1;
  418. if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
  419. perror("ioctl[SIOCSIWFRAG]");
  420. return -1;
  421. }
  422. return 0;
  423. }
  424. static int i802_get_frag(void *priv, int *frag)
  425. {
  426. struct i802_driver_data *drv = priv;
  427. struct iwreq iwr;
  428. memset(&iwr, 0, sizeof(iwr));
  429. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  430. if (ioctl(drv->ioctl_sock, SIOCGIWFRAG, &iwr) < 0) {
  431. perror("ioctl[SIOCGIWFRAG]");
  432. return -1;
  433. }
  434. *frag = iwr.u.frag.value;
  435. return 0;
  436. }
  437. static int i802_set_retry(void *priv, int short_retry, int long_retry)
  438. {
  439. struct i802_driver_data *drv = priv;
  440. struct iwreq iwr;
  441. memset(&iwr, 0, sizeof(iwr));
  442. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  443. iwr.u.retry.value = short_retry;
  444. iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
  445. if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
  446. perror("ioctl[SIOCSIWRETRY(short)]");
  447. return -1;
  448. }
  449. iwr.u.retry.value = long_retry;
  450. iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  451. if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
  452. perror("ioctl[SIOCSIWRETRY(long)]");
  453. return -1;
  454. }
  455. return 0;
  456. }
  457. static int i802_get_retry(void *priv, int *short_retry, int *long_retry)
  458. {
  459. struct i802_driver_data *drv = priv;
  460. struct iwreq iwr;
  461. memset(&iwr, 0, sizeof(iwr));
  462. os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
  463. iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
  464. if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
  465. perror("ioctl[SIOCGIWFRAG(short)]");
  466. return -1;
  467. }
  468. *short_retry = iwr.u.retry.value;
  469. iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  470. if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
  471. perror("ioctl[SIOCGIWFRAG(long)]");
  472. return -1;
  473. }
  474. *long_retry = iwr.u.retry.value;
  475. return 0;
  476. }
  477. static int i802_flush(void *priv)
  478. {
  479. struct i802_driver_data *drv = priv;
  480. struct nl_msg *msg;
  481. int ret = -1;
  482. msg = nlmsg_alloc();
  483. if (!msg)
  484. goto out;
  485. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  486. 0, NL80211_CMD_DEL_STATION, 0);
  487. /*
  488. * XXX: FIX! this needs to flush all VLANs too
  489. */
  490. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  491. if_nametoindex(drv->iface));
  492. ret = 0;
  493. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  494. nl_wait_for_ack(drv->nl_handle) < 0) {
  495. ret = -1;
  496. }
  497. nla_put_failure:
  498. nlmsg_free(msg);
  499. out:
  500. return ret;
  501. }
  502. static int get_sta_handler(struct nl_msg *msg, void *arg)
  503. {
  504. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  505. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  506. struct hostap_sta_driver_data *data = arg;
  507. struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
  508. static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
  509. [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
  510. [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
  511. [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
  512. };
  513. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  514. genlmsg_attrlen(gnlh, 0), NULL);
  515. /*
  516. * TODO: validate the interface and mac address!
  517. * Otherwise, there's a race condition as soon as
  518. * the kernel starts sending station notifications.
  519. */
  520. if (!tb[NL80211_ATTR_STA_INFO]) {
  521. wpa_printf(MSG_DEBUG, "sta stats missing!");
  522. return NL_SKIP;
  523. }
  524. if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
  525. tb[NL80211_ATTR_STA_INFO],
  526. stats_policy)) {
  527. wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
  528. return NL_SKIP;
  529. }
  530. if (stats[NL80211_STA_INFO_INACTIVE_TIME])
  531. data->inactive_msec =
  532. nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
  533. if (stats[NL80211_STA_INFO_RX_BYTES])
  534. data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
  535. if (stats[NL80211_STA_INFO_TX_BYTES])
  536. data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
  537. return NL_SKIP;
  538. }
  539. static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
  540. const u8 *addr)
  541. {
  542. struct i802_driver_data *drv = priv;
  543. struct nl_msg *msg;
  544. struct nl_cb *cb = NULL;
  545. int ret = -1;
  546. int err = 0;
  547. int finished = 0;
  548. msg = nlmsg_alloc();
  549. if (!msg)
  550. goto out;
  551. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  552. 0, NL80211_CMD_GET_STATION, 0);
  553. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  554. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
  555. cb = nl_cb_clone(drv->nl_cb);
  556. if (!cb)
  557. goto out;
  558. if (nl_send_auto_complete(drv->nl_handle, msg) < 0)
  559. goto out;
  560. nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, get_sta_handler, data);
  561. nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, &finished);
  562. err = nl_recvmsgs(drv->nl_handle, cb);
  563. if (!finished)
  564. err = nl_wait_for_ack(drv->nl_handle);
  565. if (err < 0)
  566. goto out;
  567. ret = 0;
  568. out:
  569. nl_cb_put(cb);
  570. nla_put_failure:
  571. nlmsg_free(msg);
  572. return ret;
  573. }
  574. static int i802_send_eapol(void *priv, const u8 *addr, const u8 *data,
  575. size_t data_len, int encrypt, const u8 *own_addr)
  576. {
  577. struct i802_driver_data *drv = priv;
  578. struct ieee80211_hdr *hdr;
  579. size_t len;
  580. u8 *pos;
  581. int res;
  582. #if 0 /* FIX */
  583. int qos = sta->flags & WLAN_STA_WME;
  584. #else
  585. int qos = 0;
  586. #endif
  587. len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
  588. data_len;
  589. hdr = os_zalloc(len);
  590. if (hdr == NULL) {
  591. printf("malloc() failed for i802_send_data(len=%lu)\n",
  592. (unsigned long) len);
  593. return -1;
  594. }
  595. hdr->frame_control =
  596. IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
  597. hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
  598. if (encrypt)
  599. hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
  600. #if 0 /* To be enabled if qos determination is added above */
  601. if (qos) {
  602. hdr->frame_control |=
  603. host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
  604. }
  605. #endif
  606. memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
  607. memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
  608. memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
  609. pos = (u8 *) (hdr + 1);
  610. #if 0 /* To be enabled if qos determination is added above */
  611. if (qos) {
  612. /* add an empty QoS header if needed */
  613. pos[0] = 0;
  614. pos[1] = 0;
  615. pos += 2;
  616. }
  617. #endif
  618. memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
  619. pos += sizeof(rfc1042_header);
  620. WPA_PUT_BE16(pos, ETH_P_PAE);
  621. pos += 2;
  622. memcpy(pos, data, data_len);
  623. res = i802_send_mgmt_frame(drv, (u8 *) hdr, len, 0);
  624. free(hdr);
  625. if (res < 0) {
  626. perror("i802_send_eapol: send");
  627. printf("i802_send_eapol - packet len: %lu - failed\n",
  628. (unsigned long) len);
  629. }
  630. return res;
  631. }
  632. static int i802_sta_add2(const char *ifname, void *priv,
  633. struct hostapd_sta_add_params *params)
  634. {
  635. struct i802_driver_data *drv = priv;
  636. struct nl_msg *msg;
  637. int ret = -1;
  638. msg = nlmsg_alloc();
  639. if (!msg)
  640. goto out;
  641. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  642. 0, NL80211_CMD_NEW_STATION, 0);
  643. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  644. if_nametoindex(drv->iface));
  645. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr);
  646. NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid);
  647. NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len,
  648. params->supp_rates);
  649. NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
  650. params->listen_interval);
  651. #ifdef CONFIG_IEEE80211N
  652. #ifdef NL80211_ATTR_HT_CAPABILITY
  653. if (params->ht_capabilities) {
  654. NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY,
  655. params->ht_capabilities->length,
  656. &params->ht_capabilities->data);
  657. }
  658. #endif /* NL80211_ATTR_HT_CAPABILITY */
  659. #endif /* CONFIG_IEEE80211N */
  660. ret = nl_send_auto_complete(drv->nl_handle, msg);
  661. if (ret < 0)
  662. goto nla_put_failure;
  663. ret = nl_wait_for_ack(drv->nl_handle);
  664. /* ignore EEXIST, this happens if a STA associates while associated */
  665. if (ret == -EEXIST || ret >= 0)
  666. ret = 0;
  667. nla_put_failure:
  668. nlmsg_free(msg);
  669. out:
  670. return ret;
  671. }
  672. static int i802_sta_remove(void *priv, const u8 *addr)
  673. {
  674. struct i802_driver_data *drv = priv;
  675. struct nl_msg *msg;
  676. int ret = -1;
  677. msg = nlmsg_alloc();
  678. if (!msg)
  679. goto out;
  680. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  681. 0, NL80211_CMD_DEL_STATION, 0);
  682. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  683. if_nametoindex(drv->iface));
  684. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  685. ret = 0;
  686. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  687. nl_wait_for_ack(drv->nl_handle) < 0) {
  688. ret = -1;
  689. }
  690. nla_put_failure:
  691. nlmsg_free(msg);
  692. out:
  693. return ret;
  694. }
  695. static int i802_sta_set_flags(void *priv, const u8 *addr,
  696. int total_flags, int flags_or, int flags_and)
  697. {
  698. struct i802_driver_data *drv = priv;
  699. struct nl_msg *msg, *flags = NULL;
  700. int ret = -1;
  701. msg = nlmsg_alloc();
  702. if (!msg)
  703. goto out;
  704. flags = nlmsg_alloc();
  705. if (!flags)
  706. goto free_msg;
  707. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  708. 0, NL80211_CMD_SET_STATION, 0);
  709. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  710. if_nametoindex(drv->iface));
  711. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  712. if (total_flags & WLAN_STA_AUTHORIZED || !drv->ieee802_1x_active)
  713. NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
  714. if (total_flags & WLAN_STA_WME)
  715. NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
  716. if (total_flags & WLAN_STA_SHORT_PREAMBLE)
  717. NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
  718. #ifdef NL80211_MFP_PENDING
  719. if (total_flags & WLAN_STA_MFP)
  720. NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
  721. #endif /* NL80211_MFP_PENDING */
  722. if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
  723. goto nla_put_failure;
  724. ret = 0;
  725. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  726. nl_wait_for_ack(drv->nl_handle) < 0) {
  727. ret = -1;
  728. }
  729. nla_put_failure:
  730. nlmsg_free(flags);
  731. free_msg:
  732. nlmsg_free(msg);
  733. out:
  734. return ret;
  735. }
  736. static int i802_set_channel_flag(void *priv, int mode, int chan, int flag,
  737. unsigned char power_level,
  738. unsigned char antenna_max)
  739. {
  740. return -1;
  741. }
  742. static int i802_set_regulatory_domain(void *priv, unsigned int rd)
  743. {
  744. return -1;
  745. }
  746. static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
  747. int cw_min, int cw_max, int burst_time)
  748. {
  749. return -1;
  750. }
  751. static void nl80211_remove_iface(struct i802_driver_data *drv, int ifidx)
  752. {
  753. struct nl_msg *msg;
  754. /* stop listening for EAPOL on this interface */
  755. del_ifidx(drv, ifidx);
  756. msg = nlmsg_alloc();
  757. if (!msg)
  758. goto nla_put_failure;
  759. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  760. 0, NL80211_CMD_DEL_INTERFACE, 0);
  761. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
  762. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  763. nl_wait_for_ack(drv->nl_handle) < 0)
  764. nla_put_failure:
  765. printf("Failed to remove interface.\n");
  766. nlmsg_free(msg);
  767. }
  768. static int nl80211_create_iface(struct i802_driver_data *drv,
  769. const char *ifname,
  770. enum nl80211_iftype iftype,
  771. const u8 *addr)
  772. {
  773. struct nl_msg *msg, *flags = NULL;
  774. int ifidx;
  775. struct ifreq ifreq;
  776. struct iwreq iwr;
  777. msg = nlmsg_alloc();
  778. if (!msg)
  779. return -1;
  780. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  781. 0, NL80211_CMD_NEW_INTERFACE, 0);
  782. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  783. if_nametoindex(drv->hapd->conf->iface));
  784. NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
  785. NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
  786. if (iftype == NL80211_IFTYPE_MONITOR) {
  787. int err;
  788. flags = nlmsg_alloc();
  789. if (!flags)
  790. goto nla_put_failure;
  791. NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
  792. err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
  793. nlmsg_free(flags);
  794. if (err)
  795. goto nla_put_failure;
  796. }
  797. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  798. nl_wait_for_ack(drv->nl_handle) < 0) {
  799. nla_put_failure:
  800. printf("Failed to create interface %s.\n", ifname);
  801. nlmsg_free(msg);
  802. return -1;
  803. }
  804. nlmsg_free(msg);
  805. ifidx = if_nametoindex(ifname);
  806. if (ifidx <= 0)
  807. return -1;
  808. /* start listening for EAPOL on this interface */
  809. add_ifidx(drv, ifidx);
  810. if (addr) {
  811. switch (iftype) {
  812. case NL80211_IFTYPE_AP:
  813. os_strlcpy(ifreq.ifr_name, ifname, IFNAMSIZ);
  814. memcpy(ifreq.ifr_hwaddr.sa_data, addr, ETH_ALEN);
  815. ifreq.ifr_hwaddr.sa_family = ARPHRD_ETHER;
  816. if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifreq)) {
  817. nl80211_remove_iface(drv, ifidx);
  818. return -1;
  819. }
  820. break;
  821. case NL80211_IFTYPE_WDS:
  822. memset(&iwr, 0, sizeof(iwr));
  823. os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
  824. iwr.u.addr.sa_family = ARPHRD_ETHER;
  825. memcpy(iwr.u.addr.sa_data, addr, ETH_ALEN);
  826. if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr))
  827. return -1;
  828. break;
  829. default:
  830. /* nothing */
  831. break;
  832. }
  833. }
  834. return ifidx;
  835. }
  836. static int i802_bss_add(void *priv, const char *ifname, const u8 *bssid)
  837. {
  838. int ifidx;
  839. /*
  840. * The kernel supports that when the low-level driver does,
  841. * but we currently don't because we need per-BSS data that
  842. * currently we can't handle easily.
  843. */
  844. return -1;
  845. ifidx = nl80211_create_iface(priv, ifname, NL80211_IFTYPE_AP, bssid);
  846. if (ifidx < 0)
  847. return -1;
  848. if (hostapd_set_iface_flags(priv, ifname, 1)) {
  849. nl80211_remove_iface(priv, ifidx);
  850. return -1;
  851. }
  852. return 0;
  853. }
  854. static int i802_bss_remove(void *priv, const char *ifname)
  855. {
  856. nl80211_remove_iface(priv, if_nametoindex(ifname));
  857. return 0;
  858. }
  859. static int i802_set_beacon(const char *iface, void *priv,
  860. u8 *head, size_t head_len,
  861. u8 *tail, size_t tail_len)
  862. {
  863. struct i802_driver_data *drv = priv;
  864. struct nl_msg *msg;
  865. u8 cmd = NL80211_CMD_NEW_BEACON;
  866. int ret = -1;
  867. msg = nlmsg_alloc();
  868. if (!msg)
  869. goto out;
  870. if (drv->beacon_set)
  871. cmd = NL80211_CMD_SET_BEACON;
  872. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  873. 0, cmd, 0);
  874. NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
  875. NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
  876. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
  877. NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, drv->beacon_int);
  878. if (!drv->dtim_period)
  879. drv->dtim_period = 2;
  880. NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
  881. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  882. nl_wait_for_ack(drv->nl_handle) < 0)
  883. goto out;
  884. ret = 0;
  885. drv->beacon_set = 1;
  886. out:
  887. nla_put_failure:
  888. nlmsg_free(msg);
  889. return ret;
  890. }
  891. static int i802_del_beacon(struct i802_driver_data *drv)
  892. {
  893. struct nl_msg *msg;
  894. int ret = -1;
  895. msg = nlmsg_alloc();
  896. if (!msg)
  897. goto out;
  898. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  899. 0, NL80211_CMD_DEL_BEACON, 0);
  900. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
  901. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  902. nl_wait_for_ack(drv->nl_handle) < 0)
  903. goto out;
  904. ret = 0;
  905. out:
  906. nla_put_failure:
  907. nlmsg_free(msg);
  908. return ret;
  909. }
  910. static int i802_set_ieee8021x(const char *ifname, void *priv, int enabled)
  911. {
  912. struct i802_driver_data *drv = priv;
  913. /*
  914. * FIXME: This needs to be per interface (BSS)
  915. */
  916. drv->ieee802_1x_active = enabled;
  917. return 0;
  918. }
  919. static int i802_set_privacy(const char *ifname, void *priv, int enabled)
  920. {
  921. struct i802_driver_data *drv = priv;
  922. struct iwreq iwr;
  923. memset(&iwr, 0, sizeof(iwr));
  924. os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
  925. iwr.u.param.flags = IW_AUTH_PRIVACY_INVOKED;
  926. iwr.u.param.value = enabled;
  927. ioctl(drv->ioctl_sock, SIOCSIWAUTH, &iwr);
  928. /* ignore errors, the kernel/driver might not care */
  929. return 0;
  930. }
  931. static int i802_set_internal_bridge(void *priv, int value)
  932. {
  933. return -1;
  934. }
  935. static int i802_set_beacon_int(void *priv, int value)
  936. {
  937. struct i802_driver_data *drv = priv;
  938. struct nl_msg *msg;
  939. int ret = -1;
  940. drv->beacon_int = value;
  941. if (!drv->beacon_set)
  942. return 0;
  943. msg = nlmsg_alloc();
  944. if (!msg)
  945. goto out;
  946. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  947. 0, NL80211_CMD_SET_BEACON, 0);
  948. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
  949. NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
  950. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  951. nl_wait_for_ack(drv->nl_handle) < 0)
  952. goto out;
  953. ret = 0;
  954. out:
  955. nla_put_failure:
  956. nlmsg_free(msg);
  957. return ret;
  958. }
  959. static int i802_set_dtim_period(const char *iface, void *priv, int value)
  960. {
  961. struct i802_driver_data *drv = priv;
  962. struct nl_msg *msg;
  963. int ret = -1;
  964. msg = nlmsg_alloc();
  965. if (!msg)
  966. goto out;
  967. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  968. 0, NL80211_CMD_SET_BEACON, 0);
  969. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
  970. drv->dtim_period = value;
  971. NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
  972. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  973. nl_wait_for_ack(drv->nl_handle) < 0)
  974. goto out;
  975. ret = 0;
  976. out:
  977. nla_put_failure:
  978. nlmsg_free(msg);
  979. return ret;
  980. }
  981. static int i802_set_bss(void *priv, int cts, int preamble, int slot)
  982. {
  983. #ifdef NL80211_CMD_SET_BSS
  984. struct i802_driver_data *drv = priv;
  985. struct nl_msg *msg;
  986. int ret = -1;
  987. msg = nlmsg_alloc();
  988. if (!msg)
  989. goto out;
  990. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
  991. NL80211_CMD_SET_BSS, 0);
  992. if (cts >= 0)
  993. NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts);
  994. if (preamble >= 0)
  995. NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble);
  996. if (slot >= 0)
  997. NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
  998. ret = 0;
  999. /* TODO: multi-BSS support */
  1000. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
  1001. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  1002. nl_wait_for_ack(drv->nl_handle) < 0) {
  1003. ret = -1;
  1004. }
  1005. nla_put_failure:
  1006. nlmsg_free(msg);
  1007. out:
  1008. return ret;
  1009. #else /* NL80211_CMD_SET_BSS */
  1010. return -1;
  1011. #endif /* NL80211_CMD_SET_BSS */
  1012. }
  1013. static int i802_set_cts_protect(void *priv, int value)
  1014. {
  1015. return i802_set_bss(priv, value, -1, -1);
  1016. }
  1017. static int i802_set_preamble(void *priv, int value)
  1018. {
  1019. return i802_set_bss(priv, -1, value, -1);
  1020. }
  1021. static int i802_set_short_slot_time(void *priv, int value)
  1022. {
  1023. return i802_set_bss(priv, -1, -1, value);
  1024. }
  1025. static enum nl80211_iftype i802_if_type(enum hostapd_driver_if_type type)
  1026. {
  1027. switch (type) {
  1028. case HOSTAPD_IF_VLAN:
  1029. return NL80211_IFTYPE_AP_VLAN;
  1030. case HOSTAPD_IF_WDS:
  1031. return NL80211_IFTYPE_WDS;
  1032. }
  1033. return -1;
  1034. }
  1035. static int i802_if_add(const char *iface, void *priv,
  1036. enum hostapd_driver_if_type type, char *ifname,
  1037. const u8 *addr)
  1038. {
  1039. if (nl80211_create_iface(priv, ifname, i802_if_type(type), addr) < 0)
  1040. return -1;
  1041. return 0;
  1042. }
  1043. static int i802_if_update(void *priv, enum hostapd_driver_if_type type,
  1044. char *ifname, const u8 *addr)
  1045. {
  1046. /* unused at the moment */
  1047. return -1;
  1048. }
  1049. static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
  1050. const char *ifname, const u8 *addr)
  1051. {
  1052. nl80211_remove_iface(priv, if_nametoindex(ifname));
  1053. return 0;
  1054. }
  1055. struct phy_info_arg {
  1056. u16 *num_modes;
  1057. struct hostapd_hw_modes *modes;
  1058. int error;
  1059. };
  1060. static int phy_info_handler(struct nl_msg *msg, void *arg)
  1061. {
  1062. struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
  1063. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  1064. struct phy_info_arg *phy_info = arg;
  1065. struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
  1066. struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
  1067. static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
  1068. [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
  1069. [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
  1070. [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
  1071. [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
  1072. [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
  1073. };
  1074. struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
  1075. static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
  1076. [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
  1077. [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
  1078. };
  1079. struct nlattr *nl_band;
  1080. struct nlattr *nl_freq;
  1081. struct nlattr *nl_rate;
  1082. int rem_band, rem_freq, rem_rate;
  1083. struct hostapd_hw_modes *mode;
  1084. int idx, mode_is_set;
  1085. nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  1086. genlmsg_attrlen(gnlh, 0), NULL);
  1087. if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
  1088. return NL_SKIP;
  1089. nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
  1090. mode = realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode));
  1091. if (!mode)
  1092. return NL_SKIP;
  1093. phy_info->modes = mode;
  1094. mode_is_set = 0;
  1095. mode = &phy_info->modes[*(phy_info->num_modes)];
  1096. memset(mode, 0, sizeof(*mode));
  1097. *(phy_info->num_modes) += 1;
  1098. nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
  1099. nla_len(nl_band), NULL);
  1100. nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
  1101. nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
  1102. nla_len(nl_freq), freq_policy);
  1103. if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
  1104. continue;
  1105. mode->num_channels++;
  1106. }
  1107. mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_channel_data));
  1108. if (!mode->channels)
  1109. return NL_SKIP;
  1110. idx = 0;
  1111. nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
  1112. nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
  1113. nla_len(nl_freq), freq_policy);
  1114. if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
  1115. continue;
  1116. mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
  1117. mode->channels[idx].flag |= HOSTAPD_CHAN_W_SCAN |
  1118. HOSTAPD_CHAN_W_ACTIVE_SCAN |
  1119. HOSTAPD_CHAN_W_IBSS;
  1120. if (!mode_is_set) {
  1121. /* crude heuristic */
  1122. if (mode->channels[idx].freq < 4000)
  1123. mode->mode = HOSTAPD_MODE_IEEE80211B;
  1124. else
  1125. mode->mode = HOSTAPD_MODE_IEEE80211A;
  1126. mode_is_set = 1;
  1127. }
  1128. /* crude heuristic */
  1129. if (mode->channels[idx].freq < 4000)
  1130. if (mode->channels[idx].freq == 2848)
  1131. mode->channels[idx].chan = 14;
  1132. else
  1133. mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5;
  1134. else
  1135. mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000;
  1136. if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
  1137. mode->channels[idx].flag &= ~HOSTAPD_CHAN_W_SCAN;
  1138. if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
  1139. mode->channels[idx].flag &= ~HOSTAPD_CHAN_W_ACTIVE_SCAN;
  1140. if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
  1141. mode->channels[idx].flag &= ~HOSTAPD_CHAN_W_IBSS;
  1142. idx++;
  1143. }
  1144. nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
  1145. nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
  1146. nla_len(nl_rate), rate_policy);
  1147. if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
  1148. continue;
  1149. mode->num_rates++;
  1150. }
  1151. mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
  1152. if (!mode->rates)
  1153. return NL_SKIP;
  1154. idx = 0;
  1155. nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
  1156. nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
  1157. nla_len(nl_rate), rate_policy);
  1158. if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
  1159. continue;
  1160. mode->rates[idx].rate = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
  1161. /* crude heuristic */
  1162. if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
  1163. mode->rates[idx].rate > 200)
  1164. mode->mode = HOSTAPD_MODE_IEEE80211G;
  1165. if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
  1166. mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
  1167. idx++;
  1168. }
  1169. }
  1170. phy_info->error = 0;
  1171. return NL_SKIP;
  1172. }
  1173. static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
  1174. u16 *num_modes,
  1175. u16 *flags)
  1176. {
  1177. struct i802_driver_data *drv = priv;
  1178. struct nl_msg *msg;
  1179. int err = -1;
  1180. struct nl_cb *cb = NULL;
  1181. int finished = 0;
  1182. struct phy_info_arg result = {
  1183. .num_modes = num_modes,
  1184. .modes = NULL,
  1185. .error = 1,
  1186. };
  1187. *num_modes = 0;
  1188. *flags = 0;
  1189. msg = nlmsg_alloc();
  1190. if (!msg)
  1191. return NULL;
  1192. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  1193. 0, NL80211_CMD_GET_WIPHY, 0);
  1194. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
  1195. cb = nl_cb_clone(drv->nl_cb);
  1196. if (!cb)
  1197. goto out;
  1198. if (nl_send_auto_complete(drv->nl_handle, msg) < 0)
  1199. goto out;
  1200. nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, phy_info_handler, &result);
  1201. nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, &finished);
  1202. err = nl_recvmsgs(drv->nl_handle, cb);
  1203. if (!finished)
  1204. err = nl_wait_for_ack(drv->nl_handle);
  1205. if (err < 0 || result.error) {
  1206. hostapd_free_hw_features(result.modes, *num_modes);
  1207. result.modes = NULL;
  1208. }
  1209. out:
  1210. nl_cb_put(cb);
  1211. nla_put_failure:
  1212. if (err)
  1213. fprintf(stderr, "failed to get information: %d\n", err);
  1214. nlmsg_free(msg);
  1215. return result.modes;
  1216. }
  1217. static int i802_set_sta_vlan(void *priv, const u8 *addr,
  1218. const char *ifname, int vlan_id)
  1219. {
  1220. struct i802_driver_data *drv = priv;
  1221. struct nl_msg *msg;
  1222. int ret = -1;
  1223. msg = nlmsg_alloc();
  1224. if (!msg)
  1225. goto out;
  1226. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  1227. 0, NL80211_CMD_SET_STATION, 0);
  1228. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  1229. if_nametoindex(drv->iface));
  1230. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  1231. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  1232. if_nametoindex(ifname));
  1233. ret = 0;
  1234. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  1235. (errno = nl_wait_for_ack(drv->nl_handle) < 0)) {
  1236. ret = -1;
  1237. }
  1238. nla_put_failure:
  1239. nlmsg_free(msg);
  1240. out:
  1241. return ret;
  1242. }
  1243. static void handle_unknown_sta(struct hostapd_data *hapd, u8 *ta)
  1244. {
  1245. struct sta_info *sta;
  1246. sta = ap_get_sta(hapd, ta);
  1247. if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
  1248. printf("Data/PS-poll frame from not associated STA "
  1249. MACSTR "\n", MAC2STR(ta));
  1250. if (sta && (sta->flags & WLAN_STA_AUTH))
  1251. hostapd_sta_disassoc(
  1252. hapd, ta,
  1253. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1254. else
  1255. hostapd_sta_deauth(
  1256. hapd, ta,
  1257. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1258. }
  1259. }
  1260. static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
  1261. int ok)
  1262. {
  1263. struct ieee80211_hdr *hdr;
  1264. u16 fc, type, stype;
  1265. struct sta_info *sta;
  1266. hdr = (struct ieee80211_hdr *) buf;
  1267. fc = le_to_host16(hdr->frame_control);
  1268. type = WLAN_FC_GET_TYPE(fc);
  1269. stype = WLAN_FC_GET_STYPE(fc);
  1270. switch (type) {
  1271. case WLAN_FC_TYPE_MGMT:
  1272. wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
  1273. ok ? "ACK" : "fail");
  1274. ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
  1275. break;
  1276. case WLAN_FC_TYPE_CTRL:
  1277. wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
  1278. ok ? "ACK" : "fail");
  1279. break;
  1280. case WLAN_FC_TYPE_DATA:
  1281. wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
  1282. ok ? "ACK" : "fail");
  1283. sta = ap_get_sta(hapd, hdr->addr1);
  1284. if (sta && sta->flags & WLAN_STA_PENDING_POLL) {
  1285. wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
  1286. "activity poll", MAC2STR(sta->addr),
  1287. ok ? "ACKed" : "did not ACK");
  1288. if (ok)
  1289. sta->flags &= ~WLAN_STA_PENDING_POLL;
  1290. }
  1291. if (sta)
  1292. ieee802_1x_tx_status(hapd, sta, buf, len, ok);
  1293. break;
  1294. default:
  1295. printf("unknown TX callback frame type %d\n", type);
  1296. break;
  1297. }
  1298. }
  1299. static void handle_frame(struct hostapd_iface *iface, u8 *buf, size_t len,
  1300. struct hostapd_frame_info *hfi,
  1301. enum ieee80211_msg_type msg_type)
  1302. {
  1303. struct ieee80211_hdr *hdr;
  1304. u16 fc, type, stype;
  1305. size_t data_len = len;
  1306. struct hostapd_data *hapd = NULL;
  1307. int broadcast_bssid = 0;
  1308. size_t i;
  1309. u8 *bssid;
  1310. /*
  1311. * PS-Poll frames are 16 bytes. All other frames are
  1312. * 24 bytes or longer.
  1313. */
  1314. if (len < 16)
  1315. return;
  1316. hdr = (struct ieee80211_hdr *) buf;
  1317. fc = le_to_host16(hdr->frame_control);
  1318. type = WLAN_FC_GET_TYPE(fc);
  1319. stype = WLAN_FC_GET_STYPE(fc);
  1320. switch (type) {
  1321. case WLAN_FC_TYPE_DATA:
  1322. if (len < 24)
  1323. return;
  1324. switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
  1325. case WLAN_FC_TODS:
  1326. bssid = hdr->addr1;
  1327. break;
  1328. default:
  1329. /* discard */
  1330. return;
  1331. }
  1332. break;
  1333. case WLAN_FC_TYPE_CTRL:
  1334. /* discard non-ps-poll frames */
  1335. if (stype != WLAN_FC_STYPE_PSPOLL)
  1336. return;
  1337. bssid = hdr->addr1;
  1338. break;
  1339. case WLAN_FC_TYPE_MGMT:
  1340. bssid = hdr->addr3;
  1341. break;
  1342. default:
  1343. /* discard */
  1344. return;
  1345. }
  1346. /* find interface frame belongs to */
  1347. for (i = 0; i < iface->num_bss; i++) {
  1348. if (memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) {
  1349. hapd = iface->bss[i];
  1350. break;
  1351. }
  1352. }
  1353. if (hapd == NULL) {
  1354. hapd = iface->bss[0];
  1355. if (bssid[0] != 0xff || bssid[1] != 0xff ||
  1356. bssid[2] != 0xff || bssid[3] != 0xff ||
  1357. bssid[4] != 0xff || bssid[5] != 0xff) {
  1358. /*
  1359. * Unknown BSSID - drop frame if this is not from
  1360. * passive scanning or a beacon (at least ProbeReq
  1361. * frames to other APs may be allowed through RX
  1362. * filtering in the wlan hw/driver)
  1363. */
  1364. if ((type != WLAN_FC_TYPE_MGMT ||
  1365. stype != WLAN_FC_STYPE_BEACON))
  1366. return;
  1367. } else
  1368. broadcast_bssid = 1;
  1369. }
  1370. switch (msg_type) {
  1371. case ieee80211_msg_normal:
  1372. /* continue processing */
  1373. break;
  1374. case ieee80211_msg_tx_callback_ack:
  1375. handle_tx_callback(hapd, buf, data_len, 1);
  1376. return;
  1377. case ieee80211_msg_tx_callback_fail:
  1378. handle_tx_callback(hapd, buf, data_len, 0);
  1379. return;
  1380. }
  1381. switch (type) {
  1382. case WLAN_FC_TYPE_MGMT:
  1383. if (stype != WLAN_FC_STYPE_BEACON &&
  1384. stype != WLAN_FC_STYPE_PROBE_REQ)
  1385. wpa_printf(MSG_MSGDUMP, "MGMT");
  1386. if (broadcast_bssid) {
  1387. for (i = 0; i < iface->num_bss; i++)
  1388. ieee802_11_mgmt(iface->bss[i], buf, data_len,
  1389. stype, hfi);
  1390. } else
  1391. ieee802_11_mgmt(hapd, buf, data_len, stype, hfi);
  1392. break;
  1393. case WLAN_FC_TYPE_CTRL:
  1394. /* can only get here with PS-Poll frames */
  1395. wpa_printf(MSG_DEBUG, "CTRL");
  1396. handle_unknown_sta(hapd, hdr->addr2);
  1397. break;
  1398. case WLAN_FC_TYPE_DATA:
  1399. wpa_printf(MSG_DEBUG, "DATA");
  1400. handle_unknown_sta(hapd, hdr->addr2);
  1401. break;
  1402. }
  1403. }
  1404. static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
  1405. {
  1406. struct i802_driver_data *drv = eloop_ctx;
  1407. struct hostapd_data *hapd = drv->hapd;
  1408. struct sockaddr_ll lladdr;
  1409. unsigned char buf[3000];
  1410. int len;
  1411. socklen_t fromlen = sizeof(lladdr);
  1412. len = recvfrom(sock, buf, sizeof(buf), 0,
  1413. (struct sockaddr *)&lladdr, &fromlen);
  1414. if (len < 0) {
  1415. perror("recv");
  1416. return;
  1417. }
  1418. if (have_ifidx(drv, lladdr.sll_ifindex))
  1419. ieee802_1x_receive(hapd, lladdr.sll_addr, buf, len);
  1420. }
  1421. static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
  1422. {
  1423. struct i802_driver_data *drv = eloop_ctx;
  1424. int len;
  1425. unsigned char buf[3000];
  1426. struct hostapd_data *hapd = drv->hapd;
  1427. struct ieee80211_radiotap_iterator iter;
  1428. int ret;
  1429. struct hostapd_frame_info hfi;
  1430. int injected = 0, failed = 0, msg_type, rxflags = 0;
  1431. len = recv(sock, buf, sizeof(buf), 0);
  1432. if (len < 0) {
  1433. perror("recv");
  1434. return;
  1435. }
  1436. if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) {
  1437. printf("received invalid radiotap frame\n");
  1438. return;
  1439. }
  1440. memset(&hfi, 0, sizeof(hfi));
  1441. while (1) {
  1442. ret = ieee80211_radiotap_iterator_next(&iter);
  1443. if (ret == -ENOENT)
  1444. break;
  1445. if (ret) {
  1446. printf("received invalid radiotap frame (%d)\n", ret);
  1447. return;
  1448. }
  1449. switch (iter.this_arg_index) {
  1450. case IEEE80211_RADIOTAP_FLAGS:
  1451. if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
  1452. len -= 4;
  1453. break;
  1454. case IEEE80211_RADIOTAP_RX_FLAGS:
  1455. rxflags = 1;
  1456. break;
  1457. case IEEE80211_RADIOTAP_TX_FLAGS:
  1458. injected = 1;
  1459. failed = le_to_host16((*(uint16_t *) iter.this_arg)) &
  1460. IEEE80211_RADIOTAP_F_TX_FAIL;
  1461. break;
  1462. case IEEE80211_RADIOTAP_DATA_RETRIES:
  1463. break;
  1464. case IEEE80211_RADIOTAP_CHANNEL:
  1465. /* TODO convert from freq/flags to channel number
  1466. hfi.channel = XXX;
  1467. hfi.phytype = XXX;
  1468. */
  1469. break;
  1470. case IEEE80211_RADIOTAP_RATE:
  1471. hfi.datarate = *iter.this_arg * 5;
  1472. break;
  1473. case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
  1474. hfi.ssi_signal = *iter.this_arg;
  1475. break;
  1476. }
  1477. }
  1478. if (rxflags && injected)
  1479. return;
  1480. if (!injected)
  1481. msg_type = ieee80211_msg_normal;
  1482. else if (failed)
  1483. msg_type = ieee80211_msg_tx_callback_fail;
  1484. else
  1485. msg_type = ieee80211_msg_tx_callback_ack;
  1486. handle_frame(hapd->iface, buf + iter.max_length,
  1487. len - iter.max_length, &hfi, msg_type);
  1488. }
  1489. static int nl80211_create_monitor_interface(struct i802_driver_data *drv)
  1490. {
  1491. char buf[IFNAMSIZ];
  1492. struct sockaddr_ll ll;
  1493. int optval;
  1494. socklen_t optlen;
  1495. snprintf(buf, IFNAMSIZ, "mon.%s", drv->iface);
  1496. buf[IFNAMSIZ - 1] = '\0';
  1497. drv->monitor_ifidx =
  1498. nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL);
  1499. if (drv->monitor_ifidx < 0)
  1500. return -1;
  1501. if (hostapd_set_iface_flags(drv, buf, 1))
  1502. goto error;
  1503. memset(&ll, 0, sizeof(ll));
  1504. ll.sll_family = AF_PACKET;
  1505. ll.sll_ifindex = drv->monitor_ifidx;
  1506. drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  1507. if (drv->monitor_sock < 0) {
  1508. perror("socket[PF_PACKET,SOCK_RAW]");
  1509. goto error;
  1510. }
  1511. if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
  1512. sizeof(ll)) < 0) {
  1513. perror("monitor socket bind");
  1514. goto error;
  1515. }
  1516. optlen = sizeof(optval);
  1517. optval = 20;
  1518. if (setsockopt
  1519. (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
  1520. perror("Failed to set socket priority");
  1521. goto error;
  1522. }
  1523. if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
  1524. drv, NULL)) {
  1525. printf("Could not register monitor read socket\n");
  1526. goto error;
  1527. }
  1528. return 0;
  1529. error:
  1530. nl80211_remove_iface(drv, drv->monitor_ifidx);
  1531. return -1;
  1532. }
  1533. static int nl80211_set_master_mode(struct i802_driver_data *drv,
  1534. const char *ifname)
  1535. {
  1536. struct nl_msg *msg;
  1537. msg = nlmsg_alloc();
  1538. if (!msg)
  1539. return -1;
  1540. genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
  1541. 0, NL80211_CMD_SET_INTERFACE, 0);
  1542. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
  1543. if_nametoindex(ifname));
  1544. NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
  1545. if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
  1546. nl_wait_for_ack(drv->nl_handle) < 0) {
  1547. nla_put_failure:
  1548. wpa_printf(MSG_ERROR, "Failed to set interface %s to master "
  1549. "mode.", ifname);
  1550. nlmsg_free(msg);
  1551. return -1;
  1552. }
  1553. nlmsg_free(msg);
  1554. return 0;
  1555. }
  1556. static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
  1557. {
  1558. struct ifreq ifr;
  1559. struct sockaddr_ll addr;
  1560. drv->ioctl_sock = -1;
  1561. drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
  1562. if (drv->ioctl_sock < 0) {
  1563. perror("socket[PF_INET,SOCK_DGRAM]");
  1564. return -1;
  1565. }
  1566. /* start listening for EAPOL on the default AP interface */
  1567. add_ifidx(drv, if_nametoindex(drv->iface));
  1568. if (hostapd_set_iface_flags(drv, drv->iface, 0))
  1569. return -1;
  1570. if (bssid) {
  1571. os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
  1572. memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
  1573. ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
  1574. if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
  1575. perror("ioctl(SIOCSIFHWADDR)");
  1576. return -1;
  1577. }
  1578. }
  1579. /*
  1580. * initialise generic netlink and nl80211
  1581. */
  1582. drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
  1583. if (!drv->nl_cb) {
  1584. printf("Failed to allocate netlink callbacks.\n");
  1585. return -1;
  1586. }
  1587. drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
  1588. if (!drv->nl_handle) {
  1589. printf("Failed to allocate netlink handle.\n");
  1590. return -1;
  1591. }
  1592. if (genl_connect(drv->nl_handle)) {
  1593. printf("Failed to connect to generic netlink.\n");
  1594. return -1;
  1595. }
  1596. drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
  1597. if (!drv->nl_cache) {
  1598. printf("Failed to allocate generic netlink cache.\n");
  1599. return -1;
  1600. }
  1601. drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
  1602. if (!drv->nl80211) {
  1603. printf("nl80211 not found.\n");
  1604. return -1;
  1605. }
  1606. /* Initialise a monitor interface */
  1607. if (nl80211_create_monitor_interface(drv))
  1608. return -1;
  1609. if (nl80211_set_master_mode(drv, drv->iface))
  1610. return -1;
  1611. if (hostapd_set_iface_flags(drv, drv->iface, 1))
  1612. return -1;
  1613. memset(&addr, 0, sizeof(addr));
  1614. addr.sll_family = AF_PACKET;
  1615. addr.sll_ifindex = ifr.ifr_ifindex;
  1616. wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
  1617. addr.sll_ifindex);
  1618. drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
  1619. if (drv->eapol_sock < 0) {
  1620. perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
  1621. return -1;
  1622. }
  1623. if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
  1624. {
  1625. printf("Could not register read socket for eapol\n");
  1626. return -1;
  1627. }
  1628. memset(&ifr, 0, sizeof(ifr));
  1629. os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
  1630. if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr) != 0) {
  1631. perror("ioctl(SIOCGIFHWADDR)");
  1632. return -1;
  1633. }
  1634. if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
  1635. printf("Invalid HW-addr family 0x%04x\n",
  1636. ifr.ifr_hwaddr.sa_family);
  1637. return -1;
  1638. }
  1639. memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
  1640. return 0;
  1641. }
  1642. static int i802_get_inact_sec(void *priv, const u8 *addr)
  1643. {
  1644. struct hostap_sta_driver_data data;
  1645. int ret;
  1646. data.inactive_msec = (unsigned long) -1;
  1647. ret = i802_read_sta_data(priv, &data, addr);
  1648. if (ret || data.inactive_msec == (unsigned long) -1)
  1649. return -1;
  1650. return data.inactive_msec / 1000;
  1651. }
  1652. static int i802_sta_clear_stats(void *priv, const u8 *addr)
  1653. {
  1654. #if 0
  1655. /* TODO */
  1656. #endif
  1657. return 0;
  1658. }
  1659. static void
  1660. hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
  1661. char *custom)
  1662. {
  1663. wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
  1664. if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
  1665. char *pos;
  1666. u8 addr[ETH_ALEN];
  1667. pos = strstr(custom, "addr=");
  1668. if (pos == NULL) {
  1669. wpa_printf(MSG_DEBUG,
  1670. "MLME-MICHAELMICFAILURE.indication "
  1671. "without sender address ignored");
  1672. return;
  1673. }
  1674. pos += 5;
  1675. if (hwaddr_aton(pos, addr) == 0) {
  1676. ieee80211_michael_mic_failure(drv->hapd, addr, 1);
  1677. } else {
  1678. wpa_printf(MSG_DEBUG,
  1679. "MLME-MICHAELMICFAILURE.indication "
  1680. "with invalid MAC address");
  1681. }
  1682. }
  1683. }
  1684. static void hostapd_wireless_event_wireless(struct i802_driver_data *drv,
  1685. char *data, int len)
  1686. {
  1687. struct iw_event iwe_buf, *iwe = &iwe_buf;
  1688. char *pos, *end, *custom, *buf;
  1689. pos = data;
  1690. end = data + len;
  1691. while (pos + IW_EV_LCP_LEN <= end) {
  1692. /* Event data may be unaligned, so make a local, aligned copy
  1693. * before processing. */
  1694. memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
  1695. wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
  1696. iwe->cmd, iwe->len);
  1697. if (iwe->len <= IW_EV_LCP_LEN)
  1698. return;
  1699. custom = pos + IW_EV_POINT_LEN;
  1700. if (drv->we_version > 18 &&
  1701. (iwe->cmd == IWEVMICHAELMICFAILURE ||
  1702. iwe->cmd == IWEVCUSTOM)) {
  1703. /* WE-19 removed the pointer from struct iw_point */
  1704. char *dpos = (char *) &iwe_buf.u.data.length;
  1705. int dlen = dpos - (char *) &iwe_buf;
  1706. memcpy(dpos, pos + IW_EV_LCP_LEN,
  1707. sizeof(struct iw_event) - dlen);
  1708. } else {
  1709. memcpy(&iwe_buf, pos, sizeof(struct iw_event));
  1710. custom += IW_EV_POINT_OFF;
  1711. }
  1712. switch (iwe->cmd) {
  1713. case IWEVCUSTOM:
  1714. if (custom + iwe->u.data.length > end)
  1715. return;
  1716. buf = malloc(iwe->u.data.length + 1);
  1717. if (buf == NULL)
  1718. return;
  1719. memcpy(buf, custom, iwe->u.data.length);
  1720. buf[iwe->u.data.length] = '\0';
  1721. hostapd_wireless_event_wireless_custom(drv, buf);
  1722. free(buf);
  1723. break;
  1724. }
  1725. pos += iwe->len;
  1726. }
  1727. }
  1728. static void hostapd_wireless_event_rtm_newlink(struct i802_driver_data *drv,
  1729. struct nlmsghdr *h, int len)
  1730. {
  1731. struct ifinfomsg *ifi;
  1732. int attrlen, nlmsg_len, rta_len;
  1733. struct rtattr *attr;
  1734. if (len < (int) sizeof(*ifi))
  1735. return;
  1736. ifi = NLMSG_DATA(h);
  1737. /* TODO: use ifi->ifi_index to filter out wireless events from other
  1738. * interfaces */
  1739. nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
  1740. attrlen = h->nlmsg_len - nlmsg_len;
  1741. if (attrlen < 0)
  1742. return;
  1743. attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
  1744. rta_len = RTA_ALIGN(sizeof(struct rtattr));
  1745. while (RTA_OK(attr, attrlen)) {
  1746. if (attr->rta_type == IFLA_WIRELESS) {
  1747. hostapd_wireless_event_wireless(
  1748. drv, ((char *) attr) + rta_len,
  1749. attr->rta_len - rta_len);
  1750. }
  1751. attr = RTA_NEXT(attr, attrlen);
  1752. }
  1753. }
  1754. static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
  1755. void *sock_ctx)
  1756. {
  1757. char buf[256];
  1758. int left;
  1759. struct sockaddr_nl from;
  1760. socklen_t fromlen;
  1761. struct nlmsghdr *h;
  1762. struct i802_driver_data *drv = eloop_ctx;
  1763. fromlen = sizeof(from);
  1764. left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
  1765. (struct sockaddr *) &from, &fromlen);
  1766. if (left < 0) {
  1767. if (errno != EINTR && errno != EAGAIN)
  1768. perror("recvfrom(netlink)");
  1769. return;
  1770. }
  1771. h = (struct nlmsghdr *) buf;
  1772. while (left >= (int) sizeof(*h)) {
  1773. int len, plen;
  1774. len = h->nlmsg_len;
  1775. plen = len - sizeof(*h);
  1776. if (len > left || plen < 0) {
  1777. printf("Malformed netlink message: "
  1778. "len=%d left=%d plen=%d\n",
  1779. len, left, plen);
  1780. break;
  1781. }
  1782. switch (h->nlmsg_type) {
  1783. case RTM_NEWLINK:
  1784. hostapd_wireless_event_rtm_newlink(drv, h, plen);
  1785. break;
  1786. }
  1787. len = NLMSG_ALIGN(len);
  1788. left -= len;
  1789. h = (struct nlmsghdr *) ((char *) h + len);
  1790. }
  1791. if (left > 0) {
  1792. printf("%d extra bytes in the end of netlink message\n", left);
  1793. }
  1794. }
  1795. static int hostap_get_we_version(struct i802_driver_data *drv)
  1796. {
  1797. struct iw_range *range;
  1798. struct iwreq iwr;
  1799. int minlen;
  1800. size_t buflen;
  1801. drv->we_version = 0;
  1802. /*
  1803. * Use larger buffer than struct iw_range in order to allow the
  1804. * structure to grow in the future.
  1805. */
  1806. buflen = sizeof(struct iw_range) + 500;
  1807. range = os_zalloc(buflen);
  1808. if (range == NULL)
  1809. return -1;
  1810. memset(&iwr, 0, sizeof(iwr));
  1811. os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  1812. iwr.u.data.pointer = (caddr_t) range;
  1813. iwr.u.data.length = buflen;
  1814. minlen = ((char *) &range->enc_capa) - (char *) range +
  1815. sizeof(range->enc_capa);
  1816. if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
  1817. perror("ioctl[SIOCGIWRANGE]");
  1818. free(range);
  1819. return -1;
  1820. } else if (iwr.u.data.length >= minlen &&
  1821. range->we_version_compiled >= 18) {
  1822. wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
  1823. "WE(source)=%d enc_capa=0x%x",
  1824. range->we_version_compiled,
  1825. range->we_version_source,
  1826. range->enc_capa);
  1827. drv->we_version = range->we_version_compiled;
  1828. }
  1829. free(range);
  1830. return 0;
  1831. }
  1832. static int i802_wireless_event_init(void *priv)
  1833. {
  1834. struct i802_driver_data *drv = priv;
  1835. int s;
  1836. struct sockaddr_nl local;
  1837. hostap_get_we_version(drv);
  1838. drv->wext_sock = -1;
  1839. s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  1840. if (s < 0) {
  1841. perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
  1842. return -1;
  1843. }
  1844. memset(&local, 0, sizeof(local));
  1845. local.nl_family = AF_NETLINK;
  1846. local.nl_groups = RTMGRP_LINK;
  1847. if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
  1848. perror("bind(netlink)");
  1849. close(s);
  1850. return -1;
  1851. }
  1852. eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
  1853. NULL);
  1854. drv->wext_sock = s;
  1855. return 0;
  1856. }
  1857. static void i802_wireless_event_deinit(void *priv)
  1858. {
  1859. struct i802_driver_data *drv = priv;
  1860. if (drv->wext_sock < 0)
  1861. return;
  1862. eloop_unregister_read_sock(drv->wext_sock);
  1863. close(drv->wext_sock);
  1864. }
  1865. static int i802_sta_deauth(void *priv, const u8 *addr, int reason)
  1866. {
  1867. struct i802_driver_data *drv = priv;
  1868. struct ieee80211_mgmt mgmt;
  1869. memset(&mgmt, 0, sizeof(mgmt));
  1870. mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  1871. WLAN_FC_STYPE_DEAUTH);
  1872. memcpy(mgmt.da, addr, ETH_ALEN);
  1873. memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
  1874. memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
  1875. mgmt.u.deauth.reason_code = host_to_le16(reason);
  1876. return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
  1877. sizeof(mgmt.u.deauth), 0);
  1878. }
  1879. static int i802_sta_disassoc(void *priv, const u8 *addr, int reason)
  1880. {
  1881. struct i802_driver_data *drv = priv;
  1882. struct ieee80211_mgmt mgmt;
  1883. memset(&mgmt, 0, sizeof(mgmt));
  1884. mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  1885. WLAN_FC_STYPE_DISASSOC);
  1886. memcpy(mgmt.da, addr, ETH_ALEN);
  1887. memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
  1888. memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
  1889. mgmt.u.disassoc.reason_code = host_to_le16(reason);
  1890. return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
  1891. sizeof(mgmt.u.disassoc), 0);
  1892. }
  1893. static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
  1894. {
  1895. struct i802_driver_data *drv;
  1896. drv = os_zalloc(sizeof(struct i802_driver_data));
  1897. if (drv == NULL) {
  1898. printf("Could not allocate memory for i802 driver data\n");
  1899. return NULL;
  1900. }
  1901. drv->hapd = hapd;
  1902. memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
  1903. drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
  1904. drv->if_indices = drv->default_if_indices;
  1905. drv->bridge = if_nametoindex(hapd->conf->bridge);
  1906. if (i802_init_sockets(drv, bssid))
  1907. goto failed;
  1908. return drv;
  1909. failed:
  1910. free(drv);
  1911. return NULL;
  1912. }
  1913. static void *i802_init(struct hostapd_data *hapd)
  1914. {
  1915. return i802_init_bssid(hapd, NULL);
  1916. }
  1917. static void i802_deinit(void *priv)
  1918. {
  1919. struct i802_driver_data *drv = priv;
  1920. i802_del_beacon(drv);
  1921. /* remove monitor interface */
  1922. nl80211_remove_iface(drv, drv->monitor_ifidx);
  1923. (void) hostapd_set_iface_flags(drv, drv->iface, 0);
  1924. if (drv->monitor_sock >= 0) {
  1925. eloop_unregister_read_sock(drv->monitor_sock);
  1926. close(drv->monitor_sock);
  1927. }
  1928. if (drv->ioctl_sock >= 0)
  1929. close(drv->ioctl_sock);
  1930. if (drv->eapol_sock >= 0) {
  1931. eloop_unregister_read_sock(drv->eapol_sock);
  1932. close(drv->eapol_sock);
  1933. }
  1934. genl_family_put(drv->nl80211);
  1935. nl_cache_free(drv->nl_cache);
  1936. nl_handle_destroy(drv->nl_handle);
  1937. nl_cb_put(drv->nl_cb);
  1938. if (drv->if_indices != drv->default_if_indices)
  1939. free(drv->if_indices);
  1940. free(drv);
  1941. }
  1942. const struct wpa_driver_ops wpa_driver_nl80211_ops = {
  1943. .name = "nl80211",
  1944. .init = i802_init,
  1945. .init_bssid = i802_init_bssid,
  1946. .deinit = i802_deinit,
  1947. .wireless_event_init = i802_wireless_event_init,
  1948. .wireless_event_deinit = i802_wireless_event_deinit,
  1949. .set_ieee8021x = i802_set_ieee8021x,
  1950. .set_privacy = i802_set_privacy,
  1951. .set_encryption = i802_set_encryption,
  1952. .get_seqnum = i802_get_seqnum,
  1953. .flush = i802_flush,
  1954. .read_sta_data = i802_read_sta_data,
  1955. .send_eapol = i802_send_eapol,
  1956. .sta_set_flags = i802_sta_set_flags,
  1957. .sta_deauth = i802_sta_deauth,
  1958. .sta_disassoc = i802_sta_disassoc,
  1959. .sta_remove = i802_sta_remove,
  1960. .set_ssid = i802_set_ssid,
  1961. .send_mgmt_frame = i802_send_mgmt_frame,
  1962. .sta_add2 = i802_sta_add2,
  1963. .get_inact_sec = i802_get_inact_sec,
  1964. .sta_clear_stats = i802_sta_clear_stats,
  1965. .set_freq = i802_set_freq,
  1966. .set_rts = i802_set_rts,
  1967. .get_rts = i802_get_rts,
  1968. .set_frag = i802_set_frag,
  1969. .get_frag = i802_get_frag,
  1970. .set_retry = i802_set_retry,
  1971. .get_retry = i802_get_retry,
  1972. .set_rate_sets = i802_set_rate_sets,
  1973. .set_channel_flag = i802_set_channel_flag,
  1974. .set_regulatory_domain = i802_set_regulatory_domain,
  1975. .set_beacon = i802_set_beacon,
  1976. .set_internal_bridge = i802_set_internal_bridge,
  1977. .set_beacon_int = i802_set_beacon_int,
  1978. .set_dtim_period = i802_set_dtim_period,
  1979. .set_cts_protect = i802_set_cts_protect,
  1980. .set_preamble = i802_set_preamble,
  1981. .set_short_slot_time = i802_set_short_slot_time,
  1982. .set_tx_queue_params = i802_set_tx_queue_params,
  1983. .bss_add = i802_bss_add,
  1984. .bss_remove = i802_bss_remove,
  1985. .if_add = i802_if_add,
  1986. .if_update = i802_if_update,
  1987. .if_remove = i802_if_remove,
  1988. .get_hw_feature_data = i802_get_hw_feature_data,
  1989. .set_sta_vlan = i802_set_sta_vlan,
  1990. };