driver_test.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. /*
  2. * hostapd / Driver interface for development testing
  3. * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include <sys/un.h>
  16. #include <dirent.h>
  17. #include "hostapd.h"
  18. #include "driver.h"
  19. #include "sha1.h"
  20. #include "eloop.h"
  21. #include "ieee802_1x.h"
  22. #include "sta_info.h"
  23. #include "wpa.h"
  24. #include "accounting.h"
  25. #include "radius/radius.h"
  26. #include "l2_packet/l2_packet.h"
  27. #include "ieee802_11.h"
  28. #include "hw_features.h"
  29. #include "wps_hostapd.h"
  30. struct test_client_socket {
  31. struct test_client_socket *next;
  32. u8 addr[ETH_ALEN];
  33. struct sockaddr_un un;
  34. socklen_t unlen;
  35. struct test_driver_bss *bss;
  36. };
  37. struct test_driver_bss {
  38. struct test_driver_bss *next;
  39. char ifname[IFNAMSIZ + 1];
  40. u8 bssid[ETH_ALEN];
  41. u8 *ie;
  42. size_t ielen;
  43. u8 *wps_beacon_ie;
  44. size_t wps_beacon_ie_len;
  45. u8 *wps_probe_resp_ie;
  46. size_t wps_probe_resp_ie_len;
  47. u8 ssid[32];
  48. size_t ssid_len;
  49. int privacy;
  50. };
  51. struct test_driver_data {
  52. struct hostapd_data *hapd;
  53. struct test_client_socket *cli;
  54. int test_socket;
  55. struct test_driver_bss *bss;
  56. char *socket_dir;
  57. char *own_socket_path;
  58. int udp_port;
  59. };
  60. static void test_driver_free_bss(struct test_driver_bss *bss)
  61. {
  62. free(bss->ie);
  63. free(bss->wps_beacon_ie);
  64. free(bss->wps_probe_resp_ie);
  65. free(bss);
  66. }
  67. static void test_driver_free_priv(struct test_driver_data *drv)
  68. {
  69. struct test_driver_bss *bss, *prev;
  70. if (drv == NULL)
  71. return;
  72. bss = drv->bss;
  73. while (bss) {
  74. prev = bss;
  75. bss = bss->next;
  76. test_driver_free_bss(prev);
  77. }
  78. free(drv->own_socket_path);
  79. free(drv->socket_dir);
  80. free(drv);
  81. }
  82. static struct test_client_socket *
  83. test_driver_get_cli(struct test_driver_data *drv, struct sockaddr_un *from,
  84. socklen_t fromlen)
  85. {
  86. struct test_client_socket *cli = drv->cli;
  87. while (cli) {
  88. if (cli->unlen == fromlen &&
  89. strncmp(cli->un.sun_path, from->sun_path,
  90. fromlen - sizeof(cli->un.sun_family)) == 0)
  91. return cli;
  92. cli = cli->next;
  93. }
  94. return NULL;
  95. }
  96. static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
  97. size_t data_len, int encrypt,
  98. const u8 *own_addr)
  99. {
  100. struct test_driver_data *drv = priv;
  101. struct test_client_socket *cli;
  102. struct msghdr msg;
  103. struct iovec io[3];
  104. struct l2_ethhdr eth;
  105. if (drv->test_socket < 0)
  106. return -1;
  107. cli = drv->cli;
  108. while (cli) {
  109. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  110. break;
  111. cli = cli->next;
  112. }
  113. if (!cli) {
  114. wpa_printf(MSG_DEBUG, "%s: no destination client entry",
  115. __func__);
  116. return -1;
  117. }
  118. memcpy(eth.h_dest, addr, ETH_ALEN);
  119. memcpy(eth.h_source, own_addr, ETH_ALEN);
  120. eth.h_proto = htons(ETH_P_EAPOL);
  121. io[0].iov_base = "EAPOL ";
  122. io[0].iov_len = 6;
  123. io[1].iov_base = &eth;
  124. io[1].iov_len = sizeof(eth);
  125. io[2].iov_base = (u8 *) data;
  126. io[2].iov_len = data_len;
  127. memset(&msg, 0, sizeof(msg));
  128. msg.msg_iov = io;
  129. msg.msg_iovlen = 3;
  130. msg.msg_name = &cli->un;
  131. msg.msg_namelen = cli->unlen;
  132. return sendmsg(drv->test_socket, &msg, 0);
  133. }
  134. static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
  135. u16 proto, const u8 *data, size_t data_len)
  136. {
  137. struct test_driver_data *drv = priv;
  138. struct msghdr msg;
  139. struct iovec io[3];
  140. struct l2_ethhdr eth;
  141. char desttxt[30];
  142. struct sockaddr_un addr;
  143. struct dirent *dent;
  144. DIR *dir;
  145. int ret = 0, broadcast = 0, count = 0;
  146. if (drv->test_socket < 0 || drv->socket_dir == NULL) {
  147. wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d "
  148. "socket_dir=%p)",
  149. __func__, drv->test_socket, drv->socket_dir);
  150. return -1;
  151. }
  152. broadcast = memcmp(dst, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
  153. snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dst));
  154. memcpy(eth.h_dest, dst, ETH_ALEN);
  155. memcpy(eth.h_source, src, ETH_ALEN);
  156. eth.h_proto = htons(proto);
  157. io[0].iov_base = "ETHER ";
  158. io[0].iov_len = 6;
  159. io[1].iov_base = &eth;
  160. io[1].iov_len = sizeof(eth);
  161. io[2].iov_base = (u8 *) data;
  162. io[2].iov_len = data_len;
  163. memset(&msg, 0, sizeof(msg));
  164. msg.msg_iov = io;
  165. msg.msg_iovlen = 3;
  166. dir = opendir(drv->socket_dir);
  167. if (dir == NULL) {
  168. perror("test_driver: opendir");
  169. return -1;
  170. }
  171. while ((dent = readdir(dir))) {
  172. #ifdef _DIRENT_HAVE_D_TYPE
  173. /* Skip the file if it is not a socket. Also accept
  174. * DT_UNKNOWN (0) in case the C library or underlying file
  175. * system does not support d_type. */
  176. if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
  177. continue;
  178. #endif /* _DIRENT_HAVE_D_TYPE */
  179. if (strcmp(dent->d_name, ".") == 0 ||
  180. strcmp(dent->d_name, "..") == 0)
  181. continue;
  182. memset(&addr, 0, sizeof(addr));
  183. addr.sun_family = AF_UNIX;
  184. snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
  185. drv->socket_dir, dent->d_name);
  186. if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
  187. continue;
  188. if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
  189. continue;
  190. wpa_printf(MSG_DEBUG, "%s: Send ether frame to %s",
  191. __func__, dent->d_name);
  192. msg.msg_name = &addr;
  193. msg.msg_namelen = sizeof(addr);
  194. ret = sendmsg(drv->test_socket, &msg, 0);
  195. if (ret < 0)
  196. perror("driver_test: sendmsg");
  197. count++;
  198. }
  199. closedir(dir);
  200. if (!broadcast && count == 0) {
  201. wpa_printf(MSG_DEBUG, "%s: Destination " MACSTR " not found",
  202. __func__, MAC2STR(dst));
  203. return -1;
  204. }
  205. return ret;
  206. }
  207. static int test_driver_send_mgmt_frame(void *priv, const void *buf,
  208. size_t len, int flags)
  209. {
  210. struct test_driver_data *drv = priv;
  211. struct msghdr msg;
  212. struct iovec io[2];
  213. const u8 *dest;
  214. int ret = 0, broadcast = 0;
  215. char desttxt[30];
  216. struct sockaddr_un addr;
  217. struct dirent *dent;
  218. DIR *dir;
  219. struct ieee80211_hdr *hdr;
  220. u16 fc;
  221. if (drv->test_socket < 0 || len < 10 || drv->socket_dir == NULL) {
  222. wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d len=%lu"
  223. " socket_dir=%p)",
  224. __func__, drv->test_socket, (unsigned long) len,
  225. drv->socket_dir);
  226. return -1;
  227. }
  228. dest = buf;
  229. dest += 4;
  230. broadcast = memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
  231. snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dest));
  232. io[0].iov_base = "MLME ";
  233. io[0].iov_len = 5;
  234. io[1].iov_base = (void *) buf;
  235. io[1].iov_len = len;
  236. memset(&msg, 0, sizeof(msg));
  237. msg.msg_iov = io;
  238. msg.msg_iovlen = 2;
  239. dir = opendir(drv->socket_dir);
  240. if (dir == NULL) {
  241. perror("test_driver: opendir");
  242. return -1;
  243. }
  244. while ((dent = readdir(dir))) {
  245. #ifdef _DIRENT_HAVE_D_TYPE
  246. /* Skip the file if it is not a socket. Also accept
  247. * DT_UNKNOWN (0) in case the C library or underlying file
  248. * system does not support d_type. */
  249. if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
  250. continue;
  251. #endif /* _DIRENT_HAVE_D_TYPE */
  252. if (strcmp(dent->d_name, ".") == 0 ||
  253. strcmp(dent->d_name, "..") == 0)
  254. continue;
  255. memset(&addr, 0, sizeof(addr));
  256. addr.sun_family = AF_UNIX;
  257. snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
  258. drv->socket_dir, dent->d_name);
  259. if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
  260. continue;
  261. if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
  262. continue;
  263. wpa_printf(MSG_DEBUG, "%s: Send management frame to %s",
  264. __func__, dent->d_name);
  265. msg.msg_name = &addr;
  266. msg.msg_namelen = sizeof(addr);
  267. ret = sendmsg(drv->test_socket, &msg, 0);
  268. if (ret < 0)
  269. perror("driver_test: sendmsg");
  270. }
  271. closedir(dir);
  272. hdr = (struct ieee80211_hdr *) buf;
  273. fc = le_to_host16(hdr->frame_control);
  274. ieee802_11_mgmt_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
  275. ret >= 0);
  276. return ret;
  277. }
  278. static void test_driver_scan(struct test_driver_data *drv,
  279. struct sockaddr_un *from, socklen_t fromlen,
  280. char *data)
  281. {
  282. char buf[512], *pos, *end;
  283. int ret;
  284. struct test_driver_bss *bss;
  285. u8 sa[ETH_ALEN];
  286. u8 ie[512];
  287. size_t ielen;
  288. /* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
  289. wpa_printf(MSG_DEBUG, "test_driver: SCAN");
  290. if (*data) {
  291. if (*data != ' ' ||
  292. hwaddr_aton(data + 1, sa)) {
  293. wpa_printf(MSG_DEBUG, "test_driver: Unexpected SCAN "
  294. "command format");
  295. return;
  296. }
  297. data += 18;
  298. while (*data == ' ')
  299. data++;
  300. ielen = os_strlen(data) / 2;
  301. if (ielen > sizeof(ie))
  302. ielen = sizeof(ie);
  303. if (hexstr2bin(data, ie, ielen) < 0)
  304. ielen = 0;
  305. wpa_printf(MSG_DEBUG, "test_driver: Scan from " MACSTR,
  306. MAC2STR(sa));
  307. wpa_hexdump(MSG_MSGDUMP, "test_driver: scan IEs", ie, ielen);
  308. hostapd_wps_probe_req_rx(drv->hapd, sa, ie, ielen);
  309. }
  310. for (bss = drv->bss; bss; bss = bss->next) {
  311. pos = buf;
  312. end = buf + sizeof(buf);
  313. /* reply: SCANRESP BSSID SSID IEs */
  314. ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
  315. MAC2STR(bss->bssid));
  316. if (ret < 0 || ret >= end - pos)
  317. return;
  318. pos += ret;
  319. pos += wpa_snprintf_hex(pos, end - pos,
  320. bss->ssid, bss->ssid_len);
  321. ret = snprintf(pos, end - pos, " ");
  322. if (ret < 0 || ret >= end - pos)
  323. return;
  324. pos += ret;
  325. pos += wpa_snprintf_hex(pos, end - pos, bss->ie, bss->ielen);
  326. pos += wpa_snprintf_hex(pos, end - pos, bss->wps_probe_resp_ie,
  327. bss->wps_probe_resp_ie_len);
  328. if (bss->privacy) {
  329. ret = snprintf(pos, end - pos, " PRIVACY");
  330. if (ret < 0 || ret >= end - pos)
  331. return;
  332. pos += ret;
  333. }
  334. sendto(drv->test_socket, buf, pos - buf, 0,
  335. (struct sockaddr *) from, fromlen);
  336. }
  337. }
  338. static struct hostapd_data * test_driver_get_hapd(struct test_driver_data *drv,
  339. struct test_driver_bss *bss)
  340. {
  341. struct hostapd_iface *iface = drv->hapd->iface;
  342. struct hostapd_data *hapd = NULL;
  343. size_t i;
  344. if (bss == NULL) {
  345. wpa_printf(MSG_DEBUG, "%s: bss == NULL", __func__);
  346. return NULL;
  347. }
  348. for (i = 0; i < iface->num_bss; i++) {
  349. hapd = iface->bss[i];
  350. if (memcmp(hapd->own_addr, bss->bssid, ETH_ALEN) == 0)
  351. break;
  352. }
  353. if (i == iface->num_bss) {
  354. wpa_printf(MSG_DEBUG, "%s: no matching interface entry found "
  355. "for BSSID " MACSTR, __func__, MAC2STR(bss->bssid));
  356. return NULL;
  357. }
  358. return hapd;
  359. }
  360. static int test_driver_new_sta(struct test_driver_data *drv,
  361. struct test_driver_bss *bss, const u8 *addr,
  362. const u8 *ie, size_t ielen)
  363. {
  364. struct hostapd_data *hapd;
  365. struct sta_info *sta;
  366. int new_assoc, res;
  367. hapd = test_driver_get_hapd(drv, bss);
  368. if (hapd == NULL)
  369. return -1;
  370. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  371. HOSTAPD_LEVEL_INFO, "associated");
  372. sta = ap_get_sta(hapd, addr);
  373. if (sta) {
  374. accounting_sta_stop(hapd, sta);
  375. } else {
  376. sta = ap_sta_add(hapd, addr);
  377. if (sta == NULL)
  378. return -1;
  379. }
  380. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
  381. if (hapd->conf->wpa) {
  382. if (ie == NULL || ielen == 0) {
  383. if (hapd->conf->wps_state) {
  384. sta->flags |= WLAN_STA_WPS;
  385. goto skip_wpa_check;
  386. }
  387. printf("test_driver: no IE from STA\n");
  388. return -1;
  389. }
  390. if (sta->wpa_sm == NULL)
  391. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  392. sta->addr);
  393. if (sta->wpa_sm == NULL) {
  394. printf("test_driver: Failed to initialize WPA state "
  395. "machine\n");
  396. return -1;
  397. }
  398. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  399. ie, ielen, NULL, 0);
  400. if (res != WPA_IE_OK) {
  401. printf("WPA/RSN information element rejected? "
  402. "(res %u)\n", res);
  403. return -1;
  404. }
  405. }
  406. skip_wpa_check:
  407. new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
  408. sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
  409. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  410. hostapd_new_assoc_sta(hapd, sta, !new_assoc);
  411. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  412. return 0;
  413. }
  414. static void test_driver_assoc(struct test_driver_data *drv,
  415. struct sockaddr_un *from, socklen_t fromlen,
  416. char *data)
  417. {
  418. struct test_client_socket *cli;
  419. u8 ie[256], ssid[32];
  420. size_t ielen, ssid_len = 0;
  421. char *pos, *pos2, cmd[50];
  422. struct test_driver_bss *bss;
  423. /* data: STA-addr SSID(hex) IEs(hex) */
  424. cli = os_zalloc(sizeof(*cli));
  425. if (cli == NULL)
  426. return;
  427. if (hwaddr_aton(data, cli->addr)) {
  428. printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
  429. data);
  430. free(cli);
  431. return;
  432. }
  433. pos = data + 17;
  434. while (*pos == ' ')
  435. pos++;
  436. pos2 = strchr(pos, ' ');
  437. ielen = 0;
  438. if (pos2) {
  439. ssid_len = (pos2 - pos) / 2;
  440. if (hexstr2bin(pos, ssid, ssid_len) < 0) {
  441. wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
  442. free(cli);
  443. return;
  444. }
  445. wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
  446. ssid, ssid_len);
  447. pos = pos2 + 1;
  448. ielen = strlen(pos) / 2;
  449. if (ielen > sizeof(ie))
  450. ielen = sizeof(ie);
  451. if (hexstr2bin(pos, ie, ielen) < 0)
  452. ielen = 0;
  453. }
  454. for (bss = drv->bss; bss; bss = bss->next) {
  455. if (bss->ssid_len == ssid_len &&
  456. memcmp(bss->ssid, ssid, ssid_len) == 0)
  457. break;
  458. }
  459. if (bss == NULL) {
  460. wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
  461. "configured BSSes", __func__);
  462. free(cli);
  463. return;
  464. }
  465. cli->bss = bss;
  466. memcpy(&cli->un, from, sizeof(cli->un));
  467. cli->unlen = fromlen;
  468. cli->next = drv->cli;
  469. drv->cli = cli;
  470. wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
  471. (const u8 *) cli->un.sun_path,
  472. cli->unlen - sizeof(cli->un.sun_family));
  473. snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
  474. MAC2STR(bss->bssid));
  475. sendto(drv->test_socket, cmd, strlen(cmd), 0,
  476. (struct sockaddr *) from, fromlen);
  477. if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
  478. wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
  479. }
  480. }
  481. static void test_driver_disassoc(struct test_driver_data *drv,
  482. struct sockaddr_un *from, socklen_t fromlen)
  483. {
  484. struct test_client_socket *cli;
  485. struct sta_info *sta;
  486. cli = test_driver_get_cli(drv, from, fromlen);
  487. if (!cli)
  488. return;
  489. hostapd_logger(drv->hapd, cli->addr, HOSTAPD_MODULE_IEEE80211,
  490. HOSTAPD_LEVEL_INFO, "disassociated");
  491. sta = ap_get_sta(drv->hapd, cli->addr);
  492. if (sta != NULL) {
  493. sta->flags &= ~WLAN_STA_ASSOC;
  494. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  495. sta->acct_terminate_cause =
  496. RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  497. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  498. ap_free_sta(drv->hapd, sta);
  499. }
  500. }
  501. static void test_driver_eapol(struct test_driver_data *drv,
  502. struct sockaddr_un *from, socklen_t fromlen,
  503. u8 *data, size_t datalen)
  504. {
  505. struct test_client_socket *cli;
  506. if (datalen > 14) {
  507. u8 *proto = data + 2 * ETH_ALEN;
  508. /* Skip Ethernet header */
  509. wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
  510. MACSTR " proto=%04x",
  511. MAC2STR(data), MAC2STR(data + ETH_ALEN),
  512. WPA_GET_BE16(proto));
  513. data += 14;
  514. datalen -= 14;
  515. }
  516. cli = test_driver_get_cli(drv, from, fromlen);
  517. if (cli) {
  518. struct hostapd_data *hapd;
  519. hapd = test_driver_get_hapd(drv, cli->bss);
  520. if (hapd == NULL)
  521. return;
  522. ieee802_1x_receive(hapd, cli->addr, data, datalen);
  523. } else {
  524. wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
  525. "client");
  526. }
  527. }
  528. static void test_driver_ether(struct test_driver_data *drv,
  529. struct sockaddr_un *from, socklen_t fromlen,
  530. u8 *data, size_t datalen)
  531. {
  532. struct l2_ethhdr *eth;
  533. if (datalen < sizeof(*eth))
  534. return;
  535. eth = (struct l2_ethhdr *) data;
  536. wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
  537. MACSTR " proto=%04x",
  538. MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
  539. be_to_host16(eth->h_proto));
  540. #ifdef CONFIG_IEEE80211R
  541. if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
  542. wpa_ft_rrb_rx(drv->hapd->wpa_auth, eth->h_source,
  543. data + sizeof(*eth), datalen - sizeof(*eth));
  544. }
  545. #endif /* CONFIG_IEEE80211R */
  546. }
  547. static void test_driver_mlme(struct test_driver_data *drv,
  548. struct sockaddr_un *from, socklen_t fromlen,
  549. u8 *data, size_t datalen)
  550. {
  551. struct ieee80211_hdr *hdr;
  552. u16 fc;
  553. hdr = (struct ieee80211_hdr *) data;
  554. if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
  555. struct test_client_socket *cli;
  556. cli = os_zalloc(sizeof(*cli));
  557. if (cli == NULL)
  558. return;
  559. wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
  560. MAC2STR(hdr->addr2));
  561. memcpy(cli->addr, hdr->addr2, ETH_ALEN);
  562. memcpy(&cli->un, from, sizeof(cli->un));
  563. cli->unlen = fromlen;
  564. cli->next = drv->cli;
  565. drv->cli = cli;
  566. }
  567. wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
  568. data, datalen);
  569. fc = le_to_host16(hdr->frame_control);
  570. if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
  571. wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
  572. __func__);
  573. return;
  574. }
  575. ieee802_11_mgmt(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
  576. }
  577. static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
  578. {
  579. struct test_driver_data *drv = eloop_ctx;
  580. char buf[2000];
  581. int res;
  582. struct sockaddr_un from;
  583. socklen_t fromlen = sizeof(from);
  584. res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
  585. (struct sockaddr *) &from, &fromlen);
  586. if (res < 0) {
  587. perror("recvfrom(test_socket)");
  588. return;
  589. }
  590. buf[res] = '\0';
  591. wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
  592. if (strncmp(buf, "SCAN", 4) == 0) {
  593. test_driver_scan(drv, &from, fromlen, buf + 4);
  594. } else if (strncmp(buf, "ASSOC ", 6) == 0) {
  595. test_driver_assoc(drv, &from, fromlen, buf + 6);
  596. } else if (strcmp(buf, "DISASSOC") == 0) {
  597. test_driver_disassoc(drv, &from, fromlen);
  598. } else if (strncmp(buf, "EAPOL ", 6) == 0) {
  599. test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
  600. res - 6);
  601. } else if (strncmp(buf, "ETHER ", 6) == 0) {
  602. test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
  603. res - 6);
  604. } else if (strncmp(buf, "MLME ", 5) == 0) {
  605. test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
  606. } else {
  607. wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
  608. (u8 *) buf, res);
  609. }
  610. }
  611. static struct test_driver_bss *
  612. test_driver_get_bss(struct test_driver_data *drv, const char *ifname)
  613. {
  614. struct test_driver_bss *bss;
  615. for (bss = drv->bss; bss; bss = bss->next) {
  616. if (strcmp(bss->ifname, ifname) == 0)
  617. return bss;
  618. }
  619. return NULL;
  620. }
  621. static int test_driver_set_generic_elem(const char *ifname, void *priv,
  622. const u8 *elem, size_t elem_len)
  623. {
  624. struct test_driver_data *drv = priv;
  625. struct test_driver_bss *bss;
  626. bss = test_driver_get_bss(drv, ifname);
  627. if (bss == NULL)
  628. return -1;
  629. free(bss->ie);
  630. if (elem == NULL) {
  631. bss->ie = NULL;
  632. bss->ielen = 0;
  633. return 0;
  634. }
  635. bss->ie = malloc(elem_len);
  636. if (bss->ie == NULL) {
  637. bss->ielen = 0;
  638. return -1;
  639. }
  640. memcpy(bss->ie, elem, elem_len);
  641. bss->ielen = elem_len;
  642. return 0;
  643. }
  644. static int test_driver_set_wps_beacon_ie(const char *ifname, void *priv,
  645. const u8 *ie, size_t len)
  646. {
  647. struct test_driver_data *drv = priv;
  648. struct test_driver_bss *bss;
  649. wpa_hexdump(MSG_DEBUG, "test_driver: Beacon WPS IE", ie, len);
  650. bss = test_driver_get_bss(drv, ifname);
  651. if (bss == NULL)
  652. return -1;
  653. free(bss->wps_beacon_ie);
  654. if (ie == NULL) {
  655. bss->wps_beacon_ie = NULL;
  656. bss->wps_beacon_ie_len = 0;
  657. return 0;
  658. }
  659. bss->wps_beacon_ie = malloc(len);
  660. if (bss->wps_beacon_ie == NULL) {
  661. bss->wps_beacon_ie_len = 0;
  662. return -1;
  663. }
  664. memcpy(bss->wps_beacon_ie, ie, len);
  665. bss->wps_beacon_ie_len = len;
  666. return 0;
  667. }
  668. static int test_driver_set_wps_probe_resp_ie(const char *ifname, void *priv,
  669. const u8 *ie, size_t len)
  670. {
  671. struct test_driver_data *drv = priv;
  672. struct test_driver_bss *bss;
  673. wpa_hexdump(MSG_DEBUG, "test_driver: ProbeResp WPS IE", ie, len);
  674. bss = test_driver_get_bss(drv, ifname);
  675. if (bss == NULL)
  676. return -1;
  677. free(bss->wps_probe_resp_ie);
  678. if (ie == NULL) {
  679. bss->wps_probe_resp_ie = NULL;
  680. bss->wps_probe_resp_ie_len = 0;
  681. return 0;
  682. }
  683. bss->wps_probe_resp_ie = malloc(len);
  684. if (bss->wps_probe_resp_ie == NULL) {
  685. bss->wps_probe_resp_ie_len = 0;
  686. return -1;
  687. }
  688. memcpy(bss->wps_probe_resp_ie, ie, len);
  689. bss->wps_probe_resp_ie_len = len;
  690. return 0;
  691. }
  692. static int test_driver_sta_deauth(void *priv, const u8 *addr, int reason)
  693. {
  694. struct test_driver_data *drv = priv;
  695. struct test_client_socket *cli;
  696. if (drv->test_socket < 0)
  697. return -1;
  698. cli = drv->cli;
  699. while (cli) {
  700. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  701. break;
  702. cli = cli->next;
  703. }
  704. if (!cli)
  705. return -1;
  706. return sendto(drv->test_socket, "DEAUTH", 6, 0,
  707. (struct sockaddr *) &cli->un, cli->unlen);
  708. }
  709. static int test_driver_sta_disassoc(void *priv, const u8 *addr, int reason)
  710. {
  711. struct test_driver_data *drv = priv;
  712. struct test_client_socket *cli;
  713. if (drv->test_socket < 0)
  714. return -1;
  715. cli = drv->cli;
  716. while (cli) {
  717. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  718. break;
  719. cli = cli->next;
  720. }
  721. if (!cli)
  722. return -1;
  723. return sendto(drv->test_socket, "DISASSOC", 8, 0,
  724. (struct sockaddr *) &cli->un, cli->unlen);
  725. }
  726. static struct hostapd_hw_modes *
  727. test_driver_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
  728. {
  729. struct hostapd_hw_modes *modes;
  730. *num_modes = 3;
  731. *flags = 0;
  732. modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
  733. if (modes == NULL)
  734. return NULL;
  735. modes[0].mode = HOSTAPD_MODE_IEEE80211G;
  736. modes[0].num_channels = 1;
  737. modes[0].num_rates = 1;
  738. modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
  739. modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
  740. if (modes[0].channels == NULL || modes[0].rates == NULL) {
  741. hostapd_free_hw_features(modes, *num_modes);
  742. return NULL;
  743. }
  744. modes[0].channels[0].chan = 1;
  745. modes[0].channels[0].freq = 2412;
  746. modes[0].channels[0].flag = 0;
  747. modes[0].rates[0].rate = 10;
  748. modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
  749. HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
  750. modes[1].mode = HOSTAPD_MODE_IEEE80211B;
  751. modes[1].num_channels = 1;
  752. modes[1].num_rates = 1;
  753. modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
  754. modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
  755. if (modes[1].channels == NULL || modes[1].rates == NULL) {
  756. hostapd_free_hw_features(modes, *num_modes);
  757. return NULL;
  758. }
  759. modes[1].channels[0].chan = 1;
  760. modes[1].channels[0].freq = 2412;
  761. modes[1].channels[0].flag = 0;
  762. modes[1].rates[0].rate = 10;
  763. modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
  764. HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
  765. modes[2].mode = HOSTAPD_MODE_IEEE80211A;
  766. modes[2].num_channels = 1;
  767. modes[2].num_rates = 1;
  768. modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
  769. modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
  770. if (modes[2].channels == NULL || modes[2].rates == NULL) {
  771. hostapd_free_hw_features(modes, *num_modes);
  772. return NULL;
  773. }
  774. modes[2].channels[0].chan = 60;
  775. modes[2].channels[0].freq = 5300;
  776. modes[2].channels[0].flag = 0;
  777. modes[2].rates[0].rate = 60;
  778. modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
  779. HOSTAPD_RATE_MANDATORY;
  780. return modes;
  781. }
  782. static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
  783. {
  784. struct test_driver_data *drv = priv;
  785. struct test_driver_bss *bss;
  786. wpa_printf(MSG_DEBUG, "%s(ifname=%s bssid=" MACSTR ")",
  787. __func__, ifname, MAC2STR(bssid));
  788. bss = os_zalloc(sizeof(*bss));
  789. if (bss == NULL)
  790. return -1;
  791. os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
  792. memcpy(bss->bssid, bssid, ETH_ALEN);
  793. bss->next = drv->bss;
  794. drv->bss = bss;
  795. return 0;
  796. }
  797. static int test_driver_bss_remove(void *priv, const char *ifname)
  798. {
  799. struct test_driver_data *drv = priv;
  800. struct test_driver_bss *bss, *prev;
  801. struct test_client_socket *cli, *prev_c;
  802. wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
  803. for (prev = NULL, bss = drv->bss; bss; prev = bss, bss = bss->next) {
  804. if (strcmp(bss->ifname, ifname) != 0)
  805. continue;
  806. if (prev)
  807. prev->next = bss->next;
  808. else
  809. drv->bss = bss->next;
  810. for (prev_c = NULL, cli = drv->cli; cli;
  811. prev_c = cli, cli = cli->next) {
  812. if (cli->bss != bss)
  813. continue;
  814. if (prev_c)
  815. prev_c->next = cli->next;
  816. else
  817. drv->cli = cli->next;
  818. free(cli);
  819. break;
  820. }
  821. test_driver_free_bss(bss);
  822. return 0;
  823. }
  824. return -1;
  825. }
  826. static int test_driver_if_add(const char *iface, void *priv,
  827. enum hostapd_driver_if_type type, char *ifname,
  828. const u8 *addr)
  829. {
  830. wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s)",
  831. __func__, iface, type, ifname);
  832. return 0;
  833. }
  834. static int test_driver_if_update(void *priv, enum hostapd_driver_if_type type,
  835. char *ifname, const u8 *addr)
  836. {
  837. wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
  838. return 0;
  839. }
  840. static int test_driver_if_remove(void *priv, enum hostapd_driver_if_type type,
  841. const char *ifname, const u8 *addr)
  842. {
  843. wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
  844. return 0;
  845. }
  846. static int test_driver_valid_bss_mask(void *priv, const u8 *addr,
  847. const u8 *mask)
  848. {
  849. return 0;
  850. }
  851. static int test_driver_set_ssid(const char *ifname, void *priv, const u8 *buf,
  852. int len)
  853. {
  854. struct test_driver_data *drv = priv;
  855. struct test_driver_bss *bss;
  856. wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
  857. wpa_hexdump_ascii(MSG_DEBUG, "test_driver_set_ssid: SSID", buf, len);
  858. for (bss = drv->bss; bss; bss = bss->next) {
  859. if (strcmp(bss->ifname, ifname) != 0)
  860. continue;
  861. if (len < 0 || (size_t) len > sizeof(bss->ssid))
  862. return -1;
  863. memcpy(bss->ssid, buf, len);
  864. bss->ssid_len = len;
  865. return 0;
  866. }
  867. return -1;
  868. }
  869. static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
  870. {
  871. struct test_driver_data *drv = priv;
  872. struct test_driver_bss *bss;
  873. wpa_printf(MSG_DEBUG, "%s(ifname=%s enabled=%d)",
  874. __func__, ifname, enabled);
  875. for (bss = drv->bss; bss; bss = bss->next) {
  876. if (strcmp(bss->ifname, ifname) != 0)
  877. continue;
  878. bss->privacy = enabled;
  879. return 0;
  880. }
  881. return -1;
  882. }
  883. static int test_driver_set_encryption(const char *iface, void *priv,
  884. const char *alg, const u8 *addr, int idx,
  885. const u8 *key, size_t key_len, int txkey)
  886. {
  887. wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%s idx=%d txkey=%d)",
  888. __func__, iface, alg, idx, txkey);
  889. if (addr)
  890. wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
  891. if (key)
  892. wpa_hexdump_key(MSG_DEBUG, " key", key, key_len);
  893. return 0;
  894. }
  895. static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
  896. const char *ifname, int vlan_id)
  897. {
  898. wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
  899. __func__, MAC2STR(addr), ifname, vlan_id);
  900. return 0;
  901. }
  902. static int test_driver_sta_add(const char *ifname, void *priv, const u8 *addr,
  903. u16 aid, u16 capability, u8 *supp_rates,
  904. size_t supp_rates_len, int flags,
  905. u16 listen_interval)
  906. {
  907. struct test_driver_data *drv = priv;
  908. struct test_client_socket *cli;
  909. struct test_driver_bss *bss;
  910. wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
  911. "capability=0x%x flags=0x%x listen_interval=%d)",
  912. __func__, ifname, MAC2STR(addr), aid, capability, flags,
  913. listen_interval);
  914. wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
  915. supp_rates, supp_rates_len);
  916. cli = drv->cli;
  917. while (cli) {
  918. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  919. break;
  920. cli = cli->next;
  921. }
  922. if (!cli) {
  923. wpa_printf(MSG_DEBUG, "%s: no matching client entry",
  924. __func__);
  925. return -1;
  926. }
  927. for (bss = drv->bss; bss; bss = bss->next) {
  928. if (strcmp(ifname, bss->ifname) == 0)
  929. break;
  930. }
  931. if (bss == NULL) {
  932. wpa_printf(MSG_DEBUG, "%s: No matching interface found from "
  933. "configured BSSes", __func__);
  934. return -1;
  935. }
  936. cli->bss = bss;
  937. return 0;
  938. }
  939. static void * test_driver_init(struct hostapd_data *hapd)
  940. {
  941. struct test_driver_data *drv;
  942. struct sockaddr_un addr_un;
  943. struct sockaddr_in addr_in;
  944. struct sockaddr *addr;
  945. socklen_t alen;
  946. drv = os_zalloc(sizeof(struct test_driver_data));
  947. if (drv == NULL) {
  948. printf("Could not allocate memory for test driver data\n");
  949. return NULL;
  950. }
  951. drv->bss = os_zalloc(sizeof(*drv->bss));
  952. if (drv->bss == NULL) {
  953. printf("Could not allocate memory for test driver BSS data\n");
  954. free(drv);
  955. return NULL;
  956. }
  957. drv->hapd = hapd;
  958. /* Generate a MAC address to help testing with multiple APs */
  959. hapd->own_addr[0] = 0x02; /* locally administered */
  960. sha1_prf((const u8 *) hapd->conf->iface, strlen(hapd->conf->iface),
  961. "hostapd test bssid generation",
  962. (const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len,
  963. hapd->own_addr + 1, ETH_ALEN - 1);
  964. os_strlcpy(drv->bss->ifname, hapd->conf->iface, IFNAMSIZ);
  965. memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
  966. if (hapd->conf->test_socket) {
  967. if (strlen(hapd->conf->test_socket) >=
  968. sizeof(addr_un.sun_path)) {
  969. printf("Too long test_socket path\n");
  970. test_driver_free_priv(drv);
  971. return NULL;
  972. }
  973. if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) {
  974. size_t len = strlen(hapd->conf->test_socket) + 30;
  975. drv->socket_dir = strdup(hapd->conf->test_socket + 4);
  976. drv->own_socket_path = malloc(len);
  977. if (drv->own_socket_path) {
  978. snprintf(drv->own_socket_path, len,
  979. "%s/AP-" MACSTR,
  980. hapd->conf->test_socket + 4,
  981. MAC2STR(hapd->own_addr));
  982. }
  983. } else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) {
  984. drv->udp_port = atoi(hapd->conf->test_socket + 4);
  985. } else {
  986. drv->own_socket_path = strdup(hapd->conf->test_socket);
  987. }
  988. if (drv->own_socket_path == NULL && drv->udp_port == 0) {
  989. test_driver_free_priv(drv);
  990. return NULL;
  991. }
  992. drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
  993. SOCK_DGRAM, 0);
  994. if (drv->test_socket < 0) {
  995. perror("socket");
  996. test_driver_free_priv(drv);
  997. return NULL;
  998. }
  999. if (drv->udp_port) {
  1000. os_memset(&addr_in, 0, sizeof(addr_in));
  1001. addr_in.sin_family = AF_INET;
  1002. addr_in.sin_port = htons(drv->udp_port);
  1003. addr = (struct sockaddr *) &addr_in;
  1004. alen = sizeof(addr_in);
  1005. } else {
  1006. os_memset(&addr_un, 0, sizeof(addr_un));
  1007. addr_un.sun_family = AF_UNIX;
  1008. os_strlcpy(addr_un.sun_path, drv->own_socket_path,
  1009. sizeof(addr_un.sun_path));
  1010. addr = (struct sockaddr *) &addr_un;
  1011. alen = sizeof(addr_un);
  1012. }
  1013. if (bind(drv->test_socket, addr, alen) < 0) {
  1014. perror("bind(PF_UNIX)");
  1015. close(drv->test_socket);
  1016. if (drv->own_socket_path)
  1017. unlink(drv->own_socket_path);
  1018. test_driver_free_priv(drv);
  1019. return NULL;
  1020. }
  1021. eloop_register_read_sock(drv->test_socket,
  1022. test_driver_receive_unix, drv, NULL);
  1023. } else
  1024. drv->test_socket = -1;
  1025. return drv;
  1026. }
  1027. static void test_driver_deinit(void *priv)
  1028. {
  1029. struct test_driver_data *drv = priv;
  1030. struct test_client_socket *cli, *prev;
  1031. cli = drv->cli;
  1032. while (cli) {
  1033. prev = cli;
  1034. cli = cli->next;
  1035. free(prev);
  1036. }
  1037. if (drv->test_socket >= 0) {
  1038. eloop_unregister_read_sock(drv->test_socket);
  1039. close(drv->test_socket);
  1040. if (drv->own_socket_path)
  1041. unlink(drv->own_socket_path);
  1042. }
  1043. /* There should be only one BSS remaining at this point. */
  1044. if (drv->bss == NULL)
  1045. wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
  1046. else if (drv->bss->next)
  1047. wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
  1048. test_driver_free_priv(drv);
  1049. }
  1050. const struct wpa_driver_ops wpa_driver_test_ops = {
  1051. .name = "test",
  1052. .init = test_driver_init,
  1053. .deinit = test_driver_deinit,
  1054. .send_eapol = test_driver_send_eapol,
  1055. .send_mgmt_frame = test_driver_send_mgmt_frame,
  1056. .set_generic_elem = test_driver_set_generic_elem,
  1057. .sta_deauth = test_driver_sta_deauth,
  1058. .sta_disassoc = test_driver_sta_disassoc,
  1059. .get_hw_feature_data = test_driver_get_hw_feature_data,
  1060. .bss_add = test_driver_bss_add,
  1061. .bss_remove = test_driver_bss_remove,
  1062. .if_add = test_driver_if_add,
  1063. .if_update = test_driver_if_update,
  1064. .if_remove = test_driver_if_remove,
  1065. .valid_bss_mask = test_driver_valid_bss_mask,
  1066. .set_ssid = test_driver_set_ssid,
  1067. .set_privacy = test_driver_set_privacy,
  1068. .set_encryption = test_driver_set_encryption,
  1069. .set_sta_vlan = test_driver_set_sta_vlan,
  1070. .sta_add = test_driver_sta_add,
  1071. .send_ether = test_driver_send_ether,
  1072. .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
  1073. .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
  1074. };