/**
 @brief WDI_STATableAddSta - Function to Add Station

 
 @param  pWDICtx:     pointer to the WLAN DAL context 
         pwdiParam:   station parameters  
  
 @see
 @return Result of the function call
*/
WDI_Status
WDI_STATableAddSta
(
    WDI_ControlBlockType*  pWDICtx,
    WDI_AddStaParams*      pwdiParam
)
{
    wpt_uint8        ucSTAIdx  = 0;
    WDI_StaStruct*   pSTATable = (WDI_StaStruct*) pWDICtx->staTable;
    /*- - - -  - - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - */

    /*-----------------------------------------------------------------------
      Sanity check
      - station ids are allocated by the HAL located on RIVA SS - they must
      always be valid 
    -----------------------------------------------------------------------*/
    if (( pwdiParam->ucSTAIdx  == WDI_STA_INVALID_IDX) ||
        ( pwdiParam->ucSTAIdx >= pWDICtx->ucMaxStations ))
    {
      WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                "Station id sent by HAL is invalid - not OK"); 
      WDI_ASSERT(0); 
      return WDI_STATUS_E_FAILURE; 
    }
    
    ucSTAIdx =  pwdiParam->ucSTAIdx;

    /*Since we are not the allocator of STA Ids but HAL is - just set flag to
      valid*/
    pSTATable[ucSTAIdx].valid = 1;     
    
    
    // Save the STA type - this is used for lookup
    WDI_STATableSetStaType(pWDICtx, ucSTAIdx, pwdiParam->ucStaType);
    WDI_STATableSetStaQosEnabled(pWDICtx, ucSTAIdx, 
          (wpt_uint8)(pwdiParam->ucWmmEnabled | pwdiParam->ucHTCapable) );

#ifdef WLAN_PERF
    pWDICtx->uBdSigSerialNum ++;
#endif
    
    wpalMemoryCopy(pSTATable[ucSTAIdx].macBSSID, 
                   pwdiParam->macBSSID, WDI_MAC_ADDR_LEN);

    /*------------------------------------------------------------------------
      Set DPU Related Information 
    ------------------------------------------------------------------------*/
    pSTATable[ucSTAIdx].dpuIndex              = pwdiParam->dpuIndex; 
    pSTATable[ucSTAIdx].dpuSig                = pwdiParam->dpuSig; 

    pSTATable[ucSTAIdx].bcastDpuIndex         = pwdiParam->bcastDpuIndex; 
    pSTATable[ucSTAIdx].bcastDpuSignature     = pwdiParam->bcastDpuSignature; 

    pSTATable[ucSTAIdx].bcastMgmtDpuIndex     = pwdiParam->bcastMgmtDpuIndex; 
    pSTATable[ucSTAIdx].bcastMgmtDpuSignature = pwdiParam->bcastMgmtDpuSignature; 

    /*Robust Mgmt Frame enabled */
    pSTATable[ucSTAIdx].rmfEnabled            = pwdiParam->ucRmfEnabled;

    pSTATable[ucSTAIdx].bssIdx                = pwdiParam->ucBSSIdx;

    /* Now update the STA entry with the new MAC address */
    if(WDI_STATUS_SUCCESS != WDI_STATableSetStaAddr( pWDICtx, 
                                                     ucSTAIdx, 
                                                     pwdiParam->staMacAddr))
    {
       WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                 "Failed to update station entry - internal failure");
       WDI_ASSERT(0);
       return WDI_STATUS_E_FAILURE; 
    }

    /* Now update the STA entry with the new BSSID address */
    if(WDI_STATUS_SUCCESS != WDI_STATableSetBSSID( pWDICtx, 
                                                     ucSTAIdx, 
                                                     pwdiParam->macBSSID))
    {
       WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                 "Failed to update station entry - internal failure");
       WDI_ASSERT(0);
       return WDI_STATUS_E_FAILURE; 
    }

    return WDI_STATUS_SUCCESS;
}/*WDI_AddSta*/
WDI_Status
WDI_STATableAddSta
(
    WDI_ControlBlockType*  pWDICtx,
    WDI_AddStaParams*      pwdiParam
)
{
    wpt_uint8        ucSTAIdx  = 0;
    WDI_StaStruct*   pSTATable = (WDI_StaStruct*) pWDICtx->staTable;
    

    if (( pwdiParam->ucSTAIdx  == WDI_STA_INVALID_IDX) ||
        ( pwdiParam->ucSTAIdx >= pWDICtx->ucMaxStations ))
    {
      WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                "Station id sent by HAL is invalid - not OK"); 
      WDI_ASSERT(0); 
      return WDI_STATUS_E_FAILURE; 
    }
    
    ucSTAIdx =  pwdiParam->ucSTAIdx;

    pSTATable[ucSTAIdx].valid = 1;     
    
    
    
    WDI_STATableSetStaType(pWDICtx, ucSTAIdx, pwdiParam->ucStaType);
    WDI_STATableSetStaQosEnabled(pWDICtx, ucSTAIdx, 
          (wpt_uint8)(pwdiParam->ucWmmEnabled | pwdiParam->ucHTCapable) );

#ifdef WLAN_PERF
    pWDICtx->uBdSigSerialNum ++;
#endif
    
    wpalMemoryCopy(pSTATable[ucSTAIdx].macBSSID, 
                   pwdiParam->macBSSID, WDI_MAC_ADDR_LEN);

    pSTATable[ucSTAIdx].dpuIndex              = pwdiParam->dpuIndex; 
    pSTATable[ucSTAIdx].dpuSig                = pwdiParam->dpuSig; 

    pSTATable[ucSTAIdx].bcastDpuIndex         = pwdiParam->bcastDpuIndex; 
    pSTATable[ucSTAIdx].bcastDpuSignature     = pwdiParam->bcastDpuSignature; 

    pSTATable[ucSTAIdx].bcastMgmtDpuIndex     = pwdiParam->bcastMgmtDpuIndex; 
    pSTATable[ucSTAIdx].bcastMgmtDpuSignature = pwdiParam->bcastMgmtDpuSignature; 

    
    pSTATable[ucSTAIdx].rmfEnabled            = pwdiParam->ucRmfEnabled;

    pSTATable[ucSTAIdx].bssIdx                = pwdiParam->ucBSSIdx;

    
    if(WDI_STATUS_SUCCESS != WDI_STATableSetStaAddr( pWDICtx, 
                                                     ucSTAIdx, 
                                                     pwdiParam->staMacAddr))
    {
       WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                 "Failed to update station entry - internal failure");
       WDI_ASSERT(0);
       return WDI_STATUS_E_FAILURE; 
    }

    
    if(WDI_STATUS_SUCCESS != WDI_STATableSetBSSID( pWDICtx, 
                                                     ucSTAIdx, 
                                                     pwdiParam->macBSSID))
    {
       WPAL_TRACE(eWLAN_MODULE_DAL_CTRL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                 "Failed to update station entry - internal failure");
       WDI_ASSERT(0);
       return WDI_STATUS_E_FAILURE; 
    }

    return WDI_STATUS_SUCCESS;
}