示例#1
0
float block_queue::get_speed(const boost::uuids::uuid &connection_id) const
{
  boost::unique_lock<boost::recursive_mutex> lock(mutex);
  std::unordered_map<boost::uuids::uuid, float> speeds;
  for (const auto &span: blocks)
  {
    if (span.blocks.empty())
      continue;
    // note that the average below does not average over the whole set, but over the
    // previous pseudo average and the latest rate: this gives much more importance
    // to the latest measurements, which is fine here
    std::unordered_map<boost::uuids::uuid, float>::iterator i = speeds.find(span.connection_id);
    if (i == speeds.end())
      speeds.insert(std::make_pair(span.connection_id, span.rate));
    else
      i->second = (i->second + span.rate) / 2;
  }
  float conn_rate = -1, best_rate = 0;
  for (auto i: speeds)
  {
    if (i.first == connection_id)
      conn_rate = i.second;
    if (i.second > best_rate)
      best_rate = i.second;
  }

  if (conn_rate <= 0)
    return 1.0f; // not found, assume good speed
  if (best_rate == 0)
    return 1.0f; // everything dead ? Can't happen, but let's trap anyway

  const float speed = conn_rate / best_rate;
  MTRACE(" Relative speed for " << connection_id << ": " << speed << " (" << conn_rate << "/" << best_rate);
  return speed;
}
tANI_U32
limDeactivateMinChannelTimerDuringScan(tpAniSirGlobal pMac)
{
    if ((pMac->lim.gLimMlmState == eLIM_MLM_WT_PROBE_RESP_STATE) && (pMac->lim.gLimHalScanState == eLIM_HAL_SCANNING_STATE))
    {
        /**
            * Beacon/Probe Response is received during active scanning.
            * Deactivate MIN channel timer if running.
            */

        limDeactivateAndChangeTimer(pMac,eLIM_MIN_CHANNEL_TIMER);
        MTRACE(macTrace(pMac, TRACE_CODE_TIMER_ACTIVATE, NO_SESSION, eLIM_MAX_CHANNEL_TIMER));
        if (tx_timer_activate(&pMac->lim.limTimers.gLimMaxChannelTimer)
                                          == TX_TIMER_ERROR)
        {
            /// Could not activate max channel timer.
            // Log error
            limLog(pMac,LOGP, FL("could not activate max channel timer"));

            limCompleteMlmScan(pMac, eSIR_SME_RESOURCES_UNAVAILABLE);
            return TX_TIMER_ERROR;
        }
    }
    return eSIR_SUCCESS;
} /*** end limDeactivateMinChannelTimerDuringScan() ***/
void lim_update_re_assoc_globals(tpAniSirGlobal pMac, tpSirAssocRsp pAssocRsp,
				 tpPESession psessionEntry)
{
	/* Update the current Bss Information */
	cdf_mem_copy(psessionEntry->bssId,
		     psessionEntry->limReAssocbssId, sizeof(tSirMacAddr));
	psessionEntry->currentOperChannel = psessionEntry->limReassocChannelId;
	psessionEntry->htSecondaryChannelOffset =
		psessionEntry->reAssocHtSupportedChannelWidthSet;
	psessionEntry->htRecommendedTxWidthSet =
		psessionEntry->reAssocHtRecommendedTxWidthSet;
	psessionEntry->htSecondaryChannelOffset =
		psessionEntry->reAssocHtSecondaryChannelOffset;
	psessionEntry->limCurrentBssCaps = psessionEntry->limReassocBssCaps;
	psessionEntry->limCurrentBssQosCaps =
		psessionEntry->limReassocBssQosCaps;
	psessionEntry->limCurrentBssPropCap =
		psessionEntry->limReassocBssPropCap;

	cdf_mem_copy((uint8_t *) &psessionEntry->ssId,
		     (uint8_t *) &psessionEntry->limReassocSSID,
		     psessionEntry->limReassocSSID.length + 1);

	/* Store assigned AID for TIM processing */
	psessionEntry->limAID = pAssocRsp->aid & 0x3FFF;
	/** Set the State Back to ReAssoc Rsp*/
	psessionEntry->limMlmState = eLIM_MLM_WT_REASSOC_RSP_STATE;
	MTRACE(mac_trace
		       (pMac, TRACE_CODE_MLM_STATE, psessionEntry->peSessionId,
		       psessionEntry->limMlmState));

}
示例#4
0
void connection_basic::sleep_before_packet(size_t packet_size, int phase,  int q_len) {
	double delay=0; // will be calculated
	do
	{ // rate limiting
		if (m_was_shutdown) { 
			_dbg2("m_was_shutdown - so abort sleep");
			return;
		}

		{ 
			CRITICAL_REGION_LOCAL(	network_throttle_manager::m_lock_get_global_throttle_out );
			delay = network_throttle_manager::get_global_throttle_out().get_sleep_time_after_tick( packet_size );
		}

		delay *= 0.50;
		if (delay > 0) {
            long int ms = (long int)(delay * 1000);
			MTRACE("Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // debug sleep
			boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) );
		}
	} while(delay > 0);

// XXX LATER XXX
	{
	  CRITICAL_REGION_LOCAL(	network_throttle_manager::m_lock_get_global_throttle_out );
		network_throttle_manager::get_global_throttle_out().handle_trafic_exact( packet_size ); // increase counter - global
	}

}
示例#5
0
/**
 * lim_send_cf_params()
 *
 ***FUNCTION:
 * This function is called to send CFP Parameters to WMA, when they are changed.
 *
 ***LOGIC:
 *
 ***ASSUMPTIONS:
 * NA
 *
 ***NOTE:
 * NA
 *
 * @param pMac  pointer to Global Mac structure.
 * @param bssIdx Bss Index of the BSS to which STA is associated.
 * @param cfpCount CFP Count, if that is changed.
 * @param cfpPeriod CFP Period if that is changed.
 *
 * @return success if message send is ok, else false.
 */
tSirRetStatus lim_send_cf_params(tpAniSirGlobal pMac, uint8_t bssIdx,
				 uint8_t cfpCount, uint8_t cfpPeriod)
{
	tpUpdateCFParams pCFParams = NULL;
	tSirRetStatus retCode = eSIR_SUCCESS;
	tSirMsgQ msgQ;

	pCFParams = cdf_mem_malloc(sizeof(tUpdateCFParams));
	if (NULL == pCFParams) {
		lim_log(pMac, LOGP,
			FL("Unable to allocate memory during Update CF Params"));
		retCode = eSIR_MEM_ALLOC_FAILED;
		goto returnFailure;
	}
	cdf_mem_set((uint8_t *) pCFParams, sizeof(tUpdateCFParams), 0);
	pCFParams->cfpCount = cfpCount;
	pCFParams->cfpPeriod = cfpPeriod;
	pCFParams->bssIdx = bssIdx;

	msgQ.type = WMA_UPDATE_CF_IND;
	msgQ.reserved = 0;
	msgQ.bodyptr = pCFParams;
	msgQ.bodyval = 0;
	lim_log(pMac, LOG3, FL("Sending WMA_UPDATE_CF_IND..."));
	MTRACE(mac_trace_msg_tx(pMac, NO_SESSION, msgQ.type));
	retCode = wma_post_ctrl_msg(pMac, &msgQ);
	if (eSIR_SUCCESS != retCode) {
		cdf_mem_free(pCFParams);
		lim_log(pMac, LOGP,
			FL("Posting WMA_UPDATE_CF_IND failed, reason=%X"),
			retCode);
	}
returnFailure:
	return retCode;
}
示例#6
0
void
limReleasePreAuthNode(tpAniSirGlobal pMac, tpLimPreAuthNode pAuthNode)
{
    pAuthNode->fFree = 1;
    MTRACE(macTrace(pMac, TRACE_CODE_TIMER_DEACTIVATE, NO_SESSION, eLIM_PRE_AUTH_CLEANUP_TIMER));
    tx_timer_deactivate(&pAuthNode->timer);                
    pMac->lim.gLimNumPreAuthContexts--;
} /*** end limReleasePreAuthNode() ***/
示例#7
0
void
limRestoreFromAuthState(tpAniSirGlobal pMac, tSirResultCodes resultCode, tANI_U16 protStatusCode,tpPESession sessionEntry)
{
    tSirMacAddr     currentBssId;
    tLimMlmAuthCnf  mlmAuthCnf;

    vos_mem_copy( (tANI_U8 *) &mlmAuthCnf.peerMacAddr,
                  (tANI_U8 *) &pMac->lim.gpLimMlmAuthReq->peerMacAddr,
                  sizeof(tSirMacAddr));
    mlmAuthCnf.authType   = pMac->lim.gpLimMlmAuthReq->authType;
    mlmAuthCnf.resultCode = resultCode;
    mlmAuthCnf.protStatusCode = protStatusCode;
    
    /* Update PE session ID*/
    mlmAuthCnf.sessionId = sessionEntry->peSessionId;

    /// Free up buffer allocated
    /// for pMac->lim.gLimMlmAuthReq
    vos_mem_free(pMac->lim.gpLimMlmAuthReq);
    pMac->lim.gpLimMlmAuthReq = NULL;

    sessionEntry->limMlmState = sessionEntry->limPrevMlmState;
    
    MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));


    // 'Change' timer for future activations
    limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);

    #if 0
    if (wlan_cfgGetStr(pMac, WNI_CFG_BSSID, currentBssId, &cfg) != eSIR_SUCCESS)
    {
        /// Could not get BSSID from CFG. Log error.
        limLog(pMac, LOGP, FL("could not retrieve BSSID"));
    }
    #endif //TO SUPPORT BT-AMP
    sirCopyMacAddr(currentBssId,sessionEntry->bssId);

    if (sessionEntry->limSmeState == eLIM_SME_WT_PRE_AUTH_STATE)
    {
        pMac->lim.gLimPreAuthChannelNumber = 0;
    }

    limPostSmeMessage(pMac,
                      LIM_MLM_AUTH_CNF,
                      (tANI_U32 *) &mlmAuthCnf);
} /*** end limRestoreFromAuthState() ***/
示例#8
0
static void __limInitStates(tpAniSirGlobal pMac)
{
    
    pMac->lim.gLimHBfailureCntInLinkEstState = 0;
    pMac->lim.gLimProbeFailureAfterHBfailedCnt = 0;
    pMac->lim.gLimHBfailureCntInOtherStates = 0;
    pMac->lim.gLimRspReqd = 0;
    pMac->lim.gLimPrevSmeState = eLIM_SME_OFFLINE_STATE;

    
    MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, NO_SESSION, eLIM_MLM_IDLE_STATE));
    pMac->lim.gLimMlmState = eLIM_MLM_IDLE_STATE;

    
    pMac->lim.gLimPrevMlmState = eLIM_MLM_OFFLINE_STATE;

#ifdef GEN4_SCAN
    
    pMac->lim.gLimHalScanState = eLIM_HAL_IDLE_SCAN_STATE;
#endif 

    pMac->lim.gLimSmeState     = eLIM_SME_OFFLINE_STATE;


    vos_mem_set(&pMac->lim.gLimOverlap11gParams, sizeof(tLimProtStaParams), 0);
    vos_mem_set(&pMac->lim.gLimOverlap11aParams, sizeof(tLimProtStaParams), 0);
    vos_mem_set(&pMac->lim.gLimOverlapHt20Params, sizeof(tLimProtStaParams), 0);
    vos_mem_set(&pMac->lim.gLimOverlapNonGfParams, sizeof(tLimProtStaParams), 0);
    vos_mem_set(&pMac->lim.gLimNoShortParams, sizeof(tLimNoShortParams), 0);
    vos_mem_set(&pMac->lim.gLimNoShortSlotParams, sizeof(tLimNoShortSlotParams), 0);

    pMac->lim.gLimPhyMode = 0; 
    pMac->lim.scanStartTime = 0;    

    vos_mem_set(pMac->lim.gLimMyMacAddr, sizeof(pMac->lim.gLimMyMacAddr), 0);
    pMac->lim.ackPolicy = 0;

#if 0 
    pMac->lim.gLimQosEnabled = 0; 
    pMac->lim.gLimWmeEnabled = 0; 
    pMac->lim.gLimWsmEnabled = 0; 
    pMac->lim.gLimHcfEnabled = 0;
    pMac->lim.gLim11dEnabled = 0;
#endif

    pMac->lim.gLimProbeRespDisableFlag = 0; 
}
void
initXEmbedServerData() {
    JNIEnv      *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jclass clazz;
    MTRACE("initXEmbedServerData\n");
    XA_XEmbedInfo = XInternAtom(awt_display, "_XEMBED_INFO", False);
    XA_XEmbed = XInternAtom(awt_display, "_XEMBED", False);

    clazz = (*env)->FindClass(env, "sun/awt/motif/MEmbedCanvasPeer");
    DASSERT(clazz != NULL);
    requestXEmbedFocusMID = (*env)->GetMethodID(env, clazz, "requestXEmbedFocus", "()V");
    DASSERT(requestXEmbedFocusMID != NULL);
    focusNextMID = (*env)->GetMethodID(env, clazz, "focusNext", "()V");
    DASSERT(focusNextMID != NULL);
    focusPrevMID = (*env)->GetMethodID(env, clazz, "focusPrev", "()V");
    DASSERT(focusPrevMID != NULL);
    registerAcceleratorMID = (*env)->GetMethodID(env, clazz, "registerAccelerator", "(JJJ)V");
    DASSERT(registerAcceleratorMID != NULL);
    unregisterAcceleratorMID = (*env)->GetMethodID(env, clazz, "unregisterAccelerator", "(J)V");
    DASSERT(unregisterAcceleratorMID != NULL);
    grabKeyMID = (*env)->GetMethodID(env, clazz, "grabKey", "(JJ)V");
    DASSERT(grabKeyMID != NULL);
    ungrabKeyMID = (*env)->GetMethodID(env, clazz, "ungrabKey", "(JJ)V");
    DASSERT(ungrabKeyMID != NULL);
    childResizedMID = (*env)->GetMethodID(env, clazz, "childResized", "()V");
    DASSERT(childResizedMID != NULL);
    setXEmbedDropTargetMID =
        (*env)->GetMethodID(env, clazz, "setXEmbedDropTarget", "()V");
    DASSERT(setXEmbedDropTargetMID != NULL);
    removeXEmbedDropTargetMID =
        (*env)->GetMethodID(env, clazz, "removeXEmbedDropTarget", "()V");
    DASSERT(removeXEmbedDropTargetMID != NULL);

    applicationActiveFID = (*env)->GetFieldID(env, clazz, "applicationActive", "Z");
    DASSERT(applicationActiveFID != NULL);
    (*env)->DeleteLocalRef(env, clazz);

    clazz = (*env)->FindClass(env, "sun/awt/motif/GrabbedKey");
    DASSERT(clazz != NULL);
    keysymFID = (*env)->GetFieldID(env, clazz, "keysym", "J");
    DASSERT(keysymFID != NULL);
    modifiersFID = (*env)->GetFieldID(env, clazz, "modifiers", "J");
    DASSERT(modifiersFID != NULL);
    (*env)->DeleteLocalRef(env, clazz);
}
void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_size)
{
	tick();

	calculate_times_struct cts ;  calculate_times(packet_size, cts , false, -1);
	calculate_times_struct cts2;  calculate_times(packet_size, cts2, false, 5);
	m_history[0].m_size += packet_size;

	std::ostringstream oss; oss << "["; 	for (auto sample: m_history) oss << sample.m_size << " ";	 oss << "]" << std::ends;
	std::string history_str = oss.str();

	MTRACE("Throttle " << m_name << ": packet of ~"<<packet_size<<"b " << " (from "<<orginal_size<<" b)"
        << " Speed AVG=" << std::setw(4) <<  ((long int)(cts .average/1024)) <<"[w="<<cts .window<<"]"
        <<           " " << std::setw(4) <<  ((long int)(cts2.average/1024)) <<"[w="<<cts2.window<<"]"
				<<" / " << " Limit="<< ((long int)(m_target_speed/1024)) <<" KiB/sec "
				<< " " << history_str
		);
}
示例#11
0
/**
 * limSendCFParams()
 *
 *FUNCTION:
 * This function is called to send CFP Parameters to WDA, when they are changed.
 *
 *LOGIC:
 *
 *ASSUMPTIONS:
 * NA
 *
 *NOTE:
 * NA
 *
 * @param pMac  pointer to Global Mac structure.
 * @param bssIdx Bss Index of the BSS to which STA is associated.
 * @param cfpCount CFP Count, if that is changed.
 * @param cfpPeriod CFP Period if that is changed.
 *
 * @return success if message send is ok, else false.
 */
tSirRetStatus limSendCFParams(tpAniSirGlobal pMac, tANI_U8 bssIdx, tANI_U8 cfpCount, tANI_U8 cfpPeriod)
{
    tpUpdateCFParams pCFParams = NULL;
    tSirRetStatus   retCode = eSIR_SUCCESS;
    tSirMsgQ msgQ;

    if( eHAL_STATUS_SUCCESS != palAllocateMemory( pMac->hHdd,
          (void **) &pCFParams,
          sizeof( tUpdateCFParams )))
      {
        limLog( pMac, LOGP,
            FL( "Unable to PAL allocate memory during Update CF Params\n" ));
        retCode = eSIR_MEM_ALLOC_FAILED;
        goto returnFailure;
      }
    palZeroMemory( pMac->hHdd, (tANI_U8 *) pCFParams, sizeof(tUpdateCFParams));
    pCFParams->cfpCount = cfpCount;
    pCFParams->cfpPeriod = cfpPeriod;
    pCFParams->bssIdx     = bssIdx;

    msgQ.type = WDA_UPDATE_CF_IND;
    msgQ.reserved = 0;
    msgQ.bodyptr = pCFParams;
    msgQ.bodyval = 0;
    limLog( pMac, LOG3,
                FL( "Sending WDA_UPDATE_CF_IND..." ));
    MTRACE(macTraceMsgTx(pMac, NO_SESSION, msgQ.type));
    if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
    {
        palFreeMemory(pMac->hHdd, pCFParams);
        limLog( pMac, LOGP,
                    FL("Posting  WDA_UPDATE_CF_IND to WDA failed, reason=%X\n"),
                    retCode );
    }
returnFailure:
    return retCode;
}
/**
 * limSendCFParams()
 *
 *FUNCTION:
 * This function is called to send CFP Parameters to WDA, when they are changed.
 *
 *LOGIC:
 *
 *ASSUMPTIONS:
 * NA
 *
 *NOTE:
 * NA
 *
 * @param pMac  pointer to Global Mac structure.
 * @param bssIdx Bss Index of the BSS to which STA is associated.
 * @param cfpCount CFP Count, if that is changed.
 * @param cfpPeriod CFP Period if that is changed.
 *
 * @return success if message send is ok, else false.
 */
tSirRetStatus limSendCFParams(tpAniSirGlobal pMac, tANI_U8 bssIdx, tANI_U8 cfpCount, tANI_U8 cfpPeriod)
{
    tpUpdateCFParams pCFParams = NULL;
    tSirRetStatus   retCode = eSIR_SUCCESS;
    tSirMsgQ msgQ;

    pCFParams = vos_mem_malloc(sizeof( tUpdateCFParams ));
    if ( NULL == pCFParams )
      {
        limLog( pMac, LOGP,
            FL( "Unable to allocate memory during Update CF Params" ));
        retCode = eSIR_MEM_ALLOC_FAILED;
        goto returnFailure;
      }
    vos_mem_set( (tANI_U8 *) pCFParams, sizeof(tUpdateCFParams), 0);
    pCFParams->cfpCount = cfpCount;
    pCFParams->cfpPeriod = cfpPeriod;
    pCFParams->bssIdx     = bssIdx;

    msgQ.type = WDA_UPDATE_CF_IND;
    msgQ.reserved = 0;
    msgQ.bodyptr = pCFParams;
    msgQ.bodyval = 0;
    limLog( pMac, LOG3,
                FL( "Sending WDA_UPDATE_CF_IND..." ));
    MTRACE(macTraceMsgTx(pMac, NO_SESSION, msgQ.type));
    if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
    {
        vos_mem_free(pCFParams);
        limLog( pMac, LOGP,
                    FL("Posting  WDA_UPDATE_CF_IND to WDA failed, reason=%X"),
                    retCode );
    }
returnFailure:
    return retCode;
}
示例#13
0
void MNetLink::SetLinkState(MNetLink::LINKSTATE nState) 
{ 
	if (m_nLinkState == nState)
		return;

	m_nLinkState = nState; 

	#ifdef LINKSTATE_LOG
	switch(m_nLinkState) {
	case LINKSTATE_CLOSED:
		Setconnected(false);
		MTRACE("<LINK_STATE> LINKSTATE_CLOSED \n");
		if (m_pSafeUDP && m_pSafeUDP->m_fnNetLinkStateCallback)
			m_pSafeUDP->m_fnNetLinkStateCallback(this, LINKSTATE_CLOSED);
		break;
	case LINKSTATE_ESTABLISHED:
		Setconnected(true);
		MTRACE("<LINK_STATE> LINKSTATE_ESTABLISHED \n");
		if (m_pSafeUDP && m_pSafeUDP->m_fnNetLinkStateCallback)
			m_pSafeUDP->m_fnNetLinkStateCallback(this, LINKSTATE_ESTABLISHED);
		break;
	case LINKSTATE_SYN_SENT:
		MTRACE("<LINK_STATE> LINKSTATE_SYN_SENT \n");
		break;
	case LINKSTATE_SYN_RCVD:
		MTRACE("<LINK_STATE> LINKSTATE_SYN_RCVD \n");
		break;
	case LINKSTATE_FIN_SENT:
		MTRACE("<LINK_STATE> LINKSTATE_FIN_SENT \n");
		break;
	case LINKSTATE_FIN_RCVD:
		MTRACE("<LINK_STATE> LINKSTATE_FIN_RCVD \n");
		break;
	};
	#endif
}
示例#14
0
void connection_basic::do_send_handler_write_from_queue( const boost::system::error_code& e, size_t cb, int q_len ) {
        // No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write
	MTRACE("handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)");
}
示例#15
0
void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) {
        // No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write
	MTRACE("handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)");
}
/**
 * sysBbtProcessMessageCore
 *
 * FUNCTION:
 * Process BBT messages
 *
 * LOGIC:
 *
 * ASSUMPTIONS:
 *
 * NOTE:
 *
 * @param tpAniSirGlobal A pointer to MAC params instance
 * @param pMsg message pointer
 * @param tANI_U32 type
 * @param tANI_U32 sub type
 * @return None
 */
tSirRetStatus
sysBbtProcessMessageCore(tpAniSirGlobal pMac, tpSirMsgQ pMsg, tANI_U32 type,
                         tANI_U32 subType)
{
    tANI_U32 framecount;
    tSirRetStatus ret;
    void*         pBd;
    tMgmtFrmDropReason dropReason;
    vos_pkt_t  *pVosPkt = (vos_pkt_t *)pMsg->bodyptr;
    VOS_STATUS  vosStatus =
              WDA_DS_PeekRxPacketInfo( pVosPkt, (v_PVOID_t *)&pBd, VOS_FALSE );

    pMac->sys.gSysBbtReceived++;

    if ( !VOS_IS_STATUS_SUCCESS(vosStatus) )
    {
        goto fail;
    }

    sysLog(pMac, LOG3, FL("Rx Mgmt Frame Subtype: %d\n"), subType);
    sirDumpBuf(pMac, SIR_SYS_MODULE_ID, LOG3, (tANI_U8 *)WDA_GET_RX_MAC_HEADER(pBd), WDA_GET_RX_MPDU_LEN(pBd));
    sirDumpBuf(pMac, SIR_SYS_MODULE_ID, LOG3, WDA_GET_RX_MPDU_DATA(pBd), WDA_GET_RX_PAYLOAD_LEN(pBd));

    pMac->sys.gSysFrameCount[type][subType]++;
    framecount = pMac->sys.gSysFrameCount[type][subType];

    if(type == SIR_MAC_MGMT_FRAME)
    {
            tpSirMacMgmtHdr mac_hdr;
            /*
             * Drop beacon frames in deferred state to avoid VOSS run out of
             * message wrappers.
             */
            if ((subType == SIR_MAC_MGMT_BEACON) &&
                (!limIsSystemInScanState(pMac)) &&
                (true != GET_LIM_PROCESS_DEFD_MESGS(pMac)) &&
                !pMac->lim.gLimSystemInScanLearnMode) {
                sysLog(pMac, LOG1,
                          FL("dropping received beacon in deffered state"));
                goto fail;
            }

            dropReason = limIsPktCandidateForDrop(pMac, pBd, subType);
            if (dropReason != eMGMT_DROP_NO_DROP) {
                sysLog(pMac, LOG1,
                            FL("Mgmt Frame %d being dropped, reason: %d\n"),
                            subType, dropReason);
                MTRACE(macTrace(pMac, TRACE_CODE_RX_MGMT_DROP, NO_SESSION, dropReason));
                goto fail;
            }

            mac_hdr = WDA_GET_RX_MAC_HEADER(pBd);
            if (subType == SIR_MAC_MGMT_ASSOC_REQ) {
                sysLog(pMac, LOG1,
                       FL("ASSOC REQ frame allowed: da: " MAC_ADDRESS_STR ", sa: " MAC_ADDRESS_STR ", bssid: " MAC_ADDRESS_STR ", Assoc Req count so far: %d\n"),
                       MAC_ADDR_ARRAY(mac_hdr->da),
                       MAC_ADDR_ARRAY(mac_hdr->sa),
                       MAC_ADDR_ARRAY(mac_hdr->bssId),
                       pMac->sys.gSysFrameCount[type][subType]);
            }

            if (subType == SIR_MAC_MGMT_DEAUTH)
            {
                sysLog(pMac, LOG1,
                       FL("DEAUTH frame allowed: da: " MAC_ADDRESS_STR ", sa: " MAC_ADDRESS_STR ", bssid: " MAC_ADDRESS_STR ", DEAUTH count so far: %d\n"),
                       MAC_ADDR_ARRAY(mac_hdr->da),
                       MAC_ADDR_ARRAY(mac_hdr->sa),
                       MAC_ADDR_ARRAY(mac_hdr->bssId),
                       pMac->sys.gSysFrameCount[type][subType]);
            }
            if (subType == SIR_MAC_MGMT_DISASSOC)
            {
                sysLog(pMac, LOG1,
                       FL("DISASSOC frame allowed: da: " MAC_ADDRESS_STR ", sa: " MAC_ADDRESS_STR ", bssid: " MAC_ADDRESS_STR ", DISASSOC count so far: %d\n"),
                       MAC_ADDR_ARRAY(mac_hdr->da),
                       MAC_ADDR_ARRAY(mac_hdr->sa),
                       MAC_ADDR_ARRAY(mac_hdr->bssId),
                       pMac->sys.gSysFrameCount[type][subType]);
            }

            //Post the message to PE Queue
            ret = (tSirRetStatus) limPostMsgApi(pMac, pMsg);
            if (ret != eSIR_SUCCESS)
            {
                /* Print only one debug failure out of 512 failure messages */
                if(pMac->sys.gSysBbtReceived & 0x0200)
                   sysLog(pMac, LOGE,
                       FL("posting to LIM2 failed, ret %d"), ret);
                goto fail;
            }
            pMac->sys.gSysBbtPostedToLim++;
    }
    else if (type == SIR_MAC_DATA_FRAME)
    {
#ifdef FEATURE_WLAN_ESE
        sysLog(pMac, LOGW, FL("IAPP Frame...\n"));
        //Post the message to PE Queue
        ret = (tSirRetStatus) limPostMsgApi(pMac, pMsg);
        if (ret != eSIR_SUCCESS)
        {
            sysLog(pMac, LOGE, FL("posting to LIM2 failed, ret %d\n"), ret);
            goto fail;
        }
        pMac->sys.gSysBbtPostedToLim++;
#endif
    }
    else
    {
        sysLog(pMac, LOG3, "BBT received Invalid type %d subType %d "
                   "LIM state %X. BD dump is:\n",
                   type, subType, limGetSmeState(pMac));
        sirDumpBuf(pMac, SIR_SYS_MODULE_ID, LOG3,
                       (tANI_U8 *) pBd, WLANHAL_RX_BD_HEADER_SIZE);

        goto fail;
    }

    return eSIR_SUCCESS;

fail:

    pMac->sys.gSysBbtDropped++;
    return eSIR_FAILURE;
}
// MAIN LOGIC:
void network_throttle::calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const 
{
    const double the_window_size = std::max( (double)m_window_size ,
		((force_window>0) ? force_window : m_window_size) 
	);

	if (!m_any_packet_yet) {
		cts.window=0; cts.average=0; cts.delay=0; 
		cts.recomendetDataSize = m_network_minimal_segment; // should be overrided by caller anyway
		return ; // no packet yet, I can not decide about sleep time
	}

	network_time_seconds window_len = (the_window_size-1) * m_slot_size ; // -1 since current slot is not finished
	window_len += (m_last_sample_time - time_to_slot(m_last_sample_time));  // add the time for current slot e.g. 13.7-13 = 0.7

	auto time_passed = get_time_seconds() - m_start_time;
	cts.window = std::max( std::min( window_len , time_passed ) , m_slot_size )  ; // window length resulting from size of history but limited by how long ago history was started,
	// also at least slot size (e.g. 1 second) to not be ridiculous
	// window_len e.g. 5.7 because takes into account current slot time

	size_t Epast = 0; // summ of traffic till now
	for (auto sample : m_history) Epast += sample.m_size; 

	const size_t E = Epast;
	const size_t Enow = Epast + packet_size ; // including the data we're about to send now

	const double M = m_target_speed; // max
	const double D1 = (Epast - M*cts.window) / M; // delay - how long to sleep to get back to target speed
	const double D2 = (Enow  - M*cts.window) / M; // delay - how long to sleep to get back to target speed (including current packet)

    cts.delay = (D1*0.80 + D2*0.20); // finall sleep depends on both with/without current packet
	//				update_overheat();
	cts.average = Epast/cts.window; // current avg. speed (for info)

	if (Epast <= 0) {
		if (cts.delay>=0) cts.delay = 0; // no traffic in history so we will not wait
	}

    double Wgood=-1;
    {	// how much data we recommend now to download
        Wgood = the_window_size + 1;
        cts.recomendetDataSize = M*cts.window - E;
    }

	if (dbg) {
		std::ostringstream oss; oss << "["; 	for (auto sample: m_history) oss << sample.m_size << " ";	 oss << "]" << std::ends;
		std::string history_str = oss.str();
		MTRACE((cts.delay > 0 ? "SLEEP" : "")
			<< "dbg " << m_name << ": " 
			<< "speed is A=" << std::setw(8) <<cts.average<<" vs "
			<< "Max=" << std::setw(8) <<M<<" "
			<< " so sleep: "
			<< "D=" << std::setw(8) <<cts.delay<<" sec "
			<< "E="<< std::setw(8) << E << " (Enow="<<std::setw(8)<<Enow<<") "
            << "M=" << std::setw(8) << M <<" W="<< std::setw(8) << cts.window << " "
            << "R=" << std::setw(8) << cts.recomendetDataSize << " Wgood" << std::setw(8) << Wgood << " "
			<< "History: " << std::setw(8) << history_str << " "
			<< "m_last_sample_time=" << std::setw(8) << m_last_sample_time
		);

	}
}
示例#18
0
文件: trnc.c 项目: schwehr/mb-system
/// @fn int s_trnc_state_machine(iow_socket_t *s, app_cfg_t *cfg)
/// @brief state machine implementation
/// @param[in] s iow_socket_t reference
/// @param[in] cfg app_cfg reference
/// @return none
static int s_trnc_state_machine(iow_socket_t *s, app_cfg_t *cfg)
{
    int retval=-1;
    int scycles=cfg->cycles;
    int trn_tx_count=0;
    int trn_rx_count=0;
    int trn_tx_bytes=0;
    int trn_rx_bytes=0;
    int trn_msg_count=0;
    int trn_msg_bytes=0;
    const char *reqstr="REQ\0";
    
    if (NULL!=s) {
        
        // initialize variables
        trn_message_t message;
        trn_message_t *pmessage = &message;
        mbtrn_header_t *pheader = &pmessage->data.header;
        mbtrn_sounding_t *psounding = &pmessage->data.sounding;
        
        memset(pmessage,0,sizeof(message));
        int hbeat_counter=0;
        int64_t test=0;
        byte *pread=NULL;
        uint32_t readlen=0;
        
        trnc_state_t state=ST_INIT;
        trnc_action_t action=AT_NOP;
        
        // state machine entry point
        while (state != ST_DONE && !g_interrupt) {
            
            // check states, assign actions
            switch (state) {
                case ST_INIT:
                    memset(&message,0,MBTRN_MAX_MSG_BYTES);
                    action = AT_CONNECT;
                    break;
                case ST_CONNECTED:
                    action=AT_WR_REQ;
                    break;
                case ST_REQ_PENDING:
                case ST_SUBSCRIBED:
                    memset(&message,0,MBTRN_MAX_MSG_BYTES);
                    action=AT_RD_MSG;
                    break;
                case ST_HBEAT_EXPIRED:
                    action=AT_WR_REQ;
                    break;
                    
                default:
                    break;
            }// switch
            
            // action: connect
            if (action == AT_CONNECT) {
                MMDEBUG(ID_APP,"connecting [%s:%d]\n",cfg->host,cfg->port);
                if( (test=iow_connect(s))==0 ) {
                    MMDEBUG(ID_APP,"connect OK\n");
                    state=ST_CONNECTED;
                }else{
                    MERROR("connect failed [%"PRId64"]\n",test);
                }
            }
            
            // action: write request
            if (action == AT_WR_REQ) {
                
                test=iow_sendto(s,NULL,(byte *)reqstr,4,0);
                
                MMDEBUG(ID_APP,"sendto REQ ret[%"PRId64"] [%d/%s]\n",test,errno,strerror(errno));
                
                if( test>0 ){
                    trn_tx_count++;
                    trn_tx_bytes+=test;
                    state=ST_REQ_PENDING;
                }else{
                    MMDEBUG(ID_APP,"sendto failed ret[%"PRId64"] [%d/%s]\n",test,errno,strerror(errno));
                }
            }
            
            // action: read response
            if (action == AT_RD_MSG) {
                pread = (byte *)&message;
                readlen = MBTRN_MAX_MSG_BYTES;
                // request message
                if ((test = iow_recvfrom(s, NULL, pread, readlen))>0) {
                    
                    trn_rx_bytes+=test;
                    trn_rx_count++;
                    
                    // check message type
                    if (pheader->type==MBTRN_MSGTYPE_ACK) {
                        MMDEBUG(ID_APP,"received ACK ret[%"PRId64"] [%08X]\n",test,pheader->type);
                        hbeat_counter=0;
                        state=ST_SUBSCRIBED;
                    }else if (pheader->type==MBTRN_MSGTYPE_MB1) {
                        MMDEBUG(ID_APP,"received MSG ret[%"PRId64"] type[%08X] size[%d] ping[%06d]\n",test,pheader->type,pheader->size,psounding->ping_number);
                        trn_msg_count++;
                        trn_msg_bytes+=test;
                        
                        action=AT_SHOW_MSG;
                        
                        if (state==ST_REQ_PENDING) {
                            state=ST_REQ_PENDING;
                        }else{
                            state=ST_SUBSCRIBED;
                        }
                        hbeat_counter++;
                        MMDEBUG(ID_APP,"hbeat[%d/%d]\n",hbeat_counter,cfg->hbeat);
                        if ( (hbeat_counter!=0) && (hbeat_counter%cfg->hbeat==0)) {
                            state=ST_HBEAT_EXPIRED;
                        }
                    }else{
                        // response not recognized
                        MMDEBUG(ID_APP,"invalid message [%08X]\n",pheader->type);
                    }
                }else{
                    // read returned error
                    //  MMDEBUG(ID_APP,"invalid message [%d]\n",test);
                    switch (errno) {
                        case EWOULDBLOCK:
                            // nothing to read
                            //   MMDEBUG(ID_APP,"err - [%d/%s]\n",errno, strerror(errno));
                            break;
                        case ENOTCONN:
                        case ECONNREFUSED:
                            // host disconnected
                            MMDEBUG(ID_APP,"err - server not connected [%d/%s]\n",errno, strerror(errno));
                            iow_socket_destroy(&s);
                            s = iow_socket_new(cfg->host, cfg->port, ST_UDP);
                            iow_set_blocking(s,(cfg->blocking==0?false:true));
                            sleep(5);
                            state=ST_INIT;
                            retval=-1;
                            break;
                        default:
                            MMDEBUG(ID_APP,"err ? [%d/%s]\n",errno, strerror(errno));
                            break;
                    }//switch
                }
            }
            
            // action: show message
            if (action == AT_SHOW_MSG) {
                MMDEBUG(ID_APP,"\nts[%.3f] ping[%06d] lat[%.4lf] lon[%.4lf]\nsd[%7.2lf] hdg[%6.2lf] nb[%03"PRIu32"]\n",
                        psounding->ts,
                        psounding->ping_number,
                        psounding->lat,
                        psounding->lon,
                        psounding->depth,
                        psounding->hdg,
                        (uint32_t)psounding->nbeams);
                uint32_t j=0;
                struct mbtrn_beam_data *bd=psounding->beams;
                for (j=0; j<psounding->nbeams; j++,bd++){
                    MMDEBUG(ID_APP,"n[%03"PRIu32"] atrk/X[% 10.3lf] ctrk/Y[% 10.3lf] dpth/Z[% 10.3lf]\n",
                            (uint32_t)bd->beam_num,
                            bd->rhox,
                            bd->rhoy,
                            bd->rhoz);
                }
            }
            
            // action: quit state machine
            if (action == AT_QUIT) {
                break;
            }
            
            // check cycles and signals
            scycles--;
            if(scycles==0){
                MTRACE();
                retval=0;
                state=ST_DONE;
            }
            
            if(g_interrupt){
                MTRACE();
                retval=-1;
                state=ST_DONE;
            }
            
        }// while !ST_DONE
    }//else invalid arg
    
    MMINFO(ID_APP,"tx count/bytes[%d/%d]\n",trn_tx_count,trn_tx_bytes);
    MMINFO(ID_APP,"rx count/bytes[%d/%d]\n",trn_rx_count,trn_rx_bytes);
    MMINFO(ID_APP,"trn count/bytes[%d/%d]\n",trn_msg_count,trn_msg_bytes);
    
    return retval;
}
void
lim_process_assoc_rsp_frame(tpAniSirGlobal mac_ctx,
	uint8_t *rx_pkt_info, uint8_t subtype, tpPESession session_entry)
{
	uint8_t *body;
	uint16_t caps, ie_len;
	uint32_t frame_len;
	tSirMacAddr current_bssid;
	tpSirMacMgmtHdr hdr = NULL;
	tSirMacCapabilityInfo mac_capab;
	tpDphHashNode sta_ds;
	tpSirAssocRsp assoc_rsp;
	tLimMlmAssocCnf assoc_cnf;
	tSchBeaconStruct *beacon;
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
	uint8_t sme_sessionid = 0;
#endif
	tCsrRoamSession *roam_session;

	/* Initialize status code to success. */
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
	if (session_entry->bRoamSynchInProgress)
		hdr = (tpSirMacMgmtHdr) mac_ctx->roam.pReassocResp;
	else
#endif
	hdr = WMA_GET_RX_MAC_HEADER(rx_pkt_info);
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
	sme_sessionid = session_entry->smeSessionId;
#endif
	assoc_cnf.resultCode = eSIR_SME_SUCCESS;
	/* Update PE session Id */
	assoc_cnf.sessionId = session_entry->peSessionId;
	if (hdr == NULL) {
		lim_log(mac_ctx, LOGE,
			FL("LFR3: Reassoc response packet header is NULL"));
		return;
	} else if (hdr->sa == NULL) {
		lim_log(mac_ctx, LOGE,
			FL("LFR3: Reassoc resp packet source address is NULL"));
		return;
	}

	lim_log(mac_ctx, LOG1,
		FL("received Re/Assoc(%d) resp on sessionid: %d systemrole: %d"
		"and mlmstate: %d RSSI %d from " MAC_ADDRESS_STR), subtype,
		session_entry->peSessionId, GET_LIM_SYSTEM_ROLE(session_entry),
		session_entry->limMlmState,
		(uint) abs((int8_t) WMA_GET_RX_RSSI_DB(rx_pkt_info)),
		MAC_ADDR_ARRAY(hdr->sa));

	beacon = cdf_mem_malloc(sizeof(tSchBeaconStruct));
	if (NULL == beacon) {
		lim_log(mac_ctx, LOGE, FL("Unable to allocate memory"));
		return;
	}

	if (LIM_IS_AP_ROLE(session_entry) ||
		LIM_IS_BT_AMP_AP_ROLE(session_entry)) {
		/*
		 * Should not have received Re/Association
		 * Response frame on AP. Log error
		 */
		lim_log(mac_ctx, LOGE,
			FL("Should not recieved Re/Assoc Response in role %d "),
			GET_LIM_SYSTEM_ROLE(session_entry));
		cdf_mem_free(beacon);
		return;
	}
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
	if (session_entry->bRoamSynchInProgress) {
		hdr = (tpSirMacMgmtHdr) mac_ctx->roam.pReassocResp;
		frame_len = mac_ctx->roam.reassocRespLen - SIR_MAC_HDR_LEN_3A;
	} else {
#endif
	hdr = WMA_GET_RX_MAC_HEADER(rx_pkt_info);
	frame_len = WMA_GET_RX_PAYLOAD_LEN(rx_pkt_info);
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
}
#endif
	if (((subtype == LIM_ASSOC) &&
		(session_entry->limMlmState != eLIM_MLM_WT_ASSOC_RSP_STATE)) ||
		((subtype == LIM_REASSOC) &&
		((session_entry->limMlmState != eLIM_MLM_WT_REASSOC_RSP_STATE)
#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
		&& (session_entry->limMlmState !=
		eLIM_MLM_WT_FT_REASSOC_RSP_STATE)
#endif
		))) {
		/* Received unexpected Re/Association Response frame */

#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
		lim_log(mac_ctx, LOG1,
			FL("Recieved Re/Assoc rsp in unexpected "
			"state %d on session=%d"),
			session_entry->limMlmState, session_entry->peSessionId);
#endif
		if (!hdr->fc.retry) {
			if (!(mac_ctx->lim.retry_packet_cnt & 0xf)) {
				lim_log(mac_ctx, LOGE,
				    FL("recvd Re/Assoc rsp:not a retry frame"));
				lim_print_mlm_state(mac_ctx, LOGE,
						session_entry->limMlmState);
			} else {
				mac_ctx->lim.retry_packet_cnt++;
			}
		}
		cdf_mem_free(beacon);
		return;
	}
	sir_copy_mac_addr(current_bssid, session_entry->bssId);
	if (subtype == LIM_ASSOC) {
		if (!cdf_mem_compare
			(hdr->sa, current_bssid, sizeof(tSirMacAddr))) {
			/*
			 * Received Association Response frame from an entity
			 * other than one to which request was initiated.
			 * Ignore this and wait until Assoc Failure Timeout
			 */
			lim_log(mac_ctx, LOGW,
				 FL("received AssocRsp from unexpected peer "
				MAC_ADDRESS_STR),
				MAC_ADDR_ARRAY(hdr->sa));
			cdf_mem_free(beacon);
			return;
		}
	} else {
		if (!cdf_mem_compare
			(hdr->sa, session_entry->limReAssocbssId,
			sizeof(tSirMacAddr))) {
			/*
			 * Received Reassociation Response frame from an entity
			 * other than one to which request was initiated.
			 * Ignore this and wait until Reassoc Failure Timeout.
			 */
			lim_log(mac_ctx, LOGW,
				FL("received ReassocRsp from unexpected peer "
				MAC_ADDRESS_STR),
				MAC_ADDR_ARRAY(hdr->sa));
			cdf_mem_free(beacon);
			return;
		}
	}

	assoc_rsp = cdf_mem_malloc(sizeof(*assoc_rsp));
	if (NULL == assoc_rsp) {
		lim_log(mac_ctx, LOGP,
			FL("Allocate Memory failed in AssocRsp"));
		cdf_mem_free(beacon);
		return;
	}
	/* Get pointer to Re/Association Response frame body */
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
	if (session_entry->bRoamSynchInProgress)
		body = mac_ctx->roam.pReassocResp + SIR_MAC_HDR_LEN_3A;
	else
#endif
	body = WMA_GET_RX_MPDU_DATA(rx_pkt_info);
	/* parse Re/Association Response frame. */
	if (sir_convert_assoc_resp_frame2_struct(mac_ctx, body,
		frame_len, assoc_rsp) == eSIR_FAILURE) {
		cdf_mem_free(assoc_rsp);
		lim_log(mac_ctx, LOGE,
			FL("Parse error Assoc resp subtype %d," "length=%d"),
			frame_len, subtype);
		cdf_mem_free(beacon);
		return;
	}

	if (!assoc_rsp->suppRatesPresent) {
		lim_log(mac_ctx, LOGE,
		FL("assoc response does not have supported rate set"));
		cdf_mem_copy(&assoc_rsp->supportedRates,
			&session_entry->rateSet,
			sizeof(tSirMacRateSet));
	}

	assoc_cnf.protStatusCode = assoc_rsp->statusCode;
	if (session_entry->assocRsp != NULL) {
		lim_log(mac_ctx, LOGW,
			FL("session_entry->assocRsp is not NULL freeing it "
			 "and setting NULL"));
		cdf_mem_free(session_entry->assocRsp);
		session_entry->assocRsp = NULL;
	}

	session_entry->assocRsp = cdf_mem_malloc(frame_len);
	if (NULL == session_entry->assocRsp) {
		lim_log(mac_ctx, LOGE,
			FL("Unable to allocate memory for assoc res,len=%d"),
			 frame_len);
	} else {
		/*
		 * Store the Assoc response. This is sent
		 * to csr/hdd in join cnf response.
		 */
		cdf_mem_copy(session_entry->assocRsp, body, frame_len);
		session_entry->assocRspLen = frame_len;
	}

#ifdef WLAN_FEATURE_VOWIFI_11R
	lim_update_ric_data(mac_ctx, session_entry, assoc_rsp);
#endif

#ifdef WLAN_FEATURE_ROAM_OFFLOAD
	roam_session =
		&mac_ctx->roam.roamSession[sme_sessionid];
	if (assoc_rsp->FTInfo.R0KH_ID.present) {
		roam_session->ftSmeContext.r0kh_id_len =
			assoc_rsp->FTInfo.R0KH_ID.num_PMK_R0_ID;
		cdf_mem_copy(roam_session->ftSmeContext.r0kh_id,
			assoc_rsp->FTInfo.R0KH_ID.PMK_R0_ID,
			roam_session->ftSmeContext.r0kh_id_len);
	} else {
		roam_session->ftSmeContext.r0kh_id_len = 0;
		cdf_mem_zero(roam_session->ftSmeContext.r0kh_id,
			SIR_ROAM_R0KH_ID_MAX_LEN);
	}
#endif

#ifdef FEATURE_WLAN_ESE
	lim_update_ese_tspec(mac_ctx, session_entry, assoc_rsp);
#endif

	if (assoc_rsp->capabilityInfo.ibss) {
		/*
		 * Received Re/Association Response from peer
		 * with IBSS capability set.
		 * Ignore the frame and wait until Re/assoc
		 * failure timeout.
		 */
		lim_log(mac_ctx, LOGE,
			FL("received Re/AssocRsp frame with IBSS capability"));
		cdf_mem_free(assoc_rsp);
		cdf_mem_free(beacon);
		return;
	}

	if (cfg_get_capability_info(mac_ctx, &caps, session_entry)
		!= eSIR_SUCCESS) {
		cdf_mem_free(assoc_rsp);
		cdf_mem_free(beacon);
		lim_log(mac_ctx, LOGP, FL("could not retrieve Capabilities "));
		return;
	}
	lim_copy_u16((uint8_t *) &mac_capab, caps);

	/* Stop Association failure timer */
	if (subtype == LIM_ASSOC)
		lim_deactivate_and_change_timer(mac_ctx, eLIM_ASSOC_FAIL_TIMER);
	else
	{
		/* Stop Reassociation failure timer */
#if  defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
		mac_ctx->lim.reAssocRetryAttempt = 0;
		if ((NULL != mac_ctx->lim.pSessionEntry)
		    && (NULL !=
			mac_ctx->lim.pSessionEntry->pLimMlmReassocRetryReq)) {
			cdf_mem_free(
			mac_ctx->lim.pSessionEntry->pLimMlmReassocRetryReq);
			mac_ctx->lim.pSessionEntry->pLimMlmReassocRetryReq =
				NULL;
		}
#endif
		lim_deactivate_and_change_timer(mac_ctx,
			eLIM_REASSOC_FAIL_TIMER);
	}

	if (assoc_rsp->statusCode != eSIR_MAC_SUCCESS_STATUS
#ifdef WLAN_FEATURE_11W
		&& (session_entry->limRmfEnabled ||
			assoc_rsp->statusCode != eSIR_MAC_TRY_AGAIN_LATER)
#endif
	    ) {
		/*
		 *Re/Association response was received
		 * either with failure code.
		*/
		lim_log(mac_ctx, LOGE,
			FL("received Re/AssocRsp frame failure code %d"),
			 assoc_rsp->statusCode);
		/*
		 * Need to update 'association failure' error counter
		 * along with STATUS CODE
		 * Return Assoc confirm to SME with received failure code
		*/
		assoc_cnf.resultCode = eSIR_SME_ASSOC_REFUSED;
		/* Delete Pre-auth context for the associated BSS */
		if (lim_search_pre_auth_list(mac_ctx, hdr->sa))
			lim_delete_pre_auth_node(mac_ctx, hdr->sa);
		goto assocReject;
	} else if ((assoc_rsp->aid & 0x3FFF) > 2007) {
		/*
		 * Re/Association response was received
		 * with invalid AID value
		*/
		lim_log(mac_ctx, LOGE, FL("received Re/AssocRsp frame with"
			"invalid aid %X"), assoc_rsp->aid);
		assoc_cnf.resultCode = eSIR_SME_INVALID_ASSOC_RSP_RXED;
		assoc_cnf.protStatusCode = eSIR_MAC_UNSPEC_FAILURE_STATUS;
		/* Send advisory Disassociation frame to AP */
		lim_send_disassoc_mgmt_frame(mac_ctx,
			eSIR_MAC_UNSPEC_FAILURE_REASON,
			hdr->sa, session_entry, false);
		goto assocReject;
	}
	/*
	 * Association Response received with success code
	 * Set the link state to POSTASSOC now that we have received
	 * assoc/reassoc response
	 * NOTE: for BTAMP case, it is being handled in
	 * lim_process_mlm_assoc_req
	 */
#ifdef WLAN_FEATURE_11W
	if (session_entry->limRmfEnabled &&
		assoc_rsp->statusCode == eSIR_MAC_TRY_AGAIN_LATER) {
		if (assoc_rsp->TimeoutInterval.present &&
		(assoc_rsp->TimeoutInterval.timeoutType ==
			SIR_MAC_TI_TYPE_ASSOC_COMEBACK)) {
			uint16_t timeout_value =
				assoc_rsp->TimeoutInterval.timeoutValue;
			if (timeout_value < 10) {
				/*
				 * if this value is less than 10 then our timer
				 * will fail to start and due to this we will
				 * never re-attempt. Better modify the timer
				 * value here.
				 */
				timeout_value = 10;
			}
			lim_log(mac_ctx, LOG1,
				FL("ASSOC res with eSIR_MAC_TRY_AGAIN_LATER "
				" recvd.Starting timer to wait timeout=%d."),
				timeout_value);
			if (CDF_STATUS_SUCCESS !=
				cdf_mc_timer_start(
					&session_entry->pmfComebackTimer,
					timeout_value)) {
				lim_log(mac_ctx, LOGE,
					FL("Failed to start comeback timer."));
			}
		} else {
			lim_log(mac_ctx, LOGW,
				FL("ASSOC resp with try again event recvd. "
				"But try again time interval IE is wrong."));
		}
		cdf_mem_free(beacon);
		cdf_mem_free(assoc_rsp);
		return;
	}
#endif
	if (!((session_entry->bssType == eSIR_BTAMP_STA_MODE) ||
		((session_entry->bssType == eSIR_BTAMP_AP_MODE) &&
		LIM_IS_BT_AMP_STA_ROLE(session_entry)))) {
		if (lim_set_link_state
			(mac_ctx, eSIR_LINK_POSTASSOC_STATE,
			session_entry->bssId,
			session_entry->selfMacAddr, NULL,
			NULL) != eSIR_SUCCESS) {
			lim_log(mac_ctx, LOGE,
				FL("Set link state to POSTASSOC failed"));
			cdf_mem_free(beacon);
			cdf_mem_free(assoc_rsp);
			return;
		}
	}
	if (subtype == LIM_REASSOC) {
		lim_log
		(mac_ctx, LOG1, FL("Successfully Reassociated with BSS"));
#ifdef FEATURE_WLAN_DIAG_SUPPORT
	lim_diag_event_report(mac_ctx, WLAN_PE_DIAG_ROAM_ASSOC_COMP_EVENT,
			      session_entry, eSIR_SUCCESS, eSIR_SUCCESS);
#endif
#ifdef FEATURE_WLAN_ESE
	if (assoc_rsp->tsmPresent)
		lim_update_ese_tsm(mac_ctx, session_entry, assoc_rsp);
#endif
		if (session_entry->pLimMlmJoinReq) {
			cdf_mem_free(session_entry->pLimMlmJoinReq);
			session_entry->pLimMlmJoinReq = NULL;
		}

		session_entry->limAssocResponseData = (void *)assoc_rsp;
		/*
		 * Store the ReAssocRsp Frame in DphTable
		 * to be used during processing DelSta and
		 * DelBss to send AddBss again
		 */
		sta_ds =
			dph_get_hash_entry(mac_ctx, DPH_STA_HASH_INDEX_PEER,
				&session_entry->dph.dphHashTable);

		if (!sta_ds) {
			lim_log(mac_ctx, LOGE,
				FL("could not get hash entry at DPH for"));
			lim_print_mac_addr(mac_ctx, hdr->sa, LOGE);
			assoc_cnf.resultCode =
				eSIR_SME_INVALID_ASSOC_RSP_RXED;
			assoc_cnf.protStatusCode =
				eSIR_MAC_UNSPEC_FAILURE_STATUS;

			/* Send advisory Disassociation frame to AP */
			lim_send_disassoc_mgmt_frame(mac_ctx,
				eSIR_MAC_UNSPEC_FAILURE_REASON, hdr->sa,
				session_entry, false);
			goto assocReject;
		}
#if defined(WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
		if (session_entry->limMlmState ==
		    eLIM_MLM_WT_FT_REASSOC_RSP_STATE) {
#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
			lim_log(mac_ctx, LOG1, FL("Sending self sta"));
#endif
			lim_update_assoc_sta_datas(mac_ctx, sta_ds, assoc_rsp,
				session_entry);
			/* Store assigned AID for TIM processing */
			session_entry->limAID = assoc_rsp->aid & 0x3FFF;
			/* Downgrade the EDCA parameters if needed */
			lim_set_active_edca_params(mac_ctx,
				session_entry->gLimEdcaParams,
				session_entry);
			/* Send the active EDCA parameters to HAL */
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
			if (!session_entry->bRoamSynchInProgress) {
#endif
			lim_send_edca_params(mac_ctx,
				session_entry->gLimEdcaParamsActive,
				sta_ds->bssId);
#ifdef WLAN_FEATURE_ROAM_OFFLOAD
		}
#endif
			lim_add_ft_sta_self(mac_ctx, (assoc_rsp->aid & 0x3FFF),
				session_entry);
			cdf_mem_free(beacon);
			return;
		}
#endif /* WLAN_FEATURE_VOWIFI_11R */

		/*
		 * If we're re-associating to the same BSS,
		 * we don't want to invoke delete STA, delete
		 * BSS, as that would remove the already
		 * established TSPEC. Just go ahead and re-add
		 * the BSS, STA with new capability information.
		 * However, if we're re-associating to a different
		 * BSS, then follow thru with del STA, del BSS,
		 * add BSS, add STA.
		 */
		if (sir_compare_mac_addr(session_entry->bssId,
			session_entry->limReAssocbssId))
			lim_handle_add_bss_in_re_assoc_context(mac_ctx, sta_ds,
				 session_entry);
		else {
			/*
			 * reset the uapsd mask settings since
			 * we're re-associating to new AP
			 */
			session_entry->gUapsdPerAcDeliveryEnableMask = 0;
			session_entry->gUapsdPerAcTriggerEnableMask = 0;

			if (lim_cleanup_rx_path(mac_ctx, sta_ds, session_entry)
				!= eSIR_SUCCESS) {
				lim_log(mac_ctx, LOGE,
					FL("Could not cleanup the rx path"));
				goto assocReject;
			}
		}
		cdf_mem_free(beacon);
		return;
	}
	lim_log(mac_ctx, LOG1,
		FL("Successfully Associated with BSS " MAC_ADDRESS_STR),
		 MAC_ADDR_ARRAY(hdr->sa));
#ifdef FEATURE_WLAN_ESE
	if (session_entry->eseContext.tsm.tsmInfo.state)
		session_entry->eseContext.tsm.tsmMetrics.RoamingCount = 0;
#endif
	/* Store assigned AID for TIM processing */
	session_entry->limAID = assoc_rsp->aid & 0x3FFF;

	/* STA entry was created during pre-assoc state. */
	sta_ds = dph_get_hash_entry(mac_ctx, DPH_STA_HASH_INDEX_PEER,
			&session_entry->dph.dphHashTable);
	if (sta_ds == NULL) {
		/* Could not add hash table entry */
		lim_log(mac_ctx, LOGE, FL("could not get hash entry at DPH "));
		lim_print_mac_addr(mac_ctx, hdr->sa, LOGE);
		assoc_cnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
		assoc_cnf.protStatusCode = eSIR_SME_SUCCESS;
		lim_post_sme_message(mac_ctx, LIM_MLM_ASSOC_CNF,
			(uint32_t *) &assoc_cnf);
		cdf_mem_free(assoc_rsp);
		cdf_mem_free(beacon);
		return;
	}
	/* Delete Pre-auth context for the associated BSS */
	if (lim_search_pre_auth_list(mac_ctx, hdr->sa))
		lim_delete_pre_auth_node(mac_ctx, hdr->sa);

	lim_update_assoc_sta_datas(mac_ctx, sta_ds, assoc_rsp, session_entry);
	/*
	 * Extract the AP capabilities from the beacon that
	 * was received earlier
	*/
	ie_len = lim_get_ielen_from_bss_description(
		&session_entry->pLimJoinReq->bssDescription);
	lim_extract_ap_capabilities(mac_ctx,
		(uint8_t *) session_entry->pLimJoinReq->bssDescription.ieFields,
		ie_len,
		beacon);

	if (mac_ctx->lim.gLimProtectionControl !=
		WNI_CFG_FORCE_POLICY_PROTECTION_DISABLE)
		lim_decide_sta_protection_on_assoc(mac_ctx, beacon,
			session_entry);

	if (beacon->erpPresent) {
		if (beacon->erpIEInfo.barkerPreambleMode)
			session_entry->beaconParams.fShortPreamble = false;
		else
			session_entry->beaconParams.fShortPreamble = true;
	}

#ifdef FEATURE_WLAN_DIAG_SUPPORT
	lim_diag_event_report(mac_ctx, WLAN_PE_DIAG_CONNECTED, session_entry,
			      eSIR_SUCCESS, eSIR_SUCCESS);
#endif
	if (assoc_rsp->QosMapSet.present)
		cdf_mem_copy(&session_entry->QosMapSet,
			&assoc_rsp->QosMapSet, sizeof(tSirQosMapSet));
	 else
		cdf_mem_zero(&session_entry->QosMapSet, sizeof(tSirQosMapSet));

	lim_update_stads_ext_cap(mac_ctx, session_entry, assoc_rsp, sta_ds);
	/* Update the BSS Entry, this entry was added during preassoc. */
	if (eSIR_SUCCESS == lim_sta_send_add_bss(mac_ctx, assoc_rsp,
			beacon,
			&session_entry->pLimJoinReq->bssDescription, true,
			 session_entry)) {
		cdf_mem_free(assoc_rsp);
		cdf_mem_free(beacon);
		return;
	} else {
		lim_log(mac_ctx, LOGE, FL("could not update the bss entry"));
		assoc_cnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
		assoc_cnf.protStatusCode = eSIR_MAC_UNSPEC_FAILURE_STATUS;
	}

assocReject:
	if ((subtype == LIM_ASSOC)
#ifdef WLAN_FEATURE_VOWIFI_11R
		|| ((subtype == LIM_REASSOC)
		&& (session_entry->limMlmState ==
		    eLIM_MLM_WT_FT_REASSOC_RSP_STATE))
#endif
	    ) {
		lim_log(mac_ctx, LOGE, FL("Assoc Rejected by the peer. "
			"mlmestate: %d sessionid %d Reason: %d MACADDR:"
			MAC_ADDRESS_STR),
			session_entry->limMlmState,
			session_entry->peSessionId,
			assoc_cnf.resultCode, MAC_ADDR_ARRAY(hdr->sa));
		session_entry->limMlmState = eLIM_MLM_IDLE_STATE;
		MTRACE(mac_trace(mac_ctx, TRACE_CODE_MLM_STATE,
			session_entry->peSessionId,
			session_entry->limMlmState));
		if (session_entry->pLimMlmJoinReq) {
			cdf_mem_free(session_entry->pLimMlmJoinReq);
			session_entry->pLimMlmJoinReq = NULL;
		}
		if (subtype == LIM_ASSOC) {
			lim_post_sme_message(mac_ctx, LIM_MLM_ASSOC_CNF,
				(uint32_t *) &assoc_cnf);
		}
#ifdef WLAN_FEATURE_VOWIFI_11R
		else {
			assoc_cnf.resultCode = eSIR_SME_FT_REASSOC_FAILURE;
			lim_post_sme_message(mac_ctx, LIM_MLM_REASSOC_CNF,
					(uint32_t *)&assoc_cnf);
		}
#endif
	} else {
		lim_restore_pre_reassoc_state(mac_ctx,
			eSIR_SME_REASSOC_REFUSED,
			assoc_cnf.protStatusCode,
			session_entry);
	}

	cdf_mem_free(beacon);
	cdf_mem_free(assoc_rsp);
	return;
}