rtlxdrv.patch 73 KB

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