rtw_tdls.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_TDLS_C_
  21. #include <drv_types.h>
  22. #ifdef CONFIG_TDLS
  23. extern unsigned char MCS_rate_2R[16];
  24. extern unsigned char MCS_rate_1R[16];
  25. extern void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame);
  26. extern s32 rtw_dump_xframe(_adapter *padapter, struct xmit_frame *pxmitframe);
  27. void rtw_reset_tdls_info(_adapter* padapter)
  28. {
  29. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  30. ptdlsinfo->ap_prohibited = _FALSE;
  31. ptdlsinfo->setup_state = TDLS_STATE_NONE;
  32. ptdlsinfo->sta_cnt = 0;
  33. ptdlsinfo->sta_maximum = _FALSE;
  34. ptdlsinfo->macid_index= 6;
  35. ptdlsinfo->clear_cam= 0;
  36. ptdlsinfo->ch_sensing = 0;
  37. ptdlsinfo->cur_channel = 0;
  38. ptdlsinfo->candidate_ch = 1; //when inplement channel switching, default candidate channel is 1
  39. ptdlsinfo->watchdog_count = 0;
  40. ptdlsinfo->dev_discovered = 0;
  41. #ifdef CONFIG_WFD
  42. ptdlsinfo->wfd_info = &padapter->wfd_info;
  43. #endif //CONFIG_WFD
  44. }
  45. int rtw_init_tdls_info(_adapter* padapter)
  46. {
  47. int res = _SUCCESS;
  48. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  49. ptdlsinfo->enable = 1;
  50. rtw_reset_tdls_info(padapter);
  51. _rtw_spinlock_init(&ptdlsinfo->cmd_lock);
  52. _rtw_spinlock_init(&ptdlsinfo->hdl_lock);
  53. return res;
  54. }
  55. void rtw_free_tdls_info(struct tdls_info *ptdlsinfo)
  56. {
  57. _rtw_spinlock_free(&ptdlsinfo->cmd_lock);
  58. _rtw_spinlock_free(&ptdlsinfo->hdl_lock);
  59. _rtw_memset(ptdlsinfo, 0, sizeof(struct tdls_info) );
  60. }
  61. void issue_nulldata_to_TDLS_peer_STA(_adapter *padapter, struct sta_info *ptdls_sta, unsigned int power_mode)
  62. {
  63. struct xmit_frame *pmgntframe;
  64. struct pkt_attrib *pattrib;
  65. unsigned char *pframe;
  66. struct rtw_ieee80211_hdr *pwlanhdr;
  67. unsigned short *fctrl;
  68. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  69. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  70. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  71. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  72. {
  73. return;
  74. }
  75. //update attribute
  76. pattrib = &pmgntframe->attrib;
  77. update_mgntframe_attrib(padapter, pattrib);
  78. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  79. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  80. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  81. fctrl = &(pwlanhdr->frame_ctl);
  82. *(fctrl) = 0;
  83. // SetToDs(fctrl);
  84. if (power_mode)
  85. {
  86. SetPwrMgt(fctrl);
  87. }
  88. _rtw_memcpy(pwlanhdr->addr1, ptdls_sta->hwaddr, ETH_ALEN);
  89. _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
  90. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  91. ptdls_sta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
  92. ptdls_sta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
  93. pattrib->seqnum = ptdls_sta->sta_xmitpriv.txseq_tid[pattrib->priority];
  94. SetSeqNum(pwlanhdr, pattrib->seqnum);
  95. SetFrameSubType(pframe, WIFI_DATA_NULL);
  96. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  97. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  98. pattrib->last_txcmdsz = pattrib->pktlen;
  99. dump_mgntframe(padapter, pmgntframe);
  100. return;
  101. }
  102. s32 update_tdls_attrib(_adapter *padapter, struct pkt_attrib *pattrib)
  103. {
  104. struct sta_info *psta = NULL;
  105. struct sta_priv *pstapriv = &padapter->stapriv;
  106. struct security_priv *psecuritypriv = &padapter->securitypriv;
  107. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  108. struct qos_priv *pqospriv= &pmlmepriv->qospriv;
  109. s32 res=_SUCCESS;
  110. sint bmcast;
  111. bmcast = IS_MCAST(pattrib->ra);
  112. psta = rtw_get_stainfo(pstapriv, pattrib->ra);
  113. if (psta == NULL) {
  114. res =_FAIL;
  115. goto exit;
  116. }
  117. pattrib->mac_id = psta->mac_id;
  118. pattrib->psta = psta;
  119. pattrib->ack_policy = 0;
  120. // get ether_hdr_len
  121. pattrib->pkt_hdrlen = ETH_HLEN;//(pattrib->ether_type == 0x8100) ? (14 + 4 ): 14; //vlan tag
  122. if (pqospriv->qos_option && psta->qos_option) {
  123. pattrib->priority = 1; //tdls management frame should be AC_BK
  124. pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
  125. pattrib->subtype = WIFI_QOS_DATA_TYPE;
  126. } else {
  127. pattrib->hdrlen = WLAN_HDR_A3_LEN;
  128. pattrib->subtype = WIFI_DATA_TYPE;
  129. pattrib->priority = 0;
  130. }
  131. if (psta->ieee8021x_blocked == _TRUE)
  132. {
  133. pattrib->encrypt = 0;
  134. }
  135. else
  136. {
  137. GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
  138. switch(psecuritypriv->dot11AuthAlgrthm)
  139. {
  140. case dot11AuthAlgrthm_Open:
  141. case dot11AuthAlgrthm_Shared:
  142. case dot11AuthAlgrthm_Auto:
  143. pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
  144. break;
  145. case dot11AuthAlgrthm_8021X:
  146. pattrib->key_idx = 0;
  147. break;
  148. default:
  149. pattrib->key_idx = 0;
  150. break;
  151. }
  152. }
  153. switch (pattrib->encrypt)
  154. {
  155. case _WEP40_:
  156. case _WEP104_:
  157. pattrib->iv_len = 4;
  158. pattrib->icv_len = 4;
  159. break;
  160. case _TKIP_:
  161. pattrib->iv_len = 8;
  162. pattrib->icv_len = 4;
  163. if(padapter->securitypriv.busetkipkey==_FAIL)
  164. {
  165. res =_FAIL;
  166. goto exit;
  167. }
  168. break;
  169. case _AES_:
  170. pattrib->iv_len = 8;
  171. pattrib->icv_len = 8;
  172. break;
  173. default:
  174. pattrib->iv_len = 0;
  175. pattrib->icv_len = 0;
  176. break;
  177. }
  178. if (pattrib->encrypt &&
  179. ((padapter->securitypriv.sw_encrypt == _TRUE) || (psecuritypriv->hw_decrypted == _FALSE)))
  180. {
  181. pattrib->bswenc = _TRUE;
  182. } else {
  183. pattrib->bswenc = _FALSE;
  184. }
  185. //qos_en, ht_en, init rate, ,bw, ch_offset, sgi
  186. pattrib->qos_en = psta->qos_option;
  187. pattrib->ht_en = psta->htpriv.ht_option;
  188. pattrib->raid = psta->raid;
  189. pattrib->bwmode = psta->htpriv.bwmode;
  190. pattrib->ch_offset = psta->htpriv.ch_offset;
  191. pattrib->sgi= psta->htpriv.sgi;
  192. pattrib->ampdu_en = _FALSE;
  193. //if(pattrib->ht_en && psta->htpriv.ampdu_enable)
  194. //{
  195. // if(psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
  196. // pattrib->ampdu_en = _TRUE;
  197. //}
  198. exit:
  199. return res;
  200. }
  201. void free_tdls_sta(_adapter *padapter, struct sta_info *ptdls_sta)
  202. {
  203. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  204. struct sta_priv *pstapriv = &padapter->stapriv;
  205. _irqL irqL;
  206. //free peer sta_info
  207. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  208. if(ptdlsinfo->sta_cnt != 0)
  209. ptdlsinfo->sta_cnt--;
  210. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  211. if( ptdlsinfo->sta_cnt < (NUM_STA - 2) ) // -2: AP + BC/MC sta
  212. {
  213. ptdlsinfo->sta_maximum = _FALSE;
  214. _rtw_memset( &ptdlsinfo->ss_record, 0x00, sizeof(struct tdls_ss_record) );
  215. }
  216. //ready to clear cam
  217. if(ptdls_sta->mac_id!=0){
  218. ptdlsinfo->clear_cam=ptdls_sta->mac_id;
  219. rtw_setstakey_cmd(padapter, (u8 *)ptdls_sta, _TRUE);
  220. }
  221. if(ptdlsinfo->sta_cnt==0){
  222. rtw_tdls_cmd(padapter, myid(&(padapter->eeprompriv)), TDLS_RS_RCR);
  223. ptdlsinfo->setup_state=TDLS_STATE_NONE;
  224. }
  225. else
  226. DBG_871X("Remain tdls sta:%02x\n", ptdlsinfo->sta_cnt);
  227. rtw_free_stainfo(padapter, ptdls_sta);
  228. }
  229. // cam entry will be the same as mac_id
  230. void rtw_tdls_set_mac_id(struct tdls_info *ptdlsinfo, struct sta_info *ptdls_sta)
  231. {
  232. if(ptdls_sta->mac_id==0)
  233. {
  234. ptdls_sta->mac_id = ptdlsinfo->macid_index;
  235. if( (++ptdlsinfo->macid_index) > (NUM_STA -2) )
  236. ptdlsinfo->macid_index= TDLS_INI_MACID_ENTRY;
  237. }
  238. }
  239. //TDLS encryption(if needed) will always be CCMP
  240. void rtw_tdls_set_key(_adapter *adapter, struct rx_pkt_attrib *prx_pkt_attrib, struct sta_info *ptdls_sta)
  241. {
  242. if(prx_pkt_attrib->encrypt)
  243. {
  244. ptdls_sta->dot118021XPrivacy=_AES_;
  245. rtw_setstakey_cmd(adapter, (u8*)ptdls_sta, _TRUE);
  246. }
  247. }
  248. void rtw_tdls_process_ht_cap(_adapter *adapter, struct sta_info *ptdls_sta, u8 *data, u8 Length)
  249. {
  250. /* save HT capabilities in the sta object */
  251. _rtw_memset(&ptdls_sta->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
  252. if (data && Length >= sizeof(struct rtw_ieee80211_ht_cap) )
  253. {
  254. ptdls_sta->flags |= WLAN_STA_HT;
  255. ptdls_sta->flags |= WLAN_STA_WME;
  256. _rtw_memcpy(&ptdls_sta->htpriv.ht_cap, data, sizeof(struct rtw_ieee80211_ht_cap));
  257. } else
  258. ptdls_sta->flags &= ~WLAN_STA_HT;
  259. if(ptdls_sta->flags & WLAN_STA_HT)
  260. {
  261. if(adapter->registrypriv.ht_enable == _TRUE)
  262. {
  263. ptdls_sta->htpriv.ht_option = _TRUE;
  264. }
  265. else
  266. {
  267. ptdls_sta->htpriv.ht_option = _FALSE;
  268. ptdls_sta->stat_code = _STATS_FAILURE_;
  269. }
  270. }
  271. //HT related cap
  272. if(ptdls_sta->htpriv.ht_option)
  273. {
  274. //check if sta supports rx ampdu
  275. if(adapter->registrypriv.ampdu_enable==1)
  276. ptdls_sta->htpriv.ampdu_enable = _TRUE;
  277. //check if sta support s Short GI
  278. if(ptdls_sta->htpriv.ht_cap.cap_info & cpu_to_le16(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40))
  279. {
  280. ptdls_sta->htpriv.sgi = _TRUE;
  281. }
  282. // bwmode would still followed AP's setting
  283. if(ptdls_sta->htpriv.ht_cap.cap_info & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
  284. {
  285. ptdls_sta->htpriv.bwmode = adapter->mlmeextpriv.cur_bwmode;
  286. ptdls_sta->htpriv.ch_offset = adapter->mlmeextpriv.cur_ch_offset;
  287. }
  288. }
  289. }
  290. u8 *rtw_tdls_set_ht_cap(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
  291. {
  292. struct rtw_ieee80211_ht_cap ht_capie;
  293. u8 rf_type;
  294. //HT capabilities
  295. _rtw_memset(&ht_capie, 0, sizeof(struct rtw_ieee80211_ht_cap));
  296. ht_capie.cap_info = IEEE80211_HT_CAP_SUP_WIDTH |IEEE80211_HT_CAP_SGI_20 |IEEE80211_HT_CAP_SM_PS |
  297. IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_TX_STBC |IEEE80211_HT_CAP_DSSSCCK40;
  298. {
  299. u32 rx_packet_offset, max_recvbuf_sz;
  300. padapter->HalFunc.GetHalDefVarHandler(padapter, HAL_DEF_RX_PACKET_OFFSET, &rx_packet_offset);
  301. padapter->HalFunc.GetHalDefVarHandler(padapter, HAL_DEF_MAX_RECVBUF_SZ, &max_recvbuf_sz);
  302. if(max_recvbuf_sz-rx_packet_offset>(8191-256))
  303. ht_capie.cap_info = ht_capie.cap_info |IEEE80211_HT_CAP_MAX_AMSDU;
  304. }
  305. ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR&0x03);
  306. padapter->HalFunc.GetHwRegHandler(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  307. switch(rf_type)
  308. {
  309. case RF_1T1R:
  310. ht_capie.cap_info |= 0x0100;//RX STBC One spatial stream
  311. _rtw_memcpy(ht_capie.supp_mcs_set, MCS_rate_1R, 16);
  312. break;
  313. case RF_2T2R:
  314. case RF_1T2R:
  315. default:
  316. ht_capie.cap_info|= 0x0200;//RX STBC two spatial stream
  317. _rtw_memcpy(ht_capie.supp_mcs_set, MCS_rate_2R, 16);
  318. break;
  319. }
  320. return(rtw_set_ie(pframe, _HT_CAPABILITY_IE_,
  321. sizeof(struct rtw_ieee80211_ht_cap), (unsigned char*)&ht_capie, &(pattrib->pktlen)));
  322. }
  323. u8 *rtw_tdls_set_sup_ch(struct mlme_ext_priv *pmlmeext, u8 *pframe, struct pkt_attrib *pattrib)
  324. {
  325. u8 sup_ch[ 30 * 2 ] = { 0x00 }, sup_ch_idx = 0, idx_5g = 2; //For supported channel
  326. do{
  327. if( pmlmeext->channel_set[sup_ch_idx].ChannelNum <= 14 )
  328. {
  329. sup_ch[0] = 1; //First channel number
  330. sup_ch[1] = pmlmeext->channel_set[sup_ch_idx].ChannelNum; //Number of channel
  331. }
  332. else
  333. {
  334. sup_ch[idx_5g++] = pmlmeext->channel_set[sup_ch_idx].ChannelNum;
  335. sup_ch[idx_5g++] = 1;
  336. }
  337. sup_ch_idx++;
  338. }
  339. while( pmlmeext->channel_set[sup_ch_idx].ChannelNum != 0 );
  340. return(rtw_set_ie(pframe, _SUPPORTED_CH_IE_, idx_5g, sup_ch, &(pattrib->pktlen)));
  341. }
  342. #ifdef CONFIG_WFD
  343. void rtw_tdls_process_wfd_ie(struct tdls_info *ptdlsinfo, u8 *ptr, u8 length)
  344. {
  345. u8 wfd_ie[ 128 ] = { 0x00 };
  346. u32 wfd_ielen = 0;
  347. u32 wfd_offset = 0;
  348. // Try to get the TCP port information when receiving the negotiation response.
  349. //
  350. wfd_offset = 0;
  351. wfd_offset = rtw_get_wfd_ie( ptr + wfd_offset, length - wfd_offset, wfd_ie, &wfd_ielen );
  352. while( wfd_offset )
  353. {
  354. u8 attr_content[ 10 ] = { 0x00 };
  355. u32 attr_contentlen = 0;
  356. int i;
  357. DBG_871X( "[%s] WFD IE Found!!\n", __FUNCTION__ );
  358. rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, attr_content, &attr_contentlen);
  359. if ( attr_contentlen )
  360. {
  361. ptdlsinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16( attr_content + 2 );
  362. DBG_871X( "[%s] Peer PORT NUM = %d\n", __FUNCTION__, ptdlsinfo->wfd_info->peer_rtsp_ctrlport );
  363. }
  364. _rtw_memset( attr_content, 0x00, 10);
  365. attr_contentlen = 0;
  366. rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_LOCAL_IP_ADDR, attr_content, &attr_contentlen);
  367. if ( attr_contentlen )
  368. {
  369. _rtw_memcpy(ptdlsinfo->wfd_info->peer_ip_address, ( attr_content + 1 ), 4);
  370. DBG_871X( "[%s] Peer IP = %02u.%02u.%02u.%02u \n", __FUNCTION__,
  371. ptdlsinfo->wfd_info->peer_ip_address[0], ptdlsinfo->wfd_info->peer_ip_address[1],
  372. ptdlsinfo->wfd_info->peer_ip_address[2], ptdlsinfo->wfd_info->peer_ip_address[3]
  373. );
  374. }
  375. wfd_offset = rtw_get_wfd_ie( ptr + wfd_offset, length - wfd_offset, wfd_ie, &wfd_ielen );
  376. }
  377. }
  378. void issue_tunneled_probe_req(_adapter *padapter)
  379. {
  380. struct xmit_frame *pmgntframe;
  381. struct pkt_attrib *pattrib;
  382. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  383. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  384. u8 baddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  385. DBG_871X("[%s]\n", __FUNCTION__);
  386. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  387. {
  388. return;
  389. }
  390. //update attribute
  391. pattrib = &pmgntframe->attrib;
  392. pmgntframe->frame_tag = DATA_FRAMETAG;
  393. pattrib->ether_type = 0x890d;
  394. _rtw_memcpy(pattrib->dst, baddr, ETH_ALEN);
  395. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  396. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  397. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  398. update_tdls_attrib(padapter, pattrib);
  399. pattrib->qsel=pattrib->priority;
  400. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TUNNELED_PROBE_REQ) != _SUCCESS) {
  401. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  402. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  403. goto exit;
  404. }
  405. rtw_dump_xframe(padapter, pmgntframe);
  406. exit:
  407. return;
  408. }
  409. void issue_tunneled_probe_rsp(_adapter *padapter, union recv_frame *precv_frame)
  410. {
  411. struct xmit_frame *pmgntframe;
  412. struct pkt_attrib *pattrib;
  413. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  414. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  415. struct rx_pkt_attrib *rx_pkt_pattrib = &precv_frame->u.hdr.attrib;
  416. DBG_871X("[%s]\n", __FUNCTION__);
  417. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  418. {
  419. return;
  420. }
  421. //update attribute
  422. pattrib = &pmgntframe->attrib;
  423. pmgntframe->frame_tag = DATA_FRAMETAG;
  424. pattrib->ether_type = 0x890d;
  425. _rtw_memcpy(pattrib->dst, rx_pkt_pattrib->src, ETH_ALEN);
  426. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  427. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  428. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  429. update_tdls_attrib(padapter, pattrib);
  430. pattrib->qsel=pattrib->priority;
  431. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TUNNELED_PROBE_RSP) != _SUCCESS) {
  432. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  433. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  434. goto exit;
  435. }
  436. rtw_dump_xframe(padapter, pmgntframe);
  437. exit:
  438. return;
  439. }
  440. #endif //CONFIG_WFD
  441. void issue_tdls_setup_req(_adapter *padapter, u8 *mac_addr)
  442. {
  443. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  444. struct xmit_frame *pmgntframe;
  445. struct pkt_attrib *pattrib;
  446. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  447. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  448. struct sta_priv *pstapriv = &padapter->stapriv;
  449. struct sta_info *ptdls_sta= NULL;
  450. _irqL irqL;
  451. static u8 dialogtoken = 0;
  452. u32 timeout_interval= TPK_RESEND_COUNT * 1000; //retry timer should set at least 301 sec, using TPK_count counting 301 times.
  453. if(ptdlsinfo->ap_prohibited == _TRUE)
  454. goto exit;
  455. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  456. {
  457. return;
  458. }
  459. //update attribute
  460. pattrib = &pmgntframe->attrib;
  461. pmgntframe->frame_tag = DATA_FRAMETAG;
  462. pattrib->ether_type = 0x890d;
  463. _rtw_memcpy(pattrib->dst, mac_addr, ETH_ALEN);
  464. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  465. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  466. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  467. update_tdls_attrib(padapter, pattrib);
  468. //init peer sta_info
  469. ptdls_sta = rtw_get_stainfo(pstapriv, mac_addr);
  470. if(ptdls_sta==NULL)
  471. {
  472. ptdls_sta = rtw_alloc_stainfo(pstapriv, mac_addr);
  473. if(ptdls_sta)
  474. {
  475. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  476. if(!(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE))
  477. ptdlsinfo->sta_cnt++;
  478. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  479. if( ptdlsinfo->sta_cnt == (NUM_STA - 2) ) // -2: AP + BC/MC sta
  480. {
  481. ptdlsinfo->sta_maximum = _TRUE;
  482. }
  483. }
  484. else
  485. {
  486. rtw_free_xmitbuf(pxmitpriv,pmgntframe->pxmitbuf);
  487. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  488. goto exit;
  489. }
  490. }
  491. if(ptdls_sta){
  492. ptdls_sta->tdls_sta_state |= TDLS_RESPONDER_STATE;
  493. //for tdls; ptdls_sta->aid is used to fill dialogtoken
  494. ptdls_sta->dialog = dialogtoken;
  495. dialogtoken = (dialogtoken+1)%256;
  496. ptdls_sta->TDLS_PeerKey_Lifetime = timeout_interval;
  497. _set_timer( &ptdls_sta->handshake_timer, TDLS_HANDSHAKE_TIME );
  498. }
  499. pattrib->qsel=pattrib->priority;
  500. if(rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_SETUP_REQUEST) !=_SUCCESS ){
  501. rtw_free_xmitbuf(pxmitpriv,pmgntframe->pxmitbuf);
  502. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  503. goto exit;
  504. }
  505. rtw_dump_xframe(padapter, pmgntframe);
  506. exit:
  507. return;
  508. }
  509. void issue_tdls_teardown(_adapter *padapter, u8 *mac_addr)
  510. {
  511. struct xmit_frame *pmgntframe;
  512. struct pkt_attrib *pattrib;
  513. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  514. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  515. struct sta_priv *pstapriv = &padapter->stapriv;
  516. struct sta_info *ptdls_sta=NULL;
  517. _irqL irqL;
  518. ptdls_sta = rtw_get_stainfo(pstapriv, mac_addr);
  519. if(ptdls_sta==NULL){
  520. DBG_871X("issue tdls teardown unsuccessful\n");
  521. return;
  522. }else{
  523. ptdls_sta->tdls_sta_state=TDLS_STATE_NONE;
  524. }
  525. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  526. {
  527. return;
  528. }
  529. //update attribute
  530. pattrib = &pmgntframe->attrib;
  531. pmgntframe->frame_tag = DATA_FRAMETAG;
  532. pattrib->ether_type = 0x890d;
  533. _rtw_memcpy(pattrib->dst, mac_addr, ETH_ALEN);
  534. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  535. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  536. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  537. update_tdls_attrib(padapter, pattrib);
  538. pattrib->qsel=pattrib->priority;
  539. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_TEARDOWN) != _SUCCESS) {
  540. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  541. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  542. goto exit;
  543. }
  544. rtw_dump_xframe(padapter, pmgntframe);
  545. if(ptdls_sta->tdls_sta_state & TDLS_CH_SWITCH_ON_STATE){
  546. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CS_OFF);
  547. }
  548. if( ptdls_sta->timer_flag == 1 )
  549. {
  550. _enter_critical_bh(&(padapter->tdlsinfo.hdl_lock), &irqL);
  551. ptdls_sta->timer_flag = 2;
  552. _exit_critical_bh(&(padapter->tdlsinfo.hdl_lock), &irqL);
  553. }
  554. else
  555. rtw_tdls_cmd(padapter, mac_addr, TDLS_FREE_STA );
  556. exit:
  557. return;
  558. }
  559. void issue_tdls_dis_req(_adapter *padapter, u8 *mac_addr)
  560. {
  561. struct xmit_frame *pmgntframe;
  562. struct pkt_attrib *pattrib;
  563. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  564. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  565. u8 baddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  566. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  567. {
  568. return;
  569. }
  570. //update attribute
  571. pattrib = &pmgntframe->attrib;
  572. pmgntframe->frame_tag = DATA_FRAMETAG;
  573. pattrib->ether_type = 0x890d;
  574. if(mac_addr == NULL)
  575. _rtw_memcpy(pattrib->dst, baddr, ETH_ALEN);
  576. else
  577. _rtw_memcpy(pattrib->dst, mac_addr, ETH_ALEN);
  578. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  579. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  580. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  581. update_tdls_attrib(padapter, pattrib);
  582. pattrib->qsel=pattrib->priority;
  583. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_DISCOVERY_REQUEST) != _SUCCESS) {
  584. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  585. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  586. goto exit;
  587. }
  588. rtw_dump_xframe(padapter, pmgntframe);
  589. DBG_871X("issue tdls dis req\n");
  590. exit:
  591. return;
  592. }
  593. void issue_tdls_setup_rsp(_adapter *padapter, union recv_frame *precv_frame)
  594. {
  595. struct xmit_frame *pmgntframe;
  596. struct pkt_attrib *pattrib;
  597. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  598. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  599. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  600. struct rx_pkt_attrib *rx_pkt_pattrib = &precv_frame->u.hdr.attrib;
  601. _irqL irqL;
  602. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  603. {
  604. return;
  605. }
  606. //update attribute
  607. pattrib = &pmgntframe->attrib;
  608. pmgntframe->frame_tag = DATA_FRAMETAG;
  609. pattrib->ether_type = 0x890d;
  610. _rtw_memcpy(pattrib->dst, rx_pkt_pattrib->src, ETH_ALEN);
  611. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  612. _rtw_memcpy(pattrib->ra, rx_pkt_pattrib->bssid, ETH_ALEN);
  613. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  614. update_tdls_attrib(padapter, pattrib);
  615. pattrib->qsel=pattrib->priority;
  616. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_SETUP_RESPONSE) != _SUCCESS) {
  617. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  618. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  619. goto exit;
  620. }
  621. rtw_dump_xframe(padapter, pmgntframe);
  622. exit:
  623. return;
  624. }
  625. void issue_tdls_setup_cfm(_adapter *padapter, union recv_frame *precv_frame)
  626. {
  627. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  628. struct xmit_frame *pmgntframe;
  629. struct pkt_attrib *pattrib;
  630. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  631. struct sta_info *ptdls_sta=NULL;
  632. _irqL irqL;
  633. struct rx_pkt_attrib *rx_pkt_pattrib = & precv_frame->u.hdr.attrib;
  634. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  635. {
  636. return;
  637. }
  638. //update attribute
  639. pattrib = &pmgntframe->attrib;
  640. pmgntframe->frame_tag = DATA_FRAMETAG;
  641. pattrib->ether_type = 0x890d;
  642. _rtw_memcpy(pattrib->dst, rx_pkt_pattrib->src, ETH_ALEN);
  643. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  644. _rtw_memcpy(pattrib->ra, rx_pkt_pattrib->bssid, ETH_ALEN);
  645. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  646. update_tdls_attrib(padapter, pattrib);
  647. pattrib->qsel=pattrib->priority;
  648. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_SETUP_CONFIRM) != _SUCCESS) {
  649. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  650. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  651. goto exit;
  652. }
  653. rtw_dump_xframe(padapter, pmgntframe);
  654. exit:
  655. return;
  656. }
  657. //TDLS Discovery Response frame is a management action frame
  658. void issue_tdls_dis_rsp(_adapter *padapter, union recv_frame *precv_frame, u8 dialog)
  659. {
  660. struct xmit_frame *pmgntframe;
  661. struct pkt_attrib *pattrib;
  662. unsigned char *pframe;
  663. struct rtw_ieee80211_hdr *pwlanhdr;
  664. unsigned short *fctrl;
  665. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  666. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  667. struct rx_pkt_attrib *rx_pkt_pattrib = &precv_frame->u.hdr.attrib;
  668. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  669. {
  670. return;
  671. }
  672. //update attribute
  673. pattrib = &pmgntframe->attrib;
  674. update_mgntframe_attrib(padapter, pattrib);
  675. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  676. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  677. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  678. fctrl = &(pwlanhdr->frame_ctl);
  679. *(fctrl) = 0;
  680. // unicast probe request frame
  681. _rtw_memcpy(pwlanhdr->addr1, rx_pkt_pattrib->src, ETH_ALEN);
  682. _rtw_memcpy(pattrib->dst, pwlanhdr->addr1, ETH_ALEN);
  683. _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
  684. _rtw_memcpy(pattrib->src, pwlanhdr->addr2, ETH_ALEN);
  685. _rtw_memcpy(pwlanhdr->addr3, rx_pkt_pattrib->bssid, ETH_ALEN);
  686. _rtw_memcpy(pattrib->ra, pwlanhdr->addr3, ETH_ALEN);
  687. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  688. pmlmeext->mgnt_seq++;
  689. SetFrameSubType(pframe, WIFI_ACTION);
  690. pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
  691. pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
  692. rtw_build_tdls_dis_rsp_ies(padapter, pmgntframe, pframe, dialog);
  693. pattrib->nr_frags = 1;
  694. pattrib->last_txcmdsz = pattrib->pktlen;
  695. dump_mgntframe(padapter, pmgntframe);
  696. return;
  697. }
  698. void issue_tdls_peer_traffic_indication(_adapter *padapter, struct sta_info *ptdls_sta)
  699. {
  700. struct xmit_frame *pmgntframe;
  701. struct pkt_attrib *pattrib;
  702. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  703. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  704. static u8 dialogtoken=0;
  705. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  706. {
  707. return;
  708. }
  709. //update attribute
  710. pattrib = &pmgntframe->attrib;
  711. pmgntframe->frame_tag = DATA_FRAMETAG;
  712. pattrib->ether_type = 0x890d;
  713. _rtw_memcpy(pattrib->dst, ptdls_sta->hwaddr, ETH_ALEN);
  714. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  715. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  716. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  717. //for tdls; pattrib->nr_frags is used to fill dialogtoken
  718. ptdls_sta->dialog = dialogtoken;
  719. dialogtoken = (dialogtoken+1)%256;
  720. //PTI frame's priority should be AC_VO
  721. pattrib->priority = 7;
  722. update_tdls_attrib(padapter, pattrib);
  723. pattrib->qsel=pattrib->priority;
  724. if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_PEER_TRAFFIC_INDICATION) != _SUCCESS) {
  725. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  726. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  727. goto exit;
  728. }
  729. rtw_dump_xframe(padapter, pmgntframe);
  730. exit:
  731. return;
  732. }
  733. void issue_tdls_ch_switch_req(_adapter *padapter, u8 *mac_addr)
  734. {
  735. struct xmit_frame *pmgntframe;
  736. struct pkt_attrib *pattrib;
  737. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  738. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  739. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  740. {
  741. return;
  742. }
  743. //update attribute
  744. pattrib = &pmgntframe->attrib;
  745. pmgntframe->frame_tag = DATA_FRAMETAG;
  746. pattrib->ether_type = 0x890d;
  747. _rtw_memcpy(pattrib->dst, mac_addr, ETH_ALEN);
  748. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  749. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  750. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  751. update_tdls_attrib(padapter, pattrib);
  752. pattrib->qsel=pattrib->priority;
  753. if(rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_CHANNEL_SWITCH_REQUEST) !=_SUCCESS ){
  754. rtw_free_xmitbuf(pxmitpriv,pmgntframe->pxmitbuf);
  755. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  756. goto exit;
  757. }
  758. rtw_dump_xframe(padapter, pmgntframe);
  759. exit:
  760. return;
  761. }
  762. void issue_tdls_ch_switch_rsp(_adapter *padapter, u8 *mac_addr)
  763. {
  764. struct xmit_frame *pmgntframe;
  765. struct pkt_attrib *pattrib;
  766. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  767. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  768. _irqL irqL;
  769. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  770. {
  771. return;
  772. }
  773. //update attribute
  774. pattrib = &pmgntframe->attrib;
  775. pmgntframe->frame_tag = DATA_FRAMETAG;
  776. pattrib->ether_type = 0x890d;
  777. _rtw_memcpy(pattrib->dst, mac_addr, ETH_ALEN);
  778. _rtw_memcpy(pattrib->src, myid(&(padapter->eeprompriv)), ETH_ALEN);
  779. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  780. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  781. update_tdls_attrib(padapter, pattrib);
  782. pattrib->qsel=pattrib->priority;
  783. /*
  784. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  785. if(xmitframe_enqueue_for_tdls_sleeping_sta(padapter, pmgntframe)==_TRUE){
  786. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  787. return _FALSE;
  788. }
  789. */
  790. if(rtw_xmit_tdls_coalesce(padapter, pmgntframe, TDLS_CHANNEL_SWITCH_RESPONSE) !=_SUCCESS ){
  791. rtw_free_xmitbuf(pxmitpriv,pmgntframe->pxmitbuf);
  792. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  793. goto exit;
  794. }
  795. rtw_dump_xframe(padapter, pmgntframe);
  796. exit:
  797. return;
  798. }
  799. sint On_TDLS_Dis_Rsp(_adapter *adapter, union recv_frame *precv_frame)
  800. {
  801. struct sta_info *ptdls_sta = NULL, *psta = rtw_get_stainfo(&(adapter->stapriv), get_bssid(&(adapter->mlmepriv)));
  802. struct recv_priv *precvpriv = &(adapter->recvpriv);
  803. u8 *ptr = precv_frame->u.hdr.rx_data, *psa;
  804. struct rx_pkt_attrib *pattrib = &(precv_frame->u.hdr.attrib);
  805. struct tdls_info *ptdlsinfo = &(adapter->tdlsinfo);
  806. u8 empty_addr[ETH_ALEN] = { 0x00 };
  807. int UndecoratedSmoothedPWDB;
  808. //WFDTDLS: for sigma test, not to setup direct link automatically
  809. ptdlsinfo->dev_discovered = 1;
  810. #ifdef CONFIG_TDLS_AUTOSETUP
  811. psa = get_sa(ptr);
  812. ptdls_sta = rtw_get_stainfo(&(adapter->stapriv), psa);
  813. if(ptdls_sta != NULL)
  814. {
  815. ptdls_sta->tdls_sta_state |= TDLS_ALIVE_STATE;
  816. //Record the tdls sta with lowest signal strength
  817. if( (ptdlsinfo->sta_maximum == _TRUE) && (ptdls_sta->alive_count >= 1) )
  818. {
  819. if( _rtw_memcmp(ptdlsinfo->ss_record.macaddr, empty_addr, ETH_ALEN) )
  820. {
  821. _rtw_memcpy(ptdlsinfo->ss_record.macaddr, psa, ETH_ALEN);
  822. ptdlsinfo->ss_record.RxPWDBAll = pattrib->RxPWDBAll;
  823. }
  824. else
  825. {
  826. if( ptdlsinfo->ss_record.RxPWDBAll < pattrib->RxPWDBAll )
  827. {
  828. _rtw_memcpy(ptdlsinfo->ss_record.macaddr, psa, ETH_ALEN);
  829. ptdlsinfo->ss_record.RxPWDBAll = pattrib->RxPWDBAll;
  830. }
  831. }
  832. }
  833. }
  834. else
  835. {
  836. if( ptdlsinfo->sta_maximum == _TRUE)
  837. {
  838. if( _rtw_memcmp( ptdlsinfo->ss_record.macaddr, empty_addr, ETH_ALEN ) )
  839. {
  840. //All traffics are busy, do not set up another direct link.
  841. return _FAIL;
  842. }
  843. else
  844. {
  845. if( pattrib->RxPWDBAll > ptdlsinfo->ss_record.RxPWDBAll )
  846. {
  847. issue_tdls_teardown(adapter, ptdlsinfo->ss_record.macaddr);
  848. }
  849. else
  850. {
  851. return _FAIL;
  852. }
  853. }
  854. }
  855. adapter->HalFunc.GetHalDefVarHandler(adapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
  856. if( pattrib->RxPWDBAll + TDLS_SIGNAL_THRESH >= UndecoratedSmoothedPWDB);
  857. {
  858. DBG_871X("pattrib->RxPWDBAll=%d, pdmpriv->UndecoratedSmoothedPWDB=%d\n", pattrib->RxPWDBAll, UndecoratedSmoothedPWDB);
  859. issue_tdls_setup_req(adapter, psa);
  860. }
  861. }
  862. #endif //CONFIG_TDLS_AUTOSETUP
  863. return _SUCCESS;
  864. }
  865. sint On_TDLS_Setup_Req(_adapter *adapter, union recv_frame *precv_frame)
  866. {
  867. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  868. u8 *psa, *pmyid;
  869. struct sta_info *ptdls_sta= NULL;
  870. struct sta_priv *pstapriv = &adapter->stapriv;
  871. u8 *ptr = precv_frame->u.hdr.rx_data;
  872. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  873. struct security_priv *psecuritypriv = &adapter->securitypriv;
  874. _irqL irqL;
  875. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  876. u8 *prsnie, *ppairwise_cipher;
  877. u8 i, k, pairwise_count;
  878. u8 ccmp_have=0, rsnie_have=0;
  879. u16 j;
  880. u8 SNonce[32];
  881. u32 *timeout_interval;
  882. sint parsing_length; //frame body length, without icv_len
  883. PNDIS_802_11_VARIABLE_IEs pIE;
  884. u8 FIXED_IE = 5;
  885. unsigned char supportRate[16];
  886. int supportRateNum = 0;
  887. psa = get_sa(ptr);
  888. ptdls_sta = rtw_get_stainfo(pstapriv, psa);
  889. pmyid=myid(&(adapter->eeprompriv));
  890. ptr +=prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len+LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE+1;
  891. parsing_length= ((union recv_frame *)precv_frame)->u.hdr.len
  892. -prx_pkt_attrib->hdrlen
  893. -prx_pkt_attrib->iv_len
  894. -prx_pkt_attrib->icv_len
  895. -LLC_HEADER_SIZE
  896. -ETH_TYPE_LEN
  897. -PAYLOAD_TYPE_LEN
  898. -FIXED_IE;
  899. if(ptdlsinfo->ap_prohibited == _TRUE)
  900. {
  901. goto exit;
  902. }
  903. if(ptdls_sta==NULL){
  904. ptdls_sta = rtw_alloc_stainfo(pstapriv, psa);
  905. }else{
  906. if(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE){
  907. //If the direct link is already set up
  908. //Process as re-setup after tear down
  909. DBG_871X("re-setup a direct link\n");
  910. }
  911. //already receiving TDLS setup request
  912. else if(ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE){
  913. DBG_871X("receive duplicated TDLS setup request frame in handshaking\n");
  914. goto exit;
  915. }
  916. //When receiving and sending setup_req to the same link at the same time, STA with higher MAC_addr would be initiator
  917. //following is to check out MAC_addr
  918. else if(ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE){
  919. DBG_871X("receive setup_req after sending setup_req\n");
  920. for (i=0;i<6;i++){
  921. if(*(pmyid+i)==*(psa+i)){
  922. }
  923. else if(*(pmyid+i)>*(psa+i)){
  924. goto exit;
  925. }else if(*(pmyid+i)<*(psa+i)){
  926. ptdls_sta->tdls_sta_state=TDLS_INITIATOR_STATE;
  927. break;
  928. }
  929. }
  930. }
  931. }
  932. if(ptdls_sta)
  933. {
  934. ptdls_sta->dialog = *(ptr+2); //copy dialog token
  935. ptdls_sta->stat_code = 0;
  936. //parsing information element
  937. for(j=FIXED_IE; j<parsing_length;){
  938. pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr+ j);
  939. switch (pIE->ElementID)
  940. {
  941. case _SUPPORTEDRATES_IE_:
  942. _rtw_memcpy(supportRate, pIE->data, pIE->Length);
  943. supportRateNum = pIE->Length;
  944. break;
  945. case _COUNTRY_IE_:
  946. break;
  947. case _EXT_SUPPORTEDRATES_IE_:
  948. if(supportRateNum<=sizeof(supportRate))
  949. {
  950. _rtw_memcpy(supportRate+supportRateNum, pIE->data, pIE->Length);
  951. supportRateNum += pIE->Length;
  952. }
  953. break;
  954. case _SUPPORTED_CH_IE_:
  955. break;
  956. case _RSN_IE_2_:
  957. rsnie_have=1;
  958. if(prx_pkt_attrib->encrypt){
  959. prsnie=(u8*)pIE;
  960. //check whether initiator STA has CCMP pairwise_cipher.
  961. ppairwise_cipher=prsnie+10;
  962. _rtw_memcpy(&pairwise_count, (u16*)(ppairwise_cipher-2), 1);
  963. for(k=0;k<pairwise_count;k++){
  964. if(_rtw_memcmp( ppairwise_cipher+4*k, RSN_CIPHER_SUITE_CCMP, 4)==_TRUE)
  965. ccmp_have=1;
  966. }
  967. if(ccmp_have==0){
  968. //invalid contents of RSNIE
  969. ptdls_sta->stat_code=72;
  970. }
  971. }
  972. break;
  973. case _EXT_CAP_IE_:
  974. break;
  975. case _VENDOR_SPECIFIC_IE_:
  976. break;
  977. case _FTIE_:
  978. if(prx_pkt_attrib->encrypt)
  979. _rtw_memcpy(SNonce, (ptr+j+52), 32);
  980. break;
  981. case _TIMEOUT_ITVL_IE_:
  982. if(prx_pkt_attrib->encrypt)
  983. timeout_interval = (u32 *)(ptr+j+3);
  984. break;
  985. case _RIC_Descriptor_IE_:
  986. break;
  987. case _HT_CAPABILITY_IE_:
  988. rtw_tdls_process_ht_cap(adapter, ptdls_sta, pIE->data, pIE->Length);
  989. break;
  990. case EID_BSSCoexistence:
  991. break;
  992. case _LINK_ID_IE_:
  993. if(_rtw_memcmp(get_bssid(pmlmepriv), pIE->data, 6) == _FALSE)
  994. {
  995. //not in the same BSS
  996. ptdls_sta->stat_code=7;
  997. }
  998. break;
  999. default:
  1000. break;
  1001. }
  1002. j += (pIE->Length + 2);
  1003. }
  1004. //update station supportRate
  1005. ptdls_sta->bssratelen = supportRateNum;
  1006. _rtw_memcpy(ptdls_sta->bssrateset, supportRate, supportRateNum);
  1007. //check status code
  1008. //if responder STA has/hasn't security on AP, but request hasn't/has RSNIE, it should reject
  1009. if(ptdls_sta->stat_code == 0 )
  1010. {
  1011. if(rsnie_have && (prx_pkt_attrib->encrypt==0)){
  1012. //security disabled
  1013. ptdls_sta->stat_code = 5;
  1014. }else if(rsnie_have==0 && (prx_pkt_attrib->encrypt)){
  1015. //request haven't RSNIE
  1016. ptdls_sta->stat_code = 38;
  1017. }
  1018. #ifdef CONFIG_WFD
  1019. //WFD test plan version 0.18.2 test item 5.1.5
  1020. //SoUT does not use TDLS if AP uses weak security
  1021. if ( adapter->wdinfo.wfd_tdls_enable )
  1022. {
  1023. if(rsnie_have && (prx_pkt_attrib->encrypt != _AES_))
  1024. {
  1025. ptdls_sta->stat_code = 5;
  1026. }
  1027. }
  1028. #endif //CONFIG_WFD
  1029. }
  1030. ptdls_sta->tdls_sta_state|= TDLS_INITIATOR_STATE;
  1031. if(prx_pkt_attrib->encrypt){
  1032. _rtw_memcpy(ptdls_sta->SNonce, SNonce, 32);
  1033. _rtw_memcpy(&(ptdls_sta->TDLS_PeerKey_Lifetime), timeout_interval, 4);
  1034. }
  1035. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1036. if(!(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE))
  1037. ptdlsinfo->sta_cnt++;
  1038. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1039. if( ptdlsinfo->sta_cnt == (NUM_STA - 2) ) // -2: AP + BC/MC sta
  1040. {
  1041. ptdlsinfo->sta_maximum = _TRUE;
  1042. }
  1043. #ifdef CONFIG_WFD
  1044. rtw_tdls_process_wfd_ie(ptdlsinfo, ptr + FIXED_IE, parsing_length - FIXED_IE);
  1045. #endif // CONFIG_WFD
  1046. }
  1047. else
  1048. {
  1049. goto exit;
  1050. }
  1051. issue_tdls_setup_rsp(adapter, precv_frame);
  1052. if(ptdls_sta->stat_code==0)
  1053. {
  1054. _set_timer( &ptdls_sta->handshake_timer, TDLS_HANDSHAKE_TIME);
  1055. }
  1056. else //status code!=0 ; setup unsuccess
  1057. {
  1058. free_tdls_sta(adapter, ptdls_sta);
  1059. }
  1060. exit:
  1061. return _FAIL;
  1062. }
  1063. sint On_TDLS_Setup_Rsp(_adapter *adapter, union recv_frame *precv_frame)
  1064. {
  1065. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  1066. struct sta_info *ptdls_sta= NULL;
  1067. struct sta_priv *pstapriv = &adapter->stapriv;
  1068. u8 *ptr = precv_frame->u.hdr.rx_data;
  1069. _irqL irqL;
  1070. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  1071. u8 *psa;
  1072. u16 stat_code;
  1073. sint parsing_length; //frame body length, without icv_len
  1074. PNDIS_802_11_VARIABLE_IEs pIE;
  1075. u8 FIXED_IE =7;
  1076. u8 *pftie, *ptimeout_ie, *plinkid_ie, *prsnie, *pftie_mic, *ppairwise_cipher;
  1077. u16 pairwise_count, j, k;
  1078. u8 verify_ccmp=0;
  1079. unsigned char supportRate[16];
  1080. int supportRateNum = 0;
  1081. psa = get_sa(ptr);
  1082. ptdls_sta = rtw_get_stainfo(pstapriv, psa);
  1083. if ( NULL == ptdls_sta )
  1084. {
  1085. return _FAIL;
  1086. }
  1087. ptr +=prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len+LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE+1;
  1088. parsing_length= ((union recv_frame *)precv_frame)->u.hdr.len
  1089. -prx_pkt_attrib->hdrlen
  1090. -prx_pkt_attrib->iv_len
  1091. -prx_pkt_attrib->icv_len
  1092. -LLC_HEADER_SIZE
  1093. -TYPE_LENGTH_FIELD_SIZE
  1094. -1
  1095. -FIXED_IE;
  1096. _rtw_memcpy(&stat_code, ptr+2, 2);
  1097. if(stat_code!=0)
  1098. {
  1099. DBG_871X( "[%s] status_code = %d, free_tdls_sta\n", __FUNCTION__, stat_code );
  1100. free_tdls_sta(adapter, ptdls_sta);
  1101. return _FAIL;
  1102. }
  1103. stat_code = 0;
  1104. //parsing information element
  1105. for(j=FIXED_IE; j<parsing_length;)
  1106. {
  1107. pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr+ j);
  1108. switch (pIE->ElementID)
  1109. {
  1110. case _SUPPORTEDRATES_IE_:
  1111. _rtw_memcpy(supportRate, pIE->data, pIE->Length);
  1112. supportRateNum = pIE->Length;
  1113. break;
  1114. case _COUNTRY_IE_:
  1115. break;
  1116. case _EXT_SUPPORTEDRATES_IE_:
  1117. if(supportRateNum<=sizeof(supportRate))
  1118. {
  1119. _rtw_memcpy(supportRate+supportRateNum, pIE->data, pIE->Length);
  1120. supportRateNum += pIE->Length;
  1121. }
  1122. break;
  1123. case _SUPPORTED_CH_IE_:
  1124. break;
  1125. case _RSN_IE_2_:
  1126. prsnie=(u8*)pIE;
  1127. //check whether responder STA has CCMP pairwise_cipher.
  1128. ppairwise_cipher=prsnie+10;
  1129. _rtw_memcpy(&pairwise_count, (u16*)(ppairwise_cipher-2), 2);
  1130. for(k=0;k<pairwise_count;k++){
  1131. if(_rtw_memcmp( ppairwise_cipher+4*k, RSN_CIPHER_SUITE_CCMP, 4)==_TRUE)
  1132. verify_ccmp=1;
  1133. }
  1134. case _EXT_CAP_IE_:
  1135. break;
  1136. case _VENDOR_SPECIFIC_IE_:
  1137. break;
  1138. case _FTIE_:
  1139. pftie=(u8*)pIE;
  1140. _rtw_memcpy(ptdls_sta->ANonce, (ptr+j+20), 32);
  1141. break;
  1142. case _TIMEOUT_ITVL_IE_:
  1143. ptimeout_ie=(u8*)pIE;
  1144. break;
  1145. case _RIC_Descriptor_IE_:
  1146. break;
  1147. case _HT_CAPABILITY_IE_:
  1148. rtw_tdls_process_ht_cap(adapter, ptdls_sta, pIE->data, pIE->Length);
  1149. break;
  1150. case EID_BSSCoexistence:
  1151. break;
  1152. case _LINK_ID_IE_:
  1153. plinkid_ie=(u8*)pIE;
  1154. break;
  1155. default:
  1156. break;
  1157. }
  1158. j += (pIE->Length + 2);
  1159. }
  1160. //update station supportRate
  1161. ptdls_sta->bssratelen = supportRateNum;
  1162. _rtw_memcpy(ptdls_sta->bssrateset, supportRate, supportRateNum);
  1163. #ifdef CONFIG_WFD
  1164. rtw_tdls_process_wfd_ie(ptdlsinfo, ptr + FIXED_IE, parsing_length - FIXED_IE);
  1165. #endif // CONFIG_WFD
  1166. if(stat_code != 0)
  1167. {
  1168. ptdls_sta->stat_code = stat_code;
  1169. }
  1170. else
  1171. {
  1172. if(prx_pkt_attrib->encrypt)
  1173. {
  1174. if(verify_ccmp==1)
  1175. {
  1176. wpa_tdls_generate_tpk(adapter, ptdls_sta);
  1177. ptdls_sta->stat_code=0;
  1178. if(tdls_verify_mic(ptdls_sta->tpk.kck, 2, plinkid_ie, prsnie, ptimeout_ie, pftie)==0) //0: Invalid, 1: valid
  1179. {
  1180. free_tdls_sta(adapter, ptdls_sta);
  1181. return _FAIL;
  1182. }
  1183. }
  1184. else
  1185. {
  1186. ptdls_sta->stat_code=72; //invalide contents of RSNIE
  1187. }
  1188. }else{
  1189. ptdls_sta->stat_code=0;
  1190. }
  1191. }
  1192. DBG_871X("issue_tdls_setup_cfm\n");
  1193. issue_tdls_setup_cfm(adapter, precv_frame);
  1194. if(ptdls_sta->stat_code==0)
  1195. {
  1196. ptdlsinfo->setup_state = TDLS_LINKED_STATE;
  1197. if( ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE )
  1198. {
  1199. ptdls_sta->tdls_sta_state |= TDLS_LINKED_STATE;
  1200. _cancel_timer_ex( &ptdls_sta->handshake_timer);
  1201. #ifdef CONFIG_TDLS_AUTOCHECKALIVE
  1202. _set_timer( &ptdls_sta->alive_timer1, TDLS_ALIVE_TIMER_PH1);
  1203. #endif //CONFIG_TDLS_AUTOSETUP
  1204. }
  1205. rtw_tdls_set_mac_id(ptdlsinfo, ptdls_sta);
  1206. rtw_tdls_set_key(adapter, prx_pkt_attrib, ptdls_sta);
  1207. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_WRCR);
  1208. }
  1209. else //status code!=0 ; setup unsuccessful
  1210. {
  1211. free_tdls_sta(adapter, ptdls_sta);
  1212. }
  1213. return _FAIL;
  1214. }
  1215. sint On_TDLS_Setup_Cfm(_adapter *adapter, union recv_frame *precv_frame)
  1216. {
  1217. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  1218. struct sta_info *ptdls_sta= NULL;
  1219. struct sta_priv *pstapriv = &adapter->stapriv;
  1220. u8 *ptr = precv_frame->u.hdr.rx_data;
  1221. _irqL irqL;
  1222. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  1223. u8 *psa;
  1224. u16 stat_code;
  1225. sint parsing_length;
  1226. PNDIS_802_11_VARIABLE_IEs pIE;
  1227. u8 FIXED_IE =5;
  1228. u8 *pftie, *ptimeout_ie, *plinkid_ie, *prsnie, *pftie_mic, *ppairwise_cipher;
  1229. u16 j, pairwise_count;
  1230. psa = get_sa(ptr);
  1231. ptdls_sta = rtw_get_stainfo(pstapriv, psa);
  1232. ptr +=prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len+LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE+1;
  1233. parsing_length= ((union recv_frame *)precv_frame)->u.hdr.len
  1234. -prx_pkt_attrib->hdrlen
  1235. -prx_pkt_attrib->iv_len
  1236. -prx_pkt_attrib->icv_len
  1237. -LLC_HEADER_SIZE
  1238. -ETH_TYPE_LEN
  1239. -PAYLOAD_TYPE_LEN
  1240. -FIXED_IE;
  1241. _rtw_memcpy(&stat_code, ptr+2, 2);
  1242. if(stat_code!=0){
  1243. DBG_871X( "[%s] stat_code = %d\n, free_tdls_sta", __FUNCTION__, stat_code );
  1244. free_tdls_sta(adapter, ptdls_sta);
  1245. return _FAIL;
  1246. }
  1247. if(prx_pkt_attrib->encrypt){
  1248. //parsing information element
  1249. for(j=FIXED_IE; j<parsing_length;){
  1250. pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr+ j);
  1251. switch (pIE->ElementID)
  1252. {
  1253. case _RSN_IE_2_:
  1254. prsnie=(u8*)pIE;
  1255. break;
  1256. case _VENDOR_SPECIFIC_IE_:
  1257. break;
  1258. case _FTIE_:
  1259. pftie=(u8*)pIE;
  1260. break;
  1261. case _TIMEOUT_ITVL_IE_:
  1262. ptimeout_ie=(u8*)pIE;
  1263. break;
  1264. case _HT_EXTRA_INFO_IE_:
  1265. break;
  1266. case _LINK_ID_IE_:
  1267. plinkid_ie=(u8*)pIE;
  1268. break;
  1269. default:
  1270. break;
  1271. }
  1272. j += (pIE->Length + 2);
  1273. }
  1274. //verify mic in FTIE MIC field
  1275. if(tdls_verify_mic(ptdls_sta->tpk.kck, 3, plinkid_ie, prsnie, ptimeout_ie, pftie)==0){ //0: Invalid, 1: Valid
  1276. free_tdls_sta(adapter, ptdls_sta);
  1277. return _FAIL;
  1278. }
  1279. }
  1280. ptdlsinfo->setup_state = TDLS_LINKED_STATE;
  1281. if( ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE )
  1282. {
  1283. ptdls_sta->tdls_sta_state|=TDLS_LINKED_STATE;
  1284. _cancel_timer_ex( &ptdls_sta->handshake_timer);
  1285. #ifdef CONFIG_TDLS_AUTOCHECKALIVE
  1286. _set_timer( &ptdls_sta->alive_timer1, TDLS_ALIVE_TIMER_PH1);
  1287. #endif //CONFIG_TDLS_AUTOCHECKALIVE
  1288. }
  1289. rtw_tdls_set_mac_id(ptdlsinfo, ptdls_sta);
  1290. rtw_tdls_set_key(adapter, prx_pkt_attrib, ptdls_sta);
  1291. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_WRCR);
  1292. return _FAIL;
  1293. }
  1294. sint On_TDLS_Dis_Req(_adapter *adapter, union recv_frame *precv_frame)
  1295. {
  1296. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  1297. struct sta_priv *pstapriv = &adapter->stapriv;
  1298. struct sta_info *psta_ap;
  1299. u8 *ptr = precv_frame->u.hdr.rx_data;
  1300. sint parsing_length; //frame body length, without icv_len
  1301. PNDIS_802_11_VARIABLE_IEs pIE;
  1302. u8 FIXED_IE = 3, *dst, *pdialog = NULL;
  1303. u16 j;
  1304. ptr +=prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE + 1;
  1305. pdialog=ptr+2;
  1306. parsing_length= ((union recv_frame *)precv_frame)->u.hdr.len
  1307. -prx_pkt_attrib->hdrlen
  1308. -prx_pkt_attrib->iv_len
  1309. -prx_pkt_attrib->icv_len
  1310. -LLC_HEADER_SIZE
  1311. -TYPE_LENGTH_FIELD_SIZE
  1312. -1
  1313. -FIXED_IE;
  1314. //parsing information element
  1315. for(j=FIXED_IE; j<parsing_length;){
  1316. pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr+ j);
  1317. switch (pIE->ElementID)
  1318. {
  1319. case _LINK_ID_IE_:
  1320. psta_ap = rtw_get_stainfo(pstapriv, pIE->data);
  1321. if(psta_ap == NULL)
  1322. {
  1323. goto exit;
  1324. }
  1325. dst = pIE->data + 12;
  1326. if( (MacAddr_isBcst(dst) == _FALSE) && (_rtw_memcmp(myid(&(adapter->eeprompriv)), dst, 6) == _FALSE) )
  1327. {
  1328. goto exit;
  1329. }
  1330. break;
  1331. default:
  1332. break;
  1333. }
  1334. j += (pIE->Length + 2);
  1335. }
  1336. //check frame contents
  1337. issue_tdls_dis_rsp(adapter, precv_frame, *(pdialog) );
  1338. exit:
  1339. return _FAIL;
  1340. }
  1341. sint On_TDLS_Teardown(_adapter *adapter, union recv_frame *precv_frame)
  1342. {
  1343. u8 *psa;
  1344. u8 *ptr = precv_frame->u.hdr.rx_data;
  1345. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  1346. struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
  1347. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1348. struct sta_priv *pstapriv = &adapter->stapriv;
  1349. struct sta_info *ptdls_sta= NULL;
  1350. _irqL irqL;
  1351. psa = get_sa(ptr);
  1352. ptdls_sta = rtw_get_stainfo(pstapriv, psa);
  1353. if(ptdls_sta!=NULL){
  1354. if(ptdls_sta->tdls_sta_state & TDLS_CH_SWITCH_ON_STATE){
  1355. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_CS_OFF);
  1356. }
  1357. free_tdls_sta(adapter, ptdls_sta);
  1358. }
  1359. return _FAIL;
  1360. }
  1361. u8 TDLS_check_ch_state(uint state){
  1362. if( (state & TDLS_CH_SWITCH_ON_STATE) &&
  1363. (state & TDLS_AT_OFF_CH_STATE) &&
  1364. (state & TDLS_PEER_AT_OFF_STATE) ){
  1365. if(state & TDLS_PEER_SLEEP_STATE)
  1366. return 2; //U-APSD + ch. switch
  1367. else
  1368. return 1; //ch. switch
  1369. }else
  1370. return 0;
  1371. }
  1372. //we process buffered data for 1. U-APSD, 2. ch. switch, 3. U-APSD + ch. switch here
  1373. sint On_TDLS_Peer_Traffic_Rsp(_adapter *adapter, union recv_frame *precv_frame)
  1374. {
  1375. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  1376. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  1377. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  1378. struct sta_priv *pstapriv = &adapter->stapriv;
  1379. //get peer sta infomation
  1380. struct sta_info *ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->src);
  1381. u8 wmmps_ac=0, state=TDLS_check_ch_state(ptdls_sta->tdls_sta_state);
  1382. int i;
  1383. ptdls_sta->sta_stats.rx_data_pkts++;
  1384. //receive peer traffic response frame, sleeping STA wakes up
  1385. //ptdls_sta->tdls_sta_state &= ~(TDLS_PEER_SLEEP_STATE);
  1386. process_wmmps_data( adapter, precv_frame);
  1387. // if noticed peer STA wakes up by receiving peer traffic response
  1388. // and we want to do channel swtiching, then we will transmit channel switch request first
  1389. if(ptdls_sta->tdls_sta_state & TDLS_APSD_CHSW_STATE){
  1390. issue_tdls_ch_switch_req(adapter, pattrib->src);
  1391. ptdls_sta->tdls_sta_state &= ~(TDLS_APSD_CHSW_STATE);
  1392. return _FAIL;
  1393. }
  1394. //check 4-AC queue bit
  1395. if(ptdls_sta->uapsd_vo || ptdls_sta->uapsd_vi || ptdls_sta->uapsd_be || ptdls_sta->uapsd_bk)
  1396. wmmps_ac=1;
  1397. //if it's a direct link and have buffered frame
  1398. if(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE){
  1399. if(wmmps_ac && state)
  1400. {
  1401. _irqL irqL;
  1402. _list *xmitframe_plist, *xmitframe_phead;
  1403. struct xmit_frame *pxmitframe=NULL;
  1404. _enter_critical_bh(&ptdls_sta->sleep_q.lock, &irqL);
  1405. xmitframe_phead = get_list_head(&ptdls_sta->sleep_q);
  1406. xmitframe_plist = get_next(xmitframe_phead);
  1407. //transmit buffered frames
  1408. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
  1409. {
  1410. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  1411. xmitframe_plist = get_next(xmitframe_plist);
  1412. rtw_list_delete(&pxmitframe->list);
  1413. ptdls_sta->sleepq_len--;
  1414. if(ptdls_sta->sleepq_len>0){
  1415. pxmitframe->attrib.mdata = 1;
  1416. pxmitframe->attrib.eosp = 0;
  1417. }else{
  1418. pxmitframe->attrib.mdata = 0;
  1419. pxmitframe->attrib.eosp = 1;
  1420. }
  1421. //pxmitframe->attrib.triggered = 1; //maybe doesn't need in TDLS
  1422. if(adapter->HalFunc.hal_xmit(adapter, pxmitframe) == _TRUE)
  1423. {
  1424. rtw_os_xmit_complete(adapter, pxmitframe);
  1425. }
  1426. }
  1427. if(ptdls_sta->sleepq_len==0)
  1428. {
  1429. DBG_871X("no buffered packets for tdls to xmit\n");
  1430. //on U-APSD + CH. switch state, when there is no buffered date to xmit,
  1431. // we should go back to base channel
  1432. if(state==2){
  1433. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_CS_OFF);
  1434. }else if(ptdls_sta->tdls_sta_state&TDLS_SW_OFF_STATE){
  1435. ptdls_sta->tdls_sta_state &= ~(TDLS_SW_OFF_STATE);
  1436. ptdlsinfo->candidate_ch= pmlmeext->cur_channel;
  1437. issue_tdls_ch_switch_req(adapter, pattrib->src);
  1438. DBG_871X("issue tdls ch switch req back to base channel\n");
  1439. }
  1440. }
  1441. else
  1442. {
  1443. DBG_871X("error!psta->sleepq_len=%d\n", ptdls_sta->sleepq_len);
  1444. ptdls_sta->sleepq_len=0;
  1445. }
  1446. _exit_critical_bh(&ptdls_sta->sleep_q.lock, &irqL);
  1447. }
  1448. }
  1449. return _FAIL;
  1450. }
  1451. sint On_TDLS_Ch_Switch_Req(_adapter *adapter, union recv_frame *precv_frame)
  1452. {
  1453. struct sta_info *ptdls_sta= NULL;
  1454. struct sta_priv *pstapriv = &adapter->stapriv;
  1455. u8 *ptr = precv_frame->u.hdr.rx_data;
  1456. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  1457. u8 *psa;
  1458. sint parsing_length;
  1459. PNDIS_802_11_VARIABLE_IEs pIE;
  1460. u8 FIXED_IE =3;
  1461. u16 j;
  1462. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  1463. psa = get_sa(ptr);
  1464. ptdls_sta = rtw_get_stainfo(pstapriv, psa);
  1465. ptr +=prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len+LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE+1;
  1466. parsing_length= ((union recv_frame *)precv_frame)->u.hdr.len
  1467. -prx_pkt_attrib->hdrlen
  1468. -prx_pkt_attrib->iv_len
  1469. -prx_pkt_attrib->icv_len
  1470. -LLC_HEADER_SIZE
  1471. -ETH_TYPE_LEN
  1472. -PAYLOAD_TYPE_LEN
  1473. -FIXED_IE;
  1474. ptdls_sta->off_ch = *(ptr+2);
  1475. //parsing information element
  1476. for(j=FIXED_IE; j<parsing_length;){
  1477. pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr+ j);
  1478. switch (pIE->ElementID)
  1479. {
  1480. case _COUNTRY_IE_:
  1481. break;
  1482. case _CH_SWTICH_ANNOUNCE_:
  1483. break;
  1484. case _LINK_ID_IE_:
  1485. break;
  1486. case _CH_SWITCH_TIMING_:
  1487. _rtw_memcpy(&ptdls_sta->ch_switch_time, pIE->data, 2);
  1488. _rtw_memcpy(&ptdls_sta->ch_switch_timeout, pIE->data+2, 2);
  1489. default:
  1490. break;
  1491. }
  1492. j += (pIE->Length + 2);
  1493. }
  1494. //todo: check status
  1495. ptdls_sta->stat_code=0;
  1496. ptdls_sta->tdls_sta_state |= TDLS_CH_SWITCH_ON_STATE;
  1497. issue_nulldata(adapter, NULL, 1, 0, 0);
  1498. issue_tdls_ch_switch_rsp(adapter, psa);
  1499. DBG_871X("issue tdls channel switch response\n");
  1500. if((ptdls_sta->tdls_sta_state & TDLS_CH_SWITCH_ON_STATE) && ptdls_sta->off_ch==pmlmeext->cur_channel){
  1501. DBG_871X("back to base channel %x\n", pmlmeext->cur_channel);
  1502. ptdls_sta->option=7;
  1503. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_BASE_CH);
  1504. }else{
  1505. ptdls_sta->option=6;
  1506. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_OFF_CH);
  1507. }
  1508. return _FAIL;
  1509. }
  1510. sint On_TDLS_Ch_Switch_Rsp(_adapter *adapter, union recv_frame *precv_frame)
  1511. {
  1512. struct sta_info *ptdls_sta= NULL;
  1513. struct sta_priv *pstapriv = &adapter->stapriv;
  1514. u8 *ptr = precv_frame->u.hdr.rx_data;
  1515. struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
  1516. u8 *psa;
  1517. sint parsing_length;
  1518. PNDIS_802_11_VARIABLE_IEs pIE;
  1519. u8 FIXED_IE =4;
  1520. u16 stat_code, j, switch_time, switch_timeout;
  1521. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  1522. psa = get_sa(ptr);
  1523. ptdls_sta = rtw_get_stainfo(pstapriv, psa);
  1524. //if channel switch is running and receiving Unsolicited TDLS Channel Switch Response,
  1525. //it will go back to base channel and terminate this channel switch procedure
  1526. if(ptdls_sta->tdls_sta_state & TDLS_CH_SWITCH_ON_STATE ){
  1527. if(pmlmeext->cur_channel==ptdls_sta->off_ch){
  1528. DBG_871X("back to base channel %x\n", pmlmeext->cur_channel);
  1529. ptdls_sta->option=7;
  1530. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_OFF_CH);
  1531. }else{
  1532. DBG_871X("receive unsolicited channel switch response \n");
  1533. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_CS_OFF);
  1534. }
  1535. return _FAIL;
  1536. }
  1537. //avoiding duplicated or unconditional ch. switch. rsp
  1538. if((ptdls_sta->tdls_sta_state & TDLS_CH_SW_INITIATOR_STATE) != TDLS_CH_SW_INITIATOR_STATE)
  1539. return _FAIL;
  1540. ptr +=prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len+LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE+1;
  1541. parsing_length= ((union recv_frame *)precv_frame)->u.hdr.len
  1542. -prx_pkt_attrib->hdrlen
  1543. -prx_pkt_attrib->iv_len
  1544. -prx_pkt_attrib->icv_len
  1545. -LLC_HEADER_SIZE
  1546. -ETH_TYPE_LEN
  1547. -PAYLOAD_TYPE_LEN
  1548. -FIXED_IE;
  1549. _rtw_memcpy(&stat_code, ptr+2, 2);
  1550. if(stat_code!=0){
  1551. return _FAIL;
  1552. }
  1553. //parsing information element
  1554. for(j=FIXED_IE; j<parsing_length;){
  1555. pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr+ j);
  1556. switch (pIE->ElementID)
  1557. {
  1558. case _LINK_ID_IE_:
  1559. break;
  1560. case _CH_SWITCH_TIMING_:
  1561. _rtw_memcpy(&switch_time, pIE->data, 2);
  1562. if(switch_time > ptdls_sta->ch_switch_time)
  1563. _rtw_memcpy(&ptdls_sta->ch_switch_time, &switch_time, 2);
  1564. _rtw_memcpy(&switch_timeout, pIE->data+2, 2);
  1565. if(switch_timeout > ptdls_sta->ch_switch_timeout)
  1566. _rtw_memcpy(&ptdls_sta->ch_switch_timeout, &switch_timeout, 2);
  1567. default:
  1568. break;
  1569. }
  1570. j += (pIE->Length + 2);
  1571. }
  1572. ptdls_sta->tdls_sta_state &= ~(TDLS_CH_SW_INITIATOR_STATE);
  1573. ptdls_sta->tdls_sta_state |=TDLS_CH_SWITCH_ON_STATE;
  1574. //goto set_channel_workitem_callback()
  1575. ptdls_sta->option=6;
  1576. rtw_tdls_cmd(adapter, ptdls_sta->hwaddr, TDLS_OFF_CH);
  1577. return _FAIL;
  1578. }
  1579. #ifdef CONFIG_WFD
  1580. void wfd_ie_tdls(_adapter * padapter, u8 *pframe, u32 *pktlen )
  1581. {
  1582. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1583. struct wifi_display_info *pwfd_info = padapter->tdlsinfo.wfd_info;
  1584. u8 wfdie[ MAX_WFD_IE_LEN] = { 0x00 };
  1585. u32 wfdielen = 0;
  1586. // WFD OUI
  1587. wfdielen = 0;
  1588. wfdie[ wfdielen++ ] = 0x50;
  1589. wfdie[ wfdielen++ ] = 0x6F;
  1590. wfdie[ wfdielen++ ] = 0x9A;
  1591. wfdie[ wfdielen++ ] = 0x0A; // WFA WFD v1.0
  1592. // Commented by Albert 20110825
  1593. // According to the WFD Specification, the negotiation request frame should contain 3 WFD attributes
  1594. // 1. WFD Device Information
  1595. // 2. Associated BSSID ( Optional )
  1596. // 3. Local IP Adress ( Optional )
  1597. // WFD Device Information ATTR
  1598. // Type:
  1599. wfdie[ wfdielen++ ] = WFD_ATTR_DEVICE_INFO;
  1600. // Length:
  1601. // Note: In the WFD specification, the size of length field is 2.
  1602. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1603. wfdielen += 2;
  1604. // Value1:
  1605. // WFD device information
  1606. // available for WFD session + Preferred TDLS + WSD ( WFD Service Discovery )
  1607. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL
  1608. | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_WSD);
  1609. wfdielen += 2;
  1610. // Value2:
  1611. // Session Management Control Port
  1612. // Default TCP port for RTSP messages is 554
  1613. RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport );
  1614. wfdielen += 2;
  1615. // Value3:
  1616. // WFD Device Maximum Throughput
  1617. // 300Mbps is the maximum throughput
  1618. RTW_PUT_BE16(wfdie + wfdielen, 300);
  1619. wfdielen += 2;
  1620. // Associated BSSID ATTR
  1621. // Type:
  1622. wfdie[ wfdielen++ ] = WFD_ATTR_ASSOC_BSSID;
  1623. // Length:
  1624. // Note: In the WFD specification, the size of length field is 2.
  1625. RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
  1626. wfdielen += 2;
  1627. // Value:
  1628. // Associated BSSID
  1629. if ( check_fwstate( pmlmepriv, _FW_LINKED) == _TRUE )
  1630. {
  1631. _rtw_memcpy( wfdie + wfdielen, &pmlmepriv->assoc_bssid[ 0 ], ETH_ALEN );
  1632. }
  1633. else
  1634. {
  1635. _rtw_memset( wfdie + wfdielen, 0x00, ETH_ALEN );
  1636. }
  1637. // Local IP Address ATTR
  1638. wfdie[ wfdielen++ ] = WFD_ATTR_LOCAL_IP_ADDR;
  1639. // Length:
  1640. // Note: In the WFD specification, the size of length field is 2.
  1641. RTW_PUT_BE16(wfdie + wfdielen, 0x0005);
  1642. wfdielen += 2;
  1643. // Version:
  1644. // 0x01: Version1;IPv4
  1645. wfdie[ wfdielen++ ] = 0x01;
  1646. // IPv4 Address
  1647. _rtw_memcpy( wfdie + wfdielen, pwfd_info->ip_address, 4 );
  1648. wfdielen += 4;
  1649. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, pktlen);
  1650. }
  1651. #endif //CONFIG_WFD
  1652. void rtw_build_tdls_setup_req_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  1653. {
  1654. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1655. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  1656. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1657. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1658. struct sta_info *ptdls_sta=rtw_get_stainfo( (&padapter->stapriv) , pattrib->dst);
  1659. u8 payload_type = 0x02;
  1660. u8 category = RTW_WLAN_CATEGORY_TDLS;
  1661. u8 action = TDLS_SETUP_REQUEST;
  1662. u8 bssrate[NDIS_802_11_LENGTH_RATES_EX]; //Use NDIS_802_11_LENGTH_RATES_EX in order to call func.rtw_set_supported_rate
  1663. int bssrate_len = 0, i = 0 ;
  1664. u8 more_supportedrates = 0;
  1665. unsigned int ie_len;
  1666. u8 *p;
  1667. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1668. u8 link_id_addr[18] = {0};
  1669. u8 iedata=0;
  1670. u8 sup_ch[ 30 * 2 ] = {0x00 }, sup_ch_idx = 0, idx_5g = 2; //For supported channel
  1671. u8 timeout_itvl[5]; //set timeout interval to maximum value
  1672. u32 time;
  1673. //SNonce
  1674. if(pattrib->encrypt){
  1675. for(i=0;i<8;i++){
  1676. time=rtw_get_current_time();
  1677. _rtw_memcpy(&ptdls_sta->SNonce[4*i], (u8 *)&time, 4);
  1678. }
  1679. }
  1680. //payload type
  1681. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  1682. //category, action, dialog token
  1683. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  1684. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  1685. pframe = rtw_set_fixed_ie(pframe, 1, &(ptdls_sta->dialog), &(pattrib->pktlen));
  1686. //capability
  1687. _rtw_memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
  1688. if(pattrib->encrypt)
  1689. *pframe =*pframe | BIT(4);
  1690. pframe += 2;
  1691. pattrib->pktlen += 2;
  1692. //supported rates
  1693. rtw_set_supported_rate(bssrate, WIRELESS_11BG_24N);
  1694. bssrate_len = IEEE80211_CCK_RATE_LEN + IEEE80211_NUM_OFDM_RATESLEN;
  1695. if (bssrate_len > 8)
  1696. {
  1697. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
  1698. more_supportedrates = 1;
  1699. }
  1700. else
  1701. {
  1702. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
  1703. }
  1704. //country(optional)
  1705. //extended supported rates
  1706. if(more_supportedrates==1){
  1707. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
  1708. }
  1709. //supported channels
  1710. pframe = rtw_tdls_set_sup_ch(pmlmeext, pframe, pattrib);
  1711. // SRC IE
  1712. pframe = rtw_set_ie( pframe, _SRC_IE_, 16, TDLS_SRC, &(pattrib->pktlen));
  1713. //RSNIE
  1714. if(pattrib->encrypt)
  1715. pframe = rtw_set_ie(pframe, _RSN_IE_2_, 20, TDLS_RSNIE, &(pattrib->pktlen));
  1716. //extended capabilities
  1717. pframe = rtw_set_ie(pframe, _EXT_CAP_IE_ , 5, TDLS_EXT_CAPIE, &(pattrib->pktlen));
  1718. //QoS capability(WMM_IE)
  1719. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 7, TDLS_WMMIE, &(pattrib->pktlen));
  1720. if(pattrib->encrypt){
  1721. //FTIE
  1722. _rtw_memset(pframe, 0, 84); //All fields except SNonce shall be set to 0
  1723. _rtw_memset(pframe, _FTIE_, 1); //version
  1724. _rtw_memset((pframe+1), 82, 1); //length
  1725. _rtw_memcpy((pframe+52), ptdls_sta->SNonce, 32);
  1726. pframe += 84;
  1727. pattrib->pktlen += 84;
  1728. //Timeout interval
  1729. timeout_itvl[0]=0x02;
  1730. _rtw_memcpy(timeout_itvl+1, (u8 *)(&ptdls_sta->TDLS_PeerKey_Lifetime), 4);
  1731. pframe = rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, 5, timeout_itvl, &(pattrib->pktlen));
  1732. }
  1733. //Sup_reg_classes(optional)
  1734. //HT capabilities
  1735. pframe = rtw_tdls_set_ht_cap(padapter, pframe, pattrib);
  1736. //20/40 BSS coexistence
  1737. if(pmlmepriv->num_FortyMHzIntolerant>0)
  1738. iedata |= BIT(2);//20 MHz BSS Width Request
  1739. pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
  1740. //Link identifier
  1741. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  1742. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  1743. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  1744. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  1745. #ifdef CONFIG_WFD
  1746. wfd_ie_tdls( padapter, pframe, &(pattrib->pktlen) );
  1747. #endif //CONFIG_WFD
  1748. }
  1749. void rtw_build_tdls_setup_rsp_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  1750. {
  1751. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1752. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1753. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1754. struct sta_info *ptdls_sta;
  1755. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1756. u8 payload_type = 0x02;
  1757. unsigned char category = RTW_WLAN_CATEGORY_TDLS;
  1758. unsigned char action = TDLS_SETUP_RESPONSE;
  1759. unsigned char bssrate[NDIS_802_11_LENGTH_RATES_EX];
  1760. int bssrate_len = 0;
  1761. u8 more_supportedrates = 0;
  1762. unsigned int ie_len;
  1763. unsigned char *p;
  1764. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1765. u8 link_id_addr[18] = {0};
  1766. u8 iedata=0;
  1767. u8 timeout_itvl[5]; //setup response timeout interval will copy from request
  1768. u8 ANonce[32]; //maybe it can put in ontdls_req
  1769. u8 k; //for random ANonce
  1770. u8 *pftie, *ptimeout_ie, *plinkid_ie, *prsnie, *pftie_mic;
  1771. u32 time;
  1772. ptdls_sta = rtw_get_stainfo( &(padapter->stapriv) , pattrib->dst);
  1773. if(ptdls_sta == NULL )
  1774. {
  1775. DBG_871X("[%s] %d\n", __FUNCTION__, __LINE__);
  1776. return;
  1777. }
  1778. if(pattrib->encrypt){
  1779. for(k=0;k<8;k++){
  1780. time=rtw_get_current_time();
  1781. _rtw_memcpy(&ptdls_sta->ANonce[4*k], (u8*)&time, 4);
  1782. }
  1783. }
  1784. //payload type
  1785. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  1786. //category, action, status code
  1787. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  1788. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  1789. pframe = rtw_set_fixed_ie(pframe, 2, (u8 *)&ptdls_sta->stat_code, &(pattrib->pktlen));
  1790. if(ptdls_sta->stat_code!=0) //invalid setup request
  1791. {
  1792. DBG_871X("ptdls_sta->stat_code:%04x \n", ptdls_sta->stat_code);
  1793. return;
  1794. }
  1795. //dialog token
  1796. pframe = rtw_set_fixed_ie(pframe, 1, &(ptdls_sta->dialog), &(pattrib->pktlen));
  1797. //capability
  1798. _rtw_memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
  1799. if(pattrib->encrypt )
  1800. *pframe =*pframe | BIT(4);
  1801. pframe += 2;
  1802. pattrib->pktlen += 2;
  1803. //supported rates
  1804. rtw_set_supported_rate(bssrate, WIRELESS_11BG_24N);
  1805. bssrate_len = IEEE80211_CCK_RATE_LEN + IEEE80211_NUM_OFDM_RATESLEN;
  1806. if (bssrate_len > 8)
  1807. {
  1808. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
  1809. more_supportedrates = 1;
  1810. }
  1811. else
  1812. {
  1813. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
  1814. }
  1815. //country(optional)
  1816. //extended supported rates
  1817. if(more_supportedrates==1){
  1818. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
  1819. }
  1820. //supported channels
  1821. pframe = rtw_tdls_set_sup_ch(pmlmeext, pframe, pattrib);
  1822. // SRC IE
  1823. pframe = rtw_set_ie(pframe, _SRC_IE_ , 16, TDLS_SRC, &(pattrib->pktlen));
  1824. //RSNIE
  1825. if(pattrib->encrypt){
  1826. prsnie = pframe;
  1827. pframe = rtw_set_ie(pframe, _RSN_IE_2_, 20, TDLS_RSNIE, &(pattrib->pktlen));
  1828. }
  1829. //extended capabilities
  1830. pframe = rtw_set_ie(pframe, _EXT_CAP_IE_ , 5, TDLS_EXT_CAPIE, &(pattrib->pktlen));
  1831. //QoS capability(WMM_IE)
  1832. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 7, TDLS_WMMIE, &(pattrib->pktlen));
  1833. if(pattrib->encrypt){
  1834. wpa_tdls_generate_tpk(padapter, ptdls_sta);
  1835. //FTIE
  1836. pftie = pframe;
  1837. pftie_mic = pframe+4;
  1838. _rtw_memset(pframe, 0, 84); //All fields except SNonce shall be set to 0
  1839. _rtw_memset(pframe, _FTIE_, 1); //version
  1840. _rtw_memset((pframe+1), 82, 1); //length
  1841. _rtw_memcpy((pframe+20), ptdls_sta->ANonce, 32);
  1842. _rtw_memcpy((pframe+52), ptdls_sta->SNonce, 32);
  1843. pframe += 84;
  1844. pattrib->pktlen += 84;
  1845. //Timeout interval
  1846. ptimeout_ie = pframe;
  1847. timeout_itvl[0]=0x02;
  1848. _rtw_memcpy(timeout_itvl+1, (u8 *)(&ptdls_sta->TDLS_PeerKey_Lifetime), 4);
  1849. pframe = rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, 5, timeout_itvl, &(pattrib->pktlen));
  1850. }
  1851. //Sup_reg_classes(optional)
  1852. //HT capabilities
  1853. pframe = rtw_tdls_set_ht_cap(padapter, pframe, pattrib);
  1854. //20/40 BSS coexistence
  1855. if(pmlmepriv->num_FortyMHzIntolerant>0)
  1856. iedata |= BIT(2);//20 MHz BSS Width Request
  1857. pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
  1858. //Link identifier
  1859. plinkid_ie = pframe;
  1860. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  1861. _rtw_memcpy((link_id_addr+6), pattrib->dst, 6);
  1862. _rtw_memcpy((link_id_addr+12), pattrib->src, 6);
  1863. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  1864. //fill FTIE mic
  1865. if(pattrib->encrypt)
  1866. wpa_tdls_ftie_mic(ptdls_sta->tpk.kck, 2, plinkid_ie, prsnie, ptimeout_ie, pftie, pftie_mic);
  1867. #ifdef CONFIG_WFD
  1868. wfd_ie_tdls( padapter, pframe, &(pattrib->pktlen) );
  1869. #endif //CONFIG_WFD
  1870. }
  1871. void rtw_build_tdls_setup_cfm_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  1872. {
  1873. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1874. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1875. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1876. struct sta_info *ptdls_sta=rtw_get_stainfo( (&padapter->stapriv) , pattrib->dst);
  1877. u8 payload_type = 0x02;
  1878. unsigned char category = RTW_WLAN_CATEGORY_TDLS;
  1879. unsigned char action = TDLS_SETUP_CONFIRM;
  1880. u8 more_supportedrates = 0;
  1881. unsigned int ie_len;
  1882. unsigned char *p;
  1883. u8 timeout_itvl[5]; //set timeout interval to maximum value
  1884. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1885. u8 link_id_addr[18] = {0};
  1886. u8 *pftie, *ptimeout_ie, *plinkid_ie, *prsnie, *pftie_mic;
  1887. //payload type
  1888. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  1889. //category, action, status code, dialog token
  1890. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  1891. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  1892. pframe = rtw_set_fixed_ie(pframe, 2, (u8 *)&ptdls_sta->stat_code, &(pattrib->pktlen));
  1893. pframe = rtw_set_fixed_ie(pframe, 1, &(ptdls_sta->dialog), &(pattrib->pktlen));
  1894. if(ptdls_sta->stat_code!=0) //invalid setup request
  1895. return;
  1896. //RSNIE
  1897. if(pattrib->encrypt){
  1898. prsnie = pframe;
  1899. pframe = rtw_set_ie(pframe, _RSN_IE_2_, 20, TDLS_RSNIE, &(pattrib->pktlen));
  1900. }
  1901. //EDCA param set; WMM param ele.
  1902. if(pattrib->encrypt){
  1903. //FTIE
  1904. pftie = pframe;
  1905. pftie_mic = pframe+4;
  1906. _rtw_memset(pframe, 0, 84); //All fields except SNonce shall be set to 0
  1907. _rtw_memset(pframe, _FTIE_, 1); //version
  1908. _rtw_memset((pframe+1), 82, 1); //length
  1909. _rtw_memcpy((pframe+20), ptdls_sta->ANonce, 32);
  1910. _rtw_memcpy((pframe+52), ptdls_sta->SNonce, 32);
  1911. pframe += 84;
  1912. pattrib->pktlen += 84;
  1913. //Timeout interval
  1914. ptimeout_ie = pframe;
  1915. timeout_itvl[0]=0x02;
  1916. _rtw_memcpy(timeout_itvl+1, (u8 *)(&ptdls_sta->TDLS_PeerKey_Lifetime), 4);
  1917. ptdls_sta->TPK_count=0;
  1918. _set_timer(&ptdls_sta->TPK_timer, ptdls_sta->TDLS_PeerKey_Lifetime/TPK_RESEND_COUNT);
  1919. pframe = rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, 5, timeout_itvl, &(pattrib->pktlen));
  1920. }
  1921. //HT operation; todo
  1922. //Link identifier
  1923. plinkid_ie = pframe;
  1924. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  1925. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  1926. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  1927. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  1928. //fill FTIE mic
  1929. if(pattrib->encrypt)
  1930. wpa_tdls_ftie_mic(ptdls_sta->tpk.kck, 3, plinkid_ie, prsnie, ptimeout_ie, pftie, pftie_mic);
  1931. }
  1932. void rtw_build_tdls_teardown_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  1933. {
  1934. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1935. u8 payload_type = 0x02;
  1936. unsigned char category = RTW_WLAN_CATEGORY_TDLS;
  1937. unsigned char action = TDLS_TEARDOWN;
  1938. u8 link_id_addr[18] = {0};
  1939. struct sta_info *ptdls_sta = rtw_get_stainfo( &(padapter->stapriv) , pattrib->dst);
  1940. struct sta_priv *pstapriv = &padapter->stapriv;
  1941. //payload type
  1942. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  1943. //category, action, reason code
  1944. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  1945. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  1946. pframe = rtw_set_fixed_ie(pframe, 1, (u8 *)&ptdls_sta->stat_code, &(pattrib->pktlen));
  1947. //Link identifier
  1948. if(ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE){
  1949. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  1950. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  1951. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  1952. }else if(ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE){
  1953. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  1954. _rtw_memcpy((link_id_addr+6), pattrib->dst, 6);
  1955. _rtw_memcpy((link_id_addr+12), pattrib->src, 6);
  1956. }
  1957. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  1958. }
  1959. void rtw_build_tdls_dis_req_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  1960. {
  1961. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1962. u8 payload_type = 0x02;
  1963. u8 category = RTW_WLAN_CATEGORY_TDLS;
  1964. u8 action = TDLS_DISCOVERY_REQUEST;
  1965. u8 link_id_addr[18] = {0};
  1966. static u8 dialogtoken=0;
  1967. //payload type
  1968. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  1969. //category, action, reason code
  1970. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  1971. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  1972. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogtoken), &(pattrib->pktlen));
  1973. dialogtoken = (dialogtoken+1)%256;
  1974. //Link identifier
  1975. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  1976. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  1977. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  1978. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  1979. }
  1980. void rtw_build_tdls_dis_rsp_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe, u8 dialog)
  1981. {
  1982. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1983. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  1984. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1985. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1986. u8 category = RTW_WLAN_CATEGORY_PUBLIC;
  1987. u8 action = TDLS_DISCOVERY_RESPONSE;
  1988. u8 bssrate[NDIS_802_11_LENGTH_RATES_EX];
  1989. int bssrate_len = 0;
  1990. u8 more_supportedrates = 0;
  1991. u8 *p;
  1992. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1993. u8 link_id_addr[18] = {0};
  1994. u8 iedata=0;
  1995. u8 timeout_itvl[5]; //set timeout interval to maximum value
  1996. u32 timeout_interval= TPK_RESEND_COUNT * 1000;
  1997. //category, action, dialog token
  1998. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  1999. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  2000. pframe = rtw_set_fixed_ie(pframe, 1, &(dialog), &(pattrib->pktlen));
  2001. //capability
  2002. _rtw_memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
  2003. if(pattrib->encrypt)
  2004. *pframe =*pframe | BIT(4);
  2005. pframe += 2;
  2006. pattrib->pktlen += 2;
  2007. //supported rates
  2008. rtw_set_supported_rate(bssrate, WIRELESS_11BG_24N);
  2009. bssrate_len = IEEE80211_CCK_RATE_LEN + IEEE80211_NUM_OFDM_RATESLEN;
  2010. if (bssrate_len > 8)
  2011. {
  2012. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
  2013. more_supportedrates = 1;
  2014. }
  2015. else
  2016. {
  2017. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
  2018. }
  2019. //extended supported rates
  2020. if(more_supportedrates==1){
  2021. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
  2022. }
  2023. //supported channels
  2024. pframe = rtw_tdls_set_sup_ch(pmlmeext, pframe, pattrib);
  2025. //RSNIE
  2026. if(pattrib->encrypt)
  2027. pframe = rtw_set_ie(pframe, _RSN_IE_2_, 20, TDLS_RSNIE, &(pattrib->pktlen));
  2028. //extended capability
  2029. pframe = rtw_set_ie(pframe, _EXT_CAP_IE_ , 5, TDLS_EXT_CAPIE, &(pattrib->pktlen));
  2030. if(pattrib->encrypt){
  2031. //FTIE
  2032. _rtw_memset(pframe, 0, 84); //All fields shall be set to 0
  2033. _rtw_memset(pframe, _FTIE_, 1); //version
  2034. _rtw_memset((pframe+1), 82, 1); //length
  2035. pframe += 84;
  2036. pattrib->pktlen += 84;
  2037. //Timeout interval
  2038. timeout_itvl[0]=0x02;
  2039. _rtw_memcpy(timeout_itvl+1, &timeout_interval, 4);
  2040. pframe = rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, 5, timeout_itvl, &(pattrib->pktlen));
  2041. }
  2042. //Sup_reg_classes(optional)
  2043. //HT capabilities
  2044. pframe = rtw_tdls_set_ht_cap(padapter, pframe, pattrib);
  2045. //20/40 BSS coexistence
  2046. if(pmlmepriv->num_FortyMHzIntolerant>0)
  2047. iedata |= BIT(2);//20 MHz BSS Width Request
  2048. pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
  2049. //Link identifier
  2050. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  2051. _rtw_memcpy((link_id_addr+6), pattrib->dst, 6);
  2052. _rtw_memcpy((link_id_addr+12), pattrib->src, 6);
  2053. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  2054. }
  2055. void rtw_build_tdls_peer_traffic_indication_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  2056. {
  2057. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2058. u8 payload_type = 0x02;
  2059. unsigned char category = RTW_WLAN_CATEGORY_TDLS;
  2060. unsigned char action = TDLS_PEER_TRAFFIC_INDICATION;
  2061. u8 link_id_addr[18] = {0};
  2062. u8 AC_queue=0;
  2063. struct sta_priv *pstapriv = &padapter->stapriv;
  2064. struct sta_info *ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->dst);
  2065. //payload type
  2066. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  2067. //category, action, reason code
  2068. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  2069. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  2070. pframe = rtw_set_fixed_ie(pframe, 1, &(ptdls_sta->dialog), &(pattrib->pktlen));
  2071. //Link identifier
  2072. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  2073. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  2074. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  2075. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  2076. //PTI control
  2077. //PU buffer status
  2078. if(ptdls_sta->uapsd_bk&BIT(1))
  2079. AC_queue=BIT(0);
  2080. if(ptdls_sta->uapsd_be&BIT(1))
  2081. AC_queue=BIT(1);
  2082. if(ptdls_sta->uapsd_vi&BIT(1))
  2083. AC_queue=BIT(2);
  2084. if(ptdls_sta->uapsd_vo&BIT(1))
  2085. AC_queue=BIT(3);
  2086. pframe = rtw_set_ie(pframe, _PTI_BUFFER_STATUS_, 1, &AC_queue, &(pattrib->pktlen));
  2087. }
  2088. void rtw_build_tdls_ch_switch_req_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  2089. {
  2090. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2091. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2092. u8 payload_type = 0x02;
  2093. unsigned char category = RTW_WLAN_CATEGORY_TDLS;
  2094. unsigned char action = TDLS_CHANNEL_SWITCH_REQUEST;
  2095. u8 link_id_addr[18] = {0};
  2096. struct sta_priv *pstapriv = &padapter->stapriv;
  2097. struct sta_info *ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->dst);
  2098. u8 ch_switch_timing[4] = {0};
  2099. u16 switch_time= CH_SWITCH_TIME, switch_timeout=CH_SWITCH_TIMEOUT;
  2100. //payload type
  2101. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  2102. //category, action, target_ch
  2103. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  2104. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  2105. pframe = rtw_set_fixed_ie(pframe, 1, &(ptdlsinfo->candidate_ch), &(pattrib->pktlen));
  2106. //Link identifier
  2107. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  2108. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  2109. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  2110. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  2111. //ch switch timing
  2112. _rtw_memcpy(ch_switch_timing, &switch_time, 2);
  2113. _rtw_memcpy(ch_switch_timing+2, &switch_timeout, 2);
  2114. pframe = rtw_set_ie(pframe, _CH_SWITCH_TIMING_, 4, ch_switch_timing, &(pattrib->pktlen));
  2115. //update ch switch attrib to sta_info
  2116. ptdls_sta->off_ch=ptdlsinfo->candidate_ch;
  2117. ptdls_sta->ch_switch_time=switch_time;
  2118. ptdls_sta->ch_switch_timeout=switch_timeout;
  2119. }
  2120. void rtw_build_tdls_ch_switch_rsp_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  2121. {
  2122. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2123. u8 payload_type = 0x02;
  2124. unsigned char category = RTW_WLAN_CATEGORY_TDLS;
  2125. unsigned char action = TDLS_CHANNEL_SWITCH_RESPONSE;
  2126. u8 link_id_addr[18] = {0};
  2127. struct sta_priv *pstapriv = &padapter->stapriv;
  2128. struct sta_info *ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->dst);
  2129. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2130. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  2131. u8 ch_switch_timing[4] = {0};
  2132. //payload type
  2133. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  2134. //category, action, status_code
  2135. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  2136. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  2137. pframe = rtw_set_fixed_ie(pframe, 2, (u8 *)&ptdls_sta->stat_code, &(pattrib->pktlen));
  2138. //Link identifier
  2139. _rtw_memcpy(link_id_addr, pattrib->ra, 6);
  2140. _rtw_memcpy((link_id_addr+6), pattrib->src, 6);
  2141. _rtw_memcpy((link_id_addr+12), pattrib->dst, 6);
  2142. pframe = rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
  2143. //ch switch timing
  2144. _rtw_memcpy(ch_switch_timing, &ptdls_sta->ch_switch_time, 2);
  2145. _rtw_memcpy(ch_switch_timing+2, &ptdls_sta->ch_switch_timeout, 2);
  2146. pframe = rtw_set_ie(pframe, _CH_SWITCH_TIMING_, 4, ch_switch_timing, &(pattrib->pktlen));
  2147. }
  2148. #ifdef CONFIG_WFD
  2149. void rtw_build_tunneled_probe_req_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  2150. {
  2151. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2152. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2153. struct wifidirect_info *pbuddy_wdinfo = &padapter->pbuddy_adapter->wdinfo;
  2154. u8 payload_type = 0x02;
  2155. u8 category = RTW_WLAN_CATEGORY_P2P;
  2156. u8 WFA_OUI[3] = { 0x50, 0x6f, 0x9a};
  2157. u8 probe_req = 4;
  2158. u8 wfdielen = 0;
  2159. //payload type
  2160. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  2161. //category, OUI, frame_body_type
  2162. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  2163. pframe = rtw_set_fixed_ie(pframe, 3, WFA_OUI, &(pattrib->pktlen));
  2164. pframe = rtw_set_fixed_ie(pframe, 1, &(probe_req), &(pattrib->pktlen));
  2165. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2166. {
  2167. wfdielen = build_probe_req_wfd_ie(pwdinfo, pframe);
  2168. pframe += wfdielen;
  2169. pattrib->pktlen += wfdielen;
  2170. }
  2171. else if(!rtw_p2p_chk_state(pbuddy_wdinfo, P2P_STATE_NONE))
  2172. {
  2173. wfdielen = build_probe_req_wfd_ie(pbuddy_wdinfo, pframe);
  2174. pframe += wfdielen;
  2175. pattrib->pktlen += wfdielen;
  2176. }
  2177. }
  2178. void rtw_build_tunneled_probe_rsp_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe)
  2179. {
  2180. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2181. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2182. struct wifidirect_info *pbuddy_wdinfo = &padapter->pbuddy_adapter->wdinfo;
  2183. u8 payload_type = 0x02;
  2184. u8 category = RTW_WLAN_CATEGORY_P2P;
  2185. u8 WFA_OUI[3] = { 0x50, 0x6f, 0x9a};
  2186. u8 probe_rsp = 5;
  2187. u8 wfdielen = 0;
  2188. //payload type
  2189. pframe = rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
  2190. //category, OUI, frame_body_type
  2191. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  2192. pframe = rtw_set_fixed_ie(pframe, 3, WFA_OUI, &(pattrib->pktlen));
  2193. pframe = rtw_set_fixed_ie(pframe, 1, &(probe_rsp), &(pattrib->pktlen));
  2194. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2195. {
  2196. wfdielen = build_probe_resp_wfd_ie(pwdinfo, pframe, 1);
  2197. pframe += wfdielen;
  2198. pattrib->pktlen += wfdielen;
  2199. }
  2200. else if(!rtw_p2p_chk_state(pbuddy_wdinfo, P2P_STATE_NONE))
  2201. {
  2202. wfdielen = build_probe_resp_wfd_ie(pbuddy_wdinfo, pframe, 1);
  2203. pframe += wfdielen;
  2204. pattrib->pktlen += wfdielen;
  2205. }
  2206. }
  2207. #endif //CONFIG_WFD
  2208. void _TPK_timer_hdl(void *FunctionContext)
  2209. {
  2210. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2211. ptdls_sta->TPK_count++;
  2212. //TPK_timer set 1000 as default
  2213. //retry timer should set at least 301 sec.
  2214. if(ptdls_sta->TPK_count==TPK_RESEND_COUNT){
  2215. ptdls_sta->TPK_count=0;
  2216. issue_tdls_setup_req(ptdls_sta->padapter, ptdls_sta->hwaddr);
  2217. }
  2218. _set_timer(&ptdls_sta->TPK_timer, ptdls_sta->TDLS_PeerKey_Lifetime/TPK_RESEND_COUNT);
  2219. }
  2220. void init_TPK_timer(_adapter *padapter, struct sta_info *psta)
  2221. {
  2222. psta->padapter=padapter;
  2223. _init_timer(&psta->TPK_timer, padapter->pnetdev, _TPK_timer_hdl, psta);
  2224. }
  2225. // TDLS_DONE_CH_SEN: channel sensing and report candidate channel
  2226. // TDLS_OFF_CH: first time set channel to off channel
  2227. // TDLS_BASE_CH: when go back to the channel linked with AP, send null data to peer STA as an indication
  2228. void _ch_switch_timer_hdl(void *FunctionContext)
  2229. {
  2230. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2231. _adapter *padapter = ptdls_sta->padapter;
  2232. if( ptdls_sta->option == TDLS_DONE_CH_SEN ){
  2233. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_DONE_CH_SEN);
  2234. }else if( ptdls_sta->option == TDLS_OFF_CH ){
  2235. issue_nulldata_to_TDLS_peer_STA(ptdls_sta->padapter, ptdls_sta, 0);
  2236. _set_timer(&ptdls_sta->base_ch_timer, 500);
  2237. }else if( ptdls_sta->option == TDLS_BASE_CH){
  2238. issue_nulldata_to_TDLS_peer_STA(ptdls_sta->padapter, ptdls_sta, 0);
  2239. }
  2240. }
  2241. void init_ch_switch_timer(_adapter *padapter, struct sta_info *psta)
  2242. {
  2243. psta->padapter=padapter;
  2244. _init_timer(&psta->option_timer, padapter->pnetdev, _ch_switch_timer_hdl, psta);
  2245. }
  2246. void _base_ch_timer_hdl(void *FunctionContext)
  2247. {
  2248. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2249. rtw_tdls_cmd(ptdls_sta->padapter, ptdls_sta->hwaddr, TDLS_P_OFF_CH);
  2250. }
  2251. void init_base_ch_timer(_adapter *padapter, struct sta_info *psta)
  2252. {
  2253. psta->padapter=padapter;
  2254. _init_timer(&psta->base_ch_timer, padapter->pnetdev, _base_ch_timer_hdl, psta);
  2255. }
  2256. void _off_ch_timer_hdl(void *FunctionContext)
  2257. {
  2258. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2259. rtw_tdls_cmd(ptdls_sta->padapter, ptdls_sta->hwaddr, TDLS_P_BASE_CH );
  2260. }
  2261. void init_off_ch_timer(_adapter *padapter, struct sta_info *psta)
  2262. {
  2263. psta->padapter=padapter;
  2264. _init_timer(&psta->off_ch_timer, padapter->pnetdev, _off_ch_timer_hdl, psta);
  2265. }
  2266. void _tdls_handshake_timer_hdl(void *FunctionContext)
  2267. {
  2268. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2269. if(ptdls_sta != NULL)
  2270. {
  2271. if( !(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE) )
  2272. {
  2273. DBG_871X("tdls handshake time out\n");
  2274. free_tdls_sta(ptdls_sta->padapter, ptdls_sta);
  2275. }
  2276. }
  2277. }
  2278. void init_handshake_timer(_adapter *padapter, struct sta_info *psta)
  2279. {
  2280. psta->padapter=padapter;
  2281. _init_timer(&psta->handshake_timer, padapter->pnetdev, _tdls_handshake_timer_hdl, psta);
  2282. }
  2283. //Check tdls peer sta alive.
  2284. void _tdls_alive_timer_phase1_hdl(void *FunctionContext)
  2285. {
  2286. _irqL irqL;
  2287. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2288. _adapter *padapter = ptdls_sta->padapter;
  2289. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2290. _enter_critical_bh(&ptdlsinfo->hdl_lock, &irqL);
  2291. ptdls_sta->timer_flag = 1;
  2292. _exit_critical_bh(&ptdlsinfo->hdl_lock, &irqL);
  2293. ptdls_sta->tdls_sta_state &= (~TDLS_ALIVE_STATE);
  2294. DBG_871X("issue_tdls_dis_req to check alive\n");
  2295. issue_tdls_dis_req( padapter, ptdls_sta->hwaddr);
  2296. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CKALV_PH1);
  2297. sta_update_last_rx_pkts(ptdls_sta);
  2298. if ( ptdls_sta->timer_flag == 2 )
  2299. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_FREE_STA);
  2300. else
  2301. {
  2302. _enter_critical_bh(&ptdlsinfo->hdl_lock, &irqL);
  2303. ptdls_sta->timer_flag = 0;
  2304. _exit_critical_bh(&ptdlsinfo->hdl_lock, &irqL);
  2305. }
  2306. }
  2307. void _tdls_alive_timer_phase2_hdl(void *FunctionContext)
  2308. {
  2309. _irqL irqL;
  2310. struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
  2311. _adapter *padapter = ptdls_sta->padapter;
  2312. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2313. _enter_critical_bh(&(ptdlsinfo->hdl_lock), &irqL);
  2314. ptdls_sta->timer_flag = 1;
  2315. _exit_critical_bh(&ptdlsinfo->hdl_lock, &irqL);
  2316. if( (ptdls_sta->tdls_sta_state & TDLS_ALIVE_STATE) &&
  2317. (sta_last_rx_pkts(ptdls_sta) + 3 <= sta_rx_pkts(ptdls_sta)) )
  2318. {
  2319. DBG_871X("TDLS STA ALIVE, ptdls_sta->sta_stats.last_rx_pkts:%llu, ptdls_sta->sta_stats.rx_pkts:%llu\n",
  2320. sta_last_rx_pkts(ptdls_sta), sta_rx_pkts(ptdls_sta));
  2321. ptdls_sta->alive_count = 0;
  2322. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CKALV_PH2);
  2323. }
  2324. else
  2325. {
  2326. if( !(ptdls_sta->tdls_sta_state & TDLS_ALIVE_STATE) )
  2327. DBG_871X("TDLS STA TOO FAR\n");
  2328. if( !(sta_last_rx_pkts(ptdls_sta) + 3 <= sta_rx_pkts(ptdls_sta)))
  2329. DBG_871X("TDLS LINK WITH LOW TRAFFIC, ptdls_sta->sta_stats.last_rx_pkts:%llu, ptdls_sta->sta_stats.rx_pkts:%llu\n",
  2330. sta_last_rx_pkts(ptdls_sta), sta_rx_pkts(ptdls_sta));
  2331. ptdls_sta->alive_count++;
  2332. if( ptdls_sta->alive_count == TDLS_ALIVE_COUNT )
  2333. {
  2334. ptdls_sta->stat_code = _RSON_TDLS_TEAR_TOOFAR_;
  2335. issue_tdls_teardown(padapter, ptdls_sta->hwaddr);
  2336. }
  2337. else
  2338. {
  2339. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CKALV_PH2);
  2340. }
  2341. }
  2342. if ( ptdls_sta->timer_flag == 2 )
  2343. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_FREE_STA);
  2344. else
  2345. {
  2346. _enter_critical_bh(&(ptdlsinfo->hdl_lock), &irqL);
  2347. ptdls_sta->timer_flag = 0;
  2348. _exit_critical_bh(&ptdlsinfo->hdl_lock, &irqL);
  2349. }
  2350. }
  2351. void init_tdls_alive_timer(_adapter *padapter, struct sta_info *psta)
  2352. {
  2353. psta->padapter=padapter;
  2354. _init_timer(&psta->alive_timer1, padapter->pnetdev, _tdls_alive_timer_phase1_hdl, psta);
  2355. _init_timer(&psta->alive_timer2, padapter->pnetdev, _tdls_alive_timer_phase2_hdl, psta);
  2356. }
  2357. int update_sgi_tdls(_adapter *padapter, struct sta_info *psta)
  2358. {
  2359. struct ht_priv *psta_ht = NULL;
  2360. psta_ht = &psta->htpriv;
  2361. if(psta_ht->ht_option)
  2362. {
  2363. return psta_ht->sgi;
  2364. }
  2365. else
  2366. return _FALSE;
  2367. }
  2368. u32 update_mask_tdls(_adapter *padapter, struct sta_info *psta)
  2369. {
  2370. int i;
  2371. u8 rf_type, id;
  2372. unsigned char sta_band = 0;
  2373. unsigned char limit;
  2374. unsigned int tx_ra_bitmap=0;
  2375. struct ht_priv *psta_ht = NULL;
  2376. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2377. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  2378. psta_ht = &psta->htpriv;
  2379. //b/g mode ra_bitmap
  2380. for (i=0; i<sizeof(psta->bssrateset); i++)
  2381. {
  2382. if (psta->bssrateset[i])
  2383. tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i]&0x7f);
  2384. }
  2385. //n mode ra_bitmap
  2386. if(psta_ht->ht_option)
  2387. {
  2388. padapter->HalFunc.GetHwRegHandler(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  2389. if(rf_type == RF_2T2R)
  2390. limit=16;// 2R
  2391. else
  2392. limit=8;// 1R
  2393. for (i=0; i<limit; i++) {
  2394. if (psta_ht->ht_cap.supp_mcs_set[i/8] & BIT(i%8))
  2395. tx_ra_bitmap |= BIT(i+12);
  2396. }
  2397. }
  2398. if ( pcur_network->Configuration.DSConfig > 14 ) {
  2399. // 5G band
  2400. if (tx_ra_bitmap & 0xffff000)
  2401. sta_band |= WIRELESS_11_5N | WIRELESS_11A;
  2402. else
  2403. sta_band |= WIRELESS_11A;
  2404. } else {
  2405. if (tx_ra_bitmap & 0xffff000)
  2406. sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
  2407. else if (tx_ra_bitmap & 0xff0)
  2408. sta_band |= WIRELESS_11G |WIRELESS_11B;
  2409. else
  2410. sta_band |= WIRELESS_11B;
  2411. }
  2412. //id = networktype_to_raid(sta_band);
  2413. id = rtw_hal_networktype_to_raid(padapter,sta_band);
  2414. tx_ra_bitmap |= ((id<<28)&0xf0000000);
  2415. return tx_ra_bitmap;
  2416. }
  2417. #endif //CONFIG_TDLS