ps3_gelic_wireless.c 72 KB

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