os_intfs.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821
  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 _OS_INTFS_C_
  21. #include <drv_types.h>
  22. #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
  23. #error "Shall be Linux or Windows, but not both!\n"
  24. #endif
  25. MODULE_LICENSE("GPL");
  26. MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
  27. MODULE_AUTHOR("Realtek Semiconductor Corp.");
  28. MODULE_VERSION(DRIVERVERSION);
  29. /* module param defaults */
  30. int rtw_chip_version = 0x00;
  31. int rtw_rfintfs = HWPI;
  32. int rtw_lbkmode = 0;//RTL8712_AIR_TRX;
  33. int rtw_network_mode = Ndis802_11IBSS;//Ndis802_11Infrastructure;//infra, ad-hoc, auto
  34. //NDIS_802_11_SSID ssid;
  35. int rtw_channel = 1;//ad-hoc support requirement
  36. int rtw_wireless_mode = WIRELESS_MODE_MAX;
  37. int rtw_vrtl_carrier_sense = AUTO_VCS;
  38. int rtw_vcs_type = RTS_CTS;//*
  39. int rtw_rts_thresh = 2347;//*
  40. int rtw_frag_thresh = 2346;//*
  41. int rtw_preamble = PREAMBLE_LONG;//long, short, auto
  42. int rtw_scan_mode = 1;//active, passive
  43. int rtw_adhoc_tx_pwr = 1;
  44. int rtw_soft_ap = 0;
  45. //int smart_ps = 1;
  46. #ifdef CONFIG_POWER_SAVING
  47. int rtw_power_mgnt = 1;
  48. #ifdef CONFIG_IPS_LEVEL_2
  49. int rtw_ips_mode = IPS_LEVEL_2;
  50. #else
  51. int rtw_ips_mode = IPS_NORMAL;
  52. #endif
  53. #else
  54. int rtw_power_mgnt = PS_MODE_ACTIVE;
  55. int rtw_ips_mode = IPS_NONE;
  56. #endif
  57. int rtw_smart_ps = 2;
  58. #ifdef CONFIG_TX_EARLY_MODE
  59. int rtw_early_mode=1;
  60. #endif
  61. module_param(rtw_ips_mode, int, 0644);
  62. MODULE_PARM_DESC(rtw_ips_mode,"The default IPS mode");
  63. int rtw_radio_enable = 1;
  64. int rtw_long_retry_lmt = 7;
  65. int rtw_short_retry_lmt = 7;
  66. int rtw_busy_thresh = 40;
  67. //int qos_enable = 0; //*
  68. int rtw_ack_policy = NORMAL_ACK;
  69. int rtw_mp_mode = 0;
  70. int rtw_software_encrypt = 0;
  71. int rtw_software_decrypt = 0;
  72. int rtw_acm_method = 0;// 0:By SW 1:By HW.
  73. int rtw_wmm_enable = 1;// default is set to enable the wmm.
  74. int rtw_uapsd_enable = 0;
  75. int rtw_uapsd_max_sp = NO_LIMIT;
  76. int rtw_uapsd_acbk_en = 0;
  77. int rtw_uapsd_acbe_en = 0;
  78. int rtw_uapsd_acvi_en = 0;
  79. int rtw_uapsd_acvo_en = 0;
  80. #ifdef CONFIG_80211N_HT
  81. int rtw_ht_enable = 1;
  82. // 0: 20 MHz, 1: 40 MHz, 2: 80 MHz, 3: 160MHz, 4: 80+80MHz
  83. // 2.4G use bit 0 ~ 3, 5G use bit 4 ~ 7
  84. // 0x21 means enable 2.4G 40MHz & 5G 80MHz
  85. int rtw_bw_mode = 0x21;
  86. int rtw_cbw40_enable = 3; // 0 :diable, bit(0): enable 2.4g, bit(1): enable 5g
  87. int rtw_ampdu_enable = 1;//for enable tx_ampdu
  88. int rtw_rx_stbc = 1;// 0: disable, bit(0):enable 2.4g, bit(1):enable 5g, default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ
  89. int rtw_ampdu_amsdu = 0;// 0: disabled, 1:enabled, 2:auto
  90. // Short GI support Bit Map
  91. // BIT0 - 20MHz, 0: support, 1: non-support
  92. // BIT1 - 40MHz, 0: support, 1: non-support
  93. // BIT2 - 80MHz, 0: support, 1: non-support
  94. // BIT3 - 160MHz, 0: support, 1: non-support
  95. int rtw_short_gi = 0xf;
  96. #endif //CONFIG_80211N_HT
  97. #ifdef CONFIG_80211AC_VHT
  98. int rtw_vht_enable = 1;
  99. int rtw_ampdu_factor = 7;
  100. int rtw_vht_rate_sel = 0;
  101. // BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx
  102. int rtw_ldpc_cap = 0x33;
  103. // BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx
  104. int rtw_stbc_cap = 0x3;
  105. // BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee
  106. int rtw_beamform_cap = 0;
  107. #endif //CONFIG_80211AC_VHT
  108. int rtw_lowrate_two_xmit = 1;//Use 2 path Tx to transmit MCS0~7 and legacy mode
  109. //int rf_config = RF_1T2R; // 1T2R
  110. int rtw_rf_config = RF_MAX_TYPE; //auto
  111. int rtw_low_power = 0;
  112. #ifdef CONFIG_WIFI_TEST
  113. int rtw_wifi_spec = 1;//for wifi test
  114. #else
  115. int rtw_wifi_spec = 0;
  116. #endif
  117. int rtw_channel_plan = RT_CHANNEL_DOMAIN_MAX;
  118. #ifdef CONFIG_BT_COEXIST
  119. int rtw_btcoex_enable = 1;
  120. int rtw_bt_iso = 2;// 0:Low, 1:High, 2:From Efuse
  121. int rtw_bt_sco = 3;// 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter, 4.Busy, 5.OtherBusy
  122. int rtw_bt_ampdu =1 ;// 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU.
  123. #endif
  124. int rtw_AcceptAddbaReq = _TRUE;// 0:Reject AP's Add BA req, 1:Accept AP's Add BA req.
  125. int rtw_antdiv_cfg = 2; // 0:OFF , 1:ON, 2:decide by Efuse config
  126. int rtw_antdiv_type = 0 ; //0:decide by efuse 1: for 88EE, 1Tx and 1RxCG are diversity.(2 Ant with SPDT), 2: for 88EE, 1Tx and 2Rx are diversity.( 2 Ant, Tx and RxCG are both on aux port, RxCS is on main port ), 3: for 88EE, 1Tx and 1RxCG are fixed.(1Ant, Tx and RxCG are both on aux port)
  127. #ifdef CONFIG_USB_AUTOSUSPEND
  128. int rtw_enusbss = 1;//0:disable,1:enable
  129. #else
  130. int rtw_enusbss = 0;//0:disable,1:enable
  131. #endif
  132. int rtw_hwpdn_mode=2;//0:disable,1:enable,2: by EFUSE config
  133. #ifdef CONFIG_HW_PWRP_DETECTION
  134. int rtw_hwpwrp_detect = 1;
  135. #else
  136. int rtw_hwpwrp_detect = 0; //HW power ping detect 0:disable , 1:enable
  137. #endif
  138. #ifdef CONFIG_USB_HCI
  139. int rtw_hw_wps_pbc = 1;
  140. #else
  141. int rtw_hw_wps_pbc = 0;
  142. #endif
  143. #ifdef CONFIG_TX_MCAST2UNI
  144. int rtw_mc2u_disable = 0;
  145. #endif // CONFIG_TX_MCAST2UNI
  146. #ifdef CONFIG_DUALMAC_CONCURRENT
  147. int rtw_dmsp = 0;
  148. #endif // CONFIG_DUALMAC_CONCURRENT
  149. #ifdef CONFIG_80211D
  150. int rtw_80211d = 0;
  151. #endif
  152. #ifdef CONFIG_REGULATORY_CTRL
  153. int rtw_regulatory_id =2;
  154. #else
  155. int rtw_regulatory_id = 0xff;// Regulatory tab id, 0xff = follow efuse's setting
  156. #endif
  157. module_param(rtw_regulatory_id, int, 0644);
  158. #ifdef CONFIG_SPECIAL_SETTING_FOR_FUNAI_TV
  159. int rtw_force_ant = 2;//0 :normal, 1:Main ant, 2:Aux ant
  160. int rtw_force_igi =0;//0 :normal
  161. module_param(rtw_force_ant, int, 0644);
  162. module_param(rtw_force_igi, int, 0644);
  163. #endif
  164. char* ifname = "wlan%d";
  165. module_param(ifname, charp, 0644);
  166. MODULE_PARM_DESC(ifname, "The default name to allocate for first interface");
  167. char* if2name = "wlan%d";
  168. module_param(if2name, charp, 0644);
  169. MODULE_PARM_DESC(if2name, "The default name to allocate for second interface");
  170. char* rtw_initmac = 0; // temp mac address if users want to use instead of the mac address in Efuse
  171. #ifdef CONFIG_MULTI_VIR_IFACES
  172. int rtw_ext_iface_num = 1;//primary/secondary iface is excluded
  173. module_param(rtw_ext_iface_num, int, 0644);
  174. #endif //CONFIG_MULTI_VIR_IFACES
  175. module_param(rtw_initmac, charp, 0644);
  176. module_param(rtw_channel_plan, int, 0644);
  177. module_param(rtw_chip_version, int, 0644);
  178. module_param(rtw_rfintfs, int, 0644);
  179. module_param(rtw_lbkmode, int, 0644);
  180. module_param(rtw_network_mode, int, 0644);
  181. module_param(rtw_channel, int, 0644);
  182. module_param(rtw_mp_mode, int, 0644);
  183. module_param(rtw_wmm_enable, int, 0644);
  184. module_param(rtw_vrtl_carrier_sense, int, 0644);
  185. module_param(rtw_vcs_type, int, 0644);
  186. module_param(rtw_busy_thresh, int, 0644);
  187. #ifdef CONFIG_80211N_HT
  188. module_param(rtw_ht_enable, int, 0644);
  189. module_param(rtw_bw_mode, int, 0644);
  190. module_param(rtw_ampdu_enable, int, 0644);
  191. module_param(rtw_rx_stbc, int, 0644);
  192. module_param(rtw_ampdu_amsdu, int, 0644);
  193. #endif //CONFIG_80211N_HT
  194. #ifdef CONFIG_80211AC_VHT
  195. module_param(rtw_vht_enable, int, 0644);
  196. #endif //CONFIG_80211AC_VHT
  197. module_param(rtw_lowrate_two_xmit, int, 0644);
  198. module_param(rtw_rf_config, int, 0644);
  199. module_param(rtw_power_mgnt, int, 0644);
  200. module_param(rtw_smart_ps, int, 0644);
  201. module_param(rtw_low_power, int, 0644);
  202. module_param(rtw_wifi_spec, int, 0644);
  203. module_param(rtw_antdiv_cfg, int, 0644);
  204. module_param(rtw_antdiv_type, int, 0644);
  205. module_param(rtw_enusbss, int, 0644);
  206. module_param(rtw_hwpdn_mode, int, 0644);
  207. module_param(rtw_hwpwrp_detect, int, 0644);
  208. module_param(rtw_hw_wps_pbc, int, 0644);
  209. #ifdef CONFIG_TX_EARLY_MODE
  210. module_param(rtw_early_mode, int, 0644);
  211. #endif
  212. #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
  213. char *rtw_adaptor_info_caching_file_path= "/data/misc/wifi/rtw_cache";
  214. module_param(rtw_adaptor_info_caching_file_path, charp, 0644);
  215. MODULE_PARM_DESC(rtw_adaptor_info_caching_file_path, "The path of adapter info cache file");
  216. #endif //CONFIG_ADAPTOR_INFO_CACHING_FILE
  217. #ifdef CONFIG_LAYER2_ROAMING
  218. uint rtw_max_roaming_times=2;
  219. module_param(rtw_max_roaming_times, uint, 0644);
  220. MODULE_PARM_DESC(rtw_max_roaming_times,"The max roaming times to try");
  221. #endif //CONFIG_LAYER2_ROAMING
  222. #ifdef CONFIG_IOL
  223. int rtw_fw_iol=1;// 0:Disable, 1:enable, 2:by usb speed
  224. module_param(rtw_fw_iol, int, 0644);
  225. MODULE_PARM_DESC(rtw_fw_iol,"FW IOL");
  226. #endif //CONFIG_IOL
  227. #ifdef CONFIG_FILE_FWIMG
  228. char *rtw_fw_file_path= "";
  229. module_param(rtw_fw_file_path, charp, 0644);
  230. MODULE_PARM_DESC(rtw_fw_file_path, "The path of fw image");
  231. #endif //CONFIG_FILE_FWIMG
  232. #ifdef CONFIG_TX_MCAST2UNI
  233. module_param(rtw_mc2u_disable, int, 0644);
  234. #endif // CONFIG_TX_MCAST2UNI
  235. #ifdef CONFIG_DUALMAC_CONCURRENT
  236. module_param(rtw_dmsp, int, 0644);
  237. #endif // CONFIG_DUALMAC_CONCURRENT
  238. #ifdef CONFIG_80211D
  239. module_param(rtw_80211d, int, 0644);
  240. MODULE_PARM_DESC(rtw_80211d, "Enable 802.11d mechanism");
  241. #endif
  242. #ifdef CONFIG_BT_COEXIST
  243. module_param(rtw_btcoex_enable, int, 0644);
  244. MODULE_PARM_DESC(rtw_btcoex_enable, "Enable BT co-existence mechanism");
  245. #endif
  246. uint rtw_notch_filter = RTW_NOTCH_FILTER;
  247. module_param(rtw_notch_filter, uint, 0644);
  248. MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P");
  249. #ifdef CONFIG_SW_LED
  250. int rtw_led_enable = 1;
  251. module_param(rtw_led_enable, int, 0644);
  252. MODULE_PARM_DESC(rtw_led_enable,"Enable status LED");
  253. #endif //CONFIG_SW_LED
  254. static uint loadparam(PADAPTER padapter, _nic_hdl pnetdev);
  255. int _netdev_open(struct net_device *pnetdev);
  256. int netdev_open (struct net_device *pnetdev);
  257. static int netdev_close (struct net_device *pnetdev);
  258. //#ifdef RTK_DMP_PLATFORM
  259. #ifdef CONFIG_PROC_DEBUG
  260. #define RTL8192C_PROC_NAME "rtl819xC"
  261. #define RTL8192D_PROC_NAME "rtl819xD"
  262. static char rtw_proc_name[IFNAMSIZ];
  263. static struct proc_dir_entry *rtw_proc = NULL;
  264. static int rtw_proc_cnt = 0;
  265. #define RTW_PROC_NAME DRV_NAME
  266. #if(LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
  267. typedef ssize_t (*read_proc_t) (struct file *, char __user *, ssize_t, loff_t *);
  268. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  269. mode_t mode, struct proc_dir_entry *base,
  270. read_proc_t *read_proc, void * data)
  271. {
  272. struct file_operations fops = {
  273. owner: THIS_MODULE,
  274. read: read_proc
  275. };
  276. struct proc_dir_entry *res = proc_create_data(name, mode, base, &fops, data);
  277. return res;
  278. }
  279. typedef ssize_t (*write_proc_t) (struct file *, const char __user *, ssize_t, loff_t *);
  280. static inline struct proc_dir_entry *create_proc_read_write_entry(const char *name,
  281. mode_t mode, struct proc_dir_entry *base,
  282. read_proc_t *read_proc, void * data, write_proc_t *write_proc)
  283. {
  284. struct file_operations fops = {
  285. owner: THIS_MODULE,
  286. read: read_proc,
  287. write: write_proc
  288. };
  289. struct proc_dir_entry *res = proc_create_data(name, mode, base, &fops, data);
  290. return res;
  291. }
  292. #endif
  293. void rtw_proc_init_one(struct net_device *dev)
  294. {
  295. struct proc_dir_entry *dir_dev = NULL;
  296. struct proc_dir_entry *entry=NULL;
  297. _adapter *padapter = rtw_netdev_priv(dev);
  298. u8 rf_type;
  299. if(rtw_proc == NULL)
  300. {
  301. if(padapter->chip_type == RTL8188C_8192C)
  302. {
  303. _rtw_memcpy(rtw_proc_name, RTL8192C_PROC_NAME, sizeof(RTL8192C_PROC_NAME));
  304. }
  305. else if(padapter->chip_type == RTL8192D)
  306. {
  307. _rtw_memcpy(rtw_proc_name, RTL8192D_PROC_NAME, sizeof(RTL8192D_PROC_NAME));
  308. }
  309. else if(padapter->chip_type == RTL8723A)
  310. {
  311. _rtw_memcpy(rtw_proc_name, RTW_PROC_NAME, sizeof(RTW_PROC_NAME));
  312. }
  313. else if(padapter->chip_type == RTL8188E)
  314. {
  315. _rtw_memcpy(rtw_proc_name, RTW_PROC_NAME, sizeof(RTW_PROC_NAME));
  316. }
  317. else
  318. {
  319. _rtw_memcpy(rtw_proc_name, RTW_PROC_NAME, sizeof(RTW_PROC_NAME));
  320. }
  321. #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  322. rtw_proc=create_proc_entry(rtw_proc_name, S_IFDIR, proc_net);
  323. #elif(LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0))
  324. rtw_proc=create_proc_entry(rtw_proc_name, S_IFDIR, init_net.proc_net);
  325. #else
  326. rtw_proc=proc_create(rtw_proc_name, S_IFDIR, init_net.proc_net, NULL);
  327. #endif
  328. if (rtw_proc == NULL) {
  329. DBG_871X(KERN_ERR "Unable to create rtw_proc directory\n");
  330. return;
  331. }
  332. entry = create_proc_read_entry("ver_info", S_IFREG | S_IRUGO, rtw_proc, proc_get_drv_version, dev);
  333. if (!entry) {
  334. DBG_871X("Unable to create_proc_read_entry!\n");
  335. return;
  336. }
  337. }
  338. if(padapter->dir_dev == NULL)
  339. {
  340. #if(LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0))
  341. padapter->dir_dev = create_proc_entry(dev->name,
  342. S_IFDIR | S_IRUGO | S_IXUGO,
  343. rtw_proc);
  344. #else
  345. padapter->dir_dev = proc_create(dev->name,
  346. S_IFDIR | S_IRUGO | S_IXUGO,
  347. rtw_proc, NULL);
  348. #endif
  349. dir_dev = padapter->dir_dev;
  350. if(dir_dev==NULL)
  351. {
  352. if(rtw_proc_cnt == 0)
  353. {
  354. if(rtw_proc){
  355. #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  356. remove_proc_entry(rtw_proc_name, proc_net);
  357. #else
  358. remove_proc_entry(rtw_proc_name, init_net.proc_net);
  359. #endif
  360. rtw_proc = NULL;
  361. }
  362. }
  363. DBG_871X("Unable to create dir_dev directory\n");
  364. return;
  365. }
  366. }
  367. else
  368. {
  369. return;
  370. }
  371. rtw_proc_cnt++;
  372. entry = create_proc_read_write_entry("write_reg", S_IFREG | S_IRUGO,
  373. dir_dev, proc_get_write_reg, dev, proc_set_write_reg);
  374. if (!entry) {
  375. DBG_871X("Unable to create_proc_read_entry!\n");
  376. return;
  377. }
  378. entry = create_proc_read_write_entry("read_reg", S_IFREG | S_IRUGO,
  379. dir_dev, proc_get_read_reg, dev, proc_set_read_reg);
  380. if (!entry) {
  381. DBG_871X("Unable to create_proc_read_entry!\n");
  382. return;
  383. }
  384. entry = create_proc_read_entry("fwstate", S_IFREG | S_IRUGO,
  385. dir_dev, proc_get_fwstate, dev);
  386. if (!entry) {
  387. DBG_871X("Unable to create_proc_read_entry!\n");
  388. return;
  389. }
  390. entry = create_proc_read_entry("sec_info", S_IFREG | S_IRUGO,
  391. dir_dev, proc_get_sec_info, dev);
  392. if (!entry) {
  393. DBG_871X("Unable to create_proc_read_entry!\n");
  394. return;
  395. }
  396. entry = create_proc_read_entry("mlmext_state", S_IFREG | S_IRUGO,
  397. dir_dev, proc_get_mlmext_state, dev);
  398. if (!entry) {
  399. DBG_871X("Unable to create_proc_read_entry!\n");
  400. return;
  401. }
  402. entry = create_proc_read_entry("qos_option", S_IFREG | S_IRUGO,
  403. dir_dev, proc_get_qos_option, dev);
  404. if (!entry) {
  405. DBG_871X("Unable to create_proc_read_entry!\n");
  406. return;
  407. }
  408. entry = create_proc_read_entry("ht_option", S_IFREG | S_IRUGO,
  409. dir_dev, proc_get_ht_option, dev);
  410. if (!entry) {
  411. DBG_871X("Unable to create_proc_read_entry!\n");
  412. return;
  413. }
  414. entry = create_proc_read_entry("rf_info", S_IFREG | S_IRUGO,
  415. dir_dev, proc_get_rf_info, dev);
  416. if (!entry) {
  417. DBG_871X("Unable to create_proc_read_entry!\n");
  418. return;
  419. }
  420. entry = create_proc_read_entry("ap_info", S_IFREG | S_IRUGO,
  421. dir_dev, proc_get_ap_info, dev);
  422. if (!entry) {
  423. DBG_871X("Unable to create_proc_read_entry!\n");
  424. return;
  425. }
  426. entry = create_proc_read_entry("adapter_state", S_IFREG | S_IRUGO,
  427. dir_dev, proc_get_adapter_state, dev);
  428. if (!entry) {
  429. DBG_871X("Unable to create_proc_read_entry!\n");
  430. return;
  431. }
  432. entry = create_proc_read_entry("trx_info", S_IFREG | S_IRUGO,
  433. dir_dev, proc_get_trx_info, dev);
  434. if (!entry) {
  435. DBG_871X("Unable to create_proc_read_entry!\n");
  436. return;
  437. }
  438. entry = create_proc_read_entry("mac_reg_dump1", S_IFREG | S_IRUGO,
  439. dir_dev, proc_get_mac_reg_dump1, dev);
  440. if (!entry) {
  441. DBG_871X("Unable to create_proc_read_entry!\n");
  442. return;
  443. }
  444. entry = create_proc_read_entry("mac_reg_dump2", S_IFREG | S_IRUGO,
  445. dir_dev, proc_get_mac_reg_dump2, dev);
  446. if (!entry) {
  447. DBG_871X("Unable to create_proc_read_entry!\n");
  448. return;
  449. }
  450. entry = create_proc_read_entry("mac_reg_dump3", S_IFREG | S_IRUGO,
  451. dir_dev, proc_get_mac_reg_dump3, dev);
  452. if (!entry) {
  453. DBG_871X("Unable to create_proc_read_entry!\n");
  454. return;
  455. }
  456. entry = create_proc_read_entry("bb_reg_dump1", S_IFREG | S_IRUGO,
  457. dir_dev, proc_get_bb_reg_dump1, dev);
  458. if (!entry) {
  459. DBG_871X("Unable to create_proc_read_entry!\n");
  460. return;
  461. }
  462. entry = create_proc_read_entry("bb_reg_dump2", S_IFREG | S_IRUGO,
  463. dir_dev, proc_get_bb_reg_dump2, dev);
  464. if (!entry) {
  465. DBG_871X("Unable to create_proc_read_entry!\n");
  466. return;
  467. }
  468. entry = create_proc_read_entry("bb_reg_dump3", S_IFREG | S_IRUGO,
  469. dir_dev, proc_get_bb_reg_dump3, dev);
  470. if (!entry) {
  471. DBG_871X("Unable to create_proc_read_entry!\n");
  472. return;
  473. }
  474. entry = create_proc_read_entry("rf_reg_dump1", S_IFREG | S_IRUGO,
  475. dir_dev, proc_get_rf_reg_dump1, dev);
  476. if (!entry) {
  477. DBG_871X("Unable to create_proc_read_entry!\n");
  478. return;
  479. }
  480. entry = create_proc_read_entry("rf_reg_dump2", S_IFREG | S_IRUGO,
  481. dir_dev, proc_get_rf_reg_dump2, dev);
  482. if (!entry) {
  483. DBG_871X("Unable to create_proc_read_entry!\n");
  484. return;
  485. }
  486. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  487. if((RF_1T2R == rf_type) ||(RF_1T1R ==rf_type )) {
  488. entry = create_proc_read_entry("rf_reg_dump3", S_IFREG | S_IRUGO,
  489. dir_dev, proc_get_rf_reg_dump3, dev);
  490. if (!entry) {
  491. DBG_871X("Unable to create_proc_read_entry!\n");
  492. return;
  493. }
  494. entry = create_proc_read_entry("rf_reg_dump4", S_IFREG | S_IRUGO,
  495. dir_dev, proc_get_rf_reg_dump4, dev);
  496. if (!entry) {
  497. DBG_871X("Unable to create_proc_read_entry!\n");
  498. return;
  499. }
  500. }
  501. #ifdef CONFIG_AP_MODE
  502. entry = create_proc_read_entry("all_sta_info", S_IFREG | S_IRUGO,
  503. dir_dev, proc_get_all_sta_info, dev);
  504. if (!entry) {
  505. DBG_871X("Unable to create_proc_read_entry!\n");
  506. return;
  507. }
  508. #endif
  509. #ifdef DBG_MEMORY_LEAK
  510. entry = create_proc_read_entry("_malloc_cnt", S_IFREG | S_IRUGO,
  511. dir_dev, proc_get_malloc_cnt, dev);
  512. if (!entry) {
  513. DBG_871X("Unable to create_proc_read_entry!\n");
  514. return;
  515. }
  516. #endif
  517. #ifdef CONFIG_FIND_BEST_CHANNEL
  518. entry = create_proc_read_entry("best_channel", S_IFREG | S_IRUGO,
  519. dir_dev, proc_get_best_channel, dev);
  520. if (!entry) {
  521. DBG_871X("Unable to create_proc_read_entry!\n");
  522. return;
  523. }
  524. #endif
  525. entry = create_proc_read_write_entry("rx_signal", S_IFREG | S_IRUGO,
  526. dir_dev, proc_get_rx_signal, dev, proc_set_rx_signal);
  527. if (!entry) {
  528. DBG_871X("Unable to create_proc_read_entry!\n");
  529. return;
  530. }
  531. #ifdef CONFIG_80211N_HT
  532. entry = create_proc_read_write_entry("ht_enable", S_IFREG | S_IRUGO,
  533. dir_dev, proc_get_ht_enable, dev, proc_set_ht_enable);
  534. if (!entry) {
  535. DBG_871X("Unable to create_proc_read_entry!\n");
  536. return;
  537. }
  538. entry = create_proc_read_write_entry("bw_mode", S_IFREG | S_IRUGO,
  539. dir_dev, proc_get_bw_mode, dev, proc_set_bw_mode);
  540. if (!entry) {
  541. DBG_871X("Unable to create_proc_read_entry!\n");
  542. return;
  543. }
  544. entry = create_proc_read_write_entry("ampdu_enable", S_IFREG | S_IRUGO,
  545. dir_dev, proc_get_ampdu_enable, dev, proc_set_ampdu_enable);
  546. if (!entry) {
  547. DBG_871X("Unable to create_proc_read_entry!\n");
  548. return;
  549. }
  550. entry = create_proc_read_write_entry("rx_stbc", S_IFREG | S_IRUGO,
  551. dir_dev, proc_get_rx_stbc, dev, proc_set_rx_stbc);
  552. if (!entry) {
  553. DBG_871X("Unable to create_proc_read_entry!\n");
  554. return;
  555. }
  556. #endif //CONFIG_80211N_HT
  557. entry = create_proc_read_entry("path_rssi", S_IFREG | S_IRUGO,
  558. dir_dev, proc_get_two_path_rssi, dev);
  559. entry = create_proc_read_write_entry("rssi_disp", S_IFREG | S_IRUGO,
  560. dir_dev, proc_get_rssi_disp, dev, proc_set_rssi_disp);
  561. if (!entry) {
  562. DBG_871X("Unable to create_proc_read_entry!\n");
  563. return;
  564. }
  565. #ifdef CONFIG_BT_COEXIST
  566. entry = create_proc_read_write_entry("btcoex_dbg", S_IFREG | S_IRUGO,
  567. dir_dev, proc_get_btcoex_dbg, dev, proc_set_btcoex_dbg);
  568. if (!entry) {
  569. DBG_871X("Unable to create_proc_read_entry!\n");
  570. return;
  571. }
  572. #endif /*CONFIG_BT_COEXIST*/
  573. #if defined(DBG_CONFIG_ERROR_DETECT)
  574. entry = create_proc_read_write_entry("sreset", S_IFREG | S_IRUGO,
  575. dir_dev, proc_get_sreset, dev, proc_set_sreset);
  576. if (!entry) {
  577. DBG_871X("Unable to create_proc_read_entry!\n");
  578. return;
  579. }
  580. #endif /* DBG_CONFIG_ERROR_DETECT */
  581. }
  582. void rtw_proc_remove_one(struct net_device *dev)
  583. {
  584. struct proc_dir_entry *dir_dev = NULL;
  585. _adapter *padapter = rtw_netdev_priv(dev);
  586. u8 rf_type;
  587. dir_dev = padapter->dir_dev;
  588. padapter->dir_dev = NULL;
  589. if (dir_dev) {
  590. remove_proc_entry("write_reg", dir_dev);
  591. remove_proc_entry("read_reg", dir_dev);
  592. remove_proc_entry("fwstate", dir_dev);
  593. remove_proc_entry("sec_info", dir_dev);
  594. remove_proc_entry("mlmext_state", dir_dev);
  595. remove_proc_entry("qos_option", dir_dev);
  596. remove_proc_entry("ht_option", dir_dev);
  597. remove_proc_entry("rf_info", dir_dev);
  598. remove_proc_entry("ap_info", dir_dev);
  599. remove_proc_entry("adapter_state", dir_dev);
  600. remove_proc_entry("trx_info", dir_dev);
  601. remove_proc_entry("mac_reg_dump1", dir_dev);
  602. remove_proc_entry("mac_reg_dump2", dir_dev);
  603. remove_proc_entry("mac_reg_dump3", dir_dev);
  604. remove_proc_entry("bb_reg_dump1", dir_dev);
  605. remove_proc_entry("bb_reg_dump2", dir_dev);
  606. remove_proc_entry("bb_reg_dump3", dir_dev);
  607. remove_proc_entry("rf_reg_dump1", dir_dev);
  608. remove_proc_entry("rf_reg_dump2", dir_dev);
  609. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  610. if((RF_1T2R == rf_type) ||(RF_1T1R ==rf_type )) {
  611. remove_proc_entry("rf_reg_dump3", dir_dev);
  612. remove_proc_entry("rf_reg_dump4", dir_dev);
  613. }
  614. #ifdef CONFIG_AP_MODE
  615. remove_proc_entry("all_sta_info", dir_dev);
  616. #endif
  617. #ifdef DBG_MEMORY_LEAK
  618. remove_proc_entry("_malloc_cnt", dir_dev);
  619. #endif
  620. #ifdef CONFIG_FIND_BEST_CHANNEL
  621. remove_proc_entry("best_channel", dir_dev);
  622. #endif
  623. remove_proc_entry("rx_signal", dir_dev);
  624. #ifdef CONFIG_80211N_HT
  625. remove_proc_entry("bw_mode", dir_dev);
  626. remove_proc_entry("ht_enable", dir_dev);
  627. remove_proc_entry("ampdu_enable", dir_dev);
  628. remove_proc_entry("rx_stbc", dir_dev);
  629. #endif //CONFIG_80211N_HT
  630. remove_proc_entry("path_rssi", dir_dev);
  631. remove_proc_entry("rssi_disp", dir_dev);
  632. #ifdef CONFIG_BT_COEXIST
  633. remove_proc_entry("btcoex_dbg", dir_dev);
  634. #endif //CONFIG_BT_COEXIST
  635. #if defined(DBG_CONFIG_ERROR_DETECT)
  636. remove_proc_entry("sreset", dir_dev);
  637. #endif /* DBG_CONFIG_ERROR_DETECT */
  638. remove_proc_entry(dev->name, rtw_proc);
  639. dir_dev = NULL;
  640. }
  641. else
  642. {
  643. return;
  644. }
  645. rtw_proc_cnt--;
  646. if(rtw_proc_cnt == 0)
  647. {
  648. if(rtw_proc){
  649. remove_proc_entry("ver_info", rtw_proc);
  650. #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  651. remove_proc_entry(rtw_proc_name, proc_net);
  652. #else
  653. remove_proc_entry(rtw_proc_name, init_net.proc_net);
  654. #endif
  655. rtw_proc = NULL;
  656. }
  657. }
  658. }
  659. #endif
  660. uint loadparam( _adapter *padapter, _nic_hdl pnetdev)
  661. {
  662. uint status = _SUCCESS;
  663. struct registry_priv *registry_par = &padapter->registrypriv;
  664. _func_enter_;
  665. registry_par->chip_version = (u8)rtw_chip_version;
  666. registry_par->rfintfs = (u8)rtw_rfintfs;
  667. registry_par->lbkmode = (u8)rtw_lbkmode;
  668. //registry_par->hci = (u8)hci;
  669. registry_par->network_mode = (u8)rtw_network_mode;
  670. _rtw_memcpy(registry_par->ssid.Ssid, "ANY", 3);
  671. registry_par->ssid.SsidLength = 3;
  672. registry_par->channel = (u8)rtw_channel;
  673. registry_par->wireless_mode = (u8)rtw_wireless_mode;
  674. if (IsSupported24G(registry_par->wireless_mode) && (!IsSupported5G(registry_par->wireless_mode))
  675. && (registry_par->channel > 14)) {
  676. registry_par->channel = 1;
  677. }
  678. else if (IsSupported5G(registry_par->wireless_mode) && (!IsSupported24G(registry_par->wireless_mode))
  679. && (registry_par->channel <= 14)) {
  680. registry_par->channel = 36;
  681. }
  682. registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense ;
  683. registry_par->vcs_type = (u8)rtw_vcs_type;
  684. registry_par->rts_thresh=(u16)rtw_rts_thresh;
  685. registry_par->frag_thresh=(u16)rtw_frag_thresh;
  686. registry_par->preamble = (u8)rtw_preamble;
  687. registry_par->scan_mode = (u8)rtw_scan_mode;
  688. registry_par->adhoc_tx_pwr = (u8)rtw_adhoc_tx_pwr;
  689. registry_par->soft_ap= (u8)rtw_soft_ap;
  690. registry_par->smart_ps = (u8)rtw_smart_ps;
  691. registry_par->power_mgnt = (u8)rtw_power_mgnt;
  692. registry_par->ips_mode = (u8)rtw_ips_mode;
  693. registry_par->radio_enable = (u8)rtw_radio_enable;
  694. registry_par->long_retry_lmt = (u8)rtw_long_retry_lmt;
  695. registry_par->short_retry_lmt = (u8)rtw_short_retry_lmt;
  696. registry_par->busy_thresh = (u16)rtw_busy_thresh;
  697. //registry_par->qos_enable = (u8)rtw_qos_enable;
  698. registry_par->ack_policy = (u8)rtw_ack_policy;
  699. registry_par->mp_mode = (u8)rtw_mp_mode;
  700. registry_par->software_encrypt = (u8)rtw_software_encrypt;
  701. registry_par->software_decrypt = (u8)rtw_software_decrypt;
  702. registry_par->acm_method = (u8)rtw_acm_method;
  703. //UAPSD
  704. registry_par->wmm_enable = (u8)rtw_wmm_enable;
  705. registry_par->uapsd_enable = (u8)rtw_uapsd_enable;
  706. registry_par->uapsd_max_sp = (u8)rtw_uapsd_max_sp;
  707. registry_par->uapsd_acbk_en = (u8)rtw_uapsd_acbk_en;
  708. registry_par->uapsd_acbe_en = (u8)rtw_uapsd_acbe_en;
  709. registry_par->uapsd_acvi_en = (u8)rtw_uapsd_acvi_en;
  710. registry_par->uapsd_acvo_en = (u8)rtw_uapsd_acvo_en;
  711. #ifdef CONFIG_80211N_HT
  712. registry_par->ht_enable = (u8)rtw_ht_enable;
  713. registry_par->bw_mode = (u8)rtw_bw_mode;
  714. registry_par->ampdu_enable = (u8)rtw_ampdu_enable;
  715. registry_par->rx_stbc = (u8)rtw_rx_stbc;
  716. registry_par->ampdu_amsdu = (u8)rtw_ampdu_amsdu;
  717. registry_par->short_gi = (u8)rtw_short_gi;
  718. #endif
  719. #ifdef CONFIG_80211AC_VHT
  720. registry_par->vht_enable = (u8)rtw_vht_enable;
  721. registry_par->ampdu_factor = (u8)rtw_ampdu_factor;
  722. registry_par->vht_rate_sel = (u8)rtw_vht_rate_sel;
  723. registry_par->ldpc_cap = (u8)rtw_ldpc_cap;
  724. registry_par->stbc_cap = (u8)rtw_stbc_cap;
  725. registry_par->beamform_cap = (u8)rtw_beamform_cap;
  726. #endif
  727. #ifdef CONFIG_TX_EARLY_MODE
  728. registry_par->early_mode = (u8)rtw_early_mode;
  729. #endif
  730. registry_par->lowrate_two_xmit = (u8)rtw_lowrate_two_xmit;
  731. registry_par->rf_config = (u8)rtw_rf_config;
  732. registry_par->low_power = (u8)rtw_low_power;
  733. registry_par->wifi_spec = (u8)rtw_wifi_spec;
  734. registry_par->channel_plan = (u8)rtw_channel_plan;
  735. #ifdef CONFIG_BT_COEXIST
  736. registry_par->btcoex = (u8)rtw_btcoex_enable;
  737. registry_par->bt_iso = (u8)rtw_bt_iso;
  738. registry_par->bt_sco = (u8)rtw_bt_sco;
  739. registry_par->bt_ampdu = (u8)rtw_bt_ampdu;
  740. #endif
  741. registry_par->bAcceptAddbaReq = (u8)rtw_AcceptAddbaReq;
  742. registry_par->antdiv_cfg = (u8)rtw_antdiv_cfg;
  743. registry_par->antdiv_type = (u8)rtw_antdiv_type;
  744. #ifdef CONFIG_AUTOSUSPEND
  745. registry_par->usbss_enable = (u8)rtw_enusbss;//0:disable,1:enable
  746. #endif
  747. #ifdef SUPPORT_HW_RFOFF_DETECTED
  748. registry_par->hwpdn_mode = (u8)rtw_hwpdn_mode;//0:disable,1:enable,2:by EFUSE config
  749. registry_par->hwpwrp_detect = (u8)rtw_hwpwrp_detect;//0:disable,1:enable
  750. #endif
  751. registry_par->hw_wps_pbc = (u8)rtw_hw_wps_pbc;
  752. #ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
  753. snprintf(registry_par->adaptor_info_caching_file_path, PATH_LENGTH_MAX, "%s", rtw_adaptor_info_caching_file_path);
  754. registry_par->adaptor_info_caching_file_path[PATH_LENGTH_MAX-1]=0;
  755. #endif
  756. #ifdef CONFIG_LAYER2_ROAMING
  757. registry_par->max_roaming_times = (u8)rtw_max_roaming_times;
  758. #ifdef CONFIG_INTEL_WIDI
  759. registry_par->max_roaming_times = (u8)rtw_max_roaming_times + 2;
  760. #endif // CONFIG_INTEL_WIDI
  761. #endif
  762. #ifdef CONFIG_IOL
  763. registry_par->fw_iol = rtw_fw_iol;
  764. #endif
  765. #ifdef CONFIG_DUALMAC_CONCURRENT
  766. registry_par->dmsp= (u8)rtw_dmsp;
  767. #endif
  768. #ifdef CONFIG_80211D
  769. registry_par->enable80211d = (u8)rtw_80211d;
  770. #endif
  771. snprintf(registry_par->ifname, 16, "%s", ifname);
  772. snprintf(registry_par->if2name, 16, "%s", if2name);
  773. registry_par->notch_filter = (u8)rtw_notch_filter;
  774. #ifdef CONFIG_SPECIAL_SETTING_FOR_FUNAI_TV
  775. registry_par->force_ant = (u8)rtw_force_ant;
  776. registry_par->force_igi = (u8)rtw_force_igi;
  777. #endif
  778. registry_par->regulatory_tid = (u8)rtw_regulatory_id;
  779. #ifdef CONFIG_MULTI_VIR_IFACES
  780. registry_par->ext_iface_num = (u8)rtw_ext_iface_num;
  781. #endif //CONFIG_MULTI_VIR_IFACES
  782. #ifdef CONFIG_SW_LED
  783. registry_par->led_enable = (u8)rtw_led_enable;
  784. #endif //CONFIG_SW_LED
  785. _func_exit_;
  786. return status;
  787. }
  788. static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
  789. {
  790. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  791. struct sockaddr *addr = p;
  792. if(padapter->bup == _FALSE)
  793. {
  794. //DBG_871X("r8711_net_set_mac_address(), MAC=%x:%x:%x:%x:%x:%x\n", addr->sa_data[0], addr->sa_data[1], addr->sa_data[2], addr->sa_data[3],
  795. //addr->sa_data[4], addr->sa_data[5]);
  796. _rtw_memcpy(padapter->eeprompriv.mac_addr, addr->sa_data, ETH_ALEN);
  797. //_rtw_memcpy(pnetdev->dev_addr, addr->sa_data, ETH_ALEN);
  798. //padapter->bset_hwaddr = _TRUE;
  799. }
  800. return 0;
  801. }
  802. static struct net_device_stats *rtw_net_get_stats(struct net_device *pnetdev)
  803. {
  804. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  805. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  806. struct recv_priv *precvpriv = &(padapter->recvpriv);
  807. padapter->stats.tx_packets = pxmitpriv->tx_pkts;//pxmitpriv->tx_pkts++;
  808. padapter->stats.rx_packets = precvpriv->rx_pkts;//precvpriv->rx_pkts++;
  809. padapter->stats.tx_dropped = pxmitpriv->tx_drop;
  810. padapter->stats.rx_dropped = precvpriv->rx_drop;
  811. padapter->stats.tx_bytes = pxmitpriv->tx_bytes;
  812. padapter->stats.rx_bytes = precvpriv->rx_bytes;
  813. return &padapter->stats;
  814. }
  815. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
  816. /*
  817. * AC to queue mapping
  818. *
  819. * AC_VO -> queue 0
  820. * AC_VI -> queue 1
  821. * AC_BE -> queue 2
  822. * AC_BK -> queue 3
  823. */
  824. static const u16 rtw_1d_to_queue[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
  825. /* Given a data frame determine the 802.1p/1d tag to use. */
  826. unsigned int rtw_classify8021d(struct sk_buff *skb)
  827. {
  828. unsigned int dscp;
  829. /* skb->priority values from 256->263 are magic values to
  830. * directly indicate a specific 802.1d priority. This is used
  831. * to allow 802.1d priority to be passed directly in from VLAN
  832. * tags, etc.
  833. */
  834. if (skb->priority >= 256 && skb->priority <= 263)
  835. return skb->priority - 256;
  836. switch (skb->protocol) {
  837. case htons(ETH_P_IP):
  838. dscp = ip_hdr(skb)->tos & 0xfc;
  839. break;
  840. default:
  841. return 0;
  842. }
  843. return dscp >> 5;
  844. }
  845. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(4,19,0))
  846. static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
  847. struct net_device *sb_dev,
  848. select_queue_fallback_t fallback
  849. #else
  850. static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb
  851. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
  852. #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
  853. , void *accel_priv
  854. #else
  855. , struct net_device *sb_dev
  856. #endif
  857. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0))
  858. , select_queue_fallback_t fallback
  859. #endif
  860. #endif
  861. #endif
  862. ){
  863. _adapter *padapter = rtw_netdev_priv(dev);
  864. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  865. skb->priority = rtw_classify8021d(skb);
  866. if(pmlmepriv->acm_mask != 0)
  867. {
  868. skb->priority = qos_acm(pmlmepriv->acm_mask, skb->priority);
  869. }
  870. return rtw_1d_to_queue[skb->priority];
  871. }
  872. u16 rtw_recv_select_queue(struct sk_buff *skb)
  873. {
  874. struct iphdr *piphdr;
  875. unsigned int dscp;
  876. u16 eth_type;
  877. u32 priority;
  878. u8 *pdata = skb->data;
  879. _rtw_memcpy(&eth_type, pdata+(ETH_ALEN<<1), 2);
  880. switch (eth_type) {
  881. case htons(ETH_P_IP):
  882. piphdr = (struct iphdr *)(pdata+ETH_HLEN);
  883. dscp = piphdr->tos & 0xfc;
  884. priority = dscp >> 5;
  885. break;
  886. default:
  887. priority = 0;
  888. }
  889. return rtw_1d_to_queue[priority];
  890. }
  891. #endif
  892. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  893. static const struct net_device_ops rtw_netdev_ops = {
  894. .ndo_open = netdev_open,
  895. .ndo_stop = netdev_close,
  896. .ndo_start_xmit = rtw_xmit_entry,
  897. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
  898. .ndo_select_queue = rtw_select_queue,
  899. #endif
  900. .ndo_set_mac_address = rtw_net_set_mac_address,
  901. .ndo_get_stats = rtw_net_get_stats,
  902. .ndo_do_ioctl = rtw_ioctl,
  903. };
  904. #endif
  905. int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname)
  906. {
  907. _adapter *padapter = rtw_netdev_priv(pnetdev);
  908. #ifdef CONFIG_EASY_REPLACEMENT
  909. struct net_device *TargetNetdev = NULL;
  910. _adapter *TargetAdapter = NULL;
  911. struct net *devnet = NULL;
  912. if(padapter->bDongle == 1)
  913. {
  914. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  915. TargetNetdev = dev_get_by_name("wlan0");
  916. #else
  917. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
  918. devnet = pnetdev->nd_net;
  919. #else
  920. devnet = dev_net(pnetdev);
  921. #endif
  922. TargetNetdev = dev_get_by_name(devnet, "wlan0");
  923. #endif
  924. if(TargetNetdev) {
  925. DBG_871X("Force onboard module driver disappear !!!\n");
  926. TargetAdapter = rtw_netdev_priv(TargetNetdev);
  927. TargetAdapter->DriverState = DRIVER_DISAPPEAR;
  928. padapter->pid[0] = TargetAdapter->pid[0];
  929. padapter->pid[1] = TargetAdapter->pid[1];
  930. padapter->pid[2] = TargetAdapter->pid[2];
  931. dev_put(TargetNetdev);
  932. unregister_netdev(TargetNetdev);
  933. if(TargetAdapter->chip_type == padapter->chip_type)
  934. rtw_proc_remove_one(TargetNetdev);
  935. padapter->DriverState = DRIVER_REPLACE_DONGLE;
  936. }
  937. }
  938. #endif //CONFIG_EASY_REPLACEMENT
  939. if(dev_alloc_name(pnetdev, ifname) < 0)
  940. {
  941. RT_TRACE(_module_os_intfs_c_,_drv_err_,("dev_alloc_name, fail! \n"));
  942. }
  943. netif_carrier_off(pnetdev);
  944. //rtw_netif_stop_queue(pnetdev);
  945. return 0;
  946. }
  947. struct net_device *rtw_init_netdev(_adapter *old_padapter)
  948. {
  949. _adapter *padapter;
  950. struct net_device *pnetdev;
  951. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+init_net_dev\n"));
  952. if(old_padapter != NULL)
  953. pnetdev = rtw_alloc_etherdev_with_old_priv(sizeof(_adapter), (void *)old_padapter);
  954. else
  955. pnetdev = rtw_alloc_etherdev(sizeof(_adapter));
  956. if (!pnetdev)
  957. return NULL;
  958. padapter = rtw_netdev_priv(pnetdev);
  959. padapter->pnetdev = pnetdev;
  960. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
  961. SET_MODULE_OWNER(pnetdev);
  962. #endif
  963. //pnetdev->init = NULL;
  964. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  965. DBG_871X("register rtw_netdev_ops to netdev_ops\n");
  966. pnetdev->netdev_ops = &rtw_netdev_ops;
  967. #else
  968. pnetdev->open = netdev_open;
  969. pnetdev->stop = netdev_close;
  970. pnetdev->hard_start_xmit = rtw_xmit_entry;
  971. pnetdev->set_mac_address = rtw_net_set_mac_address;
  972. pnetdev->get_stats = rtw_net_get_stats;
  973. pnetdev->do_ioctl = rtw_ioctl;
  974. #endif
  975. #ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
  976. pnetdev->features |= NETIF_F_IP_CSUM;
  977. #endif
  978. //pnetdev->tx_timeout = NULL;
  979. pnetdev->watchdog_timeo = HZ*3; /* 3 second timeout */
  980. #ifdef CONFIG_WIRELESS_EXT
  981. pnetdev->wireless_handlers = (struct iw_handler_def *)&rtw_handlers_def;
  982. #endif
  983. #ifdef WIRELESS_SPY
  984. //priv->wireless_data.spy_data = &priv->spy_data;
  985. //pnetdev->wireless_data = &priv->wireless_data;
  986. #endif
  987. //step 2.
  988. loadparam(padapter, pnetdev);
  989. return pnetdev;
  990. }
  991. u32 rtw_start_drv_threads(_adapter *padapter)
  992. {
  993. u32 _status = _SUCCESS;
  994. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+rtw_start_drv_threads\n"));
  995. #ifdef CONFIG_XMIT_THREAD_MODE
  996. #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_CONCURRENT_MODE)
  997. if(padapter->adapter_type == PRIMARY_ADAPTER){
  998. #endif
  999. padapter->xmitThread = kthread_run(rtw_xmit_thread, padapter, "RTW_XMIT_THREAD");
  1000. if(IS_ERR(padapter->xmitThread))
  1001. _status = _FAIL;
  1002. #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_CONCURRENT_MODE)
  1003. }
  1004. #endif // CONFIG_SDIO_HCI+CONFIG_CONCURRENT_MODE
  1005. #endif
  1006. #ifdef CONFIG_RECV_THREAD_MODE
  1007. padapter->recvThread = kthread_run(rtw_recv_thread, padapter, "RTW_RECV_THREAD");
  1008. if(IS_ERR(padapter->recvThread))
  1009. _status = _FAIL;
  1010. #endif
  1011. #ifdef CONFIG_CONCURRENT_MODE
  1012. if(padapter->isprimary == _TRUE)
  1013. #endif //CONFIG_CONCURRENT_MODE
  1014. {
  1015. padapter->cmdThread = kthread_run(rtw_cmd_thread, padapter, "RTW_CMD_THREAD");
  1016. if(IS_ERR(padapter->cmdThread))
  1017. _status = _FAIL;
  1018. else
  1019. _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema); //wait for cmd_thread to run
  1020. }
  1021. #ifdef CONFIG_EVENT_THREAD_MODE
  1022. padapter->evtThread = kthread_run(event_thread, padapter, "RTW_EVENT_THREAD");
  1023. if(IS_ERR(padapter->evtThread))
  1024. _status = _FAIL;
  1025. #endif
  1026. rtw_hal_start_thread(padapter);
  1027. return _status;
  1028. }
  1029. void rtw_stop_drv_threads (_adapter *padapter)
  1030. {
  1031. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+rtw_stop_drv_threads\n"));
  1032. #ifdef CONFIG_CONCURRENT_MODE
  1033. if(padapter->isprimary == _TRUE)
  1034. #endif //CONFIG_CONCURRENT_MODE
  1035. {
  1036. //Below is to termindate rtw_cmd_thread & event_thread...
  1037. _rtw_up_sema(&padapter->cmdpriv.cmd_queue_sema);
  1038. //_rtw_up_sema(&padapter->cmdpriv.cmd_done_sema);
  1039. if(padapter->cmdThread){
  1040. _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
  1041. }
  1042. }
  1043. #ifdef CONFIG_EVENT_THREAD_MODE
  1044. _rtw_up_sema(&padapter->evtpriv.evt_notify);
  1045. if(padapter->evtThread){
  1046. _rtw_down_sema(&padapter->evtpriv.terminate_evtthread_sema);
  1047. }
  1048. #endif
  1049. #ifdef CONFIG_XMIT_THREAD_MODE
  1050. // Below is to termindate tx_thread...
  1051. #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_CONCURRENT_MODE)
  1052. // Only wake-up primary adapter
  1053. if(padapter->adapter_type == PRIMARY_ADAPTER)
  1054. #endif //SDIO_HCI + CONCURRENT
  1055. {
  1056. _rtw_up_sema(&padapter->xmitpriv.xmit_sema);
  1057. _rtw_down_sema(&padapter->xmitpriv.terminate_xmitthread_sema);
  1058. }
  1059. RT_TRACE(_module_os_intfs_c_,_drv_info_,("\n drv_halt: rtw_xmit_thread can be terminated ! \n"));
  1060. #endif
  1061. #ifdef CONFIG_RECV_THREAD_MODE
  1062. // Below is to termindate rx_thread...
  1063. _rtw_up_sema(&padapter->recvpriv.recv_sema);
  1064. _rtw_down_sema(&padapter->recvpriv.terminate_recvthread_sema);
  1065. RT_TRACE(_module_os_intfs_c_,_drv_info_,("\n drv_halt:recv_thread can be terminated! \n"));
  1066. #endif
  1067. rtw_hal_stop_thread(padapter);
  1068. }
  1069. u8 rtw_init_default_value(_adapter *padapter);
  1070. u8 rtw_init_default_value(_adapter *padapter)
  1071. {
  1072. u8 ret = _SUCCESS;
  1073. struct registry_priv* pregistrypriv = &padapter->registrypriv;
  1074. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1075. struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
  1076. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1077. //xmit_priv
  1078. pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
  1079. pxmitpriv->vcs = pregistrypriv->vcs_type;
  1080. pxmitpriv->vcs_type = pregistrypriv->vcs_type;
  1081. //pxmitpriv->rts_thresh = pregistrypriv->rts_thresh;
  1082. pxmitpriv->frag_len = pregistrypriv->frag_thresh;
  1083. //recv_priv
  1084. //mlme_priv
  1085. pmlmepriv->scan_interval = SCAN_INTERVAL;// 30*2 sec = 60sec
  1086. pmlmepriv->scan_mode = SCAN_ACTIVE;
  1087. //qos_priv
  1088. //pmlmepriv->qospriv.qos_option = pregistrypriv->wmm_enable;
  1089. //ht_priv
  1090. #ifdef CONFIG_80211N_HT
  1091. pmlmepriv->htpriv.ampdu_enable = _FALSE;//set to disabled
  1092. #endif
  1093. //security_priv
  1094. //rtw_get_encrypt_decrypt_from_registrypriv(padapter);
  1095. psecuritypriv->binstallGrpkey = _FAIL;
  1096. psecuritypriv->sw_encrypt=pregistrypriv->software_encrypt;
  1097. psecuritypriv->sw_decrypt=pregistrypriv->software_decrypt;
  1098. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; //open system
  1099. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  1100. psecuritypriv->dot11PrivacyKeyIndex = 0;
  1101. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  1102. psecuritypriv->dot118021XGrpKeyid = 1;
  1103. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  1104. psecuritypriv->ndisencryptstatus = Ndis802_11WEPDisabled;
  1105. //pwrctrl_priv
  1106. //registry_priv
  1107. rtw_init_registrypriv_dev_network(padapter);
  1108. rtw_update_registrypriv_dev_network(padapter);
  1109. //hal_priv
  1110. rtw_hal_def_value_init(padapter);
  1111. //misc.
  1112. padapter->bReadPortCancel = _FALSE;
  1113. padapter->bWritePortCancel = _FALSE;
  1114. padapter->bLinkInfoDump = 0;
  1115. padapter->bNotifyChannelChange = 0;
  1116. #ifdef CONFIG_P2P
  1117. padapter->bShowGetP2PState = 1;
  1118. #endif
  1119. return ret;
  1120. }
  1121. u8 rtw_reset_drv_sw(_adapter *padapter)
  1122. {
  1123. u8 ret8=_SUCCESS;
  1124. struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
  1125. struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
  1126. //hal_priv
  1127. rtw_hal_def_value_init(padapter);
  1128. padapter->bReadPortCancel = _FALSE;
  1129. padapter->bWritePortCancel = _FALSE;
  1130. padapter->bLinkInfoDump = 0;
  1131. pmlmepriv->scan_interval = SCAN_INTERVAL;// 30*2 sec = 60sec
  1132. padapter->xmitpriv.tx_pkts = 0;
  1133. padapter->recvpriv.rx_pkts = 0;
  1134. pmlmepriv->LinkDetectInfo.bBusyTraffic = _FALSE;
  1135. _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY |_FW_UNDER_LINKING);
  1136. #ifdef CONFIG_AUTOSUSPEND
  1137. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
  1138. adapter_to_dvobj(padapter)->pusbdev->autosuspend_disabled = 1;//autosuspend disabled by the user
  1139. #endif
  1140. #endif
  1141. #ifdef DBG_CONFIG_ERROR_DETECT
  1142. rtw_hal_sreset_reset_value(padapter);
  1143. #endif
  1144. pwrctrlpriv->pwr_state_check_cnts = 0;
  1145. //mlmeextpriv
  1146. padapter->mlmeextpriv.sitesurvey_res.state= SCAN_DISABLE;
  1147. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  1148. rtw_set_signal_stat_timer(&padapter->recvpriv);
  1149. #endif
  1150. return ret8;
  1151. }
  1152. u8 rtw_init_drv_sw(_adapter *padapter)
  1153. {
  1154. u8 ret8=_SUCCESS;
  1155. _func_enter_;
  1156. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+rtw_init_drv_sw\n"));
  1157. ret8 = rtw_init_default_value(padapter);
  1158. if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL)
  1159. {
  1160. RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't init cmd_priv\n"));
  1161. ret8=_FAIL;
  1162. goto exit;
  1163. }
  1164. padapter->cmdpriv.padapter=padapter;
  1165. if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL)
  1166. {
  1167. RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't init evt_priv\n"));
  1168. ret8=_FAIL;
  1169. goto exit;
  1170. }
  1171. if (rtw_init_mlme_priv(padapter) == _FAIL)
  1172. {
  1173. RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't init mlme_priv\n"));
  1174. ret8=_FAIL;
  1175. goto exit;
  1176. }
  1177. #ifdef CONFIG_P2P
  1178. rtw_init_wifidirect_timers(padapter);
  1179. init_wifidirect_info(padapter, P2P_ROLE_DISABLE);
  1180. reset_global_wifidirect_info(padapter);
  1181. #ifdef CONFIG_IOCTL_CFG80211
  1182. rtw_init_cfg80211_wifidirect_info(padapter);
  1183. #endif
  1184. #ifdef CONFIG_WFD
  1185. if(rtw_init_wifi_display_info(padapter) == _FAIL)
  1186. RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't init init_wifi_display_info\n"));
  1187. #endif
  1188. #endif /* CONFIG_P2P */
  1189. if(init_mlme_ext_priv(padapter) == _FAIL)
  1190. {
  1191. RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't init mlme_ext_priv\n"));
  1192. ret8=_FAIL;
  1193. goto exit;
  1194. }
  1195. #ifdef CONFIG_TDLS
  1196. if(rtw_init_tdls_info(padapter) == _FAIL)
  1197. {
  1198. DBG_871X("Can't rtw_init_tdls_info\n");
  1199. ret8=_FAIL;
  1200. goto exit;
  1201. }
  1202. #endif //CONFIG_TDLS
  1203. if(_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL)
  1204. {
  1205. DBG_871X("Can't _rtw_init_xmit_priv\n");
  1206. ret8=_FAIL;
  1207. goto exit;
  1208. }
  1209. if(_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL)
  1210. {
  1211. DBG_871X("Can't _rtw_init_recv_priv\n");
  1212. ret8=_FAIL;
  1213. goto exit;
  1214. }
  1215. // We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc().
  1216. //_rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv));
  1217. //_init_timer(&(padapter->securitypriv.tkip_timer), padapter->pifp, rtw_use_tkipkey_handler, padapter);
  1218. if(_rtw_init_sta_priv(&padapter->stapriv) == _FAIL)
  1219. {
  1220. DBG_871X("Can't _rtw_init_sta_priv\n");
  1221. ret8=_FAIL;
  1222. goto exit;
  1223. }
  1224. padapter->stapriv.padapter = padapter;
  1225. padapter->setband = GHZ24_50;
  1226. rtw_init_bcmc_stainfo(padapter);
  1227. rtw_init_pwrctrl_priv(padapter);
  1228. //_rtw_memset((u8 *)&padapter->qospriv, 0, sizeof (struct qos_priv));//move to mlme_priv
  1229. #ifdef CONFIG_MP_INCLUDED
  1230. if (init_mp_priv(padapter) == _FAIL) {
  1231. DBG_871X("%s: initialize MP private data Fail!\n", __func__);
  1232. }
  1233. #endif
  1234. rtw_hal_dm_init(padapter);
  1235. rtw_hal_sw_led_init(padapter);
  1236. #ifdef DBG_CONFIG_ERROR_DETECT
  1237. rtw_hal_sreset_init(padapter);
  1238. #endif
  1239. #ifdef CONFIG_INTEL_WIDI
  1240. if(rtw_init_intel_widi(padapter) == _FAIL)
  1241. {
  1242. DBG_871X("Can't rtw_init_intel_widi\n");
  1243. ret8=_FAIL;
  1244. goto exit;
  1245. }
  1246. #endif //CONFIG_INTEL_WIDI
  1247. #ifdef CONFIG_WAPI_SUPPORT
  1248. padapter->WapiSupport = true; //set true temp, will revise according to Efuse or Registry value later.
  1249. rtw_wapi_init(padapter);
  1250. #endif
  1251. #ifdef CONFIG_BR_EXT
  1252. _rtw_spinlock_init(&padapter->br_ext_lock);
  1253. #endif // CONFIG_BR_EXT
  1254. exit:
  1255. RT_TRACE(_module_os_intfs_c_,_drv_info_,("-rtw_init_drv_sw\n"));
  1256. _func_exit_;
  1257. return ret8;
  1258. }
  1259. #ifdef CONFIG_WOWLAN
  1260. void rtw_cancel_dynamic_chk_timer(_adapter *padapter)
  1261. {
  1262. _cancel_timer_ex(&padapter->mlmepriv.dynamic_chk_timer);
  1263. RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel dynamic_chk_timer! \n"));
  1264. }
  1265. #endif
  1266. void rtw_cancel_all_timer(_adapter *padapter)
  1267. {
  1268. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+rtw_cancel_all_timer\n"));
  1269. _cancel_timer_ex(&padapter->mlmepriv.assoc_timer);
  1270. RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel association timer complete! \n"));
  1271. //_cancel_timer_ex(&padapter->securitypriv.tkip_timer);
  1272. //RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel tkip_timer! \n"));
  1273. _cancel_timer_ex(&padapter->mlmepriv.scan_to_timer);
  1274. RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel scan_to_timer! \n"));
  1275. _cancel_timer_ex(&padapter->mlmepriv.dynamic_chk_timer);
  1276. RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel dynamic_chk_timer! \n"));
  1277. // cancel sw led timer
  1278. rtw_hal_sw_led_deinit(padapter);
  1279. RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel DeInitSwLeds! \n"));
  1280. _cancel_timer_ex(&padapter->pwrctrlpriv.pwr_state_check_timer);
  1281. #ifdef CONFIG_IOCTL_CFG80211
  1282. #ifdef CONFIG_P2P
  1283. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  1284. #endif //CONFIG_P2P
  1285. #endif //CONFIG_IOCTL_CFG80211
  1286. #ifdef CONFIG_SET_SCAN_DENY_TIMER
  1287. _cancel_timer_ex(&padapter->mlmepriv.set_scan_deny_timer);
  1288. rtw_clear_scan_deny(padapter);
  1289. RT_TRACE(_module_os_intfs_c_,_drv_info_,("rtw_cancel_all_timer:cancel set_scan_deny_timer! \n"));
  1290. #endif
  1291. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  1292. _cancel_timer_ex(&padapter->recvpriv.signal_stat_timer);
  1293. #endif
  1294. //cancel dm timer
  1295. rtw_hal_dm_deinit(padapter);
  1296. #ifdef CONFIG_PLATFORM_FS_MX61
  1297. msleep(50);
  1298. #endif
  1299. }
  1300. u8 rtw_free_drv_sw(_adapter *padapter)
  1301. {
  1302. struct net_device *pnetdev = (struct net_device*)padapter->pnetdev;
  1303. RT_TRACE(_module_os_intfs_c_,_drv_info_,("==>rtw_free_drv_sw"));
  1304. #ifdef CONFIG_WAPI_SUPPORT
  1305. rtw_wapi_free(padapter);
  1306. #endif
  1307. //we can call rtw_p2p_enable here, but:
  1308. // 1. rtw_p2p_enable may have IO operation
  1309. // 2. rtw_p2p_enable is bundled with wext interface
  1310. #ifdef CONFIG_P2P
  1311. {
  1312. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  1313. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1314. {
  1315. _cancel_timer_ex( &pwdinfo->find_phase_timer );
  1316. _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
  1317. _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
  1318. #ifdef CONFIG_CONCURRENT_MODE
  1319. _cancel_timer_ex( &pwdinfo->ap_p2p_switch_timer );
  1320. #endif // CONFIG_CONCURRENT_MODE
  1321. rtw_p2p_set_state(pwdinfo, P2P_STATE_NONE);
  1322. }
  1323. }
  1324. #endif
  1325. #ifdef CONFIG_BR_EXT
  1326. _rtw_spinlock_free(&padapter->br_ext_lock);
  1327. #endif // CONFIG_BR_EXT
  1328. #ifdef CONFIG_INTEL_WIDI
  1329. rtw_free_intel_widi(padapter);
  1330. #endif //CONFIG_INTEL_WIDI
  1331. free_mlme_ext_priv(&padapter->mlmeextpriv);
  1332. #ifdef CONFIG_TDLS
  1333. //rtw_free_tdls_info(&padapter->tdlsinfo);
  1334. #endif //CONFIG_TDLS
  1335. rtw_free_cmd_priv(&padapter->cmdpriv);
  1336. rtw_free_evt_priv(&padapter->evtpriv);
  1337. rtw_free_mlme_priv(&padapter->mlmepriv);
  1338. //free_io_queue(padapter);
  1339. _rtw_free_xmit_priv(&padapter->xmitpriv);
  1340. _rtw_free_sta_priv(&padapter->stapriv); //will free bcmc_stainfo here
  1341. _rtw_free_recv_priv(&padapter->recvpriv);
  1342. rtw_free_pwrctrl_priv(padapter);
  1343. //rtw_mfree((void *)padapter, sizeof (padapter));
  1344. #ifdef CONFIG_DRVEXT_MODULE
  1345. free_drvext(&padapter->drvextpriv);
  1346. #endif
  1347. rtw_hal_free_data(padapter);
  1348. RT_TRACE(_module_os_intfs_c_,_drv_info_,("<==rtw_free_drv_sw\n"));
  1349. //free the old_pnetdev
  1350. if(padapter->rereg_nd_name_priv.old_pnetdev) {
  1351. free_netdev(padapter->rereg_nd_name_priv.old_pnetdev);
  1352. padapter->rereg_nd_name_priv.old_pnetdev = NULL;
  1353. }
  1354. // clear pbuddy_adapter to avoid access wrong pointer.
  1355. if(padapter->pbuddy_adapter != NULL) {
  1356. padapter->pbuddy_adapter->pbuddy_adapter = NULL;
  1357. }
  1358. RT_TRACE(_module_os_intfs_c_,_drv_info_,("-rtw_free_drv_sw\n"));
  1359. return _SUCCESS;
  1360. }
  1361. #ifdef CONFIG_CONCURRENT_MODE
  1362. #ifdef CONFIG_MULTI_VIR_IFACES
  1363. int _netdev_vir_if_open(struct net_device *pnetdev)
  1364. {
  1365. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1366. _adapter *primary_padapter = GET_PRIMARY_ADAPTER(padapter);
  1367. DBG_871X(FUNC_NDEV_FMT" enter\n", FUNC_NDEV_ARG(pnetdev));
  1368. if(!primary_padapter)
  1369. goto _netdev_virtual_iface_open_error;
  1370. if(primary_padapter->bup == _FALSE || primary_padapter->hw_init_completed == _FALSE)
  1371. {
  1372. _netdev_open(primary_padapter->pnetdev);
  1373. }
  1374. if(padapter->bup == _FALSE && primary_padapter->bup == _TRUE &&
  1375. primary_padapter->hw_init_completed == _TRUE)
  1376. {
  1377. int i;
  1378. padapter->bDriverStopped = _FALSE;
  1379. padapter->bSurpriseRemoved = _FALSE;
  1380. padapter->bCardDisableWOHSM = _FALSE;
  1381. rtw_hal_clone_data(padapter, primary_padapter);
  1382. padapter->bFWReady = primary_padapter->bFWReady;
  1383. if(rtw_start_drv_threads(padapter) == _FAIL)
  1384. {
  1385. goto _netdev_virtual_iface_open_error;
  1386. }
  1387. padapter->dir_dev = NULL;
  1388. rtw_proc_init_one(pnetdev);
  1389. #ifdef CONFIG_IOCTL_CFG80211
  1390. rtw_cfg80211_init_wiphy(padapter);
  1391. #endif
  1392. padapter->bup = _TRUE;
  1393. padapter->hw_init_completed = _TRUE;
  1394. }
  1395. padapter->net_closed = _FALSE;
  1396. _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
  1397. if(!rtw_netif_queue_stopped(pnetdev))
  1398. rtw_netif_start_queue(pnetdev);
  1399. else
  1400. rtw_netif_wake_queue(pnetdev);
  1401. DBG_871X(FUNC_NDEV_FMT" exit\n", FUNC_NDEV_ARG(pnetdev));
  1402. return 0;
  1403. _netdev_virtual_iface_open_error:
  1404. padapter->bup = _FALSE;
  1405. netif_carrier_off(pnetdev);
  1406. rtw_netif_stop_queue(pnetdev);
  1407. return (-1);
  1408. }
  1409. int netdev_vir_if_open(struct net_device *pnetdev)
  1410. {
  1411. int ret;
  1412. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1413. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->hw_init_mutex), NULL);
  1414. ret = _netdev_vir_if_open(pnetdev);
  1415. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->hw_init_mutex), NULL);
  1416. #ifdef CONFIG_AUTO_AP_MODE
  1417. //if(padapter->iface_id == 2)
  1418. // rtw_start_auto_ap(padapter);
  1419. #endif
  1420. return ret;
  1421. }
  1422. static int netdev_vir_if_close(struct net_device *pnetdev)
  1423. {
  1424. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1425. padapter->net_closed = _TRUE;
  1426. if(pnetdev)
  1427. {
  1428. if (!rtw_netif_queue_stopped(pnetdev))
  1429. rtw_netif_stop_queue(pnetdev);
  1430. }
  1431. #ifdef CONFIG_IOCTL_CFG80211
  1432. rtw_scan_abort(padapter);
  1433. wdev_to_priv(padapter->rtw_wdev)->bandroid_scan = _FALSE;
  1434. #endif
  1435. return 0;
  1436. }
  1437. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  1438. static const struct net_device_ops rtw_netdev_vir_if_ops = {
  1439. .ndo_open = netdev_vir_if_open,
  1440. .ndo_stop = netdev_vir_if_close,
  1441. .ndo_start_xmit = rtw_xmit_entry,
  1442. .ndo_set_mac_address = rtw_net_set_mac_address,
  1443. .ndo_get_stats = rtw_net_get_stats,
  1444. .ndo_do_ioctl = rtw_ioctl,
  1445. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
  1446. .ndo_select_queue = rtw_select_queue,
  1447. #endif
  1448. };
  1449. #endif
  1450. _adapter *rtw_drv_add_vir_if(_adapter *primary_padapter,
  1451. void (*set_intf_ops)(_adapter *primary_padapter,struct _io_ops *pops))
  1452. {
  1453. int res = _FAIL;
  1454. struct net_device *pnetdev=NULL;
  1455. _adapter *padapter = NULL;
  1456. struct dvobj_priv *pdvobjpriv;
  1457. u8 mac[ETH_ALEN];
  1458. /*
  1459. if((primary_padapter->bup == _FALSE) ||
  1460. (rtw_buddy_adapter_up(primary_padapter) == _FALSE))
  1461. {
  1462. goto error_rtw_drv_add_iface;
  1463. }
  1464. */
  1465. /****** init netdev ******/
  1466. pnetdev = rtw_init_netdev(NULL);
  1467. if (!pnetdev)
  1468. goto error_rtw_drv_add_iface;
  1469. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  1470. DBG_871X("register rtw_netdev_virtual_iface_ops to netdev_ops\n");
  1471. pnetdev->netdev_ops = &rtw_netdev_vir_if_ops;
  1472. #else
  1473. pnetdev->open = netdev_vir_if_open;
  1474. pnetdev->stop = netdev_vir_if_close;
  1475. #endif
  1476. #ifdef CONFIG_NO_WIRELESS_HANDLERS
  1477. pnetdev->wireless_handlers = NULL;
  1478. #endif
  1479. /****** init adapter ******/
  1480. padapter = rtw_netdev_priv(pnetdev);
  1481. _rtw_memcpy(padapter, primary_padapter, sizeof(_adapter));
  1482. //
  1483. padapter->bup = _FALSE;
  1484. padapter->net_closed = _TRUE;
  1485. padapter->hw_init_completed = _FALSE;
  1486. //set adapter_type/iface type
  1487. padapter->isprimary = _FALSE;
  1488. padapter->adapter_type = MAX_ADAPTER;
  1489. padapter->pbuddy_adapter = primary_padapter;
  1490. #if 0
  1491. #ifndef CONFIG_HWPORT_SWAP //Port0 -> Pri , Port1 -> Sec
  1492. padapter->iface_type = IFACE_PORT1;
  1493. #else
  1494. padapter->iface_type = IFACE_PORT0;
  1495. #endif //CONFIG_HWPORT_SWAP
  1496. #else
  1497. //extended virtual interfaces always are set to port0
  1498. padapter->iface_type = IFACE_PORT0;
  1499. #endif
  1500. //
  1501. padapter->pnetdev = pnetdev;
  1502. /****** setup dvobj ******/
  1503. pdvobjpriv = adapter_to_dvobj(padapter);
  1504. padapter->iface_id = pdvobjpriv->iface_nums;
  1505. pdvobjpriv->padapters[pdvobjpriv->iface_nums++] = padapter;
  1506. SET_NETDEV_DEV(pnetdev, dvobj_to_dev(pdvobjpriv));
  1507. #ifdef CONFIG_IOCTL_CFG80211
  1508. rtw_wdev_alloc(padapter, dvobj_to_dev(pdvobjpriv));
  1509. #endif //CONFIG_IOCTL_CFG80211
  1510. //set interface_type/chip_type/HardwareType
  1511. padapter->interface_type = primary_padapter->interface_type;
  1512. padapter->chip_type = primary_padapter->chip_type;
  1513. padapter->HardwareType = primary_padapter->HardwareType;
  1514. //step 2. hook HalFunc, allocate HalData
  1515. //hal_set_hal_ops(padapter);
  1516. rtw_set_hal_ops(padapter);
  1517. padapter->HalFunc.inirp_init = NULL;
  1518. padapter->HalFunc.inirp_deinit = NULL;
  1519. padapter->intf_start = NULL;
  1520. padapter->intf_stop = NULL;
  1521. //step init_io_priv
  1522. if ((rtw_init_io_priv(padapter, set_intf_ops)) == _FAIL) {
  1523. RT_TRACE(_module_hci_intfs_c_,_drv_err_,(" \n Can't init io_reqs\n"));
  1524. }
  1525. //step read_chip_version
  1526. rtw_hal_read_chip_version(padapter);
  1527. //step usb endpoint mapping
  1528. rtw_hal_chip_configure(padapter);
  1529. //init drv data
  1530. if(rtw_init_drv_sw(padapter)!= _SUCCESS)
  1531. goto error_rtw_drv_add_iface;
  1532. //get mac address from primary_padapter
  1533. _rtw_memcpy(mac, primary_padapter->eeprompriv.mac_addr, ETH_ALEN);
  1534. if (((mac[0]==0xff) &&(mac[1]==0xff) && (mac[2]==0xff) &&
  1535. (mac[3]==0xff) && (mac[4]==0xff) &&(mac[5]==0xff)) ||
  1536. ((mac[0]==0x0) && (mac[1]==0x0) && (mac[2]==0x0) &&
  1537. (mac[3]==0x0) && (mac[4]==0x0) &&(mac[5]==0x0)))
  1538. {
  1539. mac[0] = 0x00;
  1540. mac[1] = 0xe0;
  1541. mac[2] = 0x4c;
  1542. mac[3] = 0x87;
  1543. mac[4] = 0x11;
  1544. mac[5] = 0x22;
  1545. }
  1546. else
  1547. {
  1548. //If the BIT1 is 0, the address is universally administered.
  1549. //If it is 1, the address is locally administered
  1550. #if 1 //needs enable MBSSID CAM
  1551. mac[0] |= BIT(1); // locally administered
  1552. mac[0] |= (padapter->iface_id-1)<<4;
  1553. #endif
  1554. }
  1555. _rtw_memcpy(padapter->eeprompriv.mac_addr, mac, ETH_ALEN);
  1556. padapter->dir_dev = NULL;
  1557. res = _SUCCESS;
  1558. return padapter;
  1559. error_rtw_drv_add_iface:
  1560. if(padapter)
  1561. rtw_free_drv_sw(padapter);
  1562. if (pnetdev)
  1563. rtw_free_netdev(pnetdev);
  1564. return NULL;
  1565. }
  1566. void rtw_drv_stop_vir_if(_adapter *padapter)
  1567. {
  1568. struct net_device *pnetdev=NULL;
  1569. if (padapter == NULL)
  1570. return;
  1571. pnetdev = padapter->pnetdev;
  1572. if(pnetdev)
  1573. {
  1574. unregister_netdev(pnetdev); //will call netdev_close()
  1575. rtw_proc_remove_one(pnetdev);
  1576. }
  1577. rtw_cancel_all_timer(padapter);
  1578. if(padapter->bup == _TRUE)
  1579. {
  1580. padapter->bDriverStopped = _TRUE;
  1581. #ifdef CONFIG_XMIT_ACK
  1582. if (padapter->xmitpriv.ack_tx)
  1583. rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
  1584. #endif
  1585. if(padapter->intf_stop)
  1586. {
  1587. padapter->intf_stop(padapter);
  1588. }
  1589. rtw_stop_drv_threads(padapter);
  1590. padapter->bup = _FALSE;
  1591. }
  1592. #ifdef CONFIG_IOCTL_CFG80211
  1593. rtw_wdev_unregister(padapter->rtw_wdev);
  1594. #endif //CONFIG_IOCTL_CFG80211
  1595. }
  1596. void rtw_drv_free_vir_if(_adapter *padapter)
  1597. {
  1598. struct net_device *pnetdev=NULL;
  1599. if (padapter == NULL)
  1600. return;
  1601. padapter->pbuddy_adapter = NULL;
  1602. pnetdev = padapter->pnetdev;
  1603. #ifdef CONFIG_IOCTL_CFG80211
  1604. rtw_wdev_free(padapter->rtw_wdev);
  1605. #endif //CONFIG_IOCTL_CFG80211
  1606. rtw_free_drv_sw(padapter);
  1607. rtw_free_netdev(pnetdev);
  1608. }
  1609. void rtw_drv_stop_vir_ifaces(struct dvobj_priv *dvobj)
  1610. {
  1611. int i;
  1612. //struct dvobj_priv *dvobj = primary_padapter->dvobj;
  1613. for(i=2;i<dvobj->iface_nums;i++)
  1614. {
  1615. rtw_drv_stop_vir_if(dvobj->padapters[i]);
  1616. }
  1617. }
  1618. void rtw_drv_free_vir_ifaces(struct dvobj_priv *dvobj)
  1619. {
  1620. int i;
  1621. //struct dvobj_priv *dvobj = primary_padapter->dvobj;
  1622. for(i=2;i<dvobj->iface_nums;i++)
  1623. {
  1624. rtw_drv_free_vir_if(dvobj->padapters[i]);
  1625. }
  1626. }
  1627. void rtw_drv_del_vir_if(_adapter *padapter)
  1628. {
  1629. rtw_drv_stop_vir_if(padapter);
  1630. rtw_drv_free_vir_if(padapter);
  1631. }
  1632. void rtw_drv_del_vir_ifaces(_adapter *primary_padapter)
  1633. {
  1634. int i;
  1635. struct dvobj_priv *dvobj = primary_padapter->dvobj;
  1636. for(i=2;i<dvobj->iface_nums;i++)
  1637. {
  1638. rtw_drv_del_vir_if(dvobj->padapters[i]);
  1639. }
  1640. }
  1641. #endif //CONFIG_MULTI_VIR_IFACES
  1642. int _netdev_if2_open(struct net_device *pnetdev)
  1643. {
  1644. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1645. _adapter *primary_padapter = padapter->pbuddy_adapter;
  1646. DBG_871X("+871x_drv - if2_open, bup=%d\n", padapter->bup);
  1647. if(primary_padapter->bup == _FALSE || primary_padapter->hw_init_completed == _FALSE)
  1648. {
  1649. _netdev_open(primary_padapter->pnetdev);
  1650. }
  1651. if(padapter->bup == _FALSE && primary_padapter->bup == _TRUE &&
  1652. primary_padapter->hw_init_completed == _TRUE)
  1653. {
  1654. int i;
  1655. padapter->bDriverStopped = _FALSE;
  1656. padapter->bSurpriseRemoved = _FALSE;
  1657. padapter->bCardDisableWOHSM = _FALSE;
  1658. // _rtw_memcpy(padapter->HalData, primary_padapter->HalData, padapter->hal_data_sz);
  1659. rtw_hal_clone_data(padapter, primary_padapter);
  1660. padapter->bFWReady = primary_padapter->bFWReady;
  1661. //if (init_mlme_ext_priv(padapter) == _FAIL)
  1662. // goto netdev_if2_open_error;
  1663. if(rtw_start_drv_threads(padapter) == _FAIL)
  1664. {
  1665. goto netdev_if2_open_error;
  1666. }
  1667. if(padapter->intf_start)
  1668. {
  1669. padapter->intf_start(padapter);
  1670. }
  1671. padapter->hw_init_completed = _TRUE;
  1672. padapter->dir_dev = NULL;
  1673. rtw_proc_init_one(pnetdev);
  1674. #ifdef CONFIG_IOCTL_CFG80211
  1675. rtw_cfg80211_init_wiphy(padapter);
  1676. #endif
  1677. padapter->bup = _TRUE;
  1678. }
  1679. padapter->net_closed = _FALSE;
  1680. _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
  1681. if(!rtw_netif_queue_stopped(pnetdev))
  1682. rtw_netif_start_queue(pnetdev);
  1683. else
  1684. rtw_netif_wake_queue(pnetdev);
  1685. DBG_871X("-871x_drv - if2_open, bup=%d\n", padapter->bup);
  1686. return 0;
  1687. netdev_if2_open_error:
  1688. padapter->bup = _FALSE;
  1689. netif_carrier_off(pnetdev);
  1690. rtw_netif_stop_queue(pnetdev);
  1691. return (-1);
  1692. }
  1693. int netdev_if2_open(struct net_device *pnetdev)
  1694. {
  1695. int ret;
  1696. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1697. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->hw_init_mutex), NULL);
  1698. ret = _netdev_if2_open(pnetdev);
  1699. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->hw_init_mutex), NULL);
  1700. #ifdef CONFIG_AUTO_AP_MODE
  1701. //if(padapter->iface_id == 2)
  1702. rtw_start_auto_ap(padapter);
  1703. #endif
  1704. return ret;
  1705. }
  1706. static int netdev_if2_close(struct net_device *pnetdev)
  1707. {
  1708. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1709. padapter->net_closed = _TRUE;
  1710. if(pnetdev)
  1711. {
  1712. if (!rtw_netif_queue_stopped(pnetdev))
  1713. rtw_netif_stop_queue(pnetdev);
  1714. }
  1715. #ifdef CONFIG_IOCTL_CFG80211
  1716. rtw_scan_abort(padapter);
  1717. wdev_to_priv(padapter->rtw_wdev)->bandroid_scan = _FALSE;
  1718. #endif
  1719. return 0;
  1720. }
  1721. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  1722. static const struct net_device_ops rtw_netdev_if2_ops = {
  1723. .ndo_open = netdev_if2_open,
  1724. .ndo_stop = netdev_if2_close,
  1725. .ndo_start_xmit = rtw_xmit_entry,
  1726. .ndo_set_mac_address = rtw_net_set_mac_address,
  1727. .ndo_get_stats = rtw_net_get_stats,
  1728. .ndo_do_ioctl = rtw_ioctl,
  1729. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
  1730. .ndo_select_queue = rtw_select_queue,
  1731. #endif
  1732. };
  1733. #endif
  1734. _adapter *rtw_drv_if2_init(_adapter *primary_padapter,
  1735. void (*set_intf_ops)(_adapter *primary_padapter,struct _io_ops *pops))
  1736. {
  1737. int res = _FAIL;
  1738. struct net_device *pnetdev = NULL;
  1739. _adapter *padapter = NULL;
  1740. struct dvobj_priv *pdvobjpriv;
  1741. u8 mac[ETH_ALEN];
  1742. /****** init netdev ******/
  1743. pnetdev = rtw_init_netdev(NULL);
  1744. if (!pnetdev)
  1745. goto error_rtw_drv_if2_init;
  1746. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  1747. DBG_871X("register rtw_netdev_if2_ops to netdev_ops\n");
  1748. pnetdev->netdev_ops = &rtw_netdev_if2_ops;
  1749. #else
  1750. pnetdev->open = netdev_if2_open;
  1751. pnetdev->stop = netdev_if2_close;
  1752. #endif
  1753. #ifdef CONFIG_NO_WIRELESS_HANDLERS
  1754. pnetdev->wireless_handlers = NULL;
  1755. #endif
  1756. /****** init adapter ******/
  1757. padapter = rtw_netdev_priv(pnetdev);
  1758. _rtw_memcpy(padapter, primary_padapter, sizeof(_adapter));
  1759. //
  1760. padapter->bup = _FALSE;
  1761. padapter->net_closed = _TRUE;
  1762. padapter->hw_init_completed = _FALSE;
  1763. //set adapter_type/iface type
  1764. padapter->isprimary = _FALSE;
  1765. padapter->adapter_type = SECONDARY_ADAPTER;
  1766. padapter->pbuddy_adapter = primary_padapter;
  1767. padapter->iface_id = IFACE_ID1;
  1768. #ifndef CONFIG_HWPORT_SWAP //Port0 -> Pri , Port1 -> Sec
  1769. padapter->iface_type = IFACE_PORT1;
  1770. #else
  1771. padapter->iface_type = IFACE_PORT0;
  1772. #endif //CONFIG_HWPORT_SWAP
  1773. //
  1774. padapter->pnetdev = pnetdev;
  1775. /****** setup dvobj ******/
  1776. pdvobjpriv = adapter_to_dvobj(padapter);
  1777. pdvobjpriv->if2 = padapter;
  1778. pdvobjpriv->padapters[pdvobjpriv->iface_nums++] = padapter;
  1779. SET_NETDEV_DEV(pnetdev, dvobj_to_dev(pdvobjpriv));
  1780. #ifdef CONFIG_IOCTL_CFG80211
  1781. rtw_wdev_alloc(padapter, dvobj_to_dev(pdvobjpriv));
  1782. #endif //CONFIG_IOCTL_CFG80211
  1783. //set interface_type/chip_type/HardwareType
  1784. padapter->interface_type = primary_padapter->interface_type;
  1785. padapter->chip_type = primary_padapter->chip_type;
  1786. padapter->HardwareType = primary_padapter->HardwareType;
  1787. //step 2. hook HalFunc, allocate HalData
  1788. //hal_set_hal_ops(padapter);
  1789. rtw_set_hal_ops(padapter);
  1790. padapter->HalFunc.inirp_init = NULL;
  1791. padapter->HalFunc.inirp_deinit = NULL;
  1792. //
  1793. padapter->intf_start = primary_padapter->intf_start;
  1794. padapter->intf_stop = primary_padapter->intf_stop;
  1795. //step init_io_priv
  1796. if ((rtw_init_io_priv(padapter, set_intf_ops)) == _FAIL) {
  1797. RT_TRACE(_module_hci_intfs_c_,_drv_err_,(" \n Can't init io_reqs\n"));
  1798. }
  1799. //step read_chip_version
  1800. rtw_hal_read_chip_version(padapter);
  1801. //step usb endpoint mapping
  1802. rtw_hal_chip_configure(padapter);
  1803. //init drv data
  1804. if(rtw_init_drv_sw(padapter)!= _SUCCESS)
  1805. goto error_rtw_drv_if2_init;
  1806. //get mac address from primary_padapter
  1807. _rtw_memcpy(mac, primary_padapter->eeprompriv.mac_addr, ETH_ALEN);
  1808. if (((mac[0]==0xff) &&(mac[1]==0xff) && (mac[2]==0xff) &&
  1809. (mac[3]==0xff) && (mac[4]==0xff) &&(mac[5]==0xff)) ||
  1810. ((mac[0]==0x0) && (mac[1]==0x0) && (mac[2]==0x0) &&
  1811. (mac[3]==0x0) && (mac[4]==0x0) &&(mac[5]==0x0)))
  1812. {
  1813. mac[0] = 0x00;
  1814. mac[1] = 0xe0;
  1815. mac[2] = 0x4c;
  1816. mac[3] = 0x87;
  1817. mac[4] = 0x11;
  1818. mac[5] = 0x22;
  1819. }
  1820. else
  1821. {
  1822. //If the BIT1 is 0, the address is universally administered.
  1823. //If it is 1, the address is locally administered
  1824. mac[0] |= BIT(1); // locally administered
  1825. }
  1826. _rtw_memcpy(padapter->eeprompriv.mac_addr, mac, ETH_ALEN);
  1827. rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr);
  1828. primary_padapter->pbuddy_adapter = padapter;
  1829. padapter->dir_dev = NULL;
  1830. res = _SUCCESS;
  1831. return padapter;
  1832. error_rtw_drv_if2_init:
  1833. if(padapter)
  1834. rtw_free_drv_sw(padapter);
  1835. if (pnetdev)
  1836. rtw_free_netdev(pnetdev);
  1837. return NULL;
  1838. }
  1839. void rtw_drv_if2_free(_adapter *if2)
  1840. {
  1841. _adapter *padapter = if2;
  1842. struct net_device *pnetdev = NULL;
  1843. if (padapter == NULL)
  1844. return;
  1845. pnetdev = padapter->pnetdev;
  1846. #ifdef CONFIG_IOCTL_CFG80211
  1847. rtw_wdev_free(padapter->rtw_wdev);
  1848. #endif /* CONFIG_IOCTL_CFG80211 */
  1849. rtw_free_drv_sw(padapter);
  1850. rtw_free_netdev(pnetdev);
  1851. }
  1852. void rtw_drv_if2_stop(_adapter *if2)
  1853. {
  1854. _adapter *padapter = if2;
  1855. struct net_device *pnetdev = NULL;
  1856. if (padapter == NULL)
  1857. return;
  1858. pnetdev = padapter->pnetdev;
  1859. if (pnetdev) {
  1860. unregister_netdev(pnetdev); //will call netdev_close()
  1861. rtw_proc_remove_one(pnetdev);
  1862. }
  1863. rtw_cancel_all_timer(padapter);
  1864. if (padapter->bup == _TRUE) {
  1865. padapter->bDriverStopped = _TRUE;
  1866. #ifdef CONFIG_XMIT_ACK
  1867. if (padapter->xmitpriv.ack_tx)
  1868. rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
  1869. #endif
  1870. if(padapter->intf_stop)
  1871. {
  1872. padapter->intf_stop(padapter);
  1873. }
  1874. rtw_stop_drv_threads(padapter);
  1875. padapter->bup = _FALSE;
  1876. }
  1877. #ifdef CONFIG_IOCTL_CFG80211
  1878. rtw_wdev_unregister(padapter->rtw_wdev);
  1879. #endif
  1880. }
  1881. #endif //end of CONFIG_CONCURRENT_MODE
  1882. #ifdef CONFIG_BR_EXT
  1883. void netdev_br_init(struct net_device *netdev)
  1884. {
  1885. _adapter *adapter = (_adapter *)rtw_netdev_priv(netdev);
  1886. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1887. rcu_read_lock();
  1888. #endif // (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1889. //if(check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) == _TRUE)
  1890. {
  1891. //struct net_bridge *br = netdev->br_port->br;//->dev->dev_addr;
  1892. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  1893. if (netdev->br_port)
  1894. #else // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  1895. if (rcu_dereference(adapter->pnetdev->rx_handler_data))
  1896. #endif // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  1897. {
  1898. struct net_device *br_netdev;
  1899. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  1900. br_netdev = dev_get_by_name(CONFIG_BR_EXT_BRNAME);
  1901. #else // (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  1902. struct net *devnet = NULL;
  1903. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
  1904. devnet = netdev->nd_net;
  1905. #else // (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
  1906. devnet = dev_net(netdev);
  1907. #endif // (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
  1908. br_netdev = dev_get_by_name(devnet, CONFIG_BR_EXT_BRNAME);
  1909. #endif // (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
  1910. if (br_netdev) {
  1911. memcpy(adapter->br_mac, br_netdev->dev_addr, ETH_ALEN);
  1912. dev_put(br_netdev);
  1913. } else
  1914. printk("%s()-%d: dev_get_by_name(%s) failed!", __FUNCTION__, __LINE__, CONFIG_BR_EXT_BRNAME);
  1915. }
  1916. adapter->ethBrExtInfo.addPPPoETag = 1;
  1917. }
  1918. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1919. rcu_read_unlock();
  1920. #endif // (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1921. }
  1922. #endif //CONFIG_BR_EXT
  1923. static int _rtw_drv_register_netdev(_adapter *padapter, char *name)
  1924. {
  1925. int ret = _SUCCESS;
  1926. struct net_device *pnetdev = padapter->pnetdev;
  1927. /* alloc netdev name */
  1928. rtw_init_netdev_name(pnetdev, name);
  1929. _rtw_memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
  1930. /* Tell the network stack we exist */
  1931. if (register_netdev(pnetdev) != 0) {
  1932. DBG_871X(FUNC_NDEV_FMT "Failed!\n", FUNC_NDEV_ARG(pnetdev));
  1933. ret = _FAIL;
  1934. goto error_register_netdev;
  1935. }
  1936. DBG_871X("%s, MAC Address (if%d) = " MAC_FMT "\n", __FUNCTION__, (padapter->iface_id+1), MAC_ARG(pnetdev->dev_addr));
  1937. return ret;
  1938. error_register_netdev:
  1939. if(padapter->iface_id > IFACE_ID0)
  1940. {
  1941. rtw_free_drv_sw(padapter);
  1942. rtw_free_netdev(pnetdev);
  1943. }
  1944. return ret;
  1945. }
  1946. int rtw_drv_register_netdev(_adapter *if1)
  1947. {
  1948. int i, status = _SUCCESS;
  1949. struct dvobj_priv *dvobj = if1->dvobj;
  1950. if(dvobj->iface_nums < IFACE_ID_MAX)
  1951. {
  1952. for(i=0; i<dvobj->iface_nums; i++)
  1953. {
  1954. _adapter *padapter = dvobj->padapters[i];
  1955. if(padapter)
  1956. {
  1957. char *name;
  1958. if(padapter->iface_id == IFACE_ID0)
  1959. name = if1->registrypriv.ifname;
  1960. else if(padapter->iface_id == IFACE_ID1)
  1961. name = if1->registrypriv.if2name;
  1962. else
  1963. name = "wlan%d";
  1964. if((status = _rtw_drv_register_netdev(padapter, name)) != _SUCCESS) {
  1965. break;
  1966. }
  1967. }
  1968. }
  1969. }
  1970. return status;
  1971. }
  1972. int _netdev_open(struct net_device *pnetdev)
  1973. {
  1974. uint status;
  1975. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  1976. struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
  1977. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+871x_drv - dev_open\n"));
  1978. DBG_871X("+871x_drv - drv_open, bup=%d\n", padapter->bup);
  1979. if(pwrctrlpriv->ps_flag == _TRUE){
  1980. padapter->net_closed = _FALSE;
  1981. goto netdev_open_normal_process;
  1982. }
  1983. if(padapter->bup == _FALSE)
  1984. {
  1985. padapter->bDriverStopped = _FALSE;
  1986. padapter->bSurpriseRemoved = _FALSE;
  1987. padapter->bCardDisableWOHSM = _FALSE;
  1988. status = rtw_hal_init(padapter);
  1989. if (status ==_FAIL)
  1990. {
  1991. RT_TRACE(_module_os_intfs_c_,_drv_err_,("rtl871x_hal_init(): Can't init h/w!\n"));
  1992. goto netdev_open_error;
  1993. }
  1994. DBG_871X("MAC Address = "MAC_FMT"\n", MAC_ARG(pnetdev->dev_addr));
  1995. status=rtw_start_drv_threads(padapter);
  1996. if(status ==_FAIL)
  1997. {
  1998. DBG_871X("Initialize driver software resource Failed!\n");
  1999. goto netdev_open_error;
  2000. }
  2001. if (init_hw_mlme_ext(padapter) == _FAIL)
  2002. {
  2003. DBG_871X("can't init mlme_ext_priv\n");
  2004. goto netdev_open_error;
  2005. }
  2006. #ifdef CONFIG_DRVEXT_MODULE
  2007. init_drvext(padapter);
  2008. #endif
  2009. if(padapter->intf_start)
  2010. {
  2011. padapter->intf_start(padapter);
  2012. }
  2013. #ifndef RTK_DMP_PLATFORM
  2014. rtw_proc_init_one(pnetdev);
  2015. #endif
  2016. #ifdef CONFIG_IOCTL_CFG80211
  2017. rtw_cfg80211_init_wiphy(padapter);
  2018. #endif
  2019. rtw_led_control(padapter, LED_CTL_NO_LINK);
  2020. padapter->bup = _TRUE;
  2021. }
  2022. padapter->net_closed = _FALSE;
  2023. _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
  2024. padapter->pwrctrlpriv.bips_processing = _FALSE;
  2025. rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
  2026. //netif_carrier_on(pnetdev);//call this func when rtw_joinbss_event_callback return success
  2027. if(!rtw_netif_queue_stopped(pnetdev))
  2028. rtw_netif_start_queue(pnetdev);
  2029. else
  2030. rtw_netif_wake_queue(pnetdev);
  2031. #ifdef CONFIG_BR_EXT
  2032. netdev_br_init(pnetdev);
  2033. #endif // CONFIG_BR_EXT
  2034. netdev_open_normal_process:
  2035. #ifdef CONFIG_CONCURRENT_MODE
  2036. {
  2037. _adapter *sec_adapter = padapter->pbuddy_adapter;
  2038. if(sec_adapter && (sec_adapter->bup == _FALSE || sec_adapter->hw_init_completed == _FALSE))
  2039. _netdev_if2_open(sec_adapter->pnetdev);
  2040. }
  2041. #endif
  2042. RT_TRACE(_module_os_intfs_c_,_drv_info_,("-871x_drv - dev_open\n"));
  2043. DBG_871X("-871x_drv - drv_open, bup=%d\n", padapter->bup);
  2044. return 0;
  2045. netdev_open_error:
  2046. padapter->bup = _FALSE;
  2047. netif_carrier_off(pnetdev);
  2048. rtw_netif_stop_queue(pnetdev);
  2049. RT_TRACE(_module_os_intfs_c_,_drv_err_,("-871x_drv - dev_open, fail!\n"));
  2050. DBG_871X("-871x_drv - drv_open fail, bup=%d\n", padapter->bup);
  2051. return (-1);
  2052. }
  2053. int netdev_open(struct net_device *pnetdev)
  2054. {
  2055. int ret;
  2056. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  2057. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->hw_init_mutex), NULL);
  2058. ret = _netdev_open(pnetdev);
  2059. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->hw_init_mutex), NULL);
  2060. return ret;
  2061. }
  2062. #ifdef CONFIG_IPS
  2063. int ips_netdrv_open(_adapter *padapter)
  2064. {
  2065. int status = _SUCCESS;
  2066. padapter->net_closed = _FALSE;
  2067. DBG_871X("===> %s.........\n",__FUNCTION__);
  2068. padapter->bDriverStopped = _FALSE;
  2069. padapter->bSurpriseRemoved = _FALSE;
  2070. padapter->bCardDisableWOHSM = _FALSE;
  2071. //padapter->bup = _TRUE;
  2072. status = rtw_hal_init(padapter);
  2073. if (status ==_FAIL)
  2074. {
  2075. RT_TRACE(_module_os_intfs_c_,_drv_err_,("ips_netdrv_open(): Can't init h/w!\n"));
  2076. goto netdev_open_error;
  2077. }
  2078. if(padapter->intf_start)
  2079. {
  2080. padapter->intf_start(padapter);
  2081. }
  2082. rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
  2083. _set_timer(&padapter->mlmepriv.dynamic_chk_timer,5000);
  2084. return _SUCCESS;
  2085. netdev_open_error:
  2086. //padapter->bup = _FALSE;
  2087. DBG_871X("-ips_netdrv_open - drv_open failure, bup=%d\n", padapter->bup);
  2088. return _FAIL;
  2089. }
  2090. int rtw_ips_pwr_up(_adapter *padapter)
  2091. {
  2092. int result;
  2093. u32 start_time = rtw_get_current_time();
  2094. DBG_871X("===> rtw_ips_pwr_up..............\n");
  2095. rtw_reset_drv_sw(padapter);
  2096. result = ips_netdrv_open(padapter);
  2097. rtw_led_control(padapter, LED_CTL_NO_LINK);
  2098. DBG_871X("<=== rtw_ips_pwr_up.............. in %dms\n", rtw_get_passing_time_ms(start_time));
  2099. return result;
  2100. }
  2101. void rtw_ips_pwr_down(_adapter *padapter)
  2102. {
  2103. u32 start_time = rtw_get_current_time();
  2104. DBG_871X("===> rtw_ips_pwr_down...................\n");
  2105. padapter->bCardDisableWOHSM = _TRUE;
  2106. padapter->net_closed = _TRUE;
  2107. rtw_ips_dev_unload(padapter);
  2108. padapter->bCardDisableWOHSM = _FALSE;
  2109. DBG_871X("<=== rtw_ips_pwr_down..................... in %dms\n", rtw_get_passing_time_ms(start_time));
  2110. }
  2111. #endif
  2112. void rtw_ips_dev_unload(_adapter *padapter)
  2113. {
  2114. struct net_device *pnetdev= (struct net_device*)padapter->pnetdev;
  2115. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  2116. DBG_871X("====> %s...\n",__FUNCTION__);
  2117. rtw_hal_set_hwreg(padapter, HW_VAR_FIFO_CLEARN_UP, 0);
  2118. if(padapter->intf_stop)
  2119. {
  2120. padapter->intf_stop(padapter);
  2121. }
  2122. //s5.
  2123. if(padapter->bSurpriseRemoved == _FALSE)
  2124. {
  2125. rtw_hal_deinit(padapter);
  2126. }
  2127. }
  2128. int pm_netdev_open(struct net_device *pnetdev,u8 bnormal)
  2129. {
  2130. int status;
  2131. if (_TRUE == bnormal)
  2132. status = netdev_open(pnetdev);
  2133. #ifdef CONFIG_IPS
  2134. else
  2135. status = (_SUCCESS == ips_netdrv_open((_adapter *)rtw_netdev_priv(pnetdev)))?(0):(-1);
  2136. #endif
  2137. return status;
  2138. }
  2139. static int netdev_close(struct net_device *pnetdev)
  2140. {
  2141. _adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
  2142. RT_TRACE(_module_os_intfs_c_,_drv_info_,("+871x_drv - drv_close\n"));
  2143. if(padapter->pwrctrlpriv.bInternalAutoSuspend == _TRUE)
  2144. {
  2145. //rtw_pwr_wakeup(padapter);
  2146. if(padapter->pwrctrlpriv.rf_pwrstate == rf_off)
  2147. padapter->pwrctrlpriv.ps_flag = _TRUE;
  2148. }
  2149. padapter->net_closed = _TRUE;
  2150. /* if(!padapter->hw_init_completed)
  2151. {
  2152. DBG_871X("(1)871x_drv - drv_close, bup=%d, hw_init_completed=%d\n", padapter->bup, padapter->hw_init_completed);
  2153. padapter->bDriverStopped = _TRUE;
  2154. rtw_dev_unload(padapter);
  2155. }
  2156. else*/
  2157. if(padapter->pwrctrlpriv.rf_pwrstate == rf_on){
  2158. DBG_871X("(2)871x_drv - drv_close, bup=%d, hw_init_completed=%d\n", padapter->bup, padapter->hw_init_completed);
  2159. //s1.
  2160. if(pnetdev)
  2161. {
  2162. if (!rtw_netif_queue_stopped(pnetdev))
  2163. rtw_netif_stop_queue(pnetdev);
  2164. }
  2165. #ifndef CONFIG_ANDROID
  2166. //s2.
  2167. LeaveAllPowerSaveMode(padapter);
  2168. rtw_disassoc_cmd(padapter, 500, _FALSE);
  2169. //s2-2. indicate disconnect to os
  2170. rtw_indicate_disconnect(padapter);
  2171. //s2-3.
  2172. rtw_free_assoc_resources(padapter, 1);
  2173. //s2-4.
  2174. rtw_free_network_queue(padapter,_TRUE);
  2175. #endif
  2176. // Close LED
  2177. rtw_led_control(padapter, LED_CTL_POWER_OFF);
  2178. }
  2179. #ifdef CONFIG_BR_EXT
  2180. //if (OPMODE & (WIFI_STATION_STATE | WIFI_ADHOC_STATE))
  2181. {
  2182. //void nat25_db_cleanup(_adapter *priv);
  2183. nat25_db_cleanup(padapter);
  2184. }
  2185. #endif // CONFIG_BR_EXT
  2186. #ifdef CONFIG_P2P
  2187. #ifdef CONFIG_IOCTL_CFG80211
  2188. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  2189. {
  2190. if(wdev_to_priv(padapter->rtw_wdev)->p2p_enabled == _TRUE)
  2191. wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = _FALSE;
  2192. }
  2193. #endif //CONFIG_IOCTL_CFG80211
  2194. rtw_p2p_enable(padapter, P2P_ROLE_DISABLE);
  2195. #endif //CONFIG_P2P
  2196. #ifdef CONFIG_IOCTL_CFG80211
  2197. rtw_scan_abort(padapter);
  2198. wdev_to_priv(padapter->rtw_wdev)->bandroid_scan = _FALSE;
  2199. padapter->rtw_wdev->iftype = NL80211_IFTYPE_MONITOR; //set this at the end
  2200. #endif //CONFIG_IOCTL_CFG80211
  2201. #ifdef CONFIG_WAPI_SUPPORT
  2202. rtw_wapi_disable_tx(padapter);
  2203. #endif
  2204. RT_TRACE(_module_os_intfs_c_,_drv_info_,("-871x_drv - drv_close\n"));
  2205. DBG_871X("-871x_drv - drv_close, bup=%d\n", padapter->bup);
  2206. return 0;
  2207. }
  2208. void rtw_ndev_destructor(struct net_device *ndev)
  2209. {
  2210. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2211. #ifdef CONFIG_IOCTL_CFG80211
  2212. if (ndev->ieee80211_ptr)
  2213. rtw_mfree((u8 *)ndev->ieee80211_ptr, sizeof(struct wireless_dev));
  2214. #endif
  2215. free_netdev(ndev);
  2216. }