main.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  1. /**
  2. * This file contains the major functions in WLAN
  3. * driver. It includes init, exit, open, close and main
  4. * thread etc..
  5. */
  6. #include <linux/moduleparam.h>
  7. #include <linux/delay.h>
  8. #include <linux/etherdevice.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/if_arp.h>
  11. #include <linux/kthread.h>
  12. #include <linux/kfifo.h>
  13. #include <linux/stddef.h>
  14. #include <linux/ieee80211.h>
  15. #include <net/iw_handler.h>
  16. #include <net/cfg80211.h>
  17. #include "host.h"
  18. #include "decl.h"
  19. #include "dev.h"
  20. #include "wext.h"
  21. #include "cfg.h"
  22. #include "debugfs.h"
  23. #include "scan.h"
  24. #include "assoc.h"
  25. #include "cmd.h"
  26. #define DRIVER_RELEASE_VERSION "323.p0"
  27. const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
  28. #ifdef DEBUG
  29. "-dbg"
  30. #endif
  31. "";
  32. /* Module parameters */
  33. unsigned int lbs_debug;
  34. EXPORT_SYMBOL_GPL(lbs_debug);
  35. module_param_named(libertas_debug, lbs_debug, int, 0644);
  36. /* This global structure is used to send the confirm_sleep command as
  37. * fast as possible down to the firmware. */
  38. struct cmd_confirm_sleep confirm_sleep;
  39. #define LBS_TX_PWR_DEFAULT 20 /*100mW */
  40. #define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
  41. #define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
  42. #define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
  43. #define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
  44. /* Format { channel, frequency (MHz), maxtxpower } */
  45. /* band: 'B/G', region: USA FCC/Canada IC */
  46. static struct chan_freq_power channel_freq_power_US_BG[] = {
  47. {1, 2412, LBS_TX_PWR_US_DEFAULT},
  48. {2, 2417, LBS_TX_PWR_US_DEFAULT},
  49. {3, 2422, LBS_TX_PWR_US_DEFAULT},
  50. {4, 2427, LBS_TX_PWR_US_DEFAULT},
  51. {5, 2432, LBS_TX_PWR_US_DEFAULT},
  52. {6, 2437, LBS_TX_PWR_US_DEFAULT},
  53. {7, 2442, LBS_TX_PWR_US_DEFAULT},
  54. {8, 2447, LBS_TX_PWR_US_DEFAULT},
  55. {9, 2452, LBS_TX_PWR_US_DEFAULT},
  56. {10, 2457, LBS_TX_PWR_US_DEFAULT},
  57. {11, 2462, LBS_TX_PWR_US_DEFAULT}
  58. };
  59. /* band: 'B/G', region: Europe ETSI */
  60. static struct chan_freq_power channel_freq_power_EU_BG[] = {
  61. {1, 2412, LBS_TX_PWR_EMEA_DEFAULT},
  62. {2, 2417, LBS_TX_PWR_EMEA_DEFAULT},
  63. {3, 2422, LBS_TX_PWR_EMEA_DEFAULT},
  64. {4, 2427, LBS_TX_PWR_EMEA_DEFAULT},
  65. {5, 2432, LBS_TX_PWR_EMEA_DEFAULT},
  66. {6, 2437, LBS_TX_PWR_EMEA_DEFAULT},
  67. {7, 2442, LBS_TX_PWR_EMEA_DEFAULT},
  68. {8, 2447, LBS_TX_PWR_EMEA_DEFAULT},
  69. {9, 2452, LBS_TX_PWR_EMEA_DEFAULT},
  70. {10, 2457, LBS_TX_PWR_EMEA_DEFAULT},
  71. {11, 2462, LBS_TX_PWR_EMEA_DEFAULT},
  72. {12, 2467, LBS_TX_PWR_EMEA_DEFAULT},
  73. {13, 2472, LBS_TX_PWR_EMEA_DEFAULT}
  74. };
  75. /* band: 'B/G', region: Spain */
  76. static struct chan_freq_power channel_freq_power_SPN_BG[] = {
  77. {10, 2457, LBS_TX_PWR_DEFAULT},
  78. {11, 2462, LBS_TX_PWR_DEFAULT}
  79. };
  80. /* band: 'B/G', region: France */
  81. static struct chan_freq_power channel_freq_power_FR_BG[] = {
  82. {10, 2457, LBS_TX_PWR_FR_DEFAULT},
  83. {11, 2462, LBS_TX_PWR_FR_DEFAULT},
  84. {12, 2467, LBS_TX_PWR_FR_DEFAULT},
  85. {13, 2472, LBS_TX_PWR_FR_DEFAULT}
  86. };
  87. /* band: 'B/G', region: Japan */
  88. static struct chan_freq_power channel_freq_power_JPN_BG[] = {
  89. {1, 2412, LBS_TX_PWR_JP_DEFAULT},
  90. {2, 2417, LBS_TX_PWR_JP_DEFAULT},
  91. {3, 2422, LBS_TX_PWR_JP_DEFAULT},
  92. {4, 2427, LBS_TX_PWR_JP_DEFAULT},
  93. {5, 2432, LBS_TX_PWR_JP_DEFAULT},
  94. {6, 2437, LBS_TX_PWR_JP_DEFAULT},
  95. {7, 2442, LBS_TX_PWR_JP_DEFAULT},
  96. {8, 2447, LBS_TX_PWR_JP_DEFAULT},
  97. {9, 2452, LBS_TX_PWR_JP_DEFAULT},
  98. {10, 2457, LBS_TX_PWR_JP_DEFAULT},
  99. {11, 2462, LBS_TX_PWR_JP_DEFAULT},
  100. {12, 2467, LBS_TX_PWR_JP_DEFAULT},
  101. {13, 2472, LBS_TX_PWR_JP_DEFAULT},
  102. {14, 2484, LBS_TX_PWR_JP_DEFAULT}
  103. };
  104. /**
  105. * the structure for channel, frequency and power
  106. */
  107. struct region_cfp_table {
  108. u8 region;
  109. struct chan_freq_power *cfp_BG;
  110. int cfp_no_BG;
  111. };
  112. /**
  113. * the structure for the mapping between region and CFP
  114. */
  115. static struct region_cfp_table region_cfp_table[] = {
  116. {0x10, /*US FCC */
  117. channel_freq_power_US_BG,
  118. ARRAY_SIZE(channel_freq_power_US_BG),
  119. }
  120. ,
  121. {0x20, /*CANADA IC */
  122. channel_freq_power_US_BG,
  123. ARRAY_SIZE(channel_freq_power_US_BG),
  124. }
  125. ,
  126. {0x30, /*EU*/ channel_freq_power_EU_BG,
  127. ARRAY_SIZE(channel_freq_power_EU_BG),
  128. }
  129. ,
  130. {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
  131. ARRAY_SIZE(channel_freq_power_SPN_BG),
  132. }
  133. ,
  134. {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
  135. ARRAY_SIZE(channel_freq_power_FR_BG),
  136. }
  137. ,
  138. {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
  139. ARRAY_SIZE(channel_freq_power_JPN_BG),
  140. }
  141. ,
  142. /*Add new region here */
  143. };
  144. /**
  145. * the table to keep region code
  146. */
  147. u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
  148. { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
  149. /**
  150. * 802.11b/g supported bitrates (in 500Kb/s units)
  151. */
  152. u8 lbs_bg_rates[MAX_RATES] =
  153. { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
  154. 0x00, 0x00 };
  155. /**
  156. * FW rate table. FW refers to rates by their index in this table, not by the
  157. * rate value itself. Values of 0x00 are
  158. * reserved positions.
  159. */
  160. static u8 fw_data_rates[MAX_RATES] =
  161. { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
  162. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
  163. };
  164. /**
  165. * @brief use index to get the data rate
  166. *
  167. * @param idx The index of data rate
  168. * @return data rate or 0
  169. */
  170. u32 lbs_fw_index_to_data_rate(u8 idx)
  171. {
  172. if (idx >= sizeof(fw_data_rates))
  173. idx = 0;
  174. return fw_data_rates[idx];
  175. }
  176. /**
  177. * @brief use rate to get the index
  178. *
  179. * @param rate data rate
  180. * @return index or 0
  181. */
  182. u8 lbs_data_rate_to_fw_index(u32 rate)
  183. {
  184. u8 i;
  185. if (!rate)
  186. return 0;
  187. for (i = 0; i < sizeof(fw_data_rates); i++) {
  188. if (rate == fw_data_rates[i])
  189. return i;
  190. }
  191. return 0;
  192. }
  193. /**
  194. * Attributes exported through sysfs
  195. */
  196. /**
  197. * @brief Get function for sysfs attribute anycast_mask
  198. */
  199. static ssize_t lbs_anycast_get(struct device *dev,
  200. struct device_attribute *attr, char * buf)
  201. {
  202. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  203. struct cmd_ds_mesh_access mesh_access;
  204. int ret;
  205. memset(&mesh_access, 0, sizeof(mesh_access));
  206. ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
  207. if (ret)
  208. return ret;
  209. return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
  210. }
  211. /**
  212. * @brief Set function for sysfs attribute anycast_mask
  213. */
  214. static ssize_t lbs_anycast_set(struct device *dev,
  215. struct device_attribute *attr, const char * buf, size_t count)
  216. {
  217. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  218. struct cmd_ds_mesh_access mesh_access;
  219. uint32_t datum;
  220. int ret;
  221. memset(&mesh_access, 0, sizeof(mesh_access));
  222. sscanf(buf, "%x", &datum);
  223. mesh_access.data[0] = cpu_to_le32(datum);
  224. ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
  225. if (ret)
  226. return ret;
  227. return strlen(buf);
  228. }
  229. /**
  230. * @brief Get function for sysfs attribute prb_rsp_limit
  231. */
  232. static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
  233. struct device_attribute *attr, char *buf)
  234. {
  235. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  236. struct cmd_ds_mesh_access mesh_access;
  237. int ret;
  238. u32 retry_limit;
  239. memset(&mesh_access, 0, sizeof(mesh_access));
  240. mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
  241. ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
  242. &mesh_access);
  243. if (ret)
  244. return ret;
  245. retry_limit = le32_to_cpu(mesh_access.data[1]);
  246. return snprintf(buf, 10, "%d\n", retry_limit);
  247. }
  248. /**
  249. * @brief Set function for sysfs attribute prb_rsp_limit
  250. */
  251. static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
  252. struct device_attribute *attr, const char *buf, size_t count)
  253. {
  254. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  255. struct cmd_ds_mesh_access mesh_access;
  256. int ret;
  257. unsigned long retry_limit;
  258. memset(&mesh_access, 0, sizeof(mesh_access));
  259. mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
  260. if (!strict_strtoul(buf, 10, &retry_limit))
  261. return -ENOTSUPP;
  262. if (retry_limit > 15)
  263. return -ENOTSUPP;
  264. mesh_access.data[1] = cpu_to_le32(retry_limit);
  265. ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
  266. &mesh_access);
  267. if (ret)
  268. return ret;
  269. return strlen(buf);
  270. }
  271. static int lbs_add_rtap(struct lbs_private *priv);
  272. static void lbs_remove_rtap(struct lbs_private *priv);
  273. static int lbs_add_mesh(struct lbs_private *priv);
  274. static void lbs_remove_mesh(struct lbs_private *priv);
  275. /**
  276. * Get function for sysfs attribute rtap
  277. */
  278. static ssize_t lbs_rtap_get(struct device *dev,
  279. struct device_attribute *attr, char * buf)
  280. {
  281. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  282. return snprintf(buf, 5, "0x%X\n", priv->monitormode);
  283. }
  284. /**
  285. * Set function for sysfs attribute rtap
  286. */
  287. static ssize_t lbs_rtap_set(struct device *dev,
  288. struct device_attribute *attr, const char * buf, size_t count)
  289. {
  290. int monitor_mode;
  291. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  292. sscanf(buf, "%x", &monitor_mode);
  293. if (monitor_mode) {
  294. if (priv->monitormode == monitor_mode)
  295. return strlen(buf);
  296. if (!priv->monitormode) {
  297. if (priv->infra_open || priv->mesh_open)
  298. return -EBUSY;
  299. if (priv->mode == IW_MODE_INFRA)
  300. lbs_cmd_80211_deauthenticate(priv,
  301. priv->curbssparams.bssid,
  302. WLAN_REASON_DEAUTH_LEAVING);
  303. else if (priv->mode == IW_MODE_ADHOC)
  304. lbs_adhoc_stop(priv);
  305. lbs_add_rtap(priv);
  306. }
  307. priv->monitormode = monitor_mode;
  308. } else {
  309. if (!priv->monitormode)
  310. return strlen(buf);
  311. priv->monitormode = 0;
  312. lbs_remove_rtap(priv);
  313. if (priv->currenttxskb) {
  314. dev_kfree_skb_any(priv->currenttxskb);
  315. priv->currenttxskb = NULL;
  316. }
  317. /* Wake queues, command thread, etc. */
  318. lbs_host_to_card_done(priv);
  319. }
  320. lbs_prepare_and_send_command(priv,
  321. CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
  322. CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
  323. return strlen(buf);
  324. }
  325. /**
  326. * lbs_rtap attribute to be exported per ethX interface
  327. * through sysfs (/sys/class/net/ethX/lbs_rtap)
  328. */
  329. static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
  330. /**
  331. * Get function for sysfs attribute mesh
  332. */
  333. static ssize_t lbs_mesh_get(struct device *dev,
  334. struct device_attribute *attr, char * buf)
  335. {
  336. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  337. return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
  338. }
  339. /**
  340. * Set function for sysfs attribute mesh
  341. */
  342. static ssize_t lbs_mesh_set(struct device *dev,
  343. struct device_attribute *attr, const char * buf, size_t count)
  344. {
  345. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  346. int enable;
  347. int ret, action = CMD_ACT_MESH_CONFIG_STOP;
  348. sscanf(buf, "%x", &enable);
  349. enable = !!enable;
  350. if (enable == !!priv->mesh_dev)
  351. return count;
  352. if (enable)
  353. action = CMD_ACT_MESH_CONFIG_START;
  354. ret = lbs_mesh_config(priv, action, priv->curbssparams.channel);
  355. if (ret)
  356. return ret;
  357. if (enable)
  358. lbs_add_mesh(priv);
  359. else
  360. lbs_remove_mesh(priv);
  361. return count;
  362. }
  363. /**
  364. * lbs_mesh attribute to be exported per ethX interface
  365. * through sysfs (/sys/class/net/ethX/lbs_mesh)
  366. */
  367. static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
  368. /**
  369. * anycast_mask attribute to be exported per mshX interface
  370. * through sysfs (/sys/class/net/mshX/anycast_mask)
  371. */
  372. static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
  373. /**
  374. * prb_rsp_limit attribute to be exported per mshX interface
  375. * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
  376. */
  377. static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
  378. lbs_prb_rsp_limit_set);
  379. static struct attribute *lbs_mesh_sysfs_entries[] = {
  380. &dev_attr_anycast_mask.attr,
  381. &dev_attr_prb_rsp_limit.attr,
  382. NULL,
  383. };
  384. static struct attribute_group lbs_mesh_attr_group = {
  385. .attrs = lbs_mesh_sysfs_entries,
  386. };
  387. /**
  388. * @brief This function opens the ethX or mshX interface
  389. *
  390. * @param dev A pointer to net_device structure
  391. * @return 0 or -EBUSY if monitor mode active
  392. */
  393. static int lbs_dev_open(struct net_device *dev)
  394. {
  395. struct lbs_private *priv = dev->ml_priv;
  396. int ret = 0;
  397. lbs_deb_enter(LBS_DEB_NET);
  398. spin_lock_irq(&priv->driver_lock);
  399. if (priv->monitormode) {
  400. ret = -EBUSY;
  401. goto out;
  402. }
  403. if (dev == priv->mesh_dev) {
  404. priv->mesh_open = 1;
  405. priv->mesh_connect_status = LBS_CONNECTED;
  406. netif_carrier_on(dev);
  407. } else {
  408. priv->infra_open = 1;
  409. if (priv->connect_status == LBS_CONNECTED)
  410. netif_carrier_on(dev);
  411. else
  412. netif_carrier_off(dev);
  413. }
  414. if (!priv->tx_pending_len)
  415. netif_wake_queue(dev);
  416. out:
  417. spin_unlock_irq(&priv->driver_lock);
  418. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  419. return ret;
  420. }
  421. /**
  422. * @brief This function closes the mshX interface
  423. *
  424. * @param dev A pointer to net_device structure
  425. * @return 0
  426. */
  427. static int lbs_mesh_stop(struct net_device *dev)
  428. {
  429. struct lbs_private *priv = dev->ml_priv;
  430. lbs_deb_enter(LBS_DEB_MESH);
  431. spin_lock_irq(&priv->driver_lock);
  432. priv->mesh_open = 0;
  433. priv->mesh_connect_status = LBS_DISCONNECTED;
  434. netif_stop_queue(dev);
  435. netif_carrier_off(dev);
  436. spin_unlock_irq(&priv->driver_lock);
  437. schedule_work(&priv->mcast_work);
  438. lbs_deb_leave(LBS_DEB_MESH);
  439. return 0;
  440. }
  441. /**
  442. * @brief This function closes the ethX interface
  443. *
  444. * @param dev A pointer to net_device structure
  445. * @return 0
  446. */
  447. static int lbs_eth_stop(struct net_device *dev)
  448. {
  449. struct lbs_private *priv = dev->ml_priv;
  450. lbs_deb_enter(LBS_DEB_NET);
  451. spin_lock_irq(&priv->driver_lock);
  452. priv->infra_open = 0;
  453. netif_stop_queue(dev);
  454. spin_unlock_irq(&priv->driver_lock);
  455. schedule_work(&priv->mcast_work);
  456. lbs_deb_leave(LBS_DEB_NET);
  457. return 0;
  458. }
  459. static void lbs_tx_timeout(struct net_device *dev)
  460. {
  461. struct lbs_private *priv = dev->ml_priv;
  462. lbs_deb_enter(LBS_DEB_TX);
  463. lbs_pr_err("tx watch dog timeout\n");
  464. dev->trans_start = jiffies;
  465. if (priv->currenttxskb)
  466. lbs_send_tx_feedback(priv, 0);
  467. /* XX: Shouldn't we also call into the hw-specific driver
  468. to kick it somehow? */
  469. lbs_host_to_card_done(priv);
  470. /* More often than not, this actually happens because the
  471. firmware has crapped itself -- rather than just a very
  472. busy medium. So send a harmless command, and if/when
  473. _that_ times out, we'll kick it in the head. */
  474. lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  475. 0, 0, NULL);
  476. lbs_deb_leave(LBS_DEB_TX);
  477. }
  478. void lbs_host_to_card_done(struct lbs_private *priv)
  479. {
  480. unsigned long flags;
  481. lbs_deb_enter(LBS_DEB_THREAD);
  482. spin_lock_irqsave(&priv->driver_lock, flags);
  483. priv->dnld_sent = DNLD_RES_RECEIVED;
  484. /* Wake main thread if commands are pending */
  485. if (!priv->cur_cmd || priv->tx_pending_len > 0) {
  486. if (!priv->wakeup_dev_required)
  487. wake_up_interruptible(&priv->waitq);
  488. }
  489. spin_unlock_irqrestore(&priv->driver_lock, flags);
  490. lbs_deb_leave(LBS_DEB_THREAD);
  491. }
  492. EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
  493. static int lbs_set_mac_address(struct net_device *dev, void *addr)
  494. {
  495. int ret = 0;
  496. struct lbs_private *priv = dev->ml_priv;
  497. struct sockaddr *phwaddr = addr;
  498. struct cmd_ds_802_11_mac_address cmd;
  499. lbs_deb_enter(LBS_DEB_NET);
  500. /* In case it was called from the mesh device */
  501. dev = priv->dev;
  502. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  503. cmd.action = cpu_to_le16(CMD_ACT_SET);
  504. memcpy(cmd.macadd, phwaddr->sa_data, ETH_ALEN);
  505. ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd);
  506. if (ret) {
  507. lbs_deb_net("set MAC address failed\n");
  508. goto done;
  509. }
  510. memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
  511. memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
  512. if (priv->mesh_dev)
  513. memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
  514. done:
  515. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  516. return ret;
  517. }
  518. static inline int mac_in_list(unsigned char *list, int list_len,
  519. unsigned char *mac)
  520. {
  521. while (list_len) {
  522. if (!memcmp(list, mac, ETH_ALEN))
  523. return 1;
  524. list += ETH_ALEN;
  525. list_len--;
  526. }
  527. return 0;
  528. }
  529. static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd,
  530. struct net_device *dev, int nr_addrs)
  531. {
  532. int i = nr_addrs;
  533. struct dev_mc_list *mc_list;
  534. if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST))
  535. return nr_addrs;
  536. netif_addr_lock_bh(dev);
  537. for (mc_list = dev->mc_list; mc_list; mc_list = mc_list->next) {
  538. if (mac_in_list(cmd->maclist, nr_addrs, mc_list->dmi_addr)) {
  539. lbs_deb_net("mcast address %s:%pM skipped\n", dev->name,
  540. mc_list->dmi_addr);
  541. continue;
  542. }
  543. if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE)
  544. break;
  545. memcpy(&cmd->maclist[6*i], mc_list->dmi_addr, ETH_ALEN);
  546. lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name,
  547. mc_list->dmi_addr);
  548. i++;
  549. }
  550. netif_addr_unlock_bh(dev);
  551. if (mc_list)
  552. return -EOVERFLOW;
  553. return i;
  554. }
  555. static void lbs_set_mcast_worker(struct work_struct *work)
  556. {
  557. struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work);
  558. struct cmd_ds_mac_multicast_adr mcast_cmd;
  559. int dev_flags;
  560. int nr_addrs;
  561. int old_mac_control = priv->mac_control;
  562. lbs_deb_enter(LBS_DEB_NET);
  563. dev_flags = priv->dev->flags;
  564. if (priv->mesh_dev)
  565. dev_flags |= priv->mesh_dev->flags;
  566. if (dev_flags & IFF_PROMISC) {
  567. priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
  568. priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
  569. CMD_ACT_MAC_MULTICAST_ENABLE);
  570. goto out_set_mac_control;
  571. } else if (dev_flags & IFF_ALLMULTI) {
  572. do_allmulti:
  573. priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  574. priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
  575. CMD_ACT_MAC_MULTICAST_ENABLE);
  576. goto out_set_mac_control;
  577. }
  578. /* Once for priv->dev, again for priv->mesh_dev if it exists */
  579. nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0);
  580. if (nr_addrs >= 0 && priv->mesh_dev)
  581. nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs);
  582. if (nr_addrs < 0)
  583. goto do_allmulti;
  584. if (nr_addrs) {
  585. int size = offsetof(struct cmd_ds_mac_multicast_adr,
  586. maclist[6*nr_addrs]);
  587. mcast_cmd.action = cpu_to_le16(CMD_ACT_SET);
  588. mcast_cmd.hdr.size = cpu_to_le16(size);
  589. mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs);
  590. lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size);
  591. priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
  592. } else
  593. priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
  594. priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
  595. CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
  596. out_set_mac_control:
  597. if (priv->mac_control != old_mac_control)
  598. lbs_set_mac_control(priv);
  599. lbs_deb_leave(LBS_DEB_NET);
  600. }
  601. static void lbs_set_multicast_list(struct net_device *dev)
  602. {
  603. struct lbs_private *priv = dev->ml_priv;
  604. schedule_work(&priv->mcast_work);
  605. }
  606. /**
  607. * @brief This function handles the major jobs in the LBS driver.
  608. * It handles all events generated by firmware, RX data received
  609. * from firmware and TX data sent from kernel.
  610. *
  611. * @param data A pointer to lbs_thread structure
  612. * @return 0
  613. */
  614. static int lbs_thread(void *data)
  615. {
  616. struct net_device *dev = data;
  617. struct lbs_private *priv = dev->ml_priv;
  618. wait_queue_t wait;
  619. lbs_deb_enter(LBS_DEB_THREAD);
  620. init_waitqueue_entry(&wait, current);
  621. for (;;) {
  622. int shouldsleep;
  623. u8 resp_idx;
  624. lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
  625. priv->currenttxskb, priv->dnld_sent);
  626. add_wait_queue(&priv->waitq, &wait);
  627. set_current_state(TASK_INTERRUPTIBLE);
  628. spin_lock_irq(&priv->driver_lock);
  629. if (kthread_should_stop())
  630. shouldsleep = 0; /* Bye */
  631. else if (priv->surpriseremoved)
  632. shouldsleep = 1; /* We need to wait until we're _told_ to die */
  633. else if (priv->psstate == PS_STATE_SLEEP)
  634. shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
  635. else if (priv->cmd_timed_out)
  636. shouldsleep = 0; /* Command timed out. Recover */
  637. else if (!priv->fw_ready)
  638. shouldsleep = 1; /* Firmware not ready. We're waiting for it */
  639. else if (priv->dnld_sent)
  640. shouldsleep = 1; /* Something is en route to the device already */
  641. else if (priv->tx_pending_len > 0)
  642. shouldsleep = 0; /* We've a packet to send */
  643. else if (priv->resp_len[priv->resp_idx])
  644. shouldsleep = 0; /* We have a command response */
  645. else if (priv->cur_cmd)
  646. shouldsleep = 1; /* Can't send a command; one already running */
  647. else if (!list_empty(&priv->cmdpendingq) &&
  648. !(priv->wakeup_dev_required))
  649. shouldsleep = 0; /* We have a command to send */
  650. else if (__kfifo_len(priv->event_fifo))
  651. shouldsleep = 0; /* We have an event to process */
  652. else
  653. shouldsleep = 1; /* No command */
  654. if (shouldsleep) {
  655. lbs_deb_thread("sleeping, connect_status %d, "
  656. "psmode %d, psstate %d\n",
  657. priv->connect_status,
  658. priv->psmode, priv->psstate);
  659. spin_unlock_irq(&priv->driver_lock);
  660. schedule();
  661. } else
  662. spin_unlock_irq(&priv->driver_lock);
  663. lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
  664. priv->currenttxskb, priv->dnld_sent);
  665. set_current_state(TASK_RUNNING);
  666. remove_wait_queue(&priv->waitq, &wait);
  667. lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
  668. priv->currenttxskb, priv->dnld_sent);
  669. if (kthread_should_stop()) {
  670. lbs_deb_thread("break from main thread\n");
  671. break;
  672. }
  673. if (priv->surpriseremoved) {
  674. lbs_deb_thread("adapter removed; waiting to die...\n");
  675. continue;
  676. }
  677. lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
  678. priv->currenttxskb, priv->dnld_sent);
  679. /* Process any pending command response */
  680. spin_lock_irq(&priv->driver_lock);
  681. resp_idx = priv->resp_idx;
  682. if (priv->resp_len[resp_idx]) {
  683. spin_unlock_irq(&priv->driver_lock);
  684. lbs_process_command_response(priv,
  685. priv->resp_buf[resp_idx],
  686. priv->resp_len[resp_idx]);
  687. spin_lock_irq(&priv->driver_lock);
  688. priv->resp_len[resp_idx] = 0;
  689. }
  690. spin_unlock_irq(&priv->driver_lock);
  691. /* Process hardware events, e.g. card removed, link lost */
  692. spin_lock_irq(&priv->driver_lock);
  693. while (__kfifo_len(priv->event_fifo)) {
  694. u32 event;
  695. __kfifo_get(priv->event_fifo, (unsigned char *) &event,
  696. sizeof(event));
  697. spin_unlock_irq(&priv->driver_lock);
  698. lbs_process_event(priv, event);
  699. spin_lock_irq(&priv->driver_lock);
  700. }
  701. spin_unlock_irq(&priv->driver_lock);
  702. if (priv->wakeup_dev_required) {
  703. lbs_deb_thread("Waking up device...\n");
  704. /* Wake up device */
  705. if (priv->exit_deep_sleep(priv))
  706. lbs_deb_thread("Wakeup device failed\n");
  707. continue;
  708. }
  709. /* command timeout stuff */
  710. if (priv->cmd_timed_out && priv->cur_cmd) {
  711. struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
  712. if (++priv->nr_retries > 3) {
  713. lbs_pr_info("Excessive timeouts submitting "
  714. "command 0x%04x\n",
  715. le16_to_cpu(cmdnode->cmdbuf->command));
  716. lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
  717. priv->nr_retries = 0;
  718. if (priv->reset_card)
  719. priv->reset_card(priv);
  720. } else {
  721. priv->cur_cmd = NULL;
  722. priv->dnld_sent = DNLD_RES_RECEIVED;
  723. lbs_pr_info("requeueing command 0x%04x due "
  724. "to timeout (#%d)\n",
  725. le16_to_cpu(cmdnode->cmdbuf->command),
  726. priv->nr_retries);
  727. /* Stick it back at the _top_ of the pending queue
  728. for immediate resubmission */
  729. list_add(&cmdnode->list, &priv->cmdpendingq);
  730. }
  731. }
  732. priv->cmd_timed_out = 0;
  733. if (!priv->fw_ready)
  734. continue;
  735. /* Check if we need to confirm Sleep Request received previously */
  736. if (priv->psstate == PS_STATE_PRE_SLEEP &&
  737. !priv->dnld_sent && !priv->cur_cmd) {
  738. if (priv->connect_status == LBS_CONNECTED) {
  739. lbs_deb_thread("pre-sleep, currenttxskb %p, "
  740. "dnld_sent %d, cur_cmd %p\n",
  741. priv->currenttxskb, priv->dnld_sent,
  742. priv->cur_cmd);
  743. lbs_ps_confirm_sleep(priv);
  744. } else {
  745. /* workaround for firmware sending
  746. * deauth/linkloss event immediately
  747. * after sleep request; remove this
  748. * after firmware fixes it
  749. */
  750. priv->psstate = PS_STATE_AWAKE;
  751. lbs_pr_alert("ignore PS_SleepConfirm in "
  752. "non-connected state\n");
  753. }
  754. }
  755. /* The PS state is changed during processing of Sleep Request
  756. * event above
  757. */
  758. if ((priv->psstate == PS_STATE_SLEEP) ||
  759. (priv->psstate == PS_STATE_PRE_SLEEP))
  760. continue;
  761. if (priv->is_deep_sleep)
  762. continue;
  763. /* Execute the next command */
  764. if (!priv->dnld_sent && !priv->cur_cmd)
  765. lbs_execute_next_command(priv);
  766. /* Wake-up command waiters which can't sleep in
  767. * lbs_prepare_and_send_command
  768. */
  769. if (!list_empty(&priv->cmdpendingq))
  770. wake_up_all(&priv->cmd_pending);
  771. spin_lock_irq(&priv->driver_lock);
  772. if (!priv->dnld_sent && priv->tx_pending_len > 0) {
  773. int ret = priv->hw_host_to_card(priv, MVMS_DAT,
  774. priv->tx_pending_buf,
  775. priv->tx_pending_len);
  776. if (ret) {
  777. lbs_deb_tx("host_to_card failed %d\n", ret);
  778. priv->dnld_sent = DNLD_RES_RECEIVED;
  779. }
  780. priv->tx_pending_len = 0;
  781. if (!priv->currenttxskb) {
  782. /* We can wake the queues immediately if we aren't
  783. waiting for TX feedback */
  784. if (priv->connect_status == LBS_CONNECTED)
  785. netif_wake_queue(priv->dev);
  786. if (priv->mesh_dev &&
  787. priv->mesh_connect_status == LBS_CONNECTED)
  788. netif_wake_queue(priv->mesh_dev);
  789. }
  790. }
  791. spin_unlock_irq(&priv->driver_lock);
  792. }
  793. del_timer(&priv->command_timer);
  794. del_timer(&priv->auto_deepsleep_timer);
  795. wake_up_all(&priv->cmd_pending);
  796. lbs_deb_leave(LBS_DEB_THREAD);
  797. return 0;
  798. }
  799. static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy,
  800. struct cmd_header *cmd)
  801. {
  802. lbs_deb_enter(LBS_DEB_FW);
  803. netif_device_detach(priv->dev);
  804. if (priv->mesh_dev)
  805. netif_device_detach(priv->mesh_dev);
  806. priv->fw_ready = 0;
  807. lbs_deb_leave(LBS_DEB_FW);
  808. return 0;
  809. }
  810. int lbs_suspend(struct lbs_private *priv)
  811. {
  812. struct cmd_header cmd;
  813. int ret;
  814. lbs_deb_enter(LBS_DEB_FW);
  815. if (priv->wol_criteria == 0xffffffff) {
  816. lbs_pr_info("Suspend attempt without configuring wake params!\n");
  817. return -EINVAL;
  818. }
  819. memset(&cmd, 0, sizeof(cmd));
  820. ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd,
  821. sizeof(cmd), lbs_suspend_callback, 0);
  822. if (ret)
  823. lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret);
  824. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  825. return ret;
  826. }
  827. EXPORT_SYMBOL_GPL(lbs_suspend);
  828. void lbs_resume(struct lbs_private *priv)
  829. {
  830. lbs_deb_enter(LBS_DEB_FW);
  831. priv->fw_ready = 1;
  832. /* Firmware doesn't seem to give us RX packets any more
  833. until we send it some command. Might as well update */
  834. lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  835. 0, 0, NULL);
  836. netif_device_attach(priv->dev);
  837. if (priv->mesh_dev)
  838. netif_device_attach(priv->mesh_dev);
  839. lbs_deb_leave(LBS_DEB_FW);
  840. }
  841. EXPORT_SYMBOL_GPL(lbs_resume);
  842. /**
  843. * @brief This function gets the HW spec from the firmware and sets
  844. * some basic parameters.
  845. *
  846. * @param priv A pointer to struct lbs_private structure
  847. * @return 0 or -1
  848. */
  849. static int lbs_setup_firmware(struct lbs_private *priv)
  850. {
  851. int ret = -1;
  852. s16 curlevel = 0, minlevel = 0, maxlevel = 0;
  853. lbs_deb_enter(LBS_DEB_FW);
  854. /* Read MAC address from firmware */
  855. memset(priv->current_addr, 0xff, ETH_ALEN);
  856. ret = lbs_update_hw_spec(priv);
  857. if (ret)
  858. goto done;
  859. /* Read power levels if available */
  860. ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
  861. if (ret == 0) {
  862. priv->txpower_cur = curlevel;
  863. priv->txpower_min = minlevel;
  864. priv->txpower_max = maxlevel;
  865. }
  866. lbs_set_mac_control(priv);
  867. done:
  868. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  869. return ret;
  870. }
  871. /**
  872. * This function handles the timeout of command sending.
  873. * It will re-send the same command again.
  874. */
  875. static void command_timer_fn(unsigned long data)
  876. {
  877. struct lbs_private *priv = (struct lbs_private *)data;
  878. unsigned long flags;
  879. lbs_deb_enter(LBS_DEB_CMD);
  880. spin_lock_irqsave(&priv->driver_lock, flags);
  881. if (!priv->cur_cmd)
  882. goto out;
  883. lbs_pr_info("command 0x%04x timed out\n",
  884. le16_to_cpu(priv->cur_cmd->cmdbuf->command));
  885. priv->cmd_timed_out = 1;
  886. wake_up_interruptible(&priv->waitq);
  887. out:
  888. spin_unlock_irqrestore(&priv->driver_lock, flags);
  889. lbs_deb_leave(LBS_DEB_CMD);
  890. }
  891. /**
  892. * This function put the device back to deep sleep mode when timer expires
  893. * and no activity (command, event, data etc.) is detected.
  894. */
  895. static void auto_deepsleep_timer_fn(unsigned long data)
  896. {
  897. struct lbs_private *priv = (struct lbs_private *)data;
  898. int ret;
  899. lbs_deb_enter(LBS_DEB_CMD);
  900. if (priv->is_activity_detected) {
  901. priv->is_activity_detected = 0;
  902. } else {
  903. if (priv->is_auto_deep_sleep_enabled &&
  904. (!priv->wakeup_dev_required) &&
  905. (priv->connect_status != LBS_CONNECTED)) {
  906. lbs_deb_main("Entering auto deep sleep mode...\n");
  907. ret = lbs_prepare_and_send_command(priv,
  908. CMD_802_11_DEEP_SLEEP, 0,
  909. 0, 0, NULL);
  910. }
  911. }
  912. mod_timer(&priv->auto_deepsleep_timer , jiffies +
  913. (priv->auto_deep_sleep_timeout * HZ)/1000);
  914. lbs_deb_leave(LBS_DEB_CMD);
  915. }
  916. int lbs_enter_auto_deep_sleep(struct lbs_private *priv)
  917. {
  918. lbs_deb_enter(LBS_DEB_SDIO);
  919. priv->is_auto_deep_sleep_enabled = 1;
  920. if (priv->is_deep_sleep)
  921. priv->wakeup_dev_required = 1;
  922. mod_timer(&priv->auto_deepsleep_timer ,
  923. jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000);
  924. lbs_deb_leave(LBS_DEB_SDIO);
  925. return 0;
  926. }
  927. int lbs_exit_auto_deep_sleep(struct lbs_private *priv)
  928. {
  929. lbs_deb_enter(LBS_DEB_SDIO);
  930. priv->is_auto_deep_sleep_enabled = 0;
  931. priv->auto_deep_sleep_timeout = 0;
  932. del_timer(&priv->auto_deepsleep_timer);
  933. lbs_deb_leave(LBS_DEB_SDIO);
  934. return 0;
  935. }
  936. static void lbs_sync_channel_worker(struct work_struct *work)
  937. {
  938. struct lbs_private *priv = container_of(work, struct lbs_private,
  939. sync_channel);
  940. lbs_deb_enter(LBS_DEB_MAIN);
  941. if (lbs_update_channel(priv))
  942. lbs_pr_info("Channel synchronization failed.");
  943. lbs_deb_leave(LBS_DEB_MAIN);
  944. }
  945. static int lbs_init_adapter(struct lbs_private *priv)
  946. {
  947. size_t bufsize;
  948. int i, ret = 0;
  949. lbs_deb_enter(LBS_DEB_MAIN);
  950. /* Allocate buffer to store the BSSID list */
  951. bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
  952. priv->networks = kzalloc(bufsize, GFP_KERNEL);
  953. if (!priv->networks) {
  954. lbs_pr_err("Out of memory allocating beacons\n");
  955. ret = -1;
  956. goto out;
  957. }
  958. /* Initialize scan result lists */
  959. INIT_LIST_HEAD(&priv->network_free_list);
  960. INIT_LIST_HEAD(&priv->network_list);
  961. for (i = 0; i < MAX_NETWORK_COUNT; i++) {
  962. list_add_tail(&priv->networks[i].list,
  963. &priv->network_free_list);
  964. }
  965. memset(priv->current_addr, 0xff, ETH_ALEN);
  966. priv->connect_status = LBS_DISCONNECTED;
  967. priv->mesh_connect_status = LBS_DISCONNECTED;
  968. priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  969. priv->mode = IW_MODE_INFRA;
  970. priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
  971. priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
  972. priv->radio_on = 1;
  973. priv->enablehwauto = 1;
  974. priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
  975. priv->psmode = LBS802_11POWERMODECAM;
  976. priv->psstate = PS_STATE_FULL_POWER;
  977. priv->is_deep_sleep = 0;
  978. priv->is_auto_deep_sleep_enabled = 0;
  979. priv->wakeup_dev_required = 0;
  980. init_waitqueue_head(&priv->ds_awake_q);
  981. mutex_init(&priv->lock);
  982. setup_timer(&priv->command_timer, command_timer_fn,
  983. (unsigned long)priv);
  984. setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn,
  985. (unsigned long)priv);
  986. INIT_LIST_HEAD(&priv->cmdfreeq);
  987. INIT_LIST_HEAD(&priv->cmdpendingq);
  988. spin_lock_init(&priv->driver_lock);
  989. init_waitqueue_head(&priv->cmd_pending);
  990. /* Allocate the command buffers */
  991. if (lbs_allocate_cmd_buffer(priv)) {
  992. lbs_pr_err("Out of memory allocating command buffers\n");
  993. ret = -ENOMEM;
  994. goto out;
  995. }
  996. priv->resp_idx = 0;
  997. priv->resp_len[0] = priv->resp_len[1] = 0;
  998. /* Create the event FIFO */
  999. priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL);
  1000. if (IS_ERR(priv->event_fifo)) {
  1001. lbs_pr_err("Out of memory allocating event FIFO buffer\n");
  1002. ret = -ENOMEM;
  1003. goto out;
  1004. }
  1005. out:
  1006. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  1007. return ret;
  1008. }
  1009. static void lbs_free_adapter(struct lbs_private *priv)
  1010. {
  1011. lbs_deb_enter(LBS_DEB_MAIN);
  1012. lbs_free_cmd_buffer(priv);
  1013. if (priv->event_fifo)
  1014. kfifo_free(priv->event_fifo);
  1015. del_timer(&priv->command_timer);
  1016. del_timer(&priv->auto_deepsleep_timer);
  1017. kfree(priv->networks);
  1018. priv->networks = NULL;
  1019. lbs_deb_leave(LBS_DEB_MAIN);
  1020. }
  1021. static const struct net_device_ops lbs_netdev_ops = {
  1022. .ndo_open = lbs_dev_open,
  1023. .ndo_stop = lbs_eth_stop,
  1024. .ndo_start_xmit = lbs_hard_start_xmit,
  1025. .ndo_set_mac_address = lbs_set_mac_address,
  1026. .ndo_tx_timeout = lbs_tx_timeout,
  1027. .ndo_set_multicast_list = lbs_set_multicast_list,
  1028. .ndo_change_mtu = eth_change_mtu,
  1029. .ndo_validate_addr = eth_validate_addr,
  1030. };
  1031. /**
  1032. * @brief This function adds the card. it will probe the
  1033. * card, allocate the lbs_priv and initialize the device.
  1034. *
  1035. * @param card A pointer to card
  1036. * @return A pointer to struct lbs_private structure
  1037. */
  1038. struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
  1039. {
  1040. struct net_device *dev;
  1041. struct wireless_dev *wdev;
  1042. struct lbs_private *priv = NULL;
  1043. lbs_deb_enter(LBS_DEB_MAIN);
  1044. /* Allocate an Ethernet device and register it */
  1045. wdev = lbs_cfg_alloc(dmdev);
  1046. if (IS_ERR(wdev)) {
  1047. lbs_pr_err("cfg80211 init failed\n");
  1048. goto done;
  1049. }
  1050. /* TODO? */
  1051. wdev->iftype = NL80211_IFTYPE_STATION;
  1052. priv = wdev_priv(wdev);
  1053. priv->wdev = wdev;
  1054. if (lbs_init_adapter(priv)) {
  1055. lbs_pr_err("failed to initialize adapter structure.\n");
  1056. goto err_wdev;
  1057. }
  1058. //TODO? dev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
  1059. dev = alloc_netdev(0, "wlan%d", ether_setup);
  1060. if (!dev) {
  1061. dev_err(dmdev, "no memory for network device instance\n");
  1062. goto err_adapter;
  1063. }
  1064. dev->netdev_ops = &lbs_netdev_ops;
  1065. dev->ieee80211_ptr = wdev;
  1066. dev->ml_priv = priv;
  1067. SET_NETDEV_DEV(dev, dmdev);
  1068. wdev->netdev = dev;
  1069. priv->dev = dev;
  1070. dev->netdev_ops = &lbs_netdev_ops;
  1071. dev->watchdog_timeo = 5 * HZ;
  1072. dev->ethtool_ops = &lbs_ethtool_ops;
  1073. #ifdef WIRELESS_EXT
  1074. dev->wireless_handlers = &lbs_handler_def;
  1075. #endif
  1076. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  1077. // TODO: kzalloc + iwm_init_default_profile(iwm, iwm->umac_profile); ??
  1078. priv->card = card;
  1079. priv->mesh_open = 0;
  1080. priv->infra_open = 0;
  1081. priv->rtap_net_dev = NULL;
  1082. strcpy(dev->name, "wlan%d");
  1083. lbs_deb_thread("Starting main thread...\n");
  1084. init_waitqueue_head(&priv->waitq);
  1085. priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
  1086. if (IS_ERR(priv->main_thread)) {
  1087. lbs_deb_thread("Error creating main thread.\n");
  1088. goto err_ndev;
  1089. }
  1090. priv->work_thread = create_singlethread_workqueue("lbs_worker");
  1091. INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
  1092. INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
  1093. INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
  1094. INIT_WORK(&priv->sync_channel, lbs_sync_channel_worker);
  1095. sprintf(priv->mesh_ssid, "mesh");
  1096. priv->mesh_ssid_len = 4;
  1097. priv->wol_criteria = 0xffffffff;
  1098. priv->wol_gpio = 0xff;
  1099. goto done;
  1100. err_ndev:
  1101. free_netdev(dev);
  1102. err_adapter:
  1103. lbs_free_adapter(priv);
  1104. err_wdev:
  1105. lbs_cfg_free(priv);
  1106. priv = NULL;
  1107. done:
  1108. lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
  1109. return priv;
  1110. }
  1111. EXPORT_SYMBOL_GPL(lbs_add_card);
  1112. void lbs_remove_card(struct lbs_private *priv)
  1113. {
  1114. struct net_device *dev = priv->dev;
  1115. union iwreq_data wrqu;
  1116. lbs_deb_enter(LBS_DEB_MAIN);
  1117. lbs_remove_mesh(priv);
  1118. lbs_remove_rtap(priv);
  1119. dev = priv->dev;
  1120. cancel_delayed_work_sync(&priv->scan_work);
  1121. cancel_delayed_work_sync(&priv->assoc_work);
  1122. cancel_work_sync(&priv->mcast_work);
  1123. /* worker thread destruction blocks on the in-flight command which
  1124. * should have been cleared already in lbs_stop_card().
  1125. */
  1126. lbs_deb_main("destroying worker thread\n");
  1127. destroy_workqueue(priv->work_thread);
  1128. lbs_deb_main("done destroying worker thread\n");
  1129. if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
  1130. priv->psmode = LBS802_11POWERMODECAM;
  1131. lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
  1132. }
  1133. memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
  1134. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1135. wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
  1136. if (priv->is_deep_sleep) {
  1137. priv->is_deep_sleep = 0;
  1138. wake_up_interruptible(&priv->ds_awake_q);
  1139. }
  1140. /* Stop the thread servicing the interrupts */
  1141. priv->surpriseremoved = 1;
  1142. kthread_stop(priv->main_thread);
  1143. lbs_free_adapter(priv);
  1144. lbs_cfg_free(priv);
  1145. priv->dev = NULL;
  1146. free_netdev(dev);
  1147. lbs_deb_leave(LBS_DEB_MAIN);
  1148. }
  1149. EXPORT_SYMBOL_GPL(lbs_remove_card);
  1150. int lbs_start_card(struct lbs_private *priv)
  1151. {
  1152. struct net_device *dev = priv->dev;
  1153. int ret = -1;
  1154. lbs_deb_enter(LBS_DEB_MAIN);
  1155. /* poke the firmware */
  1156. ret = lbs_setup_firmware(priv);
  1157. if (ret)
  1158. goto done;
  1159. /* init 802.11d */
  1160. lbs_init_11d(priv);
  1161. if (lbs_cfg_register(priv)) {
  1162. lbs_pr_err("cannot register device\n");
  1163. goto done;
  1164. }
  1165. lbs_update_channel(priv);
  1166. /* Check mesh FW version and appropriately send the mesh start
  1167. * command
  1168. */
  1169. if (priv->mesh_fw_ver == MESH_FW_OLD) {
  1170. /* Enable mesh, if supported, and work out which TLV it uses.
  1171. 0x100 + 291 is an unofficial value used in 5.110.20.pXX
  1172. 0x100 + 37 is the official value used in 5.110.21.pXX
  1173. but we check them in that order because 20.pXX doesn't
  1174. give an error -- it just silently fails. */
  1175. /* 5.110.20.pXX firmware will fail the command if the channel
  1176. doesn't match the existing channel. But only if the TLV
  1177. is correct. If the channel is wrong, _BOTH_ versions will
  1178. give an error to 0x100+291, and allow 0x100+37 to succeed.
  1179. It's just that 5.110.20.pXX will not have done anything
  1180. useful */
  1181. priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
  1182. if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
  1183. priv->curbssparams.channel)) {
  1184. priv->mesh_tlv = TLV_TYPE_MESH_ID;
  1185. if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
  1186. priv->curbssparams.channel))
  1187. priv->mesh_tlv = 0;
  1188. }
  1189. } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
  1190. /* 10.0.0.pXX new firmwares should succeed with TLV
  1191. * 0x100+37; Do not invoke command with old TLV.
  1192. */
  1193. priv->mesh_tlv = TLV_TYPE_MESH_ID;
  1194. if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
  1195. priv->curbssparams.channel))
  1196. priv->mesh_tlv = 0;
  1197. }
  1198. if (priv->mesh_tlv) {
  1199. lbs_add_mesh(priv);
  1200. if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
  1201. lbs_pr_err("cannot register lbs_mesh attribute\n");
  1202. /* While rtap isn't related to mesh, only mesh-enabled
  1203. * firmware implements the rtap functionality via
  1204. * CMD_802_11_MONITOR_MODE.
  1205. */
  1206. if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
  1207. lbs_pr_err("cannot register lbs_rtap attribute\n");
  1208. }
  1209. lbs_debugfs_init_one(priv, dev);
  1210. lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
  1211. ret = 0;
  1212. done:
  1213. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  1214. return ret;
  1215. }
  1216. EXPORT_SYMBOL_GPL(lbs_start_card);
  1217. void lbs_stop_card(struct lbs_private *priv)
  1218. {
  1219. struct net_device *dev;
  1220. struct cmd_ctrl_node *cmdnode;
  1221. unsigned long flags;
  1222. lbs_deb_enter(LBS_DEB_MAIN);
  1223. if (!priv)
  1224. goto out;
  1225. dev = priv->dev;
  1226. netif_stop_queue(dev);
  1227. netif_carrier_off(dev);
  1228. lbs_debugfs_remove_one(priv);
  1229. if (priv->mesh_tlv) {
  1230. device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
  1231. device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
  1232. }
  1233. /* Delete the timeout of the currently processing command */
  1234. del_timer_sync(&priv->command_timer);
  1235. del_timer_sync(&priv->auto_deepsleep_timer);
  1236. /* Flush pending command nodes */
  1237. spin_lock_irqsave(&priv->driver_lock, flags);
  1238. lbs_deb_main("clearing pending commands\n");
  1239. list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
  1240. cmdnode->result = -ENOENT;
  1241. cmdnode->cmdwaitqwoken = 1;
  1242. wake_up_interruptible(&cmdnode->cmdwait_q);
  1243. }
  1244. /* Flush the command the card is currently processing */
  1245. if (priv->cur_cmd) {
  1246. lbs_deb_main("clearing current command\n");
  1247. priv->cur_cmd->result = -ENOENT;
  1248. priv->cur_cmd->cmdwaitqwoken = 1;
  1249. wake_up_interruptible(&priv->cur_cmd->cmdwait_q);
  1250. }
  1251. lbs_deb_main("done clearing commands\n");
  1252. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1253. unregister_netdev(dev);
  1254. out:
  1255. lbs_deb_leave(LBS_DEB_MAIN);
  1256. }
  1257. EXPORT_SYMBOL_GPL(lbs_stop_card);
  1258. static const struct net_device_ops mesh_netdev_ops = {
  1259. .ndo_open = lbs_dev_open,
  1260. .ndo_stop = lbs_mesh_stop,
  1261. .ndo_start_xmit = lbs_hard_start_xmit,
  1262. .ndo_set_mac_address = lbs_set_mac_address,
  1263. .ndo_set_multicast_list = lbs_set_multicast_list,
  1264. };
  1265. /**
  1266. * @brief This function adds mshX interface
  1267. *
  1268. * @param priv A pointer to the struct lbs_private structure
  1269. * @return 0 if successful, -X otherwise
  1270. */
  1271. static int lbs_add_mesh(struct lbs_private *priv)
  1272. {
  1273. struct net_device *mesh_dev = NULL;
  1274. int ret = 0;
  1275. lbs_deb_enter(LBS_DEB_MESH);
  1276. /* Allocate a virtual mesh device */
  1277. if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
  1278. lbs_deb_mesh("init mshX device failed\n");
  1279. ret = -ENOMEM;
  1280. goto done;
  1281. }
  1282. mesh_dev->ml_priv = priv;
  1283. priv->mesh_dev = mesh_dev;
  1284. mesh_dev->netdev_ops = &mesh_netdev_ops;
  1285. mesh_dev->ethtool_ops = &lbs_ethtool_ops;
  1286. memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
  1287. sizeof(priv->dev->dev_addr));
  1288. SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
  1289. #ifdef WIRELESS_EXT
  1290. mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
  1291. #endif
  1292. mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  1293. /* Register virtual mesh interface */
  1294. ret = register_netdev(mesh_dev);
  1295. if (ret) {
  1296. lbs_pr_err("cannot register mshX virtual interface\n");
  1297. goto err_free;
  1298. }
  1299. ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
  1300. if (ret)
  1301. goto err_unregister;
  1302. lbs_persist_config_init(mesh_dev);
  1303. /* Everything successful */
  1304. ret = 0;
  1305. goto done;
  1306. err_unregister:
  1307. unregister_netdev(mesh_dev);
  1308. err_free:
  1309. free_netdev(mesh_dev);
  1310. done:
  1311. lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
  1312. return ret;
  1313. }
  1314. static void lbs_remove_mesh(struct lbs_private *priv)
  1315. {
  1316. struct net_device *mesh_dev;
  1317. mesh_dev = priv->mesh_dev;
  1318. if (!mesh_dev)
  1319. return;
  1320. lbs_deb_enter(LBS_DEB_MESH);
  1321. netif_stop_queue(mesh_dev);
  1322. netif_carrier_off(mesh_dev);
  1323. sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
  1324. lbs_persist_config_remove(mesh_dev);
  1325. unregister_netdev(mesh_dev);
  1326. priv->mesh_dev = NULL;
  1327. free_netdev(mesh_dev);
  1328. lbs_deb_leave(LBS_DEB_MESH);
  1329. }
  1330. /**
  1331. * @brief This function finds the CFP in
  1332. * region_cfp_table based on region and band parameter.
  1333. *
  1334. * @param region The region code
  1335. * @param band The band
  1336. * @param cfp_no A pointer to CFP number
  1337. * @return A pointer to CFP
  1338. */
  1339. struct chan_freq_power *lbs_get_region_cfp_table(u8 region, int *cfp_no)
  1340. {
  1341. int i, end;
  1342. lbs_deb_enter(LBS_DEB_MAIN);
  1343. end = ARRAY_SIZE(region_cfp_table);
  1344. for (i = 0; i < end ; i++) {
  1345. lbs_deb_main("region_cfp_table[i].region=%d\n",
  1346. region_cfp_table[i].region);
  1347. if (region_cfp_table[i].region == region) {
  1348. *cfp_no = region_cfp_table[i].cfp_no_BG;
  1349. lbs_deb_leave(LBS_DEB_MAIN);
  1350. return region_cfp_table[i].cfp_BG;
  1351. }
  1352. }
  1353. lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
  1354. return NULL;
  1355. }
  1356. int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
  1357. {
  1358. int ret = 0;
  1359. int i = 0;
  1360. struct chan_freq_power *cfp;
  1361. int cfp_no;
  1362. lbs_deb_enter(LBS_DEB_MAIN);
  1363. memset(priv->region_channel, 0, sizeof(priv->region_channel));
  1364. cfp = lbs_get_region_cfp_table(region, &cfp_no);
  1365. if (cfp != NULL) {
  1366. priv->region_channel[i].nrcfp = cfp_no;
  1367. priv->region_channel[i].CFP = cfp;
  1368. } else {
  1369. lbs_deb_main("wrong region code %#x in band B/G\n",
  1370. region);
  1371. ret = -1;
  1372. goto out;
  1373. }
  1374. priv->region_channel[i].valid = 1;
  1375. priv->region_channel[i].region = region;
  1376. priv->region_channel[i].band = band;
  1377. i++;
  1378. out:
  1379. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  1380. return ret;
  1381. }
  1382. void lbs_queue_event(struct lbs_private *priv, u32 event)
  1383. {
  1384. unsigned long flags;
  1385. lbs_deb_enter(LBS_DEB_THREAD);
  1386. spin_lock_irqsave(&priv->driver_lock, flags);
  1387. if (priv->psstate == PS_STATE_SLEEP)
  1388. priv->psstate = PS_STATE_AWAKE;
  1389. __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32));
  1390. wake_up_interruptible(&priv->waitq);
  1391. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1392. lbs_deb_leave(LBS_DEB_THREAD);
  1393. }
  1394. EXPORT_SYMBOL_GPL(lbs_queue_event);
  1395. void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
  1396. {
  1397. lbs_deb_enter(LBS_DEB_THREAD);
  1398. if (priv->psstate == PS_STATE_SLEEP)
  1399. priv->psstate = PS_STATE_AWAKE;
  1400. /* Swap buffers by flipping the response index */
  1401. BUG_ON(resp_idx > 1);
  1402. priv->resp_idx = resp_idx;
  1403. wake_up_interruptible(&priv->waitq);
  1404. lbs_deb_leave(LBS_DEB_THREAD);
  1405. }
  1406. EXPORT_SYMBOL_GPL(lbs_notify_command_response);
  1407. static int __init lbs_init_module(void)
  1408. {
  1409. lbs_deb_enter(LBS_DEB_MAIN);
  1410. memset(&confirm_sleep, 0, sizeof(confirm_sleep));
  1411. confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
  1412. confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
  1413. confirm_sleep.action = cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
  1414. lbs_debugfs_init();
  1415. lbs_deb_leave(LBS_DEB_MAIN);
  1416. return 0;
  1417. }
  1418. static void __exit lbs_exit_module(void)
  1419. {
  1420. lbs_deb_enter(LBS_DEB_MAIN);
  1421. lbs_debugfs_remove();
  1422. lbs_deb_leave(LBS_DEB_MAIN);
  1423. }
  1424. /*
  1425. * rtap interface support fuctions
  1426. */
  1427. static int lbs_rtap_open(struct net_device *dev)
  1428. {
  1429. /* Yes, _stop_ the queue. Because we don't support injection */
  1430. lbs_deb_enter(LBS_DEB_MAIN);
  1431. netif_carrier_off(dev);
  1432. netif_stop_queue(dev);
  1433. lbs_deb_leave(LBS_DEB_LEAVE);
  1434. return 0;
  1435. }
  1436. static int lbs_rtap_stop(struct net_device *dev)
  1437. {
  1438. lbs_deb_enter(LBS_DEB_MAIN);
  1439. lbs_deb_leave(LBS_DEB_MAIN);
  1440. return 0;
  1441. }
  1442. static netdev_tx_t lbs_rtap_hard_start_xmit(struct sk_buff *skb,
  1443. struct net_device *dev)
  1444. {
  1445. netif_stop_queue(dev);
  1446. return NETDEV_TX_BUSY;
  1447. }
  1448. static void lbs_remove_rtap(struct lbs_private *priv)
  1449. {
  1450. lbs_deb_enter(LBS_DEB_MAIN);
  1451. if (priv->rtap_net_dev == NULL)
  1452. goto out;
  1453. unregister_netdev(priv->rtap_net_dev);
  1454. free_netdev(priv->rtap_net_dev);
  1455. priv->rtap_net_dev = NULL;
  1456. out:
  1457. lbs_deb_leave(LBS_DEB_MAIN);
  1458. }
  1459. static const struct net_device_ops rtap_netdev_ops = {
  1460. .ndo_open = lbs_rtap_open,
  1461. .ndo_stop = lbs_rtap_stop,
  1462. .ndo_start_xmit = lbs_rtap_hard_start_xmit,
  1463. };
  1464. static int lbs_add_rtap(struct lbs_private *priv)
  1465. {
  1466. int ret = 0;
  1467. struct net_device *rtap_dev;
  1468. lbs_deb_enter(LBS_DEB_MAIN);
  1469. if (priv->rtap_net_dev) {
  1470. ret = -EPERM;
  1471. goto out;
  1472. }
  1473. rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
  1474. if (rtap_dev == NULL) {
  1475. ret = -ENOMEM;
  1476. goto out;
  1477. }
  1478. memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
  1479. rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
  1480. rtap_dev->netdev_ops = &rtap_netdev_ops;
  1481. rtap_dev->ml_priv = priv;
  1482. SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent);
  1483. ret = register_netdev(rtap_dev);
  1484. if (ret) {
  1485. free_netdev(rtap_dev);
  1486. goto out;
  1487. }
  1488. priv->rtap_net_dev = rtap_dev;
  1489. out:
  1490. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  1491. return ret;
  1492. }
  1493. module_init(lbs_init_module);
  1494. module_exit(lbs_exit_module);
  1495. MODULE_DESCRIPTION("Libertas WLAN Driver Library");
  1496. MODULE_AUTHOR("Marvell International Ltd.");
  1497. MODULE_LICENSE("GPL");