ps3_gelic_wireless.c 72 KB

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