driver_test.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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 = host_to_be16(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 = host_to_be16(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 (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
  391. os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
  392. sta->flags |= WLAN_STA_WPS;
  393. goto skip_wpa_check;
  394. }
  395. if (sta->wpa_sm == NULL)
  396. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  397. sta->addr);
  398. if (sta->wpa_sm == NULL) {
  399. printf("test_driver: Failed to initialize WPA state "
  400. "machine\n");
  401. return -1;
  402. }
  403. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  404. ie, ielen, NULL, 0);
  405. if (res != WPA_IE_OK) {
  406. printf("WPA/RSN information element rejected? "
  407. "(res %u)\n", res);
  408. wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
  409. return -1;
  410. }
  411. }
  412. skip_wpa_check:
  413. new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
  414. sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
  415. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  416. hostapd_new_assoc_sta(hapd, sta, !new_assoc);
  417. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  418. return 0;
  419. }
  420. static void test_driver_assoc(struct test_driver_data *drv,
  421. struct sockaddr_un *from, socklen_t fromlen,
  422. char *data)
  423. {
  424. struct test_client_socket *cli;
  425. u8 ie[256], ssid[32];
  426. size_t ielen, ssid_len = 0;
  427. char *pos, *pos2, cmd[50];
  428. struct test_driver_bss *bss;
  429. /* data: STA-addr SSID(hex) IEs(hex) */
  430. cli = os_zalloc(sizeof(*cli));
  431. if (cli == NULL)
  432. return;
  433. if (hwaddr_aton(data, cli->addr)) {
  434. printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
  435. data);
  436. free(cli);
  437. return;
  438. }
  439. pos = data + 17;
  440. while (*pos == ' ')
  441. pos++;
  442. pos2 = strchr(pos, ' ');
  443. ielen = 0;
  444. if (pos2) {
  445. ssid_len = (pos2 - pos) / 2;
  446. if (hexstr2bin(pos, ssid, ssid_len) < 0) {
  447. wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
  448. free(cli);
  449. return;
  450. }
  451. wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
  452. ssid, ssid_len);
  453. pos = pos2 + 1;
  454. ielen = strlen(pos) / 2;
  455. if (ielen > sizeof(ie))
  456. ielen = sizeof(ie);
  457. if (hexstr2bin(pos, ie, ielen) < 0)
  458. ielen = 0;
  459. }
  460. for (bss = drv->bss; bss; bss = bss->next) {
  461. if (bss->ssid_len == ssid_len &&
  462. memcmp(bss->ssid, ssid, ssid_len) == 0)
  463. break;
  464. }
  465. if (bss == NULL) {
  466. wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
  467. "configured BSSes", __func__);
  468. free(cli);
  469. return;
  470. }
  471. cli->bss = bss;
  472. memcpy(&cli->un, from, sizeof(cli->un));
  473. cli->unlen = fromlen;
  474. cli->next = drv->cli;
  475. drv->cli = cli;
  476. wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
  477. (const u8 *) cli->un.sun_path,
  478. cli->unlen - sizeof(cli->un.sun_family));
  479. snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
  480. MAC2STR(bss->bssid));
  481. sendto(drv->test_socket, cmd, strlen(cmd), 0,
  482. (struct sockaddr *) from, fromlen);
  483. if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
  484. wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
  485. }
  486. }
  487. static void test_driver_disassoc(struct test_driver_data *drv,
  488. struct sockaddr_un *from, socklen_t fromlen)
  489. {
  490. struct test_client_socket *cli;
  491. struct sta_info *sta;
  492. cli = test_driver_get_cli(drv, from, fromlen);
  493. if (!cli)
  494. return;
  495. hostapd_logger(drv->hapd, cli->addr, HOSTAPD_MODULE_IEEE80211,
  496. HOSTAPD_LEVEL_INFO, "disassociated");
  497. sta = ap_get_sta(drv->hapd, cli->addr);
  498. if (sta != NULL) {
  499. sta->flags &= ~WLAN_STA_ASSOC;
  500. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  501. sta->acct_terminate_cause =
  502. RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  503. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  504. ap_free_sta(drv->hapd, sta);
  505. }
  506. }
  507. static void test_driver_eapol(struct test_driver_data *drv,
  508. struct sockaddr_un *from, socklen_t fromlen,
  509. u8 *data, size_t datalen)
  510. {
  511. struct test_client_socket *cli;
  512. if (datalen > 14) {
  513. u8 *proto = data + 2 * ETH_ALEN;
  514. /* Skip Ethernet header */
  515. wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
  516. MACSTR " proto=%04x",
  517. MAC2STR(data), MAC2STR(data + ETH_ALEN),
  518. WPA_GET_BE16(proto));
  519. data += 14;
  520. datalen -= 14;
  521. }
  522. cli = test_driver_get_cli(drv, from, fromlen);
  523. if (cli) {
  524. struct hostapd_data *hapd;
  525. hapd = test_driver_get_hapd(drv, cli->bss);
  526. if (hapd == NULL)
  527. return;
  528. ieee802_1x_receive(hapd, cli->addr, data, datalen);
  529. } else {
  530. wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
  531. "client");
  532. }
  533. }
  534. static void test_driver_ether(struct test_driver_data *drv,
  535. struct sockaddr_un *from, socklen_t fromlen,
  536. u8 *data, size_t datalen)
  537. {
  538. struct l2_ethhdr *eth;
  539. if (datalen < sizeof(*eth))
  540. return;
  541. eth = (struct l2_ethhdr *) data;
  542. wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
  543. MACSTR " proto=%04x",
  544. MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
  545. be_to_host16(eth->h_proto));
  546. #ifdef CONFIG_IEEE80211R
  547. if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
  548. wpa_ft_rrb_rx(drv->hapd->wpa_auth, eth->h_source,
  549. data + sizeof(*eth), datalen - sizeof(*eth));
  550. }
  551. #endif /* CONFIG_IEEE80211R */
  552. }
  553. static void test_driver_mlme(struct test_driver_data *drv,
  554. struct sockaddr_un *from, socklen_t fromlen,
  555. u8 *data, size_t datalen)
  556. {
  557. struct ieee80211_hdr *hdr;
  558. u16 fc;
  559. hdr = (struct ieee80211_hdr *) data;
  560. if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
  561. struct test_client_socket *cli;
  562. cli = os_zalloc(sizeof(*cli));
  563. if (cli == NULL)
  564. return;
  565. wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
  566. MAC2STR(hdr->addr2));
  567. memcpy(cli->addr, hdr->addr2, ETH_ALEN);
  568. memcpy(&cli->un, from, sizeof(cli->un));
  569. cli->unlen = fromlen;
  570. cli->next = drv->cli;
  571. drv->cli = cli;
  572. }
  573. wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
  574. data, datalen);
  575. fc = le_to_host16(hdr->frame_control);
  576. if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
  577. wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
  578. __func__);
  579. return;
  580. }
  581. ieee802_11_mgmt(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
  582. }
  583. static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
  584. {
  585. struct test_driver_data *drv = eloop_ctx;
  586. char buf[2000];
  587. int res;
  588. struct sockaddr_un from;
  589. socklen_t fromlen = sizeof(from);
  590. res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
  591. (struct sockaddr *) &from, &fromlen);
  592. if (res < 0) {
  593. perror("recvfrom(test_socket)");
  594. return;
  595. }
  596. buf[res] = '\0';
  597. wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
  598. if (strncmp(buf, "SCAN", 4) == 0) {
  599. test_driver_scan(drv, &from, fromlen, buf + 4);
  600. } else if (strncmp(buf, "ASSOC ", 6) == 0) {
  601. test_driver_assoc(drv, &from, fromlen, buf + 6);
  602. } else if (strcmp(buf, "DISASSOC") == 0) {
  603. test_driver_disassoc(drv, &from, fromlen);
  604. } else if (strncmp(buf, "EAPOL ", 6) == 0) {
  605. test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
  606. res - 6);
  607. } else if (strncmp(buf, "ETHER ", 6) == 0) {
  608. test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
  609. res - 6);
  610. } else if (strncmp(buf, "MLME ", 5) == 0) {
  611. test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
  612. } else {
  613. wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
  614. (u8 *) buf, res);
  615. }
  616. }
  617. static struct test_driver_bss *
  618. test_driver_get_bss(struct test_driver_data *drv, const char *ifname)
  619. {
  620. struct test_driver_bss *bss;
  621. for (bss = drv->bss; bss; bss = bss->next) {
  622. if (strcmp(bss->ifname, ifname) == 0)
  623. return bss;
  624. }
  625. return NULL;
  626. }
  627. static int test_driver_set_generic_elem(const char *ifname, void *priv,
  628. const u8 *elem, size_t elem_len)
  629. {
  630. struct test_driver_data *drv = priv;
  631. struct test_driver_bss *bss;
  632. bss = test_driver_get_bss(drv, ifname);
  633. if (bss == NULL)
  634. return -1;
  635. free(bss->ie);
  636. if (elem == NULL) {
  637. bss->ie = NULL;
  638. bss->ielen = 0;
  639. return 0;
  640. }
  641. bss->ie = malloc(elem_len);
  642. if (bss->ie == NULL) {
  643. bss->ielen = 0;
  644. return -1;
  645. }
  646. memcpy(bss->ie, elem, elem_len);
  647. bss->ielen = elem_len;
  648. return 0;
  649. }
  650. static int test_driver_set_wps_beacon_ie(const char *ifname, void *priv,
  651. const u8 *ie, size_t len)
  652. {
  653. struct test_driver_data *drv = priv;
  654. struct test_driver_bss *bss;
  655. wpa_hexdump(MSG_DEBUG, "test_driver: Beacon WPS IE", ie, len);
  656. bss = test_driver_get_bss(drv, ifname);
  657. if (bss == NULL)
  658. return -1;
  659. free(bss->wps_beacon_ie);
  660. if (ie == NULL) {
  661. bss->wps_beacon_ie = NULL;
  662. bss->wps_beacon_ie_len = 0;
  663. return 0;
  664. }
  665. bss->wps_beacon_ie = malloc(len);
  666. if (bss->wps_beacon_ie == NULL) {
  667. bss->wps_beacon_ie_len = 0;
  668. return -1;
  669. }
  670. memcpy(bss->wps_beacon_ie, ie, len);
  671. bss->wps_beacon_ie_len = len;
  672. return 0;
  673. }
  674. static int test_driver_set_wps_probe_resp_ie(const char *ifname, void *priv,
  675. const u8 *ie, size_t len)
  676. {
  677. struct test_driver_data *drv = priv;
  678. struct test_driver_bss *bss;
  679. wpa_hexdump(MSG_DEBUG, "test_driver: ProbeResp WPS IE", ie, len);
  680. bss = test_driver_get_bss(drv, ifname);
  681. if (bss == NULL)
  682. return -1;
  683. free(bss->wps_probe_resp_ie);
  684. if (ie == NULL) {
  685. bss->wps_probe_resp_ie = NULL;
  686. bss->wps_probe_resp_ie_len = 0;
  687. return 0;
  688. }
  689. bss->wps_probe_resp_ie = malloc(len);
  690. if (bss->wps_probe_resp_ie == NULL) {
  691. bss->wps_probe_resp_ie_len = 0;
  692. return -1;
  693. }
  694. memcpy(bss->wps_probe_resp_ie, ie, len);
  695. bss->wps_probe_resp_ie_len = len;
  696. return 0;
  697. }
  698. static int test_driver_sta_deauth(void *priv, const u8 *addr, int reason)
  699. {
  700. struct test_driver_data *drv = priv;
  701. struct test_client_socket *cli;
  702. if (drv->test_socket < 0)
  703. return -1;
  704. cli = drv->cli;
  705. while (cli) {
  706. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  707. break;
  708. cli = cli->next;
  709. }
  710. if (!cli)
  711. return -1;
  712. return sendto(drv->test_socket, "DEAUTH", 6, 0,
  713. (struct sockaddr *) &cli->un, cli->unlen);
  714. }
  715. static int test_driver_sta_disassoc(void *priv, const u8 *addr, int reason)
  716. {
  717. struct test_driver_data *drv = priv;
  718. struct test_client_socket *cli;
  719. if (drv->test_socket < 0)
  720. return -1;
  721. cli = drv->cli;
  722. while (cli) {
  723. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  724. break;
  725. cli = cli->next;
  726. }
  727. if (!cli)
  728. return -1;
  729. return sendto(drv->test_socket, "DISASSOC", 8, 0,
  730. (struct sockaddr *) &cli->un, cli->unlen);
  731. }
  732. static struct hostapd_hw_modes *
  733. test_driver_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
  734. {
  735. struct hostapd_hw_modes *modes;
  736. *num_modes = 3;
  737. *flags = 0;
  738. modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
  739. if (modes == NULL)
  740. return NULL;
  741. modes[0].mode = HOSTAPD_MODE_IEEE80211G;
  742. modes[0].num_channels = 1;
  743. modes[0].num_rates = 1;
  744. modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
  745. modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
  746. if (modes[0].channels == NULL || modes[0].rates == NULL) {
  747. hostapd_free_hw_features(modes, *num_modes);
  748. return NULL;
  749. }
  750. modes[0].channels[0].chan = 1;
  751. modes[0].channels[0].freq = 2412;
  752. modes[0].channels[0].flag = 0;
  753. modes[0].rates[0].rate = 10;
  754. modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
  755. HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
  756. modes[1].mode = HOSTAPD_MODE_IEEE80211B;
  757. modes[1].num_channels = 1;
  758. modes[1].num_rates = 1;
  759. modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
  760. modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
  761. if (modes[1].channels == NULL || modes[1].rates == NULL) {
  762. hostapd_free_hw_features(modes, *num_modes);
  763. return NULL;
  764. }
  765. modes[1].channels[0].chan = 1;
  766. modes[1].channels[0].freq = 2412;
  767. modes[1].channels[0].flag = 0;
  768. modes[1].rates[0].rate = 10;
  769. modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
  770. HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
  771. modes[2].mode = HOSTAPD_MODE_IEEE80211A;
  772. modes[2].num_channels = 1;
  773. modes[2].num_rates = 1;
  774. modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
  775. modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
  776. if (modes[2].channels == NULL || modes[2].rates == NULL) {
  777. hostapd_free_hw_features(modes, *num_modes);
  778. return NULL;
  779. }
  780. modes[2].channels[0].chan = 60;
  781. modes[2].channels[0].freq = 5300;
  782. modes[2].channels[0].flag = 0;
  783. modes[2].rates[0].rate = 60;
  784. modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
  785. HOSTAPD_RATE_MANDATORY;
  786. return modes;
  787. }
  788. static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
  789. {
  790. struct test_driver_data *drv = priv;
  791. struct test_driver_bss *bss;
  792. wpa_printf(MSG_DEBUG, "%s(ifname=%s bssid=" MACSTR ")",
  793. __func__, ifname, MAC2STR(bssid));
  794. bss = os_zalloc(sizeof(*bss));
  795. if (bss == NULL)
  796. return -1;
  797. os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
  798. memcpy(bss->bssid, bssid, ETH_ALEN);
  799. bss->next = drv->bss;
  800. drv->bss = bss;
  801. return 0;
  802. }
  803. static int test_driver_bss_remove(void *priv, const char *ifname)
  804. {
  805. struct test_driver_data *drv = priv;
  806. struct test_driver_bss *bss, *prev;
  807. struct test_client_socket *cli, *prev_c;
  808. wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
  809. for (prev = NULL, bss = drv->bss; bss; prev = bss, bss = bss->next) {
  810. if (strcmp(bss->ifname, ifname) != 0)
  811. continue;
  812. if (prev)
  813. prev->next = bss->next;
  814. else
  815. drv->bss = bss->next;
  816. for (prev_c = NULL, cli = drv->cli; cli;
  817. prev_c = cli, cli = cli->next) {
  818. if (cli->bss != bss)
  819. continue;
  820. if (prev_c)
  821. prev_c->next = cli->next;
  822. else
  823. drv->cli = cli->next;
  824. free(cli);
  825. break;
  826. }
  827. test_driver_free_bss(bss);
  828. return 0;
  829. }
  830. return -1;
  831. }
  832. static int test_driver_if_add(const char *iface, void *priv,
  833. enum hostapd_driver_if_type type, char *ifname,
  834. const u8 *addr)
  835. {
  836. wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s)",
  837. __func__, iface, type, ifname);
  838. return 0;
  839. }
  840. static int test_driver_if_update(void *priv, enum hostapd_driver_if_type type,
  841. 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_if_remove(void *priv, enum hostapd_driver_if_type type,
  847. const char *ifname, const u8 *addr)
  848. {
  849. wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
  850. return 0;
  851. }
  852. static int test_driver_valid_bss_mask(void *priv, const u8 *addr,
  853. const u8 *mask)
  854. {
  855. return 0;
  856. }
  857. static int test_driver_set_ssid(const char *ifname, void *priv, const u8 *buf,
  858. int len)
  859. {
  860. struct test_driver_data *drv = priv;
  861. struct test_driver_bss *bss;
  862. wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
  863. wpa_hexdump_ascii(MSG_DEBUG, "test_driver_set_ssid: SSID", buf, len);
  864. for (bss = drv->bss; bss; bss = bss->next) {
  865. if (strcmp(bss->ifname, ifname) != 0)
  866. continue;
  867. if (len < 0 || (size_t) len > sizeof(bss->ssid))
  868. return -1;
  869. memcpy(bss->ssid, buf, len);
  870. bss->ssid_len = len;
  871. return 0;
  872. }
  873. return -1;
  874. }
  875. static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
  876. {
  877. struct test_driver_data *drv = priv;
  878. struct test_driver_bss *bss;
  879. wpa_printf(MSG_DEBUG, "%s(ifname=%s enabled=%d)",
  880. __func__, ifname, enabled);
  881. for (bss = drv->bss; bss; bss = bss->next) {
  882. if (strcmp(bss->ifname, ifname) != 0)
  883. continue;
  884. bss->privacy = enabled;
  885. return 0;
  886. }
  887. return -1;
  888. }
  889. static int test_driver_set_encryption(const char *iface, void *priv,
  890. const char *alg, const u8 *addr, int idx,
  891. const u8 *key, size_t key_len, int txkey)
  892. {
  893. wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%s idx=%d txkey=%d)",
  894. __func__, iface, alg, idx, txkey);
  895. if (addr)
  896. wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
  897. if (key)
  898. wpa_hexdump_key(MSG_DEBUG, " key", key, key_len);
  899. return 0;
  900. }
  901. static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
  902. const char *ifname, int vlan_id)
  903. {
  904. wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
  905. __func__, MAC2STR(addr), ifname, vlan_id);
  906. return 0;
  907. }
  908. static int test_driver_sta_add(const char *ifname, void *priv, const u8 *addr,
  909. u16 aid, u16 capability, u8 *supp_rates,
  910. size_t supp_rates_len, int flags,
  911. u16 listen_interval)
  912. {
  913. struct test_driver_data *drv = priv;
  914. struct test_client_socket *cli;
  915. struct test_driver_bss *bss;
  916. wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
  917. "capability=0x%x flags=0x%x listen_interval=%d)",
  918. __func__, ifname, MAC2STR(addr), aid, capability, flags,
  919. listen_interval);
  920. wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
  921. supp_rates, supp_rates_len);
  922. cli = drv->cli;
  923. while (cli) {
  924. if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
  925. break;
  926. cli = cli->next;
  927. }
  928. if (!cli) {
  929. wpa_printf(MSG_DEBUG, "%s: no matching client entry",
  930. __func__);
  931. return -1;
  932. }
  933. for (bss = drv->bss; bss; bss = bss->next) {
  934. if (strcmp(ifname, bss->ifname) == 0)
  935. break;
  936. }
  937. if (bss == NULL) {
  938. wpa_printf(MSG_DEBUG, "%s: No matching interface found from "
  939. "configured BSSes", __func__);
  940. return -1;
  941. }
  942. cli->bss = bss;
  943. return 0;
  944. }
  945. static void * test_driver_init(struct hostapd_data *hapd)
  946. {
  947. struct test_driver_data *drv;
  948. struct sockaddr_un addr_un;
  949. struct sockaddr_in addr_in;
  950. struct sockaddr *addr;
  951. socklen_t alen;
  952. drv = os_zalloc(sizeof(struct test_driver_data));
  953. if (drv == NULL) {
  954. printf("Could not allocate memory for test driver data\n");
  955. return NULL;
  956. }
  957. drv->bss = os_zalloc(sizeof(*drv->bss));
  958. if (drv->bss == NULL) {
  959. printf("Could not allocate memory for test driver BSS data\n");
  960. free(drv);
  961. return NULL;
  962. }
  963. drv->hapd = hapd;
  964. /* Generate a MAC address to help testing with multiple APs */
  965. hapd->own_addr[0] = 0x02; /* locally administered */
  966. sha1_prf((const u8 *) hapd->conf->iface, strlen(hapd->conf->iface),
  967. "hostapd test bssid generation",
  968. (const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len,
  969. hapd->own_addr + 1, ETH_ALEN - 1);
  970. os_strlcpy(drv->bss->ifname, hapd->conf->iface, IFNAMSIZ);
  971. memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
  972. if (hapd->conf->test_socket) {
  973. if (strlen(hapd->conf->test_socket) >=
  974. sizeof(addr_un.sun_path)) {
  975. printf("Too long test_socket path\n");
  976. test_driver_free_priv(drv);
  977. return NULL;
  978. }
  979. if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) {
  980. size_t len = strlen(hapd->conf->test_socket) + 30;
  981. drv->socket_dir = strdup(hapd->conf->test_socket + 4);
  982. drv->own_socket_path = malloc(len);
  983. if (drv->own_socket_path) {
  984. snprintf(drv->own_socket_path, len,
  985. "%s/AP-" MACSTR,
  986. hapd->conf->test_socket + 4,
  987. MAC2STR(hapd->own_addr));
  988. }
  989. } else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) {
  990. drv->udp_port = atoi(hapd->conf->test_socket + 4);
  991. } else {
  992. drv->own_socket_path = strdup(hapd->conf->test_socket);
  993. }
  994. if (drv->own_socket_path == NULL && drv->udp_port == 0) {
  995. test_driver_free_priv(drv);
  996. return NULL;
  997. }
  998. drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
  999. SOCK_DGRAM, 0);
  1000. if (drv->test_socket < 0) {
  1001. perror("socket");
  1002. test_driver_free_priv(drv);
  1003. return NULL;
  1004. }
  1005. if (drv->udp_port) {
  1006. os_memset(&addr_in, 0, sizeof(addr_in));
  1007. addr_in.sin_family = AF_INET;
  1008. addr_in.sin_port = htons(drv->udp_port);
  1009. addr = (struct sockaddr *) &addr_in;
  1010. alen = sizeof(addr_in);
  1011. } else {
  1012. os_memset(&addr_un, 0, sizeof(addr_un));
  1013. addr_un.sun_family = AF_UNIX;
  1014. os_strlcpy(addr_un.sun_path, drv->own_socket_path,
  1015. sizeof(addr_un.sun_path));
  1016. addr = (struct sockaddr *) &addr_un;
  1017. alen = sizeof(addr_un);
  1018. }
  1019. if (bind(drv->test_socket, addr, alen) < 0) {
  1020. perror("bind(PF_UNIX)");
  1021. close(drv->test_socket);
  1022. if (drv->own_socket_path)
  1023. unlink(drv->own_socket_path);
  1024. test_driver_free_priv(drv);
  1025. return NULL;
  1026. }
  1027. eloop_register_read_sock(drv->test_socket,
  1028. test_driver_receive_unix, drv, NULL);
  1029. } else
  1030. drv->test_socket = -1;
  1031. return drv;
  1032. }
  1033. static void test_driver_deinit(void *priv)
  1034. {
  1035. struct test_driver_data *drv = priv;
  1036. struct test_client_socket *cli, *prev;
  1037. cli = drv->cli;
  1038. while (cli) {
  1039. prev = cli;
  1040. cli = cli->next;
  1041. free(prev);
  1042. }
  1043. if (drv->test_socket >= 0) {
  1044. eloop_unregister_read_sock(drv->test_socket);
  1045. close(drv->test_socket);
  1046. if (drv->own_socket_path)
  1047. unlink(drv->own_socket_path);
  1048. }
  1049. /* There should be only one BSS remaining at this point. */
  1050. if (drv->bss == NULL)
  1051. wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
  1052. else if (drv->bss->next)
  1053. wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
  1054. test_driver_free_priv(drv);
  1055. }
  1056. const struct wpa_driver_ops wpa_driver_test_ops = {
  1057. .name = "test",
  1058. .init = test_driver_init,
  1059. .deinit = test_driver_deinit,
  1060. .send_eapol = test_driver_send_eapol,
  1061. .send_mgmt_frame = test_driver_send_mgmt_frame,
  1062. .set_generic_elem = test_driver_set_generic_elem,
  1063. .sta_deauth = test_driver_sta_deauth,
  1064. .sta_disassoc = test_driver_sta_disassoc,
  1065. .get_hw_feature_data = test_driver_get_hw_feature_data,
  1066. .bss_add = test_driver_bss_add,
  1067. .bss_remove = test_driver_bss_remove,
  1068. .if_add = test_driver_if_add,
  1069. .if_update = test_driver_if_update,
  1070. .if_remove = test_driver_if_remove,
  1071. .valid_bss_mask = test_driver_valid_bss_mask,
  1072. .set_ssid = test_driver_set_ssid,
  1073. .set_privacy = test_driver_set_privacy,
  1074. .set_encryption = test_driver_set_encryption,
  1075. .set_sta_vlan = test_driver_set_sta_vlan,
  1076. .sta_add = test_driver_sta_add,
  1077. .send_ether = test_driver_send_ether,
  1078. .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
  1079. .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
  1080. };