Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 71.74 KB | None | 0 0
  1. diff --git a/hostapd/main.c b/hostapd/main.c
  2. index 6c7406a..07dda78 100644
  3. --- a/hostapd/main.c
  4. +++ b/hostapd/main.c
  5. @@ -422,7 +422,7 @@ static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
  6. static void show_version(void)
  7. {
  8. fprintf(stderr,
  9. - "hostapd v" VERSION_STR "\n"
  10. + "hostapd v" VERSION_STR " for Realtek rtl871xdrv\n"
  11. "User space daemon for IEEE 802.11 AP management,\n"
  12. "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
  13. "Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> "
  14. diff --git a/src/ap/beacon.c b/src/ap/beacon.c
  15. index 5fe8fd5..5f7c077 100644
  16. --- a/src/ap/beacon.c
  17. +++ b/src/ap/beacon.c
  18. @@ -1007,6 +1007,11 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
  19. #ifdef CONFIG_IEEE80211N
  20. tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
  21. tailpos = hostapd_eid_ht_operation(hapd, tailpos);
  22. +
  23. + //DRIVER_RTW ADD
  24. + if(hapd->iconf->ieee80211n)
  25. + hapd->conf->wmm_enabled = 1;
  26. +
  27. #endif /* CONFIG_IEEE80211N */
  28.  
  29. tailpos = hostapd_eid_ext_capab(hapd, tailpos);
  30. diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c
  31. index fc8786d..efd3841 100644
  32. --- a/src/ap/hw_features.c
  33. +++ b/src/ap/hw_features.c
  34. @@ -494,7 +494,10 @@ static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
  35. iface->num_ht40_scan_tries = 1;
  36. eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
  37. eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
  38. - return 1;
  39. +
  40. + //DRIVER_RTW Modify
  41. + //return -1;
  42. + return 0;//ignore this error
  43. }
  44.  
  45. if (ret < 0) {
  46. diff --git a/src/drivers/driver_bsd.c b/src/drivers/driver_bsd.c
  47. index bab1f03..555d0d8 100644
  48. --- a/src/drivers/driver_bsd.c
  49. +++ b/src/drivers/driver_bsd.c
  50. @@ -47,6 +47,12 @@
  51.  
  52. #include "l2_packet/l2_packet.h"
  53.  
  54. +#ifdef HOSTAPD
  55. +#ifdef CONFIG_SUPPORT_RTW_DRIVER
  56. +#define RTW_BSD_HOSTAPD_SET_BEACON (1100)
  57. +#endif
  58. +#endif
  59. +
  60. struct bsd_driver_data {
  61. struct hostapd_data *hapd; /* back pointer */
  62.  
  63. @@ -800,6 +806,296 @@ handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
  64. drv_event_eapol_rx(drv->hapd, src_addr, buf, len);
  65. }
  66.  
  67. +#ifdef CONFIG_SUPPORT_RTW_DRIVER
  68. +static int rtw_set_beacon_ops(void *priv, const u8 *head, size_t head_len,
  69. + const u8 *tail, size_t tail_len, int dtim_period,
  70. + int beacon_int)
  71. +{
  72. + int ret=0;
  73. + u8 *pbuf;
  74. + size_t sz;
  75. + struct bsd_driver_data *drv = priv;
  76. +
  77. + if((head_len<24) ||(!head))
  78. + return -1;
  79. +
  80. + sz = head_len+tail_len - 24; // 24 = wlan hdr
  81. +
  82. + printf("%s, beacon_sz=%d\n", __func__, sz);
  83. +
  84. + pbuf = os_zalloc(sz);
  85. + if (pbuf == NULL) {
  86. + return -ENOMEM;
  87. + }
  88. +
  89. + os_memcpy(pbuf, (head+24), (head_len-24));// 24=beacon header len.
  90. +
  91. + os_memcpy(&pbuf[head_len-24], tail, tail_len);
  92. +
  93. + ret = set80211var(drv, RTW_BSD_HOSTAPD_SET_BEACON, pbuf, sz);
  94. +
  95. + os_free(pbuf);
  96. +
  97. + return ret;
  98. +
  99. +}
  100. +
  101. +static struct hostapd_hw_modes *rtw_get_hw_feature_data_ops(
  102. + void *priv, u16 *num_modes, u16 *flags)
  103. +{
  104. +
  105. +#define MAX_NUM_CHANNEL (14)
  106. +#define MAX_NUM_CHANNEL_5G (24)
  107. +
  108. + struct hostapd_hw_modes *modes;
  109. + size_t i;
  110. + int k;
  111. +
  112. + printf("%s\n", __func__);
  113. +
  114. + *num_modes = 3;
  115. + *flags = 0;
  116. +
  117. + modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
  118. + if (modes == NULL)
  119. + return NULL;
  120. +
  121. + //.1
  122. + modes[0].mode = HOSTAPD_MODE_IEEE80211G;
  123. + modes[0].num_channels = MAX_NUM_CHANNEL;
  124. + modes[0].num_rates = 12;
  125. + modes[0].channels =
  126. + os_zalloc(MAX_NUM_CHANNEL * sizeof(struct hostapd_channel_data));
  127. + modes[0].rates = os_zalloc(modes[0].num_rates * sizeof(int));
  128. + if (modes[0].channels == NULL || modes[0].rates == NULL)
  129. + goto fail;
  130. + for (i = 0; i < MAX_NUM_CHANNEL; i++) {
  131. + modes[0].channels[i].chan = i + 1;
  132. + modes[0].channels[i].freq = 2412 + 5 * i;
  133. + modes[0].channels[i].flag = 0;
  134. + if (i >= 13)
  135. + modes[0].channels[i].flag = HOSTAPD_CHAN_DISABLED;
  136. + }
  137. + modes[0].rates[0] = 10;
  138. + modes[0].rates[1] = 20;
  139. + modes[0].rates[2] = 55;
  140. + modes[0].rates[3] = 110;
  141. + modes[0].rates[4] = 60;
  142. + modes[0].rates[5] = 90;
  143. + modes[0].rates[6] = 120;
  144. + modes[0].rates[7] = 180;
  145. + modes[0].rates[8] = 240;
  146. + modes[0].rates[9] = 360;
  147. + modes[0].rates[10] = 480;
  148. + modes[0].rates[11] = 540;
  149. +
  150. +
  151. + //.2
  152. + modes[1].mode = HOSTAPD_MODE_IEEE80211B;
  153. + modes[1].num_channels = MAX_NUM_CHANNEL;
  154. + modes[1].num_rates = 4;
  155. + modes[1].channels =
  156. + os_zalloc(MAX_NUM_CHANNEL * sizeof(struct hostapd_channel_data));
  157. + modes[1].rates = os_zalloc(modes[1].num_rates * sizeof(int));
  158. + if (modes[1].channels == NULL || modes[1].rates == NULL)
  159. + goto fail;
  160. + for (i = 0; i < MAX_NUM_CHANNEL; i++) {
  161. + modes[1].channels[i].chan = i + 1;
  162. + modes[1].channels[i].freq = 2412 + 5 * i;
  163. + modes[1].channels[i].flag = 0;
  164. + if (i >= 11)
  165. + modes[1].channels[i].flag = HOSTAPD_CHAN_DISABLED;
  166. + }
  167. + modes[1].rates[0] = 10;
  168. + modes[1].rates[1] = 20;
  169. + modes[1].rates[2] = 55;
  170. + modes[1].rates[3] = 110;
  171. +
  172. +
  173. + //.3
  174. + modes[2].mode = HOSTAPD_MODE_IEEE80211A;
  175. +#ifdef CONFIG_DRIVER_RTL_DFS
  176. + modes[2].num_channels = MAX_NUM_CHANNEL_5G;
  177. +#else /* CONFIG_DRIVER_RTL_DFS */
  178. + modes[2].num_channels = 9;
  179. +#endif /* CONFIG_DRIVER_RTL_DFS */
  180. +
  181. + modes[2].num_rates = 8;
  182. + modes[2].channels = os_zalloc(modes[2].num_channels * sizeof(struct hostapd_channel_data));
  183. + modes[2].rates = os_zalloc(modes[2].num_rates * sizeof(int));
  184. + if (modes[2].channels == NULL || modes[2].rates == NULL)
  185. + goto fail;
  186. +
  187. +
  188. + k = 0;
  189. + // 5G band1 Channel: 36, 40, 44, 48
  190. + for (i=0; i < 4; i++) {
  191. + modes[2].channels[k].chan = 36+(i*4);
  192. + modes[2].channels[k].freq = 5180+(i*20);
  193. + modes[2].channels[k].flag = 0;
  194. + k++;
  195. + }
  196. +
  197. +#ifdef CONFIG_DRIVER_RTL_DFS
  198. + // 5G band2 Channel: 52, 56, 60, 64
  199. + for (i=0; i < 4; i++) {
  200. + modes[2].channels[k].chan = 52+(i*4);
  201. + modes[2].channels[k].freq = 5260+(i*20);
  202. + modes[2].channels[k].flag = 0;
  203. + k++;
  204. + }
  205. +
  206. + // 5G band3 Channel: 100, 104, 108. 112, 116, 120, 124, 128, 132, 136, 140
  207. + for (i=0; i < 11; i++) {
  208. + modes[2].channels[k].chan = 100+(i*4);
  209. + modes[2].channels[k].freq = 5500+(i*20);
  210. + modes[2].channels[k].flag = 0;
  211. + k++;
  212. + }
  213. +#endif /* CONFIG_DRIVER_RTL_DFS */
  214. +
  215. + // 5G band4 Channel: 149, 153, 157, 161, 165
  216. + for (i=0; i < 5; i++) {
  217. + modes[2].channels[k].chan = 149+(i*4);
  218. + modes[2].channels[k].freq = 5745+(i*20);
  219. + modes[2].channels[k].flag = 0;
  220. + k++;
  221. + }
  222. +
  223. + modes[2].rates[0] = 60;
  224. + modes[2].rates[1] = 90;
  225. + modes[2].rates[2] = 120;
  226. + modes[2].rates[3] = 180;
  227. + modes[2].rates[4] = 240;
  228. + modes[2].rates[5] = 360;
  229. + modes[2].rates[6] = 480;
  230. + modes[2].rates[7] = 540;
  231. +
  232. +
  233. + //
  234. +#if 0
  235. +#define HT_CAP_INFO_LDPC_CODING_CAP ((u16) BIT(0))
  236. +#define HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET ((u16) BIT(1))
  237. +#define HT_CAP_INFO_SMPS_MASK ((u16) (BIT(2) | BIT(3)))
  238. +#define HT_CAP_INFO_SMPS_STATIC ((u16) 0)
  239. +#define HT_CAP_INFO_SMPS_DYNAMIC ((u16) BIT(2))
  240. +#define HT_CAP_INFO_SMPS_DISABLED ((u16) (BIT(2) | BIT(3)))
  241. +#define HT_CAP_INFO_GREEN_FIELD ((u16) BIT(4))
  242. +#define HT_CAP_INFO_SHORT_GI20MHZ ((u16) BIT(5))
  243. +#define HT_CAP_INFO_SHORT_GI40MHZ ((u16) BIT(6))
  244. +#define HT_CAP_INFO_TX_STBC ((u16) BIT(7))
  245. +#define HT_CAP_INFO_RX_STBC_MASK ((u16) (BIT(8) | BIT(9)))
  246. +#define HT_CAP_INFO_RX_STBC_1 ((u16) BIT(8))
  247. +#define HT_CAP_INFO_RX_STBC_12 ((u16) BIT(9))
  248. +#define HT_CAP_INFO_RX_STBC_123 ((u16) (BIT(8) | BIT(9)))
  249. +#define HT_CAP_INFO_DELAYED_BA ((u16) BIT(10))
  250. +#define HT_CAP_INFO_MAX_AMSDU_SIZE ((u16) BIT(11))
  251. +#define HT_CAP_INFO_DSSS_CCK40MHZ ((u16) BIT(12))
  252. +#define HT_CAP_INFO_PSMP_SUPP ((u16) BIT(13))
  253. +#define HT_CAP_INFO_40MHZ_INTOLERANT ((u16) BIT(14))
  254. +#define HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT ((u16) BIT(15))
  255. +#endif
  256. +
  257. + //HOSTAPD_MODE_IEEE80211G
  258. + modes[0].ht_capab = HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET|HT_CAP_INFO_SHORT_GI20MHZ|
  259. + HT_CAP_INFO_SHORT_GI40MHZ|HT_CAP_INFO_MAX_AMSDU_SIZE|HT_CAP_INFO_DSSS_CCK40MHZ;
  260. +
  261. + modes[0].mcs_set[0]= 0xff;
  262. + modes[0].mcs_set[1]= 0xff;
  263. +
  264. + //HOSTAPD_MODE_IEEE80211B
  265. + modes[1].ht_capab = 0;
  266. +
  267. + //HOSTAPD_MODE_IEEE80211A
  268. + modes[2].ht_capab = modes[0].ht_capab;
  269. +
  270. + modes[2].mcs_set[0]= 0xff;
  271. + modes[2].mcs_set[1]= 0xff;
  272. +
  273. + return modes;
  274. +
  275. +fail:
  276. + if (modes) {
  277. + for (i = 0; i < *num_modes; i++) {
  278. + os_free(modes[i].channels);
  279. + os_free(modes[i].rates);
  280. + }
  281. + os_free(modes);
  282. + }
  283. +
  284. + return NULL;
  285. +
  286. +}
  287. +
  288. +#if 0
  289. +#define IEEE80211_FC0_TYPE_MASK 0x0c
  290. +#define IEEE80211_FC0_TYPE_SHIFT 2
  291. +#define IEEE80211_FC0_TYPE_MGT 0x00
  292. +#define IEEE80211_FC0_TYPE_CTL 0x04
  293. +#define IEEE80211_FC0_TYPE_DATA 0x08
  294. +#define IEEE80211_FC0_SUBTYPE_MASK 0xf0
  295. +#define IEEE80211_FC0_SUBTYPE_SHIFT 4
  296. +#define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00
  297. +#define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10
  298. +#define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20
  299. +#define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30
  300. +#define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40
  301. +#define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50
  302. +#define IEEE80211_FC0_SUBTYPE_BEACON 0x80
  303. +#define IEEE80211_FC0_SUBTYPE_ATIM 0x90
  304. +#define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0
  305. +#define IEEE80211_FC0_SUBTYPE_AUTH 0xb0
  306. +#define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0
  307. +#define IEEE80211_FC0_SUBTYPE_ACTION 0xd0
  308. +#define IEEE80211_FC0_SUBTYPE_ACTION_NOACK 0xe0
  309. +
  310. +#define IEEE80211_APPIE_WPA (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_BEACON | \
  311. + IEEE80211_FC0_SUBTYPE_PROBE_RESP)
  312. +
  313. +#endif
  314. +
  315. +#define RTW_IEEE80211_APPIE_BEACON (IEEE80211_FC0_TYPE_MGT|IEEE80211_FC0_SUBTYPE_BEACON)
  316. +#define RTW_IEEE80211_APPIE_PROBE_RESP (IEEE80211_FC0_TYPE_MGT|IEEE80211_FC0_SUBTYPE_PROBE_RESP)
  317. +#define RTW_IEEE80211_APPIE_ASSOC_RESP (IEEE80211_FC0_TYPE_MGT|IEEE80211_FC0_SUBTYPE_ASSOC_RESP)
  318. +
  319. +
  320. +static int rtw_set_wps_assoc_resp_ie(void *priv, const void *ie, size_t len)
  321. +{
  322. + return bsd_set80211(priv, IEEE80211_IOC_APPIE, RTW_IEEE80211_APPIE_ASSOC_RESP,
  323. + ie, len);
  324. +}
  325. +
  326. +static int rtw_set_wps_beacon_ie(void *priv, const void *ie, size_t len)
  327. +{
  328. + return bsd_set80211(priv, IEEE80211_IOC_APPIE, RTW_IEEE80211_APPIE_BEACON,
  329. + ie, len);
  330. +}
  331. +
  332. +static int rtw_set_wps_probe_resp_ie(void *priv, const void *ie, size_t len)
  333. +{
  334. + return bsd_set80211(priv, IEEE80211_IOC_APPIE, RTW_IEEE80211_APPIE_PROBE_RESP,
  335. + ie, len);
  336. +}
  337. +
  338. +static int rtw_set_ap_wps_ie_ops(void *priv, const struct wpabuf *beacon,
  339. + const struct wpabuf *proberesp, const struct wpabuf *assocresp)
  340. +{
  341. + if (rtw_set_wps_assoc_resp_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
  342. + assocresp ? wpabuf_len(assocresp) : 0))
  343. + return -1;
  344. +
  345. + if (rtw_set_wps_beacon_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
  346. + beacon ? wpabuf_len(beacon) : 0))
  347. + return -1;
  348. +
  349. + return rtw_set_wps_probe_resp_ie(priv,
  350. + proberesp ? wpabuf_head(proberesp) : NULL,
  351. + proberesp ? wpabuf_len(proberesp): 0);
  352. +
  353. +}
  354. +#endif
  355. +
  356. +
  357. static void *
  358. bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
  359. {
  360. @@ -854,6 +1150,12 @@ bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
  361. goto bad;
  362. }
  363.  
  364. +#ifdef CONFIG_SUPPORT_RTW_DRIVER
  365. + /* mark up after init */
  366. + if (bsd_ctrl_iface(drv, 1) < 0)
  367. + goto bad;
  368. +#endif
  369. +
  370. return drv;
  371. bad:
  372. if (drv->sock_xmit != NULL)
  373. @@ -1292,6 +1594,15 @@ wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx)
  374. event.interface_status.ifname);
  375. wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
  376. }
  377. + else{
  378. + os_strlcpy(event.interface_status.ifname, drv->ifname,
  379. + sizeof(event.interface_status.ifname));
  380. + event.interface_status.ievent = EVENT_INTERFACE_ADDED;
  381. + wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' UP",
  382. + event.interface_status.ifname);
  383. + wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
  384. + }
  385. +
  386. break;
  387. }
  388. }
  389. @@ -1609,7 +1920,52 @@ wpa_driver_bsd_get_capa(void *priv, struct wpa_driver_capa *capa)
  390. }
  391. #endif /* HOSTAPD */
  392.  
  393. -
  394. +#ifdef CONFIG_SUPPORT_RTW_DRIVER
  395. +const struct wpa_driver_ops wpa_driver_bsd_ops = {
  396. + .name = "bsd",
  397. + .desc = "BSD 802.11 support",
  398. +#ifdef HOSTAPD
  399. + .hapd_init = bsd_init,
  400. + .hapd_deinit = bsd_deinit,
  401. + .set_privacy = bsd_set_privacy,//del ?
  402. + .get_seqnum = bsd_get_seqnum,//del ?
  403. + .flush = bsd_flush,
  404. + .read_sta_data = bsd_read_sta_driver_data,//del ?
  405. + .sta_disassoc = bsd_sta_disassoc,
  406. + .sta_deauth = bsd_sta_deauth,
  407. + .get_hw_feature_data = rtw_get_hw_feature_data_ops,//add
  408. + //.sta_remove = rtl871x_sta_remove_ops,//add
  409. + .set_beacon = rtw_set_beacon_ops, //add
  410. + .set_ap_wps_ie = rtw_set_ap_wps_ie_ops,//add
  411. +#else /* HOSTAPD */
  412. + .init = wpa_driver_bsd_init,
  413. + .deinit = wpa_driver_bsd_deinit,
  414. + .get_bssid = wpa_driver_bsd_get_bssid,
  415. + .get_ssid = wpa_driver_bsd_get_ssid,
  416. + .set_countermeasures = wpa_driver_bsd_set_countermeasures,
  417. + .scan2 = wpa_driver_bsd_scan,
  418. + .get_scan_results2 = wpa_driver_bsd_get_scan_results2,
  419. + .deauthenticate = wpa_driver_bsd_deauthenticate,
  420. + .disassociate = wpa_driver_bsd_disassociate,
  421. + .associate = wpa_driver_bsd_associate,
  422. + .get_capa = wpa_driver_bsd_get_capa,
  423. + .set_freq = bsd_set_freq, //only for wpa_supplicant
  424. + .set_ieee8021x = bsd_set_ieee8021x,//only for wpa_supplicant
  425. + .hapd_set_ssid = bsd_set_ssid,//only for wpa_supplicant
  426. + .hapd_get_ssid = bsd_get_ssid,//only for wpa_supplicant
  427. + .sta_set_flags = bsd_set_sta_authorized, //only for wpa_supplicant
  428. + .set_generic_elem = bsd_set_opt_ie, //only for wpa_supplicant
  429. +#endif /* HOSTAPD */
  430. + //.set_freq = bsd_set_freq, //only for wpa_supplicant
  431. + .set_key = bsd_set_key,
  432. + //.set_ieee8021x = bsd_set_ieee8021x, //only for wpa_supplicant
  433. + //.hapd_set_ssid = bsd_set_ssid, //only for wpa_supplicant
  434. + //.hapd_get_ssid = bsd_get_ssid, //only for wpa_supplicant
  435. + .hapd_send_eapol = bsd_send_eapol, //only for wpa_supplicant
  436. + //.sta_set_flags = bsd_set_sta_authorized, //only for wpa_supplicant
  437. + //.set_generic_elem = bsd_set_opt_ie, //only for wpa_supplicant
  438. +};
  439. +#else
  440. const struct wpa_driver_ops wpa_driver_bsd_ops = {
  441. .name = "bsd",
  442. .desc = "BSD 802.11 support",
  443. @@ -1644,3 +2000,4 @@ const struct wpa_driver_ops wpa_driver_bsd_ops = {
  444. .hapd_send_eapol = bsd_send_eapol,
  445. .set_generic_elem = bsd_set_opt_ie,
  446. };
  447. +#endif
  448. diff --git a/src/drivers/driver_rtl.h b/src/drivers/driver_rtl.h
  449. new file mode 100644
  450. index 0000000..c5ee335
  451. --- /dev/null
  452. +++ b/src/drivers/driver_rtl.h
  453. @@ -0,0 +1,114 @@
  454. +
  455. +#ifndef _DRIVER_RTL_H_
  456. +#define _DRIVER_RTL_H_
  457. +
  458. +
  459. +#define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
  460. +
  461. +#define IEEE_CRYPT_ALG_NAME_LEN (16)
  462. +
  463. +/* RTL871X_IOCTL_HOSTAPD ioctl() cmd: */
  464. +enum {
  465. + RTL871X_HOSTAPD_FLUSH = 1,
  466. + RTL871X_HOSTAPD_ADD_STA = 2,
  467. + RTL871X_HOSTAPD_REMOVE_STA = 3,
  468. + RTL871X_HOSTAPD_GET_INFO_STA = 4,
  469. + /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
  470. + RTL871X_HOSTAPD_GET_WPAIE_STA = 5,
  471. + RTL871X_SET_ENCRYPTION = 6,
  472. + RTL871X_GET_ENCRYPTION = 7,
  473. + RTL871X_HOSTAPD_SET_FLAGS_STA = 8,
  474. + RTL871X_HOSTAPD_GET_RID = 9,
  475. + RTL871X_HOSTAPD_SET_RID = 10,
  476. + RTL871X_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
  477. + RTL871X_HOSTAPD_SET_GENERIC_ELEMENT = 12,
  478. + RTL871X_HOSTAPD_MLME = 13,
  479. + RTL871X_HOSTAPD_SCAN_REQ = 14,
  480. + RTL871X_HOSTAPD_STA_CLEAR_STATS = 15,
  481. + RTL871X_HOSTAPD_SET_BEACON = 16,
  482. + RTL871X_HOSTAPD_SET_WPS_BEACON = 17,
  483. + RTL871X_HOSTAPD_SET_WPS_PROBE_RESP = 18,
  484. + RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP = 19,
  485. + RTL871X_HOSTAPD_SET_HIDDEN_SSID = 20,
  486. +};
  487. +
  488. +typedef struct ieee_param {
  489. + u32 cmd;
  490. + u8 sta_addr[ETH_ALEN];
  491. + union {
  492. + struct {
  493. + u8 name;
  494. + u32 value;
  495. + } wpa_param;
  496. + struct {
  497. + u32 len;
  498. + u8 reserved[32];
  499. + u8 data[0];
  500. + } wpa_ie;
  501. + struct{
  502. + int command;
  503. + int reason_code;
  504. + } mlme;
  505. + struct {
  506. + u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
  507. + u8 set_tx;
  508. + u32 err;
  509. + u8 idx;
  510. + u8 seq[8]; /* sequence counter (set: RX, get: TX) */
  511. + u16 key_len;
  512. + u8 key[0];
  513. + } crypt;
  514. + struct {
  515. + u16 aid;
  516. + u16 capability;
  517. + int flags;
  518. + u8 tx_supp_rates[16];
  519. + //struct ieee80211_ht_capability ht_cap;
  520. + struct ieee80211_ht_capabilities ht_cap;
  521. + } add_sta;
  522. + struct {
  523. + u8 reserved[2];//for set max_num_sta
  524. + u8 buf[0];
  525. + } bcn_ie;
  526. +
  527. + } u;
  528. +
  529. +} ieee_param;
  530. +
  531. +
  532. +
  533. +#define IEEE80211_CCK_RATE_LEN 4
  534. +#define IEEE80211_OFDM_RATE_LEN 8
  535. +
  536. +#define IEEE80211_CCK_RATE_1MB 0x02
  537. +#define IEEE80211_CCK_RATE_2MB 0x04
  538. +#define IEEE80211_CCK_RATE_5MB 0x0B
  539. +#define IEEE80211_CCK_RATE_11MB 0x16
  540. +#define IEEE80211_OFDM_RATE_6MB 0x0C
  541. +#define IEEE80211_OFDM_RATE_9MB 0x12
  542. +#define IEEE80211_OFDM_RATE_12MB 0x18
  543. +#define IEEE80211_OFDM_RATE_18MB 0x24
  544. +#define IEEE80211_OFDM_RATE_24MB 0x30
  545. +#define IEEE80211_OFDM_RATE_36MB 0x48
  546. +#define IEEE80211_OFDM_RATE_48MB 0x60
  547. +#define IEEE80211_OFDM_RATE_54MB 0x6C
  548. +#define IEEE80211_BASIC_RATE_MASK 0x80
  549. +
  550. +#define IEEE80211_CCK_RATE_1MB_MASK (1<<0)
  551. +#define IEEE80211_CCK_RATE_2MB_MASK (1<<1)
  552. +#define IEEE80211_CCK_RATE_5MB_MASK (1<<2)
  553. +#define IEEE80211_CCK_RATE_11MB_MASK (1<<3)
  554. +#define IEEE80211_OFDM_RATE_6MB_MASK (1<<4)
  555. +#define IEEE80211_OFDM_RATE_9MB_MASK (1<<5)
  556. +#define IEEE80211_OFDM_RATE_12MB_MASK (1<<6)
  557. +#define IEEE80211_OFDM_RATE_18MB_MASK (1<<7)
  558. +#define IEEE80211_OFDM_RATE_24MB_MASK (1<<8)
  559. +#define IEEE80211_OFDM_RATE_36MB_MASK (1<<9)
  560. +#define IEEE80211_OFDM_RATE_48MB_MASK (1<<10)
  561. +#define IEEE80211_OFDM_RATE_54MB_MASK (1<<11)
  562. +
  563. +#define IEEE80211_CCK_RATES_MASK 0x0000000F
  564. +#define IEEE80211_OFDM_RATES_MASK 0x00000FF0
  565. +
  566. +#endif
  567. +
  568. diff --git a/src/drivers/driver_rtw.c b/src/drivers/driver_rtw.c
  569. new file mode 100644
  570. index 0000000..cbee5d2
  571. --- /dev/null
  572. +++ b/src/drivers/driver_rtw.c
  573. @@ -0,0 +1,1993 @@
  574. +/*
  575. + * hostapd / Driver interface for rtl871x driver
  576. + * Copyright (c) 2010,
  577. + *
  578. + * This program is free software; you can redistribute it and/or modify
  579. + * it under the terms of the GNU General Public License version 2 as
  580. + * published by the Free Software Foundation.
  581. + *
  582. + * Alternatively, this software may be distributed under the terms of BSD
  583. + * license.
  584. + *
  585. + * See README and COPYING for more details.
  586. + */
  587. +
  588. +//#define CONFIG_MGNT_L2SOCK 1
  589. +#define CONFIG_MLME_OFFLOAD 1
  590. +
  591. +
  592. +#include "includes.h"
  593. +#include <net/if.h>
  594. +#include <sys/ioctl.h>
  595. +
  596. +#include "common.h"
  597. +
  598. +/*#include "wireless_copy.h"*/
  599. +#include "linux_wext.h"
  600. +
  601. +#include "driver.h"
  602. +#include "eloop.h"
  603. +#include "priv_netlink.h"
  604. +#include "l2_packet/l2_packet.h"
  605. +#include "common/ieee802_11_defs.h"
  606. +#include "netlink.h"
  607. +#include "linux_ioctl.h"
  608. +
  609. +//#include "../src/ap/hostapd.h"
  610. +//#include "../src/ap/ap_config.h"
  611. +#include "ap/hostapd.h"
  612. +#include "ap/ap_config.h"
  613. +
  614. +#ifdef USE_KERNEL_HEADERS
  615. +/* compat-wireless does not include linux/compiler.h to define __user, so
  616. + * define it here */
  617. +#ifndef __user
  618. +#define __user
  619. +#endif /* __user */
  620. +#include <asm/types.h>
  621. +#include <linux/if_packet.h>
  622. +#include <linux/if_ether.h> /* The L2 protocols */
  623. +#include <linux/if_arp.h>
  624. +#include <linux/wireless.h>
  625. +#else /* USE_KERNEL_HEADERS */
  626. +#include <net/if_arp.h>
  627. +#include <netpacket/packet.h>
  628. +//#include "wireless_copy.h"
  629. +#endif /* USE_KERNEL_HEADERS */
  630. +
  631. +//#include <net/if.h>
  632. +
  633. +
  634. +#ifndef ETH_P_80211_RAW
  635. +#define ETH_P_80211_RAW 0x0019
  636. +#endif
  637. +
  638. +#if 0
  639. +#include "hostapd.h"
  640. +#include "driver.h"
  641. +#include "ieee802_1x.h"
  642. +#include "eloop.h"
  643. +#include "priv_netlink.h"
  644. +#include "sta_info.h"
  645. +#include "l2_packet/l2_packet.h"
  646. +
  647. +#include "wpa.h"
  648. +#include "accounting.h"
  649. +#include "ieee802_11.h"
  650. +#include "hw_features.h"
  651. +#include "radius/radius.h"
  652. +#endif
  653. +
  654. +#include "driver_rtl.h"
  655. +
  656. +
  657. +//static int rtl871x_sta_remove_ops(void *priv, const u8 *addr);
  658. +
  659. +struct rtl871x_driver_data {
  660. + struct hostapd_data *hapd;
  661. +
  662. + char iface[IFNAMSIZ + 1];
  663. + int ifindex;
  664. + struct l2_packet_data *l2_sock;/* socket for sending eapol frames*/
  665. + struct l2_packet_data *l2_sock_recv;/* raw packet recv socket from bridge interface*/
  666. +#ifdef CONFIG_MGNT_L2SOCK
  667. + struct l2_packet_data *mgnt_l2_sock; /* socket for tx/rx management frames*/
  668. +#else
  669. + int mgnt_sock;/* socket for tx/rx management frames*/
  670. +#endif
  671. + int ioctl_sock; /* socket for ioctl() use */
  672. + int wext_sock; /* socket for wireless events */
  673. +
  674. + struct netlink_data *netlink;
  675. +
  676. + int we_version;
  677. +
  678. + u8 hw_mac[ETH_ALEN];
  679. +
  680. + u8 acct_mac[ETH_ALEN];
  681. +
  682. + struct hostap_sta_driver_data acct_data;
  683. +
  684. +};
  685. +
  686. +/*
  687. +static const char *ether_sprintf(const u8 *addr)
  688. +{
  689. + static char buf[sizeof(MACSTR)];
  690. +
  691. + if (addr != NULL)
  692. + snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
  693. + else
  694. + snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
  695. +
  696. + return buf;
  697. +}
  698. +*/
  699. +
  700. +#ifndef CONFIG_MLME_OFFLOAD
  701. +static int rtl871x_set_iface_flags(void *priv, int dev_up)
  702. +{
  703. + struct rtl871x_driver_data *drv = priv;
  704. + struct ifreq ifr;
  705. +
  706. + wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up);
  707. +
  708. + if (drv->mgnt_sock < 0)
  709. + return -1;
  710. +
  711. + memset(&ifr, 0, sizeof(ifr));
  712. + //os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
  713. + //os_strlcpy(ifr.ifr_name, "mgnt.wlan", IFNAMSIZ);
  714. + snprintf(ifr.ifr_name, IFNAMSIZ, "mgnt.%s", "wlan0");
  715. +
  716. + if (ioctl(drv->mgnt_sock, SIOCGIFFLAGS, &ifr) != 0) {
  717. + perror("ioctl[SIOCGIFFLAGS]");
  718. + return -1;
  719. + }
  720. +
  721. + if (dev_up)
  722. + ifr.ifr_flags |= IFF_UP;
  723. + else
  724. + ifr.ifr_flags &= ~IFF_UP;
  725. +
  726. + if (ioctl(drv->mgnt_sock, SIOCSIFFLAGS, &ifr) != 0) {
  727. + perror("ioctl[SIOCSIFFLAGS]");
  728. + return -1;
  729. + }
  730. +
  731. +#if 0
  732. + if (dev_up) {
  733. + memset(&ifr, 0, sizeof(ifr));
  734. + os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
  735. + ifr.ifr_mtu = HOSTAPD_MTU;
  736. + if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
  737. + perror("ioctl[SIOCSIFMTU]");
  738. + printf("Setting MTU failed - trying to survive with "
  739. + "current value\n");
  740. + }
  741. + }
  742. +#endif
  743. +
  744. + return 0;
  745. +}
  746. +#endif
  747. +
  748. +static int rtl871x_hostapd_ioctl(struct rtl871x_driver_data *drv, ieee_param *param, int len)
  749. +{
  750. + struct iwreq iwr;
  751. +
  752. + memset(&iwr, 0, sizeof(iwr));
  753. + os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  754. + iwr.u.data.pointer = (caddr_t) param;
  755. + iwr.u.data.length = len;
  756. +
  757. + if (ioctl(drv->ioctl_sock, RTL_IOCTL_HOSTAPD, &iwr) < 0) {
  758. + perror("ioctl[RTL_IOCTL_HOSTAPD]");
  759. + return -1;
  760. + }
  761. +
  762. + return 0;
  763. +}
  764. +
  765. +static int rtl871x_set_mode(struct rtl871x_driver_data *drv, u32 mode)
  766. +{
  767. + struct iwreq iwr;
  768. +
  769. + if (drv->ioctl_sock < 0)
  770. + return -1;
  771. +
  772. + memset(&iwr, 0, sizeof(iwr));
  773. +
  774. + os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  775. +
  776. + //iwr.u.mode = IW_MODE_MASTER;
  777. + iwr.u.mode = mode;
  778. +
  779. + if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
  780. + perror("ioctl[SIOCSIWMODE]");
  781. + printf("Could not set interface to mode(%d)!\n", mode);
  782. + return -1;
  783. + }
  784. +
  785. + return 0;
  786. +
  787. +}
  788. +
  789. +/*
  790. +static int rtl871x_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  791. + const u8 *ie, size_t ielen)
  792. +{
  793. + struct sta_info *sta;
  794. + int new_assoc, res;
  795. +
  796. + //hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  797. + // HOSTAPD_LEVEL_INFO, "associated");
  798. +
  799. + sta = ap_get_sta(hapd, addr);
  800. + if (sta) {
  801. + accounting_sta_stop(hapd, sta);
  802. + } else {
  803. + sta = ap_sta_add(hapd, addr);
  804. + if (sta == NULL)
  805. + {
  806. + rtl871x_sta_remove_ops(hapd->drv_priv, addr);
  807. + return -1;
  808. + }
  809. + }
  810. + sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
  811. +
  812. + if (hapd->conf->wpa) {
  813. + if (ie == NULL || ielen == 0) {
  814. + if (hapd->conf->wps_state) {
  815. + wpa_printf(MSG_DEBUG, "STA did not include "
  816. + "WPA/RSN IE in (Re)Association "
  817. + "Request - possible WPS use");
  818. + sta->flags |= WLAN_STA_MAYBE_WPS;
  819. + goto skip_wpa_check;
  820. + }
  821. +
  822. + wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
  823. + return -1;
  824. + }
  825. + if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
  826. + os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
  827. + sta->flags |= WLAN_STA_WPS;
  828. + goto skip_wpa_check;
  829. + }
  830. +
  831. + if (sta->wpa_sm == NULL)
  832. + sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  833. + sta->addr);
  834. + if (sta->wpa_sm == NULL) {
  835. + wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
  836. + "machine");
  837. + return -1;
  838. + }
  839. + res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  840. + ie, ielen, NULL, 0);
  841. + if (res != WPA_IE_OK) {
  842. + wpa_printf(MSG_DEBUG, "WPA/RSN information element "
  843. + "rejected? (res %u)", res);
  844. + wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
  845. + return -1;
  846. + }
  847. + } else if (hapd->conf->wps_state) {
  848. + if (ie && ielen > 4 && ie[0] == 0xdd && ie[1] >= 4 &&
  849. + os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
  850. + sta->flags |= WLAN_STA_WPS;
  851. + } else
  852. + sta->flags |= WLAN_STA_MAYBE_WPS;
  853. + }
  854. +skip_wpa_check:
  855. +
  856. + new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
  857. + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
  858. + wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  859. +
  860. + hostapd_new_assoc_sta(hapd, sta, !new_assoc);
  861. +
  862. + ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  863. +
  864. + return 0;
  865. +}
  866. +*/
  867. +
  868. +static int rtl871x_get_sta_wpaie(struct rtl871x_driver_data *drv, u8 *iebuf, u8 *addr)
  869. +{
  870. + struct ieee_param param;
  871. +
  872. + printf("+%s, " MACSTR " is sta's address\n", __func__, MAC2STR(addr));
  873. +
  874. + memset(&param, 0, sizeof(param));
  875. +
  876. + param.cmd = RTL871X_HOSTAPD_GET_WPAIE_STA;
  877. +
  878. + memcpy(param.sta_addr, addr, ETH_ALEN);
  879. +
  880. + if (rtl871x_hostapd_ioctl(drv, &param, sizeof(param))) {
  881. + printf("Could not get sta wpaie from kernel driver.\n");
  882. + return -1;
  883. + }
  884. +
  885. +
  886. + if(param.u.wpa_ie.len > 32)
  887. + return -1;
  888. +
  889. + memcpy(iebuf, param.u.wpa_ie.reserved, param.u.wpa_ie.len);
  890. +
  891. + return 0;
  892. +
  893. +}
  894. +
  895. +static int rtl871x_del_sta(struct rtl871x_driver_data *drv, u8 *addr)
  896. +{
  897. + struct hostapd_data *hapd = drv->hapd;
  898. +
  899. +#if 1
  900. +
  901. + //union wpa_event_data event;
  902. + //os_memset(&event, 0, sizeof(event));
  903. + //event.disassoc_info.addr = addr;
  904. + //wpa_supplicant_event(hapd, EVENT_DISASSOC, &event);
  905. +
  906. + drv_event_disassoc(hapd, addr);
  907. +
  908. +#else
  909. +
  910. + struct sta_info *sta;
  911. +
  912. + //hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  913. + // HOSTAPD_LEVEL_INFO, "disassociated");
  914. +
  915. + sta = ap_get_sta(hapd, addr);
  916. + if (sta != NULL)
  917. + {
  918. + sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  919. + wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  920. + sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  921. + ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  922. + ap_free_sta(hapd, sta);
  923. + }
  924. + else
  925. + {
  926. + wpa_printf(MSG_DEBUG, "Disassociation notification for "
  927. + "unknown STA " MACSTR, MAC2STR(addr));
  928. + }
  929. +#endif
  930. +
  931. + return 0;
  932. +
  933. +}
  934. +
  935. +static int rtl871x_new_sta(struct rtl871x_driver_data *drv, u8 *addr)
  936. +{
  937. + struct hostapd_data *hapd = drv->hapd;
  938. + //struct ieee80211req_wpaie ie;
  939. + int ielen = 0, res=0;
  940. + //u8 *iebuf = NULL;
  941. + u8 iebuf[32], *piebuf=NULL;
  942. +
  943. + /*
  944. + * Fetch negotiated WPA/RSN parameters from the driver.
  945. + */
  946. + //memset(&ie, 0, sizeof(ie));
  947. + //memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
  948. + memset(iebuf, 0 , sizeof(iebuf));
  949. + if (rtl871x_get_sta_wpaie(drv, iebuf, addr)) {
  950. + //if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
  951. +
  952. + wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
  953. + __func__, strerror(errno));
  954. + goto no_ie;
  955. + }
  956. +
  957. + //wpa_hexdump(MSG_MSGDUMP, "req WPA IE",
  958. + // ie.wpa_ie, IEEE80211_MAX_OPT_IE);
  959. +
  960. + //wpa_hexdump(MSG_MSGDUMP, "req RSN IE",
  961. + // ie.rsn_ie, IEEE80211_MAX_OPT_IE);
  962. +
  963. + //iebuf = ie.wpa_ie;
  964. +
  965. +/*
  966. + if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
  967. + iebuf[1] = 0;
  968. + if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
  969. + iebuf = ie.rsn_ie;
  970. + if (iebuf[0] != WLAN_EID_RSN)
  971. + iebuf[1] = 0;
  972. + }
  973. +*/
  974. +
  975. + if ((iebuf[0] == WLAN_EID_VENDOR_SPECIFIC) || (iebuf[0] == WLAN_EID_RSN) )
  976. + {
  977. + piebuf = iebuf;
  978. + ielen = iebuf[1];
  979. +
  980. + if (ielen == 0)
  981. + piebuf = NULL;
  982. + else
  983. + ielen += 2;
  984. + }
  985. +
  986. +no_ie:
  987. +
  988. + //res = rtl871x_notif_assoc(hapd, addr, piebuf, ielen);
  989. + //drv_event_assoc(hapd, addr, piebuf, ielen);
  990. + drv_event_assoc(hapd, addr, piebuf, ielen, 0);
  991. +
  992. + if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
  993. + /* Cached accounting data is not valid anymore. */
  994. + memset(drv->acct_mac, 0, ETH_ALEN);
  995. + memset(&drv->acct_data, 0, sizeof(drv->acct_data));
  996. + }
  997. +
  998. + return res;
  999. +
  1000. +}
  1001. +
  1002. +static void rtl871x_wireless_event_wireless(struct rtl871x_driver_data *drv,
  1003. + char *data, int len)
  1004. +{
  1005. + struct iw_event iwe_buf, *iwe = &iwe_buf;
  1006. + char *pos, *end, *custom, *buf;
  1007. +
  1008. + pos = data;
  1009. + end = data + len;
  1010. +
  1011. + while (pos + IW_EV_LCP_LEN <= end) {
  1012. + /* Event data may be unaligned, so make a local, aligned copy
  1013. + * before processing. */
  1014. + memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
  1015. + wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
  1016. + iwe->cmd, iwe->len);
  1017. + if (iwe->len <= IW_EV_LCP_LEN)
  1018. + return;
  1019. +
  1020. + custom = pos + IW_EV_POINT_LEN;
  1021. + if (drv->we_version > 18 &&
  1022. + (iwe->cmd == IWEVMICHAELMICFAILURE ||
  1023. + iwe->cmd == IWEVCUSTOM)) {
  1024. + /* WE-19 removed the pointer from struct iw_point */
  1025. + char *dpos = (char *) &iwe_buf.u.data.length;
  1026. + int dlen = dpos - (char *) &iwe_buf;
  1027. + memcpy(dpos, pos + IW_EV_LCP_LEN,
  1028. + sizeof(struct iw_event) - dlen);
  1029. + } else {
  1030. + memcpy(&iwe_buf, pos, sizeof(struct iw_event));
  1031. + custom += IW_EV_POINT_OFF;
  1032. + }
  1033. +
  1034. + //printf("got wireless event, iwe->cmd=%d\n", iwe->cmd);
  1035. +
  1036. + switch (iwe->cmd) {
  1037. + case IWEVEXPIRED:
  1038. + rtl871x_del_sta(drv, (u8 *)iwe->u.addr.sa_data);
  1039. + break;
  1040. + case IWEVREGISTERED:
  1041. + if(rtl871x_new_sta(drv, (u8 *)iwe->u.addr.sa_data))
  1042. + {
  1043. + printf("Failed to add new sta: "MACSTR" \n", MAC2STR((u8 *)iwe->u.addr.sa_data));
  1044. + }
  1045. + break;
  1046. + case IWEVCUSTOM:
  1047. + if (custom + iwe->u.data.length > end)
  1048. + return;
  1049. + buf = malloc(iwe->u.data.length + 1);
  1050. + if (buf == NULL)
  1051. + return; /* XXX */
  1052. + memcpy(buf, custom, iwe->u.data.length);
  1053. + buf[iwe->u.data.length] = '\0';
  1054. + //madwifi_wireless_event_wireless_custom(drv, buf);
  1055. + free(buf);
  1056. + break;
  1057. + }
  1058. +
  1059. + pos += iwe->len;
  1060. + }
  1061. +
  1062. +}
  1063. +
  1064. +#if 1
  1065. +static void rtl871x_wireless_event_rtm_newlink(void *ctx,
  1066. + struct ifinfomsg *ifi, u8 *buf, size_t len)
  1067. +{
  1068. + struct rtl871x_driver_data *drv = ctx;
  1069. + int attrlen, rta_len;
  1070. + struct rtattr *attr;
  1071. +
  1072. + if (ifi->ifi_index != drv->ifindex)
  1073. + return;
  1074. +
  1075. + attrlen = len;
  1076. + attr = (struct rtattr *) buf;
  1077. +
  1078. + rta_len = RTA_ALIGN(sizeof(struct rtattr));
  1079. + while (RTA_OK(attr, attrlen)) {
  1080. + if (attr->rta_type == IFLA_WIRELESS) {
  1081. + rtl871x_wireless_event_wireless(
  1082. + drv, ((char *) attr) + rta_len,
  1083. + attr->rta_len - rta_len);
  1084. + }
  1085. + attr = RTA_NEXT(attr, attrlen);
  1086. + }
  1087. +}
  1088. +
  1089. +#else
  1090. +static void rtl871x_wireless_event_rtm_newlink(struct rtl871x_driver_data *drv,
  1091. + struct nlmsghdr *h, int len)
  1092. +{
  1093. + struct ifinfomsg *ifi;
  1094. + int attrlen, nlmsg_len, rta_len;
  1095. + struct rtattr * attr;
  1096. +
  1097. + if (len < (int) sizeof(*ifi))
  1098. + return;
  1099. +
  1100. + ifi = NLMSG_DATA(h);
  1101. +
  1102. + if (ifi->ifi_index != drv->ifindex)
  1103. + return;
  1104. +
  1105. + nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
  1106. +
  1107. + attrlen = h->nlmsg_len - nlmsg_len;
  1108. + if (attrlen < 0)
  1109. + return;
  1110. +
  1111. + attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
  1112. +
  1113. + rta_len = RTA_ALIGN(sizeof(struct rtattr));
  1114. + while (RTA_OK(attr, attrlen)) {
  1115. + if (attr->rta_type == IFLA_WIRELESS) {
  1116. + rtl871x_wireless_event_wireless(
  1117. + drv, ((char *) attr) + rta_len,
  1118. + attr->rta_len - rta_len);
  1119. + }
  1120. + attr = RTA_NEXT(attr, attrlen);
  1121. + }
  1122. +}
  1123. +#endif
  1124. +
  1125. +/*
  1126. +static void rtl871x_wireless_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
  1127. +{
  1128. + char buf[256];//!!!
  1129. + int left;
  1130. + struct sockaddr_nl from;
  1131. + socklen_t fromlen;
  1132. + struct nlmsghdr *h;
  1133. + struct rtl871x_driver_data *drv = eloop_ctx;
  1134. +
  1135. + //printf("+rtl871x_wireless_event_receive\n");
  1136. +
  1137. + fromlen = sizeof(from);
  1138. + left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
  1139. + (struct sockaddr *) &from, &fromlen);
  1140. + if (left < 0) {
  1141. + if (errno != EINTR && errno != EAGAIN)
  1142. + perror("recvfrom(netlink)");
  1143. + return;
  1144. + }
  1145. +
  1146. + h = (struct nlmsghdr *)buf;
  1147. + while (left >= (int) sizeof(*h)) {
  1148. + int len, plen;
  1149. +
  1150. + len = h->nlmsg_len;
  1151. + plen = len - sizeof(*h);//payload len
  1152. + if (len > left || plen < 0) {
  1153. + printf("Malformed netlink message: "
  1154. + "len=%d left=%d plen=%d\n",
  1155. + len, left, plen);
  1156. + break;
  1157. + }
  1158. +
  1159. + switch (h->nlmsg_type) {
  1160. + case RTM_NEWLINK:
  1161. + rtl871x_wireless_event_rtm_newlink(drv, h, plen);
  1162. + break;
  1163. + }
  1164. +
  1165. + len = NLMSG_ALIGN(len);
  1166. + left -= len;
  1167. + h = (struct nlmsghdr *) ((char *) h + len);
  1168. + }
  1169. +
  1170. + if (left > 0) {
  1171. + printf("%d extra bytes in the end of netlink message\n", left);
  1172. + }
  1173. +
  1174. +}
  1175. +*/
  1176. +
  1177. +static int rtl871x_wireless_event_init(struct rtl871x_driver_data *drv)
  1178. +{
  1179. + struct netlink_config *cfg;
  1180. +
  1181. + //madwifi_get_we_version(drv);
  1182. +
  1183. + cfg = os_zalloc(sizeof(*cfg));
  1184. + if (cfg == NULL)
  1185. + return -1;
  1186. + cfg->ctx = drv;
  1187. + cfg->newlink_cb = rtl871x_wireless_event_rtm_newlink;
  1188. + drv->netlink = netlink_init(cfg);
  1189. + if (drv->netlink == NULL) {
  1190. + os_free(cfg);
  1191. + return -1;
  1192. + }
  1193. +
  1194. + return 0;
  1195. +}
  1196. +
  1197. +/*
  1198. +static int rtl871x_wireless_event_init_ops(void *priv)
  1199. +{
  1200. + int s;
  1201. + struct sockaddr_nl local;
  1202. + struct rtl871x_driver_data *drv = priv;
  1203. +
  1204. + //madwifi_get_we_version(drv);
  1205. +
  1206. + drv->wext_sock = -1;
  1207. +
  1208. + s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  1209. + if (s < 0) {
  1210. + perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
  1211. + return -1;
  1212. + }
  1213. +
  1214. + memset(&local, 0, sizeof(local));
  1215. + local.nl_family = AF_NETLINK;
  1216. + local.nl_groups = RTMGRP_LINK;
  1217. + if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
  1218. + perror("bind(netlink)");
  1219. + close(s);
  1220. + return -1;
  1221. + }
  1222. +
  1223. + eloop_register_read_sock(s, rtl871x_wireless_event_receive, drv, NULL);
  1224. + drv->wext_sock = s;
  1225. +
  1226. + return 0;
  1227. +
  1228. +}
  1229. +
  1230. +static void rtl871x_wireless_event_deinit_ops(void *priv)
  1231. +{
  1232. + struct rtl871x_driver_data *drv = priv;
  1233. +
  1234. + if (drv != NULL) {
  1235. + if (drv->wext_sock < 0)
  1236. + return;
  1237. + eloop_unregister_read_sock(drv->wext_sock);
  1238. + close(drv->wext_sock);
  1239. + }
  1240. +}
  1241. +*/
  1242. +
  1243. +#if 1
  1244. +static void rtl871x_handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
  1245. +{
  1246. + struct rtl871x_driver_data *drv = ctx;
  1247. + drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
  1248. + len - sizeof(struct l2_ethhdr));
  1249. +}
  1250. +#else
  1251. +static void rtl871x_handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
  1252. +{
  1253. + struct rtl871x_driver_data *drv = ctx;
  1254. + struct hostapd_data *hapd = drv->hapd;
  1255. + struct sta_info *sta;
  1256. +
  1257. + sta = ap_get_sta(hapd, src_addr);
  1258. + if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
  1259. + printf("Data frame from not associated STA %s\n",
  1260. + ether_sprintf(src_addr));
  1261. + /* XXX cannot happen */
  1262. + return;
  1263. + }
  1264. + ieee802_1x_receive(hapd, src_addr, buf + sizeof(struct l2_ethhdr),
  1265. + len - sizeof(struct l2_ethhdr));
  1266. +}
  1267. +#endif
  1268. +
  1269. +static int rtl871x_send_eapol_ops(void *priv, const u8 *addr, const u8 *data, size_t data_len,
  1270. + int encrypt, const u8 *own_addr, u32 flags)
  1271. +{
  1272. + struct rtl871x_driver_data *drv = priv;
  1273. + unsigned char buf[3000];
  1274. + unsigned char *bp = buf;
  1275. + struct l2_ethhdr *eth;
  1276. + size_t len;
  1277. + int status;
  1278. +
  1279. + printf("+rtl871x_send_eapol\n");
  1280. +
  1281. + /*
  1282. + * Prepend the Ethernet header. If the caller left us
  1283. + * space at the front we could just insert it but since
  1284. + * we don't know we copy to a local buffer. Given the frequency
  1285. + * and size of frames this probably doesn't matter.
  1286. + */
  1287. + len = data_len + sizeof(struct l2_ethhdr);
  1288. + if (len > sizeof(buf)) {
  1289. + bp = malloc(len);
  1290. + if (bp == NULL) {
  1291. + printf("EAPOL frame discarded, cannot malloc temp "
  1292. + "buffer of size %lu!\n", (unsigned long) len);
  1293. + return -1;
  1294. + }
  1295. + }
  1296. +
  1297. + eth = (struct l2_ethhdr *) bp;
  1298. + memcpy(eth->h_dest, addr, ETH_ALEN);
  1299. + memcpy(eth->h_source, own_addr, ETH_ALEN);
  1300. + eth->h_proto = htons(ETH_P_EAPOL);
  1301. + memcpy(eth+1, data, data_len);
  1302. +
  1303. + wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
  1304. +
  1305. + status = l2_packet_send(drv->l2_sock, addr, ETH_P_EAPOL, bp, len);
  1306. +
  1307. + if (bp != buf)
  1308. + free(bp);
  1309. +
  1310. + return status;
  1311. +
  1312. +}
  1313. +
  1314. +#ifndef CONFIG_MLME_OFFLOAD
  1315. +static void rtl871x_receive_mgnt(struct rtl871x_driver_data *drv , const u8 *buf, size_t len)
  1316. +{
  1317. + const struct ieee80211_mgmt *mgmt;
  1318. + //const u8 *end, *ie;
  1319. + u16 fc, type, stype;
  1320. + //size_t ie_len;
  1321. + struct hostapd_data *hapd = drv->hapd;
  1322. +
  1323. + //printf("+rtl871x_receive_mgnt, " MACSTR " is our address\n", MAC2STR(hapd->own_addr));
  1324. +
  1325. +
  1326. +#if 0
  1327. + {
  1328. + int i;
  1329. + for(i=0; i<len; i+=8)
  1330. + {
  1331. + printf("%x:%x:%x:%x:%x:%x:%x:%x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]);
  1332. + }
  1333. +
  1334. + }
  1335. +#endif
  1336. +
  1337. + if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
  1338. + return;
  1339. +
  1340. + mgmt = (const struct ieee80211_mgmt *)buf;
  1341. +
  1342. + fc = le_to_host16(mgmt->frame_control);
  1343. + type = WLAN_FC_GET_TYPE(fc);
  1344. + stype = WLAN_FC_GET_STYPE(fc);
  1345. +
  1346. +#if 1
  1347. + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  1348. + WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP)
  1349. + {
  1350. + //printf("MGNT Frame - PROBE_RESP Frame\n");
  1351. + }
  1352. +#endif
  1353. +
  1354. + //end = buf + len;
  1355. + //ie = mgmt->u.probe_req.variable;
  1356. + //ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
  1357. + //hostapd_wps_probe_req_rx(drv->hapd, mgmt->sa, ie, ie_len);
  1358. +
  1359. + switch (type) {
  1360. + case WLAN_FC_TYPE_MGMT:
  1361. + if (stype != WLAN_FC_STYPE_BEACON)
  1362. + wpa_printf(MSG_MSGDUMP, "MGMT");
  1363. +
  1364. +
  1365. +
  1366. + if (stype == WLAN_FC_STYPE_PROBE_REQ)
  1367. + {
  1368. +
  1369. + }
  1370. + else
  1371. + {
  1372. + //printf("rtl871x_receive_mgnt, type=0x%x, stype=0x%x\n", type, stype);
  1373. + }
  1374. +
  1375. +
  1376. + //ieee802_11_mgmt(hapd, (u8 *)buf, len, stype, NULL);
  1377. +
  1378. + break;
  1379. + case WLAN_FC_TYPE_CTRL:
  1380. + printf("rtl871x_receive_mgnt, CTRL\n");
  1381. + break;
  1382. + case WLAN_FC_TYPE_DATA:
  1383. + printf("rtl871x_receive_mgnt, DATA\n");
  1384. + //handle_data(hapd, buf, data_len, stype);
  1385. + break;
  1386. + default:
  1387. + printf("unknown frame type %d\n", type);
  1388. + break;
  1389. + }
  1390. +
  1391. +
  1392. +}
  1393. +
  1394. +#ifdef CONFIG_MGNT_L2SOCK
  1395. +static void rtl871x_recvive_mgmt_frame(void *ctx, const u8 *src_addr, const u8 *buf,
  1396. + size_t len)
  1397. +{
  1398. + struct rtl871x_driver_data *drv = ctx;
  1399. +
  1400. + rtl871x_receive_mgnt(drv, buf, len);
  1401. +}
  1402. +#else
  1403. +static void rtl871x_recvive_mgmt_frame(int sock, void *eloop_ctx, void *sock_ctx)
  1404. +{
  1405. +#if 0
  1406. + int len;
  1407. + unsigned char buf[1024];
  1408. + struct hostapd_data *hapd = (struct hostapd_data *)eloop_ctx;
  1409. + struct rtl871x_driver_data *drv = (struct rtl871x_driver_data *)hapd->drv_priv;
  1410. +
  1411. + len = recv(sock, buf, sizeof(buf), 0);
  1412. + if (len < 0) {
  1413. + perror("recv");
  1414. + return;
  1415. + }
  1416. +
  1417. + rtl871x_receive_mgnt(drv, buf, len);
  1418. +#endif
  1419. +}
  1420. +
  1421. +static int rtl871x_mgnt_sock_init(struct rtl871x_driver_data *drv, const char *name)
  1422. +{
  1423. + int sock;
  1424. + struct ifreq ifr;
  1425. + struct sockaddr_ll addr;
  1426. +
  1427. + sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  1428. + if (sock < 0) {
  1429. + perror("socket[PF_PACKET,SOCK_RAW]");
  1430. + return -1;
  1431. + }
  1432. +
  1433. + if (eloop_register_read_sock(sock, rtl871x_recvive_mgmt_frame, drv->hapd, NULL))
  1434. + {
  1435. + printf("Could not register read socket\n");
  1436. + return -1;
  1437. + }
  1438. +
  1439. + memset(&ifr, 0, sizeof(ifr));
  1440. + //snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
  1441. + os_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
  1442. + if (ioctl(sock, SIOCGIFINDEX, &ifr) != 0) {
  1443. + perror("ioctl(SIOCGIFINDEX)");
  1444. + return -1;
  1445. + }
  1446. +
  1447. + //if (rtl871x_set_iface_flags(drv, 1)) {
  1448. + // return -1;
  1449. + //}
  1450. +
  1451. + memset(&addr, 0, sizeof(addr));
  1452. + addr.sll_family = AF_PACKET;
  1453. + addr.sll_ifindex = ifr.ifr_ifindex;
  1454. + wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
  1455. + addr.sll_ifindex);
  1456. +
  1457. + if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  1458. + perror("bind");
  1459. + return -1;
  1460. + }
  1461. +
  1462. + memset(&ifr, 0, sizeof(ifr));
  1463. + os_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
  1464. + if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) {
  1465. + perror("ioctl(SIOCGIFHWADDR)");
  1466. + return -1;
  1467. + }
  1468. +
  1469. +
  1470. + if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
  1471. + printf("Invalid HW-addr family 0x%04x\n",
  1472. + ifr.ifr_hwaddr.sa_family);
  1473. + return -1;
  1474. + }
  1475. +
  1476. + //memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
  1477. +
  1478. + return sock;
  1479. +
  1480. +}
  1481. +#endif
  1482. +#endif
  1483. +
  1484. +static void rtl871x_handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
  1485. + int ok)
  1486. +{
  1487. +#if 0
  1488. + struct ieee80211_hdr *hdr;
  1489. + u16 fc, type, stype;
  1490. + struct sta_info *sta;
  1491. +
  1492. + //printf("%s\n", __func__);
  1493. +
  1494. + hdr = (struct ieee80211_hdr *) buf;
  1495. + fc = le_to_host16(hdr->frame_control);
  1496. +
  1497. + type = WLAN_FC_GET_TYPE(fc);
  1498. + stype = WLAN_FC_GET_STYPE(fc);
  1499. +
  1500. + switch (type) {
  1501. + case WLAN_FC_TYPE_MGMT:
  1502. + //printf("MGMT (TX callback) %s\n",
  1503. + // ok ? "ACK" : "fail");
  1504. + ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
  1505. + break;
  1506. + case WLAN_FC_TYPE_CTRL:
  1507. + printf("CTRL (TX callback) %s\n",
  1508. + ok ? "ACK" : "fail");
  1509. + break;
  1510. + case WLAN_FC_TYPE_DATA:
  1511. + printf("DATA (TX callback) %s\n",
  1512. + ok ? "ACK" : "fail");
  1513. + sta = ap_get_sta(hapd, hdr->addr1);
  1514. + if (sta && sta->flags & WLAN_STA_PENDING_POLL) {
  1515. + wpa_printf(MSG_DEBUG, "STA " MACSTR
  1516. + " %s pending activity poll",
  1517. + MAC2STR(sta->addr),
  1518. + ok ? "ACKed" : "did not ACK");
  1519. + if (ok)
  1520. + sta->flags &= ~WLAN_STA_PENDING_POLL;
  1521. + }
  1522. + if (sta)
  1523. + ieee802_1x_tx_status(hapd, sta, buf, len, ok);
  1524. + break;
  1525. + default:
  1526. + printf("unknown TX callback frame type %d\n", type);
  1527. + break;
  1528. + }
  1529. +#endif
  1530. +}
  1531. +
  1532. +static int rtl871x_send_mgnt(struct rtl871x_driver_data *drv, const void *msg, size_t len)
  1533. +{
  1534. + int res=0;
  1535. +
  1536. + return res;
  1537. +}
  1538. +
  1539. +static int rtl871x_send_mgmt_frame_ops(void *priv, const void *msg, size_t len,
  1540. + int flags)
  1541. +{
  1542. + struct rtl871x_driver_data *drv = priv;
  1543. + //struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msg;
  1544. + int res=0;
  1545. +
  1546. + //printf("%s\n", __func__);
  1547. +
  1548. +
  1549. + //hdr->frame_control |= host_to_le16(BIT(1));/* Request TX callback */
  1550. +#ifdef CONFIG_MGNT_L2SOCK
  1551. + //res = send(drv->mgnt_l2_sock, msg, len, flags);
  1552. + //res = l2_packet_send(drv->mgnt_l2_sock, addr, ETH_P_EAPOL, msg, len);
  1553. + if(drv->mgnt_l2_sock == NULL)
  1554. + return res;
  1555. +
  1556. + res = l2_packet_send(drv->mgnt_l2_sock, NULL, ETH_P_80211_RAW, msg, len);
  1557. +#else
  1558. +
  1559. + if(drv->mgnt_sock < 0)
  1560. + return res;
  1561. +
  1562. + res = send(drv->mgnt_sock, msg, len, flags);
  1563. +#endif
  1564. + //hdr->frame_control &= ~host_to_le16(BIT(1));
  1565. +
  1566. +
  1567. + rtl871x_send_mgnt(drv, msg, len);
  1568. +
  1569. + rtl871x_handle_tx_callback(drv->hapd, (u8*)msg, len, 1);
  1570. +
  1571. + return res;
  1572. +
  1573. +}
  1574. +
  1575. +/*
  1576. +static int rtl871x_driver_send_ether_ops(void *priv, const u8 *dst, const u8 *src,
  1577. + u16 proto, const u8 *data, size_t data_len)
  1578. +{
  1579. + return 0;
  1580. +}
  1581. +*/
  1582. +
  1583. +static struct hostapd_hw_modes *rtl871x_get_hw_feature_data_ops(void *priv,
  1584. + u16 *num_modes,
  1585. + u16 *flags)
  1586. +{
  1587. +
  1588. +#define MAX_NUM_CHANNEL (14)
  1589. +#define MAX_NUM_CHANNEL_5G (24)
  1590. +
  1591. + struct hostapd_hw_modes *modes;
  1592. + size_t i;
  1593. + int k;
  1594. +
  1595. + *num_modes = 3;
  1596. + *flags = 0;
  1597. +
  1598. + modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
  1599. + if (modes == NULL)
  1600. + return NULL;
  1601. +
  1602. + //.1
  1603. + modes[0].mode = HOSTAPD_MODE_IEEE80211G;
  1604. + modes[0].num_channels = MAX_NUM_CHANNEL;
  1605. + modes[0].num_rates = 12;
  1606. + modes[0].channels =
  1607. + os_zalloc(MAX_NUM_CHANNEL * sizeof(struct hostapd_channel_data));
  1608. + modes[0].rates = os_zalloc(modes[0].num_rates * sizeof(int));
  1609. + if (modes[0].channels == NULL || modes[0].rates == NULL)
  1610. + goto fail;
  1611. + for (i = 0; i < MAX_NUM_CHANNEL; i++) {
  1612. + modes[0].channels[i].chan = i + 1;
  1613. + modes[0].channels[i].freq = 2412 + 5 * i;
  1614. + modes[0].channels[i].flag = 0;
  1615. + if (i >= 13)
  1616. + modes[0].channels[i].flag = HOSTAPD_CHAN_DISABLED;
  1617. + }
  1618. + modes[0].rates[0] = 10;
  1619. + modes[0].rates[1] = 20;
  1620. + modes[0].rates[2] = 55;
  1621. + modes[0].rates[3] = 110;
  1622. + modes[0].rates[4] = 60;
  1623. + modes[0].rates[5] = 90;
  1624. + modes[0].rates[6] = 120;
  1625. + modes[0].rates[7] = 180;
  1626. + modes[0].rates[8] = 240;
  1627. + modes[0].rates[9] = 360;
  1628. + modes[0].rates[10] = 480;
  1629. + modes[0].rates[11] = 540;
  1630. +
  1631. +
  1632. + //.2
  1633. + modes[1].mode = HOSTAPD_MODE_IEEE80211B;
  1634. + modes[1].num_channels = MAX_NUM_CHANNEL;
  1635. + modes[1].num_rates = 4;
  1636. + modes[1].channels =
  1637. + os_zalloc(MAX_NUM_CHANNEL * sizeof(struct hostapd_channel_data));
  1638. + modes[1].rates = os_zalloc(modes[1].num_rates * sizeof(int));
  1639. + if (modes[1].channels == NULL || modes[1].rates == NULL)
  1640. + goto fail;
  1641. + for (i = 0; i < MAX_NUM_CHANNEL; i++) {
  1642. + modes[1].channels[i].chan = i + 1;
  1643. + modes[1].channels[i].freq = 2412 + 5 * i;
  1644. + modes[1].channels[i].flag = 0;
  1645. + if (i >= 11)
  1646. + modes[1].channels[i].flag = HOSTAPD_CHAN_DISABLED;
  1647. + }
  1648. + modes[1].rates[0] = 10;
  1649. + modes[1].rates[1] = 20;
  1650. + modes[1].rates[2] = 55;
  1651. + modes[1].rates[3] = 110;
  1652. +
  1653. +
  1654. + //.3
  1655. + modes[2].mode = HOSTAPD_MODE_IEEE80211A;
  1656. +#ifdef CONFIG_DRIVER_RTL_DFS
  1657. + modes[2].num_channels = MAX_NUM_CHANNEL_5G;
  1658. +#else /* CONFIG_DRIVER_RTL_DFS */
  1659. + modes[2].num_channels = 9;
  1660. +#endif /* CONFIG_DRIVER_RTL_DFS */
  1661. +
  1662. + modes[2].num_rates = 8;
  1663. + modes[2].channels = os_zalloc(modes[2].num_channels * sizeof(struct hostapd_channel_data));
  1664. + modes[2].rates = os_zalloc(modes[2].num_rates * sizeof(int));
  1665. + if (modes[2].channels == NULL || modes[2].rates == NULL)
  1666. + goto fail;
  1667. +
  1668. +
  1669. + k = 0;
  1670. + // 5G band1 Channel: 36, 40, 44, 48
  1671. + for (i=0; i < 4; i++) {
  1672. + modes[2].channels[k].chan = 36+(i*4);
  1673. + modes[2].channels[k].freq = 5180+(i*20);
  1674. + modes[2].channels[k].flag = 0;
  1675. + k++;
  1676. + }
  1677. +
  1678. +#ifdef CONFIG_DRIVER_RTL_DFS
  1679. + // 5G band2 Channel: 52, 56, 60, 64
  1680. + for (i=0; i < 4; i++) {
  1681. + modes[2].channels[k].chan = 52+(i*4);
  1682. + modes[2].channels[k].freq = 5260+(i*20);
  1683. + modes[2].channels[k].flag = 0;
  1684. + k++;
  1685. + }
  1686. +
  1687. + // 5G band3 Channel: 100, 104, 108. 112, 116, 120, 124, 128, 132, 136, 140
  1688. + for (i=0; i < 11; i++) {
  1689. + modes[2].channels[k].chan = 100+(i*4);
  1690. + modes[2].channels[k].freq = 5500+(i*20);
  1691. + modes[2].channels[k].flag = 0;
  1692. + k++;
  1693. + }
  1694. +#endif /* CONFIG_DRIVER_RTL_DFS */
  1695. +
  1696. + // 5G band4 Channel: 149, 153, 157, 161, 165
  1697. + for (i=0; i < 5; i++) {
  1698. + modes[2].channels[k].chan = 149+(i*4);
  1699. + modes[2].channels[k].freq = 5745+(i*20);
  1700. + modes[2].channels[k].flag = 0;
  1701. + k++;
  1702. + }
  1703. +
  1704. + modes[2].rates[0] = 60;
  1705. + modes[2].rates[1] = 90;
  1706. + modes[2].rates[2] = 120;
  1707. + modes[2].rates[3] = 180;
  1708. + modes[2].rates[4] = 240;
  1709. + modes[2].rates[5] = 360;
  1710. + modes[2].rates[6] = 480;
  1711. + modes[2].rates[7] = 540;
  1712. +
  1713. +
  1714. + //
  1715. +#if 0
  1716. +#define HT_CAP_INFO_LDPC_CODING_CAP ((u16) BIT(0))
  1717. +#define HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET ((u16) BIT(1))
  1718. +#define HT_CAP_INFO_SMPS_MASK ((u16) (BIT(2) | BIT(3)))
  1719. +#define HT_CAP_INFO_SMPS_STATIC ((u16) 0)
  1720. +#define HT_CAP_INFO_SMPS_DYNAMIC ((u16) BIT(2))
  1721. +#define HT_CAP_INFO_SMPS_DISABLED ((u16) (BIT(2) | BIT(3)))
  1722. +#define HT_CAP_INFO_GREEN_FIELD ((u16) BIT(4))
  1723. +#define HT_CAP_INFO_SHORT_GI20MHZ ((u16) BIT(5))
  1724. +#define HT_CAP_INFO_SHORT_GI40MHZ ((u16) BIT(6))
  1725. +#define HT_CAP_INFO_TX_STBC ((u16) BIT(7))
  1726. +#define HT_CAP_INFO_RX_STBC_MASK ((u16) (BIT(8) | BIT(9)))
  1727. +#define HT_CAP_INFO_RX_STBC_1 ((u16) BIT(8))
  1728. +#define HT_CAP_INFO_RX_STBC_12 ((u16) BIT(9))
  1729. +#define HT_CAP_INFO_RX_STBC_123 ((u16) (BIT(8) | BIT(9)))
  1730. +#define HT_CAP_INFO_DELAYED_BA ((u16) BIT(10))
  1731. +#define HT_CAP_INFO_MAX_AMSDU_SIZE ((u16) BIT(11))
  1732. +#define HT_CAP_INFO_DSSS_CCK40MHZ ((u16) BIT(12))
  1733. +#define HT_CAP_INFO_PSMP_SUPP ((u16) BIT(13))
  1734. +#define HT_CAP_INFO_40MHZ_INTOLERANT ((u16) BIT(14))
  1735. +#define HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT ((u16) BIT(15))
  1736. +#endif
  1737. +
  1738. + //HOSTAPD_MODE_IEEE80211G
  1739. + modes[0].ht_capab = HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET|HT_CAP_INFO_SHORT_GI20MHZ|
  1740. + HT_CAP_INFO_SHORT_GI40MHZ|HT_CAP_INFO_MAX_AMSDU_SIZE|HT_CAP_INFO_DSSS_CCK40MHZ;
  1741. +
  1742. + modes[0].mcs_set[0]= 0xff;
  1743. + modes[0].mcs_set[1]= 0xff;
  1744. +
  1745. + //HOSTAPD_MODE_IEEE80211B
  1746. + modes[1].ht_capab = 0;
  1747. +
  1748. + //HOSTAPD_MODE_IEEE80211A
  1749. + modes[2].ht_capab = modes[0].ht_capab;
  1750. +
  1751. + modes[2].mcs_set[0]= 0xff;
  1752. + modes[2].mcs_set[1]= 0xff;
  1753. +
  1754. + return modes;
  1755. +
  1756. +fail:
  1757. + if (modes) {
  1758. + for (i = 0; i < *num_modes; i++) {
  1759. + os_free(modes[i].channels);
  1760. + os_free(modes[i].rates);
  1761. + }
  1762. + os_free(modes);
  1763. + }
  1764. +
  1765. + return NULL;
  1766. +
  1767. +}
  1768. +
  1769. +#if 0
  1770. +static int rtl871x_sta_add_ops(const char *ifname, void *priv, const u8 *addr,
  1771. + u16 aid, u16 capability, u8 *supp_rates,
  1772. + size_t supp_rates_len, int flags,
  1773. + u16 listen_interval)
  1774. +{
  1775. +
  1776. +#if 1
  1777. + printf("+%s, " MACSTR " is new sta address added\n", __func__, MAC2STR(addr));
  1778. + return 0;
  1779. +#else
  1780. + struct hostap_driver_data *drv = priv;
  1781. + struct prism2_hostapd_param param;
  1782. + int tx_supp_rates = 0;
  1783. + size_t i;
  1784. +
  1785. +#define WLAN_RATE_1M BIT(0)
  1786. +#define WLAN_RATE_2M BIT(1)
  1787. +#define WLAN_RATE_5M5 BIT(2)
  1788. +#define WLAN_RATE_11M BIT(3)
  1789. +
  1790. + for (i = 0; i < supp_rates_len; i++) {
  1791. + if ((supp_rates[i] & 0x7f) == 2)
  1792. + tx_supp_rates |= WLAN_RATE_1M;
  1793. + if ((supp_rates[i] & 0x7f) == 4)
  1794. + tx_supp_rates |= WLAN_RATE_2M;
  1795. + if ((supp_rates[i] & 0x7f) == 11)
  1796. + tx_supp_rates |= WLAN_RATE_5M5;
  1797. + if ((supp_rates[i] & 0x7f) == 22)
  1798. + tx_supp_rates |= WLAN_RATE_11M;
  1799. + }
  1800. +
  1801. + memset(&param, 0, sizeof(param));
  1802. + param.cmd = PRISM2_HOSTAPD_ADD_STA;
  1803. + memcpy(param.sta_addr, addr, ETH_ALEN);
  1804. + param.u.add_sta.aid = aid;
  1805. + param.u.add_sta.capability = capability;
  1806. + param.u.add_sta.tx_supp_rates = tx_supp_rates;
  1807. + return hostapd_ioctl(drv, &param, sizeof(param));
  1808. +#endif
  1809. +}
  1810. +
  1811. +static int rtl871x_sta_add2_ops(const char *ifname, void *priv,
  1812. + struct hostapd_sta_add_params *params)
  1813. +{
  1814. +#if 0
  1815. + ieee_param param;
  1816. + //int i, tx_supp_rates = 0;
  1817. + struct rtl871x_driver_data *drv = priv;
  1818. +
  1819. + printf("%s\n", __func__);
  1820. +
  1821. + memset(&param, 0, sizeof(param));
  1822. + param.cmd = RTL871X_HOSTAPD_ADD_STA;
  1823. + memcpy(param.sta_addr, params->addr, ETH_ALEN);
  1824. + param.u.add_sta.aid = params->aid;
  1825. + param.u.add_sta.capability = params->capability;
  1826. + param.u.add_sta.flags = params->flags;
  1827. +
  1828. + memcpy(param.u.add_sta.tx_supp_rates, params->supp_rates, params->supp_rates_len);
  1829. +
  1830. +/*
  1831. + for (i = 0; i < params->supp_rates_len; i++)
  1832. + {
  1833. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_CCK_RATE_1MB)
  1834. + tx_supp_rates |= IEEE80211_CCK_RATE_1MB_MASK;
  1835. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_CCK_RATE_2MB)
  1836. + tx_supp_rates |= IEEE80211_CCK_RATE_2MB_MASK;
  1837. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_CCK_RATE_5MB)
  1838. + tx_supp_rates |= IEEE80211_CCK_RATE_5MB_MASK;
  1839. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_CCK_RATE_11MB)
  1840. + tx_supp_rates |= IEEE80211_CCK_RATE_11MB_MASK;
  1841. +
  1842. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_6MB)
  1843. + tx_supp_rates |= IEEE80211_OFDM_RATE_6MB_MASK;
  1844. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_9MB)
  1845. + tx_supp_rates |= IEEE80211_OFDM_RATE_9MB_MASK;
  1846. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_12MB)
  1847. + tx_supp_rates |= IEEE80211_OFDM_RATE_12MB_MASK;
  1848. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_18MB)
  1849. + tx_supp_rates |= IEEE80211_OFDM_RATE_18MB_MASK;
  1850. +
  1851. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_24MB)
  1852. + tx_supp_rates |= IEEE80211_OFDM_RATE_24MB_MASK;
  1853. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_36MB)
  1854. + tx_supp_rates |= IEEE80211_OFDM_RATE_36MB_MASK;
  1855. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_48MB)
  1856. + tx_supp_rates |= IEEE80211_OFDM_RATE_48MB_MASK;
  1857. + if ((params->supp_rates[i] & 0x7f) == IEEE80211_OFDM_RATE_54MB)
  1858. + tx_supp_rates |= IEEE80211_OFDM_RATE_54MB_MASK;
  1859. +
  1860. + }
  1861. +
  1862. + param.u.add_sta.tx_supp_rates = tx_supp_rates;
  1863. +*/
  1864. +
  1865. +#ifdef CONFIG_IEEE80211N
  1866. + if (params->ht_capabilities && params->ht_capabilities->length>0)
  1867. + {
  1868. + struct ieee80211_ht_capability *pht_cap = (struct ieee80211_ht_capability *)&params->ht_capabilities->data;
  1869. + memcpy((u8*)&param.u.add_sta.ht_cap, (u8*)pht_cap, sizeof(struct ieee80211_ht_capability));
  1870. +
  1871. + }
  1872. +#endif /* CONFIG_IEEE80211N */
  1873. +
  1874. + return rtl871x_hostapd_ioctl(drv, &param, sizeof(param));
  1875. +#else
  1876. + return 0;
  1877. +#endif
  1878. +}
  1879. +#endif
  1880. +
  1881. +static int rtl871x_sta_remove_ops(void *priv, const u8 *addr)
  1882. +{
  1883. + struct rtl871x_driver_data *drv = priv;
  1884. + struct ieee_param param;
  1885. +
  1886. + printf("+%s, " MACSTR " is sta address removed\n", __func__, MAC2STR(addr));
  1887. +
  1888. + //hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
  1889. +
  1890. + memset(&param, 0, sizeof(param));
  1891. + param.cmd = RTL871X_HOSTAPD_REMOVE_STA;
  1892. + memcpy(param.sta_addr, addr, ETH_ALEN);
  1893. + if (rtl871x_hostapd_ioctl(drv, &param, sizeof(param))) {
  1894. + printf("Could not remove station from kernel driver.\n");
  1895. + return -1;
  1896. + }
  1897. +
  1898. + return 0;
  1899. +
  1900. +}
  1901. +
  1902. +#define RTL871X_HIDDEN_SSID_SUPPORT
  1903. +#ifdef RTL871X_HIDDEN_SSID_SUPPORT
  1904. +static int rtl871x_set_hidden_ssid_ops(const char *iface, void *priv, u8 value)
  1905. +{
  1906. + int ret;
  1907. + ieee_param pparam;
  1908. + struct rtl871x_driver_data *drv = priv;
  1909. + struct hostapd_data *hapd = drv->hapd;
  1910. +
  1911. + printf("%s\n", __func__);
  1912. +
  1913. + pparam.cmd = RTL871X_HOSTAPD_SET_HIDDEN_SSID;
  1914. + pparam.u.wpa_param.name = 0;
  1915. + pparam.u.wpa_param.value = value;
  1916. +
  1917. + ret = rtl871x_hostapd_ioctl(drv, &pparam, sizeof(ieee_param));
  1918. +
  1919. + return ret;
  1920. +}
  1921. +
  1922. +static const u8 * get_ie(u8 *ies, size_t ies_len, u8 id)
  1923. +{
  1924. + const u8 *end, *pos;
  1925. +
  1926. + pos = ies;
  1927. + end = pos + ies_len;
  1928. +
  1929. + while (pos + 1 < end) {
  1930. + if (pos + 2 + pos[1] > end)
  1931. + break;
  1932. +
  1933. + //printf("id:%u, clen:%u\n", pos[0], pos[1]);
  1934. +
  1935. + if (pos[0] == id)
  1936. + return pos;
  1937. + pos += 2 + pos[1];
  1938. + }
  1939. +
  1940. + return NULL;
  1941. +}
  1942. +#endif //RTL871X_HIDDEN_SSID_SUPPORT
  1943. +
  1944. +static int rtl871x_set_beacon_ops(void *priv, struct wpa_driver_ap_params *params)
  1945. +{
  1946. + int ret;
  1947. + size_t sz;
  1948. + ieee_param *pparam;
  1949. + struct rtl871x_driver_data *drv = priv;
  1950. + struct hostapd_data *hapd = drv->hapd;
  1951. +
  1952. + u8 *ssid_ie;
  1953. + u8 ssid_len;
  1954. + u8 expend_len = 0;
  1955. +
  1956. + if((params->head_len<24) ||(!params->head))
  1957. + return -1;
  1958. +
  1959. + printf("%s\n", __func__);
  1960. +
  1961. +
  1962. +#ifdef RTL871X_HIDDEN_SSID_SUPPORT
  1963. + rtl871x_set_hidden_ssid_ops(drv->iface, priv, hapd->conf->ignore_broadcast_ssid);
  1964. +
  1965. + ssid_ie = get_ie((params->head+24+12), (params->head_len-24-12), WLAN_EID_SSID);
  1966. +
  1967. + if(hapd->conf->ignore_broadcast_ssid == 2)
  1968. + {
  1969. + ssid_len = ssid_ie[1];
  1970. +
  1971. + //confirm the ssid_len
  1972. + if(ssid_len != hapd->conf->ssid.ssid_len)
  1973. + {
  1974. + printf("%s ssid_len(%u) != hapd->conf->ssid.ssid_len(%u)!!\n", __func__
  1975. + , ssid_len, hapd->conf->ssid.ssid_len
  1976. + );
  1977. + }
  1978. +
  1979. + memcpy(ssid_ie+2, hapd->conf->ssid.ssid, ssid_len);
  1980. + }
  1981. + else if(hapd->conf->ignore_broadcast_ssid == 1)
  1982. + {
  1983. + expend_len = hapd->conf->ssid.ssid_len;
  1984. + printf("%s ignore_broadcast_ssid:%d, %s,%d, expend_len:%u\n", __func__
  1985. + , hapd->conf->ignore_broadcast_ssid
  1986. + , hapd->conf->ssid.ssid
  1987. + , hapd->conf->ssid.ssid_len
  1988. + , expend_len
  1989. + );
  1990. + }
  1991. +#endif //RTL871X_HIDDEN_SSID_SUPPORT
  1992. +
  1993. + sz = params->head_len+params->tail_len+12-24 + 2 + expend_len;// 12+2 = cmd+sta_addr+reserved, sizeof(ieee_param)=64, no packed
  1994. + pparam = os_zalloc(sz);
  1995. + if (pparam == NULL) {
  1996. + return -ENOMEM;
  1997. + }
  1998. +
  1999. + pparam->cmd = RTL871X_HOSTAPD_SET_BEACON;
  2000. +
  2001. + memcpy(pparam->u.bcn_ie.reserved, &hapd->conf->max_num_sta, 2);//for set max_num_sta
  2002. +
  2003. +#ifdef RTL871X_HIDDEN_SSID_SUPPORT
  2004. + if(hapd->conf->ignore_broadcast_ssid == 1)
  2005. + {
  2006. + u8 *ssid_ie_next = params->head+24+12+2;
  2007. + size_t head_remain_len = params->head_len-24-12-2;
  2008. +
  2009. + memcpy(pparam->u.bcn_ie.buf, (params->head+24), 12);
  2010. +
  2011. + pparam->u.bcn_ie.buf[12] = WLAN_EID_SSID;
  2012. + pparam->u.bcn_ie.buf[13] = expend_len;
  2013. + memcpy(pparam->u.bcn_ie.buf+12+2, hapd->conf->ssid.ssid, expend_len);
  2014. +
  2015. + memcpy(pparam->u.bcn_ie.buf+12+2+expend_len, ssid_ie_next, head_remain_len);// 24=beacon header len.
  2016. + memcpy(&pparam->u.bcn_ie.buf[params->head_len-24+expend_len], params->tail, params->tail_len);
  2017. + }
  2018. + else
  2019. +#endif //RTL871X_HIDDEN_SSID_SUPPORT
  2020. + {
  2021. + memcpy(pparam->u.bcn_ie.buf, (params->head+24), (params->head_len-24));// 24=beacon header len.
  2022. + memcpy(&pparam->u.bcn_ie.buf[params->head_len-24], params->tail, params->tail_len);
  2023. + }
  2024. +
  2025. + ret = rtl871x_hostapd_ioctl(drv, pparam, sz);
  2026. +
  2027. + os_free(pparam);
  2028. +
  2029. + //rtl871x_set_max_num_sta(drv);
  2030. +
  2031. + return ret;
  2032. +
  2033. +}
  2034. +
  2035. +/*
  2036. +enum wpa_alg {
  2037. + WPA_ALG_NONE,
  2038. + WPA_ALG_WEP,
  2039. + WPA_ALG_TKIP,
  2040. + WPA_ALG_CCMP,
  2041. + WPA_ALG_IGTK,
  2042. + WPA_ALG_PMK
  2043. +};
  2044. +*/
  2045. +static int rtl871x_set_key_ops(const char *ifname, void *priv, enum wpa_alg alg,
  2046. + const u8 *addr, int idx, int txkey, const u8 *seq,
  2047. + size_t seq_len, const u8 *key, size_t key_len)
  2048. +{
  2049. + ieee_param *param;
  2050. + u8 *buf;
  2051. + char *alg_str;
  2052. + size_t blen;
  2053. + int ret = 0;
  2054. + struct rtl871x_driver_data *drv = priv;
  2055. +
  2056. + printf("%s\n", __func__);
  2057. +
  2058. + blen = sizeof(*param) + key_len;
  2059. + buf = os_zalloc(blen);
  2060. + if (buf == NULL)
  2061. + return -1;
  2062. +
  2063. + param = (ieee_param *)buf;
  2064. + param->cmd = RTL871X_SET_ENCRYPTION;
  2065. + if (addr == NULL)
  2066. + memset(param->sta_addr, 0xff, ETH_ALEN);
  2067. + else
  2068. + memcpy(param->sta_addr, addr, ETH_ALEN);
  2069. +
  2070. +
  2071. + switch (alg) {
  2072. + case WPA_ALG_NONE:
  2073. + alg_str = "none";
  2074. + break;
  2075. + case WPA_ALG_WEP:
  2076. + //cipher = IEEE80211_CIPHER_WEP;
  2077. + alg_str = "WEP";
  2078. + break;
  2079. + case WPA_ALG_TKIP:
  2080. + //cipher = IEEE80211_CIPHER_TKIP;
  2081. + alg_str = "TKIP";
  2082. + break;
  2083. + case WPA_ALG_CCMP:
  2084. + //cipher = IEEE80211_CIPHER_AES_CCM;
  2085. + alg_str = "CCMP";
  2086. + break;
  2087. + default:
  2088. + printf("%s: unknown/unsupported algorithm %d\n",
  2089. + __func__, alg);
  2090. + return -1;
  2091. + }
  2092. +
  2093. + os_strlcpy((char *) param->u.crypt.alg, alg_str,
  2094. + IEEE_CRYPT_ALG_NAME_LEN);
  2095. +
  2096. + //param->u.crypt.flags = txkey ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
  2097. + param->u.crypt.set_tx = txkey ? 1 : 0;
  2098. + param->u.crypt.idx = idx;
  2099. + param->u.crypt.key_len = key_len;
  2100. +
  2101. + //memcpy((u8 *) (param + 1), key, key_len);
  2102. + memcpy(param->u.crypt.key, key, key_len);
  2103. +
  2104. + if (rtl871x_hostapd_ioctl(drv, param, blen)) {
  2105. + printf("Failed to set encryption.\n");
  2106. + ret = -1;
  2107. + }
  2108. +
  2109. + os_free(buf);
  2110. +
  2111. + return ret;
  2112. +
  2113. +}
  2114. +
  2115. +/*
  2116. +static int rtl871x_set_encryption_ops(const char *ifname, void *priv,
  2117. + const char *alg, const u8 *addr,
  2118. + int idx, const u8 *key, size_t key_len,
  2119. + int txkey)
  2120. +{
  2121. + ieee_param *param;
  2122. + u8 *buf;
  2123. + size_t blen;
  2124. + int ret = 0;
  2125. + struct rtl871x_driver_data *drv = priv;
  2126. +
  2127. + printf("%s\n", __func__);
  2128. +#if 0
  2129. + blen = sizeof(*param) + key_len;
  2130. + buf = os_zalloc(blen);
  2131. + if (buf == NULL)
  2132. + return -1;
  2133. +
  2134. + param = (ieee_param *)buf;
  2135. + param->cmd = RTL871X_SET_ENCRYPTION;
  2136. + if (addr == NULL)
  2137. + memset(param->sta_addr, 0xff, ETH_ALEN);
  2138. + else
  2139. + memcpy(param->sta_addr, addr, ETH_ALEN);
  2140. +
  2141. + os_strlcpy((char *) param->u.crypt.alg, alg,
  2142. + IEEE_CRYPT_ALG_NAME_LEN);
  2143. +
  2144. + //param->u.crypt.flags = txkey ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
  2145. + param->u.crypt.set_tx = txkey ? 1 : 0;
  2146. + param->u.crypt.idx = idx;
  2147. + param->u.crypt.key_len = key_len;
  2148. +
  2149. + //memcpy((u8 *) (param + 1), key, key_len);
  2150. + memcpy(param->u.crypt.key, key, key_len);
  2151. +
  2152. + if (rtl871x_hostapd_ioctl(drv, param, blen)) {
  2153. + printf("Failed to set encryption.\n");
  2154. + ret = -1;
  2155. + }
  2156. +
  2157. + os_free(buf);
  2158. +#endif
  2159. + return ret;
  2160. +
  2161. +}
  2162. +*/
  2163. +
  2164. +//static int rtl871x_sta_deauth_ops(void *priv, const u8 *addr, int reason)
  2165. +static int rtl871x_sta_deauth_ops(void *priv, const u8 *own_addr, const u8 *addr,
  2166. + int reason)
  2167. +{
  2168. + printf("+%s, " MACSTR " is deauth, reason=%d\n", __func__, MAC2STR(addr), reason);
  2169. +
  2170. + //struct hostap_driver_data *drv = priv;
  2171. + struct rtl871x_driver_data *drv = priv;
  2172. + struct ieee80211_mgmt mgmt;
  2173. +
  2174. + memset(&mgmt, 0, sizeof(mgmt));
  2175. + mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  2176. + WLAN_FC_STYPE_DEAUTH);
  2177. +
  2178. + memcpy(mgmt.da, addr, ETH_ALEN);
  2179. + //memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
  2180. + //memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
  2181. + memcpy(mgmt.sa, own_addr, ETH_ALEN);
  2182. + memcpy(mgmt.bssid, own_addr, ETH_ALEN);
  2183. + mgmt.u.deauth.reason_code = host_to_le16(reason);
  2184. +
  2185. + return rtl871x_send_mgmt_frame_ops(drv, &mgmt, IEEE80211_HDRLEN +
  2186. + sizeof(mgmt.u.deauth), 0);
  2187. +
  2188. +}
  2189. +
  2190. +
  2191. +//static int rtl871x_sta_disassoc_ops(void *priv, const u8 *addr, int reason)
  2192. +static int rtl871x_sta_disassoc_ops(void *priv, const u8 *own_addr, const u8 *addr,
  2193. + int reason)
  2194. +{
  2195. + printf("+%s, " MACSTR " is disassoc, reason=%d\n", __func__, MAC2STR(addr), reason);
  2196. +
  2197. + struct rtl871x_driver_data *drv = priv;
  2198. + struct ieee80211_mgmt mgmt;
  2199. +
  2200. + memset(&mgmt, 0, sizeof(mgmt));
  2201. + mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  2202. + WLAN_FC_STYPE_DISASSOC);
  2203. +
  2204. + memcpy(mgmt.da, addr, ETH_ALEN);
  2205. + //memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
  2206. + //memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
  2207. + memcpy(mgmt.sa, own_addr, ETH_ALEN);
  2208. + memcpy(mgmt.bssid, own_addr, ETH_ALEN);
  2209. +
  2210. + mgmt.u.disassoc.reason_code = host_to_le16(reason);
  2211. +
  2212. + return rtl871x_send_mgmt_frame_ops(drv, &mgmt, IEEE80211_HDRLEN +
  2213. + sizeof(mgmt.u.disassoc), 0);
  2214. +
  2215. +}
  2216. +
  2217. +static int rtl871x_set_wps_assoc_resp_ie(struct rtl871x_driver_data *drv, const void *ie, size_t len)
  2218. +{
  2219. + int ret;
  2220. + size_t sz;
  2221. + ieee_param *pparam;
  2222. +
  2223. +
  2224. + printf("%s\n", __func__);
  2225. +
  2226. + sz = len + 12 + 2;// 12+2 = cmd+sta_addr+reserved, sizeof(ieee_param)=64, no packed
  2227. + pparam = os_zalloc(sz);
  2228. + if (pparam == NULL) {
  2229. + return -ENOMEM;
  2230. + }
  2231. +
  2232. + pparam->cmd = RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP;
  2233. +
  2234. + if(ie && len>0)
  2235. + {
  2236. + memcpy(pparam->u.bcn_ie.buf, ie, len);
  2237. + }
  2238. +
  2239. + ret = rtl871x_hostapd_ioctl(drv, pparam, sz);
  2240. +
  2241. + os_free(pparam);
  2242. +
  2243. + return ret;
  2244. +
  2245. +}
  2246. +
  2247. +static int rtl871x_set_wps_beacon_ie(struct rtl871x_driver_data *drv, const void *ie, size_t len)
  2248. +{
  2249. + int ret;
  2250. + size_t sz;
  2251. + ieee_param *pparam;
  2252. +
  2253. +
  2254. + printf("%s\n", __func__);
  2255. +
  2256. + sz = len + 12 + 2;// 12+2 = cmd+sta_addr+reserved, sizeof(ieee_param)=64, no packed
  2257. + pparam = os_zalloc(sz);
  2258. + if (pparam == NULL) {
  2259. + return -ENOMEM;
  2260. + }
  2261. +
  2262. + pparam->cmd = RTL871X_HOSTAPD_SET_WPS_BEACON;
  2263. +
  2264. + if(ie && len>0)
  2265. + {
  2266. + memcpy(pparam->u.bcn_ie.buf, ie, len);
  2267. + }
  2268. +
  2269. + ret = rtl871x_hostapd_ioctl(drv, pparam, sz);
  2270. +
  2271. + os_free(pparam);
  2272. +
  2273. + return ret;
  2274. +
  2275. +}
  2276. +
  2277. +static int rtl871x_set_wps_probe_resp_ie(struct rtl871x_driver_data *drv, const void *ie, size_t len)
  2278. +{
  2279. + int ret;
  2280. + size_t sz;
  2281. + ieee_param *pparam;
  2282. +
  2283. +
  2284. + printf("%s\n", __func__);
  2285. +
  2286. + sz = len + 12 + 2;// 12+2 = cmd+sta_addr+reserved, sizeof(ieee_param)=64, no packed
  2287. + pparam = os_zalloc(sz);
  2288. + if (pparam == NULL) {
  2289. + return -ENOMEM;
  2290. + }
  2291. +
  2292. + pparam->cmd = RTL871X_HOSTAPD_SET_WPS_PROBE_RESP;
  2293. +
  2294. + if(ie && len>0)
  2295. + {
  2296. + memcpy(pparam->u.bcn_ie.buf, ie, len);
  2297. + }
  2298. +
  2299. + ret = rtl871x_hostapd_ioctl(drv, pparam, sz);
  2300. +
  2301. + os_free(pparam);
  2302. +
  2303. + return ret;
  2304. +
  2305. +}
  2306. +
  2307. +static int rtl871x_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
  2308. + const struct wpabuf *proberesp, const struct wpabuf *assocresp)
  2309. +{
  2310. + struct rtl871x_driver_data *drv = priv;
  2311. +
  2312. + if (rtl871x_set_wps_assoc_resp_ie(drv, assocresp ? wpabuf_head(assocresp) : NULL,
  2313. + assocresp ? wpabuf_len(assocresp) : 0))
  2314. + return -1;
  2315. +
  2316. + if (rtl871x_set_wps_beacon_ie(drv, beacon ? wpabuf_head(beacon) : NULL,
  2317. + beacon ? wpabuf_len(beacon) : 0))
  2318. + return -1;
  2319. +
  2320. + return rtl871x_set_wps_probe_resp_ie(drv,
  2321. + proberesp ? wpabuf_head(proberesp) : NULL,
  2322. + proberesp ? wpabuf_len(proberesp): 0);
  2323. +
  2324. +}
  2325. +
  2326. +static int rtl871x_sta_flush_ops(void *priv)
  2327. +{
  2328. + ieee_param param;
  2329. + struct rtl871x_driver_data *drv = priv;
  2330. +
  2331. + memset(&param, 0, sizeof(param));
  2332. +
  2333. + param.cmd = RTL871X_HOSTAPD_FLUSH;
  2334. +
  2335. + return rtl871x_hostapd_ioctl(drv, &param, sizeof(param));
  2336. +}
  2337. +
  2338. +static void *rtl871x_driver_init_ops(struct hostapd_data *hapd, struct wpa_init_params *params)
  2339. +{
  2340. + struct rtl871x_driver_data *drv;
  2341. + struct ifreq ifr;
  2342. + //struct iwreq iwr;
  2343. + char ifrn_name[IFNAMSIZ + 1];//for mgnt_l2_sock/mgnt_sock
  2344. + char brname[IFNAMSIZ];
  2345. +
  2346. + drv = os_zalloc(sizeof(struct rtl871x_driver_data));
  2347. + if (drv == NULL) {
  2348. + printf("Could not allocate memory for rtl871x driver data\n");
  2349. + return NULL;
  2350. + }
  2351. +
  2352. + drv->hapd = hapd;
  2353. + drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
  2354. + if (drv->ioctl_sock < 0) {
  2355. + perror("socket[PF_INET,SOCK_DGRAM]");
  2356. + goto bad;
  2357. + }
  2358. + os_memcpy(drv->iface, params->ifname, sizeof(drv->iface));
  2359. +
  2360. + linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);/*set interface up*/
  2361. +
  2362. + os_memset(&ifr, 0, sizeof(ifr));
  2363. + os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
  2364. + if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
  2365. + perror("ioctl(SIOCGIFINDEX)");
  2366. + goto bad;
  2367. + }
  2368. + drv->ifindex = ifr.ifr_ifindex;
  2369. + printf("drv->ifindex=%d\n", drv->ifindex);
  2370. +
  2371. + drv->l2_sock = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
  2372. + rtl871x_handle_read, drv, 1);
  2373. +
  2374. + if (drv->l2_sock == NULL)
  2375. + goto bad;
  2376. +
  2377. + if (l2_packet_get_own_addr(drv->l2_sock, params->own_addr))
  2378. + goto bad;
  2379. +
  2380. +
  2381. + if (params->bridge[0]) {
  2382. + wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
  2383. + params->bridge[0]);
  2384. + drv->l2_sock_recv = l2_packet_init(params->bridge[0], NULL,
  2385. + ETH_P_EAPOL, rtl871x_handle_read, drv,
  2386. + 1);
  2387. + if (drv->l2_sock_recv == NULL)
  2388. + {
  2389. + //goto bad;
  2390. + drv->l2_sock_recv = drv->l2_sock;
  2391. + printf("no br0 interface , let l2_sock_recv==l2_sock_xmit=0x%p\n", drv->l2_sock);
  2392. + }
  2393. +
  2394. + } else if (linux_br_get(brname, drv->iface) == 0) {
  2395. + wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
  2396. + "EAPOL receive", brname);
  2397. + drv->l2_sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
  2398. + rtl871x_handle_read, drv, 1);
  2399. + if (drv->l2_sock_recv == NULL)
  2400. + goto bad;
  2401. + }
  2402. + else
  2403. + {
  2404. + drv->l2_sock_recv = drv->l2_sock;
  2405. + printf("l2_sock_recv==l2_sock_xmit=0x%p\n", drv->l2_sock);
  2406. + }
  2407. +
  2408. +
  2409. + os_memset(ifrn_name, 0, sizeof(ifrn_name));
  2410. + //snprintf(ifrn_name, sizeof(ifrn_name), "mgnt.%s_rena", drv->iface);
  2411. + snprintf(ifrn_name, sizeof(ifrn_name), "mgnt.%s", "wlan0"/*drv->iface*/);
  2412. +#ifdef CONFIG_MGNT_L2SOCK
  2413. + drv->mgnt_l2_sock = NULL;
  2414. + drv->mgnt_l2_sock = l2_packet_init(ifrn_name, NULL, ETH_P_80211_RAW,
  2415. + rtl871x_recvive_mgmt_frame, drv, 1);
  2416. + if (drv->mgnt_l2_sock == NULL)
  2417. + goto bad;
  2418. +
  2419. +#else
  2420. +
  2421. +#ifdef CONFIG_MLME_OFFLOAD
  2422. + drv->mgnt_sock = -1;
  2423. +#else
  2424. + drv->mgnt_sock = rtl871x_mgnt_sock_init(drv, ifrn_name);
  2425. + if (drv->mgnt_sock < 0) {
  2426. + goto bad;
  2427. + }
  2428. +#endif
  2429. +
  2430. +#endif
  2431. +
  2432. +
  2433. + //madwifi_set_iface_flags(drv, 0); /* mark down during setup */
  2434. + //madwifi_set_privacy(drv->iface, drv, 0); /* default to no privacy */
  2435. +
  2436. +
  2437. + //linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);/*set interface up*/
  2438. +
  2439. +
  2440. + //enter MASTER MODE when init.
  2441. + if(rtl871x_set_mode(drv, IW_MODE_MASTER)<0)
  2442. + {
  2443. + printf("Could not set interface to master mode!\n");
  2444. + goto bad;
  2445. + }
  2446. +
  2447. +/*
  2448. + memset(&iwr, 0, sizeof(iwr));
  2449. + os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  2450. + iwr.u.mode = IW_MODE_MASTER;
  2451. + if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
  2452. + perror("ioctl[SIOCSIWMODE]");
  2453. + printf("Could not set interface to master mode!\n");
  2454. + goto bad;
  2455. + }
  2456. +*/
  2457. +
  2458. +#ifndef CONFIG_MLME_OFFLOAD
  2459. + rtl871x_set_iface_flags(drv, 1); /*set mgnt interface up*/
  2460. +#endif
  2461. +
  2462. +
  2463. + if (rtl871x_wireless_event_init(drv))
  2464. + goto bad;
  2465. +
  2466. +
  2467. + os_memcpy(drv->hw_mac, params->own_addr, ETH_ALEN);
  2468. +
  2469. + return drv;
  2470. +
  2471. +bad:
  2472. +
  2473. + if (drv->l2_sock_recv != NULL && drv->l2_sock_recv != drv->l2_sock)
  2474. + l2_packet_deinit(drv->l2_sock_recv);
  2475. +
  2476. + if (drv->l2_sock != NULL)
  2477. + l2_packet_deinit(drv->l2_sock);
  2478. +
  2479. + if (drv->ioctl_sock >= 0)
  2480. + close(drv->ioctl_sock);
  2481. +
  2482. +#ifdef CONFIG_MGNT_L2SOCK
  2483. + if ( drv->mgnt_l2_sock != NULL)
  2484. + l2_packet_deinit(drv->mgnt_l2_sock);
  2485. +#else
  2486. + if (drv->mgnt_sock >= 0)
  2487. + close(drv->mgnt_sock);
  2488. +#endif
  2489. +
  2490. + if (drv != NULL)
  2491. + free(drv);
  2492. +
  2493. + return NULL;
  2494. +
  2495. +}
  2496. +
  2497. +static void rtl871x_driver_deinit_ops(void *priv)
  2498. +{
  2499. + //struct iwreq iwr;
  2500. + struct rtl871x_driver_data *drv = priv;
  2501. +
  2502. + //back to INFRA MODE when exit.
  2503. +/*
  2504. + memset(&iwr, 0, sizeof(iwr));
  2505. + os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
  2506. + iwr.u.mode = IW_MODE_INFRA;
  2507. + if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
  2508. + perror("ioctl[SIOCSIWMODE]");
  2509. + }
  2510. +*/
  2511. + rtl871x_set_mode(drv, IW_MODE_INFRA);
  2512. +
  2513. +
  2514. + if (drv->ioctl_sock >= 0)
  2515. + close(drv->ioctl_sock);
  2516. +
  2517. +
  2518. + if (drv->l2_sock_recv != NULL && drv->l2_sock_recv != drv->l2_sock)
  2519. + l2_packet_deinit(drv->l2_sock_recv);
  2520. +
  2521. + if(drv->l2_sock)
  2522. + l2_packet_deinit(drv->l2_sock);
  2523. +
  2524. + //if (drv->sock_xmit != NULL)
  2525. + // l2_packet_deinit(drv->sock_xmit);
  2526. +
  2527. +#ifdef CONFIG_MGNT_L2SOCK
  2528. + if (drv->mgnt_l2_sock)
  2529. + l2_packet_deinit(drv->mgnt_l2_sock);
  2530. +#else
  2531. + if (drv->mgnt_sock >= 0)
  2532. + close(drv->mgnt_sock);
  2533. +#endif
  2534. +
  2535. + os_free(drv);
  2536. +
  2537. +}
  2538. +
  2539. +
  2540. +const struct wpa_driver_ops wpa_driver_rtw_ops = {
  2541. + .name = "rtl871xdrv",
  2542. + //.init = rtl871x_driver_init_ops,
  2543. + //.deinit = rtl871x_driver_deinit_ops,
  2544. + .hapd_init = rtl871x_driver_init_ops,
  2545. + .hapd_deinit = rtl871x_driver_deinit_ops,
  2546. + //.wireless_event_init = rtl871x_wireless_event_init_ops,
  2547. + //.wireless_event_deinit = rtl871x_wireless_event_deinit_ops,
  2548. + //.send_eapol = rtl871x_send_eapol_ops,
  2549. + .hapd_send_eapol = rtl871x_send_eapol_ops,
  2550. + //.send_ether = rtl871x_driver_send_ether_ops,
  2551. + //.send_mgmt_frame = rtl871x_send_mgmt_frame_ops,
  2552. + .get_hw_feature_data = rtl871x_get_hw_feature_data_ops,
  2553. + //.sta_add = rtl871x_sta_add_ops,
  2554. + //.sta_add2 = rtl871x_sta_add2_ops,
  2555. + .sta_remove = rtl871x_sta_remove_ops,
  2556. + .set_ap = rtl871x_set_beacon_ops,
  2557. + //.set_encryption = rtl871x_set_encryption_ops,
  2558. + .set_key = rtl871x_set_key_ops,
  2559. + .sta_deauth = rtl871x_sta_deauth_ops,
  2560. + .sta_disassoc = rtl871x_sta_disassoc_ops,
  2561. + //.set_wps_beacon_ie = rtl871x_set_wps_beacon_ie_ops,
  2562. + //.set_wps_probe_resp_ie = rtl871x_set_wps_probe_resp_ie_ops,
  2563. + .set_ap_wps_ie = rtl871x_set_ap_wps_ie,
  2564. + .flush = rtl871x_sta_flush_ops,
  2565. +};
  2566. +
  2567. diff --git a/src/drivers/driver_wext.c b/src/drivers/driver_wext.c
  2568. index 01defdf..1091108 100644
  2569. --- a/src/drivers/driver_wext.c
  2570. +++ b/src/drivers/driver_wext.c
  2571. @@ -1081,6 +1081,38 @@ void wpa_driver_wext_scan_timeout(void *eloop_ctx, void *timeout_ctx)
  2572. wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
  2573. }
  2574.  
  2575. +//added for wps2.0 @20110519
  2576. +static int wpa_driver_wext_set_probe_req_ie(struct wpa_driver_wext_data *drv, const u8 *extra_ies,
  2577. + size_t extra_ies_len)
  2578. +{
  2579. + unsigned char *pbuf;
  2580. + struct iwreq iwr;
  2581. + int ret = 0;
  2582. +
  2583. + pbuf = os_malloc(extra_ies_len);
  2584. + os_memset(pbuf, 0, extra_ies_len);
  2585. +
  2586. + os_memset(&iwr, 0, sizeof(iwr));
  2587. + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
  2588. +
  2589. + os_memcpy(pbuf, extra_ies, extra_ies_len);
  2590. +
  2591. + iwr.u.data.pointer = (caddr_t)pbuf;
  2592. + iwr.u.data.length = extra_ies_len;
  2593. + iwr.u.data.flags = 0x8766;//magic number
  2594. +
  2595. + if (ioctl(drv->ioctl_sock, SIOCSIWPRIV, &iwr) < 0) {
  2596. + perror("ioctl[SIOCSIWMLME]");
  2597. + ret = -1;
  2598. + }
  2599. +
  2600. + if(pbuf)
  2601. + os_free(pbuf);
  2602. +
  2603. + return ret;
  2604. +
  2605. +}
  2606. +
  2607.  
  2608. /**
  2609. * wpa_driver_wext_scan - Request the driver to initiate scan
  2610. @@ -1103,6 +1135,10 @@ int wpa_driver_wext_scan(void *priv, struct wpa_driver_scan_params *params)
  2611. return -1;
  2612. }
  2613.  
  2614. + //added for wps2.0 @20110519
  2615. + wpa_driver_wext_set_probe_req_ie(drv, params->extra_ies,
  2616. + params->extra_ies_len);
  2617. +
  2618. os_memset(&iwr, 0, sizeof(iwr));
  2619. os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
  2620.  
  2621. diff --git a/src/drivers/drivers.c b/src/drivers/drivers.c
  2622. index a98af9a..d7d9c5b 100644
  2623. --- a/src/drivers/drivers.c
  2624. +++ b/src/drivers/drivers.c
  2625. @@ -45,6 +45,9 @@ extern struct wpa_driver_ops wpa_driver_atheros_ops; /* driver_atheros.c */
  2626. #ifdef CONFIG_DRIVER_NONE
  2627. extern struct wpa_driver_ops wpa_driver_none_ops; /* driver_none.c */
  2628. #endif /* CONFIG_DRIVER_NONE */
  2629. +#ifdef CONFIG_DRIVER_RTW
  2630. +extern struct wpa_driver_ops wpa_driver_rtw_ops; /* driver_rtw.c */
  2631. +#endif /* CONFIG_DRIVER_RTW */
  2632.  
  2633.  
  2634. const struct wpa_driver_ops *const wpa_drivers[] =
  2635. @@ -82,5 +85,8 @@ const struct wpa_driver_ops *const wpa_drivers[] =
  2636. #ifdef CONFIG_DRIVER_NONE
  2637. &wpa_driver_none_ops,
  2638. #endif /* CONFIG_DRIVER_NONE */
  2639. +#ifdef CONFIG_DRIVER_RTW
  2640. + &wpa_driver_rtw_ops,
  2641. +#endif /* CONFIG_DRIVER_RTW */
  2642. NULL
  2643. };
  2644. diff --git a/src/drivers/drivers.mak b/src/drivers/drivers.mak
  2645. index 3dd43c7..3e44fcb 100644
  2646. --- a/src/drivers/drivers.mak
  2647. +++ b/src/drivers/drivers.mak
  2648. @@ -74,6 +74,10 @@ DRV_CFLAGS += -DCONFIG_DRIVER_BSD
  2649. DRV_OBJS += ../src/drivers/driver_bsd.o
  2650. CONFIG_L2_FREEBSD=y
  2651. CONFIG_DNET_PCAP=y
  2652. +ifdef CONFIG_SUPPORT_RTW_DRIVER
  2653. +DRV_CFLAGS += -DCONFIG_SUPPORT_RTW_DRIVER -DCONFIG_DRIVER_RTL_DFS
  2654. +NEED_AP_MLME=y
  2655. +endif
  2656. endif
  2657.  
  2658. ifdef CONFIG_DRIVER_OPENBSD
  2659. @@ -84,6 +88,17 @@ DRV_CFLAGS += -DCONFIG_DRIVER_OPENBSD
  2660. DRV_OBJS += ../src/drivers/driver_openbsd.o
  2661. endif
  2662.  
  2663. +ifdef CONFIG_DRIVER_RTW
  2664. +#CFLAGS += -DCONFIG_DRIVER_RTL
  2665. +#OBJS += driver_rtl.o
  2666. +DRV_AP_CFLAGS += -DCONFIG_DRIVER_RTW -DCONFIG_DRIVER_RTL_DFS
  2667. +DRV_AP_OBJS += ../src/drivers/driver_rtw.o
  2668. +CONFIG_L2_PACKET=linux
  2669. +NEED_NETLINK=y
  2670. +NEED_LINUX_IOCTL=y
  2671. +NEED_AP_MLME=y
  2672. +endif
  2673. +
  2674. ifdef CONFIG_DRIVER_NONE
  2675. DRV_CFLAGS += -DCONFIG_DRIVER_NONE
  2676. DRV_OBJS += ../src/drivers/driver_none.o
  2677. diff --git a/src/eap_peer/eap_wsc.c b/src/eap_peer/eap_wsc.c
  2678. index 7ac99c7..1f7697c 100644
  2679. --- a/src/eap_peer/eap_wsc.c
  2680. +++ b/src/eap_peer/eap_wsc.c
  2681. @@ -569,8 +569,13 @@ send_msg:
  2682. r = eap_wsc_build_msg(data, ret, id);
  2683. if (data->state == FAIL && ret->methodState == METHOD_DONE) {
  2684. /* Use reduced client timeout for WPS to avoid long wait */
  2685. +#if 0 /* Aries add, 2012/06/12, extend timeout for AP IOT */
  2686. + if (sm->ClientTimeout > 4)
  2687. + sm->ClientTimeout = 4;
  2688. +#else
  2689. if (sm->ClientTimeout > 2)
  2690. sm->ClientTimeout = 2;
  2691. +#endif
  2692. }
  2693. return r;
  2694. }
  2695. diff --git a/src/wps/wps.c b/src/wps/wps.c
  2696. index fbaf85a..10a82e1 100644
  2697. --- a/src/wps/wps.c
  2698. +++ b/src/wps/wps.c
  2699. @@ -321,11 +321,15 @@ int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
  2700. if (wps_parse_msg(msg, &attr) < 0)
  2701. return 0;
  2702.  
  2703. + return is_selected_pin_registrar(&attr);
  2704. +// Marked by Albert 2011/11/17
  2705. +// Some APs won't carry the AuthorizedMACs in the probe response.
  2706. +// So, skip this check will speed up the process to find the current AP out for WPS handshake.
  2707. +/*
  2708. if (!attr.version2 && ver1_compat) {
  2709. /*
  2710. * Version 1.0 AP - AuthorizedMACs not used, so revert back to
  2711. * old mechanism of using SelectedRegistrar.
  2712. - */
  2713. return is_selected_pin_registrar(&attr);
  2714. }
  2715.  
  2716. @@ -342,6 +346,7 @@ int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
  2717. }
  2718.  
  2719. return 0;
  2720. +*/
  2721. }
  2722.  
  2723.  
  2724. diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c
  2725. index 4ca3a42..f74b036 100644
  2726. --- a/src/wps/wps_registrar.c
  2727. +++ b/src/wps/wps_registrar.c
  2728. @@ -589,9 +589,10 @@ static int wps_build_probe_config_methods(struct wps_registrar *reg,
  2729. * These are the methods that the AP supports as an Enrollee for adding
  2730. * external Registrars.
  2731. */
  2732. - methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
  2733. - methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
  2734. - WPS_CONFIG_PHY_PUSHBUTTON);
  2735. + methods = reg->wps->config_methods;
  2736. + //methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
  2737. + //methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
  2738. + // WPS_CONFIG_PHY_PUSHBUTTON);
  2739. wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
  2740. wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
  2741. wpabuf_put_be16(msg, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement