static VOID APPeerAuthReqAtIdleAction( IN struct rtmp_adapter *pAd, IN MLME_QUEUE_ELEM *Elem) { INT i; unsigned short Seq, Alg, RspReason, Status; u8 Addr1[MAC_ADDR_LEN]; u8 Addr2[MAC_ADDR_LEN]; CHAR Chtxt[CIPHER_TEXT_LEN]; uint32_t apidx; PHEADER_802_11 pRcvHdr; HEADER_802_11 AuthHdr; u8 *pOutBuffer = NULL; int NStatus; ULONG FrameLen = 0; MAC_TABLE_ENTRY *pEntry; u8 ChTxtIe = 16, ChTxtLen = CIPHER_TEXT_LEN; MULTISSID_STRUCT *pMbss; struct rtmp_wifi_dev *wdev; CHAR rssi; if (! APPeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr1, Addr2, &Alg, &Seq, &Status, Chtxt )) return; /* Find which MBSSID to be authenticate */ apidx = get_apidx_by_addr(pAd, Addr1); if (apidx >= pAd->ApCfg.BssidNum) { DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Bssid not found\n")); return; } pMbss = &pAd->ApCfg.MBSSID[apidx]; wdev = &pMbss->wdev; if ((wdev->if_dev == NULL) || ((wdev->if_dev != NULL) && !(RTMP_OS_NETDEV_STATE_RUNNING(wdev->if_dev)))) { DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Bssid IF didn't up yet.\n")); return; } pEntry = MacTableLookup(pAd, Addr2); if (pEntry && IS_ENTRY_CLIENT(pEntry)) { if (!RTMPEqualMemory(Addr1, pAd->ApCfg.MBSSID[pEntry->apidx].wdev.bssid, MAC_ADDR_LEN)) { MacTableDeleteEntry(pAd, pEntry->wcid, pEntry->Addr); pEntry = NULL; DBGPRINT(RT_DEBUG_WARN, ("AUTH - Bssid does not match\n")); } else { if (pEntry->bIAmBadAtheros == true) { AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, false, false); DBGPRINT(RT_DEBUG_TRACE, ("Atheros Problem. Turn on RTS/CTS!!!\n")); pEntry->bIAmBadAtheros = false; } BASessionTearDownALL(pAd, pEntry->wcid); ASSERT(pEntry->Aid == Elem->Wcid); } } pRcvHdr = (PHEADER_802_11)(Elem->Msg); DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MBSS(%d), Rcv AUTH seq#%d, Alg=%d, Status=%d from " "[wcid=%d]%02x:%02x:%02x:%02x:%02x:%02x\n", apidx, Seq, Alg, Status, Elem->Wcid, PRINT_MAC(Addr2))); /* YF@20130102: Refuse the weak signal of AuthReq */ rssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, (CHAR)Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, (CHAR)Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, (CHAR)Elem->Rssi2, RSSI_2)); DBGPRINT(RT_DEBUG_TRACE, ("%s: AUTH_FAIL_REQ Threshold = %d, AUTH_NO_RSP_REQ Threshold = %d, AUTH RSSI = %d\n", wdev->if_dev->name, pMbss->AuthFailRssiThreshold, pMbss->AuthNoRspRssiThreshold, rssi)); if (((pMbss->AuthFailRssiThreshold != 0) && (rssi < pMbss->AuthFailRssiThreshold)) || ((pMbss->AuthNoRspRssiThreshold != 0) && (rssi < pMbss->AuthNoRspRssiThreshold))) { DBGPRINT(RT_DEBUG_TRACE, ("Reject this AUTH_REQ due to Weak Signal.\n")); if ((pMbss->AuthFailRssiThreshold != 0) && (rssi < pMbss->AuthFailRssiThreshold)) APPeerAuthSimpleRspGenAndSend(pAd, pRcvHdr, Alg, Seq + 1, MLME_UNSPECIFY_FAIL); /* If this STA exists, delete it. */ if (pEntry) MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr); RTMPSendWirelessEvent(pAd, IW_MAC_FILTER_LIST_EVENT_FLAG, Addr2, apidx, 0); return; } /* fail in ACL checking => send an AUTH-Fail seq#2. */ if (! ApCheckAccessControlList(pAd, Addr2, apidx)) { ASSERT(Seq == 1); ASSERT(pEntry == NULL); APPeerAuthSimpleRspGenAndSend(pAd, pRcvHdr, Alg, Seq + 1, MLME_UNSPECIFY_FAIL); /* If this STA exists, delete it. */ if (pEntry) MacTableDeleteEntry(pAd, pEntry->wcid, pEntry->Addr); RTMPSendWirelessEvent(pAd, IW_MAC_FILTER_LIST_EVENT_FLAG, Addr2, apidx, 0); DBGPRINT(RT_DEBUG_TRACE, ("Failed in ACL checking => send an AUTH seq#2 with " "Status code = %d\n", MLME_UNSPECIFY_FAIL)); return; } if ((Alg == AUTH_MODE_OPEN) && (pMbss->wdev.AuthMode != Ndis802_11AuthModeShared)) { if (!pEntry) pEntry = MacTableInsertEntry(pAd, Addr2, wdev, apidx, OPMODE_AP, true); if (pEntry) { { pEntry->AuthState = AS_AUTH_OPEN; pEntry->Sst = SST_AUTH; /* what if it already in SST_ASSOC ??????? */ } APPeerAuthSimpleRspGenAndSend(pAd, pRcvHdr, Alg, Seq + 1, MLME_SUCCESS); } else ; /* MAC table full, what should we respond ????? */ } else if ((Alg == AUTH_MODE_KEY) && ((wdev->AuthMode == Ndis802_11AuthModeShared) || (wdev->AuthMode == Ndis802_11AuthModeAutoSwitch))) { if (!pEntry) pEntry = MacTableInsertEntry(pAd, Addr2, wdev, apidx, OPMODE_AP, true); if (pEntry) { pEntry->AuthState = AS_AUTHENTICATING; pEntry->Sst = SST_NOT_AUTH; /* what if it already in SST_ASSOC ??????? */ /* log this STA in AuthRspAux machine, only one STA is stored. If two STAs using */ /* SHARED_KEY authentication mingled together, then the late comer will win. */ COPY_MAC_ADDR(&pAd->ApMlmeAux.Addr, Addr2); for(i=0; i<CIPHER_TEXT_LEN; i++) pAd->ApMlmeAux.Challenge[i] = RandomByte(pAd); RspReason = 0; Seq++; pOutBuffer = kmalloc(MGMT_DMA_BUFFER_SIZE, GFP_ATOMIC); if(pOutBuffer == NULL) return; /* if no memory, can't do anything */ DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH seq#2 (Challenge)\n")); MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr2, wdev->if_addr, wdev->bssid); MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(HEADER_802_11), &AuthHdr, 2, &Alg, 2, &Seq, 2, &RspReason, 1, &ChTxtIe, 1, &ChTxtLen, CIPHER_TEXT_LEN, pAd->ApMlmeAux.Challenge, END_OF_ARGS); MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); kfree(pOutBuffer); } else ; /* MAC table full, what should we respond ???? */ } else { /* wrong algorithm */ APPeerAuthSimpleRspGenAndSend(pAd, pRcvHdr, Alg, Seq + 1, MLME_ALG_NOT_SUPPORT); /* If this STA exists, delete it. */ if (pEntry) MacTableDeleteEntry(pAd, pEntry->wcid, pEntry->Addr); DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Alg=%d, Seq=%d, AuthMode=%d\n", Alg, Seq, pAd->ApCfg.MBSSID[apidx].wdev.AuthMode)); } }
/* 2 -- Change ee settings */ int Set_EECMD_Proc( IN PRTMP_ADAPTER pAd, IN PUCHAR arg) { USHORT i; i = simple_strtol(arg, 0, 10); switch(i) { case 0: { USHORT value, k; for (k = 0; k < EEPROM_SIZE; k+=2) { RT28xx_EEPROM_READ16(pAd, k, value); DBGPRINT(RT_DEBUG_OFF, ("%4.4x ", value)); if (((k+2) % 0x20) == 0) DBGPRINT(RT_DEBUG_OFF,("\n")); } } break; case 1: if (pAd->infType == RTMP_DEV_INF_RBUS) { DBGPRINT(RT_DEBUG_OFF, ("EEPROM reset to default......\n")); DBGPRINT(RT_DEBUG_OFF, ("The last byte of MAC address will be re-generated...\n")); if (rtmp_ee_flash_reset(nv_ee_start) != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_ERROR, ("Set_EECMD_Proc: rtmp_ee_flash_reset() failed\n")); return FALSE; } // Random number for the last bytes of MAC address { USHORT Addr45; rtmp_ee_flash_read(pAd, 0x08, &Addr45); Addr45 = Addr45 & 0xff; Addr45 = Addr45 | (RandomByte(pAd)&0xf8) << 8; DBGPRINT(RT_DEBUG_OFF, ("Addr45 = %4x\n", Addr45)); rtmp_ee_flash_write(pAd, 0x08, Addr45); } if ((rtmp_ee_flash_read(pAd, 0, &i) != 0x2880) && (rtmp_ee_flash_read(pAd, 0, &i) != 0x2860)) { DBGPRINT(RT_DEBUG_ERROR, ("Set_EECMD_Proc: invalid eeprom\n")); return FALSE; } } break; case 2: { USHORT offset, value = 0; PUCHAR p; p = arg+2; offset = simple_strtol(p, 0, 10); p+=2; while (*p != '\0') { if (*p >= '0' && *p <= '9') value = (value << 4) + (*p - 0x30); else if (*p >= 'a' && *p <= 'f') value = (value << 4) + (*p - 0x57); else if (*p >= 'A' && *p <= 'F') value = (value << 4) + (*p - 0x37); p++; } RT28xx_EEPROM_WRITE16(pAd, offset, value); } break; default: break; } return TRUE; }
/* ========================================================================== Description: insert a peer to P2P Group Table. Because this Peer contains P2P IE and P2P Wildwork SSID to indicate that it support P2P Parameters: Note: ========================================================================== */ UCHAR P2pGroupTabInsert( IN PRTMP_ADAPTER pAd, IN PUCHAR Addr, IN P2P_CLIENT_STATE State, IN CHAR Ssid[], IN UCHAR SsidLen, IN UCHAR DevCap, IN UCHAR GrpCap) { PRT_P2P_TABLE Tab = &pAd->P2pTable; UCHAR i; if (NdisEqualMemory(ZeroSsid, Addr, 6)) { DBGPRINT(RT_DEBUG_ERROR,("P2pGroupTabInsert . Addr all zero Error. \n")); return P2P_NOT_FOUND; } if ((Addr[0] & 0x1) == 0x1) { DBGPRINT(RT_DEBUG_ERROR,("P2pGroupTabInsert . Insert mcast Addr Error. \n")); return P2P_NOT_FOUND; } for (i = 0; i < MAX_P2P_GROUP_SIZE; i++) { /* This peer already exist, so only update state. */ if ((Tab->Client[i].P2pClientState != P2PSTATE_NONE) && (RTMPEqualMemory(Tab->Client[i].addr, Addr, MAC_ADDR_LEN))) { if (State != P2PSTATE_NONE) Tab->Client[i].P2pClientState = State; if ((SsidLen > 0) && (Ssid != NULL)) RTMPMoveMemory(Tab->Client[i].Ssid, Ssid, 32); Tab->Client[i].SsidLen = SsidLen; return i; } else if (Tab->Client[i].P2pClientState == P2PSTATE_NONE) { Tab->ClientNumber++; RTMPMoveMemory(Tab->Client[i].addr, Addr, 6); DBGPRINT(RT_DEBUG_ERROR, (" P2pGroupTabInsert[%d] . Arrd[%02x:%02x:%02x:%02x:%02x:%02x] Update State = %s \n", i, Addr[0], Addr[1], Addr[2], Addr[3], Addr[4], Addr[5], decodeP2PClientState(State))); Tab->Client[i].P2pClientState = State; if ((SsidLen > 0) && (Ssid != NULL)) RTMPMoveMemory(Tab->Client[i].Ssid, Ssid, 32); Tab->Client[i].SsidLen = SsidLen; pAd->P2pTable.Client[i].Dbm = 0; pAd->P2pTable.Client[i].GoIntent = 0; pAd->P2pTable.Client[i].MyGOIndex = 0xff; pAd->P2pTable.Client[i].Peerip = 0; pAd->P2pTable.Client[i].ConfigTimeOut = 0; pAd->P2pTable.Client[i].OpChannel = 0; pAd->P2pTable.Client[i].ListenChannel = 0; pAd->P2pTable.Client[i].GeneralToken = RandomByte(pAd); pAd->P2pTable.Client[i].DevCapability = DevCap; pAd->P2pTable.Client[i].GroupCapability = GrpCap; if ((pAd->P2pTable.Client[i].GeneralToken == 0) || (pAd->P2pTable.Client[i].GeneralToken > 245)) pAd->P2pTable.Client[i].GeneralToken = 6; pAd->P2pTable.Client[i].Dpid = DEV_PASS_ID_NOSPEC; pAd->P2pTable.Client[i].P2pFlag = 0; if (State == P2PSTATE_DISCOVERY_GO) pAd->P2pTable.Client[i].Rule = P2P_IS_GO; else pAd->P2pTable.Client[i].Rule = P2P_IS_CLIENT; return i; } } return P2P_NOT_FOUND; }