/**
 *  @brief This function adds a BSS priority table
 *  
 *  @param pmadapter	A pointer to mlan_adapter structure
 *  @param bss_num  	BSS number
 *
 *  @return		MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
mlan_status
wlan_add_bsspriotbl(pmlan_adapter pmadapter, t_u8 bss_num)
{
    pmlan_private priv = pmadapter->priv[bss_num];
    mlan_bssprio_node *pbssprio;
    mlan_status status = MLAN_STATUS_SUCCESS;

    ENTER();

    if ((status = pmadapter->callbacks.moal_malloc(sizeof(mlan_bssprio_node),
                                                   (t_u8 **) & pbssprio))) {
        PRINTM(MERROR, "Allocation failed for add_bsspriotbl\n");
        return status;
    }

    pbssprio->priv = priv;

    util_init_list((pmlan_linked_list) pbssprio);

    if (!pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur)
        pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur = pbssprio;

    util_enqueue_list_tail(&pmadapter->bssprio_tbl[priv->bss_priority].
                           bssprio_head, (pmlan_linked_list) pbssprio,
                           pmadapter->callbacks.moal_spin_lock,
                           pmadapter->callbacks.moal_spin_unlock);

    LEAVE();
    return status;
}
/**
 *  @brief This function adds a BSS priority table
 *
 *  @param priv		A pointer to mlan_private structure
 *
 *  @return		MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
static mlan_status
wlan_add_bsspriotbl(pmlan_private priv)
{
    pmlan_adapter pmadapter = priv->adapter;
    mlan_bssprio_node *pbssprio = MNULL;
    mlan_status status = MLAN_STATUS_SUCCESS;

    ENTER();

    if ((status =
                pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
                        sizeof(mlan_bssprio_node),
                        MLAN_MEM_DEF,
                        (t_u8 **) & pbssprio))) {
        PRINTM(MERROR, "Failed to allocate bsspriotbl\n");
        return status;
    }

    pbssprio->priv = priv;

    util_init_list((pmlan_linked_list) pbssprio);

    if (!pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur)
        pmadapter->bssprio_tbl[priv->bss_priority].bssprio_cur = pbssprio;

    util_enqueue_list_tail(pmadapter->pmoal_handle,
                           &pmadapter->bssprio_tbl[priv->
                                   bss_priority].bssprio_head,
                           (pmlan_linked_list) pbssprio,
                           pmadapter->callbacks.moal_spin_lock,
                           pmadapter->callbacks.moal_spin_unlock);

    LEAVE();
    return status;
}
/**
 *  @brief This function will create a entry in tx ba stream table for the 
 *  		given RA/TID.
 *  
 *  @param priv      A pointer to mlan_private
 *  @param ra        RA to find in reordering table
 *  @param tid	     TID to find in reordering table
 *  @param ba_status BA stream status to create the stream with
 *
 *  @return 	    N/A
 */
void
wlan_11n_create_txbastream_tbl(mlan_private * priv,
                               t_u8 * ra, int tid, baStatus_e ba_status)
{
    TxBAStreamTbl *newNode = MNULL;
    pmlan_adapter pmadapter = priv->adapter;

    ENTER();

    if (!wlan_11n_get_txbastream_tbl(priv, tid, ra)) {
        PRINTM(MDAT_D, "get_txbastream_tbl TID %d", tid);
        DBG_HEXDUMP(MDAT_D, "RA", ra, MLAN_MAC_ADDR_LENGTH);

        pmadapter->callbacks.moal_malloc(pmadapter->pmoal_handle,
                                         sizeof(TxBAStreamTbl), MLAN_MEM_DEF,
                                         (t_u8 **) & newNode);
        util_init_list((pmlan_linked_list) newNode);

        newNode->tid = tid;
        newNode->ba_status = ba_status;
        memcpy(pmadapter, newNode->ra, ra, MLAN_MAC_ADDR_LENGTH);

        util_enqueue_list_tail(pmadapter->pmoal_handle,
                               &priv->tx_ba_stream_tbl_ptr,
                               (pmlan_linked_list) newNode,
                               pmadapter->callbacks.moal_spin_lock,
                               pmadapter->callbacks.moal_spin_unlock);
    }

    LEAVE();
}
/** 
 *  @brief This function inserts command node to cmd_free_q
 *              after cleaning it.
 *  
 *  @param pmadapter    A pointer to mlan_adapter structure
 *  @param pcmd_node    A pointer to cmd_ctrl_node structure
 *
 *  @return             N/A
 */
t_void
wlan_insert_cmd_to_free_q(IN mlan_adapter * pmadapter,
                          IN cmd_ctrl_node * pcmd_node)
{
    mlan_callbacks *pcb = (mlan_callbacks *) & pmadapter->callbacks;
    mlan_ioctl_req *pioctl_req = MNULL;
    ENTER();

    if (pcmd_node == MNULL)
        goto done;
    if (pcmd_node->pioctl_buf) {
        pioctl_req = (mlan_ioctl_req *) pcmd_node->pioctl_buf;
        if (pioctl_req->status_code != MLAN_ERROR_NO_ERROR)
            pcb->moal_ioctl_complete(pmadapter->pmoal_handle,
                                     pioctl_req, MLAN_STATUS_FAILURE);
        else
            pcb->moal_ioctl_complete(pmadapter->pmoal_handle,
                                     pioctl_req, MLAN_STATUS_SUCCESS);
    }
    /* Clean the node */
    wlan_clean_cmd_node(pmadapter, pcmd_node);

    /* Insert node into cmd_free_q */
    util_enqueue_list_tail(&pmadapter->cmd_free_q,
                           (pmlan_linked_list) pcmd_node,
                           pmadapter->callbacks.moal_spin_lock,
                           pmadapter->callbacks.moal_spin_unlock);
  done:
    LEAVE();
}
Esempio n. 5
0
/**
 *  @brief Add packet to Bypass TX queue
 *
 *  @param pmadapter  Pointer to the mlan_adapter driver data struct
 *  @param pmbuf      Pointer to the mlan_buffer data struct
 *
 *  @return         N/A
 */
t_void
wlan_add_buf_bypass_txqueue(mlan_adapter * pmadapter, pmlan_buffer pmbuf)
{
    ENTER();

    pmbuf->buf_type = MLAN_BUF_TYPE_DATA;
    util_enqueue_list_tail(pmadapter->pmoal_handle, &pmadapter->bypass_txq,
                           (pmlan_linked_list) pmbuf,
                           pmadapter->callbacks.moal_spin_lock,
                           pmadapter->callbacks.moal_spin_unlock);
    LEAVE();
}
/** 
 *  @brief This function queues the command to cmd list.
 *  
 *  @param pmadapter    A pointer to mlan_adapter structure
 *  @param pcmd_node    A pointer to cmd_ctrl_node structure
 *  @param add_tail      Specify if the cmd needs to be queued in the header or tail
 *
 *  @return             N/A
 */
t_void
wlan_insert_cmd_to_pending_q(IN mlan_adapter * pmadapter,
                             IN cmd_ctrl_node * pcmd_node, IN t_u32 add_tail)
{
    HostCmd_DS_COMMAND *pcmd = MNULL;
    t_u16 command;

    ENTER();

    if (pcmd_node == MNULL) {
        PRINTM(MERROR, "QUEUE_CMD: pcmd_node is MNULL\n");
        goto done;
    }

    pcmd =
        (HostCmd_DS_COMMAND *) (pcmd_node->cmdbuf->pbuf +
                                pcmd_node->cmdbuf->data_offset);
    if (pcmd == MNULL) {
        PRINTM(MERROR, "QUEUE_CMD: pcmd is MNULL\n");
        goto done;
    }

    command = wlan_le16_to_cpu(pcmd->command);

/* Exit_PS command needs to be queued in the header always. */
    if (command == HostCmd_CMD_802_11_PS_MODE_ENH) {
        HostCmd_DS_802_11_PS_MODE_ENH *pm = &pcmd->params.psmode_enh;
        if (wlan_le16_to_cpu(pm->action) == DIS_PS) {
            if (pmadapter->ps_state != PS_STATE_AWAKE)
                add_tail = MFALSE;
        }
    }

    if (add_tail) {
        util_enqueue_list_tail(&pmadapter->cmd_pending_q,
                               (pmlan_linked_list) pcmd_node,
                               pmadapter->callbacks.moal_spin_lock,
                               pmadapter->callbacks.moal_spin_unlock);
    } else {
        util_enqueue_list_head(&pmadapter->cmd_pending_q,
                               (pmlan_linked_list) pcmd_node,
                               pmadapter->callbacks.moal_spin_lock,
                               pmadapter->callbacks.moal_spin_unlock);
    }

    PRINTM(MCMND, "QUEUE_CMD: cmd=0x%x is queued\n", command);

  done:
    LEAVE();
    return;
}
/**
 *  @brief Add packet to Bypass TX queue
 *
 *  @param pmadapter  Pointer to the mlan_adapter driver data struct
 *  @param pmbuf      Pointer to the mlan_buffer data struct
 *
 *  @return         N/A
 */
t_void
wlan_add_buf_bypass_txqueue(mlan_adapter * pmadapter, pmlan_buffer pmbuf)
{
	pmlan_private priv = pmadapter->priv[pmbuf->bss_index];
	ENTER();

	if (pmbuf->buf_type != MLAN_BUF_TYPE_RAW_DATA)
		pmbuf->buf_type = MLAN_BUF_TYPE_DATA;
	pmadapter->callbacks.moal_spin_lock(pmadapter->pmoal_handle,
					    priv->bypass_txq.plock);
	pmadapter->bypass_pkt_count++;
	util_enqueue_list_tail(pmadapter->pmoal_handle, &priv->bypass_txq,
			       (pmlan_linked_list) pmbuf, MNULL, MNULL);
	pmadapter->callbacks.moal_spin_unlock(pmadapter->pmoal_handle,
					      priv->bypass_txq.plock);
	LEAVE();
}
/**
 *  @brief This function will create a entry in rx reordering table for the 
 *  		given ta/tid and will initialize it with seq_num, win_size
 *  
 *  @param priv     A pointer to mlan_private
 *  @param ta       ta to find in reordering table
 *  @param tid	    tid to find in reordering table
 *  @param win_size win_size for the give ta/tid pair.
 *  @param seq_num  Starting sequence number for current entry.
 *
 *  @return 	    N/A
 */
t_void
wlan_11n_create_rxreorder_tbl(mlan_private * priv, t_u8 * ta, int tid,
                              int win_size, int seq_num)
{
    int i;
    pmlan_adapter pmadapter = priv->adapter;
    RxReorderTbl *rx_reor_tbl_ptr, *new_node;

    ENTER();

    /* 
     * If we get a TID, ta pair which is already present dispatch all the
     * the packets and move the window size until the ssn
     */
    if ((rx_reor_tbl_ptr = wlan_11n_get_rxreorder_tbl(priv, tid, ta))) {
        wlan_11n_dispatch_pkt_until_start_win(priv, rx_reor_tbl_ptr, seq_num);
    } else {
        PRINTM(MDAT_D, "%s: seq_num %d, tid %d, ta %02x:%02x:%02x:%02x:"
               "%02x:%02x, win_size %d\n", __FUNCTION__,
               seq_num, tid, ta[0], ta[1], ta[2], ta[3],
               ta[4], ta[5], win_size);
        if (pmadapter->callbacks.moal_malloc(sizeof(RxReorderTbl),
                                             (t_u8 **) & new_node)) {
            PRINTM(MERROR, "Rx reorder memory allocation failed\n");
            return;
        }

        util_init_list((pmlan_linked_list) new_node);
        new_node->tid = tid;
        memcpy(new_node->ta, ta, MLAN_MAC_ADDR_LENGTH);
        new_node->start_win = seq_num;
        new_node->win_size = win_size;

        if (pmadapter->callbacks.moal_malloc(sizeof(t_void *) * win_size,
                                             (t_u8 **) & new_node->
                                             rx_reorder_ptr)) {
            PRINTM(MERROR, "Rx reorder table memory allocation" "failed\n");
            pmadapter->callbacks.moal_mfree((t_u8 *) new_node);
            return;
        }

        PRINTM(MDAT_D, "Create ReorderPtr: %p\n", new_node);
        new_node->timer_context.ptr = new_node;
        new_node->timer_context.priv = priv;
        new_node->timer_context.timer_is_set = MFALSE;

        pmadapter->callbacks.moal_init_timer(&new_node->timer_context.
                                             timer, wlan_flush_data,
                                             &new_node->timer_context);

        for (i = 0; i < win_size; ++i)
            new_node->rx_reorder_ptr[i] = MNULL;

        util_enqueue_list_tail(&priv->rx_reorder_tbl_ptr,
                               (pmlan_linked_list) new_node,
                               pmadapter->callbacks.moal_spin_lock,
                               pmadapter->callbacks.moal_spin_unlock);
    }

    LEAVE();
}
/**
 *  @brief This function will create a entry in rx reordering table for the 
 *  		given ta/tid and will initialize it with seq_num, win_size
 *  
 *  @param priv     A pointer to mlan_private
 *  @param ta       ta to find in reordering table
 *  @param tid	    tid to find in reordering table
 *  @param win_size win_size for the give ta/tid pair.
 *  @param seq_num  Starting sequence number for current entry.
 *
 *  @return 	    N/A
 */
t_void
wlan_11n_create_rxreorder_tbl(mlan_private * priv, t_u8 * ta, int tid,
                              int win_size, int seq_num)
{
    int i;
    pmlan_adapter pmadapter = priv->adapter;
    RxReorderTbl *rx_reor_tbl_ptr, *new_node;
#ifdef UAP_SUPPORT
    sta_node *sta_ptr = MNULL;
#endif
    t_u16 last_seq = 0;
    ENTER();

    /* 
     * If we get a TID, ta pair which is already present dispatch all the
     * the packets and move the window size until the ssn
     */
    if ((rx_reor_tbl_ptr = wlan_11n_get_rxreorder_tbl(priv, tid, ta))) {
        wlan_11n_dispatch_pkt_until_start_win(priv, rx_reor_tbl_ptr, seq_num);
    } else {
        PRINTM(MDAT_D, "%s: seq_num %d, tid %d, ta %02x:%02x:%02x:%02x:"
               "%02x:%02x, win_size %d\n", __FUNCTION__,
               seq_num, tid, ta[0], ta[1], ta[2], ta[3],
               ta[4], ta[5], win_size);
        if (pmadapter->callbacks.
            moal_malloc(pmadapter->pmoal_handle, sizeof(RxReorderTbl),
                        MLAN_MEM_DEF, (t_u8 **) & new_node)) {
            PRINTM(MERROR, "Rx reorder memory allocation failed\n");
            return;
        }

        util_init_list((pmlan_linked_list) new_node);
        new_node->tid = tid;
        memcpy(pmadapter, new_node->ta, ta, MLAN_MAC_ADDR_LENGTH);
        new_node->start_win = seq_num;
        if (queuing_ra_based(priv)) {
            // TODO for adhoc
#ifdef UAP_SUPPORT
            if (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_UAP) {
                if ((sta_ptr = wlan_get_station_entry(priv, ta)))
                    last_seq = sta_ptr->rx_seq[tid];
            }
#endif
            PRINTM(MINFO, "UAP/ADHOC:last_seq=%d start_win=%d\n", last_seq,
                   new_node->start_win);
        } else {
            last_seq = priv->rx_seq[tid];
        }
        if (last_seq >= new_node->start_win) {
            PRINTM(MDAT_D, "Update start_win: last_seq=%d, start_win=%d\n",
                   last_seq, new_node->start_win);
            new_node->start_win = last_seq + 1;
        }
        new_node->win_size = win_size;

        if (pmadapter->callbacks.
            moal_malloc(pmadapter->pmoal_handle, sizeof(t_void *) * win_size,
                        MLAN_MEM_DEF, (t_u8 **) & new_node->rx_reorder_ptr)) {
            PRINTM(MERROR, "Rx reorder table memory allocation" "failed\n");
            pmadapter->callbacks.moal_mfree(pmadapter->pmoal_handle,
                                            (t_u8 *) new_node);
            return;
        }

        PRINTM(MDAT_D, "Create ReorderPtr: %p\n", new_node);
        new_node->timer_context.ptr = new_node;
        new_node->timer_context.priv = priv;
        new_node->timer_context.timer_is_set = MFALSE;

        pmadapter->callbacks.moal_init_timer(pmadapter->pmoal_handle,
                                             &new_node->timer_context.timer,
                                             wlan_flush_data,
                                             &new_node->timer_context);

        for (i = 0; i < win_size; ++i)
            new_node->rx_reorder_ptr[i] = MNULL;

        util_enqueue_list_tail(pmadapter->pmoal_handle,
                               &priv->rx_reorder_tbl_ptr,
                               (pmlan_linked_list) new_node,
                               pmadapter->callbacks.moal_spin_lock,
                               pmadapter->callbacks.moal_spin_unlock);
    }

    LEAVE();
}
/**
 *  @brief This function decodes the rx packet &
 *  calls corresponding handlers according to the packet type
 *
 *  @param pmadapter A pointer to mlan_adapter structure
 *  @param pmbuf      A pointer to the SDIO data/cmd buffer
 *  @param upld_typ  Type of rx packet
 *  @return 	   MLAN_STATUS_SUCCESS
 */
static mlan_status
wlan_decode_rx_packet(mlan_adapter * pmadapter, mlan_buffer * pmbuf,
		      t_u32 upld_typ)
{
	t_u8 *cmdBuf;
	t_u32 event;

	ENTER();

	switch (upld_typ) {
	case MLAN_TYPE_DATA:
		PRINTM(MINFO, "--- Rx: Data packet ---\n");
		pmbuf->data_len = (pmadapter->upld_len - INTF_HEADER_LEN);
		pmbuf->data_offset += INTF_HEADER_LEN;
		util_enqueue_list_tail(pmadapter->pmoal_handle,
				       &pmadapter->rx_data_queue,
				       (pmlan_linked_list) pmbuf,
				       pmadapter->callbacks.moal_spin_lock,
				       pmadapter->callbacks.moal_spin_unlock);
		util_scalar_increment(pmadapter->pmoal_handle,
				      &pmadapter->rx_pkts_queued,
				      pmadapter->callbacks.moal_spin_lock,
				      pmadapter->callbacks.moal_spin_unlock);
		pmadapter->data_received = MTRUE;
		break;

	case MLAN_TYPE_CMD:
		PRINTM(MINFO, "--- Rx: Cmd Response ---\n");
		/* take care of curr_cmd = NULL case */
		if (!pmadapter->curr_cmd) {
			cmdBuf = pmadapter->upld_buf;
			if (pmadapter->ps_state == PS_STATE_SLEEP_CFM) {
				wlan_process_sleep_confirm_resp(pmadapter,
								pmbuf->pbuf +
								pmbuf->
								data_offset +
								INTF_HEADER_LEN,
								pmadapter->
								upld_len -
								INTF_HEADER_LEN);
			}
			pmadapter->upld_len -= INTF_HEADER_LEN;
			memcpy(pmadapter, cmdBuf,
			       pmbuf->pbuf + pmbuf->data_offset +
			       INTF_HEADER_LEN, MIN(MRVDRV_SIZE_OF_CMD_BUFFER,
						    pmadapter->upld_len -
						    INTF_HEADER_LEN));
			wlan_free_mlan_buffer(pmadapter, pmbuf);
		} else {
			pmadapter->cmd_resp_received = MTRUE;
			pmadapter->upld_len -= INTF_HEADER_LEN;
			pmbuf->data_len = pmadapter->upld_len;
			pmbuf->data_offset += INTF_HEADER_LEN;
			pmadapter->curr_cmd->respbuf = pmbuf;
		}
		break;

	case MLAN_TYPE_EVENT:
		PRINTM(MINFO, "--- Rx: Event ---\n");
		event = *(t_u32 *) & pmbuf->pbuf[pmbuf->data_offset +
						 INTF_HEADER_LEN];
		pmadapter->event_cause = wlan_le32_to_cpu(event);
		if ((pmadapter->upld_len > MLAN_EVENT_HEADER_LEN) &&
		    ((pmadapter->upld_len - MLAN_EVENT_HEADER_LEN) <
		     MAX_EVENT_SIZE)) {
			memcpy(pmadapter, pmadapter->event_body,
			       pmbuf->pbuf + pmbuf->data_offset +
			       MLAN_EVENT_HEADER_LEN,
			       pmadapter->upld_len - MLAN_EVENT_HEADER_LEN);
		}

		/* event cause has been saved to adapter->event_cause */
		pmadapter->event_received = MTRUE;
		pmbuf->data_len = pmadapter->upld_len;
		pmadapter->pmlan_buffer_event = pmbuf;

		/* remove SDIO header */
		pmbuf->data_offset += INTF_HEADER_LEN;
		pmbuf->data_len -= INTF_HEADER_LEN;
		break;

	default:
		PRINTM(MERROR, "SDIO unknown upload type = 0x%x\n", upld_typ);
		wlan_free_mlan_buffer(pmadapter, pmbuf);
		break;
	}

	LEAVE();
	return MLAN_STATUS_SUCCESS;
}