dhd_common.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540
  1. /*
  2. * Broadcom Dongle Host Driver (DHD), common DHD core.
  3. *
  4. * Copyright (C) 1999-2015, Broadcom Corporation
  5. *
  6. * Unless you and Broadcom execute a separate written software license
  7. * agreement governing use of this software, this software is licensed to you
  8. * under the terms of the GNU General Public License version 2 (the "GPL"),
  9. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  10. * following added to such license:
  11. *
  12. * As a special exception, the copyright holders of this software give you
  13. * permission to link this software with independent modules, and to copy and
  14. * distribute the resulting executable under terms of your choice, provided that
  15. * you also meet, for each linked independent module, the terms and conditions of
  16. * the license of that module. An independent module is a module which is not
  17. * derived from this software. The special exception does not apply to any
  18. * modifications of the software.
  19. *
  20. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. * $Id: dhd_common.c 605803 2015-12-11 14:44:32Z $
  25. */
  26. #include <typedefs.h>
  27. #include <osl.h>
  28. #include <epivers.h>
  29. #include <bcmutils.h>
  30. #include <bcmendian.h>
  31. #include <dngl_stats.h>
  32. #include <wlioctl.h>
  33. #include <dhd.h>
  34. #include <dhd_ip.h>
  35. #include <proto/bcmevent.h>
  36. #include <dhd_bus.h>
  37. #include <dhd_proto.h>
  38. #include <dhd_dbg.h>
  39. #include <msgtrace.h>
  40. #ifdef WL_CFG80211
  41. #include <wl_cfg80211.h>
  42. #endif
  43. #ifdef WLBTAMP
  44. #include <proto/bt_amp_hci.h>
  45. #include <dhd_bta.h>
  46. #endif
  47. #ifdef PNO_SUPPORT
  48. #include <dhd_pno.h>
  49. #endif
  50. #ifdef SET_RANDOM_MAC_SOFTAP
  51. #include <linux/random.h>
  52. #include <linux/jiffies.h>
  53. #endif
  54. #define htod32(i) (i)
  55. #define htod16(i) (i)
  56. #define dtoh32(i) (i)
  57. #define dtoh16(i) (i)
  58. #define htodchanspec(i) (i)
  59. #define dtohchanspec(i) (i)
  60. #ifdef PROP_TXSTATUS
  61. #include <wlfc_proto.h>
  62. #include <dhd_wlfc.h>
  63. #endif
  64. #ifdef WLMEDIA_HTSF
  65. extern void htsf_update(struct dhd_info *dhd, void *data);
  66. #endif
  67. int dhd_msg_level = DHD_ERROR_VAL;
  68. #ifdef SOFTAP
  69. char fw_path2[MOD_PARAM_PATHLEN];
  70. extern bool softap_enabled;
  71. #endif
  72. /* Last connection success/failure status */
  73. uint32 dhd_conn_event;
  74. uint32 dhd_conn_status;
  75. uint32 dhd_conn_reason;
  76. extern int dhd_iscan_request(void * dhdp, uint16 action);
  77. extern void dhd_ind_scan_confirm(void *h, bool status);
  78. extern int dhd_iscan_in_progress(void *h);
  79. void dhd_iscan_lock(void);
  80. void dhd_iscan_unlock(void);
  81. extern int dhd_change_mtu(dhd_pub_t *dhd, int new_mtu, int ifidx);
  82. #if !defined(AP) && defined(WLP2P)
  83. extern int dhd_get_concurrent_capabilites(dhd_pub_t *dhd);
  84. #endif
  85. bool ap_cfg_running = FALSE;
  86. bool ap_fw_loaded = FALSE;
  87. /* Version string to report */
  88. #ifdef DHD_DEBUG
  89. #ifndef SRCBASE
  90. #define SRCBASE "drivers/net/wireless/bcmdhd"
  91. #endif
  92. #define DHD_COMPILED "\nCompiled in " SRCBASE
  93. #endif /* DHD_DEBUG */
  94. #if defined(DHD_DEBUG)
  95. const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
  96. DHD_COMPILED " on " __DATE__ " at " __TIME__;
  97. #else
  98. const char dhd_version[] = "\nDongle Host Driver, version " EPI_VERSION_STR "\nCompiled from ";
  99. #endif
  100. #ifdef DHD_LOG_DUMP
  101. char fw_version[FW_VER_STR_LEN] = "\0";
  102. #endif /* DHD_LOG_DUMP */
  103. void dhd_set_timer(void *bus, uint wdtick);
  104. /* IOVar table */
  105. enum {
  106. IOV_VERSION = 1,
  107. IOV_MSGLEVEL,
  108. IOV_BCMERRORSTR,
  109. IOV_BCMERROR,
  110. IOV_WDTICK,
  111. IOV_DUMP,
  112. IOV_CLEARCOUNTS,
  113. IOV_LOGDUMP,
  114. IOV_LOGCAL,
  115. IOV_LOGSTAMP,
  116. IOV_GPIOOB,
  117. IOV_IOCTLTIMEOUT,
  118. #ifdef WLBTAMP
  119. IOV_HCI_CMD, /* HCI command */
  120. IOV_HCI_ACL_DATA, /* HCI data packet */
  121. #endif
  122. #if defined(DHD_DEBUG)
  123. IOV_CONS,
  124. IOV_DCONSOLE_POLL,
  125. #endif /* defined(DHD_DEBUG) */
  126. #ifdef PROP_TXSTATUS
  127. IOV_PROPTXSTATUS_ENABLE,
  128. IOV_PROPTXSTATUS_MODE,
  129. IOV_PROPTXSTATUS_OPT,
  130. IOV_PROPTXSTATUS_MODULE_IGNORE,
  131. IOV_PROPTXSTATUS_CREDIT_IGNORE,
  132. IOV_PROPTXSTATUS_TXSTATUS_IGNORE,
  133. IOV_PROPTXSTATUS_RXPKT_CHK,
  134. #endif /* PROP_TXSTATUS */
  135. IOV_BUS_TYPE,
  136. #ifdef WLMEDIA_HTSF
  137. IOV_WLPKTDLYSTAT_SZ,
  138. #endif
  139. IOV_CHANGEMTU,
  140. IOV_HOSTREORDER_FLOWS,
  141. #ifdef DHDTCPACK_SUPPRESS
  142. IOV_TCPACK_SUPPRESS,
  143. #endif /* DHDTCPACK_SUPPRESS */
  144. IOV_LAST
  145. };
  146. const bcm_iovar_t dhd_iovars[] = {
  147. {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(dhd_version) },
  148. #ifdef DHD_DEBUG
  149. {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0 },
  150. #endif /* DHD_DEBUG */
  151. {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN },
  152. {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0 },
  153. {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0 },
  154. {"dump", IOV_DUMP, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN },
  155. #ifdef DHD_DEBUG
  156. {"cons", IOV_CONS, 0, IOVT_BUFFER, 0 },
  157. {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0 },
  158. #endif
  159. {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0 },
  160. {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0 },
  161. {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0 },
  162. #ifdef WLBTAMP
  163. {"HCI_cmd", IOV_HCI_CMD, 0, IOVT_BUFFER, 0},
  164. {"HCI_ACL_data", IOV_HCI_ACL_DATA, 0, IOVT_BUFFER, 0},
  165. #endif
  166. #ifdef PROP_TXSTATUS
  167. {"proptx", IOV_PROPTXSTATUS_ENABLE, 0, IOVT_BOOL, 0 },
  168. /*
  169. set the proptxtstatus operation mode:
  170. 0 - Do not do any proptxtstatus flow control
  171. 1 - Use implied credit from a packet status
  172. 2 - Use explicit credit
  173. */
  174. {"ptxmode", IOV_PROPTXSTATUS_MODE, 0, IOVT_UINT32, 0 },
  175. {"proptx_opt", IOV_PROPTXSTATUS_OPT, 0, IOVT_UINT32, 0 },
  176. {"pmodule_ignore", IOV_PROPTXSTATUS_MODULE_IGNORE, 0, IOVT_BOOL, 0 },
  177. {"pcredit_ignore", IOV_PROPTXSTATUS_CREDIT_IGNORE, 0, IOVT_BOOL, 0 },
  178. {"ptxstatus_ignore", IOV_PROPTXSTATUS_TXSTATUS_IGNORE, 0, IOVT_BOOL, 0 },
  179. {"rxpkt_chk", IOV_PROPTXSTATUS_RXPKT_CHK, 0, IOVT_BOOL, 0 },
  180. #endif /* PROP_TXSTATUS */
  181. {"bustype", IOV_BUS_TYPE, 0, IOVT_UINT32, 0},
  182. #ifdef WLMEDIA_HTSF
  183. {"pktdlystatsz", IOV_WLPKTDLYSTAT_SZ, 0, IOVT_UINT8, 0 },
  184. #endif
  185. {"changemtu", IOV_CHANGEMTU, 0, IOVT_UINT32, 0 },
  186. {"host_reorder_flows", IOV_HOSTREORDER_FLOWS, 0, IOVT_BUFFER,
  187. (WLHOST_REORDERDATA_MAXFLOWS + 1) },
  188. #ifdef DHDTCPACK_SUPPRESS
  189. {"tcpack_suppress", IOV_TCPACK_SUPPRESS, 0, IOVT_UINT8, 0 },
  190. #endif /* DHDTCPACK_SUPPRESS */
  191. {NULL, 0, 0, 0, 0 }
  192. };
  193. #define DHD_IOVAR_BUF_SIZE 128
  194. /* to NDIS developer, the structure dhd_common is redundant,
  195. * please do NOT merge it back from other branches !!!
  196. */
  197. static int
  198. dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen)
  199. {
  200. char eabuf[ETHER_ADDR_STR_LEN];
  201. struct bcmstrbuf b;
  202. struct bcmstrbuf *strbuf = &b;
  203. if (!dhdp || !dhdp->prot || !buf)
  204. return BCME_ERROR;
  205. bcm_binit(strbuf, buf, buflen);
  206. /* Base DHD info */
  207. bcm_bprintf(strbuf, "%s\n", dhd_version);
  208. bcm_bprintf(strbuf, "\n");
  209. bcm_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n",
  210. dhdp->up, dhdp->txoff, dhdp->busstate);
  211. bcm_bprintf(strbuf, "pub.hdrlen %u pub.maxctl %u pub.rxsz %u\n",
  212. dhdp->hdrlen, dhdp->maxctl, dhdp->rxsz);
  213. bcm_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %s\n",
  214. dhdp->iswl, dhdp->drv_version, bcm_ether_ntoa(&dhdp->mac, eabuf));
  215. bcm_bprintf(strbuf, "pub.bcmerror %d tickcnt %u\n", dhdp->bcmerror, dhdp->tickcnt);
  216. bcm_bprintf(strbuf, "dongle stats:\n");
  217. bcm_bprintf(strbuf, "tx_packets %lu tx_bytes %lu tx_errors %lu tx_dropped %lu\n",
  218. dhdp->dstats.tx_packets, dhdp->dstats.tx_bytes,
  219. dhdp->dstats.tx_errors, dhdp->dstats.tx_dropped);
  220. bcm_bprintf(strbuf, "rx_packets %lu rx_bytes %lu rx_errors %lu rx_dropped %lu\n",
  221. dhdp->dstats.rx_packets, dhdp->dstats.rx_bytes,
  222. dhdp->dstats.rx_errors, dhdp->dstats.rx_dropped);
  223. bcm_bprintf(strbuf, "multicast %lu\n", dhdp->dstats.multicast);
  224. bcm_bprintf(strbuf, "bus stats:\n");
  225. bcm_bprintf(strbuf, "tx_packets %lu tx_multicast %lu tx_errors %lu\n",
  226. dhdp->tx_packets, dhdp->tx_multicast, dhdp->tx_errors);
  227. bcm_bprintf(strbuf, "tx_ctlpkts %lu tx_ctlerrs %lu\n",
  228. dhdp->tx_ctlpkts, dhdp->tx_ctlerrs);
  229. bcm_bprintf(strbuf, "rx_packets %lu rx_multicast %lu rx_errors %lu \n",
  230. dhdp->rx_packets, dhdp->rx_multicast, dhdp->rx_errors);
  231. bcm_bprintf(strbuf, "rx_ctlpkts %lu rx_ctlerrs %lu rx_dropped %lu\n",
  232. dhdp->rx_ctlpkts, dhdp->rx_ctlerrs, dhdp->rx_dropped);
  233. bcm_bprintf(strbuf, "rx_readahead_cnt %lu tx_realloc %lu\n",
  234. dhdp->rx_readahead_cnt, dhdp->tx_realloc);
  235. bcm_bprintf(strbuf, "\n");
  236. /* Add any prot info */
  237. dhd_prot_dump(dhdp, strbuf);
  238. bcm_bprintf(strbuf, "\n");
  239. /* Add any bus info */
  240. dhd_bus_dump(dhdp, strbuf);
  241. return (!strbuf->size ? BCME_BUFTOOSHORT : 0);
  242. }
  243. int
  244. dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set, int ifindex)
  245. {
  246. wl_ioctl_t ioc;
  247. ioc.cmd = cmd;
  248. ioc.buf = arg;
  249. ioc.len = len;
  250. ioc.set = set;
  251. return dhd_wl_ioctl(dhd_pub, ifindex, &ioc, arg, len);
  252. }
  253. int
  254. dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len)
  255. {
  256. int ret = 0;
  257. if (dhd_os_proto_block(dhd_pub))
  258. {
  259. #ifdef DHD_LOG_DUMP
  260. int slen, i, val, rem;
  261. long int lval;
  262. char *pval, *pos, *msg;
  263. char tmp[64];
  264. /* WLC_GET_VAR */
  265. if (ioc->cmd == WLC_GET_VAR) {
  266. memset(tmp, 0, sizeof(tmp));
  267. bcopy(ioc->buf, tmp, strlen(ioc->buf) + 1);
  268. }
  269. #endif /* DHD_LOG_DUMP */
  270. ret = dhd_prot_ioctl(dhd_pub, ifindex, ioc, buf, len);
  271. #if defined(CUSTOMER_HW4)
  272. if ((ret || ret == -ETIMEDOUT) && (dhd_pub->up))
  273. #else
  274. if ((ret) && (dhd_pub->up))
  275. #endif /* CUSTOMER_HW4 */
  276. /* Send hang event only if dhd_open() was success */
  277. dhd_os_check_hang(dhd_pub, ifindex, ret);
  278. if (ret == -ETIMEDOUT && !dhd_pub->up) {
  279. DHD_ERROR(("%s: 'resumed on timeout' error is "
  280. "occurred before the interface does not"
  281. " bring up\n", __FUNCTION__));
  282. dhd_pub->busstate = DHD_BUS_DOWN;
  283. }
  284. dhd_os_proto_unblock(dhd_pub);
  285. #ifdef DHD_LOG_DUMP
  286. if (ioc->cmd == WLC_GET_VAR || ioc->cmd == WLC_SET_VAR) {
  287. lval = 0;
  288. slen = strlen(ioc->buf) + 1;
  289. msg = (char*)ioc->buf;
  290. if (ioc->cmd == WLC_GET_VAR) {
  291. bcopy(msg, &lval, sizeof(long int));
  292. msg = tmp;
  293. } else {
  294. bcopy((msg + slen), &lval, sizeof(long int));
  295. }
  296. DHD_ERROR_EX(("%s: cmd: %d, msg: %s, val: 0x%lx, len: %d, set: %d\n",
  297. ioc->cmd == WLC_GET_VAR ? "WLC_GET_VAR" : "WLC_SET_VAR",
  298. ioc->cmd, msg, lval, ioc->len, ioc->set));
  299. } else {
  300. slen = ioc->len;
  301. if (ioc->buf != NULL) {
  302. val = *(int*)ioc->buf;
  303. pval = (char*)ioc->buf;
  304. pos = tmp;
  305. rem = sizeof(tmp);
  306. memset(tmp, 0, sizeof(tmp));
  307. for (i = 0; i < slen; i++) {
  308. pos += snprintf(pos, rem, "%02x ", pval[i]);
  309. rem = sizeof(tmp) - (int)(pos - tmp);
  310. if (rem <= 0) {
  311. break;
  312. }
  313. }
  314. DHD_ERROR_EX(("WLC_IOCTL: cmd: %d, val: %d (%s), len: %d, "
  315. "set: %d\n", ioc->cmd, val, tmp, ioc->len, ioc->set));
  316. } else {
  317. DHD_ERROR_EX(("WLC_IOCTL: cmd: %d, buf is NULL\n", ioc->cmd));
  318. }
  319. }
  320. #endif /* DHD_LOG_DUMP */
  321. #if defined(CUSTOMER_HW4)
  322. if (ret < 0) {
  323. if (ioc->cmd == WLC_GET_VAR)
  324. DHD_ERROR(("%s: WLC_GET_VAR: %s, ret = %d\n",
  325. __FUNCTION__, (char *)ioc->buf, ret));
  326. else if (ioc->cmd == WLC_SET_VAR)
  327. DHD_ERROR(("%s: WLC_SET_VAR: %s, ret = %d\n",
  328. __FUNCTION__, (char *)ioc->buf, ret));
  329. else
  330. DHD_ERROR(("%s: WLC_IOCTL: cmd: %d, ret = %d\n",
  331. __FUNCTION__, ioc->cmd, ret));
  332. }
  333. #endif /* OEM_ANDROID && CUSTOMER_HW4 */
  334. }
  335. return ret;
  336. }
  337. static int
  338. dhd_doiovar(dhd_pub_t *dhd_pub, const bcm_iovar_t *vi, uint32 actionid, const char *name,
  339. void *params, int plen, void *arg, int len, int val_size)
  340. {
  341. int bcmerror = 0;
  342. int32 int_val = 0;
  343. DHD_TRACE(("%s: Enter\n", __FUNCTION__));
  344. DHD_TRACE(("%s: actionid = %d; name %s\n", __FUNCTION__, actionid, name));
  345. if ((bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid))) != 0)
  346. goto exit;
  347. if (plen >= (int)sizeof(int_val))
  348. bcopy(params, &int_val, sizeof(int_val));
  349. switch (actionid) {
  350. case IOV_GVAL(IOV_VERSION):
  351. /* Need to have checked buffer length */
  352. bcm_strncpy_s((char*)arg, len, dhd_version, len);
  353. break;
  354. case IOV_GVAL(IOV_MSGLEVEL):
  355. int_val = (int32)dhd_msg_level;
  356. bcopy(&int_val, arg, val_size);
  357. break;
  358. case IOV_SVAL(IOV_MSGLEVEL):
  359. #ifdef WL_CFG80211
  360. /* Enable DHD and WL logs in oneshot */
  361. if (int_val & DHD_WL_VAL2)
  362. wl_cfg80211_enable_trace(TRUE, int_val & (~DHD_WL_VAL2));
  363. else if (int_val & DHD_WL_VAL)
  364. wl_cfg80211_enable_trace(FALSE, WL_DBG_DBG);
  365. if (!(int_val & DHD_WL_VAL2))
  366. #endif /* WL_CFG80211 */
  367. dhd_msg_level = int_val;
  368. break;
  369. case IOV_GVAL(IOV_BCMERRORSTR):
  370. bcm_strncpy_s((char *)arg, len, bcmerrorstr(dhd_pub->bcmerror), BCME_STRLEN);
  371. ((char *)arg)[BCME_STRLEN - 1] = 0x00;
  372. break;
  373. case IOV_GVAL(IOV_BCMERROR):
  374. int_val = (int32)dhd_pub->bcmerror;
  375. bcopy(&int_val, arg, val_size);
  376. break;
  377. case IOV_GVAL(IOV_WDTICK):
  378. int_val = (int32)dhd_watchdog_ms;
  379. bcopy(&int_val, arg, val_size);
  380. break;
  381. case IOV_SVAL(IOV_WDTICK):
  382. if (!dhd_pub->up) {
  383. bcmerror = BCME_NOTUP;
  384. break;
  385. }
  386. dhd_os_wd_timer(dhd_pub, (uint)int_val);
  387. break;
  388. case IOV_GVAL(IOV_DUMP):
  389. bcmerror = dhd_dump(dhd_pub, arg, len);
  390. break;
  391. #ifdef DHD_DEBUG
  392. case IOV_GVAL(IOV_DCONSOLE_POLL):
  393. int_val = (int32)dhd_console_ms;
  394. bcopy(&int_val, arg, val_size);
  395. break;
  396. case IOV_SVAL(IOV_DCONSOLE_POLL):
  397. dhd_console_ms = (uint)int_val;
  398. break;
  399. case IOV_SVAL(IOV_CONS):
  400. if (len > 0)
  401. bcmerror = dhd_bus_console_in(dhd_pub, arg, len - 1);
  402. break;
  403. #endif /* DHD_DEBUG */
  404. case IOV_SVAL(IOV_CLEARCOUNTS):
  405. dhd_pub->tx_packets = dhd_pub->rx_packets = 0;
  406. dhd_pub->tx_errors = dhd_pub->rx_errors = 0;
  407. dhd_pub->tx_ctlpkts = dhd_pub->rx_ctlpkts = 0;
  408. dhd_pub->tx_ctlerrs = dhd_pub->rx_ctlerrs = 0;
  409. dhd_pub->rx_dropped = 0;
  410. dhd_pub->rx_readahead_cnt = 0;
  411. dhd_pub->tx_realloc = 0;
  412. dhd_pub->wd_dpc_sched = 0;
  413. memset(&dhd_pub->dstats, 0, sizeof(dhd_pub->dstats));
  414. dhd_bus_clearcounts(dhd_pub);
  415. #ifdef PROP_TXSTATUS
  416. /* clear proptxstatus related counters */
  417. dhd_wlfc_clear_counts(dhd_pub);
  418. #endif /* PROP_TXSTATUS */
  419. break;
  420. case IOV_GVAL(IOV_IOCTLTIMEOUT): {
  421. int_val = (int32)dhd_os_get_ioctl_resp_timeout();
  422. bcopy(&int_val, arg, sizeof(int_val));
  423. break;
  424. }
  425. case IOV_SVAL(IOV_IOCTLTIMEOUT): {
  426. if (int_val <= 0)
  427. bcmerror = BCME_BADARG;
  428. else
  429. dhd_os_set_ioctl_resp_timeout((unsigned int)int_val);
  430. break;
  431. }
  432. #ifdef WLBTAMP
  433. case IOV_SVAL(IOV_HCI_CMD): {
  434. amp_hci_cmd_t *cmd = (amp_hci_cmd_t *)arg;
  435. /* sanity check: command preamble present */
  436. if (len < HCI_CMD_PREAMBLE_SIZE)
  437. return BCME_BUFTOOSHORT;
  438. /* sanity check: command parameters are present */
  439. if (len < (int)(HCI_CMD_PREAMBLE_SIZE + cmd->plen))
  440. return BCME_BUFTOOSHORT;
  441. dhd_bta_docmd(dhd_pub, cmd, len);
  442. break;
  443. }
  444. case IOV_SVAL(IOV_HCI_ACL_DATA): {
  445. amp_hci_ACL_data_t *ACL_data = (amp_hci_ACL_data_t *)arg;
  446. /* sanity check: HCI header present */
  447. if (len < HCI_ACL_DATA_PREAMBLE_SIZE)
  448. return BCME_BUFTOOSHORT;
  449. /* sanity check: ACL data is present */
  450. if (len < (int)(HCI_ACL_DATA_PREAMBLE_SIZE + ACL_data->dlen))
  451. return BCME_BUFTOOSHORT;
  452. dhd_bta_tx_hcidata(dhd_pub, ACL_data, len);
  453. break;
  454. }
  455. #endif /* WLBTAMP */
  456. #ifdef PROP_TXSTATUS
  457. case IOV_GVAL(IOV_PROPTXSTATUS_ENABLE): {
  458. bool wlfc_enab = FALSE;
  459. bcmerror = dhd_wlfc_get_enable(dhd_pub, &wlfc_enab);
  460. if (bcmerror != BCME_OK)
  461. goto exit;
  462. int_val = wlfc_enab ? 1 : 0;
  463. bcopy(&int_val, arg, val_size);
  464. break;
  465. }
  466. case IOV_SVAL(IOV_PROPTXSTATUS_ENABLE): {
  467. bool wlfc_enab = FALSE;
  468. bcmerror = dhd_wlfc_get_enable(dhd_pub, &wlfc_enab);
  469. if (bcmerror != BCME_OK)
  470. goto exit;
  471. /* wlfc is already set as desired */
  472. if (wlfc_enab == (int_val == 0 ? FALSE : TRUE))
  473. goto exit;
  474. if (int_val == TRUE)
  475. bcmerror = dhd_wlfc_init(dhd_pub);
  476. else
  477. bcmerror = dhd_wlfc_deinit(dhd_pub);
  478. break;
  479. }
  480. case IOV_GVAL(IOV_PROPTXSTATUS_MODE):
  481. bcmerror = dhd_wlfc_get_mode(dhd_pub, &int_val);
  482. if (bcmerror != BCME_OK)
  483. goto exit;
  484. bcopy(&int_val, arg, val_size);
  485. break;
  486. case IOV_SVAL(IOV_PROPTXSTATUS_MODE):
  487. dhd_wlfc_set_mode(dhd_pub, int_val);
  488. break;
  489. case IOV_GVAL(IOV_PROPTXSTATUS_MODULE_IGNORE):
  490. bcmerror = dhd_wlfc_get_module_ignore(dhd_pub, &int_val);
  491. if (bcmerror != BCME_OK)
  492. goto exit;
  493. bcopy(&int_val, arg, val_size);
  494. break;
  495. case IOV_SVAL(IOV_PROPTXSTATUS_MODULE_IGNORE):
  496. dhd_wlfc_set_module_ignore(dhd_pub, int_val);
  497. break;
  498. case IOV_GVAL(IOV_PROPTXSTATUS_CREDIT_IGNORE):
  499. bcmerror = dhd_wlfc_get_credit_ignore(dhd_pub, &int_val);
  500. if (bcmerror != BCME_OK)
  501. goto exit;
  502. bcopy(&int_val, arg, val_size);
  503. break;
  504. case IOV_SVAL(IOV_PROPTXSTATUS_CREDIT_IGNORE):
  505. dhd_wlfc_set_credit_ignore(dhd_pub, int_val);
  506. break;
  507. case IOV_GVAL(IOV_PROPTXSTATUS_TXSTATUS_IGNORE):
  508. bcmerror = dhd_wlfc_get_txstatus_ignore(dhd_pub, &int_val);
  509. if (bcmerror != BCME_OK)
  510. goto exit;
  511. bcopy(&int_val, arg, val_size);
  512. break;
  513. case IOV_SVAL(IOV_PROPTXSTATUS_TXSTATUS_IGNORE):
  514. dhd_wlfc_set_txstatus_ignore(dhd_pub, int_val);
  515. break;
  516. case IOV_GVAL(IOV_PROPTXSTATUS_RXPKT_CHK):
  517. bcmerror = dhd_wlfc_get_rxpkt_chk(dhd_pub, &int_val);
  518. if (bcmerror != BCME_OK)
  519. goto exit;
  520. bcopy(&int_val, arg, val_size);
  521. break;
  522. case IOV_SVAL(IOV_PROPTXSTATUS_RXPKT_CHK):
  523. dhd_wlfc_set_rxpkt_chk(dhd_pub, int_val);
  524. break;
  525. #endif /* PROP_TXSTATUS */
  526. case IOV_GVAL(IOV_BUS_TYPE):
  527. /* The dhd application queries the driver to check if its usb or sdio. */
  528. #ifdef BCMDHDUSB
  529. int_val = BUS_TYPE_USB;
  530. #endif
  531. int_val = BUS_TYPE_SDIO;
  532. #ifdef PCIE_FULL_DONGLE
  533. int_val = BUS_TYPE_PCIE;
  534. #endif
  535. bcopy(&int_val, arg, val_size);
  536. break;
  537. #ifdef WLMEDIA_HTSF
  538. case IOV_GVAL(IOV_WLPKTDLYSTAT_SZ):
  539. int_val = dhd_pub->htsfdlystat_sz;
  540. bcopy(&int_val, arg, val_size);
  541. break;
  542. case IOV_SVAL(IOV_WLPKTDLYSTAT_SZ):
  543. dhd_pub->htsfdlystat_sz = int_val & 0xff;
  544. printf("Setting tsfdlystat_sz:%d\n", dhd_pub->htsfdlystat_sz);
  545. break;
  546. #endif
  547. case IOV_SVAL(IOV_CHANGEMTU):
  548. int_val &= 0xffff;
  549. bcmerror = dhd_change_mtu(dhd_pub, int_val, 0);
  550. break;
  551. case IOV_GVAL(IOV_HOSTREORDER_FLOWS):
  552. {
  553. uint i = 0;
  554. uint8 *ptr = (uint8 *)arg;
  555. uint8 count = 0;
  556. ptr++;
  557. for (i = 0; i < WLHOST_REORDERDATA_MAXFLOWS; i++) {
  558. if (dhd_pub->reorder_bufs[i] != NULL) {
  559. *ptr = dhd_pub->reorder_bufs[i]->flow_id;
  560. ptr++;
  561. count++;
  562. }
  563. }
  564. ptr = (uint8 *)arg;
  565. *ptr = count;
  566. break;
  567. }
  568. #ifdef DHDTCPACK_SUPPRESS
  569. case IOV_GVAL(IOV_TCPACK_SUPPRESS): {
  570. int_val = (uint32)dhd_pub->tcpack_sup_mode;
  571. bcopy(&int_val, arg, val_size);
  572. break;
  573. }
  574. case IOV_SVAL(IOV_TCPACK_SUPPRESS): {
  575. bcmerror = dhd_tcpack_suppress_set(dhd_pub, (uint8)int_val);
  576. break;
  577. }
  578. #endif /* DHDTCPACK_SUPPRESS */
  579. default:
  580. bcmerror = BCME_UNSUPPORTED;
  581. break;
  582. }
  583. exit:
  584. DHD_TRACE(("%s: actionid %d, bcmerror %d\n", __FUNCTION__, actionid, bcmerror));
  585. return bcmerror;
  586. }
  587. /* Store the status of a connection attempt for later retrieval by an iovar */
  588. void
  589. dhd_store_conn_status(uint32 event, uint32 status, uint32 reason)
  590. {
  591. /* Do not overwrite a WLC_E_PRUNE with a WLC_E_SET_SSID
  592. * because an encryption/rsn mismatch results in both events, and
  593. * the important information is in the WLC_E_PRUNE.
  594. */
  595. if (!(event == WLC_E_SET_SSID && status == WLC_E_STATUS_FAIL &&
  596. dhd_conn_event == WLC_E_PRUNE)) {
  597. dhd_conn_event = event;
  598. dhd_conn_status = status;
  599. dhd_conn_reason = reason;
  600. }
  601. }
  602. bool
  603. dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec)
  604. {
  605. void *p;
  606. int eprec = -1; /* precedence to evict from */
  607. bool discard_oldest;
  608. /* Fast case, precedence queue is not full and we are also not
  609. * exceeding total queue length
  610. */
  611. if (!pktq_pfull(q, prec) && !pktq_full(q)) {
  612. pktq_penq(q, prec, pkt);
  613. return TRUE;
  614. }
  615. /* Determine precedence from which to evict packet, if any */
  616. if (pktq_pfull(q, prec))
  617. eprec = prec;
  618. else if (pktq_full(q)) {
  619. p = pktq_peek_tail(q, &eprec);
  620. ASSERT(p);
  621. if (eprec > prec || eprec < 0)
  622. return FALSE;
  623. }
  624. /* Evict if needed */
  625. if (eprec >= 0) {
  626. /* Detect queueing to unconfigured precedence */
  627. ASSERT(!pktq_pempty(q, eprec));
  628. discard_oldest = AC_BITMAP_TST(dhdp->wme_dp, eprec);
  629. if (eprec == prec && !discard_oldest)
  630. return FALSE; /* refuse newer (incoming) packet */
  631. /* Evict packet according to discard policy */
  632. p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q, eprec);
  633. ASSERT(p);
  634. #ifdef DHDTCPACK_SUPPRESS
  635. if (dhd_tcpack_check_xmit(dhdp, p) == BCME_ERROR) {
  636. DHD_ERROR(("%s %d: tcpack_suppress ERROR!!! Stop using it\n",
  637. __FUNCTION__, __LINE__));
  638. dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_OFF);
  639. }
  640. #endif /* DHDTCPACK_SUPPRESS */
  641. PKTFREE(dhdp->osh, p, TRUE);
  642. }
  643. /* Enqueue */
  644. p = pktq_penq(q, prec, pkt);
  645. ASSERT(p);
  646. return TRUE;
  647. }
  648. /*
  649. * Functions to drop proper pkts from queue:
  650. * If one pkt in queue is non-fragmented, drop first non-fragmented pkt only
  651. * If all pkts in queue are all fragmented, find and drop one whole set fragmented pkts
  652. * If can't find pkts matching upper 2 cases, drop first pkt anyway
  653. */
  654. bool
  655. dhd_prec_drop_pkts(dhd_pub_t *dhdp, struct pktq *pq, int prec, f_droppkt_t fn)
  656. {
  657. struct pktq_prec *q = NULL;
  658. void *p, *prev = NULL, *next = NULL, *first = NULL, *last = NULL, *prev_first = NULL;
  659. pkt_frag_t frag_info;
  660. ASSERT(dhdp && pq);
  661. ASSERT(prec >= 0 && prec < pq->num_prec);
  662. q = &pq->q[prec];
  663. p = q->head;
  664. if (p == NULL)
  665. return FALSE;
  666. while (p) {
  667. frag_info = pkt_frag_info(dhdp->osh, p);
  668. if (frag_info == DHD_PKT_FRAG_NONE) {
  669. break;
  670. } else if (frag_info == DHD_PKT_FRAG_FIRST) {
  671. if (first) {
  672. /* No last frag pkt, use prev as last */
  673. last = prev;
  674. break;
  675. } else {
  676. first = p;
  677. prev_first = prev;
  678. }
  679. } else if (frag_info == DHD_PKT_FRAG_LAST) {
  680. if (first) {
  681. last = p;
  682. break;
  683. }
  684. }
  685. prev = p;
  686. p = PKTLINK(p);
  687. }
  688. if ((p == NULL) || ((frag_info != DHD_PKT_FRAG_NONE) && !(first && last))) {
  689. /* Not found matching pkts, use oldest */
  690. prev = NULL;
  691. p = q->head;
  692. frag_info = 0;
  693. }
  694. if (frag_info == DHD_PKT_FRAG_NONE) {
  695. first = last = p;
  696. prev_first = prev;
  697. }
  698. p = first;
  699. while (p) {
  700. next = PKTLINK(p);
  701. q->len--;
  702. pq->len--;
  703. PKTSETLINK(p, NULL);
  704. if (fn)
  705. fn(dhdp, prec, p, TRUE);
  706. if (p == last)
  707. break;
  708. p = next;
  709. }
  710. if (prev_first == NULL) {
  711. if ((q->head = next) == NULL)
  712. q->tail = NULL;
  713. } else {
  714. PKTSETLINK(prev_first, next);
  715. if (!next)
  716. q->tail = prev_first;
  717. }
  718. return TRUE;
  719. }
  720. static int
  721. dhd_iovar_op(dhd_pub_t *dhd_pub, const char *name,
  722. void *params, int plen, void *arg, int len, bool set)
  723. {
  724. int bcmerror = 0;
  725. int val_size;
  726. const bcm_iovar_t *vi = NULL;
  727. uint32 actionid;
  728. DHD_TRACE(("%s: Enter\n", __FUNCTION__));
  729. ASSERT(name);
  730. ASSERT(len >= 0);
  731. /* Get MUST have return space */
  732. ASSERT(set || (arg && len));
  733. /* Set does NOT take qualifiers */
  734. ASSERT(!set || (!params && !plen));
  735. if ((vi = bcm_iovar_lookup(dhd_iovars, name)) == NULL) {
  736. bcmerror = BCME_UNSUPPORTED;
  737. goto exit;
  738. }
  739. DHD_CTL(("%s: %s %s, len %d plen %d\n", __FUNCTION__,
  740. name, (set ? "set" : "get"), len, plen));
  741. /* set up 'params' pointer in case this is a set command so that
  742. * the convenience int and bool code can be common to set and get
  743. */
  744. if (params == NULL) {
  745. params = arg;
  746. plen = len;
  747. }
  748. if (vi->type == IOVT_VOID)
  749. val_size = 0;
  750. else if (vi->type == IOVT_BUFFER)
  751. val_size = len;
  752. else
  753. /* all other types are integer sized */
  754. val_size = sizeof(int);
  755. actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
  756. bcmerror = dhd_doiovar(dhd_pub, vi, actionid, name, params, plen, arg, len, val_size);
  757. exit:
  758. return bcmerror;
  759. }
  760. int
  761. dhd_ioctl(dhd_pub_t * dhd_pub, dhd_ioctl_t *ioc, void * buf, uint buflen)
  762. {
  763. int bcmerror = 0;
  764. DHD_TRACE(("%s: Enter\n", __FUNCTION__));
  765. if (!buf) {
  766. return BCME_BADARG;
  767. }
  768. switch (ioc->cmd) {
  769. case DHD_GET_MAGIC:
  770. if (buflen < sizeof(int))
  771. bcmerror = BCME_BUFTOOSHORT;
  772. else
  773. *(int*)buf = DHD_IOCTL_MAGIC;
  774. break;
  775. case DHD_GET_VERSION:
  776. if (buflen < sizeof(int))
  777. bcmerror = BCME_BUFTOOSHORT;
  778. else
  779. *(int*)buf = DHD_IOCTL_VERSION;
  780. break;
  781. case DHD_GET_VAR:
  782. case DHD_SET_VAR: {
  783. char *arg;
  784. uint arglen;
  785. /* scan past the name to any arguments */
  786. for (arg = buf, arglen = buflen; *arg && arglen; arg++, arglen--)
  787. ;
  788. if (*arg) {
  789. bcmerror = BCME_BUFTOOSHORT;
  790. break;
  791. }
  792. /* account for the NUL terminator */
  793. arg++, arglen--;
  794. /* call with the appropriate arguments */
  795. if (ioc->cmd == DHD_GET_VAR)
  796. bcmerror = dhd_iovar_op(dhd_pub, buf, arg, arglen,
  797. buf, buflen, IOV_GET);
  798. else
  799. bcmerror = dhd_iovar_op(dhd_pub, buf, NULL, 0, arg, arglen, IOV_SET);
  800. if (bcmerror != BCME_UNSUPPORTED)
  801. break;
  802. /* not in generic table, try protocol module */
  803. if (ioc->cmd == DHD_GET_VAR)
  804. bcmerror = dhd_prot_iovar_op(dhd_pub, buf, arg,
  805. arglen, buf, buflen, IOV_GET);
  806. else
  807. bcmerror = dhd_prot_iovar_op(dhd_pub, buf,
  808. NULL, 0, arg, arglen, IOV_SET);
  809. if (bcmerror != BCME_UNSUPPORTED)
  810. break;
  811. /* if still not found, try bus module */
  812. if (ioc->cmd == DHD_GET_VAR) {
  813. bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
  814. arg, arglen, buf, buflen, IOV_GET);
  815. } else {
  816. bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
  817. NULL, 0, arg, arglen, IOV_SET);
  818. }
  819. break;
  820. }
  821. default:
  822. bcmerror = BCME_UNSUPPORTED;
  823. }
  824. return bcmerror;
  825. }
  826. #ifdef SHOW_EVENTS
  827. static void
  828. wl_show_host_event(wl_event_msg_t *event, void *event_data)
  829. {
  830. uint i, status, reason;
  831. bool group = FALSE, flush_txq = FALSE, link = FALSE;
  832. const char *auth_str;
  833. const char *event_name;
  834. uchar *buf;
  835. char err_msg[256], eabuf[ETHER_ADDR_STR_LEN];
  836. uint event_type, flags, auth_type, datalen;
  837. event_type = ntoh32(event->event_type);
  838. flags = ntoh16(event->flags);
  839. status = ntoh32(event->status);
  840. reason = ntoh32(event->reason);
  841. BCM_REFERENCE(reason);
  842. auth_type = ntoh32(event->auth_type);
  843. datalen = ntoh32(event->datalen);
  844. /* debug dump of event messages */
  845. snprintf(eabuf, sizeof(eabuf), "%02x:%02x:%02x:%02x:%02x:%02x",
  846. (uchar)event->addr.octet[0]&0xff,
  847. (uchar)event->addr.octet[1]&0xff,
  848. (uchar)event->addr.octet[2]&0xff,
  849. (uchar)event->addr.octet[3]&0xff,
  850. (uchar)event->addr.octet[4]&0xff,
  851. (uchar)event->addr.octet[5]&0xff);
  852. event_name = "UNKNOWN";
  853. for (i = 0; i < (uint)bcmevent_names_size; i++)
  854. if (bcmevent_names[i].event == event_type)
  855. event_name = bcmevent_names[i].name;
  856. if (flags & WLC_EVENT_MSG_LINK)
  857. link = TRUE;
  858. if (flags & WLC_EVENT_MSG_GROUP)
  859. group = TRUE;
  860. if (flags & WLC_EVENT_MSG_FLUSHTXQ)
  861. flush_txq = TRUE;
  862. switch (event_type) {
  863. case WLC_E_START:
  864. case WLC_E_DEAUTH:
  865. case WLC_E_DISASSOC:
  866. DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
  867. break;
  868. case WLC_E_ASSOC_IND:
  869. case WLC_E_REASSOC_IND:
  870. DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
  871. break;
  872. case WLC_E_ASSOC:
  873. case WLC_E_REASSOC:
  874. if (status == WLC_E_STATUS_SUCCESS) {
  875. DHD_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n", event_name, eabuf));
  876. } else if (status == WLC_E_STATUS_TIMEOUT) {
  877. DHD_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n", event_name, eabuf));
  878. } else if (status == WLC_E_STATUS_FAIL) {
  879. DHD_EVENT(("MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
  880. event_name, eabuf, (int)reason));
  881. } else {
  882. DHD_EVENT(("MACEVENT: %s, MAC %s, unexpected status %d\n",
  883. event_name, eabuf, (int)status));
  884. }
  885. break;
  886. case WLC_E_DEAUTH_IND:
  887. case WLC_E_DISASSOC_IND:
  888. DHD_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name, eabuf, (int)reason));
  889. break;
  890. case WLC_E_AUTH:
  891. case WLC_E_AUTH_IND:
  892. if (auth_type == DOT11_OPEN_SYSTEM)
  893. auth_str = "Open System";
  894. else if (auth_type == DOT11_SHARED_KEY)
  895. auth_str = "Shared Key";
  896. else {
  897. snprintf(err_msg, sizeof(err_msg), "AUTH unknown: %d", (int)auth_type);
  898. auth_str = err_msg;
  899. }
  900. if (event_type == WLC_E_AUTH_IND) {
  901. DHD_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name, eabuf, auth_str));
  902. } else if (status == WLC_E_STATUS_SUCCESS) {
  903. DHD_EVENT(("MACEVENT: %s, MAC %s, %s, SUCCESS\n",
  904. event_name, eabuf, auth_str));
  905. } else if (status == WLC_E_STATUS_TIMEOUT) {
  906. DHD_EVENT(("MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
  907. event_name, eabuf, auth_str));
  908. } else if (status == WLC_E_STATUS_FAIL) {
  909. DHD_EVENT(("MACEVENT: %s, MAC %s, %s, FAILURE, reason %d\n",
  910. event_name, eabuf, auth_str, (int)reason));
  911. }
  912. BCM_REFERENCE(auth_str);
  913. break;
  914. case WLC_E_JOIN:
  915. case WLC_E_ROAM:
  916. case WLC_E_SET_SSID:
  917. if (status == WLC_E_STATUS_SUCCESS) {
  918. DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
  919. } else if (status == WLC_E_STATUS_FAIL) {
  920. DHD_EVENT(("MACEVENT: %s, failed\n", event_name));
  921. } else if (status == WLC_E_STATUS_NO_NETWORKS) {
  922. DHD_EVENT(("MACEVENT: %s, no networks found\n", event_name));
  923. } else {
  924. DHD_EVENT(("MACEVENT: %s, unexpected status %d\n",
  925. event_name, (int)status));
  926. }
  927. break;
  928. case WLC_E_BEACON_RX:
  929. if (status == WLC_E_STATUS_SUCCESS) {
  930. DHD_EVENT(("MACEVENT: %s, SUCCESS\n", event_name));
  931. } else if (status == WLC_E_STATUS_FAIL) {
  932. DHD_EVENT(("MACEVENT: %s, FAIL\n", event_name));
  933. } else {
  934. DHD_EVENT(("MACEVENT: %s, status %d\n", event_name, status));
  935. }
  936. break;
  937. case WLC_E_LINK:
  938. DHD_EVENT(("MACEVENT: %s %s\n", event_name, link?"UP":"DOWN"));
  939. BCM_REFERENCE(link);
  940. break;
  941. case WLC_E_MIC_ERROR:
  942. DHD_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
  943. event_name, eabuf, group, flush_txq));
  944. BCM_REFERENCE(group);
  945. BCM_REFERENCE(flush_txq);
  946. break;
  947. case WLC_E_ICV_ERROR:
  948. case WLC_E_UNICAST_DECODE_ERROR:
  949. case WLC_E_MULTICAST_DECODE_ERROR:
  950. DHD_EVENT(("MACEVENT: %s, MAC %s\n",
  951. event_name, eabuf));
  952. break;
  953. case WLC_E_TXFAIL:
  954. DHD_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf));
  955. break;
  956. case WLC_E_SCAN_COMPLETE:
  957. case WLC_E_ASSOC_REQ_IE:
  958. case WLC_E_ASSOC_RESP_IE:
  959. case WLC_E_PMKID_CACHE:
  960. DHD_EVENT(("MACEVENT: %s\n", event_name));
  961. break;
  962. case WLC_E_PFN_NET_FOUND:
  963. case WLC_E_PFN_NET_LOST:
  964. case WLC_E_PFN_SCAN_COMPLETE:
  965. case WLC_E_PFN_SCAN_NONE:
  966. case WLC_E_PFN_SCAN_ALLGONE:
  967. DHD_EVENT(("PNOEVENT: %s\n", event_name));
  968. break;
  969. case WLC_E_PSK_SUP:
  970. case WLC_E_PRUNE:
  971. DHD_EVENT(("MACEVENT: %s, status %d, reason %d\n",
  972. event_name, (int)status, (int)reason));
  973. break;
  974. #ifdef WIFI_ACT_FRAME
  975. case WLC_E_ACTION_FRAME:
  976. DHD_TRACE(("MACEVENT: %s Bssid %s\n", event_name, eabuf));
  977. break;
  978. #endif /* WIFI_ACT_FRAME */
  979. case WLC_E_TRACE: {
  980. static uint32 seqnum_prev = 0;
  981. static uint32 logtrace_seqnum_prev = 0;
  982. msgtrace_hdr_t hdr;
  983. uint32 nblost;
  984. char *s, *p;
  985. buf = (uchar *) event_data;
  986. memcpy(&hdr, buf, MSGTRACE_HDRLEN);
  987. if (hdr.version != MSGTRACE_VERSION) {
  988. printf("\nMACEVENT: %s [unsupported version --> "
  989. "dhd version:%d dongle version:%d]\n",
  990. event_name, MSGTRACE_VERSION, hdr.version);
  991. /* Reset datalen to avoid display below */
  992. datalen = 0;
  993. break;
  994. }
  995. if (hdr.trace_type == MSGTRACE_HDR_TYPE_MSG) {
  996. /* There are 2 bytes available at the end of data */
  997. buf[MSGTRACE_HDRLEN + ntoh16(hdr.len)] = '\0';
  998. if (ntoh32(hdr.discarded_bytes) || ntoh32(hdr.discarded_printf)) {
  999. printf("\nWLC_E_TRACE: [Discarded traces in dongle -->"
  1000. "discarded_bytes %d discarded_printf %d]\n",
  1001. ntoh32(hdr.discarded_bytes), ntoh32(hdr.discarded_printf));
  1002. }
  1003. nblost = ntoh32(hdr.seqnum) - seqnum_prev - 1;
  1004. if (nblost > 0) {
  1005. printf("\nWLC_E_TRACE: [Event lost (msg) --> seqnum %d nblost %d\n",
  1006. ntoh32(hdr.seqnum), nblost);
  1007. }
  1008. seqnum_prev = ntoh32(hdr.seqnum);
  1009. /* Display the trace buffer. Advance from \n to \n to avoid display big
  1010. * printf (issue with Linux printk )
  1011. */
  1012. p = (char *)&buf[MSGTRACE_HDRLEN];
  1013. while (*p != '\0' && (s = strstr(p, "\n")) != NULL) {
  1014. *s = '\0';
  1015. printf("WLC_E_TRACE: %s\n", p);
  1016. p = s+1;
  1017. }
  1018. if (*p) printf("WLC_E_TRACE: %s", p);
  1019. /* Reset datalen to avoid display below */
  1020. datalen = 0;
  1021. } else if (hdr.trace_type == MSGTRACE_HDR_TYPE_LOG) {
  1022. /* Let the standard event printing work for now */
  1023. uint32 timestamp, w;
  1024. if (ntoh32(hdr.seqnum) == logtrace_seqnum_prev) {
  1025. printf("\nWLC_E_TRACE: [Event duplicate (log) %d",
  1026. logtrace_seqnum_prev);
  1027. } else {
  1028. nblost = ntoh32(hdr.seqnum) - logtrace_seqnum_prev - 1;
  1029. if (nblost > 0) {
  1030. printf("\nWLC_E_TRACE: [Event lost (log)"
  1031. " --> seqnum %d nblost %d\n",
  1032. ntoh32(hdr.seqnum), nblost);
  1033. }
  1034. logtrace_seqnum_prev = ntoh32(hdr.seqnum);
  1035. p = (char *)&buf[MSGTRACE_HDRLEN];
  1036. datalen -= MSGTRACE_HDRLEN;
  1037. w = ntoh32((uint32) *p);
  1038. p += 4;
  1039. datalen -= 4;
  1040. timestamp = ntoh32((uint32) *p);
  1041. printf("Logtrace %x timestamp %x %x",
  1042. logtrace_seqnum_prev, timestamp, w);
  1043. while (datalen > 4) {
  1044. p += 4;
  1045. datalen -= 4;
  1046. /* Print each word. DO NOT ntoh it. */
  1047. printf(" %8.8x", *((uint32 *) p));
  1048. }
  1049. printf("\n");
  1050. }
  1051. datalen = 0;
  1052. }
  1053. break;
  1054. }
  1055. case WLC_E_RSSI:
  1056. DHD_EVENT(("MACEVENT: %s %d\n", event_name, ntoh32(*((int *)event_data))));
  1057. break;
  1058. case WLC_E_SERVICE_FOUND:
  1059. case WLC_E_P2PO_ADD_DEVICE:
  1060. case WLC_E_P2PO_DEL_DEVICE:
  1061. DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
  1062. break;
  1063. default:
  1064. DHD_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, auth %d\n",
  1065. event_name, event_type, eabuf, (int)status, (int)reason,
  1066. (int)auth_type));
  1067. break;
  1068. }
  1069. /* show any appended data */
  1070. if (DHD_BYTES_ON() && DHD_EVENT_ON() && datalen) {
  1071. buf = (uchar *) event_data;
  1072. DHD_EVENT((" data (%d) : ", datalen));
  1073. for (i = 0; i < datalen; i++)
  1074. DHD_EVENT((" 0x%02x ", *buf++));
  1075. DHD_EVENT(("\n"));
  1076. }
  1077. }
  1078. #endif /* SHOW_EVENTS */
  1079. int
  1080. wl_host_event(dhd_pub_t *dhd_pub, int *ifidx, void *pktdata, size_t pktlen,
  1081. wl_event_msg_t *event, void **data_ptr)
  1082. {
  1083. /* check whether packet is a BRCM event pkt */
  1084. bcm_event_t *pvt_data = (bcm_event_t *)pktdata;
  1085. uint8 *event_data;
  1086. uint32 type, status, datalen;
  1087. uint16 flags;
  1088. uint evlen;
  1089. if (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
  1090. DHD_ERROR(("%s: mismatched OUI, bailing\n", __FUNCTION__));
  1091. return (BCME_ERROR);
  1092. }
  1093. if (ntoh16_ua((void *)&pvt_data->bcm_hdr.subtype) != BCMILCP_SUBTYPE_VENDOR_LONG ||
  1094. (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) ||
  1095. ntoh16_ua((void *)&pvt_data->bcm_hdr.usr_subtype) != BCMILCP_BCM_SUBTYPE_EVENT)
  1096. {
  1097. DHD_ERROR(("%s: mismatched bcm_event_t info, bailing out\n", __FUNCTION__));
  1098. return (BCME_ERROR);
  1099. }
  1100. if (pktlen < sizeof(bcm_event_t))
  1101. return (BCME_ERROR);
  1102. *data_ptr = &pvt_data[1];
  1103. event_data = *data_ptr;
  1104. /* memcpy since BRCM event pkt may be unaligned. */
  1105. memcpy(event, &pvt_data->event, sizeof(wl_event_msg_t));
  1106. type = ntoh32_ua((void *)&event->event_type);
  1107. flags = ntoh16_ua((void *)&event->flags);
  1108. status = ntoh32_ua((void *)&event->status);
  1109. datalen = ntoh32_ua((void *)&event->datalen);
  1110. if (datalen > pktlen)
  1111. return (BCME_ERROR);
  1112. evlen = datalen + sizeof(bcm_event_t);
  1113. if (evlen > pktlen)
  1114. return (BCME_ERROR);
  1115. switch (type) {
  1116. #ifdef PROP_TXSTATUS
  1117. case WLC_E_FIFO_CREDIT_MAP:
  1118. if (dhd_wlfc_enable(dhd_pub) != BCME_OK) {
  1119. DHD_ERROR(("%s: dhd_wlfc_enable failed\n", __FUNCTION__));
  1120. return (BCME_ERROR);
  1121. }
  1122. dhd_wlfc_FIFOcreditmap_event(dhd_pub, event_data);
  1123. WLFC_DBGMESG(("WLC_E_FIFO_CREDIT_MAP:(AC0,AC1,AC2,AC3),(BC_MC),(OTHER): "
  1124. "(%d,%d,%d,%d),(%d),(%d)\n", event_data[0], event_data[1],
  1125. event_data[2],
  1126. event_data[3], event_data[4], event_data[5]));
  1127. break;
  1128. case WLC_E_BCMC_CREDIT_SUPPORT:
  1129. dhd_wlfc_BCMCCredit_support_event(dhd_pub);
  1130. break;
  1131. #endif /* PROP_TXSTATUS */
  1132. case WLC_E_IF: {
  1133. struct wl_event_data_if *ifevent = (struct wl_event_data_if *)event_data;
  1134. /* Ignore the event if NOIF is set */
  1135. if (ifevent->reserved & WLC_E_IF_FLAGS_BSSCFG_NOIF) {
  1136. DHD_ERROR(("WLC_E_IF: NO_IF set, event Ignored\r\n"));
  1137. return (BCME_UNSUPPORTED);
  1138. }
  1139. #ifdef PROP_TXSTATUS
  1140. {
  1141. uint8* ea = pvt_data->eth.ether_dhost;
  1142. WLFC_DBGMESG(("WLC_E_IF: idx:%d, action:%s, iftype:%s, "
  1143. "[%02x:%02x:%02x:%02x:%02x:%02x]\n",
  1144. ifevent->ifidx,
  1145. ((ifevent->opcode == WLC_E_IF_ADD) ? "ADD":"DEL"),
  1146. ((ifevent->role == 0) ? "STA":"AP "),
  1147. ea[0], ea[1], ea[2], ea[3], ea[4], ea[5]));
  1148. (void)ea;
  1149. if (ifevent->opcode == WLC_E_IF_CHANGE)
  1150. dhd_wlfc_interface_event(dhd_pub,
  1151. eWLFC_MAC_ENTRY_ACTION_UPDATE,
  1152. ifevent->ifidx, ifevent->role, ea);
  1153. else
  1154. dhd_wlfc_interface_event(dhd_pub,
  1155. ((ifevent->opcode == WLC_E_IF_ADD) ?
  1156. eWLFC_MAC_ENTRY_ACTION_ADD : eWLFC_MAC_ENTRY_ACTION_DEL),
  1157. ifevent->ifidx, ifevent->role, ea);
  1158. /* dhd already has created an interface by default, for 0 */
  1159. if (ifevent->ifidx == 0)
  1160. break;
  1161. }
  1162. #endif /* PROP_TXSTATUS */
  1163. if (ifevent->ifidx > 0 && ifevent->ifidx < DHD_MAX_IFS) {
  1164. if (ifevent->opcode == WLC_E_IF_ADD) {
  1165. if (dhd_event_ifadd(dhd_pub->info, ifevent, event->ifname,
  1166. event->addr.octet)) {
  1167. DHD_ERROR(("%s: dhd_event_ifadd failed ifidx: %d %s\n",
  1168. __FUNCTION__, ifevent->ifidx, event->ifname));
  1169. return (BCME_ERROR);
  1170. }
  1171. } else if (ifevent->opcode == WLC_E_IF_DEL) {
  1172. dhd_event_ifdel(dhd_pub->info, ifevent, event->ifname,
  1173. event->addr.octet);
  1174. } else if (ifevent->opcode == WLC_E_IF_CHANGE) {
  1175. #ifdef WL_CFG80211
  1176. wl_cfg80211_notify_ifchange(ifevent->ifidx,
  1177. event->ifname, event->addr.octet, ifevent->bssidx);
  1178. #endif /* WL_CFG80211 */
  1179. }
  1180. } else {
  1181. #ifndef PROP_TXSTATUS
  1182. DHD_ERROR(("%s: Invalid ifidx %d for %s\n",
  1183. __FUNCTION__, ifevent->ifidx, event->ifname));
  1184. #endif /* !PROP_TXSTATUS */
  1185. }
  1186. /* send up the if event: btamp user needs it */
  1187. *ifidx = dhd_ifname2idx(dhd_pub->info, event->ifname);
  1188. /* push up to external supp/auth */
  1189. dhd_event(dhd_pub->info, (char *)pvt_data, evlen, *ifidx);
  1190. break;
  1191. }
  1192. #ifdef WLMEDIA_HTSF
  1193. case WLC_E_HTSFSYNC:
  1194. htsf_update(dhd_pub->info, event_data);
  1195. break;
  1196. #endif /* WLMEDIA_HTSF */
  1197. case WLC_E_NDIS_LINK: {
  1198. uint32 temp = hton32(WLC_E_LINK);
  1199. memcpy((void *)(&pvt_data->event.event_type), &temp,
  1200. sizeof(pvt_data->event.event_type));
  1201. }
  1202. case WLC_E_PFN_NET_FOUND:
  1203. case WLC_E_PFN_NET_LOST:
  1204. break;
  1205. #if defined(PNO_SUPPORT)
  1206. case WLC_E_PFN_BSSID_NET_FOUND:
  1207. case WLC_E_PFN_BSSID_NET_LOST:
  1208. case WLC_E_PFN_BEST_BATCHING:
  1209. dhd_pno_event_handler(dhd_pub, event, (void *)event_data);
  1210. break;
  1211. #endif
  1212. /* These are what external supplicant/authenticator wants */
  1213. /* fall through */
  1214. case WLC_E_LINK:
  1215. case WLC_E_DEAUTH:
  1216. case WLC_E_DEAUTH_IND:
  1217. case WLC_E_DISASSOC:
  1218. case WLC_E_DISASSOC_IND:
  1219. DHD_EVENT(("%s: Link event %d, flags %x, status %x\n",
  1220. __FUNCTION__, type, flags, status));
  1221. /* fall through */
  1222. default:
  1223. *ifidx = dhd_ifname2idx(dhd_pub->info, event->ifname);
  1224. /* push up to external supp/auth */
  1225. dhd_event(dhd_pub->info, (char *)pvt_data, evlen, *ifidx);
  1226. DHD_TRACE(("%s: MAC event %d, flags %x, status %x\n",
  1227. __FUNCTION__, type, flags, status));
  1228. BCM_REFERENCE(flags);
  1229. BCM_REFERENCE(status);
  1230. break;
  1231. }
  1232. #ifdef SHOW_EVENTS
  1233. wl_show_host_event(event, (void *)event_data);
  1234. #endif /* SHOW_EVENTS */
  1235. return (BCME_OK);
  1236. }
  1237. void
  1238. wl_event_to_host_order(wl_event_msg_t * evt)
  1239. {
  1240. /* Event struct members passed from dongle to host are stored in network
  1241. * byte order. Convert all members to host-order.
  1242. */
  1243. evt->event_type = ntoh32(evt->event_type);
  1244. evt->flags = ntoh16(evt->flags);
  1245. evt->status = ntoh32(evt->status);
  1246. evt->reason = ntoh32(evt->reason);
  1247. evt->auth_type = ntoh32(evt->auth_type);
  1248. evt->datalen = ntoh32(evt->datalen);
  1249. evt->version = ntoh16(evt->version);
  1250. }
  1251. void
  1252. dhd_print_buf(void *pbuf, int len, int bytes_per_line)
  1253. {
  1254. #ifdef DHD_DEBUG
  1255. int i, j = 0;
  1256. unsigned char *buf = pbuf;
  1257. if (bytes_per_line == 0) {
  1258. bytes_per_line = len;
  1259. }
  1260. for (i = 0; i < len; i++) {
  1261. printf("%2.2x", *buf++);
  1262. j++;
  1263. if (j == bytes_per_line) {
  1264. printf("\n");
  1265. j = 0;
  1266. } else {
  1267. printf(":");
  1268. }
  1269. }
  1270. printf("\n");
  1271. #endif /* DHD_DEBUG */
  1272. }
  1273. #ifndef strtoul
  1274. #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
  1275. #endif
  1276. #ifdef PKT_FILTER_SUPPORT
  1277. /* Convert user's input in hex pattern to byte-size mask */
  1278. static int
  1279. wl_pattern_atoh(char *src, char *dst)
  1280. {
  1281. int i;
  1282. if (strncmp(src, "0x", 2) != 0 &&
  1283. strncmp(src, "0X", 2) != 0) {
  1284. DHD_ERROR(("Mask invalid format. Needs to start with 0x\n"));
  1285. return -1;
  1286. }
  1287. src = src + 2; /* Skip past 0x */
  1288. if (strlen(src) % 2 != 0) {
  1289. DHD_ERROR(("Mask invalid format. Needs to be of even length\n"));
  1290. return -1;
  1291. }
  1292. for (i = 0; *src != '\0'; i++) {
  1293. char num[3];
  1294. bcm_strncpy_s(num, sizeof(num), src, 2);
  1295. num[2] = '\0';
  1296. dst[i] = (uint8)strtoul(num, NULL, 16);
  1297. src += 2;
  1298. }
  1299. return i;
  1300. }
  1301. void
  1302. dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode)
  1303. {
  1304. char *argv[8];
  1305. int i = 0;
  1306. const char *str;
  1307. int buf_len;
  1308. int str_len;
  1309. char *arg_save = 0, *arg_org = 0;
  1310. int rc;
  1311. char buf[128];
  1312. wl_pkt_filter_enable_t enable_parm;
  1313. wl_pkt_filter_enable_t * pkt_filterp;
  1314. if (!arg)
  1315. return;
  1316. if (!(arg_save = MALLOC(dhd->osh, strlen(arg) + 1))) {
  1317. DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
  1318. goto fail;
  1319. }
  1320. arg_org = arg_save;
  1321. memcpy(arg_save, arg, strlen(arg) + 1);
  1322. argv[i] = bcmstrtok(&arg_save, " ", 0);
  1323. i = 0;
  1324. if (argv[i] == NULL) {
  1325. DHD_ERROR(("No args provided\n"));
  1326. goto fail;
  1327. }
  1328. str = "pkt_filter_enable";
  1329. str_len = strlen(str);
  1330. bcm_strncpy_s(buf, sizeof(buf), str, str_len);
  1331. buf[str_len] = '\0';
  1332. buf_len = str_len + 1;
  1333. pkt_filterp = (wl_pkt_filter_enable_t *)(buf + str_len + 1);
  1334. /* Parse packet filter id. */
  1335. enable_parm.id = htod32(strtoul(argv[i], NULL, 0));
  1336. /* Parse enable/disable value. */
  1337. enable_parm.enable = htod32(enable);
  1338. buf_len += sizeof(enable_parm);
  1339. memcpy((char *)pkt_filterp,
  1340. &enable_parm,
  1341. sizeof(enable_parm));
  1342. /* Enable/disable the specified filter. */
  1343. rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, buf_len, TRUE, 0);
  1344. rc = rc >= 0 ? 0 : rc;
  1345. if (rc)
  1346. DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
  1347. __FUNCTION__, arg, rc));
  1348. else
  1349. DHD_TRACE(("%s: successfully added pktfilter %s\n",
  1350. __FUNCTION__, arg));
  1351. /* Contorl the master mode */
  1352. bcm_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf, sizeof(buf));
  1353. rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
  1354. rc = rc >= 0 ? 0 : rc;
  1355. if (rc)
  1356. DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
  1357. __FUNCTION__, arg, rc));
  1358. fail:
  1359. if (arg_org)
  1360. MFREE(dhd->osh, arg_org, strlen(arg) + 1);
  1361. }
  1362. void
  1363. dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg)
  1364. {
  1365. const char *str;
  1366. wl_pkt_filter_t pkt_filter;
  1367. wl_pkt_filter_t *pkt_filterp;
  1368. int buf_len;
  1369. int str_len;
  1370. int rc;
  1371. uint32 mask_size;
  1372. uint32 pattern_size;
  1373. char *argv[8], * buf = 0;
  1374. int i = 0;
  1375. char *arg_save = 0, *arg_org = 0;
  1376. #define BUF_SIZE 2048
  1377. if (!arg)
  1378. return;
  1379. if (!(arg_save = MALLOC(dhd->osh, strlen(arg) + 1))) {
  1380. DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
  1381. goto fail;
  1382. }
  1383. arg_org = arg_save;
  1384. if (!(buf = MALLOC(dhd->osh, BUF_SIZE))) {
  1385. DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
  1386. goto fail;
  1387. }
  1388. memcpy(arg_save, arg, strlen(arg) + 1);
  1389. if (strlen(arg) > BUF_SIZE) {
  1390. DHD_ERROR(("Not enough buffer %d < %d\n", (int)strlen(arg), (int)sizeof(buf)));
  1391. goto fail;
  1392. }
  1393. argv[i] = bcmstrtok(&arg_save, " ", 0);
  1394. while (argv[i++])
  1395. argv[i] = bcmstrtok(&arg_save, " ", 0);
  1396. i = 0;
  1397. if (argv[i] == NULL) {
  1398. DHD_ERROR(("No args provided\n"));
  1399. goto fail;
  1400. }
  1401. str = "pkt_filter_add";
  1402. str_len = strlen(str);
  1403. bcm_strncpy_s(buf, BUF_SIZE, str, str_len);
  1404. buf[ str_len ] = '\0';
  1405. buf_len = str_len + 1;
  1406. pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1);
  1407. /* Parse packet filter id. */
  1408. pkt_filter.id = htod32(strtoul(argv[i], NULL, 0));
  1409. if (argv[++i] == NULL) {
  1410. DHD_ERROR(("Polarity not provided\n"));
  1411. goto fail;
  1412. }
  1413. /* Parse filter polarity. */
  1414. pkt_filter.negate_match = htod32(strtoul(argv[i], NULL, 0));
  1415. if (argv[++i] == NULL) {
  1416. DHD_ERROR(("Filter type not provided\n"));
  1417. goto fail;
  1418. }
  1419. /* Parse filter type. */
  1420. pkt_filter.type = htod32(strtoul(argv[i], NULL, 0));
  1421. if (argv[++i] == NULL) {
  1422. DHD_ERROR(("Offset not provided\n"));
  1423. goto fail;
  1424. }
  1425. /* Parse pattern filter offset. */
  1426. pkt_filter.u.pattern.offset = htod32(strtoul(argv[i], NULL, 0));
  1427. if (argv[++i] == NULL) {
  1428. DHD_ERROR(("Bitmask not provided\n"));
  1429. goto fail;
  1430. }
  1431. /* Parse pattern filter mask. */
  1432. mask_size =
  1433. htod32(wl_pattern_atoh(argv[i], (char *) pkt_filterp->u.pattern.mask_and_pattern));
  1434. if (argv[++i] == NULL) {
  1435. DHD_ERROR(("Pattern not provided\n"));
  1436. goto fail;
  1437. }
  1438. /* Parse pattern filter pattern. */
  1439. pattern_size =
  1440. htod32(wl_pattern_atoh(argv[i],
  1441. (char *) &pkt_filterp->u.pattern.mask_and_pattern[mask_size]));
  1442. if (mask_size != pattern_size) {
  1443. DHD_ERROR(("Mask and pattern not the same size\n"));
  1444. goto fail;
  1445. }
  1446. pkt_filter.u.pattern.size_bytes = mask_size;
  1447. buf_len += WL_PKT_FILTER_FIXED_LEN;
  1448. buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
  1449. /* Keep-alive attributes are set in local variable (keep_alive_pkt), and
  1450. ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
  1451. ** guarantee that the buffer is properly aligned.
  1452. */
  1453. memcpy((char *)pkt_filterp,
  1454. &pkt_filter,
  1455. WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
  1456. rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, buf_len, TRUE, 0);
  1457. rc = rc >= 0 ? 0 : rc;
  1458. if (rc)
  1459. DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
  1460. __FUNCTION__, arg, rc));
  1461. else
  1462. DHD_TRACE(("%s: successfully added pktfilter %s\n",
  1463. __FUNCTION__, arg));
  1464. fail:
  1465. if (arg_org)
  1466. MFREE(dhd->osh, arg_org, strlen(arg) + 1);
  1467. if (buf)
  1468. MFREE(dhd->osh, buf, BUF_SIZE);
  1469. }
  1470. void dhd_pktfilter_offload_delete(dhd_pub_t *dhd, int id)
  1471. {
  1472. char iovbuf[32];
  1473. int ret;
  1474. bcm_mkiovar("pkt_filter_delete", (char *)&id, 4, iovbuf, sizeof(iovbuf));
  1475. ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
  1476. if (ret < 0) {
  1477. DHD_ERROR(("%s: Failed to delete filter ID:%d, ret=%d\n",
  1478. __FUNCTION__, id, ret));
  1479. }
  1480. }
  1481. #endif /* PKT_FILTER_SUPPORT */
  1482. /* ========================== */
  1483. /* ==== ARP OFFLOAD SUPPORT = */
  1484. /* ========================== */
  1485. #ifdef ARP_OFFLOAD_SUPPORT
  1486. void
  1487. dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode)
  1488. {
  1489. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1490. int iovar_len;
  1491. int retcode;
  1492. iovar_len = bcm_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
  1493. if (!iovar_len) {
  1494. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1495. __FUNCTION__, sizeof(iovbuf)));
  1496. return;
  1497. }
  1498. retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iovar_len, TRUE, 0);
  1499. retcode = retcode >= 0 ? 0 : retcode;
  1500. if (retcode)
  1501. DHD_TRACE(("%s: failed to set ARP offload mode to 0x%x, retcode = %d\n",
  1502. __FUNCTION__, arp_mode, retcode));
  1503. else
  1504. DHD_TRACE(("%s: successfully set ARP offload mode to 0x%x\n",
  1505. __FUNCTION__, arp_mode));
  1506. }
  1507. void
  1508. dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable)
  1509. {
  1510. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1511. int iovar_len;
  1512. int retcode;
  1513. iovar_len = bcm_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf));
  1514. if (!iovar_len) {
  1515. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1516. __FUNCTION__, sizeof(iovbuf)));
  1517. return;
  1518. }
  1519. retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iovar_len, TRUE, 0);
  1520. retcode = retcode >= 0 ? 0 : retcode;
  1521. if (retcode)
  1522. DHD_TRACE(("%s: failed to enabe ARP offload to %d, retcode = %d\n",
  1523. __FUNCTION__, arp_enable, retcode));
  1524. else
  1525. DHD_TRACE(("%s: successfully enabed ARP offload to %d\n",
  1526. __FUNCTION__, arp_enable));
  1527. if (arp_enable) {
  1528. uint32 version;
  1529. bcm_mkiovar("arp_version", 0, 0, iovbuf, sizeof(iovbuf));
  1530. retcode = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0);
  1531. if (retcode) {
  1532. DHD_INFO(("%s: fail to get version (maybe version 1:retcode = %d\n",
  1533. __FUNCTION__, retcode));
  1534. dhd->arp_version = 1;
  1535. }
  1536. else {
  1537. memcpy(&version, iovbuf, sizeof(version));
  1538. DHD_INFO(("%s: ARP Version= %x\n", __FUNCTION__, version));
  1539. dhd->arp_version = version;
  1540. }
  1541. }
  1542. }
  1543. void
  1544. dhd_aoe_arp_clr(dhd_pub_t *dhd, int idx)
  1545. {
  1546. int ret = 0;
  1547. int iov_len = 0;
  1548. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1549. if (dhd == NULL) return;
  1550. if (dhd->arp_version == 1)
  1551. idx = 0;
  1552. iov_len = bcm_mkiovar("arp_table_clear", 0, 0, iovbuf, sizeof(iovbuf));
  1553. if (!iov_len) {
  1554. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1555. __FUNCTION__, sizeof(iovbuf)));
  1556. return;
  1557. }
  1558. if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx)) < 0)
  1559. DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret));
  1560. }
  1561. void
  1562. dhd_aoe_hostip_clr(dhd_pub_t *dhd, int idx)
  1563. {
  1564. int ret = 0;
  1565. int iov_len = 0;
  1566. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1567. if (dhd == NULL) return;
  1568. if (dhd->arp_version == 1)
  1569. idx = 0;
  1570. iov_len = bcm_mkiovar("arp_hostip_clear", 0, 0, iovbuf, sizeof(iovbuf));
  1571. if (!iov_len) {
  1572. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1573. __FUNCTION__, sizeof(iovbuf)));
  1574. return;
  1575. }
  1576. if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx)) < 0)
  1577. DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret));
  1578. }
  1579. void
  1580. dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr, int idx)
  1581. {
  1582. int iov_len = 0;
  1583. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1584. int retcode;
  1585. if (dhd == NULL) return;
  1586. if (dhd->arp_version == 1)
  1587. idx = 0;
  1588. iov_len = bcm_mkiovar("arp_hostip", (char *)&ipaddr,
  1589. sizeof(ipaddr), iovbuf, sizeof(iovbuf));
  1590. if (!iov_len) {
  1591. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1592. __FUNCTION__, sizeof(iovbuf)));
  1593. return;
  1594. }
  1595. retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx);
  1596. if (retcode)
  1597. DHD_TRACE(("%s: ARP ip addr add failed, retcode = %d\n",
  1598. __FUNCTION__, retcode));
  1599. else
  1600. DHD_TRACE(("%s: sARP H ipaddr entry added \n",
  1601. __FUNCTION__));
  1602. }
  1603. int
  1604. dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen, int idx)
  1605. {
  1606. int retcode, i;
  1607. int iov_len;
  1608. uint32 *ptr32 = buf;
  1609. bool clr_bottom = FALSE;
  1610. if (!buf)
  1611. return -1;
  1612. if (dhd == NULL) return -1;
  1613. if (dhd->arp_version == 1)
  1614. idx = 0;
  1615. iov_len = bcm_mkiovar("arp_hostip", 0, 0, buf, buflen);
  1616. BCM_REFERENCE(iov_len);
  1617. retcode = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, buflen, FALSE, idx);
  1618. if (retcode) {
  1619. DHD_TRACE(("%s: ioctl WLC_GET_VAR error %d\n",
  1620. __FUNCTION__, retcode));
  1621. return -1;
  1622. }
  1623. /* clean up the buf, ascii reminder */
  1624. for (i = 0; i < MAX_IPV4_ENTRIES; i++) {
  1625. if (!clr_bottom) {
  1626. if (*ptr32 == 0)
  1627. clr_bottom = TRUE;
  1628. } else {
  1629. *ptr32 = 0;
  1630. }
  1631. ptr32++;
  1632. }
  1633. return 0;
  1634. }
  1635. #endif /* ARP_OFFLOAD_SUPPORT */
  1636. /*
  1637. * Neighbor Discovery Offload: enable NDO feature
  1638. * Called by ipv6 event handler when interface comes up/goes down
  1639. */
  1640. int
  1641. dhd_ndo_enable(dhd_pub_t * dhd, int ndo_enable)
  1642. {
  1643. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1644. int iov_len;
  1645. int retcode;
  1646. if (dhd == NULL)
  1647. return -1;
  1648. iov_len = bcm_mkiovar("ndoe", (char *)&ndo_enable, 4, iovbuf, sizeof(iovbuf));
  1649. if (!iov_len) {
  1650. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1651. __FUNCTION__, sizeof(iovbuf)));
  1652. return -1;
  1653. }
  1654. retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, 0);
  1655. if (retcode)
  1656. DHD_ERROR(("%s: failed to enabe ndo to %d, retcode = %d\n",
  1657. __FUNCTION__, ndo_enable, retcode));
  1658. else
  1659. DHD_TRACE(("%s: successfully enabed ndo offload to %d\n",
  1660. __FUNCTION__, ndo_enable));
  1661. return retcode;
  1662. }
  1663. /*
  1664. * Neighbor Discover Offload: enable NDO feature
  1665. * Called by ipv6 event handler when interface comes up
  1666. */
  1667. int
  1668. dhd_ndo_add_ip(dhd_pub_t *dhd, char* ipv6addr, int idx)
  1669. {
  1670. int iov_len = 0;
  1671. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1672. int retcode;
  1673. if (dhd == NULL)
  1674. return -1;
  1675. iov_len = bcm_mkiovar("nd_hostip", (char *)ipv6addr,
  1676. IPV6_ADDR_LEN, iovbuf, sizeof(iovbuf));
  1677. if (!iov_len) {
  1678. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1679. __FUNCTION__, sizeof(iovbuf)));
  1680. return -1;
  1681. }
  1682. retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx);
  1683. if (retcode)
  1684. DHD_ERROR(("%s: ndo ip addr add failed, retcode = %d\n",
  1685. __FUNCTION__, retcode));
  1686. else
  1687. DHD_TRACE(("%s: ndo ipaddr entry added \n",
  1688. __FUNCTION__));
  1689. return retcode;
  1690. }
  1691. /*
  1692. * Neighbor Discover Offload: enable NDO feature
  1693. * Called by ipv6 event handler when interface goes down
  1694. */
  1695. int
  1696. dhd_ndo_remove_ip(dhd_pub_t *dhd, int idx)
  1697. {
  1698. int iov_len = 0;
  1699. char iovbuf[DHD_IOVAR_BUF_SIZE];
  1700. int retcode;
  1701. if (dhd == NULL)
  1702. return -1;
  1703. iov_len = bcm_mkiovar("nd_hostip_clear", NULL,
  1704. 0, iovbuf, sizeof(iovbuf));
  1705. if (!iov_len) {
  1706. DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
  1707. __FUNCTION__, sizeof(iovbuf)));
  1708. return -1;
  1709. }
  1710. retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx);
  1711. if (retcode) {
  1712. DHD_ERROR(("%s: ndo ip addr remove returned (%d)\n",
  1713. __FUNCTION__, retcode));
  1714. } else {
  1715. DHD_TRACE(("%s: ndo ipaddr entry removed \n",
  1716. __FUNCTION__));
  1717. }
  1718. return retcode;
  1719. }
  1720. /* send up locally generated event */
  1721. void
  1722. dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
  1723. {
  1724. switch (ntoh32(event->event_type)) {
  1725. #ifdef WLBTAMP
  1726. case WLC_E_BTA_HCI_EVENT:
  1727. break;
  1728. #endif /* WLBTAMP */
  1729. default:
  1730. break;
  1731. }
  1732. /* Call per-port handler. */
  1733. dhd_sendup_event(dhdp, event, data);
  1734. }
  1735. #ifdef SIMPLE_ISCAN
  1736. uint iscan_thread_id = 0;
  1737. iscan_buf_t * iscan_chain = 0;
  1738. iscan_buf_t *
  1739. dhd_iscan_allocate_buf(dhd_pub_t *dhd, iscan_buf_t **iscanbuf)
  1740. {
  1741. iscan_buf_t *iscanbuf_alloc = 0;
  1742. iscan_buf_t *iscanbuf_head;
  1743. DHD_ISCAN(("%s: Entered\n", __FUNCTION__));
  1744. dhd_iscan_lock();
  1745. iscanbuf_alloc = (iscan_buf_t*)MALLOC(dhd->osh, sizeof(iscan_buf_t));
  1746. if (iscanbuf_alloc == NULL)
  1747. goto fail;
  1748. iscanbuf_alloc->next = NULL;
  1749. iscanbuf_head = *iscanbuf;
  1750. DHD_ISCAN(("%s: addr of allocated node = 0x%X"
  1751. "addr of iscanbuf_head = 0x%X dhd = 0x%X\n",
  1752. __FUNCTION__, iscanbuf_alloc, iscanbuf_head, dhd));
  1753. if (iscanbuf_head == NULL) {
  1754. *iscanbuf = iscanbuf_alloc;
  1755. DHD_ISCAN(("%s: Head is allocated\n", __FUNCTION__));
  1756. goto fail;
  1757. }
  1758. while (iscanbuf_head->next)
  1759. iscanbuf_head = iscanbuf_head->next;
  1760. iscanbuf_head->next = iscanbuf_alloc;
  1761. fail:
  1762. dhd_iscan_unlock();
  1763. return iscanbuf_alloc;
  1764. }
  1765. void
  1766. dhd_iscan_free_buf(void *dhdp, iscan_buf_t *iscan_delete)
  1767. {
  1768. iscan_buf_t *iscanbuf_free = 0;
  1769. iscan_buf_t *iscanbuf_prv = 0;
  1770. iscan_buf_t *iscanbuf_cur;
  1771. dhd_pub_t *dhd = dhd_bus_pub(dhdp);
  1772. DHD_ISCAN(("%s: Entered\n", __FUNCTION__));
  1773. dhd_iscan_lock();
  1774. iscanbuf_cur = iscan_chain;
  1775. /* If iscan_delete is null then delete the entire
  1776. * chain or else delete specific one provided
  1777. */
  1778. if (!iscan_delete) {
  1779. while (iscanbuf_cur) {
  1780. iscanbuf_free = iscanbuf_cur;
  1781. iscanbuf_cur = iscanbuf_cur->next;
  1782. iscanbuf_free->next = 0;
  1783. MFREE(dhd->osh, iscanbuf_free, sizeof(iscan_buf_t));
  1784. }
  1785. iscan_chain = 0;
  1786. } else {
  1787. while (iscanbuf_cur) {
  1788. if (iscanbuf_cur == iscan_delete)
  1789. break;
  1790. iscanbuf_prv = iscanbuf_cur;
  1791. iscanbuf_cur = iscanbuf_cur->next;
  1792. }
  1793. if (iscanbuf_prv)
  1794. iscanbuf_prv->next = iscan_delete->next;
  1795. iscan_delete->next = 0;
  1796. MFREE(dhd->osh, iscan_delete, sizeof(iscan_buf_t));
  1797. if (!iscanbuf_prv)
  1798. iscan_chain = 0;
  1799. }
  1800. dhd_iscan_unlock();
  1801. }
  1802. iscan_buf_t *
  1803. dhd_iscan_result_buf(void)
  1804. {
  1805. return iscan_chain;
  1806. }
  1807. int
  1808. dhd_iscan_issue_request(void * dhdp, wl_iscan_params_t *pParams, uint32 size)
  1809. {
  1810. int rc = -1;
  1811. dhd_pub_t *dhd = dhd_bus_pub(dhdp);
  1812. char *buf;
  1813. char iovar[] = "iscan";
  1814. uint32 allocSize = 0;
  1815. wl_ioctl_t ioctl;
  1816. if (pParams) {
  1817. allocSize = (size + strlen(iovar) + 1);
  1818. if ((allocSize < size) || (allocSize < strlen(iovar)))
  1819. {
  1820. DHD_ERROR(("%s: overflow - allocation size too large %d < %d + %d!\n",
  1821. __FUNCTION__, allocSize, size, strlen(iovar)));
  1822. goto cleanUp;
  1823. }
  1824. buf = MALLOC(dhd->osh, allocSize);
  1825. if (buf == NULL)
  1826. {
  1827. DHD_ERROR(("%s: malloc of size %d failed!\n", __FUNCTION__, allocSize));
  1828. goto cleanUp;
  1829. }
  1830. ioctl.cmd = WLC_SET_VAR;
  1831. bcm_mkiovar(iovar, (char *)pParams, size, buf, allocSize);
  1832. rc = dhd_wl_ioctl(dhd, 0, &ioctl, buf, allocSize);
  1833. }
  1834. cleanUp:
  1835. if (buf) {
  1836. MFREE(dhd->osh, buf, allocSize);
  1837. }
  1838. return rc;
  1839. }
  1840. static int
  1841. dhd_iscan_get_partial_result(void *dhdp, uint *scan_count)
  1842. {
  1843. wl_iscan_results_t *list_buf;
  1844. wl_iscan_results_t list;
  1845. wl_scan_results_t *results;
  1846. iscan_buf_t *iscan_cur;
  1847. int status = -1;
  1848. dhd_pub_t *dhd = dhd_bus_pub(dhdp);
  1849. int rc;
  1850. wl_ioctl_t ioctl;
  1851. DHD_ISCAN(("%s: Enter\n", __FUNCTION__));
  1852. iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain);
  1853. if (!iscan_cur) {
  1854. DHD_ERROR(("%s: Failed to allocate node\n", __FUNCTION__));
  1855. dhd_iscan_free_buf(dhdp, 0);
  1856. dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT);
  1857. dhd_ind_scan_confirm(dhdp, FALSE);
  1858. goto fail;
  1859. }
  1860. dhd_iscan_lock();
  1861. memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
  1862. list_buf = (wl_iscan_results_t*)iscan_cur->iscan_buf;
  1863. results = &list_buf->results;
  1864. results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
  1865. results->version = 0;
  1866. results->count = 0;
  1867. memset(&list, 0, sizeof(list));
  1868. list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
  1869. bcm_mkiovar("iscanresults", (char *)&list, WL_ISCAN_RESULTS_FIXED_SIZE,
  1870. iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
  1871. ioctl.cmd = WLC_GET_VAR;
  1872. ioctl.set = FALSE;
  1873. rc = dhd_wl_ioctl(dhd, 0, &ioctl, iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
  1874. results->buflen = dtoh32(results->buflen);
  1875. results->version = dtoh32(results->version);
  1876. *scan_count = results->count = dtoh32(results->count);
  1877. status = dtoh32(list_buf->status);
  1878. DHD_ISCAN(("%s: Got %d resuls status = (%x)\n", __FUNCTION__, results->count, status));
  1879. dhd_iscan_unlock();
  1880. if (!(*scan_count)) {
  1881. /* TODO: race condition when FLUSH already called */
  1882. dhd_iscan_free_buf(dhdp, 0);
  1883. }
  1884. fail:
  1885. return status;
  1886. }
  1887. #endif /* SIMPLE_ISCAN */
  1888. /*
  1889. * returns = TRUE if associated, FALSE if not associated
  1890. */
  1891. bool dhd_is_associated(dhd_pub_t *dhd, void *bss_buf, int *retval)
  1892. {
  1893. char bssid[6], zbuf[6];
  1894. int ret = -1;
  1895. bzero(bssid, 6);
  1896. bzero(zbuf, 6);
  1897. ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_BSSID, (char *)&bssid, ETHER_ADDR_LEN, FALSE, 0);
  1898. DHD_TRACE((" %s WLC_GET_BSSID ioctl res = %d\n", __FUNCTION__, ret));
  1899. if (ret == BCME_NOTASSOCIATED) {
  1900. DHD_TRACE(("%s: not associated! res:%d\n", __FUNCTION__, ret));
  1901. }
  1902. if (retval)
  1903. *retval = ret;
  1904. if (ret < 0)
  1905. return FALSE;
  1906. if ((memcmp(bssid, zbuf, ETHER_ADDR_LEN) != 0)) {
  1907. /* STA is assocoated BSSID is non zero */
  1908. if (bss_buf) {
  1909. /* return bss if caller provided buf */
  1910. memcpy(bss_buf, bssid, ETHER_ADDR_LEN);
  1911. }
  1912. return TRUE;
  1913. } else {
  1914. DHD_TRACE(("%s: WLC_GET_BSSID ioctl returned zero bssid\n", __FUNCTION__));
  1915. return FALSE;
  1916. }
  1917. }
  1918. /* Function to estimate possible DTIM_SKIP value */
  1919. int
  1920. dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd)
  1921. {
  1922. int bcn_li_dtim = 1; /* deafult no dtim skip setting */
  1923. int ret = -1;
  1924. int dtim_period = 0;
  1925. int ap_beacon = 0;
  1926. #ifndef ENABLE_MAX_DTIM_IN_SUSPEND
  1927. int allowed_skip_dtim_cnt = 0;
  1928. #endif /* !ENABLE_MAX_DTIM_IN_SUSPEND */
  1929. /* Check if associated */
  1930. if (dhd_is_associated(dhd, NULL, NULL) == FALSE) {
  1931. DHD_TRACE(("%s NOT assoc ret %d\n", __FUNCTION__, ret));
  1932. goto exit;
  1933. }
  1934. /* read associated AP beacon interval */
  1935. if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_BCNPRD,
  1936. &ap_beacon, sizeof(ap_beacon), FALSE, 0)) < 0) {
  1937. DHD_ERROR(("%s get beacon failed code %d\n", __FUNCTION__, ret));
  1938. goto exit;
  1939. }
  1940. /* read associated ap's dtim setup */
  1941. if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_DTIMPRD,
  1942. &dtim_period, sizeof(dtim_period), FALSE, 0)) < 0) {
  1943. DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret));
  1944. goto exit;
  1945. }
  1946. /* if not assocated just eixt */
  1947. if (dtim_period == 0) {
  1948. goto exit;
  1949. }
  1950. #ifdef ENABLE_MAX_DTIM_IN_SUSPEND
  1951. bcn_li_dtim = (int) (MAX_DTIM_ALLOWED_INTERVAL / (ap_beacon * dtim_period));
  1952. if (bcn_li_dtim == 0) {
  1953. bcn_li_dtim = 1;
  1954. }
  1955. #else /* ENABLE_MAX_DTIM_IN_SUSPEND */
  1956. /* attemp to use platform defined dtim skip interval */
  1957. bcn_li_dtim = dhd->suspend_bcn_li_dtim;
  1958. /* check if sta listen interval fits into AP dtim */
  1959. if (dtim_period > CUSTOM_LISTEN_INTERVAL) {
  1960. /* AP DTIM to big for our Listen Interval : no dtim skiping */
  1961. bcn_li_dtim = NO_DTIM_SKIP;
  1962. DHD_ERROR(("%s DTIM=%d > Listen=%d : too big ...\n",
  1963. __FUNCTION__, dtim_period, CUSTOM_LISTEN_INTERVAL));
  1964. goto exit;
  1965. }
  1966. if ((dtim_period * ap_beacon * bcn_li_dtim) > MAX_DTIM_ALLOWED_INTERVAL) {
  1967. allowed_skip_dtim_cnt = MAX_DTIM_ALLOWED_INTERVAL / (dtim_period * ap_beacon);
  1968. bcn_li_dtim = (allowed_skip_dtim_cnt != 0) ? allowed_skip_dtim_cnt : NO_DTIM_SKIP;
  1969. }
  1970. if ((bcn_li_dtim * dtim_period) > CUSTOM_LISTEN_INTERVAL) {
  1971. /* Round up dtim_skip to fit into STAs Listen Interval */
  1972. bcn_li_dtim = (int)(CUSTOM_LISTEN_INTERVAL / dtim_period);
  1973. DHD_TRACE(("%s agjust dtim_skip as %d\n", __FUNCTION__, bcn_li_dtim));
  1974. }
  1975. #endif /* ENABLE_MAX_DTIM_IN_SUSPEND */
  1976. DHD_ERROR(("%s beacon=%d bcn_li_dtim=%d DTIM=%d Listen=%d\n",
  1977. __FUNCTION__, ap_beacon, bcn_li_dtim, dtim_period, CUSTOM_LISTEN_INTERVAL));
  1978. exit:
  1979. return bcn_li_dtim;
  1980. }
  1981. /* Check if the mode supports STA MODE */
  1982. bool dhd_support_sta_mode(dhd_pub_t *dhd)
  1983. {
  1984. #ifdef WL_CFG80211
  1985. if (!(dhd->op_mode & DHD_FLAG_STA_MODE))
  1986. return FALSE;
  1987. else
  1988. #endif /* WL_CFG80211 */
  1989. return TRUE;
  1990. }
  1991. #if defined(KEEP_ALIVE)
  1992. int dhd_keep_alive_onoff(dhd_pub_t *dhd)
  1993. {
  1994. char buf[256];
  1995. const char *str;
  1996. wl_mkeep_alive_pkt_t mkeep_alive_pkt = {0};
  1997. wl_mkeep_alive_pkt_t *mkeep_alive_pktp;
  1998. int buf_len;
  1999. int str_len;
  2000. int res = -1;
  2001. if (!dhd_support_sta_mode(dhd))
  2002. return res;
  2003. DHD_TRACE(("%s execution\n", __FUNCTION__));
  2004. str = "mkeep_alive";
  2005. str_len = strlen(str);
  2006. strncpy(buf, str, str_len);
  2007. buf[ str_len ] = '\0';
  2008. mkeep_alive_pktp = (wl_mkeep_alive_pkt_t *) (buf + str_len + 1);
  2009. mkeep_alive_pkt.period_msec = CUSTOM_KEEP_ALIVE_SETTING;
  2010. buf_len = str_len + 1;
  2011. mkeep_alive_pkt.version = htod16(WL_MKEEP_ALIVE_VERSION);
  2012. mkeep_alive_pkt.length = htod16(WL_MKEEP_ALIVE_FIXED_LEN);
  2013. /* Setup keep alive zero for null packet generation */
  2014. mkeep_alive_pkt.keep_alive_id = 0;
  2015. mkeep_alive_pkt.len_bytes = 0;
  2016. buf_len += WL_MKEEP_ALIVE_FIXED_LEN;
  2017. bzero(mkeep_alive_pkt.data, sizeof(mkeep_alive_pkt.data));
  2018. /* Keep-alive attributes are set in local variable (mkeep_alive_pkt), and
  2019. * then memcpy'ed into buffer (mkeep_alive_pktp) since there is no
  2020. * guarantee that the buffer is properly aligned.
  2021. */
  2022. memcpy((char *)mkeep_alive_pktp, &mkeep_alive_pkt, WL_MKEEP_ALIVE_FIXED_LEN);
  2023. res = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, buf_len, TRUE, 0);
  2024. return res;
  2025. }
  2026. #endif /* defined(KEEP_ALIVE) */
  2027. /* Android ComboSCAN support */
  2028. /*
  2029. * data parsing from ComboScan tlv list
  2030. */
  2031. int
  2032. wl_iw_parse_data_tlv(char** list_str, void *dst, int dst_size, const char token,
  2033. int input_size, int *bytes_left)
  2034. {
  2035. char* str;
  2036. uint16 short_temp;
  2037. uint32 int_temp;
  2038. if ((list_str == NULL) || (*list_str == NULL) ||(bytes_left == NULL) || (*bytes_left < 0)) {
  2039. DHD_ERROR(("%s error paramters\n", __FUNCTION__));
  2040. return -1;
  2041. }
  2042. str = *list_str;
  2043. /* Clean all dest bytes */
  2044. memset(dst, 0, dst_size);
  2045. while (*bytes_left > 0) {
  2046. if (str[0] != token) {
  2047. DHD_TRACE(("%s NOT Type=%d get=%d left_parse=%d \n",
  2048. __FUNCTION__, token, str[0], *bytes_left));
  2049. return -1;
  2050. }
  2051. *bytes_left -= 1;
  2052. str += 1;
  2053. if (input_size == 1) {
  2054. memcpy(dst, str, input_size);
  2055. }
  2056. else if (input_size == 2) {
  2057. memcpy(dst, (char *)htod16(memcpy(&short_temp, str, input_size)),
  2058. input_size);
  2059. }
  2060. else if (input_size == 4) {
  2061. memcpy(dst, (char *)htod32(memcpy(&int_temp, str, input_size)),
  2062. input_size);
  2063. }
  2064. *bytes_left -= input_size;
  2065. str += input_size;
  2066. *list_str = str;
  2067. return 1;
  2068. }
  2069. return 1;
  2070. }
  2071. #define CSCAN_TLV_TYPE_SSID_IE 'S'
  2072. /*
  2073. * SSIDs list parsing from cscan tlv list
  2074. */
  2075. int
  2076. wl_iw_parse_ssid_list_tlv(char** list_str, wlc_ssid_t* ssid, int max, int *bytes_left)
  2077. {
  2078. char* str;
  2079. int idx = 0;
  2080. if ((list_str == NULL) || (*list_str == NULL) || (*bytes_left < 0)) {
  2081. DHD_ERROR(("%s error paramters\n", __FUNCTION__));
  2082. return -1;
  2083. }
  2084. str = *list_str;
  2085. while (*bytes_left > 0) {
  2086. if (str[0] != CSCAN_TLV_TYPE_SSID_IE) {
  2087. *list_str = str;
  2088. DHD_TRACE(("nssid=%d left_parse=%d %d\n", idx, *bytes_left, str[0]));
  2089. return idx;
  2090. }
  2091. /* Get proper CSCAN_TLV_TYPE_SSID_IE */
  2092. *bytes_left -= 1;
  2093. str += 1;
  2094. if (str[0] == 0) {
  2095. /* Broadcast SSID */
  2096. ssid[idx].SSID_len = 0;
  2097. memset((char*)ssid[idx].SSID, 0x0, DOT11_MAX_SSID_LEN);
  2098. *bytes_left -= 1;
  2099. str += 1;
  2100. DHD_TRACE(("BROADCAST SCAN left=%d\n", *bytes_left));
  2101. }
  2102. else if (str[0] <= DOT11_MAX_SSID_LEN) {
  2103. /* Get proper SSID size */
  2104. ssid[idx].SSID_len = str[0];
  2105. *bytes_left -= 1;
  2106. str += 1;
  2107. /* Get SSID */
  2108. if (ssid[idx].SSID_len > *bytes_left) {
  2109. DHD_ERROR(("%s out of memory range len=%d but left=%d\n",
  2110. __FUNCTION__, ssid[idx].SSID_len, *bytes_left));
  2111. return -1;
  2112. }
  2113. memcpy((char*)ssid[idx].SSID, str, ssid[idx].SSID_len);
  2114. *bytes_left -= ssid[idx].SSID_len;
  2115. str += ssid[idx].SSID_len;
  2116. DHD_TRACE(("%s :size=%d left=%d\n",
  2117. (char*)ssid[idx].SSID, ssid[idx].SSID_len, *bytes_left));
  2118. }
  2119. else {
  2120. DHD_ERROR(("### SSID size more that %d\n", str[0]));
  2121. return -1;
  2122. }
  2123. if (idx++ > max) {
  2124. DHD_ERROR(("%s number of SSIDs more that %d\n", __FUNCTION__, idx));
  2125. return -1;
  2126. }
  2127. }
  2128. *list_str = str;
  2129. return idx;
  2130. }
  2131. #if defined(DHD_8021X_DUMP)
  2132. /* Parse EAPOL 4 way handshake messages */
  2133. void
  2134. dhd_dump_eapol_4way_message(char *dump_data, bool direction)
  2135. {
  2136. unsigned char type;
  2137. int pair, ack, mic, kerr, req, sec, install;
  2138. unsigned short us_tmp;
  2139. type = dump_data[18];
  2140. if (type == 2 || type == 254) {
  2141. us_tmp = (dump_data[19] << 8) | dump_data[20];
  2142. pair = 0 != (us_tmp & 0x08);
  2143. ack = 0 != (us_tmp & 0x80);
  2144. mic = 0 != (us_tmp & 0x100);
  2145. kerr = 0 != (us_tmp & 0x400);
  2146. req = 0 != (us_tmp & 0x800);
  2147. sec = 0 != (us_tmp & 0x200);
  2148. install = 0 != (us_tmp & 0x40);
  2149. if (!sec && !mic && ack && !install && pair && !kerr && !req) {
  2150. DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M1 of 4way\n",
  2151. direction ? "TX" : "RX"));
  2152. } else if (pair && !install && !ack && mic && !sec && !kerr && !req) {
  2153. DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M2 of 4way\n",
  2154. direction ? "TX" : "RX"));
  2155. } else if (pair && ack && mic && sec && !kerr && !req) {
  2156. DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M3 of 4way\n",
  2157. direction ? "TX" : "RX"));
  2158. } else if (pair && !install && !ack && mic && sec && !req && !kerr) {
  2159. DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M4 of 4way\n",
  2160. direction ? "TX" : "RX"));
  2161. } else {
  2162. DHD_ERROR(("ETHER_TYPE_802_1X [%s]: ver %d, type %d, replay %d\n",
  2163. direction ? "TX" : "RX",
  2164. dump_data[14], dump_data[15], dump_data[30]));
  2165. }
  2166. } else {
  2167. DHD_ERROR(("ETHER_TYPE_802_1X [%s]: ver %d, type %d, replay %d\n",
  2168. direction ? "TX" : "RX",
  2169. dump_data[14], dump_data[15], dump_data[30]));
  2170. }
  2171. }
  2172. #endif /* DHD_8021X_DUMP */