ps3_gelic_wireless.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792
  1. /*
  2. * PS3 gelic network driver.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2007 Sony Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #undef DEBUG
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/if_vlan.h>
  26. #include <linux/in.h>
  27. #include <linux/ip.h>
  28. #include <linux/tcp.h>
  29. #include <linux/wireless.h>
  30. #include <linux/ctype.h>
  31. #include <linux/string.h>
  32. #include <net/iw_handler.h>
  33. #include <net/ieee80211.h>
  34. #include <linux/dma-mapping.h>
  35. #include <net/checksum.h>
  36. #include <asm/firmware.h>
  37. #include <asm/ps3.h>
  38. #include <asm/lv1call.h>
  39. #include "ps3_gelic_net.h"
  40. #include "ps3_gelic_wireless.h"
  41. static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan);
  42. static int gelic_wl_try_associate(struct net_device *netdev);
  43. /*
  44. * tables
  45. */
  46. /* 802.11b/g channel to freq in MHz */
  47. static const int channel_freq[] = {
  48. 2412, 2417, 2422, 2427, 2432,
  49. 2437, 2442, 2447, 2452, 2457,
  50. 2462, 2467, 2472, 2484
  51. };
  52. #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
  53. /* in bps */
  54. static const int bitrate_list[] = {
  55. 1000000,
  56. 2000000,
  57. 5500000,
  58. 11000000,
  59. 6000000,
  60. 9000000,
  61. 12000000,
  62. 18000000,
  63. 24000000,
  64. 36000000,
  65. 48000000,
  66. 54000000
  67. };
  68. #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
  69. /*
  70. * wpa2 support requires the hypervisor version 2.0 or later
  71. */
  72. static inline int wpa2_capable(void)
  73. {
  74. return (0 <= ps3_compare_firmware_version(2, 0, 0));
  75. }
  76. static inline int precise_ie(void)
  77. {
  78. return (0 <= ps3_compare_firmware_version(2, 2, 0));
  79. }
  80. /*
  81. * post_eurus_cmd helpers
  82. */
  83. struct eurus_cmd_arg_info {
  84. int pre_arg; /* command requres arg1, arg2 at POST COMMAND */
  85. int post_arg; /* command requires arg1, arg2 at GET_RESULT */
  86. };
  87. static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
  88. [GELIC_EURUS_CMD_SET_COMMON_CFG] = { .pre_arg = 1},
  89. [GELIC_EURUS_CMD_SET_WEP_CFG] = { .pre_arg = 1},
  90. [GELIC_EURUS_CMD_SET_WPA_CFG] = { .pre_arg = 1},
  91. [GELIC_EURUS_CMD_GET_COMMON_CFG] = { .post_arg = 1},
  92. [GELIC_EURUS_CMD_GET_WEP_CFG] = { .post_arg = 1},
  93. [GELIC_EURUS_CMD_GET_WPA_CFG] = { .post_arg = 1},
  94. [GELIC_EURUS_CMD_GET_RSSI_CFG] = { .post_arg = 1},
  95. [GELIC_EURUS_CMD_GET_SCAN] = { .post_arg = 1},
  96. };
  97. #ifdef DEBUG
  98. static const char *cmdstr(enum gelic_eurus_command ix)
  99. {
  100. switch (ix) {
  101. case GELIC_EURUS_CMD_ASSOC:
  102. return "ASSOC";
  103. case GELIC_EURUS_CMD_DISASSOC:
  104. return "DISASSOC";
  105. case GELIC_EURUS_CMD_START_SCAN:
  106. return "SCAN";
  107. case GELIC_EURUS_CMD_GET_SCAN:
  108. return "GET SCAN";
  109. case GELIC_EURUS_CMD_SET_COMMON_CFG:
  110. return "SET_COMMON_CFG";
  111. case GELIC_EURUS_CMD_GET_COMMON_CFG:
  112. return "GET_COMMON_CFG";
  113. case GELIC_EURUS_CMD_SET_WEP_CFG:
  114. return "SET_WEP_CFG";
  115. case GELIC_EURUS_CMD_GET_WEP_CFG:
  116. return "GET_WEP_CFG";
  117. case GELIC_EURUS_CMD_SET_WPA_CFG:
  118. return "SET_WPA_CFG";
  119. case GELIC_EURUS_CMD_GET_WPA_CFG:
  120. return "GET_WPA_CFG";
  121. case GELIC_EURUS_CMD_GET_RSSI_CFG:
  122. return "GET_RSSI";
  123. default:
  124. break;
  125. }
  126. return "";
  127. };
  128. #else
  129. static inline const char *cmdstr(enum gelic_eurus_command ix)
  130. {
  131. return "";
  132. }
  133. #endif
  134. /* synchronously do eurus commands */
  135. static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
  136. {
  137. struct gelic_eurus_cmd *cmd;
  138. struct gelic_card *card;
  139. struct gelic_wl_info *wl;
  140. u64 arg1, arg2;
  141. pr_debug("%s: <-\n", __func__);
  142. cmd = container_of(work, struct gelic_eurus_cmd, work);
  143. BUG_ON(cmd_info[cmd->cmd].pre_arg &&
  144. cmd_info[cmd->cmd].post_arg);
  145. wl = cmd->wl;
  146. card = port_to_card(wl_port(wl));
  147. if (cmd_info[cmd->cmd].pre_arg) {
  148. arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
  149. arg2 = cmd->buf_size;
  150. } else {
  151. arg1 = 0;
  152. arg2 = 0;
  153. }
  154. init_completion(&wl->cmd_done_intr);
  155. pr_debug("%s: cmd='%s' start\n", __func__, cmdstr(cmd->cmd));
  156. cmd->status = lv1_net_control(bus_id(card), dev_id(card),
  157. GELIC_LV1_POST_WLAN_CMD,
  158. cmd->cmd, arg1, arg2,
  159. &cmd->tag, &cmd->size);
  160. if (cmd->status) {
  161. complete(&cmd->done);
  162. pr_info("%s: cmd issue failed\n", __func__);
  163. return;
  164. }
  165. wait_for_completion(&wl->cmd_done_intr);
  166. if (cmd_info[cmd->cmd].post_arg) {
  167. arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
  168. arg2 = cmd->buf_size;
  169. } else {
  170. arg1 = 0;
  171. arg2 = 0;
  172. }
  173. cmd->status = lv1_net_control(bus_id(card), dev_id(card),
  174. GELIC_LV1_GET_WLAN_CMD_RESULT,
  175. cmd->tag, arg1, arg2,
  176. &cmd->cmd_status, &cmd->size);
  177. #ifdef DEBUG
  178. if (cmd->status || cmd->cmd_status) {
  179. pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__,
  180. cmd->tag, arg1, arg2);
  181. pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
  182. __func__, cmd->status, cmd->cmd_status, cmd->size);
  183. }
  184. #endif
  185. complete(&cmd->done);
  186. pr_debug("%s: cmd='%s' done\n", __func__, cmdstr(cmd->cmd));
  187. }
  188. static struct gelic_eurus_cmd *gelic_eurus_sync_cmd(struct gelic_wl_info *wl,
  189. unsigned int eurus_cmd,
  190. void *buffer,
  191. unsigned int buf_size)
  192. {
  193. struct gelic_eurus_cmd *cmd;
  194. /* allocate cmd */
  195. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  196. if (!cmd)
  197. return NULL;
  198. /* initialize members */
  199. cmd->cmd = eurus_cmd;
  200. cmd->buffer = buffer;
  201. cmd->buf_size = buf_size;
  202. cmd->wl = wl;
  203. INIT_WORK(&cmd->work, gelic_eurus_sync_cmd_worker);
  204. init_completion(&cmd->done);
  205. queue_work(wl->eurus_cmd_queue, &cmd->work);
  206. /* wait for command completion */
  207. wait_for_completion(&cmd->done);
  208. return cmd;
  209. }
  210. static u32 gelic_wl_get_link(struct net_device *netdev)
  211. {
  212. struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
  213. u32 ret;
  214. pr_debug("%s: <-\n", __func__);
  215. mutex_lock(&wl->assoc_stat_lock);
  216. if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
  217. ret = 1;
  218. else
  219. ret = 0;
  220. mutex_unlock(&wl->assoc_stat_lock);
  221. pr_debug("%s: ->\n", __func__);
  222. return ret;
  223. }
  224. static void gelic_wl_send_iwap_event(struct gelic_wl_info *wl, u8 *bssid)
  225. {
  226. union iwreq_data data;
  227. memset(&data, 0, sizeof(data));
  228. if (bssid)
  229. memcpy(data.ap_addr.sa_data, bssid, ETH_ALEN);
  230. data.ap_addr.sa_family = ARPHRD_ETHER;
  231. wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWAP,
  232. &data, NULL);
  233. }
  234. /*
  235. * wireless extension handlers and helpers
  236. */
  237. /* SIOGIWNAME */
  238. static int gelic_wl_get_name(struct net_device *dev,
  239. struct iw_request_info *info,
  240. union iwreq_data *iwreq, char *extra)
  241. {
  242. strcpy(iwreq->name, "IEEE 802.11bg");
  243. return 0;
  244. }
  245. static void gelic_wl_get_ch_info(struct gelic_wl_info *wl)
  246. {
  247. struct gelic_card *card = port_to_card(wl_port(wl));
  248. u64 ch_info_raw, tmp;
  249. int status;
  250. if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO, &wl->stat)) {
  251. status = lv1_net_control(bus_id(card), dev_id(card),
  252. GELIC_LV1_GET_CHANNEL, 0, 0, 0,
  253. &ch_info_raw,
  254. &tmp);
  255. /* some fw versions may return error */
  256. if (status) {
  257. if (status != LV1_NO_ENTRY)
  258. pr_info("%s: available ch unknown\n", __func__);
  259. wl->ch_info = 0x07ff;/* 11 ch */
  260. } else
  261. /* 16 bits of MSB has available channels */
  262. wl->ch_info = ch_info_raw >> 48;
  263. }
  264. return;
  265. }
  266. /* SIOGIWRANGE */
  267. static int gelic_wl_get_range(struct net_device *netdev,
  268. struct iw_request_info *info,
  269. union iwreq_data *iwreq, char *extra)
  270. {
  271. struct iw_point *point = &iwreq->data;
  272. struct iw_range *range = (struct iw_range *)extra;
  273. struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
  274. unsigned int i, chs;
  275. pr_debug("%s: <-\n", __func__);
  276. point->length = sizeof(struct iw_range);
  277. memset(range, 0, sizeof(struct iw_range));
  278. range->we_version_compiled = WIRELESS_EXT;
  279. range->we_version_source = 22;
  280. /* available channels and frequencies */
  281. gelic_wl_get_ch_info(wl);
  282. for (i = 0, chs = 0;
  283. i < NUM_CHANNELS && chs < IW_MAX_FREQUENCIES; i++)
  284. if (wl->ch_info & (1 << i)) {
  285. range->freq[chs].i = i + 1;
  286. range->freq[chs].m = channel_freq[i];
  287. range->freq[chs].e = 6;
  288. chs++;
  289. }
  290. range->num_frequency = chs;
  291. range->old_num_frequency = chs;
  292. range->num_channels = chs;
  293. range->old_num_channels = chs;
  294. /* bitrates */
  295. for (i = 0; i < NUM_BITRATES; i++)
  296. range->bitrate[i] = bitrate_list[i];
  297. range->num_bitrates = i;
  298. /* signal levels */
  299. range->max_qual.qual = 100; /* relative value */
  300. range->max_qual.level = 100;
  301. range->avg_qual.qual = 50;
  302. range->avg_qual.level = 50;
  303. range->sensitivity = 0;
  304. /* Event capability */
  305. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  306. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  307. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  308. /* encryption capability */
  309. range->enc_capa = IW_ENC_CAPA_WPA |
  310. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  311. if (wpa2_capable())
  312. range->enc_capa |= IW_ENC_CAPA_WPA2;
  313. range->encoding_size[0] = 5; /* 40bit WEP */
  314. range->encoding_size[1] = 13; /* 104bit WEP */
  315. range->encoding_size[2] = 32; /* WPA-PSK */
  316. range->num_encoding_sizes = 3;
  317. range->max_encoding_tokens = GELIC_WEP_KEYS;
  318. pr_debug("%s: ->\n", __func__);
  319. return 0;
  320. }
  321. /* SIOC{G,S}IWSCAN */
  322. static int gelic_wl_set_scan(struct net_device *netdev,
  323. struct iw_request_info *info,
  324. union iwreq_data *wrqu, char *extra)
  325. {
  326. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  327. return gelic_wl_start_scan(wl, 1);
  328. }
  329. #define OUI_LEN 3
  330. static const u8 rsn_oui[OUI_LEN] = { 0x00, 0x0f, 0xac };
  331. static const u8 wpa_oui[OUI_LEN] = { 0x00, 0x50, 0xf2 };
  332. /*
  333. * synthesize WPA/RSN IE data
  334. * See WiFi WPA specification and IEEE 802.11-2007 7.3.2.25
  335. * for the format
  336. */
  337. static size_t gelic_wl_synthesize_ie(u8 *buf,
  338. struct gelic_eurus_scan_info *scan)
  339. {
  340. const u8 *oui_header;
  341. u8 *start = buf;
  342. int rsn;
  343. int ccmp;
  344. pr_debug("%s: <- sec=%16x\n", __func__, scan->security);
  345. switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_MASK) {
  346. case GELIC_EURUS_SCAN_SEC_WPA:
  347. rsn = 0;
  348. break;
  349. case GELIC_EURUS_SCAN_SEC_WPA2:
  350. rsn = 1;
  351. break;
  352. default:
  353. /* WEP or none. No IE returned */
  354. return 0;
  355. }
  356. switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_WPA_MASK) {
  357. case GELIC_EURUS_SCAN_SEC_WPA_TKIP:
  358. ccmp = 0;
  359. break;
  360. case GELIC_EURUS_SCAN_SEC_WPA_AES:
  361. ccmp = 1;
  362. break;
  363. default:
  364. if (rsn) {
  365. ccmp = 1;
  366. pr_info("%s: no cipher info. defaulted to CCMP\n",
  367. __func__);
  368. } else {
  369. ccmp = 0;
  370. pr_info("%s: no cipher info. defaulted to TKIP\n",
  371. __func__);
  372. }
  373. }
  374. if (rsn)
  375. oui_header = rsn_oui;
  376. else
  377. oui_header = wpa_oui;
  378. /* element id */
  379. if (rsn)
  380. *buf++ = MFIE_TYPE_RSN;
  381. else
  382. *buf++ = MFIE_TYPE_GENERIC;
  383. /* length filed; set later */
  384. buf++;
  385. /* wpa special header */
  386. if (!rsn) {
  387. memcpy(buf, wpa_oui, OUI_LEN);
  388. buf += OUI_LEN;
  389. *buf++ = 0x01;
  390. }
  391. /* version */
  392. *buf++ = 0x01; /* version 1.0 */
  393. *buf++ = 0x00;
  394. /* group cipher */
  395. memcpy(buf, oui_header, OUI_LEN);
  396. buf += OUI_LEN;
  397. if (ccmp)
  398. *buf++ = 0x04; /* CCMP */
  399. else
  400. *buf++ = 0x02; /* TKIP */
  401. /* pairwise key count always 1 */
  402. *buf++ = 0x01;
  403. *buf++ = 0x00;
  404. /* pairwise key suit */
  405. memcpy(buf, oui_header, OUI_LEN);
  406. buf += OUI_LEN;
  407. if (ccmp)
  408. *buf++ = 0x04; /* CCMP */
  409. else
  410. *buf++ = 0x02; /* TKIP */
  411. /* AKM count is 1 */
  412. *buf++ = 0x01;
  413. *buf++ = 0x00;
  414. /* AKM suite is assumed as PSK*/
  415. memcpy(buf, oui_header, OUI_LEN);
  416. buf += OUI_LEN;
  417. *buf++ = 0x02; /* PSK */
  418. /* RSN capabilities is 0 */
  419. *buf++ = 0x00;
  420. *buf++ = 0x00;
  421. /* set length field */
  422. start[1] = (buf - start - 2);
  423. pr_debug("%s: ->\n", __func__);
  424. return (buf - start);
  425. }
  426. struct ie_item {
  427. u8 *data;
  428. u8 len;
  429. };
  430. struct ie_info {
  431. struct ie_item wpa;
  432. struct ie_item rsn;
  433. };
  434. static void gelic_wl_parse_ie(u8 *data, size_t len,
  435. struct ie_info *ie_info)
  436. {
  437. size_t data_left = len;
  438. u8 *pos = data;
  439. u8 item_len;
  440. u8 item_id;
  441. pr_debug("%s: data=%p len=%ld \n", __func__,
  442. data, len);
  443. memset(ie_info, 0, sizeof(struct ie_info));
  444. while (2 <= data_left) {
  445. item_id = *pos++;
  446. item_len = *pos++;
  447. data_left -= 2;
  448. if (data_left < item_len)
  449. break;
  450. switch (item_id) {
  451. case MFIE_TYPE_GENERIC:
  452. if ((OUI_LEN + 1 <= item_len) &&
  453. !memcmp(pos, wpa_oui, OUI_LEN) &&
  454. pos[OUI_LEN] == 0x01) {
  455. ie_info->wpa.data = pos - 2;
  456. ie_info->wpa.len = item_len + 2;
  457. }
  458. break;
  459. case MFIE_TYPE_RSN:
  460. ie_info->rsn.data = pos - 2;
  461. /* length includes the header */
  462. ie_info->rsn.len = item_len + 2;
  463. break;
  464. default:
  465. pr_debug("%s: ignore %#x,%d\n", __func__,
  466. item_id, item_len);
  467. break;
  468. }
  469. pos += item_len;
  470. data_left -= item_len;
  471. }
  472. pr_debug("%s: wpa=%p,%d wpa2=%p,%d\n", __func__,
  473. ie_info->wpa.data, ie_info->wpa.len,
  474. ie_info->rsn.data, ie_info->rsn.len);
  475. }
  476. /*
  477. * translate the scan informations from hypervisor to a
  478. * independent format
  479. */
  480. static char *gelic_wl_translate_scan(struct net_device *netdev,
  481. char *ev,
  482. char *stop,
  483. struct gelic_wl_scan_info *network)
  484. {
  485. struct iw_event iwe;
  486. struct gelic_eurus_scan_info *scan = network->hwinfo;
  487. char *tmp;
  488. u8 rate;
  489. unsigned int i, j, len;
  490. u8 buf[MAX_WPA_IE_LEN];
  491. pr_debug("%s: <-\n", __func__);
  492. /* first entry should be AP's mac address */
  493. iwe.cmd = SIOCGIWAP;
  494. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  495. memcpy(iwe.u.ap_addr.sa_data, &scan->bssid[2], ETH_ALEN);
  496. ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_ADDR_LEN);
  497. /* ESSID */
  498. iwe.cmd = SIOCGIWESSID;
  499. iwe.u.data.flags = 1;
  500. iwe.u.data.length = strnlen(scan->essid, 32);
  501. ev = iwe_stream_add_point(ev, stop, &iwe, scan->essid);
  502. /* FREQUENCY */
  503. iwe.cmd = SIOCGIWFREQ;
  504. iwe.u.freq.m = be16_to_cpu(scan->channel);
  505. iwe.u.freq.e = 0; /* table value in MHz */
  506. iwe.u.freq.i = 0;
  507. ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_FREQ_LEN);
  508. /* RATES */
  509. iwe.cmd = SIOCGIWRATE;
  510. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  511. /* to stuff multiple values in one event */
  512. tmp = ev + IW_EV_LCP_LEN;
  513. /* put them in ascendant order (older is first) */
  514. i = 0;
  515. j = 0;
  516. pr_debug("%s: rates=%d rate=%d\n", __func__,
  517. network->rate_len, network->rate_ext_len);
  518. while (i < network->rate_len) {
  519. if (j < network->rate_ext_len &&
  520. ((scan->ext_rate[j] & 0x7f) < (scan->rate[i] & 0x7f)))
  521. rate = scan->ext_rate[j++] & 0x7f;
  522. else
  523. rate = scan->rate[i++] & 0x7f;
  524. iwe.u.bitrate.value = rate * 500000; /* 500kbps unit */
  525. tmp = iwe_stream_add_value(ev, tmp, stop, &iwe,
  526. IW_EV_PARAM_LEN);
  527. }
  528. while (j < network->rate_ext_len) {
  529. iwe.u.bitrate.value = (scan->ext_rate[j++] & 0x7f) * 500000;
  530. tmp = iwe_stream_add_value(ev, tmp, stop, &iwe,
  531. IW_EV_PARAM_LEN);
  532. }
  533. /* Check if we added any rate */
  534. if (IW_EV_LCP_LEN < (tmp - ev))
  535. ev = tmp;
  536. /* ENCODE */
  537. iwe.cmd = SIOCGIWENCODE;
  538. if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_PRIVACY)
  539. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  540. else
  541. iwe.u.data.flags = IW_ENCODE_DISABLED;
  542. iwe.u.data.length = 0;
  543. ev = iwe_stream_add_point(ev, stop, &iwe, scan->essid);
  544. /* MODE */
  545. iwe.cmd = SIOCGIWMODE;
  546. if (be16_to_cpu(scan->capability) &
  547. (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  548. if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_ESS)
  549. iwe.u.mode = IW_MODE_MASTER;
  550. else
  551. iwe.u.mode = IW_MODE_ADHOC;
  552. ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_UINT_LEN);
  553. }
  554. /* QUAL */
  555. iwe.cmd = IWEVQUAL;
  556. iwe.u.qual.updated = IW_QUAL_ALL_UPDATED |
  557. IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
  558. iwe.u.qual.level = be16_to_cpu(scan->rssi);
  559. iwe.u.qual.qual = be16_to_cpu(scan->rssi);
  560. iwe.u.qual.noise = 0;
  561. ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_QUAL_LEN);
  562. /* RSN */
  563. memset(&iwe, 0, sizeof(iwe));
  564. if (be16_to_cpu(scan->size) <= sizeof(*scan)) {
  565. /* If wpa[2] capable station, synthesize IE and put it */
  566. len = gelic_wl_synthesize_ie(buf, scan);
  567. if (len) {
  568. iwe.cmd = IWEVGENIE;
  569. iwe.u.data.length = len;
  570. ev = iwe_stream_add_point(ev, stop, &iwe, buf);
  571. }
  572. } else {
  573. /* this scan info has IE data */
  574. struct ie_info ie_info;
  575. size_t data_len;
  576. data_len = be16_to_cpu(scan->size) - sizeof(*scan);
  577. gelic_wl_parse_ie(scan->elements, data_len, &ie_info);
  578. if (ie_info.wpa.len && (ie_info.wpa.len <= sizeof(buf))) {
  579. memcpy(buf, ie_info.wpa.data, ie_info.wpa.len);
  580. iwe.cmd = IWEVGENIE;
  581. iwe.u.data.length = ie_info.wpa.len;
  582. ev = iwe_stream_add_point(ev, stop, &iwe, buf);
  583. }
  584. if (ie_info.rsn.len && (ie_info.rsn.len <= sizeof(buf))) {
  585. memset(&iwe, 0, sizeof(iwe));
  586. memcpy(buf, ie_info.rsn.data, ie_info.rsn.len);
  587. iwe.cmd = IWEVGENIE;
  588. iwe.u.data.length = ie_info.rsn.len;
  589. ev = iwe_stream_add_point(ev, stop, &iwe, buf);
  590. }
  591. }
  592. pr_debug("%s: ->\n", __func__);
  593. return ev;
  594. }
  595. static int gelic_wl_get_scan(struct net_device *netdev,
  596. struct iw_request_info *info,
  597. union iwreq_data *wrqu, char *extra)
  598. {
  599. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  600. struct gelic_wl_scan_info *scan_info;
  601. char *ev = extra;
  602. char *stop = ev + wrqu->data.length;
  603. int ret = 0;
  604. unsigned long this_time = jiffies;
  605. pr_debug("%s: <-\n", __func__);
  606. if (mutex_lock_interruptible(&wl->scan_lock))
  607. return -EAGAIN;
  608. switch (wl->scan_stat) {
  609. case GELIC_WL_SCAN_STAT_SCANNING:
  610. /* If a scan in progress, caller should call me again */
  611. ret = -EAGAIN;
  612. goto out;
  613. break;
  614. case GELIC_WL_SCAN_STAT_INIT:
  615. /* last scan request failed or never issued */
  616. ret = -ENODEV;
  617. goto out;
  618. break;
  619. case GELIC_WL_SCAN_STAT_GOT_LIST:
  620. /* ok, use current list */
  621. break;
  622. }
  623. list_for_each_entry(scan_info, &wl->network_list, list) {
  624. if (wl->scan_age == 0 ||
  625. time_after(scan_info->last_scanned + wl->scan_age,
  626. this_time))
  627. ev = gelic_wl_translate_scan(netdev, ev, stop,
  628. scan_info);
  629. else
  630. pr_debug("%s:entry too old\n", __func__);
  631. if (stop - ev <= IW_EV_ADDR_LEN) {
  632. ret = -E2BIG;
  633. goto out;
  634. }
  635. }
  636. wrqu->data.length = ev - extra;
  637. wrqu->data.flags = 0;
  638. out:
  639. mutex_unlock(&wl->scan_lock);
  640. pr_debug("%s: -> %d %d\n", __func__, ret, wrqu->data.length);
  641. return ret;
  642. }
  643. #ifdef DEBUG
  644. static void scan_list_dump(struct gelic_wl_info *wl)
  645. {
  646. struct gelic_wl_scan_info *scan_info;
  647. int i;
  648. DECLARE_MAC_BUF(mac);
  649. i = 0;
  650. list_for_each_entry(scan_info, &wl->network_list, list) {
  651. pr_debug("%s: item %d\n", __func__, i++);
  652. pr_debug("valid=%d eurusindex=%d last=%lx\n",
  653. scan_info->valid, scan_info->eurus_index,
  654. scan_info->last_scanned);
  655. pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
  656. scan_info->rate_len, scan_info->rate_ext_len,
  657. scan_info->essid_len);
  658. /* -- */
  659. pr_debug("bssid=%s\n",
  660. print_mac(mac, &scan_info->hwinfo->bssid[2]));
  661. pr_debug("essid=%s\n", scan_info->hwinfo->essid);
  662. }
  663. }
  664. #endif
  665. static int gelic_wl_set_auth(struct net_device *netdev,
  666. struct iw_request_info *info,
  667. union iwreq_data *data, char *extra)
  668. {
  669. struct iw_param *param = &data->param;
  670. struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
  671. unsigned long irqflag;
  672. int ret = 0;
  673. pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
  674. spin_lock_irqsave(&wl->lock, irqflag);
  675. switch (param->flags & IW_AUTH_INDEX) {
  676. case IW_AUTH_WPA_VERSION:
  677. if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
  678. pr_debug("%s: NO WPA selected\n", __func__);
  679. wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
  680. wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
  681. wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
  682. }
  683. if (param->value & IW_AUTH_WPA_VERSION_WPA) {
  684. pr_debug("%s: WPA version 1 selected\n", __func__);
  685. wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
  686. wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
  687. wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
  688. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  689. }
  690. if (param->value & IW_AUTH_WPA_VERSION_WPA2) {
  691. /*
  692. * As the hypervisor may not tell the cipher
  693. * information of the AP if it is WPA2,
  694. * you will not decide suitable cipher from
  695. * its beacon.
  696. * You should have knowledge about the AP's
  697. * cipher infomation in other method prior to
  698. * the association.
  699. */
  700. if (!precise_ie())
  701. pr_info("%s: WPA2 may not work\n", __func__);
  702. if (wpa2_capable()) {
  703. wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
  704. wl->group_cipher_method = GELIC_WL_CIPHER_AES;
  705. wl->pairwise_cipher_method =
  706. GELIC_WL_CIPHER_AES;
  707. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  708. } else
  709. ret = -EINVAL;
  710. }
  711. break;
  712. case IW_AUTH_CIPHER_PAIRWISE:
  713. if (param->value &
  714. (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
  715. pr_debug("%s: WEP selected\n", __func__);
  716. wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
  717. }
  718. if (param->value & IW_AUTH_CIPHER_TKIP) {
  719. pr_debug("%s: TKIP selected\n", __func__);
  720. wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
  721. }
  722. if (param->value & IW_AUTH_CIPHER_CCMP) {
  723. pr_debug("%s: CCMP selected\n", __func__);
  724. wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
  725. }
  726. if (param->value & IW_AUTH_CIPHER_NONE) {
  727. pr_debug("%s: no auth selected\n", __func__);
  728. wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
  729. }
  730. break;
  731. case IW_AUTH_CIPHER_GROUP:
  732. if (param->value &
  733. (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
  734. pr_debug("%s: WEP selected\n", __func__);
  735. wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
  736. }
  737. if (param->value & IW_AUTH_CIPHER_TKIP) {
  738. pr_debug("%s: TKIP selected\n", __func__);
  739. wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
  740. }
  741. if (param->value & IW_AUTH_CIPHER_CCMP) {
  742. pr_debug("%s: CCMP selected\n", __func__);
  743. wl->group_cipher_method = GELIC_WL_CIPHER_AES;
  744. }
  745. if (param->value & IW_AUTH_CIPHER_NONE) {
  746. pr_debug("%s: no auth selected\n", __func__);
  747. wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
  748. }
  749. break;
  750. case IW_AUTH_80211_AUTH_ALG:
  751. if (param->value & IW_AUTH_ALG_SHARED_KEY) {
  752. pr_debug("%s: shared key specified\n", __func__);
  753. wl->auth_method = GELIC_EURUS_AUTH_SHARED;
  754. } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  755. pr_debug("%s: open system specified\n", __func__);
  756. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  757. } else
  758. ret = -EINVAL;
  759. break;
  760. case IW_AUTH_WPA_ENABLED:
  761. if (param->value) {
  762. pr_debug("%s: WPA enabled\n", __func__);
  763. wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
  764. } else {
  765. pr_debug("%s: WPA disabled\n", __func__);
  766. wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
  767. }
  768. break;
  769. case IW_AUTH_KEY_MGMT:
  770. if (param->value & IW_AUTH_KEY_MGMT_PSK)
  771. break;
  772. /* intentionally fall through */
  773. default:
  774. ret = -EOPNOTSUPP;
  775. break;
  776. };
  777. if (!ret)
  778. set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
  779. spin_unlock_irqrestore(&wl->lock, irqflag);
  780. pr_debug("%s: -> %d\n", __func__, ret);
  781. return ret;
  782. }
  783. static int gelic_wl_get_auth(struct net_device *netdev,
  784. struct iw_request_info *info,
  785. union iwreq_data *iwreq, char *extra)
  786. {
  787. struct iw_param *param = &iwreq->param;
  788. struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
  789. unsigned long irqflag;
  790. int ret = 0;
  791. pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
  792. spin_lock_irqsave(&wl->lock, irqflag);
  793. switch (param->flags & IW_AUTH_INDEX) {
  794. case IW_AUTH_WPA_VERSION:
  795. switch (wl->wpa_level) {
  796. case GELIC_WL_WPA_LEVEL_WPA:
  797. param->value |= IW_AUTH_WPA_VERSION_WPA;
  798. break;
  799. case GELIC_WL_WPA_LEVEL_WPA2:
  800. param->value |= IW_AUTH_WPA_VERSION_WPA2;
  801. break;
  802. default:
  803. param->value |= IW_AUTH_WPA_VERSION_DISABLED;
  804. }
  805. break;
  806. case IW_AUTH_80211_AUTH_ALG:
  807. if (wl->auth_method == GELIC_EURUS_AUTH_SHARED)
  808. param->value = IW_AUTH_ALG_SHARED_KEY;
  809. else if (wl->auth_method == GELIC_EURUS_AUTH_OPEN)
  810. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  811. break;
  812. case IW_AUTH_WPA_ENABLED:
  813. switch (wl->wpa_level) {
  814. case GELIC_WL_WPA_LEVEL_WPA:
  815. case GELIC_WL_WPA_LEVEL_WPA2:
  816. param->value = 1;
  817. break;
  818. default:
  819. param->value = 0;
  820. break;
  821. }
  822. break;
  823. default:
  824. ret = -EOPNOTSUPP;
  825. }
  826. spin_unlock_irqrestore(&wl->lock, irqflag);
  827. pr_debug("%s: -> %d\n", __func__, ret);
  828. return ret;
  829. }
  830. /* SIOC{S,G}IWESSID */
  831. static int gelic_wl_set_essid(struct net_device *netdev,
  832. struct iw_request_info *info,
  833. union iwreq_data *data, char *extra)
  834. {
  835. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  836. unsigned long irqflag;
  837. pr_debug("%s: <- l=%d f=%d\n", __func__,
  838. data->essid.length, data->essid.flags);
  839. if (IW_ESSID_MAX_SIZE < data->essid.length)
  840. return -EINVAL;
  841. spin_lock_irqsave(&wl->lock, irqflag);
  842. if (data->essid.flags) {
  843. wl->essid_len = data->essid.length;
  844. memcpy(wl->essid, extra, wl->essid_len);
  845. pr_debug("%s: essid = '%s'\n", __func__, extra);
  846. set_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
  847. } else {
  848. pr_debug("%s: ESSID any \n", __func__);
  849. clear_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
  850. }
  851. set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
  852. spin_unlock_irqrestore(&wl->lock, irqflag);
  853. gelic_wl_try_associate(netdev); /* FIXME */
  854. pr_debug("%s: -> \n", __func__);
  855. return 0;
  856. }
  857. static int gelic_wl_get_essid(struct net_device *netdev,
  858. struct iw_request_info *info,
  859. union iwreq_data *data, char *extra)
  860. {
  861. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  862. unsigned long irqflag;
  863. pr_debug("%s: <- \n", __func__);
  864. mutex_lock(&wl->assoc_stat_lock);
  865. spin_lock_irqsave(&wl->lock, irqflag);
  866. if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat) ||
  867. wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
  868. memcpy(extra, wl->essid, wl->essid_len);
  869. data->essid.length = wl->essid_len;
  870. data->essid.flags = 1;
  871. } else
  872. data->essid.flags = 0;
  873. mutex_unlock(&wl->assoc_stat_lock);
  874. spin_unlock_irqrestore(&wl->lock, irqflag);
  875. pr_debug("%s: -> len=%d \n", __func__, data->essid.length);
  876. return 0;
  877. }
  878. /* SIO{S,G}IWENCODE */
  879. static int gelic_wl_set_encode(struct net_device *netdev,
  880. struct iw_request_info *info,
  881. union iwreq_data *data, char *extra)
  882. {
  883. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  884. struct iw_point *enc = &data->encoding;
  885. __u16 flags;
  886. unsigned int irqflag;
  887. int key_index, index_specified;
  888. int ret = 0;
  889. pr_debug("%s: <- \n", __func__);
  890. flags = enc->flags & IW_ENCODE_FLAGS;
  891. key_index = enc->flags & IW_ENCODE_INDEX;
  892. pr_debug("%s: key_index = %d\n", __func__, key_index);
  893. pr_debug("%s: key_len = %d\n", __func__, enc->length);
  894. pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
  895. if (GELIC_WEP_KEYS < key_index)
  896. return -EINVAL;
  897. spin_lock_irqsave(&wl->lock, irqflag);
  898. if (key_index) {
  899. index_specified = 1;
  900. key_index--;
  901. } else {
  902. index_specified = 0;
  903. key_index = wl->current_key;
  904. }
  905. if (flags & IW_ENCODE_NOKEY) {
  906. /* if just IW_ENCODE_NOKEY, change current key index */
  907. if (!flags && index_specified) {
  908. wl->current_key = key_index;
  909. goto done;
  910. }
  911. if (flags & IW_ENCODE_DISABLED) {
  912. if (!index_specified) {
  913. /* disable encryption */
  914. wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
  915. wl->pairwise_cipher_method =
  916. GELIC_WL_CIPHER_NONE;
  917. /* invalidate all key */
  918. wl->key_enabled = 0;
  919. } else
  920. clear_bit(key_index, &wl->key_enabled);
  921. }
  922. if (flags & IW_ENCODE_OPEN)
  923. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  924. if (flags & IW_ENCODE_RESTRICTED) {
  925. pr_info("%s: shared key mode enabled\n", __func__);
  926. wl->auth_method = GELIC_EURUS_AUTH_SHARED;
  927. }
  928. } else {
  929. if (IW_ENCODING_TOKEN_MAX < enc->length) {
  930. ret = -EINVAL;
  931. goto done;
  932. }
  933. wl->key_len[key_index] = enc->length;
  934. memcpy(wl->key[key_index], extra, enc->length);
  935. set_bit(key_index, &wl->key_enabled);
  936. wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
  937. wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
  938. }
  939. set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
  940. done:
  941. spin_unlock_irqrestore(&wl->lock, irqflag);
  942. pr_debug("%s: -> \n", __func__);
  943. return ret;
  944. }
  945. static int gelic_wl_get_encode(struct net_device *netdev,
  946. struct iw_request_info *info,
  947. union iwreq_data *data, char *extra)
  948. {
  949. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  950. struct iw_point *enc = &data->encoding;
  951. unsigned int irqflag;
  952. unsigned int key_index, index_specified;
  953. int ret = 0;
  954. pr_debug("%s: <- \n", __func__);
  955. key_index = enc->flags & IW_ENCODE_INDEX;
  956. pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
  957. enc->flags, enc->pointer, enc->length, extra);
  958. if (GELIC_WEP_KEYS < key_index)
  959. return -EINVAL;
  960. spin_lock_irqsave(&wl->lock, irqflag);
  961. if (key_index) {
  962. index_specified = 1;
  963. key_index--;
  964. } else {
  965. index_specified = 0;
  966. key_index = wl->current_key;
  967. }
  968. if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
  969. switch (wl->auth_method) {
  970. case GELIC_EURUS_AUTH_OPEN:
  971. enc->flags = IW_ENCODE_OPEN;
  972. break;
  973. case GELIC_EURUS_AUTH_SHARED:
  974. enc->flags = IW_ENCODE_RESTRICTED;
  975. break;
  976. }
  977. } else
  978. enc->flags = IW_ENCODE_DISABLED;
  979. if (test_bit(key_index, &wl->key_enabled)) {
  980. if (enc->length < wl->key_len[key_index]) {
  981. ret = -EINVAL;
  982. goto done;
  983. }
  984. enc->length = wl->key_len[key_index];
  985. memcpy(extra, wl->key[key_index], wl->key_len[key_index]);
  986. } else {
  987. enc->length = 0;
  988. enc->flags |= IW_ENCODE_NOKEY;
  989. }
  990. enc->flags |= key_index + 1;
  991. pr_debug("%s: -> flag=%x len=%d\n", __func__,
  992. enc->flags, enc->length);
  993. done:
  994. spin_unlock_irqrestore(&wl->lock, irqflag);
  995. return ret;
  996. }
  997. /* SIOC{S,G}IWAP */
  998. static int gelic_wl_set_ap(struct net_device *netdev,
  999. struct iw_request_info *info,
  1000. union iwreq_data *data, char *extra)
  1001. {
  1002. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  1003. unsigned long irqflag;
  1004. pr_debug("%s: <-\n", __func__);
  1005. if (data->ap_addr.sa_family != ARPHRD_ETHER)
  1006. return -EINVAL;
  1007. spin_lock_irqsave(&wl->lock, irqflag);
  1008. if (is_valid_ether_addr(data->ap_addr.sa_data)) {
  1009. memcpy(wl->bssid, data->ap_addr.sa_data,
  1010. ETH_ALEN);
  1011. set_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
  1012. set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
  1013. pr_debug("%s: bss=%02x:%02x:%02x:%02x:%02x:%02x\n",
  1014. __func__,
  1015. wl->bssid[0], wl->bssid[1],
  1016. wl->bssid[2], wl->bssid[3],
  1017. wl->bssid[4], wl->bssid[5]);
  1018. } else {
  1019. pr_debug("%s: clear bssid\n", __func__);
  1020. clear_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
  1021. memset(wl->bssid, 0, ETH_ALEN);
  1022. }
  1023. spin_unlock_irqrestore(&wl->lock, irqflag);
  1024. pr_debug("%s: ->\n", __func__);
  1025. return 0;
  1026. }
  1027. static int gelic_wl_get_ap(struct net_device *netdev,
  1028. struct iw_request_info *info,
  1029. union iwreq_data *data, char *extra)
  1030. {
  1031. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  1032. unsigned long irqflag;
  1033. pr_debug("%s: <-\n", __func__);
  1034. mutex_lock(&wl->assoc_stat_lock);
  1035. spin_lock_irqsave(&wl->lock, irqflag);
  1036. if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
  1037. data->ap_addr.sa_family = ARPHRD_ETHER;
  1038. memcpy(data->ap_addr.sa_data, wl->active_bssid,
  1039. ETH_ALEN);
  1040. } else
  1041. memset(data->ap_addr.sa_data, 0, ETH_ALEN);
  1042. spin_unlock_irqrestore(&wl->lock, irqflag);
  1043. mutex_unlock(&wl->assoc_stat_lock);
  1044. pr_debug("%s: ->\n", __func__);
  1045. return 0;
  1046. }
  1047. /* SIOC{S,G}IWENCODEEXT */
  1048. static int gelic_wl_set_encodeext(struct net_device *netdev,
  1049. struct iw_request_info *info,
  1050. union iwreq_data *data, char *extra)
  1051. {
  1052. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  1053. struct iw_point *enc = &data->encoding;
  1054. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1055. __u16 alg;
  1056. __u16 flags;
  1057. unsigned int irqflag;
  1058. int key_index;
  1059. int ret = 0;
  1060. pr_debug("%s: <- \n", __func__);
  1061. flags = enc->flags & IW_ENCODE_FLAGS;
  1062. alg = ext->alg;
  1063. key_index = enc->flags & IW_ENCODE_INDEX;
  1064. pr_debug("%s: key_index = %d\n", __func__, key_index);
  1065. pr_debug("%s: key_len = %d\n", __func__, enc->length);
  1066. pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
  1067. pr_debug("%s: ext_flag=%x\n", __func__, ext->ext_flags);
  1068. pr_debug("%s: ext_key_len=%x\n", __func__, ext->key_len);
  1069. if (GELIC_WEP_KEYS < key_index)
  1070. return -EINVAL;
  1071. spin_lock_irqsave(&wl->lock, irqflag);
  1072. if (key_index)
  1073. key_index--;
  1074. else
  1075. key_index = wl->current_key;
  1076. if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
  1077. /* reques to change default key index */
  1078. pr_debug("%s: request to change default key to %d\n",
  1079. __func__, key_index);
  1080. wl->current_key = key_index;
  1081. goto done;
  1082. }
  1083. if (alg == IW_ENCODE_ALG_NONE || (flags & IW_ENCODE_DISABLED)) {
  1084. pr_debug("%s: alg disabled\n", __func__);
  1085. wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
  1086. wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
  1087. wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
  1088. wl->auth_method = GELIC_EURUS_AUTH_OPEN; /* should be open */
  1089. } else if (alg == IW_ENCODE_ALG_WEP) {
  1090. pr_debug("%s: WEP requested\n", __func__);
  1091. if (flags & IW_ENCODE_OPEN) {
  1092. pr_debug("%s: open key mode\n", __func__);
  1093. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  1094. }
  1095. if (flags & IW_ENCODE_RESTRICTED) {
  1096. pr_debug("%s: shared key mode\n", __func__);
  1097. wl->auth_method = GELIC_EURUS_AUTH_SHARED;
  1098. }
  1099. if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
  1100. pr_info("%s: key is too long %d\n", __func__,
  1101. ext->key_len);
  1102. ret = -EINVAL;
  1103. goto done;
  1104. }
  1105. /* OK, update the key */
  1106. wl->key_len[key_index] = ext->key_len;
  1107. memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
  1108. memcpy(wl->key[key_index], ext->key, ext->key_len);
  1109. set_bit(key_index, &wl->key_enabled);
  1110. /* remember wep info changed */
  1111. set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
  1112. } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
  1113. pr_debug("%s: TKIP/CCMP requested alg=%d\n", __func__, alg);
  1114. /* check key length */
  1115. if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
  1116. pr_info("%s: key is too long %d\n", __func__,
  1117. ext->key_len);
  1118. ret = -EINVAL;
  1119. goto done;
  1120. }
  1121. if (alg == IW_ENCODE_ALG_CCMP) {
  1122. pr_debug("%s: AES selected\n", __func__);
  1123. wl->group_cipher_method = GELIC_WL_CIPHER_AES;
  1124. wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
  1125. wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
  1126. } else {
  1127. pr_debug("%s: TKIP selected, WPA forced\n", __func__);
  1128. wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
  1129. wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
  1130. /* FIXME: how do we do if WPA2 + TKIP? */
  1131. wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
  1132. }
  1133. if (flags & IW_ENCODE_RESTRICTED)
  1134. BUG();
  1135. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  1136. /* We should use same key for both and unicast */
  1137. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
  1138. pr_debug("%s: group key \n", __func__);
  1139. else
  1140. pr_debug("%s: unicast key \n", __func__);
  1141. /* OK, update the key */
  1142. wl->key_len[key_index] = ext->key_len;
  1143. memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
  1144. memcpy(wl->key[key_index], ext->key, ext->key_len);
  1145. set_bit(key_index, &wl->key_enabled);
  1146. /* remember info changed */
  1147. set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
  1148. }
  1149. done:
  1150. spin_unlock_irqrestore(&wl->lock, irqflag);
  1151. pr_debug("%s: -> \n", __func__);
  1152. return ret;
  1153. }
  1154. static int gelic_wl_get_encodeext(struct net_device *netdev,
  1155. struct iw_request_info *info,
  1156. union iwreq_data *data, char *extra)
  1157. {
  1158. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  1159. struct iw_point *enc = &data->encoding;
  1160. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1161. unsigned int irqflag;
  1162. int key_index;
  1163. int ret = 0;
  1164. int max_key_len;
  1165. pr_debug("%s: <- \n", __func__);
  1166. max_key_len = enc->length - sizeof(struct iw_encode_ext);
  1167. if (max_key_len < 0)
  1168. return -EINVAL;
  1169. key_index = enc->flags & IW_ENCODE_INDEX;
  1170. pr_debug("%s: key_index = %d\n", __func__, key_index);
  1171. pr_debug("%s: key_len = %d\n", __func__, enc->length);
  1172. pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
  1173. if (GELIC_WEP_KEYS < key_index)
  1174. return -EINVAL;
  1175. spin_lock_irqsave(&wl->lock, irqflag);
  1176. if (key_index)
  1177. key_index--;
  1178. else
  1179. key_index = wl->current_key;
  1180. memset(ext, 0, sizeof(struct iw_encode_ext));
  1181. switch (wl->group_cipher_method) {
  1182. case GELIC_WL_CIPHER_WEP:
  1183. ext->alg = IW_ENCODE_ALG_WEP;
  1184. enc->flags |= IW_ENCODE_ENABLED;
  1185. break;
  1186. case GELIC_WL_CIPHER_TKIP:
  1187. ext->alg = IW_ENCODE_ALG_TKIP;
  1188. enc->flags |= IW_ENCODE_ENABLED;
  1189. break;
  1190. case GELIC_WL_CIPHER_AES:
  1191. ext->alg = IW_ENCODE_ALG_CCMP;
  1192. enc->flags |= IW_ENCODE_ENABLED;
  1193. break;
  1194. case GELIC_WL_CIPHER_NONE:
  1195. default:
  1196. ext->alg = IW_ENCODE_ALG_NONE;
  1197. enc->flags |= IW_ENCODE_NOKEY;
  1198. break;
  1199. }
  1200. if (!(enc->flags & IW_ENCODE_NOKEY)) {
  1201. if (max_key_len < wl->key_len[key_index]) {
  1202. ret = -E2BIG;
  1203. goto out;
  1204. }
  1205. if (test_bit(key_index, &wl->key_enabled))
  1206. memcpy(ext->key, wl->key[key_index],
  1207. wl->key_len[key_index]);
  1208. else
  1209. pr_debug("%s: disabled key requested ix=%d\n",
  1210. __func__, key_index);
  1211. }
  1212. out:
  1213. spin_unlock_irqrestore(&wl->lock, irqflag);
  1214. pr_debug("%s: -> \n", __func__);
  1215. return ret;
  1216. }
  1217. /* SIOC{S,G}IWMODE */
  1218. static int gelic_wl_set_mode(struct net_device *netdev,
  1219. struct iw_request_info *info,
  1220. union iwreq_data *data, char *extra)
  1221. {
  1222. __u32 mode = data->mode;
  1223. int ret;
  1224. pr_debug("%s: <- \n", __func__);
  1225. if (mode == IW_MODE_INFRA)
  1226. ret = 0;
  1227. else
  1228. ret = -EOPNOTSUPP;
  1229. pr_debug("%s: -> %d\n", __func__, ret);
  1230. return ret;
  1231. }
  1232. static int gelic_wl_get_mode(struct net_device *netdev,
  1233. struct iw_request_info *info,
  1234. union iwreq_data *data, char *extra)
  1235. {
  1236. __u32 *mode = &data->mode;
  1237. pr_debug("%s: <- \n", __func__);
  1238. *mode = IW_MODE_INFRA;
  1239. pr_debug("%s: ->\n", __func__);
  1240. return 0;
  1241. }
  1242. /* SIOCIWFIRSTPRIV */
  1243. static int hex2bin(u8 *str, u8 *bin, unsigned int len)
  1244. {
  1245. unsigned int i;
  1246. static unsigned char *hex = "0123456789ABCDEF";
  1247. unsigned char *p, *q;
  1248. u8 tmp;
  1249. if (len != WPA_PSK_LEN * 2)
  1250. return -EINVAL;
  1251. for (i = 0; i < WPA_PSK_LEN * 2; i += 2) {
  1252. p = strchr(hex, toupper(str[i]));
  1253. q = strchr(hex, toupper(str[i + 1]));
  1254. if (!p || !q) {
  1255. pr_info("%s: unconvertible PSK digit=%d\n",
  1256. __func__, i);
  1257. return -EINVAL;
  1258. }
  1259. tmp = ((p - hex) << 4) + (q - hex);
  1260. *bin++ = tmp;
  1261. }
  1262. return 0;
  1263. };
  1264. static int gelic_wl_priv_set_psk(struct net_device *net_dev,
  1265. struct iw_request_info *info,
  1266. union iwreq_data *data, char *extra)
  1267. {
  1268. struct gelic_wl_info *wl = port_wl(netdev_priv(net_dev));
  1269. unsigned int len;
  1270. unsigned int irqflag;
  1271. int ret = 0;
  1272. pr_debug("%s:<- len=%d\n", __func__, data->data.length);
  1273. len = data->data.length - 1;
  1274. if (len <= 2)
  1275. return -EINVAL;
  1276. spin_lock_irqsave(&wl->lock, irqflag);
  1277. if (extra[0] == '"' && extra[len - 1] == '"') {
  1278. pr_debug("%s: passphrase mode\n", __func__);
  1279. /* pass phrase */
  1280. if (GELIC_WL_EURUS_PSK_MAX_LEN < (len - 2)) {
  1281. pr_info("%s: passphrase too long\n", __func__);
  1282. ret = -E2BIG;
  1283. goto out;
  1284. }
  1285. memset(wl->psk, 0, sizeof(wl->psk));
  1286. wl->psk_len = len - 2;
  1287. memcpy(wl->psk, &(extra[1]), wl->psk_len);
  1288. wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
  1289. } else {
  1290. ret = hex2bin(extra, wl->psk, len);
  1291. if (ret)
  1292. goto out;
  1293. wl->psk_len = WPA_PSK_LEN;
  1294. wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
  1295. }
  1296. set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
  1297. out:
  1298. spin_unlock_irqrestore(&wl->lock, irqflag);
  1299. pr_debug("%s:->\n", __func__);
  1300. return ret;
  1301. }
  1302. static int gelic_wl_priv_get_psk(struct net_device *net_dev,
  1303. struct iw_request_info *info,
  1304. union iwreq_data *data, char *extra)
  1305. {
  1306. struct gelic_wl_info *wl = port_wl(netdev_priv(net_dev));
  1307. char *p;
  1308. unsigned int irqflag;
  1309. unsigned int i;
  1310. pr_debug("%s:<-\n", __func__);
  1311. if (!capable(CAP_NET_ADMIN))
  1312. return -EPERM;
  1313. spin_lock_irqsave(&wl->lock, irqflag);
  1314. p = extra;
  1315. if (test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat)) {
  1316. if (wl->psk_type == GELIC_EURUS_WPA_PSK_BIN) {
  1317. for (i = 0; i < wl->psk_len; i++) {
  1318. sprintf(p, "%02xu", wl->psk[i]);
  1319. p += 2;
  1320. }
  1321. *p = '\0';
  1322. data->data.length = wl->psk_len * 2;
  1323. } else {
  1324. *p++ = '"';
  1325. memcpy(p, wl->psk, wl->psk_len);
  1326. p += wl->psk_len;
  1327. *p++ = '"';
  1328. *p = '\0';
  1329. data->data.length = wl->psk_len + 2;
  1330. }
  1331. } else
  1332. /* no psk set */
  1333. data->data.length = 0;
  1334. spin_unlock_irqrestore(&wl->lock, irqflag);
  1335. pr_debug("%s:-> %d\n", __func__, data->data.length);
  1336. return 0;
  1337. }
  1338. /* SIOCGIWNICKN */
  1339. static int gelic_wl_get_nick(struct net_device *net_dev,
  1340. struct iw_request_info *info,
  1341. union iwreq_data *data, char *extra)
  1342. {
  1343. strcpy(extra, "gelic_wl");
  1344. data->data.length = strlen(extra);
  1345. data->data.flags = 1;
  1346. return 0;
  1347. }
  1348. /* --- */
  1349. static struct iw_statistics *gelic_wl_get_wireless_stats(
  1350. struct net_device *netdev)
  1351. {
  1352. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  1353. struct gelic_eurus_cmd *cmd;
  1354. struct iw_statistics *is;
  1355. struct gelic_eurus_rssi_info *rssi;
  1356. void *buf;
  1357. pr_debug("%s: <-\n", __func__);
  1358. buf = (void *)__get_free_page(GFP_KERNEL);
  1359. if (!buf)
  1360. return NULL;
  1361. is = &wl->iwstat;
  1362. memset(is, 0, sizeof(*is));
  1363. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
  1364. buf, sizeof(*rssi));
  1365. if (cmd && !cmd->status && !cmd->cmd_status) {
  1366. rssi = buf;
  1367. is->qual.level = be16_to_cpu(rssi->rssi);
  1368. is->qual.updated = IW_QUAL_LEVEL_UPDATED |
  1369. IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
  1370. } else
  1371. /* not associated */
  1372. is->qual.updated = IW_QUAL_ALL_INVALID;
  1373. kfree(cmd);
  1374. free_page((unsigned long)buf);
  1375. pr_debug("%s: ->\n", __func__);
  1376. return is;
  1377. }
  1378. /*
  1379. * scanning helpers
  1380. */
  1381. static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan)
  1382. {
  1383. struct gelic_eurus_cmd *cmd;
  1384. int ret = 0;
  1385. pr_debug("%s: <- always=%d\n", __func__, always_scan);
  1386. if (mutex_lock_interruptible(&wl->scan_lock))
  1387. return -ERESTARTSYS;
  1388. /*
  1389. * If already a scan in progress, do not trigger more
  1390. */
  1391. if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING) {
  1392. pr_debug("%s: scanning now\n", __func__);
  1393. goto out;
  1394. }
  1395. init_completion(&wl->scan_done);
  1396. /*
  1397. * If we have already a bss list, don't try to get new
  1398. */
  1399. if (!always_scan && wl->scan_stat == GELIC_WL_SCAN_STAT_GOT_LIST) {
  1400. pr_debug("%s: already has the list\n", __func__);
  1401. complete(&wl->scan_done);
  1402. goto out;
  1403. }
  1404. /*
  1405. * issue start scan request
  1406. */
  1407. wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
  1408. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
  1409. NULL, 0);
  1410. if (!cmd || cmd->status || cmd->cmd_status) {
  1411. wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
  1412. complete(&wl->scan_done);
  1413. ret = -ENOMEM;
  1414. goto out;
  1415. }
  1416. kfree(cmd);
  1417. out:
  1418. mutex_unlock(&wl->scan_lock);
  1419. pr_debug("%s: ->\n", __func__);
  1420. return ret;
  1421. }
  1422. /*
  1423. * retrieve scan result from the chip (hypervisor)
  1424. * this function is invoked by schedule work.
  1425. */
  1426. static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
  1427. {
  1428. struct gelic_eurus_cmd *cmd = NULL;
  1429. struct gelic_wl_scan_info *target, *tmp;
  1430. struct gelic_wl_scan_info *oldest = NULL;
  1431. struct gelic_eurus_scan_info *scan_info;
  1432. unsigned int scan_info_size;
  1433. union iwreq_data data;
  1434. unsigned long this_time = jiffies;
  1435. unsigned int data_len, i, found, r;
  1436. void *buf;
  1437. DECLARE_MAC_BUF(mac);
  1438. pr_debug("%s:start\n", __func__);
  1439. mutex_lock(&wl->scan_lock);
  1440. buf = (void *)__get_free_page(GFP_KERNEL);
  1441. if (!buf) {
  1442. pr_info("%s: scan buffer alloc failed\n", __func__);
  1443. goto out;
  1444. }
  1445. if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
  1446. /*
  1447. * stop() may be called while scanning, ignore result
  1448. */
  1449. pr_debug("%s: scan complete when stat != scanning(%d)\n",
  1450. __func__, wl->scan_stat);
  1451. goto out;
  1452. }
  1453. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
  1454. buf, PAGE_SIZE);
  1455. if (!cmd || cmd->status || cmd->cmd_status) {
  1456. wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
  1457. pr_info("%s:cmd failed\n", __func__);
  1458. kfree(cmd);
  1459. goto out;
  1460. }
  1461. data_len = cmd->size;
  1462. pr_debug("%s: data_len = %d\n", __func__, data_len);
  1463. kfree(cmd);
  1464. /* OK, bss list retrieved */
  1465. wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST;
  1466. /* mark all entries are old */
  1467. list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
  1468. target->valid = 0;
  1469. /* expire too old entries */
  1470. if (time_before(target->last_scanned + wl->scan_age,
  1471. this_time)) {
  1472. kfree(target->hwinfo);
  1473. target->hwinfo = NULL;
  1474. list_move_tail(&target->list, &wl->network_free_list);
  1475. }
  1476. }
  1477. /* put them in the newtork_list */
  1478. for (i = 0, scan_info_size = 0, scan_info = buf;
  1479. scan_info_size < data_len;
  1480. i++, scan_info_size += be16_to_cpu(scan_info->size),
  1481. scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
  1482. pr_debug("%s:size=%d bssid=%s scan_info=%p\n", __func__,
  1483. be16_to_cpu(scan_info->size),
  1484. print_mac(mac, &scan_info->bssid[2]), scan_info);
  1485. /*
  1486. * The wireless firmware may return invalid channel 0 and/or
  1487. * invalid rate if the AP emits zero length SSID ie. As this
  1488. * scan information is useless, ignore it
  1489. */
  1490. if (!be16_to_cpu(scan_info->channel) || !scan_info->rate[0]) {
  1491. pr_debug("%s: invalid scan info\n", __func__);
  1492. continue;
  1493. }
  1494. found = 0;
  1495. oldest = NULL;
  1496. list_for_each_entry(target, &wl->network_list, list) {
  1497. if (!compare_ether_addr(&target->hwinfo->bssid[2],
  1498. &scan_info->bssid[2])) {
  1499. found = 1;
  1500. pr_debug("%s: same BBS found scanned list\n",
  1501. __func__);
  1502. break;
  1503. }
  1504. if (!oldest ||
  1505. (target->last_scanned < oldest->last_scanned))
  1506. oldest = target;
  1507. }
  1508. if (!found) {
  1509. /* not found in the list */
  1510. if (list_empty(&wl->network_free_list)) {
  1511. /* expire oldest */
  1512. target = oldest;
  1513. } else {
  1514. target = list_entry(wl->network_free_list.next,
  1515. struct gelic_wl_scan_info,
  1516. list);
  1517. }
  1518. }
  1519. /* update the item */
  1520. target->last_scanned = this_time;
  1521. target->valid = 1;
  1522. target->eurus_index = i;
  1523. kfree(target->hwinfo);
  1524. target->hwinfo = kzalloc(be16_to_cpu(scan_info->size),
  1525. GFP_KERNEL);
  1526. if (!target->hwinfo) {
  1527. pr_info("%s: kzalloc failed\n", __func__);
  1528. continue;
  1529. }
  1530. /* copy hw scan info */
  1531. memcpy(target->hwinfo, scan_info, scan_info->size);
  1532. target->essid_len = strnlen(scan_info->essid,
  1533. sizeof(scan_info->essid));
  1534. target->rate_len = 0;
  1535. for (r = 0; r < MAX_RATES_LENGTH; r++)
  1536. if (scan_info->rate[r])
  1537. target->rate_len++;
  1538. if (8 < target->rate_len)
  1539. pr_info("%s: AP returns %d rates\n", __func__,
  1540. target->rate_len);
  1541. target->rate_ext_len = 0;
  1542. for (r = 0; r < MAX_RATES_EX_LENGTH; r++)
  1543. if (scan_info->ext_rate[r])
  1544. target->rate_ext_len++;
  1545. list_move_tail(&target->list, &wl->network_list);
  1546. }
  1547. memset(&data, 0, sizeof(data));
  1548. wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
  1549. NULL);
  1550. out:
  1551. free_page((unsigned long)buf);
  1552. complete(&wl->scan_done);
  1553. mutex_unlock(&wl->scan_lock);
  1554. pr_debug("%s:end\n", __func__);
  1555. }
  1556. /*
  1557. * Select an appropriate bss from current scan list regarding
  1558. * current settings from userspace.
  1559. * The caller must hold wl->scan_lock,
  1560. * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
  1561. */
  1562. static void update_best(struct gelic_wl_scan_info **best,
  1563. struct gelic_wl_scan_info *candid,
  1564. int *best_weight,
  1565. int *weight)
  1566. {
  1567. if (*best_weight < ++(*weight)) {
  1568. *best_weight = *weight;
  1569. *best = candid;
  1570. }
  1571. }
  1572. static
  1573. struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
  1574. {
  1575. struct gelic_wl_scan_info *scan_info;
  1576. struct gelic_wl_scan_info *best_bss;
  1577. int weight, best_weight;
  1578. u16 security;
  1579. DECLARE_MAC_BUF(mac);
  1580. pr_debug("%s: <-\n", __func__);
  1581. best_bss = NULL;
  1582. best_weight = 0;
  1583. list_for_each_entry(scan_info, &wl->network_list, list) {
  1584. pr_debug("%s: station %p\n", __func__, scan_info);
  1585. if (!scan_info->valid) {
  1586. pr_debug("%s: station invalid\n", __func__);
  1587. continue;
  1588. }
  1589. /* If bss specified, check it only */
  1590. if (test_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat)) {
  1591. if (!compare_ether_addr(&scan_info->hwinfo->bssid[2],
  1592. wl->bssid)) {
  1593. best_bss = scan_info;
  1594. pr_debug("%s: bssid matched\n", __func__);
  1595. break;
  1596. } else {
  1597. pr_debug("%s: bssid unmached\n", __func__);
  1598. continue;
  1599. }
  1600. }
  1601. weight = 0;
  1602. /* security */
  1603. security = be16_to_cpu(scan_info->hwinfo->security) &
  1604. GELIC_EURUS_SCAN_SEC_MASK;
  1605. if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
  1606. if (security == GELIC_EURUS_SCAN_SEC_WPA2)
  1607. update_best(&best_bss, scan_info,
  1608. &best_weight, &weight);
  1609. else
  1610. continue;
  1611. } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA) {
  1612. if (security == GELIC_EURUS_SCAN_SEC_WPA)
  1613. update_best(&best_bss, scan_info,
  1614. &best_weight, &weight);
  1615. else
  1616. continue;
  1617. } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_NONE &&
  1618. wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
  1619. if (security == GELIC_EURUS_SCAN_SEC_WEP)
  1620. update_best(&best_bss, scan_info,
  1621. &best_weight, &weight);
  1622. else
  1623. continue;
  1624. }
  1625. /* If ESSID is set, check it */
  1626. if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
  1627. if ((scan_info->essid_len == wl->essid_len) &&
  1628. !strncmp(wl->essid,
  1629. scan_info->hwinfo->essid,
  1630. scan_info->essid_len))
  1631. update_best(&best_bss, scan_info,
  1632. &best_weight, &weight);
  1633. else
  1634. continue;
  1635. }
  1636. }
  1637. #ifdef DEBUG
  1638. pr_debug("%s: -> bss=%p\n", __func__, best_bss);
  1639. if (best_bss) {
  1640. pr_debug("%s:addr=%s\n", __func__,
  1641. print_mac(mac, &best_bss->hwinfo->bssid[2]));
  1642. }
  1643. #endif
  1644. return best_bss;
  1645. }
  1646. /*
  1647. * Setup WEP configuration to the chip
  1648. * The caller must hold wl->scan_lock,
  1649. * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
  1650. */
  1651. static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
  1652. {
  1653. unsigned int i;
  1654. struct gelic_eurus_wep_cfg *wep;
  1655. struct gelic_eurus_cmd *cmd;
  1656. int wep104 = 0;
  1657. int have_key = 0;
  1658. int ret = 0;
  1659. pr_debug("%s: <-\n", __func__);
  1660. /* we can assume no one should uses the buffer */
  1661. wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
  1662. if (!wep)
  1663. return -ENOMEM;
  1664. memset(wep, 0, sizeof(*wep));
  1665. if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
  1666. pr_debug("%s: WEP mode\n", __func__);
  1667. for (i = 0; i < GELIC_WEP_KEYS; i++) {
  1668. if (!test_bit(i, &wl->key_enabled))
  1669. continue;
  1670. pr_debug("%s: key#%d enabled\n", __func__, i);
  1671. have_key = 1;
  1672. if (wl->key_len[i] == 13)
  1673. wep104 = 1;
  1674. else if (wl->key_len[i] != 5) {
  1675. pr_info("%s: wrong wep key[%d]=%d\n",
  1676. __func__, i, wl->key_len[i]);
  1677. ret = -EINVAL;
  1678. goto out;
  1679. }
  1680. memcpy(wep->key[i], wl->key[i], wl->key_len[i]);
  1681. }
  1682. if (!have_key) {
  1683. pr_info("%s: all wep key disabled\n", __func__);
  1684. ret = -EINVAL;
  1685. goto out;
  1686. }
  1687. if (wep104) {
  1688. pr_debug("%s: 104bit key\n", __func__);
  1689. wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT);
  1690. } else {
  1691. pr_debug("%s: 40bit key\n", __func__);
  1692. wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT);
  1693. }
  1694. } else {
  1695. pr_debug("%s: NO encryption\n", __func__);
  1696. wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE);
  1697. }
  1698. /* issue wep setup */
  1699. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WEP_CFG,
  1700. wep, sizeof(*wep));
  1701. if (!cmd)
  1702. ret = -ENOMEM;
  1703. else if (cmd->status || cmd->cmd_status)
  1704. ret = -ENXIO;
  1705. kfree(cmd);
  1706. out:
  1707. free_page((unsigned long)wep);
  1708. pr_debug("%s: ->\n", __func__);
  1709. return ret;
  1710. }
  1711. #ifdef DEBUG
  1712. static const char *wpasecstr(enum gelic_eurus_wpa_security sec)
  1713. {
  1714. switch (sec) {
  1715. case GELIC_EURUS_WPA_SEC_NONE:
  1716. return "NONE";
  1717. break;
  1718. case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP:
  1719. return "WPA_TKIP_TKIP";
  1720. break;
  1721. case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES:
  1722. return "WPA_TKIP_AES";
  1723. break;
  1724. case GELIC_EURUS_WPA_SEC_WPA_AES_AES:
  1725. return "WPA_AES_AES";
  1726. break;
  1727. case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP:
  1728. return "WPA2_TKIP_TKIP";
  1729. break;
  1730. case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES:
  1731. return "WPA2_TKIP_AES";
  1732. break;
  1733. case GELIC_EURUS_WPA_SEC_WPA2_AES_AES:
  1734. return "WPA2_AES_AES";
  1735. break;
  1736. }
  1737. return "";
  1738. };
  1739. #endif
  1740. static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
  1741. {
  1742. struct gelic_eurus_wpa_cfg *wpa;
  1743. struct gelic_eurus_cmd *cmd;
  1744. u16 security;
  1745. int ret = 0;
  1746. pr_debug("%s: <-\n", __func__);
  1747. /* we can assume no one should uses the buffer */
  1748. wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
  1749. if (!wpa)
  1750. return -ENOMEM;
  1751. memset(wpa, 0, sizeof(*wpa));
  1752. if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
  1753. pr_info("%s: PSK not configured yet\n", __func__);
  1754. /* copy key */
  1755. memcpy(wpa->psk, wl->psk, wl->psk_len);
  1756. /* set security level */
  1757. if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
  1758. if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
  1759. security = GELIC_EURUS_WPA_SEC_WPA2_AES_AES;
  1760. } else {
  1761. if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
  1762. precise_ie())
  1763. security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES;
  1764. else
  1765. security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP;
  1766. }
  1767. } else {
  1768. if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
  1769. security = GELIC_EURUS_WPA_SEC_WPA_AES_AES;
  1770. } else {
  1771. if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
  1772. precise_ie())
  1773. security = GELIC_EURUS_WPA_SEC_WPA_TKIP_AES;
  1774. else
  1775. security = GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP;
  1776. }
  1777. }
  1778. wpa->security = cpu_to_be16(security);
  1779. /* PSK type */
  1780. wpa->psk_type = cpu_to_be16(wl->psk_type);
  1781. #ifdef DEBUG
  1782. pr_debug("%s: sec=%s psktype=%s\nn", __func__,
  1783. wpasecstr(wpa->security),
  1784. (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
  1785. "BIN" : "passphrase");
  1786. #if 0
  1787. /*
  1788. * don't enable here if you plan to submit
  1789. * the debug log because this dumps your precious
  1790. * passphrase/key.
  1791. */
  1792. pr_debug("%s: psk=%s\n",
  1793. (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
  1794. (char *)"N/A" : (char *)wpa->psk);
  1795. #endif
  1796. #endif
  1797. /* issue wpa setup */
  1798. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WPA_CFG,
  1799. wpa, sizeof(*wpa));
  1800. if (!cmd)
  1801. ret = -ENOMEM;
  1802. else if (cmd->status || cmd->cmd_status)
  1803. ret = -ENXIO;
  1804. kfree(cmd);
  1805. free_page((unsigned long)wpa);
  1806. pr_debug("%s: --> %d\n", __func__, ret);
  1807. return ret;
  1808. }
  1809. /*
  1810. * Start association. caller must hold assoc_stat_lock
  1811. */
  1812. static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
  1813. struct gelic_wl_scan_info *bss)
  1814. {
  1815. struct gelic_eurus_cmd *cmd;
  1816. struct gelic_eurus_common_cfg *common;
  1817. int ret = 0;
  1818. unsigned long rc;
  1819. pr_debug("%s: <-\n", __func__);
  1820. /* do common config */
  1821. common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
  1822. if (!common)
  1823. return -ENOMEM;
  1824. memset(common, 0, sizeof(*common));
  1825. common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
  1826. common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
  1827. common->scan_index = cpu_to_be16(bss->eurus_index);
  1828. switch (wl->auth_method) {
  1829. case GELIC_EURUS_AUTH_OPEN:
  1830. common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_OPEN);
  1831. break;
  1832. case GELIC_EURUS_AUTH_SHARED:
  1833. common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_SHARED);
  1834. break;
  1835. }
  1836. #ifdef DEBUG
  1837. scan_list_dump(wl);
  1838. #endif
  1839. pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
  1840. be16_to_cpu(common->scan_index),
  1841. be16_to_cpu(common->bss_type),
  1842. be16_to_cpu(common->auth_method));
  1843. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_COMMON_CFG,
  1844. common, sizeof(*common));
  1845. if (!cmd || cmd->status || cmd->cmd_status) {
  1846. ret = -ENOMEM;
  1847. kfree(cmd);
  1848. goto out;
  1849. }
  1850. kfree(cmd);
  1851. /* WEP/WPA */
  1852. switch (wl->wpa_level) {
  1853. case GELIC_WL_WPA_LEVEL_NONE:
  1854. /* If WEP or no security, setup WEP config */
  1855. ret = gelic_wl_do_wep_setup(wl);
  1856. break;
  1857. case GELIC_WL_WPA_LEVEL_WPA:
  1858. case GELIC_WL_WPA_LEVEL_WPA2:
  1859. ret = gelic_wl_do_wpa_setup(wl);
  1860. break;
  1861. };
  1862. if (ret) {
  1863. pr_debug("%s: WEP/WPA setup failed %d\n", __func__,
  1864. ret);
  1865. }
  1866. /* start association */
  1867. init_completion(&wl->assoc_done);
  1868. wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATING;
  1869. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_ASSOC,
  1870. NULL, 0);
  1871. if (!cmd || cmd->status || cmd->cmd_status) {
  1872. pr_debug("%s: assoc request failed\n", __func__);
  1873. wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
  1874. kfree(cmd);
  1875. ret = -ENOMEM;
  1876. gelic_wl_send_iwap_event(wl, NULL);
  1877. goto out;
  1878. }
  1879. kfree(cmd);
  1880. /* wait for connected event */
  1881. rc = wait_for_completion_timeout(&wl->assoc_done, HZ * 4);/*FIXME*/
  1882. if (!rc) {
  1883. /* timeouted. Maybe key or cyrpt mode is wrong */
  1884. pr_info("%s: connect timeout \n", __func__);
  1885. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC,
  1886. NULL, 0);
  1887. kfree(cmd);
  1888. wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
  1889. gelic_wl_send_iwap_event(wl, NULL);
  1890. ret = -ENXIO;
  1891. } else {
  1892. wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATED;
  1893. /* copy bssid */
  1894. memcpy(wl->active_bssid, &bss->hwinfo->bssid[2], ETH_ALEN);
  1895. /* send connect event */
  1896. gelic_wl_send_iwap_event(wl, wl->active_bssid);
  1897. pr_info("%s: connected\n", __func__);
  1898. }
  1899. out:
  1900. free_page((unsigned long)common);
  1901. pr_debug("%s: ->\n", __func__);
  1902. return ret;
  1903. }
  1904. /*
  1905. * connected event
  1906. */
  1907. static void gelic_wl_connected_event(struct gelic_wl_info *wl,
  1908. u64 event)
  1909. {
  1910. u64 desired_event = 0;
  1911. switch (wl->wpa_level) {
  1912. case GELIC_WL_WPA_LEVEL_NONE:
  1913. desired_event = GELIC_LV1_WL_EVENT_CONNECTED;
  1914. break;
  1915. case GELIC_WL_WPA_LEVEL_WPA:
  1916. case GELIC_WL_WPA_LEVEL_WPA2:
  1917. desired_event = GELIC_LV1_WL_EVENT_WPA_CONNECTED;
  1918. break;
  1919. }
  1920. if (desired_event == event) {
  1921. pr_debug("%s: completed \n", __func__);
  1922. complete(&wl->assoc_done);
  1923. netif_carrier_on(port_to_netdev(wl_port(wl)));
  1924. } else
  1925. pr_debug("%s: event %#lx under wpa\n",
  1926. __func__, event);
  1927. }
  1928. /*
  1929. * disconnect event
  1930. */
  1931. static void gelic_wl_disconnect_event(struct gelic_wl_info *wl,
  1932. u64 event)
  1933. {
  1934. struct gelic_eurus_cmd *cmd;
  1935. int lock;
  1936. /*
  1937. * If we fall here in the middle of association,
  1938. * associate_bss() should be waiting for complation of
  1939. * wl->assoc_done.
  1940. * As it waits with timeout, just leave assoc_done
  1941. * uncompleted, then it terminates with timeout
  1942. */
  1943. if (!mutex_trylock(&wl->assoc_stat_lock)) {
  1944. pr_debug("%s: already locked\n", __func__);
  1945. lock = 0;
  1946. } else {
  1947. pr_debug("%s: obtain lock\n", __func__);
  1948. lock = 1;
  1949. }
  1950. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
  1951. kfree(cmd);
  1952. /* send disconnected event to the supplicant */
  1953. if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
  1954. gelic_wl_send_iwap_event(wl, NULL);
  1955. wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
  1956. netif_carrier_off(port_to_netdev(wl_port(wl)));
  1957. if (lock)
  1958. mutex_unlock(&wl->assoc_stat_lock);
  1959. }
  1960. /*
  1961. * event worker
  1962. */
  1963. #ifdef DEBUG
  1964. static const char *eventstr(enum gelic_lv1_wl_event event)
  1965. {
  1966. static char buf[32];
  1967. char *ret;
  1968. if (event & GELIC_LV1_WL_EVENT_DEVICE_READY)
  1969. ret = "EURUS_READY";
  1970. else if (event & GELIC_LV1_WL_EVENT_SCAN_COMPLETED)
  1971. ret = "SCAN_COMPLETED";
  1972. else if (event & GELIC_LV1_WL_EVENT_DEAUTH)
  1973. ret = "DEAUTH";
  1974. else if (event & GELIC_LV1_WL_EVENT_BEACON_LOST)
  1975. ret = "BEACON_LOST";
  1976. else if (event & GELIC_LV1_WL_EVENT_CONNECTED)
  1977. ret = "CONNECTED";
  1978. else if (event & GELIC_LV1_WL_EVENT_WPA_CONNECTED)
  1979. ret = "WPA_CONNECTED";
  1980. else if (event & GELIC_LV1_WL_EVENT_WPA_ERROR)
  1981. ret = "WPA_ERROR";
  1982. else {
  1983. sprintf(buf, "Unknown(%#x)", event);
  1984. ret = buf;
  1985. }
  1986. return ret;
  1987. }
  1988. #else
  1989. static const char *eventstr(enum gelic_lv1_wl_event event)
  1990. {
  1991. return NULL;
  1992. }
  1993. #endif
  1994. static void gelic_wl_event_worker(struct work_struct *work)
  1995. {
  1996. struct gelic_wl_info *wl;
  1997. struct gelic_port *port;
  1998. u64 event, tmp;
  1999. int status;
  2000. pr_debug("%s:start\n", __func__);
  2001. wl = container_of(work, struct gelic_wl_info, event_work.work);
  2002. port = wl_port(wl);
  2003. while (1) {
  2004. status = lv1_net_control(bus_id(port->card), dev_id(port->card),
  2005. GELIC_LV1_GET_WLAN_EVENT, 0, 0, 0,
  2006. &event, &tmp);
  2007. if (status) {
  2008. if (status != LV1_NO_ENTRY)
  2009. pr_debug("%s:wlan event failed %d\n",
  2010. __func__, status);
  2011. /* got all events */
  2012. pr_debug("%s:end\n", __func__);
  2013. return;
  2014. }
  2015. pr_debug("%s: event=%s\n", __func__, eventstr(event));
  2016. switch (event) {
  2017. case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
  2018. gelic_wl_scan_complete_event(wl);
  2019. break;
  2020. case GELIC_LV1_WL_EVENT_BEACON_LOST:
  2021. case GELIC_LV1_WL_EVENT_DEAUTH:
  2022. gelic_wl_disconnect_event(wl, event);
  2023. break;
  2024. case GELIC_LV1_WL_EVENT_CONNECTED:
  2025. case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
  2026. gelic_wl_connected_event(wl, event);
  2027. break;
  2028. default:
  2029. break;
  2030. }
  2031. } /* while */
  2032. }
  2033. /*
  2034. * association worker
  2035. */
  2036. static void gelic_wl_assoc_worker(struct work_struct *work)
  2037. {
  2038. struct gelic_wl_info *wl;
  2039. struct gelic_wl_scan_info *best_bss;
  2040. int ret;
  2041. wl = container_of(work, struct gelic_wl_info, assoc_work.work);
  2042. mutex_lock(&wl->assoc_stat_lock);
  2043. if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
  2044. goto out;
  2045. ret = gelic_wl_start_scan(wl, 0);
  2046. if (ret == -ERESTARTSYS) {
  2047. pr_debug("%s: scan start failed association\n", __func__);
  2048. schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
  2049. goto out;
  2050. } else if (ret) {
  2051. pr_info("%s: scan prerequisite failed\n", __func__);
  2052. goto out;
  2053. }
  2054. /*
  2055. * Wait for bss scan completion
  2056. * If we have scan list already, gelic_wl_start_scan()
  2057. * returns OK and raises the complete. Thus,
  2058. * it's ok to wait unconditionally here
  2059. */
  2060. wait_for_completion(&wl->scan_done);
  2061. pr_debug("%s: scan done\n", __func__);
  2062. mutex_lock(&wl->scan_lock);
  2063. if (wl->scan_stat != GELIC_WL_SCAN_STAT_GOT_LIST) {
  2064. gelic_wl_send_iwap_event(wl, NULL);
  2065. pr_info("%s: no scan list. association failed\n", __func__);
  2066. goto scan_lock_out;
  2067. }
  2068. /* find best matching bss */
  2069. best_bss = gelic_wl_find_best_bss(wl);
  2070. if (!best_bss) {
  2071. gelic_wl_send_iwap_event(wl, NULL);
  2072. pr_info("%s: no bss matched. association failed\n", __func__);
  2073. goto scan_lock_out;
  2074. }
  2075. /* ok, do association */
  2076. ret = gelic_wl_associate_bss(wl, best_bss);
  2077. if (ret)
  2078. pr_info("%s: association failed %d\n", __func__, ret);
  2079. scan_lock_out:
  2080. mutex_unlock(&wl->scan_lock);
  2081. out:
  2082. mutex_unlock(&wl->assoc_stat_lock);
  2083. }
  2084. /*
  2085. * Interrupt handler
  2086. * Called from the ethernet interrupt handler
  2087. * Processes wireless specific virtual interrupts only
  2088. */
  2089. void gelic_wl_interrupt(struct net_device *netdev, u64 status)
  2090. {
  2091. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  2092. if (status & GELIC_CARD_WLAN_COMMAND_COMPLETED) {
  2093. pr_debug("%s:cmd complete\n", __func__);
  2094. complete(&wl->cmd_done_intr);
  2095. }
  2096. if (status & GELIC_CARD_WLAN_EVENT_RECEIVED) {
  2097. pr_debug("%s:event received\n", __func__);
  2098. queue_delayed_work(wl->event_queue, &wl->event_work, 0);
  2099. }
  2100. }
  2101. /*
  2102. * driver helpers
  2103. */
  2104. #define IW_IOCTL(n) [(n) - SIOCSIWCOMMIT]
  2105. static const iw_handler gelic_wl_wext_handler[] =
  2106. {
  2107. IW_IOCTL(SIOCGIWNAME) = gelic_wl_get_name,
  2108. IW_IOCTL(SIOCGIWRANGE) = gelic_wl_get_range,
  2109. IW_IOCTL(SIOCSIWSCAN) = gelic_wl_set_scan,
  2110. IW_IOCTL(SIOCGIWSCAN) = gelic_wl_get_scan,
  2111. IW_IOCTL(SIOCSIWAUTH) = gelic_wl_set_auth,
  2112. IW_IOCTL(SIOCGIWAUTH) = gelic_wl_get_auth,
  2113. IW_IOCTL(SIOCSIWESSID) = gelic_wl_set_essid,
  2114. IW_IOCTL(SIOCGIWESSID) = gelic_wl_get_essid,
  2115. IW_IOCTL(SIOCSIWENCODE) = gelic_wl_set_encode,
  2116. IW_IOCTL(SIOCGIWENCODE) = gelic_wl_get_encode,
  2117. IW_IOCTL(SIOCSIWAP) = gelic_wl_set_ap,
  2118. IW_IOCTL(SIOCGIWAP) = gelic_wl_get_ap,
  2119. IW_IOCTL(SIOCSIWENCODEEXT) = gelic_wl_set_encodeext,
  2120. IW_IOCTL(SIOCGIWENCODEEXT) = gelic_wl_get_encodeext,
  2121. IW_IOCTL(SIOCSIWMODE) = gelic_wl_set_mode,
  2122. IW_IOCTL(SIOCGIWMODE) = gelic_wl_get_mode,
  2123. IW_IOCTL(SIOCGIWNICKN) = gelic_wl_get_nick,
  2124. };
  2125. static struct iw_priv_args gelic_wl_private_args[] =
  2126. {
  2127. {
  2128. .cmd = GELIC_WL_PRIV_SET_PSK,
  2129. .set_args = IW_PRIV_TYPE_CHAR |
  2130. (GELIC_WL_EURUS_PSK_MAX_LEN + 2),
  2131. .name = "set_psk"
  2132. },
  2133. {
  2134. .cmd = GELIC_WL_PRIV_GET_PSK,
  2135. .get_args = IW_PRIV_TYPE_CHAR |
  2136. (GELIC_WL_EURUS_PSK_MAX_LEN + 2),
  2137. .name = "get_psk"
  2138. }
  2139. };
  2140. static const iw_handler gelic_wl_private_handler[] =
  2141. {
  2142. gelic_wl_priv_set_psk,
  2143. gelic_wl_priv_get_psk,
  2144. };
  2145. static const struct iw_handler_def gelic_wl_wext_handler_def = {
  2146. .num_standard = ARRAY_SIZE(gelic_wl_wext_handler),
  2147. .standard = gelic_wl_wext_handler,
  2148. .get_wireless_stats = gelic_wl_get_wireless_stats,
  2149. .num_private = ARRAY_SIZE(gelic_wl_private_handler),
  2150. .num_private_args = ARRAY_SIZE(gelic_wl_private_args),
  2151. .private = gelic_wl_private_handler,
  2152. .private_args = gelic_wl_private_args,
  2153. };
  2154. static struct net_device *gelic_wl_alloc(struct gelic_card *card)
  2155. {
  2156. struct net_device *netdev;
  2157. struct gelic_port *port;
  2158. struct gelic_wl_info *wl;
  2159. unsigned int i;
  2160. pr_debug("%s:start\n", __func__);
  2161. netdev = alloc_etherdev(sizeof(struct gelic_port) +
  2162. sizeof(struct gelic_wl_info));
  2163. pr_debug("%s: netdev =%p card=%p \np", __func__, netdev, card);
  2164. if (!netdev)
  2165. return NULL;
  2166. strcpy(netdev->name, "wlan%d");
  2167. port = netdev_priv(netdev);
  2168. port->netdev = netdev;
  2169. port->card = card;
  2170. port->type = GELIC_PORT_WIRELESS;
  2171. wl = port_wl(port);
  2172. pr_debug("%s: wl=%p port=%p\n", __func__, wl, port);
  2173. /* allocate scan list */
  2174. wl->networks = kzalloc(sizeof(struct gelic_wl_scan_info) *
  2175. GELIC_WL_BSS_MAX_ENT, GFP_KERNEL);
  2176. if (!wl->networks)
  2177. goto fail_bss;
  2178. wl->eurus_cmd_queue = create_singlethread_workqueue("gelic_cmd");
  2179. if (!wl->eurus_cmd_queue)
  2180. goto fail_cmd_workqueue;
  2181. wl->event_queue = create_singlethread_workqueue("gelic_event");
  2182. if (!wl->event_queue)
  2183. goto fail_event_workqueue;
  2184. INIT_LIST_HEAD(&wl->network_free_list);
  2185. INIT_LIST_HEAD(&wl->network_list);
  2186. for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++)
  2187. list_add_tail(&wl->networks[i].list,
  2188. &wl->network_free_list);
  2189. init_completion(&wl->cmd_done_intr);
  2190. INIT_DELAYED_WORK(&wl->event_work, gelic_wl_event_worker);
  2191. INIT_DELAYED_WORK(&wl->assoc_work, gelic_wl_assoc_worker);
  2192. mutex_init(&wl->scan_lock);
  2193. mutex_init(&wl->assoc_stat_lock);
  2194. init_completion(&wl->scan_done);
  2195. /* for the case that no scan request is issued and stop() is called */
  2196. complete(&wl->scan_done);
  2197. spin_lock_init(&wl->lock);
  2198. wl->scan_age = 5*HZ; /* FIXME */
  2199. /* buffer for receiving scanned list etc */
  2200. BUILD_BUG_ON(PAGE_SIZE <
  2201. sizeof(struct gelic_eurus_scan_info) *
  2202. GELIC_EURUS_MAX_SCAN);
  2203. wl->buf = (void *)get_zeroed_page(GFP_KERNEL);
  2204. if (!wl->buf) {
  2205. pr_info("%s:buffer allocation failed\n", __func__);
  2206. goto fail_getpage;
  2207. }
  2208. pr_debug("%s:end\n", __func__);
  2209. return netdev;
  2210. fail_getpage:
  2211. destroy_workqueue(wl->event_queue);
  2212. fail_event_workqueue:
  2213. destroy_workqueue(wl->eurus_cmd_queue);
  2214. fail_cmd_workqueue:
  2215. kfree(wl->networks);
  2216. fail_bss:
  2217. free_netdev(netdev);
  2218. pr_debug("%s:end error\n", __func__);
  2219. return NULL;
  2220. }
  2221. static void gelic_wl_free(struct gelic_wl_info *wl)
  2222. {
  2223. struct gelic_wl_scan_info *scan_info;
  2224. unsigned int i;
  2225. pr_debug("%s: <-\n", __func__);
  2226. free_page((unsigned long)wl->buf);
  2227. pr_debug("%s: destroy queues\n", __func__);
  2228. destroy_workqueue(wl->eurus_cmd_queue);
  2229. destroy_workqueue(wl->event_queue);
  2230. scan_info = wl->networks;
  2231. for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++, scan_info++)
  2232. kfree(scan_info->hwinfo);
  2233. kfree(wl->networks);
  2234. free_netdev(port_to_netdev(wl_port(wl)));
  2235. pr_debug("%s: ->\n", __func__);
  2236. }
  2237. static int gelic_wl_try_associate(struct net_device *netdev)
  2238. {
  2239. struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
  2240. int ret = -1;
  2241. unsigned int i;
  2242. pr_debug("%s: <-\n", __func__);
  2243. /* check constraits for start association */
  2244. /* for no access restriction AP */
  2245. if (wl->group_cipher_method == GELIC_WL_CIPHER_NONE) {
  2246. if (test_bit(GELIC_WL_STAT_CONFIGURED,
  2247. &wl->stat))
  2248. goto do_associate;
  2249. else {
  2250. pr_debug("%s: no wep, not configured\n", __func__);
  2251. return ret;
  2252. }
  2253. }
  2254. /* for WEP, one of four keys should be set */
  2255. if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
  2256. /* one of keys set */
  2257. for (i = 0; i < GELIC_WEP_KEYS; i++) {
  2258. if (test_bit(i, &wl->key_enabled))
  2259. goto do_associate;
  2260. }
  2261. pr_debug("%s: WEP, but no key specified\n", __func__);
  2262. return ret;
  2263. }
  2264. /* for WPA[2], psk should be set */
  2265. if ((wl->group_cipher_method == GELIC_WL_CIPHER_TKIP) ||
  2266. (wl->group_cipher_method == GELIC_WL_CIPHER_AES)) {
  2267. if (test_bit(GELIC_WL_STAT_WPA_PSK_SET,
  2268. &wl->stat))
  2269. goto do_associate;
  2270. else {
  2271. pr_debug("%s: AES/TKIP, but PSK not configured\n",
  2272. __func__);
  2273. return ret;
  2274. }
  2275. }
  2276. do_associate:
  2277. ret = schedule_delayed_work(&wl->assoc_work, 0);
  2278. pr_debug("%s: start association work %d\n", __func__, ret);
  2279. return ret;
  2280. }
  2281. /*
  2282. * netdev handlers
  2283. */
  2284. static int gelic_wl_open(struct net_device *netdev)
  2285. {
  2286. struct gelic_card *card = netdev_card(netdev);
  2287. pr_debug("%s:->%p\n", __func__, netdev);
  2288. gelic_card_up(card);
  2289. /* try to associate */
  2290. gelic_wl_try_associate(netdev);
  2291. netif_start_queue(netdev);
  2292. pr_debug("%s:<-\n", __func__);
  2293. return 0;
  2294. }
  2295. /*
  2296. * reset state machine
  2297. */
  2298. static int gelic_wl_reset_state(struct gelic_wl_info *wl)
  2299. {
  2300. struct gelic_wl_scan_info *target;
  2301. struct gelic_wl_scan_info *tmp;
  2302. /* empty scan list */
  2303. list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
  2304. list_move_tail(&target->list, &wl->network_free_list);
  2305. }
  2306. wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
  2307. /* clear configuration */
  2308. wl->auth_method = GELIC_EURUS_AUTH_OPEN;
  2309. wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
  2310. wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
  2311. wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
  2312. wl->key_enabled = 0;
  2313. wl->current_key = 0;
  2314. wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
  2315. wl->psk_len = 0;
  2316. wl->essid_len = 0;
  2317. memset(wl->essid, 0, sizeof(wl->essid));
  2318. memset(wl->bssid, 0, sizeof(wl->bssid));
  2319. memset(wl->active_bssid, 0, sizeof(wl->active_bssid));
  2320. wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
  2321. memset(&wl->iwstat, 0, sizeof(wl->iwstat));
  2322. /* all status bit clear */
  2323. wl->stat = 0;
  2324. return 0;
  2325. }
  2326. /*
  2327. * Tell eurus to terminate association
  2328. */
  2329. static void gelic_wl_disconnect(struct net_device *netdev)
  2330. {
  2331. struct gelic_port *port = netdev_priv(netdev);
  2332. struct gelic_wl_info *wl = port_wl(port);
  2333. struct gelic_eurus_cmd *cmd;
  2334. /*
  2335. * If scann process is running on chip,
  2336. * further requests will be rejected
  2337. */
  2338. if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING)
  2339. wait_for_completion_timeout(&wl->scan_done, HZ);
  2340. cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
  2341. kfree(cmd);
  2342. gelic_wl_send_iwap_event(wl, NULL);
  2343. };
  2344. static int gelic_wl_stop(struct net_device *netdev)
  2345. {
  2346. struct gelic_port *port = netdev_priv(netdev);
  2347. struct gelic_wl_info *wl = port_wl(port);
  2348. struct gelic_card *card = netdev_card(netdev);
  2349. pr_debug("%s:<-\n", __func__);
  2350. /*
  2351. * Cancel pending association work.
  2352. * event work can run after netdev down
  2353. */
  2354. cancel_delayed_work(&wl->assoc_work);
  2355. if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
  2356. gelic_wl_disconnect(netdev);
  2357. /* reset our state machine */
  2358. gelic_wl_reset_state(wl);
  2359. netif_stop_queue(netdev);
  2360. gelic_card_down(card);
  2361. pr_debug("%s:->\n", __func__);
  2362. return 0;
  2363. }
  2364. /* -- */
  2365. static struct ethtool_ops gelic_wl_ethtool_ops = {
  2366. .get_drvinfo = gelic_net_get_drvinfo,
  2367. .get_link = gelic_wl_get_link,
  2368. .get_tx_csum = ethtool_op_get_tx_csum,
  2369. .set_tx_csum = ethtool_op_set_tx_csum,
  2370. .get_rx_csum = gelic_net_get_rx_csum,
  2371. .set_rx_csum = gelic_net_set_rx_csum,
  2372. };
  2373. static void gelic_wl_setup_netdev_ops(struct net_device *netdev)
  2374. {
  2375. struct gelic_wl_info *wl;
  2376. wl = port_wl(netdev_priv(netdev));
  2377. BUG_ON(!wl);
  2378. netdev->open = &gelic_wl_open;
  2379. netdev->stop = &gelic_wl_stop;
  2380. netdev->hard_start_xmit = &gelic_net_xmit;
  2381. netdev->set_multicast_list = &gelic_net_set_multi;
  2382. netdev->change_mtu = &gelic_net_change_mtu;
  2383. netdev->wireless_data = &wl->wireless_data;
  2384. netdev->wireless_handlers = &gelic_wl_wext_handler_def;
  2385. /* tx watchdog */
  2386. netdev->tx_timeout = &gelic_net_tx_timeout;
  2387. netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
  2388. netdev->ethtool_ops = &gelic_wl_ethtool_ops;
  2389. #ifdef CONFIG_NET_POLL_CONTROLLER
  2390. netdev->poll_controller = gelic_net_poll_controller;
  2391. #endif
  2392. }
  2393. /*
  2394. * driver probe/remove
  2395. */
  2396. int gelic_wl_driver_probe(struct gelic_card *card)
  2397. {
  2398. int ret;
  2399. struct net_device *netdev;
  2400. pr_debug("%s:start\n", __func__);
  2401. if (ps3_compare_firmware_version(1, 6, 0) < 0)
  2402. return 0;
  2403. if (!card->vlan[GELIC_PORT_WIRELESS].tx)
  2404. return 0;
  2405. /* alloc netdevice for wireless */
  2406. netdev = gelic_wl_alloc(card);
  2407. if (!netdev)
  2408. return -ENOMEM;
  2409. /* setup net_device structure */
  2410. SET_NETDEV_DEV(netdev, &card->dev->core);
  2411. gelic_wl_setup_netdev_ops(netdev);
  2412. /* setup some of net_device and register it */
  2413. ret = gelic_net_setup_netdev(netdev, card);
  2414. if (ret)
  2415. goto fail_setup;
  2416. card->netdev[GELIC_PORT_WIRELESS] = netdev;
  2417. /* add enable wireless interrupt */
  2418. card->irq_mask |= GELIC_CARD_WLAN_EVENT_RECEIVED |
  2419. GELIC_CARD_WLAN_COMMAND_COMPLETED;
  2420. /* to allow wireless commands while both interfaces are down */
  2421. gelic_card_set_irq_mask(card, GELIC_CARD_WLAN_EVENT_RECEIVED |
  2422. GELIC_CARD_WLAN_COMMAND_COMPLETED);
  2423. pr_debug("%s:end\n", __func__);
  2424. return 0;
  2425. fail_setup:
  2426. gelic_wl_free(port_wl(netdev_port(netdev)));
  2427. return ret;
  2428. }
  2429. int gelic_wl_driver_remove(struct gelic_card *card)
  2430. {
  2431. struct gelic_wl_info *wl;
  2432. struct net_device *netdev;
  2433. pr_debug("%s:start\n", __func__);
  2434. if (ps3_compare_firmware_version(1, 6, 0) < 0)
  2435. return 0;
  2436. if (!card->vlan[GELIC_PORT_WIRELESS].tx)
  2437. return 0;
  2438. netdev = card->netdev[GELIC_PORT_WIRELESS];
  2439. wl = port_wl(netdev_priv(netdev));
  2440. /* if the interface was not up, but associated */
  2441. if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
  2442. gelic_wl_disconnect(netdev);
  2443. complete(&wl->cmd_done_intr);
  2444. /* cancel all work queue */
  2445. cancel_delayed_work(&wl->assoc_work);
  2446. cancel_delayed_work(&wl->event_work);
  2447. flush_workqueue(wl->eurus_cmd_queue);
  2448. flush_workqueue(wl->event_queue);
  2449. unregister_netdev(netdev);
  2450. /* disable wireless interrupt */
  2451. pr_debug("%s: disable intr\n", __func__);
  2452. card->irq_mask &= ~(GELIC_CARD_WLAN_EVENT_RECEIVED |
  2453. GELIC_CARD_WLAN_COMMAND_COMPLETED);
  2454. /* free bss list, netdev*/
  2455. gelic_wl_free(wl);
  2456. pr_debug("%s:end\n", __func__);
  2457. return 0;
  2458. }