rsi_91x_pkt.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "rsi_mgmt.h"
  17. /**
  18. * rsi_send_data_pkt() - This function sends the recieved data packet from
  19. * driver to device.
  20. * @common: Pointer to the driver private structure.
  21. * @skb: Pointer to the socket buffer structure.
  22. *
  23. * Return: status: 0 on success, -1 on failure.
  24. */
  25. int rsi_send_data_pkt(struct rsi_common *common, struct sk_buff *skb)
  26. {
  27. struct rsi_hw *adapter = common->priv;
  28. struct ieee80211_hdr *tmp_hdr = NULL;
  29. struct ieee80211_tx_info *info;
  30. struct skb_info *tx_params;
  31. struct ieee80211_bss_conf *bss = NULL;
  32. int status = -EINVAL;
  33. u8 ieee80211_size = MIN_802_11_HDR_LEN;
  34. u8 extnd_size = 0;
  35. __le16 *frame_desc;
  36. u16 seq_num = 0;
  37. info = IEEE80211_SKB_CB(skb);
  38. bss = &info->control.vif->bss_conf;
  39. tx_params = (struct skb_info *)info->driver_data;
  40. if (!bss->assoc)
  41. goto err;
  42. tmp_hdr = (struct ieee80211_hdr *)&skb->data[0];
  43. seq_num = (le16_to_cpu(tmp_hdr->seq_ctrl) >> 4);
  44. extnd_size = ((uintptr_t)skb->data & 0x3);
  45. if ((FRAME_DESC_SZ + extnd_size) > skb_headroom(skb)) {
  46. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
  47. status = -ENOSPC;
  48. goto err;
  49. }
  50. skb_push(skb, (FRAME_DESC_SZ + extnd_size));
  51. frame_desc = (__le16 *)&skb->data[0];
  52. memset((u8 *)frame_desc, 0, FRAME_DESC_SZ);
  53. if (ieee80211_is_data_qos(tmp_hdr->frame_control)) {
  54. ieee80211_size += 2;
  55. frame_desc[6] |= cpu_to_le16(BIT(12));
  56. }
  57. if ((!(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) &&
  58. (common->secinfo.security_enable)) {
  59. if (rsi_is_cipher_wep(common))
  60. ieee80211_size += 4;
  61. else
  62. ieee80211_size += 8;
  63. frame_desc[6] |= cpu_to_le16(BIT(15));
  64. }
  65. frame_desc[0] = cpu_to_le16((skb->len - FRAME_DESC_SZ) |
  66. (RSI_WIFI_DATA_Q << 12));
  67. frame_desc[2] = cpu_to_le16((extnd_size) | (ieee80211_size) << 8);
  68. if (common->min_rate != 0xffff) {
  69. /* Send fixed rate */
  70. frame_desc[3] = cpu_to_le16(RATE_INFO_ENABLE);
  71. frame_desc[4] = cpu_to_le16(common->min_rate);
  72. }
  73. frame_desc[6] |= cpu_to_le16(seq_num & 0xfff);
  74. frame_desc[7] = cpu_to_le16(((tx_params->tid & 0xf) << 4) |
  75. (skb->priority & 0xf) |
  76. (tx_params->sta_id << 8));
  77. status = adapter->host_intf_write_pkt(common->priv,
  78. skb->data,
  79. skb->len);
  80. if (status)
  81. rsi_dbg(ERR_ZONE, "%s: Failed to write pkt\n",
  82. __func__);
  83. err:
  84. ++common->tx_stats.total_tx_pkt_freed[skb->priority];
  85. rsi_indicate_tx_status(common->priv, skb, status);
  86. return status;
  87. }
  88. /**
  89. * rsi_send_mgmt_pkt() - This functions sends the received management packet
  90. * from driver to device.
  91. * @common: Pointer to the driver private structure.
  92. * @skb: Pointer to the socket buffer structure.
  93. *
  94. * Return: status: 0 on success, -1 on failure.
  95. */
  96. int rsi_send_mgmt_pkt(struct rsi_common *common,
  97. struct sk_buff *skb)
  98. {
  99. struct rsi_hw *adapter = common->priv;
  100. struct ieee80211_hdr *wh = NULL;
  101. struct ieee80211_tx_info *info;
  102. struct ieee80211_bss_conf *bss = NULL;
  103. struct skb_info *tx_params;
  104. int status = -E2BIG;
  105. __le16 *msg = NULL;
  106. u8 extnd_size = 0;
  107. u8 vap_id = 0;
  108. info = IEEE80211_SKB_CB(skb);
  109. tx_params = (struct skb_info *)info->driver_data;
  110. extnd_size = ((uintptr_t)skb->data & 0x3);
  111. if (tx_params->flags & INTERNAL_MGMT_PKT) {
  112. if ((extnd_size) > skb_headroom(skb)) {
  113. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
  114. dev_kfree_skb(skb);
  115. return -ENOSPC;
  116. }
  117. skb_push(skb, extnd_size);
  118. skb->data[extnd_size + 4] = extnd_size;
  119. status = adapter->host_intf_write_pkt(common->priv,
  120. (u8 *)skb->data,
  121. skb->len);
  122. if (status) {
  123. rsi_dbg(ERR_ZONE,
  124. "%s: Failed to write the packet\n", __func__);
  125. }
  126. dev_kfree_skb(skb);
  127. return status;
  128. }
  129. bss = &info->control.vif->bss_conf;
  130. wh = (struct ieee80211_hdr *)&skb->data[0];
  131. if (FRAME_DESC_SZ > skb_headroom(skb))
  132. goto err;
  133. skb_push(skb, FRAME_DESC_SZ);
  134. memset(skb->data, 0, FRAME_DESC_SZ);
  135. msg = (__le16 *)skb->data;
  136. if (skb->len > MAX_MGMT_PKT_SIZE) {
  137. rsi_dbg(INFO_ZONE, "%s: Dropping mgmt pkt > 512\n", __func__);
  138. goto err;
  139. }
  140. msg[0] = cpu_to_le16((skb->len - FRAME_DESC_SZ) |
  141. (RSI_WIFI_MGMT_Q << 12));
  142. msg[1] = cpu_to_le16(TX_DOT11_MGMT);
  143. msg[2] = cpu_to_le16(MIN_802_11_HDR_LEN << 8);
  144. msg[3] = cpu_to_le16(RATE_INFO_ENABLE);
  145. msg[6] = cpu_to_le16(le16_to_cpu(wh->seq_ctrl) >> 4);
  146. if (wh->addr1[0] & BIT(0))
  147. msg[3] |= cpu_to_le16(RSI_BROADCAST_PKT);
  148. if (common->band == IEEE80211_BAND_2GHZ)
  149. msg[4] = cpu_to_le16(RSI_11B_MODE);
  150. else
  151. msg[4] = cpu_to_le16((RSI_RATE_6 & 0x0f) | RSI_11G_MODE);
  152. /* Indicate to firmware to give cfm */
  153. if ((skb->data[16] == IEEE80211_STYPE_PROBE_REQ) && (!bss->assoc)) {
  154. msg[1] |= cpu_to_le16(BIT(10));
  155. msg[7] = cpu_to_le16(PROBEREQ_CONFIRM);
  156. common->mgmt_q_block = true;
  157. }
  158. msg[7] |= cpu_to_le16(vap_id << 8);
  159. status = adapter->host_intf_write_pkt(common->priv,
  160. (u8 *)msg,
  161. skb->len);
  162. if (status)
  163. rsi_dbg(ERR_ZONE, "%s: Failed to write the packet\n", __func__);
  164. err:
  165. rsi_indicate_tx_status(common->priv, skb, status);
  166. return status;
  167. }