linux/drivers/staging/csr/unifi_pdu_processing.c
<<
>>
Prefs
   1/*
   2 * ---------------------------------------------------------------------------
   3 * FILE:     unifi_pdu_processing.c
   4 *
   5 * PURPOSE:
   6 *      This file provides the PDU handling functionality before it gets sent to unfi and after
   7 *      receiving a PDU from unifi
   8 *
   9 * Copyright (C) 2010 by Cambridge Silicon Radio Ltd.
  10 *
  11 * Refer to LICENSE.txt included with this source code for details on
  12 * the license terms.
  13 *
  14 * ---------------------------------------------------------------------------
  15 */
  16
  17#include <linux/version.h>
  18#include <linux/types.h>
  19#include <linux/etherdevice.h>
  20#include <linux/vmalloc.h>
  21
  22#include "csr_wifi_hip_unifi.h"
  23#include "csr_wifi_hip_conversions.h"
  24#include "csr_time.h"
  25#include "unifi_priv.h"
  26#include <net/pkt_sched.h>
  27
  28#ifdef CSR_SUPPORT_SME
  29static void _update_buffered_pkt_params_after_alignment(unifi_priv_t *priv, bulk_data_param_t *bulkdata,
  30                                                        tx_buffered_packets_t* buffered_pkt)
  31{
  32    struct sk_buff *skb ;
  33    u32 align_offset;
  34
  35    if (priv == NULL || bulkdata == NULL || buffered_pkt == NULL){
  36        return;
  37    }
  38
  39    skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
  40    align_offset = (u32)(long)(bulkdata->d[0].os_data_ptr) & (CSR_WIFI_ALIGN_BYTES-1);
  41    if(align_offset){
  42        skb_pull(skb,align_offset);
  43    }
  44
  45    buffered_pkt->bulkdata.os_data_ptr = bulkdata->d[0].os_data_ptr;
  46    buffered_pkt->bulkdata.data_length = bulkdata->d[0].data_length;
  47    buffered_pkt->bulkdata.os_net_buf_ptr = bulkdata->d[0].os_net_buf_ptr;
  48    buffered_pkt->bulkdata.net_buf_length = bulkdata->d[0].net_buf_length;
  49}
  50#endif
  51
  52void
  53unifi_frame_ma_packet_req(unifi_priv_t *priv, CSR_PRIORITY priority,
  54                          CSR_RATE TransmitRate, CSR_CLIENT_TAG hostTag,
  55                          u16 interfaceTag, CSR_TRANSMISSION_CONTROL transmissionControl,
  56                          CSR_PROCESS_ID leSenderProcessId, u8 *peerMacAddress,
  57                          CSR_SIGNAL *signal)
  58{
  59
  60    CSR_MA_PACKET_REQUEST *req = &signal->u.MaPacketRequest;
  61    netInterface_priv_t *interfacePriv;
  62    u8 ba_session_idx = 0;
  63    ba_session_tx_struct *ba_session = NULL;
  64    u8 *ba_addr = NULL;
  65
  66    interfacePriv = priv->interfacePriv[interfaceTag];
  67
  68        unifi_trace(priv, UDBG5,
  69                "In unifi_frame_ma_packet_req, Frame for Peer: %pMF\n",
  70                peerMacAddress);
  71    signal->SignalPrimitiveHeader.SignalId = CSR_MA_PACKET_REQUEST_ID;
  72    signal->SignalPrimitiveHeader.ReceiverProcessId = 0;
  73    signal->SignalPrimitiveHeader.SenderProcessId = leSenderProcessId;
  74
  75    /* Fill the MA-PACKET.req */
  76    req->Priority = priority;
  77    unifi_trace(priv, UDBG3, "Tx Frame with Priority: 0x%x\n", req->Priority);
  78
  79    /* A value of 0 is used for auto selection of rates. But for P2P GO case
  80     * for action frames the rate is governed by SME. Hence instead of 0,
  81     * the rate is filled in with the value passed here
  82     */
  83    req->TransmitRate = TransmitRate;
  84
  85    /* packets from netdev then no confirm required but packets from
  86     * Nme/Sme eapol data frames requires the confirmation
  87     */
  88    req->TransmissionControl = transmissionControl;
  89    req->VirtualInterfaceIdentifier =
  90           uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag);
  91    memcpy(req->Ra.x, peerMacAddress, ETH_ALEN);
  92
  93    if (hostTag == 0xffffffff) {
  94        req->HostTag = interfacePriv->tag++;
  95        req->HostTag |= 0x40000000;
  96        unifi_trace(priv, UDBG3, "new host tag assigned = 0x%x\n", req->HostTag);
  97        interfacePriv->tag &= 0x0fffffff;
  98    } else {
  99        req->HostTag = hostTag;
 100        unifi_trace(priv, UDBG3, "host tag got from SME  = 0x%x\n", req->HostTag);
 101    }
 102    /* check if BA session exists for the peer MAC address on same tID */
 103    if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
 104       interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO){
 105        ba_addr = peerMacAddress;
 106    }else{
 107        ba_addr = interfacePriv->bssid.a;
 108    }
 109    for (ba_session_idx=0; ba_session_idx < MAX_SUPPORTED_BA_SESSIONS_TX; ba_session_idx++){
 110        ba_session = interfacePriv->ba_session_tx[ba_session_idx];
 111        if (ba_session){
 112           if ((!memcmp(ba_session->macAddress.a, ba_addr, ETH_ALEN)) && (ba_session->tID == priority)){
 113                req->TransmissionControl |= CSR_ALLOW_BA;
 114                break;
 115            }
 116        }
 117    }
 118
 119    unifi_trace(priv, UDBG5, "leaving unifi_frame_ma_packet_req\n");
 120}
 121
 122#ifdef CSR_SUPPORT_SME
 123
 124#define TRANSMISSION_CONTROL_TRIGGER_MASK 0x0001
 125#define TRANSMISSION_CONTROL_EOSP_MASK 0x0002
 126
 127static
 128int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered_pkt,
 129            CsrWifiRouterCtrlStaInfo_t *staRecord,u8 moreData , u8 eosp)
 130{
 131
 132    CSR_SIGNAL signal;
 133    bulk_data_param_t bulkdata;
 134    int result;
 135    u8 toDs, fromDs, macHeaderLengthInBytes = MAC_HEADER_SIZE;
 136    u8 *qc;
 137    u16 *fc = (u16*)(buffered_pkt->bulkdata.os_data_ptr);
 138    unsigned long lock_flags;
 139    unifi_trace(priv, UDBG3, "frame_and_send_queued_pdu with moreData: %d , EOSP: %d\n",moreData,eosp);
 140    unifi_frame_ma_packet_req(priv, buffered_pkt->priority, buffered_pkt->rate, buffered_pkt->hostTag,
 141               buffered_pkt->interfaceTag, buffered_pkt->transmissionControl,
 142               buffered_pkt->leSenderProcessId, buffered_pkt->peerMacAddress.a, &signal);
 143    bulkdata.d[0].os_data_ptr = buffered_pkt->bulkdata.os_data_ptr;
 144    bulkdata.d[0].data_length = buffered_pkt->bulkdata.data_length;
 145    bulkdata.d[0].os_net_buf_ptr = buffered_pkt->bulkdata.os_net_buf_ptr;
 146    bulkdata.d[0].net_buf_length = buffered_pkt->bulkdata.net_buf_length;
 147    bulkdata.d[1].os_data_ptr = NULL;
 148    bulkdata.d[1].data_length = 0;
 149    bulkdata.d[1].os_net_buf_ptr =0;
 150    bulkdata.d[1].net_buf_length =0;
 151
 152    if(moreData) {
 153        *fc |= cpu_to_le16(IEEE802_11_FC_MOREDATA_MASK);
 154    } else {
 155        *fc &= cpu_to_le16(~IEEE802_11_FC_MOREDATA_MASK);
 156    }
 157
 158    if((staRecord != NULL)&& (staRecord->wmmOrQosEnabled == TRUE))
 159    {
 160        unifi_trace(priv, UDBG3, "frame_and_send_queued_pdu WMM Enabled: %d \n",staRecord->wmmOrQosEnabled);
 161
 162        toDs = (*fc & cpu_to_le16(IEEE802_11_FC_TO_DS_MASK))?1 : 0;
 163        fromDs = (*fc & cpu_to_le16(IEEE802_11_FC_FROM_DS_MASK))? 1: 0;
 164
 165        switch(le16_to_cpu(*fc) & IEEE80211_FC_SUBTYPE_MASK)
 166        {
 167            case IEEE802_11_FC_TYPE_QOS_DATA & IEEE80211_FC_SUBTYPE_MASK:
 168            case IEEE802_11_FC_TYPE_QOS_NULL & IEEE80211_FC_SUBTYPE_MASK:
 169                /* If both are set then the Address4 exists (only for AP) */
 170                if (fromDs && toDs) {
 171                    /* 6 is the size of Address4 field */
 172                    macHeaderLengthInBytes += (QOS_CONTROL_HEADER_SIZE + 6);
 173                } else {
 174                    macHeaderLengthInBytes += QOS_CONTROL_HEADER_SIZE;
 175                }
 176
 177                /* If order bit set then HT control field is the part of MAC header */
 178                if (*fc & cpu_to_le16(IEEE80211_FC_ORDER_MASK)) {
 179                    macHeaderLengthInBytes += HT_CONTROL_HEADER_SIZE;
 180                    qc = (u8*)(buffered_pkt->bulkdata.os_data_ptr + (macHeaderLengthInBytes-6));
 181                } else {
 182                    qc = (u8*)(buffered_pkt->bulkdata.os_data_ptr + (macHeaderLengthInBytes-2));
 183                }
 184                *qc = eosp ? *qc | (1 << 4) : *qc & (~(1 << 4));
 185                break;
 186            default:
 187                if (fromDs && toDs)
 188                    macHeaderLengthInBytes += 6;
 189        }
 190
 191    }
 192    result = ul_send_signal_unpacked(priv, &signal, &bulkdata);
 193    if(result){
 194        _update_buffered_pkt_params_after_alignment(priv, &bulkdata,buffered_pkt);
 195    }
 196
 197 /* Decrement the packet counts queued in driver */
 198    if (result != -ENOSPC) {
 199        /* protect entire counter updation by disabling preemption */
 200        if (!priv->noOfPktQueuedInDriver) {
 201            unifi_error(priv, "packets queued in driver 0 still decrementing\n");
 202        } else {
 203            spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
 204            priv->noOfPktQueuedInDriver--;
 205            spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
 206        }
 207        /* Sta Record is available for all unicast (except genericMgt Frames) & in other case its NULL */
 208        if (staRecord) {
 209            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
 210            if (!staRecord->noOfPktQueued) {
 211                unifi_error(priv, "packets queued in driver per station is 0 still decrementing\n");
 212            } else {
 213                staRecord->noOfPktQueued--;
 214            }
 215            /* if the STA alive probe frame has failed then reset the saved host tag */
 216            if (result){
 217                if (staRecord->nullDataHostTag == buffered_pkt->hostTag){
 218                    staRecord->nullDataHostTag = INVALID_HOST_TAG;
 219                }
 220            }
 221            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
 222        }
 223
 224    }
 225    return result;
 226}
 227#ifdef CSR_SUPPORT_SME
 228static
 229void set_eosp_transmit_ctrl(unifi_priv_t *priv, struct list_head *txList)
 230{
 231    /* dequeue the tx data packets from the appropriate queue */
 232    tx_buffered_packets_t *tx_q_item = NULL;
 233    struct list_head *listHead;
 234    struct list_head *placeHolder;
 235    unsigned long lock_flags;
 236
 237
 238    unifi_trace(priv, UDBG5, "entering set_eosp_transmit_ctrl\n");
 239    /* check for list empty */
 240    if (list_empty(txList)) {
 241        unifi_warning(priv, "In set_eosp_transmit_ctrl, the list is empty\n");
 242        return;
 243    }
 244
 245    /* return the last node , and modify it. */
 246
 247    spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
 248    list_for_each_prev_safe(listHead, placeHolder, txList) {
 249        tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
 250        tx_q_item->transmissionControl |= TRANSMISSION_CONTROL_EOSP_MASK;
 251        tx_q_item->transmissionControl = (tx_q_item->transmissionControl & ~(CSR_NO_CONFIRM_REQUIRED));
 252        unifi_trace(priv, UDBG1,
 253                "set_eosp_transmit_ctrl Transmission Control = 0x%x hostTag = 0x%x \n",tx_q_item->transmissionControl,tx_q_item->hostTag);
 254        unifi_trace(priv,UDBG3,"in set_eosp_transmit_ctrl no.of buffered frames %d\n",priv->noOfPktQueuedInDriver);
 255        break;
 256    }
 257    spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
 258    unifi_trace(priv, UDBG1,"List Empty %d\n",list_empty(txList));
 259    unifi_trace(priv, UDBG5, "leaving set_eosp_transmit_ctrl\n");
 260    return;
 261}
 262
 263static
 264void send_vif_availibility_rsp(unifi_priv_t *priv,CSR_VIF_IDENTIFIER vif,CSR_RESULT_CODE resultCode)
 265{
 266    CSR_SIGNAL signal;
 267    CSR_MA_VIF_AVAILABILITY_RESPONSE *rsp;
 268    bulk_data_param_t *bulkdata = NULL;
 269    int r;
 270
 271    unifi_trace(priv, UDBG3, "send_vif_availibility_rsp : invoked with resultCode = %d \n", resultCode);
 272
 273    memset(&signal,0,sizeof(CSR_SIGNAL));
 274    rsp = &signal.u.MaVifAvailabilityResponse;
 275    rsp->VirtualInterfaceIdentifier = vif;
 276    rsp->ResultCode = resultCode;
 277    signal.SignalPrimitiveHeader.SignalId = CSR_MA_VIF_AVAILABILITY_RESPONSE_ID;
 278    signal.SignalPrimitiveHeader.ReceiverProcessId = 0;
 279    signal.SignalPrimitiveHeader.SenderProcessId = priv->netdev_client->sender_id;
 280
 281    /* Send the signal to UniFi */
 282    r = ul_send_signal_unpacked(priv, &signal, bulkdata);
 283    if(r) {
 284        unifi_error(priv,"Availibility response sending failed %x status %d\n",vif,r);
 285    }
 286    else {
 287        unifi_trace(priv, UDBG3, "send_vif_availibility_rsp : status = %d \n", r);
 288    }
 289}
 290#endif
 291
 292static
 293void verify_and_accomodate_tx_packet(unifi_priv_t *priv)
 294{
 295    tx_buffered_packets_t *tx_q_item;
 296    unsigned long lock_flags;
 297    struct list_head *listHead, *list;
 298    struct list_head *placeHolder;
 299    u8 i, j,eospFramedeleted=0;
 300    u8 thresholdExcedeDueToBroadcast = TRUE;
 301    /* it will be made it interface Specific in the future when multi interfaces are supported ,
 302    right now interface 0 is considered */
 303    netInterface_priv_t *interfacePriv = priv->interfacePriv[0];
 304    CsrWifiRouterCtrlStaInfo_t *staInfo = NULL;
 305
 306    unifi_trace(priv, UDBG3, "entering verify_and_accomodate_tx_packet\n");
 307
 308    for(i = 0; i < UNIFI_MAX_CONNECTIONS; i++) {
 309        staInfo = interfacePriv->staInfo[i];
 310            if (staInfo && (staInfo->noOfPktQueued >= CSR_WIFI_DRIVER_MAX_PKT_QUEUING_THRESHOLD_PER_PEER)) {
 311            /* remove the first(oldest) packet from the all the access catogory, since data
 312             * packets for station record crossed the threshold limit (64 for AP supporting
 313             * 8 peers)
 314             */
 315            unifi_trace(priv,UDBG3,"number of station pkts queued=  %d for sta id = %d\n", staInfo->noOfPktQueued, staInfo->aid);
 316            for(j = 0; j < MAX_ACCESS_CATOGORY; j++) {
 317                list = &staInfo->dataPdu[j];
 318                spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
 319                list_for_each_safe(listHead, placeHolder, list) {
 320                    tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
 321                    list_del(listHead);
 322                    thresholdExcedeDueToBroadcast = FALSE;
 323                    unifi_net_data_free(priv, &tx_q_item->bulkdata);
 324                    kfree(tx_q_item);
 325                    tx_q_item = NULL;
 326                    if (!priv->noOfPktQueuedInDriver) {
 327                        unifi_error(priv, "packets queued in driver 0 still decrementing in %s\n", __FUNCTION__);
 328                    } else {
 329                        /* protection provided by spinlock */
 330                        priv->noOfPktQueuedInDriver--;
 331
 332                    }
 333                    /* Sta Record is available for all unicast (except genericMgt Frames) & in other case its NULL */
 334                    if (!staInfo->noOfPktQueued) {
 335                        unifi_error(priv, "packets queued in driver per station is 0 still decrementing in %s\n", __FUNCTION__);
 336                    } else {
 337                        spin_lock(&priv->staRecord_lock);
 338                        staInfo->noOfPktQueued--;
 339                        spin_unlock(&priv->staRecord_lock);
 340                    }
 341                    break;
 342                }
 343                spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
 344            }
 345        }
 346    }
 347    if (thresholdExcedeDueToBroadcast &&  interfacePriv->noOfbroadcastPktQueued > CSR_WIFI_DRIVER_MINIMUM_BROADCAST_PKT_THRESHOLD ) {
 348        /* Remove the packets from genericMulticastOrBroadCastFrames queue
 349         * (the max packets in driver is reached due to broadcast/multicast frames)
 350         */
 351        spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
 352        list_for_each_safe(listHead, placeHolder, &interfacePriv->genericMulticastOrBroadCastFrames) {
 353            tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
 354            if(eospFramedeleted){
 355                tx_q_item->transmissionControl |= TRANSMISSION_CONTROL_EOSP_MASK;
 356                tx_q_item->transmissionControl = (tx_q_item->transmissionControl & ~(CSR_NO_CONFIRM_REQUIRED));
 357                unifi_trace(priv, UDBG1,"updating eosp for next packet hostTag:= 0x%x ",tx_q_item->hostTag);
 358                eospFramedeleted =0;
 359                break;
 360            }
 361
 362            if(tx_q_item->transmissionControl & TRANSMISSION_CONTROL_EOSP_MASK ){
 363               eospFramedeleted = 1;
 364            }
 365            unifi_trace(priv,UDBG1, "freeing of multicast packets ToC = 0x%x hostTag = 0x%x \n",tx_q_item->transmissionControl,tx_q_item->hostTag);
 366            list_del(listHead);
 367            unifi_net_data_free(priv, &tx_q_item->bulkdata);
 368            kfree(tx_q_item);
 369            priv->noOfPktQueuedInDriver--;
 370            spin_lock(&priv->staRecord_lock);
 371            interfacePriv->noOfbroadcastPktQueued--;
 372            spin_unlock(&priv->staRecord_lock);
 373            if(!eospFramedeleted){
 374                break;
 375            }
 376        }
 377        spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
 378    }
 379    unifi_trace(priv, UDBG3, "leaving verify_and_accomodate_tx_packet\n");
 380}
 381
 382static
 383CsrResult enque_tx_data_pdu(unifi_priv_t *priv, bulk_data_param_t *bulkdata,
 384                            struct list_head *list, CSR_SIGNAL *signal,
 385                            u8 requeueOnSamePos)
 386{
 387
 388    /* queue the tx data packets on to appropriate queue */
 389    CSR_MA_PACKET_REQUEST *req = &signal->u.MaPacketRequest;
 390    tx_buffered_packets_t *tx_q_item;
 391    unsigned long lock_flags;
 392
 393    unifi_trace(priv, UDBG5, "entering enque_tx_data_pdu\n");
 394    if(!list) {
 395       unifi_error(priv,"List is not specified\n");
 396       return CSR_RESULT_FAILURE;
 397    }
 398
 399    /* Removes aged packets & adds the incoming packet */
 400    if (priv->noOfPktQueuedInDriver >= CSR_WIFI_DRIVER_SUPPORT_FOR_MAX_PKT_QUEUEING) {
 401        unifi_trace(priv,UDBG3,"number of pkts queued=  %d \n", priv->noOfPktQueuedInDriver);
 402        verify_and_accomodate_tx_packet(priv);
 403    }
 404
 405
 406
 407    tx_q_item = (tx_buffered_packets_t *)kmalloc(sizeof(tx_buffered_packets_t), GFP_ATOMIC);
 408    if (tx_q_item == NULL) {
 409        unifi_error(priv,
 410                "Failed to allocate %d bytes for tx packet record\n",
 411                sizeof(tx_buffered_packets_t));
 412        func_exit();
 413        return CSR_RESULT_FAILURE;
 414    }
 415
 416    /* disable the preemption */
 417    spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
 418    INIT_LIST_HEAD(&tx_q_item->q);
 419    /* fill the tx_q structure members */
 420    tx_q_item->bulkdata.os_data_ptr = bulkdata->d[0].os_data_ptr;
 421    tx_q_item->bulkdata.data_length = bulkdata->d[0].data_length;
 422    tx_q_item->bulkdata.os_net_buf_ptr = bulkdata->d[0].os_net_buf_ptr;
 423    tx_q_item->bulkdata.net_buf_length = bulkdata->d[0].net_buf_length;
 424    tx_q_item->interfaceTag = req->VirtualInterfaceIdentifier & 0xff;
 425    tx_q_item->hostTag = req->HostTag;
 426    tx_q_item->leSenderProcessId = signal->SignalPrimitiveHeader.SenderProcessId;
 427    tx_q_item->transmissionControl = req->TransmissionControl;
 428    tx_q_item->priority = req->Priority;
 429    tx_q_item->rate = req->TransmitRate;
 430    memcpy(tx_q_item->peerMacAddress.a, req->Ra.x, ETH_ALEN);
 431
 432
 433
 434    if (requeueOnSamePos) {
 435        list_add(&tx_q_item->q, list);
 436    } else {
 437        list_add_tail(&tx_q_item->q, list);
 438    }
 439
 440    /* Count of packet queued in driver */
 441    priv->noOfPktQueuedInDriver++;
 442    spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
 443    unifi_trace(priv, UDBG5, "leaving enque_tx_data_pdu\n");
 444    return CSR_RESULT_SUCCESS;
 445}
 446
 447#ifdef CSR_WIFI_REQUEUE_PACKET_TO_HAL
 448CsrResult unifi_reque_ma_packet_request (void *ospriv, u32 host_tag,
 449                                         u16 txStatus, bulk_data_desc_t *bulkDataDesc)
 450{
 451    CsrResult status = CSR_RESULT_SUCCESS;
 452    unifi_priv_t *priv = (unifi_priv_t*)ospriv;
 453    netInterface_priv_t *interfacePriv;
 454    struct list_head *list = NULL;
 455    CsrWifiRouterCtrlStaInfo_t *staRecord = NULL;
 456    bulk_data_param_t bulkData;
 457    CSR_SIGNAL signal;
 458    CSR_PRIORITY priority = 0;
 459    u16 interfaceTag = 0;
 460    unifi_TrafficQueue priority_q;
 461    u16 frameControl = 0, frameType = 0;
 462    unsigned long lock_flags;
 463
 464    interfacePriv = priv->interfacePriv[interfaceTag];
 465
 466    /* If the current mode is not AP or P2PGO then just return failure
 467     * to clear the hip slot
 468     */
 469    if(!((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP) ||
 470        (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO))) {
 471        return CSR_RESULT_FAILURE;
 472    }
 473
 474    unifi_trace(priv, UDBG6, "unifi_reque_ma_packet_request: host_tag = 0x%x\n", host_tag);
 475
 476    staRecord = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,
 477                                                                    (((u8 *) bulkDataDesc->os_data_ptr) + 4),
 478                                                                    interfaceTag);
 479    if (NULL == staRecord) {
 480        unifi_trace(priv, UDBG5, "unifi_reque_ma_packet_request: Invalid STA record \n");
 481        return CSR_RESULT_FAILURE;
 482    }
 483
 484    /* Update TIM if MA-PACKET.cfm fails with status as Tx-retry-limit or No-BSS and then just return failure
 485     * to clear the hip slot associated with the Packet
 486     */
 487    if (CSR_TX_RETRY_LIMIT == txStatus || CSR_TX_NO_BSS == txStatus) {
 488        if (staRecord->timSet == CSR_WIFI_TIM_RESET || staRecord->timSet == CSR_WIFI_TIM_RESETTING)
 489        {
 490            unifi_trace(priv, UDBG2, "unifi_reque_ma_packet_request: CFM failed with Retry Limit or No BSS-->update TIM\n");
 491            if (!staRecord->timRequestPendingFlag) {
 492                update_tim(priv, staRecord->aid, 1, interfaceTag, staRecord->assignedHandle);
 493            }
 494            else {
 495                /* Cache the TimSet value so that it will processed immidiatly after
 496                 * completing the current setTim Request
 497                 */
 498                staRecord->updateTimReqQueued = 1;
 499                unifi_trace(priv, UDBG6, "unifi_reque_ma_packet_request: One more UpdateTim Request(:%d)Queued for AID %x\n",
 500                                         staRecord->updateTimReqQueued, staRecord->aid);
 501            }
 502        }
 503        return CSR_RESULT_FAILURE;
 504    }
 505    else if ((CSR_TX_LIFETIME == txStatus) ||  (CSR_TX_BLOCK_ACK_TIMEOUT == txStatus) ||
 506             (CSR_TX_FAIL_TRANSMISSION_VIF_INTERRUPTED == txStatus) ||
 507             (CSR_TX_REJECTED_PEER_STATION_SLEEPING == txStatus)    ||
 508             (CSR_TX_REJECTED_DTIM_STARTED == txStatus)) {
 509        /* Extract the Frame control and the frame type */
 510        frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(bulkDataDesc->os_data_ptr);
 511        frameType =  ((frameControl & IEEE80211_FC_TYPE_MASK) >> FRAME_CONTROL_TYPE_FIELD_OFFSET);
 512
 513        /* Mgmt frames will not be re-queued for Tx
 514         * so just return failure to clear the hip slot
 515         */
 516        if (IEEE802_11_FRAMETYPE_MANAGEMENT == frameType) {
 517            return CSR_RESULT_FAILURE;
 518        }
 519        else if (IEEE802_11_FRAMETYPE_DATA == frameType) {
 520            /* QOS NULL and DATA NULL frames will not be re-queued for Tx
 521             * so just return failure to clear the hip slot
 522             */
 523            if ((((frameControl & IEEE80211_FC_SUBTYPE_MASK) >> FRAME_CONTROL_SUBTYPE_FIELD_OFFSET) == QOS_DATA_NULL) ||
 524                (((frameControl & IEEE80211_FC_SUBTYPE_MASK) >> FRAME_CONTROL_SUBTYPE_FIELD_OFFSET)== DATA_NULL )) {
 525                return CSR_RESULT_FAILURE;
 526            }
 527        }
 528
 529        /* Extract the Packet priority */
 530        if (TRUE == staRecord->wmmOrQosEnabled) {
 531            u16 qosControl = 0;
 532            u8  dataFrameType = 0;
 533
 534            dataFrameType =((frameControl & IEEE80211_FC_SUBTYPE_MASK) >> 4);
 535
 536            if (dataFrameType == QOS_DATA) {
 537                /* QoS control field is offset from frame control by 2 (frame control)
 538                 * + 2 (duration/ID) + 2 (sequence control) + 3*ETH_ALEN or 4*ETH_ALEN
 539                 */
 540                if((frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK)) {
 541                    qosControl= CSR_GET_UINT16_FROM_LITTLE_ENDIAN(bulkDataDesc->os_data_ptr + 30);
 542                }
 543                else {
 544                    qosControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(bulkDataDesc->os_data_ptr + 24);
 545                }
 546            }
 547
 548            priority = (CSR_PRIORITY)(qosControl & IEEE802_11_QC_TID_MASK);
 549
 550            if (priority < CSR_QOS_UP0 || priority > CSR_QOS_UP7) {
 551                unifi_trace(priv, UDBG5, "unifi_reque_ma_packet_request: Invalid priority:%x \n", priority);
 552                return CSR_RESULT_FAILURE;
 553            }
 554        }
 555        else {
 556            priority = CSR_CONTENTION;
 557        }
 558
 559        /* Frame Bulk data to requeue it back to HAL Queues */
 560        bulkData.d[0].os_data_ptr    = bulkDataDesc->os_data_ptr;
 561        bulkData.d[0].data_length    = bulkDataDesc->data_length;
 562        bulkData.d[0].os_net_buf_ptr = bulkDataDesc->os_net_buf_ptr;
 563        bulkData.d[0].net_buf_length = bulkDataDesc->net_buf_length;
 564
 565        bulkData.d[1].os_data_ptr    = NULL;
 566        bulkData.d[1].os_net_buf_ptr = NULL;
 567        bulkData.d[1].data_length    = bulkData.d[1].net_buf_length = 0;
 568
 569        /* Initialize signal to zero */
 570        memset(&signal, 0, sizeof(CSR_SIGNAL));
 571
 572        /* Frame MA Packet Req */
 573        unifi_frame_ma_packet_req(priv, priority, 0, host_tag,
 574                              interfaceTag, CSR_NO_CONFIRM_REQUIRED,
 575                              priv->netdev_client->sender_id,
 576                              staRecord->peerMacAddress.a, &signal);
 577
 578        /* Find the Q-Priority */
 579        priority_q = unifi_frame_priority_to_queue(priority);
 580        list = &staRecord->dataPdu[priority_q];
 581
 582        /* Place the Packet on to HAL Queue */
 583        status = enque_tx_data_pdu(priv, &bulkData, list, &signal, TRUE);
 584
 585        /* Update the Per-station queued packet counter */
 586        if (!status) {
 587            spin_lock_irqsave(&priv->staRecord_lock, lock_flags);
 588            staRecord->noOfPktQueued++;
 589            spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags);
 590        }
 591    }
 592    else {
 593        /* Packet will not be re-queued for any of the other MA Packet Tx failure
 594         * reasons so just return failure to clear the hip slot
 595         */
 596        return CSR_RESULT_FAILURE;
 597    }
 598
 599    return status;
 600}
 601#endif
 602
 603static void is_all_ac_deliver_enabled_and_moredata(CsrWifiRouterCtrlStaInfo_t *staRecord, u8 *allDeliveryEnabled, u8 *dataAvailable)
 604{
 605    u8 i;
 606    *allDeliveryEnabled = TRUE;
 607    for (i = 0 ;i < MAX_ACCESS_CATOGORY; i++) {
 608        if (!IS_DELIVERY_ENABLED(staRecord->powersaveMode[i])) {
 609            /* One is is not Delivery Enabled */
 610            *allDeliveryEnabled = FALSE;
 611            break;
 612        }
 613    }
 614    if (*allDeliveryEnabled) {
 615        *dataAvailable = (!list_empty(&staRecord->dataPdu[0]) || !list_empty(&staRecord->dataPdu[1])
 616                          ||!list_empty(&staRecord->dataPdu[2]) ||!list_empty(&staRecord->dataPdu[3])
 617                          ||!list_empty(&staRecord->mgtFrames));
 618    }
 619}
 620
 621/*
 622 * ---------------------------------------------------------------------------
 623 *  uf_handle_tim_cfm
 624 *
 625 *
 626 *      This function updates tim status in host depending confirm status from firmware
 627 *
 628 *  Arguments:
 629 *      priv            Pointer to device private context struct
 630 *      cfm             CSR_MLME_SET_TIM_CONFIRM
 631 *      receiverProcessId SenderProcessID to fetch handle & timSet status
 632 *
 633 * ---------------------------------------------------------------------------
 634 */
 635void uf_handle_tim_cfm(unifi_priv_t *priv, CSR_MLME_SET_TIM_CONFIRM *cfm, u16 receiverProcessId)
 636{
 637    u8 handle = CSR_WIFI_GET_STATION_HANDLE_FROM_RECEIVER_ID(receiverProcessId);
 638    u8 timSetStatus = CSR_WIFI_GET_TIMSET_STATE_FROM_RECEIVER_ID(receiverProcessId);
 639    u16 interfaceTag = (cfm->VirtualInterfaceIdentifier & 0xff);
 640    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
 641    CsrWifiRouterCtrlStaInfo_t *staRecord = NULL;
 642    /* This variable holds what TIM value we wanted to set in firmware */
 643    u16 timSetValue = 0;
 644    /* Irrespective of interface the count maintained */
 645    static u8 retryCount = 0;
 646    unsigned long lock_flags;
 647    unifi_trace(priv, UDBG3, "entering %s, handle = %x, timSetStatus = %x\n", __FUNCTION__, handle, timSetStatus);
 648
 649    if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
 650        unifi_warning(priv, "bad interfaceTag = %x\n", interfaceTag);
 651        return;
 652    }
 653
 654    if ((handle != CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE) && (handle >= UNIFI_MAX_CONNECTIONS)) {
 655        unifi_warning(priv, "bad station Handle = %x\n", handle);
 656        return;
 657    }
 658
 659    if (handle != CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE) {
 660        spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
 661        if ((staRecord = ((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[handle]))) == NULL) {
 662            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
 663            unifi_warning(priv, "uf_handle_tim_cfm: station record is NULL  handle = %x\n", handle);
 664            return;
 665        }
 666       spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
 667    }
 668    switch(timSetStatus)
 669    {
 670        case CSR_WIFI_TIM_SETTING:
 671            timSetValue = CSR_WIFI_TIM_SET;
 672            break;
 673        case CSR_WIFI_TIM_RESETTING:
 674            timSetValue = CSR_WIFI_TIM_RESET;
 675            break;
 676        default:
 677            unifi_warning(priv, "timSet state is %x: Debug\n", timSetStatus);
 678            return;
 679    }
 680
 681    /* check TIM confirm for success/failures */
 682    switch(cfm->ResultCode)
 683    {
 684        case CSR_RC_SUCCESS:
 685            if (handle != CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE) {
 686                /* Unicast frame & station record available */
 687                if (timSetStatus == staRecord->timSet) {
 688                    staRecord->timSet = timSetValue;
 689                    /* fh_cmd_q can also be full at some point of time!,
 690                     * resetting count as queue is cleaned by firmware at this point
 691                     */
 692                    retryCount = 0;
 693                    unifi_trace(priv, UDBG2, "tim (%s) successfully in firmware\n", (timSetValue)?"SET":"RESET");
 694                } else {
 695                    unifi_trace(priv, UDBG3, "receiver processID = %x, success: request & confirm states are not matching in TIM cfm: Debug status = %x, staRecord->timSet = %x, handle = %x\n",
 696                                 receiverProcessId, timSetStatus, staRecord->timSet, handle);
 697                }
 698
 699                /* Reset TIM pending flag to send next TIM request */
 700                staRecord->timRequestPendingFlag = FALSE;
 701
 702                /* Make sure that one more UpdateTim request is queued, if Queued its value
 703                 * should be CSR_WIFI_TIM_SET or CSR_WIFI_TIM_RESET
 704                 */
 705                if (0xFF != staRecord->updateTimReqQueued)
 706                {
 707                    /* Process the UpdateTim Request which is queued while previous UpdateTim was in progress */
 708                    if (staRecord->timSet != staRecord->updateTimReqQueued)
 709                    {
 710                       unifi_trace(priv, UDBG2, "uf_handle_tim_cfm : Processing Queued UpdateTimReq \n");
 711
 712                       update_tim(priv, staRecord->aid, staRecord->updateTimReqQueued, interfaceTag, handle);
 713
 714                       staRecord->updateTimReqQueued = 0xFF;
 715                    }
 716                }
 717            } else {
 718
 719                interfacePriv->bcTimSet = timSetValue;
 720                /* fh_cmd_q can also be full at some point of time!,
 721                 * resetting count as queue is cleaned by firmware at this point
 722                 */
 723                retryCount = 0;
 724                unifi_trace(priv, UDBG3, "tim (%s) successfully for broadcast frame in firmware\n", (timSetValue)?"SET":"RESET");
 725
 726                /* Reset DTIM pending flag to send next DTIM request */
 727                interfacePriv->bcTimSetReqPendingFlag = FALSE;
 728
 729                /* Make sure that one more UpdateDTim request is queued, if Queued its value
 730                 * should be CSR_WIFI_TIM_SET or CSR_WIFI_TIM_RESET
 731                 */
 732                if (0xFF != interfacePriv->bcTimSetReqQueued)
 733                {
 734                    /* Process the UpdateTim Request which is queued while previous UpdateTim was in progress */
 735                    if (interfacePriv->bcTimSet != interfacePriv->bcTimSetReqQueued)
 736                    {
 737                        unifi_trace(priv, UDBG2, "uf_handle_tim_cfm : Processing Queued UpdateDTimReq \n");
 738
 739                        update_tim(priv, 0, interfacePriv->bcTimSetReqQueued, interfaceTag, 0xFFFFFFFF);
 740
 741                        interfacePriv->bcTimSetReqQueued = 0xFF;
 742                    }
 743                }
 744
 745            }
 746            break;
 747        case CSR_RC_INVALID_PARAMETERS:
 748        case CSR_RC_INSUFFICIENT_RESOURCE:
 749            /* check for max retry limit & send again
 750             * MAX_RETRY_LIMIT is not maintained for each set of transactions..Its generic
 751             * If failure crosses this Limit, we have to take a call to FIX
 752             */
 753            if (retryCount > UNIFI_MAX_RETRY_LIMIT) {
 754                u8 moreData = FALSE;
 755                retryCount = 0;
 756                /* Because of continuos traffic in fh_cmd_q the tim set request is failing (exceeding retry limit)
 757                 * but if we didn't synchronize our timSet varible state with firmware then it can cause below issues
 758                 * cond 1. We want to SET tim in firmware if its fails & max retry limit reached
 759                 *   -> If host set's the timSet to 1, we wont try to send(as max retry reached) update tim but
 760                 *   firmware is not updated with queue(TIM) status so it wont set TIM in beacon finally host start piling
 761                 *    up data & wont try to set tim in firmware (This can cause worser performance)
 762                 * cond 2. We want to reset tim in firmware it fails & reaches max retry limit
 763                 *   -> If host sets the timSet to Zero, it wont try to set a TIM request unless we wont have any packets
 764                 *   to be queued, so beacon unnecessarily advertizes the TIM
 765                 */
 766
 767                if(staRecord) {
 768                    if(!staRecord->wmmOrQosEnabled) {
 769                        moreData = (!list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]) ||
 770                                !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]) ||
 771                                !list_empty(&staRecord->mgtFrames));
 772                    } else {
 773                        /* Peer is QSTA */
 774                        u8 allDeliveryEnabled = 0, dataAvailable = 0;
 775                        /* Check if all AC's are Delivery Enabled */
 776                        is_all_ac_deliver_enabled_and_moredata(staRecord, &allDeliveryEnabled, &dataAvailable);
 777                        /*check for more data in non-delivery enabled queues*/
 778                        moreData = (uf_is_more_data_for_non_delivery_ac(staRecord) || (allDeliveryEnabled && dataAvailable));
 779
 780                    }
 781                    /* To avoid cond 1 & 2, check internal Queues status, if we have more Data then set RESET the timSet(0),
 782                     *  so we are trying to be in sync with firmware & next packets before queuing atleast try to
 783                     *  set TIM in firmware otherwise it SET timSet(1)
 784                     */
 785                    if (moreData) {
 786                        staRecord->timSet = CSR_WIFI_TIM_RESET;
 787                    } else {
 788                        staRecord->timSet = CSR_WIFI_TIM_SET;
 789                    }
 790                } else {
 791                    /* Its a broadcast frames */
 792                    moreData = (!list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames) ||
 793                               !list_empty(&interfacePriv->genericMulticastOrBroadCastFrames));
 794                    if (moreData) {
 795                        update_tim(priv, 0, CSR_WIFI_TIM_SET, interfaceTag, 0xFFFFFFFF);
 796                    } else {
 797                        update_tim(priv, 0, CSR_WIFI_TIM_RESET, interfaceTag, 0xFFFFFFFF);
 798                    }
 799                }
 800
 801                unifi_error(priv, "no of error's for TIM setting crossed the Limit: verify\n");
 802                return;
 803            }
 804            retryCount++;
 805
 806            if (handle != CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE) {
 807                if (timSetStatus == staRecord->timSet) {
 808                    unifi_warning(priv, "tim request failed, retry for AID = %x\n", staRecord->aid);
 809                    update_tim(priv, staRecord->aid, timSetValue, interfaceTag, handle);
 810                } else {
 811                    unifi_trace(priv, UDBG1, "failure: request & confirm states are not matching in TIM cfm: Debug status = %x, staRecord->timSet = %x\n",
 812                                  timSetStatus, staRecord->timSet);
 813                }
 814            } else {
 815                unifi_warning(priv, "tim request failed, retry for broadcast frames\n");
 816                update_tim(priv, 0, timSetValue, interfaceTag, 0xFFFFFFFF);
 817            }
 818            break;
 819        default:
 820            unifi_warning(priv, "tim update request failed resultcode = %x\n", cfm->ResultCode);
 821    }
 822
 823    unifi_trace(priv, UDBG2, "leaving %s\n", __FUNCTION__);
 824}
 825
 826/*
 827 * ---------------------------------------------------------------------------
 828 *  update_tim
 829 *
 830 *
 831 *      This function updates tim status in firmware for AID[1 to UNIFI_MAX_CONNECTIONS] or
 832 *       AID[0] for broadcast/multicast packets.
 833 *
 834 *      NOTE: The LSB (least significant BYTE) of senderId while sending this MLME premitive
 835 *       has been modified(utilized) as below
 836 *
 837 *       SenderID in signal's SignalPrimitiveHeader is 2 byte the lowe byte bitmap is below
 838 *
 839 *       station handle(6 bits)      timSet Status (2 bits)
 840 *       ---------------------       ----------------------
 841 *       0  0  0  0  0  0        |       0  0
 842 *
 843 * timSet Status can be one of below:
 844 *
 845 * CSR_WIFI_TIM_RESET
 846 * CSR_WIFI_TIM_RESETTING
 847 * CSR_WIFI_TIM_SET
 848 * CSR_WIFI_TIM_SETTING
 849 *
 850 *  Arguments:
 851 *      priv            Pointer to device private context struct
 852 *      aid             can be 1 t0 UNIFI_MAX_CONNECTIONS & 0 means multicast/broadcast
 853 *      setTim          value SET(1) / RESET(0)
 854 *      interfaceTag    the interfaceID on which activity going on
 855 *      handle          from  (0 <= handle < UNIFI_MAX_CONNECTIONS)
 856 *
 857 * ---------------------------------------------------------------------------
 858 */
 859void update_tim(unifi_priv_t * priv, u16 aid, u8 setTim, u16 interfaceTag, u32 handle)
 860{
 861    CSR_SIGNAL signal;
 862    s32 r;
 863    CSR_MLME_SET_TIM_REQUEST *req = &signal.u.MlmeSetTimRequest;
 864    bulk_data_param_t *bulkdata = NULL;
 865    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
 866    u8 senderIdLsb = 0;
 867    CsrWifiRouterCtrlStaInfo_t *staRecord = NULL;
 868    u32 oldTimSetStatus = 0, timSetStatus = 0;
 869
 870    unifi_trace(priv, UDBG5, "entering the update_tim routine\n");
 871
 872
 873    if (handle == 0xFFFFFFFF) {
 874        handle &= CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE;
 875        if (setTim == interfacePriv->bcTimSet)
 876        {
 877            unifi_trace(priv, UDBG3, "update_tim, Drop:Hdl=%x, timval=%d, globalTim=%d\n", handle, setTim, interfacePriv->bcTimSet);
 878            return;
 879        }
 880    } else if ((handle != 0xFFFFFFFF) && (handle >= UNIFI_MAX_CONNECTIONS)) {
 881        unifi_warning(priv, "bad station Handle = %x\n", handle);
 882        return;
 883    }
 884
 885    if (setTim) {
 886        timSetStatus =  CSR_WIFI_TIM_SETTING;
 887    } else {
 888        timSetStatus =  CSR_WIFI_TIM_RESETTING;
 889    }
 890
 891    if (handle != CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE) {
 892        if ((staRecord = ((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[handle]))) == NULL) {
 893            unifi_warning(priv, "station record is NULL in  update_tim: handle = %x :debug\n", handle);
 894            return;
 895        }
 896        /* In case of signal sending failed, revert back to old state */
 897        oldTimSetStatus = staRecord->timSet;
 898        staRecord->timSet = timSetStatus;
 899    }
 900
 901    /* pack senderID LSB */
 902    senderIdLsb = CSR_WIFI_PACK_SENDER_ID_LSB_FOR_TIM_REQ(handle,  timSetStatus);
 903
 904    /* initialize signal to zero */
 905    memset(&signal, 0, sizeof(CSR_SIGNAL));
 906
 907    /* Frame the MLME-SET-TIM request */
 908    signal.SignalPrimitiveHeader.SignalId = CSR_MLME_SET_TIM_REQUEST_ID;
 909    signal.SignalPrimitiveHeader.ReceiverProcessId = 0;
 910    CSR_COPY_UINT16_TO_LITTLE_ENDIAN(((priv->netdev_client->sender_id & 0xff00) | senderIdLsb),
 911                   (u8*)&signal.SignalPrimitiveHeader.SenderProcessId);
 912
 913    /* set The virtual interfaceIdentifier, aid, tim value */
 914    req->VirtualInterfaceIdentifier = uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag);
 915    req->AssociationId = aid;
 916    req->TimValue = setTim;
 917
 918
 919    unifi_trace(priv, UDBG2, "update_tim:AID %x,senderIdLsb = 0x%x, handle = 0x%x, timSetStatus = %x, sender proceesID = %x \n",
 920                aid,senderIdLsb, handle, timSetStatus, signal.SignalPrimitiveHeader.SenderProcessId);
 921
 922    /* Send the signal to UniFi */
 923    r = ul_send_signal_unpacked(priv, &signal, bulkdata);
 924    if (r) {
 925        /* No need to free bulk data, as TIM request doesn't carries any data */
 926        unifi_error(priv, "Error queueing CSR_MLME_SET_TIM_REQUEST signal\n");
 927        if (staRecord) {
 928            staRecord->timSet = oldTimSetStatus ;
 929        }
 930        else
 931        {
 932            /* MLME_SET_TIM.req sending failed here for AID0, so revert back our bcTimSet status */
 933            interfacePriv->bcTimSet = !setTim;
 934        }
 935    }
 936    else {
 937        /* Update tim request pending flag and ensure no more TIM set requests are send
 938           for the same station until TIM confirm is received */
 939        if (staRecord) {
 940            staRecord->timRequestPendingFlag = TRUE;
 941        }
 942        else
 943        {
 944            /* Update tim request (for AID 0) pending flag and ensure no more DTIM set requests are send
 945             * for the same station until TIM confirm is received
 946             */
 947            interfacePriv->bcTimSetReqPendingFlag = TRUE;
 948        }
 949    }
 950    unifi_trace(priv, UDBG5, "leaving the update_tim routine\n");
 951}
 952
 953static
 954void process_peer_active_transition(unifi_priv_t * priv,
 955                                    CsrWifiRouterCtrlStaInfo_t *staRecord,
 956                                    u16 interfaceTag)
 957{
 958    int r,i;
 959    u8 spaceAvail[4] = {TRUE,TRUE,TRUE,TRUE};
 960    tx_buffered_packets_t * buffered_pkt = NULL;
 961    unsigned long lock_flags;
 962    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
 963
 964    unifi_trace(priv, UDBG5, "entering process_peer_active_transition\n");
 965
 966    if(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) {
 967        /* giving more priority to multicast packets so delaying unicast packets*/
 968        unifi_trace(priv,UDBG2, "Multicast transmission is going on so resume unicast transmission after DTIM over\n");
 969
 970        /* As station is active now, even though AP is not able to send frames to it
 971         * because of DTIM, it needs to reset the TIM here
 972         */
 973        if (!staRecord->timRequestPendingFlag){
 974            if((staRecord->timSet == CSR_WIFI_TIM_SET) || (staRecord->timSet == CSR_WIFI_TIM_SETTING)){
 975                update_tim(priv, staRecord->aid, 0, interfaceTag, staRecord->assignedHandle);
 976            }
 977        }
 978        else
 979        {
 980            /* Cache the TimSet value so that it will processed immidiatly after
 981             * completing the current setTim Request
 982             */
 983            staRecord->updateTimReqQueued = 0;
 984            unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
 985                        staRecord->aid);
 986        }
 987        return;
 988    }
 989    while((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->mgtFrames))) {
 990        buffered_pkt->transmissionControl &=
 991                     ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK);
 992        if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,0,FALSE)) == -ENOSPC) {
 993            unifi_trace(priv, UDBG2, "p_p_a_t:(ENOSPC) Mgt Frame queueing \n");
 994            /* Enqueue at the head of the queue */
 995            spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
 996            list_add(&buffered_pkt->q, &staRecord->mgtFrames);
 997            spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
 998            priv->pausedStaHandle[3]=(u8)(staRecord->assignedHandle);
 999            spaceAvail[3] = FALSE;
1000            break;
1001        } else {
1002            if(r){
1003                unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
1004                /* the PDU failed where we can't do any thing so free the storage */
1005                unifi_net_data_free(priv, &buffered_pkt->bulkdata);
1006            }
1007            kfree(buffered_pkt);
1008        }
1009    }
1010    if (!staRecord->timRequestPendingFlag) {
1011        if (staRecord->txSuspend) {
1012            if(staRecord->timSet == CSR_WIFI_TIM_SET) {
1013                update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle);
1014            }
1015            return;
1016        }
1017    }
1018    else
1019    {
1020        /* Cache the TimSet value so that it will processed immidiatly after
1021         * completing the current setTim Request
1022         */
1023        staRecord->updateTimReqQueued = 0;
1024        unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
1025                    staRecord->aid);
1026    }
1027    for(i=3;i>=0;i--) {
1028        if(!spaceAvail[i])
1029            continue;
1030        unifi_trace(priv, UDBG6, "p_p_a_t:data pkt sending for AC %d \n",i);
1031        while((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->dataPdu[i]))) {
1032           buffered_pkt->transmissionControl &=
1033                      ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK);
1034           if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,0,FALSE)) == -ENOSPC) {
1035               /* Clear the trigger bit transmission control*/
1036               /* Enqueue at the head of the queue */
1037               spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
1038               list_add(&buffered_pkt->q, &staRecord->dataPdu[i]);
1039               spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
1040               priv->pausedStaHandle[i]=(u8)(staRecord->assignedHandle);
1041               break;
1042           } else {
1043              if(r){
1044                  unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
1045                  /* the PDU failed where we can't do any thing so free the storage */
1046                  unifi_net_data_free(priv, &buffered_pkt->bulkdata);
1047               }
1048              kfree(buffered_pkt);
1049           }
1050        }
1051    }
1052    if (!staRecord->timRequestPendingFlag){
1053        if((staRecord->timSet  == CSR_WIFI_TIM_SET) || (staRecord->timSet  == CSR_WIFI_TIM_SETTING)) {
1054            unifi_trace(priv, UDBG3, "p_p_a_t:resetting tim .....\n");
1055            update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle);
1056        }
1057    }
1058    else
1059    {
1060        /* Cache the TimSet value so that it will processed immidiatly after
1061         * completing the current setTim Request
1062         */
1063        staRecord->updateTimReqQueued = 0;
1064        unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
1065                    staRecord->aid);
1066    }
1067    unifi_trace(priv, UDBG5, "leaving process_peer_active_transition\n");
1068}
1069
1070
1071
1072void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv,u16 interfaceTag, const CSR_MA_PACKET_CONFIRM *pkt_cfm)
1073{
1074    netInterface_priv_t *interfacePriv;
1075    u8 i;
1076    CsrWifiRouterCtrlStaInfo_t *staRecord = NULL;
1077    interfacePriv = priv->interfacePriv[interfaceTag];
1078
1079
1080    if(pkt_cfm->HostTag == interfacePriv->multicastPduHostTag) {
1081         unifi_trace(priv,UDBG2,"CFM for marked Multicast Tag = %x\n",interfacePriv->multicastPduHostTag);
1082         interfacePriv->multicastPduHostTag = 0xffffffff;
1083         resume_suspended_uapsd(priv,interfaceTag);
1084         resume_unicast_buffered_frames(priv,interfaceTag);
1085         if(list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames) &&
1086              list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)) {
1087            unifi_trace(priv,UDBG1,"Resetting multicastTIM");
1088            if (!interfacePriv->bcTimSetReqPendingFlag)
1089            {
1090                update_tim(priv,0,CSR_WIFI_TIM_RESET,interfaceTag, 0xFFFFFFFF);
1091            }
1092            else
1093            {
1094                /* Cache the DTimSet value so that it will processed immidiatly after
1095                 * completing the current setDTim Request
1096                 */
1097                 interfacePriv->bcTimSetReqQueued = CSR_WIFI_TIM_RESET;
1098                 unifi_trace(priv, UDBG2, "uf_process_ma_pkt_cfm_for_ap : One more UpdateDTim Request(%d) Queued \n",
1099                             interfacePriv->bcTimSetReqQueued);
1100            }
1101
1102        }
1103        return;
1104    }
1105
1106    /* Check if it is a Confirm for null data frame used
1107     * for probing station activity
1108     */
1109    for(i =0; i < UNIFI_MAX_CONNECTIONS; i++) {
1110        staRecord = (CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[i]);
1111        if (staRecord && (staRecord->nullDataHostTag == pkt_cfm->HostTag)) {
1112
1113            unifi_trace(priv, UDBG1, "CFM for Inactive probe Null frame (tag = %x, status = %d)\n",
1114                                    pkt_cfm->HostTag,
1115                                    pkt_cfm->TransmissionStatus
1116                                    );
1117            staRecord->nullDataHostTag = INVALID_HOST_TAG;
1118
1119            if(pkt_cfm->TransmissionStatus == CSR_TX_RETRY_LIMIT){
1120                CsrTime now;
1121                CsrTime inactive_time;
1122
1123                unifi_trace(priv, UDBG1, "Nulldata to probe STA ALIVE Failed with retry limit\n");
1124                /* Recheck if there is some activity after null data is sent.
1125                *
1126                * If still there is no activity then send a disconnected indication
1127                * to SME to delete the station record.
1128                */
1129                if (staRecord->activity_flag){
1130                    return;
1131                }
1132                now = CsrTimeGet(NULL);
1133
1134                if (staRecord->lastActivity > now)
1135                {
1136                    /* simple timer wrap (for 1 wrap) */
1137                    inactive_time = CsrTimeAdd((CsrTime)CsrTimeSub(CSR_SCHED_TIME_MAX, staRecord->lastActivity),
1138                                               now);
1139                }
1140                else
1141                {
1142                    inactive_time = (CsrTime)CsrTimeSub(now, staRecord->lastActivity);
1143                }
1144
1145                if (inactive_time >= STA_INACTIVE_TIMEOUT_VAL)
1146                {
1147                    struct list_head send_cfm_list;
1148                    u8 j;
1149
1150                    /* The SME/NME may be waiting for confirmation for requested frames to this station.
1151                     * Though this is --VERY UNLIKELY-- in case of station in active mode. But still as a
1152                     * a defensive check, it loops through buffered frames for this station and if confirmation
1153                     * is requested, send auto confirmation with failure status. Also flush the frames so
1154                     * that these are not processed again in PEER_DEL_REQ handler.
1155                     */
1156                    INIT_LIST_HEAD(&send_cfm_list);
1157
1158                    uf_prepare_send_cfm_list_for_queued_pkts(priv,
1159                                                             &send_cfm_list,
1160                                                             &(staRecord->mgtFrames));
1161
1162                    uf_flush_list(priv, &(staRecord->mgtFrames));
1163
1164                    for(j = 0; j < MAX_ACCESS_CATOGORY; j++){
1165                        uf_prepare_send_cfm_list_for_queued_pkts(priv,
1166                                                                 &send_cfm_list,
1167                                                                 &(staRecord->dataPdu[j]));
1168
1169                        uf_flush_list(priv,&(staRecord->dataPdu[j]));
1170                    }
1171
1172                    send_auto_ma_packet_confirm(priv, staRecord->interfacePriv, &send_cfm_list);
1173
1174
1175
1176                    unifi_warning(priv, "uf_process_ma_pkt_cfm_for_ap: Router Disconnected IND Peer (%x-%x-%x-%x-%x-%x)\n",
1177                                             staRecord->peerMacAddress.a[0],
1178                                             staRecord->peerMacAddress.a[1],
1179                                             staRecord->peerMacAddress.a[2],
1180                                             staRecord->peerMacAddress.a[3],
1181                                             staRecord->peerMacAddress.a[4],
1182                                             staRecord->peerMacAddress.a[5]);
1183
1184                    CsrWifiRouterCtrlConnectedIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,
1185                                                      0,
1186                                                      staRecord->interfacePriv->InterfaceTag,
1187                                                      staRecord->peerMacAddress,
1188                                                      CSR_WIFI_ROUTER_CTRL_PEER_DISCONNECTED);
1189                }
1190
1191            }
1192            else if (pkt_cfm->TransmissionStatus == CSR_TX_SUCCESSFUL)
1193            {
1194                 staRecord->activity_flag = TRUE;
1195            }
1196        }
1197    }
1198}
1199
1200#endif
1201u16 uf_get_vif_identifier (CsrWifiRouterCtrlMode mode, u16 tag)
1202{
1203    switch(mode)
1204    {
1205        case CSR_WIFI_ROUTER_CTRL_MODE_STA:
1206        case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
1207            return (0x02<<8|tag);
1208
1209        case CSR_WIFI_ROUTER_CTRL_MODE_AP:
1210        case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
1211            return (0x03<<8|tag);
1212
1213        case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
1214            return (0x01<<8|tag);
1215
1216        case CSR_WIFI_ROUTER_CTRL_MODE_MONITOR:
1217            return (0x04<<8|tag);
1218        case CSR_WIFI_ROUTER_CTRL_MODE_AMP:
1219            return (0x05<<8|tag);
1220        default:
1221            return tag;
1222    }
1223}
1224
1225#ifdef CSR_SUPPORT_SME
1226
1227/*
1228 * ---------------------------------------------------------------------------
1229 *  update_macheader
1230 *
1231 *
1232 *      These functions updates mac header for intra BSS packet
1233 *      routing.
1234 *      NOTE: This function always has to be called in rx context which
1235 *      is in bh thread context since GFP_KERNEL is used. In soft IRQ/ Interrupt
1236 *      context shouldn't be used
1237 *
1238 *  Arguments:
1239 *      priv            Pointer to device private context struct
1240 *      skb             Socket buffer containing data packet to transmit
1241 *      newSkb          Socket buffer containing data packet + Mac header if no sufficient headroom in skb
1242 *      priority        to append QOS control header in Mac header
1243 *      bulkdata        if newSkb allocated then bulkdata updated to send to unifi
1244 *      interfaceTag    the interfaceID on which activity going on
1245 *      macHeaderLengthInBytes no. of bytes of mac header in received frame
1246 *      qosDestination  used to append Qos control field
1247 *
1248 *  Returns:
1249 *      Zero on success or -1 on error.
1250 * ---------------------------------------------------------------------------
1251 */
1252
1253static int update_macheader(unifi_priv_t *priv, struct sk_buff *skb,
1254                            struct sk_buff *newSkb, CSR_PRIORITY *priority,
1255                            bulk_data_param_t *bulkdata, u16 interfaceTag,
1256                            u8 macHeaderLengthInBytes,
1257                            u8 qosDestination)
1258{
1259
1260    u16 *fc = NULL;
1261    u8 direction = 0, toDs, fromDs;
1262    u8 *bufPtr = NULL;
1263    u8 sa[ETH_ALEN], da[ETH_ALEN];
1264    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
1265    int headroom;
1266    u8 macHeaderBuf[IEEE802_11_DATA_FRAME_MAC_HEADER_SIZE] = {0};
1267
1268    unifi_trace(priv, UDBG5, "entering the update_macheader function\n");
1269
1270    /* temporary buffer for the Mac header storage */
1271    memcpy(macHeaderBuf, skb->data, macHeaderLengthInBytes);
1272
1273    /* remove the Macheader from the skb */
1274    skb_pull(skb, macHeaderLengthInBytes);
1275
1276    /* get the skb headroom for skb_push check */
1277    headroom = skb_headroom(skb);
1278
1279    /*  pointer to frame control field */
1280    fc = (u16*) macHeaderBuf;
1281
1282    toDs = (*fc & cpu_to_le16(IEEE802_11_FC_TO_DS_MASK))?1 : 0;
1283    fromDs = (*fc & cpu_to_le16(IEEE802_11_FC_FROM_DS_MASK))? 1: 0;
1284    unifi_trace(priv, UDBG5, "In update_macheader function, fromDs = %x, toDs = %x\n", fromDs, toDs);
1285    direction = ((fromDs | (toDs << 1)) & 0x3);
1286
1287    /* Address1 or 3 from the macheader */
1288    memcpy(da, macHeaderBuf+4+toDs*12, ETH_ALEN);
1289    /* Address2, 3 or 4 from the mac header */
1290    memcpy(sa, macHeaderBuf+10+fromDs*(6+toDs*8), ETH_ALEN);
1291
1292    unifi_trace(priv, UDBG3, "update_macheader:direction = %x\n", direction);
1293    /* update the toDs, fromDs & address fields in Mac header */
1294    switch(direction)
1295    {
1296        case 2:
1297            /* toDs = 1 & fromDs = 0 , toAp when frames received from peer
1298             * while sending this packet to Destination the Mac header changed
1299             * as fromDs = 1 & toDs = 0, fromAp
1300             */
1301            *fc &= cpu_to_le16(~IEEE802_11_FC_TO_DS_MASK);
1302            *fc |= cpu_to_le16(IEEE802_11_FC_FROM_DS_MASK);
1303            /* Address1: MAC address of the actual destination (4 = 2+2) */
1304            memcpy(macHeaderBuf + 4, da, ETH_ALEN);
1305            /* Address2: The MAC address of the AP (10 = 2+2+6) */
1306            memcpy(macHeaderBuf + 10, &interfacePriv->bssid, ETH_ALEN);
1307            /* Address3: MAC address of the actual source from mac header (16 = 2+2+6+6) */
1308            memcpy(macHeaderBuf + 16, sa, ETH_ALEN);
1309            break;
1310        case 3:
1311            unifi_trace(priv, UDBG3, "when both the toDs & fromDS set, NOT SUPPORTED\n");
1312            break;
1313        default:
1314            unifi_trace(priv, UDBG3, "problem in decoding packet in update_macheader \n");
1315            return -1;
1316    }
1317
1318    /* frameType is Data always, Validation is done before calling this function */
1319
1320    /* check for the souce station type */
1321    switch(le16_to_cpu(*fc) & IEEE80211_FC_SUBTYPE_MASK)
1322    {
1323        case IEEE802_11_FC_TYPE_QOS_DATA & IEEE80211_FC_SUBTYPE_MASK:
1324            /* No need to modify the qos control field */
1325            if (!qosDestination) {
1326
1327                /* If source Sta is QOS enabled & if this bit set, then HTC is supported by
1328                 * peer station & htc field present in macHeader
1329                 */
1330                if (*fc & cpu_to_le16(IEEE80211_FC_ORDER_MASK)) {
1331                    /* HT control field present in Mac header
1332                     * 6 = sizeof(qosControl) + sizeof(htc)
1333                     */
1334                    macHeaderLengthInBytes -= 6;
1335                } else {
1336                    macHeaderLengthInBytes -= 2;
1337                }
1338                /* Destination STA is non qos so change subtype to DATA */
1339                *fc &= cpu_to_le16(~IEEE80211_FC_SUBTYPE_MASK);
1340                *fc |= cpu_to_le16(IEEE802_11_FC_TYPE_DATA);
1341                /* remove the qos control field & HTC(if present). new macHeaderLengthInBytes is less than old
1342                 * macHeaderLengthInBytes so no need to verify skb headroom
1343                 */
1344                if (headroom < macHeaderLengthInBytes) {
1345                    unifi_trace(priv, UDBG1, " sufficient headroom not there to push updated mac header \n");
1346                    return -1;
1347                }
1348                bufPtr = (u8 *) skb_push(skb, macHeaderLengthInBytes);
1349
1350                /*  update bulk data os_data_ptr */
1351                bulkdata->d[0].os_data_ptr = skb->data;
1352                bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skb;
1353                bulkdata->d[0].data_length = skb->len;
1354
1355            } else {
1356                /* pointing to QOS control field */
1357                u8 qc;
1358                if (*fc & cpu_to_le16(IEEE80211_FC_ORDER_MASK)) {
1359                    qc = *((u8*)(macHeaderBuf + (macHeaderLengthInBytes - 4 - 2)));
1360                } else {
1361                    qc = *((u8*)(macHeaderBuf + (macHeaderLengthInBytes - 2)));
1362                }
1363
1364                if ((qc & IEEE802_11_QC_TID_MASK) > 7) {
1365                    *priority = 7;
1366                } else {
1367                    *priority = qc & IEEE802_11_QC_TID_MASK;
1368                }
1369
1370                unifi_trace(priv, UDBG1, "Incoming packet priority from QSTA is %x\n", *priority);
1371
1372                if (headroom < macHeaderLengthInBytes) {
1373                    unifi_trace(priv, UDBG3, " sufficient headroom not there to push updated mac header \n");
1374                    return -1;
1375                }
1376                bufPtr = (u8 *) skb_push(skb, macHeaderLengthInBytes);
1377            }
1378            break;
1379        default:
1380            {
1381                bulk_data_param_t data_ptrs;
1382                CsrResult csrResult;
1383                unifi_trace(priv, UDBG5, "normal Data packet, NO QOS \n");
1384
1385                if (qosDestination) {
1386                    u8 qc = 0;
1387                    unifi_trace(priv, UDBG3, "destination is QOS station \n");
1388
1389                    /* Set Ma-Packet.req UP to UP0 */
1390                    *priority = CSR_QOS_UP0;
1391
1392                    /* prepare the qos control field */
1393                    qc |= CSR_QOS_UP0;
1394                    /* no Amsdu is in ap buffer so eosp is left 0 */
1395                    if (da[0] & 0x1) {
1396                        /* multicast/broadcast frames, no acknowledgement needed */
1397                        qc |= 1 << 5;
1398                    }
1399
1400                    /* update new Mac header Length with 2 = sizeof(qos control) */
1401                    macHeaderLengthInBytes += 2;
1402
1403                    /* received DATA frame but destiantion is QOS station so update subtype to QOS*/
1404                    *fc &= cpu_to_le16(~IEEE80211_FC_SUBTYPE_MASK);
1405                    *fc |= cpu_to_le16(IEEE802_11_FC_TYPE_QOS_DATA);
1406
1407                    /* appendQosControlOffset = macHeaderLengthInBytes - 2, since source sta is not QOS */
1408                    macHeaderBuf[macHeaderLengthInBytes - 2] = qc;
1409                    /* txopLimit is 0 */
1410                    macHeaderBuf[macHeaderLengthInBytes - 1] = 0;
1411                    if (headroom < macHeaderLengthInBytes) {
1412                        csrResult = unifi_net_data_malloc(priv, &data_ptrs.d[0], skb->len + macHeaderLengthInBytes);
1413
1414                        if (csrResult != CSR_RESULT_SUCCESS) {
1415                            unifi_error(priv, " failed to allocate request_data. in update_macheader func\n");
1416                            return -1;
1417                        }
1418                        newSkb = (struct sk_buff *)(data_ptrs.d[0].os_net_buf_ptr);
1419                        newSkb->len = skb->len + macHeaderLengthInBytes;
1420
1421                        memcpy((void*)data_ptrs.d[0].os_data_ptr + macHeaderLengthInBytes,
1422                                skb->data, skb->len);
1423
1424                        bulkdata->d[0].os_data_ptr = newSkb->data;
1425                        bulkdata->d[0].os_net_buf_ptr = (unsigned char*)newSkb;
1426                        bulkdata->d[0].data_length = newSkb->len;
1427
1428                        bufPtr = (u8*)data_ptrs.d[0].os_data_ptr;
1429
1430                        /* The old skb will not be used again */
1431                        kfree_skb(skb);
1432                    } else {
1433                        /* skb headroom is sufficient to append Macheader */
1434                        bufPtr = (u8*)skb_push(skb, macHeaderLengthInBytes);
1435                        bulkdata->d[0].os_data_ptr = skb->data;
1436                        bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skb;
1437                        bulkdata->d[0].data_length = skb->len;
1438                    }
1439                } else {
1440                    unifi_trace(priv, UDBG3, "destination is not a QSTA\n");
1441                    if (headroom < macHeaderLengthInBytes) {
1442                        csrResult = unifi_net_data_malloc(priv, &data_ptrs.d[0], skb->len + macHeaderLengthInBytes);
1443
1444                        if (csrResult != CSR_RESULT_SUCCESS) {
1445                            unifi_error(priv, " failed to allocate request_data. in update_macheader func\n");
1446                            return -1;
1447                        }
1448                        newSkb = (struct sk_buff *)(data_ptrs.d[0].os_net_buf_ptr);
1449                        newSkb->len = skb->len + macHeaderLengthInBytes;
1450
1451                        memcpy((void*)data_ptrs.d[0].os_data_ptr + macHeaderLengthInBytes,
1452                                skb->data, skb->len);
1453
1454                        bulkdata->d[0].os_data_ptr = newSkb->data;
1455                        bulkdata->d[0].os_net_buf_ptr = (unsigned char*)newSkb;
1456                        bulkdata->d[0].data_length = newSkb->len;
1457
1458                        bufPtr = (u8*)data_ptrs.d[0].os_data_ptr;
1459
1460                        /* The old skb will not be used again */
1461                        kfree_skb(skb);
1462                    } else {
1463                        /* skb headroom is sufficient to append Macheader */
1464                        bufPtr = (u8*)skb_push(skb, macHeaderLengthInBytes);
1465                        bulkdata->d[0].os_data_ptr = skb->data;
1466                        bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skb;
1467                        bulkdata->d[0].data_length = skb->len;
1468                    }
1469                }
1470            }
1471    }
1472
1473    /* prepare the complete skb, by pushing the MAC header to the begining of the skb->data */
1474    unifi_trace(priv, UDBG5, "updated Mac Header: %d \n",macHeaderLengthInBytes);
1475    memcpy(bufPtr, macHeaderBuf, macHeaderLengthInBytes);
1476
1477    unifi_trace(priv, UDBG5, "leaving the update_macheader function\n");
1478    return 0;
1479}
1480/*
1481 * ---------------------------------------------------------------------------
1482 *  uf_ap_process_data_pdu
1483 *
1484 *
1485 *      Takes care of intra BSS admission control & routing packets within BSS
1486 *
1487 *  Arguments:
1488 *      priv            Pointer to device private context struct
1489 *      skb             Socket buffer containing data packet to transmit
1490 *      ehdr            ethernet header to fetch priority of packet
1491 *      srcStaInfo      source stations record for connection verification
1492 *      packed_signal
1493 *      signal_len
1494 *      signal          MA-PACKET.indication signal
1495 *      bulkdata        if newSkb allocated then bulkdata updated to send to unifi
1496 *      macHeaderLengthInBytes no. of bytes of mac header in received frame
1497 *
1498 *  Returns:
1499 *      Zero on success(ap processing complete) or -1 if packet also have to be sent to NETDEV.
1500 * ---------------------------------------------------------------------------
1501 */
1502int
1503uf_ap_process_data_pdu(unifi_priv_t *priv, struct sk_buff *skb,
1504                       struct ethhdr *ehdr, CsrWifiRouterCtrlStaInfo_t * srcStaInfo,
1505                       const CSR_SIGNAL *signal,
1506                       bulk_data_param_t *bulkdata,
1507                       u8 macHeaderLengthInBytes)
1508{
1509    const CSR_MA_PACKET_INDICATION *ind = &(signal->u.MaPacketIndication);
1510    u16 interfaceTag = (ind->VirtualInterfaceIdentifier & 0x00ff);
1511    struct sk_buff *newSkb = NULL;
1512    /* pointer to skb or private skb created using skb_copy() */
1513    struct sk_buff *skbPtr = skb;
1514    u8 sendToNetdev = FALSE;
1515    u8 qosDestination = FALSE;
1516    CSR_PRIORITY priority = CSR_CONTENTION;
1517    CsrWifiRouterCtrlStaInfo_t *dstStaInfo = NULL;
1518    netInterface_priv_t *interfacePriv;
1519
1520    unifi_trace(priv, UDBG5, "entering  uf_ap_process_data_pdu %d\n",macHeaderLengthInBytes);
1521    /* InterfaceTag validation from MA_PACKET.indication */
1522    if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
1523        unifi_trace(priv, UDBG1, "Interface Tag is Invalid in uf_ap_process_data_pdu\n");
1524        unifi_net_data_free(priv, &bulkdata->d[0]);
1525        return 0;
1526    }
1527    interfacePriv = priv->interfacePriv[interfaceTag];
1528
1529    if((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) &&
1530       (interfacePriv->intraBssEnabled == FALSE)) {
1531        unifi_trace(priv, UDBG2, "uf_ap_process_data_pdu:P2P GO intrabssEnabled?= %d\n", interfacePriv->intraBssEnabled);
1532
1533        /*In P2P GO case, if intraBSS distribution Disabled then don't do IntraBSS routing */
1534        /* If destination in our BSS then drop otherwise give packet to netdev */
1535        dstStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, ehdr->h_dest, interfaceTag);
1536        if (dstStaInfo) {
1537            unifi_net_data_free(priv, &bulkdata->d[0]);
1538            return 0;
1539        }
1540        /* May be associated P2PCLI trying to send the packets on backbone (Netdev) */
1541        return -1;
1542    }
1543
1544    if(!memcmp(ehdr->h_dest, interfacePriv->bssid.a, ETH_ALEN)) {
1545        /* This packet will be given to the TCP/IP stack since this packet is for us(AP)
1546         * No routing needed */
1547        unifi_trace(priv, UDBG4, "destination address is csr_ap\n");
1548        return -1;
1549    }
1550
1551    /* fetch the destination record from staion record database */
1552    dstStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, ehdr->h_dest, interfaceTag);
1553
1554    /* AP mode processing, & if packet is unicast */
1555    if(!dstStaInfo) {
1556        if (!(ehdr->h_dest[0] & 0x1)) {
1557            /* destination not in station record & its a unicast packet, so pass the packet to network stack */
1558            unifi_trace(priv, UDBG3, "unicast frame & destination record not exist, send to netdev proto = %x\n", htons(skb->protocol));
1559            return -1;
1560        } else {
1561            /* packet is multicast/broadcast */
1562            /* copy the skb to skbPtr, send skb to netdev & skbPtr to multicast/broad cast list */
1563            unifi_trace(priv, UDBG5, "skb_copy, in  uf_ap_process_data_pdu, protocol = %x\n", htons(skb->protocol));
1564            skbPtr = skb_copy(skb, GFP_KERNEL);
1565            if(skbPtr == NULL) {
1566                /* We don't have memory to don't send the frame in BSS*/
1567                unifi_notice(priv, "broacast/multicast frame can't be sent in BSS No memeory: proto = %x\n", htons(skb->protocol));
1568                return -1;
1569            }
1570            sendToNetdev = TRUE;
1571        }
1572    } else {
1573
1574        /* validate the Peer & Destination Station record */
1575        if (uf_process_station_records_for_sending_data(priv, interfaceTag, srcStaInfo, dstStaInfo)) {
1576            unifi_notice(priv, "uf_ap_process_data_pdu: station record validation failed \n");
1577            interfacePriv->stats.rx_errors++;
1578            unifi_net_data_free(priv, &bulkdata->d[0]);
1579            return 0;
1580        }
1581    }
1582
1583    /* BroadCast packet received and it's been sent as non QOS packets.
1584     * Since WMM spec not mandates broadcast/multicast to be sent as QOS data only,
1585     * if all Peers are QSTA
1586     */
1587    if(sendToNetdev) {
1588       /* BroadCast packet and it's been sent as non QOS packets */
1589        qosDestination = FALSE;
1590    } else if(dstStaInfo && (dstStaInfo->wmmOrQosEnabled == TRUE)) {
1591          qosDestination = TRUE;
1592    }
1593
1594    unifi_trace(priv, UDBG3, "uf_ap_process_data_pdu QoS destination  = %s\n", (qosDestination)? "TRUE": "FALSE");
1595
1596    /* packet is allowed to send to unifi, update the Mac header */
1597    if (update_macheader(priv, skbPtr, newSkb, &priority, bulkdata, interfaceTag, macHeaderLengthInBytes, qosDestination)) {
1598        interfacePriv->stats.rx_errors++;
1599        unifi_notice(priv, "(Packet Drop) failed to update the Mac header in uf_ap_process_data_pdu\n");
1600        if (sendToNetdev) {
1601            /*  Free's the skb_copy(skbPtr) data since packet processing failed */
1602            bulkdata->d[0].os_data_ptr = skbPtr->data;
1603            bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skbPtr;
1604            bulkdata->d[0].data_length = skbPtr->len;
1605            unifi_net_data_free(priv, &bulkdata->d[0]);
1606        }
1607        return -1;
1608    }
1609
1610    unifi_trace(priv, UDBG3, "Mac Header updated...calling uf_process_ma_packet_req \n");
1611
1612    /* Packet is ready to send to unifi ,transmissionControl = 0x0004, confirmation is not needed for data packets */
1613    if (uf_process_ma_packet_req(priv,  ehdr->h_dest, 0xffffffff, interfaceTag, CSR_NO_CONFIRM_REQUIRED, (CSR_RATE)0,priority, priv->netdev_client->sender_id, bulkdata)) {
1614        if (sendToNetdev) {
1615            unifi_trace(priv, UDBG1, "In uf_ap_process_data_pdu, (Packet Drop) uf_process_ma_packet_req failed. freeing skb_copy data (original data sent to Netdev)\n");
1616            /*  Free's the skb_copy(skbPtr) data since packet processing failed */
1617            bulkdata->d[0].os_data_ptr = skbPtr->data;
1618            bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skbPtr;
1619            bulkdata->d[0].data_length = skbPtr->len;
1620            unifi_net_data_free(priv, &bulkdata->d[0]);
1621        } else {
1622            /* This free's the skb data */
1623            unifi_trace(priv, UDBG1, "In uf_ap_process_data_pdu, (Packet Drop). Unicast data so freeing original skb \n");
1624            unifi_net_data_free(priv, &bulkdata->d[0]);
1625        }
1626    }
1627    unifi_trace(priv, UDBG5, "leaving  uf_ap_process_data_pdu\n");
1628
1629    if (sendToNetdev) {
1630        /* The packet is multicast/broadcast, so after AP processing packet has to
1631         * be sent to netdev, if peer port state is open
1632        */
1633        unifi_trace(priv, UDBG4, "Packet will be routed to NetDev\n");
1634        return -1;
1635    }
1636    /* Ap handled the packet & its a unicast packet, no need to send to netdev */
1637    return 0;
1638}
1639
1640#endif
1641
1642CsrResult uf_process_ma_packet_req(unifi_priv_t *priv,
1643                                   u8 *peerMacAddress,
1644                                   CSR_CLIENT_TAG hostTag,
1645                                   u16 interfaceTag,
1646                                   CSR_TRANSMISSION_CONTROL transmissionControl,
1647                                   CSR_RATE TransmitRate,
1648                                   CSR_PRIORITY priority,
1649                                   CSR_PROCESS_ID leSenderProcessId,
1650                                   bulk_data_param_t *bulkdata)
1651{
1652    CsrResult status = CSR_RESULT_SUCCESS;
1653    CSR_SIGNAL signal;
1654    int result;
1655#ifdef CSR_SUPPORT_SME
1656   CsrWifiRouterCtrlStaInfo_t *staRecord = NULL;
1657    const u8 *macHdrLocation =  bulkdata->d[0].os_data_ptr;
1658    CsrWifiPacketType pktType;
1659    int frameType = 0;
1660    u8 queuePacketDozing = FALSE;
1661    u32 priority_q;
1662    u16 frmCtrl;
1663    struct list_head * list = NULL; /* List to which buffered PDUs are to be enqueued*/
1664    u8 setBcTim=FALSE;
1665    netInterface_priv_t *interfacePriv;
1666    u8 requeueOnSamePos = FALSE;
1667    u32 handle = 0xFFFFFFFF;
1668    unsigned long lock_flags;
1669
1670        unifi_trace(priv, UDBG5,
1671                "entering uf_process_ma_packet_req, peer: %pMF\n",
1672                peerMacAddress);
1673
1674    if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
1675        unifi_error(priv, "interfaceTag >= CSR_WIFI_NUM_INTERFACES, interfacetag = %d\n", interfaceTag);
1676        return CSR_RESULT_FAILURE;
1677    }
1678    interfacePriv = priv->interfacePriv[interfaceTag];
1679
1680
1681    /* fetch the station record for corresponding peer mac address */
1682    if ((staRecord = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, peerMacAddress, interfaceTag))) {
1683        handle = staRecord->assignedHandle;
1684    }
1685
1686    /* Frame ma-packet.req, this is saved/transmitted depend on queue state */
1687    unifi_frame_ma_packet_req(priv, priority, TransmitRate, hostTag,
1688                              interfaceTag, transmissionControl, leSenderProcessId,
1689                              peerMacAddress, &signal);
1690
1691   /* Since it's common path between STA & AP mode, in case of STA packet
1692     * need not to be queued but in AP case we have to queue PDU's in
1693     * different scenarios
1694     */
1695    switch(interfacePriv->interfaceMode)
1696    {
1697        case CSR_WIFI_ROUTER_CTRL_MODE_AP:
1698        case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
1699            /* For this mode processing done below */
1700            break;
1701        default:
1702            /* In case of STA/IBSS/P2PCLI/AMP, no checks needed send the packet down & return */
1703            unifi_trace(priv, UDBG5, "In %s, interface mode is %x \n", __FUNCTION__, interfacePriv->interfaceMode);
1704            if (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_NONE) {
1705                unifi_warning(priv, "In %s, interface mode NONE \n", __FUNCTION__);
1706            }
1707            if ((result = ul_send_signal_unpacked(priv, &signal, bulkdata))) {
1708                status = CSR_RESULT_FAILURE;
1709            }
1710            return status;
1711    }
1712
1713    /* -----Only AP/P2pGO mode handling falls below----- */
1714
1715    /* convert priority to queue */
1716    priority_q = unifi_frame_priority_to_queue((CSR_PRIORITY) priority);
1717
1718    /* check the powersave status of the peer */
1719    if (staRecord && (staRecord->currentPeerState ==
1720                     CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE)) {
1721        /* Peer is dozing & packet have to be delivered, so buffer the packet &
1722         * update the TIM
1723         */
1724        queuePacketDozing = TRUE;
1725    }
1726
1727    /* find the type of frame unicast or mulicast/broadcast */
1728    if (*peerMacAddress & 0x1) {
1729        /* Multicast/broadCast data are always triggered by vif_availability.ind
1730         * at the DTIM
1731         */
1732        pktType = CSR_WIFI_MULTICAST_PDU;
1733    } else {
1734        pktType = CSR_WIFI_UNICAST_PDU;
1735    }
1736
1737    /* Fetch the frame control field from mac header & check for frame type */
1738    frmCtrl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(macHdrLocation);
1739
1740    /* Processing done according to Frame/Packet type */
1741    frameType =  ((frmCtrl & 0x000c) >> FRAME_CONTROL_TYPE_FIELD_OFFSET);
1742    switch(frameType)
1743    {
1744        case IEEE802_11_FRAMETYPE_MANAGEMENT:
1745
1746            switch(pktType)
1747            {
1748                case CSR_WIFI_UNICAST_PDU:
1749                    unifi_trace(priv, UDBG5, "management unicast PDU in uf_process_ma_packet_req \n");
1750                    /* push the packet in to the queue with appropriate mgt list */
1751                    if (!staRecord) {
1752                        /* push the packet to the unifi if list is empty (if packet lost how to re-enque) */
1753                        if (list_empty(&interfacePriv->genericMgtFrames)) {
1754#ifdef CSR_SUPPORT_SME
1755                            if(!(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) {
1756#endif
1757
1758                            unifi_trace(priv, UDBG3, "genericMgtFrames list is empty uf_process_ma_packet_req \n");
1759                            result = ul_send_signal_unpacked(priv, &signal, bulkdata);
1760                            /*  reque only on ENOSPC */
1761                            if(result == -ENOSPC) {
1762                                /* requeue the failed packet to genericMgtFrame with same position */
1763                                unifi_trace(priv, UDBG1, "(ENOSPC) Sending genericMgtFrames Failed so buffering\n");
1764                                list = &interfacePriv->genericMgtFrames;
1765                                requeueOnSamePos = TRUE;
1766                            }
1767#ifdef CSR_SUPPORT_SME
1768                            }else{
1769                                list = &interfacePriv->genericMgtFrames;
1770                                unifi_trace(priv, UDBG3, "genericMgtFrames queue empty and dtim started\n hosttag is 0x%x,\n",signal.u.MaPacketRequest.HostTag);
1771                                update_eosp_to_head_of_broadcast_list_head(priv,interfaceTag);
1772                           }
1773#endif
1774                        } else {
1775                            /* Queue the packet to genericMgtFrame of unifi_priv_t data structure */
1776                            list = &interfacePriv->genericMgtFrames;
1777                            unifi_trace(priv, UDBG2, "genericMgtFrames queue not empty\n");
1778                        }
1779                    } else {
1780                        /* check peer power state */
1781                        if (queuePacketDozing || !list_empty(&staRecord->mgtFrames) || IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) {
1782                            /* peer is in dozing mode, so queue packet in mgt frame list of station record */
1783                           /*if multicast traffic is going on, buffer the unicast packets*/
1784                            list = &staRecord->mgtFrames;
1785
1786                            unifi_trace(priv, UDBG1, "staRecord->MgtFrames list empty? = %s, handle = %d, queuePacketDozing = %d\n",
1787                                        (list_empty(&staRecord->mgtFrames))? "YES": "NO", staRecord->assignedHandle, queuePacketDozing);
1788                            if(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)){
1789                                update_eosp_to_head_of_broadcast_list_head(priv,interfaceTag);
1790                            }
1791
1792                        } else {
1793                            unifi_trace(priv, UDBG5, "staRecord->mgtFrames list is empty uf_process_ma_packet_req \n");
1794                            result = ul_send_signal_unpacked(priv, &signal, bulkdata);
1795                            if(result == -ENOSPC) {
1796                                /* requeue the failed packet to staRecord->mgtFrames with same position */
1797                                list = &staRecord->mgtFrames;
1798                                requeueOnSamePos = TRUE;
1799                                unifi_trace(priv, UDBG1, "(ENOSPC) Sending MgtFrames Failed handle = %d so buffering\n",staRecord->assignedHandle);
1800                                priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle);
1801                            } else if (result) {
1802                                status = CSR_RESULT_FAILURE;
1803                            }
1804                        }
1805                    }
1806                    break;
1807                case CSR_WIFI_MULTICAST_PDU:
1808                    unifi_trace(priv, UDBG5, "management multicast/broadcast PDU in uf_process_ma_packet_req 'QUEUE it' \n");
1809                    /* Queue the packet to genericMulticastOrBroadCastMgtFrames of unifi_priv_t data structure
1810                     * will be sent when we receive VIF AVAILABILITY from firmware as part of DTIM
1811                     */
1812
1813                    list = &interfacePriv->genericMulticastOrBroadCastMgtFrames;
1814                    if((interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_IBSS) &&
1815                            (list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames))) {
1816                        setBcTim=TRUE;
1817                    }
1818                    break;
1819                default:
1820                    unifi_error(priv, "condition never meets: packet type unrecognized\n");
1821            }
1822            break;
1823        case IEEE802_11_FRAMETYPE_DATA:
1824            switch(pktType)
1825            {
1826                case CSR_WIFI_UNICAST_PDU:
1827                    unifi_trace(priv, UDBG5, "data unicast PDU in uf_process_ma_packet_req \n");
1828                    /* check peer power state, list status & peer port status */
1829                    if(!staRecord) {
1830                        unifi_error(priv, "In %s unicast but staRecord = NULL\n", __FUNCTION__);
1831                        return CSR_RESULT_FAILURE;
1832                    } else if (queuePacketDozing || isRouterBufferEnabled(priv,priority_q)|| !list_empty(&staRecord->dataPdu[priority_q]) || IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) {
1833                        /* peer is in dozing mode, so queue packet in mgt frame list of station record */
1834                        /* if multicast traffic is going on, buffet the unicast packets */
1835                        unifi_trace(priv, UDBG2, "Enqueued to staRecord->dataPdu[%d] queuePacketDozing=%d,\
1836                                Buffering enabled = %d \n", priority_q,queuePacketDozing,isRouterBufferEnabled(priv,priority_q));
1837                        list = &staRecord->dataPdu[priority_q];
1838                    } else {
1839                        unifi_trace(priv, UDBG5, "staRecord->dataPdu[%d] list is empty uf_process_ma_packet_req \n", priority_q);
1840                        /* Pdu allowed to send to unifi */
1841                        result = ul_send_signal_unpacked(priv, &signal, bulkdata);
1842                        if(result == -ENOSPC) {
1843                            /* requeue the failed packet to staRecord->dataPdu[priority_q] with same position */
1844                            unifi_trace(priv, UDBG1, "(ENOSPC) Sending Unicast DataPDU to queue %d Failed so buffering\n",priority_q);
1845                            requeueOnSamePos = TRUE;
1846                            list = &staRecord->dataPdu[priority_q];
1847                            priv->pausedStaHandle[priority_q]=(u8)(staRecord->assignedHandle);
1848                            if(!isRouterBufferEnabled(priv,priority_q)) {
1849                                unifi_error(priv,"Buffering Not enabled for queue %d \n",priority_q);
1850                            }
1851                        } else if (result) {
1852                            status = CSR_RESULT_FAILURE;
1853                        }
1854                    }
1855                    break;
1856                case CSR_WIFI_MULTICAST_PDU:
1857                    unifi_trace(priv, UDBG5, "data multicast/broadcast PDU in uf_process_ma_packet_req \n");
1858                    /* Queue the packet to genericMulticastOrBroadCastFrames list of unifi_priv_t data structure
1859                     * will be sent when we receive VIF AVAILABILITY from firmware as part of DTIM
1860                     */
1861                    list = &interfacePriv->genericMulticastOrBroadCastFrames;
1862                    if(list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)) {
1863                        setBcTim = TRUE;
1864                    }
1865                    break;
1866                default:
1867                    unifi_error(priv, "condition never meets: packet type un recognized\n");
1868            }
1869            break;
1870        default:
1871            unifi_error(priv, "unrecognized frame type\n");
1872    }
1873    if(list) {
1874        status = enque_tx_data_pdu(priv, bulkdata,list, &signal,requeueOnSamePos);
1875        /* Record no. of packet queued for each peer */
1876        if (staRecord && (pktType == CSR_WIFI_UNICAST_PDU) && (!status)) {
1877            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
1878            staRecord->noOfPktQueued++;
1879            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
1880        }
1881        else if ((pktType == CSR_WIFI_MULTICAST_PDU) && (!status))
1882        {
1883            /* If broadcast Tim is set && queuing is successfull, then only update TIM */
1884            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
1885            interfacePriv->noOfbroadcastPktQueued++;
1886            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
1887        }
1888    }
1889    /* If broadcast Tim is set && queuing is successfull, then only update TIM */
1890    if(setBcTim && !status) {
1891        unifi_trace(priv, UDBG3, "tim set due to broadcast pkt\n");
1892        if (!interfacePriv->bcTimSetReqPendingFlag)
1893        {
1894            update_tim(priv,0,CSR_WIFI_TIM_SET,interfaceTag, handle);
1895        }
1896        else
1897        {
1898            /* Cache the TimSet value so that it will processed immidiatly after
1899            * completing the current setTim Request
1900            */
1901            interfacePriv->bcTimSetReqQueued = CSR_WIFI_TIM_SET;
1902            unifi_trace(priv, UDBG2, "uf_process_ma_packet_req : One more UpdateDTim Request(:%d) Queued \n",
1903                        interfacePriv->bcTimSetReqQueued);
1904        }
1905    } else if(staRecord && staRecord->currentPeerState ==
1906                            CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE) {
1907        if(staRecord->timSet == CSR_WIFI_TIM_RESET || staRecord->timSet == CSR_WIFI_TIM_RESETTING) {
1908            if(!staRecord->wmmOrQosEnabled) {
1909                if(!list_empty(&staRecord->mgtFrames) ||
1910                   !list_empty(&staRecord->dataPdu[3]) ||
1911                   !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION])) {
1912                    unifi_trace(priv, UDBG3, "tim set due to unicast pkt & peer in powersave\n");
1913                    if (!staRecord->timRequestPendingFlag){
1914                        update_tim(priv,staRecord->aid,1,interfaceTag, handle);
1915                    }
1916                    else
1917                    {
1918                        /* Cache the TimSet value so that it will processed immidiatly after
1919                         * completing the current setTim Request
1920                         */
1921                        staRecord->updateTimReqQueued = 1;
1922                        unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
1923                                    staRecord->aid);
1924                    }
1925                }
1926            } else {
1927                /* Check for non delivery enable(i.e trigger enable), all delivery enable & legacy AC for TIM update in firmware */
1928                u8 allDeliveryEnabled = 0, dataAvailable = 0;
1929                /* Check if all AC's are Delivery Enabled */
1930                is_all_ac_deliver_enabled_and_moredata(staRecord, &allDeliveryEnabled, &dataAvailable);
1931                if (uf_is_more_data_for_non_delivery_ac(staRecord) || (allDeliveryEnabled && dataAvailable)
1932                    || (!list_empty(&staRecord->mgtFrames))) {
1933                    if (!staRecord->timRequestPendingFlag) {
1934                        update_tim(priv,staRecord->aid,1,interfaceTag, handle);
1935                    }
1936                    else
1937                    {
1938                        /* Cache the TimSet value so that it will processed immidiatly after
1939                         * completing the current setTim Request
1940                         */
1941                        staRecord->updateTimReqQueued = 1;
1942                        unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
1943                                    staRecord->aid);
1944                    }
1945                }
1946            }
1947        }
1948    }
1949
1950    if((list) && (pktType == CSR_WIFI_UNICAST_PDU && !queuePacketDozing) && !(isRouterBufferEnabled(priv,priority_q)) && !(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) {
1951        unifi_trace(priv, UDBG2, "buffering cleared for queue = %d So resending buffered frames\n",priority_q);
1952        uf_send_buffered_frames(priv, priority_q);
1953    }
1954    unifi_trace(priv, UDBG5, "leaving uf_process_ma_packet_req \n");
1955    return status;
1956#else
1957#ifdef CSR_NATIVE_LINUX
1958    if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
1959        unifi_error(priv, "interfaceTag >= CSR_WIFI_NUM_INTERFACES, interfacetag = %d\n", interfaceTag);
1960        return CSR_RESULT_FAILURE;
1961    }
1962    /* Frame ma-packet.req, this is saved/transmitted depend on queue state */
1963    unifi_frame_ma_packet_req(priv, priority, TransmitRate, hostTag, interfaceTag,
1964            transmissionControl, leSenderProcessId,
1965            peerMacAddress, &signal);
1966    result = ul_send_signal_unpacked(priv, &signal, bulkdata);
1967    if (result) {
1968        return CSR_RESULT_FAILURE;
1969    }
1970#endif
1971    return status;
1972#endif
1973}
1974
1975#ifdef CSR_SUPPORT_SME
1976s8 uf_get_protection_bit_from_interfacemode(unifi_priv_t *priv, u16 interfaceTag, const u8 *daddr)
1977{
1978    s8 protection = 0;
1979    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
1980
1981    switch(interfacePriv->interfaceMode)
1982    {
1983        case CSR_WIFI_ROUTER_CTRL_MODE_STA:
1984        case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
1985        case CSR_WIFI_ROUTER_CTRL_MODE_AMP:
1986        case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
1987            protection = interfacePriv->protect;
1988            break;
1989        case CSR_WIFI_ROUTER_CTRL_MODE_AP:
1990        case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
1991            {
1992                CsrWifiRouterCtrlStaInfo_t *dstStaInfo = NULL;
1993                if (daddr[0] & 0x1) {
1994                    unifi_trace(priv, UDBG3, "broadcast/multicast packet in send_ma_pkt_request\n");
1995                    /* In this mode, the protect member of priv structure has an information of how
1996                     * AP/P2PGO has started, & the member updated in set mode request for AP/P2PGO
1997                     */
1998                    protection = interfacePriv->protect;
1999                } else {
2000                    /* fetch the destination record from staion record database */
2001                    dstStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, daddr, interfaceTag);
2002                    if (!dstStaInfo) {
2003                        unifi_trace(priv, UDBG3, "peer not found in station record in send_ma_pkt_request\n");
2004                        return -1;
2005                    }
2006                    protection = dstStaInfo->protection;
2007                }
2008            }
2009            break;
2010        default:
2011            unifi_trace(priv, UDBG2, "mode unknown in send_ma_pkt_request\n");
2012    }
2013    return protection;
2014}
2015#endif
2016#ifdef CSR_SUPPORT_SME
2017u8 send_multicast_frames(unifi_priv_t *priv, u16 interfaceTag)
2018{
2019    int r;
2020    tx_buffered_packets_t * buffered_pkt = NULL;
2021    u8 moreData = FALSE;
2022    u8 pduSent =0;
2023    unsigned long lock_flags;
2024    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2025    u32 hostTag = 0xffffffff;
2026
2027    func_enter();
2028    if(!isRouterBufferEnabled(priv,UNIFI_TRAFFIC_Q_VO)) {
2029        while((interfacePriv->dtimActive)&& (buffered_pkt=dequeue_tx_data_pdu(priv,&interfacePriv->genericMulticastOrBroadCastMgtFrames))) {
2030            buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK);
2031            moreData = (buffered_pkt->transmissionControl & TRANSMISSION_CONTROL_EOSP_MASK)?FALSE:TRUE;
2032
2033
2034            unifi_trace(priv,UDBG2,"DTIM Occurred for interface:sending Mgt packet %d\n",interfaceTag);
2035
2036            if((r=frame_and_send_queued_pdu(priv,buffered_pkt,NULL,moreData,FALSE)) == -ENOSPC) {
2037               unifi_trace(priv,UDBG1,"frame_and_send_queued_pdu failed with ENOSPC for host tag = %x\n", buffered_pkt->hostTag);
2038               /* Enqueue at the head of the queue */
2039               spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
2040               list_add(&buffered_pkt->q, &interfacePriv->genericMulticastOrBroadCastMgtFrames);
2041               spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
2042               break;
2043            } else {
2044                unifi_trace(priv,UDBG1,"send_multicast_frames: Send genericMulticastOrBroadCastMgtFrames (%x, %x)\n",
2045                                        buffered_pkt->hostTag,
2046                                        r);
2047                if(r) {
2048                   unifi_net_data_free(priv, &buffered_pkt->bulkdata);
2049                }
2050                if(!moreData) {
2051
2052                    interfacePriv->dtimActive = FALSE;
2053                    if(!r) {
2054                        hostTag = buffered_pkt->hostTag;
2055                        pduSent++;
2056                    } else {
2057                        send_vif_availibility_rsp(priv,uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag),CSR_RC_UNSPECIFIED_FAILURE);
2058                    }
2059                }
2060                /* Buffered frame sent successfully */
2061                spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2062                interfacePriv->noOfbroadcastPktQueued--;
2063                spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2064                kfree(buffered_pkt);
2065           }
2066
2067        }
2068    }
2069    if(!isRouterBufferEnabled(priv,UNIFI_TRAFFIC_Q_CONTENTION)) {
2070        while((interfacePriv->dtimActive)&& (buffered_pkt=dequeue_tx_data_pdu(priv,&interfacePriv->genericMulticastOrBroadCastFrames))) {
2071            buffered_pkt->transmissionControl |= TRANSMISSION_CONTROL_TRIGGER_MASK;
2072            moreData = (buffered_pkt->transmissionControl & TRANSMISSION_CONTROL_EOSP_MASK)?FALSE:TRUE;
2073
2074
2075            if((r=frame_and_send_queued_pdu(priv,buffered_pkt,NULL,moreData,FALSE)) == -ENOSPC) {
2076                /* Clear the trigger bit transmission control*/
2077                buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK);
2078                /* Enqueue at the head of the queue */
2079                spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
2080                list_add(&buffered_pkt->q, &interfacePriv->genericMulticastOrBroadCastFrames);
2081                spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
2082                break;
2083            } else {
2084                if(r) {
2085                    unifi_trace(priv,UDBG1,"send_multicast_frames: Send genericMulticastOrBroadCastFrame failed (%x, %x)\n",
2086                                            buffered_pkt->hostTag,
2087                                            r);
2088                    unifi_net_data_free(priv, &buffered_pkt->bulkdata);
2089                }
2090                if(!moreData) {
2091                    interfacePriv->dtimActive = FALSE;
2092                    if(!r) {
2093                        pduSent ++;
2094                        hostTag = buffered_pkt->hostTag;
2095                    } else {
2096                        send_vif_availibility_rsp(priv,uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag),CSR_RC_UNSPECIFIED_FAILURE);
2097                    }
2098                }
2099                /* Buffered frame sent successfully */
2100                spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2101                interfacePriv->noOfbroadcastPktQueued--;
2102                spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2103                kfree(buffered_pkt);
2104            }
2105        }
2106    }
2107    if((interfacePriv->dtimActive == FALSE)) {
2108        /* Record the host Tag*/
2109        unifi_trace(priv,UDBG2,"send_multicast_frames: Recorded hostTag of EOSP packet: = 0x%x\n",hostTag);
2110        interfacePriv->multicastPduHostTag = hostTag;
2111    }
2112    return pduSent;
2113}
2114#endif
2115void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv,u8 *sigdata,
2116                                        u32 siglen)
2117{
2118#ifdef CSR_SUPPORT_SME
2119    CSR_SIGNAL signal;
2120    CSR_MA_VIF_AVAILABILITY_INDICATION *ind;
2121    int r;
2122    u16 interfaceTag;
2123    u8 pduSent =0;
2124    CSR_RESULT_CODE resultCode = CSR_RC_SUCCESS;
2125    netInterface_priv_t *interfacePriv;
2126
2127    func_enter();
2128    unifi_trace(priv, UDBG3,
2129            "uf_process_ma_vif_availibility_ind: Process signal 0x%.4X\n",
2130            *((u16*)sigdata));
2131
2132    r = read_unpack_signal(sigdata, &signal);
2133    if (r) {
2134        unifi_error(priv,
2135                    "uf_process_ma_vif_availibility_ind: Received unknown signal 0x%.4X.\n",
2136                    CSR_GET_UINT16_FROM_LITTLE_ENDIAN(sigdata));
2137        func_exit();
2138        return;
2139    }
2140    ind = &signal.u.MaVifAvailabilityIndication;
2141    interfaceTag=ind->VirtualInterfaceIdentifier & 0xff;
2142
2143    if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
2144        unifi_error(priv, "in vif_availability_ind interfaceTag is wrong\n");
2145        return;
2146    }
2147
2148    interfacePriv = priv->interfacePriv[interfaceTag];
2149
2150    if(ind->Multicast) {
2151        if(list_empty(&interfacePriv->genericMulticastOrBroadCastFrames) &&
2152            list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames)) {
2153            /* This condition can occur because of a potential race where the
2154               TIM is not yet reset as host is waiting for confirm but it is sent
2155               by firmware and DTIM occurs*/
2156            unifi_notice(priv,"ma_vif_availibility_ind recevied for multicast but queues are empty%d\n",interfaceTag);
2157            send_vif_availibility_rsp(priv,ind->VirtualInterfaceIdentifier,CSR_RC_NO_BUFFERED_BROADCAST_MULTICAST_FRAMES);
2158            interfacePriv->dtimActive = FALSE;
2159            if(interfacePriv->multicastPduHostTag == 0xffffffff) {
2160                unifi_notice(priv,"ma_vif_availibility_ind recevied for multicast but queues are empty%d\n",interfaceTag);
2161                /* This may be an extra request in very rare race conditions but it is fine as it would atleast remove the potential lock up */
2162                if (!interfacePriv->bcTimSetReqPendingFlag)
2163                {
2164                    update_tim(priv,0,CSR_WIFI_TIM_RESET,interfaceTag, 0xFFFFFFFF);
2165                }
2166                else
2167                {
2168                    /* Cache the TimSet value so that it will processed immidiatly after
2169                     * completing the current setTim Request
2170                     */
2171                    interfacePriv->bcTimSetReqQueued = CSR_WIFI_TIM_RESET;
2172                    unifi_trace(priv, UDBG2, "uf_process_ma_vif_availibility_ind : One more UpdateDTim Request(%d) Queued \n",
2173                                interfacePriv->bcTimSetReqQueued);
2174                }
2175            }
2176            return;
2177        }
2178        if(interfacePriv->dtimActive) {
2179            unifi_trace(priv,UDBG2,"DTIM Occurred for already active DTIM interface %d\n",interfaceTag);
2180            return;
2181        } else {
2182            unifi_trace(priv,UDBG2,"DTIM Occurred for interface %d\n",interfaceTag);
2183            if(list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)) {
2184                set_eosp_transmit_ctrl(priv,&interfacePriv->genericMulticastOrBroadCastMgtFrames);
2185            } else {
2186                set_eosp_transmit_ctrl(priv,&interfacePriv->genericMulticastOrBroadCastFrames);
2187            }
2188        }
2189        interfacePriv->dtimActive = TRUE;
2190        pduSent = send_multicast_frames(priv,interfaceTag);
2191    }
2192    else {
2193        unifi_error(priv,"Interface switching is not supported %d\n",interfaceTag);
2194        resultCode = CSR_RC_NOT_SUPPORTED;
2195        send_vif_availibility_rsp(priv,ind->VirtualInterfaceIdentifier,CSR_RC_NOT_SUPPORTED);
2196    }
2197#endif
2198}
2199#ifdef CSR_SUPPORT_SME
2200
2201#define  GET_ACTIVE_INTERFACE_TAG(priv) 0
2202
2203static u8 uf_is_more_data_for_delivery_ac(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t *staRecord)
2204{
2205    s8 i;
2206
2207    for(i=UNIFI_TRAFFIC_Q_VO; i >= UNIFI_TRAFFIC_Q_BK; i--)
2208    {
2209        if(((staRecord->powersaveMode[i]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)
2210             ||(staRecord->powersaveMode[i]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED))
2211             &&(!list_empty(&staRecord->dataPdu[i]))) {
2212            unifi_trace(priv,UDBG2,"uf_is_more_data_for_delivery_ac: Data Available AC = %d\n", i);
2213            return TRUE;
2214        }
2215    }
2216
2217    unifi_trace(priv,UDBG2,"uf_is_more_data_for_delivery_ac: Data NOT Available \n");
2218    return FALSE;
2219}
2220
2221static u8 uf_is_more_data_for_usp_delivery(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t *staRecord, unifi_TrafficQueue queue)
2222{
2223    s8 i;
2224
2225    for(i = queue; i >= UNIFI_TRAFFIC_Q_BK; i--)
2226    {
2227        if(((staRecord->powersaveMode[i]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)
2228             ||(staRecord->powersaveMode[i]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED))
2229             &&(!list_empty(&staRecord->dataPdu[i]))) {
2230            unifi_trace(priv,UDBG2,"uf_is_more_data_for_usp_delivery: Data Available AC = %d\n", i);
2231            return TRUE;
2232        }
2233    }
2234
2235    unifi_trace(priv,UDBG2,"uf_is_more_data_for_usp_delivery: Data NOT Available \n");
2236    return FALSE;
2237}
2238
2239/*
2240 * ---------------------------------------------------------------------------
2241 *  uf_send_buffered_data_from_delivery_ac
2242 *
2243 *      This function takes care of
2244 *      -> Parsing the delivery enabled queue & sending frame down to HIP
2245 *      -> Setting EOSP=1 when USP to be terminated
2246 *      -> Depending on MAX SP length services the USP
2247 *
2248 * NOTE:This function always called from uf_handle_uspframes_delivery(), Dont
2249 *      call this function from any other location in code
2250 *
2251 *  Arguments:
2252 *      priv        Pointer to device private context struct
2253 *      vif         interface specific HIP vif instance
2254 *      staInfo     peer for which UAPSD to be scheduled
2255 *      queue       AC from which Data to be sent in USP
2256 *      txList      access category for processing list
2257 * ---------------------------------------------------------------------------
2258 */
2259void uf_send_buffered_data_from_delivery_ac(unifi_priv_t *priv,
2260                                            CsrWifiRouterCtrlStaInfo_t * staInfo,
2261                                            u8 queue,
2262                                            struct list_head *txList)
2263{
2264
2265    u16 interfaceTag = GET_ACTIVE_INTERFACE_TAG(priv);
2266    tx_buffered_packets_t * buffered_pkt = NULL;
2267    unsigned long lock_flags;
2268    u8 eosp=FALSE;
2269    s8 r =0;
2270    u8 moreData = FALSE;
2271    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2272
2273    unifi_trace(priv, UDBG2, "++uf_send_buffered_data_from_delivery_ac, active=%x\n", staInfo->uapsdActive);
2274
2275    if (queue > UNIFI_TRAFFIC_Q_VO)
2276    {
2277        return;
2278    }
2279    while((buffered_pkt=dequeue_tx_data_pdu(priv, txList))) {
2280        if((IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) {
2281            unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac: DTIM Active, suspend UAPSD, staId: 0x%x\n",
2282                        staInfo->aid);
2283
2284            /* Once resume called, the U-APSD delivery operation will resume */
2285            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2286            staInfo->uspSuspend = TRUE;
2287            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2288            /* re-queueing the packet as DTIM started */
2289            spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
2290            list_add(&buffered_pkt->q,txList);
2291            spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
2292            break;
2293        }
2294
2295        buffered_pkt->transmissionControl &=
2296                 ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
2297
2298
2299        if((staInfo->wmmOrQosEnabled == TRUE)&&(staInfo->uapsdActive == TRUE)) {
2300
2301             buffered_pkt->transmissionControl = TRANSMISSION_CONTROL_TRIGGER_MASK;
2302
2303             /* Check All delivery enables Ac for more data, because caller of this
2304              * function not aware about last packet
2305              * (First check in moreData fetching helps in draining out Mgt frames Q)
2306              */
2307              moreData = (!list_empty(txList) || uf_is_more_data_for_usp_delivery(priv, staInfo, queue));
2308
2309              if(staInfo->noOfSpFramesSent == (staInfo->maxSpLength - 1)) {
2310                  moreData = FALSE;
2311              }
2312
2313              if(moreData == FALSE) {
2314                  eosp = TRUE;
2315                  buffered_pkt->transmissionControl =
2316                      (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
2317              }
2318        } else {
2319            /* Non QoS and non U-APSD */
2320            unifi_warning(priv, "uf_send_buffered_data_from_delivery_ac: non U-APSD !!! \n");
2321        }
2322
2323        unifi_trace(priv,UDBG2,"uf_send_buffered_data_from_delivery_ac : MoreData:%d, EOSP:%d\n",moreData,eosp);
2324
2325        if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,moreData,eosp)) == -ENOSPC) {
2326
2327            unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac: UASPD suspended, ENOSPC in hipQ=%x\n", queue);
2328
2329            /* Once resume called, the U-APSD delivery operation will resume */
2330            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2331            staInfo->uspSuspend = TRUE;
2332            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2333
2334            spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
2335            list_add(&buffered_pkt->q,txList);
2336            spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
2337            priv->pausedStaHandle[queue]=(u8)(staInfo->assignedHandle);
2338            break;
2339        } else {
2340            if(r){
2341                /* the PDU failed where we can't do any thing so free the storage */
2342                unifi_net_data_free(priv, &buffered_pkt->bulkdata);
2343            }
2344            kfree(buffered_pkt);
2345            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2346            staInfo->noOfSpFramesSent++;
2347            if((!moreData) || (staInfo->noOfSpFramesSent == staInfo->maxSpLength)) {
2348                unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac: Terminating USP\n");
2349                staInfo->uapsdActive = FALSE;
2350                staInfo->uspSuspend = FALSE;
2351                staInfo->noOfSpFramesSent = 0;
2352                spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2353                break;
2354            }
2355            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2356        }
2357    }
2358    unifi_trace(priv, UDBG2, "--uf_send_buffered_data_from_delivery_ac, active=%x\n", staInfo->uapsdActive);
2359}
2360
2361void uf_send_buffered_data_from_ac(unifi_priv_t *priv,
2362                                   CsrWifiRouterCtrlStaInfo_t * staInfo,
2363                                   u8 queue,
2364                                   struct list_head *txList)
2365{
2366    tx_buffered_packets_t * buffered_pkt = NULL;
2367    unsigned long lock_flags;
2368    u8 eosp=FALSE;
2369    u8 moreData = FALSE;
2370    s8 r =0;
2371
2372    func_enter();
2373
2374    unifi_trace(priv,UDBG2,"uf_send_buffered_data_from_ac :\n");
2375
2376    while(!isRouterBufferEnabled(priv,queue) &&
2377                    ((buffered_pkt=dequeue_tx_data_pdu(priv, txList))!=NULL)){
2378
2379        buffered_pkt->transmissionControl &=
2380                 ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK);
2381
2382        unifi_trace(priv,UDBG3,"uf_send_buffered_data_from_ac : MoreData:%d, EOSP:%d\n",moreData,eosp);
2383
2384        if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,moreData,eosp)) == -ENOSPC) {
2385           /* Enqueue at the head of the queue */
2386           spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
2387           list_add(&buffered_pkt->q,txList);
2388           spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
2389           if(staInfo != NULL){
2390              priv->pausedStaHandle[queue]=(u8)(staInfo->assignedHandle);
2391           }
2392           unifi_trace(priv,UDBG3," uf_send_buffered_data_from_ac: PDU sending failed .. no space for queue %d \n",queue);
2393           } else {
2394            if(r){
2395                /* the PDU failed where we can't do any thing so free the storage */
2396                unifi_net_data_free(priv, &buffered_pkt->bulkdata);
2397            }
2398            kfree(buffered_pkt);
2399      }
2400  }
2401
2402  func_exit();
2403
2404}
2405
2406void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q)
2407{
2408    u16 interfaceTag = GET_ACTIVE_INTERFACE_TAG(priv);
2409    u32 startIndex=0,endIndex=0;
2410    CsrWifiRouterCtrlStaInfo_t * staInfo = NULL;
2411    u8 queue;
2412    u8 moreData = FALSE;
2413
2414    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2415
2416    if(!((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP) ||
2417        (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)))
2418        return;
2419    func_enter();
2420
2421    queue = (q<=3)?q:0;
2422
2423    if(interfacePriv->dtimActive) {
2424        /* this function updates dtimActive*/
2425        send_multicast_frames(priv,interfaceTag);
2426        if(!interfacePriv->dtimActive) {
2427            moreData = (!list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames) ||
2428             !list_empty(&interfacePriv->genericMulticastOrBroadCastFrames));
2429            if(!moreData) {
2430                if (!interfacePriv->bcTimSetReqPendingFlag)
2431                {
2432                    update_tim(priv,0,CSR_WIFI_TIM_RESET,interfaceTag, 0XFFFFFFFF);
2433                }
2434                else
2435                {
2436                    /* Cache the TimSet value so that it will processed immidiatly after
2437                     * completing the current setTim Request
2438                     */
2439                    interfacePriv->bcTimSetReqQueued = CSR_WIFI_TIM_RESET;
2440                    unifi_trace(priv, UDBG2, "uf_send_buffered_frames : One more UpdateDTim Request(%d) Queued \n",
2441                                interfacePriv->bcTimSetReqQueued);
2442                }
2443            }
2444        } else {
2445            moreData = (!list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames) ||
2446                        !list_empty(&interfacePriv->genericMulticastOrBroadCastFrames));
2447           if(!moreData) {
2448               /* This should never happen but if it happens, we need a way out */
2449               unifi_error(priv,"ERROR: No More Data but DTIM is active sending Response\n");
2450               send_vif_availibility_rsp(priv,uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag),CSR_RC_NO_BUFFERED_BROADCAST_MULTICAST_FRAMES);
2451               interfacePriv->dtimActive = FALSE;
2452           }
2453        }
2454        func_exit();
2455        return;
2456    }
2457    if(priv->pausedStaHandle[queue] > 7) {
2458        priv->pausedStaHandle[queue] = 0;
2459    }
2460
2461    if(queue == UNIFI_TRAFFIC_Q_VO) {
2462
2463
2464        unifi_trace(priv,UDBG2,"uf_send_buffered_frames : trying mgt from queue=%d\n",queue);
2465        for(startIndex= 0; startIndex < UNIFI_MAX_CONNECTIONS;startIndex++) {
2466            staInfo =  CsrWifiRouterCtrlGetStationRecordFromHandle(priv,startIndex,interfaceTag);
2467            if(!staInfo ) {
2468                continue;
2469            } else if((staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE)
2470                       &&(staInfo->uapsdActive == FALSE) ) {
2471                continue;
2472            }
2473
2474            if((staInfo != NULL)&&(staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE)
2475                               &&(staInfo->uapsdActive == FALSE)){
2476                            /*Non-UAPSD case push the management frames out*/
2477               if(!list_empty(&staInfo->mgtFrames)){
2478                    uf_send_buffered_data_from_ac(priv,staInfo, UNIFI_TRAFFIC_Q_VO, &staInfo->mgtFrames);
2479                }
2480            }
2481
2482            if(isRouterBufferEnabled(priv,queue)) {
2483                unifi_notice(priv,"uf_send_buffered_frames : No space Left for queue = %d\n",queue);
2484                break;
2485            }
2486        }
2487        /*push generic management frames out*/
2488        if(!list_empty(&interfacePriv->genericMgtFrames)) {
2489            unifi_trace(priv,UDBG2,"uf_send_buffered_frames : trying generic mgt from queue=%d\n",queue);
2490            uf_send_buffered_data_from_ac(priv,staInfo, UNIFI_TRAFFIC_Q_VO, &interfacePriv->genericMgtFrames);
2491        }
2492    }
2493
2494
2495    unifi_trace(priv,UDBG2,"uf_send_buffered_frames : Resume called for Queue=%d\n",queue);
2496    unifi_trace(priv,UDBG2,"uf_send_buffered_frames : start=%d end=%d\n",startIndex,endIndex);
2497
2498    startIndex = priv->pausedStaHandle[queue];
2499    endIndex = (startIndex + UNIFI_MAX_CONNECTIONS -1) % UNIFI_MAX_CONNECTIONS;
2500
2501    while(startIndex != endIndex) {
2502        staInfo =  CsrWifiRouterCtrlGetStationRecordFromHandle(priv,startIndex,interfaceTag);
2503        if(!staInfo) {
2504            startIndex ++;
2505            if(startIndex >= UNIFI_MAX_CONNECTIONS) {
2506                startIndex = 0;
2507            }
2508            continue;
2509        } else if((staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE)
2510                   &&(staInfo->uapsdActive == FALSE)) {
2511            startIndex ++;
2512            if(startIndex >= UNIFI_MAX_CONNECTIONS) {
2513                startIndex = 0;
2514            }
2515            continue;
2516        }
2517        /* Peer is active or U-APSD is active so send PDUs to the peer */
2518        unifi_trace(priv,UDBG2,"uf_send_buffered_frames : trying data from queue=%d\n",queue);
2519
2520
2521        if((staInfo != NULL)&&(staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE)
2522                           &&(staInfo->uapsdActive == FALSE)) {
2523           if(!list_empty(&staInfo->dataPdu[queue])) {
2524
2525               /*Non-UAPSD case push the AC frames out*/
2526               uf_send_buffered_data_from_ac(priv, staInfo, queue, (&staInfo->dataPdu[queue]));
2527           }
2528        }
2529        startIndex ++;
2530        if(startIndex >= UNIFI_MAX_CONNECTIONS) {
2531           startIndex = 0;
2532        }
2533    }
2534    if(isRouterBufferEnabled(priv,queue)) {
2535        priv->pausedStaHandle[queue] = endIndex;
2536    } else {
2537        priv->pausedStaHandle[queue] = 0;
2538    }
2539
2540    /* U-APSD might have stopped because of ENOSPC in lib_hip (pause activity).
2541     * So restart it if U-APSD was active with any of the station
2542     */
2543    unifi_trace(priv, UDBG4, "csrWifiHipSendBufferedFrames: UAPSD Resume Q=%x\n", queue);
2544    resume_suspended_uapsd(priv, interfaceTag);
2545    func_exit();
2546}
2547
2548
2549u8 uf_is_more_data_for_non_delivery_ac(CsrWifiRouterCtrlStaInfo_t *staRecord)
2550{
2551    u8 i;
2552
2553    for(i=0;i<=3;i++)
2554    {
2555        if(((staRecord->powersaveMode[i]==CSR_WIFI_AC_TRIGGER_ONLY_ENABLED)
2556                ||(staRecord->powersaveMode[i]==CSR_WIFI_AC_LEGACY_POWER_SAVE))
2557                &&(!list_empty(&staRecord->dataPdu[i]))){
2558
2559         return TRUE;
2560        }
2561    }
2562
2563    if(((staRecord->powersaveMode[UNIFI_TRAFFIC_Q_VO]==CSR_WIFI_AC_TRIGGER_ONLY_ENABLED)
2564            ||(staRecord->powersaveMode[UNIFI_TRAFFIC_Q_VO]==CSR_WIFI_AC_LEGACY_POWER_SAVE))
2565            &&(!list_empty(&staRecord->mgtFrames))){
2566
2567     return TRUE;
2568    }
2569
2570
2571
2572    return FALSE;
2573}
2574
2575
2576int uf_process_station_records_for_sending_data(unifi_priv_t *priv,u16 interfaceTag,
2577                                                 CsrWifiRouterCtrlStaInfo_t *srcStaInfo,
2578                                                 CsrWifiRouterCtrlStaInfo_t *dstStaInfo)
2579{
2580    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2581
2582    unifi_trace(priv, UDBG5, "entering uf_process_station_records_for_sending_data\n");
2583
2584    if (srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_DISCONNECTED) {
2585        unifi_error(priv, "Peer State not connected AID = %x, handle = %x, control port state = %x\n",
2586                    srcStaInfo->aid, srcStaInfo->assignedHandle, srcStaInfo->peerControlledPort->port_action);
2587        return -1;
2588    }
2589    switch (interfacePriv->interfaceMode)
2590    {
2591        case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
2592        case CSR_WIFI_ROUTER_CTRL_MODE_AP:
2593            unifi_trace(priv, UDBG5, "mode is AP/P2PGO\n");
2594            break;
2595        default:
2596            unifi_warning(priv, "mode is nor AP neither P2PGO, packet cant be xmit\n");
2597            return -1;
2598    }
2599
2600    switch(dstStaInfo->peerControlledPort->port_action)
2601    {
2602        case CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD:
2603        case CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_BLOCK:
2604            unifi_trace(priv, UDBG5, "destination port is closed/blocked, discarding the packet\n");
2605            return -1;
2606        default:
2607            unifi_trace(priv, UDBG5, "destination port state is open\n");
2608    }
2609
2610    /* port state is open, destination station record is valid, Power save state is
2611     * validated in uf_process_ma_packet_req function
2612     */
2613    unifi_trace(priv, UDBG5, "leaving uf_process_station_records_for_sending_data\n");
2614    return 0;
2615}
2616
2617
2618/*
2619 * ---------------------------------------------------------------------------
2620 *  uf_handle_uspframes_delivery
2621 *
2622 *      This function takes care of handling USP session for peer, when
2623 *      -> trigger frame from peer
2624 *      -> suspended USP to be processed (resumed)
2625 *
2626 *      NOTE: uf_send_buffered_data_from_delivery_ac() always called from this function, Dont
2627 *      make a direct call to uf_send_buffered_data_from_delivery_ac() from any other part of
2628 *      code
2629 *
2630 *  Arguments:
2631 *      priv            Pointer to device private context struct
2632 *      staInfo         peer for which UAPSD to be scheduled
2633 *      interfaceTag    virtual interface tag
2634 * ---------------------------------------------------------------------------
2635 */
2636static void uf_handle_uspframes_delivery(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t *staInfo, u16 interfaceTag)
2637{
2638
2639    s8 i;
2640    u8 allDeliveryEnabled = 0, dataAvailable = 0;
2641    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2642    unsigned long lock_flags;
2643
2644    unifi_trace(priv, UDBG2, " ++ uf_handle_uspframes_delivery, uapsd active=%x, suspended?=%x\n",
2645                staInfo->uapsdActive, staInfo->uspSuspend);
2646
2647    /* Check for Buffered frames according to priority order & deliver it
2648     *  1. AC_VO delivery enable & Mgt frames available
2649     *  2. Process remaining Ac's from order AC_VO to AC_BK
2650     */
2651
2652    /* USP initiated by WMMPS enabled peer  & SET the status flag to TRUE */
2653    if (!staInfo->uspSuspend && staInfo->uapsdActive)
2654    {
2655        unifi_notice(priv, "uf_handle_uspframes_delivery: U-APSD already active! STA=%x:%x:%x:%x:%x:%x\n",
2656                staInfo->peerMacAddress.a[0], staInfo->peerMacAddress.a[1],
2657                staInfo->peerMacAddress.a[2], staInfo->peerMacAddress.a[3],
2658                staInfo->peerMacAddress.a[4], staInfo->peerMacAddress.a[5]);
2659        return;
2660    }
2661
2662    spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2663    staInfo->uapsdActive = TRUE;
2664    staInfo->uspSuspend = FALSE;
2665    spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2666
2667    if(((staInfo->powersaveMode[UNIFI_TRAFFIC_Q_VO]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED)||
2668        (staInfo->powersaveMode[UNIFI_TRAFFIC_Q_VO]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE))
2669        && (!list_empty(&staInfo->mgtFrames))) {
2670
2671         /* Management queue has data &&  UNIFI_TRAFFIC_Q_VO is delivery enable */
2672        unifi_trace(priv, UDBG4, "uf_handle_uspframes_delivery: Sending buffered management frames\n");
2673        uf_send_buffered_data_from_delivery_ac(priv, staInfo, UNIFI_TRAFFIC_Q_VO, &staInfo->mgtFrames);
2674    }
2675
2676    if (!uf_is_more_data_for_delivery_ac(priv, staInfo)) {
2677        /* All delivery enable AC's are empty, so QNULL to be sent to terminate the USP
2678         * NOTE: If we have sent Mgt frame also, we must send QNULL followed to terminate USP
2679         */
2680        if (!staInfo->uspSuspend) {
2681            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2682            staInfo->uapsdActive = FALSE;
2683            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2684
2685            unifi_trace(priv, UDBG2, "uf_handle_uspframes_delivery: sending QNull for trigger\n");
2686            uf_send_qos_null(priv, interfaceTag, staInfo->peerMacAddress.a, (CSR_PRIORITY) staInfo->triggerFramePriority, staInfo);
2687            staInfo->triggerFramePriority = CSR_QOS_UP0;
2688        } else {
2689            unifi_trace(priv, UDBG2, "uf_handle_uspframes_delivery: MgtQ xfer suspended\n");
2690        }
2691    } else {
2692        for(i = UNIFI_TRAFFIC_Q_VO; i >= UNIFI_TRAFFIC_Q_BK; i--) {
2693            if(((staInfo->powersaveMode[i]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)
2694                ||(staInfo->powersaveMode[i]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED))
2695                && (!list_empty(&staInfo->dataPdu[i]))) {
2696                /* Deliver Data according to AC priority (from VO to BK) as part of USP */
2697                unifi_trace(priv, UDBG4, "uf_handle_uspframes_delivery: Buffered data frames from Queue (%d) for USP\n", i);
2698                uf_send_buffered_data_from_delivery_ac(priv, staInfo, i, &staInfo->dataPdu[i]);
2699            }
2700
2701            if ((!staInfo->uapsdActive) ||
2702                    (staInfo->uspSuspend && IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) {
2703                /* If DTIM active found on one AC, No need to parse the remaining AC's
2704                 * as USP suspended. Break out of loop
2705                 */
2706                unifi_trace(priv, UDBG2, "uf_handle_uspframes_delivery: suspend=%x,  DTIM=%x, USP terminated=%s\n",
2707                           staInfo->uspSuspend, IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag),
2708                           staInfo->uapsdActive?"NO":"YES");
2709                break;
2710            }
2711        }
2712    }
2713
2714    /* Depending on the USP status, update the TIM accordingly for delivery enabled AC only
2715     * (since we are not manipulating any Non-delivery list(AC))
2716     */
2717    is_all_ac_deliver_enabled_and_moredata(staInfo, &allDeliveryEnabled, &dataAvailable);
2718    if ((allDeliveryEnabled && !dataAvailable)) {
2719        if ((staInfo->timSet != CSR_WIFI_TIM_RESET) || (staInfo->timSet != CSR_WIFI_TIM_RESETTING)) {
2720            staInfo->updateTimReqQueued = (u8) CSR_WIFI_TIM_RESET;
2721            unifi_trace(priv, UDBG4, " --uf_handle_uspframes_delivery, UAPSD timset\n");
2722            if (!staInfo->timRequestPendingFlag) {
2723                update_tim(priv, staInfo->aid, 0, interfaceTag, staInfo->assignedHandle);
2724            }
2725        }
2726    }
2727    unifi_trace(priv, UDBG2, " --uf_handle_uspframes_delivery, uapsd active=%x, suspend?=%x\n",
2728                staInfo->uapsdActive, staInfo->uspSuspend);
2729}
2730
2731void uf_process_wmm_deliver_ac_uapsd(unifi_priv_t * priv,
2732                                     CsrWifiRouterCtrlStaInfo_t * srcStaInfo,
2733                                     u16 qosControl,
2734                                     u16 interfaceTag)
2735{
2736    CSR_PRIORITY priority;
2737    unifi_TrafficQueue priority_q;
2738    unsigned long lock_flags;
2739
2740    unifi_trace(priv, UDBG2, "++uf_process_wmm_deliver_ac_uapsd: uapsdactive?=%x\n", srcStaInfo->uapsdActive);
2741    /* If recceived Frames trigger Frame and Devlivery enabled AC has data
2742     * then transmit from High priorty delivery enabled AC
2743     */
2744    priority = (CSR_PRIORITY)(qosControl & IEEE802_11_QC_TID_MASK);
2745    priority_q = unifi_frame_priority_to_queue((CSR_PRIORITY) priority);
2746
2747    if((srcStaInfo->powersaveMode[priority_q]==CSR_WIFI_AC_TRIGGER_ONLY_ENABLED)
2748        ||(srcStaInfo->powersaveMode[priority_q]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED)) {
2749        spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2750        srcStaInfo->triggerFramePriority = priority;
2751        spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2752        unifi_trace(priv, UDBG2, "uf_process_wmm_deliver_ac_uapsd: trigger frame, Begin U-APSD, triggerQ=%x\n", priority_q);
2753        uf_handle_uspframes_delivery(priv, srcStaInfo, interfaceTag);
2754    }
2755    unifi_trace(priv, UDBG2, "--uf_process_wmm_deliver_ac_uapsd: uapsdactive?=%x\n", srcStaInfo->uapsdActive);
2756}
2757
2758
2759void uf_send_qos_null(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo)
2760{
2761    bulk_data_param_t bulkdata;
2762    CsrResult csrResult;
2763    struct sk_buff *skb, *newSkb = NULL;
2764    CsrWifiMacAddress peerAddress;
2765    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2766    CSR_TRANSMISSION_CONTROL transmissionControl = (TRANSMISSION_CONTROL_EOSP_MASK | TRANSMISSION_CONTROL_TRIGGER_MASK);
2767    int r;
2768    CSR_SIGNAL signal;
2769    u32 priority_q;
2770    CSR_RATE transmitRate = 0;
2771
2772
2773    func_enter();
2774    /* Send a Null Frame to Peer,
2775     * 32= size of mac header  */
2776    csrResult = unifi_net_data_malloc(priv, &bulkdata.d[0], MAC_HEADER_SIZE + QOS_CONTROL_HEADER_SIZE);
2777
2778    if (csrResult != CSR_RESULT_SUCCESS) {
2779        unifi_error(priv, " failed to allocate request_data. in uf_send_qos_null func\n");
2780        return ;
2781    }
2782    skb = (struct sk_buff *)(bulkdata.d[0].os_net_buf_ptr);
2783    skb->len = 0;
2784    bulkdata.d[0].os_data_ptr = skb->data;
2785    bulkdata.d[0].os_net_buf_ptr = (unsigned char*)skb;
2786    bulkdata.d[0].net_buf_length = bulkdata.d[0].data_length = skb->len;
2787    bulkdata.d[1].os_data_ptr = NULL;
2788    bulkdata.d[1].os_net_buf_ptr = NULL;
2789    bulkdata.d[1].net_buf_length = bulkdata.d[1].data_length = 0;
2790
2791    /* For null frames protection bit should not be set in MAC header, so passing value 0 below for protection field */
2792
2793    if (prepare_and_add_macheader(priv, skb, newSkb, priority, &bulkdata, interfaceTag, da, interfacePriv->bssid.a, 0)) {
2794        unifi_error(priv, "failed to create MAC header\n");
2795        unifi_net_data_free(priv, &bulkdata.d[0]);
2796        return;
2797    }
2798    memcpy(peerAddress.a, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
2799    /* convert priority to queue */
2800    priority_q = unifi_frame_priority_to_queue((CSR_PRIORITY) priority);
2801
2802    /* Frame ma-packet.req, this is saved/transmitted depend on queue state
2803     * send the null frame at data rate of 1 Mb/s for AP or 6 Mb/s for P2PGO
2804     */
2805    switch (interfacePriv->interfaceMode)
2806    {
2807        case CSR_WIFI_ROUTER_CTRL_MODE_AP:
2808            transmitRate = 2;
2809            break;
2810        case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
2811            transmitRate = 12;
2812            break;
2813        default:
2814            transmitRate = 0;
2815    }
2816    unifi_frame_ma_packet_req(priv, priority, transmitRate, 0xffffffff, interfaceTag,
2817                              transmissionControl, priv->netdev_client->sender_id,
2818                              peerAddress.a, &signal);
2819
2820    r = ul_send_signal_unpacked(priv, &signal, &bulkdata);
2821    if(r) {
2822        unifi_error(priv, "failed to send QOS data null packet result: %d\n",r);
2823        unifi_net_data_free(priv, &bulkdata.d[0]);
2824    }
2825
2826    func_exit();
2827    return;
2828
2829}
2830void uf_send_nulldata(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo)
2831{
2832    bulk_data_param_t bulkdata;
2833    CsrResult csrResult;
2834    struct sk_buff *skb, *newSkb = NULL;
2835    CsrWifiMacAddress peerAddress;
2836    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2837    CSR_TRANSMISSION_CONTROL transmissionControl = 0;
2838    int r;
2839    CSR_SIGNAL signal;
2840    u32 priority_q;
2841    CSR_RATE transmitRate = 0;
2842    CSR_MA_PACKET_REQUEST *req = &signal.u.MaPacketRequest;
2843    unsigned long lock_flags;
2844
2845    func_enter();
2846    /* Send a Null Frame to Peer, size = 24 for MAC header */
2847    csrResult = unifi_net_data_malloc(priv, &bulkdata.d[0], MAC_HEADER_SIZE);
2848
2849    if (csrResult != CSR_RESULT_SUCCESS) {
2850        unifi_error(priv, "uf_send_nulldata: Failed to allocate memory for NULL frame\n");
2851        return ;
2852    }
2853    skb = (struct sk_buff *)(bulkdata.d[0].os_net_buf_ptr);
2854    skb->len = 0;
2855    bulkdata.d[0].os_data_ptr = skb->data;
2856    bulkdata.d[0].os_net_buf_ptr = (unsigned char*)skb;
2857    bulkdata.d[0].net_buf_length = bulkdata.d[0].data_length = skb->len;
2858    bulkdata.d[1].os_data_ptr = NULL;
2859    bulkdata.d[1].os_net_buf_ptr = NULL;
2860    bulkdata.d[1].net_buf_length = bulkdata.d[1].data_length = 0;
2861
2862    /* For null frames protection bit should not be set in MAC header, so passing value 0 below for protection field */
2863    if (prepare_and_add_macheader(priv, skb, newSkb, priority, &bulkdata, interfaceTag, da, interfacePriv->bssid.a, 0)) {
2864        unifi_error(priv, "uf_send_nulldata: Failed to create MAC header\n");
2865        unifi_net_data_free(priv, &bulkdata.d[0]);
2866        return;
2867    }
2868    memcpy(peerAddress.a, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
2869    /* convert priority to queue */
2870    priority_q = unifi_frame_priority_to_queue((CSR_PRIORITY) priority);
2871    transmissionControl &= ~(CSR_NO_CONFIRM_REQUIRED);
2872
2873    /* Frame ma-packet.req, this is saved/transmitted depend on queue state
2874     * send the null frame at data rate of 1 Mb/s for AP or 6 Mb/s for P2PGO
2875     */
2876    switch (interfacePriv->interfaceMode)
2877    {
2878        case CSR_WIFI_ROUTER_CTRL_MODE_AP:
2879            transmitRate = 2;
2880            break;
2881        case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
2882            transmitRate = 12;
2883            break;
2884        default:
2885            transmitRate = 0;
2886    }
2887    unifi_frame_ma_packet_req(priv, priority, transmitRate, INVALID_HOST_TAG, interfaceTag,
2888                              transmissionControl, priv->netdev_client->sender_id,
2889                              peerAddress.a, &signal);
2890
2891    /* Save host tag to check the status on reception of MA packet confirm */
2892    srcStaInfo->nullDataHostTag = req->HostTag;
2893    unifi_trace(priv, UDBG1, "uf_send_nulldata: STA AID = %d hostTag = %x\n", srcStaInfo->aid, req->HostTag);
2894
2895    r = ul_send_signal_unpacked(priv, &signal, &bulkdata);
2896
2897    if(r == -ENOSPC) {
2898        unifi_trace(priv, UDBG1, "uf_send_nulldata: ENOSPC Requeue the Null frame\n");
2899        enque_tx_data_pdu(priv, &bulkdata, &srcStaInfo->dataPdu[priority_q], &signal, 1);
2900        spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2901        srcStaInfo->noOfPktQueued++;
2902        spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2903
2904
2905    }
2906    if(r && r != -ENOSPC){
2907        unifi_error(priv, "uf_send_nulldata: Failed to send Null frame Error = %d\n",r);
2908        unifi_net_data_free(priv, &bulkdata.d[0]);
2909        srcStaInfo->nullDataHostTag = INVALID_HOST_TAG;
2910    }
2911
2912    func_exit();
2913    return;
2914}
2915
2916u8 uf_check_broadcast_bssid(unifi_priv_t *priv, const bulk_data_param_t *bulkdata)
2917{
2918    u8 *bssid = NULL;
2919    static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
2920    u8 toDs, fromDs;
2921
2922    toDs = (((bulkdata->d[0].os_data_ptr)[1]) & 0x01) ? 1 : 0;
2923    fromDs =(((bulkdata->d[0].os_data_ptr)[1]) & 0x02) ? 1 : 0;
2924
2925     if (toDs && fromDs)
2926    {
2927        unifi_trace(priv, UDBG6, "Address 4 present, Don't try to find BSSID\n");
2928        bssid = NULL;
2929    }
2930    else if((toDs == 0) && (fromDs ==0))
2931    {
2932        /* BSSID is Address 3 */
2933        bssid = (u8 *) (bulkdata->d[0].os_data_ptr + 4 + (2 * ETH_ALEN));
2934    }
2935    else if(toDs)
2936    {
2937        /* BSSID is Address 1 */
2938        bssid = (u8 *) (bulkdata->d[0].os_data_ptr + 4);
2939    }
2940    else if(fromDs)
2941    {
2942        /* BSSID is Address 2 */
2943        bssid = (u8 *) (bulkdata->d[0].os_data_ptr + 4 + ETH_ALEN);
2944    }
2945
2946    if (memcmp(broadcast_address.a, bssid, ETH_ALEN)== 0)
2947    {
2948        return TRUE;
2949    }
2950    else
2951    {
2952        return FALSE;
2953    }
2954}
2955
2956
2957u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * srcStaInfo,
2958                                u8 pmBit,u16 interfaceTag)
2959{
2960    u8 moreData = FALSE;
2961    u8 powerSaveChanged = FALSE;
2962    unsigned long lock_flags;
2963
2964    unifi_trace(priv, UDBG3, "entering uf_process_pm_bit_for_peer\n");
2965    if (pmBit) {
2966        priv->allPeerDozing |= (0x01 << (srcStaInfo->assignedHandle));
2967    } else {
2968        priv->allPeerDozing &= ~(0x01 << (srcStaInfo->assignedHandle));
2969    }
2970    if(pmBit) {
2971        if(srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE) {
2972
2973            /* disable the preemption */
2974            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2975            srcStaInfo->currentPeerState =CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE;
2976            powerSaveChanged = TRUE;
2977            /* enable the preemption */
2978            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2979        } else {
2980            return powerSaveChanged;
2981        }
2982    } else {
2983        if(srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE) {
2984            /* disable the preemption */
2985            spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
2986            srcStaInfo->currentPeerState = CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE;
2987            powerSaveChanged = TRUE;
2988            /* enable the preemption */
2989            spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
2990        }else {
2991            return powerSaveChanged;
2992        }
2993    }
2994
2995
2996    if(srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE) {
2997        unifi_trace(priv,UDBG3, "Peer with AID = %d is active now\n",srcStaInfo->aid);
2998        process_peer_active_transition(priv,srcStaInfo,interfaceTag);
2999    } else {
3000        unifi_trace(priv,UDBG3, "Peer with AID = %d is in PS Now\n",srcStaInfo->aid);
3001        /* Set TIM if needed */
3002        if(!srcStaInfo->wmmOrQosEnabled) {
3003            moreData = (!list_empty(&srcStaInfo->mgtFrames) ||
3004                        !list_empty(&srcStaInfo->dataPdu[UNIFI_TRAFFIC_Q_VO])||
3005                        !list_empty(&srcStaInfo->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]));
3006            if(moreData && (srcStaInfo->timSet == CSR_WIFI_TIM_RESET)) {
3007                unifi_trace(priv, UDBG3, "This condition should not occur\n");
3008                if (!srcStaInfo->timRequestPendingFlag){
3009                    update_tim(priv,srcStaInfo->aid,1,interfaceTag, srcStaInfo->assignedHandle);
3010                }
3011                else
3012                {
3013                    /* Cache the TimSet value so that it will processed immidiatly after
3014                     * completing the current setTim Request
3015                     */
3016                    srcStaInfo->updateTimReqQueued = 1;
3017                    unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", srcStaInfo->updateTimReqQueued,
3018                                srcStaInfo->aid);
3019                }
3020
3021            }
3022        } else {
3023            u8 allDeliveryEnabled = 0, dataAvailable = 0;
3024            unifi_trace(priv, UDBG5, "Qos in AP Mode\n");
3025            /* Check if all AC's are Delivery Enabled */
3026            is_all_ac_deliver_enabled_and_moredata(srcStaInfo, &allDeliveryEnabled, &dataAvailable);
3027            /*check for more data in non-delivery enabled queues*/
3028            moreData = (uf_is_more_data_for_non_delivery_ac(srcStaInfo) || (allDeliveryEnabled && dataAvailable));
3029
3030            if(moreData && (srcStaInfo->timSet == CSR_WIFI_TIM_RESET)) {
3031                if (!srcStaInfo->timRequestPendingFlag){
3032                    update_tim(priv,srcStaInfo->aid,1,interfaceTag, srcStaInfo->assignedHandle);
3033                }
3034                else
3035                {
3036                    /* Cache the TimSet value so that it will processed immidiatly after
3037                     * completing the current setTim Request
3038                     */
3039                    srcStaInfo->updateTimReqQueued = 1;
3040                    unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", srcStaInfo->updateTimReqQueued,
3041                                srcStaInfo->aid);
3042                }
3043            }
3044        }
3045    }
3046    unifi_trace(priv, UDBG3, "leaving uf_process_pm_bit_for_peer\n");
3047    return powerSaveChanged;
3048}
3049
3050
3051
3052void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceTag)
3053{
3054    CsrWifiRouterCtrlStaInfo_t *staRecord =
3055    CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, sa, interfaceTag);
3056    tx_buffered_packets_t * buffered_pkt = NULL;
3057    CsrWifiMacAddress peerMacAddress;
3058    unsigned long lock_flags;
3059    s8 r =0;
3060    u8 moreData = FALSE;
3061    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
3062
3063    unifi_trace(priv, UDBG3, "entering uf_process_ps_poll\n");
3064    if(!staRecord) {
3065        memcpy(peerMacAddress.a,sa,ETH_ALEN);
3066        unifi_trace(priv, UDBG3, "In uf_process_ps_poll, sta record not found:unexpected frame addr = %x:%x:%x:%x:%x:%x\n",
3067                sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
3068        CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
3069        return;
3070    }
3071
3072    uf_process_pm_bit_for_peer(priv,staRecord,pmBit,interfaceTag);
3073
3074    /* Update station last activity time */
3075    staRecord->activity_flag = TRUE;
3076
3077    /* This should not change the PM bit as PS-POLL has PM bit always set */
3078    if(!pmBit) {
3079        unifi_notice (priv," PM bit reset in PS-POLL\n");
3080        return;
3081    }
3082
3083    if(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) {
3084        /* giving more priority to multicast packets so dropping ps-poll*/
3085        unifi_notice (priv," multicast transmission is going on so don't take action on PS-POLL\n");
3086        return;
3087    }
3088
3089    if(!staRecord->wmmOrQosEnabled) {
3090        if((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->mgtFrames))) {
3091            buffered_pkt->transmissionControl |= TRANSMISSION_CONTROL_TRIGGER_MASK;
3092            moreData = (!list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]) ||
3093                        !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]) ||
3094                        !list_empty(&staRecord->mgtFrames));
3095
3096            buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3097            if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) {
3098                /* Clear the trigger bit transmission control*/
3099                buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3100                /* Enqueue at the head of the queue */
3101                spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3102                list_add(&buffered_pkt->q, &staRecord->mgtFrames);
3103                spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3104                unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n");
3105                priv->pausedStaHandle[3]=(u8)(staRecord->assignedHandle);
3106            } else {
3107                if(r){
3108                    unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3109                    /* the PDU failed where we can't do any thing so free the storage */
3110                    unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3111                }
3112                kfree(buffered_pkt);
3113            }
3114        } else if((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]))) {
3115            buffered_pkt->transmissionControl |= TRANSMISSION_CONTROL_TRIGGER_MASK;
3116            moreData = (!list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]) ||
3117                        !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]));
3118
3119            buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3120            if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) {
3121                /* Clear the trigger bit transmission control*/
3122                buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3123                /* Enqueue at the head of the queue */
3124                spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3125                list_add(&buffered_pkt->q, &staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]);
3126                spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3127                priv->pausedStaHandle[3]=(u8)(staRecord->assignedHandle);
3128                unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n");
3129            } else {
3130                if(r){
3131                    unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3132                    /* the PDU failed where we can't do any thing so free the storage */
3133                    unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3134                }
3135                kfree(buffered_pkt);
3136            }
3137        } else  if((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]))) {
3138            buffered_pkt->transmissionControl |= TRANSMISSION_CONTROL_TRIGGER_MASK;
3139            moreData = !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]);
3140
3141            buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3142            if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) {
3143                /* Clear the trigger bit transmission control*/
3144                buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3145                /* Enqueue at the head of the queue */
3146                spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3147                list_add(&buffered_pkt->q, &staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]);
3148                spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3149                priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle);
3150                unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n");
3151            } else {
3152                if(r){
3153                    unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3154                    /* the PDU failed where we can't do any thing so free the storage */
3155                    unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3156                }
3157                kfree(buffered_pkt);
3158            }
3159        } else {
3160         /* Actually since we have sent an ACK, there
3161         * there is no need to send a NULL frame*/
3162        }
3163        moreData = (!list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]) ||
3164           !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]) ||
3165            !list_empty(&staRecord->mgtFrames));
3166        if(!moreData && (staRecord->timSet == CSR_WIFI_TIM_SET)) {
3167            unifi_trace(priv, UDBG3, "more data = NULL, set tim to 0 in uf_process_ps_poll\n");
3168            if (!staRecord->timRequestPendingFlag){
3169                update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle);
3170            }
3171            else
3172            {
3173                /* Cache the TimSet value so that it will processed immidiatly after
3174                 * completing the current setTim Request
3175                 */
3176                staRecord->updateTimReqQueued = 0;
3177                unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
3178                            staRecord->aid);
3179            }
3180        }
3181    } else {
3182
3183        u8 allDeliveryEnabled = 0, dataAvailable = 0;
3184        unifi_trace(priv, UDBG3,"Qos Support station.Processing PS-Poll\n");
3185
3186        /*Send Data From Management Frames*/
3187        /* Priority orders for delivering the buffered packets are
3188         * 1. Deliver the Management frames if there
3189         * 2. Other access catagory frames which are non deliver enable including UNIFI_TRAFFIC_Q_VO
3190         * priority is from VO->BK
3191         */
3192
3193        /* Check if all AC's are Delivery Enabled */
3194        is_all_ac_deliver_enabled_and_moredata(staRecord, &allDeliveryEnabled, &dataAvailable);
3195
3196        if (allDeliveryEnabled) {
3197            unifi_trace(priv, UDBG3, "uf_process_ps_poll: All ACs are delivery enable so Sending QOS Null in response of Ps-poll\n");
3198            uf_send_qos_null(priv,interfaceTag,sa,CSR_QOS_UP0,staRecord);
3199            return;
3200        }
3201
3202        if (!list_empty(&staRecord->mgtFrames)) {
3203             if ((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->mgtFrames))) {
3204                    /* We dont have packets in non delivery enabled UNIFI_TRAFFIC_Q_VO, So we are looking in management
3205                     * queue of the station record
3206                     */
3207                    moreData = uf_is_more_data_for_non_delivery_ac(staRecord);
3208                    buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3209
3210                    /* Last parameter is EOSP & its false always for PS-POLL processing */
3211                    if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) {
3212                        /* Clear the trigger bit transmission control*/
3213                        buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3214                        /* Enqueue at the head of the queue */
3215                        spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3216                        list_add(&buffered_pkt->q, &staRecord->mgtFrames);
3217                        spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3218                        priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle);
3219                        unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n");
3220                    } else {
3221                        if(r){
3222                            unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3223                            /* the PDU failed where we can't do any thing so free the storage */
3224                            unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3225                        }
3226                        kfree(buffered_pkt);
3227                    }
3228                } else {
3229                    unifi_error(priv, "uf_process_ps_poll: Mgt frame list empty!! \n");
3230                }
3231
3232        } else {
3233            s8 i;
3234            /* We dont have buffered packet in mangement frame queue (1 failed), So proceed with condition 2
3235             * UNIFI_TRAFFIC_Q_VO -> VI -> BE -> BK
3236             */
3237            for(i= 3; i>=0; i--) {
3238                if (!IS_DELIVERY_ENABLED(staRecord->powersaveMode[i])) {
3239                    /* Send One packet, if queue is NULL then continue */
3240                    if((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->dataPdu[i]))) {
3241                        moreData = uf_is_more_data_for_non_delivery_ac(staRecord);
3242
3243                        buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3244
3245                        /* Last parameter is EOSP & its false always for PS-POLL processing */
3246                        if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) {
3247                            /* Clear the trigger bit transmission control*/
3248                            buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK);
3249                            /* Enqueue at the head of the queue */
3250                            spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3251                            list_add(&buffered_pkt->q, &staRecord->dataPdu[i]);
3252                            spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3253                            priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle);
3254                            unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n");
3255                        } else {
3256                            if(r) {
3257                                unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3258                                /* the PDU failed where we can't do any thing so free the storage */
3259                                unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3260                            }
3261                            kfree(buffered_pkt);
3262                        }
3263                        break;
3264                    }
3265                }
3266            }
3267        }
3268        /* Check if all AC's are Delivery Enabled */
3269        is_all_ac_deliver_enabled_and_moredata(staRecord, &allDeliveryEnabled, &dataAvailable);
3270        /*check for more data in non-delivery enabled queues*/
3271        moreData = (uf_is_more_data_for_non_delivery_ac(staRecord) || (allDeliveryEnabled && dataAvailable));
3272        if(!moreData && (staRecord->timSet == CSR_WIFI_TIM_SET)) {
3273            unifi_trace(priv, UDBG3, "more data = NULL, set tim to 0 in uf_process_ps_poll\n");
3274            if (!staRecord->timRequestPendingFlag){
3275                update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle);
3276            }
3277            else
3278            {
3279                /* Cache the TimSet value so that it will processed immidiatly after
3280                 * completing the current setTim Request
3281                 */
3282                staRecord->updateTimReqQueued = 0;
3283                unifi_trace(priv, UDBG6, "update_tim : One more UpdateTim Request (Tim value:%d) Queued for AID %x\n", staRecord->updateTimReqQueued,
3284                            staRecord->aid);
3285            }
3286
3287        }
3288    }
3289
3290        unifi_trace(priv, UDBG3, "leaving uf_process_ps_poll\n");
3291}
3292
3293
3294
3295void add_to_send_cfm_list(unifi_priv_t * priv,
3296                          tx_buffered_packets_t *tx_q_item,
3297                          struct list_head *frames_need_cfm_list)
3298{
3299    tx_buffered_packets_t *send_cfm_list_item = NULL;
3300
3301    send_cfm_list_item = (tx_buffered_packets_t *) kmalloc(sizeof(tx_buffered_packets_t), GFP_ATOMIC);
3302
3303    if(send_cfm_list_item == NULL){
3304        unifi_warning(priv, "%s: Failed to allocate memory for new list item \n");
3305        return;
3306    }
3307
3308    INIT_LIST_HEAD(&send_cfm_list_item->q);
3309
3310    send_cfm_list_item->hostTag = tx_q_item->hostTag;
3311    send_cfm_list_item->interfaceTag = tx_q_item->interfaceTag;
3312    send_cfm_list_item->transmissionControl = tx_q_item->transmissionControl;
3313    send_cfm_list_item->leSenderProcessId = tx_q_item->leSenderProcessId;
3314    send_cfm_list_item->rate = tx_q_item->rate;
3315    memcpy(send_cfm_list_item->peerMacAddress.a, tx_q_item->peerMacAddress.a, ETH_ALEN);
3316    send_cfm_list_item->priority = tx_q_item->priority;
3317
3318    list_add_tail(&send_cfm_list_item->q, frames_need_cfm_list);
3319}
3320
3321void uf_prepare_send_cfm_list_for_queued_pkts(unifi_priv_t * priv,
3322                                                 struct list_head *frames_need_cfm_list,
3323                                                 struct list_head * list)
3324{
3325    tx_buffered_packets_t *tx_q_item = NULL;
3326    struct list_head *listHead;
3327    struct list_head *placeHolder;
3328    unsigned long lock_flags;
3329
3330    func_enter();
3331
3332    spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3333
3334    /* Search through the list and if confirmation required for any frames,
3335    add it to the send_cfm list */
3336    list_for_each_safe(listHead, placeHolder, list) {
3337        tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
3338
3339        if(!tx_q_item) {
3340            unifi_error(priv, "Entry should exist, otherwise it is a (BUG)\n");
3341            continue;
3342        }
3343
3344        /* check if confirmation is requested and if the sender ID
3345        is not netdevice client then save the entry in the list for need cfms */
3346        if (!(tx_q_item->transmissionControl & CSR_NO_CONFIRM_REQUIRED) &&
3347            (tx_q_item->leSenderProcessId != priv->netdev_client->sender_id)){
3348             unifi_trace(priv, UDBG1, "%s: SenderProcessID=%x host tag=%x transmission control=%x\n",
3349                __FUNCTION__,
3350                tx_q_item->leSenderProcessId,
3351                tx_q_item->hostTag,
3352                tx_q_item->transmissionControl);
3353
3354             add_to_send_cfm_list(priv, tx_q_item, frames_need_cfm_list);
3355        }
3356    }
3357
3358    spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3359
3360    func_exit();
3361}
3362
3363
3364
3365void uf_flush_list(unifi_priv_t * priv, struct list_head * list)
3366{
3367    tx_buffered_packets_t *tx_q_item;
3368    struct list_head *listHead;
3369    struct list_head *placeHolder;
3370    unsigned long lock_flags;
3371
3372    unifi_trace(priv, UDBG5, "entering the uf_flush_list \n");
3373
3374    spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3375    /* go through list, delete & free memory */
3376    list_for_each_safe(listHead, placeHolder, list) {
3377        tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
3378
3379        if(!tx_q_item) {
3380            unifi_error(priv, "entry should exists, otherwise crashes (bug)\n");
3381        }
3382        unifi_trace(priv, UDBG5,
3383                "proccess_tx:  in uf_flush_list peerMacAddress=%02X%02X%02X%02X%02X%02X senderProcessId=%x\n",
3384                tx_q_item->peerMacAddress.a[0], tx_q_item->peerMacAddress.a[1],
3385                tx_q_item->peerMacAddress.a[2], tx_q_item->peerMacAddress.a[3],
3386                tx_q_item->peerMacAddress.a[4], tx_q_item->peerMacAddress.a[5],
3387                tx_q_item->leSenderProcessId);
3388
3389        list_del(listHead);
3390        /* free the allocated memory */
3391        unifi_net_data_free(priv, &tx_q_item->bulkdata);
3392        kfree(tx_q_item);
3393        tx_q_item = NULL;
3394        if (!priv->noOfPktQueuedInDriver) {
3395            unifi_error(priv, "packets queued in driver 0 still decrementing in %s\n", __FUNCTION__);
3396        } else {
3397            priv->noOfPktQueuedInDriver--;
3398        }
3399    }
3400    spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3401}
3402
3403tx_buffered_packets_t *dequeue_tx_data_pdu(unifi_priv_t *priv, struct list_head *txList)
3404{
3405    /* dequeue the tx data packets from the appropriate queue */
3406    tx_buffered_packets_t *tx_q_item = NULL;
3407    struct list_head *listHead;
3408    struct list_head *placeHolder;
3409    unsigned long lock_flags;
3410
3411    unifi_trace(priv, UDBG5, "entering dequeue_tx_data_pdu\n");
3412    /* check for list empty */
3413    if (list_empty(txList)) {
3414        unifi_trace(priv, UDBG5, "In dequeue_tx_data_pdu, the list is empty\n");
3415        return NULL;
3416    }
3417
3418    /* Verification, if packet count is negetive */
3419    if (priv->noOfPktQueuedInDriver == 0xFFFF) {
3420        unifi_warning(priv, "no packet available in queue: debug");
3421        return NULL;
3422    }
3423
3424    /* return first node after header, & delete from the list  && atleast one item exist */
3425    spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3426    list_for_each_safe(listHead, placeHolder, txList) {
3427        tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
3428        list_del(listHead);
3429        break;
3430    }
3431    spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3432
3433    if (tx_q_item) {
3434        unifi_trace(priv, UDBG5,
3435                "proccess_tx:  In dequeue_tx_data_pdu peerMacAddress=%02X%02X%02X%02X%02X%02X senderProcessId=%x\n",
3436                tx_q_item->peerMacAddress.a[0], tx_q_item->peerMacAddress.a[1],
3437                tx_q_item->peerMacAddress.a[2], tx_q_item->peerMacAddress.a[3],
3438                tx_q_item->peerMacAddress.a[4], tx_q_item->peerMacAddress.a[5],
3439                tx_q_item->leSenderProcessId);
3440    }
3441
3442    unifi_trace(priv, UDBG5, "leaving dequeue_tx_data_pdu\n");
3443    return tx_q_item;
3444}
3445/* generic function to get the station record handler */
3446CsrWifiRouterCtrlStaInfo_t *CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(unifi_priv_t *priv,
3447        const u8 *peerMacAddress,
3448        u16 interfaceTag)
3449{
3450    u8 i;
3451    netInterface_priv_t *interfacePriv;
3452    unsigned long lock_flags;
3453
3454    if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
3455        unifi_error(priv, "interfaceTag is not proper, interfaceTag = %d\n", interfaceTag);
3456        return NULL;
3457    }
3458
3459    interfacePriv = priv->interfacePriv[interfaceTag];
3460
3461    /* disable the preemption untill station record is fetched */
3462    spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
3463
3464    for (i = 0; i < UNIFI_MAX_CONNECTIONS; i++) {
3465        if (interfacePriv->staInfo[i]!= NULL) {
3466            if (!memcmp(((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[i]))->peerMacAddress.a, peerMacAddress, ETH_ALEN)) {
3467                /* enable the preemption as station record is fetched */
3468                spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
3469                unifi_trace(priv, UDBG5, "peer entry found in station record\n");
3470                return ((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[i]));
3471            }
3472        }
3473    }
3474    /* enable the preemption as station record is fetched */
3475    spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
3476    unifi_trace(priv, UDBG5, "peer entry not found in station record\n");
3477    return NULL;
3478}
3479/* generic function to get the station record handler from the handle */
3480CsrWifiRouterCtrlStaInfo_t * CsrWifiRouterCtrlGetStationRecordFromHandle(unifi_priv_t *priv,
3481                                                                 u32 handle,
3482                                                                 u16 interfaceTag)
3483{
3484    netInterface_priv_t *interfacePriv;
3485
3486    if ((handle >= UNIFI_MAX_CONNECTIONS) || (interfaceTag >= CSR_WIFI_NUM_INTERFACES)) {
3487        unifi_error(priv, "handle/interfaceTag is not proper, handle = %d, interfaceTag = %d\n", handle, interfaceTag);
3488        return NULL;
3489    }
3490    interfacePriv = priv->interfacePriv[interfaceTag];
3491    return ((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[handle]));
3492}
3493
3494/* Function to do inactivity */
3495void uf_check_inactivity(unifi_priv_t *priv, u16 interfaceTag, CsrTime currentTime)
3496{
3497    u32 i;
3498    CsrWifiRouterCtrlStaInfo_t *staInfo;
3499    CsrTime elapsedTime;    /* Time in microseconds */
3500    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
3501    CsrWifiMacAddress peerMacAddress;
3502    unsigned long lock_flags;
3503
3504    if (interfacePriv == NULL) {
3505        unifi_trace(priv, UDBG3, "uf_check_inactivity: Interface priv is NULL \n");
3506        return;
3507    }
3508
3509    spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
3510    /* Go through the list of stations to check for inactivity */
3511    for(i = 0; i < UNIFI_MAX_CONNECTIONS; i++) {
3512        staInfo =  CsrWifiRouterCtrlGetStationRecordFromHandle(priv, i, interfaceTag);
3513        if(!staInfo ) {
3514            continue;
3515        }
3516
3517        unifi_trace(priv, UDBG3, "Running Inactivity handler Time %xus station's last activity %xus\n",
3518                currentTime, staInfo->lastActivity);
3519
3520
3521        elapsedTime = (currentTime >= staInfo->lastActivity)?
3522                (currentTime - staInfo->lastActivity):
3523                (~((u32)0) - staInfo->lastActivity + currentTime);
3524        spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
3525
3526        if (elapsedTime > MAX_INACTIVITY_INTERVAL) {
3527            memcpy((u8*)&peerMacAddress, (u8*)&staInfo->peerMacAddress, sizeof(CsrWifiMacAddress));
3528
3529            /* Indicate inactivity for the station */
3530            unifi_trace(priv, UDBG3, "Station %x:%x:%x:%x:%x:%x inactive since %xus\n sending Inactive Ind\n",
3531                        peerMacAddress.a[0], peerMacAddress.a[1],
3532                        peerMacAddress.a[2], peerMacAddress.a[3],
3533                        peerMacAddress.a[4], peerMacAddress.a[5],
3534                        elapsedTime);
3535
3536            CsrWifiRouterCtrlStaInactiveIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress);
3537        }
3538    }
3539
3540    interfacePriv->last_inactivity_check = currentTime;
3541}
3542
3543/* Function to update activity of a station */
3544void uf_update_sta_activity(unifi_priv_t *priv, u16 interfaceTag, const u8 *peerMacAddress)
3545{
3546    CsrTime elapsedTime, currentTime;    /* Time in microseconds */
3547    CsrTime timeHi;         /* Not used - Time in microseconds */
3548    CsrWifiRouterCtrlStaInfo_t *staInfo;
3549    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
3550    unsigned long lock_flags;
3551
3552    if (interfacePriv == NULL) {
3553        unifi_trace(priv, UDBG3, "uf_check_inactivity: Interface priv is NULL \n");
3554        return;
3555    }
3556
3557    currentTime = CsrTimeGet(&timeHi);
3558
3559
3560    staInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, peerMacAddress, interfaceTag);
3561
3562    if (staInfo == NULL) {
3563        unifi_trace(priv, UDBG4, "Sta does not exist yet");
3564        return;
3565    }
3566
3567    spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
3568    /* Update activity */
3569    staInfo->lastActivity = currentTime;
3570
3571    /* See if inactivity handler needs to be run
3572     * Here it is theoretically possible that the counter may have wrapped around. But
3573     * since we just want to know when to run the inactivity handler it does not really matter.
3574     * Especially since this is data path it makes sense in keeping it simple and avoiding
3575     * 64 bit handling */
3576    elapsedTime = (currentTime >= interfacePriv->last_inactivity_check)?
3577                    (currentTime - interfacePriv->last_inactivity_check):
3578                    (~((u32)0) - interfacePriv->last_inactivity_check + currentTime);
3579
3580    spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
3581
3582    /* Check if it is time to run the inactivity handler */
3583    if (elapsedTime > INACTIVITY_CHECK_INTERVAL) {
3584        uf_check_inactivity(priv, interfaceTag, currentTime);
3585    }
3586}
3587void resume_unicast_buffered_frames(unifi_priv_t *priv, u16 interfaceTag)
3588{
3589
3590   netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
3591   u8 i;
3592   int j;
3593   tx_buffered_packets_t * buffered_pkt = NULL;
3594   u8 hipslotFree[4] = {TRUE,TRUE,TRUE,TRUE};
3595   int r;
3596   unsigned long lock_flags;
3597
3598   func_enter();
3599   while(!isRouterBufferEnabled(priv,3) &&
3600                            ((buffered_pkt=dequeue_tx_data_pdu(priv,&interfacePriv->genericMgtFrames))!=NULL)) {
3601        buffered_pkt->transmissionControl &=
3602                     ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK);
3603        if((r=frame_and_send_queued_pdu(priv,buffered_pkt,NULL,0,FALSE)) == -ENOSPC) {
3604            /* Enqueue at the head of the queue */
3605            spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3606            list_add(&buffered_pkt->q, &interfacePriv->genericMgtFrames);
3607            spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3608            hipslotFree[3]=FALSE;
3609            break;
3610        }else {
3611            if(r){
3612                unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3613                /* the PDU failed where we can't do any thing so free the storage */
3614                unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3615            }
3616            kfree(buffered_pkt);
3617        }
3618   }
3619   for(i = 0; i < UNIFI_MAX_CONNECTIONS; i++) {
3620        CsrWifiRouterCtrlStaInfo_t *staInfo = interfacePriv->staInfo[i];
3621        if(!hipslotFree[0] && !hipslotFree[1] && !hipslotFree[2] && !hipslotFree[3]) {
3622            unifi_trace(priv, UDBG3, "(ENOSPC) in resume_unicast_buffered_frames:: hip slots are full \n");
3623            break;
3624        }
3625        if (staInfo && (staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE)) {
3626          while((( TRUE == hipslotFree[3] ) && (buffered_pkt=dequeue_tx_data_pdu(priv, &staInfo->mgtFrames)))) {
3627              buffered_pkt->transmissionControl &=
3628                           ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK);
3629              if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,0,FALSE)) == -ENOSPC) {
3630                  unifi_trace(priv, UDBG3, "(ENOSPC) in resume_unicast_buffered_frames:: hip slots are full for voice queue\n");
3631                  /* Enqueue at the head of the queue */
3632                  spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3633                  list_add(&buffered_pkt->q, &staInfo->mgtFrames);
3634                  spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3635                  priv->pausedStaHandle[3]=(u8)(staInfo->assignedHandle);
3636                  hipslotFree[3] = FALSE;
3637                  break;
3638              } else {
3639                  if(r){
3640                      unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3641                      /* the PDU failed where we can't do any thing so free the storage */
3642                      unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3643                  }
3644                  kfree(buffered_pkt);
3645              }
3646          }
3647
3648          for(j=3;j>=0;j--) {
3649              if(!hipslotFree[j])
3650                  continue;
3651
3652              while((buffered_pkt=dequeue_tx_data_pdu(priv, &staInfo->dataPdu[j]))) {
3653                 buffered_pkt->transmissionControl &=
3654                            ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK);
3655                 if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,0,FALSE)) == -ENOSPC) {
3656                     /* Enqueue at the head of the queue */
3657                     spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3658                     list_add(&buffered_pkt->q, &staInfo->dataPdu[j]);
3659                     spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3660                     priv->pausedStaHandle[j]=(u8)(staInfo->assignedHandle);
3661                     hipslotFree[j]=FALSE;
3662                     break;
3663                 } else {
3664                    if(r){
3665                        unifi_trace (priv, UDBG1, " HIP validation failure : PDU sending failed \n");
3666                        /* the PDU failed where we can't do any thing so free the storage */
3667                        unifi_net_data_free(priv, &buffered_pkt->bulkdata);
3668                     }
3669                    kfree(buffered_pkt);
3670                 }
3671              }
3672          }
3673       }
3674    }
3675    func_exit();
3676}
3677void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,u16 interfaceTag)
3678{
3679
3680    netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
3681    unsigned long lock_flags;
3682    struct list_head *listHead;
3683    struct list_head *placeHolder;
3684    tx_buffered_packets_t *tx_q_item;
3685
3686    func_enter();
3687    if (interfacePriv->noOfbroadcastPktQueued) {
3688
3689        /* Update the EOSP to the HEAD of b/c list
3690         * beacuse we have received any mgmt packet so it should not hold for long time
3691         * peer may time out.
3692         */
3693        spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
3694        list_for_each_safe(listHead, placeHolder, &interfacePriv->genericMulticastOrBroadCastFrames) {
3695            tx_q_item = list_entry(listHead, tx_buffered_packets_t, q);
3696            tx_q_item->transmissionControl |= TRANSMISSION_CONTROL_EOSP_MASK;
3697            tx_q_item->transmissionControl = (tx_q_item->transmissionControl & ~(CSR_NO_CONFIRM_REQUIRED));
3698            unifi_trace(priv, UDBG1,"updating eosp for list Head hostTag:= 0x%x ",tx_q_item->hostTag);
3699            break;
3700        }
3701        spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags);
3702    }
3703    func_exit();
3704}
3705
3706/*
3707 * ---------------------------------------------------------------------------
3708 *  resume_suspended_uapsd
3709 *
3710 *      This function takes care processing packets of Unscheduled Service Period,
3711 *      which been suspended earlier due to DTIM/HIP ENOSPC scenarios
3712 *
3713 *  Arguments:
3714 *      priv            Pointer to device private context struct
3715 *      interfaceTag    For which resume should happen
3716 * ---------------------------------------------------------------------------
3717 */
3718void resume_suspended_uapsd(unifi_priv_t* priv,u16 interfaceTag)
3719{
3720
3721   u8 startIndex;
3722   CsrWifiRouterCtrlStaInfo_t * staInfo = NULL;
3723    unsigned long lock_flags;
3724
3725    unifi_trace(priv, UDBG2, "++resume_suspended_uapsd: \n");
3726    for(startIndex= 0; startIndex < UNIFI_MAX_CONNECTIONS;startIndex++) {
3727        staInfo =  CsrWifiRouterCtrlGetStationRecordFromHandle(priv,startIndex,interfaceTag);
3728
3729        if(!staInfo || !staInfo->wmmOrQosEnabled) {
3730            continue;
3731        } else if((staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE)
3732                   &&staInfo->uapsdActive && staInfo->uspSuspend) {
3733            /* U-APSD Still active & previously suspended either ENOSPC of FH queues OR
3734             * due to DTIM activity
3735             */
3736            uf_handle_uspframes_delivery(priv, staInfo, interfaceTag);
3737        } else {
3738            unifi_trace(priv, UDBG2, "resume_suspended_uapsd: PS state=%x, uapsdActive?=%x, suspend?=%x\n",
3739                        staInfo->currentPeerState, staInfo->uapsdActive, staInfo->uspSuspend);
3740            if (staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE)
3741            {
3742                spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
3743                staInfo->uapsdActive = FALSE;
3744                staInfo->uspSuspend = FALSE;
3745                spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
3746            }
3747        }
3748    }
3749    unifi_trace(priv, UDBG2, "--resume_suspended_uapsd:\n");
3750}
3751
3752#endif
3753