12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540 |
- /*
- * Broadcom Dongle Host Driver (DHD), common DHD core.
- *
- * Copyright (C) 1999-2015, Broadcom Corporation
- *
- * Unless you and Broadcom execute a separate written software license
- * agreement governing use of this software, this software is licensed to you
- * under the terms of the GNU General Public License version 2 (the "GPL"),
- * available at http://www.broadcom.com/licenses/GPLv2.php, with the
- * following added to such license:
- *
- * As a special exception, the copyright holders of this software give you
- * permission to link this software with independent modules, and to copy and
- * distribute the resulting executable under terms of your choice, provided that
- * you also meet, for each linked independent module, the terms and conditions of
- * the license of that module. An independent module is a module which is not
- * derived from this software. The special exception does not apply to any
- * modifications of the software.
- *
- * Notwithstanding the above, under no circumstances may you combine this
- * software in any way with any other Broadcom software provided under a license
- * other than the GPL, without Broadcom's express prior written consent.
- *
- * $Id: dhd_common.c 605803 2015-12-11 14:44:32Z $
- */
- #include <typedefs.h>
- #include <osl.h>
- #include <epivers.h>
- #include <bcmutils.h>
- #include <bcmendian.h>
- #include <dngl_stats.h>
- #include <wlioctl.h>
- #include <dhd.h>
- #include <dhd_ip.h>
- #include <proto/bcmevent.h>
- #include <dhd_bus.h>
- #include <dhd_proto.h>
- #include <dhd_dbg.h>
- #include <msgtrace.h>
- #ifdef WL_CFG80211
- #include <wl_cfg80211.h>
- #endif
- #ifdef WLBTAMP
- #include <proto/bt_amp_hci.h>
- #include <dhd_bta.h>
- #endif
- #ifdef PNO_SUPPORT
- #include <dhd_pno.h>
- #endif
- #ifdef SET_RANDOM_MAC_SOFTAP
- #include <linux/random.h>
- #include <linux/jiffies.h>
- #endif
- #define htod32(i) (i)
- #define htod16(i) (i)
- #define dtoh32(i) (i)
- #define dtoh16(i) (i)
- #define htodchanspec(i) (i)
- #define dtohchanspec(i) (i)
- #ifdef PROP_TXSTATUS
- #include <wlfc_proto.h>
- #include <dhd_wlfc.h>
- #endif
- #ifdef WLMEDIA_HTSF
- extern void htsf_update(struct dhd_info *dhd, void *data);
- #endif
- int dhd_msg_level = DHD_ERROR_VAL;
- #ifdef SOFTAP
- char fw_path2[MOD_PARAM_PATHLEN];
- extern bool softap_enabled;
- #endif
- /* Last connection success/failure status */
- uint32 dhd_conn_event;
- uint32 dhd_conn_status;
- uint32 dhd_conn_reason;
- extern int dhd_iscan_request(void * dhdp, uint16 action);
- extern void dhd_ind_scan_confirm(void *h, bool status);
- extern int dhd_iscan_in_progress(void *h);
- void dhd_iscan_lock(void);
- void dhd_iscan_unlock(void);
- extern int dhd_change_mtu(dhd_pub_t *dhd, int new_mtu, int ifidx);
- #if !defined(AP) && defined(WLP2P)
- extern int dhd_get_concurrent_capabilites(dhd_pub_t *dhd);
- #endif
- bool ap_cfg_running = FALSE;
- bool ap_fw_loaded = FALSE;
- /* Version string to report */
- #ifdef DHD_DEBUG
- #ifndef SRCBASE
- #define SRCBASE "drivers/net/wireless/bcmdhd"
- #endif
- #define DHD_COMPILED "\nCompiled in " SRCBASE
- #endif /* DHD_DEBUG */
- #if defined(DHD_DEBUG)
- const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
- DHD_COMPILED " on " __DATE__ " at " __TIME__;
- #else
- const char dhd_version[] = "\nDongle Host Driver, version " EPI_VERSION_STR "\nCompiled from ";
- #endif
- #ifdef DHD_LOG_DUMP
- char fw_version[FW_VER_STR_LEN] = "\0";
- #endif /* DHD_LOG_DUMP */
- void dhd_set_timer(void *bus, uint wdtick);
- /* IOVar table */
- enum {
- IOV_VERSION = 1,
- IOV_MSGLEVEL,
- IOV_BCMERRORSTR,
- IOV_BCMERROR,
- IOV_WDTICK,
- IOV_DUMP,
- IOV_CLEARCOUNTS,
- IOV_LOGDUMP,
- IOV_LOGCAL,
- IOV_LOGSTAMP,
- IOV_GPIOOB,
- IOV_IOCTLTIMEOUT,
- #ifdef WLBTAMP
- IOV_HCI_CMD, /* HCI command */
- IOV_HCI_ACL_DATA, /* HCI data packet */
- #endif
- #if defined(DHD_DEBUG)
- IOV_CONS,
- IOV_DCONSOLE_POLL,
- #endif /* defined(DHD_DEBUG) */
- #ifdef PROP_TXSTATUS
- IOV_PROPTXSTATUS_ENABLE,
- IOV_PROPTXSTATUS_MODE,
- IOV_PROPTXSTATUS_OPT,
- IOV_PROPTXSTATUS_MODULE_IGNORE,
- IOV_PROPTXSTATUS_CREDIT_IGNORE,
- IOV_PROPTXSTATUS_TXSTATUS_IGNORE,
- IOV_PROPTXSTATUS_RXPKT_CHK,
- #endif /* PROP_TXSTATUS */
- IOV_BUS_TYPE,
- #ifdef WLMEDIA_HTSF
- IOV_WLPKTDLYSTAT_SZ,
- #endif
- IOV_CHANGEMTU,
- IOV_HOSTREORDER_FLOWS,
- #ifdef DHDTCPACK_SUPPRESS
- IOV_TCPACK_SUPPRESS,
- #endif /* DHDTCPACK_SUPPRESS */
- IOV_LAST
- };
- const bcm_iovar_t dhd_iovars[] = {
- {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(dhd_version) },
- #ifdef DHD_DEBUG
- {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0 },
- #endif /* DHD_DEBUG */
- {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN },
- {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0 },
- {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0 },
- {"dump", IOV_DUMP, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN },
- #ifdef DHD_DEBUG
- {"cons", IOV_CONS, 0, IOVT_BUFFER, 0 },
- {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0 },
- #endif
- {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0 },
- {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0 },
- {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0 },
- #ifdef WLBTAMP
- {"HCI_cmd", IOV_HCI_CMD, 0, IOVT_BUFFER, 0},
- {"HCI_ACL_data", IOV_HCI_ACL_DATA, 0, IOVT_BUFFER, 0},
- #endif
- #ifdef PROP_TXSTATUS
- {"proptx", IOV_PROPTXSTATUS_ENABLE, 0, IOVT_BOOL, 0 },
- /*
- set the proptxtstatus operation mode:
- 0 - Do not do any proptxtstatus flow control
- 1 - Use implied credit from a packet status
- 2 - Use explicit credit
- */
- {"ptxmode", IOV_PROPTXSTATUS_MODE, 0, IOVT_UINT32, 0 },
- {"proptx_opt", IOV_PROPTXSTATUS_OPT, 0, IOVT_UINT32, 0 },
- {"pmodule_ignore", IOV_PROPTXSTATUS_MODULE_IGNORE, 0, IOVT_BOOL, 0 },
- {"pcredit_ignore", IOV_PROPTXSTATUS_CREDIT_IGNORE, 0, IOVT_BOOL, 0 },
- {"ptxstatus_ignore", IOV_PROPTXSTATUS_TXSTATUS_IGNORE, 0, IOVT_BOOL, 0 },
- {"rxpkt_chk", IOV_PROPTXSTATUS_RXPKT_CHK, 0, IOVT_BOOL, 0 },
- #endif /* PROP_TXSTATUS */
- {"bustype", IOV_BUS_TYPE, 0, IOVT_UINT32, 0},
- #ifdef WLMEDIA_HTSF
- {"pktdlystatsz", IOV_WLPKTDLYSTAT_SZ, 0, IOVT_UINT8, 0 },
- #endif
- {"changemtu", IOV_CHANGEMTU, 0, IOVT_UINT32, 0 },
- {"host_reorder_flows", IOV_HOSTREORDER_FLOWS, 0, IOVT_BUFFER,
- (WLHOST_REORDERDATA_MAXFLOWS + 1) },
- #ifdef DHDTCPACK_SUPPRESS
- {"tcpack_suppress", IOV_TCPACK_SUPPRESS, 0, IOVT_UINT8, 0 },
- #endif /* DHDTCPACK_SUPPRESS */
- {NULL, 0, 0, 0, 0 }
- };
- #define DHD_IOVAR_BUF_SIZE 128
- /* to NDIS developer, the structure dhd_common is redundant,
- * please do NOT merge it back from other branches !!!
- */
- static int
- dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen)
- {
- char eabuf[ETHER_ADDR_STR_LEN];
- struct bcmstrbuf b;
- struct bcmstrbuf *strbuf = &b;
- if (!dhdp || !dhdp->prot || !buf)
- return BCME_ERROR;
- bcm_binit(strbuf, buf, buflen);
- /* Base DHD info */
- bcm_bprintf(strbuf, "%s\n", dhd_version);
- bcm_bprintf(strbuf, "\n");
- bcm_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n",
- dhdp->up, dhdp->txoff, dhdp->busstate);
- bcm_bprintf(strbuf, "pub.hdrlen %u pub.maxctl %u pub.rxsz %u\n",
- dhdp->hdrlen, dhdp->maxctl, dhdp->rxsz);
- bcm_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %s\n",
- dhdp->iswl, dhdp->drv_version, bcm_ether_ntoa(&dhdp->mac, eabuf));
- bcm_bprintf(strbuf, "pub.bcmerror %d tickcnt %u\n", dhdp->bcmerror, dhdp->tickcnt);
- bcm_bprintf(strbuf, "dongle stats:\n");
- bcm_bprintf(strbuf, "tx_packets %lu tx_bytes %lu tx_errors %lu tx_dropped %lu\n",
- dhdp->dstats.tx_packets, dhdp->dstats.tx_bytes,
- dhdp->dstats.tx_errors, dhdp->dstats.tx_dropped);
- bcm_bprintf(strbuf, "rx_packets %lu rx_bytes %lu rx_errors %lu rx_dropped %lu\n",
- dhdp->dstats.rx_packets, dhdp->dstats.rx_bytes,
- dhdp->dstats.rx_errors, dhdp->dstats.rx_dropped);
- bcm_bprintf(strbuf, "multicast %lu\n", dhdp->dstats.multicast);
- bcm_bprintf(strbuf, "bus stats:\n");
- bcm_bprintf(strbuf, "tx_packets %lu tx_multicast %lu tx_errors %lu\n",
- dhdp->tx_packets, dhdp->tx_multicast, dhdp->tx_errors);
- bcm_bprintf(strbuf, "tx_ctlpkts %lu tx_ctlerrs %lu\n",
- dhdp->tx_ctlpkts, dhdp->tx_ctlerrs);
- bcm_bprintf(strbuf, "rx_packets %lu rx_multicast %lu rx_errors %lu \n",
- dhdp->rx_packets, dhdp->rx_multicast, dhdp->rx_errors);
- bcm_bprintf(strbuf, "rx_ctlpkts %lu rx_ctlerrs %lu rx_dropped %lu\n",
- dhdp->rx_ctlpkts, dhdp->rx_ctlerrs, dhdp->rx_dropped);
- bcm_bprintf(strbuf, "rx_readahead_cnt %lu tx_realloc %lu\n",
- dhdp->rx_readahead_cnt, dhdp->tx_realloc);
- bcm_bprintf(strbuf, "\n");
- /* Add any prot info */
- dhd_prot_dump(dhdp, strbuf);
- bcm_bprintf(strbuf, "\n");
- /* Add any bus info */
- dhd_bus_dump(dhdp, strbuf);
- return (!strbuf->size ? BCME_BUFTOOSHORT : 0);
- }
- int
- dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set, int ifindex)
- {
- wl_ioctl_t ioc;
- ioc.cmd = cmd;
- ioc.buf = arg;
- ioc.len = len;
- ioc.set = set;
- return dhd_wl_ioctl(dhd_pub, ifindex, &ioc, arg, len);
- }
- int
- dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len)
- {
- int ret = 0;
- if (dhd_os_proto_block(dhd_pub))
- {
- #ifdef DHD_LOG_DUMP
- int slen, i, val, rem;
- long int lval;
- char *pval, *pos, *msg;
- char tmp[64];
- /* WLC_GET_VAR */
- if (ioc->cmd == WLC_GET_VAR) {
- memset(tmp, 0, sizeof(tmp));
- bcopy(ioc->buf, tmp, strlen(ioc->buf) + 1);
- }
- #endif /* DHD_LOG_DUMP */
- ret = dhd_prot_ioctl(dhd_pub, ifindex, ioc, buf, len);
- #if defined(CUSTOMER_HW4)
- if ((ret || ret == -ETIMEDOUT) && (dhd_pub->up))
- #else
- if ((ret) && (dhd_pub->up))
- #endif /* CUSTOMER_HW4 */
- /* Send hang event only if dhd_open() was success */
- dhd_os_check_hang(dhd_pub, ifindex, ret);
- if (ret == -ETIMEDOUT && !dhd_pub->up) {
- DHD_ERROR(("%s: 'resumed on timeout' error is "
- "occurred before the interface does not"
- " bring up\n", __FUNCTION__));
- dhd_pub->busstate = DHD_BUS_DOWN;
- }
- dhd_os_proto_unblock(dhd_pub);
- #ifdef DHD_LOG_DUMP
- if (ioc->cmd == WLC_GET_VAR || ioc->cmd == WLC_SET_VAR) {
- lval = 0;
- slen = strlen(ioc->buf) + 1;
- msg = (char*)ioc->buf;
- if (ioc->cmd == WLC_GET_VAR) {
- bcopy(msg, &lval, sizeof(long int));
- msg = tmp;
- } else {
- bcopy((msg + slen), &lval, sizeof(long int));
- }
- DHD_ERROR_EX(("%s: cmd: %d, msg: %s, val: 0x%lx, len: %d, set: %d\n",
- ioc->cmd == WLC_GET_VAR ? "WLC_GET_VAR" : "WLC_SET_VAR",
- ioc->cmd, msg, lval, ioc->len, ioc->set));
- } else {
- slen = ioc->len;
- if (ioc->buf != NULL) {
- val = *(int*)ioc->buf;
- pval = (char*)ioc->buf;
- pos = tmp;
- rem = sizeof(tmp);
- memset(tmp, 0, sizeof(tmp));
- for (i = 0; i < slen; i++) {
- pos += snprintf(pos, rem, "%02x ", pval[i]);
- rem = sizeof(tmp) - (int)(pos - tmp);
- if (rem <= 0) {
- break;
- }
- }
- DHD_ERROR_EX(("WLC_IOCTL: cmd: %d, val: %d (%s), len: %d, "
- "set: %d\n", ioc->cmd, val, tmp, ioc->len, ioc->set));
- } else {
- DHD_ERROR_EX(("WLC_IOCTL: cmd: %d, buf is NULL\n", ioc->cmd));
- }
- }
- #endif /* DHD_LOG_DUMP */
- #if defined(CUSTOMER_HW4)
- if (ret < 0) {
- if (ioc->cmd == WLC_GET_VAR)
- DHD_ERROR(("%s: WLC_GET_VAR: %s, ret = %d\n",
- __FUNCTION__, (char *)ioc->buf, ret));
- else if (ioc->cmd == WLC_SET_VAR)
- DHD_ERROR(("%s: WLC_SET_VAR: %s, ret = %d\n",
- __FUNCTION__, (char *)ioc->buf, ret));
- else
- DHD_ERROR(("%s: WLC_IOCTL: cmd: %d, ret = %d\n",
- __FUNCTION__, ioc->cmd, ret));
- }
- #endif /* OEM_ANDROID && CUSTOMER_HW4 */
- }
- return ret;
- }
- static int
- dhd_doiovar(dhd_pub_t *dhd_pub, const bcm_iovar_t *vi, uint32 actionid, const char *name,
- void *params, int plen, void *arg, int len, int val_size)
- {
- int bcmerror = 0;
- int32 int_val = 0;
- DHD_TRACE(("%s: Enter\n", __FUNCTION__));
- DHD_TRACE(("%s: actionid = %d; name %s\n", __FUNCTION__, actionid, name));
- if ((bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid))) != 0)
- goto exit;
- if (plen >= (int)sizeof(int_val))
- bcopy(params, &int_val, sizeof(int_val));
- switch (actionid) {
- case IOV_GVAL(IOV_VERSION):
- /* Need to have checked buffer length */
- bcm_strncpy_s((char*)arg, len, dhd_version, len);
- break;
- case IOV_GVAL(IOV_MSGLEVEL):
- int_val = (int32)dhd_msg_level;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_MSGLEVEL):
- #ifdef WL_CFG80211
- /* Enable DHD and WL logs in oneshot */
- if (int_val & DHD_WL_VAL2)
- wl_cfg80211_enable_trace(TRUE, int_val & (~DHD_WL_VAL2));
- else if (int_val & DHD_WL_VAL)
- wl_cfg80211_enable_trace(FALSE, WL_DBG_DBG);
- if (!(int_val & DHD_WL_VAL2))
- #endif /* WL_CFG80211 */
- dhd_msg_level = int_val;
- break;
- case IOV_GVAL(IOV_BCMERRORSTR):
- bcm_strncpy_s((char *)arg, len, bcmerrorstr(dhd_pub->bcmerror), BCME_STRLEN);
- ((char *)arg)[BCME_STRLEN - 1] = 0x00;
- break;
- case IOV_GVAL(IOV_BCMERROR):
- int_val = (int32)dhd_pub->bcmerror;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_GVAL(IOV_WDTICK):
- int_val = (int32)dhd_watchdog_ms;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_WDTICK):
- if (!dhd_pub->up) {
- bcmerror = BCME_NOTUP;
- break;
- }
- dhd_os_wd_timer(dhd_pub, (uint)int_val);
- break;
- case IOV_GVAL(IOV_DUMP):
- bcmerror = dhd_dump(dhd_pub, arg, len);
- break;
- #ifdef DHD_DEBUG
- case IOV_GVAL(IOV_DCONSOLE_POLL):
- int_val = (int32)dhd_console_ms;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_DCONSOLE_POLL):
- dhd_console_ms = (uint)int_val;
- break;
- case IOV_SVAL(IOV_CONS):
- if (len > 0)
- bcmerror = dhd_bus_console_in(dhd_pub, arg, len - 1);
- break;
- #endif /* DHD_DEBUG */
- case IOV_SVAL(IOV_CLEARCOUNTS):
- dhd_pub->tx_packets = dhd_pub->rx_packets = 0;
- dhd_pub->tx_errors = dhd_pub->rx_errors = 0;
- dhd_pub->tx_ctlpkts = dhd_pub->rx_ctlpkts = 0;
- dhd_pub->tx_ctlerrs = dhd_pub->rx_ctlerrs = 0;
- dhd_pub->rx_dropped = 0;
- dhd_pub->rx_readahead_cnt = 0;
- dhd_pub->tx_realloc = 0;
- dhd_pub->wd_dpc_sched = 0;
- memset(&dhd_pub->dstats, 0, sizeof(dhd_pub->dstats));
- dhd_bus_clearcounts(dhd_pub);
- #ifdef PROP_TXSTATUS
- /* clear proptxstatus related counters */
- dhd_wlfc_clear_counts(dhd_pub);
- #endif /* PROP_TXSTATUS */
- break;
- case IOV_GVAL(IOV_IOCTLTIMEOUT): {
- int_val = (int32)dhd_os_get_ioctl_resp_timeout();
- bcopy(&int_val, arg, sizeof(int_val));
- break;
- }
- case IOV_SVAL(IOV_IOCTLTIMEOUT): {
- if (int_val <= 0)
- bcmerror = BCME_BADARG;
- else
- dhd_os_set_ioctl_resp_timeout((unsigned int)int_val);
- break;
- }
- #ifdef WLBTAMP
- case IOV_SVAL(IOV_HCI_CMD): {
- amp_hci_cmd_t *cmd = (amp_hci_cmd_t *)arg;
- /* sanity check: command preamble present */
- if (len < HCI_CMD_PREAMBLE_SIZE)
- return BCME_BUFTOOSHORT;
- /* sanity check: command parameters are present */
- if (len < (int)(HCI_CMD_PREAMBLE_SIZE + cmd->plen))
- return BCME_BUFTOOSHORT;
- dhd_bta_docmd(dhd_pub, cmd, len);
- break;
- }
- case IOV_SVAL(IOV_HCI_ACL_DATA): {
- amp_hci_ACL_data_t *ACL_data = (amp_hci_ACL_data_t *)arg;
- /* sanity check: HCI header present */
- if (len < HCI_ACL_DATA_PREAMBLE_SIZE)
- return BCME_BUFTOOSHORT;
- /* sanity check: ACL data is present */
- if (len < (int)(HCI_ACL_DATA_PREAMBLE_SIZE + ACL_data->dlen))
- return BCME_BUFTOOSHORT;
- dhd_bta_tx_hcidata(dhd_pub, ACL_data, len);
- break;
- }
- #endif /* WLBTAMP */
- #ifdef PROP_TXSTATUS
- case IOV_GVAL(IOV_PROPTXSTATUS_ENABLE): {
- bool wlfc_enab = FALSE;
- bcmerror = dhd_wlfc_get_enable(dhd_pub, &wlfc_enab);
- if (bcmerror != BCME_OK)
- goto exit;
- int_val = wlfc_enab ? 1 : 0;
- bcopy(&int_val, arg, val_size);
- break;
- }
- case IOV_SVAL(IOV_PROPTXSTATUS_ENABLE): {
- bool wlfc_enab = FALSE;
- bcmerror = dhd_wlfc_get_enable(dhd_pub, &wlfc_enab);
- if (bcmerror != BCME_OK)
- goto exit;
- /* wlfc is already set as desired */
- if (wlfc_enab == (int_val == 0 ? FALSE : TRUE))
- goto exit;
- if (int_val == TRUE)
- bcmerror = dhd_wlfc_init(dhd_pub);
- else
- bcmerror = dhd_wlfc_deinit(dhd_pub);
- break;
- }
- case IOV_GVAL(IOV_PROPTXSTATUS_MODE):
- bcmerror = dhd_wlfc_get_mode(dhd_pub, &int_val);
- if (bcmerror != BCME_OK)
- goto exit;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_PROPTXSTATUS_MODE):
- dhd_wlfc_set_mode(dhd_pub, int_val);
- break;
- case IOV_GVAL(IOV_PROPTXSTATUS_MODULE_IGNORE):
- bcmerror = dhd_wlfc_get_module_ignore(dhd_pub, &int_val);
- if (bcmerror != BCME_OK)
- goto exit;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_PROPTXSTATUS_MODULE_IGNORE):
- dhd_wlfc_set_module_ignore(dhd_pub, int_val);
- break;
- case IOV_GVAL(IOV_PROPTXSTATUS_CREDIT_IGNORE):
- bcmerror = dhd_wlfc_get_credit_ignore(dhd_pub, &int_val);
- if (bcmerror != BCME_OK)
- goto exit;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_PROPTXSTATUS_CREDIT_IGNORE):
- dhd_wlfc_set_credit_ignore(dhd_pub, int_val);
- break;
- case IOV_GVAL(IOV_PROPTXSTATUS_TXSTATUS_IGNORE):
- bcmerror = dhd_wlfc_get_txstatus_ignore(dhd_pub, &int_val);
- if (bcmerror != BCME_OK)
- goto exit;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_PROPTXSTATUS_TXSTATUS_IGNORE):
- dhd_wlfc_set_txstatus_ignore(dhd_pub, int_val);
- break;
- case IOV_GVAL(IOV_PROPTXSTATUS_RXPKT_CHK):
- bcmerror = dhd_wlfc_get_rxpkt_chk(dhd_pub, &int_val);
- if (bcmerror != BCME_OK)
- goto exit;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_PROPTXSTATUS_RXPKT_CHK):
- dhd_wlfc_set_rxpkt_chk(dhd_pub, int_val);
- break;
- #endif /* PROP_TXSTATUS */
- case IOV_GVAL(IOV_BUS_TYPE):
- /* The dhd application queries the driver to check if its usb or sdio. */
- #ifdef BCMDHDUSB
- int_val = BUS_TYPE_USB;
- #endif
- int_val = BUS_TYPE_SDIO;
- #ifdef PCIE_FULL_DONGLE
- int_val = BUS_TYPE_PCIE;
- #endif
- bcopy(&int_val, arg, val_size);
- break;
- #ifdef WLMEDIA_HTSF
- case IOV_GVAL(IOV_WLPKTDLYSTAT_SZ):
- int_val = dhd_pub->htsfdlystat_sz;
- bcopy(&int_val, arg, val_size);
- break;
- case IOV_SVAL(IOV_WLPKTDLYSTAT_SZ):
- dhd_pub->htsfdlystat_sz = int_val & 0xff;
- printf("Setting tsfdlystat_sz:%d\n", dhd_pub->htsfdlystat_sz);
- break;
- #endif
- case IOV_SVAL(IOV_CHANGEMTU):
- int_val &= 0xffff;
- bcmerror = dhd_change_mtu(dhd_pub, int_val, 0);
- break;
- case IOV_GVAL(IOV_HOSTREORDER_FLOWS):
- {
- uint i = 0;
- uint8 *ptr = (uint8 *)arg;
- uint8 count = 0;
- ptr++;
- for (i = 0; i < WLHOST_REORDERDATA_MAXFLOWS; i++) {
- if (dhd_pub->reorder_bufs[i] != NULL) {
- *ptr = dhd_pub->reorder_bufs[i]->flow_id;
- ptr++;
- count++;
- }
- }
- ptr = (uint8 *)arg;
- *ptr = count;
- break;
- }
- #ifdef DHDTCPACK_SUPPRESS
- case IOV_GVAL(IOV_TCPACK_SUPPRESS): {
- int_val = (uint32)dhd_pub->tcpack_sup_mode;
- bcopy(&int_val, arg, val_size);
- break;
- }
- case IOV_SVAL(IOV_TCPACK_SUPPRESS): {
- bcmerror = dhd_tcpack_suppress_set(dhd_pub, (uint8)int_val);
- break;
- }
- #endif /* DHDTCPACK_SUPPRESS */
- default:
- bcmerror = BCME_UNSUPPORTED;
- break;
- }
- exit:
- DHD_TRACE(("%s: actionid %d, bcmerror %d\n", __FUNCTION__, actionid, bcmerror));
- return bcmerror;
- }
- /* Store the status of a connection attempt for later retrieval by an iovar */
- void
- dhd_store_conn_status(uint32 event, uint32 status, uint32 reason)
- {
- /* Do not overwrite a WLC_E_PRUNE with a WLC_E_SET_SSID
- * because an encryption/rsn mismatch results in both events, and
- * the important information is in the WLC_E_PRUNE.
- */
- if (!(event == WLC_E_SET_SSID && status == WLC_E_STATUS_FAIL &&
- dhd_conn_event == WLC_E_PRUNE)) {
- dhd_conn_event = event;
- dhd_conn_status = status;
- dhd_conn_reason = reason;
- }
- }
- bool
- dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec)
- {
- void *p;
- int eprec = -1; /* precedence to evict from */
- bool discard_oldest;
- /* Fast case, precedence queue is not full and we are also not
- * exceeding total queue length
- */
- if (!pktq_pfull(q, prec) && !pktq_full(q)) {
- pktq_penq(q, prec, pkt);
- return TRUE;
- }
- /* Determine precedence from which to evict packet, if any */
- if (pktq_pfull(q, prec))
- eprec = prec;
- else if (pktq_full(q)) {
- p = pktq_peek_tail(q, &eprec);
- ASSERT(p);
- if (eprec > prec || eprec < 0)
- return FALSE;
- }
- /* Evict if needed */
- if (eprec >= 0) {
- /* Detect queueing to unconfigured precedence */
- ASSERT(!pktq_pempty(q, eprec));
- discard_oldest = AC_BITMAP_TST(dhdp->wme_dp, eprec);
- if (eprec == prec && !discard_oldest)
- return FALSE; /* refuse newer (incoming) packet */
- /* Evict packet according to discard policy */
- p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q, eprec);
- ASSERT(p);
- #ifdef DHDTCPACK_SUPPRESS
- if (dhd_tcpack_check_xmit(dhdp, p) == BCME_ERROR) {
- DHD_ERROR(("%s %d: tcpack_suppress ERROR!!! Stop using it\n",
- __FUNCTION__, __LINE__));
- dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_OFF);
- }
- #endif /* DHDTCPACK_SUPPRESS */
- PKTFREE(dhdp->osh, p, TRUE);
- }
- /* Enqueue */
- p = pktq_penq(q, prec, pkt);
- ASSERT(p);
- return TRUE;
- }
- /*
- * Functions to drop proper pkts from queue:
- * If one pkt in queue is non-fragmented, drop first non-fragmented pkt only
- * If all pkts in queue are all fragmented, find and drop one whole set fragmented pkts
- * If can't find pkts matching upper 2 cases, drop first pkt anyway
- */
- bool
- dhd_prec_drop_pkts(dhd_pub_t *dhdp, struct pktq *pq, int prec, f_droppkt_t fn)
- {
- struct pktq_prec *q = NULL;
- void *p, *prev = NULL, *next = NULL, *first = NULL, *last = NULL, *prev_first = NULL;
- pkt_frag_t frag_info;
- ASSERT(dhdp && pq);
- ASSERT(prec >= 0 && prec < pq->num_prec);
- q = &pq->q[prec];
- p = q->head;
- if (p == NULL)
- return FALSE;
- while (p) {
- frag_info = pkt_frag_info(dhdp->osh, p);
- if (frag_info == DHD_PKT_FRAG_NONE) {
- break;
- } else if (frag_info == DHD_PKT_FRAG_FIRST) {
- if (first) {
- /* No last frag pkt, use prev as last */
- last = prev;
- break;
- } else {
- first = p;
- prev_first = prev;
- }
- } else if (frag_info == DHD_PKT_FRAG_LAST) {
- if (first) {
- last = p;
- break;
- }
- }
- prev = p;
- p = PKTLINK(p);
- }
- if ((p == NULL) || ((frag_info != DHD_PKT_FRAG_NONE) && !(first && last))) {
- /* Not found matching pkts, use oldest */
- prev = NULL;
- p = q->head;
- frag_info = 0;
- }
- if (frag_info == DHD_PKT_FRAG_NONE) {
- first = last = p;
- prev_first = prev;
- }
- p = first;
- while (p) {
- next = PKTLINK(p);
- q->len--;
- pq->len--;
- PKTSETLINK(p, NULL);
- if (fn)
- fn(dhdp, prec, p, TRUE);
- if (p == last)
- break;
- p = next;
- }
- if (prev_first == NULL) {
- if ((q->head = next) == NULL)
- q->tail = NULL;
- } else {
- PKTSETLINK(prev_first, next);
- if (!next)
- q->tail = prev_first;
- }
- return TRUE;
- }
- static int
- dhd_iovar_op(dhd_pub_t *dhd_pub, const char *name,
- void *params, int plen, void *arg, int len, bool set)
- {
- int bcmerror = 0;
- int val_size;
- const bcm_iovar_t *vi = NULL;
- uint32 actionid;
- DHD_TRACE(("%s: Enter\n", __FUNCTION__));
- ASSERT(name);
- ASSERT(len >= 0);
- /* Get MUST have return space */
- ASSERT(set || (arg && len));
- /* Set does NOT take qualifiers */
- ASSERT(!set || (!params && !plen));
- if ((vi = bcm_iovar_lookup(dhd_iovars, name)) == NULL) {
- bcmerror = BCME_UNSUPPORTED;
- goto exit;
- }
- DHD_CTL(("%s: %s %s, len %d plen %d\n", __FUNCTION__,
- name, (set ? "set" : "get"), len, plen));
- /* set up 'params' pointer in case this is a set command so that
- * the convenience int and bool code can be common to set and get
- */
- if (params == NULL) {
- params = arg;
- plen = len;
- }
- if (vi->type == IOVT_VOID)
- val_size = 0;
- else if (vi->type == IOVT_BUFFER)
- val_size = len;
- else
- /* all other types are integer sized */
- val_size = sizeof(int);
- actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
- bcmerror = dhd_doiovar(dhd_pub, vi, actionid, name, params, plen, arg, len, val_size);
- exit:
- return bcmerror;
- }
- int
- dhd_ioctl(dhd_pub_t * dhd_pub, dhd_ioctl_t *ioc, void * buf, uint buflen)
- {
- int bcmerror = 0;
- DHD_TRACE(("%s: Enter\n", __FUNCTION__));
- if (!buf) {
- return BCME_BADARG;
- }
- switch (ioc->cmd) {
- case DHD_GET_MAGIC:
- if (buflen < sizeof(int))
- bcmerror = BCME_BUFTOOSHORT;
- else
- *(int*)buf = DHD_IOCTL_MAGIC;
- break;
- case DHD_GET_VERSION:
- if (buflen < sizeof(int))
- bcmerror = BCME_BUFTOOSHORT;
- else
- *(int*)buf = DHD_IOCTL_VERSION;
- break;
- case DHD_GET_VAR:
- case DHD_SET_VAR: {
- char *arg;
- uint arglen;
- /* scan past the name to any arguments */
- for (arg = buf, arglen = buflen; *arg && arglen; arg++, arglen--)
- ;
- if (*arg) {
- bcmerror = BCME_BUFTOOSHORT;
- break;
- }
- /* account for the NUL terminator */
- arg++, arglen--;
- /* call with the appropriate arguments */
- if (ioc->cmd == DHD_GET_VAR)
- bcmerror = dhd_iovar_op(dhd_pub, buf, arg, arglen,
- buf, buflen, IOV_GET);
- else
- bcmerror = dhd_iovar_op(dhd_pub, buf, NULL, 0, arg, arglen, IOV_SET);
- if (bcmerror != BCME_UNSUPPORTED)
- break;
- /* not in generic table, try protocol module */
- if (ioc->cmd == DHD_GET_VAR)
- bcmerror = dhd_prot_iovar_op(dhd_pub, buf, arg,
- arglen, buf, buflen, IOV_GET);
- else
- bcmerror = dhd_prot_iovar_op(dhd_pub, buf,
- NULL, 0, arg, arglen, IOV_SET);
- if (bcmerror != BCME_UNSUPPORTED)
- break;
- /* if still not found, try bus module */
- if (ioc->cmd == DHD_GET_VAR) {
- bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
- arg, arglen, buf, buflen, IOV_GET);
- } else {
- bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
- NULL, 0, arg, arglen, IOV_SET);
- }
- break;
- }
- default:
- bcmerror = BCME_UNSUPPORTED;
- }
- return bcmerror;
- }
- #ifdef SHOW_EVENTS
- static void
- wl_show_host_event(wl_event_msg_t *event, void *event_data)
- {
- uint i, status, reason;
- bool group = FALSE, flush_txq = FALSE, link = FALSE;
- const char *auth_str;
- const char *event_name;
- uchar *buf;
- char err_msg[256], eabuf[ETHER_ADDR_STR_LEN];
- uint event_type, flags, auth_type, datalen;
- event_type = ntoh32(event->event_type);
- flags = ntoh16(event->flags);
- status = ntoh32(event->status);
- reason = ntoh32(event->reason);
- BCM_REFERENCE(reason);
- auth_type = ntoh32(event->auth_type);
- datalen = ntoh32(event->datalen);
- /* debug dump of event messages */
- snprintf(eabuf, sizeof(eabuf), "%02x:%02x:%02x:%02x:%02x:%02x",
- (uchar)event->addr.octet[0]&0xff,
- (uchar)event->addr.octet[1]&0xff,
- (uchar)event->addr.octet[2]&0xff,
- (uchar)event->addr.octet[3]&0xff,
- (uchar)event->addr.octet[4]&0xff,
- (uchar)event->addr.octet[5]&0xff);
- event_name = "UNKNOWN";
- for (i = 0; i < (uint)bcmevent_names_size; i++)
- if (bcmevent_names[i].event == event_type)
- event_name = bcmevent_names[i].name;
- if (flags & WLC_EVENT_MSG_LINK)
- link = TRUE;
- if (flags & WLC_EVENT_MSG_GROUP)
- group = TRUE;
- if (flags & WLC_EVENT_MSG_FLUSHTXQ)
- flush_txq = TRUE;
- switch (event_type) {
- case WLC_E_START:
- case WLC_E_DEAUTH:
- case WLC_E_DISASSOC:
- DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
- break;
- case WLC_E_ASSOC_IND:
- case WLC_E_REASSOC_IND:
- DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
- break;
- case WLC_E_ASSOC:
- case WLC_E_REASSOC:
- if (status == WLC_E_STATUS_SUCCESS) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n", event_name, eabuf));
- } else if (status == WLC_E_STATUS_TIMEOUT) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n", event_name, eabuf));
- } else if (status == WLC_E_STATUS_FAIL) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
- event_name, eabuf, (int)reason));
- } else {
- DHD_EVENT(("MACEVENT: %s, MAC %s, unexpected status %d\n",
- event_name, eabuf, (int)status));
- }
- break;
- case WLC_E_DEAUTH_IND:
- case WLC_E_DISASSOC_IND:
- DHD_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name, eabuf, (int)reason));
- break;
- case WLC_E_AUTH:
- case WLC_E_AUTH_IND:
- if (auth_type == DOT11_OPEN_SYSTEM)
- auth_str = "Open System";
- else if (auth_type == DOT11_SHARED_KEY)
- auth_str = "Shared Key";
- else {
- snprintf(err_msg, sizeof(err_msg), "AUTH unknown: %d", (int)auth_type);
- auth_str = err_msg;
- }
- if (event_type == WLC_E_AUTH_IND) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name, eabuf, auth_str));
- } else if (status == WLC_E_STATUS_SUCCESS) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, %s, SUCCESS\n",
- event_name, eabuf, auth_str));
- } else if (status == WLC_E_STATUS_TIMEOUT) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
- event_name, eabuf, auth_str));
- } else if (status == WLC_E_STATUS_FAIL) {
- DHD_EVENT(("MACEVENT: %s, MAC %s, %s, FAILURE, reason %d\n",
- event_name, eabuf, auth_str, (int)reason));
- }
- BCM_REFERENCE(auth_str);
- break;
- case WLC_E_JOIN:
- case WLC_E_ROAM:
- case WLC_E_SET_SSID:
- if (status == WLC_E_STATUS_SUCCESS) {
- DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
- } else if (status == WLC_E_STATUS_FAIL) {
- DHD_EVENT(("MACEVENT: %s, failed\n", event_name));
- } else if (status == WLC_E_STATUS_NO_NETWORKS) {
- DHD_EVENT(("MACEVENT: %s, no networks found\n", event_name));
- } else {
- DHD_EVENT(("MACEVENT: %s, unexpected status %d\n",
- event_name, (int)status));
- }
- break;
- case WLC_E_BEACON_RX:
- if (status == WLC_E_STATUS_SUCCESS) {
- DHD_EVENT(("MACEVENT: %s, SUCCESS\n", event_name));
- } else if (status == WLC_E_STATUS_FAIL) {
- DHD_EVENT(("MACEVENT: %s, FAIL\n", event_name));
- } else {
- DHD_EVENT(("MACEVENT: %s, status %d\n", event_name, status));
- }
- break;
- case WLC_E_LINK:
- DHD_EVENT(("MACEVENT: %s %s\n", event_name, link?"UP":"DOWN"));
- BCM_REFERENCE(link);
- break;
- case WLC_E_MIC_ERROR:
- DHD_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
- event_name, eabuf, group, flush_txq));
- BCM_REFERENCE(group);
- BCM_REFERENCE(flush_txq);
- break;
- case WLC_E_ICV_ERROR:
- case WLC_E_UNICAST_DECODE_ERROR:
- case WLC_E_MULTICAST_DECODE_ERROR:
- DHD_EVENT(("MACEVENT: %s, MAC %s\n",
- event_name, eabuf));
- break;
- case WLC_E_TXFAIL:
- DHD_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf));
- break;
- case WLC_E_SCAN_COMPLETE:
- case WLC_E_ASSOC_REQ_IE:
- case WLC_E_ASSOC_RESP_IE:
- case WLC_E_PMKID_CACHE:
- DHD_EVENT(("MACEVENT: %s\n", event_name));
- break;
- case WLC_E_PFN_NET_FOUND:
- case WLC_E_PFN_NET_LOST:
- case WLC_E_PFN_SCAN_COMPLETE:
- case WLC_E_PFN_SCAN_NONE:
- case WLC_E_PFN_SCAN_ALLGONE:
- DHD_EVENT(("PNOEVENT: %s\n", event_name));
- break;
- case WLC_E_PSK_SUP:
- case WLC_E_PRUNE:
- DHD_EVENT(("MACEVENT: %s, status %d, reason %d\n",
- event_name, (int)status, (int)reason));
- break;
- #ifdef WIFI_ACT_FRAME
- case WLC_E_ACTION_FRAME:
- DHD_TRACE(("MACEVENT: %s Bssid %s\n", event_name, eabuf));
- break;
- #endif /* WIFI_ACT_FRAME */
- case WLC_E_TRACE: {
- static uint32 seqnum_prev = 0;
- static uint32 logtrace_seqnum_prev = 0;
- msgtrace_hdr_t hdr;
- uint32 nblost;
- char *s, *p;
- buf = (uchar *) event_data;
- memcpy(&hdr, buf, MSGTRACE_HDRLEN);
- if (hdr.version != MSGTRACE_VERSION) {
- printf("\nMACEVENT: %s [unsupported version --> "
- "dhd version:%d dongle version:%d]\n",
- event_name, MSGTRACE_VERSION, hdr.version);
- /* Reset datalen to avoid display below */
- datalen = 0;
- break;
- }
- if (hdr.trace_type == MSGTRACE_HDR_TYPE_MSG) {
- /* There are 2 bytes available at the end of data */
- buf[MSGTRACE_HDRLEN + ntoh16(hdr.len)] = '\0';
- if (ntoh32(hdr.discarded_bytes) || ntoh32(hdr.discarded_printf)) {
- printf("\nWLC_E_TRACE: [Discarded traces in dongle -->"
- "discarded_bytes %d discarded_printf %d]\n",
- ntoh32(hdr.discarded_bytes), ntoh32(hdr.discarded_printf));
- }
- nblost = ntoh32(hdr.seqnum) - seqnum_prev - 1;
- if (nblost > 0) {
- printf("\nWLC_E_TRACE: [Event lost (msg) --> seqnum %d nblost %d\n",
- ntoh32(hdr.seqnum), nblost);
- }
- seqnum_prev = ntoh32(hdr.seqnum);
- /* Display the trace buffer. Advance from \n to \n to avoid display big
- * printf (issue with Linux printk )
- */
- p = (char *)&buf[MSGTRACE_HDRLEN];
- while (*p != '\0' && (s = strstr(p, "\n")) != NULL) {
- *s = '\0';
- printf("WLC_E_TRACE: %s\n", p);
- p = s+1;
- }
- if (*p) printf("WLC_E_TRACE: %s", p);
- /* Reset datalen to avoid display below */
- datalen = 0;
- } else if (hdr.trace_type == MSGTRACE_HDR_TYPE_LOG) {
- /* Let the standard event printing work for now */
- uint32 timestamp, w;
- if (ntoh32(hdr.seqnum) == logtrace_seqnum_prev) {
- printf("\nWLC_E_TRACE: [Event duplicate (log) %d",
- logtrace_seqnum_prev);
- } else {
- nblost = ntoh32(hdr.seqnum) - logtrace_seqnum_prev - 1;
- if (nblost > 0) {
- printf("\nWLC_E_TRACE: [Event lost (log)"
- " --> seqnum %d nblost %d\n",
- ntoh32(hdr.seqnum), nblost);
- }
- logtrace_seqnum_prev = ntoh32(hdr.seqnum);
- p = (char *)&buf[MSGTRACE_HDRLEN];
- datalen -= MSGTRACE_HDRLEN;
- w = ntoh32((uint32) *p);
- p += 4;
- datalen -= 4;
- timestamp = ntoh32((uint32) *p);
- printf("Logtrace %x timestamp %x %x",
- logtrace_seqnum_prev, timestamp, w);
- while (datalen > 4) {
- p += 4;
- datalen -= 4;
- /* Print each word. DO NOT ntoh it. */
- printf(" %8.8x", *((uint32 *) p));
- }
- printf("\n");
- }
- datalen = 0;
- }
- break;
- }
- case WLC_E_RSSI:
- DHD_EVENT(("MACEVENT: %s %d\n", event_name, ntoh32(*((int *)event_data))));
- break;
- case WLC_E_SERVICE_FOUND:
- case WLC_E_P2PO_ADD_DEVICE:
- case WLC_E_P2PO_DEL_DEVICE:
- DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
- break;
- default:
- DHD_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, auth %d\n",
- event_name, event_type, eabuf, (int)status, (int)reason,
- (int)auth_type));
- break;
- }
- /* show any appended data */
- if (DHD_BYTES_ON() && DHD_EVENT_ON() && datalen) {
- buf = (uchar *) event_data;
- DHD_EVENT((" data (%d) : ", datalen));
- for (i = 0; i < datalen; i++)
- DHD_EVENT((" 0x%02x ", *buf++));
- DHD_EVENT(("\n"));
- }
- }
- #endif /* SHOW_EVENTS */
- int
- wl_host_event(dhd_pub_t *dhd_pub, int *ifidx, void *pktdata, size_t pktlen,
- wl_event_msg_t *event, void **data_ptr)
- {
- /* check whether packet is a BRCM event pkt */
- bcm_event_t *pvt_data = (bcm_event_t *)pktdata;
- uint8 *event_data;
- uint32 type, status, datalen;
- uint16 flags;
- uint evlen;
- if (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
- DHD_ERROR(("%s: mismatched OUI, bailing\n", __FUNCTION__));
- return (BCME_ERROR);
- }
- if (ntoh16_ua((void *)&pvt_data->bcm_hdr.subtype) != BCMILCP_SUBTYPE_VENDOR_LONG ||
- (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) ||
- ntoh16_ua((void *)&pvt_data->bcm_hdr.usr_subtype) != BCMILCP_BCM_SUBTYPE_EVENT)
- {
- DHD_ERROR(("%s: mismatched bcm_event_t info, bailing out\n", __FUNCTION__));
- return (BCME_ERROR);
- }
- if (pktlen < sizeof(bcm_event_t))
- return (BCME_ERROR);
- *data_ptr = &pvt_data[1];
- event_data = *data_ptr;
- /* memcpy since BRCM event pkt may be unaligned. */
- memcpy(event, &pvt_data->event, sizeof(wl_event_msg_t));
- type = ntoh32_ua((void *)&event->event_type);
- flags = ntoh16_ua((void *)&event->flags);
- status = ntoh32_ua((void *)&event->status);
- datalen = ntoh32_ua((void *)&event->datalen);
- if (datalen > pktlen)
- return (BCME_ERROR);
- evlen = datalen + sizeof(bcm_event_t);
- if (evlen > pktlen)
- return (BCME_ERROR);
- switch (type) {
- #ifdef PROP_TXSTATUS
- case WLC_E_FIFO_CREDIT_MAP:
- if (dhd_wlfc_enable(dhd_pub) != BCME_OK) {
- DHD_ERROR(("%s: dhd_wlfc_enable failed\n", __FUNCTION__));
- return (BCME_ERROR);
- }
- dhd_wlfc_FIFOcreditmap_event(dhd_pub, event_data);
- WLFC_DBGMESG(("WLC_E_FIFO_CREDIT_MAP:(AC0,AC1,AC2,AC3),(BC_MC),(OTHER): "
- "(%d,%d,%d,%d),(%d),(%d)\n", event_data[0], event_data[1],
- event_data[2],
- event_data[3], event_data[4], event_data[5]));
- break;
- case WLC_E_BCMC_CREDIT_SUPPORT:
- dhd_wlfc_BCMCCredit_support_event(dhd_pub);
- break;
- #endif /* PROP_TXSTATUS */
- case WLC_E_IF: {
- struct wl_event_data_if *ifevent = (struct wl_event_data_if *)event_data;
- /* Ignore the event if NOIF is set */
- if (ifevent->reserved & WLC_E_IF_FLAGS_BSSCFG_NOIF) {
- DHD_ERROR(("WLC_E_IF: NO_IF set, event Ignored\r\n"));
- return (BCME_UNSUPPORTED);
- }
- #ifdef PROP_TXSTATUS
- {
- uint8* ea = pvt_data->eth.ether_dhost;
- WLFC_DBGMESG(("WLC_E_IF: idx:%d, action:%s, iftype:%s, "
- "[%02x:%02x:%02x:%02x:%02x:%02x]\n",
- ifevent->ifidx,
- ((ifevent->opcode == WLC_E_IF_ADD) ? "ADD":"DEL"),
- ((ifevent->role == 0) ? "STA":"AP "),
- ea[0], ea[1], ea[2], ea[3], ea[4], ea[5]));
- (void)ea;
- if (ifevent->opcode == WLC_E_IF_CHANGE)
- dhd_wlfc_interface_event(dhd_pub,
- eWLFC_MAC_ENTRY_ACTION_UPDATE,
- ifevent->ifidx, ifevent->role, ea);
- else
- dhd_wlfc_interface_event(dhd_pub,
- ((ifevent->opcode == WLC_E_IF_ADD) ?
- eWLFC_MAC_ENTRY_ACTION_ADD : eWLFC_MAC_ENTRY_ACTION_DEL),
- ifevent->ifidx, ifevent->role, ea);
- /* dhd already has created an interface by default, for 0 */
- if (ifevent->ifidx == 0)
- break;
- }
- #endif /* PROP_TXSTATUS */
- if (ifevent->ifidx > 0 && ifevent->ifidx < DHD_MAX_IFS) {
- if (ifevent->opcode == WLC_E_IF_ADD) {
- if (dhd_event_ifadd(dhd_pub->info, ifevent, event->ifname,
- event->addr.octet)) {
- DHD_ERROR(("%s: dhd_event_ifadd failed ifidx: %d %s\n",
- __FUNCTION__, ifevent->ifidx, event->ifname));
- return (BCME_ERROR);
- }
- } else if (ifevent->opcode == WLC_E_IF_DEL) {
- dhd_event_ifdel(dhd_pub->info, ifevent, event->ifname,
- event->addr.octet);
- } else if (ifevent->opcode == WLC_E_IF_CHANGE) {
- #ifdef WL_CFG80211
- wl_cfg80211_notify_ifchange(ifevent->ifidx,
- event->ifname, event->addr.octet, ifevent->bssidx);
- #endif /* WL_CFG80211 */
- }
- } else {
- #ifndef PROP_TXSTATUS
- DHD_ERROR(("%s: Invalid ifidx %d for %s\n",
- __FUNCTION__, ifevent->ifidx, event->ifname));
- #endif /* !PROP_TXSTATUS */
- }
- /* send up the if event: btamp user needs it */
- *ifidx = dhd_ifname2idx(dhd_pub->info, event->ifname);
- /* push up to external supp/auth */
- dhd_event(dhd_pub->info, (char *)pvt_data, evlen, *ifidx);
- break;
- }
- #ifdef WLMEDIA_HTSF
- case WLC_E_HTSFSYNC:
- htsf_update(dhd_pub->info, event_data);
- break;
- #endif /* WLMEDIA_HTSF */
- case WLC_E_NDIS_LINK: {
- uint32 temp = hton32(WLC_E_LINK);
- memcpy((void *)(&pvt_data->event.event_type), &temp,
- sizeof(pvt_data->event.event_type));
- }
- case WLC_E_PFN_NET_FOUND:
- case WLC_E_PFN_NET_LOST:
- break;
- #if defined(PNO_SUPPORT)
- case WLC_E_PFN_BSSID_NET_FOUND:
- case WLC_E_PFN_BSSID_NET_LOST:
- case WLC_E_PFN_BEST_BATCHING:
- dhd_pno_event_handler(dhd_pub, event, (void *)event_data);
- break;
- #endif
- /* These are what external supplicant/authenticator wants */
- /* fall through */
- case WLC_E_LINK:
- case WLC_E_DEAUTH:
- case WLC_E_DEAUTH_IND:
- case WLC_E_DISASSOC:
- case WLC_E_DISASSOC_IND:
- DHD_EVENT(("%s: Link event %d, flags %x, status %x\n",
- __FUNCTION__, type, flags, status));
- /* fall through */
- default:
- *ifidx = dhd_ifname2idx(dhd_pub->info, event->ifname);
- /* push up to external supp/auth */
- dhd_event(dhd_pub->info, (char *)pvt_data, evlen, *ifidx);
- DHD_TRACE(("%s: MAC event %d, flags %x, status %x\n",
- __FUNCTION__, type, flags, status));
- BCM_REFERENCE(flags);
- BCM_REFERENCE(status);
- break;
- }
- #ifdef SHOW_EVENTS
- wl_show_host_event(event, (void *)event_data);
- #endif /* SHOW_EVENTS */
- return (BCME_OK);
- }
- void
- wl_event_to_host_order(wl_event_msg_t * evt)
- {
- /* Event struct members passed from dongle to host are stored in network
- * byte order. Convert all members to host-order.
- */
- evt->event_type = ntoh32(evt->event_type);
- evt->flags = ntoh16(evt->flags);
- evt->status = ntoh32(evt->status);
- evt->reason = ntoh32(evt->reason);
- evt->auth_type = ntoh32(evt->auth_type);
- evt->datalen = ntoh32(evt->datalen);
- evt->version = ntoh16(evt->version);
- }
- void
- dhd_print_buf(void *pbuf, int len, int bytes_per_line)
- {
- #ifdef DHD_DEBUG
- int i, j = 0;
- unsigned char *buf = pbuf;
- if (bytes_per_line == 0) {
- bytes_per_line = len;
- }
- for (i = 0; i < len; i++) {
- printf("%2.2x", *buf++);
- j++;
- if (j == bytes_per_line) {
- printf("\n");
- j = 0;
- } else {
- printf(":");
- }
- }
- printf("\n");
- #endif /* DHD_DEBUG */
- }
- #ifndef strtoul
- #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
- #endif
- #ifdef PKT_FILTER_SUPPORT
- /* Convert user's input in hex pattern to byte-size mask */
- static int
- wl_pattern_atoh(char *src, char *dst)
- {
- int i;
- if (strncmp(src, "0x", 2) != 0 &&
- strncmp(src, "0X", 2) != 0) {
- DHD_ERROR(("Mask invalid format. Needs to start with 0x\n"));
- return -1;
- }
- src = src + 2; /* Skip past 0x */
- if (strlen(src) % 2 != 0) {
- DHD_ERROR(("Mask invalid format. Needs to be of even length\n"));
- return -1;
- }
- for (i = 0; *src != '\0'; i++) {
- char num[3];
- bcm_strncpy_s(num, sizeof(num), src, 2);
- num[2] = '\0';
- dst[i] = (uint8)strtoul(num, NULL, 16);
- src += 2;
- }
- return i;
- }
- void
- dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode)
- {
- char *argv[8];
- int i = 0;
- const char *str;
- int buf_len;
- int str_len;
- char *arg_save = 0, *arg_org = 0;
- int rc;
- char buf[128];
- wl_pkt_filter_enable_t enable_parm;
- wl_pkt_filter_enable_t * pkt_filterp;
- if (!arg)
- return;
- if (!(arg_save = MALLOC(dhd->osh, strlen(arg) + 1))) {
- DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
- goto fail;
- }
- arg_org = arg_save;
- memcpy(arg_save, arg, strlen(arg) + 1);
- argv[i] = bcmstrtok(&arg_save, " ", 0);
- i = 0;
- if (argv[i] == NULL) {
- DHD_ERROR(("No args provided\n"));
- goto fail;
- }
- str = "pkt_filter_enable";
- str_len = strlen(str);
- bcm_strncpy_s(buf, sizeof(buf), str, str_len);
- buf[str_len] = '\0';
- buf_len = str_len + 1;
- pkt_filterp = (wl_pkt_filter_enable_t *)(buf + str_len + 1);
- /* Parse packet filter id. */
- enable_parm.id = htod32(strtoul(argv[i], NULL, 0));
- /* Parse enable/disable value. */
- enable_parm.enable = htod32(enable);
- buf_len += sizeof(enable_parm);
- memcpy((char *)pkt_filterp,
- &enable_parm,
- sizeof(enable_parm));
- /* Enable/disable the specified filter. */
- rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, buf_len, TRUE, 0);
- rc = rc >= 0 ? 0 : rc;
- if (rc)
- DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
- __FUNCTION__, arg, rc));
- else
- DHD_TRACE(("%s: successfully added pktfilter %s\n",
- __FUNCTION__, arg));
- /* Contorl the master mode */
- bcm_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf, sizeof(buf));
- rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
- rc = rc >= 0 ? 0 : rc;
- if (rc)
- DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
- __FUNCTION__, arg, rc));
- fail:
- if (arg_org)
- MFREE(dhd->osh, arg_org, strlen(arg) + 1);
- }
- void
- dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg)
- {
- const char *str;
- wl_pkt_filter_t pkt_filter;
- wl_pkt_filter_t *pkt_filterp;
- int buf_len;
- int str_len;
- int rc;
- uint32 mask_size;
- uint32 pattern_size;
- char *argv[8], * buf = 0;
- int i = 0;
- char *arg_save = 0, *arg_org = 0;
- #define BUF_SIZE 2048
- if (!arg)
- return;
- if (!(arg_save = MALLOC(dhd->osh, strlen(arg) + 1))) {
- DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
- goto fail;
- }
- arg_org = arg_save;
- if (!(buf = MALLOC(dhd->osh, BUF_SIZE))) {
- DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
- goto fail;
- }
- memcpy(arg_save, arg, strlen(arg) + 1);
- if (strlen(arg) > BUF_SIZE) {
- DHD_ERROR(("Not enough buffer %d < %d\n", (int)strlen(arg), (int)sizeof(buf)));
- goto fail;
- }
- argv[i] = bcmstrtok(&arg_save, " ", 0);
- while (argv[i++])
- argv[i] = bcmstrtok(&arg_save, " ", 0);
- i = 0;
- if (argv[i] == NULL) {
- DHD_ERROR(("No args provided\n"));
- goto fail;
- }
- str = "pkt_filter_add";
- str_len = strlen(str);
- bcm_strncpy_s(buf, BUF_SIZE, str, str_len);
- buf[ str_len ] = '\0';
- buf_len = str_len + 1;
- pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1);
- /* Parse packet filter id. */
- pkt_filter.id = htod32(strtoul(argv[i], NULL, 0));
- if (argv[++i] == NULL) {
- DHD_ERROR(("Polarity not provided\n"));
- goto fail;
- }
- /* Parse filter polarity. */
- pkt_filter.negate_match = htod32(strtoul(argv[i], NULL, 0));
- if (argv[++i] == NULL) {
- DHD_ERROR(("Filter type not provided\n"));
- goto fail;
- }
- /* Parse filter type. */
- pkt_filter.type = htod32(strtoul(argv[i], NULL, 0));
- if (argv[++i] == NULL) {
- DHD_ERROR(("Offset not provided\n"));
- goto fail;
- }
- /* Parse pattern filter offset. */
- pkt_filter.u.pattern.offset = htod32(strtoul(argv[i], NULL, 0));
- if (argv[++i] == NULL) {
- DHD_ERROR(("Bitmask not provided\n"));
- goto fail;
- }
- /* Parse pattern filter mask. */
- mask_size =
- htod32(wl_pattern_atoh(argv[i], (char *) pkt_filterp->u.pattern.mask_and_pattern));
- if (argv[++i] == NULL) {
- DHD_ERROR(("Pattern not provided\n"));
- goto fail;
- }
- /* Parse pattern filter pattern. */
- pattern_size =
- htod32(wl_pattern_atoh(argv[i],
- (char *) &pkt_filterp->u.pattern.mask_and_pattern[mask_size]));
- if (mask_size != pattern_size) {
- DHD_ERROR(("Mask and pattern not the same size\n"));
- goto fail;
- }
- pkt_filter.u.pattern.size_bytes = mask_size;
- buf_len += WL_PKT_FILTER_FIXED_LEN;
- buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
- /* Keep-alive attributes are set in local variable (keep_alive_pkt), and
- ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
- ** guarantee that the buffer is properly aligned.
- */
- memcpy((char *)pkt_filterp,
- &pkt_filter,
- WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
- rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, buf_len, TRUE, 0);
- rc = rc >= 0 ? 0 : rc;
- if (rc)
- DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
- __FUNCTION__, arg, rc));
- else
- DHD_TRACE(("%s: successfully added pktfilter %s\n",
- __FUNCTION__, arg));
- fail:
- if (arg_org)
- MFREE(dhd->osh, arg_org, strlen(arg) + 1);
- if (buf)
- MFREE(dhd->osh, buf, BUF_SIZE);
- }
- void dhd_pktfilter_offload_delete(dhd_pub_t *dhd, int id)
- {
- char iovbuf[32];
- int ret;
- bcm_mkiovar("pkt_filter_delete", (char *)&id, 4, iovbuf, sizeof(iovbuf));
- ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
- if (ret < 0) {
- DHD_ERROR(("%s: Failed to delete filter ID:%d, ret=%d\n",
- __FUNCTION__, id, ret));
- }
- }
- #endif /* PKT_FILTER_SUPPORT */
- /* ========================== */
- /* ==== ARP OFFLOAD SUPPORT = */
- /* ========================== */
- #ifdef ARP_OFFLOAD_SUPPORT
- void
- dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode)
- {
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- int iovar_len;
- int retcode;
- iovar_len = bcm_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
- if (!iovar_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return;
- }
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iovar_len, TRUE, 0);
- retcode = retcode >= 0 ? 0 : retcode;
- if (retcode)
- DHD_TRACE(("%s: failed to set ARP offload mode to 0x%x, retcode = %d\n",
- __FUNCTION__, arp_mode, retcode));
- else
- DHD_TRACE(("%s: successfully set ARP offload mode to 0x%x\n",
- __FUNCTION__, arp_mode));
- }
- void
- dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable)
- {
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- int iovar_len;
- int retcode;
- iovar_len = bcm_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf));
- if (!iovar_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return;
- }
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iovar_len, TRUE, 0);
- retcode = retcode >= 0 ? 0 : retcode;
- if (retcode)
- DHD_TRACE(("%s: failed to enabe ARP offload to %d, retcode = %d\n",
- __FUNCTION__, arp_enable, retcode));
- else
- DHD_TRACE(("%s: successfully enabed ARP offload to %d\n",
- __FUNCTION__, arp_enable));
- if (arp_enable) {
- uint32 version;
- bcm_mkiovar("arp_version", 0, 0, iovbuf, sizeof(iovbuf));
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0);
- if (retcode) {
- DHD_INFO(("%s: fail to get version (maybe version 1:retcode = %d\n",
- __FUNCTION__, retcode));
- dhd->arp_version = 1;
- }
- else {
- memcpy(&version, iovbuf, sizeof(version));
- DHD_INFO(("%s: ARP Version= %x\n", __FUNCTION__, version));
- dhd->arp_version = version;
- }
- }
- }
- void
- dhd_aoe_arp_clr(dhd_pub_t *dhd, int idx)
- {
- int ret = 0;
- int iov_len = 0;
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- if (dhd == NULL) return;
- if (dhd->arp_version == 1)
- idx = 0;
- iov_len = bcm_mkiovar("arp_table_clear", 0, 0, iovbuf, sizeof(iovbuf));
- if (!iov_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return;
- }
- if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx)) < 0)
- DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret));
- }
- void
- dhd_aoe_hostip_clr(dhd_pub_t *dhd, int idx)
- {
- int ret = 0;
- int iov_len = 0;
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- if (dhd == NULL) return;
- if (dhd->arp_version == 1)
- idx = 0;
- iov_len = bcm_mkiovar("arp_hostip_clear", 0, 0, iovbuf, sizeof(iovbuf));
- if (!iov_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return;
- }
- if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx)) < 0)
- DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret));
- }
- void
- dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr, int idx)
- {
- int iov_len = 0;
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- int retcode;
- if (dhd == NULL) return;
- if (dhd->arp_version == 1)
- idx = 0;
- iov_len = bcm_mkiovar("arp_hostip", (char *)&ipaddr,
- sizeof(ipaddr), iovbuf, sizeof(iovbuf));
- if (!iov_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return;
- }
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx);
- if (retcode)
- DHD_TRACE(("%s: ARP ip addr add failed, retcode = %d\n",
- __FUNCTION__, retcode));
- else
- DHD_TRACE(("%s: sARP H ipaddr entry added \n",
- __FUNCTION__));
- }
- int
- dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen, int idx)
- {
- int retcode, i;
- int iov_len;
- uint32 *ptr32 = buf;
- bool clr_bottom = FALSE;
- if (!buf)
- return -1;
- if (dhd == NULL) return -1;
- if (dhd->arp_version == 1)
- idx = 0;
- iov_len = bcm_mkiovar("arp_hostip", 0, 0, buf, buflen);
- BCM_REFERENCE(iov_len);
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, buflen, FALSE, idx);
- if (retcode) {
- DHD_TRACE(("%s: ioctl WLC_GET_VAR error %d\n",
- __FUNCTION__, retcode));
- return -1;
- }
- /* clean up the buf, ascii reminder */
- for (i = 0; i < MAX_IPV4_ENTRIES; i++) {
- if (!clr_bottom) {
- if (*ptr32 == 0)
- clr_bottom = TRUE;
- } else {
- *ptr32 = 0;
- }
- ptr32++;
- }
- return 0;
- }
- #endif /* ARP_OFFLOAD_SUPPORT */
- /*
- * Neighbor Discovery Offload: enable NDO feature
- * Called by ipv6 event handler when interface comes up/goes down
- */
- int
- dhd_ndo_enable(dhd_pub_t * dhd, int ndo_enable)
- {
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- int iov_len;
- int retcode;
- if (dhd == NULL)
- return -1;
- iov_len = bcm_mkiovar("ndoe", (char *)&ndo_enable, 4, iovbuf, sizeof(iovbuf));
- if (!iov_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return -1;
- }
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, 0);
- if (retcode)
- DHD_ERROR(("%s: failed to enabe ndo to %d, retcode = %d\n",
- __FUNCTION__, ndo_enable, retcode));
- else
- DHD_TRACE(("%s: successfully enabed ndo offload to %d\n",
- __FUNCTION__, ndo_enable));
- return retcode;
- }
- /*
- * Neighbor Discover Offload: enable NDO feature
- * Called by ipv6 event handler when interface comes up
- */
- int
- dhd_ndo_add_ip(dhd_pub_t *dhd, char* ipv6addr, int idx)
- {
- int iov_len = 0;
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- int retcode;
- if (dhd == NULL)
- return -1;
- iov_len = bcm_mkiovar("nd_hostip", (char *)ipv6addr,
- IPV6_ADDR_LEN, iovbuf, sizeof(iovbuf));
- if (!iov_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return -1;
- }
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx);
- if (retcode)
- DHD_ERROR(("%s: ndo ip addr add failed, retcode = %d\n",
- __FUNCTION__, retcode));
- else
- DHD_TRACE(("%s: ndo ipaddr entry added \n",
- __FUNCTION__));
- return retcode;
- }
- /*
- * Neighbor Discover Offload: enable NDO feature
- * Called by ipv6 event handler when interface goes down
- */
- int
- dhd_ndo_remove_ip(dhd_pub_t *dhd, int idx)
- {
- int iov_len = 0;
- char iovbuf[DHD_IOVAR_BUF_SIZE];
- int retcode;
- if (dhd == NULL)
- return -1;
- iov_len = bcm_mkiovar("nd_hostip_clear", NULL,
- 0, iovbuf, sizeof(iovbuf));
- if (!iov_len) {
- DHD_ERROR(("%s: Insufficient iovar buffer size %zu \n",
- __FUNCTION__, sizeof(iovbuf)));
- return -1;
- }
- retcode = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, iov_len, TRUE, idx);
- if (retcode) {
- DHD_ERROR(("%s: ndo ip addr remove returned (%d)\n",
- __FUNCTION__, retcode));
- } else {
- DHD_TRACE(("%s: ndo ipaddr entry removed \n",
- __FUNCTION__));
- }
- return retcode;
- }
- /* send up locally generated event */
- void
- dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
- {
- switch (ntoh32(event->event_type)) {
- #ifdef WLBTAMP
- case WLC_E_BTA_HCI_EVENT:
- break;
- #endif /* WLBTAMP */
- default:
- break;
- }
- /* Call per-port handler. */
- dhd_sendup_event(dhdp, event, data);
- }
- #ifdef SIMPLE_ISCAN
- uint iscan_thread_id = 0;
- iscan_buf_t * iscan_chain = 0;
- iscan_buf_t *
- dhd_iscan_allocate_buf(dhd_pub_t *dhd, iscan_buf_t **iscanbuf)
- {
- iscan_buf_t *iscanbuf_alloc = 0;
- iscan_buf_t *iscanbuf_head;
- DHD_ISCAN(("%s: Entered\n", __FUNCTION__));
- dhd_iscan_lock();
- iscanbuf_alloc = (iscan_buf_t*)MALLOC(dhd->osh, sizeof(iscan_buf_t));
- if (iscanbuf_alloc == NULL)
- goto fail;
- iscanbuf_alloc->next = NULL;
- iscanbuf_head = *iscanbuf;
- DHD_ISCAN(("%s: addr of allocated node = 0x%X"
- "addr of iscanbuf_head = 0x%X dhd = 0x%X\n",
- __FUNCTION__, iscanbuf_alloc, iscanbuf_head, dhd));
- if (iscanbuf_head == NULL) {
- *iscanbuf = iscanbuf_alloc;
- DHD_ISCAN(("%s: Head is allocated\n", __FUNCTION__));
- goto fail;
- }
- while (iscanbuf_head->next)
- iscanbuf_head = iscanbuf_head->next;
- iscanbuf_head->next = iscanbuf_alloc;
- fail:
- dhd_iscan_unlock();
- return iscanbuf_alloc;
- }
- void
- dhd_iscan_free_buf(void *dhdp, iscan_buf_t *iscan_delete)
- {
- iscan_buf_t *iscanbuf_free = 0;
- iscan_buf_t *iscanbuf_prv = 0;
- iscan_buf_t *iscanbuf_cur;
- dhd_pub_t *dhd = dhd_bus_pub(dhdp);
- DHD_ISCAN(("%s: Entered\n", __FUNCTION__));
- dhd_iscan_lock();
- iscanbuf_cur = iscan_chain;
- /* If iscan_delete is null then delete the entire
- * chain or else delete specific one provided
- */
- if (!iscan_delete) {
- while (iscanbuf_cur) {
- iscanbuf_free = iscanbuf_cur;
- iscanbuf_cur = iscanbuf_cur->next;
- iscanbuf_free->next = 0;
- MFREE(dhd->osh, iscanbuf_free, sizeof(iscan_buf_t));
- }
- iscan_chain = 0;
- } else {
- while (iscanbuf_cur) {
- if (iscanbuf_cur == iscan_delete)
- break;
- iscanbuf_prv = iscanbuf_cur;
- iscanbuf_cur = iscanbuf_cur->next;
- }
- if (iscanbuf_prv)
- iscanbuf_prv->next = iscan_delete->next;
- iscan_delete->next = 0;
- MFREE(dhd->osh, iscan_delete, sizeof(iscan_buf_t));
- if (!iscanbuf_prv)
- iscan_chain = 0;
- }
- dhd_iscan_unlock();
- }
- iscan_buf_t *
- dhd_iscan_result_buf(void)
- {
- return iscan_chain;
- }
- int
- dhd_iscan_issue_request(void * dhdp, wl_iscan_params_t *pParams, uint32 size)
- {
- int rc = -1;
- dhd_pub_t *dhd = dhd_bus_pub(dhdp);
- char *buf;
- char iovar[] = "iscan";
- uint32 allocSize = 0;
- wl_ioctl_t ioctl;
- if (pParams) {
- allocSize = (size + strlen(iovar) + 1);
- if ((allocSize < size) || (allocSize < strlen(iovar)))
- {
- DHD_ERROR(("%s: overflow - allocation size too large %d < %d + %d!\n",
- __FUNCTION__, allocSize, size, strlen(iovar)));
- goto cleanUp;
- }
- buf = MALLOC(dhd->osh, allocSize);
- if (buf == NULL)
- {
- DHD_ERROR(("%s: malloc of size %d failed!\n", __FUNCTION__, allocSize));
- goto cleanUp;
- }
- ioctl.cmd = WLC_SET_VAR;
- bcm_mkiovar(iovar, (char *)pParams, size, buf, allocSize);
- rc = dhd_wl_ioctl(dhd, 0, &ioctl, buf, allocSize);
- }
- cleanUp:
- if (buf) {
- MFREE(dhd->osh, buf, allocSize);
- }
- return rc;
- }
- static int
- dhd_iscan_get_partial_result(void *dhdp, uint *scan_count)
- {
- wl_iscan_results_t *list_buf;
- wl_iscan_results_t list;
- wl_scan_results_t *results;
- iscan_buf_t *iscan_cur;
- int status = -1;
- dhd_pub_t *dhd = dhd_bus_pub(dhdp);
- int rc;
- wl_ioctl_t ioctl;
- DHD_ISCAN(("%s: Enter\n", __FUNCTION__));
- iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain);
- if (!iscan_cur) {
- DHD_ERROR(("%s: Failed to allocate node\n", __FUNCTION__));
- dhd_iscan_free_buf(dhdp, 0);
- dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT);
- dhd_ind_scan_confirm(dhdp, FALSE);
- goto fail;
- }
- dhd_iscan_lock();
- memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
- list_buf = (wl_iscan_results_t*)iscan_cur->iscan_buf;
- results = &list_buf->results;
- results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
- results->version = 0;
- results->count = 0;
- memset(&list, 0, sizeof(list));
- list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
- bcm_mkiovar("iscanresults", (char *)&list, WL_ISCAN_RESULTS_FIXED_SIZE,
- iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
- ioctl.cmd = WLC_GET_VAR;
- ioctl.set = FALSE;
- rc = dhd_wl_ioctl(dhd, 0, &ioctl, iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
- results->buflen = dtoh32(results->buflen);
- results->version = dtoh32(results->version);
- *scan_count = results->count = dtoh32(results->count);
- status = dtoh32(list_buf->status);
- DHD_ISCAN(("%s: Got %d resuls status = (%x)\n", __FUNCTION__, results->count, status));
- dhd_iscan_unlock();
- if (!(*scan_count)) {
- /* TODO: race condition when FLUSH already called */
- dhd_iscan_free_buf(dhdp, 0);
- }
- fail:
- return status;
- }
- #endif /* SIMPLE_ISCAN */
- /*
- * returns = TRUE if associated, FALSE if not associated
- */
- bool dhd_is_associated(dhd_pub_t *dhd, void *bss_buf, int *retval)
- {
- char bssid[6], zbuf[6];
- int ret = -1;
- bzero(bssid, 6);
- bzero(zbuf, 6);
- ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_BSSID, (char *)&bssid, ETHER_ADDR_LEN, FALSE, 0);
- DHD_TRACE((" %s WLC_GET_BSSID ioctl res = %d\n", __FUNCTION__, ret));
- if (ret == BCME_NOTASSOCIATED) {
- DHD_TRACE(("%s: not associated! res:%d\n", __FUNCTION__, ret));
- }
- if (retval)
- *retval = ret;
- if (ret < 0)
- return FALSE;
- if ((memcmp(bssid, zbuf, ETHER_ADDR_LEN) != 0)) {
- /* STA is assocoated BSSID is non zero */
- if (bss_buf) {
- /* return bss if caller provided buf */
- memcpy(bss_buf, bssid, ETHER_ADDR_LEN);
- }
- return TRUE;
- } else {
- DHD_TRACE(("%s: WLC_GET_BSSID ioctl returned zero bssid\n", __FUNCTION__));
- return FALSE;
- }
- }
- /* Function to estimate possible DTIM_SKIP value */
- int
- dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd)
- {
- int bcn_li_dtim = 1; /* deafult no dtim skip setting */
- int ret = -1;
- int dtim_period = 0;
- int ap_beacon = 0;
- #ifndef ENABLE_MAX_DTIM_IN_SUSPEND
- int allowed_skip_dtim_cnt = 0;
- #endif /* !ENABLE_MAX_DTIM_IN_SUSPEND */
- /* Check if associated */
- if (dhd_is_associated(dhd, NULL, NULL) == FALSE) {
- DHD_TRACE(("%s NOT assoc ret %d\n", __FUNCTION__, ret));
- goto exit;
- }
- /* read associated AP beacon interval */
- if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_BCNPRD,
- &ap_beacon, sizeof(ap_beacon), FALSE, 0)) < 0) {
- DHD_ERROR(("%s get beacon failed code %d\n", __FUNCTION__, ret));
- goto exit;
- }
- /* read associated ap's dtim setup */
- if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_DTIMPRD,
- &dtim_period, sizeof(dtim_period), FALSE, 0)) < 0) {
- DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret));
- goto exit;
- }
- /* if not assocated just eixt */
- if (dtim_period == 0) {
- goto exit;
- }
- #ifdef ENABLE_MAX_DTIM_IN_SUSPEND
- bcn_li_dtim = (int) (MAX_DTIM_ALLOWED_INTERVAL / (ap_beacon * dtim_period));
- if (bcn_li_dtim == 0) {
- bcn_li_dtim = 1;
- }
- #else /* ENABLE_MAX_DTIM_IN_SUSPEND */
- /* attemp to use platform defined dtim skip interval */
- bcn_li_dtim = dhd->suspend_bcn_li_dtim;
- /* check if sta listen interval fits into AP dtim */
- if (dtim_period > CUSTOM_LISTEN_INTERVAL) {
- /* AP DTIM to big for our Listen Interval : no dtim skiping */
- bcn_li_dtim = NO_DTIM_SKIP;
- DHD_ERROR(("%s DTIM=%d > Listen=%d : too big ...\n",
- __FUNCTION__, dtim_period, CUSTOM_LISTEN_INTERVAL));
- goto exit;
- }
- if ((dtim_period * ap_beacon * bcn_li_dtim) > MAX_DTIM_ALLOWED_INTERVAL) {
- allowed_skip_dtim_cnt = MAX_DTIM_ALLOWED_INTERVAL / (dtim_period * ap_beacon);
- bcn_li_dtim = (allowed_skip_dtim_cnt != 0) ? allowed_skip_dtim_cnt : NO_DTIM_SKIP;
- }
- if ((bcn_li_dtim * dtim_period) > CUSTOM_LISTEN_INTERVAL) {
- /* Round up dtim_skip to fit into STAs Listen Interval */
- bcn_li_dtim = (int)(CUSTOM_LISTEN_INTERVAL / dtim_period);
- DHD_TRACE(("%s agjust dtim_skip as %d\n", __FUNCTION__, bcn_li_dtim));
- }
- #endif /* ENABLE_MAX_DTIM_IN_SUSPEND */
- DHD_ERROR(("%s beacon=%d bcn_li_dtim=%d DTIM=%d Listen=%d\n",
- __FUNCTION__, ap_beacon, bcn_li_dtim, dtim_period, CUSTOM_LISTEN_INTERVAL));
- exit:
- return bcn_li_dtim;
- }
- /* Check if the mode supports STA MODE */
- bool dhd_support_sta_mode(dhd_pub_t *dhd)
- {
- #ifdef WL_CFG80211
- if (!(dhd->op_mode & DHD_FLAG_STA_MODE))
- return FALSE;
- else
- #endif /* WL_CFG80211 */
- return TRUE;
- }
- #if defined(KEEP_ALIVE)
- int dhd_keep_alive_onoff(dhd_pub_t *dhd)
- {
- char buf[256];
- const char *str;
- wl_mkeep_alive_pkt_t mkeep_alive_pkt = {0};
- wl_mkeep_alive_pkt_t *mkeep_alive_pktp;
- int buf_len;
- int str_len;
- int res = -1;
- if (!dhd_support_sta_mode(dhd))
- return res;
- DHD_TRACE(("%s execution\n", __FUNCTION__));
- str = "mkeep_alive";
- str_len = strlen(str);
- strncpy(buf, str, str_len);
- buf[ str_len ] = '\0';
- mkeep_alive_pktp = (wl_mkeep_alive_pkt_t *) (buf + str_len + 1);
- mkeep_alive_pkt.period_msec = CUSTOM_KEEP_ALIVE_SETTING;
- buf_len = str_len + 1;
- mkeep_alive_pkt.version = htod16(WL_MKEEP_ALIVE_VERSION);
- mkeep_alive_pkt.length = htod16(WL_MKEEP_ALIVE_FIXED_LEN);
- /* Setup keep alive zero for null packet generation */
- mkeep_alive_pkt.keep_alive_id = 0;
- mkeep_alive_pkt.len_bytes = 0;
- buf_len += WL_MKEEP_ALIVE_FIXED_LEN;
- bzero(mkeep_alive_pkt.data, sizeof(mkeep_alive_pkt.data));
- /* Keep-alive attributes are set in local variable (mkeep_alive_pkt), and
- * then memcpy'ed into buffer (mkeep_alive_pktp) since there is no
- * guarantee that the buffer is properly aligned.
- */
- memcpy((char *)mkeep_alive_pktp, &mkeep_alive_pkt, WL_MKEEP_ALIVE_FIXED_LEN);
- res = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, buf_len, TRUE, 0);
- return res;
- }
- #endif /* defined(KEEP_ALIVE) */
- /* Android ComboSCAN support */
- /*
- * data parsing from ComboScan tlv list
- */
- int
- wl_iw_parse_data_tlv(char** list_str, void *dst, int dst_size, const char token,
- int input_size, int *bytes_left)
- {
- char* str;
- uint16 short_temp;
- uint32 int_temp;
- if ((list_str == NULL) || (*list_str == NULL) ||(bytes_left == NULL) || (*bytes_left < 0)) {
- DHD_ERROR(("%s error paramters\n", __FUNCTION__));
- return -1;
- }
- str = *list_str;
- /* Clean all dest bytes */
- memset(dst, 0, dst_size);
- while (*bytes_left > 0) {
- if (str[0] != token) {
- DHD_TRACE(("%s NOT Type=%d get=%d left_parse=%d \n",
- __FUNCTION__, token, str[0], *bytes_left));
- return -1;
- }
- *bytes_left -= 1;
- str += 1;
- if (input_size == 1) {
- memcpy(dst, str, input_size);
- }
- else if (input_size == 2) {
- memcpy(dst, (char *)htod16(memcpy(&short_temp, str, input_size)),
- input_size);
- }
- else if (input_size == 4) {
- memcpy(dst, (char *)htod32(memcpy(&int_temp, str, input_size)),
- input_size);
- }
- *bytes_left -= input_size;
- str += input_size;
- *list_str = str;
- return 1;
- }
- return 1;
- }
- #define CSCAN_TLV_TYPE_SSID_IE 'S'
- /*
- * SSIDs list parsing from cscan tlv list
- */
- int
- wl_iw_parse_ssid_list_tlv(char** list_str, wlc_ssid_t* ssid, int max, int *bytes_left)
- {
- char* str;
- int idx = 0;
- if ((list_str == NULL) || (*list_str == NULL) || (*bytes_left < 0)) {
- DHD_ERROR(("%s error paramters\n", __FUNCTION__));
- return -1;
- }
- str = *list_str;
- while (*bytes_left > 0) {
- if (str[0] != CSCAN_TLV_TYPE_SSID_IE) {
- *list_str = str;
- DHD_TRACE(("nssid=%d left_parse=%d %d\n", idx, *bytes_left, str[0]));
- return idx;
- }
- /* Get proper CSCAN_TLV_TYPE_SSID_IE */
- *bytes_left -= 1;
- str += 1;
- if (str[0] == 0) {
- /* Broadcast SSID */
- ssid[idx].SSID_len = 0;
- memset((char*)ssid[idx].SSID, 0x0, DOT11_MAX_SSID_LEN);
- *bytes_left -= 1;
- str += 1;
- DHD_TRACE(("BROADCAST SCAN left=%d\n", *bytes_left));
- }
- else if (str[0] <= DOT11_MAX_SSID_LEN) {
- /* Get proper SSID size */
- ssid[idx].SSID_len = str[0];
- *bytes_left -= 1;
- str += 1;
- /* Get SSID */
- if (ssid[idx].SSID_len > *bytes_left) {
- DHD_ERROR(("%s out of memory range len=%d but left=%d\n",
- __FUNCTION__, ssid[idx].SSID_len, *bytes_left));
- return -1;
- }
- memcpy((char*)ssid[idx].SSID, str, ssid[idx].SSID_len);
- *bytes_left -= ssid[idx].SSID_len;
- str += ssid[idx].SSID_len;
- DHD_TRACE(("%s :size=%d left=%d\n",
- (char*)ssid[idx].SSID, ssid[idx].SSID_len, *bytes_left));
- }
- else {
- DHD_ERROR(("### SSID size more that %d\n", str[0]));
- return -1;
- }
- if (idx++ > max) {
- DHD_ERROR(("%s number of SSIDs more that %d\n", __FUNCTION__, idx));
- return -1;
- }
- }
- *list_str = str;
- return idx;
- }
- #if defined(DHD_8021X_DUMP)
- /* Parse EAPOL 4 way handshake messages */
- void
- dhd_dump_eapol_4way_message(char *dump_data, bool direction)
- {
- unsigned char type;
- int pair, ack, mic, kerr, req, sec, install;
- unsigned short us_tmp;
- type = dump_data[18];
- if (type == 2 || type == 254) {
- us_tmp = (dump_data[19] << 8) | dump_data[20];
- pair = 0 != (us_tmp & 0x08);
- ack = 0 != (us_tmp & 0x80);
- mic = 0 != (us_tmp & 0x100);
- kerr = 0 != (us_tmp & 0x400);
- req = 0 != (us_tmp & 0x800);
- sec = 0 != (us_tmp & 0x200);
- install = 0 != (us_tmp & 0x40);
- if (!sec && !mic && ack && !install && pair && !kerr && !req) {
- DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M1 of 4way\n",
- direction ? "TX" : "RX"));
- } else if (pair && !install && !ack && mic && !sec && !kerr && !req) {
- DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M2 of 4way\n",
- direction ? "TX" : "RX"));
- } else if (pair && ack && mic && sec && !kerr && !req) {
- DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M3 of 4way\n",
- direction ? "TX" : "RX"));
- } else if (pair && !install && !ack && mic && sec && !req && !kerr) {
- DHD_ERROR(("ETHER_TYPE_802_1X [%s] : M4 of 4way\n",
- direction ? "TX" : "RX"));
- } else {
- DHD_ERROR(("ETHER_TYPE_802_1X [%s]: ver %d, type %d, replay %d\n",
- direction ? "TX" : "RX",
- dump_data[14], dump_data[15], dump_data[30]));
- }
- } else {
- DHD_ERROR(("ETHER_TYPE_802_1X [%s]: ver %d, type %d, replay %d\n",
- direction ? "TX" : "RX",
- dump_data[14], dump_data[15], dump_data[30]));
- }
- }
- #endif /* DHD_8021X_DUMP */
|