wlandrv.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. /****************************************************************************
  2. * This file is part of the WLAN-Ethernut device driver.
  3. *
  4. * Copyright (c) 2004 by Michael Fischer. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the author nor the names of its contributors may
  16. * be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  23. * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. ****************************************************************************
  33. * Portions Copyright:
  34. *
  35. * Copyright (c) 2002
  36. * M Warner Losh <imp@freebsd.org>. All rights reserved.
  37. * Copyright (c) 1997, 1998, 1999
  38. * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. * 1. Redistributions of source code must retain the above copyright
  44. * notice, this list of conditions and the following disclaimer.
  45. * 2. Redistributions in binary form must reproduce the above copyright
  46. * notice, this list of conditions and the following disclaimer in the
  47. * documentation and/or other materials provided with the distribution.
  48. * 3. Neither the name of the author nor the names of any co-contributors
  49. * may be used to endorse or promote products derived from this software
  50. * without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
  53. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55. * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
  56. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  57. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  58. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  59. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  60. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  61. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  62. * THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. ****************************************************************************
  65. * History:
  66. *
  67. * 28.02.04 mifi First Version
  68. * If you like to see the original source. Take a look
  69. * in if_wi.c from FreeBSD.
  70. * 01.03.04 mifi Now we use a timeout in our Thread, and check if we lost
  71. * the card. In this case we try to Init it again.
  72. * 02.03.04 mifi Remove QuickHack for Networkname and WEP.
  73. * 03.03.04 mifi Use struct to config WLAN (WLAN_IOCTL_SET_CONFIG)
  74. * 04.03.04 mifi Add function to get WLAN_STATUS (WLAN_IOCTL_GET_STATUS)
  75. * 06.03.04 mifi Remove all @@MF later for monitor mode.
  76. * It does not work with my card, and I think we need a
  77. * special firmware for it.
  78. ****************************************************************************/
  79. #define __WLANDRV_C__
  80. #include <compiler.h>
  81. #include <stdio.h>
  82. #include <stddef.h>
  83. #include <string.h>
  84. #include <sys/timer.h>
  85. #include <sys/thread.h>
  86. #include <sys/event.h>
  87. #include <errno.h>
  88. #include <netinet/if_ether.h>
  89. #include <net/ether.h>
  90. #include <net/if_var.h>
  91. #include <dev/irqreg.h>
  92. #include <dev/wlantypes.h>
  93. #include <dev/pcmcia.h>
  94. #include <dev/wlancfg.h>
  95. #include <dev/wlan.h>
  96. #include <dev/wlandrv.h>
  97. /*==========================================================*/
  98. /* DEFINE: All Structures and Common Constants */
  99. /*==========================================================*/
  100. #if (_DEBUG >= 1)
  101. #define Debug(_x) if (bDebugState ) printf _x
  102. #define Debug2(_x) if (bDebugState > 1) printf _x
  103. #define panic printf
  104. #else
  105. #define Debug(_x)
  106. #define Debug2(_x)
  107. #define panic
  108. #endif
  109. #define WI_LOCK(sc) NutEventWait(&hDeviceSemaphore,0)
  110. #define WI_UNLOCK(sc) NutEventPost(&hDeviceSemaphore)
  111. #define ieee80211_new_state(_a,_b,_c) _a->ic_state=_b
  112. #define isset(_a,_b) (*_a & (1<<_b))
  113. #define CSR_WRITE_2(_a,_b,_c) pcmcia_WriteReg(_b,_c)
  114. #define CSR_READ_2(_a,_b) pcmcia_ReadReg(_b)
  115. /*
  116. * Length information
  117. */
  118. #define WLAN_MIN_ETHERNET_FRAME_LEN 60
  119. #define WLAN_MAX_ETHERNET_FRAME_LEN 1514
  120. #define WLAN_ETHERNET_HEADER_LEN 14
  121. /*
  122. * Interrupt define
  123. */
  124. #define WI_INTRS (WI_EV_RX | WI_EV_ALLOC | WI_EV_INFO)
  125. struct wi_card_ident {
  126. u_int16_t card_id;
  127. char *card_name;
  128. u_int8_t firm_type;
  129. };
  130. struct ieee80211_frame_addr4 {
  131. u_int8_t i_fc[2];
  132. u_int8_t i_dur[2];
  133. u_int8_t i_addr1[IEEE80211_ADDR_LEN];
  134. u_int8_t i_addr2[IEEE80211_ADDR_LEN];
  135. u_int8_t i_addr3[IEEE80211_ADDR_LEN];
  136. u_int8_t i_seq[2];
  137. u_int8_t i_addr4[IEEE80211_ADDR_LEN];
  138. };
  139. /*
  140. * transmit/receive frame structure
  141. */
  142. struct wi_frame {
  143. u_int16_t wi_status; /* 0x00 */
  144. u_int16_t wi_rx_tstamp1; /* 0x02 */
  145. u_int16_t wi_rx_tstamp0; /* 0x04 */
  146. u_int8_t wi_rx_silence; /* 0x06 */
  147. u_int8_t wi_rx_signal; /* 0x07 */
  148. u_int8_t wi_rx_rate; /* 0x08 */
  149. u_int8_t wi_rx_flow; /* 0x09 */
  150. u_int8_t wi_tx_rtry; /* 0x0a *//* Prism2 AP Only */
  151. u_int8_t wi_tx_rate; /* 0x0b *//* Prism2 AP Only */
  152. u_int16_t wi_tx_ctl; /* 0x0c */
  153. struct ieee80211_frame_addr4 wi_whdr; /* 0x0e */
  154. u_int16_t wi_dat_len; /* 0x2c */
  155. struct ether_header wi_ehdr; /* 0x2e */
  156. };
  157. /*
  158. * Station set identification (SSID). (0xFC02, 0xFC04)
  159. */
  160. struct wi_ssid {
  161. u_int16_t wi_len;
  162. u_int8_t wi_ssid[32];
  163. };
  164. /*
  165. * Ethernet LLCS + SNAP header
  166. */
  167. typedef struct {
  168. u_int16_t DSAPSSAP;
  169. u_int16_t Control;
  170. u_int16_t MustZero;
  171. u_int16_t Type;
  172. } LLCS_SNAP_HEADER;
  173. /*==========================================================*/
  174. /* DEFINE: Prototypes */
  175. /*==========================================================*/
  176. /*==========================================================*/
  177. /* DEFINE: Definition of all local Data */
  178. /*==========================================================*/
  179. static HANDLE hDeviceSemaphore;
  180. static BYTE bDebugState = 0;
  181. struct wi_card_ident wi_card_ident[] = {
  182. /*
  183. * CARD_ID CARD_NAME FIRM_TYPE
  184. */
  185. #if (WLAN_SUPPORT_LUCENT >= 1)
  186. {WI_NIC_LUCENT_ID, WI_NIC_LUCENT_STR, WI_LUCENT},
  187. {WI_NIC_SONY_ID, WI_NIC_SONY_STR, WI_LUCENT},
  188. {WI_NIC_LUCENT_EMB_ID, WI_NIC_LUCENT_EMB_STR, WI_LUCENT},
  189. #endif /* (WLAN_SUPPORT_LUCENT >= 1) */
  190. #if (WLAN_SUPPORT_INTERSIL >= 1)
  191. {WI_NIC_EVB2_ID, WI_NIC_EVB2_STR, WI_INTERSIL},
  192. {WI_NIC_HWB3763_ID, WI_NIC_HWB3763_STR, WI_INTERSIL},
  193. {WI_NIC_HWB3163_ID, WI_NIC_HWB3163_STR, WI_INTERSIL},
  194. {WI_NIC_HWB3163B_ID, WI_NIC_HWB3163B_STR, WI_INTERSIL},
  195. {WI_NIC_EVB3_ID, WI_NIC_EVB3_STR, WI_INTERSIL},
  196. {WI_NIC_HWB1153_ID, WI_NIC_HWB1153_STR, WI_INTERSIL},
  197. {WI_NIC_P2_SST_ID, WI_NIC_P2_SST_STR, WI_INTERSIL},
  198. {WI_NIC_EVB2_SST_ID, WI_NIC_EVB2_SST_STR, WI_INTERSIL},
  199. {WI_NIC_3842_EVA_ID, WI_NIC_3842_EVA_STR, WI_INTERSIL},
  200. {WI_NIC_3842_PCMCIA_AMD_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL},
  201. {WI_NIC_3842_PCMCIA_SST_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL},
  202. {WI_NIC_3842_PCMCIA_ATL_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL},
  203. {WI_NIC_3842_PCMCIA_ATS_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL},
  204. {WI_NIC_3842_MINI_AMD_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL},
  205. {WI_NIC_3842_MINI_SST_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL},
  206. {WI_NIC_3842_MINI_ATL_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL},
  207. {WI_NIC_3842_MINI_ATS_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL},
  208. {WI_NIC_3842_PCI_AMD_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL},
  209. {WI_NIC_3842_PCI_SST_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL},
  210. {WI_NIC_3842_PCI_ATS_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL},
  211. {WI_NIC_3842_PCI_ATL_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL},
  212. {WI_NIC_P3_PCMCIA_AMD_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL},
  213. {WI_NIC_P3_PCMCIA_SST_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL},
  214. {WI_NIC_P3_PCMCIA_ATL_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL},
  215. {WI_NIC_P3_PCMCIA_ATS_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL},
  216. {WI_NIC_P3_MINI_AMD_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL},
  217. {WI_NIC_P3_MINI_SST_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL},
  218. {WI_NIC_P3_MINI_ATL_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL},
  219. {WI_NIC_P3_MINI_ATS_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL},
  220. #endif /* (WLAN_SUPPORT_INTERSIL >= 1) */
  221. {0, NULL, 0},
  222. };
  223. /*==========================================================*/
  224. /* DEFINE: Definition of all local Procedures */
  225. /*==========================================================*/
  226. /************************************************************/
  227. /* DELAY */
  228. /* */
  229. /* Delay in us. */
  230. /************************************************************/
  231. static void DELAY(u_int32_t delay_us)
  232. {
  233. delay_us = delay_us / 1000;
  234. delay_us++;
  235. NutSleep(delay_us);
  236. }
  237. /************************************************************/
  238. /* DumpData */
  239. /* */
  240. /* Dump the Buffer to the Terminal */
  241. /************************************************************/
  242. /* Harald: Not always used, but not sure how. Changed
  243. fron static to global and changed name to avoid conflicts */
  244. void DumpWlanData(BYTE * pBuffer, WORD wBufferSize)
  245. {
  246. u_int16_t x, MaxX = 16;
  247. u_int16_t y, MaxY;
  248. u_int16_t Size;
  249. if (bDebugState != 0) {
  250. Size = 0;
  251. MaxY = (wBufferSize / 16) + 1;
  252. for (y = 0; y < MaxY; y++) {
  253. Debug(("%04X: ", (y * 16)));
  254. for (x = 0; x < MaxX; x++) {
  255. Debug(("%02X ", pBuffer[Size]));
  256. Size++;
  257. if (Size >= wBufferSize) {
  258. Debug(("\r\n"));
  259. return;
  260. }
  261. }
  262. Debug(("\r\n"));
  263. }
  264. }
  265. }
  266. /************************************************************/
  267. /* wi_cmd */
  268. /************************************************************/
  269. static int wi_cmd(struct wi_softc *sc, int cmd, int val0, int val1, int val2)
  270. {
  271. unsigned long i; /* Harald: Changed from int to long. */
  272. unsigned int s = 0; /* Oliver: Changed from signed to unsigned. */
  273. static volatile int count = 0;
  274. if (sc->wi_gone) {
  275. return (ENODEV);
  276. }
  277. /* Harald: Removed this, it makes no sense */
  278. //if (count > 0) {
  279. // panic("Hey partner, hold on there!");
  280. //}
  281. count++;
  282. /*
  283. * wait for the busy bit to clear
  284. */
  285. for (i = sc->wi_cmd_count; i > 0; i--) { /* 500ms */
  286. if (!(CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY)) {
  287. break;
  288. }
  289. DELAY(1 * 1000); /* 1ms */
  290. }
  291. if (i == 0) {
  292. Debug(("wi_cmd: busy bit won't clear.\n"));
  293. sc->wi_gone = 1;
  294. count--;
  295. return (ETIMEDOUT);
  296. }
  297. CSR_WRITE_2(sc, WI_PARAM0, val0);
  298. CSR_WRITE_2(sc, WI_PARAM1, val1);
  299. CSR_WRITE_2(sc, WI_PARAM2, val2);
  300. CSR_WRITE_2(sc, WI_COMMAND, cmd);
  301. if (cmd == WI_CMD_INI) {
  302. /*
  303. * XXX: should sleep here.
  304. */
  305. /* Harald: Added UL specifiers, no idea how Michael's ICC accepted this */
  306. DELAY(250UL * 1000UL); /* 250ms delay for init */
  307. }
  308. for (i = 0; i < WI_TIMEOUT; i++) {
  309. /*
  310. * Wait for 'command complete' bit to be
  311. * set in the event status register.
  312. */
  313. s = CSR_READ_2(sc, WI_EVENT_STAT);
  314. if (s & WI_EV_CMD) {
  315. /*
  316. * Ack the event and read result code.
  317. */
  318. s = CSR_READ_2(sc, WI_STATUS);
  319. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD);
  320. if (s & WI_STAT_CMD_RESULT) {
  321. count--;
  322. return (EIO);
  323. }
  324. break;
  325. }
  326. DELAY(WI_DELAY);
  327. }
  328. count--;
  329. if (i == WI_TIMEOUT) {
  330. Debug(("timeout in wi_cmd 0x%04x; event status 0x%04x\n", cmd, s));
  331. if (s == 0xffff) {
  332. sc->wi_gone = 1;
  333. }
  334. return (ETIMEDOUT);
  335. }
  336. return (0);
  337. }
  338. /************************************************************/
  339. /* wi_stop */
  340. /************************************************************/
  341. void wi_stop(struct wi_softc *sc, int disable)
  342. {
  343. struct ieee80211com *ic = &sc->sc_ic;
  344. DELAY(100000);
  345. ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
  346. if (sc->sc_enabled && !sc->wi_gone) {
  347. CSR_WRITE_2(sc, WI_INT_EN, 0);
  348. wi_cmd(sc, WI_CMD_DISABLE | sc->sc_portnum, 0, 0, 0);
  349. if (disable) {
  350. sc->sc_enabled = 0;
  351. }
  352. } else {
  353. if (sc->wi_gone && disable) { /* gone --> not enabled */
  354. sc->sc_enabled = 0;
  355. }
  356. }
  357. sc->sc_tx_timer = 0;
  358. sc->sc_scan_timer = 0;
  359. }
  360. /************************************************************/
  361. /* wi_seek_bap */
  362. /************************************************************/
  363. static int wi_seek_bap(struct wi_softc *sc, int id, int off)
  364. {
  365. long i; /* Harald: from int to long */
  366. unsigned int status; /* Oliver: from signed to unsigned */
  367. CSR_WRITE_2(sc, WI_SEL0, id);
  368. CSR_WRITE_2(sc, WI_OFF0, off);
  369. for (i = 0;; i++) {
  370. status = CSR_READ_2(sc, WI_OFF0);
  371. if ((status & WI_OFF_BUSY) == 0) {
  372. break;
  373. }
  374. if (i == WI_TIMEOUT) {
  375. Debug(("timeout in wi_seek to %x/%x\n", id, off));
  376. sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
  377. if (status == 0xffff) {
  378. sc->wi_gone = 1;
  379. }
  380. return ETIMEDOUT;
  381. }
  382. DELAY(1);
  383. }
  384. if (status & WI_OFF_ERR) {
  385. Debug(("failed in wi_seek to %x/%x\n", id, off));
  386. sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
  387. return EIO;
  388. }
  389. sc->sc_bap_id = id;
  390. sc->sc_bap_off = off;
  391. return 0;
  392. }
  393. /************************************************************/
  394. /* wi_read_bap */
  395. /************************************************************/
  396. static int wi_read_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
  397. {
  398. u_int16_t *ptr;
  399. int i, error, cnt;
  400. if (buflen == 0) {
  401. return 0;
  402. }
  403. if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
  404. if ((error = wi_seek_bap(sc, id, off)) != 0) {
  405. return error;
  406. }
  407. }
  408. cnt = (buflen + 1) / 2;
  409. ptr = (u_int16_t *) buf;
  410. for (i = 0; i < cnt; i++) {
  411. *ptr++ = CSR_READ_2(sc, WI_DATA0);
  412. }
  413. sc->sc_bap_off += cnt * 2;
  414. return 0;
  415. }
  416. /************************************************************/
  417. /* wi_write_bap */
  418. /************************************************************/
  419. static int wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
  420. {
  421. u_int16_t *ptr;
  422. int i, error, cnt;
  423. if (buflen == 0) {
  424. return 0;
  425. }
  426. #ifdef WI_HERMES_AUTOINC_WAR
  427. again:
  428. #endif
  429. if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
  430. if ((error = wi_seek_bap(sc, id, off)) != 0) {
  431. return error;
  432. }
  433. }
  434. cnt = (buflen + 1) / 2;
  435. ptr = (u_int16_t *) buf;
  436. for (i = 0; i < cnt; i++) {
  437. CSR_WRITE_2(sc, WI_DATA0, ptr[i]);
  438. }
  439. sc->sc_bap_off += cnt * 2;
  440. #ifdef WI_HERMES_AUTOINC_WAR
  441. /*
  442. * According to the comments in the HCF Light code, there is a bug
  443. * in the Hermes (or possibly in certain Hermes firmware revisions)
  444. * where the chip's internal autoincrement counter gets thrown off
  445. * during data writes: the autoincrement is missed, causing one
  446. * data word to be overwritten and subsequent words to be written to
  447. * the wrong memory locations. The end result is that we could end
  448. * up transmitting bogus frames without realizing it. The workaround
  449. * for this is to write a couple of extra guard words after the end
  450. * of the transfer, then attempt to read then back. If we fail to
  451. * locate the guard words where we expect them, we preform the
  452. * transfer over again.
  453. */
  454. if ((sc->sc_flags & WI_FLAGS_BUG_AUTOINC) && (id & 0xf000) == 0) {
  455. CSR_WRITE_2(sc, WI_DATA0, 0x1234);
  456. CSR_WRITE_2(sc, WI_DATA0, 0x5678);
  457. wi_seek_bap(sc, id, sc->sc_bap_off);
  458. sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
  459. if (CSR_READ_2(sc, WI_DATA0) != 0x1234 || CSR_READ_2(sc, WI_DATA0) != 0x5678) {
  460. Debug(("detect auto increment bug, try again\n"));
  461. goto again;
  462. }
  463. }
  464. #endif
  465. return 0;
  466. }
  467. /************************************************************/
  468. /* wi_read_rid */
  469. /************************************************************/
  470. static int wi_read_rid(struct wi_softc *sc, int rid, void *buf, int *buflenp)
  471. {
  472. int error, len;
  473. u_int16_t ltbuf[2];
  474. /*
  475. * Tell the NIC to enter record read mode.
  476. */
  477. error = wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_READ, rid, 0, 0);
  478. if (error) {
  479. return error;
  480. }
  481. error = wi_read_bap(sc, rid, 0, ltbuf, sizeof(ltbuf));
  482. if (error) {
  483. return error;
  484. }
  485. if (le16toh(ltbuf[1]) != (u_int16_t) rid) {
  486. Debug(("record read mismatch, rid=%x, got=%x\n", rid, le16toh(ltbuf[1])));
  487. return EIO;
  488. }
  489. len = (le16toh(ltbuf[0]) - 1) * 2; /* already got rid */
  490. if (*buflenp < len) {
  491. Debug(("record buffer is too small, rid=%x, size=%d, len=%d\n", rid, *buflenp, len));
  492. return ENOSPC;
  493. }
  494. *buflenp = len;
  495. return wi_read_bap(sc, rid, sizeof(ltbuf), buf, len);
  496. }
  497. /************************************************************/
  498. /* wi_write_rid */
  499. /* */
  500. /* Write a block of data to the Resource Identifier. */
  501. /* */
  502. /* Return: OK or Error cause. */
  503. /************************************************************/
  504. static int wi_write_rid(struct wi_softc *sc, int rid, void *buf, int buflen)
  505. {
  506. int error;
  507. u_int16_t ltbuf[2];
  508. ltbuf[0] = htole16((buflen + 1) / 2 + 1); /* includes rid */
  509. ltbuf[1] = htole16(rid);
  510. error = wi_write_bap(sc, rid, 0, ltbuf, sizeof(ltbuf));
  511. if (error) {
  512. return error;
  513. }
  514. error = wi_write_bap(sc, rid, sizeof(ltbuf), buf, buflen);
  515. if (error) {
  516. return error;
  517. }
  518. return wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_WRITE, rid, 0, 0);
  519. }
  520. /************************************************************/
  521. /* wi_write_val */
  522. /* */
  523. /* Write the value to the Resource Identifier. */
  524. /* The function will write only a WORD */
  525. /* */
  526. /* Return: OK or Error cause. */
  527. /************************************************************/
  528. static int wi_write_val(struct wi_softc *sc, int rid, u_int16_t val)
  529. {
  530. val = htole16(val);
  531. return wi_write_rid(sc, rid, &val, sizeof(val));
  532. }
  533. /************************************************************/
  534. /* wi_write_txrate */
  535. /************************************************************/
  536. static int wi_write_txrate(struct wi_softc *sc)
  537. {
  538. struct ieee80211com *ic = &sc->sc_ic;
  539. int i;
  540. u_int16_t rate;
  541. if (ic->ic_fixed_rate < 0) {
  542. rate = 0; /* auto */
  543. } else {
  544. rate = (ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[ic->ic_fixed_rate] & IEEE80211_RATE_VAL) / 2;
  545. }
  546. /*
  547. * rate: 0, 1, 2, 5, 11
  548. */
  549. switch (sc->sc_firmware_type) {
  550. case WI_LUCENT:
  551. switch (rate) {
  552. case 0: /* auto == 11mbps auto */
  553. rate = 3;
  554. break;
  555. /*
  556. * case 1, 2 map to 1, 2
  557. */
  558. case 5: /* 5.5Mbps -> 4 */
  559. rate = 4;
  560. break;
  561. case 11: /* 11mbps -> 5 */
  562. rate = 5;
  563. break;
  564. default:
  565. break;
  566. }
  567. break;
  568. default:
  569. /*
  570. * Choose a bit according to this table.
  571. * *
  572. * * bit | data rate
  573. * * ----+-------------------
  574. * * 0 | 1Mbps
  575. * * 1 | 2Mbps
  576. * * 2 | 5.5Mbps
  577. * * 3 | 11Mbps
  578. */
  579. for (i = 8; i > 0; i >>= 1) {
  580. if ((int) rate >= i) {
  581. break;
  582. }
  583. }
  584. if (i == 0) {
  585. rate = 0xf; /* auto */
  586. } else {
  587. rate = i;
  588. }
  589. break;
  590. }
  591. return wi_write_val(sc, WI_RID_TX_RATE, rate);
  592. }
  593. /************************************************************/
  594. /* wi_reset */
  595. /************************************************************/
  596. static int wi_reset(struct wi_softc *sc)
  597. {
  598. //struct ieee80211com *ic = &sc->sc_ic; /* Harald: Not used */
  599. int i;
  600. int error = 0;
  601. int tries;
  602. /*
  603. * Symbol firmware cannot be initialized more than once
  604. */
  605. if (sc->sc_firmware_type == WI_SYMBOL && sc->sc_reset) {
  606. return (0);
  607. }
  608. if (sc->sc_firmware_type == WI_SYMBOL) {
  609. tries = 1;
  610. } else {
  611. tries = 3;
  612. }
  613. for (i = 0; i < tries; i++) {
  614. if ((error = wi_cmd(sc, WI_CMD_INI, 0, 0, 0)) == 0) {
  615. break;
  616. }
  617. DELAY(WI_DELAY * 1000);
  618. }
  619. sc->sc_reset = 1;
  620. if (i == tries) {
  621. Debug(("init failed\n"));
  622. return (error);
  623. }
  624. CSR_WRITE_2(sc, WI_INT_EN, 0);
  625. CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
  626. /*
  627. * Calibrate timer
  628. */
  629. wi_write_val(sc, WI_RID_TICK_TIME, 8);
  630. return (0);
  631. }
  632. /************************************************************/
  633. /* WLANInterrupt */
  634. /************************************************************/
  635. static void WLANInterrupt(void *p)
  636. {
  637. NUTDEVICE *dev = (NUTDEVICE *) p;
  638. struct wi_softc *sc = (struct wi_softc *) dev->dev_dcb;
  639. if ((sc->wi_gone == 1) || (sc->sc_enabled == 0)) {
  640. CSR_WRITE_2(sc, WI_INT_EN, 0);
  641. CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
  642. return;
  643. }
  644. /*
  645. * Disable interrupts. We will enable the interrupt
  646. * later in the RxThread.
  647. */
  648. CSR_WRITE_2(sc, WI_INT_EN, 0);
  649. sc->EventStatus = CSR_READ_2(sc, WI_EVENT_STAT);
  650. NutEventPostFromIrq(&sc->InterruptEvent);
  651. }
  652. /************************************************************/
  653. /* wi_tx_intr */
  654. /************************************************************/
  655. static void wi_tx_intr(struct wi_softc *sc)
  656. {
  657. // struct ieee80211com *ic = &sc->sc_ic; /* Harald: Not used. */
  658. int fid, cur;
  659. if (sc->wi_gone) {
  660. return;
  661. }
  662. fid = CSR_READ_2(sc, WI_ALLOC_FID);
  663. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC);
  664. cur = sc->sc_txcur;
  665. if (sc->sc_txd[cur].d_fid != fid) {
  666. #if (WLAN_ENABLE_TX_FRAME_DUMP >= 1)
  667. Debug(("bad alloc %x != %x, cur %d nxt %d\n", fid, sc->sc_txd[cur].d_fid, cur, sc->sc_txnext));
  668. #endif
  669. return;
  670. }
  671. sc->sc_tx_timer = 0;
  672. sc->sc_txd[cur].d_len = 0;
  673. sc->sc_txcur = cur = (cur + 1) % sc->sc_ntxbuf;
  674. if (sc->sc_txd[cur].d_len == 0) {
  675. //ifp->if_flags &= ~IFF_OACTIVE;
  676. } else {
  677. if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, sc->sc_txd[cur].d_fid, 0, 0)) {
  678. Debug(("xmit failed\n"));
  679. sc->sc_txd[cur].d_len = 0;
  680. } else {
  681. sc->sc_tx_timer = 5;
  682. //ifp->if_timer = 1;
  683. }
  684. }
  685. }
  686. /************************************************************/
  687. /* wi_info_intr */
  688. /************************************************************/
  689. static void wi_info_intr(struct wi_softc *sc)
  690. {
  691. struct ieee80211com *ic = &sc->sc_ic;
  692. //struct ifnet *ifp = &ic->ic_if;
  693. //int i, len, off; /* Harald: Not used */
  694. int fid;
  695. u_int16_t ltbuf[2];
  696. u_int16_t stat;
  697. //u_int32_t *ptr; /* Harald: Not used. */
  698. fid = CSR_READ_2(sc, WI_INFO_FID);
  699. wi_read_bap(sc, fid, 0, ltbuf, sizeof(ltbuf));
  700. switch (le16toh(ltbuf[1])) {
  701. case WI_INFO_LINK_STAT:
  702. wi_read_bap(sc, fid, sizeof(ltbuf), &stat, sizeof(stat));
  703. #if (WLAN_ENABLE_LINK_STATUS >= 1)
  704. Debug(("wi_info_intr: LINK_STAT 0x%x\n", le16toh(stat)));
  705. #endif /* (WLAN_ENABLE_LINK_STATUS >= 1) */
  706. switch (le16toh(stat)) {
  707. case WI_INFO_LINK_STAT_CONNECTED:
  708. sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
  709. if (ic->ic_state == IEEE80211_S_RUN && ic->ic_opmode != IEEE80211_M_IBSS) {
  710. break;
  711. }
  712. /*
  713. * FALLTHROUGH
  714. */
  715. case WI_INFO_LINK_STAT_AP_CHG:
  716. ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
  717. break;
  718. case WI_INFO_LINK_STAT_AP_INR:
  719. sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
  720. break;
  721. case WI_INFO_LINK_STAT_AP_OOR:
  722. if (sc->sc_firmware_type == WI_SYMBOL && sc->sc_scan_timer > 0) {
  723. if (wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_HOST_SCAN_RESULTS, 0, 0)
  724. != 0) {
  725. sc->sc_scan_timer = 0;
  726. }
  727. break;
  728. }
  729. if (ic->ic_opmode == IEEE80211_M_STA) {
  730. sc->sc_flags |= WI_FLAGS_OUTRANGE;
  731. }
  732. break;
  733. case WI_INFO_LINK_STAT_DISCONNECTED:
  734. case WI_INFO_LINK_STAT_ASSOC_FAILED:
  735. if (ic->ic_opmode == IEEE80211_M_STA) {
  736. ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
  737. }
  738. break;
  739. }
  740. break;
  741. case WI_INFO_COUNTERS:
  742. #if 0 //@@MF later
  743. /*
  744. * I think we does not need the counter,
  745. * therefore it can be take longer to implement it.
  746. */
  747. /*
  748. * some card versions have a larger stats structure
  749. */
  750. len = min(le16toh(ltbuf[0]) - 1, sizeof(sc->sc_stats) / 4);
  751. ptr = (u_int32_t *) & sc->sc_stats;
  752. off = sizeof(ltbuf);
  753. for (i = 0; i < len; i++, off += 2, ptr++) {
  754. wi_read_bap(sc, fid, off, &stat, sizeof(stat));
  755. #ifdef WI_HERMES_STATS_WAR
  756. if (stat & 0xf000) {
  757. stat = ~stat;
  758. }
  759. #endif
  760. *ptr += stat;
  761. }
  762. ifp->if_collisions = sc->sc_stats.wi_tx_single_retries + sc->sc_stats.wi_tx_multi_retries + sc->sc_stats.wi_tx_retry_limit;
  763. #endif /* later */
  764. break;
  765. #if 0 //@@MF later
  766. case WI_INFO_SCAN_RESULTS:
  767. case WI_INFO_HOST_SCAN_RESULTS:
  768. wi_scan_result(sc, fid, le16toh(ltbuf[0]));
  769. break;
  770. #endif /* later */
  771. default:
  772. Debug(("wi_info_intr: got fid %x type %x len %d\n", fid, le16toh(ltbuf[1]), le16toh(ltbuf[0])));
  773. break;
  774. }
  775. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_INFO);
  776. }
  777. /************************************************************/
  778. /* wi_rx_intr */
  779. /************************************************************/
  780. static NETBUF *wi_rx_intr(struct wi_softc *sc)
  781. {
  782. // struct ieee80211com *ic = &sc->sc_ic; /* Harald: Not used */
  783. struct wi_frame frmhdr;
  784. int fid, len, off;
  785. u_int16_t status;
  786. int error;
  787. NETBUF *nb = 0;
  788. LLCS_SNAP_HEADER *pLLCSSNAPHeader;
  789. ETHERHDR LABBuffer;
  790. ETHERHDR MAC802_3;
  791. u_int8_t *pFrameBuffer = 0; /* Harald: Missing init */
  792. u_int8_t *pBytePointer;
  793. int copy_size = 0; /* Harald: Missing init */
  794. int size;
  795. int IPFrame = 0;
  796. if (sc->wi_gone) {
  797. Debug(("wi_rx_intr gone\r\n"));
  798. return (0);
  799. }
  800. fid = CSR_READ_2(sc, WI_RX_FID);
  801. /*
  802. * First read in the frame header
  803. */
  804. if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr))) {
  805. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
  806. Debug(("wi_rx_intr: read fid %x failed\n", fid));
  807. return 0;
  808. }
  809. /*
  810. * Drop undecryptable or packets with receive errors here
  811. */
  812. status = le16toh(frmhdr.wi_status);
  813. if (status & WI_STAT_ERRSTAT) {
  814. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
  815. Debug(("wi_rx_intr: fid %x error status %x\n", fid, status));
  816. return 0;
  817. }
  818. /*
  819. * Catch the MAC 802.3 header
  820. */
  821. memcpy(MAC802_3.ether_dhost, frmhdr.wi_ehdr.ether_dhost, IEEE80211_ADDR_LEN);
  822. memcpy(MAC802_3.ether_shost, frmhdr.wi_ehdr.ether_shost, IEEE80211_ADDR_LEN);
  823. /*
  824. * The ether_type comes later
  825. */
  826. /*
  827. * Get the frame length, at this point I don't know
  828. * if it is a RFC1024 or RFC894 frame. But Ethernut need
  829. * an RFC894 frame! So we will alloc the NetBuffer later.
  830. */
  831. len = le16toh(frmhdr.wi_dat_len);
  832. off = sizeof(frmhdr);
  833. /*
  834. * Sometimes the PRISM2.x returns bogusly large frames. Except
  835. * in monitor mode, just throw them away.
  836. */
  837. if (len > WLAN_MAX_ETHERNET_FRAME_LEN) {
  838. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
  839. Debug(("wi_rx_intr: oversized packet\n"));
  840. return (0);
  841. }
  842. /*
  843. * First read the LookAheadBuffer
  844. */
  845. error = wi_read_bap(sc, fid, off, &LABBuffer, sizeof(LABBuffer));
  846. off += sizeof(LABBuffer);
  847. if (error == 0) {
  848. /*
  849. * Check if this is a 802.2 LLC 802.2 SNAP IP-Header RFC1024
  850. */
  851. pLLCSSNAPHeader = (LLCS_SNAP_HEADER *) & LABBuffer;
  852. if ((pLLCSSNAPHeader->DSAPSSAP == 0xAAAA) && (pLLCSSNAPHeader->Control == 0x0003) && (pLLCSSNAPHeader->MustZero == 0x0000)) {
  853. if ((pLLCSSNAPHeader->Type == 0x0608) || (pLLCSSNAPHeader->Type == 0x0008)) {
  854. #if (WLAN_ENABLE_RX_FRAME_DUMP >= 1)
  855. Debug(("RFC1024 IP-Frame\n"));
  856. #endif
  857. IPFrame = 1;
  858. MAC802_3.ether_type = pLLCSSNAPHeader->Type;
  859. /*
  860. * Now we can calculate the wFrameLength.
  861. * It is a RFC1042 Frame, and we must discard the:
  862. * DSAP, SSAP, cntl, and the org. code
  863. * 1 + 1 + 1 + 3 = 6
  864. */
  865. len -= 6;
  866. /*
  867. * The Ethernut need the dest and source address,
  868. * therefore add 12 again.
  869. */
  870. len += 12;
  871. /*
  872. * The MAC can not handle odd counts, test it.
  873. *
  874. */
  875. len += 1;
  876. len &= ~1;
  877. /*
  878. * Now alloc the NetBuffer for Ethernut.
  879. */
  880. nb = NutNetBufAlloc(0, NBAF_DATALINK, len);
  881. if (nb != 0) {
  882. pFrameBuffer = nb->nb_dl.vp;
  883. /*
  884. * We must copy wFrameLength out of the MAC
  885. */
  886. copy_size = len;
  887. /*
  888. * Copy the MAC 802.3 Header
  889. */
  890. memcpy(pFrameBuffer, &MAC802_3, sizeof(MAC802_3));
  891. pFrameBuffer += sizeof(MAC802_3);
  892. copy_size -= sizeof(MAC802_3); /* This was already in the WLANHeader */
  893. /*
  894. * Now we have some data in our LABBuffer which we need
  895. */
  896. pBytePointer = (BYTE *) & LABBuffer;
  897. /*
  898. * jump over the header
  899. */
  900. pBytePointer += sizeof(LLCS_SNAP_HEADER);
  901. /*
  902. * and copy the rest
  903. */
  904. size = sizeof(LABBuffer) - sizeof(LLCS_SNAP_HEADER);
  905. memcpy(pFrameBuffer, pBytePointer, size);
  906. /*
  907. * Change the pointer for the "global copy"
  908. */
  909. pFrameBuffer += size;
  910. copy_size -= size; /* This was already in the LookAheadBuffer */
  911. } else {
  912. IPFrame = 0;
  913. }
  914. } /* only ARP and IP */
  915. } else {
  916. /*
  917. * Check if this is a RFX894 Frame
  918. */
  919. if ((LABBuffer.ether_type == 0x0608) || (LABBuffer.ether_type == 0x0008)) {
  920. #if (WLAN_ENABLE_RX_FRAME_DUMP >= 1)
  921. Debug(("RFC894 IP-Frame\n"));
  922. #endif
  923. IPFrame = 1;
  924. /*
  925. * The MAC can not handle odd counts, test it.
  926. *
  927. */
  928. len += 1;
  929. len &= ~1;
  930. /*
  931. * The FrameLength is now the correct length for an RFC894 Frame,
  932. * Now alloc the NetBuffer for Ethernut.
  933. */
  934. nb = NutNetBufAlloc(0, NBAF_DATALINK, len);
  935. if (nb != 0) {
  936. pFrameBuffer = nb->nb_dl.vp;
  937. /*
  938. * We must copy wFrameLength out of the MAC
  939. */
  940. copy_size = len;
  941. /*
  942. * The LookAheadBuffer is the MAC-Header
  943. */
  944. memcpy(pFrameBuffer, &LABBuffer, sizeof(LABBuffer));
  945. pFrameBuffer += sizeof(LABBuffer);
  946. copy_size -= sizeof(LABBuffer); /* This was our LookAheadBuffer */
  947. } else {
  948. IPFrame = 0;
  949. } /* NutNetBufAlloc */
  950. } /* RFC894 Frame */
  951. } /* Error read LookAheadBuffer */
  952. /*
  953. * Do the rest here, "global copy"
  954. */
  955. if (IPFrame == 1) {
  956. error = wi_read_bap(sc, fid, off, pFrameBuffer, copy_size);
  957. if (error != 0) {
  958. NutNetBufFree(nb);
  959. nb = NULL;
  960. } else {
  961. #if (WLAN_ENABLE_RX_FRAME_DUMP >= 1)
  962. Debug(("RxFrame: %d\n", len));
  963. DumpWlanData(nb->nb_dl.vp, nb->nb_dl.sz);
  964. #endif
  965. }
  966. }
  967. }
  968. /*
  969. * At least, send a ack for the event
  970. */
  971. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
  972. return (nb);
  973. }
  974. /************************************************************/
  975. /* RxThread */
  976. /************************************************************/
  977. THREAD(RxThread, arg)
  978. {
  979. NUTDEVICE *dev;
  980. IFNET *ifn;
  981. NETBUF *nb;
  982. struct wi_softc *sc;
  983. u_int16_t EventStatus;
  984. dev = arg;
  985. ifn = (IFNET *) dev->dev_icb;
  986. sc = (struct wi_softc *) dev->dev_dcb;
  987. for (;;) {
  988. /*
  989. * Wait for the arrival of new packets or check
  990. * the receiver every two second.
  991. */
  992. NutEventWait(&sc->InterruptEvent, 2000);
  993. EventStatus = sc->EventStatus;
  994. /*
  995. * Clear the sc-EventStatus. If the next time the
  996. * EventStatus is 0, it was the timeout and not
  997. * an interrupt.
  998. */
  999. sc->EventStatus = 0;
  1000. if (EventStatus != 0) {
  1001. if (EventStatus & WI_EV_RX) {
  1002. WI_LOCK(sc);
  1003. nb = wi_rx_intr(sc);
  1004. WI_UNLOCK(sc);
  1005. if (nb != 0) {
  1006. (*ifn->if_recv) (dev, nb);
  1007. }
  1008. }
  1009. if (EventStatus & WI_EV_ALLOC) {
  1010. WI_LOCK(sc);
  1011. wi_tx_intr(sc);
  1012. WI_UNLOCK(sc);
  1013. }
  1014. if (EventStatus & WI_EV_INFO) {
  1015. WI_LOCK(sc);
  1016. wi_info_intr(sc);
  1017. WI_UNLOCK(sc);
  1018. }
  1019. if (EventStatus & WI_EV_TX_EXC) {
  1020. Debug(("WI_EV_TX_EXC\n"));
  1021. }
  1022. CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS);
  1023. } else {
  1024. /*
  1025. * It was the timeout, check if the card is alive
  1026. */
  1027. if ((sc->sc_enabled == 1) && (sc->wi_gone == 1)) {
  1028. /*
  1029. * The card was enabled but we has lost the card, reinit...
  1030. */
  1031. Debug(("Houston, we have a problem...\n"));
  1032. sc->wi_gone = 0;
  1033. wlandrv_Init(dev);
  1034. }
  1035. } /* (EventStatus != 0) */
  1036. } /* for */
  1037. }
  1038. /************************************************************/
  1039. /* wi_alloc_fid */
  1040. /************************************************************/
  1041. static int wi_alloc_fid(struct wi_softc *sc, int len, int *idp)
  1042. {
  1043. unsigned long i; /* Harald: Changed from int to long */
  1044. /* Oliver: Changed from signed to unsigned */
  1045. if (wi_cmd(sc, WI_CMD_ALLOC_MEM, len, 0, 0)) {
  1046. Debug(("failed to allocate %d bytes on NIC\n", len));
  1047. return ENOMEM;
  1048. }
  1049. for (i = 0; i < WI_TIMEOUT; i++) {
  1050. if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_ALLOC) {
  1051. break;
  1052. }
  1053. if (i == WI_TIMEOUT) {
  1054. Debug(("timeout in alloc\n"));
  1055. return ETIMEDOUT;
  1056. }
  1057. DELAY(1);
  1058. }
  1059. *idp = CSR_READ_2(sc, WI_ALLOC_FID);
  1060. CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC);
  1061. return 0;
  1062. }
  1063. /************************************************************/
  1064. /* wi_write_ssid */
  1065. /************************************************************/
  1066. static int wi_write_ssid(struct wi_softc *sc, int rid, u_int8_t * buf, int buflen)
  1067. {
  1068. struct wi_ssid ssid;
  1069. if (buflen > IEEE80211_NWID_LEN) {
  1070. return ENOBUFS;
  1071. }
  1072. memset(&ssid, 0, sizeof(ssid));
  1073. ssid.wi_len = htole16(buflen);
  1074. memcpy(ssid.wi_ssid, buf, buflen);
  1075. return wi_write_rid(sc, rid, &ssid, sizeof(ssid));
  1076. }
  1077. /************************************************************/
  1078. /* wi_read_nicid */
  1079. /************************************************************/
  1080. static void wi_read_nicid(struct wi_softc *sc)
  1081. {
  1082. struct wi_card_ident *id;
  1083. char *p;
  1084. int len;
  1085. u_int16_t ver[4];
  1086. /*
  1087. * getting chip identity
  1088. */
  1089. memset(ver, 0, sizeof(ver));
  1090. len = sizeof(ver);
  1091. wi_read_rid(sc, WI_RID_CARD_ID, ver, &len);
  1092. Debug(("using "));
  1093. sc->sc_firmware_type = WI_NOTYPE;
  1094. for (id = wi_card_ident; id->card_name != NULL; id++) {
  1095. if (le16toh(ver[0]) == id->card_id) {
  1096. Debug(("%s", id->card_name));
  1097. sc->sc_firmware_type = id->firm_type;
  1098. break;
  1099. }
  1100. }
  1101. if (sc->sc_firmware_type == WI_NOTYPE) {
  1102. if (le16toh(ver[0]) & 0x8000) {
  1103. Debug(("Unknown PRISM2 chip"));
  1104. sc->sc_firmware_type = WI_INTERSIL;
  1105. } else {
  1106. Debug(("Unknown Lucent chip"));
  1107. sc->sc_firmware_type = WI_LUCENT;
  1108. }
  1109. }
  1110. /*
  1111. * get primary firmware version (Only Prism chips)
  1112. */
  1113. if (sc->sc_firmware_type != WI_LUCENT) {
  1114. memset(ver, 0, sizeof(ver));
  1115. len = sizeof(ver);
  1116. wi_read_rid(sc, WI_RID_PRI_IDENTITY, ver, &len);
  1117. sc->sc_pri_firmware_ver = le16toh(ver[2]) * 10000 + le16toh(ver[3]) * 100 + le16toh(ver[1]);
  1118. }
  1119. /*
  1120. * get station firmware version
  1121. */
  1122. memset(ver, 0, sizeof(ver));
  1123. len = sizeof(ver);
  1124. wi_read_rid(sc, WI_RID_STA_IDENTITY, ver, &len);
  1125. sc->sc_sta_firmware_ver = le16toh(ver[2]) * 10000 + le16toh(ver[3]) * 100 + le16toh(ver[1]);
  1126. if (sc->sc_firmware_type == WI_INTERSIL && (sc->sc_sta_firmware_ver == 10102 || sc->sc_sta_firmware_ver == 20102)) {
  1127. char ident[12];
  1128. memset(ident, 0, sizeof(ident));
  1129. len = sizeof(ident);
  1130. /*
  1131. * value should be the format like "V2.00-11"
  1132. */
  1133. if (wi_read_rid(sc, WI_RID_SYMBOL_IDENTITY, ident, &len) == 0 &&
  1134. *(p = (char *) ident) >= 'A' && p[2] == '.' && p[5] == '-' && p[8] == '\0') {
  1135. sc->sc_firmware_type = WI_SYMBOL;
  1136. sc->sc_sta_firmware_ver = (p[1] - '0') * 10000 +
  1137. (p[3] - '0') * 1000 + (p[4] - '0') * 100 + (p[6] - '0') * 10 + (p[7] - '0');
  1138. }
  1139. }
  1140. Debug(("\n"));
  1141. Debug(("%s Firmware: ",
  1142. sc->sc_firmware_type == WI_LUCENT ? "Lucent" : (sc->sc_firmware_type == WI_SYMBOL ? "Symbol" : "Intersil")));
  1143. if (sc->sc_firmware_type != WI_LUCENT) { /* XXX */
  1144. Debug(("Primary (%ld.%ld.%ld), ",
  1145. sc->sc_pri_firmware_ver / 10000, (sc->sc_pri_firmware_ver % 10000) / 100, sc->sc_pri_firmware_ver % 100));
  1146. }
  1147. Debug(("Station (%ld.%ld.%ld)\n",
  1148. sc->sc_sta_firmware_ver / 10000, (sc->sc_sta_firmware_ver % 10000) / 100, sc->sc_sta_firmware_ver % 100));
  1149. }
  1150. /************************************************************/
  1151. /* wi_write_wep */
  1152. /************************************************************/
  1153. static int wi_write_wep(struct wi_softc *sc)
  1154. {
  1155. struct ieee80211com *ic = &sc->sc_ic;
  1156. int error = 0;
  1157. int i, keylen;
  1158. u_int16_t val;
  1159. struct wi_key wkey[IEEE80211_WEP_NKID];
  1160. switch (sc->sc_firmware_type) {
  1161. #if (WLAN_SUPPORT_LUCENT >= 1)
  1162. case WI_LUCENT:
  1163. val = (ic->ic_flags & IEEE80211_F_WEPON) ? 1 : 0;
  1164. error = wi_write_val(sc, WI_RID_ENCRYPTION, val);
  1165. if (error)
  1166. break;
  1167. error = wi_write_val(sc, WI_RID_TX_CRYPT_KEY, ic->ic_wep_txkey);
  1168. if (error)
  1169. break;
  1170. memset(wkey, 0, sizeof(wkey));
  1171. for (i = 0; i < IEEE80211_WEP_NKID; i++) {
  1172. keylen = ic->ic_nw_keys[i].wk_len;
  1173. wkey[i].wi_keylen = htole16(keylen);
  1174. memcpy(wkey[i].wi_keydat, ic->ic_nw_keys[i].wk_key, keylen);
  1175. }
  1176. error = wi_write_rid(sc, WI_RID_DEFLT_CRYPT_KEYS, wkey, sizeof(wkey));
  1177. break;
  1178. #endif /* (WLAN_SUPPORT_LUCENT >= 1) */
  1179. #if ((WLAN_SUPPORT_INTERSIL >= 1) || (WLAN_SUPPORT_SYMBOL >= 1))
  1180. case WI_INTERSIL:
  1181. case WI_SYMBOL:
  1182. if (ic->ic_flags & IEEE80211_F_WEPON) {
  1183. /*
  1184. * ONLY HWB3163 EVAL-CARD Firmware version
  1185. * less than 0.8 variant2
  1186. *
  1187. * If promiscuous mode disable, Prism2 chip
  1188. * does not work with WEP .
  1189. * It is under investigation for details.
  1190. * (ichiro@netbsd.org)
  1191. */
  1192. if (sc->sc_firmware_type == WI_INTERSIL && sc->sc_sta_firmware_ver < 802) {
  1193. /*
  1194. * firm ver < 0.8 variant 2
  1195. */
  1196. wi_write_val(sc, WI_RID_PROMISC, 1);
  1197. }
  1198. wi_write_val(sc, WI_RID_CNFAUTHMODE, sc->sc_cnfauthmode);
  1199. val = PRIVACY_INVOKED | EXCLUDE_UNENCRYPTED;
  1200. /*
  1201. * Encryption firmware has a bug for HostAP mode.
  1202. */
  1203. if (sc->sc_firmware_type == WI_INTERSIL && ic->ic_opmode == IEEE80211_M_HOSTAP) {
  1204. val |= HOST_ENCRYPT;
  1205. }
  1206. } else {
  1207. wi_write_val(sc, WI_RID_CNFAUTHMODE, IEEE80211_AUTH_OPEN);
  1208. val = HOST_ENCRYPT | HOST_DECRYPT;
  1209. }
  1210. error = wi_write_val(sc, WI_RID_P2_ENCRYPTION, val);
  1211. if (error) {
  1212. break;
  1213. }
  1214. error = wi_write_val(sc, WI_RID_P2_TX_CRYPT_KEY, ic->ic_wep_txkey);
  1215. if (error) {
  1216. break;
  1217. }
  1218. /*
  1219. * It seems that the firmware accept 104bit key only if
  1220. * all the keys have 104bit length. We get the length of
  1221. * the transmit key and use it for all other keys.
  1222. * Perhaps we should use software WEP for such situation.
  1223. */
  1224. keylen = ic->ic_nw_keys[ic->ic_wep_txkey].wk_len;
  1225. if (keylen > IEEE80211_WEP_KEYLEN) {
  1226. keylen = 13; /* 104bit keys */
  1227. } else {
  1228. keylen = IEEE80211_WEP_KEYLEN;
  1229. }
  1230. for (i = 0; i < IEEE80211_WEP_NKID; i++) {
  1231. error = wi_write_rid(sc, WI_RID_P2_CRYPT_KEY0 + i, ic->ic_nw_keys[i].wk_key, keylen);
  1232. if (error) {
  1233. break;
  1234. }
  1235. }
  1236. break;
  1237. #endif /* ((WLAN_SUPPORT_INTERSIL >= 1) || (WLAN_SUPPORT_SYMBOL >= 1)) */
  1238. }
  1239. return error;
  1240. }
  1241. /*==========================================================*/
  1242. /* DEFINE: All code exported */
  1243. /*==========================================================*/
  1244. /************************************************************/
  1245. /* wlandrv_ProbeDevice */
  1246. /* */
  1247. /* Make a HW-Reset and test if a card is available. */
  1248. /* */
  1249. /* Return: ERROR, OK */
  1250. /************************************************************/
  1251. int wlandrv_ProbeDevice(void)
  1252. {
  1253. int error = -1;
  1254. u_int16_t Value;
  1255. /*
  1256. * Set RESET
  1257. */
  1258. RESET_EN_PORT |= RESET_BIT;
  1259. RESET_PORT |= RESET_BIT;
  1260. NutSleep(100);
  1261. /*
  1262. * Remove RESET
  1263. */
  1264. RESET_PORT &= ~RESET_BIT;
  1265. NutSleep(500);
  1266. /*
  1267. * Set the MAC into I/O mode
  1268. */
  1269. pcmcia_WriteMem(WI_COR_OFFSET, WI_COR_VALUE);
  1270. NutSleep(100);
  1271. /*
  1272. * Test if we can found a card
  1273. */
  1274. pcmcia_WriteReg(WI_HFA384X_SWSUPPORT0_OFF, WI_PRISM2STA_MAGIC);
  1275. Value = pcmcia_ReadReg(WI_HFA384X_SWSUPPORT0_OFF);
  1276. if (Value == WI_PRISM2STA_MAGIC) {
  1277. /*
  1278. * We found a card :-)
  1279. */
  1280. error = 0;
  1281. }
  1282. return (error);
  1283. }
  1284. /************************************************************/
  1285. /* wlandrv_Attach */
  1286. /* */
  1287. /* Catch all information about the card which */
  1288. /* could be found. And set some default parameter */
  1289. /* */
  1290. /* Return: ERROR, OK */
  1291. /************************************************************/
  1292. int wlandrv_Attach(device_t dev)
  1293. {
  1294. struct wi_softc *sc = device_get_softc(dev);
  1295. struct ieee80211com *ic = &sc->sc_ic;
  1296. struct ieee80211_rateset *rs;
  1297. int i, nrates, buflen;
  1298. u_int16_t val;
  1299. u_int8_t ratebuf[2 + IEEE80211_RATE_SIZE];
  1300. //u_int8_t empty_macaddr[IEEE80211_ADDR_LEN] = {
  1301. // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  1302. //}; /* Harald: This is unused */
  1303. int error;
  1304. bDebugState = 2;
  1305. sc->wi_cmd_count = 500;
  1306. ic->ic_fixed_rate = -1; /* auto */
  1307. /*
  1308. * Reset the NIC.
  1309. */
  1310. if (wi_reset(sc) != 0) {
  1311. return ENXIO; /* XXX */
  1312. }
  1313. /*
  1314. * Read the station address.
  1315. * And do it twice. I've seen PRISM-based cards that return
  1316. * an error when trying to read it the first time, which causes
  1317. * the probe to fail.
  1318. */
  1319. buflen = IEEE80211_ADDR_LEN;
  1320. error = wi_read_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, &buflen);
  1321. if (error != 0) {
  1322. buflen = IEEE80211_ADDR_LEN;
  1323. error = wi_read_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, &buflen);
  1324. }
  1325. if (error != 0) {
  1326. Debug(("mac read failed %d\n", error));
  1327. return (error);
  1328. }
  1329. Debug(("802.11 address: %02X-%02X-%02X-%02X-%02X-%02X\n",
  1330. ic->ic_myaddr[0], ic->ic_myaddr[1], ic->ic_myaddr[2], ic->ic_myaddr[3], ic->ic_myaddr[4], ic->ic_myaddr[5]));
  1331. /*
  1332. * Read NIC identification
  1333. */
  1334. wi_read_nicid(sc);
  1335. ic->ic_opmode = IEEE80211_M_STA;
  1336. ic->ic_caps = IEEE80211_C_PMGT | IEEE80211_C_AHDEMO;
  1337. ic->ic_state = IEEE80211_S_INIT;
  1338. /*
  1339. * Query the card for available channels.
  1340. */
  1341. buflen = sizeof(val);
  1342. if (wi_read_rid(sc, WI_RID_CHANNEL_LIST, &val, &buflen) != 0) {
  1343. val = htole16(0x1fff); /* assume 1-13 */
  1344. }
  1345. if (val == 0) {
  1346. Debug(("wi_attach: no available channels listed!"));
  1347. }
  1348. ic->ChannelList = (val << 1);
  1349. /*
  1350. * Read the default channel from the NIC. This may vary
  1351. * depending on the country where the NIC was purchased, so
  1352. * we can't hard-code a default and expect it to work for
  1353. * everyone.
  1354. *
  1355. * If no channel is specified, let the 802.11 code select.
  1356. */
  1357. buflen = sizeof(val);
  1358. if (wi_read_rid(sc, WI_RID_OWN_CHNL, &val, &buflen) == 0) {
  1359. val = le16toh(val);
  1360. i = (1 << val);
  1361. if ((val > 16) || ((ic->ChannelList & i) == 0)) {
  1362. Debug(("wi_attach: invalid own channel %d!", val));
  1363. }
  1364. ic->ic_ibss_chan = val;
  1365. } else {
  1366. Debug(("WI_RID_OWN_CHNL failed, using first channel!\n"));
  1367. ic->ic_ibss_chan = 1;
  1368. }
  1369. /*
  1370. * Set flags based on firmware version.
  1371. */
  1372. switch (sc->sc_firmware_type) {
  1373. #if (WLAN_SUPPORT_LUCENT >= 1)
  1374. case WI_LUCENT:
  1375. sc->sc_ntxbuf = 1;
  1376. sc->sc_flags |= WI_FLAGS_HAS_SYSSCALE;
  1377. #ifdef WI_HERMES_AUTOINC_WAR
  1378. /*
  1379. * XXX: not confirmed, but never seen for recent firmware
  1380. */
  1381. if (sc->sc_sta_firmware_ver < 40000) {
  1382. sc->sc_flags |= WI_FLAGS_BUG_AUTOINC;
  1383. }
  1384. #endif
  1385. if (sc->sc_sta_firmware_ver >= 60000) {
  1386. sc->sc_flags |= WI_FLAGS_HAS_MOR;
  1387. }
  1388. if (sc->sc_sta_firmware_ver >= 60006) {
  1389. ic->ic_caps |= IEEE80211_C_IBSS;
  1390. ic->ic_caps |= IEEE80211_C_MONITOR;
  1391. }
  1392. sc->sc_ibss_port = htole16(1);
  1393. sc->sc_min_rssi = WI_LUCENT_MIN_RSSI;
  1394. sc->sc_max_rssi = WI_LUCENT_MAX_RSSI;
  1395. sc->sc_dbm_offset = WI_LUCENT_DBM_OFFSET;
  1396. break;
  1397. #endif /* (WLAN_SUPPORT_LUCENT >= 1) */
  1398. #if (WLAN_SUPPORT_INTERSIL >= 1)
  1399. case WI_INTERSIL:
  1400. sc->sc_ntxbuf = WI_NTXBUF;
  1401. sc->sc_flags |= WI_FLAGS_HAS_FRAGTHR;
  1402. sc->sc_flags |= WI_FLAGS_HAS_ROAMING;
  1403. sc->sc_flags |= WI_FLAGS_HAS_SYSSCALE;
  1404. /*
  1405. * Old firmware are slow, so give peace a chance.
  1406. */
  1407. if (sc->sc_sta_firmware_ver < 10000) {
  1408. sc->wi_cmd_count = 5000;
  1409. }
  1410. if (sc->sc_sta_firmware_ver > 10101) {
  1411. sc->sc_flags |= WI_FLAGS_HAS_DBMADJUST;
  1412. }
  1413. if (sc->sc_sta_firmware_ver >= 800) {
  1414. ic->ic_caps |= IEEE80211_C_IBSS;
  1415. ic->ic_caps |= IEEE80211_C_MONITOR;
  1416. }
  1417. /*
  1418. * version 0.8.3 and newer are the only ones that are known
  1419. * to currently work. Earlier versions can be made to work,
  1420. * at least according to the Linux driver.
  1421. */
  1422. if (sc->sc_sta_firmware_ver >= 803) {
  1423. ic->ic_caps |= IEEE80211_C_HOSTAP;
  1424. }
  1425. sc->sc_ibss_port = htole16(0);
  1426. sc->sc_min_rssi = WI_PRISM_MIN_RSSI;
  1427. sc->sc_max_rssi = WI_PRISM_MAX_RSSI;
  1428. sc->sc_dbm_offset = WI_PRISM_DBM_OFFSET;
  1429. break;
  1430. #endif /* (WLAN_SUPPORT_INTERSIL >= 1) */
  1431. #if (WLAN_SUPPORT_SYMBOL >= 1)
  1432. case WI_SYMBOL:
  1433. sc->sc_ntxbuf = 1;
  1434. sc->sc_flags |= WI_FLAGS_HAS_DIVERSITY;
  1435. if (sc->sc_sta_firmware_ver >= 25000) {
  1436. ic->ic_caps |= IEEE80211_C_IBSS;
  1437. }
  1438. sc->sc_ibss_port = htole16(4);
  1439. sc->sc_min_rssi = WI_PRISM_MIN_RSSI;
  1440. sc->sc_max_rssi = WI_PRISM_MAX_RSSI;
  1441. sc->sc_dbm_offset = WI_PRISM_DBM_OFFSET;
  1442. break;
  1443. #endif /* (WLAN_SUPPORT_SYMBOL >= 1) */
  1444. }
  1445. /*
  1446. * Find out if we support WEP on this card.
  1447. */
  1448. buflen = sizeof(val);
  1449. if (wi_read_rid(sc, WI_RID_WEP_AVAIL, &val, &buflen) == 0 && val != htole16(0)) {
  1450. ic->ic_caps |= IEEE80211_C_WEP;
  1451. }
  1452. /*
  1453. * Find supported rates.
  1454. */
  1455. buflen = sizeof(ratebuf);
  1456. rs = &ic->ic_sup_rates[IEEE80211_MODE_11B];
  1457. if (wi_read_rid(sc, WI_RID_DATA_RATES, ratebuf, &buflen) == 0) {
  1458. nrates = le16toh(*(u_int16_t *) ratebuf);
  1459. if (nrates > IEEE80211_RATE_MAXSIZE) {
  1460. nrates = IEEE80211_RATE_MAXSIZE;
  1461. }
  1462. rs->rs_nrates = 0;
  1463. for (i = 0; i < nrates; i++) {
  1464. if (ratebuf[2 + i]) {
  1465. rs->rs_rates[rs->rs_nrates++] = ratebuf[2 + i];
  1466. }
  1467. }
  1468. } else {
  1469. /*
  1470. * XXX fallback on error?
  1471. */
  1472. rs->rs_nrates = 0;
  1473. }
  1474. buflen = sizeof(val);
  1475. if ((sc->sc_flags & WI_FLAGS_HAS_DBMADJUST) && wi_read_rid(sc, WI_RID_DBM_ADJUST, &val, &buflen) == 0) {
  1476. sc->sc_dbm_offset = le16toh(val);
  1477. }
  1478. sc->sc_max_datalen = 2304;
  1479. sc->sc_system_scale = 1;
  1480. sc->sc_cnfauthmode = IEEE80211_AUTH_OPEN;
  1481. sc->sc_roaming_mode = WI_DEFAULT_ROAMING;
  1482. sc->sc_portnum = WI_DEFAULT_PORT;
  1483. sc->sc_authtype = WI_DEFAULT_AUTHTYPE;
  1484. /*
  1485. * Init DeviceSemaphore
  1486. */
  1487. NutEventPost(&hDeviceSemaphore);
  1488. return (0);
  1489. }
  1490. /************************************************************/
  1491. /* wlandrv_Init */
  1492. /************************************************************/
  1493. void wlandrv_Init(device_t dev)
  1494. {
  1495. struct wi_softc *sc = device_get_softc(dev);
  1496. struct ieee80211com *ic = &sc->sc_ic;
  1497. int i;
  1498. int error = 0, wasenabled;
  1499. WI_LOCK(sc);
  1500. if (sc->wi_gone) {
  1501. WI_UNLOCK(sc);
  1502. return;
  1503. }
  1504. if ((wasenabled = sc->sc_enabled)) {
  1505. wi_stop(sc, 1);
  1506. }
  1507. wi_reset(sc);
  1508. /*
  1509. * common 802.11 configuration
  1510. */
  1511. ic->ic_flags &= ~IEEE80211_F_IBSSON;
  1512. sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
  1513. switch (ic->ic_opmode) {
  1514. case IEEE80211_M_STA:
  1515. wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_BSS);
  1516. break;
  1517. case IEEE80211_M_IBSS:
  1518. wi_write_val(sc, WI_RID_PORTTYPE, sc->sc_ibss_port);
  1519. ic->ic_flags |= IEEE80211_F_IBSSON;
  1520. break;
  1521. case IEEE80211_M_AHDEMO:
  1522. wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_ADHOC);
  1523. break;
  1524. case IEEE80211_M_HOSTAP:
  1525. /*
  1526. * For PRISM cards, override the empty SSID, because in
  1527. * HostAP mode the controller will lock up otherwise.
  1528. */
  1529. if (sc->sc_firmware_type == WI_INTERSIL && ic->ic_des_esslen == 0) {
  1530. ic->ic_des_essid[0] = ' ';
  1531. ic->ic_des_esslen = 1;
  1532. }
  1533. wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_HOSTAP);
  1534. break;
  1535. case IEEE80211_M_MONITOR:
  1536. /* Harald: Should be handled. */
  1537. #if 0 // @@MF this mode is not working with my card
  1538. if (sc->sc_firmware_type == WI_LUCENT) {
  1539. wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_ADHOC);
  1540. }
  1541. error = wi_cmd(sc, WI_CMD_DEBUG | (WI_TEST_MONITOR << 8), 0, 0, 0);
  1542. #endif
  1543. break;
  1544. }
  1545. /*
  1546. * Intersil interprets this RID as joining ESS even in IBSS mode
  1547. */
  1548. if (sc->sc_firmware_type == WI_LUCENT && (ic->ic_flags & IEEE80211_F_IBSSON) && ic->ic_des_esslen > 0) {
  1549. wi_write_val(sc, WI_RID_CREATE_IBSS, 1);
  1550. } else {
  1551. wi_write_val(sc, WI_RID_CREATE_IBSS, 0);
  1552. }
  1553. #if 0 //@@MF later
  1554. wi_write_val(sc, WI_RID_MAX_SLEEP, ic->ic_lintval);
  1555. #endif /* later */
  1556. wi_write_ssid(sc, WI_RID_DESIRED_SSID, ic->ic_des_essid, ic->ic_des_esslen);
  1557. wi_write_val(sc, WI_RID_OWN_CHNL, ic->ic_ibss_chan);
  1558. wi_write_ssid(sc, WI_RID_OWN_SSID, ic->ic_des_essid, ic->ic_des_esslen);
  1559. wi_write_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, IEEE80211_ADDR_LEN);
  1560. wi_write_val(sc, WI_RID_PM_ENABLED, (ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0);
  1561. /*
  1562. * not yet common 802.11 configuration
  1563. */
  1564. wi_write_val(sc, WI_RID_MAX_DATALEN, sc->sc_max_datalen);
  1565. #if 0 //@@MF later
  1566. wi_write_val(sc, WI_RID_RTS_THRESH, ic->ic_rtsthreshold);
  1567. if (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR) {
  1568. wi_write_val(sc, WI_RID_FRAG_THRESH, ic->ic_fragthreshold);
  1569. }
  1570. #endif /* later */
  1571. /*
  1572. * driver specific 802.11 configuration
  1573. */
  1574. if (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE) {
  1575. wi_write_val(sc, WI_RID_SYSTEM_SCALE, sc->sc_system_scale);
  1576. }
  1577. if (sc->sc_flags & WI_FLAGS_HAS_ROAMING) {
  1578. wi_write_val(sc, WI_RID_ROAMING_MODE, sc->sc_roaming_mode);
  1579. }
  1580. if (sc->sc_flags & WI_FLAGS_HAS_MOR) {
  1581. wi_write_val(sc, WI_RID_MICROWAVE_OVEN, sc->sc_microwave_oven);
  1582. }
  1583. wi_write_txrate(sc);
  1584. #if 0 //@@MF later
  1585. /*
  1586. * What is a nodename ??? :-(
  1587. */
  1588. wi_write_ssid(sc, WI_RID_NODENAME, sc->sc_nodename, sc->sc_nodelen);
  1589. #endif /* later */
  1590. #if 0 //@@MF later
  1591. /*
  1592. * Does we realy need HOSTAP on Ethernut??
  1593. */
  1594. if (ic->ic_opmode == IEEE80211_M_HOSTAP && sc->sc_firmware_type == WI_INTERSIL) {
  1595. wi_write_val(sc, WI_RID_OWN_BEACON_INT, ic->ic_lintval);
  1596. wi_write_val(sc, WI_RID_BASIC_RATE, 0x03); /* 1, 2 */
  1597. wi_write_val(sc, WI_RID_SUPPORT_RATE, 0x0f); /* 1, 2, 5.5, 11 */
  1598. wi_write_val(sc, WI_RID_DTIM_PERIOD, 1);
  1599. }
  1600. #endif /* later */
  1601. /*
  1602. * Initialize promisc mode.
  1603. * Being in the Host-AP mode causes a great
  1604. * deal of pain if primisc mode is set.
  1605. * Therefore we avoid confusing the firmware
  1606. * and always reset promisc mode in Host-AP
  1607. * mode. Host-AP sees all the packets anyway.
  1608. */
  1609. if ((ic->ic_opmode != IEEE80211_M_HOSTAP) && (sc->PromiscuousMode != 0)) {
  1610. wi_write_val(sc, WI_RID_PROMISC, 1);
  1611. } else {
  1612. wi_write_val(sc, WI_RID_PROMISC, 0);
  1613. }
  1614. /*
  1615. * Configure WEP.
  1616. */
  1617. if (ic->ic_caps & IEEE80211_C_WEP) {
  1618. wi_write_wep(sc);
  1619. }
  1620. #if 0 //@@MF later
  1621. /*
  1622. * Set multicast filter.
  1623. */
  1624. wi_write_multi(sc);
  1625. #endif /* later */
  1626. /*
  1627. * Allocate fids for the card
  1628. */
  1629. if (sc->sc_firmware_type != WI_SYMBOL || !wasenabled) {
  1630. sc->sc_buflen = IEEE80211_MAX_LEN + sizeof(struct wi_frame);
  1631. if (sc->sc_firmware_type == WI_SYMBOL) {
  1632. sc->sc_buflen = 1585; /* XXX */
  1633. }
  1634. for (i = 0; i < sc->sc_ntxbuf; i++) {
  1635. error = wi_alloc_fid(sc, sc->sc_buflen, &sc->sc_txd[i].d_fid);
  1636. if (error) {
  1637. Debug(("tx buffer allocation failed (error %u)\n", error));
  1638. goto out;
  1639. }
  1640. sc->sc_txd[i].d_len = 0;
  1641. }
  1642. }
  1643. sc->sc_txcur = sc->sc_txnext = 0;
  1644. /*
  1645. * Enable desired port
  1646. */
  1647. wi_cmd(sc, WI_CMD_ENABLE | sc->sc_portnum, 0, 0, 0);
  1648. sc->sc_enabled = 1;
  1649. if (ic->ic_opmode == IEEE80211_M_AHDEMO || ic->ic_opmode == IEEE80211_M_MONITOR || ic->ic_opmode == IEEE80211_M_HOSTAP) {
  1650. ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
  1651. }
  1652. /*************************************************************************/
  1653. /* Set interrupt and start RxThread */
  1654. /*************************************************************************/
  1655. if (sc->InterruptInitDone == 0) {
  1656. sc->InterruptInitDone = 1;
  1657. /*
  1658. * Install WLAN interrupt
  1659. */
  1660. PORTE |= 0x80; /* Enable PullUp */
  1661. error = NutRegisterIrqHandler(&sig_INTERRUPT7, WLANInterrupt, dev);
  1662. if (error == FALSE) {
  1663. EICR |= 0x80; // falling edge
  1664. sbi(EIMSK, INT7);
  1665. /*
  1666. * Start the receiver thread.
  1667. */
  1668. NutThreadCreate("rxi7", RxThread, dev, 640);
  1669. }
  1670. }
  1671. /*************************************************************************/
  1672. /*
  1673. * Enable interrupts
  1674. */
  1675. CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS);
  1676. if (!wasenabled && ic->ic_opmode == IEEE80211_M_HOSTAP && sc->sc_firmware_type == WI_INTERSIL) {
  1677. /*
  1678. * XXX: some card need to be re-enabled for hostap
  1679. */
  1680. wi_cmd(sc, WI_CMD_DISABLE | WI_PORT0, 0, 0, 0);
  1681. wi_cmd(sc, WI_CMD_ENABLE | WI_PORT0, 0, 0, 0);
  1682. }
  1683. #if 0 //@@MF later
  1684. /*
  1685. * This is only for IEEE80211_M_STA
  1686. */
  1687. if (ic->ic_opmode == IEEE80211_M_STA && ((ic->ic_flags & IEEE80211_F_DESBSSID) || ic->ic_des_chan != IEEE80211_CHAN_ANYC)) {
  1688. memset(&join, 0, sizeof(join));
  1689. if (ic->ic_flags & IEEE80211_F_DESBSSID)
  1690. IEEE80211_ADDR_COPY(&join.wi_bssid, ic->ic_des_bssid);
  1691. if (ic->ic_des_chan != IEEE80211_CHAN_ANYC)
  1692. join.wi_chan = htole16(ieee80211_chan2ieee(ic, ic->ic_des_chan));
  1693. /*
  1694. * Lucent firmware does not support the JOIN RID.
  1695. */
  1696. if (sc->sc_firmware_type != WI_LUCENT)
  1697. wi_write_rid(sc, WI_RID_JOIN_REQ, &join, sizeof(join));
  1698. }
  1699. #endif /* later */
  1700. WI_UNLOCK(sc);
  1701. return;
  1702. out:
  1703. if (error) {
  1704. Debug(("interface not running\n"));
  1705. wi_stop(sc, 1);
  1706. }
  1707. WI_UNLOCK(sc);
  1708. Debug(("wi_init: return %d\n", error));
  1709. return;
  1710. }
  1711. /************************************************************/
  1712. /* wlandrv_PutPacket */
  1713. /************************************************************/
  1714. int wlandrv_PutPacket(NUTDEVICE * dev, NETBUF * nb)
  1715. {
  1716. int error = -1;
  1717. struct wi_softc *sc = (struct wi_softc *) dev->dev_dcb;
  1718. struct wi_frame frmhdr;
  1719. LLCS_SNAP_HEADER LLCSSNAPHeader;
  1720. ETHERHDR *pMAC8023Header;
  1721. int cur, fid, off, len;
  1722. if (sc->wi_gone) {
  1723. Debug(("wlandrv_PutPacket gone\r\n"));
  1724. return (-1);
  1725. }
  1726. /*
  1727. * Calculate the number of bytes to be send. Do not
  1728. * send packets larger than 1518 bytes.
  1729. */
  1730. len = nb->nb_dl.sz + nb->nb_nw.sz + nb->nb_tp.sz + nb->nb_ap.sz;
  1731. if (len > 1518) {
  1732. return (-1);
  1733. } else {
  1734. WI_LOCK(sc);
  1735. /*
  1736. * This is a RFC894 Frame from Ethernut
  1737. */
  1738. #if (WLAN_ENABLE_TX_FRAME_DUMP >= 1)
  1739. Debug(("TxFrame: %d\n", len));
  1740. DumpWlanData(nb->nb_dl.vp, len);
  1741. #endif
  1742. /*
  1743. * But we must send a RFC1024 Frame.
  1744. * ETHERHDR is not part of an RFC1024 Frame
  1745. */
  1746. len = len - sizeof(ETHERHDR);
  1747. /*
  1748. * Add RFC1024 Header
  1749. */
  1750. len += sizeof(LLCS_SNAP_HEADER);
  1751. /*
  1752. * I do not know what I do here, therefore clear the header
  1753. * and to hope for, the card will do the rest?
  1754. */
  1755. memset(&frmhdr, 0, sizeof(frmhdr));
  1756. /*
  1757. * Copy the Ethernut MAC 802.3 Dest/Source Address into the WLANHeader
  1758. */
  1759. pMAC8023Header = (ETHERHDR *) nb->nb_dl.vp;
  1760. frmhdr.wi_dat_len = len;
  1761. memcpy(frmhdr.wi_ehdr.ether_dhost, pMAC8023Header->ether_dhost, IEEE80211_ADDR_LEN);
  1762. memcpy(frmhdr.wi_ehdr.ether_shost, pMAC8023Header->ether_shost, IEEE80211_ADDR_LEN);
  1763. frmhdr.wi_ehdr.ether_type = SWAP(len);
  1764. /*
  1765. * Prepare the RFC1024 Header
  1766. */
  1767. LLCSSNAPHeader.DSAPSSAP = 0xAAAA;
  1768. LLCSSNAPHeader.Control = 0x0003;
  1769. LLCSSNAPHeader.MustZero = 0x0000;
  1770. LLCSSNAPHeader.Type = pMAC8023Header->ether_type;
  1771. /*
  1772. * Get the TX-BUffer-ID
  1773. */
  1774. cur = sc->sc_txcur;
  1775. fid = sc->sc_txd[cur].d_fid;
  1776. /*
  1777. * And Copy the WLANHeader
  1778. */
  1779. error = wi_write_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr));
  1780. if (error == 0) {
  1781. off = sizeof(frmhdr);
  1782. /*
  1783. * Now copy the RFC1024 Header
  1784. */
  1785. error = wi_write_bap(sc, fid, off, &LLCSSNAPHeader, sizeof(LLCSSNAPHeader));
  1786. if (error == 0) {
  1787. off += sizeof(LLCSSNAPHeader);
  1788. /*
  1789. * Copy the rest of the Ethernut Data
  1790. */
  1791. if ((error == 0) && (nb->nb_nw.sz != 0)) {
  1792. error = wi_write_bap(sc, fid, off, nb->nb_nw.vp, nb->nb_nw.sz);
  1793. off += nb->nb_nw.sz;
  1794. }
  1795. if ((error == 0) && (nb->nb_tp.sz != 0)) {
  1796. error = wi_write_bap(sc, fid, off, nb->nb_tp.vp, nb->nb_tp.sz);
  1797. off += nb->nb_tp.sz;
  1798. }
  1799. if ((error == 0) && (nb->nb_ap.sz != 0)) {
  1800. error = wi_write_bap(sc, fid, off, nb->nb_ap.vp, nb->nb_ap.sz);
  1801. }
  1802. if (error == 0) {
  1803. //@@MF sc->sc_txd[cur].d_len = off;
  1804. error = wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, fid, 0, 0);
  1805. if (error != 0) {
  1806. Debug(("xmit failed\n"));
  1807. sc->sc_txd[cur].d_len = 0;
  1808. }
  1809. sc->sc_txnext = cur = (cur + 1) % sc->sc_ntxbuf;
  1810. }
  1811. }
  1812. }
  1813. WI_UNLOCK(sc);
  1814. }
  1815. return (error);
  1816. }
  1817. /************************************************************/
  1818. /* wlandrv_IOCTL */
  1819. /************************************************************/
  1820. int wlandrv_IOCTL(NUTDEVICE * dev, int req, void *conf)
  1821. {
  1822. int error = 0;
  1823. int len;
  1824. int i;
  1825. u_int16_t DataBuffer[6];
  1826. struct wi_softc *sc = (struct wi_softc *) dev->dev_dcb;
  1827. struct ieee80211com *ic = &sc->sc_ic;
  1828. WLAN_CONFIG *pWLANConfig;
  1829. WLAN_STATUS *pWLANStatus;
  1830. u_int8_t BSSIDAddress[6];
  1831. if ((sc->wi_gone) || (conf == 0)) {
  1832. error = -1;
  1833. } else {
  1834. switch (req) {
  1835. /*****************************************************/
  1836. /* WLAN_IOCTL_GET_MAC_ADDRESS */
  1837. /*****************************************************/
  1838. case WLAN_IOCTL_GET_MAC_ADDRESS:{
  1839. memcpy(conf, ic->ic_myaddr, IEEE80211_ADDR_LEN);
  1840. break;
  1841. } /* WLAN_IOCTL_GET_MAC_ADDRESS */
  1842. /*****************************************************/
  1843. /* WLAN_IOCTL_SET_CONFIG */
  1844. /*****************************************************/
  1845. case WLAN_IOCTL_SET_CONFIG:{
  1846. pWLANConfig = (WLAN_CONFIG *) conf;
  1847. if ((pWLANConfig != NULL) && (pWLANConfig->Size == sizeof(WLAN_CONFIG))) {
  1848. WI_LOCK(sc);
  1849. /* Stop WLAN controller */
  1850. wi_stop(sc, 1);
  1851. /* Set mode */
  1852. switch (pWLANConfig->Mode) {
  1853. case WLAN_MODE_STOP:{
  1854. WI_UNLOCK(sc);
  1855. return (0);
  1856. break;
  1857. }
  1858. case WLAN_MODE_STATION:{
  1859. ic->ic_opmode = IEEE80211_M_STA;
  1860. break;
  1861. }
  1862. case WLAN_MODE_ADHOC:{
  1863. ic->ic_opmode = IEEE80211_M_IBSS;
  1864. break;
  1865. }
  1866. default:{
  1867. error = -1;
  1868. break;
  1869. }
  1870. }
  1871. if (error == 0) {
  1872. /* Set SSID */
  1873. len = strlen(pWLANConfig->Networkname);
  1874. memcpy(ic->ic_des_essid, pWLANConfig->Networkname, len);
  1875. ic->ic_des_esslen = len;
  1876. /* Enable WEP */
  1877. switch (pWLANConfig->UseWEP) {
  1878. case WLAN_USE_NO_WEP:{
  1879. ic->ic_flags &= ~IEEE80211_F_WEPON;
  1880. break;
  1881. }
  1882. case WLAN_USE_64BIT_WEP:
  1883. case WLAN_USE_128BIT_WEP:{
  1884. ic->ic_flags |= IEEE80211_F_WEPON;
  1885. break;
  1886. }
  1887. default:{
  1888. error = -1;
  1889. break;
  1890. }
  1891. }
  1892. /* Set WEP tx key */
  1893. ic->ic_wep_txkey = pWLANConfig->UseWEPTxKey;
  1894. /* Set WEP keys */
  1895. for (i = 0; i < WLAN_WEP_MAX_KEY_COUNT; i++) {
  1896. ic->ic_nw_keys[i].wk_len = pWLANConfig->WEPKey[i].KeyLen;
  1897. memcpy(ic->ic_nw_keys[i].wk_key, pWLANConfig->WEPKey[i].Key, WLAN_WEP_MAX_KEY_SIZE);
  1898. }
  1899. }
  1900. WI_UNLOCK(sc);
  1901. if (error == 0) {
  1902. wlandrv_Init(dev);
  1903. }
  1904. } else {
  1905. error = -1;
  1906. }
  1907. break;
  1908. } /* WLAN_IOCTL_SET_CONFIG */
  1909. /*****************************************************/
  1910. /* WLAN_IOCTL_GET_STATUS */
  1911. /*****************************************************/
  1912. case WLAN_IOCTL_GET_STATUS:{
  1913. pWLANStatus = (WLAN_STATUS *) conf;
  1914. if ((pWLANStatus != NULL) && (pWLANStatus->Size == sizeof(WLAN_STATUS))) {
  1915. WI_LOCK(sc);
  1916. memset(pWLANStatus, 0x00, sizeof(WLAN_STATUS));
  1917. pWLANStatus->Size = sizeof(WLAN_STATUS);
  1918. /*
  1919. * PortStatus
  1920. */
  1921. memset(DataBuffer, 0, sizeof(DataBuffer));
  1922. len = sizeof(DataBuffer);
  1923. error = wi_read_rid(sc, WI_RID_PORT_STAT, DataBuffer, &len);
  1924. if (error == 0) {
  1925. pWLANStatus->PortStatus = (u_int8_t) DataBuffer[0];
  1926. }
  1927. /*
  1928. * Current BSSID
  1929. */
  1930. memset(BSSIDAddress, 0, sizeof(BSSIDAddress));
  1931. len = sizeof(BSSIDAddress);
  1932. error = wi_read_rid(sc, WI_RID_CURRENT_BSSID, BSSIDAddress, &len);
  1933. if (error == 0) {
  1934. memcpy(pWLANStatus->BSSIDAddress, BSSIDAddress, IEEE80211_ADDR_LEN);
  1935. }
  1936. /*
  1937. * Current Channel
  1938. */
  1939. memset(DataBuffer, 0, sizeof(DataBuffer));
  1940. len = sizeof(DataBuffer);
  1941. error = wi_read_rid(sc, WI_RID_CURRENT_CHAN, DataBuffer, &len);
  1942. if (error == 0) {
  1943. pWLANStatus->Channel = (u_int8_t) DataBuffer[0];
  1944. }
  1945. /*
  1946. * Current TxRate
  1947. */
  1948. memset(DataBuffer, 0, sizeof(DataBuffer));
  1949. len = sizeof(DataBuffer);
  1950. error = wi_read_rid(sc, WI_RID_CUR_TX_RATE, DataBuffer, &len);
  1951. if (error == 0) {
  1952. pWLANStatus->TxRate = (u_int8_t) DataBuffer[0];
  1953. }
  1954. /*
  1955. * Getting Quality
  1956. */
  1957. memset(DataBuffer, 0, sizeof(DataBuffer));
  1958. len = sizeof(DataBuffer);
  1959. error = wi_read_rid(sc, WI_RID_DBM_COMMS_QUAL, DataBuffer, &len);
  1960. if (error == 0) {
  1961. pWLANStatus->Quality = DataBuffer[0];
  1962. pWLANStatus->Signal = DataBuffer[1];
  1963. pWLANStatus->Noise = DataBuffer[2];
  1964. }
  1965. WI_UNLOCK(sc);
  1966. } else {
  1967. error = -1;
  1968. }
  1969. break;
  1970. } /* WLAN_IOCTL_GET_STATUS */
  1971. default:{
  1972. error = -1;
  1973. break;
  1974. }
  1975. } /* switch */
  1976. } /* sc->wi_gone */
  1977. return (error);
  1978. }