ps3_gelic_wireless.c 72 KB

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