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