ps3_gelic_wireless.c 72 KB

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